local-operator-ui 0.29.11 → 0.30.0

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 (71) hide show
  1. package/out/main/index.js +4801 -386
  2. package/out/preload/index.js +117 -0
  3. package/out/renderer/assets/{_basePickBy-gHcXb1KL.js → _basePickBy-Bxj6z8Wi.js} +1 -1
  4. package/out/renderer/assets/{_baseUniq-Cjg_TxLc.js → _baseUniq-CRJuWtvs.js} +1 -1
  5. package/out/renderer/assets/{agent-details-page-BLVP0oIP.js → agent-details-page-DRjUMEUI.js} +1 -1
  6. package/out/renderer/assets/{agent-hub-page-DAzUXdCl.js → agent-hub-page-BMCNLFYk.js} +1 -1
  7. package/out/renderer/assets/{agents-page-BqqWqJRL.js → agents-page-D4pQP4dR.js} +2 -2
  8. package/out/renderer/assets/{arc-7-q8aDG3.js → arc-W5w8I8BO.js} +1 -1
  9. package/out/renderer/assets/{architectureDiagram-IEHRJDOE-Ba7yCUVS.js → architectureDiagram-IEHRJDOE-uGd1cdqb.js} +1 -1
  10. package/out/renderer/assets/{blockDiagram-JOT3LUYC-t6SLXRXN.js → blockDiagram-JOT3LUYC-D1Eg2vE0.js} +1 -1
  11. package/out/renderer/assets/browser-page-CZ3Z-PgY.js +1 -0
  12. package/out/renderer/assets/{browser-webauthn-prompt-BiFtkxJX.js → browser-webauthn-prompt-C1cS8dj0.js} +1 -1
  13. package/out/renderer/assets/{c4Diagram-VJAJSXHY-C6nxJeUu.js → c4Diagram-VJAJSXHY-Me-bZTC4.js} +1 -1
  14. package/out/renderer/assets/channel-CYsqm6Ws.js +1 -0
  15. package/out/renderer/assets/{chunk-4BMEZGHF-iV0vwEQH.js → chunk-4BMEZGHF-CEIGhpCi.js} +1 -1
  16. package/out/renderer/assets/{chunk-A2AXSNBT-Bo_VOUDE.js → chunk-A2AXSNBT-GF1F80gh.js} +1 -1
  17. package/out/renderer/assets/{chunk-AEK57VVT-CdHexsQ8.js → chunk-AEK57VVT-DtLnbbUV.js} +1 -1
  18. package/out/renderer/assets/{chunk-D6G4REZN-CeLv_5W7.js → chunk-D6G4REZN-B1DRTHm0.js} +1 -1
  19. package/out/renderer/assets/{chunk-RZ5BOZE2-BnQffRFA.js → chunk-RZ5BOZE2-D6h9Tibd.js} +1 -1
  20. package/out/renderer/assets/{chunk-XZIHB7SX-5It_CStB.js → chunk-XZIHB7SX-DO5kHk_V.js} +1 -1
  21. package/out/renderer/assets/classDiagram-GIVACNV2-ChJdbdZp.js +1 -0
  22. package/out/renderer/assets/classDiagram-v2-COTLJTTW-ChJdbdZp.js +1 -0
  23. package/out/renderer/assets/clone-C6PHt_85.js +1 -0
  24. package/out/renderer/assets/{compact-pagination-BJfBJjZq.js → compact-pagination-DvIFPVVF.js} +1 -1
  25. package/out/renderer/assets/{dagre-OKDRZEBW-CPHSSmct.js → dagre-OKDRZEBW-u5fIdPgH.js} +1 -1
  26. package/out/renderer/assets/{diagram-SSKATNLV-uoifaHV7.js → diagram-SSKATNLV-BX2uYodZ.js} +1 -1
  27. package/out/renderer/assets/{diagram-VNBRO52H-DiPorn-j.js → diagram-VNBRO52H-CjnNNdUv.js} +1 -1
  28. package/out/renderer/assets/{erDiagram-Q7BY3M3F-D3_RVsgS.js → erDiagram-Q7BY3M3F-qtGVvLUM.js} +1 -1
  29. package/out/renderer/assets/{flowDiagram-4HSFHLVR-9kpTgY8l.js → flowDiagram-4HSFHLVR-DQvp9JGV.js} +1 -1
  30. package/out/renderer/assets/{ganttDiagram-APWFNJXF-C1hwJAlh.js → ganttDiagram-APWFNJXF-Ci1ah8CY.js} +1 -1
  31. package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-BvA7T2vP.js → gitGraphDiagram-7IBYFJ6S-wJbkC8Is.js} +1 -1
  32. package/out/renderer/assets/{graph-DpmQwtUv.js → graph-DJopaDTn.js} +1 -1
  33. package/out/renderer/assets/icon-Bld1dwLh.css +1 -0
  34. package/out/renderer/assets/{index-Bw89Hsw-.js → index-CnT3YOgO.js} +383 -378
  35. package/out/renderer/assets/{index-CxwcyLWF.js → index-CxqFXiU9.js} +1 -1
  36. package/out/renderer/assets/{index-Dl2E40WV.js → index-DnCfIkzT.js} +1 -1
  37. package/out/renderer/assets/{infoDiagram-PH2N3AL5-W9OqWzoG.js → infoDiagram-PH2N3AL5-B3U7DI90.js} +1 -1
  38. package/out/renderer/assets/{installer-Cf6g2y9a.js → installer-B8Nn8EOm.js} +1 -1
  39. package/out/renderer/assets/{journeyDiagram-U35MCT3I-Deb5RarE.js → journeyDiagram-U35MCT3I-DScIXrsc.js} +1 -1
  40. package/out/renderer/assets/{kanban-definition-NDS4AKOZ-BsbQgmLq.js → kanban-definition-NDS4AKOZ-44QsoV35.js} +1 -1
  41. package/out/renderer/assets/{layout-CrJ6Fu9B.js → layout-C2XO3rbH.js} +1 -1
  42. package/out/renderer/assets/{legacy-agents-page-egSNYRnK.js → legacy-agents-page-DzvJsW6a.js} +9 -14
  43. package/out/renderer/assets/{mermaid.core-BYxmKNp-.js → mermaid.core-CedM0RYf.js} +19 -19
  44. package/out/renderer/assets/{mindmap-definition-ALO5MXBD-C-9egivQ.js → mindmap-definition-ALO5MXBD-Cjvw-N5z.js} +1 -1
  45. package/out/renderer/assets/{page-header-B9ZaEm1G.js → page-header-CpVC9jUn.js} +1 -1
  46. package/out/renderer/assets/{parseISO-B1ekvrn4.js → parseISO-D0NosKnD.js} +1 -1
  47. package/out/renderer/assets/{pieDiagram-IB7DONF6-B8qVlKET.js → pieDiagram-IB7DONF6-BqCKCsJW.js} +1 -1
  48. package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-DFTB7_6X.js → quadrantDiagram-7GDLP6J5-Pojkyhrm.js} +1 -1
  49. package/out/renderer/assets/{radar-MK3ICKWK-BBqHNsuC.js → radar-MK3ICKWK-Bx4TYIXP.js} +1 -1
  50. package/out/renderer/assets/{radient-auth-buttons-D7Z-gfFA.js → radient-auth-buttons-D_SoNQJd.js} +1 -1
  51. package/out/renderer/assets/{requirementDiagram-KVF5MWMF-nfWLgIi1.js → requirementDiagram-KVF5MWMF-DUkbReMG.js} +1 -1
  52. package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-kz3aMr3g.js → sankeyDiagram-QLVOVGJD-BUGhR_2u.js} +1 -1
  53. package/out/renderer/assets/{schedules-page-9k1r0G5Z.js → schedules-page-9pqWDmrK.js} +1 -1
  54. package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-BlPj6-VP.js → sequenceDiagram-X6HHIX6F-B0ZGPAMn.js} +1 -1
  55. package/out/renderer/assets/{settings-page-7FNkwi6H.js → settings-page-CnL9a7Fr.js} +1 -1
  56. package/out/renderer/assets/{stateDiagram-DGXRK772-U-C3BZ-1.js → stateDiagram-DGXRK772-Cg6i1sjE.js} +1 -1
  57. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-SfqhHCpy.js +1 -0
  58. package/out/renderer/assets/{timeline-definition-BDJGKUSR-Bg_ZEH7m.js → timeline-definition-BDJGKUSR-8RQ5e7vN.js} +1 -1
  59. package/out/renderer/assets/{use-agent-like-mutation-B5uInGPk.js → use-agent-like-mutation-anGek86t.js} +1 -1
  60. package/out/renderer/assets/{xychartDiagram-VJFVF3MP-CUjkSuIE.js → xychartDiagram-VJFVF3MP-DgYi9eSD.js} +1 -1
  61. package/out/renderer/index.html +3 -3
  62. package/out/renderer/installer.html +3 -3
  63. package/package.json +12 -4
  64. package/out/renderer/assets/browser-page-B3ww4TIa.js +0 -1
  65. package/out/renderer/assets/channel-D05avaQg.js +0 -1
  66. package/out/renderer/assets/classDiagram-GIVACNV2-DjtkcyI4.js +0 -1
  67. package/out/renderer/assets/classDiagram-v2-COTLJTTW-DjtkcyI4.js +0 -1
  68. package/out/renderer/assets/clone-CkDaYVxE.js +0 -1
  69. package/out/renderer/assets/icon-C7JJ2uBI.css +0 -1
  70. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-Co-dAGQa.js +0 -1
  71. /package/out/renderer/assets/{icon-BeTB53O2.js → icon-BrElBHST.js} +0 -0
@@ -1,43 +1,38 @@
1
- import{a as H,r,j as e,w as _e,x as Ie,B as T,y as Se,z as B,c as R,S as De,o as q,I as Ee,F as Ye,C as Fe,G as re,L as oe,J as Pe,X as Te,P as Ze,K as Je,M as Xe,A as ne,i as de,k as ee,N as et,O as tt,m as at,n as st}from"./icon-BeTB53O2.js";import{P as nt}from"./page-header-B9ZaEm1G.js";import{bi as it,bj as Le,bk as Ue,bl as he,bm as pe,bn as ot,aA as rt,bo as je,bp as lt,g as Re,f as Oe,bq as fe,br as Q,a6 as qe,at as ct,bs as dt,ar as te,a as ut,bt as mt,bu as ht,aq as Me,aK as Y,aL as ie,P as $e,bv as pt,bw as G,bx as F,by as xt,bz as ft,bA as gt,bB as bt,aJ as yt,bC as jt,bD as kt,B as ge,bE as vt,bF as wt,bG as ze,bH as Nt,bI as xe,h as be,c as Ct,bJ as _t,bK as It,bL as St,bM as ke,bN as Dt,bO as Et,bP as Pt,a4 as Ae,bQ as Be,bR as Tt,bS as He,r as Lt,bT as Ut,bU as Rt,bV as ve}from"./index-Bw89Hsw-.js";import{I as Ot,a as ue,N as qt,R as we}from"./radient-auth-buttons-D7Z-gfFA.js";import{C as Mt}from"./compact-pagination-BJfBJjZq.js";/**
1
+ import{a as Q,r,j as e,w as _e,x as Ie,B as T,y as Se,z as B,c as R,S as De,o as q,I as Ee,F as Ye,C as Fe,G as re,L as oe,J as Pe,X as Te,P as Ze,K as Je,M as Xe,A as ne,i as de,k as ee,N as et,O as tt,m as at,n as st}from"./icon-BrElBHST.js";import{P as nt}from"./page-header-CpVC9jUn.js";import{bi as it,bj as Le,bk as Ue,bl as he,bm as pe,bn as ot,aA as rt,bo as je,bp as lt,g as Re,f as Oe,bq as fe,br as K,a6 as qe,at as ct,bs as dt,ar as te,a as ut,bt as mt,bu as ht,aq as Me,bv as pt,aK as Y,aL as ie,P as $e,bw as xt,bx as G,by as F,bz as ft,bA as gt,bB as bt,bC as yt,aJ as jt,bD as kt,bE as vt,B as ge,bF as wt,bG as Nt,bH as ze,bI as Ct,bJ as xe,h as be,c as _t,bK as It,bL as St,bM as Dt,bN as ke,bO as Et,bP as Pt,bQ as Tt,a4 as Ae,bR as Be,bS as Lt,bT as He,r as Ut,bU as Rt,bV as Ot,bW as ve}from"./index-CnT3YOgO.js";import{I as qt,a as ue,N as Mt,R as we}from"./radient-auth-buttons-D_SoNQJd.js";import{C as $t}from"./compact-pagination-DvIFPVVF.js";/**
2
2
  * @license lucide-react v0.507.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const $t=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]],zt=H("calendar",$t);/**
6
+ */const zt=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]],At=Q("calendar",zt);/**
7
7
  * @license lucide-react v0.507.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const At=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Bt=H("ellipsis-vertical",At);/**
11
+ */const Bt=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Ht=Q("ellipsis-vertical",Bt);/**
12
12
  * @license lucide-react v0.507.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Ht=[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 15h10",key:"jfw4w8"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]],Ne=H("file-input",Ht);/**
16
+ */const Wt=[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 15h10",key:"jfw4w8"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]],Ne=Q("file-input",Wt);/**
17
17
  * @license lucide-react v0.507.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Wt=[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 7V4a2 2 0 0 1 2-2 2 2 0 0 0-2 2",key:"1vk7w2"}],["path",{d:"M4.063 20.999a2 2 0 0 0 2 1L18 22a2 2 0 0 0 2-2V7l-5-5H6",key:"1jink5"}],["path",{d:"m5 11-3 3",key:"1dgrs4"}],["path",{d:"m5 17-3-3h10",key:"1mvvaf"}]],Vt=H("file-output",Wt);/**
21
+ */const Vt=[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 7V4a2 2 0 0 1 2-2 2 2 0 0 0-2 2",key:"1vk7w2"}],["path",{d:"M4.063 20.999a2 2 0 0 0 2 1L18 22a2 2 0 0 0 2-2V7l-5-5H6",key:"1jink5"}],["path",{d:"m5 11-3 3",key:"1dgrs4"}],["path",{d:"m5 17-3-3h10",key:"1mvvaf"}]],Kt=Q("file-output",Vt);/**
22
22
  * @license lucide-react v0.507.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Kt=[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]],Qt=H("git-branch",Kt);/**
26
+ */const Qt=[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]],Gt=Q("git-branch",Qt);/**
27
27
  * @license lucide-react v0.507.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const Gt=[["path",{d:"M16 10h2",key:"8sgtl7"}],["path",{d:"M16 14h2",key:"epxaof"}],["path",{d:"M6.17 15a3 3 0 0 1 5.66 0",key:"n6f512"}],["circle",{cx:"9",cy:"11",r:"2",key:"yxgjnd"}],["rect",{x:"2",y:"5",width:"20",height:"14",rx:"2",key:"qneu4z"}]],Yt=H("id-card",Gt);/**
31
+ */const Yt=[["path",{d:"M16 10h2",key:"8sgtl7"}],["path",{d:"M16 14h2",key:"epxaof"}],["path",{d:"M6.17 15a3 3 0 0 1 5.66 0",key:"n6f512"}],["circle",{cx:"9",cy:"11",r:"2",key:"yxgjnd"}],["rect",{x:"2",y:"5",width:"20",height:"14",rx:"2",key:"qneu4z"}]],Ft=Q("id-card",Yt);/**
32
32
  * @license lucide-react v0.507.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const Ft=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m8 11 4 4 4-4",key:"1dohi6"}],["path",{d:"M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4",key:"1ywtjm"}]],Zt=H("import",Ft);/**
37
- * @license lucide-react v0.507.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const Jt=[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]],Xt=H("upload",Jt),ea=({agentId:t,agentName:s,onAgentDeleted:a,buttonSx:i={},isAgentsPage:n=!1,onViewAgentSettings:o,onChatWithAgent:l,onExportAgent:x,onClearConversation:m,onUploadAgentToHub:j})=>{const[h,y]=r.useState(!1),[c,d]=r.useState(!1),[u,f]=r.useState(!1),k=r.useRef(!1),S=it(),{clearAgentFromAllPages:_}=Le(),L=async()=>{try{await S.mutateAsync(t),_(t),a?.(t)}catch(w){console.error("Failed to delete agent:",w)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(_e,{open:h,onOpenChange:y,modal:!1,children:[e.jsx(Ie,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"agent options","data-tour-tag":"agent-options-button",onClick:w=>{w.stopPropagation(),w.detail===0&&y(D=>!D)},style:i,children:e.jsx(Bt,{"aria-hidden":"true"})})}),e.jsxs(Se,{align:"end",className:"min-w-45",onClick:w=>w.stopPropagation(),onInteractOutside:w=>{const D=w.detail.originalEvent.target;D instanceof Element&&D.closest(".shepherd-element")&&w.preventDefault()},onCloseAutoFocus:w=>{k.current&&(k.current=!1,w.preventDefault())},children:[n&&l&&e.jsxs(B,{onSelect:l,children:[e.jsx(Ue,{"aria-hidden":"true"}),e.jsx("span",{children:"Chat with agent"})]}),!n&&o&&e.jsxs(B,{"data-tour-tag":"view-agent-settings-menu-item",onSelect:o,children:[e.jsx(he,{"aria-hidden":"true"}),e.jsx("span",{children:"View agent settings"})]}),x&&e.jsxs(B,{onSelect:x,children:[e.jsx(Vt,{"aria-hidden":"true"}),e.jsx("span",{children:"Export agent"})]}),j&&e.jsxs(B,{"data-tour-tag":"upload-to-hub-menu-item",onSelect:j,children:[e.jsx(pe,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]}),m&&e.jsxs(B,{className:"text-warning data-[highlighted]:bg-warning-wash",onSelect:()=>{k.current=!0,f(!0)},children:[e.jsx(ot,{"aria-hidden":"true"}),e.jsx("span",{children:"Clear conversation"})]}),e.jsxs(B,{destructive:!0,onSelect:()=>{k.current=!0,d(!0)},children:[e.jsx(rt,{"aria-hidden":"true"}),e.jsx("span",{children:"Delete agent"})]})]})]}),e.jsx(je,{open:c,title:"Delete agent",message:e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-body text-ink",children:['Are you sure you want to delete the agent "',s,'"?']}),e.jsx("p",{className:"mt-2 text-body-sm text-ink-muted",children:"This action cannot be undone. All conversations with this agent will be permanently deleted."})]}),confirmText:"Delete",cancelText:"Cancel",isDangerous:!0,onConfirm:L,onCancel:()=>d(!1)}),e.jsx(je,{open:u,title:"Clear this conversation?",message:"Every message in it is deleted from this computer, and there is no undo. The agent itself is not affected.",confirmText:"Clear",cancelText:"Cancel",isDangerous:!0,onConfirm:()=>{m?.(),f(!1)},onCancel:()=>f(!1)})]})},We=t=>["agent-system-prompt",t],Ve=t=>{const{shouldEnableQuery:s}=lt();return Re({enabled:s({bypassInternetCheck:!0})&&!!t,queryKey:We(t),queryFn:async()=>{try{const i=await fe(Q.baseUrl).agents.getAgentSystemPrompt(t);if(i.status>=400)throw new Error(i.message||"Failed to fetch agent system prompt");return i.result?.system_prompt||""}catch(a){const i=a instanceof Error?a.message:"An unknown error occurred while fetching agent system prompt";throw te(i),a}},refetchOnWindowFocus:!1,staleTime:5e3})},ta=t=>{const s=Oe(),a=fe(Q.baseUrl);return qe({mutationFn:async i=>{const n=dt(i);if(n)throw te(n),new Error(n);try{const o=await a.agents.updateAgentSystemPrompt(t,i);if(o.status>=400)throw new Error(o.message||"Failed to update agent system prompt");return o}catch(o){const l=o instanceof Error?o.message:"An unknown error occurred while updating agent system prompt";throw te(l),o}},onSuccess:async()=>{await s.invalidateQueries({queryKey:We(t)}),ct("Agent system prompt updated")},onError:i=>{console.error("Error updating agent system prompt:",i)}})},aa=()=>{const[t,s]=ut(),a=mt(),i=()=>{const o=t.get("page");return o?Number.parseInt(o,10):1},n=o=>{const l=new URLSearchParams(t);o===1?l.delete("page"):l.set("page",o.toString()),s(l)};return{page:i(),setPage:n,isView:o=>a.pathname.startsWith(`/${o}`)}},sa=({open:t,onClose:s,onAgentImported:a})=>{const[i,n]=r.useState(null),[o,l]=r.useState(!1),[x,m]=r.useState(null),j=r.useRef(null),h=ht(),y=r.useCallback(g=>{g.preventDefault(),g.stopPropagation(),l(!0)},[]),c=r.useCallback(g=>{g.preventDefault(),g.stopPropagation(),l(!1)},[]),d=r.useCallback(g=>{g.preventDefault(),g.stopPropagation()},[]),u=r.useCallback(g=>g.name.toLowerCase().endsWith(".zip")?(m(null),!0):(m("Only ZIP files are supported"),!1),[]),f=r.useCallback(g=>{if(g.preventDefault(),g.stopPropagation(),l(!1),g.dataTransfer.files&&g.dataTransfer.files.length>0){const E=g.dataTransfer.files[0];u(E)&&n(E)}},[u]),k=r.useCallback(g=>{if(g.target.files&&g.target.files.length>0){const E=g.target.files[0];u(E)&&n(E)}},[u]),S=r.useCallback(()=>{j.current?.click()},[]),_=async()=>{if(i)try{const g=await h.mutateAsync(i);n(null),m(null),a&&g&&a(g.id),s()}catch(g){console.error("Failed to import agent:",g)}},L=()=>{n(null),m(null),s()},w=h.isPending,D=w||!i,p=e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:19,className:"text-accent","aria-hidden":"true"}),"Import agent"]}),C=e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:L,disabled:w,children:"Cancel"}),e.jsx(ie,{onClick:_,disabled:D,startIcon:w?e.jsx(De,{}):null,children:"Import agent"})]});return e.jsxs(Me,{open:t,onClose:L,title:p,actions:C,maxWidth:"sm",children:[e.jsx("p",{className:"mb-4 text-body-sm text-ink-muted",children:"Import an agent from a ZIP file exported from Local Operator. The file should contain an agent.yml file."}),e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx("input",{ref:j,type:"file",accept:".zip",onChange:k,disabled:w,className:"hidden"}),e.jsx("button",{type:"button",onClick:S,onDragEnter:y,onDragLeave:c,onDragOver:d,onDrop:f,disabled:w,className:R("cursor-pointer rounded-lg border-2 border-control border-dashed bg-surface p-4 text-center","transition-colors duration-base ease-out-quart","hover:bg-accent-wash","disabled:border-hairline disabled:bg-sunken disabled:text-ink-disabled",o&&"border-accent bg-accent-wash"),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:32,className:"mx-auto mb-2 text-ink-muted","aria-hidden":"true"}),e.jsx("p",{className:"text-body text-ink",children:i.name}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:"Click or drag to replace"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{size:32,className:"mx-auto mb-2 text-ink-muted","aria-hidden":"true"}),e.jsx("p",{className:"text-body text-ink",children:"Drag and drop a ZIP file here"}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:"or click to select a file"})]})}),x&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:x})]})]})},na=({title:t,searchQuery:s,onSearchChange:a,onNewAgentClick:i,searchPlaceholder:n="Search agents",newAgentTooltip:o="Create a new agent",onImportAgentClick:l,importAgentTooltip:x="Import an agent from a ZIP file"})=>e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("h2",{className:"truncate text-heading text-ink",children:t}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[l&&e.jsx(q,{content:x,children:e.jsx(T,{variant:"ghost",size:"icon",onClick:l,"aria-label":"Import agent",children:e.jsx(Zt,{"aria-hidden":"true"})})}),e.jsx(q,{content:o,children:e.jsx(T,{variant:"primary",size:"icon",onClick:i,"aria-label":"New agent","data-tour-tag":"create-new-agent-button",children:e.jsx($e,{"aria-hidden":"true"})})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(pt,{size:16,"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-ink-dim"}),e.jsx(Ee,{type:"search",inputSize:"lg",placeholder:n,value:s,onChange:m=>a(m.target.value),"aria-label":n,className:"pl-9"})]})]}),N={temperature:.2,top_p:.9,top_k:40,max_tokens:4096,frequency_penalty:0,presence_penalty:0,seed:42},A=({label:t,description:s,defaultLabel:a,onSet:i})=>e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-body-sm text-ink",children:t}),e.jsx("span",{className:"text-meta text-ink-dim",children:"Not set yet"})]}),e.jsx("p",{className:"mt-1 text-meta text-ink-dim",children:s})]}),e.jsxs(T,{variant:"secondary",size:"sm",className:"shrink-0",onClick:i,children:["Set to default (",a,")"]})]}),me=({title:t,children:s})=>e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h3",{className:"text-body-sm font-semibold text-ink-muted",children:t}),s]}),ia=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>{const[l,x]=r.useState(t);r.useEffect(()=>{x(t)},[t]);const[m,j]=r.useState(!1),h=r.useId(),y=m?Ye:Fe;return e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>j(!m),"aria-expanded":m,"aria-controls":h,className:"group flex items-center gap-2 py-1 text-left text-heading text-ink",children:[e.jsx(y,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-dim transition-colors duration-fast ease-out-quart group-hover:text-ink"}),"Advanced chat settings"]}),e.jsx(q,{content:"Advanced settings to change how the agent generates responses",children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About advanced chat settings",children:e.jsx(re,{})})})]}),m&&e.jsxs("div",{id:h,className:"mt-3",children:[e.jsx("p",{className:"max-w-2xl text-body-sm text-ink-muted",children:"Set custom values for any of these options. Anything left unset uses a default optimized from user testing."}),e.jsxs("div",{className:"mt-6 flex flex-col gap-8",children:[e.jsxs(me,{title:"Sampling",children:[l.temperature===null?e.jsx(A,{label:"Temperature",description:"Controls randomness in responses (0.0-1.0). Higher values make output more random.",defaultLabel:N.temperature,onSet:async()=>{a("temperature");try{const c={temperature:N.temperature};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,temperature:N.temperature})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.temperature??N.temperature,label:"Temperature",description:"Controls randomness in responses (0.0-1.0). Higher values make output more random.",min:0,max:1,step:.01,isSaving:s==="temperature",onChange:async c=>{a("temperature");try{const d={temperature:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.top_p===null?e.jsx(A,{label:"Top P",description:"Controls cumulative probability of tokens to sample from (0.0-1.0).",defaultLabel:N.top_p,onSet:async()=>{a("top_p");try{const c={top_p:N.top_p};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,top_p:N.top_p})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.top_p??N.top_p,label:"Top P",description:"Controls cumulative probability of tokens to sample from (0.0-1.0).",min:0,max:1,step:.01,isSaving:s==="top_p",onChange:async c=>{a("top_p");try{const d={top_p:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.top_k===null?e.jsx(A,{label:"Top K",description:"Limits tokens to sample from at each step.",defaultLabel:N.top_k,onSet:async()=>{a("top_k");try{const c={top_k:N.top_k};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,top_k:N.top_k})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.top_k??N.top_k,label:"Top K",description:"Limits tokens to sample from at each step.",min:1,max:100,step:1,isSaving:s==="top_k",onChange:async c=>{a("top_k");try{const d={top_k:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.seed===null?e.jsx(A,{label:"Seed",description:"Random number seed for deterministic generation.",defaultLabel:N.seed,onSet:async()=>{a("seed");try{const c={seed:N.seed};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,seed:N.seed})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(F,{value:l.seed?.toString()||"",label:"Seed",placeholder:"Random number seed for deterministic generation",icon:e.jsx(he,{size:16}),isSaving:s==="seed",onSave:async c=>{a("seed");try{const d=c.trim()?Number.parseInt(c,10):void 0;if(c.trim()&&Number.isNaN(d)){te("Seed must be a valid number");return}const u={seed:d};await i.mutateAsync({agentId:t.id,update:u}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(me,{title:"Repetition",children:[l.frequency_penalty===null?e.jsx(A,{label:"Frequency penalty",description:"Reduces repetition by lowering likelihood of repeated tokens (-2.0 to 2.0).",defaultLabel:N.frequency_penalty,onSet:async()=>{a("frequency_penalty");try{const c={frequency_penalty:N.frequency_penalty};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,frequency_penalty:N.frequency_penalty})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.frequency_penalty??N.frequency_penalty,label:"Frequency penalty",description:"Reduces repetition by lowering likelihood of repeated tokens (-2.0 to 2.0).",min:-2,max:2,step:.01,isSaving:s==="frequency_penalty",onChange:async c=>{a("frequency_penalty");try{const d={frequency_penalty:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.presence_penalty===null?e.jsx(A,{label:"Presence penalty",description:"Increases diversity by lowering likelihood of prompt tokens (-2.0 to 2.0).",defaultLabel:N.presence_penalty,onSet:async()=>{a("presence_penalty");try{const c={presence_penalty:N.presence_penalty};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,presence_penalty:N.presence_penalty})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.presence_penalty??N.presence_penalty,label:"Presence penalty",description:"Increases diversity by lowering likelihood of prompt tokens (-2.0 to 2.0).",min:-2,max:2,step:.01,isSaving:s==="presence_penalty",onChange:async c=>{a("presence_penalty");try{const d={presence_penalty:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(me,{title:"Length and stopping",children:[l.max_tokens===null?e.jsx(A,{label:"Max tokens",description:"Maximum tokens to generate in response.",defaultLabel:N.max_tokens,onSet:async()=>{a("max_tokens");try{const c={max_tokens:N.max_tokens};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,max_tokens:N.max_tokens})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.max_tokens??N.max_tokens,label:"Max tokens",description:"Maximum tokens to generate in response.",min:1,max:8192,step:1,isSaving:s==="max_tokens",onChange:async c=>{a("max_tokens");try{const d={max_tokens:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.stop===null?e.jsx(A,{label:"Stop sequences",description:"Sequences that will cause the model to stop generating text.",defaultLabel:"empty",onSet:async()=>{a("stop");try{const c={stop:[]};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,stop:[]})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(F,{value:l.stop?.join(`
36
+ */const Zt=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m8 11 4 4 4-4",key:"1dohi6"}],["path",{d:"M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4",key:"1ywtjm"}]],Jt=Q("import",Zt),Xt=({agentId:t,agentName:s,onAgentDeleted:a,buttonSx:i={},isAgentsPage:n=!1,onViewAgentSettings:o,onChatWithAgent:l,onExportAgent:x,onClearConversation:m,onUploadAgentToHub:j})=>{const[h,y]=r.useState(!1),[c,d]=r.useState(!1),[u,f]=r.useState(!1),k=r.useRef(!1),S=it(),{clearAgentFromAllPages:_}=Le(),L=async()=>{try{await S.mutateAsync(t),_(t),a?.(t)}catch(w){console.error("Failed to delete agent:",w)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(_e,{open:h,onOpenChange:y,modal:!1,children:[e.jsx(Ie,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"agent options","data-tour-tag":"agent-options-button",onClick:w=>{w.stopPropagation(),w.detail===0&&y(D=>!D)},style:i,children:e.jsx(Ht,{"aria-hidden":"true"})})}),e.jsxs(Se,{align:"end",className:"min-w-45",onClick:w=>w.stopPropagation(),onInteractOutside:w=>{const D=w.detail.originalEvent.target;D instanceof Element&&D.closest(".shepherd-element")&&w.preventDefault()},onCloseAutoFocus:w=>{k.current&&(k.current=!1,w.preventDefault())},children:[n&&l&&e.jsxs(B,{onSelect:l,children:[e.jsx(Ue,{"aria-hidden":"true"}),e.jsx("span",{children:"Chat with agent"})]}),!n&&o&&e.jsxs(B,{"data-tour-tag":"view-agent-settings-menu-item",onSelect:o,children:[e.jsx(he,{"aria-hidden":"true"}),e.jsx("span",{children:"View agent settings"})]}),x&&e.jsxs(B,{onSelect:x,children:[e.jsx(Kt,{"aria-hidden":"true"}),e.jsx("span",{children:"Export agent"})]}),j&&e.jsxs(B,{"data-tour-tag":"upload-to-hub-menu-item",onSelect:j,children:[e.jsx(pe,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]}),m&&e.jsxs(B,{className:"text-warning data-[highlighted]:bg-warning-wash",onSelect:()=>{k.current=!0,f(!0)},children:[e.jsx(ot,{"aria-hidden":"true"}),e.jsx("span",{children:"Clear conversation"})]}),e.jsxs(B,{destructive:!0,onSelect:()=>{k.current=!0,d(!0)},children:[e.jsx(rt,{"aria-hidden":"true"}),e.jsx("span",{children:"Delete agent"})]})]})]}),e.jsx(je,{open:c,title:"Delete agent",message:e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-body text-ink",children:['Are you sure you want to delete the agent "',s,'"?']}),e.jsx("p",{className:"mt-2 text-body-sm text-ink-muted",children:"This action cannot be undone. All conversations with this agent will be permanently deleted."})]}),confirmText:"Delete",cancelText:"Cancel",isDangerous:!0,onConfirm:L,onCancel:()=>d(!1)}),e.jsx(je,{open:u,title:"Clear this conversation?",message:"Every message in it is deleted from this computer, and there is no undo. The agent itself is not affected.",confirmText:"Clear",cancelText:"Cancel",isDangerous:!0,onConfirm:()=>{m?.(),f(!1)},onCancel:()=>f(!1)})]})},We=t=>["agent-system-prompt",t],Ve=t=>{const{shouldEnableQuery:s}=lt();return Re({enabled:s({bypassInternetCheck:!0})&&!!t,queryKey:We(t),queryFn:async()=>{try{const i=await fe(K.baseUrl).agents.getAgentSystemPrompt(t);if(i.status>=400)throw new Error(i.message||"Failed to fetch agent system prompt");return i.result?.system_prompt||""}catch(a){const i=a instanceof Error?a.message:"An unknown error occurred while fetching agent system prompt";throw te(i),a}},refetchOnWindowFocus:!1,staleTime:5e3})},ea=t=>{const s=Oe(),a=fe(K.baseUrl);return qe({mutationFn:async i=>{const n=dt(i);if(n)throw te(n),new Error(n);try{const o=await a.agents.updateAgentSystemPrompt(t,i);if(o.status>=400)throw new Error(o.message||"Failed to update agent system prompt");return o}catch(o){const l=o instanceof Error?o.message:"An unknown error occurred while updating agent system prompt";throw te(l),o}},onSuccess:async()=>{await s.invalidateQueries({queryKey:We(t)}),ct("Agent system prompt updated")},onError:i=>{console.error("Error updating agent system prompt:",i)}})},ta=()=>{const[t,s]=ut(),a=mt(),i=()=>{const o=t.get("page");return o?Number.parseInt(o,10):1},n=o=>{const l=new URLSearchParams(t);o===1?l.delete("page"):l.set("page",o.toString()),s(l)};return{page:i(),setPage:n,isView:o=>a.pathname.startsWith(`/${o}`)}},aa=({open:t,onClose:s,onAgentImported:a})=>{const[i,n]=r.useState(null),[o,l]=r.useState(!1),[x,m]=r.useState(null),j=r.useRef(null),h=ht(),y=r.useCallback(g=>{g.preventDefault(),g.stopPropagation(),l(!0)},[]),c=r.useCallback(g=>{g.preventDefault(),g.stopPropagation(),l(!1)},[]),d=r.useCallback(g=>{g.preventDefault(),g.stopPropagation()},[]),u=r.useCallback(g=>g.name.toLowerCase().endsWith(".zip")?(m(null),!0):(m("Only ZIP files are supported"),!1),[]),f=r.useCallback(g=>{if(g.preventDefault(),g.stopPropagation(),l(!1),g.dataTransfer.files&&g.dataTransfer.files.length>0){const E=g.dataTransfer.files[0];u(E)&&n(E)}},[u]),k=r.useCallback(g=>{if(g.target.files&&g.target.files.length>0){const E=g.target.files[0];u(E)&&n(E)}},[u]),S=r.useCallback(()=>{j.current?.click()},[]),_=async()=>{if(i)try{const g=await h.mutateAsync(i);n(null),m(null),a&&g&&a(g.id),s()}catch(g){console.error("Failed to import agent:",g)}},L=()=>{n(null),m(null),s()},w=h.isPending,D=w||!i,p=e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:19,className:"text-accent","aria-hidden":"true"}),"Import agent"]}),C=e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:L,disabled:w,children:"Cancel"}),e.jsx(ie,{onClick:_,disabled:D,startIcon:w?e.jsx(De,{}):null,children:"Import agent"})]});return e.jsxs(Me,{open:t,onClose:L,title:p,actions:C,maxWidth:"sm",children:[e.jsx("p",{className:"mb-4 text-body-sm text-ink-muted",children:"Import an agent from a ZIP file exported from Local Operator. The file should contain an agent.yml file."}),e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx("input",{ref:j,type:"file",accept:".zip",onChange:k,disabled:w,className:"hidden"}),e.jsx("button",{type:"button",onClick:S,onDragEnter:y,onDragLeave:c,onDragOver:d,onDrop:f,disabled:w,className:R("cursor-pointer rounded-lg border-2 border-control border-dashed bg-surface p-4 text-center","transition-colors duration-base ease-out-quart","hover:bg-accent-wash","disabled:border-hairline disabled:bg-sunken disabled:text-ink-disabled",o&&"border-accent bg-accent-wash"),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{size:32,className:"mx-auto mb-2 text-ink-muted","aria-hidden":"true"}),e.jsx("p",{className:"text-body text-ink",children:i.name}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:"Click or drag to replace"})]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{size:32,className:"mx-auto mb-2 text-ink-muted","aria-hidden":"true"}),e.jsx("p",{className:"text-body text-ink",children:"Drag and drop a ZIP file here"}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:"or click to select a file"})]})}),x&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:x})]})]})},sa=({title:t,searchQuery:s,onSearchChange:a,onNewAgentClick:i,searchPlaceholder:n="Search agents",newAgentTooltip:o="Create a new agent",onImportAgentClick:l,importAgentTooltip:x="Import an agent from a ZIP file"})=>e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("h2",{className:"truncate text-heading text-ink",children:t}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[l&&e.jsx(q,{content:x,children:e.jsx(T,{variant:"ghost",size:"icon",onClick:l,"aria-label":"Import agent",children:e.jsx(Jt,{"aria-hidden":"true"})})}),e.jsx(q,{content:o,children:e.jsx(T,{variant:"primary",size:"icon",onClick:i,"aria-label":"New agent","data-tour-tag":"create-new-agent-button",children:e.jsx($e,{"aria-hidden":"true"})})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{size:16,"aria-hidden":"true",className:"pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-ink-dim"}),e.jsx(Ee,{type:"search",inputSize:"lg",placeholder:n,value:s,onChange:m=>a(m.target.value),"aria-label":n,className:"pl-9"})]})]}),N={temperature:.2,top_p:.9,top_k:40,max_tokens:4096,frequency_penalty:0,presence_penalty:0,seed:42},A=({label:t,description:s,defaultLabel:a,onSet:i})=>e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-body-sm text-ink",children:t}),e.jsx("span",{className:"text-meta text-ink-dim",children:"Not set yet"})]}),e.jsx("p",{className:"mt-1 text-meta text-ink-dim",children:s})]}),e.jsxs(T,{variant:"secondary",size:"sm",className:"shrink-0",onClick:i,children:["Set to default (",a,")"]})]}),me=({title:t,children:s})=>e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h3",{className:"text-body-sm font-semibold text-ink-muted",children:t}),s]}),na=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>{const[l,x]=r.useState(t);r.useEffect(()=>{x(t)},[t]);const[m,j]=r.useState(!1),h=r.useId(),y=m?Ye:Fe;return e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>j(!m),"aria-expanded":m,"aria-controls":h,className:"group flex items-center gap-2 py-1 text-left text-heading text-ink",children:[e.jsx(y,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-dim transition-colors duration-fast ease-out-quart group-hover:text-ink"}),"Advanced chat settings"]}),e.jsx(q,{content:"Advanced settings to change how the agent generates responses",children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About advanced chat settings",children:e.jsx(re,{})})})]}),m&&e.jsxs("div",{id:h,className:"mt-3",children:[e.jsx("p",{className:"max-w-2xl text-body-sm text-ink-muted",children:"Set custom values for any of these options. Anything left unset uses a default optimized from user testing."}),e.jsxs("div",{className:"mt-6 flex flex-col gap-8",children:[e.jsxs(me,{title:"Sampling",children:[l.temperature===null?e.jsx(A,{label:"Temperature",description:"Controls randomness in responses (0.0-1.0). Higher values make output more random.",defaultLabel:N.temperature,onSet:async()=>{a("temperature");try{const c={temperature:N.temperature};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,temperature:N.temperature})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.temperature??N.temperature,label:"Temperature",description:"Controls randomness in responses (0.0-1.0). Higher values make output more random.",min:0,max:1,step:.01,isSaving:s==="temperature",onChange:async c=>{a("temperature");try{const d={temperature:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.top_p===null?e.jsx(A,{label:"Top P",description:"Controls cumulative probability of tokens to sample from (0.0-1.0).",defaultLabel:N.top_p,onSet:async()=>{a("top_p");try{const c={top_p:N.top_p};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,top_p:N.top_p})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.top_p??N.top_p,label:"Top P",description:"Controls cumulative probability of tokens to sample from (0.0-1.0).",min:0,max:1,step:.01,isSaving:s==="top_p",onChange:async c=>{a("top_p");try{const d={top_p:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.top_k===null?e.jsx(A,{label:"Top K",description:"Limits tokens to sample from at each step.",defaultLabel:N.top_k,onSet:async()=>{a("top_k");try{const c={top_k:N.top_k};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,top_k:N.top_k})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.top_k??N.top_k,label:"Top K",description:"Limits tokens to sample from at each step.",min:1,max:100,step:1,isSaving:s==="top_k",onChange:async c=>{a("top_k");try{const d={top_k:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.seed===null?e.jsx(A,{label:"Seed",description:"Random number seed for deterministic generation.",defaultLabel:N.seed,onSet:async()=>{a("seed");try{const c={seed:N.seed};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,seed:N.seed})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(F,{value:l.seed?.toString()||"",label:"Seed",placeholder:"Random number seed for deterministic generation",icon:e.jsx(he,{size:16}),isSaving:s==="seed",onSave:async c=>{a("seed");try{const d=c.trim()?Number.parseInt(c,10):void 0;if(c.trim()&&Number.isNaN(d)){te("Seed must be a valid number");return}const u={seed:d};await i.mutateAsync({agentId:t.id,update:u}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(me,{title:"Repetition",children:[l.frequency_penalty===null?e.jsx(A,{label:"Frequency penalty",description:"Reduces repetition by lowering likelihood of repeated tokens (-2.0 to 2.0).",defaultLabel:N.frequency_penalty,onSet:async()=>{a("frequency_penalty");try{const c={frequency_penalty:N.frequency_penalty};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,frequency_penalty:N.frequency_penalty})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.frequency_penalty??N.frequency_penalty,label:"Frequency penalty",description:"Reduces repetition by lowering likelihood of repeated tokens (-2.0 to 2.0).",min:-2,max:2,step:.01,isSaving:s==="frequency_penalty",onChange:async c=>{a("frequency_penalty");try{const d={frequency_penalty:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.presence_penalty===null?e.jsx(A,{label:"Presence penalty",description:"Increases diversity by lowering likelihood of prompt tokens (-2.0 to 2.0).",defaultLabel:N.presence_penalty,onSet:async()=>{a("presence_penalty");try{const c={presence_penalty:N.presence_penalty};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,presence_penalty:N.presence_penalty})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.presence_penalty??N.presence_penalty,label:"Presence penalty",description:"Increases diversity by lowering likelihood of prompt tokens (-2.0 to 2.0).",min:-2,max:2,step:.01,isSaving:s==="presence_penalty",onChange:async c=>{a("presence_penalty");try{const d={presence_penalty:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(me,{title:"Length and stopping",children:[l.max_tokens===null?e.jsx(A,{label:"Max tokens",description:"Maximum tokens to generate in response.",defaultLabel:N.max_tokens,onSet:async()=>{a("max_tokens");try{const c={max_tokens:N.max_tokens};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,max_tokens:N.max_tokens})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(G,{value:l.max_tokens??N.max_tokens,label:"Max tokens",description:"Maximum tokens to generate in response.",min:1,max:8192,step:1,isSaving:s==="max_tokens",onChange:async c=>{a("max_tokens");try{const d={max_tokens:c};await i.mutateAsync({agentId:t.id,update:d}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),l.stop===null?e.jsx(A,{label:"Stop sequences",description:"Sequences that will cause the model to stop generating text.",defaultLabel:"empty",onSet:async()=>{a("stop");try{const c={stop:[]};await i.mutateAsync({agentId:t.id,update:c}),x(d=>({...d,stop:[]})),t.id===o&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(F,{value:l.stop?.join(`
42
37
  `)||"",label:"Stop sequences",placeholder:"Enter stop sequences (one per line)...",icon:e.jsx(he,{size:16}),multiline:!0,rows:3,isSaving:s==="stop",onSave:async c=>{a("stop");try{const d=c.split(`
43
- `).map(f=>f.trim()).filter(f=>f.length>0),u={stop:d.length>0?d:void 0};await i.mutateAsync({agentId:t.id,update:u}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]})]})]})]})},Ke=["investment","accounting","healthcare","legal","software","security","role_play","personal_assistance","education","marketing","sales","research","analysis","management","social_media","other"],se=Object.fromEntries(Ke.map(t=>[t,t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")])),oa=({value:t,label:s,onChange:a,placeholder:i="Add category...",disabled:n=!1,icon:o})=>{const[l,x]=r.useState(""),[m,j]=r.useState(!1),[h,y]=r.useState(0),c=r.useRef(null),d=r.useRef([]),u=r.useId(),f=r.useId(),k=r.useMemo(()=>{const p=l.trim().toLowerCase();return Ke.filter(C=>!t.includes(C)&&(!p||se[C].toLowerCase().includes(p)))},[t,l]);r.useEffect(()=>{m&&d.current[h]?.scrollIntoView({block:"nearest"})},[h,m]);const S=p=>{t.includes(p)||a([...t,p]),x(""),j(!1),y(0),c.current?.focus()},_=p=>{x(p.target.value),y(0),j(!0)},L=p=>{const C=k.length;switch(p.key){case"ArrowDown":if(p.preventDefault(),C===0)break;m?y((h+1)%C):(y(0),j(!0));break;case"ArrowUp":if(p.preventDefault(),C===0)break;m?y((h-1+C)%C):(y(C-1),j(!0));break;case"Enter":m&&k[h]&&(p.preventDefault(),S(k[h]));break;case"Escape":m&&(p.preventDefault(),j(!1));break;case"Home":m&&(p.preventDefault(),y(0));break;case"End":m&&(p.preventDefault(),y(k.length-1));break}},w=p=>{a(t.filter(C=>C!==p)),y(0)},D=m&&k[h]?`${f}-option-${h}`:void 0;return e.jsxs("div",{children:[e.jsxs(oe,{htmlFor:u,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[o,s]}),e.jsxs("div",{className:R("flex min-h-11 flex-wrap items-center gap-2 rounded-sm border border-control bg-surface p-2","has-[input:focus-visible]:outline-solid has-[input:focus-visible]:outline-2","has-[input:focus-visible]:outline-accent has-[input:focus-visible]:outline-offset-2",n&&"border-hairline bg-sunken"),children:[t.map(p=>e.jsxs(Pe,{className:"gap-1 pr-1 text-ink",children:[se[p]||p,e.jsx("button",{type:"button","aria-label":`Remove category ${se[p]||p}`,disabled:n,onClick:()=>w(p),className:R("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Te,{})})]},p)),e.jsxs(Ze,{open:m,onOpenChange:j,children:[e.jsx(Je,{asChild:!0,children:e.jsx("input",{id:u,ref:c,type:"text",role:"combobox","aria-expanded":m,"aria-controls":f,"aria-autocomplete":"list","aria-activedescendant":D,autoComplete:"off",value:l,placeholder:i,disabled:n,"aria-label":s,onChange:_,onKeyDown:L,onClick:()=>{k.length>0&&j(!0)},className:R("min-w-20 flex-1 bg-transparent px-1 py-0.5 outline-none","text-body-sm text-ink placeholder:text-ink-dim","disabled:text-ink-disabled disabled:placeholder:text-ink-disabled")})}),e.jsx(Xe,{align:"start",sideOffset:4,onOpenAutoFocus:p=>p.preventDefault(),className:"max-h-60 w-(--radix-popover-trigger-width) overflow-y-auto p-1",children:e.jsx("div",{id:f,role:"listbox","aria-label":s,children:k.map((p,C)=>e.jsx("div",{id:`${f}-option-${C}`,ref:g=>{d.current[C]=g},role:"option","aria-selected":C===h,onMouseDown:g=>{g.preventDefault()},onMouseEnter:()=>y(C),onClick:()=>S(p),className:R("cursor-pointer rounded-sm px-3 py-1.5 font-medium text-body-sm",C===h?"bg-accent-wash":void 0,"text-ink"),children:se[p]||p},p))})})]})]}),t.length===0&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No categories selected"})]})},ra=({value:t,label:s,onChange:a,placeholder:i="Add tag...",disabled:n=!1,icon:o})=>{const[l,x]=r.useState(""),m=r.useRef(null),j=r.useId(),h=u=>{x(u.target.value)},y=()=>{const u=l.trim().toLowerCase();u&&!t.includes(u)&&a([...t,u]),x("")},c=u=>{u.key==="Enter"&&l.trim()?(u.preventDefault(),y()):u.key==="Backspace"&&!l&&t.length>0&&a(t.slice(0,-1))},d=u=>{a(t.filter(f=>f!==u))};return e.jsxs("div",{children:[e.jsxs(oe,{htmlFor:j,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[o,s]}),e.jsxs("div",{className:R("flex min-h-11 flex-wrap items-center gap-2 rounded-sm border border-control bg-surface p-2","has-[input:focus-visible]:outline-solid has-[input:focus-visible]:outline-2","has-[input:focus-visible]:outline-accent has-[input:focus-visible]:outline-offset-2",n&&"border-hairline bg-sunken"),children:[t.map(u=>e.jsxs(Pe,{className:"gap-1 pr-1 text-ink",children:[u,e.jsx("button",{type:"button","aria-label":`Remove tag ${u}`,disabled:n,onClick:()=>d(u),className:R("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Te,{})})]},u)),e.jsx("input",{id:j,ref:m,type:"text",value:l,onChange:h,onKeyDown:c,placeholder:i,disabled:n,"aria-label":s,className:R("min-w-20 flex-1 bg-transparent px-1 py-0.5 outline-none","text-body-sm text-ink placeholder:text-ink-dim","disabled:text-ink-disabled disabled:placeholder:text-ink-disabled")}),l.trim()&&e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"Add tag",disabled:n,onClick:()=>{y(),m.current?.focus()},className:"text-accent hover:text-accent",children:e.jsx($e,{})})]}),t.length===0&&!l&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No tags added"})]})},la=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>{const{data:l,isLoading:x}=xt(),[m,j]=r.useState("");r.useEffect(()=>{!x&&l?.values?j(t.hosting||l.values.hosting||""):x||j(t.hosting||"")},[t,l,x]);const[h,y]=r.useState(!1),[c,d]=r.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(F,{value:t.name,label:"Agent name",placeholder:"Enter agent name...",isSaving:s==="name",onSave:async u=>{if(!u.trim()){te("Agent name cannot be empty");return}a("name");try{const f={name:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{"data-tour-tag":"agent-settings-hosting-select",children:e.jsx(ft,{value:t.hosting||(l?.values.hosting??""),isSaving:s==="hosting",onSave:async u=>{a("hosting"),j(u);try{const f={hosting:u,model:""};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{j(t.hosting||"")}finally{a(null)}},filterByCredentials:!0,allowDefault:!0},`hosting-select-${t.id}-${t.hosting||(l?.values.hosting??"default")}`)}),e.jsx("div",{"data-tour-tag":"agent-settings-model-select",children:m?e.jsx(gt,{value:t.hosting?t.model||"":t.model||(l?.values.model_name??""),hostingId:m,isSaving:s==="model",allowDefault:!0,onSave:async u=>{a("model");try{const f={model:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}},`model-select-${t.id}-${m}-${t.model||(!t.hosting&&l?.values.model_name?l.values.model_name:"default")}`):e.jsxs("div",{className:"relative",children:[e.jsx(q,{content:"Select a hosting provider first, and then select the AI model that you want to use. Each model has different capabilities and costs. Recommended: Automatic",children:e.jsxs("div",{className:"mb-1.5 flex w-fit items-center gap-2 text-body-sm text-ink-muted",children:[e.jsx(bt,{size:16,"aria-hidden":"true"}),"Model"]})}),e.jsx("div",{className:"flex h-8 w-full items-center rounded-sm border border-control bg-surface px-3",children:e.jsx("span",{className:"truncate text-body-sm text-ink-disabled",children:"Select a hosting provider first..."})})]})})]}),e.jsxs("h2",{className:"mt-4 flex items-center gap-2 text-heading text-ink",children:[e.jsx(re,{size:16,className:"shrink-0 text-ink-dim"}),"Agent information"]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(F,{value:t.description||"",label:"Description",placeholder:"Enter agent description...",multiline:!0,rows:3,isSaving:s==="description",onSave:async u=>{a("description");try{const f={description:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),e.jsx(ra,{value:t.tags||[],label:"Tags",placeholder:"Add tag...",disabled:h,onChange:async u=>{if(!(Array.isArray(t.tags)&&u.length===t.tags.length&&u.every((f,k)=>f===t.tags?.[k]))){y(!0);try{const f={tags:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{y(!1)}}}}),e.jsx(oa,{value:t.categories||[],label:"Categories",placeholder:"Add category...",disabled:c,onChange:async u=>{if(!(Array.isArray(t.categories)&&u.length===t.categories.length&&u.every((f,k)=>f===t.categories?.[k]))){d(!0);try{const f={categories:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{d(!1)}}}}),e.jsxs(Ot,{children:[e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(Yt,{size:12,"aria-hidden":"true"}),"ID"]}),value:e.jsx("span",{className:"font-mono text-mono-sm",children:t.id})}),e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(zt,{size:12,"aria-hidden":"true"}),"Created"]}),value:yt(t.created_date)}),e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(Qt,{size:12,"aria-hidden":"true"}),"Version"]}),value:t.version})]})]})]})},ca=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>e.jsxs("div",{"data-tour-tag":"agent-settings-security",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[e.jsx(jt,{size:16,className:"shrink-0 text-ink-dim"}),"Security instructions",e.jsx(q,{content:`Security instructions that guide the agent's behavior and limitations. This is the "system prompt" for the security agent.`,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About security instructions",children:e.jsx(re,{})})})]}),e.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:`This prompt is directed to the AI security reviewer. It helps the reviewer decide whether to block or allow actions based on safety. Write as if talking to another agent that is watching this agent (eg. "Allow all git operations", "Don't let the agent access drive files in the restricted folder"). Update this to allow the agent to perform actions if you are getting frequent security blocks.`}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{value:t.security_prompt||"",label:"",placeholder:"Enter instructions for the security agent...",multiline:!0,rows:6,isSaving:s==="security_prompt",onSave:async l=>{a("security_prompt");try{const x={security_prompt:l};await i.mutateAsync({agentId:t.id,update:x}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})})]}),da=({selectedAgent:t,savingField:s,setSavingField:a,refetchAgent:i,initialSelectedAgentId:n})=>{const{data:o,isLoading:l}=Ve(t.id),x=ta(t.id),[m,j]=r.useState("");return r.useEffect(()=>{o!==void 0&&j(o)},[o]),e.jsxs("div",{"data-tour-tag":"agent-settings-system-prompt",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[e.jsx(qt,{size:16,className:"shrink-0 text-ink-dim"}),"Agent instructions",e.jsx(q,{content:`System instructions that define the agent's behavior and capabilities. This is the agent's "system prompt".`,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About agent instructions",children:e.jsx(re,{})})})]}),e.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:`Define the agent's role, personality, or provide context. Write as if talking to the agent (e.g., "You are an expert researcher") and/or about yourself (e.g., "My name is John").`}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{value:m,label:"",placeholder:l?"Loading system prompt...":"Enter instructions for the agent...",multiline:!0,rows:6,isSaving:s==="system_prompt",onSave:async h=>{a("system_prompt");try{await x.mutateAsync(h),t.id===n&&i&&await i()}finally{a(null)}}})})]})},ua=({selectedAgent:t,refetchAgent:s,initialSelectedAgentId:a})=>{const[i,n]=r.useState(null),o=kt();return e.jsx("div",{"data-tour-tag":"agent-settings-details-paper",className:"h-full overflow-hidden",children:t?e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-4xl flex-col gap-8 pb-8",children:[e.jsx(la,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(da,{selectedAgent:t,savingField:i,setSavingField:n,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(ca,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(ia,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a})]})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-8 text-center",children:[e.jsx(ge,{size:48,className:"text-ink-dim","aria-hidden":"true"}),e.jsx("h2",{className:"text-heading text-ink",children:"No agent selected"}),e.jsx("p",{className:"max-w-md text-body-sm text-ink-muted",children:"Select an agent from the list on the left to view its configuration and details."})]})})},ye=vt()(wt(t=>({listings:{},remember:(s,a)=>{t(i=>({listings:{...i.listings,[s]:a}}))},forget:s=>{t(a=>{if(!(s in a.listings))return a;const i={...a.listings};return delete i[s],{listings:i}})}}),{name:"published-listings-storage"})),ma=t=>ye(s=>t?s.listings[t]??null:null),ha=400,pa=2,xa=t=>[...t].length>=pa;function fa(t){if(!t)return{state:"unknown",builtinName:null};if(t.available)return{state:"available",builtinName:null};const s=t.details?.builtin_name??null;return t.code==="name_taken"?{state:"taken",builtinName:null}:t.code==="name_reserved_builtin"?{state:"reserved",builtinName:s}:{state:"unknown",builtinName:null}}const ga=(t,s)=>{const a=t.trim(),i=ze(a,ha),n=s&&i===a&&xa(i)&&Nt(i),o=Re({queryKey:["agent-name-availability",i],enabled:n,queryFn:async()=>(await xe.getAgentNameAvailability(Q.baseUrl,i)).result,retry:!1,staleTime:15e3,refetchOnWindowFocus:!1});return!n||o.isPending?{state:n?"checking":"idle",builtinName:null}:o.isError?{state:"unknown",builtinName:null}:fa(o.data)},ba=()=>{const t=Oe();return qe({mutationFn:async({agentId:s,document:a,hubAgentId:i})=>{if(!Q.baseUrl)throw new Error("Local Operator API URL is not configured.");return i?xe.republishAgentInstructionSet(Q.baseUrl,s,i,a):xe.publishAgentInstructionSet(Q.baseUrl,s,a)},onSuccess:(s,a)=>{const i=s.result;i?.agent_id&&ye.getState().remember(a.agentId,{hubAgentId:i.agent_id,name:i.name,publishedAt:new Date().toISOString()}),t.invalidateQueries({queryKey:["public-agents"]})},onError:s=>{console.error("Publishing an agent to the hub failed:",s)}})},Qe=({open:t,onClose:s,agent:a,isAuthenticated:i,onSignInSuccess:n,onPublished:o})=>{const[l,x]=r.useState(!1),[m,j]=r.useState(""),[h,y]=r.useState(null),[c,d]=r.useState(null),[u,f]=r.useState(!1),k=r.useRef(null),S=r.useRef(null),_=be(),L=ba(),w=ma(a?.id??null),D=r.useId(),p=r.useId(),{data:C}=Ve(t&&a?a.id:""),{data:g}=Ct(t);r.useEffect(()=>{t&&j(a?.name??"")},[t,a?.name]),r.useEffect(()=>{t||(x(!1),y(null),d(null),f(!1))},[t]);const E=r.useMemo(()=>(g??[]).filter(v=>v.source==="builtin").map(v=>v.name),[g]),W=_t(m,E),ae=ga(m,t&&i),M=r.useMemo(()=>{const v=It({name:m,description:a?.description??"",instructions:C??null,tools:St(a?.tags)});return W&&v.unshift({field:"name",message:ke({code:"name_reserved_builtin",message:""},{name:m,hubAgentId:null}).body}),v},[m,a?.description,a?.tags,C,W]),P=h?ke(h,{name:m,hubAgentId:w?.hubAgentId??null}):null,V=L.isPending,Z=async v=>{if(!a||V||M.length>0)return;y(null);const U=v?.asNewListing?null:w?.hubAgentId??null,b=!!U;try{const I={name:m.trim()},O=(await L.mutateAsync({agentId:a.id,document:I,hubAgentId:U})).result,K={name:O?.name??m.trim(),hubAgentId:O?.agent_id??null,republished:b};d(K),O&&o?.(O,K.republished)}catch(I){y(Et(I)?{code:I.code,message:I.message,details:I.details}:{message:Dt(I,"The agent could not be published. Try again.")})}},J=v=>{switch(v){case"focus-name":y(null),requestAnimationFrame(()=>{k.current?.focus(),k.current?.select()});break;case"update-listing":{const U=h?.details?.existing_agent_id??w?.hubAgentId;U&&(s(),_(`/agent-hub/${U}`));break}case"install-builtin":{const U=h?.details?.builtin_name??ae.builtinName;U&&(s(),_(`/agents?kind=agent&name=${encodeURIComponent(U)}`));break}case"edit-instructions":case"edit-agent":a&&(s(),_(`/agents/${a.id}`));break;case"publish-as-new":a&&ye.getState().forget(a.id),Z({asNewListing:!0});break;case"sign-in":f(!0);break;case"refresh-hub":s(),_("/agent-hub");break;case"retry":Z();break}},$=a?.name??"",le=c?c.republished?`Updated the Agent hub listing for "${$}"`:`Published "${$}" to the Agent hub`:w?`Update the Agent hub listing for "${$}"?`:`Publish "${$}" to the Agent hub?`;r.useLayoutEffect(()=>{!h&&!c||S.current?.focus()},[h,c]);const ce=c?e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),c.hubAgentId&&e.jsx(ie,{onClick:()=>{s(),_(`/agent-hub/${c.hubAgentId}`)},children:"Open the listing"})]}):P?e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),P.actions.map((v,U)=>U===0?e.jsx(ie,{onClick:()=>J(v),disabled:V,children:Ce[v]},v):e.jsx(Y,{onClick:()=>J(v),disabled:V,children:Ce[v]},v))]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Cancel"}),M.some(v=>v.field!=="name")&&e.jsx(Y,{onClick:()=>{a&&(s(),_(`/agents/${a.id}`))},children:"Edit the agent"}),i&&e.jsx(ie,{"data-testid":"publish-submit",onClick:()=>void Z(),disabled:!l||M.length>0||!m.trim()||V,children:V?"Publishing…":w?"Update listing":"Publish"})]});return e.jsx(Me,{open:t,onClose:s,title:le,maxWidth:"sm",fullWidth:!0,actions:ce,dataTourTag:"upload-agent-dialog",dialogProps:{className:"outline-none"},children:e.jsxs("div",{ref:S,tabIndex:h||c?-1:void 0,className:R("flex flex-col gap-4",(h||c)&&"outline-none"),children:[i?c?e.jsxs(ne,{variant:"success","aria-live":"polite",children:[e.jsx(de,{children:c.republished?"Listing updated":"Published to the hub"}),e.jsx(ee,{children:c.republished?`The hub now holds the current instruction set of "${c.name}".`:`"${c.name}" is on the hub as an instruction set. Anyone can read and install it.`}),e.jsx(ee,{className:"text-ink-muted",children:"Nothing else left this machine: no conversation, no execution history, no memory, no plan and no machine-specific configuration."})]}):P&&h?e.jsxs(ne,{variant:P.variant,role:"alert",children:[e.jsx(de,{children:P.headline}),e.jsx(ee,{children:P.body}),P.note&&e.jsx(ee,{className:"text-ink-muted",children:P.note})]}):null:e.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[e.jsx("p",{className:"text-body text-ink",children:"You need to be signed in to Radient to publish agents to the Agent hub."}),e.jsx(we,{titleText:"Sign in to continue",descriptionText:"",onSignInSuccess:n})]}),P&&u&&e.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[e.jsx("p",{className:"text-body text-ink",children:"Sign in to Radient again to replace the credential the hub refused."}),e.jsx(we,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:()=>{f(!1),y(null),n?.()}})]}),!c&&!P&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body text-ink",children:"You are about to publish this agent's instruction set to the public Agent hub. What is published is what describes the agent:"}),e.jsxs("ul",{className:"list-disc space-y-1 pl-5 text-body text-ink-muted",children:[e.jsx("li",{children:"Its name and description"}),e.jsx("li",{children:"Its instructions"}),e.jsx("li",{children:"Its tool surface, effort and delegation, when it has them"})]}),e.jsx("p",{className:"text-body text-ink",children:"Nothing else leaves this machine: no conversation, no execution history, no memory or learnings, no plan, and no machine-specific configuration. Anyone can read and install what you publish."}),M.length>0&&e.jsxs(ne,{variant:"danger",children:[e.jsx(de,{children:"This agent cannot be published yet"}),e.jsx("ul",{className:"list-disc space-y-1 pl-5",children:M.map(v=>e.jsx("li",{children:v.message},`${v.field}:${v.message}`))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(oe,{htmlFor:p,children:"Name on the hub"}),e.jsx(Ee,{id:p,ref:k,value:m,onChange:v=>j(v.target.value),autoComplete:"off",spellCheck:!1,"aria-invalid":M.some(v=>v.field==="name"),"aria-describedby":`${p}-hint`}),e.jsx("p",{id:`${p}-hint`,className:"text-meta text-ink-muted",children:'No "/", "\\" or ":". Up to 128 characters.'}),ya(ae)]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex h-5 shrink-0 items-center",children:e.jsx(et,{id:D,name:"termsAgreement","data-testid":"publish-consent",checked:l,onCheckedChange:v=>x(v===!0)})}),e.jsxs(oe,{htmlFor:D,className:"block font-normal text-body text-ink",children:["I confirm that I have read and agree to the"," ",e.jsx("a",{href:"https://radienthq.com/terms",target:"_blank",rel:"noopener noreferrer",className:"text-accent underline-offset-4 hover:text-accent-hover hover:underline",children:"terms and conditions"})," ","and that this agent does not contain malicious content or violate usage policies."]})]})]}),(c||P)&&$&&e.jsxs("p",{className:"text-meta text-ink-muted",children:["Agent: ",$]})]})})},ya=t=>{switch(t.state){case"checking":return e.jsx("p",{className:"text-meta text-ink-muted",children:"Checking whether this name is free…"});case"available":return e.jsx("p",{className:"text-meta text-ink-muted",children:"This name looks free."});case"taken":return e.jsx("p",{className:"text-meta text-ink",children:"This name is already published on the hub."});case"reserved":return e.jsx("p",{className:"text-meta text-ink-muted",children:t.builtinName?`The hub reserves "${t.builtinName}" for one of its built-in agents.`:"The hub reserves this name for one of its built-in agents."});default:return null}},Ce={"focus-name":"Choose another name","update-listing":"Update the existing listing","install-builtin":"Install the built-in instead",retry:"Try again","edit-instructions":"Edit the instructions","edit-agent":"Edit the agent","publish-as-new":"Publish as a new listing","sign-in":"Sign in again","refresh-hub":"Refresh the hub"},ja=1200,ka=({agent:t,isSelected:s,onSelectAgent:a,onChatWithAgent:i,onExportAgent:n,onAgentDeleted:o,onUploadAgentToHub:l})=>{const x=t.description||"No description";return e.jsxs("li",{className:"group relative",children:[e.jsxs("button",{type:"button",onClick:()=>a(t),"aria-current":s?"true":void 0,"data-tour-tag":"agent-list-item-button",className:R("flex w-full items-center gap-2 rounded-sm py-1.5 pr-9 pl-2 text-left","transition-colors duration-fast ease-out-quart",s?Lt:"hover:bg-row-hover"),children:[e.jsx(at,{className:"size-8 shrink-0",children:e.jsx(st,{className:"border border-control bg-sunken",children:e.jsx(ge,{size:16,"aria-hidden":!0})})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx(q,{content:t.name,side:"top",align:"start",children:e.jsx("span",{className:"block truncate font-medium text-body-sm text-ink",children:t.name})}),e.jsx(q,{content:x,side:"bottom",align:"start",children:e.jsx("span",{className:"block truncate text-meta text-ink-dim",children:x})})]})]}),e.jsx("div",{className:R("pointer-events-none absolute top-0 right-1 flex h-full items-center","opacity-0 transition-opacity duration-fast ease-out-quart","group-hover:pointer-events-auto group-hover:opacity-100","group-focus-within:pointer-events-auto group-focus-within:opacity-100"),children:e.jsx(q,{content:"Agent options",children:e.jsx("span",{children:e.jsx(ea,{agentId:t.id,agentName:t.name,isAgentsPage:!0,onAgentDeleted:()=>o(t.id),onChatWithAgent:()=>i(t.id),onExportAgent:()=>n(t.id),onUploadAgentToHub:()=>l(t),buttonSx:{width:24,height:24,borderRadius:"6px",display:"flex",justifyContent:"center",alignItems:"center"}})})})})]})},va=(t,s)=>t.isSelected===s.isSelected&&t.agent.id===s.agent.id&&t.agent.name===s.agent.name&&t.agent.description===s.agent.description&&t.onSelectAgent===s.onSelectAgent&&t.onChatWithAgent===s.onChatWithAgent&&t.onExportAgent===s.onExportAgent&&t.onAgentDeleted===s.onAgentDeleted&&t.onUploadAgentToHub===s.onUploadAgentToHub,wa=r.memo(ka,va),Na=({selectedAgentId:t,onSelectAgent:s})=>{const a=be(),[i,n]=r.useState(""),o=Pt(b=>b.openCreateAgentDialog),l=ze(i.trim(),250),[x,m]=r.useState(!1),j=50,[h,y]=r.useState(!1),[c,d]=r.useState(null),{isAuthenticated:u}=Ae(),f=r.useMemo(()=>fe(Q.baseUrl),[]),k=Be(),{page:S,setPage:_}=aa(),{data:L,isLoading:w,isError:D,refetch:p}=Tt(S,j,0,l||void 0,"created_date","desc"),C=L?.agents||[],g=L?.total||0,{data:E}=He(t&&!C.find(b=>b.id===t)?t:void 0),W=r.useMemo(()=>{const b=[...C];return E&&!b.find(I=>I.id===E.id)&&b.push(E),b.sort((I,z)=>new Date(z.created_date).getTime()-new Date(I.created_date).getTime()),b},[C,E]),ae=r.useCallback(b=>{_(b)},[_]),M=r.useCallback(b=>{s(b)},[s]),P=r.useCallback(()=>{m(!0)},[]),V=r.useCallback(()=>{m(!1)},[]),Z=r.useCallback(async b=>{try{const I=await k.mutateAsync(b),z=W.find(Ge=>Ge.id===b),O=z?z.name.replace(/\s+/g,"-").toLowerCase():b,K=URL.createObjectURL(I),X=document.createElement("a");X.href=K,X.download=`${O}-export.zip`,document.body.appendChild(X),X.click(),URL.revokeObjectURL(K),document.body.removeChild(X)}catch(I){console.error("Failed to export agent:",I)}},[W,k]),J=r.useCallback(b=>{d(b),y(!0)},[]),$=r.useCallback(()=>{y(!1),d(null)},[]),le=r.useCallback(async b=>{try{const z=((await p()).data?.agents||[]).find(K=>K.id===b);if(z){s(z);return}const O=await f.agents.getAgent(b);O.status<400&&O.result&&s(O.result)}catch(I){console.error("Error selecting newly created agent:",I)}},[s,p,f]),ce=r.useCallback(b=>{a(`/chat/${b}`)},[a]),v=r.useCallback(b=>{p(),a("/agents")},[t,p,a]),U=r.useCallback(b=>{J(b)},[J]);return e.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden border-hairline border-r bg-surface",children:[e.jsx(na,{title:"Agents",searchQuery:i,onSearchChange:b=>n(b),onNewAgentClick:o,onImportAgentClick:P,importAgentTooltip:"Import an agent from a ZIP file"}),w?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(De,{size:"lg",label:"Loading agents"})}):D?e.jsxs(ne,{variant:"danger",role:"alert",className:"m-4 w-auto",children:[e.jsx(ee,{children:"Failed to load agents. Please try again."}),e.jsx(T,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>p(),children:"Retry"})]}):W.length===0&&!w?e.jsx("p",{className:"p-6 text-center text-body-sm text-ink-muted",children:i?"No agents match your search":"No agents found"}):e.jsx(tt,{delayDuration:ja,skipDelayDuration:0,children:e.jsx("ul",{className:"flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-2",children:W.map(b=>e.jsx(wa,{agent:b,isSelected:t===b.id||E?.id===b.id,onSelectAgent:M,onChatWithAgent:ce,onExportAgent:Z,onAgentDeleted:v,onUploadAgentToHub:U},b.id))})}),e.jsx(sa,{open:x,onClose:V,onAgentImported:le}),g>0&&e.jsx(Mt,{page:S,count:Math.max(1,Math.ceil(g/j)),onChange:ae}),e.jsx(Qe,{open:h,onClose:$,agent:c,isAuthenticated:u})]})},Ca=r.memo(Na),Pa=()=>{const{agentId:t,navigateToAgent:s}=Ut(),a=be(),{isAuthenticated:i}=Ae(),[n,o]=r.useState(!1),l=Be(),{setLastAgentsPageAgentId:x,getLastAgentId:m}=Le(),j=t||m("agents"),{data:h,refetch:y}=He(j||void 0);r.useEffect(()=>{t&&x(t)},[t,x]);const c=async()=>{if(h)try{const k=await l.mutateAsync(h.id),S=URL.createObjectURL(k),_=document.createElement("a");_.href=S,_.download=`${h.name.replace(/\s+/g,"-").toLowerCase()}-lo-agent.zip`,document.body.appendChild(_),_.click(),URL.revokeObjectURL(S),document.body.removeChild(_)}catch(k){console.error("Failed to export agent:",k)}},d=()=>{o(!0)},u=()=>{o(!1)},f=k=>{x(k.id),s(k.id,"agents")};return e.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[e.jsx("div",{className:"h-full w-70 shrink-0",children:e.jsx(Ca,{selectedAgentId:h?.id,onSelectAgent:f})}),e.jsx("div",{className:"h-full grow overflow-hidden",children:e.jsxs("div",{className:"flex h-full flex-col gap-8 p-4 sm:p-6 lg:p-8",children:[e.jsx("div",{className:"mx-auto w-full max-w-4xl",children:e.jsx(nt,{title:"Agent management",icon:ge,subtitle:"View, configure and manage your agents",children:h&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_e,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx(T,{"data-tour-tag":"upload-to-hub-header-button",variant:"secondary",size:"icon","aria-label":"More agent actions",className:"@min-[400px]:hidden",children:e.jsx(Rt,{"aria-hidden":"true"})})}),e.jsxs(Se,{align:"end",className:"min-w-45",children:[e.jsxs(B,{disabled:l.isPending,onSelect:c,children:[e.jsx(ve,{"aria-hidden":"true"}),e.jsx("span",{children:"Export"})]}),e.jsxs(B,{onSelect:d,children:[e.jsx(pe,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]})]})]}),e.jsxs(T,{variant:"secondary",onClick:c,disabled:l.isPending,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(ve,{"aria-hidden":"true"}),"Export"]}),e.jsxs(T,{"data-tour-tag":"upload-to-hub-header-button","data-tour-action":"open-upload-dialog",variant:"secondary",onClick:d,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(pe,{"aria-hidden":"true"}),"Upload to hub"]}),e.jsx(q,{content:`Chat with ${h.name||"this agent"}`,children:e.jsxs(T,{variant:"primary",onClick:()=>a(`/chat/${h.id}`),children:[e.jsx(Ue,{"aria-hidden":"true"}),"Chat"]})})]})})}),e.jsx("div",{className:"min-h-0 grow overflow-hidden",children:e.jsx(ua,{selectedAgent:h??null,refetchAgent:y,initialSelectedAgentId:t})})]})}),h&&e.jsx(Qe,{open:n,onClose:u,agent:h,isAuthenticated:i})]})};export{Pa as LegacyAgentsPage};
38
+ `).map(f=>f.trim()).filter(f=>f.length>0),u={stop:d.length>0?d:void 0};await i.mutateAsync({agentId:t.id,update:u}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})]})]})]})]})},Ke=["investment","accounting","healthcare","legal","software","security","role_play","personal_assistance","education","marketing","sales","research","analysis","management","social_media","other"],se=Object.fromEntries(Ke.map(t=>[t,t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")])),ia=({value:t,label:s,onChange:a,placeholder:i="Add category...",disabled:n=!1,icon:o})=>{const[l,x]=r.useState(""),[m,j]=r.useState(!1),[h,y]=r.useState(0),c=r.useRef(null),d=r.useRef([]),u=r.useId(),f=r.useId(),k=r.useMemo(()=>{const p=l.trim().toLowerCase();return Ke.filter(C=>!t.includes(C)&&(!p||se[C].toLowerCase().includes(p)))},[t,l]);r.useEffect(()=>{m&&d.current[h]?.scrollIntoView({block:"nearest"})},[h,m]);const S=p=>{t.includes(p)||a([...t,p]),x(""),j(!1),y(0),c.current?.focus()},_=p=>{x(p.target.value),y(0),j(!0)},L=p=>{const C=k.length;switch(p.key){case"ArrowDown":if(p.preventDefault(),C===0)break;m?y((h+1)%C):(y(0),j(!0));break;case"ArrowUp":if(p.preventDefault(),C===0)break;m?y((h-1+C)%C):(y(C-1),j(!0));break;case"Enter":m&&k[h]&&(p.preventDefault(),S(k[h]));break;case"Escape":m&&(p.preventDefault(),j(!1));break;case"Home":m&&(p.preventDefault(),y(0));break;case"End":m&&(p.preventDefault(),y(k.length-1));break}},w=p=>{a(t.filter(C=>C!==p)),y(0)},D=m&&k[h]?`${f}-option-${h}`:void 0;return e.jsxs("div",{children:[e.jsxs(oe,{htmlFor:u,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[o,s]}),e.jsxs("div",{className:R("flex min-h-11 flex-wrap items-center gap-2 rounded-sm border border-control bg-surface p-2","has-[input:focus-visible]:outline-solid has-[input:focus-visible]:outline-2","has-[input:focus-visible]:outline-accent has-[input:focus-visible]:outline-offset-2",n&&"border-hairline bg-sunken"),children:[t.map(p=>e.jsxs(Pe,{className:"gap-1 pr-1 text-ink",children:[se[p]||p,e.jsx("button",{type:"button","aria-label":`Remove category ${se[p]||p}`,disabled:n,onClick:()=>w(p),className:R("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Te,{})})]},p)),e.jsxs(Ze,{open:m,onOpenChange:j,children:[e.jsx(Je,{asChild:!0,children:e.jsx("input",{id:u,ref:c,type:"text",role:"combobox","aria-expanded":m,"aria-controls":f,"aria-autocomplete":"list","aria-activedescendant":D,autoComplete:"off",value:l,placeholder:i,disabled:n,"aria-label":s,onChange:_,onKeyDown:L,onClick:()=>{k.length>0&&j(!0)},className:R("min-w-20 flex-1 bg-transparent px-1 py-0.5 outline-none","text-body-sm text-ink placeholder:text-ink-dim","disabled:text-ink-disabled disabled:placeholder:text-ink-disabled")})}),e.jsx(Xe,{align:"start",sideOffset:4,onOpenAutoFocus:p=>p.preventDefault(),className:"max-h-60 w-(--radix-popover-trigger-width) overflow-y-auto p-1",children:e.jsx("div",{id:f,role:"listbox","aria-label":s,children:k.map((p,C)=>e.jsx("div",{id:`${f}-option-${C}`,ref:g=>{d.current[C]=g},role:"option","aria-selected":C===h,onMouseDown:g=>{g.preventDefault()},onMouseEnter:()=>y(C),onClick:()=>S(p),className:R("cursor-pointer rounded-sm px-3 py-1.5 font-medium text-body-sm",C===h?"bg-accent-wash":void 0,"text-ink"),children:se[p]||p},p))})})]})]}),t.length===0&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No categories selected"})]})},oa=({value:t,label:s,onChange:a,placeholder:i="Add tag...",disabled:n=!1,icon:o})=>{const[l,x]=r.useState(""),m=r.useRef(null),j=r.useId(),h=u=>{x(u.target.value)},y=()=>{const u=l.trim().toLowerCase();u&&!t.includes(u)&&a([...t,u]),x("")},c=u=>{u.key==="Enter"&&l.trim()?(u.preventDefault(),y()):u.key==="Backspace"&&!l&&t.length>0&&a(t.slice(0,-1))},d=u=>{a(t.filter(f=>f!==u))};return e.jsxs("div",{children:[e.jsxs(oe,{htmlFor:j,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[o,s]}),e.jsxs("div",{className:R("flex min-h-11 flex-wrap items-center gap-2 rounded-sm border border-control bg-surface p-2","has-[input:focus-visible]:outline-solid has-[input:focus-visible]:outline-2","has-[input:focus-visible]:outline-accent has-[input:focus-visible]:outline-offset-2",n&&"border-hairline bg-sunken"),children:[t.map(u=>e.jsxs(Pe,{className:"gap-1 pr-1 text-ink",children:[u,e.jsx("button",{type:"button","aria-label":`Remove tag ${u}`,disabled:n,onClick:()=>d(u),className:R("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Te,{})})]},u)),e.jsx("input",{id:j,ref:m,type:"text",value:l,onChange:h,onKeyDown:c,placeholder:i,disabled:n,"aria-label":s,className:R("min-w-20 flex-1 bg-transparent px-1 py-0.5 outline-none","text-body-sm text-ink placeholder:text-ink-dim","disabled:text-ink-disabled disabled:placeholder:text-ink-disabled")}),l.trim()&&e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"Add tag",disabled:n,onClick:()=>{y(),m.current?.focus()},className:"text-accent hover:text-accent",children:e.jsx($e,{})})]}),t.length===0&&!l&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No tags added"})]})},ra=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>{const{data:l,isLoading:x}=ft(),[m,j]=r.useState("");r.useEffect(()=>{!x&&l?.values?j(t.hosting||l.values.hosting||""):x||j(t.hosting||"")},[t,l,x]);const[h,y]=r.useState(!1),[c,d]=r.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(F,{value:t.name,label:"Agent name",placeholder:"Enter agent name...",isSaving:s==="name",onSave:async u=>{if(!u.trim()){te("Agent name cannot be empty");return}a("name");try{const f={name:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{"data-tour-tag":"agent-settings-hosting-select",children:e.jsx(gt,{value:t.hosting||(l?.values.hosting??""),isSaving:s==="hosting",onSave:async u=>{a("hosting"),j(u);try{const f={hosting:u,model:""};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{j(t.hosting||"")}finally{a(null)}},filterByCredentials:!0,allowDefault:!0},`hosting-select-${t.id}-${t.hosting||(l?.values.hosting??"default")}`)}),e.jsx("div",{"data-tour-tag":"agent-settings-model-select",children:m?e.jsx(bt,{value:t.hosting?t.model||"":t.model||(l?.values.model_name??""),hostingId:m,isSaving:s==="model",allowDefault:!0,onSave:async u=>{a("model");try{const f={model:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}},`model-select-${t.id}-${m}-${t.model||(!t.hosting&&l?.values.model_name?l.values.model_name:"default")}`):e.jsxs("div",{className:"relative",children:[e.jsx(q,{content:"Select a hosting provider first, and then select the AI model that you want to use. Each model has different capabilities and costs. Recommended: Automatic",children:e.jsxs("div",{className:"mb-1.5 flex w-fit items-center gap-2 text-body-sm text-ink-muted",children:[e.jsx(yt,{size:16,"aria-hidden":"true"}),"Model"]})}),e.jsx("div",{className:"flex h-8 w-full items-center rounded-sm border border-control bg-surface px-3",children:e.jsx("span",{className:"truncate text-body-sm text-ink-disabled",children:"Select a hosting provider first..."})})]})})]}),e.jsxs("h2",{className:"mt-4 flex items-center gap-2 text-heading text-ink",children:[e.jsx(re,{size:16,className:"shrink-0 text-ink-dim"}),"Agent information"]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(F,{value:t.description||"",label:"Description",placeholder:"Enter agent description...",multiline:!0,rows:3,isSaving:s==="description",onSave:async u=>{a("description");try{const f={description:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{a(null)}}}),e.jsx(oa,{value:t.tags||[],label:"Tags",placeholder:"Add tag...",disabled:h,onChange:async u=>{if(!(Array.isArray(t.tags)&&u.length===t.tags.length&&u.every((f,k)=>f===t.tags?.[k]))){y(!0);try{const f={tags:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{y(!1)}}}}),e.jsx(ia,{value:t.categories||[],label:"Categories",placeholder:"Add category...",disabled:c,onChange:async u=>{if(!(Array.isArray(t.categories)&&u.length===t.categories.length&&u.every((f,k)=>f===t.categories?.[k]))){d(!0);try{const f={categories:u};await i.mutateAsync({agentId:t.id,update:f}),t.id===o&&n&&await n()}catch{}finally{d(!1)}}}}),e.jsxs(qt,{children:[e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(Ft,{size:12,"aria-hidden":"true"}),"ID"]}),value:e.jsx("span",{className:"font-mono text-mono-sm",children:t.id})}),e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(At,{size:12,"aria-hidden":"true"}),"Created"]}),value:jt(t.created_date)}),e.jsx(ue,{label:e.jsxs(e.Fragment,{children:[e.jsx(Gt,{size:12,"aria-hidden":"true"}),"Version"]}),value:t.version})]})]})]})},la=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:o})=>e.jsxs("div",{"data-tour-tag":"agent-settings-security",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[e.jsx(kt,{size:16,className:"shrink-0 text-ink-dim"}),"Security instructions",e.jsx(q,{content:`Security instructions that guide the agent's behavior and limitations. This is the "system prompt" for the security agent.`,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About security instructions",children:e.jsx(re,{})})})]}),e.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:`This prompt is directed to the AI security reviewer. It helps the reviewer decide whether to block or allow actions based on safety. Write as if talking to another agent that is watching this agent (eg. "Allow all git operations", "Don't let the agent access drive files in the restricted folder"). Update this to allow the agent to perform actions if you are getting frequent security blocks.`}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{value:t.security_prompt||"",label:"",placeholder:"Enter instructions for the security agent...",multiline:!0,rows:6,isSaving:s==="security_prompt",onSave:async l=>{a("security_prompt");try{const x={security_prompt:l};await i.mutateAsync({agentId:t.id,update:x}),t.id===o&&n&&await n()}catch{}finally{a(null)}}})})]}),ca=({selectedAgent:t,savingField:s,setSavingField:a,refetchAgent:i,initialSelectedAgentId:n})=>{const{data:o,isLoading:l}=Ve(t.id),x=ea(t.id),[m,j]=r.useState("");return r.useEffect(()=>{o!==void 0&&j(o)},[o]),e.jsxs("div",{"data-tour-tag":"agent-settings-system-prompt",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-heading text-ink",children:[e.jsx(Mt,{size:16,className:"shrink-0 text-ink-dim"}),"Agent instructions",e.jsx(q,{content:`System instructions that define the agent's behavior and capabilities. This is the agent's "system prompt".`,children:e.jsx(T,{variant:"ghost",size:"icon-sm","aria-label":"About agent instructions",children:e.jsx(re,{})})})]}),e.jsx("p",{className:"mt-1 max-w-2xl text-body-sm text-ink-muted",children:`Define the agent's role, personality, or provide context. Write as if talking to the agent (e.g., "You are an expert researcher") and/or about yourself (e.g., "My name is John").`}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{value:m,label:"",placeholder:l?"Loading system prompt...":"Enter instructions for the agent...",multiline:!0,rows:6,isSaving:s==="system_prompt",onSave:async h=>{a("system_prompt");try{await x.mutateAsync(h),t.id===n&&i&&await i()}finally{a(null)}}})})]})},da=({selectedAgent:t,refetchAgent:s,initialSelectedAgentId:a})=>{const[i,n]=r.useState(null),o=vt();return e.jsx("div",{"data-tour-tag":"agent-settings-details-paper",className:"h-full overflow-hidden",children:t?e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-4xl flex-col gap-8 pb-8",children:[e.jsx(ra,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(ca,{selectedAgent:t,savingField:i,setSavingField:n,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(la,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(na,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:o,refetchAgent:s,initialSelectedAgentId:a})]})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-8 text-center",children:[e.jsx(ge,{size:48,className:"text-ink-dim","aria-hidden":"true"}),e.jsx("h2",{className:"text-heading text-ink",children:"No agent selected"}),e.jsx("p",{className:"max-w-md text-body-sm text-ink-muted",children:"Select an agent from the list on the left to view its configuration and details."})]})})},ye=wt()(Nt(t=>({listings:{},remember:(s,a)=>{t(i=>({listings:{...i.listings,[s]:a}}))},forget:s=>{t(a=>{if(!(s in a.listings))return a;const i={...a.listings};return delete i[s],{listings:i}})}}),{name:"published-listings-storage"})),ua=t=>ye(s=>t?s.listings[t]??null:null),ma=400,ha=2,pa=t=>[...t].length>=ha;function xa(t){if(!t)return{state:"unknown",builtinName:null};if(t.available)return{state:"available",builtinName:null};const s=t.details?.builtin_name??null;return t.code==="name_taken"?{state:"taken",builtinName:null}:t.code==="name_reserved_builtin"?{state:"reserved",builtinName:s}:{state:"unknown",builtinName:null}}const fa=(t,s)=>{const a=t.trim(),i=ze(a,ma),n=s&&i===a&&pa(i)&&Ct(i),o=Re({queryKey:["agent-name-availability",i],enabled:n,queryFn:async()=>(await xe.getAgentNameAvailability(K.baseUrl,i)).result,retry:!1,staleTime:15e3,refetchOnWindowFocus:!1});return!n||o.isPending?{state:n?"checking":"idle",builtinName:null}:o.isError?{state:"unknown",builtinName:null}:xa(o.data)},ga=()=>{const t=Oe();return qe({mutationFn:async({agentId:s,document:a,hubAgentId:i})=>{if(!K.baseUrl)throw new Error("Local Operator API URL is not configured.");return i?xe.republishAgentInstructionSet(K.baseUrl,s,i,a):xe.publishAgentInstructionSet(K.baseUrl,s,a)},onSuccess:(s,a)=>{const i=s.result;i?.agent_id&&ye.getState().remember(a.agentId,{hubAgentId:i.agent_id,name:i.name,publishedAt:new Date().toISOString()}),t.invalidateQueries({queryKey:["public-agents"]})},onError:s=>{console.error("Publishing an agent to the hub failed:",s)}})},Qe=({open:t,onClose:s,agent:a,isAuthenticated:i,onSignInSuccess:n,onPublished:o})=>{const[l,x]=r.useState(!1),[m,j]=r.useState(""),[h,y]=r.useState(null),[c,d]=r.useState(null),[u,f]=r.useState(!1),k=r.useRef(null),S=r.useRef(null),_=be(),L=ga(),w=ua(a?.id??null),D=r.useId(),p=r.useId(),{data:C}=Ve(t&&a?a.id:""),{data:g}=_t(t);r.useEffect(()=>{t&&j(a?.name??"")},[t,a?.name]),r.useEffect(()=>{t||(x(!1),y(null),d(null),f(!1))},[t]);const E=r.useMemo(()=>(g??[]).filter(v=>v.source==="builtin").map(v=>v.name),[g]),H=It(m,E),ae=fa(m,t&&i),M=r.useMemo(()=>{const v=St({name:m,description:a?.description??"",instructions:C??null,tools:Dt(a?.tags)});return H&&v.unshift({field:"name",message:ke({code:"name_reserved_builtin",message:""},{name:m,hubAgentId:null}).body}),v},[m,a?.description,a?.tags,C,H]),P=h?ke(h,{name:m,hubAgentId:w?.hubAgentId??null}):null,W=L.isPending,Z=async v=>{if(!a||W||M.length>0)return;y(null);const U=v?.asNewListing?null:w?.hubAgentId??null,b=!!U;try{const I={name:m.trim()},O=(await L.mutateAsync({agentId:a.id,document:I,hubAgentId:U})).result,V={name:O?.name??m.trim(),hubAgentId:O?.agent_id??null,republished:b};d(V),O&&o?.(O,V.republished)}catch(I){y(Pt(I)?{code:I.code,message:I.message,details:I.details}:{message:Et(I,"The agent could not be published. Try again.")})}},J=v=>{switch(v){case"focus-name":y(null),requestAnimationFrame(()=>{k.current?.focus(),k.current?.select()});break;case"update-listing":{const U=h?.details?.existing_agent_id??w?.hubAgentId;U&&(s(),_(`/agent-hub/${U}`));break}case"install-builtin":{const U=h?.details?.builtin_name??ae.builtinName;U&&(s(),_(`/agents?kind=agent&name=${encodeURIComponent(U)}`));break}case"edit-instructions":case"edit-agent":a&&(s(),_(`/agents/${a.id}`));break;case"publish-as-new":a&&ye.getState().forget(a.id),Z({asNewListing:!0});break;case"sign-in":f(!0);break;case"refresh-hub":s(),_("/agent-hub");break;case"retry":Z();break}},$=a?.name??"",le=c?c.republished?`Updated the Agent hub listing for "${$}"`:`Published "${$}" to the Agent hub`:w?`Update the Agent hub listing for "${$}"?`:`Publish "${$}" to the Agent hub?`;r.useLayoutEffect(()=>{!h&&!c||S.current?.focus()},[h,c]);const ce=c?e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),c.hubAgentId&&e.jsx(ie,{onClick:()=>{s(),_(`/agent-hub/${c.hubAgentId}`)},children:"Open the listing"})]}):P?e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),P.actions.map((v,U)=>U===0?e.jsx(ie,{onClick:()=>J(v),disabled:W,children:Ce[v]},v):e.jsx(Y,{onClick:()=>J(v),disabled:W,children:Ce[v]},v))]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Cancel"}),M.some(v=>v.field!=="name")&&e.jsx(Y,{onClick:()=>{a&&(s(),_(`/agents/${a.id}`))},children:"Edit the agent"}),i&&e.jsx(ie,{"data-testid":"publish-submit",onClick:()=>void Z(),disabled:!l||M.length>0||!m.trim()||W,children:W?"Publishing…":w?"Update listing":"Publish"})]});return e.jsx(Me,{open:t,onClose:s,title:le,maxWidth:"sm",fullWidth:!0,actions:ce,dataTourTag:"upload-agent-dialog",dialogProps:{className:"outline-none"},children:e.jsxs("div",{ref:S,tabIndex:h||c?-1:void 0,className:R("flex flex-col gap-4",(h||c)&&"outline-none"),children:[i?c?e.jsxs(ne,{variant:"success","aria-live":"polite",children:[e.jsx(de,{children:c.republished?"Listing updated":"Published to the hub"}),e.jsx(ee,{children:c.republished?`The hub now holds the current instruction set of "${c.name}".`:`"${c.name}" is on the hub as an instruction set. Anyone can read and install it.`}),e.jsx(ee,{className:"text-ink-muted",children:"Nothing else left this machine: no conversation, no execution history, no memory, no plan and no machine-specific configuration."})]}):P&&h?e.jsxs(ne,{variant:P.variant,role:"alert",children:[e.jsx(de,{children:P.headline}),e.jsx(ee,{children:P.body}),P.note&&e.jsx(ee,{className:"text-ink-muted",children:P.note})]}):null:e.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[e.jsx("p",{className:"text-body text-ink",children:"You need to be signed in to Radient to publish agents to the Agent hub."}),e.jsx(we,{titleText:"Sign in to continue",descriptionText:"",onSignInSuccess:n})]}),P&&u&&e.jsxs("div",{className:"flex flex-col items-center gap-6 text-center",children:[e.jsx("p",{className:"text-body text-ink",children:"Sign in to Radient again to replace the credential the hub refused."}),e.jsx(we,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:()=>{f(!1),y(null),n?.()}})]}),!c&&!P&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body text-ink",children:"You are about to publish this agent's instruction set to the public Agent hub. What is published is what describes the agent:"}),e.jsxs("ul",{className:"list-disc space-y-1 pl-5 text-body text-ink-muted",children:[e.jsx("li",{children:"Its name and description"}),e.jsx("li",{children:"Its instructions"}),e.jsx("li",{children:"Its tool surface, effort and delegation, when it has them"})]}),e.jsx("p",{className:"text-body text-ink",children:"Nothing else leaves this machine: no conversation, no execution history, no memory or learnings, no plan, and no machine-specific configuration. Anyone can read and install what you publish."}),M.length>0&&e.jsxs(ne,{variant:"danger",children:[e.jsx(de,{children:"This agent cannot be published yet"}),e.jsx("ul",{className:"list-disc space-y-1 pl-5",children:M.map(v=>e.jsx("li",{children:v.message},`${v.field}:${v.message}`))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(oe,{htmlFor:p,children:"Name on the hub"}),e.jsx(Ee,{id:p,ref:k,value:m,onChange:v=>j(v.target.value),autoComplete:"off",spellCheck:!1,"aria-invalid":M.some(v=>v.field==="name"),"aria-describedby":`${p}-hint`}),e.jsx("p",{id:`${p}-hint`,className:"text-meta text-ink-muted",children:'No "/", "\\" or ":". Up to 128 characters.'}),ba(ae)]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex h-5 shrink-0 items-center",children:e.jsx(et,{id:D,name:"termsAgreement","data-testid":"publish-consent",checked:l,onCheckedChange:v=>x(v===!0)})}),e.jsxs(oe,{htmlFor:D,className:"block font-normal text-body text-ink",children:["I confirm that I have read and agree to the"," ",e.jsx("a",{href:"https://radienthq.com/terms",target:"_blank",rel:"noopener noreferrer",className:"text-accent underline-offset-4 hover:text-accent-hover hover:underline",children:"terms and conditions"})," ","and that this agent does not contain malicious content or violate usage policies."]})]})]}),(c||P)&&$&&e.jsxs("p",{className:"text-meta text-ink-muted",children:["Agent: ",$]})]})})},ba=t=>{switch(t.state){case"checking":return e.jsx("p",{className:"text-meta text-ink-muted",children:"Checking whether this name is free…"});case"available":return e.jsx("p",{className:"text-meta text-ink-muted",children:"This name looks free."});case"taken":return e.jsx("p",{className:"text-meta text-ink",children:"This name is already published on the hub."});case"reserved":return e.jsx("p",{className:"text-meta text-ink-muted",children:t.builtinName?`The hub reserves "${t.builtinName}" for one of its built-in agents.`:"The hub reserves this name for one of its built-in agents."});default:return null}},Ce={"focus-name":"Choose another name","update-listing":"Update the existing listing","install-builtin":"Install the built-in instead",retry:"Try again","edit-instructions":"Edit the instructions","edit-agent":"Edit the agent","publish-as-new":"Publish as a new listing","sign-in":"Sign in again","refresh-hub":"Refresh the hub"},ya=1200,ja=({agent:t,isSelected:s,onSelectAgent:a,onChatWithAgent:i,onExportAgent:n,onAgentDeleted:o,onUploadAgentToHub:l})=>{const x=t.description||"No description";return e.jsxs("li",{className:"group relative",children:[e.jsxs("button",{type:"button",onClick:()=>a(t),"aria-current":s?"true":void 0,"data-tour-tag":"agent-list-item-button",className:R("flex w-full items-center gap-2 rounded-sm py-1.5 pr-9 pl-2 text-left","transition-colors duration-fast ease-out-quart",s?Ut:"hover:bg-row-hover"),children:[e.jsx(at,{className:"size-8 shrink-0",children:e.jsx(st,{className:"border border-control bg-sunken",children:e.jsx(ge,{size:16,"aria-hidden":!0})})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx(q,{content:t.name,side:"top",align:"start",children:e.jsx("span",{className:"block truncate font-medium text-body-sm text-ink",children:t.name})}),e.jsx(q,{content:x,side:"bottom",align:"start",children:e.jsx("span",{className:"block truncate text-meta text-ink-dim",children:x})})]})]}),e.jsx("div",{className:R("pointer-events-none absolute top-0 right-1 flex h-full items-center","opacity-0 transition-opacity duration-fast ease-out-quart","group-hover:pointer-events-auto group-hover:opacity-100","group-focus-within:pointer-events-auto group-focus-within:opacity-100"),children:e.jsx(q,{content:"Agent options",children:e.jsx("span",{children:e.jsx(Xt,{agentId:t.id,agentName:t.name,isAgentsPage:!0,onAgentDeleted:()=>o(t.id),onChatWithAgent:()=>i(t.id),onExportAgent:()=>n(t.id),onUploadAgentToHub:()=>l(t),buttonSx:{width:24,height:24,borderRadius:"6px",display:"flex",justifyContent:"center",alignItems:"center"}})})})})]})},ka=(t,s)=>t.isSelected===s.isSelected&&t.agent.id===s.agent.id&&t.agent.name===s.agent.name&&t.agent.description===s.agent.description&&t.onSelectAgent===s.onSelectAgent&&t.onChatWithAgent===s.onChatWithAgent&&t.onExportAgent===s.onExportAgent&&t.onAgentDeleted===s.onAgentDeleted&&t.onUploadAgentToHub===s.onUploadAgentToHub,va=r.memo(ja,ka),wa=({selectedAgentId:t,onSelectAgent:s})=>{const a=be(),[i,n]=r.useState(""),o=Tt(b=>b.openCreateAgentDialog),l=ze(i.trim(),250),[x,m]=r.useState(!1),j=50,[h,y]=r.useState(!1),[c,d]=r.useState(null),{isAuthenticated:u}=Ae(),f=r.useMemo(()=>fe(K.baseUrl),[]),k=Be(),{page:S,setPage:_}=ta(),{data:L,isLoading:w,isError:D,refetch:p}=Lt(S,j,0,l||void 0,"created_date","desc"),C=L?.agents||[],g=L?.total||0,{data:E}=He(t&&!C.find(b=>b.id===t)?t:void 0),H=r.useMemo(()=>{const b=[...C];return E&&!b.find(I=>I.id===E.id)&&b.push(E),b.sort((I,z)=>new Date(z.created_date).getTime()-new Date(I.created_date).getTime()),b},[C,E]),ae=r.useCallback(b=>{_(b)},[_]),M=r.useCallback(b=>{s(b)},[s]),P=r.useCallback(()=>{m(!0)},[]),W=r.useCallback(()=>{m(!1)},[]),Z=r.useCallback(async b=>{try{const I=await k.mutateAsync(b),z=H.find(Ge=>Ge.id===b),O=z?z.name.replace(/\s+/g,"-").toLowerCase():b,V=URL.createObjectURL(I),X=document.createElement("a");X.href=V,X.download=`${O}-export.zip`,document.body.appendChild(X),X.click(),URL.revokeObjectURL(V),document.body.removeChild(X)}catch(I){console.error("Failed to export agent:",I)}},[H,k]),J=r.useCallback(b=>{d(b),y(!0)},[]),$=r.useCallback(()=>{y(!1),d(null)},[]),le=r.useCallback(async b=>{try{const z=((await p()).data?.agents||[]).find(V=>V.id===b);if(z){s(z);return}const O=await f.agents.getAgent(b);O.status<400&&O.result&&s(O.result)}catch(I){console.error("Error selecting newly created agent:",I)}},[s,p,f]),ce=r.useCallback(b=>{a(`/chat/${b}`)},[a]),v=r.useCallback(b=>{p(),a("/agents")},[t,p,a]),U=r.useCallback(b=>{J(b)},[J]);return e.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden border-hairline border-r bg-surface",children:[e.jsx(sa,{title:"Agents",searchQuery:i,onSearchChange:b=>n(b),onNewAgentClick:o,onImportAgentClick:P,importAgentTooltip:"Import an agent from a ZIP file"}),w?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(De,{size:"lg",label:"Loading agents"})}):D?e.jsxs(ne,{variant:"danger",role:"alert",className:"m-4 w-auto",children:[e.jsx(ee,{children:"Failed to load agents. Please try again."}),e.jsx(T,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>p(),children:"Retry"})]}):H.length===0&&!w?e.jsx("p",{className:"p-6 text-center text-body-sm text-ink-muted",children:i?"No agents match your search":"No agents found"}):e.jsx(tt,{delayDuration:ya,skipDelayDuration:0,children:e.jsx("ul",{className:"flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-2",children:H.map(b=>e.jsx(va,{agent:b,isSelected:t===b.id||E?.id===b.id,onSelectAgent:M,onChatWithAgent:ce,onExportAgent:Z,onAgentDeleted:v,onUploadAgentToHub:U},b.id))})}),e.jsx(aa,{open:x,onClose:W,onAgentImported:le}),g>0&&e.jsx($t,{page:S,count:Math.max(1,Math.ceil(g/j)),onChange:ae}),e.jsx(Qe,{open:h,onClose:$,agent:c,isAuthenticated:u})]})},Na=r.memo(wa),Ea=()=>{const{agentId:t,navigateToAgent:s}=Rt(),a=be(),{isAuthenticated:i}=Ae(),[n,o]=r.useState(!1),l=Be(),{setLastAgentsPageAgentId:x,getLastAgentId:m}=Le(),j=t||m("agents"),{data:h,refetch:y}=He(j||void 0);r.useEffect(()=>{t&&x(t)},[t,x]);const c=async()=>{if(h)try{const k=await l.mutateAsync(h.id),S=URL.createObjectURL(k),_=document.createElement("a");_.href=S,_.download=`${h.name.replace(/\s+/g,"-").toLowerCase()}-lo-agent.zip`,document.body.appendChild(_),_.click(),URL.revokeObjectURL(S),document.body.removeChild(_)}catch(k){console.error("Failed to export agent:",k)}},d=()=>{o(!0)},u=()=>{o(!1)},f=k=>{x(k.id),s(k.id,"agents")};return e.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[e.jsx("div",{className:"h-full w-70 shrink-0",children:e.jsx(Na,{selectedAgentId:h?.id,onSelectAgent:f})}),e.jsx("div",{className:"h-full grow overflow-hidden",children:e.jsxs("div",{className:"flex h-full flex-col gap-8 p-4 sm:p-6 lg:p-8",children:[e.jsx("div",{className:"mx-auto w-full max-w-4xl",children:e.jsx(nt,{title:"Agent management",icon:ge,subtitle:"View, configure and manage your agents",children:h&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_e,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx(T,{"data-tour-tag":"upload-to-hub-header-button",variant:"secondary",size:"icon","aria-label":"More agent actions",className:"@min-[400px]:hidden",children:e.jsx(Ot,{"aria-hidden":"true"})})}),e.jsxs(Se,{align:"end",className:"min-w-45",children:[e.jsxs(B,{disabled:l.isPending,onSelect:c,children:[e.jsx(ve,{"aria-hidden":"true"}),e.jsx("span",{children:"Export"})]}),e.jsxs(B,{onSelect:d,children:[e.jsx(pe,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]})]})]}),e.jsxs(T,{variant:"secondary",onClick:c,disabled:l.isPending,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(ve,{"aria-hidden":"true"}),"Export"]}),e.jsxs(T,{"data-tour-tag":"upload-to-hub-header-button","data-tour-action":"open-upload-dialog",variant:"secondary",onClick:d,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(pe,{"aria-hidden":"true"}),"Upload to hub"]}),e.jsx(q,{content:`Chat with ${h.name||"this agent"}`,children:e.jsxs(T,{variant:"primary",onClick:()=>a(`/chat/${h.id}`),children:[e.jsx(Ue,{"aria-hidden":"true"}),"Chat"]})})]})})}),e.jsx("div",{className:"min-h-0 grow overflow-hidden",children:e.jsx(da,{selectedAgent:h??null,refetchAgent:y,initialSelectedAgentId:t})})]})}),h&&e.jsx(Qe,{open:n,onClose:u,agent:h,isAuthenticated:i})]})};export{Ea as LegacyAgentsPage};