1import{r as x,j as s,L as ee}from"./vendor-react-DwdBSULw.js";import{d as H,b as N,S as k,a as ce,u as te,c as ne,e as se,f as de,P as ue,g as K}from"./DevPortalApp-CxBpfIBH.js";import{aA as me,aC as Y,az as E,ak as pe,N as oe,g as he,L as ge}from"./index-CevYBHts.js";import{S as L}from"./Skeleton-apTqROKr.js";import{S as fe}from"./StatusPill-ChaQefx9.js";import{P as ae}from"./Panel-SwuYqry0.js";import{d as _e,a as ve,c as ke,u as we,b as be}from"./connectionRows-XC5sGhfc.js";import{d as je,u as xe}from"./domainStatus-D8Vmij_C.js";import{l as ye,p as Se,f as y,a as Ne,b as S,u as Ae,c as $e,s as ie,d as Me,e as Te,g as Le,h as Ie}from"./usageMath-HoT2n9aS.js";import{l as Ce}from"./peopleData-C3tU7pkb.js";import"./vendor-editor-Bzbrp23R.js";import"./vendor-icons-Cm-8eP2T.js";import"./vendor-supabase-u_RV3o_X.js";import"./vendor-socketio-DElUTK9t.js";import"./vendor-markdown-CZNCj_Y9.js";import"./vendor-katex-BhPo-4pa.js";import"./groupCredentials-oIl8Fk7K.js";import"./mcpInstall-Dg0dxRT1.js";function le(e){const t=me(),o=t.getQueryData(H.people(e));return{teamsLoaded:t.getQueryData(H.teams(e))!==void 0,peopleLoaded:o!==void 0,invitesAvailable:o?.pendingInvitesAvailable!==!1}}const D=5,W={bad:0,warn:1,idle:2,none:3},Pe=e=>[...e].sort((t,o)=>W[t.tone]-W[o.tone]),Ee=e=>e.tone==="idle"&&e.label==="Status unknown";function U(e,{to:t,noun:o,key:l}){const a=Pe(e);if(a.length<=D)return a;const i=a.slice(0,D),n=a.length-D;return[...i,{key:`${l}-more`,tone:"none",title:`And ${n} more ${o}`,detail:"",to:t,linkLabel:"See all"}]}function q({platformId:e,connection:t,kind:o,described:l}){const a=ke(t),i=N({platformId:e,screen:k.capabilities,tab:"connections"}),n=`connection-${o}-${t.id??a}`;return Ee(l)?{key:n,tone:"idle",title:`Can't tell whether ${a} is working`,detail:"Its status is unknown.",to:i,linkLabel:"Open connections"}:l.needsAuth?{key:n,tone:"warn",title:`${a} needs authorization`,detail:"Its tools won't work until someone signs in to it.",to:i,linkLabel:"Authorize"}:l.tone==="bad"?{key:n,tone:"bad",title:`${a} has an error`,detail:"Open it to see what went wrong.",to:i,linkLabel:"Open connections"}:null}function De({platformId:e,mcp:t=[],openApi:o=[]}){const l=[];for(const a of t){const i=q({platformId:e,connection:a,kind:"mcp",described:_e(a)});i&&l.push(i)}for(const a of o){const i=q({platformId:e,connection:a,kind:"openapi",described:ve(a)});i&&l.push(i)}return U(l,{key:"connections",noun:"connections",to:N({platformId:e,screen:k.capabilities,tab:"connections"})})}function Oe({platformId:e,teams:t,caps:o,now:l=Date.now()}){const a=[];for(const i of t){const n=o[i.group_id];if(!n)continue;const r=ye(n.tokens_used,n.token_limit),p=Se({used:n.tokens_used,limit:n.token_limit,periodStart:n.period_start,now:l});if(!r&&p===null)continue;const d=i.group_name||"Unnamed team",u=`${y(n.tokens_used)} of ${y(n.token_limit)} tokens used this month.`,c=n.hard_block_at_100===!0?" Its requests will stop when it does.":n.hard_block_at_100===!1?" It can keep going past the limit.":"";let m,h=u;r==="reached"?m=`${d} has reached its monthly token limit`:r==="near"?(m=`${d} has used ${Ne(n.tokens_used,n.token_limit)}% of its monthly token limit`,p!==null&&(h+=` At this month's rate so far it reaches the limit around ${S(p)}.${c}`)):(m=`${d} is on track to reach its monthly token limit around ${S(p)}`,h+=`${c}`),a.push({key:`team-limit-${i.group_id}`,tone:r==="reached"?"bad":"warn",title:m,detail:h,to:ce({platformId:e,groupId:i.group_id,tab:"usage"}),linkLabel:"Review limit"})}return U(a,{key:"team-limits",noun:"teams nearing their limit",to:N({platformId:e,screen:k.usage})})}function Fe({platformId:e,domains:t}){const o=N({platformId:e,screen:k.settings,tab:"email-domains"}),l=[];for(const a of t){const i=je(a);if(a?.domain_ready===!0||Array.isArray(a?.domain_ready_issues)&&a.domain_ready_issues.includes("status_disabled"))continue;const n=typeof a?.domain=="string"&&a.domain?a.domain:"A sending domain",r=i.label==="Status not available";l.push({key:`domain-${a.id??n}`,tone:r?"idle":i.tone==="bad"?"bad":"warn",title:r?`Can't tell whether ${n} is ready to send email`:`${n}
1 isn't ready to send email`,detail:r?"Its status is unknown.":i.label,to:o,linkLabel:"Open email domains"})}return U(l,{key:"domains",noun:"domains",to:o})}const We=2880*60*1e3;function Ue({platformId:e,invites:t,now:o=Date.now()}){const l=t.filter(i=>{const n=Date.parse(i?.expiresAt);return Number.isFinite(n)&&n>o&&n<=o+We});if(l.length===0)return[];const a=l.length;return[{key:"ending-invites",tone:"warn",title:a===1?"An invitation ends within 2 days":`${a} invitations end within 2 days`,detail:`${Ce(l.map(i=>i.email))} must accept soon, or be invited again.`,to:N({platformId:e,screen:k.people}),linkLabel:"Review invitations"}]}const Re=50,Be=6e4,Qe=1500;function Ge(e){const[t,o]=x.useState(!1);return x.useEffect(()=>{const l=()=>o(!0),a=pe?.onFlagsChange?.(l),i=setTimeout(l,Qe);return()=>{clearTimeout(i),typeof a=="function"&&a()}},[]),t||e}const X=(e,t,o)=>e===1?t:o;function ze(){const{sessionToken:e,platformId:t,permissions:o}=te(),l=Y("mcp_connection"),a=Y("email_domains"),i=Ge(l&&a),n=!!o.canManageTools,r=!!o.canManageWorkspaceGroups,p=r&&a,d=!!o.canManageWorkspaceUsers,u=we({sessionToken:e,platformId:t,enabled:n&&l}),c=be({sessionToken:e,platformId:t,enabled:n}),m=ne({sessionToken:e,platformId:t,enabled:r}),h=xe({sessionToken:e,platformId:t,enabled:p}),f=se({sessionToken:e,platformId:t,enabled:d}),{teamsLoaded:w,peopleLoaded:I,invitesAvailable:R}=le(t),M=m.teams,A=x.useMemo(()=>r&&w?M.slice(0,Re):E,[r,w,M]),T=x.useMemo(()=>A.map(b=>b.group_id),[A]),B=Ae({sessionToken:e,platformId:t,groupIds:T,enabled:r&&T.length>0,staleTime:Be});return x.useMemo(()=>{const b=[],_=[];let j=!i;if(n){const g=l;g&&u.loading&&(j=!0),c.loading&&(j=!0),g&&u.error&&_.push("MCP connections"),c.error&&_.push("API connections"),b.push(De({platformId:t,mcp:g&&!u.loading&&!u.error?u.data:E,openApi:!c.loading&&!c.error?c.data:E}))}if(r)if(!w&&m.loading)j=!0;else if(!w)_.push("team limits");else{const g={};let v=0,G=!1;for(const z of T){const P=B[z];P?.cap?g[z]=P.cap:P?.loading?G=!0:v+=1}G&&(j=!0),b.push(Oe({platformId:t,teams:A,caps:g})),v>0&&_.push(`limits for ${v} ${X(v,"team","teams")}`);const C=M.length-A.length;C>0&&_.push(`limits for ${C} more ${X(C,"team","teams")}`)}p&&(h.loading?j=!0:h.error?_.push("email domains"):b.push(Fe({platformId:t,domains:h.domains}))),d&&(!I&&f.loading?j=!0:!I||!R?_.push("invitations"):b.push(Ue({platformId:t,invites:f.pendingInvites})));const Q=g=>Math.min(...g.map(v=>W[v.tone])),re=b.filter(g=>g.length>0).sort((g,v)=>Q(g)-Q(v)).flat(),$=[];return n&&$.push("connections"),r&&$.push("team limits"),p&&$.push("email domains"),d&&$.push("invitations"),{items:re,unchecked:_,loading:j,checked:$,complete:n&&r&&d}},[i,t,n,r,p,d,l,u.loading,u.error,u.data,c.loading,c.error,c.data,w,m.loading,M,A,T,B,h.loading,h.error,h.domains,I,f.loading,f.pendingInvites,R])}const V={bad:"Problem",warn:"Needs attention",idle:"Unknown"},J=e=>e.length<=2?e.join(" and "):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;function He(){const{items:e,unchecked:t,loading:o,checked:l,complete:a}=ze(),i=!o&&e.length===0;return s.jsxs(ae,{title:"Needs attention",description:"Things in this workspace that need someone to act.",children:[e.length>0?s.jsx("ul",{className:"dp-overview__attention","aria-label":"Needs attention",children:e.map(n=>s.jsxs("li",{className:"dp-overview__attention-item",children:[V[n.tone]?s.jsx(fe,{tone:n.tone,children:V[n.tone]}):s.jsx("span",{"aria-hidden":"true"}),s.jsxs("div",{className:"dp-overview__attention-text",children:[s.jsx("p",{className:"dp-overview__attention-title",children:n.title}),n.detail?s.jsx("p",{className:"dp-overview__attention-detail",children:n.detail}):null]}),s.jsx(ee,{className:"dp-overview__attention-link",to:n.to,children:n.linkLabel})]},n.key))}):null,o?s.jsxs("div",{className:"dp-overview__attention-loading","aria-busy":"true","aria-label":"Checking what needs attention",children:[s.jsx(L,{width:"100%",height:18}),s.jsx(L,{width:"70%",height:18})]}):null,i&&l.length===0?s.jsx("p",{className:"dp-overview__muted",role:"status",children:"Your role in this workspace has nothing to review here."}):null,i&&l.length>0&&t.length===0?s.jsx("p",{className:"dp-overview__all-clear",role:"status",children:a?"Nothing needs attention.":`No problems with your ${J(l)}.`}):null,i&&l.length>0&&t.length>0?s.jsx("p",{className:"dp-overview__muted",role:"status",children:"Nothing else needs attention in what we could check."}):null,t.length>0?s.jsx("div",{className:"dp-overview__notice",children:s.jsxs(oe,{type:"inline",level:"warning",children:["Couldn't check ",J(t),". Reload the page to try again."]})}):null]})}const Z=1440*60*1e3,Ke=()=>new Date(ie()).toISOString();
1function O({label:e,to:t,state:o,count:l}){return s.jsxs(ee,{className:"dp-overview__tile",to:t,children:[s.jsx("span",{className:"dp-overview__tile-label",children:e}),o==="loading"?s.jsx(L,{width:40,height:26}):o==="failed"?s.jsx("span",{className:"dp-overview__tile-note",children:"Couldn't load"}):s.jsx("span",{className:"dp-overview__tile-count",children:l})]})}const F=({loaded:e,loading:t})=>e?"ready":t?"loading":"failed";function Ye({metrics:e}){const t=e.updatedAt||Date.now(),{days:o,totals:l,total:a}=x.useMemo(()=>{const d=Math.floor(t/Z)*Z,u=ie(t),c=Me(e.records,{startDay:u,endDay:d}),m=Te(c,{view:"total",labelFor:()=>"All teams"});return{days:c.days,totals:m[0]?.data??[],total:c.grandTotal}},[e.records,t]),i=Le({monthToDate:a,now:t}),n=Ie(new Date(i.monthStart).toISOString()),r=Math.max(0,...l),p=`Tokens per day, month to date: ${y(a)} in total.`;return s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"dp-overview__usage-total",children:[s.jsx("strong",{children:y(a)})," tokens month to date"]}),s.jsx("p",{className:"dp-overview__usage-projection",children:i.projected===null?`A projection for ${n||"this month"} appears from ${S(i.availableFrom)}.`:s.jsxs(s.Fragment,{children:["Projected for ",n||"this month",": about ",s.jsx("strong",{children:y(i.projected)})," tokens, at this month's rate so far"]})}),s.jsx("div",{className:"dp-overview__bars",role:"img","aria-label":p,children:o.map((d,u)=>{const c=l[u]??0;return s.jsx("span",{className:"dp-overview__bar",title:`${S(d)}: ${y(c)} tokens`,style:{height:r>0?`${Math.max(c>0?4:0,c/r*100)}%`:"0%"}},d)})}),s.jsxs("p",{className:"dp-overview__usage-axis",children:[s.jsx("span",{children:o.length?S(o[0]):""}),s.jsx("span",{children:o.length?S(o[o.length-1]):""})]})]})}function qe(){const{sessionToken:e,platformId:t,permissions:o}=te(),l=!!o.canAccessGroupManagement,a=!!o.canManageWorkspaceUsers,i=!!o.canManageWorkspaceGroups,n=de({sessionToken:e,platformId:t,enabled:!!o.canManageAis}),r=ne({sessionToken:e,platformId:t,enabled:l}),p=se({sessionToken:e,platformId:t,enabled:a}),{teamsLoaded:d,peopleLoaded:u}=le(t),[c]=x.useState(Ke),m=$e({sessionToken:e,platformId:t,enabled:i,startDate:c}),h=F({loaded:!n.loading&&(!n.error||n.ais.length>0),loading:n.loading}),f=w=>N({platformId:t,screen:w});return!o.canManageAis&&!l&&!a&&!i?null:s.jsxs(ae,{title:"Summary",description:"What's in this workspace.",children:[s.jsxs("div",{className:"dp-overview__tiles",children:[o.canManageAis?s.jsx(O,{label:"AIs",to:f(k.ais),state:h,count:n.ais.length}):null,l?s.jsx(O,{label:"Teams",to:f(k.teams),state:F({loaded:d,loading:r.loading}),count:r.teams.length}):null,a?s.jsx(O,{label:"People",to:f(k.people),state:F({loaded:u,loading:p.loading}),count:p.people.length}):null]}),i?s.jsxs("section",{className:"dp-overview__usage","aria-label":"Tokens per day",children:[s.jsx("h3",{className:"dp-overview__subtitle",children:"Tokens per day"}),m.loading?s.jsx("div",{"aria-busy":"true","aria-label":"Loading usage",children:s.jsx(L,{width:"100%",height:72})}):m.error?s.jsxs(oe,{type:"inline",level:"error",children:["Couldn't load usage. ",he(m.error)," ",s.jsx(ge,{type:"button",variant:"secondary",onClick:()=>m.refetch(),children:"Try again"})]}):s.jsx(Ye,{metrics:m})]}):null]})}function gt(){return s.jsxs("div",{className:"dp-overview",children:[s.jsx(ue,{title:K.overview.label,description:K.overview.description}),s.jsx(He,{}),s.jsx(qe,{})]})}export{gt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.