limixbot 0.3.131 → 0.3.133

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 (128) hide show
  1. package/NOTICE +119 -0
  2. package/README.md +3 -5
  3. package/dist/assets/{ActivityPanel-DLm-v_Kg.js → ActivityPanel-BTszBP4a.js} +1 -1
  4. package/dist/assets/App-B2fBpoRZ.js +250 -0
  5. package/dist/assets/{AppEventEditor-BdU7zTya.js → AppEventEditor-CDO2rLAR.js} +1 -1
  6. package/dist/assets/{BotSettingsDialog-DZbrG3Yu.js → BotSettingsDialog-bwIEtMBP.js} +7 -7
  7. package/dist/assets/{BrowserPanel-BAmkHZNW.js → BrowserPanel-Cm4lK77e.js} +1 -1
  8. package/dist/assets/{BrowserProfilesManager-DL_IVvlO.js → BrowserProfilesManager-zGt-sq4k.js} +1 -1
  9. package/dist/assets/{CloudAddDialog-Cs6tRBOu.js → CloudAddDialog-Bhz32gRM.js} +1 -1
  10. package/dist/assets/{ComputerFilesPane-Bl6NnCOe.js → ComputerFilesPane-BC49N1Pm.js} +1 -1
  11. package/dist/assets/{ComputerPanel-CzwDPKV_.js → ComputerPanel-B5BJuUqm.js} +2 -2
  12. package/dist/assets/{DataPanel-FEAZNWku.js → DataPanel-D-zD8ngK.js} +1 -1
  13. package/dist/assets/{DesktopViewer-Cb9PL6v1.js → DesktopViewer-CgTlC2ON.js} +1 -1
  14. package/dist/assets/{GrokMoveDialog-Bp0mxIE8.js → GrokMoveDialog-Diktcl5X.js} +1 -1
  15. package/dist/assets/{InspectorPanel-DJADxXPA.js → InspectorPanel-Dzl7wwRq.js} +1 -1
  16. package/dist/assets/{KeyboardShortcutsModal-CNiZBEA1.js → KeyboardShortcutsModal-Bo7yVUTs.js} +1 -1
  17. package/dist/assets/{LimixResizeHandles-nzE7n7jC.js → LimixResizeHandles-Bdcz_w8I.js} +1 -1
  18. package/dist/assets/{LiveDesktop-BvdjlV9Q.js → LiveDesktop-qk7oOKR-.js} +1 -1
  19. package/dist/assets/{LocalVmWorkspace-DmQTSD1_.js → LocalVmWorkspace-B7YaXgti.js} +1 -1
  20. package/dist/assets/{MacLocalControl-WWFi-S9U.js → MacLocalControl-YCjPm4U3.js} +1 -1
  21. package/dist/assets/{MarkdownFilePreview-BsGqiWI2.js → MarkdownFilePreview-uvNI77v4.js} +1 -1
  22. package/dist/assets/{MenuMotion-owWIcamS.js → MenuMotion-D8l5zOOH.js} +1 -1
  23. package/dist/assets/{NewBotDialog-sr2kfVv6.js → NewBotDialog-veYkUiA5.js} +1 -1
  24. package/dist/assets/{PhoneAppDialog-DC4JUrmh.js → PhoneAppDialog-CkE9M2PT.js} +1 -1
  25. package/dist/assets/{PlacesRail-BxdV2GDQ.js → PlacesRail-B0T5a390.js} +1 -1
  26. package/dist/assets/{PluginsPanel-BMHhkTNZ.js → PluginsPanel-BSv-aWR7.js} +1 -1
  27. package/dist/assets/{ProIntroduction-CLLJ3Vgd.js → ProIntroduction-BJMwoQGa.js} +1 -1
  28. package/dist/assets/{RemoteAgentSettingsPanel-DWTstMZc.js → RemoteAgentSettingsPanel-Dkaxe7IA.js} +1 -1
  29. package/dist/assets/{RoomPanel-DuE_Gpr5.js → RoomPanel-BIXVLWNZ.js} +1 -1
  30. package/dist/assets/{RoutinesPage-CPo3eSc1.js → RoutinesPage-B-QJRpZi.js} +2 -2
  31. package/dist/assets/SettingsModal-BtRFqxwn.js +20 -0
  32. package/dist/assets/{ShareTeamDialog-CDkcowQz.js → ShareTeamDialog-D3Ea5oSB.js} +1 -1
  33. package/dist/assets/{SignedInSites-DLDJv-6U.js → SignedInSites-CPLPNDp5.js} +1 -1
  34. package/dist/assets/{TeamLibraryPanel-X0NQqbX0.js → TeamLibraryPanel-D_pKnj54.js} +1 -1
  35. package/dist/assets/{TeamMapPage-C6K12Ejq.js → TeamMapPage-CBV2HmaF.js} +1 -1
  36. package/dist/assets/{TriggersPage-BAXbOt6i.js → TriggersPage-C9FIxQGD.js} +1 -1
  37. package/dist/assets/{VisibilitySection-CC7rEV8o.js → VisibilitySection-B0z1XJD4.js} +1 -1
  38. package/dist/assets/{WebhookTrigger-cHV0kIQv.js → WebhookTrigger-C7qvE8eC.js} +1 -1
  39. package/dist/assets/{WorksOnGrid-DZ5DXYgb.js → WorksOnGrid-BOLs3g9Y.js} +1 -1
  40. package/dist/assets/{abnfDiagram-YUKMZFIV-vvJbRPlq.js → abnfDiagram-YUKMZFIV-CBc7oFEe.js} +1 -1
  41. package/dist/assets/{activity-D26W1wR5.js → activity-BVpu0XkG.js} +1 -1
  42. package/dist/assets/{architectureDiagram-47P4ROYG-BxqUvVUX.js → architectureDiagram-47P4ROYG-B5jJZs7S.js} +1 -1
  43. package/dist/assets/{blockDiagram-E7TT5TSB-DDe2YxQP.js → blockDiagram-E7TT5TSB-DAjxXILv.js} +1 -1
  44. package/dist/assets/{c4Diagram-CRA5TL53-OdUvGZP-.js → c4Diagram-CRA5TL53-KWoy72TL.js} +1 -1
  45. package/dist/assets/{calendar-days-OEtSVrLe.js → calendar-days-DNA-E4Np.js} +1 -1
  46. package/dist/assets/channel-q-lG3psP.js +1 -0
  47. package/dist/assets/{chunk-2Q5K7J3B-DpnJlpzb.js → chunk-2Q5K7J3B-D3Ycc8P6.js} +1 -1
  48. package/dist/assets/{chunk-5VM5RSS4-C5UgOu8-.js → chunk-5VM5RSS4-C7mfSQVV.js} +1 -1
  49. package/dist/assets/{chunk-7TKQ45FW-Dv-gctKP.js → chunk-7TKQ45FW-BKvAYNH2.js} +1 -1
  50. package/dist/assets/{chunk-AW2ZBBNX-mehzuNgt.js → chunk-AW2ZBBNX-Ca8gRTzc.js} +1 -1
  51. package/dist/assets/{chunk-FVRAUYC3-6bArILty.js → chunk-FVRAUYC3-Bzkks_DT.js} +2 -2
  52. package/dist/assets/{chunk-HTAEGDNF-0w6XIlls.js → chunk-HTAEGDNF-Zo7ZYlx6.js} +1 -1
  53. package/dist/assets/{chunk-JWPE2WC7-DaZro178.js → chunk-JWPE2WC7-DuQPO5Rt.js} +1 -1
  54. package/dist/assets/{chunk-KQW6MTUR-CqA51RiN.js → chunk-KQW6MTUR-C3yGOwbc.js} +1 -1
  55. package/dist/assets/{chunk-XXDRQBXY-DPZH_wOz.js → chunk-XXDRQBXY-Dza0vL4n.js} +1 -1
  56. package/dist/assets/{classDiagram-v2-K4WV4PDN-Dgn2w_U2.js → classDiagram-v2-K4WV4PDN-DTtDRSzj.js} +1 -1
  57. package/dist/assets/{coins-D0EwvaZf.js → coins-Bn14rFjr.js} +1 -1
  58. package/dist/assets/{core-Lc3koHof.js → core-CGuF_Hr1.js} +1 -1
  59. package/dist/assets/{cose-bilkent-JH36ORCC-B9lVmBnW.js → cose-bilkent-JH36ORCC-wZ_7CqXu.js} +1 -1
  60. package/dist/assets/{cynefin-EF2NZ3EQ-BoirpSv2.js → cynefin-EF2NZ3EQ-CE0jDEB2.js} +1 -1
  61. package/dist/assets/{cynefinDiagram-3GCD6N5R-Cdmdj7_K.js → cynefinDiagram-3GCD6N5R-CHr9A4jc.js} +1 -1
  62. package/dist/assets/{dagre-W4DXFKR2-BFjlE582.js → dagre-W4DXFKR2-C3IEvn1u.js} +1 -1
  63. package/dist/assets/{diagram-2UJZ2QOL-OsLSZez_.js → diagram-2UJZ2QOL-D6GEShaY.js} +1 -1
  64. package/dist/assets/{diagram-OVF4WLC6-CwDUdKBh.js → diagram-OVF4WLC6-vc-kIw0c.js} +1 -1
  65. package/dist/assets/{diagram-PFPMY2P6-BLtFTcT4.js → diagram-PFPMY2P6-Dz6L5P0U.js} +1 -1
  66. package/dist/assets/{diagram-UMYRVEAY-BSLF9HqA.js → diagram-UMYRVEAY-BKH-KrgS.js} +1 -1
  67. package/dist/assets/{diagram-YEKJPTXX-9rCjHXiY.js → diagram-YEKJPTXX-BugCeBVB.js} +1 -1
  68. package/dist/assets/{diagram-ZIFT7M5P-C4BY_KLT.js → diagram-ZIFT7M5P-BYARFkzf.js} +1 -1
  69. package/dist/assets/{ebnfDiagram-VR2GEFS7-AhQ5NsrM.js → ebnfDiagram-VR2GEFS7-CKzxPCV8.js} +1 -1
  70. package/dist/assets/{elk-IJKZMXRS-UnH28E2R.js → elk-IJKZMXRS--PWP5h9X.js} +1 -1
  71. package/dist/assets/{erDiagram-O2IAPWRE-CO0nepRl.js → erDiagram-O2IAPWRE-OYgx1l4s.js} +1 -1
  72. package/dist/assets/{file-up-D-jXnd_Y.js → file-up-DmgXwNtQ.js} +1 -1
  73. package/dist/assets/{flowDiagram-OXPTDLAJ-DdStYfx7.js → flowDiagram-OXPTDLAJ-Cx9uOAhj.js} +1 -1
  74. package/dist/assets/{ganttDiagram-R7TSEDQI-DH8CA0Mt.js → ganttDiagram-R7TSEDQI-DF4G2mlV.js} +1 -1
  75. package/dist/assets/{gitGraphDiagram-XJZIOB7I-Ds4256L4.js → gitGraphDiagram-XJZIOB7I-D9CUZ9nv.js} +1 -1
  76. package/dist/assets/{import-name-CHPmMQSU.js → import-name-DUNKRTJV.js} +1 -1
  77. package/dist/assets/{index-CFBg45ji.js → index-CV61vbZS.js} +1 -1
  78. package/dist/assets/{index-CGhQDBT_.js → index-VDBTcIMw.js} +3 -3
  79. package/dist/assets/{infoDiagram-5W2HQ5XZ-mNLO1zPg.js → infoDiagram-5W2HQ5XZ-CZW1K3wV.js} +1 -1
  80. package/dist/assets/{ishikawaDiagram-K3B6WC7H-Daak_Ht_.js → ishikawaDiagram-K3B6WC7H-CnK_NQTK.js} +1 -1
  81. package/dist/assets/{journeyDiagram-COXZFDF6-U58GAPno.js → journeyDiagram-COXZFDF6-DSuoKe19.js} +1 -1
  82. package/dist/assets/{kanban-definition-P3RFRI5V-CcRE6J9f.js → kanban-definition-P3RFRI5V-DjmRhFSg.js} +1 -1
  83. package/dist/assets/{mermaid.core-QHRYQaNt.js → mermaid.core-DeRUYgIm.js} +4 -4
  84. package/dist/assets/{mindmap-definition-LZFPQGKD-CEyDomxS.js → mindmap-definition-LZFPQGKD-BJ3VBjfI.js} +1 -1
  85. package/dist/assets/{minimize-oQ71ZbVB.js → minimize-BXc-miDU.js} +1 -1
  86. package/dist/assets/{monitor-BmIglcrr.js → monitor-15mG3xlc.js} +1 -1
  87. package/dist/assets/{new-bot-tCPJjkMQ.js → new-bot-__CMk5sR.js} +1 -1
  88. package/dist/assets/{org-library-Dr5sX_Fu.js → org-library-DT_poCG3.js} +1 -1
  89. package/dist/assets/{package-format-heZrOI7V.js → package-format-CgaIxeTU.js} +1 -1
  90. package/dist/assets/{pegDiagram-BGZESJAR-CTxI-cP8.js → pegDiagram-BGZESJAR-BZ-1foJI.js} +1 -1
  91. package/dist/assets/{pieDiagram-CAPJLFHJ-B8DCNi6O.js → pieDiagram-CAPJLFHJ-v_kbKYIo.js} +1 -1
  92. package/dist/assets/{quadrantDiagram-GDMTTRAM-CWdpAW4W.js → quadrantDiagram-GDMTTRAM-fpE5oT7k.js} +1 -1
  93. package/dist/assets/{rail-WaxapGbo.js → rail-fintvt10.js} +1 -1
  94. package/dist/assets/{railroadDiagram-SM67HX2B-BCY8OR1i.js → railroadDiagram-SM67HX2B-C8JH_pmt.js} +1 -1
  95. package/dist/assets/{remote-desktop-panel-CRSqL4w9.js → remote-desktop-panel-DAU_1yzY.js} +1 -1
  96. package/dist/assets/{requirementDiagram-X7JNWC4A-BcX43ufU.js → requirementDiagram-X7JNWC4A-DIZkii0D.js} +1 -1
  97. package/dist/assets/{sankeyDiagram-UM26HJRW-C3YBTWo7.js → sankeyDiagram-UM26HJRW-D28LUPgJ.js} +1 -1
  98. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-CNLzalKN.js → sequenceDiagram-ZO4K6R2Y-By6Qr2OZ.js} +1 -1
  99. package/dist/assets/{sizeCapture-INFHLROL-D55E_ZEd.js → sizeCapture-INFHLROL-B8ky8h-O.js} +1 -1
  100. package/dist/assets/{stateDiagram-v2-TBUQTH76-CRDCsicX.js → stateDiagram-v2-TBUQTH76-CtuCVgt_.js} +1 -1
  101. package/dist/assets/styles-DKlhnsr7.css +1 -0
  102. package/dist/assets/{swimlanes-N4OXWK64-Ah7OauuN.js → swimlanes-N4OXWK64-DxwcpFlC.js} +1 -1
  103. package/dist/assets/swimlanesDiagram-K3J5GTZL-B7Xl2xDR.js +8 -0
  104. package/dist/assets/{team-share-D3Hwdncm.js → team-share-Dl1JG3TI.js} +1 -1
  105. package/dist/assets/{timeline-definition-YOQAKGHF-DV-V6CCB.js → timeline-definition-YOQAKGHF-C76P0vUA.js} +1 -1
  106. package/dist/assets/{usecaseDiagram-VIAY4XPW-T9J5Wpir.js → usecaseDiagram-VIAY4XPW-CYHUVqRH.js} +1 -1
  107. package/dist/assets/{vennDiagram-BLWOH2XV-RqJjHEmQ.js → vennDiagram-BLWOH2XV-Da7BHd4-.js} +1 -1
  108. package/dist/assets/{wardleyDiagram-YMQ3BMBF-xZxQC8Rt.js → wardleyDiagram-YMQ3BMBF-Ckv9W8Fc.js} +1 -1
  109. package/dist/assets/{xychartDiagram-TAQBALBS-BgPG2lil.js → xychartDiagram-TAQBALBS-Dw876alP.js} +1 -1
  110. package/dist/index.html +3 -3
  111. package/dist/rail.html +5 -5
  112. package/dist-server/hybrid-plugin-gateway.js +11 -9
  113. package/dist-server/index.js +98 -88
  114. package/dist-server/package.json +1 -1
  115. package/dist-server/server/hybrid-plugin-manifest.js +2 -1
  116. package/dist-server/server/limix-skill-hub.js +3 -3
  117. package/dist-server/server/limix-skill-requirements.js +29 -11
  118. package/dist-server/server/routes/plugin-studio.js +11 -2
  119. package/dist-server/shared/plugin-hub.js +52 -0
  120. package/package.json +5 -1
  121. package/skills/limix-bot-factory/SKILL.md +2 -0
  122. package/skills/limix-bot-factory/references/vi.md +2 -0
  123. package/dist/assets/App-Co1EFoza.js +0 -250
  124. package/dist/assets/SettingsModal-BZzK-mss.js +0 -19
  125. package/dist/assets/channel-D_nJ6dC4.js +0 -1
  126. package/dist/assets/styles-Cr4TcnLq.css +0 -1
  127. package/dist/assets/swimlanesDiagram-K3J5GTZL-G_1ilp2C.js +0 -8
  128. /package/dist/assets/{styles-D7SaLPZf.js → styles-Bixj4Mfc.js} +0 -0
@@ -1,16 +1,16 @@
1
- import{c as Ae,t as s,l as ee,aF as Vs,j as e,i as De,ae as fe,a as O,r as u,S as tt,ah as Qt,X as st,d as mt}from"./styles-D7SaLPZf.js";import{fq as Zs,fr as Gs,_ as nt,f3 as at,bE as Ys,dq as Xt,C as Js,fs as Qs,ft as Xs,E as es,fu as en,M as ts,eA as tn,p as sn,fv as ut,bu as xt,fw as ss,j as Z,u as B,fx as ht,fy as gt,f4 as ie,fz as nn,fA as an,ag as it,af as ns,A as as,S as be,ab as Me,T as is,R as rn,fB as on,fC as ln,fD as cn,fE as dn,fF as pn,fG as ft,fH as mn,fI as un,fJ as xn,fK as hn,a$ as gn,fL as fn,fM as yn,fN as bn,I as vn,fO as Oe,bY as Le,fP as kn,aH as M,aN as Q,ek as jn,dS as wn,fQ as Nn,aI as Ge,cw as Sn,e5 as Cn,e6 as Pn,fR as On,fS as rs,fT as os,fU as En,fV as Rn,fW as Tn,fX as In,dV as Ye,aq as yt,fY as ze,fZ as An,f_ as Re,au as Mn,f$ as ls,g0 as bt,aj as Je,g1 as Ln,g2 as Bn,g3 as $n,g4 as cs,g5 as Fn,g6 as vt,g7 as Dn,g8 as zn,g9 as Hn,ga as te,aX as ae,aZ as X,gb as _n,gc as Kn,gd as Un,dc as qn,aP as Wn,G as Vn,da as ds,ai as Zn,ge as V,aW as me,gf as ue,x as S,gg as Gn,dw as Yn,gh as Be,aY as le,gi as Jn,gj as Qn,gk as Xn,eo as ea,gl as kt,gm as ta,gn as sa,go as na,gp as aa,gq as ia,gr as ra,az as oa,gs as ps,gt as ms,gu as la,gv as ca,gw as da,gx as pa,gy as ma,gz as ua,gA as xa,gB as ha,gC as ga,gD as us,gE as fa,gF as ya,gG as ba,gH as rt,g as va,B as Qe,gI as ka,gJ as ja,gK as wa,gL as Na,gM as Sa,gN as Ca,c5 as Pa,gO as xs,D as jt,gP as Oa,f6 as Ea,gQ as wt,gR as Ra,gS as Ta,gT as Ia,cT as Nt,bC as Aa,d9 as Ma,gU as La,gV as hs,gW as Ce,gX as St,gY as Ba,aL as He,e7 as $a,gZ as Fa,aR as Da,dA as za,cx as Ha,g_ as _a,g$ as Ka,h0 as Ua,aT as qa}from"./App-Co1EFoza.js";import{v as gs,d as we,a0 as Te,a1 as Wa,a2 as Va,a3 as Ct,a4 as _e,a5 as Za,a6 as Ga,a7 as Ya,a8 as Ja,a9 as Qa,aa as Pt,ab as Xa,ac as ei,L as Ee,M as ti,B as Xe,P as Ne,r as fs,ad as si,$ as ni,u as ys}from"./PlacesRail-BxdV2GDQ.js";import{C as ai}from"./coins-D0EwvaZf.js";import{C as je,a as ii}from"./MenuMotion-owWIcamS.js";import{b as se,m as bs,i as et,f as ot,c as ge,d as Ot,e as Ie,o as ri,g as oi,h as pe,n as Ke,t as vs,s as lt,j as ks,k as li,l as ci,p as di,r as js,q as pi,u as mi,w as ui,x as ws,y as Ns,z as Et,B as xi,C as Ss,R as Rt,D as hi,E as gi,F as fi,G as yi,H as bi,J as vi,O as ki,K as ji,L as Cs,N as Tt,V as wi,P as Ni,M as Si,A as Ci,a as Pi,S as Oi,I as Ei}from"./VisibilitySection-CC7rEV8o.js";import{s as Ri,r as Ti,a as Ii,R as Ai}from"./ComputerFilesPane-Bl6NnCOe.js";import{M as It}from"./monitor-BmIglcrr.js";import{R as Mi}from"./RoutinesPage-CPo3eSc1.js";import{S as Li}from"./SignedInSites-DLDJv-6U.js";import"./index-CGhQDBT_.js";import"./org-library-Dr5sX_Fu.js";import"./package-format-heZrOI7V.js";import"./WorksOnGrid-DZ5DXYgb.js";import"./ProIntroduction-CLLJ3Vgd.js";import"./remote-desktop-DDRRx8uY.js";const Bi=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],$i=Ae("calendar-plus",Bi);const Fi=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],Di=Ae("library",Fi);const zi=[["rect",{width:"3",height:"8",x:"13",y:"2",rx:"1.5",key:"diqz80"}],["path",{d:"M19 8.5V10h1.5A1.5 1.5 0 1 0 19 8.5",key:"183iwg"}],["rect",{width:"3",height:"8",x:"8",y:"14",rx:"1.5",key:"hqg7r1"}],["path",{d:"M5 15.5V14H3.5A1.5 1.5 0 1 0 5 15.5",key:"76g71w"}],["rect",{width:"8",height:"3",x:"14",y:"13",rx:"1.5",key:"1kmz0a"}],["path",{d:"M15.5 19H14v1.5a1.5 1.5 0 1 0 1.5-1.5",key:"jc4sz0"}],["rect",{width:"8",height:"3",x:"2",y:"8",rx:"1.5",key:"1omvl4"}],["path",{d:"M8.5 5H10V3.5A1.5 1.5 0 1 0 8.5 5",key:"16f3cl"}]],Ps=Ae("slack",zi);const Hi=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],_i=Ae("tag",Hi),Ki=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Zs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Gs,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:Ps,keywords:["slack","slack app","admin","message","direct messages","mentions"]},{id:"soul",label:"Soul",labelKey:"botSettings.sections.soul",icon:nt,keywords:["standing instructions","instructions","persona","rules","soul.md"]},{id:"plugins",label:"Plugins",labelKey:"plugins.botMenu",icon:at,keywords:["plugin","attach","gắn"]},{id:"skills",label:"Skills",labelKey:"botSettings.sections.skills",icon:Ys,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:Xt,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:Di,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Js,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Qs,keywords:["works on","computer","vm","cloud","vps","folder","workspace","browser","connected apps","composio","webhooks","always allow","grants","tool selection","tools","mcp","allow","exclude"]},{id:"model",label:"Model",labelKey:"botSettings.sections.model",icon:Xs,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:es,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:en,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:ts,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:tn,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:ai,keywords:["tokens","cost","billing"]}],At={completed:"botOverview.routine.last.completed",failed:"botOverview.routine.last.failed",missed:"botOverview.routine.last.missed",cancelled:"botOverview.routine.last.cancelled",running:"botOverview.routine.last.running",queued:"botOverview.routine.last.queued",waiting:"botOverview.routine.last.waiting"};function Ui(t,n=ee()){if(!t||n==="en")return null;if(t.paused)return s("botOverview.routine.paused",{name:t.name});const a=t.lastRun;if(a&&!Object.hasOwn(At,a.status))return null;try{return[s("botOverview.routine.line",{schedule:sn(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:ut(t.nextRunAt)})]:[],...a?[s(At[a.status],{time:ut(a.at)})]:[]].join(" ")}catch{return null}}const Mt={"Works in its private workspace.":"botOverview.line.privateWorkspace","Has the built-in browser.":"botOverview.line.browser","Has no connected apps.":"botOverview.line.noApps","Won't act on a schedule.":"botOverview.line.noSchedule","Can talk to the other bot.":"botOverview.line.talksToOne","Talks only to the bots chosen for it.":"botOverview.line.talksToChosen","Cannot initiate contact with other bots.":"botOverview.line.noPeerContact","Command approvals use Ask mode; saved permissions and provider rules still apply.":"botOverview.line.askMode","Command approvals follow the provider's custom configuration.":"botOverview.line.customApprovals","Asks before contacting other bots.":"botOverview.line.asksPeers","Can't use a computer.":"botOverview.line.noComputer","Profile proposal cards require your approval.":"botOverview.line.profileApproval","Connected apps could not be checked.":"botOverview.line.appsUnchecked"},Lt={"Auto; availability is checked when a task starts":"botOverview.preference.auto","cloud computer":"botOverview.preference.cloud","Local VM":"botOverview.preference.vm","this computer":"botOverview.preference.local","browser only":"botOverview.preference.browser"};function Bt(t,n){return!n||n.map(a=>a||"General").join(", ")!==t?t:n.map(a=>a||s("botAccess.teams.general")).join(", ")}const $t=t=>Object.hasOwn(Lt,t)?s(Lt[t]):t,Ft=(t,n,a)=>Number(t)===1?n:a,qi=[{line:/^Can talk to all (\d+) other bots, in any department\.$/,key:()=>"botOverview.line.talksToAll",params:([,t])=>({count:Number(t)})},{line:/^Also in charge of these departments: (.+)\.$/,key:()=>"botOverview.line.alsoInCharge",params:([,t],n)=>({departments:Bt(t,n)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>Ft(t,"botOverview.line.peersSectionOne","botOverview.line.peersSectionMany"),params:([,t])=>({count:Number(t)})},{line:/^Can talk to (\d+) other bots? in its allowed (?:teams|departments)\.$/,key:([,t])=>Ft(t,"botOverview.line.peersTeamsOne","botOverview.line.peersTeamsMany"),params:([,t])=>({count:Number(t)})},{line:/^Coordinates its (?:section|department) as Chief of Staff\.$/,key:()=>"botOverview.line.chief",params:()=>({role:s("sidebar.bot.chiefOfStaff")})},{line:/^May also coordinate these (?:teams|departments): (.+)\.$/,key:()=>"botOverview.line.alsoTeams",params:([,t],n)=>({teams:Bt(t,n)})}],Wi=t=>ee()!=="en"&&Object.hasOwn(Vs[ee()]??{},t);function Vi(t,n){for(const a of qi){const o=a.line.exec(t);if(!o)continue;const i=a.key(o);return Wi(i)?s(i,a.params(o,n)):t}return null}function Ue(t,n){if(Object.hasOwn(Mt,t))return s(Mt[t]);const a=Vi(t,n);if(a!==null)return a;const o=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(o)return s(o[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(o[1]),apps:o[2]});const i=ee()==="en"?null:/^Computer preference: (.+), which isn't available on My Cloud\.$/.exec(t);if(i)return s("botOverview.line.computerNotOnCloud",{preference:$t(i[1])});const l=/^Computer preference: (.+)\.$/.exec(t);if(l)return s("botOverview.line.computer",{preference:$t(l[1])});const d=/^Works in (.+)\.$/.exec(t);if(d)return s("botOverview.line.folder",{folder:d[1]});const m=/^Knows how to (.+)\.$/.exec(t);if(m)return s("botOverview.line.skill",{skill:m[1]});const r=/^Listens for “(.+)” webhooks\.$/.exec(t);return r?s("botOverview.line.webhook",{name:r[1]}):t}const Dt={name:"approval.applied.field.name",title:"approval.applied.field.title",description:"approval.applied.field.description",soul:"approval.applied.field.soul",cwd:"approval.applied.field.cwd",notifications:"approval.applied.field.notifications",speakReplies:"approval.applied.field.speakReplies"};function Zi(t,n=ee()){const a=/^(\w+): /.exec(t)?.[1];return n==="en"||!a||!Object.hasOwn(Dt,a)?t:`${s(Dt[a])}: ${t.slice(a.length+2)}`}function Gi({data:t,error:n,open:a,onToggle:o}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:o,"aria-expanded":a,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("span",{className:"text-[15px] font-medium text-ink",children:t?s("botOverview.promptPreviewCount",{bytes:t.totalBytes.toLocaleString(De()),tokens:t.approxTokens.toLocaleString(De())}):s("botOverview.promptPreview")}),e.jsx(fe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",a&&"rotate-180")})]}),a&&!t&&n&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.promptError")}),a&&!t&&!n&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.loading")}),a&&t&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[t.sections.map(i=>e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center justify-between gap-3 text-[13px] text-ink",children:[e.jsx("span",{children:i.label}),e.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:s("botOverview.bytes",{count:i.bytes.toLocaleString(De())})})]}),e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-ink",children:i.text})]},i.id)),t.note&&e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t.note})]})]})}function Yi({overview:t,refreshError:n,prompt:a,promptError:o,onOpen:i,onSetup:l}){const[d,m]=u.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const c=(t.setup??[]).filter(x=>!x.done),p=(x,k)=>s(`botOverview.setup.${x}`)||k;return e.jsxs("div",{className:"flex flex-col gap-4",children:[n&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("botOverview.refreshError")}),c.length>0&&e.jsxs("div",{className:"rounded-xl border border-accent/30 bg-accent/[0.06] p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botSetup.ideas")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:s("botSetup.optional")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:c.map(x=>e.jsx("li",{children:x.section?e.jsxs("button",{type:"button",onClick:()=>i(x.section),className:"flex w-full items-center gap-2.5 rounded-lg px-1 py-1 text-left text-[13px] text-ink hover:bg-inset",children:[e.jsx(xt,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:p(x.id,x.label)}),e.jsx(je,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-secondary rtl:-scale-x-100"})]}):e.jsxs("div",{className:"flex items-center gap-2.5 px-1 py-1 text-[13px] text-ink",children:[e.jsx(xt,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:p(x.id,x.label)})]})},x.id))}),l&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(nt,{size:14})," ",s("botSetup.withBot")]}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:s("botSetup.help")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t.who.name}),t.who.title&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t.who.title}),t.who.blurb&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink",children:t.who.blurb}),t.who.soulLead&&e.jsxs("div",{className:"mt-3 rounded-lg bg-inset px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t.who.soulLead}),e.jsx("button",{type:"button",onClick:()=>i("soul"),className:"mt-1.5 rounded-md text-[12px] font-medium text-accent-text hover:underline",children:s("botOverview.readAll")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.does")}),t.does.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.doesEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.does.map((x,k)=>e.jsx("li",{children:Ui(t.doesRoutines?.[k])??Ue(x)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.canReach")}),t.reaches.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.reachEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.reaches.map((x,k)=>e.jsx("li",{children:Ue(x,t.managedSections)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.wont")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.wont.map((x,k)=>e.jsx("li",{children:Ue(x,t.managedSections)},k))})]}),e.jsx(Gi,{data:a,error:o,open:d,onToggle:()=>m(x=>!x)}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.recentChanges")}),e.jsxs("button",{type:"button",onClick:()=>i("history"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink",children:[s("botOverview.viewAll")," ",e.jsx(je,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),t.recent.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.recentEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-ink",children:t.recent.map((x,k)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Zi(x.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",ss(x.at)]})]},k))})]})]})}function Ji({managementUrl:t}){return e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:s("botSlack.body")}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[s("botSlack.manage")," ",e.jsx(gs,{size:14,"aria-hidden":"true"})]})]})}function Qi(t){if(!t||typeof t!="object")return null;const{available:n,managementUrl:a}=t;if(n!==!0||typeof a!="string")return null;try{return new URL(a).protocol==="https:"?a:null}catch{return null}}function Os(t){const[n,a]=u.useState(null);return u.useEffect(()=>{const o=new AbortController;return Z(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:o.signal,timeoutMs:1e4}).then(i=>{o.signal.aborted||a({botId:t,url:Qi(i)})}).catch(()=>{o.signal.aborted||a({botId:t,url:null})}),()=>o.abort()},[t]),n?.botId===t?n.url:null}const zt="/api/limix/plugins";function Es({bot:t}){const{state:n,dispatch:a}=B(),[o,i]=u.useState(),[l,d]=u.useState(""),[m,r]=u.useState(!1),c=ee().startsWith("vi")?"vi":"en";u.useEffect(()=>{if(n.pluginsOpen)return;const x=new AbortController;return Z(zt,{signal:x.signal}).then(i).catch(k=>{x.signal.aborted||d(ht(k.message))}),()=>x.abort()},[n.pluginsOpen]);async function p(x,k,f){r(!0),d("");try{i(await Z(zt,{method:"POST",body:JSON.stringify({action:"assign",target:"bot",key:t.id,id:x,sha256:k,enabled:f})}))}catch(v){d(ht(v instanceof Error?v.message:String(v)))}finally{r(!1)}}return e.jsxs("section",{className:"space-y-3",children:[e.jsx("button",{type:"button",className:gt,onClick:()=>a({type:"togglePlugins",open:!0,surface:"library"}),children:s("plugins.openLibrary")}),l&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:l}),!o&&!l&&e.jsx("p",{role:"status",className:"text-sm text-ink-secondary",children:ie("Đang tải plugin…","Loading plugins…")}),o?.installed.length===0&&e.jsx("p",{className:"text-sm text-ink-secondary",children:ie("Chưa có plugin sẵn sàng để gắn.","No plugins are ready to attach.")}),o?.installed.map(x=>{const f=!Object.hasOwn(x.bots,t.id)?"inherit":String(x.bots[t.id]),v=nn(x,t,o.installed),j=x.manifest?.source&&!x.allowHostExecution;return e.jsxs("article",{className:"flex flex-wrap items-center gap-3 rounded-xl border border-hairline p-3",children:[e.jsx(at,{size:20,className:"shrink-0","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h3",{className:"break-words text-sm font-semibold",children:[x.name[c]," ",e.jsxs("small",{className:"text-ink-secondary",children:["v",x.version]})]}),e.jsx("p",{className:"text-xs text-ink-secondary",children:j?ie("Cần duyệt quyền dùng Skill từ xa trong kho","Remote Skill execution consent required in the library"):v?ie("Đang gắn","Attached"):ie("Chưa gắn","Detached")})]}),e.jsxs("select",{className:gt,value:f,disabled:m,"aria-label":x.name[c]+" v"+x.version,onChange:N=>{p(x.id,x.sha256,N.target.value==="inherit"?null:N.target.value==="true")},children:[e.jsx("option",{value:"inherit",children:ie("Theo nhóm","Inherit from team")}),e.jsx("option",{value:"true",disabled:!!j,children:ie("Gắn plugin","Attach plugin")}),e.jsx("option",{value:"false",children:ie("Tắt trên bot","Disable for this bot")})]})]},x.sha256)})]})}const oe="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",qe="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",re=t=>t instanceof Error?t.message:String(t);function Rs(t){const n=[],a=(i,l,d)=>{i&&n.push(s(i===1?l:d,{count:i}))};a(t.expired,"memory.upkeep.summary.archived.one","memory.upkeep.summary.archived.many"),a(t.duplicates,"memory.upkeep.summary.merged.one","memory.upkeep.summary.merged.many"),a(t.superseded,"memory.upkeep.summary.crossed.one","memory.upkeep.summary.crossed.many"),a(t.organized,"memory.upkeep.summary.filed.one","memory.upkeep.summary.filed.many");const o=n.length?n.join(", "):s("memory.upkeep.summary.none");return o.charAt(0).toUpperCase()+o.slice(1)}function Xi(t,n){const a=t.via==="team-setup"?s("memory.journal.actor.teamSetup"):t.actor==="bot"?n:t.actor==="import"?s("memory.journal.actor.import"):t.actor==="upkeep"?s("memory.journal.actor.upkeep"):s("memory.journal.actor.you"),o=pi(t.path),i=t.path===se?o:t.path===mi?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:o}):s("memory.journal.topic",{file:o}),l=d=>s(d===1?"memory.journal.line.one":"memory.journal.line.many",{count:d});return t.kind==="created"?s("memory.journal.created",{who:a,topic:i,detail:t.added?s("memory.journal.withLines",{lines:l(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:a,topic:i}):t.added&&!t.removed?s("memory.journal.added",{who:a,lines:l(t.added),topic:i}):t.removed&&!t.added?s("memory.journal.removed",{who:a,lines:l(t.removed),topic:i}):s("memory.journal.rewrote",{who:a,lines:l(Math.max(t.added,t.removed)),topic:i})}function Ts({changed:t,stale:n,busy:a,onReviewed:o}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(n?"memory.lendingReviewStale":"memory.lendingReview")}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.lendingReviewChanged")}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.map(i=>e.jsx("li",{className:"break-all font-mono text-[12px] text-ink",children:i},i))})]}),e.jsx("button",{type:"button",className:O(oe,"mt-3"),disabled:a,onClick:o,children:s("memory.lendingReviewed")})]})}function er({bot:t,active:n=!0,onToggle:a}){const{capabilities:o}=we(),[i,l]=u.useState(null),[d,m]=u.useState(null),[r,c]=u.useState(null),[p,x]=u.useState(null),[k,f]=u.useState(null),[v,j]=u.useState(null),[N,w]=u.useState(null),[b,h]=u.useState(!1),[P,L]=u.useState(null),[D,$]=u.useState(""),[A,H]=u.useState(null),[I,g]=u.useState(!1),[T,F]=u.useState(null),[_,K]=u.useState(!1),[J,Y]=u.useState(!1),{state:U,dispatch:y}=B(),z=an(U.config),[ce,xe]=u.useState(!1),[ye,E]=u.useState(""),q=async C=>{const[R,$e,Ws]=await Promise.all([ot(t.id),ge(t.id),Ot(t.id).catch(()=>null)]);if(l(R),F(R.lendingReview??null),m($e),H(Ws),C){const Fe=await Ie(t.id,C);c({path:Fe.path,text:Fe.text,hash:Fe.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}};u.useEffect(()=>{if(!n)return;let C=!1;j(null);const R=r?.dirty===!0;return q(R?void 0:r?.path??se).catch($e=>{C||j(re($e))}),()=>{C=!0}},[n,t.id]);const G=async C=>{j(null),x(null);try{const R=await Ie(t.id,C);c({path:R.path,text:R.text,hash:R.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}catch(R){j(re(R))}},W=async C=>{if(r){h(!0),j(null);try{const R=await lt(t.id,r.path,r.text,C);if(!R.ok){x({path:r.path,current:R.current,currentHash:R.currentHash});return}x(null),f(null),c({...r,text:R.doc.text,hash:R.doc.hash,dirty:!1}),l(R.overview),m(await ge(t.id))}catch(R){j(re(R))}finally{h(!1)}}},de=()=>{!p||!r||(f(r.text),c({...r,text:p.current,hash:p.currentHash,dirty:!1}),x(null))},Se=async C=>{if(window.confirm(s("memory.confirmDelete",{name:C.name}))){j(null);try{const{overview:R}=await ks(t.id,C.path);l(R),m(await ge(t.id)),r?.path===C.path&&c(null)}catch(R){j(re(R))}}},dt=async()=>{const C=li(D);if(!C){j(s("memory.topicNameError"));return}$(""),await G(`memory/${C}`),c(R=>R&&{...R,dirty:!0,text:R.text||tr(C)})},Hs=async C=>{L(C.id),j(null);try{const R=await js(t.id,C.id);l(R.overview),m(await ge(t.id)),r?.path===C.path&&!r.dirty&&c({...r,text:R.text,hash:R.hash}),w(s("memory.restored",{path:C.path}))}catch(R){j(re(R))}finally{L(null)}},pt=async C=>{j(null),w(null);try{await ri(t.id,C)}catch(R){j(re(R))}},_s=()=>{const C=t.memoryUpkeep===!1;y({type:"updateBot",botId:t.id,patch:{memoryUpkeep:C}}),H(R=>R&&{...R,enabled:C})},Ks=async()=>{if(!ce){xe(!0),E("");try{const C=await Z("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!z}})});y({type:"configStatus",config:C})}catch(C){E(C instanceof Error?C.message:s("memory.learnFromRooms.error"))}finally{xe(!1)}}},Us=async()=>{g(!0),j(null),w(null);try{const{report:C,overview:R}=await vs(t.id);l(R),m(await ge(t.id)),H(await Ot(t.id)),r&&!r.dirty&&await G(r.path),w(`${Rs(C)}.${C.note?` ${C.note}`:""}`)}catch(C){j(re(C))}finally{g(!1)}},qs=o.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange:C=>a(C.target.checked)}),s("memory.enable")]}),e.jsxs("p",{className:"mt-1 text-[13px] text-ink-secondary",children:[s("memory.enableHelp"),t.busy?` ${s("memory.busyHelp")}`:""]}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.notesHelp")}),i&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink-secondary",title:i.workspacePath,children:it(i.workspacePath,qs)}),e.jsx("button",{type:"button",className:oe,onClick:()=>{pt("obsidian")},children:s("memory.openObsidian")}),e.jsxs("button",{type:"button",className:O(oe,"inline-flex items-center gap-1.5"),onClick:()=>{pt("folder")},children:[e.jsx(ns,{size:14}),s("memory.showFileManager")]})]})]}),T&&e.jsx(Ts,{changed:T.changed,stale:_,busy:J,onReviewed:()=>{Y(!0),bs(t.id,T.token).then(()=>{F(null),K(!1)}).catch(C=>{if(C instanceof as&&C.status===409)return K(!0),q();j(re(C))}).finally(()=>Y(!1))}}),i&&e.jsx(nr,{index:i.index}),t.memoryEnabled!==!1&&e.jsx(sr,{enabled:t.memoryUpkeep!==!1,status:A,tidying:I,onToggle:_s,onTidy:()=>{Us()},rooms:{enabled:z,saving:ce,error:ye,onToggle:()=>{Ks()}}}),r&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:r.path}),r.path!==se&&e.jsx("button",{type:"button",className:qe,onClick:()=>{G(se)},children:s("memory.backToIndex")})]}),p&&e.jsx(Is,{botName:t.name,busy:b,onReload:de,onOverwrite:()=>{W(p.currentHash)}}),e.jsx("textarea",{className:O(et,"mt-2 min-h-[200px] resize-y font-mono text-[13px] leading-relaxed"),value:r.text,readOnly:r.readOnly,placeholder:r.path===se?s("memory.indexPlaceholder"):s("memory.notePlaceholder"),"aria-label":r.path===se?s("memory.botMemory"):s("memory.fileLabel",{path:r.path}),onChange:C=>c({...r,text:C.target.value,dirty:!0})}),r.readOnly?e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.logsReadOnly")}):e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{W(r.hash)},disabled:b||!r.dirty,className:oe,children:b?s("memory.saving"):s("memory.save")}),r.dirty&&e.jsx("button",{type:"button",className:qe,disabled:b,onClick:()=>{G(r.path)},children:s("memory.discard")})]}),k!==null&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:k}),e.jsx("button",{type:"button",className:O(qe,"mt-1"),onClick:()=>f(null),children:s("memory.dismissDraft")})]})]}),i&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx(_t,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:i.topics,selected:r?.path,onOpen:C=>{G(C.path)},onDelete:C=>{Se(C)}}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{className:O(et,"py-1.5 text-[13px]"),value:D,placeholder:s("memory.newTopicPlaceholder"),"aria-label":s("memory.newTopicLabel"),onChange:C=>$(C.target.value),onKeyDown:C=>{C.key==="Enter"&&dt()}}),e.jsx("button",{type:"button",className:oe,disabled:!D.trim(),onClick:()=>{dt()},children:s("memory.newTopic")})]}),i.logs.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(_t,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:i.logs,selected:r?.path,onOpen:C=>{G(C.path)},onDelete:C=>{Se(C)}})})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.changes")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.changesHelp")}),e.jsx("div",{className:"mt-3",children:e.jsx(ct,{rows:d,botName:t.name,reverting:P,onRevert:C=>{Hs(C)}})})]}),N&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:N}),v&&e.jsx("div",{className:"text-[13px] text-danger",children:v})]})}function tr(t){return`---
1
+ import{c as Ae,t as s,l as ee,aF as Vs,j as e,i as De,ae as fe,a as O,r as x,S as tt,ah as Jt,X as st,d as pt}from"./styles-Bixj4Mfc.js";import{fq as Zs,fr as Gs,_ as nt,f3 as Qt,bE as Ys,dq as Xt,C as Js,fs as Qs,ft as Xs,E as es,fu as en,M as ts,eA as tn,p as sn,fv as mt,bu as ut,fw as ss,j as Z,u as B,fx as xt,fy as ht,f4 as ie,fz as nn,fA as an,fB as rn,fC as on,ag as at,af as ns,A as as,S as be,ab as Me,T as is,R as ln,fD as cn,fE as dn,fF as pn,fG as mn,fH as un,fI as gt,fJ as xn,fK as hn,fL as gn,fM as fn,a$ as yn,fN as bn,fO as vn,fP as kn,I as jn,fQ as Oe,bY as Le,fR as wn,aH as M,aN as Q,ek as Nn,dS as Sn,fS as Cn,aI as Ge,cw as Pn,e5 as On,e6 as En,fT as Rn,fU as rs,fV as os,fW as Tn,fX as In,fY as An,fZ as Mn,dV as Ye,aq as ft,f_ as ze,f$ as Ln,g0 as Re,au as Bn,g1 as ls,g2 as yt,aj as Je,g3 as $n,g4 as Fn,g5 as Dn,g6 as cs,g7 as zn,g8 as bt,g9 as Hn,ga as _n,gb as Kn,gc as te,aX as ae,aZ as X,gd as Un,ge as qn,gf as Wn,dc as Vn,aP as Zn,G as Gn,da as ds,ai as Yn,gg as V,aW as me,gh as ue,x as S,gi as Jn,dw as Qn,gj as Be,aY as le,gk as Xn,gl as ea,gm as ta,eo as sa,gn as vt,go as na,gp as aa,gq as ia,gr as ra,gs as oa,gt as la,az as ca,gu as ps,gv as ms,gw as da,gx as pa,gy as ma,gz as ua,gA as xa,gB as ha,gC as ga,gD as fa,gE as ya,gF as us,gG as ba,gH as va,gI as ka,gJ as it,g as ja,B as Qe,gK as wa,gL as Na,gM as Sa,gN as Ca,gO as Pa,gP as Oa,c5 as Ea,gQ as xs,D as kt,gR as Ra,f6 as Ta,gS as jt,gT as Ia,gU as Aa,gV as Ma,cT as wt,bC as La,d9 as Ba,gW as $a,gX as hs,gY as Ce,gZ as Nt,g_ as Fa,aL as He,e7 as Da,g$ as za,aR as Ha,dA as _a,cx as Ka,h0 as Ua,h1 as qa,h2 as Wa,aT as Va}from"./App-B2fBpoRZ.js";import{v as gs,d as we,a0 as Te,a1 as Za,a2 as Ga,a3 as St,a4 as _e,a5 as Ya,a6 as Ja,a7 as Qa,a8 as Xa,a9 as ei,aa as Ct,ab as ti,ac as si,L as Ee,M as ni,B as Xe,P as Ne,r as fs,ad as ai,$ as ii,u as ys}from"./PlacesRail-B0T5a390.js";import{C as ri}from"./coins-Bn14rFjr.js";import{C as je,a as oi}from"./MenuMotion-D8l5zOOH.js";import{b as se,m as bs,i as et,f as rt,c as ge,d as Pt,e as Ie,o as li,g as ci,h as pe,n as Ke,t as vs,s as ot,j as ks,k as di,l as pi,p as mi,r as js,q as ui,u as xi,w as hi,x as ws,y as Ns,z as Ot,B as gi,C as Ss,R as Et,D as fi,E as yi,F as bi,G as vi,H as ki,J as ji,O as wi,K as Ni,L as Cs,N as Rt,V as Si,P as Ci,M as Pi,A as Oi,a as Ei,S as Ri,I as Ti}from"./VisibilitySection-B0z1XJD4.js";import{s as Ii,r as Ai,a as Mi,R as Li}from"./ComputerFilesPane-BC49N1Pm.js";import{M as Tt}from"./monitor-15mG3xlc.js";import{R as Bi}from"./RoutinesPage-B-QJRpZi.js";import{S as $i}from"./SignedInSites-CPLPNDp5.js";import"./index-VDBTcIMw.js";import"./org-library-DT_poCG3.js";import"./package-format-CgaIxeTU.js";import"./WorksOnGrid-BOLs3g9Y.js";import"./ProIntroduction-BJMwoQGa.js";import"./remote-desktop-DDRRx8uY.js";const Fi=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],Di=Ae("calendar-plus",Fi);const zi=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],Hi=Ae("library",zi);const _i=[["rect",{width:"3",height:"8",x:"13",y:"2",rx:"1.5",key:"diqz80"}],["path",{d:"M19 8.5V10h1.5A1.5 1.5 0 1 0 19 8.5",key:"183iwg"}],["rect",{width:"3",height:"8",x:"8",y:"14",rx:"1.5",key:"hqg7r1"}],["path",{d:"M5 15.5V14H3.5A1.5 1.5 0 1 0 5 15.5",key:"76g71w"}],["rect",{width:"8",height:"3",x:"14",y:"13",rx:"1.5",key:"1kmz0a"}],["path",{d:"M15.5 19H14v1.5a1.5 1.5 0 1 0 1.5-1.5",key:"jc4sz0"}],["rect",{width:"8",height:"3",x:"2",y:"8",rx:"1.5",key:"1omvl4"}],["path",{d:"M8.5 5H10V3.5A1.5 1.5 0 1 0 8.5 5",key:"16f3cl"}]],Ps=Ae("slack",_i);const Ki=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Ui=Ae("tag",Ki),qi=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Zs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Gs,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:Ps,keywords:["slack","slack app","admin","message","direct messages","mentions"]},{id:"soul",label:"Soul",labelKey:"botSettings.sections.soul",icon:nt,keywords:["standing instructions","instructions","persona","rules","soul.md"]},{id:"plugins",label:"Plugins",labelKey:"plugins.botMenu",icon:Qt,keywords:["plugin","attach","gắn"]},{id:"skills",label:"Skills",labelKey:"botSettings.sections.skills",icon:Ys,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:Xt,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:Hi,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:Js,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Qs,keywords:["works on","computer","vm","cloud","vps","folder","workspace","browser","connected apps","composio","webhooks","always allow","grants","tool selection","tools","mcp","allow","exclude"]},{id:"model",label:"Model",labelKey:"botSettings.sections.model",icon:Xs,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:es,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:en,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:ts,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:tn,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:ri,keywords:["tokens","cost","billing"]}],It={completed:"botOverview.routine.last.completed",failed:"botOverview.routine.last.failed",missed:"botOverview.routine.last.missed",cancelled:"botOverview.routine.last.cancelled",running:"botOverview.routine.last.running",queued:"botOverview.routine.last.queued",waiting:"botOverview.routine.last.waiting"};function Wi(t,n=ee()){if(!t||n==="en")return null;if(t.paused)return s("botOverview.routine.paused",{name:t.name});const a=t.lastRun;if(a&&!Object.hasOwn(It,a.status))return null;try{return[s("botOverview.routine.line",{schedule:sn(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:mt(t.nextRunAt)})]:[],...a?[s(It[a.status],{time:mt(a.at)})]:[]].join(" ")}catch{return null}}const At={"Works in its private workspace.":"botOverview.line.privateWorkspace","Has the built-in browser.":"botOverview.line.browser","Has no connected apps.":"botOverview.line.noApps","Won't act on a schedule.":"botOverview.line.noSchedule","Can talk to the other bot.":"botOverview.line.talksToOne","Talks only to the bots chosen for it.":"botOverview.line.talksToChosen","Cannot initiate contact with other bots.":"botOverview.line.noPeerContact","Command approvals use Ask mode; saved permissions and provider rules still apply.":"botOverview.line.askMode","Command approvals follow the provider's custom configuration.":"botOverview.line.customApprovals","Asks before contacting other bots.":"botOverview.line.asksPeers","Can't use a computer.":"botOverview.line.noComputer","Profile proposal cards require your approval.":"botOverview.line.profileApproval","Connected apps could not be checked.":"botOverview.line.appsUnchecked"},Mt={"Auto; availability is checked when a task starts":"botOverview.preference.auto","cloud computer":"botOverview.preference.cloud","Local VM":"botOverview.preference.vm","this computer":"botOverview.preference.local","browser only":"botOverview.preference.browser"};function Lt(t,n){return!n||n.map(a=>a||"General").join(", ")!==t?t:n.map(a=>a||s("botAccess.teams.general")).join(", ")}const Bt=t=>Object.hasOwn(Mt,t)?s(Mt[t]):t,$t=(t,n,a)=>Number(t)===1?n:a,Vi=[{line:/^Can talk to all (\d+) other bots, in any department\.$/,key:()=>"botOverview.line.talksToAll",params:([,t])=>({count:Number(t)})},{line:/^Also in charge of these departments: (.+)\.$/,key:()=>"botOverview.line.alsoInCharge",params:([,t],n)=>({departments:Lt(t,n)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>$t(t,"botOverview.line.peersSectionOne","botOverview.line.peersSectionMany"),params:([,t])=>({count:Number(t)})},{line:/^Can talk to (\d+) other bots? in its allowed (?:teams|departments)\.$/,key:([,t])=>$t(t,"botOverview.line.peersTeamsOne","botOverview.line.peersTeamsMany"),params:([,t])=>({count:Number(t)})},{line:/^Coordinates its (?:section|department) as Chief of Staff\.$/,key:()=>"botOverview.line.chief",params:()=>({role:s("sidebar.bot.chiefOfStaff")})},{line:/^May also coordinate these (?:teams|departments): (.+)\.$/,key:()=>"botOverview.line.alsoTeams",params:([,t],n)=>({teams:Lt(t,n)})}],Zi=t=>ee()!=="en"&&Object.hasOwn(Vs[ee()]??{},t);function Gi(t,n){for(const a of Vi){const o=a.line.exec(t);if(!o)continue;const i=a.key(o);return Zi(i)?s(i,a.params(o,n)):t}return null}function Ue(t,n){if(Object.hasOwn(At,t))return s(At[t]);const a=Gi(t,n);if(a!==null)return a;const o=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(o)return s(o[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(o[1]),apps:o[2]});const i=ee()==="en"?null:/^Computer preference: (.+), which isn't available on My Cloud\.$/.exec(t);if(i)return s("botOverview.line.computerNotOnCloud",{preference:Bt(i[1])});const l=/^Computer preference: (.+)\.$/.exec(t);if(l)return s("botOverview.line.computer",{preference:Bt(l[1])});const d=/^Works in (.+)\.$/.exec(t);if(d)return s("botOverview.line.folder",{folder:d[1]});const m=/^Knows how to (.+)\.$/.exec(t);if(m)return s("botOverview.line.skill",{skill:m[1]});const r=/^Listens for “(.+)” webhooks\.$/.exec(t);return r?s("botOverview.line.webhook",{name:r[1]}):t}const Ft={name:"approval.applied.field.name",title:"approval.applied.field.title",description:"approval.applied.field.description",soul:"approval.applied.field.soul",cwd:"approval.applied.field.cwd",notifications:"approval.applied.field.notifications",speakReplies:"approval.applied.field.speakReplies"};function Yi(t,n=ee()){const a=/^(\w+): /.exec(t)?.[1];return n==="en"||!a||!Object.hasOwn(Ft,a)?t:`${s(Ft[a])}: ${t.slice(a.length+2)}`}function Ji({data:t,error:n,open:a,onToggle:o}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:o,"aria-expanded":a,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("span",{className:"text-[15px] font-medium text-ink",children:t?s("botOverview.promptPreviewCount",{bytes:t.totalBytes.toLocaleString(De()),tokens:t.approxTokens.toLocaleString(De())}):s("botOverview.promptPreview")}),e.jsx(fe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",a&&"rotate-180")})]}),a&&!t&&n&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.promptError")}),a&&!t&&!n&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.loading")}),a&&t&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[t.sections.map(i=>e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center justify-between gap-3 text-[13px] text-ink",children:[e.jsx("span",{children:i.label}),e.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:s("botOverview.bytes",{count:i.bytes.toLocaleString(De())})})]}),e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-ink",children:i.text})]},i.id)),t.note&&e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t.note})]})]})}function Qi({overview:t,refreshError:n,prompt:a,promptError:o,onOpen:i,onSetup:l}){const[d,m]=x.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const c=(t.setup??[]).filter(u=>!u.done),p=(u,k)=>s(`botOverview.setup.${u}`)||k;return e.jsxs("div",{className:"flex flex-col gap-4",children:[n&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("botOverview.refreshError")}),c.length>0&&e.jsxs("div",{className:"rounded-xl border border-accent/30 bg-accent/[0.06] p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botSetup.ideas")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:s("botSetup.optional")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:c.map(u=>e.jsx("li",{children:u.section?e.jsxs("button",{type:"button",onClick:()=>i(u.section),className:"flex w-full items-center gap-2.5 rounded-lg px-1 py-1 text-left text-[13px] text-ink hover:bg-inset",children:[e.jsx(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:p(u.id,u.label)}),e.jsx(je,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-secondary rtl:-scale-x-100"})]}):e.jsxs("div",{className:"flex items-center gap-2.5 px-1 py-1 text-[13px] text-ink",children:[e.jsx(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:p(u.id,u.label)})]})},u.id))}),l&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(nt,{size:14})," ",s("botSetup.withBot")]}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:s("botSetup.help")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t.who.name}),t.who.title&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t.who.title}),t.who.blurb&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink",children:t.who.blurb}),t.who.soulLead&&e.jsxs("div",{className:"mt-3 rounded-lg bg-inset px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t.who.soulLead}),e.jsx("button",{type:"button",onClick:()=>i("soul"),className:"mt-1.5 rounded-md text-[12px] font-medium text-accent-text hover:underline",children:s("botOverview.readAll")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.does")}),t.does.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.doesEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.does.map((u,k)=>e.jsx("li",{children:Wi(t.doesRoutines?.[k])??Ue(u)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.canReach")}),t.reaches.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.reachEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.reaches.map((u,k)=>e.jsx("li",{children:Ue(u,t.managedSections)},k))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.wont")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.wont.map((u,k)=>e.jsx("li",{children:Ue(u,t.managedSections)},k))})]}),e.jsx(Ji,{data:a,error:o,open:d,onToggle:()=>m(u=>!u)}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.recentChanges")}),e.jsxs("button",{type:"button",onClick:()=>i("history"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink",children:[s("botOverview.viewAll")," ",e.jsx(je,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),t.recent.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.recentEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-ink",children:t.recent.map((u,k)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Yi(u.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",ss(u.at)]})]},k))})]})]})}function Xi({managementUrl:t}){return e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:s("botSlack.body")}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[s("botSlack.manage")," ",e.jsx(gs,{size:14,"aria-hidden":"true"})]})]})}function er(t){if(!t||typeof t!="object")return null;const{available:n,managementUrl:a}=t;if(n!==!0||typeof a!="string")return null;try{return new URL(a).protocol==="https:"?a:null}catch{return null}}function Os(t){const[n,a]=x.useState(null);return x.useEffect(()=>{const o=new AbortController;return Z(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:o.signal,timeoutMs:1e4}).then(i=>{o.signal.aborted||a({botId:t,url:er(i)})}).catch(()=>{o.signal.aborted||a({botId:t,url:null})}),()=>o.abort()},[t]),n?.botId===t?n.url:null}const Dt="/api/limix/plugins";function Es({bot:t}){const{state:n,dispatch:a}=B(),[o,i]=x.useState(),[l,d]=x.useState(""),[m,r]=x.useState(!1),c=ee().startsWith("vi")?"vi":"en";x.useEffect(()=>{if(n.pluginsOpen)return;const u=new AbortController;return Z(Dt,{signal:u.signal}).then(i).catch(k=>{u.signal.aborted||d(xt(k.message))}),()=>u.abort()},[n.pluginsOpen]);async function p(u,k,f){r(!0),d("");try{i(await Z(Dt,{method:"POST",body:JSON.stringify({action:"assign",target:"bot",key:t.id,id:u,sha256:k,enabled:f})}))}catch(v){d(xt(v instanceof Error?v.message:String(v)))}finally{r(!1)}}return e.jsxs("section",{className:"space-y-3",children:[e.jsx("button",{type:"button",className:ht,onClick:()=>a({type:"togglePlugins",open:!0,surface:"library"}),children:s("plugins.openLibrary")}),l&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:l}),!o&&!l&&e.jsx("p",{role:"status",className:"text-sm text-ink-secondary",children:ie("Đang tải plugin…","Loading plugins…")}),o?.installed.length===0&&e.jsx("p",{className:"text-sm text-ink-secondary",children:ie("Chưa có plugin sẵn sàng để gắn.","No plugins are ready to attach.")}),o?.installed.map(u=>{const f=!Object.hasOwn(u.bots,t.id)?"inherit":String(u.bots[t.id]),v=nn(u,t,o.installed),j=u.manifest?.source&&!u.allowHostExecution;return e.jsxs("article",{className:"flex flex-wrap items-center gap-3 rounded-xl border border-hairline p-3",children:[e.jsx(an,{icon:u.manifest?.icon??rn(u.id,u.name.en,u.name.vi,...u.requiresMcp),compact:!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h3",{className:"break-words text-sm font-semibold",children:[u.name[c]," ",e.jsxs("small",{className:"text-ink-secondary",children:["v",u.version]})]}),e.jsx("p",{className:"text-xs text-ink-secondary",children:j?ie("Cần duyệt quyền dùng Skill từ xa trong kho","Remote Skill execution consent required in the library"):v?ie("Đang gắn","Attached"):ie("Chưa gắn","Detached")})]}),e.jsxs("select",{className:ht,value:f,disabled:m,"aria-label":u.name[c]+" v"+u.version,onChange:N=>{p(u.id,u.sha256,N.target.value==="inherit"?null:N.target.value==="true")},children:[e.jsx("option",{value:"inherit",children:ie("Theo nhóm","Inherit from team")}),e.jsx("option",{value:"true",disabled:!!j,children:ie("Gắn plugin","Attach plugin")}),e.jsx("option",{value:"false",children:ie("Tắt trên bot","Disable for this bot")})]})]},u.sha256)})]})}const oe="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",qe="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",re=t=>t instanceof Error?t.message:String(t);function Rs(t){const n=[],a=(i,l,d)=>{i&&n.push(s(i===1?l:d,{count:i}))};a(t.expired,"memory.upkeep.summary.archived.one","memory.upkeep.summary.archived.many"),a(t.duplicates,"memory.upkeep.summary.merged.one","memory.upkeep.summary.merged.many"),a(t.superseded,"memory.upkeep.summary.crossed.one","memory.upkeep.summary.crossed.many"),a(t.organized,"memory.upkeep.summary.filed.one","memory.upkeep.summary.filed.many");const o=n.length?n.join(", "):s("memory.upkeep.summary.none");return o.charAt(0).toUpperCase()+o.slice(1)}function tr(t,n){const a=t.via==="team-setup"?s("memory.journal.actor.teamSetup"):t.actor==="bot"?n:t.actor==="import"?s("memory.journal.actor.import"):t.actor==="upkeep"?s("memory.journal.actor.upkeep"):s("memory.journal.actor.you"),o=ui(t.path),i=t.path===se?o:t.path===xi?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:o}):s("memory.journal.topic",{file:o}),l=d=>s(d===1?"memory.journal.line.one":"memory.journal.line.many",{count:d});return t.kind==="created"?s("memory.journal.created",{who:a,topic:i,detail:t.added?s("memory.journal.withLines",{lines:l(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:a,topic:i}):t.added&&!t.removed?s("memory.journal.added",{who:a,lines:l(t.added),topic:i}):t.removed&&!t.added?s("memory.journal.removed",{who:a,lines:l(t.removed),topic:i}):s("memory.journal.rewrote",{who:a,lines:l(Math.max(t.added,t.removed)),topic:i})}function Ts({changed:t,stale:n,busy:a,onReviewed:o}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(n?"memory.lendingReviewStale":"memory.lendingReview")}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.lendingReviewChanged")}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.map(i=>e.jsx("li",{className:"break-all font-mono text-[12px] text-ink",children:i},i))})]}),e.jsx("button",{type:"button",className:O(oe,"mt-3"),disabled:a,onClick:o,children:s("memory.lendingReviewed")})]})}function sr({bot:t,active:n=!0,onToggle:a}){const{capabilities:o}=we(),[i,l]=x.useState(null),[d,m]=x.useState(null),[r,c]=x.useState(null),[p,u]=x.useState(null),[k,f]=x.useState(null),[v,j]=x.useState(null),[N,w]=x.useState(null),[b,h]=x.useState(!1),[P,L]=x.useState(null),[D,$]=x.useState(""),[A,H]=x.useState(null),[I,g]=x.useState(!1),[T,F]=x.useState(null),[_,K]=x.useState(!1),[J,Y]=x.useState(!1),{state:U,dispatch:y}=B(),z=on(U.config),[ce,xe]=x.useState(!1),[ye,E]=x.useState(""),q=async C=>{const[R,$e,Ws]=await Promise.all([rt(t.id),ge(t.id),Pt(t.id).catch(()=>null)]);if(l(R),F(R.lendingReview??null),m($e),H(Ws),C){const Fe=await Ie(t.id,C);c({path:Fe.path,text:Fe.text,hash:Fe.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}};x.useEffect(()=>{if(!n)return;let C=!1;j(null);const R=r?.dirty===!0;return q(R?void 0:r?.path??se).catch($e=>{C||j(re($e))}),()=>{C=!0}},[n,t.id]);const G=async C=>{j(null),u(null);try{const R=await Ie(t.id,C);c({path:R.path,text:R.text,hash:R.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}catch(R){j(re(R))}},W=async C=>{if(r){h(!0),j(null);try{const R=await ot(t.id,r.path,r.text,C);if(!R.ok){u({path:r.path,current:R.current,currentHash:R.currentHash});return}u(null),f(null),c({...r,text:R.doc.text,hash:R.doc.hash,dirty:!1}),l(R.overview),m(await ge(t.id))}catch(R){j(re(R))}finally{h(!1)}}},de=()=>{!p||!r||(f(r.text),c({...r,text:p.current,hash:p.currentHash,dirty:!1}),u(null))},Se=async C=>{if(window.confirm(s("memory.confirmDelete",{name:C.name}))){j(null);try{const{overview:R}=await ks(t.id,C.path);l(R),m(await ge(t.id)),r?.path===C.path&&c(null)}catch(R){j(re(R))}}},ct=async()=>{const C=di(D);if(!C){j(s("memory.topicNameError"));return}$(""),await G(`memory/${C}`),c(R=>R&&{...R,dirty:!0,text:R.text||nr(C)})},Hs=async C=>{L(C.id),j(null);try{const R=await js(t.id,C.id);l(R.overview),m(await ge(t.id)),r?.path===C.path&&!r.dirty&&c({...r,text:R.text,hash:R.hash}),w(s("memory.restored",{path:C.path}))}catch(R){j(re(R))}finally{L(null)}},dt=async C=>{j(null),w(null);try{await li(t.id,C)}catch(R){j(re(R))}},_s=()=>{const C=t.memoryUpkeep===!1;y({type:"updateBot",botId:t.id,patch:{memoryUpkeep:C}}),H(R=>R&&{...R,enabled:C})},Ks=async()=>{if(!ce){xe(!0),E("");try{const C=await Z("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!z}})});y({type:"configStatus",config:C})}catch(C){E(C instanceof Error?C.message:s("memory.learnFromRooms.error"))}finally{xe(!1)}}},Us=async()=>{g(!0),j(null),w(null);try{const{report:C,overview:R}=await vs(t.id);l(R),m(await ge(t.id)),H(await Pt(t.id)),r&&!r.dirty&&await G(r.path),w(`${Rs(C)}.${C.note?` ${C.note}`:""}`)}catch(C){j(re(C))}finally{g(!1)}},qs=o.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange:C=>a(C.target.checked)}),s("memory.enable")]}),e.jsxs("p",{className:"mt-1 text-[13px] text-ink-secondary",children:[s("memory.enableHelp"),t.busy?` ${s("memory.busyHelp")}`:""]}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.notesHelp")}),i&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink-secondary",title:i.workspacePath,children:at(i.workspacePath,qs)}),e.jsx("button",{type:"button",className:oe,onClick:()=>{dt("obsidian")},children:s("memory.openObsidian")}),e.jsxs("button",{type:"button",className:O(oe,"inline-flex items-center gap-1.5"),onClick:()=>{dt("folder")},children:[e.jsx(ns,{size:14}),s("memory.showFileManager")]})]})]}),T&&e.jsx(Ts,{changed:T.changed,stale:_,busy:J,onReviewed:()=>{Y(!0),bs(t.id,T.token).then(()=>{F(null),K(!1)}).catch(C=>{if(C instanceof as&&C.status===409)return K(!0),q();j(re(C))}).finally(()=>Y(!1))}}),i&&e.jsx(ir,{index:i.index}),t.memoryEnabled!==!1&&e.jsx(ar,{enabled:t.memoryUpkeep!==!1,status:A,tidying:I,onToggle:_s,onTidy:()=>{Us()},rooms:{enabled:z,saving:ce,error:ye,onToggle:()=>{Ks()}}}),r&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:r.path}),r.path!==se&&e.jsx("button",{type:"button",className:qe,onClick:()=>{G(se)},children:s("memory.backToIndex")})]}),p&&e.jsx(Is,{botName:t.name,busy:b,onReload:de,onOverwrite:()=>{W(p.currentHash)}}),e.jsx("textarea",{className:O(et,"mt-2 min-h-[200px] resize-y font-mono text-[13px] leading-relaxed"),value:r.text,readOnly:r.readOnly,placeholder:r.path===se?s("memory.indexPlaceholder"):s("memory.notePlaceholder"),"aria-label":r.path===se?s("memory.botMemory"):s("memory.fileLabel",{path:r.path}),onChange:C=>c({...r,text:C.target.value,dirty:!0})}),r.readOnly?e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.logsReadOnly")}):e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{W(r.hash)},disabled:b||!r.dirty,className:oe,children:b?s("memory.saving"):s("memory.save")}),r.dirty&&e.jsx("button",{type:"button",className:qe,disabled:b,onClick:()=>{G(r.path)},children:s("memory.discard")})]}),k!==null&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:k}),e.jsx("button",{type:"button",className:O(qe,"mt-1"),onClick:()=>f(null),children:s("memory.dismissDraft")})]})]}),i&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx(Ht,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:i.topics,selected:r?.path,onOpen:C=>{G(C.path)},onDelete:C=>{Se(C)}}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{className:O(et,"py-1.5 text-[13px]"),value:D,placeholder:s("memory.newTopicPlaceholder"),"aria-label":s("memory.newTopicLabel"),onChange:C=>$(C.target.value),onKeyDown:C=>{C.key==="Enter"&&ct()}}),e.jsx("button",{type:"button",className:oe,disabled:!D.trim(),onClick:()=>{ct()},children:s("memory.newTopic")})]}),i.logs.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Ht,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:i.logs,selected:r?.path,onOpen:C=>{G(C.path)},onDelete:C=>{Se(C)}})})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.changes")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.changesHelp")}),e.jsx("div",{className:"mt-3",children:e.jsx(lt,{rows:d,botName:t.name,reverting:P,onRevert:C=>{Hs(C)}})})]}),N&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:N}),v&&e.jsx("div",{className:"text-[13px] text-danger",children:v})]})}function nr(t){return`---
2
2
  title: ${t.replace(/\.md$/,"")}
3
3
  description:
4
4
  aliases: []
5
5
  ---
6
6
 
7
- `}function sr({enabled:t,status:n,tidying:a,onToggle:o,onTidy:i,rooms:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.upkeep.title")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.upkeep.help")})]}),e.jsx(be,{checked:t,"aria-label":s("memory.upkeep.title"),onClick:o})]}),t&&l&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3 border-t border-hairline/40 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:s("memory.learnFromRooms.title")}),e.jsx("p",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.subtitle")}),n&&!n.modelSteps&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.noModelSteps")}),l.error&&e.jsx("p",{role:"alert",className:"mt-1 text-[13px] text-danger",children:l.error})]}),e.jsx(be,{checked:l.enabled,"aria-label":s("memory.learnFromRooms.title"),disabled:l.saving,onClick:l.onToggle,className:"disabled:cursor-wait disabled:opacity-50"})]}),t&&n&&!n.modelSteps&&e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.upkeep.noModelSteps")}),t&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",className:oe,disabled:a,onClick:i,children:a?s("memory.upkeep.tidying"):s("memory.upkeep.tidyNow")}),e.jsxs("span",{className:"text-[13px] text-ink-secondary",children:[n?.lastTidy?s("memory.upkeep.lastTidy",{time:Te(n.lastTidy.at,ee()),summary:Rs(n.lastTidy).toLowerCase()}):s("memory.upkeep.notTidied"),n?.lastCapture&&Ke(n.lastCapture)?` ${s(Ke(n.lastCapture)===1?"memory.upkeep.lastNoticed.one":"memory.upkeep.lastNoticed.many",{count:Ke(n.lastCapture),time:Te(n.lastCapture.at,ee())})}`:""]})]})]})}function nr({index:t}){const n=oi(t),a=n.level==="over"?"bg-danger":n.level==="near"?"bg-warning":"bg-accent";return e.jsxs("div",{className:O("rounded-xl p-4",n.level==="over"?"border border-danger/30 bg-danger/10":"bg-card"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[13px]",children:[e.jsx("span",{className:"font-medium text-ink",children:s("memory.capacity.title")}),e.jsx("span",{className:O("text-[12px]",n.level==="over"?"text-danger":"text-ink-secondary"),children:s("memory.capacity.summary",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes)})})]}),e.jsx(Ht,{label:s("memory.capacity.lines"),share:n.lineShare,fill:a}),e.jsx(Ht,{label:s("memory.capacity.size"),share:n.byteShare,fill:a}),e.jsx("p",{className:O("mt-2 text-[13px] leading-relaxed",n.level==="over"?"text-danger":"text-ink-secondary"),children:n.warning??s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes),maxLoaded:t.maxLines})}),n.warning&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes),maxLoaded:t.maxLines})})]})}function Ht({label:t,share:n,fill:a}){const o=`${Math.min(100,Math.round(n*100))}%`;return e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"w-10 shrink-0",children:t}),e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-inset",role:"meter","aria-label":s("memory.capacity.used",{label:t}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,Math.round(n*100)),children:e.jsx("div",{className:O("h-full rounded-full",a),style:{width:o}})})]})}function Is({botName:t,busy:n,onReload:a,onOverwrite:o}){return e.jsxs("div",{className:"mt-2 rounded-lg border border-warning/25 bg-warning/10 p-3 text-[13px] leading-relaxed text-ink",children:[e.jsx("div",{className:"font-medium",children:s("memory.conflict.title",{name:t})}),e.jsx("div",{className:"mt-0.5 text-ink-secondary",children:s("memory.conflict.help",{name:t})}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",className:oe,disabled:n,onClick:a,children:s("memory.reload")}),e.jsx("button",{type:"button",className:oe,disabled:n,onClick:o,children:s("memory.overwrite")})]})]})}function _t({title:t,hint:n,files:a,selected:o,onOpen:i,onDelete:l}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] text-ink-secondary",children:n}),a.length===0?e.jsx("div",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.noneYet")}):e.jsx("div",{className:"mt-2 overflow-hidden rounded-lg border border-hairline/40",children:a.map(d=>e.jsxs("div",{className:O("flex items-center gap-2 border-b border-hairline/40 px-3 py-2 last:border-b-0",o===d.path?"bg-control/60":"hover:bg-control/40"),children:[e.jsxs("button",{type:"button",onClick:()=>i(d),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Me,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:d.name}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:[pe(d.bytes)," · ",Te(d.modifiedAt,ee())]})]}),e.jsx("button",{type:"button",onClick:()=>l(d),"aria-label":s("memory.deleteFile",{name:d.name}),title:s("memory.delete"),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:bg-control hover:text-danger",children:e.jsx(is,{size:14})})]},d.path))})]})}function ct({rows:t,botName:n,reverting:a,onRevert:o,now:i=Date.now()}){return t?t.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.noChanges")}):e.jsx("div",{className:"flex flex-col gap-2",children:t.map(l=>{const d=ci(l),m=di(l);return e.jsxs("div",{className:"rounded-lg bg-inset px-3 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{children:Xi(l,n)})," · ",e.jsx("span",{className:"text-ink-secondary",children:Te(l.at,ee(),i)}),d&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-ink-secondary",children:m?s(m,l.threadTitle?{title:l.threadTitle}:void 0):d})]})]}),l.canRevert?e.jsxs("button",{type:"button",disabled:a!==null,onClick:()=>o(l),className:"inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:[e.jsx(rn,{size:12}),a===l.id?s("memory.undoing"):s("memory.undo")]}):e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",title:l.revertUnavailableReason,children:s("memory.cantUndo")})]}),l.diff&&e.jsxs("details",{className:"mt-1",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:["+",l.added," −",l.removed," · ",s("memory.showChanged")]}),e.jsx("pre",{className:"mt-1 max-h-[240px] overflow-auto whitespace-pre-wrap rounded-md bg-card p-2 font-mono text-[12px] leading-relaxed text-ink",children:l.diff})]})]},l.id)})}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.loading")})}function ar({bot:t,rows:n,refreshError:a,onRollback:o,rollingBack:i}){if(!n)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.loading")});if(n.length===0)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.empty")});const l=[...n].sort((d,m)=>m.at-d.at);return e.jsxs("div",{className:"flex flex-col gap-2",children:[a&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("history.refreshError")}),l.map(d=>e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{className:"text-ink-secondary",children:ss(d.at)})," · ",e.jsxs("span",{children:[d.actor," via ",d.via]})," · ",e.jsx("span",{children:d.summary})]}),d.field==="soul"&&d.canRestore===!0&&e.jsx("button",{type:"button",disabled:i,onClick:()=>o(d.id),className:"shrink-0 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:s("history.undo")})]}),d.field==="soul"&&d.canRestore!==!0&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:d.restoreUnavailableReason??s("history.restoreUnavailable")})]},`${t.id}-${d.id}`))]})}function ir({bot:t,bare:n=!1}){const{state:a,dispatch:o}=B(),i=on(t),l=a.instances.find(d=>d.instanceId===t.modelSelection.instanceId);return i.turns===0?e.jsx("div",{className:O(n?"":"rounded-xl bg-card p-4","text-[13px] text-ink-secondary"),children:s("usage.bot.empty")}):e.jsxs("div",{className:n?void 0:"rounded-xl bg-card p-4",children:[!n&&e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("usage.title")}),e.jsxs("button",{onClick:()=>o({type:"toggleAppSettings",open:!0,section:"usage"}),className:"text-[12px] text-ink-secondary hover:text-ink",children:[s("usage.allBots")," ",e.jsx(je,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),e.jsxs("div",{className:O("grid grid-cols-3 gap-3 text-[13px]",!n&&"mt-3"),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colTurns")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:i.turns})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:ln(i)}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",title:pn(i),children:cn(dn(i))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colCost")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:ft(i.costUsd)?mn(i.costUsd):"—"})]})]}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:ft(i.costUsd)?s("usage.costLine",{caption:un(l?.snapshot.billing)}):s("usage.bot.unpriced")})]})}const rr=[["bot","botPanel.avatar.tabBot"],["generate","botPanel.avatar.tabGenerate"],["upload","botPanel.avatar.tabUpload"]],or=["circle","rounded","square"],lr={circle:"botPanel.avatar.circle",rounded:"botPanel.avatar.rounded",square:"botPanel.avatar.square"},cr={idle:"botPanel.face.idle",happy:"botPanel.face.happy",curious:"botPanel.face.curious",drowsy:"botPanel.face.drowsy",working:"botPanel.face.working",thinking:"botPanel.face.thinking",listening:"botPanel.face.listening",sleeping:"botPanel.face.sleeping",suspicious:"botPanel.face.suspicious",proud:"botPanel.face.proud"},dr=t=>{const n=cr[t];return n?s(n):t};function pr({bot:t,activeState:n,onPatch:a,onClose:o}){const i=xn(t,a),{fileRef:l,crop:d,uploading:m,generating:r,busy:c,error:p,upload:x,removeImage:k,generate:f}=i,v=d!=="mascot"&&!!t.avatarUrl,[j,N]=u.useState(v?"upload":"bot"),w=u.useRef(null);u.useEffect(()=>{w.current?.querySelector('[aria-selected="true"]')?.focus()},[]);const b=g=>a(d==="mascot"?g:{...g,avatarCrop:"mascot"}),h=t.mascotBody??"cursor",P=Wa(),L=Va(t.mascotBody,t.color,P),[D,$]=u.useState(()=>!!P||Ct(h)||!!(t.mascotExpression&&t.mascotExpression!=="idle")),A=P&&L!==h&&Ct(L)?_e(L):null,H=(g,T)=>e.jsx("button",{type:"button",disabled:c,"aria-pressed":!v&&h===g,"aria-label":s("mascot.useBody",{name:T}),title:T,onClick:()=>b({mascotBody:g}),className:O("flex h-[58px] items-center justify-center rounded-xl disabled:opacity-50",!v&&h===g?"bg-ink/[0.08] ring-[1.5px] ring-inset ring-ink/25":"hover:bg-ink/[0.05]"),children:e.jsx(ti,{color:t.color,faceColor:t.mascotFaceColor,bodyId:g,size:40,animated:!1,trackPointer:!1})},g),I=g=>{g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),o())};return e.jsxs("div",{role:"dialog","aria-label":s("botPanel.avatar.edit"),"data-panel-avatar-editor":!0,"data-look":"popover",onKeyDown:I,className:"popover-surface absolute inset-x-[-5px] top-[80px] z-30 overflow-hidden rounded-2xl border border-ink/[0.08] bg-menu text-left shadow-2xl shadow-black/50",children:[e.jsxs("div",{ref:w,className:"flex items-center gap-0.5 border-b border-ink/[0.06] p-2",children:[rr.map(([g,T])=>e.jsx("button",{type:"button",role:"tab","aria-selected":j===g,"data-avatar-tab":g,onClick:()=>N(g),className:O("rounded-lg px-[11px] py-[5px] text-[13px]",j===g?"bg-ink/[0.08] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(T)},g)),e.jsx("button",{type:"button","data-avatar-reset":!0,disabled:c,onClick:()=>a(hn),className:"ml-auto rounded-lg px-[11px] py-[5px] text-[13px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("botPanel.avatar.reset")})]}),e.jsxs("div",{className:"p-3",children:[j==="bot"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Za.map(g=>H(g,_e(g)))}),e.jsx("div",{className:"flex flex-wrap justify-center gap-2 px-1 pb-1 pt-3.5",children:gn.map(g=>e.jsx("button",{type:"button",disabled:c,"aria-pressed":t.color===g,"aria-label":s("mascot.useColor",{color:Ja(g)}),title:s(Ya[g]),onClick:()=>b({color:g}),className:O("size-6 rounded-full disabled:opacity-50",t.color===g&&"ring-2 ring-ink/80 ring-offset-2 ring-offset-menu"),style:{background:Ga(g)}},g))}),e.jsx(ui,{bot:t,disabled:c,onPatch:b}),e.jsxs("button",{type:"button","data-avatar-more":!0,"aria-expanded":D,onClick:()=>$(g=>!g),className:"mx-auto mt-2.5 flex items-center gap-1 rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[s("botPanel.avatar.more"),e.jsx(fe,{size:13,"aria-hidden":"true",className:O("transition-transform",D&&"rotate-180")})]}),D&&e.jsxs("div",{"data-avatar-more-looks":!0,children:[Qa.map(g=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-1 pb-1.5 pt-2 text-[12px] text-ink-tertiary",children:[e.jsx("span",{children:Pt(g)}),g===P&&A&&e.jsx("span",{"data-avatar-costume":!0,children:s("botPanel.avatar.costume",{name:A,skin:Pt(g)})})]}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5","data-festival-bodies":g,children:Xa[g].bodies.map(T=>H(T,_e(T)))})]},g)),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-1.5 pt-2.5",role:"group","aria-label":s("botPanel.avatar.face"),children:[e.jsx("span",{className:"mr-0.5 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.face")}),ei.map(g=>e.jsx("button",{type:"button",disabled:c,"data-avatar-face":g,"aria-pressed":n===g,onClick:()=>b({mascotExpression:g}),className:O("rounded-full px-2.5 py-1 text-[12px] disabled:opacity-50",n===g?"bg-ink/[0.15] text-ink":"bg-ink/[0.04] text-ink-secondary hover:text-ink"),children:dr(g)},g))]})]})]}),j==="generate"&&e.jsx("div",{className:"[&>div:first-child]:mt-0 [&>div:first-child]:border-0 [&>div:first-child]:pt-0",children:e.jsx(fn,{botLabel:t.title||t.name,disabled:m,generating:r,onGenerate:f})}),j==="upload"&&e.jsxs(e.Fragment,{children:[e.jsx(yn,{busy:c,onUpload:g=>{x(g)}}),v&&e.jsx(bn,{bot:t,disabled:c,onPatch:a}),e.jsx("input",{ref:l,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",onChange:g=>{x(g.target.files?.[0])}}),e.jsxs("button",{type:"button","data-avatar-drop":!0,disabled:c,onClick:()=>l.current?.click(),onDragOver:g=>g.preventDefault(),onDrop:g=>{g.preventDefault(),x(g.dataTransfer.files?.[0])},className:"flex w-full flex-col items-center gap-1.5 rounded-xl border-[1.5px] border-dashed border-ink/15 px-3 py-6 text-center text-[13px] text-ink-secondary hover:border-ink/25 hover:text-ink disabled:opacity-50",children:[m?e.jsx(Ee,{size:22,className:"animate-spin"}):e.jsx(vn,{size:22}),e.jsx("span",{children:s("botPanel.avatar.drop")}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:s("botPanel.avatar.types")})]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-2.5",children:[e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:s("botPanel.avatar.shape")}),e.jsx(Oe,{attr:"data-avatar-crop",label:s("botPanel.avatar.shape"),value:v?d:null,onChange:g=>a({avatarCrop:g}),options:or.map(g=>({value:g,label:s(lr[g]),disabled:c||!t.avatarUrl}))}),t.avatarUrl&&e.jsx("button",{type:"button",onClick:k,disabled:c,"aria-label":s("botIdentity.removeAvatar"),title:s("botPanel.avatar.remove"),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(is,{size:14})})]}),!v&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.uploadHint")})]}),p&&e.jsx("div",{role:"alert",className:"mt-3 text-[12px] text-danger",children:p})]})]})}const mr=()=>s("place.off");function As(t){const{dispatch:n}=B();return(a="computer")=>{wn(t.id,a),n({type:"toggleSettings",open:!1}),n({type:"toggleComputer",open:!0})}}function ur(t,n){const[a,o]=u.useState(null);return u.useEffect(()=>{if(!n)return;let i=!1;return Z(`/api/browser-sites?bot=${encodeURIComponent(t.id)}`).then(l=>{i||o({botId:t.id,count:l.sites?.length??0})}).catch(()=>{}),()=>{i=!0}},[t.id,n]),a?.botId===t.id?a.count:null}function Ms(t){const{state:n}=B(),{capabilities:a}=we(),o=a.host?.platform??"other",i=Nn(t),l=t.computer??"auto",d=n.config?.browserEngine?.myChrome===!0&&(n.config?.browserProfiles??[]).some(f=>f.id===t.browserProfile&&f.browser==="chrome"),m=f=>f==="browser"&&d?s("settings.profiles.myChrome"):Pn(f,o),r=f=>{const{view:v,reachable:j}=i[f];return{value:f,label:m(f),disabled:!j,hint:!j||Cn(v)?v.line:void 0}},c=[{value:"auto",label:s("computer.simple.dest.letItChoose")},...i.local.policy?[r("local")]:[],...i.browser.policy||l==="browser"?[r("browser")]:[],...i.cloud.policy?[r("cloud")]:[],...i.vm.policy||l==="vm"?[r("vm")]:[],...l==="off"?[{value:l,label:mr(),disabled:!0}]:[]],p=t.tasks?.find(f=>f.threadId===t.threadId)?.surface,x=p&&p!==l?m(p):null,k=c.find(f=>f.value===l)?.label??(l==="auto"||l==="off"?void 0:m(l));return{options:c,current:l,currentLabel:k,usingNow:x}}function xr({bot:t,derived:n}){const{dispatch:a}=B(),{options:o,current:i,usingNow:l}=Ms(t),[d,m]=u.useState(null),{patch:r,approvalMode:c}=n,p=x=>{if(!(x===i||x==="off")){if(x==="local"&&c==="auto"){m({botId:t.id,patch:{computer:"local",acknowledgeLocalAuto:!0}});return}r(x==="browser"?{computer:"browser",browser:!0}:{computer:x==="auto"?null:x})}};return e.jsxs(e.Fragment,{children:[e.jsx(M,{children:e.jsx("div",{role:"radiogroup","aria-label":s("computer.simple.whereWorks",{name:t.name}),className:"flex flex-col divide-y divide-ink/[0.05]",children:o.map(x=>e.jsx(Ge,{"data-panel-choice":x.value,title:x.label,hint:x.hint,checked:i===x.value,disabled:x.disabled,onClick:()=>p(x.value)},x.value))})}),l&&e.jsx("p",{"data-panel-using-now":!0,className:"mx-1 text-[13px] text-ink-secondary",children:s("computer.simple.usingNow",{place:l})}),e.jsx(Sn,{open:d!==null,onCancel:()=>m(null),onConfirm:()=>{const x=d;m(null),x&&a({type:"updateBot",botId:x.botId,patch:x.patch})}})]})}function hr({bot:t,derived:n,onOpen:a}){const o=As(t),i=Le(),{browserEnabled:l}=n,d=ur(t,l&&t.computer!=="off"&&i!==!1),{currentLabel:m,usingNow:r}=Ms(t),c=s("computer.screenOf",{name:t.name}),p=[...t.messages].reverse().find(k=>k.kind==="screen"&&(k.hasImage||k.png)),x=p?kn({threadId:t.threadId,messageId:p.id},p.mime).src:null;return e.jsxs("div",{"data-panel-tabpanel":"computer",children:[e.jsxs("button",{type:"button","data-panel-action":"open-computer","aria-label":`${s("place.action.watch")}: ${c}`,onClick:()=>o(),className:"group relative mt-2.5 flex aspect-[16/10] w-full flex-col items-center justify-center gap-2 overflow-hidden rounded-xl bg-composer ring-1 ring-inset ring-ink/[0.06] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[x?e.jsx("img",{src:x,alt:"",className:"absolute inset-0 size-full object-cover"}):t.busy?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-55",children:e.jsx(Xe,{bot:t,size:52,animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] text-ink-secondary",children:s("botPanel.screen.working")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-60",children:e.jsx(Xe,{bot:t,size:44,state:"sleeping",animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] font-medium text-ink",children:s("botPanel.screen.resting")})]}),e.jsxs("span",{"aria-hidden":"true",className:"absolute bottom-2.5 right-2.5 flex h-7 items-center gap-1.5 rounded-full border border-ink/10 bg-panel/80 px-2.5 text-[12px] text-ink opacity-0 backdrop-blur-sm transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 touch:opacity-100",children:[e.jsx(It,{size:13,"aria-hidden":"true"}),s("place.action.watch")]})]}),e.jsx("div",{className:"mt-3 text-center text-[13px] text-ink-tertiary",children:c}),e.jsxs(M,{anchor:"where",children:[e.jsx(Q,{"data-panel-page":"where",icon:It,title:s("computer.simple.whereWorks",{name:t.name}),hint:r?s("computer.simple.usingNow",{place:r}):void 0,value:m,onClick:()=>a("where")}),e.jsx(Q,{"data-panel-page":"browser",icon:jn,title:s("settings.sites.title"),value:d??void 0,onClick:()=>a("browser")})]})]})}const gr=3,Kt="[&_.font-semibold]:font-medium [&_time]:text-[12px] [&_time]:text-ink-tertiary [&_span.bg-accent]:size-2",fr=8,yr=200,he=new Map,We=new Set,Ut=t=>`${t.threadId}@${cs(t)}`;function br(t,n){const[,a]=u.useState(0),i=n.filter(m=>m.threadId!==t.threadId).map(Ut).filter(m=>!he.has(m)&&!We.has(m)).join(",");u.useEffect(()=>{if(i)for(const m of i.split(",")){We.add(m);const r=m.slice(0,m.lastIndexOf("@"));Z(`/api/threads/${encodeURIComponent(r)}/messages?limit=${fr}`,{background:!0}).then(c=>{he.set(m,Je({messages:c.messages??[],activeLeafId:c.activeLeafId??void 0})),he.size>yr&&he.delete(he.keys().next().value),a(p=>p+1)}).catch(()=>{}).finally(()=>We.delete(m))}},[i]);const l=Je(t),d=new Map(n.map(m=>[m.threadId,Ut(m)]));return m=>m===t.threadId?l:he.get(d.get(m)??"")}function vr({bot:t}){const{state:n,dispatch:a}=B(),o=On(),i=!rs(os,!0),[l,d]=u.useState(""),[m,r]=u.useState(!1),[c,p]=u.useState(!1),[x,k]=u.useState(!1),f=En(n.config),v=u.useMemo(()=>{const{onRename:y,onRegenerateTitle:z,onDelete:ce,onMove:xe,onPin:ye,onArchive:E}=Rn(t.id,a,f);return{onRename:y,onRegenerateTitle:z,onDelete:ce,onMove:xe,onPin:ye,onArchive:E}},[t.id,a,f]),j=Tn(t),N=t.tasks??[{threadId:t.threadId,title:s("task.newShort"),createdAt:0}],w=(j?In({...t,tasks:N},j):N).filter(y=>!y.routineRunId).map(y=>{const z=Ye(t,y.threadId);return{...y,busy:z.busy,activity:z.activity,waitingForTeammates:z.waitingForTeammates,turnStartedAt:z.turnStartedAt??void 0,queued:!!n.pendingQueued[y.threadId]?.length}}),b=yt(w.filter(y=>!ze(y)||y.threadId===t.threadId)),h=yt(w.filter(y=>ze(y)&&y.threadId!==t.threadId)),P=l.trim(),L=b.filter((y,z)=>z<gr||y.threadId===t.threadId),D=br(t,[...P||c?b:L,...x?h:[]]),$=y=>{const z=D(y);return z?Ln(Ye(t,y),z,n.instances,!1):void 0},A=An(b,P),H=P?[...A,...b.filter(y=>!A.includes(y)&&$(y.threadId)?.toLowerCase().includes(P.toLowerCase()))]:b,I=P?H:c?b:L,g=b.length-L.length,T=t.projects?.find(y=>y.id===t.tasks?.find(z=>z.threadId===t.threadId)?.projectId),F=()=>{i&&a({type:"toggleSettings",open:!1})},_=y=>{y.threadId!==t.threadId&&Fn(a,t,y.threadId,!1),F()},K=()=>{a({type:"newTask",botId:t.id,...T?{projectId:T.id}:{}}),F()},J=()=>{d(""),r(!1)},Y=b.length>=2||m||b.some(y=>y.threadId===t.threadId&&ze(y)),U=y=>e.jsx("div",{role:"listitem","data-conversation":y.threadId,children:e.jsx(Bn,{panel:!0,preview:$(y.threadId),task:y,ownerId:t.id,current:y.threadId===t.threadId,folders:t.projects,now:$n(cs(y),o),locale:ee(),onSelect:_,...v})},y.threadId);return e.jsxs("section",{"data-panel-card":"conversations","aria-label":s("botPanel.conversations.title"),children:[e.jsx(Re,{action:Y&&e.jsx("button",{type:"button","data-conversations-search":!0,"aria-label":s("botPanel.conversations.search"),title:s("botPanel.conversations.search"),"aria-pressed":m,onClick:()=>m?J():r(!0),className:O("-me-1 flex size-6 shrink-0 items-center justify-center rounded-[6px] text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink",m&&"bg-ink/[0.06] text-ink"),children:e.jsx(tt,{size:14,"aria-hidden":"true"})}),children:s("botPanel.conversations.title")}),e.jsx("div",{className:O("flex items-center gap-2",Y&&"mb-2"),children:t.yourAccess!=="view"&&j!=="team"&&e.jsxs("button",{type:"button","data-conversations-new":!0,"aria-label":s("botPanel.conversations.new"),onClick:K,className:O(ls,"flex-1"),children:[e.jsx(Mn,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.conversations.new")})]})}),Y&&m&&e.jsx("input",{autoFocus:!0,type:"search","data-conversations-query":!0,value:l,onChange:y=>d(y.target.value),onKeyDown:y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),J())},placeholder:s("botPanel.conversations.searchPlaceholder",{name:t.name}),"aria-label":s("botPanel.conversations.searchPlaceholder",{name:t.name}),className:"mb-1.5 w-full rounded-[8px] border border-hairline/60 bg-inset px-3 py-1.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-focus"}),Y&&e.jsx("div",{role:"list","aria-label":s("botPanel.conversations.title"),className:O("flex flex-col gap-px",Kt),children:I.map(U)}),Y&&P&&I.length===0&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:s("task.noMatch",{query:P})}),Y&&!P&&g>0&&e.jsxs("button",{type:"button","data-conversations-more":!0,"aria-expanded":c,onClick:()=>p(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[c?e.jsx(bt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),c?s("botPanel.conversations.showFewer"):s("botPanel.conversations.showMore",{count:g})]}),!P&&h.length>0&&e.jsxs("button",{type:"button","data-conversations-archived":!0,"aria-expanded":x,onClick:()=>k(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[x?e.jsx(bt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),s("task.archivedList",{count:h.length})]}),!P&&x&&h.length>0&&e.jsx("div",{role:"list","aria-label":s("task.archivedList",{count:h.length}),className:O("flex flex-col gap-px",Kt),children:h.map(U)})]})}function kr({bot:t}){const{dispatch:n}=B(),a=Qt();return t.defaultBot?a?e.jsx(vt,{placement:"panel-card"}):e.jsxs(M,{label:s("botPanel.tryAsking"),anchor:"try-asking",children:[Dn.map(o=>e.jsx("button",{type:"button","data-panel-ask":o,onClick:()=>n({type:"send",botId:t.id,text:s(o),threadId:t.threadId}),className:"flex h-9 w-full items-center px-3.5 text-left text-[14px] text-ink transition-colors hover:bg-ink/[0.03]",children:e.jsx("span",{className:"truncate",children:s(o)})},o)),e.jsx(vt,{placement:"panel"})]}):null}const jr=["find","start-fresh","usage","activity","inspector"];function wr({item:t}){const n=t.key==="usage";return e.jsxs("button",{type:"button","data-panel-item":t.key,disabled:t.disabled,title:t.title,"aria-pressed":t.active||void 0,onClick:t.onSelect,className:O(X,"w-full rounded-[8px] text-left enabled:hover:bg-ink/[0.04] disabled:cursor-default disabled:opacity-45"),children:[e.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-ink-secondary [&_svg]:size-4","aria-hidden":"true",children:t.icon}),e.jsx("span",{className:O("min-w-0 truncate text-[14px] font-medium",!n&&"flex-1",t.active?"text-accent-text":"text-ink"),children:t.label}),t.trailing&&e.jsx("span",{className:O("flex items-center",n?"min-w-0 flex-1 justify-end text-right":"shrink-0"),children:t.trailing}),t.key!=="find"&&t.key!=="start-fresh"&&e.jsx(je,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary rtl:-scale-x-100"})]})}function Nr({bot:t,derived:n,onOpen:a}){const{items:o}=zn(t),{dispatch:i}=B(),l=n.botRoutines.filter(m=>m.enabled).length,d=jr.flatMap(m=>o.filter(r=>r.key===m));return e.jsxs("div",{"data-panel-tabpanel":"details",children:[e.jsx("section",{"data-panel-card":"model",className:"pt-2",children:e.jsx("div",{"data-panel-row":"model",className:O(X,"rounded-[8px]"),children:e.jsx(Hn,{bot:t,contained:!0,threadId:t.threadId,label:e.jsxs("span",{className:"flex shrink-0 items-center gap-2.5",children:[e.jsx(te,{icon:nt}),e.jsx(ae,{title:s("model.simple.model")})]})})})}),e.jsx(vr,{bot:t}),e.jsx(kr,{bot:t}),d.length>0&&e.jsxs("section",{"data-panel-card":"conversation",children:[e.jsx(Re,{children:s("botPanel.section.conversation")}),d.map(m=>e.jsx(wr,{item:m},m.key))]}),n.botRoutines.length===0?e.jsxs("section",{"data-panel-empty":"routines",children:[e.jsx(Re,{action:e.jsx(_n,{"data-panel-automations":"",onClick:()=>i({type:"showRoutines",view:"list"}),children:s("sidebar.nav.automations")}),children:s("botSettings.simple.routines")}),e.jsxs("button",{type:"button","data-panel-page":"routines",title:s("botPanel.routines.emptyHint"),onClick:()=>a("routines"),className:O(ls,"w-full"),children:[e.jsx($i,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.routines.add")})]})]}):e.jsx(M,{label:s("botSettings.simple.routines"),anchor:"routines",children:e.jsx(Q,{"data-panel-page":"routines",icon:Kn,title:s("botSettings.simple.routines"),value:l>0?s("botPanel.routinesOn",{count:l}):s("botPanel.none"),onClick:()=>a("routines")})})]})}const Ls=/^\s*[-*]\s+(.+?)\s*$/;function Sr(t){return t.split(`
8
- `).flatMap((n,a)=>{const o=Ls.exec(n)?.[1];return o?[{line:a,text:o}]:[]})}function Cr(t,n){const a=t.split(`
7
+ `}function ar({enabled:t,status:n,tidying:a,onToggle:o,onTidy:i,rooms:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.upkeep.title")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.upkeep.help")})]}),e.jsx(be,{checked:t,"aria-label":s("memory.upkeep.title"),onClick:o})]}),t&&l&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3 border-t border-hairline/40 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:s("memory.learnFromRooms.title")}),e.jsx("p",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.subtitle")}),n&&!n.modelSteps&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.noModelSteps")}),l.error&&e.jsx("p",{role:"alert",className:"mt-1 text-[13px] text-danger",children:l.error})]}),e.jsx(be,{checked:l.enabled,"aria-label":s("memory.learnFromRooms.title"),disabled:l.saving,onClick:l.onToggle,className:"disabled:cursor-wait disabled:opacity-50"})]}),t&&n&&!n.modelSteps&&e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.upkeep.noModelSteps")}),t&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",className:oe,disabled:a,onClick:i,children:a?s("memory.upkeep.tidying"):s("memory.upkeep.tidyNow")}),e.jsxs("span",{className:"text-[13px] text-ink-secondary",children:[n?.lastTidy?s("memory.upkeep.lastTidy",{time:Te(n.lastTidy.at,ee()),summary:Rs(n.lastTidy).toLowerCase()}):s("memory.upkeep.notTidied"),n?.lastCapture&&Ke(n.lastCapture)?` ${s(Ke(n.lastCapture)===1?"memory.upkeep.lastNoticed.one":"memory.upkeep.lastNoticed.many",{count:Ke(n.lastCapture),time:Te(n.lastCapture.at,ee())})}`:""]})]})]})}function ir({index:t}){const n=ci(t),a=n.level==="over"?"bg-danger":n.level==="near"?"bg-warning":"bg-accent";return e.jsxs("div",{className:O("rounded-xl p-4",n.level==="over"?"border border-danger/30 bg-danger/10":"bg-card"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[13px]",children:[e.jsx("span",{className:"font-medium text-ink",children:s("memory.capacity.title")}),e.jsx("span",{className:O("text-[12px]",n.level==="over"?"text-danger":"text-ink-secondary"),children:s("memory.capacity.summary",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes)})})]}),e.jsx(zt,{label:s("memory.capacity.lines"),share:n.lineShare,fill:a}),e.jsx(zt,{label:s("memory.capacity.size"),share:n.byteShare,fill:a}),e.jsx("p",{className:O("mt-2 text-[13px] leading-relaxed",n.level==="over"?"text-danger":"text-ink-secondary"),children:n.warning??s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes),maxLoaded:t.maxLines})}),n.warning&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:pe(t.bytes),maxBytes:pe(t.maxBytes),maxLoaded:t.maxLines})})]})}function zt({label:t,share:n,fill:a}){const o=`${Math.min(100,Math.round(n*100))}%`;return e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"w-10 shrink-0",children:t}),e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-inset",role:"meter","aria-label":s("memory.capacity.used",{label:t}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,Math.round(n*100)),children:e.jsx("div",{className:O("h-full rounded-full",a),style:{width:o}})})]})}function Is({botName:t,busy:n,onReload:a,onOverwrite:o}){return e.jsxs("div",{className:"mt-2 rounded-lg border border-warning/25 bg-warning/10 p-3 text-[13px] leading-relaxed text-ink",children:[e.jsx("div",{className:"font-medium",children:s("memory.conflict.title",{name:t})}),e.jsx("div",{className:"mt-0.5 text-ink-secondary",children:s("memory.conflict.help",{name:t})}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",className:oe,disabled:n,onClick:a,children:s("memory.reload")}),e.jsx("button",{type:"button",className:oe,disabled:n,onClick:o,children:s("memory.overwrite")})]})]})}function Ht({title:t,hint:n,files:a,selected:o,onOpen:i,onDelete:l}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] text-ink-secondary",children:n}),a.length===0?e.jsx("div",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.noneYet")}):e.jsx("div",{className:"mt-2 overflow-hidden rounded-lg border border-hairline/40",children:a.map(d=>e.jsxs("div",{className:O("flex items-center gap-2 border-b border-hairline/40 px-3 py-2 last:border-b-0",o===d.path?"bg-control/60":"hover:bg-control/40"),children:[e.jsxs("button",{type:"button",onClick:()=>i(d),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Me,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:d.name}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:[pe(d.bytes)," · ",Te(d.modifiedAt,ee())]})]}),e.jsx("button",{type:"button",onClick:()=>l(d),"aria-label":s("memory.deleteFile",{name:d.name}),title:s("memory.delete"),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:bg-control hover:text-danger",children:e.jsx(is,{size:14})})]},d.path))})]})}function lt({rows:t,botName:n,reverting:a,onRevert:o,now:i=Date.now()}){return t?t.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.noChanges")}):e.jsx("div",{className:"flex flex-col gap-2",children:t.map(l=>{const d=pi(l),m=mi(l);return e.jsxs("div",{className:"rounded-lg bg-inset px-3 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{children:tr(l,n)})," · ",e.jsx("span",{className:"text-ink-secondary",children:Te(l.at,ee(),i)}),d&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-ink-secondary",children:m?s(m,l.threadTitle?{title:l.threadTitle}:void 0):d})]})]}),l.canRevert?e.jsxs("button",{type:"button",disabled:a!==null,onClick:()=>o(l),className:"inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:[e.jsx(ln,{size:12}),a===l.id?s("memory.undoing"):s("memory.undo")]}):e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",title:l.revertUnavailableReason,children:s("memory.cantUndo")})]}),l.diff&&e.jsxs("details",{className:"mt-1",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:["+",l.added," −",l.removed," · ",s("memory.showChanged")]}),e.jsx("pre",{className:"mt-1 max-h-[240px] overflow-auto whitespace-pre-wrap rounded-md bg-card p-2 font-mono text-[12px] leading-relaxed text-ink",children:l.diff})]})]},l.id)})}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.loading")})}function rr({bot:t,rows:n,refreshError:a,onRollback:o,rollingBack:i}){if(!n)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.loading")});if(n.length===0)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.empty")});const l=[...n].sort((d,m)=>m.at-d.at);return e.jsxs("div",{className:"flex flex-col gap-2",children:[a&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("history.refreshError")}),l.map(d=>e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{className:"text-ink-secondary",children:ss(d.at)})," · ",e.jsxs("span",{children:[d.actor," via ",d.via]})," · ",e.jsx("span",{children:d.summary})]}),d.field==="soul"&&d.canRestore===!0&&e.jsx("button",{type:"button",disabled:i,onClick:()=>o(d.id),className:"shrink-0 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:s("history.undo")})]}),d.field==="soul"&&d.canRestore!==!0&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:d.restoreUnavailableReason??s("history.restoreUnavailable")})]},`${t.id}-${d.id}`))]})}function or({bot:t,bare:n=!1}){const{state:a,dispatch:o}=B(),i=cn(t),l=a.instances.find(d=>d.instanceId===t.modelSelection.instanceId);return i.turns===0?e.jsx("div",{className:O(n?"":"rounded-xl bg-card p-4","text-[13px] text-ink-secondary"),children:s("usage.bot.empty")}):e.jsxs("div",{className:n?void 0:"rounded-xl bg-card p-4",children:[!n&&e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("usage.title")}),e.jsxs("button",{onClick:()=>o({type:"toggleAppSettings",open:!0,section:"usage"}),className:"text-[12px] text-ink-secondary hover:text-ink",children:[s("usage.allBots")," ",e.jsx(je,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),e.jsxs("div",{className:O("grid grid-cols-3 gap-3 text-[13px]",!n&&"mt-3"),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colTurns")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:i.turns})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:dn(i)}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",title:un(i),children:pn(mn(i))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colCost")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:gt(i.costUsd)?xn(i.costUsd):"—"})]})]}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:gt(i.costUsd)?s("usage.costLine",{caption:hn(l?.snapshot.billing)}):s("usage.bot.unpriced")})]})}const lr=[["bot","botPanel.avatar.tabBot"],["generate","botPanel.avatar.tabGenerate"],["upload","botPanel.avatar.tabUpload"]],cr=["circle","rounded","square"],dr={circle:"botPanel.avatar.circle",rounded:"botPanel.avatar.rounded",square:"botPanel.avatar.square"},pr={idle:"botPanel.face.idle",happy:"botPanel.face.happy",curious:"botPanel.face.curious",drowsy:"botPanel.face.drowsy",working:"botPanel.face.working",thinking:"botPanel.face.thinking",listening:"botPanel.face.listening",sleeping:"botPanel.face.sleeping",suspicious:"botPanel.face.suspicious",proud:"botPanel.face.proud"},mr=t=>{const n=pr[t];return n?s(n):t};function ur({bot:t,activeState:n,onPatch:a,onClose:o}){const i=gn(t,a),{fileRef:l,crop:d,uploading:m,generating:r,busy:c,error:p,upload:u,removeImage:k,generate:f}=i,v=d!=="mascot"&&!!t.avatarUrl,[j,N]=x.useState(v?"upload":"bot"),w=x.useRef(null);x.useEffect(()=>{w.current?.querySelector('[aria-selected="true"]')?.focus()},[]);const b=g=>a(d==="mascot"?g:{...g,avatarCrop:"mascot"}),h=t.mascotBody??"cursor",P=Za(),L=Ga(t.mascotBody,t.color,P),[D,$]=x.useState(()=>!!P||St(h)||!!(t.mascotExpression&&t.mascotExpression!=="idle")),A=P&&L!==h&&St(L)?_e(L):null,H=(g,T)=>e.jsx("button",{type:"button",disabled:c,"aria-pressed":!v&&h===g,"aria-label":s("mascot.useBody",{name:T}),title:T,onClick:()=>b({mascotBody:g}),className:O("flex h-[58px] items-center justify-center rounded-xl disabled:opacity-50",!v&&h===g?"bg-ink/[0.08] ring-[1.5px] ring-inset ring-ink/25":"hover:bg-ink/[0.05]"),children:e.jsx(ni,{color:t.color,faceColor:t.mascotFaceColor,bodyId:g,size:40,animated:!1,trackPointer:!1})},g),I=g=>{g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),o())};return e.jsxs("div",{role:"dialog","aria-label":s("botPanel.avatar.edit"),"data-panel-avatar-editor":!0,"data-look":"popover",onKeyDown:I,className:"popover-surface absolute inset-x-[-5px] top-[80px] z-30 overflow-hidden rounded-2xl border border-ink/[0.08] bg-menu text-left shadow-2xl shadow-black/50",children:[e.jsxs("div",{ref:w,className:"flex items-center gap-0.5 border-b border-ink/[0.06] p-2",children:[lr.map(([g,T])=>e.jsx("button",{type:"button",role:"tab","aria-selected":j===g,"data-avatar-tab":g,onClick:()=>N(g),className:O("rounded-lg px-[11px] py-[5px] text-[13px]",j===g?"bg-ink/[0.08] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(T)},g)),e.jsx("button",{type:"button","data-avatar-reset":!0,disabled:c,onClick:()=>a(fn),className:"ml-auto rounded-lg px-[11px] py-[5px] text-[13px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("botPanel.avatar.reset")})]}),e.jsxs("div",{className:"p-3",children:[j==="bot"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Ya.map(g=>H(g,_e(g)))}),e.jsx("div",{className:"flex flex-wrap justify-center gap-2 px-1 pb-1 pt-3.5",children:yn.map(g=>e.jsx("button",{type:"button",disabled:c,"aria-pressed":t.color===g,"aria-label":s("mascot.useColor",{color:Xa(g)}),title:s(Qa[g]),onClick:()=>b({color:g}),className:O("size-6 rounded-full disabled:opacity-50",t.color===g&&"ring-2 ring-ink/80 ring-offset-2 ring-offset-menu"),style:{background:Ja(g)}},g))}),e.jsx(hi,{bot:t,disabled:c,onPatch:b}),e.jsxs("button",{type:"button","data-avatar-more":!0,"aria-expanded":D,onClick:()=>$(g=>!g),className:"mx-auto mt-2.5 flex items-center gap-1 rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[s("botPanel.avatar.more"),e.jsx(fe,{size:13,"aria-hidden":"true",className:O("transition-transform",D&&"rotate-180")})]}),D&&e.jsxs("div",{"data-avatar-more-looks":!0,children:[ei.map(g=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-1 pb-1.5 pt-2 text-[12px] text-ink-tertiary",children:[e.jsx("span",{children:Ct(g)}),g===P&&A&&e.jsx("span",{"data-avatar-costume":!0,children:s("botPanel.avatar.costume",{name:A,skin:Ct(g)})})]}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5","data-festival-bodies":g,children:ti[g].bodies.map(T=>H(T,_e(T)))})]},g)),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-1.5 pt-2.5",role:"group","aria-label":s("botPanel.avatar.face"),children:[e.jsx("span",{className:"mr-0.5 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.face")}),si.map(g=>e.jsx("button",{type:"button",disabled:c,"data-avatar-face":g,"aria-pressed":n===g,onClick:()=>b({mascotExpression:g}),className:O("rounded-full px-2.5 py-1 text-[12px] disabled:opacity-50",n===g?"bg-ink/[0.15] text-ink":"bg-ink/[0.04] text-ink-secondary hover:text-ink"),children:mr(g)},g))]})]})]}),j==="generate"&&e.jsx("div",{className:"[&>div:first-child]:mt-0 [&>div:first-child]:border-0 [&>div:first-child]:pt-0",children:e.jsx(bn,{botLabel:t.title||t.name,disabled:m,generating:r,onGenerate:f})}),j==="upload"&&e.jsxs(e.Fragment,{children:[e.jsx(vn,{busy:c,onUpload:g=>{u(g)}}),v&&e.jsx(kn,{bot:t,disabled:c,onPatch:a}),e.jsx("input",{ref:l,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",onChange:g=>{u(g.target.files?.[0])}}),e.jsxs("button",{type:"button","data-avatar-drop":!0,disabled:c,onClick:()=>l.current?.click(),onDragOver:g=>g.preventDefault(),onDrop:g=>{g.preventDefault(),u(g.dataTransfer.files?.[0])},className:"flex w-full flex-col items-center gap-1.5 rounded-xl border-[1.5px] border-dashed border-ink/15 px-3 py-6 text-center text-[13px] text-ink-secondary hover:border-ink/25 hover:text-ink disabled:opacity-50",children:[m?e.jsx(Ee,{size:22,className:"animate-spin"}):e.jsx(jn,{size:22}),e.jsx("span",{children:s("botPanel.avatar.drop")}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:s("botPanel.avatar.types")})]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-2.5",children:[e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:s("botPanel.avatar.shape")}),e.jsx(Oe,{attr:"data-avatar-crop",label:s("botPanel.avatar.shape"),value:v?d:null,onChange:g=>a({avatarCrop:g}),options:cr.map(g=>({value:g,label:s(dr[g]),disabled:c||!t.avatarUrl}))}),t.avatarUrl&&e.jsx("button",{type:"button",onClick:k,disabled:c,"aria-label":s("botIdentity.removeAvatar"),title:s("botPanel.avatar.remove"),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(is,{size:14})})]}),!v&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.uploadHint")})]}),p&&e.jsx("div",{role:"alert",className:"mt-3 text-[12px] text-danger",children:p})]})]})}const xr=()=>s("place.off");function As(t){const{dispatch:n}=B();return(a="computer")=>{Sn(t.id,a),n({type:"toggleSettings",open:!1}),n({type:"toggleComputer",open:!0})}}function hr(t,n){const[a,o]=x.useState(null);return x.useEffect(()=>{if(!n)return;let i=!1;return Z(`/api/browser-sites?bot=${encodeURIComponent(t.id)}`).then(l=>{i||o({botId:t.id,count:l.sites?.length??0})}).catch(()=>{}),()=>{i=!0}},[t.id,n]),a?.botId===t.id?a.count:null}function Ms(t){const{state:n}=B(),{capabilities:a}=we(),o=a.host?.platform??"other",i=Cn(t),l=t.computer??"auto",d=n.config?.browserEngine?.myChrome===!0&&(n.config?.browserProfiles??[]).some(f=>f.id===t.browserProfile&&f.browser==="chrome"),m=f=>f==="browser"&&d?s("settings.profiles.myChrome"):En(f,o),r=f=>{const{view:v,reachable:j}=i[f];return{value:f,label:m(f),disabled:!j,hint:!j||On(v)?v.line:void 0}},c=[{value:"auto",label:s("computer.simple.dest.letItChoose")},...i.local.policy?[r("local")]:[],...i.browser.policy||l==="browser"?[r("browser")]:[],...i.cloud.policy?[r("cloud")]:[],...i.vm.policy||l==="vm"?[r("vm")]:[],...l==="off"?[{value:l,label:xr(),disabled:!0}]:[]],p=t.tasks?.find(f=>f.threadId===t.threadId)?.surface,u=p&&p!==l?m(p):null,k=c.find(f=>f.value===l)?.label??(l==="auto"||l==="off"?void 0:m(l));return{options:c,current:l,currentLabel:k,usingNow:u}}function gr({bot:t,derived:n}){const{dispatch:a}=B(),{options:o,current:i,usingNow:l}=Ms(t),[d,m]=x.useState(null),{patch:r,approvalMode:c}=n,p=u=>{if(!(u===i||u==="off")){if(u==="local"&&c==="auto"){m({botId:t.id,patch:{computer:"local",acknowledgeLocalAuto:!0}});return}r(u==="browser"?{computer:"browser",browser:!0}:{computer:u==="auto"?null:u})}};return e.jsxs(e.Fragment,{children:[e.jsx(M,{children:e.jsx("div",{role:"radiogroup","aria-label":s("computer.simple.whereWorks",{name:t.name}),className:"flex flex-col divide-y divide-ink/[0.05]",children:o.map(u=>e.jsx(Ge,{"data-panel-choice":u.value,title:u.label,hint:u.hint,checked:i===u.value,disabled:u.disabled,onClick:()=>p(u.value)},u.value))})}),l&&e.jsx("p",{"data-panel-using-now":!0,className:"mx-1 text-[13px] text-ink-secondary",children:s("computer.simple.usingNow",{place:l})}),e.jsx(Pn,{open:d!==null,onCancel:()=>m(null),onConfirm:()=>{const u=d;m(null),u&&a({type:"updateBot",botId:u.botId,patch:u.patch})}})]})}function fr({bot:t,derived:n,onOpen:a}){const o=As(t),i=Le(),{browserEnabled:l}=n,d=hr(t,l&&t.computer!=="off"&&i!==!1),{currentLabel:m,usingNow:r}=Ms(t),c=s("computer.screenOf",{name:t.name}),p=[...t.messages].reverse().find(k=>k.kind==="screen"&&(k.hasImage||k.png)),u=p?wn({threadId:t.threadId,messageId:p.id},p.mime).src:null;return e.jsxs("div",{"data-panel-tabpanel":"computer",children:[e.jsxs("button",{type:"button","data-panel-action":"open-computer","aria-label":`${s("place.action.watch")}: ${c}`,onClick:()=>o(),className:"group relative mt-2.5 flex aspect-[16/10] w-full flex-col items-center justify-center gap-2 overflow-hidden rounded-xl bg-composer ring-1 ring-inset ring-ink/[0.06] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[u?e.jsx("img",{src:u,alt:"",className:"absolute inset-0 size-full object-cover"}):t.busy?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-55",children:e.jsx(Xe,{bot:t,size:52,animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] text-ink-secondary",children:s("botPanel.screen.working")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-60",children:e.jsx(Xe,{bot:t,size:44,state:"sleeping",animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] font-medium text-ink",children:s("botPanel.screen.resting")})]}),e.jsxs("span",{"aria-hidden":"true",className:"absolute bottom-2.5 right-2.5 flex h-7 items-center gap-1.5 rounded-full border border-ink/10 bg-panel/80 px-2.5 text-[12px] text-ink opacity-0 backdrop-blur-sm transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 touch:opacity-100",children:[e.jsx(Tt,{size:13,"aria-hidden":"true"}),s("place.action.watch")]})]}),e.jsx("div",{className:"mt-3 text-center text-[13px] text-ink-tertiary",children:c}),e.jsxs(M,{anchor:"where",children:[e.jsx(Q,{"data-panel-page":"where",icon:Tt,title:s("computer.simple.whereWorks",{name:t.name}),hint:r?s("computer.simple.usingNow",{place:r}):void 0,value:m,onClick:()=>a("where")}),e.jsx(Q,{"data-panel-page":"browser",icon:Nn,title:s("settings.sites.title"),value:d??void 0,onClick:()=>a("browser")})]})]})}const yr=3,_t="[&_.font-semibold]:font-medium [&_time]:text-[12px] [&_time]:text-ink-tertiary [&_span.bg-accent]:size-2",br=8,vr=200,he=new Map,We=new Set,Kt=t=>`${t.threadId}@${cs(t)}`;function kr(t,n){const[,a]=x.useState(0),i=n.filter(m=>m.threadId!==t.threadId).map(Kt).filter(m=>!he.has(m)&&!We.has(m)).join(",");x.useEffect(()=>{if(i)for(const m of i.split(",")){We.add(m);const r=m.slice(0,m.lastIndexOf("@"));Z(`/api/threads/${encodeURIComponent(r)}/messages?limit=${br}`,{background:!0}).then(c=>{he.set(m,Je({messages:c.messages??[],activeLeafId:c.activeLeafId??void 0})),he.size>vr&&he.delete(he.keys().next().value),a(p=>p+1)}).catch(()=>{}).finally(()=>We.delete(m))}},[i]);const l=Je(t),d=new Map(n.map(m=>[m.threadId,Kt(m)]));return m=>m===t.threadId?l:he.get(d.get(m)??"")}function jr({bot:t}){const{state:n,dispatch:a}=B(),o=Rn(),i=!rs(os,!0),[l,d]=x.useState(""),[m,r]=x.useState(!1),[c,p]=x.useState(!1),[u,k]=x.useState(!1),f=Tn(n.config),v=x.useMemo(()=>{const{onRename:y,onRegenerateTitle:z,onDelete:ce,onMove:xe,onPin:ye,onArchive:E}=In(t.id,a,f);return{onRename:y,onRegenerateTitle:z,onDelete:ce,onMove:xe,onPin:ye,onArchive:E}},[t.id,a,f]),j=An(t),N=t.tasks??[{threadId:t.threadId,title:s("task.newShort"),createdAt:0}],w=(j?Mn({...t,tasks:N},j):N).filter(y=>!y.routineRunId).map(y=>{const z=Ye(t,y.threadId);return{...y,busy:z.busy,activity:z.activity,waitingForTeammates:z.waitingForTeammates,turnStartedAt:z.turnStartedAt??void 0,queued:!!n.pendingQueued[y.threadId]?.length}}),b=ft(w.filter(y=>!ze(y)||y.threadId===t.threadId)),h=ft(w.filter(y=>ze(y)&&y.threadId!==t.threadId)),P=l.trim(),L=b.filter((y,z)=>z<yr||y.threadId===t.threadId),D=kr(t,[...P||c?b:L,...u?h:[]]),$=y=>{const z=D(y);return z?$n(Ye(t,y),z,n.instances,!1):void 0},A=Ln(b,P),H=P?[...A,...b.filter(y=>!A.includes(y)&&$(y.threadId)?.toLowerCase().includes(P.toLowerCase()))]:b,I=P?H:c?b:L,g=b.length-L.length,T=t.projects?.find(y=>y.id===t.tasks?.find(z=>z.threadId===t.threadId)?.projectId),F=()=>{i&&a({type:"toggleSettings",open:!1})},_=y=>{y.threadId!==t.threadId&&zn(a,t,y.threadId,!1),F()},K=()=>{a({type:"newTask",botId:t.id,...T?{projectId:T.id}:{}}),F()},J=()=>{d(""),r(!1)},Y=b.length>=2||m||b.some(y=>y.threadId===t.threadId&&ze(y)),U=y=>e.jsx("div",{role:"listitem","data-conversation":y.threadId,children:e.jsx(Fn,{panel:!0,preview:$(y.threadId),task:y,ownerId:t.id,current:y.threadId===t.threadId,folders:t.projects,now:Dn(cs(y),o),locale:ee(),onSelect:_,...v})},y.threadId);return e.jsxs("section",{"data-panel-card":"conversations","aria-label":s("botPanel.conversations.title"),children:[e.jsx(Re,{action:Y&&e.jsx("button",{type:"button","data-conversations-search":!0,"aria-label":s("botPanel.conversations.search"),title:s("botPanel.conversations.search"),"aria-pressed":m,onClick:()=>m?J():r(!0),className:O("-me-1 flex size-6 shrink-0 items-center justify-center rounded-[6px] text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink",m&&"bg-ink/[0.06] text-ink"),children:e.jsx(tt,{size:14,"aria-hidden":"true"})}),children:s("botPanel.conversations.title")}),e.jsx("div",{className:O("flex items-center gap-2",Y&&"mb-2"),children:t.yourAccess!=="view"&&j!=="team"&&e.jsxs("button",{type:"button","data-conversations-new":!0,"aria-label":s("botPanel.conversations.new"),onClick:K,className:O(ls,"flex-1"),children:[e.jsx(Bn,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.conversations.new")})]})}),Y&&m&&e.jsx("input",{autoFocus:!0,type:"search","data-conversations-query":!0,value:l,onChange:y=>d(y.target.value),onKeyDown:y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),J())},placeholder:s("botPanel.conversations.searchPlaceholder",{name:t.name}),"aria-label":s("botPanel.conversations.searchPlaceholder",{name:t.name}),className:"mb-1.5 w-full rounded-[8px] border border-hairline/60 bg-inset px-3 py-1.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-focus"}),Y&&e.jsx("div",{role:"list","aria-label":s("botPanel.conversations.title"),className:O("flex flex-col gap-px",_t),children:I.map(U)}),Y&&P&&I.length===0&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:s("task.noMatch",{query:P})}),Y&&!P&&g>0&&e.jsxs("button",{type:"button","data-conversations-more":!0,"aria-expanded":c,onClick:()=>p(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[c?e.jsx(yt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),c?s("botPanel.conversations.showFewer"):s("botPanel.conversations.showMore",{count:g})]}),!P&&h.length>0&&e.jsxs("button",{type:"button","data-conversations-archived":!0,"aria-expanded":u,onClick:()=>k(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[u?e.jsx(yt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),s("task.archivedList",{count:h.length})]}),!P&&u&&h.length>0&&e.jsx("div",{role:"list","aria-label":s("task.archivedList",{count:h.length}),className:O("flex flex-col gap-px",_t),children:h.map(U)})]})}function wr({bot:t}){const{dispatch:n}=B(),a=Jt();return t.defaultBot?a?e.jsx(bt,{placement:"panel-card"}):e.jsxs(M,{label:s("botPanel.tryAsking"),anchor:"try-asking",children:[Hn.map(o=>e.jsx("button",{type:"button","data-panel-ask":o,onClick:()=>n({type:"send",botId:t.id,text:s(o),threadId:t.threadId}),className:"flex h-9 w-full items-center px-3.5 text-left text-[14px] text-ink transition-colors hover:bg-ink/[0.03]",children:e.jsx("span",{className:"truncate",children:s(o)})},o)),e.jsx(bt,{placement:"panel"})]}):null}const Nr=["find","start-fresh","usage","activity","inspector"];function Sr({item:t}){const n=t.key==="usage";return e.jsxs("button",{type:"button","data-panel-item":t.key,disabled:t.disabled,title:t.title,"aria-pressed":t.active||void 0,onClick:t.onSelect,className:O(X,"w-full rounded-[8px] text-left enabled:hover:bg-ink/[0.04] disabled:cursor-default disabled:opacity-45"),children:[e.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-ink-secondary [&_svg]:size-4","aria-hidden":"true",children:t.icon}),e.jsx("span",{className:O("min-w-0 truncate text-[14px] font-medium",!n&&"flex-1",t.active?"text-accent-text":"text-ink"),children:t.label}),t.trailing&&e.jsx("span",{className:O("flex items-center",n?"min-w-0 flex-1 justify-end text-right":"shrink-0"),children:t.trailing}),t.key!=="find"&&t.key!=="start-fresh"&&e.jsx(je,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary rtl:-scale-x-100"})]})}function Cr({bot:t,derived:n,onOpen:a}){const{items:o}=_n(t),{dispatch:i}=B(),l=n.botRoutines.filter(m=>m.enabled).length,d=Nr.flatMap(m=>o.filter(r=>r.key===m));return e.jsxs("div",{"data-panel-tabpanel":"details",children:[e.jsx("section",{"data-panel-card":"model",className:"pt-2",children:e.jsx("div",{"data-panel-row":"model",className:O(X,"rounded-[8px]"),children:e.jsx(Kn,{bot:t,contained:!0,threadId:t.threadId,label:e.jsxs("span",{className:"flex shrink-0 items-center gap-2.5",children:[e.jsx(te,{icon:nt}),e.jsx(ae,{title:s("model.simple.model")})]})})})}),e.jsx(jr,{bot:t}),e.jsx(wr,{bot:t}),d.length>0&&e.jsxs("section",{"data-panel-card":"conversation",children:[e.jsx(Re,{children:s("botPanel.section.conversation")}),d.map(m=>e.jsx(Sr,{item:m},m.key))]}),n.botRoutines.length===0?e.jsxs("section",{"data-panel-empty":"routines",children:[e.jsx(Re,{action:e.jsx(Un,{"data-panel-automations":"",onClick:()=>i({type:"showRoutines",view:"list"}),children:s("sidebar.nav.automations")}),children:s("botSettings.simple.routines")}),e.jsxs("button",{type:"button","data-panel-page":"routines",title:s("botPanel.routines.emptyHint"),onClick:()=>a("routines"),className:O(ls,"w-full"),children:[e.jsx(Di,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.routines.add")})]})]}):e.jsx(M,{label:s("botSettings.simple.routines"),anchor:"routines",children:e.jsx(Q,{"data-panel-page":"routines",icon:qn,title:s("botSettings.simple.routines"),value:l>0?s("botPanel.routinesOn",{count:l}):s("botPanel.none"),onClick:()=>a("routines")})})]})}const Ls=/^\s*[-*]\s+(.+?)\s*$/;function Pr(t){return t.split(`
8
+ `).flatMap((n,a)=>{const o=Ls.exec(n)?.[1];return o?[{line:a,text:o}]:[]})}function Or(t,n){const a=t.split(`
9
9
  `);return Ls.test(a[n]??"")?(a.splice(n,1),a.join(`
10
- `)):t}function Pr(t,n){const a=t.replace(/\s+$/,""),o=`- ${n.trim().replace(/\s*\n\s*/g," ")}`;return a?`${a}
10
+ `)):t}function Er(t,n){const a=t.replace(/\s+$/,""),o=`- ${n.trim().replace(/\s*\n\s*/g," ")}`;return a?`${a}
11
11
  ${o}
12
12
  `:`${o}
13
- `}function Bs(t){return t.flatMap(n=>{const a=Sr(n.text).map(i=>({path:n.path,...i}));if(a.length||n.path===se)return a;const o=n.text.split(`
14
- `).map(i=>i.replace(/^#+\s*/,"").trim()).filter(Boolean).join(" ");return o?[{path:n.path,line:null,text:o}]:[]})}async function Or(t,n){if(!n)return[await Ie(t,se)];const a=await ot(t,!0);return Promise.all([se,...a.topics.map(o=>o.path)].map(o=>Ie(t,o,!0)))}function $s(t){const n=!!B().state.config?.team,[a,o]=u.useState({botId:t.id,docs:null,error:!1}),i=t.memoryEnabled!==!1,l=async(r,c)=>{try{const p=await Or(r,n);c?.()||o({botId:r,docs:p,error:!1})}catch{c?.()||o({botId:r,docs:null,error:!0})}},d=!!t.busy;u.useEffect(()=>{if(!i)return;let r=!1;return l(t.id,()=>r),()=>{r=!0}},[t.id,i,d,n]);const m=a.botId===t.id;return{docs:m?a.docs:null,error:m&&a.error,mine:n,setDoc:r=>o(c=>({botId:t.id,docs:(c.botId===t.id?c.docs??[]:[]).map(p=>p.path===r.path?r:p),error:!1})),reload:()=>l(t.id)}}function Er(t,n=Je(t)){const a=[],o=[],i=new Set;for(const c of[...n].reverse()){const p=c.publishedPage;p?.state==="live"&&p.url&&!i.has(p.url)&&(i.add(p.url),a.push({messageId:c.id,title:p.title||p.url,url:p.url})),c.kind==="app"&&c.app?.doc&&o.push({messageId:c.id,title:c.app.title})}const l=Ri(t),d=[],m=new Set;for(const c of l.values())m.has(c.file.path)||(m.add(c.file.path),d.push(c));const r=Ti(t).filter(c=>!l.has(c));return{pages:a,apps:o,shared:d,unshared:r}}const Rr=t=>t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);function Fs({bot:t,onOpen:n}){const{dispatch:a}=B(),o=Le(),{capabilities:i}=we(),l=Un(),d=!rs(os,!0),m=ws(t),r=$s(t),{pages:c,apps:p,shared:x,unshared:k}=u.useMemo(()=>Er(t),[t]),f=b=>{a({type:"focusMessage",threadId:t.threadId,messageId:b}),d&&a({type:"toggleSettings",open:!1})},v=m.skills.filter(Ns).length,j=r.docs?Bs(r.docs).length:null,N=t.memoryEnabled===!1?s("botPanel.memory.off"):j===null?r.error?s("botPanel.memory.nothingYet"):void 0:j===0?s("botPanel.memory.nothingYet"):j===1?s("botPanel.memory.note"):s("botPanel.memory.notes",{count:j}),w=e.jsxs(M,{anchor:"keeps",children:[e.jsx(Q,{"data-panel-page":"memory",icon:Xt,title:s("botPanel.memoryRow"),value:N,onClick:()=>n("memory")}),e.jsx(Q,{"data-panel-page":"skills",icon:qn,title:s("botSettings.simple.skills"),value:m.loading?void 0:v>0?v:s("botPanel.none"),onClick:()=>n("skills")}),o&&e.jsx(Q,{"data-panel-page":"plugins",icon:at,title:s("plugins.botMenu"),onClick:()=>n("plugins")}),e.jsx(Q,{"data-panel-page":"folder",icon:Wn,title:s("computer.files.folder"),value:t.cwd?it(t.cwd,i.host?.homeDir):s("botPanel.folder.private"),onClick:()=>n("folder")})]});return c.length+p.length+x.length+k.length===0?e.jsxs("div",{"data-panel-tabpanel":"library",children:[e.jsx("p",{"data-panel-empty":"library",className:"px-3 py-7 text-center text-[13px] leading-[18px] text-ink-tertiary",children:s("botPanel.library.empty")}),w]}):e.jsxs("div",{"data-panel-tabpanel":"library",children:[c.length>0&&e.jsx(M,{label:s("botPanel.library.pages"),anchor:"pages",children:c.map(b=>e.jsx(Q,{"data-panel-row":"page",icon:Vn,title:e.jsx("span",{className:"block truncate",children:b.title}),hint:e.jsx("span",{className:"block truncate",children:b.url}),onClick:()=>l(b.url)},b.url))}),p.length>0&&e.jsx(M,{label:s("botPanel.library.apps"),anchor:"apps",children:p.map(b=>e.jsx(Q,{"data-panel-row":"app",icon:ds,title:e.jsx("span",{className:"block truncate",children:b.title}),onClick:()=>f(b.messageId)},b.messageId))}),x.length+k.length>0&&e.jsxs("section",{"data-panel-card":"files",children:[e.jsx(Re,{children:s("botPanel.library.files")}),e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[x.map(b=>e.jsx("li",{className:"min-w-0",children:e.jsx(Zn,{file:b.file,message:b.message,linked:b.file.linked,className:"w-full max-w-none"})},`${b.message.messageId}:${b.file.path}`)),k.map(b=>e.jsxs("li",{title:s("computer.files.notSharedHint"),className:"flex min-w-0 items-center gap-2 rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx(Me,{size:14,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:Rr(b)}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-tertiary",children:s("computer.files.notShared")})]},b))]})]}),e.jsx("p",{className:"mt-3 text-center text-[12px] text-ink-tertiary",children:s("botPanel.library.scope")}),w]})}function Tr({bot:t,browserEnabled:n,onOpenBrowser:a}){const{state:o}=B(),i=Le(),l=t.browserProfile??"",d=(o.config?.browserProfiles??[]).find(p=>p.id===l),m=l==="guest",r=d?.browser==="chrome"&&o.config?.browserEngine?.myChrome===!0,c=l&&!m?o.bots.filter(p=>p.browserProfile===l).map(p=>p.name):[t.name];return e.jsx(M,{anchor:"logins",children:n?m?e.jsx(V,{children:s("settings.profiles.temporaryHint")}):r?e.jsx(V,{children:s("settings.profiles.myChromeHint")}):e.jsxs(e.Fragment,{children:[i!==!1&&(l===""||d)&&e.jsx(me,{children:e.jsx(Li,{bare:!0,target:{bot:t.id},sharedBy:c,disabled:!!t.busy},`${t.id}:${l}`)}),e.jsx(V,{children:s("botSettings.simple.loginsHint",{name:t.name})}),e.jsx(ue,{"data-panel-action":"add-login",icon:Ne,onClick:a,children:s("botSettings.simple.addLogin")})]}):e.jsx(V,{children:s("botSettings.simple.loginsOff",{name:t.name})})})}const Ir=[["all",()=>S("Tất cả","All")],["added",()=>S("Bot đang có","On this bot")],["more",()=>S("Chưa thêm","Not added")]],Ar=t=>({bundled:S("Có sẵn","Built in"),library:S("Đã tải về","Downloaded"),imported:S("Từ máy tính","From this computer")})[t],Ve="inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50";async function qt(t,n){const a=await fetch(t,n===void 0?void 0:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error??S(`Lỗi ${a.status}`,`Error ${a.status}`));return o.skills??[]}function Mr({botId:t,botName:n,onClose:a,onOpenSettings:o}){const[i,l]=u.useState(null),[d,m]=u.useState(""),[r,c]=u.useState("all"),[p,x]=u.useState(""),[k,f]=u.useState(""),v=`/api/limix/skill-store/${encodeURIComponent(t)}`;u.useEffect(()=>{let h=!1;return qt(v).then(P=>{h||l(P)}).catch(P=>{h||(l([]),f(P.message))}),()=>{h=!0}},[v]),u.useEffect(()=>{const h=P=>{P.key==="Escape"&&a()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[a]);const j=u.useMemo(()=>{const h=d.trim().toLowerCase();return(i??[]).filter(P=>(r==="all"||(r==="added"?P.added:!P.added))&&(!h||`${P.name} ${P.description}`.toLowerCase().includes(h)))},[i,d,r]),N=async(h,P)=>{if(!p){x(h.name),f("");try{l(await qt(v,{name:h.name,kind:h.kind,add:P}))}catch(L){f(L instanceof Error?L.message:S("Không đổi được kỹ năng này.","Couldn't change this skill."))}finally{x("")}}},w=(i??[]).filter(h=>h.added).length,b=e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onMouseDown:h=>h.stopPropagation(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"limix-skill-store-title",className:"flex max-h-full w-full max-w-[640px] flex-col rounded-2xl border border-hairline/50 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pb-3 pt-5",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"limix-skill-store-title",className:"text-[17px] font-semibold text-ink",children:S("Kho kỹ năng","Skills Store")}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:S(`Chọn kỹ năng cho ${n}. Bot sẽ nhận hướng dẫn của những kỹ năng bạn thêm. Để dùng một kỹ năng, gõ dấu / rồi nhập tên kỹ năng trong khung chat.`,`Pick skills just for ${n}. Only added skills go into the bot's prompt, so it never gets overloaded. Type /skill-name in chat to call one.`)})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":S("Đóng","Close"),className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(st,{size:16})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-6 pb-3",children:[e.jsxs("label",{className:"flex min-w-[200px] flex-1 items-center gap-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx(tt,{size:14,className:"text-ink-tertiary"}),e.jsx("input",{value:d,onChange:h=>m(h.target.value),placeholder:S("Tìm kỹ năng…","Search skills…"),"aria-label":S("Tìm kỹ năng","Search skills"),className:"w-full bg-transparent text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsx("div",{className:"flex gap-1",role:"tablist","aria-label":S("Lọc kỹ năng","Filter skills"),children:Ir.map(([h,P])=>e.jsxs("button",{type:"button",role:"tab","aria-selected":r===h,onClick:()=>c(h),className:`rounded-lg px-2.5 py-1.5 text-[13px] ${r===h?"bg-raised text-ink":"text-ink-secondary hover:bg-raised"}`,children:[P(),h==="added"&&i?` ${w}`:""]},h))})]}),k&&e.jsx("p",{role:"alert",className:"mx-6 mb-2 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:k}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6",children:i===null?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-[13px] text-ink-secondary",children:[e.jsx(Ee,{size:14,className:"animate-spin"}),S("Đang tải kho…","Loading the store…")]}):j.length===0?e.jsx("p",{className:"py-6 text-[13px] text-ink-secondary",children:i.length===0?S("Kho chưa có kỹ năng nào.","The store has no skills yet."):S("Không tìm thấy kỹ năng phù hợp.","No matching skills.")}):e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40",children:j.map(h=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[13px] text-ink",children:h.name}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:h.core?S("Kỹ năng gốc","Core skill"):Ar(h.kind)}),h.warnings>0&&e.jsxs("span",{className:"text-[12px] text-warning",children:[h.warnings," ",S("cảnh báo","warnings")]})]}),e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[12px] leading-relaxed text-ink-secondary",children:h.description})]}),h.core?e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 px-1 py-1.5 text-[12px] text-ink-secondary",children:[e.jsx(mt,{size:14}),S("Luôn bật","Always on")]}):h.added?e.jsxs("button",{type:"button",className:Ve,disabled:!!p,onClick:()=>{N(h,!1)},"aria-label":S(`Bỏ ${h.name} khỏi bot`,`Remove ${h.name} from this bot`),children:[p===h.name?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(mt,{size:14}),S("Đã thêm","Added")]}):e.jsxs("button",{type:"button",className:Ve,disabled:!!p||!h.ready,onClick:()=>{N(h,!0)},"aria-label":S(`Thêm ${h.name} cho bot`,`Add ${h.name} to this bot`),children:[p===h.name?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ne,{size:14}),S("Thêm","Add")]})]},`${h.kind}:${h.name}`))})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 px-6 pb-5 pt-3",children:[e.jsx("p",{className:"text-[12px] text-ink-tertiary",children:S('Bấm "Đã thêm" để bỏ kỹ năng khỏi bot này.','Press "Added" to remove a skill from this bot.')}),e.jsx("button",{type:"button",className:Ve,onClick:o,children:S("Tải thêm kỹ năng","Get more skills")})]})]})});return typeof document>"u"?b:fs.createPortal(b,document.body)}const ve=()=>window.ogb?.limixMessenger,Wt=[{kind:"telegram",label:"Telegram",placeholder:"123456789:AA…",howTo:()=>S("Tạo bot với @BotFather (lệnh /newbot), rồi dán token vào đây.","Make a bot with @BotFather (/newbot), then paste its token here."),where:t=>`@${t.username}`,linkFrom:t=>S(`Nhắn cho @${t.username}: `,`Send @${t.username}: `)},{kind:"discord",label:"Discord",placeholder:"MTA…",howTo:()=>S("Vào discord.com/developers → New Application → Bot → Reset Token, dán token vào đây. Mời bot vào server: OAuth2 → URL Generator → chọn bot và quyền Send Messages. Trong server, gọi bot bằng @tên-bot.","At discord.com/developers: New Application → Bot → Reset Token, paste it here. Invite it with OAuth2 → URL Generator (bot, Send Messages). In a server, call it with @its-name."),where:t=>`@${t.username}`,linkFrom:()=>S("Nhắn riêng cho bot trên Discord: ","Send the bot a direct message on Discord: ")},{kind:"zalo",label:"Zalo",howTo:()=>S("Quét mã QR bằng ứng dụng Zalo của tài khoản sẽ làm bot.","Scan the QR code with the Zalo app of the account that will be the bot."),note:()=>S("Nên dùng tài khoản Zalo phụ: đây là cách đăng nhập không chính thức (như Zalo Web), Zalo có thể khoá tài khoản. Mở Zalo Web bằng tài khoản này ở nơi khác sẽ ngắt bot.","Use a spare Zalo account: this sign-in is unofficial (like Zalo Web) and Zalo may lock the account. Opening Zalo Web with it elsewhere disconnects the bot."),where:t=>t.name||t.username||"Zalo",linkFrom:()=>S("Từ Zalo của bạn, nhắn cho tài khoản bot: ","From your own Zalo, message the bot's account: ")},{kind:"facebook",label:"Facebook Page",placeholder:"EAA…",howTo:()=>S("Dán Page Access Token: developers.facebook.com → tạo app → thêm Messenger → Access Tokens → chọn Page → Generate token.","Paste a Page access token: developers.facebook.com → create an app → add Messenger → Access Tokens → pick the Page → Generate token."),note:()=>S("Bot trả lời khách nhắn vào Page sau khoảng 10–20 giây. Muốn trả lời mọi khách, app Meta cần được duyệt quyền pages_messaging.","The bot answers people who message the Page within about 10–20 seconds. To answer everyone, the Meta app needs pages_messaging approved."),where:t=>t.name||"Page",linkFrom:()=>S("Từ Facebook cá nhân, nhắn cho Page: ","From your own Facebook, message the Page: ")},{kind:"messenger",label:"Messenger",howTo:()=>S("Đăng nhập Facebook trong cửa sổ của app (nhập cả mã PIN khôi phục tin nhắn nếu Facebook hỏi), rồi đóng cửa sổ. App giữ một cửa sổ Facebook ẩn, đọc tin mới và gõ câu trả lời.","Sign in to Facebook in the app's window (enter the chat-restore PIN if Facebook asks), then close it. The app keeps a hidden Facebook window that reads new messages and types the replies."),note:()=>S("Thử nghiệm, tài khoản cá nhân. Chỉ chạy khi app đang mở trên máy này. Nên dùng tài khoản phụ: Facebook không có cách chính thức cho tài khoản cá nhân và có thể khoá tài khoản. Ai nhắn cũng được trả lời ở chế độ an toàn.","Beta, personal accounts. Runs only while the app is open on this computer. Use a spare account: Facebook has no official way for personal accounts and may lock it. Everyone is answered in safe mode."),where:()=>S("tài khoản Facebook đã đăng nhập","the signed-in Facebook account"),linkFrom:()=>""}],ne="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50";function Lr({bot:t,className:n}){const[a,o]=u.useState("telegram"),[i,l]=u.useState({});u.useEffect(()=>{let r=!0;l({});for(const c of Wt.filter(p=>p.kind!=="messenger"||ve()))Z(`/api/bots/${t.id}/${c.kind}`).then(p=>{r&&l(x=>({...x,[c.kind]:p}))}).catch(()=>{});return()=>{r=!1}},[t.id]);const d=Wt.filter(r=>r.kind!=="messenger"||ve()),m=d.find(r=>r.kind===a);return e.jsxs("div",{className:O("rounded-xl bg-card p-4",n),"data-testid":"channels-card",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:S("Kênh chat","Chat channels")}),e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:S(`Cho ${t.name} trả lời tin nhắn ngoài app.`,`Let ${t.name} answer messages outside the app.`)}),e.jsx("div",{role:"tablist",className:"mt-3 flex flex-wrap gap-1.5",children:d.map(r=>{const c=i[r.kind];return e.jsxs("button",{type:"button",role:"tab","aria-selected":a===r.kind,onClick:()=>o(r.kind),"data-testid":`channel-tab-${r.kind}`,className:O("flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-[13px]",a===r.kind?"bg-control text-ink":"text-ink-secondary hover:bg-raised-hover"),children:[c?.connected&&e.jsx("span",{className:O("size-1.5 rounded-full",c.error?"bg-danger":c.enabled?"bg-success":"bg-ink-tertiary")}),r.label]},r.kind)})}),e.jsx(Br,{bot:t,channel:m,view:i[a],onView:r=>l(c=>({...c,[a]:r}))},`${t.id}:${a}`)]})}function Br({bot:t,channel:n,view:a,onView:o}){const i=`/api/bots/${t.id}/${n.kind}`,[l,d]=u.useState(""),[m,r]=u.useState(null),[c,p]=u.useState(!1),[x,k]=u.useState(null),f=!!(a?.login&&!a.login.error&&!a.connected);u.useEffect(()=>{if(!f&&!m)return;let N=!0;const w=setInterval(()=>{Z(i).then(b=>{N&&(o(b),b.linkExpiresAt||r(null))}).catch(()=>{})},2e3);return()=>{N=!1,clearInterval(w)}},[f,m,i,o]);const v=async N=>{p(!0),k(null);try{const{code:w,...b}=await N();o(b),w&&r(w)}catch(w){k(w instanceof Error?w.message:String(w))}finally{p(!1)}},j=(N,w="")=>v(()=>Z(`${i}${w}`,{method:"POST",body:JSON.stringify(N??{})}));return a?e.jsxs("div",{className:"mt-3 text-[13px]","data-testid":`channel-${n.kind}`,children:[!a.connected&&e.jsxs("div",{className:"flex flex-col gap-2 text-ink-secondary",children:[e.jsx("span",{children:n.howTo()}),n.note&&e.jsx("span",{className:"text-[12px]",children:n.note()}),n.placeholder?e.jsxs("form",{className:"flex gap-2",onSubmit:N=>{N.preventDefault(),l.trim()&&j({token:l.trim()}).then(()=>d(""))},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:l,onChange:N=>d(N.target.value),placeholder:n.placeholder,"aria-label":S(`Token ${n.label}`,`${n.label} token`),className:"min-w-0 flex-1 rounded-lg bg-inset px-3 py-1.5 font-mono text-[13px] text-ink outline-none","data-testid":`channel-token-${n.kind}`}),e.jsx("button",{type:"submit",disabled:c||!l.trim(),className:ne,"data-testid":`channel-connect-${n.kind}`,children:S("Kết nối","Connect")})]}):n.kind==="messenger"?e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:c,onClick:()=>{v(async()=>await ve().signIn(t.id))},"data-testid":"channel-signin-messenger",children:S("Mở cửa sổ đăng nhập Facebook","Open the Facebook sign-in window")}):e.jsx($r,{view:a,busy:c,start:()=>{j({},"/login")},cancel:()=>{v(()=>Z(`${i}/login`,{method:"DELETE"}))}})]}),a.connected&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsx("span",{children:S(`${t.name} trả lời tin nhắn gửi tới ${n.where(a)}.`,`${t.name} answers messages sent to ${n.where(a)}.`)}),e.jsx(be,{"aria-label":S(`Bật ${n.label}`,`${n.label} on`),checked:a.enabled===!0,disabled:c,onClick:()=>{j({enabled:!a.enabled})},"data-testid":`channel-switch-${n.kind}`})]}),n.note&&(n.kind==="facebook"||n.kind==="messenger")&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:n.note()}),n.kind==="messenger"?e.jsx("button",{type:"button",className:O(ne,"self-start"),onClick:()=>{ve()?.show(t.id)},children:S("Mở cửa sổ Messenger của bot","Show the bot's Messenger window")}):e.jsxs("div",{className:"flex flex-col gap-2 text-ink-secondary",children:[a.owner&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:S(`Chủ bot: ${a.owner}`,`Owner: ${a.owner}`)}),e.jsx("button",{type:"button",className:ne,disabled:c,onClick:()=>{j({},"/unlink")},children:S("Bỏ liên kết","Unlink")})]}),a.admins?.map(N=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:s("channels.admin.account",{name:N.name,id:N.id})}),e.jsx("button",{type:"button",className:ne,disabled:c,"aria-label":s("channels.admin.removeNamed",{name:N.name,id:N.id}),onClick:()=>{j({id:N.id},"/remove-admin")},children:s("channels.admin.remove")})]},N.id)),e.jsx("span",{children:s("channels.admin.explain")}),m&&a.linkExpiresAt?e.jsxs("span",{className:"text-ink","data-testid":`channel-code-${n.kind}`,children:[n.linkFrom(a),e.jsxs("code",{className:"rounded bg-inset px-1.5 py-0.5 font-mono",children:["/link ",m]}),S(" (hết hạn sau 15 phút)"," (expires in 15 minutes)")]}):e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:c,onClick:()=>{j({},"/link")},"data-testid":`channel-link-${n.kind}`,children:a.owner?s("channels.admin.invite"):S("Tạo mã liên kết","Make a link code")})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsxs("span",{children:[S("Trả lời cả người khác","Answer other people too"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:n.kind==="zalo"?S("Người khác có thể nhắn riêng cho bot với quyền khách.","Other people can message the bot privately as guests."):S("Người khác và nhóm nhắn được bot ở chế độ an toàn: không dùng công cụ, không thấy cuộc trò chuyện của bạn.","Others and groups can write to the bot in safe mode: no tools, none of your conversations.")})]}),e.jsx(be,{"aria-label":S("Trả lời cả người khác","Answer other people too"),checked:a.access==="everyone",disabled:c,onClick:()=>{j({access:a.access==="everyone"?"owner":"everyone",...a.groupMentions!==void 0?{groupMentions:a.groupMentions}:{}})},"data-testid":`channel-everyone-${n.kind}`})]}),n.kind==="zalo"&&e.jsxs("label",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsxs("span",{children:[S("Trả lời khi được @gọi trong nhóm","Reply to @mentions in groups"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:S("Chủ bot đã liên kết luôn có toàn quyền khi gọi bot trong nhóm. Bật tùy chọn này để các thành viên khác cũng có thể gọi bot với quyền khách.","The linked owner always has full access when mentioning the bot in a group. Turn this on to let other members mention it with guest access.")})]}),e.jsx(be,{"aria-label":S("Trả lời khi được @gọi trong nhóm","Reply to @mentions in groups"),checked:a.groupMentions??a.access==="everyone",disabled:c,onClick:()=>{j({groupMentions:!(a.groupMentions??a.access==="everyone")})},"data-testid":"channel-zalo-group-mentions"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",className:ne,disabled:c,onClick:()=>{v(async()=>{const N=await Z(i,{method:"DELETE"});return n.kind==="messenger"&&await ve()?.signOut(t.id),N})},"data-testid":`channel-remove-${n.kind}`,children:S("Gỡ kết nối","Disconnect")})})]}),(x||a.error)&&e.jsx("div",{role:"alert",className:"mt-2 text-[13px] text-danger",children:x??a.error})]}):e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:"…"})}function $r({view:t,busy:n,start:a,cancel:o}){const i=t.login;return!i||i.error?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i?.error&&e.jsx("span",{className:"text-danger",children:i.error}),e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:n,onClick:a,"data-testid":"channel-qr-zalo",children:S("Tạo mã QR đăng nhập","Show a sign-in QR code")})]}):e.jsxs("div",{className:"flex items-start gap-3",children:[i.qr?e.jsx("img",{src:i.qr,alt:S("Mã QR đăng nhập Zalo","Zalo sign-in QR code"),className:"size-44 rounded-lg bg-white p-1.5","data-testid":"channel-qr-image"}):e.jsx("div",{className:"flex size-44 items-center justify-center rounded-lg bg-inset",children:"…"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-ink",children:i.scanned?S(`${i.scanned} đã quét. Xác nhận đăng nhập trong ứng dụng Zalo.`,`${i.scanned} scanned it. Confirm the sign-in in the Zalo app.`):S("Mở Zalo trên điện thoại → biểu tượng quét mã → quét mã này.","Open Zalo on the phone → scan icon → scan this code.")}),e.jsx("button",{type:"button",className:O(ne,"self-start"),onClick:o,children:S("Huỷ","Cancel")})]})]})}const Fr=5,Dr={instanceId:"",model:""},Ds=(t,n)=>`${t}\0${n}`,zr=new Set;function Vt({bot:t,current:n,exclude:a,onPick:o,label:i,title:l,buttonRef:d,className:m,children:r,...c}){const{state:p,dispatch:x,refreshInstances:k,refreshModels:f}=B(),[v,j]=u.useState(!1),[N,w]=u.useState(""),[b,h]=u.useState(()=>new Set),[P,L]=u.useState(!1),[D,$]=u.useState(null),[A,H]=u.useState(null),I=u.useRef(null),g=d??I,T=u.useRef(null),F=u.useRef(null),_=u.useRef(!1),K=u.useId(),J=ii(v),Y=u.useRef({contains:E=>[g.current,T.current].some(q=>q?.contains(E))});ea(v,Y,()=>j(!1)),u.useLayoutEffect(()=>{if(!v)return;const E=q=>{if(q?.type==="scroll"&&q.target instanceof Node&&T.current?.contains(q.target))return;const G=g.current?.getBoundingClientRect(),W=T.current;!G||!W||H(de=>na(G,{width:kt,height:W.offsetHeight},{width:window.innerWidth,height:window.innerHeight},de??void 0))};return E(),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0),()=>{window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0)}},[v,g]),u.useEffect(()=>{if(!v||!A||!_.current)return;_.current=!1;const E=T.current;(E?.querySelector("[data-menu-search]")??E?.querySelector("[data-current-model]")??E?.querySelector("[data-menu-row]:not(:disabled)")??E)?.focus({preventScroll:!0})},[v,A]);const U=E=>{j(!1),E&&g.current?.focus({preventScroll:!0})},y=()=>{w(""),h(new Set),H(null),_.current=!0,j(!0),L(!0),k().catch(()=>{}).finally(()=>L(!1))},z=E=>{D||($(E.instanceId),f(E.instanceId).catch(()=>{}).finally(()=>$(null)))},ce=()=>{U(!1),x({type:"toggleAppSettings",open:!0,section:"engines"})},xe=()=>{const E=ia(p.instances,n?.instanceId).flatMap(W=>{const de=W.models.options.filter(Se=>!a.has(Ds(W.instanceId,Se.id)));return de.length===W.models.options.length?[W]:de.length?[{...W,models:{...W.models,options:de}}]:[]}),q=ra({instances:p.instances,listed:E,selection:n??Dr,bot:{name:t.name,selection:t.modelSelection},query:N,expanded:b,probing:zr,loading:P,refreshing:D}),G=q.groups.map(W=>W.instance.instanceId===t.modelSelection.instanceId?{...W,note:s("botPanel.backups.sameAccount")}:W);return{...q,groups:G,...n?{}:{current:null}}},ye=E=>{if(!(E.nativeEvent.isComposing||E.defaultPrevented)){if(E.key!=="Escape")return aa(E,{query:N,typed:F,close:()=>U(!0)});E.preventDefault(),E.stopPropagation(),N?w(""):U(!0)}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",...c,"aria-label":i,title:l,"aria-haspopup":"dialog","aria-expanded":v,"aria-controls":v?K:void 0,onClick:()=>v?U(!1):y(),onKeyDown:E=>{E.key==="Escape"&&v?(E.preventDefault(),E.stopPropagation(),U(!1)):(E.key==="ArrowDown"||E.key==="ArrowUp")&&!v&&(E.preventDefault(),y())},className:m,children:r}),J.shown&&fs.createPortal(e.jsx("div",{ref:T,id:K,"data-backup-menu":!0,role:"dialog","aria-label":s("botPanel.backups.choose"),"aria-modal":"false",tabIndex:-1,...J.exitProps,onKeyDown:ye,onPointerMove:ta,style:{position:"fixed",left:A?.left??0,top:A?.top,bottom:A?.bottom,width:A?.width??kt,maxHeight:A?.maxHeight,transformOrigin:A?.origin,visibility:A?void 0:"hidden"},className:O("menu-surface z-[80] flex flex-col overflow-hidden",J.className),children:e.jsx(sa,{menu:xe(),query:N,bot:t,botModel:{label:"",title:""},idPrefix:K,onQuery:w,onPick:(E,q)=>{E.policy||(o({instanceId:E.instanceId,model:q}),U(!0))},onPickCurrent:()=>U(!0),onFollowBot:()=>U(!0),onToggle:E=>h(q=>{const G=new Set(q);return G.delete(E.instanceId)||G.add(E.instanceId),G}),onSetUp:ce,onCheckAgain:z,onManage:ce})}),document.body)]})}function Hr({bot:t,onChange:n}){const{state:a}=B(),o=t.fallback??[],i=u.useRef(null),l=m=>new Set([t.modelSelection,...o.filter((r,c)=>c!==m)].map(r=>Ds(r.instanceId,r.model))),d=m=>{const r=a.instances.find(x=>x.instanceId===m.instanceId),c=r?.models.options.find(x=>x.id===m.model),p=Jn(r,m.model);return{instance:r,name:p,short:r&&c?Qn(c.label,Xn(r)):p}};return e.jsx(M,{anchor:"backups",children:e.jsxs(me,{"data-panel-row":"backups",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:Gn}),e.jsx(ae,{title:s("botPanel.backups.title")})]}),e.jsx("p",{className:"-mt-1 pl-[38px] text-[13px] leading-[1.35] text-ink-secondary",children:s("botPanel.backups.hint",{name:t.name})}),o.length>0&&e.jsx("ol",{"aria-label":s("botPanel.backups.title"),className:"flex flex-col gap-1 pl-[38px]",children:o.map((m,r)=>{const{instance:c,name:p,short:x}=d(m);return e.jsxs("li",{"data-backup":m.instanceId,className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"w-3 shrink-0 text-[12px] tabular-nums text-ink-tertiary","aria-hidden":"true",children:r+1}),e.jsxs(Vt,{bot:t,current:m,exclude:l(r),onPick:k=>n(o.map((f,v)=>v===r?k:f)),label:s("botPanel.backups.row",{position:r+1,model:p}),title:c?`${c.displayName} · ${p}`:p,"data-panel-action":"backup-change",className:"group flex h-8 min-w-0 flex-1 items-center gap-2 rounded-[8px] bg-ink/[0.04] pl-2.5 pr-2 text-left text-[13px] text-ink hover:bg-ink/[0.07] aria-expanded:bg-ink/[0.08]",children:[c?e.jsx(Yn,{instance:c,size:14,subtle:!0}):e.jsx("span",{className:"size-3.5 shrink-0 rounded-full bg-ink/[0.08]","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:x}),!c&&e.jsx("span",{className:"shrink-0 text-[12px] text-warning",children:s("model.simple.unavailable")}),e.jsx(fe,{size:12,strokeWidth:2,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary group-hover:text-ink-secondary"})]}),e.jsx(Be,{"data-panel-action":"backup-remove",label:s("botPanel.backups.remove",{model:p}),onClick:()=>{n(o.filter((k,f)=>f!==r)),i.current?.focus({preventScroll:!0})}})]},r)})}),o.length<Fr&&e.jsx("div",{className:"pl-[38px]",children:e.jsxs(Vt,{bot:t,current:null,exclude:l(null),onPick:m=>n([...o,m]),label:s("model.fallback.add"),buttonRef:i,"data-panel-action":"backup-add",className:O(le,"aria-expanded:bg-raised-hover"),children:[e.jsx(Ne,{size:14,"aria-hidden":"true"}),s("model.fallback.add")]})})]})})}function _r({bot:t}){const{dispatch:n}=B(),[a,o]=u.useState(!1),[i,l]=u.useState(!1),[d,m]=u.useState(0),r=t.memoryEnabled!==!1&&t.memoryUpkeep!==!1;if(u.useEffect(()=>{if(!r)return;let p=!0;return Z(`/api/bots/${t.id}/system-prompt`).then(x=>{p&&o(x.heavy===!0)},()=>{}),()=>{p=!1}},[t.id,r,d]),!r||!a)return null;const c=async()=>{l(!0);try{await vs(t.id)}catch(p){n({type:"error",message:p instanceof Error&&p.message?p.message:s("common.tryAgain")})}finally{l(!1),m(p=>p+1)}};return e.jsx(M,{anchor:"heavy",children:e.jsxs("div",{"data-panel-row":"heavy",className:X,children:[e.jsx(te,{icon:oa}),e.jsx(ae,{title:s("botPanel.heavy")}),e.jsx("button",{type:"button","data-panel-action":"tidy-memory",disabled:i,onClick:()=>{c()},className:le,children:i?s("memory.upkeep.tidying"):s("botPanel.tidyMemory")})]})})}const Kr=5;function Ur({bot:t}){const{dispatch:n,flushBotPatches:a}=B(),[o,i]=u.useState([]),[l,d]=u.useState(null),m=u.useCallback(()=>Et(t.id).then(c=>i(c.rows.slice(0,Kr)),()=>{}),[t.id]);if(u.useEffect(()=>{m()},[m,t.soul]),!o.length)return null;const r=async c=>{if(!l){d(c.id);try{await a(t.id);const{revision:p}=await Et(t.id);await xi(t.id,c.id,p)}catch(p){n({type:"error",message:p instanceof Error&&p.message?p.message:s("botOverview.undoFailed")})}finally{d(null),await m()}}};return e.jsxs("div",{"data-panel-row":"soul-changes",className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:s("memory.changes")}),e.jsx(ct,{rows:o,botName:t.name,reverting:l,onRevert:c=>{r(c)}})]})}const Ze={ask:()=>s("botSettings.simple.ask"),full:()=>s("botSettings.simple.justDoIt"),auto:()=>s("botSettings.simple.decide"),edits:()=>s("approvalMode.edits.label"),custom:()=>s("botPanel.acts.custom")};function qr({bot:t,derived:n,onOpen:a,editingInstructions:o=!1,onEditInstructions:i}){const{state:l,dispatch:d,flushBotPatches:m}=B(),{capabilities:r,ready:c}=we(),p=ps(t),{servers:x}=ms(),k=la(Ye(t)),f=ca(),v=Os(t.id),j=Ss(),[N,w]=u.useState(null),{patch:b,approvalMode:h,engine:P}=n,L=t.name,D=()=>{N!==null&&N.trim()!==t.title.trim()&&b({title:N.trim()}),w(null)},$=P?.driverKind==="antigravityAgent"&&h==="auto"?"ask":h,A=[{value:"ask",label:Ze.ask(),tooltip:s("botSettings.simple.askHint")},{value:"full",label:Ze.full(),tooltip:s("botSettings.simple.fullHint")},...$==="ask"||$==="full"?[]:[{value:$,label:Ze[$](),disabled:!0,tooltip:$==="custom"?s("botPanel.acts.customHint"):void 0}]],H=y=>{y===h||y!=="ask"&&y!=="full"||d({type:"updateBot",botId:t.id,patch:{approvalMode:y,applyToAllThreads:!0}})},I=!c||da(r,l.config),g=ja(f,{turnsHere:I,canLive:!0}),T=I?null:pa(r,!!ua()?.speechStart,ma(l.config)),F=xa.map(y=>({value:y.id,label:s(y.label),disabled:y.id==="turns"&&T!==null,tooltip:y.id==="turns"&&T?`${T.label}. ${T.reason}`:y.id==="live"?s("call.mode.liveHint"):ha("turns")})),_=ga.map(y=>({value:y,label:s(Rt[y][0]),tooltip:s(Rt[y][1])})),K=()=>{const y=!t.notifications;y&&wa(),b({notifications:y})},J=t.alwaysAllow??[],Y=o||!!t.soulDrift,U=[...p.apps.filter(y=>y.scope!==null).map(y=>y.label),...x?us(x,t.mcpServers,t.id).map(y=>y.name):[]];return e.jsxs("div",{"data-panel-settings":!0,children:[e.jsx(hi,{bot:t}),e.jsx(M,{anchor:"instructions",children:Y?e.jsxs(me,{"data-panel-row":"soul",children:[e.jsx(gi,{bot:t,onPatch:b,simple:{label:s("botSettings.simple.instructions"),placeholder:s("botSettings.simple.instructionsPlaceholder",{name:L})}}),e.jsx(Ur,{bot:t}),o&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-panel-done":"soul",onClick:()=>{m(t.id),i?.(!1)},className:le,children:s("botSettings.simple.done")})})]}):e.jsxs("button",{type:"button","data-panel-edit":"soul","aria-label":`${s("botSettings.simple.edit")}: ${s("botSettings.simple.instructions")}`,onClick:()=>i?.(!0),className:O(X,"w-full text-left hover:bg-ink/[0.03]"),children:[e.jsx(te,{icon:Me}),e.jsx(ae,{title:s("botSettings.simple.instructions"),hint:e.jsx("span",{className:"line-clamp-1",children:fi(t.soul??"")||s("botPanel.instructionsHint",{name:L})})}),e.jsx(je,{size:15,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]})}),e.jsx(_r,{bot:t}),e.jsx(M,{anchor:"approval",children:e.jsxs(me,{"data-panel-row":"approval",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:es}),e.jsx(ae,{title:s("botSettings.simple.beforeActs",{name:L}),hint:t.busy?s("approvalMode.whileWorking"):void 0})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-approval-choice",label:s("botSettings.simple.beforeActs",{name:L}),value:$,onChange:H,options:A})}),k.choice&&e.jsxs("div",{"data-panel-row":"thread-approval",className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botPanel.thisConversation")}),e.jsx("span",{className:"ms-auto flex",children:e.jsx(fa,{choice:k.choice})})]}),J.length>0&&e.jsxs("div",{"data-panel-row":"always-allow",className:"flex min-w-0 flex-col gap-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botAccess.always.title")}),J.map(y=>e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",children:y}),e.jsx(Be,{"data-panel-action":`always-allow:${y}`,label:s("botAccess.always.remove",{entry:y}),onClick:()=>b({alwaysAllow:J.filter(z=>z!==y)})})]},y))]})]})}),e.jsx(Hr,{bot:t,onChange:y=>b({fallback:y})}),e.jsx(M,{anchor:"call",children:e.jsxs(me,{"data-panel-row":"call-mode",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:si}),e.jsx(ae,{title:s("call.mode.menu")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-call-mode",label:s("call.mode.menu"),value:g,onChange:ya,options:F})})]})}),e.jsxs(M,{anchor:"replies",children:[e.jsxs(me,{"data-panel-row":"reply-style",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:ba}),e.jsx(ae,{title:s("botSettings.replyStyle.title")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-reply-style",label:s("botSettings.replyStyle.title"),value:t.replyStyle??"default",onChange:y=>b({replyStyle:y}),options:_})})]}),e.jsx(rt,{"data-panel-row":"notifications",icon:va,title:s("voice.notifications.title"),color:t.color,checked:t.notifications,onChange:K})]}),e.jsxs(M,{anchor:"uses",children:[e.jsx(Q,{"data-panel-page":"apps",icon:ds,title:s("botPanel.appsRow"),value:U.length>0?U.join(", "):s("botPanel.appsNoneYet"),onClick:()=>a?.("apps")}),e.jsxs("label",{"data-panel-row":"job",className:O(X,"cursor-text"),children:[e.jsx(te,{icon:_i}),e.jsx("span",{className:"shrink-0 text-[14px] font-medium text-ink",children:s("botSettings.simple.job")}),e.jsx("input",{"data-panel-job":!0,value:N??t.title,placeholder:s("botSettings.simple.jobPlaceholder"),"aria-label":s("botSettings.simple.job"),maxLength:Qe.title,onChange:y=>w(y.target.value),onBlur:D,onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),y.currentTarget.blur()):y.key==="Escape"&&N!==null&&(y.preventDefault(),y.stopPropagation(),w(null))},className:"min-w-0 flex-1 bg-transparent text-right text-[13px] text-ink-secondary outline-none placeholder:text-ink-tertiary focus:text-ink"})]}),v&&e.jsxs("a",{"data-panel-row":"slack",href:v,target:"_blank",rel:"noopener noreferrer",className:O(X,"hover:bg-ink/[0.03]"),children:[e.jsx(te,{icon:Ps}),e.jsx(ae,{title:s("botPanel.page.slack"),hint:s("botSlack.manage")}),e.jsx(gs,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]}),j&&e.jsx(Q,{"data-panel-page":"visibility",icon:ts,title:s("botSettings.visibility.title"),value:yi(t.visibility),onClick:()=>a?.("visibility")})]}),t.yourAccess!=="view"&&!t.defaultBot&&e.jsx(Lr,{bot:t,className:"mt-3.5"}),e.jsx(bi,{bot:t,webhooksLink:!0,className:"mt-3.5"}),e.jsx(ka,{bot:t}),k.dialogs]})}const Wr=5;function Vr({bot:t,onChanged:n}){const{dispatch:a}=B(),[o,i]=u.useState([]),[l,d]=u.useState(null),[m,r]=u.useState(null),c=u.useCallback(async()=>{const[f,v]=await Promise.all([ot(t.id),ge(t.id)]);d(j=>f.lendingReview?{value:f.lendingReview,stale:j?.stale??!1}:null),i(v.slice(0,Wr))},[t.id]);u.useEffect(()=>{c().catch(()=>{})},[c,t.busy]);const p=f=>a({type:"error",message:f instanceof Error&&f.message?f.message:s("common.tryAgain")}),x=async f=>{r(f.id);try{await js(t.id,f.id),await n()}catch(v){p(v)}finally{r(null),await c().catch(()=>{})}},k=async f=>{r("review");try{await bs(t.id,f.value.token),d(null)}catch(v){v instanceof as&&v.status===409?(d({...f,stale:!0}),await c().catch(()=>{})):p(v)}finally{r(null)}};return e.jsxs(e.Fragment,{children:[l&&e.jsx(Ts,{changed:l.value.changed,stale:l.stale,busy:m!==null,onReviewed:()=>{k(l)}}),e.jsx(M,{children:e.jsx(rt,{"data-panel-row":"memory-upkeep",title:s("memory.upkeep.title"),checked:t.memoryUpkeep!==!1,color:t.color,onChange:()=>a({type:"updateBot",botId:t.id,patch:{memoryUpkeep:t.memoryUpkeep===!1}})})}),o.length>0&&e.jsx(M,{label:s("memory.changes"),children:e.jsx("div",{"data-panel-row":"memory-changes",className:"px-3.5 py-3",children:e.jsx(ct,{rows:o,botName:t.name,reverting:m,onRevert:f=>{x(f)}})})})]})}const Zr="flex flex-col gap-3",Zt="https://www.skills.sh";function ke(t,n){return t instanceof Error&&t.message?t.message:n}function Gr({bot:t,derived:n}){const{dispatch:a}=B(),o=ps(t),{servers:i,error:l}=ms(),{patch:d,canUseConnectedApps:m}=n,r=i?Oa(i,t.id):[],c=new Set(us(r,t.mcpServers,t.id).map(f=>f.name)),p=f=>{const v=Ta(t,o.connectedSlugs,f.slug,f.scope===null);Object.keys(v).length>0&&d(v)},x=f=>{t.busy||l||d({mcpServers:Ia(r,t.mcpServers,f)})},k=m?o.phase==="loading"?s("common.checking"):o.phase==="unknown"?s("botSettings.simple.appsUnknown"):o.apps.length===0?s("botSettings.simple.appsNone"):null:s("botSettings.simple.appsCannot",{name:t.name});return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[k&&e.jsx(V,{children:k}),m&&o.apps.map(f=>e.jsxs("div",{"data-simple-app":f.slug,className:X,children:[e.jsx(Ea,{card:f.card,className:"size-7 shrink-0"},`${f.card.logo}:${f.card.domain}`),e.jsx("div",{className:"min-w-0 flex-1 truncate text-[14px] font-medium text-ink",children:f.label}),e.jsx(wt,{color:t.color,checked:f.scope!==null,"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.label}),disabled:!!t.busy,onClick:()=>p(f),className:"disabled:cursor-not-allowed"})]},f.slug))]}),(r.length>0||l)&&e.jsxs(M,{label:s("connectors.tab.mcp"),children:[l&&e.jsx(V,{children:s("botAccess.mcpRefreshError")}),r.map(f=>e.jsxs("div",{"data-simple-mcp":f.name,className:X,children:[e.jsx(te,{icon:ni}),e.jsx(ae,{title:e.jsx("span",{className:"block truncate",children:f.name}),hint:f.enabled?f.offFor?.includes(t.id)?s("mcp.offFor",{bots:t.name}):void 0:s("botAccess.mcpDisabled")}),e.jsx(wt,{color:t.color,checked:c.has(f.name),"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.name}),disabled:!f.enabled||!!t.busy||l,onClick:()=>x(f.name),className:"disabled:cursor-not-allowed"})]},f.name))]}),e.jsx(M,{children:e.jsx(ue,{"data-panel-link":"add-app",icon:Ne,onClick:()=>Ra(a,t.id),children:s("botPanel.apps.connectAnother")})})]})}function Yr({bot:t,derived:n}){const{state:a,dispatch:o}=B(),[i,l]=u.useState(()=>n.botRoutines.length===0?"new":null);return e.jsxs(e.Fragment,{children:[e.jsx(Ii,{routines:n.botRoutines,runs:a.routineRuns,pausedBots:a.config?.pausedBots,heldBots:a.config?.heldBots,loading:a.routinesLoadState==="loading"&&n.botRoutines.length===0,error:a.routinesLoadState==="error",onOpen:l,onLogs:d=>o({type:"showRoutines",section:"logs",botId:t.id,routineId:d.id}),onToggle:d=>o({type:"updateRoutine",routineId:d.id,patch:{enabled:!d.enabled}})}),e.jsx(M,{children:e.jsx(ue,{"data-panel-action":"new-routine",icon:Ne,onClick:()=>l("new"),children:s("botPanel.routines.add")})}),e.jsx("p",{className:"mx-1 text-[13px] leading-normal text-ink-secondary",children:s("botPanel.routines.ask",{name:t.name})}),i&&e.jsx(Mi,{routine:i==="new"?void 0:i,bots:[t],lockedBotId:t.id,onClose:()=>l(null)},t.id)]})}function Jr({bot:t}){const n=$s(t),[a,o]=u.useState(""),[i,l]=u.useState(null),[d,m]=u.useState(!1),[r,c]=u.useState(null),p=t.memoryEnabled!==!1,x=n.docs?Bs(n.docs):null,k=n.docs?.find(w=>w.path===se)??null;u.useEffect(()=>l(null),[t.id,p]);const f=async w=>{if(d)return!1;m(!0),c(null);try{return await w()}catch(b){return c(ke(b,s("botPanel.library.memoryError"))),!1}finally{m(!1)}},v=(w,b)=>f(async()=>{const h=await lt(t.id,w.path,b,w.exists?w.hash:void 0,n.mine);return h.ok?(n.setDoc(h.doc),!0):(await n.reload(),c(s("memory.conflict.title",{name:t.name})),!1)}),j=w=>{const b=n.docs?.find(h=>h.path===w.path);b&&(w.line!==null?v(b,Cr(b.text,w.line)):f(async()=>(await ks(t.id,b.path,n.mine),await n.reload(),!0)))},N=async()=>{!k||!a.trim()||await v(k,Pr(k.text,a))&&o("")};return p&&i?.botId===t.id?e.jsx(Qr,{bot:t,doc:i.doc,mine:n.mine,onDone:w=>{w&&n.setDoc(w),l(null),c(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[p?n.error?e.jsx(V,{tone:"warn",children:s("botPanel.library.memoryError")}):x===null?e.jsx(V,{children:s("common.checking")}):x.length===0?e.jsx(V,{children:s("botPanel.memory.empty")}):x.map(w=>e.jsxs("div",{"data-memory-note":w.line??w.path,className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 text-[13px] leading-[1.45] text-ink",children:w.text}),e.jsx(Be,{label:s("botPanel.memory.forget"),disabled:d,onClick:()=>j(w)})]},`${w.path}:${w.line}:${w.text}`)):e.jsx(V,{children:s("botPanel.library.memoryOff",{name:t.name})}),r&&e.jsx(V,{tone:"warn",children:r})]}),p&&e.jsxs(M,{children:[e.jsx(xs,{"data-panel-form":"memory-add",value:a,placeholder:s("botPanel.memory.addPlaceholder",{name:t.name}),label:s("botPanel.memory.addPlaceholder",{name:t.name}),action:s("common.add"),disabled:d||k===null,onChange:o,onSubmit:()=>{N()}}),k&&e.jsx(ue,{"data-panel-link":"memory-text",icon:Me,onClick:()=>l({botId:t.id,doc:k}),children:s("botPanel.memory.editText")})]}),p&&!n.mine&&e.jsx(Vr,{bot:t,onChanged:n.reload})]})}function Qr({bot:t,doc:n,mine:a,onDone:o}){const[i,l]=u.useState({text:n.text,hash:n.hash}),[d,m]=u.useState(n.text),[r,c]=u.useState(null),[p,x]=u.useState(null),[k,f]=u.useState(!1),[v,j]=u.useState(null),N=u.useRef(!0);u.useEffect(()=>(N.current=!0,()=>{N.current=!1}),[]);const w=async h=>{f(!0),j(null);try{const P=await lt(t.id,n.path,d,h,a);if(!N.current)return;P.ok?o(P.doc):c({current:P.current,currentHash:P.currentHash})}catch(P){j(ke(P,s("botPanel.library.memoryError")))}finally{f(!1)}},b=()=>{r&&(x(h=>h===null||h===d?d:`${h}
13
+ `}function Bs(t){return t.flatMap(n=>{const a=Pr(n.text).map(i=>({path:n.path,...i}));if(a.length||n.path===se)return a;const o=n.text.split(`
14
+ `).map(i=>i.replace(/^#+\s*/,"").trim()).filter(Boolean).join(" ");return o?[{path:n.path,line:null,text:o}]:[]})}async function Rr(t,n){if(!n)return[await Ie(t,se)];const a=await rt(t,!0);return Promise.all([se,...a.topics.map(o=>o.path)].map(o=>Ie(t,o,!0)))}function $s(t){const n=!!B().state.config?.team,[a,o]=x.useState({botId:t.id,docs:null,error:!1}),i=t.memoryEnabled!==!1,l=async(r,c)=>{try{const p=await Rr(r,n);c?.()||o({botId:r,docs:p,error:!1})}catch{c?.()||o({botId:r,docs:null,error:!0})}},d=!!t.busy;x.useEffect(()=>{if(!i)return;let r=!1;return l(t.id,()=>r),()=>{r=!0}},[t.id,i,d,n]);const m=a.botId===t.id;return{docs:m?a.docs:null,error:m&&a.error,mine:n,setDoc:r=>o(c=>({botId:t.id,docs:(c.botId===t.id?c.docs??[]:[]).map(p=>p.path===r.path?r:p),error:!1})),reload:()=>l(t.id)}}function Tr(t,n=Je(t)){const a=[],o=[],i=new Set;for(const c of[...n].reverse()){const p=c.publishedPage;p?.state==="live"&&p.url&&!i.has(p.url)&&(i.add(p.url),a.push({messageId:c.id,title:p.title||p.url,url:p.url})),c.kind==="app"&&c.app?.doc&&o.push({messageId:c.id,title:c.app.title})}const l=Ii(t),d=[],m=new Set;for(const c of l.values())m.has(c.file.path)||(m.add(c.file.path),d.push(c));const r=Ai(t).filter(c=>!l.has(c));return{pages:a,apps:o,shared:d,unshared:r}}const Ir=t=>t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);function Fs({bot:t,onOpen:n}){const{dispatch:a}=B(),o=Le(),{capabilities:i}=we(),l=Wn(),d=!rs(os,!0),m=ws(t),r=$s(t),{pages:c,apps:p,shared:u,unshared:k}=x.useMemo(()=>Tr(t),[t]),f=b=>{a({type:"focusMessage",threadId:t.threadId,messageId:b}),d&&a({type:"toggleSettings",open:!1})},v=m.skills.filter(Ns).length,j=r.docs?Bs(r.docs).length:null,N=t.memoryEnabled===!1?s("botPanel.memory.off"):j===null?r.error?s("botPanel.memory.nothingYet"):void 0:j===0?s("botPanel.memory.nothingYet"):j===1?s("botPanel.memory.note"):s("botPanel.memory.notes",{count:j}),w=e.jsxs(M,{anchor:"keeps",children:[e.jsx(Q,{"data-panel-page":"memory",icon:Xt,title:s("botPanel.memoryRow"),value:N,onClick:()=>n("memory")}),e.jsx(Q,{"data-panel-page":"skills",icon:Vn,title:s("botSettings.simple.skills"),value:m.loading?void 0:v>0?v:s("botPanel.none"),onClick:()=>n("skills")}),o&&e.jsx(Q,{"data-panel-page":"plugins",icon:Qt,title:s("plugins.botMenu"),onClick:()=>n("plugins")}),e.jsx(Q,{"data-panel-page":"folder",icon:Zn,title:s("computer.files.folder"),value:t.cwd?at(t.cwd,i.host?.homeDir):s("botPanel.folder.private"),onClick:()=>n("folder")})]});return c.length+p.length+u.length+k.length===0?e.jsxs("div",{"data-panel-tabpanel":"library",children:[e.jsx("p",{"data-panel-empty":"library",className:"px-3 py-7 text-center text-[13px] leading-[18px] text-ink-tertiary",children:s("botPanel.library.empty")}),w]}):e.jsxs("div",{"data-panel-tabpanel":"library",children:[c.length>0&&e.jsx(M,{label:s("botPanel.library.pages"),anchor:"pages",children:c.map(b=>e.jsx(Q,{"data-panel-row":"page",icon:Gn,title:e.jsx("span",{className:"block truncate",children:b.title}),hint:e.jsx("span",{className:"block truncate",children:b.url}),onClick:()=>l(b.url)},b.url))}),p.length>0&&e.jsx(M,{label:s("botPanel.library.apps"),anchor:"apps",children:p.map(b=>e.jsx(Q,{"data-panel-row":"app",icon:ds,title:e.jsx("span",{className:"block truncate",children:b.title}),onClick:()=>f(b.messageId)},b.messageId))}),u.length+k.length>0&&e.jsxs("section",{"data-panel-card":"files",children:[e.jsx(Re,{children:s("botPanel.library.files")}),e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[u.map(b=>e.jsx("li",{className:"min-w-0",children:e.jsx(Yn,{file:b.file,message:b.message,linked:b.file.linked,className:"w-full max-w-none"})},`${b.message.messageId}:${b.file.path}`)),k.map(b=>e.jsxs("li",{title:s("computer.files.notSharedHint"),className:"flex min-w-0 items-center gap-2 rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx(Me,{size:14,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:Ir(b)}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-tertiary",children:s("computer.files.notShared")})]},b))]})]}),e.jsx("p",{className:"mt-3 text-center text-[12px] text-ink-tertiary",children:s("botPanel.library.scope")}),w]})}function Ar({bot:t,browserEnabled:n,onOpenBrowser:a}){const{state:o}=B(),i=Le(),l=t.browserProfile??"",d=(o.config?.browserProfiles??[]).find(p=>p.id===l),m=l==="guest",r=d?.browser==="chrome"&&o.config?.browserEngine?.myChrome===!0,c=l&&!m?o.bots.filter(p=>p.browserProfile===l).map(p=>p.name):[t.name];return e.jsx(M,{anchor:"logins",children:n?m?e.jsx(V,{children:s("settings.profiles.temporaryHint")}):r?e.jsx(V,{children:s("settings.profiles.myChromeHint")}):e.jsxs(e.Fragment,{children:[i!==!1&&(l===""||d)&&e.jsx(me,{children:e.jsx($i,{bare:!0,target:{bot:t.id},sharedBy:c,disabled:!!t.busy},`${t.id}:${l}`)}),e.jsx(V,{children:s("botSettings.simple.loginsHint",{name:t.name})}),e.jsx(ue,{"data-panel-action":"add-login",icon:Ne,onClick:a,children:s("botSettings.simple.addLogin")})]}):e.jsx(V,{children:s("botSettings.simple.loginsOff",{name:t.name})})})}const Mr=[["all",()=>S("Tất cả","All")],["added",()=>S("Bot đang có","On this bot")],["more",()=>S("Chưa thêm","Not added")]],Lr=t=>({bundled:S("Có sẵn","Built in"),library:S("Đã tải về","Downloaded"),imported:S("Từ máy tính","From this computer")})[t],Ve="inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50";async function Ut(t,n){const a=await fetch(t,n===void 0?void 0:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error??S(`Lỗi ${a.status}`,`Error ${a.status}`));return o.skills??[]}function Br({botId:t,botName:n,onClose:a,onOpenSettings:o}){const[i,l]=x.useState(null),[d,m]=x.useState(""),[r,c]=x.useState("all"),[p,u]=x.useState(""),[k,f]=x.useState(""),v=`/api/limix/skill-store/${encodeURIComponent(t)}`;x.useEffect(()=>{let h=!1;return Ut(v).then(P=>{h||l(P)}).catch(P=>{h||(l([]),f(P.message))}),()=>{h=!0}},[v]),x.useEffect(()=>{const h=P=>{P.key==="Escape"&&a()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[a]);const j=x.useMemo(()=>{const h=d.trim().toLowerCase();return(i??[]).filter(P=>(r==="all"||(r==="added"?P.added:!P.added))&&(!h||`${P.name} ${P.description}`.toLowerCase().includes(h)))},[i,d,r]),N=async(h,P)=>{if(!p){u(h.name),f("");try{l(await Ut(v,{name:h.name,kind:h.kind,add:P}))}catch(L){f(L instanceof Error?L.message:S("Không đổi được kỹ năng này.","Couldn't change this skill."))}finally{u("")}}},w=(i??[]).filter(h=>h.added).length,b=e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onMouseDown:h=>h.stopPropagation(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"limix-skill-store-title",className:"flex max-h-full w-full max-w-[640px] flex-col rounded-2xl border border-hairline/50 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pb-3 pt-5",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"limix-skill-store-title",className:"text-[17px] font-semibold text-ink",children:S("Kho kỹ năng","Skills Store")}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:S(`Chọn kỹ năng cho ${n}. Bot sẽ nhận hướng dẫn của những kỹ năng bạn thêm. Để dùng một kỹ năng, gõ dấu / rồi nhập tên kỹ năng trong khung chat.`,`Pick skills just for ${n}. Only added skills go into the bot's prompt, so it never gets overloaded. Type /skill-name in chat to call one.`)})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":S("Đóng","Close"),className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(st,{size:16})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-6 pb-3",children:[e.jsxs("label",{className:"flex min-w-[200px] flex-1 items-center gap-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx(tt,{size:14,className:"text-ink-tertiary"}),e.jsx("input",{value:d,onChange:h=>m(h.target.value),placeholder:S("Tìm kỹ năng…","Search skills…"),"aria-label":S("Tìm kỹ năng","Search skills"),className:"w-full bg-transparent text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsx("div",{className:"flex gap-1",role:"tablist","aria-label":S("Lọc kỹ năng","Filter skills"),children:Mr.map(([h,P])=>e.jsxs("button",{type:"button",role:"tab","aria-selected":r===h,onClick:()=>c(h),className:`rounded-lg px-2.5 py-1.5 text-[13px] ${r===h?"bg-raised text-ink":"text-ink-secondary hover:bg-raised"}`,children:[P(),h==="added"&&i?` ${w}`:""]},h))})]}),k&&e.jsx("p",{role:"alert",className:"mx-6 mb-2 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:k}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6",children:i===null?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-[13px] text-ink-secondary",children:[e.jsx(Ee,{size:14,className:"animate-spin"}),S("Đang tải kho…","Loading the store…")]}):j.length===0?e.jsx("p",{className:"py-6 text-[13px] text-ink-secondary",children:i.length===0?S("Kho chưa có kỹ năng nào.","The store has no skills yet."):S("Không tìm thấy kỹ năng phù hợp.","No matching skills.")}):e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40",children:j.map(h=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[13px] text-ink",children:h.name}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:h.core?S("Kỹ năng gốc","Core skill"):Lr(h.kind)}),h.warnings>0&&e.jsxs("span",{className:"text-[12px] text-warning",children:[h.warnings," ",S("cảnh báo","warnings")]})]}),e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[12px] leading-relaxed text-ink-secondary",children:h.description})]}),h.core?e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 px-1 py-1.5 text-[12px] text-ink-secondary",children:[e.jsx(pt,{size:14}),S("Luôn bật","Always on")]}):h.added?e.jsxs("button",{type:"button",className:Ve,disabled:!!p,onClick:()=>{N(h,!1)},"aria-label":S(`Bỏ ${h.name} khỏi bot`,`Remove ${h.name} from this bot`),children:[p===h.name?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(pt,{size:14}),S("Đã thêm","Added")]}):e.jsxs("button",{type:"button",className:Ve,disabled:!!p||!h.ready,onClick:()=>{N(h,!0)},"aria-label":S(`Thêm ${h.name} cho bot`,`Add ${h.name} to this bot`),children:[p===h.name?e.jsx(Ee,{size:14,className:"animate-spin"}):e.jsx(Ne,{size:14}),S("Thêm","Add")]})]},`${h.kind}:${h.name}`))})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 px-6 pb-5 pt-3",children:[e.jsx("p",{className:"text-[12px] text-ink-tertiary",children:S('Bấm "Đã thêm" để bỏ kỹ năng khỏi bot này.','Press "Added" to remove a skill from this bot.')}),e.jsx("button",{type:"button",className:Ve,onClick:o,children:S("Tải thêm kỹ năng","Get more skills")})]})]})});return typeof document>"u"?b:fs.createPortal(b,document.body)}const ve=()=>window.ogb?.limixMessenger,qt=[{kind:"telegram",label:"Telegram",placeholder:"123456789:AA…",howTo:()=>S("Tạo bot với @BotFather (lệnh /newbot), rồi dán token vào đây.","Make a bot with @BotFather (/newbot), then paste its token here."),where:t=>`@${t.username}`,linkFrom:t=>S(`Nhắn cho @${t.username}: `,`Send @${t.username}: `)},{kind:"discord",label:"Discord",placeholder:"MTA…",howTo:()=>S("Vào discord.com/developers → New Application → Bot → Reset Token, dán token vào đây. Mời bot vào server: OAuth2 → URL Generator → chọn bot và quyền Send Messages. Trong server, gọi bot bằng @tên-bot.","At discord.com/developers: New Application → Bot → Reset Token, paste it here. Invite it with OAuth2 → URL Generator (bot, Send Messages). In a server, call it with @its-name."),where:t=>`@${t.username}`,linkFrom:()=>S("Nhắn riêng cho bot trên Discord: ","Send the bot a direct message on Discord: ")},{kind:"zalo",label:"Zalo",howTo:()=>S("Quét mã QR bằng ứng dụng Zalo của tài khoản sẽ làm bot.","Scan the QR code with the Zalo app of the account that will be the bot."),note:()=>S("Nên dùng tài khoản Zalo phụ: đây là cách đăng nhập không chính thức (như Zalo Web), Zalo có thể khoá tài khoản. Mở Zalo Web bằng tài khoản này ở nơi khác sẽ ngắt bot.","Use a spare Zalo account: this sign-in is unofficial (like Zalo Web) and Zalo may lock the account. Opening Zalo Web with it elsewhere disconnects the bot."),where:t=>t.name||t.username||"Zalo",linkFrom:()=>S("Từ Zalo của bạn, nhắn cho tài khoản bot: ","From your own Zalo, message the bot's account: ")},{kind:"facebook",label:"Facebook Page",placeholder:"EAA…",howTo:()=>S("Dán Page Access Token: developers.facebook.com → tạo app → thêm Messenger → Access Tokens → chọn Page → Generate token.","Paste a Page access token: developers.facebook.com → create an app → add Messenger → Access Tokens → pick the Page → Generate token."),note:()=>S("Bot trả lời khách nhắn vào Page sau khoảng 10–20 giây. Muốn trả lời mọi khách, app Meta cần được duyệt quyền pages_messaging.","The bot answers people who message the Page within about 10–20 seconds. To answer everyone, the Meta app needs pages_messaging approved."),where:t=>t.name||"Page",linkFrom:()=>S("Từ Facebook cá nhân, nhắn cho Page: ","From your own Facebook, message the Page: ")},{kind:"messenger",label:"Messenger",howTo:()=>S("Đăng nhập Facebook trong cửa sổ của app (nhập cả mã PIN khôi phục tin nhắn nếu Facebook hỏi), rồi đóng cửa sổ. App giữ một cửa sổ Facebook ẩn, đọc tin mới và gõ câu trả lời.","Sign in to Facebook in the app's window (enter the chat-restore PIN if Facebook asks), then close it. The app keeps a hidden Facebook window that reads new messages and types the replies."),note:()=>S("Thử nghiệm, tài khoản cá nhân. Chỉ chạy khi app đang mở trên máy này. Nên dùng tài khoản phụ: Facebook không có cách chính thức cho tài khoản cá nhân và có thể khoá tài khoản. Ai nhắn cũng được trả lời ở chế độ an toàn.","Beta, personal accounts. Runs only while the app is open on this computer. Use a spare account: Facebook has no official way for personal accounts and may lock it. Everyone is answered in safe mode."),where:()=>S("tài khoản Facebook đã đăng nhập","the signed-in Facebook account"),linkFrom:()=>""}],ne="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50";function $r({bot:t,className:n}){const[a,o]=x.useState("telegram"),[i,l]=x.useState({});x.useEffect(()=>{let r=!0;l({});for(const c of qt.filter(p=>p.kind!=="messenger"||ve()))Z(`/api/bots/${t.id}/${c.kind}`).then(p=>{r&&l(u=>({...u,[c.kind]:p}))}).catch(()=>{});return()=>{r=!1}},[t.id]);const d=qt.filter(r=>r.kind!=="messenger"||ve()),m=d.find(r=>r.kind===a);return e.jsxs("div",{className:O("rounded-xl bg-card p-4",n),"data-testid":"channels-card",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:S("Kênh chat","Chat channels")}),e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:S(`Cho ${t.name} trả lời tin nhắn ngoài app.`,`Let ${t.name} answer messages outside the app.`)}),e.jsx("div",{role:"tablist",className:"mt-3 flex flex-wrap gap-1.5",children:d.map(r=>{const c=i[r.kind];return e.jsxs("button",{type:"button",role:"tab","aria-selected":a===r.kind,onClick:()=>o(r.kind),"data-testid":`channel-tab-${r.kind}`,className:O("flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-[13px]",a===r.kind?"bg-control text-ink":"text-ink-secondary hover:bg-raised-hover"),children:[c?.connected&&e.jsx("span",{className:O("size-1.5 rounded-full",c.error?"bg-danger":c.enabled?"bg-success":"bg-ink-tertiary")}),r.label]},r.kind)})}),e.jsx(Fr,{bot:t,channel:m,view:i[a],onView:r=>l(c=>({...c,[a]:r}))},`${t.id}:${a}`)]})}function Fr({bot:t,channel:n,view:a,onView:o}){const i=`/api/bots/${t.id}/${n.kind}`,[l,d]=x.useState(""),[m,r]=x.useState(null),[c,p]=x.useState(!1),[u,k]=x.useState(null),f=!!(a?.login&&!a.login.error&&!a.connected);x.useEffect(()=>{if(!f&&!m)return;let N=!0;const w=setInterval(()=>{Z(i).then(b=>{N&&(o(b),b.linkExpiresAt||r(null))}).catch(()=>{})},2e3);return()=>{N=!1,clearInterval(w)}},[f,m,i,o]);const v=async N=>{p(!0),k(null);try{const{code:w,...b}=await N();o(b),w&&r(w)}catch(w){k(w instanceof Error?w.message:String(w))}finally{p(!1)}},j=(N,w="")=>v(()=>Z(`${i}${w}`,{method:"POST",body:JSON.stringify(N??{})}));return a?e.jsxs("div",{className:"mt-3 text-[13px]","data-testid":`channel-${n.kind}`,children:[!a.connected&&e.jsxs("div",{className:"flex flex-col gap-2 text-ink-secondary",children:[e.jsx("span",{children:n.howTo()}),n.note&&e.jsx("span",{className:"text-[12px]",children:n.note()}),n.placeholder?e.jsxs("form",{className:"flex gap-2",onSubmit:N=>{N.preventDefault(),l.trim()&&j({token:l.trim()}).then(()=>d(""))},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:l,onChange:N=>d(N.target.value),placeholder:n.placeholder,"aria-label":S(`Token ${n.label}`,`${n.label} token`),className:"min-w-0 flex-1 rounded-lg bg-inset px-3 py-1.5 font-mono text-[13px] text-ink outline-none","data-testid":`channel-token-${n.kind}`}),e.jsx("button",{type:"submit",disabled:c||!l.trim(),className:ne,"data-testid":`channel-connect-${n.kind}`,children:S("Kết nối","Connect")})]}):n.kind==="messenger"?e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:c,onClick:()=>{v(async()=>await ve().signIn(t.id))},"data-testid":"channel-signin-messenger",children:S("Mở cửa sổ đăng nhập Facebook","Open the Facebook sign-in window")}):e.jsx(Dr,{view:a,busy:c,start:()=>{j({},"/login")},cancel:()=>{v(()=>Z(`${i}/login`,{method:"DELETE"}))}})]}),a.connected&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsx("span",{children:S(`${t.name} trả lời tin nhắn gửi tới ${n.where(a)}.`,`${t.name} answers messages sent to ${n.where(a)}.`)}),e.jsx(be,{"aria-label":S(`Bật ${n.label}`,`${n.label} on`),checked:a.enabled===!0,disabled:c,onClick:()=>{j({enabled:!a.enabled})},"data-testid":`channel-switch-${n.kind}`})]}),n.note&&(n.kind==="facebook"||n.kind==="messenger")&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:n.note()}),n.kind==="messenger"?e.jsx("button",{type:"button",className:O(ne,"self-start"),onClick:()=>{ve()?.show(t.id)},children:S("Mở cửa sổ Messenger của bot","Show the bot's Messenger window")}):e.jsxs("div",{className:"flex flex-col gap-2 text-ink-secondary",children:[a.owner&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:S(`Chủ bot: ${a.owner}`,`Owner: ${a.owner}`)}),e.jsx("button",{type:"button",className:ne,disabled:c,onClick:()=>{j({},"/unlink")},children:S("Bỏ liên kết","Unlink")})]}),a.admins?.map(N=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:s("channels.admin.account",{name:N.name,id:N.id})}),e.jsx("button",{type:"button",className:ne,disabled:c,"aria-label":s("channels.admin.removeNamed",{name:N.name,id:N.id}),onClick:()=>{j({id:N.id},"/remove-admin")},children:s("channels.admin.remove")})]},N.id)),e.jsx("span",{children:s("channels.admin.explain")}),m&&a.linkExpiresAt?e.jsxs("span",{className:"text-ink","data-testid":`channel-code-${n.kind}`,children:[n.linkFrom(a),e.jsxs("code",{className:"rounded bg-inset px-1.5 py-0.5 font-mono",children:["/link ",m]}),S(" (hết hạn sau 15 phút)"," (expires in 15 minutes)")]}):e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:c,onClick:()=>{j({},"/link")},"data-testid":`channel-link-${n.kind}`,children:a.owner?s("channels.admin.invite"):S("Tạo mã liên kết","Make a link code")})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsxs("span",{children:[S("Trả lời cả người khác","Answer other people too"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:n.kind==="zalo"?S("Người khác có thể nhắn riêng cho bot với quyền khách.","Other people can message the bot privately as guests."):S("Người khác và nhóm nhắn được bot ở chế độ an toàn: không dùng công cụ, không thấy cuộc trò chuyện của bạn.","Others and groups can write to the bot in safe mode: no tools, none of your conversations.")})]}),e.jsx(be,{"aria-label":S("Trả lời cả người khác","Answer other people too"),checked:a.access==="everyone",disabled:c,onClick:()=>{j({access:a.access==="everyone"?"owner":"everyone",...a.groupMentions!==void 0?{groupMentions:a.groupMentions}:{}})},"data-testid":`channel-everyone-${n.kind}`})]}),n.kind==="zalo"&&e.jsxs("label",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsxs("span",{children:[S("Trả lời khi được @gọi trong nhóm","Reply to @mentions in groups"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:S("Chủ bot đã liên kết luôn có toàn quyền khi gọi bot trong nhóm. Bật tùy chọn này để các thành viên khác cũng có thể gọi bot với quyền khách.","The linked owner always has full access when mentioning the bot in a group. Turn this on to let other members mention it with guest access.")})]}),e.jsx(be,{"aria-label":S("Trả lời khi được @gọi trong nhóm","Reply to @mentions in groups"),checked:a.groupMentions??a.access==="everyone",disabled:c,onClick:()=>{j({groupMentions:!(a.groupMentions??a.access==="everyone")})},"data-testid":"channel-zalo-group-mentions"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",className:ne,disabled:c,onClick:()=>{v(async()=>{const N=await Z(i,{method:"DELETE"});return n.kind==="messenger"&&await ve()?.signOut(t.id),N})},"data-testid":`channel-remove-${n.kind}`,children:S("Gỡ kết nối","Disconnect")})})]}),(u||a.error)&&e.jsx("div",{role:"alert",className:"mt-2 text-[13px] text-danger",children:u??a.error})]}):e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:"…"})}function Dr({view:t,busy:n,start:a,cancel:o}){const i=t.login;return!i||i.error?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i?.error&&e.jsx("span",{className:"text-danger",children:i.error}),e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:n,onClick:a,"data-testid":"channel-qr-zalo",children:S("Tạo mã QR đăng nhập","Show a sign-in QR code")})]}):e.jsxs("div",{className:"flex items-start gap-3",children:[i.qr?e.jsx("img",{src:i.qr,alt:S("Mã QR đăng nhập Zalo","Zalo sign-in QR code"),className:"size-44 rounded-lg bg-white p-1.5","data-testid":"channel-qr-image"}):e.jsx("div",{className:"flex size-44 items-center justify-center rounded-lg bg-inset",children:"…"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-ink",children:i.scanned?S(`${i.scanned} đã quét. Xác nhận đăng nhập trong ứng dụng Zalo.`,`${i.scanned} scanned it. Confirm the sign-in in the Zalo app.`):S("Mở Zalo trên điện thoại → biểu tượng quét mã → quét mã này.","Open Zalo on the phone → scan icon → scan this code.")}),e.jsx("button",{type:"button",className:O(ne,"self-start"),onClick:o,children:S("Huỷ","Cancel")})]})]})}const zr=5,Hr={instanceId:"",model:""},Ds=(t,n)=>`${t}\0${n}`,_r=new Set;function Wt({bot:t,current:n,exclude:a,onPick:o,label:i,title:l,buttonRef:d,className:m,children:r,...c}){const{state:p,dispatch:u,refreshInstances:k,refreshModels:f}=B(),[v,j]=x.useState(!1),[N,w]=x.useState(""),[b,h]=x.useState(()=>new Set),[P,L]=x.useState(!1),[D,$]=x.useState(null),[A,H]=x.useState(null),I=x.useRef(null),g=d??I,T=x.useRef(null),F=x.useRef(null),_=x.useRef(!1),K=x.useId(),J=oi(v),Y=x.useRef({contains:E=>[g.current,T.current].some(q=>q?.contains(E))});sa(v,Y,()=>j(!1)),x.useLayoutEffect(()=>{if(!v)return;const E=q=>{if(q?.type==="scroll"&&q.target instanceof Node&&T.current?.contains(q.target))return;const G=g.current?.getBoundingClientRect(),W=T.current;!G||!W||H(de=>ia(G,{width:vt,height:W.offsetHeight},{width:window.innerWidth,height:window.innerHeight},de??void 0))};return E(),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0),()=>{window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0)}},[v,g]),x.useEffect(()=>{if(!v||!A||!_.current)return;_.current=!1;const E=T.current;(E?.querySelector("[data-menu-search]")??E?.querySelector("[data-current-model]")??E?.querySelector("[data-menu-row]:not(:disabled)")??E)?.focus({preventScroll:!0})},[v,A]);const U=E=>{j(!1),E&&g.current?.focus({preventScroll:!0})},y=()=>{w(""),h(new Set),H(null),_.current=!0,j(!0),L(!0),k().catch(()=>{}).finally(()=>L(!1))},z=E=>{D||($(E.instanceId),f(E.instanceId).catch(()=>{}).finally(()=>$(null)))},ce=()=>{U(!1),u({type:"toggleAppSettings",open:!0,section:"engines"})},xe=()=>{const E=oa(p.instances,n?.instanceId).flatMap(W=>{const de=W.models.options.filter(Se=>!a.has(Ds(W.instanceId,Se.id)));return de.length===W.models.options.length?[W]:de.length?[{...W,models:{...W.models,options:de}}]:[]}),q=la({instances:p.instances,listed:E,selection:n??Hr,bot:{name:t.name,selection:t.modelSelection},query:N,expanded:b,probing:_r,loading:P,refreshing:D}),G=q.groups.map(W=>W.instance.instanceId===t.modelSelection.instanceId?{...W,note:s("botPanel.backups.sameAccount")}:W);return{...q,groups:G,...n?{}:{current:null}}},ye=E=>{if(!(E.nativeEvent.isComposing||E.defaultPrevented)){if(E.key!=="Escape")return ra(E,{query:N,typed:F,close:()=>U(!0)});E.preventDefault(),E.stopPropagation(),N?w(""):U(!0)}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",...c,"aria-label":i,title:l,"aria-haspopup":"dialog","aria-expanded":v,"aria-controls":v?K:void 0,onClick:()=>v?U(!1):y(),onKeyDown:E=>{E.key==="Escape"&&v?(E.preventDefault(),E.stopPropagation(),U(!1)):(E.key==="ArrowDown"||E.key==="ArrowUp")&&!v&&(E.preventDefault(),y())},className:m,children:r}),J.shown&&fs.createPortal(e.jsx("div",{ref:T,id:K,"data-backup-menu":!0,role:"dialog","aria-label":s("botPanel.backups.choose"),"aria-modal":"false",tabIndex:-1,...J.exitProps,onKeyDown:ye,onPointerMove:na,style:{position:"fixed",left:A?.left??0,top:A?.top,bottom:A?.bottom,width:A?.width??vt,maxHeight:A?.maxHeight,transformOrigin:A?.origin,visibility:A?void 0:"hidden"},className:O("menu-surface z-[80] flex flex-col overflow-hidden",J.className),children:e.jsx(aa,{menu:xe(),query:N,bot:t,botModel:{label:"",title:""},idPrefix:K,onQuery:w,onPick:(E,q)=>{E.policy||(o({instanceId:E.instanceId,model:q}),U(!0))},onPickCurrent:()=>U(!0),onFollowBot:()=>U(!0),onToggle:E=>h(q=>{const G=new Set(q);return G.delete(E.instanceId)||G.add(E.instanceId),G}),onSetUp:ce,onCheckAgain:z,onManage:ce})}),document.body)]})}function Kr({bot:t,onChange:n}){const{state:a}=B(),o=t.fallback??[],i=x.useRef(null),l=m=>new Set([t.modelSelection,...o.filter((r,c)=>c!==m)].map(r=>Ds(r.instanceId,r.model))),d=m=>{const r=a.instances.find(u=>u.instanceId===m.instanceId),c=r?.models.options.find(u=>u.id===m.model),p=Xn(r,m.model);return{instance:r,name:p,short:r&&c?ea(c.label,ta(r)):p}};return e.jsx(M,{anchor:"backups",children:e.jsxs(me,{"data-panel-row":"backups",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:Jn}),e.jsx(ae,{title:s("botPanel.backups.title")})]}),e.jsx("p",{className:"-mt-1 pl-[38px] text-[13px] leading-[1.35] text-ink-secondary",children:s("botPanel.backups.hint",{name:t.name})}),o.length>0&&e.jsx("ol",{"aria-label":s("botPanel.backups.title"),className:"flex flex-col gap-1 pl-[38px]",children:o.map((m,r)=>{const{instance:c,name:p,short:u}=d(m);return e.jsxs("li",{"data-backup":m.instanceId,className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"w-3 shrink-0 text-[12px] tabular-nums text-ink-tertiary","aria-hidden":"true",children:r+1}),e.jsxs(Wt,{bot:t,current:m,exclude:l(r),onPick:k=>n(o.map((f,v)=>v===r?k:f)),label:s("botPanel.backups.row",{position:r+1,model:p}),title:c?`${c.displayName} · ${p}`:p,"data-panel-action":"backup-change",className:"group flex h-8 min-w-0 flex-1 items-center gap-2 rounded-[8px] bg-ink/[0.04] pl-2.5 pr-2 text-left text-[13px] text-ink hover:bg-ink/[0.07] aria-expanded:bg-ink/[0.08]",children:[c?e.jsx(Qn,{instance:c,size:14,subtle:!0}):e.jsx("span",{className:"size-3.5 shrink-0 rounded-full bg-ink/[0.08]","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:u}),!c&&e.jsx("span",{className:"shrink-0 text-[12px] text-warning",children:s("model.simple.unavailable")}),e.jsx(fe,{size:12,strokeWidth:2,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary group-hover:text-ink-secondary"})]}),e.jsx(Be,{"data-panel-action":"backup-remove",label:s("botPanel.backups.remove",{model:p}),onClick:()=>{n(o.filter((k,f)=>f!==r)),i.current?.focus({preventScroll:!0})}})]},r)})}),o.length<zr&&e.jsx("div",{className:"pl-[38px]",children:e.jsxs(Wt,{bot:t,current:null,exclude:l(null),onPick:m=>n([...o,m]),label:s("model.fallback.add"),buttonRef:i,"data-panel-action":"backup-add",className:O(le,"aria-expanded:bg-raised-hover"),children:[e.jsx(Ne,{size:14,"aria-hidden":"true"}),s("model.fallback.add")]})})]})})}function Ur({bot:t}){const{dispatch:n}=B(),[a,o]=x.useState(!1),[i,l]=x.useState(!1),[d,m]=x.useState(0),r=t.memoryEnabled!==!1&&t.memoryUpkeep!==!1;if(x.useEffect(()=>{if(!r)return;let p=!0;return Z(`/api/bots/${t.id}/system-prompt`).then(u=>{p&&o(u.heavy===!0)},()=>{}),()=>{p=!1}},[t.id,r,d]),!r||!a)return null;const c=async()=>{l(!0);try{await vs(t.id)}catch(p){n({type:"error",message:p instanceof Error&&p.message?p.message:s("common.tryAgain")})}finally{l(!1),m(p=>p+1)}};return e.jsx(M,{anchor:"heavy",children:e.jsxs("div",{"data-panel-row":"heavy",className:X,children:[e.jsx(te,{icon:ca}),e.jsx(ae,{title:s("botPanel.heavy")}),e.jsx("button",{type:"button","data-panel-action":"tidy-memory",disabled:i,onClick:()=>{c()},className:le,children:i?s("memory.upkeep.tidying"):s("botPanel.tidyMemory")})]})})}const qr=5;function Wr({bot:t}){const{dispatch:n,flushBotPatches:a}=B(),[o,i]=x.useState([]),[l,d]=x.useState(null),m=x.useCallback(()=>Ot(t.id).then(c=>i(c.rows.slice(0,qr)),()=>{}),[t.id]);if(x.useEffect(()=>{m()},[m,t.soul]),!o.length)return null;const r=async c=>{if(!l){d(c.id);try{await a(t.id);const{revision:p}=await Ot(t.id);await gi(t.id,c.id,p)}catch(p){n({type:"error",message:p instanceof Error&&p.message?p.message:s("botOverview.undoFailed")})}finally{d(null),await m()}}};return e.jsxs("div",{"data-panel-row":"soul-changes",className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:s("memory.changes")}),e.jsx(lt,{rows:o,botName:t.name,reverting:l,onRevert:c=>{r(c)}})]})}const Ze={ask:()=>s("botSettings.simple.ask"),full:()=>s("botSettings.simple.justDoIt"),auto:()=>s("botSettings.simple.decide"),edits:()=>s("approvalMode.edits.label"),custom:()=>s("botPanel.acts.custom")};function Vr({bot:t,derived:n,onOpen:a,editingInstructions:o=!1,onEditInstructions:i}){const{state:l,dispatch:d,flushBotPatches:m}=B(),{capabilities:r,ready:c}=we(),p=ps(t),{servers:u}=ms(),k=da(Ye(t)),f=pa(),v=Os(t.id),j=Ss(),[N,w]=x.useState(null),{patch:b,approvalMode:h,engine:P}=n,L=t.name,D=()=>{N!==null&&N.trim()!==t.title.trim()&&b({title:N.trim()}),w(null)},$=P?.driverKind==="antigravityAgent"&&h==="auto"?"ask":h,A=[{value:"ask",label:Ze.ask(),tooltip:s("botSettings.simple.askHint")},{value:"full",label:Ze.full(),tooltip:s("botSettings.simple.fullHint")},...$==="ask"||$==="full"?[]:[{value:$,label:Ze[$](),disabled:!0,tooltip:$==="custom"?s("botPanel.acts.customHint"):void 0}]],H=y=>{y===h||y!=="ask"&&y!=="full"||d({type:"updateBot",botId:t.id,patch:{approvalMode:y,applyToAllThreads:!0}})},I=!c||ma(r,l.config),g=Na(f,{turnsHere:I,canLive:!0}),T=I?null:ua(r,!!ha()?.speechStart,xa(l.config)),F=ga.map(y=>({value:y.id,label:s(y.label),disabled:y.id==="turns"&&T!==null,tooltip:y.id==="turns"&&T?`${T.label}. ${T.reason}`:y.id==="live"?s("call.mode.liveHint"):fa("turns")})),_=ya.map(y=>({value:y,label:s(Et[y][0]),tooltip:s(Et[y][1])})),K=()=>{const y=!t.notifications;y&&Sa(),b({notifications:y})},J=t.alwaysAllow??[],Y=o||!!t.soulDrift,U=[...p.apps.filter(y=>y.scope!==null).map(y=>y.label),...u?us(u,t.mcpServers,t.id).map(y=>y.name):[]];return e.jsxs("div",{"data-panel-settings":!0,children:[e.jsx(fi,{bot:t}),e.jsx(M,{anchor:"instructions",children:Y?e.jsxs(me,{"data-panel-row":"soul",children:[e.jsx(yi,{bot:t,onPatch:b,simple:{label:s("botSettings.simple.instructions"),placeholder:s("botSettings.simple.instructionsPlaceholder",{name:L})}}),e.jsx(Wr,{bot:t}),o&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-panel-done":"soul",onClick:()=>{m(t.id),i?.(!1)},className:le,children:s("botSettings.simple.done")})})]}):e.jsxs("button",{type:"button","data-panel-edit":"soul","aria-label":`${s("botSettings.simple.edit")}: ${s("botSettings.simple.instructions")}`,onClick:()=>i?.(!0),className:O(X,"w-full text-left hover:bg-ink/[0.03]"),children:[e.jsx(te,{icon:Me}),e.jsx(ae,{title:s("botSettings.simple.instructions"),hint:e.jsx("span",{className:"line-clamp-1",children:bi(t.soul??"")||s("botPanel.instructionsHint",{name:L})})}),e.jsx(je,{size:15,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]})}),e.jsx(Ur,{bot:t}),e.jsx(M,{anchor:"approval",children:e.jsxs(me,{"data-panel-row":"approval",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:es}),e.jsx(ae,{title:s("botSettings.simple.beforeActs",{name:L}),hint:t.busy?s("approvalMode.whileWorking"):void 0})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-approval-choice",label:s("botSettings.simple.beforeActs",{name:L}),value:$,onChange:H,options:A})}),k.choice&&e.jsxs("div",{"data-panel-row":"thread-approval",className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botPanel.thisConversation")}),e.jsx("span",{className:"ms-auto flex",children:e.jsx(ba,{choice:k.choice})})]}),J.length>0&&e.jsxs("div",{"data-panel-row":"always-allow",className:"flex min-w-0 flex-col gap-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botAccess.always.title")}),J.map(y=>e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",children:y}),e.jsx(Be,{"data-panel-action":`always-allow:${y}`,label:s("botAccess.always.remove",{entry:y}),onClick:()=>b({alwaysAllow:J.filter(z=>z!==y)})})]},y))]})]})}),e.jsx(Kr,{bot:t,onChange:y=>b({fallback:y})}),e.jsx(M,{anchor:"call",children:e.jsxs(me,{"data-panel-row":"call-mode",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:ai}),e.jsx(ae,{title:s("call.mode.menu")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-call-mode",label:s("call.mode.menu"),value:g,onChange:va,options:F})})]})}),e.jsxs(M,{anchor:"replies",children:[e.jsxs(me,{"data-panel-row":"reply-style",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(te,{icon:ka}),e.jsx(ae,{title:s("botSettings.replyStyle.title")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Oe,{attr:"data-reply-style",label:s("botSettings.replyStyle.title"),value:t.replyStyle??"default",onChange:y=>b({replyStyle:y}),options:_})})]}),e.jsx(it,{"data-panel-row":"notifications",icon:ja,title:s("voice.notifications.title"),color:t.color,checked:t.notifications,onChange:K})]}),e.jsxs(M,{anchor:"uses",children:[e.jsx(Q,{"data-panel-page":"apps",icon:ds,title:s("botPanel.appsRow"),value:U.length>0?U.join(", "):s("botPanel.appsNoneYet"),onClick:()=>a?.("apps")}),e.jsxs("label",{"data-panel-row":"job",className:O(X,"cursor-text"),children:[e.jsx(te,{icon:Ui}),e.jsx("span",{className:"shrink-0 text-[14px] font-medium text-ink",children:s("botSettings.simple.job")}),e.jsx("input",{"data-panel-job":!0,value:N??t.title,placeholder:s("botSettings.simple.jobPlaceholder"),"aria-label":s("botSettings.simple.job"),maxLength:Qe.title,onChange:y=>w(y.target.value),onBlur:D,onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),y.currentTarget.blur()):y.key==="Escape"&&N!==null&&(y.preventDefault(),y.stopPropagation(),w(null))},className:"min-w-0 flex-1 bg-transparent text-right text-[13px] text-ink-secondary outline-none placeholder:text-ink-tertiary focus:text-ink"})]}),v&&e.jsxs("a",{"data-panel-row":"slack",href:v,target:"_blank",rel:"noopener noreferrer",className:O(X,"hover:bg-ink/[0.03]"),children:[e.jsx(te,{icon:Ps}),e.jsx(ae,{title:s("botPanel.page.slack"),hint:s("botSlack.manage")}),e.jsx(gs,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]}),j&&e.jsx(Q,{"data-panel-page":"visibility",icon:ts,title:s("botSettings.visibility.title"),value:vi(t.visibility),onClick:()=>a?.("visibility")})]}),t.yourAccess!=="view"&&!t.defaultBot&&e.jsx($r,{bot:t,className:"mt-3.5"}),e.jsx(ki,{bot:t,webhooksLink:!0,className:"mt-3.5"}),e.jsx(wa,{bot:t}),k.dialogs]})}const Zr=5;function Gr({bot:t,onChanged:n}){const{dispatch:a}=B(),[o,i]=x.useState([]),[l,d]=x.useState(null),[m,r]=x.useState(null),c=x.useCallback(async()=>{const[f,v]=await Promise.all([rt(t.id),ge(t.id)]);d(j=>f.lendingReview?{value:f.lendingReview,stale:j?.stale??!1}:null),i(v.slice(0,Zr))},[t.id]);x.useEffect(()=>{c().catch(()=>{})},[c,t.busy]);const p=f=>a({type:"error",message:f instanceof Error&&f.message?f.message:s("common.tryAgain")}),u=async f=>{r(f.id);try{await js(t.id,f.id),await n()}catch(v){p(v)}finally{r(null),await c().catch(()=>{})}},k=async f=>{r("review");try{await bs(t.id,f.value.token),d(null)}catch(v){v instanceof as&&v.status===409?(d({...f,stale:!0}),await c().catch(()=>{})):p(v)}finally{r(null)}};return e.jsxs(e.Fragment,{children:[l&&e.jsx(Ts,{changed:l.value.changed,stale:l.stale,busy:m!==null,onReviewed:()=>{k(l)}}),e.jsx(M,{children:e.jsx(it,{"data-panel-row":"memory-upkeep",title:s("memory.upkeep.title"),checked:t.memoryUpkeep!==!1,color:t.color,onChange:()=>a({type:"updateBot",botId:t.id,patch:{memoryUpkeep:t.memoryUpkeep===!1}})})}),o.length>0&&e.jsx(M,{label:s("memory.changes"),children:e.jsx("div",{"data-panel-row":"memory-changes",className:"px-3.5 py-3",children:e.jsx(lt,{rows:o,botName:t.name,reverting:m,onRevert:f=>{u(f)}})})})]})}const Yr="flex flex-col gap-3",Vt="https://www.skills.sh";function ke(t,n){return t instanceof Error&&t.message?t.message:n}function Jr({bot:t,derived:n}){const{dispatch:a}=B(),o=ps(t),{servers:i,error:l}=ms(),{patch:d,canUseConnectedApps:m}=n,r=i?Ra(i,t.id):[],c=new Set(us(r,t.mcpServers,t.id).map(f=>f.name)),p=f=>{const v=Aa(t,o.connectedSlugs,f.slug,f.scope===null);Object.keys(v).length>0&&d(v)},u=f=>{t.busy||l||d({mcpServers:Ma(r,t.mcpServers,f)})},k=m?o.phase==="loading"?s("common.checking"):o.phase==="unknown"?s("botSettings.simple.appsUnknown"):o.apps.length===0?s("botSettings.simple.appsNone"):null:s("botSettings.simple.appsCannot",{name:t.name});return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[k&&e.jsx(V,{children:k}),m&&o.apps.map(f=>e.jsxs("div",{"data-simple-app":f.slug,className:X,children:[e.jsx(Ta,{card:f.card,className:"size-7 shrink-0"},`${f.card.logo}:${f.card.domain}`),e.jsx("div",{className:"min-w-0 flex-1 truncate text-[14px] font-medium text-ink",children:f.label}),e.jsx(jt,{color:t.color,checked:f.scope!==null,"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.label}),disabled:!!t.busy,onClick:()=>p(f),className:"disabled:cursor-not-allowed"})]},f.slug))]}),(r.length>0||l)&&e.jsxs(M,{label:s("connectors.tab.mcp"),children:[l&&e.jsx(V,{children:s("botAccess.mcpRefreshError")}),r.map(f=>e.jsxs("div",{"data-simple-mcp":f.name,className:X,children:[e.jsx(te,{icon:ii}),e.jsx(ae,{title:e.jsx("span",{className:"block truncate",children:f.name}),hint:f.enabled?f.offFor?.includes(t.id)?s("mcp.offFor",{bots:t.name}):void 0:s("botAccess.mcpDisabled")}),e.jsx(jt,{color:t.color,checked:c.has(f.name),"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.name}),disabled:!f.enabled||!!t.busy||l,onClick:()=>u(f.name),className:"disabled:cursor-not-allowed"})]},f.name))]}),e.jsx(M,{children:e.jsx(ue,{"data-panel-link":"add-app",icon:Ne,onClick:()=>Ia(a,t.id),children:s("botPanel.apps.connectAnother")})})]})}function Qr({bot:t,derived:n}){const{state:a,dispatch:o}=B(),[i,l]=x.useState(()=>n.botRoutines.length===0?"new":null);return e.jsxs(e.Fragment,{children:[e.jsx(Mi,{routines:n.botRoutines,runs:a.routineRuns,pausedBots:a.config?.pausedBots,heldBots:a.config?.heldBots,loading:a.routinesLoadState==="loading"&&n.botRoutines.length===0,error:a.routinesLoadState==="error",onOpen:l,onLogs:d=>o({type:"showRoutines",section:"logs",botId:t.id,routineId:d.id}),onToggle:d=>o({type:"updateRoutine",routineId:d.id,patch:{enabled:!d.enabled}})}),e.jsx(M,{children:e.jsx(ue,{"data-panel-action":"new-routine",icon:Ne,onClick:()=>l("new"),children:s("botPanel.routines.add")})}),e.jsx("p",{className:"mx-1 text-[13px] leading-normal text-ink-secondary",children:s("botPanel.routines.ask",{name:t.name})}),i&&e.jsx(Bi,{routine:i==="new"?void 0:i,bots:[t],lockedBotId:t.id,onClose:()=>l(null)},t.id)]})}function Xr({bot:t}){const n=$s(t),[a,o]=x.useState(""),[i,l]=x.useState(null),[d,m]=x.useState(!1),[r,c]=x.useState(null),p=t.memoryEnabled!==!1,u=n.docs?Bs(n.docs):null,k=n.docs?.find(w=>w.path===se)??null;x.useEffect(()=>l(null),[t.id,p]);const f=async w=>{if(d)return!1;m(!0),c(null);try{return await w()}catch(b){return c(ke(b,s("botPanel.library.memoryError"))),!1}finally{m(!1)}},v=(w,b)=>f(async()=>{const h=await ot(t.id,w.path,b,w.exists?w.hash:void 0,n.mine);return h.ok?(n.setDoc(h.doc),!0):(await n.reload(),c(s("memory.conflict.title",{name:t.name})),!1)}),j=w=>{const b=n.docs?.find(h=>h.path===w.path);b&&(w.line!==null?v(b,Or(b.text,w.line)):f(async()=>(await ks(t.id,b.path,n.mine),await n.reload(),!0)))},N=async()=>{!k||!a.trim()||await v(k,Er(k.text,a))&&o("")};return p&&i?.botId===t.id?e.jsx(eo,{bot:t,doc:i.doc,mine:n.mine,onDone:w=>{w&&n.setDoc(w),l(null),c(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[p?n.error?e.jsx(V,{tone:"warn",children:s("botPanel.library.memoryError")}):u===null?e.jsx(V,{children:s("common.checking")}):u.length===0?e.jsx(V,{children:s("botPanel.memory.empty")}):u.map(w=>e.jsxs("div",{"data-memory-note":w.line??w.path,className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 text-[13px] leading-[1.45] text-ink",children:w.text}),e.jsx(Be,{label:s("botPanel.memory.forget"),disabled:d,onClick:()=>j(w)})]},`${w.path}:${w.line}:${w.text}`)):e.jsx(V,{children:s("botPanel.library.memoryOff",{name:t.name})}),r&&e.jsx(V,{tone:"warn",children:r})]}),p&&e.jsxs(M,{children:[e.jsx(xs,{"data-panel-form":"memory-add",value:a,placeholder:s("botPanel.memory.addPlaceholder",{name:t.name}),label:s("botPanel.memory.addPlaceholder",{name:t.name}),action:s("common.add"),disabled:d||k===null,onChange:o,onSubmit:()=>{N()}}),k&&e.jsx(ue,{"data-panel-link":"memory-text",icon:Me,onClick:()=>l({botId:t.id,doc:k}),children:s("botPanel.memory.editText")})]}),p&&!n.mine&&e.jsx(Gr,{bot:t,onChanged:n.reload})]})}function eo({bot:t,doc:n,mine:a,onDone:o}){const[i,l]=x.useState({text:n.text,hash:n.hash}),[d,m]=x.useState(n.text),[r,c]=x.useState(null),[p,u]=x.useState(null),[k,f]=x.useState(!1),[v,j]=x.useState(null),N=x.useRef(!0);x.useEffect(()=>(N.current=!0,()=>{N.current=!1}),[]);const w=async h=>{f(!0),j(null);try{const P=await ot(t.id,n.path,d,h,a);if(!N.current)return;P.ok?o(P.doc):c({current:P.current,currentHash:P.currentHash})}catch(P){j(ke(P,s("botPanel.library.memoryError")))}finally{f(!1)}},b=()=>{r&&(u(h=>h===null||h===d?d:`${h}
15
15
 
16
- ${d}`),l({text:r.current,hash:r.currentHash}),m(r.current),c(null))};return e.jsx(M,{children:e.jsxs(me,{"data-panel-row":"memory-text",children:[r&&e.jsx(Is,{botName:t.name,busy:k,onReload:b,onOverwrite:()=>{w(r.currentHash)}}),e.jsx("textarea",{"data-memory-text":"",className:O(et,"min-h-[280px] resize-y font-mono text-[13px] leading-relaxed"),value:d,placeholder:s("memory.indexPlaceholder"),"aria-label":s("memory.botMemory"),readOnly:k,onChange:h=>m(h.target.value)}),v&&e.jsx("div",{className:"text-[13px] text-warning",children:v}),p!==null&&e.jsxs("div",{"data-memory-draft":"",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:p}),e.jsx("button",{type:"button",className:O(le,"mt-1"),onClick:()=>x(null),children:s("memory.dismissDraft")})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:le,disabled:k,onClick:()=>o(null),children:s("common.cancel")}),e.jsx("button",{type:"button","data-panel-done":"memory-text",className:le,disabled:k||d===i.text,onClick:()=>{w(i.hash)},children:k?s("memory.saving"):s("memory.save")})]})]})})}function Xr({bot:t}){const{request:n}=Ca(),{state:a,dispatch:o}=B(),i=ws(t),[l,d]=u.useState(""),[m,r]=u.useState(!1),[c,p]=u.useState([]),x=Pa(a.config),k=async h=>{if(!i.working&&window.confirm(s(h.origin==="library"?"skills.unassignConfirm":"botPanel.skills.removeConfirm",{name:h.name}))){i.setWorking(h.name),i.setError("");try{await n(`/api/bots/${t.id}/skills/${encodeURIComponent(h.name)}`,{method:"DELETE"}),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.removeFailed")))}finally{i.setWorking("")}}},f=async()=>{const h=l.trim();if(!(!h||m)){r(!0),i.setError(""),p([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:h})});p(Tt(P.imported??[])),d(""),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},v=async()=>{const h=await window.ogb?.pickFolder?.();if(!(!h||m)){r(!0),i.setError(""),p([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:`local-folder:${h}`})});p(Tt(P.imported??[])),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},[j,N]=u.useState(!1),w=()=>{N(!1),o({type:"toggleSettings",open:!1}),o({type:"toggleAppSettings",open:!0,section:"skills"})},b=()=>{if(x){N(!0);return}jt(Zt)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[i.loading?e.jsx(V,{children:s("skills.loading")}):i.skills.length===0?e.jsx(V,{children:s("botSettings.simple.noSkills")}):i.skills.map(h=>e.jsx(rt,{"data-panel-row":`skill:${h.name}`,title:h.name,hint:h.description||h.source,label:s("botSettings.simple.skillToggle",{name:h.name}),color:t.color,checked:Ns(h),disabled:!!i.working||h.core===!0,onChange:()=>{i.toggle(h)},extra:h.origin==="imported"||h.origin==="native"||h.origin==="bundled"?void 0:e.jsx(Be,{"data-panel-action":`remove-skill:${h.name}`,label:s("botPanel.skills.remove",{name:h.name}),disabled:!!i.working,onClick:()=>{k(h)}})},h.name)),i.error&&!i.reviewing&&e.jsx(V,{tone:"warn",children:i.error})]}),e.jsx(ki,{bot:t,onAdded:()=>{i.refresh()}}),e.jsxs(M,{children:[e.jsx(xs,{"data-panel-form":"skill-import",value:l,placeholder:s("botPanel.skills.importPlaceholder"),label:s("skills.import.label"),action:m?s("skills.import.importing"):s("common.add"),disabled:m,onChange:d,onSubmit:()=>{f()}}),c.map(h=>e.jsx(V,{children:h},h)),e.jsx(ue,{"data-panel-link":"skills-sh",onClick:()=>{jt(Zt)},children:s("botPanel.skills.skillsSh")}),e.jsx(ue,{"data-panel-link":"browse-skills",onClick:b,children:s("botPanel.skills.bundled")}),window.ogb?.pickFolder&&e.jsx(ue,{"data-panel-link":"skills-folder",onClick:()=>{v()},children:s("botPanel.skills.fromFolder")})]}),j&&e.jsx(Mr,{botId:t.id,botName:t.name,onOpenSettings:w,onClose:()=>{N(!1),i.refresh()}}),i.reviewing&&e.jsx(ji,{skill:i.reviewing.skill,text:i.reviewing.text,error:i.error,working:i.working===i.reviewing.skill.name,onCancel:()=>i.setReviewing(null),onEnable:()=>{i.enableReviewed()}})]})}function eo({bot:t}){const{capabilities:n}=we(),a=n.host?.homeDir,{draft:o,setDraft:i,error:l,saving:d,canPick:m,save:r,pick:c}=vi(t),[p,x]=u.useState(!1),k=!!t.cwd||p,f=()=>{if(m){c();return}x(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[e.jsx(Ge,{"data-panel-choice":"private",title:s("botPanel.folder.own"),hint:s("botPanel.folder.ownHint"),checked:!k,disabled:d,onClick:()=>{x(!1),t.cwd&&r(null)}}),e.jsx(Ge,{"data-panel-choice":"pick",title:s("botPanel.folder.pick"),hint:s("botPanel.folder.pickHint"),checked:k,disabled:d,onClick:()=>{t.cwd||f()}})]}),k&&e.jsxs(M,{children:[m?e.jsxs("div",{className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 truncate rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[13px] text-ink",title:t.cwd,children:t.cwd?it(t.cwd,a):e.jsx("span",{className:"text-ink-secondary",children:s("botAccess.folder.private")})}),e.jsxs("button",{type:"button","data-panel-action":"pick-folder",disabled:d,onClick:()=>{c()},className:le,children:[e.jsx(ns,{size:14,"aria-hidden":"true"}),s("botAccess.folder.choose")]})]}):e.jsxs("form",{"data-panel-form":"folder-path",className:X,onSubmit:v=>{v.preventDefault();const j=(o??t.cwd??"").trim();j&&r(j)},children:[e.jsx("input",{value:o??t.cwd??"",placeholder:s("botAccess.folder.placeholder"),"aria-label":s("botAccess.folder.title"),onChange:v=>i(v.target.value),className:"h-8 min-w-0 flex-1 rounded-lg border border-hairline bg-inset px-2.5 font-mono text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent-border"}),e.jsx("button",{type:"submit",disabled:d||o===null,className:le,children:s("botAccess.folder.save")})]}),l&&e.jsx(V,{tone:"warn",children:l})]}),e.jsx(Na,{value:t.cwd,disabled:d,onChoose:r}),e.jsx(Sa,{kind:"bots",id:t.id,folder:t.cwd})]})}function to({bot:t,derived:n}){const a=As(t);return e.jsx(Tr,{bot:t,browserEnabled:n.browserEnabled,onOpenBrowser:()=>a("browser")})}function so({bot:t}){return Ss()?e.jsx(Cs,{bot:t}):null}function no({page:t,onOpen:n,editingInstructions:a,onEditInstructions:o,...i}){switch(t){case"settings":return e.jsx(qr,{...i,onOpen:n,editingInstructions:a,onEditInstructions:o});case"where":return e.jsx(xr,{...i});case"apps":return e.jsx(Gr,{...i});case"routines":return e.jsx(Yr,{...i});case"visibility":return e.jsx(so,{...i});case"memory":return e.jsx(Jr,{...i});case"plugins":return e.jsx(Es,{bot:i.bot},i.bot.id);case"skills":return e.jsx(Xr,{...i});case"folder":return e.jsx(eo,{...i});case"browser":return e.jsx(to,{...i})}}const Gt="rounded-lg border border-accent-border bg-inset px-2 py-[3px] text-center text-ink outline-none placeholder:text-ink-tertiary";function Yt(t){const[n,a]=u.useState(null),o=u.useRef(!1),i=u.useRef(!1),l=u.useRef(null);u.useEffect(()=>{n!==null||!i.current||(i.current=!1,l.current?.focus())},[n]);const d=p=>{o.current=!1,a(p)},m=()=>{n!==null&&t(n),a(null)};return{draft:n,setDraft:a,start:d,onKeyDown:p=>{if(Ma(p.nativeEvent)){p.stopPropagation();return}p.key==="Enter"?(p.preventDefault(),o.current=!0,i.current=!0,m()):p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),o.current=!0,i.current=!0,a(null))},onBlur:()=>{o.current||m()},buttonRef:l}}function ao({bot:t,activeState:n,patch:a,editorOpen:o,onToggleEditor:i}){const l=Yt(r=>{const c=r.trim();c&&c!==t.name&&a({name:c})}),d=Yt(r=>{const c=r.trim();c!==t.title.trim()&&a({title:c})}),m=t.title.trim();return e.jsxs("div",{className:"group/hero flex flex-col items-center text-center",children:[e.jsxs("button",{type:"button","data-panel-avatar":!0,"aria-label":s("botPanel.avatar.edit"),"aria-expanded":o,onClick:i,className:"group relative rounded-[18px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[e.jsx(Xe,{bot:t,size:64,state:n}),e.jsx("span",{"aria-hidden":"true",className:"absolute inset-0 flex items-center justify-center rounded-[18px] bg-black/0 text-white opacity-0 transition-[opacity,background-color] group-hover:bg-black/40 group-hover:opacity-100 group-focus-visible:bg-black/40 group-focus-visible:opacity-100 group-focus-within:opacity-100 touch:opacity-100 motion-reduce:transition-none",children:e.jsx(Nt,{size:20})}),t.chiefOfStaff&&e.jsxs("span",{"data-panel-chief":!0,title:s("chat.chiefOfStaff"),className:"absolute -bottom-0.5 -right-0.5 flex size-[22px] items-center justify-center rounded-full bg-accent text-accent-ink ring-[3px] ring-app",children:[e.jsx(Aa,{size:12,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:s("chat.chiefOfStaff")})]}),e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute left-1/2 top-[calc(100%+4px)] z-10 -translate-x-1/2 whitespace-nowrap rounded-md border border-hairline bg-menu px-[7px] py-0.5 text-[12px] text-ink opacity-0 transition-opacity group-hover:opacity-100",children:s("botPanel.avatar.edit")})]}),e.jsx("div",{"data-panel-name-row":!0,className:"mt-2 flex max-w-full items-center justify-center",children:e.jsx("h2",{id:"bot-settings-title",className:"flex min-w-0 justify-center",children:l.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-rename-input":!0,"aria-label":s("botSettings.simple.name"),maxLength:Qe.name,value:l.draft,onChange:r=>l.setDraft(r.target.value),onKeyDown:l.onKeyDown,onBlur:l.onBlur,className:O(Gt,"w-[220px] max-w-full text-[17px] font-medium leading-6")}):e.jsxs("button",{ref:l.buttonRef,type:"button","data-panel-rename":!0,title:s("botPanel.rename"),onClick:()=>l.start(t.name),className:"group/name relative inline-flex max-w-full items-center rounded-[8px] px-1.5 text-[17px] font-medium leading-6 text-ink hover:bg-ink/[0.04]",children:[e.jsx("span",{className:"min-w-0 truncate",children:t.name}),e.jsx(Nt,{size:13,"aria-hidden":"true",className:"absolute -right-4 shrink-0 text-ink-tertiary opacity-0 transition-opacity group-hover/name:opacity-100 group-focus-visible/name:opacity-100 group-focus-within/name:opacity-100 touch:opacity-100"})]})})}),d.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-label-input":!0,"aria-label":s("botSettings.simple.job"),placeholder:s("botSettings.simple.jobPlaceholder"),maxLength:Qe.title,value:d.draft,onChange:r=>d.setDraft(r.target.value),onKeyDown:d.onKeyDown,onBlur:d.onBlur,className:O(Gt,"mt-[3px] w-[200px] max-w-full text-[13px]")}):m&&e.jsx("button",{ref:d.buttonRef,type:"button","data-panel-label":!0,onClick:()=>d.start(t.title),className:"mt-px max-w-full truncate rounded-md px-1.5 py-px text-[13px] text-ink-secondary hover:bg-ink/[0.04]",children:m})]})}function Pe(t,n){return t?hs(t,n):{tab:"details"}}function io({bot:t,derived:n,linkedSection:a,onClose:o}){const{dragProps:i}=ys(),l=La(),[d,m]=u.useState(()=>Pe(a,l).tab),[r,c]=u.useState(()=>{const g=Pe(a,l).page;return g?[g]:[]}),[p,x]=u.useState(()=>Pe(a,l).anchor??null),[k,f]=u.useState(!1),[v,j]=u.useState(()=>!!Pe(a,l).editInstructions),N=u.useRef(null),w=u.useRef(null),b=r.at(-1)??null,h=()=>N.current?.scrollTo({top:0}),P=g=>{m(g.tab),c(g.page?[g.page]:[]),x(g.anchor??null),f(!1),j(!!g.editInstructions),h()},L=g=>P({tab:g}),D=g=>{c(T=>[...T,g]),f(!1),h()},$=()=>{f(!1),w.current?.querySelector("[data-panel-avatar]")?.focus()},A=()=>{c(g=>g.slice(0,-1)),h()};u.useEffect(()=>{a&&P(hs(a,l))},[a,l]),u.useEffect(()=>{p&&(N.current?.querySelector(`[data-panel-card="${p}"]`)?.scrollIntoView({block:"start"}),x(null))},[p,b,d]);const H=g=>{if(g.key!=="Escape"||g.defaultPrevented)return;const T=g.target,F=typeof T?.closest=="function"?T.closest('[role="dialog"], [role="alertdialog"]'):null;if(!(F&&!F.contains(g.currentTarget)&&F!==w.current&&!w.current?.contains(F))){if(k)$();else if(r.length>0)A();else return;g.preventDefault(),g.stopPropagation()}},I=r.length>1?s(Ce[r[r.length-2]].title,{name:t.name}):s(St[d]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",onKeyDown:H,children:[e.jsxs("div",{...i,className:"flex h-[50px] shrink-0 items-start justify-end gap-2.5 px-[13px] pt-[13px]",children:[e.jsx(Ba,{bot:t,className:He}),e.jsx("button",{type:"button","data-panel-gear":!0,"aria-label":s("botPanel.page.settings"),title:s("botPanel.page.settings"),"aria-current":b==="settings"?"page":void 0,onClick:()=>P({tab:"details",page:"settings"}),className:He,children:e.jsx($a,{size:16,className:"pointer-events-none"})}),e.jsx("button",{type:"button",onClick:o,"aria-label":s("botSettings.simple.close"),className:He,children:e.jsx(st,{size:16,className:"pointer-events-none"})})]}),e.jsx("div",{ref:N,className:"@container relative min-h-0 flex-1 overflow-y-auto px-4 pb-7",children:b===null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mt-3.5",ref:w,children:[e.jsx(ao,{bot:t,activeState:n.activeState,patch:n.patch,editorOpen:k,onToggleEditor:()=>f(g=>!g)}),k&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-20","aria-hidden":"true","data-panel-scrim":!0,onClick:$}),e.jsx(pr,{bot:t,activeState:n.activeState,onPatch:n.patch,onClose:$})]})]}),e.jsx("div",{role:"tablist","aria-label":s("botSettings.simple.tabs"),className:"sticky top-0 z-[1] -mx-4 mt-[15px] flex justify-center bg-app px-4 pb-2.5 pt-1 after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-3 after:bg-linear-to-b after:from-app after:to-transparent",children:e.jsx("div",{className:"flex min-w-0 gap-0.5 rounded-full bg-ink/[0.05] p-[3px]",children:Fa.map(g=>e.jsx("button",{type:"button",role:"tab","aria-selected":d===g,"data-panel-tab":g,onClick:()=>L(g),className:O("h-[26px] min-w-0 shrink truncate rounded-full px-3 text-[13px] leading-[18px] transition-colors",d===g?"bg-ink/[0.1] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(St[g])},g))})}),e.jsxs("div",{role:"tabpanel",children:[d==="details"&&e.jsx(Nr,{bot:t,derived:n,onOpen:D}),d==="library"&&e.jsx(Fs,{bot:t,onOpen:D}),d==="computer"&&e.jsx(hr,{bot:t,derived:n,onOpen:D})]})]}):e.jsxs("div",{"data-panel-page-view":b,children:[e.jsx("span",{id:"bot-settings-title",className:"sr-only",children:t.name}),e.jsx(Da,{back:I,title:s(Ce[b].title,{name:t.name}),intro:Ce[b].intro?s(Ce[b].intro,{name:t.name}):void 0,onBack:A}),e.jsx("div",{className:O("mt-4",Zr),children:e.jsx(no,{page:b,bot:t,derived:n,onOpen:D,editingInstructions:v,onEditInstructions:j})})]})})]})}function ro(t,n){const{state:a,flushBotPatches:o}=B(),[i,l]=u.useState(null),[d,m]=u.useState(!1),[r,c]=u.useState(null),[p,x]=u.useState(!1),k=u.useMemo(()=>JSON.stringify([t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),[t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),f=n.followEdits??!0,v=f?k:null,j=f?a.routines:null,N=f?a.webhooks:null;return u.useEffect(()=>{if(!n.overview&&!n.prompt)return;let w=!1;return(async()=>(await o(t.id),!w&&(n.overview&&Z(`/api/bots/${t.id}/overview`).then(h=>{w||(l(h),m(!1))}).catch(()=>{w||m(!0)}),n.prompt&&Z(`/api/bots/${t.id}/system-prompt`).then(h=>{w||(c(h),x(!1))}).catch(()=>{w||x(!0)}))))(),()=>{w=!0}},[t.id,n.overview,n.prompt,v,j,N,o]),{overview:i,overviewError:d,prompt:r,promptError:p}}function oo(t,n){const{dispatch:a,flushBotPatches:o}=B(),[i,l]=u.useState(null),[d,m]=u.useState(!1),[r,c]=u.useState(null),p=u.useRef(0),[x,k]=u.useState(!1),[f,v]=u.useState(null),j=u.useCallback(()=>{const b=++p.current;return m(!1),o(t.id).then(()=>Z(`/api/bots/${t.id}/history?limit=100`)).then(h=>{b===p.current&&(l(h.rows),c(h.revision))}).catch(()=>{b===p.current&&m(!0)})},[t.id,o]);return u.useEffect(()=>{if(n)return j(),()=>{p.current++}},[n,j]),{rows:i,error:d,revision:r,rollingBack:x,rollbackTarget:f,setRollbackTarget:v,rollback:async b=>{if(!x){v(null),k(!0);try{await o(t.id),await Z(`/api/bots/${t.id}/history/rollback`,{method:"POST",body:JSON.stringify(b)})}catch(h){a({type:"error",message:h instanceof Error?h.message:s("botOverview.undoFailed")})}finally{await j(),k(!1)}}},requestRollback:b=>{r&&v({id:b,expectedRevision:r})}}}function lo({history:t,returnFocusRef:n}){const{rollbackTarget:a,setRollbackTarget:o,rollback:i}=t;return e.jsx(za,{open:a!==null,title:s("botOverview.restoreSoul.title"),body:s("botOverview.restoreSoul.body"),confirmLabel:s("botOverview.restoreSoul.confirm"),tone:"neutral",returnFocusRef:n,onCancel:()=>o(null),onConfirm:()=>{a&&i(a)}})}const co={memory:"memory",skills:"skills",plugins:"plugins",folder:"access"},zs=t=>t.labelKey?s(t.labelKey):t.label;function Jt(t,n){return n?[t.label,zs(t),...t.keywords].some(a=>a.toLowerCase().includes(n)):!0}function Po({bot:t,overlay:n=!1}){const{state:a,dispatch:o}=B(),i=a.botSettingsSection,l=Ha(t),d=u.useRef(null),{dragProps:m}=ys(),[r,c]=u.useState(""),p=!a.botSettingsExpandAccordion,x=r.trim().toLowerCase(),f=!Qt(),v=!p&&!a.botSettingsExpandRemembered?i:null,j=Os(t.id),N=Le(),w=_a(),b=Ki.filter(I=>I.id!=="plugins"||N===!0).filter(I=>I.id!=="slack"||j!==null).filter(I=>I.id!=="visibility"||!window.ogb&&N===!0&&!w),h=b.filter(I=>Jt(I,x)),{overview:P,overviewError:L,prompt:D,promptError:$}=ro(t,{overview:i==="overview"&&!f,prompt:i==="overview"&&!f}),A=oo(t,i==="history"&&!f);u.useEffect(()=>{if(!p){if(x){c("");return}d.current?.querySelector(`[data-bot-settings-section="${i}"]`)?.scrollIntoView({block:"nearest"})}},[p,i,x]),u.useEffect(()=>{const I=document.activeElement instanceof HTMLElement?document.activeElement:null,g=d.current;g?.focus();const T=F=>{const _=g?.querySelector('[role="dialog"], [role="alertdialog"]');_&&_.getClientRects().length>0||g&&F.target instanceof Node&&!g.contains(F.target)||F.key==="Escape"&&!F.defaultPrevented&&(F.preventDefault(),o({type:"toggleSettings",open:!1}))};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T),I?.focus()}},[o]);const H=I=>{switch(I){case"overview":return P===null&&L?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.overviewFailed")}):e.jsx(Yi,{overview:P,refreshError:P!==null&&L,prompt:D,promptError:$,onOpen:g=>o({type:"toggleSettings",open:!0,section:g}),onSetup:l.canCoordinate&&!t.busy?()=>{o({type:"toggleSettings",open:!1}),o({type:"send",botId:t.id,text:"/setup",threadId:t.threadId})}:void 0});case"identity":return e.jsx(Ei,{bot:t,patch:l.patch,activeState:l.activeState,mascotMotion:l.mascotMotion});case"soul":return e.jsx(Oi,{bot:t,patch:l.patch});case"slack":return j?e.jsx(Ji,{managementUrl:j}):null;case"plugins":return e.jsx(Es,{bot:t},t.id);case"skills":return e.jsx(Pi,{bot:t});case"memory":return e.jsx(er,{bot:t,active:!p&&i==="memory",onToggle:g=>l.patch({memoryEnabled:g})});case"library":return e.jsx(Fs,{bot:t,onOpen:g=>o({type:"toggleSettings",open:!0,section:co[g]??"overview"})});case"routines":return e.jsx(Ai,{bot:t,routines:l.botRoutines,runs:a.routineRuns});case"access":return e.jsx(Ci,{bot:t,derived:l});case"model":return e.jsx(Si,{bot:t});case"permissions":return e.jsx(Ni,{bot:t,derived:l});case"voice":return e.jsx(wi,{bot:t,derived:l});case"visibility":return e.jsx(Cs,{bot:t});case"history":return A.rows===null&&A.error?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.historyFailed")}):e.jsx(ar,{bot:t,rows:A.rows,refreshError:A.rows!==null&&A.error,onRollback:A.requestRollback,rollingBack:A.rollingBack||!A.revision});case"usage":return e.jsx(ir,{bot:t});default:return null}};return e.jsxs(e.Fragment,{children:[e.jsx("aside",{ref:d,id:f?Ka:void 0,role:"dialog","aria-labelledby":"bot-settings-title",tabIndex:-1,className:qa(n,f),children:f?e.jsx(io,{bot:t,derived:l,linkedSection:v,onClose:()=>o({type:"toggleSettings",open:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{...m,className:"flex shrink-0 items-center justify-between px-4 py-3",children:[e.jsx("span",{id:"bot-settings-title",className:"truncate text-[15px] font-semibold text-ink",children:t.name}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Ua,{bot:t,className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink"}),e.jsx("button",{type:"button",onClick:()=>o({type:"toggleSettings",open:!1}),"aria-label":s("botSettings.simple.close"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(st,{size:18,className:"pointer-events-none"})})]})]}),e.jsxs("div",{className:"mx-4 mb-2 flex shrink-0 items-center gap-2 rounded-lg border border-transparent bg-control/70 px-2.5 py-2 focus-within:border-focus",children:[e.jsx(tt,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{value:r,onChange:I=>{c(I.target.value),o({type:"toggleSettings",open:!0})},onKeyDown:I=>{I.key==="Escape"&&(I.stopPropagation(),r?c(""):o({type:"toggleSettings",open:!1}))},placeholder:s("botSettings.search"),"aria-label":s("botSettings.searchAria"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:[h.length===0&&e.jsx("div",{className:"px-4 py-4 text-[13px] leading-relaxed text-ink-secondary",children:s("botSettings.searchNone",{query:r.trim()})}),b.map(I=>{const{id:g,icon:T}=I,F=zs(I),_=Jt(I,x);if(!_&&g!=="memory")return null;const K=!p&&i===g;return e.jsxs("div",{"data-bot-settings-section":g,className:"border-b border-hairline/30",hidden:!_,children:[e.jsxs("button",{type:"button",onClick:()=>{if(i===g&&!p){o({type:"toggleSettings",open:!0});return}o({type:"toggleSettings",open:!0,section:g})},"aria-expanded":K,className:O("flex w-full shrink-0 items-center gap-2.5 px-4 py-2.5 text-left text-[14px]",K?"bg-control/60 text-ink":"text-ink-secondary hover:bg-control/40 hover:text-ink"),children:[e.jsx(T,{size:15,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:F}),e.jsx(fe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",K&&"rotate-180")})]}),g==="memory"?e.jsx("div",{hidden:!K,className:"px-4 pb-4 pt-1",children:H("memory")}):K&&e.jsx("div",{className:"px-4 pb-4 pt-1",children:H(g)})]},g)})]})]})}),e.jsx(lo,{history:A,returnFocusRef:d})]})}export{Po as BotSettingsDialog};
16
+ ${d}`),l({text:r.current,hash:r.currentHash}),m(r.current),c(null))};return e.jsx(M,{children:e.jsxs(me,{"data-panel-row":"memory-text",children:[r&&e.jsx(Is,{botName:t.name,busy:k,onReload:b,onOverwrite:()=>{w(r.currentHash)}}),e.jsx("textarea",{"data-memory-text":"",className:O(et,"min-h-[280px] resize-y font-mono text-[13px] leading-relaxed"),value:d,placeholder:s("memory.indexPlaceholder"),"aria-label":s("memory.botMemory"),readOnly:k,onChange:h=>m(h.target.value)}),v&&e.jsx("div",{className:"text-[13px] text-warning",children:v}),p!==null&&e.jsxs("div",{"data-memory-draft":"",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:p}),e.jsx("button",{type:"button",className:O(le,"mt-1"),onClick:()=>u(null),children:s("memory.dismissDraft")})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:le,disabled:k,onClick:()=>o(null),children:s("common.cancel")}),e.jsx("button",{type:"button","data-panel-done":"memory-text",className:le,disabled:k||d===i.text,onClick:()=>{w(i.hash)},children:k?s("memory.saving"):s("memory.save")})]})]})})}function to({bot:t}){const{request:n}=Oa(),{state:a,dispatch:o}=B(),i=ws(t),[l,d]=x.useState(""),[m,r]=x.useState(!1),[c,p]=x.useState([]),u=Ea(a.config),k=async h=>{if(!i.working&&window.confirm(s(h.origin==="library"?"skills.unassignConfirm":"botPanel.skills.removeConfirm",{name:h.name}))){i.setWorking(h.name),i.setError("");try{await n(`/api/bots/${t.id}/skills/${encodeURIComponent(h.name)}`,{method:"DELETE"}),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.removeFailed")))}finally{i.setWorking("")}}},f=async()=>{const h=l.trim();if(!(!h||m)){r(!0),i.setError(""),p([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:h})});p(Rt(P.imported??[])),d(""),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},v=async()=>{const h=await window.ogb?.pickFolder?.();if(!(!h||m)){r(!0),i.setError(""),p([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:`local-folder:${h}`})});p(Rt(P.imported??[])),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},[j,N]=x.useState(!1),w=()=>{N(!1),o({type:"toggleSettings",open:!1}),o({type:"toggleAppSettings",open:!0,section:"skills"})},b=()=>{if(u){N(!0);return}kt(Vt)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[i.loading?e.jsx(V,{children:s("skills.loading")}):i.skills.length===0?e.jsx(V,{children:s("botSettings.simple.noSkills")}):i.skills.map(h=>e.jsx(it,{"data-panel-row":`skill:${h.name}`,title:h.name,hint:h.description||h.source,label:s("botSettings.simple.skillToggle",{name:h.name}),color:t.color,checked:Ns(h),disabled:!!i.working||h.core===!0,onChange:()=>{i.toggle(h)},extra:h.origin==="imported"||h.origin==="native"||h.origin==="bundled"?void 0:e.jsx(Be,{"data-panel-action":`remove-skill:${h.name}`,label:s("botPanel.skills.remove",{name:h.name}),disabled:!!i.working,onClick:()=>{k(h)}})},h.name)),i.error&&!i.reviewing&&e.jsx(V,{tone:"warn",children:i.error})]}),e.jsx(wi,{bot:t,onAdded:()=>{i.refresh()}}),e.jsxs(M,{children:[e.jsx(xs,{"data-panel-form":"skill-import",value:l,placeholder:s("botPanel.skills.importPlaceholder"),label:s("skills.import.label"),action:m?s("skills.import.importing"):s("common.add"),disabled:m,onChange:d,onSubmit:()=>{f()}}),c.map(h=>e.jsx(V,{children:h},h)),e.jsx(ue,{"data-panel-link":"skills-sh",onClick:()=>{kt(Vt)},children:s("botPanel.skills.skillsSh")}),e.jsx(ue,{"data-panel-link":"browse-skills",onClick:b,children:s("botPanel.skills.bundled")}),window.ogb?.pickFolder&&e.jsx(ue,{"data-panel-link":"skills-folder",onClick:()=>{v()},children:s("botPanel.skills.fromFolder")})]}),j&&e.jsx(Br,{botId:t.id,botName:t.name,onOpenSettings:w,onClose:()=>{N(!1),i.refresh()}}),i.reviewing&&e.jsx(Ni,{skill:i.reviewing.skill,text:i.reviewing.text,error:i.error,working:i.working===i.reviewing.skill.name,onCancel:()=>i.setReviewing(null),onEnable:()=>{i.enableReviewed()}})]})}function so({bot:t}){const{capabilities:n}=we(),a=n.host?.homeDir,{draft:o,setDraft:i,error:l,saving:d,canPick:m,save:r,pick:c}=ji(t),[p,u]=x.useState(!1),k=!!t.cwd||p,f=()=>{if(m){c();return}u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[e.jsx(Ge,{"data-panel-choice":"private",title:s("botPanel.folder.own"),hint:s("botPanel.folder.ownHint"),checked:!k,disabled:d,onClick:()=>{u(!1),t.cwd&&r(null)}}),e.jsx(Ge,{"data-panel-choice":"pick",title:s("botPanel.folder.pick"),hint:s("botPanel.folder.pickHint"),checked:k,disabled:d,onClick:()=>{t.cwd||f()}})]}),k&&e.jsxs(M,{children:[m?e.jsxs("div",{className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 truncate rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[13px] text-ink",title:t.cwd,children:t.cwd?at(t.cwd,a):e.jsx("span",{className:"text-ink-secondary",children:s("botAccess.folder.private")})}),e.jsxs("button",{type:"button","data-panel-action":"pick-folder",disabled:d,onClick:()=>{c()},className:le,children:[e.jsx(ns,{size:14,"aria-hidden":"true"}),s("botAccess.folder.choose")]})]}):e.jsxs("form",{"data-panel-form":"folder-path",className:X,onSubmit:v=>{v.preventDefault();const j=(o??t.cwd??"").trim();j&&r(j)},children:[e.jsx("input",{value:o??t.cwd??"",placeholder:s("botAccess.folder.placeholder"),"aria-label":s("botAccess.folder.title"),onChange:v=>i(v.target.value),className:"h-8 min-w-0 flex-1 rounded-lg border border-hairline bg-inset px-2.5 font-mono text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent-border"}),e.jsx("button",{type:"submit",disabled:d||o===null,className:le,children:s("botAccess.folder.save")})]}),l&&e.jsx(V,{tone:"warn",children:l})]}),e.jsx(Ca,{value:t.cwd,disabled:d,onChoose:r}),e.jsx(Pa,{kind:"bots",id:t.id,folder:t.cwd})]})}function no({bot:t,derived:n}){const a=As(t);return e.jsx(Ar,{bot:t,browserEnabled:n.browserEnabled,onOpenBrowser:()=>a("browser")})}function ao({bot:t}){return Ss()?e.jsx(Cs,{bot:t}):null}function io({page:t,onOpen:n,editingInstructions:a,onEditInstructions:o,...i}){switch(t){case"settings":return e.jsx(Vr,{...i,onOpen:n,editingInstructions:a,onEditInstructions:o});case"where":return e.jsx(gr,{...i});case"apps":return e.jsx(Jr,{...i});case"routines":return e.jsx(Qr,{...i});case"visibility":return e.jsx(ao,{...i});case"memory":return e.jsx(Xr,{...i});case"plugins":return e.jsx(Es,{bot:i.bot},i.bot.id);case"skills":return e.jsx(to,{...i});case"folder":return e.jsx(so,{...i});case"browser":return e.jsx(no,{...i})}}const Zt="rounded-lg border border-accent-border bg-inset px-2 py-[3px] text-center text-ink outline-none placeholder:text-ink-tertiary";function Gt(t){const[n,a]=x.useState(null),o=x.useRef(!1),i=x.useRef(!1),l=x.useRef(null);x.useEffect(()=>{n!==null||!i.current||(i.current=!1,l.current?.focus())},[n]);const d=p=>{o.current=!1,a(p)},m=()=>{n!==null&&t(n),a(null)};return{draft:n,setDraft:a,start:d,onKeyDown:p=>{if(Ba(p.nativeEvent)){p.stopPropagation();return}p.key==="Enter"?(p.preventDefault(),o.current=!0,i.current=!0,m()):p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),o.current=!0,i.current=!0,a(null))},onBlur:()=>{o.current||m()},buttonRef:l}}function ro({bot:t,activeState:n,patch:a,editorOpen:o,onToggleEditor:i}){const l=Gt(r=>{const c=r.trim();c&&c!==t.name&&a({name:c})}),d=Gt(r=>{const c=r.trim();c!==t.title.trim()&&a({title:c})}),m=t.title.trim();return e.jsxs("div",{className:"group/hero flex flex-col items-center text-center",children:[e.jsxs("button",{type:"button","data-panel-avatar":!0,"aria-label":s("botPanel.avatar.edit"),"aria-expanded":o,onClick:i,className:"group relative rounded-[18px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[e.jsx(Xe,{bot:t,size:64,state:n}),e.jsx("span",{"aria-hidden":"true",className:"absolute inset-0 flex items-center justify-center rounded-[18px] bg-black/0 text-white opacity-0 transition-[opacity,background-color] group-hover:bg-black/40 group-hover:opacity-100 group-focus-visible:bg-black/40 group-focus-visible:opacity-100 group-focus-within:opacity-100 touch:opacity-100 motion-reduce:transition-none",children:e.jsx(wt,{size:20})}),t.chiefOfStaff&&e.jsxs("span",{"data-panel-chief":!0,title:s("chat.chiefOfStaff"),className:"absolute -bottom-0.5 -right-0.5 flex size-[22px] items-center justify-center rounded-full bg-accent text-accent-ink ring-[3px] ring-app",children:[e.jsx(La,{size:12,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:s("chat.chiefOfStaff")})]}),e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute left-1/2 top-[calc(100%+4px)] z-10 -translate-x-1/2 whitespace-nowrap rounded-md border border-hairline bg-menu px-[7px] py-0.5 text-[12px] text-ink opacity-0 transition-opacity group-hover:opacity-100",children:s("botPanel.avatar.edit")})]}),e.jsx("div",{"data-panel-name-row":!0,className:"mt-2 flex max-w-full items-center justify-center",children:e.jsx("h2",{id:"bot-settings-title",className:"flex min-w-0 justify-center",children:l.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-rename-input":!0,"aria-label":s("botSettings.simple.name"),maxLength:Qe.name,value:l.draft,onChange:r=>l.setDraft(r.target.value),onKeyDown:l.onKeyDown,onBlur:l.onBlur,className:O(Zt,"w-[220px] max-w-full text-[17px] font-medium leading-6")}):e.jsxs("button",{ref:l.buttonRef,type:"button","data-panel-rename":!0,title:s("botPanel.rename"),onClick:()=>l.start(t.name),className:"group/name relative inline-flex max-w-full items-center rounded-[8px] px-1.5 text-[17px] font-medium leading-6 text-ink hover:bg-ink/[0.04]",children:[e.jsx("span",{className:"min-w-0 truncate",children:t.name}),e.jsx(wt,{size:13,"aria-hidden":"true",className:"absolute -right-4 shrink-0 text-ink-tertiary opacity-0 transition-opacity group-hover/name:opacity-100 group-focus-visible/name:opacity-100 group-focus-within/name:opacity-100 touch:opacity-100"})]})})}),d.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-label-input":!0,"aria-label":s("botSettings.simple.job"),placeholder:s("botSettings.simple.jobPlaceholder"),maxLength:Qe.title,value:d.draft,onChange:r=>d.setDraft(r.target.value),onKeyDown:d.onKeyDown,onBlur:d.onBlur,className:O(Zt,"mt-[3px] w-[200px] max-w-full text-[13px]")}):m&&e.jsx("button",{ref:d.buttonRef,type:"button","data-panel-label":!0,onClick:()=>d.start(t.title),className:"mt-px max-w-full truncate rounded-md px-1.5 py-px text-[13px] text-ink-secondary hover:bg-ink/[0.04]",children:m})]})}function Pe(t,n){return t?hs(t,n):{tab:"details"}}function oo({bot:t,derived:n,linkedSection:a,onClose:o}){const{dragProps:i}=ys(),l=$a(),[d,m]=x.useState(()=>Pe(a,l).tab),[r,c]=x.useState(()=>{const g=Pe(a,l).page;return g?[g]:[]}),[p,u]=x.useState(()=>Pe(a,l).anchor??null),[k,f]=x.useState(!1),[v,j]=x.useState(()=>!!Pe(a,l).editInstructions),N=x.useRef(null),w=x.useRef(null),b=r.at(-1)??null,h=()=>N.current?.scrollTo({top:0}),P=g=>{m(g.tab),c(g.page?[g.page]:[]),u(g.anchor??null),f(!1),j(!!g.editInstructions),h()},L=g=>P({tab:g}),D=g=>{c(T=>[...T,g]),f(!1),h()},$=()=>{f(!1),w.current?.querySelector("[data-panel-avatar]")?.focus()},A=()=>{c(g=>g.slice(0,-1)),h()};x.useEffect(()=>{a&&P(hs(a,l))},[a,l]),x.useEffect(()=>{p&&(N.current?.querySelector(`[data-panel-card="${p}"]`)?.scrollIntoView({block:"start"}),u(null))},[p,b,d]);const H=g=>{if(g.key!=="Escape"||g.defaultPrevented)return;const T=g.target,F=typeof T?.closest=="function"?T.closest('[role="dialog"], [role="alertdialog"]'):null;if(!(F&&!F.contains(g.currentTarget)&&F!==w.current&&!w.current?.contains(F))){if(k)$();else if(r.length>0)A();else return;g.preventDefault(),g.stopPropagation()}},I=r.length>1?s(Ce[r[r.length-2]].title,{name:t.name}):s(Nt[d]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",onKeyDown:H,children:[e.jsxs("div",{...i,className:"flex h-[50px] shrink-0 items-start justify-end gap-2.5 px-[13px] pt-[13px]",children:[e.jsx(Fa,{bot:t,className:He}),e.jsx("button",{type:"button","data-panel-gear":!0,"aria-label":s("botPanel.page.settings"),title:s("botPanel.page.settings"),"aria-current":b==="settings"?"page":void 0,onClick:()=>P({tab:"details",page:"settings"}),className:He,children:e.jsx(Da,{size:16,className:"pointer-events-none"})}),e.jsx("button",{type:"button",onClick:o,"aria-label":s("botSettings.simple.close"),className:He,children:e.jsx(st,{size:16,className:"pointer-events-none"})})]}),e.jsx("div",{ref:N,className:"@container relative min-h-0 flex-1 overflow-y-auto px-4 pb-7",children:b===null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mt-3.5",ref:w,children:[e.jsx(ro,{bot:t,activeState:n.activeState,patch:n.patch,editorOpen:k,onToggleEditor:()=>f(g=>!g)}),k&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-20","aria-hidden":"true","data-panel-scrim":!0,onClick:$}),e.jsx(ur,{bot:t,activeState:n.activeState,onPatch:n.patch,onClose:$})]})]}),e.jsx("div",{role:"tablist","aria-label":s("botSettings.simple.tabs"),className:"sticky top-0 z-[1] -mx-4 mt-[15px] flex justify-center bg-app px-4 pb-2.5 pt-1 after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-3 after:bg-linear-to-b after:from-app after:to-transparent",children:e.jsx("div",{className:"flex min-w-0 gap-0.5 rounded-full bg-ink/[0.05] p-[3px]",children:za.map(g=>e.jsx("button",{type:"button",role:"tab","aria-selected":d===g,"data-panel-tab":g,onClick:()=>L(g),className:O("h-[26px] min-w-0 shrink truncate rounded-full px-3 text-[13px] leading-[18px] transition-colors",d===g?"bg-ink/[0.1] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(Nt[g])},g))})}),e.jsxs("div",{role:"tabpanel",children:[d==="details"&&e.jsx(Cr,{bot:t,derived:n,onOpen:D}),d==="library"&&e.jsx(Fs,{bot:t,onOpen:D}),d==="computer"&&e.jsx(fr,{bot:t,derived:n,onOpen:D})]})]}):e.jsxs("div",{"data-panel-page-view":b,children:[e.jsx("span",{id:"bot-settings-title",className:"sr-only",children:t.name}),e.jsx(Ha,{back:I,title:s(Ce[b].title,{name:t.name}),intro:Ce[b].intro?s(Ce[b].intro,{name:t.name}):void 0,onBack:A}),e.jsx("div",{className:O("mt-4",Yr),children:e.jsx(io,{page:b,bot:t,derived:n,onOpen:D,editingInstructions:v,onEditInstructions:j})})]})})]})}function lo(t,n){const{state:a,flushBotPatches:o}=B(),[i,l]=x.useState(null),[d,m]=x.useState(!1),[r,c]=x.useState(null),[p,u]=x.useState(!1),k=x.useMemo(()=>JSON.stringify([t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),[t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),f=n.followEdits??!0,v=f?k:null,j=f?a.routines:null,N=f?a.webhooks:null;return x.useEffect(()=>{if(!n.overview&&!n.prompt)return;let w=!1;return(async()=>(await o(t.id),!w&&(n.overview&&Z(`/api/bots/${t.id}/overview`).then(h=>{w||(l(h),m(!1))}).catch(()=>{w||m(!0)}),n.prompt&&Z(`/api/bots/${t.id}/system-prompt`).then(h=>{w||(c(h),u(!1))}).catch(()=>{w||u(!0)}))))(),()=>{w=!0}},[t.id,n.overview,n.prompt,v,j,N,o]),{overview:i,overviewError:d,prompt:r,promptError:p}}function co(t,n){const{dispatch:a,flushBotPatches:o}=B(),[i,l]=x.useState(null),[d,m]=x.useState(!1),[r,c]=x.useState(null),p=x.useRef(0),[u,k]=x.useState(!1),[f,v]=x.useState(null),j=x.useCallback(()=>{const b=++p.current;return m(!1),o(t.id).then(()=>Z(`/api/bots/${t.id}/history?limit=100`)).then(h=>{b===p.current&&(l(h.rows),c(h.revision))}).catch(()=>{b===p.current&&m(!0)})},[t.id,o]);return x.useEffect(()=>{if(n)return j(),()=>{p.current++}},[n,j]),{rows:i,error:d,revision:r,rollingBack:u,rollbackTarget:f,setRollbackTarget:v,rollback:async b=>{if(!u){v(null),k(!0);try{await o(t.id),await Z(`/api/bots/${t.id}/history/rollback`,{method:"POST",body:JSON.stringify(b)})}catch(h){a({type:"error",message:h instanceof Error?h.message:s("botOverview.undoFailed")})}finally{await j(),k(!1)}}},requestRollback:b=>{r&&v({id:b,expectedRevision:r})}}}function po({history:t,returnFocusRef:n}){const{rollbackTarget:a,setRollbackTarget:o,rollback:i}=t;return e.jsx(_a,{open:a!==null,title:s("botOverview.restoreSoul.title"),body:s("botOverview.restoreSoul.body"),confirmLabel:s("botOverview.restoreSoul.confirm"),tone:"neutral",returnFocusRef:n,onCancel:()=>o(null),onConfirm:()=>{a&&i(a)}})}const mo={memory:"memory",skills:"skills",plugins:"plugins",folder:"access"},zs=t=>t.labelKey?s(t.labelKey):t.label;function Yt(t,n){return n?[t.label,zs(t),...t.keywords].some(a=>a.toLowerCase().includes(n)):!0}function Eo({bot:t,overlay:n=!1}){const{state:a,dispatch:o}=B(),i=a.botSettingsSection,l=Ka(t),d=x.useRef(null),{dragProps:m}=ys(),[r,c]=x.useState(""),p=!a.botSettingsExpandAccordion,u=r.trim().toLowerCase(),f=!Jt(),v=!p&&!a.botSettingsExpandRemembered?i:null,j=Os(t.id),N=Le(),w=Ua(),b=qi.filter(I=>I.id!=="plugins"||N===!0).filter(I=>I.id!=="slack"||j!==null).filter(I=>I.id!=="visibility"||!window.ogb&&N===!0&&!w),h=b.filter(I=>Yt(I,u)),{overview:P,overviewError:L,prompt:D,promptError:$}=lo(t,{overview:i==="overview"&&!f,prompt:i==="overview"&&!f}),A=co(t,i==="history"&&!f);x.useEffect(()=>{if(!p){if(u){c("");return}d.current?.querySelector(`[data-bot-settings-section="${i}"]`)?.scrollIntoView({block:"nearest"})}},[p,i,u]),x.useEffect(()=>{const I=document.activeElement instanceof HTMLElement?document.activeElement:null,g=d.current;g?.focus();const T=F=>{const _=g?.querySelector('[role="dialog"], [role="alertdialog"]');_&&_.getClientRects().length>0||g&&F.target instanceof Node&&!g.contains(F.target)||F.key==="Escape"&&!F.defaultPrevented&&(F.preventDefault(),o({type:"toggleSettings",open:!1}))};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T),I?.focus()}},[o]);const H=I=>{switch(I){case"overview":return P===null&&L?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.overviewFailed")}):e.jsx(Qi,{overview:P,refreshError:P!==null&&L,prompt:D,promptError:$,onOpen:g=>o({type:"toggleSettings",open:!0,section:g}),onSetup:l.canCoordinate&&!t.busy?()=>{o({type:"toggleSettings",open:!1}),o({type:"send",botId:t.id,text:"/setup",threadId:t.threadId})}:void 0});case"identity":return e.jsx(Ti,{bot:t,patch:l.patch,activeState:l.activeState,mascotMotion:l.mascotMotion});case"soul":return e.jsx(Ri,{bot:t,patch:l.patch});case"slack":return j?e.jsx(Xi,{managementUrl:j}):null;case"plugins":return e.jsx(Es,{bot:t},t.id);case"skills":return e.jsx(Ei,{bot:t});case"memory":return e.jsx(sr,{bot:t,active:!p&&i==="memory",onToggle:g=>l.patch({memoryEnabled:g})});case"library":return e.jsx(Fs,{bot:t,onOpen:g=>o({type:"toggleSettings",open:!0,section:mo[g]??"overview"})});case"routines":return e.jsx(Li,{bot:t,routines:l.botRoutines,runs:a.routineRuns});case"access":return e.jsx(Oi,{bot:t,derived:l});case"model":return e.jsx(Pi,{bot:t});case"permissions":return e.jsx(Ci,{bot:t,derived:l});case"voice":return e.jsx(Si,{bot:t,derived:l});case"visibility":return e.jsx(Cs,{bot:t});case"history":return A.rows===null&&A.error?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.historyFailed")}):e.jsx(rr,{bot:t,rows:A.rows,refreshError:A.rows!==null&&A.error,onRollback:A.requestRollback,rollingBack:A.rollingBack||!A.revision});case"usage":return e.jsx(or,{bot:t});default:return null}};return e.jsxs(e.Fragment,{children:[e.jsx("aside",{ref:d,id:f?qa:void 0,role:"dialog","aria-labelledby":"bot-settings-title",tabIndex:-1,className:Va(n,f),children:f?e.jsx(oo,{bot:t,derived:l,linkedSection:v,onClose:()=>o({type:"toggleSettings",open:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{...m,className:"flex shrink-0 items-center justify-between px-4 py-3",children:[e.jsx("span",{id:"bot-settings-title",className:"truncate text-[15px] font-semibold text-ink",children:t.name}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Wa,{bot:t,className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink"}),e.jsx("button",{type:"button",onClick:()=>o({type:"toggleSettings",open:!1}),"aria-label":s("botSettings.simple.close"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(st,{size:18,className:"pointer-events-none"})})]})]}),e.jsxs("div",{className:"mx-4 mb-2 flex shrink-0 items-center gap-2 rounded-lg border border-transparent bg-control/70 px-2.5 py-2 focus-within:border-focus",children:[e.jsx(tt,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{value:r,onChange:I=>{c(I.target.value),o({type:"toggleSettings",open:!0})},onKeyDown:I=>{I.key==="Escape"&&(I.stopPropagation(),r?c(""):o({type:"toggleSettings",open:!1}))},placeholder:s("botSettings.search"),"aria-label":s("botSettings.searchAria"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:[h.length===0&&e.jsx("div",{className:"px-4 py-4 text-[13px] leading-relaxed text-ink-secondary",children:s("botSettings.searchNone",{query:r.trim()})}),b.map(I=>{const{id:g,icon:T}=I,F=zs(I),_=Yt(I,u);if(!_&&g!=="memory")return null;const K=!p&&i===g;return e.jsxs("div",{"data-bot-settings-section":g,className:"border-b border-hairline/30",hidden:!_,children:[e.jsxs("button",{type:"button",onClick:()=>{if(i===g&&!p){o({type:"toggleSettings",open:!0});return}o({type:"toggleSettings",open:!0,section:g})},"aria-expanded":K,className:O("flex w-full shrink-0 items-center gap-2.5 px-4 py-2.5 text-left text-[14px]",K?"bg-control/60 text-ink":"text-ink-secondary hover:bg-control/40 hover:text-ink"),children:[e.jsx(T,{size:15,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:F}),e.jsx(fe,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",K&&"rotate-180")})]}),g==="memory"?e.jsx("div",{hidden:!K,className:"px-4 pb-4 pt-1",children:H("memory")}):K&&e.jsx("div",{className:"px-4 pb-4 pt-1",children:H(g)})]},g)})]})]})}),e.jsx(po,{history:A,returnFocusRef:d})]})}export{Eo as BotSettingsDialog};