openmausbot 0.1.99 → 0.1.100

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 (87) hide show
  1. package/dist/assets/{ActivityPanel-CgUgtumZ.js → ActivityPanel-CA9zfl3_.js} +1 -1
  2. package/dist/assets/{BotSettingsDialog-lJj6oiir.js → BotSettingsDialog-3i_izROu.js} +1 -1
  3. package/dist/assets/{CloudBackendPicker-C5-_arUz.js → CloudBackendPicker-BR42-xBg.js} +1 -1
  4. package/dist/assets/{ComputerPanel-euJ2CSlH.js → ComputerPanel-CvThnFmt.js} +1 -1
  5. package/dist/assets/{DesktopViewer-XCln1Pn_.js → DesktopViewer-CqovWUic.js} +1 -1
  6. package/dist/assets/{InspectorPanel-DKYyQZlo.js → InspectorPanel-Cbjm86gt.js} +1 -1
  7. package/dist/assets/{KeyboardShortcutsModal-DkkZWZRI.js → KeyboardShortcutsModal-X13pVrkh.js} +1 -1
  8. package/dist/assets/{LocalVmWorkspace-Cwt3_XSx.js → LocalVmWorkspace-BGD3Tvd3.js} +1 -1
  9. package/dist/assets/{MacLocalControl-B28RbdCS.js → MacLocalControl-ExdXHVUv.js} +1 -1
  10. package/dist/assets/{NewBotDialog-dMWDs5xm.js → NewBotDialog-ftDBMjWR.js} +1 -1
  11. package/dist/assets/{RemoteAgentSettingsPanel-B5KWXnqH.js → RemoteAgentSettingsPanel-BUHLV_vC.js} +1 -1
  12. package/dist/assets/{RoutinesPage-DOosRYDK.js → RoutinesPage-Buk5-r3o.js} +1 -1
  13. package/dist/assets/{RoutinesSection-uOfOTfkB.js → RoutinesSection-NyReOXr8.js} +1 -1
  14. package/dist/assets/{SettingsModal-BTGkFbj1.js → SettingsModal-DkkhdxKM.js} +1 -1
  15. package/dist/assets/{TeamMapPage-DqNdJn96.js → TeamMapPage-BIxeHoy3.js} +1 -1
  16. package/dist/assets/{TriggersPanel-c6xkG9mi.js → TriggersPanel-m5iqc43H.js} +1 -1
  17. package/dist/assets/{VisibilitySection-DD4ffIR5.js → VisibilitySection-y8Adk-c4.js} +1 -1
  18. package/dist/assets/{WebhooksPanel-Cz17K-_O.js → WebhooksPanel-G_NWjHOP.js} +1 -1
  19. package/dist/assets/{abnfDiagram-O67JEVCF-CX6tDpkg.js → abnfDiagram-O67JEVCF-D56ZgyPf.js} +1 -1
  20. package/dist/assets/{activity-BAVWO0Zj.js → activity-D_puBfZo.js} +1 -1
  21. package/dist/assets/{arc-h45-9NFk.js → arc-DzduGHbq.js} +1 -1
  22. package/dist/assets/{architectureDiagram-NJMV4G6O-CgLFXbg6.js → architectureDiagram-NJMV4G6O-C4NS6DQF.js} +1 -1
  23. package/dist/assets/{blockDiagram-BEXU5L5S-DGDFFc9M.js → blockDiagram-BEXU5L5S-BNvsskiE.js} +1 -1
  24. package/dist/assets/{brain-CeCdoTb2.js → brain-oq48IgWl.js} +1 -1
  25. package/dist/assets/{c4Diagram-YGBWAQC7-B9aklAUj.js → c4Diagram-YGBWAQC7-ch3B7xZy.js} +1 -1
  26. package/dist/assets/channel-CmFDMHrN.js +1 -0
  27. package/dist/assets/{chunk-2Q5K7J3B-BC0KmWsM.js → chunk-2Q5K7J3B-D9dL9ZS7.js} +1 -1
  28. package/dist/assets/{chunk-3FUC2YCW-BbDFHsJ1.js → chunk-3FUC2YCW-DmLUUuNr.js} +2 -2
  29. package/dist/assets/{chunk-5VM5RSS4-DtGbsjOM.js → chunk-5VM5RSS4-B90ODeo2.js} +1 -1
  30. package/dist/assets/{chunk-GTNCS2PH-VMghMcEl.js → chunk-GTNCS2PH-BtlGIG3W.js} +1 -1
  31. package/dist/assets/{chunk-GWA4HPMP-BP_JyGWQ.js → chunk-GWA4HPMP-CurBwFFG.js} +1 -1
  32. package/dist/assets/{chunk-JWPE2WC7-CYFyzgAU.js → chunk-JWPE2WC7-DTjNNXcd.js} +1 -1
  33. package/dist/assets/{chunk-NETBCI7D-DBNa_kqm.js → chunk-NETBCI7D-xS7hOqBJ.js} +1 -1
  34. package/dist/assets/{chunk-WEXAMYUT-BKEeM7CJ.js → chunk-WEXAMYUT-DJZBSyA9.js} +1 -1
  35. package/dist/assets/{chunk-XXDRQBXY-C__m3ZXl.js → chunk-XXDRQBXY-CbiNRzjt.js} +1 -1
  36. package/dist/assets/{classDiagram-v2-NBCMYWYE-CBUrTSAX.js → classDiagram-v2-NBCMYWYE-DyON9tUb.js} +1 -1
  37. package/dist/assets/{core-6lvx-ypA.js → core-CRkAXD3N.js} +1 -1
  38. package/dist/assets/{cose-bilkent-JH36ORCC-GRfL-1Vb.js → cose-bilkent-JH36ORCC-C7UwNnp8.js} +1 -1
  39. package/dist/assets/{cynefin-OW5HDTMX-LopwGUjm.js → cynefin-OW5HDTMX-Dv1GTekc.js} +1 -1
  40. package/dist/assets/{cynefinDiagram-VND7K2PF-DSB8ZRNS.js → cynefinDiagram-VND7K2PF-CKgpyZxo.js} +1 -1
  41. package/dist/assets/{dagre-6A5THRUB-DL3Kgdfk.js → dagre-6A5THRUB-BY3cYc8R.js} +1 -1
  42. package/dist/assets/{diagram-22UHCM2B-DIxN34BM.js → diagram-22UHCM2B-D71jBFCO.js} +1 -1
  43. package/dist/assets/{diagram-3UASUU5V-CJnSvXaI.js → diagram-3UASUU5V-Bc3i6JGD.js} +1 -1
  44. package/dist/assets/{diagram-ATOU4E4O-C-XF-lO8.js → diagram-ATOU4E4O-BPDSHISG.js} +1 -1
  45. package/dist/assets/{diagram-CDSNMT55-Df2yZPi_.js → diagram-CDSNMT55-xuCT1v32.js} +1 -1
  46. package/dist/assets/{diagram-MLGK6HIB-BBs9oZFs.js → diagram-MLGK6HIB-LEDTXDPg.js} +1 -1
  47. package/dist/assets/{diagram-MPIPVDR6-CEbK11mM.js → diagram-MPIPVDR6-B0kfscRD.js} +1 -1
  48. package/dist/assets/{ebnfDiagram-ZINNZB2B-BNq6Yv3C.js → ebnfDiagram-ZINNZB2B-B-Z0HLzJ.js} +1 -1
  49. package/dist/assets/{elk-276RUBZZ-CFbQ2bGm.js → elk-276RUBZZ-Bzypn7lU.js} +1 -1
  50. package/dist/assets/{erDiagram-OPXOYQCR-Bz8vmjN4.js → erDiagram-OPXOYQCR-vl1xKmbS.js} +1 -1
  51. package/dist/assets/{flowDiagram-KWPJA3E3-cQUfEYrx.js → flowDiagram-KWPJA3E3-DQXCXm7z.js} +1 -1
  52. package/dist/assets/{ganttDiagram-FUAMR5RP-BY8n9tbI.js → ganttDiagram-FUAMR5RP-B0wwnP2j.js} +1 -1
  53. package/dist/assets/{gitGraphDiagram-X574FWY7-KduSOMDN.js → gitGraphDiagram-X574FWY7-HfEVZRuR.js} +1 -1
  54. package/dist/assets/{image-plus-DNIWU160.js → image-plus-D9o3v9bi.js} +1 -1
  55. package/dist/assets/{index-C8xb62XS.js → index-CyM91z0J.js} +111 -111
  56. package/dist/assets/{infoDiagram-VRGFBTTK-xBKgUkpL.js → infoDiagram-VRGFBTTK-BcCklxlu.js} +1 -1
  57. package/dist/assets/{ishikawaDiagram-OU5B5YK6-_ei09tAJ.js → ishikawaDiagram-OU5B5YK6-Bw7Fp8yZ.js} +1 -1
  58. package/dist/assets/{journeyDiagram-ZHPQQLJL-Fp49MkSp.js → journeyDiagram-ZHPQQLJL-BqFaTPiB.js} +1 -1
  59. package/dist/assets/{kanban-definition-PNTS6WVX-CY9lLm7V.js → kanban-definition-PNTS6WVX-BdGyimUh.js} +1 -1
  60. package/dist/assets/{linear-D2ai4eM2.js → linear-DezKjgv7.js} +1 -1
  61. package/dist/assets/{mermaid.core-DP6qPqu1.js → mermaid.core-97L7xtx0.js} +5 -5
  62. package/dist/assets/{mindmap-definition-NLK3R4M7-g1ynEw_d.js → mindmap-definition-NLK3R4M7-DP6qz87C.js} +1 -1
  63. package/dist/assets/{page-visible-BZn8304W.js → page-visible-BehtKJDm.js} +1 -1
  64. package/dist/assets/{pegDiagram-GJSIUBJH-Bt4ObsZj.js → pegDiagram-GJSIUBJH-CsYSloVz.js} +1 -1
  65. package/dist/assets/{pieDiagram-5QR66LMP-CeLld8bY.js → pieDiagram-5QR66LMP-CFI2Dcix.js} +1 -1
  66. package/dist/assets/{quadrantDiagram-O4NWA36T-D4WWZw3x.js → quadrantDiagram-O4NWA36T-DqTdAE5z.js} +1 -1
  67. package/dist/assets/{railroadDiagram-XR7U4H2S-D95P5NqU.js → railroadDiagram-XR7U4H2S-t_rszRIF.js} +1 -1
  68. package/dist/assets/{remote-desktop-panel-DOIMmT4T.js → remote-desktop-panel-WTaz_HI9.js} +1 -1
  69. package/dist/assets/{requirementDiagram-PLB6GJNP-D12p3RhR.js → requirementDiagram-PLB6GJNP-1MU-l7p8.js} +1 -1
  70. package/dist/assets/{sankeyDiagram-IPEJSGJF-Co26Dwcs.js → sankeyDiagram-IPEJSGJF-CtkrwAvo.js} +1 -1
  71. package/dist/assets/{sequenceDiagram-PO4LG4MO-y5YxaDKt.js → sequenceDiagram-PO4LG4MO-CJOwBubv.js} +1 -1
  72. package/dist/assets/{sizeCapture-INFHLROL-D49hZ8U5.js → sizeCapture-INFHLROL-DhQVhKCc.js} +1 -1
  73. package/dist/assets/{stateDiagram-v2-GCMORJYK-C0sylr-r.js → stateDiagram-v2-GCMORJYK-CaQK9yA9.js} +1 -1
  74. package/dist/assets/{swimlanes-2SLR337P-DmRWsDIs.js → swimlanes-2SLR337P-Ct8cqf01.js} +1 -1
  75. package/dist/assets/swimlanesDiagram-TC7HE7FX-BBUcFKOA.js +8 -0
  76. package/dist/assets/{timeline-definition-EJHVYXUP-DVmHYs3w.js → timeline-definition-EJHVYXUP-qim2Km3q.js} +1 -1
  77. package/dist/assets/{usecaseDiagram-POWQR4AR-BQ1q0VV6.js → usecaseDiagram-POWQR4AR-BIzcxmgX.js} +1 -1
  78. package/dist/assets/{user-B9lohN4n.js → user-EQ8rI0f4.js} +1 -1
  79. package/dist/assets/{vennDiagram-UO4OBE2U-C_cnfST0.js → vennDiagram-UO4OBE2U-BFEuz8Ba.js} +1 -1
  80. package/dist/assets/{wardleyDiagram-VNRHLVJA-Bb3BSu12.js → wardleyDiagram-VNRHLVJA-JRkAN01c.js} +1 -1
  81. package/dist/assets/{xychartDiagram-PMCCYNJV-CcwEuuEi.js → xychartDiagram-PMCCYNJV-WBsvmu0R.js} +1 -1
  82. package/dist/index.html +1 -1
  83. package/dist-server/index.js +9 -6
  84. package/dist-server/server/mcp-probe.js +18 -10
  85. package/package.json +1 -1
  86. package/dist/assets/channel-TsOXCiPg.js +0 -1
  87. package/dist/assets/swimlanesDiagram-TC7HE7FX-DzhbBHtd.js +0 -8
@@ -1,4 +1,4 @@
1
- import{m as Ne,u as K,r,j as e,t,cj as te,v as Y,ck as L,c as _,d as H,p as oe,E as Ze,g as U,aJ as sn,aW as ds,P as Te,R as xe,cl as Re,aM as Ge,cm as nn,cn as an,co as rn,cp as ln,as as on,cq as At,cr as $e,cs as us,ct as cn,cu as dn,cv as un,cw as It,cx as xn,a9 as pn,O as ke,a4 as mn,bf as gn,T as we,w as mt,cy as hn,cz as xs,cA as fn,cB as Ye,cC as bn,ag as Pt,cD as yn,bc as vn,cE as jn,cF as Rt,cG as kn,au as ps,cH as ms,cI as Nn,av as wn,a6 as Sn,cJ as Cn,X as De,y as En,b0 as le,b1 as ue,q as An,cK as gs,aa as In,aw as Pn,x as ut,cL as hs,cM as fs,cN as bs,bi as Rn,cO as Bn,bI as Dn,cP as Tn,cQ as ze,ax as zn,cR as Mn,cS as On,cT as Un,cU as ys,aY as vs,aZ as je,a_ as Be,aX as Ln,cV as _n,B as Fn,a$ as Bt,b2 as $n,S as js,cW as Kn,cX as Hn,cY as Vn,cZ as Wn,c_ as qn,c$ as Jn,at as Gn,d0 as Dt,d1 as Yn,d2 as Xn,d3 as Tt,ba as ks,aj as Qn,d4 as Zn,d5 as ea,Z as ta,aG as sa,bZ as ot,M as Ns,d6 as na,aF as aa,d7 as ia,b$ as zt,d8 as ra,o as la,aQ as oa,d9 as ca,da,db as ua,dc as xa,br as ws,bq as pa,be as ma,b_ as ga,bB as ha,dd as fa,de as ba,df as ya,dg as va,dh as ja,di as ka,dj as Na,dk as wa,dl as Sa,dm as Ca,dn as Ea,dp as Aa,dq as Ia,dr as Pa,ds as Ra,dt as Ba,du as Da,dv as Ta,dw as za,dx as Ma,dy as Oa,dz as Ua,dA as La,dB as _a,dC as Fa,dD as $a,dE as Ka,dF as Ha,dG as Va,dH as Wa,dI as qa}from"./index-C8xb62XS.js";import{a as Ja,M as Ga,w as Ya,A as me,b as Xa,O as Qa,V as Za,c as ei,B as ti}from"./MacLocalControl-B28RbdCS.js";import{a as si,A as ni,w as ai,d as ii,b as Mt}from"./activity-BAVWO0Zj.js";import{b as ri}from"./RoutinesPage-DOosRYDK.js";import{DefaultBotSettings as li}from"./NewBotDialog-dMWDs5xm.js";import{U as xt,C as oi}from"./user-B9lohN4n.js";import"./WebhooksPanel-Cz17K-_O.js";import"./VisibilitySection-DD4ffIR5.js";import"./image-plus-DNIWU160.js";import"./CloudBackendPicker-C5-_arUz.js";const ci=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]],di=Ne("circle-user",ci);const ui=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],xi=Ne("hard-drive",ui);const pi=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ss=Ne("palette",pi);const mi=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],gi=Ne("scroll-text",mi);const hi=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],fi=Ne("server",hi);const bi=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],yi=Ne("terminal",bi);const vi=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],ji=Ne("unplug",vi),ki="https://typesafe.ai",Ni={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},Ot={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"};function wi(s,n=!1){if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Ot[s.reason])return t(Ot[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const a=Ni[s.reason];return a?t(a):t("decider.error.other")}const Si=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Ci(){const{state:s,dispatch:n}=K(),a=s.config?.decider,i=a?.configured??!1,o=i&&a?.included===!0,l=i&&!o,d=a?.enabled??!1,u=a?.jobs.roomRouting??!0,[c,x]=r.useState(""),[m,g]=r.useState(!1),[p,y]=r.useState(!1),[k,N]=r.useState(!1),[v,j]=r.useState(null),[C,w]=r.useState(null),D=c.trim(),I=!D&&l,f=A=>n({type:"configStatus",config:A}),b=async A=>{if(!p){y(!0),j(null);try{f(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:A})}))}catch(P){j(P instanceof Error?P.message:String(P))}finally{y(!1)}}},h=async()=>{if(!(m||!D&&!l)){g(!0),j(null),w(null);try{const A=window.ogb?.setCredential?await window.ogb.setCredential("jevApiKey",D):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{key:D}})});f(A),x("")}catch(A){j(A instanceof Error?A.message:String(A))}finally{g(!1)}}},E=async()=>{if(k||m||!D&&!i)return;N(!0),w(null),j(null);const A=!D&&o;try{const P=await U("/api/decider/test",{method:"POST",body:JSON.stringify(D?{key:D}:{})});w(P.ok?{ok:!0,text:t("decider.test.ok",{ms:String(P.latencyMs)})}:{ok:!1,text:wi(P,A)})}catch(P){w({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("div",{children:e.jsx(te,{title:t("decider.master"),subtitle:i?void 0:t("decider.masterNeedsKey"),children:e.jsx(Y,{"data-testid":"decider-master","aria-label":t("decider.master"),checked:d,disabled:!i||p||!s.config,onClick:()=>{b({enabled:!d})},className:"cursor-pointer"})})}),e.jsxs(L,{title:t("decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:_("size-1.5 rounded-full",i?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:i?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):i?t("decider.status.connected"):t("decider.status.notConnected")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:c,onChange:A=>{w(null),j(null),x(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void h(),disabled:m,placeholder:l?t("keys.replace"):t("decider.key.placeholder"),"aria-label":t("decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{h()},disabled:m||!D&&!l,title:I?t("keys.removeKey"):t("common.save"),className:_("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",I?"text-danger":"text-ink"),children:m?e.jsx(H,{size:13,className:"animate-spin"}):I?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{E()},disabled:k||m||!D&&!i,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:k?t("keys.testing"):t("keys.test")})]}),v&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:v}),C&&e.jsx("p",{role:"status",className:_("mt-1 text-[12px]",C.ok?"text-success":"text-danger"),children:C.text}),e.jsxs("a",{href:ki,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.key.getKey"),e.jsx(Ze,{size:11,"aria-hidden":"true"})]})]}),e.jsx(L,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(Y,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:d&&u,disabled:!d||p,onClick:()=>{b({jobs:{roomRouting:!u}})},className:"cursor-pointer"})]}),Si.map(A=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(A)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},A))]})})]})}const Cs=["openai","anthropic","google","azure","aws","xai","deepseek","meta","mistral","qwen","moonshot","cohere","openrouter"],Es=128*1024,fe=1024,As=["image/png","image/jpeg","image/webp"],Ei={openai:"OpenAI",anthropic:"Anthropic",google:"Google Gemini",azure:"Microsoft Azure",aws:"Amazon Bedrock (AWS)",xai:"xAI",deepseek:"DeepSeek",meta:"Meta",mistral:"Mistral AI",qwen:"Qwen",moonshot:"Moonshot AI",cohere:"Cohere",openrouter:"OpenRouter"};function Ai(s){const n=s.endsWith("==")?2:s.endsWith("=")?1:0;return Math.floor(s.length*3/4)-n}function Ii(s,n){const a=c=>s[c]*256+s[c+1],i=c=>s[c]+s[c+1]*256,o=c=>s[c]+s[c+1]*256+s[c+2]*65536,l=c=>s[c]+s[c+1]*256+s[c+2]*65536+s[c+3]*16777216,d=c=>s[c]*16777216+s[c+1]*65536+s[c+2]*256+s[c+3];if(n==="image/png")return s.length<33||s.slice(0,8).join(",")!=="137,80,78,71,13,10,26,10"||String.fromCharCode(...s.slice(12,16))!=="IHDR"||s.slice(-8).join(",")!=="73,69,78,68,174,66,96,130"?null:{width:d(16),height:d(20)};if(n==="image/jpeg"){if(s.length<12||s[0]!==255||s[1]!==216||s.at(-2)!==255||s.at(-1)!==217)return null;for(let c=2;c+8<s.length;){if(s[c]!==255){c+=1;continue}const x=s[c+1];if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(x))return{height:a(c+5),width:a(c+7)};if(x===216||x===217||x===1||x>=208&&x<=215){c+=2;continue}const m=a(c+2);if(m<2)return null;c+=m+2}return null}if(s.length<30||String.fromCharCode(...s.slice(0,4))!=="RIFF"||String.fromCharCode(...s.slice(8,12))!=="WEBP"||l(4)+8!==s.length)return null;const u=String.fromCharCode(...s.slice(12,16));if(u==="VP8X")return{width:o(24)+1,height:o(27)+1};if(u==="VP8L"&&s[20]===47){const c=s[21]|s[22]<<8|s[23]<<16|s[24]<<24;return{width:(c&16383)+1,height:(c>>>14&16383)+1}}return u==="VP8 "&&s[23]===157&&s[24]===1&&s[25]===42?{width:i(26)&16383,height:i(28)&16383}:null}function Pi(s){if(s.kind==="preset")return Cs.includes(s.preset)?null:"Choose a supported provider icon.";const n=/^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/]+={0,2})$/.exec(s.dataUrl);if(!n)return"Upload a PNG, JPEG, or WebP image.";const a=Ai(n[2]);if(a>Es)return"Provider icons must be 128 KB or smaller.";let i;try{i=atob(n[2])}catch{return"The uploaded image is not valid base64."}if(i.length!==a)return"The uploaded image is not valid base64.";const o=Uint8Array.from(i,d=>d.charCodeAt(0)),l=Ii(o,n[1]);return l?l.width<1||l.height<1||l.width>fe||l.height>fe||l.width*l.height>fe**2?`Provider icons must be at most ${fe} × ${fe} pixels.`:null:"The uploaded image is incomplete or does not match its file type."}function Ri(s){return new Promise((n,a)=>{const i=new Image;i.onerror=()=>a(new Error(t("engines.icon.decodeError"))),i.onload=()=>n({width:i.naturalWidth,height:i.naturalHeight}),i.src=s})}async function Bi(s,n=Ri){if(!As.includes(s.type))throw new Error(t("engines.icon.formatError"));if(s.size>Es)throw new Error(t("engines.icon.sizeError"));const a=new Uint8Array(await s.arrayBuffer());let i="";for(let u=0;u<a.length;u+=8192)i+=String.fromCharCode(...a.subarray(u,u+8192));const o={kind:"custom",dataUrl:`data:${s.type};base64,${btoa(i)}`};if(Pi(o))throw new Error(t("engines.icon.invalidError",{dimension:fe}));const d=await n(o.dataUrl);if(d.width<1||d.height<1||d.width>fe||d.height>fe)throw new Error(t("engines.icon.dimensionError",{dimension:fe}));return o}function Di({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(null),d=r.useRef(!1),u=async m=>{if(!d.current){d.current=!0,i(!0),l(null);try{const g=typeof m=="function"?await m():m;await U(`/api/instances/${encodeURIComponent(s.instanceId)}/icon`,{method:"PATCH",body:JSON.stringify({icon:g})}),await n()}catch(g){l(g instanceof Error?g.message:String(g))}finally{d.current=!1,i(!1)}}},c=m=>{const g=m.currentTarget,p=g.files?.[0];p&&u(()=>Bi(p)).finally(()=>{g.value=""})},x=s.icon?.kind==="preset"?s.icon.preset:s.icon?.kind==="custom"?"custom":"default";return e.jsxs("section",{"aria-label":t("engines.icon.label"),className:"mb-3 rounded-xl border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-xl border border-hairline/30 bg-panel",children:e.jsx(sn,{instance:s,size:24})}),e.jsxs("label",{className:"min-w-40 flex-1 text-[12px] font-medium text-ink",children:[t("engines.icon.label"),e.jsxs("select",{"aria-label":t("engines.icon.selectAria",{name:s.displayName}),value:x,disabled:a,onChange:m=>{m.target.value==="default"?u(null):m.target.value!=="custom"&&u({kind:"preset",preset:m.target.value})},className:"mt-1 block w-full rounded-lg border border-hairline/40 bg-inset px-2.5 py-2 text-[12px] text-ink focus:border-accent/60 focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"default",children:t("engines.icon.default")}),s.icon?.kind==="custom"&&e.jsx("option",{value:"custom",children:t("engines.icon.custom")}),Cs.map(m=>e.jsx("option",{value:m,children:Ei[m]},m))]})]}),a&&e.jsx(H,{size:15,"aria-label":t("engines.icon.saving"),className:"animate-spin text-ink-secondary"}),s.icon&&e.jsxs("button",{type:"button",disabled:a,onClick:()=>{u(null)},className:"inline-flex items-center gap-1 rounded-lg px-2 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:[e.jsx(ds,{size:13,"aria-hidden":"true"}),t("engines.icon.reset")]})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-ink-secondary",children:t("engines.icon.help")}),e.jsx("input",{type:"file",accept:As.join(","),disabled:a,onChange:c,"aria-label":t("engines.icon.uploadAria",{name:s.displayName}),className:"mt-2 block w-full text-[11px] text-ink-secondary file:mr-2 file:rounded-lg file:border-0 file:bg-control file:px-2.5 file:py-1.5 file:text-[11px] file:font-medium file:text-ink hover:file:bg-raised-hover disabled:opacity-50"}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Is({instance:s,onSaved:n,onCancel:a}){const{refreshInstances:i}=K(),[o,l]=r.useState(s?.displayName??""),[d,u]=r.useState(s?.claudeAccount?.configDir??""),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=!s||o.trim()!==s.displayName||d.trim()!==s.claudeAccount?.configDir,y=!!(s?.claudeAccount?.configDir&&!d.trim()),k=async()=>{if(!(c||!o.trim()||!p||y)){x(!0),g(null);try{await U(s?`/api/instances/${encodeURIComponent(s.instanceId)}`:"/api/instances/claude-accounts",{method:s?"PATCH":"POST",body:JSON.stringify({displayName:o.trim(),...d.trim()?{configDir:d.trim()}:{}})}),await i().catch(()=>{}),n()}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}}};return e.jsxs("form",{className:"flex min-w-0 flex-col gap-3",onSubmit:N=>{N.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:o,onChange:N=>l(N.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-ink-secondary hover:text-ink",children:t("engines.account.advanced")}),e.jsxs("label",{className:"mt-2 flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.configDir"),e.jsx("input",{value:d,onChange:N=>u(N.target.value),placeholder:t(s?"engines.account.defaultDir":"engines.account.configDirPlaceholder"),maxLength:4096,spellCheck:!1,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.configDirHint")}),s&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.changeDirHint")})]}),!s&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("engines.account.addHint")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex justify-end gap-2",children:[a&&e.jsx("button",{type:"button",onClick:a,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!o.trim()||!p||y,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),s?t("common.save"):t("engines.account.add")]})]})]})}function Ti(){const[s,n]=r.useState(!1);return s?e.jsx("div",{className:"rounded-xl border border-hairline/40 p-3",children:e.jsx(Is,{onSaved:()=>n(!1),onCancel:()=>n(!1)})}):e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-fit items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(Te,{size:13}),t("engines.account.add")]})}function zi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(!1),[c,x]=r.useState(!1),[m,g]=r.useState(!1),[p,y]=r.useState(null),k=s.claudeAccount;if(!k)return null;const N=n.bots.filter(h=>h.modelSelection.instanceId===s.instanceId).length,v=N>0,j=s.snapshot.authenticated===!0,C=s.snapshot.account?.method==="api-key",w=j&&s.authentication?.signOut===!0&&!C,D=j?C?t("engines.account.apiKey"):[s.snapshot.account?.email,s.snapshot.account?.organization].filter(Boolean).join(" · "):"",I=async()=>{if(!(o||m)){l(!0),y(null);try{await i()}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},f=async()=>{if(u(!1),!(o||m||k.isDefault||v)){l(!0),y(null);try{await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"}),await i().catch(()=>{})}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},b=async()=>{if(x(!1),!(o||m||!w)){g(!0),y(null);try{const{instances:h}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:h})}catch(h){y(h instanceof Error?h.message:String(h))}finally{g(!1)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:_("min-w-0 break-words",j?"text-success":"text-ink-secondary"),children:[j?t("engines.account.connected"):s.snapshot.authenticated===!1?t("model.signInRequired"):t("engines.account.unknown"),D&&` · ${D}`]}),k.isDefault&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:t("engines.account.default")}),e.jsxs("button",{type:"button",onClick:()=>{I()},disabled:o||m,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o&&"animate-spin")}),t("engines.account.check")]})]}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:t("engines.account.signInHint")}),k.signInShell==="powershell"&&e.jsx("p",{className:"text-ink-secondary",children:t("engines.account.powershell")}),e.jsx(Re,{command:k.signInCommand,copyLabel:t("engineSetup.copyCommand")}),e.jsx("fieldset",{disabled:o||m,className:"min-w-0",children:e.jsx(Is,{instance:s,onSaved:()=>{}},`${s.displayName}:${k.configDir}`)}),w&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!0),disabled:o||m,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:m?t("engines.account.signingOut"):t("engines.account.signOut")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.signOutHint")}),v&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.signOutAssigned",{count:String(N)})})]}),!k.isDefault&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o||m||v,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:t("engines.account.remove")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t(v?"engines.account.assigned":"engines.account.removeHint")})]})]})]}),p&&e.jsx("p",{role:"alert",className:"text-danger",children:p}),e.jsx(Ge,{open:d,title:t("engines.account.removeTitle",{name:s.displayName}),body:t("engines.account.removeHint"),confirmLabel:t("engines.account.remove"),tone:"neutral",onCancel:()=>u(!1),onConfirm:()=>{f()}}),e.jsx(Ge,{open:c,title:t("engines.account.signOutTitle",{name:s.displayName}),body:t("engines.account.signOutHint"),confirmLabel:t("engines.account.signOut"),onCancel:()=>x(!1),onConfirm:()=>{b()}})]})}function Mi(){const{dispatch:s}=K(),[n,a]=r.useState(!1),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(null),x=async()=>{if(!(l||!i.trim())){d(!0),c(null);try{const{instances:m}=await U("/api/instances/chatgpt-accounts",{method:"POST",body:JSON.stringify({displayName:i.trim()})});s({type:"instances",instances:m}),a(!1),o("")}catch(m){c(m instanceof Error?m.message:String(m))}finally{d(!1)}}};return n?e.jsxs("form",{className:"min-w-0 space-y-3 rounded-xl border border-hairline/40 p-3",onSubmit:m=>{m.preventDefault(),x()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:i,onChange:m=>o(m.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:l,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("engineSetup.chatgpt.addAccountHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a(!1),disabled:l,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:l||!i.trim(),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[l&&e.jsx(H,{size:13,className:"animate-spin"}),t("engineSetup.chatgpt.addAccount")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex w-fit items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(Te,{size:13}),t("engineSetup.chatgpt.addAccount")]})}function Oi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),m=s.snapshot.account?.email,g=s.authentication?.signOut===!0,p=s.snapshot.chatgptPlan===!0,y=t(p?"engineSetup.chatgpt.signOutHint":"engineSetup.device.signOutHint"),k=n.bots.filter(j=>j.modelSelection.instanceId===s.instanceId).length,N=async()=>{if(!o){l("check"),x(null);try{await i()}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}},v=async()=>{if(u(!1),!(o||!g)){l("signOut"),x(null);try{const{instances:j}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 break-words text-success",children:[e.jsx(oe,{size:13,className:"shrink-0"}),t(p?"engineSetup.chatgpt.connectedAccount":"engineSetup.device.connectedAccount"),m&&e.jsxs("span",{className:"text-ink-secondary",children:["· ",m]})]}),e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:o!==null,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o==="check"&&"animate-spin")}),t("engines.account.check")]})]}),p&&e.jsx(nn,{instanceId:s.instanceId},s.instanceId),g&&e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:y}),k>0&&e.jsx("p",{className:"leading-relaxed text-warning",children:t(p?"engineSetup.chatgpt.signOutAssigned":"engineSetup.device.signOutAssigned",{count:String(k)})}),e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o!==null,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:o==="signOut"?t("engineSetup.device.signingOut"):t("engineSetup.device.signOut")})]})]}),c&&e.jsx("p",{role:"alert",className:"text-danger",children:c}),e.jsx(Ge,{open:d,title:t("engineSetup.device.signOutTitle"),body:y,confirmLabel:t("engineSetup.device.signOut"),onCancel:()=>u(!1),onConfirm:()=>{v()}})]})}function Ut(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Ui({instance:s,initial:n={kind:"idle"}}){const[a,i]=r.useState(n),[o,l]=r.useState(null),d=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,u=async()=>{l(null),i({kind:"scanning"});try{const m=await U(d);i(m.folders>0?{kind:"found",bytes:m.bytes,complete:m.complete}:{kind:"none"})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},c=async()=>{l(null),i({kind:"deleting"});try{const m=await U(`${d}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:m.freedBytes,remaining:m.remaining})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},x=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xi,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||x)&&e.jsxs("button",{type:"button",onClick:()=>{u()},disabled:x,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Ut(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{c()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Ut(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Li({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[o,l]=r.useState(s.cliCandidates??null),[d,u]=r.useState(""),[c,x]=r.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[m,g]=r.useState(!1),[p,y]=r.useState(null),[k,N]=r.useState(!1),[v,j]=r.useState(null),C=r.useRef(!1);r.useEffect(()=>{C.current||(C.current=!0,U(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:h})=>{l(h),s.cli&&(h.includes(s.cli)?u(s.cli):x(s.cli))}).catch(()=>l(h=>h??[])))},[n,s.cli]);const w=c.trim()||d,D=w!==(s.cli??""),I=m||k;r.useEffect(()=>{y(null)},[w]);const f=()=>{if(I||!w||!D)return;N(!0),j(null);const h=w;U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:h})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(E=>j(E.message)).finally(()=>N(!1))},b=()=>{I||!w||!D||(g(!0),j(null),U("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(h=>{y(h),h.ok&&f()}).catch(h=>j(h.message)).finally(()=>g(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[o!==null&&o.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:c.trim()?"":d,onChange:h=>{u(h.target.value),x("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,className:"w-full appearance-none rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),o.map(h=>e.jsx("option",{value:h,children:h},h))]}),e.jsx(pn,{size:13,className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"})]}),e.jsx("input",{type:"text",value:c,onChange:h=>x(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),!(!w||!D)&&b())},placeholder:o?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:I,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),p&&!p.ok&&p.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(ke,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:p.message})})]}),p?.ok&&p.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:p.version})}),v&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:v}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),p&&!p.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y(null),disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>f(),disabled:I,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:k?e.jsx(H,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:b,disabled:I||!w||!D,className:_("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:I?e.jsx(H,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})})]})]})}function _i({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),o=on(a),[l,d]=r.useState(!1),[u,c]=r.useState(!1),[x,m]=r.useState(null),[g,p]=r.useState(null),y=r.useRef(null);r.useEffect(()=>{y.current!==null&&y.current!==s.cli&&i(!1),y.current=s.cli??null},[s.cli]);const k=()=>{l||u||(d(!0),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>p(j.message)).finally(()=>d(!1)))},N=()=>{l||u||(c(!0),m(null),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{m(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>p(j.message)).finally(()=>c(!1)))},v=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.readOnly?e.jsxs(At,{instance:s,children:[v,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!$e(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(At,{instance:s,children:[v,e.jsx(Di,{instance:s}),!$e(s)&&e.jsx(us,{instance:s,intent:s.access==="custom"?"inject":"cloud",unframed:!0}),$e(s)&&e.jsx(cn,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(dn,{update:s.snapshot.update,instance:s,className:"mt-3"}),s.snapshot.warning&&e.jsx(un,{warning:s.snapshot.warning,className:"mt-3"}),s.claudeAccount&&e.jsx(zi,{instance:s}),$e(s)&&s.snapshot.authenticated===!0&&((s.authentication?.method==="device-code"||s.authentication?.method==="browser-pkce")&&It(s.driverKind)==="codex"?e.jsx(Oi,{instance:s}):s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t(xn[It(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&!s.claudeAccount&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Ui,{instance:s}),e.jsxs("details",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[11.5px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:N,disabled:l||u,className:"flex shrink-0 items-center gap-1 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[u?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(xe,{size:12}),u?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:k,disabled:l||u,className:"shrink-0 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:l?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:u,"aria-expanded":a,className:_("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),x&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:x})}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g}),o.shown&&e.jsx("div",{className:o.className,...o.exitProps,children:e.jsx(Li,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})]})}function Fi(){const{state:s}=K(),n=s.instances.filter(a=>a.readOnly||a.cli!==void 0||a.cliDefault!==void 0||a.snapshot.state==="unavailable"||an(a));return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(rn,{})]}),e.jsx(ln,{instances:n,renderEngine:a=>e.jsx(_i,{instance:a})}),e.jsxs("div",{className:"space-y-3 border-t border-hairline/40 pt-4",children:[e.jsx(Ti,{}),s.instances.some(a=>a.snapshot.chatgptPlan&&!a.readOnly&&!a.snapshot.authenticationUnavailableReason)&&e.jsx(Mi,{})]})]})}const $i=[1e3,2e3,4e3];function Ki(s){return new Promise(n=>window.setTimeout(n,s))}const Hi={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Vi={unmanaged:"vm.state.notManaged","in-use":"vm.state.inUse",stopped:"vm.state.stopped",running:"vm.state.running",attention:"vm.state.attention",sleeping:"vm.state.sleeping","going-to-sleep":"vm.state.goingToSleep",starting:"vm.state.starting",restarting:"vm.state.restarting",removing:"vm.state.removing",paused:"vm.state.paused"};function gt(s){return t(Vi[s])}function Wi(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function qi(s){return gt(Wi(s))}function Ji(s){return s.inUse?"in-use":s.state==="removing"?"removing":["archived","stopped"].includes(s.state)?"sleeping":["archiving","stopping"].includes(s.state)?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning","starting"].includes(s.state)?"starting":"attention"}function Ps(s,n,a){const i={...a},o=new Set(s.map(d=>d.boxId)),l=s.flatMap(d=>{const u=a[d.boxId];return u==="deleted"?[]:u==="deleting"?[{...d,state:"removing"}]:u!=="sleeping"?[d]:["archived","stopped"].includes(d.state)?(delete i[d.boxId],[d]):[{...d,state:"archived"}]});for(const d of n)a[d.boxId]!=="sleeping"||o.has(d.boxId)||l.push({...d,state:"archived"});for(const[d,u]of Object.entries(a))(u==="deleted"||u==="deleting")&&!o.has(d)&&delete i[d];return{instances:l,overrides:i}}function Gi(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ps(Array.isArray(s.instances)?s.instances:[],n,a)}function Yi(s){return["idle","ready","running"].includes(s.state)}function Xi(s){return s.inUse?"in-use":s.state==="running"?"running":s.state==="restarting"?"restarting":s.state==="removing"?"removing":["created","exited"].includes(s.state)?"stopped":s.state==="paused"?"paused":"attention"}function ht(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}const Qi={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function Ke(s,n){return[Qi[s],{signal:n}]}function ft(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Zi(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:ft(`/api/bots/${s.botId}/local-computer/remove`,{})}}function er(s,n){return{confirmation:s==="delete"?t("vm.confirm.deleteCloud",{subject:n.orphaned?t("vm.confirm.orphanCloud"):t("vm.confirm.ownedCloud",{name:n.ownerName??""})}):null,request:ft(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function tr(s){const n=ht(s.name);return{confirmation:t("vm.confirm.removeVps",{subject:s.orphaned?t("vm.confirm.orphanVps",{id:n}):t("vm.confirm.ownedVps",{name:s.ownerName??""})}),request:ft(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name})}}function ct(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function sr({instances:s,configured:n,sshAlias:a,loading:i,removingName:o,error:l,unavailableReason:d,onRefresh:u,onRemove:c}){return e.jsxs(L,{title:t("vm.vps.title"),subtitle:t("vm.vps.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.vps.sshHost",{alias:a??t("vm.vps.configuredFallback")}):n===!1?t("vm.vps.needsAlias"):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:u,disabled:i||o!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(i&&"animate-spin")})," ",t("vm.refresh")]})]}),l&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:l}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):d?t("vm.vps.unavailable",{reason:d}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":i||o!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):d?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",d]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(fi,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((x,m)=>{const g=Xi(x),p=gt(g),y=o===x.name,k=ht(x.name);return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.vps.orphan",{id:k}):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="stopped"||g==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:i||x.inUse||o!==null,"aria-busy":y||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("vm.vps.remove")]})]},x.name)})})]})}function nr({instances:s,configured:n,loading:a,pending:i,error:o,unavailableReason:l,onRefresh:d,onSleep:u,onDelete:c}){return e.jsxs(L,{title:t("vm.cloud.title"),subtitle:t("vm.cloud.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.cloud.includesOrphans"):n===!1?t("vm.cloud.needsKey"):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):l?t("vm.cloud.unavailable",{reason:l}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(mt,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((x,m)=>{const g=Ji(x),p=gt(g),y=i?.boxId===x.boxId,k=Yi(x),N=g==="removing";return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.cloud.orphan"):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="sleeping"||g==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsxs("div",{className:"mt-1 break-all text-[11.5px] text-ink-secondary",children:[x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",x.name]}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>u(x),disabled:a||x.inUse||i!==null||!k,"aria-busy":y&&i?.action==="sleep"?!0:void 0,title:k?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:p.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[y&&i?.action==="sleep"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ga,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:a||x.inUse||i!==null||N,"aria-busy":y&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y&&i?.action==="delete"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]})]},x.boxId)})})]})}function ar({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:o,unavailableReason:l,onRefresh:d,onDelete:u}){return e.jsxs(L,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:l?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):l?t("vm.perBot.unavailable",{reason:l}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((c,x)=>{const m=qi(c),g=i===c.botId,p=c.managed===!0;return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:c.name}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",p?c.inUse||c.ready?"bg-success/15 text-success":c.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:m})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Hi[c.destination])})}),!p&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:t("vm.perBot.unmanaged")}),p&&c.problem&&!c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:c.problem}),p&&c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),p&&e.jsxs("button",{type:"button",onClick:()=>u(c),disabled:a||c.inUse||i!==null,"aria-busy":g||void 0,title:c.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:c.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[g?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]},c.botId)})})]})}function He({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:_("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(oe,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:_("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function Ie({action:s,pending:n,children:a,onClick:i,danger:o=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:_("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[12.5px] font-medium disabled:opacity-50",o?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(H,{size:13,className:"animate-spin"}),a]})}const Rs=5,Bs=1440,ir=480;function rr(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Rs&&a<=Bs?a:null}function lr({minutes:s,disabled:n,onSave:a}){const[i,o]=r.useState(String(s)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1);r.useEffect(()=>{l||o(String(s))},[s,l]);const g=async()=>{if(!l||x)return;const p=rr(i);if(p===null){c(t("vm.idle.range"));return}m(!0);try{await a(p),o(String(p)),d(!1),c("")}catch(y){c(y instanceof Error?y.message:t("vm.idle.error"))}finally{m(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[11.5px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:_("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",u?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Rs,max:Bs,step:1,inputMode:"numeric",value:i,disabled:n||x,"aria-invalid":!!u,"aria-describedby":u?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:p=>{o(p.target.value),d(!0),c("")},onBlur:()=>{g()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[12.5px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),u?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:u}):null]})}function Lt(){const s=K().state.config?.cloudHome===!0,[n,a]=r.useState(null),[i,o]=r.useState(!0),[l,d]=r.useState(null),u=r.useRef(null);r.useEffect(()=>()=>u.current?.abort(),[]);const[c,x]=r.useState(null),[m,g]=r.useState(!1),[p,y]=r.useState(0),[k,N]=r.useState([]),[v,j]=r.useState(2),[C,w]=r.useState(!1),[D,I]=r.useState(null),[f,b]=r.useState(null),[h,E]=r.useState(null),[A,P]=r.useState(0),[V,J]=r.useState([]),[$,W]=r.useState(null),[z,G]=r.useState(!0),[ne,R]=r.useState(null),[F,q]=r.useState(null),[ce,pe]=r.useState(null),[be,ye]=r.useState(0),X=r.useRef([]),se=r.useRef({}),[Se,ge]=r.useState([]),[ee,Le]=r.useState(null),[T,Q]=r.useState(null),[ie,ae]=r.useState(!0),[Me,et]=r.useState(null),[qs,yt]=r.useState(null),[Js,vt]=r.useState(null),[Gs,Ys]=r.useState(0),[Xs,ve]=r.useState(""),Oe=r.useCallback(async S=>{const B=await fetch(...Ke("status",S)),M=await B.json().catch(()=>({}));if(!S?.aborted){if(!B.ok)throw new Error(M.error??t("vm.err.status",{code:B.status}));return a(M),x(null),M}},[]),tt=r.useCallback(async S=>{const B=await fetch(...Ke("local-vms",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.inventory",{code:B.status}));const O=M;N(O.instances),j(O.maxInstances),b(O.available?null:O.problem??t("vm.err.runtimeUnavailable")),I(null)},[]),Ue=r.useCallback(async S=>{const B=await fetch(...Ke("cloud",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.cloudInventory",{code:B.status}));const O=M,Z=Gi(O,X.current,se.current);se.current=Z.overrides,X.current=Z.instances,J(Z.instances),W(O.configured===!0),q(O.available||!O.configured?null:O.problem??t("vm.err.cloudUnavailable")),R(null)},[]),st=r.useCallback(async S=>{const B=await fetch(...Ke("vps",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.vpsInventory",{code:B.status}));const O=M;ge(Array.isArray(O.instances)?O.instances:[]),Le(O.configured===!0),Q(typeof O.sshAlias=="string"?O.sshAlias:null),yt(O.available||!O.configured?null:O.problem??t("vm.err.vpsUnavailable")),et(null)},[]);r.useEffect(()=>{if(s)return;let S=!0,B,M;const O=async()=>{M=new AbortController;try{await Oe(M.signal)}catch(Z){S&&!(Z instanceof DOMException&&Z.name==="AbortError")&&(a(null),x(Z instanceof Error?Z.message:String(Z)))}finally{S&&(o(!1),B=window.setTimeout(()=>{O()},5e3))}};return O(),()=>{S=!1,M?.abort(),B!==void 0&&window.clearTimeout(B)}},[s,Oe,p]),r.useEffect(()=>{if(n?.mode!=="per-bot"){N([]),w(!1),I(null),b(null);return}const S=new AbortController;return w(!0),tt(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||I(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||w(!1)}),()=>S.abort()},[A,tt,n?.mode]),r.useEffect(()=>{const S=new AbortController;return G(!0),Ue(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||q(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||G(!1)}),()=>S.abort()},[be,Ue]),r.useEffect(()=>{const S=new AbortController;return ae(!0),st(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||yt(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||ae(!1)}),()=>S.abort()},[st,Gs]);const nt=async(S,B)=>{const M=await fetch(`/api/local-computer/${S}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:B}),O=await M.json().catch(()=>({})),Z={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!M.ok)throw new Error(O.error??t(Z[S]));return B.throwIfAborted(),a(O),O},jt=S=>window.ogb?.confirm?window.ogb.confirm(S):window.confirm(S),Ce=async S=>{if(l!==null||u.current)return;const B=new AbortController;u.current=B,d(S),x(null);try{if(S==="remove"&&!await jt(t("vm.confirm.deleteShared"))||S==="recreate"&&!await jt(t("vm.confirm.recreate")))return;let M;if(S==="recreate"?(await nt("remove",B.signal),M=await nt("run",B.signal)):M=await nt(S,B.signal),(S==="run"||S==="start"||S==="recreate")&&(M=await Ya(M,async()=>await Oe(B.signal)??M,B.signal),!M.ready))throw new Error(M.problem??t("vm.err.start"));await Oe(),ve(S==="remove"?t("vm.announce.deleted"):S==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(M){if(B.signal.aborted)return;x(M instanceof Error?M.message:String(M))}finally{u.current=null,B.signal.aborted||d(null)}},kt=async(S,B)=>{g(!0),x(null);try{const M=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:S,maxInstances:B}})}),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.policyError"));a(Z=>Z&&{...Z,mode:S,max_instances:B}),await Oe()}catch(M){x(M instanceof Error?M.message:String(M))}finally{g(!1)}},Qs=async S=>{const B=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:S}})}),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.idle.error"));a(O=>O&&{...O,idle_timeout_ms:S*6e4})},Zs=async S=>{if(!S.managed){I(t("vm.unmanagedError"));return}const B=ct(Zi(S),M=>window.confirm(M));if(B){E(S.botId),I(null);try{const M=await fetch(...B),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.deleteError"));await tt(),ve(t("vm.announce.deletedBot",{name:S.name}))}catch(M){I(M instanceof Error?M.message:String(M))}finally{E(null)}}},Nt=async(S,B)=>{const M=ct(er(S,B),O=>window.confirm(O));if(M){pe({boxId:B.boxId,action:S}),R(null),ve("");try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t(S==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const rt=S==="delete"&&Z?.pending===!0;se.current={...se.current,[B.boxId]:S==="delete"?rt?"deleting":"deleted":"sleeping"};const lt=Ps(X.current,X.current,se.current);se.current=lt.overrides,X.current=lt.instances,J(lt.instances);const Ee=B.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:B.ownerName??""});if(ve(rt?`${Ee}: ${t("vm.state.removing")}.`:t(S==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ee})),rt){for(const de of $i){await Ki(de);try{await Ue()}catch{}if(se.current[B.boxId]!=="deleting"){ve(t("vm.announce.cloudDeleted",{subject:Ee}));return}}const Ae={...se.current};delete Ae[B.boxId],se.current=Ae;const Fe=X.current.map(de=>de.boxId===B.boxId?{...de,state:B.state}:de);X.current=Fe,J(Fe);try{await Ue(),X.current.some(de=>de.boxId===B.boxId)||ve(t("vm.announce.cloudDeleted",{subject:Ee}))}catch(de){const tn=de instanceof Error?de.message:String(de);R(`${Ee}: ${t("vm.state.removing")}. ${tn}`)}return}try{await Ue()}catch(Ae){const Fe=Ae instanceof Error?Ae.message:String(Ae);R(t(S==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ee,detail:Fe}))}}catch(O){R(O instanceof Error?O.message:String(O))}finally{pe(null)}}},en=async S=>{const B=ht(S.name),M=ct(tr(S),O=>window.confirm(O));if(M){vt(S.name),et(null);try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t("vm.vpsRemoveError"));await st(),ve(t("vm.announce.vpsRemoved",{subject:S.orphaned?t("vm.announce.orphanVps",{id:B}):t("vm.confirm.ownedVps",{name:S.ownerName??""})}))}catch(O){et(O instanceof Error?O.message:String(O))}finally{vt(null)}}},he=n?.commands,_e=n?.ready===!0,wt=n?.container!=="missing",St=!!(wt&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ct=!i&&!n,Et=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),re=n?.mode==="per-bot",at=re&&n?.runtime==="container",it=re?!!(n?.daemonUp&&n?.image&&!at):_e;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Xs}),e.jsx(nr,{instances:V,configured:$,loading:z,pending:ce,error:ne,unavailableReason:F,onRefresh:()=>ye(S=>S+1),onSleep:S=>{Nt("sleep",S)},onDelete:S=>{Nt("delete",S)}}),e.jsx(sr,{instances:Se,configured:ee,sshAlias:T,loading:ie,removingName:Js,error:Me,unavailableReason:qs,onRefresh:()=>Ys(S=>S+1),onRemove:S=>{en(S)}}),e.jsx(Ja,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{title:t("vm.main.title"),subtitle:re?t("vm.main.perBotSubtitle",{host:Et}):t("vm.main.sharedSubtitle",{host:Et}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:_("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12.5px]",it?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(H,{size:12,className:"animate-spin"}):it?e.jsx(oe,{size:12}):e.jsx(mn,{size:9}),i?t("common.checking"):Ct?t("vm.main.statusUnavailable"):re&&it?t("vm.main.readyPerBot"):at?t("vm.main.perBotUnsupported"):_e?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{o(!0),y(S=>S+1),P(S=>S+1)},disabled:i||l!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12})," ",t("vm.main.recheck")]}),_e&&!re&&e.jsxs("a",{href:n?.viewer_url??he?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink hover:bg-control",children:[e.jsx(Ze,{size:12})," ",t("vm.main.watch")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c})]}),e.jsxs(L,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((S,B)=>e.jsx("button",{type:"button",disabled:!n||m,onClick:()=>{kt(S,n?.max_instances??2)},className:_("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",B>0&&"border-l border-hairline/40",n?.mode===S?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:S==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},S))}),re&&e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("vm.isolation.max")}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx("select",{"aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||m,onChange:S=>{kt(n?.mode??"shared",Number(S.target.value))},className:"rounded-lg border border-hairline/40 bg-control px-2.5 py-1.5 text-[13px] text-ink disabled:opacity-50",children:[1,2,3,4,5,6,7,8].map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsx(lr,{minutes:n?Math.round(n.idle_timeout_ms/6e4):ir,disabled:!n||m,onSave:Qs}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(H,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(L,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(He,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),he?.install?e.jsx(Re,{command:he.install}):e.jsx("a",{href:"https://podman.io/docs/installation",target:"_blank",rel:"noreferrer",className:"text-[13px] text-accent hover:underline",children:t("vm.setup.podmanGuide")})]}),e.jsx(He,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?he?.runtimeStart?e.jsx(Re,{command:he.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(He,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ie,{action:"pull",pending:l,onClick:()=>{Ce("pull")},children:t("vm.setup.prepare")}),he?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.pull})})]})]}),e.jsxs(He,{n:4,title:re?t("vm.setup.step4PerBot"):St?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!re&&_e,children:[re?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:at?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):St?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ie,{action:"recreate",pending:l,onClick:()=>{Ce("recreate")},danger:!0,children:[e.jsx(ds,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ie,{action:"start",pending:l,onClick:()=>{Ce("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{action:"run",pending:l,onClick:()=>{Ce("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,he?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.run})})]})]})]})}),re&&e.jsx(ar,{instances:k,maxInstances:v||n?.max_instances||2,loading:C,deletingBotId:h,error:D,unavailableReason:f,onRefresh:()=>P(S=>S+1),onDelete:S=>{Zs(S)}}),Ct&&e.jsx(L,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(L,{title:t("vm.safety.title"),subtitle:re?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[wt&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ie,{action:"stop",pending:l,onClick:()=>{Ce("stop")},children:[e.jsx(gn,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ie,{action:"remove",pending:l,onClick:()=>{Ce("remove")},danger:!0,children:[e.jsx(we,{size:12})," ",re?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.20.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function or(s,n){return s.error?{kind:"error",title:t("remote.status.attention"),detail:s.error}:n&&s.tailnetName?{kind:"ready",title:t("remote.tailscale.ready",{name:s.tailnetName}),detail:t("remote.tailscale.readyDetail")}:s.tailscale?{kind:"magicdns",title:t("remote.tailscale.magicDns"),detail:t("remote.tailscale.magicDnsDetail")}:s.enabled?{kind:"unavailable",title:t("remote.tailscale.notConnected"),detail:t("remote.tailscale.notConnectedDetail")}:{kind:"unchecked",title:t("remote.tailscale.already"),detail:t("remote.tailscale.alreadyDetail")}}function cr(s){return s.tailscaleFallback?{title:t("remote.pairing.tailscale.title"),subtitle:t("remote.pairing.tailscale.subtitle")}:s.localFallback?{title:t("remote.pairing.wifi.title"),subtitle:t("remote.pairing.wifi.subtitle")}:{title:t("remote.pairing.https.title"),subtitle:t("remote.pairing.https.subtitle")}}function dr(s){if(s.error)return{label:t("remote.status.attention"),good:!1};if(!s.enabled)return{label:t("remote.status.off"),good:!1};const n=s.devices.length;return n?{label:`${n} ${n===1?"device":"devices"} paired`,good:!0}:null}const ur=s=>{const n=Math.round((Date.now()-s)/1e3);if(n<90)return t("remote.time.justNow");const a=Math.round(n/60);if(a<60)return t("remote.time.minutes",{count:a});const i=Math.round(a/60);return i<24?t("remote.time.hours",{count:i}):t("remote.time.days",{count:Math.round(i/24)})},xr=s=>{try{return new URL(s).host}catch{return s}};function pr({profileEmail:s="",focusRequest:n=0}){const a=hn(s),i=a.state,o=r.useRef(null),l=r.useRef(0),d=!!i;r.useEffect(()=>{n?l.current!==n&&xs(o.current)&&(l.current=n):l.current=0},[n,d]);const u=K().state.config?.managedPolicy,c=u?.remoteAccess===!1?t("policy.remoteBlocked",{organization:u.organizationName}):null,x=u?.remoteAccess===!1?t("policy.managedBy",{organization:u.organizationName}):null;if(!fn())return e.jsx(L,{title:t("remote.desktopOnly.title",{app:Ye().name}),subtitle:t("remote.desktopOnly.subtitle")});if(!i)return e.jsx(L,{title:t("remote.title"),subtitle:t("remote.checking"),children:e.jsx(H,{size:15,className:"animate-spin text-ink-secondary"})});const m=i.devices.length,g=dr(i),p=bn(a.account,a.accountError),y=cr(a),k=or(i,a.tailscaleAvailable),N=i.endpoints?.find(j=>j.kind==="hosted"),v=[i.tailnetName?{label:"Tailscale",value:`${i.tailnetName}:${i.port}`}:null,i.lan?{label:t("remote.connection.wifi"),value:`${i.lan}:${i.port}`}:null,i.discovery?.name?{label:t("remote.connection.discovery"),value:`${i.discovery.name}:${i.port}`}:null,...(i.addresses??[]).filter(j=>j!==i.lan&&j!==i.tailscale).map((j,C)=>({label:t("remote.connection.localRoute",{index:C+1}),value:`${j}:${i.port}`}))].filter(j=>!!j);return e.jsxs("div",{className:"flex flex-col gap-4",children:[c&&e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink-secondary",children:c}),e.jsx("div",{ref:o,tabIndex:-1,"data-phone-pairing":"computer",className:"scroll-mt-4 rounded-xl ring-1 ring-accent/40 focus:outline-none",children:e.jsxs(L,{title:y.title,subtitle:y.subtitle,children:[(g||m>0&&a.hostedReady)&&e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[g&&e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-2.5 py-1 text-[11.5px] ${g.good?"bg-success/10 text-success":"bg-control text-ink-secondary"}`,children:[e.jsx("span",{className:`size-1.5 rounded-full ${g.good?"bg-success":"bg-ink-secondary/50"}`}),g.label]}),m>0&&a.hostedReady&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx(Pt,{size:13,className:"text-accent"})," ",t("remote.worksAway")]})]}),e.jsx(yn,{controller:a,variant:"settings"})]})}),e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-card",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-3.5 text-[13px] font-medium text-ink",children:t("remote.advanced")}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-hairline/30 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.toggleDetail")})]}),e.jsx(Y,{checked:i.enabled,"aria-label":t("remote.title"),disabled:a.busy||!!c&&!i.enabled,onClick:()=>{a.act(j=>i.enabled?j.stop():j.start())}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.devices.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:m?t("remote.devices.subtitle",{app:Ye().name}):t("remote.devices.empty")}),e.jsx("div",{className:"mt-3",children:m>0&&e.jsx("ul",{className:"flex flex-col gap-2",children:i.devices.map(j=>e.jsxs("li",{className:"rounded-xl bg-inset px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(vn,{size:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13.5px] font-medium text-ink",children:j.name}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("remote.devices.lastSeen",{when:ur(j.lastSeenAt)})})]}),e.jsx("button",{disabled:a.busy,onClick:()=>{a.act(C=>C.revoke(j.id))},"aria-label":t("remote.devices.remove",{name:j.name}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-40",children:e.jsx(we,{size:14})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowView")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowViewDetail")})]}),e.jsx(Y,{checked:j.cloudDesktopAccess,"aria-label":t("remote.devices.viewAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.cloudDesktop(j.id,!j.cloudDesktopAccess))}})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowBrowser")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowBrowserDetail")})]}),e.jsx(Y,{checked:j.browserControlAccess===!0,"aria-label":t("remote.devices.browserAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.browserControl(j.id,!j.browserControlAccess))}})]})]},j.id))})})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.tailscale.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.tailscaleCard.subtitle")}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"rounded-xl bg-inset px-3 py-3","aria-live":"polite",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Pt,{size:16,className:`mt-0.5 shrink-0 ${k.kind==="ready"?"text-success":"text-ink-secondary"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:k.title}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:k.detail})]})]})}),k.kind==="ready"?e.jsx("button",{disabled:a.busy||a.accountBusy||!!x,title:x??void 0,onClick:()=>{a.useTailscale(),window.requestAnimationFrame(()=>{o.current?.scrollIntoView({block:"start"}),o.current?.focus({preventScroll:!0})})},className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.pairOverTailscale")}):e.jsx("button",{disabled:a.busy||a.accountBusy||!!x&&!i.enabled,title:x??void 0,onClick:a.refreshTailscale,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.busy?t("common.checking"):x&&!i.enabled?x:i.enabled?t("remote.checkAgain"):t("remote.turnOnAndCheck")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.keepAwake")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.keepAwakeDetail")})]}),e.jsx(Y,{checked:i.keepAwake,"aria-label":t("remote.keepAwakeAria"),disabled:a.busy||!i.enabled,onClick:()=>{a.act(j=>j.keepAwake(!i.keepAwake))}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(mt,{size:15,className:"mt-0.5 shrink-0 text-accent"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.account.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:a.account?.status==="ready"?t("remote.account.signedIn",{email:a.account.email??t("remote.account.yourAccount")}):a.account?.status==="connecting"?t("remote.account.connecting"):a.account?.status==="error"?a.account.message??t("remote.account.error"):t("remote.account.idle")})]})]}),(a.account?.status==="ready"||a.account?.status==="connecting"||a.account?.status==="error")&&e.jsxs("button",{disabled:a.accountBusy,onClick:()=>{a.accountAct(j=>j.signOut())},className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[11.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(jn,{size:12})," ",t("remote.account.signOut")]})]}),a.account?.status==="error"&&e.jsx("button",{disabled:a.accountBusy,onClick:a.retryAccount,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.accountBusy?t("remote.account.retrying"):t("remote.account.retry")}),p&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:p})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.connection.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] text-ink-secondary",children:t("remote.connection.detail")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[N&&e.jsx(Rt,{label:t("remote.connection.secureRoute"),value:xr(N.url)}),v.map(j=>e.jsx(Rt,{...j},`${j.label}:${j.value}`)),!N&&v.length===0&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("remote.connection.none")})]})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(kn,{size:15,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.wifi.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.wifi.detail")})]})]}),e.jsx("button",{disabled:a.busy||a.accountBusy,onClick:a.useLocal,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.wifi.pair")})]}),i.enabled&&!N&&!i.tailscale&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.localOnly")}),(a.error||i.error)&&e.jsx("div",{className:"text-[12px] text-danger",children:a.error??i.error})]})]})]})}function Xe(s){return wn(s)}function mr(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function gr(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}function hr(s,n=Date.now()){return Math.max(0,Math.ceil((s-n)/6e4))}function fr(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const br="rounded-md bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-50",_t="rounded-md border border-hairline/50 px-3 py-1.5 text-[13px] text-ink hover:bg-control";function yr({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0}){const[o,l]=r.useState(s),[d,u]=r.useState(n),[c,x]=r.useState("admin"),[m,g]=r.useState(null),[p,y]=r.useState([]),[k,N]=r.useState(null),[v,j]=r.useState(!1),[C,w]=r.useState("idle"),[D,I]=r.useState(null),[f,b]=r.useState(()=>Date.now()),h=r.useRef(null),E=r.useRef(0);async function A(){try{const z=await U("/api/auth/sessions");y(Array.isArray(z?.sessions)?z.sessions:[]),N(typeof z?.current=="string"?z.current:null)}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}}if(r.useEffect(()=>{ps().then(z=>{l(z),Xe(z)&&A(),(z.kind==="loopback"||z.kind==="session")&&U("/api/config").then(G=>u(ms(G).pairingCodes)).catch(()=>{})})},[]),r.useEffect(()=>{i?E.current!==i&&xs(h.current)&&(E.current=i):E.current=0},[i,o]),r.useEffect(()=>{if(!m)return;const z=setInterval(()=>b(Date.now()),15e3);return()=>clearInterval(z)},[m]),!Xe(o))return mr(o)!=="chat-only"?null:e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(d?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const P=m?m.expiresAt<=f:!1,V=gr(p,a);async function J(){j(!0),I(null),w("idle");try{const z=await U("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:c==="admin"||a?["admin","client"]:["client"]})});g(z),b(Date.now())}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}finally{j(!1)}}async function $(z){I(null);try{await U(`/api/auth/sessions/${encodeURIComponent(z)}`,{method:"DELETE"}),await A()}catch(G){I(t("remote.serverPairing.error",{error:G instanceof Error?G.message:String(G)}))}}async function W(){if(!m?.url)return;const z=await Sn(m.url);z!=="empty"&&w(z)}return e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[d&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,d?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="admin",onChange:()=>x("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="client",onChange:()=>x("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{J()},disabled:v,className:br,children:v?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),d&&m?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:P?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[m.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Nn,{value:m.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:m.code}),e.jsx("div",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.expires",{minutes:hr(m.expiresAt,f)})}),m.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:m.url}),e.jsx("button",{type:"button",onClick:()=>{W()},className:_t,children:t(C==="copied"?"remote.serverPairing.copied":C==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[12.5px] text-ink-secondary",children:m.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(d?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),V.length===0?e.jsx("p",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:V.map(z=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[z.label,z.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:fr(z.lastSeenAt,f)}),z.id===k?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),z.id===k?null:e.jsx("button",{type:"button",onClick:()=>{$(z.id)},className:_t,children:t("remote.serverPairing.signOut")})]},z.id))}),D?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:D}):null]})})}function vr(s){const n=s.trim().toLowerCase();return!n||/\s/.test(n)?null:n.startsWith("@")?/^@[^@\s]+\.[^@\s]+$/.test(n)?n:null:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(n)?n:null}function Ft(s,n,a){const i=s.admins.filter(l=>l!==n),o=s.members.filter(l=>l!==n);return a==="admin"?{admins:[...i,n],members:o}:{admins:i,members:[...o,n]}}function jr(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $t(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function kr(s,n,a){const i=[],o=new Set,l=(d,u)=>{const c=d.trim().toLowerCase();if(!c||o.has(c))return;o.add(c);const x=n.filter(g=>g.email?.toLowerCase()===c),m=a.find(g=>g.key===`user:${c}`);i.push({entry:c,role:u,isDomain:c.startsWith("@"),lastSeenAt:x.length?Math.max(...x.map(g=>g.lastSeenAt)):null,devices:x.length,turns:m?.turns??0,costUsd:m?.costUsd??null,...le(m?.estimatedUsd)&&m.estimatedUsd>0?{estimated:!0}:{}})};for(const d of s.admins)l(d,"admin");for(const d of s.members)l(d,"member");return i}function Nr(s,n){const a=new Map;for(const i of s){const o=i.email?.trim().toLowerCase();o&&a.set(o,[...a.get(o)??[],i])}return[...a.entries()].map(([i,o])=>{const l=n.find(d=>d.key===`user:${i}`);return{entry:i,role:o.some(d=>d.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...o.map(d=>d.lastSeenAt)),devices:o.length,turns:l?.turns??0,costUsd:l?.costUsd??null}}).sort((i,o)=>i.role===o.role?i.entry.localeCompare(o.entry):i.role==="admin"?-1:1)}function wr(s,n=Date.now()){return s===null?t("people.never"):n-s<1440*6e4?t("people.today"):new Date(s).toISOString().slice(0,10)}function Ds({people:s,busy:n,onRole:a,onRemove:i,onLink:o,readOnly:l=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(l?"people.portal.empty":"people.empty")});const d="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(d,"border-b border-hairline/40 pb-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(u=>e.jsxs("div",{className:_(d,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:u.isDomain?t("people.everyoneAt",{domain:u.entry.slice(1)}):u.entry}),u.devices>0&&e.jsx("span",{className:"block text-[11.5px] text-ink-secondary",children:t("people.devices",{count:String(u.devices)})})]}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px] font-medium",u.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:u.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:u.isDomain?"—":wr(u.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(u.turns)}),children:le(u.costUsd)?`${u.estimated?"~":""}${ue(u.costUsd)}`:"—"}),l?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>o(u),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(An,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(u,u.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:u.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(u),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},u.entry))]})}function Ts({link:s}){const{state:n,copy:a}=Cn(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[12.5px]",children:[e.jsx("div",{className:"mb-1 text-ink-secondary",children:t("people.link")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 select-all break-all text-ink",children:s}),e.jsxs("button",{type:"button",onClick:a,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:[n==="copied"?e.jsx(oe,{size:13,className:"text-success"}):n==="failed"?e.jsx(De,{size:13,className:"text-danger"}):e.jsx(En,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Sr({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(L,{title:t("people.title"),subtitle:t("people.portal.subtitle"),children:[e.jsxs("div",{"data-people-portal":!0,className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:t("people.portal.managed")}),s&&e.jsxs("a",{href:s,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:[t("people.portal.open")," ",e.jsx(Ze,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Cr(){const[s,n]=r.useState(null),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState([]),[c,x]=r.useState(typeof window<"u"?window.location.origin:""),[m,g]=r.useState(null),[p,y]=r.useState(""),[k,N]=r.useState("member"),[v,j]=r.useState(null),[C,w]=r.useState(!1),[D,I]=r.useState(!1),[f,b]=r.useState(null),h=r.useCallback(async()=>{I(!0),b(null);try{const[P,V,J,$,W]=await Promise.all([U("/api/config"),U("/api/auth/sessions").catch(()=>({sessions:[]})),U("/api/usage?groupBy=user").catch(()=>({groups:[]})),U("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(F=>F.ok?F.json():null).catch(()=>null)]),z={admins:Array.isArray(P?.signIn?.admins)?P.signIn.admins:[],members:Array.isArray(P?.signIn?.members)?P.signIn.members:[]},G=ms(P);i(G),l(z);const ne=Array.isArray(V?.sessions)?V.sessions:[],R=Array.isArray(J?.groups)?J.groups:[];u(G.authority==="portal"?Nr(ne,R):kr(z,ne,R)),typeof $?.publicUrl=="string"&&$.publicUrl&&x($.publicUrl),g(W?.capabilities?.emailSignIn===!0?!0:W?!1:null)}catch(P){b(P instanceof Error?P.message:String(P))}finally{I(!1)}},[]);r.useEffect(()=>{ps().then(P=>{n(P),Xe(P)&&h()})},[h]);const E=async P=>{w(!0),b(null);try{await U("/api/config",{method:"PUT",body:JSON.stringify({signIn:P})}),await h()}catch(V){b(V instanceof Error?V.message:String(V))}finally{w(!1)}},A=async()=>{if(!o||C)return;const P=vr(p);if(!P){b(t("remote.signInAccess.invalid"));return}await E(Ft(o,P,k)),y(""),j($t(c,P))};return Xe(s)?a?.authority==="portal"?e.jsx(Sr,{peopleUrl:a.peopleUrl,people:d}):e.jsxs(L,{title:t("people.title"),subtitle:t("people.subtitle"),children:[m===!1&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[12.5px] text-ink-secondary",children:t(a?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:P=>{P.preventDefault(),A()},children:[e.jsx("input",{value:p,onChange:P=>y(P.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:C,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("select",{value:k,onChange:P=>N(P.target.value),"aria-label":t("people.colRole"),disabled:C,className:"rounded-lg border border-hairline/40 bg-inset px-2 py-2 text-[12.5px] text-ink focus:outline-none",children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:C||!p.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[C?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(Te,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:D||C,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(xe,{size:13,className:_(D&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Ts,{link:v}),f&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:f}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:d,busy:C,onRole:(P,V)=>{o&&E(Ft(o,P.entry,V))},onRemove:P=>{o&&E(jr(o,P.entry))},onLink:P=>j($t(c,P.entry))})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.note")})]}):null}const Ve="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function Er({entry:s}){const[n,a]=r.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:ai(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:ii(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:s.summary}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(In,{size:12,className:_("transition-transform",n&&"rotate-90")}),t("activity.changed",{paths:(s.changed??[]).join(", ")||"—"})]}),i&&n&&s.type==="admin"&&e.jsxs("dl",{className:"mt-1 grid grid-cols-[auto_1fr_1fr] gap-x-3 gap-y-0.5 rounded-lg bg-inset p-2 text-[12px]",children:[e.jsx("dt",{}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.before")}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.after")}),(s.changed??Object.keys({...s.before,...s.after})).map(o=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.before?.[o])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.after?.[o])})]},o))]})]})]})})}function Ar(){const[s,n]=r.useState({who:"",what:"all",from:"",to:""}),[a,i]=r.useState([]),[o,l]=r.useState(0),[d,u]=r.useState(null),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=si(s),y=r.useCallback(async()=>{x(!0),g(null);try{const N=await U(`/api/admin-activity${p}`);i(N.entries),l(N.total),u(N.retentionDays)}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}},[p]);r.useEffect(()=>{const N=window.setTimeout(()=>{y()},250);return()=>window.clearTimeout(N)},[y]);const k=N=>n(v=>({...v,...N}));return e.jsxs(L,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(d??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:N=>k({who:N.target.value}),placeholder:t("activity.whoPlaceholder"),className:_(Ve,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx("select",{value:s.what,onChange:N=>k({what:N.target.value}),className:Ve,children:ni.map(N=>e.jsx("option",{value:N,children:t(`activity.what.${N}`)},N))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:N=>k({from:N.target.value}),className:Ve})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:N=>k({to:N.target.value}),className:Ve})]}),e.jsx("button",{type:"button",onClick:()=>{y()},disabled:c,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:c?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${p}`,download:!0,className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12.5px] font-medium text-ink hover:bg-control/70",children:[e.jsx(gs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:t("activity.error",{message:m})}),!m&&a.length===0&&!c&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((N,v)=>e.jsx(Er,{entry:N},`${N.at}-${v}`))}),o>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(o)})})]})}function Ir(s){const n=s.trim();if(!n||/[\s\\?#@%]/.test(n))return null;try{const a=new URL(n.includes("://")?n:`https://${n}`),i=a.hostname.replace(/\.$/,"");return a.protocol!=="https:"||a.port||a.pathname!=="/"||!i.includes(".")||i.length>253||/^[\d.]+$/.test(i)||!i.split(".").every(o=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(o))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Pr({domain:s,serverIpv4:n}){const a=Ir(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([o,l])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0",children:l?e.jsx(Re,{command:l,copyLabel:t("settings.domain.copyField",{field:o})},l):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},o))}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Rr(s){return`bots.example.com {
1
+ import{m as Ne,u as K,r,j as e,t,cj as te,v as Y,ck as L,c as _,d as H,p as oe,E as Ze,g as U,aJ as sn,aW as ds,P as Te,R as xe,cl as Re,aM as Ge,cm as nn,cn as an,co as rn,cp as ln,as as on,cq as At,cr as $e,cs as us,ct as cn,cu as dn,cv as un,cw as It,cx as xn,a9 as pn,O as ke,a4 as mn,bf as gn,T as we,w as mt,cy as hn,cz as xs,cA as fn,cB as Ye,cC as bn,ag as Pt,cD as yn,bc as vn,cE as jn,cF as Rt,cG as kn,au as ps,cH as ms,cI as Nn,av as wn,a6 as Sn,cJ as Cn,X as De,y as En,b0 as le,b1 as ue,q as An,cK as gs,aa as In,aw as Pn,x as ut,cL as hs,cM as fs,cN as bs,bi as Rn,cO as Bn,bI as Dn,cP as Tn,cQ as ze,ax as zn,cR as Mn,cS as On,cT as Un,cU as ys,aY as vs,aZ as je,a_ as Be,aX as Ln,cV as _n,B as Fn,a$ as Bt,b2 as $n,S as js,cW as Kn,cX as Hn,cY as Vn,cZ as Wn,c_ as qn,c$ as Jn,at as Gn,d0 as Dt,d1 as Yn,d2 as Xn,d3 as Tt,ba as ks,aj as Qn,d4 as Zn,d5 as ea,Z as ta,aG as sa,bZ as ot,M as Ns,d6 as na,aF as aa,d7 as ia,b$ as zt,d8 as ra,o as la,aQ as oa,d9 as ca,da,db as ua,dc as xa,br as ws,bq as pa,be as ma,b_ as ga,bB as ha,dd as fa,de as ba,df as ya,dg as va,dh as ja,di as ka,dj as Na,dk as wa,dl as Sa,dm as Ca,dn as Ea,dp as Aa,dq as Ia,dr as Pa,ds as Ra,dt as Ba,du as Da,dv as Ta,dw as za,dx as Ma,dy as Oa,dz as Ua,dA as La,dB as _a,dC as Fa,dD as $a,dE as Ka,dF as Ha,dG as Va,dH as Wa,dI as qa}from"./index-CyM91z0J.js";import{a as Ja,M as Ga,w as Ya,A as me,b as Xa,O as Qa,V as Za,c as ei,B as ti}from"./MacLocalControl-ExdXHVUv.js";import{a as si,A as ni,w as ai,d as ii,b as Mt}from"./activity-D_puBfZo.js";import{b as ri}from"./RoutinesPage-Buk5-r3o.js";import{DefaultBotSettings as li}from"./NewBotDialog-ftDBMjWR.js";import{U as xt,C as oi}from"./user-EQ8rI0f4.js";import"./WebhooksPanel-G_NWjHOP.js";import"./VisibilitySection-y8Adk-c4.js";import"./image-plus-D9o3v9bi.js";import"./CloudBackendPicker-BR42-xBg.js";const ci=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]],di=Ne("circle-user",ci);const ui=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],xi=Ne("hard-drive",ui);const pi=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ss=Ne("palette",pi);const mi=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],gi=Ne("scroll-text",mi);const hi=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],fi=Ne("server",hi);const bi=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],yi=Ne("terminal",bi);const vi=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],ji=Ne("unplug",vi),ki="https://typesafe.ai",Ni={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},Ot={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"};function wi(s,n=!1){if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Ot[s.reason])return t(Ot[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const a=Ni[s.reason];return a?t(a):t("decider.error.other")}const Si=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Ci(){const{state:s,dispatch:n}=K(),a=s.config?.decider,i=a?.configured??!1,o=i&&a?.included===!0,l=i&&!o,d=a?.enabled??!1,u=a?.jobs.roomRouting??!0,[c,x]=r.useState(""),[m,g]=r.useState(!1),[p,y]=r.useState(!1),[k,N]=r.useState(!1),[v,j]=r.useState(null),[C,w]=r.useState(null),D=c.trim(),I=!D&&l,f=A=>n({type:"configStatus",config:A}),b=async A=>{if(!p){y(!0),j(null);try{f(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:A})}))}catch(P){j(P instanceof Error?P.message:String(P))}finally{y(!1)}}},h=async()=>{if(!(m||!D&&!l)){g(!0),j(null),w(null);try{const A=window.ogb?.setCredential?await window.ogb.setCredential("jevApiKey",D):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{key:D}})});f(A),x("")}catch(A){j(A instanceof Error?A.message:String(A))}finally{g(!1)}}},E=async()=>{if(k||m||!D&&!i)return;N(!0),w(null),j(null);const A=!D&&o;try{const P=await U("/api/decider/test",{method:"POST",body:JSON.stringify(D?{key:D}:{})});w(P.ok?{ok:!0,text:t("decider.test.ok",{ms:String(P.latencyMs)})}:{ok:!1,text:wi(P,A)})}catch(P){w({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("div",{children:e.jsx(te,{title:t("decider.master"),subtitle:i?void 0:t("decider.masterNeedsKey"),children:e.jsx(Y,{"data-testid":"decider-master","aria-label":t("decider.master"),checked:d,disabled:!i||p||!s.config,onClick:()=>{b({enabled:!d})},className:"cursor-pointer"})})}),e.jsxs(L,{title:t("decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:_("size-1.5 rounded-full",i?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:i?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):i?t("decider.status.connected"):t("decider.status.notConnected")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:c,onChange:A=>{w(null),j(null),x(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void h(),disabled:m,placeholder:l?t("keys.replace"):t("decider.key.placeholder"),"aria-label":t("decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{h()},disabled:m||!D&&!l,title:I?t("keys.removeKey"):t("common.save"),className:_("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",I?"text-danger":"text-ink"),children:m?e.jsx(H,{size:13,className:"animate-spin"}):I?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{E()},disabled:k||m||!D&&!i,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:k?t("keys.testing"):t("keys.test")})]}),v&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:v}),C&&e.jsx("p",{role:"status",className:_("mt-1 text-[12px]",C.ok?"text-success":"text-danger"),children:C.text}),e.jsxs("a",{href:ki,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.key.getKey"),e.jsx(Ze,{size:11,"aria-hidden":"true"})]})]}),e.jsx(L,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(Y,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:d&&u,disabled:!d||p,onClick:()=>{b({jobs:{roomRouting:!u}})},className:"cursor-pointer"})]}),Si.map(A=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(A)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},A))]})})]})}const Cs=["openai","anthropic","google","azure","aws","xai","deepseek","meta","mistral","qwen","moonshot","cohere","openrouter"],Es=128*1024,fe=1024,As=["image/png","image/jpeg","image/webp"],Ei={openai:"OpenAI",anthropic:"Anthropic",google:"Google Gemini",azure:"Microsoft Azure",aws:"Amazon Bedrock (AWS)",xai:"xAI",deepseek:"DeepSeek",meta:"Meta",mistral:"Mistral AI",qwen:"Qwen",moonshot:"Moonshot AI",cohere:"Cohere",openrouter:"OpenRouter"};function Ai(s){const n=s.endsWith("==")?2:s.endsWith("=")?1:0;return Math.floor(s.length*3/4)-n}function Ii(s,n){const a=c=>s[c]*256+s[c+1],i=c=>s[c]+s[c+1]*256,o=c=>s[c]+s[c+1]*256+s[c+2]*65536,l=c=>s[c]+s[c+1]*256+s[c+2]*65536+s[c+3]*16777216,d=c=>s[c]*16777216+s[c+1]*65536+s[c+2]*256+s[c+3];if(n==="image/png")return s.length<33||s.slice(0,8).join(",")!=="137,80,78,71,13,10,26,10"||String.fromCharCode(...s.slice(12,16))!=="IHDR"||s.slice(-8).join(",")!=="73,69,78,68,174,66,96,130"?null:{width:d(16),height:d(20)};if(n==="image/jpeg"){if(s.length<12||s[0]!==255||s[1]!==216||s.at(-2)!==255||s.at(-1)!==217)return null;for(let c=2;c+8<s.length;){if(s[c]!==255){c+=1;continue}const x=s[c+1];if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(x))return{height:a(c+5),width:a(c+7)};if(x===216||x===217||x===1||x>=208&&x<=215){c+=2;continue}const m=a(c+2);if(m<2)return null;c+=m+2}return null}if(s.length<30||String.fromCharCode(...s.slice(0,4))!=="RIFF"||String.fromCharCode(...s.slice(8,12))!=="WEBP"||l(4)+8!==s.length)return null;const u=String.fromCharCode(...s.slice(12,16));if(u==="VP8X")return{width:o(24)+1,height:o(27)+1};if(u==="VP8L"&&s[20]===47){const c=s[21]|s[22]<<8|s[23]<<16|s[24]<<24;return{width:(c&16383)+1,height:(c>>>14&16383)+1}}return u==="VP8 "&&s[23]===157&&s[24]===1&&s[25]===42?{width:i(26)&16383,height:i(28)&16383}:null}function Pi(s){if(s.kind==="preset")return Cs.includes(s.preset)?null:"Choose a supported provider icon.";const n=/^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/]+={0,2})$/.exec(s.dataUrl);if(!n)return"Upload a PNG, JPEG, or WebP image.";const a=Ai(n[2]);if(a>Es)return"Provider icons must be 128 KB or smaller.";let i;try{i=atob(n[2])}catch{return"The uploaded image is not valid base64."}if(i.length!==a)return"The uploaded image is not valid base64.";const o=Uint8Array.from(i,d=>d.charCodeAt(0)),l=Ii(o,n[1]);return l?l.width<1||l.height<1||l.width>fe||l.height>fe||l.width*l.height>fe**2?`Provider icons must be at most ${fe} × ${fe} pixels.`:null:"The uploaded image is incomplete or does not match its file type."}function Ri(s){return new Promise((n,a)=>{const i=new Image;i.onerror=()=>a(new Error(t("engines.icon.decodeError"))),i.onload=()=>n({width:i.naturalWidth,height:i.naturalHeight}),i.src=s})}async function Bi(s,n=Ri){if(!As.includes(s.type))throw new Error(t("engines.icon.formatError"));if(s.size>Es)throw new Error(t("engines.icon.sizeError"));const a=new Uint8Array(await s.arrayBuffer());let i="";for(let u=0;u<a.length;u+=8192)i+=String.fromCharCode(...a.subarray(u,u+8192));const o={kind:"custom",dataUrl:`data:${s.type};base64,${btoa(i)}`};if(Pi(o))throw new Error(t("engines.icon.invalidError",{dimension:fe}));const d=await n(o.dataUrl);if(d.width<1||d.height<1||d.width>fe||d.height>fe)throw new Error(t("engines.icon.dimensionError",{dimension:fe}));return o}function Di({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(null),d=r.useRef(!1),u=async m=>{if(!d.current){d.current=!0,i(!0),l(null);try{const g=typeof m=="function"?await m():m;await U(`/api/instances/${encodeURIComponent(s.instanceId)}/icon`,{method:"PATCH",body:JSON.stringify({icon:g})}),await n()}catch(g){l(g instanceof Error?g.message:String(g))}finally{d.current=!1,i(!1)}}},c=m=>{const g=m.currentTarget,p=g.files?.[0];p&&u(()=>Bi(p)).finally(()=>{g.value=""})},x=s.icon?.kind==="preset"?s.icon.preset:s.icon?.kind==="custom"?"custom":"default";return e.jsxs("section",{"aria-label":t("engines.icon.label"),className:"mb-3 rounded-xl border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-xl border border-hairline/30 bg-panel",children:e.jsx(sn,{instance:s,size:24})}),e.jsxs("label",{className:"min-w-40 flex-1 text-[12px] font-medium text-ink",children:[t("engines.icon.label"),e.jsxs("select",{"aria-label":t("engines.icon.selectAria",{name:s.displayName}),value:x,disabled:a,onChange:m=>{m.target.value==="default"?u(null):m.target.value!=="custom"&&u({kind:"preset",preset:m.target.value})},className:"mt-1 block w-full rounded-lg border border-hairline/40 bg-inset px-2.5 py-2 text-[12px] text-ink focus:border-accent/60 focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"default",children:t("engines.icon.default")}),s.icon?.kind==="custom"&&e.jsx("option",{value:"custom",children:t("engines.icon.custom")}),Cs.map(m=>e.jsx("option",{value:m,children:Ei[m]},m))]})]}),a&&e.jsx(H,{size:15,"aria-label":t("engines.icon.saving"),className:"animate-spin text-ink-secondary"}),s.icon&&e.jsxs("button",{type:"button",disabled:a,onClick:()=>{u(null)},className:"inline-flex items-center gap-1 rounded-lg px-2 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:[e.jsx(ds,{size:13,"aria-hidden":"true"}),t("engines.icon.reset")]})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-ink-secondary",children:t("engines.icon.help")}),e.jsx("input",{type:"file",accept:As.join(","),disabled:a,onChange:c,"aria-label":t("engines.icon.uploadAria",{name:s.displayName}),className:"mt-2 block w-full text-[11px] text-ink-secondary file:mr-2 file:rounded-lg file:border-0 file:bg-control file:px-2.5 file:py-1.5 file:text-[11px] file:font-medium file:text-ink hover:file:bg-raised-hover disabled:opacity-50"}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Is({instance:s,onSaved:n,onCancel:a}){const{refreshInstances:i}=K(),[o,l]=r.useState(s?.displayName??""),[d,u]=r.useState(s?.claudeAccount?.configDir??""),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=!s||o.trim()!==s.displayName||d.trim()!==s.claudeAccount?.configDir,y=!!(s?.claudeAccount?.configDir&&!d.trim()),k=async()=>{if(!(c||!o.trim()||!p||y)){x(!0),g(null);try{await U(s?`/api/instances/${encodeURIComponent(s.instanceId)}`:"/api/instances/claude-accounts",{method:s?"PATCH":"POST",body:JSON.stringify({displayName:o.trim(),...d.trim()?{configDir:d.trim()}:{}})}),await i().catch(()=>{}),n()}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}}};return e.jsxs("form",{className:"flex min-w-0 flex-col gap-3",onSubmit:N=>{N.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:o,onChange:N=>l(N.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-ink-secondary hover:text-ink",children:t("engines.account.advanced")}),e.jsxs("label",{className:"mt-2 flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.configDir"),e.jsx("input",{value:d,onChange:N=>u(N.target.value),placeholder:t(s?"engines.account.defaultDir":"engines.account.configDirPlaceholder"),maxLength:4096,spellCheck:!1,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.configDirHint")}),s&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.changeDirHint")})]}),!s&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("engines.account.addHint")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex justify-end gap-2",children:[a&&e.jsx("button",{type:"button",onClick:a,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!o.trim()||!p||y,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),s?t("common.save"):t("engines.account.add")]})]})]})}function Ti(){const[s,n]=r.useState(!1);return s?e.jsx("div",{className:"rounded-xl border border-hairline/40 p-3",children:e.jsx(Is,{onSaved:()=>n(!1),onCancel:()=>n(!1)})}):e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-fit items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(Te,{size:13}),t("engines.account.add")]})}function zi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(!1),[c,x]=r.useState(!1),[m,g]=r.useState(!1),[p,y]=r.useState(null),k=s.claudeAccount;if(!k)return null;const N=n.bots.filter(h=>h.modelSelection.instanceId===s.instanceId).length,v=N>0,j=s.snapshot.authenticated===!0,C=s.snapshot.account?.method==="api-key",w=j&&s.authentication?.signOut===!0&&!C,D=j?C?t("engines.account.apiKey"):[s.snapshot.account?.email,s.snapshot.account?.organization].filter(Boolean).join(" · "):"",I=async()=>{if(!(o||m)){l(!0),y(null);try{await i()}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},f=async()=>{if(u(!1),!(o||m||k.isDefault||v)){l(!0),y(null);try{await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"}),await i().catch(()=>{})}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},b=async()=>{if(x(!1),!(o||m||!w)){g(!0),y(null);try{const{instances:h}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:h})}catch(h){y(h instanceof Error?h.message:String(h))}finally{g(!1)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:_("min-w-0 break-words",j?"text-success":"text-ink-secondary"),children:[j?t("engines.account.connected"):s.snapshot.authenticated===!1?t("model.signInRequired"):t("engines.account.unknown"),D&&` · ${D}`]}),k.isDefault&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:t("engines.account.default")}),e.jsxs("button",{type:"button",onClick:()=>{I()},disabled:o||m,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o&&"animate-spin")}),t("engines.account.check")]})]}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:t("engines.account.signInHint")}),k.signInShell==="powershell"&&e.jsx("p",{className:"text-ink-secondary",children:t("engines.account.powershell")}),e.jsx(Re,{command:k.signInCommand,copyLabel:t("engineSetup.copyCommand")}),e.jsx("fieldset",{disabled:o||m,className:"min-w-0",children:e.jsx(Is,{instance:s,onSaved:()=>{}},`${s.displayName}:${k.configDir}`)}),w&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!0),disabled:o||m,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:m?t("engines.account.signingOut"):t("engines.account.signOut")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.signOutHint")}),v&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.signOutAssigned",{count:String(N)})})]}),!k.isDefault&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o||m||v,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:t("engines.account.remove")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t(v?"engines.account.assigned":"engines.account.removeHint")})]})]})]}),p&&e.jsx("p",{role:"alert",className:"text-danger",children:p}),e.jsx(Ge,{open:d,title:t("engines.account.removeTitle",{name:s.displayName}),body:t("engines.account.removeHint"),confirmLabel:t("engines.account.remove"),tone:"neutral",onCancel:()=>u(!1),onConfirm:()=>{f()}}),e.jsx(Ge,{open:c,title:t("engines.account.signOutTitle",{name:s.displayName}),body:t("engines.account.signOutHint"),confirmLabel:t("engines.account.signOut"),onCancel:()=>x(!1),onConfirm:()=>{b()}})]})}function Mi(){const{dispatch:s}=K(),[n,a]=r.useState(!1),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(null),x=async()=>{if(!(l||!i.trim())){d(!0),c(null);try{const{instances:m}=await U("/api/instances/chatgpt-accounts",{method:"POST",body:JSON.stringify({displayName:i.trim()})});s({type:"instances",instances:m}),a(!1),o("")}catch(m){c(m instanceof Error?m.message:String(m))}finally{d(!1)}}};return n?e.jsxs("form",{className:"min-w-0 space-y-3 rounded-xl border border-hairline/40 p-3",onSubmit:m=>{m.preventDefault(),x()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:i,onChange:m=>o(m.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:l,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("engineSetup.chatgpt.addAccountHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a(!1),disabled:l,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:l||!i.trim(),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[l&&e.jsx(H,{size:13,className:"animate-spin"}),t("engineSetup.chatgpt.addAccount")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex w-fit items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(Te,{size:13}),t("engineSetup.chatgpt.addAccount")]})}function Oi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),m=s.snapshot.account?.email,g=s.authentication?.signOut===!0,p=s.snapshot.chatgptPlan===!0,y=t(p?"engineSetup.chatgpt.signOutHint":"engineSetup.device.signOutHint"),k=n.bots.filter(j=>j.modelSelection.instanceId===s.instanceId).length,N=async()=>{if(!o){l("check"),x(null);try{await i()}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}},v=async()=>{if(u(!1),!(o||!g)){l("signOut"),x(null);try{const{instances:j}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 break-words text-success",children:[e.jsx(oe,{size:13,className:"shrink-0"}),t(p?"engineSetup.chatgpt.connectedAccount":"engineSetup.device.connectedAccount"),m&&e.jsxs("span",{className:"text-ink-secondary",children:["· ",m]})]}),e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:o!==null,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o==="check"&&"animate-spin")}),t("engines.account.check")]})]}),p&&e.jsx(nn,{instanceId:s.instanceId},s.instanceId),g&&e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:y}),k>0&&e.jsx("p",{className:"leading-relaxed text-warning",children:t(p?"engineSetup.chatgpt.signOutAssigned":"engineSetup.device.signOutAssigned",{count:String(k)})}),e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o!==null,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:o==="signOut"?t("engineSetup.device.signingOut"):t("engineSetup.device.signOut")})]})]}),c&&e.jsx("p",{role:"alert",className:"text-danger",children:c}),e.jsx(Ge,{open:d,title:t("engineSetup.device.signOutTitle"),body:y,confirmLabel:t("engineSetup.device.signOut"),onCancel:()=>u(!1),onConfirm:()=>{v()}})]})}function Ut(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Ui({instance:s,initial:n={kind:"idle"}}){const[a,i]=r.useState(n),[o,l]=r.useState(null),d=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,u=async()=>{l(null),i({kind:"scanning"});try{const m=await U(d);i(m.folders>0?{kind:"found",bytes:m.bytes,complete:m.complete}:{kind:"none"})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},c=async()=>{l(null),i({kind:"deleting"});try{const m=await U(`${d}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:m.freedBytes,remaining:m.remaining})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},x=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xi,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||x)&&e.jsxs("button",{type:"button",onClick:()=>{u()},disabled:x,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Ut(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{c()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Ut(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Li({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[o,l]=r.useState(s.cliCandidates??null),[d,u]=r.useState(""),[c,x]=r.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[m,g]=r.useState(!1),[p,y]=r.useState(null),[k,N]=r.useState(!1),[v,j]=r.useState(null),C=r.useRef(!1);r.useEffect(()=>{C.current||(C.current=!0,U(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:h})=>{l(h),s.cli&&(h.includes(s.cli)?u(s.cli):x(s.cli))}).catch(()=>l(h=>h??[])))},[n,s.cli]);const w=c.trim()||d,D=w!==(s.cli??""),I=m||k;r.useEffect(()=>{y(null)},[w]);const f=()=>{if(I||!w||!D)return;N(!0),j(null);const h=w;U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:h})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(E=>j(E.message)).finally(()=>N(!1))},b=()=>{I||!w||!D||(g(!0),j(null),U("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(h=>{y(h),h.ok&&f()}).catch(h=>j(h.message)).finally(()=>g(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[o!==null&&o.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:c.trim()?"":d,onChange:h=>{u(h.target.value),x("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,className:"w-full appearance-none rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),o.map(h=>e.jsx("option",{value:h,children:h},h))]}),e.jsx(pn,{size:13,className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"})]}),e.jsx("input",{type:"text",value:c,onChange:h=>x(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),!(!w||!D)&&b())},placeholder:o?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:I,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),p&&!p.ok&&p.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(ke,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:p.message})})]}),p?.ok&&p.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:p.version})}),v&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:v}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),p&&!p.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y(null),disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>f(),disabled:I,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:k?e.jsx(H,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:b,disabled:I||!w||!D,className:_("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:I?e.jsx(H,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})})]})]})}function _i({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),o=on(a),[l,d]=r.useState(!1),[u,c]=r.useState(!1),[x,m]=r.useState(null),[g,p]=r.useState(null),y=r.useRef(null);r.useEffect(()=>{y.current!==null&&y.current!==s.cli&&i(!1),y.current=s.cli??null},[s.cli]);const k=()=>{l||u||(d(!0),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>p(j.message)).finally(()=>d(!1)))},N=()=>{l||u||(c(!0),m(null),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{m(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>p(j.message)).finally(()=>c(!1)))},v=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.readOnly?e.jsxs(At,{instance:s,children:[v,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!$e(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(At,{instance:s,children:[v,e.jsx(Di,{instance:s}),!$e(s)&&e.jsx(us,{instance:s,intent:s.access==="custom"?"inject":"cloud",unframed:!0}),$e(s)&&e.jsx(cn,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(dn,{update:s.snapshot.update,instance:s,className:"mt-3"}),s.snapshot.warning&&e.jsx(un,{warning:s.snapshot.warning,className:"mt-3"}),s.claudeAccount&&e.jsx(zi,{instance:s}),$e(s)&&s.snapshot.authenticated===!0&&((s.authentication?.method==="device-code"||s.authentication?.method==="browser-pkce")&&It(s.driverKind)==="codex"?e.jsx(Oi,{instance:s}):s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t(xn[It(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&!s.claudeAccount&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Ui,{instance:s}),e.jsxs("details",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[11.5px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:N,disabled:l||u,className:"flex shrink-0 items-center gap-1 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[u?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(xe,{size:12}),u?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:k,disabled:l||u,className:"shrink-0 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:l?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:u,"aria-expanded":a,className:_("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),x&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:x})}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g}),o.shown&&e.jsx("div",{className:o.className,...o.exitProps,children:e.jsx(Li,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})]})}function Fi(){const{state:s}=K(),n=s.instances.filter(a=>a.readOnly||a.cli!==void 0||a.cliDefault!==void 0||a.snapshot.state==="unavailable"||an(a));return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(rn,{})]}),e.jsx(ln,{instances:n,renderEngine:a=>e.jsx(_i,{instance:a})}),e.jsxs("div",{className:"space-y-3 border-t border-hairline/40 pt-4",children:[e.jsx(Ti,{}),s.instances.some(a=>a.snapshot.chatgptPlan&&!a.readOnly&&!a.snapshot.authenticationUnavailableReason)&&e.jsx(Mi,{})]})]})}const $i=[1e3,2e3,4e3];function Ki(s){return new Promise(n=>window.setTimeout(n,s))}const Hi={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Vi={unmanaged:"vm.state.notManaged","in-use":"vm.state.inUse",stopped:"vm.state.stopped",running:"vm.state.running",attention:"vm.state.attention",sleeping:"vm.state.sleeping","going-to-sleep":"vm.state.goingToSleep",starting:"vm.state.starting",restarting:"vm.state.restarting",removing:"vm.state.removing",paused:"vm.state.paused"};function gt(s){return t(Vi[s])}function Wi(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function qi(s){return gt(Wi(s))}function Ji(s){return s.inUse?"in-use":s.state==="removing"?"removing":["archived","stopped"].includes(s.state)?"sleeping":["archiving","stopping"].includes(s.state)?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning","starting"].includes(s.state)?"starting":"attention"}function Ps(s,n,a){const i={...a},o=new Set(s.map(d=>d.boxId)),l=s.flatMap(d=>{const u=a[d.boxId];return u==="deleted"?[]:u==="deleting"?[{...d,state:"removing"}]:u!=="sleeping"?[d]:["archived","stopped"].includes(d.state)?(delete i[d.boxId],[d]):[{...d,state:"archived"}]});for(const d of n)a[d.boxId]!=="sleeping"||o.has(d.boxId)||l.push({...d,state:"archived"});for(const[d,u]of Object.entries(a))(u==="deleted"||u==="deleting")&&!o.has(d)&&delete i[d];return{instances:l,overrides:i}}function Gi(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ps(Array.isArray(s.instances)?s.instances:[],n,a)}function Yi(s){return["idle","ready","running"].includes(s.state)}function Xi(s){return s.inUse?"in-use":s.state==="running"?"running":s.state==="restarting"?"restarting":s.state==="removing"?"removing":["created","exited"].includes(s.state)?"stopped":s.state==="paused"?"paused":"attention"}function ht(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}const Qi={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function Ke(s,n){return[Qi[s],{signal:n}]}function ft(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Zi(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:ft(`/api/bots/${s.botId}/local-computer/remove`,{})}}function er(s,n){return{confirmation:s==="delete"?t("vm.confirm.deleteCloud",{subject:n.orphaned?t("vm.confirm.orphanCloud"):t("vm.confirm.ownedCloud",{name:n.ownerName??""})}):null,request:ft(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function tr(s){const n=ht(s.name);return{confirmation:t("vm.confirm.removeVps",{subject:s.orphaned?t("vm.confirm.orphanVps",{id:n}):t("vm.confirm.ownedVps",{name:s.ownerName??""})}),request:ft(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name})}}function ct(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function sr({instances:s,configured:n,sshAlias:a,loading:i,removingName:o,error:l,unavailableReason:d,onRefresh:u,onRemove:c}){return e.jsxs(L,{title:t("vm.vps.title"),subtitle:t("vm.vps.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.vps.sshHost",{alias:a??t("vm.vps.configuredFallback")}):n===!1?t("vm.vps.needsAlias"):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:u,disabled:i||o!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(i&&"animate-spin")})," ",t("vm.refresh")]})]}),l&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:l}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):d?t("vm.vps.unavailable",{reason:d}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":i||o!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):d?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",d]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(fi,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((x,m)=>{const g=Xi(x),p=gt(g),y=o===x.name,k=ht(x.name);return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.vps.orphan",{id:k}):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="stopped"||g==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:i||x.inUse||o!==null,"aria-busy":y||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("vm.vps.remove")]})]},x.name)})})]})}function nr({instances:s,configured:n,loading:a,pending:i,error:o,unavailableReason:l,onRefresh:d,onSleep:u,onDelete:c}){return e.jsxs(L,{title:t("vm.cloud.title"),subtitle:t("vm.cloud.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.cloud.includesOrphans"):n===!1?t("vm.cloud.needsKey"):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):l?t("vm.cloud.unavailable",{reason:l}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(mt,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((x,m)=>{const g=Ji(x),p=gt(g),y=i?.boxId===x.boxId,k=Yi(x),N=g==="removing";return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.cloud.orphan"):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="sleeping"||g==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsxs("div",{className:"mt-1 break-all text-[11.5px] text-ink-secondary",children:[x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",x.name]}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>u(x),disabled:a||x.inUse||i!==null||!k,"aria-busy":y&&i?.action==="sleep"?!0:void 0,title:k?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:p.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[y&&i?.action==="sleep"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ga,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:a||x.inUse||i!==null||N,"aria-busy":y&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y&&i?.action==="delete"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]})]},x.boxId)})})]})}function ar({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:o,unavailableReason:l,onRefresh:d,onDelete:u}){return e.jsxs(L,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:l?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):l?t("vm.perBot.unavailable",{reason:l}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((c,x)=>{const m=qi(c),g=i===c.botId,p=c.managed===!0;return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:c.name}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",p?c.inUse||c.ready?"bg-success/15 text-success":c.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:m})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Hi[c.destination])})}),!p&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:t("vm.perBot.unmanaged")}),p&&c.problem&&!c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:c.problem}),p&&c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),p&&e.jsxs("button",{type:"button",onClick:()=>u(c),disabled:a||c.inUse||i!==null,"aria-busy":g||void 0,title:c.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:c.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[g?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]},c.botId)})})]})}function He({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:_("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(oe,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:_("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function Ie({action:s,pending:n,children:a,onClick:i,danger:o=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:_("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[12.5px] font-medium disabled:opacity-50",o?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(H,{size:13,className:"animate-spin"}),a]})}const Rs=5,Bs=1440,ir=480;function rr(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Rs&&a<=Bs?a:null}function lr({minutes:s,disabled:n,onSave:a}){const[i,o]=r.useState(String(s)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1);r.useEffect(()=>{l||o(String(s))},[s,l]);const g=async()=>{if(!l||x)return;const p=rr(i);if(p===null){c(t("vm.idle.range"));return}m(!0);try{await a(p),o(String(p)),d(!1),c("")}catch(y){c(y instanceof Error?y.message:t("vm.idle.error"))}finally{m(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[11.5px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:_("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",u?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Rs,max:Bs,step:1,inputMode:"numeric",value:i,disabled:n||x,"aria-invalid":!!u,"aria-describedby":u?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:p=>{o(p.target.value),d(!0),c("")},onBlur:()=>{g()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[12.5px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),u?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:u}):null]})}function Lt(){const s=K().state.config?.cloudHome===!0,[n,a]=r.useState(null),[i,o]=r.useState(!0),[l,d]=r.useState(null),u=r.useRef(null);r.useEffect(()=>()=>u.current?.abort(),[]);const[c,x]=r.useState(null),[m,g]=r.useState(!1),[p,y]=r.useState(0),[k,N]=r.useState([]),[v,j]=r.useState(2),[C,w]=r.useState(!1),[D,I]=r.useState(null),[f,b]=r.useState(null),[h,E]=r.useState(null),[A,P]=r.useState(0),[V,J]=r.useState([]),[$,W]=r.useState(null),[z,G]=r.useState(!0),[ne,R]=r.useState(null),[F,q]=r.useState(null),[ce,pe]=r.useState(null),[be,ye]=r.useState(0),X=r.useRef([]),se=r.useRef({}),[Se,ge]=r.useState([]),[ee,Le]=r.useState(null),[T,Q]=r.useState(null),[ie,ae]=r.useState(!0),[Me,et]=r.useState(null),[qs,yt]=r.useState(null),[Js,vt]=r.useState(null),[Gs,Ys]=r.useState(0),[Xs,ve]=r.useState(""),Oe=r.useCallback(async S=>{const B=await fetch(...Ke("status",S)),M=await B.json().catch(()=>({}));if(!S?.aborted){if(!B.ok)throw new Error(M.error??t("vm.err.status",{code:B.status}));return a(M),x(null),M}},[]),tt=r.useCallback(async S=>{const B=await fetch(...Ke("local-vms",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.inventory",{code:B.status}));const O=M;N(O.instances),j(O.maxInstances),b(O.available?null:O.problem??t("vm.err.runtimeUnavailable")),I(null)},[]),Ue=r.useCallback(async S=>{const B=await fetch(...Ke("cloud",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.cloudInventory",{code:B.status}));const O=M,Z=Gi(O,X.current,se.current);se.current=Z.overrides,X.current=Z.instances,J(Z.instances),W(O.configured===!0),q(O.available||!O.configured?null:O.problem??t("vm.err.cloudUnavailable")),R(null)},[]),st=r.useCallback(async S=>{const B=await fetch(...Ke("vps",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.vpsInventory",{code:B.status}));const O=M;ge(Array.isArray(O.instances)?O.instances:[]),Le(O.configured===!0),Q(typeof O.sshAlias=="string"?O.sshAlias:null),yt(O.available||!O.configured?null:O.problem??t("vm.err.vpsUnavailable")),et(null)},[]);r.useEffect(()=>{if(s)return;let S=!0,B,M;const O=async()=>{M=new AbortController;try{await Oe(M.signal)}catch(Z){S&&!(Z instanceof DOMException&&Z.name==="AbortError")&&(a(null),x(Z instanceof Error?Z.message:String(Z)))}finally{S&&(o(!1),B=window.setTimeout(()=>{O()},5e3))}};return O(),()=>{S=!1,M?.abort(),B!==void 0&&window.clearTimeout(B)}},[s,Oe,p]),r.useEffect(()=>{if(n?.mode!=="per-bot"){N([]),w(!1),I(null),b(null);return}const S=new AbortController;return w(!0),tt(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||I(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||w(!1)}),()=>S.abort()},[A,tt,n?.mode]),r.useEffect(()=>{const S=new AbortController;return G(!0),Ue(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||q(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||G(!1)}),()=>S.abort()},[be,Ue]),r.useEffect(()=>{const S=new AbortController;return ae(!0),st(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||yt(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||ae(!1)}),()=>S.abort()},[st,Gs]);const nt=async(S,B)=>{const M=await fetch(`/api/local-computer/${S}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:B}),O=await M.json().catch(()=>({})),Z={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!M.ok)throw new Error(O.error??t(Z[S]));return B.throwIfAborted(),a(O),O},jt=S=>window.ogb?.confirm?window.ogb.confirm(S):window.confirm(S),Ce=async S=>{if(l!==null||u.current)return;const B=new AbortController;u.current=B,d(S),x(null);try{if(S==="remove"&&!await jt(t("vm.confirm.deleteShared"))||S==="recreate"&&!await jt(t("vm.confirm.recreate")))return;let M;if(S==="recreate"?(await nt("remove",B.signal),M=await nt("run",B.signal)):M=await nt(S,B.signal),(S==="run"||S==="start"||S==="recreate")&&(M=await Ya(M,async()=>await Oe(B.signal)??M,B.signal),!M.ready))throw new Error(M.problem??t("vm.err.start"));await Oe(),ve(S==="remove"?t("vm.announce.deleted"):S==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(M){if(B.signal.aborted)return;x(M instanceof Error?M.message:String(M))}finally{u.current=null,B.signal.aborted||d(null)}},kt=async(S,B)=>{g(!0),x(null);try{const M=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:S,maxInstances:B}})}),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.policyError"));a(Z=>Z&&{...Z,mode:S,max_instances:B}),await Oe()}catch(M){x(M instanceof Error?M.message:String(M))}finally{g(!1)}},Qs=async S=>{const B=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:S}})}),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.idle.error"));a(O=>O&&{...O,idle_timeout_ms:S*6e4})},Zs=async S=>{if(!S.managed){I(t("vm.unmanagedError"));return}const B=ct(Zi(S),M=>window.confirm(M));if(B){E(S.botId),I(null);try{const M=await fetch(...B),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.deleteError"));await tt(),ve(t("vm.announce.deletedBot",{name:S.name}))}catch(M){I(M instanceof Error?M.message:String(M))}finally{E(null)}}},Nt=async(S,B)=>{const M=ct(er(S,B),O=>window.confirm(O));if(M){pe({boxId:B.boxId,action:S}),R(null),ve("");try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t(S==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const rt=S==="delete"&&Z?.pending===!0;se.current={...se.current,[B.boxId]:S==="delete"?rt?"deleting":"deleted":"sleeping"};const lt=Ps(X.current,X.current,se.current);se.current=lt.overrides,X.current=lt.instances,J(lt.instances);const Ee=B.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:B.ownerName??""});if(ve(rt?`${Ee}: ${t("vm.state.removing")}.`:t(S==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ee})),rt){for(const de of $i){await Ki(de);try{await Ue()}catch{}if(se.current[B.boxId]!=="deleting"){ve(t("vm.announce.cloudDeleted",{subject:Ee}));return}}const Ae={...se.current};delete Ae[B.boxId],se.current=Ae;const Fe=X.current.map(de=>de.boxId===B.boxId?{...de,state:B.state}:de);X.current=Fe,J(Fe);try{await Ue(),X.current.some(de=>de.boxId===B.boxId)||ve(t("vm.announce.cloudDeleted",{subject:Ee}))}catch(de){const tn=de instanceof Error?de.message:String(de);R(`${Ee}: ${t("vm.state.removing")}. ${tn}`)}return}try{await Ue()}catch(Ae){const Fe=Ae instanceof Error?Ae.message:String(Ae);R(t(S==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ee,detail:Fe}))}}catch(O){R(O instanceof Error?O.message:String(O))}finally{pe(null)}}},en=async S=>{const B=ht(S.name),M=ct(tr(S),O=>window.confirm(O));if(M){vt(S.name),et(null);try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t("vm.vpsRemoveError"));await st(),ve(t("vm.announce.vpsRemoved",{subject:S.orphaned?t("vm.announce.orphanVps",{id:B}):t("vm.confirm.ownedVps",{name:S.ownerName??""})}))}catch(O){et(O instanceof Error?O.message:String(O))}finally{vt(null)}}},he=n?.commands,_e=n?.ready===!0,wt=n?.container!=="missing",St=!!(wt&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ct=!i&&!n,Et=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),re=n?.mode==="per-bot",at=re&&n?.runtime==="container",it=re?!!(n?.daemonUp&&n?.image&&!at):_e;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Xs}),e.jsx(nr,{instances:V,configured:$,loading:z,pending:ce,error:ne,unavailableReason:F,onRefresh:()=>ye(S=>S+1),onSleep:S=>{Nt("sleep",S)},onDelete:S=>{Nt("delete",S)}}),e.jsx(sr,{instances:Se,configured:ee,sshAlias:T,loading:ie,removingName:Js,error:Me,unavailableReason:qs,onRefresh:()=>Ys(S=>S+1),onRemove:S=>{en(S)}}),e.jsx(Ja,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{title:t("vm.main.title"),subtitle:re?t("vm.main.perBotSubtitle",{host:Et}):t("vm.main.sharedSubtitle",{host:Et}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:_("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12.5px]",it?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(H,{size:12,className:"animate-spin"}):it?e.jsx(oe,{size:12}):e.jsx(mn,{size:9}),i?t("common.checking"):Ct?t("vm.main.statusUnavailable"):re&&it?t("vm.main.readyPerBot"):at?t("vm.main.perBotUnsupported"):_e?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{o(!0),y(S=>S+1),P(S=>S+1)},disabled:i||l!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12})," ",t("vm.main.recheck")]}),_e&&!re&&e.jsxs("a",{href:n?.viewer_url??he?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink hover:bg-control",children:[e.jsx(Ze,{size:12})," ",t("vm.main.watch")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c})]}),e.jsxs(L,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((S,B)=>e.jsx("button",{type:"button",disabled:!n||m,onClick:()=>{kt(S,n?.max_instances??2)},className:_("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",B>0&&"border-l border-hairline/40",n?.mode===S?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:S==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},S))}),re&&e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("vm.isolation.max")}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx("select",{"aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||m,onChange:S=>{kt(n?.mode??"shared",Number(S.target.value))},className:"rounded-lg border border-hairline/40 bg-control px-2.5 py-1.5 text-[13px] text-ink disabled:opacity-50",children:[1,2,3,4,5,6,7,8].map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsx(lr,{minutes:n?Math.round(n.idle_timeout_ms/6e4):ir,disabled:!n||m,onSave:Qs}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(H,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(L,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(He,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),he?.install?e.jsx(Re,{command:he.install}):e.jsx("a",{href:"https://podman.io/docs/installation",target:"_blank",rel:"noreferrer",className:"text-[13px] text-accent hover:underline",children:t("vm.setup.podmanGuide")})]}),e.jsx(He,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?he?.runtimeStart?e.jsx(Re,{command:he.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(He,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ie,{action:"pull",pending:l,onClick:()=>{Ce("pull")},children:t("vm.setup.prepare")}),he?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.pull})})]})]}),e.jsxs(He,{n:4,title:re?t("vm.setup.step4PerBot"):St?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!re&&_e,children:[re?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:at?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):St?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ie,{action:"recreate",pending:l,onClick:()=>{Ce("recreate")},danger:!0,children:[e.jsx(ds,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ie,{action:"start",pending:l,onClick:()=>{Ce("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{action:"run",pending:l,onClick:()=>{Ce("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,he?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.run})})]})]})]})}),re&&e.jsx(ar,{instances:k,maxInstances:v||n?.max_instances||2,loading:C,deletingBotId:h,error:D,unavailableReason:f,onRefresh:()=>P(S=>S+1),onDelete:S=>{Zs(S)}}),Ct&&e.jsx(L,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(L,{title:t("vm.safety.title"),subtitle:re?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[wt&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ie,{action:"stop",pending:l,onClick:()=>{Ce("stop")},children:[e.jsx(gn,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ie,{action:"remove",pending:l,onClick:()=>{Ce("remove")},danger:!0,children:[e.jsx(we,{size:12})," ",re?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.20.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function or(s,n){return s.error?{kind:"error",title:t("remote.status.attention"),detail:s.error}:n&&s.tailnetName?{kind:"ready",title:t("remote.tailscale.ready",{name:s.tailnetName}),detail:t("remote.tailscale.readyDetail")}:s.tailscale?{kind:"magicdns",title:t("remote.tailscale.magicDns"),detail:t("remote.tailscale.magicDnsDetail")}:s.enabled?{kind:"unavailable",title:t("remote.tailscale.notConnected"),detail:t("remote.tailscale.notConnectedDetail")}:{kind:"unchecked",title:t("remote.tailscale.already"),detail:t("remote.tailscale.alreadyDetail")}}function cr(s){return s.tailscaleFallback?{title:t("remote.pairing.tailscale.title"),subtitle:t("remote.pairing.tailscale.subtitle")}:s.localFallback?{title:t("remote.pairing.wifi.title"),subtitle:t("remote.pairing.wifi.subtitle")}:{title:t("remote.pairing.https.title"),subtitle:t("remote.pairing.https.subtitle")}}function dr(s){if(s.error)return{label:t("remote.status.attention"),good:!1};if(!s.enabled)return{label:t("remote.status.off"),good:!1};const n=s.devices.length;return n?{label:`${n} ${n===1?"device":"devices"} paired`,good:!0}:null}const ur=s=>{const n=Math.round((Date.now()-s)/1e3);if(n<90)return t("remote.time.justNow");const a=Math.round(n/60);if(a<60)return t("remote.time.minutes",{count:a});const i=Math.round(a/60);return i<24?t("remote.time.hours",{count:i}):t("remote.time.days",{count:Math.round(i/24)})},xr=s=>{try{return new URL(s).host}catch{return s}};function pr({profileEmail:s="",focusRequest:n=0}){const a=hn(s),i=a.state,o=r.useRef(null),l=r.useRef(0),d=!!i;r.useEffect(()=>{n?l.current!==n&&xs(o.current)&&(l.current=n):l.current=0},[n,d]);const u=K().state.config?.managedPolicy,c=u?.remoteAccess===!1?t("policy.remoteBlocked",{organization:u.organizationName}):null,x=u?.remoteAccess===!1?t("policy.managedBy",{organization:u.organizationName}):null;if(!fn())return e.jsx(L,{title:t("remote.desktopOnly.title",{app:Ye().name}),subtitle:t("remote.desktopOnly.subtitle")});if(!i)return e.jsx(L,{title:t("remote.title"),subtitle:t("remote.checking"),children:e.jsx(H,{size:15,className:"animate-spin text-ink-secondary"})});const m=i.devices.length,g=dr(i),p=bn(a.account,a.accountError),y=cr(a),k=or(i,a.tailscaleAvailable),N=i.endpoints?.find(j=>j.kind==="hosted"),v=[i.tailnetName?{label:"Tailscale",value:`${i.tailnetName}:${i.port}`}:null,i.lan?{label:t("remote.connection.wifi"),value:`${i.lan}:${i.port}`}:null,i.discovery?.name?{label:t("remote.connection.discovery"),value:`${i.discovery.name}:${i.port}`}:null,...(i.addresses??[]).filter(j=>j!==i.lan&&j!==i.tailscale).map((j,C)=>({label:t("remote.connection.localRoute",{index:C+1}),value:`${j}:${i.port}`}))].filter(j=>!!j);return e.jsxs("div",{className:"flex flex-col gap-4",children:[c&&e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink-secondary",children:c}),e.jsx("div",{ref:o,tabIndex:-1,"data-phone-pairing":"computer",className:"scroll-mt-4 rounded-xl ring-1 ring-accent/40 focus:outline-none",children:e.jsxs(L,{title:y.title,subtitle:y.subtitle,children:[(g||m>0&&a.hostedReady)&&e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[g&&e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-2.5 py-1 text-[11.5px] ${g.good?"bg-success/10 text-success":"bg-control text-ink-secondary"}`,children:[e.jsx("span",{className:`size-1.5 rounded-full ${g.good?"bg-success":"bg-ink-secondary/50"}`}),g.label]}),m>0&&a.hostedReady&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx(Pt,{size:13,className:"text-accent"})," ",t("remote.worksAway")]})]}),e.jsx(yn,{controller:a,variant:"settings"})]})}),e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-card",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-3.5 text-[13px] font-medium text-ink",children:t("remote.advanced")}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-hairline/30 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.toggleDetail")})]}),e.jsx(Y,{checked:i.enabled,"aria-label":t("remote.title"),disabled:a.busy||!!c&&!i.enabled,onClick:()=>{a.act(j=>i.enabled?j.stop():j.start())}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.devices.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:m?t("remote.devices.subtitle",{app:Ye().name}):t("remote.devices.empty")}),e.jsx("div",{className:"mt-3",children:m>0&&e.jsx("ul",{className:"flex flex-col gap-2",children:i.devices.map(j=>e.jsxs("li",{className:"rounded-xl bg-inset px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(vn,{size:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13.5px] font-medium text-ink",children:j.name}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("remote.devices.lastSeen",{when:ur(j.lastSeenAt)})})]}),e.jsx("button",{disabled:a.busy,onClick:()=>{a.act(C=>C.revoke(j.id))},"aria-label":t("remote.devices.remove",{name:j.name}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-40",children:e.jsx(we,{size:14})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowView")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowViewDetail")})]}),e.jsx(Y,{checked:j.cloudDesktopAccess,"aria-label":t("remote.devices.viewAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.cloudDesktop(j.id,!j.cloudDesktopAccess))}})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowBrowser")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowBrowserDetail")})]}),e.jsx(Y,{checked:j.browserControlAccess===!0,"aria-label":t("remote.devices.browserAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.browserControl(j.id,!j.browserControlAccess))}})]})]},j.id))})})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.tailscale.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.tailscaleCard.subtitle")}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"rounded-xl bg-inset px-3 py-3","aria-live":"polite",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Pt,{size:16,className:`mt-0.5 shrink-0 ${k.kind==="ready"?"text-success":"text-ink-secondary"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:k.title}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:k.detail})]})]})}),k.kind==="ready"?e.jsx("button",{disabled:a.busy||a.accountBusy||!!x,title:x??void 0,onClick:()=>{a.useTailscale(),window.requestAnimationFrame(()=>{o.current?.scrollIntoView({block:"start"}),o.current?.focus({preventScroll:!0})})},className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.pairOverTailscale")}):e.jsx("button",{disabled:a.busy||a.accountBusy||!!x&&!i.enabled,title:x??void 0,onClick:a.refreshTailscale,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.busy?t("common.checking"):x&&!i.enabled?x:i.enabled?t("remote.checkAgain"):t("remote.turnOnAndCheck")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.keepAwake")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.keepAwakeDetail")})]}),e.jsx(Y,{checked:i.keepAwake,"aria-label":t("remote.keepAwakeAria"),disabled:a.busy||!i.enabled,onClick:()=>{a.act(j=>j.keepAwake(!i.keepAwake))}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(mt,{size:15,className:"mt-0.5 shrink-0 text-accent"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.account.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:a.account?.status==="ready"?t("remote.account.signedIn",{email:a.account.email??t("remote.account.yourAccount")}):a.account?.status==="connecting"?t("remote.account.connecting"):a.account?.status==="error"?a.account.message??t("remote.account.error"):t("remote.account.idle")})]})]}),(a.account?.status==="ready"||a.account?.status==="connecting"||a.account?.status==="error")&&e.jsxs("button",{disabled:a.accountBusy,onClick:()=>{a.accountAct(j=>j.signOut())},className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[11.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(jn,{size:12})," ",t("remote.account.signOut")]})]}),a.account?.status==="error"&&e.jsx("button",{disabled:a.accountBusy,onClick:a.retryAccount,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.accountBusy?t("remote.account.retrying"):t("remote.account.retry")}),p&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:p})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.connection.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] text-ink-secondary",children:t("remote.connection.detail")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[N&&e.jsx(Rt,{label:t("remote.connection.secureRoute"),value:xr(N.url)}),v.map(j=>e.jsx(Rt,{...j},`${j.label}:${j.value}`)),!N&&v.length===0&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("remote.connection.none")})]})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(kn,{size:15,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.wifi.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.wifi.detail")})]})]}),e.jsx("button",{disabled:a.busy||a.accountBusy,onClick:a.useLocal,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.wifi.pair")})]}),i.enabled&&!N&&!i.tailscale&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.localOnly")}),(a.error||i.error)&&e.jsx("div",{className:"text-[12px] text-danger",children:a.error??i.error})]})]})]})}function Xe(s){return wn(s)}function mr(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function gr(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}function hr(s,n=Date.now()){return Math.max(0,Math.ceil((s-n)/6e4))}function fr(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const br="rounded-md bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-50",_t="rounded-md border border-hairline/50 px-3 py-1.5 text-[13px] text-ink hover:bg-control";function yr({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0}){const[o,l]=r.useState(s),[d,u]=r.useState(n),[c,x]=r.useState("admin"),[m,g]=r.useState(null),[p,y]=r.useState([]),[k,N]=r.useState(null),[v,j]=r.useState(!1),[C,w]=r.useState("idle"),[D,I]=r.useState(null),[f,b]=r.useState(()=>Date.now()),h=r.useRef(null),E=r.useRef(0);async function A(){try{const z=await U("/api/auth/sessions");y(Array.isArray(z?.sessions)?z.sessions:[]),N(typeof z?.current=="string"?z.current:null)}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}}if(r.useEffect(()=>{ps().then(z=>{l(z),Xe(z)&&A(),(z.kind==="loopback"||z.kind==="session")&&U("/api/config").then(G=>u(ms(G).pairingCodes)).catch(()=>{})})},[]),r.useEffect(()=>{i?E.current!==i&&xs(h.current)&&(E.current=i):E.current=0},[i,o]),r.useEffect(()=>{if(!m)return;const z=setInterval(()=>b(Date.now()),15e3);return()=>clearInterval(z)},[m]),!Xe(o))return mr(o)!=="chat-only"?null:e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(d?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const P=m?m.expiresAt<=f:!1,V=gr(p,a);async function J(){j(!0),I(null),w("idle");try{const z=await U("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:c==="admin"||a?["admin","client"]:["client"]})});g(z),b(Date.now())}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}finally{j(!1)}}async function $(z){I(null);try{await U(`/api/auth/sessions/${encodeURIComponent(z)}`,{method:"DELETE"}),await A()}catch(G){I(t("remote.serverPairing.error",{error:G instanceof Error?G.message:String(G)}))}}async function W(){if(!m?.url)return;const z=await Sn(m.url);z!=="empty"&&w(z)}return e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[d&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,d?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="admin",onChange:()=>x("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="client",onChange:()=>x("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{J()},disabled:v,className:br,children:v?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),d&&m?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:P?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[m.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Nn,{value:m.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:m.code}),e.jsx("div",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.expires",{minutes:hr(m.expiresAt,f)})}),m.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:m.url}),e.jsx("button",{type:"button",onClick:()=>{W()},className:_t,children:t(C==="copied"?"remote.serverPairing.copied":C==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[12.5px] text-ink-secondary",children:m.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(d?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),V.length===0?e.jsx("p",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:V.map(z=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[z.label,z.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:fr(z.lastSeenAt,f)}),z.id===k?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),z.id===k?null:e.jsx("button",{type:"button",onClick:()=>{$(z.id)},className:_t,children:t("remote.serverPairing.signOut")})]},z.id))}),D?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:D}):null]})})}function vr(s){const n=s.trim().toLowerCase();return!n||/\s/.test(n)?null:n.startsWith("@")?/^@[^@\s]+\.[^@\s]+$/.test(n)?n:null:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(n)?n:null}function Ft(s,n,a){const i=s.admins.filter(l=>l!==n),o=s.members.filter(l=>l!==n);return a==="admin"?{admins:[...i,n],members:o}:{admins:i,members:[...o,n]}}function jr(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $t(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function kr(s,n,a){const i=[],o=new Set,l=(d,u)=>{const c=d.trim().toLowerCase();if(!c||o.has(c))return;o.add(c);const x=n.filter(g=>g.email?.toLowerCase()===c),m=a.find(g=>g.key===`user:${c}`);i.push({entry:c,role:u,isDomain:c.startsWith("@"),lastSeenAt:x.length?Math.max(...x.map(g=>g.lastSeenAt)):null,devices:x.length,turns:m?.turns??0,costUsd:m?.costUsd??null,...le(m?.estimatedUsd)&&m.estimatedUsd>0?{estimated:!0}:{}})};for(const d of s.admins)l(d,"admin");for(const d of s.members)l(d,"member");return i}function Nr(s,n){const a=new Map;for(const i of s){const o=i.email?.trim().toLowerCase();o&&a.set(o,[...a.get(o)??[],i])}return[...a.entries()].map(([i,o])=>{const l=n.find(d=>d.key===`user:${i}`);return{entry:i,role:o.some(d=>d.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...o.map(d=>d.lastSeenAt)),devices:o.length,turns:l?.turns??0,costUsd:l?.costUsd??null}}).sort((i,o)=>i.role===o.role?i.entry.localeCompare(o.entry):i.role==="admin"?-1:1)}function wr(s,n=Date.now()){return s===null?t("people.never"):n-s<1440*6e4?t("people.today"):new Date(s).toISOString().slice(0,10)}function Ds({people:s,busy:n,onRole:a,onRemove:i,onLink:o,readOnly:l=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(l?"people.portal.empty":"people.empty")});const d="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(d,"border-b border-hairline/40 pb-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(u=>e.jsxs("div",{className:_(d,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:u.isDomain?t("people.everyoneAt",{domain:u.entry.slice(1)}):u.entry}),u.devices>0&&e.jsx("span",{className:"block text-[11.5px] text-ink-secondary",children:t("people.devices",{count:String(u.devices)})})]}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px] font-medium",u.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:u.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:u.isDomain?"—":wr(u.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(u.turns)}),children:le(u.costUsd)?`${u.estimated?"~":""}${ue(u.costUsd)}`:"—"}),l?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>o(u),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(An,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(u,u.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:u.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(u),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},u.entry))]})}function Ts({link:s}){const{state:n,copy:a}=Cn(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[12.5px]",children:[e.jsx("div",{className:"mb-1 text-ink-secondary",children:t("people.link")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 select-all break-all text-ink",children:s}),e.jsxs("button",{type:"button",onClick:a,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:[n==="copied"?e.jsx(oe,{size:13,className:"text-success"}):n==="failed"?e.jsx(De,{size:13,className:"text-danger"}):e.jsx(En,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Sr({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(L,{title:t("people.title"),subtitle:t("people.portal.subtitle"),children:[e.jsxs("div",{"data-people-portal":!0,className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:t("people.portal.managed")}),s&&e.jsxs("a",{href:s,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:[t("people.portal.open")," ",e.jsx(Ze,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Cr(){const[s,n]=r.useState(null),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState([]),[c,x]=r.useState(typeof window<"u"?window.location.origin:""),[m,g]=r.useState(null),[p,y]=r.useState(""),[k,N]=r.useState("member"),[v,j]=r.useState(null),[C,w]=r.useState(!1),[D,I]=r.useState(!1),[f,b]=r.useState(null),h=r.useCallback(async()=>{I(!0),b(null);try{const[P,V,J,$,W]=await Promise.all([U("/api/config"),U("/api/auth/sessions").catch(()=>({sessions:[]})),U("/api/usage?groupBy=user").catch(()=>({groups:[]})),U("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(F=>F.ok?F.json():null).catch(()=>null)]),z={admins:Array.isArray(P?.signIn?.admins)?P.signIn.admins:[],members:Array.isArray(P?.signIn?.members)?P.signIn.members:[]},G=ms(P);i(G),l(z);const ne=Array.isArray(V?.sessions)?V.sessions:[],R=Array.isArray(J?.groups)?J.groups:[];u(G.authority==="portal"?Nr(ne,R):kr(z,ne,R)),typeof $?.publicUrl=="string"&&$.publicUrl&&x($.publicUrl),g(W?.capabilities?.emailSignIn===!0?!0:W?!1:null)}catch(P){b(P instanceof Error?P.message:String(P))}finally{I(!1)}},[]);r.useEffect(()=>{ps().then(P=>{n(P),Xe(P)&&h()})},[h]);const E=async P=>{w(!0),b(null);try{await U("/api/config",{method:"PUT",body:JSON.stringify({signIn:P})}),await h()}catch(V){b(V instanceof Error?V.message:String(V))}finally{w(!1)}},A=async()=>{if(!o||C)return;const P=vr(p);if(!P){b(t("remote.signInAccess.invalid"));return}await E(Ft(o,P,k)),y(""),j($t(c,P))};return Xe(s)?a?.authority==="portal"?e.jsx(Sr,{peopleUrl:a.peopleUrl,people:d}):e.jsxs(L,{title:t("people.title"),subtitle:t("people.subtitle"),children:[m===!1&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[12.5px] text-ink-secondary",children:t(a?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:P=>{P.preventDefault(),A()},children:[e.jsx("input",{value:p,onChange:P=>y(P.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:C,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("select",{value:k,onChange:P=>N(P.target.value),"aria-label":t("people.colRole"),disabled:C,className:"rounded-lg border border-hairline/40 bg-inset px-2 py-2 text-[12.5px] text-ink focus:outline-none",children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:C||!p.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[C?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(Te,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:D||C,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(xe,{size:13,className:_(D&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Ts,{link:v}),f&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:f}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:d,busy:C,onRole:(P,V)=>{o&&E(Ft(o,P.entry,V))},onRemove:P=>{o&&E(jr(o,P.entry))},onLink:P=>j($t(c,P.entry))})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.note")})]}):null}const Ve="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function Er({entry:s}){const[n,a]=r.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:ai(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:ii(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:s.summary}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(In,{size:12,className:_("transition-transform",n&&"rotate-90")}),t("activity.changed",{paths:(s.changed??[]).join(", ")||"—"})]}),i&&n&&s.type==="admin"&&e.jsxs("dl",{className:"mt-1 grid grid-cols-[auto_1fr_1fr] gap-x-3 gap-y-0.5 rounded-lg bg-inset p-2 text-[12px]",children:[e.jsx("dt",{}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.before")}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.after")}),(s.changed??Object.keys({...s.before,...s.after})).map(o=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.before?.[o])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.after?.[o])})]},o))]})]})]})})}function Ar(){const[s,n]=r.useState({who:"",what:"all",from:"",to:""}),[a,i]=r.useState([]),[o,l]=r.useState(0),[d,u]=r.useState(null),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=si(s),y=r.useCallback(async()=>{x(!0),g(null);try{const N=await U(`/api/admin-activity${p}`);i(N.entries),l(N.total),u(N.retentionDays)}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}},[p]);r.useEffect(()=>{const N=window.setTimeout(()=>{y()},250);return()=>window.clearTimeout(N)},[y]);const k=N=>n(v=>({...v,...N}));return e.jsxs(L,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(d??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:N=>k({who:N.target.value}),placeholder:t("activity.whoPlaceholder"),className:_(Ve,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx("select",{value:s.what,onChange:N=>k({what:N.target.value}),className:Ve,children:ni.map(N=>e.jsx("option",{value:N,children:t(`activity.what.${N}`)},N))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:N=>k({from:N.target.value}),className:Ve})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:N=>k({to:N.target.value}),className:Ve})]}),e.jsx("button",{type:"button",onClick:()=>{y()},disabled:c,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:c?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${p}`,download:!0,className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12.5px] font-medium text-ink hover:bg-control/70",children:[e.jsx(gs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:t("activity.error",{message:m})}),!m&&a.length===0&&!c&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((N,v)=>e.jsx(Er,{entry:N},`${N.at}-${v}`))}),o>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(o)})})]})}function Ir(s){const n=s.trim();if(!n||/[\s\\?#@%]/.test(n))return null;try{const a=new URL(n.includes("://")?n:`https://${n}`),i=a.hostname.replace(/\.$/,"");return a.protocol!=="https:"||a.port||a.pathname!=="/"||!i.includes(".")||i.length>253||/^[\d.]+$/.test(i)||!i.split(".").every(o=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(o))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Pr({domain:s,serverIpv4:n}){const a=Ir(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([o,l])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0",children:l?e.jsx(Re,{command:l,copyLabel:t("settings.domain.copyField",{field:o})},l):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},o))}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Rr(s){return`bots.example.com {
2
2
  handle /hooks/* {
3
3
  reverse_proxy 127.0.0.1:${s.webhookPort}
4
4
  }