@decocms/mesh 1.0.0-alpha.31 → 1.0.0-alpha.32
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/dist/client/assets/{alert-dialog-lT7fjsnS.js → alert-dialog-CCDQTgck.js} +1 -1
- package/dist/client/assets/{auth-B4DV4YJb.js → auth-DcsMEwUL.js} +1 -1
- package/dist/client/assets/{auth-catchall-BXXli3-E.js → auth-catchall-CcVurtOz.js} +1 -1
- package/dist/client/assets/{avatar-DrbrX3Fb.js → avatar-4ymdPXa_.js} +1 -1
- package/dist/client/assets/{badge-Sw-5Fjm_.js → badge-M2zkAPfT.js} +1 -1
- package/dist/client/assets/{button-De8TtfIc.js → button-DpN85Po0.js} +1 -1
- package/dist/client/assets/{card-Clgs1Ler.js → card-CjmS8q7G.js} +1 -1
- package/dist/client/assets/{checkbox-BZTG8MjG.js → checkbox-DWHTP51a.js} +1 -1
- package/dist/client/assets/{circle-alert-Bo6PdNJA.js → circle-alert-nIYjC1xl.js} +1 -1
- package/dist/client/assets/{collection-detail-bCm7IhzQ.js → collection-detail-BEA961Ga.js} +1 -1
- package/dist/client/assets/{collection-display-button-CANVxM78.js → collection-display-button-Cq_29P0W.js} +1 -1
- package/dist/client/assets/{collection-header-DWpT3ZvE.js → collection-header-CP7DLL6n.js} +1 -1
- package/dist/client/assets/{collection-page-BDYpmZx2.js → collection-page-C1jzPNDj.js} +1 -1
- package/dist/client/assets/{collection-search-7dvS8CPU.js → collection-search-CrkK01Ci.js} +1 -1
- package/dist/client/assets/{collection-table-wrapper-DFImlrAn.js → collection-table-wrapper-DtI6Q7NT.js} +1 -1
- package/dist/client/assets/{connection-card-Dgd2qOAx.js → connection-card-CvYHrR5S.js} +1 -1
- package/dist/client/assets/{connection-detail-B5XIo4jJ.js → connection-detail-8UBUICjc.js} +1 -1
- package/dist/client/assets/{connections-DgVq2Zi4.js → connections-B3SNLZTA.js} +1 -1
- package/dist/client/assets/{core-6UZH86ZU.js → core-C84vbQ6C.js} +1 -1
- package/dist/client/assets/{create-organization-dialog-DpintAfW.js → create-organization-dialog-DXWcXd5o.js} +1 -1
- package/dist/client/assets/{dialog-CcWkQ3-q.js → dialog-CfKieCBd.js} +1 -1
- package/dist/client/assets/{dropdown-menu-BMBTO1aI.js → dropdown-menu-Bvf4p8xE.js} +1 -1
- package/dist/client/assets/{empty-state-WuOT2hFn.js → empty-state-jtBjSgAJ.js} +1 -1
- package/dist/client/assets/{error-boundary-Sj1-czrQ.js → error-boundary-BjLQDRan.js} +1 -1
- package/dist/client/assets/{extract-connection-data-q7cQAIMM.js → extract-connection-data-CbCjXz3B.js} +1 -1
- package/dist/client/assets/{form-CTTDgzck.js → form-C-tSv2Q6.js} +1 -1
- package/dist/client/assets/{gateway-detail-DrTM5RUx.js → gateway-detail-ho3nacsQ.js} +1 -1
- package/dist/client/assets/{gateways-C0TCQRt5.js → gateways-BMuRXxz2.js} +1 -1
- package/dist/client/assets/{home-Dy-_EeTf.js → home-MLX9b5zd.js} +1 -1
- package/dist/client/assets/{icon-Dk9j-Z4d.js → icon-CBAJ1FOz.js} +1 -1
- package/dist/client/assets/{index-Dss36SHE.js → index-BHlakCJ5.js} +1 -1
- package/dist/client/assets/{index-BSuuYE7a.js → index-DV_-45hJ.js} +1 -1
- package/dist/client/assets/{index-GY3GXADp.js → index-DysuQWmq.js} +1 -1
- package/dist/client/assets/{index-DIXLDBVl.js → index-WOQ13cP6.js} +3 -3
- package/dist/client/assets/{input-ByJBGfq3.js → input-DRMFvIcp.js} +1 -1
- package/dist/client/assets/json-CNPNTT1T.js +1 -0
- package/dist/client/assets/{layout-DRBUzMK7.js → layout-C7PMXMWr.js} +1 -1
- package/dist/client/assets/{lazy-highlighter-BZ3JTPPT.js → lazy-highlighter-lg0C_alN.js} +1 -1
- package/dist/client/assets/{localstorage-keys-CrXjwcSZ.js → localstorage-keys-D9JCFoUA.js} +1 -1
- package/dist/client/assets/{login-baVguqcM.js → login-BBdlWaUa.js} +1 -1
- package/dist/client/assets/{mcp-oauth-Chn8Vl6o.js → mcp-oauth-CF0djzC4.js} +1 -1
- package/dist/client/assets/{members-BL6-e_ID.js → members-D_0pxXiL.js} +1 -1
- package/dist/client/assets/{monitoring-DSGI33MK.js → monitoring-dAXFetG3.js} +1 -1
- package/dist/client/assets/{oauth-callback-BxWJgxm-.js → oauth-callback-VTrUtdoZ.js} +1 -1
- package/dist/client/assets/{page-D0r-m9VX.js → page-BR8BRWlW.js} +1 -1
- package/dist/client/assets/{popover-C_H6Z3YS.js → popover-DIDe1tAI.js} +1 -1
- package/dist/client/assets/prism-light-DJ9E6c7l.js +1 -0
- package/dist/client/assets/{resource-tabs-Dptn276z.js → resource-tabs-e5WwAHct.js} +1 -1
- package/dist/client/assets/{schema-iWDGcZfv.js → schema-DaJ1vGek.js} +1 -1
- package/dist/client/assets/{select-KKeuY_8A.js → select-DzEOHgSq.js} +1 -1
- package/dist/client/assets/{settings-DOQRUeGN.js → settings-DCv43rTD.js} +1 -1
- package/dist/client/assets/{shell-layout-DxFvs5RE.js → shell-layout-CE6a48bs.js} +4 -4
- package/dist/client/assets/{spinner-C5mTiECQ.js → spinner-DCnW_hcw.js} +1 -1
- package/dist/client/assets/{store-app-detail-D8K1UJ66.js → store-app-detail-Boq9PC3_.js} +1 -1
- package/dist/client/assets/{store-BsHJOv3r.js → store-w0RourHd.js} +1 -1
- package/dist/client/assets/{switch-BN3gNP3v.js → switch-P43q-fGo.js} +1 -1
- package/dist/client/assets/{textarea-DYrEFGVo.js → textarea-BNSwm2Uw.js} +1 -1
- package/dist/client/assets/{tool-set-selector-BU0xXwDF.js → tool-set-selector-M0YnbcFP.js} +1 -1
- package/dist/client/assets/{tooltip-ZzCYSPeH.js → tooltip-D5O925Gp.js} +1 -1
- package/dist/client/assets/{types-DndJPAWa.js → types-8p_ZLQNY.js} +3 -3
- package/dist/client/assets/{upload-CsXE0eHm.js → upload-RqBSTCRA.js} +1 -1
- package/dist/client/assets/{use-binding-CIVQUW9t.js → use-binding-BxKMNjmS.js} +1 -1
- package/dist/client/assets/{use-connection-CgusccPZ.js → use-connection-B5VryFm7.js} +1 -1
- package/dist/client/assets/{use-gateway-iwW9W997.js → use-gateway-Bcl96GTS.js} +1 -1
- package/dist/client/assets/{use-list-state-B2svGg01.js → use-list-state-BvxCVBXg.js} +1 -1
- package/dist/client/assets/{use-mcp-ByPLvFZj.js → use-mcp-BXroRbt9.js} +1 -1
- package/dist/client/assets/{use-members-dzf6tzsH.js → use-members--7RkMxwe.js} +1 -1
- package/dist/client/assets/{use-mobile-BqnROvZt.js → use-mobile-D09YPI1X.js} +1 -1
- package/dist/client/assets/{use-organization-settings-DYa2j-qu.js → use-organization-settings-Ctjt5GGI.js} +1 -1
- package/dist/client/assets/{use-tool-call-CFjw03Kh.js → use-tool-call-DMT2JJQo.js} +1 -1
- package/dist/client/assets/useQuery-XS-ILlMf.js +1 -0
- package/dist/client/assets/utils-E9aiNDpO.js +1 -0
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/dist/client/assets/json-B2EH3aa6.js +0 -1
- package/dist/client/assets/prism-light-CKU-zSUS.js +0 -1
- package/dist/client/assets/useQuery-B5H-PpIX.js +0 -1
- package/dist/client/assets/utils-Ny57I_y6.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as C,a1 as L}from"./index-
|
|
1
|
+
import{c as C,a1 as L}from"./index-WOQ13cP6.js";import{u as Q}from"./useQuery-XS-ILlMf.js";import{u as $}from"./button-DpN85Po0.js";function q(e){try{return JSON.parse(e)}catch{return}}function O(e,n){const t=localStorage.getItem(e),s=t?q(t):void 0,a=typeof n=="function"?n(s):s??n;if(s===void 0||a!==s)try{const o=JSON.stringify(a);localStorage.setItem(e,o)}catch{}return a}function E(e,n){const t=C.c(25),s=L();let a;t[0]!==e?(a=["localStorage",e],t[0]=e,t[1]=a):a=t[1];const o=a;let r,i;t[2]!==n||t[3]!==e?(r=()=>O(e,n),i=()=>O(e,n),t[2]=n,t[3]=e,t[4]=r,t[5]=i):(r=t[4],i=t[5]);let m;t[6]!==o||t[7]!==r||t[8]!==i?(m={queryKey:o,queryFn:r,initialData:i,staleTime:1/0,gcTime:1/0},t[6]=o,t[7]=r,t[8]=i,t[9]=m):m=t[9];const{data:I}=Q(m);let l;t[10]!==e?(l=async c=>{const y=JSON.stringify(c);return localStorage.setItem(e,y),c},t[10]=e,t[11]=l):l=t[11];let u;t[12]!==s||t[13]!==o?(u=c=>{s.setQueryData(o,c)},t[12]=s,t[13]=o,t[14]=u):u=t[14];let f;t[15]!==l||t[16]!==u?(f={mutationFn:l,onSuccess:u},t[15]=l,t[16]=u,t[17]=f):f=t[17];const h=$(f);let g;t[18]!==h||t[19]!==s||t[20]!==o?(g=c=>{const y=s.getQueryData(o),x=typeof c=="function"?c(y):c;h.mutate(x)},t[18]=h,t[19]=s,t[20]=o,t[21]=g):g=t[21];const S=g,p=I;let d;return t[22]!==S||t[23]!==p?(d=[p,S],t[22]=S,t[23]=p,t[24]=d):d=t[24],d}const F={decoChatOpen:()=>"mesh:decochat:open",threadManagerState:e=>`mesh:thread-manager-state:${e}`,chatSelectedModel:e=>`mesh:chat:selectedModel:${e}`,decoChatPanelWidth:()=>"mesh:decochat:panel-width",sidebarOpen:()=>"mesh:sidebar-open",selectedRegistry:e=>`mesh:store:selected-registry:${e}`,orgHomeQuickstart:e=>`mesh:org-home:quickstart:${e}`};export{F as L,E as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as k,r as p,j as e,a as j,b as z,S as L,N as R,c as U}from"./index-
|
|
1
|
+
import{u as k,r as p,j as e,a as j,b as z,S as L,N as R,c as U}from"./index-WOQ13cP6.js";import{u as T,B as P}from"./button-DpN85Po0.js";import{I as E}from"./input-DRMFvIcp.js";import{c as b}from"./utils-E9aiNDpO.js";function B({redirectUrl:r}){const{emailAndPassword:t}=k(),[s,d]=p.useState(""),[o,u]=p.useState(""),[l,v]=p.useState(""),[i,N]=p.useState(()=>globalThis.localStorage?.getItem("hasLoggedIn")!=="true"),[m,h]=p.useState(""),g=T({mutationFn:async({email:a,password:n,name:C})=>{try{if(i){const c=await j.signUp.email({email:a,password:n,name:C||""});if(c.error)throw new Error(c.error.message||"Sign up failed");return c}else{const c=await j.signIn.email({email:a,password:n});if(c.error)throw new Error(c.error.message||"Sign in failed");return c}}catch(c){throw c instanceof Error?c:new Error("Authentication failed")}},onSuccess:()=>{globalThis.localStorage?.setItem("hasLoggedIn","true"),r&&(window.location.href=r)}}),y=a=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a),x=()=>{s.trim()&&!y(s)&&h("Invalid email address")},S=a=>{if(a.preventDefault(),!y(s)){h("Invalid email address");return}g.mutate({email:s,password:o,name:l})},_=a=>n=>{a(n.target.value),I&&g.reset(),a===d&&m&&h("")},f=g.isPending,I=g.error,w=i?s.trim()&&o.trim()&&l.trim():s.trim()&&o.trim(),A=a=>{if(!a)return null;const n=a.message.toLowerCase();return n.includes("unauthorized")||n.includes("401")?"Invalid email or password. Please try again.":n.includes("already exists")||n.includes("409")?"An account with this email already exists. Try signing in instead.":n.includes("network")||n.includes("fetch")?"Network error. Please check your connection and try again.":n.includes("rate limit")||n.includes("429")?"Too many attempts. Please wait a moment and try again.":a.message||"An error occurred. Please try again."};return e.jsxs("div",{className:"mx-auto w-full min-w-[400px] max-w-md grid gap-6 bg-card p-10 border border-primary-foreground/20",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("img",{src:"/logos/deco logo.svg",alt:"Deco",className:"h-12 w-12"})}),e.jsx("div",{className:"text-center space-y-1",children:e.jsx("p",{className:"text-sm text-foreground/70",children:i?"Create your account":"Login or signup below"})}),I&&e.jsx("div",{className:"rounded-xl bg-destructive/10 p-3 text-sm text-destructive text-center",children:A(I)}),t.enabled&&e.jsxs("form",{onSubmit:S,className:"grid gap-4",children:[e.jsx("div",{className:b("overflow-hidden transition-all duration-300 ease-[cubic-bezier(0.075,0.82,0.165,1)]",i?"max-h-[200px] opacity-100 translate-y-0":"max-h-0 opacity-0 -translate-y-2"),children:e.jsxs("div",{className:b("p-1",!i&&"pointer-events-none"),children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"Name"}),e.jsx(E,{type:"text",placeholder:"Your name",value:l,onChange:_(v),required:!0,disabled:f||!i,"aria-hidden":!i})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"Email"}),e.jsx(E,{type:"email",placeholder:"you@example.com",value:s,onChange:_(d),onBlur:x,required:!0,disabled:f,"aria-invalid":!!m}),m&&e.jsx("p",{className:"text-xs text-destructive mt-1.5",children:m})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"Password"}),e.jsx(E,{type:"password",placeholder:"••••••••",value:o,onChange:_(u),required:!0,disabled:f})]}),e.jsx("div",{className:b("overflow-hidden transition-all duration-300 ease-[cubic-bezier(0.075,0.82,0.165,1)]",w?"max-h-[100px] opacity-100 translate-y-0":"max-h-0 opacity-0 -translate-y-2"),children:e.jsx("div",{className:b("p-1",!w&&"pointer-events-none"),children:e.jsx(P,{type:"submit",disabled:f||!w,className:b("w-full font-semibold"),size:"lg","aria-hidden":!w,children:f?i?"Creating account...":"Signing in...":"Continue"})})})]}),e.jsx("div",{className:"text-center",children:e.jsx(P,{type:"button",variant:"link",onClick:()=>{N(!i),v(""),h(""),g.reset()},disabled:f,className:"text-sm text-muted-foreground hover:text-foreground",children:i?"Already have an account? Sign in":"Don't have an account? Sign up"})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground pt-4",children:[e.jsx("a",{href:"https://www.decocms.com/terms-of-use",target:"_blank",rel:"noopener noreferrer",className:"hover:text-foreground transition-colors",children:"Terms of Service"}),e.jsx("a",{href:"https://www.decocms.com/privacy-policy",target:"_blank",rel:"noopener noreferrer",className:"hover:text-foreground transition-colors",children:"Privacy Policy"})]})]})}function M(r){if(!r.client_id||r.response_type!=="code")return null;const t=new URLSearchParams;return r.client_id&&t.set("client_id",r.client_id),r.redirect_uri&&t.set("redirect_uri",r.redirect_uri),r.response_type&&t.set("response_type",r.response_type),r.state&&t.set("state",r.state),r.scope&&t.set("scope",r.scope),r.code_challenge&&t.set("code_challenge",r.code_challenge),r.code_challenge_method&&t.set("code_challenge_method",r.code_challenge_method),`/api/auth/mcp/authorize?${t.toString()}`}function q(r){const t=U.c(5),{callbackURL:s,providerId:d}=r;let o,u;t[0]!==s||t[1]!==d?(o=()=>{(async()=>await j.signIn.sso({providerId:d,callbackURL:s}))()},u=[d,s],t[0]=s,t[1]=d,t[2]=o,t[3]=u):(o=t[2],u=t[3]),p.useEffect(o,u);let l;return t[4]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(L,{}),t[4]=l):l=t[4],l}function Y(){const r=j.useSession(),t=z({from:"/login"}),{next:s="/",client_id:d,redirect_uri:o,response_type:u,state:l,scope:v,code_challenge:i,code_challenge_method:N}=t,{sso:m,emailAndPassword:h,magicLink:g,socialProviders:y}=k(),x=M({client_id:d,redirect_uri:o,response_type:u,state:l,scope:v,code_challenge:i,code_challenge_method:N}),S=x||s;return r.data?x?(window.location.href=x,e.jsx(L,{})):e.jsx(R,{to:s}):m.enabled?e.jsx(q,{callbackURL:S,providerId:m.providerId}):h.enabled||g.enabled||y.enabled?e.jsxs("main",{className:"relative flex min-h-screen items-center justify-center bg-gradient-to-br from-primary to-primary/75 p-4",children:[e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle, var(--primary-foreground) 1px, transparent 1px)",backgroundSize:"16px 16px",opacity:.15}}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-screen h-px bg-primary-foreground/15"}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 w-screen h-px bg-primary-foreground/15"}),e.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-px h-screen bg-primary-foreground/15"}),e.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 w-px h-screen bg-primary-foreground/15"}),e.jsx(B,{redirectUrl:x})]})]}):e.jsx("div",{children:"No login options available"})}export{Y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as I,q as V,r as P,m as T}from"./auth-
|
|
1
|
+
import{p as I,q as V,r as P,m as T}from"./auth-DcsMEwUL.js";function S(r){let e=0;for(let t=0;t<r.length;t++){const o=r.charCodeAt(t);e=(e<<5)-e+o,e=e&e}return Math.abs(e).toString(16)}const U=new Map,A="mcp:oauth:callback:";class ${serverUrl;_clientMetadata;_redirectUrl;_state=null;_codeVerifier=null;_clientInfo=null;_tokens=null;constructor(e){this.serverUrl=e.serverUrl,this._redirectUrl=e.callbackUrl??`${window.location.origin}/oauth/callback`,this._clientMetadata={redirect_uris:[this._redirectUrl],token_endpoint_auth_method:"none",grant_types:["authorization_code","refresh_token"],response_types:["code"],client_name:e.clientName??"@decocms/mesh MCP client",scope:"mcp"},U.set(S(this.serverUrl),this)}get redirectUrl(){return this._redirectUrl}get clientMetadata(){return this._clientMetadata}state(){return this._state||(this._state=crypto.randomUUID()),this._state}getStoredState(){return this._state}clientInformation(){return this._clientInfo??void 0}saveClientInformation(e){this._clientInfo=e}tokens(){return this._tokens??void 0}saveTokens(e){this._tokens=e}redirectToAuthorization(e){const l=window.screenX+(window.outerWidth-600)/2,i=window.screenY+(window.outerHeight-700)/2;window.open(e.toString(),"mcp-oauth",`width=600,height=700,left=${l},top=${i},popup=yes`)}saveCodeVerifier(e){this._codeVerifier=e}codeVerifier(){if(!this._codeVerifier)throw new Error("Code verifier not found");return this._codeVerifier}invalidateCredentials(){this._clientInfo=null,this._tokens=null,this._codeVerifier=null,this._state=null}getServerUrl(){return this.serverUrl}cleanup(){U.delete(S(this.serverUrl))}}async function R(r){const e=new URL(`/mcp/${r.connectionId}`,window.location.origin),t=new $({serverUrl:e.href,clientName:r.clientName,clientUri:r.clientUri,callbackUrl:r.callbackUrl});try{const o=new Promise((c,n)=>{const u=r.timeout||12e4;let w,h=!1;const b=t.state(),p=`${A}${b}`,a=()=>{if(!h){h=!0,window.removeEventListener("message",g),window.removeEventListener("storage",_),clearTimeout(w);try{localStorage.removeItem(p)}catch{}}},m=async s=>{if(h)return;if(!s.success){a(),n(new Error(s.error||"OAuth authentication failed"));return}const{code:d,state:C}=s;if(!d){a(),n(new Error("Missing authorization code"));return}if(t.getStoredState()!==C){a(),n(new Error("OAuth state mismatch - possible CSRF attack"));return}try{const v=(await I(e))?.authorization_servers?.[0]||e,M=await V(v),y=t.clientInformation();if(!y){a(),n(new Error("Client information not found"));return}const O=t.codeVerifier(),E=await P(v,{metadata:M,clientInformation:y,authorizationCode:d,codeVerifier:O,redirectUri:t.redirectUrl,resource:new URL(e)});a(),c(E)}catch(k){a(),n(k)}},g=async s=>{s.origin===window.location.origin&&s.data?.type==="mcp:oauth:callback"&&await m(s.data)},_=async s=>{if(!(s.key!==p||!s.newValue))try{const d=JSON.parse(s.newValue);await m(d)}catch{}};window.addEventListener("message",g),window.addEventListener("storage",_),w=setTimeout(()=>{a(),n(new Error("OAuth authentication timeout"))},u)});return await T(t,{serverUrl:e})==="REDIRECT"?{token:(await o).access_token,error:null}:{token:t.tokens()?.access_token||null,error:null}}catch(o){return{token:null,error:o instanceof Error?o.message:String(o)}}finally{t.cleanup()}}function f(r,e){if(window.opener&&!window.opener.closed)return window.opener.postMessage(r,window.location.origin),!0;if(e)try{const t=`${A}${e}`;return localStorage.setItem(t,JSON.stringify(r)),!0}catch{}return!1}async function N(){const r=new URLSearchParams(window.location.search),e=r.get("code");let t=r.get("state");const o=r.get("error"),l=r.get("error_description");let i=t;if(t)try{const n=atob(t),u=JSON.parse(n);u.clientState&&(i=u.clientState)}catch{}if(o){const n=l||o;return f({type:"mcp:oauth:callback",success:!1,error:n},i),{success:!1,error:n}}if(!e||!t){const n="Missing code or state parameter";return f({type:"mcp:oauth:callback",success:!1,error:n},i),{success:!1,error:n}}return t=i||t,f({type:"mcp:oauth:callback",success:!0,code:e,state:t},t)?{success:!0}:{success:!1,error:"Parent window not available"}}async function D({url:r,token:e}){try{const t=new Headers;t.set("Content-Type","application/json"),t.set("Accept","application/json, text/event-stream");const o=await fetch(r,{method:"POST",headers:t,body:JSON.stringify({jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-06-18",capabilities:{},clientInfo:{name:"@decocms/mesh MCP client",version:"1.0.0"}}})});if(o.ok)return{isAuthenticated:!0,supportsOAuth:!0};const i=!!o.headers.get("WWW-Authenticate");let c;try{const n=await o.json();c=n.error||n.message}catch{}return{isAuthenticated:!1,supportsOAuth:i,error:c||`HTTP ${o.status}`}}catch(t){return console.error("[isConnectionAuthenticated] Error:",t),{isAuthenticated:!1,supportsOAuth:!1,error:t.message}}}export{R as a,N as h,D as i};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a2 as ae,a as X,ap as us,aE as Je,aF as As,aG as Os,aq as fe,r as V,a1 as Ze,as as Ns,ar as Rs,a6 as J,j as t,c as me,a3 as _s}from"./index-DIXLDBVl.js";import{C as Ps}from"./collection-header-DWpT3ZvE.js";import{C as ss}from"./collection-page-BDYpmZx2.js";import{C as Ye}from"./collection-search-7dvS8CPU.js";import{C as Ls}from"./collection-table-wrapper-DFImlrAn.js";import{T as Ms}from"./tool-set-selector-BU0xXwDF.js";import{b as zs,c as ks}from"./use-connection-CgusccPZ.js";import{u as os}from"./use-members-dzf6tzsH.js";import{W as Ds}from"./well-known-mcp-Dg77mwx9.js";import{u as ve,d as ye,b as Ee,a as Ie,T as Se}from"./tooltip-ZzCYSPeH.js";import{u as ys}from"./useQuery-B5H-PpIX.js";import{A as Ce}from"./avatar-DrbrX3Fb.js";import{B as Te}from"./badge-Sw-5Fjm_.js";import{u as he,B as ee}from"./button-De8TtfIc.js";import{C as Bs}from"./checkbox-BZTG8MjG.js";import{f as we,a as Ae,b as Oe,c as Re,d as _e,e as Pe,A as Le,g as Me}from"./alert-dialog-lT7fjsnS.js";import{d as Es,e as Is,c as Ss,D as Gs,a as Us,f as Vs}from"./dialog-CcWkQ3-q.js";import{b as as,D as cs,a as ds,c as Qe,e as Fs,f as $s,g as Ks,d as Qs}from"./dropdown-menu-BMBTO1aI.js";import{I as se}from"./icon-Dk9j-Z4d.js";import{I as qs}from"./input-ByJBGfq3.js";import{S as Ve}from"./switch-BN3gNP3v.js";import{c as ie}from"./utils-Ny57I_y6.js";import{E as Xe}from"./empty-state-WuOT2hFn.js";import{E as Zs}from"./error-boundary-Sj1-czrQ.js";import{a as Ys,F as fs,b as hs,c as Ws,d as gs,f as xs}from"./form-CTTDgzck.js";import{c as ts,a as ns,S as rs,b as is,d as ls}from"./select-KKeuY_8A.js";import{T as Hs}from"./textarea-DYrEFGVo.js";import{C as ps}from"./card-Clgs1Ler.js";import"./collection-display-button-CANVxM78.js";const Ts=[{name:"ORGANIZATION_CREATE",description:"Create a new organization",category:"Organizations"},{name:"ORGANIZATION_LIST",description:"List organizations",category:"Organizations"},{name:"ORGANIZATION_GET",description:"View organization details",category:"Organizations"},{name:"ORGANIZATION_UPDATE",description:"Update organization",category:"Organizations"},{name:"ORGANIZATION_DELETE",description:"Delete organization",category:"Organizations",dangerous:!0},{name:"ORGANIZATION_SETTINGS_GET",description:"View organization settings",category:"Organizations"},{name:"ORGANIZATION_SETTINGS_UPDATE",description:"Update organization settings",category:"Organizations"},{name:"ORGANIZATION_MEMBER_ADD",description:"Add members",category:"Organizations"},{name:"ORGANIZATION_MEMBER_REMOVE",description:"Remove members",category:"Organizations",dangerous:!0},{name:"ORGANIZATION_MEMBER_LIST",description:"List members",category:"Organizations"},{name:"ORGANIZATION_MEMBER_UPDATE_ROLE",description:"Update member roles",category:"Organizations"},{name:"COLLECTION_CONNECTIONS_CREATE",description:"Create connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_LIST",description:"List connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_GET",description:"View connection details",category:"Connections"},{name:"COLLECTION_CONNECTIONS_UPDATE",description:"Update connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_DELETE",description:"Delete connections",category:"Connections",dangerous:!0},{name:"CONNECTION_TEST",description:"Test connections",category:"Connections"},{name:"DATABASES_RUN_SQL",description:"Run SQL queries",category:"Connections",dangerous:!0},{name:"COLLECTION_GATEWAY_CREATE",description:"Create gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_LIST",description:"List gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_GET",description:"View gateway details",category:"Gateways"},{name:"COLLECTION_GATEWAY_UPDATE",description:"Update gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_DELETE",description:"Delete gateways",category:"Gateways",dangerous:!0},{name:"MONITORING_LOGS_LIST",description:"List monitoring logs",category:"Monitoring"},{name:"MONITORING_STATS",description:"View monitoring statistics",category:"Monitoring"},{name:"API_KEY_CREATE",description:"Create API key",category:"API Keys"},{name:"API_KEY_LIST",description:"List API keys",category:"API Keys"},{name:"API_KEY_UPDATE",description:"Update API key",category:"API Keys"},{name:"API_KEY_DELETE",description:"Delete API key",category:"API Keys",dangerous:!0},{name:"EVENT_PUBLISH",description:"Publish events",category:"Event Bus"},{name:"EVENT_SUBSCRIBE",description:"Subscribe to events",category:"Event Bus"},{name:"EVENT_UNSUBSCRIBE",description:"Unsubscribe from events",category:"Event Bus"},{name:"EVENT_CANCEL",description:"Cancel recurring events",category:"Event Bus"},{name:"EVENT_ACK",description:"Acknowledge event delivery",category:"Event Bus"},{name:"EVENT_SUBSCRIPTION_LIST",description:"List event subscriptions",category:"Event Bus"},{name:"EVENT_SYNC_SUBSCRIPTIONS",description:"Sync subscriptions to desired state",category:"Event Bus"}],Js={ORGANIZATION_CREATE:"Create organization",ORGANIZATION_LIST:"List organizations",ORGANIZATION_GET:"View organization details",ORGANIZATION_UPDATE:"Update organization",ORGANIZATION_DELETE:"Delete organization",ORGANIZATION_SETTINGS_GET:"View organization settings",ORGANIZATION_SETTINGS_UPDATE:"Update organization settings",ORGANIZATION_MEMBER_LIST:"List members",ORGANIZATION_MEMBER_ADD:"Add members",ORGANIZATION_MEMBER_REMOVE:"Remove members",ORGANIZATION_MEMBER_UPDATE_ROLE:"Update member roles",COLLECTION_CONNECTIONS_LIST:"List connections",COLLECTION_CONNECTIONS_GET:"View connection details",COLLECTION_CONNECTIONS_CREATE:"Create connections",COLLECTION_CONNECTIONS_UPDATE:"Update connections",COLLECTION_CONNECTIONS_DELETE:"Delete connections",CONNECTION_TEST:"Test connections",DATABASES_RUN_SQL:"Run SQL queries",COLLECTION_GATEWAY_CREATE:"Create gateways",COLLECTION_GATEWAY_LIST:"List gateways",COLLECTION_GATEWAY_GET:"View gateway details",COLLECTION_GATEWAY_UPDATE:"Update gateways",COLLECTION_GATEWAY_DELETE:"Delete gateways",MONITORING_LOGS_LIST:"List monitoring logs",MONITORING_STATS:"View monitoring statistics",API_KEY_CREATE:"Create API key",API_KEY_LIST:"List API keys",API_KEY_UPDATE:"Update API key",API_KEY_DELETE:"Delete API key",EVENT_PUBLISH:"Publish events",EVENT_SUBSCRIBE:"Subscribe to events",EVENT_UNSUBSCRIBE:"Unsubscribe from events",EVENT_CANCEL:"Cancel recurring events",EVENT_ACK:"Acknowledge event delivery",EVENT_SUBSCRIPTION_LIST:"List event subscriptions",EVENT_SYNC_SUBSCRIPTIONS:"Sync subscriptions to desired state"};function Xs(){const s={Organizations:[],Connections:[],Gateways:[],Monitoring:[],"API Keys":[],"Event Bus":[]};for(const e of Ts)s[e.category]?.push(e);return s}function et(){return Ts.map(s=>({value:s.name,label:Js[s.name],dangerous:s.dangerous}))}const bs=[{value:"owner",label:"Owner",isBuiltin:!0},{value:"admin",label:"Admin",isBuiltin:!0},{value:"user",label:"User",isBuiltin:!0}];function st(s){return s.replace(/-/g," ")}function tt(s){if(!s)return{staticPermissions:[],allowsAllStaticPermissions:!1,connectionIds:[],allowsAllConnections:!1,toolNames:[],allowsAllTools:!1};const e=[];let n=!1;const l=[];let a=!1;const i=new Set;let h=!1;for(const[o,x]of Object.entries(s)){if(o===Ds.SELF){x.includes("*")?n=!0:e.push(...x);continue}if(o==="*"){if(a=!0,x.includes("*"))h=!0;else for(const y of x)i.add(y);continue}if(l.push(o),x.includes("*"))h=!0;else for(const y of x)i.add(y)}return{staticPermissions:e,allowsAllStaticPermissions:n,connectionIds:l,allowsAllConnections:a,toolNames:Array.from(i),allowsAllTools:h}}function ms(){const{locator:s}=ve(),{data:e,isLoading:n,error:l,refetch:a}=ys({queryKey:ae.organizationRoles(s),queryFn:async()=>{try{const o=await X.organization.listRoles();return o?.error?(console.error("[useOrganizationRoles] API error:",o.error),[]):o?.data??[]}catch(o){return console.error("[useOrganizationRoles] Fetch error:",o),[]}},staleTime:3e4}),i=bs.map(o=>({role:o.value,label:o.label,isBuiltin:o.isBuiltin}));if(e&&Array.isArray(e))for(const o of e){const x=o.role;if(!x||bs.some(j=>j.value===x))continue;const{staticPermissions:y,allowsAllStaticPermissions:f,connectionIds:w,allowsAllConnections:d,toolNames:I,allowsAllTools:u}=tt(o.permission);i.push({id:o.id,role:x,label:st(x),isBuiltin:!1,permission:o.permission??void 0,staticPermissionCount:f?-1:y.length,allowsAllStaticPermissions:f,connectionCount:d?-1:w.length,allowsAllConnections:d,toolCount:u?-1:I.length,allowsAllTools:u})}const h=i.filter(o=>!o.isBuiltin);return{roles:i,customRoles:h,builtinRoles:i.filter(o=>o.isBuiltin),isLoading:n,error:l,refetch:a}}const nt=us({role:us({id:fe().optional(),slug:fe().optional(),label:fe()}),allowAllStaticPermissions:Os(),staticPermissions:Je(fe()),toolSet:As(Je(fe())),memberIds:Je(fe())});function ws(s){return s?s.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2):"?"}const rt=[{role:"owner",label:"Owner",color:"bg-red-500"},{role:"admin",label:"Admin",color:"bg-blue-500"},{role:"user",label:"User",color:"bg-green-500"}],es=["bg-red-500","bg-orange-500","bg-amber-500","bg-yellow-500","bg-lime-500","bg-green-500","bg-emerald-500","bg-teal-500","bg-cyan-500","bg-sky-500","bg-blue-500","bg-indigo-500","bg-violet-500","bg-purple-500","bg-fuchsia-500","bg-pink-500","bg-rose-500"];function it(s){if(!s)return"bg-neutral-400";let e=0;for(let l=0;l<s.length;l++){const a=s.charCodeAt(l);e=(e<<5)-e+a,e=e&e}const n=Math.abs(e)%es.length;return es[n]??es[0]}function Fe(){return{role:{id:void 0,slug:void 0,label:""},allowAllStaticPermissions:!1,staticPermissions:[],toolSet:{},memberIds:[]}}function lt(s){const e=me.c(39),{allowAllStaticPermissions:n,staticPermissions:l,onAllowAllChange:a,onPermissionsChange:i,readOnly:h}=s,o=h===void 0?!1:h,[x,y]=V.useState(""),f=V.useDeferredValue(x);let w,d,I,u,j;if(e[0]!==n||e[1]!==f||e[2]!==a||e[3]!==i||e[4]!==o||e[5]!==x||e[6]!==l){const g=Xs(),c=et(),v=c.filter(E=>E.label.toLowerCase().includes(f.toLowerCase())),S=E=>{if(l.includes(E))i(l.filter(_=>_!==E));else{const _=[...l,E];_.length===c.length?(a(!0),i([])):i(_)}};I="flex flex-col h-full",e[12]!==x?(u=t.jsx("div",{className:"border-b border-border",children:t.jsx(Ye,{value:x,onChange:y,placeholder:"Search permissions...",className:"border-b-0"})}),e[12]=x,e[13]=u):u=e[13];const P=!o&&"hover:bg-muted/50 cursor-pointer";let T;e[14]!==P?(T=ie("flex items-center justify-between px-4 py-3 rounded-lg",P),e[14]=P,e[15]=T):T=e[15];let O;e[16]!==n||e[17]!==a||e[18]!==i||e[19]!==o?(O=()=>{if(o)return;a(!n),i([])},e[16]=n,e[17]=a,e[18]=i,e[19]=o,e[20]=O):O=e[20];let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx("span",{className:"text-sm font-medium",children:"All organization permissions"}),e[21]=A):A=e[21];let L;e[22]!==n||e[23]!==a||e[24]!==i||e[25]!==o?(L=t.jsx("div",{onClick:mt,children:o?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(Ve,{checked:n,disabled:o,onCheckedChange:E=>{o||(a(E),i([]))}})})}),t.jsx(Se,{children:t.jsx("p",{children:"Built-in role permissions cannot be changed"})})]})}):t.jsx(Ve,{checked:n,disabled:o,onCheckedChange:E=>{o||(a(E),i([]))}})}),e[22]=n,e[23]=a,e[24]=i,e[25]=o,e[26]=L):L=e[26],e[27]!==L||e[28]!==T||e[29]!==O?(j=t.jsx("div",{className:"border-b border-border",children:t.jsxs("div",{className:T,onClick:O,children:[A,L]})}),e[27]=L,e[28]=T,e[29]=O,e[30]=j):j=e[30],w="flex-1 overflow-auto",d=Object.entries(g).map(E=>{const[_,z]=E,N=v.filter(m=>z.some(M=>M.name===m.value));return N.length===0?null:t.jsxs("div",{className:"mb-6 last:mb-0",children:[t.jsx("h4",{className:"text-sm font-medium p-3 pb-1.5 text-muted-foreground/75",children:_}),t.jsx("div",{className:"space-y-1",children:N.map(m=>t.jsxs("div",{className:ie("flex items-center justify-between gap-3 px-4 py-3",!o&&"hover:bg-muted/50 cursor-pointer"),onClick:()=>{if(!o)if(n){a(!1);const M=c.map(dt);i(M.filter(U=>U!==m.value))}else S(m.value)},children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx("span",{className:"text-sm",children:m.label})}),t.jsx("div",{onClick:ct,children:o?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(Ve,{checked:n||l.includes(m.value),disabled:o,onCheckedChange:()=>{if(!o)if(n){a(!1);const M=c.map(at);i(M.filter(U=>U!==m.value))}else S(m.value)}})})}),t.jsx(Se,{children:t.jsx("p",{children:"Built-in role permissions cannot be changed"})})]})}):t.jsx(Ve,{checked:n||l.includes(m.value),disabled:o,onCheckedChange:()=>{if(!o)if(n){a(!1);const M=c.map(ot);i(M.filter(U=>U!==m.value))}else S(m.value)}})})]},m.value))})]},_)}),e[0]=n,e[1]=f,e[2]=a,e[3]=i,e[4]=o,e[5]=x,e[6]=l,e[7]=w,e[8]=d,e[9]=I,e[10]=u,e[11]=j}else w=e[7],d=e[8],I=e[9],u=e[10],j=e[11];let p;e[31]!==w||e[32]!==d?(p=t.jsx("div",{className:w,children:d}),e[31]=w,e[32]=d,e[33]=p):p=e[33];let C;return e[34]!==I||e[35]!==u||e[36]!==j||e[37]!==p?(C=t.jsxs("div",{className:I,children:[u,j,p]}),e[34]=I,e[35]=u,e[36]=j,e[37]=p,e[38]=C):C=e[38],C}function ot(s){return s.value}function at(s){return s.value}function ct(s){return s.stopPropagation()}function dt(s){return s.value}function mt(s){return s.stopPropagation()}function ut(s){const e=me.c(56),{open:n,onOpenChange:l,selectedMemberIds:a,onAddMembers:i}=s,[h,o]=V.useState(""),x=V.useDeferredValue(h);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[0]=y):y=e[0];const[f,w]=V.useState(y),{data:d}=os();let I,u,j,p,C,g,c,v,S,P,T;if(e[1]!==d?.data?.members||e[2]!==x||e[3]!==i||e[4]!==l||e[5]!==n||e[6]!==f||e[7]!==h||e[8]!==a){const M=d?.data?.members??[];let U;e[20]!==x?(U=D=>{const r=x.toLowerCase();return D.user?.name?.toLowerCase().includes(r)||D.user?.email?.toLowerCase().includes(r)},e[20]=x,e[21]=U):U=e[21];const te=M.filter(U),$=ft;let K;e[22]!==a?(K=D=>a.includes(D),e[22]=a,e[23]=K):K=e[23];const Q=K;let Y;e[24]!==f?(Y=D=>{f.includes(D)?w(f.filter(r=>r!==D)):w([...f,D])},e[24]=f,e[25]=Y):Y=e[25];const re=Y;let ne;e[26]!==i||e[27]!==l||e[28]!==f?(ne=()=>{i(f),w([]),l(!1)},e[26]=i,e[27]=l,e[28]=f,e[29]=ne):ne=e[29],j=ne,u=we,P=n,T=l,I=Ae,v="sm:max-w-md p-0 overflow-hidden",e[30]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsxs(Oe,{className:"px-6 pt-6",children:[t.jsx(Re,{children:"Add Members to Role"}),t.jsx(_e,{children:"Select members to add to this role."})]}),e[30]=S):S=e[30],g="flex flex-col h-80",e[31]!==h?(c=t.jsx(Ye,{value:h,onChange:o,placeholder:"Search members...",className:"border-b border-t-0 border-x-0 rounded-none"}),e[31]=h,e[32]=c):c=e[32],p="flex-1 overflow-auto",C=te.length===0?t.jsx("div",{className:"flex items-center justify-center h-full px-6",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:h?"No members found":"No members available"})}):t.jsx("div",{className:"px-6 py-2 space-y-1",children:te.map(D=>{const r=$(D),b=Q(D.id),F=f.includes(D.id);return t.jsxs("label",{className:ie("flex items-center gap-3 p-2 rounded-lg",!r||b?"opacity-50 cursor-not-allowed":"cursor-pointer hover:bg-muted/50"),children:[t.jsx(Bs,{checked:F||b,onCheckedChange:()=>{r&&!b&&re(D.id)},disabled:!r||b}),t.jsx(Ce,{url:D.user?.image??void 0,fallback:ws(D.user?.name),shape:"circle",size:"sm"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium truncate",children:D.user?.name||"Unknown"}),t.jsx("p",{className:"text-xs text-muted-foreground truncate",children:D.user?.email})]}),!r&&t.jsx(Te,{variant:"secondary",className:"shrink-0",children:"Owner"}),b&&r&&t.jsx(Te,{variant:"outline",className:"shrink-0",children:"Added"})]},D.id)})}),e[1]=d?.data?.members,e[2]=x,e[3]=i,e[4]=l,e[5]=n,e[6]=f,e[7]=h,e[8]=a,e[9]=I,e[10]=u,e[11]=j,e[12]=p,e[13]=C,e[14]=g,e[15]=c,e[16]=v,e[17]=S,e[18]=P,e[19]=T}else I=e[9],u=e[10],j=e[11],p=e[12],C=e[13],g=e[14],c=e[15],v=e[16],S=e[17],P=e[18],T=e[19];let O;e[33]!==p||e[34]!==C?(O=t.jsx("div",{className:p,children:C}),e[33]=p,e[34]=C,e[35]=O):O=e[35];let A;e[36]!==O||e[37]!==g||e[38]!==c?(A=t.jsxs("div",{className:g,children:[c,O]}),e[36]=O,e[37]=g,e[38]=c,e[39]=A):A=e[39];let L;e[40]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(Le,{children:"Cancel"}),e[40]=L):L=e[40];const E=f.length===0,_=f.length>0&&`(${f.length})`;let z;e[41]!==j||e[42]!==E||e[43]!==_?(z=t.jsxs(Pe,{className:"px-6 pb-6",children:[L,t.jsxs(Me,{onClick:j,disabled:E,children:["Add ",_]})]}),e[41]=j,e[42]=E,e[43]=_,e[44]=z):z=e[44];let N;e[45]!==I||e[46]!==A||e[47]!==z||e[48]!==v||e[49]!==S?(N=t.jsxs(I,{className:v,children:[S,A,z]}),e[45]=I,e[46]=A,e[47]=z,e[48]=v,e[49]=S,e[50]=N):N=e[50];let m;return e[51]!==u||e[52]!==N||e[53]!==P||e[54]!==T?(m=t.jsx(u,{open:P,onOpenChange:T,children:N}),e[51]=u,e[52]=N,e[53]=P,e[54]=T,e[55]=m):m=e[55],m}function ft(s){return s.role!=="owner"}function ht(s){const e=me.c(40),{memberIds:n,onMemberIdsChange:l,readOnly:a}=s,i=a===void 0?!1:a,[h,o]=V.useState(""),x=V.useDeferredValue(h),[y,f]=V.useState(!1),{data:w}=os();let d,I,u,j,p;if(e[0]!==w?.data?.members||e[1]!==x||e[2]!==n||e[3]!==l||e[4]!==i||e[5]!==h){const v=w?.data?.members??[];let S;e[11]!==n?(S=N=>n.includes(N.id),e[11]=n,e[12]=S):S=e[12];const P=v.filter(S);let T;e[13]!==x?(T=N=>{const m=x.toLowerCase();return N.user?.name?.toLowerCase().includes(m)||N.user?.email?.toLowerCase().includes(m)},e[13]=x,e[14]=T):T=e[14];const O=P.filter(T);let A;e[15]!==n||e[16]!==l?(A=N=>{l(n.filter(m=>m!==N))},e[15]=n,e[16]=l,e[17]=A):A=e[17];const L=A;let E;e[18]!==n||e[19]!==l?(E=N=>{l([...n,...N])},e[18]=n,e[19]=l,e[20]=E):E=e[20],d=E,j="flex flex-col h-full";let _;e[21]!==h?(_=t.jsx(Ye,{value:h,onChange:o,placeholder:"Search members...",className:"flex-1 border-b-0"}),e[21]=h,e[22]=_):_=e[22];let z;e[23]!==i?(z=i?t.jsx("div",{className:"pr-4",children:t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsxs(ee,{variant:"outline",size:"sm",disabled:!0,children:[t.jsx(se,{name:"add",size:16}),"Add Member"]})})}),t.jsx(Se,{children:t.jsx("p",{children:"Owner membership cannot be changed"})})]})})}):t.jsx("div",{className:"pr-4",children:t.jsxs(ee,{variant:"outline",size:"sm",onClick:()=>f(!0),children:[t.jsx(se,{name:"add",size:16}),"Add Member"]})}),e[23]=i,e[24]=z):z=e[24],e[25]!==_||e[26]!==z?(p=t.jsxs("div",{className:"flex items-center border-b border-border",children:[_,z]}),e[25]=_,e[26]=z,e[27]=p):p=e[27],I="flex-1 overflow-auto",u=P.length===0?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center",children:[t.jsx("h3",{className:"text-lg font-medium mb-2",children:"No members"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Add members to this role to grant them the configured permissions."})]})}):O.length===0?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("p",{className:"text-sm text-muted-foreground",children:['No members match "',h,'"']})}):t.jsx("div",{className:"p-4 space-y-2",children:O.map(N=>t.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted/30",children:[t.jsx(Ce,{url:N.user?.image??void 0,fallback:ws(N.user?.name),shape:"circle",size:"sm"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium truncate",children:N.user?.name||"Unknown"}),t.jsx("p",{className:"text-xs text-muted-foreground truncate",children:N.user?.email})]}),i?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(ee,{variant:"ghost",size:"sm",disabled:!0,children:t.jsx(se,{name:"close",size:16})})})}),t.jsx(Se,{children:t.jsx("p",{children:"Owner membership cannot be changed"})})]})}):t.jsx(ee,{variant:"ghost",size:"sm",onClick:()=>L(N.id),children:t.jsx(se,{name:"close",size:16})})]},N.id))}),e[0]=w?.data?.members,e[1]=x,e[2]=n,e[3]=l,e[4]=i,e[5]=h,e[6]=d,e[7]=I,e[8]=u,e[9]=j,e[10]=p}else d=e[6],I=e[7],u=e[8],j=e[9],p=e[10];let C;e[28]!==I||e[29]!==u?(C=t.jsx("div",{className:I,children:u}),e[28]=I,e[29]=u,e[30]=C):C=e[30];let g;e[31]!==y||e[32]!==d||e[33]!==n?(g=t.jsx(ut,{open:y,onOpenChange:f,selectedMemberIds:n,onAddMembers:d}),e[31]=y,e[32]=d,e[33]=n,e[34]=g):g=e[34];let c;return e[35]!==j||e[36]!==p||e[37]!==C||e[38]!==g?(c=t.jsxs("div",{className:j,children:[p,C,g]}),e[35]=j,e[36]=p,e[37]=C,e[38]=g,e[39]=c):c=e[39],c}function gt(s){const e=me.c(3);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(se,{name:"progress_activity",size:24,className:"animate-spin text-muted-foreground"})}),e[0]=n):n=e[0];let l;return e[1]!==s?(l=t.jsx(V.Suspense,{fallback:n,children:t.jsx(ht,{...s})}),e[1]=s,e[2]=l):l=e[2],l}const xt={owner:[],admin:[],user:[]};function $e(s,e){const n=s==="owner"||s==="admin",l=e.filter(a=>a.role===s);return{role:{slug:s,label:s.charAt(0).toUpperCase()+s.slice(1)},allowAllStaticPermissions:n,staticPermissions:xt[s],toolSet:{},memberIds:l.map(a=>a.id)}}function pt({trigger:s,onSuccess:e}){const[n,l]=V.useState(!1),[a,i]=V.useState("mcp"),{locator:h}=ve(),o=Ze(),x=zs()??[],{customRoles:y,refetch:f}=ms(),{data:w}=ys({queryKey:ae.members(h),queryFn:()=>X.organization.listMembers()}),d=Ns({resolver:Rs(nt),defaultValues:Fe()}),I=d.formState.isValid,u=d.formState.isDirty,[j,p]=V.useState(null),[C,g]=V.useState(null),c=!d.watch("role.id")&&!d.watch("role.slug")&&!C,[v,S]=V.useState(null),[P,T]=V.useState(!1),[O,A]=V.useState(null),L=r=>{const b=r.permission||{},F=b.self||[],oe=F.includes("*"),le=oe?[]:F.filter(k=>k!=="*"),W={};for(const[k,B]of Object.entries(b))if(k!=="self")if(k==="*")for(const Z of x)B.includes("*")?W[Z.id]=Z.tools?.map(ce=>ce.name)??[]:W[Z.id]=B;else{const Z=x.find(ce=>ce.id===k);Z&&(B.includes("*")?W[k]=Z.tools?.map(ce=>ce.name)??[]:W[k]=B)}const ue=(w?.data?.members??[]).filter(k=>k.role===r.role).map(k=>k.id);return{role:{id:r.id,slug:r.role,label:r.label},allowAllStaticPermissions:oe,staticPermissions:le,toolSet:W,memberIds:ue}},E=r=>{const b=L(r);d.reset(b),p(r.id??null),g(null)},_=()=>{d.reset(Fe()),p(null),g(null),i("mcp")},z=r=>{u&&I?(A(()=>()=>E(r)),T(!0)):E(r)},N=async()=>{u&&I&&await Y(),_()},m=r=>{if(u&&I)A(()=>()=>{const b=$e(r,w?.data?.members??[]);d.reset(b),g(r),p(null),i("org")}),T(!0);else{const b=$e(r,w?.data?.members??[]);d.reset(b),g(r),p(null),i("org")}},M=r=>{if(!r&&d.formState.isDirty&&I){A(()=>()=>{l(!1),d.reset(Fe()),g(null)}),T(!0);return}if(l(r),!r)d.reset(Fe()),g(null),p(null);else{const b=y[0];if(b)E(b);else{const F=$e("user",w?.data?.members??[]);d.reset(F),g("user"),p(null),i("org")}}},U=()=>{T(!1),O&&(O(),A(null))},te=r=>{const b={};r.allowAllStaticPermissions?b.self=["*"]:r.staticPermissions.length>0&&(b.self=r.staticPermissions);for(const[F,oe]of Object.entries(r.toolSet))if(oe.length>0){const W=x.find(q=>q.id===F)?.tools?.map(q=>q.name)??[];W.length>0&&W.every(q=>oe.includes(q))?b[F]=["*"]:b[F]=oe}return b},$=he({mutationFn:async r=>{const b=te(r),F=r.role.slug||r.role.label.toLowerCase().replace(/\s+/g,"-");if(r.role.slug&&!r.role.id){const W=(w?.data?.members??[]).filter(k=>k.role===r.role.slug).map(k=>k.id),q=r.memberIds.filter(k=>!W.includes(k)),ue=W.filter(k=>!r.memberIds.includes(k));for(const k of q){const B=await X.organization.updateMemberRole({memberId:k,role:[r.role.slug]});if(B?.error)throw new Error(B.error.message)}for(const k of ue){const B=await X.organization.updateMemberRole({memberId:k,role:["user"]});if(B?.error)throw new Error(B.error.message)}return r}else if(r.role.id){const le=await X.organization.updateRole({roleId:r.role.id,data:{permission:b}});if(le?.error)throw new Error(le.error.message);const q=(w?.data?.members??[]).filter(B=>B.role===r.role.slug).map(B=>B.id),ue=r.memberIds.filter(B=>!q.includes(B)),k=q.filter(B=>!r.memberIds.includes(B));for(const B of ue){const Z=await X.organization.updateMemberRole({memberId:B,role:[r.role.slug]});if(Z?.error)throw new Error(Z.error.message)}for(const B of k){const Z=await X.organization.updateMemberRole({memberId:B,role:["user"]});if(Z?.error)throw new Error(Z.error.message)}return r}else{const le=await X.organization.createRole({role:F,permission:b});if(le?.error)throw new Error(le.error.message);for(const W of r.memberIds){const q=await X.organization.updateMemberRole({memberId:W,role:[F]});if(q?.error)throw new Error(q.error.message)}return{...r,role:{...r.role,id:le.data?.roleData?.id,slug:F}}}},onSuccess:(r,b)=>{o.invalidateQueries({queryKey:ae.members(h)}),o.invalidateQueries({queryKey:ae.organizationRoles(h)});const F=!b.role.id&&!b.role.slug,oe=b.role.slug&&!b.role.id;J.success(oe?"Members updated successfully!":F?"Role created successfully!":"Role updated successfully!"),f(),d.reset(r),r.role.id&&p(r.role.id),e?.()},onError:r=>{J.error(r instanceof Error?r.message:"Failed to save role")}}),K=he({mutationFn:async r=>{const b=await X.organization.deleteRole({roleId:r});if(b?.error)throw new Error(b.error.message);return b?.data},onSuccess:()=>{if(o.invalidateQueries({queryKey:ae.members(h)}),o.invalidateQueries({queryKey:ae.organizationRoles(h)}),J.success("Role deleted successfully!"),f(),v?.id===j){const r=y.filter(b=>b.id!==v?.id);if(r[0])E(r[0]);else{const b=$e("user",w?.data?.members??[]);d.reset(b),g("user"),p(null),i("org")}}},onError:r=>{J.error(r instanceof Error?r.message:"Failed to delete role")}}),Q=$.isPending||K.isPending,Y=async()=>{const r=d.getValues();if(!r.role.label.trim()){J.error("Role name is required"),d.setFocus("role.label");return}await $.mutateAsync(r)},re=d.handleSubmit(r=>{if(!r.role.label.trim()){J.error("Role name is required"),d.setFocus("role.label");return}$.mutate(r)}),ne=r=>{r.id&&S({id:r.id,label:r.label})},D=()=>{v?.id&&K.mutate(v.id),S(null)};return t.jsxs(Es,{open:n,onOpenChange:M,children:[t.jsx(Is,{asChild:!0,children:s}),t.jsx(Ss,{className:"sm:max-w-5xl h-[80vh] max-h-[80vh] flex flex-col p-0 overflow-hidden w-[95vw]",children:t.jsxs("div",{className:"flex-1 flex overflow-hidden min-h-0 flex-col sm:flex-row",children:[t.jsxs("div",{className:"w-full sm:w-64 sm:border-r border-b sm:border-b-0 border-border flex flex-col bg-background sm:h-full max-h-[40vh] sm:max-h-full",children:[t.jsx("div",{className:"flex-1 overflow-auto px-3.5 py-3.5 pt-3.5",children:t.jsxs("div",{className:"flex flex-col gap-1",children:[rt.map(r=>{const b=C===r.role;return t.jsxs("div",{className:ie("flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden cursor-pointer transition-colors",b?"bg-accent":"hover:bg-muted/50"),onClick:()=>m(r.role),children:[t.jsx("div",{className:ie("shrink-0 size-3 rounded-full",r.color)}),t.jsx("p",{className:"text-sm font-medium truncate flex-1",children:r.label}),t.jsx(se,{name:"lock",size:14,className:"text-muted-foreground shrink-0"})]},r.role)}),y.map(r=>{const b=j===r.id;return t.jsxs("div",{className:ie("group flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden transition-colors cursor-pointer",b?"bg-accent":"hover:bg-muted/50"),onClick:()=>z(r),children:[t.jsx("div",{className:ie("shrink-0 size-3 rounded-full",it(r.label))}),t.jsx("p",{className:"text-sm font-medium truncate flex-1",children:r.label}),t.jsxs(as,{children:[t.jsx(cs,{asChild:!0,children:t.jsx(ee,{variant:"ghost",size:"icon",className:ie("size-5 shrink-0 transition-opacity opacity-0 pointer-events-none","group-hover:opacity-100 group-hover:pointer-events-auto",b&&"opacity-100 pointer-events-auto"),onClick:F=>F.stopPropagation(),children:t.jsx(se,{name:"more_horiz",size:14})})}),t.jsx(ds,{align:"end",children:t.jsxs(Qe,{className:"text-destructive",onClick:F=>{F.stopPropagation(),ne(r)},children:[t.jsx(se,{name:"delete",size:16}),"Delete"]})})]})]},r.id)}),c&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden bg-accent",children:[t.jsx("div",{className:"shrink-0 size-3 rounded-full bg-neutral-400"}),t.jsx(qs,{...d.register("role.label"),placeholder:"Enter role name",className:"flex-1 text-sm font-medium border-0 shadow-none h-auto px-0 py-0 focus-visible:ring-0 bg-transparent",autoFocus:!0}),t.jsx(Te,{variant:"secondary",className:"shrink-0 text-xs px-1.5 py-0",children:"New"})]})]})}),t.jsx("div",{className:"px-3.5 pb-3.5",children:t.jsxs(ee,{variant:"outline",size:"default",onClick:N,disabled:Q||u,className:"w-full h-10",children:[t.jsx(se,{name:"add",size:16}),"Create new role"]})})]}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[t.jsxs("div",{className:"h-12 border-b border-border px-4 py-3.5 flex items-center gap-2 shrink-0",children:[!C&&t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("mcp"),className:ie("h-8 rounded-lg px-2 py-1",a==="mcp"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"MCP Permissions"}),t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("org"),className:ie("h-8 rounded-lg px-2 py-1",a==="org"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"Organization Permissions"}),t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("members"),className:ie("h-8 rounded-lg px-2 py-1",a==="members"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"Members"})]}),t.jsxs("div",{className:"flex-1 overflow-hidden min-h-0",children:[a==="mcp"&&!C&&t.jsx(Ms,{toolSet:d.watch("toolSet"),onToolSetChange:r=>d.setValue("toolSet",r,{shouldDirty:!0})}),a==="org"&&t.jsx(lt,{allowAllStaticPermissions:d.watch("allowAllStaticPermissions"),staticPermissions:d.watch("staticPermissions"),onAllowAllChange:r=>d.setValue("allowAllStaticPermissions",r,{shouldDirty:!0}),onPermissionsChange:r=>d.setValue("staticPermissions",r,{shouldDirty:!0}),readOnly:!!C}),a==="members"&&t.jsx(gt,{memberIds:d.watch("memberIds"),onMemberIdsChange:r=>d.setValue("memberIds",r,{shouldDirty:!0}),readOnly:C==="owner"})]}),(!C||C!=="owner")&&t.jsxs("div",{className:"border-t border-border px-5 py-5 flex items-center justify-end gap-2.5 shrink-0",children:[t.jsx(ee,{variant:"outline",onClick:()=>M(!1),disabled:Q,className:"h-10",children:"Cancel"}),t.jsx(ee,{onClick:re,disabled:Q||!I||!d.formState.isDirty,className:"h-10",children:$.isPending?"Saving...":c?"Create Role":"Save Changes"})]})]})]})}),t.jsx(we,{open:v!==null,onOpenChange:r=>!r&&S(null),children:t.jsxs(Ae,{children:[t.jsxs(Oe,{children:[t.jsx(Re,{children:"Delete Role"}),t.jsxs(_e,{children:['Are you sure you want to delete the "',v?.label,'" role? This action cannot be undone.']})]}),t.jsxs(Pe,{children:[t.jsx(Le,{children:"Cancel"}),t.jsx(Me,{onClick:D,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),t.jsx(we,{open:P,onOpenChange:T,children:t.jsxs(Ae,{children:[t.jsxs(Oe,{children:[t.jsx(Re,{children:"Discard Changes"}),t.jsx(_e,{children:"You have unsaved changes. Are you sure you want to discard them?"})]}),t.jsxs(Pe,{children:[t.jsx(Le,{onClick:()=>A(null),children:"Keep Editing"}),t.jsx(Me,{onClick:U,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Discard"})]})]})})]})}const bt=fe().email("Invalid email address");function jt(s){if(!s.trim())return[];const e=s.split(/[,;\n]/).map(n=>n.trim().toLowerCase()).filter(n=>n.length>0);return Array.from(new Set(e))}function Ct({trigger:s}){const[e,n]=V.useState(!1),{locator:l}=ve(),a=Ze(),{data:i}=X.useSession(),h=i?.user?.email,{roles:o,isLoading:x}=ms(),y=o.filter(g=>g.role!=="owner"),f=Ns({mode:"onChange",defaultValues:{emailsText:"",role:"user"}}),w=f.watch("emailsText"),d=f.watch("role"),u=jt(w).filter(g=>{const c=bt.safeParse(g).success,v=!h||g!==h.toLowerCase();return c&&v}),j=he({mutationFn:async({emails:g,role:c})=>{if(!c)throw new Error("Please select a role");const v=await Promise.allSettled(g.map(async P=>{const T=await X.organization.inviteMember({email:P,role:c});if(T.error)throw new Error(T.error.message);return T.data})),S=v.filter(P=>P.status==="rejected");if(S.length>0)throw new Error(`Failed to invite ${S.length} member${S.length>1?"s":""}`);return v},onSuccess:(g,{emails:c})=>{a.invalidateQueries({queryKey:ae.members(l)}),a.invalidateQueries({queryKey:ae.invitations(l)}),J.success(c.length===1?"Member invited successfully!":`${c.length} members invited successfully!`),f.reset({emailsText:"",role:"user"}),n(!1)},onError:g=>{J.error(g instanceof Error?g.message:"Failed to invite members")}}),p=g=>{if(u.length===0){J.error("Please enter at least one valid email address");return}if(!g.role){J.error("Please select a role");return}j.mutate({emails:u,role:g.role})},C=u.length>0&&!!d;return t.jsxs(Es,{open:e,onOpenChange:n,children:[t.jsx(Is,{asChild:!0,children:s}),t.jsxs(Ss,{className:"sm:max-w-lg",children:[t.jsx(Gs,{children:t.jsx(Us,{children:"Invite members"})}),t.jsx(Ys,{...f,children:t.jsxs("form",{onSubmit:f.handleSubmit(p),className:"space-y-4",children:[t.jsx(fs,{control:f.control,name:"emailsText",render:({field:g})=>t.jsxs(hs,{children:[t.jsx(Ws,{children:"Email addresses"}),t.jsx(gs,{children:t.jsx(Hs,{...g,disabled:j.isPending,placeholder:`Enter email addresses separated by commas or new lines
|
|
1
|
+
import{a2 as ae,a as X,ap as us,aE as Je,aF as As,aG as Os,aq as fe,r as V,a1 as Ze,as as Ns,ar as Rs,a6 as J,j as t,c as me,a3 as _s}from"./index-WOQ13cP6.js";import{C as Ps}from"./collection-header-CP7DLL6n.js";import{C as ss}from"./collection-page-C1jzPNDj.js";import{C as Ye}from"./collection-search-CrkK01Ci.js";import{C as Ls}from"./collection-table-wrapper-DtI6Q7NT.js";import{T as Ms}from"./tool-set-selector-M0YnbcFP.js";import{b as zs,c as ks}from"./use-connection-B5VryFm7.js";import{u as os}from"./use-members--7RkMxwe.js";import{W as Ds}from"./well-known-mcp-Dg77mwx9.js";import{u as ve,d as ye,b as Ee,a as Ie,T as Se}from"./tooltip-D5O925Gp.js";import{u as ys}from"./useQuery-XS-ILlMf.js";import{A as Ce}from"./avatar-4ymdPXa_.js";import{B as Te}from"./badge-M2zkAPfT.js";import{u as he,B as ee}from"./button-DpN85Po0.js";import{C as Bs}from"./checkbox-DWHTP51a.js";import{f as we,a as Ae,b as Oe,c as Re,d as _e,e as Pe,A as Le,g as Me}from"./alert-dialog-CCDQTgck.js";import{d as Es,e as Is,c as Ss,D as Gs,a as Us,f as Vs}from"./dialog-CfKieCBd.js";import{b as as,D as cs,a as ds,c as Qe,e as Fs,f as $s,g as Ks,d as Qs}from"./dropdown-menu-Bvf4p8xE.js";import{I as se}from"./icon-CBAJ1FOz.js";import{I as qs}from"./input-DRMFvIcp.js";import{S as Ve}from"./switch-P43q-fGo.js";import{c as ie}from"./utils-E9aiNDpO.js";import{E as Xe}from"./empty-state-jtBjSgAJ.js";import{E as Zs}from"./error-boundary-BjLQDRan.js";import{a as Ys,F as fs,b as hs,c as Ws,d as gs,f as xs}from"./form-C-tSv2Q6.js";import{c as ts,a as ns,S as rs,b as is,d as ls}from"./select-DzEOHgSq.js";import{T as Hs}from"./textarea-BNSwm2Uw.js";import{C as ps}from"./card-CjmS8q7G.js";import"./collection-display-button-Cq_29P0W.js";const Ts=[{name:"ORGANIZATION_CREATE",description:"Create a new organization",category:"Organizations"},{name:"ORGANIZATION_LIST",description:"List organizations",category:"Organizations"},{name:"ORGANIZATION_GET",description:"View organization details",category:"Organizations"},{name:"ORGANIZATION_UPDATE",description:"Update organization",category:"Organizations"},{name:"ORGANIZATION_DELETE",description:"Delete organization",category:"Organizations",dangerous:!0},{name:"ORGANIZATION_SETTINGS_GET",description:"View organization settings",category:"Organizations"},{name:"ORGANIZATION_SETTINGS_UPDATE",description:"Update organization settings",category:"Organizations"},{name:"ORGANIZATION_MEMBER_ADD",description:"Add members",category:"Organizations"},{name:"ORGANIZATION_MEMBER_REMOVE",description:"Remove members",category:"Organizations",dangerous:!0},{name:"ORGANIZATION_MEMBER_LIST",description:"List members",category:"Organizations"},{name:"ORGANIZATION_MEMBER_UPDATE_ROLE",description:"Update member roles",category:"Organizations"},{name:"COLLECTION_CONNECTIONS_CREATE",description:"Create connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_LIST",description:"List connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_GET",description:"View connection details",category:"Connections"},{name:"COLLECTION_CONNECTIONS_UPDATE",description:"Update connections",category:"Connections"},{name:"COLLECTION_CONNECTIONS_DELETE",description:"Delete connections",category:"Connections",dangerous:!0},{name:"CONNECTION_TEST",description:"Test connections",category:"Connections"},{name:"DATABASES_RUN_SQL",description:"Run SQL queries",category:"Connections",dangerous:!0},{name:"COLLECTION_GATEWAY_CREATE",description:"Create gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_LIST",description:"List gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_GET",description:"View gateway details",category:"Gateways"},{name:"COLLECTION_GATEWAY_UPDATE",description:"Update gateways",category:"Gateways"},{name:"COLLECTION_GATEWAY_DELETE",description:"Delete gateways",category:"Gateways",dangerous:!0},{name:"MONITORING_LOGS_LIST",description:"List monitoring logs",category:"Monitoring"},{name:"MONITORING_STATS",description:"View monitoring statistics",category:"Monitoring"},{name:"API_KEY_CREATE",description:"Create API key",category:"API Keys"},{name:"API_KEY_LIST",description:"List API keys",category:"API Keys"},{name:"API_KEY_UPDATE",description:"Update API key",category:"API Keys"},{name:"API_KEY_DELETE",description:"Delete API key",category:"API Keys",dangerous:!0},{name:"EVENT_PUBLISH",description:"Publish events",category:"Event Bus"},{name:"EVENT_SUBSCRIBE",description:"Subscribe to events",category:"Event Bus"},{name:"EVENT_UNSUBSCRIBE",description:"Unsubscribe from events",category:"Event Bus"},{name:"EVENT_CANCEL",description:"Cancel recurring events",category:"Event Bus"},{name:"EVENT_ACK",description:"Acknowledge event delivery",category:"Event Bus"},{name:"EVENT_SUBSCRIPTION_LIST",description:"List event subscriptions",category:"Event Bus"},{name:"EVENT_SYNC_SUBSCRIPTIONS",description:"Sync subscriptions to desired state",category:"Event Bus"}],Js={ORGANIZATION_CREATE:"Create organization",ORGANIZATION_LIST:"List organizations",ORGANIZATION_GET:"View organization details",ORGANIZATION_UPDATE:"Update organization",ORGANIZATION_DELETE:"Delete organization",ORGANIZATION_SETTINGS_GET:"View organization settings",ORGANIZATION_SETTINGS_UPDATE:"Update organization settings",ORGANIZATION_MEMBER_LIST:"List members",ORGANIZATION_MEMBER_ADD:"Add members",ORGANIZATION_MEMBER_REMOVE:"Remove members",ORGANIZATION_MEMBER_UPDATE_ROLE:"Update member roles",COLLECTION_CONNECTIONS_LIST:"List connections",COLLECTION_CONNECTIONS_GET:"View connection details",COLLECTION_CONNECTIONS_CREATE:"Create connections",COLLECTION_CONNECTIONS_UPDATE:"Update connections",COLLECTION_CONNECTIONS_DELETE:"Delete connections",CONNECTION_TEST:"Test connections",DATABASES_RUN_SQL:"Run SQL queries",COLLECTION_GATEWAY_CREATE:"Create gateways",COLLECTION_GATEWAY_LIST:"List gateways",COLLECTION_GATEWAY_GET:"View gateway details",COLLECTION_GATEWAY_UPDATE:"Update gateways",COLLECTION_GATEWAY_DELETE:"Delete gateways",MONITORING_LOGS_LIST:"List monitoring logs",MONITORING_STATS:"View monitoring statistics",API_KEY_CREATE:"Create API key",API_KEY_LIST:"List API keys",API_KEY_UPDATE:"Update API key",API_KEY_DELETE:"Delete API key",EVENT_PUBLISH:"Publish events",EVENT_SUBSCRIBE:"Subscribe to events",EVENT_UNSUBSCRIBE:"Unsubscribe from events",EVENT_CANCEL:"Cancel recurring events",EVENT_ACK:"Acknowledge event delivery",EVENT_SUBSCRIPTION_LIST:"List event subscriptions",EVENT_SYNC_SUBSCRIPTIONS:"Sync subscriptions to desired state"};function Xs(){const s={Organizations:[],Connections:[],Gateways:[],Monitoring:[],"API Keys":[],"Event Bus":[]};for(const e of Ts)s[e.category]?.push(e);return s}function et(){return Ts.map(s=>({value:s.name,label:Js[s.name],dangerous:s.dangerous}))}const bs=[{value:"owner",label:"Owner",isBuiltin:!0},{value:"admin",label:"Admin",isBuiltin:!0},{value:"user",label:"User",isBuiltin:!0}];function st(s){return s.replace(/-/g," ")}function tt(s){if(!s)return{staticPermissions:[],allowsAllStaticPermissions:!1,connectionIds:[],allowsAllConnections:!1,toolNames:[],allowsAllTools:!1};const e=[];let n=!1;const l=[];let a=!1;const i=new Set;let h=!1;for(const[o,x]of Object.entries(s)){if(o===Ds.SELF){x.includes("*")?n=!0:e.push(...x);continue}if(o==="*"){if(a=!0,x.includes("*"))h=!0;else for(const y of x)i.add(y);continue}if(l.push(o),x.includes("*"))h=!0;else for(const y of x)i.add(y)}return{staticPermissions:e,allowsAllStaticPermissions:n,connectionIds:l,allowsAllConnections:a,toolNames:Array.from(i),allowsAllTools:h}}function ms(){const{locator:s}=ve(),{data:e,isLoading:n,error:l,refetch:a}=ys({queryKey:ae.organizationRoles(s),queryFn:async()=>{try{const o=await X.organization.listRoles();return o?.error?(console.error("[useOrganizationRoles] API error:",o.error),[]):o?.data??[]}catch(o){return console.error("[useOrganizationRoles] Fetch error:",o),[]}},staleTime:3e4}),i=bs.map(o=>({role:o.value,label:o.label,isBuiltin:o.isBuiltin}));if(e&&Array.isArray(e))for(const o of e){const x=o.role;if(!x||bs.some(j=>j.value===x))continue;const{staticPermissions:y,allowsAllStaticPermissions:f,connectionIds:w,allowsAllConnections:d,toolNames:I,allowsAllTools:u}=tt(o.permission);i.push({id:o.id,role:x,label:st(x),isBuiltin:!1,permission:o.permission??void 0,staticPermissionCount:f?-1:y.length,allowsAllStaticPermissions:f,connectionCount:d?-1:w.length,allowsAllConnections:d,toolCount:u?-1:I.length,allowsAllTools:u})}const h=i.filter(o=>!o.isBuiltin);return{roles:i,customRoles:h,builtinRoles:i.filter(o=>o.isBuiltin),isLoading:n,error:l,refetch:a}}const nt=us({role:us({id:fe().optional(),slug:fe().optional(),label:fe()}),allowAllStaticPermissions:Os(),staticPermissions:Je(fe()),toolSet:As(Je(fe())),memberIds:Je(fe())});function ws(s){return s?s.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2):"?"}const rt=[{role:"owner",label:"Owner",color:"bg-red-500"},{role:"admin",label:"Admin",color:"bg-blue-500"},{role:"user",label:"User",color:"bg-green-500"}],es=["bg-red-500","bg-orange-500","bg-amber-500","bg-yellow-500","bg-lime-500","bg-green-500","bg-emerald-500","bg-teal-500","bg-cyan-500","bg-sky-500","bg-blue-500","bg-indigo-500","bg-violet-500","bg-purple-500","bg-fuchsia-500","bg-pink-500","bg-rose-500"];function it(s){if(!s)return"bg-neutral-400";let e=0;for(let l=0;l<s.length;l++){const a=s.charCodeAt(l);e=(e<<5)-e+a,e=e&e}const n=Math.abs(e)%es.length;return es[n]??es[0]}function Fe(){return{role:{id:void 0,slug:void 0,label:""},allowAllStaticPermissions:!1,staticPermissions:[],toolSet:{},memberIds:[]}}function lt(s){const e=me.c(39),{allowAllStaticPermissions:n,staticPermissions:l,onAllowAllChange:a,onPermissionsChange:i,readOnly:h}=s,o=h===void 0?!1:h,[x,y]=V.useState(""),f=V.useDeferredValue(x);let w,d,I,u,j;if(e[0]!==n||e[1]!==f||e[2]!==a||e[3]!==i||e[4]!==o||e[5]!==x||e[6]!==l){const g=Xs(),c=et(),v=c.filter(E=>E.label.toLowerCase().includes(f.toLowerCase())),S=E=>{if(l.includes(E))i(l.filter(_=>_!==E));else{const _=[...l,E];_.length===c.length?(a(!0),i([])):i(_)}};I="flex flex-col h-full",e[12]!==x?(u=t.jsx("div",{className:"border-b border-border",children:t.jsx(Ye,{value:x,onChange:y,placeholder:"Search permissions...",className:"border-b-0"})}),e[12]=x,e[13]=u):u=e[13];const P=!o&&"hover:bg-muted/50 cursor-pointer";let T;e[14]!==P?(T=ie("flex items-center justify-between px-4 py-3 rounded-lg",P),e[14]=P,e[15]=T):T=e[15];let O;e[16]!==n||e[17]!==a||e[18]!==i||e[19]!==o?(O=()=>{if(o)return;a(!n),i([])},e[16]=n,e[17]=a,e[18]=i,e[19]=o,e[20]=O):O=e[20];let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx("span",{className:"text-sm font-medium",children:"All organization permissions"}),e[21]=A):A=e[21];let L;e[22]!==n||e[23]!==a||e[24]!==i||e[25]!==o?(L=t.jsx("div",{onClick:mt,children:o?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(Ve,{checked:n,disabled:o,onCheckedChange:E=>{o||(a(E),i([]))}})})}),t.jsx(Se,{children:t.jsx("p",{children:"Built-in role permissions cannot be changed"})})]})}):t.jsx(Ve,{checked:n,disabled:o,onCheckedChange:E=>{o||(a(E),i([]))}})}),e[22]=n,e[23]=a,e[24]=i,e[25]=o,e[26]=L):L=e[26],e[27]!==L||e[28]!==T||e[29]!==O?(j=t.jsx("div",{className:"border-b border-border",children:t.jsxs("div",{className:T,onClick:O,children:[A,L]})}),e[27]=L,e[28]=T,e[29]=O,e[30]=j):j=e[30],w="flex-1 overflow-auto",d=Object.entries(g).map(E=>{const[_,z]=E,N=v.filter(m=>z.some(M=>M.name===m.value));return N.length===0?null:t.jsxs("div",{className:"mb-6 last:mb-0",children:[t.jsx("h4",{className:"text-sm font-medium p-3 pb-1.5 text-muted-foreground/75",children:_}),t.jsx("div",{className:"space-y-1",children:N.map(m=>t.jsxs("div",{className:ie("flex items-center justify-between gap-3 px-4 py-3",!o&&"hover:bg-muted/50 cursor-pointer"),onClick:()=>{if(!o)if(n){a(!1);const M=c.map(dt);i(M.filter(U=>U!==m.value))}else S(m.value)},children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx("span",{className:"text-sm",children:m.label})}),t.jsx("div",{onClick:ct,children:o?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(Ve,{checked:n||l.includes(m.value),disabled:o,onCheckedChange:()=>{if(!o)if(n){a(!1);const M=c.map(at);i(M.filter(U=>U!==m.value))}else S(m.value)}})})}),t.jsx(Se,{children:t.jsx("p",{children:"Built-in role permissions cannot be changed"})})]})}):t.jsx(Ve,{checked:n||l.includes(m.value),disabled:o,onCheckedChange:()=>{if(!o)if(n){a(!1);const M=c.map(ot);i(M.filter(U=>U!==m.value))}else S(m.value)}})})]},m.value))})]},_)}),e[0]=n,e[1]=f,e[2]=a,e[3]=i,e[4]=o,e[5]=x,e[6]=l,e[7]=w,e[8]=d,e[9]=I,e[10]=u,e[11]=j}else w=e[7],d=e[8],I=e[9],u=e[10],j=e[11];let p;e[31]!==w||e[32]!==d?(p=t.jsx("div",{className:w,children:d}),e[31]=w,e[32]=d,e[33]=p):p=e[33];let C;return e[34]!==I||e[35]!==u||e[36]!==j||e[37]!==p?(C=t.jsxs("div",{className:I,children:[u,j,p]}),e[34]=I,e[35]=u,e[36]=j,e[37]=p,e[38]=C):C=e[38],C}function ot(s){return s.value}function at(s){return s.value}function ct(s){return s.stopPropagation()}function dt(s){return s.value}function mt(s){return s.stopPropagation()}function ut(s){const e=me.c(56),{open:n,onOpenChange:l,selectedMemberIds:a,onAddMembers:i}=s,[h,o]=V.useState(""),x=V.useDeferredValue(h);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[0]=y):y=e[0];const[f,w]=V.useState(y),{data:d}=os();let I,u,j,p,C,g,c,v,S,P,T;if(e[1]!==d?.data?.members||e[2]!==x||e[3]!==i||e[4]!==l||e[5]!==n||e[6]!==f||e[7]!==h||e[8]!==a){const M=d?.data?.members??[];let U;e[20]!==x?(U=D=>{const r=x.toLowerCase();return D.user?.name?.toLowerCase().includes(r)||D.user?.email?.toLowerCase().includes(r)},e[20]=x,e[21]=U):U=e[21];const te=M.filter(U),$=ft;let K;e[22]!==a?(K=D=>a.includes(D),e[22]=a,e[23]=K):K=e[23];const Q=K;let Y;e[24]!==f?(Y=D=>{f.includes(D)?w(f.filter(r=>r!==D)):w([...f,D])},e[24]=f,e[25]=Y):Y=e[25];const re=Y;let ne;e[26]!==i||e[27]!==l||e[28]!==f?(ne=()=>{i(f),w([]),l(!1)},e[26]=i,e[27]=l,e[28]=f,e[29]=ne):ne=e[29],j=ne,u=we,P=n,T=l,I=Ae,v="sm:max-w-md p-0 overflow-hidden",e[30]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsxs(Oe,{className:"px-6 pt-6",children:[t.jsx(Re,{children:"Add Members to Role"}),t.jsx(_e,{children:"Select members to add to this role."})]}),e[30]=S):S=e[30],g="flex flex-col h-80",e[31]!==h?(c=t.jsx(Ye,{value:h,onChange:o,placeholder:"Search members...",className:"border-b border-t-0 border-x-0 rounded-none"}),e[31]=h,e[32]=c):c=e[32],p="flex-1 overflow-auto",C=te.length===0?t.jsx("div",{className:"flex items-center justify-center h-full px-6",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:h?"No members found":"No members available"})}):t.jsx("div",{className:"px-6 py-2 space-y-1",children:te.map(D=>{const r=$(D),b=Q(D.id),F=f.includes(D.id);return t.jsxs("label",{className:ie("flex items-center gap-3 p-2 rounded-lg",!r||b?"opacity-50 cursor-not-allowed":"cursor-pointer hover:bg-muted/50"),children:[t.jsx(Bs,{checked:F||b,onCheckedChange:()=>{r&&!b&&re(D.id)},disabled:!r||b}),t.jsx(Ce,{url:D.user?.image??void 0,fallback:ws(D.user?.name),shape:"circle",size:"sm"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium truncate",children:D.user?.name||"Unknown"}),t.jsx("p",{className:"text-xs text-muted-foreground truncate",children:D.user?.email})]}),!r&&t.jsx(Te,{variant:"secondary",className:"shrink-0",children:"Owner"}),b&&r&&t.jsx(Te,{variant:"outline",className:"shrink-0",children:"Added"})]},D.id)})}),e[1]=d?.data?.members,e[2]=x,e[3]=i,e[4]=l,e[5]=n,e[6]=f,e[7]=h,e[8]=a,e[9]=I,e[10]=u,e[11]=j,e[12]=p,e[13]=C,e[14]=g,e[15]=c,e[16]=v,e[17]=S,e[18]=P,e[19]=T}else I=e[9],u=e[10],j=e[11],p=e[12],C=e[13],g=e[14],c=e[15],v=e[16],S=e[17],P=e[18],T=e[19];let O;e[33]!==p||e[34]!==C?(O=t.jsx("div",{className:p,children:C}),e[33]=p,e[34]=C,e[35]=O):O=e[35];let A;e[36]!==O||e[37]!==g||e[38]!==c?(A=t.jsxs("div",{className:g,children:[c,O]}),e[36]=O,e[37]=g,e[38]=c,e[39]=A):A=e[39];let L;e[40]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(Le,{children:"Cancel"}),e[40]=L):L=e[40];const E=f.length===0,_=f.length>0&&`(${f.length})`;let z;e[41]!==j||e[42]!==E||e[43]!==_?(z=t.jsxs(Pe,{className:"px-6 pb-6",children:[L,t.jsxs(Me,{onClick:j,disabled:E,children:["Add ",_]})]}),e[41]=j,e[42]=E,e[43]=_,e[44]=z):z=e[44];let N;e[45]!==I||e[46]!==A||e[47]!==z||e[48]!==v||e[49]!==S?(N=t.jsxs(I,{className:v,children:[S,A,z]}),e[45]=I,e[46]=A,e[47]=z,e[48]=v,e[49]=S,e[50]=N):N=e[50];let m;return e[51]!==u||e[52]!==N||e[53]!==P||e[54]!==T?(m=t.jsx(u,{open:P,onOpenChange:T,children:N}),e[51]=u,e[52]=N,e[53]=P,e[54]=T,e[55]=m):m=e[55],m}function ft(s){return s.role!=="owner"}function ht(s){const e=me.c(40),{memberIds:n,onMemberIdsChange:l,readOnly:a}=s,i=a===void 0?!1:a,[h,o]=V.useState(""),x=V.useDeferredValue(h),[y,f]=V.useState(!1),{data:w}=os();let d,I,u,j,p;if(e[0]!==w?.data?.members||e[1]!==x||e[2]!==n||e[3]!==l||e[4]!==i||e[5]!==h){const v=w?.data?.members??[];let S;e[11]!==n?(S=N=>n.includes(N.id),e[11]=n,e[12]=S):S=e[12];const P=v.filter(S);let T;e[13]!==x?(T=N=>{const m=x.toLowerCase();return N.user?.name?.toLowerCase().includes(m)||N.user?.email?.toLowerCase().includes(m)},e[13]=x,e[14]=T):T=e[14];const O=P.filter(T);let A;e[15]!==n||e[16]!==l?(A=N=>{l(n.filter(m=>m!==N))},e[15]=n,e[16]=l,e[17]=A):A=e[17];const L=A;let E;e[18]!==n||e[19]!==l?(E=N=>{l([...n,...N])},e[18]=n,e[19]=l,e[20]=E):E=e[20],d=E,j="flex flex-col h-full";let _;e[21]!==h?(_=t.jsx(Ye,{value:h,onChange:o,placeholder:"Search members...",className:"flex-1 border-b-0"}),e[21]=h,e[22]=_):_=e[22];let z;e[23]!==i?(z=i?t.jsx("div",{className:"pr-4",children:t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsxs(ee,{variant:"outline",size:"sm",disabled:!0,children:[t.jsx(se,{name:"add",size:16}),"Add Member"]})})}),t.jsx(Se,{children:t.jsx("p",{children:"Owner membership cannot be changed"})})]})})}):t.jsx("div",{className:"pr-4",children:t.jsxs(ee,{variant:"outline",size:"sm",onClick:()=>f(!0),children:[t.jsx(se,{name:"add",size:16}),"Add Member"]})}),e[23]=i,e[24]=z):z=e[24],e[25]!==_||e[26]!==z?(p=t.jsxs("div",{className:"flex items-center border-b border-border",children:[_,z]}),e[25]=_,e[26]=z,e[27]=p):p=e[27],I="flex-1 overflow-auto",u=P.length===0?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center",children:[t.jsx("h3",{className:"text-lg font-medium mb-2",children:"No members"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Add members to this role to grant them the configured permissions."})]})}):O.length===0?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("p",{className:"text-sm text-muted-foreground",children:['No members match "',h,'"']})}):t.jsx("div",{className:"p-4 space-y-2",children:O.map(N=>t.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted/30",children:[t.jsx(Ce,{url:N.user?.image??void 0,fallback:ws(N.user?.name),shape:"circle",size:"sm"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium truncate",children:N.user?.name||"Unknown"}),t.jsx("p",{className:"text-xs text-muted-foreground truncate",children:N.user?.email})]}),i?t.jsx(ye,{children:t.jsxs(Ee,{children:[t.jsx(Ie,{asChild:!0,children:t.jsx("div",{children:t.jsx(ee,{variant:"ghost",size:"sm",disabled:!0,children:t.jsx(se,{name:"close",size:16})})})}),t.jsx(Se,{children:t.jsx("p",{children:"Owner membership cannot be changed"})})]})}):t.jsx(ee,{variant:"ghost",size:"sm",onClick:()=>L(N.id),children:t.jsx(se,{name:"close",size:16})})]},N.id))}),e[0]=w?.data?.members,e[1]=x,e[2]=n,e[3]=l,e[4]=i,e[5]=h,e[6]=d,e[7]=I,e[8]=u,e[9]=j,e[10]=p}else d=e[6],I=e[7],u=e[8],j=e[9],p=e[10];let C;e[28]!==I||e[29]!==u?(C=t.jsx("div",{className:I,children:u}),e[28]=I,e[29]=u,e[30]=C):C=e[30];let g;e[31]!==y||e[32]!==d||e[33]!==n?(g=t.jsx(ut,{open:y,onOpenChange:f,selectedMemberIds:n,onAddMembers:d}),e[31]=y,e[32]=d,e[33]=n,e[34]=g):g=e[34];let c;return e[35]!==j||e[36]!==p||e[37]!==C||e[38]!==g?(c=t.jsxs("div",{className:j,children:[p,C,g]}),e[35]=j,e[36]=p,e[37]=C,e[38]=g,e[39]=c):c=e[39],c}function gt(s){const e=me.c(3);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(se,{name:"progress_activity",size:24,className:"animate-spin text-muted-foreground"})}),e[0]=n):n=e[0];let l;return e[1]!==s?(l=t.jsx(V.Suspense,{fallback:n,children:t.jsx(ht,{...s})}),e[1]=s,e[2]=l):l=e[2],l}const xt={owner:[],admin:[],user:[]};function $e(s,e){const n=s==="owner"||s==="admin",l=e.filter(a=>a.role===s);return{role:{slug:s,label:s.charAt(0).toUpperCase()+s.slice(1)},allowAllStaticPermissions:n,staticPermissions:xt[s],toolSet:{},memberIds:l.map(a=>a.id)}}function pt({trigger:s,onSuccess:e}){const[n,l]=V.useState(!1),[a,i]=V.useState("mcp"),{locator:h}=ve(),o=Ze(),x=zs()??[],{customRoles:y,refetch:f}=ms(),{data:w}=ys({queryKey:ae.members(h),queryFn:()=>X.organization.listMembers()}),d=Ns({resolver:Rs(nt),defaultValues:Fe()}),I=d.formState.isValid,u=d.formState.isDirty,[j,p]=V.useState(null),[C,g]=V.useState(null),c=!d.watch("role.id")&&!d.watch("role.slug")&&!C,[v,S]=V.useState(null),[P,T]=V.useState(!1),[O,A]=V.useState(null),L=r=>{const b=r.permission||{},F=b.self||[],oe=F.includes("*"),le=oe?[]:F.filter(k=>k!=="*"),W={};for(const[k,B]of Object.entries(b))if(k!=="self")if(k==="*")for(const Z of x)B.includes("*")?W[Z.id]=Z.tools?.map(ce=>ce.name)??[]:W[Z.id]=B;else{const Z=x.find(ce=>ce.id===k);Z&&(B.includes("*")?W[k]=Z.tools?.map(ce=>ce.name)??[]:W[k]=B)}const ue=(w?.data?.members??[]).filter(k=>k.role===r.role).map(k=>k.id);return{role:{id:r.id,slug:r.role,label:r.label},allowAllStaticPermissions:oe,staticPermissions:le,toolSet:W,memberIds:ue}},E=r=>{const b=L(r);d.reset(b),p(r.id??null),g(null)},_=()=>{d.reset(Fe()),p(null),g(null),i("mcp")},z=r=>{u&&I?(A(()=>()=>E(r)),T(!0)):E(r)},N=async()=>{u&&I&&await Y(),_()},m=r=>{if(u&&I)A(()=>()=>{const b=$e(r,w?.data?.members??[]);d.reset(b),g(r),p(null),i("org")}),T(!0);else{const b=$e(r,w?.data?.members??[]);d.reset(b),g(r),p(null),i("org")}},M=r=>{if(!r&&d.formState.isDirty&&I){A(()=>()=>{l(!1),d.reset(Fe()),g(null)}),T(!0);return}if(l(r),!r)d.reset(Fe()),g(null),p(null);else{const b=y[0];if(b)E(b);else{const F=$e("user",w?.data?.members??[]);d.reset(F),g("user"),p(null),i("org")}}},U=()=>{T(!1),O&&(O(),A(null))},te=r=>{const b={};r.allowAllStaticPermissions?b.self=["*"]:r.staticPermissions.length>0&&(b.self=r.staticPermissions);for(const[F,oe]of Object.entries(r.toolSet))if(oe.length>0){const W=x.find(q=>q.id===F)?.tools?.map(q=>q.name)??[];W.length>0&&W.every(q=>oe.includes(q))?b[F]=["*"]:b[F]=oe}return b},$=he({mutationFn:async r=>{const b=te(r),F=r.role.slug||r.role.label.toLowerCase().replace(/\s+/g,"-");if(r.role.slug&&!r.role.id){const W=(w?.data?.members??[]).filter(k=>k.role===r.role.slug).map(k=>k.id),q=r.memberIds.filter(k=>!W.includes(k)),ue=W.filter(k=>!r.memberIds.includes(k));for(const k of q){const B=await X.organization.updateMemberRole({memberId:k,role:[r.role.slug]});if(B?.error)throw new Error(B.error.message)}for(const k of ue){const B=await X.organization.updateMemberRole({memberId:k,role:["user"]});if(B?.error)throw new Error(B.error.message)}return r}else if(r.role.id){const le=await X.organization.updateRole({roleId:r.role.id,data:{permission:b}});if(le?.error)throw new Error(le.error.message);const q=(w?.data?.members??[]).filter(B=>B.role===r.role.slug).map(B=>B.id),ue=r.memberIds.filter(B=>!q.includes(B)),k=q.filter(B=>!r.memberIds.includes(B));for(const B of ue){const Z=await X.organization.updateMemberRole({memberId:B,role:[r.role.slug]});if(Z?.error)throw new Error(Z.error.message)}for(const B of k){const Z=await X.organization.updateMemberRole({memberId:B,role:["user"]});if(Z?.error)throw new Error(Z.error.message)}return r}else{const le=await X.organization.createRole({role:F,permission:b});if(le?.error)throw new Error(le.error.message);for(const W of r.memberIds){const q=await X.organization.updateMemberRole({memberId:W,role:[F]});if(q?.error)throw new Error(q.error.message)}return{...r,role:{...r.role,id:le.data?.roleData?.id,slug:F}}}},onSuccess:(r,b)=>{o.invalidateQueries({queryKey:ae.members(h)}),o.invalidateQueries({queryKey:ae.organizationRoles(h)});const F=!b.role.id&&!b.role.slug,oe=b.role.slug&&!b.role.id;J.success(oe?"Members updated successfully!":F?"Role created successfully!":"Role updated successfully!"),f(),d.reset(r),r.role.id&&p(r.role.id),e?.()},onError:r=>{J.error(r instanceof Error?r.message:"Failed to save role")}}),K=he({mutationFn:async r=>{const b=await X.organization.deleteRole({roleId:r});if(b?.error)throw new Error(b.error.message);return b?.data},onSuccess:()=>{if(o.invalidateQueries({queryKey:ae.members(h)}),o.invalidateQueries({queryKey:ae.organizationRoles(h)}),J.success("Role deleted successfully!"),f(),v?.id===j){const r=y.filter(b=>b.id!==v?.id);if(r[0])E(r[0]);else{const b=$e("user",w?.data?.members??[]);d.reset(b),g("user"),p(null),i("org")}}},onError:r=>{J.error(r instanceof Error?r.message:"Failed to delete role")}}),Q=$.isPending||K.isPending,Y=async()=>{const r=d.getValues();if(!r.role.label.trim()){J.error("Role name is required"),d.setFocus("role.label");return}await $.mutateAsync(r)},re=d.handleSubmit(r=>{if(!r.role.label.trim()){J.error("Role name is required"),d.setFocus("role.label");return}$.mutate(r)}),ne=r=>{r.id&&S({id:r.id,label:r.label})},D=()=>{v?.id&&K.mutate(v.id),S(null)};return t.jsxs(Es,{open:n,onOpenChange:M,children:[t.jsx(Is,{asChild:!0,children:s}),t.jsx(Ss,{className:"sm:max-w-5xl h-[80vh] max-h-[80vh] flex flex-col p-0 overflow-hidden w-[95vw]",children:t.jsxs("div",{className:"flex-1 flex overflow-hidden min-h-0 flex-col sm:flex-row",children:[t.jsxs("div",{className:"w-full sm:w-64 sm:border-r border-b sm:border-b-0 border-border flex flex-col bg-background sm:h-full max-h-[40vh] sm:max-h-full",children:[t.jsx("div",{className:"flex-1 overflow-auto px-3.5 py-3.5 pt-3.5",children:t.jsxs("div",{className:"flex flex-col gap-1",children:[rt.map(r=>{const b=C===r.role;return t.jsxs("div",{className:ie("flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden cursor-pointer transition-colors",b?"bg-accent":"hover:bg-muted/50"),onClick:()=>m(r.role),children:[t.jsx("div",{className:ie("shrink-0 size-3 rounded-full",r.color)}),t.jsx("p",{className:"text-sm font-medium truncate flex-1",children:r.label}),t.jsx(se,{name:"lock",size:14,className:"text-muted-foreground shrink-0"})]},r.role)}),y.map(r=>{const b=j===r.id;return t.jsxs("div",{className:ie("group flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden transition-colors cursor-pointer",b?"bg-accent":"hover:bg-muted/50"),onClick:()=>z(r),children:[t.jsx("div",{className:ie("shrink-0 size-3 rounded-full",it(r.label))}),t.jsx("p",{className:"text-sm font-medium truncate flex-1",children:r.label}),t.jsxs(as,{children:[t.jsx(cs,{asChild:!0,children:t.jsx(ee,{variant:"ghost",size:"icon",className:ie("size-5 shrink-0 transition-opacity opacity-0 pointer-events-none","group-hover:opacity-100 group-hover:pointer-events-auto",b&&"opacity-100 pointer-events-auto"),onClick:F=>F.stopPropagation(),children:t.jsx(se,{name:"more_horiz",size:14})})}),t.jsx(ds,{align:"end",children:t.jsxs(Qe,{className:"text-destructive",onClick:F=>{F.stopPropagation(),ne(r)},children:[t.jsx(se,{name:"delete",size:16}),"Delete"]})})]})]},r.id)}),c&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg overflow-hidden bg-accent",children:[t.jsx("div",{className:"shrink-0 size-3 rounded-full bg-neutral-400"}),t.jsx(qs,{...d.register("role.label"),placeholder:"Enter role name",className:"flex-1 text-sm font-medium border-0 shadow-none h-auto px-0 py-0 focus-visible:ring-0 bg-transparent",autoFocus:!0}),t.jsx(Te,{variant:"secondary",className:"shrink-0 text-xs px-1.5 py-0",children:"New"})]})]})}),t.jsx("div",{className:"px-3.5 pb-3.5",children:t.jsxs(ee,{variant:"outline",size:"default",onClick:N,disabled:Q||u,className:"w-full h-10",children:[t.jsx(se,{name:"add",size:16}),"Create new role"]})})]}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[t.jsxs("div",{className:"h-12 border-b border-border px-4 py-3.5 flex items-center gap-2 shrink-0",children:[!C&&t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("mcp"),className:ie("h-8 rounded-lg px-2 py-1",a==="mcp"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"MCP Permissions"}),t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("org"),className:ie("h-8 rounded-lg px-2 py-1",a==="org"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"Organization Permissions"}),t.jsx(ee,{variant:"outline",size:"sm",onClick:()=>i("members"),className:ie("h-8 rounded-lg px-2 py-1",a==="members"?"bg-muted border-input text-foreground":"border-input text-muted-foreground bg-transparent"),children:"Members"})]}),t.jsxs("div",{className:"flex-1 overflow-hidden min-h-0",children:[a==="mcp"&&!C&&t.jsx(Ms,{toolSet:d.watch("toolSet"),onToolSetChange:r=>d.setValue("toolSet",r,{shouldDirty:!0})}),a==="org"&&t.jsx(lt,{allowAllStaticPermissions:d.watch("allowAllStaticPermissions"),staticPermissions:d.watch("staticPermissions"),onAllowAllChange:r=>d.setValue("allowAllStaticPermissions",r,{shouldDirty:!0}),onPermissionsChange:r=>d.setValue("staticPermissions",r,{shouldDirty:!0}),readOnly:!!C}),a==="members"&&t.jsx(gt,{memberIds:d.watch("memberIds"),onMemberIdsChange:r=>d.setValue("memberIds",r,{shouldDirty:!0}),readOnly:C==="owner"})]}),(!C||C!=="owner")&&t.jsxs("div",{className:"border-t border-border px-5 py-5 flex items-center justify-end gap-2.5 shrink-0",children:[t.jsx(ee,{variant:"outline",onClick:()=>M(!1),disabled:Q,className:"h-10",children:"Cancel"}),t.jsx(ee,{onClick:re,disabled:Q||!I||!d.formState.isDirty,className:"h-10",children:$.isPending?"Saving...":c?"Create Role":"Save Changes"})]})]})]})}),t.jsx(we,{open:v!==null,onOpenChange:r=>!r&&S(null),children:t.jsxs(Ae,{children:[t.jsxs(Oe,{children:[t.jsx(Re,{children:"Delete Role"}),t.jsxs(_e,{children:['Are you sure you want to delete the "',v?.label,'" role? This action cannot be undone.']})]}),t.jsxs(Pe,{children:[t.jsx(Le,{children:"Cancel"}),t.jsx(Me,{onClick:D,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),t.jsx(we,{open:P,onOpenChange:T,children:t.jsxs(Ae,{children:[t.jsxs(Oe,{children:[t.jsx(Re,{children:"Discard Changes"}),t.jsx(_e,{children:"You have unsaved changes. Are you sure you want to discard them?"})]}),t.jsxs(Pe,{children:[t.jsx(Le,{onClick:()=>A(null),children:"Keep Editing"}),t.jsx(Me,{onClick:U,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Discard"})]})]})})]})}const bt=fe().email("Invalid email address");function jt(s){if(!s.trim())return[];const e=s.split(/[,;\n]/).map(n=>n.trim().toLowerCase()).filter(n=>n.length>0);return Array.from(new Set(e))}function Ct({trigger:s}){const[e,n]=V.useState(!1),{locator:l}=ve(),a=Ze(),{data:i}=X.useSession(),h=i?.user?.email,{roles:o,isLoading:x}=ms(),y=o.filter(g=>g.role!=="owner"),f=Ns({mode:"onChange",defaultValues:{emailsText:"",role:"user"}}),w=f.watch("emailsText"),d=f.watch("role"),u=jt(w).filter(g=>{const c=bt.safeParse(g).success,v=!h||g!==h.toLowerCase();return c&&v}),j=he({mutationFn:async({emails:g,role:c})=>{if(!c)throw new Error("Please select a role");const v=await Promise.allSettled(g.map(async P=>{const T=await X.organization.inviteMember({email:P,role:c});if(T.error)throw new Error(T.error.message);return T.data})),S=v.filter(P=>P.status==="rejected");if(S.length>0)throw new Error(`Failed to invite ${S.length} member${S.length>1?"s":""}`);return v},onSuccess:(g,{emails:c})=>{a.invalidateQueries({queryKey:ae.members(l)}),a.invalidateQueries({queryKey:ae.invitations(l)}),J.success(c.length===1?"Member invited successfully!":`${c.length} members invited successfully!`),f.reset({emailsText:"",role:"user"}),n(!1)},onError:g=>{J.error(g instanceof Error?g.message:"Failed to invite members")}}),p=g=>{if(u.length===0){J.error("Please enter at least one valid email address");return}if(!g.role){J.error("Please select a role");return}j.mutate({emails:u,role:g.role})},C=u.length>0&&!!d;return t.jsxs(Es,{open:e,onOpenChange:n,children:[t.jsx(Is,{asChild:!0,children:s}),t.jsxs(Ss,{className:"sm:max-w-lg",children:[t.jsx(Gs,{children:t.jsx(Us,{children:"Invite members"})}),t.jsx(Ys,{...f,children:t.jsxs("form",{onSubmit:f.handleSubmit(p),className:"space-y-4",children:[t.jsx(fs,{control:f.control,name:"emailsText",render:({field:g})=>t.jsxs(hs,{children:[t.jsx(Ws,{children:"Email addresses"}),t.jsx(gs,{children:t.jsx(Hs,{...g,disabled:j.isPending,placeholder:`Enter email addresses separated by commas or new lines
|
|
2
2
|
e.g. user1@example.com, user2@example.com
|
|
3
3
|
or one per line`,className:"min-h-[120px] resize-none"})}),t.jsx(xs,{})]})}),t.jsx(fs,{control:f.control,name:"role",render:({field:g})=>t.jsxs(hs,{children:[t.jsx(gs,{children:t.jsxs(ts,{value:g.value,onValueChange:g.onChange,disabled:j.isPending||x,children:[t.jsx(ns,{className:"w-full",children:t.jsx(rs,{placeholder:"Select a role"})}),t.jsx(is,{children:y.map(c=>{const v=[];return c.isBuiltin||(c.allowsAllStaticPermissions?v.push("Full org access"):c.staticPermissionCount&&c.staticPermissionCount>0&&v.push(`${c.staticPermissionCount} org perm${c.staticPermissionCount!==1?"s":""}`),c.allowsAllConnections?v.push("All connections"):c.connectionCount&&c.connectionCount>0&&v.push(`${c.connectionCount} connection${c.connectionCount!==1?"s":""}`),(c.connectionCount!==0||c.allowsAllConnections)&&(c.allowsAllTools?v.push("all tools"):c.toolCount&&c.toolCount>0&&v.push(`${c.toolCount} tool${c.toolCount!==1?"s":""}`))),t.jsx(ls,{value:c.role,children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{children:c.label}),!c.isBuiltin&&v.length>0&&t.jsx("span",{className:"text-xs text-muted-foreground",children:v.join(", ")})]})},c.role)})})]})}),t.jsx(xs,{})]})}),t.jsxs(Vs,{children:[t.jsx(ee,{variant:"outline",onClick:()=>{f.reset({emailsText:"",role:"user"}),n(!1)},type:"button",disabled:j.isPending,children:"Cancel"}),t.jsx(ee,{type:"submit",disabled:j.isPending||!C,children:j.isPending?"Inviting...":`Invite ${u.length||0} Member${u.length!==1?"s":""}`})]})]})})]})]})}function vt(){const s=me.c(6),{locator:e}=ve();let n;s[0]===Symbol.for("react.memo_cache_sentinel")?(n=ks(),s[0]=n):n=s[0];const l=n;let a;s[1]!==e?(a=ae.invitations(e),s[1]=e,s[2]=a):a=s[2];let i;s[3]===Symbol.for("react.memo_cache_sentinel")?(i=async()=>(await l("ORGANIZATION_GET",{}))?.invitations??[],s[3]=i):i=s[3];let h;return s[4]!==a?(h={queryKey:a,queryFn:i},s[4]=a,s[5]=h):h=s[5],_s(h)}function Nt(){const s=me.c(5),{locator:e}=ve(),n=Ze();let l;s[0]!==e||s[1]!==n?(l={mutationFn:Et,onSuccess:()=>{n.invalidateQueries({queryKey:ae.invitations(e)}),J.success("Invitation cancelled")},onError:yt},s[0]=e,s[1]=n,s[2]=l):l=s[2];const a=he(l);let i;return s[3]!==a?(i={cancel:a},s[3]=a,s[4]=i):i=s[4],i}function yt(s){J.error(s instanceof Error?s.message:"Failed to cancel invitation")}async function Et(s){const e=await X.organization.cancelInvitation({invitationId:s});if(e?.error)throw new Error(e.error.message);return e.data}const js=["bg-neutral-400","bg-red-500","bg-orange-500","bg-amber-500","bg-yellow-500","bg-lime-500","bg-green-500","bg-emerald-500","bg-teal-500","bg-cyan-500","bg-sky-500","bg-blue-500","bg-indigo-500","bg-violet-500","bg-purple-500","bg-fuchsia-500","bg-pink-500","bg-rose-500","bg-slate-500"],It={owner:"bg-red-500",admin:"bg-blue-500",user:"bg-green-500"};function qe(s){return s?s.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2):"?"}function St(s){const e=new Map;for(const[n,l]of Object.entries(It))e.set(n,l);for(let n=0;n<s.length;n++){const l=s[n];l&&!e.has(l.role)&&e.set(l.role,js[n%js.length]??"bg-neutral-400")}return e}function Tt(s){return new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}function Ke(s){const e=me.c(79),{role:n,memberId:l,isOwner:a,roleColorMap:i,selectableRoles:h,onRoleChange:o,size:x,className:y}=s,f=x===void 0?"xs":x;let w,d,I,u,j,p,C,g,c,v,S;if(e[0]!==y||e[1]!==a||e[2]!==l||e[3]!==o||e[4]!==n||e[5]!==i||e[6]!==h||e[7]!==f){S=Symbol.for("react.early_return_sentinel");e:{const N=i.get(n)??"bg-neutral-400";if(a){let m;e[19]!==l||e[20]!==o?(m=D=>o(l,D),e[19]=l,e[20]=o,e[21]=m):m=e[21];let M;e[22]!==n?(M=t.jsx("span",{className:"capitalize truncate",children:n}),e[22]=n,e[23]=M):M=e[23];const U=t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("div",{className:ie("size-2 rounded-full shrink-0",N)}),M]});let te;e[24]!==U?(te=t.jsx(rs,{children:U}),e[24]=U,e[25]=te):te=e[25];let $;e[26]!==y||e[27]!==f||e[28]!==te?($=t.jsx(ns,{size:f,className:y,children:te}),e[26]=y,e[27]=f,e[28]=te,e[29]=$):$=e[29];let K;if(e[30]!==i||e[31]!==h){let D;e[33]!==i?(D=r=>{const b=i.get(r.role)??"bg-neutral-400";return t.jsx(ls,{value:r.role,children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:ie("size-3 rounded-full",b)}),t.jsx("span",{className:"capitalize",children:r.label})]})},r.role)},e[33]=i,e[34]=D):D=e[34],K=h.map(D),e[30]=i,e[31]=h,e[32]=K}else K=e[32];let Q;e[35]!==K?(Q=t.jsx(is,{children:K}),e[35]=K,e[36]=Q):Q=e[36];let Y;e[37]!==a||e[38]!==n||e[39]!==m||e[40]!==$||e[41]!==Q?(Y=t.jsx(Ie,{asChild:!0,children:t.jsx("div",{className:"w-fit",children:t.jsxs(ts,{value:n,onValueChange:m,disabled:a,children:[$,Q]})})}),e[37]=a,e[38]=n,e[39]=m,e[40]=$,e[41]=Q,e[42]=Y):Y=e[42];let re;e[43]===Symbol.for("react.memo_cache_sentinel")?(re=t.jsx(Se,{children:t.jsx("p",{children:"The owner role cannot be changed"})}),e[43]=re):re=e[43];let ne;e[44]!==Y?(ne=t.jsx(ye,{children:t.jsxs(Ee,{children:[Y,re]})}),e[44]=Y,e[45]=ne):ne=e[45],S=ne;break e}I=ts,g=n,e[46]!==l||e[47]!==o?(c=m=>o(l,m),e[46]=l,e[47]=o,e[48]=c):c=e[48],v=a,d=ns,p=f,C=y,w=rs,j="flex items-center gap-2 min-w-0",u=ie("size-2 rounded-full shrink-0",N)}e[0]=y,e[1]=a,e[2]=l,e[3]=o,e[4]=n,e[5]=i,e[6]=h,e[7]=f,e[8]=w,e[9]=d,e[10]=I,e[11]=u,e[12]=j,e[13]=p,e[14]=C,e[15]=g,e[16]=c,e[17]=v,e[18]=S}else w=e[8],d=e[9],I=e[10],u=e[11],j=e[12],p=e[13],C=e[14],g=e[15],c=e[16],v=e[17],S=e[18];if(S!==Symbol.for("react.early_return_sentinel"))return S;let P;e[49]!==u?(P=t.jsx("div",{className:u}),e[49]=u,e[50]=P):P=e[50];let T;e[51]!==n?(T=t.jsx("span",{className:"capitalize truncate",children:n}),e[51]=n,e[52]=T):T=e[52];let O;e[53]!==P||e[54]!==T||e[55]!==j?(O=t.jsxs("div",{className:j,children:[P,T]}),e[53]=P,e[54]=T,e[55]=j,e[56]=O):O=e[56];let A;e[57]!==w||e[58]!==O?(A=t.jsx(w,{children:O}),e[57]=w,e[58]=O,e[59]=A):A=e[59];let L;e[60]!==d||e[61]!==A||e[62]!==p||e[63]!==C?(L=t.jsx(d,{size:p,className:C,children:A}),e[60]=d,e[61]=A,e[62]=p,e[63]=C,e[64]=L):L=e[64];let E;if(e[65]!==i||e[66]!==h){let N;e[68]!==i?(N=m=>{const M=i.get(m.role)??"bg-neutral-400";return t.jsx(ls,{value:m.role,children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:ie("size-3 rounded-full",M)}),t.jsx("span",{className:"capitalize",children:m.label})]})},m.role)},e[68]=i,e[69]=N):N=e[69],E=h.map(N),e[65]=i,e[66]=h,e[67]=E}else E=e[67];let _;e[70]!==E?(_=t.jsx(is,{children:E}),e[70]=E,e[71]=_):_=e[71];let z;return e[72]!==I||e[73]!==L||e[74]!==_||e[75]!==g||e[76]!==c||e[77]!==v?(z=t.jsxs(I,{value:g,onValueChange:c,disabled:v,children:[L,_]}),e[72]=I,e[73]=L,e[74]=_,e[75]=g,e[76]=c,e[77]=v,e[78]=z):z=e[78],z}function Cs(s){const e=me.c(51),{member:n,roles:l,onChangeRole:a,onRemove:i,isUpdating:h}=s,o=h===void 0?!1:h,x=n.role==="owner";let y,f,w,d,I,u,j,p,C;if(e[0]!==x||e[1]!==o||e[2]!==n.id||e[3]!==n.role||e[4]!==a||e[5]!==l){let L;e[15]!==n.role?(L=m=>m.role!==n.role&&m.role!=="owner",e[15]=n.role,e[16]=L):L=e[16];const E=l.filter(L);d=as;let _;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=t.jsx(se,{name:"more_vert",size:20}),e[17]=_):_=e[17],e[18]!==x?(C=t.jsx(cs,{asChild:!0,children:t.jsx(ee,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",disabled:x,onClick:At,children:_})}),e[18]=x,e[19]=C):C=e[19],w=ds,j="end",p=wt,f=Fs;let z;e[20]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(se,{name:"swap_horiz",size:16}),e[20]=z):z=e[20],e[21]!==o?(u=t.jsxs($s,{disabled:o,children:[z,"Change Role"]}),e[21]=o,e[22]=u):u=e[22],y=Ks;let N;e[23]!==o||e[24]!==n.id||e[25]!==a?(N=m=>{const M=[];return m.isBuiltin||(m.allowsAllStaticPermissions?M.push("Full org access"):m.staticPermissionCount&&m.staticPermissionCount>0&&M.push(`${m.staticPermissionCount} org perm${m.staticPermissionCount!==1?"s":""}`),m.allowsAllConnections?M.push("All connections"):m.connectionCount&&m.connectionCount>0&&M.push(`${m.connectionCount} connection${m.connectionCount!==1?"s":""}`),(m.connectionCount!==0||m.allowsAllConnections)&&(m.allowsAllTools?M.push("all tools"):m.toolCount&&m.toolCount>0&&M.push(`${m.toolCount} tool${m.toolCount!==1?"s":""}`))),t.jsxs(Qe,{onClick:U=>{U.stopPropagation(),a(n.id,m.role)},disabled:o,children:[t.jsx(se,{name:m.isBuiltin?"shield":"key",size:16}),t.jsxs("span",{className:"flex flex-col",children:[t.jsx("span",{children:m.label}),!m.isBuiltin&&M.length>0&&t.jsx("span",{className:"text-xs text-muted-foreground",children:M.join(", ")})]})]},m.role)},e[23]=o,e[24]=n.id,e[25]=a,e[26]=N):N=e[26],I=E.map(N),e[0]=x,e[1]=o,e[2]=n.id,e[3]=n.role,e[4]=a,e[5]=l,e[6]=y,e[7]=f,e[8]=w,e[9]=d,e[10]=I,e[11]=u,e[12]=j,e[13]=p,e[14]=C}else y=e[6],f=e[7],w=e[8],d=e[9],I=e[10],u=e[11],j=e[12],p=e[13],C=e[14];let g;e[27]!==y||e[28]!==I?(g=t.jsx(y,{children:I}),e[27]=y,e[28]=I,e[29]=g):g=e[29];let c;e[30]!==f||e[31]!==u||e[32]!==g?(c=t.jsxs(f,{children:[u,g]}),e[30]=f,e[31]=u,e[32]=g,e[33]=c):c=e[33];let v;e[34]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(Qs,{}),e[34]=v):v=e[34];let S;e[35]!==n.id||e[36]!==i?(S=L=>{L.stopPropagation(),i(n.id)},e[35]=n.id,e[36]=i,e[37]=S):S=e[37];let P;e[38]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(se,{name:"delete",size:16}),e[38]=P):P=e[38];let T;e[39]!==S?(T=t.jsxs(Qe,{variant:"destructive",onClick:S,children:[P,"Remove Member"]}),e[39]=S,e[40]=T):T=e[40];let O;e[41]!==w||e[42]!==T||e[43]!==j||e[44]!==p||e[45]!==c?(O=t.jsxs(w,{align:j,onClick:p,children:[c,v,T]}),e[41]=w,e[42]=T,e[43]=j,e[44]=p,e[45]=c,e[46]=O):O=e[46];let A;return e[47]!==d||e[48]!==O||e[49]!==C?(A=t.jsxs(d,{children:[C,O]}),e[47]=d,e[48]=O,e[49]=C,e[50]=A):A=e[50],A}function wt(s){return s.stopPropagation()}function At(s){return s.stopPropagation()}function vs(s){const e=me.c(8),{invitationId:n,onCancel:l,isCancelling:a}=s,i=a===void 0?!1:a;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(cs,{asChild:!0,children:t.jsx(ee,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:Rt,children:t.jsx(se,{name:"more_vert",size:20})})}),e[0]=h):h=e[0];let o;e[1]!==n||e[2]!==l?(o=f=>{f.stopPropagation(),l(n)},e[1]=n,e[2]=l,e[3]=o):o=e[3];let x;e[4]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(se,{name:"cancel",size:16}),e[4]=x):x=e[4];let y;return e[5]!==i||e[6]!==o?(y=t.jsxs(as,{children:[h,t.jsx(ds,{align:"end",onClick:Ot,children:t.jsxs(Qe,{variant:"destructive",onClick:o,disabled:i,children:[x,"Cancel Invitation"]})})]}),e[5]=i,e[6]=o,e[7]=y):y=e[7],y}function Ot(s){return s.stopPropagation()}function Rt(s){return s.stopPropagation()}function _t(){const s=me.c(74),{data:e}=os(),{data:n}=vt(),l=Nt(),a=Ze(),{locator:i}=ve(),[h,o]=V.useState(null),[x,y]=V.useState(null),[f,w]=V.useState(""),[d,I]=V.useState("table"),[u,j]=V.useState("member"),[p,C]=V.useState("asc"),g=e?.data?.members;let c;s[0]!==u?(c=R=>{u===R?C(Kt):(j(R),C("asc"))},s[0]=u,s[1]=c):c=s[1];const v=c;let S=g??[],P=n??[];if(f){const R=f.toLowerCase();S=S.filter(G=>G.user?.name?.toLowerCase().includes(R)||G.user?.email?.toLowerCase().includes(R)||G.role?.toLowerCase().includes(R)),P=P.filter(G=>G.email?.toLowerCase().includes(R)||G.role?.toLowerCase().includes(R))}if(u&&p){let R;s[2]!==p||s[3]!==u?(R=(G,H)=>{let de,Ne;e:switch(u){case"member":{de=G.user?.name||"",Ne=H.user?.name||"";break e}case"role":{de=G.role||"",Ne=H.role||"";break e}case"joined":{de=G.createdAt?typeof G.createdAt=="string"?G.createdAt:G.createdAt.toISOString():"",Ne=H.createdAt?typeof H.createdAt=="string"?H.createdAt:H.createdAt.toISOString():"";break e}default:return 0}return p==="asc"?de.localeCompare(Ne):Ne.localeCompare(de)},s[2]=p,s[3]=u,s[4]=R):R=s[4],S=[...S].sort(R)}const T=S;let O;s[5]!==i||s[6]!==a?(O={mutationFn:$t,onSuccess:()=>{a.invalidateQueries({queryKey:ae.members(i)}),J.success("Member has been removed from the organization"),o(null)},onError:Ft},s[5]=i,s[6]=a,s[7]=O):O=s[7];const A=he(O);let L;s[8]!==i||s[9]!==a?(L={mutationFn:Vt,onSuccess:()=>{a.invalidateQueries({queryKey:ae.members(i)}),J.success("Member's role has been updated")},onError:Ut},s[8]=i,s[9]=a,s[10]=L):L=s[10];const E=he(L);let _;s[11]!==i||s[12]!==a?(_={mutationFn:Gt,onSuccess:()=>{a.invalidateQueries({queryKey:ae.invitations(i)}),J.success("Invitation role has been updated")},onError:Bt},s[11]=i,s[12]=a,s[13]=_):_=s[13];const z=he(_),{roles:N,customRoles:m}=ms();let M;s[14]!==m?(M=St(m),s[14]=m,s[15]=M):M=s[15];const U=M;let te;s[16]!==N?(te=N.filter(Dt),s[16]=N,s[17]=te):te=s[17];const $=te;let K;s[18]===Symbol.for("react.memo_cache_sentinel")?(K={id:"member",header:"Member",render:kt,cellClassName:"flex-1 min-w-0",sortable:!0},s[18]=K):K=s[18];let Q;s[19]!==U||s[20]!==$||s[21]!==z||s[22]!==E?(Q={id:"role",header:"Role",render:R=>R.type==="member"?t.jsx(Ke,{role:R.data.role,memberId:R.data.id,isOwner:R.data.role==="owner",roleColorMap:U,selectableRoles:$,onRoleChange:(G,H)=>E.mutate({memberId:G,role:H}),className:"w-36"}):t.jsx(Ke,{role:R.data.role,memberId:R.data.id,isOwner:!1,roleColorMap:U,selectableRoles:$,onRoleChange:(G,H)=>z.mutate({invitationId:G,role:H,email:R.data.email}),className:"w-36"}),cellClassName:"w-36 shrink-0",sortable:!0},s[19]=U,s[20]=$,s[21]=z,s[22]=E,s[23]=Q):Q=s[23];let Y;s[24]===Symbol.for("react.memo_cache_sentinel")?(Y={id:"joined",header:"Joined",render:zt,cellClassName:"w-48 shrink-0",sortable:!0},s[24]=Y):Y=s[24];let re;s[25]!==l.cancel.isPending||s[26]!==N||s[27]!==E?(re={id:"actions",header:"",render:R=>R.type==="member"?t.jsx(Cs,{member:R.data,roles:N,onChangeRole:(G,H)=>E.mutate({memberId:G,role:H}),onRemove:o,isUpdating:E.isPending}):t.jsx(vs,{invitationId:R.data.id,onCancel:y,isCancelling:l.cancel.isPending}),cellClassName:"w-12 shrink-0"},s[25]=l.cancel.isPending,s[26]=N,s[27]=E,s[28]=re):re=s[28];let ne;s[29]!==Q||s[30]!==re?(ne=[K,Q,Y,re],s[29]=Q,s[30]=re,s[31]=ne):ne=s[31];const D=ne;let r;s[32]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(pt,{trigger:t.jsxs(ee,{variant:"outline",size:"sm",className:"h-7 px-3 rounded-lg text-sm font-medium",children:[t.jsx(se,{name:"shield",size:16}),"Manage Roles"]})}),s[32]=r):r=s[32];let b;s[33]===Symbol.for("react.memo_cache_sentinel")?(b=t.jsxs("div",{className:"flex items-center gap-2",children:[r,t.jsx(Ct,{trigger:t.jsx(ee,{size:"sm",className:"h-7 px-3 rounded-lg text-sm font-medium",children:"Invite Member"})})]}),s[33]=b):b=s[33];const F=b,oe=[...T.map(Mt),...P.filter(Lt).map(Pt)],le=ss,W=!!x;let q;s[34]===Symbol.for("react.memo_cache_sentinel")?(q=()=>y(null),s[34]=q):q=s[34];let ue;s[35]===Symbol.for("react.memo_cache_sentinel")?(ue=t.jsxs(Oe,{children:[t.jsx(Re,{children:"Cancel Invitation"}),t.jsx(_e,{children:"Are you sure you want to cancel this invitation? The invitee will no longer be able to join the organization with this invitation."})]}),s[35]=ue):ue=s[35];let k;s[36]===Symbol.for("react.memo_cache_sentinel")?(k=t.jsx(Le,{children:"Keep Invitation"}),s[36]=k):k=s[36];let B;s[37]!==l.cancel||s[38]!==x?(B=()=>{x&&(l.cancel.mutate(x),y(null))},s[37]=l.cancel,s[38]=x,s[39]=B):B=s[39];let Z;s[40]!==l.cancel.isPending||s[41]!==B?(Z=t.jsxs(Ae,{children:[ue,t.jsxs(Pe,{children:[k,t.jsx(Me,{onClick:B,disabled:l.cancel.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Cancel Invitation"})]})]}),s[40]=l.cancel.isPending,s[41]=B,s[42]=Z):Z=s[42];let ce;s[43]!==W||s[44]!==Z?(ce=t.jsx(we,{open:W,onOpenChange:q,children:Z}),s[43]=W,s[44]=Z,s[45]=ce):ce=s[45];const We=!!h;let ze;s[46]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>o(null),s[46]=ze):ze=s[46];let ke;s[47]===Symbol.for("react.memo_cache_sentinel")?(ke=t.jsxs(Oe,{children:[t.jsx(Re,{children:"Remove Member"}),t.jsx(_e,{children:"Are you sure you want to remove this member from the organization? This action cannot be undone."})]}),s[47]=ke):ke=s[47];let De;s[48]===Symbol.for("react.memo_cache_sentinel")?(De=t.jsx(Le,{children:"Cancel"}),s[48]=De):De=s[48];let ge;s[49]!==h||s[50]!==A?(ge=()=>h&&A.mutate(h),s[49]=h,s[50]=A,s[51]=ge):ge=s[51];let xe;s[52]!==A.isPending||s[53]!==ge?(xe=t.jsxs(Ae,{children:[ke,t.jsxs(Pe,{children:[De,t.jsx(Me,{onClick:ge,disabled:A.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]}),s[52]=A.isPending,s[53]=ge,s[54]=xe):xe=s[54];let pe;s[55]!==We||s[56]!==xe?(pe=t.jsx(we,{open:We,onOpenChange:ze,children:xe}),s[55]=We,s[56]=xe,s[57]=pe):pe=s[57];let Be;s[58]===Symbol.for("react.memo_cache_sentinel")?(Be=[{id:"member",label:"Name"},{id:"role",label:"Role"},{id:"joined",label:"Joined"}],s[58]=Be):Be=s[58];let be;s[59]!==v||s[60]!==p||s[61]!==u||s[62]!==d?(be=t.jsx(Ps,{title:"Members",viewMode:d,onViewModeChange:I,sortKey:u,sortDirection:p,onSort:v,sortOptions:Be,ctaButton:F}),s[59]=v,s[60]=p,s[61]=u,s[62]=d,s[63]=be):be=s[63];let Ge;s[64]===Symbol.for("react.memo_cache_sentinel")?(Ge=R=>{R.key==="Escape"&&(w(""),R.target.blur())},s[64]=Ge):Ge=s[64];let je;s[65]!==f?(je=t.jsx(Ye,{value:f,onChange:w,placeholder:"Search members...",onKeyDown:Ge}),s[65]=f,s[66]=je):je=s[66];const He=d==="cards"?t.jsx("div",{className:"flex-1 overflow-auto p-5",children:oe.length===0?t.jsx(Xe,{title:"No members found",description:f?`No members match "${f}"`:"Invite members to get started."}):t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-4",children:oe.map(R=>{if(R.type==="invitation")return t.jsxs(ps,{className:"transition-colors relative opacity-75",children:[t.jsx("div",{className:"absolute top-4 right-4 z-10",children:t.jsx(vs,{invitationId:R.data.id,onCancel:y,isCancelling:l.cancel.isPending})}),t.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[t.jsx(Ce,{fallback:qe(R.data.email),shape:"circle",size:"lg",className:"shrink-0"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-base font-medium text-foreground truncate",children:R.data.email}),t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(Te,{variant:"outline",className:"w-fit text-amber-600 border-amber-400",children:"Pending"})}),t.jsx(Ke,{role:R.data.role,memberId:R.data.id,isOwner:!1,roleColorMap:U,selectableRoles:$,onRoleChange:(H,de)=>z.mutate({invitationId:H,role:de,email:R.data.email}),className:"w-fit"})]})]})]},`inv-${R.data.id}`);const G=R.data;return t.jsxs(ps,{className:"transition-colors relative",children:[t.jsx("div",{className:"absolute top-4 right-4 z-10",children:t.jsx(Cs,{member:G,roles:N,onChangeRole:(H,de)=>E.mutate({memberId:H,role:de}),onRemove:o,isUpdating:E.isPending})}),t.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[t.jsx(Ce,{url:G.user?.image??void 0,fallback:qe(G.user?.name),shape:"circle",size:"lg",className:"shrink-0"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-base font-medium text-foreground truncate",children:G.user?.name||"Unknown"}),t.jsx("p",{className:"text-sm text-muted-foreground truncate",children:G.user?.email}),t.jsx(Ke,{role:G.role,memberId:G.id,isOwner:G.role==="owner",roleColorMap:U,selectableRoles:$,onRoleChange:(H,de)=>E.mutate({memberId:H,role:de}),className:"w-fit"})]})]})]},G.id)})})}):t.jsx(Ls,{columns:D,data:oe,isLoading:!1,sortKey:u,sortDirection:p,onSort:v,emptyState:f?t.jsx(Xe,{title:"No members found",description:`No members match "${f}"`}):t.jsx(Xe,{title:"No members found",description:"Invite members to get started."})});let Ue;return s[67]!==le||s[68]!==ce||s[69]!==pe||s[70]!==be||s[71]!==je||s[72]!==He?(Ue=t.jsxs(le,{children:[ce,pe,be,je,He]}),s[67]=le,s[68]=ce,s[69]=pe,s[70]=be,s[71]=je,s[72]=He,s[73]=Ue):Ue=s[73],Ue}function Pt(s){return{type:"invitation",data:s}}function Lt(s){return s.status==="pending"}function Mt(s){return{type:"member",data:s}}function zt(s){return s.type==="member"?t.jsx("span",{className:"text-sm text-foreground",children:s.data.createdAt?Tt(s.data.createdAt):"N/A"}):t.jsx(Te,{variant:"outline",children:"Pending"})}function kt(s){return s.type==="member"?t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Ce,{url:s.data.user?.image??void 0,fallback:qe(s.data.user?.name),shape:"circle",size:"sm"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:s.data.user?.name||"Unknown"}),t.jsx("div",{className:"text-sm text-muted-foreground truncate",children:s.data.user?.email})]})]}):t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Ce,{fallback:qe(s.data.email),shape:"circle",size:"sm"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:s.data.email}),t.jsx("div",{className:"text-sm text-muted-foreground truncate",children:"Invitation sent"})]})]})}function Dt(s){return s.role!=="owner"}function Bt(s){J.error(s instanceof Error?s.message:"Failed to update invitation role")}async function Gt(s){const{invitationId:e,role:n,email:l}=s,a=await X.organization.cancelInvitation({invitationId:e});if(a?.error)throw new Error(a.error.message);const i=await X.organization.inviteMember({email:l,role:n});if(i?.error)throw new Error(i.error.message)}function Ut(s){J.error(s instanceof Error?s.message:"Failed to update role")}async function Vt(s){const{memberId:e,role:n}=s,l=await X.organization.updateMemberRole({memberId:e,role:[n]});if(l?.error)throw new Error(l.error.message)}function Ft(s){J.error(s instanceof Error?s.message:"Failed to remove member")}async function $t(s){const e=await X.organization.removeMember({memberIdOrEmail:s});if(e?.error)throw new Error(e.error.message)}function Kt(s){return s==="asc"?"desc":s==="desc"?null:"asc"}function Nn(){const s=me.c(2);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(ss,{children:t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx("div",{className:"text-sm text-muted-foreground",children:"Failed to load members"})})}),s[0]=e):e=s[0];let n;return s[1]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx(Zs,{fallback:e,children:t.jsx(V.Suspense,{fallback:t.jsx(ss,{children:t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(se,{name:"progress_activity",size:32,className:"animate-spin text-muted-foreground"})})}),children:t.jsx(_t,{})})}),s[1]=n):n=s[1],n}export{Nn as default};
|