limixbot 0.2.11 → 0.2.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.
- package/dist/assets/{ActivityPanel-DGFY9WG0.js → ActivityPanel-BHCUppbs.js} +1 -1
- package/dist/assets/{App-DToXVaV2.js → App-D93hKk8l.js} +9 -9
- package/dist/assets/{AppEventEditor-B1BhBpPN.js → AppEventEditor-tGh5VM2Z.js} +1 -1
- package/dist/assets/{BotSettingsDialog-Di0mWCIw.js → BotSettingsDialog-D6Y7Bflm.js} +1 -1
- package/dist/assets/{BrowserPanel-BdM7bp0Z.js → BrowserPanel-k55-4cIw.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-C-R1apBf.js → BrowserProfilesManager-BRZM0q_M.js} +1 -1
- package/dist/assets/{CloudAddDialog-VPm_nDm1.js → CloudAddDialog-BZQDNnKi.js} +1 -1
- package/dist/assets/{ComputerFilesPane-DdeiWUnd.js → ComputerFilesPane-DAQhcfSG.js} +1 -1
- package/dist/assets/{ComputerPanel-R_m1XX7x.js → ComputerPanel-ExjbTj4s.js} +2 -2
- package/dist/assets/{DataPanel-CvcP8VUG.js → DataPanel-DRPDfcrQ.js} +1 -1
- package/dist/assets/{DesktopViewer-Bgk3I55B.js → DesktopViewer-D9jr2w9X.js} +1 -1
- package/dist/assets/{FilesView-CbJtl_B6.js → FilesView-CplahKQt.js} +1 -1
- package/dist/assets/{GrokMoveDialog-D4Ey0NPX.js → GrokMoveDialog-Cc5o6HuE.js} +1 -1
- package/dist/assets/{InspectorPanel-CCp8ivaJ.js → InspectorPanel-B5iY0Ism.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-PdTGANti.js → KeyboardShortcutsModal-DhUpWvIZ.js} +1 -1
- package/dist/assets/{LiveDesktop-Db-Mmed5.js → LiveDesktop-DRcJOYg3.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-TDvs66q1.js → LocalVmWorkspace-CrRyugwl.js} +1 -1
- package/dist/assets/{MacLocalControl-C9WNKBOQ.js → MacLocalControl-D2pf75xx.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-TpLES41m.js → MarkdownFilePreview-CLYypRvz.js} +1 -1
- package/dist/assets/{MenuMotion-DlcPi29I.js → MenuMotion-CNjHVOE4.js} +1 -1
- package/dist/assets/{NewBotDialog-RR1Mpu6A.js → NewBotDialog-CuYIfLJL.js} +1 -1
- package/dist/assets/{PhoneAppDialog-BgCzfoTA.js → PhoneAppDialog-EKN4JV-B.js} +1 -1
- package/dist/assets/{PlacesRail-BuGh6RP-.js → PlacesRail-eySktVNq.js} +1 -1
- package/dist/assets/{PluginsPanel-9xs64wF-.js → PluginsPanel-D8Kw3j_E.js} +1 -1
- package/dist/assets/{ProIntroduction-D2VFoI2P.js → ProIntroduction-Dutut6C-.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-CTXHKn9W.js → RemoteAgentSettingsPanel-BuNfrHcn.js} +1 -1
- package/dist/assets/{RoomPanel-DWMLsyy8.js → RoomPanel-vlOHVr2o.js} +1 -1
- package/dist/assets/{RoutinesPage-DMzWcWIs.js → RoutinesPage-Dgl6g38a.js} +1 -1
- package/dist/assets/{SettingsModal-Bg7GHnyA.js → SettingsModal-B6mWaU4-.js} +1 -1
- package/dist/assets/{ShareTeamDialog-CdwYfI5e.js → ShareTeamDialog-BNMxpMeG.js} +1 -1
- package/dist/assets/{SignedInSites-DuMfQBj_.js → SignedInSites-rqBhWQLe.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-CoGfO0Gu.js → TeamLibraryPanel-pCffPnk4.js} +1 -1
- package/dist/assets/{TeamMapPage-CDAuLL_z.js → TeamMapPage-BPNPSuOR.js} +1 -1
- package/dist/assets/{TriggersPage-BWYj3Pmd.js → TriggersPage--eDtuNSl.js} +1 -1
- package/dist/assets/{VisibilitySection-CVG-Q5ZJ.js → VisibilitySection-BCqfMHFk.js} +1 -1
- package/dist/assets/{WebhookTrigger-CmHpvYnK.js → WebhookTrigger-AXmqIpLx.js} +1 -1
- package/dist/assets/{WorksOnGrid-f6ao1NKp.js → WorksOnGrid-IvyvcWBI.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-Yl8cX4uT.js → abnfDiagram-YUKMZFIV-CNbBpzNE.js} +1 -1
- package/dist/assets/{activity-BkaEPnrL.js → activity-CtCHrNz-.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-DcAjaSwl.js → architectureDiagram-47P4ROYG-BZ3BXsFv.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-D4GJkvO7.js → blockDiagram-E7TT5TSB-9DpYtThS.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-COp8Arrz.js → c4Diagram-CRA5TL53-C9ygyYDI.js} +1 -1
- package/dist/assets/{calendar-days-WHyMFrxx.js → calendar-days-7b_rKY9F.js} +1 -1
- package/dist/assets/channel-CkUESPbF.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DL8jLa6h.js → chunk-2Q5K7J3B-DXA1dGYf.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CSCWg3L9.js → chunk-5VM5RSS4-Cmdn6u6A.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-Bsxo8S0u.js → chunk-7TKQ45FW-C6_3KbD6.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-DJ8cpd8z.js → chunk-AW2ZBBNX-DE_9xcGW.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3--tXiaXyH.js → chunk-FVRAUYC3-DeXezLUR.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-DMajpLo2.js → chunk-HTAEGDNF-WoJSboze.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-B-IMdEtd.js → chunk-JWPE2WC7-BarwLFEj.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-Bf62pjwo.js → chunk-KQW6MTUR-DZV0Hgcq.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-DraRivnf.js → chunk-XXDRQBXY-XRA7d5ef.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-7auUwgy0.js → classDiagram-v2-K4WV4PDN-BB9-8H0H.js} +1 -1
- package/dist/assets/{coins-DTDgWOsz.js → coins-RZxks5Iq.js} +1 -1
- package/dist/assets/{core-mTeZUwt8.js → core-CNxiO5i6.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-tRMEfI42.js → cose-bilkent-JH36ORCC-DlAty1qX.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-eSq0vgY_.js → cynefin-EF2NZ3EQ-DjVt4mTB.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-C9VCE7pj.js → cynefinDiagram-3GCD6N5R-BP3mxzbM.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-BNfBWy10.js → dagre-W4DXFKR2-D6R89cka.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-CKHbVIoS.js → diagram-2UJZ2QOL-ED6ZLR9P.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-BqtE_8V0.js → diagram-OVF4WLC6-DS5DPgfj.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-DavkIJ9f.js → diagram-PFPMY2P6-CkwWFUys.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-CfIVUSFu.js → diagram-UMYRVEAY-B6_INDe2.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-ChAEERCf.js → diagram-YEKJPTXX-Dt30zl92.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-C2a4um4F.js → diagram-ZIFT7M5P-BWQrszzW.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-B9-p-eJk.js → ebnfDiagram-VR2GEFS7-B40bZpn4.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BP2YfISU.js → elk-IJKZMXRS-BOAPURLs.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-ouqRz2lG.js → erDiagram-O2IAPWRE-DhIN8EFk.js} +1 -1
- package/dist/assets/{file-up-B3qv0JW8.js → file-up-Dg7JsLFP.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-FkJl8ORu.js → flowDiagram-OXPTDLAJ-o61yZ5Jp.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-Bxl5dqy0.js → ganttDiagram-R7TSEDQI-DKwTsk_A.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-CDp_K_81.js → gitGraphDiagram-XJZIOB7I-Dqte4h2a.js} +1 -1
- package/dist/assets/{import-name-Bs1m8Og-.js → import-name-BpcY7eF3.js} +1 -1
- package/dist/assets/{index-Cpmj1m_f.js → index-CN3qYQZ7.js} +2 -2
- package/dist/assets/{index-Cw8JuHFb.js → index-Df4sIScD.js} +1 -1
- package/dist/assets/{index-Dz0LVY7-.js → index-y3wal1WK.js} +1 -1
- package/dist/assets/{infoDiagram-5W2HQ5XZ-Bl5KtFKM.js → infoDiagram-5W2HQ5XZ-CeOhDqP5.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-DS9Ua7Oz.js → ishikawaDiagram-K3B6WC7H-BLxBG4Ku.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-Bk0db4xo.js → journeyDiagram-COXZFDF6-a7-OqFVb.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-OMdPbZg6.js → kanban-definition-P3RFRI5V-BpqE9wv9.js} +1 -1
- package/dist/assets/{mcp-servers-CFz7D6CS.js → mcp-servers-Cb7NFF4i.js} +1 -1
- package/dist/assets/{mermaid.core-DDfOqk65.js → mermaid.core-DCkDS2l6.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-DZWTgX60.js → mindmap-definition-LZFPQGKD-CbVxI-Dw.js} +1 -1
- package/dist/assets/{minimize-BGJr9i4X.js → minimize-BzhEcU2C.js} +1 -1
- package/dist/assets/{monitor-DOJm1Kz5.js → monitor-tq9gQZRc.js} +1 -1
- package/dist/assets/{new-bot-CSzhi2cd.js → new-bot-FZ7p0MaB.js} +1 -1
- package/dist/assets/{org-library-uUDo6Jt1.js → org-library-BurlfP-M.js} +1 -1
- package/dist/assets/{package-format-CDS8vgZO.js → package-format-B2CMS446.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-BLa51iQk.js → pegDiagram-BGZESJAR-JzbTYrpF.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-DZ9lT6YP.js → pieDiagram-CAPJLFHJ-FJGAn2CJ.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-DPvkU-WF.js → quadrantDiagram-GDMTTRAM-BH0XP_4R.js} +1 -1
- package/dist/assets/{rail-DUauxI9u.js → rail-Cq1USSn9.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-B5tz4-6y.js → railroadDiagram-SM67HX2B-DdmOm9v7.js} +1 -1
- package/dist/assets/{remote-desktop-panel-BlyMOzuP.js → remote-desktop-panel-ByjBIDKD.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-Cwx0ISbR.js → requirementDiagram-X7JNWC4A-CmHsqVU3.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-Cx12aSPG.js → sankeyDiagram-UM26HJRW-20UkT1qC.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-DcV1QedB.js → sequenceDiagram-ZO4K6R2Y-DbOCvva9.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BROnPBIO.js → sizeCapture-INFHLROL-BiRygHwv.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-8oI_fQuf.js → stateDiagram-v2-TBUQTH76-_b0RTe98.js} +1 -1
- package/dist/assets/{styles-B9Nw0uqu.js → styles-b2tBrp-F.js} +1 -1
- package/dist/assets/{swimlanes-N4OXWK64-eu_XqqPw.js → swimlanes-N4OXWK64-Cph2675B.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-DqgQUDUL.js +8 -0
- package/dist/assets/{team-share-CCRm9o2r.js → team-share-BegoEw7-.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-C6kOwwW9.js → timeline-definition-YOQAKGHF-2fj61Rzb.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-B_znjYaV.js → usecaseDiagram-VIAY4XPW-Cfx3YEF_.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-BSKbHvwy.js → vennDiagram-BLWOH2XV-BX_M6eTv.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-YoDrToQs.js → wardleyDiagram-YMQ3BMBF-BfDn4ghH.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-DVyv8Qod.js → xychartDiagram-TAQBALBS-CqrDBgpf.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/rail.html +4 -4
- package/dist-server/package.json +1 -1
- package/package.json +1 -1
- package/dist/assets/channel-CcBYtz0S.js +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-CVl0fy_Y.js +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,t as s,j as t,X as $,a as X}from"./styles-
|
|
1
|
+
import{r as l,t as s,j as t,X as $,a as X}from"./styles-b2tBrp-F.js";import{c as ee,B as te,L as G}from"./PlacesRail-eySktVNq.js";import{u as ae,z as F,D as L}from"./App-D93hKk8l.js";import{suggestedName as H}from"./WebhookTrigger-AXmqIpLx.js";import"./monitor-tq9gQZRc.js";import"./index-CN3qYQZ7.js";import"./MenuMotion-CNjHVOE4.js";import"./remote-desktop-DDRRx8uY.js";const N="w-full rounded-xl border border-hairline/60 bg-panel px-3.5 py-2.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/70",m="mb-1.5 block text-[12px] font-medium text-ink-secondary";function de({trigger:a,bots:x,initialBotId:y,onClose:u,onSaved:J}){const{dispatch:K}=ae(),[i,Q]=l.useState(a?.botId??(y&&x.some(e=>e.id===y)?y:x[0]?.id)??""),[r,O]=l.useState(null),[v,B]=l.useState(a?.app??""),[b,g]=l.useState(a?.event??""),[k,U]=l.useState(a?.accountId??""),[D,V]=l.useState(a?.filter??{}),[f,E]=l.useState({}),[h,W]=l.useState(a?.prompt??""),[w,Y]=l.useState(a?.name??""),[I,P]=l.useState(!1),[S,C]=l.useState(""),R=l.useRef(null);ee(R,u),l.useEffect(()=>{if(a||!i)return;let e=!0;return O(null),F.events(i).then(n=>{if(!e)return;O(n);const o=n.apps.find(d=>d.events.length);B(d=>n.apps.some(A=>A.app===d)?d:o?.app??"")}).catch(n=>{e&&C(n instanceof Error?n.message:String(n))}),()=>{e=!1}},[i,a]);const p=r?.apps.find(e=>e.app===v),z=p?.events??[],c=z.find(e=>e.event===b)??(a?void 0:z[0]);l.useEffect(()=>{!a&&c&&c.event!==b&&g(c.event)},[c,b,a]);const T=(c?.configFields??[]).filter(e=>e.required),Z=v==="gmail",q=a?.delivery??c?.delivery,_=async()=>{const e=x.find(o=>o.id===i),n=Object.fromEntries(Object.entries(D).filter(([,o])=>typeof o=="string"&&o.trim()));P(!0),C("");try{const o=a?await F.update(a.id,{name:w.trim()||a.name,prompt:h.trim(),filter:Object.keys(n).length?n:null}):await F.create({botId:i,app:v,event:c?.event??b,prompt:h.trim(),name:w.trim()||H(h,e),...k?{account:k}:{},...Object.keys(n).length?{filter:n}:{},...Object.keys(f).length?{config:f}:{}});J?.(o),u()}catch(o){C(o instanceof Error?o.message:String(o))}finally{P(!1)}},j=(e,n,o)=>t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:n}),t.jsx("input",{value:D[e]??"",onChange:d=>V(A=>({...A,[e]:d.target.value})),placeholder:o,className:N})]},e),M=a?s("automations.editor.app.editTitle"):s("automations.editor.appEvent.title");return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-5",onMouseDown:e=>e.target===e.currentTarget&&u(),children:t.jsxs("div",{ref:R,role:"dialog","aria-modal":"true","aria-label":M,tabIndex:-1,className:"flex max-h-[90vh] w-full max-w-[560px] flex-col overflow-hidden rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[t.jsxs("div",{className:"flex items-start justify-between border-b border-hairline/40 px-5 py-4",children:[t.jsx("div",{className:"text-[17px] font-semibold text-ink",children:M}),t.jsx("button",{type:"button",onClick:u,"aria-label":s("automations.newBox.cancel"),className:"rounded-lg p-2 text-ink-secondary hover:bg-raised hover:text-ink",children:t.jsx($,{size:18})})]}),t.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-5",children:[!a&&t.jsxs("div",{children:[t.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:s("automations.editor.app.who")}),t.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:x.map(e=>t.jsxs("button",{type:"button",onClick:()=>Q(e.id),className:X("flex min-w-0 items-center gap-2 rounded-xl border px-3 py-2 text-left",i===e.id?"border-accent/70 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised/60"),children:[t.jsx(te,{bot:e,state:i===e.id?"happy":"idle",size:32,animated:!1}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-ink",children:e.name})]},e.id))})]}),!a&&!r&&!S&&t.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[t.jsx(G,{size:14,className:"animate-spin"}),s("automations.editor.appEvent.loading")]}),!a&&r&&(r.unavailable||!r.apps.some(e=>e.events.length))&&t.jsxs("div",{className:"rounded-xl border border-hairline/45 bg-inset/50 p-3.5 text-[13px] text-ink-secondary",children:[t.jsx("p",{children:r.unavailable??s("automations.editor.appEvent.noApps")}),!r.unavailable&&t.jsx("button",{type:"button",onClick:()=>K({type:"togglePlugins",open:!0,surface:"apps"}),className:"mt-2.5 rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink hover:brightness-110",children:s("automations.editor.appEvent.connect")})]}),!a&&r&&p&&t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.app")}),t.jsx(L,{value:v,onChange:e=>{B(e.target.value),g(""),E({})},"aria-label":s("automations.editor.appEvent.app"),className:"w-full",children:r.apps.filter(e=>e.events.length).map(e=>t.jsx("option",{value:e.app,children:e.name},e.app))})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.event")}),t.jsx(L,{value:c?.event??"",onChange:e=>{g(e.target.value),E({})},"aria-label":s("automations.editor.appEvent.event"),className:"w-full",children:z.map(e=>t.jsx("option",{value:e.event,children:e.name},e.event))})]}),p.accounts.length>1&&t.jsxs("label",{className:"block sm:col-span-2",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.account")}),t.jsxs(L,{value:k,onChange:e=>U(e.target.value),"aria-label":s("automations.editor.appEvent.account"),className:"w-full",children:[t.jsx("option",{value:""}),p.accounts.map(e=>t.jsx("option",{value:e.id,children:e.alias??e.id},e.id))]})]}),T.map(e=>t.jsxs("label",{className:"block sm:col-span-2",children:[t.jsx("span",{className:m,children:e.name}),t.jsx("input",{value:f[e.name]??"",onChange:n=>E(o=>({...o,[e.name]:n.target.value})),placeholder:e.description,className:N})]},e.name))]}),(a||p)&&t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[Z?[j("from",s("automations.editor.appEvent.from"),"acme.com"),j("subject",s("automations.editor.appEvent.subject"),"order"),j("label",s("automations.editor.appEvent.label"),"Customers")]:j("text",s("automations.editor.appEvent.text"),"urgent"),q&&t.jsx("p",{className:"self-end text-[12px] text-ink-secondary sm:col-span-2",children:q==="poll"?s("automations.editor.appEvent.checks"):s("automations.editor.appEvent.instant")})]}),(a||p)&&t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"mb-2 block text-[13px] font-medium text-ink",children:s("automations.editor.app.what")}),t.jsx("textarea",{value:h,onChange:e=>W(e.target.value),rows:3,placeholder:s("automations.editor.appEvent.whatPlaceholder"),className:X(N,"resize-y py-3 leading-relaxed")})]}),(a||p)&&t.jsxs("details",{className:"rounded-xl border border-hairline/45 bg-inset/45 px-4 py-3",children:[t.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink",children:s("automations.more")}),t.jsxs("label",{className:"mt-4 block",children:[t.jsx("span",{className:m,children:s("automations.editor.app.name")}),t.jsx("input",{value:w,onChange:e=>Y(e.target.value),placeholder:H(h,x.find(e=>e.id===i)),className:N})]})]}),S&&t.jsx("div",{role:"alert",className:"rounded-xl border border-danger/30 bg-danger/10 px-3.5 py-3 text-[12px] text-danger",children:S})]}),t.jsxs("div",{className:"flex justify-end gap-2 border-t border-hairline/40 px-5 py-4",children:[t.jsx("button",{type:"button",onClick:u,className:"rounded-xl px-4 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:s("automations.newBox.cancel")}),t.jsxs("button",{type:"button",disabled:I||!i||!a&&!c||T.some(e=>!f[e.name]?.trim()),onClick:()=>{_()},className:"flex items-center gap-2 rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-40",children:[I&&t.jsx(G,{size:14,className:"animate-spin"}),a?s("automations.editor.app.save"):s("automations.editor.app.create")]})]})]})})}export{de as AppEventEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Ce,t as s,b as ee,aA as Os,j as e,i as Ae,ae as pe,a as O,r as x,S as Lt,ah as Mt,o as Es,X as Tt}from"./styles-B9Nw0uqu.js";import{fa as Rs,fb as Is,_ as Ve,bu as As,dd as Bt,w as Ls,fc as Ms,fd as Ts,E as Dt,fe as Bs,N as Ft,eo as Ds,x as Fs,ff as st,bp as at,fg as $t,n as se,u as B,fh as $s,ad as Ye,F as zt,A as Ht,S as nt,a9 as Pe,T as _t,R as zs,fi as Hs,fj as _s,fk as Us,fl as Ks,fm as qs,fn as rt,fo as Ws,fp as Vs,fq as Ys,fr as Gs,b5 as Js,fs as Qs,ft as Xs,fu as Zs,I as ea,fv as ke,bL as Ge,fw as ta,aE as L,aK as X,e8 as sa,dF as aa,fx as na,aF as He,ck as ra,dU as ia,dV as la,fy as oa,fz as Ut,fA as Kt,fB as ca,fC as da,fD as ua,fE as ma,dI as _e,an as it,fF as Le,fG as pa,fH as je,ar as xa,fI as qt,fJ as lt,ag as Ue,fK as ha,fL as fa,fM as ga,fN as Wt,fO as ya,fP as va,fQ as ba,fR as ka,fS as Q,aT as te,aV as J,fT as ja,fU as wa,fV as Na,d0 as Sa,d as Ca,G as Pa,c_ as Vt,af as Oa,fW as W,aS as ce,fX as fe,fY as Ea,dj as Ra,fZ as Oe,aU as re,f_ as Ia,f$ as Aa,g0 as La,eb as Ma,g1 as ot,g2 as Ta,g3 as Ba,g4 as Da,g5 as Fa,g6 as $a,g7 as za,ay as Ha,g8 as Yt,g9 as _a,ga as Ua,gb as Ka,gc as qa,gd as Wa,ge as Va,gf as Ya,gg as Ga,gh as Ja,gi as Qa,gj as Xa,gk as Za,gl as Je,k as en,B as Ke,gm as tn,gn as sn,go as an,gp as nn,bT as rn,gq as Gt,eS as ln,gr as ct,gs as on,gt as cn,cH as dt,bs as dn,cZ as un,gu as mn,gv as Jt,gw as ve,gx as ut,gy as pn,aI as Me,dW as xn,gz as hn,aN as fn,C as gn,cl as yn,gA as vn,gB as bn,gC as kn,aP as jn}from"./App-DToXVaV2.js";import{y as Qt,d as ge,a0 as we,a1 as wn,a2 as Nn,a3 as mt,a4 as Te,a5 as Sn,a6 as Cn,a7 as Pn,a8 as On,a9 as En,aa as pt,ab as Rn,ac as In,L as An,K as Ln,B as qe,P as Ee,r as Mn,ad as Tn,$ as Bn,u as Xt}from"./PlacesRail-BuGh6RP-.js";import{C as Dn}from"./coins-DTDgWOsz.js";import{C as he,a as Fn}from"./MenuMotion-DlcPi29I.js";import{b as Z,m as Zt,i as We,f as Qe,c as me,d as xt,e as Ne,o as $n,g as zn,h as oe,n as Be,t as es,s as Xe,j as ts,k as Hn,l as _n,p as Un,r as ss,q as Kn,u as qn,w as Wn,x as as,y as ns,z as ht,B as Vn,C as rs,R as ft,D as Yn,E as Gn,F as Jn,G as Qn,H as Xn,J as Zn,O as er,K as tr,L as is,N as sr,V as ar,P as nr,M as rr,A as ir,a as lr,S as or,I as cr}from"./VisibilitySection-CVG-Q5ZJ.js";import{s as dr,r as ur,a as mr,R as pr}from"./ComputerFilesPane-DdeiWUnd.js";import{M as gt}from"./monitor-DOJm1Kz5.js";import{a as ls,m as os,b as xr,c as hr}from"./mcp-servers-CFz7D6CS.js";import{R as fr}from"./RoutinesPage-DMzWcWIs.js";import{S as gr}from"./SignedInSites-DuMfQBj_.js";import"./index-Cpmj1m_f.js";import"./org-library-uUDo6Jt1.js";import"./package-format-CDS8vgZO.js";import"./WorksOnGrid-f6ao1NKp.js";import"./ProIntroduction-D2VFoI2P.js";import"./remote-desktop-DDRRx8uY.js";const yr=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],vr=Ce("calendar-plus",yr);const br=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],kr=Ce("library",br);const jr=[["rect",{width:"3",height:"8",x:"13",y:"2",rx:"1.5",key:"diqz80"}],["path",{d:"M19 8.5V10h1.5A1.5 1.5 0 1 0 19 8.5",key:"183iwg"}],["rect",{width:"3",height:"8",x:"8",y:"14",rx:"1.5",key:"hqg7r1"}],["path",{d:"M5 15.5V14H3.5A1.5 1.5 0 1 0 5 15.5",key:"76g71w"}],["rect",{width:"8",height:"3",x:"14",y:"13",rx:"1.5",key:"1kmz0a"}],["path",{d:"M15.5 19H14v1.5a1.5 1.5 0 1 0 1.5-1.5",key:"jc4sz0"}],["rect",{width:"8",height:"3",x:"2",y:"8",rx:"1.5",key:"1omvl4"}],["path",{d:"M8.5 5H10V3.5A1.5 1.5 0 1 0 8.5 5",key:"16f3cl"}]],cs=Ce("slack",jr);const wr=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Nr=Ce("tag",wr),Sr=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Rs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Is,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:cs,keywords:["slack","slack app","admin","message","direct messages","mentions"]},{id:"soul",label:"Soul",labelKey:"botSettings.sections.soul",icon:Ve,keywords:["standing instructions","instructions","persona","rules","soul.md"]},{id:"skills",label:"Skills",labelKey:"botSettings.sections.skills",icon:As,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:Bt,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:kr,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Ls,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Ms,keywords:["works on","computer","vm","cloud","vps","folder","workspace","browser","connected apps","composio","webhooks","always allow","grants","tool selection","tools","mcp","allow","exclude"]},{id:"model",label:"Model",labelKey:"botSettings.sections.model",icon:Ts,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:Dt,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:Bs,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:Ft,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:Ds,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:Dn,keywords:["tokens","cost","billing"]}],yt={completed:"botOverview.routine.last.completed",failed:"botOverview.routine.last.failed",missed:"botOverview.routine.last.missed",cancelled:"botOverview.routine.last.cancelled",running:"botOverview.routine.last.running",queued:"botOverview.routine.last.queued",waiting:"botOverview.routine.last.waiting"};function Cr(t,a=ee()){if(!t||a==="en")return null;if(t.paused)return s("botOverview.routine.paused",{name:t.name});const n=t.lastRun;if(n&&!Object.hasOwn(yt,n.status))return null;try{return[s("botOverview.routine.line",{schedule:Fs(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:st(t.nextRunAt)})]:[],...n?[s(yt[n.status],{time:st(n.at)})]:[]].join(" ")}catch{return null}}const vt={"Works in its private workspace.":"botOverview.line.privateWorkspace","Has the built-in browser.":"botOverview.line.browser","Has no connected apps.":"botOverview.line.noApps","Won't act on a schedule.":"botOverview.line.noSchedule","Can talk to the other bot.":"botOverview.line.talksToOne","Talks only to the bots chosen for it.":"botOverview.line.talksToChosen","Cannot initiate contact with other bots.":"botOverview.line.noPeerContact","Command approvals use Ask mode; saved permissions and provider rules still apply.":"botOverview.line.askMode","Command approvals follow the provider's custom configuration.":"botOverview.line.customApprovals","Asks before contacting other bots.":"botOverview.line.asksPeers","Can't use a computer.":"botOverview.line.noComputer","Profile proposal cards require your approval.":"botOverview.line.profileApproval","Connected apps could not be checked.":"botOverview.line.appsUnchecked"},bt={"Auto; availability is checked when a task starts":"botOverview.preference.auto","cloud computer":"botOverview.preference.cloud","Local VM":"botOverview.preference.vm","this computer":"botOverview.preference.local","browser only":"botOverview.preference.browser"};function kt(t,a){return!a||a.map(n=>n||"General").join(", ")!==t?t:a.map(n=>n||s("botAccess.teams.general")).join(", ")}const jt=t=>Object.hasOwn(bt,t)?s(bt[t]):t,wt=(t,a,n)=>Number(t)===1?a:n,Pr=[{line:/^Can talk to all (\d+) other bots, in any department\.$/,key:()=>"botOverview.line.talksToAll",params:([,t])=>({count:Number(t)})},{line:/^Also in charge of these departments: (.+)\.$/,key:()=>"botOverview.line.alsoInCharge",params:([,t],a)=>({departments:kt(t,a)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>wt(t,"botOverview.line.peersSectionOne","botOverview.line.peersSectionMany"),params:([,t])=>({count:Number(t)})},{line:/^Can talk to (\d+) other bots? in its allowed (?:teams|departments)\.$/,key:([,t])=>wt(t,"botOverview.line.peersTeamsOne","botOverview.line.peersTeamsMany"),params:([,t])=>({count:Number(t)})},{line:/^Coordinates its (?:section|department) as Chief of Staff\.$/,key:()=>"botOverview.line.chief",params:()=>({role:s("sidebar.bot.chiefOfStaff")})},{line:/^May also coordinate these (?:teams|departments): (.+)\.$/,key:()=>"botOverview.line.alsoTeams",params:([,t],a)=>({teams:kt(t,a)})}],Or=t=>ee()!=="en"&&Object.hasOwn(Os[ee()]??{},t);function Er(t,a){for(const n of Pr){const l=n.line.exec(t);if(!l)continue;const r=n.key(l);return Or(r)?s(r,n.params(l,a)):t}return null}function De(t,a){if(Object.hasOwn(vt,t))return s(vt[t]);const n=Er(t,a);if(n!==null)return n;const l=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(l)return s(l[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(l[1]),apps:l[2]});const r=ee()==="en"?null:/^Computer preference: (.+), which isn't available on My Cloud\.$/.exec(t);if(r)return s("botOverview.line.computerNotOnCloud",{preference:jt(r[1])});const i=/^Computer preference: (.+)\.$/.exec(t);if(i)return s("botOverview.line.computer",{preference:jt(i[1])});const c=/^Works in (.+)\.$/.exec(t);if(c)return s("botOverview.line.folder",{folder:c[1]});const d=/^Knows how to (.+)\.$/.exec(t);if(d)return s("botOverview.line.skill",{skill:d[1]});const o=/^Listens for “(.+)” webhooks\.$/.exec(t);return o?s("botOverview.line.webhook",{name:o[1]}):t}const Nt={name:"approval.applied.field.name",title:"approval.applied.field.title",description:"approval.applied.field.description",soul:"approval.applied.field.soul",cwd:"approval.applied.field.cwd",notifications:"approval.applied.field.notifications",speakReplies:"approval.applied.field.speakReplies"};function Rr(t,a=ee()){const n=/^(\w+): /.exec(t)?.[1];return a==="en"||!n||!Object.hasOwn(Nt,n)?t:`${s(Nt[n])}: ${t.slice(n.length+2)}`}function Ir({data:t,error:a,open:n,onToggle:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:l,"aria-expanded":n,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("span",{className:"text-[15px] font-medium text-ink",children:t?s("botOverview.promptPreviewCount",{bytes:t.totalBytes.toLocaleString(Ae()),tokens:t.approxTokens.toLocaleString(Ae())}):s("botOverview.promptPreview")}),e.jsx(pe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",n&&"rotate-180")})]}),n&&!t&&a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.promptError")}),n&&!t&&!a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.loading")}),n&&t&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[t.sections.map(r=>e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center justify-between gap-3 text-[13px] text-ink",children:[e.jsx("span",{children:r.label}),e.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:s("botOverview.bytes",{count:r.bytes.toLocaleString(Ae())})})]}),e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-ink",children:r.text})]},r.id)),t.note&&e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t.note})]})]})}function Ar({overview:t,refreshError:a,prompt:n,promptError:l,onOpen:r,onSetup:i}){const[c,d]=x.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const u=(t.setup??[]).filter(h=>!h.done),p=(h,k)=>s(`botOverview.setup.${h}`)||k;return e.jsxs("div",{className:"flex flex-col gap-4",children:[a&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("botOverview.refreshError")}),u.length>0&&e.jsxs("div",{className:"rounded-xl border border-accent/30 bg-accent/[0.06] p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botSetup.ideas")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:s("botSetup.optional")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:u.map(h=>e.jsx("li",{children:h.section?e.jsxs("button",{type:"button",onClick:()=>r(h.section),className:"flex w-full items-center gap-2.5 rounded-lg px-1 py-1 text-left text-[13px] text-ink hover:bg-inset",children:[e.jsx(at,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:p(h.id,h.label)}),e.jsx(he,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-secondary rtl:-scale-x-100"})]}):e.jsxs("div",{className:"flex items-center gap-2.5 px-1 py-1 text-[13px] text-ink",children:[e.jsx(at,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:p(h.id,h.label)})]})},h.id))}),i&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:i,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(Ve,{size:14})," ",s("botSetup.withBot")]}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:s("botSetup.help")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t.who.name}),t.who.title&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t.who.title}),t.who.blurb&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink",children:t.who.blurb}),t.who.soulLead&&e.jsxs("div",{className:"mt-3 rounded-lg bg-inset px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t.who.soulLead}),e.jsx("button",{type:"button",onClick:()=>r("soul"),className:"mt-1.5 rounded-md text-[12px] font-medium text-accent-text hover:underline",children:s("botOverview.readAll")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.does")}),t.does.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.doesEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.does.map((h,k)=>e.jsx("li",{children:Cr(t.doesRoutines?.[k])??De(h)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.canReach")}),t.reaches.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.reachEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.reaches.map((h,k)=>e.jsx("li",{children:De(h,t.managedSections)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.wont")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.wont.map((h,k)=>e.jsx("li",{children:De(h,t.managedSections)},k))})]}),e.jsx(Ir,{data:n,error:l,open:c,onToggle:()=>d(h=>!h)}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.recentChanges")}),e.jsxs("button",{type:"button",onClick:()=>r("history"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink",children:[s("botOverview.viewAll")," ",e.jsx(he,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),t.recent.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.recentEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-ink",children:t.recent.map((h,k)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Rr(h.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",$t(h.at)]})]},k))})]})]})}function Lr({managementUrl:t}){return e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:s("botSlack.body")}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[s("botSlack.manage")," ",e.jsx(Qt,{size:14,"aria-hidden":"true"})]})]})}function Mr(t){if(!t||typeof t!="object")return null;const{available:a,managementUrl:n}=t;if(a!==!0||typeof n!="string")return null;try{return new URL(n).protocol==="https:"?n:null}catch{return null}}function ds(t){const[a,n]=x.useState(null);return x.useEffect(()=>{const l=new AbortController;return se(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:l.signal,timeoutMs:1e4}).then(r=>{l.signal.aborted||n({botId:t,url:Mr(r)})}).catch(()=>{l.signal.aborted||n({botId:t,url:null})}),()=>l.abort()},[t]),a?.botId===t?a.url:null}const ne="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",Fe="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",ae=t=>t instanceof Error?t.message:String(t);function us(t){const a=[],n=(r,i,c)=>{r&&a.push(s(r===1?i:c,{count:r}))};n(t.expired,"memory.upkeep.summary.archived.one","memory.upkeep.summary.archived.many"),n(t.duplicates,"memory.upkeep.summary.merged.one","memory.upkeep.summary.merged.many"),n(t.superseded,"memory.upkeep.summary.crossed.one","memory.upkeep.summary.crossed.many"),n(t.organized,"memory.upkeep.summary.filed.one","memory.upkeep.summary.filed.many");const l=a.length?a.join(", "):s("memory.upkeep.summary.none");return l.charAt(0).toUpperCase()+l.slice(1)}function Tr(t,a){const n=t.via==="team-setup"?s("memory.journal.actor.teamSetup"):t.actor==="bot"?a:t.actor==="import"?s("memory.journal.actor.import"):t.actor==="upkeep"?s("memory.journal.actor.upkeep"):s("memory.journal.actor.you"),l=Kn(t.path),r=t.path===Z?l:t.path===qn?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:l}):s("memory.journal.topic",{file:l}),i=c=>s(c===1?"memory.journal.line.one":"memory.journal.line.many",{count:c});return t.kind==="created"?s("memory.journal.created",{who:n,topic:r,detail:t.added?s("memory.journal.withLines",{lines:i(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:n,topic:r}):t.added&&!t.removed?s("memory.journal.added",{who:n,lines:i(t.added),topic:r}):t.removed&&!t.added?s("memory.journal.removed",{who:n,lines:i(t.removed),topic:r}):s("memory.journal.rewrote",{who:n,lines:i(Math.max(t.added,t.removed)),topic:r})}function ms({changed:t,stale:a,busy:n,onReviewed:l}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(a?"memory.lendingReviewStale":"memory.lendingReview")}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.lendingReviewChanged")}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.map(r=>e.jsx("li",{className:"break-all font-mono text-[12px] text-ink",children:r},r))})]}),e.jsx("button",{type:"button",className:O(ne,"mt-3"),disabled:n,onClick:l,children:s("memory.lendingReviewed")})]})}function Br({bot:t,active:a=!0,onToggle:n}){const{capabilities:l}=ge(),[r,i]=x.useState(null),[c,d]=x.useState(null),[o,u]=x.useState(null),[p,h]=x.useState(null),[k,f]=x.useState(null),[b,y]=x.useState(null),[C,v]=x.useState(null),[w,N]=x.useState(!1),[E,M]=x.useState(null),[F,T]=x.useState(""),[I,z]=x.useState(null),[A,m]=x.useState(!1),[R,D]=x.useState(null),[H,_]=x.useState(!1),[G,Y]=x.useState(!1),{state:U,dispatch:g}=B(),$=$s(U.config),[ie,de]=x.useState(!1),[xe,S]=x.useState(""),K=async j=>{const[P,Re,Ps]=await Promise.all([Qe(t.id),me(t.id),xt(t.id).catch(()=>null)]);if(i(P),D(P.lendingReview??null),d(Re),z(Ps),j){const Ie=await Ne(t.id,j);u({path:Ie.path,text:Ie.text,hash:Ie.hash,dirty:!1,readOnly:j.startsWith("memory/log/")})}};x.useEffect(()=>{if(!a)return;let j=!1;y(null);const P=o?.dirty===!0;return K(P?void 0:o?.path??Z).catch(Re=>{j||y(ae(Re))}),()=>{j=!0}},[a,t.id]);const V=async j=>{y(null),h(null);try{const P=await Ne(t.id,j);u({path:P.path,text:P.text,hash:P.hash,dirty:!1,readOnly:j.startsWith("memory/log/")})}catch(P){y(ae(P))}},q=async j=>{if(o){N(!0),y(null);try{const P=await Xe(t.id,o.path,o.text,j);if(!P.ok){h({path:o.path,current:P.current,currentHash:P.currentHash});return}h(null),f(null),u({...o,text:P.doc.text,hash:P.doc.hash,dirty:!1}),i(P.overview),d(await me(t.id))}catch(P){y(ae(P))}finally{N(!1)}}},le=()=>{!p||!o||(f(o.text),u({...o,text:p.current,hash:p.currentHash,dirty:!1}),h(null))},ye=async j=>{if(window.confirm(s("memory.confirmDelete",{name:j.name}))){y(null);try{const{overview:P}=await ts(t.id,j.path);i(P),d(await me(t.id)),o?.path===j.path&&u(null)}catch(P){y(ae(P))}}},et=async()=>{const j=Hn(F);if(!j){y(s("memory.topicNameError"));return}T(""),await V(`memory/${j}`),u(P=>P&&{...P,dirty:!0,text:P.text||Dr(j)})},js=async j=>{M(j.id),y(null);try{const P=await ss(t.id,j.id);i(P.overview),d(await me(t.id)),o?.path===j.path&&!o.dirty&&u({...o,text:P.text,hash:P.hash}),v(s("memory.restored",{path:j.path}))}catch(P){y(ae(P))}finally{M(null)}},tt=async j=>{y(null),v(null);try{await $n(t.id,j)}catch(P){y(ae(P))}},ws=()=>{const j=t.memoryUpkeep===!1;g({type:"updateBot",botId:t.id,patch:{memoryUpkeep:j}}),z(P=>P&&{...P,enabled:j})},Ns=async()=>{if(!ie){de(!0),S("");try{const j=await se("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!$}})});g({type:"configStatus",config:j})}catch(j){S(j instanceof Error?j.message:s("memory.learnFromRooms.error"))}finally{de(!1)}}},Ss=async()=>{m(!0),y(null),v(null);try{const{report:j,overview:P}=await es(t.id);i(P),d(await me(t.id)),z(await xt(t.id)),o&&!o.dirty&&await V(o.path),v(`${us(j)}.${j.note?` ${j.note}`:""}`)}catch(j){y(ae(j))}finally{m(!1)}},Cs=l.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange:j=>n(j.target.checked)}),s("memory.enable")]}),e.jsxs("p",{className:"mt-1 text-[13px] text-ink-secondary",children:[s("memory.enableHelp"),t.busy?` ${s("memory.busyHelp")}`:""]}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.notesHelp")}),r&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink-secondary",title:r.workspacePath,children:Ye(r.workspacePath,Cs)}),e.jsx("button",{type:"button",className:ne,onClick:()=>{tt("obsidian")},children:s("memory.openObsidian")}),e.jsxs("button",{type:"button",className:O(ne,"inline-flex items-center gap-1.5"),onClick:()=>{tt("folder")},children:[e.jsx(zt,{size:14}),s("memory.showFileManager")]})]})]}),R&&e.jsx(ms,{changed:R.changed,stale:H,busy:G,onReviewed:()=>{Y(!0),Zt(t.id,R.token).then(()=>{D(null),_(!1)}).catch(j=>{if(j instanceof Ht&&j.status===409)return _(!0),K();y(ae(j))}).finally(()=>Y(!1))}}),r&&e.jsx($r,{index:r.index}),t.memoryEnabled!==!1&&e.jsx(Fr,{enabled:t.memoryUpkeep!==!1,status:I,tidying:A,onToggle:ws,onTidy:()=>{Ss()},rooms:{enabled:$,saving:ie,error:xe,onToggle:()=>{Ns()}}}),o&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:o.path}),o.path!==Z&&e.jsx("button",{type:"button",className:Fe,onClick:()=>{V(Z)},children:s("memory.backToIndex")})]}),p&&e.jsx(ps,{botName:t.name,busy:w,onReload:le,onOverwrite:()=>{q(p.currentHash)}}),e.jsx("textarea",{className:O(We,"mt-2 min-h-[200px] resize-y font-mono text-[13px] leading-relaxed"),value:o.text,readOnly:o.readOnly,placeholder:o.path===Z?s("memory.indexPlaceholder"):s("memory.notePlaceholder"),"aria-label":o.path===Z?s("memory.botMemory"):s("memory.fileLabel",{path:o.path}),onChange:j=>u({...o,text:j.target.value,dirty:!0})}),o.readOnly?e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.logsReadOnly")}):e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{q(o.hash)},disabled:w||!o.dirty,className:ne,children:w?s("memory.saving"):s("memory.save")}),o.dirty&&e.jsx("button",{type:"button",className:Fe,disabled:w,onClick:()=>{V(o.path)},children:s("memory.discard")})]}),k!==null&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:k}),e.jsx("button",{type:"button",className:O(Fe,"mt-1"),onClick:()=>f(null),children:s("memory.dismissDraft")})]})]}),r&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx(Ct,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:r.topics,selected:o?.path,onOpen:j=>{V(j.path)},onDelete:j=>{ye(j)}}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{className:O(We,"py-1.5 text-[13px]"),value:F,placeholder:s("memory.newTopicPlaceholder"),"aria-label":s("memory.newTopicLabel"),onChange:j=>T(j.target.value),onKeyDown:j=>{j.key==="Enter"&&et()}}),e.jsx("button",{type:"button",className:ne,disabled:!F.trim(),onClick:()=>{et()},children:s("memory.newTopic")})]}),r.logs.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Ct,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:r.logs,selected:o?.path,onOpen:j=>{V(j.path)},onDelete:j=>{ye(j)}})})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.changes")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.changesHelp")}),e.jsx("div",{className:"mt-3",children:e.jsx(Ze,{rows:c,botName:t.name,reverting:E,onRevert:j=>{js(j)}})})]}),C&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:C}),b&&e.jsx("div",{className:"text-[13px] text-danger",children:b})]})}function Dr(t){return`---
|
|
1
|
+
import{c as Ce,t as s,b as ee,aA as Os,j as e,i as Ae,ae as pe,a as O,r as x,S as Lt,ah as Mt,o as Es,X as Tt}from"./styles-b2tBrp-F.js";import{fa as Rs,fb as Is,_ as Ve,bu as As,dd as Bt,w as Ls,fc as Ms,fd as Ts,E as Dt,fe as Bs,N as Ft,eo as Ds,x as Fs,ff as st,bp as at,fg as $t,n as se,u as B,fh as $s,ad as Ye,F as zt,A as Ht,S as nt,a9 as Pe,T as _t,R as zs,fi as Hs,fj as _s,fk as Us,fl as Ks,fm as qs,fn as rt,fo as Ws,fp as Vs,fq as Ys,fr as Gs,b5 as Js,fs as Qs,ft as Xs,fu as Zs,I as ea,fv as ke,bL as Ge,fw as ta,aE as L,aK as X,e8 as sa,dF as aa,fx as na,aF as He,ck as ra,dU as ia,dV as la,fy as oa,fz as Ut,fA as Kt,fB as ca,fC as da,fD as ua,fE as ma,dI as _e,an as it,fF as Le,fG as pa,fH as je,ar as xa,fI as qt,fJ as lt,ag as Ue,fK as ha,fL as fa,fM as ga,fN as Wt,fO as ya,fP as va,fQ as ba,fR as ka,fS as Q,aT as te,aV as J,fT as ja,fU as wa,fV as Na,d0 as Sa,d as Ca,G as Pa,c_ as Vt,af as Oa,fW as W,aS as ce,fX as fe,fY as Ea,dj as Ra,fZ as Oe,aU as re,f_ as Ia,f$ as Aa,g0 as La,eb as Ma,g1 as ot,g2 as Ta,g3 as Ba,g4 as Da,g5 as Fa,g6 as $a,g7 as za,ay as Ha,g8 as Yt,g9 as _a,ga as Ua,gb as Ka,gc as qa,gd as Wa,ge as Va,gf as Ya,gg as Ga,gh as Ja,gi as Qa,gj as Xa,gk as Za,gl as Je,k as en,B as Ke,gm as tn,gn as sn,go as an,gp as nn,bT as rn,gq as Gt,eS as ln,gr as ct,gs as on,gt as cn,cH as dt,bs as dn,cZ as un,gu as mn,gv as Jt,gw as ve,gx as ut,gy as pn,aI as Me,dW as xn,gz as hn,aN as fn,C as gn,cl as yn,gA as vn,gB as bn,gC as kn,aP as jn}from"./App-D93hKk8l.js";import{y as Qt,d as ge,a0 as we,a1 as wn,a2 as Nn,a3 as mt,a4 as Te,a5 as Sn,a6 as Cn,a7 as Pn,a8 as On,a9 as En,aa as pt,ab as Rn,ac as In,L as An,K as Ln,B as qe,P as Ee,r as Mn,ad as Tn,$ as Bn,u as Xt}from"./PlacesRail-eySktVNq.js";import{C as Dn}from"./coins-RZxks5Iq.js";import{C as he,a as Fn}from"./MenuMotion-CNjHVOE4.js";import{b as Z,m as Zt,i as We,f as Qe,c as me,d as xt,e as Ne,o as $n,g as zn,h as oe,n as Be,t as es,s as Xe,j as ts,k as Hn,l as _n,p as Un,r as ss,q as Kn,u as qn,w as Wn,x as as,y as ns,z as ht,B as Vn,C as rs,R as ft,D as Yn,E as Gn,F as Jn,G as Qn,H as Xn,J as Zn,O as er,K as tr,L as is,N as sr,V as ar,P as nr,M as rr,A as ir,a as lr,S as or,I as cr}from"./VisibilitySection-BCqfMHFk.js";import{s as dr,r as ur,a as mr,R as pr}from"./ComputerFilesPane-DAQhcfSG.js";import{M as gt}from"./monitor-tq9gQZRc.js";import{a as ls,m as os,b as xr,c as hr}from"./mcp-servers-Cb7NFF4i.js";import{R as fr}from"./RoutinesPage-Dgl6g38a.js";import{S as gr}from"./SignedInSites-rqBhWQLe.js";import"./index-CN3qYQZ7.js";import"./org-library-BurlfP-M.js";import"./package-format-B2CMS446.js";import"./WorksOnGrid-IvyvcWBI.js";import"./ProIntroduction-Dutut6C-.js";import"./remote-desktop-DDRRx8uY.js";const yr=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],vr=Ce("calendar-plus",yr);const br=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],kr=Ce("library",br);const jr=[["rect",{width:"3",height:"8",x:"13",y:"2",rx:"1.5",key:"diqz80"}],["path",{d:"M19 8.5V10h1.5A1.5 1.5 0 1 0 19 8.5",key:"183iwg"}],["rect",{width:"3",height:"8",x:"8",y:"14",rx:"1.5",key:"hqg7r1"}],["path",{d:"M5 15.5V14H3.5A1.5 1.5 0 1 0 5 15.5",key:"76g71w"}],["rect",{width:"8",height:"3",x:"14",y:"13",rx:"1.5",key:"1kmz0a"}],["path",{d:"M15.5 19H14v1.5a1.5 1.5 0 1 0 1.5-1.5",key:"jc4sz0"}],["rect",{width:"8",height:"3",x:"2",y:"8",rx:"1.5",key:"1omvl4"}],["path",{d:"M8.5 5H10V3.5A1.5 1.5 0 1 0 8.5 5",key:"16f3cl"}]],cs=Ce("slack",jr);const wr=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Nr=Ce("tag",wr),Sr=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Rs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Is,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:cs,keywords:["slack","slack app","admin","message","direct messages","mentions"]},{id:"soul",label:"Soul",labelKey:"botSettings.sections.soul",icon:Ve,keywords:["standing instructions","instructions","persona","rules","soul.md"]},{id:"skills",label:"Skills",labelKey:"botSettings.sections.skills",icon:As,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:Bt,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:kr,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Ls,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Ms,keywords:["works on","computer","vm","cloud","vps","folder","workspace","browser","connected apps","composio","webhooks","always allow","grants","tool selection","tools","mcp","allow","exclude"]},{id:"model",label:"Model",labelKey:"botSettings.sections.model",icon:Ts,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:Dt,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:Bs,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:Ft,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:Ds,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:Dn,keywords:["tokens","cost","billing"]}],yt={completed:"botOverview.routine.last.completed",failed:"botOverview.routine.last.failed",missed:"botOverview.routine.last.missed",cancelled:"botOverview.routine.last.cancelled",running:"botOverview.routine.last.running",queued:"botOverview.routine.last.queued",waiting:"botOverview.routine.last.waiting"};function Cr(t,a=ee()){if(!t||a==="en")return null;if(t.paused)return s("botOverview.routine.paused",{name:t.name});const n=t.lastRun;if(n&&!Object.hasOwn(yt,n.status))return null;try{return[s("botOverview.routine.line",{schedule:Fs(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:st(t.nextRunAt)})]:[],...n?[s(yt[n.status],{time:st(n.at)})]:[]].join(" ")}catch{return null}}const vt={"Works in its private workspace.":"botOverview.line.privateWorkspace","Has the built-in browser.":"botOverview.line.browser","Has no connected apps.":"botOverview.line.noApps","Won't act on a schedule.":"botOverview.line.noSchedule","Can talk to the other bot.":"botOverview.line.talksToOne","Talks only to the bots chosen for it.":"botOverview.line.talksToChosen","Cannot initiate contact with other bots.":"botOverview.line.noPeerContact","Command approvals use Ask mode; saved permissions and provider rules still apply.":"botOverview.line.askMode","Command approvals follow the provider's custom configuration.":"botOverview.line.customApprovals","Asks before contacting other bots.":"botOverview.line.asksPeers","Can't use a computer.":"botOverview.line.noComputer","Profile proposal cards require your approval.":"botOverview.line.profileApproval","Connected apps could not be checked.":"botOverview.line.appsUnchecked"},bt={"Auto; availability is checked when a task starts":"botOverview.preference.auto","cloud computer":"botOverview.preference.cloud","Local VM":"botOverview.preference.vm","this computer":"botOverview.preference.local","browser only":"botOverview.preference.browser"};function kt(t,a){return!a||a.map(n=>n||"General").join(", ")!==t?t:a.map(n=>n||s("botAccess.teams.general")).join(", ")}const jt=t=>Object.hasOwn(bt,t)?s(bt[t]):t,wt=(t,a,n)=>Number(t)===1?a:n,Pr=[{line:/^Can talk to all (\d+) other bots, in any department\.$/,key:()=>"botOverview.line.talksToAll",params:([,t])=>({count:Number(t)})},{line:/^Also in charge of these departments: (.+)\.$/,key:()=>"botOverview.line.alsoInCharge",params:([,t],a)=>({departments:kt(t,a)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>wt(t,"botOverview.line.peersSectionOne","botOverview.line.peersSectionMany"),params:([,t])=>({count:Number(t)})},{line:/^Can talk to (\d+) other bots? in its allowed (?:teams|departments)\.$/,key:([,t])=>wt(t,"botOverview.line.peersTeamsOne","botOverview.line.peersTeamsMany"),params:([,t])=>({count:Number(t)})},{line:/^Coordinates its (?:section|department) as Chief of Staff\.$/,key:()=>"botOverview.line.chief",params:()=>({role:s("sidebar.bot.chiefOfStaff")})},{line:/^May also coordinate these (?:teams|departments): (.+)\.$/,key:()=>"botOverview.line.alsoTeams",params:([,t],a)=>({teams:kt(t,a)})}],Or=t=>ee()!=="en"&&Object.hasOwn(Os[ee()]??{},t);function Er(t,a){for(const n of Pr){const l=n.line.exec(t);if(!l)continue;const r=n.key(l);return Or(r)?s(r,n.params(l,a)):t}return null}function De(t,a){if(Object.hasOwn(vt,t))return s(vt[t]);const n=Er(t,a);if(n!==null)return n;const l=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(l)return s(l[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(l[1]),apps:l[2]});const r=ee()==="en"?null:/^Computer preference: (.+), which isn't available on My Cloud\.$/.exec(t);if(r)return s("botOverview.line.computerNotOnCloud",{preference:jt(r[1])});const i=/^Computer preference: (.+)\.$/.exec(t);if(i)return s("botOverview.line.computer",{preference:jt(i[1])});const c=/^Works in (.+)\.$/.exec(t);if(c)return s("botOverview.line.folder",{folder:c[1]});const d=/^Knows how to (.+)\.$/.exec(t);if(d)return s("botOverview.line.skill",{skill:d[1]});const o=/^Listens for “(.+)” webhooks\.$/.exec(t);return o?s("botOverview.line.webhook",{name:o[1]}):t}const Nt={name:"approval.applied.field.name",title:"approval.applied.field.title",description:"approval.applied.field.description",soul:"approval.applied.field.soul",cwd:"approval.applied.field.cwd",notifications:"approval.applied.field.notifications",speakReplies:"approval.applied.field.speakReplies"};function Rr(t,a=ee()){const n=/^(\w+): /.exec(t)?.[1];return a==="en"||!n||!Object.hasOwn(Nt,n)?t:`${s(Nt[n])}: ${t.slice(n.length+2)}`}function Ir({data:t,error:a,open:n,onToggle:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:l,"aria-expanded":n,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("span",{className:"text-[15px] font-medium text-ink",children:t?s("botOverview.promptPreviewCount",{bytes:t.totalBytes.toLocaleString(Ae()),tokens:t.approxTokens.toLocaleString(Ae())}):s("botOverview.promptPreview")}),e.jsx(pe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",n&&"rotate-180")})]}),n&&!t&&a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.promptError")}),n&&!t&&!a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.loading")}),n&&t&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[t.sections.map(r=>e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center justify-between gap-3 text-[13px] text-ink",children:[e.jsx("span",{children:r.label}),e.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:s("botOverview.bytes",{count:r.bytes.toLocaleString(Ae())})})]}),e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-ink",children:r.text})]},r.id)),t.note&&e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t.note})]})]})}function Ar({overview:t,refreshError:a,prompt:n,promptError:l,onOpen:r,onSetup:i}){const[c,d]=x.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const u=(t.setup??[]).filter(h=>!h.done),p=(h,k)=>s(`botOverview.setup.${h}`)||k;return e.jsxs("div",{className:"flex flex-col gap-4",children:[a&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("botOverview.refreshError")}),u.length>0&&e.jsxs("div",{className:"rounded-xl border border-accent/30 bg-accent/[0.06] p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botSetup.ideas")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:s("botSetup.optional")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:u.map(h=>e.jsx("li",{children:h.section?e.jsxs("button",{type:"button",onClick:()=>r(h.section),className:"flex w-full items-center gap-2.5 rounded-lg px-1 py-1 text-left text-[13px] text-ink hover:bg-inset",children:[e.jsx(at,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:p(h.id,h.label)}),e.jsx(he,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-secondary rtl:-scale-x-100"})]}):e.jsxs("div",{className:"flex items-center gap-2.5 px-1 py-1 text-[13px] text-ink",children:[e.jsx(at,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:p(h.id,h.label)})]})},h.id))}),i&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:i,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(Ve,{size:14})," ",s("botSetup.withBot")]}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:s("botSetup.help")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t.who.name}),t.who.title&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t.who.title}),t.who.blurb&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink",children:t.who.blurb}),t.who.soulLead&&e.jsxs("div",{className:"mt-3 rounded-lg bg-inset px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t.who.soulLead}),e.jsx("button",{type:"button",onClick:()=>r("soul"),className:"mt-1.5 rounded-md text-[12px] font-medium text-accent-text hover:underline",children:s("botOverview.readAll")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.does")}),t.does.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.doesEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.does.map((h,k)=>e.jsx("li",{children:Cr(t.doesRoutines?.[k])??De(h)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.canReach")}),t.reaches.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.reachEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.reaches.map((h,k)=>e.jsx("li",{children:De(h,t.managedSections)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.wont")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.wont.map((h,k)=>e.jsx("li",{children:De(h,t.managedSections)},k))})]}),e.jsx(Ir,{data:n,error:l,open:c,onToggle:()=>d(h=>!h)}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.recentChanges")}),e.jsxs("button",{type:"button",onClick:()=>r("history"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink",children:[s("botOverview.viewAll")," ",e.jsx(he,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),t.recent.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.recentEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-ink",children:t.recent.map((h,k)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Rr(h.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",$t(h.at)]})]},k))})]})]})}function Lr({managementUrl:t}){return e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:s("botSlack.body")}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[s("botSlack.manage")," ",e.jsx(Qt,{size:14,"aria-hidden":"true"})]})]})}function Mr(t){if(!t||typeof t!="object")return null;const{available:a,managementUrl:n}=t;if(a!==!0||typeof n!="string")return null;try{return new URL(n).protocol==="https:"?n:null}catch{return null}}function ds(t){const[a,n]=x.useState(null);return x.useEffect(()=>{const l=new AbortController;return se(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:l.signal,timeoutMs:1e4}).then(r=>{l.signal.aborted||n({botId:t,url:Mr(r)})}).catch(()=>{l.signal.aborted||n({botId:t,url:null})}),()=>l.abort()},[t]),a?.botId===t?a.url:null}const ne="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",Fe="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",ae=t=>t instanceof Error?t.message:String(t);function us(t){const a=[],n=(r,i,c)=>{r&&a.push(s(r===1?i:c,{count:r}))};n(t.expired,"memory.upkeep.summary.archived.one","memory.upkeep.summary.archived.many"),n(t.duplicates,"memory.upkeep.summary.merged.one","memory.upkeep.summary.merged.many"),n(t.superseded,"memory.upkeep.summary.crossed.one","memory.upkeep.summary.crossed.many"),n(t.organized,"memory.upkeep.summary.filed.one","memory.upkeep.summary.filed.many");const l=a.length?a.join(", "):s("memory.upkeep.summary.none");return l.charAt(0).toUpperCase()+l.slice(1)}function Tr(t,a){const n=t.via==="team-setup"?s("memory.journal.actor.teamSetup"):t.actor==="bot"?a:t.actor==="import"?s("memory.journal.actor.import"):t.actor==="upkeep"?s("memory.journal.actor.upkeep"):s("memory.journal.actor.you"),l=Kn(t.path),r=t.path===Z?l:t.path===qn?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:l}):s("memory.journal.topic",{file:l}),i=c=>s(c===1?"memory.journal.line.one":"memory.journal.line.many",{count:c});return t.kind==="created"?s("memory.journal.created",{who:n,topic:r,detail:t.added?s("memory.journal.withLines",{lines:i(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:n,topic:r}):t.added&&!t.removed?s("memory.journal.added",{who:n,lines:i(t.added),topic:r}):t.removed&&!t.added?s("memory.journal.removed",{who:n,lines:i(t.removed),topic:r}):s("memory.journal.rewrote",{who:n,lines:i(Math.max(t.added,t.removed)),topic:r})}function ms({changed:t,stale:a,busy:n,onReviewed:l}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(a?"memory.lendingReviewStale":"memory.lendingReview")}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.lendingReviewChanged")}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.map(r=>e.jsx("li",{className:"break-all font-mono text-[12px] text-ink",children:r},r))})]}),e.jsx("button",{type:"button",className:O(ne,"mt-3"),disabled:n,onClick:l,children:s("memory.lendingReviewed")})]})}function Br({bot:t,active:a=!0,onToggle:n}){const{capabilities:l}=ge(),[r,i]=x.useState(null),[c,d]=x.useState(null),[o,u]=x.useState(null),[p,h]=x.useState(null),[k,f]=x.useState(null),[b,y]=x.useState(null),[C,v]=x.useState(null),[w,N]=x.useState(!1),[E,M]=x.useState(null),[F,T]=x.useState(""),[I,z]=x.useState(null),[A,m]=x.useState(!1),[R,D]=x.useState(null),[H,_]=x.useState(!1),[G,Y]=x.useState(!1),{state:U,dispatch:g}=B(),$=$s(U.config),[ie,de]=x.useState(!1),[xe,S]=x.useState(""),K=async j=>{const[P,Re,Ps]=await Promise.all([Qe(t.id),me(t.id),xt(t.id).catch(()=>null)]);if(i(P),D(P.lendingReview??null),d(Re),z(Ps),j){const Ie=await Ne(t.id,j);u({path:Ie.path,text:Ie.text,hash:Ie.hash,dirty:!1,readOnly:j.startsWith("memory/log/")})}};x.useEffect(()=>{if(!a)return;let j=!1;y(null);const P=o?.dirty===!0;return K(P?void 0:o?.path??Z).catch(Re=>{j||y(ae(Re))}),()=>{j=!0}},[a,t.id]);const V=async j=>{y(null),h(null);try{const P=await Ne(t.id,j);u({path:P.path,text:P.text,hash:P.hash,dirty:!1,readOnly:j.startsWith("memory/log/")})}catch(P){y(ae(P))}},q=async j=>{if(o){N(!0),y(null);try{const P=await Xe(t.id,o.path,o.text,j);if(!P.ok){h({path:o.path,current:P.current,currentHash:P.currentHash});return}h(null),f(null),u({...o,text:P.doc.text,hash:P.doc.hash,dirty:!1}),i(P.overview),d(await me(t.id))}catch(P){y(ae(P))}finally{N(!1)}}},le=()=>{!p||!o||(f(o.text),u({...o,text:p.current,hash:p.currentHash,dirty:!1}),h(null))},ye=async j=>{if(window.confirm(s("memory.confirmDelete",{name:j.name}))){y(null);try{const{overview:P}=await ts(t.id,j.path);i(P),d(await me(t.id)),o?.path===j.path&&u(null)}catch(P){y(ae(P))}}},et=async()=>{const j=Hn(F);if(!j){y(s("memory.topicNameError"));return}T(""),await V(`memory/${j}`),u(P=>P&&{...P,dirty:!0,text:P.text||Dr(j)})},js=async j=>{M(j.id),y(null);try{const P=await ss(t.id,j.id);i(P.overview),d(await me(t.id)),o?.path===j.path&&!o.dirty&&u({...o,text:P.text,hash:P.hash}),v(s("memory.restored",{path:j.path}))}catch(P){y(ae(P))}finally{M(null)}},tt=async j=>{y(null),v(null);try{await $n(t.id,j)}catch(P){y(ae(P))}},ws=()=>{const j=t.memoryUpkeep===!1;g({type:"updateBot",botId:t.id,patch:{memoryUpkeep:j}}),z(P=>P&&{...P,enabled:j})},Ns=async()=>{if(!ie){de(!0),S("");try{const j=await se("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!$}})});g({type:"configStatus",config:j})}catch(j){S(j instanceof Error?j.message:s("memory.learnFromRooms.error"))}finally{de(!1)}}},Ss=async()=>{m(!0),y(null),v(null);try{const{report:j,overview:P}=await es(t.id);i(P),d(await me(t.id)),z(await xt(t.id)),o&&!o.dirty&&await V(o.path),v(`${us(j)}.${j.note?` ${j.note}`:""}`)}catch(j){y(ae(j))}finally{m(!1)}},Cs=l.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange:j=>n(j.target.checked)}),s("memory.enable")]}),e.jsxs("p",{className:"mt-1 text-[13px] text-ink-secondary",children:[s("memory.enableHelp"),t.busy?` ${s("memory.busyHelp")}`:""]}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.notesHelp")}),r&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink-secondary",title:r.workspacePath,children:Ye(r.workspacePath,Cs)}),e.jsx("button",{type:"button",className:ne,onClick:()=>{tt("obsidian")},children:s("memory.openObsidian")}),e.jsxs("button",{type:"button",className:O(ne,"inline-flex items-center gap-1.5"),onClick:()=>{tt("folder")},children:[e.jsx(zt,{size:14}),s("memory.showFileManager")]})]})]}),R&&e.jsx(ms,{changed:R.changed,stale:H,busy:G,onReviewed:()=>{Y(!0),Zt(t.id,R.token).then(()=>{D(null),_(!1)}).catch(j=>{if(j instanceof Ht&&j.status===409)return _(!0),K();y(ae(j))}).finally(()=>Y(!1))}}),r&&e.jsx($r,{index:r.index}),t.memoryEnabled!==!1&&e.jsx(Fr,{enabled:t.memoryUpkeep!==!1,status:I,tidying:A,onToggle:ws,onTidy:()=>{Ss()},rooms:{enabled:$,saving:ie,error:xe,onToggle:()=>{Ns()}}}),o&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:o.path}),o.path!==Z&&e.jsx("button",{type:"button",className:Fe,onClick:()=>{V(Z)},children:s("memory.backToIndex")})]}),p&&e.jsx(ps,{botName:t.name,busy:w,onReload:le,onOverwrite:()=>{q(p.currentHash)}}),e.jsx("textarea",{className:O(We,"mt-2 min-h-[200px] resize-y font-mono text-[13px] leading-relaxed"),value:o.text,readOnly:o.readOnly,placeholder:o.path===Z?s("memory.indexPlaceholder"):s("memory.notePlaceholder"),"aria-label":o.path===Z?s("memory.botMemory"):s("memory.fileLabel",{path:o.path}),onChange:j=>u({...o,text:j.target.value,dirty:!0})}),o.readOnly?e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.logsReadOnly")}):e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{q(o.hash)},disabled:w||!o.dirty,className:ne,children:w?s("memory.saving"):s("memory.save")}),o.dirty&&e.jsx("button",{type:"button",className:Fe,disabled:w,onClick:()=>{V(o.path)},children:s("memory.discard")})]}),k!==null&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:k}),e.jsx("button",{type:"button",className:O(Fe,"mt-1"),onClick:()=>f(null),children:s("memory.dismissDraft")})]})]}),r&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx(Ct,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:r.topics,selected:o?.path,onOpen:j=>{V(j.path)},onDelete:j=>{ye(j)}}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{className:O(We,"py-1.5 text-[13px]"),value:F,placeholder:s("memory.newTopicPlaceholder"),"aria-label":s("memory.newTopicLabel"),onChange:j=>T(j.target.value),onKeyDown:j=>{j.key==="Enter"&&et()}}),e.jsx("button",{type:"button",className:ne,disabled:!F.trim(),onClick:()=>{et()},children:s("memory.newTopic")})]}),r.logs.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Ct,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:r.logs,selected:o?.path,onOpen:j=>{V(j.path)},onDelete:j=>{ye(j)}})})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.changes")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.changesHelp")}),e.jsx("div",{className:"mt-3",children:e.jsx(Ze,{rows:c,botName:t.name,reverting:E,onRevert:j=>{js(j)}})})]}),C&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:C}),b&&e.jsx("div",{className:"text-[13px] text-danger",children:b})]})}function Dr(t){return`---
|
|
2
2
|
title: ${t.replace(/\.md$/,"")}
|
|
3
3
|
description:
|
|
4
4
|
aliases: []
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{c as Tt,r as a,j as n,t as s,X as Ue,f as Mt,o as Kt,ay as Vt,aq as qt}from"./styles-B9Nw0uqu.js";import{G as lt,U as Rt,c_ as Gt,bD as Xt,de as Yt,cD as Jt,e6 as Zt,e7 as Qt,df as en,R as tn,u as dt,e8 as nn,n as Ge,e9 as It,M as rn,bK as sn}from"./App-DToXVaV2.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-C-R1apBf.js";import{P as At,L as Xe,Y as ln,J as ht,W as cn}from"./PlacesRail-BuGh6RP-.js";import{M as un,a as dn}from"./minimize-BGJr9i4X.js";import{F as fn}from"./file-up-B3qv0JW8.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(Gt,{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(Xt,{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(Yt,{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(Jt,{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(Zt,{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(Qt,{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(en,{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(tn,{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(nn,{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:()=>{Kt(Vt)},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:F,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 F=="number"&&typeof le=="number")v=0,t.onViewport({width:F,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 Fn(e,t){return e?1:t==="human"?.18:.35}function Hn({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:Fn(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:F=>F.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(""),[F,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),H=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=H.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=H.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(H.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:qt(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=H.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;H.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=H.current;if(f.panning){H.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:H.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})},Fe=(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())},He=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=F;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(Hn,{...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=>Fe("down",l),onKeyUp:l=>Fe("up",l),onInput:He,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,F&&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(F.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:F.multiple,accept:F.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(F.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()),F=()=>{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()),F())}).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++,F(),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&&F()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||F())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,F()}},hold(x){u||w===x||(w=x,x||F())},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,Ft=()=>{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(),Ft()}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,Ft();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",Ht=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ht(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(Ht)),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 F=(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:(F(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 H=0;H<A.length;H++)G[H]=A.charCodeAt(H);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const H=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(H.width!==C?.width||H.height!==C.height)&&(C=H,t.onViewport(H))}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{}F(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&F(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,F]=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),[H,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),Fe=a.useRef(0),He=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,o as Kt,ay as Vt,aq as qt}from"./styles-b2tBrp-F.js";import{G as lt,U as Rt,c_ as Gt,bD as Xt,de as Yt,cD as Jt,e6 as Zt,e7 as Qt,df as en,R as tn,u as dt,e8 as nn,n as Ge,e9 as It,M as rn,bK as sn}from"./App-D93hKk8l.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-BRZM0q_M.js";import{P as At,L as Xe,Y as ln,J as ht,W as cn}from"./PlacesRail-eySktVNq.js";import{M as un,a as dn}from"./minimize-BzhEcU2C.js";import{F as fn}from"./file-up-Dg7JsLFP.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(Gt,{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(Xt,{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(Yt,{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(Jt,{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(Zt,{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(Qt,{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(en,{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(tn,{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(nn,{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:()=>{Kt(Vt)},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:F,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 F=="number"&&typeof le=="number")v=0,t.onViewport({width:F,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 Fn(e,t){return e?1:t==="human"?.18:.35}function Hn({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:Fn(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:F=>F.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(""),[F,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),H=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=H.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=H.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(H.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:qt(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=H.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;H.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=H.current;if(f.panning){H.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:H.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})},Fe=(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())},He=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=F;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(Hn,{...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=>Fe("down",l),onKeyUp:l=>Fe("up",l),onInput:He,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,F&&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(F.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:F.multiple,accept:F.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(F.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()),F=()=>{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()),F())}).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++,F(),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&&F()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||F())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,F()}},hold(x){u||w===x||(w=x,x||F())},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,Ft=()=>{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(),Ft()}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,Ft();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",Ht=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ht(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(Ht)),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 F=(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:(F(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 H=0;H<A.length;H++)G[H]=A.charCodeAt(H);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const H=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(H.width!==C?.width||H.height!==C.height)&&(C=H,t.onViewport(H))}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{}F(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&F(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,F]=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),[H,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),Fe=a.useRef(0),He=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"&&F(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=He.current;!h||xe.current===null||(He.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,He.current=t.url,me.current.takeControl(),me.current.openSignInPage())},[t,m]),a.useEffect(()=>{if(!(!r||!m||Fe.current===r.nonce)){if(W){W==="asleep"&&de.current?.send({type:"wake"})&&te("waking");return}Fe.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&&H&&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(!H)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)},[H,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:H?"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:H,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 Fr({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{Fr as B,xn as u};
|