1import{j as e}from"./ui-vendor-DSsww-Kv.js";import{a as et}from"./github-Co6ooy2d.js";import{f as ae,a6 as tt,i as st,ay as G,an as ue,A as Fe,b0 as Ne,ax as $e,bX as _e,w as Se,a1 as re,bT as pe,B as b,a2 as R,aD as Ke,ap as nt,C as at,bY as rt,bZ as it,b_ as ot,b$ as lt,ao as Ge,D as ct,h as dt,k as mt,n as Ee,u as ut,H as pt,b7 as xt,c0 as ht,c1 as ft,c2 as gt,a as Ie,b1 as Z,c3 as jt,c4 as vt}from"./index-DAt3PBr5.js";import{a as p,f as bt,u as Nt}from"./react-vendor-NvA41F0Y.js";import{C as yt,l as wt,r as Ct}from"./mcp-applications-R6BN6k6t.js";import{S as Oe}from"./section-eyebrow-CV8sKsMi.js";import{R as Me,a as ee}from"./resource-creation-drawer-IGTtlW2D.js";import{A as O,a as ye,b as M}from"./alert-CdSoCuqw.js";import{A as Le,a as te,b as se,c as ne}from"./accordion-CCygrFR4.js";import{B as y}from"./badge-BSg2mDhB.js";import{C as kt}from"./checkbox-lOGwPh8b.js";import{D as Ue,a as Be,b as Ve,c as Qe,d as He,e as We}from"./dialog-DrheB7Vn.js";import{I}from"./input-BJ_IkYk8.js";import{L as k}from"./label-C1gC47fQ.js";import{R as xe}from"./refresh-cw-BSg9mvOJ.js";import{B as _t,S as ge}from"./shield-alert-C32DFOSD.js";import{C as we}from"./copy-ChdxLeGu.js";import{K as St}from"./key-round-CZtI2O6J.js";import{P as Xe}from"./plus-CMs130Xd.js";import{T as me}from"./trash-2-Bw-aIahY.js";import{S as Dt}from"./shield-check-DLUm19LA.js";import{C as At}from"./clock-3-CWBvcaQ7.js";import{D as Pt}from"./workspace-primitives-C1dQ4mvy.js";import{S as Et,a as It,b as Rt,c as Tt,d as ce}from"./select-A6ob4bc1.js";import{f as Ye}from"./format-DGcDGe_R.js";import{E as zt}from"./ellipsis-vertical-B_bW3UAA.js";import{P as qt}from"./production-action-pending-dialog-x39UKPyM.js";import{u as Ft}from"./use-view-transition-navigate-OfoUcrvx.js";import{P as Re,g as $t}from"./project-name-DAeWzcZ9.js";import{u as Kt}from"./use-github-oauth-popup-Czf39eUM.js";import{A as Gt,a as Ot,b as Mt}from"./avatar-CGtqDp-M.js";import{T as Lt}from"./textarea-LEDzw1AN.js";import{S as Ut}from"./save-Buv2rZAi.js";import{G as Bt}from"./github-Ntk7cmZH.js";import"./index-CZfdWZD3.js";import"./chevron-down-CcJPVXaR.js";import"./box-Bz_4p_Hp.js";import"./github-oauth-C5UKpHTL.js";const De={all:["agent-resource-deletions"],list:t=>[...De.all,t]};function Vt(){const t=ae(),s=t.organizationId??"";return tt({queryKey:G(t,De.list(s)),queryFn:({signal:n})=>$e.forTenant(t).get("/resource-deletions?limit=100",{signal:n}),enabled:st(t),refetchInterval:15e3})}function Je(t){const s=ae(),n=ue(),a=Fe();return Ne({mutationFn:o=>n.run(s,({scope:m,signal:l})=>$e.forTenant(m).post(`/resource-deletions/${o}/${t}`,{},{signal:l})),onMutate:()=>n.capture(s),onSuccess:(o,m,l)=>{n.commit(l,()=>{const g=l.organizationId;a.setQueryData(G(l,De.list(g)),(h=[])=>h.map(u=>u.id===o.id?o:u))})}})}function Qt(){return Je("approve")}function Ht(){return Je("cancel")}function Ae(t,s){return{headers:{[yt]:t.organizationId},signal:s}}function Wt(t,s){return _e(t,s,n=>Se.oauth2.getClients({fetchOptions:Ae(t,n)}))}function Xt(t,s,n){return _e(t,n,a=>Se.oauth2.createClient({...s,fetchOptions:Ae(t,a)}))}function Yt(t,s,n){return _e(t,n,a=>Se.oauth2.deleteClient({...s,fetchOptions:Ae(t,a)}))}const je=Ke("mcpResourceURL","https://mcp.resilis.io"),ve=Ke("authBaseURL","https://auth.resilis.io/api/auth").replace(/\/$/,""),Jt=`${ve.endsWith("/api/auth")?ve:`${ve}/api/auth`}/oauth2/token`,Zt=[{id:"resilis:observe",label:"Observe",description:"Read projects, resources, deployments, logs, and health."},{id:"resilis:deploy",label:"Deploy",description:"Create deployments, redeploy applications, and roll back releases."},{id:"resilis:operate",label:"Operate",description:"Start, stop, and restart resources."},{id:"resilis:configure",label:"Configure",description:"Create resources and update configuration or secret values."},{id:"resilis:delete:request",label:"Request deletion",description:"Prepare deleti
1on requests and calculate their impact.",sensitive:!0},{id:"resilis:delete:execute",label:"Execute approved deletion",description:"Schedule deletions after any required approval.",sensitive:!0}];function es(){const{toast:t}=re(),s=ae(),n=ue(),[a,o]=p.useState([]),[m,l]=p.useState([]),[g,h]=p.useState(!0),[u,j]=p.useState(null),[v,f]=p.useState(!1),[x,C]=p.useState(!1),[_,w]=p.useState(""),[D,q]=p.useState(["resilis:observe"]),[A,N]=p.useState(null),[P,L]=p.useState(null),[H,W]=p.useState(null),$=Vt(),K=($.data||[]).filter(r=>["prepared","approved","scheduled","deleting"].includes(r.status)).length,[U,ie]=p.useState(["connected-agents"]),X=p.useRef(0),oe=p.useRef(null),B=p.useCallback(async(r=!0)=>{let i;try{i=n.capture(s)}catch{return}n.commit(i,()=>{r&&h(!0),j(null)});try{const[d,c]=await n.run(i,({scope:S,signal:le})=>Promise.all([wt(S.organizationId,le),Wt({userId:S.userId,sessionGeneration:S.sessionGeneration,organizationId:S.organizationId},le)]));if(c.error)throw new Error(c.error.message);n.commit(i,()=>{o(d),l((c.data||[]).filter(S=>S.grant_types?.includes("client_credentials")))})}catch(d){n.commit(i,()=>{const c=d instanceof Error?d.message:"Unknown error";j(c),t({title:"Could not load agent access",description:c,variant:"destructive"})})}finally{r&&h(!1)}},[n,s,t]);p.useEffect(()=>{B()},[B]),p.useEffect(()=>{K>0&&X.current===0&&ie(r=>r.includes("deletion-approvals")?r:[...r,"deletion-approvals"]),X.current=K},[K]);const he=()=>{w(""),q(["resilis:observe"]),N(null)},V=r=>{f(r),r||he()},E=r=>{q(i=>i.includes(r)?i.filter(d=>d!==r):[...i,r])},Y=async()=>{const r=_.trim();if(!r||D.length===0)return;let i;try{i=n.capture(s)}catch{return}n.commit(i,()=>C(!0));try{const d=await n.run(i,({scope:c,signal:S})=>Xt({userId:c.userId,sessionGeneration:c.sessionGeneration,organizationId:c.organizationId},{client_name:r,redirect_uris:[je],scope:D.join(" "),token_endpoint_auth_method:"client_secret_basic",grant_types:["client_credentials"]},S));if(d.error)throw new Error(d.error.message);if(!d.data?.client_secret)throw new Error("The authorization server did not return a client secret.");n.commit(i,()=>{N({clientID:d.data.client_id,clientSecret:d.data.client_secret,name:r})}),await B(!1)}catch(d){n.commit(i,()=>{t({title:"Could not create key",description:d instanceof Error?d.message:"Unknown error",variant:"destructive"})})}finally{C(!1)}},fe=async r=>{let i;try{i=n.capture(s)}catch{return}n.commit(i,()=>W(r));try{const d=await n.run(i,({scope:c,signal:S})=>Yt({userId:c.userId,sessionGeneration:c.sessionGeneration,organizationId:c.organizationId},{client_id:r},S));if(d.error)throw new Error(d.error.message);n.commit(i,()=>{l(c=>c.filter(S=>S.client_id!==r)),t({title:"Key revoked",description:"This client can no longer obtain access tokens."})})}catch(d){n.commit(i,()=>{t({title:"Could not revoke key",description:d instanceof Error?d.message:"Unknown error",variant:"destructive"})})}finally{W(null)}},J=async r=>{let i;try{i=n.capture(s)}catch{return}n.commit(i,()=>L(r.id));try{await n.run(i,({scope:d,signal:c})=>Ct(r.id,d.organizationId,c)),n.commit(i,()=>{o(d=>d.filter(c=>c.id!==r.id)),t({title:"Agent disconnected",description:"Every active token for this app and organization has been revoked."})})}catch(d){n.commit(i,()=>{t({title:"Could not disconnect agent",description:d instanceof Error?d.message:"Unknown error",variant:"destructive"})})}finally{L(null)}},T=async(r,i="Value")=>{if(!navigator.clipboard){t({title:"Copy failed",description:"Clipboard access is not available in this browser.",variant:"destructive"});return}try{await navigator.clipboard.writeText(r),t({title:`${i} copied`})}catch{t({title:"Copy failed",description:"Clipboard access was denied.",variant:"destructive"})}};return e.jsxs("div",{className:"space-y-5",children:[u?e.jsxs(O,{variant:"destructive",children:[e.jsx(pe,{className:"h-4 w-4"}),e.jsx(ye,{children:"Agent access is temporarily unavailable"}),e.jsxs(M,{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("span",{className:"break-words",children:u}),e.jsxs(b,{className:"h-8",onClick:()=>{B()},size:"sm",variant:"outline",children:[e.jsx(xe,{className:"mr-2 h-3.5 w-3.5"}),"Retry"]})]})]}):null,e.jsxs("section",{className:"border border-cool-border bg-surface-primary",children:[e.jsxs("div",{className:"flex items-start gap-3 px-5 py-5",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center bg-resil
1is-core/10 text-resilis-core",children:e.jsx(_t,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(Oe,{muted:!0,children:"Interactive connection"}),e.jsx("h2",{className:"mt-1.5 text-sm font-semibold text-foreground",children:"Connect from an MCP-compatible agent"}),e.jsx("p",{className:"mt-1 max-w-[72ch] text-xs leading-5 text-muted-foreground",children:"Add this endpoint in your agent or development tool. Resilis opens a browser authorization flow so you can review access before anything is connected."})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 border-t border-mist-line bg-field-muted px-5 py-3 sm:flex-row sm:items-center",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs leading-5 text-foreground",children:je}),e.jsxs(b,{className:"h-9 shrink-0",onClick:()=>{T(je,"MCP endpoint")},size:"sm",variant:"outline",children:[e.jsx(we,{className:"mr-2 h-3.5 w-3.5"}),"Copy endpoint"]})]})]}),e.jsxs(Le,{className:"space-y-3",onValueChange:ie,type:"multiple",value:U,children:[e.jsxs(te,{className:"border border-cool-border bg-surface-primary",value:"connected-agents",children:[e.jsxs(se,{className:"min-h-14 gap-4 px-5 py-3 text-left hover:no-underline",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground",children:"Connected agents"}),e.jsx("span",{className:"mt-0.5 block text-xs font-normal leading-5 text-muted-foreground",children:"Browser-approved apps with access to this organization."})]}),e.jsxs(y,{className:"ml-auto shrink-0",variant:"outline",children:[a.length," connected"]})]}),e.jsx(ne,{className:"border-t border-mist-line p-0",children:e.jsx("div",{className:"divide-y divide-mist-line",children:g?e.jsx(Ce,{label:"Loading connected agents"}):a.length===0?e.jsx(ze,{detail:"Start the authorization flow from your agent using the endpoint above.",title:"No agents connected"}):a.map(r=>e.jsxs("div",{className:"flex flex-col gap-4 px-5 py-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"break-words text-sm font-semibold text-foreground",children:r.name}),e.jsx(y,{variant:"info",children:"OAuth"}),r.verified?e.jsx(y,{variant:"success",children:"Verified"}):e.jsx(y,{variant:"outline",children:"Unverified"})]}),e.jsxs("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:["Connected ",as(r.createdAt),r.installationCount>1?` · ${r.installationCount} installations`:""]}),e.jsx(Te,{scopes:r.scopes})]}),e.jsxs(b,{className:"h-9 shrink-0 self-start",disabled:P===r.id,onClick:()=>{J(r)},size:"sm",variant:"outline",children:[P===r.id?e.jsx(R,{className:"mr-2 h-3.5 w-3.5"}):null,"Disconnect"]})]},r.id))})})]}),e.jsxs(te,{className:"border border-cool-border bg-surface-primary",value:"automation-keys",children:[e.jsxs(se,{className:"min-h-14 gap-4 px-5 py-3 text-left hover:no-underline",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Automation keys"})]}),e.jsx("span",{className:"mt-0.5 block text-xs font-normal leading-5 text-muted-foreground",children:"Client credentials for CI/CD and headless services that cannot open a browser."})]}),e.jsxs(y,{className:"ml-auto shrink-0",variant:"outline",children:[m.length," keys"]})]}),e.jsxs(ne,{className:"border-t border-mist-line p-0",children:[e.jsx("div",{className:"flex justify-end border-b border-mist-line px-5 py-3",children:e.jsxs(b,{className:"h-9 shrink-0",onClick:()=>f(!0),ref:oe,size:"sm",children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"New key"]}
1)}),e.jsx("div",{className:"divide-y divide-mist-line",children:g?e.jsx(Ce,{label:"Loading automation keys"}):m.length===0?e.jsx(ze,{detail:"Create a narrowly scoped key when browser authorization is not possible.",title:"No automation keys"}):m.map(r=>e.jsxs("div",{className:"flex flex-col gap-4 px-5 py-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"break-words text-sm font-semibold text-foreground",children:r.client_name||"Unnamed key"}),r.disabled?e.jsx(y,{variant:"destructive",children:"Disabled"}):e.jsx(y,{variant:"success",children:"Active"})]}),e.jsx("code",{className:"mt-1 block break-all font-mono text-[10px] leading-4 text-muted-foreground",children:r.client_id}),e.jsx(Te,{scopes:(r.scope||"").split(" ").filter(Boolean)})]}),e.jsxs("div",{className:"flex shrink-0 gap-2 self-start",children:[e.jsx(b,{"aria-label":`Copy client ID for ${r.client_name||"automation key"}`,className:"h-9 w-9",onClick:()=>{T(r.client_id,"Client ID")},size:"icon",variant:"outline",children:e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsx(b,{"aria-label":`Revoke ${r.client_name||"automation key"}`,className:"h-9 w-9 text-status-error hover:text-status-error",disabled:H===r.client_id,onClick:()=>{fe(r.client_id)},size:"icon",variant:"outline",children:H===r.client_id?e.jsx(R,{className:"h-3.5 w-3.5"}):e.jsx(me,{className:"h-3.5 w-3.5"})})]})]},r.client_id))})]})]}),e.jsxs(te,{className:"border border-cool-border bg-surface-primary",value:"deletion-approvals",children:[e.jsxs(se,{className:"min-h-14 gap-4 px-5 py-3 text-left hover:no-underline",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4 text-status-warning"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Resource deletion approvals"})]}),e.jsx("span",{className:"mt-0.5 block text-xs font-normal leading-5 text-muted-foreground",children:"Review impact before allowing an agent to schedule deletion of protected resources."})]}),e.jsxs(y,{className:"ml-auto shrink-0",variant:K?"warning":"outline",children:[K," active"]})]}),e.jsx(ne,{className:"border-t border-mist-line p-0",children:e.jsx(ts,{requests:$})})]})]}),e.jsx(Me,{description:A?"Copy the secret now. Closing this drawer permanently hides it.":"Create a client-credentials key for a service that cannot complete browser authorization.",eyebrow:"Agent access / Automation",footer:A?e.jsx(b,{className:"w-full sm:w-auto",onClick:()=>V(!1),children:"I have saved the key"}):e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"w-full sm:w-auto",disabled:x,onClick:()=>V(!1),variant:"outline",children:"Cancel"}),e.jsx(b,{className:"w-full sm:w-auto",disabled:x||!_.trim()||D.length===0,onClick:()=>{Y()},children:x?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Creating keyâ¦"]}):"Create key"})]}),onOpenChange:V,open:v,returnFocusRef:oe,title:A?`${A.name} is ready`:"Create automation key",children:A?e.jsxs("div",{"aria-live":"polite",className:"space-y-6",children:[e.jsxs(O,{variant:"warning",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx(ye,{children:"Secret shown once"}),e.jsx(M,{children:"Store these values in a secret manager before closing the drawer. Resilis cannot reveal the client secret again."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(be,{label:"Client ID",value:A.clientID,onCopy:T}),e.jsx(be,{label:"Client secret",value:A.clientSecret,onCopy:T,sensitive:!0}),e.jsx(be,{label:"Token endpoint",value:Jt,onCopy:T})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(ee,{description:"Use a name that identifies the workload and environment where this key will live.",title:"Key identity",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{htmlFor:"automation-key-name",children:"Key name"}),e.jsx(I,{autoComplete:"off",id:"automation-key-name",maxLength:120,onChange:r=>w(r.target.value),placeholder:"Production deployment pipeline",value:_}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Up to 120 characters. Avoid putting secrets or tokens in the name."})]})}),e.jsx(ee,{description:"Start with read-only access and add only what this workload must perform.",title:"Permissions",children:e.jsx("div",{className:"divide-y divide-mist-line border-y border-mist-line",children:Zt.map(r=>{const i=`${r.id.replace(/:/g,"-")}-description`;return e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 py-3.5",htmlFor:r.id,children:[e.jsx(kt,{"aria-describedby":i,checked:D.includes(r.id),id:r.id,onCheckedChange:()=>E(r.id)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:r.label}),r.sensitive?e.jsx(y,{className:"px-1.5 py-0 text-[9px] leading-4",variant:"warning",children:"Sensitive"}):null]}),e.jsx("span",{className:"mt-0.5 block text-[11px] leading-4 text-muted-foreground",id:i,children:r.description})]})]},r.id)})})}),D.some(r=>r.startsWith("resilis:delete:"))?e.jsxs(O,{variant:"warning",children:[e.jsx(ge,{className:"h-4 w-4"}
1),e.jsx(M,{children:"Production, database, and storage deletion still requires a separate human approval in the deletion queue."})]}):null]})})]})}function ts({requests:t}){const{toast:s}=re(),n=ae(),a=ue(),o=Qt(),m=Ht(),[l,g]=p.useState(null),[h,u]=p.useState(""),j=(t.data||[]).filter(x=>["prepared","approved","scheduled","deleting"].includes(x.status)),v=()=>{g(null),u("")},f=async(x,C)=>{let _;try{_=a.capture(n)}catch{return!1}try{return C==="approve"?await o.mutateAsync(x.id):await m.mutateAsync(x.id),a.commit(_,()=>{s({title:C==="approve"?"Deletion approved":"Deletion cancelled",description:C==="approve"?"The requesting agent may now schedule deletion. The cancellation window still applies.":`${x.impact.resource_name} will not be deleted by this request.`})})}catch(w){return a.commit(_,()=>{s({title:`Could not ${C} deletion`,description:w instanceof Error?w.message:"Unknown error",variant:"destructive"})}),!1}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"divide-y divide-mist-line",children:t.isLoading?e.jsx(Ce,{label:"Loading deletion requests"}):t.isError?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-5 py-6",children:[e.jsx("p",{className:"text-xs text-status-error",children:"Deletion requests could not be loaded."}),e.jsxs(b,{className:"h-8",onClick:()=>{t.refetch()},size:"sm",variant:"outline",children:[e.jsx(xe,{className:"mr-2 h-3.5 w-3.5"}),"Retry"]})]}):j.length===0?e.jsxs("div",{className:"flex items-start gap-3 px-5 py-6",children:[e.jsx(Dt,{className:"mt-0.5 h-4 w-4 shrink-0 text-status-success"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"No approvals need attention"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:"Protected resources remain blocked from agent-initiated deletion until a request appears here."})]})]}):j.map(x=>e.jsx(ss,{onApprove:()=>{u(""),g(x)},onCancel:()=>{f(x,"cancel")},pending:o.isPending||m.isPending,request:x},x.id))}),e.jsx(Ue,{onOpenChange:x=>{x||v()},open:l!==null,children:e.jsxs(Be,{className:"sm:max-w-[520px]",children:[e.jsxs(Ve,{children:[e.jsx(Qe,{children:"Grant deletion approval"}),e.jsx(He,{children:"Approval does not delete the resource immediately. It lets the requesting agent schedule deletion, after which a 10-minute cancellation window begins."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("dl",{className:"grid gap-px border border-mist-line bg-mist-line sm:grid-cols-2",children:[e.jsx(de,{label:"Resource",value:l?.impact.resource_name||""}),e.jsx(de,{label:"Environment",value:l?.impact.environment_name||l?.impact.environment_slug||"Unknown"}),e.jsx(de,{label:"Type",value:l?.impact.resource_type||""}),e.jsx(de,{label:"Persistent data",value:l?.impact.persistent_data?"Yes":"No"})]}),(l?.impact.warnings.length||0)>0?e.jsxs(O,{variant:"warning",children:[e.jsx(pe,{className:"h-4 w-4"}),e.jsx(ye,{children:"Review the impact"}),e.jsx(M,{className:"space-y-1",children:(l?.impact.warnings||[]).map(x=>e.jsx("p",{className:"break-words",children:x},x))})]}):null,e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(k,{className:"break-words",htmlFor:"deletion-confirmation",children:["Type ",e.jsx("strong",{children:l?.impact.resource_name})," to confirm"]}),e.jsx(I,{"aria-describedby":"deletion-confirmation-hint",autoComplete:"off",id:"deletion-confirmation",onChange:x=>u(x.target.value),value:h}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",id:"deletion-confirmation-hint",children:"The name must match exactly. You can still cancel after the agent schedules deletion."})]})]}),e.jsxs(We,{children:[e.jsx(b,{onClick:v,variant:"outline",children:"Keep resource"}),e.jsx(b,{disabled:!l||h!==l.impact.resource_name||o.isPending,onClick:()=>{l&&f(l,"approve").then(x=>{x&&v()})},variant:"destructive",children:o.isPending?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Granting approvalâ¦"]}):"Grant approval"})]})]})})]})}function ss({request:t,pending:s,onApprove:n,onCancel:a}){const o=t.approval_required&&t.status==="prepared",m=["prepared","approved","scheduled"].includes(t.status),l=t.cancellation_deadline||t.expires_at,g
1=t.status==="scheduled"?"Cancellation closes":t.status==="approved"?"Approval expires":"Request expires",h=t.status==="prepared"?"Awaiting approval":t.status;return e.jsx("div",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"break-words text-sm font-semibold text-foreground",children:t.impact.resource_name}),e.jsx(y,{variant:t.impact.persistent_data?"destructive":"outline",children:t.impact.resource_type}),e.jsx(y,{variant:t.status==="prepared"?"warning":t.status==="deleting"?"destructive":"info",children:h})]}),e.jsxs("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:[t.impact.environment_name||t.impact.environment_slug||"Unknown environment"," · ",t.impact.resource_status]}),e.jsx("code",{className:"mt-1 block break-all font-mono text-[10px] leading-4 text-muted-foreground",children:t.resource_id}),t.impact.warnings.length?e.jsxs("div",{className:"mt-3 flex items-start gap-2 border border-status-warning/30 bg-status-warning-surface p-3",children:[e.jsx(pe,{className:"mt-0.5 h-4 w-4 shrink-0 text-status-warning"}),e.jsx("div",{className:"space-y-1 text-[11px] leading-4 text-muted-foreground",children:t.impact.warnings.map(u=>e.jsx("p",{className:"break-words",children:u},u))})]}):null,e.jsxs("p",{className:"mt-3 flex items-start gap-1.5 text-[10px] leading-4 text-muted-foreground",children:[e.jsx(At,{className:"mt-px h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{children:[g," ",e.jsx("time",{dateTime:l,children:rs(l)})]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 lg:justify-end",children:[m?e.jsxs(b,{disabled:s,onClick:a,size:"sm",variant:"outline",children:[e.jsx(nt,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel request"]}):null,o?e.jsxs(b,{disabled:s,onClick:n,size:"sm",children:[e.jsx(at,{className:"mr-1.5 h-3.5 w-3.5"}),"Review approval"]}):null]})]})})}function de({label:t,value:s}){return e.jsxs("div",{className:"min-w-0 bg-surface-primary p-3",children:[e.jsx("dt",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:t}),e.jsx("dd",{className:"mt-1 break-words text-xs font-semibold text-foreground",children:s})]})}function Te({scopes:t}){return t.length?e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:t.map(s=>e.jsx(y,{className:"max-w-full break-all text-[10px]",variant:"outline",children:ns(s)},s))}):null}function Ce({label:t}){return e.jsxs("div",{className:"flex items-center gap-2 px-5 py-7 text-xs text-muted-foreground",children:[e.jsx(R,{className:"h-4 w-4"}),t]})}function ze({detail:t,title:s}){return e.jsxs("div",{className:"px-5 py-7",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s}),e.jsx("p",{className:"mt-1 max-w-[68ch] text-xs leading-5 text-muted-foreground",children:t})]})}function be({label:t,value:s,onCopy:n,sensitive:a=!1}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(k,{children:t}),a?e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-status-warning",children:"Sensitive"}):null]}),e.jsxs("div",{className:"flex min-w-0 items-stretch border border-field-border bg-field-muted",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all px-3 py-2.5 font-mono text-xs leading-5 text-foreground",children:s}),e.jsx(b,{"aria-label":`Copy ${t}`,className:"h-auto w-11 shrink-0 border-y-0 border-r-0",onClick:()=>{n(s,t)},size:"icon",variant:"outline",children:e.jsx(we,{className:"h-4 w-4"})})]})]})}function ns(t){return t.replace(/^resilis:/,"").replace(/:/g," · ")}function as(t){const s=new Date(t);return Number.isNaN(s.getTime())?"at an unknown date":new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}).format(s)}function rs(t){const s=new Date(t);return Number.isNaN(s.getTime())?"at an unknown time":new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(s)}function is({connection:t,showLastCheck:s=!0}){return t.status==="active"?e.jsxs(y,{variant:"success",className:"gap-1.5 font-normal",children:[e.jsx("span",{className:"h-1.5 w-1.5 bg-status-success"}),"Active"]}):t.status==="invalid_credentials"?e.jsxs(y,{variant:"destructive",className:"gap-1.5 font-normal",children:[e.jsx("span",{className:"h-1.5 w-1.5 bg-destructive-foreground"}),"Invalid credentials"]}):e.jsxs(y,{variant:"warning",className:"gap-1.5 font-normal",children:[e.jsx("span",{className:"h-1.5 w-1.5 bg-status-warning"}),s?`Unreachable · ${Ye(t.last_health_check)}`:"Unreachable"]})}const Q={aws_s3:{endpoint:"https://s3.amazonaws.com",region:"us-east-1"},r2:{endpoint:"https://<account-id>.r2.cloudflarestorage.com",region:"auto"},backblaze:{endpoint:"https://s3.us-west-004.backblazeb2.com",region:"us-west-004"},custom_s3:{endpoint:"https://s3.example.com",region:"auto"}};function os({open:t,onOpenChange:s}){const[n,a]=p.useState("aws_s3"),[o,m]=p.useState(""),[l,g]=p.useState(Q.aws_s3.endpoint),[h,u]=p.useState(Q.aws_s3.region),[j,v]=p.useState(""),[f,x]=p.useState(""),[C,_]=p.useState(""),w=rt(),{toast:D}=re();p.useEffect(()=>{t||(a("aws_s3"),m(""),g(Q.aws_s3.endpoint),u(Q.aws_s3.region),v(""),x(""),_(""))},[t]);const q=N=>{const P=N;a(P),g(Q[P].endpoint),u(Q[P].region)},A=N=>{N.preventDefault(),w.mutate({name:o,provider_type:n,endpoint:l,region:h,bucket_name:j,access_key_id:f,secret_key:C},{onSuccess:()=>{D({title:"Connection added",description:`${o} is available.`}),s(!1)},onError:P=>D({title:"Failed to add connection",description:P.message,variant:"destructive"})})};return e.jsx(Me,{description:"Connect an existing S3-compatible bucket to this organization.",eyebrow:"Connections / Object storage",footer:e.jsxs(e.Fragment,{children:[e.jsx(b,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsxs(b,{form:"register-storage-connection-form",type:"submit",disabled:w.isPending,children:[w.isPending?e.jsx(R,{className:"mr-2 h-4 w-4"}):null,"Add connection"]})]}),onOpenChange:s,open:t,title:"Add storage connection",children:e.jsxs("form",{id:"register-storage-connection-form",onSubmit:A,className:"space-y-6",children:[e.jsx(ee,{description:"Name the connection and select the compatible object-storage provider.",title:"Connection identity",children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-name",children:"Name"}),e.jsx(I,{id:"connection-name",value:o,onChange:N=>m(N.target.value),placeholder:"media-source",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Provider"}),e.jsxs(Et,{value:n,onValueChange:q,children:[e.jsx(It,{children:e.jsx(Rt,{})}),e.jsxs(Tt,{children:[e.jsx(ce,{value:"aws_s3",children:"AWS S3"}),e.jsx(ce,{value:"r2",children:"Cloudflare R2"}),e.jsx(ce,{value:"backblaze",children:"Backblaze B2"}),e.jsx(ce,{value:"custom_s3",children:"Custom S3"})]})]})]})]})}),e.jsxs(ee,{description:"Point Resilis at the bucket endpoint and region.",title:"Bucket location",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-bucket",children:"Bucket"}),e.jsx(I,{id:"connection-bucket",value:j,onChange:N=>v(N.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-region",children:"Region"}),e.jsx(I,{id:"connection-region",value:h,onChange:N=>u(N.target.value),required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-endpoint",children:"Endpoint"}
1),e.jsx(I,{id:"connection-endpoint",value:l,onChange:N=>g(N.target.value),required:!0})]})]}),e.jsx(ee,{description:"Credentials are stored securely and used only for this connection.",title:"Access credentials",children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-access-key",children:"Access Key ID"}),e.jsx(I,{id:"connection-access-key",value:f,onChange:N=>x(N.target.value),autoComplete:"off",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"connection-secret-key",children:"Secret Key"}),e.jsx(I,{id:"connection-secret-key",type:"password",value:C,onChange:N=>_(N.target.value),autoComplete:"new-password",required:!0})]})]})})]})})}function ls({embedded:t=!1}){const{data:s=[],isLoading:n,error:a}=it(),[o,m]=p.useState(!1),l=ot(),g=lt(),{toast:h}=re(),u=v=>{l.mutate(v,{onSuccess:()=>h({title:"Connection validated"}),onError:f=>h({title:"Validation failed",description:f.message,variant:"destructive"})})},j=v=>{g.mutate(v,{onSuccess:()=>h({title:"Connection deleted"}),onError:f=>h({title:"Failed to delete connection",description:f.message,variant:"destructive"})})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[t?null:e.jsx("h3",{className:"text-sm font-semibold leading-5 text-foreground",children:"Storage Connections"}),e.jsx("p",{className:t?"text-xs leading-5 text-muted-foreground":"mt-1 text-xs leading-5 text-muted-foreground",children:"Connect external S3-compatible buckets for service integrations and browsing."})]}),e.jsxs(b,{className:"h-10 shrink-0 rounded-none",onClick:()=>m(!0),children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Add Connection"]})]}),e.jsxs("div",{className:"overflow-hidden border border-table-border bg-surface-primary",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-surface-secondary text-left text-xs font-medium text-muted-foreground",children:[e.jsx("th",{className:"w-[24%] px-5 py-3",children:"Name"}),e.jsx("th",{className:"w-[14%] px-5 py-3",children:"Provider"}),e.jsx("th",{className:"w-[24%] px-5 py-3",children:"Bucket"}),e.jsx("th",{className:"w-[20%] px-5 py-3",children:"Status"}),e.jsx("th",{className:"w-[14%] px-5 py-3",children:"Last Check"}),e.jsx("th",{className:"w-[4%] px-5 py-3"})]})}),e.jsx("tbody",{children:n?Array.from({length:3}).map((v,f)=>e.jsx("tr",{className:"h-[52px]",children:e.jsx("td",{className:"px-4 py-0",colSpan:6,children:e.jsx(Ge,{className:"h-5 w-full rounded-none"})})},f)):s.map(v=>e.jsxs("tr",{className:"h-[52px] border-t border-table-border hover:bg-selector-hover",children:[e.jsx("td",{className:"px-5 py-4 text-sm font-semibold text-foreground",children:v.name}),e.jsx("td",{className:"px-5 py-4 text-sm text-muted-foreground",children:v.provider_type.replace("_"," ")}),e.jsx("td",{className:"truncate px-5 py-4 text-sm text-muted-foreground",title:v.bucket_name,children:v.bucket_name}),e.jsx("td",{className:"px-5 py-4",children:e.jsx(is,{connection:v,showLastCheck:!1})}),e.jsx("td",{className:"px-5 py-4 text-sm text-muted-foreground",children:Ye(v.last_health_check)}),e.jsx("td",{className:"px-5 py-4 text-right",children:e.jsxs(ct,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-none",children:e.jsx(zt,{className:"h-4 w-4"})})}),e.jsxs(mt,{align:"end",children:[e.jsxs(Ee,{onClick:()=>u(v.id),disabled:l.isPending,children:[l.isPending?e.jsx(R,{className:"h-4 w-4"}):e.jsx(xe,{className:"h-4 w-4"}),"Validate"]}),e.jsxs(Ee,{className:"text-destructive",onClick:()=>j(v.id),disabled:g.isPending,children:[e.jsx(me,{className:"h-4 w-4"}),"Delete"]})]})]})})]},v.id))})]})}),!n&&s.length===0?e.jsx("div",{className:"py-12 text-center text-xs text-muted-foreground",children:"No external storage connections yet"}):null,a?e.jsx("div",{className:"border-t border-table-border p-4 text-xs text-destructive",children:"Failed to load storage connections."}):null]}),e.jsx(os,{open:o,onOpenChange:m})]})}const Pe=[{path:"resource_quota.requests.cpu",label:"Total CPU requests",group:"Resource quota",hint:"Kubernetes quantity, for example 2 or 500m"},{path:"resource_quota.limits.cpu",label:"Total CPU limits",group:"Resource quota",hint:"Kubernetes quantity"},{path:"resource_quota.requests.memory",label:"Total memory requests",group:"Resource quota",hint:"Kubernetes quantity, for example 4Gi"},{path:"resource_quota.limits.memory",label:"Total memory limits",group:"Resource quota",hint:"Kubernetes quantity"},{path:"resource_quota.pods",label:"Maximum pods",group:"Resource quota",hint:"Whole number"},{path:"resource_quota.requests.storage",label:"Persistent storage",group:"Resource quota",hint:"Optional Kubernetes quantity"},{path:"container_defaults.requests.cpu",label:"Default container CPU request",group:"Container defaults",hint:"Kubernetes quantity"},{path:"container_defaults.limits.cpu",label:"Default container CPU limit",group:"Container defaults",hint:"Kubernetes quantity"},{path:"container_defaults.requests.memory",label:"Default container memory request",group:"Container defaults",hint:"Kubernetes quantity"},{path:"container_defaults.limits.memory",label:"Default container memory limit",group:"Container defaults",hint:"Kubernetes quantity"},{path:"container_maximum.cpu",label:"Maximum per-container CPU",group:"Container maximums",hint:"Kubernetes quantity"},{path:"container_maximum.memory",label:"Maximum per-container memory",group:"Container maximums",hint:"Kubernetes quantity"}];function F(t,s){const[n,a,o]=s.split("."),m=n==="resource_quota"?a==="pods"?t?.resource_quota?.pods:t?.resource_quota?.[a]?.[o]:n==="container_defaults"?t?.container_defaults?.[a]?.[o]:t?.container_maximum?.[a];return m===void 0?"":String(m)}function Ze(t,s,n){const[a,o,m]=s.split(".");if(a==="resource_quota"&&o==="pods"){const u=n===""?void 0:Number(n);t.resource_quota={...t.resource_quota,pods:u};return}if(a==="container_maximum"){t.container_maximum={...t.container_maximum,[o]:n===""?void 0:n};return}const g=(a==="resource_quota"?t.resource_quota??{}:t.container_defaults??{})[o]??{},h=n===""?void 0:n;a==="resource_quota"?t.resource_quota={...t.resource_quota,[o]:{...g,[m]:h}}:t.container_defaults={...t.container_defaults,[o]:{...g,[m]:h}}}function z(t){const s=t.trim().match(/^([0-9]+(?:\.[0-9]+)?)(m|Ki|Mi|Gi|Ti|K|M|G|T)?$/);if(!s)return;const n=Number(s[1]),a=s[2];if(!a)return n;if(a==="m")return n/1e3;const o={Ki:1024,Mi:1024**2,Gi:1024**3,Ti:1024**4,K:1e3,M:1e3**2,G:1e3**3,T:1e3**4};return n*o[a]}function cs(t,s){const n=[];for(const a of Pe){const o=F(t,a.path);if(!o)continue;if(a.path.endsWith(".pods")&&(!/^\d+$/.test(o)||Number(o)<=0)){n.push(`${a.label} must be a positive whole number.`);continue}if(!a.path.endsWith(".pods")&&z(o)===void 0){n.push(`${a.label} must be a valid Kubernetes quantity.`);continue}const m=F(s,a.path);m&&z(o)!==void 0&&z(m)!==void 0&&z(o)>z(m)&&n.push(`${a.label} cannot exceed the plan maximum of ${m}.`)}for(const a of["cpu","memory"]){const o=[[`container_defaults.requests.${a}`,`container_defaults.limits.${a}`,"default request cannot exceed the default limit"],[`container_defaults.limits.${a}`,`container_maximum.${a}`,"default limit cannot exceed the per-container maximum"],[`container_maximum.${a}`,`resource_quota.limits.${a}`,"per-container maximum cannot exceed the total limit"]];for(const[m,l,g]of o){const h=F(t,m),u=F(t,l);h&&u&&z(h)!==void 0&&z(u)!==void 0&&z(h)>z(u)&&n.push(`${g} (${h} > ${u}).`)}}return n}function ds(t){const s={};for(const n of Pe){const a=F(t,n.path);a&&Ze(s,n.path,n.path.endsWith(".pods")?String(Number(a)):a)}return s}function ms({environment:t,onSave:s,isSaving:n}){const[a,o]=p.useState(t.compute_policy??{}),[m,l]=p.useState([]);p.useEffect(()=>{o(t.compute_policy??{}),l([])},[t.compute_policy]);const g=t.effective_compute_policy??{},h=t.compute_policy_maximum??{},u=t.compute_policy_enforcement?.network_policy??"unverified",j=p.useMemo(()=>JSON.stringify(a)!==JSON.stringify(t.compute_policy??{}),[a,t.compute_policy]),v=()=>{const f=ds(a),x=cs(f,h);l(x),x.length||s(f)};return e.jsxs("section",{className:"border border-cool-border bg-surface-primary",children:[e.jsxs("div",{className:"border-b border-table-border px-5 py-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Compute policy"}),e.jsxs("p",{className:"mt-1 text-[11px] font-semibold uppercase tracking-[0.1em] text-muted-foreground",children:["Environment: ",t.name]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:"Reduce the plan defaults for this environment. Effective values include plan defaults; empty settings inherit them."})]}),e.jsxs("div",{className:"space-y-5 px-5 py-5",children:[m.length?e.jsx(O,{className:"rounded-none",variant:"destructive",children:e.jsx(M,{children:m.join(" ")})}):null,e.jsx("div",{className:"grid gap-x-5 gap-y-4 md:grid-cols-2",children:Pe.map(f=>{const x=F(a,f.path),C=F(g,f.path)||"Not set",_=F(h,f.path)||"No plan maximum supplied";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{className:"text-xs font-semibold text-foreground",htmlFor:`compute-policy-${f.path}`,children:f.label}),e.jsx(I,{className:"h-9 rounded-none font-mono text-xs",id:`compute-policy-${f.path}`,inputMode:f.path.endsWith(".pods")?"numeric":"text",value:x,onChange:w=>{const D={...a};Ze(D,f.path,w.target.value),o(D)}}),e.jsxs("p",{className:"text-[10px] leading-4 text-muted-foreground",children:["Effective: ",e.jsx("span",{className:"font-mono",children:C})," · Maximum: ",e.jsx("span",{className:"font-mono",children:_})," · ",f.hint]})]},f.path)})}),e.jsxs("div",{className:"flex flex-col gap-3 border-t border-table-border pt-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"Ingress network isolation"}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"NetworkPolicy is configured for this environment and reconciles on rollout. CNI enforcement remains unverified."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"rounded-none",variant:"success",children:"Configured"}),e.jsxs(y,{className:"rounded-none",variant:"warning",children:["Enforcement ",u]})]})]}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx(b,{className:"h-9 rounded-none",disabled:!j||n,onClick:()=>{o({}),l([]),s({})},type:"button",variant:"outline",children:"Reset overrides"}),e.jsx(b,{className:"h-9 rounded-none",disabled:!j||n,onClick:v,type:"button",children:n?"Saving...":"Save policy"})]})]})]})}const qe=[{id:"general",label:"General"},{id:"connections",label:"Connections"},{id:"compute-policy",label:"Compute policy"},{id:"agent-access",label:"Agent Access"},{id:"danger",label:"Danger Zone"}];
1function ke({children:t,detail:s,danger:n,title:a}){return e.jsxs("section",{className:Ie("border bg-surface-primary p-5",n?"border-status-error":"border-cool-border"),children:[e.jsxs("div",{children:[e.jsx("h2",{className:Ie("text-sm font-semibold leading-5",n?"text-status-error":"text-foreground"),children:a}),e.jsx("p",{className:"mt-1 text-xs font-normal leading-5 text-muted-foreground",children:s})]}),e.jsx("div",{className:"mt-[18px]",children:t})]})}const Js=()=>{const{projectId:t}=bt(),{preferences:s,updatePreferences:n}=ut(),a=t||s.selectedProjectId||"",{toast:o}=re(),m=Ft(),l=Nt(),g=Fe(),h=ae(),u=ue(),{data:j,isLoading:v,error:f}=pt(a),x=xt(a),C=ht(),_=ft(v),[w,D]=p.useState(""),[q,A]=p.useState(""),[N,P]=p.useState(!1),[L,H]=p.useState(!1),[W,$]=p.useState(""),[K,U]=p.useState(!1),[ie,X]=p.useState(null),oe=N?w:j?.name||"",B=L?q:j?.description||"",he=N||L,V=l.hash.replace("#",""),E=qe.some(i=>i.id===V)?V:"general",Y=x.data?.find(i=>i.id===s.selectedEnvironmentId)??x.data?.find(i=>i.slug==="development")??x.data?.[0],fe=i=>{m(`${l.pathname}#${i}`,{replace:!0})},J=Ne({mutationFn:i=>u.run(h,({scope:d,signal:c})=>jt(d,a,i,c)),onMutate:()=>u.capture(h),onSuccess:(i,d,c)=>{u.commit(c,()=>{g.setQueryData(G(c,Z.detail(c.organizationId,a)),i),g.invalidateQueries({queryKey:G(c,Z.details())}),g.invalidateQueries({queryKey:G(c,Z.lists())}),o({title:"Saved",description:"Project settings updated."}),P(!1),H(!1)})},onError:(i,d,c)=>{c&&u.commit(c,()=>{o({title:"Error",description:i.message,variant:"destructive"})})}}),T=Ne({mutationFn:()=>u.run(h,({scope:i,signal:d})=>vt(i,a,d)),onMutate:()=>u.capture(h),onSuccess:async(i,d,c)=>{if(i.status==="approval_required"){u.commit(c,()=>{U(!1),$(""),X(i)});return}u.commit(c,()=>{g.setQueriesData({queryKey:G(c,Z.lists())},S=>S?.filter(le=>le.id!==a)??[]),g.removeQueries({queryKey:G(c,Z.details())})});try{await u.run(c,()=>n({selectedProjectId:void 0,selectedProjectName:void 0,selectedEnvironmentId:void 0,selectedEnvironmentName:void 0}))}catch{return}u.commit(c,()=>{o({title:"Project deleted",description:`"${j?.name}" has been permanently deleted.`}),m("/home")})},onError:(i,d,c)=>{c&&u.commit(c,()=>{o({title:"Error",description:i.message,variant:"destructive"})})}}),r=i=>{if(i.preventDefault(),!j)return;if(N){const c=$t(w,2);if(c){o({title:"Invalid project name",description:c,variant:"destructive"});return}}const d={};if(N&&w!==j.name&&(d.name=w),L&&q!==j.description&&(d.description=q),Object.keys(d).length===0){o({title:"No changes",description:"Nothing to save."});return}J.mutate(d)};return _?e.jsx(gt,{}):!a||f||!j?e.jsxs("div",{className:"w-full space-y-7",children:[e.jsx("h1",{className:"sr-only",children:"Settings"}),e.jsx(O,{variant:"destructive",children:e.jsx(M,{children:a?`Failed to load project: ${f?.message}`:"No project selected. Please select a project to view its settings."})})]}):e.jsxs("div",{className:"w-full space-y-7",children:[e.jsx("h1",{className:"sr-only",children:"Settings"}),e.jsxs("div",{className:"flex flex-col gap-6 md:flex-row",children:[e.jsx("aside",{className:"w-full shrink-0 md:w-[200px]",children:e.jsx(Pt,{active:E,items:qe,onChange:fe})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:E==="general"?"block":"hidden",children:e.jsx("div",{className:"space-y-6",children:e.jsx(ke,{detail:"Update your project name and description",title:"General Settings",children:e.jsxs("form",{onSubmit:r,className:"space-y-[18px]",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{className:"text-xs font-semibold text-foreground",htmlFor:"project-name",children:"Project Name"}),e.jsx(I,{className:"h-10 rounded-none text-[13px]",id:"project-name",maxLength:Re,value:oe,onChange:i=>{D(i.target.value),P(!0)},placeholder:"Enter project name"}),e.jsxs("p",{className:"text-[11px] font-normal text-muted-foreground",children:["Use up to ",Re," characters without spaces."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{className:"text-xs font-semibold text-foreground",htmlFor:"project-description",children:"Description"}),e.jsx(Lt,{className:"min-h-[88px] rounded-none text-[13px]",id:"project-description",value:
1B,onChange:i=>{A(i.target.value),H(!0)},placeholder:"Enter a description for this project",rows:3})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{className:"text-xs font-semibold text-foreground",children:"Project Slug"}),e.jsx("p",{className:"border border-field-border bg-field-muted px-3 py-2 font-mono text-[13px] font-normal text-foreground",children:j.slug}),e.jsx("p",{className:"text-[11px] font-normal text-muted-foreground",children:"The slug cannot be changed after creation."})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(b,{className:"h-10 w-[156px] rounded-none",type:"submit",disabled:!he||J.isPending,children:J.isPending?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ut,{className:"mr-2 h-4 w-4"}),"Save Changes"]})})})]})})})}),e.jsx("div",{className:E==="connections"?"block":"hidden",children:E==="connections"?e.jsx(us,{}):null}),e.jsx("div",{className:E==="compute-policy"?"block":"hidden",children:E==="compute-policy"?Y?e.jsx(ms,{environment:Y,isSaving:C.isPending,onSave:i=>C.mutate({id:Y.id,data:{compute_policy:i}},{onSuccess:()=>o({title:"Compute policy saved",description:"The environment policy override was updated."}),onError:d=>o({title:"Compute policy could not be saved",description:d.message,variant:"destructive"})})}):e.jsx(ke,{detail:"Create an environment before configuring resource policy.",title:"Compute policy",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"No environment is available for this project."})}):null}),e.jsx("div",{className:E==="agent-access"?"block":"hidden",children:E==="agent-access"?e.jsx(es,{}):null}),e.jsx("div",{className:E==="danger"?"block":"hidden",children:e.jsxs("section",{className:"border border-status-error bg-surface-primary",children:[e.jsx("div",{className:"flex h-11 items-center gap-2 border-b border-status-error px-5",children:e.jsx(Oe,{children:"Danger zone"})}),e.jsxs("div",{className:"grid min-h-20 gap-4 px-5 py-4 md:grid-cols-[180px_minmax(0,1fr)_156px] md:items-center",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Delete project"}),e.jsxs("p",{className:"text-xs font-medium text-muted-foreground",children:["Permanently deletes ",e.jsx("span",{className:"font-semibold text-foreground",children:j.name})," and all its resources."]}),e.jsx("span",{className:"flex justify-start md:justify-end",children:e.jsxs(b,{className:"h-9 rounded-none border-status-error bg-status-error text-background hover:bg-status-error",onClick:()=>U(!0),size:"sm",children:[e.jsx(me,{className:"mr-2 h-4 w-4"}),"Delete"]})})]})]})})]})]}),e.jsx(Ue,{open:K,onOpenChange:i=>{U(i),i||$("")},children:e.jsxs(Be,{children:[e.jsxs(Ve,{children:[e.jsxs(Qe,{className:"flex items-center gap-2 text-status-error",children:[e.jsx(pe,{className:"h-5 w-5"}),"Delete Project"]}),e.jsxs(He,{children:["This will permanently delete ",e.jsx("span",{className:"font-semibold text-foreground",children:j.name})," and all its associated resources and deployments. This action is irreversible."]})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs(k,{htmlFor:"delete-confirm",children:["Type ",e.jsx("span",{className:"font-mono font-semibold text-foreground",children:j.name})," to confirm"]}),e.jsx(I,{id:"delete-confirm",value:W,onChange:i=>$(i.target.value),placeholder:j.name,autoComplete:"off"})]}),e.jsxs(We,{children:[e.jsx(b,{variant:"outline",onClick:()=>{U(!1),$("")},children:"Cancel"}),e.jsx(b,{variant:"destructive",disabled:W!==j.name||T.isPending,onClick:()=>T.mutate(),children:T.isPending?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"h-4 w-4 mr-2"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),"Delete Project"]})})]})]})}),e.jsx(qt,{approval:ie,onClose:()=>X(null)})]})};function us(){return e.jsx("section",{children:e.jsxs(Le,{className:"space-y-3",defaultValue:["github"],type:"multiple",children:[e.jsxs(te,{className:"border border-cool-border bg-surface-primary",value:"github",children:[e.jsx(se,{className:"px-5 py-4 text-left hover:no-underline",children:e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground",children:"GitHub"}),e.jsx("span",{className:"mt-0.5 block text-xs font-normal leading-5 text-muted-foreground",children:"Repository access and source deployments"})]})}),e.jsx(ne,{className:"border-t border-mist-line px-5 pb-5 pt-5",children:e.jsx(ps,{embedded:!0})})]}),e.jsxs(te,{className:"border border-cool-border bg-surface-primary",value:"object-storage",children:[e.jsx(se,{className:"px-5 py-4 text-left hover:no-underline",children:e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground",children:"Object storage"}),e.jsx("span",{className:"mt-0.5 block text-xs font-normal leading-5 text-muted-foreground",children:"Exter
1nal S3-compatible buckets"})]})}),e.jsx(ne,{className:"border-t border-mist-line px-5 pb-5 pt-5",children:e.jsx(ls,{embedded:!0})})]})]})})}function ps({embedded:t=!1}){const{data:s,isLoading:n}=et(),{error:a,handleRefresh:o,isRefreshing:m}=Kt(),l=e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 border border-cool-border bg-surface-primary p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center border border-field-border bg-field-muted",children:e.jsx(Bt,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] font-bold leading-5 text-foreground",children:"GitHub"}),e.jsx("p",{className:"truncate text-xs leading-5 text-muted-foreground",children:"Access repositories and deploy from source"})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[n?e.jsx(Ge,{className:"h-5 w-20 rounded-none"}):s?.connected?e.jsx(y,{className:"rounded-none bg-resilis-mist text-[10px] font-bold text-accent-strong hover:bg-resilis-mist",children:"Connected"}):e.jsx(y,{variant:"outline",className:"rounded-none text-[10px] font-bold text-muted-foreground",children:"Not connected"}),e.jsx(b,{variant:"outline",size:"sm",onClick:o,disabled:m,className:"h-9 rounded-none",children:m?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Refreshing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"mr-2 h-4 w-4"}),s?.connected?"Refresh access":"Connect GitHub"]})})]})]}),s?.connected&&s.user&&e.jsxs("div",{className:"flex items-center gap-3 border border-field-border bg-field-muted p-3",children:[e.jsxs(Gt,{className:"h-8 w-8 rounded-none",children:[e.jsx(Ot,{className:"rounded-none object-cover",src:s.user.avatar_url,alt:s.user.login}),e.jsx(Mt,{className:"rounded-none text-xs font-bold",children:s.user.name?.charAt(0)||s.user.login?.charAt(0)})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:s.user.name||s.user.login}),e.jsxs("p",{className:"text-xs leading-5 text-muted-foreground",children:["@",s.user.login]})]})]}),a&&e.jsx(O,{variant:"destructive",className:"rounded-none py-2",children:e.jsx(M,{className:"text-xs",children:a})}),e.jsx("p",{className:"max-w-[520px] text-xs leading-5 text-muted-foreground",children:s?.connected?"Refresh your connection to grant access to additional GitHub organizations.":"Connect your GitHub account to deploy from your repositories."})]});return t?l:e.jsx(ke,{detail:"Manage your connected third-party services",title:"Connections",children:l})}export{Js as SettingsPage};
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.