import{ho as e,mo as t,po as n}from"./app-server-manager-signals-Yn0WSnoY.js";import{lt as r}from"./vscode-api-DjORcpSo.js";import{t as i}from"./useQueries-CXzlLQEV.js";import{c as a,m as o}from"./apps-queries-D95oCTjw.js";import{r as s}from"./plugin-detail-queries-QOeY335-.js";var c=`.agents/plugins/marketplace.json`;function l({directoryApps:e,pluginApps:t}){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>n.get(e.id)).filter(e=>e!=null)}function u(e,t,n){return!d(e,t)||n.type!==`local`?null:n.path}function d(r,i){return r==null||i==null?!1:t(i)===t(n(e(r),c))}function f({installedSkills:e,pluginSkills:t}){let n=p(e),r=[],i=[];for(let e of t){let t=m(e,n);if(t!=null){r.push(t);continue}i.push(e)}return{installedSkills:r,unavailableSkills:i}}function p(e){let t=new Map,n=new Map,r=new Map;for(let{skill:i}of e){r.set(i.path,i),n.set(i.name,i);let e=h(i.name),a=t.get(e);if(a==null){t.set(e,[i]);continue}a.push(i)}return{byComparableKey:t,byName:n,byPath:r}}function m(e,t){let n=(e.path==null?void 0:t.byPath.get(e.path))??t.byName.get(e.name);if(n!=null)return n;let r=t.byComparableKey.get(h(e.name));return r?.length===1?r[0]:null}function h(e){return(e??``).trim().toLowerCase().split(`:`).map(e=>e.replace(/[\s_-]+/g,``)).join(`:`)}var g=r(),_=`DISABLED_BY_ADMIN`,v=`DISABLED_BY_ADMIN`;function y(e){return e===v}function b(e){return y(e?.availability)}function x(e){let t=(0,g.c)(14),{hostId:n,pluginApps:r,marketplacePath:o,pluginName:c,remoteMarketplaceName:l}=e,u=r==null&&(o!=null||l!=null)&&c!=null,d=o??null,f=c??null,p=l??null,m;t[0]!==n||t[1]!==u||t[2]!==d||t[3]!==f||t[4]!==p?(m={hostId:n,marketplacePath:d,pluginName:f,remoteMarketplaceName:p,enabled:u},t[0]=n,t[1]=u,t[2]=d,t[3]=f,t[4]=p,t[5]=m):m=t[5];let{isLoading:h,plugin:v}=s(m),y=r??v?.apps??[],b=Array.from(new Set(y.map(T).filter(w))),x=b.length>0,E;t[6]!==n||t[7]!==x?(E={enabled:x,hostId:n},t[6]=n,t[7]=x,t[8]=E):E=t[8];let{data:D,isLoading:O,loadError:k}=a(E),A=D===void 0?[]:D,j=i({queries:b.map(C)}),M=!0,N=0,P={};for(let[e,t]of b.entries()){let n=j[e],r=!O&&k==null&&!A.some(e=>e.id===t),i=null;n?.data?.status===_?i=`disabled-by-admin`:(r||n!=null&&!n.isPending&&n.error==null&&n.data==null)&&(i=`connector-unavailable`),P[t]=i,i!=null&&(N+=1),i!==`disabled-by-admin`&&(M=!1)}let F=b.length>0&&N===b.length?M?`disabled-by-admin`:`connector-unavailable`:null,I;return t[9]!==j||t[10]!==O||t[11]!==h||t[12]!==u?(I=u&&h||O||j.some(S),t[9]=j,t[10]=O,t[11]=h,t[12]=u,t[13]=I):I=t[13],{blockedReasonsByConnectorId:P,isLoading:I,blockedReason:F}}function S(e){return e.isPending}function C(e){return o(e)}function w(e){return e.length>0}function T(e){return e.id}export{u as a,f as i,x as n,d as o,l as r,b as t};
//# sourceMappingURL=check-plugin-availability-CrPVurZq.js.map