limixbot 0.3.11 → 0.3.12

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 (124) hide show
  1. package/dist/assets/{ActivityPanel-BODxWmfO.js → ActivityPanel-CJM61CWQ.js} +1 -1
  2. package/dist/assets/{App-DPG1sq1r.js → App-DRnqqiJP.js} +125 -125
  3. package/dist/assets/{AppEventEditor-QyHQdp7V.js → AppEventEditor-1hupO_kL.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-BCNOcqOS.js → BotSettingsDialog-B56-kmya.js} +4 -4
  5. package/dist/assets/{BrowserPanel-BqPnj2Bz.js → BrowserPanel-BXBygd1y.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-BMk7i2tc.js → BrowserProfilesManager-CzzGhZGz.js} +1 -1
  7. package/dist/assets/CloudAddDialog-MMhMrVK3.js +1 -0
  8. package/dist/assets/{ComputerFilesPane-BWmAv8JT.js → ComputerFilesPane-Hpxjnk2e.js} +1 -1
  9. package/dist/assets/ComputerPanel-CMce64RT.js +2 -0
  10. package/dist/assets/{DataPanel-BgfqxYo9.js → DataPanel-BQ7Ua1Oq.js} +1 -1
  11. package/dist/assets/{DesktopViewer-BMD84CFj.js → DesktopViewer-BRzNtGEm.js} +1 -1
  12. package/dist/assets/{FilesView-CGYpajry.js → FilesView-DQYXl0zm.js} +1 -1
  13. package/dist/assets/{GrokMoveDialog-B3aEa4hb.js → GrokMoveDialog-Dk-pwczv.js} +1 -1
  14. package/dist/assets/{InspectorPanel-CTNcZYHr.js → InspectorPanel-CvnM0TFW.js} +1 -1
  15. package/dist/assets/{KeyboardShortcutsModal-CBmbtwhH.js → KeyboardShortcutsModal-BQ8aAw16.js} +1 -1
  16. package/dist/assets/{LiveDesktop-7h7Mxr41.js → LiveDesktop-Cr7uAFoQ.js} +1 -1
  17. package/dist/assets/LocalVmWorkspace-BJ-i68MR.js +1 -0
  18. package/dist/assets/MacLocalControl-DE8MVZkU.js +1 -0
  19. package/dist/assets/{MarkdownFilePreview-_1MC5Db0.js → MarkdownFilePreview-B_6azXNT.js} +1 -1
  20. package/dist/assets/{MenuMotion-C1J3xC0E.js → MenuMotion-BDYr4RxL.js} +1 -1
  21. package/dist/assets/{NewBotDialog-C35vqYL4.js → NewBotDialog-D9fUysLU.js} +1 -1
  22. package/dist/assets/PhoneAppDialog-DUv4Qx8n.js +1 -0
  23. package/dist/assets/{PlacesRail-DnedL3jM.js → PlacesRail-yZdo57pP.js} +1 -1
  24. package/dist/assets/{PluginsPanel-CvZhoTE-.js → PluginsPanel-DYuWdWZd.js} +1 -1
  25. package/dist/assets/{ProIntroduction-B1QqcZmr.js → ProIntroduction-DapZkP7I.js} +1 -1
  26. package/dist/assets/{RemoteAgentSettingsPanel-DU6QyjIY.js → RemoteAgentSettingsPanel-sNv3TbBd.js} +1 -1
  27. package/dist/assets/{RoomPanel-Om9r5yMG.js → RoomPanel-DrlyOJKZ.js} +1 -1
  28. package/dist/assets/{RoutinesPage-BWJ5Z1Sk.js → RoutinesPage-CIo30TVq.js} +2 -2
  29. package/dist/assets/SettingsModal-BpJhi2nc.js +11 -0
  30. package/dist/assets/{ShareTeamDialog-DkKdhm01.js → ShareTeamDialog-CH1ts7Uj.js} +1 -1
  31. package/dist/assets/{SignedInSites-Dxnqcjlx.js → SignedInSites-CisTAQW0.js} +1 -1
  32. package/dist/assets/{TeamLibraryPanel-C3QFOJmQ.js → TeamLibraryPanel-DvnKye05.js} +1 -1
  33. package/dist/assets/TeamMapPage-JOiilgs0.js +1 -0
  34. package/dist/assets/TriggersPage-DQ3HQ6_i.js +1 -0
  35. package/dist/assets/{VisibilitySection-DiD7SczA.js → VisibilitySection-DXfPp0Ql.js} +1 -1
  36. package/dist/assets/{WebhookTrigger-w_Pjci5K.js → WebhookTrigger-BYeOyOpX.js} +1 -1
  37. package/dist/assets/{WorksOnGrid-B84wDbPo.js → WorksOnGrid-8fCnUzpQ.js} +1 -1
  38. package/dist/assets/{abnfDiagram-YUKMZFIV-Dr-8nZOt.js → abnfDiagram-YUKMZFIV-Boj-Bkbs.js} +1 -1
  39. package/dist/assets/{activity-bTJO9mSI.js → activity-MpAxS_kw.js} +1 -1
  40. package/dist/assets/{architectureDiagram-47P4ROYG-23P1y-s5.js → architectureDiagram-47P4ROYG-Cl-ocqce.js} +1 -1
  41. package/dist/assets/{blockDiagram-E7TT5TSB-D1mBvWuR.js → blockDiagram-E7TT5TSB-0nSQiv6g.js} +1 -1
  42. package/dist/assets/{c4Diagram-CRA5TL53-BKK5iCAq.js → c4Diagram-CRA5TL53-Cx9iymkb.js} +1 -1
  43. package/dist/assets/{calendar-days-Ckb7s5k5.js → calendar-days-DXHDRm_4.js} +1 -1
  44. package/dist/assets/channel-BStWWrSt.js +1 -0
  45. package/dist/assets/{chunk-2Q5K7J3B-C6ElI8Gj.js → chunk-2Q5K7J3B-0rIrumUG.js} +1 -1
  46. package/dist/assets/{chunk-5VM5RSS4-B9VKa5BI.js → chunk-5VM5RSS4-w9e6iKvs.js} +1 -1
  47. package/dist/assets/{chunk-7TKQ45FW-CrgJv6B8.js → chunk-7TKQ45FW-c4KxVKkf.js} +1 -1
  48. package/dist/assets/{chunk-AW2ZBBNX-CVe28FV5.js → chunk-AW2ZBBNX-DmaBcuOP.js} +1 -1
  49. package/dist/assets/{chunk-FVRAUYC3-BLPrVPPQ.js → chunk-FVRAUYC3-BLzfqLHR.js} +2 -2
  50. package/dist/assets/{chunk-HTAEGDNF-BB9kWhE5.js → chunk-HTAEGDNF-BN48XtBm.js} +1 -1
  51. package/dist/assets/{chunk-JWPE2WC7-y2b0u5g-.js → chunk-JWPE2WC7-D2NACa6i.js} +1 -1
  52. package/dist/assets/{chunk-KQW6MTUR-BMp5NWQw.js → chunk-KQW6MTUR-CbAfnxxG.js} +1 -1
  53. package/dist/assets/{chunk-XXDRQBXY-gUdzE10_.js → chunk-XXDRQBXY-Bwg-DPP_.js} +1 -1
  54. package/dist/assets/{classDiagram-v2-K4WV4PDN-DNfrg4LR.js → classDiagram-v2-K4WV4PDN-Dh3ohoZp.js} +1 -1
  55. package/dist/assets/{coins-CBbaS4z-.js → coins-Bv8-qll4.js} +1 -1
  56. package/dist/assets/{core-BNIINisk.js → core-DeJAGBXR.js} +1 -1
  57. package/dist/assets/{cose-bilkent-JH36ORCC-D84YhUzh.js → cose-bilkent-JH36ORCC-DCHadn0L.js} +1 -1
  58. package/dist/assets/{cynefin-EF2NZ3EQ-DMBZCt-X.js → cynefin-EF2NZ3EQ-ClpPPxUg.js} +1 -1
  59. package/dist/assets/{cynefinDiagram-3GCD6N5R-BZhcnyNF.js → cynefinDiagram-3GCD6N5R-DZ5l7nkL.js} +1 -1
  60. package/dist/assets/{dagre-W4DXFKR2-DY68eKcA.js → dagre-W4DXFKR2-BagTvT62.js} +1 -1
  61. package/dist/assets/{diagram-2UJZ2QOL-Bv-0-qqw.js → diagram-2UJZ2QOL-DuByootb.js} +1 -1
  62. package/dist/assets/{diagram-OVF4WLC6-CEnRLa7p.js → diagram-OVF4WLC6-BQ8Cvr0D.js} +1 -1
  63. package/dist/assets/{diagram-PFPMY2P6-D3UjLOE9.js → diagram-PFPMY2P6-D_pklaf9.js} +1 -1
  64. package/dist/assets/{diagram-UMYRVEAY-CJCYH8n7.js → diagram-UMYRVEAY-1BuHq7tR.js} +1 -1
  65. package/dist/assets/{diagram-YEKJPTXX-D_YEp1XW.js → diagram-YEKJPTXX-CK0cPx8n.js} +1 -1
  66. package/dist/assets/{diagram-ZIFT7M5P-C7RgDQ_I.js → diagram-ZIFT7M5P-DVzPho45.js} +1 -1
  67. package/dist/assets/{ebnfDiagram-VR2GEFS7-CVbikCfA.js → ebnfDiagram-VR2GEFS7-D8UO_5sE.js} +1 -1
  68. package/dist/assets/{elk-IJKZMXRS-BQv73EB6.js → elk-IJKZMXRS-BRigfR5V.js} +1 -1
  69. package/dist/assets/{erDiagram-O2IAPWRE-ZMuLXVBq.js → erDiagram-O2IAPWRE-CXHPobWj.js} +1 -1
  70. package/dist/assets/{file-up-BsMMeeDy.js → file-up-CQezfdJk.js} +1 -1
  71. package/dist/assets/{flowDiagram-OXPTDLAJ-CkF5DDZj.js → flowDiagram-OXPTDLAJ-CqKD6jh8.js} +1 -1
  72. package/dist/assets/{ganttDiagram-R7TSEDQI-BaYEK3at.js → ganttDiagram-R7TSEDQI-C9FV3gsA.js} +1 -1
  73. package/dist/assets/{gitGraphDiagram-XJZIOB7I-eVpEz6un.js → gitGraphDiagram-XJZIOB7I-CRu4dnr_.js} +1 -1
  74. package/dist/assets/{import-name-DzZIJafj.js → import-name-dEG0japD.js} +1 -1
  75. package/dist/assets/{index-BSIcl6wl.js → index-B4HW_T-k.js} +1 -1
  76. package/dist/assets/{index-BkcZ5EE3.js → index-COnd2OMZ.js} +2 -2
  77. package/dist/assets/{infoDiagram-5W2HQ5XZ-cLDLLbyG.js → infoDiagram-5W2HQ5XZ-CCRjb2CQ.js} +1 -1
  78. package/dist/assets/{ishikawaDiagram-K3B6WC7H-Dxie_tdO.js → ishikawaDiagram-K3B6WC7H-TaNPsGZS.js} +1 -1
  79. package/dist/assets/{journeyDiagram-COXZFDF6-DWzHn4oz.js → journeyDiagram-COXZFDF6-Dz7YIIc2.js} +1 -1
  80. package/dist/assets/{kanban-definition-P3RFRI5V-BFNqkDTK.js → kanban-definition-P3RFRI5V-Cg69Fpp8.js} +1 -1
  81. package/dist/assets/{mcp-servers-DJceaBjT.js → mcp-servers-Ih6dI7Ga.js} +1 -1
  82. package/dist/assets/{mermaid.core-Cn7buzY3.js → mermaid.core-DiG3LoLz.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LZFPQGKD-DVS-3JPN.js → mindmap-definition-LZFPQGKD-nxP4f0fq.js} +1 -1
  84. package/dist/assets/{minimize-BpyGl78C.js → minimize-B_k_fmmo.js} +1 -1
  85. package/dist/assets/{monitor-FKQbSjca.js → monitor-BfmnPU-I.js} +1 -1
  86. package/dist/assets/{new-bot-Df7cGS3Z.js → new-bot-CQm0FPc5.js} +2 -2
  87. package/dist/assets/{org-library-CT3HZbof.js → org-library-C2li0IRL.js} +1 -1
  88. package/dist/assets/{package-format-CgnYlqV5.js → package-format-B3whu9DW.js} +1 -1
  89. package/dist/assets/{pegDiagram-BGZESJAR-qwRUMAPC.js → pegDiagram-BGZESJAR-gPjpGcNH.js} +1 -1
  90. package/dist/assets/{pieDiagram-CAPJLFHJ-CTzsGZac.js → pieDiagram-CAPJLFHJ-Cgh25Z4_.js} +1 -1
  91. package/dist/assets/{quadrantDiagram-GDMTTRAM-B7Mx793h.js → quadrantDiagram-GDMTTRAM-DD9luyqA.js} +1 -1
  92. package/dist/assets/{rail-B_BFwBxk.js → rail-B1mj4zlo.js} +1 -1
  93. package/dist/assets/{railroadDiagram-SM67HX2B-zMy3LSMK.js → railroadDiagram-SM67HX2B-CS_TYko7.js} +1 -1
  94. package/dist/assets/{remote-desktop-panel-DPutXzoI.js → remote-desktop-panel-DIllbP7i.js} +1 -1
  95. package/dist/assets/{requirementDiagram-X7JNWC4A-Dm_K18IR.js → requirementDiagram-X7JNWC4A-BePHia6E.js} +1 -1
  96. package/dist/assets/{sankeyDiagram-UM26HJRW-Dx_FP9cL.js → sankeyDiagram-UM26HJRW-24ExCXGS.js} +1 -1
  97. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-D3tIz4Te.js → sequenceDiagram-ZO4K6R2Y-Dtmx27I5.js} +1 -1
  98. package/dist/assets/{sizeCapture-INFHLROL-CwiX8-_Z.js → sizeCapture-INFHLROL-2LvmoT1T.js} +1 -1
  99. package/dist/assets/{stateDiagram-v2-TBUQTH76-Biv0Rjec.js → stateDiagram-v2-TBUQTH76-moL2SIo9.js} +1 -1
  100. package/dist/assets/{styles-Cm26P6hN.js → styles-6RbfQIY7.js} +1 -1
  101. package/dist/assets/{swimlanes-N4OXWK64-Daie2jEh.js → swimlanes-N4OXWK64-D95Pk8qh.js} +1 -1
  102. package/dist/assets/swimlanesDiagram-K3J5GTZL-DByi9G3i.js +8 -0
  103. package/dist/assets/{team-share-DyK3j6N2.js → team-share-0GXKeixY.js} +1 -1
  104. package/dist/assets/{timeline-definition-YOQAKGHF-_OnzqB6-.js → timeline-definition-YOQAKGHF-HM-J25k2.js} +1 -1
  105. package/dist/assets/{usecaseDiagram-VIAY4XPW-CITmAUqx.js → usecaseDiagram-VIAY4XPW-C6q6bCzJ.js} +1 -1
  106. package/dist/assets/{vennDiagram-BLWOH2XV-BAx_UxlU.js → vennDiagram-BLWOH2XV-hf0dh2yT.js} +1 -1
  107. package/dist/assets/{vi-GKa1-xWX.js → vi-CVDyZGky.js} +1 -1
  108. package/dist/assets/{wardleyDiagram-YMQ3BMBF-DjWzxLzl.js → wardleyDiagram-YMQ3BMBF-CpT_eRn9.js} +1 -1
  109. package/dist/assets/{xychartDiagram-TAQBALBS-DpQbiSMS.js → xychartDiagram-TAQBALBS-D6g1V9DG.js} +1 -1
  110. package/dist/index.html +2 -2
  111. package/dist/rail.html +4 -4
  112. package/dist-server/package.json +1 -1
  113. package/package.json +1 -1
  114. package/dist/assets/CloudAddDialog-S7ngrMRc.js +0 -1
  115. package/dist/assets/ComputerPanel-BDPrbwmC.js +0 -2
  116. package/dist/assets/LocalVmWorkspace-Bxvn8CQX.js +0 -1
  117. package/dist/assets/MacLocalControl-C3rHusSl.js +0 -1
  118. package/dist/assets/PhoneAppDialog-DhEEfxbl.js +0 -1
  119. package/dist/assets/SettingsModal-DmFTwQIH.js +0 -11
  120. package/dist/assets/TeamMapPage-CpPh11mE.js +0 -1
  121. package/dist/assets/TriggersPage-YjklCz2p.js +0 -1
  122. package/dist/assets/channel-_uzpXF9W.js +0 -1
  123. package/dist/assets/index-DvRd5uj9.js +0 -1
  124. package/dist/assets/swimlanesDiagram-K3J5GTZL-EP8Nb7CO.js +0 -8
@@ -1,3 +1,3 @@
1
- import{c as Tt,r as a,j as n,t as s,X as Ue,f as Mt,am as Kt}from"./styles-Cm26P6hN.js";import{G as lt,Y as Rt,d2 as Vt,bG as qt,di as Gt,cH as Xt,ea as Yt,eb as Jt,dj as Zt,U as Qt,u as dt,ec as en,J as tn,ed as nn,n as Ge,ee as It,P as rn,bN as sn}from"./App-DPG1sq1r.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-BMk7i2tc.js";import{P as At,L as Xe,Z as ln,K as ht,X as cn}from"./PlacesRail-DnedL3jM.js";import{M as un,a as dn}from"./minimize-BpyGl78C.js";import{F as fn}from"./file-up-BsMMeeDy.js";const pn=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]],hn=Tt("mouse-pointer-2",pn);const mn=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],bn=Tt("shrink",mn);function xn(){const[e,t]=a.useState(()=>document.visibilityState==="visible");return a.useEffect(()=>{const r=()=>t(document.visibilityState==="visible");return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[]),e}const je="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:cursor-not-allowed disabled:opacity-40";function wn(e,t,r){return!e||!t?"connecting":r==="pending"?"taking":r==="slow"?"waiting":t.controller==="you"?"yours":t.owned?"held":t.controller==="another-viewer"?"elsewhere":t.controller==="agent"?"bot":"watching"}const mt={connecting:()=>s("browser.panel.connecting"),watching:()=>s("browser.control.watching"),bot:e=>s("browser.control.botHas",{name:e}),yours:()=>s("vm.workspace.youHaveControl"),held:e=>s("browser.control.held",{name:e}),elsewhere:()=>s("browser.control.elsewhere"),taking:()=>s("browser.control.taking"),waiting:e=>s("browser.control.waiting",{name:e})},yn=a.forwardRef(function(t,r){const{botName:o,tabs:i,nav:c,connected:u,control:w,takeStatus:v,commandsReady:m}=t,[d,g]=a.useState(""),[y,E]=a.useState(!1),k=wn(u,w,v),C=k==="yours",T=C||k==="held",b=c.url==="about:blank"?"":c.url;return n.jsxs("div",{className:"shrink-0 border-b border-hairline/40",children:[n.jsxs("div",{className:"flex min-h-10 items-center gap-1 px-2 pt-1",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",role:"tablist","aria-label":s("browser.panel.tabs"),children:[i.length?i.map(j=>n.jsxs("div",{className:`flex max-w-52 shrink-0 items-center gap-1 rounded-xl px-1 text-[12px] ${j.active?"bg-inset text-ink":"text-ink-secondary"}`,children:[n.jsx(lt,{size:13,className:"ml-1.5 shrink-0 opacity-60","aria-hidden":"true"}),n.jsx("button",{role:"tab","aria-selected":j.active,className:"truncate px-1 py-1.5 text-left disabled:cursor-default",disabled:!m,onClick:()=>t.onCommand({type:"tabSelect",tabId:j.tabId}),title:j.title||j.url,children:j.title||s("browser.panel.newTab")}),n.jsx("button",{className:je,"aria-label":s("browser.panel.closeTab",{title:j.title||s("browser.panel.tab")}),disabled:!m,onClick:()=>t.onCommand({type:"tabClose",tabId:j.tabId}),children:n.jsx(Ue,{size:13})})]},j.tabId)):n.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-inset px-3 py-1.5 text-[12px] text-ink-secondary",children:[n.jsx(lt,{size:13,"aria-hidden":"true"}),s("browser.panel.newTab")]}),n.jsx("button",{className:`${je} shrink-0`,disabled:!m,"aria-label":s("browser.panel.newTab"),title:s("browser.panel.newTab"),onClick:()=>t.onCommand({type:"tabNew"}),children:n.jsx(At,{size:16})})]}),n.jsxs("button",{type:"button","aria-pressed":T,"aria-label":`${mt[k](o)}. ${s(T?"browser.control.handBack":"browser.control.take")}`,"aria-description":C?t.hint:void 0,title:C&&t.hint?t.hint:s(T?"browser.control.handBack":"browser.control.take"),disabled:!u||k==="elsewhere"||k==="connecting"||k==="taking"||k==="waiting",onClick:T?t.onHandBack:t.onTake,className:`flex max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border px-2.5 py-1 text-[11px] disabled:cursor-default ${T?"border-accent-border bg-accent/15 text-accent-text":"border-hairline text-ink-secondary hover:bg-inset hover:text-ink"}`,"data-pill":k,children:[k==="taking"||k==="waiting"||k==="connecting"?n.jsx(Xe,{size:12,className:"shrink-0 animate-spin","aria-hidden":"true"}):n.jsx(Rt,{size:12,className:"shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"truncate",children:mt[k](o)}),k==="bot"||k==="watching"?n.jsxs("span",{className:"shrink-0 text-ink",children:["· ",s("browser.control.take")]}):T?n.jsxs("span",{className:"shrink-0",children:["· ",s("browser.control.handBack")]}):null]}),n.jsx("button",{className:je,title:s(t.maximized?"browser.panel.restore":"browser.panel.maximizeHint"),"aria-label":s(t.maximized?"browser.panel.restore":"browser.panel.maximize"),onClick:t.onMaximize,children:t.maximized?n.jsx(bn,{size:15}):n.jsx(Vt,{size:15})}),n.jsx("button",{className:je,title:s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreenHint"),"aria-label":s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreen"),onClick:t.onFullscreen,children:t.fullscreen?n.jsx(un,{size:15}):n.jsx(dn,{size:15})}),n.jsx("button",{className:`${je} rounded-xl bg-inset p-1.5`,title:s("browser.panel.profileTitle",{name:t.profileName}),"aria-label":s("browser.panel.profiles"),onClick:t.onProfiles,children:n.jsx(ln,{size:15})})]}),n.jsxs("form",{className:"relative flex h-10 items-center gap-1 px-2",onSubmit:j=>{j.preventDefault(),t.onAddress(d),(r&&typeof r=="object"?r.current:null)?.blur()},children:[n.jsxs("div",{className:"flex shrink-0 items-center",role:"group","aria-label":s("browser.panel.navigation"),children:[n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoBack,"aria-label":s("browser.panel.back"),title:s("browser.panel.back"),onClick:()=>t.onCommand({type:"history",delta:-1}),children:n.jsx(qt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoForward,"aria-label":s("browser.panel.forward"),title:s("browser.panel.forward"),onClick:()=>t.onCommand({type:"history",delta:1}),children:n.jsx(Gt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m,"aria-label":s(c.loading?"browser.panel.loadingReload":"browser.panel.reload"),title:s("browser.panel.reloadShort"),onClick:()=>t.onCommand({type:"reload"}),children:c.loading?n.jsx(Xe,{size:16,className:"animate-spin"}):n.jsx(Xt,{size:16})})]}),n.jsx("input",{ref:r,"aria-label":s("browser.panel.address"),readOnly:!m,value:y?d:b,onChange:j=>g(j.target.value),onFocus:j=>{g(b),E(!0),m&&queueMicrotask(()=>j.target.select())},onBlur:()=>E(!1),onKeyDown:j=>{j.key==="Escape"&&(j.preventDefault(),g(b),j.currentTarget.blur())},placeholder:s(u?"browser.panel.searchOrAddress":"browser.panel.connecting"),spellCheck:!1,className:"mx-1 min-w-0 flex-1 rounded-lg bg-transparent px-2 py-1.5 text-center text-[12px] outline-none placeholder:text-ink-secondary focus:bg-inset focus:text-left"}),t.menu,n.jsx("div",{"aria-hidden":"true","data-loading":c.loading,className:`pointer-events-none absolute bottom-0 left-0 h-0.5 bg-accent transition-[width,opacity] duration-500 ${c.loading?"w-2/3 opacity-100":"w-full opacity-0"}`})]})]})});function gn(e){return Array.isArray(e)?e.flatMap(t=>{const{id:r,name:o}=t??{};return typeof r=="string"&&typeof o=="string"?[{id:r,name:o}]:[]}):[]}const kn="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40";function vn({ready:e,extensions:t,onList:r,onOpen:o}){const i=a.useRef(null);return a.useEffect(()=>{e&&i.current?.open&&r()},[e]),n.jsxs("details",{ref:i,className:"relative shrink-0",onToggle:c=>{c.currentTarget.open&&e&&r()},children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.extensions.title"),title:s("browser.extensions.title"),children:n.jsx(Yt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex max-h-80 w-56 flex-col overflow-y-auto rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.extensions.title")}),e?t&&t.length===0?n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.empty")}):(t??[]).map(c=>n.jsx("button",{type:"button",role:"menuitem",className:kn,onClick:()=>{i.current?.removeAttribute("open"),o(c.id)},children:n.jsx("span",{className:"truncate",children:c.name})},c.id)):n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.takeControl")})]})]})}const _e=[.25,.33,.5,.67,.75,.8,.9,1,1.1,1.25,1.5,1.75,2,2.5,3,4,5];function bt(e,t){return t>0?_e.find(r=>r>e+.001)??_e.at(-1):[..._e].reverse().find(r=>r<e-.001)??_e[0]}const Cn=[{label:"browser.viewport.fill",setting:{mode:"fill"}},{label:"browser.viewport.fullHd",setting:{mode:"preset",preset:"fullHd"}},{label:"browser.viewport.desktop",setting:{mode:"preset",preset:"desktop"}},{label:"browser.viewport.tablet",setting:{mode:"preset",preset:"tablet"}},{label:"browser.viewport.phone",setting:{mode:"preset",preset:"phone"}}],xt=(e,t)=>e.mode===t.mode&&(e.mode!=="preset"||t.mode==="preset"&&e.preset===t.preset),Ae="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40",Qe="rounded-md border border-hairline p-1 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40";function Sn({stream:e,ready:t,typing:r,setting:o,zoom:i,pip:c,onViewport:u,onZoom:w,onPip:v,onType:m,onSecret:d,onReconnect:g,onRestart:y}){const E=a.useRef(null),k=T=>()=>{E.current?.removeAttribute("open"),T()},C=T=>n.jsx("div",{className:"border-b border-hairline/40 py-1 last:border-b-0",children:T});return n.jsxs("details",{ref:E,className:"relative shrink-0",children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.panel.menu"),title:s("browser.panel.menu"),children:n.jsx(Jt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex w-56 flex-col rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[e?C(n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.viewport.title")}),Cn.map(T=>n.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":xt(T.setting,o),className:Ae,disabled:!t,onClick:k(()=>u(T.setting)),children:[n.jsx("span",{className:"w-3.5 shrink-0",children:xt(T.setting,o)?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null}),s(T.label)]},T.label)),n.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[n.jsx("span",{children:s("settings.profile.avatar.zoom")}),n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.out"),disabled:!t||i<=_e[0],onClick:()=>w(bt(i,-1)),children:n.jsx(Zt,{size:12})}),n.jsxs("span",{className:"min-w-11 text-center tabular-nums text-ink-secondary","aria-live":"polite",children:[Math.round(i*100),"%"]}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.in"),disabled:!t||i>=_e.at(-1),onClick:()=>w(bt(i,1)),children:n.jsx(At,{size:12})}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.reset"),disabled:!t||i===1,onClick:()=>w(1),children:n.jsx(Qt,{size:12})})]})]})]})):null,C(n.jsxs(n.Fragment,{children:[e&&c?n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(v),children:s(c.open?"browser.pip.close":"browser.pip.open")}):null,n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(m),children:s("browser.panel.typeTextMenu")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(d),children:s("browser.typeSecret")})]})),C(n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(g),children:s("browser.panel.reconnectView")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(y),children:s("browser.panel.restartBrowser")})]}))]})]})}function jn(e){const[t,r]=a.useState(null);return a.useEffect(()=>{if(!e)return;let o=!0;return Ge("/api/shared-computers").then(i=>{o&&r(i.computers?.find(c=>c.online&&c.scopes?.screen)?.name??null)}).catch(()=>{}),()=>{o=!1}},[e]),t}function En({wall:e,botName:t,onDismiss:r}){const{state:o,dispatch:i}=dt(),c=o.config?.cloudHome===!0,u=jn(c),w=e==="google"?"Google":"Microsoft";return n.jsx("section",{role:"status","aria-label":s("browser.passkey.title"),className:"shrink-0 border-b border-hairline/30 bg-inset/60 px-3 py-2.5 text-[12px] leading-relaxed text-ink-secondary",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(en,{size:14,className:"mt-0.5 shrink-0 text-accent-text","aria-hidden":"true"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium text-ink",children:s("browser.passkey.title")}),n.jsx("p",{children:s("browser.passkey.body",{provider:w})}),n.jsxs("ol",{className:"mt-1 list-decimal space-y-1 pl-4",children:[n.jsxs("li",{children:[s(e==="google"?"browser.passkey.appsGoogle":"browser.passkey.appsMicrosoft",{name:t})," ",n.jsx("button",{type:"button",className:"text-accent-text underline",onClick:()=>i({type:"togglePlugins",open:!0,surface:"apps"}),children:s("browser.passkey.connect")})]}),n.jsx("li",{children:s(e==="google"?"browser.passkey.otherWayGoogle":"browser.passkey.otherWayMicrosoft")}),c&&n.jsx("li",{children:u?s("browser.passkey.lentPc",{computer:u,name:t}):s("browser.passkey.lendPc",{name:t})})]}),n.jsx("button",{type:"button",className:"mt-1 text-accent-text underline",onClick:()=>{tn(nn)},children:s("browser.passkey.learnMore")})]}),n.jsx("button",{type:"button",className:"rounded-md p-1 text-ink-tertiary hover:bg-inset hover:text-ink","aria-label":s("browser.passkey.dismiss"),onClick:r,children:n.jsx(Ue,{size:14})})]})})}const Nn=4503,Pn=4404,Tn="sudo limixbot browser install --with-deps",Mn="https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox",ft=(e,t)=>{const r=Object.entries(t.query);if(r.length===0)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${new URLSearchParams(r).toString()}`};function Lt(e,t=window.location,r={}){const o=`/api/bots/${encodeURIComponent(e)}/browser`;return{httpBase:`${t.protocol}//${t.host}${o}`,wsBase:`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}${o}`,query:{...r},credentials:!0}}const Rn=e=>e===null||typeof e=="object"&&"type"in e&&typeof e.type=="string"&&"message"in e&&typeof e.message=="string"&&"defaultValue"in e&&typeof e.defaultValue=="string",In=(e,t)=>ft(`${e.access.httpBase}/upload?${new URLSearchParams({chooser:t}).toString()}`,e.access);async function zn(e,t){const r=new FormData;for(const i of t)r.append("file",i,i.name??"file");const o=await fetch(e.uploadUrl,{method:"POST",body:r,credentials:e.credentials?"include":"omit"});if(!o.ok){const i=await o.text();let c=i;try{c=JSON.parse(i).error??i}catch{}throw new Error(c||s("browser.page.uploadRefused"))}}const An=(e,t)=>ft(`${e.access.httpBase}/download/${encodeURIComponent(t)}`,e.access),et=e=>(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0),Ln=(e,t)=>e.type==="takeControl"||e.type==="resize"||e.type==="frameCap"||e.type==="restart"||e.type==="wake"||e.type==="releaseControl"&&t.owned===!0||t.controller==="you",_n=JSON.stringify({type:"ack"});function _t(e,t){let r={width:e.maxWidth,height:e.maxHeight},o=e.width!==void 0&&e.height!==void 0?{width:e.width,height:e.height}:null;const i=()=>{const y=new URLSearchParams({maxWidth:String(Math.max(1,Math.round(r.width))),maxHeight:String(Math.max(1,Math.round(r.height)))});return o&&(y.set("width",String(Math.round(o.width))),y.set("height",String(Math.round(o.height)))),e.interactive===!1&&y.set("interactive","false"),ft(`${e.access.wsBase}/stream?${y.toString()}`,e.access)};let c=!1,u=null,w=null,v=0,m=null,d=null;const g=()=>{if(c)return;const y={cap:r,size:o},E=new WebSocket(i());E.binaryType="arraybuffer",u=E;let k=!1;E.addEventListener("open",()=>{u===E&&(k=!0,t.onConnectedChange(!0))}),E.addEventListener("message",C=>{if(u!==E)return;if(C.data instanceof ArrayBuffer){v=0,E.send(_n),t.onFrame(C.data);return}if(typeof C.data!="string")return;let T;try{T=JSON.parse(C.data)}catch{return}if(typeof T!="object"||T===null)return;const{type:b,x:j,y:O,width:H,height:le,editable:re,canOperate:J,controller:Y,generation:$,dialog:x,stale:K,owned:B,text:V,id:Z,fileName:W,sizeBytes:te,multiple:P,accept:R,phase:D,sequence:U,tabId:q}=T;if(b==="fileChooser"&&typeof Z=="string"&&typeof P=="boolean"&&typeof R=="string")d=Z,t.onFileChooser?.({multiple:P,accept:R,uploadUrl:In(e,Z),credentials:e.access.credentials});else if(b==="fileChooserClosed"&&typeof Z=="string"){if(d!==Z)return;d=null,t.onFileChooser?.(null)}else if(b==="pointer"&&(D==="move"||D==="click")&&typeof j=="number"&&typeof O=="number"&&typeof U=="number")t.onPointer?.({phase:D,x:j,y:O,sequence:U});else if(b==="popup"&&typeof q=="string")t.onPopup?.(q);else if(b==="clipboard"&&typeof V=="string")t.onClipboard?.(V);else if(b==="download"&&typeof Z=="string"&&typeof W=="string"&&typeof te=="number")t.onDownload?.({fileName:W,sizeBytes:te,url:An(e,Z)});else if(b==="viewport"&&typeof H=="number"&&typeof le=="number")v=0,t.onViewport({width:H,height:le}),t.onMessage?.(T);else if(b==="probe"&&typeof j=="number"&&typeof O=="number"&&typeof re=="boolean")t.onProbe?.({x:j,y:O,editable:re});else if(b==="control"&&typeof J=="boolean"&&(Y==="agent"||Y==="you"||Y==="another-viewer"||Y==="unclaimed")&&typeof $=="number"&&Rn(x)){const N={canOperate:J,controller:Y,generation:$,dialog:x,...K===!0?{stale:!0}:{},...B===!0?{owned:!0}:{}},A=m===null;m=N,A&&J&&r!==y.cap&&E.send(JSON.stringify({type:"frameCap",maxWidth:r.width,maxHeight:r.height})),A&&J&&o&&o!==y.size&&E.send(JSON.stringify({type:"resize",...o})),t.onControl?.(N)}else typeof b=="string"&&t.onMessage?.(T)}),E.addEventListener("close",C=>{if(u===E&&(u=null,m=null,k&&t.onConnectedChange(!1),!c)){if(t.onClose?.(C.code,C.reason),C.code===Pn){c=!0,t.onGone?.();return}if(C.code===Nn){c=!0,t.onHostSetup?.(Bn(C.reason));return}if(C.code===1008||C.code===4401||!k&&C.code===1006){c=!0,t.onUnauthorized();return}w=setTimeout(g,Math.min(500*2**v++,1e4))}}),E.addEventListener("error",()=>E.close())};return g(),{send:y=>(y.type==="resize"?o={width:y.width,height:y.height}:y.type==="frameCap"&&(r={width:y.maxWidth,height:y.maxHeight}),u?.readyState!==WebSocket.OPEN||!m?.canOperate||!Ln(y,m)?!1:(u.send(JSON.stringify(y)),!0)),stop:()=>{c=!0,w!==null&&clearTimeout(w);const y=u;u=null,m=null,y?.close()}}}function Bt(e,t){const r=e.getContext("2d");let o=!1,i=!1,c=null;const u=w=>{i=!0,createImageBitmap(new Blob([w],{type:"image/jpeg"})).then(v=>{if(o||!r){v.close();return}(e.width!==v.width||e.height!==v.height)&&(e.width=v.width,e.height=v.height),r.drawImage(v,0,0),v.close(),t?.()}).catch(()=>{}).finally(()=>{i=!1;const v=c;c=null,v&&!o&&u(v)})};return{paint:w=>{o||(i?c=w:u(w))},stop:()=>{o=!0,c=null}}}const Bn=e=>{try{if(JSON.parse(e).need==="libraries")return{need:"libraries",command:Tn}}catch{}return{need:"sandbox"}},On=e=>e.need==="sandbox"?"This server's host blocks the sandbox its browser runs in. An administrator can allow it for one copy of Chrome with these steps, then try again:":"This server's host is missing libraries its browser needs. Run this once on the host, then try again:",Dn=700;function Hn(e,t){return e?1:t==="human"?.18:.35}function Fn({phase:e,sequence:t,left:r,top:o,controller:i}){const[c,u]=a.useState(null),w=c!==t;return a.useEffect(()=>{const v=window.setTimeout(()=>u(t),Dn);return()=>window.clearTimeout(v)},[t]),n.jsxs("div",{className:"pointer-events-none absolute left-0 top-0 z-30 transition-[opacity,transform] duration-150 ease-out motion-reduce:transition-none",style:{opacity:Hn(w,i),transform:`translate3d(${r}px, ${o}px, 0)`},"aria-hidden":"true","data-agent-cursor":!0,children:[e==="click"?n.jsx("span",{className:"absolute left-0.5 top-0.5 size-4 animate-ping rounded-full bg-accent/25 motion-reduce:animate-none"},t):null,n.jsx(hn,{className:"relative size-5 -translate-x-0.5 -translate-y-0.5 fill-card text-accent drop-shadow-sm",strokeWidth:2})]})}function $n({origin:e,realm:t,onAnswer:r}){const o=i=>{i.preventDefault();const c=i.currentTarget,u=c.elements.namedItem("username"),w=c.elements.namedItem("password");r({username:u.value,password:w.value}),u.value="",w.value=""};return n.jsxs("form",{role:"dialog","aria-label":s("browser.auth.label"),onSubmit:o,className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2.5 rounded-xl border border-hairline/60 bg-card p-4 text-ink shadow-xl",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-medium",children:[n.jsx(It,{size:14,"aria-hidden":"true"}),s("browser.auth.signIn")]}),n.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t?s("browser.auth.asks",{origin:e,realm:t}):e}),n.jsx("input",{name:"username","aria-label":s("browser.auth.username"),autoComplete:"off",spellCheck:!1,maxLength:1024,placeholder:s("browser.auth.username"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsx("input",{name:"password",type:"password","aria-label":s("logins.password"),autoComplete:"new-password",maxLength:1024,placeholder:s("logins.password"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:()=>r(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",children:s("common.cancel")}),n.jsx("button",{type:"submit",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",children:s("browser.auth.signIn")})]})]})}function Un({options:e,selectedIndex:t,anchor:r,bounds:o,onChoose:i,onClose:c}){const[u,w]=a.useState(()=>t>=0?t:e.findIndex(b=>!b.disabled)),v=a.useRef(null);a.useEffect(()=>{v.current?.focus({preventScroll:!0})},[]),a.useEffect(()=>{v.current?.querySelector(`[data-index="${u}"]`)?.scrollIntoView?.({block:"nearest"})},[u]);const m=o.height-(r.top+r.height),d=r.top,g=m<160&&d>m,y=Math.max(96,Math.min(320,(g?d:m)-8)),E=Math.max(0,Math.min(r.left,o.width-Math.max(r.width,160))),k=(b,j)=>{for(let O=b+j;O>=0&&O<e.length;O+=j)if(!e[O].disabled)return O;return b},C=b=>{b.key==="ArrowDown"||b.key==="ArrowUp"?(b.preventDefault(),w(j=>k(j,b.key==="ArrowDown"?1:-1))):b.key==="Home"||b.key==="End"?(b.preventDefault(),w(b.key==="Home"?k(-1,1):k(e.length,-1))):b.key==="Enter"||b.key===" "?(b.preventDefault(),e[u]&&!e[u].disabled&&i(u)):(b.key==="Escape"||b.key==="Tab")&&(b.preventDefault(),b.stopPropagation(),c())};let T;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"absolute inset-0 z-30","aria-hidden":"true",onPointerDown:b=>{b.preventDefault(),c()}}),n.jsx("div",{ref:v,role:"listbox","aria-label":s("browser.select.label"),"aria-activedescendant":u>=0?`select-option-${u}`:void 0,tabIndex:0,onKeyDown:C,onBlur:b=>{b.currentTarget.contains(b.relatedTarget)||c()},className:"absolute z-40 overflow-y-auto rounded-lg border border-hairline/60 bg-menu py-1 text-[13px] text-ink shadow-xl outline-none",style:{left:E,minWidth:Math.max(r.width,160),maxHeight:y,...g?{bottom:o.height-r.top+2}:{top:r.top+r.height+2}},children:e.map((b,j)=>{const O=b.group!==void 0&&b.group!==T?b.group:null;return T=b.group,n.jsxs("div",{children:[O!==null?n.jsx("div",{className:"px-3 pb-0.5 pt-1.5 text-[11px] font-medium text-ink-tertiary",role:"presentation",children:O}):null,n.jsxs("div",{id:`select-option-${j}`,"data-index":j,role:"option","aria-selected":j===t,"aria-disabled":b.disabled||void 0,onPointerEnter:()=>{b.disabled||w(j)},onPointerDown:H=>H.preventDefault(),onClick:()=>{b.disabled||i(j)},className:`flex cursor-default items-center gap-2 px-3 py-1.5 ${b.group!==void 0?"pl-5":""} ${b.disabled?"text-ink-tertiary":j===u?"bg-accent text-accent-ink":""}`,children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label||" "}),j===t?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null]})]},j)})})]})}const wt=150,Wn=24,Kn=1e4,$e="​",Vn={key:"Backspace",code:"Backspace",keyCode:8},qn={key:"Delete",code:"Delete",keyCode:46},Gn=8,Xn=500,Yn=4,Jn=16,yt=e=>e===0?"left":e===1?"middle":e===2?"right":"none",gt=e=>e&1?"left":e&2?"right":e&4?"middle":"none",Le=e=>e!==null&&e.canOperate&&e.controller!=="another-viewer";function Ot(e,t){const r=Math.min(e.width/t.width,e.height/t.height),o=t.width*r,i=t.height*r;return{width:o,height:i,left:(e.width-o)/2,top:(e.height-i)/2}}function Zn(e,t,r,o,i,c){const u=Ot(e,t);if(!(u.width>0&&u.height>0))return null;const w=r.width/u.width,v=(o-e.left-u.left)*w,m=(i-e.top-u.top)*(r.height/u.height);return!(v>=0&&m>=0&&v<=r.width&&m<=r.height)&&!c?null:{x:Math.min(Math.max(v,0),r.width),y:Math.min(Math.max(m,0),r.height),scale:w}}function kt(e,t,r,o){const i=Ot(t,r),c=i.width/o.width,u=i.height/o.height;return{left:i.left+e.x*c,top:i.top+e.y*u,width:e.width*c,height:e.height*u}}function Qn(e){const t=document.createElement("a");t.href=e.url,t.download=e.fileName,t.rel="noopener",t.click()}function er(e){const{connect:t,ref:r}=e,o=a.useRef(e);o.current=e;const i=a.useRef(null),c=a.useRef(null),u=a.useRef(!1),w=a.useRef(null),v=a.useRef(null),m=a.useRef(null),d=a.useRef(!1),g=a.useRef(null),[y,E]=a.useState(null),[k,C]=a.useState(!1),[T,b]=a.useState(!1),[j,O]=a.useState(""),[H,le]=a.useState(null),[re,J]=a.useState(null),[Y,$]=a.useState(null),[x,K]=a.useState("default"),[B,V]=a.useState(null),[Z,W]=a.useState([]),[te,P]=a.useState(null),R=a.useRef(0),D=a.useRef(null),U=a.useRef(null),q=a.useRef(null),N=a.useRef(null),A=a.useRef(0),G=a.useRef({left:1,middle:1,right:1,none:1}),ie=a.useRef(null),pe=a.useRef(null),F=a.useRef(null),Ee=a.useRef(null),Oe=a.useRef(null),[We,Ke]=a.useState(!1),Ne=a.useCallback(l=>{const p=++R.current;W(S=>[...S.slice(-2),{...l,id:p}])},[]),ue=l=>W(p=>p.filter(S=>S.id!==l)),Q=a.useCallback(l=>{o.current.input(l)},[]),Re=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null,U.current=q.current=null,A.current=0,G.current={left:1,middle:1,right:1,none:1},ie.current=null,pe.current=F.current=Ee.current=null,u.current=!1,c.current&&(c.current.value=$e)},[]),be=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null;const l=U.current,p=q.current;U.current=null,q.current=null,l&&Q(l),p&&Q(p)},[Q]),ve=a.useCallback(()=>{N.current??=requestAnimationFrame(be)},[be]),de=a.useCallback((l,p,S,z)=>{const I=q.current;q.current={type:"wheel",x:l.x,y:l.y,deltaX:(I?.deltaX??0)+p,deltaY:(I?.deltaY??0)+S,modifiers:z},ve()},[ve]),he=a.useCallback((l,p,S)=>{const z=i.current,I=v.current;return!z||!I||!d.current||!Le(g.current)?null:Zn(z.getBoundingClientRect(),z,I,l,p,S)},[]),Ie=(l,p,S,z)=>{const I=ie.current,X=I&&I.button===l&&z-I.time<Xn&&Math.hypot(p-I.x,S-I.y)<Yn?I.count+1:1;return ie.current={button:l,time:z,x:p,y:S,count:X},X},ee=()=>c.current?.focus({preventScroll:!0});a.useImperativeHandle(r,()=>({canvas:()=>d.current?i.current:null,focusPage:ee}),[]),a.useEffect(()=>{const l=i.current?.parentElement;if(!l||typeof ResizeObserver>"u")return;let p=null,S=null;const z=()=>{S=null;const f=m.current;if(!f)return;const M=window.devicePixelRatio||1,se=Math.round(f.width*M),ye=Math.round(f.height*M),ae=Oe.current;if(ae!==null&&ae.width>=se&&ae.height>=ye)return;const _={width:Math.max(se,ae?.width??0),height:Math.max(ye,ae?.height??0)};Oe.current=_,ae===null?Ke(!0):w.current?.send({type:"frameCap",maxWidth:_.width,maxHeight:_.height})},I=()=>{p=null;const f=l.getBoundingClientRect();if(f.width<1||f.height<1)return;const M={width:Math.round(f.width),height:Math.round(f.height)},se=m.current;se?.width===M.width&&se.height===M.height||(m.current=M,w.current?.send({type:"resize",...M}),S!==null&&clearTimeout(S),S=setTimeout(z,se===null?0:wt*2))},X=new ResizeObserver(()=>{p===null&&(p=setTimeout(I,m.current===null?0:wt))});return X.observe(l),()=>{X.disconnect(),p!==null&&clearTimeout(p),S!==null&&clearTimeout(S)}},[]),a.useEffect(()=>{const l=i.current,p=m.current,S=Oe.current;if(te||!We||!S||!l||!p)return;d.current=!1,b(!1);const z=Bt(l,()=>{d.current||(d.current=!0,b(!0),o.current.onFirstFrame?.())}),I=f=>{const M=g.current;g.current=f,E(f),o.current.onControl?.(f),(f?.dialog?.message!==M?.dialog?.message||f?.dialog?.defaultValue!==M?.dialog?.defaultValue)&&O(f?.dialog?.defaultValue??""),f?.controller!=="you"?$(null):M?.controller!=="you"&&m.current&&w.current?.send({type:"resize",...m.current}),Le(f)||(Re(),c.current?.blur())},X=t({maxWidth:S.width,maxHeight:S.height,width:p.width,height:p.height},{onFrame:f=>z.paint(f),onProbe:f=>{if(g.current?.controller!=="you")return;Ee.current={...f,at:performance.now()};const M=F.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(F.current=null,f.editable?c.current?.focus({preventScroll:!0}):c.current?.blur()))},onPointer:f=>{const M=i.current,se=v.current;if(!M||!se||M.width<1||M.height<1)return;const ye={width:M.clientWidth,height:M.clientHeight},ae=kt({x:f.x,y:f.y,width:0,height:0},ye,M,se);J({...ae,phase:f.phase,sequence:f.sequence})},onClipboard:f=>{ht(f).then(M=>{M==="failed"&&Ne({kind:"clipboard",text:f})})},onDownload:f=>Ne({kind:"download",download:f}),onPopup:()=>{},onFileChooser:le,onViewport:f=>{v.current=f},onControl:I,onMessage:f=>{if(f.type==="selectPopup"&&typeof f.id=="string"&&Array.isArray(f.options)){const M=f.rect;M&&$({id:f.id,options:f.options,selectedIndex:Number(f.selectedIndex),rect:M})}else f.type==="cursor"&&typeof f.shape=="string"?K(f.shape):f.type==="authPrompt"&&typeof f.tabId=="string"&&typeof f.id=="string"&&typeof f.origin=="string"?V({tabId:f.tabId,id:f.id,origin:f.origin,realm:typeof f.realm=="string"?f.realm:""}):f.type==="authPromptClosed"?V(M=>M&&M.id!==f.id?M:null):f.type==="notice"&&typeof f.message=="string"&&Ne({kind:"error",message:Kt(f,f.message)});o.current.onMessage?.(f)},onConnectedChange:f=>{C(f),o.current.onConnectedChange?.(f),!f&&(le(null),$(null),V(null),I(null))},onHostSetup:P,onUnauthorized:()=>o.current.onUnauthorized?.(),onGone:()=>o.current.onGone?.(),onClose:(f,M)=>o.current.onClose?.(f,M)});return w.current=X,o.current.onClient?.(X),()=>{z.stop(),X.stop(),w.current===X&&(w.current=null),o.current.onClient?.(null),I(null),C(!1),J(null),Re()}},[We,Re,t,te,Ne]),a.useEffect(()=>{const l=i.current;if(!l)return;const p=S=>{const z=he(S.clientX,S.clientY,!1);if(!z)return;S.preventDefault();const I=S.deltaMode===WheelEvent.DOM_DELTA_LINE?Jn:S.deltaMode===WheelEvent.DOM_DELTA_PAGE?v.current?.height??0:1;de(z,S.deltaX*I,S.deltaY*I,et(S))};return l.addEventListener("wheel",p,{passive:!1}),()=>l.removeEventListener("wheel",p)},[he,de]),a.useEffect(()=>()=>{N.current!==null&&cancelAnimationFrame(N.current)},[]);const Ce=l=>{if(!Le(g.current))return;const{type:p,pointerId:S,clientX:z,clientY:I}=l,X=p==="pointercancel",f=pe.current;if(X&&f?.pointerId===S){pe.current=F.current=null;return}if(l.pointerType==="touch"&&!X){const _=he(z,I,p==="pointermove");if(p==="pointerdown"){if(!l.isPrimary)return;pe.current={pointerId:S,startX:z,startY:I,lastX:z,lastY:I,panning:!1};const Se=Ee.current,Te=_&&Se&&performance.now()-Se.at<Kn&&Math.hypot(_.x-Se.x,_.y-Se.y)<Wn;F.current=_?{x:_.x,y:_.y,editable:Te?Se.editable:null,answered:!1,tapped:!1}:null,_&&Q({type:"probe",x:_.x,y:_.y});return}if(!f||f.pointerId!==S)return;if(p==="pointermove"){if(!f.panning&&Math.hypot(z-f.startX,I-f.startY)<Gn)return;f.panning=!0,_&&de(_,(f.lastX-z)*_.scale,(f.lastY-I)*_.scale,0),f.lastX=z,f.lastY=I;return}pe.current=null;const oe=F.current;if(f.panning){F.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:F.current=null,be();const ge=Ie("left",z,I,l.timeStamp),ne={x:_.x,y:_.y,modifiers:0};Q({type:"mouse",action:"move",...ne,button:"none",buttons:0,clickCount:0}),Q({type:"mouse",action:"down",...ne,button:"left",buttons:1,clickCount:ge}),Q({type:"mouse",action:"up",...ne,button:"left",buttons:0,clickCount:ge});return}const M=A.current;if((X||p==="pointerup")&&M===0)return;(X||p==="pointerup")&&(A.current=X?0:l.buttons&7);const se=he(z,I,p!=="pointerdown"&&(X||p==="pointerup"||M!==0||l.buttons!==0));if(!se)return;const ye={x:se.x,y:se.y,modifiers:et(l)},ae=(_,oe,ge)=>{_==="down"&&(G.current[oe]=Ie(oe,z,I,l.timeStamp)),Q({type:"mouse",action:_,...ye,button:oe,buttons:ge,clickCount:G.current[oe]})};if(p==="pointerdown")ee(),l.currentTarget.setPointerCapture(S),be(),A.current=l.buttons&7,ae("down",yt(l.button),l.buttons);else if(p==="pointerup")be(),ae("up",yt(l.button),l.buttons);else{const _=X?0:l.buttons&7,oe=M^_;if(M!==0&&oe!==0){be();let ge=M;for(const ne of[1,2,4])oe&ne&&(ge^=ne,ae(_&ne?"down":"up",gt(ne),ge));A.current=_}if(X)return;U.current={type:"mouse",action:"move",...ye,button:gt(l.buttons),buttons:l.buttons,clickCount:0},ve()}},ze=l=>{u.current=!1,l.value=$e,l.setSelectionRange($e.length,$e.length)},De=l=>{Q({type:"key",action:"down",...l,modifiers:0}),Q({type:"key",action:"up",...l,modifiers:0})},He=(l,p)=>{if(!Le(g.current)||(u.current=!1,p.nativeEvent.isComposing||p.keyCode===229||p.key==="Process"||p.key==="Unidentified"))return;if(p.key==="Escape"&&p.shiftKey){p.preventDefault(),p.stopPropagation(),l==="down"&&(p.currentTarget.blur(),o.current.onLeave?.());return}const S=p.ctrlKey||p.metaKey;if(S&&p.key.toLowerCase()==="v"||p.shiftKey&&p.key==="Insert")return;const z=S?void 0:[...p.key].length===1?p.key:p.key==="Enter"?"\r":void 0;Q({type:"key",action:l,key:p.key,code:p.code,keyCode:p.keyCode,...l==="down"&&z!==void 0?{text:z}:{},modifiers:et(p)}),u.current=l==="down"&&!S&&(z!==void 0||p.key==="Backspace"||p.key==="Delete"),!S&&(p.preventDefault(),p.stopPropagation())},Fe=l=>{const p=l.nativeEvent;if(p instanceof InputEvent&&p.isComposing)return;const S=l.currentTarget,z=p instanceof InputEvent?p.inputType:"";if(u.current)u.current=!1;else if(z==="deleteContentBackward")De(Vn);else if(z==="deleteContentForward")De(qn);else{const I=S.value.replace(/^​/,"");I&&Q({type:"text",text:I})}ze(S)},xe=l=>{const p=H;p&&(le(null),zn(p,l).catch(S=>Ne({kind:"error",message:s("browser.page.uploadFailed",{error:S instanceof Error?S.message:String(S)})})))},me=l=>w.current?.send(l),ce=i.current,we=Y&&ce&&v.current&&ce.width>0?kt(Y.rect,{width:ce.clientWidth,height:ce.clientHeight},ce,v.current):null,Pe=y?.controller==="you";return n.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden ${e.className??""}`,"data-browser-surface":!0,children:[n.jsxs("div",{className:"relative min-h-0 flex-1",children:[n.jsx("canvas",{ref:i,"aria-hidden":"true",className:"block size-full touch-none object-contain",style:{cursor:Le(y)?Pe?x:"default":"not-allowed"},onPointerDown:Ce,onPointerMove:Ce,onPointerUp:Ce,onPointerCancel:Ce,onMouseDown:l=>l.preventDefault(),onContextMenu:l=>l.preventDefault()}),re&&!Pe?n.jsx(Fn,{...re,controller:y?.controller==="agent"?"agent":"none"}):null,n.jsx("textarea",{ref:c,"aria-label":e.label??s("browser.page.label"),"aria-description":s("browser.page.keysHint"),"aria-keyshortcuts":"Shift+Escape",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:!Le(y),defaultValue:$e,onFocus:l=>ze(l.currentTarget),className:"sr-only left-0 top-0 text-base",onKeyDown:l=>He("down",l),onKeyUp:l=>He("up",l),onInput:Fe,onCompositionEnd:l=>{const p=l.data.replace(/^​/,"");p&&Q({type:"text",text:p}),ze(l.currentTarget)},onCopy:l=>l.preventDefault(),onCut:l=>l.preventDefault(),onPaste:l=>{l.preventDefault();const p=l.clipboardData.getData("text/plain");p&&Q({type:"text",text:p})}}),k&&!T&&!te?n.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center text-ink-secondary","aria-hidden":"true",children:n.jsx(Xe,{size:22,className:"animate-spin"})}):null,Y&&we&&ce?n.jsx(Un,{options:Y.options,selectedIndex:Y.selectedIndex,anchor:we,bounds:{width:ce.clientWidth,height:ce.clientHeight},onChoose:l=>{me({type:"selectChoose",id:Y.id,index:l}),$(null),ee()},onClose:()=>{$(null),ee()}},Y.id):null,H&&Pe?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.page.chooseFilesLabel"),children:[n.jsxs("p",{className:"flex items-center gap-2 text-[13px]",children:[n.jsx(fn,{size:14,"aria-hidden":"true"}),s(H.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:H.multiple,accept:H.accept,onChange:l=>{const p=[...l.currentTarget.files??[]];l.currentTarget.value="",p.length>0&&xe(p)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>xe([]),children:s("common.cancel")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>D.current?.click(),children:s(H.multiple?"browser.page.chooseFiles":"browser.page.chooseFile")})]})]}):null,y?.dialog&&y.controller!=="another-viewer"?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.dialog.label"),children:[n.jsx("p",{className:"break-words text-[13px]",children:y.dialog.message}),Pe?n.jsxs(n.Fragment,{children:[y.dialog.type==="prompt"?n.jsx("input",{"aria-label":s("browser.dialog.response"),value:j,onChange:l=>O(l.target.value),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}):null,n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>me({type:"dialog",accept:!1}),children:s("browser.dialog.dismiss")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>me({type:"dialog",accept:!0,...y.dialog?.type==="prompt"?{promptText:j}:{}}),children:s("browser.dialog.accept")})]})]}):n.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("browser.dialog.takeControl")})]}):null,B&&Pe?n.jsx($n,{origin:B.origin,realm:B.realm,onAnswer:l=>{const p={tabId:B.tabId,id:B.id};me(l?{type:"authAnswer",...p,username:l.username,password:l.password}:{type:"authAnswer",...p}),V(null)}}):null,Z.length?n.jsx("div",{className:"absolute inset-x-3 bottom-3 z-20 flex flex-col items-center gap-2",role:"status",children:Z.map(l=>n.jsxs("div",{className:"flex max-w-full items-center gap-2 rounded-xl border border-hairline/60 bg-card px-3 py-2 text-[12px] text-ink shadow-lg",children:[l.kind==="download"?n.jsxs(n.Fragment,{children:[n.jsx(rn,{size:13,"aria-hidden":"true",className:"shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.downloaded",{name:l.download.fileName})}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{Qn(l.download),ue(l.id)},children:s("common.save")})]}):l.kind==="clipboard"?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.copied")}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{ht(l.text),ue(l.id)},children:s("common.copy")})]}):n.jsx("span",{role:"alert",className:"min-w-0 text-danger",children:l.message}),n.jsx("button",{type:"button","aria-label":s("browser.dialog.dismiss"),className:"shrink-0 rounded-md p-0.5 text-ink-secondary hover:bg-inset",onClick:()=>ue(l.id),children:n.jsx(Ue,{size:12})})]},l.id))}):null]}),te?n.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center",children:[n.jsx("p",{role:"alert",className:"max-w-sm text-[13px] text-ink-secondary",children:On(te)}),te.need==="libraries"?n.jsx("code",{className:"max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink",children:te.command}):n.jsx("a",{href:Mn,target:"_blank",rel:"noopener noreferrer",className:"text-[12px] text-ink underline",children:"Browser sandbox setup steps"}),n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:()=>P(null),children:s("common.tryAgain")})]}):null]})}const tr=8e3,nr=300,rr=2e4,sr=16,Dt=new Set(["Alt","Control","Meta","Shift"]),or=new Set(["Backspace","Enter","Tab","Escape","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]),qe=new Set(["navigate","history","reload","tabSelect","tabNew","tabClose"]),ar=new Set(["navigate","tabNew"]);function tt(e){return qe.has(e.type)?!0:e.type==="mouse"?e.action==="down":e.type==="key"?e.action==="down"&&!Dt.has(e.key):e.type==="wheel"||e.type==="text"}const nt=e=>e.type==="key"?`key:${e.code||e.key}`:e.type==="mouse"?`mouse:${e.button}`:e.type,vt=e=>(e.type==="key"||e.type==="mouse")&&e.action==="down",Ct=e=>(e.type==="key"||e.type==="mouse")&&e.action==="up";function lr(e){return e.type!=="key"||Dt.has(e.key)?!0:or.has(e.key)?!1:!e.modifiers||e.modifiers===8&&[...e.key].length===1}function ir(e){const t=e.transport;let r="bot",o="",i=[],c=!1,u=!1,w=!1,v=!1,m=!1,d=!1,g=0,y=Promise.resolve(),E,k;const C=new Set,T=new Set,b=x=>{o=x,e.onTakeStatus(x)},j=x=>{vt(x)&&lr(x)?C.add(nt(x)):Ct(x)&&C.delete(nt(x))},O=()=>!u&&!w&&(m||!v)&&!c&&!C.size&&(r==="held"||r==="bot"&&e.owned()),H=()=>{clearTimeout(E),E=u?void 0:setTimeout(()=>{E=void 0,re()},m?0:tr)},le=()=>{r="releasing",o==="stale"&&b(""),y=y.then(()=>u?void 0:t.release()).catch(()=>{}).then(()=>{r==="releasing"&&(r="bot")})},re=async()=>{if(!O())return;const x=g;await t.drain(),x===g&&O()&&le()},J=()=>{const x=i.filter(B=>ar.has(B.type)),K=i.some(B=>!x.includes(B)&&tt(B));i=x;for(const B of C)T.add(B);return C.clear(),K},Y=async()=>{c=!0;try{for(let x=i.shift();x&&!u;x=i.shift())t.send(x),t.size()>=sr&&await t.settle()}finally{c=!1,i=[]}},$=()=>{r="taking",e.onError(""),b("pending"),clearTimeout(k),k=setTimeout(()=>{!u&&r==="taking"&&b("slow")},nr),y=y.then(async()=>{if(u)return;const x=await t.take().then(K=>({reply:K}),K=>(u||e.onError(K instanceof Error?K.message:String(K)),null));clearTimeout(k),!u&&(x?(r="held",b(x.reply?.waited===!0&&J()?"stale":""),await Y()):(b(""),r="bot",i=[],C.clear()),H())}).catch(()=>{})};return{interact(x){if(u)return;const K=nt(x);if(Ct(x)&&T.delete(K))return;vt(x)&&T.delete(K);const B=r==="taking"||c;if(r!=="held"&&!B){if(!tt(x))return;if(t.stopped()&&!qe.has(x.type)){e.onHalted();return}}if(!(qe.has(x.type)&&B&&i.some(V=>qe.has(V.type)))){if(tt(x)&&(m=!1,o==="stale"&&b("")),j(x),g++,H(),r==="held"&&!B){t.send(x);return}i.push(x),B||$()}},observe(){if(u)return;const x=e.owned();d&&!x&&r==="held"&&!c&&(r="bot",C.clear(),T.clear(),clearTimeout(E),E=void 0),d=x,E===void 0&&x&&H()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||H())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,H()}},hold(x){u||w===x||(w=x,x||H())},leave(){!O()||t.size()||(r="releasing",t.release().catch(()=>{}))},close(){u=!0,clearTimeout(E),clearTimeout(k),i=[],C.clear(),T.clear()}}}function cr(e,t,r){return{send:o=>{e.send(o)},drain:async()=>{},settle:async()=>{},size:()=>0,stopped:()=>!1,take:()=>new Promise((o,i)=>{const c=t.current();if(c?.controller==="you"){o({waited:!1});return}if(!e.send({type:"takeControl"})){i(new Error(s("browser.panel.notConnected")));return}const u=c?.controller==="agent",w=d=>{clearTimeout(v),m(),d()},v=setTimeout(()=>w(()=>i(new Error(s("browser.panel.takeFailed")))),rr),m=t.watch(d=>{d?.controller==="you"?w(()=>o({waited:u})):d?.controller==="another-viewer"?w(()=>i(new Error(r))):d===null&&w(()=>i(new Error(s("browser.panel.viewDisconnected"))))})}),release:async()=>{e.send({type:"releaseControl"})}}}const ur="https://duckduckgo.com/?q=",dr=/^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i,fr=/^[^/?#:@]+:\d+(?:[/?#]|$)/,pr=/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\])(?::|\/|$)/i,hr=new Set(["about:","blob:","chrome:","data:","file:","ftp:","javascript:","mailto:","sms:","ssh:","tel:","view-source:","ws:","wss:"]);function mr(e){return/^([A-Za-z][A-Za-z\d+.-]*):/.exec(e)?.[1]?.toLowerCase().concat(":")}function rt(e){const t=e.includes("://")?e:`${pr.test(e)?"http":"https"}://${e}`;try{const r=new URL(t);return r.protocol==="http:"||r.protocol==="https:"?r.href:null}catch{return null}}function br(e){const t=e.trim();if(!t)return null;if(/^[a-z][a-z\d+.-]*:\/\//i.test(t))return rt(t);if(!/\s/.test(t)){const r=mr(t);if(r!==void 0&&(hr.has(r)||!fr.test(t)))return r==="http:"||r==="https:"?rt(t):null;const o=(t.split(/[/?#]/,1)[0]??"").replace(/^[^@]*@/,""),i=o.replace(/:\d+$/,"");if(i.length<o.length||dr.test(i)||/^[^.]+(?:\.[^.]+)+\.?$/.test(i)){const u=rt(t);if(u)return u}}return`${ur}${encodeURIComponent(t)}`}const xr=5;let Be=null;const it=new Set,Ht=()=>{for(const e of it)e()},wr=e=>(it.add(e),()=>it.delete(e));function yr(){if(typeof document>"u"||typeof HTMLCanvasElement.prototype.captureStream!="function")return!1;const e=HTMLVideoElement.prototype;return document.pictureInPictureEnabled&&typeof e.requestPictureInPicture=="function"||typeof e.webkitSetPresentationMode=="function"}function gr(){return a.useSyncExternalStore(wr,()=>Be?.key??null,()=>null)}function ct(){const e=Be;Be=null,e?.stop(),Ht()}async function kr(e){ct();const t=document.createElement("canvas"),r=t.getContext("2d"),o=e.seed&&e.seed.width>0&&e.seed.height>0?e.seed:null;t.width=o?.width??640,t.height=o?.height??400;const i=t.captureStream();o?r?.drawImage(o,0,0):r?.fillRect(0,0,t.width,t.height);const c=document.createElement("video");c.muted=!0,c.playsInline=!0,c.srcObject=i,c.style.cssText="position:fixed;right:0;bottom:0;width:1px;height:1px;opacity:0;pointer-events:none",document.body.append(c);const u=Bt(t);let w=null,v=!1,m=0,d=null;const g=()=>{Be===k&&ct()},y=()=>{v||(w=_t({access:Lt(e.botId),maxWidth:1280,maxHeight:1280,interactive:!1},{onFrame:C=>{m=0,u.paint(C)},onViewport:()=>{},onConnectedChange:()=>{},onUnauthorized:()=>{if(!v){if(m>=xr){g();return}d=setTimeout(y,1e3*2**m++)}},onGone:g}))},E=()=>{c.webkitPresentationMode!=="picture-in-picture"&&g()},k={key:e.botId,stop:()=>{v=!0,d!==null&&clearTimeout(d),w?.stop(),u.stop(),c.removeEventListener("leavepictureinpicture",g),c.removeEventListener("webkitpresentationmodechanged",E),document.pictureInPictureElement===c?document.exitPictureInPicture().catch(()=>{}):c.webkitPresentationMode==="picture-in-picture"&&c.webkitSetPresentationMode?.("inline");for(const C of i.getTracks())C.stop();c.srcObject=null,c.remove()}};Be=k,Ht();try{await c.play(),c.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise(C=>c.addEventListener("loadedmetadata",C,{once:!0})),document.pictureInPictureEnabled&&typeof c.requestPictureInPicture=="function"?(c.addEventListener("leavepictureinpicture",g),await c.requestPictureInPicture()):(c.addEventListener("webkitpresentationmodechanged",E),c.webkitSetPresentationMode?.("picture-in-picture"))}catch(C){throw g(),C}Be===k&&y()}const vr=[1e3,2e3,4e3,8e3,15e3],Cr=25e3,Sr=5e3,St=32,jt=4096,jr=24e3,Me=(e,t,r)=>Math.max(t,Math.min(r,Number.isFinite(e)?e:0)),Ye=e=>Me(e,-1e4,1e4);function Er(e,t,r,o){const i=t*r/e;return Math.abs(i-o)<=Math.max(1,r/e)?{width:r,height:o}:{width:r,height:Math.round(i)}}function Nr(e){for(let t=2;t+9<e.length;){if(e[t]!==255)return null;const r=e[t+1];if(r>=192&&r<=194)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8]};t+=2+(e[t+2]<<8|e[t+3])}return null}function Et(e){switch(e.type){case"mouse":return{type:"input_mouse",eventType:e.action==="down"?"mousePressed":e.action==="up"?"mouseReleased":"mouseMoved",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:e.button,clickCount:Math.round(Me(e.clickCount,0,3)),modifiers:e.modifiers};case"wheel":return{type:"input_mouse",eventType:"mouseWheel",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:"none",deltaX:Ye(e.deltaX),deltaY:Ye(e.deltaY),modifiers:e.modifiers};case"key":return e.key?{type:"input_keyboard",eventType:e.action==="up"?"keyUp":"keyDown",key:e.key.slice(0,64),code:e.code.slice(0,64),windowsVirtualKeyCode:Math.round(Me(e.keyCode??0,0,255)),modifiers:e.modifiers,...e.text!==void 0?{text:e.text}:{}}:null;case"text":{const t=[];for(let r=0;r<e.text.length;r+=jt)t.push({type:"input_keyboard",eventType:"char",text:e.text.slice(r,r+jt)});return t}case"navigate":return{type:"navigate",url:e.url};case"history":return{type:e.delta<0?"back":"forward"};case"reload":return{type:"reload"};case"tabSelect":return{type:"tab-select",tabId:e.tabId};case"tabClose":return{type:"tab-close",tabId:e.tabId};case"tabNew":return e.url?{type:"tab-new",url:e.url}:{type:"tab-new"};case"restart":return{type:"restart"};case"dialog":return{type:"dialog",accept:e.accept,...e.promptText!==void 0?{promptText:e.promptText.slice(0,4096)}:{}};default:return null}}const Ve=e=>e.type==="input_mouse"&&(e.eventType==="mouseMoved"||e.eventType==="mouseWheel"),ut=e=>e.type==="input_mouse"||e.type==="input_keyboard",Ft=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ft(e)||!ut(e);function Pr(e,t,r=()=>1){let o=[],i=null,c=0,u=!1;const w=d=>{o=o.filter(st),u||(u=!0,t(d))},v=()=>{const d=[o.shift()],g=u?1:r();let y=JSON.stringify(d[0]).length;for(;ut(d[0])&&d.length<g&&o.length&&ut(o[0]);){const E=JSON.stringify(o[0]).length;if(y+E>jr)break;y+=E,d.push(o.shift())}return d},m=()=>{if(i||!o.length)return;const d=c;i=(async()=>{for(;d===c&&o.length;){const g=v();try{await e(g.length===1?g[0]:{type:"input_batch",events:g})}catch(y){if(d!==c)continue;g.length>1&&o.unshift(...g.slice(1).filter(Ft)),w(y)}}})().finally(()=>{i=null,m()})};return{enqueue(d){if(u&&!st(d))return;const g=o.at(-1);if(g&&Ve(d)&&g.type===d.type&&g.eventType===d.eventType&&g.modifiers===d.modifiers&&g.button===d.button){o[o.length-1]=d.eventType==="mouseWheel"?{...d,deltaX:Ye(Number(g.deltaX??0)+Number(d.deltaX??0)),deltaY:Ye(Number(g.deltaY??0)+Number(d.deltaY??0))}:{...d};return}if(o.length>=St){if(Ve(d))return;const y=o.findIndex(Ve);if(y>=0)o.splice(y,1);else if(w(new Error(s("browser.input.tooSlow"))),!st(d)||o.length>=St)return}o.push({...d}),m()},async drain(){for(o=o.filter(d=>!Ve(d));i||o.length;)m(),await i},async settle(){for(;i||o.length;)m(),await i},size:()=>o.length+(i?1:0),stopped:()=>u,clear(){c++,o=[],u=!1}}}function Nt(e,t){const r=e.owned===!0?e.controlling===!0?"you":"agent":e.held===!0?"another-viewer":"unclaimed",o=e.dialog,i=o&&typeof o.type=="string"&&typeof o.message=="string"&&typeof o.defaultValue=="string"?{type:o.type,message:o.message,defaultValue:o.defaultValue}:null;return{canOperate:!0,controller:r,generation:t,dialog:i,...e.owned===!0?{owned:!0}:{}}}function Tr(e,t,r,o={viewer:""},i={},c=null){let u=!1,w=!1,v=!1,m=null,d="",g=0,y=0,E=0,k=null,C=null,T=null,b=1,j=c,O=null;const H=(P,R)=>{P.close(),m=null;const D=d!=="";if(D&&(o.viewer=d),d="",k=null,$.clear(),D&&t.onConnectedChange(!1),u)return;const U=R?vr[y++]:void 0;if(U===void 0){u=!0,w=R,t.onGone?.();return}T=setTimeout(K,U)},le=(P,R)=>P?.status!==404||!m||!R||d!==R?!1:(H(m,!0),!0),re=(P,R)=>r(P,R).catch(D=>{throw le(D,R),D}),J=P=>t.onMessage?.({type:"notice",message:P}),Y=P=>{const R=P?.notice;typeof R=="string"&&R&&J(R)},$=Pr(P=>d?re(P,d).then(Y):Promise.reject(new Error(s("browser.panel.connectionFirst"))),P=>{J(P instanceof Error?P.message:String(P))},()=>b),x=()=>{const P=j,R=d;O||!P||!R||(O=P,r({type:"resize",width:Math.round(P.width),height:Math.round(P.height)},R).catch(()=>{}).finally(()=>{O=null,j!==P&&d===R&&x()}))},K=()=>{if(T=null,u)return;const P=new URLSearchParams(o.viewer?{resume:o.viewer}:{}),R=j;j&&(P.set("width",String(Math.round(j.width))),P.set("height",String(Math.round(j.height))));const D=zt(P.size?`?${P.toString()}`:"",i),U=new EventSource(`/api/bots/${encodeURIComponent(e)}/browser/live${D}`);m=U,g=Date.now();const q=(N,A)=>U.addEventListener(N,G=>{if(m===U){g=Date.now();try{A(JSON.parse(G.data))}catch{}}});q("waiting",()=>t.onMessage?.({type:"starting"})),q("ready",N=>{typeof N.viewerId!="string"||!N.viewerId||(d=N.viewerId,b=Number.isSafeInteger(N.inputBatch)?Math.max(1,Math.min(Number(N.inputBatch),64)):1,o.viewer="",t.onConnectedChange(!0),j!==R&&x())}),q("heartbeat",()=>{y=0}),q("frame",N=>{if(!d||typeof N.data!="string"||typeof N.seq!="number")return;const A=atob(N.data),G=new Uint8Array(A.length);for(let F=0;F<A.length;F++)G[F]=A.charCodeAt(F);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const F=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(F.width!==C?.width||F.height!==C.height)&&(C=F,t.onViewport(F))}t.onFrame(G.buffer),r({type:"ack",seq:N.seq},d).catch(()=>{})}),q("tabs",N=>{Array.isArray(N.tabs)&&t.onMessage?.({type:"tabs",tabs:N.tabs})}),q("url",N=>{typeof N.url=="string"&&t.onMessage?.({type:"url",url:N.url})}),q("status",N=>{C||!(Number(N.viewportWidth)>0&&Number(N.viewportHeight)>0)||(C={width:Number(N.viewportWidth),height:Number(N.viewportHeight)},t.onViewport(C))}),q("control",N=>{const A=Nt(N,E);k&&A.controller===k.controller&&A.owned===k.owned&&JSON.stringify(A.dialog)===JSON.stringify(k.dialog)||(k=A.controller===k?.controller?A:Nt(N,++E),t.onControl?.(k))}),U.addEventListener("error",N=>{if(m!==U)return;let A=!(N instanceof MessageEvent);if(N instanceof MessageEvent)try{const G=JSON.parse(N.data);A=G.retryable===!0,G.asleep===!0?t.onMessage?.({type:"asleep"}):typeof G.message=="string"&&t.onMessage?.({type:"notice",message:G.message,...typeof G.errorKey=="string"?{errorKey:G.errorKey,...G.errorParams!==void 0?{errorParams:G.errorParams}:{}}:{}})}catch{}H(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&H(m,!0),!(!P||T===null&&!(u&&w))&&(T!==null&&clearTimeout(T),u=!1,w=!1,y=0,K()))},V=()=>{document.visibilityState!=="hidden"&&B(!0)},Z=setInterval(()=>B(!1),Sr),W=typeof window>"u"?null:window;return W?.addEventListener("focus",V),W?.addEventListener("online",V),W&&document.addEventListener("visibilitychange",V),{send:P=>{if(P.type==="resize")return j={width:P.width,height:P.height},x(),!0;if(!d||!k?.canOperate||!["takeControl","restart"].includes(P.type)&&k.controller!=="you")return!1;const R=Et(P);if(!R)return!1;if(P.type==="dialog"&&!Array.isArray(R))return re(R,d).catch(D=>J(D instanceof Error?D.message:String(D))),!0;for(const D of Array.isArray(R)?R:[R])$.enqueue(D);return!0},stop:()=>{u=!0,v=!0,clearInterval(Z),W?.removeEventListener("focus",V),W?.removeEventListener("online",V),W&&document.removeEventListener("visibilitychange",V),T!==null&&clearTimeout(T),m?.close(),m=null,d&&(o.viewer=d),d="",$.clear()},transport:{send:P=>{const R=d?Et(P):null;if(R)for(const D of Array.isArray(R)?R:[R])$.enqueue(D)},drain:()=>$.drain(),settle:()=>$.settle(),size:()=>$.size(),stopped:()=>$.stopped(),take:async()=>{if(!d)throw new Error(s("browser.panel.notConnected"));return{waited:(await re({type:"take"},d))?.waited===!0}},release:async()=>{d&&await re({type:"release"},d)}}}}const ot="Another window or device controls this browser. Hand control back there to use it here.",Mr=/^\/(?:v\d+\/)?signin\/(?:v\d+\/)?challenge\/(?:pk|sk)(?:\/|$)/u;function Rr(e){let t;try{t=new URL(e)}catch{return null}return t.hostname==="accounts.google.com"&&Mr.test(t.pathname)?"google":null}const Pt="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed",at={url:"",loading:!1,canGoBack:!1,canGoForward:!1};function Ir(e){return Array.isArray(e)?e.flatMap(t=>t&&typeof t=="object"&&typeof t.tabId=="string"?[{tabId:t.tabId,title:typeof t.title=="string"?t.title:"",url:typeof t.url=="string"?t.url:"",active:t.active===!0}]:[]):[]}function zr({bot:e,signIn:t,page:r}){const{state:o}=dt(),[i,c]=a.useState(!1),u=o.config?.browserEngine?.engine==="chrome"&&!i,[w,v]=a.useState(0),[m,d]=a.useState(!1),[g,y]=a.useState(null),[E,k]=a.useState([]),[C,T]=a.useState(at),[b,j]=a.useState({mode:"fill"}),[O,H]=a.useState(1),[le,re]=a.useState(null),[J,Y]=a.useState(""),[$,x]=a.useState(""),[K,B]=a.useState(!1),[V,Z]=a.useState(!1),[W,te]=a.useState(""),[P,R]=a.useState(!1),[D,U]=a.useState(!1),[q,N]=a.useState(!1),[A,G]=a.useState(!1),[ie,pe]=a.useState(!1),[F,Ee]=a.useState(!1),[Oe,We]=a.useState(""),Ke=gr(),Ne=xn(),ue=a.useRef(null),Q=a.useRef(null),Re=a.useRef(null),be=a.useRef(null),ve=a.useRef(null),de=a.useRef(null),he=a.useRef(null),Ie=a.useRef(new Set),ee=a.useRef(null),Ce=a.useRef({key:"",viewer:""}),ze=a.useRef(!1),De=a.useRef(0),He=a.useRef(0),Fe=a.useRef(null),xe=a.useRef(null),me=a.useRef({openSignInPage:()=>{},takeControl:()=>{}}),ce=o.computerControl?.[e.id]?.help?.place==="browser",we=on(o.config?.team,e.threadId).threadId;ze.current=P||ce;const Pe=e.browserProfile==="guest"?s("browser.panel.temporary"):o.config?.browserProfiles?.find(h=>h.id===e.browserProfile)?.name??s("browser.panel.ownBrowser",{name:e.name});a.useEffect(()=>{D?be.current?.showModal():be.current?.close()},[D]),a.useEffect(()=>{ee.current?.hold(q),q?ve.current?.showModal():ve.current?.close()},[q]);const l=a.useCallback(()=>{Z(!1),x(""),c(!1),v(h=>h+1)},[]);a.useEffect(()=>{c(!1)},[e.id,e.browserProfile,we]),a.useEffect(()=>{k([]),re(null),T(u?at:{...at,canGoBack:!0,canGoForward:!0}),B(!1),Z(!1),te(""),xe.current=null},[e.id,e.browserProfile,we,w,u]);const p=a.useCallback((h,L)=>{const fe=we?{threadId:we}:{};if(u)return _t({access:Lt(e.id,window.location,fe),...h},L);const ke=`${e.id}
1
+ import{c as Tt,r as a,j as n,t as s,X as Ue,f as Mt,al as Kt}from"./styles-6RbfQIY7.js";import{G as lt,Z as Rt,d3 as Vt,bH as qt,dj as Gt,cI as Xt,eb as Yt,ec as Jt,dk as Zt,W as Qt,u as dt,ed as en,J as tn,ee as nn,n as Ge,ef as It,P as rn,bO as sn}from"./App-DRnqqiJP.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-CzzGhZGz.js";import{P as At,L as Xe,Z as ln,K as ht,X as cn}from"./PlacesRail-yZdo57pP.js";import{M as un,a as dn}from"./minimize-B_k_fmmo.js";import{F as fn}from"./file-up-CQezfdJk.js";const pn=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]],hn=Tt("mouse-pointer-2",pn);const mn=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],bn=Tt("shrink",mn);function xn(){const[e,t]=a.useState(()=>document.visibilityState==="visible");return a.useEffect(()=>{const r=()=>t(document.visibilityState==="visible");return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[]),e}const je="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:cursor-not-allowed disabled:opacity-40";function wn(e,t,r){return!e||!t?"connecting":r==="pending"?"taking":r==="slow"?"waiting":t.controller==="you"?"yours":t.owned?"held":t.controller==="another-viewer"?"elsewhere":t.controller==="agent"?"bot":"watching"}const mt={connecting:()=>s("browser.panel.connecting"),watching:()=>s("browser.control.watching"),bot:e=>s("browser.control.botHas",{name:e}),yours:()=>s("vm.workspace.youHaveControl"),held:e=>s("browser.control.held",{name:e}),elsewhere:()=>s("browser.control.elsewhere"),taking:()=>s("browser.control.taking"),waiting:e=>s("browser.control.waiting",{name:e})},yn=a.forwardRef(function(t,r){const{botName:o,tabs:i,nav:c,connected:u,control:w,takeStatus:v,commandsReady:m}=t,[d,g]=a.useState(""),[y,E]=a.useState(!1),k=wn(u,w,v),C=k==="yours",T=C||k==="held",b=c.url==="about:blank"?"":c.url;return n.jsxs("div",{className:"shrink-0 border-b border-hairline/40",children:[n.jsxs("div",{className:"flex min-h-10 items-center gap-1 px-2 pt-1",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",role:"tablist","aria-label":s("browser.panel.tabs"),children:[i.length?i.map(j=>n.jsxs("div",{className:`flex max-w-52 shrink-0 items-center gap-1 rounded-xl px-1 text-[12px] ${j.active?"bg-inset text-ink":"text-ink-secondary"}`,children:[n.jsx(lt,{size:13,className:"ml-1.5 shrink-0 opacity-60","aria-hidden":"true"}),n.jsx("button",{role:"tab","aria-selected":j.active,className:"truncate px-1 py-1.5 text-left disabled:cursor-default",disabled:!m,onClick:()=>t.onCommand({type:"tabSelect",tabId:j.tabId}),title:j.title||j.url,children:j.title||s("browser.panel.newTab")}),n.jsx("button",{className:je,"aria-label":s("browser.panel.closeTab",{title:j.title||s("browser.panel.tab")}),disabled:!m,onClick:()=>t.onCommand({type:"tabClose",tabId:j.tabId}),children:n.jsx(Ue,{size:13})})]},j.tabId)):n.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-inset px-3 py-1.5 text-[12px] text-ink-secondary",children:[n.jsx(lt,{size:13,"aria-hidden":"true"}),s("browser.panel.newTab")]}),n.jsx("button",{className:`${je} shrink-0`,disabled:!m,"aria-label":s("browser.panel.newTab"),title:s("browser.panel.newTab"),onClick:()=>t.onCommand({type:"tabNew"}),children:n.jsx(At,{size:16})})]}),n.jsxs("button",{type:"button","aria-pressed":T,"aria-label":`${mt[k](o)}. ${s(T?"browser.control.handBack":"browser.control.take")}`,"aria-description":C?t.hint:void 0,title:C&&t.hint?t.hint:s(T?"browser.control.handBack":"browser.control.take"),disabled:!u||k==="elsewhere"||k==="connecting"||k==="taking"||k==="waiting",onClick:T?t.onHandBack:t.onTake,className:`flex max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border px-2.5 py-1 text-[11px] disabled:cursor-default ${T?"border-accent-border bg-accent/15 text-accent-text":"border-hairline text-ink-secondary hover:bg-inset hover:text-ink"}`,"data-pill":k,children:[k==="taking"||k==="waiting"||k==="connecting"?n.jsx(Xe,{size:12,className:"shrink-0 animate-spin","aria-hidden":"true"}):n.jsx(Rt,{size:12,className:"shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"truncate",children:mt[k](o)}),k==="bot"||k==="watching"?n.jsxs("span",{className:"shrink-0 text-ink",children:["· ",s("browser.control.take")]}):T?n.jsxs("span",{className:"shrink-0",children:["· ",s("browser.control.handBack")]}):null]}),n.jsx("button",{className:je,title:s(t.maximized?"browser.panel.restore":"browser.panel.maximizeHint"),"aria-label":s(t.maximized?"browser.panel.restore":"browser.panel.maximize"),onClick:t.onMaximize,children:t.maximized?n.jsx(bn,{size:15}):n.jsx(Vt,{size:15})}),n.jsx("button",{className:je,title:s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreenHint"),"aria-label":s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreen"),onClick:t.onFullscreen,children:t.fullscreen?n.jsx(un,{size:15}):n.jsx(dn,{size:15})}),n.jsx("button",{className:`${je} rounded-xl bg-inset p-1.5`,title:s("browser.panel.profileTitle",{name:t.profileName}),"aria-label":s("browser.panel.profiles"),onClick:t.onProfiles,children:n.jsx(ln,{size:15})})]}),n.jsxs("form",{className:"relative flex h-10 items-center gap-1 px-2",onSubmit:j=>{j.preventDefault(),t.onAddress(d),(r&&typeof r=="object"?r.current:null)?.blur()},children:[n.jsxs("div",{className:"flex shrink-0 items-center",role:"group","aria-label":s("browser.panel.navigation"),children:[n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoBack,"aria-label":s("browser.panel.back"),title:s("browser.panel.back"),onClick:()=>t.onCommand({type:"history",delta:-1}),children:n.jsx(qt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoForward,"aria-label":s("browser.panel.forward"),title:s("browser.panel.forward"),onClick:()=>t.onCommand({type:"history",delta:1}),children:n.jsx(Gt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m,"aria-label":s(c.loading?"browser.panel.loadingReload":"browser.panel.reload"),title:s("browser.panel.reloadShort"),onClick:()=>t.onCommand({type:"reload"}),children:c.loading?n.jsx(Xe,{size:16,className:"animate-spin"}):n.jsx(Xt,{size:16})})]}),n.jsx("input",{ref:r,"aria-label":s("browser.panel.address"),readOnly:!m,value:y?d:b,onChange:j=>g(j.target.value),onFocus:j=>{g(b),E(!0),m&&queueMicrotask(()=>j.target.select())},onBlur:()=>E(!1),onKeyDown:j=>{j.key==="Escape"&&(j.preventDefault(),g(b),j.currentTarget.blur())},placeholder:s(u?"browser.panel.searchOrAddress":"browser.panel.connecting"),spellCheck:!1,className:"mx-1 min-w-0 flex-1 rounded-lg bg-transparent px-2 py-1.5 text-center text-[12px] outline-none placeholder:text-ink-secondary focus:bg-inset focus:text-left"}),t.menu,n.jsx("div",{"aria-hidden":"true","data-loading":c.loading,className:`pointer-events-none absolute bottom-0 left-0 h-0.5 bg-accent transition-[width,opacity] duration-500 ${c.loading?"w-2/3 opacity-100":"w-full opacity-0"}`})]})]})});function gn(e){return Array.isArray(e)?e.flatMap(t=>{const{id:r,name:o}=t??{};return typeof r=="string"&&typeof o=="string"?[{id:r,name:o}]:[]}):[]}const kn="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40";function vn({ready:e,extensions:t,onList:r,onOpen:o}){const i=a.useRef(null);return a.useEffect(()=>{e&&i.current?.open&&r()},[e]),n.jsxs("details",{ref:i,className:"relative shrink-0",onToggle:c=>{c.currentTarget.open&&e&&r()},children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.extensions.title"),title:s("browser.extensions.title"),children:n.jsx(Yt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex max-h-80 w-56 flex-col overflow-y-auto rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.extensions.title")}),e?t&&t.length===0?n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.empty")}):(t??[]).map(c=>n.jsx("button",{type:"button",role:"menuitem",className:kn,onClick:()=>{i.current?.removeAttribute("open"),o(c.id)},children:n.jsx("span",{className:"truncate",children:c.name})},c.id)):n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.takeControl")})]})]})}const _e=[.25,.33,.5,.67,.75,.8,.9,1,1.1,1.25,1.5,1.75,2,2.5,3,4,5];function bt(e,t){return t>0?_e.find(r=>r>e+.001)??_e.at(-1):[..._e].reverse().find(r=>r<e-.001)??_e[0]}const Cn=[{label:"browser.viewport.fill",setting:{mode:"fill"}},{label:"browser.viewport.fullHd",setting:{mode:"preset",preset:"fullHd"}},{label:"browser.viewport.desktop",setting:{mode:"preset",preset:"desktop"}},{label:"browser.viewport.tablet",setting:{mode:"preset",preset:"tablet"}},{label:"browser.viewport.phone",setting:{mode:"preset",preset:"phone"}}],xt=(e,t)=>e.mode===t.mode&&(e.mode!=="preset"||t.mode==="preset"&&e.preset===t.preset),Ae="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40",Qe="rounded-md border border-hairline p-1 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40";function Sn({stream:e,ready:t,typing:r,setting:o,zoom:i,pip:c,onViewport:u,onZoom:w,onPip:v,onType:m,onSecret:d,onReconnect:g,onRestart:y}){const E=a.useRef(null),k=T=>()=>{E.current?.removeAttribute("open"),T()},C=T=>n.jsx("div",{className:"border-b border-hairline/40 py-1 last:border-b-0",children:T});return n.jsxs("details",{ref:E,className:"relative shrink-0",children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.panel.menu"),title:s("browser.panel.menu"),children:n.jsx(Jt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex w-56 flex-col rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[e?C(n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.viewport.title")}),Cn.map(T=>n.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":xt(T.setting,o),className:Ae,disabled:!t,onClick:k(()=>u(T.setting)),children:[n.jsx("span",{className:"w-3.5 shrink-0",children:xt(T.setting,o)?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null}),s(T.label)]},T.label)),n.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[n.jsx("span",{children:s("settings.profile.avatar.zoom")}),n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.out"),disabled:!t||i<=_e[0],onClick:()=>w(bt(i,-1)),children:n.jsx(Zt,{size:12})}),n.jsxs("span",{className:"min-w-11 text-center tabular-nums text-ink-secondary","aria-live":"polite",children:[Math.round(i*100),"%"]}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.in"),disabled:!t||i>=_e.at(-1),onClick:()=>w(bt(i,1)),children:n.jsx(At,{size:12})}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.reset"),disabled:!t||i===1,onClick:()=>w(1),children:n.jsx(Qt,{size:12})})]})]})]})):null,C(n.jsxs(n.Fragment,{children:[e&&c?n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(v),children:s(c.open?"browser.pip.close":"browser.pip.open")}):null,n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(m),children:s("browser.panel.typeTextMenu")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(d),children:s("browser.typeSecret")})]})),C(n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(g),children:s("browser.panel.reconnectView")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(y),children:s("browser.panel.restartBrowser")})]}))]})]})}function jn(e){const[t,r]=a.useState(null);return a.useEffect(()=>{if(!e)return;let o=!0;return Ge("/api/shared-computers").then(i=>{o&&r(i.computers?.find(c=>c.online&&c.scopes?.screen)?.name??null)}).catch(()=>{}),()=>{o=!1}},[e]),t}function En({wall:e,botName:t,onDismiss:r}){const{state:o,dispatch:i}=dt(),c=o.config?.cloudHome===!0,u=jn(c),w=e==="google"?"Google":"Microsoft";return n.jsx("section",{role:"status","aria-label":s("browser.passkey.title"),className:"shrink-0 border-b border-hairline/30 bg-inset/60 px-3 py-2.5 text-[12px] leading-relaxed text-ink-secondary",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(en,{size:14,className:"mt-0.5 shrink-0 text-accent-text","aria-hidden":"true"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium text-ink",children:s("browser.passkey.title")}),n.jsx("p",{children:s("browser.passkey.body",{provider:w})}),n.jsxs("ol",{className:"mt-1 list-decimal space-y-1 pl-4",children:[n.jsxs("li",{children:[s(e==="google"?"browser.passkey.appsGoogle":"browser.passkey.appsMicrosoft",{name:t})," ",n.jsx("button",{type:"button",className:"text-accent-text underline",onClick:()=>i({type:"togglePlugins",open:!0,surface:"apps"}),children:s("browser.passkey.connect")})]}),n.jsx("li",{children:s(e==="google"?"browser.passkey.otherWayGoogle":"browser.passkey.otherWayMicrosoft")}),c&&n.jsx("li",{children:u?s("browser.passkey.lentPc",{computer:u,name:t}):s("browser.passkey.lendPc",{name:t})})]}),n.jsx("button",{type:"button",className:"mt-1 text-accent-text underline",onClick:()=>{tn(nn)},children:s("browser.passkey.learnMore")})]}),n.jsx("button",{type:"button",className:"rounded-md p-1 text-ink-tertiary hover:bg-inset hover:text-ink","aria-label":s("browser.passkey.dismiss"),onClick:r,children:n.jsx(Ue,{size:14})})]})})}const Nn=4503,Pn=4404,Tn="sudo limixbot browser install --with-deps",Mn="https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox",ft=(e,t)=>{const r=Object.entries(t.query);if(r.length===0)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${new URLSearchParams(r).toString()}`};function Lt(e,t=window.location,r={}){const o=`/api/bots/${encodeURIComponent(e)}/browser`;return{httpBase:`${t.protocol}//${t.host}${o}`,wsBase:`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}${o}`,query:{...r},credentials:!0}}const Rn=e=>e===null||typeof e=="object"&&"type"in e&&typeof e.type=="string"&&"message"in e&&typeof e.message=="string"&&"defaultValue"in e&&typeof e.defaultValue=="string",In=(e,t)=>ft(`${e.access.httpBase}/upload?${new URLSearchParams({chooser:t}).toString()}`,e.access);async function zn(e,t){const r=new FormData;for(const i of t)r.append("file",i,i.name??"file");const o=await fetch(e.uploadUrl,{method:"POST",body:r,credentials:e.credentials?"include":"omit"});if(!o.ok){const i=await o.text();let c=i;try{c=JSON.parse(i).error??i}catch{}throw new Error(c||s("browser.page.uploadRefused"))}}const An=(e,t)=>ft(`${e.access.httpBase}/download/${encodeURIComponent(t)}`,e.access),et=e=>(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0),Ln=(e,t)=>e.type==="takeControl"||e.type==="resize"||e.type==="frameCap"||e.type==="restart"||e.type==="wake"||e.type==="releaseControl"&&t.owned===!0||t.controller==="you",_n=JSON.stringify({type:"ack"});function _t(e,t){let r={width:e.maxWidth,height:e.maxHeight},o=e.width!==void 0&&e.height!==void 0?{width:e.width,height:e.height}:null;const i=()=>{const y=new URLSearchParams({maxWidth:String(Math.max(1,Math.round(r.width))),maxHeight:String(Math.max(1,Math.round(r.height)))});return o&&(y.set("width",String(Math.round(o.width))),y.set("height",String(Math.round(o.height)))),e.interactive===!1&&y.set("interactive","false"),ft(`${e.access.wsBase}/stream?${y.toString()}`,e.access)};let c=!1,u=null,w=null,v=0,m=null,d=null;const g=()=>{if(c)return;const y={cap:r,size:o},E=new WebSocket(i());E.binaryType="arraybuffer",u=E;let k=!1;E.addEventListener("open",()=>{u===E&&(k=!0,t.onConnectedChange(!0))}),E.addEventListener("message",C=>{if(u!==E)return;if(C.data instanceof ArrayBuffer){v=0,E.send(_n),t.onFrame(C.data);return}if(typeof C.data!="string")return;let T;try{T=JSON.parse(C.data)}catch{return}if(typeof T!="object"||T===null)return;const{type:b,x:j,y:O,width:H,height:le,editable:re,canOperate:J,controller:Y,generation:$,dialog:x,stale:K,owned:B,text:V,id:Z,fileName:W,sizeBytes:te,multiple:P,accept:R,phase:D,sequence:U,tabId:q}=T;if(b==="fileChooser"&&typeof Z=="string"&&typeof P=="boolean"&&typeof R=="string")d=Z,t.onFileChooser?.({multiple:P,accept:R,uploadUrl:In(e,Z),credentials:e.access.credentials});else if(b==="fileChooserClosed"&&typeof Z=="string"){if(d!==Z)return;d=null,t.onFileChooser?.(null)}else if(b==="pointer"&&(D==="move"||D==="click")&&typeof j=="number"&&typeof O=="number"&&typeof U=="number")t.onPointer?.({phase:D,x:j,y:O,sequence:U});else if(b==="popup"&&typeof q=="string")t.onPopup?.(q);else if(b==="clipboard"&&typeof V=="string")t.onClipboard?.(V);else if(b==="download"&&typeof Z=="string"&&typeof W=="string"&&typeof te=="number")t.onDownload?.({fileName:W,sizeBytes:te,url:An(e,Z)});else if(b==="viewport"&&typeof H=="number"&&typeof le=="number")v=0,t.onViewport({width:H,height:le}),t.onMessage?.(T);else if(b==="probe"&&typeof j=="number"&&typeof O=="number"&&typeof re=="boolean")t.onProbe?.({x:j,y:O,editable:re});else if(b==="control"&&typeof J=="boolean"&&(Y==="agent"||Y==="you"||Y==="another-viewer"||Y==="unclaimed")&&typeof $=="number"&&Rn(x)){const N={canOperate:J,controller:Y,generation:$,dialog:x,...K===!0?{stale:!0}:{},...B===!0?{owned:!0}:{}},A=m===null;m=N,A&&J&&r!==y.cap&&E.send(JSON.stringify({type:"frameCap",maxWidth:r.width,maxHeight:r.height})),A&&J&&o&&o!==y.size&&E.send(JSON.stringify({type:"resize",...o})),t.onControl?.(N)}else typeof b=="string"&&t.onMessage?.(T)}),E.addEventListener("close",C=>{if(u===E&&(u=null,m=null,k&&t.onConnectedChange(!1),!c)){if(t.onClose?.(C.code,C.reason),C.code===Pn){c=!0,t.onGone?.();return}if(C.code===Nn){c=!0,t.onHostSetup?.(Bn(C.reason));return}if(C.code===1008||C.code===4401||!k&&C.code===1006){c=!0,t.onUnauthorized();return}w=setTimeout(g,Math.min(500*2**v++,1e4))}}),E.addEventListener("error",()=>E.close())};return g(),{send:y=>(y.type==="resize"?o={width:y.width,height:y.height}:y.type==="frameCap"&&(r={width:y.maxWidth,height:y.maxHeight}),u?.readyState!==WebSocket.OPEN||!m?.canOperate||!Ln(y,m)?!1:(u.send(JSON.stringify(y)),!0)),stop:()=>{c=!0,w!==null&&clearTimeout(w);const y=u;u=null,m=null,y?.close()}}}function Bt(e,t){const r=e.getContext("2d");let o=!1,i=!1,c=null;const u=w=>{i=!0,createImageBitmap(new Blob([w],{type:"image/jpeg"})).then(v=>{if(o||!r){v.close();return}(e.width!==v.width||e.height!==v.height)&&(e.width=v.width,e.height=v.height),r.drawImage(v,0,0),v.close(),t?.()}).catch(()=>{}).finally(()=>{i=!1;const v=c;c=null,v&&!o&&u(v)})};return{paint:w=>{o||(i?c=w:u(w))},stop:()=>{o=!0,c=null}}}const Bn=e=>{try{if(JSON.parse(e).need==="libraries")return{need:"libraries",command:Tn}}catch{}return{need:"sandbox"}},On=e=>e.need==="sandbox"?"This server's host blocks the sandbox its browser runs in. An administrator can allow it for one copy of Chrome with these steps, then try again:":"This server's host is missing libraries its browser needs. Run this once on the host, then try again:",Dn=700;function Hn(e,t){return e?1:t==="human"?.18:.35}function Fn({phase:e,sequence:t,left:r,top:o,controller:i}){const[c,u]=a.useState(null),w=c!==t;return a.useEffect(()=>{const v=window.setTimeout(()=>u(t),Dn);return()=>window.clearTimeout(v)},[t]),n.jsxs("div",{className:"pointer-events-none absolute left-0 top-0 z-30 transition-[opacity,transform] duration-150 ease-out motion-reduce:transition-none",style:{opacity:Hn(w,i),transform:`translate3d(${r}px, ${o}px, 0)`},"aria-hidden":"true","data-agent-cursor":!0,children:[e==="click"?n.jsx("span",{className:"absolute left-0.5 top-0.5 size-4 animate-ping rounded-full bg-accent/25 motion-reduce:animate-none"},t):null,n.jsx(hn,{className:"relative size-5 -translate-x-0.5 -translate-y-0.5 fill-card text-accent drop-shadow-sm",strokeWidth:2})]})}function $n({origin:e,realm:t,onAnswer:r}){const o=i=>{i.preventDefault();const c=i.currentTarget,u=c.elements.namedItem("username"),w=c.elements.namedItem("password");r({username:u.value,password:w.value}),u.value="",w.value=""};return n.jsxs("form",{role:"dialog","aria-label":s("browser.auth.label"),onSubmit:o,className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2.5 rounded-xl border border-hairline/60 bg-card p-4 text-ink shadow-xl",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-medium",children:[n.jsx(It,{size:14,"aria-hidden":"true"}),s("browser.auth.signIn")]}),n.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t?s("browser.auth.asks",{origin:e,realm:t}):e}),n.jsx("input",{name:"username","aria-label":s("browser.auth.username"),autoComplete:"off",spellCheck:!1,maxLength:1024,placeholder:s("browser.auth.username"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsx("input",{name:"password",type:"password","aria-label":s("logins.password"),autoComplete:"new-password",maxLength:1024,placeholder:s("logins.password"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:()=>r(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",children:s("common.cancel")}),n.jsx("button",{type:"submit",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",children:s("browser.auth.signIn")})]})]})}function Un({options:e,selectedIndex:t,anchor:r,bounds:o,onChoose:i,onClose:c}){const[u,w]=a.useState(()=>t>=0?t:e.findIndex(b=>!b.disabled)),v=a.useRef(null);a.useEffect(()=>{v.current?.focus({preventScroll:!0})},[]),a.useEffect(()=>{v.current?.querySelector(`[data-index="${u}"]`)?.scrollIntoView?.({block:"nearest"})},[u]);const m=o.height-(r.top+r.height),d=r.top,g=m<160&&d>m,y=Math.max(96,Math.min(320,(g?d:m)-8)),E=Math.max(0,Math.min(r.left,o.width-Math.max(r.width,160))),k=(b,j)=>{for(let O=b+j;O>=0&&O<e.length;O+=j)if(!e[O].disabled)return O;return b},C=b=>{b.key==="ArrowDown"||b.key==="ArrowUp"?(b.preventDefault(),w(j=>k(j,b.key==="ArrowDown"?1:-1))):b.key==="Home"||b.key==="End"?(b.preventDefault(),w(b.key==="Home"?k(-1,1):k(e.length,-1))):b.key==="Enter"||b.key===" "?(b.preventDefault(),e[u]&&!e[u].disabled&&i(u)):(b.key==="Escape"||b.key==="Tab")&&(b.preventDefault(),b.stopPropagation(),c())};let T;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"absolute inset-0 z-30","aria-hidden":"true",onPointerDown:b=>{b.preventDefault(),c()}}),n.jsx("div",{ref:v,role:"listbox","aria-label":s("browser.select.label"),"aria-activedescendant":u>=0?`select-option-${u}`:void 0,tabIndex:0,onKeyDown:C,onBlur:b=>{b.currentTarget.contains(b.relatedTarget)||c()},className:"absolute z-40 overflow-y-auto rounded-lg border border-hairline/60 bg-menu py-1 text-[13px] text-ink shadow-xl outline-none",style:{left:E,minWidth:Math.max(r.width,160),maxHeight:y,...g?{bottom:o.height-r.top+2}:{top:r.top+r.height+2}},children:e.map((b,j)=>{const O=b.group!==void 0&&b.group!==T?b.group:null;return T=b.group,n.jsxs("div",{children:[O!==null?n.jsx("div",{className:"px-3 pb-0.5 pt-1.5 text-[11px] font-medium text-ink-tertiary",role:"presentation",children:O}):null,n.jsxs("div",{id:`select-option-${j}`,"data-index":j,role:"option","aria-selected":j===t,"aria-disabled":b.disabled||void 0,onPointerEnter:()=>{b.disabled||w(j)},onPointerDown:H=>H.preventDefault(),onClick:()=>{b.disabled||i(j)},className:`flex cursor-default items-center gap-2 px-3 py-1.5 ${b.group!==void 0?"pl-5":""} ${b.disabled?"text-ink-tertiary":j===u?"bg-accent text-accent-ink":""}`,children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label||" "}),j===t?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null]})]},j)})})]})}const wt=150,Wn=24,Kn=1e4,$e="​",Vn={key:"Backspace",code:"Backspace",keyCode:8},qn={key:"Delete",code:"Delete",keyCode:46},Gn=8,Xn=500,Yn=4,Jn=16,yt=e=>e===0?"left":e===1?"middle":e===2?"right":"none",gt=e=>e&1?"left":e&2?"right":e&4?"middle":"none",Le=e=>e!==null&&e.canOperate&&e.controller!=="another-viewer";function Ot(e,t){const r=Math.min(e.width/t.width,e.height/t.height),o=t.width*r,i=t.height*r;return{width:o,height:i,left:(e.width-o)/2,top:(e.height-i)/2}}function Zn(e,t,r,o,i,c){const u=Ot(e,t);if(!(u.width>0&&u.height>0))return null;const w=r.width/u.width,v=(o-e.left-u.left)*w,m=(i-e.top-u.top)*(r.height/u.height);return!(v>=0&&m>=0&&v<=r.width&&m<=r.height)&&!c?null:{x:Math.min(Math.max(v,0),r.width),y:Math.min(Math.max(m,0),r.height),scale:w}}function kt(e,t,r,o){const i=Ot(t,r),c=i.width/o.width,u=i.height/o.height;return{left:i.left+e.x*c,top:i.top+e.y*u,width:e.width*c,height:e.height*u}}function Qn(e){const t=document.createElement("a");t.href=e.url,t.download=e.fileName,t.rel="noopener",t.click()}function er(e){const{connect:t,ref:r}=e,o=a.useRef(e);o.current=e;const i=a.useRef(null),c=a.useRef(null),u=a.useRef(!1),w=a.useRef(null),v=a.useRef(null),m=a.useRef(null),d=a.useRef(!1),g=a.useRef(null),[y,E]=a.useState(null),[k,C]=a.useState(!1),[T,b]=a.useState(!1),[j,O]=a.useState(""),[H,le]=a.useState(null),[re,J]=a.useState(null),[Y,$]=a.useState(null),[x,K]=a.useState("default"),[B,V]=a.useState(null),[Z,W]=a.useState([]),[te,P]=a.useState(null),R=a.useRef(0),D=a.useRef(null),U=a.useRef(null),q=a.useRef(null),N=a.useRef(null),A=a.useRef(0),G=a.useRef({left:1,middle:1,right:1,none:1}),ie=a.useRef(null),pe=a.useRef(null),F=a.useRef(null),Ee=a.useRef(null),Oe=a.useRef(null),[We,Ke]=a.useState(!1),Ne=a.useCallback(l=>{const p=++R.current;W(S=>[...S.slice(-2),{...l,id:p}])},[]),ue=l=>W(p=>p.filter(S=>S.id!==l)),Q=a.useCallback(l=>{o.current.input(l)},[]),Re=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null,U.current=q.current=null,A.current=0,G.current={left:1,middle:1,right:1,none:1},ie.current=null,pe.current=F.current=Ee.current=null,u.current=!1,c.current&&(c.current.value=$e)},[]),be=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null;const l=U.current,p=q.current;U.current=null,q.current=null,l&&Q(l),p&&Q(p)},[Q]),ve=a.useCallback(()=>{N.current??=requestAnimationFrame(be)},[be]),de=a.useCallback((l,p,S,z)=>{const I=q.current;q.current={type:"wheel",x:l.x,y:l.y,deltaX:(I?.deltaX??0)+p,deltaY:(I?.deltaY??0)+S,modifiers:z},ve()},[ve]),he=a.useCallback((l,p,S)=>{const z=i.current,I=v.current;return!z||!I||!d.current||!Le(g.current)?null:Zn(z.getBoundingClientRect(),z,I,l,p,S)},[]),Ie=(l,p,S,z)=>{const I=ie.current,X=I&&I.button===l&&z-I.time<Xn&&Math.hypot(p-I.x,S-I.y)<Yn?I.count+1:1;return ie.current={button:l,time:z,x:p,y:S,count:X},X},ee=()=>c.current?.focus({preventScroll:!0});a.useImperativeHandle(r,()=>({canvas:()=>d.current?i.current:null,focusPage:ee}),[]),a.useEffect(()=>{const l=i.current?.parentElement;if(!l||typeof ResizeObserver>"u")return;let p=null,S=null;const z=()=>{S=null;const f=m.current;if(!f)return;const M=window.devicePixelRatio||1,se=Math.round(f.width*M),ye=Math.round(f.height*M),ae=Oe.current;if(ae!==null&&ae.width>=se&&ae.height>=ye)return;const _={width:Math.max(se,ae?.width??0),height:Math.max(ye,ae?.height??0)};Oe.current=_,ae===null?Ke(!0):w.current?.send({type:"frameCap",maxWidth:_.width,maxHeight:_.height})},I=()=>{p=null;const f=l.getBoundingClientRect();if(f.width<1||f.height<1)return;const M={width:Math.round(f.width),height:Math.round(f.height)},se=m.current;se?.width===M.width&&se.height===M.height||(m.current=M,w.current?.send({type:"resize",...M}),S!==null&&clearTimeout(S),S=setTimeout(z,se===null?0:wt*2))},X=new ResizeObserver(()=>{p===null&&(p=setTimeout(I,m.current===null?0:wt))});return X.observe(l),()=>{X.disconnect(),p!==null&&clearTimeout(p),S!==null&&clearTimeout(S)}},[]),a.useEffect(()=>{const l=i.current,p=m.current,S=Oe.current;if(te||!We||!S||!l||!p)return;d.current=!1,b(!1);const z=Bt(l,()=>{d.current||(d.current=!0,b(!0),o.current.onFirstFrame?.())}),I=f=>{const M=g.current;g.current=f,E(f),o.current.onControl?.(f),(f?.dialog?.message!==M?.dialog?.message||f?.dialog?.defaultValue!==M?.dialog?.defaultValue)&&O(f?.dialog?.defaultValue??""),f?.controller!=="you"?$(null):M?.controller!=="you"&&m.current&&w.current?.send({type:"resize",...m.current}),Le(f)||(Re(),c.current?.blur())},X=t({maxWidth:S.width,maxHeight:S.height,width:p.width,height:p.height},{onFrame:f=>z.paint(f),onProbe:f=>{if(g.current?.controller!=="you")return;Ee.current={...f,at:performance.now()};const M=F.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(F.current=null,f.editable?c.current?.focus({preventScroll:!0}):c.current?.blur()))},onPointer:f=>{const M=i.current,se=v.current;if(!M||!se||M.width<1||M.height<1)return;const ye={width:M.clientWidth,height:M.clientHeight},ae=kt({x:f.x,y:f.y,width:0,height:0},ye,M,se);J({...ae,phase:f.phase,sequence:f.sequence})},onClipboard:f=>{ht(f).then(M=>{M==="failed"&&Ne({kind:"clipboard",text:f})})},onDownload:f=>Ne({kind:"download",download:f}),onPopup:()=>{},onFileChooser:le,onViewport:f=>{v.current=f},onControl:I,onMessage:f=>{if(f.type==="selectPopup"&&typeof f.id=="string"&&Array.isArray(f.options)){const M=f.rect;M&&$({id:f.id,options:f.options,selectedIndex:Number(f.selectedIndex),rect:M})}else f.type==="cursor"&&typeof f.shape=="string"?K(f.shape):f.type==="authPrompt"&&typeof f.tabId=="string"&&typeof f.id=="string"&&typeof f.origin=="string"?V({tabId:f.tabId,id:f.id,origin:f.origin,realm:typeof f.realm=="string"?f.realm:""}):f.type==="authPromptClosed"?V(M=>M&&M.id!==f.id?M:null):f.type==="notice"&&typeof f.message=="string"&&Ne({kind:"error",message:Kt(f,f.message)});o.current.onMessage?.(f)},onConnectedChange:f=>{C(f),o.current.onConnectedChange?.(f),!f&&(le(null),$(null),V(null),I(null))},onHostSetup:P,onUnauthorized:()=>o.current.onUnauthorized?.(),onGone:()=>o.current.onGone?.(),onClose:(f,M)=>o.current.onClose?.(f,M)});return w.current=X,o.current.onClient?.(X),()=>{z.stop(),X.stop(),w.current===X&&(w.current=null),o.current.onClient?.(null),I(null),C(!1),J(null),Re()}},[We,Re,t,te,Ne]),a.useEffect(()=>{const l=i.current;if(!l)return;const p=S=>{const z=he(S.clientX,S.clientY,!1);if(!z)return;S.preventDefault();const I=S.deltaMode===WheelEvent.DOM_DELTA_LINE?Jn:S.deltaMode===WheelEvent.DOM_DELTA_PAGE?v.current?.height??0:1;de(z,S.deltaX*I,S.deltaY*I,et(S))};return l.addEventListener("wheel",p,{passive:!1}),()=>l.removeEventListener("wheel",p)},[he,de]),a.useEffect(()=>()=>{N.current!==null&&cancelAnimationFrame(N.current)},[]);const Ce=l=>{if(!Le(g.current))return;const{type:p,pointerId:S,clientX:z,clientY:I}=l,X=p==="pointercancel",f=pe.current;if(X&&f?.pointerId===S){pe.current=F.current=null;return}if(l.pointerType==="touch"&&!X){const _=he(z,I,p==="pointermove");if(p==="pointerdown"){if(!l.isPrimary)return;pe.current={pointerId:S,startX:z,startY:I,lastX:z,lastY:I,panning:!1};const Se=Ee.current,Te=_&&Se&&performance.now()-Se.at<Kn&&Math.hypot(_.x-Se.x,_.y-Se.y)<Wn;F.current=_?{x:_.x,y:_.y,editable:Te?Se.editable:null,answered:!1,tapped:!1}:null,_&&Q({type:"probe",x:_.x,y:_.y});return}if(!f||f.pointerId!==S)return;if(p==="pointermove"){if(!f.panning&&Math.hypot(z-f.startX,I-f.startY)<Gn)return;f.panning=!0,_&&de(_,(f.lastX-z)*_.scale,(f.lastY-I)*_.scale,0),f.lastX=z,f.lastY=I;return}pe.current=null;const oe=F.current;if(f.panning){F.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:F.current=null,be();const ge=Ie("left",z,I,l.timeStamp),ne={x:_.x,y:_.y,modifiers:0};Q({type:"mouse",action:"move",...ne,button:"none",buttons:0,clickCount:0}),Q({type:"mouse",action:"down",...ne,button:"left",buttons:1,clickCount:ge}),Q({type:"mouse",action:"up",...ne,button:"left",buttons:0,clickCount:ge});return}const M=A.current;if((X||p==="pointerup")&&M===0)return;(X||p==="pointerup")&&(A.current=X?0:l.buttons&7);const se=he(z,I,p!=="pointerdown"&&(X||p==="pointerup"||M!==0||l.buttons!==0));if(!se)return;const ye={x:se.x,y:se.y,modifiers:et(l)},ae=(_,oe,ge)=>{_==="down"&&(G.current[oe]=Ie(oe,z,I,l.timeStamp)),Q({type:"mouse",action:_,...ye,button:oe,buttons:ge,clickCount:G.current[oe]})};if(p==="pointerdown")ee(),l.currentTarget.setPointerCapture(S),be(),A.current=l.buttons&7,ae("down",yt(l.button),l.buttons);else if(p==="pointerup")be(),ae("up",yt(l.button),l.buttons);else{const _=X?0:l.buttons&7,oe=M^_;if(M!==0&&oe!==0){be();let ge=M;for(const ne of[1,2,4])oe&ne&&(ge^=ne,ae(_&ne?"down":"up",gt(ne),ge));A.current=_}if(X)return;U.current={type:"mouse",action:"move",...ye,button:gt(l.buttons),buttons:l.buttons,clickCount:0},ve()}},ze=l=>{u.current=!1,l.value=$e,l.setSelectionRange($e.length,$e.length)},De=l=>{Q({type:"key",action:"down",...l,modifiers:0}),Q({type:"key",action:"up",...l,modifiers:0})},He=(l,p)=>{if(!Le(g.current)||(u.current=!1,p.nativeEvent.isComposing||p.keyCode===229||p.key==="Process"||p.key==="Unidentified"))return;if(p.key==="Escape"&&p.shiftKey){p.preventDefault(),p.stopPropagation(),l==="down"&&(p.currentTarget.blur(),o.current.onLeave?.());return}const S=p.ctrlKey||p.metaKey;if(S&&p.key.toLowerCase()==="v"||p.shiftKey&&p.key==="Insert")return;const z=S?void 0:[...p.key].length===1?p.key:p.key==="Enter"?"\r":void 0;Q({type:"key",action:l,key:p.key,code:p.code,keyCode:p.keyCode,...l==="down"&&z!==void 0?{text:z}:{},modifiers:et(p)}),u.current=l==="down"&&!S&&(z!==void 0||p.key==="Backspace"||p.key==="Delete"),!S&&(p.preventDefault(),p.stopPropagation())},Fe=l=>{const p=l.nativeEvent;if(p instanceof InputEvent&&p.isComposing)return;const S=l.currentTarget,z=p instanceof InputEvent?p.inputType:"";if(u.current)u.current=!1;else if(z==="deleteContentBackward")De(Vn);else if(z==="deleteContentForward")De(qn);else{const I=S.value.replace(/^​/,"");I&&Q({type:"text",text:I})}ze(S)},xe=l=>{const p=H;p&&(le(null),zn(p,l).catch(S=>Ne({kind:"error",message:s("browser.page.uploadFailed",{error:S instanceof Error?S.message:String(S)})})))},me=l=>w.current?.send(l),ce=i.current,we=Y&&ce&&v.current&&ce.width>0?kt(Y.rect,{width:ce.clientWidth,height:ce.clientHeight},ce,v.current):null,Pe=y?.controller==="you";return n.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden ${e.className??""}`,"data-browser-surface":!0,children:[n.jsxs("div",{className:"relative min-h-0 flex-1",children:[n.jsx("canvas",{ref:i,"aria-hidden":"true",className:"block size-full touch-none object-contain",style:{cursor:Le(y)?Pe?x:"default":"not-allowed"},onPointerDown:Ce,onPointerMove:Ce,onPointerUp:Ce,onPointerCancel:Ce,onMouseDown:l=>l.preventDefault(),onContextMenu:l=>l.preventDefault()}),re&&!Pe?n.jsx(Fn,{...re,controller:y?.controller==="agent"?"agent":"none"}):null,n.jsx("textarea",{ref:c,"aria-label":e.label??s("browser.page.label"),"aria-description":s("browser.page.keysHint"),"aria-keyshortcuts":"Shift+Escape",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:!Le(y),defaultValue:$e,onFocus:l=>ze(l.currentTarget),className:"sr-only left-0 top-0 text-base",onKeyDown:l=>He("down",l),onKeyUp:l=>He("up",l),onInput:Fe,onCompositionEnd:l=>{const p=l.data.replace(/^​/,"");p&&Q({type:"text",text:p}),ze(l.currentTarget)},onCopy:l=>l.preventDefault(),onCut:l=>l.preventDefault(),onPaste:l=>{l.preventDefault();const p=l.clipboardData.getData("text/plain");p&&Q({type:"text",text:p})}}),k&&!T&&!te?n.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center text-ink-secondary","aria-hidden":"true",children:n.jsx(Xe,{size:22,className:"animate-spin"})}):null,Y&&we&&ce?n.jsx(Un,{options:Y.options,selectedIndex:Y.selectedIndex,anchor:we,bounds:{width:ce.clientWidth,height:ce.clientHeight},onChoose:l=>{me({type:"selectChoose",id:Y.id,index:l}),$(null),ee()},onClose:()=>{$(null),ee()}},Y.id):null,H&&Pe?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.page.chooseFilesLabel"),children:[n.jsxs("p",{className:"flex items-center gap-2 text-[13px]",children:[n.jsx(fn,{size:14,"aria-hidden":"true"}),s(H.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:H.multiple,accept:H.accept,onChange:l=>{const p=[...l.currentTarget.files??[]];l.currentTarget.value="",p.length>0&&xe(p)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>xe([]),children:s("common.cancel")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>D.current?.click(),children:s(H.multiple?"browser.page.chooseFiles":"browser.page.chooseFile")})]})]}):null,y?.dialog&&y.controller!=="another-viewer"?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.dialog.label"),children:[n.jsx("p",{className:"break-words text-[13px]",children:y.dialog.message}),Pe?n.jsxs(n.Fragment,{children:[y.dialog.type==="prompt"?n.jsx("input",{"aria-label":s("browser.dialog.response"),value:j,onChange:l=>O(l.target.value),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}):null,n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>me({type:"dialog",accept:!1}),children:s("browser.dialog.dismiss")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>me({type:"dialog",accept:!0,...y.dialog?.type==="prompt"?{promptText:j}:{}}),children:s("browser.dialog.accept")})]})]}):n.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("browser.dialog.takeControl")})]}):null,B&&Pe?n.jsx($n,{origin:B.origin,realm:B.realm,onAnswer:l=>{const p={tabId:B.tabId,id:B.id};me(l?{type:"authAnswer",...p,username:l.username,password:l.password}:{type:"authAnswer",...p}),V(null)}}):null,Z.length?n.jsx("div",{className:"absolute inset-x-3 bottom-3 z-20 flex flex-col items-center gap-2",role:"status",children:Z.map(l=>n.jsxs("div",{className:"flex max-w-full items-center gap-2 rounded-xl border border-hairline/60 bg-card px-3 py-2 text-[12px] text-ink shadow-lg",children:[l.kind==="download"?n.jsxs(n.Fragment,{children:[n.jsx(rn,{size:13,"aria-hidden":"true",className:"shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.downloaded",{name:l.download.fileName})}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{Qn(l.download),ue(l.id)},children:s("common.save")})]}):l.kind==="clipboard"?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.copied")}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{ht(l.text),ue(l.id)},children:s("common.copy")})]}):n.jsx("span",{role:"alert",className:"min-w-0 text-danger",children:l.message}),n.jsx("button",{type:"button","aria-label":s("browser.dialog.dismiss"),className:"shrink-0 rounded-md p-0.5 text-ink-secondary hover:bg-inset",onClick:()=>ue(l.id),children:n.jsx(Ue,{size:12})})]},l.id))}):null]}),te?n.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center",children:[n.jsx("p",{role:"alert",className:"max-w-sm text-[13px] text-ink-secondary",children:On(te)}),te.need==="libraries"?n.jsx("code",{className:"max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink",children:te.command}):n.jsx("a",{href:Mn,target:"_blank",rel:"noopener noreferrer",className:"text-[12px] text-ink underline",children:"Browser sandbox setup steps"}),n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:()=>P(null),children:s("common.tryAgain")})]}):null]})}const tr=8e3,nr=300,rr=2e4,sr=16,Dt=new Set(["Alt","Control","Meta","Shift"]),or=new Set(["Backspace","Enter","Tab","Escape","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]),qe=new Set(["navigate","history","reload","tabSelect","tabNew","tabClose"]),ar=new Set(["navigate","tabNew"]);function tt(e){return qe.has(e.type)?!0:e.type==="mouse"?e.action==="down":e.type==="key"?e.action==="down"&&!Dt.has(e.key):e.type==="wheel"||e.type==="text"}const nt=e=>e.type==="key"?`key:${e.code||e.key}`:e.type==="mouse"?`mouse:${e.button}`:e.type,vt=e=>(e.type==="key"||e.type==="mouse")&&e.action==="down",Ct=e=>(e.type==="key"||e.type==="mouse")&&e.action==="up";function lr(e){return e.type!=="key"||Dt.has(e.key)?!0:or.has(e.key)?!1:!e.modifiers||e.modifiers===8&&[...e.key].length===1}function ir(e){const t=e.transport;let r="bot",o="",i=[],c=!1,u=!1,w=!1,v=!1,m=!1,d=!1,g=0,y=Promise.resolve(),E,k;const C=new Set,T=new Set,b=x=>{o=x,e.onTakeStatus(x)},j=x=>{vt(x)&&lr(x)?C.add(nt(x)):Ct(x)&&C.delete(nt(x))},O=()=>!u&&!w&&(m||!v)&&!c&&!C.size&&(r==="held"||r==="bot"&&e.owned()),H=()=>{clearTimeout(E),E=u?void 0:setTimeout(()=>{E=void 0,re()},m?0:tr)},le=()=>{r="releasing",o==="stale"&&b(""),y=y.then(()=>u?void 0:t.release()).catch(()=>{}).then(()=>{r==="releasing"&&(r="bot")})},re=async()=>{if(!O())return;const x=g;await t.drain(),x===g&&O()&&le()},J=()=>{const x=i.filter(B=>ar.has(B.type)),K=i.some(B=>!x.includes(B)&&tt(B));i=x;for(const B of C)T.add(B);return C.clear(),K},Y=async()=>{c=!0;try{for(let x=i.shift();x&&!u;x=i.shift())t.send(x),t.size()>=sr&&await t.settle()}finally{c=!1,i=[]}},$=()=>{r="taking",e.onError(""),b("pending"),clearTimeout(k),k=setTimeout(()=>{!u&&r==="taking"&&b("slow")},nr),y=y.then(async()=>{if(u)return;const x=await t.take().then(K=>({reply:K}),K=>(u||e.onError(K instanceof Error?K.message:String(K)),null));clearTimeout(k),!u&&(x?(r="held",b(x.reply?.waited===!0&&J()?"stale":""),await Y()):(b(""),r="bot",i=[],C.clear()),H())}).catch(()=>{})};return{interact(x){if(u)return;const K=nt(x);if(Ct(x)&&T.delete(K))return;vt(x)&&T.delete(K);const B=r==="taking"||c;if(r!=="held"&&!B){if(!tt(x))return;if(t.stopped()&&!qe.has(x.type)){e.onHalted();return}}if(!(qe.has(x.type)&&B&&i.some(V=>qe.has(V.type)))){if(tt(x)&&(m=!1,o==="stale"&&b("")),j(x),g++,H(),r==="held"&&!B){t.send(x);return}i.push(x),B||$()}},observe(){if(u)return;const x=e.owned();d&&!x&&r==="held"&&!c&&(r="bot",C.clear(),T.clear(),clearTimeout(E),E=void 0),d=x,E===void 0&&x&&H()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||H())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,H()}},hold(x){u||w===x||(w=x,x||H())},leave(){!O()||t.size()||(r="releasing",t.release().catch(()=>{}))},close(){u=!0,clearTimeout(E),clearTimeout(k),i=[],C.clear(),T.clear()}}}function cr(e,t,r){return{send:o=>{e.send(o)},drain:async()=>{},settle:async()=>{},size:()=>0,stopped:()=>!1,take:()=>new Promise((o,i)=>{const c=t.current();if(c?.controller==="you"){o({waited:!1});return}if(!e.send({type:"takeControl"})){i(new Error(s("browser.panel.notConnected")));return}const u=c?.controller==="agent",w=d=>{clearTimeout(v),m(),d()},v=setTimeout(()=>w(()=>i(new Error(s("browser.panel.takeFailed")))),rr),m=t.watch(d=>{d?.controller==="you"?w(()=>o({waited:u})):d?.controller==="another-viewer"?w(()=>i(new Error(r))):d===null&&w(()=>i(new Error(s("browser.panel.viewDisconnected"))))})}),release:async()=>{e.send({type:"releaseControl"})}}}const ur="https://duckduckgo.com/?q=",dr=/^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i,fr=/^[^/?#:@]+:\d+(?:[/?#]|$)/,pr=/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\])(?::|\/|$)/i,hr=new Set(["about:","blob:","chrome:","data:","file:","ftp:","javascript:","mailto:","sms:","ssh:","tel:","view-source:","ws:","wss:"]);function mr(e){return/^([A-Za-z][A-Za-z\d+.-]*):/.exec(e)?.[1]?.toLowerCase().concat(":")}function rt(e){const t=e.includes("://")?e:`${pr.test(e)?"http":"https"}://${e}`;try{const r=new URL(t);return r.protocol==="http:"||r.protocol==="https:"?r.href:null}catch{return null}}function br(e){const t=e.trim();if(!t)return null;if(/^[a-z][a-z\d+.-]*:\/\//i.test(t))return rt(t);if(!/\s/.test(t)){const r=mr(t);if(r!==void 0&&(hr.has(r)||!fr.test(t)))return r==="http:"||r==="https:"?rt(t):null;const o=(t.split(/[/?#]/,1)[0]??"").replace(/^[^@]*@/,""),i=o.replace(/:\d+$/,"");if(i.length<o.length||dr.test(i)||/^[^.]+(?:\.[^.]+)+\.?$/.test(i)){const u=rt(t);if(u)return u}}return`${ur}${encodeURIComponent(t)}`}const xr=5;let Be=null;const it=new Set,Ht=()=>{for(const e of it)e()},wr=e=>(it.add(e),()=>it.delete(e));function yr(){if(typeof document>"u"||typeof HTMLCanvasElement.prototype.captureStream!="function")return!1;const e=HTMLVideoElement.prototype;return document.pictureInPictureEnabled&&typeof e.requestPictureInPicture=="function"||typeof e.webkitSetPresentationMode=="function"}function gr(){return a.useSyncExternalStore(wr,()=>Be?.key??null,()=>null)}function ct(){const e=Be;Be=null,e?.stop(),Ht()}async function kr(e){ct();const t=document.createElement("canvas"),r=t.getContext("2d"),o=e.seed&&e.seed.width>0&&e.seed.height>0?e.seed:null;t.width=o?.width??640,t.height=o?.height??400;const i=t.captureStream();o?r?.drawImage(o,0,0):r?.fillRect(0,0,t.width,t.height);const c=document.createElement("video");c.muted=!0,c.playsInline=!0,c.srcObject=i,c.style.cssText="position:fixed;right:0;bottom:0;width:1px;height:1px;opacity:0;pointer-events:none",document.body.append(c);const u=Bt(t);let w=null,v=!1,m=0,d=null;const g=()=>{Be===k&&ct()},y=()=>{v||(w=_t({access:Lt(e.botId),maxWidth:1280,maxHeight:1280,interactive:!1},{onFrame:C=>{m=0,u.paint(C)},onViewport:()=>{},onConnectedChange:()=>{},onUnauthorized:()=>{if(!v){if(m>=xr){g();return}d=setTimeout(y,1e3*2**m++)}},onGone:g}))},E=()=>{c.webkitPresentationMode!=="picture-in-picture"&&g()},k={key:e.botId,stop:()=>{v=!0,d!==null&&clearTimeout(d),w?.stop(),u.stop(),c.removeEventListener("leavepictureinpicture",g),c.removeEventListener("webkitpresentationmodechanged",E),document.pictureInPictureElement===c?document.exitPictureInPicture().catch(()=>{}):c.webkitPresentationMode==="picture-in-picture"&&c.webkitSetPresentationMode?.("inline");for(const C of i.getTracks())C.stop();c.srcObject=null,c.remove()}};Be=k,Ht();try{await c.play(),c.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise(C=>c.addEventListener("loadedmetadata",C,{once:!0})),document.pictureInPictureEnabled&&typeof c.requestPictureInPicture=="function"?(c.addEventListener("leavepictureinpicture",g),await c.requestPictureInPicture()):(c.addEventListener("webkitpresentationmodechanged",E),c.webkitSetPresentationMode?.("picture-in-picture"))}catch(C){throw g(),C}Be===k&&y()}const vr=[1e3,2e3,4e3,8e3,15e3],Cr=25e3,Sr=5e3,St=32,jt=4096,jr=24e3,Me=(e,t,r)=>Math.max(t,Math.min(r,Number.isFinite(e)?e:0)),Ye=e=>Me(e,-1e4,1e4);function Er(e,t,r,o){const i=t*r/e;return Math.abs(i-o)<=Math.max(1,r/e)?{width:r,height:o}:{width:r,height:Math.round(i)}}function Nr(e){for(let t=2;t+9<e.length;){if(e[t]!==255)return null;const r=e[t+1];if(r>=192&&r<=194)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8]};t+=2+(e[t+2]<<8|e[t+3])}return null}function Et(e){switch(e.type){case"mouse":return{type:"input_mouse",eventType:e.action==="down"?"mousePressed":e.action==="up"?"mouseReleased":"mouseMoved",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:e.button,clickCount:Math.round(Me(e.clickCount,0,3)),modifiers:e.modifiers};case"wheel":return{type:"input_mouse",eventType:"mouseWheel",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:"none",deltaX:Ye(e.deltaX),deltaY:Ye(e.deltaY),modifiers:e.modifiers};case"key":return e.key?{type:"input_keyboard",eventType:e.action==="up"?"keyUp":"keyDown",key:e.key.slice(0,64),code:e.code.slice(0,64),windowsVirtualKeyCode:Math.round(Me(e.keyCode??0,0,255)),modifiers:e.modifiers,...e.text!==void 0?{text:e.text}:{}}:null;case"text":{const t=[];for(let r=0;r<e.text.length;r+=jt)t.push({type:"input_keyboard",eventType:"char",text:e.text.slice(r,r+jt)});return t}case"navigate":return{type:"navigate",url:e.url};case"history":return{type:e.delta<0?"back":"forward"};case"reload":return{type:"reload"};case"tabSelect":return{type:"tab-select",tabId:e.tabId};case"tabClose":return{type:"tab-close",tabId:e.tabId};case"tabNew":return e.url?{type:"tab-new",url:e.url}:{type:"tab-new"};case"restart":return{type:"restart"};case"dialog":return{type:"dialog",accept:e.accept,...e.promptText!==void 0?{promptText:e.promptText.slice(0,4096)}:{}};default:return null}}const Ve=e=>e.type==="input_mouse"&&(e.eventType==="mouseMoved"||e.eventType==="mouseWheel"),ut=e=>e.type==="input_mouse"||e.type==="input_keyboard",Ft=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ft(e)||!ut(e);function Pr(e,t,r=()=>1){let o=[],i=null,c=0,u=!1;const w=d=>{o=o.filter(st),u||(u=!0,t(d))},v=()=>{const d=[o.shift()],g=u?1:r();let y=JSON.stringify(d[0]).length;for(;ut(d[0])&&d.length<g&&o.length&&ut(o[0]);){const E=JSON.stringify(o[0]).length;if(y+E>jr)break;y+=E,d.push(o.shift())}return d},m=()=>{if(i||!o.length)return;const d=c;i=(async()=>{for(;d===c&&o.length;){const g=v();try{await e(g.length===1?g[0]:{type:"input_batch",events:g})}catch(y){if(d!==c)continue;g.length>1&&o.unshift(...g.slice(1).filter(Ft)),w(y)}}})().finally(()=>{i=null,m()})};return{enqueue(d){if(u&&!st(d))return;const g=o.at(-1);if(g&&Ve(d)&&g.type===d.type&&g.eventType===d.eventType&&g.modifiers===d.modifiers&&g.button===d.button){o[o.length-1]=d.eventType==="mouseWheel"?{...d,deltaX:Ye(Number(g.deltaX??0)+Number(d.deltaX??0)),deltaY:Ye(Number(g.deltaY??0)+Number(d.deltaY??0))}:{...d};return}if(o.length>=St){if(Ve(d))return;const y=o.findIndex(Ve);if(y>=0)o.splice(y,1);else if(w(new Error(s("browser.input.tooSlow"))),!st(d)||o.length>=St)return}o.push({...d}),m()},async drain(){for(o=o.filter(d=>!Ve(d));i||o.length;)m(),await i},async settle(){for(;i||o.length;)m(),await i},size:()=>o.length+(i?1:0),stopped:()=>u,clear(){c++,o=[],u=!1}}}function Nt(e,t){const r=e.owned===!0?e.controlling===!0?"you":"agent":e.held===!0?"another-viewer":"unclaimed",o=e.dialog,i=o&&typeof o.type=="string"&&typeof o.message=="string"&&typeof o.defaultValue=="string"?{type:o.type,message:o.message,defaultValue:o.defaultValue}:null;return{canOperate:!0,controller:r,generation:t,dialog:i,...e.owned===!0?{owned:!0}:{}}}function Tr(e,t,r,o={viewer:""},i={},c=null){let u=!1,w=!1,v=!1,m=null,d="",g=0,y=0,E=0,k=null,C=null,T=null,b=1,j=c,O=null;const H=(P,R)=>{P.close(),m=null;const D=d!=="";if(D&&(o.viewer=d),d="",k=null,$.clear(),D&&t.onConnectedChange(!1),u)return;const U=R?vr[y++]:void 0;if(U===void 0){u=!0,w=R,t.onGone?.();return}T=setTimeout(K,U)},le=(P,R)=>P?.status!==404||!m||!R||d!==R?!1:(H(m,!0),!0),re=(P,R)=>r(P,R).catch(D=>{throw le(D,R),D}),J=P=>t.onMessage?.({type:"notice",message:P}),Y=P=>{const R=P?.notice;typeof R=="string"&&R&&J(R)},$=Pr(P=>d?re(P,d).then(Y):Promise.reject(new Error(s("browser.panel.connectionFirst"))),P=>{J(P instanceof Error?P.message:String(P))},()=>b),x=()=>{const P=j,R=d;O||!P||!R||(O=P,r({type:"resize",width:Math.round(P.width),height:Math.round(P.height)},R).catch(()=>{}).finally(()=>{O=null,j!==P&&d===R&&x()}))},K=()=>{if(T=null,u)return;const P=new URLSearchParams(o.viewer?{resume:o.viewer}:{}),R=j;j&&(P.set("width",String(Math.round(j.width))),P.set("height",String(Math.round(j.height))));const D=zt(P.size?`?${P.toString()}`:"",i),U=new EventSource(`/api/bots/${encodeURIComponent(e)}/browser/live${D}`);m=U,g=Date.now();const q=(N,A)=>U.addEventListener(N,G=>{if(m===U){g=Date.now();try{A(JSON.parse(G.data))}catch{}}});q("waiting",()=>t.onMessage?.({type:"starting"})),q("ready",N=>{typeof N.viewerId!="string"||!N.viewerId||(d=N.viewerId,b=Number.isSafeInteger(N.inputBatch)?Math.max(1,Math.min(Number(N.inputBatch),64)):1,o.viewer="",t.onConnectedChange(!0),j!==R&&x())}),q("heartbeat",()=>{y=0}),q("frame",N=>{if(!d||typeof N.data!="string"||typeof N.seq!="number")return;const A=atob(N.data),G=new Uint8Array(A.length);for(let F=0;F<A.length;F++)G[F]=A.charCodeAt(F);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const F=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(F.width!==C?.width||F.height!==C.height)&&(C=F,t.onViewport(F))}t.onFrame(G.buffer),r({type:"ack",seq:N.seq},d).catch(()=>{})}),q("tabs",N=>{Array.isArray(N.tabs)&&t.onMessage?.({type:"tabs",tabs:N.tabs})}),q("url",N=>{typeof N.url=="string"&&t.onMessage?.({type:"url",url:N.url})}),q("status",N=>{C||!(Number(N.viewportWidth)>0&&Number(N.viewportHeight)>0)||(C={width:Number(N.viewportWidth),height:Number(N.viewportHeight)},t.onViewport(C))}),q("control",N=>{const A=Nt(N,E);k&&A.controller===k.controller&&A.owned===k.owned&&JSON.stringify(A.dialog)===JSON.stringify(k.dialog)||(k=A.controller===k?.controller?A:Nt(N,++E),t.onControl?.(k))}),U.addEventListener("error",N=>{if(m!==U)return;let A=!(N instanceof MessageEvent);if(N instanceof MessageEvent)try{const G=JSON.parse(N.data);A=G.retryable===!0,G.asleep===!0?t.onMessage?.({type:"asleep"}):typeof G.message=="string"&&t.onMessage?.({type:"notice",message:G.message,...typeof G.errorKey=="string"?{errorKey:G.errorKey,...G.errorParams!==void 0?{errorParams:G.errorParams}:{}}:{}})}catch{}H(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&H(m,!0),!(!P||T===null&&!(u&&w))&&(T!==null&&clearTimeout(T),u=!1,w=!1,y=0,K()))},V=()=>{document.visibilityState!=="hidden"&&B(!0)},Z=setInterval(()=>B(!1),Sr),W=typeof window>"u"?null:window;return W?.addEventListener("focus",V),W?.addEventListener("online",V),W&&document.addEventListener("visibilitychange",V),{send:P=>{if(P.type==="resize")return j={width:P.width,height:P.height},x(),!0;if(!d||!k?.canOperate||!["takeControl","restart"].includes(P.type)&&k.controller!=="you")return!1;const R=Et(P);if(!R)return!1;if(P.type==="dialog"&&!Array.isArray(R))return re(R,d).catch(D=>J(D instanceof Error?D.message:String(D))),!0;for(const D of Array.isArray(R)?R:[R])$.enqueue(D);return!0},stop:()=>{u=!0,v=!0,clearInterval(Z),W?.removeEventListener("focus",V),W?.removeEventListener("online",V),W&&document.removeEventListener("visibilitychange",V),T!==null&&clearTimeout(T),m?.close(),m=null,d&&(o.viewer=d),d="",$.clear()},transport:{send:P=>{const R=d?Et(P):null;if(R)for(const D of Array.isArray(R)?R:[R])$.enqueue(D)},drain:()=>$.drain(),settle:()=>$.settle(),size:()=>$.size(),stopped:()=>$.stopped(),take:async()=>{if(!d)throw new Error(s("browser.panel.notConnected"));return{waited:(await re({type:"take"},d))?.waited===!0}},release:async()=>{d&&await re({type:"release"},d)}}}}const ot="Another window or device controls this browser. Hand control back there to use it here.",Mr=/^\/(?:v\d+\/)?signin\/(?:v\d+\/)?challenge\/(?:pk|sk)(?:\/|$)/u;function Rr(e){let t;try{t=new URL(e)}catch{return null}return t.hostname==="accounts.google.com"&&Mr.test(t.pathname)?"google":null}const Pt="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed",at={url:"",loading:!1,canGoBack:!1,canGoForward:!1};function Ir(e){return Array.isArray(e)?e.flatMap(t=>t&&typeof t=="object"&&typeof t.tabId=="string"?[{tabId:t.tabId,title:typeof t.title=="string"?t.title:"",url:typeof t.url=="string"?t.url:"",active:t.active===!0}]:[]):[]}function zr({bot:e,signIn:t,page:r}){const{state:o}=dt(),[i,c]=a.useState(!1),u=o.config?.browserEngine?.engine==="chrome"&&!i,[w,v]=a.useState(0),[m,d]=a.useState(!1),[g,y]=a.useState(null),[E,k]=a.useState([]),[C,T]=a.useState(at),[b,j]=a.useState({mode:"fill"}),[O,H]=a.useState(1),[le,re]=a.useState(null),[J,Y]=a.useState(""),[$,x]=a.useState(""),[K,B]=a.useState(!1),[V,Z]=a.useState(!1),[W,te]=a.useState(""),[P,R]=a.useState(!1),[D,U]=a.useState(!1),[q,N]=a.useState(!1),[A,G]=a.useState(!1),[ie,pe]=a.useState(!1),[F,Ee]=a.useState(!1),[Oe,We]=a.useState(""),Ke=gr(),Ne=xn(),ue=a.useRef(null),Q=a.useRef(null),Re=a.useRef(null),be=a.useRef(null),ve=a.useRef(null),de=a.useRef(null),he=a.useRef(null),Ie=a.useRef(new Set),ee=a.useRef(null),Ce=a.useRef({key:"",viewer:""}),ze=a.useRef(!1),De=a.useRef(0),He=a.useRef(0),Fe=a.useRef(null),xe=a.useRef(null),me=a.useRef({openSignInPage:()=>{},takeControl:()=>{}}),ce=o.computerControl?.[e.id]?.help?.place==="browser",we=on(o.config?.team,e.threadId).threadId;ze.current=P||ce;const Pe=e.browserProfile==="guest"?s("browser.panel.temporary"):o.config?.browserProfiles?.find(h=>h.id===e.browserProfile)?.name??s("browser.panel.ownBrowser",{name:e.name});a.useEffect(()=>{D?be.current?.showModal():be.current?.close()},[D]),a.useEffect(()=>{ee.current?.hold(q),q?ve.current?.showModal():ve.current?.close()},[q]);const l=a.useCallback(()=>{Z(!1),x(""),c(!1),v(h=>h+1)},[]);a.useEffect(()=>{c(!1)},[e.id,e.browserProfile,we]),a.useEffect(()=>{k([]),re(null),T(u?at:{...at,canGoBack:!0,canGoForward:!0}),B(!1),Z(!1),te(""),xe.current=null},[e.id,e.browserProfile,we,w,u]);const p=a.useCallback((h,L)=>{const fe=we?{threadId:we}:{};if(u)return _t({access:Lt(e.id,window.location,fe),...h},L);const ke=`${e.id}
2
2
  ${e.browserProfile??""}${we?`
3
3
  ${we}`:""}`;return Ce.current.key!==ke&&(Ce.current={key:ke,viewer:""}),Tr(e.id,L,(Ut,Wt)=>Ge(zt(`/api/bots/${encodeURIComponent(e.id)}/browser/action`,fe),{method:"POST",body:JSON.stringify({...Ut,viewerId:Wt}),timeoutMs:12e4}),Ce.current,fe,{width:h.width,height:h.height})},[e.id,e.browserProfile,we,u]),S=a.useCallback(h=>{if(he.current?.controller==="another-viewer"){x(ot);return}ee.current?.interact(h)},[]),z=a.useCallback(h=>{if(de.current=h,ee.current?.close(),ee.current=null,!h)return;const L="transport"in h?h.transport:cr(h,{current:()=>he.current,watch:ke=>(Ie.current.add(ke),()=>{Ie.current.delete(ke)})},ot),fe=ir({transport:L,owned:()=>he.current?.controller==="you",mine:()=>he.current?.owned===!0,onTakeStatus:Y,onError:x,onHalted:()=>x(s("browser.input.tooSlow"))});fe.keep(ze.current),ee.current=fe},[]),I=a.useCallback(h=>{const L=he.current;he.current=h,y(h),L?.controller==="you"&&h?.controller!=="you"&&R(!1),h===null&&Y("");for(const fe of Ie.current)fe(h);ee.current?.observe()},[]),X=a.useCallback(h=>{if(h.type==="tabs"){const L=Ir(h.tabs);k(L);const fe=L.find(ke=>ke.active);fe&&(T(ke=>({...ke,url:fe.url})),xe.current=fe.url,me.current.openSignInPage())}else if(h.type==="nav"&&typeof h.url=="string")T({url:h.url,loading:h.loading===!0,canGoBack:h.canGoBack===!0,canGoForward:h.canGoForward===!0}),xe.current=h.url,me.current.openSignInPage();else if(h.type==="url"&&typeof h.url=="string")T(L=>({...L,url:h.url})),xe.current=h.url,me.current.openSignInPage();else if(h.type==="extensions")re(gn(h.extensions));else if(h.type==="viewport"){const L=h.setting;L&&(L.mode==="fill"||L.mode==="preset")&&j(L),typeof h.zoom=="number"&&H(h.zoom)}else h.type==="starting"?B(!0):(h.type==="asleep"||h.type==="awake")&&te(h.type==="asleep"?"asleep":"")},[]);a.useEffect(()=>{ee.current?.keep(P||ce)},[P,ce]);const f=()=>{R(!0),ee.current?.keep(!0),ee.current?.takeControl()},M=()=>{R(!1),ee.current?.handBack()},se=()=>{const h=Fe.current;!h||xe.current===null||(Fe.current=null,(!xe.current||xe.current==="about:blank")&&S({type:"navigate",url:h}))};me.current={openSignInPage:se,takeControl:f},a.useEffect(()=>{!t||!m||De.current===t.nonce||(De.current=t.nonce,Fe.current=t.url,me.current.takeControl(),me.current.openSignInPage())},[t,m]),a.useEffect(()=>{if(!(!r||!m||He.current===r.nonce)){if(W){W==="asleep"&&de.current?.send({type:"wake"})&&te("waking");return}He.current=r.nonce,S({type:"tabNew",url:r.url})}},[r,m,W,S]),a.useEffect(()=>{const h=()=>pe(!!ue.current&&document.fullscreenElement===ue.current);return document.addEventListener("fullscreenchange",h),()=>document.removeEventListener("fullscreenchange",h)},[]);const ye=()=>{const h=!!ue.current&&document.fullscreenElement===ue.current;h&&F&&Ee(!1),(h?document.exitFullscreen():ue.current?.requestFullscreen())?.catch(()=>x(s(h?"browser.panel.exitFullscreenFailed":"browser.panel.fullscreenUnavailable")))},ae=()=>{ie&&document.fullscreenElement===ue.current&&document.exitFullscreen().catch(()=>{}),Ee(h=>!h)};a.useEffect(()=>{if(!F)return;const h=L=>{L.key!=="Escape"||L.defaultPrevented||(L.preventDefault(),ie&&document.fullscreenElement===ue.current&&document.exitFullscreen().catch(()=>{}),Ee(!1))};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[F,ie]);const _=()=>{window.confirm(s("browser.panel.confirmRestart"))&&(x(""),de.current?.send({type:"restart"})||x(s("browser.panel.notConnected")))},oe=()=>{m&&de.current?.send({type:"wake"})?te("waking"):l()},ge=()=>{if(Ke===e.id){ct();return}kr({botId:e.id,seed:Re.current?.canvas()??null}).catch(()=>x(s("browser.panel.pipUnavailable")))},ne=g?.controller==="another-viewer",Se=m&&!ne,Te=g?.controller==="you",Je=Ne||Te;a.useEffect(()=>{Je||(d(!1),x(""))},[Je]);const Ze=m&&Te,$t=u&&yr(),pt=Rr(C.url);return n.jsxs("div",{ref:ue,className:F?"fixed inset-0 z-50 flex flex-col overflow-hidden bg-card text-ink":"flex min-h-0 flex-1 flex-col overflow-hidden rounded-2xl border border-hairline/40 bg-card text-ink","data-browser-transport":u?"stream":"live",children:[n.jsx(yn,{ref:Q,botName:e.name,tabs:E,nav:C,connected:m,control:g,takeStatus:J,hint:s(P||ce?"browser.control.keptHint":"browser.control.yoursHint",{name:e.name}),commandsReady:Se,profileName:Pe,fullscreen:ie,maximized:F,onCommand:S,onAddress:h=>{const L=br(h);Se&&L?S({type:"navigate",url:L}):h.trim()&&x(s("browser.panel.enterAddress"))},onTake:f,onHandBack:M,onFullscreen:ye,onMaximize:ae,onProfiles:()=>{ee.current?.handBack(),U(!0)},menu:n.jsxs(n.Fragment,{children:[u?n.jsx(vn,{ready:m&&Te,extensions:le,onList:()=>de.current?.send({type:"extensions"}),onOpen:h=>de.current?.send({type:"openExtension",id:h})}):null,n.jsx(Sn,{stream:u,ready:m&&Te,typing:Ze,setting:b,zoom:O,pip:$t?{open:Ke===e.id}:null,onViewport:h=>de.current?.send({type:"viewport",setting:h}),onZoom:h=>de.current?.send({type:"zoom",factor:h}),onPip:ge,onType:()=>{G(!1),N(!0)},onSecret:()=>{G(!0),N(!0)},onReconnect:l,onRestart:_})]})}),$&&n.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-2 border-b border-hairline/30 px-3 py-2 text-[12px] text-danger",children:[n.jsx("span",{children:$}),!m&&n.jsx("button",{className:"shrink-0 underline",onClick:l,children:s("browser.panel.reconnect")})]}),J==="stale"&&n.jsx("div",{role:"status",className:"shrink-0 border-b border-hairline/30 px-3 py-1.5 text-[12px] text-accent-text",children:s("browser.control.stale",{name:e.name})}),pt&&Oe!==C.url&&n.jsx(En,{wall:pt,botName:e.name,onDismiss:()=>We(C.url)}),n.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col bg-inset/40",children:[Je?n.jsx(er,{ref:Re,connect:p,input:S,label:s("browser.panel.pageLabel",{name:e.name}),onClient:z,onControl:I,onMessage:X,onConnectedChange:h=>{d(h),h&&(B(!1),Z(!1),x(""))},onFirstFrame:()=>B(!1),onUnauthorized:()=>{u?c(!0):Z(!0)},onGone:()=>Z(!0),onClose:(h,L)=>{h===1013&&L&&x(L)},onLeave:()=>Q.current?.focus()},`${w}:${u?"stream":"live"}:${e.browserProfile??""}`):null,W||ne||V||!m||K?n.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-card/95 p-6 text-center text-[13px] text-ink-secondary",children:[W?n.jsx(cn,{size:24}):ne?n.jsx(Rt,{size:24}):V?n.jsx(lt,{size:24}):n.jsx(Xe,{size:24,className:"animate-spin"}),n.jsx("span",{children:W?s("browser.panel.asleep"):ne?ot:V?s("browser.panel.disconnected"):K?u?s("browser.panel.starting"):s("browser.live.botBusy",{name:e.name}):s("browser.panel.opening")}),W?n.jsx("button",{type:"button",disabled:W==="waking",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset disabled:opacity-60",onClick:oe,children:s(W==="waking"?"browser.panel.waking":"browser.panel.wake")}):V?n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:l,children:s("browser.panel.reconnect")}):null]}):null]}),n.jsxs("dialog",{ref:be,onClose:()=>U(!1),onClick:h=>{h.target===h.currentTarget&&U(!1)},className:"m-auto w-[min(420px,calc(100%-32px))] max-h-[80vh] overflow-auto rounded-2xl border border-hairline/50 bg-card p-5 text-ink shadow-2xl backdrop:bg-black/40",children:[n.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[n.jsx("h2",{className:"text-[15px] font-medium",children:s("browser.panel.profiles")}),n.jsx("button",{className:Pt,"aria-label":s("browser.panel.closeProfiles"),onClick:()=>U(!1),children:n.jsx(Ue,{size:16})})]}),(ne||Te&&J!=="")&&n.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s(ne?"browser.profiles.heldElsewhere":"browser.profiles.busy")}),n.jsx(an,{bot:e,disabled:ne||J==="pending"||J==="slow",onProfileChanged:()=>{U(!1),l()}})]}),n.jsxs("dialog",{ref:ve,onClose:()=>{const h=ve.current?.querySelector("input");h&&(h.value=""),N(!1)},className:"m-auto w-[min(420px,calc(100%-32px))] rounded-2xl border border-hairline/50 bg-card p-5 text-ink shadow-2xl backdrop:bg-black/40",children:[n.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[n.jsx("h2",{className:"text-[14px] font-medium",children:A?s("browser.typeSecret.title"):s("browser.panel.typeTextTitle")}),n.jsx("button",{className:Pt,"aria-label":s("browser.panel.closeTyping"),onClick:()=>N(!1),children:n.jsx(Ue,{size:16})})]}),n.jsxs("form",{className:"flex flex-col gap-3",onSubmit:h=>{h.preventDefault();const L=h.currentTarget.elements.namedItem("pageText");Ze&&L.value&&(S({type:"text",text:L.value}),L.value="",N(!1))},children:[n.jsx("input",{name:"pageText",type:A?"password":"text","aria-label":A?s("browser.typeSecret.field"):s("browser.panel.typeTextField"),autoComplete:A?"new-password":"off",spellCheck:!1,maxLength:4096,placeholder:A?"••••••••":s("browser.panel.typeTextPlaceholder"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"},A?"secret":"text"),A&&n.jsxs("p",{className:"flex items-center gap-1 text-[12px] text-ink-tertiary",children:[n.jsx(It,{size:11,"aria-hidden":"true"}),s("browser.typeSecret.note")]}),n.jsx("button",{disabled:!Ze,className:"self-end rounded-lg bg-accent px-4 py-2 text-[12px] text-accent-ink disabled:opacity-40",children:s("browser.panel.typeButton")})]})]})]})}function Hr({bot:e,signIn:t,page:r}){const{state:o}=dt(),i=o.config?.browserEngine,[c,u]=a.useState(!1),[w,v]=a.useState(null),[m,d]=a.useState(null);a.useEffect(()=>{let E=!0;return Ge("/api/auth/session").then(k=>{E&&d(k.scopes.includes("admin"))}).catch(()=>{E&&d(!1)}),()=>{E=!1}},[]);const g=c||i?.installing===!0,y=async()=>{v(null),u(!0);try{await Ge("/api/browser-engine/install",{method:"POST"})}catch(E){v(E instanceof Error?E.message:String(E))}finally{u(!1)}};return e.browser===!1?n.jsx("div",{className:"p-5 text-[13px] text-ink-secondary",children:s("browser.panel.enableBot")}):i?.kind==="engine"&&!g&&!i.installError?n.jsx(zr,{bot:e,signIn:t,page:r},e.id):n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-start justify-center gap-3 rounded-xl bg-card p-5",children:[n.jsx("div",{className:"text-[15px] font-medium text-ink",children:i?.kind==="engine"?s("browser.panel.installIncomplete"):s("browser.panel.engineNotInstalled")}),n.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:i?.kind==="engine"?s("browser.panel.installIncompleteHelp"):i?.installable&&m!==!1?s("browser.panel.engineNotInstalledHelp",{name:e.name}):sn(o.config)}),i?.installable||i?.kind==="engine"?n.jsx("button",{type:"button",onClick:()=>{y()},disabled:g||m!==!0,className:"rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-60",children:g?s("browser.panel.installing"):i?.kind==="engine"?s("browser.panel.retryInstall"):s("browser.panel.installEngine")}):null,(i?.installError||w)&&n.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:w??i?.installError})]})}export{Hr as B,xn as u};
@@ -1 +1 @@
1
- import{t,r as y,j as s}from"./styles-Cm26P6hN.js";import{Z as Y,u as _,bb as ee,D as R,G as se,T as te,n as B,A as z}from"./App-DPG1sq1r.js";import{r as ne,i as ie}from"./index-BkcZ5EE3.js";import{S as q}from"./SignedInSites-Dxnqcjlx.js";import{P as re}from"./PlacesRail-DnedL3jM.js";function G(i){return i.map(({id:l,name:x,browser:c})=>({id:l,name:x,...c?{browser:c}:{}}))}function ae(i,l){return{browserProfiles:G(l),expectedBrowserProfiles:G(i)}}function oe(){return`profile-${Y().replaceAll("-","")}`}function J(i,l){const x=i.filter(g=>g.browserProfile===l&&g.busy);if(!x.length)return null;const c=x.map(g=>g.name).join(", ");return x.length===1?t("settings.profiles.busyOne",{names:c}):t("settings.profiles.busyMany",{names:c})}function le(i,l){return i&&l?{threadId:l}:{}}function ue(i,l){const x=new URLSearchParams(l).toString();return x?`${i}${i.includes("?")?"&":"?"}${x}`:i}function pe({bot:i,onProfileChanged:l,disabled:x=!1}){const{state:c,dispatch:g,flushBotPatches:Z}=_(),r=c.config?.browserProfiles??[],v=c.config?.browserEngine?.myChrome===!0,b=c.config?.browserEngine?.myChromeOn,E=c.config?.browserEngine?.myChromeLendable===!0,w=c.bots??[],o=i?w.find(e=>e.id===i.id)??i:void 0,[O,L]=y.useState(null),[S,f]=y.useState(!1),[N,A]=y.useState(""),[h,j]=y.useState(null),[F,u]=y.useState(""),k=y.useId(),a=S||x||O!==!0;y.useEffect(()=>{let e=!0;return ne().then(n=>{e&&L(ie(n))}),()=>{e=!1}},[]);const T=async e=>{if(u(e instanceof Error?e.message:t("settings.profiles.saveError")),e instanceof z&&e.status===409)try{const n=await B("/api/config");g({type:"configStatus",config:n})}catch{u(t("settings.profiles.refreshError"))}e instanceof z&&(e.status===401||e.status===403)&&L(!1)},C=async e=>{try{const n=await B("/api/config",{method:"PATCH",body:JSON.stringify(ae(r,e))});return g({type:"configStatus",config:n}),!0}catch(n){return await T(n),!1}},K=async()=>{if(!(a||!N.trim()||r.length>=20)){f(!0),u("");try{await C([...r,{id:oe(),name:N.trim()}])&&A("")}finally{f(!1)}}},Q=async()=>{if(!(a||!h?.name.trim())){if(!r.some(e=>e.id===h.id)){u(t("settings.profiles.removed"));return}f(!0),u("");try{await C(r.map(e=>e.id===h.id?{...e,name:h.name.trim()}:e))&&j(null)}finally{f(!1)}}},V=async e=>{if(a)return;const n=J(w,e.id);if(n)return u(n);const p=w.filter(m=>m.browserProfile===e.id),$=p.length?` ${t("settings.profiles.deleteUsers",{names:p.map(m=>m.name).join(", ")})}`:"";if(window.confirm(t("settings.profiles.confirm",{name:e.name,bots:$}))){f(!0),u("");try{await C(r.filter(m=>m.id!==e.id))&&(h?.id===e.id&&j(null),o?.browserProfile===e.id&&l?.())}finally{f(!1)}}},W=async(e,n)=>{if(!(a||(e.browser??"")===n)){f(!0),u("");try{await C(r.map(p=>p.id===e.id?{...p,browser:n==="chrome"?"chrome":void 0}:p))}finally{f(!1)}}},X=async e=>{if(!(a||!o||o.busy||e===(o.browserProfile??""))){f(!0),u("");try{await Z(o.id);const n=await B(`/api/bots/${encodeURIComponent(o.id)}`,{method:"PATCH",body:JSON.stringify({browserProfile:e||null})});g({type:"botPatched",bot:n.bot}),l?.()}catch(n){await T(n)}finally{f(!1)}}};if(O===!1)return s.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.profiles.ownerOnly")});const I="min-w-0 flex-1 rounded-md border border-hairline/40 bg-inset px-2.5 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50",P="shrink-0 rounded-md bg-control px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",d=o?.browserProfile??"",M=r.find(e=>e.id===d),U=e=>w.filter(n=>n.browserProfile===e).map(n=>n.name),D=e=>e?.browser==="chrome"&&(v||E),H=s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeHint")}),b&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeLent",{name:b.name,device:ee(b.device)})}),b?.online===!1&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeLentOffline",{name:b.name})})]});return s.jsxs("div",{className:"flex min-w-0 flex-col gap-3","aria-busy":S,children:[o&&s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:`${k}-profile`,className:"text-[12px] font-medium text-ink",children:t("settings.profiles.browserSession")}),s.jsxs(R,{className:"w-full",id:`${k}-profile`,value:d,disabled:a||o.busy,onChange:e=>{X(e.target.value)},children:[s.jsx("option",{value:"",children:t("settings.profiles.own")}),r.map(e=>s.jsx("option",{value:e.id,children:e.name},e.id)),s.jsx("option",{value:"guest",children:t("settings.profiles.temporary")}),d&&d!=="guest"&&!r.some(e=>e.id===d)?s.jsx("option",{value:d,disabled:!0,children:t("settings.profiles.removed")}):null]}),s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:o.busy?t("settings.profiles.stopToSwitch"):d==="guest"?t("settings.profiles.temporaryHint"):t("settings.profiles.sharedHint")}),D(M)?s.jsxs(s.Fragment,{children:[H,!v&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeShare")})]}):(d===""||M)&&s.jsx(q,{target:{bot:o.id},scope:le(c.config?.team,i?.threadId),sharedBy:d?U(d):[o.name],disabled:a},`${o.id}:${d}`)]}),s.jsxs("details",{open:!o,className:"min-w-0",children:[s.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("settings.profiles.manage")}),s.jsxs("div",{className:"mt-3 flex flex-col gap-3",children:[s.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:e=>{e.preventDefault(),K()},children:[s.jsx("label",{htmlFor:`${k}-new`,className:"sr-only",children:t("settings.profiles.newName")}),s.jsx("input",{id:`${k}-new`,value:N,onChange:e=>A(e.target.value),maxLength:40,required:!0,disabled:a||r.length>=20,placeholder:t("settings.profiles.newName"),className:I}),s.jsxs("button",{type:"submit",disabled:a||!N.trim()||r.length>=20,className:`${P} flex items-center gap-1`,children:[s.jsx(re,{size:13}),t("settings.profiles.create")]})]}),r.length>=20&&s.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("settings.profiles.limit")}),!v&&r.length>0&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t(E?"settings.profiles.myChromeShare":"settings.profiles.myChromeUnavailable")}),!r.length&&s.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.profiles.sharedEmpty")}),s.jsx("div",{className:"divide-y divide-hairline/30",children:r.map(e=>{const n=U(e.id),p=J(w,e.id),$=D(e);return s.jsxs("div",{className:"flex flex-col gap-1 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(se,{size:14,className:"shrink-0 text-ink-secondary"}),h?.id===e.id?s.jsxs("form",{className:"flex min-w-0 flex-1 flex-wrap gap-2",onSubmit:m=>{m.preventDefault(),Q()},children:[s.jsx("input",{autoFocus:!0,value:h.name,onChange:m=>j({id:e.id,name:m.target.value}),maxLength:40,required:!0,disabled:a,className:I,"aria-label":t("settings.profiles.nameAria")}),s.jsx("button",{type:"submit",disabled:a||!h.name.trim(),className:P,children:t("common.save")}),s.jsx("button",{type:"button",disabled:S,onClick:()=>j(null),className:P,children:t("common.cancel")})]}):s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",disabled:a,onClick:()=>{j({id:e.id,name:e.name}),u("")},className:"min-w-0 flex-1 truncate text-left text-[13px] font-medium text-ink hover:underline disabled:opacity-50",title:t("settings.profiles.rename"),children:e.name}),s.jsxs("button",{type:"button",onClick:()=>{V(e)},disabled:a||!!p,title:p??t("settings.profiles.deleteTitle"),"aria-label":`${t("common.delete")} ${e.name}`,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:[s.jsx(te,{size:13}),t("common.delete")]})]})]}),s.jsx("p",{className:"break-words pl-6 text-[11px] text-ink-secondary",children:n.length?t("settings.profiles.usedBy",{names:n.join(", ")}):t("settings.profiles.notInUse")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-2 pl-6 pt-1",children:[s.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[t("settings.profiles.browserLabel"),s.jsxs(R,{size:"sm",value:e.browser??"",disabled:a,onChange:m=>{W(e,m.target.value)},children:[s.jsx("option",{value:"",children:t("settings.profiles.builtIn")}),s.jsx("option",{value:"chrome",disabled:!v,children:t("settings.profiles.myChrome")})]})]}),$?H:s.jsx(q,{target:{profile:e.id},sharedBy:n,disabled:a})]})]},e.id)})})]})]}),F&&s.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:F})]})}export{pe as B,le as b,ue as w};
1
+ import{t,r as y,j as s}from"./styles-6RbfQIY7.js";import{_ as Y,u as Z,bc as ee,D as R,G as se,T as te,n as B,A as z}from"./App-DRnqqiJP.js";import{r as ne,i as ie}from"./index-COnd2OMZ.js";import{S as q}from"./SignedInSites-CisTAQW0.js";import{P as re}from"./PlacesRail-yZdo57pP.js";function G(i){return i.map(({id:l,name:x,browser:c})=>({id:l,name:x,...c?{browser:c}:{}}))}function ae(i,l){return{browserProfiles:G(l),expectedBrowserProfiles:G(i)}}function oe(){return`profile-${Y().replaceAll("-","")}`}function J(i,l){const x=i.filter(g=>g.browserProfile===l&&g.busy);if(!x.length)return null;const c=x.map(g=>g.name).join(", ");return x.length===1?t("settings.profiles.busyOne",{names:c}):t("settings.profiles.busyMany",{names:c})}function le(i,l){return i&&l?{threadId:l}:{}}function ue(i,l){const x=new URLSearchParams(l).toString();return x?`${i}${i.includes("?")?"&":"?"}${x}`:i}function pe({bot:i,onProfileChanged:l,disabled:x=!1}){const{state:c,dispatch:g,flushBotPatches:_}=Z(),r=c.config?.browserProfiles??[],v=c.config?.browserEngine?.myChrome===!0,b=c.config?.browserEngine?.myChromeOn,E=c.config?.browserEngine?.myChromeLendable===!0,w=c.bots??[],o=i?w.find(e=>e.id===i.id)??i:void 0,[O,L]=y.useState(null),[S,f]=y.useState(!1),[N,A]=y.useState(""),[h,j]=y.useState(null),[F,u]=y.useState(""),k=y.useId(),a=S||x||O!==!0;y.useEffect(()=>{let e=!0;return ne().then(n=>{e&&L(ie(n))}),()=>{e=!1}},[]);const T=async e=>{if(u(e instanceof Error?e.message:t("settings.profiles.saveError")),e instanceof z&&e.status===409)try{const n=await B("/api/config");g({type:"configStatus",config:n})}catch{u(t("settings.profiles.refreshError"))}e instanceof z&&(e.status===401||e.status===403)&&L(!1)},C=async e=>{try{const n=await B("/api/config",{method:"PATCH",body:JSON.stringify(ae(r,e))});return g({type:"configStatus",config:n}),!0}catch(n){return await T(n),!1}},K=async()=>{if(!(a||!N.trim()||r.length>=20)){f(!0),u("");try{await C([...r,{id:oe(),name:N.trim()}])&&A("")}finally{f(!1)}}},Q=async()=>{if(!(a||!h?.name.trim())){if(!r.some(e=>e.id===h.id)){u(t("settings.profiles.removed"));return}f(!0),u("");try{await C(r.map(e=>e.id===h.id?{...e,name:h.name.trim()}:e))&&j(null)}finally{f(!1)}}},V=async e=>{if(a)return;const n=J(w,e.id);if(n)return u(n);const p=w.filter(m=>m.browserProfile===e.id),$=p.length?` ${t("settings.profiles.deleteUsers",{names:p.map(m=>m.name).join(", ")})}`:"";if(window.confirm(t("settings.profiles.confirm",{name:e.name,bots:$}))){f(!0),u("");try{await C(r.filter(m=>m.id!==e.id))&&(h?.id===e.id&&j(null),o?.browserProfile===e.id&&l?.())}finally{f(!1)}}},W=async(e,n)=>{if(!(a||(e.browser??"")===n)){f(!0),u("");try{await C(r.map(p=>p.id===e.id?{...p,browser:n==="chrome"?"chrome":void 0}:p))}finally{f(!1)}}},X=async e=>{if(!(a||!o||o.busy||e===(o.browserProfile??""))){f(!0),u("");try{await _(o.id);const n=await B(`/api/bots/${encodeURIComponent(o.id)}`,{method:"PATCH",body:JSON.stringify({browserProfile:e||null})});g({type:"botPatched",bot:n.bot}),l?.()}catch(n){await T(n)}finally{f(!1)}}};if(O===!1)return s.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.profiles.ownerOnly")});const I="min-w-0 flex-1 rounded-md border border-hairline/40 bg-inset px-2.5 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50",P="shrink-0 rounded-md bg-control px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",d=o?.browserProfile??"",M=r.find(e=>e.id===d),U=e=>w.filter(n=>n.browserProfile===e).map(n=>n.name),D=e=>e?.browser==="chrome"&&(v||E),H=s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeHint")}),b&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeLent",{name:b.name,device:ee(b.device)})}),b?.online===!1&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeLentOffline",{name:b.name})})]});return s.jsxs("div",{className:"flex min-w-0 flex-col gap-3","aria-busy":S,children:[o&&s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:`${k}-profile`,className:"text-[12px] font-medium text-ink",children:t("settings.profiles.browserSession")}),s.jsxs(R,{className:"w-full",id:`${k}-profile`,value:d,disabled:a||o.busy,onChange:e=>{X(e.target.value)},children:[s.jsx("option",{value:"",children:t("settings.profiles.own")}),r.map(e=>s.jsx("option",{value:e.id,children:e.name},e.id)),s.jsx("option",{value:"guest",children:t("settings.profiles.temporary")}),d&&d!=="guest"&&!r.some(e=>e.id===d)?s.jsx("option",{value:d,disabled:!0,children:t("settings.profiles.removed")}):null]}),s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:o.busy?t("settings.profiles.stopToSwitch"):d==="guest"?t("settings.profiles.temporaryHint"):t("settings.profiles.sharedHint")}),D(M)?s.jsxs(s.Fragment,{children:[H,!v&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t("settings.profiles.myChromeShare")})]}):(d===""||M)&&s.jsx(q,{target:{bot:o.id},scope:le(c.config?.team,i?.threadId),sharedBy:d?U(d):[o.name],disabled:a},`${o.id}:${d}`)]}),s.jsxs("details",{open:!o,className:"min-w-0",children:[s.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("settings.profiles.manage")}),s.jsxs("div",{className:"mt-3 flex flex-col gap-3",children:[s.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:e=>{e.preventDefault(),K()},children:[s.jsx("label",{htmlFor:`${k}-new`,className:"sr-only",children:t("settings.profiles.newName")}),s.jsx("input",{id:`${k}-new`,value:N,onChange:e=>A(e.target.value),maxLength:40,required:!0,disabled:a||r.length>=20,placeholder:t("settings.profiles.newName"),className:I}),s.jsxs("button",{type:"submit",disabled:a||!N.trim()||r.length>=20,className:`${P} flex items-center gap-1`,children:[s.jsx(re,{size:13}),t("settings.profiles.create")]})]}),r.length>=20&&s.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("settings.profiles.limit")}),!v&&r.length>0&&s.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:t(E?"settings.profiles.myChromeShare":"settings.profiles.myChromeUnavailable")}),!r.length&&s.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.profiles.sharedEmpty")}),s.jsx("div",{className:"divide-y divide-hairline/30",children:r.map(e=>{const n=U(e.id),p=J(w,e.id),$=D(e);return s.jsxs("div",{className:"flex flex-col gap-1 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(se,{size:14,className:"shrink-0 text-ink-secondary"}),h?.id===e.id?s.jsxs("form",{className:"flex min-w-0 flex-1 flex-wrap gap-2",onSubmit:m=>{m.preventDefault(),Q()},children:[s.jsx("input",{autoFocus:!0,value:h.name,onChange:m=>j({id:e.id,name:m.target.value}),maxLength:40,required:!0,disabled:a,className:I,"aria-label":t("settings.profiles.nameAria")}),s.jsx("button",{type:"submit",disabled:a||!h.name.trim(),className:P,children:t("common.save")}),s.jsx("button",{type:"button",disabled:S,onClick:()=>j(null),className:P,children:t("common.cancel")})]}):s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",disabled:a,onClick:()=>{j({id:e.id,name:e.name}),u("")},className:"min-w-0 flex-1 truncate text-left text-[13px] font-medium text-ink hover:underline disabled:opacity-50",title:t("settings.profiles.rename"),children:e.name}),s.jsxs("button",{type:"button",onClick:()=>{V(e)},disabled:a||!!p,title:p??t("settings.profiles.deleteTitle"),"aria-label":`${t("common.delete")} ${e.name}`,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:[s.jsx(te,{size:13}),t("common.delete")]})]})]}),s.jsx("p",{className:"break-words pl-6 text-[11px] text-ink-secondary",children:n.length?t("settings.profiles.usedBy",{names:n.join(", ")}):t("settings.profiles.notInUse")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-2 pl-6 pt-1",children:[s.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[t("settings.profiles.browserLabel"),s.jsxs(R,{size:"sm",value:e.browser??"",disabled:a,onChange:m=>{W(e,m.target.value)},children:[s.jsx("option",{value:"",children:t("settings.profiles.builtIn")}),s.jsx("option",{value:"chrome",disabled:!v,children:t("settings.profiles.myChrome")})]})]}),$?H:s.jsx(q,{target:{profile:e.id},sharedBy:n,disabled:a})]})]},e.id)})})]})]}),F&&s.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:F})]})}export{pe as B,le as b,ue as w};
@@ -0,0 +1 @@
1
+ import{j as e,A as z,B as ve,H as U,t as n,D as se,Q,E as X,F as Pe,G as pe,I as Ce,J as Ee,K as fe,M as ze,N as Ae,O as Ue,R as qe,T as Me,U as G,a as ue,V as $e,W as Ke,r as d,Y as We,Z as Ve,$ as we,a0 as Ge,X as Je,a1 as Qe,a2 as Xe,a3 as Ye,a4 as Ze,a5 as et,a6 as Le,a7 as tt}from"./styles-6RbfQIY7.js";import{L as nt,z as st,C as at,y as J,F as lt,G as ot,H as rt,S as dt,I as ct,J as it}from"./PlacesRail-yZdo57pP.js";import{u as ut}from"./App-DRnqqiJP.js";import"./monitor-BfmnPU-I.js";import"./index-COnd2OMZ.js";import"./MenuMotion-BDYr4RxL.js";function pt({name:t,color:l,busy:o,interest:r,openFailed:s,onInterest:u,onOpen:p}){return e.jsxs("div",{"data-cloud-add":"has-cloud",className:z,children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ve,{color:l,size:32}),e.jsx(U,{title:n("cloudBuy.one.title"),sub:n("cloudBuy.one.sub",{name:t})})]}),e.jsxs("div",{className:se,children:[r!=="sent"&&e.jsx("button",{type:"button",className:Q,disabled:o,onClick:u,children:n("cloudBuy.one.email")}),e.jsx("button",{type:"button",className:X,disabled:o,onClick:p,children:n("cloudBuy.setup.open",{name:t})})]}),e.jsxs("div",{"aria-live":"polite",className:"text-[13px] leading-[18px] empty:-mt-5",children:[r==="sent"&&e.jsx("p",{className:"text-ink-secondary",children:n("cloudBuy.one.thanks")}),r==="failed"&&e.jsx("p",{role:"alert",className:"text-danger",children:n("cloudBuy.one.failed")}),s&&e.jsx("p",{role:"alert",className:"text-danger",children:n("cloudBuy.openFailed",{name:t})})]})]})}function ie({kind:t,line:l,onRetry:o,onClose:r}){return e.jsxs("div",{"data-cloud-add":t,className:z,children:[e.jsx(U,{title:n("cloudAdd.title")}),l?e.jsx("p",{role:"alert",className:"text-[14px] leading-5 text-ink",children:l}):e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[13px] leading-[18px] text-ink-secondary",children:[e.jsx(nt,{size:14,className:"animate-spin motion-reduce:animate-none","aria-hidden":"true"}),n("cloudAdd.checking")]}),e.jsxs("div",{className:se,children:[e.jsx("button",{type:"button",className:Q,onClick:r,children:n("cloudAdd.close")}),o&&e.jsx("button",{type:"button",className:X,onClick:o,children:n("cloudAdd.tryAgain")})]})]})}function ft({plan:t,offer:l,browser:o,late:r,link:s,email:u,busy:p,copied:v,failed:N,onReopen:k,onCopy:I,onChangePlan:q}){const y=l?.plans.find(M=>M.tier===t)??null,E=y?Pe(y):pe(t),A=y?.trialDays===1?n("cloudBuy.pay.planTrial.one",{plan:E,due:Ce(0)}):y?.trialDays?n("cloudBuy.pay.planTrial.many",{plan:E,days:y.trialDays,due:Ce(0)}):y?n("cloudBuy.pay.planPaid",{plan:E,price:Ee(y.amount/100)}):E;return e.jsxs("div",{"data-cloud-add":r?"waiting-late":o==="signin"?"waiting-signin":"waiting",className:z,children:[e.jsx(U,{title:r?n("cloudBuy.pay.lateTitle"):n("cloudAdd.browserTitle"),sub:r?n("cloudBuy.pay.lateSub"):n(o==="signin"?"cloudBuy.pay.subSignIn":"cloudBuy.pay.sub")}),e.jsx(fe,{items:[{key:"signed-in",state:"done",title:n("cloudBuy.pay.signedIn"),detail:u},{key:"payment",state:"now",title:n("cloudBuy.pay.waiting"),detail:A},{key:"setup",state:"next",title:n("cloudBuy.pay.setup"),detail:n("cloudBuy.pay.setupHint")}]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",className:r?X:Q,disabled:p,onClick:k,children:[e.jsx(st,{size:14,"aria-hidden":"true"}),n("cloudAdd.reopenCheckout")]}),s&&e.jsxs("button",{type:"button",className:Q,disabled:p,onClick:I,children:[e.jsx(at,{size:14,"aria-hidden":"true"}),n("cloudBuy.pay.copy")]}),e.jsx("button",{type:"button",className:`${ze} ms-1 px-1 py-1`,onClick:q,children:n("cloudAdd.changePlan")})]}),e.jsxs("div",{"aria-live":"polite",className:"text-[13px] leading-[18px] empty:-mt-5",children:[v&&e.jsx("p",{className:"text-ink-secondary",children:n("cloudBuy.pay.copied")}),N&&e.jsx("p",{role:"alert",className:"text-danger",children:n("cloudBuy.pay.failed")})]})]})}const R=[["reserving","cloudHome.step.reserving"],["storage","cloudHome.step.storage"],["starting","cloudBuy.step.starting"],["checking","cloudHome.step.checking"]];function mt({tier:t,trial:l,credit:o},r){if(r)return n("cloudAdd.receivedTitle");const s=pe(t??l?.tier??void 0);return l?o?n("cloudBuy.setup.badgeCredit",{plan:s,credit:Ee(o.grantedUsd)}):n("cloudBuy.setup.badgeTrial",{plan:s}):n("cloudBuy.setup.badgePaid",{plan:s})}function xt({started:t,received:l,step:o,slow:r,ready:s,sleeps:u=!1,name:p,typed:v,color:N,counting:k,busy:I,openFailed:q,onName:y,onColor:E,onOpen:A,onNotNow:M}){const _=s?R.length:Math.max(0,R.findIndex(([i])=>i===o)),C=pe(t.tier??t.trial?.tier??void 0);return e.jsxs("div",{"data-cloud-add":s?"ready":l?"received":"starting","data-cloud-setup":s?"ready":o??"reserving",className:z,children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Ue,{children:mt(t,l)}),e.jsx(U,{title:s?n("cloudBuy.ready.title",{name:p}):n("cloudBuy.setup.title"),sub:s?n("cloudBuy.ready.sub"):l?n("cloudAccount.purchaseNoteNoDate"):n("cloudBuy.setup.sub")})]}),e.jsxs("div",{className:"grid gap-6 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Ae,{value:_/R.length,label:n("cloudBuy.setup.progress")}),e.jsx(fe,{label:n("cloudBuy.setup.progress"),items:R.map(([i,w],j)=>({key:i,title:n(w,{name:p}),state:j<_?"done":j===_?"now":"next"}))}),r&&!s&&e.jsx("p",{role:"status",className:"px-3 text-[13px] leading-[18px] text-ink-secondary",children:n("cloudHome.slow")})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"cloud-add-name",className:"text-[13px] leading-[18px] text-ink-secondary",children:n("cloudBuy.setup.name")}),e.jsx("input",{id:"cloud-add-name",value:v,maxLength:Me,placeholder:n("cloudSetup.myCloud"),autoComplete:"off",spellCheck:!1,onChange:i=>y(i.target.value),className:qe})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{id:"cloud-add-color",className:"text-[13px] leading-[18px] text-ink-secondary",children:n("cloudBuy.setup.color")}),e.jsx("div",{role:"radiogroup","aria-labelledby":"cloud-add-color",className:"flex flex-wrap gap-2",children:G.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":i===N,"aria-label":n(Ke[i]),tabIndex:i===N?0:-1,"data-color":i,onClick:()=>E(i),onKeyDown:w=>{const j=G.indexOf(i),$=w.key==="ArrowRight"||w.key==="ArrowDown"?1:w.key==="ArrowLeft"||w.key==="ArrowUp"?-1:0;if(!$)return;w.preventDefault();const Y=G[(j+$+G.length)%G.length];E(Y),w.currentTarget.parentElement?.querySelector(`[data-color="${Y}"]`)?.focus()},style:{background:$e(i)},className:ue("size-[26px] rounded-lg border-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",i===N?"border-ink shadow-[inset_0_0_0_2px_var(--color-app)]":"border-transparent")},i))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:n("cloudBuy.setup.preview")}),e.jsxs("span",{"data-cloud-preview":!0,className:"inline-flex max-w-full items-center gap-2 self-start rounded-[12px] border-[0.5px] border-ink/10 bg-menu py-1.5 pe-3 ps-1.5",children:[e.jsx(ve,{color:N}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium leading-4 text-ink",children:p}),e.jsx("span",{className:"block truncate text-[12px] text-ink-tertiary",children:n(u?"cloudBuy.setup.previewLineSleeps":"cloudBuy.setup.previewLine",{plan:C})})]})]})]})]})]}),s&&k===null&&e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-tertiary",children:n("cloudBuy.ready.hint",{name:p})}),e.jsxs("div",{className:se,children:[k!==null&&e.jsx("span",{role:"status",className:"me-1 text-[13px] text-ink-secondary",children:n("cloudBuy.setup.openingIn",{seconds:k})}),k!==null&&e.jsx("button",{type:"button",className:Q,onClick:M,children:n("notice.notNow")}),e.jsx("button",{type:"button",className:X,disabled:!s||I,onClick:A,children:n("cloudBuy.setup.open",{name:p})})]}),q&&e.jsx("p",{role:"alert",className:"-mt-2 text-end text-[13px] leading-[18px] text-danger",children:n("cloudBuy.openFailed",{name:p})})]})}function yt({team:t,step:l,slow:o}){const r=Math.max(0,R.findIndex(([u])=>u===l)),s=t??n("cloudBuy.team.unnamed");return e.jsxs("div",{"data-cloud-add":"team-starting","data-cloud-setup":l??"reserving",className:z,children:[e.jsx(U,{title:n("cloudBuy.team.setupTitle"),sub:n("cloudBuy.team.setupSub")}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Ae,{value:r/R.length,label:n("cloudBuy.setup.progress")}),e.jsx(fe,{label:n("cloudBuy.setup.progress"),items:R.map(([u,p],v)=>({key:u,title:n(p,{name:s}),state:v<r?"done":v===r?"now":"next"}))}),o&&e.jsx("p",{role:"status",className:"px-3 text-[13px] leading-[18px] text-ink-secondary",children:n("cloudHome.slow")})]})]})}function gt({name:t,busy:l,openFailed:o,onOpen:r}){return e.jsxs("div",{"data-cloud-add":"team-ready",className:z,children:[e.jsx(U,{title:n("cloudBuy.team.readyTitle"),sub:n("cloudBuy.team.readySub",{name:t})}),e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-tertiary",children:n("cloudBuy.ready.hint",{name:t})}),e.jsx("div",{className:se,children:e.jsx("button",{type:"button","data-autofocus":!0,className:X,disabled:l,onClick:r,children:n("cloudBuy.setup.open",{name:t})})}),o&&e.jsx("p",{role:"alert",className:"-mt-2 text-end text-[13px] leading-[18px] text-danger",children:n("cloudBuy.openFailed",{name:t})})]})}function ht({view:t,ui:l,actions:o}){switch(t.kind){case"checking":return e.jsx(ie,{kind:"checking",line:null,onClose:o.close});case"unreachable":return e.jsx(ie,{kind:"unreachable",line:n("cloudAdd.unreachable"),onRetry:o.retry,onClose:o.close});case"error":return e.jsx(ie,{kind:`error-${t.reason}`,line:n(t.reason==="rate-limited"?"cloudAdd.rateLimited":"cloudAdd.failed"),onRetry:o.retry,onClose:o.close});case"offer":return e.jsx(ct,{offer:t.offer,current:l.current,now:l.now,busy:l.busy,signedOut:t.signedOut,notice:t.notice?n(t.notice==="code-expired"?"cloudAdd.codeExpired":t.notice==="signin-ended"?"cloudAdd.signInEnded":t.notice==="terms"?"cloudBuy.termsChanged":"cloudAdd.preparing"):null,onStart:o.start,onSignIn:o.signIn});case"sign-in":return e.jsx(dt,{phase:t.phase,email:l.email,code:l.code,profileEmail:l.profileEmail,busy:l.busy,now:l.now,onBack:o.back,onEmail:o.email,onSend:o.sendCode,onChangeEmail:o.changeEmail,onCode:o.code,onResend:o.resend,onBrowser:o.browser});case"signing-in":return e.jsx(rt,{code:t.code,checkout:t.checkout,busy:l.busy,trial:l.offerShown?!!Le(l.offerShown,l.chosen).trialDays:!1,onReopen:o.reopenBrowser,onCancel:o.cancelSignIn});case"waiting":return e.jsx(ft,{plan:t.plan,offer:l.offerShown,browser:t.browser,late:t.late,link:t.link,email:t.email,busy:l.busy,copied:l.copied,failed:l.payFailed,onReopen:o.reopenCheckout,onCopy:o.copyLink,onChangePlan:o.changePlan});case"starting":case"ready":return e.jsx(xt,{started:t,received:t.kind==="starting"&&t.received,step:t.kind==="starting"?t.step:null,slow:t.kind==="starting"&&t.slow,ready:t.kind==="ready",sleeps:et(t,l.offerShown),name:l.look.name,typed:l.look.typed,color:l.look.color,counting:l.counting,busy:l.busy,openFailed:l.openFailed,onName:o.name,onColor:o.color,onOpen:o.openCloud,onNotNow:o.notNow});case"has-cloud":return e.jsx(pt,{name:l.look.name,color:l.look.color,busy:l.busy,interest:l.interest,openFailed:l.openFailed,onInterest:o.interest,onOpen:o.openCloud});case"team-starting":return e.jsx(yt,{team:t.team,step:t.step,slow:t.slow});case"team-ready":return e.jsx(gt,{name:t.team.name,busy:l.busy,openFailed:l.openFailed,onOpen:()=>o.openTeam(t.team.id)});case"settings":return null}}const bt={offer:"max-w-[920px]",starting:"max-w-[720px]",ready:"max-w-[720px]"},kt=new Set(["sign-in","signing-in","waiting","starting","team-starting"]);function Be({kind:t,staging:l,onClose:o,children:r}){return e.jsx("div",{className:"ui-scrim fixed inset-0 z-[60] flex items-center justify-center p-4 sm:p-6",onMouseDown:s=>s.target===s.currentTarget&&!kt.has(t)&&o(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"cloud-add-title","data-cloud-add-dialog":!0,tabIndex:-1,className:ue(Ze,"group/sheet animate-pop-in relative max-h-full w-full overflow-y-auto overscroll-contain outline-none",bt[t]??"max-w-[540px]"),children:[e.jsx("button",{type:"button",onClick:o,"aria-label":n("cloudAdd.close"),className:ue(Xe,Qe,"absolute end-4 top-4 z-10"),children:e.jsx(Je,{size:16})}),l&&e.jsx(Ye,{className:"absolute end-14 top-[22px] z-10 group-has-[[data-night-card]]/sheet:bg-app"}),r]})})}const jt=["offer","checking","unreachable","waiting","sign-in","signing-in"],St="button:not([disabled]):not([tabindex='-1']), input:not([disabled]):not([tabindex='-1']), [href], [tabindex='0']",Nt=t=>t.status==="connected"&&t.entitlement?.plan==="free"&&!t.purchase&&!t.machine,Ct=t=>t?.status==="connected"&&t.entitlement?.plan==="pro"&&t.entitlement.status==="active"?t.entitlement.tier??"pro":null;function It({now:t=Date.now}){const{state:l,dispatch:o}=ut(),r=l.cloudAdd,s=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,[u,p]=d.useState(null),[v,N]=d.useState(void 0),[k,I]=d.useState(null),[q,y]=d.useState(null),[E,A]=d.useState(!1),[M,_]=d.useState(!1),[C,i]=d.useState(!1),[w,j]=d.useState(!1),[$,Y]=d.useState(0),[Z,me]=d.useState([]),[b,h]=d.useState(null),[T,O]=d.useState({email:"",code:""}),[B,ee]=d.useState(null),[F,H]=d.useState(null),[P,S]=d.useState(null),[,Ie]=d.useState(0),[xe,ae]=d.useState(!1),[Te,le]=d.useState(!1),[Oe,Fe]=d.useState(!1),L=!!(r&&s),oe=l.config?.profile?.email?.trim()||null,re=ot();d.useEffect(()=>{if(!L||!s)return;let a=!0,c=!1;const g=s.onState(x=>{c=!0,a&&p(x)});return s.state().then(x=>{a&&!c&&p(x)}).catch(()=>{}),()=>{a=!1,g()}},[L,s]);const m=L?We(u,v,{now:t(),error:q,choosing:M,conflict:E,signIn:b,arrived:xe,terms:Te}):null,ye=L&&m&&jt.includes(m.kind)&&u?`${u.status}:${JSON.stringify(u.offer??null)}:${$}`:null;d.useEffect(()=>{if(!ye||!s?.offer)return;let a=!0;return s.offer().then(c=>{a&&N(c)},()=>{a&&N(null)}),()=>{a=!1}},[ye,s]);const de=n("cloudSetup.myCloud"),K={typed:B?.typed??de,color:B?.color??we,name:Ve(B?.typed??de,de)},D=()=>{b&&s?.signInCancel?.().catch(()=>{}),o({type:"closeCloudAdd"}),y(null),A(!1),_(!1),j(!1),me([]),I(null),h(null),O({email:"",code:""}),ee(null),H(null),S(null),ae(!1),le(!1)};d.useEffect(()=>{if(!L)return;const a=document.activeElement,c=a&&a!==document.body&&typeof a.focus=="function"?a:null;r?.signIn&&(h({step:"email",intent:!1,problem:null}),O({email:oe??"",code:""}));const g=x=>{if(x.key==="Escape"){x.preventDefault(),D();return}if(x.key!=="Tab")return;const V=[...document.querySelector("[data-cloud-add-dialog]")?.querySelectorAll(St)??[]];if(!V.length)return;x.preventDefault();const Ne=V.indexOf(document.activeElement);V[Ne===-1?0:(Ne+(x.shiftKey?-1:1)+V.length)%V.length].focus()};return window.addEventListener("keydown",g,!0),(document.querySelector("#cloud-add-title")??document.querySelector("[data-cloud-add-dialog]"))?.focus(),()=>{window.removeEventListener("keydown",g,!0),c?.isConnected&&c.focus()}},[L]),d.useEffect(()=>{if(!(!L||!s?.sheet||re))return s.sheet(!0).catch(()=>{}),()=>{s.sheet?.(!1).catch(()=>{})}},[L,s,re]);const f=m?.kind??null,te=m?.kind==="sign-in"?`sign-in-${m.phase.step}`:f;d.useEffect(()=>{!te||te==="checking"||te==="settings"||document.activeElement?.closest?.("[data-cloud-add-dialog]")||(document.querySelector("[data-cloud-add-dialog] [data-autofocus]")??document.querySelector("#cloud-add-title"))?.focus()},[te]),d.useEffect(()=>{(f==="waiting"||f==="starting"||f==="ready")&&!xe&&ae(!0),(f==="ready"||f==="team-ready")&&s?.readySeen?.().catch(()=>{})},[f]),d.useEffect(()=>{if(!f||!r)return;if(f==="settings"){D(),o({type:"toggleAppSettings",open:!0,section:"cloudAccount"});return}if(f==="checking")return;const a=Z.length===0;a&&J("cloud_dialog_shown",{source:r.source}),["starting","ready"].includes(f)&&Z.includes(f),(a||!Z.includes(f))&&me([...Z,f])},[f]),d.useEffect(()=>{if(!f||!["starting","ready","has-cloud"].includes(f)||B||!s?.look)return;let a=!0;return s.look().then(c=>{a&&ee({typed:c.name,color:Ge(c.color)??we,dirty:f!=="has-cloud"})},()=>{}),()=>{a=!1}},[f]),d.useEffect(()=>{if(!B?.dirty||!s?.setLook)return;const a=setTimeout(()=>{s.setLook?.(K.name,B.color).catch(()=>{})},400);return()=>clearTimeout(a)},[B?.typed,B?.color]),d.useEffect(()=>{f!=="ready"||F!==null||H(!re&&typeof document.hasFocus=="function"&&document.hasFocus()?3:"off")},[f]);const ge=b?.step==="code"?b.resendAt:0;d.useEffect(()=>{if(!ge||ge<=t())return;const a=setTimeout(()=>Ie(t()),1e3);return()=>clearTimeout(a)}),d.useEffect(()=>{if(P!=="copied")return;const a=setTimeout(()=>S(null),2500);return()=>clearTimeout(a)},[P]);const ne=a=>{C||(i(!0),j(!1),a().catch(()=>y("failed")).finally(()=>i(!1)))},he=()=>{C||!s||(i(!0),j(!1),H("done"),(async()=>{B?.dirty&&s.setLook&&await s.setLook(K.name,B.color).catch(()=>{}),await s.connectHome()})().then(()=>D(),()=>j(!0)).finally(()=>i(!1)))},De=a=>{C||!s?.openTeam||(i(!0),j(!1),s.openTeam(a).then(()=>D(),()=>j(!0)).finally(()=>i(!1)))};d.useEffect(()=>{if(typeof F!="number")return;const a=setTimeout(()=>{F>1?H(F-1):he()},1e3);return()=>clearTimeout(a)},[F]);const be=typeof F=="number";if(d.useEffect(()=>{if(!be)return;const a=()=>H("off");return window.addEventListener("blur",a),()=>window.removeEventListener("blur",a)},[be]),!L||!m||!r||!s||m.kind==="settings")return null;if(m.kind==="has-cloud"&&u?.status==="connected"&&u.clouds&&window.ogb?.cloudAdd&&(u.addCloud?.canAdd!==!1||u.adding&&!u.adding.done))return e.jsx(Be,{kind:Oe?"offer":"has-cloud",staging:u.staging===!0,onClose:D,children:e.jsx(lt,{onClose:D,onFirstCloud:()=>{},onWide:Fe,source:r.source})});const W=v??null,ke=()=>m.kind==="waiting"&&!k?m.plan:W?Le(W,k).tier:null,ce=async a=>{if(!a||!s.checkout){y("failed");return}W?.plans.find(x=>x.tier===a)?.trialDays;const c=await s.checkout(a,r.source),g=c.outcome;p(c.state),g==="opened"||g==="signing-in"?(_(!1),y(null),A(!1),S(null),le(!1),J("cloud_checkout_opened",{source:r.source})):g==="rate-limited"?y("rate-limited"):g==="failed"?y("failed"):A(!0)},je=a=>{h({step:"email",intent:a,problem:null}),O({email:T.email||oe||"",code:""})},Se=()=>{if(C||!s.signInStart||!b||b.step==="done")return;const a=b;i(!0),s.signInStart(T.email).then(c=>{c.outcome==="sent"?(h({step:"code",intent:a.intent,email:c.email,resendAt:c.resendAt,problem:null,triesLeft:null,...c.signupOpen===!1?{signupOpen:!1}:{}}),O({email:c.email,code:""}),J("cloud_signin",{source:r.source})):h({...a,problem:c.outcome})},()=>h({...a,problem:"failed"})).finally(()=>i(!1))},_e=a=>{if(!s.signInVerify||b?.step!=="code")return;const c=b,g=c.intent?ke():null;i(!0),(async()=>{try{const x=await s.signInVerify(a);if(x.outcome!=="signed-in"){O({email:T.email,code:""}),h({...c,problem:x.outcome,triesLeft:x.outcome==="wrong-code"?x.triesLeft:null});return}p(x.state),ae(!0),J("cloud_signin",{step:"signed_in",source:r.source}),g&&Nt(x.state)&&(tt(W,x.state.offer,g)?(h({step:"done",intent:!0}),await ce(g)):(le(!0),I(g))),h(null),O({email:T.email,code:""})}catch{h({...c,problem:"failed",triesLeft:null})}finally{i(!1)}})()},Re={start:a=>{if(I(a),A(!1),m.kind==="offer"&&m.signedOut&&s.signInStart){je(!0);return}ne(()=>ce(a))},signIn:()=>je(!1),back:()=>{h(null),s.signInCancel?.().catch(()=>{})},email:a=>O({email:a,code:T.code}),sendCode:Se,changeEmail:()=>{b&&(h({step:"email",intent:b.intent,problem:null}),s.signInCancel?.().catch(()=>{}))},code:a=>{const c=it(a);O({email:T.email,code:c}),c.length===8&&!C&&_e(c)},resend:Se,browser:()=>ne(async()=>{const a=b?.intent?ke():null;h(null),await s.signInCancel?.().catch(()=>{}),J("cloud_signin",{source:r.source}),a?await ce(a):p(await s.begin())}),reopenBrowser:()=>ne(async()=>p(await s.reopen())),cancelSignIn:()=>ne(async()=>p(await s.cancel())),reopenCheckout:()=>{if(m.kind!=="waiting"||C)return;i(!0),S(null),(s.reopenCheckout?s.reopenCheckout(m.plan,r.source):s.checkout(m.plan,r.source)).then(c=>{p(c.state),c.outcome!=="opened"&&S("pay-failed")},()=>S("pay-failed")).finally(()=>i(!1))},copyLink:()=>{s.copyCheckoutLink?.().then(a=>S(a?"copied":"pay-failed"),()=>S("pay-failed"))},changePlan:()=>{I(m.kind==="waiting"?m.plan:k),_(!0),S(null)},retry:()=>{y(null),A(!1),N(void 0),Y($+1)},name:a=>ee({typed:a,color:K.color,dirty:!0}),color:a=>ee({typed:K.typed,color:a,dirty:!0}),openCloud:he,openTeam:De,notNow:()=>H("off"),interest:()=>{C||!s.interest||(i(!0),s.interest().then(()=>S("interest-sent"),()=>S("interest-failed")).finally(()=>i(!1)))},close:D},He={chosen:k,current:Ct(u),offerShown:W,now:t(),busy:C,openFailed:w,email:T.email,code:T.code,profileEmail:oe,look:K,counting:typeof F=="number"?F:null,copied:P==="copied",payFailed:P==="pay-failed",interest:P==="interest-sent"?"sent":P==="interest-failed"?"failed":null};return e.jsx(Be,{kind:m.kind,staging:u?.staging===!0,onClose:D,children:e.jsx(ht,{view:m,ui:He,actions:Re})})}export{It as CloudAddDialog,ht as CloudAddPanel,Be as CloudAddSheet};
@@ -1 +1 @@
1
- import{j as e,t as a,a as N,r as R}from"./styles-Cm26P6hN.js";import{a5 as F,a6 as S,x as L,S as z,a7 as y,a8 as b,a9 as A,aa as M,ab as w,ac as k,ad as P,ae as E,af as $,u as I,w as B,F as O,ag as v,ah as T,ai as D,aj as C,ak as H,al as W,am as X}from"./App-DPG1sq1r.js";import{a as _,R as q}from"./RoutinesPage-BWJ5Z1Sk.js";import{L as G,P as J,d as K}from"./PlacesRail-DnedL3jM.js";import{C as Q}from"./MenuMotion-C1J3xC0E.js";function U({routines:t,runs:r,bots:p,pausedBots:c,loading:o,error:d,onOpen:l,onLogs:n,onToggle:x}){const u=[...t].sort((s,i)=>Number(i.enabled)-Number(s.enabled)||(s.nextRunAt??1/0)-(i.nextRunAt??1/0)||s.name.localeCompare(i.name));return e.jsxs("div",{className:"space-y-3","aria-label":a("routines.list"),children:[d&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:a("routines.loadError")}),o&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 p-3 text-[12px] text-ink-secondary",children:[e.jsx(G,{size:14,className:"animate-spin"}),a("routines.loading")]}),!o&&!d&&u.length===0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-hairline/50 p-5 text-center text-[13px] text-ink-secondary",children:[e.jsx(_,{size:20,className:"mx-auto mb-2 opacity-60"}),a("routines.empty")]}),u.map(s=>{const i=F(s.id,r),m=i&&(i.attention?"attention":i.error?"error":i.output?"output":null),h=p?.find(g=>g.id===s.botId),f=x!==void 0&&!S(s);return e.jsxs("article",{className:"rounded-xl border border-hairline/40 bg-card p-3.5","aria-label":s.name,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>l(s),className:"min-w-0 flex-1 text-left hover:text-accent",children:[e.jsx("span",{className:"block truncate text-[13px] font-semibold text-ink",children:s.name}),e.jsxs("span",{className:"mt-1 block text-[12px] leading-relaxed text-ink-secondary",children:[h&&`${h.name} · `,L(s.schedule)]})]}),f?e.jsx(z,{checked:s.enabled,"aria-label":a("routines.toggle",{name:s.name}),onClick:()=>x(s)}):e.jsx("span",{className:N("shrink-0 rounded-full bg-inset px-2 py-0.5 text-[10px]",s.enabled&&s.nextRunAt!=null?"text-accent":"text-ink-secondary"),children:y(s)})]}),(f||b(s)!==y(s))&&e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:b(s)}),e.jsxs("div",{className:"mt-1 flex items-start justify-between gap-2",children:[e.jsx("div",{className:"min-w-0 text-[12px]",children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:M(i),children:a("routines.latestRun",{status:A(i)})}),e.jsx("span",{className:"block text-[11px] text-ink-secondary",children:w(i.finishedAt??i.startedAt??i.scheduledFor)})]}):e.jsx("span",{className:"text-ink-secondary",children:a("routines.neverRun")})}),e.jsxs("button",{type:"button",onClick:()=>n(s),"aria-label":a("routines.logsFor",{name:s.name}),className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[11px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(k,{size:12}),a("routines.logs")]})]}),i&&m&&e.jsx("p",{className:N("mt-2 line-clamp-2 whitespace-pre-wrap text-[12px] leading-relaxed",i.error?"text-danger":"text-ink-secondary"),children:P(i,m)}),!!s.failureStreak&&e.jsx("p",{className:"mt-2 text-[12px] text-danger",children:a("routines.failureStreak",{count:s.failureStreak})}),s.weekRuns&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:a(s.weekRuns.total===1?"routines.weekRunsOne":"routines.weekRuns",s.weekRuns)}),s.warning&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-warning",children:s.warning}),s.enabled&&c?.includes(s.botId)&&e.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-warning","data-routine-bot-paused":"",children:[a("routines.botPaused")," ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent hover:underline",onClick:()=>E("paused"),children:a("routines.botPausedSwap")})]}),s.heldFor&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:$(s)}),!!s.skippedRuns&&e.jsxs("p",{className:"mt-2 text-[12px] text-ink-secondary",children:[a("routines.skippedRuns",{count:s.skippedRuns}),s.lastSkippedAt!=null&&e.jsxs(e.Fragment,{children:[" · ",a("routines.lastSkipped",{date:w(s.lastSkippedAt)})]})]})]},s.id)})]})}function le({bot:t,routines:r,runs:p,defaultRunOn:c}){const{state:o,dispatch:d}=I(),[l,n]=R.useState(null);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{size:16,className:"text-accent"}),e.jsx("h2",{className:"min-w-0 flex-1 text-[15px] font-medium text-ink",children:a("computer.tab.routines")}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:r.length})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>n("new"),className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white hover:brightness-110",children:[e.jsx(J,{size:14}),a("computer.routines.create")]}),e.jsxs("button",{type:"button",onClick:()=>d({type:"showRoutines",section:"logs",botId:t.id}),className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[e.jsx(k,{size:13}),a("routines.logs")]})]})]}),e.jsx(U,{routines:r,runs:p,pausedBots:o.config?.pausedBots,loading:o.routinesLoadState==="loading"&&r.length===0,error:o.routinesLoadState==="error",onOpen:n,onLogs:x=>d({type:"showRoutines",section:"logs",botId:t.id,routineId:x.id}),onToggle:x=>d({type:"updateRoutine",routineId:x.id,patch:{enabled:!x.enabled}})}),e.jsxs("button",{type:"button",onClick:()=>d({type:"showRoutines",section:"schedule",view:"list",botId:t.id}),className:"self-start text-[12px] text-accent hover:underline",children:[a("computer.routines.openTitle")," ",e.jsx(Q,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]}),l&&e.jsx(q,{routine:l==="new"?void 0:l,bots:[t],lockedBotId:t.id,defaultRunOn:c,onClose:()=>n(null)},t.id)]})}const V=20;function Y(t,r=V){const p=new Set,c=[],o=C(t);for(let d=o.length-1;d>=0&&c.length<r;d-=1){const l=o[d].digest?.files;if(l){for(const n of l.deleted)p.add(n);for(const n of[...l.added,...l.changed])if(!p.has(n)&&(p.add(n),c.push(n),c.length>=r))break}}return c}function Z(t){const r=new Map,p=t.tasks?.find(n=>n.threadId===t.threadId),c=p?.cwd===void 0?t.cwd:p.cwd,o=c&&(/^[a-z]:[\\/]/i.test(c)||c.startsWith("\\\\")),d=n=>o?n.replace(/\\/g,"/"):n,l=typeof c=="string"?`${d(c).replace(/\/+$/,"")}/`:void 0;for(const n of[...C(t)].reverse()){if(n.role!=="bot"||n.kind!=="text")continue;const x=H(n.attachments),u=[...x.files,...W(n.text??"",[...x.images,...x.files.map(s=>s.path)])];for(const s of u){const i=s.private?s.path:X(s.path),m={file:s,message:{threadId:t.threadId,messageId:n.id}},h=d(i),f=l&&(o?h.slice(0,l.length).toLowerCase()===l.toLowerCase():h.startsWith(l)),g=[i,...f?[h.slice(l.length)]:[]];i.startsWith("./")&&g.push(i.replace(/^(\.\/)+/,""));for(const j of g)r.has(j)||r.set(j,m)}}return r}function ee(t){const r=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return r<0?{name:t,folder:""}:{name:t.slice(r+1),folder:t.slice(0,r)}}function re({bot:t}){const{dispatch:r}=I(),{capabilities:p}=K(),c=p.host.homeDir,d=t.tasks?.find(u=>u.threadId===t.threadId)?.cwd,l=d===void 0?t.cwd:d,n=Y(t),x=R.useMemo(()=>Z(t),[t.messages,t.activeLeafId,t.threadId,t.tasks,t.cwd]);return e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pb-5","data-testid":"computer-files",children:[e.jsxs("div",{className:"mt-2 rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a("computer.files.folder")}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx(O,{size:15,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",title:l??void 0,children:l?v(l,c):l===null?a("computer.files.homeFolder"):a("computer.files.privateFolder",{name:t.name})}),e.jsx("button",{type:"button",onClick:()=>{r({type:"toggleComputer",open:!1}),T(r,"access",{page:"folder"})},className:"shrink-0 rounded-lg bg-control px-2.5 py-1 text-[12px] text-ink hover:bg-raised-hover",children:a(d===void 0?"computer.files.changeFolder":"computer.files.changeDefaultFolder")})]}),d!==void 0&&e.jsx("p",{className:"mt-2 text-[12px] leading-5 text-ink-secondary",children:a("computer.files.pinnedFolderHint")})]}),e.jsxs("div",{className:"mt-3 rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a("computer.files.recent")}),n.length===0?e.jsx("p",{className:"mt-2 text-[12px] leading-5 text-ink-secondary",children:a("computer.files.empty",{name:t.name})}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:n.map(u=>{const{name:s,folder:i}=ee(u),m=x.get(u);return e.jsxs("li",{className:"min-w-0 rounded-lg py-1",title:u,children:[m?e.jsx(D,{file:{...m.file,name:s},message:m.message,linked:m.file.linked,className:"w-full max-w-none"},`${m.message.threadId}:${m.message.messageId}:${m.file.path}`):e.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-2.5 py-2",title:a("computer.files.notSharedHint"),children:[e.jsx(k,{size:14,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:s}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-tertiary",children:a("computer.files.notShared")})]}),i&&e.jsx("div",{className:"mt-1 truncate px-2.5 text-[11px] text-ink-tertiary",children:v(i,c)})]},u)})})]})]})}export{re as C,le as R,U as a,Y as r,Z as s};
1
+ import{j as e,t as a,a as N,r as R}from"./styles-6RbfQIY7.js";import{a6 as F,a7 as S,x as L,S as z,a8 as y,a9 as b,aa as A,ab as M,ac as w,ad as k,ae as P,af as E,ag as $,u as I,w as B,F as O,ah as v,ai as T,aj as D,ak as C,al as H,am as W,an as X}from"./App-DRnqqiJP.js";import{a as _,R as q}from"./RoutinesPage-CIo30TVq.js";import{L as G,P as J,d as K}from"./PlacesRail-yZdo57pP.js";import{C as Q}from"./MenuMotion-BDYr4RxL.js";function U({routines:t,runs:r,bots:p,pausedBots:c,loading:o,error:d,onOpen:l,onLogs:n,onToggle:x}){const u=[...t].sort((s,i)=>Number(i.enabled)-Number(s.enabled)||(s.nextRunAt??1/0)-(i.nextRunAt??1/0)||s.name.localeCompare(i.name));return e.jsxs("div",{className:"space-y-3","aria-label":a("routines.list"),children:[d&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:a("routines.loadError")}),o&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 p-3 text-[12px] text-ink-secondary",children:[e.jsx(G,{size:14,className:"animate-spin"}),a("routines.loading")]}),!o&&!d&&u.length===0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-hairline/50 p-5 text-center text-[13px] text-ink-secondary",children:[e.jsx(_,{size:20,className:"mx-auto mb-2 opacity-60"}),a("routines.empty")]}),u.map(s=>{const i=F(s.id,r),m=i&&(i.attention?"attention":i.error?"error":i.output?"output":null),h=p?.find(g=>g.id===s.botId),f=x!==void 0&&!S(s);return e.jsxs("article",{className:"rounded-xl border border-hairline/40 bg-card p-3.5","aria-label":s.name,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>l(s),className:"min-w-0 flex-1 text-left hover:text-accent",children:[e.jsx("span",{className:"block truncate text-[13px] font-semibold text-ink",children:s.name}),e.jsxs("span",{className:"mt-1 block text-[12px] leading-relaxed text-ink-secondary",children:[h&&`${h.name} · `,L(s.schedule)]})]}),f?e.jsx(z,{checked:s.enabled,"aria-label":a("routines.toggle",{name:s.name}),onClick:()=>x(s)}):e.jsx("span",{className:N("shrink-0 rounded-full bg-inset px-2 py-0.5 text-[10px]",s.enabled&&s.nextRunAt!=null?"text-accent":"text-ink-secondary"),children:y(s)})]}),(f||b(s)!==y(s))&&e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:b(s)}),e.jsxs("div",{className:"mt-1 flex items-start justify-between gap-2",children:[e.jsx("div",{className:"min-w-0 text-[12px]",children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:M(i),children:a("routines.latestRun",{status:A(i)})}),e.jsx("span",{className:"block text-[11px] text-ink-secondary",children:w(i.finishedAt??i.startedAt??i.scheduledFor)})]}):e.jsx("span",{className:"text-ink-secondary",children:a("routines.neverRun")})}),e.jsxs("button",{type:"button",onClick:()=>n(s),"aria-label":a("routines.logsFor",{name:s.name}),className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[11px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(k,{size:12}),a("routines.logs")]})]}),i&&m&&e.jsx("p",{className:N("mt-2 line-clamp-2 whitespace-pre-wrap text-[12px] leading-relaxed",i.error?"text-danger":"text-ink-secondary"),children:P(i,m)}),!!s.failureStreak&&e.jsx("p",{className:"mt-2 text-[12px] text-danger",children:a("routines.failureStreak",{count:s.failureStreak})}),s.weekRuns&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:a(s.weekRuns.total===1?"routines.weekRunsOne":"routines.weekRuns",s.weekRuns)}),s.warning&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-warning",children:s.warning}),s.enabled&&c?.includes(s.botId)&&e.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-warning","data-routine-bot-paused":"",children:[a("routines.botPaused")," ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent hover:underline",onClick:()=>E("paused"),children:a("routines.botPausedSwap")})]}),s.heldFor&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:$(s)}),!!s.skippedRuns&&e.jsxs("p",{className:"mt-2 text-[12px] text-ink-secondary",children:[a("routines.skippedRuns",{count:s.skippedRuns}),s.lastSkippedAt!=null&&e.jsxs(e.Fragment,{children:[" · ",a("routines.lastSkipped",{date:w(s.lastSkippedAt)})]})]})]},s.id)})]})}function le({bot:t,routines:r,runs:p,defaultRunOn:c}){const{state:o,dispatch:d}=I(),[l,n]=R.useState(null);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{size:16,className:"text-accent"}),e.jsx("h2",{className:"min-w-0 flex-1 text-[15px] font-medium text-ink",children:a("computer.tab.routines")}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:r.length})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>n("new"),className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white hover:brightness-110",children:[e.jsx(J,{size:14}),a("computer.routines.create")]}),e.jsxs("button",{type:"button",onClick:()=>d({type:"showRoutines",section:"logs",botId:t.id}),className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[e.jsx(k,{size:13}),a("routines.logs")]})]})]}),e.jsx(U,{routines:r,runs:p,pausedBots:o.config?.pausedBots,loading:o.routinesLoadState==="loading"&&r.length===0,error:o.routinesLoadState==="error",onOpen:n,onLogs:x=>d({type:"showRoutines",section:"logs",botId:t.id,routineId:x.id}),onToggle:x=>d({type:"updateRoutine",routineId:x.id,patch:{enabled:!x.enabled}})}),e.jsxs("button",{type:"button",onClick:()=>d({type:"showRoutines",section:"schedule",view:"list",botId:t.id}),className:"self-start text-[12px] text-accent hover:underline",children:[a("computer.routines.openTitle")," ",e.jsx(Q,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]}),l&&e.jsx(q,{routine:l==="new"?void 0:l,bots:[t],lockedBotId:t.id,defaultRunOn:c,onClose:()=>n(null)},t.id)]})}const V=20;function Y(t,r=V){const p=new Set,c=[],o=C(t);for(let d=o.length-1;d>=0&&c.length<r;d-=1){const l=o[d].digest?.files;if(l){for(const n of l.deleted)p.add(n);for(const n of[...l.added,...l.changed])if(!p.has(n)&&(p.add(n),c.push(n),c.length>=r))break}}return c}function Z(t){const r=new Map,p=t.tasks?.find(n=>n.threadId===t.threadId),c=p?.cwd===void 0?t.cwd:p.cwd,o=c&&(/^[a-z]:[\\/]/i.test(c)||c.startsWith("\\\\")),d=n=>o?n.replace(/\\/g,"/"):n,l=typeof c=="string"?`${d(c).replace(/\/+$/,"")}/`:void 0;for(const n of[...C(t)].reverse()){if(n.role!=="bot"||n.kind!=="text")continue;const x=H(n.attachments),u=[...x.files,...W(n.text??"",[...x.images,...x.files.map(s=>s.path)])];for(const s of u){const i=s.private?s.path:X(s.path),m={file:s,message:{threadId:t.threadId,messageId:n.id}},h=d(i),f=l&&(o?h.slice(0,l.length).toLowerCase()===l.toLowerCase():h.startsWith(l)),g=[i,...f?[h.slice(l.length)]:[]];i.startsWith("./")&&g.push(i.replace(/^(\.\/)+/,""));for(const j of g)r.has(j)||r.set(j,m)}}return r}function ee(t){const r=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return r<0?{name:t,folder:""}:{name:t.slice(r+1),folder:t.slice(0,r)}}function re({bot:t}){const{dispatch:r}=I(),{capabilities:p}=K(),c=p.host.homeDir,d=t.tasks?.find(u=>u.threadId===t.threadId)?.cwd,l=d===void 0?t.cwd:d,n=Y(t),x=R.useMemo(()=>Z(t),[t.messages,t.activeLeafId,t.threadId,t.tasks,t.cwd]);return e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pb-5","data-testid":"computer-files",children:[e.jsxs("div",{className:"mt-2 rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a("computer.files.folder")}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx(O,{size:15,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",title:l??void 0,children:l?v(l,c):l===null?a("computer.files.homeFolder"):a("computer.files.privateFolder",{name:t.name})}),e.jsx("button",{type:"button",onClick:()=>{r({type:"toggleComputer",open:!1}),T(r,"access",{page:"folder"})},className:"shrink-0 rounded-lg bg-control px-2.5 py-1 text-[12px] text-ink hover:bg-raised-hover",children:a(d===void 0?"computer.files.changeFolder":"computer.files.changeDefaultFolder")})]}),d!==void 0&&e.jsx("p",{className:"mt-2 text-[12px] leading-5 text-ink-secondary",children:a("computer.files.pinnedFolderHint")})]}),e.jsxs("div",{className:"mt-3 rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a("computer.files.recent")}),n.length===0?e.jsx("p",{className:"mt-2 text-[12px] leading-5 text-ink-secondary",children:a("computer.files.empty",{name:t.name})}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:n.map(u=>{const{name:s,folder:i}=ee(u),m=x.get(u);return e.jsxs("li",{className:"min-w-0 rounded-lg py-1",title:u,children:[m?e.jsx(D,{file:{...m.file,name:s},message:m.message,linked:m.file.linked,className:"w-full max-w-none"},`${m.message.threadId}:${m.message.messageId}:${m.file.path}`):e.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-2.5 py-2",title:a("computer.files.notSharedHint"),children:[e.jsx(k,{size:14,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:s}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-tertiary",children:a("computer.files.notShared")})]}),i&&e.jsx("div",{className:"mt-1 truncate px-2.5 text-[11px] text-ink-tertiary",children:v(i,c)})]},u)})})]})]})}export{re as C,le as R,U as a,Y as r,Z as s};