local-operator-ui 0.31.33 → 0.31.34
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.
- package/out/main/index.js +3 -2
- package/out/renderer/assets/{_basePickBy-bcfs9TEr.js → _basePickBy-BGuZGQlL.js} +1 -1
- package/out/renderer/assets/{_baseUniq-Dq5fCrcT.js → _baseUniq-avrxGYhI.js} +1 -1
- package/out/renderer/assets/{agent-details-page-DkT2uj00.js → agent-details-page-CSjm9_q7.js} +2 -2
- package/out/renderer/assets/{agent-hub-page-CTC0pGaY.js → agent-hub-page-BXiVDudt.js} +3 -3
- package/out/renderer/assets/agents-page-CDuIQEse.js +7 -0
- package/out/renderer/assets/{arc-Bv0edomq.js → arc-CQRcxcOn.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-CLW6fUTo.js → architectureDiagram-IEHRJDOE-CkwuxGbl.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-CqBJeLCG.js → blockDiagram-JOT3LUYC-DErhLlTs.js} +1 -1
- package/out/renderer/assets/{browser-page-Bj1Mad8G.js → browser-page-BH9k2DzV.js} +1 -1
- package/out/renderer/assets/{browser-webauthn-prompt-DmLalo_4.js → browser-webauthn-prompt-D5Ca5EtW.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-D1ACsX_g.js → c4Diagram-VJAJSXHY-Bvg0BHpF.js} +1 -1
- package/out/renderer/assets/channel-238GQ5wt.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-DPO5PI8T.js → chunk-4BMEZGHF-EIhFYl3X.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-DD7FxFiD.js → chunk-A2AXSNBT-xwy-uUTS.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-DrskxkLn.js → chunk-AEK57VVT-Br1voKIL.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-DYRL1bxl.js → chunk-D6G4REZN-C4Dh_tJf.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-DaclAhR2.js → chunk-RZ5BOZE2-bSGVs_Tb.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-DRTndF9W.js → chunk-XZIHB7SX-CN1-qcAy.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-BFR--RB2.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-BFR--RB2.js +1 -0
- package/out/renderer/assets/clone-DJut1uh5.js +1 -0
- package/out/renderer/assets/{conversation-input-sync-By-Ip-cn.js → conversation-input-sync-QxTZG_kn.js} +234 -234
- package/out/renderer/assets/{dagre-OKDRZEBW-CNrz5tYW.js → dagre-OKDRZEBW-BY039iHz.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-SeK0PUOI.js → diagram-SSKATNLV-bB3dlGcF.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-Blm0tAEG.js → diagram-VNBRO52H-Cyhtu1_5.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-Dyy4J9ps.js → erDiagram-Q7BY3M3F-CNtBW35e.js} +1 -1
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-Ba-IA64-.js → flowDiagram-4HSFHLVR-DpPSE1IC.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-BzzcxceD.js → ganttDiagram-APWFNJXF-xMxTMO4B.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-DW5ZROmb.js → gitGraphDiagram-7IBYFJ6S-B7-mMQYk.js} +1 -1
- package/out/renderer/assets/{graph-BOfaXMez.js → graph-By5Jgx_F.js} +1 -1
- package/out/renderer/assets/{index-nE2B1WwG.js → index-CL3E7OEw.js} +185 -185
- package/out/renderer/assets/{index-BY1c2a-Y.js → index-DE0OwCyE.js} +1 -1
- package/out/renderer/assets/{index-B5HRkkSS.js → index-jwwX9AyN.js} +1 -1
- package/out/renderer/assets/{infoDiagram-PH2N3AL5-DrMRA4LZ.js → infoDiagram-PH2N3AL5-DX8aEhB8.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-BCfvcQ6_.js → journeyDiagram-U35MCT3I-CH_A0wDP.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-CG6GwI4I.js → kanban-definition-NDS4AKOZ-DtwsMDtl.js} +1 -1
- package/out/renderer/assets/{layout-WMs4l1A5.js → layout-HO9_Xm1P.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-DQ9yPUQ3.js → legacy-agents-page-D6fK_4tD.js} +3 -3
- package/out/renderer/assets/{mermaid.core-B90Kwpzs.js → mermaid.core-w9t0zfcx.js} +5 -5
- package/out/renderer/assets/{mesh-page-J_HqbJcs.js → mesh-page-D4paHK3u.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-BH5EtjM0.js → mindmap-definition-ALO5MXBD-B76wJgpo.js} +1 -1
- package/out/renderer/assets/mini-BUYwiX1L.js +1 -0
- package/out/renderer/assets/{org-surface-gate-TkAAmla_.js → org-surface-gate-CoX7en0B.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-Bttw0yAp.js → pieDiagram-IB7DONF6-DBCDwb5q.js} +1 -1
- package/out/renderer/assets/projects-page-agDoCBOh.js +55 -0
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-CQK9RniO.js → quadrantDiagram-7GDLP6J5-OWbzuMt_.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-jRswQEUh.js → radar-MK3ICKWK-CRLok0av.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-DgWBN2ZH.js → radient-auth-buttons-BuYF7pw2.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-Dldw_39_.js → requirementDiagram-KVF5MWMF-Ct-Jg5Jo.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-oIaN-Mv8.js → sankeyDiagram-QLVOVGJD-BJ0V1pBE.js} +1 -1
- package/out/renderer/assets/{schedules-page-CtoH7bhK.js → schedules-page-BjwANHEZ.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-BfTkfN46.js → sequenceDiagram-X6HHIX6F-CqLGptQb.js} +1 -1
- package/out/renderer/assets/{settings-page-v8T-P1CC.js → settings-page-NSosCB_S.js} +10 -10
- package/out/renderer/assets/{stateDiagram-DGXRK772-C6DQ_e6p.js → stateDiagram-DGXRK772-B-WRbN_h.js} +1 -1
- package/out/renderer/assets/{stateDiagram-v2-YXO3MK2T-eEqcUduD.js → stateDiagram-v2-YXO3MK2T-CzCtqiki.js} +1 -1
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-XOu_xAjl.js → timeline-definition-BDJGKUSR-Cdvoj120.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-DKdxl5oQ.js → use-download-agent-mutation-BEa3kVfY.js} +2 -2
- package/out/renderer/assets/{use-memberships-query-3L9bc5is.js → use-memberships-query-TpnxzBRP.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-BS18iJU9.js → xychartDiagram-VJFVF3MP-c6md61_B.js} +1 -1
- package/out/renderer/index.html +2 -2
- package/out/renderer/mini.html +2 -2
- package/package.json +2 -2
- package/out/renderer/assets/agents-page-pdlIKt_z.js +0 -7
- package/out/renderer/assets/channel-CTnV2XMm.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-Bb3viWAG.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-Bb3viWAG.js +0 -1
- package/out/renderer/assets/clone-7J1iL1UT.js +0 -1
- package/out/renderer/assets/mini-D7i0DiOx.js +0 -1
- package/out/renderer/assets/projects-page-DdL-ULZH.js +0 -55
package/out/renderer/assets/{legacy-agents-page-DQ9yPUQ3.js → legacy-agents-page-D6fK_4tD.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as o,j as e,c as z}from"./index-DvjcW_EJ.js";import{
|
|
1
|
+
import{r as o,j as e,c as z}from"./index-DvjcW_EJ.js";import{bJ as Ue,aP as lt,bK as ct,aG as ze,u as $e,a7 as Ne,a8 as Q,aN as qe,aO as dt,bL as ut,ax as oe,b6 as mt,bM as ht,aw as Me,aU as X,aV as he,bc as pt,bN as xt,aT as gt,bO as ft,bf as ke,aQ as Ce,a as bt,bh as yt,aZ as jt,b7 as kt,aA as vt,az as wt,aM as Ae,b5 as Nt,aY as Ct}from"./conversation-input-sync-QxTZG_kn.js";import{P as _t}from"./page-header-ouA0fPx9.js";import{c as te,D as Be,l as He,B as P,m as Ve,p as V,r as We,S as Ke,f as M,I as Qe,q as It,J as xe,L as ie,j as Ge,X as Ye,P as St,K as Dt,N as Pt,A as pe,g as fe,h as ne,s as Tt,t as Et,u as Lt,v as Ot,w as be,O as Rt,Q as Ut,b as zt,d as $t}from"./error-boundary-BCN3_4Dn.js";import{az as qt,aA as Fe,aB as ve,aC as we,aD as Mt,aE as Pe,au as At,aF as Bt,aG as Ht,ap as Ze,aH as J,aI as ee,aJ as Vt,aK as Wt,aL as Kt,aM as Qt,ax as Gt,aN as Yt,b as _e,aO as Je,aP as Xe,aQ as Ft,aR as et,as as Zt,aS as Jt,aT as Te}from"./index-CL3E7OEw.js";import{I as Xt,a as ye,N as ea}from"./settings-section-8d2ITQC3.js";import{c as ta,p as aa,u as sa}from"./ui-preferences-store-ClQPCzID.js";import{s as na,i as ia,b as oa,t as ra,v as la,w as ca,p as Ee,P as Le}from"./use-memberships-query-TpnxzBRP.js";import{u as da,p as ua,a as ma,b as ha}from"./org-surface-gate-CoX7en0B.js";import{R as Oe}from"./radient-auth-buttons-BuYF7pw2.js";import"./console-mirror-D3uHRfYy.js";/**
|
|
2
2
|
* @license lucide-react v0.507.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -28,6 +28,6 @@ import{r as o,j as e,c as z}from"./index-DvjcW_EJ.js";import{bI as Ue,aO as lt,b
|
|
|
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 wa=[["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"}]],Na=te("import",wa),Ca=({agentId:t,agentName:s,onAgentDeleted:a,buttonSx:i={},isAgentsPage:n=!1,onViewAgentSettings:r,onChatWithAgent:c,onExportAgent:h,onClearConversation:m,onUploadAgentToHub:k})=>{const[b,p]=o.useState(!1),[l,d]=o.useState(!1),[u,x]=o.useState(!1),w=o.useRef(!1),_=qt(),{clearAgentFromAllPages:I}=Ue(),S=async()=>{try{await _.mutateAsync(t),I(t),a?.(t)}catch(v){console.error("Failed to delete agent:",v)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(Be,{open:b,onOpenChange:p,modal:!1,children:[e.jsx(He,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"agent options","data-tour-tag":"agent-options-button",onClick:v=>{v.stopPropagation(),v.detail===0&&p(E=>!E)},style:i,children:e.jsx(xa,{"aria-hidden":"true"})})}),e.jsxs(We,{align:"end",className:"min-w-45",onClick:v=>v.stopPropagation(),onInteractOutside:v=>{const E=v.detail.originalEvent.target;E instanceof Element&&E.closest(".shepherd-element")&&v.preventDefault()},onCloseAutoFocus:v=>{w.current&&(w.current=!1,v.preventDefault())},children:[n&&c&&e.jsxs(W,{onSelect:c,children:[e.jsx(Fe,{"aria-hidden":"true"}),e.jsx("span",{children:"Chat with agent"})]}),!n&&r&&e.jsxs(W,{"data-tour-tag":"view-agent-settings-menu-item",onSelect:r,children:[e.jsx(ve,{"aria-hidden":"true"}),e.jsx("span",{children:"View agent settings"})]}),h&&e.jsxs(W,{onSelect:h,children:[e.jsx(ba,{"aria-hidden":"true"}),e.jsx("span",{children:"Export agent"})]}),k&&e.jsxs(W,{"data-tour-tag":"upload-to-hub-menu-item",onSelect:k,children:[e.jsx(we,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]}),m&&e.jsxs(W,{className:"text-warning data-[highlighted]:bg-warning-wash",onSelect:()=>{w.current=!0,x(!0)},children:[e.jsx(Mt,{"aria-hidden":"true"}),e.jsx("span",{children:"Clear conversation"})]}),e.jsxs(W,{destructive:!0,onSelect:()=>{w.current=!0,d(!0)},children:[e.jsx(lt,{"aria-hidden":"true"}),e.jsx("span",{children:"Delete agent"})]})]})]}),e.jsx(Pe,{open:l,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:S,onCancel:()=>d(!1)}),e.jsx(Pe,{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?.(),x(!1)},onCancel:()=>x(!1)})]})},_a=({page:t,count:s,onChange:a})=>{const i=()=>{t>1&&a(t-1)},n=()=>{t<s&&a(t+1)};return s<=1?null:e.jsxs("div",{className:"sticky bottom-0 left-0 right-0 z-10 flex min-h-13 items-center justify-between border-t border-hairline bg-surface px-4 py-2",children:[e.jsx(P,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t<=1,"aria-label":"Previous page",children:e.jsx(At,{})}),e.jsxs("span",{className:"select-none text-meta text-ink-dim",children:["Page ",t," of ",s]}),e.jsx(P,{variant:"ghost",size:"icon-sm",onClick:n,disabled:t>=s,"aria-label":"Next page",children:e.jsx(Ve,{})})]})},tt=t=>["agent-system-prompt",t],at=t=>{const{shouldEnableQuery:s}=ct();return ze({enabled:s({bypassInternetCheck:!0})&&!!t,queryKey:tt(t),queryFn:async()=>{try{const i=await Ne(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 oe(i),a}},refetchOnWindowFocus:!1,staleTime:5e3})},Ia=t=>{const s=$e(),a=Ne(Q.baseUrl);return qe({mutationFn:async i=>{const n=ut(i);if(n)throw oe(n),new Error(n);try{const r=await a.agents.updateAgentSystemPrompt(t,i);if(r.status>=400)throw new Error(r.message||"Failed to update agent system prompt");return r}catch(r){const c=r instanceof Error?r.message:"An unknown error occurred while updating agent system prompt";throw oe(c),r}},onSuccess:async()=>{await s.invalidateQueries({queryKey:tt(t)}),dt("Agent system prompt updated")},onError:i=>{console.error("Error updating agent system prompt:",i)}})},Sa=()=>{const[t,s]=mt(),a=ht(),i=()=>{const r=t.get("page");return r?Number.parseInt(r,10):1},n=r=>{const c=new URLSearchParams(t);r===1?c.delete("page"):c.set("page",r.toString()),s(c)};return{page:i(),setPage:n,isView:r=>a.pathname.startsWith(`/${r}`)}},Da=({open:t,onClose:s,onAgentImported:a})=>{const[i,n]=o.useState(null),[r,c]=o.useState(!1),[h,m]=o.useState(null),k=o.useRef(null),b=Bt(),p=o.useCallback(j=>{j.preventDefault(),j.stopPropagation(),c(!0)},[]),l=o.useCallback(j=>{j.preventDefault(),j.stopPropagation(),c(!1)},[]),d=o.useCallback(j=>{j.preventDefault(),j.stopPropagation()},[]),u=o.useCallback(j=>j.name.toLowerCase().endsWith(".zip")?(m(null),!0):(m("Only ZIP files are supported"),!1),[]),x=o.useCallback(j=>{if(j.preventDefault(),j.stopPropagation(),c(!1),j.dataTransfer.files&&j.dataTransfer.files.length>0){const T=j.dataTransfer.files[0];u(T)&&n(T)}},[u]),w=o.useCallback(j=>{if(j.target.files&&j.target.files.length>0){const T=j.target.files[0];u(T)&&n(T)}},[u]),_=o.useCallback(()=>{k.current?.click()},[]),I=async()=>{if(i)try{const j=await b.mutateAsync(i);n(null),m(null),a&&j&&a(j.id),s()}catch(j){console.error("Failed to import agent:",j)}},S=()=>{n(null),m(null),s()},v=b.isPending,E=v||!i,g=e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:19,className:"text-accent","aria-hidden":"true"}),"Import agent"]}),C=e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:S,disabled:v,children:"Cancel"}),e.jsx(he,{onClick:I,disabled:E,startIcon:v?e.jsx(Ke,{}):null,children:"Import agent"})]});return e.jsxs(Me,{open:t,onClose:S,title:g,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:k,type:"file",accept:".zip",onChange:w,disabled:v,className:"hidden"}),e.jsx("button",{type:"button",onClick:_,onDragEnter:p,onDragLeave:l,onDragOver:d,onDrop:x,disabled:v,className:z("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",r&&"border-accent bg-accent-wash"),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Re,{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(Ht,{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"})]})}),h&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:h})]})]})},Pa=({title:t,searchQuery:s,onSearchChange:a,onNewAgentClick:i,searchPlaceholder:n="Search agents",newAgentTooltip:r="Create a new agent",onImportAgentClick:c,importAgentTooltip:h="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:[c&&e.jsx(M,{content:h,children:e.jsx(P,{variant:"ghost",size:"icon",onClick:c,"aria-label":"Import agent",children:e.jsx(Na,{"aria-hidden":"true"})})}),e.jsx(M,{content:r,children:e.jsx(P,{variant:"primary",size:"icon",onClick:i,"aria-label":"New agent","data-tour-tag":"create-new-agent-button",children:e.jsx(Ze,{"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(Qe,{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},H=({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(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:i,children:["Set to default (",a,")"]})]}),je=({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]}),Ta=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>{const[c,h]=o.useState(t);o.useEffect(()=>{h(t)},[t]);const[m,k]=o.useState(!1),b=o.useId(),p=m?It:Ve;return e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>k(!m),"aria-expanded":m,"aria-controls":b,className:"group flex items-center gap-2 py-1 text-left text-heading text-ink",children:[e.jsx(p,{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(M,{content:"Advanced settings to change how the agent generates responses",children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About advanced chat settings",children:e.jsx(xe,{})})})]}),m&&e.jsxs("div",{id:b,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(je,{title:"Sampling",children:[c.temperature===null?e.jsx(H,{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 l={temperature:N.temperature};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,temperature:N.temperature})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("temperature");try{const d={temperature:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.top_p===null?e.jsx(H,{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 l={top_p:N.top_p};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,top_p:N.top_p})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("top_p");try{const d={top_p:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.top_k===null?e.jsx(H,{label:"Top K",description:"Limits tokens to sample from at each step.",defaultLabel:N.top_k,onSet:async()=>{a("top_k");try{const l={top_k:N.top_k};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,top_k:N.top_k})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("top_k");try{const d={top_k:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.seed===null?e.jsx(H,{label:"Seed",description:"Random number seed for deterministic generation.",defaultLabel:N.seed,onSet:async()=>{a("seed");try{const l={seed:N.seed};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,seed:N.seed})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(ee,{value:c.seed?.toString()||"",label:"Seed",placeholder:"Random number seed for deterministic generation",icon:e.jsx(ve,{size:16}),isSaving:s==="seed",onSave:async l=>{a("seed");try{const d=l.trim()?Number.parseInt(l,10):void 0;if(l.trim()&&Number.isNaN(d)){oe("Seed must be a valid number");return}const u={seed:d};await i.mutateAsync({agentId:t.id,update:u}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(je,{title:"Repetition",children:[c.frequency_penalty===null?e.jsx(H,{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 l={frequency_penalty:N.frequency_penalty};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,frequency_penalty:N.frequency_penalty})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("frequency_penalty");try{const d={frequency_penalty:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.presence_penalty===null?e.jsx(H,{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 l={presence_penalty:N.presence_penalty};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,presence_penalty:N.presence_penalty})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("presence_penalty");try{const d={presence_penalty:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(je,{title:"Length and stopping",children:[c.max_tokens===null?e.jsx(H,{label:"Max tokens",description:"Maximum tokens to generate in response.",defaultLabel:N.max_tokens,onSet:async()=>{a("max_tokens");try{const l={max_tokens:N.max_tokens};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,max_tokens:N.max_tokens})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("max_tokens");try{const d={max_tokens:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.stop===null?e.jsx(H,{label:"Stop sequences",description:"Sequences that will cause the model to stop generating text.",defaultLabel:"empty",onSet:async()=>{a("stop");try{const l={stop:[]};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,stop:[]})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(ee,{value:c.stop?.join(`
|
|
31
|
+
*/const wa=[["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"}]],Na=te("import",wa),Ca=({agentId:t,agentName:s,onAgentDeleted:a,buttonSx:i={},isAgentsPage:n=!1,onViewAgentSettings:r,onChatWithAgent:c,onExportAgent:h,onClearConversation:m,onUploadAgentToHub:k})=>{const[b,p]=o.useState(!1),[l,d]=o.useState(!1),[u,x]=o.useState(!1),w=o.useRef(!1),_=qt(),{clearAgentFromAllPages:I}=Ue(),S=async()=>{try{await _.mutateAsync(t),I(t),a?.(t)}catch(v){console.error("Failed to delete agent:",v)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(Be,{open:b,onOpenChange:p,modal:!1,children:[e.jsx(He,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"agent options","data-tour-tag":"agent-options-button",onClick:v=>{v.stopPropagation(),v.detail===0&&p(L=>!L)},style:i,children:e.jsx(xa,{"aria-hidden":"true"})})}),e.jsxs(Ve,{align:"end",className:"min-w-45",onClick:v=>v.stopPropagation(),onInteractOutside:v=>{const L=v.detail.originalEvent.target;L instanceof Element&&L.closest(".shepherd-element")&&v.preventDefault()},onCloseAutoFocus:v=>{w.current&&(w.current=!1,v.preventDefault())},children:[n&&c&&e.jsxs(V,{onSelect:c,children:[e.jsx(Fe,{"aria-hidden":"true"}),e.jsx("span",{children:"Chat with agent"})]}),!n&&r&&e.jsxs(V,{"data-tour-tag":"view-agent-settings-menu-item",onSelect:r,children:[e.jsx(ve,{"aria-hidden":"true"}),e.jsx("span",{children:"View agent settings"})]}),h&&e.jsxs(V,{onSelect:h,children:[e.jsx(ba,{"aria-hidden":"true"}),e.jsx("span",{children:"Export agent"})]}),k&&e.jsxs(V,{"data-tour-tag":"upload-to-hub-menu-item",onSelect:k,children:[e.jsx(we,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]}),m&&e.jsxs(V,{className:"text-warning data-[highlighted]:bg-warning-wash",onSelect:()=>{w.current=!0,x(!0)},children:[e.jsx(Mt,{"aria-hidden":"true"}),e.jsx("span",{children:"Clear conversation"})]}),e.jsxs(V,{destructive:!0,onSelect:()=>{w.current=!0,d(!0)},children:[e.jsx(lt,{"aria-hidden":"true"}),e.jsx("span",{children:"Delete agent"})]})]})]}),e.jsx(Pe,{open:l,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:S,onCancel:()=>d(!1)}),e.jsx(Pe,{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?.(),x(!1)},onCancel:()=>x(!1)})]})},_a=({page:t,count:s,onChange:a})=>{const i=()=>{t>1&&a(t-1)},n=()=>{t<s&&a(t+1)};return s<=1?null:e.jsxs("div",{className:"sticky bottom-0 left-0 right-0 z-10 flex min-h-13 items-center justify-between border-t border-hairline bg-surface px-4 py-2",children:[e.jsx(P,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t<=1,"aria-label":"Previous page",children:e.jsx(At,{})}),e.jsxs("span",{className:"select-none text-meta text-ink-dim",children:["Page ",t," of ",s]}),e.jsx(P,{variant:"ghost",size:"icon-sm",onClick:n,disabled:t>=s,"aria-label":"Next page",children:e.jsx(We,{})})]})},tt=t=>["agent-system-prompt",t],at=t=>{const{shouldEnableQuery:s}=ct();return ze({enabled:s({bypassInternetCheck:!0})&&!!t,queryKey:tt(t),queryFn:async()=>{try{const i=await Ne(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 oe(i),a}},refetchOnWindowFocus:!1,staleTime:5e3})},Ia=t=>{const s=$e(),a=Ne(Q.baseUrl);return qe({mutationFn:async i=>{const n=ut(i);if(n)throw oe(n),new Error(n);try{const r=await a.agents.updateAgentSystemPrompt(t,i);if(r.status>=400)throw new Error(r.message||"Failed to update agent system prompt");return r}catch(r){const c=r instanceof Error?r.message:"An unknown error occurred while updating agent system prompt";throw oe(c),r}},onSuccess:async()=>{await s.invalidateQueries({queryKey:tt(t)}),dt("Agent system prompt updated")},onError:i=>{console.error("Error updating agent system prompt:",i)}})},Sa=()=>{const[t,s]=mt(),a=ht(),i=()=>{const r=t.get("page");return r?Number.parseInt(r,10):1},n=r=>{const c=new URLSearchParams(t);r===1?c.delete("page"):c.set("page",r.toString()),s(c)};return{page:i(),setPage:n,isView:r=>a.pathname.startsWith(`/${r}`)}},Da=({open:t,onClose:s,onAgentImported:a})=>{const[i,n]=o.useState(null),[r,c]=o.useState(!1),[h,m]=o.useState(null),k=o.useRef(null),b=Bt(),p=o.useCallback(j=>{j.preventDefault(),j.stopPropagation(),c(!0)},[]),l=o.useCallback(j=>{j.preventDefault(),j.stopPropagation(),c(!1)},[]),d=o.useCallback(j=>{j.preventDefault(),j.stopPropagation()},[]),u=o.useCallback(j=>j.name.toLowerCase().endsWith(".zip")?(m(null),!0):(m("Only ZIP files are supported"),!1),[]),x=o.useCallback(j=>{if(j.preventDefault(),j.stopPropagation(),c(!1),j.dataTransfer.files&&j.dataTransfer.files.length>0){const T=j.dataTransfer.files[0];u(T)&&n(T)}},[u]),w=o.useCallback(j=>{if(j.target.files&&j.target.files.length>0){const T=j.target.files[0];u(T)&&n(T)}},[u]),_=o.useCallback(()=>{k.current?.click()},[]),I=async()=>{if(i)try{const j=await b.mutateAsync(i);n(null),m(null),a&&j&&a(j.id),s()}catch(j){console.error("Failed to import agent:",j)}},S=()=>{n(null),m(null),s()},v=b.isPending,L=v||!i,g=e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:19,className:"text-accent","aria-hidden":"true"}),"Import agent"]}),C=e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:S,disabled:v,children:"Cancel"}),e.jsx(he,{onClick:I,disabled:L,startIcon:v?e.jsx(Ke,{}):null,children:"Import agent"})]});return e.jsxs(Me,{open:t,onClose:S,title:g,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:k,type:"file",accept:".zip",onChange:w,disabled:v,className:"hidden"}),e.jsx("button",{type:"button",onClick:_,onDragEnter:p,onDragLeave:l,onDragOver:d,onDrop:x,disabled:v,className:z("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",r&&"border-accent bg-accent-wash"),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Re,{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(Ht,{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"})]})}),h&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:h})]})]})},Pa=({title:t,searchQuery:s,onSearchChange:a,onNewAgentClick:i,searchPlaceholder:n="Search agents",newAgentTooltip:r="Create a new agent",onImportAgentClick:c,importAgentTooltip:h="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:[c&&e.jsx(M,{content:h,children:e.jsx(P,{variant:"ghost",size:"icon",onClick:c,"aria-label":"Import agent",children:e.jsx(Na,{"aria-hidden":"true"})})}),e.jsx(M,{content:r,children:e.jsx(P,{variant:"primary",size:"icon",onClick:i,"aria-label":"New agent","data-tour-tag":"create-new-agent-button",children:e.jsx(Ze,{"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(Qe,{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},H=({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(P,{variant:"secondary",size:"sm",className:"shrink-0",onClick:i,children:["Set to default (",a,")"]})]}),je=({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]}),Ta=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>{const[c,h]=o.useState(t);o.useEffect(()=>{h(t)},[t]);const[m,k]=o.useState(!1),b=o.useId(),p=m?It:We;return e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>k(!m),"aria-expanded":m,"aria-controls":b,className:"group flex items-center gap-2 py-1 text-left text-heading text-ink",children:[e.jsx(p,{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(M,{content:"Advanced settings to change how the agent generates responses",children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About advanced chat settings",children:e.jsx(xe,{})})})]}),m&&e.jsxs("div",{id:b,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(je,{title:"Sampling",children:[c.temperature===null?e.jsx(H,{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 l={temperature:N.temperature};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,temperature:N.temperature})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("temperature");try{const d={temperature:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.top_p===null?e.jsx(H,{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 l={top_p:N.top_p};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,top_p:N.top_p})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("top_p");try{const d={top_p:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.top_k===null?e.jsx(H,{label:"Top K",description:"Limits tokens to sample from at each step.",defaultLabel:N.top_k,onSet:async()=>{a("top_k");try{const l={top_k:N.top_k};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,top_k:N.top_k})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("top_k");try{const d={top_k:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.seed===null?e.jsx(H,{label:"Seed",description:"Random number seed for deterministic generation.",defaultLabel:N.seed,onSet:async()=>{a("seed");try{const l={seed:N.seed};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,seed:N.seed})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(ee,{value:c.seed?.toString()||"",label:"Seed",placeholder:"Random number seed for deterministic generation",icon:e.jsx(ve,{size:16}),isSaving:s==="seed",onSave:async l=>{a("seed");try{const d=l.trim()?Number.parseInt(l,10):void 0;if(l.trim()&&Number.isNaN(d)){oe("Seed must be a valid number");return}const u={seed:d};await i.mutateAsync({agentId:t.id,update:u}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(je,{title:"Repetition",children:[c.frequency_penalty===null?e.jsx(H,{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 l={frequency_penalty:N.frequency_penalty};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,frequency_penalty:N.frequency_penalty})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("frequency_penalty");try{const d={frequency_penalty:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.presence_penalty===null?e.jsx(H,{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 l={presence_penalty:N.presence_penalty};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,presence_penalty:N.presence_penalty})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("presence_penalty");try{const d={presence_penalty:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]}),e.jsxs(je,{title:"Length and stopping",children:[c.max_tokens===null?e.jsx(H,{label:"Max tokens",description:"Maximum tokens to generate in response.",defaultLabel:N.max_tokens,onSet:async()=>{a("max_tokens");try{const l={max_tokens:N.max_tokens};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,max_tokens:N.max_tokens})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(J,{value:c.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 l=>{a("max_tokens");try{const d={max_tokens:l};await i.mutateAsync({agentId:t.id,update:d}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),c.stop===null?e.jsx(H,{label:"Stop sequences",description:"Sequences that will cause the model to stop generating text.",defaultLabel:"empty",onSet:async()=>{a("stop");try{const l={stop:[]};await i.mutateAsync({agentId:t.id,update:l}),h(d=>({...d,stop:[]})),t.id===r&&n&&await n()}catch{}finally{a(null)}}}):e.jsx(ee,{value:c.stop?.join(`
|
|
32
32
|
`)||"",label:"Stop sequences",placeholder:"Enter stop sequences (one per line)...",icon:e.jsx(ve,{size:16}),multiline:!0,rows:3,isSaving:s==="stop",onSave:async l=>{a("stop");try{const d=l.split(`
|
|
33
|
-
`).map(x=>x.trim()).filter(x=>x.length>0),u={stop:d.length>0?d:void 0};await i.mutateAsync({agentId:t.id,update:u}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]})]})]})]})},st=["investment","accounting","healthcare","legal","software","security","role_play","personal_assistance","education","marketing","sales","research","analysis","management","social_media","other"],ue=Object.fromEntries(st.map(t=>[t,t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")])),La=({value:t,label:s,onChange:a,placeholder:i="Add category...",disabled:n=!1,icon:r})=>{const[c,h]=o.useState(""),[m,k]=o.useState(!1),[b,p]=o.useState(0),l=o.useRef(null),d=o.useRef([]),u=o.useId(),x=o.useId(),w=o.useMemo(()=>{const g=c.trim().toLowerCase();return st.filter(C=>!t.includes(C)&&(!g||ue[C].toLowerCase().includes(g)))},[t,c]);o.useEffect(()=>{m&&d.current[b]?.scrollIntoView({block:"nearest"})},[b,m]);const _=g=>{t.includes(g)||a([...t,g]),h(""),k(!1),p(0),l.current?.focus()},I=g=>{h(g.target.value),p(0),k(!0)},S=g=>{const C=w.length;switch(g.key){case"ArrowDown":if(g.preventDefault(),C===0)break;m?p((b+1)%C):(p(0),k(!0));break;case"ArrowUp":if(g.preventDefault(),C===0)break;m?p((b-1+C)%C):(p(C-1),k(!0));break;case"Enter":m&&w[b]&&(g.preventDefault(),_(w[b]));break;case"Escape":m&&(g.preventDefault(),k(!1));break;case"Home":m&&(g.preventDefault(),p(0));break;case"End":m&&(g.preventDefault(),p(w.length-1));break}},v=g=>{a(t.filter(C=>C!==g)),p(0)},E=m&&w[b]?`${x}-option-${b}`:void 0;return e.jsxs("div",{children:[e.jsxs(ie,{htmlFor:u,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[r,s]}),e.jsxs("div",{className:z("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(g=>e.jsxs(Ge,{className:"gap-1 pr-1 text-ink",children:[ue[g]||g,e.jsx("button",{type:"button","aria-label":`Remove category ${ue[g]||g}`,disabled:n,onClick:()=>v(g),className:z("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Ye,{})})]},g)),e.jsxs(St,{open:m,onOpenChange:k,children:[e.jsx(Dt,{asChild:!0,children:e.jsx("input",{id:u,ref:l,type:"text",role:"combobox","aria-expanded":m,"aria-controls":x,"aria-autocomplete":"list","aria-activedescendant":E,autoComplete:"off",value:c,placeholder:i,disabled:n,"aria-label":s,onChange:I,onKeyDown:S,onClick:()=>{w.length>0&&k(!0)},className:z("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(Pt,{align:"start",sideOffset:4,onOpenAutoFocus:g=>g.preventDefault(),className:"max-h-60 w-(--radix-popover-trigger-width) overflow-y-auto p-1",children:e.jsx("div",{id:x,role:"listbox","aria-label":s,children:w.map((g,C)=>e.jsx("div",{id:`${x}-option-${C}`,ref:j=>{d.current[C]=j},role:"option","aria-selected":C===b,onMouseDown:j=>{j.preventDefault()},onMouseEnter:()=>p(C),onClick:()=>_(g),className:z("cursor-pointer rounded-sm px-3 py-1.5 font-medium text-body-sm",C===b?"bg-accent-wash":void 0,"text-ink"),children:ue[g]||g},g))})})]})]}),t.length===0&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No categories selected"})]})},Ea=({value:t,label:s,onChange:a,placeholder:i="Add tag...",disabled:n=!1,icon:r})=>{const[c,h]=o.useState(""),m=o.useRef(null),k=o.useId(),b=u=>{h(u.target.value)},p=()=>{const u=c.trim().toLowerCase();u&&!t.includes(u)&&a([...t,u]),h("")},l=u=>{u.key==="Enter"&&c.trim()?(u.preventDefault(),p()):u.key==="Backspace"&&!c&&t.length>0&&a(t.slice(0,-1))},d=u=>{a(t.filter(x=>x!==u))};return e.jsxs("div",{children:[e.jsxs(ie,{htmlFor:k,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[r,s]}),e.jsxs("div",{className:z("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(Ge,{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:z("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Ye,{})})]},u)),e.jsx("input",{id:k,ref:m,type:"text",value:c,onChange:b,onKeyDown:l,placeholder:i,disabled:n,"aria-label":s,className:z("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")}),c.trim()&&e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"Add tag",disabled:n,onClick:()=>{p(),m.current?.focus()},className:"text-accent hover:text-accent",children:e.jsx(Ze,{})})]}),t.length===0&&!c&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No tags added"})]})},Oa=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>{const{data:c,isLoading:h}=xt(),[m,k]=o.useState("");o.useEffect(()=>{!h&&c?.values?k(t.hosting||c.values.hosting||""):h||k(t.hosting||"")},[t,c,h]);const[b,p]=o.useState(!1),[l,d]=o.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ee,{value:t.name,label:"Agent name",placeholder:"Enter agent name...",isSaving:s==="name",onSave:async u=>{if(!u.trim()){oe("Agent name cannot be empty");return}a("name");try{const x={name:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&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(Wt,{value:t.hosting||(c?.values.hosting??""),isSaving:s==="hosting",onSave:async u=>{a("hosting"),k(u);try{const x={hosting:u,model:""};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{k(t.hosting||"")}finally{a(null)}},filterByCredentials:!0,allowDefault:!0},`hosting-select-${t.id}-${t.hosting||(c?.values.hosting??"default")}`)}),e.jsx("div",{"data-tour-tag":"agent-settings-model-select",children:m?e.jsx(Vt,{value:t.hosting?t.model||"":t.model||(c?.values.model_name??""),hostingId:m,isSaving:s==="model",allowDefault:!0,onSave:async u=>{a("model");try{const x={model:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{a(null)}}},`model-select-${t.id}-${m}-${t.model||(!t.hosting&&c?.values.model_name?c.values.model_name:"default")}`):e.jsxs("div",{className:"relative",children:[e.jsx(M,{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(Kt,{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(xe,{size:16,className:"shrink-0 text-ink-dim"}),"Agent information"]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ee,{value:t.description||"",label:"Description",placeholder:"Enter agent description...",multiline:!0,rows:3,isSaving:s==="description",onSave:async u=>{a("description");try{const x={description:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),e.jsx(Ea,{value:t.tags||[],label:"Tags",placeholder:"Add tag...",disabled:b,onChange:async u=>{if(!(Array.isArray(t.tags)&&u.length===t.tags.length&&u.every((x,w)=>x===t.tags?.[w]))){p(!0);try{const x={tags:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{p(!1)}}}}),e.jsx(La,{value:t.categories||[],label:"Categories",placeholder:"Add category...",disabled:l,onChange:async u=>{if(!(Array.isArray(t.categories)&&u.length===t.categories.length&&u.every((x,w)=>x===t.categories?.[w]))){d(!0);try{const x={categories:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{d(!1)}}}}),e.jsxs(Xt,{children:[e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(va,{size:12,"aria-hidden":"true"}),"ID"]}),value:e.jsx("span",{className:"font-mono text-mono-sm",children:t.id})}),e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(Qt,{size:12,"aria-hidden":"true"}),"Created"]}),value:gt(t.created_date)}),e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(ja,{size:12,"aria-hidden":"true"}),"Version"]}),value:t.version})]})]})]})},Ra=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>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(Gt,{size:16,className:"shrink-0 text-ink-dim"}),"Security instructions",e.jsx(M,{content:`Security instructions that guide the agent's behavior and limitations. This is the "system prompt" for the security agent.`,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About security instructions",children:e.jsx(xe,{})})})]}),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(ee,{value:t.security_prompt||"",label:"",placeholder:"Enter instructions for the security agent...",multiline:!0,rows:6,isSaving:s==="security_prompt",onSave:async c=>{a("security_prompt");try{const h={security_prompt:c};await i.mutateAsync({agentId:t.id,update:h}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})})]}),Ua=({selectedAgent:t,savingField:s,setSavingField:a,refetchAgent:i,initialSelectedAgentId:n})=>{const{data:r,isLoading:c}=at(t.id),h=Ia(t.id),[m,k]=o.useState("");return o.useEffect(()=>{r!==void 0&&k(r)},[r]),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(ea,{size:16,className:"shrink-0 text-ink-dim"}),"Agent instructions",e.jsx(M,{content:`System instructions that define the agent's behavior and capabilities. This is the agent's "system prompt".`,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About agent instructions",children:e.jsx(xe,{})})})]}),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(ee,{value:m,label:"",placeholder:c?"Loading system prompt...":"Enter instructions for the agent...",multiline:!0,rows:6,isSaving:s==="system_prompt",onSave:async b=>{a("system_prompt");try{await h.mutateAsync(b),t.id===n&&i&&await i()}finally{a(null)}}})})]})},za=({selectedAgent:t,refetchAgent:s,initialSelectedAgentId:a})=>{const[i,n]=o.useState(null),r=Yt();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(Oa,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ua,{selectedAgent:t,savingField:i,setSavingField:n,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ra,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ta,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,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(_e,{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."})]})})},Ie=ta()(aa(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"})),$a=t=>Ie(s=>t?s.listings[t]??null:null),qa=400,Ma=2,Aa=t=>[...t].length>=Ma;function Ba(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 Ha=(t,s)=>{const a=t.trim(),i=Je(a,qa),n=s&&i===a&&Aa(i)&&ft(i),r=ze({queryKey:["agent-name-availability",i],enabled:n,queryFn:async()=>(await ke.getAgentNameAvailability(Q.baseUrl,i)).result,retry:!1,staleTime:15e3,refetchOnWindowFocus:!1});return!n||r.isPending?{state:n?"checking":"idle",builtinName:null}:r.isError?{state:"unknown",builtinName:null}:Ba(r.data)},Wa=()=>{const t=$e();return qe({mutationFn:async({agentId:s,document:a,hubAgentId:i,target:n})=>{if(!Q.baseUrl)throw new Error("Local Operator API URL is not configured.");return i?ke.republishAgentInstructionSet(Q.baseUrl,s,i,a,n):ke.publishAgentInstructionSet(Q.baseUrl,s,a,n)},onSuccess:(s,a)=>{const i=s.result;i?.agent_id&&Ie.getState().remember(a.agentId,{hubAgentId:i.agent_id,name:i.name,publishedAt:new Date().toISOString()}),a.target?na(t,a.target.tenantId):ia(t)},onError:s=>{console.error("Publishing an agent to the hub failed:",s)}})},me="public",nt=({open:t,onClose:s,agent:a,isAuthenticated:i,onSignInSuccess:n,onPublished:r})=>{const[c,h]=o.useState(!1),[m,k]=o.useState(""),[b,p]=o.useState(null),[l,d]=o.useState(null),[u,x]=o.useState(!1),w=o.useRef(null),_=o.useRef(null),I=Ce(),S=Wa(),v=$a(a?.id??null),E=bt(),g=yt(),C=jt(E.data,"radient_org"),j=ha(C),T=i?ma(C,g??null):null,{memberships:A,isError:ge}=oa({enabled:t&&i&&j}),ae=o.useMemo(()=>da(A),[A]),V=o.useMemo(()=>ua(A),[A]),[G,re]=o.useState(me),R=G!==me,Y=ae.find(f=>f.tenant_id===G)?.tenant_name||"this organization",F=o.useId(),Z=o.useId(),{data:le}=at(t&&a?a.id:""),{data:ce}=kt(t);o.useEffect(()=>{t&&k(a?.name??"")},[t,a?.name]),o.useEffect(()=>{t||(h(!1),p(null),d(null),x(!1),re(me))},[t]);const y=o.useMemo(()=>(ce??[]).filter(f=>f.source==="builtin").map(f=>f.name),[ce]),L=ra(m,y),$=Ha(m,t&&i),O=o.useMemo(()=>{const f=la({name:m,description:a?.description??"",instructions:le??null,tools:ca(a?.tags)});return L&&f.unshift({field:"name",message:Le({code:"name_reserved_builtin",message:""},{name:m,hubAgentId:null}).body}),f},[m,a?.description,a?.tags,le,L]),D=b?Le(b,{name:m,hubAgentId:v?.hubAgentId??null}):null,U=S.isPending,se=async f=>{if(!a||U||O.length>0)return;p(null);const q=f?.asNewListing||R?null:v?.hubAgentId??null,rt=!!q;try{const K={name:m.trim()},de=(await S.mutateAsync({agentId:a.id,document:K,hubAgentId:q,target:R?{visibility:"org",tenantId:G}:void 0})).result,De={name:de?.name??m.trim(),hubAgentId:de?.agent_id??null,republished:rt,orgName:R?Y:null};d(De),de&&r?.(de,De.republished)}catch(K){p(wt(K)?{code:K.code,message:K.message,details:K.details}:{message:vt(K,"The agent could not be published. Try again.")})}},Se=f=>{switch(f){case"focus-name":p(null),requestAnimationFrame(()=>{w.current?.focus(),w.current?.select()});break;case"update-listing":{const q=b?.details?.existing_agent_id??v?.hubAgentId;q&&(s(),I(`/agent-hub/${q}`));break}case"install-builtin":{const q=b?.details?.builtin_name??$.builtinName;q&&(s(),I(`/agents?kind=agent&name=${encodeURIComponent(q)}`));break}case"edit-instructions":case"edit-agent":a&&(s(),I(`/agents/${a.id}`));break;case"publish-as-new":a&&Ie.getState().forget(a.id),se({asNewListing:!0});break;case"sign-in":x(!0);break;case"refresh-hub":s(),I("/agent-hub");break;case"retry":se();break}},B=a?.name??"",it=l?l.orgName?`Published "${B}" to ${l.orgName}`:l.republished?`Updated the Agent hub listing for "${B}"`:`Published "${B}" to the Agent hub`:R?`Publish "${B}" to ${Y}?`:v?`Update the Agent hub listing for "${B}"?`:`Publish "${B}" to the Agent hub?`;o.useLayoutEffect(()=>{!b&&!l||_.current?.focus()},[b,l]);const ot=l?e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),l.hubAgentId&&e.jsx(he,{onClick:()=>{s(),I(`/agent-hub/${l.hubAgentId}`)},children:"Open the listing"})]}):D?e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),D.actions.map((f,q)=>q===0?e.jsx(he,{onClick:()=>Se(f),disabled:U,children:Ee[f]},f):e.jsx(X,{onClick:()=>Se(f),disabled:U,children:Ee[f]},f))]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Cancel"}),O.some(f=>f.field!=="name")&&e.jsx(X,{onClick:()=>{a&&(s(),I(`/agents/${a.id}`))},children:"Edit the agent"}),i&&e.jsx(he,{"data-testid":"publish-submit",onClick:()=>void se(),disabled:!c||O.length>0||!m.trim()||U,children:U?"Publishing…":v&&!R?"Update listing":"Publish"})]});return e.jsx(Me,{open:t,onClose:s,title:it,maxWidth:"sm",fullWidth:!0,actions:ot,dataTourTag:"upload-agent-dialog",dialogProps:{className:"outline-none"},children:e.jsxs("div",{ref:_,tabIndex:b||l?-1:void 0,className:z("flex flex-col gap-4",(b||l)&&"outline-none"),children:[i?l?e.jsxs(pe,{variant:"success","aria-live":"polite",children:[e.jsx(fe,{children:l.orgName?`Published to ${l.orgName}`:l.republished?"Listing updated":"Published to the hub"}),e.jsx(ne,{children:l.orgName?`"${l.name}" is in ${l.orgName}'s shared agents as an instruction set. Its members can read and install it; nobody outside the organization can.`:l.republished?`The hub now holds the current instruction set of "${l.name}".`:`"${l.name}" is on the hub as an instruction set. Anyone can read and install it.`}),e.jsx(ne,{className:"text-ink-muted",children:"Nothing else left this machine: no conversation, no execution history, no memory, no plan and no machine-specific configuration."})]}):D&&b?e.jsxs(pe,{variant:D.variant,role:"alert",children:[e.jsx(fe,{children:D.headline}),e.jsx(ne,{children:D.body}),D.note&&e.jsx(ne,{className:"text-ink-muted",children:D.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(Oe,{titleText:"Sign in to continue",descriptionText:"",onSignInSuccess:n})]}),D&&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(Oe,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:()=>{x(!1),p(null),n?.()}})]}),!l&&!D&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body text-ink",children:R?`You are about to publish this agent's instruction set into ${Y}, where only its members can read and install it. What is published is what describes the agent:`:"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:R?`Nothing else leaves this machine: no conversation, no execution history, no memory or learnings, no plan, and no machine-specific configuration. ${Y}'s members can read and install what you publish; nobody outside it can.`:"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."}),ae.length>0||V.length>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(ie,{htmlFor:`${F}-target`,children:"Publish to"}),e.jsxs(Tt,{value:G,onValueChange:re,children:[e.jsx(Lt,{id:`${F}-target`,className:"w-full","data-testid":"publish-target",children:e.jsx(Et,{})}),e.jsxs(Ot,{children:[e.jsx(be,{value:me,children:"Public hub"}),ae.map(f=>e.jsx(be,{value:f.tenant_id,children:f.tenant_name||"Organization"},f.tenant_id)),V.map(f=>e.jsxs(be,{value:f.tenant_id,disabled:!0,children:[f.tenant_name||"Organization"," (upgrade needed)"]},f.tenant_id))]})]}),e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-hint",children:V.length>0?`Sharing agents inside an organization is part of the Team plan. An owner of ${V.length===1?V[0].tenant_name||"this organization":"any of the organizations marked above"} can activate it in the Radient console.`:"Public hub publications are readable by anyone. An organization's agents are readable by its members only."})]}):T?e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-unavailable",children:T}):ge?e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-failed",children:"Your organizations could not be read, so this publishes to the public hub. Try again in a moment to publish into an organization."}):null,O.length>0&&e.jsxs(pe,{variant:"danger",children:[e.jsx(fe,{children:"This agent cannot be published yet"}),e.jsx("ul",{className:"list-disc space-y-1 pl-5",children:O.map(f=>e.jsx("li",{children:f.message},`${f.field}:${f.message}`))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(ie,{htmlFor:Z,children:"Name on the hub"}),e.jsx(Qe,{id:Z,ref:w,value:m,onChange:f=>k(f.target.value),autoComplete:"off",spellCheck:!1,"aria-invalid":O.some(f=>f.field==="name"),"aria-describedby":`${Z}-hint`}),e.jsx("p",{id:`${Z}-hint`,className:"text-meta text-ink-muted",children:'No "/", "\\" or ":". Up to 128 characters.'}),!R&&Va($)]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex h-5 shrink-0 items-center",children:e.jsx(Rt,{id:F,name:"termsAgreement","data-testid":"publish-consent",checked:c,onCheckedChange:f=>h(f===!0)})}),e.jsxs(ie,{htmlFor:F,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."]})]})]}),(l||D)&&B&&e.jsxs("p",{className:"text-meta text-ink-muted",children:["Agent: ",B]})]})})},Va=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}},Ka=1200,Qa=({agent:t,isSelected:s,onSelectAgent:a,onChatWithAgent:i,onExportAgent:n,onAgentDeleted:r,onUploadAgentToHub:c})=>{const h=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:z("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?Zt:"hover:bg-row-hover"),children:[e.jsx(zt,{className:"size-8 shrink-0",children:e.jsx($t,{className:"border border-control bg-sunken",children:e.jsx(_e,{size:16,"aria-hidden":!0})})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx(M,{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(M,{content:h,side:"bottom",align:"start",children:e.jsx("span",{className:"block truncate text-meta text-ink-dim",children:h})})]})]}),e.jsx("div",{className:z("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(M,{content:"Agent options",children:e.jsx("span",{children:e.jsx(Ca,{agentId:t.id,agentName:t.name,isAgentsPage:!0,onAgentDeleted:()=>r(t.id),onChatWithAgent:()=>i(t.id),onExportAgent:()=>n(t.id),onUploadAgentToHub:()=>c(t),buttonSx:{width:24,height:24,borderRadius:"6px",display:"flex",justifyContent:"center",alignItems:"center"}})})})})]})},Ga=(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,Ya=o.memo(Qa,Ga),Fa=({selectedAgentId:t,onSelectAgent:s})=>{const a=Ce(),[i,n]=o.useState(""),r=sa(y=>y.openCreateAgentDialog),c=Je(i.trim(),250),[h,m]=o.useState(!1),k=50,[b,p]=o.useState(!1),[l,d]=o.useState(null),{isAuthenticated:u}=Ae(),x=o.useMemo(()=>Ne(Q.baseUrl),[]),w=Xe(),{page:_,setPage:I}=Sa(),{data:S,isLoading:v,isError:E,refetch:g}=Ft(_,k,0,c||void 0,"created_date","desc"),C=S?.agents||[],j=S?.total||0,{data:T}=et(t&&!C.find(y=>y.id===t)?t:void 0),A=o.useMemo(()=>{const y=[...C];return T&&!y.find(L=>L.id===T.id)&&y.push(T),y.sort((L,$)=>new Date($.created_date).getTime()-new Date(L.created_date).getTime()),y},[C,T]),ge=o.useCallback(y=>{I(y)},[I]),ae=o.useCallback(y=>{s(y)},[s]),V=o.useCallback(()=>{m(!0)},[]),G=o.useCallback(()=>{m(!1)},[]),re=o.useCallback(async y=>{try{const L=await w.mutateAsync(y),$=A.find(se=>se.id===y),O=$?$.name.replace(/\s+/g,"-").toLowerCase():y,D=URL.createObjectURL(L),U=document.createElement("a");U.href=D,U.download=`${O}-export.zip`,document.body.appendChild(U),U.click(),URL.revokeObjectURL(D),document.body.removeChild(U)}catch(L){console.error("Failed to export agent:",L)}},[A,w]),R=o.useCallback(y=>{d(y),p(!0)},[]),Y=o.useCallback(()=>{p(!1),d(null)},[]),F=o.useCallback(async y=>{try{const $=((await g()).data?.agents||[]).find(D=>D.id===y);if($){s($);return}const O=await x.agents.getAgent(y);O.status<400&&O.result&&s(O.result)}catch(L){console.error("Error selecting newly created agent:",L)}},[s,g,x]),Z=o.useCallback(y=>{a(`/chat/${y}`)},[a]),le=o.useCallback(y=>{g(),a("/agents")},[t,g,a]),ce=o.useCallback(y=>{R(y)},[R]);return e.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden bg-surface",children:[e.jsx(Pa,{title:"Agents",searchQuery:i,onSearchChange:y=>n(y),onNewAgentClick:r,onImportAgentClick:V,importAgentTooltip:"Import an agent from a ZIP file"}),v?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(Ke,{size:"lg",label:"Loading agents"})}):E?e.jsxs(pe,{variant:"danger",role:"alert",className:"m-4 w-auto",children:[e.jsx(ne,{children:"Failed to load agents. Please try again."}),e.jsx(P,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>g(),children:"Retry"})]}):A.length===0&&!v?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(Ut,{delayDuration:Ka,skipDelayDuration:0,children:e.jsx("ul",{className:"flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-2",children:A.map(y=>e.jsx(Ya,{agent:y,isSelected:t===y.id||T?.id===y.id,onSelectAgent:ae,onChatWithAgent:Z,onExportAgent:re,onAgentDeleted:le,onUploadAgentToHub:ce},y.id))})}),e.jsx(Da,{open:h,onClose:G,onAgentImported:F}),j>0&&e.jsx(_a,{page:_,count:Math.max(1,Math.ceil(j/k)),onChange:ge}),e.jsx(nt,{open:b,onClose:Y,agent:l,isAuthenticated:u})]})},Za=o.memo(Fa),ds=()=>{const t=Nt("surface"),{agentId:s,navigateToAgent:a}=Jt(),i=Ce(),{isAuthenticated:n}=Ae(),[r,c]=o.useState(!1),h=Xe(),{setLastAgentsPageAgentId:m,getLastAgentId:k}=Ue(),b=s||k("agents"),{data:p,refetch:l}=et(b||void 0);o.useEffect(()=>{s&&m(s)},[s,m]);const d=async()=>{if(p)try{const _=await h.mutateAsync(p.id),I=URL.createObjectURL(_),S=document.createElement("a");S.href=I,S.download=`${p.name.replace(/\s+/g,"-").toLowerCase()}-lo-agent.zip`,document.body.appendChild(S),S.click(),URL.revokeObjectURL(I),document.body.removeChild(S)}catch(_){console.error("Failed to export agent:",_)}},u=()=>{c(!0)},x=()=>{c(!1)},w=_=>{m(_.id),a(_.id,"agents")};return e.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[e.jsx("div",{ref:t,className:"h-full w-70 shrink-0",children:e.jsx(Za,{selectedAgentId:p?.id,onSelectAgent:w})}),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(_t,{title:"Agent management",icon:_e,subtitle:"View, configure and manage your agents",children:p&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Be,{children:[e.jsx(He,{asChild:!0,children:e.jsx(P,{"data-tour-tag":"upload-to-hub-header-button",variant:"secondary",size:"icon","aria-label":"More agent actions",className:"@min-[400px]:hidden",children:e.jsx(Ct,{"aria-hidden":"true"})})}),e.jsxs(We,{align:"end",className:"min-w-45",children:[e.jsxs(W,{disabled:h.isPending,onSelect:d,children:[e.jsx(Te,{"aria-hidden":"true"}),e.jsx("span",{children:"Export"})]}),e.jsxs(W,{onSelect:u,children:[e.jsx(we,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]})]})]}),e.jsxs(P,{variant:"secondary",onClick:d,disabled:h.isPending,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(Te,{"aria-hidden":"true"}),"Export"]}),e.jsxs(P,{"data-tour-tag":"upload-to-hub-header-button","data-tour-action":"open-upload-dialog",variant:"secondary",onClick:u,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(we,{"aria-hidden":"true"}),"Upload to hub"]}),e.jsx(M,{content:`Chat with ${p.name||"this agent"}`,children:e.jsxs(P,{variant:"primary",onClick:()=>i(`/chat/${p.id}`),children:[e.jsx(Fe,{"aria-hidden":"true"}),"Chat"]})})]})})}),e.jsx("div",{className:"min-h-0 grow overflow-hidden",children:e.jsx(za,{selectedAgent:p??null,refetchAgent:l,initialSelectedAgentId:s})})]})}),p&&e.jsx(nt,{open:r,onClose:x,agent:p,isAuthenticated:n})]})};export{ds as LegacyAgentsPage};
|
|
33
|
+
`).map(x=>x.trim()).filter(x=>x.length>0),u={stop:d.length>0?d:void 0};await i.mutateAsync({agentId:t.id,update:u}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})]})]})]})]})},st=["investment","accounting","healthcare","legal","software","security","role_play","personal_assistance","education","marketing","sales","research","analysis","management","social_media","other"],ue=Object.fromEntries(st.map(t=>[t,t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")])),Ea=({value:t,label:s,onChange:a,placeholder:i="Add category...",disabled:n=!1,icon:r})=>{const[c,h]=o.useState(""),[m,k]=o.useState(!1),[b,p]=o.useState(0),l=o.useRef(null),d=o.useRef([]),u=o.useId(),x=o.useId(),w=o.useMemo(()=>{const g=c.trim().toLowerCase();return st.filter(C=>!t.includes(C)&&(!g||ue[C].toLowerCase().includes(g)))},[t,c]);o.useEffect(()=>{m&&d.current[b]?.scrollIntoView({block:"nearest"})},[b,m]);const _=g=>{t.includes(g)||a([...t,g]),h(""),k(!1),p(0),l.current?.focus()},I=g=>{h(g.target.value),p(0),k(!0)},S=g=>{const C=w.length;switch(g.key){case"ArrowDown":if(g.preventDefault(),C===0)break;m?p((b+1)%C):(p(0),k(!0));break;case"ArrowUp":if(g.preventDefault(),C===0)break;m?p((b-1+C)%C):(p(C-1),k(!0));break;case"Enter":m&&w[b]&&(g.preventDefault(),_(w[b]));break;case"Escape":m&&(g.preventDefault(),k(!1));break;case"Home":m&&(g.preventDefault(),p(0));break;case"End":m&&(g.preventDefault(),p(w.length-1));break}},v=g=>{a(t.filter(C=>C!==g)),p(0)},L=m&&w[b]?`${x}-option-${b}`:void 0;return e.jsxs("div",{children:[e.jsxs(ie,{htmlFor:u,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[r,s]}),e.jsxs("div",{className:z("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(g=>e.jsxs(Ge,{className:"gap-1 pr-1 text-ink",children:[ue[g]||g,e.jsx("button",{type:"button","aria-label":`Remove category ${ue[g]||g}`,disabled:n,onClick:()=>v(g),className:z("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Ye,{})})]},g)),e.jsxs(St,{open:m,onOpenChange:k,children:[e.jsx(Dt,{asChild:!0,children:e.jsx("input",{id:u,ref:l,type:"text",role:"combobox","aria-expanded":m,"aria-controls":x,"aria-autocomplete":"list","aria-activedescendant":L,autoComplete:"off",value:c,placeholder:i,disabled:n,"aria-label":s,onChange:I,onKeyDown:S,onClick:()=>{w.length>0&&k(!0)},className:z("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(Pt,{align:"start",sideOffset:4,onOpenAutoFocus:g=>g.preventDefault(),className:"max-h-60 w-(--radix-popover-trigger-width) overflow-y-auto p-1",children:e.jsx("div",{id:x,role:"listbox","aria-label":s,children:w.map((g,C)=>e.jsx("div",{id:`${x}-option-${C}`,ref:j=>{d.current[C]=j},role:"option","aria-selected":C===b,onMouseDown:j=>{j.preventDefault()},onMouseEnter:()=>p(C),onClick:()=>_(g),className:z("cursor-pointer rounded-sm px-3 py-1.5 font-medium text-body-sm",C===b?"bg-accent-wash":void 0,"text-ink"),children:ue[g]||g},g))})})]})]}),t.length===0&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No categories selected"})]})},La=({value:t,label:s,onChange:a,placeholder:i="Add tag...",disabled:n=!1,icon:r})=>{const[c,h]=o.useState(""),m=o.useRef(null),k=o.useId(),b=u=>{h(u.target.value)},p=()=>{const u=c.trim().toLowerCase();u&&!t.includes(u)&&a([...t,u]),h("")},l=u=>{u.key==="Enter"&&c.trim()?(u.preventDefault(),p()):u.key==="Backspace"&&!c&&t.length>0&&a(t.slice(0,-1))},d=u=>{a(t.filter(x=>x!==u))};return e.jsxs("div",{children:[e.jsxs(ie,{htmlFor:k,className:"mb-1.5 flex items-center gap-2 text-ink-muted",children:[r,s]}),e.jsxs("div",{className:z("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(Ge,{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:z("rounded-xs text-ink-dim","transition-colors duration-fast ease-out-quart","hover:text-danger disabled:text-ink-disabled"),children:e.jsx(Ye,{})})]},u)),e.jsx("input",{id:k,ref:m,type:"text",value:c,onChange:b,onKeyDown:l,placeholder:i,disabled:n,"aria-label":s,className:z("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")}),c.trim()&&e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"Add tag",disabled:n,onClick:()=>{p(),m.current?.focus()},className:"text-accent hover:text-accent",children:e.jsx(Ze,{})})]}),t.length===0&&!c&&e.jsx("span",{className:"mt-1 ml-1 block text-ink-dim text-meta",children:"No tags added"})]})},Oa=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>{const{data:c,isLoading:h}=xt(),[m,k]=o.useState("");o.useEffect(()=>{!h&&c?.values?k(t.hosting||c.values.hosting||""):h||k(t.hosting||"")},[t,c,h]);const[b,p]=o.useState(!1),[l,d]=o.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ee,{value:t.name,label:"Agent name",placeholder:"Enter agent name...",isSaving:s==="name",onSave:async u=>{if(!u.trim()){oe("Agent name cannot be empty");return}a("name");try{const x={name:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&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(Vt,{value:t.hosting||(c?.values.hosting??""),isSaving:s==="hosting",onSave:async u=>{a("hosting"),k(u);try{const x={hosting:u,model:""};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{k(t.hosting||"")}finally{a(null)}},filterByCredentials:!0,allowDefault:!0},`hosting-select-${t.id}-${t.hosting||(c?.values.hosting??"default")}`)}),e.jsx("div",{"data-tour-tag":"agent-settings-model-select",children:m?e.jsx(Wt,{value:t.hosting?t.model||"":t.model||(c?.values.model_name??""),hostingId:m,isSaving:s==="model",allowDefault:!0,onSave:async u=>{a("model");try{const x={model:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{a(null)}}},`model-select-${t.id}-${m}-${t.model||(!t.hosting&&c?.values.model_name?c.values.model_name:"default")}`):e.jsxs("div",{className:"relative",children:[e.jsx(M,{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(Kt,{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(xe,{size:16,className:"shrink-0 text-ink-dim"}),"Agent information"]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ee,{value:t.description||"",label:"Description",placeholder:"Enter agent description...",multiline:!0,rows:3,isSaving:s==="description",onSave:async u=>{a("description");try{const x={description:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{a(null)}}}),e.jsx(La,{value:t.tags||[],label:"Tags",placeholder:"Add tag...",disabled:b,onChange:async u=>{if(!(Array.isArray(t.tags)&&u.length===t.tags.length&&u.every((x,w)=>x===t.tags?.[w]))){p(!0);try{const x={tags:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{p(!1)}}}}),e.jsx(Ea,{value:t.categories||[],label:"Categories",placeholder:"Add category...",disabled:l,onChange:async u=>{if(!(Array.isArray(t.categories)&&u.length===t.categories.length&&u.every((x,w)=>x===t.categories?.[w]))){d(!0);try{const x={categories:u};await i.mutateAsync({agentId:t.id,update:x}),t.id===r&&n&&await n()}catch{}finally{d(!1)}}}}),e.jsxs(Xt,{children:[e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(va,{size:12,"aria-hidden":"true"}),"ID"]}),value:e.jsx("span",{className:"font-mono text-mono-sm",children:t.id})}),e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(Qt,{size:12,"aria-hidden":"true"}),"Created"]}),value:gt(t.created_date)}),e.jsx(ye,{label:e.jsxs(e.Fragment,{children:[e.jsx(ja,{size:12,"aria-hidden":"true"}),"Version"]}),value:t.version})]})]})]})},Ra=({selectedAgent:t,savingField:s,setSavingField:a,updateAgentMutation:i,refetchAgent:n,initialSelectedAgentId:r})=>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(Gt,{size:16,className:"shrink-0 text-ink-dim"}),"Security instructions",e.jsx(M,{content:`Security instructions that guide the agent's behavior and limitations. This is the "system prompt" for the security agent.`,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About security instructions",children:e.jsx(xe,{})})})]}),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(ee,{value:t.security_prompt||"",label:"",placeholder:"Enter instructions for the security agent...",multiline:!0,rows:6,isSaving:s==="security_prompt",onSave:async c=>{a("security_prompt");try{const h={security_prompt:c};await i.mutateAsync({agentId:t.id,update:h}),t.id===r&&n&&await n()}catch{}finally{a(null)}}})})]}),Ua=({selectedAgent:t,savingField:s,setSavingField:a,refetchAgent:i,initialSelectedAgentId:n})=>{const{data:r,isLoading:c}=at(t.id),h=Ia(t.id),[m,k]=o.useState("");return o.useEffect(()=>{r!==void 0&&k(r)},[r]),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(ea,{size:16,className:"shrink-0 text-ink-dim"}),"Agent instructions",e.jsx(M,{content:`System instructions that define the agent's behavior and capabilities. This is the agent's "system prompt".`,children:e.jsx(P,{variant:"ghost",size:"icon-sm","aria-label":"About agent instructions",children:e.jsx(xe,{})})})]}),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(ee,{value:m,label:"",placeholder:c?"Loading system prompt...":"Enter instructions for the agent...",multiline:!0,rows:6,isSaving:s==="system_prompt",onSave:async b=>{a("system_prompt");try{await h.mutateAsync(b),t.id===n&&i&&await i()}finally{a(null)}}})})]})},za=({selectedAgent:t,refetchAgent:s,initialSelectedAgentId:a})=>{const[i,n]=o.useState(null),r=Yt();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(Oa,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ua,{selectedAgent:t,savingField:i,setSavingField:n,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ra,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,refetchAgent:s,initialSelectedAgentId:a}),e.jsx(Ta,{selectedAgent:t,savingField:i,setSavingField:n,updateAgentMutation:r,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(_e,{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."})]})})},Ie=ta()(aa(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"})),$a=t=>Ie(s=>t?s.listings[t]??null:null),qa=400,Ma=2,Aa=t=>[...t].length>=Ma;function Ba(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 Ha=(t,s)=>{const a=t.trim(),i=Je(a,qa),n=s&&i===a&&Aa(i)&&ft(i),r=ze({queryKey:["agent-name-availability",i],enabled:n,queryFn:async()=>(await ke.getAgentNameAvailability(Q.baseUrl,i)).result,retry:!1,staleTime:15e3,refetchOnWindowFocus:!1});return!n||r.isPending?{state:n?"checking":"idle",builtinName:null}:r.isError?{state:"unknown",builtinName:null}:Ba(r.data)},Va=()=>{const t=$e();return qe({mutationFn:async({agentId:s,document:a,hubAgentId:i,target:n})=>{if(!Q.baseUrl)throw new Error("Local Operator API URL is not configured.");return i?ke.republishAgentInstructionSet(Q.baseUrl,s,i,a,n):ke.publishAgentInstructionSet(Q.baseUrl,s,a,n)},onSuccess:(s,a)=>{const i=s.result;i?.agent_id&&Ie.getState().remember(a.agentId,{hubAgentId:i.agent_id,name:i.name,publishedAt:new Date().toISOString()}),a.target?na(t,a.target.tenantId):ia(t)},onError:s=>{console.error("Publishing an agent to the hub failed:",s)}})},me="public",nt=({open:t,onClose:s,agent:a,isAuthenticated:i,onSignInSuccess:n,onPublished:r})=>{const[c,h]=o.useState(!1),[m,k]=o.useState(""),[b,p]=o.useState(null),[l,d]=o.useState(null),[u,x]=o.useState(!1),w=o.useRef(null),_=o.useRef(null),I=Ce(),S=Va(),v=$a(a?.id??null),L=bt(),g=yt(),C=jt(L.data,"radient_org"),j=ha(C),T=i?ma(C,g??null):null,{memberships:A,isError:ge}=oa({enabled:t&&i&&j}),ae=o.useMemo(()=>da(A),[A]),W=o.useMemo(()=>ua(A),[A]),[G,re]=o.useState(me),R=G!==me,Y=ae.find(f=>f.tenant_id===G)?.tenant_name||"this organization",F=o.useId(),Z=o.useId(),{data:le}=at(t&&a?a.id:""),{data:ce}=kt(t);o.useEffect(()=>{t&&k(a?.name??"")},[t,a?.name]),o.useEffect(()=>{t||(h(!1),p(null),d(null),x(!1),re(me))},[t]);const y=o.useMemo(()=>(ce??[]).filter(f=>f.source==="builtin").map(f=>f.name),[ce]),E=ra(m,y),$=Ha(m,t&&i),O=o.useMemo(()=>{const f=la({name:m,description:a?.description??"",instructions:le??null,tools:ca(a?.tags)});return E&&f.unshift({field:"name",message:Ee({code:"name_reserved_builtin",message:""},{name:m,hubAgentId:null}).body}),f},[m,a?.description,a?.tags,le,E]),D=b?Ee(b,{name:m,hubAgentId:v?.hubAgentId??null}):null,U=S.isPending,se=async f=>{if(!a||U||O.length>0)return;p(null);const q=f?.asNewListing||R?null:v?.hubAgentId??null,rt=!!q;try{const K={name:m.trim()},de=(await S.mutateAsync({agentId:a.id,document:K,hubAgentId:q,target:R?{visibility:"org",tenantId:G}:void 0})).result,De={name:de?.name??m.trim(),hubAgentId:de?.agent_id??null,republished:rt,orgName:R?Y:null};d(De),de&&r?.(de,De.republished)}catch(K){p(wt(K)?{code:K.code,message:K.message,details:K.details}:{message:vt(K,"The agent could not be published. Try again.")})}},Se=f=>{switch(f){case"focus-name":p(null),requestAnimationFrame(()=>{w.current?.focus(),w.current?.select()});break;case"update-listing":{const q=b?.details?.existing_agent_id??v?.hubAgentId;q&&(s(),I(`/agent-hub/${q}`));break}case"install-builtin":{const q=b?.details?.builtin_name??$.builtinName;q&&(s(),I(`/agents?kind=agent&name=${encodeURIComponent(q)}`));break}case"edit-instructions":case"edit-agent":a&&(s(),I(`/agents/${a.id}`));break;case"publish-as-new":a&&Ie.getState().forget(a.id),se({asNewListing:!0});break;case"sign-in":x(!0);break;case"refresh-hub":s(),I("/agent-hub");break;case"retry":se();break}},B=a?.name??"",it=l?l.orgName?`Published "${B}" to ${l.orgName}`:l.republished?`Updated the Agent hub listing for "${B}"`:`Published "${B}" to the Agent hub`:R?`Publish "${B}" to ${Y}?`:v?`Update the Agent hub listing for "${B}"?`:`Publish "${B}" to the Agent hub?`;o.useLayoutEffect(()=>{!b&&!l||_.current?.focus()},[b,l]);const ot=l?e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),l.hubAgentId&&e.jsx(he,{onClick:()=>{s(),I(`/agent-hub/${l.hubAgentId}`)},children:"Open the listing"})]}):D?e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Close"}),D.actions.map((f,q)=>q===0?e.jsx(he,{onClick:()=>Se(f),disabled:U,children:Le[f]},f):e.jsx(X,{onClick:()=>Se(f),disabled:U,children:Le[f]},f))]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{onClick:s,"data-tour-tag":"upload-agent-dialog-cancel-button",children:"Cancel"}),O.some(f=>f.field!=="name")&&e.jsx(X,{onClick:()=>{a&&(s(),I(`/agents/${a.id}`))},children:"Edit the agent"}),i&&e.jsx(he,{"data-testid":"publish-submit",onClick:()=>void se(),disabled:!c||O.length>0||!m.trim()||U,children:U?"Publishing…":v&&!R?"Update listing":"Publish"})]});return e.jsx(Me,{open:t,onClose:s,title:it,maxWidth:"sm",fullWidth:!0,actions:ot,dataTourTag:"upload-agent-dialog",dialogProps:{className:"outline-none"},children:e.jsxs("div",{ref:_,tabIndex:b||l?-1:void 0,className:z("flex flex-col gap-4",(b||l)&&"outline-none"),children:[i?l?e.jsxs(pe,{variant:"success","aria-live":"polite",children:[e.jsx(fe,{children:l.orgName?`Published to ${l.orgName}`:l.republished?"Listing updated":"Published to the hub"}),e.jsx(ne,{children:l.orgName?`"${l.name}" is in ${l.orgName}'s shared agents as an instruction set. Its members can read and install it; nobody outside the organization can.`:l.republished?`The hub now holds the current instruction set of "${l.name}".`:`"${l.name}" is on the hub as an instruction set. Anyone can read and install it.`}),e.jsx(ne,{className:"text-ink-muted",children:"Nothing else left this machine: no conversation, no execution history, no memory, no plan and no machine-specific configuration."})]}):D&&b?e.jsxs(pe,{variant:D.variant,role:"alert",children:[e.jsx(fe,{children:D.headline}),e.jsx(ne,{children:D.body}),D.note&&e.jsx(ne,{className:"text-ink-muted",children:D.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(Oe,{titleText:"Sign in to continue",descriptionText:"",onSignInSuccess:n})]}),D&&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(Oe,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:()=>{x(!1),p(null),n?.()}})]}),!l&&!D&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body text-ink",children:R?`You are about to publish this agent's instruction set into ${Y}, where only its members can read and install it. What is published is what describes the agent:`:"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:R?`Nothing else leaves this machine: no conversation, no execution history, no memory or learnings, no plan, and no machine-specific configuration. ${Y}'s members can read and install what you publish; nobody outside it can.`:"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."}),ae.length>0||W.length>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(ie,{htmlFor:`${F}-target`,children:"Publish to"}),e.jsxs(Tt,{value:G,onValueChange:re,children:[e.jsx(Et,{id:`${F}-target`,className:"w-full","data-testid":"publish-target",children:e.jsx(Lt,{})}),e.jsxs(Ot,{children:[e.jsx(be,{value:me,children:"Public hub"}),ae.map(f=>e.jsx(be,{value:f.tenant_id,children:f.tenant_name||"Organization"},f.tenant_id)),W.map(f=>e.jsxs(be,{value:f.tenant_id,disabled:!0,children:[f.tenant_name||"Organization"," (upgrade needed)"]},f.tenant_id))]})]}),e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-hint",children:W.length>0?`Sharing agents inside an organization is part of the Team plan. An owner of ${W.length===1?W[0].tenant_name||"this organization":"any of the organizations marked above"} can activate it in the Radient console.`:"Public hub publications are readable by anyone. An organization's agents are readable by its members only."})]}):T?e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-unavailable",children:T}):ge?e.jsx("p",{className:"text-meta text-ink-muted","data-testid":"publish-target-failed",children:"Your organizations could not be read, so this publishes to the public hub. Try again in a moment to publish into an organization."}):null,O.length>0&&e.jsxs(pe,{variant:"danger",children:[e.jsx(fe,{children:"This agent cannot be published yet"}),e.jsx("ul",{className:"list-disc space-y-1 pl-5",children:O.map(f=>e.jsx("li",{children:f.message},`${f.field}:${f.message}`))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(ie,{htmlFor:Z,children:"Name on the hub"}),e.jsx(Qe,{id:Z,ref:w,value:m,onChange:f=>k(f.target.value),autoComplete:"off",spellCheck:!1,"aria-invalid":O.some(f=>f.field==="name"),"aria-describedby":`${Z}-hint`}),e.jsx("p",{id:`${Z}-hint`,className:"text-meta text-ink-muted",children:'No "/", "\\" or ":". Up to 128 characters.'}),!R&&Wa($)]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex h-5 shrink-0 items-center",children:e.jsx(Rt,{id:F,name:"termsAgreement","data-testid":"publish-consent",checked:c,onCheckedChange:f=>h(f===!0)})}),e.jsxs(ie,{htmlFor:F,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."]})]})]}),(l||D)&&B&&e.jsxs("p",{className:"text-meta text-ink-muted",children:["Agent: ",B]})]})})},Wa=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}},Ka=1200,Qa=({agent:t,isSelected:s,onSelectAgent:a,onChatWithAgent:i,onExportAgent:n,onAgentDeleted:r,onUploadAgentToHub:c})=>{const h=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:z("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?Zt:"hover:bg-row-hover"),children:[e.jsx(zt,{className:"size-8 shrink-0",children:e.jsx($t,{className:"border border-control bg-sunken",children:e.jsx(_e,{size:16,"aria-hidden":!0})})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx(M,{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(M,{content:h,side:"bottom",align:"start",children:e.jsx("span",{className:"block truncate text-meta text-ink-dim",children:h})})]})]}),e.jsx("div",{className:z("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(M,{content:"Agent options",children:e.jsx("span",{children:e.jsx(Ca,{agentId:t.id,agentName:t.name,isAgentsPage:!0,onAgentDeleted:()=>r(t.id),onChatWithAgent:()=>i(t.id),onExportAgent:()=>n(t.id),onUploadAgentToHub:()=>c(t),buttonSx:{width:24,height:24,borderRadius:"6px",display:"flex",justifyContent:"center",alignItems:"center"}})})})})]})},Ga=(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,Ya=o.memo(Qa,Ga),Fa=({selectedAgentId:t,onSelectAgent:s})=>{const a=Ce(),[i,n]=o.useState(""),r=sa(y=>y.openCreateAgentDialog),c=Je(i.trim(),250),[h,m]=o.useState(!1),k=50,[b,p]=o.useState(!1),[l,d]=o.useState(null),{isAuthenticated:u}=Ae(),x=o.useMemo(()=>Ne(Q.baseUrl),[]),w=Xe(),{page:_,setPage:I}=Sa(),{data:S,isLoading:v,isError:L,refetch:g}=Ft(_,k,0,c||void 0,"created_date","desc"),C=S?.agents||[],j=S?.total||0,{data:T}=et(t&&!C.find(y=>y.id===t)?t:void 0),A=o.useMemo(()=>{const y=[...C];return T&&!y.find(E=>E.id===T.id)&&y.push(T),y.sort((E,$)=>new Date($.created_date).getTime()-new Date(E.created_date).getTime()),y},[C,T]),ge=o.useCallback(y=>{I(y)},[I]),ae=o.useCallback(y=>{s(y)},[s]),W=o.useCallback(()=>{m(!0)},[]),G=o.useCallback(()=>{m(!1)},[]),re=o.useCallback(async y=>{try{const E=await w.mutateAsync(y),$=A.find(se=>se.id===y),O=$?$.name.replace(/\s+/g,"-").toLowerCase():y,D=URL.createObjectURL(E),U=document.createElement("a");U.href=D,U.download=`${O}-export.zip`,document.body.appendChild(U),U.click(),URL.revokeObjectURL(D),document.body.removeChild(U)}catch(E){console.error("Failed to export agent:",E)}},[A,w]),R=o.useCallback(y=>{d(y),p(!0)},[]),Y=o.useCallback(()=>{p(!1),d(null)},[]),F=o.useCallback(async y=>{try{const $=((await g()).data?.agents||[]).find(D=>D.id===y);if($){s($);return}const O=await x.agents.getAgent(y);O.status<400&&O.result&&s(O.result)}catch(E){console.error("Error selecting newly created agent:",E)}},[s,g,x]),Z=o.useCallback(y=>{a(`/chat/${y}`)},[a]),le=o.useCallback(y=>{g(),a("/agents")},[t,g,a]),ce=o.useCallback(y=>{R(y)},[R]);return e.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden bg-surface",children:[e.jsx(Pa,{title:"Agents",searchQuery:i,onSearchChange:y=>n(y),onNewAgentClick:r,onImportAgentClick:W,importAgentTooltip:"Import an agent from a ZIP file"}),v?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(Ke,{size:"lg",label:"Loading agents"})}):L?e.jsxs(pe,{variant:"danger",role:"alert",className:"m-4 w-auto",children:[e.jsx(ne,{children:"Failed to load agents. Please try again."}),e.jsx(P,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>g(),children:"Retry"})]}):A.length===0&&!v?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(Ut,{delayDuration:Ka,skipDelayDuration:0,children:e.jsx("ul",{className:"flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-2",children:A.map(y=>e.jsx(Ya,{agent:y,isSelected:t===y.id||T?.id===y.id,onSelectAgent:ae,onChatWithAgent:Z,onExportAgent:re,onAgentDeleted:le,onUploadAgentToHub:ce},y.id))})}),e.jsx(Da,{open:h,onClose:G,onAgentImported:F}),j>0&&e.jsx(_a,{page:_,count:Math.max(1,Math.ceil(j/k)),onChange:ge}),e.jsx(nt,{open:b,onClose:Y,agent:l,isAuthenticated:u})]})},Za=o.memo(Fa),ds=()=>{const t=Nt("surface"),{agentId:s,navigateToAgent:a}=Jt(),i=Ce(),{isAuthenticated:n}=Ae(),[r,c]=o.useState(!1),h=Xe(),{setLastAgentsPageAgentId:m,getLastAgentId:k}=Ue(),b=s||k("agents"),{data:p,refetch:l}=et(b||void 0);o.useEffect(()=>{s&&m(s)},[s,m]);const d=async()=>{if(p)try{const _=await h.mutateAsync(p.id),I=URL.createObjectURL(_),S=document.createElement("a");S.href=I,S.download=`${p.name.replace(/\s+/g,"-").toLowerCase()}-lo-agent.zip`,document.body.appendChild(S),S.click(),URL.revokeObjectURL(I),document.body.removeChild(S)}catch(_){console.error("Failed to export agent:",_)}},u=()=>{c(!0)},x=()=>{c(!1)},w=_=>{m(_.id),a(_.id,"agents")};return e.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[e.jsx("div",{ref:t,className:"h-full w-70 shrink-0",children:e.jsx(Za,{selectedAgentId:p?.id,onSelectAgent:w})}),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(_t,{title:"Agent management",icon:_e,subtitle:"View, configure and manage your agents",children:p&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Be,{children:[e.jsx(He,{asChild:!0,children:e.jsx(P,{"data-tour-tag":"upload-to-hub-header-button",variant:"secondary",size:"icon","aria-label":"More agent actions",className:"@min-[400px]:hidden",children:e.jsx(Ct,{"aria-hidden":"true"})})}),e.jsxs(Ve,{align:"end",className:"min-w-45",children:[e.jsxs(V,{disabled:h.isPending,onSelect:d,children:[e.jsx(Te,{"aria-hidden":"true"}),e.jsx("span",{children:"Export"})]}),e.jsxs(V,{onSelect:u,children:[e.jsx(we,{"aria-hidden":"true"}),e.jsx("span",{children:"Upload to hub"})]})]})]}),e.jsxs(P,{variant:"secondary",onClick:d,disabled:h.isPending,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(Te,{"aria-hidden":"true"}),"Export"]}),e.jsxs(P,{"data-tour-tag":"upload-to-hub-header-button","data-tour-action":"open-upload-dialog",variant:"secondary",onClick:u,className:"hidden @min-[400px]:inline-flex",children:[e.jsx(we,{"aria-hidden":"true"}),"Upload to hub"]}),e.jsx(M,{content:`Chat with ${p.name||"this agent"}`,children:e.jsxs(P,{variant:"primary",onClick:()=>i(`/chat/${p.id}`),children:[e.jsx(Fe,{"aria-hidden":"true"}),"Chat"]})})]})})}),e.jsx("div",{className:"min-h-0 grow overflow-hidden",children:e.jsx(za,{selectedAgent:p??null,refetchAgent:l,initialSelectedAgentId:s})})]})}),p&&e.jsx(nt,{open:r,onClose:x,agent:p,isAuthenticated:n})]})};export{ds as LegacyAgentsPage};
|