limixbot 0.3.18 → 0.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/assets/{ActivityPanel-CiVMRvA-.js → ActivityPanel-D0V5shGd.js} +1 -1
  2. package/dist/assets/{App-B612vSUv.js → App-DXv-5ZTc.js} +8 -8
  3. package/dist/assets/{AppEventEditor-Id4kTgLa.js → AppEventEditor-mJOa46It.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-DdTKCtEA.js → BotSettingsDialog-DOF82zFt.js} +1 -1
  5. package/dist/assets/{BrowserPanel-thqBHOQl.js → BrowserPanel-Cbp7LssC.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-J8hqmwv5.js → BrowserProfilesManager-LC4INRs7.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-BNroQCqt.js → CloudAddDialog-DywJ4txo.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-BXUVfqmc.js → ComputerFilesPane-BjzS9ZTa.js} +1 -1
  9. package/dist/assets/{ComputerPanel-BGE1fw6l.js → ComputerPanel-DGPKl9mx.js} +2 -2
  10. package/dist/assets/{DataPanel-CQWnhToC.js → DataPanel-CowhAHcc.js} +1 -1
  11. package/dist/assets/{FilesView-CYEcHPlb.js → FilesView-Di6bZ56Z.js} +1 -1
  12. package/dist/assets/{GrokMoveDialog-GD3YuWYi.js → GrokMoveDialog-BXwNEoZf.js} +1 -1
  13. package/dist/assets/{InspectorPanel-B_-Xse3K.js → InspectorPanel-gvViZQrp.js} +1 -1
  14. package/dist/assets/{KeyboardShortcutsModal-BAsXL39B.js → KeyboardShortcutsModal-C6gDEGpK.js} +1 -1
  15. package/dist/assets/{LiveDesktop-CLu-oUdB.js → LiveDesktop-BklBBcgn.js} +1 -1
  16. package/dist/assets/{LocalVmWorkspace-CrRurzrY.js → LocalVmWorkspace-D1xWHo1G.js} +1 -1
  17. package/dist/assets/{MacLocalControl-Jp0LjT_C.js → MacLocalControl-BfwVFZRa.js} +1 -1
  18. package/dist/assets/{MarkdownFilePreview-ceD2tKz1.js → MarkdownFilePreview-Cy-DECsV.js} +1 -1
  19. package/dist/assets/{NewBotDialog-C_M8t6Ri.js → NewBotDialog-CRCIYvfv.js} +1 -1
  20. package/dist/assets/{PhoneAppDialog-VezYkaXY.js → PhoneAppDialog-CmcHLaYr.js} +1 -1
  21. package/dist/assets/{PluginsPanel-Bcsv8kad.js → PluginsPanel-C46LU5EJ.js} +1 -1
  22. package/dist/assets/{ProIntroduction-BeqDgqS2.js → ProIntroduction-DuPsMUld.js} +1 -1
  23. package/dist/assets/{RemoteAgentSettingsPanel-Gc-vYBxb.js → RemoteAgentSettingsPanel-BauS0Y0t.js} +1 -1
  24. package/dist/assets/{RoomPanel-DBJbvMf1.js → RoomPanel-BiaRLuVx.js} +1 -1
  25. package/dist/assets/{RoutinesPage-C8O6H_m9.js → RoutinesPage-BeldL46G.js} +1 -1
  26. package/dist/assets/{SettingsModal-C28PTR8i.js → SettingsModal-DBLLYSR2.js} +1 -1
  27. package/dist/assets/{ShareTeamDialog-CSfZehTH.js → ShareTeamDialog-uEP_ILfa.js} +1 -1
  28. package/dist/assets/{SignedInSites-BaywJMFM.js → SignedInSites-BgqjFXnz.js} +1 -1
  29. package/dist/assets/{TeamLibraryPanel-DNEOuAa6.js → TeamLibraryPanel-Bd7HFgTR.js} +1 -1
  30. package/dist/assets/{TeamMapPage-CRIOLuDD.js → TeamMapPage-DslnWFG2.js} +1 -1
  31. package/dist/assets/{TriggersPage-D_HBWqEe.js → TriggersPage-BK73CwJR.js} +1 -1
  32. package/dist/assets/{VisibilitySection-C_Lg0Sxb.js → VisibilitySection-CZVuYCfP.js} +1 -1
  33. package/dist/assets/{WebhookTrigger-Cpp-PlPP.js → WebhookTrigger-DXr8EYFe.js} +1 -1
  34. package/dist/assets/{WorksOnGrid-DxsV4-UT.js → WorksOnGrid-DJJIaPGa.js} +1 -1
  35. package/dist/assets/{core-DUBJa6se.js → core-DIFUUeI5.js} +1 -1
  36. package/dist/assets/{import-name-w5H0_aIa.js → import-name-CFjzsLGq.js} +1 -1
  37. package/dist/assets/{index-CJ71uySw.js → index-BBObcTo5.js} +2 -2
  38. package/dist/assets/{index-B6hNR0We.js → index-D2Hr2dxf.js} +1 -1
  39. package/dist/assets/{mcp-servers-DT3QTM7h.js → mcp-servers-5_CMZE0a.js} +1 -1
  40. package/dist/assets/{new-bot-Wr7msRe_.js → new-bot-BNUINkXW.js} +1 -1
  41. package/dist/assets/{org-library-BTDDXkLR.js → org-library-D71rjidw.js} +1 -1
  42. package/dist/assets/{package-format-ByePhvES.js → package-format-Bc1BWLbR.js} +1 -1
  43. package/dist/assets/{remote-desktop-panel-CMGlHR7t.js → remote-desktop-panel-CG1BY1IR.js} +1 -1
  44. package/dist/index.html +1 -1
  45. package/dist-server/index.js +675 -673
  46. package/dist-server/openmausbot.js +240 -236
  47. package/dist-server/package.json +1 -1
  48. package/dist-server/pair-cli.js +240 -236
  49. package/dist-server/server/drivers/antigravity.js +11 -0
  50. package/dist-server/server/limix-agy-cli.js +65 -0
  51. package/package.json +1 -1
@@ -1 +1 @@
1
- import{r as l,t as s,j as t,X as $,a as X}from"./styles-BHtUK2qB.js";import{c as ee,B as te,L as G}from"./PlacesRail-CUntVv3u.js";import{u as ae,z as F,D as L}from"./App-B612vSUv.js";import{suggestedName as H}from"./WebhookTrigger-Cpp-PlPP.js";import"./monitor-7oLB-7rZ.js";import"./index-CJ71uySw.js";import"./MenuMotion-CobYpP7L.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
+ import{r as l,t as s,j as t,X as $,a as X}from"./styles-BHtUK2qB.js";import{c as ee,B as te,L as G}from"./PlacesRail-CUntVv3u.js";import{u as ae,z as F,D as L}from"./App-DXv-5ZTc.js";import{suggestedName as H}from"./WebhookTrigger-DXr8EYFe.js";import"./monitor-7oLB-7rZ.js";import"./index-BBObcTo5.js";import"./MenuMotion-CobYpP7L.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,av as Is,j as e,i as Ae,a9 as xe,a as O,r as x,S as Bt,ac as Dt,X as Ft}from"./styles-BHtUK2qB.js";import{fg as As,fh as Ls,a2 as Ve,by as Ms,di as $t,w as Ts,fi as Bs,fj as Ds,K as zt,fk as Fs,R as Ht,eu as $s,x as zs,fl as st,bt as at,fm as _t,n as se,u as B,fn as Hs,ah as Ye,F as Ut,A as Kt,S as nt,ad as Pe,T as qt,W as _s,fo as Us,fp as Ks,fq as qs,fr as Ws,fs as Vs,ft as rt,fu as Ys,fv as Gs,fw as Js,fx as Qs,b9 as Xs,fy as Zs,fz as ea,fA as ta,I as sa,fB as je,bP as Ge,fC as aa,aI as L,aO as X,ed as na,dK as ra,fD as ia,aJ as He,cp as la,dZ as oa,d_ as ca,fE as da,fF as Wt,fG as Vt,fH as ua,fI as ma,fJ as pa,fK as xa,dN as _e,ar as it,fL as Le,fM as ha,fN as we,av as fa,fO as Yt,fP as lt,ak as Ue,fQ as ga,fR as ya,fS as va,fT as Gt,fU as ba,fV as ka,fW as ja,fX as wa,fY as Q,aX as te,aZ as J,fZ as Na,f_ as Sa,f$ as Ca,d5 as Pa,d as Oa,G as Ea,d3 as Jt,aj as Ra,g0 as W,aW as ce,g1 as de,g2 as Ia,dp as Aa,g3 as Oe,aY as re,g4 as La,g5 as Ma,g6 as Ta,eh as Ba,g7 as ot,g8 as Da,g9 as Fa,ga as $a,gb as za,gc as Ha,gd as _a,aC as Ua,ge as Qt,gf as Ka,gg as qa,gh as Wa,gi as Va,gj as Ya,gk as Ga,gl as Ja,gm as Qa,gn as Xa,go as Za,gp as en,gq as tn,gr as Je,k as sn,B as Ke,gs as an,gt as nn,gu as rn,gv as ln,bY as on,gw as Xt,J as ct,eY as cn,gx as dt,gy as dn,gz as un,cM as ut,bw as mn,d2 as pn,gA as xn,gB as Zt,gC as be,gD as mt,gE as hn,aM as Me,d$ as fn,gF as gn,aR as yn,C as vn,cq as bn,gG as kn,gH as jn,gI as wn,aT as Nn}from"./App-B612vSUv.js";import{z as es,d as ye,a1 as Ne,a2 as Sn,a3 as Cn,a4 as pt,a5 as Te,a6 as Pn,a7 as On,a8 as En,a9 as Rn,aa as In,ab as xt,ac as An,ad as Ln,L as Mn,N as Tn,B as qe,P as Ee,r as Bn,ae as Dn,a0 as Fn,u as ts}from"./PlacesRail-CUntVv3u.js";import{C as $n}from"./coins-D1fhjgas.js";import{C as ge,a as zn}from"./MenuMotion-CobYpP7L.js";import{b as Z,m as ss,i as We,f as Qe,c as pe,d as ht,e as Se,o as Hn,g as _n,h as oe,n as Be,t as as,s as Xe,j as ns,k as Un,l as Kn,p as qn,r as rs,q as Wn,u as Vn,w as Yn,x as is,y as ls,z as ft,B as Gn,C as os,R as gt,D as Jn,E as Qn,F as Xn,G as Zn,H as er,J as tr,O as sr,K as ar,L as cs,N as yt,V as nr,P as rr,M as ir,A as lr,a as or,S as cr,I as dr}from"./VisibilitySection-C_Lg0Sxb.js";import{s as ur,r as mr,a as pr,R as xr}from"./ComputerFilesPane-BXUVfqmc.js";import{M as vt}from"./monitor-7oLB-7rZ.js";import{a as ds,m as us,b as hr,c as fr}from"./mcp-servers-DT3QTM7h.js";import{R as gr}from"./RoutinesPage-C8O6H_m9.js";import{S as yr}from"./SignedInSites-BaywJMFM.js";import"./index-CJ71uySw.js";import"./org-library-BTDDXkLR.js";import"./package-format-ByePhvES.js";import"./WorksOnGrid-DxsV4-UT.js";import"./ProIntroduction-BeqDgqS2.js";import"./remote-desktop-DDRRx8uY.js";const vr=[["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"}]],br=Ce("calendar-plus",vr);const kr=[["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"}]],jr=Ce("library",kr);const wr=[["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"}]],ms=Ce("slack",wr);const Nr=[["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"}]],Sr=Ce("tag",Nr),Cr=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:As,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Ls,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:ms,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:Ms,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:$t,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:jr,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Ts,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Bs,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:Ds,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:zt,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:Fs,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:Ht,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:$s,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:$n,keywords:["tokens","cost","billing"]}],bt={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 Pr(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(bt,n.status))return null;try{return[s("botOverview.routine.line",{schedule:zs(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:st(t.nextRunAt)})]:[],...n?[s(bt[n.status],{time:st(n.at)})]:[]].join(" ")}catch{return null}}const kt={"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"},jt={"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 wt(t,a){return!a||a.map(n=>n||"General").join(", ")!==t?t:a.map(n=>n||s("botAccess.teams.general")).join(", ")}const Nt=t=>Object.hasOwn(jt,t)?s(jt[t]):t,St=(t,a,n)=>Number(t)===1?a:n,Or=[{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:wt(t,a)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>St(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])=>St(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:wt(t,a)})}],Er=t=>ee()!=="en"&&Object.hasOwn(Is[ee()]??{},t);function Rr(t,a){for(const n of Or){const l=n.line.exec(t);if(!l)continue;const r=n.key(l);return Er(r)?s(r,n.params(l,a)):t}return null}function De(t,a){if(Object.hasOwn(kt,t))return s(kt[t]);const n=Rr(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:Nt(r[1])});const i=/^Computer preference: (.+)\.$/.exec(t);if(i)return s("botOverview.line.computer",{preference:Nt(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 Ct={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 Ir(t,a=ee()){const n=/^(\w+): /.exec(t)?.[1];return a==="en"||!n||!Object.hasOwn(Ct,n)?t:`${s(Ct[n])}: ${t.slice(n.length+2)}`}function Ar({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(xe,{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 Lr({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),m=(h,b)=>s(`botOverview.setup.${h}`)||b;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:m(h.id,h.label)}),e.jsx(ge,{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:m(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,b)=>e.jsx("li",{children:Pr(t.doesRoutines?.[b])??De(h)},b))})]}),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,b)=>e.jsx("li",{children:De(h,t.managedSections)},b))})]}),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,b)=>e.jsx("li",{children:De(h,t.managedSections)},b))})]}),e.jsx(Ar,{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(ge,{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,b)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Ir(h.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",_t(h.at)]})]},b))})]})]})}function Mr({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(es,{size:14,"aria-hidden":"true"})]})]})}function Tr(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 ps(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:Tr(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 xs(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 Br(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=Wn(t.path),r=t.path===Z?l:t.path===Vn?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 hs({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 Dr({bot:t,active:a=!0,onToggle:n}){const{capabilities:l}=ye(),[r,i]=x.useState(null),[c,d]=x.useState(null),[o,u]=x.useState(null),[m,h]=x.useState(null),[b,f]=x.useState(null),[v,j]=x.useState(null),[k,y]=x.useState(null),[N,S]=x.useState(!1),[E,M]=x.useState(null),[F,T]=x.useState(""),[I,z]=x.useState(null),[A,p]=x.useState(!1),[R,D]=x.useState(null),[H,_]=x.useState(!1),[G,Y]=x.useState(!1),{state:U,dispatch:g}=B(),$=Hs(U.config),[ie,ue]=x.useState(!1),[he,C]=x.useState(""),K=async w=>{const[P,Re,Rs]=await Promise.all([Qe(t.id),pe(t.id),ht(t.id).catch(()=>null)]);if(i(P),D(P.lendingReview??null),d(Re),z(Rs),w){const Ie=await Se(t.id,w);u({path:Ie.path,text:Ie.text,hash:Ie.hash,dirty:!1,readOnly:w.startsWith("memory/log/")})}};x.useEffect(()=>{if(!a)return;let w=!1;j(null);const P=o?.dirty===!0;return K(P?void 0:o?.path??Z).catch(Re=>{w||j(ae(Re))}),()=>{w=!0}},[a,t.id]);const V=async w=>{j(null),h(null);try{const P=await Se(t.id,w);u({path:P.path,text:P.text,hash:P.hash,dirty:!1,readOnly:w.startsWith("memory/log/")})}catch(P){j(ae(P))}},q=async w=>{if(o){S(!0),j(null);try{const P=await Xe(t.id,o.path,o.text,w);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 pe(t.id))}catch(P){j(ae(P))}finally{S(!1)}}},le=()=>{!m||!o||(f(o.text),u({...o,text:m.current,hash:m.currentHash,dirty:!1}),h(null))},ve=async w=>{if(window.confirm(s("memory.confirmDelete",{name:w.name}))){j(null);try{const{overview:P}=await ns(t.id,w.path);i(P),d(await pe(t.id)),o?.path===w.path&&u(null)}catch(P){j(ae(P))}}},et=async()=>{const w=Un(F);if(!w){j(s("memory.topicNameError"));return}T(""),await V(`memory/${w}`),u(P=>P&&{...P,dirty:!0,text:P.text||Fr(w)})},Ss=async w=>{M(w.id),j(null);try{const P=await rs(t.id,w.id);i(P.overview),d(await pe(t.id)),o?.path===w.path&&!o.dirty&&u({...o,text:P.text,hash:P.hash}),y(s("memory.restored",{path:w.path}))}catch(P){j(ae(P))}finally{M(null)}},tt=async w=>{j(null),y(null);try{await Hn(t.id,w)}catch(P){j(ae(P))}},Cs=()=>{const w=t.memoryUpkeep===!1;g({type:"updateBot",botId:t.id,patch:{memoryUpkeep:w}}),z(P=>P&&{...P,enabled:w})},Ps=async()=>{if(!ie){ue(!0),C("");try{const w=await se("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!$}})});g({type:"configStatus",config:w})}catch(w){C(w instanceof Error?w.message:s("memory.learnFromRooms.error"))}finally{ue(!1)}}},Os=async()=>{p(!0),j(null),y(null);try{const{report:w,overview:P}=await as(t.id);i(P),d(await pe(t.id)),z(await ht(t.id)),o&&!o.dirty&&await V(o.path),y(`${xs(w)}.${w.note?` ${w.note}`:""}`)}catch(w){j(ae(w))}finally{p(!1)}},Es=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:w=>n(w.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,Es)}),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(Ut,{size:14}),s("memory.showFileManager")]})]})]}),R&&e.jsx(hs,{changed:R.changed,stale:H,busy:G,onReviewed:()=>{Y(!0),ss(t.id,R.token).then(()=>{D(null),_(!1)}).catch(w=>{if(w instanceof Kt&&w.status===409)return _(!0),K();j(ae(w))}).finally(()=>Y(!1))}}),r&&e.jsx(zr,{index:r.index}),t.memoryEnabled!==!1&&e.jsx($r,{enabled:t.memoryUpkeep!==!1,status:I,tidying:A,onToggle:Cs,onTidy:()=>{Os()},rooms:{enabled:$,saving:ie,error:he,onToggle:()=>{Ps()}}}),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")})]}),m&&e.jsx(fs,{botName:t.name,busy:N,onReload:le,onOverwrite:()=>{q(m.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:w=>u({...o,text:w.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:N||!o.dirty,className:ne,children:N?s("memory.saving"):s("memory.save")}),o.dirty&&e.jsx("button",{type:"button",className:Fe,disabled:N,onClick:()=>{V(o.path)},children:s("memory.discard")})]}),b!==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:b}),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(Ot,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:r.topics,selected:o?.path,onOpen:w=>{V(w.path)},onDelete:w=>{ve(w)}}),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:w=>T(w.target.value),onKeyDown:w=>{w.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(Ot,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:r.logs,selected:o?.path,onOpen:w=>{V(w.path)},onDelete:w=>{ve(w)}})})]}),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:w=>{Ss(w)}})})]}),k&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:k}),v&&e.jsx("div",{className:"text-[13px] text-danger",children:v})]})}function Fr(t){return`---
1
+ import{c as Ce,t as s,b as ee,av as Is,j as e,i as Ae,a9 as xe,a as O,r as x,S as Bt,ac as Dt,X as Ft}from"./styles-BHtUK2qB.js";import{fg as As,fh as Ls,a2 as Ve,by as Ms,di as $t,w as Ts,fi as Bs,fj as Ds,K as zt,fk as Fs,R as Ht,eu as $s,x as zs,fl as st,bt as at,fm as _t,n as se,u as B,fn as Hs,ah as Ye,F as Ut,A as Kt,S as nt,ad as Pe,T as qt,W as _s,fo as Us,fp as Ks,fq as qs,fr as Ws,fs as Vs,ft as rt,fu as Ys,fv as Gs,fw as Js,fx as Qs,b9 as Xs,fy as Zs,fz as ea,fA as ta,I as sa,fB as je,bP as Ge,fC as aa,aI as L,aO as X,ed as na,dK as ra,fD as ia,aJ as He,cp as la,dZ as oa,d_ as ca,fE as da,fF as Wt,fG as Vt,fH as ua,fI as ma,fJ as pa,fK as xa,dN as _e,ar as it,fL as Le,fM as ha,fN as we,av as fa,fO as Yt,fP as lt,ak as Ue,fQ as ga,fR as ya,fS as va,fT as Gt,fU as ba,fV as ka,fW as ja,fX as wa,fY as Q,aX as te,aZ as J,fZ as Na,f_ as Sa,f$ as Ca,d5 as Pa,d as Oa,G as Ea,d3 as Jt,aj as Ra,g0 as W,aW as ce,g1 as de,g2 as Ia,dp as Aa,g3 as Oe,aY as re,g4 as La,g5 as Ma,g6 as Ta,eh as Ba,g7 as ot,g8 as Da,g9 as Fa,ga as $a,gb as za,gc as Ha,gd as _a,aC as Ua,ge as Qt,gf as Ka,gg as qa,gh as Wa,gi as Va,gj as Ya,gk as Ga,gl as Ja,gm as Qa,gn as Xa,go as Za,gp as en,gq as tn,gr as Je,k as sn,B as Ke,gs as an,gt as nn,gu as rn,gv as ln,bY as on,gw as Xt,J as ct,eY as cn,gx as dt,gy as dn,gz as un,cM as ut,bw as mn,d2 as pn,gA as xn,gB as Zt,gC as be,gD as mt,gE as hn,aM as Me,d$ as fn,gF as gn,aR as yn,C as vn,cq as bn,gG as kn,gH as jn,gI as wn,aT as Nn}from"./App-DXv-5ZTc.js";import{z as es,d as ye,a1 as Ne,a2 as Sn,a3 as Cn,a4 as pt,a5 as Te,a6 as Pn,a7 as On,a8 as En,a9 as Rn,aa as In,ab as xt,ac as An,ad as Ln,L as Mn,N as Tn,B as qe,P as Ee,r as Bn,ae as Dn,a0 as Fn,u as ts}from"./PlacesRail-CUntVv3u.js";import{C as $n}from"./coins-D1fhjgas.js";import{C as ge,a as zn}from"./MenuMotion-CobYpP7L.js";import{b as Z,m as ss,i as We,f as Qe,c as pe,d as ht,e as Se,o as Hn,g as _n,h as oe,n as Be,t as as,s as Xe,j as ns,k as Un,l as Kn,p as qn,r as rs,q as Wn,u as Vn,w as Yn,x as is,y as ls,z as ft,B as Gn,C as os,R as gt,D as Jn,E as Qn,F as Xn,G as Zn,H as er,J as tr,O as sr,K as ar,L as cs,N as yt,V as nr,P as rr,M as ir,A as lr,a as or,S as cr,I as dr}from"./VisibilitySection-CZVuYCfP.js";import{s as ur,r as mr,a as pr,R as xr}from"./ComputerFilesPane-BjzS9ZTa.js";import{M as vt}from"./monitor-7oLB-7rZ.js";import{a as ds,m as us,b as hr,c as fr}from"./mcp-servers-5_CMZE0a.js";import{R as gr}from"./RoutinesPage-BeldL46G.js";import{S as yr}from"./SignedInSites-BgqjFXnz.js";import"./index-BBObcTo5.js";import"./org-library-D71rjidw.js";import"./package-format-Bc1BWLbR.js";import"./WorksOnGrid-DJJIaPGa.js";import"./ProIntroduction-DuPsMUld.js";import"./remote-desktop-DDRRx8uY.js";const vr=[["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"}]],br=Ce("calendar-plus",vr);const kr=[["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"}]],jr=Ce("library",kr);const wr=[["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"}]],ms=Ce("slack",wr);const Nr=[["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"}]],Sr=Ce("tag",Nr),Cr=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:As,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Ls,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:ms,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:Ms,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:$t,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:jr,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Ts,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Bs,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:Ds,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:zt,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:Fs,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:Ht,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:$s,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:$n,keywords:["tokens","cost","billing"]}],bt={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 Pr(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(bt,n.status))return null;try{return[s("botOverview.routine.line",{schedule:zs(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:st(t.nextRunAt)})]:[],...n?[s(bt[n.status],{time:st(n.at)})]:[]].join(" ")}catch{return null}}const kt={"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"},jt={"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 wt(t,a){return!a||a.map(n=>n||"General").join(", ")!==t?t:a.map(n=>n||s("botAccess.teams.general")).join(", ")}const Nt=t=>Object.hasOwn(jt,t)?s(jt[t]):t,St=(t,a,n)=>Number(t)===1?a:n,Or=[{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:wt(t,a)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>St(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])=>St(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:wt(t,a)})}],Er=t=>ee()!=="en"&&Object.hasOwn(Is[ee()]??{},t);function Rr(t,a){for(const n of Or){const l=n.line.exec(t);if(!l)continue;const r=n.key(l);return Er(r)?s(r,n.params(l,a)):t}return null}function De(t,a){if(Object.hasOwn(kt,t))return s(kt[t]);const n=Rr(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:Nt(r[1])});const i=/^Computer preference: (.+)\.$/.exec(t);if(i)return s("botOverview.line.computer",{preference:Nt(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 Ct={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 Ir(t,a=ee()){const n=/^(\w+): /.exec(t)?.[1];return a==="en"||!n||!Object.hasOwn(Ct,n)?t:`${s(Ct[n])}: ${t.slice(n.length+2)}`}function Ar({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(xe,{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 Lr({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),m=(h,b)=>s(`botOverview.setup.${h}`)||b;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:m(h.id,h.label)}),e.jsx(ge,{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:m(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,b)=>e.jsx("li",{children:Pr(t.doesRoutines?.[b])??De(h)},b))})]}),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,b)=>e.jsx("li",{children:De(h,t.managedSections)},b))})]}),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,b)=>e.jsx("li",{children:De(h,t.managedSections)},b))})]}),e.jsx(Ar,{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(ge,{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,b)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Ir(h.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",_t(h.at)]})]},b))})]})]})}function Mr({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(es,{size:14,"aria-hidden":"true"})]})]})}function Tr(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 ps(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:Tr(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 xs(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 Br(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=Wn(t.path),r=t.path===Z?l:t.path===Vn?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 hs({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 Dr({bot:t,active:a=!0,onToggle:n}){const{capabilities:l}=ye(),[r,i]=x.useState(null),[c,d]=x.useState(null),[o,u]=x.useState(null),[m,h]=x.useState(null),[b,f]=x.useState(null),[v,j]=x.useState(null),[k,y]=x.useState(null),[N,S]=x.useState(!1),[E,M]=x.useState(null),[F,T]=x.useState(""),[I,z]=x.useState(null),[A,p]=x.useState(!1),[R,D]=x.useState(null),[H,_]=x.useState(!1),[G,Y]=x.useState(!1),{state:U,dispatch:g}=B(),$=Hs(U.config),[ie,ue]=x.useState(!1),[he,C]=x.useState(""),K=async w=>{const[P,Re,Rs]=await Promise.all([Qe(t.id),pe(t.id),ht(t.id).catch(()=>null)]);if(i(P),D(P.lendingReview??null),d(Re),z(Rs),w){const Ie=await Se(t.id,w);u({path:Ie.path,text:Ie.text,hash:Ie.hash,dirty:!1,readOnly:w.startsWith("memory/log/")})}};x.useEffect(()=>{if(!a)return;let w=!1;j(null);const P=o?.dirty===!0;return K(P?void 0:o?.path??Z).catch(Re=>{w||j(ae(Re))}),()=>{w=!0}},[a,t.id]);const V=async w=>{j(null),h(null);try{const P=await Se(t.id,w);u({path:P.path,text:P.text,hash:P.hash,dirty:!1,readOnly:w.startsWith("memory/log/")})}catch(P){j(ae(P))}},q=async w=>{if(o){S(!0),j(null);try{const P=await Xe(t.id,o.path,o.text,w);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 pe(t.id))}catch(P){j(ae(P))}finally{S(!1)}}},le=()=>{!m||!o||(f(o.text),u({...o,text:m.current,hash:m.currentHash,dirty:!1}),h(null))},ve=async w=>{if(window.confirm(s("memory.confirmDelete",{name:w.name}))){j(null);try{const{overview:P}=await ns(t.id,w.path);i(P),d(await pe(t.id)),o?.path===w.path&&u(null)}catch(P){j(ae(P))}}},et=async()=>{const w=Un(F);if(!w){j(s("memory.topicNameError"));return}T(""),await V(`memory/${w}`),u(P=>P&&{...P,dirty:!0,text:P.text||Fr(w)})},Ss=async w=>{M(w.id),j(null);try{const P=await rs(t.id,w.id);i(P.overview),d(await pe(t.id)),o?.path===w.path&&!o.dirty&&u({...o,text:P.text,hash:P.hash}),y(s("memory.restored",{path:w.path}))}catch(P){j(ae(P))}finally{M(null)}},tt=async w=>{j(null),y(null);try{await Hn(t.id,w)}catch(P){j(ae(P))}},Cs=()=>{const w=t.memoryUpkeep===!1;g({type:"updateBot",botId:t.id,patch:{memoryUpkeep:w}}),z(P=>P&&{...P,enabled:w})},Ps=async()=>{if(!ie){ue(!0),C("");try{const w=await se("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!$}})});g({type:"configStatus",config:w})}catch(w){C(w instanceof Error?w.message:s("memory.learnFromRooms.error"))}finally{ue(!1)}}},Os=async()=>{p(!0),j(null),y(null);try{const{report:w,overview:P}=await as(t.id);i(P),d(await pe(t.id)),z(await ht(t.id)),o&&!o.dirty&&await V(o.path),y(`${xs(w)}.${w.note?` ${w.note}`:""}`)}catch(w){j(ae(w))}finally{p(!1)}},Es=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:w=>n(w.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,Es)}),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(Ut,{size:14}),s("memory.showFileManager")]})]})]}),R&&e.jsx(hs,{changed:R.changed,stale:H,busy:G,onReviewed:()=>{Y(!0),ss(t.id,R.token).then(()=>{D(null),_(!1)}).catch(w=>{if(w instanceof Kt&&w.status===409)return _(!0),K();j(ae(w))}).finally(()=>Y(!1))}}),r&&e.jsx(zr,{index:r.index}),t.memoryEnabled!==!1&&e.jsx($r,{enabled:t.memoryUpkeep!==!1,status:I,tidying:A,onToggle:Cs,onTidy:()=>{Os()},rooms:{enabled:$,saving:ie,error:he,onToggle:()=>{Ps()}}}),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")})]}),m&&e.jsx(fs,{botName:t.name,busy:N,onReload:le,onOverwrite:()=>{q(m.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:w=>u({...o,text:w.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:N||!o.dirty,className:ne,children:N?s("memory.saving"):s("memory.save")}),o.dirty&&e.jsx("button",{type:"button",className:Fe,disabled:N,onClick:()=>{V(o.path)},children:s("memory.discard")})]}),b!==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:b}),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(Ot,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:r.topics,selected:o?.path,onOpen:w=>{V(w.path)},onDelete:w=>{ve(w)}}),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:w=>T(w.target.value),onKeyDown:w=>{w.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(Ot,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:r.logs,selected:o?.path,onOpen:w=>{V(w.path)},onDelete:w=>{ve(w)}})})]}),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:w=>{Ss(w)}})})]}),k&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:k}),v&&e.jsx("div",{className:"text-[13px] text-danger",children:v})]})}function Fr(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,al as Kt}from"./styles-BHtUK2qB.js";import{G as lt,Z as Rt,d3 as Vt,bH as qt,dj as Gt,cI as Xt,eb as Yt,ec as Jt,dk as Zt,W as Qt,u as dt,ed as en,J as tn,ee as nn,n as Ge,ef as It,P as rn,bO as sn}from"./App-B612vSUv.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-J8hqmwv5.js";import{P as At,L as Xe,Z as ln,K as ht,X as cn}from"./PlacesRail-CUntVv3u.js";import{M as un,a as dn}from"./minimize-o-OFVasg.js";import{F as fn}from"./file-up-Cg2kYQkd.js";const pn=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]],hn=Tt("mouse-pointer-2",pn);const mn=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],bn=Tt("shrink",mn);function xn(){const[e,t]=a.useState(()=>document.visibilityState==="visible");return a.useEffect(()=>{const r=()=>t(document.visibilityState==="visible");return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[]),e}const je="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:cursor-not-allowed disabled:opacity-40";function wn(e,t,r){return!e||!t?"connecting":r==="pending"?"taking":r==="slow"?"waiting":t.controller==="you"?"yours":t.owned?"held":t.controller==="another-viewer"?"elsewhere":t.controller==="agent"?"bot":"watching"}const mt={connecting:()=>s("browser.panel.connecting"),watching:()=>s("browser.control.watching"),bot:e=>s("browser.control.botHas",{name:e}),yours:()=>s("vm.workspace.youHaveControl"),held:e=>s("browser.control.held",{name:e}),elsewhere:()=>s("browser.control.elsewhere"),taking:()=>s("browser.control.taking"),waiting:e=>s("browser.control.waiting",{name:e})},yn=a.forwardRef(function(t,r){const{botName:o,tabs:i,nav:c,connected:u,control:w,takeStatus:v,commandsReady:m}=t,[d,g]=a.useState(""),[y,E]=a.useState(!1),k=wn(u,w,v),C=k==="yours",T=C||k==="held",b=c.url==="about:blank"?"":c.url;return n.jsxs("div",{className:"shrink-0 border-b border-hairline/40",children:[n.jsxs("div",{className:"flex min-h-10 items-center gap-1 px-2 pt-1",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",role:"tablist","aria-label":s("browser.panel.tabs"),children:[i.length?i.map(j=>n.jsxs("div",{className:`flex max-w-52 shrink-0 items-center gap-1 rounded-xl px-1 text-[12px] ${j.active?"bg-inset text-ink":"text-ink-secondary"}`,children:[n.jsx(lt,{size:13,className:"ml-1.5 shrink-0 opacity-60","aria-hidden":"true"}),n.jsx("button",{role:"tab","aria-selected":j.active,className:"truncate px-1 py-1.5 text-left disabled:cursor-default",disabled:!m,onClick:()=>t.onCommand({type:"tabSelect",tabId:j.tabId}),title:j.title||j.url,children:j.title||s("browser.panel.newTab")}),n.jsx("button",{className:je,"aria-label":s("browser.panel.closeTab",{title:j.title||s("browser.panel.tab")}),disabled:!m,onClick:()=>t.onCommand({type:"tabClose",tabId:j.tabId}),children:n.jsx(Ue,{size:13})})]},j.tabId)):n.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-inset px-3 py-1.5 text-[12px] text-ink-secondary",children:[n.jsx(lt,{size:13,"aria-hidden":"true"}),s("browser.panel.newTab")]}),n.jsx("button",{className:`${je} shrink-0`,disabled:!m,"aria-label":s("browser.panel.newTab"),title:s("browser.panel.newTab"),onClick:()=>t.onCommand({type:"tabNew"}),children:n.jsx(At,{size:16})})]}),n.jsxs("button",{type:"button","aria-pressed":T,"aria-label":`${mt[k](o)}. ${s(T?"browser.control.handBack":"browser.control.take")}`,"aria-description":C?t.hint:void 0,title:C&&t.hint?t.hint:s(T?"browser.control.handBack":"browser.control.take"),disabled:!u||k==="elsewhere"||k==="connecting"||k==="taking"||k==="waiting",onClick:T?t.onHandBack:t.onTake,className:`flex max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border px-2.5 py-1 text-[11px] disabled:cursor-default ${T?"border-accent-border bg-accent/15 text-accent-text":"border-hairline text-ink-secondary hover:bg-inset hover:text-ink"}`,"data-pill":k,children:[k==="taking"||k==="waiting"||k==="connecting"?n.jsx(Xe,{size:12,className:"shrink-0 animate-spin","aria-hidden":"true"}):n.jsx(Rt,{size:12,className:"shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"truncate",children:mt[k](o)}),k==="bot"||k==="watching"?n.jsxs("span",{className:"shrink-0 text-ink",children:["· ",s("browser.control.take")]}):T?n.jsxs("span",{className:"shrink-0",children:["· ",s("browser.control.handBack")]}):null]}),n.jsx("button",{className:je,title:s(t.maximized?"browser.panel.restore":"browser.panel.maximizeHint"),"aria-label":s(t.maximized?"browser.panel.restore":"browser.panel.maximize"),onClick:t.onMaximize,children:t.maximized?n.jsx(bn,{size:15}):n.jsx(Vt,{size:15})}),n.jsx("button",{className:je,title:s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreenHint"),"aria-label":s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreen"),onClick:t.onFullscreen,children:t.fullscreen?n.jsx(un,{size:15}):n.jsx(dn,{size:15})}),n.jsx("button",{className:`${je} rounded-xl bg-inset p-1.5`,title:s("browser.panel.profileTitle",{name:t.profileName}),"aria-label":s("browser.panel.profiles"),onClick:t.onProfiles,children:n.jsx(ln,{size:15})})]}),n.jsxs("form",{className:"relative flex h-10 items-center gap-1 px-2",onSubmit:j=>{j.preventDefault(),t.onAddress(d),(r&&typeof r=="object"?r.current:null)?.blur()},children:[n.jsxs("div",{className:"flex shrink-0 items-center",role:"group","aria-label":s("browser.panel.navigation"),children:[n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoBack,"aria-label":s("browser.panel.back"),title:s("browser.panel.back"),onClick:()=>t.onCommand({type:"history",delta:-1}),children:n.jsx(qt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoForward,"aria-label":s("browser.panel.forward"),title:s("browser.panel.forward"),onClick:()=>t.onCommand({type:"history",delta:1}),children:n.jsx(Gt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m,"aria-label":s(c.loading?"browser.panel.loadingReload":"browser.panel.reload"),title:s("browser.panel.reloadShort"),onClick:()=>t.onCommand({type:"reload"}),children:c.loading?n.jsx(Xe,{size:16,className:"animate-spin"}):n.jsx(Xt,{size:16})})]}),n.jsx("input",{ref:r,"aria-label":s("browser.panel.address"),readOnly:!m,value:y?d:b,onChange:j=>g(j.target.value),onFocus:j=>{g(b),E(!0),m&&queueMicrotask(()=>j.target.select())},onBlur:()=>E(!1),onKeyDown:j=>{j.key==="Escape"&&(j.preventDefault(),g(b),j.currentTarget.blur())},placeholder:s(u?"browser.panel.searchOrAddress":"browser.panel.connecting"),spellCheck:!1,className:"mx-1 min-w-0 flex-1 rounded-lg bg-transparent px-2 py-1.5 text-center text-[12px] outline-none placeholder:text-ink-secondary focus:bg-inset focus:text-left"}),t.menu,n.jsx("div",{"aria-hidden":"true","data-loading":c.loading,className:`pointer-events-none absolute bottom-0 left-0 h-0.5 bg-accent transition-[width,opacity] duration-500 ${c.loading?"w-2/3 opacity-100":"w-full opacity-0"}`})]})]})});function gn(e){return Array.isArray(e)?e.flatMap(t=>{const{id:r,name:o}=t??{};return typeof r=="string"&&typeof o=="string"?[{id:r,name:o}]:[]}):[]}const kn="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40";function vn({ready:e,extensions:t,onList:r,onOpen:o}){const i=a.useRef(null);return a.useEffect(()=>{e&&i.current?.open&&r()},[e]),n.jsxs("details",{ref:i,className:"relative shrink-0",onToggle:c=>{c.currentTarget.open&&e&&r()},children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.extensions.title"),title:s("browser.extensions.title"),children:n.jsx(Yt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex max-h-80 w-56 flex-col overflow-y-auto rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.extensions.title")}),e?t&&t.length===0?n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.empty")}):(t??[]).map(c=>n.jsx("button",{type:"button",role:"menuitem",className:kn,onClick:()=>{i.current?.removeAttribute("open"),o(c.id)},children:n.jsx("span",{className:"truncate",children:c.name})},c.id)):n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.takeControl")})]})]})}const _e=[.25,.33,.5,.67,.75,.8,.9,1,1.1,1.25,1.5,1.75,2,2.5,3,4,5];function bt(e,t){return t>0?_e.find(r=>r>e+.001)??_e.at(-1):[..._e].reverse().find(r=>r<e-.001)??_e[0]}const Cn=[{label:"browser.viewport.fill",setting:{mode:"fill"}},{label:"browser.viewport.fullHd",setting:{mode:"preset",preset:"fullHd"}},{label:"browser.viewport.desktop",setting:{mode:"preset",preset:"desktop"}},{label:"browser.viewport.tablet",setting:{mode:"preset",preset:"tablet"}},{label:"browser.viewport.phone",setting:{mode:"preset",preset:"phone"}}],xt=(e,t)=>e.mode===t.mode&&(e.mode!=="preset"||t.mode==="preset"&&e.preset===t.preset),Ae="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40",Qe="rounded-md border border-hairline p-1 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40";function Sn({stream:e,ready:t,typing:r,setting:o,zoom:i,pip:c,onViewport:u,onZoom:w,onPip:v,onType:m,onSecret:d,onReconnect:g,onRestart:y}){const E=a.useRef(null),k=T=>()=>{E.current?.removeAttribute("open"),T()},C=T=>n.jsx("div",{className:"border-b border-hairline/40 py-1 last:border-b-0",children:T});return n.jsxs("details",{ref:E,className:"relative shrink-0",children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.panel.menu"),title:s("browser.panel.menu"),children:n.jsx(Jt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex w-56 flex-col rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[e?C(n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.viewport.title")}),Cn.map(T=>n.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":xt(T.setting,o),className:Ae,disabled:!t,onClick:k(()=>u(T.setting)),children:[n.jsx("span",{className:"w-3.5 shrink-0",children:xt(T.setting,o)?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null}),s(T.label)]},T.label)),n.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[n.jsx("span",{children:s("settings.profile.avatar.zoom")}),n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.out"),disabled:!t||i<=_e[0],onClick:()=>w(bt(i,-1)),children:n.jsx(Zt,{size:12})}),n.jsxs("span",{className:"min-w-11 text-center tabular-nums text-ink-secondary","aria-live":"polite",children:[Math.round(i*100),"%"]}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.in"),disabled:!t||i>=_e.at(-1),onClick:()=>w(bt(i,1)),children:n.jsx(At,{size:12})}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.reset"),disabled:!t||i===1,onClick:()=>w(1),children:n.jsx(Qt,{size:12})})]})]})]})):null,C(n.jsxs(n.Fragment,{children:[e&&c?n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(v),children:s(c.open?"browser.pip.close":"browser.pip.open")}):null,n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(m),children:s("browser.panel.typeTextMenu")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(d),children:s("browser.typeSecret")})]})),C(n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(g),children:s("browser.panel.reconnectView")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(y),children:s("browser.panel.restartBrowser")})]}))]})]})}function jn(e){const[t,r]=a.useState(null);return a.useEffect(()=>{if(!e)return;let o=!0;return Ge("/api/shared-computers").then(i=>{o&&r(i.computers?.find(c=>c.online&&c.scopes?.screen)?.name??null)}).catch(()=>{}),()=>{o=!1}},[e]),t}function En({wall:e,botName:t,onDismiss:r}){const{state:o,dispatch:i}=dt(),c=o.config?.cloudHome===!0,u=jn(c),w=e==="google"?"Google":"Microsoft";return n.jsx("section",{role:"status","aria-label":s("browser.passkey.title"),className:"shrink-0 border-b border-hairline/30 bg-inset/60 px-3 py-2.5 text-[12px] leading-relaxed text-ink-secondary",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(en,{size:14,className:"mt-0.5 shrink-0 text-accent-text","aria-hidden":"true"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium text-ink",children:s("browser.passkey.title")}),n.jsx("p",{children:s("browser.passkey.body",{provider:w})}),n.jsxs("ol",{className:"mt-1 list-decimal space-y-1 pl-4",children:[n.jsxs("li",{children:[s(e==="google"?"browser.passkey.appsGoogle":"browser.passkey.appsMicrosoft",{name:t})," ",n.jsx("button",{type:"button",className:"text-accent-text underline",onClick:()=>i({type:"togglePlugins",open:!0,surface:"apps"}),children:s("browser.passkey.connect")})]}),n.jsx("li",{children:s(e==="google"?"browser.passkey.otherWayGoogle":"browser.passkey.otherWayMicrosoft")}),c&&n.jsx("li",{children:u?s("browser.passkey.lentPc",{computer:u,name:t}):s("browser.passkey.lendPc",{name:t})})]}),n.jsx("button",{type:"button",className:"mt-1 text-accent-text underline",onClick:()=>{tn(nn)},children:s("browser.passkey.learnMore")})]}),n.jsx("button",{type:"button",className:"rounded-md p-1 text-ink-tertiary hover:bg-inset hover:text-ink","aria-label":s("browser.passkey.dismiss"),onClick:r,children:n.jsx(Ue,{size:14})})]})})}const Nn=4503,Pn=4404,Tn="sudo limixbot browser install --with-deps",Mn="https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox",ft=(e,t)=>{const r=Object.entries(t.query);if(r.length===0)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${new URLSearchParams(r).toString()}`};function Lt(e,t=window.location,r={}){const o=`/api/bots/${encodeURIComponent(e)}/browser`;return{httpBase:`${t.protocol}//${t.host}${o}`,wsBase:`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}${o}`,query:{...r},credentials:!0}}const Rn=e=>e===null||typeof e=="object"&&"type"in e&&typeof e.type=="string"&&"message"in e&&typeof e.message=="string"&&"defaultValue"in e&&typeof e.defaultValue=="string",In=(e,t)=>ft(`${e.access.httpBase}/upload?${new URLSearchParams({chooser:t}).toString()}`,e.access);async function zn(e,t){const r=new FormData;for(const i of t)r.append("file",i,i.name??"file");const o=await fetch(e.uploadUrl,{method:"POST",body:r,credentials:e.credentials?"include":"omit"});if(!o.ok){const i=await o.text();let c=i;try{c=JSON.parse(i).error??i}catch{}throw new Error(c||s("browser.page.uploadRefused"))}}const An=(e,t)=>ft(`${e.access.httpBase}/download/${encodeURIComponent(t)}`,e.access),et=e=>(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0),Ln=(e,t)=>e.type==="takeControl"||e.type==="resize"||e.type==="frameCap"||e.type==="restart"||e.type==="wake"||e.type==="releaseControl"&&t.owned===!0||t.controller==="you",_n=JSON.stringify({type:"ack"});function _t(e,t){let r={width:e.maxWidth,height:e.maxHeight},o=e.width!==void 0&&e.height!==void 0?{width:e.width,height:e.height}:null;const i=()=>{const y=new URLSearchParams({maxWidth:String(Math.max(1,Math.round(r.width))),maxHeight:String(Math.max(1,Math.round(r.height)))});return o&&(y.set("width",String(Math.round(o.width))),y.set("height",String(Math.round(o.height)))),e.interactive===!1&&y.set("interactive","false"),ft(`${e.access.wsBase}/stream?${y.toString()}`,e.access)};let c=!1,u=null,w=null,v=0,m=null,d=null;const g=()=>{if(c)return;const y={cap:r,size:o},E=new WebSocket(i());E.binaryType="arraybuffer",u=E;let k=!1;E.addEventListener("open",()=>{u===E&&(k=!0,t.onConnectedChange(!0))}),E.addEventListener("message",C=>{if(u!==E)return;if(C.data instanceof ArrayBuffer){v=0,E.send(_n),t.onFrame(C.data);return}if(typeof C.data!="string")return;let T;try{T=JSON.parse(C.data)}catch{return}if(typeof T!="object"||T===null)return;const{type:b,x:j,y:O,width:H,height:le,editable:re,canOperate:J,controller:Y,generation:$,dialog:x,stale:K,owned:B,text:V,id:Z,fileName:W,sizeBytes:te,multiple:P,accept:R,phase:D,sequence:U,tabId:q}=T;if(b==="fileChooser"&&typeof Z=="string"&&typeof P=="boolean"&&typeof R=="string")d=Z,t.onFileChooser?.({multiple:P,accept:R,uploadUrl:In(e,Z),credentials:e.access.credentials});else if(b==="fileChooserClosed"&&typeof Z=="string"){if(d!==Z)return;d=null,t.onFileChooser?.(null)}else if(b==="pointer"&&(D==="move"||D==="click")&&typeof j=="number"&&typeof O=="number"&&typeof U=="number")t.onPointer?.({phase:D,x:j,y:O,sequence:U});else if(b==="popup"&&typeof q=="string")t.onPopup?.(q);else if(b==="clipboard"&&typeof V=="string")t.onClipboard?.(V);else if(b==="download"&&typeof Z=="string"&&typeof W=="string"&&typeof te=="number")t.onDownload?.({fileName:W,sizeBytes:te,url:An(e,Z)});else if(b==="viewport"&&typeof H=="number"&&typeof le=="number")v=0,t.onViewport({width:H,height:le}),t.onMessage?.(T);else if(b==="probe"&&typeof j=="number"&&typeof O=="number"&&typeof re=="boolean")t.onProbe?.({x:j,y:O,editable:re});else if(b==="control"&&typeof J=="boolean"&&(Y==="agent"||Y==="you"||Y==="another-viewer"||Y==="unclaimed")&&typeof $=="number"&&Rn(x)){const N={canOperate:J,controller:Y,generation:$,dialog:x,...K===!0?{stale:!0}:{},...B===!0?{owned:!0}:{}},A=m===null;m=N,A&&J&&r!==y.cap&&E.send(JSON.stringify({type:"frameCap",maxWidth:r.width,maxHeight:r.height})),A&&J&&o&&o!==y.size&&E.send(JSON.stringify({type:"resize",...o})),t.onControl?.(N)}else typeof b=="string"&&t.onMessage?.(T)}),E.addEventListener("close",C=>{if(u===E&&(u=null,m=null,k&&t.onConnectedChange(!1),!c)){if(t.onClose?.(C.code,C.reason),C.code===Pn){c=!0,t.onGone?.();return}if(C.code===Nn){c=!0,t.onHostSetup?.(Bn(C.reason));return}if(C.code===1008||C.code===4401||!k&&C.code===1006){c=!0,t.onUnauthorized();return}w=setTimeout(g,Math.min(500*2**v++,1e4))}}),E.addEventListener("error",()=>E.close())};return g(),{send:y=>(y.type==="resize"?o={width:y.width,height:y.height}:y.type==="frameCap"&&(r={width:y.maxWidth,height:y.maxHeight}),u?.readyState!==WebSocket.OPEN||!m?.canOperate||!Ln(y,m)?!1:(u.send(JSON.stringify(y)),!0)),stop:()=>{c=!0,w!==null&&clearTimeout(w);const y=u;u=null,m=null,y?.close()}}}function Bt(e,t){const r=e.getContext("2d");let o=!1,i=!1,c=null;const u=w=>{i=!0,createImageBitmap(new Blob([w],{type:"image/jpeg"})).then(v=>{if(o||!r){v.close();return}(e.width!==v.width||e.height!==v.height)&&(e.width=v.width,e.height=v.height),r.drawImage(v,0,0),v.close(),t?.()}).catch(()=>{}).finally(()=>{i=!1;const v=c;c=null,v&&!o&&u(v)})};return{paint:w=>{o||(i?c=w:u(w))},stop:()=>{o=!0,c=null}}}const Bn=e=>{try{if(JSON.parse(e).need==="libraries")return{need:"libraries",command:Tn}}catch{}return{need:"sandbox"}},On=e=>e.need==="sandbox"?"This server's host blocks the sandbox its browser runs in. An administrator can allow it for one copy of Chrome with these steps, then try again:":"This server's host is missing libraries its browser needs. Run this once on the host, then try again:",Dn=700;function Hn(e,t){return e?1:t==="human"?.18:.35}function Fn({phase:e,sequence:t,left:r,top:o,controller:i}){const[c,u]=a.useState(null),w=c!==t;return a.useEffect(()=>{const v=window.setTimeout(()=>u(t),Dn);return()=>window.clearTimeout(v)},[t]),n.jsxs("div",{className:"pointer-events-none absolute left-0 top-0 z-30 transition-[opacity,transform] duration-150 ease-out motion-reduce:transition-none",style:{opacity:Hn(w,i),transform:`translate3d(${r}px, ${o}px, 0)`},"aria-hidden":"true","data-agent-cursor":!0,children:[e==="click"?n.jsx("span",{className:"absolute left-0.5 top-0.5 size-4 animate-ping rounded-full bg-accent/25 motion-reduce:animate-none"},t):null,n.jsx(hn,{className:"relative size-5 -translate-x-0.5 -translate-y-0.5 fill-card text-accent drop-shadow-sm",strokeWidth:2})]})}function $n({origin:e,realm:t,onAnswer:r}){const o=i=>{i.preventDefault();const c=i.currentTarget,u=c.elements.namedItem("username"),w=c.elements.namedItem("password");r({username:u.value,password:w.value}),u.value="",w.value=""};return n.jsxs("form",{role:"dialog","aria-label":s("browser.auth.label"),onSubmit:o,className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2.5 rounded-xl border border-hairline/60 bg-card p-4 text-ink shadow-xl",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-medium",children:[n.jsx(It,{size:14,"aria-hidden":"true"}),s("browser.auth.signIn")]}),n.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t?s("browser.auth.asks",{origin:e,realm:t}):e}),n.jsx("input",{name:"username","aria-label":s("browser.auth.username"),autoComplete:"off",spellCheck:!1,maxLength:1024,placeholder:s("browser.auth.username"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsx("input",{name:"password",type:"password","aria-label":s("logins.password"),autoComplete:"new-password",maxLength:1024,placeholder:s("logins.password"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:()=>r(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",children:s("common.cancel")}),n.jsx("button",{type:"submit",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",children:s("browser.auth.signIn")})]})]})}function Un({options:e,selectedIndex:t,anchor:r,bounds:o,onChoose:i,onClose:c}){const[u,w]=a.useState(()=>t>=0?t:e.findIndex(b=>!b.disabled)),v=a.useRef(null);a.useEffect(()=>{v.current?.focus({preventScroll:!0})},[]),a.useEffect(()=>{v.current?.querySelector(`[data-index="${u}"]`)?.scrollIntoView?.({block:"nearest"})},[u]);const m=o.height-(r.top+r.height),d=r.top,g=m<160&&d>m,y=Math.max(96,Math.min(320,(g?d:m)-8)),E=Math.max(0,Math.min(r.left,o.width-Math.max(r.width,160))),k=(b,j)=>{for(let O=b+j;O>=0&&O<e.length;O+=j)if(!e[O].disabled)return O;return b},C=b=>{b.key==="ArrowDown"||b.key==="ArrowUp"?(b.preventDefault(),w(j=>k(j,b.key==="ArrowDown"?1:-1))):b.key==="Home"||b.key==="End"?(b.preventDefault(),w(b.key==="Home"?k(-1,1):k(e.length,-1))):b.key==="Enter"||b.key===" "?(b.preventDefault(),e[u]&&!e[u].disabled&&i(u)):(b.key==="Escape"||b.key==="Tab")&&(b.preventDefault(),b.stopPropagation(),c())};let T;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"absolute inset-0 z-30","aria-hidden":"true",onPointerDown:b=>{b.preventDefault(),c()}}),n.jsx("div",{ref:v,role:"listbox","aria-label":s("browser.select.label"),"aria-activedescendant":u>=0?`select-option-${u}`:void 0,tabIndex:0,onKeyDown:C,onBlur:b=>{b.currentTarget.contains(b.relatedTarget)||c()},className:"absolute z-40 overflow-y-auto rounded-lg border border-hairline/60 bg-menu py-1 text-[13px] text-ink shadow-xl outline-none",style:{left:E,minWidth:Math.max(r.width,160),maxHeight:y,...g?{bottom:o.height-r.top+2}:{top:r.top+r.height+2}},children:e.map((b,j)=>{const O=b.group!==void 0&&b.group!==T?b.group:null;return T=b.group,n.jsxs("div",{children:[O!==null?n.jsx("div",{className:"px-3 pb-0.5 pt-1.5 text-[11px] font-medium text-ink-tertiary",role:"presentation",children:O}):null,n.jsxs("div",{id:`select-option-${j}`,"data-index":j,role:"option","aria-selected":j===t,"aria-disabled":b.disabled||void 0,onPointerEnter:()=>{b.disabled||w(j)},onPointerDown:H=>H.preventDefault(),onClick:()=>{b.disabled||i(j)},className:`flex cursor-default items-center gap-2 px-3 py-1.5 ${b.group!==void 0?"pl-5":""} ${b.disabled?"text-ink-tertiary":j===u?"bg-accent text-accent-ink":""}`,children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label||" "}),j===t?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null]})]},j)})})]})}const wt=150,Wn=24,Kn=1e4,$e="​",Vn={key:"Backspace",code:"Backspace",keyCode:8},qn={key:"Delete",code:"Delete",keyCode:46},Gn=8,Xn=500,Yn=4,Jn=16,yt=e=>e===0?"left":e===1?"middle":e===2?"right":"none",gt=e=>e&1?"left":e&2?"right":e&4?"middle":"none",Le=e=>e!==null&&e.canOperate&&e.controller!=="another-viewer";function Ot(e,t){const r=Math.min(e.width/t.width,e.height/t.height),o=t.width*r,i=t.height*r;return{width:o,height:i,left:(e.width-o)/2,top:(e.height-i)/2}}function Zn(e,t,r,o,i,c){const u=Ot(e,t);if(!(u.width>0&&u.height>0))return null;const w=r.width/u.width,v=(o-e.left-u.left)*w,m=(i-e.top-u.top)*(r.height/u.height);return!(v>=0&&m>=0&&v<=r.width&&m<=r.height)&&!c?null:{x:Math.min(Math.max(v,0),r.width),y:Math.min(Math.max(m,0),r.height),scale:w}}function kt(e,t,r,o){const i=Ot(t,r),c=i.width/o.width,u=i.height/o.height;return{left:i.left+e.x*c,top:i.top+e.y*u,width:e.width*c,height:e.height*u}}function Qn(e){const t=document.createElement("a");t.href=e.url,t.download=e.fileName,t.rel="noopener",t.click()}function er(e){const{connect:t,ref:r}=e,o=a.useRef(e);o.current=e;const i=a.useRef(null),c=a.useRef(null),u=a.useRef(!1),w=a.useRef(null),v=a.useRef(null),m=a.useRef(null),d=a.useRef(!1),g=a.useRef(null),[y,E]=a.useState(null),[k,C]=a.useState(!1),[T,b]=a.useState(!1),[j,O]=a.useState(""),[H,le]=a.useState(null),[re,J]=a.useState(null),[Y,$]=a.useState(null),[x,K]=a.useState("default"),[B,V]=a.useState(null),[Z,W]=a.useState([]),[te,P]=a.useState(null),R=a.useRef(0),D=a.useRef(null),U=a.useRef(null),q=a.useRef(null),N=a.useRef(null),A=a.useRef(0),G=a.useRef({left:1,middle:1,right:1,none:1}),ie=a.useRef(null),pe=a.useRef(null),F=a.useRef(null),Ee=a.useRef(null),Oe=a.useRef(null),[We,Ke]=a.useState(!1),Ne=a.useCallback(l=>{const p=++R.current;W(S=>[...S.slice(-2),{...l,id:p}])},[]),ue=l=>W(p=>p.filter(S=>S.id!==l)),Q=a.useCallback(l=>{o.current.input(l)},[]),Re=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null,U.current=q.current=null,A.current=0,G.current={left:1,middle:1,right:1,none:1},ie.current=null,pe.current=F.current=Ee.current=null,u.current=!1,c.current&&(c.current.value=$e)},[]),be=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null;const l=U.current,p=q.current;U.current=null,q.current=null,l&&Q(l),p&&Q(p)},[Q]),ve=a.useCallback(()=>{N.current??=requestAnimationFrame(be)},[be]),de=a.useCallback((l,p,S,z)=>{const I=q.current;q.current={type:"wheel",x:l.x,y:l.y,deltaX:(I?.deltaX??0)+p,deltaY:(I?.deltaY??0)+S,modifiers:z},ve()},[ve]),he=a.useCallback((l,p,S)=>{const z=i.current,I=v.current;return!z||!I||!d.current||!Le(g.current)?null:Zn(z.getBoundingClientRect(),z,I,l,p,S)},[]),Ie=(l,p,S,z)=>{const I=ie.current,X=I&&I.button===l&&z-I.time<Xn&&Math.hypot(p-I.x,S-I.y)<Yn?I.count+1:1;return ie.current={button:l,time:z,x:p,y:S,count:X},X},ee=()=>c.current?.focus({preventScroll:!0});a.useImperativeHandle(r,()=>({canvas:()=>d.current?i.current:null,focusPage:ee}),[]),a.useEffect(()=>{const l=i.current?.parentElement;if(!l||typeof ResizeObserver>"u")return;let p=null,S=null;const z=()=>{S=null;const f=m.current;if(!f)return;const M=window.devicePixelRatio||1,se=Math.round(f.width*M),ye=Math.round(f.height*M),ae=Oe.current;if(ae!==null&&ae.width>=se&&ae.height>=ye)return;const _={width:Math.max(se,ae?.width??0),height:Math.max(ye,ae?.height??0)};Oe.current=_,ae===null?Ke(!0):w.current?.send({type:"frameCap",maxWidth:_.width,maxHeight:_.height})},I=()=>{p=null;const f=l.getBoundingClientRect();if(f.width<1||f.height<1)return;const M={width:Math.round(f.width),height:Math.round(f.height)},se=m.current;se?.width===M.width&&se.height===M.height||(m.current=M,w.current?.send({type:"resize",...M}),S!==null&&clearTimeout(S),S=setTimeout(z,se===null?0:wt*2))},X=new ResizeObserver(()=>{p===null&&(p=setTimeout(I,m.current===null?0:wt))});return X.observe(l),()=>{X.disconnect(),p!==null&&clearTimeout(p),S!==null&&clearTimeout(S)}},[]),a.useEffect(()=>{const l=i.current,p=m.current,S=Oe.current;if(te||!We||!S||!l||!p)return;d.current=!1,b(!1);const z=Bt(l,()=>{d.current||(d.current=!0,b(!0),o.current.onFirstFrame?.())}),I=f=>{const M=g.current;g.current=f,E(f),o.current.onControl?.(f),(f?.dialog?.message!==M?.dialog?.message||f?.dialog?.defaultValue!==M?.dialog?.defaultValue)&&O(f?.dialog?.defaultValue??""),f?.controller!=="you"?$(null):M?.controller!=="you"&&m.current&&w.current?.send({type:"resize",...m.current}),Le(f)||(Re(),c.current?.blur())},X=t({maxWidth:S.width,maxHeight:S.height,width:p.width,height:p.height},{onFrame:f=>z.paint(f),onProbe:f=>{if(g.current?.controller!=="you")return;Ee.current={...f,at:performance.now()};const M=F.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(F.current=null,f.editable?c.current?.focus({preventScroll:!0}):c.current?.blur()))},onPointer:f=>{const M=i.current,se=v.current;if(!M||!se||M.width<1||M.height<1)return;const ye={width:M.clientWidth,height:M.clientHeight},ae=kt({x:f.x,y:f.y,width:0,height:0},ye,M,se);J({...ae,phase:f.phase,sequence:f.sequence})},onClipboard:f=>{ht(f).then(M=>{M==="failed"&&Ne({kind:"clipboard",text:f})})},onDownload:f=>Ne({kind:"download",download:f}),onPopup:()=>{},onFileChooser:le,onViewport:f=>{v.current=f},onControl:I,onMessage:f=>{if(f.type==="selectPopup"&&typeof f.id=="string"&&Array.isArray(f.options)){const M=f.rect;M&&$({id:f.id,options:f.options,selectedIndex:Number(f.selectedIndex),rect:M})}else f.type==="cursor"&&typeof f.shape=="string"?K(f.shape):f.type==="authPrompt"&&typeof f.tabId=="string"&&typeof f.id=="string"&&typeof f.origin=="string"?V({tabId:f.tabId,id:f.id,origin:f.origin,realm:typeof f.realm=="string"?f.realm:""}):f.type==="authPromptClosed"?V(M=>M&&M.id!==f.id?M:null):f.type==="notice"&&typeof f.message=="string"&&Ne({kind:"error",message:Kt(f,f.message)});o.current.onMessage?.(f)},onConnectedChange:f=>{C(f),o.current.onConnectedChange?.(f),!f&&(le(null),$(null),V(null),I(null))},onHostSetup:P,onUnauthorized:()=>o.current.onUnauthorized?.(),onGone:()=>o.current.onGone?.(),onClose:(f,M)=>o.current.onClose?.(f,M)});return w.current=X,o.current.onClient?.(X),()=>{z.stop(),X.stop(),w.current===X&&(w.current=null),o.current.onClient?.(null),I(null),C(!1),J(null),Re()}},[We,Re,t,te,Ne]),a.useEffect(()=>{const l=i.current;if(!l)return;const p=S=>{const z=he(S.clientX,S.clientY,!1);if(!z)return;S.preventDefault();const I=S.deltaMode===WheelEvent.DOM_DELTA_LINE?Jn:S.deltaMode===WheelEvent.DOM_DELTA_PAGE?v.current?.height??0:1;de(z,S.deltaX*I,S.deltaY*I,et(S))};return l.addEventListener("wheel",p,{passive:!1}),()=>l.removeEventListener("wheel",p)},[he,de]),a.useEffect(()=>()=>{N.current!==null&&cancelAnimationFrame(N.current)},[]);const Ce=l=>{if(!Le(g.current))return;const{type:p,pointerId:S,clientX:z,clientY:I}=l,X=p==="pointercancel",f=pe.current;if(X&&f?.pointerId===S){pe.current=F.current=null;return}if(l.pointerType==="touch"&&!X){const _=he(z,I,p==="pointermove");if(p==="pointerdown"){if(!l.isPrimary)return;pe.current={pointerId:S,startX:z,startY:I,lastX:z,lastY:I,panning:!1};const Se=Ee.current,Te=_&&Se&&performance.now()-Se.at<Kn&&Math.hypot(_.x-Se.x,_.y-Se.y)<Wn;F.current=_?{x:_.x,y:_.y,editable:Te?Se.editable:null,answered:!1,tapped:!1}:null,_&&Q({type:"probe",x:_.x,y:_.y});return}if(!f||f.pointerId!==S)return;if(p==="pointermove"){if(!f.panning&&Math.hypot(z-f.startX,I-f.startY)<Gn)return;f.panning=!0,_&&de(_,(f.lastX-z)*_.scale,(f.lastY-I)*_.scale,0),f.lastX=z,f.lastY=I;return}pe.current=null;const oe=F.current;if(f.panning){F.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:F.current=null,be();const ge=Ie("left",z,I,l.timeStamp),ne={x:_.x,y:_.y,modifiers:0};Q({type:"mouse",action:"move",...ne,button:"none",buttons:0,clickCount:0}),Q({type:"mouse",action:"down",...ne,button:"left",buttons:1,clickCount:ge}),Q({type:"mouse",action:"up",...ne,button:"left",buttons:0,clickCount:ge});return}const M=A.current;if((X||p==="pointerup")&&M===0)return;(X||p==="pointerup")&&(A.current=X?0:l.buttons&7);const se=he(z,I,p!=="pointerdown"&&(X||p==="pointerup"||M!==0||l.buttons!==0));if(!se)return;const ye={x:se.x,y:se.y,modifiers:et(l)},ae=(_,oe,ge)=>{_==="down"&&(G.current[oe]=Ie(oe,z,I,l.timeStamp)),Q({type:"mouse",action:_,...ye,button:oe,buttons:ge,clickCount:G.current[oe]})};if(p==="pointerdown")ee(),l.currentTarget.setPointerCapture(S),be(),A.current=l.buttons&7,ae("down",yt(l.button),l.buttons);else if(p==="pointerup")be(),ae("up",yt(l.button),l.buttons);else{const _=X?0:l.buttons&7,oe=M^_;if(M!==0&&oe!==0){be();let ge=M;for(const ne of[1,2,4])oe&ne&&(ge^=ne,ae(_&ne?"down":"up",gt(ne),ge));A.current=_}if(X)return;U.current={type:"mouse",action:"move",...ye,button:gt(l.buttons),buttons:l.buttons,clickCount:0},ve()}},ze=l=>{u.current=!1,l.value=$e,l.setSelectionRange($e.length,$e.length)},De=l=>{Q({type:"key",action:"down",...l,modifiers:0}),Q({type:"key",action:"up",...l,modifiers:0})},He=(l,p)=>{if(!Le(g.current)||(u.current=!1,p.nativeEvent.isComposing||p.keyCode===229||p.key==="Process"||p.key==="Unidentified"))return;if(p.key==="Escape"&&p.shiftKey){p.preventDefault(),p.stopPropagation(),l==="down"&&(p.currentTarget.blur(),o.current.onLeave?.());return}const S=p.ctrlKey||p.metaKey;if(S&&p.key.toLowerCase()==="v"||p.shiftKey&&p.key==="Insert")return;const z=S?void 0:[...p.key].length===1?p.key:p.key==="Enter"?"\r":void 0;Q({type:"key",action:l,key:p.key,code:p.code,keyCode:p.keyCode,...l==="down"&&z!==void 0?{text:z}:{},modifiers:et(p)}),u.current=l==="down"&&!S&&(z!==void 0||p.key==="Backspace"||p.key==="Delete"),!S&&(p.preventDefault(),p.stopPropagation())},Fe=l=>{const p=l.nativeEvent;if(p instanceof InputEvent&&p.isComposing)return;const S=l.currentTarget,z=p instanceof InputEvent?p.inputType:"";if(u.current)u.current=!1;else if(z==="deleteContentBackward")De(Vn);else if(z==="deleteContentForward")De(qn);else{const I=S.value.replace(/^​/,"");I&&Q({type:"text",text:I})}ze(S)},xe=l=>{const p=H;p&&(le(null),zn(p,l).catch(S=>Ne({kind:"error",message:s("browser.page.uploadFailed",{error:S instanceof Error?S.message:String(S)})})))},me=l=>w.current?.send(l),ce=i.current,we=Y&&ce&&v.current&&ce.width>0?kt(Y.rect,{width:ce.clientWidth,height:ce.clientHeight},ce,v.current):null,Pe=y?.controller==="you";return n.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden ${e.className??""}`,"data-browser-surface":!0,children:[n.jsxs("div",{className:"relative min-h-0 flex-1",children:[n.jsx("canvas",{ref:i,"aria-hidden":"true",className:"block size-full touch-none object-contain",style:{cursor:Le(y)?Pe?x:"default":"not-allowed"},onPointerDown:Ce,onPointerMove:Ce,onPointerUp:Ce,onPointerCancel:Ce,onMouseDown:l=>l.preventDefault(),onContextMenu:l=>l.preventDefault()}),re&&!Pe?n.jsx(Fn,{...re,controller:y?.controller==="agent"?"agent":"none"}):null,n.jsx("textarea",{ref:c,"aria-label":e.label??s("browser.page.label"),"aria-description":s("browser.page.keysHint"),"aria-keyshortcuts":"Shift+Escape",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:!Le(y),defaultValue:$e,onFocus:l=>ze(l.currentTarget),className:"sr-only left-0 top-0 text-base",onKeyDown:l=>He("down",l),onKeyUp:l=>He("up",l),onInput:Fe,onCompositionEnd:l=>{const p=l.data.replace(/^​/,"");p&&Q({type:"text",text:p}),ze(l.currentTarget)},onCopy:l=>l.preventDefault(),onCut:l=>l.preventDefault(),onPaste:l=>{l.preventDefault();const p=l.clipboardData.getData("text/plain");p&&Q({type:"text",text:p})}}),k&&!T&&!te?n.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center text-ink-secondary","aria-hidden":"true",children:n.jsx(Xe,{size:22,className:"animate-spin"})}):null,Y&&we&&ce?n.jsx(Un,{options:Y.options,selectedIndex:Y.selectedIndex,anchor:we,bounds:{width:ce.clientWidth,height:ce.clientHeight},onChoose:l=>{me({type:"selectChoose",id:Y.id,index:l}),$(null),ee()},onClose:()=>{$(null),ee()}},Y.id):null,H&&Pe?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.page.chooseFilesLabel"),children:[n.jsxs("p",{className:"flex items-center gap-2 text-[13px]",children:[n.jsx(fn,{size:14,"aria-hidden":"true"}),s(H.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:H.multiple,accept:H.accept,onChange:l=>{const p=[...l.currentTarget.files??[]];l.currentTarget.value="",p.length>0&&xe(p)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>xe([]),children:s("common.cancel")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>D.current?.click(),children:s(H.multiple?"browser.page.chooseFiles":"browser.page.chooseFile")})]})]}):null,y?.dialog&&y.controller!=="another-viewer"?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.dialog.label"),children:[n.jsx("p",{className:"break-words text-[13px]",children:y.dialog.message}),Pe?n.jsxs(n.Fragment,{children:[y.dialog.type==="prompt"?n.jsx("input",{"aria-label":s("browser.dialog.response"),value:j,onChange:l=>O(l.target.value),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}):null,n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>me({type:"dialog",accept:!1}),children:s("browser.dialog.dismiss")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>me({type:"dialog",accept:!0,...y.dialog?.type==="prompt"?{promptText:j}:{}}),children:s("browser.dialog.accept")})]})]}):n.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("browser.dialog.takeControl")})]}):null,B&&Pe?n.jsx($n,{origin:B.origin,realm:B.realm,onAnswer:l=>{const p={tabId:B.tabId,id:B.id};me(l?{type:"authAnswer",...p,username:l.username,password:l.password}:{type:"authAnswer",...p}),V(null)}}):null,Z.length?n.jsx("div",{className:"absolute inset-x-3 bottom-3 z-20 flex flex-col items-center gap-2",role:"status",children:Z.map(l=>n.jsxs("div",{className:"flex max-w-full items-center gap-2 rounded-xl border border-hairline/60 bg-card px-3 py-2 text-[12px] text-ink shadow-lg",children:[l.kind==="download"?n.jsxs(n.Fragment,{children:[n.jsx(rn,{size:13,"aria-hidden":"true",className:"shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.downloaded",{name:l.download.fileName})}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{Qn(l.download),ue(l.id)},children:s("common.save")})]}):l.kind==="clipboard"?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.copied")}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{ht(l.text),ue(l.id)},children:s("common.copy")})]}):n.jsx("span",{role:"alert",className:"min-w-0 text-danger",children:l.message}),n.jsx("button",{type:"button","aria-label":s("browser.dialog.dismiss"),className:"shrink-0 rounded-md p-0.5 text-ink-secondary hover:bg-inset",onClick:()=>ue(l.id),children:n.jsx(Ue,{size:12})})]},l.id))}):null]}),te?n.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center",children:[n.jsx("p",{role:"alert",className:"max-w-sm text-[13px] text-ink-secondary",children:On(te)}),te.need==="libraries"?n.jsx("code",{className:"max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink",children:te.command}):n.jsx("a",{href:Mn,target:"_blank",rel:"noopener noreferrer",className:"text-[12px] text-ink underline",children:"Browser sandbox setup steps"}),n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:()=>P(null),children:s("common.tryAgain")})]}):null]})}const tr=8e3,nr=300,rr=2e4,sr=16,Dt=new Set(["Alt","Control","Meta","Shift"]),or=new Set(["Backspace","Enter","Tab","Escape","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]),qe=new Set(["navigate","history","reload","tabSelect","tabNew","tabClose"]),ar=new Set(["navigate","tabNew"]);function tt(e){return qe.has(e.type)?!0:e.type==="mouse"?e.action==="down":e.type==="key"?e.action==="down"&&!Dt.has(e.key):e.type==="wheel"||e.type==="text"}const nt=e=>e.type==="key"?`key:${e.code||e.key}`:e.type==="mouse"?`mouse:${e.button}`:e.type,vt=e=>(e.type==="key"||e.type==="mouse")&&e.action==="down",Ct=e=>(e.type==="key"||e.type==="mouse")&&e.action==="up";function lr(e){return e.type!=="key"||Dt.has(e.key)?!0:or.has(e.key)?!1:!e.modifiers||e.modifiers===8&&[...e.key].length===1}function ir(e){const t=e.transport;let r="bot",o="",i=[],c=!1,u=!1,w=!1,v=!1,m=!1,d=!1,g=0,y=Promise.resolve(),E,k;const C=new Set,T=new Set,b=x=>{o=x,e.onTakeStatus(x)},j=x=>{vt(x)&&lr(x)?C.add(nt(x)):Ct(x)&&C.delete(nt(x))},O=()=>!u&&!w&&(m||!v)&&!c&&!C.size&&(r==="held"||r==="bot"&&e.owned()),H=()=>{clearTimeout(E),E=u?void 0:setTimeout(()=>{E=void 0,re()},m?0:tr)},le=()=>{r="releasing",o==="stale"&&b(""),y=y.then(()=>u?void 0:t.release()).catch(()=>{}).then(()=>{r==="releasing"&&(r="bot")})},re=async()=>{if(!O())return;const x=g;await t.drain(),x===g&&O()&&le()},J=()=>{const x=i.filter(B=>ar.has(B.type)),K=i.some(B=>!x.includes(B)&&tt(B));i=x;for(const B of C)T.add(B);return C.clear(),K},Y=async()=>{c=!0;try{for(let x=i.shift();x&&!u;x=i.shift())t.send(x),t.size()>=sr&&await t.settle()}finally{c=!1,i=[]}},$=()=>{r="taking",e.onError(""),b("pending"),clearTimeout(k),k=setTimeout(()=>{!u&&r==="taking"&&b("slow")},nr),y=y.then(async()=>{if(u)return;const x=await t.take().then(K=>({reply:K}),K=>(u||e.onError(K instanceof Error?K.message:String(K)),null));clearTimeout(k),!u&&(x?(r="held",b(x.reply?.waited===!0&&J()?"stale":""),await Y()):(b(""),r="bot",i=[],C.clear()),H())}).catch(()=>{})};return{interact(x){if(u)return;const K=nt(x);if(Ct(x)&&T.delete(K))return;vt(x)&&T.delete(K);const B=r==="taking"||c;if(r!=="held"&&!B){if(!tt(x))return;if(t.stopped()&&!qe.has(x.type)){e.onHalted();return}}if(!(qe.has(x.type)&&B&&i.some(V=>qe.has(V.type)))){if(tt(x)&&(m=!1,o==="stale"&&b("")),j(x),g++,H(),r==="held"&&!B){t.send(x);return}i.push(x),B||$()}},observe(){if(u)return;const x=e.owned();d&&!x&&r==="held"&&!c&&(r="bot",C.clear(),T.clear(),clearTimeout(E),E=void 0),d=x,E===void 0&&x&&H()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||H())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,H()}},hold(x){u||w===x||(w=x,x||H())},leave(){!O()||t.size()||(r="releasing",t.release().catch(()=>{}))},close(){u=!0,clearTimeout(E),clearTimeout(k),i=[],C.clear(),T.clear()}}}function cr(e,t,r){return{send:o=>{e.send(o)},drain:async()=>{},settle:async()=>{},size:()=>0,stopped:()=>!1,take:()=>new Promise((o,i)=>{const c=t.current();if(c?.controller==="you"){o({waited:!1});return}if(!e.send({type:"takeControl"})){i(new Error(s("browser.panel.notConnected")));return}const u=c?.controller==="agent",w=d=>{clearTimeout(v),m(),d()},v=setTimeout(()=>w(()=>i(new Error(s("browser.panel.takeFailed")))),rr),m=t.watch(d=>{d?.controller==="you"?w(()=>o({waited:u})):d?.controller==="another-viewer"?w(()=>i(new Error(r))):d===null&&w(()=>i(new Error(s("browser.panel.viewDisconnected"))))})}),release:async()=>{e.send({type:"releaseControl"})}}}const ur="https://duckduckgo.com/?q=",dr=/^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i,fr=/^[^/?#:@]+:\d+(?:[/?#]|$)/,pr=/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\])(?::|\/|$)/i,hr=new Set(["about:","blob:","chrome:","data:","file:","ftp:","javascript:","mailto:","sms:","ssh:","tel:","view-source:","ws:","wss:"]);function mr(e){return/^([A-Za-z][A-Za-z\d+.-]*):/.exec(e)?.[1]?.toLowerCase().concat(":")}function rt(e){const t=e.includes("://")?e:`${pr.test(e)?"http":"https"}://${e}`;try{const r=new URL(t);return r.protocol==="http:"||r.protocol==="https:"?r.href:null}catch{return null}}function br(e){const t=e.trim();if(!t)return null;if(/^[a-z][a-z\d+.-]*:\/\//i.test(t))return rt(t);if(!/\s/.test(t)){const r=mr(t);if(r!==void 0&&(hr.has(r)||!fr.test(t)))return r==="http:"||r==="https:"?rt(t):null;const o=(t.split(/[/?#]/,1)[0]??"").replace(/^[^@]*@/,""),i=o.replace(/:\d+$/,"");if(i.length<o.length||dr.test(i)||/^[^.]+(?:\.[^.]+)+\.?$/.test(i)){const u=rt(t);if(u)return u}}return`${ur}${encodeURIComponent(t)}`}const xr=5;let Be=null;const it=new Set,Ht=()=>{for(const e of it)e()},wr=e=>(it.add(e),()=>it.delete(e));function yr(){if(typeof document>"u"||typeof HTMLCanvasElement.prototype.captureStream!="function")return!1;const e=HTMLVideoElement.prototype;return document.pictureInPictureEnabled&&typeof e.requestPictureInPicture=="function"||typeof e.webkitSetPresentationMode=="function"}function gr(){return a.useSyncExternalStore(wr,()=>Be?.key??null,()=>null)}function ct(){const e=Be;Be=null,e?.stop(),Ht()}async function kr(e){ct();const t=document.createElement("canvas"),r=t.getContext("2d"),o=e.seed&&e.seed.width>0&&e.seed.height>0?e.seed:null;t.width=o?.width??640,t.height=o?.height??400;const i=t.captureStream();o?r?.drawImage(o,0,0):r?.fillRect(0,0,t.width,t.height);const c=document.createElement("video");c.muted=!0,c.playsInline=!0,c.srcObject=i,c.style.cssText="position:fixed;right:0;bottom:0;width:1px;height:1px;opacity:0;pointer-events:none",document.body.append(c);const u=Bt(t);let w=null,v=!1,m=0,d=null;const g=()=>{Be===k&&ct()},y=()=>{v||(w=_t({access:Lt(e.botId),maxWidth:1280,maxHeight:1280,interactive:!1},{onFrame:C=>{m=0,u.paint(C)},onViewport:()=>{},onConnectedChange:()=>{},onUnauthorized:()=>{if(!v){if(m>=xr){g();return}d=setTimeout(y,1e3*2**m++)}},onGone:g}))},E=()=>{c.webkitPresentationMode!=="picture-in-picture"&&g()},k={key:e.botId,stop:()=>{v=!0,d!==null&&clearTimeout(d),w?.stop(),u.stop(),c.removeEventListener("leavepictureinpicture",g),c.removeEventListener("webkitpresentationmodechanged",E),document.pictureInPictureElement===c?document.exitPictureInPicture().catch(()=>{}):c.webkitPresentationMode==="picture-in-picture"&&c.webkitSetPresentationMode?.("inline");for(const C of i.getTracks())C.stop();c.srcObject=null,c.remove()}};Be=k,Ht();try{await c.play(),c.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise(C=>c.addEventListener("loadedmetadata",C,{once:!0})),document.pictureInPictureEnabled&&typeof c.requestPictureInPicture=="function"?(c.addEventListener("leavepictureinpicture",g),await c.requestPictureInPicture()):(c.addEventListener("webkitpresentationmodechanged",E),c.webkitSetPresentationMode?.("picture-in-picture"))}catch(C){throw g(),C}Be===k&&y()}const vr=[1e3,2e3,4e3,8e3,15e3],Cr=25e3,Sr=5e3,St=32,jt=4096,jr=24e3,Me=(e,t,r)=>Math.max(t,Math.min(r,Number.isFinite(e)?e:0)),Ye=e=>Me(e,-1e4,1e4);function Er(e,t,r,o){const i=t*r/e;return Math.abs(i-o)<=Math.max(1,r/e)?{width:r,height:o}:{width:r,height:Math.round(i)}}function Nr(e){for(let t=2;t+9<e.length;){if(e[t]!==255)return null;const r=e[t+1];if(r>=192&&r<=194)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8]};t+=2+(e[t+2]<<8|e[t+3])}return null}function Et(e){switch(e.type){case"mouse":return{type:"input_mouse",eventType:e.action==="down"?"mousePressed":e.action==="up"?"mouseReleased":"mouseMoved",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:e.button,clickCount:Math.round(Me(e.clickCount,0,3)),modifiers:e.modifiers};case"wheel":return{type:"input_mouse",eventType:"mouseWheel",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:"none",deltaX:Ye(e.deltaX),deltaY:Ye(e.deltaY),modifiers:e.modifiers};case"key":return e.key?{type:"input_keyboard",eventType:e.action==="up"?"keyUp":"keyDown",key:e.key.slice(0,64),code:e.code.slice(0,64),windowsVirtualKeyCode:Math.round(Me(e.keyCode??0,0,255)),modifiers:e.modifiers,...e.text!==void 0?{text:e.text}:{}}:null;case"text":{const t=[];for(let r=0;r<e.text.length;r+=jt)t.push({type:"input_keyboard",eventType:"char",text:e.text.slice(r,r+jt)});return t}case"navigate":return{type:"navigate",url:e.url};case"history":return{type:e.delta<0?"back":"forward"};case"reload":return{type:"reload"};case"tabSelect":return{type:"tab-select",tabId:e.tabId};case"tabClose":return{type:"tab-close",tabId:e.tabId};case"tabNew":return e.url?{type:"tab-new",url:e.url}:{type:"tab-new"};case"restart":return{type:"restart"};case"dialog":return{type:"dialog",accept:e.accept,...e.promptText!==void 0?{promptText:e.promptText.slice(0,4096)}:{}};default:return null}}const Ve=e=>e.type==="input_mouse"&&(e.eventType==="mouseMoved"||e.eventType==="mouseWheel"),ut=e=>e.type==="input_mouse"||e.type==="input_keyboard",Ft=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ft(e)||!ut(e);function Pr(e,t,r=()=>1){let o=[],i=null,c=0,u=!1;const w=d=>{o=o.filter(st),u||(u=!0,t(d))},v=()=>{const d=[o.shift()],g=u?1:r();let y=JSON.stringify(d[0]).length;for(;ut(d[0])&&d.length<g&&o.length&&ut(o[0]);){const E=JSON.stringify(o[0]).length;if(y+E>jr)break;y+=E,d.push(o.shift())}return d},m=()=>{if(i||!o.length)return;const d=c;i=(async()=>{for(;d===c&&o.length;){const g=v();try{await e(g.length===1?g[0]:{type:"input_batch",events:g})}catch(y){if(d!==c)continue;g.length>1&&o.unshift(...g.slice(1).filter(Ft)),w(y)}}})().finally(()=>{i=null,m()})};return{enqueue(d){if(u&&!st(d))return;const g=o.at(-1);if(g&&Ve(d)&&g.type===d.type&&g.eventType===d.eventType&&g.modifiers===d.modifiers&&g.button===d.button){o[o.length-1]=d.eventType==="mouseWheel"?{...d,deltaX:Ye(Number(g.deltaX??0)+Number(d.deltaX??0)),deltaY:Ye(Number(g.deltaY??0)+Number(d.deltaY??0))}:{...d};return}if(o.length>=St){if(Ve(d))return;const y=o.findIndex(Ve);if(y>=0)o.splice(y,1);else if(w(new Error(s("browser.input.tooSlow"))),!st(d)||o.length>=St)return}o.push({...d}),m()},async drain(){for(o=o.filter(d=>!Ve(d));i||o.length;)m(),await i},async settle(){for(;i||o.length;)m(),await i},size:()=>o.length+(i?1:0),stopped:()=>u,clear(){c++,o=[],u=!1}}}function Nt(e,t){const r=e.owned===!0?e.controlling===!0?"you":"agent":e.held===!0?"another-viewer":"unclaimed",o=e.dialog,i=o&&typeof o.type=="string"&&typeof o.message=="string"&&typeof o.defaultValue=="string"?{type:o.type,message:o.message,defaultValue:o.defaultValue}:null;return{canOperate:!0,controller:r,generation:t,dialog:i,...e.owned===!0?{owned:!0}:{}}}function Tr(e,t,r,o={viewer:""},i={},c=null){let u=!1,w=!1,v=!1,m=null,d="",g=0,y=0,E=0,k=null,C=null,T=null,b=1,j=c,O=null;const H=(P,R)=>{P.close(),m=null;const D=d!=="";if(D&&(o.viewer=d),d="",k=null,$.clear(),D&&t.onConnectedChange(!1),u)return;const U=R?vr[y++]:void 0;if(U===void 0){u=!0,w=R,t.onGone?.();return}T=setTimeout(K,U)},le=(P,R)=>P?.status!==404||!m||!R||d!==R?!1:(H(m,!0),!0),re=(P,R)=>r(P,R).catch(D=>{throw le(D,R),D}),J=P=>t.onMessage?.({type:"notice",message:P}),Y=P=>{const R=P?.notice;typeof R=="string"&&R&&J(R)},$=Pr(P=>d?re(P,d).then(Y):Promise.reject(new Error(s("browser.panel.connectionFirst"))),P=>{J(P instanceof Error?P.message:String(P))},()=>b),x=()=>{const P=j,R=d;O||!P||!R||(O=P,r({type:"resize",width:Math.round(P.width),height:Math.round(P.height)},R).catch(()=>{}).finally(()=>{O=null,j!==P&&d===R&&x()}))},K=()=>{if(T=null,u)return;const P=new URLSearchParams(o.viewer?{resume:o.viewer}:{}),R=j;j&&(P.set("width",String(Math.round(j.width))),P.set("height",String(Math.round(j.height))));const D=zt(P.size?`?${P.toString()}`:"",i),U=new EventSource(`/api/bots/${encodeURIComponent(e)}/browser/live${D}`);m=U,g=Date.now();const q=(N,A)=>U.addEventListener(N,G=>{if(m===U){g=Date.now();try{A(JSON.parse(G.data))}catch{}}});q("waiting",()=>t.onMessage?.({type:"starting"})),q("ready",N=>{typeof N.viewerId!="string"||!N.viewerId||(d=N.viewerId,b=Number.isSafeInteger(N.inputBatch)?Math.max(1,Math.min(Number(N.inputBatch),64)):1,o.viewer="",t.onConnectedChange(!0),j!==R&&x())}),q("heartbeat",()=>{y=0}),q("frame",N=>{if(!d||typeof N.data!="string"||typeof N.seq!="number")return;const A=atob(N.data),G=new Uint8Array(A.length);for(let F=0;F<A.length;F++)G[F]=A.charCodeAt(F);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const F=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(F.width!==C?.width||F.height!==C.height)&&(C=F,t.onViewport(F))}t.onFrame(G.buffer),r({type:"ack",seq:N.seq},d).catch(()=>{})}),q("tabs",N=>{Array.isArray(N.tabs)&&t.onMessage?.({type:"tabs",tabs:N.tabs})}),q("url",N=>{typeof N.url=="string"&&t.onMessage?.({type:"url",url:N.url})}),q("status",N=>{C||!(Number(N.viewportWidth)>0&&Number(N.viewportHeight)>0)||(C={width:Number(N.viewportWidth),height:Number(N.viewportHeight)},t.onViewport(C))}),q("control",N=>{const A=Nt(N,E);k&&A.controller===k.controller&&A.owned===k.owned&&JSON.stringify(A.dialog)===JSON.stringify(k.dialog)||(k=A.controller===k?.controller?A:Nt(N,++E),t.onControl?.(k))}),U.addEventListener("error",N=>{if(m!==U)return;let A=!(N instanceof MessageEvent);if(N instanceof MessageEvent)try{const G=JSON.parse(N.data);A=G.retryable===!0,G.asleep===!0?t.onMessage?.({type:"asleep"}):typeof G.message=="string"&&t.onMessage?.({type:"notice",message:G.message,...typeof G.errorKey=="string"?{errorKey:G.errorKey,...G.errorParams!==void 0?{errorParams:G.errorParams}:{}}:{}})}catch{}H(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&H(m,!0),!(!P||T===null&&!(u&&w))&&(T!==null&&clearTimeout(T),u=!1,w=!1,y=0,K()))},V=()=>{document.visibilityState!=="hidden"&&B(!0)},Z=setInterval(()=>B(!1),Sr),W=typeof window>"u"?null:window;return W?.addEventListener("focus",V),W?.addEventListener("online",V),W&&document.addEventListener("visibilitychange",V),{send:P=>{if(P.type==="resize")return j={width:P.width,height:P.height},x(),!0;if(!d||!k?.canOperate||!["takeControl","restart"].includes(P.type)&&k.controller!=="you")return!1;const R=Et(P);if(!R)return!1;if(P.type==="dialog"&&!Array.isArray(R))return re(R,d).catch(D=>J(D instanceof Error?D.message:String(D))),!0;for(const D of Array.isArray(R)?R:[R])$.enqueue(D);return!0},stop:()=>{u=!0,v=!0,clearInterval(Z),W?.removeEventListener("focus",V),W?.removeEventListener("online",V),W&&document.removeEventListener("visibilitychange",V),T!==null&&clearTimeout(T),m?.close(),m=null,d&&(o.viewer=d),d="",$.clear()},transport:{send:P=>{const R=d?Et(P):null;if(R)for(const D of Array.isArray(R)?R:[R])$.enqueue(D)},drain:()=>$.drain(),settle:()=>$.settle(),size:()=>$.size(),stopped:()=>$.stopped(),take:async()=>{if(!d)throw new Error(s("browser.panel.notConnected"));return{waited:(await re({type:"take"},d))?.waited===!0}},release:async()=>{d&&await re({type:"release"},d)}}}}const ot="Another window or device controls this browser. Hand control back there to use it here.",Mr=/^\/(?:v\d+\/)?signin\/(?:v\d+\/)?challenge\/(?:pk|sk)(?:\/|$)/u;function Rr(e){let t;try{t=new URL(e)}catch{return null}return t.hostname==="accounts.google.com"&&Mr.test(t.pathname)?"google":null}const Pt="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed",at={url:"",loading:!1,canGoBack:!1,canGoForward:!1};function Ir(e){return Array.isArray(e)?e.flatMap(t=>t&&typeof t=="object"&&typeof t.tabId=="string"?[{tabId:t.tabId,title:typeof t.title=="string"?t.title:"",url:typeof t.url=="string"?t.url:"",active:t.active===!0}]:[]):[]}function zr({bot:e,signIn:t,page:r}){const{state:o}=dt(),[i,c]=a.useState(!1),u=o.config?.browserEngine?.engine==="chrome"&&!i,[w,v]=a.useState(0),[m,d]=a.useState(!1),[g,y]=a.useState(null),[E,k]=a.useState([]),[C,T]=a.useState(at),[b,j]=a.useState({mode:"fill"}),[O,H]=a.useState(1),[le,re]=a.useState(null),[J,Y]=a.useState(""),[$,x]=a.useState(""),[K,B]=a.useState(!1),[V,Z]=a.useState(!1),[W,te]=a.useState(""),[P,R]=a.useState(!1),[D,U]=a.useState(!1),[q,N]=a.useState(!1),[A,G]=a.useState(!1),[ie,pe]=a.useState(!1),[F,Ee]=a.useState(!1),[Oe,We]=a.useState(""),Ke=gr(),Ne=xn(),ue=a.useRef(null),Q=a.useRef(null),Re=a.useRef(null),be=a.useRef(null),ve=a.useRef(null),de=a.useRef(null),he=a.useRef(null),Ie=a.useRef(new Set),ee=a.useRef(null),Ce=a.useRef({key:"",viewer:""}),ze=a.useRef(!1),De=a.useRef(0),He=a.useRef(0),Fe=a.useRef(null),xe=a.useRef(null),me=a.useRef({openSignInPage:()=>{},takeControl:()=>{}}),ce=o.computerControl?.[e.id]?.help?.place==="browser",we=on(o.config?.team,e.threadId).threadId;ze.current=P||ce;const Pe=e.browserProfile==="guest"?s("browser.panel.temporary"):o.config?.browserProfiles?.find(h=>h.id===e.browserProfile)?.name??s("browser.panel.ownBrowser",{name:e.name});a.useEffect(()=>{D?be.current?.showModal():be.current?.close()},[D]),a.useEffect(()=>{ee.current?.hold(q),q?ve.current?.showModal():ve.current?.close()},[q]);const l=a.useCallback(()=>{Z(!1),x(""),c(!1),v(h=>h+1)},[]);a.useEffect(()=>{c(!1)},[e.id,e.browserProfile,we]),a.useEffect(()=>{k([]),re(null),T(u?at:{...at,canGoBack:!0,canGoForward:!0}),B(!1),Z(!1),te(""),xe.current=null},[e.id,e.browserProfile,we,w,u]);const p=a.useCallback((h,L)=>{const fe=we?{threadId:we}:{};if(u)return _t({access:Lt(e.id,window.location,fe),...h},L);const ke=`${e.id}
1
+ import{c as Tt,r as a,j as n,t as s,X as Ue,f as Mt,al as Kt}from"./styles-BHtUK2qB.js";import{G as lt,Z as Rt,d3 as Vt,bH as qt,dj as Gt,cI as Xt,eb as Yt,ec as Jt,dk as Zt,W as Qt,u as dt,ed as en,J as tn,ee as nn,n as Ge,ef as It,P as rn,bO as sn}from"./App-DXv-5ZTc.js";import{w as zt,b as on,B as an}from"./BrowserProfilesManager-LC4INRs7.js";import{P as At,L as Xe,Z as ln,K as ht,X as cn}from"./PlacesRail-CUntVv3u.js";import{M as un,a as dn}from"./minimize-o-OFVasg.js";import{F as fn}from"./file-up-Cg2kYQkd.js";const pn=[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]],hn=Tt("mouse-pointer-2",pn);const mn=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],bn=Tt("shrink",mn);function xn(){const[e,t]=a.useState(()=>document.visibilityState==="visible");return a.useEffect(()=>{const r=()=>t(document.visibilityState==="visible");return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[]),e}const je="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:cursor-not-allowed disabled:opacity-40";function wn(e,t,r){return!e||!t?"connecting":r==="pending"?"taking":r==="slow"?"waiting":t.controller==="you"?"yours":t.owned?"held":t.controller==="another-viewer"?"elsewhere":t.controller==="agent"?"bot":"watching"}const mt={connecting:()=>s("browser.panel.connecting"),watching:()=>s("browser.control.watching"),bot:e=>s("browser.control.botHas",{name:e}),yours:()=>s("vm.workspace.youHaveControl"),held:e=>s("browser.control.held",{name:e}),elsewhere:()=>s("browser.control.elsewhere"),taking:()=>s("browser.control.taking"),waiting:e=>s("browser.control.waiting",{name:e})},yn=a.forwardRef(function(t,r){const{botName:o,tabs:i,nav:c,connected:u,control:w,takeStatus:v,commandsReady:m}=t,[d,g]=a.useState(""),[y,E]=a.useState(!1),k=wn(u,w,v),C=k==="yours",T=C||k==="held",b=c.url==="about:blank"?"":c.url;return n.jsxs("div",{className:"shrink-0 border-b border-hairline/40",children:[n.jsxs("div",{className:"flex min-h-10 items-center gap-1 px-2 pt-1",children:[n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",role:"tablist","aria-label":s("browser.panel.tabs"),children:[i.length?i.map(j=>n.jsxs("div",{className:`flex max-w-52 shrink-0 items-center gap-1 rounded-xl px-1 text-[12px] ${j.active?"bg-inset text-ink":"text-ink-secondary"}`,children:[n.jsx(lt,{size:13,className:"ml-1.5 shrink-0 opacity-60","aria-hidden":"true"}),n.jsx("button",{role:"tab","aria-selected":j.active,className:"truncate px-1 py-1.5 text-left disabled:cursor-default",disabled:!m,onClick:()=>t.onCommand({type:"tabSelect",tabId:j.tabId}),title:j.title||j.url,children:j.title||s("browser.panel.newTab")}),n.jsx("button",{className:je,"aria-label":s("browser.panel.closeTab",{title:j.title||s("browser.panel.tab")}),disabled:!m,onClick:()=>t.onCommand({type:"tabClose",tabId:j.tabId}),children:n.jsx(Ue,{size:13})})]},j.tabId)):n.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-inset px-3 py-1.5 text-[12px] text-ink-secondary",children:[n.jsx(lt,{size:13,"aria-hidden":"true"}),s("browser.panel.newTab")]}),n.jsx("button",{className:`${je} shrink-0`,disabled:!m,"aria-label":s("browser.panel.newTab"),title:s("browser.panel.newTab"),onClick:()=>t.onCommand({type:"tabNew"}),children:n.jsx(At,{size:16})})]}),n.jsxs("button",{type:"button","aria-pressed":T,"aria-label":`${mt[k](o)}. ${s(T?"browser.control.handBack":"browser.control.take")}`,"aria-description":C?t.hint:void 0,title:C&&t.hint?t.hint:s(T?"browser.control.handBack":"browser.control.take"),disabled:!u||k==="elsewhere"||k==="connecting"||k==="taking"||k==="waiting",onClick:T?t.onHandBack:t.onTake,className:`flex max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border px-2.5 py-1 text-[11px] disabled:cursor-default ${T?"border-accent-border bg-accent/15 text-accent-text":"border-hairline text-ink-secondary hover:bg-inset hover:text-ink"}`,"data-pill":k,children:[k==="taking"||k==="waiting"||k==="connecting"?n.jsx(Xe,{size:12,className:"shrink-0 animate-spin","aria-hidden":"true"}):n.jsx(Rt,{size:12,className:"shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"truncate",children:mt[k](o)}),k==="bot"||k==="watching"?n.jsxs("span",{className:"shrink-0 text-ink",children:["· ",s("browser.control.take")]}):T?n.jsxs("span",{className:"shrink-0",children:["· ",s("browser.control.handBack")]}):null]}),n.jsx("button",{className:je,title:s(t.maximized?"browser.panel.restore":"browser.panel.maximizeHint"),"aria-label":s(t.maximized?"browser.panel.restore":"browser.panel.maximize"),onClick:t.onMaximize,children:t.maximized?n.jsx(bn,{size:15}):n.jsx(Vt,{size:15})}),n.jsx("button",{className:je,title:s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreenHint"),"aria-label":s(t.fullscreen?"browser.panel.exitFullscreen":"browser.panel.fullscreen"),onClick:t.onFullscreen,children:t.fullscreen?n.jsx(un,{size:15}):n.jsx(dn,{size:15})}),n.jsx("button",{className:`${je} rounded-xl bg-inset p-1.5`,title:s("browser.panel.profileTitle",{name:t.profileName}),"aria-label":s("browser.panel.profiles"),onClick:t.onProfiles,children:n.jsx(ln,{size:15})})]}),n.jsxs("form",{className:"relative flex h-10 items-center gap-1 px-2",onSubmit:j=>{j.preventDefault(),t.onAddress(d),(r&&typeof r=="object"?r.current:null)?.blur()},children:[n.jsxs("div",{className:"flex shrink-0 items-center",role:"group","aria-label":s("browser.panel.navigation"),children:[n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoBack,"aria-label":s("browser.panel.back"),title:s("browser.panel.back"),onClick:()=>t.onCommand({type:"history",delta:-1}),children:n.jsx(qt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m||!c.canGoForward,"aria-label":s("browser.panel.forward"),title:s("browser.panel.forward"),onClick:()=>t.onCommand({type:"history",delta:1}),children:n.jsx(Gt,{size:16})}),n.jsx("button",{type:"button",className:je,disabled:!m,"aria-label":s(c.loading?"browser.panel.loadingReload":"browser.panel.reload"),title:s("browser.panel.reloadShort"),onClick:()=>t.onCommand({type:"reload"}),children:c.loading?n.jsx(Xe,{size:16,className:"animate-spin"}):n.jsx(Xt,{size:16})})]}),n.jsx("input",{ref:r,"aria-label":s("browser.panel.address"),readOnly:!m,value:y?d:b,onChange:j=>g(j.target.value),onFocus:j=>{g(b),E(!0),m&&queueMicrotask(()=>j.target.select())},onBlur:()=>E(!1),onKeyDown:j=>{j.key==="Escape"&&(j.preventDefault(),g(b),j.currentTarget.blur())},placeholder:s(u?"browser.panel.searchOrAddress":"browser.panel.connecting"),spellCheck:!1,className:"mx-1 min-w-0 flex-1 rounded-lg bg-transparent px-2 py-1.5 text-center text-[12px] outline-none placeholder:text-ink-secondary focus:bg-inset focus:text-left"}),t.menu,n.jsx("div",{"aria-hidden":"true","data-loading":c.loading,className:`pointer-events-none absolute bottom-0 left-0 h-0.5 bg-accent transition-[width,opacity] duration-500 ${c.loading?"w-2/3 opacity-100":"w-full opacity-0"}`})]})]})});function gn(e){return Array.isArray(e)?e.flatMap(t=>{const{id:r,name:o}=t??{};return typeof r=="string"&&typeof o=="string"?[{id:r,name:o}]:[]}):[]}const kn="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40";function vn({ready:e,extensions:t,onList:r,onOpen:o}){const i=a.useRef(null);return a.useEffect(()=>{e&&i.current?.open&&r()},[e]),n.jsxs("details",{ref:i,className:"relative shrink-0",onToggle:c=>{c.currentTarget.open&&e&&r()},children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.extensions.title"),title:s("browser.extensions.title"),children:n.jsx(Yt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex max-h-80 w-56 flex-col overflow-y-auto rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.extensions.title")}),e?t&&t.length===0?n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.empty")}):(t??[]).map(c=>n.jsx("button",{type:"button",role:"menuitem",className:kn,onClick:()=>{i.current?.removeAttribute("open"),o(c.id)},children:n.jsx("span",{className:"truncate",children:c.name})},c.id)):n.jsx("div",{className:"px-3 py-1.5 text-ink-secondary",children:s("browser.extensions.takeControl")})]})]})}const _e=[.25,.33,.5,.67,.75,.8,.9,1,1.1,1.25,1.5,1.75,2,2.5,3,4,5];function bt(e,t){return t>0?_e.find(r=>r>e+.001)??_e.at(-1):[..._e].reverse().find(r=>r<e-.001)??_e[0]}const Cn=[{label:"browser.viewport.fill",setting:{mode:"fill"}},{label:"browser.viewport.fullHd",setting:{mode:"preset",preset:"fullHd"}},{label:"browser.viewport.desktop",setting:{mode:"preset",preset:"desktop"}},{label:"browser.viewport.tablet",setting:{mode:"preset",preset:"tablet"}},{label:"browser.viewport.phone",setting:{mode:"preset",preset:"phone"}}],xt=(e,t)=>e.mode===t.mode&&(e.mode!=="preset"||t.mode==="preset"&&e.preset===t.preset),Ae="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left hover:bg-inset disabled:cursor-not-allowed disabled:opacity-40",Qe="rounded-md border border-hairline p-1 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40";function Sn({stream:e,ready:t,typing:r,setting:o,zoom:i,pip:c,onViewport:u,onZoom:w,onPip:v,onType:m,onSecret:d,onReconnect:g,onRestart:y}){const E=a.useRef(null),k=T=>()=>{E.current?.removeAttribute("open"),T()},C=T=>n.jsx("div",{className:"border-b border-hairline/40 py-1 last:border-b-0",children:T});return n.jsxs("details",{ref:E,className:"relative shrink-0",children:[n.jsx("summary",{className:"list-none cursor-pointer rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink [&::-webkit-details-marker]:hidden","aria-label":s("browser.panel.menu"),title:s("browser.panel.menu"),children:n.jsx(Jt,{size:16})}),n.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 flex w-56 flex-col rounded-xl border border-hairline/50 bg-card p-1 text-[12px] text-ink shadow-xl",role:"menu",children:[e?C(n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[11px] text-ink-tertiary",children:s("browser.viewport.title")}),Cn.map(T=>n.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":xt(T.setting,o),className:Ae,disabled:!t,onClick:k(()=>u(T.setting)),children:[n.jsx("span",{className:"w-3.5 shrink-0",children:xt(T.setting,o)?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null}),s(T.label)]},T.label)),n.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[n.jsx("span",{children:s("settings.profile.avatar.zoom")}),n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.out"),disabled:!t||i<=_e[0],onClick:()=>w(bt(i,-1)),children:n.jsx(Zt,{size:12})}),n.jsxs("span",{className:"min-w-11 text-center tabular-nums text-ink-secondary","aria-live":"polite",children:[Math.round(i*100),"%"]}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.in"),disabled:!t||i>=_e.at(-1),onClick:()=>w(bt(i,1)),children:n.jsx(At,{size:12})}),n.jsx("button",{type:"button",className:Qe,"aria-label":s("browser.zoom.reset"),disabled:!t||i===1,onClick:()=>w(1),children:n.jsx(Qt,{size:12})})]})]})]})):null,C(n.jsxs(n.Fragment,{children:[e&&c?n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(v),children:s(c.open?"browser.pip.close":"browser.pip.open")}):null,n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(m),children:s("browser.panel.typeTextMenu")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,disabled:!r,onClick:k(d),children:s("browser.typeSecret")})]})),C(n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(g),children:s("browser.panel.reconnectView")}),n.jsx("button",{type:"button",role:"menuitem",className:Ae,onClick:k(y),children:s("browser.panel.restartBrowser")})]}))]})]})}function jn(e){const[t,r]=a.useState(null);return a.useEffect(()=>{if(!e)return;let o=!0;return Ge("/api/shared-computers").then(i=>{o&&r(i.computers?.find(c=>c.online&&c.scopes?.screen)?.name??null)}).catch(()=>{}),()=>{o=!1}},[e]),t}function En({wall:e,botName:t,onDismiss:r}){const{state:o,dispatch:i}=dt(),c=o.config?.cloudHome===!0,u=jn(c),w=e==="google"?"Google":"Microsoft";return n.jsx("section",{role:"status","aria-label":s("browser.passkey.title"),className:"shrink-0 border-b border-hairline/30 bg-inset/60 px-3 py-2.5 text-[12px] leading-relaxed text-ink-secondary",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(en,{size:14,className:"mt-0.5 shrink-0 text-accent-text","aria-hidden":"true"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"font-medium text-ink",children:s("browser.passkey.title")}),n.jsx("p",{children:s("browser.passkey.body",{provider:w})}),n.jsxs("ol",{className:"mt-1 list-decimal space-y-1 pl-4",children:[n.jsxs("li",{children:[s(e==="google"?"browser.passkey.appsGoogle":"browser.passkey.appsMicrosoft",{name:t})," ",n.jsx("button",{type:"button",className:"text-accent-text underline",onClick:()=>i({type:"togglePlugins",open:!0,surface:"apps"}),children:s("browser.passkey.connect")})]}),n.jsx("li",{children:s(e==="google"?"browser.passkey.otherWayGoogle":"browser.passkey.otherWayMicrosoft")}),c&&n.jsx("li",{children:u?s("browser.passkey.lentPc",{computer:u,name:t}):s("browser.passkey.lendPc",{name:t})})]}),n.jsx("button",{type:"button",className:"mt-1 text-accent-text underline",onClick:()=>{tn(nn)},children:s("browser.passkey.learnMore")})]}),n.jsx("button",{type:"button",className:"rounded-md p-1 text-ink-tertiary hover:bg-inset hover:text-ink","aria-label":s("browser.passkey.dismiss"),onClick:r,children:n.jsx(Ue,{size:14})})]})})}const Nn=4503,Pn=4404,Tn="sudo limixbot browser install --with-deps",Mn="https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox",ft=(e,t)=>{const r=Object.entries(t.query);if(r.length===0)return e;const o=e.includes("?")?"&":"?";return`${e}${o}${new URLSearchParams(r).toString()}`};function Lt(e,t=window.location,r={}){const o=`/api/bots/${encodeURIComponent(e)}/browser`;return{httpBase:`${t.protocol}//${t.host}${o}`,wsBase:`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}${o}`,query:{...r},credentials:!0}}const Rn=e=>e===null||typeof e=="object"&&"type"in e&&typeof e.type=="string"&&"message"in e&&typeof e.message=="string"&&"defaultValue"in e&&typeof e.defaultValue=="string",In=(e,t)=>ft(`${e.access.httpBase}/upload?${new URLSearchParams({chooser:t}).toString()}`,e.access);async function zn(e,t){const r=new FormData;for(const i of t)r.append("file",i,i.name??"file");const o=await fetch(e.uploadUrl,{method:"POST",body:r,credentials:e.credentials?"include":"omit"});if(!o.ok){const i=await o.text();let c=i;try{c=JSON.parse(i).error??i}catch{}throw new Error(c||s("browser.page.uploadRefused"))}}const An=(e,t)=>ft(`${e.access.httpBase}/download/${encodeURIComponent(t)}`,e.access),et=e=>(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0),Ln=(e,t)=>e.type==="takeControl"||e.type==="resize"||e.type==="frameCap"||e.type==="restart"||e.type==="wake"||e.type==="releaseControl"&&t.owned===!0||t.controller==="you",_n=JSON.stringify({type:"ack"});function _t(e,t){let r={width:e.maxWidth,height:e.maxHeight},o=e.width!==void 0&&e.height!==void 0?{width:e.width,height:e.height}:null;const i=()=>{const y=new URLSearchParams({maxWidth:String(Math.max(1,Math.round(r.width))),maxHeight:String(Math.max(1,Math.round(r.height)))});return o&&(y.set("width",String(Math.round(o.width))),y.set("height",String(Math.round(o.height)))),e.interactive===!1&&y.set("interactive","false"),ft(`${e.access.wsBase}/stream?${y.toString()}`,e.access)};let c=!1,u=null,w=null,v=0,m=null,d=null;const g=()=>{if(c)return;const y={cap:r,size:o},E=new WebSocket(i());E.binaryType="arraybuffer",u=E;let k=!1;E.addEventListener("open",()=>{u===E&&(k=!0,t.onConnectedChange(!0))}),E.addEventListener("message",C=>{if(u!==E)return;if(C.data instanceof ArrayBuffer){v=0,E.send(_n),t.onFrame(C.data);return}if(typeof C.data!="string")return;let T;try{T=JSON.parse(C.data)}catch{return}if(typeof T!="object"||T===null)return;const{type:b,x:j,y:O,width:H,height:le,editable:re,canOperate:J,controller:Y,generation:$,dialog:x,stale:K,owned:B,text:V,id:Z,fileName:W,sizeBytes:te,multiple:P,accept:R,phase:D,sequence:U,tabId:q}=T;if(b==="fileChooser"&&typeof Z=="string"&&typeof P=="boolean"&&typeof R=="string")d=Z,t.onFileChooser?.({multiple:P,accept:R,uploadUrl:In(e,Z),credentials:e.access.credentials});else if(b==="fileChooserClosed"&&typeof Z=="string"){if(d!==Z)return;d=null,t.onFileChooser?.(null)}else if(b==="pointer"&&(D==="move"||D==="click")&&typeof j=="number"&&typeof O=="number"&&typeof U=="number")t.onPointer?.({phase:D,x:j,y:O,sequence:U});else if(b==="popup"&&typeof q=="string")t.onPopup?.(q);else if(b==="clipboard"&&typeof V=="string")t.onClipboard?.(V);else if(b==="download"&&typeof Z=="string"&&typeof W=="string"&&typeof te=="number")t.onDownload?.({fileName:W,sizeBytes:te,url:An(e,Z)});else if(b==="viewport"&&typeof H=="number"&&typeof le=="number")v=0,t.onViewport({width:H,height:le}),t.onMessage?.(T);else if(b==="probe"&&typeof j=="number"&&typeof O=="number"&&typeof re=="boolean")t.onProbe?.({x:j,y:O,editable:re});else if(b==="control"&&typeof J=="boolean"&&(Y==="agent"||Y==="you"||Y==="another-viewer"||Y==="unclaimed")&&typeof $=="number"&&Rn(x)){const N={canOperate:J,controller:Y,generation:$,dialog:x,...K===!0?{stale:!0}:{},...B===!0?{owned:!0}:{}},A=m===null;m=N,A&&J&&r!==y.cap&&E.send(JSON.stringify({type:"frameCap",maxWidth:r.width,maxHeight:r.height})),A&&J&&o&&o!==y.size&&E.send(JSON.stringify({type:"resize",...o})),t.onControl?.(N)}else typeof b=="string"&&t.onMessage?.(T)}),E.addEventListener("close",C=>{if(u===E&&(u=null,m=null,k&&t.onConnectedChange(!1),!c)){if(t.onClose?.(C.code,C.reason),C.code===Pn){c=!0,t.onGone?.();return}if(C.code===Nn){c=!0,t.onHostSetup?.(Bn(C.reason));return}if(C.code===1008||C.code===4401||!k&&C.code===1006){c=!0,t.onUnauthorized();return}w=setTimeout(g,Math.min(500*2**v++,1e4))}}),E.addEventListener("error",()=>E.close())};return g(),{send:y=>(y.type==="resize"?o={width:y.width,height:y.height}:y.type==="frameCap"&&(r={width:y.maxWidth,height:y.maxHeight}),u?.readyState!==WebSocket.OPEN||!m?.canOperate||!Ln(y,m)?!1:(u.send(JSON.stringify(y)),!0)),stop:()=>{c=!0,w!==null&&clearTimeout(w);const y=u;u=null,m=null,y?.close()}}}function Bt(e,t){const r=e.getContext("2d");let o=!1,i=!1,c=null;const u=w=>{i=!0,createImageBitmap(new Blob([w],{type:"image/jpeg"})).then(v=>{if(o||!r){v.close();return}(e.width!==v.width||e.height!==v.height)&&(e.width=v.width,e.height=v.height),r.drawImage(v,0,0),v.close(),t?.()}).catch(()=>{}).finally(()=>{i=!1;const v=c;c=null,v&&!o&&u(v)})};return{paint:w=>{o||(i?c=w:u(w))},stop:()=>{o=!0,c=null}}}const Bn=e=>{try{if(JSON.parse(e).need==="libraries")return{need:"libraries",command:Tn}}catch{}return{need:"sandbox"}},On=e=>e.need==="sandbox"?"This server's host blocks the sandbox its browser runs in. An administrator can allow it for one copy of Chrome with these steps, then try again:":"This server's host is missing libraries its browser needs. Run this once on the host, then try again:",Dn=700;function Hn(e,t){return e?1:t==="human"?.18:.35}function Fn({phase:e,sequence:t,left:r,top:o,controller:i}){const[c,u]=a.useState(null),w=c!==t;return a.useEffect(()=>{const v=window.setTimeout(()=>u(t),Dn);return()=>window.clearTimeout(v)},[t]),n.jsxs("div",{className:"pointer-events-none absolute left-0 top-0 z-30 transition-[opacity,transform] duration-150 ease-out motion-reduce:transition-none",style:{opacity:Hn(w,i),transform:`translate3d(${r}px, ${o}px, 0)`},"aria-hidden":"true","data-agent-cursor":!0,children:[e==="click"?n.jsx("span",{className:"absolute left-0.5 top-0.5 size-4 animate-ping rounded-full bg-accent/25 motion-reduce:animate-none"},t):null,n.jsx(hn,{className:"relative size-5 -translate-x-0.5 -translate-y-0.5 fill-card text-accent drop-shadow-sm",strokeWidth:2})]})}function $n({origin:e,realm:t,onAnswer:r}){const o=i=>{i.preventDefault();const c=i.currentTarget,u=c.elements.namedItem("username"),w=c.elements.namedItem("password");r({username:u.value,password:w.value}),u.value="",w.value=""};return n.jsxs("form",{role:"dialog","aria-label":s("browser.auth.label"),onSubmit:o,className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2.5 rounded-xl border border-hairline/60 bg-card p-4 text-ink shadow-xl",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-medium",children:[n.jsx(It,{size:14,"aria-hidden":"true"}),s("browser.auth.signIn")]}),n.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t?s("browser.auth.asks",{origin:e,realm:t}):e}),n.jsx("input",{name:"username","aria-label":s("browser.auth.username"),autoComplete:"off",spellCheck:!1,maxLength:1024,placeholder:s("browser.auth.username"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsx("input",{name:"password",type:"password","aria-label":s("logins.password"),autoComplete:"new-password",maxLength:1024,placeholder:s("logins.password"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:()=>r(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",children:s("common.cancel")}),n.jsx("button",{type:"submit",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",children:s("browser.auth.signIn")})]})]})}function Un({options:e,selectedIndex:t,anchor:r,bounds:o,onChoose:i,onClose:c}){const[u,w]=a.useState(()=>t>=0?t:e.findIndex(b=>!b.disabled)),v=a.useRef(null);a.useEffect(()=>{v.current?.focus({preventScroll:!0})},[]),a.useEffect(()=>{v.current?.querySelector(`[data-index="${u}"]`)?.scrollIntoView?.({block:"nearest"})},[u]);const m=o.height-(r.top+r.height),d=r.top,g=m<160&&d>m,y=Math.max(96,Math.min(320,(g?d:m)-8)),E=Math.max(0,Math.min(r.left,o.width-Math.max(r.width,160))),k=(b,j)=>{for(let O=b+j;O>=0&&O<e.length;O+=j)if(!e[O].disabled)return O;return b},C=b=>{b.key==="ArrowDown"||b.key==="ArrowUp"?(b.preventDefault(),w(j=>k(j,b.key==="ArrowDown"?1:-1))):b.key==="Home"||b.key==="End"?(b.preventDefault(),w(b.key==="Home"?k(-1,1):k(e.length,-1))):b.key==="Enter"||b.key===" "?(b.preventDefault(),e[u]&&!e[u].disabled&&i(u)):(b.key==="Escape"||b.key==="Tab")&&(b.preventDefault(),b.stopPropagation(),c())};let T;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"absolute inset-0 z-30","aria-hidden":"true",onPointerDown:b=>{b.preventDefault(),c()}}),n.jsx("div",{ref:v,role:"listbox","aria-label":s("browser.select.label"),"aria-activedescendant":u>=0?`select-option-${u}`:void 0,tabIndex:0,onKeyDown:C,onBlur:b=>{b.currentTarget.contains(b.relatedTarget)||c()},className:"absolute z-40 overflow-y-auto rounded-lg border border-hairline/60 bg-menu py-1 text-[13px] text-ink shadow-xl outline-none",style:{left:E,minWidth:Math.max(r.width,160),maxHeight:y,...g?{bottom:o.height-r.top+2}:{top:r.top+r.height+2}},children:e.map((b,j)=>{const O=b.group!==void 0&&b.group!==T?b.group:null;return T=b.group,n.jsxs("div",{children:[O!==null?n.jsx("div",{className:"px-3 pb-0.5 pt-1.5 text-[11px] font-medium text-ink-tertiary",role:"presentation",children:O}):null,n.jsxs("div",{id:`select-option-${j}`,"data-index":j,role:"option","aria-selected":j===t,"aria-disabled":b.disabled||void 0,onPointerEnter:()=>{b.disabled||w(j)},onPointerDown:H=>H.preventDefault(),onClick:()=>{b.disabled||i(j)},className:`flex cursor-default items-center gap-2 px-3 py-1.5 ${b.group!==void 0?"pl-5":""} ${b.disabled?"text-ink-tertiary":j===u?"bg-accent text-accent-ink":""}`,children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label||" "}),j===t?n.jsx(Mt,{size:13,"aria-hidden":"true"}):null]})]},j)})})]})}const wt=150,Wn=24,Kn=1e4,$e="​",Vn={key:"Backspace",code:"Backspace",keyCode:8},qn={key:"Delete",code:"Delete",keyCode:46},Gn=8,Xn=500,Yn=4,Jn=16,yt=e=>e===0?"left":e===1?"middle":e===2?"right":"none",gt=e=>e&1?"left":e&2?"right":e&4?"middle":"none",Le=e=>e!==null&&e.canOperate&&e.controller!=="another-viewer";function Ot(e,t){const r=Math.min(e.width/t.width,e.height/t.height),o=t.width*r,i=t.height*r;return{width:o,height:i,left:(e.width-o)/2,top:(e.height-i)/2}}function Zn(e,t,r,o,i,c){const u=Ot(e,t);if(!(u.width>0&&u.height>0))return null;const w=r.width/u.width,v=(o-e.left-u.left)*w,m=(i-e.top-u.top)*(r.height/u.height);return!(v>=0&&m>=0&&v<=r.width&&m<=r.height)&&!c?null:{x:Math.min(Math.max(v,0),r.width),y:Math.min(Math.max(m,0),r.height),scale:w}}function kt(e,t,r,o){const i=Ot(t,r),c=i.width/o.width,u=i.height/o.height;return{left:i.left+e.x*c,top:i.top+e.y*u,width:e.width*c,height:e.height*u}}function Qn(e){const t=document.createElement("a");t.href=e.url,t.download=e.fileName,t.rel="noopener",t.click()}function er(e){const{connect:t,ref:r}=e,o=a.useRef(e);o.current=e;const i=a.useRef(null),c=a.useRef(null),u=a.useRef(!1),w=a.useRef(null),v=a.useRef(null),m=a.useRef(null),d=a.useRef(!1),g=a.useRef(null),[y,E]=a.useState(null),[k,C]=a.useState(!1),[T,b]=a.useState(!1),[j,O]=a.useState(""),[H,le]=a.useState(null),[re,J]=a.useState(null),[Y,$]=a.useState(null),[x,K]=a.useState("default"),[B,V]=a.useState(null),[Z,W]=a.useState([]),[te,P]=a.useState(null),R=a.useRef(0),D=a.useRef(null),U=a.useRef(null),q=a.useRef(null),N=a.useRef(null),A=a.useRef(0),G=a.useRef({left:1,middle:1,right:1,none:1}),ie=a.useRef(null),pe=a.useRef(null),F=a.useRef(null),Ee=a.useRef(null),Oe=a.useRef(null),[We,Ke]=a.useState(!1),Ne=a.useCallback(l=>{const p=++R.current;W(S=>[...S.slice(-2),{...l,id:p}])},[]),ue=l=>W(p=>p.filter(S=>S.id!==l)),Q=a.useCallback(l=>{o.current.input(l)},[]),Re=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null,U.current=q.current=null,A.current=0,G.current={left:1,middle:1,right:1,none:1},ie.current=null,pe.current=F.current=Ee.current=null,u.current=!1,c.current&&(c.current.value=$e)},[]),be=a.useCallback(()=>{N.current!==null&&cancelAnimationFrame(N.current),N.current=null;const l=U.current,p=q.current;U.current=null,q.current=null,l&&Q(l),p&&Q(p)},[Q]),ve=a.useCallback(()=>{N.current??=requestAnimationFrame(be)},[be]),de=a.useCallback((l,p,S,z)=>{const I=q.current;q.current={type:"wheel",x:l.x,y:l.y,deltaX:(I?.deltaX??0)+p,deltaY:(I?.deltaY??0)+S,modifiers:z},ve()},[ve]),he=a.useCallback((l,p,S)=>{const z=i.current,I=v.current;return!z||!I||!d.current||!Le(g.current)?null:Zn(z.getBoundingClientRect(),z,I,l,p,S)},[]),Ie=(l,p,S,z)=>{const I=ie.current,X=I&&I.button===l&&z-I.time<Xn&&Math.hypot(p-I.x,S-I.y)<Yn?I.count+1:1;return ie.current={button:l,time:z,x:p,y:S,count:X},X},ee=()=>c.current?.focus({preventScroll:!0});a.useImperativeHandle(r,()=>({canvas:()=>d.current?i.current:null,focusPage:ee}),[]),a.useEffect(()=>{const l=i.current?.parentElement;if(!l||typeof ResizeObserver>"u")return;let p=null,S=null;const z=()=>{S=null;const f=m.current;if(!f)return;const M=window.devicePixelRatio||1,se=Math.round(f.width*M),ye=Math.round(f.height*M),ae=Oe.current;if(ae!==null&&ae.width>=se&&ae.height>=ye)return;const _={width:Math.max(se,ae?.width??0),height:Math.max(ye,ae?.height??0)};Oe.current=_,ae===null?Ke(!0):w.current?.send({type:"frameCap",maxWidth:_.width,maxHeight:_.height})},I=()=>{p=null;const f=l.getBoundingClientRect();if(f.width<1||f.height<1)return;const M={width:Math.round(f.width),height:Math.round(f.height)},se=m.current;se?.width===M.width&&se.height===M.height||(m.current=M,w.current?.send({type:"resize",...M}),S!==null&&clearTimeout(S),S=setTimeout(z,se===null?0:wt*2))},X=new ResizeObserver(()=>{p===null&&(p=setTimeout(I,m.current===null?0:wt))});return X.observe(l),()=>{X.disconnect(),p!==null&&clearTimeout(p),S!==null&&clearTimeout(S)}},[]),a.useEffect(()=>{const l=i.current,p=m.current,S=Oe.current;if(te||!We||!S||!l||!p)return;d.current=!1,b(!1);const z=Bt(l,()=>{d.current||(d.current=!0,b(!0),o.current.onFirstFrame?.())}),I=f=>{const M=g.current;g.current=f,E(f),o.current.onControl?.(f),(f?.dialog?.message!==M?.dialog?.message||f?.dialog?.defaultValue!==M?.dialog?.defaultValue)&&O(f?.dialog?.defaultValue??""),f?.controller!=="you"?$(null):M?.controller!=="you"&&m.current&&w.current?.send({type:"resize",...m.current}),Le(f)||(Re(),c.current?.blur())},X=t({maxWidth:S.width,maxHeight:S.height,width:p.width,height:p.height},{onFrame:f=>z.paint(f),onProbe:f=>{if(g.current?.controller!=="you")return;Ee.current={...f,at:performance.now()};const M=F.current;!M||M.x!==f.x||M.y!==f.y||(M.editable=f.editable,M.answered=!0,M.tapped&&(F.current=null,f.editable?c.current?.focus({preventScroll:!0}):c.current?.blur()))},onPointer:f=>{const M=i.current,se=v.current;if(!M||!se||M.width<1||M.height<1)return;const ye={width:M.clientWidth,height:M.clientHeight},ae=kt({x:f.x,y:f.y,width:0,height:0},ye,M,se);J({...ae,phase:f.phase,sequence:f.sequence})},onClipboard:f=>{ht(f).then(M=>{M==="failed"&&Ne({kind:"clipboard",text:f})})},onDownload:f=>Ne({kind:"download",download:f}),onPopup:()=>{},onFileChooser:le,onViewport:f=>{v.current=f},onControl:I,onMessage:f=>{if(f.type==="selectPopup"&&typeof f.id=="string"&&Array.isArray(f.options)){const M=f.rect;M&&$({id:f.id,options:f.options,selectedIndex:Number(f.selectedIndex),rect:M})}else f.type==="cursor"&&typeof f.shape=="string"?K(f.shape):f.type==="authPrompt"&&typeof f.tabId=="string"&&typeof f.id=="string"&&typeof f.origin=="string"?V({tabId:f.tabId,id:f.id,origin:f.origin,realm:typeof f.realm=="string"?f.realm:""}):f.type==="authPromptClosed"?V(M=>M&&M.id!==f.id?M:null):f.type==="notice"&&typeof f.message=="string"&&Ne({kind:"error",message:Kt(f,f.message)});o.current.onMessage?.(f)},onConnectedChange:f=>{C(f),o.current.onConnectedChange?.(f),!f&&(le(null),$(null),V(null),I(null))},onHostSetup:P,onUnauthorized:()=>o.current.onUnauthorized?.(),onGone:()=>o.current.onGone?.(),onClose:(f,M)=>o.current.onClose?.(f,M)});return w.current=X,o.current.onClient?.(X),()=>{z.stop(),X.stop(),w.current===X&&(w.current=null),o.current.onClient?.(null),I(null),C(!1),J(null),Re()}},[We,Re,t,te,Ne]),a.useEffect(()=>{const l=i.current;if(!l)return;const p=S=>{const z=he(S.clientX,S.clientY,!1);if(!z)return;S.preventDefault();const I=S.deltaMode===WheelEvent.DOM_DELTA_LINE?Jn:S.deltaMode===WheelEvent.DOM_DELTA_PAGE?v.current?.height??0:1;de(z,S.deltaX*I,S.deltaY*I,et(S))};return l.addEventListener("wheel",p,{passive:!1}),()=>l.removeEventListener("wheel",p)},[he,de]),a.useEffect(()=>()=>{N.current!==null&&cancelAnimationFrame(N.current)},[]);const Ce=l=>{if(!Le(g.current))return;const{type:p,pointerId:S,clientX:z,clientY:I}=l,X=p==="pointercancel",f=pe.current;if(X&&f?.pointerId===S){pe.current=F.current=null;return}if(l.pointerType==="touch"&&!X){const _=he(z,I,p==="pointermove");if(p==="pointerdown"){if(!l.isPrimary)return;pe.current={pointerId:S,startX:z,startY:I,lastX:z,lastY:I,panning:!1};const Se=Ee.current,Te=_&&Se&&performance.now()-Se.at<Kn&&Math.hypot(_.x-Se.x,_.y-Se.y)<Wn;F.current=_?{x:_.x,y:_.y,editable:Te?Se.editable:null,answered:!1,tapped:!1}:null,_&&Q({type:"probe",x:_.x,y:_.y});return}if(!f||f.pointerId!==S)return;if(p==="pointermove"){if(!f.panning&&Math.hypot(z-f.startX,I-f.startY)<Gn)return;f.panning=!0,_&&de(_,(f.lastX-z)*_.scale,(f.lastY-I)*_.scale,0),f.lastX=z,f.lastY=I;return}pe.current=null;const oe=F.current;if(f.panning){F.current=null;return}if(!_)return;oe?.editable===!0?ee():oe?.editable===!1&&c.current?.blur(),oe&&!oe.answered?oe.tapped=!0:F.current=null,be();const ge=Ie("left",z,I,l.timeStamp),ne={x:_.x,y:_.y,modifiers:0};Q({type:"mouse",action:"move",...ne,button:"none",buttons:0,clickCount:0}),Q({type:"mouse",action:"down",...ne,button:"left",buttons:1,clickCount:ge}),Q({type:"mouse",action:"up",...ne,button:"left",buttons:0,clickCount:ge});return}const M=A.current;if((X||p==="pointerup")&&M===0)return;(X||p==="pointerup")&&(A.current=X?0:l.buttons&7);const se=he(z,I,p!=="pointerdown"&&(X||p==="pointerup"||M!==0||l.buttons!==0));if(!se)return;const ye={x:se.x,y:se.y,modifiers:et(l)},ae=(_,oe,ge)=>{_==="down"&&(G.current[oe]=Ie(oe,z,I,l.timeStamp)),Q({type:"mouse",action:_,...ye,button:oe,buttons:ge,clickCount:G.current[oe]})};if(p==="pointerdown")ee(),l.currentTarget.setPointerCapture(S),be(),A.current=l.buttons&7,ae("down",yt(l.button),l.buttons);else if(p==="pointerup")be(),ae("up",yt(l.button),l.buttons);else{const _=X?0:l.buttons&7,oe=M^_;if(M!==0&&oe!==0){be();let ge=M;for(const ne of[1,2,4])oe&ne&&(ge^=ne,ae(_&ne?"down":"up",gt(ne),ge));A.current=_}if(X)return;U.current={type:"mouse",action:"move",...ye,button:gt(l.buttons),buttons:l.buttons,clickCount:0},ve()}},ze=l=>{u.current=!1,l.value=$e,l.setSelectionRange($e.length,$e.length)},De=l=>{Q({type:"key",action:"down",...l,modifiers:0}),Q({type:"key",action:"up",...l,modifiers:0})},He=(l,p)=>{if(!Le(g.current)||(u.current=!1,p.nativeEvent.isComposing||p.keyCode===229||p.key==="Process"||p.key==="Unidentified"))return;if(p.key==="Escape"&&p.shiftKey){p.preventDefault(),p.stopPropagation(),l==="down"&&(p.currentTarget.blur(),o.current.onLeave?.());return}const S=p.ctrlKey||p.metaKey;if(S&&p.key.toLowerCase()==="v"||p.shiftKey&&p.key==="Insert")return;const z=S?void 0:[...p.key].length===1?p.key:p.key==="Enter"?"\r":void 0;Q({type:"key",action:l,key:p.key,code:p.code,keyCode:p.keyCode,...l==="down"&&z!==void 0?{text:z}:{},modifiers:et(p)}),u.current=l==="down"&&!S&&(z!==void 0||p.key==="Backspace"||p.key==="Delete"),!S&&(p.preventDefault(),p.stopPropagation())},Fe=l=>{const p=l.nativeEvent;if(p instanceof InputEvent&&p.isComposing)return;const S=l.currentTarget,z=p instanceof InputEvent?p.inputType:"";if(u.current)u.current=!1;else if(z==="deleteContentBackward")De(Vn);else if(z==="deleteContentForward")De(qn);else{const I=S.value.replace(/^​/,"");I&&Q({type:"text",text:I})}ze(S)},xe=l=>{const p=H;p&&(le(null),zn(p,l).catch(S=>Ne({kind:"error",message:s("browser.page.uploadFailed",{error:S instanceof Error?S.message:String(S)})})))},me=l=>w.current?.send(l),ce=i.current,we=Y&&ce&&v.current&&ce.width>0?kt(Y.rect,{width:ce.clientWidth,height:ce.clientHeight},ce,v.current):null,Pe=y?.controller==="you";return n.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden ${e.className??""}`,"data-browser-surface":!0,children:[n.jsxs("div",{className:"relative min-h-0 flex-1",children:[n.jsx("canvas",{ref:i,"aria-hidden":"true",className:"block size-full touch-none object-contain",style:{cursor:Le(y)?Pe?x:"default":"not-allowed"},onPointerDown:Ce,onPointerMove:Ce,onPointerUp:Ce,onPointerCancel:Ce,onMouseDown:l=>l.preventDefault(),onContextMenu:l=>l.preventDefault()}),re&&!Pe?n.jsx(Fn,{...re,controller:y?.controller==="agent"?"agent":"none"}):null,n.jsx("textarea",{ref:c,"aria-label":e.label??s("browser.page.label"),"aria-description":s("browser.page.keysHint"),"aria-keyshortcuts":"Shift+Escape",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:!Le(y),defaultValue:$e,onFocus:l=>ze(l.currentTarget),className:"sr-only left-0 top-0 text-base",onKeyDown:l=>He("down",l),onKeyUp:l=>He("up",l),onInput:Fe,onCompositionEnd:l=>{const p=l.data.replace(/^​/,"");p&&Q({type:"text",text:p}),ze(l.currentTarget)},onCopy:l=>l.preventDefault(),onCut:l=>l.preventDefault(),onPaste:l=>{l.preventDefault();const p=l.clipboardData.getData("text/plain");p&&Q({type:"text",text:p})}}),k&&!T&&!te?n.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center text-ink-secondary","aria-hidden":"true",children:n.jsx(Xe,{size:22,className:"animate-spin"})}):null,Y&&we&&ce?n.jsx(Un,{options:Y.options,selectedIndex:Y.selectedIndex,anchor:we,bounds:{width:ce.clientWidth,height:ce.clientHeight},onChoose:l=>{me({type:"selectChoose",id:Y.id,index:l}),$(null),ee()},onClose:()=>{$(null),ee()}},Y.id):null,H&&Pe?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.page.chooseFilesLabel"),children:[n.jsxs("p",{className:"flex items-center gap-2 text-[13px]",children:[n.jsx(fn,{size:14,"aria-hidden":"true"}),s(H.multiple?"browser.page.asksFiles":"browser.page.asksFile")]}),n.jsx("input",{ref:D,type:"file",className:"hidden",multiple:H.multiple,accept:H.accept,onChange:l=>{const p=[...l.currentTarget.files??[]];l.currentTarget.value="",p.length>0&&xe(p)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>xe([]),children:s("common.cancel")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>D.current?.click(),children:s(H.multiple?"browser.page.chooseFiles":"browser.page.chooseFile")})]})]}):null,y?.dialog&&y.controller!=="another-viewer"?n.jsxs("div",{className:"absolute inset-x-3 top-3 z-20 mx-auto flex max-w-sm flex-col gap-2 rounded-xl border border-hairline/60 bg-card p-3 text-ink shadow-xl",role:"dialog","aria-label":s("browser.dialog.label"),children:[n.jsx("p",{className:"break-words text-[13px]",children:y.dialog.message}),Pe?n.jsxs(n.Fragment,{children:[y.dialog.type==="prompt"?n.jsx("input",{"aria-label":s("browser.dialog.response"),value:j,onChange:l=>O(l.target.value),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"}):null,n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-inset",onClick:()=>me({type:"dialog",accept:!1}),children:s("browser.dialog.dismiss")}),n.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] text-accent-ink",onClick:()=>me({type:"dialog",accept:!0,...y.dialog?.type==="prompt"?{promptText:j}:{}}),children:s("browser.dialog.accept")})]})]}):n.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("browser.dialog.takeControl")})]}):null,B&&Pe?n.jsx($n,{origin:B.origin,realm:B.realm,onAnswer:l=>{const p={tabId:B.tabId,id:B.id};me(l?{type:"authAnswer",...p,username:l.username,password:l.password}:{type:"authAnswer",...p}),V(null)}}):null,Z.length?n.jsx("div",{className:"absolute inset-x-3 bottom-3 z-20 flex flex-col items-center gap-2",role:"status",children:Z.map(l=>n.jsxs("div",{className:"flex max-w-full items-center gap-2 rounded-xl border border-hairline/60 bg-card px-3 py-2 text-[12px] text-ink shadow-lg",children:[l.kind==="download"?n.jsxs(n.Fragment,{children:[n.jsx(rn,{size:13,"aria-hidden":"true",className:"shrink-0"}),n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.downloaded",{name:l.download.fileName})}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{Qn(l.download),ue(l.id)},children:s("common.save")})]}):l.kind==="clipboard"?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"min-w-0 truncate",children:s("browser.notice.copied")}),n.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-accent-ink",onClick:()=>{ht(l.text),ue(l.id)},children:s("common.copy")})]}):n.jsx("span",{role:"alert",className:"min-w-0 text-danger",children:l.message}),n.jsx("button",{type:"button","aria-label":s("browser.dialog.dismiss"),className:"shrink-0 rounded-md p-0.5 text-ink-secondary hover:bg-inset",onClick:()=>ue(l.id),children:n.jsx(Ue,{size:12})})]},l.id))}):null]}),te?n.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center",children:[n.jsx("p",{role:"alert",className:"max-w-sm text-[13px] text-ink-secondary",children:On(te)}),te.need==="libraries"?n.jsx("code",{className:"max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink",children:te.command}):n.jsx("a",{href:Mn,target:"_blank",rel:"noopener noreferrer",className:"text-[12px] text-ink underline",children:"Browser sandbox setup steps"}),n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:()=>P(null),children:s("common.tryAgain")})]}):null]})}const tr=8e3,nr=300,rr=2e4,sr=16,Dt=new Set(["Alt","Control","Meta","Shift"]),or=new Set(["Backspace","Enter","Tab","Escape","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]),qe=new Set(["navigate","history","reload","tabSelect","tabNew","tabClose"]),ar=new Set(["navigate","tabNew"]);function tt(e){return qe.has(e.type)?!0:e.type==="mouse"?e.action==="down":e.type==="key"?e.action==="down"&&!Dt.has(e.key):e.type==="wheel"||e.type==="text"}const nt=e=>e.type==="key"?`key:${e.code||e.key}`:e.type==="mouse"?`mouse:${e.button}`:e.type,vt=e=>(e.type==="key"||e.type==="mouse")&&e.action==="down",Ct=e=>(e.type==="key"||e.type==="mouse")&&e.action==="up";function lr(e){return e.type!=="key"||Dt.has(e.key)?!0:or.has(e.key)?!1:!e.modifiers||e.modifiers===8&&[...e.key].length===1}function ir(e){const t=e.transport;let r="bot",o="",i=[],c=!1,u=!1,w=!1,v=!1,m=!1,d=!1,g=0,y=Promise.resolve(),E,k;const C=new Set,T=new Set,b=x=>{o=x,e.onTakeStatus(x)},j=x=>{vt(x)&&lr(x)?C.add(nt(x)):Ct(x)&&C.delete(nt(x))},O=()=>!u&&!w&&(m||!v)&&!c&&!C.size&&(r==="held"||r==="bot"&&e.owned()),H=()=>{clearTimeout(E),E=u?void 0:setTimeout(()=>{E=void 0,re()},m?0:tr)},le=()=>{r="releasing",o==="stale"&&b(""),y=y.then(()=>u?void 0:t.release()).catch(()=>{}).then(()=>{r==="releasing"&&(r="bot")})},re=async()=>{if(!O())return;const x=g;await t.drain(),x===g&&O()&&le()},J=()=>{const x=i.filter(B=>ar.has(B.type)),K=i.some(B=>!x.includes(B)&&tt(B));i=x;for(const B of C)T.add(B);return C.clear(),K},Y=async()=>{c=!0;try{for(let x=i.shift();x&&!u;x=i.shift())t.send(x),t.size()>=sr&&await t.settle()}finally{c=!1,i=[]}},$=()=>{r="taking",e.onError(""),b("pending"),clearTimeout(k),k=setTimeout(()=>{!u&&r==="taking"&&b("slow")},nr),y=y.then(async()=>{if(u)return;const x=await t.take().then(K=>({reply:K}),K=>(u||e.onError(K instanceof Error?K.message:String(K)),null));clearTimeout(k),!u&&(x?(r="held",b(x.reply?.waited===!0&&J()?"stale":""),await Y()):(b(""),r="bot",i=[],C.clear()),H())}).catch(()=>{})};return{interact(x){if(u)return;const K=nt(x);if(Ct(x)&&T.delete(K))return;vt(x)&&T.delete(K);const B=r==="taking"||c;if(r!=="held"&&!B){if(!tt(x))return;if(t.stopped()&&!qe.has(x.type)){e.onHalted();return}}if(!(qe.has(x.type)&&B&&i.some(V=>qe.has(V.type)))){if(tt(x)&&(m=!1,o==="stale"&&b("")),j(x),g++,H(),r==="held"&&!B){t.send(x);return}i.push(x),B||$()}},observe(){if(u)return;const x=e.owned();d&&!x&&r==="held"&&!c&&(r="bot",C.clear(),T.clear(),clearTimeout(E),E=void 0),d=x,E===void 0&&x&&H()},takeControl(){u||r==="held"||r==="taking"||c||(m=!1,$())},keep(x){u||v===x||(v=x,x||H())},handBack(){if(!u){if(r==="bot"&&!e.owned()&&e.mine?.()){le();return}m=!0,H()}},hold(x){u||w===x||(w=x,x||H())},leave(){!O()||t.size()||(r="releasing",t.release().catch(()=>{}))},close(){u=!0,clearTimeout(E),clearTimeout(k),i=[],C.clear(),T.clear()}}}function cr(e,t,r){return{send:o=>{e.send(o)},drain:async()=>{},settle:async()=>{},size:()=>0,stopped:()=>!1,take:()=>new Promise((o,i)=>{const c=t.current();if(c?.controller==="you"){o({waited:!1});return}if(!e.send({type:"takeControl"})){i(new Error(s("browser.panel.notConnected")));return}const u=c?.controller==="agent",w=d=>{clearTimeout(v),m(),d()},v=setTimeout(()=>w(()=>i(new Error(s("browser.panel.takeFailed")))),rr),m=t.watch(d=>{d?.controller==="you"?w(()=>o({waited:u})):d?.controller==="another-viewer"?w(()=>i(new Error(r))):d===null&&w(()=>i(new Error(s("browser.panel.viewDisconnected"))))})}),release:async()=>{e.send({type:"releaseControl"})}}}const ur="https://duckduckgo.com/?q=",dr=/^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i,fr=/^[^/?#:@]+:\d+(?:[/?#]|$)/,pr=/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\])(?::|\/|$)/i,hr=new Set(["about:","blob:","chrome:","data:","file:","ftp:","javascript:","mailto:","sms:","ssh:","tel:","view-source:","ws:","wss:"]);function mr(e){return/^([A-Za-z][A-Za-z\d+.-]*):/.exec(e)?.[1]?.toLowerCase().concat(":")}function rt(e){const t=e.includes("://")?e:`${pr.test(e)?"http":"https"}://${e}`;try{const r=new URL(t);return r.protocol==="http:"||r.protocol==="https:"?r.href:null}catch{return null}}function br(e){const t=e.trim();if(!t)return null;if(/^[a-z][a-z\d+.-]*:\/\//i.test(t))return rt(t);if(!/\s/.test(t)){const r=mr(t);if(r!==void 0&&(hr.has(r)||!fr.test(t)))return r==="http:"||r==="https:"?rt(t):null;const o=(t.split(/[/?#]/,1)[0]??"").replace(/^[^@]*@/,""),i=o.replace(/:\d+$/,"");if(i.length<o.length||dr.test(i)||/^[^.]+(?:\.[^.]+)+\.?$/.test(i)){const u=rt(t);if(u)return u}}return`${ur}${encodeURIComponent(t)}`}const xr=5;let Be=null;const it=new Set,Ht=()=>{for(const e of it)e()},wr=e=>(it.add(e),()=>it.delete(e));function yr(){if(typeof document>"u"||typeof HTMLCanvasElement.prototype.captureStream!="function")return!1;const e=HTMLVideoElement.prototype;return document.pictureInPictureEnabled&&typeof e.requestPictureInPicture=="function"||typeof e.webkitSetPresentationMode=="function"}function gr(){return a.useSyncExternalStore(wr,()=>Be?.key??null,()=>null)}function ct(){const e=Be;Be=null,e?.stop(),Ht()}async function kr(e){ct();const t=document.createElement("canvas"),r=t.getContext("2d"),o=e.seed&&e.seed.width>0&&e.seed.height>0?e.seed:null;t.width=o?.width??640,t.height=o?.height??400;const i=t.captureStream();o?r?.drawImage(o,0,0):r?.fillRect(0,0,t.width,t.height);const c=document.createElement("video");c.muted=!0,c.playsInline=!0,c.srcObject=i,c.style.cssText="position:fixed;right:0;bottom:0;width:1px;height:1px;opacity:0;pointer-events:none",document.body.append(c);const u=Bt(t);let w=null,v=!1,m=0,d=null;const g=()=>{Be===k&&ct()},y=()=>{v||(w=_t({access:Lt(e.botId),maxWidth:1280,maxHeight:1280,interactive:!1},{onFrame:C=>{m=0,u.paint(C)},onViewport:()=>{},onConnectedChange:()=>{},onUnauthorized:()=>{if(!v){if(m>=xr){g();return}d=setTimeout(y,1e3*2**m++)}},onGone:g}))},E=()=>{c.webkitPresentationMode!=="picture-in-picture"&&g()},k={key:e.botId,stop:()=>{v=!0,d!==null&&clearTimeout(d),w?.stop(),u.stop(),c.removeEventListener("leavepictureinpicture",g),c.removeEventListener("webkitpresentationmodechanged",E),document.pictureInPictureElement===c?document.exitPictureInPicture().catch(()=>{}):c.webkitPresentationMode==="picture-in-picture"&&c.webkitSetPresentationMode?.("inline");for(const C of i.getTracks())C.stop();c.srcObject=null,c.remove()}};Be=k,Ht();try{await c.play(),c.readyState<HTMLMediaElement.HAVE_METADATA&&await new Promise(C=>c.addEventListener("loadedmetadata",C,{once:!0})),document.pictureInPictureEnabled&&typeof c.requestPictureInPicture=="function"?(c.addEventListener("leavepictureinpicture",g),await c.requestPictureInPicture()):(c.addEventListener("webkitpresentationmodechanged",E),c.webkitSetPresentationMode?.("picture-in-picture"))}catch(C){throw g(),C}Be===k&&y()}const vr=[1e3,2e3,4e3,8e3,15e3],Cr=25e3,Sr=5e3,St=32,jt=4096,jr=24e3,Me=(e,t,r)=>Math.max(t,Math.min(r,Number.isFinite(e)?e:0)),Ye=e=>Me(e,-1e4,1e4);function Er(e,t,r,o){const i=t*r/e;return Math.abs(i-o)<=Math.max(1,r/e)?{width:r,height:o}:{width:r,height:Math.round(i)}}function Nr(e){for(let t=2;t+9<e.length;){if(e[t]!==255)return null;const r=e[t+1];if(r>=192&&r<=194)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8]};t+=2+(e[t+2]<<8|e[t+3])}return null}function Et(e){switch(e.type){case"mouse":return{type:"input_mouse",eventType:e.action==="down"?"mousePressed":e.action==="up"?"mouseReleased":"mouseMoved",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:e.button,clickCount:Math.round(Me(e.clickCount,0,3)),modifiers:e.modifiers};case"wheel":return{type:"input_mouse",eventType:"mouseWheel",x:Me(e.x,0,8192),y:Me(e.y,0,8192),button:"none",deltaX:Ye(e.deltaX),deltaY:Ye(e.deltaY),modifiers:e.modifiers};case"key":return e.key?{type:"input_keyboard",eventType:e.action==="up"?"keyUp":"keyDown",key:e.key.slice(0,64),code:e.code.slice(0,64),windowsVirtualKeyCode:Math.round(Me(e.keyCode??0,0,255)),modifiers:e.modifiers,...e.text!==void 0?{text:e.text}:{}}:null;case"text":{const t=[];for(let r=0;r<e.text.length;r+=jt)t.push({type:"input_keyboard",eventType:"char",text:e.text.slice(r,r+jt)});return t}case"navigate":return{type:"navigate",url:e.url};case"history":return{type:e.delta<0?"back":"forward"};case"reload":return{type:"reload"};case"tabSelect":return{type:"tab-select",tabId:e.tabId};case"tabClose":return{type:"tab-close",tabId:e.tabId};case"tabNew":return e.url?{type:"tab-new",url:e.url}:{type:"tab-new"};case"restart":return{type:"restart"};case"dialog":return{type:"dialog",accept:e.accept,...e.promptText!==void 0?{promptText:e.promptText.slice(0,4096)}:{}};default:return null}}const Ve=e=>e.type==="input_mouse"&&(e.eventType==="mouseMoved"||e.eventType==="mouseWheel"),ut=e=>e.type==="input_mouse"||e.type==="input_keyboard",Ft=e=>e.type==="input_mouse"&&e.eventType==="mouseReleased"||e.type==="input_keyboard"&&e.eventType==="keyUp",st=e=>Ft(e)||!ut(e);function Pr(e,t,r=()=>1){let o=[],i=null,c=0,u=!1;const w=d=>{o=o.filter(st),u||(u=!0,t(d))},v=()=>{const d=[o.shift()],g=u?1:r();let y=JSON.stringify(d[0]).length;for(;ut(d[0])&&d.length<g&&o.length&&ut(o[0]);){const E=JSON.stringify(o[0]).length;if(y+E>jr)break;y+=E,d.push(o.shift())}return d},m=()=>{if(i||!o.length)return;const d=c;i=(async()=>{for(;d===c&&o.length;){const g=v();try{await e(g.length===1?g[0]:{type:"input_batch",events:g})}catch(y){if(d!==c)continue;g.length>1&&o.unshift(...g.slice(1).filter(Ft)),w(y)}}})().finally(()=>{i=null,m()})};return{enqueue(d){if(u&&!st(d))return;const g=o.at(-1);if(g&&Ve(d)&&g.type===d.type&&g.eventType===d.eventType&&g.modifiers===d.modifiers&&g.button===d.button){o[o.length-1]=d.eventType==="mouseWheel"?{...d,deltaX:Ye(Number(g.deltaX??0)+Number(d.deltaX??0)),deltaY:Ye(Number(g.deltaY??0)+Number(d.deltaY??0))}:{...d};return}if(o.length>=St){if(Ve(d))return;const y=o.findIndex(Ve);if(y>=0)o.splice(y,1);else if(w(new Error(s("browser.input.tooSlow"))),!st(d)||o.length>=St)return}o.push({...d}),m()},async drain(){for(o=o.filter(d=>!Ve(d));i||o.length;)m(),await i},async settle(){for(;i||o.length;)m(),await i},size:()=>o.length+(i?1:0),stopped:()=>u,clear(){c++,o=[],u=!1}}}function Nt(e,t){const r=e.owned===!0?e.controlling===!0?"you":"agent":e.held===!0?"another-viewer":"unclaimed",o=e.dialog,i=o&&typeof o.type=="string"&&typeof o.message=="string"&&typeof o.defaultValue=="string"?{type:o.type,message:o.message,defaultValue:o.defaultValue}:null;return{canOperate:!0,controller:r,generation:t,dialog:i,...e.owned===!0?{owned:!0}:{}}}function Tr(e,t,r,o={viewer:""},i={},c=null){let u=!1,w=!1,v=!1,m=null,d="",g=0,y=0,E=0,k=null,C=null,T=null,b=1,j=c,O=null;const H=(P,R)=>{P.close(),m=null;const D=d!=="";if(D&&(o.viewer=d),d="",k=null,$.clear(),D&&t.onConnectedChange(!1),u)return;const U=R?vr[y++]:void 0;if(U===void 0){u=!0,w=R,t.onGone?.();return}T=setTimeout(K,U)},le=(P,R)=>P?.status!==404||!m||!R||d!==R?!1:(H(m,!0),!0),re=(P,R)=>r(P,R).catch(D=>{throw le(D,R),D}),J=P=>t.onMessage?.({type:"notice",message:P}),Y=P=>{const R=P?.notice;typeof R=="string"&&R&&J(R)},$=Pr(P=>d?re(P,d).then(Y):Promise.reject(new Error(s("browser.panel.connectionFirst"))),P=>{J(P instanceof Error?P.message:String(P))},()=>b),x=()=>{const P=j,R=d;O||!P||!R||(O=P,r({type:"resize",width:Math.round(P.width),height:Math.round(P.height)},R).catch(()=>{}).finally(()=>{O=null,j!==P&&d===R&&x()}))},K=()=>{if(T=null,u)return;const P=new URLSearchParams(o.viewer?{resume:o.viewer}:{}),R=j;j&&(P.set("width",String(Math.round(j.width))),P.set("height",String(Math.round(j.height))));const D=zt(P.size?`?${P.toString()}`:"",i),U=new EventSource(`/api/bots/${encodeURIComponent(e)}/browser/live${D}`);m=U,g=Date.now();const q=(N,A)=>U.addEventListener(N,G=>{if(m===U){g=Date.now();try{A(JSON.parse(G.data))}catch{}}});q("waiting",()=>t.onMessage?.({type:"starting"})),q("ready",N=>{typeof N.viewerId!="string"||!N.viewerId||(d=N.viewerId,b=Number.isSafeInteger(N.inputBatch)?Math.max(1,Math.min(Number(N.inputBatch),64)):1,o.viewer="",t.onConnectedChange(!0),j!==R&&x())}),q("heartbeat",()=>{y=0}),q("frame",N=>{if(!d||typeof N.data!="string"||typeof N.seq!="number")return;const A=atob(N.data),G=new Uint8Array(A.length);for(let F=0;F<A.length;F++)G[F]=A.charCodeAt(F);const ie=N.metadata??{},pe=Nr(G);if(pe&&ie.deviceWidth&&ie.deviceHeight){const F=Er(pe.width,pe.height,ie.deviceWidth,ie.deviceHeight);(F.width!==C?.width||F.height!==C.height)&&(C=F,t.onViewport(F))}t.onFrame(G.buffer),r({type:"ack",seq:N.seq},d).catch(()=>{})}),q("tabs",N=>{Array.isArray(N.tabs)&&t.onMessage?.({type:"tabs",tabs:N.tabs})}),q("url",N=>{typeof N.url=="string"&&t.onMessage?.({type:"url",url:N.url})}),q("status",N=>{C||!(Number(N.viewportWidth)>0&&Number(N.viewportHeight)>0)||(C={width:Number(N.viewportWidth),height:Number(N.viewportHeight)},t.onViewport(C))}),q("control",N=>{const A=Nt(N,E);k&&A.controller===k.controller&&A.owned===k.owned&&JSON.stringify(A.dialog)===JSON.stringify(k.dialog)||(k=A.controller===k?.controller?A:Nt(N,++E),t.onControl?.(k))}),U.addEventListener("error",N=>{if(m!==U)return;let A=!(N instanceof MessageEvent);if(N instanceof MessageEvent)try{const G=JSON.parse(N.data);A=G.retryable===!0,G.asleep===!0?t.onMessage?.({type:"asleep"}):typeof G.message=="string"&&t.onMessage?.({type:"notice",message:G.message,...typeof G.errorKey=="string"?{errorKey:G.errorKey,...G.errorParams!==void 0?{errorParams:G.errorParams}:{}}:{}})}catch{}H(U,A)})};K();const B=P=>{v||(m&&d&&Date.now()-g>Cr&&H(m,!0),!(!P||T===null&&!(u&&w))&&(T!==null&&clearTimeout(T),u=!1,w=!1,y=0,K()))},V=()=>{document.visibilityState!=="hidden"&&B(!0)},Z=setInterval(()=>B(!1),Sr),W=typeof window>"u"?null:window;return W?.addEventListener("focus",V),W?.addEventListener("online",V),W&&document.addEventListener("visibilitychange",V),{send:P=>{if(P.type==="resize")return j={width:P.width,height:P.height},x(),!0;if(!d||!k?.canOperate||!["takeControl","restart"].includes(P.type)&&k.controller!=="you")return!1;const R=Et(P);if(!R)return!1;if(P.type==="dialog"&&!Array.isArray(R))return re(R,d).catch(D=>J(D instanceof Error?D.message:String(D))),!0;for(const D of Array.isArray(R)?R:[R])$.enqueue(D);return!0},stop:()=>{u=!0,v=!0,clearInterval(Z),W?.removeEventListener("focus",V),W?.removeEventListener("online",V),W&&document.removeEventListener("visibilitychange",V),T!==null&&clearTimeout(T),m?.close(),m=null,d&&(o.viewer=d),d="",$.clear()},transport:{send:P=>{const R=d?Et(P):null;if(R)for(const D of Array.isArray(R)?R:[R])$.enqueue(D)},drain:()=>$.drain(),settle:()=>$.settle(),size:()=>$.size(),stopped:()=>$.stopped(),take:async()=>{if(!d)throw new Error(s("browser.panel.notConnected"));return{waited:(await re({type:"take"},d))?.waited===!0}},release:async()=>{d&&await re({type:"release"},d)}}}}const ot="Another window or device controls this browser. Hand control back there to use it here.",Mr=/^\/(?:v\d+\/)?signin\/(?:v\d+\/)?challenge\/(?:pk|sk)(?:\/|$)/u;function Rr(e){let t;try{t=new URL(e)}catch{return null}return t.hostname==="accounts.google.com"&&Mr.test(t.pathname)?"google":null}const Pt="rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed",at={url:"",loading:!1,canGoBack:!1,canGoForward:!1};function Ir(e){return Array.isArray(e)?e.flatMap(t=>t&&typeof t=="object"&&typeof t.tabId=="string"?[{tabId:t.tabId,title:typeof t.title=="string"?t.title:"",url:typeof t.url=="string"?t.url:"",active:t.active===!0}]:[]):[]}function zr({bot:e,signIn:t,page:r}){const{state:o}=dt(),[i,c]=a.useState(!1),u=o.config?.browserEngine?.engine==="chrome"&&!i,[w,v]=a.useState(0),[m,d]=a.useState(!1),[g,y]=a.useState(null),[E,k]=a.useState([]),[C,T]=a.useState(at),[b,j]=a.useState({mode:"fill"}),[O,H]=a.useState(1),[le,re]=a.useState(null),[J,Y]=a.useState(""),[$,x]=a.useState(""),[K,B]=a.useState(!1),[V,Z]=a.useState(!1),[W,te]=a.useState(""),[P,R]=a.useState(!1),[D,U]=a.useState(!1),[q,N]=a.useState(!1),[A,G]=a.useState(!1),[ie,pe]=a.useState(!1),[F,Ee]=a.useState(!1),[Oe,We]=a.useState(""),Ke=gr(),Ne=xn(),ue=a.useRef(null),Q=a.useRef(null),Re=a.useRef(null),be=a.useRef(null),ve=a.useRef(null),de=a.useRef(null),he=a.useRef(null),Ie=a.useRef(new Set),ee=a.useRef(null),Ce=a.useRef({key:"",viewer:""}),ze=a.useRef(!1),De=a.useRef(0),He=a.useRef(0),Fe=a.useRef(null),xe=a.useRef(null),me=a.useRef({openSignInPage:()=>{},takeControl:()=>{}}),ce=o.computerControl?.[e.id]?.help?.place==="browser",we=on(o.config?.team,e.threadId).threadId;ze.current=P||ce;const Pe=e.browserProfile==="guest"?s("browser.panel.temporary"):o.config?.browserProfiles?.find(h=>h.id===e.browserProfile)?.name??s("browser.panel.ownBrowser",{name:e.name});a.useEffect(()=>{D?be.current?.showModal():be.current?.close()},[D]),a.useEffect(()=>{ee.current?.hold(q),q?ve.current?.showModal():ve.current?.close()},[q]);const l=a.useCallback(()=>{Z(!1),x(""),c(!1),v(h=>h+1)},[]);a.useEffect(()=>{c(!1)},[e.id,e.browserProfile,we]),a.useEffect(()=>{k([]),re(null),T(u?at:{...at,canGoBack:!0,canGoForward:!0}),B(!1),Z(!1),te(""),xe.current=null},[e.id,e.browserProfile,we,w,u]);const p=a.useCallback((h,L)=>{const fe=we?{threadId:we}:{};if(u)return _t({access:Lt(e.id,window.location,fe),...h},L);const ke=`${e.id}
2
2
  ${e.browserProfile??""}${we?`
3
3
  ${we}`:""}`;return Ce.current.key!==ke&&(Ce.current={key:ke,viewer:""}),Tr(e.id,L,(Ut,Wt)=>Ge(zt(`/api/bots/${encodeURIComponent(e.id)}/browser/action`,fe),{method:"POST",body:JSON.stringify({...Ut,viewerId:Wt}),timeoutMs:12e4}),Ce.current,fe,{width:h.width,height:h.height})},[e.id,e.browserProfile,we,u]),S=a.useCallback(h=>{if(he.current?.controller==="another-viewer"){x(ot);return}ee.current?.interact(h)},[]),z=a.useCallback(h=>{if(de.current=h,ee.current?.close(),ee.current=null,!h)return;const L="transport"in h?h.transport:cr(h,{current:()=>he.current,watch:ke=>(Ie.current.add(ke),()=>{Ie.current.delete(ke)})},ot),fe=ir({transport:L,owned:()=>he.current?.controller==="you",mine:()=>he.current?.owned===!0,onTakeStatus:Y,onError:x,onHalted:()=>x(s("browser.input.tooSlow"))});fe.keep(ze.current),ee.current=fe},[]),I=a.useCallback(h=>{const L=he.current;he.current=h,y(h),L?.controller==="you"&&h?.controller!=="you"&&R(!1),h===null&&Y("");for(const fe of Ie.current)fe(h);ee.current?.observe()},[]),X=a.useCallback(h=>{if(h.type==="tabs"){const L=Ir(h.tabs);k(L);const fe=L.find(ke=>ke.active);fe&&(T(ke=>({...ke,url:fe.url})),xe.current=fe.url,me.current.openSignInPage())}else if(h.type==="nav"&&typeof h.url=="string")T({url:h.url,loading:h.loading===!0,canGoBack:h.canGoBack===!0,canGoForward:h.canGoForward===!0}),xe.current=h.url,me.current.openSignInPage();else if(h.type==="url"&&typeof h.url=="string")T(L=>({...L,url:h.url})),xe.current=h.url,me.current.openSignInPage();else if(h.type==="extensions")re(gn(h.extensions));else if(h.type==="viewport"){const L=h.setting;L&&(L.mode==="fill"||L.mode==="preset")&&j(L),typeof h.zoom=="number"&&H(h.zoom)}else h.type==="starting"?B(!0):(h.type==="asleep"||h.type==="awake")&&te(h.type==="asleep"?"asleep":"")},[]);a.useEffect(()=>{ee.current?.keep(P||ce)},[P,ce]);const f=()=>{R(!0),ee.current?.keep(!0),ee.current?.takeControl()},M=()=>{R(!1),ee.current?.handBack()},se=()=>{const h=Fe.current;!h||xe.current===null||(Fe.current=null,(!xe.current||xe.current==="about:blank")&&S({type:"navigate",url:h}))};me.current={openSignInPage:se,takeControl:f},a.useEffect(()=>{!t||!m||De.current===t.nonce||(De.current=t.nonce,Fe.current=t.url,me.current.takeControl(),me.current.openSignInPage())},[t,m]),a.useEffect(()=>{if(!(!r||!m||He.current===r.nonce)){if(W){W==="asleep"&&de.current?.send({type:"wake"})&&te("waking");return}He.current=r.nonce,S({type:"tabNew",url:r.url})}},[r,m,W,S]),a.useEffect(()=>{const h=()=>pe(!!ue.current&&document.fullscreenElement===ue.current);return document.addEventListener("fullscreenchange",h),()=>document.removeEventListener("fullscreenchange",h)},[]);const ye=()=>{const h=!!ue.current&&document.fullscreenElement===ue.current;h&&F&&Ee(!1),(h?document.exitFullscreen():ue.current?.requestFullscreen())?.catch(()=>x(s(h?"browser.panel.exitFullscreenFailed":"browser.panel.fullscreenUnavailable")))},ae=()=>{ie&&document.fullscreenElement===ue.current&&document.exitFullscreen().catch(()=>{}),Ee(h=>!h)};a.useEffect(()=>{if(!F)return;const h=L=>{L.key!=="Escape"||L.defaultPrevented||(L.preventDefault(),ie&&document.fullscreenElement===ue.current&&document.exitFullscreen().catch(()=>{}),Ee(!1))};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[F,ie]);const _=()=>{window.confirm(s("browser.panel.confirmRestart"))&&(x(""),de.current?.send({type:"restart"})||x(s("browser.panel.notConnected")))},oe=()=>{m&&de.current?.send({type:"wake"})?te("waking"):l()},ge=()=>{if(Ke===e.id){ct();return}kr({botId:e.id,seed:Re.current?.canvas()??null}).catch(()=>x(s("browser.panel.pipUnavailable")))},ne=g?.controller==="another-viewer",Se=m&&!ne,Te=g?.controller==="you",Je=Ne||Te;a.useEffect(()=>{Je||(d(!1),x(""))},[Je]);const Ze=m&&Te,$t=u&&yr(),pt=Rr(C.url);return n.jsxs("div",{ref:ue,className:F?"fixed inset-0 z-50 flex flex-col overflow-hidden bg-card text-ink":"flex min-h-0 flex-1 flex-col overflow-hidden rounded-2xl border border-hairline/40 bg-card text-ink","data-browser-transport":u?"stream":"live",children:[n.jsx(yn,{ref:Q,botName:e.name,tabs:E,nav:C,connected:m,control:g,takeStatus:J,hint:s(P||ce?"browser.control.keptHint":"browser.control.yoursHint",{name:e.name}),commandsReady:Se,profileName:Pe,fullscreen:ie,maximized:F,onCommand:S,onAddress:h=>{const L=br(h);Se&&L?S({type:"navigate",url:L}):h.trim()&&x(s("browser.panel.enterAddress"))},onTake:f,onHandBack:M,onFullscreen:ye,onMaximize:ae,onProfiles:()=>{ee.current?.handBack(),U(!0)},menu:n.jsxs(n.Fragment,{children:[u?n.jsx(vn,{ready:m&&Te,extensions:le,onList:()=>de.current?.send({type:"extensions"}),onOpen:h=>de.current?.send({type:"openExtension",id:h})}):null,n.jsx(Sn,{stream:u,ready:m&&Te,typing:Ze,setting:b,zoom:O,pip:$t?{open:Ke===e.id}:null,onViewport:h=>de.current?.send({type:"viewport",setting:h}),onZoom:h=>de.current?.send({type:"zoom",factor:h}),onPip:ge,onType:()=>{G(!1),N(!0)},onSecret:()=>{G(!0),N(!0)},onReconnect:l,onRestart:_})]})}),$&&n.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-2 border-b border-hairline/30 px-3 py-2 text-[12px] text-danger",children:[n.jsx("span",{children:$}),!m&&n.jsx("button",{className:"shrink-0 underline",onClick:l,children:s("browser.panel.reconnect")})]}),J==="stale"&&n.jsx("div",{role:"status",className:"shrink-0 border-b border-hairline/30 px-3 py-1.5 text-[12px] text-accent-text",children:s("browser.control.stale",{name:e.name})}),pt&&Oe!==C.url&&n.jsx(En,{wall:pt,botName:e.name,onDismiss:()=>We(C.url)}),n.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col bg-inset/40",children:[Je?n.jsx(er,{ref:Re,connect:p,input:S,label:s("browser.panel.pageLabel",{name:e.name}),onClient:z,onControl:I,onMessage:X,onConnectedChange:h=>{d(h),h&&(B(!1),Z(!1),x(""))},onFirstFrame:()=>B(!1),onUnauthorized:()=>{u?c(!0):Z(!0)},onGone:()=>Z(!0),onClose:(h,L)=>{h===1013&&L&&x(L)},onLeave:()=>Q.current?.focus()},`${w}:${u?"stream":"live"}:${e.browserProfile??""}`):null,W||ne||V||!m||K?n.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-card/95 p-6 text-center text-[13px] text-ink-secondary",children:[W?n.jsx(cn,{size:24}):ne?n.jsx(Rt,{size:24}):V?n.jsx(lt,{size:24}):n.jsx(Xe,{size:24,className:"animate-spin"}),n.jsx("span",{children:W?s("browser.panel.asleep"):ne?ot:V?s("browser.panel.disconnected"):K?u?s("browser.panel.starting"):s("browser.live.botBusy",{name:e.name}):s("browser.panel.opening")}),W?n.jsx("button",{type:"button",disabled:W==="waking",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset disabled:opacity-60",onClick:oe,children:s(W==="waking"?"browser.panel.waking":"browser.panel.wake")}):V?n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset",onClick:l,children:s("browser.panel.reconnect")}):null]}):null]}),n.jsxs("dialog",{ref:be,onClose:()=>U(!1),onClick:h=>{h.target===h.currentTarget&&U(!1)},className:"m-auto w-[min(420px,calc(100%-32px))] max-h-[80vh] overflow-auto rounded-2xl border border-hairline/50 bg-card p-5 text-ink shadow-2xl backdrop:bg-black/40",children:[n.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[n.jsx("h2",{className:"text-[15px] font-medium",children:s("browser.panel.profiles")}),n.jsx("button",{className:Pt,"aria-label":s("browser.panel.closeProfiles"),onClick:()=>U(!1),children:n.jsx(Ue,{size:16})})]}),(ne||Te&&J!=="")&&n.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s(ne?"browser.profiles.heldElsewhere":"browser.profiles.busy")}),n.jsx(an,{bot:e,disabled:ne||J==="pending"||J==="slow",onProfileChanged:()=>{U(!1),l()}})]}),n.jsxs("dialog",{ref:ve,onClose:()=>{const h=ve.current?.querySelector("input");h&&(h.value=""),N(!1)},className:"m-auto w-[min(420px,calc(100%-32px))] rounded-2xl border border-hairline/50 bg-card p-5 text-ink shadow-2xl backdrop:bg-black/40",children:[n.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[n.jsx("h2",{className:"text-[14px] font-medium",children:A?s("browser.typeSecret.title"):s("browser.panel.typeTextTitle")}),n.jsx("button",{className:Pt,"aria-label":s("browser.panel.closeTyping"),onClick:()=>N(!1),children:n.jsx(Ue,{size:16})})]}),n.jsxs("form",{className:"flex flex-col gap-3",onSubmit:h=>{h.preventDefault();const L=h.currentTarget.elements.namedItem("pageText");Ze&&L.value&&(S({type:"text",text:L.value}),L.value="",N(!1))},children:[n.jsx("input",{name:"pageText",type:A?"password":"text","aria-label":A?s("browser.typeSecret.field"):s("browser.panel.typeTextField"),autoComplete:A?"new-password":"off",spellCheck:!1,maxLength:4096,placeholder:A?"••••••••":s("browser.panel.typeTextPlaceholder"),className:"rounded-lg bg-inset px-3 py-2 text-[13px] outline-none focus:ring-1 focus:ring-accent"},A?"secret":"text"),A&&n.jsxs("p",{className:"flex items-center gap-1 text-[12px] text-ink-tertiary",children:[n.jsx(It,{size:11,"aria-hidden":"true"}),s("browser.typeSecret.note")]}),n.jsx("button",{disabled:!Ze,className:"self-end rounded-lg bg-accent px-4 py-2 text-[12px] text-accent-ink disabled:opacity-40",children:s("browser.panel.typeButton")})]})]})]})}function Hr({bot:e,signIn:t,page:r}){const{state:o}=dt(),i=o.config?.browserEngine,[c,u]=a.useState(!1),[w,v]=a.useState(null),[m,d]=a.useState(null);a.useEffect(()=>{let E=!0;return Ge("/api/auth/session").then(k=>{E&&d(k.scopes.includes("admin"))}).catch(()=>{E&&d(!1)}),()=>{E=!1}},[]);const g=c||i?.installing===!0,y=async()=>{v(null),u(!0);try{await Ge("/api/browser-engine/install",{method:"POST"})}catch(E){v(E instanceof Error?E.message:String(E))}finally{u(!1)}};return e.browser===!1?n.jsx("div",{className:"p-5 text-[13px] text-ink-secondary",children:s("browser.panel.enableBot")}):i?.kind==="engine"&&!g&&!i.installError?n.jsx(zr,{bot:e,signIn:t,page:r},e.id):n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-start justify-center gap-3 rounded-xl bg-card p-5",children:[n.jsx("div",{className:"text-[15px] font-medium text-ink",children:i?.kind==="engine"?s("browser.panel.installIncomplete"):s("browser.panel.engineNotInstalled")}),n.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:i?.kind==="engine"?s("browser.panel.installIncompleteHelp"):i?.installable&&m!==!1?s("browser.panel.engineNotInstalledHelp",{name:e.name}):sn(o.config)}),i?.installable||i?.kind==="engine"?n.jsx("button",{type:"button",onClick:()=>{y()},disabled:g||m!==!0,className:"rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-60",children:g?s("browser.panel.installing"):i?.kind==="engine"?s("browser.panel.retryInstall"):s("browser.panel.installEngine")}):null,(i?.installError||w)&&n.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:w??i?.installError})]})}export{Hr as B,xn as u};