limixbot 0.3.159 → 0.3.161

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 (139) hide show
  1. package/dist/assets/{ActivityPanel-Cdo1dBIm.js → ActivityPanel-D4K2fyw7.js} +1 -1
  2. package/dist/assets/{App-Cs_sQgN3.js → App-B6W9JFXZ.js} +123 -123
  3. package/dist/assets/{AppEventEditor-LKd22lmx.js → AppEventEditor-OWWzSxPd.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog--5NZgIuz.js → BotSettingsDialog-W_eO05D2.js} +7 -7
  5. package/dist/assets/{BrowserPanel-Eq7Ln2F-.js → BrowserPanel-C0NOYaOK.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-BFS9rfCH.js → BrowserProfilesManager-48HNAHJm.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-B5SV-dNM.js → CloudAddDialog-RDN92Hbu.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-BkqxPiGz.js → ComputerFilesPane-HhCIEUQ4.js} +1 -1
  9. package/dist/assets/{ComputerPanel-BcHGUiuP.js → ComputerPanel-C8ZuT_hf.js} +2 -2
  10. package/dist/assets/{DataPanel-Dx1TirKY.js → DataPanel-CEPYRb_t.js} +1 -1
  11. package/dist/assets/{DesktopViewer-BZBWLKHf.js → DesktopViewer-Rhj5Rg_E.js} +1 -1
  12. package/dist/assets/{GrokMoveDialog-DSCiPkeR.js → GrokMoveDialog-BEkVuGJs.js} +1 -1
  13. package/dist/assets/{InspectorPanel-DvdMSUcV.js → InspectorPanel-CYwO5Hpk.js} +1 -1
  14. package/dist/assets/{KeyboardShortcutsModal-CAE7w-Wr.js → KeyboardShortcutsModal-CvoUyPNv.js} +1 -1
  15. package/dist/assets/{KnowledgePanel-DnrNUt4C.js → KnowledgePanel-Crh_Mb2-.js} +1 -1
  16. package/dist/assets/{LimixResizeHandles-BS339Uq8.js → LimixResizeHandles-ByutmqfH.js} +1 -1
  17. package/dist/assets/{LiveDesktop-BcFA7umB.js → LiveDesktop-DZV6iCg2.js} +1 -1
  18. package/dist/assets/{LocalVmWorkspace-BG20R05j.js → LocalVmWorkspace-C82LcwJQ.js} +1 -1
  19. package/dist/assets/{MacLocalControl-B-MIWO9N.js → MacLocalControl-Bx_fyo-H.js} +1 -1
  20. package/dist/assets/{MarkdownFilePreview-aNqcmjPH.js → MarkdownFilePreview-BXNCSmvg.js} +1 -1
  21. package/dist/assets/{MenuMotion-BanPNWqt.js → MenuMotion-xBTC4eOZ.js} +1 -1
  22. package/dist/assets/{NewBotDialog-CPFz45h8.js → NewBotDialog-D0agPdOC.js} +1 -1
  23. package/dist/assets/{PhoneAppDialog-DFR6MxK9.js → PhoneAppDialog-DQpyRnEJ.js} +1 -1
  24. package/dist/assets/{PlacesRail-cbzNti8k.js → PlacesRail-fw4FbMbq.js} +1 -1
  25. package/dist/assets/{PluginsPanel-SsAQcstw.js → PluginsPanel-C4HY0lnL.js} +1 -1
  26. package/dist/assets/{ProIntroduction-DZXB6xh2.js → ProIntroduction-BO5ABFTi.js} +1 -1
  27. package/dist/assets/{RemoteAgentSettingsPanel-DW7HjrZ-.js → RemoteAgentSettingsPanel-D0vIEaec.js} +1 -1
  28. package/dist/assets/{RoomPanel-BX6oOzAJ.js → RoomPanel-KgR5RAVc.js} +1 -1
  29. package/dist/assets/{RoutinesPage-xZq6f7F7.js → RoutinesPage-CFb9pR_B.js} +1 -1
  30. package/dist/assets/{SettingsModal-D4xDVhBl.js → SettingsModal-CBovr73q.js} +8 -8
  31. package/dist/assets/{ShareTeamDialog-B8dsAay0.js → ShareTeamDialog-E7_x3dOd.js} +1 -1
  32. package/dist/assets/{SignedInSites-CwXZYrPd.js → SignedInSites-tgZ-kFN4.js} +1 -1
  33. package/dist/assets/{TeamLibraryPanel-DHK2epUq.js → TeamLibraryPanel-DA7R6knC.js} +1 -1
  34. package/dist/assets/{TeamMapPage-DlJ87yR6.js → TeamMapPage-CrEl0669.js} +1 -1
  35. package/dist/assets/{TriggersPage-BkfOweI0.js → TriggersPage-DoApzhWG.js} +1 -1
  36. package/dist/assets/VisibilitySection-ChKxjJ5C.js +22 -0
  37. package/dist/assets/{WebhookTrigger-DNNVhUXR.js → WebhookTrigger-B_VHQtPd.js} +1 -1
  38. package/dist/assets/{WorksOnGrid-CXKUHPY-.js → WorksOnGrid-CBZxKyOV.js} +1 -1
  39. package/dist/assets/{abnfDiagram-YUKMZFIV-T1re1jGp.js → abnfDiagram-YUKMZFIV-B9vpInYU.js} +1 -1
  40. package/dist/assets/{activity-ME_qLdss.js → activity-C1tmKAiO.js} +1 -1
  41. package/dist/assets/{architectureDiagram-47P4ROYG-qqDKVS6g.js → architectureDiagram-47P4ROYG-B9ymIDha.js} +1 -1
  42. package/dist/assets/{blockDiagram-E7TT5TSB-BuC572BY.js → blockDiagram-E7TT5TSB-DNFty3Tc.js} +1 -1
  43. package/dist/assets/{c4Diagram-CRA5TL53-nip4Y8hp.js → c4Diagram-CRA5TL53-MMvdoF22.js} +1 -1
  44. package/dist/assets/{calendar-days--KsT6bHs.js → calendar-days-DMbqxmdo.js} +1 -1
  45. package/dist/assets/channel-D6UpO6dv.js +1 -0
  46. package/dist/assets/{chunk-2Q5K7J3B-Bnqnzpvn.js → chunk-2Q5K7J3B-Dbvx3IUy.js} +1 -1
  47. package/dist/assets/{chunk-5VM5RSS4-CXFOIYDF.js → chunk-5VM5RSS4-Bv4tGTc_.js} +1 -1
  48. package/dist/assets/{chunk-7TKQ45FW-CKrdRfeX.js → chunk-7TKQ45FW-CTWHE5Z7.js} +1 -1
  49. package/dist/assets/{chunk-AW2ZBBNX-COP_kkGp.js → chunk-AW2ZBBNX-o4mtkbiH.js} +1 -1
  50. package/dist/assets/{chunk-FVRAUYC3-Bnxu_UJy.js → chunk-FVRAUYC3-bk4P4ylI.js} +2 -2
  51. package/dist/assets/{chunk-HTAEGDNF-Blc4NKLJ.js → chunk-HTAEGDNF-xXImTXlw.js} +1 -1
  52. package/dist/assets/{chunk-JWPE2WC7-0DUEaslJ.js → chunk-JWPE2WC7-fJsfWv1C.js} +1 -1
  53. package/dist/assets/{chunk-KQW6MTUR-nzkuoYgY.js → chunk-KQW6MTUR-BfdY-FQt.js} +1 -1
  54. package/dist/assets/{chunk-XXDRQBXY-CKXQy0NJ.js → chunk-XXDRQBXY-tv73di0t.js} +1 -1
  55. package/dist/assets/{classDiagram-v2-K4WV4PDN-BalScTvc.js → classDiagram-v2-K4WV4PDN-zMRuBGqC.js} +1 -1
  56. package/dist/assets/{coins-CINwwKBz.js → coins-DRetD1sY.js} +1 -1
  57. package/dist/assets/{core-CjJabOYi.js → core-DXs_9m1L.js} +1 -1
  58. package/dist/assets/{cose-bilkent-JH36ORCC-B8gYHVgP.js → cose-bilkent-JH36ORCC-DZuqoYX_.js} +1 -1
  59. package/dist/assets/{cynefin-EF2NZ3EQ-DLIydYUM.js → cynefin-EF2NZ3EQ-DSgkFo85.js} +1 -1
  60. package/dist/assets/{cynefinDiagram-3GCD6N5R-CPW3HX3C.js → cynefinDiagram-3GCD6N5R-CosHssEi.js} +1 -1
  61. package/dist/assets/{dagre-W4DXFKR2-BmO4lMA3.js → dagre-W4DXFKR2-Bdl477yX.js} +1 -1
  62. package/dist/assets/{diagram-2UJZ2QOL-WNbWLgdx.js → diagram-2UJZ2QOL-BxLY64qg.js} +1 -1
  63. package/dist/assets/{diagram-OVF4WLC6-DxouP33f.js → diagram-OVF4WLC6-CQZ9vBZU.js} +1 -1
  64. package/dist/assets/{diagram-PFPMY2P6-BYQSRoRr.js → diagram-PFPMY2P6-DD3ObzdI.js} +1 -1
  65. package/dist/assets/{diagram-UMYRVEAY-MH7Rac62.js → diagram-UMYRVEAY-CtkMUmqw.js} +1 -1
  66. package/dist/assets/{diagram-YEKJPTXX-_sMOi7in.js → diagram-YEKJPTXX-CrVhZFfx.js} +1 -1
  67. package/dist/assets/{diagram-ZIFT7M5P-AXHi3F5b.js → diagram-ZIFT7M5P-D2gNTqtm.js} +1 -1
  68. package/dist/assets/{ebnfDiagram-VR2GEFS7-LVOSbU4Q.js → ebnfDiagram-VR2GEFS7-DbIJRYrm.js} +1 -1
  69. package/dist/assets/{elk-IJKZMXRS-DnUKKiZ4.js → elk-IJKZMXRS-D7Nf3yON.js} +1 -1
  70. package/dist/assets/{erDiagram-O2IAPWRE-C4TtBzjI.js → erDiagram-O2IAPWRE-Bzm5GzY4.js} +1 -1
  71. package/dist/assets/{file-up-CqRrWw_K.js → file-up-DMaJmosg.js} +1 -1
  72. package/dist/assets/{flowDiagram-OXPTDLAJ-D4Ba6z7o.js → flowDiagram-OXPTDLAJ-BKoqAa_q.js} +1 -1
  73. package/dist/assets/{ganttDiagram-R7TSEDQI-BKyQw4h2.js → ganttDiagram-R7TSEDQI-BSKWWYpy.js} +1 -1
  74. package/dist/assets/{gitGraphDiagram-XJZIOB7I-dHlQDpAX.js → gitGraphDiagram-XJZIOB7I-DgpLQY2o.js} +1 -1
  75. package/dist/assets/{import-name-D7fiWRLC.js → import-name-DviM_E6k.js} +1 -1
  76. package/dist/assets/{index-Cx0TrR7Z.js → index-Bh1qTRXw.js} +3 -3
  77. package/dist/assets/{index-DYywZ7Dm.js → index-kl2U4CdS.js} +1 -1
  78. package/dist/assets/{infoDiagram-5W2HQ5XZ-C1_zxT3L.js → infoDiagram-5W2HQ5XZ-DoodC8bc.js} +1 -1
  79. package/dist/assets/{ishikawaDiagram-K3B6WC7H-D49-s4e6.js → ishikawaDiagram-K3B6WC7H-BxXRcPmI.js} +1 -1
  80. package/dist/assets/{journeyDiagram-COXZFDF6-Cw7pDpwe.js → journeyDiagram-COXZFDF6-DtSJ97ol.js} +1 -1
  81. package/dist/assets/{kanban-definition-P3RFRI5V-CiEVfjhJ.js → kanban-definition-P3RFRI5V-DCW9s12w.js} +1 -1
  82. package/dist/assets/{mermaid.core-DXRspYvN.js → mermaid.core-CaG3BHp-.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LZFPQGKD-BE4A5xqi.js → mindmap-definition-LZFPQGKD-CI0l83_i.js} +1 -1
  84. package/dist/assets/{minimize-B06xVF0X.js → minimize-LlGLn-cd.js} +1 -1
  85. package/dist/assets/{monitor-ylRMuFnb.js → monitor-D-rHzZVy.js} +1 -1
  86. package/dist/assets/{new-bot-DylEMxP3.js → new-bot-78Wk4hfY.js} +1 -1
  87. package/dist/assets/{org-library-C2VYVL97.js → org-library-tkloWFxW.js} +1 -1
  88. package/dist/assets/{package-format-DFYqwtTY.js → package-format-nQAkOC1F.js} +1 -1
  89. package/dist/assets/{pegDiagram-BGZESJAR-CFRdko2m.js → pegDiagram-BGZESJAR-Cz5M4kqt.js} +1 -1
  90. package/dist/assets/{pieDiagram-CAPJLFHJ-DSxoFQy1.js → pieDiagram-CAPJLFHJ-C98cn5QM.js} +1 -1
  91. package/dist/assets/{quadrantDiagram-GDMTTRAM-CjsJyYiF.js → quadrantDiagram-GDMTTRAM-C5NU7SoI.js} +1 -1
  92. package/dist/assets/{rail-C19iSV-q.js → rail-Ct_mmLes.js} +1 -1
  93. package/dist/assets/{railroadDiagram-SM67HX2B-CllshBKq.js → railroadDiagram-SM67HX2B-GaVaWWOo.js} +1 -1
  94. package/dist/assets/{remote-desktop-panel-BZTQhq8G.js → remote-desktop-panel-ByE5Ghzy.js} +1 -1
  95. package/dist/assets/{requirementDiagram-X7JNWC4A-DZRv-heI.js → requirementDiagram-X7JNWC4A-C5wckjoU.js} +1 -1
  96. package/dist/assets/{sankeyDiagram-UM26HJRW-CyPjr28L.js → sankeyDiagram-UM26HJRW-DdVehWU6.js} +1 -1
  97. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-D1U7Kq6G.js → sequenceDiagram-ZO4K6R2Y-eBbzhCW8.js} +1 -1
  98. package/dist/assets/{sizeCapture-INFHLROL-B5DQZxxP.js → sizeCapture-INFHLROL-DQyTTXfY.js} +1 -1
  99. package/dist/assets/{stateDiagram-v2-TBUQTH76-BhYzDBGj.js → stateDiagram-v2-TBUQTH76-8vBTNLu_.js} +1 -1
  100. package/dist/assets/styles-Ck7XEMka.css +1 -0
  101. package/dist/assets/{styles-C8d057NY.js → styles-DnkNzLDs.js} +7 -7
  102. package/dist/assets/{swimlanes-N4OXWK64-DRXo5_ln.js → swimlanes-N4OXWK64-B9vus97I.js} +1 -1
  103. package/dist/assets/swimlanesDiagram-K3J5GTZL-D3jmYauw.js +8 -0
  104. package/dist/assets/{team-share-ijObVLAA.js → team-share-DwBBsedz.js} +1 -1
  105. package/dist/assets/{timeline-definition-YOQAKGHF-CTE0vbtk.js → timeline-definition-YOQAKGHF-s3tn3RzT.js} +1 -1
  106. package/dist/assets/{usecaseDiagram-VIAY4XPW-CkN6xroI.js → usecaseDiagram-VIAY4XPW-88H9jUqs.js} +1 -1
  107. package/dist/assets/{vennDiagram-BLWOH2XV-bFXRahK5.js → vennDiagram-BLWOH2XV-CPFZmxPQ.js} +1 -1
  108. package/dist/assets/{vi-YIuoqNub.js → vi-QjCGytsv.js} +1 -1
  109. package/dist/assets/{wardleyDiagram-YMQ3BMBF-CeYkXfd8.js → wardleyDiagram-YMQ3BMBF-Be_1GpZE.js} +1 -1
  110. package/dist/assets/{xychartDiagram-TAQBALBS-j5MQYrHi.js → xychartDiagram-TAQBALBS-C1zZX1ko.js} +1 -1
  111. package/dist/index.html +3 -3
  112. package/dist/rail.html +5 -5
  113. package/dist-server/cloud-home-start.js +4 -4
  114. package/dist-server/container-mcp.js +10 -10
  115. package/dist-server/index.js +5210 -5187
  116. package/dist-server/limixbot.js +83 -81
  117. package/dist-server/package.json +1 -1
  118. package/dist-server/pair-cli.js +83 -81
  119. package/dist-server/server/cloud-home-start.js +1 -0
  120. package/dist-server/server/drivers/acp/core.js +4 -3
  121. package/dist-server/server/drivers/claude.js +6 -1
  122. package/dist-server/server/drivers/codex.js +12 -2
  123. package/dist-server/server/fcc-endpoint.js +77 -0
  124. package/dist-server/server/index.js +22 -4
  125. package/dist-server/server/new-bot-defaults.js +2 -0
  126. package/dist-server/server/routes/bot-patch.js +9 -0
  127. package/dist-server/server/routes/bots-create.js +11 -1
  128. package/dist-server/server/routes/groups.js +12 -0
  129. package/dist-server/server/routes/instances.js +40 -0
  130. package/dist-server/server/working-folders.js +141 -0
  131. package/dist-server/server/workspace.js +2 -0
  132. package/dist-server/shared/working-folders.js +1 -0
  133. package/dist-server/vps-container-mcp.js +10 -10
  134. package/dist-server/workspace-backup.worker.js +10 -10
  135. package/package.json +1 -1
  136. package/dist/assets/VisibilitySection-Du5EURZP.js +0 -22
  137. package/dist/assets/channel-BxasM4SP.js +0 -1
  138. package/dist/assets/styles-Cjm60Wtn.css +0 -1
  139. package/dist/assets/swimlanesDiagram-K3J5GTZL-Cej5tKCL.js +0 -8
@@ -1,16 +1,16 @@
1
- import{c as Ae,t as s,m as ee,aG as Vs,j as e,i as Fe,af as fe,a as O,r as m,S as tt,ai as Jt,l as S,X as st,d as pt}from"./styles-C8d057NY.js";import{fu as Gs,fv as Zs,Z as nt,f6 as Qt,bD as Ys,du as Xt,C as Js,bV as Qs,fw as Xs,D as es,fx as en,K as ts,eD as tn,p as sn,fy as mt,bt as ut,fz as ss,j as G,u as B,fA as xt,fB as ht,f7 as ie,fC as nn,fD as an,fE as rn,fF as on,af as at,ae as ns,A as as,S as be,aa as Me,T as is,R as ln,fG as cn,fH as dn,fI as pn,fJ as mn,fK as un,fL as gt,fM as xn,fN as hn,fO as gn,fP as fn,a_ as yn,fQ as bn,fR as vn,fS as kn,I as jn,fT as Oe,b_ as Le,fU as wn,aG as M,aM as Q,en as Nn,dV as Sn,fV as Cn,aH as Ze,cA as Pn,e8 as On,e9 as En,fW as Rn,fX as rs,fY as os,fZ as Tn,f_ as In,f$ as An,g0 as Mn,dY as Ye,ap as ft,g1 as ze,g2 as Ln,g3 as Re,at as Bn,g4 as ls,g5 as yt,ai as Je,g6 as $n,g7 as Dn,g8 as Fn,g9 as cs,ga as zn,gb as bt,gc as Hn,gd as _n,ge as Kn,gf as te,aW as ae,aY as X,gg as Un,gh as qn,gi as Wn,dg as Vn,aO as Gn,G as Zn,de as ds,ah as Yn,gj as V,aV as me,gk as ue,gl as Jn,dz as Qn,gm as Be,aX as le,gn as Xn,go as ea,gp as ta,er as sa,gq as vt,gr as na,gs as aa,gt as ia,gu as ra,gv as oa,gw as la,ay as ca,gx as ps,gy as ms,gz as da,gA as pa,gB as ma,gC as ua,gD as xa,gE as ha,gF as ga,gG as fa,gH as ya,gI as us,gJ as ba,gK as va,gL as ka,gM as it,g as ja,B as Qe,gN as wa,gO as Na,gP as Sa,gQ as Ca,gR as Pa,gS as Oa,c7 as Ea,gT as xs,z as kt,gU as Ra,fa as Ta,gV as jt,gW as Ia,gX as Aa,gY as Ma,cX as wt,bB as La,dd as Ba,gZ as $a,g_ as hs,g$ as Ce,h0 as Nt,h1 as Da,aK as He,ea as Fa,h2 as za,aQ as Ha,dD as _a,cB as Ka,h3 as Ua,h4 as qa,h5 as Wa,aS as Va}from"./App-Cs_sQgN3.js";import{v as gs,d as we,a0 as Te,a1 as Ga,a2 as Za,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-cbzNti8k.js";import{C as ri}from"./coins-CINwwKBz.js";import{C as je,a as oi}from"./MenuMotion-BanPNWqt.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-Du5EURZP.js";import{s as Ii,r as Ai,a as Mi,R as Li}from"./ComputerFilesPane-BkqxPiGz.js";import{M as Tt}from"./monitor-ylRMuFnb.js";import{R as Bi}from"./RoutinesPage-xZq6f7F7.js";import{S as $i}from"./SignedInSites-CwXZYrPd.js";import"./index-Cx0TrR7Z.js";import"./org-library-C2VYVL97.js";import"./package-format-DFYqwtTY.js";import"./WorksOnGrid-CXKUHPY-.js";import"./ProIntroduction-DZXB6xh2.js";import"./remote-desktop-DDRRx8uY.js";const Di=[["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"}]],Fi=Ae("calendar-plus",Di);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:Gs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Zs,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)})}],Gi=t=>ee()!=="en"&&Object.hasOwn(Vs[ee()]??{},t);function Zi(t,n){for(const a of Vi){const l=a.line.exec(t);if(!l)continue;const i=a.key(l);return Gi(i)?s(i,a.params(l,n)):t}return null}function Ue(t,n){if(Object.hasOwn(At,t))return s(At[t]);const a=Zi(t,n);if(a!==null)return a;const l=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(l)return s(l[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(l[1]),apps:l[2]});const 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 o=/^Computer preference: (.+)\.$/.exec(t);if(o)return s("botOverview.line.computer",{preference:Bt(o[1])});const c=/^Works in (.+)\.$/.exec(t);if(c)return s("botOverview.line.folder",{folder:c[1]});const p=/^Knows how to (.+)\.$/.exec(t);if(p)return s("botOverview.line.skill",{skill:p[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 Yi(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 Ji({data:t,error:n,open:a,onToggle:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:l,"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(Fe()),tokens:t.approxTokens.toLocaleString(Fe())}):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(Fe())})})]}),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:l,onOpen:i,onSetup:o}){const[c,p]=m.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const d=(t.setup??[]).filter(x=>!x.done),u=(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")}),d.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:d.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(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:u(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(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:u(x.id,x.label)})]})},x.id))}),o&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:o,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:Wi(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(Ji,{data:a,error:l,open:c,onToggle:()=>p(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:Yi(x.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",ss(x.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]=m.useState(null);return m.useEffect(()=>{const l=new AbortController;return G(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:l.signal,timeoutMs:1e4}).then(i=>{l.signal.aborted||a({botId:t,url:er(i)})}).catch(()=>{l.signal.aborted||a({botId:t,url:null})}),()=>l.abort()},[t]),n?.botId===t?n.url:null}const Ft="/api/limix/plugins";function Es({bot:t}){const{state:n,dispatch:a}=B(),[l,i]=m.useState(),[o,c]=m.useState(""),[p,r]=m.useState(!1),d=ee().startsWith("vi")?"vi":"en";m.useEffect(()=>{if(n.pluginsOpen)return;const x=new AbortController;return G(Ft,{signal:x.signal}).then(i).catch(k=>{x.signal.aborted||c(xt(k.message))}),()=>x.abort()},[n.pluginsOpen]);async function u(x,k,f){r(!0),c("");try{i(await G(Ft,{method:"POST",body:JSON.stringify({action:"assign",target:"bot",key:t.id,id:x,sha256:k,enabled:f})}))}catch(v){c(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")}),o&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:o}),!l&&!o&&e.jsx("p",{role:"status",className:"text-sm text-ink-secondary",children:ie("Đang tải plugin…","Loading plugins…")}),l?.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.")}),l?.installed.map(x=>{const f=!Object.hasOwn(x.bots,t.id)?"inherit":String(x.bots[t.id]),v=nn(x,t,l.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(an,{icon:x.manifest?.icon??rn(x.id,x.name.en,x.name.vi,...x.requiresMcp),compact:!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h3",{className:"break-words text-sm font-semibold",children:[x.name[d]," ",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:ht,value:f,disabled:p,"aria-label":x.name[d]+" v"+x.version,onChange:N=>{u(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,o,c)=>{i&&n.push(s(i===1?o:c,{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 l=n.length?n.join(", "):s("memory.upkeep.summary.none");return l.charAt(0).toUpperCase()+l.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"),l=ui(t.path),i=t.path===se?l:t.path===xi?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:l}):s("memory.journal.topic",{file:l}),o=c=>s(c===1?"memory.journal.line.one":"memory.journal.line.many",{count:c});return t.kind==="created"?s("memory.journal.created",{who:a,topic:i,detail:t.added?s("memory.journal.withLines",{lines:o(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:a,topic:i}):t.added&&!t.removed?s("memory.journal.added",{who:a,lines:o(t.added),topic:i}):t.removed&&!t.added?s("memory.journal.removed",{who:a,lines:o(t.removed),topic:i}):s("memory.journal.rewrote",{who:a,lines:o(Math.max(t.added,t.removed)),topic:i})}function Ts({changed:t,stale:n,busy:a,onReviewed:l}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(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:l,children:s("memory.lendingReviewed")})]})}function sr({bot:t,active:n=!0,onToggle:a}){const{capabilities:l}=we(),[i,o]=m.useState(null),[c,p]=m.useState(null),[r,d]=m.useState(null),[u,x]=m.useState(null),[k,f]=m.useState(null),[v,j]=m.useState(null),[N,w]=m.useState(null),[b,h]=m.useState(!1),[P,L]=m.useState(null),[F,$]=m.useState(""),[A,H]=m.useState(null),[I,g]=m.useState(!1),[T,D]=m.useState(null),[_,K]=m.useState(!1),[J,Y]=m.useState(!1),{state:U,dispatch:y}=B(),z=on(U.config),[ce,xe]=m.useState(!1),[ye,E]=m.useState(""),q=async C=>{const[R,$e,Ws]=await Promise.all([rt(t.id),ge(t.id),Pt(t.id).catch(()=>null)]);if(o(R),D(R.lendingReview??null),p($e),H(Ws),C){const De=await Ie(t.id,C);d({path:De.path,text:De.text,hash:De.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}};m.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 Z=async C=>{j(null),x(null);try{const R=await Ie(t.id,C);d({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){x({path:r.path,current:R.current,currentHash:R.currentHash});return}x(null),f(null),d({...r,text:R.doc.text,hash:R.doc.hash,dirty:!1}),o(R.overview),p(await ge(t.id))}catch(R){j(re(R))}finally{h(!1)}}},de=()=>{!u||!r||(f(r.text),d({...r,text:u.current,hash:u.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);o(R),p(await ge(t.id)),r?.path===C.path&&d(null)}catch(R){j(re(R))}}},ct=async()=>{const C=di(F);if(!C){j(s("memory.topicNameError"));return}$(""),await Z(`memory/${C}`),d(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);o(R.overview),p(await ge(t.id)),r?.path===C.path&&!r.dirty&&d({...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 G("/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);o(R),p(await ge(t.id)),H(await Pt(t.id)),r&&!r.dirty&&await Z(r.path),w(`${Rs(C)}.${C.note?` ${C.note}`:""}`)}catch(C){j(re(C))}finally{g(!1)}},qs=l.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange: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(()=>{D(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:()=>{Z(se)},children:s("memory.backToIndex")})]}),u&&e.jsx(Is,{botName:t.name,busy:b,onReload:de,onOverwrite:()=>{W(u.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=>d({...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:()=>{Z(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=>{Z(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:F,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:!F.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=>{Z(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:c,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`---
1
+ import{c as Ae,t as s,m as ee,aG as Vs,j as e,i as Fe,af as fe,a as O,r as m,S as tt,ai as Jt,l as S,X as st,d as pt}from"./styles-DnkNzLDs.js";import{fu as Gs,fv as Zs,Z as nt,f6 as Qt,bD as Ys,du as Xt,C as Js,bV as Qs,fw as Xs,D as es,fx as en,K as ts,eD as tn,p as sn,fy as mt,bt as ut,fz as ss,j as G,u as B,fA as xt,fB as ht,f7 as ie,fC as nn,fD as an,fE as rn,fF as on,af as at,ae as ns,A as as,S as be,aa as Me,T as is,R as ln,fG as cn,fH as dn,fI as pn,fJ as mn,fK as un,fL as gt,fM as xn,fN as hn,fO as gn,fP as fn,a_ as yn,fQ as bn,fR as vn,fS as kn,I as jn,fT as Oe,b_ as Le,fU as wn,aG as M,aM as Q,en as Nn,dV as Sn,fV as Cn,aH as Ze,cA as Pn,e8 as On,e9 as En,fW as Rn,fX as rs,fY as os,fZ as Tn,f_ as In,f$ as An,g0 as Mn,dY as Ye,ap as ft,g1 as ze,g2 as Ln,g3 as Re,at as Bn,g4 as ls,g5 as yt,ai as Je,g6 as $n,g7 as Dn,g8 as Fn,g9 as cs,ga as zn,gb as bt,gc as Hn,gd as _n,ge as Kn,gf as te,aW as ae,aY as X,gg as Un,gh as qn,gi as Wn,dg as Vn,aO as Gn,G as Zn,de as ds,ah as Yn,gj as V,aV as me,gk as ue,gl as Jn,dz as Qn,gm as Be,aX as le,gn as Xn,go as ea,gp as ta,er as sa,gq as vt,gr as na,gs as aa,gt as ia,gu as ra,gv as oa,gw as la,ay as ca,gx as ps,gy as ms,gz as da,gA as pa,gB as ma,gC as ua,gD as xa,gE as ha,gF as ga,gG as fa,gH as ya,gI as us,gJ as ba,gK as va,gL as ka,gM as it,g as ja,B as Qe,gN as wa,gO as Na,gP as Sa,gQ as Ca,gR as Pa,gS as Oa,c7 as Ea,gT as xs,z as kt,gU as Ra,fa as Ta,gV as jt,gW as Ia,gX as Aa,gY as Ma,cX as wt,bB as La,dd as Ba,gZ as $a,g_ as hs,g$ as Ce,h0 as Nt,h1 as Da,aK as He,ea as Fa,h2 as za,aQ as Ha,dD as _a,cB as Ka,h3 as Ua,h4 as qa,h5 as Wa,aS as Va}from"./App-B6W9JFXZ.js";import{v as gs,d as we,a0 as Te,a1 as Ga,a2 as Za,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-fw4FbMbq.js";import{C as ri}from"./coins-DRetD1sY.js";import{C as je,a as oi}from"./MenuMotion-xBTC4eOZ.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,K as wi,O as Ni,L as Si,N as Cs,Q as Rt,V as Ci,P as Pi,M as Oi,A as Ei,a as Ri,S as Ti,I as Ii}from"./VisibilitySection-ChKxjJ5C.js";import{s as Ai,r as Mi,a as Li,R as Bi}from"./ComputerFilesPane-HhCIEUQ4.js";import{M as Tt}from"./monitor-D-rHzZVy.js";import{R as $i}from"./RoutinesPage-CFb9pR_B.js";import{S as Di}from"./SignedInSites-tgZ-kFN4.js";import"./index-Bh1qTRXw.js";import"./org-library-tkloWFxW.js";import"./package-format-nQAkOC1F.js";import"./WorksOnGrid-CBZxKyOV.js";import"./ProIntroduction-BO5ABFTi.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"}]],zi=Ae("calendar-plus",Fi);const Hi=[["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"}]],_i=Ae("library",Hi);const Ki=[["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",Ki);const Ui=[["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"}]],qi=Ae("tag",Ui),Wi=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Gs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:Zs,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:_i,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 Vi(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,Gi=[{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 Yi(t,n){for(const a of Gi){const l=a.line.exec(t);if(!l)continue;const i=a.key(l);return Zi(i)?s(i,a.params(l,n)):t}return null}function Ue(t,n){if(Object.hasOwn(At,t))return s(At[t]);const a=Yi(t,n);if(a!==null)return a;const l=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(l)return s(l[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(l[1]),apps:l[2]});const 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 o=/^Computer preference: (.+)\.$/.exec(t);if(o)return s("botOverview.line.computer",{preference:Bt(o[1])});const c=/^Works in (.+)\.$/.exec(t);if(c)return s("botOverview.line.folder",{folder:c[1]});const p=/^Knows how to (.+)\.$/.exec(t);if(p)return s("botOverview.line.skill",{skill:p[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 Ji(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 Qi({data:t,error:n,open:a,onToggle:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:l,"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(Fe()),tokens:t.approxTokens.toLocaleString(Fe())}):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(Fe())})})]}),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 Xi({overview:t,refreshError:n,prompt:a,promptError:l,onOpen:i,onSetup:o}){const[c,p]=m.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const d=(t.setup??[]).filter(x=>!x.done),u=(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")}),d.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:d.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(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:u(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(ut,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:u(x.id,x.label)})]})},x.id))}),o&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:o,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:Vi(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(Qi,{data:a,error:l,open:c,onToggle:()=>p(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:Ji(x.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",ss(x.at)]})]},k))})]})]})}function er({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 tr(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]=m.useState(null);return m.useEffect(()=>{const l=new AbortController;return G(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:l.signal,timeoutMs:1e4}).then(i=>{l.signal.aborted||a({botId:t,url:tr(i)})}).catch(()=>{l.signal.aborted||a({botId:t,url:null})}),()=>l.abort()},[t]),n?.botId===t?n.url:null}const Ft="/api/limix/plugins";function Es({bot:t}){const{state:n,dispatch:a}=B(),[l,i]=m.useState(),[o,c]=m.useState(""),[p,r]=m.useState(!1),d=ee().startsWith("vi")?"vi":"en";m.useEffect(()=>{if(n.pluginsOpen)return;const x=new AbortController;return G(Ft,{signal:x.signal}).then(i).catch(k=>{x.signal.aborted||c(xt(k.message))}),()=>x.abort()},[n.pluginsOpen]);async function u(x,k,f){r(!0),c("");try{i(await G(Ft,{method:"POST",body:JSON.stringify({action:"assign",target:"bot",key:t.id,id:x,sha256:k,enabled:f})}))}catch(v){c(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")}),o&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:o}),!l&&!o&&e.jsx("p",{role:"status",className:"text-sm text-ink-secondary",children:ie("Đang tải plugin…","Loading plugins…")}),l?.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.")}),l?.installed.map(x=>{const f=!Object.hasOwn(x.bots,t.id)?"inherit":String(x.bots[t.id]),v=nn(x,t,l.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(an,{icon:x.manifest?.icon??rn(x.id,x.name.en,x.name.vi,...x.requiresMcp),compact:!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h3",{className:"break-words text-sm font-semibold",children:[x.name[d]," ",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:ht,value:f,disabled:p,"aria-label":x.name[d]+" v"+x.version,onChange:N=>{u(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,o,c)=>{i&&n.push(s(i===1?o:c,{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 l=n.length?n.join(", "):s("memory.upkeep.summary.none");return l.charAt(0).toUpperCase()+l.slice(1)}function sr(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"),l=ui(t.path),i=t.path===se?l:t.path===xi?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:l}):s("memory.journal.topic",{file:l}),o=c=>s(c===1?"memory.journal.line.one":"memory.journal.line.many",{count:c});return t.kind==="created"?s("memory.journal.created",{who:a,topic:i,detail:t.added?s("memory.journal.withLines",{lines:o(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:a,topic:i}):t.added&&!t.removed?s("memory.journal.added",{who:a,lines:o(t.added),topic:i}):t.removed&&!t.added?s("memory.journal.removed",{who:a,lines:o(t.removed),topic:i}):s("memory.journal.rewrote",{who:a,lines:o(Math.max(t.added,t.removed)),topic:i})}function Ts({changed:t,stale:n,busy:a,onReviewed:l}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(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:l,children:s("memory.lendingReviewed")})]})}function nr({bot:t,active:n=!0,onToggle:a}){const{capabilities:l}=we(),[i,o]=m.useState(null),[c,p]=m.useState(null),[r,d]=m.useState(null),[u,x]=m.useState(null),[k,f]=m.useState(null),[v,j]=m.useState(null),[N,w]=m.useState(null),[b,h]=m.useState(!1),[P,L]=m.useState(null),[F,$]=m.useState(""),[A,H]=m.useState(null),[I,g]=m.useState(!1),[T,D]=m.useState(null),[_,K]=m.useState(!1),[J,Y]=m.useState(!1),{state:U,dispatch:y}=B(),z=on(U.config),[ce,xe]=m.useState(!1),[ye,E]=m.useState(""),q=async C=>{const[R,$e,Ws]=await Promise.all([rt(t.id),ge(t.id),Pt(t.id).catch(()=>null)]);if(o(R),D(R.lendingReview??null),p($e),H(Ws),C){const De=await Ie(t.id,C);d({path:De.path,text:De.text,hash:De.hash,dirty:!1,readOnly:C.startsWith("memory/log/")})}};m.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 Z=async C=>{j(null),x(null);try{const R=await Ie(t.id,C);d({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){x({path:r.path,current:R.current,currentHash:R.currentHash});return}x(null),f(null),d({...r,text:R.doc.text,hash:R.doc.hash,dirty:!1}),o(R.overview),p(await ge(t.id))}catch(R){j(re(R))}finally{h(!1)}}},de=()=>{!u||!r||(f(r.text),d({...r,text:u.current,hash:u.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);o(R),p(await ge(t.id)),r?.path===C.path&&d(null)}catch(R){j(re(R))}}},ct=async()=>{const C=di(F);if(!C){j(s("memory.topicNameError"));return}$(""),await Z(`memory/${C}`),d(R=>R&&{...R,dirty:!0,text:R.text||ar(C)})},Hs=async C=>{L(C.id),j(null);try{const R=await js(t.id,C.id);o(R.overview),p(await ge(t.id)),r?.path===C.path&&!r.dirty&&d({...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 G("/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);o(R),p(await ge(t.id)),H(await Pt(t.id)),r&&!r.dirty&&await Z(r.path),w(`${Rs(C)}.${C.note?` ${C.note}`:""}`)}catch(C){j(re(C))}finally{g(!1)}},qs=l.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange: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(()=>{D(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(rr,{index:i.index}),t.memoryEnabled!==!1&&e.jsx(ir,{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:()=>{Z(se)},children:s("memory.backToIndex")})]}),u&&e.jsx(Is,{botName:t.name,busy:b,onReload:de,onOverwrite:()=>{W(u.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=>d({...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:()=>{Z(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=>{Z(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:F,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:!F.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=>{Z(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:c,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 ar(t){return`---
2
2
  title: ${t.replace(/\.md$/,"")}
3
3
  description:
4
4
  aliases: []
5
5
  ---
6
6
 
7
- `}function ar({enabled:t,status:n,tidying:a,onToggle:l,onTidy:i,rooms:o}){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:l})]}),t&&o&&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")}),o.error&&e.jsx("p",{role:"alert",className:"mt-1 text-[13px] text-danger",children:o.error})]}),e.jsx(be,{checked:o.enabled,"aria-label":s("memory.learnFromRooms.title"),disabled:o.saving,onClick:o.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 l=`${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:l}})})]})}function Is({botName:t,busy:n,onReload:a,onOverwrite:l}){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:l,children:s("memory.overwrite")})]})]})}function Ht({title:t,hint:n,files:a,selected:l,onOpen:i,onDelete:o}){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(c=>e.jsxs("div",{className:O("flex items-center gap-2 border-b border-hairline/40 px-3 py-2 last:border-b-0",l===c.path?"bg-control/60":"hover:bg-control/40"),children:[e.jsxs("button",{type:"button",onClick:()=>i(c),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:c.name}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:[pe(c.bytes)," · ",Te(c.modifiedAt,ee())]})]}),e.jsx("button",{type:"button",onClick:()=>o(c),"aria-label":s("memory.deleteFile",{name:c.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})})]},c.path))})]})}function lt({rows:t,botName:n,reverting:a,onRevert:l,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(o=>{const c=pi(o),p=mi(o);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(o,n)})," · ",e.jsx("span",{className:"text-ink-secondary",children:Te(o.at,ee(),i)}),c&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-ink-secondary",children:p?s(p,o.threadTitle?{title:o.threadTitle}:void 0):c})]})]}),o.canRevert?e.jsxs("button",{type:"button",disabled:a!==null,onClick:()=>l(o),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===o.id?s("memory.undoing"):s("memory.undo")]}):e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",title:o.revertUnavailableReason,children:s("memory.cantUndo")})]}),o.diff&&e.jsxs("details",{className:"mt-1",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:["+",o.added," −",o.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:o.diff})]})]},o.id)})}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.loading")})}function rr({bot:t,rows:n,refreshError:a,onRollback:l,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 o=[...n].sort((c,p)=>p.at-c.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")}),o.map(c=>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(c.at)})," · ",e.jsxs("span",{children:[c.actor," via ",c.via]})," · ",e.jsx("span",{children:c.summary})]}),c.field==="soul"&&c.canRestore===!0&&e.jsx("button",{type:"button",disabled:i,onClick:()=>l(c.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")})]}),c.field==="soul"&&c.canRestore!==!0&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:c.restoreUnavailableReason??s("history.restoreUnavailable")})]},`${t.id}-${c.id}`))]})}function or({bot:t,bare:n=!1}){const{state:a,dispatch:l}=B(),i=cn(t),o=a.instances.find(c=>c.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:()=>l({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(o?.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:l}){const i=gn(t,a),{fileRef:o,crop:c,uploading:p,generating:r,busy:d,error:u,upload:x,removeImage:k,generate:f}=i,v=c!=="mascot"&&!!t.avatarUrl,[j,N]=m.useState(v?"upload":"bot"),w=m.useRef(null);m.useEffect(()=>{w.current?.querySelector('[aria-selected="true"]')?.focus()},[]);const b=g=>a(c==="mascot"?g:{...g,avatarCrop:"mascot"}),h=t.mascotBody??"cursor",P=Ga(),L=Za(t.mascotBody,t.color,P),[F,$]=m.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:d,"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(),l())};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:d,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:d,"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:d,onPatch:b}),e.jsxs("button",{type:"button","data-avatar-more":!0,"aria-expanded":F,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",F&&"rotate-180")})]}),F&&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:d,"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:p,generating:r,onGenerate:f})}),j==="upload"&&e.jsxs(e.Fragment,{children:[e.jsx(vn,{busy:d,onUpload:g=>{x(g)}}),v&&e.jsx(kn,{bot:t,disabled:d,onPatch:a}),e.jsx("input",{ref:o,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:d,onClick:()=>o.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:[p?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?c:null,onChange:g=>a({avatarCrop:g}),options:cr.map(g=>({value:g,label:s(dr[g]),disabled:d||!t.avatarUrl}))}),t.avatarUrl&&e.jsx("button",{type:"button",onClick:k,disabled:d,"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")})]}),u&&e.jsx("div",{role:"alert",className:"mt-3 text-[12px] text-danger",children:u})]})]})}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,l]=m.useState(null);return m.useEffect(()=>{if(!n)return;let i=!1;return G(`/api/browser-sites?bot=${encodeURIComponent(t.id)}`).then(o=>{i||l({botId:t.id,count:o.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(),l=a.host?.platform??"other",i=Cn(t),o=t.computer??"auto",c=n.config?.browserEngine?.myChrome===!0&&(n.config?.browserProfiles??[]).some(f=>f.id===t.browserProfile&&f.browser==="chrome"),p=f=>f==="browser"&&c?s("settings.profiles.myChrome"):En(f,l),r=f=>{const{view:v,reachable:j}=i[f];return{value:f,label:p(f),disabled:!j,hint:!j||On(v)?v.line:void 0}},d=[{value:"auto",label:s("computer.simple.dest.letItChoose")},...i.local.policy?[r("local")]:[],...i.browser.policy||o==="browser"?[r("browser")]:[],...i.cloud.policy?[r("cloud")]:[],...i.vm.policy||o==="vm"?[r("vm")]:[],...o==="off"?[{value:o,label:xr(),disabled:!0}]:[]],u=t.tasks?.find(f=>f.threadId===t.threadId)?.surface,x=u&&u!==o?p(u):null,k=d.find(f=>f.value===o)?.label??(o==="auto"||o==="off"?void 0:p(o));return{options:d,current:o,currentLabel:k,usingNow:x}}function gr({bot:t,derived:n}){const{dispatch:a}=B(),{options:l,current:i,usingNow:o}=Ms(t),[c,p]=m.useState(null),{patch:r,approvalMode:d}=n,u=x=>{if(!(x===i||x==="off")){if(x==="local"&&d==="auto"){p({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:l.map(x=>e.jsx(Ze,{"data-panel-choice":x.value,title:x.label,hint:x.hint,checked:i===x.value,disabled:x.disabled,onClick:()=>u(x.value)},x.value))})}),o&&e.jsx("p",{"data-panel-using-now":!0,className:"mx-1 text-[13px] text-ink-secondary",children:s("computer.simple.usingNow",{place:o})}),e.jsx(Pn,{open:c!==null,onCancel:()=>p(null),onConfirm:()=>{const x=c;p(null),x&&a({type:"updateBot",botId:x.botId,patch:x.patch})}})]})}function fr({bot:t,derived:n,onOpen:a}){const l=As(t),i=Le(),{browserEnabled:o}=n,c=hr(t,o&&t.computer!=="off"&&i!==!1),{currentLabel:p,usingNow:r}=Ms(t),d=s("computer.screenOf",{name:t.name}),u=[...t.messages].reverse().find(k=>k.kind==="screen"&&(k.hasImage||k.png)),x=u?wn({threadId:t.threadId,messageId:u.id},u.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")}: ${d}`,onClick:()=>l(),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(Tt,{size:13,"aria-hidden":"true"}),s("place.action.watch")]})]}),e.jsx("div",{className:"mt-3 text-center text-[13px] text-ink-tertiary",children:d}),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:p,onClick:()=>a("where")}),e.jsx(Q,{"data-panel-page":"browser",icon:Nn,title:s("settings.sites.title"),value:c??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]=m.useState(0),i=n.filter(p=>p.threadId!==t.threadId).map(Kt).filter(p=>!he.has(p)&&!We.has(p)).join(",");m.useEffect(()=>{if(i)for(const p of i.split(",")){We.add(p);const r=p.slice(0,p.lastIndexOf("@"));G(`/api/threads/${encodeURIComponent(r)}/messages?limit=${br}`,{background:!0}).then(d=>{he.set(p,Je({messages:d.messages??[],activeLeafId:d.activeLeafId??void 0})),he.size>vr&&he.delete(he.keys().next().value),a(u=>u+1)}).catch(()=>{}).finally(()=>We.delete(p))}},[i]);const o=Je(t),c=new Map(n.map(p=>[p.threadId,Kt(p)]));return p=>p===t.threadId?o:he.get(c.get(p)??"")}function jr({bot:t}){const{state:n,dispatch:a}=B(),l=Rn(),i=!rs(os,!0),[o,c]=m.useState(""),[p,r]=m.useState(!1),[d,u]=m.useState(!1),[x,k]=m.useState(!1),f=Tn(n.config),v=m.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=o.trim(),L=b.filter((y,z)=>z<yr||y.threadId===t.threadId),F=kr(t,[...P||d?b:L,...x?h:[]]),$=y=>{const z=F(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:d?b:L,g=b.length-L.length,T=t.projects?.find(y=>y.id===t.tasks?.find(z=>z.threadId===t.threadId)?.projectId),D=()=>{i&&a({type:"toggleSettings",open:!1})},_=y=>{y.threadId!==t.threadId&&zn(a,t,y.threadId,!1),D()},K=()=>{a({type:"newTask",botId:t.id,...T?{projectId:T.id}:{}}),D()},J=()=>{c(""),r(!1)},Y=b.length>=2||p||b.some(y=>y.threadId===t.threadId&&ze(y)),U=y=>e.jsx("div",{role:"listitem","data-conversation":y.threadId,children:e.jsx(Dn,{panel:!0,preview:$(y.threadId),task:y,ownerId:t.id,current:y.threadId===t.threadId,folders:t.projects,now:Fn(cs(y),l),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":p,onClick:()=>p?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",p&&"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&&p&&e.jsx("input",{autoFocus:!0,type:"search","data-conversations-query":!0,value:o,onChange:y=>c(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":d,onClick:()=>u(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:[d?e.jsx(yt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),d?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(yt,{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",_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(l=>e.jsx("button",{type:"button","data-panel-ask":l,onClick:()=>n({type:"send",botId:t.id,text:s(l),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(l)})},l)),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:l}=_n(t),{dispatch:i}=B(),o=n.botRoutines.filter(p=>p.enabled).length,c=Nr.flatMap(p=>l.filter(r=>r.key===p));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}),c.length>0&&e.jsxs("section",{"data-panel-card":"conversation",children:[e.jsx(Re,{children:s("botPanel.section.conversation")}),c.map(p=>e.jsx(Sr,{item:p},p.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(Fi,{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:o>0?s("botPanel.routinesOn",{count:o}):s("botPanel.none"),onClick:()=>a("routines")})})]})}const Ls=/^\s*[-*]\s+(.+?)\s*$/;function Pr(t){return t.split(`
8
- `).flatMap((n,a)=>{const l=Ls.exec(n)?.[1];return l?[{line:a,text:l}]:[]})}function Or(t,n){const a=t.split(`
7
+ `}function ir({enabled:t,status:n,tidying:a,onToggle:l,onTidy:i,rooms:o}){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:l})]}),t&&o&&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")}),o.error&&e.jsx("p",{role:"alert",className:"mt-1 text-[13px] text-danger",children:o.error})]}),e.jsx(be,{checked:o.enabled,"aria-label":s("memory.learnFromRooms.title"),disabled:o.saving,onClick:o.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 rr({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 l=`${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:l}})})]})}function Is({botName:t,busy:n,onReload:a,onOverwrite:l}){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:l,children:s("memory.overwrite")})]})]})}function Ht({title:t,hint:n,files:a,selected:l,onOpen:i,onDelete:o}){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(c=>e.jsxs("div",{className:O("flex items-center gap-2 border-b border-hairline/40 px-3 py-2 last:border-b-0",l===c.path?"bg-control/60":"hover:bg-control/40"),children:[e.jsxs("button",{type:"button",onClick:()=>i(c),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:c.name}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:[pe(c.bytes)," · ",Te(c.modifiedAt,ee())]})]}),e.jsx("button",{type:"button",onClick:()=>o(c),"aria-label":s("memory.deleteFile",{name:c.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})})]},c.path))})]})}function lt({rows:t,botName:n,reverting:a,onRevert:l,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(o=>{const c=pi(o),p=mi(o);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:sr(o,n)})," · ",e.jsx("span",{className:"text-ink-secondary",children:Te(o.at,ee(),i)}),c&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-ink-secondary",children:p?s(p,o.threadTitle?{title:o.threadTitle}:void 0):c})]})]}),o.canRevert?e.jsxs("button",{type:"button",disabled:a!==null,onClick:()=>l(o),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===o.id?s("memory.undoing"):s("memory.undo")]}):e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",title:o.revertUnavailableReason,children:s("memory.cantUndo")})]}),o.diff&&e.jsxs("details",{className:"mt-1",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:["+",o.added," −",o.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:o.diff})]})]},o.id)})}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.loading")})}function or({bot:t,rows:n,refreshError:a,onRollback:l,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 o=[...n].sort((c,p)=>p.at-c.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")}),o.map(c=>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(c.at)})," · ",e.jsxs("span",{children:[c.actor," via ",c.via]})," · ",e.jsx("span",{children:c.summary})]}),c.field==="soul"&&c.canRestore===!0&&e.jsx("button",{type:"button",disabled:i,onClick:()=>l(c.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")})]}),c.field==="soul"&&c.canRestore!==!0&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:c.restoreUnavailableReason??s("history.restoreUnavailable")})]},`${t.id}-${c.id}`))]})}function lr({bot:t,bare:n=!1}){const{state:a,dispatch:l}=B(),i=cn(t),o=a.instances.find(c=>c.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:()=>l({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(o?.snapshot.billing)}):s("usage.bot.unpriced")})]})}const cr=[["bot","botPanel.avatar.tabBot"],["generate","botPanel.avatar.tabGenerate"],["upload","botPanel.avatar.tabUpload"]],dr=["circle","rounded","square"],pr={circle:"botPanel.avatar.circle",rounded:"botPanel.avatar.rounded",square:"botPanel.avatar.square"},mr={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"},ur=t=>{const n=mr[t];return n?s(n):t};function xr({bot:t,activeState:n,onPatch:a,onClose:l}){const i=gn(t,a),{fileRef:o,crop:c,uploading:p,generating:r,busy:d,error:u,upload:x,removeImage:k,generate:f}=i,v=c!=="mascot"&&!!t.avatarUrl,[j,N]=m.useState(v?"upload":"bot"),w=m.useRef(null);m.useEffect(()=>{w.current?.querySelector('[aria-selected="true"]')?.focus()},[]);const b=g=>a(c==="mascot"?g:{...g,avatarCrop:"mascot"}),h=t.mascotBody??"cursor",P=Ga(),L=Za(t.mascotBody,t.color,P),[F,$]=m.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:d,"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(),l())};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:[cr.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:d,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:d,"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:d,onPatch:b}),e.jsxs("button",{type:"button","data-avatar-more":!0,"aria-expanded":F,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",F&&"rotate-180")})]}),F&&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:d,"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:ur(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:p,generating:r,onGenerate:f})}),j==="upload"&&e.jsxs(e.Fragment,{children:[e.jsx(vn,{busy:d,onUpload:g=>{x(g)}}),v&&e.jsx(kn,{bot:t,disabled:d,onPatch:a}),e.jsx("input",{ref:o,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:d,onClick:()=>o.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:[p?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?c:null,onChange:g=>a({avatarCrop:g}),options:dr.map(g=>({value:g,label:s(pr[g]),disabled:d||!t.avatarUrl}))}),t.avatarUrl&&e.jsx("button",{type:"button",onClick:k,disabled:d,"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")})]}),u&&e.jsx("div",{role:"alert",className:"mt-3 text-[12px] text-danger",children:u})]})]})}const hr=()=>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 gr(t,n){const[a,l]=m.useState(null);return m.useEffect(()=>{if(!n)return;let i=!1;return G(`/api/browser-sites?bot=${encodeURIComponent(t.id)}`).then(o=>{i||l({botId:t.id,count:o.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(),l=a.host?.platform??"other",i=Cn(t),o=t.computer??"auto",c=n.config?.browserEngine?.myChrome===!0&&(n.config?.browserProfiles??[]).some(f=>f.id===t.browserProfile&&f.browser==="chrome"),p=f=>f==="browser"&&c?s("settings.profiles.myChrome"):En(f,l),r=f=>{const{view:v,reachable:j}=i[f];return{value:f,label:p(f),disabled:!j,hint:!j||On(v)?v.line:void 0}},d=[{value:"auto",label:s("computer.simple.dest.letItChoose")},...i.local.policy?[r("local")]:[],...i.browser.policy||o==="browser"?[r("browser")]:[],...i.cloud.policy?[r("cloud")]:[],...i.vm.policy||o==="vm"?[r("vm")]:[],...o==="off"?[{value:o,label:hr(),disabled:!0}]:[]],u=t.tasks?.find(f=>f.threadId===t.threadId)?.surface,x=u&&u!==o?p(u):null,k=d.find(f=>f.value===o)?.label??(o==="auto"||o==="off"?void 0:p(o));return{options:d,current:o,currentLabel:k,usingNow:x}}function fr({bot:t,derived:n}){const{dispatch:a}=B(),{options:l,current:i,usingNow:o}=Ms(t),[c,p]=m.useState(null),{patch:r,approvalMode:d}=n,u=x=>{if(!(x===i||x==="off")){if(x==="local"&&d==="auto"){p({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:l.map(x=>e.jsx(Ze,{"data-panel-choice":x.value,title:x.label,hint:x.hint,checked:i===x.value,disabled:x.disabled,onClick:()=>u(x.value)},x.value))})}),o&&e.jsx("p",{"data-panel-using-now":!0,className:"mx-1 text-[13px] text-ink-secondary",children:s("computer.simple.usingNow",{place:o})}),e.jsx(Pn,{open:c!==null,onCancel:()=>p(null),onConfirm:()=>{const x=c;p(null),x&&a({type:"updateBot",botId:x.botId,patch:x.patch})}})]})}function yr({bot:t,derived:n,onOpen:a}){const l=As(t),i=Le(),{browserEnabled:o}=n,c=gr(t,o&&t.computer!=="off"&&i!==!1),{currentLabel:p,usingNow:r}=Ms(t),d=s("computer.screenOf",{name:t.name}),u=[...t.messages].reverse().find(k=>k.kind==="screen"&&(k.hasImage||k.png)),x=u?wn({threadId:t.threadId,messageId:u.id},u.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")}: ${d}`,onClick:()=>l(),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(Tt,{size:13,"aria-hidden":"true"}),s("place.action.watch")]})]}),e.jsx("div",{className:"mt-3 text-center text-[13px] text-ink-tertiary",children:d}),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:p,onClick:()=>a("where")}),e.jsx(Q,{"data-panel-page":"browser",icon:Nn,title:s("settings.sites.title"),value:c??void 0,onClick:()=>a("browser")})]})]})}const br=3,_t="[&_.font-semibold]:font-medium [&_time]:text-[12px] [&_time]:text-ink-tertiary [&_span.bg-accent]:size-2",vr=8,kr=200,he=new Map,We=new Set,Kt=t=>`${t.threadId}@${cs(t)}`;function jr(t,n){const[,a]=m.useState(0),i=n.filter(p=>p.threadId!==t.threadId).map(Kt).filter(p=>!he.has(p)&&!We.has(p)).join(",");m.useEffect(()=>{if(i)for(const p of i.split(",")){We.add(p);const r=p.slice(0,p.lastIndexOf("@"));G(`/api/threads/${encodeURIComponent(r)}/messages?limit=${vr}`,{background:!0}).then(d=>{he.set(p,Je({messages:d.messages??[],activeLeafId:d.activeLeafId??void 0})),he.size>kr&&he.delete(he.keys().next().value),a(u=>u+1)}).catch(()=>{}).finally(()=>We.delete(p))}},[i]);const o=Je(t),c=new Map(n.map(p=>[p.threadId,Kt(p)]));return p=>p===t.threadId?o:he.get(c.get(p)??"")}function wr({bot:t}){const{state:n,dispatch:a}=B(),l=Rn(),i=!rs(os,!0),[o,c]=m.useState(""),[p,r]=m.useState(!1),[d,u]=m.useState(!1),[x,k]=m.useState(!1),f=Tn(n.config),v=m.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=o.trim(),L=b.filter((y,z)=>z<br||y.threadId===t.threadId),F=jr(t,[...P||d?b:L,...x?h:[]]),$=y=>{const z=F(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:d?b:L,g=b.length-L.length,T=t.projects?.find(y=>y.id===t.tasks?.find(z=>z.threadId===t.threadId)?.projectId),D=()=>{i&&a({type:"toggleSettings",open:!1})},_=y=>{y.threadId!==t.threadId&&zn(a,t,y.threadId,!1),D()},K=()=>{a({type:"newTask",botId:t.id,...T?{projectId:T.id}:{}}),D()},J=()=>{c(""),r(!1)},Y=b.length>=2||p||b.some(y=>y.threadId===t.threadId&&ze(y)),U=y=>e.jsx("div",{role:"listitem","data-conversation":y.threadId,children:e.jsx(Dn,{panel:!0,preview:$(y.threadId),task:y,ownerId:t.id,current:y.threadId===t.threadId,folders:t.projects,now:Fn(cs(y),l),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":p,onClick:()=>p?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",p&&"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&&p&&e.jsx("input",{autoFocus:!0,type:"search","data-conversations-query":!0,value:o,onChange:y=>c(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":d,onClick:()=>u(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:[d?e.jsx(yt,{size:14,"aria-hidden":"true"}):e.jsx(fe,{size:14,"aria-hidden":"true"}),d?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(yt,{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",_t),children:h.map(U)})]})}function Nr({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(l=>e.jsx("button",{type:"button","data-panel-ask":l,onClick:()=>n({type:"send",botId:t.id,text:s(l),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(l)})},l)),e.jsx(bt,{placement:"panel"})]}):null}const Sr=["find","start-fresh","usage","activity","inspector"];function Cr({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 Pr({bot:t,derived:n,onOpen:a}){const{items:l}=_n(t),{dispatch:i}=B(),o=n.botRoutines.filter(p=>p.enabled).length,c=Sr.flatMap(p=>l.filter(r=>r.key===p));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(wr,{bot:t}),e.jsx(Nr,{bot:t}),c.length>0&&e.jsxs("section",{"data-panel-card":"conversation",children:[e.jsx(Re,{children:s("botPanel.section.conversation")}),c.map(p=>e.jsx(Cr,{item:p},p.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(zi,{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:o>0?s("botPanel.routinesOn",{count:o}):s("botPanel.none"),onClick:()=>a("routines")})})]})}const Ls=/^\s*[-*]\s+(.+?)\s*$/;function Or(t){return t.split(`
8
+ `).flatMap((n,a)=>{const l=Ls.exec(n)?.[1];return l?[{line:a,text:l}]:[]})}function Er(t,n){const a=t.split(`
9
9
  `);return Ls.test(a[n]??"")?(a.splice(n,1),a.join(`
10
- `)):t}function Er(t,n){const a=t.replace(/\s+$/,""),l=`- ${n.trim().replace(/\s*\n\s*/g," ")}`;return a?`${a}
10
+ `)):t}function Rr(t,n){const a=t.replace(/\s+$/,""),l=`- ${n.trim().replace(/\s*\n\s*/g," ")}`;return a?`${a}
11
11
  ${l}
12
12
  `:`${l}
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 l=n.text.split(`
14
- `).map(i=>i.replace(/^#+\s*/,"").trim()).filter(Boolean).join(" ");return l?[{path:n.path,line:null,text:l}]:[]})}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(l=>l.path)].map(l=>Ie(t,l,!0)))}function $s(t){const n=!!B().state.config?.team,[a,l]=m.useState({botId:t.id,docs:null,error:!1}),i=t.memoryEnabled!==!1,o=async(r,d)=>{try{const u=await Rr(r,n);d?.()||l({botId:r,docs:u,error:!1})}catch{d?.()||l({botId:r,docs:null,error:!0})}},c=!!t.busy;m.useEffect(()=>{if(!i)return;let r=!1;return o(t.id,()=>r),()=>{r=!0}},[t.id,i,c,n]);const p=a.botId===t.id;return{docs:p?a.docs:null,error:p&&a.error,mine:n,setDoc:r=>l(d=>({botId:t.id,docs:(d.botId===t.id?d.docs??[]:[]).map(u=>u.path===r.path?r:u),error:!1})),reload:()=>o(t.id)}}function Tr(t,n=Je(t)){const a=[],l=[],i=new Set;for(const d of[...n].reverse()){const u=d.publishedPage;u?.state==="live"&&u.url&&!i.has(u.url)&&(i.add(u.url),a.push({messageId:d.id,title:u.title||u.url,url:u.url})),d.kind==="app"&&d.app?.doc&&l.push({messageId:d.id,title:d.app.title})}const o=Ii(t),c=[],p=new Set;for(const d of o.values())p.has(d.file.path)||(p.add(d.file.path),c.push(d));const r=Ai(t).filter(d=>!o.has(d));return{pages:a,apps:l,shared:c,unshared:r}}const Ir=t=>t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);function Ds({bot:t,onOpen:n}){const{dispatch:a}=B(),l=Le(),{capabilities:i}=we(),o=Wn(),c=!rs(os,!0),p=ws(t),r=$s(t),{pages:d,apps:u,shared:x,unshared:k}=m.useMemo(()=>Tr(t),[t]),f=b=>{a({type:"focusMessage",threadId:t.threadId,messageId:b}),c&&a({type:"toggleSettings",open:!1})},v=p.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:p.loading?void 0:v>0?v:s("botPanel.none"),onClick:()=>n("skills")}),l&&e.jsx(Q,{"data-panel-page":"plugins",icon:Qt,title:s("plugins.botMenu"),onClick:()=>n("plugins")}),e.jsx(Q,{"data-panel-page":"folder",icon:Gn,title:s("computer.files.folder"),value:t.cwd?at(t.cwd,i.host?.homeDir):s("botPanel.folder.private"),onClick:()=>n("folder")})]});return d.length+u.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:[d.length>0&&e.jsx(M,{label:s("botPanel.library.pages"),anchor:"pages",children:d.map(b=>e.jsx(Q,{"data-panel-row":"page",icon:Zn,title:e.jsx("span",{className:"block truncate",children:b.title}),hint:e.jsx("span",{className:"block truncate",children:b.url}),onClick:()=>o(b.url)},b.url))}),u.length>0&&e.jsx(M,{label:s("botPanel.library.apps"),anchor:"apps",children:u.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(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:l}=B(),i=Le(),o=t.browserProfile??"",c=(l.config?.browserProfiles??[]).find(u=>u.id===o),p=o==="guest",r=c?.browser==="chrome"&&l.config?.browserEngine?.myChrome===!0,d=o&&!p?l.bots.filter(u=>u.browserProfile===o).map(u=>u.name):[t.name];return e.jsx(M,{anchor:"logins",children:n?p?e.jsx(V,{children:s("settings.profiles.temporaryHint")}):r?e.jsx(V,{children:s("settings.profiles.myChromeHint")}):e.jsxs(e.Fragment,{children:[i!==!1&&(o===""||c)&&e.jsx(me,{children:e.jsx($i,{bare:!0,target:{bot:t.id},sharedBy:d,disabled:!!t.busy},`${t.id}:${o}`)}),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)}),l=await a.json().catch(()=>({}));if(!a.ok)throw new Error(l.error??S(`Lỗi ${a.status}`,`Error ${a.status}`));return l.skills??[]}function Br({botId:t,botName:n,onClose:a,onOpenSettings:l}){const[i,o]=m.useState(null),[c,p]=m.useState(""),[r,d]=m.useState("all"),[u,x]=m.useState(""),[k,f]=m.useState(""),v=`/api/limix/skill-store/${encodeURIComponent(t)}`;m.useEffect(()=>{let h=!1;return Ut(v).then(P=>{h||o(P)}).catch(P=>{h||(o([]),f(P.message))}),()=>{h=!0}},[v]),m.useEffect(()=>{const h=P=>{P.key==="Escape"&&a()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[a]);const j=m.useMemo(()=>{const h=c.trim().toLowerCase();return(i??[]).filter(P=>(r==="all"||(r==="added"?P.added:!P.added))&&(!h||`${P.name} ${P.description}`.toLowerCase().includes(h)))},[i,c,r]),N=async(h,P)=>{if(!u){x(h.name),f("");try{o(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{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:c,onChange:h=>p(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:()=>d(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:!!u,onClick:()=>{N(h,!1)},"aria-label":S(`Bỏ ${h.name} khỏi bot`,`Remove ${h.name} from this bot`),children:[u===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:!!u||!h.ready,onClick:()=>{N(h,!0)},"aria-label":S(`Thêm ${h.name} cho bot`,`Add ${h.name} to this bot`),children:[u===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:l,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,l]=m.useState("telegram"),[i,o]=m.useState({});m.useEffect(()=>{let r=!0;o({});for(const d of qt.filter(u=>u.kind!=="messenger"||ve()))G(`/api/bots/${t.id}/${d.kind}`).then(u=>{r&&o(x=>({...x,[d.kind]:u}))}).catch(()=>{});return()=>{r=!1}},[t.id]);const c=qt.filter(r=>r.kind!=="messenger"||ve()),p=c.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:c.map(r=>{const d=i[r.kind];return e.jsxs("button",{type:"button",role:"tab","aria-selected":a===r.kind,onClick:()=>l(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:[d?.connected&&e.jsx("span",{className:O("size-1.5 rounded-full",d.error?"bg-danger":d.enabled?"bg-success":"bg-ink-tertiary")}),r.label]},r.kind)})}),e.jsx(Dr,{bot:t,channel:p,view:i[a],onView:r=>o(d=>({...d,[a]:r}))},`${t.id}:${a}`)]})}function Dr({bot:t,channel:n,view:a,onView:l}){const i=`/api/bots/${t.id}/${n.kind}`,[o,c]=m.useState(""),[p,r]=m.useState(null),[d,u]=m.useState(!1),[x,k]=m.useState(null),f=!!(a?.login&&!a.login.error&&!a.connected);m.useEffect(()=>{if(!f&&!p)return;let N=!0;const w=setInterval(()=>{G(i).then(b=>{N&&(l(b),b.linkExpiresAt||r(null))}).catch(()=>{})},2e3);return()=>{N=!1,clearInterval(w)}},[f,p,i,l]);const v=async N=>{u(!0),k(null);try{const{code:w,...b}=await N();l(b),w&&r(w)}catch(w){k(w instanceof Error?w.message:String(w))}finally{u(!1)}},j=(N,w="")=>v(()=>G(`${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(),o.trim()&&j({token:o.trim()}).then(()=>c(""))},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:N=>c(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:d||!o.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:d,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(Fr,{view:a,busy:d,start:()=>{j({},"/login")},cancel:()=>{v(()=>G(`${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:d,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:d,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:d,"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")}),p&&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 ",p]}),S(" (hết hạn sau 15 phút)"," (expires in 15 minutes)")]}):e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:d,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:d,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:d,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:d,onClick:()=>{v(async()=>{const N=await G(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 Fr({view:t,busy:n,start:a,cancel:l}){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:l,children:S("Huỷ","Cancel")})]})]})}const zr=5,Hr={instanceId:"",model:""},Fs=(t,n)=>`${t}\0${n}`,_r=new Set;function Wt({bot:t,current:n,exclude:a,onPick:l,label:i,title:o,buttonRef:c,className:p,children:r,...d}){const{state:u,dispatch:x,refreshInstances:k,refreshModels:f}=B(),[v,j]=m.useState(!1),[N,w]=m.useState(""),[b,h]=m.useState(()=>new Set),[P,L]=m.useState(!1),[F,$]=m.useState(null),[A,H]=m.useState(null),I=m.useRef(null),g=c??I,T=m.useRef(null),D=m.useRef(null),_=m.useRef(!1),K=m.useId(),J=oi(v),Y=m.useRef({contains:E=>[g.current,T.current].some(q=>q?.contains(E))});sa(v,Y,()=>j(!1)),m.useLayoutEffect(()=>{if(!v)return;const E=q=>{if(q?.type==="scroll"&&q.target instanceof Node&&T.current?.contains(q.target))return;const Z=g.current?.getBoundingClientRect(),W=T.current;!Z||!W||H(de=>ia(Z,{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]),m.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=>{F||($(E.instanceId),f(E.instanceId).catch(()=>{}).finally(()=>$(null)))},ce=()=>{U(!1),x({type:"toggleAppSettings",open:!0,section:"engines"})},xe=()=>{const E=oa(u.instances,n?.instanceId).flatMap(W=>{const de=W.models.options.filter(Se=>!a.has(Fs(W.instanceId,Se.id)));return de.length===W.models.options.length?[W]:de.length?[{...W,models:{...W.models,options:de}}]:[]}),q=la({instances:u.instances,listed:E,selection:n??Hr,bot:{name:t.name,selection:t.modelSelection},query:N,expanded:b,probing:_r,loading:P,refreshing:F}),Z=q.groups.map(W=>W.instance.instanceId===t.modelSelection.instanceId?{...W,note:s("botPanel.backups.sameAccount")}:W);return{...q,groups:Z,...n?{}:{current:null}}},ye=E=>{if(!(E.nativeEvent.isComposing||E.defaultPrevented)){if(E.key!=="Escape")return ra(E,{query:N,typed:D,close:()=>U(!0)});E.preventDefault(),E.stopPropagation(),N?w(""):U(!0)}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",...d,"aria-label":i,title:o,"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:p,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||(l({instanceId:E.instanceId,model:q}),U(!0))},onPickCurrent:()=>U(!0),onFollowBot:()=>U(!0),onToggle:E=>h(q=>{const Z=new Set(q);return Z.delete(E.instanceId)||Z.add(E.instanceId),Z}),onSetUp:ce,onCheckAgain:z,onManage:ce})}),document.body)]})}function Kr({bot:t,onChange:n}){const{state:a}=B(),l=t.fallback??[],i=m.useRef(null),o=p=>new Set([t.modelSelection,...l.filter((r,d)=>d!==p)].map(r=>Fs(r.instanceId,r.model))),c=p=>{const r=a.instances.find(x=>x.instanceId===p.instanceId),d=r?.models.options.find(x=>x.id===p.model),u=Xn(r,p.model);return{instance:r,name:u,short:r&&d?ea(d.label,ta(r)):u}};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})}),l.length>0&&e.jsx("ol",{"aria-label":s("botPanel.backups.title"),className:"flex flex-col gap-1 pl-[38px]",children:l.map((p,r)=>{const{instance:d,name:u,short:x}=c(p);return e.jsxs("li",{"data-backup":p.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:p,exclude:o(r),onPick:k=>n(l.map((f,v)=>v===r?k:f)),label:s("botPanel.backups.row",{position:r+1,model:u}),title:d?`${d.displayName} · ${u}`:u,"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:[d?e.jsx(Qn,{instance:d,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}),!d&&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:u}),onClick:()=>{n(l.filter((k,f)=>f!==r)),i.current?.focus({preventScroll:!0})}})]},r)})}),l.length<zr&&e.jsx("div",{className:"pl-[38px]",children:e.jsxs(Wt,{bot:t,current:null,exclude:o(null),onPick:p=>n([...l,p]),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,l]=m.useState(!1),[i,o]=m.useState(!1),[c,p]=m.useState(0),r=t.memoryEnabled!==!1&&t.memoryUpkeep!==!1;if(m.useEffect(()=>{if(!r)return;let u=!0;return G(`/api/bots/${t.id}/system-prompt`).then(x=>{u&&l(x.heavy===!0)},()=>{}),()=>{u=!1}},[t.id,r,c]),!r||!a)return null;const d=async()=>{o(!0);try{await vs(t.id)}catch(u){n({type:"error",message:u instanceof Error&&u.message?u.message:s("common.tryAgain")})}finally{o(!1),p(u=>u+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:()=>{d()},className:le,children:i?s("memory.upkeep.tidying"):s("botPanel.tidyMemory")})]})})}const qr=5;function Wr({bot:t}){const{dispatch:n,flushBotPatches:a}=B(),[l,i]=m.useState([]),[o,c]=m.useState(null),p=m.useCallback(()=>Ot(t.id).then(d=>i(d.rows.slice(0,qr)),()=>{}),[t.id]);if(m.useEffect(()=>{p()},[p,t.soul]),!l.length)return null;const r=async d=>{if(!o){c(d.id);try{await a(t.id);const{revision:u}=await Ot(t.id);await gi(t.id,d.id,u)}catch(u){n({type:"error",message:u instanceof Error&&u.message?u.message:s("botOverview.undoFailed")})}finally{c(null),await p()}}};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:l,botName:t.name,reverting:o,onRevert:d=>{r(d)}})]})}const Ge={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:l=!1,onEditInstructions:i}){const{state:o,dispatch:c,flushBotPatches:p}=B(),{capabilities:r,ready:d}=we(),u=ps(t),{servers:x}=ms(),k=da(Ye(t)),f=pa(),v=Os(t.id),j=Ss(),[N,w]=m.useState(null),{patch:b,approvalMode:h,engine:P}=n,L=t.name,F=()=>{N!==null&&N.trim()!==t.title.trim()&&b({title:N.trim()}),w(null)},$=P?.driverKind==="antigravityAgent"&&h==="auto"?"ask":h,A=[{value:"ask",label:Ge.ask(),tooltip:s("botSettings.simple.askHint")},{value:"full",label:Ge.full(),tooltip:s("botSettings.simple.fullHint")},...$==="ask"||$==="full"?[]:[{value:$,label:Ge[$](),disabled:!0,tooltip:$==="custom"?s("botPanel.acts.customHint"):void 0}]],H=y=>{y===h||y!=="ask"&&y!=="full"||c({type:"updateBot",botId:t.id,patch:{approvalMode:y,applyToAllThreads:!0}})},I=!d||ma(r,o.config),g=Na(f,{turnsHere:I,canLive:!0}),T=I?null:ua(r,!!ha()?.speechStart,xa(o.config)),D=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=l||!!t.soulDrift,U=[...u.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(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}),l&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-panel-done":"soul",onClick:()=>{p(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:D})})]})}),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:F,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"&&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 Gr=5;function Zr({bot:t,onChanged:n}){const{dispatch:a}=B(),[l,i]=m.useState([]),[o,c]=m.useState(null),[p,r]=m.useState(null),d=m.useCallback(async()=>{const[f,v]=await Promise.all([rt(t.id),ge(t.id)]);c(j=>f.lendingReview?{value:f.lendingReview,stale:j?.stale??!1}:null),i(v.slice(0,Gr))},[t.id]);m.useEffect(()=>{d().catch(()=>{})},[d,t.busy]);const u=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){u(v)}finally{r(null),await d().catch(()=>{})}},k=async f=>{r("review");try{await bs(t.id,f.value.token),c(null)}catch(v){v instanceof as&&v.status===409?(c({...f,stale:!0}),await d().catch(()=>{})):u(v)}finally{r(null)}};return e.jsxs(e.Fragment,{children:[o&&e.jsx(Ts,{changed:o.value.changed,stale:o.stale,busy:p!==null,onReviewed:()=>{k(o)}}),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}})})}),l.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:l,botName:t.name,reverting:p,onRevert:f=>{x(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(),l=ps(t),{servers:i,error:o}=ms(),{patch:c,canUseConnectedApps:p}=n,r=i?Ra(i,t.id):[],d=new Set(us(r,t.mcpServers,t.id).map(f=>f.name)),u=f=>{const v=Aa(t,l.connectedSlugs,f.slug,f.scope===null);Object.keys(v).length>0&&c(v)},x=f=>{t.busy||o||c({mcpServers:Ma(r,t.mcpServers,f)})},k=p?l.phase==="loading"?s("common.checking"):l.phase==="unknown"?s("botSettings.simple.appsUnknown"):l.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}),p&&l.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:()=>u(f),className:"disabled:cursor-not-allowed"})]},f.slug))]}),(r.length>0||o)&&e.jsxs(M,{label:s("connectors.tab.mcp"),children:[o&&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:d.has(f.name),"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.name}),disabled:!f.enabled||!!t.busy||o,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:()=>Ia(a,t.id),children:s("botPanel.apps.connectAnother")})})]})}function Qr({bot:t,derived:n}){const{state:a,dispatch:l}=B(),[i,o]=m.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:o,onLogs:c=>l({type:"showRoutines",section:"logs",botId:t.id,routineId:c.id}),onToggle:c=>l({type:"updateRoutine",routineId:c.id,patch:{enabled:!c.enabled}})}),e.jsx(M,{children:e.jsx(ue,{"data-panel-action":"new-routine",icon:Ne,onClick:()=>o("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:()=>o(null)},t.id)]})}function Xr({bot:t}){const n=$s(t),[a,l]=m.useState(""),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),u=t.memoryEnabled!==!1,x=n.docs?Bs(n.docs):null,k=n.docs?.find(w=>w.path===se)??null;m.useEffect(()=>o(null),[t.id,u]);const f=async w=>{if(c)return!1;p(!0),d(null);try{return await w()}catch(b){return d(ke(b,s("botPanel.library.memoryError"))),!1}finally{p(!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(),d(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))&&l("")};return u&&i?.botId===t.id?e.jsx(eo,{bot:t,doc:i.doc,mine:n.mine,onDone:w=>{w&&n.setDoc(w),o(null),d(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[u?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:c,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})]}),u&&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:c||k===null,onChange:l,onSubmit:()=>{N()}}),k&&e.jsx(ue,{"data-panel-link":"memory-text",icon:Me,onClick:()=>o({botId:t.id,doc:k}),children:s("botPanel.memory.editText")})]}),u&&!n.mine&&e.jsx(Zr,{bot:t,onChanged:n.reload})]})}function eo({bot:t,doc:n,mine:a,onDone:l}){const[i,o]=m.useState({text:n.text,hash:n.hash}),[c,p]=m.useState(n.text),[r,d]=m.useState(null),[u,x]=m.useState(null),[k,f]=m.useState(!1),[v,j]=m.useState(null),N=m.useRef(!0);m.useEffect(()=>(N.current=!0,()=>{N.current=!1}),[]);const w=async h=>{f(!0),j(null);try{const P=await ot(t.id,n.path,c,h,a);if(!N.current)return;P.ok?l(P.doc):d({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===c?c:`${h}
13
+ `}function Bs(t){return t.flatMap(n=>{const a=Or(n.text).map(i=>({path:n.path,...i}));if(a.length||n.path===se)return a;const l=n.text.split(`
14
+ `).map(i=>i.replace(/^#+\s*/,"").trim()).filter(Boolean).join(" ");return l?[{path:n.path,line:null,text:l}]:[]})}async function Tr(t,n){if(!n)return[await Ie(t,se)];const a=await rt(t,!0);return Promise.all([se,...a.topics.map(l=>l.path)].map(l=>Ie(t,l,!0)))}function $s(t){const n=!!B().state.config?.team,[a,l]=m.useState({botId:t.id,docs:null,error:!1}),i=t.memoryEnabled!==!1,o=async(r,d)=>{try{const u=await Tr(r,n);d?.()||l({botId:r,docs:u,error:!1})}catch{d?.()||l({botId:r,docs:null,error:!0})}},c=!!t.busy;m.useEffect(()=>{if(!i)return;let r=!1;return o(t.id,()=>r),()=>{r=!0}},[t.id,i,c,n]);const p=a.botId===t.id;return{docs:p?a.docs:null,error:p&&a.error,mine:n,setDoc:r=>l(d=>({botId:t.id,docs:(d.botId===t.id?d.docs??[]:[]).map(u=>u.path===r.path?r:u),error:!1})),reload:()=>o(t.id)}}function Ir(t,n=Je(t)){const a=[],l=[],i=new Set;for(const d of[...n].reverse()){const u=d.publishedPage;u?.state==="live"&&u.url&&!i.has(u.url)&&(i.add(u.url),a.push({messageId:d.id,title:u.title||u.url,url:u.url})),d.kind==="app"&&d.app?.doc&&l.push({messageId:d.id,title:d.app.title})}const o=Ai(t),c=[],p=new Set;for(const d of o.values())p.has(d.file.path)||(p.add(d.file.path),c.push(d));const r=Mi(t).filter(d=>!o.has(d));return{pages:a,apps:l,shared:c,unshared:r}}const Ar=t=>t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);function Ds({bot:t,onOpen:n}){const{dispatch:a}=B(),l=Le(),{capabilities:i}=we(),o=Wn(),c=!rs(os,!0),p=ws(t),r=$s(t),{pages:d,apps:u,shared:x,unshared:k}=m.useMemo(()=>Ir(t),[t]),f=b=>{a({type:"focusMessage",threadId:t.threadId,messageId:b}),c&&a({type:"toggleSettings",open:!1})},v=p.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:p.loading?void 0:v>0?v:s("botPanel.none"),onClick:()=>n("skills")}),l&&e.jsx(Q,{"data-panel-page":"plugins",icon:Qt,title:s("plugins.botMenu"),onClick:()=>n("plugins")}),e.jsx(Q,{"data-panel-page":"folder",icon:Gn,title:s("computer.files.folder"),value:t.cwd?at(t.cwd,i.host?.homeDir):s("botPanel.folder.private"),onClick:()=>n("folder")})]});return d.length+u.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:[d.length>0&&e.jsx(M,{label:s("botPanel.library.pages"),anchor:"pages",children:d.map(b=>e.jsx(Q,{"data-panel-row":"page",icon:Zn,title:e.jsx("span",{className:"block truncate",children:b.title}),hint:e.jsx("span",{className:"block truncate",children:b.url}),onClick:()=>o(b.url)},b.url))}),u.length>0&&e.jsx(M,{label:s("botPanel.library.apps"),anchor:"apps",children:u.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(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:Ar(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 Mr({bot:t,browserEnabled:n,onOpenBrowser:a}){const{state:l}=B(),i=Le(),o=t.browserProfile??"",c=(l.config?.browserProfiles??[]).find(u=>u.id===o),p=o==="guest",r=c?.browser==="chrome"&&l.config?.browserEngine?.myChrome===!0,d=o&&!p?l.bots.filter(u=>u.browserProfile===o).map(u=>u.name):[t.name];return e.jsx(M,{anchor:"logins",children:n?p?e.jsx(V,{children:s("settings.profiles.temporaryHint")}):r?e.jsx(V,{children:s("settings.profiles.myChromeHint")}):e.jsxs(e.Fragment,{children:[i!==!1&&(o===""||c)&&e.jsx(me,{children:e.jsx(Di,{bare:!0,target:{bot:t.id},sharedBy:d,disabled:!!t.busy},`${t.id}:${o}`)}),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 Lr=[["all",()=>S("Tất cả","All")],["added",()=>S("Bot đang có","On this bot")],["more",()=>S("Chưa thêm","Not added")]],Br=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)}),l=await a.json().catch(()=>({}));if(!a.ok)throw new Error(l.error??S(`Lỗi ${a.status}`,`Error ${a.status}`));return l.skills??[]}function $r({botId:t,botName:n,onClose:a,onOpenSettings:l}){const[i,o]=m.useState(null),[c,p]=m.useState(""),[r,d]=m.useState("all"),[u,x]=m.useState(""),[k,f]=m.useState(""),v=`/api/limix/skill-store/${encodeURIComponent(t)}`;m.useEffect(()=>{let h=!1;return Ut(v).then(P=>{h||o(P)}).catch(P=>{h||(o([]),f(P.message))}),()=>{h=!0}},[v]),m.useEffect(()=>{const h=P=>{P.key==="Escape"&&a()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[a]);const j=m.useMemo(()=>{const h=c.trim().toLowerCase();return(i??[]).filter(P=>(r==="all"||(r==="added"?P.added:!P.added))&&(!h||`${P.name} ${P.description}`.toLowerCase().includes(h)))},[i,c,r]),N=async(h,P)=>{if(!u){x(h.name),f("");try{o(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{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:c,onChange:h=>p(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:Lr.map(([h,P])=>e.jsxs("button",{type:"button",role:"tab","aria-selected":r===h,onClick:()=>d(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"):Br(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:!!u,onClick:()=>{N(h,!1)},"aria-label":S(`Bỏ ${h.name} khỏi bot`,`Remove ${h.name} from this bot`),children:[u===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:!!u||!h.ready,onClick:()=>{N(h,!0)},"aria-label":S(`Thêm ${h.name} cho bot`,`Add ${h.name} to this bot`),children:[u===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:l,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 Dr({bot:t,className:n}){const[a,l]=m.useState("telegram"),[i,o]=m.useState({});m.useEffect(()=>{let r=!0;o({});for(const d of qt.filter(u=>u.kind!=="messenger"||ve()))G(`/api/bots/${t.id}/${d.kind}`).then(u=>{r&&o(x=>({...x,[d.kind]:u}))}).catch(()=>{});return()=>{r=!1}},[t.id]);const c=qt.filter(r=>r.kind!=="messenger"||ve()),p=c.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:c.map(r=>{const d=i[r.kind];return e.jsxs("button",{type:"button",role:"tab","aria-selected":a===r.kind,onClick:()=>l(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:[d?.connected&&e.jsx("span",{className:O("size-1.5 rounded-full",d.error?"bg-danger":d.enabled?"bg-success":"bg-ink-tertiary")}),r.label]},r.kind)})}),e.jsx(Fr,{bot:t,channel:p,view:i[a],onView:r=>o(d=>({...d,[a]:r}))},`${t.id}:${a}`)]})}function Fr({bot:t,channel:n,view:a,onView:l}){const i=`/api/bots/${t.id}/${n.kind}`,[o,c]=m.useState(""),[p,r]=m.useState(null),[d,u]=m.useState(!1),[x,k]=m.useState(null),f=!!(a?.login&&!a.login.error&&!a.connected);m.useEffect(()=>{if(!f&&!p)return;let N=!0;const w=setInterval(()=>{G(i).then(b=>{N&&(l(b),b.linkExpiresAt||r(null))}).catch(()=>{})},2e3);return()=>{N=!1,clearInterval(w)}},[f,p,i,l]);const v=async N=>{u(!0),k(null);try{const{code:w,...b}=await N();l(b),w&&r(w)}catch(w){k(w instanceof Error?w.message:String(w))}finally{u(!1)}},j=(N,w="")=>v(()=>G(`${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(),o.trim()&&j({token:o.trim()}).then(()=>c(""))},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:N=>c(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:d||!o.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:d,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(zr,{view:a,busy:d,start:()=>{j({},"/login")},cancel:()=>{v(()=>G(`${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:d,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:d,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:d,"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")}),p&&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 ",p]}),S(" (hết hạn sau 15 phút)"," (expires in 15 minutes)")]}):e.jsx("button",{type:"button",className:O(ne,"self-start"),disabled:d,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:d,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:d,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:d,onClick:()=>{v(async()=>{const N=await G(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 zr({view:t,busy:n,start:a,cancel:l}){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:l,children:S("Huỷ","Cancel")})]})]})}const Hr=5,_r={instanceId:"",model:""},Fs=(t,n)=>`${t}\0${n}`,Kr=new Set;function Wt({bot:t,current:n,exclude:a,onPick:l,label:i,title:o,buttonRef:c,className:p,children:r,...d}){const{state:u,dispatch:x,refreshInstances:k,refreshModels:f}=B(),[v,j]=m.useState(!1),[N,w]=m.useState(""),[b,h]=m.useState(()=>new Set),[P,L]=m.useState(!1),[F,$]=m.useState(null),[A,H]=m.useState(null),I=m.useRef(null),g=c??I,T=m.useRef(null),D=m.useRef(null),_=m.useRef(!1),K=m.useId(),J=oi(v),Y=m.useRef({contains:E=>[g.current,T.current].some(q=>q?.contains(E))});sa(v,Y,()=>j(!1)),m.useLayoutEffect(()=>{if(!v)return;const E=q=>{if(q?.type==="scroll"&&q.target instanceof Node&&T.current?.contains(q.target))return;const Z=g.current?.getBoundingClientRect(),W=T.current;!Z||!W||H(de=>ia(Z,{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]),m.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=>{F||($(E.instanceId),f(E.instanceId).catch(()=>{}).finally(()=>$(null)))},ce=()=>{U(!1),x({type:"toggleAppSettings",open:!0,section:"engines"})},xe=()=>{const E=oa(u.instances,n?.instanceId).flatMap(W=>{const de=W.models.options.filter(Se=>!a.has(Fs(W.instanceId,Se.id)));return de.length===W.models.options.length?[W]:de.length?[{...W,models:{...W.models,options:de}}]:[]}),q=la({instances:u.instances,listed:E,selection:n??_r,bot:{name:t.name,selection:t.modelSelection},query:N,expanded:b,probing:Kr,loading:P,refreshing:F}),Z=q.groups.map(W=>W.instance.instanceId===t.modelSelection.instanceId?{...W,note:s("botPanel.backups.sameAccount")}:W);return{...q,groups:Z,...n?{}:{current:null}}},ye=E=>{if(!(E.nativeEvent.isComposing||E.defaultPrevented)){if(E.key!=="Escape")return ra(E,{query:N,typed:D,close:()=>U(!0)});E.preventDefault(),E.stopPropagation(),N?w(""):U(!0)}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",...d,"aria-label":i,title:o,"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:p,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||(l({instanceId:E.instanceId,model:q}),U(!0))},onPickCurrent:()=>U(!0),onFollowBot:()=>U(!0),onToggle:E=>h(q=>{const Z=new Set(q);return Z.delete(E.instanceId)||Z.add(E.instanceId),Z}),onSetUp:ce,onCheckAgain:z,onManage:ce})}),document.body)]})}function Ur({bot:t,onChange:n}){const{state:a}=B(),l=t.fallback??[],i=m.useRef(null),o=p=>new Set([t.modelSelection,...l.filter((r,d)=>d!==p)].map(r=>Fs(r.instanceId,r.model))),c=p=>{const r=a.instances.find(x=>x.instanceId===p.instanceId),d=r?.models.options.find(x=>x.id===p.model),u=Xn(r,p.model);return{instance:r,name:u,short:r&&d?ea(d.label,ta(r)):u}};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})}),l.length>0&&e.jsx("ol",{"aria-label":s("botPanel.backups.title"),className:"flex flex-col gap-1 pl-[38px]",children:l.map((p,r)=>{const{instance:d,name:u,short:x}=c(p);return e.jsxs("li",{"data-backup":p.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:p,exclude:o(r),onPick:k=>n(l.map((f,v)=>v===r?k:f)),label:s("botPanel.backups.row",{position:r+1,model:u}),title:d?`${d.displayName} · ${u}`:u,"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:[d?e.jsx(Qn,{instance:d,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}),!d&&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:u}),onClick:()=>{n(l.filter((k,f)=>f!==r)),i.current?.focus({preventScroll:!0})}})]},r)})}),l.length<Hr&&e.jsx("div",{className:"pl-[38px]",children:e.jsxs(Wt,{bot:t,current:null,exclude:o(null),onPick:p=>n([...l,p]),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 qr({bot:t}){const{dispatch:n}=B(),[a,l]=m.useState(!1),[i,o]=m.useState(!1),[c,p]=m.useState(0),r=t.memoryEnabled!==!1&&t.memoryUpkeep!==!1;if(m.useEffect(()=>{if(!r)return;let u=!0;return G(`/api/bots/${t.id}/system-prompt`).then(x=>{u&&l(x.heavy===!0)},()=>{}),()=>{u=!1}},[t.id,r,c]),!r||!a)return null;const d=async()=>{o(!0);try{await vs(t.id)}catch(u){n({type:"error",message:u instanceof Error&&u.message?u.message:s("common.tryAgain")})}finally{o(!1),p(u=>u+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:()=>{d()},className:le,children:i?s("memory.upkeep.tidying"):s("botPanel.tidyMemory")})]})})}const Wr=5;function Vr({bot:t}){const{dispatch:n,flushBotPatches:a}=B(),[l,i]=m.useState([]),[o,c]=m.useState(null),p=m.useCallback(()=>Ot(t.id).then(d=>i(d.rows.slice(0,Wr)),()=>{}),[t.id]);if(m.useEffect(()=>{p()},[p,t.soul]),!l.length)return null;const r=async d=>{if(!o){c(d.id);try{await a(t.id);const{revision:u}=await Ot(t.id);await gi(t.id,d.id,u)}catch(u){n({type:"error",message:u instanceof Error&&u.message?u.message:s("botOverview.undoFailed")})}finally{c(null),await p()}}};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:l,botName:t.name,reverting:o,onRevert:d=>{r(d)}})]})}const Ge={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 Gr({bot:t,derived:n,onOpen:a,editingInstructions:l=!1,onEditInstructions:i}){const{state:o,dispatch:c,flushBotPatches:p}=B(),{capabilities:r,ready:d}=we(),u=ps(t),{servers:x}=ms(),k=da(Ye(t)),f=pa(),v=Os(t.id),j=Ss(),[N,w]=m.useState(null),{patch:b,approvalMode:h,engine:P}=n,L=t.name,F=()=>{N!==null&&N.trim()!==t.title.trim()&&b({title:N.trim()}),w(null)},$=P?.driverKind==="antigravityAgent"&&h==="auto"?"ask":h,A=[{value:"ask",label:Ge.ask(),tooltip:s("botSettings.simple.askHint")},{value:"full",label:Ge.full(),tooltip:s("botSettings.simple.fullHint")},...$==="ask"||$==="full"?[]:[{value:$,label:Ge[$](),disabled:!0,tooltip:$==="custom"?s("botPanel.acts.customHint"):void 0}]],H=y=>{y===h||y!=="ask"&&y!=="full"||c({type:"updateBot",botId:t.id,patch:{approvalMode:y,applyToAllThreads:!0}})},I=!d||ma(r,o.config),g=Na(f,{turnsHere:I,canLive:!0}),T=I?null:ua(r,!!ha()?.speechStart,xa(o.config)),D=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=l||!!t.soulDrift,U=[...u.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(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(Vr,{bot:t}),l&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-panel-done":"soul",onClick:()=>{p(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(qr,{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(Ur,{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:D})})]})}),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:qi}),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:F,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"&&e.jsx(Dr,{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 Yr({bot:t,onChanged:n}){const{dispatch:a}=B(),[l,i]=m.useState([]),[o,c]=m.useState(null),[p,r]=m.useState(null),d=m.useCallback(async()=>{const[f,v]=await Promise.all([rt(t.id),ge(t.id)]);c(j=>f.lendingReview?{value:f.lendingReview,stale:j?.stale??!1}:null),i(v.slice(0,Zr))},[t.id]);m.useEffect(()=>{d().catch(()=>{})},[d,t.busy]);const u=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){u(v)}finally{r(null),await d().catch(()=>{})}},k=async f=>{r("review");try{await bs(t.id,f.value.token),c(null)}catch(v){v instanceof as&&v.status===409?(c({...f,stale:!0}),await d().catch(()=>{})):u(v)}finally{r(null)}};return e.jsxs(e.Fragment,{children:[o&&e.jsx(Ts,{changed:o.value.changed,stale:o.stale,busy:p!==null,onReviewed:()=>{k(o)}}),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}})})}),l.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:l,botName:t.name,reverting:p,onRevert:f=>{x(f)}})})})]})}const Jr="flex flex-col gap-3",Vt="https://www.skills.sh";function ke(t,n){return t instanceof Error&&t.message?t.message:n}function Qr({bot:t,derived:n}){const{dispatch:a}=B(),l=ps(t),{servers:i,error:o}=ms(),{patch:c,canUseConnectedApps:p}=n,r=i?Ra(i,t.id):[],d=new Set(us(r,t.mcpServers,t.id).map(f=>f.name)),u=f=>{const v=Aa(t,l.connectedSlugs,f.slug,f.scope===null);Object.keys(v).length>0&&c(v)},x=f=>{t.busy||o||c({mcpServers:Ma(r,t.mcpServers,f)})},k=p?l.phase==="loading"?s("common.checking"):l.phase==="unknown"?s("botSettings.simple.appsUnknown"):l.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}),p&&l.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:()=>u(f),className:"disabled:cursor-not-allowed"})]},f.slug))]}),(r.length>0||o)&&e.jsxs(M,{label:s("connectors.tab.mcp"),children:[o&&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:d.has(f.name),"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:f.name}),disabled:!f.enabled||!!t.busy||o,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:()=>Ia(a,t.id),children:s("botPanel.apps.connectAnother")})})]})}function Xr({bot:t,derived:n}){const{state:a,dispatch:l}=B(),[i,o]=m.useState(()=>n.botRoutines.length===0?"new":null);return e.jsxs(e.Fragment,{children:[e.jsx(Li,{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:o,onLogs:c=>l({type:"showRoutines",section:"logs",botId:t.id,routineId:c.id}),onToggle:c=>l({type:"updateRoutine",routineId:c.id,patch:{enabled:!c.enabled}})}),e.jsx(M,{children:e.jsx(ue,{"data-panel-action":"new-routine",icon:Ne,onClick:()=>o("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($i,{routine:i==="new"?void 0:i,bots:[t],lockedBotId:t.id,onClose:()=>o(null)},t.id)]})}function eo({bot:t}){const n=$s(t),[a,l]=m.useState(""),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),u=t.memoryEnabled!==!1,x=n.docs?Bs(n.docs):null,k=n.docs?.find(w=>w.path===se)??null;m.useEffect(()=>o(null),[t.id,u]);const f=async w=>{if(c)return!1;p(!0),d(null);try{return await w()}catch(b){return d(ke(b,s("botPanel.library.memoryError"))),!1}finally{p(!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(),d(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,Er(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,Rr(k.text,a))&&l("")};return u&&i?.botId===t.id?e.jsx(to,{bot:t,doc:i.doc,mine:n.mine,onDone:w=>{w&&n.setDoc(w),o(null),d(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[u?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:c,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})]}),u&&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:c||k===null,onChange:l,onSubmit:()=>{N()}}),k&&e.jsx(ue,{"data-panel-link":"memory-text",icon:Me,onClick:()=>o({botId:t.id,doc:k}),children:s("botPanel.memory.editText")})]}),u&&!n.mine&&e.jsx(Yr,{bot:t,onChanged:n.reload})]})}function to({bot:t,doc:n,mine:a,onDone:l}){const[i,o]=m.useState({text:n.text,hash:n.hash}),[c,p]=m.useState(n.text),[r,d]=m.useState(null),[u,x]=m.useState(null),[k,f]=m.useState(!1),[v,j]=m.useState(null),N=m.useRef(!0);m.useEffect(()=>(N.current=!0,()=>{N.current=!1}),[]);const w=async h=>{f(!0),j(null);try{const P=await ot(t.id,n.path,c,h,a);if(!N.current)return;P.ok?l(P.doc):d({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===c?c:`${h}
15
15
 
16
- ${c}`),o({text:r.current,hash:r.currentHash}),p(r.current),d(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:c,placeholder:s("memory.indexPlaceholder"),"aria-label":s("memory.botMemory"),readOnly:k,onChange:h=>p(h.target.value)}),v&&e.jsx("div",{className:"text-[13px] text-warning",children:v}),u!==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:u}),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:()=>l(null),children:s("common.cancel")}),e.jsx("button",{type:"button","data-panel-done":"memory-text",className:le,disabled:k||c===i.text,onClick:()=>{w(i.hash)},children:k?s("memory.saving"):s("memory.save")})]})]})})}function to({text:t}){const[n,a]=m.useState(!1),[l,i]=m.useState(!1),o=m.useRef(null);return m.useEffect(()=>{const c=o.current;if(!c||n)return;const p=()=>i(c.scrollHeight>c.clientHeight);p();const r=new ResizeObserver(p);return r.observe(c),()=>r.disconnect()},[t,n]),e.jsx("button",{type:"button",disabled:!n&&!l,"aria-expanded":n,className:"block w-full text-start enabled:cursor-pointer enabled:hover:underline",onClick:()=>a(c=>!c),children:e.jsx("span",{ref:o,className:n?"block break-words":"line-clamp-2 break-words",children:t})})}function so({bot:t}){const{request:n}=Oa(),{state:a,dispatch:l}=B(),i=ws(t),[o,c]=m.useState(""),[p,r]=m.useState(!1),[d,u]=m.useState([]),x=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=o.trim();if(!(!h||p)){r(!0),i.setError(""),u([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:h})});u(Rt(P.imported??[])),c(""),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||p)){r(!0),i.setError(""),u([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:`local-folder:${h}`})});u(Rt(P.imported??[])),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},[j,N]=m.useState(!1),w=()=>{N(!1),l({type:"toggleSettings",open:!1}),l({type:"toggleAppSettings",open:!0,section:"skills"})},b=()=>{if(x){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:e.jsx(to,{text: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:o,placeholder:s("botPanel.skills.importPlaceholder"),label:s("skills.import.label"),action:p?s("skills.import.importing"):s("common.add"),disabled:p,onChange:c,onSubmit:()=>{f()}}),d.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 no({bot:t}){const{capabilities:n}=we(),a=n.host?.homeDir,{draft:l,setDraft:i,error:o,saving:c,canPick:p,save:r,pick:d}=ji(t),[u,x]=m.useState(!1),k=!!t.cwd||u,f=()=>{if(p){d();return}x(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[e.jsx(Ze,{"data-panel-choice":"private",title:s("botPanel.folder.own"),hint:s("botPanel.folder.ownHint"),checked:!k,disabled:c,onClick:()=>{x(!1),t.cwd&&r(null)}}),e.jsx(Ze,{"data-panel-choice":"pick",title:s("botPanel.folder.pick"),hint:s("botPanel.folder.pickHint"),checked:k,disabled:c,onClick:()=>{t.cwd||f()}})]}),k&&e.jsxs(M,{children:[p?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:c,onClick:()=>{d()},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=(l??t.cwd??"").trim();j&&r(j)},children:[e.jsx("input",{value:l??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:c||l===null,className:le,children:s("botAccess.folder.save")})]}),o&&e.jsx(V,{tone:"warn",children:o})]}),e.jsx(Ca,{value:t.cwd,disabled:c,onChoose:r}),e.jsx(Pa,{kind:"bots",id:t.id,folder:t.cwd})]})}function ao({bot:t,derived:n}){const a=As(t);return e.jsx(Ar,{bot:t,browserEnabled:n.browserEnabled,onOpenBrowser:()=>a("browser")})}function io({bot:t}){return Ss()?e.jsx(Cs,{bot:t}):null}function ro({page:t,onOpen:n,editingInstructions:a,onEditInstructions:l,...i}){switch(t){case"settings":return e.jsx(Vr,{...i,onOpen:n,editingInstructions:a,onEditInstructions:l});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(io,{...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(so,{...i});case"folder":return e.jsx(no,{...i});case"browser":return e.jsx(ao,{...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 Zt(t){const[n,a]=m.useState(null),l=m.useRef(!1),i=m.useRef(!1),o=m.useRef(null);m.useEffect(()=>{n!==null||!i.current||(i.current=!1,o.current?.focus())},[n]);const c=u=>{l.current=!1,a(u)},p=()=>{n!==null&&t(n),a(null)};return{draft:n,setDraft:a,start:c,onKeyDown:u=>{if(Ba(u.nativeEvent)){u.stopPropagation();return}u.key==="Enter"?(u.preventDefault(),l.current=!0,i.current=!0,p()):u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),l.current=!0,i.current=!0,a(null))},onBlur:()=>{l.current||p()},buttonRef:o}}function oo({bot:t,activeState:n,patch:a,editorOpen:l,onToggleEditor:i}){const o=Zt(r=>{const d=r.trim();d&&d!==t.name&&a({name:d})}),c=Zt(r=>{const d=r.trim();d!==t.title.trim()&&a({title:d})}),p=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":l,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:o.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-rename-input":!0,"aria-label":s("botSettings.simple.name"),maxLength:Qe.name,value:o.draft,onChange:r=>o.setDraft(r.target.value),onKeyDown:o.onKeyDown,onBlur:o.onBlur,className:O(Gt,"w-[220px] max-w-full text-[17px] font-medium leading-6")}):e.jsxs("button",{ref:o.buttonRef,type:"button","data-panel-rename":!0,title:s("botPanel.rename"),onClick:()=>o.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"})]})})}),c.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:c.draft,onChange:r=>c.setDraft(r.target.value),onKeyDown:c.onKeyDown,onBlur:c.onBlur,className:O(Gt,"mt-[3px] w-[200px] max-w-full text-[13px]")}):p&&e.jsx("button",{ref:c.buttonRef,type:"button","data-panel-label":!0,onClick:()=>c.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:p})]})}function Pe(t,n){return t?hs(t,n):{tab:"details"}}function lo({bot:t,derived:n,linkedSection:a,onClose:l}){const{dragProps:i}=ys(),o=$a(),[c,p]=m.useState(()=>Pe(a,o).tab),[r,d]=m.useState(()=>{const g=Pe(a,o).page;return g?[g]:[]}),[u,x]=m.useState(()=>Pe(a,o).anchor??null),[k,f]=m.useState(!1),[v,j]=m.useState(()=>!!Pe(a,o).editInstructions),N=m.useRef(null),w=m.useRef(null),b=r.at(-1)??null,h=()=>N.current?.scrollTo({top:0}),P=g=>{p(g.tab),d(g.page?[g.page]:[]),x(g.anchor??null),f(!1),j(!!g.editInstructions),h()},L=g=>P({tab:g}),F=g=>{d(T=>[...T,g]),f(!1),h()},$=()=>{f(!1),w.current?.querySelector("[data-panel-avatar]")?.focus()},A=()=>{d(g=>g.slice(0,-1)),h()};m.useEffect(()=>{a&&P(hs(a,o))},[a,o]),m.useEffect(()=>{u&&(N.current?.querySelector(`[data-panel-card="${u}"]`)?.scrollIntoView({block:"start"}),x(null))},[u,b,c]);const H=g=>{if(g.key!=="Escape"||g.defaultPrevented)return;const T=g.target,D=typeof T?.closest=="function"?T.closest('[role="dialog"], [role="alertdialog"]'):null;if(!(D&&!D.contains(g.currentTarget)&&D!==w.current&&!w.current?.contains(D))){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[c]);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(Da,{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(Fa,{size:16,className:"pointer-events-none"})}),e.jsx("button",{type:"button",onClick:l,"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(oo,{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":c===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",c===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:[c==="details"&&e.jsx(Cr,{bot:t,derived:n,onOpen:F}),c==="library"&&e.jsx(Ds,{bot:t,onOpen:F}),c==="computer"&&e.jsx(fr,{bot:t,derived:n,onOpen:F})]})]}):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(ro,{page:b,bot:t,derived:n,onOpen:F,editingInstructions:v,onEditInstructions:j})})]})})]})}function co(t,n){const{state:a,flushBotPatches:l}=B(),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),[u,x]=m.useState(!1),k=m.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 m.useEffect(()=>{if(!n.overview&&!n.prompt)return;let w=!1;return(async()=>(await l(t.id),!w&&(n.overview&&G(`/api/bots/${t.id}/overview`).then(h=>{w||(o(h),p(!1))}).catch(()=>{w||p(!0)}),n.prompt&&G(`/api/bots/${t.id}/system-prompt`).then(h=>{w||(d(h),x(!1))}).catch(()=>{w||x(!0)}))))(),()=>{w=!0}},[t.id,n.overview,n.prompt,v,j,N,l]),{overview:i,overviewError:c,prompt:r,promptError:u}}function po(t,n){const{dispatch:a,flushBotPatches:l}=B(),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),u=m.useRef(0),[x,k]=m.useState(!1),[f,v]=m.useState(null),j=m.useCallback(()=>{const b=++u.current;return p(!1),l(t.id).then(()=>G(`/api/bots/${t.id}/history?limit=100`)).then(h=>{b===u.current&&(o(h.rows),d(h.revision))}).catch(()=>{b===u.current&&p(!0)})},[t.id,l]);return m.useEffect(()=>{if(n)return j(),()=>{u.current++}},[n,j]),{rows:i,error:c,revision:r,rollingBack:x,rollbackTarget:f,setRollbackTarget:v,rollback:async b=>{if(!x){v(null),k(!0);try{await l(t.id),await G(`/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 mo({history:t,returnFocusRef:n}){const{rollbackTarget:a,setRollbackTarget:l,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:()=>l(null),onConfirm:()=>{a&&i(a)}})}const uo={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 Ro({bot:t,overlay:n=!1}){const{state:a,dispatch:l}=B(),i=a.botSettingsSection,o=Ka(t),c=m.useRef(null),{dragProps:p}=ys(),[r,d]=m.useState(""),u=!a.botSettingsExpandAccordion,x=r.trim().toLowerCase(),f=!Jt(),v=!u&&!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,x)),{overview:P,overviewError:L,prompt:F,promptError:$}=co(t,{overview:i==="overview"&&!f,prompt:i==="overview"&&!f}),A=po(t,i==="history"&&!f);m.useEffect(()=>{if(!u){if(x){d("");return}c.current?.querySelector(`[data-bot-settings-section="${i}"]`)?.scrollIntoView({block:"nearest"})}},[u,i,x]),m.useEffect(()=>{const I=document.activeElement instanceof HTMLElement?document.activeElement:null,g=c.current;g?.focus();const T=D=>{const _=g?.querySelector('[role="dialog"], [role="alertdialog"]');_&&_.getClientRects().length>0||g&&D.target instanceof Node&&!g.contains(D.target)||D.key==="Escape"&&!D.defaultPrevented&&(D.preventDefault(),l({type:"toggleSettings",open:!1}))};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T),I?.focus()}},[l]);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:F,promptError:$,onOpen:g=>l({type:"toggleSettings",open:!0,section:g}),onSetup:o.canCoordinate&&!t.busy?()=>{l({type:"toggleSettings",open:!1}),l({type:"send",botId:t.id,text:"/setup",threadId:t.threadId})}:void 0});case"identity":return e.jsx(Ti,{bot:t,patch:o.patch,activeState:o.activeState,mascotMotion:o.mascotMotion});case"soul":return e.jsx(Ri,{bot:t,patch:o.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:!u&&i==="memory",onToggle:g=>o.patch({memoryEnabled:g})});case"library":return e.jsx(Ds,{bot:t,onOpen:g=>l({type:"toggleSettings",open:!0,section:uo[g]??"overview"})});case"routines":return e.jsx(Li,{bot:t,routines:o.botRoutines,runs:a.routineRuns});case"access":return e.jsx(Oi,{bot:t,derived:o});case"model":return e.jsx(Pi,{bot:t});case"permissions":return e.jsx(Ci,{bot:t,derived:o});case"voice":return e.jsx(Si,{bot:t,derived:o});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:c,id:f?qa:void 0,role:"dialog","aria-labelledby":"bot-settings-title",tabIndex:-1,className:Va(n,f),children:f?e.jsx(lo,{bot:t,derived:o,linkedSection:v,onClose:()=>l({type:"toggleSettings",open:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{...p,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:()=>l({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=>{d(I.target.value),l({type:"toggleSettings",open:!0})},onKeyDown:I=>{I.key==="Escape"&&(I.stopPropagation(),r?d(""):l({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,D=zs(I),_=Yt(I,x);if(!_&&g!=="memory")return null;const K=!u&&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&&!u){l({type:"toggleSettings",open:!0});return}l({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:D}),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(mo,{history:A,returnFocusRef:c})]})}export{Ro as BotSettingsDialog};
16
+ ${c}`),o({text:r.current,hash:r.currentHash}),p(r.current),d(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:c,placeholder:s("memory.indexPlaceholder"),"aria-label":s("memory.botMemory"),readOnly:k,onChange:h=>p(h.target.value)}),v&&e.jsx("div",{className:"text-[13px] text-warning",children:v}),u!==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:u}),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:()=>l(null),children:s("common.cancel")}),e.jsx("button",{type:"button","data-panel-done":"memory-text",className:le,disabled:k||c===i.text,onClick:()=>{w(i.hash)},children:k?s("memory.saving"):s("memory.save")})]})]})})}function so({text:t}){const[n,a]=m.useState(!1),[l,i]=m.useState(!1),o=m.useRef(null);return m.useEffect(()=>{const c=o.current;if(!c||n)return;const p=()=>i(c.scrollHeight>c.clientHeight);p();const r=new ResizeObserver(p);return r.observe(c),()=>r.disconnect()},[t,n]),e.jsx("button",{type:"button",disabled:!n&&!l,"aria-expanded":n,className:"block w-full text-start enabled:cursor-pointer enabled:hover:underline",onClick:()=>a(c=>!c),children:e.jsx("span",{ref:o,className:n?"block break-words":"line-clamp-2 break-words",children:t})})}function no({bot:t}){const{request:n}=Oa(),{state:a,dispatch:l}=B(),i=ws(t),[o,c]=m.useState(""),[p,r]=m.useState(!1),[d,u]=m.useState([]),x=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=o.trim();if(!(!h||p)){r(!0),i.setError(""),u([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:h})});u(Rt(P.imported??[])),c(""),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||p)){r(!0),i.setError(""),u([]);try{const P=await n(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:`local-folder:${h}`})});u(Rt(P.imported??[])),await i.refresh()}catch(P){i.setError(ke(P,s("botPanel.skills.importFailed")))}finally{r(!1)}}},[j,N]=m.useState(!1),w=()=>{N(!1),l({type:"toggleSettings",open:!1}),l({type:"toggleAppSettings",open:!0,section:"skills"})},b=()=>{if(x){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:e.jsx(so,{text: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(Ni,{bot:t,onAdded:()=>{i.refresh()}}),e.jsxs(M,{children:[e.jsx(xs,{"data-panel-form":"skill-import",value:o,placeholder:s("botPanel.skills.importPlaceholder"),label:s("skills.import.label"),action:p?s("skills.import.importing"):s("common.add"),disabled:p,onChange:c,onSubmit:()=>{f()}}),d.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($r,{botId:t.id,botName:t.name,onOpenSettings:w,onClose:()=>{N(!1),i.refresh()}}),i.reviewing&&e.jsx(Si,{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 ao({bot:t}){const{capabilities:n}=we(),a=n.host?.homeDir,{draft:l,setDraft:i,error:o,saving:c,canPick:p,save:r,pick:d}=ji(t),[u,x]=m.useState(!1),k=!!t.cwd||u,f=()=>{if(p){d();return}x(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(M,{children:[e.jsx(Ze,{"data-panel-choice":"private",title:s("botPanel.folder.own"),hint:s("botPanel.folder.ownHint"),checked:!k,disabled:c,onClick:()=>{x(!1),t.cwd&&r(null)}}),e.jsx(Ze,{"data-panel-choice":"pick",title:s("botPanel.folder.pick"),hint:s("botPanel.folder.pickHint"),checked:k,disabled:c,onClick:()=>{t.cwd||f()}})]}),k&&e.jsxs(M,{children:[p?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:c,onClick:()=>{d()},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=(l??t.cwd??"").trim();j&&r(j)},children:[e.jsx("input",{value:l??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:c||l===null,className:le,children:s("botAccess.folder.save")})]}),o&&e.jsx(V,{tone:"warn",children:o})]}),e.jsx(wi,{bot:t,disabled:c}),e.jsx(Ca,{value:t.cwd,disabled:c,onChoose:r}),e.jsx(Pa,{kind:"bots",id:t.id,folder:t.cwd})]})}function io({bot:t,derived:n}){const a=As(t);return e.jsx(Mr,{bot:t,browserEnabled:n.browserEnabled,onOpenBrowser:()=>a("browser")})}function ro({bot:t}){return Ss()?e.jsx(Cs,{bot:t}):null}function oo({page:t,onOpen:n,editingInstructions:a,onEditInstructions:l,...i}){switch(t){case"settings":return e.jsx(Gr,{...i,onOpen:n,editingInstructions:a,onEditInstructions:l});case"where":return e.jsx(fr,{...i});case"apps":return e.jsx(Qr,{...i});case"routines":return e.jsx(Xr,{...i});case"visibility":return e.jsx(ro,{...i});case"memory":return e.jsx(eo,{...i});case"plugins":return e.jsx(Es,{bot:i.bot},i.bot.id);case"skills":return e.jsx(no,{...i});case"folder":return e.jsx(ao,{...i});case"browser":return e.jsx(io,{...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 Zt(t){const[n,a]=m.useState(null),l=m.useRef(!1),i=m.useRef(!1),o=m.useRef(null);m.useEffect(()=>{n!==null||!i.current||(i.current=!1,o.current?.focus())},[n]);const c=u=>{l.current=!1,a(u)},p=()=>{n!==null&&t(n),a(null)};return{draft:n,setDraft:a,start:c,onKeyDown:u=>{if(Ba(u.nativeEvent)){u.stopPropagation();return}u.key==="Enter"?(u.preventDefault(),l.current=!0,i.current=!0,p()):u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),l.current=!0,i.current=!0,a(null))},onBlur:()=>{l.current||p()},buttonRef:o}}function lo({bot:t,activeState:n,patch:a,editorOpen:l,onToggleEditor:i}){const o=Zt(r=>{const d=r.trim();d&&d!==t.name&&a({name:d})}),c=Zt(r=>{const d=r.trim();d!==t.title.trim()&&a({title:d})}),p=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":l,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:o.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-rename-input":!0,"aria-label":s("botSettings.simple.name"),maxLength:Qe.name,value:o.draft,onChange:r=>o.setDraft(r.target.value),onKeyDown:o.onKeyDown,onBlur:o.onBlur,className:O(Gt,"w-[220px] max-w-full text-[17px] font-medium leading-6")}):e.jsxs("button",{ref:o.buttonRef,type:"button","data-panel-rename":!0,title:s("botPanel.rename"),onClick:()=>o.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"})]})})}),c.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:c.draft,onChange:r=>c.setDraft(r.target.value),onKeyDown:c.onKeyDown,onBlur:c.onBlur,className:O(Gt,"mt-[3px] w-[200px] max-w-full text-[13px]")}):p&&e.jsx("button",{ref:c.buttonRef,type:"button","data-panel-label":!0,onClick:()=>c.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:p})]})}function Pe(t,n){return t?hs(t,n):{tab:"details"}}function co({bot:t,derived:n,linkedSection:a,onClose:l}){const{dragProps:i}=ys(),o=$a(),[c,p]=m.useState(()=>Pe(a,o).tab),[r,d]=m.useState(()=>{const g=Pe(a,o).page;return g?[g]:[]}),[u,x]=m.useState(()=>Pe(a,o).anchor??null),[k,f]=m.useState(!1),[v,j]=m.useState(()=>!!Pe(a,o).editInstructions),N=m.useRef(null),w=m.useRef(null),b=r.at(-1)??null,h=()=>N.current?.scrollTo({top:0}),P=g=>{p(g.tab),d(g.page?[g.page]:[]),x(g.anchor??null),f(!1),j(!!g.editInstructions),h()},L=g=>P({tab:g}),F=g=>{d(T=>[...T,g]),f(!1),h()},$=()=>{f(!1),w.current?.querySelector("[data-panel-avatar]")?.focus()},A=()=>{d(g=>g.slice(0,-1)),h()};m.useEffect(()=>{a&&P(hs(a,o))},[a,o]),m.useEffect(()=>{u&&(N.current?.querySelector(`[data-panel-card="${u}"]`)?.scrollIntoView({block:"start"}),x(null))},[u,b,c]);const H=g=>{if(g.key!=="Escape"||g.defaultPrevented)return;const T=g.target,D=typeof T?.closest=="function"?T.closest('[role="dialog"], [role="alertdialog"]'):null;if(!(D&&!D.contains(g.currentTarget)&&D!==w.current&&!w.current?.contains(D))){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[c]);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(Da,{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(Fa,{size:16,className:"pointer-events-none"})}),e.jsx("button",{type:"button",onClick:l,"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(lo,{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(xr,{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":c===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",c===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:[c==="details"&&e.jsx(Pr,{bot:t,derived:n,onOpen:F}),c==="library"&&e.jsx(Ds,{bot:t,onOpen:F}),c==="computer"&&e.jsx(yr,{bot:t,derived:n,onOpen:F})]})]}):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",Jr),children:e.jsx(oo,{page:b,bot:t,derived:n,onOpen:F,editingInstructions:v,onEditInstructions:j})})]})})]})}function po(t,n){const{state:a,flushBotPatches:l}=B(),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),[u,x]=m.useState(!1),k=m.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 m.useEffect(()=>{if(!n.overview&&!n.prompt)return;let w=!1;return(async()=>(await l(t.id),!w&&(n.overview&&G(`/api/bots/${t.id}/overview`).then(h=>{w||(o(h),p(!1))}).catch(()=>{w||p(!0)}),n.prompt&&G(`/api/bots/${t.id}/system-prompt`).then(h=>{w||(d(h),x(!1))}).catch(()=>{w||x(!0)}))))(),()=>{w=!0}},[t.id,n.overview,n.prompt,v,j,N,l]),{overview:i,overviewError:c,prompt:r,promptError:u}}function mo(t,n){const{dispatch:a,flushBotPatches:l}=B(),[i,o]=m.useState(null),[c,p]=m.useState(!1),[r,d]=m.useState(null),u=m.useRef(0),[x,k]=m.useState(!1),[f,v]=m.useState(null),j=m.useCallback(()=>{const b=++u.current;return p(!1),l(t.id).then(()=>G(`/api/bots/${t.id}/history?limit=100`)).then(h=>{b===u.current&&(o(h.rows),d(h.revision))}).catch(()=>{b===u.current&&p(!0)})},[t.id,l]);return m.useEffect(()=>{if(n)return j(),()=>{u.current++}},[n,j]),{rows:i,error:c,revision:r,rollingBack:x,rollbackTarget:f,setRollbackTarget:v,rollback:async b=>{if(!x){v(null),k(!0);try{await l(t.id),await G(`/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 uo({history:t,returnFocusRef:n}){const{rollbackTarget:a,setRollbackTarget:l,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:()=>l(null),onConfirm:()=>{a&&i(a)}})}const xo={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 To({bot:t,overlay:n=!1}){const{state:a,dispatch:l}=B(),i=a.botSettingsSection,o=Ka(t),c=m.useRef(null),{dragProps:p}=ys(),[r,d]=m.useState(""),u=!a.botSettingsExpandAccordion,x=r.trim().toLowerCase(),f=!Jt(),v=!u&&!a.botSettingsExpandRemembered?i:null,j=Os(t.id),N=Le(),w=Ua(),b=Wi.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,x)),{overview:P,overviewError:L,prompt:F,promptError:$}=po(t,{overview:i==="overview"&&!f,prompt:i==="overview"&&!f}),A=mo(t,i==="history"&&!f);m.useEffect(()=>{if(!u){if(x){d("");return}c.current?.querySelector(`[data-bot-settings-section="${i}"]`)?.scrollIntoView({block:"nearest"})}},[u,i,x]),m.useEffect(()=>{const I=document.activeElement instanceof HTMLElement?document.activeElement:null,g=c.current;g?.focus();const T=D=>{const _=g?.querySelector('[role="dialog"], [role="alertdialog"]');_&&_.getClientRects().length>0||g&&D.target instanceof Node&&!g.contains(D.target)||D.key==="Escape"&&!D.defaultPrevented&&(D.preventDefault(),l({type:"toggleSettings",open:!1}))};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T),I?.focus()}},[l]);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(Xi,{overview:P,refreshError:P!==null&&L,prompt:F,promptError:$,onOpen:g=>l({type:"toggleSettings",open:!0,section:g}),onSetup:o.canCoordinate&&!t.busy?()=>{l({type:"toggleSettings",open:!1}),l({type:"send",botId:t.id,text:"/setup",threadId:t.threadId})}:void 0});case"identity":return e.jsx(Ii,{bot:t,patch:o.patch,activeState:o.activeState,mascotMotion:o.mascotMotion});case"soul":return e.jsx(Ti,{bot:t,patch:o.patch});case"slack":return j?e.jsx(er,{managementUrl:j}):null;case"plugins":return e.jsx(Es,{bot:t},t.id);case"skills":return e.jsx(Ri,{bot:t});case"memory":return e.jsx(nr,{bot:t,active:!u&&i==="memory",onToggle:g=>o.patch({memoryEnabled:g})});case"library":return e.jsx(Ds,{bot:t,onOpen:g=>l({type:"toggleSettings",open:!0,section:xo[g]??"overview"})});case"routines":return e.jsx(Bi,{bot:t,routines:o.botRoutines,runs:a.routineRuns});case"access":return e.jsx(Ei,{bot:t,derived:o});case"model":return e.jsx(Oi,{bot:t});case"permissions":return e.jsx(Pi,{bot:t,derived:o});case"voice":return e.jsx(Ci,{bot:t,derived:o});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(or,{bot:t,rows:A.rows,refreshError:A.rows!==null&&A.error,onRollback:A.requestRollback,rollingBack:A.rollingBack||!A.revision});case"usage":return e.jsx(lr,{bot:t});default:return null}};return e.jsxs(e.Fragment,{children:[e.jsx("aside",{ref:c,id:f?qa:void 0,role:"dialog","aria-labelledby":"bot-settings-title",tabIndex:-1,className:Va(n,f),children:f?e.jsx(co,{bot:t,derived:o,linkedSection:v,onClose:()=>l({type:"toggleSettings",open:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{...p,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:()=>l({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=>{d(I.target.value),l({type:"toggleSettings",open:!0})},onKeyDown:I=>{I.key==="Escape"&&(I.stopPropagation(),r?d(""):l({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,D=zs(I),_=Yt(I,x);if(!_&&g!=="memory")return null;const K=!u&&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&&!u){l({type:"toggleSettings",open:!0});return}l({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:D}),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(uo,{history:A,returnFocusRef:c})]})}export{To as BotSettingsDialog};