import{w as C,v as b,a as y,G as z,y as w,q as K,A as M}from"./chunk-QMGIS6GS-CBZUm-7V.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{C as T}from"./Card-BHrMkZ_V.js";import{G as g}from"./Group-bnACpcuK.js";import{B as v}from"./Badge-CHFht4LR.js";import{c as f}from"./createReactComponent-CwEnMXT7.js";import{T as S}from"./Text-CkpJSrnl.js";import{T as t,d as _}from"./dayjs.min-CzDNk_5I.js";import{f as D}from"./api-tgDzxHzW.js";import{d as B}from"./ScrollArea-C8H_Wh73.js";import{B as j}from"./polymorphic-factory-EW0USS3V.js";import{T as x}from"./Title-B0fFn55O.js";import{D as N}from"./Divider-BI4N1hoX.js";import{P as R}from"./Paper-k397c_lM.js";import{B as u}from"./Button-BhC08Y9X.js";import{I as J}from"./IconArrowLeft-4qKQ7vAI.js";import{S as P}from"./SimpleGrid-DIRoZGR6.js";import{I as L}from"./Input-I-MjqIR2.js";import{L as F}from"./Loader-1VreoqJz.js";import{m as I}from"./events-BOd7YSSb.js";import{S as G}from"./Stack-BsPYYAFq.js";import{P as V}from"./PasswordInput-DJfOJho_.js";import"./create-safe-context-CzEsa9t0.js";import"./index-B4z8r-Ct.js";import"./CloseButton-BDZlzHA2.js";import"./use-merged-ref-DUVM9oA6.js";import"./px-CiO0pVtX.js";import"./get-sorted-breakpoints-CWbmZd_q.js";import"./ActionIcon-BO4DDcDR.js";import"./use-input-props-CaHG8Gfi.js";/**
 * @license @tabler/icons-react v3.34.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var E=f("outline","download","IconDownload",[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M7 11l5 5l5 -5",key:"svg-1"}],["path",{d:"M12 4l0 12",key:"svg-2"}]]);/**
 * @license @tabler/icons-react v3.34.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var O=f("outline","plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.34.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Y=f("outline","search","IconSearch",[["path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M21 21l-6 -6",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.34.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var q=f("outline","settings","IconSettings",[["path",{d:"M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z",key:"svg-0"}],["path",{d:"M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0",key:"svg-1"}]]);const U="https://api-jpr.trueselph.com",$="_root_18rw4_1",W={root:$};function H({pkg:r,onClick:a}){return e.jsxs(T,{withBorder:!0,padding:"lg",radius:"md",onClick:a?()=>a(r):void 0,className:W.root,children:[e.jsxs(g,{justify:"space-between",children:[e.jsx(v,{size:"sm",color:"gray",variant:"outline",children:r.version||"-"}),e.jsx(v,{size:"sm",leftSection:e.jsx(E,{size:14}),variant:"filled",color:"dark",children:r.downloads})]}),e.jsx(S,{fz:"md",fw:500,mt:"md",children:r.title}),e.jsx(S,{fz:"sm",c:"gray.7",mt:5,lineClamp:3,children:r.description})]})}function Ce(){return[{title:"New Agent | JIVAS Manager"}]}async function be({request:r}){const a=new URL(r.url),s=a.searchParams.get("limit")||"10",o=a.searchParams.get("offset")||"0",c=a.searchParams.get("search")||"",d=a.searchParams.get("type")||"agent",n=localStorage.getItem("jpr-key")||null,i=new URL(`${U}/packages/search`);i.searchParams.set("limit",s),i.searchParams.set("offset",o),i.searchParams.set("q",c),console.log({packageType:d,search:c}),i.searchParams.set("type",d==="all"?"":d);const l=n?{"x-api-key":n}:void 0;console.log({headers:l});const m=await fetch(i.toString(),{method:"GET",headers:{...l,"Content-Type":"application/json"}}).then(h=>h.json());return{packages:m.packages,totalPackages:m.total,apiKey:n||""}}async function ze({request:r}){var d;const a=localStorage.getItem("jivas-host"),s=localStorage.getItem("jpr-key"),o=await r.formData(),c=o.get("_action");if(c==="createAgentFromDaf"){const n=o.get("version"),i=o.get("package"),l=await D(`${a}/walker/import_agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reporting:!0,daf_name:i,daf_version:n||"latest",jpr_api_key:s||void 0})}).then(async h=>await h.json()),m=(d=l.reports)==null?void 0:d[0];return m?(localStorage.setItem("jivas-agent",m.id),b("/dashboard")):l.reports}if(c==="updateJPRApiKey"){const n=o.get("apiKey");return localStorage.setItem("jpr-key",n||""),{}}}const Ke=C(function({loaderData:a}){var k;localStorage.getItem("jivas-host"),localStorage.getItem("jivas-token");const[s,o]=y.useState(null),[c,d]=y.useState(new Set([])),[n,i]=z(),l=w(),m=B(async p=>{n.set("search",p),i(n)},500),h=K(),A=M();return e.jsxs(j,{py:"xl",px:"xl",children:[e.jsx(g,{justify:"space-between",children:e.jsx(x,{order:3,children:"New Agent"})}),e.jsx(N,{mt:"xs",mb:"xl"}),e.jsx(T,{h:"80vh",px:"xs",withBorder:!0,children:e.jsxs(R,{p:"md",radius:"md",h:"100%",children:[e.jsx(x,{order:3,children:"Browse Agents"}),s?e.jsxs(j,{mt:"xl",children:[e.jsxs(g,{children:[e.jsx(u,{onClick:()=>o(null),size:"xs",leftSection:e.jsx(J,{size:16}),color:"dark",children:"Back"}),e.jsx(x,{order:4,children:s.title})]}),e.jsxs(P,{mt:"lg",cols:{base:1,md:2},children:[e.jsxs(j,{children:[e.jsx(x,{order:6,children:"Description"}),e.jsx(S,{size:"sm",c:"gray.7",children:s.description})]}),e.jsxs(j,{children:[e.jsx(t,{variant:"vertical",layout:"fixed",withTableBorder:!0,children:e.jsxs(t.Tbody,{children:[e.jsxs(t.Tr,{children:[e.jsx(t.Th,{w:160,children:"Package"}),e.jsx(t.Td,{children:s.package})]}),e.jsxs(t.Tr,{children:[e.jsx(t.Th,{children:"Version"}),e.jsx(t.Td,{children:s.version})]}),e.jsxs(t.Tr,{children:[e.jsx(t.Th,{children:"Category"}),e.jsx(t.Td,{children:e.jsx(v,{color:"dark",children:s.type})})]}),e.jsxs(t.Tr,{children:[e.jsx(t.Th,{children:"Downloads"}),e.jsx(t.Td,{children:s.downloads})]}),e.jsxs(t.Tr,{children:[e.jsx(t.Th,{children:"Last Published"}),e.jsx(t.Td,{children:_(s.publishedAt).format("MMMM D, YYYY h:mm:ss A")})]})]})}),e.jsx(g,{justify:"end",mt:"lg",children:e.jsx(u,{onClick:()=>l.submit({_action:"createAgentFromDaf",package:s.package,version:s.version},{method:"POST"}),leftSection:e.jsx(O,{size:16}),loading:l.state!=="idle",color:"dark",children:"Create Agent"})})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(g,{my:"lg",children:[e.jsx(L,{placeholder:"Search Agent",w:400,rightSection:h.state==="loading"&&h.location.pathname==A.pathname?e.jsx(F,{size:"xs"}):null,onChange:p=>{m(p.target.value)},leftSection:e.jsx(Y,{size:16})}),e.jsx(u,{size:"sm",color:"dark",onClick:()=>I.open({title:"JPR Configuration",children:e.jsx(Q,{apiKeyInit:a.apiKey})}),leftSection:e.jsx(q,{size:16}),children:"Configure"})]}),e.jsx(P,{cols:{base:1,md:2,lg:4},children:(k=a.packages)==null?void 0:k.map(p=>e.jsx(H,{onClick:o,pkg:p},p.id))})]})]})})]})});function Q({apiKeyInit:r}){const[a,s]=y.useState(r),o=w();return e.jsxs(G,{children:[e.jsx(V,{label:"API Key",placeholder:"API Key",value:a||"",onChange:c=>s(c.target.value)}),e.jsx(u,{size:"sm",color:"dark",mt:"sm",loading:o.state!=="idle",onClick:()=>{o.submit({apiKey:a,_action:"updateJPRApiKey"},{method:"POST",action:"/new-agent"}),I.closeAll()},children:"Save"})]})}export{ze as clientAction,be as clientLoader,Ke as default,Ce as meta};
