2 lines
7.3 KiB
JavaScript
2 lines
7.3 KiB
JavaScript
import{d as ee,u as ae,X as te,r as i,c as K,o as se,M as L,e as v,f as l,g as d,j as s,h as o,w as c,i as ne,F as le,C as oe,y as C,k as ie,a0 as I,t,l as u,$ as z,m as re,p as A,n as $,Z as ce,D as U,a1 as ue,_ as de,as as ge,aA as ve,a2 as pe}from"./index-b37e64ca.js";import{I as S}from"./iconify-b5ab1212.js";import{I as _e}from"./InstallProgressModal-8a22be9b.js";import{_ as me}from"./_plugin-vue_export-helper-c27b6911.js";const he={class:"agent-marketplace"},fe={class:"page-header"},ye={class:"header-content"},we={class:"header-text"},ke={class:"content"},Ce={class:"search-container"},Ie={class:"search-bar"},Ae={key:0,class:"agents-section"},Se={class:"agents-header"},be={class:"sort-controls"},Ne={class:"agents-grid"},Me=["onClick"],Pe={key:1,class:"agent-icon-placeholder"},xe={class:"agent-content"},ze={class:"agent-header"},$e={class:"agent-title-section"},Te=["onClick"],je={key:0,class:"agent-name"},Be={key:0,class:"agent-description"},Fe={class:"agent-actions"},Le={class:"pagination-container"},Ue={key:1,class:"loading"},Ve={key:2,class:"empty"},Ee=ee({__name:"AgentMarketplace",setup(Re){const b=ae(),q=te(),Q=ie(),T=i(""),f=i(!1),p=i([]),N=i(0),_=i(1),y=i(parseInt(localStorage.getItem("itemsPerPage")||"20")),M=i("creation desc"),P=i(!1),w=i(0),h=i(""),x=i("info"),k=i(!1),V=i(new Set),X=K(()=>[{label:t("Latest"),value:"creation desc"},{label:t("Oldest"),value:"creation asc"},{label:t("Name A-Z"),value:"agent_name asc"},{label:t("Name Z-A"),value:"agent_name desc"},{label:t("Most Popular"),value:"modified desc"}]),G=K(()=>Math.max(1,Math.ceil(N.value/y.value)));async function g(){f.value=!0;try{const e=new URLSearchParams({page:_.value.toString(),page_size:y.value.toString(),search:T.value,sort_by:M.value}),a=(await I.get(`/jingrow/agent-marketplace?${e}`)).data;a.items?(p.value=a.items,N.value=a.total||0):(p.value=a||[],N.value=p.value.length)}catch(e){console.error("Failed to load agents:",e),b.error(t("Failed to load agents")),p.value=[],N.value=0}finally{f.value=!1}}function H(e){y.value=e,_.value=1,localStorage.setItem("itemsPerPage",e.toString()),g()}function j(e){Q.push({path:`/agent-marketplace/${e.name}`,query:{returnTo:"/agent-marketplace"}})}async function E(e){if(!e.agent_flow&&!e.agent_name){b.error(t("Agent flow data or name is missing"));return}try{const n=e.agent_name||e.name;if(n&&(await I.get(`/jingrow/check-agent/${n}`)).data.exists){q.warning({title:t("Agent already exists"),content:t('Agent "{0}" is already installed, do you want to overwrite?').replace("{0}",n),positiveText:t("Confirm Overwrite"),negativeText:t("Cancel"),onPositiveClick:()=>{R(e)}});return}}catch(n){console.error("Check agent exists error:",n)}R(e)}async function R(e){var n,a,m,D;try{P.value=!0,w.value=0,h.value=t("Preparing installation..."),x.value="info",k.value=!0;let r=e.agent_flow,F=e.agent_name||e.name;if(!r){h.value=t("Fetching agent details..."),w.value=20;try{const J=(await I.get(`/jingrow/agent-marketplace/${e.name}`)).data;r=J.agent_flow,F=J.agent_name||F}catch{throw new Error(t("Failed to fetch agent details"))}}if(!r)throw new Error(t("Agent flow data is missing"));if(w.value=40,h.value=t("Installing agent..."),typeof r=="string")try{r=JSON.parse(r)}catch{}const O=await I.post("/jingrow/install-agent",{agent_name:F,agent_flow:r},{headers:{...pe(),"Content-Type":"application/json"}});if(w.value=100,O.data.success)P.value=!1,x.value="success",h.value=t("Agent installed successfully!"),b.success(t("Agent installed successfully")),B(),setTimeout(()=>{k.value=!1},2e3);else throw new Error(O.data.error||t("Installation failed"))}catch(r){console.error("Install agent error:",r),P.value=!1,x.value="error",h.value=((a=(n=r.response)==null?void 0:n.data)==null?void 0:a.detail)||r.message||t("Installation failed"),b.error(((D=(m=r.response)==null?void 0:m.data)==null?void 0:D.detail)||t("Installation failed")),setTimeout(()=>{k.value=!1},3e3)}}function W(e,n){return e?e.length<=n?e:e.substring(0,n)+"...":""}async function B(){try{const e=await I.get("/jingrow/installed-agent-names");if(e.data.success){const n=e.data.agents||[];V.value=new Set(n.map(a=>a.toLowerCase()))}}catch(e){console.error("Load installed agents error:",e)}}function Y(e){return e?V.value.has(e.toLowerCase()):!1}return se(()=>{g(),B(),window.addEventListener("installedAgentsUpdated",()=>{B()})}),L([M],()=>{_.value=1,g()},{deep:!0}),L([_],()=>{g()}),L(()=>localStorage.getItem("itemsPerPage"),e=>{e&&(y.value=parseInt(e),_.value=1,g())}),(e,n)=>(u(),v("div",he,[l("div",fe,[l("div",ye,[l("div",we,[l("h1",null,d(s(t)("Agent Marketplace")),1),l("p",null,d(s(t)("Browse and install agents from Jingrow Agent Marketplace")),1)])])]),l("div",ke,[l("div",Ce,[l("div",Ie,[o(s(re),{value:T.value,"onUpdate:value":n[0]||(n[0]=a=>T.value=a),placeholder:s(t)("Search agents..."),clearable:"",size:"large",onKeyup:ne(g,["enter"]),class:"search-input"},{prefix:c(()=>[o(s(z),null,{default:c(()=>[o(s(S),{icon:"tabler:search"})]),_:1})]),_:1},8,["value","placeholder"]),o(s($),{type:"primary",size:"large",onClick:g,class:"search-button"},{icon:c(()=>[o(s(z),null,{default:c(()=>[o(s(S),{icon:"tabler:search"})]),_:1})]),default:c(()=>[A(" "+d(s(t)("Search")),1)]),_:1})])]),!f.value&&p.value.length>0?(u(),v("div",Ae,[l("div",Se,[n[4]||(n[4]=l("div",{class:"agents-title"},null,-1)),l("div",be,[o(s(ce),{value:M.value,"onUpdate:value":[n[1]||(n[1]=a=>M.value=a),g],options:X.value,placeholder:s(t)("Sort by"),style:{width:"150px"}},null,8,["value","options","placeholder"])])]),l("div",Ne,[(u(!0),v(le,null,oe(p.value,a=>(u(),v("div",{key:a.name,class:"agent-card"},[l("div",{class:"agent-icon",onClick:m=>j(a)},[a.icon?(u(),U(s(S),{key:0,icon:a.icon,width:48,height:48,style:ue({color:a.color||"#6b7280"})},null,8,["icon","style"])):(u(),v("div",Pe,[o(s(z),{size:"48"},{default:c(()=>[o(s(S),{icon:"hugeicons:robotic"})]),_:1})]))],8,Me),l("div",xe,[l("div",ze,[l("div",$e,[l("h3",{onClick:m=>j(a),class:"clickable-title"},d(a.title||a.agent_name||a.name),9,Te),a.agent_name?(u(),v("div",je,d(a.agent_name),1)):C("",!0)])]),a.description?(u(),v("div",Be,d(W(a.description,80)),1)):C("",!0)]),l("div",Fe,[o(s($),{type:"default",onClick:m=>j(a)},{default:c(()=>[A(d(s(t)("View Details")),1)]),_:1},8,["onClick"]),Y(a.agent_name||a.name)?(u(),U(s($),{key:0,type:"warning",onClick:m=>E(a)},{default:c(()=>[A(d(s(t)("Installed")),1)]),_:1},8,["onClick"])):(u(),U(s($),{key:1,type:"primary",onClick:m=>E(a)},{default:c(()=>[A(d(s(t)("Install")),1)]),_:1},8,["onClick"]))])]))),128))]),l("div",Le,[o(s(de),{page:_.value,"onUpdate:page":[n[2]||(n[2]=a=>_.value=a),g],"page-count":G.value,size:"large","show-size-picker":"","page-sizes":[20,50,100],"page-size":y.value,"onUpdate:pageSize":H},null,8,["page","page-count","page-size"])])])):C("",!0),f.value?(u(),v("div",Ue,[o(s(ge),{size:"large"},{description:c(()=>[A(d(s(t)("Loading agents...")),1)]),_:1})])):C("",!0),!f.value&&p.value.length===0?(u(),v("div",Ve,[o(s(ve),{description:s(t)("No agents found")},{icon:c(()=>[o(s(z),null,{default:c(()=>[o(s(S),{icon:"hugeicons:robotic"})]),_:1})]),_:1},8,["description"])])):C("",!0)]),o(_e,{modelValue:k.value,"onUpdate:modelValue":n[3]||(n[3]=a=>k.value=a),progress:w.value,message:h.value,status:x.value,installing:P.value,title:s(t)("Installing Agent")},null,8,["modelValue","progress","message","status","installing","title"])]))}});const Ke=me(Ee,[["__scopeId","data-v-4a3804b2"]]);export{Ke as default};
|