@tickernelz/paperclip-pro-ui 2026.925.1 → 2026.925.2

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/runtime-IAg0vdY9.js","assets/model-DL5biheO.js","assets/definition-P7Pcik2r.js","assets/character-CguPM7IG.js","assets/prod-COP_vZWu.js","assets/rolldown-runtime-ZpX3ckPj.js","assets/CompanyExport-CrTwKkGN.js","assets/createLucideIcon-D-iIM3hK.js","assets/router-BxwR1PwE.js","assets/preload-helper-CceJXRIF.js","assets/zap-gf6Ev631.js","assets/agents-DrLpWAcm.js","assets/EmptyState-DOb3I5aU.js","assets/button-DCI8NFig.js","assets/mention-chips-pBjlxGok.js","assets/bot-CET4VfU-.js","assets/StatusIcon-DMDp_WJw.js","assets/clipboard-BZT4l65i.js","assets/loader-circle-DwlcG9aS.js","assets/octagon-alert-CTp78pR9.js","assets/MarkdownBody-AdwNLx7A.js","assets/check-C6myARng.js","assets/external-link-BKz-OKDG.js","assets/rotate-ccw-BhopZISX.js","assets/PageSkeleton-C-C3Xlc_.js","assets/skeleton-BxD7FB8M.js","assets/Agents.production-CSsrqqG3.js","assets/AgentAvatar-BR1Z_L_Z.js","assets/tabs-Dqn3cNzC.js","assets/dist-B3Uu-urE.js","assets/heartbeats-CY77VTM_.js","assets/triangle-alert-DOta-xfM.js","assets/SidebarContext-9UFQ2Pex.js","assets/environments-Cd-g_MmN.js","assets/Routines.production-BLDTlRLI.js","assets/RoutineRunVariablesDialog-BkLLbP3a.js","assets/MarkdownEditor-B3NYD32f.js","assets/dist-Cc3Bt6H4.js","assets/dist-DCJXgQu0.js","assets/sheet-Z4n6AEBA.js","assets/checkbox-CmYq-YMP.js","assets/chevron-right-CU6xIk8W.js","assets/label-C-aWneNy.js","assets/select-BqqjvKLd.js","assets/chevron-down-D2wNtbQf.js","assets/useHiddenSettings-D9d6LOsg.js","assets/health-Dc13TJNg.js","assets/badge-BLr1M3ne.js","assets/input-BkGpMopE.js","assets/company-members-C1IoXITE.js","assets/AgentIdentity-BgihkjQU.js","assets/card-BD8MkPAL.js","assets/RoutineDetail.production-BJLGGgbv.js","assets/save-D5KpMLil.js","assets/CompanySkills.production-22PSRfdH.js","assets/use-adapter-capabilities-0-4PhK9y.js","assets/file-text-DXa-cUrm.js","assets/CompanyActivity.production-C3D5uiX9.js","assets/Costs.production-hPGllSho.js","assets/OrgChart.production-yz5AfR-F.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/runtime-IAg0vdY9.js","assets/model-DL5biheO.js","assets/definition-C9sWnmbO.js","assets/character-CguPM7IG.js","assets/prod-COP_vZWu.js","assets/rolldown-runtime-ZpX3ckPj.js","assets/CompanyExport-D-L3aIBA.js","assets/createLucideIcon-D-iIM3hK.js","assets/router-BxwR1PwE.js","assets/preload-helper-CceJXRIF.js","assets/zap-gf6Ev631.js","assets/agents-DrLpWAcm.js","assets/EmptyState-DOb3I5aU.js","assets/button-DCI8NFig.js","assets/mention-chips-pBjlxGok.js","assets/bot-CET4VfU-.js","assets/StatusIcon-DMDp_WJw.js","assets/clipboard-BZT4l65i.js","assets/loader-circle-DwlcG9aS.js","assets/octagon-alert-CTp78pR9.js","assets/MarkdownBody-AdwNLx7A.js","assets/check-C6myARng.js","assets/external-link-BKz-OKDG.js","assets/rotate-ccw-BhopZISX.js","assets/PageSkeleton-C-C3Xlc_.js","assets/skeleton-BxD7FB8M.js","assets/Agents.production-C9UfcX_l.js","assets/AgentAvatar-BR1Z_L_Z.js","assets/tabs-Dqn3cNzC.js","assets/dist-B3Uu-urE.js","assets/heartbeats-CY77VTM_.js","assets/triangle-alert-DOta-xfM.js","assets/SidebarContext-9UFQ2Pex.js","assets/environments-Cd-g_MmN.js","assets/Routines.production-Cx0jBxDn.js","assets/RoutineRunVariablesDialog-BkLLbP3a.js","assets/MarkdownEditor-B3NYD32f.js","assets/dist-Cc3Bt6H4.js","assets/dist-DCJXgQu0.js","assets/sheet-Z4n6AEBA.js","assets/checkbox-CmYq-YMP.js","assets/chevron-right-CU6xIk8W.js","assets/label-C-aWneNy.js","assets/select-BqqjvKLd.js","assets/chevron-down-D2wNtbQf.js","assets/useHiddenSettings-D9d6LOsg.js","assets/health-Dc13TJNg.js","assets/badge-BLr1M3ne.js","assets/input-BkGpMopE.js","assets/company-members-C1IoXITE.js","assets/AgentIdentity-BgihkjQU.js","assets/card-BD8MkPAL.js","assets/RoutineDetail.production-BbeeGNoZ.js","assets/save-D5KpMLil.js","assets/CompanySkills.production-i-yIgrn5.js","assets/use-adapter-capabilities-0-4PhK9y.js","assets/file-text-DXa-cUrm.js","assets/CompanyActivity.production-BrGxzr9C.js","assets/Costs.production-Bds9QYE3.js","assets/OrgChart.production-Cgr0byQj.js"])))=>i.map(i=>d[i]);
2
2
  var m_e=Object.defineProperty;var r=(e,s)=>m_e(e,"name",{value:s,configurable:!0});import{i as V3,n as h_e,t as gv}from"./rolldown-runtime-ZpX3ckPj.js";import{$ as p_e,$n as zC,$t as Uoe,A as f_e,An as xR,At as x_e,B as Koe,Bn as g_e,Bt as Voe,C as b_e,Cn as v_e,Ct as Woe,D as qa,Dn as Hoe,Dt as y_e,E as cu,En as UC,Et as Qoe,F as DS,Fn as j_e,Fr as w_e,Ft as Goe,G as N_e,Gn as q6,Gt as Yoe,H as k_e,Hn as S_e,Ht as Joe,I as tS,In as C_e,Ir as Xoe,It as __e,J as z6,Jn as cl,Jt as Ep,K as I_e,Kn as SW,Kt as gR,L as Qu,Lr as U6,Lt as A_e,M as Da,Mn as W3,Mr as H3,Mt as JA,N as bR,Nn as R_e,Nr as T_e,Nt as XA,O as CW,On as Zoe,Ot as E_e,P as s0,Pn as KC,Pr as Ht,Pt as _W,Q as P_e,Qn as vR,Qt as ele,R as K6,Rn as yR,Rt as q$,S as U,Sn as M_e,St as D_e,T as Qr,Tt as L_e,U as fs,Un as $_e,Ut as O_e,Vn as tle,Vt as Fb,Wn as jM,Wt as F_e,X as Pa,Xn as Re,Xt as jR,Y as P,Yn as Nn,Yt as sle,Z as nle,Zn as B_e,Zt as VC,_ as Ku,_n as rle,_t as q_e,an as ale,at as ile,b as IW,bn as z_e,bt as U_e,c as K_e,cn as V_e,ct as ole,d as W_e,dn as H_e,dt as Q_e,en as V6,er as G_e,et as lle,fn as Y_e,ft as ZA,g as vc,gn as J_e,gr as X_e,gt as Z_e,h as bv,hn as eIe,hr as tIe,ht as sIe,i as Q3,in as Pp,it as AW,j as yh,jn as z$,jt as uj,k as qi,kn as RW,kt as TW,l as WC,ln as cle,lt as W6,m as Sw,mn as nIe,mt as rIe,n as sb,nn as aIe,nr as ee,nt as dle,o as iIe,on as EW,ot as oIe,pn as wM,pr as lIe,pt as Cw,q as G3,qn as ule,qt as cIe,rn as mle,rr as dIe,rt as LS,s as kb,sn as hle,st as uIe,t as Qt,tn as H6,tr as ye,tt as mIe,un as PW,ut as hIe,v as pIe,vn as fIe,vt as xIe,w as ple,wn as gIe,wt as bIe,x as Q6,xn as vIe,xt as MW,y as DW,yn as Y3,yt as fle,z as Er,zn as LW,zt as G6}from"./createLucideIcon-D-iIM3hK.js";import{t as gc}from"./preload-helper-CceJXRIF.js";import{$ as Nd,A as yIe,B as Tt,C as jIe,D as wIe,E as $W,F as OW,G as FW,H as wR,I as xle,J as BW,K as NIe,L as kIe,M as gle,N as SIe,O as CIe,P as U_,Q as _Ie,R as IIe,S as NR,T as ble,U as _w,V as kR,W as ul,X as zg,Y as Bb,Z as po,_ as AIe,a as Iw,at as vle,b as hl,ct as Ri,d as RIe,et as n0,f as qb,g as TIe,h as EIe,i as PIe,it as Zr,j as MIe,k as qW,l as DIe,m as yle,n as r0,nt as LIe,o as Wn,ot as J3,p as X3,q as NM,r as vn,rt as $Ie,st as ja,t as Qe,tt as lt,u as Y6,v as Km,w as SR,x as CR,y as OIe,z as Oy}from"./router-BxwR1PwE.js";import{$ as J6,$n as X6,$t as $S,A as Wj,An as Vu,At as xg,B as FIe,Bn as jle,Bt as mj,Cn as wle,Ct as Ug,D as BIe,Dn as Nle,Dt as qIe,E as zIe,En as kle,Et as UIe,F as KIe,Fn as Sle,Ft as Cle,G as VIe,Gn as WIe,Gt as _le,H as HIe,Hn as QIe,Ht as Ile,I as Ale,In as GIe,It as Hj,J as U$,Jn as HC,Jt as _R,K as YIe,Kn as Rle,Kt as Tle,L as JIe,Ln as zW,Lt as XIe,M as Aw,Mn as Pc,Mt as Fl,N as vv,Nn as Ele,Nt as Rw,O as Sx,On as Rm,Ot as ZIe,P as eAe,Pn as OS,Pt as wc,Q as tAe,Qn as Z6,Qt as Ple,R as sAe,Rn as nAe,Rt as rAe,Sn as IR,St as aAe,T as iAe,Tn as Mle,Tt as Dle,U as oAe,Un as Tw,Ut as Lle,V as lAe,Vn as cAe,Vt as dAe,W as $le,Wn as Z3,Wt as uAe,X as UW,Xn as mAe,Xt as nx,Y as Ole,Yn as Ew,Yt as Fle,Z as Ble,Zn as qle,Zt as hj,_ as zle,_n as AR,_r as e5,_t as hAe,a as pAe,an as KW,ar as Pw,at as fAe,b as xAe,bn as gAe,br as Kg,bt as Mw,c as kM,cn as Ule,cr as Ul,ct as Kle,d as RR,dn as Vle,dr as bAe,dt as Wle,en as pj,er as Hle,et as Qle,f as Gle,fn as ez,fr as Yle,ft as tz,g as VW,gn as TR,gr as Gp,gt as vAe,h as yAe,hn as Jle,hr as Xle,ht as jAe,i as wAe,in as WW,ir as Dw,it as QC,j as HW,jn as K$,jt as Zle,k as ece,kn as tce,kt as fj,l as NAe,ln as kAe,lr as du,lt as V$,m as ER,mn as PR,mr as SAe,mt as CAe,n as _Ae,nn as MR,nr as IAe,nt as AAe,o as RAe,on as TAe,or as el,ot as EAe,p as sce,pn as nce,pr as PAe,pt as MAe,q as DAe,qn as Lw,qt as rce,r as hx,rn as DR,rr as Yp,rt as Rh,s as QW,sn as ace,sr as tl,st as ice,t as sz,tn as oce,tr as GC,tt as yv,u as lce,un as GW,ur as Cx,ut as W$,v as SM,vn as LAe,vr as LR,vt as $l,w as cce,wn as YW,wt as YC,x as $Ae,xn as dce,xr as JC,xt as XC,y as OAe,yn as FAe,yr as t5,yt as $w,z as BAe,zn as qAe}from"./RoutineRunVariablesDialog-BkLLbP3a.js";import{$ as uce,Q as nr,Z as zAe,a as UAe,ct as KAe,et as JW,o as VAe,rt as mce,s as WAe,tt as cd}from"./mention-chips-pBjlxGok.js";import{g as HAe}from"./dist-Cc3Bt6H4.js";import{i as QAe}from"./dist-B3Uu-urE.js";import{A as GAe,C as YAe,D as JAe,E as s5,M as Tg,N as Bl,O as Pm,S as sl,T as vl,_ as n5,a as px,b as nz,c as r5,f as Eg,g as Pd,h as hce,j as xj,k as XAe,l as pa,m as Pg,n as fx,o as Th,p as Eh,r as zb,s as Jp,t as XW,v as Ad,x as rz,y as K_}from"./zap-gf6Ev631.js";import{C as ZAe,S as e2e,_ as t2e,a as Si,b as s2e,c as pce,i as Vr,l as _x,o as Vm,r as n2e,s as xc,t as yc,u as Vg,v as r2e}from"./MarkdownEditor-B3NYD32f.js";import{_ as az,a as fce,b as a5,c as xce,d as Ph,f as Mh,g as Dh,h as Lh,i as FS,l as $h,m as Oh,n as a2e,o as Fh,p as Bh,r as Qh,s as Wm,t as Gh,u as qh,v as zi,y as ql}from"./sheet-Z4n6AEBA.js";import{a as Yi,c as i2e,i as ZC,l as zc,n as o2e,o as Ji,r as Ll,s as gce,t as hr}from"./AgentAvatar-BR1Z_L_Z.js";import{A as Pi,C as hi,D as bce,E as vce,O as fa,S as Xf,T as yce,_ as iz,a as Zs,b as Ow,c as Sn,d as Fw,f as zn,g as xa,h as Un,i as l2e,k as Na,l as c2e,m as dd,n as An,o as Dn,p as Kn,r as Xs,s as yr,t as Ki,u as rn,v as ga,w as d2e,x as Sb,y as ps}from"./checkbox-CmYq-YMP.js";import{a as Ei,c as e1,d as To,f as t1,g as i5,h as _o,l as Ou,m as u2e,n as jv,o as o5,p as Qf,r as m2e,s as h2e,t as Vs,u as s1}from"./label-C-aWneNy.js";import{i as Ca,n as ia,r as Bc,t as Ci}from"./tabs-Dqn3cNzC.js";import{a as Gn,c as pr,i as H$,n as qc,o as p2e,r as sr,s as f2e,t as Wt}from"./agents-DrLpWAcm.js";import{a as jce,b as ec,d as wce,f as $R,g as oa,l as Nce,m as kd,n as x2e,o as kce,p as Sce,t as Gi,u as g2e,v as b2e,x as au,y as fo}from"./StatusIcon-DMDp_WJw.js";import{a as sc,i as xx,n as Cm,r as ri,t as Bw}from"./use-adapter-capabilities-0-4PhK9y.js";import{a as wv,c as qu,i as n1,n as v2e,o as ad,r as $n,s as l5,t as In}from"./EmptyState-DOb3I5aU.js";import{t as Xi}from"./bot-CET4VfU-.js";import{t as xs}from"./check-C6myARng.js";import{t as en}from"./chevron-down-D2wNtbQf.js";import{t as mn}from"./chevron-right-CU6xIk8W.js";import{a as y2e,c as _a,i as yn,l as r1,n as Ia,o as Cce,r as j2e,s as Aa,t as Ra}from"./select-BqqjvKLd.js";import{n as Rd,r as Vi,t as Bp}from"./save-D5KpMLil.js";import{A as gx,C as Q$,D as w2e,_ as oz,b as V_,c as N2e,h as k2e,i as S2e,j as la,k as xn,l as wg,n as C2e,o as _2e,p as G$,r as lz,t as F,u as I2e,y as A2e}from"./button-DCI8NFig.js";import{i as jr,n as ji,r as Io,t as Gr}from"./clipboard-BZT4l65i.js";import{t as xr}from"./external-link-BKz-OKDG.js";import{_ as R2e,a as T2e,c as _ce,d as Ice,f as E2e,g as P2e,h as qp,i as M2e,l as D2e,m as L2e,n as Ace,o as $2e,p as ZW,r as Rce,s as O2e,t as Rn,u as Tce,v as F2e,y as Gm}from"./MarkdownBody-AdwNLx7A.js";import{t as pi}from"./file-text-DXa-cUrm.js";import{a as c5,i as Lo,n as B2e,o as Ece,r as a1,t as Xr}from"./heartbeats-CY77VTM_.js";import{t as ot}from"./loader-circle-DwlcG9aS.js";import{n as qw,t as Ym}from"./useHiddenSettings-D9d6LOsg.js";import{t as Qj}from"./octagon-alert-CTp78pR9.js";import{t as Ii}from"./rotate-ccw-BhopZISX.js";import{t as Is}from"./triangle-alert-DOta-xfM.js";import{n as $a,t as q2e}from"./SidebarContext-9UFQ2Pex.js";import{n as z2e,t as dt}from"./badge-BLr1M3ne.js";import{n as Tr,t as _i}from"./environments-Cd-g_MmN.js";import{t as Rt}from"./input-BkGpMopE.js";import{a as Xp,i as i1,n as o1,o as fr,r as Ix,t as zw}from"./company-members-C1IoXITE.js";import{t as Ju}from"./health-Dc13TJNg.js";import{t as fn}from"./skeleton-BxD7FB8M.js";import{t as Md}from"./AgentIdentity-BgihkjQU.js";import{a as U2e,i as jl,n as K2e,o as Zi,r as za,s as uo,t as Gs}from"./card-BD8MkPAL.js";import{t as ya}from"./PageSkeleton-C-C3Xlc_.js";r((function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))a(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&a(l)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}r(n,"getFetchOpts");function a(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}r(a,"processPreload")}),"polyfill")();var V2e=class extends lIe{static{r(this,"InfiniteQueryObserver")}constructor(e,s){super(e,s)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,s){const{state:n}=e,a=super.createResult(e,s),{isFetching:i,isRefetching:o,isError:l,isRefetchError:c}=a,d=n.fetchMeta?.fetchMore?.direction,u=l&&d==="forward",h=i&&d==="forward",p=l&&d==="backward",x=i&&d==="backward";return{...a,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:tIe(s,n.data),hasPreviousPage:X_e(s,n.data),isFetchNextPageError:u,isFetchingNextPage:h,isFetchPreviousPageError:p,isFetchingPreviousPage:x,isRefetchError:c&&!u&&!p,isRefetching:o&&!h&&!x}}};function Nv(e,s){return dIe(e,V2e,s)}r(Nv,"useInfiniteQuery");var W2e="adapter_auth_missing",H2e="document",Q2e=80,G2e={markdown:"md",html:"html",json:"json",text:"txt"};function Y2e(e){return e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,Q2e).replace(/-+$/g,"")||H2e}r(Y2e,"documentExportSlug");function J2e(e){return G2e[(e??"").trim().toLowerCase()]??"md"}r(J2e,"documentExportExtension");function eH(e,s){const n=s.replace(/^\.+/,"").toLowerCase()||"md";return`${Y2e(e)}.${n}`}r(eH,"documentExportFileName");function Y$(e){const s=new Set([e.targetIssueId]);if(e.type==="create_issue"){e.draft.parentId&&s.add(e.draft.parentId);for(const n of e.draft.blockedByIssueIds??[])s.add(n)}if(e.type==="resolve_blocker")for(const n of e.removeBlockedByIssueIds)s.add(n);return[...s]}r(Y$,"decisionEffectTargetIssueIds");var X2e=new Set(["terminated","pending_approval","paused"]),Z2e=new Set(["active","idle","running","error"]);function eRe(e){return Z2e.has(e)&&!X2e.has(e)}r(eRe,"isAgentStatusInvokable");function ON(e){return e==="done"||e==="cancelled"}r(ON,"isPipelineTerminalStageKind");function Pce(e){const s={};for(const n of e)(s[n.stageId]??=[]).push(n);return s}r(Pce,"groupWarningsByStage");function Mce(e){return e==="RESPONSIBLE_USER_UNAUTHORIZED"||e==="RESPONSIBLE_USER_UNAVAILABLE"}r(Mce,"isResponsibleUserDenialCode");function l1(e){const s=e?.trim();return s&&s.length>0?s:"the responsible user"}r(l1,"responsibleUserLabel");function J$(e,s={}){const n=l1(s.userName);return e==="RESPONSIBLE_USER_UNAVAILABLE"?{code:e,tone:"unavailable",title:"Responsible user unavailable",description:`This run acts on behalf of ${n}, but that account was removed or deactivated, so its permissions can no longer be evaluated. The agent's own permissions are not enough on their own — every action still requires an active responsible user.`,recommendedAction:"Mark the work blocked and reassign a responsible user (or reactivate the account) before the agent continues."}:{code:e,tone:"unauthorized",title:"Responsible user not authorized",description:`This action was denied because ${n} — the user this run acts on behalf of — does not have permission to perform it. The agent may be allowed, but a run can never exceed the permissions of the user it acts for, so the action is blocked.`,recommendedAction:`Grant ${n} the required permission, or have someone who is authorized take this action instead.`}}r(J$,"describeResponsibleUserDenial");var tRe=["issue_write_not_visible","issue_write_actor_class_excluded","issue_write_responsible_user_ceiling","issue_write_responsible_user_unavailable","issue_write_assignee_run_lock","cross_issue_influence_cap_exceeded","cross_issue_influence_run_context_required","issue_write_attribution_spoof_rejected"];function sRe(e){const s=e?.trim();return s&&s.length>0?s:"this task"}r(sRe,"issueLabel$2");function nRe(e){const s=e?.trim();return s&&s.length>0?s:"the current assignee"}r(nRe,"assigneeLabel");function rRe(e){const s=e?.trim();return s&&s.length>0?s:"this agent"}r(rRe,"actorLabel$1");var aRe="create a child issue with the request in its description (issue creation is a separate, open write path) and let its assignee act";function iRe(e,s={}){const n=sRe(s.issueIdentifier),a=rRe(s.actorLabel),i=nRe(s.assigneeLabel),o=l1(s.responsibleUserName);switch(e){case"issue_write_not_visible":return{code:e,status:403,tone:"boundary",boundary:"Issue visibility",title:"Task is outside this actor's visibility",description:`Issue writes are open by default, but only for tasks the actor can already read. ${n} is not visible to ${a}, so its comment, update, child, and assignment channels are all closed — the wall is visibility, not the write itself.`,whoCanAct:`${i}, and any agent or board member the task is visible to.`,sanctionedPath:`Ask the board to widen visibility for ${a}, or ${aRe}.`};case"issue_write_actor_class_excluded":return{code:e,status:403,tone:"boundary",boundary:"Actor-class boundary",title:"This actor class cannot write to tasks",description:`Default-open issue writes are a standard-trust privilege. Low-trust, skill-test, and task-bridge scopes keep their existing tight walls, so ${a} cannot write to ${n} no matter who it acts for.`,whoCanAct:"A standard-trust agent in this company, or a board member.",sanctionedPath:"Report the request upward and let a standard-trust agent make the write — actor-class scope cannot be widened per task."};case"issue_write_responsible_user_ceiling":{const l=J$("RESPONSIBLE_USER_UNAUTHORIZED",{userName:s.responsibleUserName});return{code:e,status:403,tone:"boundary",boundary:"Responsible-user ceiling",title:l.title,description:`${l.description} The write to ${n} was refused for that reason.`,whoCanAct:`${o} once authorized, or anyone already permitted to write to ${n}.`,sanctionedPath:l.recommendedAction}}case"issue_write_responsible_user_unavailable":{const l=J$("RESPONSIBLE_USER_UNAVAILABLE",{userName:s.responsibleUserName});return{code:e,status:403,tone:"boundary",boundary:"Responsible-user availability",title:l.title,description:`${l.description} The write to ${n} was refused for that reason.`,whoCanAct:`A board member, or ${a} once it has an active responsible user.`,sanctionedPath:l.recommendedAction}}case"issue_write_assignee_run_lock":return{code:e,status:409,tone:"lock",boundary:"Run checkout lock",title:"Another agent's run owns this task",description:`${i} has ${n} checked out and a run is live. Checkout and run ownership stay assignee-scoped even though writes are open, so field edits belong to the run that holds the lock until it finishes.`,whoCanAct:`${i}'s live run, or an agent holding the manage-active-checkouts permission.`,sanctionedPath:`Comment instead of patching — comments stay open and wake ${i} — or wait for the run to release the lock and retry.`};case"cross_issue_influence_cap_exceeded":{const l=s.cap??20,c=s.count??null;return{code:e,status:429,tone:"cap",boundary:`Per-run cross-issue cap of ${l} writes`,title:"This run has spent its cross-issue write budget",description:`A single heartbeat run may make at most ${l} cross-issue comments or task updates combined${c!==null?`; this was attempt ${c}`:""}. The cap bounds runaway comment sprays and loops — it is a rate backstop, not a permission decision, so ${a} is still allowed to write to ${n}.`,whoCanAct:`${a} on its next heartbeat run, or ${i} on ${n} directly.`,sanctionedPath:"Consolidate what is left into one comment on your own task, or end the run and continue on the next heartbeat — the budget resets per run."}}case"cross_issue_influence_run_context_required":return{code:e,status:403,tone:"boundary",boundary:"Heartbeat run context",title:"Cross-issue writes need a run to attribute them to",description:"Every agent comment and task update is attributed to a heartbeat run so the cross-issue cap can be counted and the audit trail can name who acted for whom. This request arrived without a valid run, so it could not be contained.",whoCanAct:`${a}, once the request carries its own run id.`,sanctionedPath:"Send the `X-Paperclip-Run-Id` header with your current run (`$PAPERCLIP_RUN_ID`) and retry."};case"issue_write_attribution_spoof_rejected":return{code:e,status:422,tone:"attribution",boundary:"Server-derived attribution",title:"Responsible user cannot be chosen by the caller",description:"`onBehalfOfUserId` is derived from the authenticated actor, never from the request body — an agent cannot pick the human whose authority it rides. The attempt was recorded in the audit log.",whoCanAct:`${a} itself: the write is allowed, only the chosen attribution is not.`,sanctionedPath:`Remove \`onBehalfOfUserId\` from the request and retry; the server fills in ${o} from your run.`}}}r(iRe,"describeIssueWriteDenial");function Dce(e){return(typeof e=="string"?e:e?.name??"").trim()}r(Dce,"rawNameOf");function Lce(e){const s=e.toLowerCase();return!!(s.includes("://")||s==="localhost"||s.startsWith("localhost:")||/^\d{1,3}(\.\d{1,3}){3}(:\d+)?$/.test(s)||/^[a-z0-9.-]+:\d+$/.test(s))}r(Lce,"looksLikeNetworkAddress");function X$(e){return e.split(/[\s._-]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()).join(" ")}r(X$,"titleCaseIdentifier");function oRe(e){const s=/^plugin:\s*(.+)$/i.exec(e);if(!s)return null;let n=s[1].trim();return n=n.slice(n.lastIndexOf(".")+1),n=n.replace(/^plugin[-_]/i,""),X$(n)||"Custom app"}r(oRe,"pluginPackageLabel");function Zp(e,s={}){const n=s.title?.trim();if(n)return n;const a=Dce(e);if(!a||Lce(a))return"Custom app";const i=oRe(a);if(i)return i;if(a.includes(":")&&!a.includes("://")){const o=a.slice(a.lastIndexOf(":")+1).trim();if(o)return X$(o)}return/\s/.test(a)||/[A-Z]/.test(a)?a:/[._-]/.test(a)?X$(a):a}r(Zp,"humanizeConnectionDisplayName");function tH(e){const s=Dce(e);return s&&Lce(s)?`hosted at ${s}`:null}r(tH,"connectionDisplaySecondaryHint");var sH=`I want to connect an MCP (Model Context Protocol) server to Paperclip, and I need a paste-ready config.
3
3
 
4
4
  Target server: <name the server, or ask me if I have not said>
@@ -284,7 +284,7 @@ self.onmessage = function (e) {
284
284
  }
285
285
 
286
286
  };
287
- `;function zWe(){const e=new Blob([qWe],{type:"application/javascript"}),s=URL.createObjectURL(e);try{return new Worker(s)}finally{URL.revokeObjectURL(s)}}r(zWe,"createSandboxedWorker");var gF=new Map,ST=new Map,v2=new Set,y2=new Map,yfe=null;function UWe(e){yfe=e}r(UWe,"setDynamicParserResultNotifier");function jfe(e,s){e.worker.postMessage(s)}r(jfe,"sendToWorker");function KWe(e){return e.nextId++}r(KWe,"nextRequestId");function VWe(e,s){return`${s}\0${e}`}r(VWe,"lineCacheKey");function WWe(){yfe?.()}r(WWe,"notifyResultReady");function HWe(e,s,n){return new Promise(a=>{const i=KWe(e);e.pendingResolves.set(i,a),jfe(e,{type:"parse",id:i,line:s,ts:n})})}r(HWe,"parseLineAsync");function Ak(e){for(const s of e.pendingResolves.values())s([]);e.pendingResolves.clear()}r(Ak,"drainPendingRequests");function QWe(e){return new Promise((s,n)=>{const a=zWe(),i={worker:a,ready:!1,nextId:1,pendingResolves:new Map},o=setTimeout(()=>{Ak(i),a.terminate(),n(new Error("Parser worker init timed out"))},5e3);a.onmessage=l=>{const c=l.data;if(c.type==="ready"){clearTimeout(o),i.ready=!0,a.onmessage=d=>{const u=d.data;if(u.type==="result"){const h=i.pendingResolves.get(u.id);h&&(i.pendingResolves.delete(u.id),h(u.entries))}else u.type==="error"&&Ak(i)},s(i);return}if(c.type==="error"){clearTimeout(o),Ak(i),a.terminate(),n(new Error(c.message));return}},a.onerror=l=>{clearTimeout(o),Ak(i),a.terminate(),n(new Error(`Worker error: ${l.message}`))},jfe(i,{type:"init",source:e})})}r(QWe,"initSandboxedWorker");function GWe(e){const s=new Map,n=new Set;return{parseStdoutLine:r((i,o)=>{const l=VWe(i,o),c=s.get(l);return c?c.slice():(n.has(l)||(n.add(l),HWe(e,i,o).then(d=>{n.delete(l),s.set(l,d),WWe()})),[])},"parseStdoutLine")}}r(GWe,"buildParserModule");async function bF(e){const s=ST.get(e);if(s)return s;if(v2.has(e))return null;const n=y2.get(e);if(n)return n;const a=(async()=>{try{const i=await fetch(`/api/adapters/${encodeURIComponent(e)}/ui-parser.js`);if(!i.ok)return v2.add(e),null;const o=await QWe(await i.text());gF.set(e,o);const l=GWe(o);return ST.set(e,l),l}catch{return v2.add(e),null}finally{y2.delete(e)}})();return y2.set(e,a),a}r(bF,"loadDynamicParser");function vF(e){const s=ST.has(e);ST.delete(e),v2.delete(e),y2.delete(e);const n=gF.get(e);return n&&(Ak(n),n.worker.terminate(),gF.delete(e)),s}r(vF,"invalidateDynamicParser");var j2=[],Q5=new Map,yF=new Set,wfe=new Map,N4=new Set,iI=new Map,jF=new Set;function Nfe(e){return jF.add(e),()=>jF.delete(e)}r(Nfe,"onAdapterChange");function kfe(){for(const e of jF)e()}r(kfe,"notifyAdapterChange");UWe(kfe);function YWe(){for(const e of[M7e,Q7e,h9e,v9e,z9e,tVe,hVe,wVe,PVe,UVe,hWe,iWe,E9e,AWe,kT,BWe])yF.add(e.type),wfe.set(e.type,e),ab(e)}r(YWe,"registerBuiltInUIAdapters");function ab(e){const s=j2.findIndex(n=>n.type===e.type);s>=0?j2.splice(s,1,e):j2.push(e),Q5.set(e.type,e),kfe()}r(ab,"registerUIAdapter");function Sfe(e){return Q5.get(e)??null}r(Sfe,"findUIAdapter");YWe();function Xw(e){const s=Q5.get(e);if(!s){let n=!1;return{type:e,label:e,parseStdoutLine:r((a,i)=>(n||(n=!0,bF(e).then(o=>{o&&ab({type:e,label:e,parseStdoutLine:o.parseStdoutLine,createStdoutParser:o.createStdoutParser,ConfigFields:Xb,buildAdapterConfig:aw})})),kT.parseStdoutLine(a,i)),"parseStdoutLine"),ConfigFields:Xb,buildAdapterConfig:aw}}return s}r(Xw,"getUIAdapter");function JWe(e){const s=new Set(e.filter(a=>!a.disabled&&!a.overrideDisabled).map(a=>a.type)),n=new Set(e.map(a=>a.type));for(const a of yF){const i=wfe.get(a);if(!i)continue;const o=n.has(a),l=s.has(a),c=N4.has(a);if(o&&l&&!c){N4.add(a);const d=(iI.get(a)??0)+1;iI.set(a,d);let u=!1;const h=i.parseStdoutLine,p=e.find(x=>x.type===a)?.label??a;ab({type:a,label:p,parseStdoutLine:r((x,g)=>(u||(u=!0,bF(a).then(v=>{v&&iI.get(a)===d&&ab({type:a,label:p,parseStdoutLine:v.parseStdoutLine,createStdoutParser:v.createStdoutParser,ConfigFields:i.ConfigFields,buildAdapterConfig:i.buildAdapterConfig})})),h(x,g)),"parseStdoutLine"),ConfigFields:i.ConfigFields,buildAdapterConfig:i.buildAdapterConfig})}else(!o||!l)&&c&&(N4.delete(a),iI.delete(a),vF(a),ab(i))}for(const{type:a,label:i}of e){if(yF.has(a))continue;const o=Q5.get(a);if(o&&o!==kT)continue;let l=!1;const c=o?.parseStdoutLine??kT.parseStdoutLine;ab({type:a,label:i,parseStdoutLine:r((d,u)=>(l||(l=!0,bF(a).then(h=>{h&&ab({type:a,label:i,parseStdoutLine:h.parseStdoutLine,createStdoutParser:h.createStdoutParser,ConfigFields:o?.ConfigFields??Xb,buildAdapterConfig:o?.buildAdapterConfig??aw})})),c(d,u)),"parseStdoutLine"),ConfigFields:o?.ConfigFields??Xb,buildAdapterConfig:o?.buildAdapterConfig??aw})}}r(JWe,"syncExternalAdapters");function HU(){return[...j2]}r(HU,"listUIAdapters");function XWe(e){if(typeof e=="function")return{parseLine:e,reset:null};if(e.createStdoutParser){const s=e.createStdoutParser();return{parseLine:s.parseLine,reset:s.reset}}return{parseLine:e.parseStdoutLine,reset:null}}r(XWe,"resolveStdoutParser");function Cfe(e,s){if((s.kind==="thinking"||s.kind==="assistant")&&s.delta){const n=e[e.length-1];if(n&&n.kind===s.kind&&n.delta&&n.channel===s.channel){n.text+=s.text,n.ts=s.ts;return}}e.push(s)}r(Cfe,"appendTranscriptEntry");function ZWe(e,s){for(const n of s)Cfe(e,n)}r(ZWe,"appendTranscriptEntries");function eHe(e,s=160){return e.length<=s?e:`${e.slice(0,s-3)}...`}r(eHe,"truncateTranscriptLine");function tHe(e){if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"&&e)return e;try{return JSON.stringify(e)}catch{return String(e)}}r(tHe,"formatTranscriptParserError");function sHe(e,s,n,a){const i=tHe(n)||"unknown parser error",o=eHe(e);return{kind:"result",ts:s,text:Fu(`Chat transcript error: ${i}. Falling back for line: ${o}`,a),inputTokens:0,outputTokens:0,cachedTokens:0,costUsd:0,subtype:"transcript_parse_error",isError:!0,errors:[]}}r(sHe,"createTranscriptParseErrorEntry");function CY(e){const{entries:s,line:n,ts:a,parseLine:i,reset:o,redactionOptions:l}=e;try{ZWe(s,i(n,a).map(c=>AFe(c,l)))}catch(c){o?.(),Cfe(s,sHe(n,a,c,l))}}r(CY,"appendParsedTranscriptLine");function _fe(e,s,n){const a=[];let i="";const o={enabled:n?.censorUsernameInLogs??!1},{parseLine:l,reset:c}=XWe(s);for(const u of e){if(u.stream==="stderr"){a.push({kind:"stderr",ts:u.ts,text:Fu(u.chunk,o)});continue}if(u.stream==="system"){a.push({kind:"system",ts:u.ts,text:Fu(u.chunk,o)});continue}const h=(i+u.chunk).split(/\r?\n/);i=h.pop()??"";for(const p of h){const x=p.trim();x&&CY({entries:a,line:x,ts:u.ts,parseLine:l,reset:c,redactionOptions:o})}}const d=i.trim();return d&&CY({entries:a,line:d,ts:e.length>0?e[e.length-1].ts:new Date().toISOString(),parseLine:l,reset:c,redactionOptions:o}),c?.(),a}r(_fe,"buildTranscript");function nHe({agents:e,value:s,onChange:n,disabled:a=!1,excludeAgentIds:i=[],disabledEmptyLabel:o="Reports to: N/A (CEO)",chooseLabel:l="Reports to..."}){const[c,d]=(0,m.useState)(!1),u=new Set(i),h=e.filter(v=>v.status!=="terminated"&&!u.has(v.id)),p=s?e.find(v=>v.id===s):null,x=p?.status==="terminated",g=!!(s&&!p);return(0,t.jsxs)(sr,{open:c,onOpenChange:d,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:U("inline-flex max-w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",x&&"border-amber-600/45 bg-amber-500/5",a&&"opacity-60 cursor-not-allowed"),disabled:a,children:g?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(xc,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate text-muted-foreground",children:"Unknown manager (stale ID)"})]}):p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(hr,{agent:p,size:16,className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:U("min-w-0 truncate",x&&"text-amber-900 dark:text-amber-200"),children:`Reports to ${p.name}${x?" (terminated)":""}`})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(xc,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:a?o:l})]})})}),(0,t.jsxs)(Gn,{className:"w-48 p-1",align:"start",children:[(0,t.jsx)("button",{type:"button",className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",s===null&&"bg-accent"),onClick:r(()=>{n(null),d(!1)},"onClick"),children:"No manager"}),x&&(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:[(0,t.jsx)(hr,{agent:p,size:16,className:"shrink-0 h-3 w-3"}),(0,t.jsxs)("span",{className:"min-w-0 truncate",children:["Current: ",p.name," (terminated)"]})]}),g&&(0,t.jsx)("div",{className:"px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:"Saved manager is missing from this organization. Choose a new manager or clear."}),h.map(v=>(0,t.jsxs)("button",{type:"button",className:U("flex items-center gap-2 w-full min-w-0 px-2 py-1.5 text-xs rounded hover:bg-accent/50 overflow-hidden",v.id===s&&"bg-accent"),onClick:r(()=>{n(v.id),d(!1)},"onClick"),children:[(0,t.jsx)(hr,{agent:v,size:16,className:"shrink-0 h-3 w-3 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:v.name}),(0,t.jsx)("span",{className:"text-muted-foreground ml-auto shrink-0",children:UU[v.role]??v.role})]},v.id))]})]})}r(nHe,"ReportsToPicker");var rHe="__secret_folder__:";function aHe(e){return!e||e==="active"?null:(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) font-normal text-muted-foreground",children:e})}r(aHe,"statusBadge");function Ife(e){return e.split("/").filter(s=>s.length>0)}r(Ife,"splitSecretPath$1");function w2(e){return e.join("/")}r(w2,"pathKey$1");function KN(e){return e.length>0?`/${e.join("/")}`:"/"}r(KN,"pathLabel");function iHe(e,s){return e.length<s.length?!1:s.every((n,a)=>e[a]===n)}r(iHe,"pathStartsWith");function _Y(e){return`${rHe}${w2(e)}`}r(_Y,"folderValue");function oHe(e,s,n){const a=s.length,i=new Map,o=[];for(const c of e){const d=Ife(c.name);if(iHe(d,s)){if(d.length>a+1){const u=d.slice(0,a+1),h=w2(u);if(!i.has(h)){const p=u[u.length-1]??"/",x=KN(u);i.set(h,{key:`folder-${h||"root"}`,value:_Y(u),label:p,title:x,searchText:x,kind:"folder",folderPath:h,pathHint:x})}continue}if(d.length===a+1||a===0&&d.length===0){const u=d.at(-1)??c.name;o.push({key:`browse-${c.id}`,value:c.id,label:u,title:c.name,searchText:`${c.key} ${c.name}`,secret:c,status:c.status,kind:"secret",pathHint:c.name,disabled:c.status!=="active"&&c.id!==n})}}}const l=[];if(s.length>0){const c=s.slice(0,-1);l.push({key:`folder-up-${w2(s)}`,value:_Y(c),label:"Up one folder",title:KN(c),searchText:KN(c),kind:"back",folderPath:w2(c),pathHint:KN(c)})}return l.push(...i.values(),...o),{id:"browse-secrets",label:s.length>0?KN(s):"Browse secrets",options:l}}r(oHe,"buildFolderGroup");function QU({secretId:e,secrets:s,recentlyUsedSecrets:n,disabled:a,onSelect:i,onCreateNew:o,triggerClassName:l,disablePortal:c}){const[d,u]=(0,m.useState)(""),h=(0,m.useMemo)(()=>s.find(j=>j.id===e)??null,[s,e]),p=!!e&&!h,x=(0,m.useMemo)(()=>d?d.split("/"):[],[d]),g=(0,m.useMemo)(()=>s.some(j=>Ife(j.name).length>1),[s]),v=(0,m.useMemo)(()=>{const j=[];p&&j.push({id:"current-missing",label:"Current",options:[{key:`missing-${e}`,value:e,label:`Missing secret (${e.slice(0,8)}…)`,title:`Missing secret (${e})`,missing:!0,disabled:!0}]});const S=(n??[]).filter(w=>w.status==="active"&&w.id!==e);return S.length>0&&j.push({id:"recently-used",label:"Recently used",options:S.map(w=>({key:`recent-${w.id}`,value:w.id,label:w.name,title:w.name,searchText:`${w.key} ${w.name}`,secret:w,status:w.status,kind:"secret"}))}),j.push({id:"all-secrets",label:S.length>0?"All secrets":void 0,options:s.map(w=>({key:`all-${w.id}`,value:w.id,label:w.name,title:w.name,searchText:`${w.key} ${w.name}`,secret:w,status:w.status,kind:"secret",disabled:w.status!=="active"&&w.id!==e}))}),j},[p,n,e,s]),y=(0,m.useCallback)((j,S)=>{if(!g||m2e(j))return S;const w=oHe(s,x,e),N=S.filter(_=>_.id==="current-missing"||_.id==="recently-used");return w.options.length>0?[...N,w]:N},[x,g,e,s]);return(0,t.jsx)(jv,{value:e||"",groups:v,onValueChange:r((j,S)=>{if(S.folderPath!==void 0)return u(S.folderPath),!1;u(""),i(j)},"onValueChange"),deriveGroups:y,disabled:a,disablePortal:c,placeholder:"Select secret…",searchPlaceholder:"Search secrets…",emptyMessage:"No matching secrets",triggerClassName:U("h-(--sz-34px) min-h-(--sz-34px) font-mono text-sm",p&&"border-destructive text-destructive",h&&h.status!=="active"&&"border-amber-500/60",l),renderValue:r(j=>{if(!j)return(0,t.jsx)("span",{className:"text-muted-foreground",children:"Select secret…"});if(j.missing)return(0,t.jsxs)("span",{className:"flex w-full min-w-0 items-center gap-1.5 text-destructive",children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:j.label})]});const S=j.status&&j.status!=="active";return(0,t.jsxs)("span",{className:"flex w-full min-w-0 items-center gap-1.5",title:j.title,children:[(0,t.jsx)(ji,{className:U("size-3.5 shrink-0",S?"text-amber-600":"text-muted-foreground")}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:j.label}),S?(0,t.jsxs)("span",{className:"text-amber-600",children:["(",j.status,")"]}):null]})},"renderValue"),renderOption:r((j,{selected:S})=>{if(j.kind==="folder"||j.kind==="back"){const w=j.kind==="back"?JTe:qc;return(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",title:j.title??j.label,children:[(0,t.jsx)(w,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsxs)("span",{className:"flex min-w-0 flex-col",children:[(0,t.jsx)("span",{className:U("truncate text-sm",S&&"font-medium"),children:j.label}),j.pathHint?(0,t.jsx)("span",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground",children:j.pathHint}):null]})]})}return(0,t.jsxs)("span",{className:U("flex min-w-0 flex-1 items-center gap-1.5",j.disabled&&"opacity-60"),title:j.title??j.label,children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsxs)("span",{className:"flex min-w-0 flex-col",children:[(0,t.jsx)("span",{className:U("min-w-0 truncate font-mono text-sm",S&&"font-medium"),children:j.label}),j.pathHint&&j.pathHint!==j.label?(0,t.jsx)("span",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground",children:j.pathHint}):null]}),aHe(j.status)]})},"renderOption"),createItem:o?{render:r(j=>(0,t.jsxs)("span",{className:"flex items-center gap-1.5 text-sm",children:[(0,t.jsx)(xn,{className:"size-3.5 shrink-0"}),j.trim()?(0,t.jsxs)("span",{children:["Create secret ",(0,t.jsxs)("span",{className:"font-mono",children:["“",j.trim(),"”"]}),"…"]}):(0,t.jsx)("span",{children:"Create new secret…"})]}),"render"),onSelect:r(j=>o(j),"onSelect")}:void 0})}r(QU,"SecretPicker");var lHe=/^[a-z][a-z0-9_]*$/,IY="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/40";function Afe({mode:e,initialName:s,initialValue:n,existingSecretNames:a,onCancel:i,onSubmit:o}){const[l,c]=(0,m.useState)(s),[d,u]=(0,m.useState)(n),[h,p]=(0,m.useState)(!1),[x,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),[j,S]=(0,m.useState)(!1),w=l.trim(),N=w?lHe.test(w)?a?.some(R=>R.toLowerCase()===w)?"A secret with this name already exists":null:"Use lowercase letters, digits and _":j?"Name is required":null,_=d.length===0&&j?"Value is required":null,I=!x&&w.length>0&&d.length>0&&!N;async function C(){if(S(!0),!!I){g(!0),y(null);try{await o(w,d)}catch(R){y(R instanceof Error?R.message:"Failed to create secret"),g(!1)}}}r(C,"handleSubmit");const A=e==="create"?"Create & bind":"Store & bind";return(0,t.jsxs)("div",{className:"w-72 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(f2e,{className:"text-sm font-medium",children:e==="create"?"Create secret":"Store value as secret"}),e==="store"?(0,t.jsxs)(p2e,{className:"text-(length:--text-micro) text-muted-foreground",children:["Moves the typed value into an encrypted organization secret and binds"," ",(0,t.jsx)("span",{className:"font-mono",children:s||"this variable"})," to it."]}):null]}),(0,t.jsxs)("label",{className:"block space-y-1",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium text-muted-foreground",children:"Name"}),(0,t.jsx)("input",{className:U(IY,N&&"border-destructive focus-visible:ring-destructive/40"),value:l,autoFocus:!0,spellCheck:!1,placeholder:"secret_name","aria-label":"Secret name","aria-invalid":N?!0:void 0,onChange:r(R=>c(R.target.value),"onChange"),onBlur:r(()=>S(!0),"onBlur"),onKeyDown:r(R=>{R.key==="Enter"&&(R.preventDefault(),C())},"onKeyDown")}),N?(0,t.jsx)("span",{className:"block text-(length:--text-micro) text-destructive",children:N}):null]}),(0,t.jsxs)("label",{className:"block space-y-1",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium text-muted-foreground",children:"Value"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{className:U(IY,"pr-8",_&&"border-destructive focus-visible:ring-destructive/40"),type:h?"text":"password",value:d,readOnly:e==="store",spellCheck:!1,placeholder:e==="create"?"value":void 0,"aria-label":"Secret value","aria-invalid":_?!0:void 0,onChange:e==="create"?R=>u(R.target.value):void 0}),(0,t.jsx)("button",{type:"button",className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:text-foreground","aria-label":h?"Hide value":"Show value",onClick:r(()=>p(R=>!R),"onClick"),children:h?(0,t.jsx)(Hm,{className:"h-3.5 w-3.5"}):(0,t.jsx)(cd,{className:"h-3.5 w-3.5"})})]}),_?(0,t.jsx)("span",{className:"block text-(length:--text-micro) text-destructive",children:_}):null]}),v?(0,t.jsx)("p",{className:"text-(length:--text-micro) text-destructive",children:v}):null,(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2 pt-0.5",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",onClick:i,disabled:x,children:"Cancel"}),(0,t.jsxs)(F,{type:"button",size:"sm",onClick:r(()=>{C()},"onClick"),disabled:!I,children:[x?(0,t.jsx)(ot,{className:"h-3.5 w-3.5 animate-spin"}):null,A]})]})]})}r(Afe,"SecretPopoverForm");function Rfe(e){return(0,t.jsx)(Afe,{mode:"create",...e})}r(Rfe,"CreateSecretPopover");function cHe(e){return(0,t.jsx)(Afe,{mode:"store",...e})}r(cHe,"ConvertToSecretPopover");var dHe=/(api[-_]?key|access[-_]?token|auth(?:_?token)?|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring)/i,uHe=[/^sk-[A-Za-z0-9-_]{16,}$/,/^gh[pousr]_[A-Za-z0-9]{20,}$/,/^github_pat_[A-Za-z0-9_]{20,}$/,/^xox[baprs]-[A-Za-z0-9-]{10,}$/,/^AKIA[0-9A-Z]{16}$/,/^AIza[0-9A-Za-z\-_]{20,}$/,/-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----/,/^eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/];function mHe(e){return e.length<24||/\s/.test(e)||!/^[A-Za-z0-9+/=_\-.]+$/.test(e)?!1:[/[a-z]/.test(e),/[A-Z]/.test(e),/[0-9]/.test(e)].filter(Boolean).length>=2}r(mHe,"looksHighEntropy");function hHe(e,s){return s?dHe.test(e)||uHe.some(n=>n.test(s))?!0:mHe(s):!1}r(hHe,"isSensitiveEnv");var AY=0;function pHe(){return AY+=1,`env-row-${AY}`}r(pHe,"nextRowId");function ex(e="text"){return{id:pHe(),name:"",source:e,textValue:"",secretId:"",userSecretKey:"",required:!0,version:"latest"}}r(ex,"emptyRow");function fHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="secret_ref"}r(fHe,"isSecretRef");function xHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="plain"}r(xHe,"isPlainObj");function gHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="user_secret_ref"}r(gHe,"isUserSecretRef");function k4(e){return!e||typeof e!="object"?[]:Object.entries(e).map(([s,n])=>{if(typeof n=="string")return{...ex(),name:s,textValue:n};if(fHe(n)){const a=typeof n.version=="number"?n.version:"latest";return{...ex(),name:s,source:"secret",secretId:typeof n.secretId=="string"?n.secretId:"",version:a}}if(gHe(n)){const a=typeof n.version=="number"?n.version:"latest";return{...ex(),name:s,source:"user_secret",userSecretKey:typeof n.key=="string"?n.key:"",required:n.required!==!1,version:a}}return xHe(n)?{...ex(),name:s,source:"text",textValue:typeof n.value=="string"?n.value:""}:{...ex(),name:s}})}r(k4,"rowsFromValue");function N2(e){const s={};for(const n of e){const a=n.name.trim();if(a)if(n.source==="secret"){if(!n.secretId)continue;s[a]={type:"secret_ref",secretId:n.secretId,version:n.version}}else if(n.source==="user_secret"){const i=n.userSecretKey.trim();if(!i)continue;s[a]={type:"user_secret_ref",key:i,version:n.version,required:n.required}}else s[a]={type:"plain",value:n.textValue}}return Object.keys(s).length>0?s:void 0}r(N2,"valueFromRows");var RY="CLAUDE_CODE_OAUTH_TOKEN";function sj(){return N2([{...ex("user_secret"),name:"CLAUDE_CODE_OAUTH_TOKEN",userSecretKey:"CLAUDE_CODE_OAUTH_TOKEN",required:!0,version:"latest"}])??{}}r(sj,"buildFixedClaudeOAuthBinding");var bHe=/^[A-Za-z_][A-Za-z0-9_]*$/;function vHe(e,s,n){const a=e.trim();if(!a)return null;if(!bHe.test(a))return{level:"error",message:"Invalid name — use letters, digits and _"};if(s.has(a))return{level:"error",message:"Duplicate name"};for(const i of n)if(i&&a.startsWith(i))return{level:"warn",message:"Reserved prefix — provided automatically and may be overridden"};return null}r(vHe,"validateName");function yHe(e){const s=new Map;for(const a of e){const i=a.name.trim();i&&s.set(i,(s.get(i)??0)+1)}const n=new Set;for(const[a,i]of s)i>1&&n.add(a);return n}r(yHe,"computeDuplicateNames");function jHe(e,s){return s===e.source?{kind:"noop"}:s==="secret"?e.textValue.trim()?{kind:"open-store",name:CT(e.name)||"secret",value:e.textValue}:{kind:"to-secret"}:{kind:"to-text",undoFrom:e.secretId?{...e}:null}}r(jHe,"planSourceSwitch");function Tfe(e,s){if(e.source!=="secret"||!e.secretId)return null;const n=s.find(a=>a.id===e.secretId);return n?n.status!=="active"?{level:"warn",kind:"disabled",message:"Runs will fail until re-enabled or rebound."}:null:{level:"error",kind:"missing",message:"This secret no longer exists — runs will fail until you rebind."}}r(Tfe,"computeRowHealth");function Efe(e,s){if(e.source!=="user_secret"||!e.userSecretKey||!s?.length)return null;const n=s.find(a=>a.key===e.userSecretKey);return n?n.status!=="active"?{level:"warn",kind:"disabled",message:"Runs will fail until this user secret definition is re-enabled or rebound."}:null:{level:"error",kind:"missing",message:"This user secret definition no longer exists — runs will fail until you rebind."}}r(Efe,"computeUserSecretRowHealth");function CT(e){return e.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)}r(CT,"secretNameFromKey");function pS(e){return e.trim().toUpperCase().replace(/[^A-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)}r(pS,"envKeyFromSecretName");var wHe="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/40",TY="min-w-0 flex-1 bg-transparent px-2 py-1.5 text-sm font-mono outline-none placeholder:text-muted-foreground/40";function NHe({row:e,isLast:s,secrets:n,userSecretDefinitions:a,recentlyUsedSecrets:i,disabled:o,nameIssue:l,showNameIssue:c,dirtyFields:d,onPatch:u,onRemove:h,onNameBlur:p,onNamePaste:x,onEnterInValueLast:g,onCreateSecret:v,onToast:y,focusRequest:j,onFocusConsumed:S}){const w=(0,m.useRef)(null),N=(0,m.useRef)(null),_=(0,m.useRef)(null),[I,C]=(0,m.useState)(null),[A,R]=(0,m.useState)(!1),[E,O]=(0,m.useState)(null),L=Tfe(e,n)??Efe(e,a),$=e.source==="secret"?n.find(X=>X.id===e.secretId)??null:null,T=(a?.length??0)>0,q=e.source==="text"&&!e.sensitiveDismissed&&hHe(e.name,e.textValue);(0,m.useEffect)(()=>{j&&(j==="name"?w.current?.focus():e.source==="text"?N.current?.focus():e.source==="secret"?_.current?.querySelector("[role=combobox]")?.focus():_.current?.querySelector("select,input")?.focus(),S())},[j,S,e.source]),(0,m.useEffect)(()=>{if(!E)return;const X=window.setTimeout(()=>O(null),5e3);return()=>window.clearTimeout(X)},[E]);function B(X){if(X==="user_secret"){if(e.source==="user_secret")return;u({source:"user_secret",secretId:"",version:"latest"}),window.setTimeout(()=>_.current?.querySelector("select,input")?.focus(),0);return}const le=jHe(e,X);switch(le.kind){case"noop":return;case"open-store":{const{name:oe,value:te}=le;window.setTimeout(()=>C({mode:"store",name:oe,value:te}),0);return}case"to-secret":u({source:"secret",userSecretKey:"",required:!0}),window.setTimeout(()=>{_.current?.querySelector("[role=combobox]")?.focus()},0);return;case"to-text":le.undoFrom&&O(le.undoFrom),u({source:"text",secretId:"",userSecretKey:"",required:!0,version:"latest"}),window.setTimeout(()=>N.current?.focus(),0);return}}r(B,"switchSource");async function K(X,le){const oe=await v(X,le);u({source:"secret",secretId:oe.id,userSecretKey:"",required:!0,version:"latest",textValue:""}),y(`Secret ${oe.name} created`),C(null)}r(K,"submitSecretPopover");function z(){const X=CT(e.name)||"secret",{textValue:le}=e;window.setTimeout(()=>C({mode:"store",name:X,value:le}),0)}r(z,"openStoreAsSecret");const D=e.source==="text"?"Text value":e.source==="secret"?"Organization secret reference":"User secret reference",V=`${e.id}-name-error`,H=`${e.id}-health`,Z=d.name||d.value,Y=$?Math.max(0,$.latestVersion):0,ie=e.version==="latest"?"latest":`v${e.version}`,se=e.version!=="latest";return(0,t.jsxs)("div",{className:U("group/row grid grid-cols-(--gtc-13) items-start gap-x-1.5 gap-y-1 rounded-md px-1 py-1","@[40rem]/env:grid-cols-(--gtc-14) @[40rem]/env:items-center",Z&&"bg-amber-500/[0.06] ring-1 ring-amber-500/20"),children:[(0,t.jsx)("div",{className:"col-start-1 row-start-1 min-w-0 @[40rem]/env:row-start-1 @[40rem]/env:self-start",children:(0,t.jsx)("input",{ref:w,className:U(wHe,d.name&&"border-amber-500/70 bg-amber-500/10 focus-visible:ring-amber-500/40",c&&l?.level==="error"&&"border-destructive focus-visible:ring-destructive/40",c&&l?.level==="warn"&&"border-amber-500 focus-visible:ring-amber-500/40"),placeholder:"KEY",value:e.name,spellCheck:!1,disabled:o,"aria-label":"Variable name","aria-invalid":c&&l?.level==="error"?!0:void 0,"aria-describedby":c&&l?V:void 0,onChange:r(X=>u({name:X.target.value}),"onChange"),onBlur:p,onPaste:r(X=>{e.name||x(X.clipboardData.getData("text"))&&X.preventDefault()},"onPaste"),onKeyDown:r(X=>{X.key==="Enter"&&(X.preventDefault(),e.source==="text"?N.current?.focus():_.current?.querySelector("[role=combobox],select,input")?.focus())},"onKeyDown")})}),(0,t.jsxs)("div",{className:"col-span-2 col-start-1 row-start-2 min-w-0 @[40rem]/env:col-span-1 @[40rem]/env:col-start-2 @[40rem]/env:row-start-1",children:[(0,t.jsxs)(sr,{open:I!==null,onOpenChange:r(X=>{X||C(null)},"onOpenChange"),children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsxs)("div",{ref:_,className:U("relative flex items-stretch overflow-hidden rounded-md border border-border bg-transparent focus-within:ring-2 focus-within:ring-ring/40",d.value&&"border-amber-500/70 bg-amber-500/10 focus-within:ring-amber-500/40",o&&"opacity-60"),children:[(0,t.jsxs)(xa,{children:[(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(fa,{asChild:!0,disabled:o,children:(0,t.jsxs)("button",{type:"button","aria-label":"Value source",className:"flex shrink-0 items-center gap-0.5 border-r border-border px-2 text-muted-foreground hover:bg-accent/50 disabled:pointer-events-none",children:[e.source==="text"?(0,t.jsx)(LEe,{className:"size-3.5"}):e.source==="secret"?(0,t.jsx)(ji,{className:"size-3.5"}):(0,t.jsx)(pu,{className:"size-3.5"}),(0,t.jsx)(en,{className:"size-3 opacity-60"})]})})}),(0,t.jsx)(Kn,{side:"top",children:D})]}),(0,t.jsxs)(ga,{align:"start",className:"w-56",children:[(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("text"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"Text value"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Store the value inline as plain text."})]}),(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("secret"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"Organization secret"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Resolve a stored organization secret at run start."})]}),(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("user_secret"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"User secret"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Resolve the responsible user's own value at run start."})]})]})]}),e.source==="text"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("input",{ref:N,className:TY,placeholder:"value",value:e.textValue,type:q?"password":"text",spellCheck:!1,disabled:o,"aria-label":"Variable value",onChange:r(X=>u({textValue:X.target.value}),"onChange"),onKeyDown:r(X=>{X.key==="Enter"&&s&&(X.preventDefault(),g())},"onKeyDown")}),q?(0,t.jsxs)("div",{className:"flex shrink-0 items-stretch border-l border-border",children:[(0,t.jsxs)("button",{type:"button",onClick:z,disabled:o,className:"flex items-center gap-1 px-2 text-(length:--text-micro) text-amber-700 hover:bg-amber-500/10 dark:text-amber-400",title:"This value looks sensitive — store it as a secret",children:[(0,t.jsx)(wl,{className:"size-3.5"}),(0,t.jsx)("span",{className:"hidden @[30rem]/env:inline",children:"Store as secret"})]}),(0,t.jsx)("button",{type:"button",onClick:r(()=>u({sensitiveDismissed:!0}),"onClick"),disabled:o,"aria-label":"Dismiss sensitive-value suggestion",title:"Dismiss — keep this value as plain text",className:"flex items-center px-1.5 text-amber-700/60 hover:bg-amber-500/10 hover:text-amber-700 dark:text-amber-400/60 dark:hover:text-amber-400",children:(0,t.jsx)(nr,{className:"size-3"})})]}):null]}):e.source==="secret"?(0,t.jsxs)("div",{className:"relative min-w-0 flex-1",children:[(0,t.jsx)(QU,{secretId:e.secretId,secrets:n,recentlyUsedSecrets:i,disabled:o,onSelect:r(X=>u({secretId:X,version:"latest"}),"onSelect"),onCreateNew:r(X=>C({mode:"create",name:CT(X)||X.trim(),value:""}),"onCreateNew"),triggerClassName:U("rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0",$&&$.status==="active"&&"pr-24 has-[>svg]:!pr-24")}),$&&$.status==="active"?(0,t.jsxs)(sr,{open:A,onOpenChange:R,children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsx)("button",{type:"button",disabled:o,onClick:r(X=>{X.preventDefault(),X.stopPropagation(),R(le=>!le)},"onClick"),"aria-label":"Version",className:U("absolute right-8 top-1/2 z-10 -translate-y-1/2 rounded px-1.5 py-0.5 text-(length:--text-nano) font-medium",se?"bg-amber-500/15 text-amber-700 dark:text-amber-400":"text-muted-foreground hover:bg-accent"),children:ie})}),(0,t.jsxs)(Gn,{align:"end",className:"w-44 p-1",role:"radiogroup","aria-label":"Secret version",children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":e.version==="latest",onClick:r(()=>{u({version:"latest"}),R(!1)},"onClick"),className:U("flex w-full items-center justify-between rounded px-2 py-1.5 text-sm hover:bg-accent",e.version==="latest"&&"font-medium"),children:["latest ",(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"(recommended)"})]}),Array.from({length:Y},(X,le)=>Y-le).filter(X=>X>0).map(X=>(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":e.version===X,onClick:r(()=>{u({version:X}),R(!1)},"onClick"),className:U("flex w-full items-center rounded px-2 py-1.5 text-sm hover:bg-accent",e.version===X&&"font-medium text-amber-700 dark:text-amber-400"),children:["v",X]},X))]})]}):null]}):(0,t.jsxs)("div",{className:"grid min-w-0 flex-1 grid-cols-(--gtc-13)",children:[T?(0,t.jsxs)("select",{"aria-label":"User secret",value:e.userSecretKey,disabled:o,onChange:r(X=>{const le=X.target.value,oe=a?.find(te=>te.key===le);u({userSecretKey:le,...oe&&!e.name.trim()?{name:oe.key.toUpperCase()}:{}})},"onChange"),className:"min-w-0 bg-transparent px-2 py-1.5 text-sm font-mono outline-none disabled:pointer-events-none",children:[(0,t.jsx)("option",{value:"",children:"Select user secret..."}),e.userSecretKey&&!a?.some(X=>X.key===e.userSecretKey)?(0,t.jsxs)("option",{value:e.userSecretKey,children:["Unknown (",e.userSecretKey,")"]}):null,(a??[]).map(X=>(0,t.jsxs)("option",{value:X.key,children:[X.name,X.status!=="active"?` (${X.status})`:""]},X.id))]}):(0,t.jsx)("input",{className:TY,placeholder:"user-secret key",value:e.userSecretKey,spellCheck:!1,disabled:o,"aria-label":"User secret key",onChange:r(X=>u({userSecretKey:X.target.value}),"onChange")}),(0,t.jsxs)("select",{"aria-label":"Requirement",value:e.required?"required":"optional",disabled:o,onChange:r(X=>u({required:X.target.value==="required"}),"onChange"),className:"border-l border-border bg-transparent px-2 py-1.5 text-xs font-medium text-muted-foreground outline-none disabled:pointer-events-none",children:[(0,t.jsx)("option",{value:"required",children:"Required"}),(0,t.jsx)("option",{value:"optional",children:"Optional"})]})]})]})}),(0,t.jsx)(Gn,{align:"start",className:"w-auto p-3",onInteractOutside:r(X=>{const le=X.detail.originalEvent.target;le&&_.current?.contains(le)&&X.preventDefault()},"onInteractOutside"),children:I?.mode==="store"?(0,t.jsx)(cHe,{initialName:I.name,initialValue:I.value,existingSecretNames:n.map(X=>X.name),onCancel:r(()=>C(null),"onCancel"),onSubmit:K}):I?.mode==="create"?(0,t.jsx)(Rfe,{initialName:I.name,initialValue:I.value,existingSecretNames:n.map(X=>X.name),onCancel:r(()=>C(null),"onCancel"),onSubmit:K}):null})]}),L?(0,t.jsx)("p",{id:H,role:"status",className:U("mt-0.5 text-(length:--text-micro)",L.level==="error"?"text-destructive":"text-amber-600 dark:text-amber-400"),children:L.message}):null,E?(0,t.jsxs)("p",{className:"mt-0.5 inline-flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:["Reverted to text —"," ",(0,t.jsx)("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2 hover:text-primary",onClick:r(()=>{u({source:"secret",secretId:E.secretId,version:E.version,textValue:""}),O(null)},"onClick"),children:"Undo"})]}):null]}),c&&l?(0,t.jsx)("p",{id:V,className:U("col-span-2 col-start-1 row-start-3 min-w-0 text-(length:--text-micro) @[40rem]/env:col-span-2 @[40rem]/env:row-start-2",l.level==="error"?"text-destructive":"text-amber-600 dark:text-amber-400"),children:l.message}):null,(0,t.jsxs)("div",{className:"col-start-2 row-start-1 flex items-center justify-end gap-0.5 self-start @[40rem]/env:col-start-3 @[40rem]/env:self-center",children:[e.source==="text"&&!q&&(e.name.trim()||e.textValue)?(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,disabled:o,children:(0,t.jsx)("button",{type:"button","aria-label":"More actions",className:"rounded p-1 text-muted-foreground opacity-100 hover:bg-accent hover:text-foreground @[40rem]/env:opacity-0 @[40rem]/env:group-hover/row:opacity-100 @[40rem]/env:group-focus-within/row:opacity-100",children:(0,t.jsx)(Pi,{className:"size-4"})})}),(0,t.jsx)(ga,{align:"end",children:(0,t.jsx)(ps,{onSelect:r(()=>{window.setTimeout(z,0)},"onSelect"),children:"Store as secret…"})})]}):null,(0,t.jsx)("button",{type:"button",onClick:h,disabled:o,"aria-label":`Remove ${e.name.trim()||"variable"}`,className:"rounded p-1 text-muted-foreground opacity-100 hover:bg-destructive/10 hover:text-destructive @[40rem]/env:opacity-0 @[40rem]/env:group-hover/row:opacity-100 @[40rem]/env:group-focus-within/row:opacity-100",children:(0,t.jsx)(nr,{className:"size-4"})})]})]})}r(NHe,"EnvironmentVariableRow");var kHe=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;function SHe(e){const s=e.indexOf(" #");return s>=0?e.slice(0,s):e}r(SHe,"stripInlineComment");function CHe(e){const s=e.trim();if(s.length>=2){const n=s[0],a=s[s.length-1];if(n==='"'&&a==='"'||n==="'"&&a==="'")return s.slice(1,-1)}return SHe(s).trim()}r(CHe,"unquote");function _He(e){const s=[];for(const n of e.split(/\r?\n/)){const a=n.trim();if(!a||a.startsWith("#"))continue;const i=kHe.exec(a);if(!i)continue;const o=i[1],l=CHe(i[2]);s.push({key:o,value:l})}return s}r(_He,"parseDotenv");var IHe=["PAPERCLIP_"],AHe="Set the KEY to the env var name the process expects, for example GH_TOKEN. Choose a secret to resolve a stored value at run start. PAPERCLIP_* variables are injected automatically.";function wF(e){if(!e||typeof e!="object")return[];const s=new Map;for(const[n,a]of Object.entries(e)){const i=n.trim();if(i)if(typeof a=="string")s.set(i,{type:"plain",value:a});else if(a?.type==="secret_ref"){const o=typeof a.secretId=="string"?a.secretId:"";if(!o)continue;s.set(i,{type:"secret_ref",secretId:o,version:typeof a.version=="number"?a.version:"latest"})}else if(a?.type==="user_secret_ref"){const o=typeof a.key=="string"?a.key.trim():"";if(!o)continue;s.set(i,{type:"user_secret_ref",key:o,version:typeof a.version=="number"?a.version:"latest",required:a.required!==!1})}else a?.type==="plain"?s.set(i,{type:"plain",value:typeof a.value=="string"?a.value:""}):s.set(i,{type:"plain",value:""})}return[...s.entries()].sort(([n],[a])=>n.localeCompare(a))}r(wF,"normalizedEnvEntries");function VN(e){return JSON.stringify(wF(e))}r(VN,"normalizedEnvKey");var S4=3;function C4(e){const s=e.slice(0,S4).join(", ");return e.length>S4?`${s} +${e.length-S4} more`:s}r(C4,"formatChangedNames");function EY(e){return e.map(s=>({...s}))}r(EY,"cloneRows");function RHe(e,s){return s?{name:e.name.trim()!==s.name.trim(),value:e.source!==s.source||e.textValue!==s.textValue||e.secretId!==s.secretId||e.userSecretKey!==s.userSecretKey||e.required!==s.required||e.version!==s.version}:{name:!!e.name.trim(),value:e.source!=="text"||!!e.textValue||!!e.secretId||e.version!=="latest"}}r(RHe,"rowDirtyFields");var Zb=(0,m.forwardRef)(r(function({value:s,onChange:n,secrets:a,userSecretDefinitions:i,onCreateSecret:o,recentlyUsedSecrets:l,disabled:c,reservedPrefixes:d=IHe,footerHint:u,onDirtyChange:h,hideDraftActions:p=!1},x){const g=Nc(),v=(0,m.useRef)(null),[y,j]=(0,m.useState)(()=>k4(s)),S=(0,m.useRef)(y),[w,N]=(0,m.useState)(()=>EY(y)),_=(0,m.useMemo)(()=>VN(s),[]),I=(0,m.useRef)(_),C=(0,m.useRef)(_),A=(0,m.useRef)(null),[R,E]=(0,m.useState)(_),[O,L]=(0,m.useState)(()=>new Set(k4(s).map(de=>de.name.trim()).filter(Boolean))),[$,T]=(0,m.useState)(null);(0,m.useEffect)(()=>{S.current=y},[y]);function q(de,ve=S.current){I.current=de,E(de),N(EY(ve))}r(q,"markCommitted");function B(de){L(ve=>{const Te=new Set(ve);for(const fe of de){const Ce=fe.name.trim();Ce&&Te.add(Ce)}return Te})}r(B,"touchCommittedNames");function K(de){const ve=k4(de);return j(ve),B(ve),ve}r(K,"adoptExternalValue"),(0,m.useEffect)(()=>{const de=VN(s);if(de===C.current)return;C.current=de;const ve=VN(N2(S.current)),Te=ve!==I.current,fe=A.current===de;if(fe&&(A.current=null),!Te){q(de,K(s));return}(fe||ve===de)&&(B(S.current),q(de))},[s]);const z=(0,m.useMemo)(()=>N2(y),[y]),D=(0,m.useMemo)(()=>VN(z),[z]),V=D!==R;(0,m.useEffect)(()=>{h?.(!c&&V)},[c,V,h]);const H=(0,m.useMemo)(()=>{const de=new Map(wF(N2(w)).map(([Ce,Xe])=>[Ce,JSON.stringify(Xe)])),ve=new Map(wF(z).map(([Ce,Xe])=>[Ce,JSON.stringify(Xe)])),Te=[],fe=[];for(const[Ce,Xe]of ve)de.has(Ce)?de.get(Ce)!==Xe&&fe.push(Ce):Te.push(Ce);return{added:Te,changed:fe,removed:[...de.keys()].filter(Ce=>!ve.has(Ce))}},[w,z]),Z=(0,m.useMemo)(()=>{const de=[];return H.added.length>0&&de.push(`New: ${C4(H.added)}`),H.changed.length>0&&de.push(`Edited: ${C4(H.changed)}`),H.removed.length>0&&de.push(`Removed: ${C4(H.removed)}`),de.join(" · ")},[H]);(0,m.useEffect)(()=>{if(c||!V)return;function de(ve){ve.preventDefault(),ve.returnValue=""}return r(de,"handleBeforeUnload"),window.addEventListener("beforeunload",de),()=>window.removeEventListener("beforeunload",de)},[c,V]);const Y=(0,m.useCallback)(()=>c||!V?null:(A.current=D,(0,Up.flushSync)(()=>{n(z)}),z??{}),[c,z,D,V,n]);(0,m.useImperativeHandle)(x,()=>({flushPendingDraft:Y}),[Y]),(0,m.useEffect)(()=>{const de=v.current?.closest("form");if(!de)return;function ve(){Y()}return r(ve,"handleSubmit"),de.addEventListener("submit",ve,!0),()=>de.removeEventListener("submit",ve,!0)},[Y]),(0,m.useEffect)(()=>{const de=v.current;if(!de)return;const ve=de;function Te(fe){const Ce=fe.target;if(!(Ce instanceof Element)||ve.contains(Ce))return;const Xe=Ce.closest("button");if(!Xe||Xe.disabled)return;const Oe=`${Xe.getAttribute("aria-label")??""} ${Xe.textContent??""}`;(Xe.type==="submit"||/\b(save|create|update|test|import)\b/i.test(Oe))&&Y()}return r(Te,"handleDocumentClick"),document.addEventListener("click",Te,!0),()=>document.removeEventListener("click",Te,!0)},[Y]);function ie(de){j(de)}r(ie,"updateDraft");function se(de,ve){ie(y.map(Te=>Te.id===de?{...Te,...ve}:Te))}r(se,"patchRow");function X(de){ie(y.filter(ve=>ve.id!==de))}r(X,"removeRow");function le(){const de=ex();j([...y,de]),T({rowId:de.id,field:"name"})}r(le,"addRow");function oe(de){const ve=y.find(Te=>Te.id===de)?.name.trim();ve&&L(Te=>{if(Te.has(ve))return Te;const fe=new Set(Te);return fe.add(ve),fe})}r(oe,"markTouched");function te(de,ve){const Te=_He(de);if(Te.length===0)return!1;const fe=y.filter(Ce=>Ce.id!==ve).map(Ce=>({...Ce}));for(const{key:Ce,value:Xe}of Te){const Oe=fe.find(tt=>tt.name.trim()===Ce);Oe?(Oe.name=Ce,Oe.source="text",Oe.textValue=Xe,Oe.secretId="",Oe.sensitiveDismissed=!1,Oe.userSecretKey="",Oe.required=!0):fe.push({...ex(),name:Ce,textValue:Xe})}return ie(fe),g?.pushToast({title:`Imported ${Te.length} variable${Te.length===1?"":"s"}`,tone:"success"}),!0}r(te,"bulkImport");function J(de){const ve=y.map(Ce=>({...Ce})),Te=ve[ve.length-1];let fe;Te&&!Te.name&&!Te.textValue&&!Te.secretId&&!Te.userSecretKey?fe=Te:(fe=ex(),ve.push(fe)),fe.source="secret",fe.secretId=de.id,fe.version="latest",fe.name||(fe.name=pS(de.name)),ie(ve)}r(J,"bindRecentSecret");function Q(){V&&(A.current=D,n(z))}r(Q,"saveDraft");function pe(){A.current=null,C.current=VN(s);const de=K(s);q(C.current,de)}r(pe,"revertDraft");const re=(0,m.useMemo)(()=>yHe(y),[y]),ne=(0,m.useMemo)(()=>y.reduce((de,ve)=>Tfe(ve,a)||Efe(ve,i)?de+1:de,0),[y,a,i]),ae=(0,m.useMemo)(()=>{const de=new Set(y.filter(ve=>ve.source==="secret"&&ve.secretId).map(ve=>ve.secretId));return(l??[]).filter(ve=>ve.status==="active"&&!de.has(ve.id)).slice(0,8)},[l,y]),me=y.length>0,he=u===void 0?AHe:u,Ie=(0,m.useMemo)(()=>new Map(w.map(de=>[de.id,de])),[w]);return(0,t.jsx)(dd,{children:(0,t.jsxs)("div",{ref:v,className:"@container/env space-y-2",children:[ne>1?(0,t.jsxs)("p",{className:"inline-flex items-center gap-1.5 text-(length:--text-micro) font-medium text-amber-700 dark:text-amber-400",children:[(0,t.jsx)(Vi,{className:"size-3.5"}),ne," bindings need attention"]}):null,me?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"hidden gap-x-1.5 @[40rem]/env:grid @[40rem]/env:grid-cols-(--gtc-14)",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Name"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Value"}),(0,t.jsx)("span",{})]}),y.map((de,ve)=>{const Te=vHe(de.name,re,d),fe=O.has(de.name.trim());return(0,t.jsx)(NHe,{row:de,isLast:ve===y.length-1,secrets:a,userSecretDefinitions:i,recentlyUsedSecrets:l,disabled:c,nameIssue:Te,showNameIssue:fe,dirtyFields:RHe(de,Ie.get(de.id)),onPatch:r(Ce=>se(de.id,Ce),"onPatch"),onRemove:r(()=>X(de.id),"onRemove"),onNameBlur:r(()=>oe(de.id),"onNameBlur"),onNamePaste:r(Ce=>te(Ce,de.id),"onNamePaste"),onEnterInValueLast:le,onCreateSecret:o,onToast:r(Ce=>g?.pushToast({title:Ce,tone:"success"}),"onToast"),focusRequest:$?.rowId===de.id?$.field:null,onFocusConsumed:r(()=>T(null),"onFocusConsumed")},de.id)})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No environment variables"}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-1",children:[(0,t.jsxs)("button",{type:"button",onClick:le,disabled:c,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[(0,t.jsx)(xn,{className:"size-3.5"}),"Add variable"]}),ae.length>0&&!c?(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-(length:--text-micro) text-muted-foreground/70",children:[(0,t.jsx)(ji,{className:"size-3"}),"Recently used:"]}),ae.map(de=>(0,t.jsxs)("button",{type:"button",onClick:r(()=>J(de),"onClick"),className:"inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 font-mono text-(length:--text-micro) text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",title:`Bind ${de.name}`,children:["+ ",de.name]},de.id))]}):null]}),V&&!c&&!p?(0,t.jsxs)("div",{role:"status",className:"mt-3 flex w-full flex-col gap-3 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-3 text-amber-950 shadow-sm dark:bg-amber-500/15 dark:text-amber-100 @[34rem]/env:flex-row @[34rem]/env:items-center @[34rem]/env:justify-between",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium",children:[(0,t.jsx)("span",{className:"size-2 rounded-full bg-amber-500 shadow-(--shadow-extract-13)"}),(0,t.jsx)("span",{children:"Unsaved changes"})]}),Z?(0,t.jsx)("p",{className:"min-w-0 truncate pl-4 text-xs text-amber-950/80 dark:text-amber-100/80",title:Z,children:Z}):null]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("button",{type:"button",onClick:pe,className:"inline-flex h-9 items-center gap-1.5 rounded-md border border-amber-500/30 bg-background px-3 text-sm font-medium text-foreground transition-colors hover:bg-amber-500/10 dark:bg-background/80",children:[(0,t.jsx)(Ii,{className:"size-4"}),"Revert"]}),(0,t.jsxs)("button",{type:"button",onClick:Q,className:"inline-flex h-9 items-center gap-1.5 rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90",children:[(0,t.jsx)(Bp,{className:"size-4"}),"Save"]})]})]}):null,he?(0,t.jsx)("p",{className:"text-(length:--text-micro) text-muted-foreground/70",children:he}):null,y.some(de=>de.source==="user_secret"&&de.userSecretKey)?(0,t.jsxs)("p",{className:"inline-flex items-start gap-1 text-(length:--text-micro) text-muted-foreground/70",children:[(0,t.jsx)(pu,{className:"mt-0.5 size-3 shrink-0"}),(0,t.jsx)("span",{children:"User secrets resolve from the user responsible for the run. Required bindings fail until that user sets their value under Secrets → My secrets."})]}):null]})})},"EnvironmentVariablesEditor")),THe="env.",A1="access.",NF=/^[A-Za-z_][A-Za-z0-9_]*$/;function Pfe(e){return e?e.startsWith("access.")?"api":e.startsWith("env.")?"env":"config":"config"}r(Pfe,"deliveryModeForConfigPath");function Mfe(e){switch(e){case"env":return"Env var";case"api":return"API access";default:return"Config"}}r(Mfe,"deliveryModeLabel");function EHe(e){switch(e){case"env":return"Injected as an environment variable at run start.";case"api":return"Fetched on demand via the run-bound agent API. Never written to the environment.";default:return"Provided through adapter configuration."}}r(EHe,"deliveryModeDescription");function Dfe(e){return e?e.startsWith("access.")?e.slice(7):e.startsWith("env.")?e.slice(4):e:""}r(Dfe,"aliasFromConfigPath");function PHe(e){switch(e){case"agent_api":return"Agent API";case"plugin_worker":return"Plugin worker";case"tool_connection":return"Tool connection";default:return e.charAt(0).toUpperCase()+e.slice(1)}}r(PHe,"consumerTypeLabel");var MHe={numeric:!0,sensitivity:"base"};function Rk(e){return e.kind==="company"?e.secret.name:e.definition.name}r(Rk,"getSecretPathRowName");function dw(e){return e.split("/").filter(s=>s.length>0)}r(dw,"splitSecretPath");function _4(e){return dw(e).join("/")}r(_4,"normalizeSecretPath");function PY(e,s){return s.every((n,a)=>e[a]===n)}r(PY,"startsWithSegments");function MY(e,s){return e.localeCompare(s,void 0,MHe)}r(MY,"compareNames");function DHe(e,s){const n=dw(s),a=e.map(c=>({row:c,name:Rk(c),segments:dw(Rk(c))})),i=new Set,o=[];for(const c of a){if(!PY(c.segments,n))continue;const d=c.segments.length-n.length;(d===0||d===1)&&o.push(c.row),d>=2&&i.add(c.segments[n.length])}const l=[...i].map(c=>{const d=[...n,c],u=new Set;let h=0;for(const p of a){if(!PY(p.segments,d))continue;const x=p.segments.length-d.length;if(!(x<1)){h+=1;for(let g=1;g<x;g+=1)u.add(p.segments.slice(d.length,d.length+g).join("/"))}}return{name:c,path:d.join("/"),secretCount:h,folderCount:u.size}});return l.sort((c,d)=>MY(c.name,d.name)),o.sort((c,d)=>MY(Rk(c),Rk(d))),{folders:l,secrets:o}}r(DHe,"buildSecretPathListing");function LHe(e){const s=dw(e);return s.map((n,a)=>({name:n,path:s.slice(0,a+1).join("/")}))}r(LHe,"buildSecretPathBreadcrumbs");function $He(e){return e.trim()?e.includes("/")?"Folder name cannot contain slashes.":null:"Folder name is required."}r($He,"validateSecretFolderSegment");function aC({name:e,basePath:s="",className:n,leafClassName:a}){const i=dw(e),o=dw(s),l=o.length>0&&o.every((h,p)=>i[p]===h)&&i.length>o.length?i.slice(o.length):i,c=l.length>0?l:[e],d=c[c.length-1],u=c.slice(0,-1).join("/");return(0,t.jsxs)("span",{className:U("min-w-0 truncate",n),children:[u?(0,t.jsxs)("span",{className:"text-muted-foreground",children:[u,"/"]}):null,(0,t.jsx)("span",{className:U("font-medium text-foreground",a),children:d})]})}r(aC,"SecretPathName");function OHe(e,s){const n=e?`sha256:${e.slice(0,10)}…`:"no fingerprint",a=typeof s=="number"?`${s} ${s===1?"byte":"bytes"}`:null;return a?`${n} · ${a}`:n}r(OHe,"fingerprintLabel");function Lfe({fingerprint:e,length:s,className:n}){const{pushToast:a}=ua(),i=OHe(e,s);if(!e)return(0,t.jsxs)("span",{className:U("inline-flex items-center gap-1 font-mono",n),children:[(0,t.jsx)(JW,{className:"size-3 shrink-0"}),i]});const o=`sha256:${e}`;return(0,t.jsxs)("button",{type:"button",onClick:r(()=>{Gr(o).then(()=>a({title:"Fingerprint copied",tone:"success"})).catch(()=>a({title:"Couldn’t copy fingerprint",tone:"error"}))},"onClick"),title:`Copy full digest — ${o}`,className:U("inline-flex items-center gap-1 font-mono hover:text-foreground",n),children:[(0,t.jsx)(JW,{className:"size-3 shrink-0"}),i,(0,t.jsx)(jr,{className:"size-3 shrink-0 opacity-60"})]})}r(Lfe,"FingerprintChip");function GU({justification:e,className:s}){return(0,t.jsxs)("div",{className:U("space-y-0.5",s),children:[(0,t.jsx)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:"Reason given by the agent"}),(0,t.jsxs)("p",{className:"whitespace-pre-wrap break-words text-xs text-foreground/80",children:["“",e,"”"]})]})}r(GU,"ProposalJustification");function iC({agent:e,className:s}){return(0,t.jsxs)("span",{className:U("inline-flex min-w-0 items-center gap-1",s),children:[(0,t.jsx)(hr,{agent:e,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:e.name})]})}r(iC,"AgentRefChip");function YU({configPath:e}){const s=Pfe(e),n=s==="env",a=s==="api";return(0,t.jsxs)(dt,{variant:"outline",className:U("h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal",n&&"border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",a&&"border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",!n&&!a&&"border-border bg-muted/40 text-muted-foreground"),children:[n?(0,t.jsx)(Cde,{className:"size-3"}):a?(0,t.jsx)(f5,{className:"size-3"}):null,Mfe(s)]})}r(YU,"DeliveryBadge$1");function JU({className:e}){return(0,t.jsxs)(dt,{variant:"outline",className:U("h-5 gap-1 px-1.5 text-(length:--text-nano) font-medium","border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300",e),children:[(0,t.jsx)(wl,{className:"size-3"})," Proposed"]})}r(JU,"ProposedBadge");function G5(e){return Dfe(e.configPath)}r(G5,"bindingEnvKey");function XU(e){return e.secretProposalId?{name:e.secretProposalName??"proposed secret",pending:!0}:{name:e.secretName??"secret",pending:!1}}r(XU,"bindingSecretLabel");function DY(e){return e instanceof Nn?e.message||`Request failed: ${e.status}`:e instanceof Error?e.message:"Something went wrong. Try again."}r(DY,"readableError");function $fe(e,s=[]){const n=Ht(),{pushToast:a}=ua(),[i,o]=(0,m.useState)(null),[l,c]=(0,m.useState)(null),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(null),x=(0,m.useCallback)(()=>{e&&(n.invalidateQueries({queryKey:["secret-proposals",e]}),n.invalidateQueries({queryKey:P.secrets.list(e)}))},[e,n]),g=ye({mutationFn:r(w=>{const{proposal:N}=w;if(N.kind==="secret"){const _=w.folder.trim()?`${w.folder.trim().replace(/\/+$/,"")}/${w.leaf.trim()}`:w.leaf.trim();return mr.approveProposal(e,N.id,{overrides:{name:_,description:w.description.trim()||null,providerConfigId:w.providerConfigId||null}})}return mr.approveProposal(e,N.id,{cascade:w.cascade||void 0})},"mutationFn"),onSuccess:r(w=>{a({title:w.kind==="secret"?"Secret approved":"Binding approved",body:w.kind==="secret"?w.proposedName??"Secret created":`${w.target?.name??"Agent"} · ${G5(w)||"binding"}`,tone:"success"}),o(null),p(null),x()},"onSuccess"),onError:r(w=>p(DY(w)),"onError")}),v=ye({mutationFn:r(({proposal:w,reason:N})=>mr.rejectProposal(e,w.id,{reason:N.trim()}),"mutationFn"),onSuccess:r(w=>{a({title:"Proposal rejected",body:w.kind==="secret"?w.proposedName??void 0:void 0,tone:"info"}),c(null),u(""),p(null),x()},"onSuccess"),onError:r(w=>p(DY(w)),"onError")}),y=(0,m.useCallback)(w=>{p(null);const N=(w.proposedName??"").split("/"),_=N.pop()??"";o({proposal:w,folder:N.join("/"),leaf:_,description:w.proposedDescription??"",providerConfigId:s.find(I=>I.provider==="local_encrypted"&&I.isDefault)?.id??"",cascade:!!w.secretProposalId})},[s]),j=(0,m.useCallback)(w=>{p(null),u(""),c(w)},[]),S=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(FHe,{draft:i,error:h,pending:g.isPending,providerConfigs:s,onChange:o,onCancel:r(()=>{o(null),p(null)},"onCancel"),onConfirm:r(()=>i&&g.mutate(i),"onConfirm")}),(0,t.jsx)(qHe,{proposal:l,reason:d,error:h,pending:v.isPending,onReasonChange:u,onCancel:r(()=>{c(null),u(""),p(null)},"onCancel"),onConfirm:r(()=>l&&v.mutate({proposal:l,reason:d}),"onConfirm")})]});return{requestApprove:y,requestReject:j,isBusy:g.isPending||v.isPending,dialogs:S}}r($fe,"useProposalReview");function FHe({draft:e,error:s,pending:n,providerConfigs:a,onChange:i,onCancel:o,onConfirm:l}){const c=e?.proposal.kind==="secret",d=e?e.folder.trim()?`${e.folder.trim().replace(/\/+$/,"")}/${e.leaf.trim()}`:e.leaf.trim():"",u=a.filter(p=>p.provider==="local_encrypted"),h=c?!!(e&&e.leaf.trim()):!0;return(0,t.jsx)(Xs,{open:!!e,onOpenChange:r(p=>!p&&o(),"onOpenChange"),children:(0,t.jsx)(Zs,{className:"sm:max-w-lg",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:c?"Approve & create secret":"Approve binding"}),(0,t.jsx)(Dn,{children:c?"The value is created as the proposing agent recorded it. Re-folder or rename it before it lands.":"Grant the target agent access to this secret. This runs with your permissions."})]}),(0,t.jsxs)("div",{className:"space-y-1.5 rounded-md border border-border bg-muted/30 p-2.5 text-xs",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[(0,t.jsx)("span",{children:"Proposed by"}),(0,t.jsx)(iC,{agent:e.proposal.proposedBy,className:"font-medium text-foreground"})]}),(0,t.jsx)(GU,{justification:e.proposal.justification})]}),c?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-folder",children:"Folder"}),(0,t.jsx)(Rt,{id:"approve-folder",value:e.folder,onChange:r(p=>i({...e,folder:p.target.value}),"onChange"),placeholder:"dev/github",className:"font-mono text-xs"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-name",children:"Name"}),(0,t.jsx)(Rt,{id:"approve-name",value:e.leaf,onChange:r(p=>i({...e,leaf:p.target.value}),"onChange"),placeholder:"client-secret",autoFocus:!0,"aria-invalid":!e.leaf.trim(),className:"font-mono text-xs"})]})]}),(0,t.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:["Lands as"," ",d?(0,t.jsx)(aC,{name:d,className:"font-mono"}):(0,t.jsx)("span",{className:"italic",children:"enter a name"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-description",children:"Description"}),(0,t.jsx)(Rt,{id:"approve-description",value:e.description,onChange:r(p=>i({...e,description:p.target.value}),"onChange"),placeholder:"Optional"})]}),u.length>0?(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-provider-config",children:"Provider vault"}),(0,t.jsxs)("select",{id:"approve-provider-config",value:e.providerConfigId,onChange:r(p=>i({...e,providerConfigId:p.target.value}),"onChange"),className:"h-9 w-full rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50",children:[(0,t.jsx)("option",{value:"",children:"Deployment default"}),u.map(p=>(0,t.jsx)("option",{value:p.id,children:p.displayName},p.id))]})]}):null,(0,t.jsx)("div",{className:"rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-muted-foreground",children:(0,t.jsx)(Lfe,{fingerprint:e.proposal.valueFingerprintSha256,length:e.proposal.valueLength})})]}):(0,t.jsx)(BHe,{draft:e,onChange:i}),s?(0,t.jsx)("p",{className:"text-xs text-destructive",role:"alert",children:s}):null,(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"ghost",onClick:o,disabled:n,children:"Cancel"}),(0,t.jsx)(F,{onClick:l,disabled:n||!h,children:n?"Approving…":c?"Approve & create":e.cascade?"Approve secret & bind":"Approve binding"})]})]}):null})})}r(FHe,"ApproveDialog");function BHe({draft:e,onChange:s}){const{proposal:n}=e,a=XU(n),i=G5(n);return(0,t.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,t.jsxs)("div",{className:"space-y-2 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Target agent"}),n.target?(0,t.jsx)(iC,{agent:n.target,className:"text-sm font-medium"}):(0,t.jsx)("span",{className:"text-muted-foreground",children:"—"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Delivered as"}),(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(YU,{configPath:n.configPath}),(0,t.jsx)("code",{className:"font-mono text-xs",children:i||n.configPath})]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Secret"}),(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(ji,{className:"size-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:a.name}),a.pending?(0,t.jsx)(JU,{}):null]})]})]}),n.secretProposalId?(0,t.jsxs)("label",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5 text-xs",children:[(0,t.jsx)(Ki,{checked:e.cascade,onCheckedChange:r(o=>s({...e,cascade:o===!0}),"onCheckedChange"),className:"mt-0.5","aria-label":"Also approve the proposed secret"}),(0,t.jsxs)("span",{className:"text-foreground/90",children:["Also approve the proposed secret"," ",(0,t.jsx)("span",{className:"font-medium",children:a.name})," and create it in the same step. The binding can’t land without it."]})]}):null]})}r(BHe,"BindingApproveBody");function qHe({proposal:e,reason:s,error:n,pending:a,onReasonChange:i,onCancel:o,onConfirm:l}){const c=s.trim().length>0;return(0,t.jsx)(Xs,{open:!!e,onOpenChange:r(d=>!d&&o(),"onOpenChange"),children:(0,t.jsx)(Zs,{className:"sm:max-w-md",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Reject proposal"}),(0,t.jsxs)(Dn,{children:["The reason is sent back to"," ",(0,t.jsx)(iC,{agent:e.proposedBy,className:"text-foreground"}),". Dependent bindings are rejected too."]})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"reject-reason",children:"Reason"}),(0,t.jsx)(An,{id:"reject-reason",value:s,onChange:r(d=>i(d.target.value),"onChange"),rows:3,autoFocus:!0,placeholder:"Why is this being rejected?"})]}),n?(0,t.jsx)("p",{className:"text-xs text-destructive",role:"alert",children:n}):null,(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"ghost",onClick:o,disabled:a,children:"Cancel"}),(0,t.jsx)(F,{variant:"destructive",onClick:l,disabled:a||!c,children:a?"Rejecting…":"Reject"})]})]}):null})})}r(qHe,"RejectDialog");function Ofe({proposal:e,onApprove:s,onReject:n,disabled:a,size:i="sm"}){const o=!e.viewerCanApprove,l=i==="xs"?"h-7 px-2 text-xs":"",c=(0,t.jsx)(F,{size:"sm",className:l,disabled:a||o,onClick:r(()=>s(e),"onClick"),children:"Approve"});return(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[o?(0,t.jsx)(dd,{children:(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("span",{tabIndex:0,children:c})}),(0,t.jsx)(Kn,{className:"max-w-72",children:e.approveBlockReason??"You don’t have permission to approve this."})]})}):c,(0,t.jsx)(F,{size:"sm",variant:"outline",className:l,disabled:a,onClick:r(()=>n(e),"onClick"),children:"Reject"})]})}r(Ofe,"ProposalActions");function Ffe(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}r(Ffe,"asRecord$15");function Bfe(e){const s=Ffe(e);if(!s||s.type!=="secret_ref")return null;const n=typeof s.secretId=="string"?s.secretId:"";return n?{secretId:n,version:typeof s.version=="number"?s.version:"latest"}:null}r(Bfe,"readSecretRef");function zHe(e){const s=Ffe(e?.env);if(!s)return[];const n=[];for(const[a,i]of Object.entries(s)){const o=Bfe(i);o&&n.push({name:a,...o})}return n}r(zHe,"parseEnvSecretRefs");function UHe(e){if(!e)return[];const s=[];for(const[n,a]of Object.entries(e)){if(!n.startsWith("access."))continue;const i=Bfe(a);i&&s.push({name:n.slice(A1.length),...i})}return s}r(UHe,"parseAccessGrants");function KHe(e,s){const n=new Map,a=r(i=>{let o=n.get(i);return o||(o={secretId:i,envKeys:[],apiAliases:[]},n.set(i,o)),o},"ensure");for(const i of e)a(i.secretId).envKeys.push(i.name);for(const i of s)a(i.secretId).apiAliases.push(i.name);return[...n.values()]}r(KHe,"summarizeAgentBindings");var LY=0;function qfe(){return LY+=1,`access-row-${LY}`}r(qfe,"nextAccessRowId");function I4(e){return e.map(s=>({id:qfe(),alias:s.name,secretId:s.secretId,version:s.version}))}r(I4,"entriesToRows");function $Y(e){const s={};for(const n of e){const a=n.alias.trim();!a||!NF.test(a)||!n.secretId||(s[a]={type:"secret_ref",secretId:n.secretId,version:n.version})}return s}r($Y,"rowsToAccessMap");function OY(e){return JSON.stringify(Object.keys(e).sort().map(s=>{const n=e[s];return[s,n.secretId,n.version??"latest"]}))}r(OY,"normalizeAccessMapKey");function FY({mode:e}){return e==="env"?(0,t.jsxs)(dt,{variant:"outline",className:"h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:[(0,t.jsx)(Cde,{className:"size-3"})," Env var"]}):(0,t.jsxs)(dt,{variant:"outline",className:"h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",children:[(0,t.jsx)(f5,{className:"size-3"})," API access"]})}r(FY,"DeliveryBadge");function VHe({config:e,secrets:s,onChange:n,onCreateSecret:a,disabled:i,proposals:o,onApproveProposal:l,onRejectProposal:c}){const d=(0,m.useMemo)(()=>(o??[]).filter($=>$.kind==="binding"),[o]),u=(0,m.useMemo)(()=>zHe(e),[e]),h=(0,m.useMemo)(()=>UHe(e),[e]),p=(0,m.useMemo)(()=>KHe(u,h),[u,h]),x=(0,m.useMemo)(()=>$Y(I4(h)),[h]),g=(0,m.useMemo)(()=>OY(x),[x]),[v,y]=(0,m.useState)(()=>I4(h)),[j,S]=(0,m.useState)(null),w=(0,m.useRef)(new Map),N=(0,m.useRef)(g),_=(0,m.useRef)(g);(0,m.useEffect)(()=>{g!==_.current&&(_.current=g,g!==N.current&&y(I4(h)))},[g,h]);const I=r($=>s.find(T=>T.id===$)?.name??`${$.slice(0,8)}…`,"secretName");function C($){y($);const T=$Y($);N.current=OY(T),n(T)}r(C,"emit");function A($,T){C(v.map(q=>q.id===$?{...q,...T}:q))}r(A,"patchRow");function R($){C(v.filter(T=>T.id!==$))}r(R,"removeRow");function E(){y($=>[...$,{id:qfe(),alias:"",secretId:"",version:"latest"}])}r(E,"addRow");const O=(0,m.useMemo)(()=>{const $=new Map;for(const T of v){const q=T.alias.trim();q&&$.set(q,($.get(q)??0)+1)}return $},[v]),L=p.length>0;return(0,t.jsxs)("div",{className:"space-y-3",children:[L?(0,t.jsx)("div",{className:"space-y-1.5",children:p.map($=>(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded-md border border-border bg-muted/30 px-2.5 py-1.5 text-xs",children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:I($.secretId)}),$.envKeys.length>0?(0,t.jsx)(FY,{mode:"env"}):null,$.apiAliases.length>0?(0,t.jsx)(FY,{mode:"api"}):null,(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-(length:--text-micro) text-muted-foreground",children:[...$.envKeys.map(T=>`${THe}${T}`),...$.apiAliases.map(T=>`${A1}${T}`)].join(" · ")})]},$.secretId))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No secrets are bound to this agent yet."}),d.length>0&&l&&c?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Proposed access"}),d.map($=>{const T=XU($),q=G5($);return(0,t.jsxs)("div",{className:"flex flex-col gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 px-2.5 py-2 text-xs sm:flex-row sm:items-center",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[(0,t.jsx)(YU,{configPath:$.configPath}),(0,t.jsx)("code",{className:"font-mono",children:q||$.configPath}),(0,t.jsx)("span",{className:"text-muted-foreground",children:"→"}),(0,t.jsx)(ji,{className:"size-3 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:T.name}),T.pending?(0,t.jsx)(JU,{}):null]}),(0,t.jsxs)("p",{className:"flex flex-wrap items-center gap-1 text-muted-foreground",children:[(0,t.jsxs)("span",{children:["proposed by ",$.proposedBy.name]}),(0,t.jsx)("span",{"aria-hidden":"true",children:"·"}),(0,t.jsxs)("span",{className:"truncate italic",children:["“",$.justification,"”"]})]})]}),(0,t.jsx)(Ofe,{proposal:$,onApprove:l,onReject:c,disabled:i,size:"xs"})]},$.id)})]}):null,(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"API access (no env var)"}),v.length>0?(0,t.jsx)("div",{className:"space-y-2",children:v.map($=>{const T=$.alias.trim(),q=!!T&&!NF.test(T),B=!!T&&(O.get(T)??0)>1,K=s.find(z=>z.id===$.secretId)??null;return(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("div",{className:"grid grid-cols-(--gtc-65) items-start gap-1.5",children:[(0,t.jsx)("div",{children:(0,t.jsx)(Rt,{value:$.alias,onChange:r(z=>A($.id,{alias:z.target.value}),"onChange"),onBlur:r(z=>{const D=z.target.value.trim();if(D&&!NF.test(D)){const V=pS(D);V&&V!==D&&A($.id,{alias:V})}},"onBlur"),placeholder:"ALIAS","aria-label":"Access alias",disabled:i,className:U("h-9 font-mono text-sm",(q||B)&&"border-destructive text-destructive")})}),(0,t.jsxs)("div",{className:"flex min-w-0 items-start gap-1.5",children:[(0,t.jsxs)(sr,{open:j?.rowId===$.id,onOpenChange:r(z=>{!z&&j?.rowId===$.id&&S(null)},"onOpenChange"),children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsx)("div",{ref:r(z=>{z?w.current.set($.id,z):w.current.delete($.id)},"ref"),className:"min-w-0 flex-1",children:(0,t.jsx)(QU,{secretId:$.secretId,secrets:s,onSelect:r(z=>A($.id,{secretId:z,version:"latest",alias:!$.alias.trim()&&z?pS(I(z)):$.alias}),"onSelect"),onCreateNew:a?z=>{window.setTimeout(()=>{S({rowId:$.id,name:CT(z)||z.trim()})},0)}:void 0,disabled:i,triggerClassName:"h-9 min-h-9"})})}),(0,t.jsx)(Gn,{align:"start",className:"w-auto p-3",onInteractOutside:r(z=>{const D=z.detail.originalEvent.target;D&&w.current.get($.id)?.contains(D)&&z.preventDefault()},"onInteractOutside"),children:j?.rowId===$.id&&a?(0,t.jsx)(Rfe,{initialName:j.name,initialValue:"",existingSecretNames:s.map(z=>z.name),onCancel:r(()=>S(null),"onCancel"),onSubmit:r(async(z,D)=>{const V=await a(z,D);A($.id,{secretId:V.id,version:"latest",alias:$.alias.trim()||pS(V.name)}),S(null)},"onSubmit")}):null})]}),(0,t.jsxs)("select",{className:"h-9 shrink-0 rounded-md border border-border bg-background px-2 text-xs outline-none disabled:cursor-not-allowed disabled:opacity-60",value:$.version===void 0?"latest":String($.version),onChange:r(z=>{const D=z.target.value;A($.id,{version:D==="latest"?"latest":Number.parseInt(D,10)})},"onChange"),disabled:i||!K,"aria-label":"Version",children:[(0,t.jsx)("option",{value:"latest",children:"latest"}),K?Array.from({length:Math.max(0,K.latestVersion)},(z,D)=>{const V=K.latestVersion-D;return V<=0?null:(0,t.jsxs)("option",{value:V,children:["v",V]},V)}):null]})]}),(0,t.jsx)("button",{type:"button",onClick:r(()=>R($.id),"onClick"),disabled:i,"aria-label":"Remove API access",className:"mt-1 inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:(0,t.jsx)(Na,{className:"size-3.5"})})]}),q?(0,t.jsx)("p",{className:"pl-0.5 text-(length:--text-micro) text-destructive",children:"Invalid alias — use letters, digits and _"}):B?(0,t.jsx)("p",{className:"pl-0.5 text-(length:--text-micro) text-destructive",children:"Duplicate alias"}):null]},$.id)})}):null,(0,t.jsxs)("button",{type:"button",onClick:E,disabled:i,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[(0,t.jsx)(xn,{className:"size-3.5"}),"Add API access"]})]}),(0,t.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/70",children:[EHe("api")," The agent reads them by alias through ",(0,t.jsx)("code",{children:"GET /agents/me/secrets"}),"."]})]})}r(VHe,"AgentSecretAccessEditor");function WHe(e){if(typeof e!="string")return null;const s=e.trim();return s.length>0?s:null}r(WHe,"asNonEmptyString$3");function HHe(e){return WHe(e)!==null}r(HHe,"hasLegacyWorkingDirectory");function QHe(e){return e.isCreate?!1:HHe(e.adapterConfig?.cwd)}r(QHe,"shouldShowLegacyWorkingDirectoryField");var zfe=new Set;function GHe(e){return zfe.has(e)}r(GHe,"isAdapterTypeHidden");function YHe(e){zfe=new Set(e)}r(YHe,"setDisabledAdapterTypes");function JHe(e){return!Fm(e).hideFromVisualSelection}r(JHe,"isVisualAdapterChoice");function Ufe(e,s=HU()){const n=e??sf;return s.map(a=>({value:a.type,label:n(a.type),comingSoon:!!Fm(a.type).comingSoon,hidden:GHe(a.type),experimental:!!Fm(a.type).experimental}))}r(Ufe,"listAdapterOptions");function Kfe(e={}){const s=e.enabled??!0,{data:n}=ee({queryKey:P.adapters.all,queryFn:r(()=>Cm.list(),"queryFn"),enabled:s,staleTime:3e5});return n&&JWe(n.filter(a=>a.source==="external").map(a=>({type:a.type,label:a.label,disabled:a.disabled,overrideDisabled:a.overridePaused}))),(0,m.useEffect)(()=>{n&&YHe(n.filter(a=>a.disabled).map(a=>a.type))},[n]),(0,m.useMemo)(()=>new Set(n?.filter(a=>a.disabled).map(a=>a.type)??[]),[n])}r(Kfe,"useDisabledAdaptersSync");function XHe(e={}){const s=e.enabled??!0,{data:n}=ee({queryKey:P.adapters.all,queryFn:r(()=>Cm.list(),"queryFn"),enabled:s,staleTime:3e5});return n!==void 0}r(XHe,"useAdapterRegistryLoaded");function _T(e){return Object.fromEntries(Object.entries(e).filter(([,s])=>s!==void 0))}r(_T,"omitUndefinedEntries");function oI(e,s){const n={};if(Object.keys(s.identity).length>0&&Object.assign(n,s.identity),s.adapterType!==void 0&&(n.adapterType=s.adapterType),s.adapterType!==void 0||Object.keys(s.adapterConfig).length>0){const a=e.adapterConfig??{};n.adapterConfig=_T(s.adapterType!==void 0?{...Object.fromEntries(v_e.filter(i=>a[i]!==void 0).map(i=>[i,a[i]])),...s.adapterConfig}:{...a,...s.adapterConfig}),n.replaceAdapterConfig=!0}if(Object.keys(s.heartbeat).length>0||Object.keys(s.debug).length>0){const a=e.runtimeConfig??{},i=n.runtimeConfig??{...a};if(Object.keys(s.heartbeat).length>0&&(i.heartbeat={...a.heartbeat??{},...s.heartbeat}),Object.keys(s.debug).length>0){const o=_T({...a.debug??{},...s.debug});Object.keys(o).length===0?delete i.debug:i.debug=o}n.runtimeConfig=i}return Object.keys(s.runtime).length>0&&Object.assign(n,s.runtime),n}r(oI,"buildAgentUpdatePatch");var ZHe="kubernetes";function eQe(e){return e.driver!=="sandbox"?!1:e.config?.provider===ZHe}r(eQe,"isKubernetesSandboxEnvironment");function ZU(e,s){return e!=="kubernetes"?{forced:!1,kubernetesEnvironment:null}:{forced:!0,kubernetesEnvironment:s.find(n=>eQe(n))??null}}r(ZU,"resolveForcedKubernetesEnvironment");var A4={identity:{},adapterConfig:{},heartbeat:{},debug:{},runtime:{}},WN={};function tQe(e){return e==="claude_local"||e==="codex_local"||e==="paperclip_runner"||e==="opencode_local"}r(tQe,"supportsAdapterModelRefresh");function sQe(e,s){return Cme(e,s).model}r(sQe,"resolvePaperclipRunnerTransitionModel");function BY(e){return Object.keys(e.identity).length>0||e.adapterType!==void 0||Object.keys(e.adapterConfig).length>0||Object.keys(e.heartbeat).length>0||Object.keys(e.debug).length>0||Object.keys(e.runtime).length>0}r(BY,"isOverlayDirty");function kF(e,s){if(Object.is(e,s))return!0;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((n,a)=>kF(n,s[a]));if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof s=="object"&&s!==null&&!Array.isArray(s)){const n=Object.entries(e),a=s;return n.length===Object.keys(a).length&&n.every(([i,o])=>i in a&&kF(o,a[i]))}return!1}r(kF,"overlayValuesEqual");function nQe(e,s){const n=r((a,i)=>Object.fromEntries(Object.entries(a).filter(([o,l])=>!(o in i)||!kF(l,i[o]))),"subtractGroup");return{identity:n(e.identity,s.identity),...e.adapterType!==void 0&&e.adapterType!==s.adapterType?{adapterType:e.adapterType}:{},adapterConfig:n(e.adapterConfig,s.adapterConfig),heartbeat:n(e.heartbeat,s.heartbeat),debug:n(e.debug,s.debug),runtime:n(e.runtime,s.runtime)}}r(nQe,"subtractPersistedOverlay");var fm="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";function rQe(e){return e.split(",").map(s=>s.trim()).filter(Boolean)}r(rQe,"parseCommaArgs");function aQe(e){return Array.isArray(e)?e.filter(s=>typeof s=="string").join(", "):typeof e=="string"?e:""}r(aQe,"formatArgList");var iQe=[{id:"",label:"Auto"},{id:"minimal",label:"Minimal"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"X-High"},{id:"max",label:"Max"}],oQe=[{id:"",label:"Auto"},{id:"plan",label:"Plan"},{id:"ask",label:"Ask"}],lQe=[{id:"",label:"Auto"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"}],cQe=[{id:"",label:"Auto"},{id:"low",label:"Low"},{id:"high",label:"High"},{id:"max",label:"Max"}],dQe=2,qY=10,uQe=1,Vfe=300;function k2(e,s,n){return Math.max(s,Math.min(n,Math.floor(e)))}r(k2,"clampInteger");function mQe(e){return k2(e,0,Vfe)*1e3}r(mQe,"clampDelayMsFromSeconds");function hQe({order:e,className:s,children:n}){if(!e)return(0,t.jsx)("div",{className:s,children:n});const a=r(o=>{const l=(0,m.isValidElement)(o)?o.props["data-config-section"]:void 0,c=l?e.indexOf(l):-1;return c<0?e.length:c},"rank"),i=m.Children.toArray(n).sort((o,l)=>a(o)-a(l));return(0,t.jsx)("div",{className:s,children:i})}r(hQe,"ConfigSections");function Wfe(e){const{mode:s,adapterModels:n}=e,a=s==="create",i=e.sectionLayout==="cards",o=e.showAdapterTypeField??!0,l=e.showAdapterTestEnvironmentButton??!0,c=l&&!e.onTestActionChange&&!e.compactTestFeedback,d=!e.onTestFeedbackChange,u=e.showCreateRunPolicySection??!0,h=e.hideInstructionsFile??!1,p=e.canConfigureProviderTrace===!0,{selectedCompanyId:x}=fs(),g=Ht(),v=(0,m.useRef)(null),y=Kfe(),{data:j=[]}=ee({queryKey:x?P.secrets.list(x):["secrets","none"],queryFn:r(()=>mr.list(x),"queryFn"),enabled:!!x}),{data:S=[]}=ee({queryKey:x?P.secrets.userDefinitions(x):["user-secret-definitions","none"],queryFn:r(()=>mr.listUserSecretDefinitions(x),"queryFn"),enabled:!!x,retry:!1}),w=a?null:e.agent.id,{data:N=[]}=ee({queryKey:x?P.secrets.proposals(x,"pending"):["secret-proposals","none"],queryFn:r(()=>mr.listProposals(x,"pending"),"queryFn"),enabled:!!x&&!a,retry:!1}),_=(0,m.useMemo)(()=>N.filter(Je=>Je.kind==="binding"&&Je.target?.id===w),[N,w]),I=$fe(x,[]),{data:C}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),retry:!1}),A=(0,m.useMemo)(()=>{const Je=new Set(y);return C?.enableNativeRunner!==!0&&Je.add("paperclip_runner"),Je},[y,C?.enableNativeRunner]),R=C?.enableEnvironments===!0,E=C?.enableManagedSandboxOnly===!0,O=C===void 0||E,{data:L}=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn"),retry:!1}),{data:$}=ee({queryKey:P.instance.settings,queryFn:r(()=>Tr.get(),"queryFn"),retry:!1}),{data:T=[]}=ee({queryKey:x?P.environments.list(x):["environments","none"],queryFn:r(()=>_i.list(x),"queryFn"),enabled:!!x&&(R||L?.executionMode==="kubernetes")}),{forced:q,kubernetesEnvironment:B}=(0,m.useMemo)(()=>ZU(L?.executionMode,T),[L?.executionMode,T]),K=ye({mutationFn:r(Je=>{if(!x)throw new Error("Select an organization to create secrets");return mr.create(x,Je)},"mutationFn"),onSuccess:r(()=>{x&&g.invalidateQueries({queryKey:P.secrets.list(x)})},"onSuccess")}),z=ye({mutationFn:r(async({file:Je,namespace:qt})=>{if(!x)throw new Error("Select an organization to upload images");return c0.uploadImage(x,Je,qt)},"mutationFn")}),[D,V]=(0,m.useState)(A4),[H,Z]=(0,m.useState)(!1),[Y,ie]=(0,m.useState)(0),se=(0,m.useRef)(null),X=(0,m.useRef)(null),le=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!a){if(se.current!==null&&e.agent!==se.current&&!le.current){const Je=X.current;X.current=null,V(qt=>Je?nQe(qt,Je):{...A4})}se.current=e.agent}},[a,a?void 0:e.agent]);const oe=!a&&(BY(D)||H);function te(Je,qt,Hs){const Ks=D[Je];return qt in Ks?Ks[qt]:Hs}r(te,"eff");function J(Je,qt,Hs){V(Ks=>({...Ks,[Je]:{...Ks[Je],[qt]:Hs}}))}r(J,"mark");function Q(){return v.current?.flushPendingDraft()??null}r(Q,"flushEnvironmentDraft");const pe=(0,m.useCallback)(Je=>{a||V(qt=>{const Hs={...e.agent.adapterConfig??{},...qt.adapterConfig},Ks={...qt.adapterConfig};for(const[Ys,Ar]of Object.entries(Je))Ks[`${A1}${Ys}`]=Ar;for(const Ys of Object.keys(Hs))Ys.startsWith("access.")&&(Ys.slice(7)in Je||(Ks[Ys]=void 0));return{...qt,adapterConfig:Ks}})},[a,a?void 0:e.agent]),re=(0,m.useCallback)(()=>{V({...A4}),Z(!1),ie(Je=>Je+1)},[]),ne=(0,m.useCallback)(async()=>{if(a)return;const Je=Q(),qt=Je?{...D,adapterConfig:{...D.adapterConfig,env:Je}}:D;BY(qt)&&await e.onSave(oI(e.agent,qt))},[a,oe,D,e]);(0,m.useEffect)(()=>{a||(e.onDirtyChange?.(oe),e.onSaveActionChange?.(ne),e.onCancelActionChange?.(re))},[a,oe,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange,ne,re]),(0,m.useEffect)(()=>{if(!a)return()=>{e.onSaveActionChange?.(null),e.onCancelActionChange?.(null),e.onDirtyChange?.(!1)}},[a,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange]);const ae=a?{}:e.agent.adapterConfig??{},me=a?{}:e.agent.runtimeConfig??{},he=a?{}:me.heartbeat??{},Ie=a?{}:me.debug??{},de=a?e.values.adapterType:D.adapterType??e.agent.adapterType,ve=Bw(),Te=ve(de),fe=Te.supportsInstructionsBundle||Te.supportsSkills||Te.supportsLocalAgentJwt,Ce=fe&&!O&&QHe({isCreate:a,adapterConfig:ae}),Xe=(0,m.useMemo)(()=>Xw(de),[de]),Oe=(0,m.useMemo)(()=>new Set($Re(de)),[de]),tt=a?e.values:null,ce=a?Je=>e.onChange(Je):null;a&&tt.claudeStoredSessionId;const $e=r(()=>{x&&g.invalidateQueries({queryKey:P.secrets.userDefinitions(x)})},"invalidateUserSecretDefinitions"),mt=r(Je=>{if(!a||!ce)return;const qt=tt.envBindings??{};ce({envBindings:{...qt,...sj()},claudeStoredSessionId:Je}),$e()},"handleClaudeLoginStored"),it=r(async()=>{if(a)return;const Je={...Q()??te("adapterConfig","env",ae.env??WN),...sj()},qt={...D,adapterConfig:{...D.adapterConfig,env:Je}};V(qt),await e.onSave({...oI(e.agent,qt),applyStoredClaudeLogin:!0}),$e()},"handleClaudeLoginStoredEdit"),Ke=r(async Je=>{if(a||!Je.companyIdentityDiffers)return;const qt={...Q()??te("adapterConfig","env",ae.env??WN),CODEX_HOME:{type:"secret_ref",secretId:Je.secretId,version:"latest"}},Hs={...D,adapterConfig:{...D.adapterConfig,env:qt}};V(Hs),X.current=Hs,le.current=!0;try{await e.onSave(oI(e.agent,Hs))}catch(Ks){throw X.current=null,Ks}finally{le.current=!1}$e()},"handleCodexAccountBindingEdit"),Ge=r(()=>{if(!a||!ce)return;const Je=tt.envBindings??{};ce({envBindings:{...Je,...sj()},claudeApplyStoredLogin:!0}),$e()},"handleApplyStoredClaudeLogin"),rt=r(async()=>{if(a)return;const Je={...Q()??te("adapterConfig","env",ae.env??WN),...sj()},qt={...D,adapterConfig:{...D.adapterConfig,env:Je}};V(qt),await e.onSave({...oI(e.agent,qt),applyStoredClaudeLogin:!0}),$e()},"handleApplyStoredClaudeLoginEdit"),jt=a?tt.defaultEnvironmentId??"":te("identity","defaultEnvironmentId",e.agent.defaultEnvironmentId??""),st=(0,m.useMemo)(()=>jt?(T.find(Je=>Je.id===jt)??null)?.driver==="local"?"":jt:"",[T,jt]),Nt=(0,m.useMemo)(()=>T.find(Je=>Je.id===st)??null,[st,T]),at=(0,m.useMemo)(()=>{const Je=$?.defaultEnvironmentId??null;return Je?(T.find(qt=>qt.id===Je)??null)?.driver==="local"?"":Je:""},[T,$?.defaultEnvironmentId]),Ee=(0,m.useMemo)(()=>T.find(Je=>Je.id===at)??null,[T,at]),Ne=(0,m.useMemo)(()=>{try{return iw({agentDefaultEnvironmentId:jt||null,instanceDefaultEnvironmentId:$?.defaultEnvironmentId??null,localDefaultEnvironmentId:lw(T),managedSandboxOnly:C?.enableManagedSandboxOnly===!0,managedSandboxEnvironmentId:ow(T),visibleEnvironmentIds:T.map(Je=>Je.id)})}catch{return null}},[jt,$?.defaultEnvironmentId,T,C?.enableManagedSandboxOnly]),He=(0,m.useMemo)(()=>T.find(Je=>Je.id===Ne)??null,[T,Ne]),{data:St}=ee({queryKey:x?P.environments.capabilities(x):["environment-capabilities","none"],queryFn:r(()=>_i.capabilities(x),"queryFn"),enabled:!!x&&Te.login!=null});(0,m.useEffect)(()=>{!a||!ce||!q||!B||st!==B.id&&ce({defaultEnvironmentId:B.id})},[a,ce,q,B,st]);const Ft=(0,m.useMemo)(()=>T.filter(Je=>{if(!Oe.has(Je.driver)||Je.driver==="local")return!1;if(Je.driver!=="sandbox")return!0;const qt=typeof Je.config?.provider=="string"?Je.config.provider:null;return qt!==null&&qt!=="fake"}),[T,Oe]),ts=(0,m.useMemo)(()=>!Nt||Ft.some(Je=>Je.id===Nt.id)?Ft:[...Ft,Nt],[Nt,Ft]),Ot=R&&(q||st.length>0||Ft.length>=1),Be=Ee?cw(Ee):E?"Paperclip Computer":"Local",Ve=de==="paperclip_runner"?String(a?e.values.adapterSchemaValues?.provider??"codex":te("adapterConfig","provider",ae.provider==="acpx"&&ae.acpxAgent==="codex"?"codex":ae.provider??"codex")):void 0,ut=de==="opencode_local"&&XA.safeParse(D.runtime.runtimeConfig?.aiConnection??me.aiConnection).data?.provider==="openrouter"?"openrouter":Ve,qe=x?P.agents.adapterModels(x,de,st||null,ut):["agents","none","adapter-models",de],{data:Gt,error:We}=ee({queryKey:qe,queryFn:r(()=>Wt.adapterModels(x,de,{environmentId:st||null,provider:ut}),"queryFn"),enabled:!!x}),[$t,Dt]=(0,m.useState)(null),[Cs,ze]=(0,m.useState)(!1),ct=Gt??n??[],Pt="command",{data:ke,refetch:ys}=ee({queryKey:x?P.agents.detectModel(x,de):["agents","none","detect-model",de],queryFn:r(()=>{if(!x)throw new Error("Select an organization to detect the model");return Wt.detectModel(x,de)},"queryFn"),enabled:!!(x&&fe&&de!=="opencode_local"&&de!=="paperclip_runner")}),wt=ke?.model??null;ke?.candidates;const{data:Ut=[]}=ee({queryKey:x?P.agents.list(x):["agents","none","list"],queryFn:r(()=>Wt.list(x),"queryFn"),enabled:!!(!a&&x)}),De={mode:s,isCreate:a,adapterType:de,values:a?e.values:null,set:a?Je=>e.onChange(Je):null,config:ae,eff:te,mark:J,models:ct,hideInstructionsFile:h||O,managedSandboxOnly:O},[Se,nt]=(0,m.useState)(!1),[xt,ms]=(0,m.useState)(!1),ht=Jpe(de),zt=r(Je=>(0,t.jsxs)(t.Fragment,{children:[de==="claude_local"&&(0,t.jsx)(P7e,{...De,section:Je}),(0,t.jsx)(Xe.ConfigFields,{...De,section:Je,hideModel:fe})]}),"renderAdapterFields"),[as,Me]=(0,m.useState)(!1),[bt,ft]=(0,m.useState)(!1);function Ye(Je){if(a){const Hs=Xe.buildAdapterConfig(tt);return Je&&Object.assign(Hs,Je),_T(Hs)}const qt={...ae,...D.adapterConfig};return Je&&Object.assign(qt,Je),_T(qt)}r(Ye,"buildAdapterConfigForTest");const gs=ye({mutationFn:r(async()=>{if(!x)throw new Error("Select an organization to test adapter environment");const Je=Q(),qt=Je?{env:Je}:void 0;let Hs=$,Ks=T,Ys=C?.enableManagedSandboxOnly===!0;if(!jt)try{const[Ms,nn,wn]=await Promise.all([g.ensureQueryData({queryKey:P.instance.settings,queryFn:r(()=>Tr.get(),"queryFn")}),g.ensureQueryData({queryKey:P.environments.list(x),queryFn:r(()=>_i.list(x),"queryFn")}),g.ensureQueryData({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")})]);Hs=Ms,Ks=nn,Ys=wn?.enableManagedSandboxOnly===!0}catch{throw new Error("Could not load environment settings to determine which environment to test in. Retry the test.")}const Ar=iw({agentDefaultEnvironmentId:jt||null,instanceDefaultEnvironmentId:Hs?.defaultEnvironmentId??null,localDefaultEnvironmentId:lw(Ks),managedSandboxOnly:Ys,managedSandboxEnvironmentId:ow(Ks),visibleEnvironmentIds:Ks.map(Ms=>Ms.id)}),Ps=Ye(qt),on=a?void 0:e.agent.id,jn=a?void 0:XA.safeParse(D.runtime.runtimeConfig?.aiConnection??e.agent.runtimeConfig.aiConnection).data;if(e.compactTestFeedback){const Ms=de==="paperclip_runner"?Ps.provider==="codex"?"codex_local":Ps.provider==="acpx"&&Ps.acpxAgent==="claude"?"claude_local":de:de;return Upe({companyId:x,adapterType:de,providerAdapter:Ms,adapterConfig:Ps,agentId:on,aiConnection:jn,environmentId:Ar})}return Wt.testEnvironment(x,de,{adapterConfig:Ps,agentId:on,aiConnection:jn,environmentId:Ar})},"mutationFn")}),[Ct,os]=(0,m.useState)(!1),[_t,Xt]=(0,m.useState)(null),zs="Test",hs=!a&&!!e.isSaving,Ws=Ct||hs||!x,Cn=(0,m.useRef)(gs.reset);Cn.current=gs.reset;const Zn=(0,m.useRef)(()=>{});Zn.current=()=>{if(!a||!ce)return;const Je=tt.envBindings??{},qt=tt.claudeStoredSessionId!=null||tt.claudeApplyStoredLogin===!0,Hs=RY in Je;if(!qt&&!Hs)return;const Ks={...Je};delete Ks[RY],ce({envBindings:Ks,claudeStoredSessionId:null,claudeApplyStoredLogin:!1})},(0,m.useEffect)(()=>{Cn.current(),Xt(null),Zn.current()},[de,Ne]);const kn=Te.login!=null,tn=gs.data,Tn=tn!=null&&ve(tn.adapterType).login!=null,Bs=tn&&Tn?tn.checks.find(Je=>Je.code==="adapter_auth_missing")??null:null,an=typeof He?.config?.provider=="string"?He.config.provider:null,ca=an!=null&&St?.sandboxProviders?.[an]?.supportsLoginPty===!0,Sr=Te.login!=null,gn=(a||!(D.runtime.runtimeConfig?.aiConnection??me.aiConnection))&&kn&&He?.driver==="sandbox"&&!!Ne&&!!x&&!!Bs&&(!Sr||ca),rr=(0,m.useCallback)(async()=>{if(!x)throw new Error("Select an organization to test adapter environment");os(!0),Xt(null),gs.reset();try{return await gs.mutateAsync()}catch(Je){throw Xt(Je instanceof Error?Je.message:"Environment test failed"),Je}finally{os(!1)}},[x,gs]),wr=(0,m.useRef)(()=>{});(0,m.useEffect)(()=>{wr.current=()=>{Ws||rr().catch(()=>{})}},[rr,Ws]);const ar=(0,m.useCallback)(()=>{wr.current()},[]);(0,m.useEffect)(()=>{if(!(!l||!e.onTestActionChange))return e.onTestActionChange(ar),()=>{e.onTestActionChange?.(null)}},[l,e.onTestActionChange,ar]),(0,m.useEffect)(()=>{if(!(!l||!e.onTestActionStateChange))return e.onTestActionStateChange({disabled:Ws,pending:Ct}),()=>{e.onTestActionStateChange?.({disabled:!0,pending:!1})}},[l,e.onTestActionStateChange,Ws,Ct]),(0,m.useEffect)(()=>{if(e.onTestFeedbackChange)return e.onTestFeedbackChange({errorMessage:_t??(gs.error instanceof Error?gs.error.message:gs.error?"Environment test failed":null),result:gs.data??null,login:gn&&x&&Ne?{companyId:x,adapterType:de,environmentId:Ne}:null}),()=>{e.onTestFeedbackChange?.({errorMessage:null,result:null,login:null})}},[e.onTestFeedbackChange,_t,gs.data,gs.error,gn,x,de,Ne]);const sa=a?tt.model??"":te("adapterConfig","model",String(ae.model??"")),_r=typeof sa=="string"?sa:"";async function Cr(){if(x){ze(!0),Dt(null);try{const Je=await Wt.adapterModels(x,de,{refresh:!0,environmentId:st||null,provider:ut});g.setQueryData(qe,Je)}catch(Je){Dt(Je instanceof Error?Je.message:"Failed to refresh adapter models.")}finally{ze(!1)}}}r(Cr,"handleRefreshModels");const Wr=de==="codex_local"?"modelReasoningEffort":de==="cursor"?"mode":de==="opencode_local"?"variant":de==="grok_local"?"reasoningEffort":de==="pi_local"?"thinking":"effort",Yn=de==="codex_local"?JS(_r,"Auto").map(Je=>({id:Je.value,label:Je.label})):de==="cursor"?oQe:de==="opencode_local"?iQe:de==="kimi_local"?cQe:de==="pi_local"?[{id:"",label:"Auto"},...["off","minimal","low","medium","high","xhigh"].map(Je=>({id:Je,label:Je}))]:de==="claude_local"||de==="grok_local"?[{id:"",label:"Auto"},...jT(de,_r).map(Je=>({id:Je,label:Je==="xhigh"?"X-High":Je[0].toUpperCase()+Je.slice(1)}))]:lQe,ir=a?tt.thinkingEffort:de==="codex_local"?te("adapterConfig","modelReasoningEffort",String(ae.modelReasoningEffort??ae.reasoningEffort??"")):de==="cursor"?te("adapterConfig","mode",String(ae.mode??"")):de==="opencode_local"?te("adapterConfig","variant",String(ae.variant??"")):te("adapterConfig",Wr,String(ae[Wr]??"")),Ir=de!=="gemini_local"&&de!=="cursor_cloud"&&de!=="paperclip_runner",dr=de==="codex_local"?a?!!tt.search:te("adapterConfig","search",!!ae.search):!1,da=(0,m.useMemo)(()=>{if(a)return{heartbeat:{enabled:tt.heartbeatEnabled,intervalSec:tt.intervalSec}};const Je={...me.heartbeat&&typeof me.heartbeat=="object"?me.heartbeat:{},...D.heartbeat};return{...me,heartbeat:Je}},[a,D.heartbeat,me,tt]),Ls=IW(da.heartbeat),Hn=IW(Ls.maxTurnContinuation),ur=pIe(Hn.enabled,!0),gr=k2(DW(Hn.maxAttempts,dQe),0,qY),gt=k2(DW(Hn.delayMs,uQe*1e3)/1e3,0,Vfe);function ks(Je){J("heartbeat","maxTurnContinuation",{...Hn,...Je})}r(ks,"updateMaxTurnContinuation");const Es=(0,t.jsx)(Zb,{ref:v,onDirtyChange:Z,hideDraftActions:!a&&e.hideInlineSave,value:a?tt.envBindings??WN:te("adapterConfig","env",ae.env??WN),secrets:j,userSecretDefinitions:S,onCreateSecret:r(async(Je,qt)=>await K.mutateAsync({name:Je,value:qt}),"onCreateSecret"),onChange:r(Je=>a?ce({envBindings:Je??{},envVars:""}):J("adapterConfig","env",Je),"onChange")},Y);return!a&&e.content==="secrets"?(0,t.jsxs)("div",{className:U("relative",i&&"space-y-6"),children:[oe&&!e.hideInlineSave&&(0,t.jsx)("div",{className:"sticky top-0 z-10 flex items-center justify-end border-b border-primary/20 bg-background/90 px-4 py-2 backdrop-blur-sm",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Unsaved changes"}),(0,t.jsx)(F,{size:"sm",onClick:ne,disabled:e.isSaving,children:e.isSaving?"Saving...":"Save"})]})}),e.environmentVariablesPlacement==="secrets"&&(0,t.jsxs)("div",{"data-config-section":"environment-variables",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"mb-3 text-sm font-medium",children:"Environment variables"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment variables"}),(0,t.jsx)("div",{className:U(i?"rounded-lg border border-border p-4":"px-4 pb-3"),children:Es})]}),(0,t.jsxs)("div",{"data-config-section":"secrets",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"mb-3 text-sm font-medium",children:"Secret access"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Secret access"}),(0,t.jsxs)("div",{className:U(i?"space-y-3 rounded-lg border border-border p-4":"space-y-3 px-4 pb-3"),children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:vi.secretAccess}),(0,t.jsx)(VHe,{config:{...ae,...D.adapterConfig},secrets:j,onChange:pe,onCreateSecret:r((Je,qt)=>K.mutateAsync({name:Je,value:qt}),"onCreateSecret"),proposals:_,onApproveProposal:I.requestApprove,onRejectProposal:I.requestReject}),I.dialogs]})]})]}):(0,t.jsxs)(hQe,{order:e.sectionOrder,className:U("relative",i&&"space-y-6"),children:[oe&&!e.hideInlineSave&&(0,t.jsx)("div",{className:"sticky top-0 z-10 flex items-center justify-end px-4 py-2 bg-background/90 backdrop-blur-sm border-b border-primary/20",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Unsaved changes"}),(0,t.jsx)(F,{size:"sm",onClick:ne,disabled:!a&&e.isSaving,children:!a&&e.isSaving?"Saving...":"Save"})]})}),!a&&(0,t.jsxs)("div",{"data-config-section":"identity",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:e.sectionTitles?.identity??"Identity"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Identity"}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[(0,t.jsx)(Ss,{label:"Name",hint:vi.name,children:(0,t.jsx)(Ea,{value:te("identity","name",e.agent.name),onCommit:r(Je=>J("identity","name",Je),"onCommit"),immediate:!0,className:fm,placeholder:"Agent name"})}),(0,t.jsx)(Ss,{label:"Title",hint:vi.title,children:(0,t.jsx)(Ea,{value:te("identity","title",e.agent.title??""),onCommit:r(Je=>J("identity","title",Je||null),"onCommit"),immediate:!0,className:fm,placeholder:"e.g. VP of Engineering"})}),(0,t.jsx)(Ss,{label:"Reports to",hint:vi.reportsTo,children:(0,t.jsx)(nHe,{agents:Ut,value:te("identity","reportsTo",e.agent.reportsTo??null),onChange:r(Je=>J("identity","reportsTo",Je),"onChange"),excludeAgentIds:[e.agent.id],chooseLabel:"Choose manager…"})}),fe&&!e.hidePromptTemplate&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ss,{label:"Prompt Template",hint:vi.promptTemplate,children:(0,t.jsx)(yc,{value:te("adapterConfig","promptTemplate",String(ae.promptTemplate??"")),onChange:r(Je=>J("adapterConfig","promptTemplate",Je??""),"onChange"),placeholder:"You are agent {{ agent.name }}. Your role is {{ agent.role }}...",contentClassName:"min-h-(--sz-88px) text-sm font-mono",imageUploadHandler:r(async Je=>{const qt=`agents/${e.agent.id}/prompt-template`;return(await z.mutateAsync({file:Je,namespace:qt})).contentPath},"imageUploadHandler")})}),(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-900 dark:text-amber-100",children:"Prompt template is replayed on every heartbeat. Keep it compact and dynamic to avoid recurring token cost and cache churn."})]})]})]}),q?(0,t.jsxs)("div",{"data-config-section":"environment",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(Ss,{label:"Default environment",hint:"This instance runs all agents in the Kubernetes sandbox. Local execution is disabled.",children:B?(0,t.jsxs)("div",{className:U(fm,"flex items-center text-muted-foreground"),children:[B.name," · Kubernetes sandbox"]}):(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200",children:"This instance requires the Kubernetes sandbox, but no managed Kubernetes environment is available for this organization yet. Configure one before creating agents; execution will not fall back to local."})})})]}):Ot?(0,t.jsxs)("div",{"data-config-section":"environment",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(Ss,{label:"Environment override",children:(0,t.jsx)("div",{className:"space-y-2",children:(0,t.jsxs)("select",{className:fm,value:st,onChange:r(Je=>{const qt=Je.target.value;if(a){ce({defaultEnvironmentId:qt});return}J("identity","defaultEnvironmentId",qt||null)},"onChange"),children:[(0,t.jsxs)("option",{value:"",children:["Default: ",Be]}),ts.map(Je=>(0,t.jsx)("option",{value:Je.id,children:cw(Je)},Je.id))]})})})})]}):null,(0,t.jsxs)("div",{"data-config-section":"adapter",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[(0,t.jsxs)("div",{className:U(i?"flex items-center justify-between mb-3":"px-4 py-2 flex items-center justify-between gap-2"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium",children:e.sectionTitles?.adapter??"Adapter"}):(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Adapter"}),c&&(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",onClick:ar,disabled:Ws,children:Ct?`${zs}...`:zs})]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[o&&(0,t.jsx)(Ss,{label:"Adapter type",hint:vi.adapterType,children:(0,t.jsx)(Qfe,{value:de,disabledTypes:A,onChange:r(Je=>{if(a){const{adapterType:qt,...Hs}=Xg,Ks={...Hs,adapterType:Je};Je==="codex_local"?Ks.dangerouslyBypassSandbox=!0:Je==="gemini_local"?Ks.model="auto":Je==="kimi_local"?Ks.model="kimi-code/kimi-for-coding":Je==="cursor"?Ks.model="auto":Je==="opencode_local"?Ks.model="openai/gpt-5.2-codex":Je==="paperclip_runner"&&(Ks.model=tw),ce(Ks)}else V(qt=>({...qt,adapterType:Je,adapterConfig:{model:Je==="gemini_local"?"auto":Je==="kimi_local"?"kimi-code/kimi-for-coding":Je==="opencode_local"?"openai/gpt-5.2-codex":Je==="cursor"?"auto":Je==="paperclip_runner"?sQe(de,ae.model):"",effort:"",modelReasoningEffort:"",variant:"",mode:"",...Je==="codex_local"?{dangerouslyBypassApprovalsAndSandbox:!0}:Je==="paperclip_runner"?{...Cme(de,te("adapterConfig","model",ae.model))}:{}}}))},"onChange")})}),!a&&x&&(0,t.jsx)(zpe,{companyId:x,agentId:e.agent.id,agentName:e.agent.name,adapterType:de==="paperclip_runner"?te("adapterConfig","provider",ae.provider)==="codex"?"codex_local":te("adapterConfig","provider",ae.provider)==="opencode"?"opencode_local":te("adapterConfig","provider",ae.provider)==="acpx"&&te("adapterConfig","acpxAgent",ae.acpxAgent)==="claude"?"claude_local":de:de,value:XA.safeParse(D.runtime.runtimeConfig?.aiConnection??me.aiConnection).data,model:String(te("adapterConfig","model",ae.model)??""),environmentId:st||void 0,legacy:!0,onChange:r(Je=>J("runtime","runtimeConfig",{...me,aiConnection:Je}),"onChange")}),d&&!e.compactTestFeedback&&(_t||gs.error)&&(0,t.jsx)("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:_t??(gs.error instanceof Error?gs.error.message:"Environment test failed")}),d&&!e.compactTestFeedback&&gs.data&&(0,t.jsx)(yQe,{result:gs.data}),d&&gn&&(0,t.jsx)(eK,{companyId:x,adapterType:de,environmentId:Ne,onStored:a?mt:it,onApplyStored:a?Ge:rt,onAccountBinding:a?void 0:Ke},`${de}:${Ne}`),Ce&&(0,t.jsx)(Ss,{label:"Working directory (deprecated)",hint:vi.cwd,children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2.5 py-1.5",children:[(0,t.jsx)(Io,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)(Ea,{value:a?tt.cwd:te("adapterConfig","cwd",String(ae.cwd??"")),onCommit:r(Je=>a?ce({cwd:Je}):J("adapterConfig","cwd",Je||void 0),"onCommit"),immediate:!0,className:"w-full bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40",placeholder:"/path/to/project"}),(0,t.jsx)(ud,{})]})}),zt("adapter"),fe&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tK,{models:ct,value:_r,onChange:r(Je=>{const qt=jT(de,Je),Hs=["codex_local","claude_local","grok_local"].includes(de)&&!!ir&&!qt.includes(String(ir));if(a){ce({model:Je,...Hs?{thinkingEffort:""}:{}});return}J("adapterConfig","model",Je||void 0),Hs&&(J("adapterConfig",Wr,void 0),J("adapterConfig","reasoningEffort",void 0))},"onChange"),open:as,onOpenChange:Me,defaultLabel:de==="claude_local"?"Default (claude-opus-5)":void 0,allowDefault:de!=="opencode_local"&&de!=="pi_local"&&de!=="paperclip_runner",required:de==="opencode_local"||de==="pi_local",groupByProvider:de==="opencode_local"||de==="pi_local",creatable:!0,detectedModel:wt,detectedModelCandidates:[],onDetectModel:de==="opencode_local"||de==="paperclip_runner"?void 0:async()=>(await ys()).data?.model??null,onRefreshModels:tQe(de)?Cr:void 0,refreshingModels:Cs,detectModelLabel:"Detect model",emptyDetectHint:"No model detected. Select or enter one manually."}),($t||We)&&(0,t.jsx)("p",{className:"text-xs text-destructive",children:$t??(We instanceof Error?We.message:"Failed to load adapter models.")}),de==="opencode_local"&&Nt&&Nt.driver!=="local"&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Live OpenCode model discovery only runs for Local environments. Using the curated list and manual entry for ",Nt.name,"."]}),Ir&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(jQe,{value:ir,options:Yn,onChange:r(Je=>a?ce({thinkingEffort:Je}):J("adapterConfig",Wr,Je||void 0),"onChange"),open:bt,onOpenChange:ft}),de==="codex_local"&&dr&&ir==="minimal"&&(0,t.jsx)("p",{className:"text-xs text-amber-400",children:"Codex may reject `minimal` thinking when search is enabled."})]})]})]})]}),(0,t.jsxs)("div",{"data-config-section":"configuration",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Configuration"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Configuration"}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[!a&&typeof ae.bootstrapPromptTemplate=="string"&&ae.bootstrapPromptTemplate&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ss,{label:"Bootstrap prompt (legacy)",hint:vi.bootstrapPrompt,children:(0,t.jsx)(yc,{value:te("adapterConfig","bootstrapPromptTemplate",String(ae.bootstrapPromptTemplate??"")),onChange:r(Je=>J("adapterConfig","bootstrapPromptTemplate",Je||void 0),"onChange"),placeholder:"Optional initial setup prompt for the first run",contentClassName:"min-h-(--sz-44px) text-sm font-mono",imageUploadHandler:r(async Je=>{const qt=`agents/${e.agent.id}/bootstrap-prompt`;return(await z.mutateAsync({file:Je,namespace:qt})).contentPath},"imageUploadHandler")})}),(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200",children:"Bootstrap prompt is legacy and will be removed in a future release. Consider moving this content into the agent's prompt template or instructions file instead."})]}),zt("configuration"),(fe||de==="process"||ht?.fields.some(Je=>cF(Je.key)==="advanced"))&&(0,t.jsx)(g2,{title:"Advanced",open:xt,onToggle:r(()=>ms(!xt),"onToggle"),children:(0,t.jsxs)("div",{className:"space-y-3",children:[fe&&(0,t.jsxs)(t.Fragment,{children:[" ",!O&&(0,t.jsx)(Ss,{label:"Command",hint:vi.localCommand,children:(0,t.jsx)(Ea,{value:a?tt.command:te("adapterConfig",Pt,String(ae.command??"")),onCommit:r(Je=>a?ce({command:Je}):J("adapterConfig",Pt,Je||null),"onCommit"),immediate:!0,className:fm,placeholder:{claude_local:"claude",codex_local:"codex",gemini_local:"gemini",kimi_local:"kimi",pi_local:"pi",cursor:"agent",opencode_local:"opencode"}[de]??de.replace(/_local$/,"")})}),(0,t.jsx)(Ss,{label:"Extra args (comma-separated)",hint:vi.extraArgs,children:(0,t.jsx)(Ea,{value:a?tt.extraArgs:te("adapterConfig","extraArgs",aQe(ae.extraArgs)),onCommit:r(Je=>a?ce({extraArgs:Je}):J("adapterConfig","extraArgs",Je?.trim()?rQe(Je):null),"onCommit"),className:fm,placeholder:"e.g. --verbose, --foo=bar"})})]}),zt("advanced")]})})]})]}),e.environmentVariablesPlacement!=="secrets"&&(fe||ht?.fields.some(Je=>cF(Je.key)==="environment"))&&(0,t.jsxs)("div",{"data-config-section":"environment-variables",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment variables"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment variables"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:fe?Es:zt("environment")})]}),a&&u?(0,t.jsxs)("div",{"data-config-section":"run-policy",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}):(0,t.jsxs)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[(0,t.jsx)(nY,{label:"Heartbeat on interval",hint:vi.heartbeatInterval,checked:tt.heartbeatEnabled,onCheckedChange:r(Je=>ce({heartbeatEnabled:Je}),"onCheckedChange"),number:tt.intervalSec,onNumberChange:r(Je=>ce({intervalSec:Je}),"onNumberChange"),numberLabel:"sec",numberPrefix:"Run heartbeat every",numberHint:vi.intervalSec,showNumber:tt.heartbeatEnabled}),(0,t.jsx)(g2,{title:"Advanced Run Policy",open:Se,onToggle:r(()=>nt(!Se),"onToggle"),children:(0,t.jsx)("div",{className:"space-y-3",children:zt("runPolicy")})})]})]}):a?null:(0,t.jsxs)("div",{"data-config-section":"run-policy",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}):(0,t.jsxs)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg overflow-hidden":""),children:[(0,t.jsx)("div",{className:U(i?"p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(nY,{label:"Heartbeat on interval",hint:vi.heartbeatInterval,checked:te("heartbeat","enabled",he.enabled===!0),onCheckedChange:r(Je=>J("heartbeat","enabled",Je),"onCheckedChange"),number:te("heartbeat","intervalSec",Number(he.intervalSec??300)),onNumberChange:r(Je=>J("heartbeat","intervalSec",Je),"onNumberChange"),numberLabel:"sec",numberPrefix:"Run heartbeat every",numberHint:vi.intervalSec,showNumber:te("heartbeat","enabled",he.enabled===!0)})}),(0,t.jsx)(g2,{title:"Advanced Run Policy",bordered:i,open:Se,onToggle:r(()=>nt(!Se),"onToggle"),children:(0,t.jsxs)("div",{className:"space-y-3",children:[zt("runPolicy"),fe&&(0,t.jsx)(t.Fragment,{children:!a&&(0,t.jsxs)(t.Fragment,{children:[!ht?.fields.some(Je=>Je.key==="timeoutSec")&&(0,t.jsx)(Ss,{label:"Timeout (sec)",hint:vi.timeoutSec,children:(0,t.jsx)(Zl,{value:te("adapterConfig","timeoutSec",Number(ae.timeoutSec??0)),onCommit:r(Je=>J("adapterConfig","timeoutSec",Je),"onCommit"),immediate:!0,className:fm})}),!ht?.fields.some(Je=>Je.key==="graceSec")&&(0,t.jsx)(Ss,{label:"Interrupt grace period (sec)",hint:vi.graceSec,children:(0,t.jsx)(Zl,{value:te("adapterConfig","graceSec",Number(ae.graceSec??15)),onCommit:r(Je=>J("adapterConfig","graceSec",Je),"onCommit"),immediate:!0,className:fm})})]})}),(0,t.jsx)(rd,{label:"Wake on demand",hint:vi.wakeOnDemand,checked:te("heartbeat","wakeOnDemand",he.wakeOnDemand!==!1),onChange:r(Je=>J("heartbeat","wakeOnDemand",Je),"onChange")}),(0,t.jsx)(Ss,{label:"Cooldown (sec)",hint:vi.cooldownSec,children:(0,t.jsx)(Zl,{value:te("heartbeat","cooldownSec",Number(he.cooldownSec??10)),onCommit:r(Je=>J("heartbeat","cooldownSec",Je),"onCommit"),immediate:!0,className:fm})}),(0,t.jsx)(Ss,{label:"Max concurrent runs",hint:vi.maxConcurrentRuns,children:(0,t.jsx)(Zl,{value:te("heartbeat","maxConcurrentRuns",Number(he.maxConcurrentRuns??20)),onCommit:r(Je=>J("heartbeat","maxConcurrentRuns",Je),"onCommit"),immediate:!0,className:fm})}),(0,t.jsxs)("div",{className:"rounded-md border border-border/70 px-3 py-2",children:[(0,t.jsx)(rd,{label:"Continue after max-turn stop",hint:vi.maxTurnContinuationEnabled,checked:ur,onChange:r(Je=>ks({enabled:Je}),"onChange")}),ur?(0,t.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[(0,t.jsx)(Ss,{label:"Continuation attempts",hint:vi.maxTurnContinuationMaxAttempts,children:(0,t.jsx)(Zl,{value:gr,onCommit:r(Je=>ks({maxAttempts:k2(Je,0,qY)}),"onCommit"),immediate:!0,className:fm})}),(0,t.jsx)(Ss,{label:"Continuation delay (sec)",hint:vi.maxTurnContinuationDelaySec,children:(0,t.jsx)(Zl,{value:gt,onCommit:r(Je=>ks({delayMs:mQe(Je)}),"onCommit"),immediate:!0,className:fm})})]}):null]})]})})]})]}),!a&&p?(0,t.jsxs)("div",{className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"mb-3 flex items-center gap-2 text-sm font-medium",children:[(0,t.jsx)(xj,{className:"h-3 w-3"})," Debugging"]}):(0,t.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-xs font-medium text-muted-foreground",children:[(0,t.jsx)(xj,{className:"h-3 w-3"})," Debugging"]}),(0,t.jsxs)("div",{className:U("border-border bg-accent/30",i?"rounded-lg border p-4":"mx-4 mb-4 rounded-md border px-3 py-3"),children:[(0,t.jsx)(rd,{label:"Capture raw provider traces",hint:"Stores exact provider traffic for every future run until disabled. Traces may contain sensitive prompts and tool arguments, are administrator-only, and expire after 24 hours.",checked:te("debug","providerTrace",Ie.providerTrace)==="raw",onChange:r(Je=>J("debug","providerTrace",Je?"raw":void 0),"onChange")}),te("debug","providerTrace",Ie.providerTrace)==="raw"?(0,t.jsxs)("div",{className:"mt-3 flex items-start gap-2 rounded-md border border-border bg-background/60 px-3 py-2 text-xs text-foreground",children:[(0,t.jsx)(xj,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{children:"Raw tracing is on for future runs. Paperclip keeps at most 64 MiB per run and automatically deletes it after 24 hours."})]}):null]})]}):null,e.compactTestFeedback&&d&&l&&(0,t.jsx)(Wpe,{state:Ct?"running":_t||gs.error?"fail":tn?.status??"idle",result:tn??null,error:_t??(gs.error instanceof Error?gs.error.message:null),onTest:ar,disabled:Ws})]})}r(Wfe,"AgentConfigForm");var SF=new Set(["authenticated","failed","timed_out","cancelled"]),CF=2e3;function _F({value:e,label:s}){const[n,a]=(0,m.useState)(!1),i=(0,m.useRef)(null);return(0,m.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-xs","aria-label":s,title:s,className:"text-muted-foreground hover:text-foreground",onClick:r(async()=>{try{await Gr(e),a(!0)}catch{a(!1)}i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),1500)},"onClick"),children:n?(0,t.jsx)(xs,{className:"size-3"}):(0,t.jsx)(jr,{className:"size-3"})})}r(_F,"AdapterLoginCopyButton");function pQe({status:e,message:s}){return e==="authenticated"?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Authenticated. The environment has credentials now."})]}):(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsxs)("span",{children:[e==="timed_out"?"Login timed out":e==="cancelled"?"Login cancelled":"Login failed",s?`: ${s}`:"."]})]})}r(pQe,"AdapterLoginTerminalState");var fQe={claude_local:"Anthropic",codex_local:"OpenAI"};function Hfe(e){const s=fQe[e];return s?`Sign in to ${s}`:"Sign in to the environment"}r(Hfe,"adapterLoginTitle");function eK(e){return Bw()(e.adapterType).login?.panelMode==="submitted_browser_code"?(0,t.jsx)(vQe,{...e}):(0,t.jsx)(xQe,{...e})}r(eK,"AdapterLoginPanel");function xQe({companyId:e,adapterType:s,environmentId:n,autoStart:a,onConnected:i,onAccountBinding:o,chrome:l="panel",aiConnection:c,onPromptReady:d}){const[u,h]=(0,m.useState)(null),[p,x]=(0,m.useState)(null),[g,v]=(0,m.useState)(null),[y,j]=(0,m.useState)("idle"),S=(0,m.useRef)(!1),w=ye({mutationFn:r(()=>Wt.startAdapterAuthLogin(e,s,{environmentId:n,aiConnection:c}),"mutationFn"),onSuccess:r(X=>{S.current=!1,x(null),v(null),j("idle"),h(X.sessionId)},"onSuccess"),onError:r(X=>{x(X instanceof Error?X.message:"Could not start the login.")},"onError")}),N=(0,m.useCallback)(()=>{S.current=!1,h(null),v(null),x(null)},[]),_=ye({mutationFn:r(()=>Wt.cancelAdapterAuthLogin(e,s,u),"mutationFn"),onSuccess:N,onError:r(X=>{x(X instanceof Error?X.message:"Could not cancel the login.")},"onError")}),I=ee({queryKey:["adapter-login-active-session",e,s],queryFn:r(async()=>{try{const X=await Wt.getActiveAdapterAuthLoginSession(e,s);if(!X)return null;if(c&&X.environmentId!==n||!!X.aiConnection!=!!c||c&&(X.aiConnection?.provider!==c.provider||X.aiConnection?.method!==c.method||X.aiConnection?.connectionId!==c.connectionId||X.aiConnection?.ownership!==c.ownership||X.aiConnection?.allAgents!==c.allAgents||JSON.stringify(X.aiConnection?.agentIds)!==JSON.stringify(c.agentIds)))throw new Error("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one.");return X}catch(X){if(X instanceof Nn&&X.status===404)return null;throw X}},"queryFn"),retry:!1,gcTime:0,staleTime:0}),[C,A]=(0,m.useState)(!1),R=ee({queryKey:["adapter-login-status",e,s,u],queryFn:r(()=>Wt.getAdapterAuthLoginStatus(e,s,u),"queryFn"),enabled:!!u&&!C,retry:r((X,le)=>le instanceof Nn&&le.status===404?!1:X<3,"retry"),refetchInterval:r(X=>{const le=X.state.data?.status;return le&&SF.has(le)?!1:CF},"refetchInterval")});(0,m.useEffect)(()=>{const X=R.data?.prompt??null;X&&v(X)},[R.data]);const E=R.data??w.data??null,O=E?.status??null,L=g,$=O?SF.has(O):!1,T=!!u&&!$,q=w.isPending||T||y==="saving",B=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(B.current||!I.isFetched)return;B.current=!0;const X=I.data;X&&(S.current=!0,x(null),v(X.prompt??null),h(X.sessionId))},[I.isFetched,I.data]),(0,m.useEffect)(()=>{const X=R.error;if(!(X instanceof Nn&&X.status===404)||!S.current||C)return;A(!0);const le=u;(async()=>(le&&await Wt.cancelAdapterAuthLogin(e,s,le).catch(()=>{}),A(!1),N()))()},[R.error,C,u,e,s,N]);const K=(0,m.useRef)(!1),z=(0,m.useRef)(w.mutate);z.current=w.mutate,(0,m.useEffect)(()=>{if(!(!a||K.current)){if(I.isError){K.current=!0,x(I.error instanceof Error?I.error.message:"Could not check for an active login.");return}I.isSuccess&&(K.current=!0,!I.data&&z.current())}},[a,I.isSuccess,I.isError,I.data,I.error]);const D=(0,m.useRef)(!1),V=(0,m.useRef)(i);V.current=i,(0,m.useEffect)(()=>{O!=="authenticated"||D.current||(D.current=!0,V.current?.(u??void 0))},[O]);const H=(0,m.useRef)(null),Z=(0,m.useRef)(o);Z.current=o;const Y=R.data?.codexAccountBinding??null,ie=(0,m.useCallback)(async X=>{const le=Z.current;if(le){j("saving");try{await le(X),j("bound")}catch{j("failed")}}},[]);(0,m.useEffect)(()=>{O!=="authenticated"||!u||H.current!==u&&(!Y||!Y.companyIdentityDiffers||!Z.current||(H.current=u,ie(Y)))},[O,u,Y,ie]);const se=(0,m.useRef)(d);if(se.current=d,(0,m.useEffect)(()=>{se.current?.(L?.url??null)},[L]),l==="onboarding"){const X=$&&O&&O!=="authenticated";return(0,t.jsx)(nfe,{loading:!L&&!p&&!X,providerName:tfe(s),authorizationUrl:L?.url,mode:"displayed_code",children:p?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:p}):X?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:O==="timed_out"?"The login timed out. Start it again.":O==="cancelled"?"The login was cancelled.":"The login did not finish. Start it again."}):(0,t.jsx)(p7e,{code:L?.code??"",autoCopy:!0})})}return(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-foreground",children:Hfe(s)}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[T&&(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground hover:text-foreground",disabled:_.isPending,onClick:r(()=>_.mutate(),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:q,onClick:r(()=>w.mutate(),"onClick"),children:"Sign in"})]})]}),p&&(0,t.jsx)("div",{role:"alert",className:"text-(length:--text-micro) text-destructive",children:p}),(0,t.jsxs)("div",{role:"status","aria-live":"polite",className:"space-y-2 empty:hidden",children:[T&&!L&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Preparing..."})]}),T&&L&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"Copy the code, then open the authentication page."}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"1. Code"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:L.code})]}),(0,t.jsx)(_F,{value:L.code,label:"Copy code"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"2. Authentication URL"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:L.url})]}),(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(_F,{value:L.url,label:"Copy URL"}),(0,t.jsx)(F,{asChild:!0,type:"button",variant:"ghost",size:"icon-xs","aria-label":"Open the authentication page",title:"Open the authentication page",className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)("a",{href:L.url,target:"_blank",rel:"noreferrer noopener",children:(0,t.jsx)(xr,{className:"size-3"})})})]})]})]}),$&&O&&(0,t.jsx)(pQe,{status:O,message:E?.failure?.message??null}),O==="authenticated"&&y==="saving"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Binding this agent to the signed-in account..."})]}),O==="authenticated"&&y==="bound"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Agent bound to the signed-in account."})]}),O==="authenticated"&&y==="failed"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro)",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0 text-destructive"}),(0,t.jsx)("span",{className:"text-destructive",children:"Could not bind this agent to the signed-in account."}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:r(()=>{Y&&ie(Y)},"onClick"),children:"Retry"})]})]})]})}r(xQe,"DisplayedCodeLoginPanel");var gQe=new Set(["failed","timed_out","cancelled"]),zY="The login did not finish. Start the login again.",bQe=9e5,UY="The login timed out. Start the login again.";function vQe({companyId:e,adapterType:s,environmentId:n,onStored:a,onApplyStored:i,autoStart:o,onConnected:l,onCodeSubmitted:c,onSubmitFailed:d,chrome:u="panel",aiConnection:h,onPromptReady:p}){const[x,g]=(0,m.useState)(null),[v,y]=(0,m.useState)(null),[j,S]=(0,m.useState)(null),[w,N]=(0,m.useState)(!1),[_,I]=(0,m.useState)(""),[C,A]=(0,m.useState)(null),[R,E]=(0,m.useState)(!1),[O,L]=(0,m.useState)(!1),[$,T]=(0,m.useState)(!1),[q,B]=(0,m.useState)(!1),K=(0,m.useRef)(!1),[z,D]=(0,m.useState)(!1),V=(0,m.useRef)(!1),H=r(()=>{y(null),S(null),N(!1),I(""),A(null),E(!1),L(!1),B(!1),T(!1),K.current=!1},"resetLocalState"),Z=ee({queryKey:["claude-oauth-token-status",e],queryFn:r(async()=>{try{return await Wt.getClaudeOAuthTokenStatus(e)}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),retry:r((at,Ee)=>Ee instanceof Nn&&Ee.status===404?!1:at<2,"retry")}).data??null,Y=ye({mutationFn:r(()=>Wt.startClaudeSetupTokenLogin(e,{environmentId:n,aiConnection:h,...Z&&!h?{overwrite:{expectedSecretId:Z.secretId,expectedLatestVersion:Z.latestVersion}}:{}}),"mutationFn"),onSuccess:r(at=>{V.current=!1,H(),g(at.sessionId)},"onSuccess"),onError:r(at=>{y(at instanceof Error?at.message:"Could not start the login.")},"onError")}),ie=r(()=>{V.current=!1,g(null),H()},"clearActiveSession"),se=ye({mutationFn:r(()=>Wt.cancelClaudeSetupTokenLogin(e,x),"mutationFn"),onSuccess:r(()=>{ie()},"onSuccess"),onError:r(at=>{if(at instanceof Nn&&at.status===404){ie();return}y(at instanceof Error?at.message:"Could not cancel the login.")},"onError")}),X=(0,m.useCallback)(at=>{Wt.cancelClaudeSetupTokenLogin(e,at).catch(()=>{})},[e]),le=ee({queryKey:["claude-setup-token-active-session",e],queryFn:r(async()=>{try{const at=await Wt.getActiveClaudeSetupTokenLoginSession(e);if(!at)return null;if(h&&at.environmentId!==n||!!at.aiConnection!=!!h||h&&(at.aiConnection?.provider!==h.provider||at.aiConnection?.method!==h.method||at.aiConnection?.connectionId!==h.connectionId||at.aiConnection?.ownership!==h.ownership||at.aiConnection?.allAgents!==h.allAgents||JSON.stringify(at.aiConnection?.agentIds)!==JSON.stringify(h.agentIds)))throw new Error("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one.");return at}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),retry:!1,gcTime:0,staleTime:0}),[oe,te]=(0,m.useState)(!1),J=!!x&&!O&&!q&&!oe,Q=ee({queryKey:["claude-setup-token-status",e,x],queryFn:r(()=>Wt.getClaudeSetupTokenLoginStatus(e,x),"queryFn"),enabled:J,retry:r((at,Ee)=>Ee instanceof Nn&&Ee.status===404?!1:at<3,"retry"),refetchInterval:r(at=>{if(O||q)return!1;const Ee=at.state.data?.status;return Ee&&SF.has(Ee)?!1:CF},"refetchInterval")});(0,m.useEffect)(()=>{const at=Q.error;if(at instanceof Nn&&at.status===404){if(V.current){if(oe)return;te(!0);const Ee=x;(async()=>(Ee&&await Wt.cancelClaudeSetupTokenLogin(e,Ee).catch(()=>{}),te(!1),ie()))();return}B(!0)}},[Q.error,oe,x,e]);const pe=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(pe.current||!le.isFetched)return;pe.current=!0;const at=le.data;at&&(V.current=!0,H(),g(at.sessionId),at.prompt&&(S(at.prompt.authorizationUrl),at.prompt.transportAdvisory&&N(!0)))},[le.isFetched,le.data]);const re=ee({queryKey:["claude-setup-token-prompt",e,x],enabled:J&&!j,queryFn:r(async()=>{try{return await Wt.getClaudeSetupTokenLoginPrompt(e,x)}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),refetchInterval:r(at=>O||at.state.data?.authorizationUrl?!1:CF,"refetchInterval")});(0,m.useEffect)(()=>{const at=re.data?.authorizationUrl??null;at&&S(at),re.data?.transportAdvisory&&N(!0)},[re.data]);const ne=ye({mutationFn:r(at=>Wt.submitClaudeSetupTokenBrowserCode(e,x,at),"mutationFn"),onError:r(at=>{y(at instanceof Error?at.message:"Could not submit the browser code.")},"onError")}),ae=ye({mutationFn:r(()=>Wt.completeClaudeSetupTokenLogin(e,x),"mutationFn"),onSuccess:r(at=>{A(at.storedSessionId),a?.(at.storedSessionId)},"onSuccess"),onError:r(()=>{E(!0)},"onError")}),me=Q.data?.status??Y.data?.status??null,he=Q.data?.expiresAt??Y.data?.expiresAt??null,Ie=(0,m.useRef)(ae.mutate);Ie.current=ae.mutate,(0,m.useEffect)(()=>{me==="authenticated"&&!K.current&&(K.current=!0,Ie.current())},[me]);const de=C!==null,ve=R||q||!!(me&&gQe.has(me)),Te=me==="authenticated"&&!de&&!R,fe=!!x&&!de&&!ve&&!O,Ce=Y.isPending||fe;(0,m.useEffect)(()=>{if(!fe)return;const at=he!==null?new Date(he).getTime():NaN,Ee=Number.isFinite(at)?Math.max(0,at-Date.now()):bQe,Ne=setTimeout(()=>{x&&X(x),L(!0)},Ee);return()=>clearTimeout(Ne)},[fe,he,x,X]);const Xe=_.trim(),Oe=fe&&!!j&&!Te&&rIe(Xe)&&!ne.isPending&&!$,tt=(0,m.useRef)(c);tt.current=c;const ce=(0,m.useRef)(d);ce.current=d;const $e=r(()=>{Oe&&(y(null),ne.mutate(Xe),T(!0),tt.current?.(),u!=="onboarding"&&I(""))},"handleSubmit"),mt=(0,m.useRef)(!1),it=(0,m.useRef)(Y.mutate);it.current=Y.mutate,(0,m.useEffect)(()=>{if(!(!o||mt.current)){if(le.isError){mt.current=!0,y(le.error instanceof Error?le.error.message:"Could not check for an active login.");return}le.isSuccess&&(mt.current=!0,!le.data&&it.current())}},[o,le.isSuccess,le.isError,le.data,le.error]);const Ke=(0,m.useRef)($e);Ke.current=$e;const Ge=u==="onboarding",rt=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!Ge||!rt.current||(rt.current=!1,Oe&&Ke.current())},[Ge,Oe,_]);const jt=(0,m.useRef)(!1),st=(0,m.useRef)(l);st.current=l,(0,m.useEffect)(()=>{!de||jt.current||(jt.current=!0,st.current?.(x??void 0))},[de]),(0,m.useEffect)(()=>{$&&(!v&&!ve&&!O||(T(!1),ce.current?.()))},[$,v,ve,O]);const Nt=(0,m.useRef)(p);if(Nt.current=p,(0,m.useEffect)(()=>{Nt.current?.(j)},[j]),u==="onboarding"){const at=ve||O;return(0,t.jsxs)(nfe,{loading:!j&&!v&&!at,providerName:tfe(s),authorizationUrl:j??void 0,mode:"submitted_code",children:[w&&(0,t.jsxs)("p",{className:"flex items-start gap-2 pl-2 text-xs text-amber-700 dark:text-amber-200",children:[(0,t.jsx)(Is,{className:"mt-0.5 size-3 shrink-0"}),"This connection is not encrypted. The login code travels in clear text on this network. Continue only on a network you trust."]}),v?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:v}):at?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:O&&!ve?UY:zY}):(0,t.jsx)(V5,{value:_,onChange:I,onSubmit:$e,onPaste:r(()=>{rt.current=!0},"onPaste"),masked:!0,disabled:ne.isPending||Te||$})]})}return(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-foreground",children:Hfe(s)}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[fe&&(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground hover:text-foreground",disabled:se.isPending,onClick:r(()=>se.mutate(),"onClick"),children:"Cancel"}),i&&Z&&!fe&&!de&&!z&&(0,t.jsx)(F,{type:"button",variant:"default",size:"sm",className:"h-7 px-2.5 text-xs",onClick:r(()=>{i(),D(!0)},"onClick"),children:"Use saved login"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:Ce,onClick:r(()=>Y.mutate(),"onClick"),children:Z&&!fe&&!de?"Sign in to replace":"Sign in"})]})]}),Z&&!fe&&!de&&!z&&(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"You have a saved Claude login. Use it to bind this agent, or log in again to replace the stored token."}),z&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"The saved Claude login is bound to this agent now."})]}),v&&(0,t.jsx)("div",{role:"alert",className:"text-(length:--text-micro) text-destructive",children:v}),(0,t.jsxs)("div",{role:"status","aria-live":"polite",className:"space-y-2 empty:hidden",children:[fe&&!j&&!Te&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Preparing..."})]}),fe&&j&&!Te&&(0,t.jsxs)("div",{className:"space-y-2",children:[w&&(0,t.jsxs)("div",{className:"flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 px-2 py-1.5 text-(length:--text-micro) text-amber-800 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-200",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0 mt-0.5"}),(0,t.jsx)("span",{children:"This connection is not encrypted. The login code travels in clear text on this network. Continue only on a network you trust."})]}),(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"Open the authorization page, then enter the browser code it shows."}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"1. Authorization URL"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:j})]}),(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(_F,{value:j,label:"Copy URL"}),(0,t.jsx)(F,{asChild:!0,type:"button",variant:"ghost",size:"icon-xs","aria-label":"Open the authorization page",title:"Open the authorization page",className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)("a",{href:j,target:"_blank",rel:"noreferrer noopener",children:(0,t.jsx)(xr,{className:"size-3"})})})]})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"2. Browser code"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("input",{"aria-label":"Browser code",type:"text",autoComplete:"off",spellCheck:!1,value:_,onChange:r(at=>I(at.target.value),"onChange"),onKeyDown:r(at=>{at.key==="Enter"&&(at.preventDefault(),$e())},"onKeyDown"),className:"flex-1 min-w-0 rounded-md border border-border bg-background px-2 py-1 font-mono text-xs text-foreground"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:!Oe,onClick:$e,children:"Submit"})]})]})]}),Te&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Completing the login…"})]}),de&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Authenticated. The environment has credentials now."})]}),ve&&(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:zY})]}),O&&!ve&&!de&&(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:UY})]})]})]})}r(vQe,"SubmittedBrowserCodeLoginPanel");function yQe({result:e}){const s=e.status==="pass"?"Passed":e.status==="warn"?"Warnings":"Failed",n=e.status==="pass"?"text-green-700 dark:text-green-300 border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10":e.status==="warn"?"text-amber-700 dark:text-amber-300 border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10":"text-red-700 dark:text-red-300 border-red-300 dark:border-red-500/40 bg-red-50 dark:bg-red-500/10";return(0,t.jsxs)("div",{className:`rounded-md border px-3 py-2 text-xs ${n}`,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"font-medium",children:s}),(0,t.jsx)("span",{className:"text-(length:--text-micro) opacity-80",children:new Date(e.testedAt).toLocaleTimeString()})]}),(0,t.jsx)("div",{className:"mt-2 space-y-1.5",children:e.checks.map((a,i)=>(0,t.jsxs)("div",{className:"text-(length:--text-micro) leading-relaxed break-words",children:[(0,t.jsx)("span",{className:"font-medium uppercase tracking-wide opacity-80",children:a.level}),(0,t.jsx)("span",{className:"mx-1 opacity-60",children:"·"}),(0,t.jsx)("span",{children:a.message}),a.detail&&(0,t.jsxs)("span",{className:"block opacity-75 break-all",children:["(",a.detail,")"]}),a.hint&&(0,t.jsxs)("span",{className:"block opacity-90 break-words",children:["Hint: ",a.hint]})]},`${a.code}-${i}`))})]})}r(yQe,"AdapterEnvironmentResult$1");function Qfe({value:e,onChange:s,disabledTypes:n}){const[a,i]=(0,m.useState)(!1),o=Fm(e),l=(0,m.useMemo)(()=>Ufe(c=>rw[c]??sf(c)).filter(c=>!n.has(c.value)),[n]);return(0,t.jsxs)(sr,{open:a,onOpenChange:i,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e==="opencode_local"?(0,t.jsx)(dF,{className:"h-3.5 w-3.5"}):null,(0,t.jsx)("span",{className:"truncate",children:rw[e]??sf(e)}),o.experimental&&(0,t.jsx)(KY,{})]}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsx)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:l.map(c=>(0,t.jsxs)("button",{disabled:c.comingSoon,className:U("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded",c.comingSoon?"opacity-40 cursor-not-allowed":"hover:bg-accent/50",c.value===e&&!c.comingSoon&&"bg-accent"),onClick:r(()=>{c.comingSoon||(s(c.value),i(!1))},"onClick"),children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[c.value==="opencode_local"?(0,t.jsx)(dF,{className:"h-3.5 w-3.5"}):null,(0,t.jsx)("span",{children:c.label}),c.experimental&&(0,t.jsx)(KY,{})]}),c.comingSoon&&(0,t.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground",children:"Coming soon"})]},c.value))})]})}r(Qfe,"AdapterTypeDropdown");function KY(){return(0,t.jsx)("span",{className:"shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1.5 py-0.5 text-(length:--text-nano) font-medium leading-none text-amber-700 dark:text-amber-200",children:"Experimental"})}r(KY,"ExperimentalBadge$1");function tK({models:e,value:s,onChange:n,open:a,onOpenChange:i,allowDefault:o,required:l,groupByProvider:c,creatable:d,detectedModel:u,detectedModelCandidates:h,onDetectModel:p,onRefreshModels:x,refreshingModels:g,detectModelLabel:v,emptyDetectHint:y,defaultLabel:j}){const[S,w]=(0,m.useState)(""),[N,_]=(0,m.useState)(!1),I=e.find($=>$.id===s),C=S.trim(),A=!!(d&&C&&!e.some($=>$.id.toLowerCase()===C.toLowerCase())),R=(0,m.useMemo)(()=>{const $=new Set;u&&$.add(u);for(const T of h??[])T&&$.add(T);return $},[u,h]),E=(0,m.useMemo)(()=>e.filter($=>{if(R.has($.id))return!1;if(!S.trim())return!0;const T=S.toLowerCase(),q=EO($.id)??"";return $.id.toLowerCase().includes(T)||$.label.toLowerCase().includes(T)||q.toLowerCase().includes(T)}),[e,S,R]),O=(0,m.useMemo)(()=>{if(!c)return[{provider:"models",entries:[...E].sort((T,q)=>T.id.localeCompare(q.id))}];const $=new Map;for(const T of E){const q=EO(T.id)??"other",B=$.get(q)??[];B.push(T),$.set(q,B)}return Array.from($.entries()).sort(([T],[q])=>T.localeCompare(q)).map(([T,q])=>({provider:T,entries:[...q].sort((B,K)=>B.id.localeCompare(K.id))}))},[E,c]);async function L(){if(p){_(!0);try{const $=await p();$&&(n($),i(!1),w(""))}finally{_(!1)}}}return r(L,"handleDetectModel"),(0,t.jsx)(Ss,{label:"Model",hint:vi.model,children:(0,t.jsxs)(sr,{open:a,onOpenChange:r($=>{i($),$||w("")},"onOpenChange"),children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsx)("span",{className:U(!s&&"text-muted-foreground"),children:I?I.label:s||(o?j??"Default":l?"Select model (required)":"Select model")}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsxs)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:[(0,t.jsxs)("div",{className:"relative mb-1",children:[(0,t.jsx)("input",{className:"w-full px-2 py-1.5 pr-6 text-xs bg-transparent outline-none border-b border-border placeholder:text-muted-foreground/50",placeholder:d?"Search models... (type to create)":"Search models...",value:S,onChange:r($=>w($.target.value),"onChange"),autoFocus:!0}),S&&(0,t.jsx)("button",{type:"button",className:"absolute right-1.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:r(()=>w(""),"onClick"),children:(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,t.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),p&&!S.trim()&&(0,t.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-muted-foreground",onClick:r(()=>{L()},"onClick"),disabled:N,children:[(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,t.jsx)("path",{d:"M3 3v5h5"})]}),N?"Detecting...":u?v?.replace(/^Detect\b/,"Re-detect")??"Re-detect from config":v??"Detect from config"]}),x&&!S.trim()&&(0,t.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-muted-foreground",onClick:r(()=>{x()},"onClick"),disabled:g,children:[(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M3 12a9 9 0 0 1 15.28-6.36L21 8"}),(0,t.jsx)("path",{d:"M21 3v5h-5"}),(0,t.jsx)("path",{d:"M21 12a9 9 0 0 1-15.28 6.36L3 16"}),(0,t.jsx)("path",{d:"M8 16H3v5"})]}),g?"Refreshing...":"Refresh models"]}),s&&(!e.some($=>$.id===s)||R.has(s))&&(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded bg-accent/50"),onClick:r(()=>{i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:s,children:e.find($=>$.id===s)?.label??s}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-green-500/15 text-green-400 border-green-500/20",children:"current"})]}),u&&u!==s&&(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50"),onClick:r(()=>{n(u),i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:u,children:e.find($=>$.id===u)?.label??u}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-blue-500/15 text-blue-400 border-blue-500/20",children:"detected"})]}),h?.filter($=>$&&$!==u&&$!==s).map($=>{const T=e.find(q=>q.id===$);return(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50"),onClick:r(()=>{n($),i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:$,children:T?.label??$}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-sky-500/15 text-sky-400 border-sky-500/20",children:"config"})]},`detected-${$}`)}),(0,t.jsxs)("div",{className:"max-h-(--sz-240px) overflow-y-auto",children:[o&&(0,t.jsx)("button",{type:"button",className:U("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!s&&"bg-accent"),onClick:r(()=>{n(""),i(!1)},"onClick"),children:"Default"}),A&&(0,t.jsxs)("button",{type:"button",className:"flex items-center justify-between gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",onClick:r(()=>{n(C),i(!1),w("")},"onClick"),children:[(0,t.jsx)("span",{children:"Use manual model"}),(0,t.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:C})]}),O.map($=>(0,t.jsxs)("div",{className:"mb-1 last:mb-0",children:[c&&(0,t.jsxs)("div",{className:"px-2 py-1 text-(length:--text-nano) uppercase tracking-wide text-muted-foreground",children:[$.provider," (",$.entries.length,")"]}),$.entries.map(T=>(0,t.jsx)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",T.id===s&&"bg-accent"),onClick:r(()=>{n(T.id),i(!1)},"onClick"),children:(0,t.jsx)("span",{className:"block w-full text-left truncate",title:T.id,children:c?rBe(T.id):T.label})},T.id))]},$.provider)),E.length===0&&!A&&R.size===0&&(0,t.jsx)("div",{className:"px-2 py-2 space-y-2",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:p?y??"No model detected yet. Enter a provider/model manually.":"No models found."})})]})]})]})})}r(tK,"ModelDropdown");function jQe({value:e,options:s,onChange:n,open:a,onOpenChange:i}){const o=s.find(l=>l.id===e)??s[0];return(0,t.jsx)(Ss,{label:"Thinking effort",hint:vi.thinkingEffort,children:(0,t.jsxs)(sr,{open:a,onOpenChange:i,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsx)("span",{className:U(!e&&"text-muted-foreground"),children:o?.label??"Auto"}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsx)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:s.map(l=>(0,t.jsxs)("button",{className:U("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",l.id===e&&"bg-accent"),onClick:r(()=>{n(l.id),i(!1)},"onClick"),children:[(0,t.jsx)("span",{children:l.label}),l.id?(0,t.jsx)("span",{className:"text-xs text-muted-foreground font-mono",children:l.id}):null]},l.id||"auto"))})]})})}r(jQe,"ThinkingEffortDropdown");function Gfe(e){const s=`paperclip.agent-appearance.${e}`;function n(){try{const l=ole.safeParse(JSON.parse(sessionStorage.getItem(s)??"null"));if(l.success)return l.data}catch{}const o=ZA();try{sessionStorage.setItem(s,JSON.stringify(o))}catch{}return o}r(n,"readDraft");const[a,i]=(0,m.useState)(()=>({key:s,appearance:n()}));return a.key!==s&&i({key:s,appearance:n()}),{appearance:a.appearance,clear(){try{sessionStorage.removeItem(s)}catch{}}}}r(Gfe,"useAgentAppearanceDraft");var HN=null,lI=new Set,QN={subscribe(e){return lI.add(e),()=>{lI.delete(e)}},getSnapshot(){return HN},acquire(e){if(HN)return!1;HN=e;for(const s of lI)s();return!0},release(e){if(HN===e){HN=null;for(const s of lI)s()}}};function oC({agent:e,appearance:s,size:n=256,state:a="idle",muted:i=!1,motion:o="auto",trackingRegion:l,trackingScope:c="region",followCursor:d=!0,followRotation:u=!0,className:h,label:p,name:x}){const g=(0,m.useMemo)(()=>Cw(s??e?.appearance,e?.id),[s,e?.appearance,e?.id]),v=(0,m.useRef)(null),y=(0,m.useRef)(null),j=(0,m.useRef)(null),S=(0,m.useRef)(Symbol("agent-character")),w=(0,m.useSyncExternalStore)(QN.subscribe,QN.getSnapshot,()=>null),[N,_]=(0,m.useState)(!1),[I,C]=(0,m.useState)(!0),[A,R]=(0,m.useState)(!1),[E,O]=(0,m.useState)(!1),L=N&&!I&&!A&&o==="auto"&&a!=="rest";return(0,m.useEffect)(()=>{if(typeof matchMedia!="function"||typeof IntersectionObserver!="function")return;const $=matchMedia("(prefers-reduced-motion: reduce)"),T=r(()=>C($.matches),"change");T(),$.addEventListener("change",T);const q=new IntersectionObserver(B=>_(B[0]?.isIntersecting??!1));return v.current&&q.observe(v.current),()=>{q.disconnect(),$.removeEventListener("change",T)}},[]),(0,m.useEffect)(()=>{L&&w===null&&QN.acquire(S.current),L||QN.release(S.current)},[L,w]),(0,m.useEffect)(()=>()=>QN.release(S.current),[]),(0,m.useEffect)(()=>{if(!L||w!==S.current)return;let $=!1;return O(!1),Promise.all([gc(()=>import("./runtime-IAg0vdY9.js"),__vite__mapDeps([0,1])),gc(()=>import("./definition-P7Pcik2r.js"),__vite__mapDeps([2,3,1]))]).then(([T,q])=>{$||!y.current||(j.current=T.createCharacter(y.current,q.characterDefinition(g,i),{animation:q.animationId(a),trackingRegion:l?.current??v.current??void 0,followCursor:d,followRotation:u,trackingScope:c,displaySize:n,onError:r(()=>R(!0),"onError")}),O(!0))}).catch(()=>{$||R(!0)}),()=>{$=!0,j.current?.destroy(),j.current=null,O(!1)}},[L,w,l,c,n,d,u]),(0,m.useEffect)(()=>{j.current&&gc(()=>import("./definition-P7Pcik2r.js").then($=>{j.current?.setDefinition($.characterDefinition(g,i)),j.current?.setAnimation($.animationId(a))}),__vite__mapDeps([2,3,1]))},[g,i,a,E]),(0,t.jsxs)("span",{ref:v,role:p?"img":void 0,"aria-label":p,"aria-hidden":p?void 0:!0,className:U("relative inline-block shrink-0",o2e[n],h),children:[(0,t.jsx)(hr,{agent:e,appearance:g,size:n<256?256:n,name:x,pose:a,muted:i,className:U("size-full",E&&"invisible")}),(0,t.jsx)("span",{ref:y,className:"absolute inset-0"})]})}r(oC,"AgentCharacter");var wQe=new Set(["claude_local","codex_local","opencode_local","grok_local"]);function Yfe(e,{cloud:s,nativeRunnerEnabled:n}){return s?wQe.has(e):e!=="paperclip_runner"||n}r(Yfe,"isNewAgentAdapterAllowed");var NQe={claude_local:{src:"/brands/claude-color.svg"},codex_local:{src:"/brands/codex-color.svg"},gemini_local:{src:"/brands/adapters/gemini-color.svg"},kimi_local:{src:"/brands/adapters/kimi-color-light.svg",dark:"/brands/adapters/kimi-color.svg"},...Object.fromEntries([["cursor","cursor"],["cursor_cloud","cursor"],["grok_local","grok"],["hermes_local","hermesagent"],["hermes_gateway","hermesagent"],["pi_local","pi"]].map(([e,s])=>[e,{src:`/brands/adapters/${s}.svg`,dark:`/brands/adapters/${s}-dark.svg`}]))};function sK({type:e,className:s="size-6"}){const n=Fm(e).icon,a=NQe[e];return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("img",{src:a.src,className:U("shrink-0 object-contain",a.dark&&"dark:hidden",s),alt:""}),a.dark&&(0,t.jsx)("img",{src:a.dark,className:U("hidden shrink-0 object-contain dark:block",s),alt:""})]}):(0,t.jsx)(n,{className:s})}r(sK,"AdapterMark");function kQe(){const{selectedCompanyId:e}=fs(),{appearance:s}=Gfe(`${e}:new-agent`);return(0,t.jsx)(oC,{appearance:s,state:"sleepy",muted:!0,size:256,className:"size-48",trackingScope:"page"})}r(kQe,"AgentBasicsCharacter");function Jfe({open:e,onClose:s,onContinue:n,initialAdapter:a="",onInvite:i}){const o=(0,m.useId)(),l=!!Vc(),c=ee({queryKey:P.instance.experimentalSettings,queryFn:Tr.getExperimental,enabled:e,retry:!1}),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(a),[x,g]=(0,m.useState)("codex"),[v,y]=(0,m.useState)("name"),{data:j,isPending:S,error:w}=ee({queryKey:P.adapters.all,queryFn:Cm.list,enabled:e}),N=(j??[]).filter(I=>I.loaded&&!I.disabled&&Yfe(I.type,{cloud:l,nativeRunnerEnabled:c.data?.enableNativeRunner===!0})&&!["process","http"].includes(I.type)&&!Fm(I.type).comingSoon),_=N.some(I=>I.type===h);return(0,t.jsx)(Xs,{open:e,onOpenChange:r(I=>{I||s()},"onOpenChange"),children:(0,t.jsxs)(Zs,{className:U("flex max-h-(--sz-calc-18) flex-col gap-0 overflow-hidden p-0 sm:max-w-(--sz-640px)",v==="name"&&"sm:max-w-(--sz-560px)"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-6 py-5 text-xs text-muted-foreground","aria-label":"New agent progress",children:[(0,t.jsx)("span",{className:U(v==="name"&&"font-medium text-foreground"),children:"1. Name"}),(0,t.jsx)(mn,{className:"size-3"}),(0,t.jsx)("span",{className:U(v==="adapter"&&"font-medium text-foreground"),children:"2. Adapter"})]}),(0,t.jsxs)("form",{className:"flex min-h-0 flex-col",onSubmit:r(I=>{I.preventDefault(),d.trim()&&(v==="name"?y("adapter"):_&&n({name:d.trim(),adapterType:h,runnerProvider:x}))},"onSubmit"),children:[(0,t.jsxs)("div",{className:"flex min-h-0 flex-col gap-7 overflow-y-auto px-6 pb-8 sm:px-10",children:[(0,t.jsxs)("div",{className:"flex flex-col items-center gap-4 text-center",children:[e&&(0,t.jsx)(kQe,{}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(rn,{className:"text-3xl font-semibold tracking-tight",children:v==="name"?"Meet your next agent":"Choose an adapter"}),(0,t.jsx)(Dn,{className:"text-base",children:v==="name"?"Start with a name. Make them your own.":`How should ${d.trim()} work?`})]})]}),v==="name"?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("label",{htmlFor:o,className:"text-sm font-medium",children:"Agent name"}),(0,t.jsx)(Rt,{id:o,autoFocus:!0,maxLength:100,placeholder:"e.g. Darnold",value:d,onChange:r(I=>u(I.target.value),"onChange"),className:"h-12 text-base"}),i&&(0,t.jsx)(F,{type:"button",variant:"link",className:"px-0 text-muted-foreground",onClick:i,children:"Invite an external agent"})]}):(0,t.jsxs)("fieldset",{className:"space-y-4",children:[(0,t.jsx)("legend",{className:"sr-only",children:"Adapter"}),S&&(0,t.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Loading adapters…"}),w&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:w.message}),(0,t.jsx)("div",{className:U("grid grid-cols-2 gap-3",N.length!==4&&"sm:grid-cols-3"),children:N.map(I=>{const C=Fm(I.type);return(0,t.jsxs)("label",{className:"relative cursor-pointer",children:[(0,t.jsx)("input",{type:"radio",name:"new-agent-adapter",value:I.type,checked:h===I.type,onChange:r(()=>p(I.type),"onChange"),className:"peer sr-only"}),(0,t.jsxs)("span",{className:U("flex h-full flex-col items-center gap-2 rounded-lg border px-3 py-4 text-center peer-focus-visible:ring-2 peer-focus-visible:ring-ring hover:bg-accent/40",h===I.type?"border-foreground/40 bg-accent":"border-border bg-card"),children:[(0,t.jsx)(sK,{type:I.type}),(0,t.jsx)("span",{className:"text-sm font-medium",children:C.label}),h===I.type&&(0,t.jsx)(xs,{className:"absolute right-2 top-2 size-3.5"})]})]},I.type)})}),_&&h==="paperclip_runner"&&(0,t.jsxs)("label",{className:"flex flex-col gap-2 text-sm font-medium",children:["Runner",(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:x,onChange:r(I=>g(I.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"codex",children:"Codex (app server)"}),(0,t.jsx)("option",{value:"claude",children:"Claude (ACPX)"}),(0,t.jsx)("option",{value:"opencode",children:"OpenCode"})]})]})]})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-4 border-t border-border px-6 py-4",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>v==="name"?s():y("name"),"onClick"),children:v==="name"?"Cancel":(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(sc,{className:"size-4"}),"Back"]})}),(0,t.jsxs)(F,{type:"submit",disabled:!d.trim()||v==="adapter"&&!_,children:[v==="name"?"Choose adapter":"Configure agent",(0,t.jsx)(Zo,{className:"size-4"})]})]})]})]})})}r(Jfe,"AgentBasicsDialog");var SQe={subscription:"Subscription",api:"API"};function CQe({mode:e}){return(0,t.jsx)("span",{className:"relative flex h-4 w-full items-center justify-center overflow-hidden text-(length:--text-micro) text-muted-foreground",children:(0,t.jsx)(Jw,{initial:!1,mode:"sync",children:(0,t.jsx)(Yo.span,{className:"absolute inset-0 flex items-center justify-center whitespace-nowrap",initial:{opacity:0,y:iY},animate:{opacity:1,y:0,transition:J8e},exit:{opacity:0,y:iY,transition:X8e},children:SQe[e]},e)})})}r(CQe,"CredentialTag");function _Qe({source:e,mode:s,selected:n,onSelect:a,buttonRef:i,settling:o}){return(0,t.jsxs)("button",{ref:i,type:"button",role:"radio","aria-checked":n,onClick:a,className:U("flex min-w-0 flex-1 cursor-pointer flex-col items-center gap-1.5 self-stretch rounded-md border p-3","transition-(--tp-border-color-background-color) ease-(--motion-ease-standard)",o?"duration-(--motion-duration-slow)":"duration-(--motion-duration-fast)","outline-none focus-visible:ring-ring/50 focus-visible:ring-(length:--rad-3)",n?"border-foreground/40 bg-accent":"border-border bg-card hover:bg-accent/40"),children:[(0,t.jsx)("span",{className:"flex size-(--sz-30px) shrink-0 items-center justify-center",children:e.icon}),(0,t.jsx)("span",{className:"text-(length:--text-compact) font-medium text-foreground",children:e.label}),(0,t.jsx)(CQe,{mode:s})]})}r(_Qe,"ModelSourceTile");function Xfe({sources:e,mode:s,selectedId:n,onSelect:a,label:i,collapsed:o=!1,settling:l=!1}){const c=(0,m.useRef)(new Map),d=r(h=>{if(e.length===0)return;const p=e.findIndex(g=>g.id===n),x=e[((p===-1?h>0?-1:0:p)+h+e.length)%e.length];a(x.id),c.current.get(x.id)?.focus()},"moveSelection"),u=o?e.filter(h=>h.id===n):e;return(0,t.jsx)("div",{role:"radiogroup","aria-label":i,className:U("flex items-start gap-3",o&&"justify-center"),onKeyDown:r(h=>{o||(h.key==="ArrowRight"||h.key==="ArrowDown"?(h.preventDefault(),d(1)):(h.key==="ArrowLeft"||h.key==="ArrowUp")&&(h.preventDefault(),d(-1)))},"onKeyDown"),children:(0,t.jsx)(Jw,{initial:!1,mode:"popLayout",children:u.map(h=>(0,t.jsx)(Yo.div,{layout:!0,transition:efe,exit:{opacity:0,transition:l7e},className:U("flex min-w-0",o?"w-(--sz-source-tile-two-up)":"flex-1"),children:(0,t.jsx)(_Qe,{source:h,mode:s,selected:h.id===n,onSelect:r(()=>a(h.id),"onSelect"),settling:l,buttonRef:r(p=>{p?c.current.set(h.id,p):c.current.delete(h.id)},"buttonRef")})},h.id))})})}r(Xfe,"ModelSourceTiles");var R4={subscription:"Use API key instead",api:"Use subscription instead"},IQe={subscription:"api",api:"subscription"};function Zfe({mode:e,onChange:s}){return(0,t.jsxs)("button",{type:"button",onClick:r(()=>s(IQe[e]),"onClick"),className:U("group grid cursor-pointer px-3 py-2 text-left text-sm font-medium","rounded-md outline-none focus-visible:ring-ring/50 focus-visible:ring-(length:--rad-3)"),children:[Object.keys(R4).map(n=>(0,t.jsx)("span",{"aria-hidden":!0,className:"invisible col-start-1 row-start-1 whitespace-nowrap",children:R4[n]},n)),(0,t.jsx)(Jw,{initial:!1,mode:"sync",children:(0,t.jsx)(Yo.span,{className:U("col-start-1 row-start-1 justify-self-start whitespace-nowrap","underline decoration-muted-foreground/40 underline-offset-4","text-muted-foreground transition-colors","group-hover:text-foreground group-hover:decoration-foreground/40"),initial:{opacity:0},animate:{opacity:1,transition:VU},exit:{opacity:0,transition:Z8e},children:R4[e]},e)})]})}r(Zfe,"CredentialModeLink");function exe({onBack:e,primaryLabel:s,primaryDisabled:n,loading:a,loadingLabel:i,primaryIcon:o,onPrimary:l}){const c=a&&i?i:s,d=o??(a?"spinner":"arrow");return(0,t.jsxs)("div",{className:"flex items-center justify-between pt-9",children:[e?(0,t.jsxs)(F,{variant:"ghost",size:"lg",className:"rounded-full has-[>svg]:pl-4 has-[>svg]:pr-5",onClick:e,disabled:a,children:[(0,t.jsx)(sc,{className:"mr-1 size-3.5"}),"Back"]}):(0,t.jsx)("span",{}),(0,t.jsx)(Yo.div,{layout:!0,transition:s7e,className:"min-w-0",children:(0,t.jsx)(F,{size:"lg",className:"w-full rounded-full px-6",onClick:l,disabled:n||a,children:(0,t.jsxs)(Yo.span,{className:"flex items-center whitespace-nowrap",initial:{opacity:0},animate:{opacity:1},transition:n7e,children:[d==="spinner"?(0,t.jsx)(ot,{className:"mr-1 size-4 animate-spin"}):null,c,d==="arrow"?(0,t.jsx)(Zo,{className:"ml-1 size-3.5"}):null]},`${c}:${d}`)})})]})}r(exe,"FooterNav");function txe({companyId:e,adapterType:s,environmentId:n,canLogin:a,localEnvironment:i=!1,onConnected:o,onBack:l,testConnection:c,testError:d,managedAccount:u}){const h=ee({queryKey:P.health,queryFn:Ju.get,enabled:i}),p=i&&(h.data?.localAiLoginSupported??h.data?.deploymentMode==="local_trusted"),x=(0,m.useRef)(0);(0,m.useEffect)(()=>()=>{x.current++},[]);const g=r(()=>{x.current++,O(!1),S(!1),N(null),I("preparing")},"cancel"),[v,y]=(0,m.useState)(u?.initialMethod==="api_key"?"api":u?"subscription":null),[j,S]=(0,m.useState)(!1),[w,N]=(0,m.useState)(null),[_,I]=(0,m.useState)("preparing"),C=(0,m.useRef)("ready"),[A,R]=(0,m.useState)(""),[E,O]=(0,m.useState)(!1),[L,$]=(0,m.useState)(null),[T,q]=(0,m.useState)(null),B=s==="claude_local"?"Claude":s==="grok_local"?"Grok":"OpenAI",K=s==="claude_local"?"ANTHROPIC_API_KEY":s==="grok_local"?"XAI_API_KEY":"OPENAI_API_KEY",z=s==="claude_local"?"anthropic":s==="grok_local"?"xai":"openai",D=Fpe(e,K),V=u?{...D,options:[],subscriptions:[],loading:!1}:D,[H,Z]=(0,m.useState)(null),Y=V.subscriptions.length?V.subscriptions.find(ne=>ne.id===(H??V.subscriptions[0]?.id)):void 0,[ie,se]=(0,m.useState)(null),X=V.options.find(ne=>ne.id===(ie??V.options[0]?.id)),le=u?{...V.storedLogin,data:void 0,isPending:!1,isError:!1}:V.storedLogin,oe=(0,m.useRef)(null),te=v??(V.subscriptions.length>0||s==="claude_local"&&!Y&&le.data?"subscription":V.options.length?"api":"subscription"),J=nhe(e,u?.intent??{provider:z,method:"subscription",name:`My ${B} subscription`,ownership:"personal",agentIds:[],allAgents:!0},p&&te==="subscription"&&!Y&&!le.data,{allowHostClaude:h.data?.deploymentMode==="local_trusted"}),Q=ee({queryKey:P.agents.authSignal(e,s,n),queryFn:r(()=>Wt.getAdapterAuthSignal(e,s,n??void 0),"queryFn"),retry:!1,enabled:!u});async function pe(){if(E||u?.disabled)return;const ne=++x.current;O(!0),$(null);try{if(u){if(te==="subscription"&&!p)return;const he=oe.current??await(te==="api"?ou.create(e,{...u.intent,method:"api_key",apiKey:A.trim()}):J.connect(u.intent));oe.current=he,R(""),ne===x.current&&u.onComplete({...he,method:te==="api"?"api_key":"subscription"});return}let ae=te==="api"?X?X.aiConnection?{env:{},aiConnection:X.aiConnection}:{env:{[K]:X.binding}}:T??{env:{},credentials:{[K]:A.trim()}}:{...Y?.aiConnection?{aiConnection:Y.aiConnection}:{},env:Y?.binding?{CODEX_HOME:Y.binding}:{},...s==="claude_local"&&!Y&&le.data?{env:sj(),applyStoredClaudeLogin:!0}:{}};if(te==="subscription"&&p&&!Y&&!le.data&&(oe.current??=await J.connect(),ae={env:{},aiConnection:{provider:z,method:"subscription",mode:"responsible_user"}}),ae.credentials&&(await ou.create(e,{provider:z,method:"api_key",name:`My ${B} API`,ownership:"personal",apiKey:ae.credentials[K],agentIds:[],allAgents:!0}),ae={env:{},aiConnection:{provider:z,method:"api_key",mode:"responsible_user"}}),ne!==x.current)return;te==="api"&&(R(""),X||q(ae));const me=await c(ae);if(ne!==x.current)return;me?o(ae):$("The provider did not respond. Check the connection and try again.")}catch(ae){if(ne!==x.current)return;u&&R(""),$(ae instanceof Error?ae.message:"Could not connect to the provider.")}finally{ne===x.current&&O(!1)}}r(pe,"connect");const re=te==="subscription"&&a&&n&&!Y&&!V.loading&&!le.data&&(!!u||Q.data?.status!=="present"||H==="");return(0,t.jsxs)("div",{className:"min-w-0 max-w-full",children:[(0,t.jsx)(Xfe,{label:"Connect your model provider",sources:[{id:s,label:B,icon:(0,t.jsx)(sK,{type:s})}],mode:te,selectedId:j?s:null,collapsed:j,onSelect:r(()=>{u?.disabled||S(!0)},"onSelect")}),!j&&!u?.fixedMethod&&(0,t.jsx)("div",{className:"-ml-3 mt-1",children:(0,t.jsx)(Zfe,{mode:te,onChange:r(ne=>{oe.current=null,y(ne),$(null)},"onChange")})}),!j&&V.options.length>0&&(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:[V.options.length," saved API"," ",V.options.length===1?"key available":"keys available","."]}),te==="subscription"&&V.subscriptions.length>0&&(0,t.jsx)(Nj,{options:V.subscriptions,value:Y?.id??"",onChange:Z,loading:!1,error:!1,kind:"subscription",disabled:E}),(0,t.jsx)(Yo.div,{initial:!1,animate:{height:j?"auto":0,opacity:j?1:0},transition:{height:id,opacity:U5},className:"overflow-hidden",children:j&&(0,t.jsx)("div",{className:"pt-5",children:te==="api"?(0,t.jsxs)(K5,{instruction:V.options.length?"Choose a saved API key or enter a new one":`Provide your ${B} API key to connect`,children:[(0,t.jsx)(Nj,{...V,value:X?.id??"",disabled:E,onChange:r(ne=>{se(ne),R(""),q(null),$(null)},"onChange")}),!X&&(0,t.jsx)(V5,{label:"API key",masked:!0,autoFocus:!0,value:A,placeholder:T?"Key entered. Retry the connection.":"Enter API key here",onChange:r(ne=>{se(""),R(ne),q(null)},"onChange"),onSubmit:r(()=>{pe()},"onSubmit"),disabled:E})]}):re?(0,t.jsx)(eK,{companyId:e,adapterType:s,environmentId:n,chrome:"onboarding",aiConnection:u?.intent??{provider:z,method:"subscription",name:`My ${B} subscription`,ownership:"personal",agentIds:[],allAgents:!0},autoStart:!0,onStored:r(()=>{},"onStored"),onPromptReady:r(ne=>{N(ne),I(ae=>ne?ae==="preparing"?"ready":ae:"preparing")},"onPromptReady"),onCodeSubmitted:r(()=>{C.current=_==="waiting"?"waiting":"ready",I("connecting")},"onCodeSubmitted"),onSubmitFailed:r(()=>{I(ne=>ne==="connecting"?C.current:ne)},"onSubmitFailed"),onConnected:r(ne=>{if(u){if(!ne){$("The login did not return a saved connection. Try again.");return}const me=x.current;I("connecting"),ou.loginResult(e,ne).then(he=>{me===x.current&&u.onComplete({...he,method:"subscription"})}).catch(()=>{me===x.current&&(I("ready"),$("Could not retrieve the saved connection. Go back and retry."))});return}const ae={env:{},aiConnection:{provider:z,method:"subscription",mode:"responsible_user"}};q(ae),o(ae)},"onConnected")}):Y?null:p&&!le.data?(0,t.jsx)(WU,{adapterType:s,login:{...J,retry:r(()=>{$(null),J.retry()},"retry")}}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:le.data?"Use your saved Claude subscription for this agent.":a?"Use the existing provider connection for this environment.":"This environment does not support browser sign-in. Choose a sign-in environment or connect with an API key."})})}),te==="subscription"&&le.isError&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:"Could not check your saved Claude subscription. Try again."}),L&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:d??L}),i&&h.isError&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:"Could not prepare sign-in. Reload this page to try again."}),(0,t.jsx)(exe,{onBack:r(()=>{j?g():l()},"onBack"),primaryLabel:j&&re?_==="waiting"?"Waiting for code":_==="connecting"?"Connecting":`Sign in to ${B}`:E?"Connecting":te==="subscription"&&(le.data||Y)?"Use saved subscription":te==="api"&&X?"Use saved API key":"Connect",primaryDisabled:u?.disabled||!!u&&te==="subscription"&&!a&&!p||i&&h.isPending||J.preparing||!!J.error||!u&&Q.isPending||V.loading||s==="claude_local"&&le.isPending||!j||!!re&&(!w||_!=="ready")||te==="api"&&!A.trim()&&!T&&!X,loading:E,primaryIcon:j&&re?_==="ready"?"none":"spinner":void 0,onPrimary:r(()=>{if(re){if(!w||_!=="ready")return;window.open(w,"_blank","noreferrer,noopener"),I("waiting")}else pe()},"onPrimary")})]})}r(txe,"AgentProviderConnection");function IT(e){return e.provider==="openrouter"?(0,t.jsx)(RQe,{...e}):(0,t.jsx)(AQe,{...e})}r(IT,"AiConnectionCredentialStep");function AQe({companyId:e,provider:s,initialMethod:n,fixedMethod:a,connectionId:i,name:o,ownership:l,agentIds:c,allAgents:d,environmentId:u,onComplete:h,onCancel:p}){const[x,g]=(0,m.useState)(o),[v,y]=(0,m.useState)(),j=Ht(),S=ee({queryKey:P.environments.list(e),queryFn:r(()=>_i.list(e),"queryFn")}),w=ee({queryKey:P.environments.capabilities(e),queryFn:r(()=>_i.capabilities(e),"queryFn")}),N=ee({queryKey:P.instance.settings,queryFn:Tr.get}),_=ee({queryKey:P.instance.experimentalSettings,queryFn:Tr.getExperimental}),I=ee({queryKey:P.instance.generalSettings,queryFn:Tr.getGeneral}),C=ZU(I.data?.executionMode,S.data??[]);let A=null,R;try{A=C.forced?C.kubernetesEnvironment?.id??null:iw({agentDefaultEnvironmentId:u??v,instanceDefaultEnvironmentId:N.data?.defaultEnvironmentId,localDefaultEnvironmentId:lw(S.data),managedSandboxOnly:_.data?.enableManagedSandboxOnly,managedSandboxEnvironmentId:ow(S.data),visibleEnvironmentIds:S.data?.map(K=>K.id)})}catch(K){R=K instanceof Error?K.message:"Could not resolve the sign-in environment."}const E=(S.data??[]).filter(K=>K.status==="active"&&(K.driver==="local"||K.driver==="sandbox"&&typeof K.config.provider=="string"&&w.data?.sandboxProviders?.[K.config.provider]?.supportsLoginPty===!0));!C.forced&&!u&&!v&&!E.some(K=>K.id===A)&&(A=E[0]?.id??null);const O=S.data?.find(K=>K.id===A),L=typeof O?.config.provider=="string"?O.config.provider:"",$=O?.driver==="sandbox"&&w.data?.sandboxProviders?.[L]?.supportsLoginPty===!0,T=[S,w,N,_,I].some(K=>K.isPending),q=R??[S,w,N,_,I].find(K=>K.error)?.error?.message,B={provider:s,method:"subscription",name:x,ownership:l,agentIds:c,allAgents:d,connectionId:i};return(0,t.jsxs)("div",{className:"mx-auto w-full min-w-0 max-w-xl space-y-6",children:[(0,t.jsxs)("label",{className:"block space-y-2 text-sm",children:["Connection name",(0,t.jsx)(Rt,{value:x,onChange:r(K=>g(K.target.value),"onChange"),disabled:!!i})]}),!u&&!C.forced&&E.length>1&&(0,t.jsxs)(Ra,{value:A??"",onValueChange:y,children:[(0,t.jsx)(Aa,{"aria-label":"Sign-in environment",children:(0,t.jsx)(_a,{placeholder:"Sign-in environment"})}),(0,t.jsx)(Ia,{children:E.map(K=>(0,t.jsx)(yn,{value:K.id,children:K.name},K.id))})]}),q&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:q}),T?(0,t.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Preparing sign-in…"}):(0,t.jsx)(txe,{companyId:e,adapterType:s==="anthropic"?"claude_local":s==="xai"?"grok_local":"codex_local",environmentId:A,canLogin:$,localEnvironment:O?.driver==="local",onBack:p,onConnected:r(()=>{},"onConnected"),testConnection:r(async()=>!1,"testConnection"),managedAccount:{intent:B,initialMethod:n,fixedMethod:a||!!i,disabled:T||!!q||!x.trim(),onComplete:r(K=>{j.invalidateQueries({queryKey:["ai-connections",e]}),h(K)},"onComplete")}},A??"local")]})}r(AQe,"SubscriptionConnectionStep");function RQe({companyId:e,provider:s,connectionId:n,name:a,ownership:i,agentIds:o,allAgents:l,onComplete:c,onCancel:d}){const[u,h]=(0,m.useState)(a),[p,x]=(0,m.useState)(""),g=Ht(),v=ye({mutationFn:r(()=>ou.create(e,{provider:s,method:"api_key",name:u,ownership:i,agentIds:o,allAgents:l,connectionId:n,apiKey:p}),"mutationFn"),onSuccess:r(y=>{g.invalidateQueries({queryKey:["ai-connections",e]}),c({...y,method:"api_key"})},"onSuccess"),onSettled:r(()=>x(""),"onSettled")});return(0,t.jsxs)("div",{className:"mx-auto w-full min-w-0 max-w-xl space-y-4",children:[(0,t.jsxs)("label",{className:"block space-y-2 text-sm",children:["Connection name",(0,t.jsx)(Rt,{value:u,onChange:r(y=>h(y.target.value),"onChange"),disabled:!!n})]}),v.error&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:v.error.message}),(0,t.jsx)(rfe,{providerName:"OpenRouter",value:p,onChange:x,onSubmit:r(()=>v.mutate(),"onSubmit"),disabled:v.isPending,placeholder:"Enter API key here",autoFocus:!0}),(0,t.jsxs)("div",{className:"flex justify-between gap-2",children:[(0,t.jsx)(F,{variant:"ghost",onClick:d,children:"Cancel"}),(0,t.jsx)(F,{disabled:!u.trim()||!p.trim()||v.isPending,onClick:r(()=>v.mutate(),"onClick"),children:v.isPending?"Connecting…":"Connect"})]})]})}r(RQe,"ApiKeyConnectionStep");var TQe=new RegExp(`\\b(${["mcp","server","profile","policy","gateway","transport","stdio","endpoint"].join("|")})s?\\b`,"gi");function sxe(e){return e.replace(TQe,"").replace(/\s{2,}/g," ").replace(/\s+([.,])/g,"$1").trim()}r(sxe,"sanitizeProsumerCopy");var EQe={zapier:{tagline:"Reach 9,000+ apps your team already uses.",short:"Reach 9,000+ apps from your agents."},github:{tagline:"Read code and pull requests, comment on issues.",short:"Read code and pull requests, comment on issues."},slack:{tagline:"Send and read messages in your team's channels.",short:"Send and read messages in your channels."},notion:{tagline:"Read and update pages in your workspace.",short:"Read and update pages in your workspace."},railway:{tagline:"Inspect services, read logs, and manage deployments.",short:"Connect Railway for deployments, logs, and container access."},posthog:{tagline:"Explore product usage, errors, flags, and experiments.",short:"Sign in with PostHog. Project pinning and access controls are optional."},linear:{tagline:"Create, update and read tickets.",short:"Create, update and read tickets."},"google-sheets":{tagline:"Read and update selected spreadsheets.",short:"Read spreadsheets or update the files you choose."},gmail:{tagline:"Read mail and create drafts for your review.",short:"Read mail and create drafts for your review."},"google-drive":{tagline:"Find, read, and create files in Drive.",short:"Find, read, and create files in Drive."},"google-docs":{tagline:"Read and update documents.",short:"Read and update documents."},"google-slides":{tagline:"Read and update presentations.",short:"Read and update presentations."},"google-calendar":{tagline:"Review calendars and manage events.",short:"Review calendars and manage events."},"google-chat":{tagline:"Read conversations and send messages.",short:"Read conversations and send messages."},"google-people":{tagline:"Look up contacts and people in your directory.",short:"Look up contacts and people in your directory."},"google-workspace-search":{tagline:"Search across your Google workspace.",short:"Search across your Google workspace."},hubspot:{tagline:"Look up contacts and update deal stages.",short:"Look up contacts and update deal stages."},intercom:{tagline:"Read and reply to customer conversations.",short:"Read and reply to customer conversations."},figma:{tagline:"Read files and post comments on frames.",short:"Read files and post comments on frames."},stripe:{tagline:"Read customers, invoices, and payouts.",short:"Read customers, invoices, and payouts."},context7:{tagline:"Look up up-to-date docs for your libraries.",short:"Look up up-to-date docs for your libraries."}},PQe={tagline:"Give your agents access to this app.",short:"Give your agents access to this app."};function nxe(e,s){const n=EQe[e];if(n)return n;if(s){const a=sxe(s);if(a)return{tagline:a,short:a}}return PQe}r(nxe,"appCopyFor");function VY(e,s,n){return n<=1?`Your ${e} key`:sxe(s)||`Your ${e} key`}r(VY,"credentialFieldLabel");var MQe=1500;function nf(e=MQe){const[s,n]=(0,m.useState)("idle"),a=(0,m.useRef)(null),i=(0,m.useRef)(0);(0,m.useEffect)(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);const o=(0,m.useCallback)(async l=>{const c=++i.current;let d="copied";try{await Gr(l)}catch{d="failed"}return i.current!==c||(n(d),a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{i.current===c&&(n("idle"),a.current=null)},e)),d},[e]);return{status:s,copied:s==="copied",failed:s==="failed",copy:o}}r(nf,"useCopyAction");function nK(){const e=Nc()?.pushToast;return(0,m.useCallback)(async(s,n="Copied")=>{try{return await Gr(s),e?.({title:n,tone:"success",dedupeKey:`copy:${n}`}),!0}catch{return e?.({title:"Couldn’t copy to clipboard",body:"Select and copy the value manually.",tone:"error",dedupeKey:"copy-failed"}),!1}},[e])}r(nK,"useCopyToast");var DQe="/cloud/connections/handoff",LQe="/cloud/connections/reauth",AT="paperclip.cloud-oauth-handoff.v1",dx=class extends Error{static{r(this,"OAuthHandoffError")}code;constructor(e,s){super(e),this.code=s,this.name="OAuthHandoffError"}};function rK(e){if(e===void 0)return null;if(!e||typeof e!="object"||Array.isArray(e))throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");const s=e;if(s.kind!=="paperclip_cloud"||typeof s.session!="string"||s.session.length<16||s.session.length>512||!/^[A-Za-z0-9_-]+$/.test(s.session))throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");return{kind:"paperclip_cloud",session:s.session}}r(rK,"parseHandoff");function $Qe(e,s){return e===404||s==="SESSION_NOT_AVAILABLE"?new dx("This sign-in expired. Start the connection again.","expired"):e===401||e===403?new dx("Paperclip Cloud could not authorize this connection for your account.","forbidden"):new dx("Paperclip Cloud couldn’t prepare secure sign-in. Try again.","unavailable")}r($Qe,"handoffFailure");async function OQe(e,s){const n=s.request??fetch;let a,i;for(let o=0;o<2;o+=1)try{if(a=await n(DQe,{method:"POST",headers:{"content-type":"application/json",accept:"application/json"},credentials:"include",body:JSON.stringify({session:e}),signal:s.signal}),a.status<500||o===1)return a}catch(l){if(s.signal?.aborted||l instanceof DOMException&&l.name==="AbortError")throw l;if(i=l,o===1)break}if(a)return a;throw new dx(i instanceof Error?i.message:"Paperclip Cloud couldn’t prepare secure sign-in. Try again.","unavailable")}r(OQe,"postCloudHandoff");function FQe(e,s){if(typeof e!="string"||typeof window>"u")return null;try{const n=new URL(e,window.location.origin);return n.origin!==window.location.origin||n.pathname!==LQe||n.username||n.password||n.hash||n.searchParams.size!==1||n.searchParams.get("session")!==s?null:{kind:"reauthentication",url:n.toString(),host:n.host}}catch{return null}}r(FQe,"exactReauthenticationTarget");async function uw(e,s={}){const n=rK(e.handoff);if(!n){const l=iT(e.authorizationUrl);if(!l.ok)throw new dx(l.message,"invalid_handoff");return{kind:"authorization",url:l.url,host:l.host}}const a=await OQe(n.session,s),i=await a.json().catch(()=>null);if(!a.ok){if(i?.error==="RECENT_LOGIN_REQUIRED"){const l=FQe(i.reauthenticationUrl,n.session);if(l)return l}throw $Qe(a.status,i?.error)}const o=iT(typeof i?.authorizationUrl=="string"?i.authorizationUrl:void 0);if(!o.ok)throw new dx("Paperclip Cloud returned an invalid provider sign-in address.","invalid_handoff");return{kind:"authorization",url:o.url,host:o.host}}r(uw,"prepareOAuthNavigation");function lC(e,s=window.sessionStorage){const n=rK({kind:"paperclip_cloud",session:e});if(!n)throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");const a={version:1,session:n.session,savedAt:Date.now()};s.setItem(AT,JSON.stringify(a))}r(lC,"savePendingCloudHandoff");function BQe(e=window.sessionStorage){const s=e.getItem(AT);if(!s)return null;try{const n=JSON.parse(s);if(n.version!==1||typeof n.savedAt!="number"||Date.now()-n.savedAt>9e5)throw new Error("expired");return rK({kind:"paperclip_cloud",session:n.session})}catch{return e.removeItem(AT),null}}r(BQe,"readPendingCloudHandoff");function WY(e=window.sessionStorage){e.removeItem(AT)}r(WY,"clearPendingCloudHandoff");function Y5({host:e,className:s}){return(0,t.jsxs)("div",{className:U("flex flex-wrap items-center gap-2 text-xs",s),children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 font-medium text-amber-700 dark:text-amber-400",children:[(0,t.jsx)(wl,{className:"h-3 w-3"}),"Unverified server"]}),e?(0,t.jsx)("span",{className:"font-mono text-muted-foreground",children:e}):null]})}r(Y5,"UnverifiedServerBadge");function J5(e){return!!(e&&Yoe({...e,methods:e.methods.filter(s=>(s.purpose??"tool")!=="channel"&&s.transport!=="chat_sdk")}))}r(J5,"appSupportsToolCatalogSetup");var qQe=F_e.filter(e=>Uoe(e).some(s=>Ep(s))).map(e=>e.slug);function zQe(e){return qQe.some(s=>s===e)}r(zQe,"isMcpDirectOAuthConnectSlug");function IF(e,s){const n=new URLSearchParams({source:e});return s&&n.set("intent",s),`/apps/connect?${n.toString()}`}r(IF,"appSourceConnectHref");function UQe(e,s){return`/apps/connect?${new URLSearchParams({source:e,resume:s}).toString()}`}r(UQe,"appSourceResumeHref");function T4(e){return e?`/apps/vercel-connect?${new URLSearchParams({source:e}).toString()}`:"/apps/vercel-connect"}r(T4,"vercelConnectSourceHref");function KQe(e){return e.serviceSlug??e.appKey??e.sourceSlug??void 0}r(KQe,"resolveAppsConnectRouteKey");function VQe(e,{chatConnectorsEnabled:s=!1}={}){if(e.get("byo")==="1")return!!(e.get("reconnect")?.trim()&&e.get("applicationId")?.trim()&&e.get("link")?.trim());const n=e.get("source")??"",a=VC(n);return!s&&a?.methods.some(i=>i.transport==="chat_sdk")&&!a.methods.some(i=>(i.purpose??"tool")!=="channel"&&i.transport!=="chat_sdk")?!1:V6(n)&&e.get("reconnect")?.trim()?!0:s?Yoe(a):J5(a)}r(VQe,"canEnterAppsConnect");var E4=" for the organization",WQe=" for the company";function HY(e,s){const n=e.trim();if(s!=="organization")return n;const a=n.toLocaleLowerCase();return a.endsWith(E4)?n:a.endsWith(WQe)?`${n.slice(0,n.length-16).trimEnd()}${E4}`:`${n}${E4}`}r(HY,"connectionNameForGrantKind");function HQe(e){switch(e){case"active":return"Connected";case"needs_reauthorization":return"Needs attention";case"expired":return"Expired";case"revoked":return"Revoked";default:return"Not connected"}}r(HQe,"grantStatusLabel");function QQe(e){switch(e){case"active":return"connected";case"needs_reauthorization":case"expired":return"attention";case"revoked":return"inactive";default:return"missing"}}r(QQe,"grantStatusTone");function GQe(e,s={}){const n=e?.providerTenant?.name?.trim();return n||(e?.kind==="user"?s.subjectLabel?.trim()||"Connected account":e?.kind==="agent"?s.subjectLabel?.trim()||"Dedicated account":"Shared credential")}r(GQe,"grantAccountLabel");function YQe(e){return new Set((e?.members??[]).filter(s=>s.subjectType==="user").map(s=>s.subjectId))}r(YQe,"audienceUserIds");function JQe(e){return e.find(s=>s.kind==="organization"&&s.isDefault)??e.find(s=>s.kind==="organization")??null}r(JQe,"organizationGrant");function XQe(e,s){return s?e.find(n=>n.kind==="user"&&n.subjectUserId===s)??null:null}r(XQe,"personalGrantFor");function ZQe(e,s){if(!s)return null;const n=e.find(a=>a.userId===s);return n&&(n.name?.trim()||n.email?.trim())||null}r(ZQe,"memberLabel");var QY=0;function AF(){return QY+=1,{id:`header-${QY}`,name:"",value:""}}r(AF,"newCustomHeaderRow");function fS(e){try{return new URL(e).host||null}catch{return null}}r(fS,"endpointHost");function eGe(e=window.location.origin){const s=new URL("/api/tools/oauth/callback",e),n=s.hostname.toLowerCase().replace(/^\[|\]$/g,"");return s.protocol==="http:"&&(n==="127.0.0.1"||n==="::1")&&(s.hostname="localhost"),s.toString()}r(eGe,"oauthCallbackUrlForBrowser");function P4(e){try{const s=new URL(e);return`${s.host.replace(/^www\./,"")}${s.pathname==="/"?"":s.pathname.replace(/\/+$/,"")}`.slice(0,160)||null}catch{return null}}r(P4,"defaultGenericMcpName");function GY(e,s){const n=s?.trim()||"Paperclip couldn't connect to that address. Check it and try again.";switch(e){case"mcp_remote_url_missing":case"mcp_remote_url_invalid":return{title:"That doesn't look like a server address",body:"Paste the full address, starting with https:// — for example https://mcp.example.com/mcp.",focus:"url"};case"remote_http_private_endpoint":return{title:"That address is inside a private network",body:"This Paperclip is reachable from the internet, so it won't call addresses on your local network. Use the server's public address instead.",focus:"url"};case"remote_http_dns_failed":return{title:"We couldn't find that host",body:"The address didn't resolve. Check the spelling, or confirm the server is published on the internet.",focus:"url"};case"mcp_header_rejected":return{title:"Paperclip can't send that header",body:n,focus:"credentials"};case"tool_access_name_conflict":return{title:"Paperclip couldn’t name this connection",body:"Try connecting again.",focus:"none"};case"oauth_challenge":return{title:"This server wants a credential",body:"It asked us to authenticate but didn't offer a sign-in Paperclip can complete on its own. Add the key or headers its docs list under Advanced authentication.",focus:"credentials"};case"oauth_manual_client_required":case"oauth_manual_client_rebinding_required":return{title:"This server needs sign-in details you create yourself",body:"Register Paperclip in the provider's settings, then add the client ID and secret it gives you under Advanced authentication.",focus:"credentials"};case"oauth_redirect_origin_unsupported":case"oauth_redirect_uri_invalid":return{title:"This Paperclip needs a public HTTPS address first",body:"Sign-in sends the operator back to Paperclip, so this instance has to be reachable over HTTPS. Ask your Paperclip admin to configure it.",focus:"deployment"};case"runtime_error":return{title:"We couldn't reach that server",body:"Nothing answered at that address. Confirm the server is running and the address is right, then try again.",focus:"url"};default:return{title:"Paperclip couldn't connect",body:n,focus:"none"}}}r(GY,"genericConnectGuidance");function rxe(e){const s=new Set;for(const n of e){const a=n.name.trim();if(!a&&!n.value.trim())continue;const i=y_e(a);if(!i.ok)return TW(a,i.reason);const o=E_e(n.value);if(!o.ok)return TW(a,o.reason);if(!n.value.trim())return`Add a value for "${a}", or remove the row.`;const l=a.toLowerCase();if(s.has(l))return`"${a}" is listed twice.`;s.add(l)}return null}r(rxe,"customHeaderError");function tGe(e){const s={},n=e.keyValue.trim();if((e.authMode==="bearer"||e.authMode==="auto"&&e.needsKey)&&n&&(s["credentials.authorization"]=n),e.authMode==="custom_headers")for(const l of e.headers){const c=l.name.trim();!c||!l.value.trim()||(s[`headers.${c}`]=l.value)}const a=e.name.trim(),i=e.oauthClientId.trim(),o=e.oauthClientSecret.trim();return{link:e.link,...a?{name:a}:{},...e.authMode==="auto"?{}:{authMode:e.authMode},...Object.keys(s).length>0?{credentialValues:s}:{},...e.authMode==="oauth"&&i?{oauthClient:{clientId:i,...o?{clientSecret:o}:{}}}:{}}}r(tGe,"genericConnectPayload");function sGe(e){return e.link.trim()?e.authMode==="auto"?!e.needsKey||e.keyValue.trim().length>0:e.authMode==="bearer"?e.keyValue.trim().length>0:e.authMode==="custom_headers"?e.headers.filter(s=>s.name.trim()&&s.value.trim()).length>0&&rxe(e.headers)===null:!0:!1}r(sGe,"canSubmitGenericConnect");function mw(e){const s=new Set;let n=!1;for(const a of e??[])a.targetType==="company"?n=!0:a.targetType==="agent"&&s.add(a.targetId);return{onAll:n,agentIds:s}}r(mw,"installStateFrom");function axe(e,s){return e.onAll||e.agentIds.has(s)}r(axe,"isAgentInstalled");function ixe(e,s){return s.onAll?[{targetType:"company",targetId:e}]:[...s.agentIds].map(n=>({targetType:"agent",targetId:n}))}r(ixe,"installPayload");var nGe="Has access — tick to load its tools into this agent's context.";function oxe(e){return`paperclip.connector-enrollment-access:${e}`}r(oxe,"enrollmentAccessStorageKey");function rGe(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const s=e;if(typeof s.companyId!="string"||!s.companyId.trim()||!(s.grantKind==="user"||s.grantKind==="agent"||s.grantKind==="organization")||s.installChoice!=="specific"&&s.installChoice!=="all"||!Array.isArray(s.agentIds)||s.agentIds.some(a=>typeof a!="string"||!a.trim()))return!1;const n=new Set(s.agentIds);return n.size!==s.agentIds.length?!1:s.grantKind==="agent"?s.installChoice==="specific"&&n.size===1:s.installChoice==="all"?n.size===0:n.size>0}r(rGe,"validEnrollmentAccessState");function aGe(e,s,n){try{window.sessionStorage.setItem(oxe(s),JSON.stringify({...n,companyId:e}))}catch{}}r(aGe,"saveEnrollmentAccessState");function iGe(e){const s=oxe(e);try{const n=window.sessionStorage.getItem(s);if(window.sessionStorage.removeItem(s),!n)return null;const a=JSON.parse(n);return rGe(a)?a:null}catch{return null}}r(iGe,"consumeEnrollmentAccessState");function YY(e){if(!e)return null;try{const s=new URL(e);return s.protocol==="https:"&&s.hostname.toLowerCase()==="github.com"?s.toString():null}catch{return null}}r(YY,"githubRecoveryUrl");function JY(e,s){return e==="denied"?"Authorization was cancelled or declined. Your saved connection was not changed.":s==="github_installation_required"?"GitHub access is required. Install Paperclip and grant at least one repository, then try again.":"Authorization did not complete. Your saved connection is still here, so you can try again."}r(JY,"oauthCallbackErrorMessage");var oGe={access:"access",key:"setup",success:"complete"};function XY(e){return e.requestedAppKey?e.resumeConnectionId||e.routeStage==="setup"?"key":"access":e.hasPrefilledLink||e.zapierSource?"access":"gallery"}r(XY,"requestedConnectionInitialStep");function lGe(e){const s=e.galleryApps.find(a=>a.slug===e.requestedAppKey);if(s)return s;if(!e.reconnectConnection)return null;const n=e.applications.find(a=>a.id===e.reconnectConnection?.applicationId);return yx(n)!==e.requestedAppKey?null:V6(e.requestedAppKey)}r(lGe,"requestedConnectionEntry");function cGe(e){return!e.reconnectConnection||!e.reconnectApplication||e.reconnectConnection.applicationId!==e.reconnectApplication.id?!1:e.requestedAppKey?yx(e.reconnectApplication)===e.requestedAppKey:e.byo&&e.applicationId===e.reconnectApplication.id}r(cGe,"retainedReconnectMatches");function dGe(e){return e.credentialSource==="vercel_connect"&&!e.available&&!e.retainedReconnectMatches}r(dGe,"isVercelConnectUnavailable");function uGe(e){return e.available===!1&&!(e.reconnectConnectionId&&e.reconnectSourceMatches)}r(uGe,"isConnectionDefinitionUnavailable");function mGe(e){return!e.hasRequestedEntry||e.supportedMethodCount===0||e.unsupportedOAuth||e.vercelUnavailable||e.definitionUnavailable?e.reconnectConnectionId?"reconnect_unavailable":"fallback":"ready"}r(mGe,"requestedConnectionSetupResolution");function ZY(e,s,n,a){const i=oGe[s]??"setup",o=new URLSearchParams({source:e,stage:i});return a?.resumeConnectionId&&o.set("resume",a.resumeConnectionId),a?.reconnectConnectionId&&o.set("reconnect",a.reconnectConnectionId),a?.interactionId&&o.set("intent",a.interactionId),a?.connectionMethodKey&&o.set("method",a.connectionMethodKey),`${n==="vercel_connect"?"/apps/vercel-connect":"/apps/connect"}?${o.toString()}`}r(ZY,"appConnectHref");function cI(e,s){if(!s)return e;const[n,a=""]=e.split("?",2),i=new URLSearchParams(a);return i.set("intent",s),`${n}?${i.toString()}`}r(cI,"withConnectionIntent");var eJ=["Pick app","Access","Add your key"],tJ={gallery:0,access:1,key:2},hGe={access:0,key:1},pGe=["Access","Add MCP URL"],fGe=["Access","Sign in"];function M4(e,s=!1){return s&&e?.auth!=="none"&&(!e?.grantKinds||e.grantKinds.includes("user"))?"user":e?.grantKinds?.length===1||e?.grantKinds&&!e.grantKinds.includes("organization")?e.grantKinds[0]:"organization"}r(M4,"defaultGrantKindFor");function xGe(e){const s=e.config?.oauth;if(!s||typeof s!="object"||Array.isArray(s))return;const n=s.connectorSubjectAgentId;return typeof n=="string"?n:void 0}r(xGe,"configuredAgentIdentity");function Tk(e,s){const n=typeof s=="string"?s:s?.key;return e?.slug==="google-sheets"&&n==="local"}r(Tk,"isGoogleSheetsRobotMethod");function GN(e){return e?Object.fromEntries([...e.tenantFields??[],...e.extensionFields??[]].filter(s=>s.defaultValue!==void 0).map(s=>[s.key,s.defaultValue])):{}}r(GN,"defaultMethodConfig");function qy(e,s){if(!e)return[];const n=R1(e);return s==="vercel_connect"?n.filter(a=>!!a.credentialSources?.vercelConnect):n}r(qy,"connectionMethodsForCredentialSource");function R1(e){return Uoe(e).filter(s=>(s.purpose??"tool")!=="channel")}r(R1,"availableToolConnectionMethods");function dI(e,s){const n=R1(e);return s?n.find(a=>a.key===s)??null:H6(n)}r(dI,"availableToolConnectionMethod");function Sj(e){const s=H6(e);return e.length===1||s?.capabilityProfile||s?.grantKinds?.includes("agent")?s:null}r(Sj,"recommendedSetupConnectionMethod");function sJ(e){return Sj(e?e.methods.filter(s=>(s.purpose??"tool")==="tool"&&(s.oauthStrategy==="paperclip_cloud_connector"||s.oauthStrategy==="paperclip_id_connector")):[])}r(sJ,"recommendedManagedConnectorMethod");function nJ(e){if(!e)return!1;const s=R1(e),n=s.length===1?s[0]:null;return!!(n&&Ep(n)&&!cIe(n))}r(nJ,"canUseAutomaticOAuthFastPath");function rJ(e){if(!e)return null;const s=R1(e),n=s.length===1?s[0]:null;return n&&Ep(n)?n:null}r(rJ,"automaticOAuthMethod");function gGe(e){const s=e.metadata;if(!s)return null;const n=s.sourceTemplateKey??s.galleryKey;return typeof n=="string"?n:null}r(gGe,"appSourceSlug");function bGe(e){const s=e.config?.sourceTemplateKey??e.transportConfig.sourceTemplateKey;return typeof s=="string"?s:null}r(bGe,"connectionSourceSlug");function aJ(e,s,n,a={}){if(!e)return null;const i=new Set(s.filter(o=>o.status!=="archived"&&gGe(o)===e&&(!a.applicationId||o.id===a.applicationId)).map(o=>o.id));return n.find(o=>{const l=a.applicationId?o.applicationId===a.applicationId:i.has(o.applicationId)||bGe(o)===e;return o.status!=="archived"&&(!a.draftOnly||o.status==="draft")&&o.authKind==="oauth"&&l})??null}r(aJ,"reusableOAuthConnection");function lxe(e,s,n){if(e.origin!==s||!e.data||typeof e.data!="object")return null;const a=e.data;return a.type!=="paperclip.connection-intent.oauth"||a.interactionId!==n?null:a.outcome==="connected"||a.outcome==="declined"||a.outcome==="failed"?a.outcome:null}r(lxe,"readConnectionIntentOAuthOutcome");function X5(e={}){const[s]=Ri(),n=ja(),{selectedCompanyId:a}=fs(),i=she(),o=e.interactionId||s.get("intent")||void 0,l=e.serviceSlug||s.get("source")||n.appKey||s.get("appKey"),c=(0,m.useMemo)(()=>{if(o&&uj(l))try{return sessionStorage.getItem(`paperclip:mcp-intent-draft:${a}:${o}`)}catch{}return null},[o,a,l]),d=e.configuredConnection?.id||s.get("resume")||s.get("reconnect")||c,u=!!(d&&(!l||uj(l))),h=ee({queryKey:["tools","connection",d],queryFn:r(()=>us.getConnection(d),"queryFn"),enabled:u}),p=l||h.data?.config?.sourceTemplateKey,x=s.get("method")||h.data?.config?.connectionMethodKey;return u&&h.isPending?(0,t.jsx)("p",{className:"p-6 text-sm text-muted-foreground",children:"Loading connection…"}):u&&h.isError?(0,t.jsxs)("div",{role:"alert",className:"space-y-3 p-6",children:[(0,t.jsx)("p",{children:"Could not load this connection. Your saved access and credentials have not changed."}),(0,t.jsx)(F,{variant:"outline",onClick:r(()=>{h.refetch()},"onClick"),children:"Try again"})]}):!e.byoOnly&&(e.credentialSource??"paperclip_vault")==="paperclip_vault"&&uj(p)&&(!x||JA(p,x))?i.loaded?i.enabled?(0,t.jsx)(Nqe,{...e,interactionId:o,providerId:p,connection:h.data},`${o||"page"}:${p}`):(0,t.jsx)("p",{role:"status",className:"p-6 text-sm text-muted-foreground",children:"Enable MCP aggregators in Settings → Experimental to set up this connection."}):(0,t.jsx)("p",{className:"p-6 text-sm text-muted-foreground",children:"Loading connection settings…"}):(0,t.jsx)(vGe,{...e})}r(X5,"ConnectionSetupFlow");function vGe({byoOnly:e=!1,credentialSource:s="paperclip_vault",host:n="page",serviceSlug:a,requestedAgentId:i,interactionId:o,forceNewConnection:l=!1,existingConnections:c=[],configuredConnection:d,onUseExisting:u,onComplete:h,onOAuthDeclined:p,aiConnection:x,onPhaseChange:g,onCancel:v,renderCredentialStep:y}={}){const j=Wn(),S=(0,m.useCallback)((Fe,Lt)=>{n==="page"&&(Lt?j(Fe,Lt):j(Fe))},[n,j]),w=ja(),{selectedCompany:N,selectedCompanyId:_}=fs(),{enabled:I}=Tx(),{setBreadcrumbs:C}=$n(),{pushToast:A}=Mi(),[R]=Ri(),E=o?.trim()||R.get("intent")?.trim()||null,O=w.appKey??R.get("appKey")??void 0,L=R.get("source")?.trim()||null,$=l||R.get("new")==="1",T=R.get("stage")?.trim()||null,q=R.get("method")?.trim()||null,B=R.get("resume")?.trim()||null,K=R.get("oauth"),z=R.get("code"),D=YY(R.get("installation_url")),V=YY(R.get("management_url")),H=d?.id??(R.get("reconnect")?.trim()||null),Z=R.get("identity")==="user"?"user":R.get("identity")==="organization"?"organization":null,Y=s==="vercel_connect",ie=a??L,se=s==="paperclip_vault"&&zQe(ie)?ie:null,X=KQe({serviceSlug:a,appKey:O,sourceSlug:L}),le=(a??L??O)==="zapier",oe=le?void 0:X,te=!!d||n==="page"&&(e||R.get("byo")==="1"),[J]=(0,m.useState)(()=>n==="page"&&R.get("cloud_connector")==="enrolled"&&oe?iGe(oe):null),[Q]=(0,m.useState)(()=>{const Fe=R.get("link")?.trim()??"";return{link:/^https?:\/\//i.test(Fe)?Fe:"",name:d?.name??R.get("name")?.trim()??"",applicationId:d?.applicationId??(R.get("applicationId")?.trim()||void 0)}}),[pe,re]=(0,m.useState)(()=>XY({requestedAppKey:oe,routeStage:T,resumeConnectionId:B,hasPrefilledLink:!!Q.link,zapierSource:le})),[ne,ae]=(0,m.useState)(null),[me,he]=(0,m.useState)(""),[Ie,de]=(0,m.useState)(Q.link),[ve,Te]=(0,m.useState)(Q.name||(le?"Zapier":"")),[fe,Ce]=(0,m.useState)(!1),[Xe,Oe]=(0,m.useState)(""),[tt,ce]=(0,m.useState)("auto"),[$e,mt]=(0,m.useState)(()=>[AF()]),[it,Ke]=(0,m.useState)(""),[Ge,rt]=(0,m.useState)(""),[jt,st]=(0,m.useState)(!1),[Nt,at]=(0,m.useState)(null),[Ee,Ne]=(0,m.useState)(!1),[He,St]=(0,m.useState)({}),[Ft,ts]=(0,m.useState)(""),[Ot,Be]=(0,m.useState)(""),[Ve,ut]=(0,m.useState)(""),[qe,Gt]=(0,m.useState)(x&&x.mode!=="responsible_user"?`ai-${x.method}`:""),[We,$t]=(0,m.useState)({}),[Dt,Cs]=(0,m.useState)(""),[ze,ct]=(0,m.useState)(null),[Pt,ke]=(0,m.useState)(null),[ys,wt]=(0,m.useState)({}),[Ut,De]=(0,m.useState)("all"),[Se,nt]=(0,m.useState)(new Set),[xt,ms]=(0,m.useState)(()=>new Set(J?.agentIds??(i?[i]:[]))),[ht,zt]=(0,m.useState)(J?.grantKind??Z??(i?"user":"organization")),[as,Me]=(0,m.useState)(J?.installChoice??(i?"specific":"all")),bt=!!(B&&(K==="failed"||K==="denied")),[ft,Ye]=(0,m.useState)(bt?"error":"entry"),[gs,Ct]=(0,m.useState)(()=>bt?JY(K,z):null),[os,_t]=(0,m.useState)(null),Xt=(0,m.useRef)(!1),zs=(0,m.useRef)(!1),hs=(0,m.useRef)(null),[Ws,Cn]=(0,m.useState)(null),Zn=(0,m.useRef)(null),[kn,tn]=(0,m.useState)(null),[Tn,Bs]=(0,m.useState)(null),an=(0,m.useRef)(null),[ca,Sr]=(0,m.useState)(c.length>0&&!!u),[gn,rr]=(0,m.useState)(null),[wr,ar]=(0,m.useState)(null),[sa,_r]=(0,m.useState)(null),Cr=(0,m.useCallback)(()=>{n!=="dialog"||Zn.current?.closed===!1||(Zn.current=window.open("about:blank","paperclip-connection-oauth","popup,width=720,height=760,resizable=yes,scrollbars=yes"))},[n]),Wr=(0,m.useCallback)(Fe=>{if(n!=="dialog"){jc(Fe);return}Bs(Fe);const Lt=Zn.current;if(!Lt||Lt.closed){Ye("error"),Ct("Paperclip couldn’t open the sign-in window. Open sign-in in a new tab to continue."),g?.("needs_retry");return}Lt.location.assign(Fe),Lt.focus()},[n,g]),Yn=(0,m.useCallback)(()=>{Zn.current=null,Ct(null),Ye("redirecting"),g?.("authorizing")},[g]);(0,m.useEffect)(()=>{if(n!=="dialog"||ft!=="redirecting")return;const Fe=window.setInterval(()=>{Zn.current?.closed&&(Ye("error"),Ct("The sign-in window closed. If authorization did not finish, try again."),Bs(null),g?.("needs_retry"))},1e3);return()=>window.clearInterval(Fe)},[n,ft,g]);const ir=(0,m.useCallback)(async Fe=>{an.current?.abort();const Lt=new AbortController;an.current=Lt;try{const Ts=await uw(Fe,{signal:Lt.signal});if(Ts.kind==="reauthentication"){const _n=n==="dialog"?Zn.current:window;if(!_n||_n.closed||!Fe.handoff)throw new Error("Paperclip couldn’t preserve this sign-in while refreshing your account.");lC(Fe.handoff.session,_n.sessionStorage),Ye("starting")}else _t(Ts.host),Ye("redirecting");Wr(Ts.url)}catch(Ts){if(Lt.signal.aborted)return;Ye("error"),Ct(Ts instanceof Error?Ts.message:"Paperclip couldn’t start secure sign-in. Try again."),g?.("needs_retry")}finally{an.current===Lt&&(an.current=null)}},[n,g,Wr]);(0,m.useEffect)(()=>()=>an.current?.abort(),[]),(0,m.useEffect)(()=>{if(n!=="dialog"||!E)return;const Fe=r(Lt=>{const Ts=lxe(Lt,window.location.origin,E);if(Ts==="connected"){Ye("entry"),Bs(null),h?.({resolvedByCallback:!0});return}if(Ts==="declined"){Ye("error"),Ct("Authorization was cancelled. You can try again."),g?.("needs_retry");return}Ts==="failed"&&(Ye("error"),Ct("Authorization did not complete. Try again when you’re ready."))},"receiveOAuthOutcome");return window.addEventListener("message",Fe),()=>window.removeEventListener("message",Fe)},[E,n,h,p]),(0,m.useEffect)(()=>{if(n!=="dialog"||E||!kn)return;let Fe=!1,Lt=!1;const Ts=window.setInterval(async()=>{if(Lt||Fe)return;const _n=Zn.current;if(!_n||_n.closed){tn(null),Ye("error"),Ct("The sign-in window closed. Try again to finish connecting GitHub.");return}let Hr;try{Hr=new URL(_n.location.href)}catch{return}if(!(Hr.origin!==window.location.origin||!Hr.pathname.includes(kn))){if(Hr.searchParams.has("oauth")){tn(null),Ye("error"),Ct("Authorization did not complete. Finish setup in the sign-in window or try again.");return}if(Hr.searchParams.get("success")==="1"){Lt=!0;try{const Fa=await us.getConnection(kn);!Fe&&Fa.status==="active"&&(tn(null),_n.close(),h?.({connectionId:Fa.id}))}catch{Fe||(tn(null),Ye("error"),Ct("Could not confirm the connection. Try again."))}finally{Lt=!1}}}},1e3);return()=>{Fe=!0,window.clearInterval(Ts)}},[E,kn,n,h]);const Ir=r(()=>{ce("auto"),mt([AF()]),Ke(""),rt(""),st(!1),at(null),Ne(!1)},"resetGenericAuthState"),dr=r(Fe=>{if(n==="page"&&!E&&s==="paperclip_vault"&&uj(Fe.slug)){S(`/apps/connect?source=${Fe.slug}`);return}if(Fe.slug==="zapier"){ae(null),he(""),de(""),Te("Zapier"),Ce(!1),Oe(""),Ir(),St({}),ke(null),re("access"),S(cI("/apps/connect?source=zapier",E));return}if(s==="paperclip_vault"&&nJ(Fe)){S(IF(Fe.slug,E));return}ae(Fe),he(Fe.name),de(""),Te(""),Ce(!1),Oe(""),Ir(),St({}),ts(""),Be(""),ut("");const Lt=Sj(qy(Fe,s));Gt(Lt?.key??""),$t(GN(Lt)),Cs(""),ct(null),ke(null),ms(new Set(i?[i]:[])),Me(i?"specific":"all"),zt($s??M4(Lt,!!i)),re("access"),S(s==="vercel_connect"?cI(T4(Fe.slug),E):IF(Fe.slug,E))},"useMatchedGalleryEntry"),da=r(()=>{re("gallery"),S(cI(s==="vercel_connect"?T4():e?"/apps/byo":"/apps",E))},"backToGallery");(0,m.useEffect)(()=>{if(n==="page")return C([{label:"Connectors",href:"/apps"},{label:Y?"Vercel Connect":e?"Connect your own tool":"Connect an app"}]),()=>C([])},[e,n,C,Y]);const Ls=ee({queryKey:P.apps.gallery(_??"__none__"),queryFn:r(()=>us.listGallery(_),"queryFn"),select:(0,m.useCallback)(Fe=>E?{...Fe,apps:Fe.apps.map(Lt=>({...Lt,methods:Lt.methods.filter(Ts=>x?Ts.ai?.provider===x.provider&&(x.mode==="responsible_user"||Ts.ai.method===x.method):Ts.transport!=="runtime_auth")})).filter(Lt=>Lt.methods.length>0)}:Fe,[E,x?.provider,x?.method,x?.mode]),enabled:!!_}),Hn=(0,m.useMemo)(()=>(Ls.data?.apps??[]).filter(Fe=>I||!Fe.methods.some(Lt=>Lt.transport==="chat_sdk")||J5(Fe)),[Ls.data,I]),ur=oe?V6(oe):null,gr=!!ur?.methods.some(Fe=>Fe.oauthStrategy==="paperclip_cloud_connector"||Fe.oauthStrategy==="paperclip_id_connector"),gt=!!ne?.methods.some(Fe=>Fe.oauthStrategy==="paperclip_cloud_connector"||Fe.oauthStrategy==="paperclip_id_connector"),ks=ne&&gr&&!gt?sJ(ur):null,[Es,Je]=(0,m.useState)(null),qt=ee({queryKey:["cloud-connector","enrollment"],queryFn:r(()=>us.getCloudConnectorEnrollment(),"queryFn"),refetchInterval:Es?2e3:!1,enabled:!!(_&&gr&&!gt)}),[Hs,Ks]=(0,m.useState)(null),Ys=(0,m.useCallback)(()=>{Zn.current?.close(),Zn.current=null,Je(null)},[]),Ar=(0,m.useCallback)(()=>{!_||!oe||aGe(_,oe,{grantKind:ht,installChoice:as,agentIds:as==="specific"?[...xt]:[]})},[ht,xt,as,oe,_]),Ps=(0,m.useCallback)(Fe=>{const Lt=iT(Fe);if(!Lt.ok){Ys(),Ks(Lt.message);return}if(n==="dialog"){Je(Lt.url);const Ts=Zn.current;Ts&&!Ts.closed?(Ts.location.assign(Lt.url),Ts.focus()):Ks("Open authorization in a new tab to continue.");return}jc(Lt.url)},[n,Ys]);(0,m.useEffect)(()=>{!Es||qt.data?.status!=="active"||(Ys(),Ks(null),Ls.refetch())},[Es,qt.data?.status,Ls.refetch,Ys]);const on=ye({mutationFn:r(()=>us.startCloudConnectorEnrollment(_,N?.name,oe?ZY(oe,"key",s,{resumeConnectionId:B,reconnectConnectionId:H,interactionId:E})+(n==="dialog"?"&enrollment_host=dialog":""):void 0),"mutationFn"),onSuccess:r(Fe=>{if(!Fe.verificationUrl){Ys(),Ks("Paperclip Cloud did not return an enrollment link. Try again.");return}Ps(Fe.verificationUrl)},"onSuccess"),onError:r(Fe=>{Ys(),Ks(Fe instanceof Error?Fe.message:"Paperclip couldn’t reach Paperclip Cloud. Try again.")},"onError")}),jn=ee({queryKey:P.tools.applications(_??"__none__"),queryFn:r(()=>us.listApplications(_),"queryFn"),enabled:!!_&&(!!se||!!B||!!H),refetchOnMount:"always"}),Ms=ee({queryKey:P.tools.connections(_??"__none__"),queryFn:r(()=>us.listConnections(_),"queryFn"),enabled:!!_&&(!!se||!!B||!!H),refetchOnMount:"always"}),nn=(0,m.useMemo)(()=>l?null:aJ(se,jn.data?.applications??[],Ms.data?.connections??[],$?{applicationId:Q.applicationId,draftOnly:!0}:{}),[jn.data,Ms.data,$,se,Q.applicationId,l]),wn=(0,m.useMemo)(()=>H?(Ms.data?.connections??[]).find(Fe=>Fe.id===H)??null:null,[Ms.data,H]),bs=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(!d||!Ms.isFetchedAfterMount||!wn||bs.current===wn.id)return;const Fe=wn.config?.url??wn.transportConfig?.url??wn.transportConfig?.serverUrl??wn.config?.serverUrl;typeof Fe!="string"||!/^https?:\/\//i.test(Fe)||(bs.current=wn.id,de(Lt=>Lt||Fe))},[d,Ms.isFetchedAfterMount,wn]);const Js=(0,m.useMemo)(()=>wn?(jn.data?.applications??[]).find(Fe=>Fe.id===wn.applicationId)??null:null,[jn.data,wn]),Vn=cGe({requestedAppKey:oe,byo:te,applicationId:Q.applicationId,reconnectConnection:wn,reconnectApplication:Js}),Ln=(0,m.useMemo)(()=>B?(Ms.data?.connections??[]).find(Fe=>Fe.id===B)??null:null,[Ms.data,B]),rs=Ln??wn,$s=rs?rs.credentialPolicy==="per_user"?"user":rs.credentialPolicy==="per_agent"?"agent":"organization":Z,Jn=Ln?.authKind==="oauth"?Ln:nn,En=nn?nn.credentialPolicy==="per_user"?"user":nn.credentialPolicy==="per_agent"?"agent":"organization":null,bn=$s??En;(0,m.useEffect)(()=>{bn&&zt(bn)},[bn]);const On=(0,m.useMemo)(()=>Ie&&!ne?jR(Ie,Hn):null,[ne,Hn,Ie]),Qn=ne?dI(ne,qe||null):null,Fr=Qn&&Ep(Qn)?Qn:rJ(ne),Ta=s==="paperclip_vault"&&Fr?ne:null,Br=s==="paperclip_vault"&&nJ(ne)?ne:null,ii=!!se&&(!jn.isFetchedAfterMount||!Ms.isFetchedAfterMount),be=r(Fe=>{re(Fe),ne&&S(ZY(ne.slug,Fe,s,{connectionMethodKey:ne.methods.find(Lt=>Lt.key===qe)?.ai?qe:void 0,resumeConnectionId:B,reconnectConnectionId:H,interactionId:E}))},"setAppStep"),je=ye({mutationFn:r(Fe=>us.startOAuth(Fe.id,{asCurrentUser:Fe.credentialPolicy==="per_user",...Fe.credentialPolicy==="per_agent"?{asAgentId:xGe(Fe)??[...xt][0]}:{},...E?{interactionId:E}:{}}),"mutationFn"),onSuccess:r(Fe=>{ir(Fe)},"onSuccess"),onError:r(Fe=>{const Lt=Fe instanceof Nn&&Fe.body&&typeof Fe.body=="object"?Fe.body.details:null;Ye("error"),g?.("needs_retry"),Ct(Lt?.code==="invalid_grant"?"Your authorization expired or was revoked. Reconnect to continue.":Fe instanceof Error?Fe.message:"Paperclip couldn’t start secure sign-in. Try again.")},"onError")}),kt=je.mutate,ws=(0,m.useCallback)(Fe=>{g?.("authorizing"),Cr(),n==="dialog"&&!E&&tn(Fe.id),kt(Fe)},[kt,g,Cr,n,E]),ln=r(async Fe=>{if(i)return;const Lt=ixe(_,(bn??ht)!=="agent"&&as==="all"?{onAll:!0,agentIds:new Set}:{onAll:!1,agentIds:xt});await us.putConnectionInstalls(Fe,Lt)},"applyAccessInstalls"),Fn=bn??ht,Nr=ye({mutationFn:r(async Fe=>{const Lt=Fe??ne;let Ts;if(Lt){const _n=bn??ht,Hr=dI(Lt,qe||null),Fa=Tk(Lt,Hr)?LO(Dt).ids:[],qr=me.trim(),xo=HY(qr||Lt.name,_n);Ts=await us.connectApp(_,{galleryKey:Lt.slug,...qe?{connectionMethodKey:qe}:{},name:xo,credentialSource:s,...s==="paperclip_vault"?{credentialValues:He}:{},...s==="vercel_connect"?{vercelConnect:{connector:Ve.trim()}}:{},...Ft.trim()?{oauthClient:{clientId:Ft.trim(),...Ot?{clientSecret:Ot}:{}}}:{},configValues:Tk(Lt,Hr)?{allowedSpreadsheetIds:Fa}:Object.keys(We).length>0?We:void 0,applicationId:Q.applicationId,...B?{resumeConnectionId:B}:H?{reconnectConnectionId:H}:{},..._n!=="organization"?{grantKind:_n}:{},..._n==="agent"?{subjectAgentId:[...xt][0]}:{}})}else{const _n=tGe({link:Ie,name:ve,authMode:tt,needsKey:fe,keyValue:Xe,headers:$e,oauthClientId:it,oauthClientSecret:Ge}),Hr=HY(_n.name??P4(Ie)??"Custom app",Fn);Ts=await us.connectApp(_,{..._n,...H?{reconnectConnectionId:H}:{},...le||On?.slug==="zapier"?{galleryKey:"zapier",connectionMethodKey:"generated-url"}:{},name:Hr,applicationId:Q.applicationId,...Fn!=="organization"?{grantKind:Fn}:{},...Fn==="agent"?{subjectAgentId:[...xt][0]}:{}})}return Ts.auth?.kind==="oauth"&&!B&&!H&&await ln(Ts.connectionId),Ts},"mutationFn"),onSuccess:r(Fe=>{if(Fe.auth?.kind==="oauth"){if(ke(Fe),Fe.auth.manualClientRequired){at(GY("oauth_manual_client_required",null)),ce("oauth"),st(!0),Ne(!1);return}if(n==="dialog"||E){Ye("starting"),Ne(!ne),ws(Fe.connection);return}const Ts=Fe.auth.startUrl?.trim();if(!Ts){Ye("starting"),Ne(!0),ws(Fe.connection);return}Ne(!0),ir({authorizationUrl:Ts,handoff:Fe.auth.handoff});return}at(null),ke(Fe);const Lt={};for(const Ts of Fe.actions.readOnly)Lt[Ts.catalogEntryId]=!0;for(const Ts of Fe.actions.canMakeChanges)Lt[Ts.catalogEntryId]=!0;wt(Lt),ss.mutate({result:Fe,enabled:Lt})},"onSuccess"),onError:r(Fe=>{const Lt=Fe instanceof Nn&&Fe.body&&typeof Fe.body=="object"?Fe.body.details:null;if(Ta){Ye("error"),g?.("needs_retry"),Ct(Lt?.code==="invalid_grant"?"Your authorization expired or was revoked. Reconnect to continue.":Fe instanceof Error?Fe.message:"Paperclip couldn’t start secure sign-in. Try again.");return}if(!ne&&Ie){const Ts=typeof Lt?.code=="string"?Lt.code:null,_n=GY(Ts,Fe instanceof Error?Fe.message:null);at(_n),Ne(!1),_n.focus==="credentials"&&st(!0);return}A({title:"Couldn’t connect",body:Fe instanceof Error?Fe.message:"Please check your key and try again.",tone:"error"})},"onError")}),we=Nr.mutate,Yt=(0,m.useCallback)(Fe=>{const Lt=Fe??ne;(Lt?dI(Lt,qe||null):null)?.auth==="oauth"&&Cr(),we(Fe)},[qe,ne,we,Cr]);(0,m.useEffect)(()=>{if(!oe||Ls.isLoading||!Ls.data||H&&(!Ms.isFetchedAfterMount||!jn.isFetchedAfterMount))return;const Fe=lGe({requestedAppKey:oe,galleryApps:Ls.data.apps,reconnectConnection:wn,applications:jn.data?.applications??[]}),Lt=!!Fe?.methods.some(Bn=>Bn.oauthStrategy==="paperclip_cloud_connector"||Bn.oauthStrategy==="paperclip_id_connector");if(gr&&!Lt&&qt.isLoading)return;const Ts=qy(Fe,s),_n=x??(wn?.connectionPurpose==="ai"?_W.safeParse(wn.config?.ai).data:void 0),Hr=Ts.find(Bn=>_n?Bn.ai?.provider===_n.provider&&(!("mode"in _n)||_n.mode!=="responsible_user")&&Bn.ai.method===_n.method:Bn.key===q)??(gr&&!Lt?sJ(ur):null)??Sj(Ts),Fa=Ts.length===1?Ts[0]:null,qr=s==="paperclip_vault"&&!!rJ(Fe),xo=dGe({credentialSource:s,available:Ls.data.credentialSources?.vercelConnect.available===!0,retainedReconnectMatches:!!(H&&Vn)}),Ue=Ts.length===1&&Fa?.auth==="oauth"&&!Ep(Fa)&&!gR(Fa),pt=uGe({available:Fe?.availability?.available,reconnectConnectionId:H,reconnectSourceMatches:Vn}),vs=mGe({reconnectConnectionId:H,hasRequestedEntry:!!Fe,supportedMethodCount:Ts.length,unsupportedOAuth:Ue,vercelUnavailable:xo,definitionUnavailable:pt});if(vs!=="ready"){if(ae(null),re("gallery"),vs==="reconnect_unavailable"&&H){_r(H);return}S(cI(s==="vercel_connect"?T4():"/apps/connect",E),{replace:!0});return}if(_r(null),!!Fe){if(ne?.slug!==Fe.slug){ae(Fe),he(Fe.name),de(""),Te(""),Ce(!1),Oe(""),St({}),ts(""),Be(""),ut(""),Gt(Hr?.key??""),$t(GN(Hr)),Cs(""),ct(null),ke(null);const Bn=J?.companyId===_?J:null;zt($s??Bn?.grantKind??M4(Hr,!!i)),ms(new Set(Bn?.agentIds??(i?[i]:[]))),Me(Bn?.installChoice??(i?"specific":"all")),re(XY({requestedAppKey:oe,routeStage:T,resumeConnectionId:B,hasPrefilledLink:!!Q.link,zapierSource:le}))}else gt!==Lt&&(ae(Fe),Gt(Hr?.key??""),$t(GN(Hr)));if(!(qr&&(!jn.isFetchedAfterMount||!Ms.isFetchedAfterMount))&&!(qr&&zs.current)&&qr&&(jn.isError||Ms.isError)){Ye("error"),Ct("Paperclip couldn’t check for an existing connection. Try again."),re("key");return}}},[x,q,jn.isError,jn.isFetchedAfterMount,jn.data,Ms.isError,Ms.isFetchedAfterMount,qt.data?.configured,qt.isLoading,qe,s,ne?.slug,gt,Ls.data,Ls.isLoading,S,$s,wn,H,Vn,B,ur,oe,i,J,T,le]),(0,m.useEffect)(()=>{wn?.connectionPurpose==="ai"&&pe==="access"&&re("key")},[wn?.connectionPurpose,pe]),(0,m.useEffect)(()=>{hs.current=null,Cn(null)},[B]),(0,m.useEffect)(()=>{if(!Ln||!ne||Ln.status!=="draft"||hs.current===Ln.id)return;const Fe=Ln.config&&typeof Ln.config=="object"?Ln.config:{},Lt=typeof Fe.sourceTemplateKey=="string"?Fe.sourceTemplateKey:null;if(Lt&&Lt!==ne.slug)return;const Ts=typeof Fe.connectionMethodKey=="string"?Fe.connectionMethodKey:null,_n=Ts?qy(ne,s).find(Fa=>Fa.key===Ts)??null:null;if(he(Ln.name||ne.name),_n){Gt(_n.key);const Fa=Fe.methodConfig&&typeof Fe.methodConfig=="object"?Fe.methodConfig:{};$t({...GN(_n),...Object.fromEntries(Object.entries(Fa).filter(qr=>typeof qr[1]=="string"||typeof qr[1]=="boolean"))})}const Hr=Fe.oauth&&typeof Fe.oauth=="object"?Fe.oauth:null;Hr?.clientRegistrationSource==="manual"&&typeof Hr.clientId=="string"&&ts(Hr.clientId),K==="failed"||K==="denied"?(Ye("error"),Ct(JY(K,z))):(Ye("entry"),Ct(null)),re("key"),hs.current=Ln.id,Cn(Ln.id)},[s,ne,z,K,Ln]);const ss=ye({mutationFn:r(async Fe=>{const{result:Lt,enabled:Ts}=Fe,_n=Object.entries(Ts).filter(([,Ue])=>Ue).map(([Ue])=>Ue),Hr=new Set(Array.isArray(Lt.suggestedDefaults.askFirstRiskLevels)?Lt.suggestedDefaults.askFirstRiskLevels.filter(Ue=>typeof Ue=="string"):[]),Fa=Lt.actions.canMakeChanges.filter(Ue=>Ts[Ue.catalogEntryId]&&Hr.has(Ue.riskLevel)).map(Ue=>Ue.catalogEntryId),qr=as==="all"?"all_agents":{agentIds:Array.from(xt)},xo=await us.finishApp(_,Lt.connectionId,{enabledCatalogEntryIds:_n,askFirstCatalogEntryIds:Fa,access:qr,...i?{preserveExistingAccess:!0}:{}});return await ln(Lt.connectionId),xo},"mutationFn"),onSuccess:r((Fe,Lt)=>{be("success"),h?.({connectionId:Lt.result.connectionId})},"onSuccess"),onError:r(Fe=>{be("access"),A({title:"Couldn’t finish setup",body:Fe instanceof Error?Fe.message:"Please try again.",tone:"error"})},"onError")});if(!_)return(0,t.jsx)("div",{className:"p-6 text-sm text-muted-foreground",children:"Select an organization to connect apps."});if((B||H)&&(Ms.isError||jn.isError))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Couldn’t load connection setup"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip couldn’t check the retained connection. The retained connection was not changed."}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",onClick:r(async()=>{const[Fe,Lt]=await Promise.all([Ms.refetch(),jn.refetch()]);!Fe.isError&&!Lt.isError&&(Ct(null),Ye("entry"))},"onClick"),children:"Try again"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]})]});if(B&&Ms.isFetchedAfterMount&&!Ln)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This setup can’t be resumed"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"The saved connection no longer exists or is not available to this organization."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if(H&&Ms.isFetchedAfterMount&&jn.isFetchedAfterMount&&(!wn||!Vn))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This connection can’t be reconnected"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:wn?"This reconnect link does not match the retained connection's provider.":"The retained connection no longer exists or is not available to this organization."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if((B||H)&&Ls.isError)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Couldn’t load connection setup"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip couldn’t load the provider details needed to restore this connection. The retained connection was not changed."}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",onClick:r(()=>{Ls.refetch()},"onClick"),children:"Try again"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]})]});if(H&&sa===H)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This connection can’t be reconnected"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip no longer has a supported setup method for this retained connection. The retained connection was not changed."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if(B&&(!Ms.isFetchedAfterMount||Ls.isLoading||!ne||Ws!==Ln?.id))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl space-y-4","aria-label":"Loading saved connection setup",children:[(0,t.jsx)(fn,{className:"h-8 w-48"}),(0,t.jsx)(fn,{className:"h-40 w-full rounded-xl"})]});if(H&&(!Ms.isFetchedAfterMount||!jn.isFetchedAfterMount||Ls.isLoading||oe&&!ne))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl space-y-4","aria-label":"Loading retained connection setup",children:[(0,t.jsx)(fn,{className:"h-8 w-48"}),(0,t.jsx)(fn,{className:"h-40 w-full rounded-xl"})]});if(ca&&u)return(0,t.jsxs)("div",{className:"max-w-5xl","data-testid":"connection-existing-choice",children:[(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsxs)("h1",{className:"text-2xl font-bold tracking-tight",children:["Use an existing ",oe?"connection":"app connection"]}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Reuse a connection without changing who already has access, or connect a new one."})]}),(0,t.jsx)(lU,{choices:c.map(Fe=>({id:Fe.id,name:Fe.name,description:Fe.status==="active"&&Fe.enabled?"Ready to use":"Setup needs attention"})),pendingId:gn,onSelect:r(async Fe=>{rr(Fe),ar(null);try{await u(Fe)}catch(Lt){ar(Lt instanceof Error?Lt.message:"Couldn’t use this connection."),rr(null)}},"onSelect")}),wr?(0,t.jsx)(ri,{tone:"danger",className:"mt-4",children:wr}):null,(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>Sr(!1),"onClick"),children:d?"Review connection setup":"Connect new"}),v?(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:v,children:"Cancel"}):null]})]});const Pn=!!(Ta&&pe==="key"&&(Br||ft!=="entry")),cr=!!(pe==="key"&&ne&&gr&&!gt&&qt.data?.configured===!0),Oa=!!(pe==="key"&&ne&&gr&&!gt&&(qt.isLoading||qt.isError||qt.data?.configured!==!0));if(Pn&&Ta)return(0,t.jsx)(RF,{entry:Ta,resuming:!!B,phase:ft,error:gs,recoveryActions:z==="github_installation_required"?{installationUrl:D,managementUrl:V}:void 0,authorizationHost:os,authorizationUrl:Tn,onOpenAuthorization:Yn,onRetry:r(async()=>{Ct(null),Ye("starting");const Fe=Pt?.connection??Jn;if(Fe){ws(Fe);return}zs.current=!0;try{const[Lt,Ts]=await Promise.all([jn.refetch(),Ms.refetch()]);if(Lt.isError||Ts.isError){Ye("error"),Ct("Paperclip couldn’t check for an existing connection. Try again.");return}const _n=(B?(Ts.data?.connections??[]).find(Hr=>Hr.id===B&&Hr.authKind==="oauth")??null:null)??aJ(se,Lt.data?.applications??[],Ts.data?.connections??[],$?{applicationId:Q.applicationId,draftOnly:!0}:{});if(!Xt.current&&!B){_n&&zt(_n.credentialPolicy==="per_user"?"user":_n.credentialPolicy==="per_agent"?"agent":"organization"),Ye("entry"),Ct(null),re("access");return}_n?ws(_n):Nr.mutate(Ta)}finally{zs.current=!1}},"onRetry"),onBack:r(()=>{an.current?.abort(),Ye("entry"),Ct(null),be("access")},"onBack"),onCancel:r(()=>{an.current?.abort(),(v??(()=>S("/apps")))()},"onCancel")});if(Ee&&!ne&&Ie&&pe==="key")return(0,t.jsx)(RF,{identity:{name:ve.trim()||fS(Ie)||"this server",unverifiedHost:fS(Ie)},steps:{labels:eJ,activeIndex:tJ.key},phase:ft,error:gs,authorizationHost:os,authorizationUrl:Tn,onOpenAuthorization:Yn,onRetry:r(()=>{Ct(null);const Fe=Pt?.connection;if(Fe){Ye("starting"),ws(Fe);return}Ne(!1),Ye("entry")},"onRetry"),onBack:r(()=>{an.current?.abort(),Ne(!1),Ye("entry"),Ct(null)},"onBack"),onCancel:r(()=>{an.current?.abort(),(v??(()=>S("/apps")))()},"onCancel")});const si=Pt?.application.name??ne?.name??(ve.trim()||P4(Ie)||"this app"),Kt=qy(ne,s),ls=ks?[ks]:Kt,dn=Y?Hn.filter(Fe=>qy(Fe,s).length>0):Hn,na=le?Ls.data?.apps.find(Fe=>Fe.slug==="zapier")??null:null,Xn=(wn?.connectionPurpose==="ai"?_W.safeParse(wn.config?.ai).data:void 0)??ne?.methods.find(Fe=>Fe.key===qe)?.ai??(!qe&&ne?.methods.every(Fe=>Fe.ai)?ne.methods[0]?.ai:void 0),Yr=ne?y?.({app:ne,name:me||ne.name,grantKind:Fn,agentIds:[...xt],allAgents:as==="all",onBack:r(()=>be("access"),"onBack")})??(Xn&&_?(0,t.jsx)(t.Fragment,{children:(0,t.jsx)(IT,{companyId:_,provider:Xn.provider,fixedMethod:!!(x&&x.mode!=="responsible_user"),initialMethod:wn?.connectionPurpose==="ai"?(wn.config?.ai).method:Xn.method,connectionId:wn?.connectionPurpose==="ai"?wn.id:void 0,name:wn?.connectionPurpose==="ai"?wn.name:me||`My ${ne.name} ${Xn.method==="subscription"?"subscription":"API"}`,ownership:(wn?.connectionPurpose==="ai"?wn.credentialPolicy==="shared":Fn==="organization")?"shared":"personal",agentIds:[...xt],allAgents:as==="all",onCancel:r(()=>v?v():S("/apps"),"onCancel"),onComplete:r(Fe=>{h?.({connectionId:Fe.connectionId}),h||S(`/apps/${Fe.connectionId}/permissions`)},"onComplete")})}):void 0):void 0,Ua=wn?.connectionPurpose==="ai"?["Reconnect account"]:Yr!==void 0?["Access","Connect account"]:le?pGe:ne&&ls.length>1?["Access","Choose connection"]:ne&&ls[0]?.auth==="oauth"?["Access","Sign in"]:Tk(ne,qe)?["Access","Share sheet"]:ne?["Access","Add your key"]:eJ,Ti=ne?qe?ls.find(Fe=>Fe.key===qe)??null:ls[0]??null:null,Oi=ne?Ti?.auth??"none":tt==="none"?"none":tt==="oauth"?"oauth":"api_key",Ui=!!Br,oi=Ui?`Continue to ${ne?.name??"sign-in"}`:Oi==="oauth"?"Continue":"Save and continue",Pe=wn?.connectionPurpose==="ai"?0:(le||ne)&&pe!=="gallery"&&pe!=="success"?hGe[pe]:pe==="success"?Ua.length:tJ[pe];return(0,t.jsxs)("div",{className:"max-w-5xl",children:[pe!=="success"&&!(e&&pe==="gallery")&&(0,t.jsx)(aK,{subtitle:pe==="gallery"?Y?"Choose a reviewed app to connect through Vercel.":"Pick the app you want your agents to use.":`Step ${Pe+1} of ${Ua.length}`,step:pe,activeIndex:Pe,labels:Ua,appIdentity:le?{name:"Zapier",logoUrl:na?.branding.logoUrl??null,darkLogoUrl:na?.branding.darkLogoUrl??null}:ne&&pe!=="gallery"?{name:ne.name,logoUrl:ne.branding.logoUrl,darkLogoUrl:ne.branding.darkLogoUrl??null}:void 0,unverifiedHost:!ne&&!le&&pe!=="gallery"?fS(Ie):null,onCancel:v??(()=>S("/apps"))}),pe==="gallery"&&(0,t.jsx)(jGe,{loading:Ls.isLoading,initialLink:Ie,apps:dn,vercelConnect:Y,vercelConnectAvailability:Ls.data?.credentialSources?.vercelConnect??null,byo:te,byoOnly:e,source:R.get("source"),onPick:dr,onUseLink:r(Fe=>{const Lt=jR(Fe,Hn);ae(null),he(""),de(Fe),Te(Lt?.name??P4(Fe)??""),Ce(!1),Oe(""),St({}),Cs(""),ct(null),ms(new Set(i?[i]:[])),Me(i?"specific":"all"),zt($s??(i?"user":"organization")),re("access")},"onUseLink")}),cr&&ne?(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsxs)("h2",{className:"text-lg font-semibold text-foreground",children:[ne.name," sign-in is unavailable"]}),(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["This instance is connected to Paperclip, but ",ne.name," sign-in is not currently available. Try again shortly or contact your instance administrator."]}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between gap-3",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>be("access"),"onClick"),children:"Back"}),(0,t.jsxs)(F,{type:"button",disabled:Ls.isFetching,onClick:r(()=>{Ls.refetch()},"onClick"),children:[Ls.isFetching?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}):null,"Try again"]})]})]}):pe==="key"&&ne&&Oa?(0,t.jsx)("div",{className:"mx-auto max-w-xl",children:(0,t.jsxs)("div",{className:"rounded-xl border border-border bg-card p-6",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"rounded-lg bg-muted p-2 text-muted-foreground",children:(0,t.jsx)(Wg,{className:"h-5 w-5"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Connect with Paperclip"}),(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["You must connect this instance to Paperclip to connect to ",ne.name," (you only need to do this once)."]})]})]}),qt.isError||Hs?(0,t.jsx)(ri,{tone:"danger",className:"mt-4",children:Hs??"Paperclip couldn’t check Cloud registration. Try again."}):null,Es?(0,t.jsxs)("p",{className:"mt-4 text-sm text-muted-foreground",children:["Finish authorization in the opened window."," ",(0,t.jsx)("a",{className:"underline",href:Es,target:"_blank",rel:"noopener noreferrer",children:"Open authorization in a new tab"})]}):null,(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between gap-3",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>be("access"),"onClick"),children:"Back"}),(0,t.jsxs)(F,{type:"button",disabled:qt.isLoading||on.isPending,onClick:r(()=>{Ks(null),Cr(),Ar(),on.mutate()},"onClick"),children:[on.isPending?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}):null,qt.data?.status==="pending"?"Continue":"Connect with Paperclip"]})]})]})}):pe==="key"&&ne&&Yr!==void 0?Yr:pe==="key"&&ne?(0,t.jsx)(NGe,{entry:ne,error:Nr.isError?Nr.error instanceof Error?Nr.error.message:"Please check your key and try again.":null,values:He,onChange:St,oauthClientId:Ft,onOAuthClientIdChange:ts,oauthClientSecret:Ot,onOAuthClientSecretChange:Be,credentialSource:s,vercelConnector:Ve,onVercelConnectorChange:ut,vercelConnectAvailability:Ls.data?.credentialSources?.vercelConnect??null,methodKey:qe,onMethodChange:r(Fe=>{Gt(Fe?.key??""),!$s&&Fe?.grantKinds&&!Fe.grantKinds.includes(ht)&&zt(M4(Fe,!!i)),St({}),ts(""),Be(""),ut(""),$t(GN(Fe))},"onMethodChange"),configValues:We,onConfigChange:$t,googleSheetsLinks:Dt,googleSheetsError:ze,onGoogleSheetsLinksChange:r(Fe=>{Cs(Fe),ct(null)},"onGoogleSheetsLinksChange"),submitting:Nr.isPending,onBack:r(()=>be("access"),"onBack"),onConnect:r(()=>{if(Tk(ne,qe)){const Ts=LO(Dt);if(Ts.invalidCount>0){ct("That doesn't look like a Google Sheets link.");return}if(Ts.ids.length===0){ct("Paste at least one Google Sheets link.");return}}const Fe=dI(ne,qe||null),Lt=!!(Fe?.credentialFields?.length||Fe?.tenantFields?.some(Ts=>!Ts.hidden)||Fe?.extensionFields?.some(Ts=>!Ts.hidden));if(Fe&&Ep(Fe)&&Jn&&!Lt&&!Ft.trim()){Xt.current=!0,Ct(null),Ye("starting"),ws(Jn);return}Fe&&Ep(Fe)&&(Xt.current=!0,Ct(null),Ye("starting")),Yt()},"onConnect")}):null,pe==="key"&&!ne&&Ie&&!le&&(0,t.jsx)(wGe,{link:Ie,name:ve,needsKey:fe,onNeedsKeyChange:r(Fe=>{Ce(Fe),Fe||Oe("")},"onNeedsKeyChange"),keyValue:Xe,onKeyChange:Oe,authMode:tt,onAuthModeChange:r(Fe=>{ce(Fe),at(null),Fe!=="auto"&&Ce(!1),Fe!=="bearer"&&Fe!=="auto"&&Oe("")},"onAuthModeChange"),headers:$e,onHeadersChange:r(Fe=>{mt(Fe),at(null)},"onHeadersChange"),oauthClientId:it,onOAuthClientIdChange:Ke,oauthClientSecret:Ge,onOAuthClientSecretChange:rt,advancedOpen:jt,onAdvancedOpenChange:st,guidance:Nt,matchedEntry:On,onUseMatchedEntry:On?()=>dr(On):void 0,submitting:Nr.isPending||Ee,onBack:r(()=>re("access"),"onBack"),onConnect:r(()=>{at(null),Nr.mutate(void 0)},"onConnect")}),pe==="key"&&!ne&&le&&(0,t.jsx)(yGe,{link:Ie,onLinkChange:de,submitting:Nr.isPending,onBack:r(()=>re("access"),"onBack"),onConnect:r(()=>Nr.mutate(void 0),"onConnect")}),pe==="access"&&(0,t.jsxs)(t.Fragment,{children:[ne?.slug==="railway"&&(0,t.jsxs)("div",{className:"mb-6 space-y-3 text-sm text-muted-foreground",children:[(0,t.jsx)("p",{children:Ti?.guidanceMd}),(0,t.jsx)("ul",{className:"list-disc space-y-2 pl-5",children:Ti?.warnings?.map(Fe=>(0,t.jsx)("li",{children:Fe},Fe))})]}),(0,t.jsx)(dxe,{companyId:_,authKind:Oi,grantKinds:bn?[bn]:Ti?.grantKinds,grantKind:Fn,setGrantKind:zt,installChoice:as,setInstallChoice:Me,installAgentIds:xt,setInstallAgentIds:ms,lockedAgentId:i,capabilities:Ls.data?.capabilities,githubIdentity:ne?.slug==="github",submitLabel:oi,continuesToProvider:Ui,identityLoading:!!Ta&&ii,preserveAgentAccess:!!(Ta&&(Jn||wn)),pending:Nr.isPending||je.isPending||!!(oe&&!ne),onBack:da,onContinue:r(()=>{if(Br){Xt.current=!0,Ct(null),Ye("starting"),be("key"),Jn?ws(Jn):Yt(Br);return}ne?be("key"):re("key")},"onContinue")})]}),pe==="success"&&(0,t.jsx)(CGe,{appName:si,logoUrl:ne?.branding.logoUrl,darkLogoUrl:ne?.branding.darkLogoUrl,summary:SGe({grantKind:Fn,authKind:Oi,installChoice:as,installCount:xt.size,enabledCount:Object.values(ys).filter(Boolean).length}),onDone:v??(()=>S("/apps"))})]})}r(vGe,"StandardConnectionSetupFlow");function aK({title:e,headingRef:s,subtitle:n,step:a,activeIndex:i,labels:o,appIdentity:l,unverifiedHost:c,onCancel:d}){return(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[l?(0,t.jsx)(bc,{name:l.name,logoUrl:l.logoUrl,darkLogoUrl:l.darkLogoUrl,size:44}):null,(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{ref:s,tabIndex:s?-1:void 0,className:"text-2xl font-bold tracking-tight outline-none",children:e??(l?`Connect ${l.name}`:"Connect your own MCP server")}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:n}),c?(0,t.jsx)(Y5,{host:c,className:"mt-2"}):null]})]}),d&&(0,t.jsx)(F,{variant:"ghost",size:"sm",onClick:d,children:"Cancel"})]}),a!=="gallery"&&(0,t.jsxs)("nav",{className:"mt-4","aria-label":"Setup progress","data-testid":"wizard-stepper",children:[(0,t.jsx)("ol",{className:"flex gap-2","aria-hidden":"true",children:o.map((u,h)=>(0,t.jsx)("li",{"data-testid":"wizard-step-dot","data-step-active":h===i?"true":void 0,className:U("h-1 w-20 rounded-full",h<=i?"bg-foreground":"bg-border")},u))}),(0,t.jsx)("div",{className:"mt-2 text-xs text-muted-foreground","data-testid":"wizard-step-labels",children:o.join(" · ")})]})]})}r(aK,"StepHeader");function RF({entry:e,identity:s,resuming:n=!1,phase:a,error:i,recoveryActions:o,authorizationHost:l,authorizationUrl:c,steps:d={labels:fGe,activeIndex:1},onRetry:u,onOpenAuthorization:h,onBack:p,onCancel:x}){const g=e?.name??s?.name??"this server",v=e?null:s?.unverifiedHost??null,y=a==="entry"?{title:n?`Finish connecting ${g}`:`Connect ${g} to Paperclip`,body:n?`Your connection is saved. Continue in ${g} to approve access; its identity and agent access will stay the same.`:`Paperclip will open ${g} so you can choose a workspace and approve access.`}:a==="starting"?{title:"Preparing secure sign-in",body:`Paperclip is creating a secure ${g} connection.`}:a==="redirecting"?{title:`Opening ${g}`,body:l?`Continue at ${l} to choose a workspace and approve access. Only approve access if you recognize that address.`:`Continue in ${g} to choose a workspace and approve access.`}:{title:`${g} couldn’t connect`,body:i??"Paperclip couldn’t start secure sign-in. Try again."};return(0,t.jsxs)("div",{className:"max-w-5xl",children:[(0,t.jsx)(aK,{subtitle:"Secure MCP sign-in",step:"key",activeIndex:d.activeIndex,labels:d.labels,appIdentity:e?{name:e.name,logoUrl:e.branding.logoUrl,darkLogoUrl:e.branding.darkLogoUrl}:void 0,unverifiedHost:v,onCancel:x}),(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("span",{className:"mt-1 inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border border-border bg-background",children:a==="error"?(0,t.jsx)(nc,{className:"h-5 w-5 text-destructive"}):a==="entry"?(0,t.jsx)(Pd,{className:"h-5 w-5 text-muted-foreground"}):(0,t.jsx)(ot,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-xl font-bold tracking-tight",children:y.title}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:y.body}),v?(0,t.jsx)(Y5,{host:v,className:"mt-2"}):null]})]}),a==="error"&&o&&(o.installationUrl||o.managementUrl)?(0,t.jsxs)("div",{className:"mt-4 flex flex-wrap gap-2",children:[o.installationUrl?(0,t.jsx)(F,{type:"button",variant:"outline",asChild:!0,children:(0,t.jsxs)("a",{href:o.installationUrl,target:"_blank",rel:"noreferrer",children:["Install Paperclip on GitHub",(0,t.jsx)(eo,{className:"ml-1.5 h-3.5 w-3.5"})]})}):null,o.managementUrl?(0,t.jsx)(F,{type:"button",variant:"ghost",asChild:!0,children:(0,t.jsx)("a",{href:o.managementUrl,target:"_blank",rel:"noreferrer",children:"Manage repositories on GitHub"})}):null]}):null,(0,t.jsxs)("div",{className:"mt-6 flex items-center gap-2",children:[a==="error"||a==="entry"?(0,t.jsx)(F,{type:"button",onClick:u,children:a==="entry"?n?`Finish with ${g}`:`Continue to ${g}`:"Try again"}):(0,t.jsx)(F,{type:"button",disabled:!0,children:a==="redirecting"?`Opening ${g}…`:"Preparing…"}),c?(0,t.jsx)(F,{variant:"outline",asChild:!0,children:(0,t.jsx)("a",{href:c,target:"_blank",rel:"noopener noreferrer",onClick:h,children:"Open sign-in in a new tab"})}):null,(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:p,children:"Back"})]})]})]})}r(RF,"OAuthConnectStateScreen");function yGe({link:e,onLinkChange:s,submitting:n,onBack:a,onConnect:i}){const o=TF(e),l=o?new URL(o).hostname:"",c=l==="zapier.com"||l.endsWith(".zapier.com");return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Zapier MCP URL"}),(0,t.jsx)(Rt,{type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r(d=>s(d.target.value),"onChange"),onKeyDown:r(d=>{d.key==="Enter"&&c&&!n&&i()},"onKeyDown"),placeholder:"https://mcp.zapier.com/api/v1/connect?token=…",className:"mt-2 h-11",autoFocus:!0}),e.trim()&&!c&&(0,t.jsx)("p",{className:"mt-2 text-xs text-destructive",children:"Paste a valid Zapier URL to continue."})]}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:a,disabled:n,children:"Back"}),(0,t.jsxs)(F,{onClick:i,disabled:n||!c,children:[n&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),n?"Checking…":"Check link"]})]})]})}r(yGe,"ZapierConnectStep");function jGe({loading:e,initialLink:s="",apps:n,byo:a=!1,byoOnly:i=!1,vercelConnect:o=!1,vercelConnectAvailability:l=null,source:c=null,onPick:d,onUseLink:u}){const[h,p]=(0,m.useState)(""),[x,g]=(0,m.useState)(s),v=(0,m.useRef)(!1);(0,m.useEffect)(()=>{v.current||g(s)},[s]);const[y,j]=(0,m.useState)(null),S=(0,m.useRef)(null),w=(0,m.useRef)(null),N=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a||e&&!i||N.current||(i||S.current?.scrollIntoView?.({block:"center"}),w.current?.focus(),w.current?.select(),N.current=!0)},[a,i,e]);const _=(0,m.useMemo)(()=>{const E=h.trim().toLowerCase();return n.filter(O=>!E||O.name.toLowerCase().includes(E))},[n,h]),I=TF(x),C=I?jR(I,n):null,A=c==="zapier",R=r(()=>{const E=TF(x);if(!E){j("Paste a full http or https link.");return}j(null),u(E)},"continueWithLink");return e&&!i?(0,t.jsx)("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4",children:Array.from({length:8}).map((E,O)=>(0,t.jsx)(fn,{className:"h-32 w-full rounded-xl"},O))}):(0,t.jsxs)("div",{className:"space-y-6",children:[o?(0,t.jsxs)("div",{className:"rounded-xl border border-border bg-card p-5",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-bold tracking-tight",children:"Connect through Vercel"}),(0,t.jsx)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:"Create and manage the provider connector in Vercel. Paperclip stores its reference and applies agent access, policy, approval, and audit controls here."})]}),l?(0,t.jsx)(F,{asChild:!0,variant:"outline",size:"sm",className:"shrink-0",children:(0,t.jsxs)("a",{href:l.manageUrl,target:"_blank",rel:"noreferrer",children:["Open Vercel Connect",(0,t.jsx)(eo,{className:"ml-2 h-3.5 w-3.5"})]})}):null]}),l?.available===!1?(0,t.jsx)(ri,{tone:"danger",compact:!0,className:"mt-4",children:l.reason??"Vercel Connect is unavailable on this instance."}):null]}):null,!i&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(pa,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),(0,t.jsx)(Rt,{value:h,onChange:r(E=>p(E.target.value),"onChange"),placeholder:"Search apps…",className:"h-11 pl-9"})]}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4",children:_.map(E=>{const O=nxe(E.slug,E.description),L=R1(E),$=L.length===0||L.every(q=>q.auth==="oauth"&&!Ep(q)&&!gR(q)),T=E.availability?.available===!1||o&&l?.available!==!0;return(0,t.jsxs)("button",{type:"button",disabled:$||T,title:T?E.availability?.reason??l?.reason??void 0:void 0,onClick:r(()=>d(E),"onClick"),className:U("flex flex-col rounded-xl border border-border bg-card p-4 text-left transition-colors",$||T?"cursor-not-allowed opacity-60":"hover:border-foreground/30 hover:bg-accent/40"),children:[(0,t.jsx)(bc,{name:E.name,logoUrl:E.branding.logoUrl,darkLogoUrl:E.branding.darkLogoUrl,size:36}),(0,t.jsx)("div",{className:"mt-3 text-sm font-bold text-foreground",children:E.name}),(0,t.jsx)("div",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:O.tagline}),(0,t.jsx)("div",{className:"mt-3 text-xs font-semibold text-foreground",children:T?(0,t.jsx)("span",{className:"text-muted-foreground",children:E.availability?.reason??l?.reason??"Unavailable on this instance."}):$?(0,t.jsx)("span",{className:"text-muted-foreground",children:"Unavailable"}):(0,t.jsx)("span",{children:"Connect →"})})]},E.slug)})}),_.length===0&&(0,t.jsxs)("div",{className:"py-10 text-center text-sm text-muted-foreground",children:["No apps match “",h,"”."]})]}),o?null:(0,t.jsxs)("div",{ref:S,className:U("grid gap-4 border-t border-border pt-5 md:grid-cols-(--gtc-13)",a&&"-mx-3 rounded-xl border border-primary/40 bg-primary/[0.04] px-3 pb-4 md:mx-0"),children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[(0,t.jsx)(nc,{className:"h-4 w-4 text-muted-foreground"}),A?"Connect Zapier":a?"Connect your own MCP server":"Connect with a link"]}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:A?"Paste the complete MCP URL Zapier gives you, including its token.":a?"Paste your MCP server’s URL and every discovered tool will be available immediately.":"Paste a setup link from an app that is not listed here."}),!A&&(0,t.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:["Any remote tool URL works here — including a local MCP server like"," ",(0,t.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:"http://127.0.0.1:8848/mcp"}),"."]}),C&&(0,t.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg border border-border bg-muted/40 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,t.jsx)(bc,{name:C.name,logoUrl:C.branding.logoUrl,darkLogoUrl:C.branding.darkLogoUrl,size:24}),(0,t.jsxs)("span",{className:"truncate",children:["This looks like ",C.name,"."]})]}),(0,t.jsx)(F,{type:"button",size:"sm",variant:"outline",disabled:C.availability?.available===!1,onClick:r(()=>{if(j(null),C.slug==="zapier"){R();return}d(C)},"onClick"),children:C.availability?.available===!1?"Not available":C.slug==="zapier"?"Continue":`Use ${C.name}`})]})]}),(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-2 sm:min-w-(--sz-360px)",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(Rt,{ref:w,type:A||C?.slug==="zapier"?"password":"url",autoComplete:"off",spellCheck:!1,"aria-label":"MCP server URL",value:x,onChange:r(E=>{v.current=!0,g(E.target.value),j(null)},"onChange"),onKeyDown:r(E=>{E.key==="Enter"&&R()},"onKeyDown"),placeholder:A?"https://mcp.zapier.com/api/v1/connect?token=…":"https://example.com/actions",className:"h-10"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:R,children:"Continue"})]}),y&&(0,t.jsx)("div",{className:"text-xs text-destructive",children:y})]})]})]})}r(jGe,"GalleryStep");function TF(e){try{const s=new URL(e.trim());return s.protocol!=="http:"&&s.protocol!=="https:"?null:s.toString()}catch{return null}}r(TF,"normalizeAppLink");function wGe({link:e,name:s,needsKey:n,onNeedsKeyChange:a,keyValue:i,onKeyChange:o,authMode:l,onAuthModeChange:c,headers:d,onHeadersChange:u,oauthClientId:h,onOAuthClientIdChange:p,oauthClientSecret:x,onOAuthClientSecretChange:g,advancedOpen:v,onAdvancedOpenChange:y,guidance:j,matchedEntry:S,onUseMatchedEntry:w,submitting:N,onBack:_,onConnect:I}){const C=fS(e),A=l==="custom_headers"?rxe(d):null,R=sGe({link:e,name:s,authMode:l,needsKey:n,keyValue:i,headers:d,oauthClientId:h,oauthClientSecret:x}),E=l==="auto",O=S?.slug==="zapier"?nle(e):e,L=r(($,T)=>{u(d.map(q=>q.id===$?{...q,...T}:q))},"updateHeader");return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)("p",{className:"min-w-0 truncate font-mono text-sm text-muted-foreground",title:O,children:O}),(0,t.jsx)(Y5,{host:C})]}),S&&w?(0,t.jsxs)("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border bg-muted/40 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,t.jsx)(bc,{name:S.name,logoUrl:S.branding.logoUrl,darkLogoUrl:S.branding.darkLogoUrl,size:24}),(0,t.jsxs)("span",{className:"truncate",children:["Paperclip has a guided setup for ",S.name,"."]})]}),(0,t.jsxs)(F,{type:"button",size:"sm",variant:"outline",onClick:w,children:["Use ",S.name]})]}):null,j?(0,t.jsx)("div",{className:"mt-6",children:(0,t.jsx)(ri,{tone:"warning",title:j.title,children:j.body})}):null,(0,t.jsxs)("div",{className:"mt-6 space-y-6",children:[E&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mr-2 text-sm font-medium text-foreground",children:"Does it need a key?"}),(0,t.jsxs)("div",{className:"mt-2 inline-flex rounded-lg border border-border bg-muted/50 p-1",children:[(0,t.jsx)(D4,{label:"No",selected:!n,onClick:r(()=>a(!1),"onClick")}),(0,t.jsx)(D4,{label:"Yes",selected:n,onClick:r(()=>a(!0),"onClick")})]}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:n?"Paste the key this app gave you.":"Most servers just work from the address — pick Yes only if the server gave you a key, or if it asks you to sign in."})]}),E&&n||l==="bearer"?(0,t.jsx)("div",{className:"space-y-4",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-key",children:"App key"}),(0,t.jsx)(Rt,{id:"generic-mcp-key",type:"password",autoComplete:"off",value:i,onChange:r($=>o($.target.value),"onChange"),placeholder:"••••••••••••••••",className:"mt-2 h-11 font-mono"})]})}):null,(0,t.jsxs)(el,{open:v,onOpenChange:y,children:[(0,t.jsxs)(Ul,{className:"flex w-full items-center justify-between rounded-lg border border-border bg-background px-3 py-2 text-left text-sm font-medium text-foreground hover:bg-accent/40",children:["Advanced authentication",(0,t.jsx)(en,{className:U("h-4 w-4 text-muted-foreground transition-transform",v&&"rotate-180")})]}),(0,t.jsxs)(tl,{className:"space-y-5 pt-4",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Only needed when the server's docs are specific about how to authenticate."}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:iJ.map($=>(0,t.jsx)(D4,{label:$.label,selected:l===$.mode,onClick:r(()=>c($.mode),"onClick")},$.mode))}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:iJ.find($=>$.mode===l)?.hint}),l==="custom_headers"?(0,t.jsxs)("div",{className:"space-y-3",children:[d.map($=>(0,t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,t.jsx)(Rt,{value:$.name,onChange:r(T=>L($.id,{name:T.target.value}),"onChange"),placeholder:"Header name","aria-label":"Header name",className:"h-10 font-mono"}),(0,t.jsx)(Rt,{type:"password",autoComplete:"off",value:$.value,onChange:r(T=>L($.id,{value:T.target.value}),"onChange"),placeholder:"Value","aria-label":$.name.trim()?`Value for ${$.name.trim()}`:"Header value",className:"h-10 font-mono"}),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-10 shrink-0",onClick:r(()=>u(d.filter(T=>T.id!==$.id)),"onClick"),disabled:d.length===1,children:"Remove"})]},$.id)),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",onClick:r(()=>u([...d,AF()]),"onClick"),children:"Add another header"}),A?(0,t.jsx)("p",{className:"text-xs text-destructive",children:A}):null]}):null,l==="oauth"?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Paperclip sets sign-in up on its own whenever the server allows it. Only fill these in when the server's docs tell you to register Paperclip yourself first."}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-client-id",children:"Client ID"}),(0,t.jsx)(Rt,{id:"generic-mcp-client-id",value:h,onChange:r($=>p($.target.value),"onChange"),autoComplete:"off",placeholder:"Optional",className:"mt-2 h-11 font-mono"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-client-secret",children:"Client secret"}),(0,t.jsx)(Rt,{id:"generic-mcp-client-secret",type:"password",autoComplete:"off",value:x,onChange:r($=>g($.target.value),"onChange"),placeholder:"Optional",className:"mt-2 h-11 font-mono"})]})]}):null]})]})]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!R||!!A,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":"Check link"]})]})]})}r(wGe,"LinkConnectStep");var iJ=[{mode:"auto",label:"Let Paperclip check",hint:"Paperclip asks the server what it needs and walks you through it. Start here."},{mode:"none",label:"No sign-in needed",hint:"The server is open to anyone with the address."},{mode:"bearer",label:"Key or token",hint:"Paperclip sends your key as an Authorization header."},{mode:"custom_headers",label:"Custom headers",hint:"For servers that name their own headers. Values are stored as Paperclip secrets and can’t be read back."},{mode:"oauth",label:"Browser sign-in",hint:"You’ll sign in at the provider. Add a client ID and secret only if the provider requires you to register Paperclip first."}];function D4({label:e,selected:s,onClick:n}){return(0,t.jsx)("button",{type:"button",onClick:n,"aria-pressed":s,className:U("min-w-(--sz-64px) rounded-md px-4 py-1.5 text-sm font-medium transition-colors",s?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:e})}r(D4,"SegmentedOption");function NGe({entry:e,error:s,values:n,onChange:a,oauthClientId:i,onOAuthClientIdChange:o,oauthClientSecret:l,onOAuthClientSecretChange:c,credentialSource:d,vercelConnector:u,onVercelConnectorChange:h,vercelConnectAvailability:p,methodKey:x,onMethodChange:g,configValues:v,onConfigChange:y,googleSheetsLinks:j,googleSheetsError:S,onGoogleSheetsLinksChange:w,submitting:N,onBack:_,onConnect:I}){const C=(0,m.useMemo)(()=>qy(e,d),[d,e]),A=x?C.find(Oe=>Oe.key===x)??null:Sj(C),R=(0,m.useMemo)(()=>C.some(Oe=>Oe.capabilityProfile)?Array.from(C.reduce((Oe,tt)=>{const ce=tt.capabilityProfile.key,$e=Oe.get(ce);return $e?$e.methods.push(tt):Oe.set(ce,{key:ce,label:tt.capabilityProfile?.label??tt.label??tt.key,description:tt.capabilityProfile?.description??tt.whenToUse,methods:[tt]}),Oe},new Map)).map(([,Oe])=>Oe):[],[C]),E=A?.capabilityProfile?.key??A?.key??"",O=R.map(Oe=>Oe.key).join("|"),[L,$]=(0,m.useState)(E||Sj(C)?.capabilityProfile?.key||(R.length===1?R[0].key:""));(0,m.useEffect)(()=>{if(E){$(E);return}$(Oe=>R.some(tt=>tt.key===Oe)?Oe:Sj(C)?.capabilityProfile?.key||(R.length===1?R[0].key:""))},[O,R,C,E]);const T=R.length>1?R.find(Oe=>Oe.key===L)?.methods??[]:C,q=(A?.credentialFields??[]).map(Oe=>({...Oe,configPath:sle(Oe),helpUrl:A?.consoleLinks?.keys??A?.consoleLinks?.docs??""})),B=A?.credentialSources?.vercelConnect??null,K=d==="vercel_connect",z=K||q.every(Oe=>Oe.required===!1||(n[Oe.configPath]?.trim().length??0)>0),D=gR(A),V=D&&!Ep(A),H=K||!V||i.trim().length>0,Z=!K||u.trim().length>0,Y=A?.auth==="oauth"&&D?eGe():null,ie=[...A?.tenantFields??[],...A?.extensionFields??[]],se=ie.filter(Oe=>!Oe.hidden),X=se.filter(Oe=>Oe.advanced!==!0),le=se.filter(Oe=>Oe.advanced===!0),[oe,te]=(0,m.useState)(!1),J=ie.every(Oe=>{if(!Oe.required)return!0;const tt=v[Oe.key];return typeof tt=="boolean"||typeof tt=="string"&&tt.trim().length>0}),Q=A?.configRequirements?.atLeastOneOf??[],pe=Q.length===0||Q.some(Oe=>{const tt=v[Oe];return typeof tt=="string"&&tt.trim().length>0}),re=(R.length<=1||!!L)&&(T.length<=1?!!A:!!x),ne=e.availability?.robotEmail??null,ae=e.availability?.available===!1,me=!K&&D&&!V,he=le.length>0||me,Ie=R.length>1?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"What should Paperclip be able to do?"}),(0,t.jsx)(iu,{ariaLabel:`Access level for ${e.name}`,className:"mt-2",value:L,onValueChange:r(Oe=>{const tt=R.find(ce=>ce.key===Oe);tt&&($(Oe),g(H6(tt.methods)))},"onValueChange"),options:R.map(Oe=>({value:Oe.key,title:Oe.label,description:Oe.description}))}),!L&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Choose an access level to continue."})]}):null,de=T.find(Oe=>Oe.oauthStrategy==="paperclip_cloud_connector"&&O_e(Oe.connectorProfile??"")),ve=de&&T.find(Oe=>gR(Oe)&&!Ep(Oe)),Te=A?.key===ve?.key,fe=(0,m.useId)(),Ce=de&&ve&&T.length===2?(0,t.jsx)(F,{type:"button",variant:"link",className:"h-auto p-0 text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground","aria-expanded":Te,"aria-controls":fe,disabled:N,onClick:r(()=>g(Te?de:ve),"onClick"),children:Te?"Use Paperclip instead":"Use your own Google OAuth app"}):T.length>1?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"How do you want to connect?"}),(0,t.jsx)(iu,{ariaLabel:`How to connect ${e.name}`,className:"mt-2",value:x,onValueChange:r(Oe=>{const tt=T.find(ce=>ce.key===Oe);tt&&g(tt)},"onValueChange"),options:T.map(Oe=>({value:Oe.key,title:Oe.label??(Oe.auth==="oauth"?`Sign in with ${e.name}`:"Use an API key")}))}),!A&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Choose a connection method to continue."})]}):null;if(Tk(e,A)){const Oe=LO(j),tt=!ae&&!!ne&&j.trim().length>0;return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"space-y-6",children:[Ie,ne?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Share each sheet with this email"}),(0,t.jsxs)("div",{className:"mt-2 flex min-w-0 flex-col gap-2 sm:flex-row",children:[(0,t.jsx)("div",{title:ne,className:"min-h-11 min-w-0 flex-1 rounded-md border border-input bg-muted/40 px-3 py-2.5 font-mono text-xs leading-tight text-foreground break-all",children:ne}),(0,t.jsx)(cxe,{value:ne,ariaLabel:"Copy sharing email"})]}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"In Google Sheets, click Share and add this email as an Editor. Then paste the sheet links below."})]}):(0,t.jsx)("div",{className:"rounded-lg bg-muted/50 p-4 text-sm text-muted-foreground",children:"Google Sheets is not available on this instance yet."}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Paste links to the sheets you shared"}),(0,t.jsx)(An,{value:j,onChange:r(ce=>w(ce.target.value),"onChange"),placeholder:"https://docs.google.com/spreadsheets/d/...",className:"mt-2 min-h-28"}),(0,t.jsx)("div",{className:"mt-2 text-xs text-muted-foreground",children:Oe.ids.length>0?`${Oe.ids.length} ${Oe.ids.length===1?"sheet":"sheets"} ready to connect.`:"Paste one link per line. Both .../edit and .../edit#gid=... links work."}),S&&(0,t.jsx)("div",{className:"mt-2 text-xs text-destructive",children:S})]})]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!tt,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":"Connect"]})]})]})}const Xe=A?.consoleLinks?.docs??e.docsUrl;return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[Xe?(0,t.jsx)("div",{className:"mb-4 flex justify-end",children:(0,t.jsxs)("a",{href:Xe,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs font-medium text-muted-foreground underline underline-offset-2 hover:text-foreground",children:["Review requirements",(0,t.jsx)(eo,{className:"h-3 w-3"})]})}):null,(0,t.jsxs)("div",{className:"space-y-6",children:[Ie,Ce,K&&B&&p?(0,t.jsxs)("div",{className:"space-y-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Create or attach the connector in Vercel"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Paperclip does not copy Vercel’s setup forms. Finish connector setup there, then paste its UID below."}),(0,t.jsxs)("a",{href:p.manageUrl,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Open Vercel Connect",(0,t.jsx)(eo,{className:"h-3 w-3"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"vercel-connect-connector",children:"Connector UID or ID"}),(0,t.jsx)(Rt,{id:"vercel-connect-connector",value:u,onChange:r(Oe=>h(Oe.target.value),"onChange"),autoComplete:"off",placeholder:"service/my-connector or scl_…",className:"mt-2 h-11 font-mono"}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Paperclip validates the connector and stores only its reference and redacted verification metadata."})]})]}):null,s?(0,t.jsx)("div",{role:"alert",children:(0,t.jsx)(ri,{tone:"danger",children:s})}):null,X.map(Oe=>(0,t.jsx)(lJ,{field:Oe,value:v[Oe.key],onChange:r(tt=>y({...v,[Oe.key]:tt}),"onChange")},Oe.key)),he&&(0,t.jsxs)(el,{open:oe,onOpenChange:te,children:[(0,t.jsxs)(Ul,{className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground",children:[(0,t.jsx)(en,{className:U("h-4 w-4 transition-transform",oe&&"rotate-180")}),"Advanced"]}),(0,t.jsx)(tl,{className:"pt-4",children:(0,t.jsxs)("div",{className:"space-y-6",children:[le.map(Oe=>(0,t.jsx)(lJ,{field:Oe,value:v[Oe.key],onChange:r(tt=>y({...v,[Oe.key]:tt}),"onChange")},Oe.key)),me?(0,t.jsx)(oJ,{entry:e,method:A,callbackUrl:Y,clientId:i,onClientIdChange:o,clientSecret:l,onClientSecretChange:c,required:!1}):null]})})]}),!K&&A?.auth==="oauth"&&V?(0,t.jsx)("div",{id:fe,role:"region","aria-label":"Your OAuth app",children:(0,t.jsx)(oJ,{entry:e,method:A,callbackUrl:Y,clientId:i,onClientIdChange:o,clientSecret:l,onClientSecretChange:c,required:!0})}):null,K||!A||q.length===0?null:q.map(Oe=>(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:VY(e.name,Oe.label,q.length)}),(0,t.jsx)(Rt,{type:"password","aria-label":VY(e.name,Oe.label,q.length),autoComplete:"off",value:n[Oe.configPath]??"",onChange:r(tt=>a({...n,[Oe.configPath]:tt.target.value}),"onChange"),placeholder:"••••••••••••••••",className:"mt-2 h-11 font-mono"}),Oe.helpUrl&&(0,t.jsxs)("a",{href:Oe.helpUrl,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Where do I find this?",(0,t.jsx)(eo,{className:"h-3 w-3"})]})]},Oe.configPath))]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!re||!z||!H||!Z||!J||!pe,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":K?A?.auth==="oauth"?"Validate and continue":"Validate and connect":A?.auth==="oauth"?e.slug==="github"?"Continue to GitHub":"Continue to sign in":"Connect"]})]})]})}r(NGe,"KeyStep");function cxe({value:e,ariaLabel:s}){const{copied:n,failed:a,copy:i}=nf();return(0,t.jsxs)(F,{type:"button",variant:"outline",className:"shrink-0","aria-label":s,onClick:r(()=>{i(e)},"onClick"),children:[n?(0,t.jsx)(xs,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(jr,{className:"mr-2 h-4 w-4"}),n?"Copied":a?"Copy failed":"Copy"]})}r(cxe,"CopyValueButton");function oJ({entry:e,method:s,callbackUrl:n,clientId:a,onClientIdChange:i,clientSecret:o,onClientSecretChange:l,required:c}){return(0,t.jsxs)("div",{className:"space-y-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:c?"Your OAuth app":"Use your own OAuth app"}),(0,t.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:["Register Paperclip's callback URI in ",e.name,", then enter the customer-owned client details."]}),s.consoleLinks?.register?(0,t.jsxs)("a",{href:s.consoleLinks.register,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Open ",e.name," app settings",(0,t.jsx)(eo,{className:"h-3 w-3"})]}):null]}),n?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Paperclip callback URL"}),(0,t.jsxs)("div",{className:"mt-2 flex min-w-0 flex-col gap-2 sm:flex-row",children:[(0,t.jsx)("div",{title:n,className:"min-h-11 min-w-0 flex-1 rounded-md border border-input bg-muted/40 px-3 py-2.5 font-mono text-xs leading-tight text-foreground break-all",children:n}),(0,t.jsx)(cxe,{value:n,ariaLabel:"Copy callback URL"})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Add this exact URL to ",e.name," before continuing. It must match the authorization request."]})]}):null,(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"curated-oauth-client-id",children:"Client ID"}),(0,t.jsx)(Rt,{id:"curated-oauth-client-id",value:a,onChange:r(d=>i(d.target.value),"onChange"),autoComplete:"off",placeholder:c?"Required":"Optional",className:"mt-2 h-11 font-mono"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"curated-oauth-client-secret",children:"Client secret"}),(0,t.jsx)(Rt,{id:"curated-oauth-client-secret",type:"password",value:o,onChange:r(d=>l(d.target.value),"onChange"),autoComplete:"off",placeholder:"Optional for public clients",className:"mt-2 h-11 font-mono"})]})]})}r(oJ,"OAuthClientFields");function lJ({field:e,value:s,onChange:n}){return e.type==="checkbox"?(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.label}),e.helperMd&&(0,t.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:e.helperMd})]}),(0,t.jsx)(Ei,{checked:s===!0,onCheckedChange:n})]}):(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:e.label}),e.type==="textarea"?(0,t.jsx)(An,{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),placeholder:e.placeholder,className:"mt-2 min-h-24"}):e.type==="select"?(0,t.jsxs)("select",{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),className:"mt-2 h-11 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30",children:[(0,t.jsx)("option",{value:"",disabled:!0,children:"Select an option"}),(e.options??[]).map(a=>(0,t.jsx)("option",{value:a.value,children:a.label},a.value))]}):(0,t.jsx)(Rt,{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),placeholder:e.placeholder,className:"mt-2 h-11"}),e.helperMd&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:e.helperMd})]})}r(lJ,"MethodConfigField");function dxe({companyId:e,...s}){const n=ee({queryKey:P.agents.list(e),queryFn:r(()=>Wt.list(e),"queryFn")});return(0,t.jsx)(uxe,{...s,agents:(n.data??[]).filter(a=>a.status!=="terminated"),agentsLoading:n.isLoading})}r(dxe,"AccessStep");function uxe({agents:e,agentsLoading:s=!1,authKind:n,grantKinds:a,grantKind:i,setGrantKind:o,installChoice:l,setInstallChoice:c,installAgentIds:d,setInstallAgentIds:u,lockedAgentId:h,capabilities:p,githubIdentity:x=!1,submitLabel:g,continuesToProvider:v=!1,identityLoading:y=!1,preserveAgentAccess:j=!1,pending:S=!1,onBack:w,onContinue:N}){const _=p?.editableAgentIds,I=_?e.filter(B=>_.includes(B.id)):e,C=p?.canSetCompanyInstall??!0,A=p?.canCreateOrganizationGrant??!0,R=n!=="none",E=a??["user","organization"],O=(!R||i==="user"||i==="agent"||A)&&(j?!0:h?d.has(h):i==="agent"?l==="specific"&&d.size===1:l==="all"?C:d.size>0),L=h?e.find(B=>B.id===h)?.name??"the requesting agent":null,$=x?"Connect GitHub as":"Which humans can use this credential?",T=i==="agent"?"Which agent owns this GitHub account?":x&&i==="user"?"Which agents may use your GitHub when you’re responsible?":x?"Which agents may use the shared GitHub account?":"Which agents can use this connection?",q=x?T:"Which agents can use this connection?";return(0,t.jsxs)("div",{className:"mx-auto max-w-2xl",children:[(0,t.jsx)("div",{className:"overflow-hidden rounded-xl border border-border",children:(0,t.jsxs)("div",{className:"divide-y divide-border",children:[(0,t.jsxs)("section",{className:"p-6",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:$}),x&&i==="agent"?(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This agent uses this GitHub account for everyone’s work, instead of the person giving instructions."}):null,y?(0,t.jsxs)("div",{className:"mt-4 grid gap-2 sm:grid-cols-2","aria-label":"Loading connection identity",children:[(0,t.jsx)(fn,{className:"h-20 w-full rounded-md"}),(0,t.jsx)(fn,{className:"h-20 w-full rounded-md"})]}):R&&E.length===1?(0,t.jsxs)("div",{className:"mt-4 flex items-center gap-3 rounded-md border border-border p-4",children:[E[0]==="user"?(0,t.jsx)(pu,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}):E[0]==="agent"?(0,t.jsx)(Xi,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}):(0,t.jsx)(gj,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:E[0]==="user"?x?"My GitHub account":"Just me":E[0]==="agent"?"A dedicated account for an agent":x?"Shared organization GitHub account (advanced)":"Any human in the organization"}),x?(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:E[0]==="user"?"Agents use it only for runs where you are the responsible person.":E[0]==="agent"?"That agent always uses this account, regardless of who starts the run.":"Eligible agents use one shared credential, regardless of who starts the run."}):null]})]}):R?(0,t.jsx)(iu,{ariaLabel:x?$:"Which humans can use this credential?",className:"mt-4 sm:grid-cols-2",value:i,onValueChange:r(B=>{const K=B;o(K),K==="agent"&&(c("specific"),d.size>1&&u(new Set([[...d][0]])))},"onValueChange"),options:[{value:"user",title:x?"My GitHub account":"Just me",description:x?"Agents use it only for runs where you are the responsible person.":void 0,icon:(0,t.jsx)(pu,{className:"h-4 w-4","aria-hidden":"true"})},{value:"agent",title:"A dedicated account for an agent",description:x?"That agent always uses this account, regardless of who starts the run.":void 0,icon:(0,t.jsx)(Xi,{className:"h-4 w-4","aria-hidden":"true"})},{value:"organization",title:x?"Shared organization GitHub account (advanced)":"Any human in the organization",description:x?"Eligible agents use one shared credential, regardless of who starts the run.":void 0,icon:(0,t.jsx)(gj,{className:"h-4 w-4","aria-hidden":"true"}),accessibleLabel:A?x?"Shared organization GitHub account (advanced)":"Any human in the organization":`${x?"Shared organization GitHub account (advanced)":"Any human in the organization"}. Unavailable: ${p?.organizationGrantReason??"Only a connection manager can share this credential with the organization."}`,tooltip:A?void 0:p?.organizationGrantReason??"Only a connection manager can share this credential with the organization.",disabled:!A}].filter(B=>E.includes(B.value))}):(0,t.jsx)("p",{className:"mt-4 text-sm text-muted-foreground",children:"No identity required"})]}),(0,t.jsxs)("section",{className:"p-6",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:T}),j?(0,t.jsxs)("div",{className:"mt-4 flex items-start gap-3 rounded-md border border-border bg-muted/40 p-4",children:[(0,t.jsx)(gj,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Existing agent access stays the same"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Reconnecting replaces the credential without changing which agents can use it."})]})]}):h?(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["This task grants access only to ",(0,t.jsx)("span",{className:"font-medium text-foreground",children:L}),". Existing connection access is left unchanged."]}):i==="agent"?(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Choose exactly one agent. This identity cannot be shared with other agents."}):(0,t.jsx)(iu,{ariaLabel:q,className:"mt-4 sm:grid-cols-2",value:l,onValueChange:r(B=>c(B),"onValueChange"),options:[{value:"specific",title:x?"Only agents I choose":"Just agents I pick",description:x?i==="user"?"Only selected agents may use your GitHub when you’re responsible.":"Only selected agents may use the shared account.":void 0,icon:(0,t.jsx)(Xi,{className:"h-4 w-4","aria-hidden":"true"})},{value:"all",title:"Any agent",description:x?i==="user"?"Every agent may use your GitHub when you’re responsible.":"Every agent may use the shared account.":void 0,icon:(0,t.jsx)(kGe,{}),accessibleLabel:C?"Any agent":`Any agent. Unavailable: ${p?.companyInstallReason??"Only someone who can configure this connection can choose this."}`,tooltip:C?void 0:p?.companyInstallReason??"Only someone who can configure this connection can choose this.",disabled:!C}]}),!j&&!h&&l==="specific"?(0,t.jsx)("div",{className:"mt-3",children:(0,t.jsx)(_v,{agents:I,selectedAgentIds:d,onChange:r(B=>u(i==="agent"&&B.size>1?new Set([[...B].at(-1)]):B),"onChange"),loading:s,emptyMessage:"You cannot edit any agents yet.",showSelectionPreview:!1})}):null]})]})}),(0,t.jsxs)("div",{className:"mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,t.jsx)(F,{variant:"ghost",className:"w-full sm:w-auto",onClick:w,disabled:S,children:"Back"}),(0,t.jsxs)(F,{className:"w-full sm:w-auto",onClick:N,disabled:!O||y||S,children:[S?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):null,g,!S&&v?(0,t.jsx)(eo,{className:"h-4 w-4","aria-hidden":"true"}):null]})]})]})}r(uxe,"AccessStepContent");function kGe(){return(0,t.jsxs)("span",{className:"relative block h-4 w-5","aria-hidden":"true",children:[(0,t.jsx)(Xi,{className:"absolute left-0 top-0 h-3.5 w-3.5"}),(0,t.jsx)(Xi,{className:"absolute bottom-0 right-0 h-3.5 w-3.5"})]})}r(kGe,"BotGroupIcon");function SGe(e){const s=e.authKind==="none"?"No identity required":e.grantKind==="user"?"Your identity":e.grantKind==="agent"?"Dedicated agent identity":"Organization identity",n=e.installChoice==="all"?"Any agent":`${e.installCount} selected ${e.installCount===1?"agent":"agents"}`;return[{label:"Identity",value:s},{label:"Available to",value:n},{label:"Actions",value:`${e.enabledCount} ${e.enabledCount===1?"action":"actions"} on`}]}r(SGe,"accessSummaryLines");function CGe({appName:e,logoUrl:s,darkLogoUrl:n,summary:a,onDone:i}){return(0,t.jsxs)("div",{className:"mx-auto max-w-md py-10 text-center",children:[(0,t.jsx)("div",{className:"mx-auto flex h-20 w-20 items-center justify-center rounded-full border-2 border-emerald-500 bg-emerald-500/10",children:(0,t.jsx)(xs,{className:"h-9 w-9 text-emerald-600 dark:text-emerald-400"})}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-center gap-2",children:[(0,t.jsx)(bc,{name:e,logoUrl:s,darkLogoUrl:n,size:28}),(0,t.jsxs)("h2",{className:"text-2xl font-bold tracking-tight",children:[e," is ready."]})]}),(0,t.jsx)("dl",{className:"mx-auto mt-6 max-w-xs space-y-1 text-left",children:a.map(o=>(0,t.jsxs)("div",{className:"flex items-baseline justify-between gap-4",children:[(0,t.jsx)("dt",{className:"text-xs font-medium text-muted-foreground",children:o.label}),(0,t.jsx)("dd",{className:"text-sm text-foreground",children:o.value})]},o.label))}),(0,t.jsx)("div",{className:"mt-8",children:(0,t.jsx)(F,{size:"lg",className:"px-10",onClick:i,children:"View connection"})})]})}r(CGe,"ConnectionSetupCompletionScreen");function mxe(){const{newProjectOpen:e,closeNewProject:s}=a1(),{selectedCompanyId:n}=fs();return n&&e?(0,t.jsx)(_Ge,{companyId:n,onClose:s},n):null}r(mxe,"NewProjectDialog");function _Ge({companyId:e,onClose:s}){const n=Ht(),[a,i]=(0,m.useState)(""),[o,l]=(0,m.useState)([]),[c,d]=(0,m.useState)(!1),u=(0,m.useRef)(null),h=ye({mutationFn:r(()=>oa.create(e,{name:a.trim(),status:"planned",repositoryIds:o.map(p=>p.id)}),"mutationFn"),onSuccess:r(()=>{n.invalidateQueries({queryKey:P.projects.all(e)}),s()},"onSuccess")});return(0,t.jsx)(Xs,{open:!0,onOpenChange:r(p=>{!p&&!h.isPending&&s()},"onOpenChange"),children:(0,t.jsx)(Zs,{showCloseButton:!1,"aria-describedby":void 0,className:"flex max-h-(--sz-calc-18) flex-col gap-0 overflow-hidden p-0 shadow-sm sm:max-w-lg",onOpenAutoFocus:r(p=>{p.preventDefault(),u.current?.focus()},"onOpenAutoFocus"),children:c?(0,t.jsxs)("div",{className:"min-h-0 overflow-y-auto p-5",children:[(0,t.jsx)(rn,{className:"sr-only",children:"Connect GitHub"}),(0,t.jsx)(X5,{host:"dialog",serviceSlug:"github",forceNewConnection:!0,onCancel:r(()=>d(!1),"onCancel"),onComplete:r(()=>{n.invalidateQueries({queryKey:oU(e)}),d(!1)},"onComplete")})]}):(0,t.jsxs)("form",{className:"flex min-h-0 flex-col overflow-hidden",onSubmit:r(p=>{p.preventDefault(),a.trim()&&!h.isPending&&h.mutate()},"onSubmit"),children:[(0,t.jsxs)("div",{className:"flex shrink-0 flex-col gap-4 px-5 pb-4 pt-5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)(rn,{className:"text-lg font-semibold",children:"Create project"}),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-sm",disabled:h.isPending,"aria-label":"Close new project",onClick:s,children:(0,t.jsx)(nr,{className:"size-4"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-input px-3 focus-within:border-ring focus-within:ring-1 focus-within:ring-ring",children:[(0,t.jsx)(qc,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,t.jsx)("input",{ref:u,"aria-label":"Project name",value:a,disabled:h.isPending,onChange:r(p=>i(p.target.value),"onChange"),placeholder:"Project name",required:!0,className:"h-10 w-full min-w-0 border-0 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm"})]})]}),(0,t.jsx)("div",{role:"region","aria-label":"Source repositories",tabIndex:0,className:"min-h-0 overflow-y-auto overscroll-contain px-5 pb-1 outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring",children:(0,t.jsx)(Pme,{companyId:e,selected:o,onChange:l,onConnect:r(()=>d(!0),"onConnect"),disabled:h.isPending})}),h.isError&&(0,t.jsx)("p",{role:"alert",className:"px-5 pt-3 text-sm text-destructive",children:h.error.message}),(0,t.jsxs)("div",{className:"flex shrink-0 justify-end gap-2 px-5 py-5",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",disabled:h.isPending,onClick:s,children:"Cancel"}),(0,t.jsx)(F,{type:"submit",disabled:!a.trim()||h.isPending,children:h.isPending?"Creating…":"Create project"})]})]})})})}r(_Ge,"NewProjectForm");var ux={list:r(e=>Re.get(`/companies/${e}/goals`),"list"),get:r(e=>Re.get(`/goals/${e}`),"get"),create:r((e,s)=>Re.post(`/companies/${e}/goals`,s),"create"),update:r((e,s)=>Re.patch(`/goals/${e}`,s),"update"),remove:r(e=>Re.delete(`/goals/${e}`),"remove")};function hxe(e){return{"--sc":`var(${e})`}}r(hxe,"scStyle");function IGe(e){const s=e.replace(/_/g," ");return s.charAt(0).toUpperCase()+s.slice(1)}r(IGe,"sentenceCaseStatus");function ti({status:e,label:s}){return(0,t.jsx)("span",{className:U("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0",Q$[e]??"bg-muted text-muted-foreground"),children:s??e.replace(/[_-]/g," ")})}r(ti,"StatusBadge$5");function pxe({status:e}){const s=_2e[e]??"--status-agent-idle",n=e==="active"?"idle":e;return(0,t.jsx)("span",{className:"status-chip inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium leading-none whitespace-nowrap shrink-0",style:hxe(s),children:n.replace(/_/g," ")})}r(pxe,"AgentStatusBadge");function kp({status:e,externalConversationState:s}){const n=e==="in_review"&&s==="waiting"?"idle":e,a=w2e[n]??"--status-task-backlog";return(0,t.jsxs)("span",{className:U("status-chip inline-flex items-center gap-1.5 rounded-full border px-3 py-1 text-xs font-normal leading-none whitespace-nowrap shrink-0",n==="cancelled"&&"line-through"),style:hxe(a),children:[(0,t.jsx)(n1,{status:n,size:"sm"}),IGe(n)]})}r(kp,"IssueStatusBadge");var cJ={company:"Organization",team:"Team",agent:"Agent",task:"Task"};function fxe(){const{newGoalOpen:e,newGoalDefaults:s,closeNewGoal:n}=a1(),{selectedCompanyId:a,selectedCompany:i}=fs(),o=Ht(),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)("planned"),[x,g]=(0,m.useState)("task"),[v,y]=(0,m.useState)(""),[j,S]=(0,m.useState)(!1),[w,N]=(0,m.useState)(!1),[_,I]=(0,m.useState)(!1),[C,A]=(0,m.useState)(!1),R=(0,m.useRef)(null),E=v||s.parentId||"",{data:O}=ee({queryKey:P.goals.list(a),queryFn:r(()=>ux.list(a),"queryFn"),enabled:!!a&&e}),L=ye({mutationFn:r(z=>ux.create(a,z),"mutationFn"),onSuccess:r(()=>{o.invalidateQueries({queryKey:P.goals.list(a)}),T(),n()},"onSuccess")}),$=ye({mutationFn:r(async z=>{if(!a)throw new Error("No organization selected");return c0.uploadImage(a,z,"goals/drafts")},"mutationFn")});function T(){c(""),u(""),p("planned"),g("task"),y(""),S(!1)}r(T,"reset");function q(){!a||!l.trim()||L.mutate({title:l.trim(),description:d.trim()||void 0,status:h,level:x,...E?{parentId:E}:{}})}r(q,"handleSubmit");function B(z){z.key==="Enter"&&(z.metaKey||z.ctrlKey)&&(z.preventDefault(),q())}r(B,"handleKeyDown");const K=(O??[]).find(z=>z.id===E);return(0,t.jsx)(Xs,{open:e,onOpenChange:r(z=>{z||(T(),n())},"onOpenChange"),children:(0,t.jsxs)(Zs,{showCloseButton:!1,className:U("p-0 gap-0",j?"sm:max-w-2xl":"sm:max-w-lg"),onKeyDown:B,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[i&&(0,t.jsx)("span",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-medium",children:i.issuePrefix}),(0,t.jsx)("span",{className:"text-muted-foreground/60",children:"›"}),(0,t.jsx)("span",{children:s.parentId?"New sub-goal":"New goal"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:r(()=>S(!j),"onClick"),children:j?(0,t.jsx)(vz,{className:"h-3.5 w-3.5"}):(0,t.jsx)(a0,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:r(()=>{T(),n()},"onClick"),children:(0,t.jsx)("span",{className:"text-lg leading-none",children:"×"})})]})]}),(0,t.jsx)("div",{className:"px-4 pt-4 pb-2 shrink-0",children:(0,t.jsx)("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Goal title",value:l,onChange:r(z=>c(z.target.value),"onChange"),onKeyDown:r(z=>{z.key==="Tab"&&!z.shiftKey&&(z.preventDefault(),R.current?.focus())},"onKeyDown"),autoFocus:!0})}),(0,t.jsx)("div",{className:"px-4 pb-2 overflow-y-auto max-h-(--sz-50vh)",children:(0,t.jsx)(yc,{ref:R,value:d,onChange:u,placeholder:"Add description...",bordered:!1,contentClassName:U("text-sm text-muted-foreground",j?"min-h-(--sz-220px)":"min-h-(--sz-120px)"),imageUploadHandler:r(async z=>(await $.mutateAsync(z)).contentPath,"imageUploadHandler")})}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[(0,t.jsxs)(sr,{open:w,onOpenChange:N,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsx)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:(0,t.jsx)(ti,{status:h})})}),(0,t.jsx)(Gn,{className:"w-40 p-1",align:"start",children:Zoe.map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 capitalize",z===h&&"bg-accent"),onClick:r(()=>{p(z),N(!1)},"onClick"),children:z},z))})]}),(0,t.jsxs)(sr,{open:_,onOpenChange:I,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[(0,t.jsx)(hl,{className:"h-3 w-3 text-muted-foreground"}),cJ[x]??x]})}),(0,t.jsx)(Gn,{className:"w-40 p-1",align:"start",children:Hoe.map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",z===x&&"bg-accent"),onClick:r(()=>{g(z),I(!1)},"onClick"),children:cJ[z]??z},z))})]}),(0,t.jsxs)(sr,{open:C,onOpenChange:A,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[(0,t.jsx)(px,{className:"h-3 w-3 text-muted-foreground"}),K?K.title:"Parent goal"]})}),(0,t.jsxs)(Gn,{className:"w-48 p-1",align:"start",children:[(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!E&&"bg-accent"),onClick:r(()=>{y(""),A(!1)},"onClick"),children:"No parent"}),(O??[]).map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",z.id===E&&"bg-accent"),onClick:r(()=>{y(z.id),A(!1)},"onClick"),children:z.title},z.id))]})]})]}),(0,t.jsx)("div",{className:"flex items-center justify-end px-4 py-2.5 border-t border-border",children:(0,t.jsx)(F,{size:"sm",disabled:!l.trim()||L.isPending,onClick:q,children:L.isPending?"Creating…":s.parentId?"Create sub-goal":"Create goal"})})]})})}r(fxe,"NewGoalDialog");function AGe(e){const s=RGe(e),n=TGe(e);return`You're invited to join a Paperclip company as an agent.
287
+ `;function zWe(){const e=new Blob([qWe],{type:"application/javascript"}),s=URL.createObjectURL(e);try{return new Worker(s)}finally{URL.revokeObjectURL(s)}}r(zWe,"createSandboxedWorker");var gF=new Map,ST=new Map,v2=new Set,y2=new Map,yfe=null;function UWe(e){yfe=e}r(UWe,"setDynamicParserResultNotifier");function jfe(e,s){e.worker.postMessage(s)}r(jfe,"sendToWorker");function KWe(e){return e.nextId++}r(KWe,"nextRequestId");function VWe(e,s){return`${s}\0${e}`}r(VWe,"lineCacheKey");function WWe(){yfe?.()}r(WWe,"notifyResultReady");function HWe(e,s,n){return new Promise(a=>{const i=KWe(e);e.pendingResolves.set(i,a),jfe(e,{type:"parse",id:i,line:s,ts:n})})}r(HWe,"parseLineAsync");function Ak(e){for(const s of e.pendingResolves.values())s([]);e.pendingResolves.clear()}r(Ak,"drainPendingRequests");function QWe(e){return new Promise((s,n)=>{const a=zWe(),i={worker:a,ready:!1,nextId:1,pendingResolves:new Map},o=setTimeout(()=>{Ak(i),a.terminate(),n(new Error("Parser worker init timed out"))},5e3);a.onmessage=l=>{const c=l.data;if(c.type==="ready"){clearTimeout(o),i.ready=!0,a.onmessage=d=>{const u=d.data;if(u.type==="result"){const h=i.pendingResolves.get(u.id);h&&(i.pendingResolves.delete(u.id),h(u.entries))}else u.type==="error"&&Ak(i)},s(i);return}if(c.type==="error"){clearTimeout(o),Ak(i),a.terminate(),n(new Error(c.message));return}},a.onerror=l=>{clearTimeout(o),Ak(i),a.terminate(),n(new Error(`Worker error: ${l.message}`))},jfe(i,{type:"init",source:e})})}r(QWe,"initSandboxedWorker");function GWe(e){const s=new Map,n=new Set;return{parseStdoutLine:r((i,o)=>{const l=VWe(i,o),c=s.get(l);return c?c.slice():(n.has(l)||(n.add(l),HWe(e,i,o).then(d=>{n.delete(l),s.set(l,d),WWe()})),[])},"parseStdoutLine")}}r(GWe,"buildParserModule");async function bF(e){const s=ST.get(e);if(s)return s;if(v2.has(e))return null;const n=y2.get(e);if(n)return n;const a=(async()=>{try{const i=await fetch(`/api/adapters/${encodeURIComponent(e)}/ui-parser.js`);if(!i.ok)return v2.add(e),null;const o=await QWe(await i.text());gF.set(e,o);const l=GWe(o);return ST.set(e,l),l}catch{return v2.add(e),null}finally{y2.delete(e)}})();return y2.set(e,a),a}r(bF,"loadDynamicParser");function vF(e){const s=ST.has(e);ST.delete(e),v2.delete(e),y2.delete(e);const n=gF.get(e);return n&&(Ak(n),n.worker.terminate(),gF.delete(e)),s}r(vF,"invalidateDynamicParser");var j2=[],Q5=new Map,yF=new Set,wfe=new Map,N4=new Set,iI=new Map,jF=new Set;function Nfe(e){return jF.add(e),()=>jF.delete(e)}r(Nfe,"onAdapterChange");function kfe(){for(const e of jF)e()}r(kfe,"notifyAdapterChange");UWe(kfe);function YWe(){for(const e of[M7e,Q7e,h9e,v9e,z9e,tVe,hVe,wVe,PVe,UVe,hWe,iWe,E9e,AWe,kT,BWe])yF.add(e.type),wfe.set(e.type,e),ab(e)}r(YWe,"registerBuiltInUIAdapters");function ab(e){const s=j2.findIndex(n=>n.type===e.type);s>=0?j2.splice(s,1,e):j2.push(e),Q5.set(e.type,e),kfe()}r(ab,"registerUIAdapter");function Sfe(e){return Q5.get(e)??null}r(Sfe,"findUIAdapter");YWe();function Xw(e){const s=Q5.get(e);if(!s){let n=!1;return{type:e,label:e,parseStdoutLine:r((a,i)=>(n||(n=!0,bF(e).then(o=>{o&&ab({type:e,label:e,parseStdoutLine:o.parseStdoutLine,createStdoutParser:o.createStdoutParser,ConfigFields:Xb,buildAdapterConfig:aw})})),kT.parseStdoutLine(a,i)),"parseStdoutLine"),ConfigFields:Xb,buildAdapterConfig:aw}}return s}r(Xw,"getUIAdapter");function JWe(e){const s=new Set(e.filter(a=>!a.disabled&&!a.overrideDisabled).map(a=>a.type)),n=new Set(e.map(a=>a.type));for(const a of yF){const i=wfe.get(a);if(!i)continue;const o=n.has(a),l=s.has(a),c=N4.has(a);if(o&&l&&!c){N4.add(a);const d=(iI.get(a)??0)+1;iI.set(a,d);let u=!1;const h=i.parseStdoutLine,p=e.find(x=>x.type===a)?.label??a;ab({type:a,label:p,parseStdoutLine:r((x,g)=>(u||(u=!0,bF(a).then(v=>{v&&iI.get(a)===d&&ab({type:a,label:p,parseStdoutLine:v.parseStdoutLine,createStdoutParser:v.createStdoutParser,ConfigFields:i.ConfigFields,buildAdapterConfig:i.buildAdapterConfig})})),h(x,g)),"parseStdoutLine"),ConfigFields:i.ConfigFields,buildAdapterConfig:i.buildAdapterConfig})}else(!o||!l)&&c&&(N4.delete(a),iI.delete(a),vF(a),ab(i))}for(const{type:a,label:i}of e){if(yF.has(a))continue;const o=Q5.get(a);if(o&&o!==kT)continue;let l=!1;const c=o?.parseStdoutLine??kT.parseStdoutLine;ab({type:a,label:i,parseStdoutLine:r((d,u)=>(l||(l=!0,bF(a).then(h=>{h&&ab({type:a,label:i,parseStdoutLine:h.parseStdoutLine,createStdoutParser:h.createStdoutParser,ConfigFields:o?.ConfigFields??Xb,buildAdapterConfig:o?.buildAdapterConfig??aw})})),c(d,u)),"parseStdoutLine"),ConfigFields:o?.ConfigFields??Xb,buildAdapterConfig:o?.buildAdapterConfig??aw})}}r(JWe,"syncExternalAdapters");function HU(){return[...j2]}r(HU,"listUIAdapters");function XWe(e){if(typeof e=="function")return{parseLine:e,reset:null};if(e.createStdoutParser){const s=e.createStdoutParser();return{parseLine:s.parseLine,reset:s.reset}}return{parseLine:e.parseStdoutLine,reset:null}}r(XWe,"resolveStdoutParser");function Cfe(e,s){if((s.kind==="thinking"||s.kind==="assistant")&&s.delta){const n=e[e.length-1];if(n&&n.kind===s.kind&&n.delta&&n.channel===s.channel){n.text+=s.text,n.ts=s.ts;return}}e.push(s)}r(Cfe,"appendTranscriptEntry");function ZWe(e,s){for(const n of s)Cfe(e,n)}r(ZWe,"appendTranscriptEntries");function eHe(e,s=160){return e.length<=s?e:`${e.slice(0,s-3)}...`}r(eHe,"truncateTranscriptLine");function tHe(e){if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"&&e)return e;try{return JSON.stringify(e)}catch{return String(e)}}r(tHe,"formatTranscriptParserError");function sHe(e,s,n,a){const i=tHe(n)||"unknown parser error",o=eHe(e);return{kind:"result",ts:s,text:Fu(`Chat transcript error: ${i}. Falling back for line: ${o}`,a),inputTokens:0,outputTokens:0,cachedTokens:0,costUsd:0,subtype:"transcript_parse_error",isError:!0,errors:[]}}r(sHe,"createTranscriptParseErrorEntry");function CY(e){const{entries:s,line:n,ts:a,parseLine:i,reset:o,redactionOptions:l}=e;try{ZWe(s,i(n,a).map(c=>AFe(c,l)))}catch(c){o?.(),Cfe(s,sHe(n,a,c,l))}}r(CY,"appendParsedTranscriptLine");function _fe(e,s,n){const a=[];let i="";const o={enabled:n?.censorUsernameInLogs??!1},{parseLine:l,reset:c}=XWe(s);for(const u of e){if(u.stream==="stderr"){a.push({kind:"stderr",ts:u.ts,text:Fu(u.chunk,o)});continue}if(u.stream==="system"){a.push({kind:"system",ts:u.ts,text:Fu(u.chunk,o)});continue}const h=(i+u.chunk).split(/\r?\n/);i=h.pop()??"";for(const p of h){const x=p.trim();x&&CY({entries:a,line:x,ts:u.ts,parseLine:l,reset:c,redactionOptions:o})}}const d=i.trim();return d&&CY({entries:a,line:d,ts:e.length>0?e[e.length-1].ts:new Date().toISOString(),parseLine:l,reset:c,redactionOptions:o}),c?.(),a}r(_fe,"buildTranscript");function nHe({agents:e,value:s,onChange:n,disabled:a=!1,excludeAgentIds:i=[],disabledEmptyLabel:o="Reports to: N/A (CEO)",chooseLabel:l="Reports to..."}){const[c,d]=(0,m.useState)(!1),u=new Set(i),h=e.filter(v=>v.status!=="terminated"&&!u.has(v.id)),p=s?e.find(v=>v.id===s):null,x=p?.status==="terminated",g=!!(s&&!p);return(0,t.jsxs)(sr,{open:c,onOpenChange:d,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:U("inline-flex max-w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",x&&"border-amber-600/45 bg-amber-500/5",a&&"opacity-60 cursor-not-allowed"),disabled:a,children:g?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(xc,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate text-muted-foreground",children:"Unknown manager (stale ID)"})]}):p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(hr,{agent:p,size:16,className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:U("min-w-0 truncate",x&&"text-amber-900 dark:text-amber-200"),children:`Reports to ${p.name}${x?" (terminated)":""}`})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(xc,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:a?o:l})]})})}),(0,t.jsxs)(Gn,{className:"w-48 p-1",align:"start",children:[(0,t.jsx)("button",{type:"button",className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",s===null&&"bg-accent"),onClick:r(()=>{n(null),d(!1)},"onClick"),children:"No manager"}),x&&(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:[(0,t.jsx)(hr,{agent:p,size:16,className:"shrink-0 h-3 w-3"}),(0,t.jsxs)("span",{className:"min-w-0 truncate",children:["Current: ",p.name," (terminated)"]})]}),g&&(0,t.jsx)("div",{className:"px-2 py-1.5 text-xs text-muted-foreground border-b border-border mb-0.5",children:"Saved manager is missing from this organization. Choose a new manager or clear."}),h.map(v=>(0,t.jsxs)("button",{type:"button",className:U("flex items-center gap-2 w-full min-w-0 px-2 py-1.5 text-xs rounded hover:bg-accent/50 overflow-hidden",v.id===s&&"bg-accent"),onClick:r(()=>{n(v.id),d(!1)},"onClick"),children:[(0,t.jsx)(hr,{agent:v,size:16,className:"shrink-0 h-3 w-3 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:v.name}),(0,t.jsx)("span",{className:"text-muted-foreground ml-auto shrink-0",children:UU[v.role]??v.role})]},v.id))]})]})}r(nHe,"ReportsToPicker");var rHe="__secret_folder__:";function aHe(e){return!e||e==="active"?null:(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) font-normal text-muted-foreground",children:e})}r(aHe,"statusBadge");function Ife(e){return e.split("/").filter(s=>s.length>0)}r(Ife,"splitSecretPath$1");function w2(e){return e.join("/")}r(w2,"pathKey$1");function KN(e){return e.length>0?`/${e.join("/")}`:"/"}r(KN,"pathLabel");function iHe(e,s){return e.length<s.length?!1:s.every((n,a)=>e[a]===n)}r(iHe,"pathStartsWith");function _Y(e){return`${rHe}${w2(e)}`}r(_Y,"folderValue");function oHe(e,s,n){const a=s.length,i=new Map,o=[];for(const c of e){const d=Ife(c.name);if(iHe(d,s)){if(d.length>a+1){const u=d.slice(0,a+1),h=w2(u);if(!i.has(h)){const p=u[u.length-1]??"/",x=KN(u);i.set(h,{key:`folder-${h||"root"}`,value:_Y(u),label:p,title:x,searchText:x,kind:"folder",folderPath:h,pathHint:x})}continue}if(d.length===a+1||a===0&&d.length===0){const u=d.at(-1)??c.name;o.push({key:`browse-${c.id}`,value:c.id,label:u,title:c.name,searchText:`${c.key} ${c.name}`,secret:c,status:c.status,kind:"secret",pathHint:c.name,disabled:c.status!=="active"&&c.id!==n})}}}const l=[];if(s.length>0){const c=s.slice(0,-1);l.push({key:`folder-up-${w2(s)}`,value:_Y(c),label:"Up one folder",title:KN(c),searchText:KN(c),kind:"back",folderPath:w2(c),pathHint:KN(c)})}return l.push(...i.values(),...o),{id:"browse-secrets",label:s.length>0?KN(s):"Browse secrets",options:l}}r(oHe,"buildFolderGroup");function QU({secretId:e,secrets:s,recentlyUsedSecrets:n,disabled:a,onSelect:i,onCreateNew:o,triggerClassName:l,disablePortal:c}){const[d,u]=(0,m.useState)(""),h=(0,m.useMemo)(()=>s.find(j=>j.id===e)??null,[s,e]),p=!!e&&!h,x=(0,m.useMemo)(()=>d?d.split("/"):[],[d]),g=(0,m.useMemo)(()=>s.some(j=>Ife(j.name).length>1),[s]),v=(0,m.useMemo)(()=>{const j=[];p&&j.push({id:"current-missing",label:"Current",options:[{key:`missing-${e}`,value:e,label:`Missing secret (${e.slice(0,8)}…)`,title:`Missing secret (${e})`,missing:!0,disabled:!0}]});const S=(n??[]).filter(w=>w.status==="active"&&w.id!==e);return S.length>0&&j.push({id:"recently-used",label:"Recently used",options:S.map(w=>({key:`recent-${w.id}`,value:w.id,label:w.name,title:w.name,searchText:`${w.key} ${w.name}`,secret:w,status:w.status,kind:"secret"}))}),j.push({id:"all-secrets",label:S.length>0?"All secrets":void 0,options:s.map(w=>({key:`all-${w.id}`,value:w.id,label:w.name,title:w.name,searchText:`${w.key} ${w.name}`,secret:w,status:w.status,kind:"secret",disabled:w.status!=="active"&&w.id!==e}))}),j},[p,n,e,s]),y=(0,m.useCallback)((j,S)=>{if(!g||m2e(j))return S;const w=oHe(s,x,e),N=S.filter(_=>_.id==="current-missing"||_.id==="recently-used");return w.options.length>0?[...N,w]:N},[x,g,e,s]);return(0,t.jsx)(jv,{value:e||"",groups:v,onValueChange:r((j,S)=>{if(S.folderPath!==void 0)return u(S.folderPath),!1;u(""),i(j)},"onValueChange"),deriveGroups:y,disabled:a,disablePortal:c,placeholder:"Select secret…",searchPlaceholder:"Search secrets…",emptyMessage:"No matching secrets",triggerClassName:U("h-(--sz-34px) min-h-(--sz-34px) font-mono text-sm",p&&"border-destructive text-destructive",h&&h.status!=="active"&&"border-amber-500/60",l),renderValue:r(j=>{if(!j)return(0,t.jsx)("span",{className:"text-muted-foreground",children:"Select secret…"});if(j.missing)return(0,t.jsxs)("span",{className:"flex w-full min-w-0 items-center gap-1.5 text-destructive",children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:j.label})]});const S=j.status&&j.status!=="active";return(0,t.jsxs)("span",{className:"flex w-full min-w-0 items-center gap-1.5",title:j.title,children:[(0,t.jsx)(ji,{className:U("size-3.5 shrink-0",S?"text-amber-600":"text-muted-foreground")}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:j.label}),S?(0,t.jsxs)("span",{className:"text-amber-600",children:["(",j.status,")"]}):null]})},"renderValue"),renderOption:r((j,{selected:S})=>{if(j.kind==="folder"||j.kind==="back"){const w=j.kind==="back"?JTe:qc;return(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",title:j.title??j.label,children:[(0,t.jsx)(w,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsxs)("span",{className:"flex min-w-0 flex-col",children:[(0,t.jsx)("span",{className:U("truncate text-sm",S&&"font-medium"),children:j.label}),j.pathHint?(0,t.jsx)("span",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground",children:j.pathHint}):null]})]})}return(0,t.jsxs)("span",{className:U("flex min-w-0 flex-1 items-center gap-1.5",j.disabled&&"opacity-60"),title:j.title??j.label,children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsxs)("span",{className:"flex min-w-0 flex-col",children:[(0,t.jsx)("span",{className:U("min-w-0 truncate font-mono text-sm",S&&"font-medium"),children:j.label}),j.pathHint&&j.pathHint!==j.label?(0,t.jsx)("span",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground",children:j.pathHint}):null]}),aHe(j.status)]})},"renderOption"),createItem:o?{render:r(j=>(0,t.jsxs)("span",{className:"flex items-center gap-1.5 text-sm",children:[(0,t.jsx)(xn,{className:"size-3.5 shrink-0"}),j.trim()?(0,t.jsxs)("span",{children:["Create secret ",(0,t.jsxs)("span",{className:"font-mono",children:["“",j.trim(),"”"]}),"…"]}):(0,t.jsx)("span",{children:"Create new secret…"})]}),"render"),onSelect:r(j=>o(j),"onSelect")}:void 0})}r(QU,"SecretPicker");var lHe=/^[a-z][a-z0-9_]*$/,IY="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/40";function Afe({mode:e,initialName:s,initialValue:n,existingSecretNames:a,onCancel:i,onSubmit:o}){const[l,c]=(0,m.useState)(s),[d,u]=(0,m.useState)(n),[h,p]=(0,m.useState)(!1),[x,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),[j,S]=(0,m.useState)(!1),w=l.trim(),N=w?lHe.test(w)?a?.some(R=>R.toLowerCase()===w)?"A secret with this name already exists":null:"Use lowercase letters, digits and _":j?"Name is required":null,_=d.length===0&&j?"Value is required":null,I=!x&&w.length>0&&d.length>0&&!N;async function C(){if(S(!0),!!I){g(!0),y(null);try{await o(w,d)}catch(R){y(R instanceof Error?R.message:"Failed to create secret"),g(!1)}}}r(C,"handleSubmit");const A=e==="create"?"Create & bind":"Store & bind";return(0,t.jsxs)("div",{className:"w-72 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(f2e,{className:"text-sm font-medium",children:e==="create"?"Create secret":"Store value as secret"}),e==="store"?(0,t.jsxs)(p2e,{className:"text-(length:--text-micro) text-muted-foreground",children:["Moves the typed value into an encrypted organization secret and binds"," ",(0,t.jsx)("span",{className:"font-mono",children:s||"this variable"})," to it."]}):null]}),(0,t.jsxs)("label",{className:"block space-y-1",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium text-muted-foreground",children:"Name"}),(0,t.jsx)("input",{className:U(IY,N&&"border-destructive focus-visible:ring-destructive/40"),value:l,autoFocus:!0,spellCheck:!1,placeholder:"secret_name","aria-label":"Secret name","aria-invalid":N?!0:void 0,onChange:r(R=>c(R.target.value),"onChange"),onBlur:r(()=>S(!0),"onBlur"),onKeyDown:r(R=>{R.key==="Enter"&&(R.preventDefault(),C())},"onKeyDown")}),N?(0,t.jsx)("span",{className:"block text-(length:--text-micro) text-destructive",children:N}):null]}),(0,t.jsxs)("label",{className:"block space-y-1",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium text-muted-foreground",children:"Value"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{className:U(IY,"pr-8",_&&"border-destructive focus-visible:ring-destructive/40"),type:h?"text":"password",value:d,readOnly:e==="store",spellCheck:!1,placeholder:e==="create"?"value":void 0,"aria-label":"Secret value","aria-invalid":_?!0:void 0,onChange:e==="create"?R=>u(R.target.value):void 0}),(0,t.jsx)("button",{type:"button",className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:text-foreground","aria-label":h?"Hide value":"Show value",onClick:r(()=>p(R=>!R),"onClick"),children:h?(0,t.jsx)(Hm,{className:"h-3.5 w-3.5"}):(0,t.jsx)(cd,{className:"h-3.5 w-3.5"})})]}),_?(0,t.jsx)("span",{className:"block text-(length:--text-micro) text-destructive",children:_}):null]}),v?(0,t.jsx)("p",{className:"text-(length:--text-micro) text-destructive",children:v}):null,(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2 pt-0.5",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",onClick:i,disabled:x,children:"Cancel"}),(0,t.jsxs)(F,{type:"button",size:"sm",onClick:r(()=>{C()},"onClick"),disabled:!I,children:[x?(0,t.jsx)(ot,{className:"h-3.5 w-3.5 animate-spin"}):null,A]})]})]})}r(Afe,"SecretPopoverForm");function Rfe(e){return(0,t.jsx)(Afe,{mode:"create",...e})}r(Rfe,"CreateSecretPopover");function cHe(e){return(0,t.jsx)(Afe,{mode:"store",...e})}r(cHe,"ConvertToSecretPopover");var dHe=/(api[-_]?key|access[-_]?token|auth(?:_?token)?|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring)/i,uHe=[/^sk-[A-Za-z0-9-_]{16,}$/,/^gh[pousr]_[A-Za-z0-9]{20,}$/,/^github_pat_[A-Za-z0-9_]{20,}$/,/^xox[baprs]-[A-Za-z0-9-]{10,}$/,/^AKIA[0-9A-Z]{16}$/,/^AIza[0-9A-Za-z\-_]{20,}$/,/-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----/,/^eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/];function mHe(e){return e.length<24||/\s/.test(e)||!/^[A-Za-z0-9+/=_\-.]+$/.test(e)?!1:[/[a-z]/.test(e),/[A-Z]/.test(e),/[0-9]/.test(e)].filter(Boolean).length>=2}r(mHe,"looksHighEntropy");function hHe(e,s){return s?dHe.test(e)||uHe.some(n=>n.test(s))?!0:mHe(s):!1}r(hHe,"isSensitiveEnv");var AY=0;function pHe(){return AY+=1,`env-row-${AY}`}r(pHe,"nextRowId");function ex(e="text"){return{id:pHe(),name:"",source:e,textValue:"",secretId:"",userSecretKey:"",required:!0,version:"latest"}}r(ex,"emptyRow");function fHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="secret_ref"}r(fHe,"isSecretRef");function xHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="plain"}r(xHe,"isPlainObj");function gHe(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="user_secret_ref"}r(gHe,"isUserSecretRef");function k4(e){return!e||typeof e!="object"?[]:Object.entries(e).map(([s,n])=>{if(typeof n=="string")return{...ex(),name:s,textValue:n};if(fHe(n)){const a=typeof n.version=="number"?n.version:"latest";return{...ex(),name:s,source:"secret",secretId:typeof n.secretId=="string"?n.secretId:"",version:a}}if(gHe(n)){const a=typeof n.version=="number"?n.version:"latest";return{...ex(),name:s,source:"user_secret",userSecretKey:typeof n.key=="string"?n.key:"",required:n.required!==!1,version:a}}return xHe(n)?{...ex(),name:s,source:"text",textValue:typeof n.value=="string"?n.value:""}:{...ex(),name:s}})}r(k4,"rowsFromValue");function N2(e){const s={};for(const n of e){const a=n.name.trim();if(a)if(n.source==="secret"){if(!n.secretId)continue;s[a]={type:"secret_ref",secretId:n.secretId,version:n.version}}else if(n.source==="user_secret"){const i=n.userSecretKey.trim();if(!i)continue;s[a]={type:"user_secret_ref",key:i,version:n.version,required:n.required}}else s[a]={type:"plain",value:n.textValue}}return Object.keys(s).length>0?s:void 0}r(N2,"valueFromRows");var RY="CLAUDE_CODE_OAUTH_TOKEN";function sj(){return N2([{...ex("user_secret"),name:"CLAUDE_CODE_OAUTH_TOKEN",userSecretKey:"CLAUDE_CODE_OAUTH_TOKEN",required:!0,version:"latest"}])??{}}r(sj,"buildFixedClaudeOAuthBinding");var bHe=/^[A-Za-z_][A-Za-z0-9_]*$/;function vHe(e,s,n){const a=e.trim();if(!a)return null;if(!bHe.test(a))return{level:"error",message:"Invalid name — use letters, digits and _"};if(s.has(a))return{level:"error",message:"Duplicate name"};for(const i of n)if(i&&a.startsWith(i))return{level:"warn",message:"Reserved prefix — provided automatically and may be overridden"};return null}r(vHe,"validateName");function yHe(e){const s=new Map;for(const a of e){const i=a.name.trim();i&&s.set(i,(s.get(i)??0)+1)}const n=new Set;for(const[a,i]of s)i>1&&n.add(a);return n}r(yHe,"computeDuplicateNames");function jHe(e,s){return s===e.source?{kind:"noop"}:s==="secret"?e.textValue.trim()?{kind:"open-store",name:CT(e.name)||"secret",value:e.textValue}:{kind:"to-secret"}:{kind:"to-text",undoFrom:e.secretId?{...e}:null}}r(jHe,"planSourceSwitch");function Tfe(e,s){if(e.source!=="secret"||!e.secretId)return null;const n=s.find(a=>a.id===e.secretId);return n?n.status!=="active"?{level:"warn",kind:"disabled",message:"Runs will fail until re-enabled or rebound."}:null:{level:"error",kind:"missing",message:"This secret no longer exists — runs will fail until you rebind."}}r(Tfe,"computeRowHealth");function Efe(e,s){if(e.source!=="user_secret"||!e.userSecretKey||!s?.length)return null;const n=s.find(a=>a.key===e.userSecretKey);return n?n.status!=="active"?{level:"warn",kind:"disabled",message:"Runs will fail until this user secret definition is re-enabled or rebound."}:null:{level:"error",kind:"missing",message:"This user secret definition no longer exists — runs will fail until you rebind."}}r(Efe,"computeUserSecretRowHealth");function CT(e){return e.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)}r(CT,"secretNameFromKey");function pS(e){return e.trim().toUpperCase().replace(/[^A-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)}r(pS,"envKeyFromSecretName");var wHe="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/40",TY="min-w-0 flex-1 bg-transparent px-2 py-1.5 text-sm font-mono outline-none placeholder:text-muted-foreground/40";function NHe({row:e,isLast:s,secrets:n,userSecretDefinitions:a,recentlyUsedSecrets:i,disabled:o,nameIssue:l,showNameIssue:c,dirtyFields:d,onPatch:u,onRemove:h,onNameBlur:p,onNamePaste:x,onEnterInValueLast:g,onCreateSecret:v,onToast:y,focusRequest:j,onFocusConsumed:S}){const w=(0,m.useRef)(null),N=(0,m.useRef)(null),_=(0,m.useRef)(null),[I,C]=(0,m.useState)(null),[A,R]=(0,m.useState)(!1),[E,O]=(0,m.useState)(null),L=Tfe(e,n)??Efe(e,a),$=e.source==="secret"?n.find(X=>X.id===e.secretId)??null:null,T=(a?.length??0)>0,q=e.source==="text"&&!e.sensitiveDismissed&&hHe(e.name,e.textValue);(0,m.useEffect)(()=>{j&&(j==="name"?w.current?.focus():e.source==="text"?N.current?.focus():e.source==="secret"?_.current?.querySelector("[role=combobox]")?.focus():_.current?.querySelector("select,input")?.focus(),S())},[j,S,e.source]),(0,m.useEffect)(()=>{if(!E)return;const X=window.setTimeout(()=>O(null),5e3);return()=>window.clearTimeout(X)},[E]);function B(X){if(X==="user_secret"){if(e.source==="user_secret")return;u({source:"user_secret",secretId:"",version:"latest"}),window.setTimeout(()=>_.current?.querySelector("select,input")?.focus(),0);return}const le=jHe(e,X);switch(le.kind){case"noop":return;case"open-store":{const{name:oe,value:te}=le;window.setTimeout(()=>C({mode:"store",name:oe,value:te}),0);return}case"to-secret":u({source:"secret",userSecretKey:"",required:!0}),window.setTimeout(()=>{_.current?.querySelector("[role=combobox]")?.focus()},0);return;case"to-text":le.undoFrom&&O(le.undoFrom),u({source:"text",secretId:"",userSecretKey:"",required:!0,version:"latest"}),window.setTimeout(()=>N.current?.focus(),0);return}}r(B,"switchSource");async function K(X,le){const oe=await v(X,le);u({source:"secret",secretId:oe.id,userSecretKey:"",required:!0,version:"latest",textValue:""}),y(`Secret ${oe.name} created`),C(null)}r(K,"submitSecretPopover");function z(){const X=CT(e.name)||"secret",{textValue:le}=e;window.setTimeout(()=>C({mode:"store",name:X,value:le}),0)}r(z,"openStoreAsSecret");const D=e.source==="text"?"Text value":e.source==="secret"?"Organization secret reference":"User secret reference",V=`${e.id}-name-error`,H=`${e.id}-health`,Z=d.name||d.value,Y=$?Math.max(0,$.latestVersion):0,ie=e.version==="latest"?"latest":`v${e.version}`,se=e.version!=="latest";return(0,t.jsxs)("div",{className:U("group/row grid grid-cols-(--gtc-13) items-start gap-x-1.5 gap-y-1 rounded-md px-1 py-1","@[40rem]/env:grid-cols-(--gtc-14) @[40rem]/env:items-center",Z&&"bg-amber-500/[0.06] ring-1 ring-amber-500/20"),children:[(0,t.jsx)("div",{className:"col-start-1 row-start-1 min-w-0 @[40rem]/env:row-start-1 @[40rem]/env:self-start",children:(0,t.jsx)("input",{ref:w,className:U(wHe,d.name&&"border-amber-500/70 bg-amber-500/10 focus-visible:ring-amber-500/40",c&&l?.level==="error"&&"border-destructive focus-visible:ring-destructive/40",c&&l?.level==="warn"&&"border-amber-500 focus-visible:ring-amber-500/40"),placeholder:"KEY",value:e.name,spellCheck:!1,disabled:o,"aria-label":"Variable name","aria-invalid":c&&l?.level==="error"?!0:void 0,"aria-describedby":c&&l?V:void 0,onChange:r(X=>u({name:X.target.value}),"onChange"),onBlur:p,onPaste:r(X=>{e.name||x(X.clipboardData.getData("text"))&&X.preventDefault()},"onPaste"),onKeyDown:r(X=>{X.key==="Enter"&&(X.preventDefault(),e.source==="text"?N.current?.focus():_.current?.querySelector("[role=combobox],select,input")?.focus())},"onKeyDown")})}),(0,t.jsxs)("div",{className:"col-span-2 col-start-1 row-start-2 min-w-0 @[40rem]/env:col-span-1 @[40rem]/env:col-start-2 @[40rem]/env:row-start-1",children:[(0,t.jsxs)(sr,{open:I!==null,onOpenChange:r(X=>{X||C(null)},"onOpenChange"),children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsxs)("div",{ref:_,className:U("relative flex items-stretch overflow-hidden rounded-md border border-border bg-transparent focus-within:ring-2 focus-within:ring-ring/40",d.value&&"border-amber-500/70 bg-amber-500/10 focus-within:ring-amber-500/40",o&&"opacity-60"),children:[(0,t.jsxs)(xa,{children:[(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(fa,{asChild:!0,disabled:o,children:(0,t.jsxs)("button",{type:"button","aria-label":"Value source",className:"flex shrink-0 items-center gap-0.5 border-r border-border px-2 text-muted-foreground hover:bg-accent/50 disabled:pointer-events-none",children:[e.source==="text"?(0,t.jsx)(LEe,{className:"size-3.5"}):e.source==="secret"?(0,t.jsx)(ji,{className:"size-3.5"}):(0,t.jsx)(pu,{className:"size-3.5"}),(0,t.jsx)(en,{className:"size-3 opacity-60"})]})})}),(0,t.jsx)(Kn,{side:"top",children:D})]}),(0,t.jsxs)(ga,{align:"start",className:"w-56",children:[(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("text"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"Text value"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Store the value inline as plain text."})]}),(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("secret"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"Organization secret"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Resolve a stored organization secret at run start."})]}),(0,t.jsxs)(ps,{className:"flex-col items-start gap-0.5",onSelect:r(()=>B("user_secret"),"onSelect"),children:[(0,t.jsx)("span",{className:"text-sm",children:"User secret"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"Resolve the responsible user's own value at run start."})]})]})]}),e.source==="text"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("input",{ref:N,className:TY,placeholder:"value",value:e.textValue,type:q?"password":"text",spellCheck:!1,disabled:o,"aria-label":"Variable value",onChange:r(X=>u({textValue:X.target.value}),"onChange"),onKeyDown:r(X=>{X.key==="Enter"&&s&&(X.preventDefault(),g())},"onKeyDown")}),q?(0,t.jsxs)("div",{className:"flex shrink-0 items-stretch border-l border-border",children:[(0,t.jsxs)("button",{type:"button",onClick:z,disabled:o,className:"flex items-center gap-1 px-2 text-(length:--text-micro) text-amber-700 hover:bg-amber-500/10 dark:text-amber-400",title:"This value looks sensitive — store it as a secret",children:[(0,t.jsx)(wl,{className:"size-3.5"}),(0,t.jsx)("span",{className:"hidden @[30rem]/env:inline",children:"Store as secret"})]}),(0,t.jsx)("button",{type:"button",onClick:r(()=>u({sensitiveDismissed:!0}),"onClick"),disabled:o,"aria-label":"Dismiss sensitive-value suggestion",title:"Dismiss — keep this value as plain text",className:"flex items-center px-1.5 text-amber-700/60 hover:bg-amber-500/10 hover:text-amber-700 dark:text-amber-400/60 dark:hover:text-amber-400",children:(0,t.jsx)(nr,{className:"size-3"})})]}):null]}):e.source==="secret"?(0,t.jsxs)("div",{className:"relative min-w-0 flex-1",children:[(0,t.jsx)(QU,{secretId:e.secretId,secrets:n,recentlyUsedSecrets:i,disabled:o,onSelect:r(X=>u({secretId:X,version:"latest"}),"onSelect"),onCreateNew:r(X=>C({mode:"create",name:CT(X)||X.trim(),value:""}),"onCreateNew"),triggerClassName:U("rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0",$&&$.status==="active"&&"pr-24 has-[>svg]:!pr-24")}),$&&$.status==="active"?(0,t.jsxs)(sr,{open:A,onOpenChange:R,children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsx)("button",{type:"button",disabled:o,onClick:r(X=>{X.preventDefault(),X.stopPropagation(),R(le=>!le)},"onClick"),"aria-label":"Version",className:U("absolute right-8 top-1/2 z-10 -translate-y-1/2 rounded px-1.5 py-0.5 text-(length:--text-nano) font-medium",se?"bg-amber-500/15 text-amber-700 dark:text-amber-400":"text-muted-foreground hover:bg-accent"),children:ie})}),(0,t.jsxs)(Gn,{align:"end",className:"w-44 p-1",role:"radiogroup","aria-label":"Secret version",children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":e.version==="latest",onClick:r(()=>{u({version:"latest"}),R(!1)},"onClick"),className:U("flex w-full items-center justify-between rounded px-2 py-1.5 text-sm hover:bg-accent",e.version==="latest"&&"font-medium"),children:["latest ",(0,t.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground",children:"(recommended)"})]}),Array.from({length:Y},(X,le)=>Y-le).filter(X=>X>0).map(X=>(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":e.version===X,onClick:r(()=>{u({version:X}),R(!1)},"onClick"),className:U("flex w-full items-center rounded px-2 py-1.5 text-sm hover:bg-accent",e.version===X&&"font-medium text-amber-700 dark:text-amber-400"),children:["v",X]},X))]})]}):null]}):(0,t.jsxs)("div",{className:"grid min-w-0 flex-1 grid-cols-(--gtc-13)",children:[T?(0,t.jsxs)("select",{"aria-label":"User secret",value:e.userSecretKey,disabled:o,onChange:r(X=>{const le=X.target.value,oe=a?.find(te=>te.key===le);u({userSecretKey:le,...oe&&!e.name.trim()?{name:oe.key.toUpperCase()}:{}})},"onChange"),className:"min-w-0 bg-transparent px-2 py-1.5 text-sm font-mono outline-none disabled:pointer-events-none",children:[(0,t.jsx)("option",{value:"",children:"Select user secret..."}),e.userSecretKey&&!a?.some(X=>X.key===e.userSecretKey)?(0,t.jsxs)("option",{value:e.userSecretKey,children:["Unknown (",e.userSecretKey,")"]}):null,(a??[]).map(X=>(0,t.jsxs)("option",{value:X.key,children:[X.name,X.status!=="active"?` (${X.status})`:""]},X.id))]}):(0,t.jsx)("input",{className:TY,placeholder:"user-secret key",value:e.userSecretKey,spellCheck:!1,disabled:o,"aria-label":"User secret key",onChange:r(X=>u({userSecretKey:X.target.value}),"onChange")}),(0,t.jsxs)("select",{"aria-label":"Requirement",value:e.required?"required":"optional",disabled:o,onChange:r(X=>u({required:X.target.value==="required"}),"onChange"),className:"border-l border-border bg-transparent px-2 py-1.5 text-xs font-medium text-muted-foreground outline-none disabled:pointer-events-none",children:[(0,t.jsx)("option",{value:"required",children:"Required"}),(0,t.jsx)("option",{value:"optional",children:"Optional"})]})]})]})}),(0,t.jsx)(Gn,{align:"start",className:"w-auto p-3",onInteractOutside:r(X=>{const le=X.detail.originalEvent.target;le&&_.current?.contains(le)&&X.preventDefault()},"onInteractOutside"),children:I?.mode==="store"?(0,t.jsx)(cHe,{initialName:I.name,initialValue:I.value,existingSecretNames:n.map(X=>X.name),onCancel:r(()=>C(null),"onCancel"),onSubmit:K}):I?.mode==="create"?(0,t.jsx)(Rfe,{initialName:I.name,initialValue:I.value,existingSecretNames:n.map(X=>X.name),onCancel:r(()=>C(null),"onCancel"),onSubmit:K}):null})]}),L?(0,t.jsx)("p",{id:H,role:"status",className:U("mt-0.5 text-(length:--text-micro)",L.level==="error"?"text-destructive":"text-amber-600 dark:text-amber-400"),children:L.message}):null,E?(0,t.jsxs)("p",{className:"mt-0.5 inline-flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:["Reverted to text —"," ",(0,t.jsx)("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2 hover:text-primary",onClick:r(()=>{u({source:"secret",secretId:E.secretId,version:E.version,textValue:""}),O(null)},"onClick"),children:"Undo"})]}):null]}),c&&l?(0,t.jsx)("p",{id:V,className:U("col-span-2 col-start-1 row-start-3 min-w-0 text-(length:--text-micro) @[40rem]/env:col-span-2 @[40rem]/env:row-start-2",l.level==="error"?"text-destructive":"text-amber-600 dark:text-amber-400"),children:l.message}):null,(0,t.jsxs)("div",{className:"col-start-2 row-start-1 flex items-center justify-end gap-0.5 self-start @[40rem]/env:col-start-3 @[40rem]/env:self-center",children:[e.source==="text"&&!q&&(e.name.trim()||e.textValue)?(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,disabled:o,children:(0,t.jsx)("button",{type:"button","aria-label":"More actions",className:"rounded p-1 text-muted-foreground opacity-100 hover:bg-accent hover:text-foreground @[40rem]/env:opacity-0 @[40rem]/env:group-hover/row:opacity-100 @[40rem]/env:group-focus-within/row:opacity-100",children:(0,t.jsx)(Pi,{className:"size-4"})})}),(0,t.jsx)(ga,{align:"end",children:(0,t.jsx)(ps,{onSelect:r(()=>{window.setTimeout(z,0)},"onSelect"),children:"Store as secret…"})})]}):null,(0,t.jsx)("button",{type:"button",onClick:h,disabled:o,"aria-label":`Remove ${e.name.trim()||"variable"}`,className:"rounded p-1 text-muted-foreground opacity-100 hover:bg-destructive/10 hover:text-destructive @[40rem]/env:opacity-0 @[40rem]/env:group-hover/row:opacity-100 @[40rem]/env:group-focus-within/row:opacity-100",children:(0,t.jsx)(nr,{className:"size-4"})})]})]})}r(NHe,"EnvironmentVariableRow");var kHe=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;function SHe(e){const s=e.indexOf(" #");return s>=0?e.slice(0,s):e}r(SHe,"stripInlineComment");function CHe(e){const s=e.trim();if(s.length>=2){const n=s[0],a=s[s.length-1];if(n==='"'&&a==='"'||n==="'"&&a==="'")return s.slice(1,-1)}return SHe(s).trim()}r(CHe,"unquote");function _He(e){const s=[];for(const n of e.split(/\r?\n/)){const a=n.trim();if(!a||a.startsWith("#"))continue;const i=kHe.exec(a);if(!i)continue;const o=i[1],l=CHe(i[2]);s.push({key:o,value:l})}return s}r(_He,"parseDotenv");var IHe=["PAPERCLIP_"],AHe="Set the KEY to the env var name the process expects, for example GH_TOKEN. Choose a secret to resolve a stored value at run start. PAPERCLIP_* variables are injected automatically.";function wF(e){if(!e||typeof e!="object")return[];const s=new Map;for(const[n,a]of Object.entries(e)){const i=n.trim();if(i)if(typeof a=="string")s.set(i,{type:"plain",value:a});else if(a?.type==="secret_ref"){const o=typeof a.secretId=="string"?a.secretId:"";if(!o)continue;s.set(i,{type:"secret_ref",secretId:o,version:typeof a.version=="number"?a.version:"latest"})}else if(a?.type==="user_secret_ref"){const o=typeof a.key=="string"?a.key.trim():"";if(!o)continue;s.set(i,{type:"user_secret_ref",key:o,version:typeof a.version=="number"?a.version:"latest",required:a.required!==!1})}else a?.type==="plain"?s.set(i,{type:"plain",value:typeof a.value=="string"?a.value:""}):s.set(i,{type:"plain",value:""})}return[...s.entries()].sort(([n],[a])=>n.localeCompare(a))}r(wF,"normalizedEnvEntries");function VN(e){return JSON.stringify(wF(e))}r(VN,"normalizedEnvKey");var S4=3;function C4(e){const s=e.slice(0,S4).join(", ");return e.length>S4?`${s} +${e.length-S4} more`:s}r(C4,"formatChangedNames");function EY(e){return e.map(s=>({...s}))}r(EY,"cloneRows");function RHe(e,s){return s?{name:e.name.trim()!==s.name.trim(),value:e.source!==s.source||e.textValue!==s.textValue||e.secretId!==s.secretId||e.userSecretKey!==s.userSecretKey||e.required!==s.required||e.version!==s.version}:{name:!!e.name.trim(),value:e.source!=="text"||!!e.textValue||!!e.secretId||e.version!=="latest"}}r(RHe,"rowDirtyFields");var Zb=(0,m.forwardRef)(r(function({value:s,onChange:n,secrets:a,userSecretDefinitions:i,onCreateSecret:o,recentlyUsedSecrets:l,disabled:c,reservedPrefixes:d=IHe,footerHint:u,onDirtyChange:h,hideDraftActions:p=!1},x){const g=Nc(),v=(0,m.useRef)(null),[y,j]=(0,m.useState)(()=>k4(s)),S=(0,m.useRef)(y),[w,N]=(0,m.useState)(()=>EY(y)),_=(0,m.useMemo)(()=>VN(s),[]),I=(0,m.useRef)(_),C=(0,m.useRef)(_),A=(0,m.useRef)(null),[R,E]=(0,m.useState)(_),[O,L]=(0,m.useState)(()=>new Set(k4(s).map(de=>de.name.trim()).filter(Boolean))),[$,T]=(0,m.useState)(null);(0,m.useEffect)(()=>{S.current=y},[y]);function q(de,ve=S.current){I.current=de,E(de),N(EY(ve))}r(q,"markCommitted");function B(de){L(ve=>{const Te=new Set(ve);for(const fe of de){const Ce=fe.name.trim();Ce&&Te.add(Ce)}return Te})}r(B,"touchCommittedNames");function K(de){const ve=k4(de);return j(ve),B(ve),ve}r(K,"adoptExternalValue"),(0,m.useEffect)(()=>{const de=VN(s);if(de===C.current)return;C.current=de;const ve=VN(N2(S.current)),Te=ve!==I.current,fe=A.current===de;if(fe&&(A.current=null),!Te){q(de,K(s));return}(fe||ve===de)&&(B(S.current),q(de))},[s]);const z=(0,m.useMemo)(()=>N2(y),[y]),D=(0,m.useMemo)(()=>VN(z),[z]),V=D!==R;(0,m.useEffect)(()=>{h?.(!c&&V)},[c,V,h]);const H=(0,m.useMemo)(()=>{const de=new Map(wF(N2(w)).map(([Ce,Xe])=>[Ce,JSON.stringify(Xe)])),ve=new Map(wF(z).map(([Ce,Xe])=>[Ce,JSON.stringify(Xe)])),Te=[],fe=[];for(const[Ce,Xe]of ve)de.has(Ce)?de.get(Ce)!==Xe&&fe.push(Ce):Te.push(Ce);return{added:Te,changed:fe,removed:[...de.keys()].filter(Ce=>!ve.has(Ce))}},[w,z]),Z=(0,m.useMemo)(()=>{const de=[];return H.added.length>0&&de.push(`New: ${C4(H.added)}`),H.changed.length>0&&de.push(`Edited: ${C4(H.changed)}`),H.removed.length>0&&de.push(`Removed: ${C4(H.removed)}`),de.join(" · ")},[H]);(0,m.useEffect)(()=>{if(c||!V)return;function de(ve){ve.preventDefault(),ve.returnValue=""}return r(de,"handleBeforeUnload"),window.addEventListener("beforeunload",de),()=>window.removeEventListener("beforeunload",de)},[c,V]);const Y=(0,m.useCallback)(()=>c||!V?null:(A.current=D,(0,Up.flushSync)(()=>{n(z)}),z??{}),[c,z,D,V,n]);(0,m.useImperativeHandle)(x,()=>({flushPendingDraft:Y}),[Y]),(0,m.useEffect)(()=>{const de=v.current?.closest("form");if(!de)return;function ve(){Y()}return r(ve,"handleSubmit"),de.addEventListener("submit",ve,!0),()=>de.removeEventListener("submit",ve,!0)},[Y]),(0,m.useEffect)(()=>{const de=v.current;if(!de)return;const ve=de;function Te(fe){const Ce=fe.target;if(!(Ce instanceof Element)||ve.contains(Ce))return;const Xe=Ce.closest("button");if(!Xe||Xe.disabled)return;const Oe=`${Xe.getAttribute("aria-label")??""} ${Xe.textContent??""}`;(Xe.type==="submit"||/\b(save|create|update|test|import)\b/i.test(Oe))&&Y()}return r(Te,"handleDocumentClick"),document.addEventListener("click",Te,!0),()=>document.removeEventListener("click",Te,!0)},[Y]);function ie(de){j(de)}r(ie,"updateDraft");function se(de,ve){ie(y.map(Te=>Te.id===de?{...Te,...ve}:Te))}r(se,"patchRow");function X(de){ie(y.filter(ve=>ve.id!==de))}r(X,"removeRow");function le(){const de=ex();j([...y,de]),T({rowId:de.id,field:"name"})}r(le,"addRow");function oe(de){const ve=y.find(Te=>Te.id===de)?.name.trim();ve&&L(Te=>{if(Te.has(ve))return Te;const fe=new Set(Te);return fe.add(ve),fe})}r(oe,"markTouched");function te(de,ve){const Te=_He(de);if(Te.length===0)return!1;const fe=y.filter(Ce=>Ce.id!==ve).map(Ce=>({...Ce}));for(const{key:Ce,value:Xe}of Te){const Oe=fe.find(tt=>tt.name.trim()===Ce);Oe?(Oe.name=Ce,Oe.source="text",Oe.textValue=Xe,Oe.secretId="",Oe.sensitiveDismissed=!1,Oe.userSecretKey="",Oe.required=!0):fe.push({...ex(),name:Ce,textValue:Xe})}return ie(fe),g?.pushToast({title:`Imported ${Te.length} variable${Te.length===1?"":"s"}`,tone:"success"}),!0}r(te,"bulkImport");function J(de){const ve=y.map(Ce=>({...Ce})),Te=ve[ve.length-1];let fe;Te&&!Te.name&&!Te.textValue&&!Te.secretId&&!Te.userSecretKey?fe=Te:(fe=ex(),ve.push(fe)),fe.source="secret",fe.secretId=de.id,fe.version="latest",fe.name||(fe.name=pS(de.name)),ie(ve)}r(J,"bindRecentSecret");function Q(){V&&(A.current=D,n(z))}r(Q,"saveDraft");function pe(){A.current=null,C.current=VN(s);const de=K(s);q(C.current,de)}r(pe,"revertDraft");const re=(0,m.useMemo)(()=>yHe(y),[y]),ne=(0,m.useMemo)(()=>y.reduce((de,ve)=>Tfe(ve,a)||Efe(ve,i)?de+1:de,0),[y,a,i]),ae=(0,m.useMemo)(()=>{const de=new Set(y.filter(ve=>ve.source==="secret"&&ve.secretId).map(ve=>ve.secretId));return(l??[]).filter(ve=>ve.status==="active"&&!de.has(ve.id)).slice(0,8)},[l,y]),me=y.length>0,he=u===void 0?AHe:u,Ie=(0,m.useMemo)(()=>new Map(w.map(de=>[de.id,de])),[w]);return(0,t.jsx)(dd,{children:(0,t.jsxs)("div",{ref:v,className:"@container/env space-y-2",children:[ne>1?(0,t.jsxs)("p",{className:"inline-flex items-center gap-1.5 text-(length:--text-micro) font-medium text-amber-700 dark:text-amber-400",children:[(0,t.jsx)(Vi,{className:"size-3.5"}),ne," bindings need attention"]}):null,me?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"hidden gap-x-1.5 @[40rem]/env:grid @[40rem]/env:grid-cols-(--gtc-14)",children:[(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Name"}),(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Value"}),(0,t.jsx)("span",{})]}),y.map((de,ve)=>{const Te=vHe(de.name,re,d),fe=O.has(de.name.trim());return(0,t.jsx)(NHe,{row:de,isLast:ve===y.length-1,secrets:a,userSecretDefinitions:i,recentlyUsedSecrets:l,disabled:c,nameIssue:Te,showNameIssue:fe,dirtyFields:RHe(de,Ie.get(de.id)),onPatch:r(Ce=>se(de.id,Ce),"onPatch"),onRemove:r(()=>X(de.id),"onRemove"),onNameBlur:r(()=>oe(de.id),"onNameBlur"),onNamePaste:r(Ce=>te(Ce,de.id),"onNamePaste"),onEnterInValueLast:le,onCreateSecret:o,onToast:r(Ce=>g?.pushToast({title:Ce,tone:"success"}),"onToast"),focusRequest:$?.rowId===de.id?$.field:null,onFocusConsumed:r(()=>T(null),"onFocusConsumed")},de.id)})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No environment variables"}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-1",children:[(0,t.jsxs)("button",{type:"button",onClick:le,disabled:c,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[(0,t.jsx)(xn,{className:"size-3.5"}),"Add variable"]}),ae.length>0&&!c?(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-(length:--text-micro) text-muted-foreground/70",children:[(0,t.jsx)(ji,{className:"size-3"}),"Recently used:"]}),ae.map(de=>(0,t.jsxs)("button",{type:"button",onClick:r(()=>J(de),"onClick"),className:"inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 font-mono text-(length:--text-micro) text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",title:`Bind ${de.name}`,children:["+ ",de.name]},de.id))]}):null]}),V&&!c&&!p?(0,t.jsxs)("div",{role:"status",className:"mt-3 flex w-full flex-col gap-3 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-3 text-amber-950 shadow-sm dark:bg-amber-500/15 dark:text-amber-100 @[34rem]/env:flex-row @[34rem]/env:items-center @[34rem]/env:justify-between",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium",children:[(0,t.jsx)("span",{className:"size-2 rounded-full bg-amber-500 shadow-(--shadow-extract-13)"}),(0,t.jsx)("span",{children:"Unsaved changes"})]}),Z?(0,t.jsx)("p",{className:"min-w-0 truncate pl-4 text-xs text-amber-950/80 dark:text-amber-100/80",title:Z,children:Z}):null]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("button",{type:"button",onClick:pe,className:"inline-flex h-9 items-center gap-1.5 rounded-md border border-amber-500/30 bg-background px-3 text-sm font-medium text-foreground transition-colors hover:bg-amber-500/10 dark:bg-background/80",children:[(0,t.jsx)(Ii,{className:"size-4"}),"Revert"]}),(0,t.jsxs)("button",{type:"button",onClick:Q,className:"inline-flex h-9 items-center gap-1.5 rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90",children:[(0,t.jsx)(Bp,{className:"size-4"}),"Save"]})]})]}):null,he?(0,t.jsx)("p",{className:"text-(length:--text-micro) text-muted-foreground/70",children:he}):null,y.some(de=>de.source==="user_secret"&&de.userSecretKey)?(0,t.jsxs)("p",{className:"inline-flex items-start gap-1 text-(length:--text-micro) text-muted-foreground/70",children:[(0,t.jsx)(pu,{className:"mt-0.5 size-3 shrink-0"}),(0,t.jsx)("span",{children:"User secrets resolve from the user responsible for the run. Required bindings fail until that user sets their value under Secrets → My secrets."})]}):null]})})},"EnvironmentVariablesEditor")),THe="env.",A1="access.",NF=/^[A-Za-z_][A-Za-z0-9_]*$/;function Pfe(e){return e?e.startsWith("access.")?"api":e.startsWith("env.")?"env":"config":"config"}r(Pfe,"deliveryModeForConfigPath");function Mfe(e){switch(e){case"env":return"Env var";case"api":return"API access";default:return"Config"}}r(Mfe,"deliveryModeLabel");function EHe(e){switch(e){case"env":return"Injected as an environment variable at run start.";case"api":return"Fetched on demand via the run-bound agent API. Never written to the environment.";default:return"Provided through adapter configuration."}}r(EHe,"deliveryModeDescription");function Dfe(e){return e?e.startsWith("access.")?e.slice(7):e.startsWith("env.")?e.slice(4):e:""}r(Dfe,"aliasFromConfigPath");function PHe(e){switch(e){case"agent_api":return"Agent API";case"plugin_worker":return"Plugin worker";case"tool_connection":return"Tool connection";default:return e.charAt(0).toUpperCase()+e.slice(1)}}r(PHe,"consumerTypeLabel");var MHe={numeric:!0,sensitivity:"base"};function Rk(e){return e.kind==="company"?e.secret.name:e.definition.name}r(Rk,"getSecretPathRowName");function dw(e){return e.split("/").filter(s=>s.length>0)}r(dw,"splitSecretPath");function _4(e){return dw(e).join("/")}r(_4,"normalizeSecretPath");function PY(e,s){return s.every((n,a)=>e[a]===n)}r(PY,"startsWithSegments");function MY(e,s){return e.localeCompare(s,void 0,MHe)}r(MY,"compareNames");function DHe(e,s){const n=dw(s),a=e.map(c=>({row:c,name:Rk(c),segments:dw(Rk(c))})),i=new Set,o=[];for(const c of a){if(!PY(c.segments,n))continue;const d=c.segments.length-n.length;(d===0||d===1)&&o.push(c.row),d>=2&&i.add(c.segments[n.length])}const l=[...i].map(c=>{const d=[...n,c],u=new Set;let h=0;for(const p of a){if(!PY(p.segments,d))continue;const x=p.segments.length-d.length;if(!(x<1)){h+=1;for(let g=1;g<x;g+=1)u.add(p.segments.slice(d.length,d.length+g).join("/"))}}return{name:c,path:d.join("/"),secretCount:h,folderCount:u.size}});return l.sort((c,d)=>MY(c.name,d.name)),o.sort((c,d)=>MY(Rk(c),Rk(d))),{folders:l,secrets:o}}r(DHe,"buildSecretPathListing");function LHe(e){const s=dw(e);return s.map((n,a)=>({name:n,path:s.slice(0,a+1).join("/")}))}r(LHe,"buildSecretPathBreadcrumbs");function $He(e){return e.trim()?e.includes("/")?"Folder name cannot contain slashes.":null:"Folder name is required."}r($He,"validateSecretFolderSegment");function aC({name:e,basePath:s="",className:n,leafClassName:a}){const i=dw(e),o=dw(s),l=o.length>0&&o.every((h,p)=>i[p]===h)&&i.length>o.length?i.slice(o.length):i,c=l.length>0?l:[e],d=c[c.length-1],u=c.slice(0,-1).join("/");return(0,t.jsxs)("span",{className:U("min-w-0 truncate",n),children:[u?(0,t.jsxs)("span",{className:"text-muted-foreground",children:[u,"/"]}):null,(0,t.jsx)("span",{className:U("font-medium text-foreground",a),children:d})]})}r(aC,"SecretPathName");function OHe(e,s){const n=e?`sha256:${e.slice(0,10)}…`:"no fingerprint",a=typeof s=="number"?`${s} ${s===1?"byte":"bytes"}`:null;return a?`${n} · ${a}`:n}r(OHe,"fingerprintLabel");function Lfe({fingerprint:e,length:s,className:n}){const{pushToast:a}=ua(),i=OHe(e,s);if(!e)return(0,t.jsxs)("span",{className:U("inline-flex items-center gap-1 font-mono",n),children:[(0,t.jsx)(JW,{className:"size-3 shrink-0"}),i]});const o=`sha256:${e}`;return(0,t.jsxs)("button",{type:"button",onClick:r(()=>{Gr(o).then(()=>a({title:"Fingerprint copied",tone:"success"})).catch(()=>a({title:"Couldn’t copy fingerprint",tone:"error"}))},"onClick"),title:`Copy full digest — ${o}`,className:U("inline-flex items-center gap-1 font-mono hover:text-foreground",n),children:[(0,t.jsx)(JW,{className:"size-3 shrink-0"}),i,(0,t.jsx)(jr,{className:"size-3 shrink-0 opacity-60"})]})}r(Lfe,"FingerprintChip");function GU({justification:e,className:s}){return(0,t.jsxs)("div",{className:U("space-y-0.5",s),children:[(0,t.jsx)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:"Reason given by the agent"}),(0,t.jsxs)("p",{className:"whitespace-pre-wrap break-words text-xs text-foreground/80",children:["“",e,"”"]})]})}r(GU,"ProposalJustification");function iC({agent:e,className:s}){return(0,t.jsxs)("span",{className:U("inline-flex min-w-0 items-center gap-1",s),children:[(0,t.jsx)(hr,{agent:e,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:e.name})]})}r(iC,"AgentRefChip");function YU({configPath:e}){const s=Pfe(e),n=s==="env",a=s==="api";return(0,t.jsxs)(dt,{variant:"outline",className:U("h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal",n&&"border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",a&&"border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",!n&&!a&&"border-border bg-muted/40 text-muted-foreground"),children:[n?(0,t.jsx)(Cde,{className:"size-3"}):a?(0,t.jsx)(f5,{className:"size-3"}):null,Mfe(s)]})}r(YU,"DeliveryBadge$1");function JU({className:e}){return(0,t.jsxs)(dt,{variant:"outline",className:U("h-5 gap-1 px-1.5 text-(length:--text-nano) font-medium","border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300",e),children:[(0,t.jsx)(wl,{className:"size-3"})," Proposed"]})}r(JU,"ProposedBadge");function G5(e){return Dfe(e.configPath)}r(G5,"bindingEnvKey");function XU(e){return e.secretProposalId?{name:e.secretProposalName??"proposed secret",pending:!0}:{name:e.secretName??"secret",pending:!1}}r(XU,"bindingSecretLabel");function DY(e){return e instanceof Nn?e.message||`Request failed: ${e.status}`:e instanceof Error?e.message:"Something went wrong. Try again."}r(DY,"readableError");function $fe(e,s=[]){const n=Ht(),{pushToast:a}=ua(),[i,o]=(0,m.useState)(null),[l,c]=(0,m.useState)(null),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(null),x=(0,m.useCallback)(()=>{e&&(n.invalidateQueries({queryKey:["secret-proposals",e]}),n.invalidateQueries({queryKey:P.secrets.list(e)}))},[e,n]),g=ye({mutationFn:r(w=>{const{proposal:N}=w;if(N.kind==="secret"){const _=w.folder.trim()?`${w.folder.trim().replace(/\/+$/,"")}/${w.leaf.trim()}`:w.leaf.trim();return mr.approveProposal(e,N.id,{overrides:{name:_,description:w.description.trim()||null,providerConfigId:w.providerConfigId||null}})}return mr.approveProposal(e,N.id,{cascade:w.cascade||void 0})},"mutationFn"),onSuccess:r(w=>{a({title:w.kind==="secret"?"Secret approved":"Binding approved",body:w.kind==="secret"?w.proposedName??"Secret created":`${w.target?.name??"Agent"} · ${G5(w)||"binding"}`,tone:"success"}),o(null),p(null),x()},"onSuccess"),onError:r(w=>p(DY(w)),"onError")}),v=ye({mutationFn:r(({proposal:w,reason:N})=>mr.rejectProposal(e,w.id,{reason:N.trim()}),"mutationFn"),onSuccess:r(w=>{a({title:"Proposal rejected",body:w.kind==="secret"?w.proposedName??void 0:void 0,tone:"info"}),c(null),u(""),p(null),x()},"onSuccess"),onError:r(w=>p(DY(w)),"onError")}),y=(0,m.useCallback)(w=>{p(null);const N=(w.proposedName??"").split("/"),_=N.pop()??"";o({proposal:w,folder:N.join("/"),leaf:_,description:w.proposedDescription??"",providerConfigId:s.find(I=>I.provider==="local_encrypted"&&I.isDefault)?.id??"",cascade:!!w.secretProposalId})},[s]),j=(0,m.useCallback)(w=>{p(null),u(""),c(w)},[]),S=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(FHe,{draft:i,error:h,pending:g.isPending,providerConfigs:s,onChange:o,onCancel:r(()=>{o(null),p(null)},"onCancel"),onConfirm:r(()=>i&&g.mutate(i),"onConfirm")}),(0,t.jsx)(qHe,{proposal:l,reason:d,error:h,pending:v.isPending,onReasonChange:u,onCancel:r(()=>{c(null),u(""),p(null)},"onCancel"),onConfirm:r(()=>l&&v.mutate({proposal:l,reason:d}),"onConfirm")})]});return{requestApprove:y,requestReject:j,isBusy:g.isPending||v.isPending,dialogs:S}}r($fe,"useProposalReview");function FHe({draft:e,error:s,pending:n,providerConfigs:a,onChange:i,onCancel:o,onConfirm:l}){const c=e?.proposal.kind==="secret",d=e?e.folder.trim()?`${e.folder.trim().replace(/\/+$/,"")}/${e.leaf.trim()}`:e.leaf.trim():"",u=a.filter(p=>p.provider==="local_encrypted"),h=c?!!(e&&e.leaf.trim()):!0;return(0,t.jsx)(Xs,{open:!!e,onOpenChange:r(p=>!p&&o(),"onOpenChange"),children:(0,t.jsx)(Zs,{className:"sm:max-w-lg",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:c?"Approve & create secret":"Approve binding"}),(0,t.jsx)(Dn,{children:c?"The value is created as the proposing agent recorded it. Re-folder or rename it before it lands.":"Grant the target agent access to this secret. This runs with your permissions."})]}),(0,t.jsxs)("div",{className:"space-y-1.5 rounded-md border border-border bg-muted/30 p-2.5 text-xs",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[(0,t.jsx)("span",{children:"Proposed by"}),(0,t.jsx)(iC,{agent:e.proposal.proposedBy,className:"font-medium text-foreground"})]}),(0,t.jsx)(GU,{justification:e.proposal.justification})]}),c?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-folder",children:"Folder"}),(0,t.jsx)(Rt,{id:"approve-folder",value:e.folder,onChange:r(p=>i({...e,folder:p.target.value}),"onChange"),placeholder:"dev/github",className:"font-mono text-xs"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-name",children:"Name"}),(0,t.jsx)(Rt,{id:"approve-name",value:e.leaf,onChange:r(p=>i({...e,leaf:p.target.value}),"onChange"),placeholder:"client-secret",autoFocus:!0,"aria-invalid":!e.leaf.trim(),className:"font-mono text-xs"})]})]}),(0,t.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:["Lands as"," ",d?(0,t.jsx)(aC,{name:d,className:"font-mono"}):(0,t.jsx)("span",{className:"italic",children:"enter a name"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-description",children:"Description"}),(0,t.jsx)(Rt,{id:"approve-description",value:e.description,onChange:r(p=>i({...e,description:p.target.value}),"onChange"),placeholder:"Optional"})]}),u.length>0?(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"approve-provider-config",children:"Provider vault"}),(0,t.jsxs)("select",{id:"approve-provider-config",value:e.providerConfigId,onChange:r(p=>i({...e,providerConfigId:p.target.value}),"onChange"),className:"h-9 w-full rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50",children:[(0,t.jsx)("option",{value:"",children:"Deployment default"}),u.map(p=>(0,t.jsx)("option",{value:p.id,children:p.displayName},p.id))]})]}):null,(0,t.jsx)("div",{className:"rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-muted-foreground",children:(0,t.jsx)(Lfe,{fingerprint:e.proposal.valueFingerprintSha256,length:e.proposal.valueLength})})]}):(0,t.jsx)(BHe,{draft:e,onChange:i}),s?(0,t.jsx)("p",{className:"text-xs text-destructive",role:"alert",children:s}):null,(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"ghost",onClick:o,disabled:n,children:"Cancel"}),(0,t.jsx)(F,{onClick:l,disabled:n||!h,children:n?"Approving…":c?"Approve & create":e.cascade?"Approve secret & bind":"Approve binding"})]})]}):null})})}r(FHe,"ApproveDialog");function BHe({draft:e,onChange:s}){const{proposal:n}=e,a=XU(n),i=G5(n);return(0,t.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,t.jsxs)("div",{className:"space-y-2 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Target agent"}),n.target?(0,t.jsx)(iC,{agent:n.target,className:"text-sm font-medium"}):(0,t.jsx)("span",{className:"text-muted-foreground",children:"—"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Delivered as"}),(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(YU,{configPath:n.configPath}),(0,t.jsx)("code",{className:"font-mono text-xs",children:i||n.configPath})]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Secret"}),(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(ji,{className:"size-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:a.name}),a.pending?(0,t.jsx)(JU,{}):null]})]})]}),n.secretProposalId?(0,t.jsxs)("label",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5 text-xs",children:[(0,t.jsx)(Ki,{checked:e.cascade,onCheckedChange:r(o=>s({...e,cascade:o===!0}),"onCheckedChange"),className:"mt-0.5","aria-label":"Also approve the proposed secret"}),(0,t.jsxs)("span",{className:"text-foreground/90",children:["Also approve the proposed secret"," ",(0,t.jsx)("span",{className:"font-medium",children:a.name})," and create it in the same step. The binding can’t land without it."]})]}):null]})}r(BHe,"BindingApproveBody");function qHe({proposal:e,reason:s,error:n,pending:a,onReasonChange:i,onCancel:o,onConfirm:l}){const c=s.trim().length>0;return(0,t.jsx)(Xs,{open:!!e,onOpenChange:r(d=>!d&&o(),"onOpenChange"),children:(0,t.jsx)(Zs,{className:"sm:max-w-md",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Reject proposal"}),(0,t.jsxs)(Dn,{children:["The reason is sent back to"," ",(0,t.jsx)(iC,{agent:e.proposedBy,className:"text-foreground"}),". Dependent bindings are rejected too."]})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"reject-reason",children:"Reason"}),(0,t.jsx)(An,{id:"reject-reason",value:s,onChange:r(d=>i(d.target.value),"onChange"),rows:3,autoFocus:!0,placeholder:"Why is this being rejected?"})]}),n?(0,t.jsx)("p",{className:"text-xs text-destructive",role:"alert",children:n}):null,(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"ghost",onClick:o,disabled:a,children:"Cancel"}),(0,t.jsx)(F,{variant:"destructive",onClick:l,disabled:a||!c,children:a?"Rejecting…":"Reject"})]})]}):null})})}r(qHe,"RejectDialog");function Ofe({proposal:e,onApprove:s,onReject:n,disabled:a,size:i="sm"}){const o=!e.viewerCanApprove,l=i==="xs"?"h-7 px-2 text-xs":"",c=(0,t.jsx)(F,{size:"sm",className:l,disabled:a||o,onClick:r(()=>s(e),"onClick"),children:"Approve"});return(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[o?(0,t.jsx)(dd,{children:(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("span",{tabIndex:0,children:c})}),(0,t.jsx)(Kn,{className:"max-w-72",children:e.approveBlockReason??"You don’t have permission to approve this."})]})}):c,(0,t.jsx)(F,{size:"sm",variant:"outline",className:l,disabled:a,onClick:r(()=>n(e),"onClick"),children:"Reject"})]})}r(Ofe,"ProposalActions");function Ffe(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}r(Ffe,"asRecord$15");function Bfe(e){const s=Ffe(e);if(!s||s.type!=="secret_ref")return null;const n=typeof s.secretId=="string"?s.secretId:"";return n?{secretId:n,version:typeof s.version=="number"?s.version:"latest"}:null}r(Bfe,"readSecretRef");function zHe(e){const s=Ffe(e?.env);if(!s)return[];const n=[];for(const[a,i]of Object.entries(s)){const o=Bfe(i);o&&n.push({name:a,...o})}return n}r(zHe,"parseEnvSecretRefs");function UHe(e){if(!e)return[];const s=[];for(const[n,a]of Object.entries(e)){if(!n.startsWith("access."))continue;const i=Bfe(a);i&&s.push({name:n.slice(A1.length),...i})}return s}r(UHe,"parseAccessGrants");function KHe(e,s){const n=new Map,a=r(i=>{let o=n.get(i);return o||(o={secretId:i,envKeys:[],apiAliases:[]},n.set(i,o)),o},"ensure");for(const i of e)a(i.secretId).envKeys.push(i.name);for(const i of s)a(i.secretId).apiAliases.push(i.name);return[...n.values()]}r(KHe,"summarizeAgentBindings");var LY=0;function qfe(){return LY+=1,`access-row-${LY}`}r(qfe,"nextAccessRowId");function I4(e){return e.map(s=>({id:qfe(),alias:s.name,secretId:s.secretId,version:s.version}))}r(I4,"entriesToRows");function $Y(e){const s={};for(const n of e){const a=n.alias.trim();!a||!NF.test(a)||!n.secretId||(s[a]={type:"secret_ref",secretId:n.secretId,version:n.version})}return s}r($Y,"rowsToAccessMap");function OY(e){return JSON.stringify(Object.keys(e).sort().map(s=>{const n=e[s];return[s,n.secretId,n.version??"latest"]}))}r(OY,"normalizeAccessMapKey");function FY({mode:e}){return e==="env"?(0,t.jsxs)(dt,{variant:"outline",className:"h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:[(0,t.jsx)(Cde,{className:"size-3"})," Env var"]}):(0,t.jsxs)(dt,{variant:"outline",className:"h-5 gap-1 px-1.5 text-(length:--text-nano) font-normal border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",children:[(0,t.jsx)(f5,{className:"size-3"})," API access"]})}r(FY,"DeliveryBadge");function VHe({config:e,secrets:s,onChange:n,onCreateSecret:a,disabled:i,proposals:o,onApproveProposal:l,onRejectProposal:c}){const d=(0,m.useMemo)(()=>(o??[]).filter($=>$.kind==="binding"),[o]),u=(0,m.useMemo)(()=>zHe(e),[e]),h=(0,m.useMemo)(()=>UHe(e),[e]),p=(0,m.useMemo)(()=>KHe(u,h),[u,h]),x=(0,m.useMemo)(()=>$Y(I4(h)),[h]),g=(0,m.useMemo)(()=>OY(x),[x]),[v,y]=(0,m.useState)(()=>I4(h)),[j,S]=(0,m.useState)(null),w=(0,m.useRef)(new Map),N=(0,m.useRef)(g),_=(0,m.useRef)(g);(0,m.useEffect)(()=>{g!==_.current&&(_.current=g,g!==N.current&&y(I4(h)))},[g,h]);const I=r($=>s.find(T=>T.id===$)?.name??`${$.slice(0,8)}…`,"secretName");function C($){y($);const T=$Y($);N.current=OY(T),n(T)}r(C,"emit");function A($,T){C(v.map(q=>q.id===$?{...q,...T}:q))}r(A,"patchRow");function R($){C(v.filter(T=>T.id!==$))}r(R,"removeRow");function E(){y($=>[...$,{id:qfe(),alias:"",secretId:"",version:"latest"}])}r(E,"addRow");const O=(0,m.useMemo)(()=>{const $=new Map;for(const T of v){const q=T.alias.trim();q&&$.set(q,($.get(q)??0)+1)}return $},[v]),L=p.length>0;return(0,t.jsxs)("div",{className:"space-y-3",children:[L?(0,t.jsx)("div",{className:"space-y-1.5",children:p.map($=>(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded-md border border-border bg-muted/30 px-2.5 py-1.5 text-xs",children:[(0,t.jsx)(ji,{className:"size-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:I($.secretId)}),$.envKeys.length>0?(0,t.jsx)(FY,{mode:"env"}):null,$.apiAliases.length>0?(0,t.jsx)(FY,{mode:"api"}):null,(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-(length:--text-micro) text-muted-foreground",children:[...$.envKeys.map(T=>`${THe}${T}`),...$.apiAliases.map(T=>`${A1}${T}`)].join(" · ")})]},$.secretId))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No secrets are bound to this agent yet."}),d.length>0&&l&&c?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Proposed access"}),d.map($=>{const T=XU($),q=G5($);return(0,t.jsxs)("div",{className:"flex flex-col gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 px-2.5 py-2 text-xs sm:flex-row sm:items-center",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[(0,t.jsx)(YU,{configPath:$.configPath}),(0,t.jsx)("code",{className:"font-mono",children:q||$.configPath}),(0,t.jsx)("span",{className:"text-muted-foreground",children:"→"}),(0,t.jsx)(ji,{className:"size-3 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:T.name}),T.pending?(0,t.jsx)(JU,{}):null]}),(0,t.jsxs)("p",{className:"flex flex-wrap items-center gap-1 text-muted-foreground",children:[(0,t.jsxs)("span",{children:["proposed by ",$.proposedBy.name]}),(0,t.jsx)("span",{"aria-hidden":"true",children:"·"}),(0,t.jsxs)("span",{className:"truncate italic",children:["“",$.justification,"”"]})]})]}),(0,t.jsx)(Ofe,{proposal:$,onApprove:l,onReject:c,disabled:i,size:"xs"})]},$.id)})]}):null,(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"API access (no env var)"}),v.length>0?(0,t.jsx)("div",{className:"space-y-2",children:v.map($=>{const T=$.alias.trim(),q=!!T&&!NF.test(T),B=!!T&&(O.get(T)??0)>1,K=s.find(z=>z.id===$.secretId)??null;return(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("div",{className:"grid grid-cols-(--gtc-65) items-start gap-1.5",children:[(0,t.jsx)("div",{children:(0,t.jsx)(Rt,{value:$.alias,onChange:r(z=>A($.id,{alias:z.target.value}),"onChange"),onBlur:r(z=>{const D=z.target.value.trim();if(D&&!NF.test(D)){const V=pS(D);V&&V!==D&&A($.id,{alias:V})}},"onBlur"),placeholder:"ALIAS","aria-label":"Access alias",disabled:i,className:U("h-9 font-mono text-sm",(q||B)&&"border-destructive text-destructive")})}),(0,t.jsxs)("div",{className:"flex min-w-0 items-start gap-1.5",children:[(0,t.jsxs)(sr,{open:j?.rowId===$.id,onOpenChange:r(z=>{!z&&j?.rowId===$.id&&S(null)},"onOpenChange"),children:[(0,t.jsx)(H$,{asChild:!0,children:(0,t.jsx)("div",{ref:r(z=>{z?w.current.set($.id,z):w.current.delete($.id)},"ref"),className:"min-w-0 flex-1",children:(0,t.jsx)(QU,{secretId:$.secretId,secrets:s,onSelect:r(z=>A($.id,{secretId:z,version:"latest",alias:!$.alias.trim()&&z?pS(I(z)):$.alias}),"onSelect"),onCreateNew:a?z=>{window.setTimeout(()=>{S({rowId:$.id,name:CT(z)||z.trim()})},0)}:void 0,disabled:i,triggerClassName:"h-9 min-h-9"})})}),(0,t.jsx)(Gn,{align:"start",className:"w-auto p-3",onInteractOutside:r(z=>{const D=z.detail.originalEvent.target;D&&w.current.get($.id)?.contains(D)&&z.preventDefault()},"onInteractOutside"),children:j?.rowId===$.id&&a?(0,t.jsx)(Rfe,{initialName:j.name,initialValue:"",existingSecretNames:s.map(z=>z.name),onCancel:r(()=>S(null),"onCancel"),onSubmit:r(async(z,D)=>{const V=await a(z,D);A($.id,{secretId:V.id,version:"latest",alias:$.alias.trim()||pS(V.name)}),S(null)},"onSubmit")}):null})]}),(0,t.jsxs)("select",{className:"h-9 shrink-0 rounded-md border border-border bg-background px-2 text-xs outline-none disabled:cursor-not-allowed disabled:opacity-60",value:$.version===void 0?"latest":String($.version),onChange:r(z=>{const D=z.target.value;A($.id,{version:D==="latest"?"latest":Number.parseInt(D,10)})},"onChange"),disabled:i||!K,"aria-label":"Version",children:[(0,t.jsx)("option",{value:"latest",children:"latest"}),K?Array.from({length:Math.max(0,K.latestVersion)},(z,D)=>{const V=K.latestVersion-D;return V<=0?null:(0,t.jsxs)("option",{value:V,children:["v",V]},V)}):null]})]}),(0,t.jsx)("button",{type:"button",onClick:r(()=>R($.id),"onClick"),disabled:i,"aria-label":"Remove API access",className:"mt-1 inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:(0,t.jsx)(Na,{className:"size-3.5"})})]}),q?(0,t.jsx)("p",{className:"pl-0.5 text-(length:--text-micro) text-destructive",children:"Invalid alias — use letters, digits and _"}):B?(0,t.jsx)("p",{className:"pl-0.5 text-(length:--text-micro) text-destructive",children:"Duplicate alias"}):null]},$.id)})}):null,(0,t.jsxs)("button",{type:"button",onClick:E,disabled:i,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[(0,t.jsx)(xn,{className:"size-3.5"}),"Add API access"]})]}),(0,t.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/70",children:[EHe("api")," The agent reads them by alias through ",(0,t.jsx)("code",{children:"GET /agents/me/secrets"}),"."]})]})}r(VHe,"AgentSecretAccessEditor");function WHe(e){if(typeof e!="string")return null;const s=e.trim();return s.length>0?s:null}r(WHe,"asNonEmptyString$3");function HHe(e){return WHe(e)!==null}r(HHe,"hasLegacyWorkingDirectory");function QHe(e){return e.isCreate?!1:HHe(e.adapterConfig?.cwd)}r(QHe,"shouldShowLegacyWorkingDirectoryField");var zfe=new Set;function GHe(e){return zfe.has(e)}r(GHe,"isAdapterTypeHidden");function YHe(e){zfe=new Set(e)}r(YHe,"setDisabledAdapterTypes");function JHe(e){return!Fm(e).hideFromVisualSelection}r(JHe,"isVisualAdapterChoice");function Ufe(e,s=HU()){const n=e??sf;return s.map(a=>({value:a.type,label:n(a.type),comingSoon:!!Fm(a.type).comingSoon,hidden:GHe(a.type),experimental:!!Fm(a.type).experimental}))}r(Ufe,"listAdapterOptions");function Kfe(e={}){const s=e.enabled??!0,{data:n}=ee({queryKey:P.adapters.all,queryFn:r(()=>Cm.list(),"queryFn"),enabled:s,staleTime:3e5});return n&&JWe(n.filter(a=>a.source==="external").map(a=>({type:a.type,label:a.label,disabled:a.disabled,overrideDisabled:a.overridePaused}))),(0,m.useEffect)(()=>{n&&YHe(n.filter(a=>a.disabled).map(a=>a.type))},[n]),(0,m.useMemo)(()=>new Set(n?.filter(a=>a.disabled).map(a=>a.type)??[]),[n])}r(Kfe,"useDisabledAdaptersSync");function XHe(e={}){const s=e.enabled??!0,{data:n}=ee({queryKey:P.adapters.all,queryFn:r(()=>Cm.list(),"queryFn"),enabled:s,staleTime:3e5});return n!==void 0}r(XHe,"useAdapterRegistryLoaded");function _T(e){return Object.fromEntries(Object.entries(e).filter(([,s])=>s!==void 0))}r(_T,"omitUndefinedEntries");function oI(e,s){const n={};if(Object.keys(s.identity).length>0&&Object.assign(n,s.identity),s.adapterType!==void 0&&(n.adapterType=s.adapterType),s.adapterType!==void 0||Object.keys(s.adapterConfig).length>0){const a=e.adapterConfig??{};n.adapterConfig=_T(s.adapterType!==void 0?{...Object.fromEntries(v_e.filter(i=>a[i]!==void 0).map(i=>[i,a[i]])),...s.adapterConfig}:{...a,...s.adapterConfig}),n.replaceAdapterConfig=!0}if(Object.keys(s.heartbeat).length>0||Object.keys(s.debug).length>0){const a=e.runtimeConfig??{},i=n.runtimeConfig??{...a};if(Object.keys(s.heartbeat).length>0&&(i.heartbeat={...a.heartbeat??{},...s.heartbeat}),Object.keys(s.debug).length>0){const o=_T({...a.debug??{},...s.debug});Object.keys(o).length===0?delete i.debug:i.debug=o}n.runtimeConfig=i}return Object.keys(s.runtime).length>0&&Object.assign(n,s.runtime),n}r(oI,"buildAgentUpdatePatch");var ZHe="kubernetes";function eQe(e){return e.driver!=="sandbox"?!1:e.config?.provider===ZHe}r(eQe,"isKubernetesSandboxEnvironment");function ZU(e,s){return e!=="kubernetes"?{forced:!1,kubernetesEnvironment:null}:{forced:!0,kubernetesEnvironment:s.find(n=>eQe(n))??null}}r(ZU,"resolveForcedKubernetesEnvironment");var A4={identity:{},adapterConfig:{},heartbeat:{},debug:{},runtime:{}},WN={};function tQe(e){return e==="claude_local"||e==="codex_local"||e==="paperclip_runner"||e==="opencode_local"}r(tQe,"supportsAdapterModelRefresh");function sQe(e,s){return Cme(e,s).model}r(sQe,"resolvePaperclipRunnerTransitionModel");function BY(e){return Object.keys(e.identity).length>0||e.adapterType!==void 0||Object.keys(e.adapterConfig).length>0||Object.keys(e.heartbeat).length>0||Object.keys(e.debug).length>0||Object.keys(e.runtime).length>0}r(BY,"isOverlayDirty");function kF(e,s){if(Object.is(e,s))return!0;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((n,a)=>kF(n,s[a]));if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof s=="object"&&s!==null&&!Array.isArray(s)){const n=Object.entries(e),a=s;return n.length===Object.keys(a).length&&n.every(([i,o])=>i in a&&kF(o,a[i]))}return!1}r(kF,"overlayValuesEqual");function nQe(e,s){const n=r((a,i)=>Object.fromEntries(Object.entries(a).filter(([o,l])=>!(o in i)||!kF(l,i[o]))),"subtractGroup");return{identity:n(e.identity,s.identity),...e.adapterType!==void 0&&e.adapterType!==s.adapterType?{adapterType:e.adapterType}:{},adapterConfig:n(e.adapterConfig,s.adapterConfig),heartbeat:n(e.heartbeat,s.heartbeat),debug:n(e.debug,s.debug),runtime:n(e.runtime,s.runtime)}}r(nQe,"subtractPersistedOverlay");var fm="w-full rounded-md border border-border px-2.5 py-1.5 bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40";function rQe(e){return e.split(",").map(s=>s.trim()).filter(Boolean)}r(rQe,"parseCommaArgs");function aQe(e){return Array.isArray(e)?e.filter(s=>typeof s=="string").join(", "):typeof e=="string"?e:""}r(aQe,"formatArgList");var iQe=[{id:"",label:"Auto"},{id:"minimal",label:"Minimal"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"X-High"},{id:"max",label:"Max"}],oQe=[{id:"",label:"Auto"},{id:"plan",label:"Plan"},{id:"ask",label:"Ask"}],lQe=[{id:"",label:"Auto"},{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"}],cQe=[{id:"",label:"Auto"},{id:"low",label:"Low"},{id:"high",label:"High"},{id:"max",label:"Max"}],dQe=2,qY=10,uQe=1,Vfe=300;function k2(e,s,n){return Math.max(s,Math.min(n,Math.floor(e)))}r(k2,"clampInteger");function mQe(e){return k2(e,0,Vfe)*1e3}r(mQe,"clampDelayMsFromSeconds");function hQe({order:e,className:s,children:n}){if(!e)return(0,t.jsx)("div",{className:s,children:n});const a=r(o=>{const l=(0,m.isValidElement)(o)?o.props["data-config-section"]:void 0,c=l?e.indexOf(l):-1;return c<0?e.length:c},"rank"),i=m.Children.toArray(n).sort((o,l)=>a(o)-a(l));return(0,t.jsx)("div",{className:s,children:i})}r(hQe,"ConfigSections");function Wfe(e){const{mode:s,adapterModels:n}=e,a=s==="create",i=e.sectionLayout==="cards",o=e.showAdapterTypeField??!0,l=e.showAdapterTestEnvironmentButton??!0,c=l&&!e.onTestActionChange&&!e.compactTestFeedback,d=!e.onTestFeedbackChange,u=e.showCreateRunPolicySection??!0,h=e.hideInstructionsFile??!1,p=e.canConfigureProviderTrace===!0,{selectedCompanyId:x}=fs(),g=Ht(),v=(0,m.useRef)(null),y=Kfe(),{data:j=[]}=ee({queryKey:x?P.secrets.list(x):["secrets","none"],queryFn:r(()=>mr.list(x),"queryFn"),enabled:!!x}),{data:S=[]}=ee({queryKey:x?P.secrets.userDefinitions(x):["user-secret-definitions","none"],queryFn:r(()=>mr.listUserSecretDefinitions(x),"queryFn"),enabled:!!x,retry:!1}),w=a?null:e.agent.id,{data:N=[]}=ee({queryKey:x?P.secrets.proposals(x,"pending"):["secret-proposals","none"],queryFn:r(()=>mr.listProposals(x,"pending"),"queryFn"),enabled:!!x&&!a,retry:!1}),_=(0,m.useMemo)(()=>N.filter(Je=>Je.kind==="binding"&&Je.target?.id===w),[N,w]),I=$fe(x,[]),{data:C}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),retry:!1}),A=(0,m.useMemo)(()=>{const Je=new Set(y);return C?.enableNativeRunner!==!0&&Je.add("paperclip_runner"),Je},[y,C?.enableNativeRunner]),R=C?.enableEnvironments===!0,E=C?.enableManagedSandboxOnly===!0,O=C===void 0||E,{data:L}=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn"),retry:!1}),{data:$}=ee({queryKey:P.instance.settings,queryFn:r(()=>Tr.get(),"queryFn"),retry:!1}),{data:T=[]}=ee({queryKey:x?P.environments.list(x):["environments","none"],queryFn:r(()=>_i.list(x),"queryFn"),enabled:!!x&&(R||L?.executionMode==="kubernetes")}),{forced:q,kubernetesEnvironment:B}=(0,m.useMemo)(()=>ZU(L?.executionMode,T),[L?.executionMode,T]),K=ye({mutationFn:r(Je=>{if(!x)throw new Error("Select an organization to create secrets");return mr.create(x,Je)},"mutationFn"),onSuccess:r(()=>{x&&g.invalidateQueries({queryKey:P.secrets.list(x)})},"onSuccess")}),z=ye({mutationFn:r(async({file:Je,namespace:qt})=>{if(!x)throw new Error("Select an organization to upload images");return c0.uploadImage(x,Je,qt)},"mutationFn")}),[D,V]=(0,m.useState)(A4),[H,Z]=(0,m.useState)(!1),[Y,ie]=(0,m.useState)(0),se=(0,m.useRef)(null),X=(0,m.useRef)(null),le=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!a){if(se.current!==null&&e.agent!==se.current&&!le.current){const Je=X.current;X.current=null,V(qt=>Je?nQe(qt,Je):{...A4})}se.current=e.agent}},[a,a?void 0:e.agent]);const oe=!a&&(BY(D)||H);function te(Je,qt,Hs){const Ks=D[Je];return qt in Ks?Ks[qt]:Hs}r(te,"eff");function J(Je,qt,Hs){V(Ks=>({...Ks,[Je]:{...Ks[Je],[qt]:Hs}}))}r(J,"mark");function Q(){return v.current?.flushPendingDraft()??null}r(Q,"flushEnvironmentDraft");const pe=(0,m.useCallback)(Je=>{a||V(qt=>{const Hs={...e.agent.adapterConfig??{},...qt.adapterConfig},Ks={...qt.adapterConfig};for(const[Ys,Ar]of Object.entries(Je))Ks[`${A1}${Ys}`]=Ar;for(const Ys of Object.keys(Hs))Ys.startsWith("access.")&&(Ys.slice(7)in Je||(Ks[Ys]=void 0));return{...qt,adapterConfig:Ks}})},[a,a?void 0:e.agent]),re=(0,m.useCallback)(()=>{V({...A4}),Z(!1),ie(Je=>Je+1)},[]),ne=(0,m.useCallback)(async()=>{if(a)return;const Je=Q(),qt=Je?{...D,adapterConfig:{...D.adapterConfig,env:Je}}:D;BY(qt)&&await e.onSave(oI(e.agent,qt))},[a,oe,D,e]);(0,m.useEffect)(()=>{a||(e.onDirtyChange?.(oe),e.onSaveActionChange?.(ne),e.onCancelActionChange?.(re))},[a,oe,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange,ne,re]),(0,m.useEffect)(()=>{if(!a)return()=>{e.onSaveActionChange?.(null),e.onCancelActionChange?.(null),e.onDirtyChange?.(!1)}},[a,e.onDirtyChange,e.onSaveActionChange,e.onCancelActionChange]);const ae=a?{}:e.agent.adapterConfig??{},me=a?{}:e.agent.runtimeConfig??{},he=a?{}:me.heartbeat??{},Ie=a?{}:me.debug??{},de=a?e.values.adapterType:D.adapterType??e.agent.adapterType,ve=Bw(),Te=ve(de),fe=Te.supportsInstructionsBundle||Te.supportsSkills||Te.supportsLocalAgentJwt,Ce=fe&&!O&&QHe({isCreate:a,adapterConfig:ae}),Xe=(0,m.useMemo)(()=>Xw(de),[de]),Oe=(0,m.useMemo)(()=>new Set($Re(de)),[de]),tt=a?e.values:null,ce=a?Je=>e.onChange(Je):null;a&&tt.claudeStoredSessionId;const $e=r(()=>{x&&g.invalidateQueries({queryKey:P.secrets.userDefinitions(x)})},"invalidateUserSecretDefinitions"),mt=r(Je=>{if(!a||!ce)return;const qt=tt.envBindings??{};ce({envBindings:{...qt,...sj()},claudeStoredSessionId:Je}),$e()},"handleClaudeLoginStored"),it=r(async()=>{if(a)return;const Je={...Q()??te("adapterConfig","env",ae.env??WN),...sj()},qt={...D,adapterConfig:{...D.adapterConfig,env:Je}};V(qt),await e.onSave({...oI(e.agent,qt),applyStoredClaudeLogin:!0}),$e()},"handleClaudeLoginStoredEdit"),Ke=r(async Je=>{if(a||!Je.companyIdentityDiffers)return;const qt={...Q()??te("adapterConfig","env",ae.env??WN),CODEX_HOME:{type:"secret_ref",secretId:Je.secretId,version:"latest"}},Hs={...D,adapterConfig:{...D.adapterConfig,env:qt}};V(Hs),X.current=Hs,le.current=!0;try{await e.onSave(oI(e.agent,Hs))}catch(Ks){throw X.current=null,Ks}finally{le.current=!1}$e()},"handleCodexAccountBindingEdit"),Ge=r(()=>{if(!a||!ce)return;const Je=tt.envBindings??{};ce({envBindings:{...Je,...sj()},claudeApplyStoredLogin:!0}),$e()},"handleApplyStoredClaudeLogin"),rt=r(async()=>{if(a)return;const Je={...Q()??te("adapterConfig","env",ae.env??WN),...sj()},qt={...D,adapterConfig:{...D.adapterConfig,env:Je}};V(qt),await e.onSave({...oI(e.agent,qt),applyStoredClaudeLogin:!0}),$e()},"handleApplyStoredClaudeLoginEdit"),jt=a?tt.defaultEnvironmentId??"":te("identity","defaultEnvironmentId",e.agent.defaultEnvironmentId??""),st=(0,m.useMemo)(()=>jt?(T.find(Je=>Je.id===jt)??null)?.driver==="local"?"":jt:"",[T,jt]),Nt=(0,m.useMemo)(()=>T.find(Je=>Je.id===st)??null,[st,T]),at=(0,m.useMemo)(()=>{const Je=$?.defaultEnvironmentId??null;return Je?(T.find(qt=>qt.id===Je)??null)?.driver==="local"?"":Je:""},[T,$?.defaultEnvironmentId]),Ee=(0,m.useMemo)(()=>T.find(Je=>Je.id===at)??null,[T,at]),Ne=(0,m.useMemo)(()=>{try{return iw({agentDefaultEnvironmentId:jt||null,instanceDefaultEnvironmentId:$?.defaultEnvironmentId??null,localDefaultEnvironmentId:lw(T),managedSandboxOnly:C?.enableManagedSandboxOnly===!0,managedSandboxEnvironmentId:ow(T),visibleEnvironmentIds:T.map(Je=>Je.id)})}catch{return null}},[jt,$?.defaultEnvironmentId,T,C?.enableManagedSandboxOnly]),He=(0,m.useMemo)(()=>T.find(Je=>Je.id===Ne)??null,[T,Ne]),{data:St}=ee({queryKey:x?P.environments.capabilities(x):["environment-capabilities","none"],queryFn:r(()=>_i.capabilities(x),"queryFn"),enabled:!!x&&Te.login!=null});(0,m.useEffect)(()=>{!a||!ce||!q||!B||st!==B.id&&ce({defaultEnvironmentId:B.id})},[a,ce,q,B,st]);const Ft=(0,m.useMemo)(()=>T.filter(Je=>{if(!Oe.has(Je.driver)||Je.driver==="local")return!1;if(Je.driver!=="sandbox")return!0;const qt=typeof Je.config?.provider=="string"?Je.config.provider:null;return qt!==null&&qt!=="fake"}),[T,Oe]),ts=(0,m.useMemo)(()=>!Nt||Ft.some(Je=>Je.id===Nt.id)?Ft:[...Ft,Nt],[Nt,Ft]),Ot=R&&(q||st.length>0||Ft.length>=1),Be=Ee?cw(Ee):E?"Paperclip Computer":"Local",Ve=de==="paperclip_runner"?String(a?e.values.adapterSchemaValues?.provider??"codex":te("adapterConfig","provider",ae.provider==="acpx"&&ae.acpxAgent==="codex"?"codex":ae.provider??"codex")):void 0,ut=de==="opencode_local"&&XA.safeParse(D.runtime.runtimeConfig?.aiConnection??me.aiConnection).data?.provider==="openrouter"?"openrouter":Ve,qe=x?P.agents.adapterModels(x,de,st||null,ut):["agents","none","adapter-models",de],{data:Gt,error:We}=ee({queryKey:qe,queryFn:r(()=>Wt.adapterModels(x,de,{environmentId:st||null,provider:ut}),"queryFn"),enabled:!!x}),[$t,Dt]=(0,m.useState)(null),[Cs,ze]=(0,m.useState)(!1),ct=Gt??n??[],Pt="command",{data:ke,refetch:ys}=ee({queryKey:x?P.agents.detectModel(x,de):["agents","none","detect-model",de],queryFn:r(()=>{if(!x)throw new Error("Select an organization to detect the model");return Wt.detectModel(x,de)},"queryFn"),enabled:!!(x&&fe&&de!=="opencode_local"&&de!=="paperclip_runner")}),wt=ke?.model??null;ke?.candidates;const{data:Ut=[]}=ee({queryKey:x?P.agents.list(x):["agents","none","list"],queryFn:r(()=>Wt.list(x),"queryFn"),enabled:!!(!a&&x)}),De={mode:s,isCreate:a,adapterType:de,values:a?e.values:null,set:a?Je=>e.onChange(Je):null,config:ae,eff:te,mark:J,models:ct,hideInstructionsFile:h||O,managedSandboxOnly:O},[Se,nt]=(0,m.useState)(!1),[xt,ms]=(0,m.useState)(!1),ht=Jpe(de),zt=r(Je=>(0,t.jsxs)(t.Fragment,{children:[de==="claude_local"&&(0,t.jsx)(P7e,{...De,section:Je}),(0,t.jsx)(Xe.ConfigFields,{...De,section:Je,hideModel:fe})]}),"renderAdapterFields"),[as,Me]=(0,m.useState)(!1),[bt,ft]=(0,m.useState)(!1);function Ye(Je){if(a){const Hs=Xe.buildAdapterConfig(tt);return Je&&Object.assign(Hs,Je),_T(Hs)}const qt={...ae,...D.adapterConfig};return Je&&Object.assign(qt,Je),_T(qt)}r(Ye,"buildAdapterConfigForTest");const gs=ye({mutationFn:r(async()=>{if(!x)throw new Error("Select an organization to test adapter environment");const Je=Q(),qt=Je?{env:Je}:void 0;let Hs=$,Ks=T,Ys=C?.enableManagedSandboxOnly===!0;if(!jt)try{const[Ms,nn,wn]=await Promise.all([g.ensureQueryData({queryKey:P.instance.settings,queryFn:r(()=>Tr.get(),"queryFn")}),g.ensureQueryData({queryKey:P.environments.list(x),queryFn:r(()=>_i.list(x),"queryFn")}),g.ensureQueryData({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")})]);Hs=Ms,Ks=nn,Ys=wn?.enableManagedSandboxOnly===!0}catch{throw new Error("Could not load environment settings to determine which environment to test in. Retry the test.")}const Ar=iw({agentDefaultEnvironmentId:jt||null,instanceDefaultEnvironmentId:Hs?.defaultEnvironmentId??null,localDefaultEnvironmentId:lw(Ks),managedSandboxOnly:Ys,managedSandboxEnvironmentId:ow(Ks),visibleEnvironmentIds:Ks.map(Ms=>Ms.id)}),Ps=Ye(qt),on=a?void 0:e.agent.id,jn=a?void 0:XA.safeParse(D.runtime.runtimeConfig?.aiConnection??e.agent.runtimeConfig.aiConnection).data;if(e.compactTestFeedback){const Ms=de==="paperclip_runner"?Ps.provider==="codex"?"codex_local":Ps.provider==="acpx"&&Ps.acpxAgent==="claude"?"claude_local":de:de;return Upe({companyId:x,adapterType:de,providerAdapter:Ms,adapterConfig:Ps,agentId:on,aiConnection:jn,environmentId:Ar})}return Wt.testEnvironment(x,de,{adapterConfig:Ps,agentId:on,aiConnection:jn,environmentId:Ar})},"mutationFn")}),[Ct,os]=(0,m.useState)(!1),[_t,Xt]=(0,m.useState)(null),zs="Test",hs=!a&&!!e.isSaving,Ws=Ct||hs||!x,Cn=(0,m.useRef)(gs.reset);Cn.current=gs.reset;const Zn=(0,m.useRef)(()=>{});Zn.current=()=>{if(!a||!ce)return;const Je=tt.envBindings??{},qt=tt.claudeStoredSessionId!=null||tt.claudeApplyStoredLogin===!0,Hs=RY in Je;if(!qt&&!Hs)return;const Ks={...Je};delete Ks[RY],ce({envBindings:Ks,claudeStoredSessionId:null,claudeApplyStoredLogin:!1})},(0,m.useEffect)(()=>{Cn.current(),Xt(null),Zn.current()},[de,Ne]);const kn=Te.login!=null,tn=gs.data,Tn=tn!=null&&ve(tn.adapterType).login!=null,Bs=tn&&Tn?tn.checks.find(Je=>Je.code==="adapter_auth_missing")??null:null,an=typeof He?.config?.provider=="string"?He.config.provider:null,ca=an!=null&&St?.sandboxProviders?.[an]?.supportsLoginPty===!0,Sr=Te.login!=null,gn=(a||!(D.runtime.runtimeConfig?.aiConnection??me.aiConnection))&&kn&&He?.driver==="sandbox"&&!!Ne&&!!x&&!!Bs&&(!Sr||ca),rr=(0,m.useCallback)(async()=>{if(!x)throw new Error("Select an organization to test adapter environment");os(!0),Xt(null),gs.reset();try{return await gs.mutateAsync()}catch(Je){throw Xt(Je instanceof Error?Je.message:"Environment test failed"),Je}finally{os(!1)}},[x,gs]),wr=(0,m.useRef)(()=>{});(0,m.useEffect)(()=>{wr.current=()=>{Ws||rr().catch(()=>{})}},[rr,Ws]);const ar=(0,m.useCallback)(()=>{wr.current()},[]);(0,m.useEffect)(()=>{if(!(!l||!e.onTestActionChange))return e.onTestActionChange(ar),()=>{e.onTestActionChange?.(null)}},[l,e.onTestActionChange,ar]),(0,m.useEffect)(()=>{if(!(!l||!e.onTestActionStateChange))return e.onTestActionStateChange({disabled:Ws,pending:Ct}),()=>{e.onTestActionStateChange?.({disabled:!0,pending:!1})}},[l,e.onTestActionStateChange,Ws,Ct]),(0,m.useEffect)(()=>{if(e.onTestFeedbackChange)return e.onTestFeedbackChange({errorMessage:_t??(gs.error instanceof Error?gs.error.message:gs.error?"Environment test failed":null),result:gs.data??null,login:gn&&x&&Ne?{companyId:x,adapterType:de,environmentId:Ne}:null}),()=>{e.onTestFeedbackChange?.({errorMessage:null,result:null,login:null})}},[e.onTestFeedbackChange,_t,gs.data,gs.error,gn,x,de,Ne]);const sa=a?tt.model??"":te("adapterConfig","model",String(ae.model??"")),_r=typeof sa=="string"?sa:"";async function Cr(){if(x){ze(!0),Dt(null);try{const Je=await Wt.adapterModels(x,de,{refresh:!0,environmentId:st||null,provider:ut});g.setQueryData(qe,Je)}catch(Je){Dt(Je instanceof Error?Je.message:"Failed to refresh adapter models.")}finally{ze(!1)}}}r(Cr,"handleRefreshModels");const Wr=de==="codex_local"?"modelReasoningEffort":de==="cursor"?"mode":de==="opencode_local"?"variant":de==="grok_local"?"reasoningEffort":de==="pi_local"?"thinking":"effort",Yn=de==="codex_local"?JS(_r,"Auto").map(Je=>({id:Je.value,label:Je.label})):de==="cursor"?oQe:de==="opencode_local"?iQe:de==="kimi_local"?cQe:de==="pi_local"?[{id:"",label:"Auto"},...["off","minimal","low","medium","high","xhigh"].map(Je=>({id:Je,label:Je}))]:de==="claude_local"||de==="grok_local"?[{id:"",label:"Auto"},...jT(de,_r).map(Je=>({id:Je,label:Je==="xhigh"?"X-High":Je[0].toUpperCase()+Je.slice(1)}))]:lQe,ir=a?tt.thinkingEffort:de==="codex_local"?te("adapterConfig","modelReasoningEffort",String(ae.modelReasoningEffort??ae.reasoningEffort??"")):de==="cursor"?te("adapterConfig","mode",String(ae.mode??"")):de==="opencode_local"?te("adapterConfig","variant",String(ae.variant??"")):te("adapterConfig",Wr,String(ae[Wr]??"")),Ir=de!=="gemini_local"&&de!=="cursor_cloud"&&de!=="paperclip_runner",dr=de==="codex_local"?a?!!tt.search:te("adapterConfig","search",!!ae.search):!1,da=(0,m.useMemo)(()=>{if(a)return{heartbeat:{enabled:tt.heartbeatEnabled,intervalSec:tt.intervalSec}};const Je={...me.heartbeat&&typeof me.heartbeat=="object"?me.heartbeat:{},...D.heartbeat};return{...me,heartbeat:Je}},[a,D.heartbeat,me,tt]),Ls=IW(da.heartbeat),Hn=IW(Ls.maxTurnContinuation),ur=pIe(Hn.enabled,!0),gr=k2(DW(Hn.maxAttempts,dQe),0,qY),gt=k2(DW(Hn.delayMs,uQe*1e3)/1e3,0,Vfe);function ks(Je){J("heartbeat","maxTurnContinuation",{...Hn,...Je})}r(ks,"updateMaxTurnContinuation");const Es=(0,t.jsx)(Zb,{ref:v,onDirtyChange:Z,hideDraftActions:!a&&e.hideInlineSave,value:a?tt.envBindings??WN:te("adapterConfig","env",ae.env??WN),secrets:j,userSecretDefinitions:S,onCreateSecret:r(async(Je,qt)=>await K.mutateAsync({name:Je,value:qt}),"onCreateSecret"),onChange:r(Je=>a?ce({envBindings:Je??{},envVars:""}):J("adapterConfig","env",Je),"onChange")},Y);return!a&&e.content==="secrets"?(0,t.jsxs)("div",{className:U("relative",i&&"space-y-6"),children:[oe&&!e.hideInlineSave&&(0,t.jsx)("div",{className:"sticky top-0 z-10 flex items-center justify-end border-b border-primary/20 bg-background/90 px-4 py-2 backdrop-blur-sm",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Unsaved changes"}),(0,t.jsx)(F,{size:"sm",onClick:ne,disabled:e.isSaving,children:e.isSaving?"Saving...":"Save"})]})}),e.environmentVariablesPlacement==="secrets"&&(0,t.jsxs)("div",{"data-config-section":"environment-variables",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"mb-3 text-sm font-medium",children:"Environment variables"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment variables"}),(0,t.jsx)("div",{className:U(i?"rounded-lg border border-border p-4":"px-4 pb-3"),children:Es})]}),(0,t.jsxs)("div",{"data-config-section":"secrets",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"mb-3 text-sm font-medium",children:"Secret access"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Secret access"}),(0,t.jsxs)("div",{className:U(i?"space-y-3 rounded-lg border border-border p-4":"space-y-3 px-4 pb-3"),children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:vi.secretAccess}),(0,t.jsx)(VHe,{config:{...ae,...D.adapterConfig},secrets:j,onChange:pe,onCreateSecret:r((Je,qt)=>K.mutateAsync({name:Je,value:qt}),"onCreateSecret"),proposals:_,onApproveProposal:I.requestApprove,onRejectProposal:I.requestReject}),I.dialogs]})]})]}):(0,t.jsxs)(hQe,{order:e.sectionOrder,className:U("relative",i&&"space-y-6"),children:[oe&&!e.hideInlineSave&&(0,t.jsx)("div",{className:"sticky top-0 z-10 flex items-center justify-end px-4 py-2 bg-background/90 backdrop-blur-sm border-b border-primary/20",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Unsaved changes"}),(0,t.jsx)(F,{size:"sm",onClick:ne,disabled:!a&&e.isSaving,children:!a&&e.isSaving?"Saving...":"Save"})]})}),!a&&(0,t.jsxs)("div",{"data-config-section":"identity",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:e.sectionTitles?.identity??"Identity"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Identity"}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[(0,t.jsx)(Ss,{label:"Name",hint:vi.name,children:(0,t.jsx)(Ea,{value:te("identity","name",e.agent.name),onCommit:r(Je=>J("identity","name",Je),"onCommit"),immediate:!0,className:fm,placeholder:"Agent name"})}),(0,t.jsx)(Ss,{label:"Title",hint:vi.title,children:(0,t.jsx)(Ea,{value:te("identity","title",e.agent.title??""),onCommit:r(Je=>J("identity","title",Je||null),"onCommit"),immediate:!0,className:fm,placeholder:"e.g. VP of Engineering"})}),(0,t.jsx)(Ss,{label:"Reports to",hint:vi.reportsTo,children:(0,t.jsx)(nHe,{agents:Ut,value:te("identity","reportsTo",e.agent.reportsTo??null),onChange:r(Je=>J("identity","reportsTo",Je),"onChange"),excludeAgentIds:[e.agent.id],chooseLabel:"Choose manager…"})}),fe&&!e.hidePromptTemplate&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ss,{label:"Prompt Template",hint:vi.promptTemplate,children:(0,t.jsx)(yc,{value:te("adapterConfig","promptTemplate",String(ae.promptTemplate??"")),onChange:r(Je=>J("adapterConfig","promptTemplate",Je??""),"onChange"),placeholder:"You are agent {{ agent.name }}. Your role is {{ agent.role }}...",contentClassName:"min-h-(--sz-88px) text-sm font-mono",imageUploadHandler:r(async Je=>{const qt=`agents/${e.agent.id}/prompt-template`;return(await z.mutateAsync({file:Je,namespace:qt})).contentPath},"imageUploadHandler")})}),(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-900 dark:text-amber-100",children:"Prompt template is replayed on every heartbeat. Keep it compact and dynamic to avoid recurring token cost and cache churn."})]})]})]}),q?(0,t.jsxs)("div",{"data-config-section":"environment",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(Ss,{label:"Default environment",hint:"This instance runs all agents in the Kubernetes sandbox. Local execution is disabled.",children:B?(0,t.jsxs)("div",{className:U(fm,"flex items-center text-muted-foreground"),children:[B.name," · Kubernetes sandbox"]}):(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200",children:"This instance requires the Kubernetes sandbox, but no managed Kubernetes environment is available for this organization yet. Configure one before creating agents; execution will not fall back to local."})})})]}):Ot?(0,t.jsxs)("div",{"data-config-section":"environment",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(Ss,{label:"Environment override",children:(0,t.jsx)("div",{className:"space-y-2",children:(0,t.jsxs)("select",{className:fm,value:st,onChange:r(Je=>{const qt=Je.target.value;if(a){ce({defaultEnvironmentId:qt});return}J("identity","defaultEnvironmentId",qt||null)},"onChange"),children:[(0,t.jsxs)("option",{value:"",children:["Default: ",Be]}),ts.map(Je=>(0,t.jsx)("option",{value:Je.id,children:cw(Je)},Je.id))]})})})})]}):null,(0,t.jsxs)("div",{"data-config-section":"adapter",className:U(!i&&(a?"border-t border-border":"border-b border-border")),children:[(0,t.jsxs)("div",{className:U(i?"flex items-center justify-between mb-3":"px-4 py-2 flex items-center justify-between gap-2"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium",children:e.sectionTitles?.adapter??"Adapter"}):(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Adapter"}),c&&(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",onClick:ar,disabled:Ws,children:Ct?`${zs}...`:zs})]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[o&&(0,t.jsx)(Ss,{label:"Adapter type",hint:vi.adapterType,children:(0,t.jsx)(Qfe,{value:de,disabledTypes:A,onChange:r(Je=>{if(a){const{adapterType:qt,...Hs}=Xg,Ks={...Hs,adapterType:Je};Je==="codex_local"?Ks.dangerouslyBypassSandbox=!0:Je==="gemini_local"?Ks.model="auto":Je==="kimi_local"?Ks.model="kimi-code/kimi-for-coding":Je==="cursor"?Ks.model="auto":Je==="opencode_local"?Ks.model="openai/gpt-5.2-codex":Je==="paperclip_runner"&&(Ks.model=tw),ce(Ks)}else V(qt=>({...qt,adapterType:Je,adapterConfig:{model:Je==="gemini_local"?"auto":Je==="kimi_local"?"kimi-code/kimi-for-coding":Je==="opencode_local"?"openai/gpt-5.2-codex":Je==="cursor"?"auto":Je==="paperclip_runner"?sQe(de,ae.model):"",effort:"",modelReasoningEffort:"",variant:"",mode:"",...Je==="codex_local"?{dangerouslyBypassApprovalsAndSandbox:!0}:Je==="paperclip_runner"?{...Cme(de,te("adapterConfig","model",ae.model))}:{}}}))},"onChange")})}),!a&&x&&(0,t.jsx)(zpe,{companyId:x,agentId:e.agent.id,agentName:e.agent.name,adapterType:de==="paperclip_runner"?te("adapterConfig","provider",ae.provider)==="codex"?"codex_local":te("adapterConfig","provider",ae.provider)==="opencode"?"opencode_local":te("adapterConfig","provider",ae.provider)==="acpx"&&te("adapterConfig","acpxAgent",ae.acpxAgent)==="claude"?"claude_local":de:de,value:XA.safeParse(D.runtime.runtimeConfig?.aiConnection??me.aiConnection).data,model:String(te("adapterConfig","model",ae.model)??""),environmentId:st||void 0,legacy:!0,onChange:r(Je=>J("runtime","runtimeConfig",{...me,aiConnection:Je}),"onChange")}),d&&!e.compactTestFeedback&&(_t||gs.error)&&(0,t.jsx)("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:_t??(gs.error instanceof Error?gs.error.message:"Environment test failed")}),d&&!e.compactTestFeedback&&gs.data&&(0,t.jsx)(yQe,{result:gs.data}),d&&gn&&(0,t.jsx)(eK,{companyId:x,adapterType:de,environmentId:Ne,onStored:a?mt:it,onApplyStored:a?Ge:rt,onAccountBinding:a?void 0:Ke},`${de}:${Ne}`),Ce&&(0,t.jsx)(Ss,{label:"Working directory (deprecated)",hint:vi.cwd,children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2.5 py-1.5",children:[(0,t.jsx)(Io,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)(Ea,{value:a?tt.cwd:te("adapterConfig","cwd",String(ae.cwd??"")),onCommit:r(Je=>a?ce({cwd:Je}):J("adapterConfig","cwd",Je||void 0),"onCommit"),immediate:!0,className:"w-full bg-transparent outline-none text-sm font-mono placeholder:text-muted-foreground/40",placeholder:"/path/to/project"}),(0,t.jsx)(ud,{})]})}),zt("adapter"),fe&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tK,{models:ct,value:_r,onChange:r(Je=>{const qt=jT(de,Je),Hs=["codex_local","claude_local","grok_local"].includes(de)&&!!ir&&!qt.includes(String(ir));if(a){ce({model:Je,...Hs?{thinkingEffort:""}:{}});return}J("adapterConfig","model",Je||void 0),Hs&&(J("adapterConfig",Wr,void 0),J("adapterConfig","reasoningEffort",void 0))},"onChange"),open:as,onOpenChange:Me,defaultLabel:de==="claude_local"?"Default (claude-opus-5)":void 0,allowDefault:de!=="opencode_local"&&de!=="pi_local"&&de!=="paperclip_runner",required:de==="opencode_local"||de==="pi_local",groupByProvider:de==="opencode_local"||de==="pi_local",creatable:!0,detectedModel:wt,detectedModelCandidates:[],onDetectModel:de==="opencode_local"||de==="paperclip_runner"?void 0:async()=>(await ys()).data?.model??null,onRefreshModels:tQe(de)?Cr:void 0,refreshingModels:Cs,detectModelLabel:"Detect model",emptyDetectHint:"No model detected. Select or enter one manually."}),($t||We)&&(0,t.jsx)("p",{className:"text-xs text-destructive",children:$t??(We instanceof Error?We.message:"Failed to load adapter models.")}),de==="opencode_local"&&Nt&&Nt.driver!=="local"&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Live OpenCode model discovery only runs for Local environments. Using the curated list and manual entry for ",Nt.name,"."]}),Ir&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(jQe,{value:ir,options:Yn,onChange:r(Je=>a?ce({thinkingEffort:Je}):J("adapterConfig",Wr,Je||void 0),"onChange"),open:bt,onOpenChange:ft}),de==="codex_local"&&dr&&ir==="minimal"&&(0,t.jsx)("p",{className:"text-xs text-amber-400",children:"Codex may reject `minimal` thinking when search is enabled."})]})]})]})]}),(0,t.jsxs)("div",{"data-config-section":"configuration",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Configuration"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Configuration"}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[!a&&typeof ae.bootstrapPromptTemplate=="string"&&ae.bootstrapPromptTemplate&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ss,{label:"Bootstrap prompt (legacy)",hint:vi.bootstrapPrompt,children:(0,t.jsx)(yc,{value:te("adapterConfig","bootstrapPromptTemplate",String(ae.bootstrapPromptTemplate??"")),onChange:r(Je=>J("adapterConfig","bootstrapPromptTemplate",Je||void 0),"onChange"),placeholder:"Optional initial setup prompt for the first run",contentClassName:"min-h-(--sz-44px) text-sm font-mono",imageUploadHandler:r(async Je=>{const qt=`agents/${e.agent.id}/bootstrap-prompt`;return(await z.mutateAsync({file:Je,namespace:qt})).contentPath},"imageUploadHandler")})}),(0,t.jsx)("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200",children:"Bootstrap prompt is legacy and will be removed in a future release. Consider moving this content into the agent's prompt template or instructions file instead."})]}),zt("configuration"),(fe||de==="process"||ht?.fields.some(Je=>cF(Je.key)==="advanced"))&&(0,t.jsx)(g2,{title:"Advanced",open:xt,onToggle:r(()=>ms(!xt),"onToggle"),children:(0,t.jsxs)("div",{className:"space-y-3",children:[fe&&(0,t.jsxs)(t.Fragment,{children:[" ",!O&&(0,t.jsx)(Ss,{label:"Command",hint:vi.localCommand,children:(0,t.jsx)(Ea,{value:a?tt.command:te("adapterConfig",Pt,String(ae.command??"")),onCommit:r(Je=>a?ce({command:Je}):J("adapterConfig",Pt,Je||null),"onCommit"),immediate:!0,className:fm,placeholder:{claude_local:"claude",codex_local:"codex",gemini_local:"gemini",kimi_local:"kimi",pi_local:"pi",cursor:"agent",opencode_local:"opencode"}[de]??de.replace(/_local$/,"")})}),(0,t.jsx)(Ss,{label:"Extra args (comma-separated)",hint:vi.extraArgs,children:(0,t.jsx)(Ea,{value:a?tt.extraArgs:te("adapterConfig","extraArgs",aQe(ae.extraArgs)),onCommit:r(Je=>a?ce({extraArgs:Je}):J("adapterConfig","extraArgs",Je?.trim()?rQe(Je):null),"onCommit"),className:fm,placeholder:"e.g. --verbose, --foo=bar"})})]}),zt("advanced")]})})]})]}),e.environmentVariablesPlacement!=="secrets"&&(fe||ht?.fields.some(Je=>cF(Je.key)==="environment"))&&(0,t.jsxs)("div",{"data-config-section":"environment-variables",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Environment variables"}):(0,t.jsx)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground",children:"Environment variables"}),(0,t.jsx)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:fe?Es:zt("environment")})]}),a&&u?(0,t.jsxs)("div",{"data-config-section":"run-policy",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}):(0,t.jsxs)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg p-4 space-y-3":"px-4 pb-3 space-y-3"),children:[(0,t.jsx)(nY,{label:"Heartbeat on interval",hint:vi.heartbeatInterval,checked:tt.heartbeatEnabled,onCheckedChange:r(Je=>ce({heartbeatEnabled:Je}),"onCheckedChange"),number:tt.intervalSec,onNumberChange:r(Je=>ce({intervalSec:Je}),"onNumberChange"),numberLabel:"sec",numberPrefix:"Run heartbeat every",numberHint:vi.intervalSec,showNumber:tt.heartbeatEnabled}),(0,t.jsx)(g2,{title:"Advanced Run Policy",open:Se,onToggle:r(()=>nt(!Se),"onToggle"),children:(0,t.jsx)("div",{className:"space-y-3",children:zt("runPolicy")})})]})]}):a?null:(0,t.jsxs)("div",{"data-config-section":"run-policy",className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}):(0,t.jsxs)("div",{className:"px-4 py-2 text-xs font-medium text-muted-foreground flex items-center gap-2",children:[(0,t.jsx)(K_,{className:"h-3 w-3"})," Run Policy"]}),(0,t.jsxs)("div",{className:U(i?"border border-border rounded-lg overflow-hidden":""),children:[(0,t.jsx)("div",{className:U(i?"p-4 space-y-3":"px-4 pb-3 space-y-3"),children:(0,t.jsx)(nY,{label:"Heartbeat on interval",hint:vi.heartbeatInterval,checked:te("heartbeat","enabled",he.enabled===!0),onCheckedChange:r(Je=>J("heartbeat","enabled",Je),"onCheckedChange"),number:te("heartbeat","intervalSec",Number(he.intervalSec??300)),onNumberChange:r(Je=>J("heartbeat","intervalSec",Je),"onNumberChange"),numberLabel:"sec",numberPrefix:"Run heartbeat every",numberHint:vi.intervalSec,showNumber:te("heartbeat","enabled",he.enabled===!0)})}),(0,t.jsx)(g2,{title:"Advanced Run Policy",bordered:i,open:Se,onToggle:r(()=>nt(!Se),"onToggle"),children:(0,t.jsxs)("div",{className:"space-y-3",children:[zt("runPolicy"),fe&&(0,t.jsx)(t.Fragment,{children:!a&&(0,t.jsxs)(t.Fragment,{children:[!ht?.fields.some(Je=>Je.key==="timeoutSec")&&(0,t.jsx)(Ss,{label:"Timeout (sec)",hint:vi.timeoutSec,children:(0,t.jsx)(Zl,{value:te("adapterConfig","timeoutSec",Number(ae.timeoutSec??0)),onCommit:r(Je=>J("adapterConfig","timeoutSec",Je),"onCommit"),immediate:!0,className:fm})}),!ht?.fields.some(Je=>Je.key==="graceSec")&&(0,t.jsx)(Ss,{label:"Interrupt grace period (sec)",hint:vi.graceSec,children:(0,t.jsx)(Zl,{value:te("adapterConfig","graceSec",Number(ae.graceSec??15)),onCommit:r(Je=>J("adapterConfig","graceSec",Je),"onCommit"),immediate:!0,className:fm})})]})}),(0,t.jsx)(rd,{label:"Wake on demand",hint:vi.wakeOnDemand,checked:te("heartbeat","wakeOnDemand",he.wakeOnDemand!==!1),onChange:r(Je=>J("heartbeat","wakeOnDemand",Je),"onChange")}),(0,t.jsx)(Ss,{label:"Cooldown (sec)",hint:vi.cooldownSec,children:(0,t.jsx)(Zl,{value:te("heartbeat","cooldownSec",Number(he.cooldownSec??10)),onCommit:r(Je=>J("heartbeat","cooldownSec",Je),"onCommit"),immediate:!0,className:fm})}),(0,t.jsx)(Ss,{label:"Max concurrent runs",hint:vi.maxConcurrentRuns,children:(0,t.jsx)(Zl,{value:te("heartbeat","maxConcurrentRuns",Number(he.maxConcurrentRuns??20)),onCommit:r(Je=>J("heartbeat","maxConcurrentRuns",Je),"onCommit"),immediate:!0,className:fm})}),(0,t.jsxs)("div",{className:"rounded-md border border-border/70 px-3 py-2",children:[(0,t.jsx)(rd,{label:"Continue after max-turn stop",hint:vi.maxTurnContinuationEnabled,checked:ur,onChange:r(Je=>ks({enabled:Je}),"onChange")}),ur?(0,t.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[(0,t.jsx)(Ss,{label:"Continuation attempts",hint:vi.maxTurnContinuationMaxAttempts,children:(0,t.jsx)(Zl,{value:gr,onCommit:r(Je=>ks({maxAttempts:k2(Je,0,qY)}),"onCommit"),immediate:!0,className:fm})}),(0,t.jsx)(Ss,{label:"Continuation delay (sec)",hint:vi.maxTurnContinuationDelaySec,children:(0,t.jsx)(Zl,{value:gt,onCommit:r(Je=>ks({delayMs:mQe(Je)}),"onCommit"),immediate:!0,className:fm})})]}):null]})]})})]})]}),!a&&p?(0,t.jsxs)("div",{className:U(!i&&"border-b border-border"),children:[i?(0,t.jsxs)("h3",{className:"mb-3 flex items-center gap-2 text-sm font-medium",children:[(0,t.jsx)(xj,{className:"h-3 w-3"})," Debugging"]}):(0,t.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-xs font-medium text-muted-foreground",children:[(0,t.jsx)(xj,{className:"h-3 w-3"})," Debugging"]}),(0,t.jsxs)("div",{className:U("border-border bg-accent/30",i?"rounded-lg border p-4":"mx-4 mb-4 rounded-md border px-3 py-3"),children:[(0,t.jsx)(rd,{label:"Capture raw provider traces",hint:"Stores exact provider traffic for every future run until disabled. Traces may contain sensitive prompts and tool arguments, are administrator-only, and expire after 24 hours.",checked:te("debug","providerTrace",Ie.providerTrace)==="raw",onChange:r(Je=>J("debug","providerTrace",Je?"raw":void 0),"onChange")}),te("debug","providerTrace",Ie.providerTrace)==="raw"?(0,t.jsxs)("div",{className:"mt-3 flex items-start gap-2 rounded-md border border-border bg-background/60 px-3 py-2 text-xs text-foreground",children:[(0,t.jsx)(xj,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{children:"Raw tracing is on for future runs. Paperclip keeps at most 64 MiB per run and automatically deletes it after 24 hours."})]}):null]})]}):null,e.compactTestFeedback&&d&&l&&(0,t.jsx)(Wpe,{state:Ct?"running":_t||gs.error?"fail":tn?.status??"idle",result:tn??null,error:_t??(gs.error instanceof Error?gs.error.message:null),onTest:ar,disabled:Ws})]})}r(Wfe,"AgentConfigForm");var SF=new Set(["authenticated","failed","timed_out","cancelled"]),CF=2e3;function _F({value:e,label:s}){const[n,a]=(0,m.useState)(!1),i=(0,m.useRef)(null);return(0,m.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-xs","aria-label":s,title:s,className:"text-muted-foreground hover:text-foreground",onClick:r(async()=>{try{await Gr(e),a(!0)}catch{a(!1)}i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),1500)},"onClick"),children:n?(0,t.jsx)(xs,{className:"size-3"}):(0,t.jsx)(jr,{className:"size-3"})})}r(_F,"AdapterLoginCopyButton");function pQe({status:e,message:s}){return e==="authenticated"?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Authenticated. The environment has credentials now."})]}):(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsxs)("span",{children:[e==="timed_out"?"Login timed out":e==="cancelled"?"Login cancelled":"Login failed",s?`: ${s}`:"."]})]})}r(pQe,"AdapterLoginTerminalState");var fQe={claude_local:"Anthropic",codex_local:"OpenAI"};function Hfe(e){const s=fQe[e];return s?`Sign in to ${s}`:"Sign in to the environment"}r(Hfe,"adapterLoginTitle");function eK(e){return Bw()(e.adapterType).login?.panelMode==="submitted_browser_code"?(0,t.jsx)(vQe,{...e}):(0,t.jsx)(xQe,{...e})}r(eK,"AdapterLoginPanel");function xQe({companyId:e,adapterType:s,environmentId:n,autoStart:a,onConnected:i,onAccountBinding:o,chrome:l="panel",aiConnection:c,onPromptReady:d}){const[u,h]=(0,m.useState)(null),[p,x]=(0,m.useState)(null),[g,v]=(0,m.useState)(null),[y,j]=(0,m.useState)("idle"),S=(0,m.useRef)(!1),w=ye({mutationFn:r(()=>Wt.startAdapterAuthLogin(e,s,{environmentId:n,aiConnection:c}),"mutationFn"),onSuccess:r(X=>{S.current=!1,x(null),v(null),j("idle"),h(X.sessionId)},"onSuccess"),onError:r(X=>{x(X instanceof Error?X.message:"Could not start the login.")},"onError")}),N=(0,m.useCallback)(()=>{S.current=!1,h(null),v(null),x(null)},[]),_=ye({mutationFn:r(()=>Wt.cancelAdapterAuthLogin(e,s,u),"mutationFn"),onSuccess:N,onError:r(X=>{x(X instanceof Error?X.message:"Could not cancel the login.")},"onError")}),I=ee({queryKey:["adapter-login-active-session",e,s],queryFn:r(async()=>{try{const X=await Wt.getActiveAdapterAuthLoginSession(e,s);if(!X)return null;if(c&&X.environmentId!==n||!!X.aiConnection!=!!c||c&&(X.aiConnection?.provider!==c.provider||X.aiConnection?.method!==c.method||X.aiConnection?.connectionId!==c.connectionId||X.aiConnection?.ownership!==c.ownership||X.aiConnection?.allAgents!==c.allAgents||JSON.stringify(X.aiConnection?.agentIds)!==JSON.stringify(c.agentIds)))throw new Error("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one.");return X}catch(X){if(X instanceof Nn&&X.status===404)return null;throw X}},"queryFn"),retry:!1,gcTime:0,staleTime:0}),[C,A]=(0,m.useState)(!1),R=ee({queryKey:["adapter-login-status",e,s,u],queryFn:r(()=>Wt.getAdapterAuthLoginStatus(e,s,u),"queryFn"),enabled:!!u&&!C,retry:r((X,le)=>le instanceof Nn&&le.status===404?!1:X<3,"retry"),refetchInterval:r(X=>{const le=X.state.data?.status;return le&&SF.has(le)?!1:CF},"refetchInterval")});(0,m.useEffect)(()=>{const X=R.data?.prompt??null;X&&v(X)},[R.data]);const E=R.data??w.data??null,O=E?.status??null,L=g,$=O?SF.has(O):!1,T=!!u&&!$,q=w.isPending||T||y==="saving",B=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(B.current||!I.isFetched)return;B.current=!0;const X=I.data;X&&(S.current=!0,x(null),v(X.prompt??null),h(X.sessionId))},[I.isFetched,I.data]),(0,m.useEffect)(()=>{const X=R.error;if(!(X instanceof Nn&&X.status===404)||!S.current||C)return;A(!0);const le=u;(async()=>(le&&await Wt.cancelAdapterAuthLogin(e,s,le).catch(()=>{}),A(!1),N()))()},[R.error,C,u,e,s,N]);const K=(0,m.useRef)(!1),z=(0,m.useRef)(w.mutate);z.current=w.mutate,(0,m.useEffect)(()=>{if(!(!a||K.current)){if(I.isError){K.current=!0,x(I.error instanceof Error?I.error.message:"Could not check for an active login.");return}I.isSuccess&&(K.current=!0,!I.data&&z.current())}},[a,I.isSuccess,I.isError,I.data,I.error]);const D=(0,m.useRef)(!1),V=(0,m.useRef)(i);V.current=i,(0,m.useEffect)(()=>{O!=="authenticated"||D.current||(D.current=!0,V.current?.(u??void 0))},[O]);const H=(0,m.useRef)(null),Z=(0,m.useRef)(o);Z.current=o;const Y=R.data?.codexAccountBinding??null,ie=(0,m.useCallback)(async X=>{const le=Z.current;if(le){j("saving");try{await le(X),j("bound")}catch{j("failed")}}},[]);(0,m.useEffect)(()=>{O!=="authenticated"||!u||H.current!==u&&(!Y||!Y.companyIdentityDiffers||!Z.current||(H.current=u,ie(Y)))},[O,u,Y,ie]);const se=(0,m.useRef)(d);if(se.current=d,(0,m.useEffect)(()=>{se.current?.(L?.url??null)},[L]),l==="onboarding"){const X=$&&O&&O!=="authenticated";return(0,t.jsx)(nfe,{loading:!L&&!p&&!X,providerName:tfe(s),authorizationUrl:L?.url,mode:"displayed_code",children:p?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:p}):X?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:O==="timed_out"?"The login timed out. Start it again.":O==="cancelled"?"The login was cancelled.":"The login did not finish. Start it again."}):(0,t.jsx)(p7e,{code:L?.code??"",autoCopy:!0})})}return(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-foreground",children:Hfe(s)}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[T&&(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground hover:text-foreground",disabled:_.isPending,onClick:r(()=>_.mutate(),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:q,onClick:r(()=>w.mutate(),"onClick"),children:"Sign in"})]})]}),p&&(0,t.jsx)("div",{role:"alert",className:"text-(length:--text-micro) text-destructive",children:p}),(0,t.jsxs)("div",{role:"status","aria-live":"polite",className:"space-y-2 empty:hidden",children:[T&&!L&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Preparing..."})]}),T&&L&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"Copy the code, then open the authentication page."}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"1. Code"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:L.code})]}),(0,t.jsx)(_F,{value:L.code,label:"Copy code"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"2. Authentication URL"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:L.url})]}),(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(_F,{value:L.url,label:"Copy URL"}),(0,t.jsx)(F,{asChild:!0,type:"button",variant:"ghost",size:"icon-xs","aria-label":"Open the authentication page",title:"Open the authentication page",className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)("a",{href:L.url,target:"_blank",rel:"noreferrer noopener",children:(0,t.jsx)(xr,{className:"size-3"})})})]})]})]}),$&&O&&(0,t.jsx)(pQe,{status:O,message:E?.failure?.message??null}),O==="authenticated"&&y==="saving"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Binding this agent to the signed-in account..."})]}),O==="authenticated"&&y==="bound"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Agent bound to the signed-in account."})]}),O==="authenticated"&&y==="failed"&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro)",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0 text-destructive"}),(0,t.jsx)("span",{className:"text-destructive",children:"Could not bind this agent to the signed-in account."}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:r(()=>{Y&&ie(Y)},"onClick"),children:"Retry"})]})]})]})}r(xQe,"DisplayedCodeLoginPanel");var gQe=new Set(["failed","timed_out","cancelled"]),zY="The login did not finish. Start the login again.",bQe=9e5,UY="The login timed out. Start the login again.";function vQe({companyId:e,adapterType:s,environmentId:n,onStored:a,onApplyStored:i,autoStart:o,onConnected:l,onCodeSubmitted:c,onSubmitFailed:d,chrome:u="panel",aiConnection:h,onPromptReady:p}){const[x,g]=(0,m.useState)(null),[v,y]=(0,m.useState)(null),[j,S]=(0,m.useState)(null),[w,N]=(0,m.useState)(!1),[_,I]=(0,m.useState)(""),[C,A]=(0,m.useState)(null),[R,E]=(0,m.useState)(!1),[O,L]=(0,m.useState)(!1),[$,T]=(0,m.useState)(!1),[q,B]=(0,m.useState)(!1),K=(0,m.useRef)(!1),[z,D]=(0,m.useState)(!1),V=(0,m.useRef)(!1),H=r(()=>{y(null),S(null),N(!1),I(""),A(null),E(!1),L(!1),B(!1),T(!1),K.current=!1},"resetLocalState"),Z=ee({queryKey:["claude-oauth-token-status",e],queryFn:r(async()=>{try{return await Wt.getClaudeOAuthTokenStatus(e)}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),retry:r((at,Ee)=>Ee instanceof Nn&&Ee.status===404?!1:at<2,"retry")}).data??null,Y=ye({mutationFn:r(()=>Wt.startClaudeSetupTokenLogin(e,{environmentId:n,aiConnection:h,...Z&&!h?{overwrite:{expectedSecretId:Z.secretId,expectedLatestVersion:Z.latestVersion}}:{}}),"mutationFn"),onSuccess:r(at=>{V.current=!1,H(),g(at.sessionId)},"onSuccess"),onError:r(at=>{y(at instanceof Error?at.message:"Could not start the login.")},"onError")}),ie=r(()=>{V.current=!1,g(null),H()},"clearActiveSession"),se=ye({mutationFn:r(()=>Wt.cancelClaudeSetupTokenLogin(e,x),"mutationFn"),onSuccess:r(()=>{ie()},"onSuccess"),onError:r(at=>{if(at instanceof Nn&&at.status===404){ie();return}y(at instanceof Error?at.message:"Could not cancel the login.")},"onError")}),X=(0,m.useCallback)(at=>{Wt.cancelClaudeSetupTokenLogin(e,at).catch(()=>{})},[e]),le=ee({queryKey:["claude-setup-token-active-session",e],queryFn:r(async()=>{try{const at=await Wt.getActiveClaudeSetupTokenLoginSession(e);if(!at)return null;if(h&&at.environmentId!==n||!!at.aiConnection!=!!h||h&&(at.aiConnection?.provider!==h.provider||at.aiConnection?.method!==h.method||at.aiConnection?.connectionId!==h.connectionId||at.aiConnection?.ownership!==h.ownership||at.aiConnection?.allAgents!==h.allAgents||JSON.stringify(at.aiConnection?.agentIds)!==JSON.stringify(h.agentIds)))throw new Error("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one.");return at}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),retry:!1,gcTime:0,staleTime:0}),[oe,te]=(0,m.useState)(!1),J=!!x&&!O&&!q&&!oe,Q=ee({queryKey:["claude-setup-token-status",e,x],queryFn:r(()=>Wt.getClaudeSetupTokenLoginStatus(e,x),"queryFn"),enabled:J,retry:r((at,Ee)=>Ee instanceof Nn&&Ee.status===404?!1:at<3,"retry"),refetchInterval:r(at=>{if(O||q)return!1;const Ee=at.state.data?.status;return Ee&&SF.has(Ee)?!1:CF},"refetchInterval")});(0,m.useEffect)(()=>{const at=Q.error;if(at instanceof Nn&&at.status===404){if(V.current){if(oe)return;te(!0);const Ee=x;(async()=>(Ee&&await Wt.cancelClaudeSetupTokenLogin(e,Ee).catch(()=>{}),te(!1),ie()))();return}B(!0)}},[Q.error,oe,x,e]);const pe=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(pe.current||!le.isFetched)return;pe.current=!0;const at=le.data;at&&(V.current=!0,H(),g(at.sessionId),at.prompt&&(S(at.prompt.authorizationUrl),at.prompt.transportAdvisory&&N(!0)))},[le.isFetched,le.data]);const re=ee({queryKey:["claude-setup-token-prompt",e,x],enabled:J&&!j,queryFn:r(async()=>{try{return await Wt.getClaudeSetupTokenLoginPrompt(e,x)}catch(at){if(at instanceof Nn&&at.status===404)return null;throw at}},"queryFn"),refetchInterval:r(at=>O||at.state.data?.authorizationUrl?!1:CF,"refetchInterval")});(0,m.useEffect)(()=>{const at=re.data?.authorizationUrl??null;at&&S(at),re.data?.transportAdvisory&&N(!0)},[re.data]);const ne=ye({mutationFn:r(at=>Wt.submitClaudeSetupTokenBrowserCode(e,x,at),"mutationFn"),onError:r(at=>{y(at instanceof Error?at.message:"Could not submit the browser code.")},"onError")}),ae=ye({mutationFn:r(()=>Wt.completeClaudeSetupTokenLogin(e,x),"mutationFn"),onSuccess:r(at=>{A(at.storedSessionId),a?.(at.storedSessionId)},"onSuccess"),onError:r(()=>{E(!0)},"onError")}),me=Q.data?.status??Y.data?.status??null,he=Q.data?.expiresAt??Y.data?.expiresAt??null,Ie=(0,m.useRef)(ae.mutate);Ie.current=ae.mutate,(0,m.useEffect)(()=>{me==="authenticated"&&!K.current&&(K.current=!0,Ie.current())},[me]);const de=C!==null,ve=R||q||!!(me&&gQe.has(me)),Te=me==="authenticated"&&!de&&!R,fe=!!x&&!de&&!ve&&!O,Ce=Y.isPending||fe;(0,m.useEffect)(()=>{if(!fe)return;const at=he!==null?new Date(he).getTime():NaN,Ee=Number.isFinite(at)?Math.max(0,at-Date.now()):bQe,Ne=setTimeout(()=>{x&&X(x),L(!0)},Ee);return()=>clearTimeout(Ne)},[fe,he,x,X]);const Xe=_.trim(),Oe=fe&&!!j&&!Te&&rIe(Xe)&&!ne.isPending&&!$,tt=(0,m.useRef)(c);tt.current=c;const ce=(0,m.useRef)(d);ce.current=d;const $e=r(()=>{Oe&&(y(null),ne.mutate(Xe),T(!0),tt.current?.(),u!=="onboarding"&&I(""))},"handleSubmit"),mt=(0,m.useRef)(!1),it=(0,m.useRef)(Y.mutate);it.current=Y.mutate,(0,m.useEffect)(()=>{if(!(!o||mt.current)){if(le.isError){mt.current=!0,y(le.error instanceof Error?le.error.message:"Could not check for an active login.");return}le.isSuccess&&(mt.current=!0,!le.data&&it.current())}},[o,le.isSuccess,le.isError,le.data,le.error]);const Ke=(0,m.useRef)($e);Ke.current=$e;const Ge=u==="onboarding",rt=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!Ge||!rt.current||(rt.current=!1,Oe&&Ke.current())},[Ge,Oe,_]);const jt=(0,m.useRef)(!1),st=(0,m.useRef)(l);st.current=l,(0,m.useEffect)(()=>{!de||jt.current||(jt.current=!0,st.current?.(x??void 0))},[de]),(0,m.useEffect)(()=>{$&&(!v&&!ve&&!O||(T(!1),ce.current?.()))},[$,v,ve,O]);const Nt=(0,m.useRef)(p);if(Nt.current=p,(0,m.useEffect)(()=>{Nt.current?.(j)},[j]),u==="onboarding"){const at=ve||O;return(0,t.jsxs)(nfe,{loading:!j&&!v&&!at,providerName:tfe(s),authorizationUrl:j??void 0,mode:"submitted_code",children:[w&&(0,t.jsxs)("p",{className:"flex items-start gap-2 pl-2 text-xs text-amber-700 dark:text-amber-200",children:[(0,t.jsx)(Is,{className:"mt-0.5 size-3 shrink-0"}),"This connection is not encrypted. The login code travels in clear text on this network. Continue only on a network you trust."]}),v?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:v}):at?(0,t.jsx)("p",{role:"alert",className:"pl-2 text-xs text-destructive",children:O&&!ve?UY:zY}):(0,t.jsx)(V5,{value:_,onChange:I,onSubmit:$e,onPaste:r(()=>{rt.current=!0},"onPaste"),masked:!0,disabled:ne.isPending||Te||$})]})}return(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-foreground",children:Hfe(s)}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[fe&&(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground hover:text-foreground",disabled:se.isPending,onClick:r(()=>se.mutate(),"onClick"),children:"Cancel"}),i&&Z&&!fe&&!de&&!z&&(0,t.jsx)(F,{type:"button",variant:"default",size:"sm",className:"h-7 px-2.5 text-xs",onClick:r(()=>{i(),D(!0)},"onClick"),children:"Use saved login"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:Ce,onClick:r(()=>Y.mutate(),"onClick"),children:Z&&!fe&&!de?"Sign in to replace":"Sign in"})]})]}),Z&&!fe&&!de&&!z&&(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"You have a saved Claude login. Use it to bind this agent, or log in again to replace the stored token."}),z&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"The saved Claude login is bound to this agent now."})]}),v&&(0,t.jsx)("div",{role:"alert",className:"text-(length:--text-micro) text-destructive",children:v}),(0,t.jsxs)("div",{role:"status","aria-live":"polite",className:"space-y-2 empty:hidden",children:[fe&&!j&&!Te&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Preparing..."})]}),fe&&j&&!Te&&(0,t.jsxs)("div",{className:"space-y-2",children:[w&&(0,t.jsxs)("div",{className:"flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 px-2 py-1.5 text-(length:--text-micro) text-amber-800 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-200",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0 mt-0.5"}),(0,t.jsx)("span",{children:"This connection is not encrypted. The login code travels in clear text on this network. Continue only on a network you trust."})]}),(0,t.jsx)("div",{className:"text-(length:--text-micro) text-muted-foreground",children:"Open the authorization page, then enter the browser code it shows."}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"1. Authorization URL"}),(0,t.jsx)("span",{className:"font-mono text-xs text-foreground break-all",children:j})]}),(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(_F,{value:j,label:"Copy URL"}),(0,t.jsx)(F,{asChild:!0,type:"button",variant:"ghost",size:"icon-xs","aria-label":"Open the authorization page",title:"Open the authorization page",className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)("a",{href:j,target:"_blank",rel:"noreferrer noopener",children:(0,t.jsx)(xr,{className:"size-3"})})})]})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("div",{className:"text-(length:--text-micro) uppercase tracking-wide text-muted-foreground",children:"2. Browser code"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("input",{"aria-label":"Browser code",type:"text",autoComplete:"off",spellCheck:!1,value:_,onChange:r(at=>I(at.target.value),"onChange"),onKeyDown:r(at=>{at.key==="Enter"&&(at.preventDefault(),$e())},"onKeyDown"),className:"flex-1 min-w-0 rounded-md border border-border bg-background px-2 py-1 font-mono text-xs text-foreground"}),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs",disabled:!Oe,onClick:$e,children:"Submit"})]})]})]}),Te&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsx)(ot,{className:"size-3 animate-spin shrink-0"}),(0,t.jsx)("span",{children:"Completing the login…"})]}),de&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-(length:--text-micro) text-foreground",children:[(0,t.jsx)(xs,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:"Authenticated. The environment has credentials now."})]}),ve&&(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:zY})]}),O&&!ve&&!de&&(0,t.jsxs)("div",{className:"flex items-start gap-2 text-(length:--text-micro) text-destructive",children:[(0,t.jsx)(Is,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{children:UY})]})]})]})}r(vQe,"SubmittedBrowserCodeLoginPanel");function yQe({result:e}){const s=e.status==="pass"?"Passed":e.status==="warn"?"Warnings":"Failed",n=e.status==="pass"?"text-green-700 dark:text-green-300 border-green-300 dark:border-green-500/40 bg-green-50 dark:bg-green-500/10":e.status==="warn"?"text-amber-700 dark:text-amber-300 border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10":"text-red-700 dark:text-red-300 border-red-300 dark:border-red-500/40 bg-red-50 dark:bg-red-500/10";return(0,t.jsxs)("div",{className:`rounded-md border px-3 py-2 text-xs ${n}`,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"font-medium",children:s}),(0,t.jsx)("span",{className:"text-(length:--text-micro) opacity-80",children:new Date(e.testedAt).toLocaleTimeString()})]}),(0,t.jsx)("div",{className:"mt-2 space-y-1.5",children:e.checks.map((a,i)=>(0,t.jsxs)("div",{className:"text-(length:--text-micro) leading-relaxed break-words",children:[(0,t.jsx)("span",{className:"font-medium uppercase tracking-wide opacity-80",children:a.level}),(0,t.jsx)("span",{className:"mx-1 opacity-60",children:"·"}),(0,t.jsx)("span",{children:a.message}),a.detail&&(0,t.jsxs)("span",{className:"block opacity-75 break-all",children:["(",a.detail,")"]}),a.hint&&(0,t.jsxs)("span",{className:"block opacity-90 break-words",children:["Hint: ",a.hint]})]},`${a.code}-${i}`))})]})}r(yQe,"AdapterEnvironmentResult$1");function Qfe({value:e,onChange:s,disabledTypes:n}){const[a,i]=(0,m.useState)(!1),o=Fm(e),l=(0,m.useMemo)(()=>Ufe(c=>rw[c]??sf(c)).filter(c=>!n.has(c.value)),[n]);return(0,t.jsxs)(sr,{open:a,onOpenChange:i,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e==="opencode_local"?(0,t.jsx)(dF,{className:"h-3.5 w-3.5"}):null,(0,t.jsx)("span",{className:"truncate",children:rw[e]??sf(e)}),o.experimental&&(0,t.jsx)(KY,{})]}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsx)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:l.map(c=>(0,t.jsxs)("button",{disabled:c.comingSoon,className:U("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded",c.comingSoon?"opacity-40 cursor-not-allowed":"hover:bg-accent/50",c.value===e&&!c.comingSoon&&"bg-accent"),onClick:r(()=>{c.comingSoon||(s(c.value),i(!1))},"onClick"),children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[c.value==="opencode_local"?(0,t.jsx)(dF,{className:"h-3.5 w-3.5"}):null,(0,t.jsx)("span",{children:c.label}),c.experimental&&(0,t.jsx)(KY,{})]}),c.comingSoon&&(0,t.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground",children:"Coming soon"})]},c.value))})]})}r(Qfe,"AdapterTypeDropdown");function KY(){return(0,t.jsx)("span",{className:"shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1.5 py-0.5 text-(length:--text-nano) font-medium leading-none text-amber-700 dark:text-amber-200",children:"Experimental"})}r(KY,"ExperimentalBadge$1");function tK({models:e,value:s,onChange:n,open:a,onOpenChange:i,allowDefault:o,required:l,groupByProvider:c,creatable:d,detectedModel:u,detectedModelCandidates:h,onDetectModel:p,onRefreshModels:x,refreshingModels:g,detectModelLabel:v,emptyDetectHint:y,defaultLabel:j}){const[S,w]=(0,m.useState)(""),[N,_]=(0,m.useState)(!1),I=e.find($=>$.id===s),C=S.trim(),A=!!(d&&C&&!e.some($=>$.id.toLowerCase()===C.toLowerCase())),R=(0,m.useMemo)(()=>{const $=new Set;u&&$.add(u);for(const T of h??[])T&&$.add(T);return $},[u,h]),E=(0,m.useMemo)(()=>e.filter($=>{if(R.has($.id))return!1;if(!S.trim())return!0;const T=S.toLowerCase(),q=EO($.id)??"";return $.id.toLowerCase().includes(T)||$.label.toLowerCase().includes(T)||q.toLowerCase().includes(T)}),[e,S,R]),O=(0,m.useMemo)(()=>{if(!c)return[{provider:"models",entries:[...E].sort((T,q)=>T.id.localeCompare(q.id))}];const $=new Map;for(const T of E){const q=EO(T.id)??"other",B=$.get(q)??[];B.push(T),$.set(q,B)}return Array.from($.entries()).sort(([T],[q])=>T.localeCompare(q)).map(([T,q])=>({provider:T,entries:[...q].sort((B,K)=>B.id.localeCompare(K.id))}))},[E,c]);async function L(){if(p){_(!0);try{const $=await p();$&&(n($),i(!1),w(""))}finally{_(!1)}}}return r(L,"handleDetectModel"),(0,t.jsx)(Ss,{label:"Model",hint:vi.model,children:(0,t.jsxs)(sr,{open:a,onOpenChange:r($=>{i($),$||w("")},"onOpenChange"),children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsx)("span",{className:U(!s&&"text-muted-foreground"),children:I?I.label:s||(o?j??"Default":l?"Select model (required)":"Select model")}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsxs)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:[(0,t.jsxs)("div",{className:"relative mb-1",children:[(0,t.jsx)("input",{className:"w-full px-2 py-1.5 pr-6 text-xs bg-transparent outline-none border-b border-border placeholder:text-muted-foreground/50",placeholder:d?"Search models... (type to create)":"Search models...",value:S,onChange:r($=>w($.target.value),"onChange"),autoFocus:!0}),S&&(0,t.jsx)("button",{type:"button",className:"absolute right-1.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:r(()=>w(""),"onClick"),children:(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,t.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),p&&!S.trim()&&(0,t.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-muted-foreground",onClick:r(()=>{L()},"onClick"),disabled:N,children:[(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,t.jsx)("path",{d:"M3 3v5h5"})]}),N?"Detecting...":u?v?.replace(/^Detect\b/,"Re-detect")??"Re-detect from config":v??"Detect from config"]}),x&&!S.trim()&&(0,t.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-muted-foreground",onClick:r(()=>{x()},"onClick"),disabled:g,children:[(0,t.jsxs)("svg",{"aria-hidden":"true",focusable:"false",className:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M3 12a9 9 0 0 1 15.28-6.36L21 8"}),(0,t.jsx)("path",{d:"M21 3v5h-5"}),(0,t.jsx)("path",{d:"M21 12a9 9 0 0 1-15.28 6.36L3 16"}),(0,t.jsx)("path",{d:"M8 16H3v5"})]}),g?"Refreshing...":"Refresh models"]}),s&&(!e.some($=>$.id===s)||R.has(s))&&(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded bg-accent/50"),onClick:r(()=>{i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:s,children:e.find($=>$.id===s)?.label??s}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-green-500/15 text-green-400 border-green-500/20",children:"current"})]}),u&&u!==s&&(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50"),onClick:r(()=>{n(u),i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:u,children:e.find($=>$.id===u)?.label??u}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-blue-500/15 text-blue-400 border-blue-500/20",children:"detected"})]}),h?.filter($=>$&&$!==u&&$!==s).map($=>{const T=e.find(q=>q.id===$);return(0,t.jsxs)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50"),onClick:r(()=>{n($),i(!1)},"onClick"),children:[(0,t.jsx)("span",{className:"block w-full text-left truncate font-mono text-xs",title:$,children:T?.label??$}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano) px-1.5 bg-sky-500/15 text-sky-400 border-sky-500/20",children:"config"})]},`detected-${$}`)}),(0,t.jsxs)("div",{className:"max-h-(--sz-240px) overflow-y-auto",children:[o&&(0,t.jsx)("button",{type:"button",className:U("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",!s&&"bg-accent"),onClick:r(()=>{n(""),i(!1)},"onClick"),children:"Default"}),A&&(0,t.jsxs)("button",{type:"button",className:"flex items-center justify-between gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",onClick:r(()=>{n(C),i(!1),w("")},"onClick"),children:[(0,t.jsx)("span",{children:"Use manual model"}),(0,t.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:C})]}),O.map($=>(0,t.jsxs)("div",{className:"mb-1 last:mb-0",children:[c&&(0,t.jsxs)("div",{className:"px-2 py-1 text-(length:--text-nano) uppercase tracking-wide text-muted-foreground",children:[$.provider," (",$.entries.length,")"]}),$.entries.map(T=>(0,t.jsx)("button",{type:"button",className:U("flex items-center w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",T.id===s&&"bg-accent"),onClick:r(()=>{n(T.id),i(!1)},"onClick"),children:(0,t.jsx)("span",{className:"block w-full text-left truncate",title:T.id,children:c?rBe(T.id):T.label})},T.id))]},$.provider)),E.length===0&&!A&&R.size===0&&(0,t.jsx)("div",{className:"px-2 py-2 space-y-2",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:p?y??"No model detected yet. Enter a provider/model manually.":"No models found."})})]})]})]})})}r(tK,"ModelDropdown");function jQe({value:e,options:s,onChange:n,open:a,onOpenChange:i}){const o=s.find(l=>l.id===e)??s[0];return(0,t.jsx)(Ss,{label:"Thinking effort",hint:vi.thinkingEffort,children:(0,t.jsxs)(sr,{open:a,onOpenChange:i,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-sm hover:bg-accent/50 transition-colors w-full justify-between",children:[(0,t.jsx)("span",{className:U(!e&&"text-muted-foreground"),children:o?.label??"Auto"}),(0,t.jsx)(en,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,t.jsx)(Gn,{className:"w-(--radix-popover-trigger-width) p-1",align:"start",children:s.map(l=>(0,t.jsxs)("button",{className:U("flex items-center justify-between w-full px-2 py-1.5 text-sm rounded hover:bg-accent/50",l.id===e&&"bg-accent"),onClick:r(()=>{n(l.id),i(!1)},"onClick"),children:[(0,t.jsx)("span",{children:l.label}),l.id?(0,t.jsx)("span",{className:"text-xs text-muted-foreground font-mono",children:l.id}):null]},l.id||"auto"))})]})})}r(jQe,"ThinkingEffortDropdown");function Gfe(e){const s=`paperclip.agent-appearance.${e}`;function n(){try{const l=ole.safeParse(JSON.parse(sessionStorage.getItem(s)??"null"));if(l.success)return l.data}catch{}const o=ZA();try{sessionStorage.setItem(s,JSON.stringify(o))}catch{}return o}r(n,"readDraft");const[a,i]=(0,m.useState)(()=>({key:s,appearance:n()}));return a.key!==s&&i({key:s,appearance:n()}),{appearance:a.appearance,clear(){try{sessionStorage.removeItem(s)}catch{}}}}r(Gfe,"useAgentAppearanceDraft");var HN=null,lI=new Set,QN={subscribe(e){return lI.add(e),()=>{lI.delete(e)}},getSnapshot(){return HN},acquire(e){if(HN)return!1;HN=e;for(const s of lI)s();return!0},release(e){if(HN===e){HN=null;for(const s of lI)s()}}};function oC({agent:e,appearance:s,size:n=256,state:a="idle",muted:i=!1,motion:o="auto",trackingRegion:l,trackingScope:c="region",followCursor:d=!0,followRotation:u=!0,className:h,label:p,name:x}){const g=(0,m.useMemo)(()=>Cw(s??e?.appearance,e?.id),[s,e?.appearance,e?.id]),v=(0,m.useRef)(null),y=(0,m.useRef)(null),j=(0,m.useRef)(null),S=(0,m.useRef)(Symbol("agent-character")),w=(0,m.useSyncExternalStore)(QN.subscribe,QN.getSnapshot,()=>null),[N,_]=(0,m.useState)(!1),[I,C]=(0,m.useState)(!0),[A,R]=(0,m.useState)(!1),[E,O]=(0,m.useState)(!1),L=N&&!I&&!A&&o==="auto"&&a!=="rest";return(0,m.useEffect)(()=>{if(typeof matchMedia!="function"||typeof IntersectionObserver!="function")return;const $=matchMedia("(prefers-reduced-motion: reduce)"),T=r(()=>C($.matches),"change");T(),$.addEventListener("change",T);const q=new IntersectionObserver(B=>_(B[0]?.isIntersecting??!1));return v.current&&q.observe(v.current),()=>{q.disconnect(),$.removeEventListener("change",T)}},[]),(0,m.useEffect)(()=>{L&&w===null&&QN.acquire(S.current),L||QN.release(S.current)},[L,w]),(0,m.useEffect)(()=>()=>QN.release(S.current),[]),(0,m.useEffect)(()=>{if(!L||w!==S.current)return;let $=!1;return O(!1),Promise.all([gc(()=>import("./runtime-IAg0vdY9.js"),__vite__mapDeps([0,1])),gc(()=>import("./definition-C9sWnmbO.js"),__vite__mapDeps([2,3,1]))]).then(([T,q])=>{$||!y.current||(j.current=T.createCharacter(y.current,q.characterDefinition(g,i),{animation:q.animationId(a),trackingRegion:l?.current??v.current??void 0,followCursor:d,followRotation:u,trackingScope:c,displaySize:n,onError:r(()=>R(!0),"onError")}),O(!0))}).catch(()=>{$||R(!0)}),()=>{$=!0,j.current?.destroy(),j.current=null,O(!1)}},[L,w,l,c,n,d,u]),(0,m.useEffect)(()=>{j.current&&gc(()=>import("./definition-C9sWnmbO.js").then($=>{j.current?.setDefinition($.characterDefinition(g,i)),j.current?.setAnimation($.animationId(a))}),__vite__mapDeps([2,3,1]))},[g,i,a,E]),(0,t.jsxs)("span",{ref:v,role:p?"img":void 0,"aria-label":p,"aria-hidden":p?void 0:!0,className:U("relative inline-block shrink-0",o2e[n],h),children:[(0,t.jsx)(hr,{agent:e,appearance:g,size:n<256?256:n,name:x,pose:a,muted:i,className:U("size-full",E&&"invisible")}),(0,t.jsx)("span",{ref:y,className:"absolute inset-0"})]})}r(oC,"AgentCharacter");var wQe=new Set(["claude_local","codex_local","opencode_local","grok_local"]);function Yfe(e,{cloud:s,nativeRunnerEnabled:n}){return s?wQe.has(e):e!=="paperclip_runner"||n}r(Yfe,"isNewAgentAdapterAllowed");var NQe={claude_local:{src:"/brands/claude-color.svg"},codex_local:{src:"/brands/codex-color.svg"},gemini_local:{src:"/brands/adapters/gemini-color.svg"},kimi_local:{src:"/brands/adapters/kimi-color-light.svg",dark:"/brands/adapters/kimi-color.svg"},...Object.fromEntries([["cursor","cursor"],["cursor_cloud","cursor"],["grok_local","grok"],["hermes_local","hermesagent"],["hermes_gateway","hermesagent"],["pi_local","pi"]].map(([e,s])=>[e,{src:`/brands/adapters/${s}.svg`,dark:`/brands/adapters/${s}-dark.svg`}]))};function sK({type:e,className:s="size-6"}){const n=Fm(e).icon,a=NQe[e];return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("img",{src:a.src,className:U("shrink-0 object-contain",a.dark&&"dark:hidden",s),alt:""}),a.dark&&(0,t.jsx)("img",{src:a.dark,className:U("hidden shrink-0 object-contain dark:block",s),alt:""})]}):(0,t.jsx)(n,{className:s})}r(sK,"AdapterMark");function kQe(){const{selectedCompanyId:e}=fs(),{appearance:s}=Gfe(`${e}:new-agent`);return(0,t.jsx)(oC,{appearance:s,state:"sleepy",muted:!0,size:256,className:"size-48",trackingScope:"page"})}r(kQe,"AgentBasicsCharacter");function Jfe({open:e,onClose:s,onContinue:n,initialAdapter:a="",onInvite:i}){const o=(0,m.useId)(),l=!!Vc(),c=ee({queryKey:P.instance.experimentalSettings,queryFn:Tr.getExperimental,enabled:e,retry:!1}),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(a),[x,g]=(0,m.useState)("codex"),[v,y]=(0,m.useState)("name"),{data:j,isPending:S,error:w}=ee({queryKey:P.adapters.all,queryFn:Cm.list,enabled:e}),N=(j??[]).filter(I=>I.loaded&&!I.disabled&&Yfe(I.type,{cloud:l,nativeRunnerEnabled:c.data?.enableNativeRunner===!0})&&!["process","http"].includes(I.type)&&!Fm(I.type).comingSoon),_=N.some(I=>I.type===h);return(0,t.jsx)(Xs,{open:e,onOpenChange:r(I=>{I||s()},"onOpenChange"),children:(0,t.jsxs)(Zs,{className:U("flex max-h-(--sz-calc-18) flex-col gap-0 overflow-hidden p-0 sm:max-w-(--sz-640px)",v==="name"&&"sm:max-w-(--sz-560px)"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-6 py-5 text-xs text-muted-foreground","aria-label":"New agent progress",children:[(0,t.jsx)("span",{className:U(v==="name"&&"font-medium text-foreground"),children:"1. Name"}),(0,t.jsx)(mn,{className:"size-3"}),(0,t.jsx)("span",{className:U(v==="adapter"&&"font-medium text-foreground"),children:"2. Adapter"})]}),(0,t.jsxs)("form",{className:"flex min-h-0 flex-col",onSubmit:r(I=>{I.preventDefault(),d.trim()&&(v==="name"?y("adapter"):_&&n({name:d.trim(),adapterType:h,runnerProvider:x}))},"onSubmit"),children:[(0,t.jsxs)("div",{className:"flex min-h-0 flex-col gap-7 overflow-y-auto px-6 pb-8 sm:px-10",children:[(0,t.jsxs)("div",{className:"flex flex-col items-center gap-4 text-center",children:[e&&(0,t.jsx)(kQe,{}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(rn,{className:"text-3xl font-semibold tracking-tight",children:v==="name"?"Meet your next agent":"Choose an adapter"}),(0,t.jsx)(Dn,{className:"text-base",children:v==="name"?"Start with a name. Make them your own.":`How should ${d.trim()} work?`})]})]}),v==="name"?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("label",{htmlFor:o,className:"text-sm font-medium",children:"Agent name"}),(0,t.jsx)(Rt,{id:o,autoFocus:!0,maxLength:100,placeholder:"e.g. Darnold",value:d,onChange:r(I=>u(I.target.value),"onChange"),className:"h-12 text-base"}),i&&(0,t.jsx)(F,{type:"button",variant:"link",className:"px-0 text-muted-foreground",onClick:i,children:"Invite an external agent"})]}):(0,t.jsxs)("fieldset",{className:"space-y-4",children:[(0,t.jsx)("legend",{className:"sr-only",children:"Adapter"}),S&&(0,t.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Loading adapters…"}),w&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:w.message}),(0,t.jsx)("div",{className:U("grid grid-cols-2 gap-3",N.length!==4&&"sm:grid-cols-3"),children:N.map(I=>{const C=Fm(I.type);return(0,t.jsxs)("label",{className:"relative cursor-pointer",children:[(0,t.jsx)("input",{type:"radio",name:"new-agent-adapter",value:I.type,checked:h===I.type,onChange:r(()=>p(I.type),"onChange"),className:"peer sr-only"}),(0,t.jsxs)("span",{className:U("flex h-full flex-col items-center gap-2 rounded-lg border px-3 py-4 text-center peer-focus-visible:ring-2 peer-focus-visible:ring-ring hover:bg-accent/40",h===I.type?"border-foreground/40 bg-accent":"border-border bg-card"),children:[(0,t.jsx)(sK,{type:I.type}),(0,t.jsx)("span",{className:"text-sm font-medium",children:C.label}),h===I.type&&(0,t.jsx)(xs,{className:"absolute right-2 top-2 size-3.5"})]})]},I.type)})}),_&&h==="paperclip_runner"&&(0,t.jsxs)("label",{className:"flex flex-col gap-2 text-sm font-medium",children:["Runner",(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:x,onChange:r(I=>g(I.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"codex",children:"Codex (app server)"}),(0,t.jsx)("option",{value:"claude",children:"Claude (ACPX)"}),(0,t.jsx)("option",{value:"opencode",children:"OpenCode"})]})]})]})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-4 border-t border-border px-6 py-4",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>v==="name"?s():y("name"),"onClick"),children:v==="name"?"Cancel":(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(sc,{className:"size-4"}),"Back"]})}),(0,t.jsxs)(F,{type:"submit",disabled:!d.trim()||v==="adapter"&&!_,children:[v==="name"?"Choose adapter":"Configure agent",(0,t.jsx)(Zo,{className:"size-4"})]})]})]})]})})}r(Jfe,"AgentBasicsDialog");var SQe={subscription:"Subscription",api:"API"};function CQe({mode:e}){return(0,t.jsx)("span",{className:"relative flex h-4 w-full items-center justify-center overflow-hidden text-(length:--text-micro) text-muted-foreground",children:(0,t.jsx)(Jw,{initial:!1,mode:"sync",children:(0,t.jsx)(Yo.span,{className:"absolute inset-0 flex items-center justify-center whitespace-nowrap",initial:{opacity:0,y:iY},animate:{opacity:1,y:0,transition:J8e},exit:{opacity:0,y:iY,transition:X8e},children:SQe[e]},e)})})}r(CQe,"CredentialTag");function _Qe({source:e,mode:s,selected:n,onSelect:a,buttonRef:i,settling:o}){return(0,t.jsxs)("button",{ref:i,type:"button",role:"radio","aria-checked":n,onClick:a,className:U("flex min-w-0 flex-1 cursor-pointer flex-col items-center gap-1.5 self-stretch rounded-md border p-3","transition-(--tp-border-color-background-color) ease-(--motion-ease-standard)",o?"duration-(--motion-duration-slow)":"duration-(--motion-duration-fast)","outline-none focus-visible:ring-ring/50 focus-visible:ring-(length:--rad-3)",n?"border-foreground/40 bg-accent":"border-border bg-card hover:bg-accent/40"),children:[(0,t.jsx)("span",{className:"flex size-(--sz-30px) shrink-0 items-center justify-center",children:e.icon}),(0,t.jsx)("span",{className:"text-(length:--text-compact) font-medium text-foreground",children:e.label}),(0,t.jsx)(CQe,{mode:s})]})}r(_Qe,"ModelSourceTile");function Xfe({sources:e,mode:s,selectedId:n,onSelect:a,label:i,collapsed:o=!1,settling:l=!1}){const c=(0,m.useRef)(new Map),d=r(h=>{if(e.length===0)return;const p=e.findIndex(g=>g.id===n),x=e[((p===-1?h>0?-1:0:p)+h+e.length)%e.length];a(x.id),c.current.get(x.id)?.focus()},"moveSelection"),u=o?e.filter(h=>h.id===n):e;return(0,t.jsx)("div",{role:"radiogroup","aria-label":i,className:U("flex items-start gap-3",o&&"justify-center"),onKeyDown:r(h=>{o||(h.key==="ArrowRight"||h.key==="ArrowDown"?(h.preventDefault(),d(1)):(h.key==="ArrowLeft"||h.key==="ArrowUp")&&(h.preventDefault(),d(-1)))},"onKeyDown"),children:(0,t.jsx)(Jw,{initial:!1,mode:"popLayout",children:u.map(h=>(0,t.jsx)(Yo.div,{layout:!0,transition:efe,exit:{opacity:0,transition:l7e},className:U("flex min-w-0",o?"w-(--sz-source-tile-two-up)":"flex-1"),children:(0,t.jsx)(_Qe,{source:h,mode:s,selected:h.id===n,onSelect:r(()=>a(h.id),"onSelect"),settling:l,buttonRef:r(p=>{p?c.current.set(h.id,p):c.current.delete(h.id)},"buttonRef")})},h.id))})})}r(Xfe,"ModelSourceTiles");var R4={subscription:"Use API key instead",api:"Use subscription instead"},IQe={subscription:"api",api:"subscription"};function Zfe({mode:e,onChange:s}){return(0,t.jsxs)("button",{type:"button",onClick:r(()=>s(IQe[e]),"onClick"),className:U("group grid cursor-pointer px-3 py-2 text-left text-sm font-medium","rounded-md outline-none focus-visible:ring-ring/50 focus-visible:ring-(length:--rad-3)"),children:[Object.keys(R4).map(n=>(0,t.jsx)("span",{"aria-hidden":!0,className:"invisible col-start-1 row-start-1 whitespace-nowrap",children:R4[n]},n)),(0,t.jsx)(Jw,{initial:!1,mode:"sync",children:(0,t.jsx)(Yo.span,{className:U("col-start-1 row-start-1 justify-self-start whitespace-nowrap","underline decoration-muted-foreground/40 underline-offset-4","text-muted-foreground transition-colors","group-hover:text-foreground group-hover:decoration-foreground/40"),initial:{opacity:0},animate:{opacity:1,transition:VU},exit:{opacity:0,transition:Z8e},children:R4[e]},e)})]})}r(Zfe,"CredentialModeLink");function exe({onBack:e,primaryLabel:s,primaryDisabled:n,loading:a,loadingLabel:i,primaryIcon:o,onPrimary:l}){const c=a&&i?i:s,d=o??(a?"spinner":"arrow");return(0,t.jsxs)("div",{className:"flex items-center justify-between pt-9",children:[e?(0,t.jsxs)(F,{variant:"ghost",size:"lg",className:"rounded-full has-[>svg]:pl-4 has-[>svg]:pr-5",onClick:e,disabled:a,children:[(0,t.jsx)(sc,{className:"mr-1 size-3.5"}),"Back"]}):(0,t.jsx)("span",{}),(0,t.jsx)(Yo.div,{layout:!0,transition:s7e,className:"min-w-0",children:(0,t.jsx)(F,{size:"lg",className:"w-full rounded-full px-6",onClick:l,disabled:n||a,children:(0,t.jsxs)(Yo.span,{className:"flex items-center whitespace-nowrap",initial:{opacity:0},animate:{opacity:1},transition:n7e,children:[d==="spinner"?(0,t.jsx)(ot,{className:"mr-1 size-4 animate-spin"}):null,c,d==="arrow"?(0,t.jsx)(Zo,{className:"ml-1 size-3.5"}):null]},`${c}:${d}`)})})]})}r(exe,"FooterNav");function txe({companyId:e,adapterType:s,environmentId:n,canLogin:a,localEnvironment:i=!1,onConnected:o,onBack:l,testConnection:c,testError:d,managedAccount:u}){const h=ee({queryKey:P.health,queryFn:Ju.get,enabled:i}),p=i&&(h.data?.localAiLoginSupported??h.data?.deploymentMode==="local_trusted"),x=(0,m.useRef)(0);(0,m.useEffect)(()=>()=>{x.current++},[]);const g=r(()=>{x.current++,O(!1),S(!1),N(null),I("preparing")},"cancel"),[v,y]=(0,m.useState)(u?.initialMethod==="api_key"?"api":u?"subscription":null),[j,S]=(0,m.useState)(!1),[w,N]=(0,m.useState)(null),[_,I]=(0,m.useState)("preparing"),C=(0,m.useRef)("ready"),[A,R]=(0,m.useState)(""),[E,O]=(0,m.useState)(!1),[L,$]=(0,m.useState)(null),[T,q]=(0,m.useState)(null),B=s==="claude_local"?"Claude":s==="grok_local"?"Grok":"OpenAI",K=s==="claude_local"?"ANTHROPIC_API_KEY":s==="grok_local"?"XAI_API_KEY":"OPENAI_API_KEY",z=s==="claude_local"?"anthropic":s==="grok_local"?"xai":"openai",D=Fpe(e,K),V=u?{...D,options:[],subscriptions:[],loading:!1}:D,[H,Z]=(0,m.useState)(null),Y=V.subscriptions.length?V.subscriptions.find(ne=>ne.id===(H??V.subscriptions[0]?.id)):void 0,[ie,se]=(0,m.useState)(null),X=V.options.find(ne=>ne.id===(ie??V.options[0]?.id)),le=u?{...V.storedLogin,data:void 0,isPending:!1,isError:!1}:V.storedLogin,oe=(0,m.useRef)(null),te=v??(V.subscriptions.length>0||s==="claude_local"&&!Y&&le.data?"subscription":V.options.length?"api":"subscription"),J=nhe(e,u?.intent??{provider:z,method:"subscription",name:`My ${B} subscription`,ownership:"personal",agentIds:[],allAgents:!0},p&&te==="subscription"&&!Y&&!le.data,{allowHostClaude:h.data?.deploymentMode==="local_trusted"}),Q=ee({queryKey:P.agents.authSignal(e,s,n),queryFn:r(()=>Wt.getAdapterAuthSignal(e,s,n??void 0),"queryFn"),retry:!1,enabled:!u});async function pe(){if(E||u?.disabled)return;const ne=++x.current;O(!0),$(null);try{if(u){if(te==="subscription"&&!p)return;const he=oe.current??await(te==="api"?ou.create(e,{...u.intent,method:"api_key",apiKey:A.trim()}):J.connect(u.intent));oe.current=he,R(""),ne===x.current&&u.onComplete({...he,method:te==="api"?"api_key":"subscription"});return}let ae=te==="api"?X?X.aiConnection?{env:{},aiConnection:X.aiConnection}:{env:{[K]:X.binding}}:T??{env:{},credentials:{[K]:A.trim()}}:{...Y?.aiConnection?{aiConnection:Y.aiConnection}:{},env:Y?.binding?{CODEX_HOME:Y.binding}:{},...s==="claude_local"&&!Y&&le.data?{env:sj(),applyStoredClaudeLogin:!0}:{}};if(te==="subscription"&&p&&!Y&&!le.data&&(oe.current??=await J.connect(),ae={env:{},aiConnection:{provider:z,method:"subscription",mode:"responsible_user"}}),ae.credentials&&(await ou.create(e,{provider:z,method:"api_key",name:`My ${B} API`,ownership:"personal",apiKey:ae.credentials[K],agentIds:[],allAgents:!0}),ae={env:{},aiConnection:{provider:z,method:"api_key",mode:"responsible_user"}}),ne!==x.current)return;te==="api"&&(R(""),X||q(ae));const me=await c(ae);if(ne!==x.current)return;me?o(ae):$("The provider did not respond. Check the connection and try again.")}catch(ae){if(ne!==x.current)return;u&&R(""),$(ae instanceof Error?ae.message:"Could not connect to the provider.")}finally{ne===x.current&&O(!1)}}r(pe,"connect");const re=te==="subscription"&&a&&n&&!Y&&!V.loading&&!le.data&&(!!u||Q.data?.status!=="present"||H==="");return(0,t.jsxs)("div",{className:"min-w-0 max-w-full",children:[(0,t.jsx)(Xfe,{label:"Connect your model provider",sources:[{id:s,label:B,icon:(0,t.jsx)(sK,{type:s})}],mode:te,selectedId:j?s:null,collapsed:j,onSelect:r(()=>{u?.disabled||S(!0)},"onSelect")}),!j&&!u?.fixedMethod&&(0,t.jsx)("div",{className:"-ml-3 mt-1",children:(0,t.jsx)(Zfe,{mode:te,onChange:r(ne=>{oe.current=null,y(ne),$(null)},"onChange")})}),!j&&V.options.length>0&&(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:[V.options.length," saved API"," ",V.options.length===1?"key available":"keys available","."]}),te==="subscription"&&V.subscriptions.length>0&&(0,t.jsx)(Nj,{options:V.subscriptions,value:Y?.id??"",onChange:Z,loading:!1,error:!1,kind:"subscription",disabled:E}),(0,t.jsx)(Yo.div,{initial:!1,animate:{height:j?"auto":0,opacity:j?1:0},transition:{height:id,opacity:U5},className:"overflow-hidden",children:j&&(0,t.jsx)("div",{className:"pt-5",children:te==="api"?(0,t.jsxs)(K5,{instruction:V.options.length?"Choose a saved API key or enter a new one":`Provide your ${B} API key to connect`,children:[(0,t.jsx)(Nj,{...V,value:X?.id??"",disabled:E,onChange:r(ne=>{se(ne),R(""),q(null),$(null)},"onChange")}),!X&&(0,t.jsx)(V5,{label:"API key",masked:!0,autoFocus:!0,value:A,placeholder:T?"Key entered. Retry the connection.":"Enter API key here",onChange:r(ne=>{se(""),R(ne),q(null)},"onChange"),onSubmit:r(()=>{pe()},"onSubmit"),disabled:E})]}):re?(0,t.jsx)(eK,{companyId:e,adapterType:s,environmentId:n,chrome:"onboarding",aiConnection:u?.intent??{provider:z,method:"subscription",name:`My ${B} subscription`,ownership:"personal",agentIds:[],allAgents:!0},autoStart:!0,onStored:r(()=>{},"onStored"),onPromptReady:r(ne=>{N(ne),I(ae=>ne?ae==="preparing"?"ready":ae:"preparing")},"onPromptReady"),onCodeSubmitted:r(()=>{C.current=_==="waiting"?"waiting":"ready",I("connecting")},"onCodeSubmitted"),onSubmitFailed:r(()=>{I(ne=>ne==="connecting"?C.current:ne)},"onSubmitFailed"),onConnected:r(ne=>{if(u){if(!ne){$("The login did not return a saved connection. Try again.");return}const me=x.current;I("connecting"),ou.loginResult(e,ne).then(he=>{me===x.current&&u.onComplete({...he,method:"subscription"})}).catch(()=>{me===x.current&&(I("ready"),$("Could not retrieve the saved connection. Go back and retry."))});return}const ae={env:{},aiConnection:{provider:z,method:"subscription",mode:"responsible_user"}};q(ae),o(ae)},"onConnected")}):Y?null:p&&!le.data?(0,t.jsx)(WU,{adapterType:s,login:{...J,retry:r(()=>{$(null),J.retry()},"retry")}}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:le.data?"Use your saved Claude subscription for this agent.":a?"Use the existing provider connection for this environment.":"This environment does not support browser sign-in. Choose a sign-in environment or connect with an API key."})})}),te==="subscription"&&le.isError&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:"Could not check your saved Claude subscription. Try again."}),L&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:d??L}),i&&h.isError&&(0,t.jsx)("p",{role:"alert",className:"mt-4 text-sm text-destructive",children:"Could not prepare sign-in. Reload this page to try again."}),(0,t.jsx)(exe,{onBack:r(()=>{j?g():l()},"onBack"),primaryLabel:j&&re?_==="waiting"?"Waiting for code":_==="connecting"?"Connecting":`Sign in to ${B}`:E?"Connecting":te==="subscription"&&(le.data||Y)?"Use saved subscription":te==="api"&&X?"Use saved API key":"Connect",primaryDisabled:u?.disabled||!!u&&te==="subscription"&&!a&&!p||i&&h.isPending||J.preparing||!!J.error||!u&&Q.isPending||V.loading||s==="claude_local"&&le.isPending||!j||!!re&&(!w||_!=="ready")||te==="api"&&!A.trim()&&!T&&!X,loading:E,primaryIcon:j&&re?_==="ready"?"none":"spinner":void 0,onPrimary:r(()=>{if(re){if(!w||_!=="ready")return;window.open(w,"_blank","noreferrer,noopener"),I("waiting")}else pe()},"onPrimary")})]})}r(txe,"AgentProviderConnection");function IT(e){return e.provider==="openrouter"?(0,t.jsx)(RQe,{...e}):(0,t.jsx)(AQe,{...e})}r(IT,"AiConnectionCredentialStep");function AQe({companyId:e,provider:s,initialMethod:n,fixedMethod:a,connectionId:i,name:o,ownership:l,agentIds:c,allAgents:d,environmentId:u,onComplete:h,onCancel:p}){const[x,g]=(0,m.useState)(o),[v,y]=(0,m.useState)(),j=Ht(),S=ee({queryKey:P.environments.list(e),queryFn:r(()=>_i.list(e),"queryFn")}),w=ee({queryKey:P.environments.capabilities(e),queryFn:r(()=>_i.capabilities(e),"queryFn")}),N=ee({queryKey:P.instance.settings,queryFn:Tr.get}),_=ee({queryKey:P.instance.experimentalSettings,queryFn:Tr.getExperimental}),I=ee({queryKey:P.instance.generalSettings,queryFn:Tr.getGeneral}),C=ZU(I.data?.executionMode,S.data??[]);let A=null,R;try{A=C.forced?C.kubernetesEnvironment?.id??null:iw({agentDefaultEnvironmentId:u??v,instanceDefaultEnvironmentId:N.data?.defaultEnvironmentId,localDefaultEnvironmentId:lw(S.data),managedSandboxOnly:_.data?.enableManagedSandboxOnly,managedSandboxEnvironmentId:ow(S.data),visibleEnvironmentIds:S.data?.map(K=>K.id)})}catch(K){R=K instanceof Error?K.message:"Could not resolve the sign-in environment."}const E=(S.data??[]).filter(K=>K.status==="active"&&(K.driver==="local"||K.driver==="sandbox"&&typeof K.config.provider=="string"&&w.data?.sandboxProviders?.[K.config.provider]?.supportsLoginPty===!0));!C.forced&&!u&&!v&&!E.some(K=>K.id===A)&&(A=E[0]?.id??null);const O=S.data?.find(K=>K.id===A),L=typeof O?.config.provider=="string"?O.config.provider:"",$=O?.driver==="sandbox"&&w.data?.sandboxProviders?.[L]?.supportsLoginPty===!0,T=[S,w,N,_,I].some(K=>K.isPending),q=R??[S,w,N,_,I].find(K=>K.error)?.error?.message,B={provider:s,method:"subscription",name:x,ownership:l,agentIds:c,allAgents:d,connectionId:i};return(0,t.jsxs)("div",{className:"mx-auto w-full min-w-0 max-w-xl space-y-6",children:[(0,t.jsxs)("label",{className:"block space-y-2 text-sm",children:["Connection name",(0,t.jsx)(Rt,{value:x,onChange:r(K=>g(K.target.value),"onChange"),disabled:!!i})]}),!u&&!C.forced&&E.length>1&&(0,t.jsxs)(Ra,{value:A??"",onValueChange:y,children:[(0,t.jsx)(Aa,{"aria-label":"Sign-in environment",children:(0,t.jsx)(_a,{placeholder:"Sign-in environment"})}),(0,t.jsx)(Ia,{children:E.map(K=>(0,t.jsx)(yn,{value:K.id,children:K.name},K.id))})]}),q&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:q}),T?(0,t.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Preparing sign-in…"}):(0,t.jsx)(txe,{companyId:e,adapterType:s==="anthropic"?"claude_local":s==="xai"?"grok_local":"codex_local",environmentId:A,canLogin:$,localEnvironment:O?.driver==="local",onBack:p,onConnected:r(()=>{},"onConnected"),testConnection:r(async()=>!1,"testConnection"),managedAccount:{intent:B,initialMethod:n,fixedMethod:a||!!i,disabled:T||!!q||!x.trim(),onComplete:r(K=>{j.invalidateQueries({queryKey:["ai-connections",e]}),h(K)},"onComplete")}},A??"local")]})}r(AQe,"SubscriptionConnectionStep");function RQe({companyId:e,provider:s,connectionId:n,name:a,ownership:i,agentIds:o,allAgents:l,onComplete:c,onCancel:d}){const[u,h]=(0,m.useState)(a),[p,x]=(0,m.useState)(""),g=Ht(),v=ye({mutationFn:r(()=>ou.create(e,{provider:s,method:"api_key",name:u,ownership:i,agentIds:o,allAgents:l,connectionId:n,apiKey:p}),"mutationFn"),onSuccess:r(y=>{g.invalidateQueries({queryKey:["ai-connections",e]}),c({...y,method:"api_key"})},"onSuccess"),onSettled:r(()=>x(""),"onSettled")});return(0,t.jsxs)("div",{className:"mx-auto w-full min-w-0 max-w-xl space-y-4",children:[(0,t.jsxs)("label",{className:"block space-y-2 text-sm",children:["Connection name",(0,t.jsx)(Rt,{value:u,onChange:r(y=>h(y.target.value),"onChange"),disabled:!!n})]}),v.error&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:v.error.message}),(0,t.jsx)(rfe,{providerName:"OpenRouter",value:p,onChange:x,onSubmit:r(()=>v.mutate(),"onSubmit"),disabled:v.isPending,placeholder:"Enter API key here",autoFocus:!0}),(0,t.jsxs)("div",{className:"flex justify-between gap-2",children:[(0,t.jsx)(F,{variant:"ghost",onClick:d,children:"Cancel"}),(0,t.jsx)(F,{disabled:!u.trim()||!p.trim()||v.isPending,onClick:r(()=>v.mutate(),"onClick"),children:v.isPending?"Connecting…":"Connect"})]})]})}r(RQe,"ApiKeyConnectionStep");var TQe=new RegExp(`\\b(${["mcp","server","profile","policy","gateway","transport","stdio","endpoint"].join("|")})s?\\b`,"gi");function sxe(e){return e.replace(TQe,"").replace(/\s{2,}/g," ").replace(/\s+([.,])/g,"$1").trim()}r(sxe,"sanitizeProsumerCopy");var EQe={zapier:{tagline:"Reach 9,000+ apps your team already uses.",short:"Reach 9,000+ apps from your agents."},github:{tagline:"Read code and pull requests, comment on issues.",short:"Read code and pull requests, comment on issues."},slack:{tagline:"Send and read messages in your team's channels.",short:"Send and read messages in your channels."},notion:{tagline:"Read and update pages in your workspace.",short:"Read and update pages in your workspace."},railway:{tagline:"Inspect services, read logs, and manage deployments.",short:"Connect Railway for deployments, logs, and container access."},posthog:{tagline:"Explore product usage, errors, flags, and experiments.",short:"Sign in with PostHog. Project pinning and access controls are optional."},linear:{tagline:"Create, update and read tickets.",short:"Create, update and read tickets."},"google-sheets":{tagline:"Read and update selected spreadsheets.",short:"Read spreadsheets or update the files you choose."},gmail:{tagline:"Read mail and create drafts for your review.",short:"Read mail and create drafts for your review."},"google-drive":{tagline:"Find, read, and create files in Drive.",short:"Find, read, and create files in Drive."},"google-docs":{tagline:"Read and update documents.",short:"Read and update documents."},"google-slides":{tagline:"Read and update presentations.",short:"Read and update presentations."},"google-calendar":{tagline:"Review calendars and manage events.",short:"Review calendars and manage events."},"google-chat":{tagline:"Read conversations and send messages.",short:"Read conversations and send messages."},"google-people":{tagline:"Look up contacts and people in your directory.",short:"Look up contacts and people in your directory."},"google-workspace-search":{tagline:"Search across your Google workspace.",short:"Search across your Google workspace."},hubspot:{tagline:"Look up contacts and update deal stages.",short:"Look up contacts and update deal stages."},intercom:{tagline:"Read and reply to customer conversations.",short:"Read and reply to customer conversations."},figma:{tagline:"Read files and post comments on frames.",short:"Read files and post comments on frames."},stripe:{tagline:"Read customers, invoices, and payouts.",short:"Read customers, invoices, and payouts."},context7:{tagline:"Look up up-to-date docs for your libraries.",short:"Look up up-to-date docs for your libraries."}},PQe={tagline:"Give your agents access to this app.",short:"Give your agents access to this app."};function nxe(e,s){const n=EQe[e];if(n)return n;if(s){const a=sxe(s);if(a)return{tagline:a,short:a}}return PQe}r(nxe,"appCopyFor");function VY(e,s,n){return n<=1?`Your ${e} key`:sxe(s)||`Your ${e} key`}r(VY,"credentialFieldLabel");var MQe=1500;function nf(e=MQe){const[s,n]=(0,m.useState)("idle"),a=(0,m.useRef)(null),i=(0,m.useRef)(0);(0,m.useEffect)(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);const o=(0,m.useCallback)(async l=>{const c=++i.current;let d="copied";try{await Gr(l)}catch{d="failed"}return i.current!==c||(n(d),a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{i.current===c&&(n("idle"),a.current=null)},e)),d},[e]);return{status:s,copied:s==="copied",failed:s==="failed",copy:o}}r(nf,"useCopyAction");function nK(){const e=Nc()?.pushToast;return(0,m.useCallback)(async(s,n="Copied")=>{try{return await Gr(s),e?.({title:n,tone:"success",dedupeKey:`copy:${n}`}),!0}catch{return e?.({title:"Couldn’t copy to clipboard",body:"Select and copy the value manually.",tone:"error",dedupeKey:"copy-failed"}),!1}},[e])}r(nK,"useCopyToast");var DQe="/cloud/connections/handoff",LQe="/cloud/connections/reauth",AT="paperclip.cloud-oauth-handoff.v1",dx=class extends Error{static{r(this,"OAuthHandoffError")}code;constructor(e,s){super(e),this.code=s,this.name="OAuthHandoffError"}};function rK(e){if(e===void 0)return null;if(!e||typeof e!="object"||Array.isArray(e))throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");const s=e;if(s.kind!=="paperclip_cloud"||typeof s.session!="string"||s.session.length<16||s.session.length>512||!/^[A-Za-z0-9_-]+$/.test(s.session))throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");return{kind:"paperclip_cloud",session:s.session}}r(rK,"parseHandoff");function $Qe(e,s){return e===404||s==="SESSION_NOT_AVAILABLE"?new dx("This sign-in expired. Start the connection again.","expired"):e===401||e===403?new dx("Paperclip Cloud could not authorize this connection for your account.","forbidden"):new dx("Paperclip Cloud couldn’t prepare secure sign-in. Try again.","unavailable")}r($Qe,"handoffFailure");async function OQe(e,s){const n=s.request??fetch;let a,i;for(let o=0;o<2;o+=1)try{if(a=await n(DQe,{method:"POST",headers:{"content-type":"application/json",accept:"application/json"},credentials:"include",body:JSON.stringify({session:e}),signal:s.signal}),a.status<500||o===1)return a}catch(l){if(s.signal?.aborted||l instanceof DOMException&&l.name==="AbortError")throw l;if(i=l,o===1)break}if(a)return a;throw new dx(i instanceof Error?i.message:"Paperclip Cloud couldn’t prepare secure sign-in. Try again.","unavailable")}r(OQe,"postCloudHandoff");function FQe(e,s){if(typeof e!="string"||typeof window>"u")return null;try{const n=new URL(e,window.location.origin);return n.origin!==window.location.origin||n.pathname!==LQe||n.username||n.password||n.hash||n.searchParams.size!==1||n.searchParams.get("session")!==s?null:{kind:"reauthentication",url:n.toString(),host:n.host}}catch{return null}}r(FQe,"exactReauthenticationTarget");async function uw(e,s={}){const n=rK(e.handoff);if(!n){const l=iT(e.authorizationUrl);if(!l.ok)throw new dx(l.message,"invalid_handoff");return{kind:"authorization",url:l.url,host:l.host}}const a=await OQe(n.session,s),i=await a.json().catch(()=>null);if(!a.ok){if(i?.error==="RECENT_LOGIN_REQUIRED"){const l=FQe(i.reauthenticationUrl,n.session);if(l)return l}throw $Qe(a.status,i?.error)}const o=iT(typeof i?.authorizationUrl=="string"?i.authorizationUrl:void 0);if(!o.ok)throw new dx("Paperclip Cloud returned an invalid provider sign-in address.","invalid_handoff");return{kind:"authorization",url:o.url,host:o.host}}r(uw,"prepareOAuthNavigation");function lC(e,s=window.sessionStorage){const n=rK({kind:"paperclip_cloud",session:e});if(!n)throw new dx("Paperclip Cloud returned an invalid sign-in handoff.","invalid_handoff");const a={version:1,session:n.session,savedAt:Date.now()};s.setItem(AT,JSON.stringify(a))}r(lC,"savePendingCloudHandoff");function BQe(e=window.sessionStorage){const s=e.getItem(AT);if(!s)return null;try{const n=JSON.parse(s);if(n.version!==1||typeof n.savedAt!="number"||Date.now()-n.savedAt>9e5)throw new Error("expired");return rK({kind:"paperclip_cloud",session:n.session})}catch{return e.removeItem(AT),null}}r(BQe,"readPendingCloudHandoff");function WY(e=window.sessionStorage){e.removeItem(AT)}r(WY,"clearPendingCloudHandoff");function Y5({host:e,className:s}){return(0,t.jsxs)("div",{className:U("flex flex-wrap items-center gap-2 text-xs",s),children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 font-medium text-amber-700 dark:text-amber-400",children:[(0,t.jsx)(wl,{className:"h-3 w-3"}),"Unverified server"]}),e?(0,t.jsx)("span",{className:"font-mono text-muted-foreground",children:e}):null]})}r(Y5,"UnverifiedServerBadge");function J5(e){return!!(e&&Yoe({...e,methods:e.methods.filter(s=>(s.purpose??"tool")!=="channel"&&s.transport!=="chat_sdk")}))}r(J5,"appSupportsToolCatalogSetup");var qQe=F_e.filter(e=>Uoe(e).some(s=>Ep(s))).map(e=>e.slug);function zQe(e){return qQe.some(s=>s===e)}r(zQe,"isMcpDirectOAuthConnectSlug");function IF(e,s){const n=new URLSearchParams({source:e});return s&&n.set("intent",s),`/apps/connect?${n.toString()}`}r(IF,"appSourceConnectHref");function UQe(e,s){return`/apps/connect?${new URLSearchParams({source:e,resume:s}).toString()}`}r(UQe,"appSourceResumeHref");function T4(e){return e?`/apps/vercel-connect?${new URLSearchParams({source:e}).toString()}`:"/apps/vercel-connect"}r(T4,"vercelConnectSourceHref");function KQe(e){return e.serviceSlug??e.appKey??e.sourceSlug??void 0}r(KQe,"resolveAppsConnectRouteKey");function VQe(e,{chatConnectorsEnabled:s=!1}={}){if(e.get("byo")==="1")return!!(e.get("reconnect")?.trim()&&e.get("applicationId")?.trim()&&e.get("link")?.trim());const n=e.get("source")??"",a=VC(n);return!s&&a?.methods.some(i=>i.transport==="chat_sdk")&&!a.methods.some(i=>(i.purpose??"tool")!=="channel"&&i.transport!=="chat_sdk")?!1:V6(n)&&e.get("reconnect")?.trim()?!0:s?Yoe(a):J5(a)}r(VQe,"canEnterAppsConnect");var E4=" for the organization",WQe=" for the company";function HY(e,s){const n=e.trim();if(s!=="organization")return n;const a=n.toLocaleLowerCase();return a.endsWith(E4)?n:a.endsWith(WQe)?`${n.slice(0,n.length-16).trimEnd()}${E4}`:`${n}${E4}`}r(HY,"connectionNameForGrantKind");function HQe(e){switch(e){case"active":return"Connected";case"needs_reauthorization":return"Needs attention";case"expired":return"Expired";case"revoked":return"Revoked";default:return"Not connected"}}r(HQe,"grantStatusLabel");function QQe(e){switch(e){case"active":return"connected";case"needs_reauthorization":case"expired":return"attention";case"revoked":return"inactive";default:return"missing"}}r(QQe,"grantStatusTone");function GQe(e,s={}){const n=e?.providerTenant?.name?.trim();return n||(e?.kind==="user"?s.subjectLabel?.trim()||"Connected account":e?.kind==="agent"?s.subjectLabel?.trim()||"Dedicated account":"Shared credential")}r(GQe,"grantAccountLabel");function YQe(e){return new Set((e?.members??[]).filter(s=>s.subjectType==="user").map(s=>s.subjectId))}r(YQe,"audienceUserIds");function JQe(e){return e.find(s=>s.kind==="organization"&&s.isDefault)??e.find(s=>s.kind==="organization")??null}r(JQe,"organizationGrant");function XQe(e,s){return s?e.find(n=>n.kind==="user"&&n.subjectUserId===s)??null:null}r(XQe,"personalGrantFor");function ZQe(e,s){if(!s)return null;const n=e.find(a=>a.userId===s);return n&&(n.name?.trim()||n.email?.trim())||null}r(ZQe,"memberLabel");var QY=0;function AF(){return QY+=1,{id:`header-${QY}`,name:"",value:""}}r(AF,"newCustomHeaderRow");function fS(e){try{return new URL(e).host||null}catch{return null}}r(fS,"endpointHost");function eGe(e=window.location.origin){const s=new URL("/api/tools/oauth/callback",e),n=s.hostname.toLowerCase().replace(/^\[|\]$/g,"");return s.protocol==="http:"&&(n==="127.0.0.1"||n==="::1")&&(s.hostname="localhost"),s.toString()}r(eGe,"oauthCallbackUrlForBrowser");function P4(e){try{const s=new URL(e);return`${s.host.replace(/^www\./,"")}${s.pathname==="/"?"":s.pathname.replace(/\/+$/,"")}`.slice(0,160)||null}catch{return null}}r(P4,"defaultGenericMcpName");function GY(e,s){const n=s?.trim()||"Paperclip couldn't connect to that address. Check it and try again.";switch(e){case"mcp_remote_url_missing":case"mcp_remote_url_invalid":return{title:"That doesn't look like a server address",body:"Paste the full address, starting with https:// — for example https://mcp.example.com/mcp.",focus:"url"};case"remote_http_private_endpoint":return{title:"That address is inside a private network",body:"This Paperclip is reachable from the internet, so it won't call addresses on your local network. Use the server's public address instead.",focus:"url"};case"remote_http_dns_failed":return{title:"We couldn't find that host",body:"The address didn't resolve. Check the spelling, or confirm the server is published on the internet.",focus:"url"};case"mcp_header_rejected":return{title:"Paperclip can't send that header",body:n,focus:"credentials"};case"tool_access_name_conflict":return{title:"Paperclip couldn’t name this connection",body:"Try connecting again.",focus:"none"};case"oauth_challenge":return{title:"This server wants a credential",body:"It asked us to authenticate but didn't offer a sign-in Paperclip can complete on its own. Add the key or headers its docs list under Advanced authentication.",focus:"credentials"};case"oauth_manual_client_required":case"oauth_manual_client_rebinding_required":return{title:"This server needs sign-in details you create yourself",body:"Register Paperclip in the provider's settings, then add the client ID and secret it gives you under Advanced authentication.",focus:"credentials"};case"oauth_redirect_origin_unsupported":case"oauth_redirect_uri_invalid":return{title:"This Paperclip needs a public HTTPS address first",body:"Sign-in sends the operator back to Paperclip, so this instance has to be reachable over HTTPS. Ask your Paperclip admin to configure it.",focus:"deployment"};case"runtime_error":return{title:"We couldn't reach that server",body:"Nothing answered at that address. Confirm the server is running and the address is right, then try again.",focus:"url"};default:return{title:"Paperclip couldn't connect",body:n,focus:"none"}}}r(GY,"genericConnectGuidance");function rxe(e){const s=new Set;for(const n of e){const a=n.name.trim();if(!a&&!n.value.trim())continue;const i=y_e(a);if(!i.ok)return TW(a,i.reason);const o=E_e(n.value);if(!o.ok)return TW(a,o.reason);if(!n.value.trim())return`Add a value for "${a}", or remove the row.`;const l=a.toLowerCase();if(s.has(l))return`"${a}" is listed twice.`;s.add(l)}return null}r(rxe,"customHeaderError");function tGe(e){const s={},n=e.keyValue.trim();if((e.authMode==="bearer"||e.authMode==="auto"&&e.needsKey)&&n&&(s["credentials.authorization"]=n),e.authMode==="custom_headers")for(const l of e.headers){const c=l.name.trim();!c||!l.value.trim()||(s[`headers.${c}`]=l.value)}const a=e.name.trim(),i=e.oauthClientId.trim(),o=e.oauthClientSecret.trim();return{link:e.link,...a?{name:a}:{},...e.authMode==="auto"?{}:{authMode:e.authMode},...Object.keys(s).length>0?{credentialValues:s}:{},...e.authMode==="oauth"&&i?{oauthClient:{clientId:i,...o?{clientSecret:o}:{}}}:{}}}r(tGe,"genericConnectPayload");function sGe(e){return e.link.trim()?e.authMode==="auto"?!e.needsKey||e.keyValue.trim().length>0:e.authMode==="bearer"?e.keyValue.trim().length>0:e.authMode==="custom_headers"?e.headers.filter(s=>s.name.trim()&&s.value.trim()).length>0&&rxe(e.headers)===null:!0:!1}r(sGe,"canSubmitGenericConnect");function mw(e){const s=new Set;let n=!1;for(const a of e??[])a.targetType==="company"?n=!0:a.targetType==="agent"&&s.add(a.targetId);return{onAll:n,agentIds:s}}r(mw,"installStateFrom");function axe(e,s){return e.onAll||e.agentIds.has(s)}r(axe,"isAgentInstalled");function ixe(e,s){return s.onAll?[{targetType:"company",targetId:e}]:[...s.agentIds].map(n=>({targetType:"agent",targetId:n}))}r(ixe,"installPayload");var nGe="Has access — tick to load its tools into this agent's context.";function oxe(e){return`paperclip.connector-enrollment-access:${e}`}r(oxe,"enrollmentAccessStorageKey");function rGe(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const s=e;if(typeof s.companyId!="string"||!s.companyId.trim()||!(s.grantKind==="user"||s.grantKind==="agent"||s.grantKind==="organization")||s.installChoice!=="specific"&&s.installChoice!=="all"||!Array.isArray(s.agentIds)||s.agentIds.some(a=>typeof a!="string"||!a.trim()))return!1;const n=new Set(s.agentIds);return n.size!==s.agentIds.length?!1:s.grantKind==="agent"?s.installChoice==="specific"&&n.size===1:s.installChoice==="all"?n.size===0:n.size>0}r(rGe,"validEnrollmentAccessState");function aGe(e,s,n){try{window.sessionStorage.setItem(oxe(s),JSON.stringify({...n,companyId:e}))}catch{}}r(aGe,"saveEnrollmentAccessState");function iGe(e){const s=oxe(e);try{const n=window.sessionStorage.getItem(s);if(window.sessionStorage.removeItem(s),!n)return null;const a=JSON.parse(n);return rGe(a)?a:null}catch{return null}}r(iGe,"consumeEnrollmentAccessState");function YY(e){if(!e)return null;try{const s=new URL(e);return s.protocol==="https:"&&s.hostname.toLowerCase()==="github.com"?s.toString():null}catch{return null}}r(YY,"githubRecoveryUrl");function JY(e,s){return e==="denied"?"Authorization was cancelled or declined. Your saved connection was not changed.":s==="github_installation_required"?"GitHub access is required. Install Paperclip and grant at least one repository, then try again.":"Authorization did not complete. Your saved connection is still here, so you can try again."}r(JY,"oauthCallbackErrorMessage");var oGe={access:"access",key:"setup",success:"complete"};function XY(e){return e.requestedAppKey?e.resumeConnectionId||e.routeStage==="setup"?"key":"access":e.hasPrefilledLink||e.zapierSource?"access":"gallery"}r(XY,"requestedConnectionInitialStep");function lGe(e){const s=e.galleryApps.find(a=>a.slug===e.requestedAppKey);if(s)return s;if(!e.reconnectConnection)return null;const n=e.applications.find(a=>a.id===e.reconnectConnection?.applicationId);return yx(n)!==e.requestedAppKey?null:V6(e.requestedAppKey)}r(lGe,"requestedConnectionEntry");function cGe(e){return!e.reconnectConnection||!e.reconnectApplication||e.reconnectConnection.applicationId!==e.reconnectApplication.id?!1:e.requestedAppKey?yx(e.reconnectApplication)===e.requestedAppKey:e.byo&&e.applicationId===e.reconnectApplication.id}r(cGe,"retainedReconnectMatches");function dGe(e){return e.credentialSource==="vercel_connect"&&!e.available&&!e.retainedReconnectMatches}r(dGe,"isVercelConnectUnavailable");function uGe(e){return e.available===!1&&!(e.reconnectConnectionId&&e.reconnectSourceMatches)}r(uGe,"isConnectionDefinitionUnavailable");function mGe(e){return!e.hasRequestedEntry||e.supportedMethodCount===0||e.unsupportedOAuth||e.vercelUnavailable||e.definitionUnavailable?e.reconnectConnectionId?"reconnect_unavailable":"fallback":"ready"}r(mGe,"requestedConnectionSetupResolution");function ZY(e,s,n,a){const i=oGe[s]??"setup",o=new URLSearchParams({source:e,stage:i});return a?.resumeConnectionId&&o.set("resume",a.resumeConnectionId),a?.reconnectConnectionId&&o.set("reconnect",a.reconnectConnectionId),a?.interactionId&&o.set("intent",a.interactionId),a?.connectionMethodKey&&o.set("method",a.connectionMethodKey),`${n==="vercel_connect"?"/apps/vercel-connect":"/apps/connect"}?${o.toString()}`}r(ZY,"appConnectHref");function cI(e,s){if(!s)return e;const[n,a=""]=e.split("?",2),i=new URLSearchParams(a);return i.set("intent",s),`${n}?${i.toString()}`}r(cI,"withConnectionIntent");var eJ=["Pick app","Access","Add your key"],tJ={gallery:0,access:1,key:2},hGe={access:0,key:1},pGe=["Access","Add MCP URL"],fGe=["Access","Sign in"];function M4(e,s=!1){return s&&e?.auth!=="none"&&(!e?.grantKinds||e.grantKinds.includes("user"))?"user":e?.grantKinds?.length===1||e?.grantKinds&&!e.grantKinds.includes("organization")?e.grantKinds[0]:"organization"}r(M4,"defaultGrantKindFor");function xGe(e){const s=e.config?.oauth;if(!s||typeof s!="object"||Array.isArray(s))return;const n=s.connectorSubjectAgentId;return typeof n=="string"?n:void 0}r(xGe,"configuredAgentIdentity");function Tk(e,s){const n=typeof s=="string"?s:s?.key;return e?.slug==="google-sheets"&&n==="local"}r(Tk,"isGoogleSheetsRobotMethod");function GN(e){return e?Object.fromEntries([...e.tenantFields??[],...e.extensionFields??[]].filter(s=>s.defaultValue!==void 0).map(s=>[s.key,s.defaultValue])):{}}r(GN,"defaultMethodConfig");function qy(e,s){if(!e)return[];const n=R1(e);return s==="vercel_connect"?n.filter(a=>!!a.credentialSources?.vercelConnect):n}r(qy,"connectionMethodsForCredentialSource");function R1(e){return Uoe(e).filter(s=>(s.purpose??"tool")!=="channel")}r(R1,"availableToolConnectionMethods");function dI(e,s){const n=R1(e);return s?n.find(a=>a.key===s)??null:H6(n)}r(dI,"availableToolConnectionMethod");function Sj(e){const s=H6(e);return e.length===1||s?.capabilityProfile||s?.grantKinds?.includes("agent")?s:null}r(Sj,"recommendedSetupConnectionMethod");function sJ(e){return Sj(e?e.methods.filter(s=>(s.purpose??"tool")==="tool"&&(s.oauthStrategy==="paperclip_cloud_connector"||s.oauthStrategy==="paperclip_id_connector")):[])}r(sJ,"recommendedManagedConnectorMethod");function nJ(e){if(!e)return!1;const s=R1(e),n=s.length===1?s[0]:null;return!!(n&&Ep(n)&&!cIe(n))}r(nJ,"canUseAutomaticOAuthFastPath");function rJ(e){if(!e)return null;const s=R1(e),n=s.length===1?s[0]:null;return n&&Ep(n)?n:null}r(rJ,"automaticOAuthMethod");function gGe(e){const s=e.metadata;if(!s)return null;const n=s.sourceTemplateKey??s.galleryKey;return typeof n=="string"?n:null}r(gGe,"appSourceSlug");function bGe(e){const s=e.config?.sourceTemplateKey??e.transportConfig.sourceTemplateKey;return typeof s=="string"?s:null}r(bGe,"connectionSourceSlug");function aJ(e,s,n,a={}){if(!e)return null;const i=new Set(s.filter(o=>o.status!=="archived"&&gGe(o)===e&&(!a.applicationId||o.id===a.applicationId)).map(o=>o.id));return n.find(o=>{const l=a.applicationId?o.applicationId===a.applicationId:i.has(o.applicationId)||bGe(o)===e;return o.status!=="archived"&&(!a.draftOnly||o.status==="draft")&&o.authKind==="oauth"&&l})??null}r(aJ,"reusableOAuthConnection");function lxe(e,s,n){if(e.origin!==s||!e.data||typeof e.data!="object")return null;const a=e.data;return a.type!=="paperclip.connection-intent.oauth"||a.interactionId!==n?null:a.outcome==="connected"||a.outcome==="declined"||a.outcome==="failed"?a.outcome:null}r(lxe,"readConnectionIntentOAuthOutcome");function X5(e={}){const[s]=Ri(),n=ja(),{selectedCompanyId:a}=fs(),i=she(),o=e.interactionId||s.get("intent")||void 0,l=e.serviceSlug||s.get("source")||n.appKey||s.get("appKey"),c=(0,m.useMemo)(()=>{if(o&&uj(l))try{return sessionStorage.getItem(`paperclip:mcp-intent-draft:${a}:${o}`)}catch{}return null},[o,a,l]),d=e.configuredConnection?.id||s.get("resume")||s.get("reconnect")||c,u=!!(d&&(!l||uj(l))),h=ee({queryKey:["tools","connection",d],queryFn:r(()=>us.getConnection(d),"queryFn"),enabled:u}),p=l||h.data?.config?.sourceTemplateKey,x=s.get("method")||h.data?.config?.connectionMethodKey;return u&&h.isPending?(0,t.jsx)("p",{className:"p-6 text-sm text-muted-foreground",children:"Loading connection…"}):u&&h.isError?(0,t.jsxs)("div",{role:"alert",className:"space-y-3 p-6",children:[(0,t.jsx)("p",{children:"Could not load this connection. Your saved access and credentials have not changed."}),(0,t.jsx)(F,{variant:"outline",onClick:r(()=>{h.refetch()},"onClick"),children:"Try again"})]}):!e.byoOnly&&(e.credentialSource??"paperclip_vault")==="paperclip_vault"&&uj(p)&&(!x||JA(p,x))?i.loaded?i.enabled?(0,t.jsx)(Nqe,{...e,interactionId:o,providerId:p,connection:h.data},`${o||"page"}:${p}`):(0,t.jsx)("p",{role:"status",className:"p-6 text-sm text-muted-foreground",children:"Enable MCP aggregators in Settings → Experimental to set up this connection."}):(0,t.jsx)("p",{className:"p-6 text-sm text-muted-foreground",children:"Loading connection settings…"}):(0,t.jsx)(vGe,{...e})}r(X5,"ConnectionSetupFlow");function vGe({byoOnly:e=!1,credentialSource:s="paperclip_vault",host:n="page",serviceSlug:a,requestedAgentId:i,interactionId:o,forceNewConnection:l=!1,existingConnections:c=[],configuredConnection:d,onUseExisting:u,onComplete:h,onOAuthDeclined:p,aiConnection:x,onPhaseChange:g,onCancel:v,renderCredentialStep:y}={}){const j=Wn(),S=(0,m.useCallback)((Fe,Lt)=>{n==="page"&&(Lt?j(Fe,Lt):j(Fe))},[n,j]),w=ja(),{selectedCompany:N,selectedCompanyId:_}=fs(),{enabled:I}=Tx(),{setBreadcrumbs:C}=$n(),{pushToast:A}=Mi(),[R]=Ri(),E=o?.trim()||R.get("intent")?.trim()||null,O=w.appKey??R.get("appKey")??void 0,L=R.get("source")?.trim()||null,$=l||R.get("new")==="1",T=R.get("stage")?.trim()||null,q=R.get("method")?.trim()||null,B=R.get("resume")?.trim()||null,K=R.get("oauth"),z=R.get("code"),D=YY(R.get("installation_url")),V=YY(R.get("management_url")),H=d?.id??(R.get("reconnect")?.trim()||null),Z=R.get("identity")==="user"?"user":R.get("identity")==="organization"?"organization":null,Y=s==="vercel_connect",ie=a??L,se=s==="paperclip_vault"&&zQe(ie)?ie:null,X=KQe({serviceSlug:a,appKey:O,sourceSlug:L}),le=(a??L??O)==="zapier",oe=le?void 0:X,te=!!d||n==="page"&&(e||R.get("byo")==="1"),[J]=(0,m.useState)(()=>n==="page"&&R.get("cloud_connector")==="enrolled"&&oe?iGe(oe):null),[Q]=(0,m.useState)(()=>{const Fe=R.get("link")?.trim()??"";return{link:/^https?:\/\//i.test(Fe)?Fe:"",name:d?.name??R.get("name")?.trim()??"",applicationId:d?.applicationId??(R.get("applicationId")?.trim()||void 0)}}),[pe,re]=(0,m.useState)(()=>XY({requestedAppKey:oe,routeStage:T,resumeConnectionId:B,hasPrefilledLink:!!Q.link,zapierSource:le})),[ne,ae]=(0,m.useState)(null),[me,he]=(0,m.useState)(""),[Ie,de]=(0,m.useState)(Q.link),[ve,Te]=(0,m.useState)(Q.name||(le?"Zapier":"")),[fe,Ce]=(0,m.useState)(!1),[Xe,Oe]=(0,m.useState)(""),[tt,ce]=(0,m.useState)("auto"),[$e,mt]=(0,m.useState)(()=>[AF()]),[it,Ke]=(0,m.useState)(""),[Ge,rt]=(0,m.useState)(""),[jt,st]=(0,m.useState)(!1),[Nt,at]=(0,m.useState)(null),[Ee,Ne]=(0,m.useState)(!1),[He,St]=(0,m.useState)({}),[Ft,ts]=(0,m.useState)(""),[Ot,Be]=(0,m.useState)(""),[Ve,ut]=(0,m.useState)(""),[qe,Gt]=(0,m.useState)(x&&x.mode!=="responsible_user"?`ai-${x.method}`:""),[We,$t]=(0,m.useState)({}),[Dt,Cs]=(0,m.useState)(""),[ze,ct]=(0,m.useState)(null),[Pt,ke]=(0,m.useState)(null),[ys,wt]=(0,m.useState)({}),[Ut,De]=(0,m.useState)("all"),[Se,nt]=(0,m.useState)(new Set),[xt,ms]=(0,m.useState)(()=>new Set(J?.agentIds??(i?[i]:[]))),[ht,zt]=(0,m.useState)(J?.grantKind??Z??(i?"user":"organization")),[as,Me]=(0,m.useState)(J?.installChoice??(i?"specific":"all")),bt=!!(B&&(K==="failed"||K==="denied")),[ft,Ye]=(0,m.useState)(bt?"error":"entry"),[gs,Ct]=(0,m.useState)(()=>bt?JY(K,z):null),[os,_t]=(0,m.useState)(null),Xt=(0,m.useRef)(!1),zs=(0,m.useRef)(!1),hs=(0,m.useRef)(null),[Ws,Cn]=(0,m.useState)(null),Zn=(0,m.useRef)(null),[kn,tn]=(0,m.useState)(null),[Tn,Bs]=(0,m.useState)(null),an=(0,m.useRef)(null),[ca,Sr]=(0,m.useState)(c.length>0&&!!u),[gn,rr]=(0,m.useState)(null),[wr,ar]=(0,m.useState)(null),[sa,_r]=(0,m.useState)(null),Cr=(0,m.useCallback)(()=>{n!=="dialog"||Zn.current?.closed===!1||(Zn.current=window.open("about:blank","paperclip-connection-oauth","popup,width=720,height=760,resizable=yes,scrollbars=yes"))},[n]),Wr=(0,m.useCallback)(Fe=>{if(n!=="dialog"){jc(Fe);return}Bs(Fe);const Lt=Zn.current;if(!Lt||Lt.closed){Ye("error"),Ct("Paperclip couldn’t open the sign-in window. Open sign-in in a new tab to continue."),g?.("needs_retry");return}Lt.location.assign(Fe),Lt.focus()},[n,g]),Yn=(0,m.useCallback)(()=>{Zn.current=null,Ct(null),Ye("redirecting"),g?.("authorizing")},[g]);(0,m.useEffect)(()=>{if(n!=="dialog"||ft!=="redirecting")return;const Fe=window.setInterval(()=>{Zn.current?.closed&&(Ye("error"),Ct("The sign-in window closed. If authorization did not finish, try again."),Bs(null),g?.("needs_retry"))},1e3);return()=>window.clearInterval(Fe)},[n,ft,g]);const ir=(0,m.useCallback)(async Fe=>{an.current?.abort();const Lt=new AbortController;an.current=Lt;try{const Ts=await uw(Fe,{signal:Lt.signal});if(Ts.kind==="reauthentication"){const _n=n==="dialog"?Zn.current:window;if(!_n||_n.closed||!Fe.handoff)throw new Error("Paperclip couldn’t preserve this sign-in while refreshing your account.");lC(Fe.handoff.session,_n.sessionStorage),Ye("starting")}else _t(Ts.host),Ye("redirecting");Wr(Ts.url)}catch(Ts){if(Lt.signal.aborted)return;Ye("error"),Ct(Ts instanceof Error?Ts.message:"Paperclip couldn’t start secure sign-in. Try again."),g?.("needs_retry")}finally{an.current===Lt&&(an.current=null)}},[n,g,Wr]);(0,m.useEffect)(()=>()=>an.current?.abort(),[]),(0,m.useEffect)(()=>{if(n!=="dialog"||!E)return;const Fe=r(Lt=>{const Ts=lxe(Lt,window.location.origin,E);if(Ts==="connected"){Ye("entry"),Bs(null),h?.({resolvedByCallback:!0});return}if(Ts==="declined"){Ye("error"),Ct("Authorization was cancelled. You can try again."),g?.("needs_retry");return}Ts==="failed"&&(Ye("error"),Ct("Authorization did not complete. Try again when you’re ready."))},"receiveOAuthOutcome");return window.addEventListener("message",Fe),()=>window.removeEventListener("message",Fe)},[E,n,h,p]),(0,m.useEffect)(()=>{if(n!=="dialog"||E||!kn)return;let Fe=!1,Lt=!1;const Ts=window.setInterval(async()=>{if(Lt||Fe)return;const _n=Zn.current;if(!_n||_n.closed){tn(null),Ye("error"),Ct("The sign-in window closed. Try again to finish connecting GitHub.");return}let Hr;try{Hr=new URL(_n.location.href)}catch{return}if(!(Hr.origin!==window.location.origin||!Hr.pathname.includes(kn))){if(Hr.searchParams.has("oauth")){tn(null),Ye("error"),Ct("Authorization did not complete. Finish setup in the sign-in window or try again.");return}if(Hr.searchParams.get("success")==="1"){Lt=!0;try{const Fa=await us.getConnection(kn);!Fe&&Fa.status==="active"&&(tn(null),_n.close(),h?.({connectionId:Fa.id}))}catch{Fe||(tn(null),Ye("error"),Ct("Could not confirm the connection. Try again."))}finally{Lt=!1}}}},1e3);return()=>{Fe=!0,window.clearInterval(Ts)}},[E,kn,n,h]);const Ir=r(()=>{ce("auto"),mt([AF()]),Ke(""),rt(""),st(!1),at(null),Ne(!1)},"resetGenericAuthState"),dr=r(Fe=>{if(n==="page"&&!E&&s==="paperclip_vault"&&uj(Fe.slug)){S(`/apps/connect?source=${Fe.slug}`);return}if(Fe.slug==="zapier"){ae(null),he(""),de(""),Te("Zapier"),Ce(!1),Oe(""),Ir(),St({}),ke(null),re("access"),S(cI("/apps/connect?source=zapier",E));return}if(s==="paperclip_vault"&&nJ(Fe)){S(IF(Fe.slug,E));return}ae(Fe),he(Fe.name),de(""),Te(""),Ce(!1),Oe(""),Ir(),St({}),ts(""),Be(""),ut("");const Lt=Sj(qy(Fe,s));Gt(Lt?.key??""),$t(GN(Lt)),Cs(""),ct(null),ke(null),ms(new Set(i?[i]:[])),Me(i?"specific":"all"),zt($s??M4(Lt,!!i)),re("access"),S(s==="vercel_connect"?cI(T4(Fe.slug),E):IF(Fe.slug,E))},"useMatchedGalleryEntry"),da=r(()=>{re("gallery"),S(cI(s==="vercel_connect"?T4():e?"/apps/byo":"/apps",E))},"backToGallery");(0,m.useEffect)(()=>{if(n==="page")return C([{label:"Connectors",href:"/apps"},{label:Y?"Vercel Connect":e?"Connect your own tool":"Connect an app"}]),()=>C([])},[e,n,C,Y]);const Ls=ee({queryKey:P.apps.gallery(_??"__none__"),queryFn:r(()=>us.listGallery(_),"queryFn"),select:(0,m.useCallback)(Fe=>E?{...Fe,apps:Fe.apps.map(Lt=>({...Lt,methods:Lt.methods.filter(Ts=>x?Ts.ai?.provider===x.provider&&(x.mode==="responsible_user"||Ts.ai.method===x.method):Ts.transport!=="runtime_auth")})).filter(Lt=>Lt.methods.length>0)}:Fe,[E,x?.provider,x?.method,x?.mode]),enabled:!!_}),Hn=(0,m.useMemo)(()=>(Ls.data?.apps??[]).filter(Fe=>I||!Fe.methods.some(Lt=>Lt.transport==="chat_sdk")||J5(Fe)),[Ls.data,I]),ur=oe?V6(oe):null,gr=!!ur?.methods.some(Fe=>Fe.oauthStrategy==="paperclip_cloud_connector"||Fe.oauthStrategy==="paperclip_id_connector"),gt=!!ne?.methods.some(Fe=>Fe.oauthStrategy==="paperclip_cloud_connector"||Fe.oauthStrategy==="paperclip_id_connector"),ks=ne&&gr&&!gt?sJ(ur):null,[Es,Je]=(0,m.useState)(null),qt=ee({queryKey:["cloud-connector","enrollment"],queryFn:r(()=>us.getCloudConnectorEnrollment(),"queryFn"),refetchInterval:Es?2e3:!1,enabled:!!(_&&gr&&!gt)}),[Hs,Ks]=(0,m.useState)(null),Ys=(0,m.useCallback)(()=>{Zn.current?.close(),Zn.current=null,Je(null)},[]),Ar=(0,m.useCallback)(()=>{!_||!oe||aGe(_,oe,{grantKind:ht,installChoice:as,agentIds:as==="specific"?[...xt]:[]})},[ht,xt,as,oe,_]),Ps=(0,m.useCallback)(Fe=>{const Lt=iT(Fe);if(!Lt.ok){Ys(),Ks(Lt.message);return}if(n==="dialog"){Je(Lt.url);const Ts=Zn.current;Ts&&!Ts.closed?(Ts.location.assign(Lt.url),Ts.focus()):Ks("Open authorization in a new tab to continue.");return}jc(Lt.url)},[n,Ys]);(0,m.useEffect)(()=>{!Es||qt.data?.status!=="active"||(Ys(),Ks(null),Ls.refetch())},[Es,qt.data?.status,Ls.refetch,Ys]);const on=ye({mutationFn:r(()=>us.startCloudConnectorEnrollment(_,N?.name,oe?ZY(oe,"key",s,{resumeConnectionId:B,reconnectConnectionId:H,interactionId:E})+(n==="dialog"?"&enrollment_host=dialog":""):void 0),"mutationFn"),onSuccess:r(Fe=>{if(!Fe.verificationUrl){Ys(),Ks("Paperclip Cloud did not return an enrollment link. Try again.");return}Ps(Fe.verificationUrl)},"onSuccess"),onError:r(Fe=>{Ys(),Ks(Fe instanceof Error?Fe.message:"Paperclip couldn’t reach Paperclip Cloud. Try again.")},"onError")}),jn=ee({queryKey:P.tools.applications(_??"__none__"),queryFn:r(()=>us.listApplications(_),"queryFn"),enabled:!!_&&(!!se||!!B||!!H),refetchOnMount:"always"}),Ms=ee({queryKey:P.tools.connections(_??"__none__"),queryFn:r(()=>us.listConnections(_),"queryFn"),enabled:!!_&&(!!se||!!B||!!H),refetchOnMount:"always"}),nn=(0,m.useMemo)(()=>l?null:aJ(se,jn.data?.applications??[],Ms.data?.connections??[],$?{applicationId:Q.applicationId,draftOnly:!0}:{}),[jn.data,Ms.data,$,se,Q.applicationId,l]),wn=(0,m.useMemo)(()=>H?(Ms.data?.connections??[]).find(Fe=>Fe.id===H)??null:null,[Ms.data,H]),bs=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(!d||!Ms.isFetchedAfterMount||!wn||bs.current===wn.id)return;const Fe=wn.config?.url??wn.transportConfig?.url??wn.transportConfig?.serverUrl??wn.config?.serverUrl;typeof Fe!="string"||!/^https?:\/\//i.test(Fe)||(bs.current=wn.id,de(Lt=>Lt||Fe))},[d,Ms.isFetchedAfterMount,wn]);const Js=(0,m.useMemo)(()=>wn?(jn.data?.applications??[]).find(Fe=>Fe.id===wn.applicationId)??null:null,[jn.data,wn]),Vn=cGe({requestedAppKey:oe,byo:te,applicationId:Q.applicationId,reconnectConnection:wn,reconnectApplication:Js}),Ln=(0,m.useMemo)(()=>B?(Ms.data?.connections??[]).find(Fe=>Fe.id===B)??null:null,[Ms.data,B]),rs=Ln??wn,$s=rs?rs.credentialPolicy==="per_user"?"user":rs.credentialPolicy==="per_agent"?"agent":"organization":Z,Jn=Ln?.authKind==="oauth"?Ln:nn,En=nn?nn.credentialPolicy==="per_user"?"user":nn.credentialPolicy==="per_agent"?"agent":"organization":null,bn=$s??En;(0,m.useEffect)(()=>{bn&&zt(bn)},[bn]);const On=(0,m.useMemo)(()=>Ie&&!ne?jR(Ie,Hn):null,[ne,Hn,Ie]),Qn=ne?dI(ne,qe||null):null,Fr=Qn&&Ep(Qn)?Qn:rJ(ne),Ta=s==="paperclip_vault"&&Fr?ne:null,Br=s==="paperclip_vault"&&nJ(ne)?ne:null,ii=!!se&&(!jn.isFetchedAfterMount||!Ms.isFetchedAfterMount),be=r(Fe=>{re(Fe),ne&&S(ZY(ne.slug,Fe,s,{connectionMethodKey:ne.methods.find(Lt=>Lt.key===qe)?.ai?qe:void 0,resumeConnectionId:B,reconnectConnectionId:H,interactionId:E}))},"setAppStep"),je=ye({mutationFn:r(Fe=>us.startOAuth(Fe.id,{asCurrentUser:Fe.credentialPolicy==="per_user",...Fe.credentialPolicy==="per_agent"?{asAgentId:xGe(Fe)??[...xt][0]}:{},...E?{interactionId:E}:{}}),"mutationFn"),onSuccess:r(Fe=>{ir(Fe)},"onSuccess"),onError:r(Fe=>{const Lt=Fe instanceof Nn&&Fe.body&&typeof Fe.body=="object"?Fe.body.details:null;Ye("error"),g?.("needs_retry"),Ct(Lt?.code==="invalid_grant"?"Your authorization expired or was revoked. Reconnect to continue.":Fe instanceof Error?Fe.message:"Paperclip couldn’t start secure sign-in. Try again.")},"onError")}),kt=je.mutate,ws=(0,m.useCallback)(Fe=>{g?.("authorizing"),Cr(),n==="dialog"&&!E&&tn(Fe.id),kt(Fe)},[kt,g,Cr,n,E]),ln=r(async Fe=>{if(i)return;const Lt=ixe(_,(bn??ht)!=="agent"&&as==="all"?{onAll:!0,agentIds:new Set}:{onAll:!1,agentIds:xt});await us.putConnectionInstalls(Fe,Lt)},"applyAccessInstalls"),Fn=bn??ht,Nr=ye({mutationFn:r(async Fe=>{const Lt=Fe??ne;let Ts;if(Lt){const _n=bn??ht,Hr=dI(Lt,qe||null),Fa=Tk(Lt,Hr)?LO(Dt).ids:[],qr=me.trim(),xo=HY(qr||Lt.name,_n);Ts=await us.connectApp(_,{galleryKey:Lt.slug,...qe?{connectionMethodKey:qe}:{},name:xo,credentialSource:s,...s==="paperclip_vault"?{credentialValues:He}:{},...s==="vercel_connect"?{vercelConnect:{connector:Ve.trim()}}:{},...Ft.trim()?{oauthClient:{clientId:Ft.trim(),...Ot?{clientSecret:Ot}:{}}}:{},configValues:Tk(Lt,Hr)?{allowedSpreadsheetIds:Fa}:Object.keys(We).length>0?We:void 0,applicationId:Q.applicationId,...B?{resumeConnectionId:B}:H?{reconnectConnectionId:H}:{},..._n!=="organization"?{grantKind:_n}:{},..._n==="agent"?{subjectAgentId:[...xt][0]}:{}})}else{const _n=tGe({link:Ie,name:ve,authMode:tt,needsKey:fe,keyValue:Xe,headers:$e,oauthClientId:it,oauthClientSecret:Ge}),Hr=HY(_n.name??P4(Ie)??"Custom app",Fn);Ts=await us.connectApp(_,{..._n,...H?{reconnectConnectionId:H}:{},...le||On?.slug==="zapier"?{galleryKey:"zapier",connectionMethodKey:"generated-url"}:{},name:Hr,applicationId:Q.applicationId,...Fn!=="organization"?{grantKind:Fn}:{},...Fn==="agent"?{subjectAgentId:[...xt][0]}:{}})}return Ts.auth?.kind==="oauth"&&!B&&!H&&await ln(Ts.connectionId),Ts},"mutationFn"),onSuccess:r(Fe=>{if(Fe.auth?.kind==="oauth"){if(ke(Fe),Fe.auth.manualClientRequired){at(GY("oauth_manual_client_required",null)),ce("oauth"),st(!0),Ne(!1);return}if(n==="dialog"||E){Ye("starting"),Ne(!ne),ws(Fe.connection);return}const Ts=Fe.auth.startUrl?.trim();if(!Ts){Ye("starting"),Ne(!0),ws(Fe.connection);return}Ne(!0),ir({authorizationUrl:Ts,handoff:Fe.auth.handoff});return}at(null),ke(Fe);const Lt={};for(const Ts of Fe.actions.readOnly)Lt[Ts.catalogEntryId]=!0;for(const Ts of Fe.actions.canMakeChanges)Lt[Ts.catalogEntryId]=!0;wt(Lt),ss.mutate({result:Fe,enabled:Lt})},"onSuccess"),onError:r(Fe=>{const Lt=Fe instanceof Nn&&Fe.body&&typeof Fe.body=="object"?Fe.body.details:null;if(Ta){Ye("error"),g?.("needs_retry"),Ct(Lt?.code==="invalid_grant"?"Your authorization expired or was revoked. Reconnect to continue.":Fe instanceof Error?Fe.message:"Paperclip couldn’t start secure sign-in. Try again.");return}if(!ne&&Ie){const Ts=typeof Lt?.code=="string"?Lt.code:null,_n=GY(Ts,Fe instanceof Error?Fe.message:null);at(_n),Ne(!1),_n.focus==="credentials"&&st(!0);return}A({title:"Couldn’t connect",body:Fe instanceof Error?Fe.message:"Please check your key and try again.",tone:"error"})},"onError")}),we=Nr.mutate,Yt=(0,m.useCallback)(Fe=>{const Lt=Fe??ne;(Lt?dI(Lt,qe||null):null)?.auth==="oauth"&&Cr(),we(Fe)},[qe,ne,we,Cr]);(0,m.useEffect)(()=>{if(!oe||Ls.isLoading||!Ls.data||H&&(!Ms.isFetchedAfterMount||!jn.isFetchedAfterMount))return;const Fe=lGe({requestedAppKey:oe,galleryApps:Ls.data.apps,reconnectConnection:wn,applications:jn.data?.applications??[]}),Lt=!!Fe?.methods.some(Bn=>Bn.oauthStrategy==="paperclip_cloud_connector"||Bn.oauthStrategy==="paperclip_id_connector");if(gr&&!Lt&&qt.isLoading)return;const Ts=qy(Fe,s),_n=x??(wn?.connectionPurpose==="ai"?_W.safeParse(wn.config?.ai).data:void 0),Hr=Ts.find(Bn=>_n?Bn.ai?.provider===_n.provider&&(!("mode"in _n)||_n.mode!=="responsible_user")&&Bn.ai.method===_n.method:Bn.key===q)??(gr&&!Lt?sJ(ur):null)??Sj(Ts),Fa=Ts.length===1?Ts[0]:null,qr=s==="paperclip_vault"&&!!rJ(Fe),xo=dGe({credentialSource:s,available:Ls.data.credentialSources?.vercelConnect.available===!0,retainedReconnectMatches:!!(H&&Vn)}),Ue=Ts.length===1&&Fa?.auth==="oauth"&&!Ep(Fa)&&!gR(Fa),pt=uGe({available:Fe?.availability?.available,reconnectConnectionId:H,reconnectSourceMatches:Vn}),vs=mGe({reconnectConnectionId:H,hasRequestedEntry:!!Fe,supportedMethodCount:Ts.length,unsupportedOAuth:Ue,vercelUnavailable:xo,definitionUnavailable:pt});if(vs!=="ready"){if(ae(null),re("gallery"),vs==="reconnect_unavailable"&&H){_r(H);return}S(cI(s==="vercel_connect"?T4():"/apps/connect",E),{replace:!0});return}if(_r(null),!!Fe){if(ne?.slug!==Fe.slug){ae(Fe),he(Fe.name),de(""),Te(""),Ce(!1),Oe(""),St({}),ts(""),Be(""),ut(""),Gt(Hr?.key??""),$t(GN(Hr)),Cs(""),ct(null),ke(null);const Bn=J?.companyId===_?J:null;zt($s??Bn?.grantKind??M4(Hr,!!i)),ms(new Set(Bn?.agentIds??(i?[i]:[]))),Me(Bn?.installChoice??(i?"specific":"all")),re(XY({requestedAppKey:oe,routeStage:T,resumeConnectionId:B,hasPrefilledLink:!!Q.link,zapierSource:le}))}else gt!==Lt&&(ae(Fe),Gt(Hr?.key??""),$t(GN(Hr)));if(!(qr&&(!jn.isFetchedAfterMount||!Ms.isFetchedAfterMount))&&!(qr&&zs.current)&&qr&&(jn.isError||Ms.isError)){Ye("error"),Ct("Paperclip couldn’t check for an existing connection. Try again."),re("key");return}}},[x,q,jn.isError,jn.isFetchedAfterMount,jn.data,Ms.isError,Ms.isFetchedAfterMount,qt.data?.configured,qt.isLoading,qe,s,ne?.slug,gt,Ls.data,Ls.isLoading,S,$s,wn,H,Vn,B,ur,oe,i,J,T,le]),(0,m.useEffect)(()=>{wn?.connectionPurpose==="ai"&&pe==="access"&&re("key")},[wn?.connectionPurpose,pe]),(0,m.useEffect)(()=>{hs.current=null,Cn(null)},[B]),(0,m.useEffect)(()=>{if(!Ln||!ne||Ln.status!=="draft"||hs.current===Ln.id)return;const Fe=Ln.config&&typeof Ln.config=="object"?Ln.config:{},Lt=typeof Fe.sourceTemplateKey=="string"?Fe.sourceTemplateKey:null;if(Lt&&Lt!==ne.slug)return;const Ts=typeof Fe.connectionMethodKey=="string"?Fe.connectionMethodKey:null,_n=Ts?qy(ne,s).find(Fa=>Fa.key===Ts)??null:null;if(he(Ln.name||ne.name),_n){Gt(_n.key);const Fa=Fe.methodConfig&&typeof Fe.methodConfig=="object"?Fe.methodConfig:{};$t({...GN(_n),...Object.fromEntries(Object.entries(Fa).filter(qr=>typeof qr[1]=="string"||typeof qr[1]=="boolean"))})}const Hr=Fe.oauth&&typeof Fe.oauth=="object"?Fe.oauth:null;Hr?.clientRegistrationSource==="manual"&&typeof Hr.clientId=="string"&&ts(Hr.clientId),K==="failed"||K==="denied"?(Ye("error"),Ct(JY(K,z))):(Ye("entry"),Ct(null)),re("key"),hs.current=Ln.id,Cn(Ln.id)},[s,ne,z,K,Ln]);const ss=ye({mutationFn:r(async Fe=>{const{result:Lt,enabled:Ts}=Fe,_n=Object.entries(Ts).filter(([,Ue])=>Ue).map(([Ue])=>Ue),Hr=new Set(Array.isArray(Lt.suggestedDefaults.askFirstRiskLevels)?Lt.suggestedDefaults.askFirstRiskLevels.filter(Ue=>typeof Ue=="string"):[]),Fa=Lt.actions.canMakeChanges.filter(Ue=>Ts[Ue.catalogEntryId]&&Hr.has(Ue.riskLevel)).map(Ue=>Ue.catalogEntryId),qr=as==="all"?"all_agents":{agentIds:Array.from(xt)},xo=await us.finishApp(_,Lt.connectionId,{enabledCatalogEntryIds:_n,askFirstCatalogEntryIds:Fa,access:qr,...i?{preserveExistingAccess:!0}:{}});return await ln(Lt.connectionId),xo},"mutationFn"),onSuccess:r((Fe,Lt)=>{be("success"),h?.({connectionId:Lt.result.connectionId})},"onSuccess"),onError:r(Fe=>{be("access"),A({title:"Couldn’t finish setup",body:Fe instanceof Error?Fe.message:"Please try again.",tone:"error"})},"onError")});if(!_)return(0,t.jsx)("div",{className:"p-6 text-sm text-muted-foreground",children:"Select an organization to connect apps."});if((B||H)&&(Ms.isError||jn.isError))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Couldn’t load connection setup"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip couldn’t check the retained connection. The retained connection was not changed."}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",onClick:r(async()=>{const[Fe,Lt]=await Promise.all([Ms.refetch(),jn.refetch()]);!Fe.isError&&!Lt.isError&&(Ct(null),Ye("entry"))},"onClick"),children:"Try again"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]})]});if(B&&Ms.isFetchedAfterMount&&!Ln)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This setup can’t be resumed"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"The saved connection no longer exists or is not available to this organization."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if(H&&Ms.isFetchedAfterMount&&jn.isFetchedAfterMount&&(!wn||!Vn))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This connection can’t be reconnected"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:wn?"This reconnect link does not match the retained connection's provider.":"The retained connection no longer exists or is not available to this organization."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if((B||H)&&Ls.isError)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Couldn’t load connection setup"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip couldn’t load the provider details needed to restore this connection. The retained connection was not changed."}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",onClick:r(()=>{Ls.refetch()},"onClick"),children:"Try again"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]})]});if(H&&sa===H)return(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"This connection can’t be reconnected"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Paperclip no longer has a supported setup method for this retained connection. The retained connection was not changed."}),(0,t.jsx)(F,{type:"button",variant:"outline",className:"mt-5",onClick:r(()=>S("/apps"),"onClick"),children:"Back to apps"})]});if(B&&(!Ms.isFetchedAfterMount||Ls.isLoading||!ne||Ws!==Ln?.id))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl space-y-4","aria-label":"Loading saved connection setup",children:[(0,t.jsx)(fn,{className:"h-8 w-48"}),(0,t.jsx)(fn,{className:"h-40 w-full rounded-xl"})]});if(H&&(!Ms.isFetchedAfterMount||!jn.isFetchedAfterMount||Ls.isLoading||oe&&!ne))return(0,t.jsxs)("div",{className:"mx-auto max-w-xl space-y-4","aria-label":"Loading retained connection setup",children:[(0,t.jsx)(fn,{className:"h-8 w-48"}),(0,t.jsx)(fn,{className:"h-40 w-full rounded-xl"})]});if(ca&&u)return(0,t.jsxs)("div",{className:"max-w-5xl","data-testid":"connection-existing-choice",children:[(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsxs)("h1",{className:"text-2xl font-bold tracking-tight",children:["Use an existing ",oe?"connection":"app connection"]}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Reuse a connection without changing who already has access, or connect a new one."})]}),(0,t.jsx)(lU,{choices:c.map(Fe=>({id:Fe.id,name:Fe.name,description:Fe.status==="active"&&Fe.enabled?"Ready to use":"Setup needs attention"})),pendingId:gn,onSelect:r(async Fe=>{rr(Fe),ar(null);try{await u(Fe)}catch(Lt){ar(Lt instanceof Error?Lt.message:"Couldn’t use this connection."),rr(null)}},"onSelect")}),wr?(0,t.jsx)(ri,{tone:"danger",className:"mt-4",children:wr}):null,(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>Sr(!1),"onClick"),children:d?"Review connection setup":"Connect new"}),v?(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:v,children:"Cancel"}):null]})]});const Pn=!!(Ta&&pe==="key"&&(Br||ft!=="entry")),cr=!!(pe==="key"&&ne&&gr&&!gt&&qt.data?.configured===!0),Oa=!!(pe==="key"&&ne&&gr&&!gt&&(qt.isLoading||qt.isError||qt.data?.configured!==!0));if(Pn&&Ta)return(0,t.jsx)(RF,{entry:Ta,resuming:!!B,phase:ft,error:gs,recoveryActions:z==="github_installation_required"?{installationUrl:D,managementUrl:V}:void 0,authorizationHost:os,authorizationUrl:Tn,onOpenAuthorization:Yn,onRetry:r(async()=>{Ct(null),Ye("starting");const Fe=Pt?.connection??Jn;if(Fe){ws(Fe);return}zs.current=!0;try{const[Lt,Ts]=await Promise.all([jn.refetch(),Ms.refetch()]);if(Lt.isError||Ts.isError){Ye("error"),Ct("Paperclip couldn’t check for an existing connection. Try again.");return}const _n=(B?(Ts.data?.connections??[]).find(Hr=>Hr.id===B&&Hr.authKind==="oauth")??null:null)??aJ(se,Lt.data?.applications??[],Ts.data?.connections??[],$?{applicationId:Q.applicationId,draftOnly:!0}:{});if(!Xt.current&&!B){_n&&zt(_n.credentialPolicy==="per_user"?"user":_n.credentialPolicy==="per_agent"?"agent":"organization"),Ye("entry"),Ct(null),re("access");return}_n?ws(_n):Nr.mutate(Ta)}finally{zs.current=!1}},"onRetry"),onBack:r(()=>{an.current?.abort(),Ye("entry"),Ct(null),be("access")},"onBack"),onCancel:r(()=>{an.current?.abort(),(v??(()=>S("/apps")))()},"onCancel")});if(Ee&&!ne&&Ie&&pe==="key")return(0,t.jsx)(RF,{identity:{name:ve.trim()||fS(Ie)||"this server",unverifiedHost:fS(Ie)},steps:{labels:eJ,activeIndex:tJ.key},phase:ft,error:gs,authorizationHost:os,authorizationUrl:Tn,onOpenAuthorization:Yn,onRetry:r(()=>{Ct(null);const Fe=Pt?.connection;if(Fe){Ye("starting"),ws(Fe);return}Ne(!1),Ye("entry")},"onRetry"),onBack:r(()=>{an.current?.abort(),Ne(!1),Ye("entry"),Ct(null)},"onBack"),onCancel:r(()=>{an.current?.abort(),(v??(()=>S("/apps")))()},"onCancel")});const si=Pt?.application.name??ne?.name??(ve.trim()||P4(Ie)||"this app"),Kt=qy(ne,s),ls=ks?[ks]:Kt,dn=Y?Hn.filter(Fe=>qy(Fe,s).length>0):Hn,na=le?Ls.data?.apps.find(Fe=>Fe.slug==="zapier")??null:null,Xn=(wn?.connectionPurpose==="ai"?_W.safeParse(wn.config?.ai).data:void 0)??ne?.methods.find(Fe=>Fe.key===qe)?.ai??(!qe&&ne?.methods.every(Fe=>Fe.ai)?ne.methods[0]?.ai:void 0),Yr=ne?y?.({app:ne,name:me||ne.name,grantKind:Fn,agentIds:[...xt],allAgents:as==="all",onBack:r(()=>be("access"),"onBack")})??(Xn&&_?(0,t.jsx)(t.Fragment,{children:(0,t.jsx)(IT,{companyId:_,provider:Xn.provider,fixedMethod:!!(x&&x.mode!=="responsible_user"),initialMethod:wn?.connectionPurpose==="ai"?(wn.config?.ai).method:Xn.method,connectionId:wn?.connectionPurpose==="ai"?wn.id:void 0,name:wn?.connectionPurpose==="ai"?wn.name:me||`My ${ne.name} ${Xn.method==="subscription"?"subscription":"API"}`,ownership:(wn?.connectionPurpose==="ai"?wn.credentialPolicy==="shared":Fn==="organization")?"shared":"personal",agentIds:[...xt],allAgents:as==="all",onCancel:r(()=>v?v():S("/apps"),"onCancel"),onComplete:r(Fe=>{h?.({connectionId:Fe.connectionId}),h||S(`/apps/${Fe.connectionId}/permissions`)},"onComplete")})}):void 0):void 0,Ua=wn?.connectionPurpose==="ai"?["Reconnect account"]:Yr!==void 0?["Access","Connect account"]:le?pGe:ne&&ls.length>1?["Access","Choose connection"]:ne&&ls[0]?.auth==="oauth"?["Access","Sign in"]:Tk(ne,qe)?["Access","Share sheet"]:ne?["Access","Add your key"]:eJ,Ti=ne?qe?ls.find(Fe=>Fe.key===qe)??null:ls[0]??null:null,Oi=ne?Ti?.auth??"none":tt==="none"?"none":tt==="oauth"?"oauth":"api_key",Ui=!!Br,oi=Ui?`Continue to ${ne?.name??"sign-in"}`:Oi==="oauth"?"Continue":"Save and continue",Pe=wn?.connectionPurpose==="ai"?0:(le||ne)&&pe!=="gallery"&&pe!=="success"?hGe[pe]:pe==="success"?Ua.length:tJ[pe];return(0,t.jsxs)("div",{className:"max-w-5xl",children:[pe!=="success"&&!(e&&pe==="gallery")&&(0,t.jsx)(aK,{subtitle:pe==="gallery"?Y?"Choose a reviewed app to connect through Vercel.":"Pick the app you want your agents to use.":`Step ${Pe+1} of ${Ua.length}`,step:pe,activeIndex:Pe,labels:Ua,appIdentity:le?{name:"Zapier",logoUrl:na?.branding.logoUrl??null,darkLogoUrl:na?.branding.darkLogoUrl??null}:ne&&pe!=="gallery"?{name:ne.name,logoUrl:ne.branding.logoUrl,darkLogoUrl:ne.branding.darkLogoUrl??null}:void 0,unverifiedHost:!ne&&!le&&pe!=="gallery"?fS(Ie):null,onCancel:v??(()=>S("/apps"))}),pe==="gallery"&&(0,t.jsx)(jGe,{loading:Ls.isLoading,initialLink:Ie,apps:dn,vercelConnect:Y,vercelConnectAvailability:Ls.data?.credentialSources?.vercelConnect??null,byo:te,byoOnly:e,source:R.get("source"),onPick:dr,onUseLink:r(Fe=>{const Lt=jR(Fe,Hn);ae(null),he(""),de(Fe),Te(Lt?.name??P4(Fe)??""),Ce(!1),Oe(""),St({}),Cs(""),ct(null),ms(new Set(i?[i]:[])),Me(i?"specific":"all"),zt($s??(i?"user":"organization")),re("access")},"onUseLink")}),cr&&ne?(0,t.jsxs)("div",{className:"mx-auto max-w-xl rounded-xl border border-border bg-card p-6",children:[(0,t.jsxs)("h2",{className:"text-lg font-semibold text-foreground",children:[ne.name," sign-in is unavailable"]}),(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["This instance is connected to Paperclip, but ",ne.name," sign-in is not currently available. Try again shortly or contact your instance administrator."]}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between gap-3",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>be("access"),"onClick"),children:"Back"}),(0,t.jsxs)(F,{type:"button",disabled:Ls.isFetching,onClick:r(()=>{Ls.refetch()},"onClick"),children:[Ls.isFetching?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}):null,"Try again"]})]})]}):pe==="key"&&ne&&Oa?(0,t.jsx)("div",{className:"mx-auto max-w-xl",children:(0,t.jsxs)("div",{className:"rounded-xl border border-border bg-card p-6",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"rounded-lg bg-muted p-2 text-muted-foreground",children:(0,t.jsx)(Wg,{className:"h-5 w-5"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:"Connect with Paperclip"}),(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["You must connect this instance to Paperclip to connect to ",ne.name," (you only need to do this once)."]})]})]}),qt.isError||Hs?(0,t.jsx)(ri,{tone:"danger",className:"mt-4",children:Hs??"Paperclip couldn’t check Cloud registration. Try again."}):null,Es?(0,t.jsxs)("p",{className:"mt-4 text-sm text-muted-foreground",children:["Finish authorization in the opened window."," ",(0,t.jsx)("a",{className:"underline",href:Es,target:"_blank",rel:"noopener noreferrer",children:"Open authorization in a new tab"})]}):null,(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between gap-3",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:r(()=>be("access"),"onClick"),children:"Back"}),(0,t.jsxs)(F,{type:"button",disabled:qt.isLoading||on.isPending,onClick:r(()=>{Ks(null),Cr(),Ar(),on.mutate()},"onClick"),children:[on.isPending?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}):null,qt.data?.status==="pending"?"Continue":"Connect with Paperclip"]})]})]})}):pe==="key"&&ne&&Yr!==void 0?Yr:pe==="key"&&ne?(0,t.jsx)(NGe,{entry:ne,error:Nr.isError?Nr.error instanceof Error?Nr.error.message:"Please check your key and try again.":null,values:He,onChange:St,oauthClientId:Ft,onOAuthClientIdChange:ts,oauthClientSecret:Ot,onOAuthClientSecretChange:Be,credentialSource:s,vercelConnector:Ve,onVercelConnectorChange:ut,vercelConnectAvailability:Ls.data?.credentialSources?.vercelConnect??null,methodKey:qe,onMethodChange:r(Fe=>{Gt(Fe?.key??""),!$s&&Fe?.grantKinds&&!Fe.grantKinds.includes(ht)&&zt(M4(Fe,!!i)),St({}),ts(""),Be(""),ut(""),$t(GN(Fe))},"onMethodChange"),configValues:We,onConfigChange:$t,googleSheetsLinks:Dt,googleSheetsError:ze,onGoogleSheetsLinksChange:r(Fe=>{Cs(Fe),ct(null)},"onGoogleSheetsLinksChange"),submitting:Nr.isPending,onBack:r(()=>be("access"),"onBack"),onConnect:r(()=>{if(Tk(ne,qe)){const Ts=LO(Dt);if(Ts.invalidCount>0){ct("That doesn't look like a Google Sheets link.");return}if(Ts.ids.length===0){ct("Paste at least one Google Sheets link.");return}}const Fe=dI(ne,qe||null),Lt=!!(Fe?.credentialFields?.length||Fe?.tenantFields?.some(Ts=>!Ts.hidden)||Fe?.extensionFields?.some(Ts=>!Ts.hidden));if(Fe&&Ep(Fe)&&Jn&&!Lt&&!Ft.trim()){Xt.current=!0,Ct(null),Ye("starting"),ws(Jn);return}Fe&&Ep(Fe)&&(Xt.current=!0,Ct(null),Ye("starting")),Yt()},"onConnect")}):null,pe==="key"&&!ne&&Ie&&!le&&(0,t.jsx)(wGe,{link:Ie,name:ve,needsKey:fe,onNeedsKeyChange:r(Fe=>{Ce(Fe),Fe||Oe("")},"onNeedsKeyChange"),keyValue:Xe,onKeyChange:Oe,authMode:tt,onAuthModeChange:r(Fe=>{ce(Fe),at(null),Fe!=="auto"&&Ce(!1),Fe!=="bearer"&&Fe!=="auto"&&Oe("")},"onAuthModeChange"),headers:$e,onHeadersChange:r(Fe=>{mt(Fe),at(null)},"onHeadersChange"),oauthClientId:it,onOAuthClientIdChange:Ke,oauthClientSecret:Ge,onOAuthClientSecretChange:rt,advancedOpen:jt,onAdvancedOpenChange:st,guidance:Nt,matchedEntry:On,onUseMatchedEntry:On?()=>dr(On):void 0,submitting:Nr.isPending||Ee,onBack:r(()=>re("access"),"onBack"),onConnect:r(()=>{at(null),Nr.mutate(void 0)},"onConnect")}),pe==="key"&&!ne&&le&&(0,t.jsx)(yGe,{link:Ie,onLinkChange:de,submitting:Nr.isPending,onBack:r(()=>re("access"),"onBack"),onConnect:r(()=>Nr.mutate(void 0),"onConnect")}),pe==="access"&&(0,t.jsxs)(t.Fragment,{children:[ne?.slug==="railway"&&(0,t.jsxs)("div",{className:"mb-6 space-y-3 text-sm text-muted-foreground",children:[(0,t.jsx)("p",{children:Ti?.guidanceMd}),(0,t.jsx)("ul",{className:"list-disc space-y-2 pl-5",children:Ti?.warnings?.map(Fe=>(0,t.jsx)("li",{children:Fe},Fe))})]}),(0,t.jsx)(dxe,{companyId:_,authKind:Oi,grantKinds:bn?[bn]:Ti?.grantKinds,grantKind:Fn,setGrantKind:zt,installChoice:as,setInstallChoice:Me,installAgentIds:xt,setInstallAgentIds:ms,lockedAgentId:i,capabilities:Ls.data?.capabilities,githubIdentity:ne?.slug==="github",submitLabel:oi,continuesToProvider:Ui,identityLoading:!!Ta&&ii,preserveAgentAccess:!!(Ta&&(Jn||wn)),pending:Nr.isPending||je.isPending||!!(oe&&!ne),onBack:da,onContinue:r(()=>{if(Br){Xt.current=!0,Ct(null),Ye("starting"),be("key"),Jn?ws(Jn):Yt(Br);return}ne?be("key"):re("key")},"onContinue")})]}),pe==="success"&&(0,t.jsx)(CGe,{appName:si,logoUrl:ne?.branding.logoUrl,darkLogoUrl:ne?.branding.darkLogoUrl,summary:SGe({grantKind:Fn,authKind:Oi,installChoice:as,installCount:xt.size,enabledCount:Object.values(ys).filter(Boolean).length}),onDone:v??(()=>S("/apps"))})]})}r(vGe,"StandardConnectionSetupFlow");function aK({title:e,headingRef:s,subtitle:n,step:a,activeIndex:i,labels:o,appIdentity:l,unverifiedHost:c,onCancel:d}){return(0,t.jsxs)("div",{className:"mb-6",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[l?(0,t.jsx)(bc,{name:l.name,logoUrl:l.logoUrl,darkLogoUrl:l.darkLogoUrl,size:44}):null,(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{ref:s,tabIndex:s?-1:void 0,className:"text-2xl font-bold tracking-tight outline-none",children:e??(l?`Connect ${l.name}`:"Connect your own MCP server")}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:n}),c?(0,t.jsx)(Y5,{host:c,className:"mt-2"}):null]})]}),d&&(0,t.jsx)(F,{variant:"ghost",size:"sm",onClick:d,children:"Cancel"})]}),a!=="gallery"&&(0,t.jsxs)("nav",{className:"mt-4","aria-label":"Setup progress","data-testid":"wizard-stepper",children:[(0,t.jsx)("ol",{className:"flex gap-2","aria-hidden":"true",children:o.map((u,h)=>(0,t.jsx)("li",{"data-testid":"wizard-step-dot","data-step-active":h===i?"true":void 0,className:U("h-1 w-20 rounded-full",h<=i?"bg-foreground":"bg-border")},u))}),(0,t.jsx)("div",{className:"mt-2 text-xs text-muted-foreground","data-testid":"wizard-step-labels",children:o.join(" · ")})]})]})}r(aK,"StepHeader");function RF({entry:e,identity:s,resuming:n=!1,phase:a,error:i,recoveryActions:o,authorizationHost:l,authorizationUrl:c,steps:d={labels:fGe,activeIndex:1},onRetry:u,onOpenAuthorization:h,onBack:p,onCancel:x}){const g=e?.name??s?.name??"this server",v=e?null:s?.unverifiedHost??null,y=a==="entry"?{title:n?`Finish connecting ${g}`:`Connect ${g} to Paperclip`,body:n?`Your connection is saved. Continue in ${g} to approve access; its identity and agent access will stay the same.`:`Paperclip will open ${g} so you can choose a workspace and approve access.`}:a==="starting"?{title:"Preparing secure sign-in",body:`Paperclip is creating a secure ${g} connection.`}:a==="redirecting"?{title:`Opening ${g}`,body:l?`Continue at ${l} to choose a workspace and approve access. Only approve access if you recognize that address.`:`Continue in ${g} to choose a workspace and approve access.`}:{title:`${g} couldn’t connect`,body:i??"Paperclip couldn’t start secure sign-in. Try again."};return(0,t.jsxs)("div",{className:"max-w-5xl",children:[(0,t.jsx)(aK,{subtitle:"Secure MCP sign-in",step:"key",activeIndex:d.activeIndex,labels:d.labels,appIdentity:e?{name:e.name,logoUrl:e.branding.logoUrl,darkLogoUrl:e.branding.darkLogoUrl}:void 0,unverifiedHost:v,onCancel:x}),(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("span",{className:"mt-1 inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border border-border bg-background",children:a==="error"?(0,t.jsx)(nc,{className:"h-5 w-5 text-destructive"}):a==="entry"?(0,t.jsx)(Pd,{className:"h-5 w-5 text-muted-foreground"}):(0,t.jsx)(ot,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-xl font-bold tracking-tight",children:y.title}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:y.body}),v?(0,t.jsx)(Y5,{host:v,className:"mt-2"}):null]})]}),a==="error"&&o&&(o.installationUrl||o.managementUrl)?(0,t.jsxs)("div",{className:"mt-4 flex flex-wrap gap-2",children:[o.installationUrl?(0,t.jsx)(F,{type:"button",variant:"outline",asChild:!0,children:(0,t.jsxs)("a",{href:o.installationUrl,target:"_blank",rel:"noreferrer",children:["Install Paperclip on GitHub",(0,t.jsx)(eo,{className:"ml-1.5 h-3.5 w-3.5"})]})}):null,o.managementUrl?(0,t.jsx)(F,{type:"button",variant:"ghost",asChild:!0,children:(0,t.jsx)("a",{href:o.managementUrl,target:"_blank",rel:"noreferrer",children:"Manage repositories on GitHub"})}):null]}):null,(0,t.jsxs)("div",{className:"mt-6 flex items-center gap-2",children:[a==="error"||a==="entry"?(0,t.jsx)(F,{type:"button",onClick:u,children:a==="entry"?n?`Finish with ${g}`:`Continue to ${g}`:"Try again"}):(0,t.jsx)(F,{type:"button",disabled:!0,children:a==="redirecting"?`Opening ${g}…`:"Preparing…"}),c?(0,t.jsx)(F,{variant:"outline",asChild:!0,children:(0,t.jsx)("a",{href:c,target:"_blank",rel:"noopener noreferrer",onClick:h,children:"Open sign-in in a new tab"})}):null,(0,t.jsx)(F,{type:"button",variant:"ghost",onClick:p,children:"Back"})]})]})]})}r(RF,"OAuthConnectStateScreen");function yGe({link:e,onLinkChange:s,submitting:n,onBack:a,onConnect:i}){const o=TF(e),l=o?new URL(o).hostname:"",c=l==="zapier.com"||l.endsWith(".zapier.com");return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Zapier MCP URL"}),(0,t.jsx)(Rt,{type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r(d=>s(d.target.value),"onChange"),onKeyDown:r(d=>{d.key==="Enter"&&c&&!n&&i()},"onKeyDown"),placeholder:"https://mcp.zapier.com/api/v1/connect?token=…",className:"mt-2 h-11",autoFocus:!0}),e.trim()&&!c&&(0,t.jsx)("p",{className:"mt-2 text-xs text-destructive",children:"Paste a valid Zapier URL to continue."})]}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:a,disabled:n,children:"Back"}),(0,t.jsxs)(F,{onClick:i,disabled:n||!c,children:[n&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),n?"Checking…":"Check link"]})]})]})}r(yGe,"ZapierConnectStep");function jGe({loading:e,initialLink:s="",apps:n,byo:a=!1,byoOnly:i=!1,vercelConnect:o=!1,vercelConnectAvailability:l=null,source:c=null,onPick:d,onUseLink:u}){const[h,p]=(0,m.useState)(""),[x,g]=(0,m.useState)(s),v=(0,m.useRef)(!1);(0,m.useEffect)(()=>{v.current||g(s)},[s]);const[y,j]=(0,m.useState)(null),S=(0,m.useRef)(null),w=(0,m.useRef)(null),N=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a||e&&!i||N.current||(i||S.current?.scrollIntoView?.({block:"center"}),w.current?.focus(),w.current?.select(),N.current=!0)},[a,i,e]);const _=(0,m.useMemo)(()=>{const E=h.trim().toLowerCase();return n.filter(O=>!E||O.name.toLowerCase().includes(E))},[n,h]),I=TF(x),C=I?jR(I,n):null,A=c==="zapier",R=r(()=>{const E=TF(x);if(!E){j("Paste a full http or https link.");return}j(null),u(E)},"continueWithLink");return e&&!i?(0,t.jsx)("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4",children:Array.from({length:8}).map((E,O)=>(0,t.jsx)(fn,{className:"h-32 w-full rounded-xl"},O))}):(0,t.jsxs)("div",{className:"space-y-6",children:[o?(0,t.jsxs)("div",{className:"rounded-xl border border-border bg-card p-5",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-bold tracking-tight",children:"Connect through Vercel"}),(0,t.jsx)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:"Create and manage the provider connector in Vercel. Paperclip stores its reference and applies agent access, policy, approval, and audit controls here."})]}),l?(0,t.jsx)(F,{asChild:!0,variant:"outline",size:"sm",className:"shrink-0",children:(0,t.jsxs)("a",{href:l.manageUrl,target:"_blank",rel:"noreferrer",children:["Open Vercel Connect",(0,t.jsx)(eo,{className:"ml-2 h-3.5 w-3.5"})]})}):null]}),l?.available===!1?(0,t.jsx)(ri,{tone:"danger",compact:!0,className:"mt-4",children:l.reason??"Vercel Connect is unavailable on this instance."}):null]}):null,!i&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(pa,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),(0,t.jsx)(Rt,{value:h,onChange:r(E=>p(E.target.value),"onChange"),placeholder:"Search apps…",className:"h-11 pl-9"})]}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4",children:_.map(E=>{const O=nxe(E.slug,E.description),L=R1(E),$=L.length===0||L.every(q=>q.auth==="oauth"&&!Ep(q)&&!gR(q)),T=E.availability?.available===!1||o&&l?.available!==!0;return(0,t.jsxs)("button",{type:"button",disabled:$||T,title:T?E.availability?.reason??l?.reason??void 0:void 0,onClick:r(()=>d(E),"onClick"),className:U("flex flex-col rounded-xl border border-border bg-card p-4 text-left transition-colors",$||T?"cursor-not-allowed opacity-60":"hover:border-foreground/30 hover:bg-accent/40"),children:[(0,t.jsx)(bc,{name:E.name,logoUrl:E.branding.logoUrl,darkLogoUrl:E.branding.darkLogoUrl,size:36}),(0,t.jsx)("div",{className:"mt-3 text-sm font-bold text-foreground",children:E.name}),(0,t.jsx)("div",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:O.tagline}),(0,t.jsx)("div",{className:"mt-3 text-xs font-semibold text-foreground",children:T?(0,t.jsx)("span",{className:"text-muted-foreground",children:E.availability?.reason??l?.reason??"Unavailable on this instance."}):$?(0,t.jsx)("span",{className:"text-muted-foreground",children:"Unavailable"}):(0,t.jsx)("span",{children:"Connect →"})})]},E.slug)})}),_.length===0&&(0,t.jsxs)("div",{className:"py-10 text-center text-sm text-muted-foreground",children:["No apps match “",h,"”."]})]}),o?null:(0,t.jsxs)("div",{ref:S,className:U("grid gap-4 border-t border-border pt-5 md:grid-cols-(--gtc-13)",a&&"-mx-3 rounded-xl border border-primary/40 bg-primary/[0.04] px-3 pb-4 md:mx-0"),children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[(0,t.jsx)(nc,{className:"h-4 w-4 text-muted-foreground"}),A?"Connect Zapier":a?"Connect your own MCP server":"Connect with a link"]}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:A?"Paste the complete MCP URL Zapier gives you, including its token.":a?"Paste your MCP server’s URL and every discovered tool will be available immediately.":"Paste a setup link from an app that is not listed here."}),!A&&(0,t.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:["Any remote tool URL works here — including a local MCP server like"," ",(0,t.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:"http://127.0.0.1:8848/mcp"}),"."]}),C&&(0,t.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg border border-border bg-muted/40 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,t.jsx)(bc,{name:C.name,logoUrl:C.branding.logoUrl,darkLogoUrl:C.branding.darkLogoUrl,size:24}),(0,t.jsxs)("span",{className:"truncate",children:["This looks like ",C.name,"."]})]}),(0,t.jsx)(F,{type:"button",size:"sm",variant:"outline",disabled:C.availability?.available===!1,onClick:r(()=>{if(j(null),C.slug==="zapier"){R();return}d(C)},"onClick"),children:C.availability?.available===!1?"Not available":C.slug==="zapier"?"Continue":`Use ${C.name}`})]})]}),(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-2 sm:min-w-(--sz-360px)",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(Rt,{ref:w,type:A||C?.slug==="zapier"?"password":"url",autoComplete:"off",spellCheck:!1,"aria-label":"MCP server URL",value:x,onChange:r(E=>{v.current=!0,g(E.target.value),j(null)},"onChange"),onKeyDown:r(E=>{E.key==="Enter"&&R()},"onKeyDown"),placeholder:A?"https://mcp.zapier.com/api/v1/connect?token=…":"https://example.com/actions",className:"h-10"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:R,children:"Continue"})]}),y&&(0,t.jsx)("div",{className:"text-xs text-destructive",children:y})]})]})]})}r(jGe,"GalleryStep");function TF(e){try{const s=new URL(e.trim());return s.protocol!=="http:"&&s.protocol!=="https:"?null:s.toString()}catch{return null}}r(TF,"normalizeAppLink");function wGe({link:e,name:s,needsKey:n,onNeedsKeyChange:a,keyValue:i,onKeyChange:o,authMode:l,onAuthModeChange:c,headers:d,onHeadersChange:u,oauthClientId:h,onOAuthClientIdChange:p,oauthClientSecret:x,onOAuthClientSecretChange:g,advancedOpen:v,onAdvancedOpenChange:y,guidance:j,matchedEntry:S,onUseMatchedEntry:w,submitting:N,onBack:_,onConnect:I}){const C=fS(e),A=l==="custom_headers"?rxe(d):null,R=sGe({link:e,name:s,authMode:l,needsKey:n,keyValue:i,headers:d,oauthClientId:h,oauthClientSecret:x}),E=l==="auto",O=S?.slug==="zapier"?nle(e):e,L=r(($,T)=>{u(d.map(q=>q.id===$?{...q,...T}:q))},"updateHeader");return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)("p",{className:"min-w-0 truncate font-mono text-sm text-muted-foreground",title:O,children:O}),(0,t.jsx)(Y5,{host:C})]}),S&&w?(0,t.jsxs)("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border bg-muted/40 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,t.jsx)(bc,{name:S.name,logoUrl:S.branding.logoUrl,darkLogoUrl:S.branding.darkLogoUrl,size:24}),(0,t.jsxs)("span",{className:"truncate",children:["Paperclip has a guided setup for ",S.name,"."]})]}),(0,t.jsxs)(F,{type:"button",size:"sm",variant:"outline",onClick:w,children:["Use ",S.name]})]}):null,j?(0,t.jsx)("div",{className:"mt-6",children:(0,t.jsx)(ri,{tone:"warning",title:j.title,children:j.body})}):null,(0,t.jsxs)("div",{className:"mt-6 space-y-6",children:[E&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mr-2 text-sm font-medium text-foreground",children:"Does it need a key?"}),(0,t.jsxs)("div",{className:"mt-2 inline-flex rounded-lg border border-border bg-muted/50 p-1",children:[(0,t.jsx)(D4,{label:"No",selected:!n,onClick:r(()=>a(!1),"onClick")}),(0,t.jsx)(D4,{label:"Yes",selected:n,onClick:r(()=>a(!0),"onClick")})]}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:n?"Paste the key this app gave you.":"Most servers just work from the address — pick Yes only if the server gave you a key, or if it asks you to sign in."})]}),E&&n||l==="bearer"?(0,t.jsx)("div",{className:"space-y-4",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-key",children:"App key"}),(0,t.jsx)(Rt,{id:"generic-mcp-key",type:"password",autoComplete:"off",value:i,onChange:r($=>o($.target.value),"onChange"),placeholder:"••••••••••••••••",className:"mt-2 h-11 font-mono"})]})}):null,(0,t.jsxs)(el,{open:v,onOpenChange:y,children:[(0,t.jsxs)(Ul,{className:"flex w-full items-center justify-between rounded-lg border border-border bg-background px-3 py-2 text-left text-sm font-medium text-foreground hover:bg-accent/40",children:["Advanced authentication",(0,t.jsx)(en,{className:U("h-4 w-4 text-muted-foreground transition-transform",v&&"rotate-180")})]}),(0,t.jsxs)(tl,{className:"space-y-5 pt-4",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Only needed when the server's docs are specific about how to authenticate."}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:iJ.map($=>(0,t.jsx)(D4,{label:$.label,selected:l===$.mode,onClick:r(()=>c($.mode),"onClick")},$.mode))}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:iJ.find($=>$.mode===l)?.hint}),l==="custom_headers"?(0,t.jsxs)("div",{className:"space-y-3",children:[d.map($=>(0,t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,t.jsx)(Rt,{value:$.name,onChange:r(T=>L($.id,{name:T.target.value}),"onChange"),placeholder:"Header name","aria-label":"Header name",className:"h-10 font-mono"}),(0,t.jsx)(Rt,{type:"password",autoComplete:"off",value:$.value,onChange:r(T=>L($.id,{value:T.target.value}),"onChange"),placeholder:"Value","aria-label":$.name.trim()?`Value for ${$.name.trim()}`:"Header value",className:"h-10 font-mono"}),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"sm",className:"h-10 shrink-0",onClick:r(()=>u(d.filter(T=>T.id!==$.id)),"onClick"),disabled:d.length===1,children:"Remove"})]},$.id)),(0,t.jsx)(F,{type:"button",variant:"outline",size:"sm",onClick:r(()=>u([...d,AF()]),"onClick"),children:"Add another header"}),A?(0,t.jsx)("p",{className:"text-xs text-destructive",children:A}):null]}):null,l==="oauth"?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Paperclip sets sign-in up on its own whenever the server allows it. Only fill these in when the server's docs tell you to register Paperclip yourself first."}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-client-id",children:"Client ID"}),(0,t.jsx)(Rt,{id:"generic-mcp-client-id",value:h,onChange:r($=>p($.target.value),"onChange"),autoComplete:"off",placeholder:"Optional",className:"mt-2 h-11 font-mono"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"generic-mcp-client-secret",children:"Client secret"}),(0,t.jsx)(Rt,{id:"generic-mcp-client-secret",type:"password",autoComplete:"off",value:x,onChange:r($=>g($.target.value),"onChange"),placeholder:"Optional",className:"mt-2 h-11 font-mono"})]})]}):null]})]})]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!R||!!A,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":"Check link"]})]})]})}r(wGe,"LinkConnectStep");var iJ=[{mode:"auto",label:"Let Paperclip check",hint:"Paperclip asks the server what it needs and walks you through it. Start here."},{mode:"none",label:"No sign-in needed",hint:"The server is open to anyone with the address."},{mode:"bearer",label:"Key or token",hint:"Paperclip sends your key as an Authorization header."},{mode:"custom_headers",label:"Custom headers",hint:"For servers that name their own headers. Values are stored as Paperclip secrets and can’t be read back."},{mode:"oauth",label:"Browser sign-in",hint:"You’ll sign in at the provider. Add a client ID and secret only if the provider requires you to register Paperclip first."}];function D4({label:e,selected:s,onClick:n}){return(0,t.jsx)("button",{type:"button",onClick:n,"aria-pressed":s,className:U("min-w-(--sz-64px) rounded-md px-4 py-1.5 text-sm font-medium transition-colors",s?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:e})}r(D4,"SegmentedOption");function NGe({entry:e,error:s,values:n,onChange:a,oauthClientId:i,onOAuthClientIdChange:o,oauthClientSecret:l,onOAuthClientSecretChange:c,credentialSource:d,vercelConnector:u,onVercelConnectorChange:h,vercelConnectAvailability:p,methodKey:x,onMethodChange:g,configValues:v,onConfigChange:y,googleSheetsLinks:j,googleSheetsError:S,onGoogleSheetsLinksChange:w,submitting:N,onBack:_,onConnect:I}){const C=(0,m.useMemo)(()=>qy(e,d),[d,e]),A=x?C.find(Oe=>Oe.key===x)??null:Sj(C),R=(0,m.useMemo)(()=>C.some(Oe=>Oe.capabilityProfile)?Array.from(C.reduce((Oe,tt)=>{const ce=tt.capabilityProfile.key,$e=Oe.get(ce);return $e?$e.methods.push(tt):Oe.set(ce,{key:ce,label:tt.capabilityProfile?.label??tt.label??tt.key,description:tt.capabilityProfile?.description??tt.whenToUse,methods:[tt]}),Oe},new Map)).map(([,Oe])=>Oe):[],[C]),E=A?.capabilityProfile?.key??A?.key??"",O=R.map(Oe=>Oe.key).join("|"),[L,$]=(0,m.useState)(E||Sj(C)?.capabilityProfile?.key||(R.length===1?R[0].key:""));(0,m.useEffect)(()=>{if(E){$(E);return}$(Oe=>R.some(tt=>tt.key===Oe)?Oe:Sj(C)?.capabilityProfile?.key||(R.length===1?R[0].key:""))},[O,R,C,E]);const T=R.length>1?R.find(Oe=>Oe.key===L)?.methods??[]:C,q=(A?.credentialFields??[]).map(Oe=>({...Oe,configPath:sle(Oe),helpUrl:A?.consoleLinks?.keys??A?.consoleLinks?.docs??""})),B=A?.credentialSources?.vercelConnect??null,K=d==="vercel_connect",z=K||q.every(Oe=>Oe.required===!1||(n[Oe.configPath]?.trim().length??0)>0),D=gR(A),V=D&&!Ep(A),H=K||!V||i.trim().length>0,Z=!K||u.trim().length>0,Y=A?.auth==="oauth"&&D?eGe():null,ie=[...A?.tenantFields??[],...A?.extensionFields??[]],se=ie.filter(Oe=>!Oe.hidden),X=se.filter(Oe=>Oe.advanced!==!0),le=se.filter(Oe=>Oe.advanced===!0),[oe,te]=(0,m.useState)(!1),J=ie.every(Oe=>{if(!Oe.required)return!0;const tt=v[Oe.key];return typeof tt=="boolean"||typeof tt=="string"&&tt.trim().length>0}),Q=A?.configRequirements?.atLeastOneOf??[],pe=Q.length===0||Q.some(Oe=>{const tt=v[Oe];return typeof tt=="string"&&tt.trim().length>0}),re=(R.length<=1||!!L)&&(T.length<=1?!!A:!!x),ne=e.availability?.robotEmail??null,ae=e.availability?.available===!1,me=!K&&D&&!V,he=le.length>0||me,Ie=R.length>1?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"What should Paperclip be able to do?"}),(0,t.jsx)(iu,{ariaLabel:`Access level for ${e.name}`,className:"mt-2",value:L,onValueChange:r(Oe=>{const tt=R.find(ce=>ce.key===Oe);tt&&($(Oe),g(H6(tt.methods)))},"onValueChange"),options:R.map(Oe=>({value:Oe.key,title:Oe.label,description:Oe.description}))}),!L&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Choose an access level to continue."})]}):null,de=T.find(Oe=>Oe.oauthStrategy==="paperclip_cloud_connector"&&O_e(Oe.connectorProfile??"")),ve=de&&T.find(Oe=>gR(Oe)&&!Ep(Oe)),Te=A?.key===ve?.key,fe=(0,m.useId)(),Ce=de&&ve&&T.length===2?(0,t.jsx)(F,{type:"button",variant:"link",className:"h-auto p-0 text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground","aria-expanded":Te,"aria-controls":fe,disabled:N,onClick:r(()=>g(Te?de:ve),"onClick"),children:Te?"Use Paperclip instead":"Use your own Google OAuth app"}):T.length>1?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"How do you want to connect?"}),(0,t.jsx)(iu,{ariaLabel:`How to connect ${e.name}`,className:"mt-2",value:x,onValueChange:r(Oe=>{const tt=T.find(ce=>ce.key===Oe);tt&&g(tt)},"onValueChange"),options:T.map(Oe=>({value:Oe.key,title:Oe.label??(Oe.auth==="oauth"?`Sign in with ${e.name}`:"Use an API key")}))}),!A&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Choose a connection method to continue."})]}):null;if(Tk(e,A)){const Oe=LO(j),tt=!ae&&!!ne&&j.trim().length>0;return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[(0,t.jsxs)("div",{className:"space-y-6",children:[Ie,ne?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Share each sheet with this email"}),(0,t.jsxs)("div",{className:"mt-2 flex min-w-0 flex-col gap-2 sm:flex-row",children:[(0,t.jsx)("div",{title:ne,className:"min-h-11 min-w-0 flex-1 rounded-md border border-input bg-muted/40 px-3 py-2.5 font-mono text-xs leading-tight text-foreground break-all",children:ne}),(0,t.jsx)(cxe,{value:ne,ariaLabel:"Copy sharing email"})]}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"In Google Sheets, click Share and add this email as an Editor. Then paste the sheet links below."})]}):(0,t.jsx)("div",{className:"rounded-lg bg-muted/50 p-4 text-sm text-muted-foreground",children:"Google Sheets is not available on this instance yet."}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Paste links to the sheets you shared"}),(0,t.jsx)(An,{value:j,onChange:r(ce=>w(ce.target.value),"onChange"),placeholder:"https://docs.google.com/spreadsheets/d/...",className:"mt-2 min-h-28"}),(0,t.jsx)("div",{className:"mt-2 text-xs text-muted-foreground",children:Oe.ids.length>0?`${Oe.ids.length} ${Oe.ids.length===1?"sheet":"sheets"} ready to connect.`:"Paste one link per line. Both .../edit and .../edit#gid=... links work."}),S&&(0,t.jsx)("div",{className:"mt-2 text-xs text-destructive",children:S})]})]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!tt,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":"Connect"]})]})]})}const Xe=A?.consoleLinks?.docs??e.docsUrl;return(0,t.jsxs)("div",{className:"mx-auto max-w-xl",children:[Xe?(0,t.jsx)("div",{className:"mb-4 flex justify-end",children:(0,t.jsxs)("a",{href:Xe,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs font-medium text-muted-foreground underline underline-offset-2 hover:text-foreground",children:["Review requirements",(0,t.jsx)(eo,{className:"h-3 w-3"})]})}):null,(0,t.jsxs)("div",{className:"space-y-6",children:[Ie,Ce,K&&B&&p?(0,t.jsxs)("div",{className:"space-y-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Create or attach the connector in Vercel"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Paperclip does not copy Vercel’s setup forms. Finish connector setup there, then paste its UID below."}),(0,t.jsxs)("a",{href:p.manageUrl,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Open Vercel Connect",(0,t.jsx)(eo,{className:"h-3 w-3"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"vercel-connect-connector",children:"Connector UID or ID"}),(0,t.jsx)(Rt,{id:"vercel-connect-connector",value:u,onChange:r(Oe=>h(Oe.target.value),"onChange"),autoComplete:"off",placeholder:"service/my-connector or scl_…",className:"mt-2 h-11 font-mono"}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Paperclip validates the connector and stores only its reference and redacted verification metadata."})]})]}):null,s?(0,t.jsx)("div",{role:"alert",children:(0,t.jsx)(ri,{tone:"danger",children:s})}):null,X.map(Oe=>(0,t.jsx)(lJ,{field:Oe,value:v[Oe.key],onChange:r(tt=>y({...v,[Oe.key]:tt}),"onChange")},Oe.key)),he&&(0,t.jsxs)(el,{open:oe,onOpenChange:te,children:[(0,t.jsxs)(Ul,{className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground",children:[(0,t.jsx)(en,{className:U("h-4 w-4 transition-transform",oe&&"rotate-180")}),"Advanced"]}),(0,t.jsx)(tl,{className:"pt-4",children:(0,t.jsxs)("div",{className:"space-y-6",children:[le.map(Oe=>(0,t.jsx)(lJ,{field:Oe,value:v[Oe.key],onChange:r(tt=>y({...v,[Oe.key]:tt}),"onChange")},Oe.key)),me?(0,t.jsx)(oJ,{entry:e,method:A,callbackUrl:Y,clientId:i,onClientIdChange:o,clientSecret:l,onClientSecretChange:c,required:!1}):null]})})]}),!K&&A?.auth==="oauth"&&V?(0,t.jsx)("div",{id:fe,role:"region","aria-label":"Your OAuth app",children:(0,t.jsx)(oJ,{entry:e,method:A,callbackUrl:Y,clientId:i,onClientIdChange:o,clientSecret:l,onClientSecretChange:c,required:!0})}):null,K||!A||q.length===0?null:q.map(Oe=>(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:VY(e.name,Oe.label,q.length)}),(0,t.jsx)(Rt,{type:"password","aria-label":VY(e.name,Oe.label,q.length),autoComplete:"off",value:n[Oe.configPath]??"",onChange:r(tt=>a({...n,[Oe.configPath]:tt.target.value}),"onChange"),placeholder:"••••••••••••••••",className:"mt-2 h-11 font-mono"}),Oe.helpUrl&&(0,t.jsxs)("a",{href:Oe.helpUrl,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Where do I find this?",(0,t.jsx)(eo,{className:"h-3 w-3"})]})]},Oe.configPath))]}),(0,t.jsxs)("div",{className:"mt-8 flex items-center justify-between",children:[(0,t.jsx)(F,{variant:"ghost",onClick:_,disabled:N,children:"Back"}),(0,t.jsxs)(F,{onClick:I,disabled:N||!re||!z||!H||!Z||!J||!pe,children:[N&&(0,t.jsx)(ot,{className:"mr-2 h-4 w-4 animate-spin"}),N?"Checking…":K?A?.auth==="oauth"?"Validate and continue":"Validate and connect":A?.auth==="oauth"?e.slug==="github"?"Continue to GitHub":"Continue to sign in":"Connect"]})]})]})}r(NGe,"KeyStep");function cxe({value:e,ariaLabel:s}){const{copied:n,failed:a,copy:i}=nf();return(0,t.jsxs)(F,{type:"button",variant:"outline",className:"shrink-0","aria-label":s,onClick:r(()=>{i(e)},"onClick"),children:[n?(0,t.jsx)(xs,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(jr,{className:"mr-2 h-4 w-4"}),n?"Copied":a?"Copy failed":"Copy"]})}r(cxe,"CopyValueButton");function oJ({entry:e,method:s,callbackUrl:n,clientId:a,onClientIdChange:i,clientSecret:o,onClientSecretChange:l,required:c}){return(0,t.jsxs)("div",{className:"space-y-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:c?"Your OAuth app":"Use your own OAuth app"}),(0,t.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:["Register Paperclip's callback URI in ",e.name,", then enter the customer-owned client details."]}),s.consoleLinks?.register?(0,t.jsxs)("a",{href:s.consoleLinks.register,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex items-center gap-1 text-xs font-semibold text-foreground underline underline-offset-2",children:["Open ",e.name," app settings",(0,t.jsx)(eo,{className:"h-3 w-3"})]}):null]}),n?(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:"Paperclip callback URL"}),(0,t.jsxs)("div",{className:"mt-2 flex min-w-0 flex-col gap-2 sm:flex-row",children:[(0,t.jsx)("div",{title:n,className:"min-h-11 min-w-0 flex-1 rounded-md border border-input bg-muted/40 px-3 py-2.5 font-mono text-xs leading-tight text-foreground break-all",children:n}),(0,t.jsx)(cxe,{value:n,ariaLabel:"Copy callback URL"})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Add this exact URL to ",e.name," before continuing. It must match the authorization request."]})]}):null,(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"curated-oauth-client-id",children:"Client ID"}),(0,t.jsx)(Rt,{id:"curated-oauth-client-id",value:a,onChange:r(d=>i(d.target.value),"onChange"),autoComplete:"off",placeholder:c?"Required":"Optional",className:"mt-2 h-11 font-mono"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",htmlFor:"curated-oauth-client-secret",children:"Client secret"}),(0,t.jsx)(Rt,{id:"curated-oauth-client-secret",type:"password",value:o,onChange:r(d=>l(d.target.value),"onChange"),autoComplete:"off",placeholder:"Optional for public clients",className:"mt-2 h-11 font-mono"})]})]})}r(oJ,"OAuthClientFields");function lJ({field:e,value:s,onChange:n}){return e.type==="checkbox"?(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-border p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.label}),e.helperMd&&(0,t.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:e.helperMd})]}),(0,t.jsx)(Ei,{checked:s===!0,onCheckedChange:n})]}):(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-foreground",children:e.label}),e.type==="textarea"?(0,t.jsx)(An,{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),placeholder:e.placeholder,className:"mt-2 min-h-24"}):e.type==="select"?(0,t.jsxs)("select",{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),className:"mt-2 h-11 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30",children:[(0,t.jsx)("option",{value:"",disabled:!0,children:"Select an option"}),(e.options??[]).map(a=>(0,t.jsx)("option",{value:a.value,children:a.label},a.value))]}):(0,t.jsx)(Rt,{value:typeof s=="string"?s:"",onChange:r(a=>n(a.target.value),"onChange"),placeholder:e.placeholder,className:"mt-2 h-11"}),e.helperMd&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:e.helperMd})]})}r(lJ,"MethodConfigField");function dxe({companyId:e,...s}){const n=ee({queryKey:P.agents.list(e),queryFn:r(()=>Wt.list(e),"queryFn")});return(0,t.jsx)(uxe,{...s,agents:(n.data??[]).filter(a=>a.status!=="terminated"),agentsLoading:n.isLoading})}r(dxe,"AccessStep");function uxe({agents:e,agentsLoading:s=!1,authKind:n,grantKinds:a,grantKind:i,setGrantKind:o,installChoice:l,setInstallChoice:c,installAgentIds:d,setInstallAgentIds:u,lockedAgentId:h,capabilities:p,githubIdentity:x=!1,submitLabel:g,continuesToProvider:v=!1,identityLoading:y=!1,preserveAgentAccess:j=!1,pending:S=!1,onBack:w,onContinue:N}){const _=p?.editableAgentIds,I=_?e.filter(B=>_.includes(B.id)):e,C=p?.canSetCompanyInstall??!0,A=p?.canCreateOrganizationGrant??!0,R=n!=="none",E=a??["user","organization"],O=(!R||i==="user"||i==="agent"||A)&&(j?!0:h?d.has(h):i==="agent"?l==="specific"&&d.size===1:l==="all"?C:d.size>0),L=h?e.find(B=>B.id===h)?.name??"the requesting agent":null,$=x?"Connect GitHub as":"Which humans can use this credential?",T=i==="agent"?"Which agent owns this GitHub account?":x&&i==="user"?"Which agents may use your GitHub when you’re responsible?":x?"Which agents may use the shared GitHub account?":"Which agents can use this connection?",q=x?T:"Which agents can use this connection?";return(0,t.jsxs)("div",{className:"mx-auto max-w-2xl",children:[(0,t.jsx)("div",{className:"overflow-hidden rounded-xl border border-border",children:(0,t.jsxs)("div",{className:"divide-y divide-border",children:[(0,t.jsxs)("section",{className:"p-6",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:$}),x&&i==="agent"?(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This agent uses this GitHub account for everyone’s work, instead of the person giving instructions."}):null,y?(0,t.jsxs)("div",{className:"mt-4 grid gap-2 sm:grid-cols-2","aria-label":"Loading connection identity",children:[(0,t.jsx)(fn,{className:"h-20 w-full rounded-md"}),(0,t.jsx)(fn,{className:"h-20 w-full rounded-md"})]}):R&&E.length===1?(0,t.jsxs)("div",{className:"mt-4 flex items-center gap-3 rounded-md border border-border p-4",children:[E[0]==="user"?(0,t.jsx)(pu,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}):E[0]==="agent"?(0,t.jsx)(Xi,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}):(0,t.jsx)(gj,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:E[0]==="user"?x?"My GitHub account":"Just me":E[0]==="agent"?"A dedicated account for an agent":x?"Shared organization GitHub account (advanced)":"Any human in the organization"}),x?(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:E[0]==="user"?"Agents use it only for runs where you are the responsible person.":E[0]==="agent"?"That agent always uses this account, regardless of who starts the run.":"Eligible agents use one shared credential, regardless of who starts the run."}):null]})]}):R?(0,t.jsx)(iu,{ariaLabel:x?$:"Which humans can use this credential?",className:"mt-4 sm:grid-cols-2",value:i,onValueChange:r(B=>{const K=B;o(K),K==="agent"&&(c("specific"),d.size>1&&u(new Set([[...d][0]])))},"onValueChange"),options:[{value:"user",title:x?"My GitHub account":"Just me",description:x?"Agents use it only for runs where you are the responsible person.":void 0,icon:(0,t.jsx)(pu,{className:"h-4 w-4","aria-hidden":"true"})},{value:"agent",title:"A dedicated account for an agent",description:x?"That agent always uses this account, regardless of who starts the run.":void 0,icon:(0,t.jsx)(Xi,{className:"h-4 w-4","aria-hidden":"true"})},{value:"organization",title:x?"Shared organization GitHub account (advanced)":"Any human in the organization",description:x?"Eligible agents use one shared credential, regardless of who starts the run.":void 0,icon:(0,t.jsx)(gj,{className:"h-4 w-4","aria-hidden":"true"}),accessibleLabel:A?x?"Shared organization GitHub account (advanced)":"Any human in the organization":`${x?"Shared organization GitHub account (advanced)":"Any human in the organization"}. Unavailable: ${p?.organizationGrantReason??"Only a connection manager can share this credential with the organization."}`,tooltip:A?void 0:p?.organizationGrantReason??"Only a connection manager can share this credential with the organization.",disabled:!A}].filter(B=>E.includes(B.value))}):(0,t.jsx)("p",{className:"mt-4 text-sm text-muted-foreground",children:"No identity required"})]}),(0,t.jsxs)("section",{className:"p-6",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:T}),j?(0,t.jsxs)("div",{className:"mt-4 flex items-start gap-3 rounded-md border border-border bg-muted/40 p-4",children:[(0,t.jsx)(gj,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary","aria-hidden":"true"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Existing agent access stays the same"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Reconnecting replaces the credential without changing which agents can use it."})]})]}):h?(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["This task grants access only to ",(0,t.jsx)("span",{className:"font-medium text-foreground",children:L}),". Existing connection access is left unchanged."]}):i==="agent"?(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Choose exactly one agent. This identity cannot be shared with other agents."}):(0,t.jsx)(iu,{ariaLabel:q,className:"mt-4 sm:grid-cols-2",value:l,onValueChange:r(B=>c(B),"onValueChange"),options:[{value:"specific",title:x?"Only agents I choose":"Just agents I pick",description:x?i==="user"?"Only selected agents may use your GitHub when you’re responsible.":"Only selected agents may use the shared account.":void 0,icon:(0,t.jsx)(Xi,{className:"h-4 w-4","aria-hidden":"true"})},{value:"all",title:"Any agent",description:x?i==="user"?"Every agent may use your GitHub when you’re responsible.":"Every agent may use the shared account.":void 0,icon:(0,t.jsx)(kGe,{}),accessibleLabel:C?"Any agent":`Any agent. Unavailable: ${p?.companyInstallReason??"Only someone who can configure this connection can choose this."}`,tooltip:C?void 0:p?.companyInstallReason??"Only someone who can configure this connection can choose this.",disabled:!C}]}),!j&&!h&&l==="specific"?(0,t.jsx)("div",{className:"mt-3",children:(0,t.jsx)(_v,{agents:I,selectedAgentIds:d,onChange:r(B=>u(i==="agent"&&B.size>1?new Set([[...B].at(-1)]):B),"onChange"),loading:s,emptyMessage:"You cannot edit any agents yet.",showSelectionPreview:!1})}):null]})]})}),(0,t.jsxs)("div",{className:"mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,t.jsx)(F,{variant:"ghost",className:"w-full sm:w-auto",onClick:w,disabled:S,children:"Back"}),(0,t.jsxs)(F,{className:"w-full sm:w-auto",onClick:N,disabled:!O||y||S,children:[S?(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):null,g,!S&&v?(0,t.jsx)(eo,{className:"h-4 w-4","aria-hidden":"true"}):null]})]})]})}r(uxe,"AccessStepContent");function kGe(){return(0,t.jsxs)("span",{className:"relative block h-4 w-5","aria-hidden":"true",children:[(0,t.jsx)(Xi,{className:"absolute left-0 top-0 h-3.5 w-3.5"}),(0,t.jsx)(Xi,{className:"absolute bottom-0 right-0 h-3.5 w-3.5"})]})}r(kGe,"BotGroupIcon");function SGe(e){const s=e.authKind==="none"?"No identity required":e.grantKind==="user"?"Your identity":e.grantKind==="agent"?"Dedicated agent identity":"Organization identity",n=e.installChoice==="all"?"Any agent":`${e.installCount} selected ${e.installCount===1?"agent":"agents"}`;return[{label:"Identity",value:s},{label:"Available to",value:n},{label:"Actions",value:`${e.enabledCount} ${e.enabledCount===1?"action":"actions"} on`}]}r(SGe,"accessSummaryLines");function CGe({appName:e,logoUrl:s,darkLogoUrl:n,summary:a,onDone:i}){return(0,t.jsxs)("div",{className:"mx-auto max-w-md py-10 text-center",children:[(0,t.jsx)("div",{className:"mx-auto flex h-20 w-20 items-center justify-center rounded-full border-2 border-emerald-500 bg-emerald-500/10",children:(0,t.jsx)(xs,{className:"h-9 w-9 text-emerald-600 dark:text-emerald-400"})}),(0,t.jsxs)("div",{className:"mt-6 flex items-center justify-center gap-2",children:[(0,t.jsx)(bc,{name:e,logoUrl:s,darkLogoUrl:n,size:28}),(0,t.jsxs)("h2",{className:"text-2xl font-bold tracking-tight",children:[e," is ready."]})]}),(0,t.jsx)("dl",{className:"mx-auto mt-6 max-w-xs space-y-1 text-left",children:a.map(o=>(0,t.jsxs)("div",{className:"flex items-baseline justify-between gap-4",children:[(0,t.jsx)("dt",{className:"text-xs font-medium text-muted-foreground",children:o.label}),(0,t.jsx)("dd",{className:"text-sm text-foreground",children:o.value})]},o.label))}),(0,t.jsx)("div",{className:"mt-8",children:(0,t.jsx)(F,{size:"lg",className:"px-10",onClick:i,children:"View connection"})})]})}r(CGe,"ConnectionSetupCompletionScreen");function mxe(){const{newProjectOpen:e,closeNewProject:s}=a1(),{selectedCompanyId:n}=fs();return n&&e?(0,t.jsx)(_Ge,{companyId:n,onClose:s},n):null}r(mxe,"NewProjectDialog");function _Ge({companyId:e,onClose:s}){const n=Ht(),[a,i]=(0,m.useState)(""),[o,l]=(0,m.useState)([]),[c,d]=(0,m.useState)(!1),u=(0,m.useRef)(null),h=ye({mutationFn:r(()=>oa.create(e,{name:a.trim(),status:"planned",repositoryIds:o.map(p=>p.id)}),"mutationFn"),onSuccess:r(()=>{n.invalidateQueries({queryKey:P.projects.all(e)}),s()},"onSuccess")});return(0,t.jsx)(Xs,{open:!0,onOpenChange:r(p=>{!p&&!h.isPending&&s()},"onOpenChange"),children:(0,t.jsx)(Zs,{showCloseButton:!1,"aria-describedby":void 0,className:"flex max-h-(--sz-calc-18) flex-col gap-0 overflow-hidden p-0 shadow-sm sm:max-w-lg",onOpenAutoFocus:r(p=>{p.preventDefault(),u.current?.focus()},"onOpenAutoFocus"),children:c?(0,t.jsxs)("div",{className:"min-h-0 overflow-y-auto p-5",children:[(0,t.jsx)(rn,{className:"sr-only",children:"Connect GitHub"}),(0,t.jsx)(X5,{host:"dialog",serviceSlug:"github",forceNewConnection:!0,onCancel:r(()=>d(!1),"onCancel"),onComplete:r(()=>{n.invalidateQueries({queryKey:oU(e)}),d(!1)},"onComplete")})]}):(0,t.jsxs)("form",{className:"flex min-h-0 flex-col overflow-hidden",onSubmit:r(p=>{p.preventDefault(),a.trim()&&!h.isPending&&h.mutate()},"onSubmit"),children:[(0,t.jsxs)("div",{className:"flex shrink-0 flex-col gap-4 px-5 pb-4 pt-5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsx)(rn,{className:"text-lg font-semibold",children:"Create project"}),(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-sm",disabled:h.isPending,"aria-label":"Close new project",onClick:s,children:(0,t.jsx)(nr,{className:"size-4"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-input px-3 focus-within:border-ring focus-within:ring-1 focus-within:ring-ring",children:[(0,t.jsx)(qc,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,t.jsx)("input",{ref:u,"aria-label":"Project name",value:a,disabled:h.isPending,onChange:r(p=>i(p.target.value),"onChange"),placeholder:"Project name",required:!0,className:"h-10 w-full min-w-0 border-0 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm"})]})]}),(0,t.jsx)("div",{role:"region","aria-label":"Source repositories",tabIndex:0,className:"min-h-0 overflow-y-auto overscroll-contain px-5 pb-1 outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring",children:(0,t.jsx)(Pme,{companyId:e,selected:o,onChange:l,onConnect:r(()=>d(!0),"onConnect"),disabled:h.isPending})}),h.isError&&(0,t.jsx)("p",{role:"alert",className:"px-5 pt-3 text-sm text-destructive",children:h.error.message}),(0,t.jsxs)("div",{className:"flex shrink-0 justify-end gap-2 px-5 py-5",children:[(0,t.jsx)(F,{type:"button",variant:"ghost",disabled:h.isPending,onClick:s,children:"Cancel"}),(0,t.jsx)(F,{type:"submit",disabled:!a.trim()||h.isPending,children:h.isPending?"Creating…":"Create project"})]})]})})})}r(_Ge,"NewProjectForm");var ux={list:r(e=>Re.get(`/companies/${e}/goals`),"list"),get:r(e=>Re.get(`/goals/${e}`),"get"),create:r((e,s)=>Re.post(`/companies/${e}/goals`,s),"create"),update:r((e,s)=>Re.patch(`/goals/${e}`,s),"update"),remove:r(e=>Re.delete(`/goals/${e}`),"remove")};function hxe(e){return{"--sc":`var(${e})`}}r(hxe,"scStyle");function IGe(e){const s=e.replace(/_/g," ");return s.charAt(0).toUpperCase()+s.slice(1)}r(IGe,"sentenceCaseStatus");function ti({status:e,label:s}){return(0,t.jsx)("span",{className:U("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0",Q$[e]??"bg-muted text-muted-foreground"),children:s??e.replace(/[_-]/g," ")})}r(ti,"StatusBadge$5");function pxe({status:e}){const s=_2e[e]??"--status-agent-idle",n=e==="active"?"idle":e;return(0,t.jsx)("span",{className:"status-chip inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium leading-none whitespace-nowrap shrink-0",style:hxe(s),children:n.replace(/_/g," ")})}r(pxe,"AgentStatusBadge");function kp({status:e,externalConversationState:s}){const n=e==="in_review"&&s==="waiting"?"idle":e,a=w2e[n]??"--status-task-backlog";return(0,t.jsxs)("span",{className:U("status-chip inline-flex items-center gap-1.5 rounded-full border px-3 py-1 text-xs font-normal leading-none whitespace-nowrap shrink-0",n==="cancelled"&&"line-through"),style:hxe(a),children:[(0,t.jsx)(n1,{status:n,size:"sm"}),IGe(n)]})}r(kp,"IssueStatusBadge");var cJ={company:"Organization",team:"Team",agent:"Agent",task:"Task"};function fxe(){const{newGoalOpen:e,newGoalDefaults:s,closeNewGoal:n}=a1(),{selectedCompanyId:a,selectedCompany:i}=fs(),o=Ht(),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)("planned"),[x,g]=(0,m.useState)("task"),[v,y]=(0,m.useState)(""),[j,S]=(0,m.useState)(!1),[w,N]=(0,m.useState)(!1),[_,I]=(0,m.useState)(!1),[C,A]=(0,m.useState)(!1),R=(0,m.useRef)(null),E=v||s.parentId||"",{data:O}=ee({queryKey:P.goals.list(a),queryFn:r(()=>ux.list(a),"queryFn"),enabled:!!a&&e}),L=ye({mutationFn:r(z=>ux.create(a,z),"mutationFn"),onSuccess:r(()=>{o.invalidateQueries({queryKey:P.goals.list(a)}),T(),n()},"onSuccess")}),$=ye({mutationFn:r(async z=>{if(!a)throw new Error("No organization selected");return c0.uploadImage(a,z,"goals/drafts")},"mutationFn")});function T(){c(""),u(""),p("planned"),g("task"),y(""),S(!1)}r(T,"reset");function q(){!a||!l.trim()||L.mutate({title:l.trim(),description:d.trim()||void 0,status:h,level:x,...E?{parentId:E}:{}})}r(q,"handleSubmit");function B(z){z.key==="Enter"&&(z.metaKey||z.ctrlKey)&&(z.preventDefault(),q())}r(B,"handleKeyDown");const K=(O??[]).find(z=>z.id===E);return(0,t.jsx)(Xs,{open:e,onOpenChange:r(z=>{z||(T(),n())},"onOpenChange"),children:(0,t.jsxs)(Zs,{showCloseButton:!1,className:U("p-0 gap-0",j?"sm:max-w-2xl":"sm:max-w-lg"),onKeyDown:B,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[i&&(0,t.jsx)("span",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-medium",children:i.issuePrefix}),(0,t.jsx)("span",{className:"text-muted-foreground/60",children:"›"}),(0,t.jsx)("span",{children:s.parentId?"New sub-goal":"New goal"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:r(()=>S(!j),"onClick"),children:j?(0,t.jsx)(vz,{className:"h-3.5 w-3.5"}):(0,t.jsx)(a0,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:r(()=>{T(),n()},"onClick"),children:(0,t.jsx)("span",{className:"text-lg leading-none",children:"×"})})]})]}),(0,t.jsx)("div",{className:"px-4 pt-4 pb-2 shrink-0",children:(0,t.jsx)("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Goal title",value:l,onChange:r(z=>c(z.target.value),"onChange"),onKeyDown:r(z=>{z.key==="Tab"&&!z.shiftKey&&(z.preventDefault(),R.current?.focus())},"onKeyDown"),autoFocus:!0})}),(0,t.jsx)("div",{className:"px-4 pb-2 overflow-y-auto max-h-(--sz-50vh)",children:(0,t.jsx)(yc,{ref:R,value:d,onChange:u,placeholder:"Add description...",bordered:!1,contentClassName:U("text-sm text-muted-foreground",j?"min-h-(--sz-220px)":"min-h-(--sz-120px)"),imageUploadHandler:r(async z=>(await $.mutateAsync(z)).contentPath,"imageUploadHandler")})}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[(0,t.jsxs)(sr,{open:w,onOpenChange:N,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsx)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:(0,t.jsx)(ti,{status:h})})}),(0,t.jsx)(Gn,{className:"w-40 p-1",align:"start",children:Zoe.map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 capitalize",z===h&&"bg-accent"),onClick:r(()=>{p(z),N(!1)},"onClick"),children:z},z))})]}),(0,t.jsxs)(sr,{open:_,onOpenChange:I,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[(0,t.jsx)(hl,{className:"h-3 w-3 text-muted-foreground"}),cJ[x]??x]})}),(0,t.jsx)(Gn,{className:"w-40 p-1",align:"start",children:Hoe.map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",z===x&&"bg-accent"),onClick:r(()=>{g(z),I(!1)},"onClick"),children:cJ[z]??z},z))})]}),(0,t.jsxs)(sr,{open:C,onOpenChange:A,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[(0,t.jsx)(px,{className:"h-3 w-3 text-muted-foreground"}),K?K.title:"Parent goal"]})}),(0,t.jsxs)(Gn,{className:"w-48 p-1",align:"start",children:[(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!E&&"bg-accent"),onClick:r(()=>{y(""),A(!1)},"onClick"),children:"No parent"}),(O??[]).map(z=>(0,t.jsx)("button",{className:U("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",z.id===E&&"bg-accent"),onClick:r(()=>{y(z.id),A(!1)},"onClick"),children:z.title},z.id))]})]})]}),(0,t.jsx)("div",{className:"flex items-center justify-end px-4 py-2.5 border-t border-border",children:(0,t.jsx)(F,{size:"sm",disabled:!l.trim()||L.isPending,onClick:q,children:L.isPending?"Creating…":s.parentId?"Create sub-goal":"Create goal"})})]})})}r(fxe,"NewGoalDialog");function AGe(e){const s=RGe(e),n=TGe(e);return`You're invited to join a Paperclip company as an agent.
288
288
 
289
289
  First, respond to your user that you understand the request and are going to onboard into Paperclip. Then work through the steps below.
290
290
 
@@ -333,7 +333,7 @@ After you have connected to Paperclip, review and follow the full onboarding ins
333
333
  `}r(AGe,"buildAgentOnboardingPrompt");function RGe(e){const s=(e.connectionCandidates??[]).map(o=>o.trim()).filter(Boolean),n=new Set;let a=null;try{a=new URL(e.onboardingTextUrl),n.add(a.toString())}catch{const o=e.onboardingTextUrl.trim();o&&n.add(o)}if(!a){for(const o of s)n.add(o);return Array.from(n)}const i=`${a.pathname}${a.search}`;for(const o of s)try{const l=new URL(o);n.add(`${l.origin}${i}`)}catch{n.add(o)}return Array.from(n)}r(RGe,"buildCandidateOnboardingUrls");function TGe(e){const s=e.testResolutionUrl?.trim();if(s)return s;try{const n=new URL(e.onboardingTextUrl),a=n.pathname.replace(/\/onboarding\.txt$/,"/test-resolution");return`${n.origin}${a}`}catch{return null}}r(TGe,"buildResolutionTestUrl");function EGe({companyId:e,onClose:s,onBack:n}){const a=Ht(),i=(0,m.useRef)(!0);(0,m.useEffect)(()=>(i.current=!0,()=>{i.current=!1}),[]);const[o,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(null),[u,h]=(0,m.useState)(!1),[p,x]=(0,m.useState)(!1);async function g(y){try{await Gr(y),i.current&&(h(!0),x(!1))}catch{i.current&&x(!0)}}r(g,"copy");const v=ye({mutationFn:r(async()=>{const y=await fr.createCompanyInvite(e,{allowedJoinTypes:"agent",humanRole:null,agentMessage:o.trim()||null});a.invalidateQueries({queryKey:P.access.invites(e,"all",5)});const j=y.onboardingTextUrl??y.onboardingTextPath??`/api/invites/${y.token}/onboarding.txt`,S=new URL(j,window.location.origin).href,w=await fr.getInviteOnboarding(y.token).catch(()=>null);return AGe({onboardingTextUrl:S,connectionCandidates:w?.onboarding.connectivity?.connectionCandidates??null,testResolutionUrl:w?.onboarding.connectivity?.testResolutionEndpoint?.url??null})},"mutationFn"),onSuccess:r(async y=>{i.current&&(d(y),await g(y))},"onSuccess")});return(0,t.jsx)(Xs,{open:!0,onOpenChange:r(y=>{y||s()},"onOpenChange"),children:(0,t.jsxs)(Zs,{className:"max-h-(--sz-calc-16) overflow-y-auto sm:max-w-2xl",children:[(0,t.jsx)(rn,{children:c?"Agent onboarding prompt":"Invite an external agent"}),(0,t.jsx)(Dn,{children:c?"Send this one-time prompt to the agent that should join your organization.":"Generate a one-time onboarding prompt for an external agent. An organization admin must approve its join request before it can claim an API key."}),c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(An,{"aria-label":"Agent onboarding prompt",readOnly:!0,value:c,className:"min-h-64 font-mono text-xs"}),p&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:"Clipboard unavailable. Copy the prompt manually from the field above."}),(0,t.jsxs)("div",{className:"flex justify-between gap-4",children:[(0,t.jsx)(F,{variant:"ghost",onClick:s,children:"Done"}),(0,t.jsx)(F,{variant:"outline",onClick:r(()=>{g(c)},"onClick"),children:u?"Copied prompt":"Copy prompt"})]})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("label",{className:"space-y-2 text-sm",children:[(0,t.jsx)("span",{children:"Optional message for the agent"}),(0,t.jsx)(An,{value:o,onChange:r(y=>l(y.target.value),"onChange"),maxLength:4e3,className:"min-h-24"})]}),v.error&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:v.error.message}),(0,t.jsxs)("div",{className:"flex justify-between gap-4",children:[(0,t.jsx)(F,{variant:"ghost",onClick:n,children:"Back"}),(0,t.jsx)(F,{disabled:v.isPending,onClick:r(()=>v.mutate(),"onClick"),children:v.isPending?"Generating…":"Generate onboarding prompt"})]})]})]})})}r(EGe,"ExternalAgentInviteDialog");function xxe(){const{newAgentOpen:e,closeNewAgent:s}=a1(),{selectedCompanyId:n}=fs();return e?(0,t.jsx)(PGe,{companyId:n,onClose:s},n):null}r(xxe,"NewAgentDialog");function PGe({companyId:e,onClose:s}){const n=Wn(),[a,i]=(0,m.useState)(!1);return a&&e?(0,t.jsx)(EGe,{companyId:e,onClose:s,onBack:r(()=>i(!1),"onBack")}):(0,t.jsx)(Jfe,{open:!0,onClose:s,onInvite:e?()=>i(!0):void 0,onContinue:r(o=>{s(),n(`/agents/new?${new URLSearchParams(o)}`)},"onContinue")})}r(PGe,"NewAgentDialogContent");var MGe=[{title:"Inbox",shortcuts:[{keys:["j"],label:"Move down"},{keys:["↓"],label:"Move down"},{keys:["k"],label:"Move up"},{keys:["↑"],label:"Move up"},{keys:["←"],label:"Collapse selected group"},{keys:["→"],label:"Expand selected group"},{keys:["Enter"],label:"Open selected item"},{keys:["a"],label:"Archive item"},{keys:["y"],label:"Archive item"},{keys:["r"],label:"Mark as read"},{keys:["U"],label:"Mark as unread"}]},{title:"Task detail",shortcuts:[{keys:["y"],label:"Quick-archive back to inbox"},{keys:["g","i"],label:"Go to inbox"},{keys:["g","c"],label:"Focus comment composer"}]},{title:"Decisions",shortcuts:[{keys:["j"],label:"Move down"},{keys:["↓"],label:"Move down"},{keys:["k"],label:"Move up"},{keys:["↑"],label:"Move up"},{keys:["Enter"],label:"Open or close selected decision"},{keys:["x"],label:"Dismiss selected decision"}]},{title:"Global",shortcuts:[{keys:["/"],label:"Search current page or quick search"},{keys:["c"],label:"New task"},{keys:["["],label:"Toggle sidebar"},{keys:["]"],label:"Toggle panel"},{keys:["?"],label:"Show keyboard shortcuts"}]}];function dJ({children:e}){return(0,t.jsx)("kbd",{className:"inline-flex h-6 min-w-6 items-center justify-center rounded border border-border bg-muted px-1.5 font-mono text-xs font-medium text-foreground shadow-(--shadow-extract-10)",children:e})}r(dJ,"KeyCap");function DGe(){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"divide-y divide-border border-t border-border",children:MGe.map(e=>(0,t.jsxs)("div",{className:"px-5 py-3",children:[(0,t.jsx)("h3",{className:"mb-2 text-(length:--text-micro) font-semibold uppercase tracking-wider text-muted-foreground",children:e.title}),(0,t.jsx)("div",{className:"space-y-1.5",children:e.shortcuts.map(s=>(0,t.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,t.jsx)("span",{className:"text-sm text-foreground/90",children:s.label}),(0,t.jsx)("div",{className:"flex items-center gap-1",children:s.keys.map((n,a)=>(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[a>0&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:s.combo?"+":"then"}),(0,t.jsx)(dJ,{children:n})]},n))})]},s.label+s.keys.join()))})]},e.title))}),(0,t.jsx)("div",{className:"border-t border-border px-5 py-3",children:(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Press ",(0,t.jsx)(dJ,{children:"Esc"})," to close · Shortcuts are disabled in text fields"]})})]})}r(DGe,"KeyboardShortcutsCheatsheetContent");function gxe({open:e,onOpenChange:s}){return(0,t.jsx)(Xs,{open:e,onOpenChange:s,children:(0,t.jsxs)(Zs,{className:"sm:max-w-md gap-0 p-0 overflow-hidden",showCloseButton:!1,children:[(0,t.jsx)(Sn,{className:"px-5 pt-5 pb-3",children:(0,t.jsx)(rn,{className:"text-base",children:"Keyboard shortcuts"})}),(0,t.jsx)(DGe,{})]})})}r(gxe,"KeyboardShortcutsCheatsheet");var LGe={info:"border-sky-300 bg-sky-50 text-sky-900 dark:border-sky-500/25 dark:bg-sky-950/60 dark:text-sky-100",success:"border-emerald-300 bg-emerald-50 text-emerald-900 dark:border-emerald-500/25 dark:bg-emerald-950/60 dark:text-emerald-100",warn:"border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-500/25 dark:bg-amber-950/60 dark:text-amber-100",error:"border-red-300 bg-red-50 text-red-900 dark:border-red-500/30 dark:bg-red-950/60 dark:text-red-100"},$Ge={info:"bg-sky-500 dark:bg-sky-400",success:"bg-emerald-500 dark:bg-emerald-400",warn:"bg-amber-500 dark:bg-amber-400",error:"bg-red-500 dark:bg-red-400"};function OGe({toast:e,onDismiss:s}){const[n,a]=(0,m.useState)(!1);return(0,m.useEffect)(()=>{const i=requestAnimationFrame(()=>a(!0));return()=>cancelAnimationFrame(i)},[]),(0,t.jsx)("li",{className:U("pointer-events-auto rounded-sm border shadow-lg backdrop-blur-xl transition-(--tp-transform-opacity) duration-200 ease-out",n?"translate-y-0 opacity-100":"translate-y-3 opacity-0",LGe[e.tone]),children:(0,t.jsxs)("div",{className:"flex items-start gap-3 px-3 py-2.5",children:[(0,t.jsx)("span",{className:U("mt-1 h-2 w-2 shrink-0 rounded-full",$Ge[e.tone])}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("p",{className:"text-sm font-semibold leading-5",children:e.title}),e.body&&(0,t.jsx)("p",{className:"mt-1 text-xs leading-4 opacity-70",children:e.body}),e.action&&(e.action.onClick?(0,t.jsx)("button",{type:"button",onClick:r(()=>{e.action?.onClick?.(),s(e.id)},"onClick"),className:"mt-2 inline-flex text-xs font-medium underline underline-offset-4 hover:opacity-90",children:e.action.label}):e.action.href?(0,t.jsx)(Qe,{to:e.action.href,onClick:r(()=>s(e.id),"onClick"),className:"mt-2 inline-flex text-xs font-medium underline underline-offset-4 hover:opacity-90",children:e.action.label}):null)]}),(0,t.jsx)("button",{type:"button","aria-label":"Dismiss notification",onClick:r(()=>s(e.id),"onClick"),className:"mt-0.5 shrink-0 rounded p-1 opacity-50 hover:bg-black/10 hover:opacity-100 dark:hover:bg-white/10",children:(0,t.jsx)(nr,{className:"h-3.5 w-3.5"})})]})})}r(OGe,"AnimatedToast");function bxe(){const e=Ude(),{dismissToast:s}=ua();return e.length===0?null:(0,t.jsx)("aside",{"aria-live":"polite","aria-atomic":"false",className:"pointer-events-none fixed bottom-3 left-3 z-(--z-120) w-full max-w-sm px-1",children:(0,t.jsx)("ol",{className:"flex w-full flex-col-reverse gap-2",children:e.map(n=>(0,t.jsx)(OGe,{toast:n,onDismiss:s},n.id))})})}r(bxe,"ToastViewport");async function uJ(e,s){const n=await fetch(`/api/announcements/${e}`,{credentials:"same-origin",cache:"no-store",...s});if(!n.ok)throw new Nn("Announcement request failed",n.status,null);return n}r(uJ,"request");var mJ={async current(e){const s=await(await uJ("current",{signal:e})).json();return s===null?null:mIe.parse(s)},async dismiss(e,s,n){await uJ(`${encodeURIComponent(e)}/dismiss`,{method:"POST",signal:n,headers:{"Content-Type":"application/json"},body:JSON.stringify({companyId:s})})}},EF=new Map;function iK(e){return`paperclip.announcement-dismissals.v1:${encodeURIComponent(e)}:`}r(iK,"announcementStoragePrefix");function uI(e){const s=iK(e),n=new Map;try{for(let a=0;a<localStorage.length;a++){const i=localStorage.key(a);if(!i?.startsWith(s))continue;const o=i.slice(s.length),l=localStorage.getItem(i);lle.safeParse(o).success&&(l==="pending"||l==="synced")&&EF.set(i,l==="pending")}}catch{}for(const[a,i]of EF)a.startsWith(s)&&n.set(a.slice(s.length),i);return n}r(uI,"readAnnouncementDismissals");function L4(e,s,n){const a=`${iK(e)}${s}`;EF.set(a,n);try{return localStorage.setItem(a,n?"pending":"synced"),!0}catch{return!1}}r(L4,"saveAnnouncementDismissal");var FGe=3e3;function BGe(e){const{userId:s,enabled:n}=e,a=(0,m.useRef)(e);a.current=e;const[i,o]=(0,m.useState)(null),l=(0,m.useRef)(()=>{});(0,m.useEffect)(()=>{if(o(null),!s||!n)return;let d=!1,u=0,h=null,p;const x=new Map,g=new Set,v=iK(s);let y=null;try{y=new BroadcastChannel(v)}catch{}const j=r(()=>!d&&a.current.userId===s&&a.current.enabled,"active");async function S(E,O=!0){if(!j()||x.has(E)||!a.current.companyId)return;const L=new AbortController;x.set(E,L);const $=setTimeout(()=>L.abort(),1e4);try{await mJ.dismiss(E,a.current.companyId,L.signal),j()&&L4(s,E,!1)}catch{j()&&!g.has(E)&&(g.add(E),a.current.onSaveFailure(O))}finally{clearTimeout($),x.delete(E)}}r(S,"sync");async function w(){for(const[E,O]of uI(s)){if(!j())return;O&&await S(E)}}r(w,"flush");function N(){u++,clearTimeout(p),h?.abort(),h=null,o(null)}r(N,"suspend");function _(){if(!j()||document.visibilityState==="hidden")return;N();const E=u,O=new AbortController;h=O;const L=r(()=>j()&&u===E&&!O.signal.aborted,"stillCurrent");let $=!1,T=!1,q=null;const B=r(()=>{!L()||!$||!T||q&&!uI(s).has(q.id)&&(!q.expiresAt||Date.parse(q.expiresAt)>Date.now())&&o({userId:s,announcement:q})},"show");p=setTimeout(()=>{$=!0,B()},FGe),w(),mJ.current(O.signal).then(K=>{q=K,T=!0,B()}).catch(()=>{})}r(_,"resume");function I(){const E=uI(s);o(O=>O?.userId===s&&E.has(O.announcement.id)?null:O)}r(I,"receive");function C(E){E.key?.startsWith(v)&&I()}r(C,"onStorage");function A(){document.visibilityState==="hidden"?N():_()}r(A,"onVisibility");function R(){w()}return r(R,"onOnline"),y&&(y.onmessage=E=>{const O=lle.safeParse(E.data);O.success&&(uI(s).has(O.data)||L4(s,O.data,!0),I())}),l.current=E=>{if(!j())return;const O=L4(s,E,!0);o(null),u++,h?.abort();try{y?.postMessage(E)}catch{}S(E,O)},document.addEventListener("visibilitychange",A),window.addEventListener("online",R),window.addEventListener("storage",C),_(),()=>{d=!0,u++,clearTimeout(p),h?.abort();for(const E of x.values())E.abort();y?.close(),document.removeEventListener("visibilitychange",A),window.removeEventListener("online",R),window.removeEventListener("storage",C),l.current=()=>{}}},[s,n]);const c=n&&i?.userId===s?i.announcement:null;return(0,m.useEffect)(()=>{if(!c?.expiresAt)return;let d;const u=r(()=>{const h=Date.parse(c.expiresAt)-Date.now();h<=0?o(null):d=setTimeout(u,Math.min(h,2147483647))},"check");return u(),()=>clearTimeout(d)},[c]),{announcement:c,dismiss:(0,m.useCallback)(d=>l.current(d),[])}}r(BGe,"useAnnouncement");function qGe(e,s){const n=x2e(),a=s??`/api/announcements/${encodeURIComponent(e.id)}/animation`,i=`${a}:${e.animation?.path??""}`,[o,l]=(0,m.useState)(null),c=!!e.animation&&!n;return(0,m.useEffect)(()=>{if(!c)return;const d=new AbortController,u=setTimeout(()=>d.abort(),5e3);return(async()=>{try{const h=await fetch(a,{credentials:"same-origin",cache:"no-store",redirect:"error",referrerPolicy:"no-referrer",signal:d.signal});if(!h.ok||h.headers.get("content-type")?.split(";")[0]!=="text/html")return;const p=await h.text();d.signal.aborted||l({key:i,document:`<meta http-equiv="Content-Security-Policy" content="${p_e}">${p}`})}catch{}finally{clearTimeout(u)}})(),()=>{d.abort(),clearTimeout(u)}},[c,i,a]),c&&o?.key===i?o.document:null}r(qGe,"useAnnouncementAnimation");function hJ({action:e,primary:s,onClick:n}){const a=(0,t.jsxs)(t.Fragment,{children:[e.label,!s&&e.kind==="external"&&(0,t.jsx)(eo,{className:"size-3.5 shrink-0","aria-hidden":"true"})]}),i=r(o=>{o.button===1&&n()},"onAuxClick");return(0,t.jsx)(F,{asChild:!0,variant:s?"default":"ghost",size:"sm",className:"h-auto min-h-9 min-w-0 whitespace-normal py-2 text-left",children:e.kind==="external"?(0,t.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:n,onAuxClick:i,children:a}):(0,t.jsx)(Qe,{to:e.path,onClick:n,onAuxClick:i,children:a})})}r(hJ,"Action");function S2({announcement:e,onDismiss:s,imageSrc:n,animationSrc:a,className:i}){const o=(0,m.useId)(),[l,c]=(0,m.useState)(null),d=n??`/api/announcements/${encodeURIComponent(e.id)}/image`,u=!!(e.image&&l!==d),h=qGe(e,a),p=!!h;return(0,t.jsxs)(Gs,{role:"region","aria-labelledby":o,className:U("relative w-full max-w-(--announcement-width) gap-0 overflow-hidden rounded-xl p-0 shadow-sm",i),onKeyDown:r(x=>{x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),s())},"onKeyDown"),children:[(u||h)&&(0,t.jsxs)("div",{className:"relative h-(--announcement-image-mobile-height) w-full shrink-0 overflow-hidden bg-muted md:h-(--announcement-image-height)",children:[u&&(0,t.jsx)("img",{src:d,alt:p?"":e.image.alt,referrerPolicy:"no-referrer",onError:r(()=>c(d),"onError"),className:"h-full w-full object-cover"}),p&&(0,t.jsx)("div",{role:"img","aria-label":e.animation.alt,className:"pointer-events-none absolute inset-0",children:(0,t.jsx)("iframe",{title:e.animation.alt,"aria-hidden":"true",tabIndex:-1,sandbox:"",referrerPolicy:"no-referrer",srcDoc:h,className:"h-full w-full border-0"})})]}),(0,t.jsx)(F,{variant:"secondary",size:"icon","aria-label":"Dismiss announcement",onClick:s,className:"absolute right-2 top-2 z-10 size-8 rounded-full shadow-sm",children:(0,t.jsx)(nr,{className:"size-4","aria-hidden":"true"})}),(0,t.jsxs)("div",{className:U("flex flex-col gap-1 px-4 py-4",!u&&!h&&"pr-12"),children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e.eyebrow}),(0,t.jsx)("h2",{id:o,className:"break-words text-base font-semibold leading-snug",children:e.title}),(0,t.jsx)("p",{className:"break-words text-sm leading-snug text-muted-foreground",children:e.description})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2",children:[e.secondaryLink&&(0,t.jsx)(hJ,{action:e.secondaryLink,onClick:s}),(0,t.jsx)("div",{className:"ml-auto min-w-0 max-w-full",children:(0,t.jsx)(hJ,{action:e.primaryAction,primary:!0,onClick:s})})]})]})}r(S2,"AnnouncementCard");var zGe='[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"], [aria-modal="true"]:not([data-state="closed"]), dialog[open]';function UGe(e){const[s,n]=(0,m.useState)(!1);return(0,m.useEffect)(()=>{if(!e)return;const a=r(()=>n(!!document.querySelector(zGe)),"scan");a();const i=new MutationObserver(a);return i.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-state","aria-modal","open"]}),()=>i.disconnect()},[e]),s}r(UGe,"useModalOpen");function KGe({health:e}){const{userId:s,settled:n}=G3(),{selectedCompanyId:a,loading:i}=fs(),{onboardingOpen:o}=c5(),l=Nc(),c=q4e(),d=e?.deploymentMode==="local_trusted"?"local-board":n?s:null,{announcement:u,dismiss:h}=BGe({userId:d,companyId:a,enabled:!!(d&&!i&&a&&!o),onSaveFailure:r(x=>l?.pushToast({title:x?"Dismissed in this browser":"Dismissed for this visit",body:"Couldn’t save across devices. We’ll retry when you reconnect or return.",tone:"info",dedupeKey:"announcement-dismissal-sync"}),"onSaveFailure")}),p=UGe(!!u);return!u||p||(c?.length??0)>0?null:(0,t.jsx)("aside",{"aria-label":"Paperclip announcements",className:"announcement-well fixed left-3 bottom-(--announcement-mobile-bottom) z-40 w-(--announcement-available-width) max-w-(--announcement-width) max-h-(--announcement-mobile-max-height) overflow-y-auto md:bottom-3 md:max-h-(--announcement-max-height)",children:(0,t.jsx)(S2,{announcement:u,onDismiss:r(()=>h(u.id),"onDismiss")},u.id)})}r(KGe,"AnnouncementWell");function Z5(e){const s=e.split("/").filter(Boolean);return s.length===1?s[0]?.toLowerCase()==="onboarding":s.length===2?s[1]?.toLowerCase()==="onboarding":!1}r(Z5,"isOnboardingPath");function VGe(e){const s=e.split("/").filter(Boolean);if(s.length===2&&s[1]?.toLowerCase()==="onboarding")return s[0]}r(VGe,"companyPrefixFromOnboardingPath");function RT(){return 3}r(RT,"onboardingStepForCompany");function WGe(e){const{pathname:s,companyPrefix:n,companies:a,cloudManaged:i}=e;if(!Z5(s))return null;const o=r(()=>a.length===1?{initialStep:RT(),companyId:a[0].id}:null,"managedFallback");if(!n)return i?o():{initialStep:1};const l=a.find(c=>c.issuePrefix.toUpperCase()===n.toUpperCase())??null;return l?{initialStep:RT(),companyId:l.id}:i?o():{initialStep:1}}r(WGe,"resolveRouteOnboardingOptions");function HGe(e){return!e.agentsLoaded||e.agentsRefreshing||e.agentCount>0?!1:!Z5(e.pathname)}r(HGe,"shouldRouteAgentlessCompanyToOnboarding");function QGe(e){return e.currentStep>1&&e.currentStep>e.entryStep}r(QGe,"canGoBackFromOnboardingStep");function pJ(e){return e.targetStep<e.currentStep&&e.targetStep>=e.entryStep}r(pJ,"canJumpToOnboardingStep");function oK(e){return!e.hasCompanies&&!Z5(e.pathname)}r(oK,"shouldRedirectCompanylessRouteToOnboarding");function GGe(e){return e.onboardingOpen||!e.routeDismissed}r(GGe,"isOnboardingWizardActive");function YGe({context:e}){const{slots:s,errorMessage:n}=Kc({slotTypes:["appShellOverlay"],companyId:e.companyId});return n||s.length===0?null:(0,t.jsx)("aside",{className:"plugin-app-shell-overlays","aria-label":"Application extensions",children:s.map(a=>(0,t.jsx)(fu,{slot:a,context:e,className:"plugin-app-shell-overlay"},`${a.pluginId}:${a.pluginVersion}:${a.id}`))})}r(YGe,"AppShellEntries");function vxe({localTrusted:e=!1}){const{userId:s,settled:n}=G3(),{selectedCompanyId:a,selectedCompany:i,loading:o}=fs(),{onboardingOpen:l,onboardingRouteDismissed:c}=c5(),{pathname:d}=Zr(),u=n?s??(e?"local-board":null):null,h=l||!c&&Z5(d);if(!u||o||h)return null;const p={companyId:a,companyPrefix:i?.issuePrefix??null,projectId:null,entityId:null,entityType:null,parentEntityId:null,userId:s};return(0,t.jsx)(YGe,{context:p},JSON.stringify([u,a]))}r(vxe,"PluginAppShellOverlays");function yxe({visible:e}){const s=Zr(),{selectedCompanyId:n}=fs(),{openNewIssue:a}=Lo(),i=Hz(n),o=(0,m.useMemo)(()=>[{type:"link",to:"/dashboard",label:"Home",icon:ide},{type:"link",to:"/issues",label:"Tasks",icon:la},{type:"action",label:"New Task",icon:h1,onClick:r(()=>a(),"onClick")},{type:"link",to:"/agents/all",label:"Agents",icon:Xo},{type:"link",to:"/inbox",label:"Inbox",icon:Td,badge:i.inbox}],[a,i.inbox]);return(0,t.jsx)("nav",{className:U("fixed bottom-0 left-0 right-0 z-30 bg-border/50 transition-transform duration-200 ease-out dark:bg-muted md:hidden pb-(--sz-safe-bottom)",e?"translate-y-0":"translate-y-full"),"aria-label":"Mobile navigation",children:(0,t.jsx)("div",{className:"grid h-16 grid-cols-5 px-1",children:o.map(l=>{if(l.type==="action"){const d=l.icon,u=/\/issues\/new(?:\/|$)/.test(s.pathname);return(0,t.jsxs)("button",{type:"button",onClick:l.onClick,className:U("relative flex min-w-0 flex-col items-center justify-center gap-1 rounded-md text-(length:--text-nano) font-medium transition-colors",u?"text-foreground":"text-muted-foreground hover:text-foreground"),children:[(0,t.jsx)(d,{className:"h-(--sz-18px) w-(--sz-18px)"}),(0,t.jsx)("span",{className:"truncate",children:l.label})]},l.label)}const c=l.icon;return(0,t.jsx)(r0,{to:l.to,state:lf,className:r(({isActive:d})=>U("relative flex min-w-0 flex-col items-center justify-center gap-1 rounded-md text-(length:--text-nano) font-medium transition-colors",d?"text-foreground":"text-muted-foreground hover:text-foreground"),"className"),children:r(({isActive:d})=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"relative",children:[(0,t.jsx)(c,{className:U("h-(--sz-18px) w-(--sz-18px)",d&&"stroke-(length:--sw-2_3)")}),l.badge!=null&&l.badge>0&&(0,t.jsx)(dt,{variant:"ghost",className:"absolute -right-2 -top-2 bg-primary px-1.5 text-(length:--text-nano) leading-none text-primary-foreground",children:l.badge>99?"99+":l.badge})]}),(0,t.jsx)("span",{className:"truncate",children:l.label})]}),"children")},l.label)})})})}r(yxe,"MobileBottomNav");function nj(e){if(typeof document>"u")return null;const s=document.querySelector(`meta[name="${e}"]`)?.getAttribute("content")?.trim();return s||null}r(nj,"readMetaContent");function PF(e){if(!e)return null;const s=e.startsWith("#")?e.slice(1):e;return/^[0-9a-fA-F]{3}$/.test(s)?`#${s.split("").map(n=>`${n}${n}`).join("").toLowerCase()}`:/^[0-9a-fA-F]{6}$/.test(s)?`#${s.toLowerCase()}`:null}r(PF,"normalizeHexColor");function JGe(e){const s=PF(e)??"#000000";return{r:Number.parseInt(s.slice(1,3),16),g:Number.parseInt(s.slice(3,5),16),b:Number.parseInt(s.slice(5,7),16)}}r(JGe,"hexToRgb");function $4(e){const s=e/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4}r($4,"relativeLuminanceChannel");function XGe(e){const{r:s,g:n,b:a}=JGe(e),i=.2126*$4(s)+.7152*$4(n)+.0722*$4(a);return 1.05/(i+.05)>=(i+.05)/.05?VAe:UAe}r(XGe,"pickReadableTextColor");function ZGe(){return nj("paperclip-worktree-enabled")==="true"}r(ZGe,"isWorktreeRuntime");function eYe(){return nj("paperclip-instance-id")}r(eYe,"getWorktreeInstanceId");function tYe(){if(nj("paperclip-worktree-enabled")!=="true")return null;const e=nj("paperclip-worktree-name"),s=PF(nj("paperclip-worktree-color"));return!e||!s?null:{enabled:!0,name:e,color:s,textColor:PF(nj("paperclip-worktree-text-color"))??XGe(s)}}r(tYe,"getWorktreeUiBranding");function jxe(){const e=tYe(),{copied:s,failed:n,copy:a}=nf(),i=(0,m.useCallback)(()=>{e&&a(e.name)},[e,a]);return e?(0,t.jsx)("div",{className:"relative overflow-hidden border-b px-3 py-1.5 text-(length:--text-micro) font-medium tracking-(--tracking-caps) uppercase",style:{backgroundColor:e.color,color:e.textColor,borderColor:`${e.textColor}22`,boxShadow:`inset 0 -1px 0 ${e.textColor}18`,backgroundImage:`linear-gradient(90deg, ${e.textColor}14, transparent 28%, transparent 72%, ${e.textColor}12), repeating-linear-gradient(135deg, transparent 0 10px, ${e.textColor}08 10px 20px)`},children:(0,t.jsxs)("div",{className:"flex items-center gap-2 overflow-hidden whitespace-nowrap",children:[(0,t.jsx)("span",{className:"shrink-0 opacity-70",children:"Worktree"}),(0,t.jsx)("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-current opacity-70","aria-hidden":"true"}),(0,t.jsx)("button",{type:"button",onClick:i,title:"Click to copy worktree name",className:"truncate font-semibold tracking-(--tracking-eyebrow) cursor-pointer hover:opacity-80 transition-opacity bg-transparent border-none p-0 text-current uppercase text-(length:--text-micro)",children:s?"Copied!":n?"Copy failed":e.name})]})}):null}r(jxe,"WorktreeBanner");var sYe=3e4;function nYe(e){if(!e)return null;const s=new Date(e).getTime();if(Number.isNaN(s))return null;const n=Date.now()-s;if(n<6e4)return"just now";const a=Math.round(n/6e4);if(a<60)return`${a}m ago`;const i=Math.round(a/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}r(nYe,"formatRelativeTimestamp");function rYe(e){return e.reason==="backend_changes_and_pending_migrations"?"backend files changed and migrations are pending":e.reason==="pending_migrations"?"pending migrations need a fresh boot":"backend files changed since this server booted"}r(rYe,"describeReason");function wxe({devServer:e}){const[s,n]=(0,m.useState)(!1);if((0,m.useEffect)(()=>{if(!s)return;const d=window.setTimeout(()=>{n(!1)},sYe);return()=>window.clearTimeout(d)},[s]),!e?.enabled||!e.restartRequired)return null;const a=e,i=nYe(e.lastChangedAt),o=e.changedPathsSample.slice(0,3),l=`${e.activeRunCount} live run${e.activeRunCount===1?"":"s"}`;async function c(){const d=a.activeRunCount>0?`Restart Paperclip now? This may interrupt ${l}.`:"Restart Paperclip now?";if(window.confirm(d)){n(!0);try{await Ju.requestDevServerRestart()}catch(u){n(!1),window.alert(u instanceof Error?u.message:"Failed to request restart")}}}return r(c,"requestRestartNow"),(0,t.jsx)("div",{className:"border-b border-amber-300/60 bg-amber-50 text-amber-950 dark:border-amber-500/25 dark:bg-amber-500/10 dark:text-amber-100",children:(0,t.jsxs)("div",{className:"flex flex-col gap-3 px-3 py-2.5 md:flex-row md:items-center md:justify-between",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold uppercase tracking-(--tracking-caps)",children:[(0,t.jsx)(Is,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{children:"Restart Required"}),e.autoRestartEnabled?(0,t.jsx)(dt,{variant:"ghost",className:"bg-amber-900/10 text-(length:--text-nano) tracking-(--tracking-eyebrow) dark:bg-amber-100/10",children:"Auto-Restart On"}):null]}),(0,t.jsxs)("p",{className:"mt-1 text-sm",children:[rYe(e),i?` · updated ${i}`:""]}),(0,t.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-amber-900/80 dark:text-amber-100/75",children:[o.length>0?(0,t.jsxs)("span",{children:["Changed: ",o.join(", "),e.changedPathCount>o.length?` +${e.changedPathCount-o.length} more`:""]}):null,e.pendingMigrations.length>0?(0,t.jsxs)("span",{children:["Pending migrations: ",e.pendingMigrations.slice(0,2).join(", "),e.pendingMigrations.length>2?` +${e.pendingMigrations.length-2} more`:""]}):null]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs font-medium md:justify-end",children:[e.waitingForIdle?(0,t.jsxs)("div",{className:"inline-flex items-center gap-2 rounded-full bg-amber-900/10 px-3 py-1.5 dark:bg-amber-100/10",children:[(0,t.jsx)(REe,{className:"h-3.5 w-3.5"}),(0,t.jsxs)("span",{children:["Waiting for ",l," to finish"]})]}):e.autoRestartEnabled?(0,t.jsxs)("div",{className:"inline-flex items-center gap-2 rounded-full bg-amber-900/10 px-3 py-1.5 dark:bg-amber-100/10",children:[(0,t.jsx)(Ii,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{children:"Auto-restart will trigger when the instance is idle"})]}):(0,t.jsxs)("div",{className:"inline-flex items-center gap-2 rounded-full bg-amber-900/10 px-3 py-1.5 dark:bg-amber-100/10",children:[(0,t.jsx)(Ii,{className:"h-3.5 w-3.5"}),(0,t.jsxs)("span",{children:["Restart ",(0,t.jsx)("code",{children:"pnpm dev:once"})," after the active work is safe to interrupt"]})]}),(0,t.jsxs)("button",{type:"button",className:"inline-flex items-center gap-2 rounded-md bg-amber-950 px-3 py-1.5 text-xs font-semibold text-amber-50 transition-colors hover:bg-amber-900 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-amber-200 dark:text-amber-950 dark:hover:bg-amber-100",onClick:r(()=>{c()},"onClick"),disabled:s,children:[(0,t.jsx)(Ii,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{children:s?"Restart requested":"Restart now"})]})]})]})})}r(wxe,"DevRestartBanner");var Nxe=["standalone","fullscreen","window-controls-overlay"];function aYe(e){return`(display-mode: ${e})`}r(aYe,"displayModeQuery");function iYe(){if(!(typeof window>"u"||typeof window.matchMedia!="function"))return window.matchMedia.bind(window)}r(iYe,"defaultMatchMedia");function fJ(e=iYe(),s=typeof navigator>"u"?void 0:navigator.standalone){return s===!0?!0:e?Nxe.some(n=>e(aYe(n)).matches):!1}r(fJ,"isChromelessDisplayMode");function O4({label:e,children:s,onClick:n}){return(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-sm",className:"size-8 text-muted-foreground hover:text-foreground","aria-label":e,onClick:r(()=>{n()},"onClick"),children:s})}),(0,t.jsx)(Kn,{children:e})]})}r(O4,"ControlButton");function MF({mobile:e}){const[s,n]=(0,m.useState)(()=>typeof window<"u"&&e?fJ():!1),a=Nc();(0,m.useEffect)(()=>{if(!e||typeof window>"u"){n(!1);return}const c=r(()=>n(fJ()),"update");if(c(),typeof window.matchMedia!="function")return;const d=Nxe.map(u=>window.matchMedia(`(display-mode: ${u})`));return d.every(u=>typeof u.addEventListener=="function")?(d.forEach(u=>u.addEventListener("change",c)),()=>d.forEach(u=>u.removeEventListener("change",c))):(d.forEach(u=>u.addListener(c)),()=>d.forEach(u=>u.removeListener(c)))},[e]);const i=(0,m.useCallback)(()=>{window.location.reload()},[]),o=(0,m.useCallback)(async()=>{const c=window.location.href;try{if(navigator.share){await navigator.share({title:document.title||"Paperclip",url:c});return}await Gr(c),a?.pushToast({title:"Link copied",tone:"success"})}catch(d){if(d instanceof DOMException&&d.name==="AbortError")return;a?.pushToast({title:"Share failed",body:"Try opening the page in your browser.",tone:"error"})}},[a]),l=(0,m.useCallback)(()=>{window.open(window.location.href,"_blank","noopener,noreferrer")},[]);return!e||!s?null:(0,t.jsxs)("div",{className:"flex h-10 items-center justify-end gap-1 border-b border-border bg-background/95 px-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[(0,t.jsx)(O4,{label:"Refresh",onClick:i,children:(0,t.jsx)(zi,{className:"h-4 w-4"})}),(0,t.jsx)(O4,{label:"Share",onClick:o,children:(0,t.jsx)(jde,{className:"h-4 w-4"})}),(0,t.jsx)(O4,{label:"Open in Browser",onClick:l,children:(0,t.jsx)(xr,{className:"h-4 w-4"})})]})}r(MF,"StandaloneBrowserControls");var oYe=16384,lYe=40;function cYe(e){if(!e)return;const s=[];for(const n of e.slice(0,oYe).split(`
334
334
  `).slice(0,41)){const a=/^\s*(?:at|in) ([A-Za-z_$][\w$.-]{0,99})(?:\s|$)/.exec(n)?.[1]??/^([A-Za-z_$][\w$.-]{0,99})@/.exec(n)?.[1];if(a&&s.push(` at ${a}`),s.length===lYe)break}return s.length?`
335
335
  ${s.join(`
336
- `)}`:void 0}r(cYe,"sanitizeComponentStack");function dYe(e){const s=cYe(e.componentStack),n={};if(typeof document<"u"){try{const a=document.readyState;(a==="loading"||a==="interactive"||a==="complete")&&(n.ready_state=a)}catch{}try{const a=document.visibilityState;(a==="visible"||a==="hidden")&&(n.visibility_state=a)}catch{}try{const a=document.documentElement.classList;n.translation_marker=a.contains("translated-ltr")||a.contains("translated-rtl")}catch{}}return{tags:{react_error_boundary:e.boundary},contexts:{react:s?{componentStack:s}:{},browser_state:n}}}r(dYe,"buildBrowserErrorContext");var xJ=Promise.resolve();function lK(e){const s=xJ.then(e);return xJ=s.catch(()=>{}),s}r(lK,"enqueue");var hw=null;function uYe(e,s){return lK(async()=>{if(!hw)try{const n=await gc(()=>import("./prod-COP_vZWu.js"),__vite__mapDeps([4,5]));n.init(hYe(e,s)),hw=n}catch{}})}r(uYe,"initBrowserErrorMonitoring");function mYe(){return lK(async()=>{const e=hw;if(hw=null,!e)return;const s=e.getClient();try{e.getCurrentScope().setClient(void 0)}catch{}try{await s?.close(2e3)}catch{}})}r(mYe,"teardownBrowserErrorMonitoring");function kxe(e,s){let n;try{s&&(n=dYe(s))}catch{}lK(async()=>{try{n?hw?.captureException(e,n):hw?.captureException(e)}catch{}})}r(kxe,"captureBrowserException");function hYe(e,s){return{dsn:e,environment:s??void 0,release:"99f7b46b0220b8d4cae45a66dab3d49a5bd003be",tracesSampleRate:0,sendDefaultPii:!1,integrations:r(n=>n.filter(a=>a.name!=="HttpContext"&&a.name!=="Breadcrumbs"),"integrations")}}r(hYe,"buildBrowserSentryInitOptions");var pYe=class extends m.Component{static{r(this,"RouteErrorBoundaryInner")}state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,s){kxe(e,{boundary:"route",componentStack:s.componentStack})}componentDidUpdate(e){this.state.error&&e.resetKey!==this.props.resetKey&&this.setState({error:null})}render(){const{error:e}=this.state;return e?(0,t.jsxs)("div",{className:"mx-auto max-w-2xl space-y-4 px-4 py-10",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"This page hit an error"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Something went wrong while rendering this page. You can go back and try again, or reload."})]}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-wrap",children:e.message}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(F,{variant:"outline",size:"sm",onClick:this.props.onReset,children:"Go back"}),(0,t.jsx)(F,{size:"sm",onClick:r(()=>window.location.reload(),"onClick"),children:"Reload page"})]})]}):this.props.children}};function Sxe({children:e}){const s=Zr(),n=Wn(),a=`${s.pathname}${s.search}`;return(0,t.jsx)(pYe,{resetKey:a,onReset:r(()=>n(-1),"onReset"),children:e})}r(Sxe,"RouteErrorBoundary");var mI=240,DF=208,LF=420,gJ=16;function TT(e){return Math.min(LF,Math.max(DF,e))}r(TT,"clampSidebarWidth$1");function bJ(e){if(typeof window>"u")return mI;try{const s=window.localStorage.getItem(e);if(!s)return mI;const n=Number.parseInt(s,10);return Number.isFinite(n)?TT(n):mI}catch{return mI}}r(bJ,"readStoredSidebarWidth$1");function vJ(e,s){if(!(typeof window>"u"))try{window.localStorage.setItem(e,String(TT(s)))}catch{}}r(vJ,"writeStoredSidebarWidth$1");function fYe({children:e,open:s,collapsed:n=!1,peeking:a=!1,resizable:i=!1,storageKey:o="paperclip.sidebar.width",className:l,onPanelMouseEnter:c,onPanelMouseLeave:d,onPanelFocusCapture:u,onPanelBlurCapture:h}){const[p,x]=(0,m.useState)(()=>bJ(o)),[g,v]=(0,m.useState)(!1),y=(0,m.useRef)(p),j=(0,m.useRef)(null);(0,m.useEffect)(()=>{const T=bJ(o);y.current=T,x(T)},[o]);const S=s?p:0,w=s?n?64:S:0,N=s?n&&!a?64:S:0,_=N>w,I=i&&s&&!n,C=(0,m.useMemo)(()=>({width:`${w}px`}),[w]),A=(0,m.useMemo)(()=>({width:`${N}px`}),[N]),R=(0,m.useCallback)(T=>{const q=TT(T);y.current=q,x(q),vJ(o,q)},[o]),E=(0,m.useCallback)(T=>{I&&(T.preventDefault(),T.currentTarget.setPointerCapture(T.pointerId),j.current={startX:T.clientX,startWidth:y.current},v(!0))},[I]),O=(0,m.useCallback)(T=>{if(!j.current)return;const q=TT(j.current.startWidth+T.clientX-j.current.startX);y.current=q,x(q)},[]),L=(0,m.useCallback)(()=>{j.current&&(j.current=null,v(!1),vJ(o,y.current))},[o]),$=(0,m.useCallback)(T=>{I&&(T.key==="ArrowLeft"?(T.preventDefault(),R(p-gJ)):T.key==="ArrowRight"?(T.preventDefault(),R(p+gJ)):T.key==="Home"?(T.preventDefault(),R(DF)):T.key==="End"&&(T.preventDefault(),R(LF)))},[I,R,p]);return(0,t.jsxs)("div",{className:U("relative h-full shrink-0",l),style:C,children:[(0,t.jsx)("div",{className:U("absolute inset-y-0 left-0 flex flex-col overflow-hidden",_?"z-30 border-r border-border bg-background shadow-lg":"z-0"),style:A,"data-sidebar-overlay":_?"":void 0,onMouseEnter:c,onMouseLeave:d,onFocusCapture:u,onBlurCapture:h,children:e}),I?(0,t.jsx)("div",{role:"separator","aria-label":"Resize sidebar","aria-orientation":"vertical","aria-valuemin":DF,"aria-valuemax":LF,"aria-valuenow":p,tabIndex:0,"data-dragging":g?"":void 0,className:"group absolute inset-y-0 z-20 cursor-col-resize touch-none outline-none",style:{right:-4,width:8},onPointerDown:E,onPointerMove:O,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:L,onKeyDown:$,children:(0,t.jsx)("div",{className:U("mx-auto h-full w-0.5 transition-colors",g?"bg-ring":"bg-transparent group-hover:bg-ring group-focus-visible:bg-ring")})}):null]})}r(fYe,"SidebarShell$1");function hI({children:e,className:s}){return(0,t.jsx)("div",{"data-secondary-sidebar":"",className:U("h-full w-full min-w-0 overflow-hidden",s),children:(0,t.jsx)(qde,{children:e})})}r(hI,"SecondarySidebar$1");var xYe="Toggle the app appearance.";function Cj({className:e,variant:s="icon",onAfterToggle:n}){const{theme:a,toggleTheme:i}=F2e(),o=a==="dark",l=o?"Switch to light mode":"Switch to dark mode",c=o?wde:fde;function d(){i(),n?.()}return r(d,"handleClick"),s==="compact-menu-action"?(0,t.jsxs)("button",{type:"button",className:U("flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-accent",e),onClick:d,"aria-label":l,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(c,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:l})]}):s==="menu-action"?(0,t.jsxs)("button",{type:"button",className:U("flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-accent/60",e),onClick:d,"aria-label":l,children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(c,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:l}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:xYe})]})]}):(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-sm",onClick:d,"aria-label":l,title:l,className:U("text-muted-foreground",e),children:(0,t.jsx)(c,{})})}r(Cj,"ThemeToggle");function gYe(e){if(!e)return"Unavailable";const s=new Date(e);return Number.isNaN(s.getTime())?"Unavailable":new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(s)}r(gYe,"formatTimestamp$2");function bYe(e){return!!e&&!Number.isNaN(new Date(e).getTime())}r(bYe,"isValidTimestamp");function vYe(e){return e?.devServer?.lastRestartAt??e?.serverInfo?.processStartedAt??null}r(vYe,"restartTimestamp");function yYe(e){const s=e?.serverInfo?.git;return s?.available?`${s.shortSha} · ${s.subject}`:"Commit unavailable"}r(yYe,"commitLabel");function jYe(e){const s=e?.serverInfo?.git;if(!s?.available)return"Unavailable";const n=s.localChanges;if(!n||!n.available)return"Change status unavailable";if(!n.hasLocalChanges)return"Clean checkout";const a=[[n.stagedFileCount,"staged"],[n.unstagedFileCount,"unstaged"],[n.untrackedFileCount,"untracked"]].filter(([i])=>Number(i)>0).map(([i,o])=>`${i} ${o}`);return a.length>0?`Local changes present (${a.join(", ")})`:"Local changes present"}r(jYe,"localChangesLabel");function F4({icon:e,label:s,value:n,dateTime:a}){return(0,t.jsxs)("div",{className:"flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left",children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(e,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:s}),a?(0,t.jsx)("time",{dateTime:a,className:"block break-words text-xs text-muted-foreground",children:n}):(0,t.jsx)("span",{className:"block break-words text-xs text-muted-foreground",children:n})]})]})}r(F4,"ServerInfoRow");function Cxe(){const e=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")}).data?.enableServerInfoDebugView===!0,s=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),enabled:e,refetchOnMount:"always",refetchInterval:r(h=>h.state.data?.devServer?.enabled?2e3:!1,"refetchInterval")});if(!e)return null;const n=s.data,a=s.isLoading&&!n,i=s.isError,o=vYe(n),l=bYe(o),c=i?"Health unavailable":a?"Loading...":gYe(o),d=i?"Health unavailable":a?"Loading...":yYe(n),u=i?"Health unavailable":a?"Loading...":jYe(n);return(0,t.jsxs)("div",{className:"mt-2 border-t border-border pt-2",children:[(0,t.jsx)("p",{className:"px-3 pb-1 pt-1 text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Server"}),(0,t.jsx)(F4,{icon:Xm,label:"Last restarted",value:c,dateTime:!i&&!a&&l?o:null}),(0,t.jsx)(F4,{icon:ade,label:"Running commit",value:d}),(0,t.jsx)(F4,{icon:c3e,label:"Checkout state",value:u})]})}r(Cxe,"SidebarServerInfo");var wYe="/company/settings/instance/profile",NYe="https://docs.paperclip.ing/",kYe="https://paperclip.ing/feedback";function SYe(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?`${s[0]?.[0]??""}${s[s.length-1]?.[0]??""}`.toUpperCase():e.slice(0,2).toUpperCase()}r(SYe,"deriveInitials$2");function CYe(e,s,n){const a=[e,s?.split("@")[0],s,n];for(const i of a){const o=i?.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(o)return o}return"me"}r(CYe,"deriveUserSlug$1");function pI({label:e,icon:s,onClick:n,href:a,external:i=!1}){const o="flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-accent",l=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(s,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e})]});return a?i?(0,t.jsx)("a",{href:a,target:"_blank",rel:"noreferrer",className:o,onClick:n,children:l}):(0,t.jsx)(Qe,{to:a,className:o,onClick:n,children:l}):(0,t.jsx)("button",{type:"button",className:o,onClick:n,children:l})}r(pI,"MenuAction$1");function yJ({deploymentMode:e,open:s,onOpenChange:n,forceExpanded:a=!1}){const i=!!Vc(),[o,l]=(0,m.useState)(!1),{isMobile:c,setSidebarOpen:d,collapsed:u,peeking:h}=$a(),p=u&&!h&&!a,x=s??o,g=n??l,{data:v}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),y=Hw({onSignedOut:_}),j=v?.user.name?.trim()||"Board",S=v?.user.email?.trim()||(e==="authenticated"?"Signed in":"Local workspace board"),w=SYe(j),N=`/u/${CYe(v?.user.name,v?.user.email,v?.user.id)}`;function _(){g(!1),c&&d(!1)}r(_,"closeNavigationChrome");function I(){y.mutate()}return r(I,"handleSignOut"),(0,t.jsx)("div",{className:"bg-border/50 px-3 py-2 dark:bg-muted",children:(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",!p&&"px-2"),children:[(0,t.jsxs)(sr,{open:x,onOpenChange:g,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:U("flex min-w-0 items-center gap-2.5 rounded-lg text-left text-(length:--text-compact) font-medium text-foreground/80 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",p?"w-full px-3 py-2":"flex-1 px-2 py-1.5"),"aria-label":"Open account menu",children:[(0,t.jsxs)(Yi,{size:"sm",children:[v?.user.image?(0,t.jsx)(zc,{src:v.user.image,alt:j}):null,(0,t.jsx)(Ji,{children:w})]}),(0,t.jsx)("span",{className:U("min-w-0 flex-1 truncate",p&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),children:j})]})}),(0,t.jsxs)(Gn,{side:"top",align:"start",sideOffset:10,className:"min-h-(--profile-popover-min-height) w-(--profile-popover-width) max-w-(--sz-calc-24) overflow-hidden rounded-xl border-border bg-popover p-0 shadow-(--shadow-profile-popover)",children:[(0,t.jsxs)("div",{className:"flex h-(--profile-popover-header-height) shrink-0 items-center gap-2.5 px-3.5",children:[(0,t.jsxs)(Yi,{className:"size-9",children:[v?.user.image?(0,t.jsx)(zc,{src:v.user.image,alt:j}):null,(0,t.jsx)(Ji,{className:"text-xs text-foreground",children:w})]}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("h2",{className:"truncate text-sm font-semibold leading-(--profile-popover-label-line-height) text-foreground",children:j}),(0,t.jsx)("p",{className:"truncate text-(length:--text-micro) leading-(--profile-popover-meta-line-height) text-muted-foreground",children:S})]})]}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-0.5 border-t border-border px-2.5 pb-2.5 pt-2",children:[(0,t.jsx)(pI,{label:"Settings",icon:Dd,href:"/company/settings",onClick:_}),(0,t.jsx)(pI,{label:"View profile",icon:pu,href:N,onClick:_}),(0,t.jsx)(pI,{label:"Edit profile",icon:p1,href:wYe,onClick:_}),(0,t.jsx)(pI,{label:"Documentation",icon:Uw,href:NYe,external:!0,onClick:r(()=>g(!1),"onClick")}),(0,t.jsx)(Cj,{variant:"compact-menu-action",onAfterToggle:r(()=>g(!1),"onAfterToggle")}),e==="authenticated"?(0,t.jsxs)("button",{type:"button",className:U("flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-destructive/10",y.isPending&&"cursor-not-allowed opacity-60"),onClick:I,disabled:y.isPending,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:y.isPending?"Signing out...":"Sign out"})]}):null,(0,t.jsx)(Cxe,{})]})]})]}),!p&&!i?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("a",{href:kYe,target:"_blank",rel:"noreferrer","aria-label":"Share feedback",className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground/50 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:(0,t.jsx)(_x,{className:"h-4 w-4","aria-hidden":"true"})})}),(0,t.jsx)(Kn,{side:"top",children:"Share feedback"})]}):null]})})}r(yJ,"SidebarAccountMenu$1");function _xe({enabled:e=!0,onNewIssue:s,onSearch:n,onToggleSidebar:a,onTogglePanel:i,onShowShortcuts:o,onGoToInbox:l}){(0,m.useEffect)(()=>{if(!e)return;let c=!1,d=null;const u=r(()=>{d!==null&&(window.clearTimeout(d),d=null)},"clearGoChordTimeout"),h=r(()=>{c=!1,u()},"disarmGoChord"),p=r(()=>{c=!0,u(),d=window.setTimeout(()=>{c=!1,d=null},1200)},"armGoChord");function x(y){if(y.defaultPrevented){h();return}if(l){const j=Kle({armed:c,defaultPrevented:y.defaultPrevented,key:y.key,metaKey:y.metaKey,ctrlKey:y.ctrlKey,altKey:y.altKey,target:y.target,hasOpenDialog:Rh()});if(j==="arm"){p();return}if(j==="navigate_inbox"){h(),y.preventDefault(),l();return}if(j==="focus_comment"||j==="open_file_viewer"){h(),y.preventDefault();return}j==="disarm"&&h()}if(!QC(y.target)){if(y.key==="/"&&!y.metaKey&&!y.ctrlKey&&!y.altKey){if(Rh())return;y.preventDefault(),AAe()||n?.();return}if(y.key==="?"&&!y.metaKey&&!y.ctrlKey&&!y.altKey){y.preventDefault(),o?.();return}y.key==="c"&&!y.metaKey&&!y.ctrlKey&&!y.altKey&&(y.preventDefault(),s?.()),y.key==="["&&!y.metaKey&&!y.ctrlKey&&(y.preventDefault(),a?.()),y.key==="]"&&!y.metaKey&&!y.ctrlKey&&(y.preventDefault(),i?.())}}r(x,"handleKeyDown");const g=r(()=>h(),"handlePointerDown"),v=r(y=>{y.target instanceof HTMLElement&&y.target!==document.body&&h()},"handleFocusIn");return document.addEventListener("pointerdown",g,!0),document.addEventListener("focusin",v,!0),document.addEventListener("keydown",x),()=>{h(),document.removeEventListener("pointerdown",g,!0),document.removeEventListener("focusin",v,!0),document.removeEventListener("keydown",x)}},[e,s,n,a,i,o,l])}r(_xe,"useKeyboardShortcuts");var _Ye=new Set(["auth","invite","board-claim","cli-auth","docs"]);function Ixe(e){const s=(e.split("?")[0]??"").split("/").filter(Boolean);if(s.length===0)return!0;const[n]=s;return!_Ye.has(n)}r(Ixe,"isRememberableCompanyPath");function IYe(e){const s=qb(e.companyPrefix);return e.companies.find(n=>qb(n.issuePrefix)===s)??null}r(IYe,"findCompanyByPrefix");function AYe(e){const s=Y6(e.pathname);return s?IYe({companies:e.companies,companyPrefix:s})?.id??null:e.fallbackCompanyId}r(AYe,"getRememberedPathOwnerCompanyId");function RYe(e){const s=e.path?X3(e.path):"/dashboard";if(!Ixe(s))return"/dashboard";const[n,a]=(s.split("?")[0]??"").split("/").filter(Boolean);if(n==="issues"&&a){const i=/^([A-Za-z]+)-\d+$/.exec(a);if(i&&qb(i[1]??"")!==qb(e.companyPrefix))return"/dashboard"}return s}r(RYe,"sanitizeRememberedPathForCompany");var Axe="paperclip.companyPaths";function Rxe(){try{const e=localStorage.getItem(Axe);if(e)return JSON.parse(e)}catch{}return{}}r(Rxe,"getCompanyPaths");function TYe(e,s){const n=Rxe();n[e]=s,localStorage.setItem(Axe,JSON.stringify(n))}r(TYe,"saveCompanyPath");function Txe(){const{companies:e,selectedCompanyId:s,selectedCompany:n,selectionSource:a}=fs(),i=Zr(),o=Wn(),l=(0,m.useRef)(s),c=(0,m.useMemo)(()=>AYe({companies:e,pathname:i.pathname,fallbackCompanyId:l.current}),[e,i.pathname]),d=i.pathname+i.search;(0,m.useEffect)(()=>{const u=c,h=X3(d);u&&Ixe(h)&&TYe(u,h)},[d,c]),(0,m.useEffect)(()=>{if(s){if(l.current!==null&&s!==l.current&&a!=="route_sync"&&n){const u=Rxe(),h=RYe({path:u[s],companyPrefix:n.issuePrefix});o(`/${n.issuePrefix}${h}`,{replace:!0})}l.current=s}},[n,s,a,o])}r(Txe,"useCompanyPageMemory");function Exe(e){const{matchedCompany:s,selectedCompanyId:n,companies:a}=e;return!s||s.status!=="archived"||n===s.id?null:a.find(i=>i.id===n&&i.status!=="archived")??a.find(i=>i.status!=="archived")??null}r(Exe,"resolveArchivedCompanyBounce");function EYe(e){const{archivedCompanyId:s,companies:n,cloudPortfolioUrl:a}=e,i=n.find(o=>o.id!==s&&o.status!=="archived");return i?{kind:"company",company:i}:a?{kind:"cloud_portfolio",url:a}:{kind:"companies_list"}}r(EYe,"resolveCompanyArchiveDeparture");function Pxe(e){const{selectionSource:s,selectedCompanyId:n,routeCompanyId:a}=e;return!(n===a||s==="manual"&&n)}r(Pxe,"shouldSyncCompanySelectionFromRoute");function PYe(e,s){return e instanceof HTMLElement?!(s instanceof HTMLElement)||!document.contains(s)||s===document.body||s===document.documentElement?!0:!e.contains(s):!1}r(PYe,"shouldFocusMainContentAfterNavigation");function Mxe(e){if(!(e instanceof HTMLElement))return()=>{};const s=window.requestAnimationFrame(()=>{PYe(e,document.activeElement)&&e.focus({preventScroll:!0})});return()=>window.cancelAnimationFrame(s)}r(Mxe,"scheduleMainContentFocus");function Dxe(e=document,s=window){const n=r(()=>{e.documentElement.scrollTop!==0&&(e.documentElement.scrollTop=0),e.body.scrollTop!==0&&(e.body.scrollTop=0)},"onScroll");return s.addEventListener("scroll",n,{capture:!0}),()=>s.removeEventListener("scroll",n,{capture:!0})}r(Dxe,"pinDocumentScrollToZero");function uu({scope:e="global",requestedPrefix:s}){const n=Zr(),{setBreadcrumbs:a}=$n(),{companies:i,selectedCompany:o}=fs();(0,m.useEffect)(()=>{a([{label:"Not Found"}])},[a]);const l=o??i[0]??null,c=l?`/${l.issuePrefix}/dashboard`:"/",d=`${n.pathname}${n.search}${n.hash}`,u=s?.toUpperCase(),h=e==="invalid_company_prefix"?"Organization not found":"Page not found",p=e==="invalid_company_prefix"?`No organization matches prefix "${u??"unknown"}".`:"This route does not exist.";return(0,t.jsx)("div",{className:"mx-auto max-w-2xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 p-2",children:(0,t.jsx)(Is,{className:"h-5 w-5 text-destructive"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:h}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:p})]})]}),(0,t.jsxs)("div",{className:"mt-4 rounded-md border border-border bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:["Requested path: ",(0,t.jsx)("code",{className:"font-mono",children:d})]}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{asChild:!0,children:(0,t.jsxs)(Qe,{to:c,children:[(0,t.jsx)(CR,{className:"mr-1.5 h-4 w-4"}),"Open dashboard"]})}),(0,t.jsx)(F,{variant:"outline",asChild:!0,children:(0,t.jsx)(Qe,{to:"/",children:"Go home"})})]})]})})}r(uu,"NotFoundPage");function MYe(e,s){return nme(e,s)[0]?.toLowerCase()??null}r(MYe,"getCompanyRouteSegment$1");var DYe=new Set(["browse","connections","connect","chat","vercel-connect","review","attention","gateways","advanced","app"]);function LYe({sidebarSections:e}){const{sidebarOpen:s,setSidebarOpen:n,toggleSidebar:a,collapsed:i,peeking:o,setPeeking:l,isMobile:c,setForceCollapsed:d}=$a(),{openNewIssue:u,openOnboarding:h}=Lo(),{togglePanelVisible:p}=uf(),x=Nc()?.pushToast??null,{companies:g,loading:v,selectedCompany:y,selectedCompanyId:j,selectionSource:S,setSelectedCompanyId:w}=fs(),{companyPrefix:N,pluginRoutePath:_,agentId:I,routineId:C}=ja(),A=Wn(),R=Zr(),E=J3(),{enabled:O}=wc(),L=X$e(R.pathname,N),$=L.builtInContextualSurface==="settings",T=L.companySegments,q=L.isTaskDetail,B=O&&q,K=T[0]?.toLowerCase()==="tools",z=T[0]?.toLowerCase()==="apps",D=z&&T[1]&&!DYe.has(T[1].toLowerCase())?T[1]:null,V=z&&T[1]?.toLowerCase()==="app"&&T[2]?T[2]:null,H=(0,m.useRef)(!1),Z=(0,m.useRef)(0),Y=(0,m.useRef)(null),ie=(0,m.useRef)(null),se=(0,m.useRef)(new Ode),X=(0,m.useRef)(R.key),[le,oe]=(0,m.useState)(!0),[te,J]=(0,m.useState)(!1),Q=(0,m.useMemo)(()=>{if(!N)return null;const Ot=N.toUpperCase();return g.find(Be=>Be.issuePrefix.toUpperCase()===Ot)??null},[g,N]),pe=!!N&&!v&&g.length>0&&!Q,re=(0,m.useMemo)(()=>_?.toLowerCase()??MYe(R.pathname,N),[N,R.pathname,_]),ne=Q?.id??null,ae=Q?.issuePrefix??null,{slots:me}=Kc({slotTypes:["page","routeSidebar"],companyId:ne,enabled:!!(ne&&re)}),he=(0,m.useMemo)(()=>Fz(me,re),[re,me]),Ie=(0,m.useMemo)(()=>({companyId:ne,companyPrefix:ae}),[ne,ae]),de=$?(0,t.jsx)(sOe,{}):!O&&L.builtInContextualSurface==="skills"?(0,t.jsx)(cQ,{}):D?(0,t.jsx)(oQ,{kind:"connection",connectionId:D}):V?(0,t.jsx)(oQ,{kind:"application",applicationId:V}):z||K?(0,t.jsx)(cOe,{}):he?O?(0,t.jsx)(v1,{surface:`plugin:${he.id}`,title:he.displayName,children:(0,t.jsx)(fu,{slot:he,context:Ie,className:"min-h-0 flex-1",missingBehavior:"placeholder"})}):(0,t.jsx)(fu,{slot:he,context:Ie,className:"h-full w-full",missingBehavior:"placeholder"}):null,ve=L.builtInContextualSurface==="agent"&&I?(0,t.jsx)(kOe,{agentRef:I}):O&&L.builtInContextualSurface==="routine"&&C?(0,t.jsx)(I4e,{children:(0,t.jsx)(_Oe,{routineId:C})}):O&&L.builtInContextualSurface==="skills"?(0,t.jsx)(cQ,{}):de,Te=ve!=null,fe=O&&Te&&(L.builtInContextualSurface==="skills"||L.builtInContextualSurface==="agent"||L.builtInContextualSurface==="routine"||z||K),Ce=O&&Te&&!fe,Xe=Te&&(!O||fe),Oe=!O||!Te?null:he&&!L.builtInContextualSurface?`plugin:${he.id}`:L.builtInContextualSurface,tt=(0,m.useRef)(null),{data:ce}=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1,refetchInterval:r(Ot=>Ot.state.data?.devServer?.enabled?2e3:!1,"refetchInterval"),refetchIntervalInBackground:!1}),$e=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn")}).data?.keyboardShortcuts===!0;(0,m.useLayoutEffect)(()=>(d(!O&&Te),()=>d(!1)),[Te,d,O]),(0,m.useEffect)(()=>{const Ot=tt.current;Oe&&N&&Ot&&Ot.surface!==Oe&&Ot.pathname!==R.pathname&&Z$e({surface:Oe,companyPrefix:N,previousPathname:Ot.pathname}),tt.current={pathname:R.pathname,surface:Oe}},[N,Oe,R.pathname]),(0,m.useEffect)(()=>{v||H.current||ce?.deploymentMode!=="authenticated"&&(ce?.cloud||g.length===0&&(H.current=!0,h()))},[g,v,h,ce?.cloud,ce?.deploymentMode]),(0,m.useEffect)(()=>{if(!N||v||g.length===0)return;if(!Q){const Be=(j?g.find(Ve=>Ve.id===j):null)??g[0]??null;Be&&j!==Be.id&&w(Be.id,{source:"route_sync"});return}if(N!==Q.issuePrefix){const Be=R.pathname.replace(/^\/[^/]+/,"");A(`/${Q.issuePrefix}${Be}${R.search}`,{replace:!0});return}const Ot=Exe({matchedCompany:Q,selectedCompanyId:j,companies:g});if(Ot){x?.({title:`${Q.name} is archived`,body:`Switched to ${Ot.name}.`,tone:"info",dedupeKey:`archived-company-bounce:${Q.id}`}),w(Ot.id,{source:"route_sync"}),A(`/${Ot.issuePrefix}/dashboard`,{replace:!0});return}Pxe({selectionSource:S,selectedCompanyId:j,routeCompanyId:Q.id})&&w(Q.id,{source:"route_sync"})},[N,g,v,Q,R.pathname,R.search,A,x,S,j,w]);const mt=p,it=(0,m.useCallback)(()=>{document.dispatchEvent(new KeyboardEvent("keydown",{key:"k",metaKey:!0,bubbles:!0,cancelable:!0}))},[]),Ke=(0,m.useRef)(null),Ge=(0,m.useRef)(!1),rt=(0,m.useRef)(!1),jt=(0,m.useCallback)(()=>{Ke.current!==null&&(window.clearTimeout(Ke.current),Ke.current=null)},[]),st=(0,m.useCallback)(()=>{jt(),Ke.current=window.setTimeout(()=>l(!0),50)},[jt,l]),Nt=(0,m.useCallback)(()=>{jt(),l(!0)},[jt,l]),at=(0,m.useCallback)(()=>{jt(),Ke.current=window.setTimeout(()=>l(!1),120)},[jt,l]),Ee=(0,m.useCallback)(()=>{Ge.current=!0,i&&!rt.current&&st()},[i,st]),Ne=(0,m.useCallback)(()=>{Ge.current=!1,rt.current=!1,at()},[at]),He=(0,m.useCallback)(()=>{rt.current||Nt()},[Nt]),St=(0,m.useCallback)(()=>{Ge.current||at()},[at]);(0,m.useEffect)(()=>jt,[jt]);const Ft=(0,m.useRef)(i);(0,m.useEffect)(()=>{i!==Ft.current&&(i?(jt(),l(!1),rt.current=Ge.current):rt.current=!1,Ft.current=i)},[i,jt,l]),(0,m.useEffect)(()=>{if(!o)return;const Ot=r(Be=>{Be.key==="Escape"&&(jt(),l(!1))},"onKeyDown");return window.addEventListener("keydown",Ot),()=>window.removeEventListener("keydown",Ot)},[o,jt,l]),Txe(),_xe({enabled:$e,onNewIssue:r(()=>u(),"onNewIssue"),onSearch:it,onToggleSidebar:a,onTogglePanel:mt,onShowShortcuts:r(()=>J(!0),"onShowShortcuts"),onGoToInbox:r(()=>A("/inbox"),"onGoToInbox")}),(0,m.useEffect)(()=>{if(!c){oe(!0);return}Z.current=0,oe(!0)},[c]),(0,m.useEffect)(()=>{if(!c)return;const Ot=30,Be=50,Ve=75;let ut=0,qe=0;const Gt=r($t=>{const Dt=$t.touches[0];ut=Dt.clientX,qe=Dt.clientY},"onTouchStart"),We=r($t=>{const Dt=$t.changedTouches[0],Cs=Dt.clientX-ut;if(!(Math.abs(Dt.clientY-qe)>Ve)){if(!s&&ut<Ot&&Cs>Be){n(!0);return}s&&Cs<-50&&n(!1)}},"onTouchEnd");return document.addEventListener("touchstart",Gt,{passive:!0}),document.addEventListener("touchend",We,{passive:!0}),()=>{document.removeEventListener("touchstart",Gt),document.removeEventListener("touchend",We)}},[c,s,n]);const ts=(0,m.useCallback)(Ot=>{const Be=Ot-Z.current;Ot<=24?oe(!0):Be>8?oe(!1):Be<-8&&oe(!0),Z.current=Ot},[]);return(0,m.useEffect)(()=>{if(!c){oe(!0),Z.current=0;return}const Ot=r(()=>{ts(window.scrollY||document.documentElement.scrollTop||0)},"onScroll");return Ot(),window.addEventListener("scroll",Ot,{passive:!0}),()=>{window.removeEventListener("scroll",Ot)}},[c,ts]),(0,m.useEffect)(()=>{const Ot=document.body.style.overflow;return document.body.style.overflow=c?"visible":"clip",()=>{document.body.style.overflow=Ot}},[c]),(0,m.useEffect)(()=>{if(!c)return Dxe()},[c]),(0,m.useEffect)(()=>{if(typeof document>"u")return;const Ot=ie.current;return Mxe(Ot)},[R.pathname]),(0,m.useEffect)(()=>{const Ot=ie.current;if(!Ot)return;const Be=r(()=>{se.current.remember(X.current,Ot.scrollTop)},"recordScroll");return Ot.addEventListener("scroll",Be,{passive:!0}),()=>Ot.removeEventListener("scroll",Be)},[]),(0,m.useLayoutEffect)(()=>{const Ot=ie.current,Be=$de({previousPathname:Y.current,pathname:R.pathname,navigationType:E,state:R.state});Y.current=R.pathname;const Ve=E==="POP",ut=Ve?se.current.recall(R.key):0;if(X.current=R.key,Ve){UR(Ot,ut);const qe=requestAnimationFrame(()=>UR(Ot,ut));return()=>cancelAnimationFrame(qe)}Be&&Fde(Ot)},[R.key,R.pathname,R.state,E]),(0,t.jsx)(Lde,{children:(0,t.jsx)(Wle,{value:{keyboardShortcutsEnabled:$e},children:(0,t.jsxs)("div",{className:U("bg-background text-foreground pt-(--sz-safe-top)",c?"min-h-dvh overflow-x-clip":"flex h-dvh flex-col overflow-clip"),children:[(0,t.jsx)("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-(--z-200) focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Skip to Main Content"}),(0,t.jsx)(jxe,{}),(0,t.jsx)(wxe,{devServer:ce?.devServer}),(0,t.jsxs)("div",{className:U("min-h-0 flex-1",c?"w-full":"flex overflow-clip"),children:[c&&s&&(0,t.jsx)("button",{type:"button",className:"fixed inset-0 z-40 bg-black/50",onClick:r(()=>n(!1),"onClick"),"aria-label":"Close sidebar"}),c?(0,t.jsxs)("div",{className:U("fixed inset-y-0 left-0 z-50 flex flex-col overflow-hidden pt-(--sz-safe-top) transition-transform duration-100 ease-out",s?"translate-x-0":"-translate-x-full"),children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:(0,t.jsx)("div",{className:"w-60 shrink-0 overflow-hidden",children:Te?(0,t.jsx)(hI,{children:ve}):(0,t.jsx)(nQ,{children:e})})}),(0,t.jsx)(yJ,{deploymentMode:ce?.deploymentMode,forceExpanded:Ce})]}):(0,t.jsxs)(fYe,{open:s,collapsed:Ce?!1:i,peeking:Ce?!1:o,resizable:!0,onPanelMouseEnter:Ce?void 0:Ee,onPanelMouseLeave:Ce?void 0:Ne,onPanelFocusCapture:!Ce&&i?He:void 0,onPanelBlurCapture:!Ce&&i?St:void 0,children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0",children:Ce?(0,t.jsx)(hI,{children:ve}):(0,t.jsx)(nQ,{children:e})}),(0,t.jsx)(yJ,{deploymentMode:ce?.deploymentMode,forceExpanded:Ce})]}),!c&&Xe&&!fe?(0,t.jsx)(hI,{className:"w-60 shrink-0",children:ve}):null,(0,t.jsxs)("div",{className:U("flex min-w-0 flex-col",c?"w-full":"h-full flex-1"),children:[(0,t.jsxs)("div",{className:U(!c&&B&&"hidden",c&&"sticky top-0 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85"),children:[(0,t.jsx)(MF,{mobile:c}),(0,t.jsx)(uQ,{}),c&&$?(0,t.jsx)("div",{className:"border-b border-border px-4 pb-3",children:(0,t.jsx)(ime,{})}):null]}),(0,t.jsxs)("div",{className:U(c?"block":"flex flex-1 min-h-0",!c&&B&&"streamlined-task-detail-surface"),children:[!c&&fe?(0,t.jsx)(hI,{className:"w-60 shrink-0 bg-background",children:ve}):null,(0,t.jsxs)("div",{className:U(!c&&B?"flex min-w-0 flex-1 flex-col":"contents"),children:[!c&&B?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(MF,{mobile:!1}),(0,t.jsx)(uQ,{taskDetailLayout:!0})]}):null,(0,t.jsx)("main",{id:"main-content",ref:ie,tabIndex:-1,style:c?{"--tc-composer-bottom":le?"var(--sz-calc-14)":"var(--tc-composer-hidden-nav-offset)"}:void 0,className:U("flex-1 p-4 outline-none md:p-6",!c&&B&&"pt-0 md:pt-0",c?q&&!le?"overflow-visible pb-(--tc-composer-hidden-nav-offset)":"overflow-visible pb-(--sz-calc-14)":"overflow-auto [scrollbar-gutter:stable]"),children:pe?(0,t.jsx)(uu,{scope:"invalid_company_prefix",requestedPrefix:N??y?.issuePrefix}):(0,t.jsx)(Sxe,{children:(0,t.jsx)(n0,{})})})]}),(0,t.jsx)(bme,{taskDetailLayout:!c&&B})]})]})]}),c&&(0,t.jsx)(yxe,{visible:le}),(0,t.jsx)(jme,{}),(0,t.jsx)(Eme,{}),(0,t.jsx)(mxe,{}),(0,t.jsx)(fxe,{}),(0,t.jsx)(xxe,{}),(0,t.jsx)(gxe,{open:te,onOpenChange:J}),(0,t.jsx)(bxe,{}),(0,t.jsx)(KGe,{health:ce}),(0,t.jsx)(vxe,{localTrusted:ce?.deploymentMode==="local_trusted"})]})})})}r(LYe,"Layout$1");var Lxe=(0,m.createContext)(!1);function $Ye({children:e}){return(0,t.jsx)(Lxe.Provider,{value:!0,children:e})}r($Ye,"SidebarNavExpandedProvider");function OYe(){return(0,m.useContext)(Lxe)}r(OYe,"useSidebarNavExpanded");function Ha({to:e,label:s,icon:n,iconNode:a,end:i,className:o,labelClassName:l,badge:c,badgeTone:d="default",badgeLabel:u,textBadge:h,textBadgeTone:p="default",alert:x=!1,liveCount:g,active:v,trailing:y,trailingLabel:j,liveAccessory:S}){const{isMobile:w,setSidebarOpen:N,collapsed:_,peeking:I}=$a(),C=OYe(),A=_&&!I&&!C,R=c!=null&&c>0,E=g!=null&&g>0,O=E?`${g} live`:R?`${c}${u?` ${u}`:""}`:x?"attention needed":void 0,L=!A||!O&&!j?void 0:`${s}${O?`, ${O}`:""}${j?`, ${j}`:""}`,$=(0,t.jsxs)(r0,{to:e,state:lf,end:i,"aria-label":L,onClick:r(()=>{w&&N(!1)},"onClick"),className:r(({isActive:T})=>U("flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium transition-colors",v??T?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground",o),"className"),children:[(0,t.jsxs)("span",{className:"relative shrink-0",children:[a??(n?(0,t.jsx)(n,{className:"h-4 w-4"}):null),x&&(0,t.jsx)("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-red-500 shadow-(--shadow-extract-12)","aria-hidden":"true"}),A&&!x&&E&&(0,t.jsxs)("span",{className:"absolute -right-0.5 -top-0.5 flex h-2 w-2","aria-hidden":"true",children:[(0,t.jsx)("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-600 dark:bg-blue-400 shadow-(--shadow-extract-12)"})]}),A&&!x&&!E&&R&&(0,t.jsx)("span",{className:U("absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full shadow-(--shadow-extract-12)",d==="danger"?"bg-red-600":d==="warning"?"bg-amber-500":"bg-primary"),"aria-hidden":"true"})]}),(0,t.jsx)("span",{className:A?bv:U("min-w-0 flex-1 truncate",l),children:s}),!A&&y,!A&&h&&(0,t.jsx)(dt,{variant:"ghost",className:U("ml-auto px-1.5 text-(length:--text-nano) leading-none",p==="amber"?"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400":"bg-muted text-muted-foreground"),children:h}),!A&&(E||S)&&(0,t.jsxs)("span",{className:"ml-auto flex items-center gap-1.5",children:[S,E&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-600 dark:bg-blue-400"})]}),(0,t.jsxs)("span",{className:"text-(length:--text-micro) font-medium text-blue-600 dark:text-blue-400",children:[g," live"]})]})]}),!A&&R&&(0,t.jsx)(dt,{variant:"ghost",className:U("ml-auto px-1.5 leading-none",d==="danger"?"bg-red-600/90 text-red-50":d==="warning"?"bg-amber-500/90 text-amber-50":"bg-primary text-primary-foreground"),children:c})]});return A?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("div",{children:$})}),(0,t.jsx)(Kn,{side:"right",children:s})]}):$}r(Ha,"SidebarNavItem");var FYe=3,jJ=12e4,BYe=[{value:"top",label:"Top"},{value:"alphabetical",label:"Alphabetical"},{value:"recent",label:"Recent"}];function my(e,s){const n=e[s];if(!n)return 0;const a=new Date(n).getTime();return Number.isFinite(a)?a:0}r(my,"agentTimestamp");function wJ(e,s){if(s==="top")return e;const n=[...e];return s==="alphabetical"?(n.sort((a,i)=>a.name.localeCompare(i.name,void 0,{sensitivity:"base"})),n):(n.sort((a,i)=>{const o=my(i,"lastHeartbeatAt")-my(a,"lastHeartbeatAt");if(o!==0)return o;const l=my(i,"updatedAt")-my(a,"updatedAt");if(l!==0)return l;const c=my(i,"createdAt")-my(a,"createdAt");return c!==0?c:a.name.localeCompare(i.name,void 0,{sensitivity:"base"})}),n)}r(wJ,"sortAgents");var qYe="opacity-0 transition-opacity group-hover/agent:opacity-100 group-focus-within/agent:opacity-100";function zYe({activeAgentId:e,activeTab:s,agent:n,disabled:a,isMobile:i,leaving:o,onLeaveAgent:l,onPauseResume:c,rail:d,runCount:u,setSidebarOpen:h,builtInStatus:p,starred:x=!1,onToggleStar:g,starPending:v=!1}){const y=vc(n),j=s?`${Ku(n)}/${s}`:Ku(n),S=`${Ku(n)}/configuration`,w=e===y,N=n.status==="paused",_=N&&n.pauseReason==="budget",I=n.orgChainHealth?.status==="invalid_org_chain",C=N?"Resume agent":"Pause agent",A=a||n.status==="pending_approval"||_||N&&I,R=a?"Updating...":_?"Budget paused":N&&I?"Invalid org chain":C,E=p==="needs_setup"||p==="pending_approval",O=[E?`Built-in agent ${p.replace(/_/g," ")}`:null,I?"Invalid reporting chain":null].filter(Boolean).join(", ")||void 0,L=(0,t.jsx)(Ha,{to:j,label:n.name,iconNode:(0,t.jsx)(hr,{agent:n,size:16,className:"shrink-0 h-4 w-4"}),active:w,liveCount:u,labelClassName:E?"min-w-(--sz-4_5rem) flex-initial":void 0,className:U("min-w-0 flex-1",x&&!i?"pr-14":"pr-8"),trailing:E||I?(0,t.jsxs)("span",{className:"ml-1 flex shrink-0 items-center gap-1",children:[E?(0,t.jsx)(vj,{status:p,compact:!0}):null,I?(0,t.jsx)(Is,{className:"h-3.5 w-3.5 shrink-0 text-amber-500","aria-label":"Invalid reporting chain"}):null]}):void 0,trailingLabel:O,liveAccessory:n.pauseReason==="budget"?(0,t.jsx)(x1,{title:"Agent paused by budget"}):void 0});return d?L:(0,t.jsxs)("div",{className:"group/agent relative flex items-center",children:[L,x&&!i&&g?(0,t.jsx)("span",{className:"absolute right-10 top-1/2 -translate-y-1/2",children:(0,t.jsx)(o0,{size:"row",quiet:!0,starred:!0,pending:v,resourceName:n.name,onToggle:r(()=>g(n,!1),"onToggle"),revealClassName:qYe})}):null,(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:U("absolute right-3 top-1/2 h-6 w-6 -translate-y-1/2 transition-opacity data-[state=open]:pointer-events-auto data-[state=open]:opacity-100",i?"opacity-100":"pointer-events-none opacity-0 group-hover/agent:pointer-events-auto group-hover/agent:opacity-100 group-focus-within/agent:pointer-events-auto group-focus-within/agent:opacity-100"),"aria-label":`Open actions for ${n.name}`,children:(0,t.jsx)(Pi,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(ga,{align:"end",className:"w-48",children:[g?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(ps,{onClick:r(()=>{v||g(n,!x)},"onClick"),disabled:v,children:[v?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Th,{className:U("size-4",x&&"fill-amber-500 text-amber-500")}),(0,t.jsx)("span",{children:x?"Remove from starred":"Star agent"})]}),(0,t.jsx)(hi,{})]}):null,(0,t.jsx)(ps,{asChild:!0,children:(0,t.jsxs)(Qe,{to:S,onClick:r(()=>{i&&h(!1)},"onClick"),children:[(0,t.jsx)(ql,{className:"size-4"}),(0,t.jsx)("span",{children:"Edit agent"})]})}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{A||c(n,N?"resume":"pause")},"onClick"),disabled:A,title:_?"Agent was paused by budget limits":void 0,children:[N?(0,t.jsx)(u1,{className:"size-4"}):(0,t.jsx)(ld,{className:"size-4"}),(0,t.jsx)("span",{children:R})]}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{o||l(n)},"onClick"),disabled:o,children:[o?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Yh,{className:"size-4"}),(0,t.jsx)("span",{children:o?"Leaving...":"Leave agent"})]})]})]})]})}r(zYe,"SidebarAgentItem");function UYe({streamlined:e=!1}={}){const[s,n]=(0,m.useState)(!0),[a,i]=(0,m.useState)(()=>new Set),[o,l]=(0,m.useState)(0),c=(0,m.useRef)(new Map),d=Ht(),{selectedCompanyId:u}=fs(),{openNewAgent:h}=Lo(),{isMobile:p,setSidebarOpen:x,collapsed:g,peeking:v}=$a(),y=g&&!v,{pushToast:j}=ua(),S=Zr(),{data:w}=ee({queryKey:P.agents.list(u),queryFn:r(()=>Wt.list(u),"queryFn"),enabled:!!u}),{data:N}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),enabled:!!u}),_=N?.enableBuiltInAgents===!0,{data:I}=ee({queryKey:P.builtInAgents.list(u),queryFn:r(()=>fh.list(u),"queryFn"),enabled:!!u&&_}),C=(0,m.useMemo)(()=>{const fe=new Map;if(!_)return fe;for(const Ce of I??[])Ce.agentId&&fe.set(Ce.agentId,Ce.status);return fe},[I,_]),{data:A}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn")}),R=cf(u),E=df(u),O=P.liveRuns(u),L=mo({companyId:u,resourceKey:"live-runs",queryKey:O,enabled:!!u,refetchInterval:!1,leaderOnly:!0}),{data:$,dataUpdatedAt:T}=ee({queryKey:O,queryFn:r(()=>Xr.liveRunsForCompany(u),"queryFn"),enabled:L.enabled,refetchInterval:L.refetchInterval});ho(L,$,T);const q=(0,m.useMemo)(()=>{const fe=new Map;for(const Ce of $??[])fe.set(Ce.agentId,(fe.get(Ce.agentId)??0)+1);return fe},[$]),B=(0,m.useMemo)(()=>{const fe=new Set;for(const[Ce,Xe]of q)Xe>0&&fe.add(Ce);return fe},[q]),K=(0,m.useMemo)(()=>(w??[]).filter(fe=>fe.status!=="terminated"&&(!R.isSuccess||vx(R.data,"agent",fe.id)!=="left")),[w,R.data,R.isSuccess]),z=A?.user?.id??A?.session?.userId??null,D=(0,m.useMemo)(()=>u?Qde(u,z):null,[z,u]),[V,H]=(0,m.useState)(()=>D?yj(D):"top"),{orderedAgents:Z}=Jde({agents:K,companyId:u,userId:z}),Y=(0,m.useMemo)(()=>wJ(Z,V),[Z,V]),ie=(0,m.useMemo)(()=>new Set(Y.map(fe=>fe.id)),[Y]);(0,m.useEffect)(()=>{const fe=Date.now();for(const Ce of B)c.current.set(Ce,fe);for(const Ce of c.current.keys())ie.has(Ce)||c.current.delete(Ce)},[B,ie]);const se=(0,m.useMemo)(()=>{const fe=Date.now(),Ce=c.current;return Y.filter(Xe=>{if((q.get(Xe.id)??0)>0)return!0;const Oe=Ce.get(Xe.id);return Oe!==void 0&&fe-Oe<=jJ})},[q,o,Y]),X=se.length>0,le=e?X?se:Y.slice(0,FYe):Y,oe=e&&Y.length>0,te=S.pathname.match(/^\/(?:[^/]+\/)?agents\/([^/]+)(?:\/([^/]+))?/),J=te?.[1]??null,Q=te?.[2]??null;(0,m.useEffect)(()=>{if(!D){H("top");return}H(yj(D))},[D]),(0,m.useEffect)(()=>{if(!D)return;const fe=r(Xe=>{Xe.key===D&&H(yj(D))},"onStorage"),Ce=r(Xe=>{const Oe=Xe.detail;!Oe||Oe.storageKey!==D||H(Oe.sortMode)},"onCustomEvent");return window.addEventListener("storage",fe),window.addEventListener(US,Ce),()=>{window.removeEventListener("storage",fe),window.removeEventListener(US,Ce)}},[D]),(0,m.useEffect)(()=>{if(!e)return;const fe=Date.now();let Ce=null;for(const Oe of Y){if((q.get(Oe.id)??0)>0)continue;const tt=c.current.get(Oe.id);if(tt===void 0)continue;const ce=tt+jJ;ce<fe||(Ce=Ce===null?ce:Math.min(Ce,ce))}if(Ce===null)return;const Xe=window.setTimeout(()=>{l(Oe=>Oe+1)},Math.max(0,Ce-fe+1));return()=>{window.clearTimeout(Xe)}},[e,Y,q,o]);const pe=(0,m.useCallback)(fe=>{const Ce=fe==="alphabetical"||fe==="recent"?fe:"top";H(Ce),D&&Yde(D,Ce)},[D]),re=ye({mutationFn:r(({agent:fe,action:Ce})=>Ce==="pause"?Wt.pause(fe.id,u??void 0):Wt.resume(fe.id,u??void 0),"mutationFn"),onMutate:r(({agent:fe})=>{i(Ce=>{const Xe=new Set(Ce);return Xe.add(fe.id),Xe})},"onMutate"),onSuccess:r(async(fe,{agent:Ce,action:Xe})=>{u&&await Promise.all([d.invalidateQueries({queryKey:P.agents.list(u)}),d.invalidateQueries({queryKey:P.liveRuns(u)}),d.invalidateQueries({queryKey:P.dashboard(u)})]),await Promise.all([d.invalidateQueries({queryKey:P.agents.detail(Ce.id)}),d.invalidateQueries({queryKey:P.agents.detail(vc(Ce))})]),j({title:Xe==="pause"?"Agent paused":"Agent resumed",body:Ce.name,tone:"success"})},"onSuccess"),onError:r((fe,{agent:Ce,action:Xe})=>{j({title:Xe==="pause"?"Could not pause agent":"Could not resume agent",body:fe instanceof Error?fe.message:Ce.name,tone:"error"})},"onError"),onSettled:r((fe,Ce,{agent:Xe})=>{i(Oe=>{const tt=new Set(Oe);return tt.delete(Xe.id),tt})},"onSettled")}),ne=(0,m.useCallback)(fe=>E.mutate({resourceType:"agent",resourceId:fe.id,resourceName:fe.name,state:"left"}),[E]),ae=(0,m.useCallback)(fe=>E.isPending&&E.variables?.resourceType==="agent"&&E.variables.resourceId===fe.id,[E.isPending,E.variables]),me=(0,m.useCallback)((fe,Ce)=>E.mutate({resourceType:"agent",resourceId:fe.id,resourceName:fe.name,starred:Ce}),[E]),he=(0,m.useCallback)(fe=>E.isPending&&E.variables?.resourceType==="agent"&&E.variables.resourceId===fe.id&&E.variables.starred!==void 0,[E.isPending,E.variables]),Ie=(0,m.useMemo)(()=>new Set(y5(R.data,"agent")),[R.data]),de=(0,m.useMemo)(()=>wJ(K.filter(fe=>Ie.has(fe.id)),"alphabetical"),[K,Ie]),ve=(0,m.useMemo)(()=>le.filter(fe=>!Ie.has(fe.id)),[le,Ie]),Te=r((fe,Ce)=>(0,t.jsx)(zYe,{activeAgentId:J,activeTab:Q,agent:fe,disabled:a.has(fe.id),isMobile:p,leaving:ae(fe),onLeaveAgent:ne,onPauseResume:r((Xe,Oe)=>re.mutate({agent:Xe,action:Oe}),"onPauseResume"),rail:y,runCount:q.get(fe.id)??0,setSidebarOpen:x,builtInStatus:C.get(fe.id),starred:Ce||i0(R.data,"agent",fe.id),onToggleStar:me,starPending:he(fe)},fe.id),"renderAgentRow");return(0,t.jsxs)(cx,{label:"Agents",collapsible:{open:s,onOpenChange:n},headerAction:{ariaLabel:"New agent",icon:xn,onClick:h},menu:{ariaLabel:"Agents section actions",actions:[{type:"item",label:"Browse agents",icon:Xo,href:"/agents/all"},{type:"separator"}],radioLabel:"Agent sort",radioChoices:BYe,radioValue:V,onRadioValueChange:pe},children:[de.map(fe=>Te(fe,!0)),ve.map(fe=>Te(fe,!1)),oe&&(()=>{const fe=(0,t.jsxs)(Qe,{to:"/agents/all",state:lf,"aria-label":y?"See all agents":void 0,onClick:r(()=>{p&&x(!1)},"onClick"),className:"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(Xo,{className:"shrink-0 h-4 w-4"}),(0,t.jsx)("span",{className:y?"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none":void 0,children:"See all agents"})]});return y?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:fe}),(0,t.jsx)(Kn,{side:"right",children:"See all agents"})]}):fe})()]})}r(UYe,"SidebarAgents");var KYe="opacity-0 transition-opacity group-hover/starred-project:opacity-100 group-focus-within/starred-project:opacity-100";function VYe(){const{selectedCompanyId:e}=fs(),{isMobile:s,setSidebarOpen:n,collapsed:a,peeking:i}=$a(),o=a&&!i,l=Zr(),{data:c}=ee({queryKey:P.projects.list(e),queryFn:r(()=>oa.list(e),"queryFn"),enabled:!!e}),d=cf(e),u=df(e),h=l.pathname.match(/^\/(?:[^/]+\/)?projects\/([^/]+)/)?.[1]??null,p=(0,m.useMemo)(()=>{if(!d.isSuccess)return[];const y=new Set(y5(d.data,"project"));if(y.size===0)return[];const j=new Map((c??[]).map(S=>[S.id,S]));return Array.from(y).map(S=>j.get(S)).filter(S=>!!S).sort((S,w)=>S.name.localeCompare(w.name,void 0,{sensitivity:"base"}))},[d.data,d.isSuccess,c]),x=(0,m.useCallback)(y=>u.mutate({resourceType:"project",resourceId:y.id,resourceName:y.name,starred:!1}),[u]),g=(0,m.useCallback)(y=>u.mutate({resourceType:"project",resourceId:y.id,resourceName:y.name,state:"left"}),[u]),v=(0,m.useCallback)(y=>u.isPending&&u.variables?.resourceType==="project"&&u.variables.resourceId===y.id,[u.isPending,u.variables]);return!d.isSuccess||p.length===0?null:(0,t.jsx)("div",{className:"flex flex-col gap-0.5","aria-label":"Starred projects",children:p.map(y=>{const j=s0(y),S=h===j||h===y.id,w=v(y),N=w&&u.variables?.starred===!1,_=w&&u.variables?.state==="left",I=i0(d.data,"project",y.id),C=(0,t.jsxs)(r0,{to:`/projects/${j}/issues`,state:lf,onClick:r(()=>{s&&n(!1)},"onClick"),className:U("flex min-w-0 flex-1 items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 pr-8 text-(length:--text-compact) font-medium transition-colors",!o&&"pl-6",S?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground"),children:[(0,t.jsx)(Km,{color:y.color??null,icon:y.icon??null,size:"xs"}),(0,t.jsx)("span",{className:o?bv:"flex-1 truncate",children:y.name}),!o&&y.pauseReason==="budget"?(0,t.jsx)(x1,{title:"Project paused by budget"}):null]});return(0,t.jsxs)("div",{className:"group/starred-project relative flex items-center",children:[o?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("div",{className:"min-w-0 flex-1",children:C})}),(0,t.jsx)(Kn,{side:"right",children:y.name})]}):C,!o&&!s?(0,t.jsx)("span",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:(0,t.jsx)(o0,{size:"row",quiet:!0,starred:I,pending:N,resourceName:y.name,onToggle:r(()=>x(y),"onToggle"),revealClassName:KYe})}):null,!o&&s?(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"absolute right-3 top-1/2 h-6 w-6 -translate-y-1/2 opacity-100","aria-label":`Open actions for ${y.name}`,children:(0,t.jsx)(Pi,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(ga,{align:"end",className:"w-48",children:[(0,t.jsxs)(ps,{onClick:r(()=>{w||x(y)},"onClick"),disabled:w,children:[N?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Th,{className:"size-4 fill-amber-500 text-amber-500"}),(0,t.jsx)("span",{children:"Remove from starred"})]}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{w||g(y)},"onClick"),disabled:w,children:[_?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Yh,{className:"size-4"}),(0,t.jsx)("span",{children:"Leave project"})]})]})]}):null]},y.id)})})}r(VYe,"SidebarStarredProjects");var $xe="size-5 shrink-0 rounded-md text-(length:--text-micro)",Oxe="size-(--organization-popover-avatar-size) shrink-0 rounded-lg text-(length:--text-micro)",Fxe="h-(--organization-popover-company-row-height) min-w-0 gap-(--organization-popover-row-gap) rounded-lg px-2.5 py-0 text-(length:--text-compact) focus:bg-accent/50 focus:text-foreground",B4="h-(--organization-popover-action-row-height) gap-(--organization-popover-row-gap) rounded-lg px-2.5 py-0 text-(length:--text-compact) font-medium leading-(--organization-popover-action-line-height) text-foreground focus:bg-accent/50 focus:text-foreground";function Bxe({company:e,inPopover:s=!1}){return(0,t.jsx)(Rx,{companyName:e.name,logoUrl:e.logoUrl,className:s?Oxe:$xe})}r(Bxe,"WorkspaceIcon");function WYe({displayName:e}){return(0,t.jsx)(Rx,{companyName:e,className:Oxe})}r(WYe,"StackIcon");function HYe({displayName:e,company:s}){return(0,t.jsx)(Rx,{companyName:e,logoUrl:s?.logoUrl,className:$xe})}r(HYe,"CurrentStackIcon");function QYe({stack:e,isSelected:s,onSelect:n}){return(0,t.jsxs)(ps,{onSelect:r(()=>n(e),"onSelect"),className:Fxe,children:[(0,t.jsx)(WYe,{displayName:e.displayName}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block truncate font-medium leading-(--organization-popover-name-line-height)",title:e.displayName,children:e.displayName}),(0,t.jsx)("span",{className:"block truncate text-(length:--text-nano) leading-(--organization-popover-prefix-line-height) text-muted-foreground",title:e.stackSlug,children:e.stackSlug})]}),(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center",children:s?(0,t.jsx)(xs,{className:"size-4 text-foreground"}):null})]})}r(QYe,"CloudStackItem");function GYe({company:e,isEditing:s,isSelected:n,onSelect:a}){const{attributes:i,listeners:o,setActivatorNodeRef:l,setNodeRef:c,transform:d,transition:u,isDragging:h}=Lw({id:e.id,disabled:!s});return(0,t.jsxs)(ps,{ref:c,style:{transform:Pw.Transform.toString(d),transition:u,zIndex:h?10:void 0},onSelect:r(p=>{if(s){p.preventDefault();return}a(e)},"onSelect"),className:U(Fxe,s&&"cursor-grab",h&&"opacity-80"),children:[(0,t.jsx)(Bxe,{company:e,inPopover:!0}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block truncate font-medium leading-(--organization-popover-name-line-height)",children:e.name}),s?null:(0,t.jsx)("span",{className:"block truncate text-(length:--text-nano) leading-(--organization-popover-prefix-line-height) text-muted-foreground",children:e.issuePrefix})]}),s?(0,t.jsx)("button",{type:"button",ref:l,"aria-label":`Reorder ${e.name}`,className:"inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-(length:--rad-2) focus-visible:ring-ring",onClick:r(p=>{p.preventDefault(),p.stopPropagation()},"onClick"),...i,...o,children:(0,t.jsx)(fz,{className:"size-4","aria-hidden":"true"})}):(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center",children:n?(0,t.jsx)(xs,{className:"size-4 text-foreground"}):null})]})}r(GYe,"SortableCompanyItem");function YYe(e={}){return(0,t.jsx)(Jue,{...e,children:(0,t.jsx)(JYe,{...e})})}r(YYe,"SidebarCompanyMenu");function JYe({open:e,onOpenChange:s}){const[n,a]=(0,m.useState)(!1),[i,o]=(0,m.useState)(!1),{companies:l,selectedCompany:c,setSelectedCompanyId:d,companyListUnavailable:u,retryCompanies:h}=fs(),{openOnboarding:p}=Lo(),{isMobile:x,setSidebarOpen:g,collapsed:v,peeking:y}=$a(),j=v&&!y,S=Zr(),w=Wn(),N=e??n,_=s??a,I=Dw(Yp(Z6,{activationConstraint:{distance:8}}),Yp(Hle,{activationConstraint:{delay:180,tolerance:6}})),C=(0,m.useMemo)(()=>l.filter(Q=>Q.status!=="archived"),[l]),{data:A}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),R=A?.user?.id??A?.session?.userId??null,{orderedCompanies:E,persistOrder:O}=Gue({companies:C,userId:R}),L=Vc(),$=!!L,{hidden:T,loaded:q}=Ym(),B=q&&!LS(T,"company.members")&&!LS(T,"company.invites"),K=L?.cloudBaseUrl??null,z=ee({queryKey:P.cloud.stacks,queryFn:r(()=>Hue.listStacks(),"queryFn"),enabled:$,staleTime:3e4,retry:!1}),D=z.data?.stacks??[],V=$?D.find(Q=>Q.isCurrent)??D.find(Q=>!!L?.stackSlug&&Q.stackSlug===L?.stackSlug)??null:null,H=$?C5(K):null,Z=$?"organization":"company",Y=$?V?.displayName??L?.stackDisplayName??L?.stackSlug??null:c?.name??null,ie=Hw({onSignedOut:X});function se(Q){Q||o(!1),_(Q)}r(se,"handleOpenChange");function X(){_(!1),o(!1),x&&g(!1)}r(X,"closeNavigationChrome");function le(Q){const pe=S.pathname.split("/")[1]?.toUpperCase(),re=C.some(ae=>ae.issuePrefix.toUpperCase()===pe),ne=Q.id!==c?.id&&(S.pathname.startsWith("/instance/")||re);d(Q.id),_(!1),x&&g(!1),ne&&w(`/${Q.issuePrefix}/dashboard`)}r(le,"selectCompany");function oe(Q){if(_(!1),x&&g(!1),Q.stackSlug===V?.stackSlug)return;const pe=Yue(K,Q.stackSlug);pe&&jc(pe)}r(oe,"selectStack");function te(){if(_(!1),x&&g(!1),$){H&&jc(H);return}p({initialStep:1})}r(te,"addCompany");const J=(0,m.useCallback)(Q=>{const{active:pe,over:re}=Q;if(!re||pe.id===re.id)return;const ne=E.map(he=>he.id),ae=ne.indexOf(pe.id),me=ne.indexOf(re.id);ae===-1||me===-1||O(Z3(ne,ae,me))},[E,O]);return(0,t.jsxs)(xa,{open:N,onOpenChange:se,children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsxs)(F,{variant:"ghost",className:"h-9 min-w-0 flex-1 justify-start gap-2 px-4 text-left hover:bg-accent/50 hover:text-foreground has-[>svg]:px-4 dark:hover:bg-accent/50","aria-label":Y?`Open ${Y} ${Z} switcher`:`Open ${Z} switcher`,children:[(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[$?Y?(0,t.jsx)(HYe,{displayName:Y,company:c}):null:c?(0,t.jsx)(Bxe,{company:c}):null,(0,t.jsx)("span",{className:U("min-w-0 truncate text-sm font-bold text-foreground",j&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),title:Y??void 0,children:Y??($?"Select organization":"Select company")})]}),!j&&(0,t.jsx)(i5,{className:"size-3.5 shrink-0 text-muted-foreground"})]})}),(0,t.jsxs)(ga,{align:"start",sideOffset:8,className:"ml-2 w-(--organization-popover-width) max-w-(--sz-calc-24) overflow-hidden rounded-xl border-border bg-popover p-0 shadow-(--shadow-profile-popover)",children:[(0,t.jsxs)("div",{className:"flex h-(--organization-popover-header-height) items-center justify-between gap-2 px-3.5",children:[(0,t.jsx)(Ow,{className:"p-0 text-(length:--text-compact) font-semibold text-foreground",children:"Organizations"}),$?null:(0,t.jsx)("button",{type:"button",onClick:r(Q=>{Q.preventDefault(),Q.stopPropagation(),o(pe=>!pe)},"onClick"),className:"rounded px-1.5 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:i?"Done":"Edit"})]}),(0,t.jsx)("div",{className:"flex max-h-96 flex-col gap-0.5 overflow-y-auto px-2.5 pb-2 pt-1",children:$?(0,t.jsxs)(t.Fragment,{children:[D.map(Q=>(0,t.jsx)(QYe,{stack:Q,isSelected:Q.stackSlug===V?.stackSlug,onSelect:oe},Q.stackSlug)),D.length===0?(0,t.jsx)(ps,{disabled:!0,children:z.isLoading?"Loading organizations...":z.isError?"Could not load organizations":"No organizations"}):null]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ew,{sensors:I,collisionDetection:GC,onDragEnd:J,children:(0,t.jsx)(Tw,{items:E.map(Q=>Q.id),strategy:HC,children:E.map(Q=>(0,t.jsx)(GYe,{company:Q,isEditing:i,isSelected:Q.id===c?.id,onSelect:le},Q.id))})}),E.length===0?u?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ps,{disabled:!0,children:"Couldn't load companies"}),(0,t.jsxs)(ps,{onSelect:r(Q=>{Q.preventDefault(),h()},"onSelect"),children:[(0,t.jsx)(zi,{className:"h-4 w-4 mr-2"}),"Try again"]})]}):(0,t.jsx)(ps,{disabled:!0,children:"No companies"}):null]})}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5 border-t border-border px-2.5 pb-2.5 pt-2",children:[$&&!H?null:(0,t.jsxs)(ps,{onClick:te,className:B4,disabled:i,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(xn,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:"Create organization"})]}),B?(0,t.jsx)(ps,{asChild:!0,disabled:i,className:B4,children:(0,t.jsxs)(Qe,{to:"/company/settings/invites",onClick:r(Q=>{if(i){Q.preventDefault();return}X()},"onClick"),children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Sv,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Y?`Invite people to ${Y}`:"Invite people"})]})}):null,A?.session?(0,t.jsxs)(ps,{className:B4,onClick:r(()=>ie.mutate(),"onClick"),disabled:i||ie.isPending,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:ie.isPending?"Signing out...":"Sign out"})]}):null]})]})]})}r(JYe,"BuiltinCompanyMenu");function NJ(){const{openNewIssue:e}=Lo(),[s,n]=(0,m.useState)(!0),[a,i]=(0,m.useState)(!0),{selectedCompanyId:o,selectedCompany:l}=fs(),{collapsed:c,peeking:d}=$a(),u=c&&!d,h=Hz(o),{data:p}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")}),x=P.liveRuns(o),g=mo({companyId:o,resourceKey:"live-runs",queryKey:x,enabled:!!o,refetchInterval:!1,leaderOnly:!0}),{data:v,dataUpdatedAt:y}=ee({queryKey:x,queryFn:r(()=>Xr.liveRunsForCompany(o),"queryFn"),enabled:g.enabled,refetchInterval:g.refetchInterval});ho(g,v,y);const j=v?.length??0,S=p?.enableIsolatedWorkspaces===!0,w=p?.enableApps===!0,N=p?.enablePipelines===!0,_=p?.enableStatusCards===!0,I=p===void 0,C=p?.enableGoalsSidebarLink===!0,A=p?.enableDecisions===!0,{data:R}=ee({queryKey:P.attention(o),queryFn:r(()=>k5.list(o),"queryFn"),enabled:!!o&&A,refetchInterval:6e4}),E=kue(R),O=p?.enableCases===!0,L=!0,$=p?.enableConferenceRoomChat===!0,T={companyId:o,companyPrefix:l?.issuePrefix??null};return(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsx)("div",{className:"flex items-center gap-1 px-3 h-12 shrink-0",children:(0,t.jsx)(YYe,{})}),(0,t.jsxs)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide flex flex-col gap-4 pointer-coarse:gap-3 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(()=>{const q=(0,t.jsxs)("button",{onClick:r(()=>e(),"onClick"),"data-slot":"icon-button","aria-label":u?"New Task":void 0,className:"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium text-foreground/80 hover:bg-accent/50 hover:text-foreground transition-colors",children:[(0,t.jsx)(h1,{className:"h-4 w-4 shrink-0"}),(0,t.jsx)("span",{className:u?bv:"truncate",children:"New Task"})]});return u?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:q}),(0,t.jsx)(Kn,{side:"right",children:"New Task"})]}):q})(),(0,t.jsx)(Ha,{to:"/search",label:"Search",icon:pa}),(0,t.jsx)(Ha,{to:"/dashboard",label:"Dashboard",icon:lx,liveCount:j}),(0,t.jsx)(Ha,{to:"/inbox",label:"Inbox",icon:Td,badge:h.inbox,badgeLabel:"unread",badgeTone:h.failedRuns>0?"danger":"default",alert:h.failedRuns>0}),A?(0,t.jsx)(Ha,{to:"/decisions",label:"Decisions",icon:m1,badge:E,badgeLabel:"decisions"}):null,_?(0,t.jsx)(Ha,{to:"/status",label:"Status",icon:Kw,textBadge:"beta"}):null,$?(0,t.jsx)(Ha,{to:"/board-chat",label:"Conference Room",icon:hde}):null]}),(0,t.jsxs)(cx,{label:"Work",collapsible:{open:s,onOpenChange:n},children:[(0,t.jsx)(Ha,{to:"/issues",label:"Tasks",icon:ad}),O?(0,t.jsx)(Ha,{to:"/cases",label:"Cases",icon:hl,textBadge:"beta"}):null,(0,t.jsx)(Ha,{to:"/routines",label:"Routines",icon:du}),N?(0,t.jsx)(Ha,{to:"/pipelines",label:"Pipelines",icon:sl}):null,C?(0,t.jsx)(Ha,{to:"/goals",label:"Goals",icon:px}):I?(0,t.jsx)("div",{"data-testid":"sidebar-goals-placeholder",className:"h-8 pointer-coarse:h-7","aria-hidden":"true"}):null,(0,t.jsx)(Ha,{to:"/artifacts",label:"Artifacts",icon:Eh}),(0,t.jsx)(Ha,{to:"/skills",label:"Skills",icon:Bl}),S?(0,t.jsx)(Ha,{to:"/workspaces",label:"Workspaces",icon:sl}):null,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ha,{to:"/projects",label:"Projects",icon:Io}),(0,t.jsx)(VYe,{})]}),(0,t.jsx)(zh,{slotTypes:["sidebar"],context:T,className:"flex flex-col gap-0.5",itemClassName:"text-(length:--text-compact) font-medium",missingBehavior:"placeholder"}),(0,t.jsx)(Ww,{placementZones:["sidebar"],context:T,className:"flex flex-col gap-0.5",itemClassName:"text-(length:--text-compact) font-medium"})]}),null,(0,t.jsx)(UYe,{streamlined:L}),(0,t.jsxs)(cx,{label:"Company",collapsible:{open:a,onOpenChange:i},children:[(0,t.jsx)(Ha,{to:"/org",label:"Org",icon:Kb}),w?(0,t.jsx)(Ha,{to:"/apps",label:"Connectors",icon:qR}):null,(0,t.jsx)(Ha,{to:"/timeline",label:"Timeline",icon:vg}),(0,t.jsx)(Ha,{to:"/costs",label:"Costs",icon:_h}),(0,t.jsx)(Ha,{to:"/activity",label:"Activity",icon:Nl}),(0,t.jsx)(Ha,{to:"/company/settings",label:"Settings",icon:Dd})]}),(0,t.jsx)(zh,{slotTypes:["sidebarPanel"],context:T,className:"flex flex-col gap-3",itemClassName:"rounded-lg border border-border p-3",missingBehavior:"placeholder"})]})]})}r(NJ,"Sidebar");function XYe(e){const s=e.manifestJson.environmentDrivers??[];return s.length===0?!1:s.every(n=>n.kind==="sandbox_provider")}r(XYe,"isSandboxProviderOnly");function ZYe(){const{selectedCompany:e,selectedCompanyId:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),{hidden:i}=Ym(),o=r(x=>!i.has(x),"showPage"),l=o("instance.plugins"),c=!!Vc(),{slots:d}=Kc({slotTypes:["companySettingsPage"],companyId:s,enabled:!!s}),{data:u}=ee({queryKey:s?P.sidebarBadges(s):["sidebar-badges","__disabled__"],queryFn:r(async()=>{try{return await sme.get(s)}catch(x){if(x instanceof Nn&&(x.status===401||x.status===403))return null;throw x}},"queryFn"),enabled:!!s,retry:!1,refetchInterval:15e3}),{data:h}=ee({queryKey:P.plugins.all,queryFn:r(()=>Jo.list(),"queryFn"),enabled:l}),p=(h??[]).filter(x=>!XYe(x));return(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsx)("div",{className:"flex flex-col gap-1 px-3 py-3 shrink-0",children:(0,t.jsxs)(Qe,{to:"/dashboard",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:e?.name??"Company"})]})}),(0,t.jsx)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide px-3 py-2",children:(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/company/settings",label:"General",icon:Xu,end:!0}),o("instance.profile")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/profile",label:"Profile",icon:p1,end:!0}),o("company.members")&&(0,t.jsx)(Ha,{to:"/company/settings/members",label:"Members",icon:Xo,badge:u?.joinRequests??0,end:!0}),d.filter(x=>x.routePath).map(x=>(0,t.jsx)(Ha,{to:`/company/settings/${x.routePath}`,label:x.displayName,icon:Eg,end:!0},`${x.pluginKey}:${x.id}`)),o("company.invites")&&(0,t.jsx)(Ha,{to:"/company/settings/invites",label:"Invites",icon:i5e,end:!0}),o("company.secrets")&&(0,t.jsx)(Ha,{to:"/company/settings/secrets",label:"Secrets",icon:ji,end:!0}),o("instance.environments")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/environments",label:"Environments",icon:pde,end:!0}),o("instance.access")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/access",label:"Access",icon:r5,end:!0}),o("instance.heartbeats")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/heartbeats",label:"Heartbeats",icon:Xm,end:!0}),o("company.export")&&(0,t.jsx)(Ha,{to:"/company/export",label:"Export",icon:Ko}),!c&&o("company.import")&&(0,t.jsx)(Ha,{to:"/company/import",label:"Import",icon:Yj,end:!0}),o("instance.experimental")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/experimental",label:"Experimental",icon:Gu}),l&&(0,t.jsx)(Ha,{to:"/company/settings/instance/plugins",label:"Plugins",icon:Eg}),l&&p.length>0?(0,t.jsx)("div",{className:"ml-4 mt-1 flex flex-col gap-0.5 border-l border-border/70 pl-3",children:p.map(x=>(0,t.jsx)(r0,{to:`${xh}/plugins/${x.id}`,state:lf,className:r(({isActive:g})=>["rounded-md px-2 py-1.5 text-xs transition-colors",g?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"].join(" "),"className"),children:x.manifestJson.displayName??x.packageName},x.id))}):null,o("instance.adapters")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/adapters",label:"Adapters",icon:Pm})]})})]})}r(ZYe,"CompanySettingsSidebar");function eJe(){const{pathname:e}=Zr(),{selectedCompany:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),i=cme(),{enabled:o}=_5(),l=Xz.filter(d=>!lme(d.key)||o);if(e.endsWith("/apps/chat/connect"))return(0,t.jsx)(Iz,{});const c=e.match(/\/apps\/chat\/([^/]+)(?:\/(?:settings|access|reviews|conversations|activity))?\/?$/);return c?(0,t.jsx)(ome,{endpointId:c[1],NavItem:Ha}):(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 px-3 py-3 shrink-0",children:[(0,t.jsxs)(Qe,{to:"/dashboard",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:s?.name??"Company"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1",children:[(0,t.jsx)(aH,{className:"h-4 w-4 text-muted-foreground shrink-0"}),(0,t.jsx)("span",{className:"flex-1 truncate text-sm font-bold text-foreground",children:"Connectors"})]})]}),(0,t.jsxs)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide px-3 py-2",children:[(0,t.jsx)("div",{className:"px-3 pb-1 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Connectors"}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/apps",label:"Browse",icon:qS,end:!0}),(0,t.jsx)(Ha,{to:"/apps/review",label:"Review",icon:Vw,badge:i>0?i:void 0,badgeTone:"warning",badgeLabel:"waiting for your OK"})]}),(0,t.jsx)("div",{className:"px-3 pb-1 pt-4 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Developer"}),(0,t.jsx)("p",{className:"px-3 pb-1.5 text-(length:--text-micro) leading-snug text-muted-foreground/70",children:"Advanced setup for developers. Most teams never open this."}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/apps/connections",label:"Connections",icon:aH,end:!0}),l.map(d=>(0,t.jsx)(Ha,{to:Mg(d.key),label:d.label,icon:d.icon,end:!0},d.key))]})]})]})}r(eJe,"AppsSidebar");function kJ(e){const{selectedCompanyId:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),i=ee({queryKey:P.tools.connection(e.kind==="connection"?e.connectionId:"__none__"),queryFn:r(()=>us.getConnection(e.kind==="connection"?e.connectionId:""),"queryFn"),enabled:e.kind==="connection"&&!!e.connectionId}),o=ee({queryKey:P.tools.applications(s??"__none__"),queryFn:r(()=>us.listApplications(s),"queryFn"),enabled:e.kind==="application"&&!!s}),l=ee({queryKey:P.tools.connections(s??"__none__"),queryFn:r(()=>us.listConnections(s),"queryFn"),enabled:e.kind==="application"&&!!s}),c=ee({queryKey:P.apps.gallery(s??"__none__"),queryFn:r(()=>us.listGallery(s),"queryFn"),enabled:!!s}),d=ee({queryKey:P.apps.attention(s??"__none__"),queryFn:r(()=>us.listAppsAttention(s),"queryFn"),enabled:!!s,refetchInterval:3e4}),u=i.data,h=e.kind==="application"?(o.data?.applications??[]).find(S=>S.id===e.applicationId):null,p=nJe(e.kind==="application"?(l.data?.connections??[]).filter(S=>S.applicationId===e.applicationId):[]),x=u?Zp(u):h?.name??"App",g=sJe(c.data?.apps??[],u,h??void 0),v=u?.id??p?.id??null,y=v?d.data?.apps.find(S=>S.connection.id===v):null,j=(y?.pendingActionRequestCount??0)+((y?.quarantinedCatalogEntryCount??0)>0?1:0);return(0,t.jsxs)("aside",{className:"flex h-full min-h-0 w-full flex-col border-r border-border bg-background",children:[(0,t.jsxs)("div",{className:"flex shrink-0 flex-col gap-3 px-3 py-3",children:[(0,t.jsxs)(Qe,{to:"/apps/connections",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:"All apps"})]}),(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 px-2 py-1",children:[(0,t.jsx)(bc,{name:x,logoUrl:y1(g),size:28}),(0,t.jsx)("span",{className:"flex-1 truncate text-sm font-bold text-foreground",children:x})]})]}),(0,t.jsx)("nav",{className:"scrollbar-auto-hide min-h-0 flex-1 overflow-y-auto px-3 py-2",children:(0,t.jsx)("div",{className:"flex flex-col gap-0.5",children:I5.map(S=>(0,t.jsx)(Ha,{to:tJe(e,S.key),label:S.label,icon:S.icon,end:!0,badge:S.key==="review"&&j>0?j:void 0,badgeTone:"danger",badgeLabel:"needing review"},S.key))})})]})}r(kJ,"AppDetailSidebar");function tJe(e,s){return e.kind==="connection"?Bu(e.connectionId,s):iS(e.applicationId,s)}r(tJe,"tabHref");function sJe(e,s,n){if(n?.applicationKey){const i=e.find(o=>$c(o)===n.applicationKey);if(i)return i}const a=(s?.name??n?.name)?.toLowerCase();return a?e.find(i=>Gg(i).toLowerCase()===a)??e.find(i=>$c(i)===a)??null:null}r(sJe,"galleryEntryFor$1");function nJe(e){const s=e.filter(n=>n.status==="archived");return s.length===0?null:s.reduce((n,a)=>{const i=new Date(n.updatedAt??n.createdAt??0).getTime();return new Date(a.updatedAt??a.createdAt??0).getTime()>i?a:n})}r(nJe,"latestArchivedConnection$1");function q4({identifier:e}){return e?(0,t.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:e}):null}r(q4,"CrumbIdentifier");function rJe({context:e}){const{slots:s}=Kc({slotTypes:["globalToolbarButton"],companyId:e.companyId}),{launchers:n}=Qz({placementZones:["globalToolbarButton"],companyId:e.companyId,enabled:!!e.companyId});return(0,t.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-1 pl-2 empty:hidden",children:[s.length>0?(0,t.jsx)(zh,{slotTypes:["globalToolbarButton"],context:e,className:"flex items-center gap-1"}):null,n.length>0?(0,t.jsx)(Ww,{placementZones:["globalToolbarButton"],context:e,className:"flex items-center gap-1"}):null]})}r(rJe,"GlobalToolbar");function aJe(){const{breadcrumbs:e,mobileToolbar:s}=$n(),{toggleSidebar:n,isMobile:a}=$a(),{selectedCompanyId:i,selectedCompany:o}=fs(),l=(0,m.useMemo)(()=>({companyId:i??null,companyPrefix:o?.issuePrefix??null}),[i,o?.issuePrefix]),c=(0,t.jsx)(rJe,{context:l});if(a&&s)return(0,t.jsx)("div",{className:"border-b border-border px-2 h-12 shrink-0 flex items-center",children:s});if(e.length===0)return(0,t.jsx)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center justify-end",children:c});const d=a&&(0,t.jsx)(F,{variant:"ghost",size:"icon-sm",className:"mr-2 shrink-0",onClick:n,"aria-label":"Open sidebar",children:(0,t.jsx)(ude,{className:"h-5 w-5"})});return e.length===1?(0,t.jsxs)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center",children:[d,(0,t.jsx)("div",{className:"min-w-0 overflow-hidden flex-1",children:e[0].leading||e[0].identifier?(0,t.jsxs)("h1",{className:"flex items-center gap-1.5 text-sm font-semibold uppercase tracking-wider",children:[e[0].leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:e[0].leading}),(0,t.jsx)(q4,{identifier:e[0].identifier}),(0,t.jsx)("span",{className:"truncate",children:e[0].label})]}):(0,t.jsx)("h1",{className:"text-sm font-semibold uppercase tracking-wider truncate",children:e[0].label})}),c]}):(0,t.jsxs)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center",children:[d,(0,t.jsx)("div",{className:"min-w-0 overflow-hidden flex-1",children:(0,t.jsx)(Zz,{className:"min-w-0 overflow-hidden",children:(0,t.jsx)(eU,{className:"flex-nowrap",children:e.map((u,h)=>{const p=h===e.length-1;return(0,t.jsxs)(m.Fragment,{children:[h>0&&(0,t.jsx)(XR,{}),(0,t.jsx)(oS,{className:p?"min-w-0":"shrink-0",children:p||!u.href?u.leading||u.identifier?(0,t.jsxs)(QS,{className:"flex min-w-0 items-center gap-1.5",children:[u.leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:u.leading}),(0,t.jsx)(q4,{identifier:u.identifier}),(0,t.jsx)("span",{className:"truncate",children:u.label})]}):(0,t.jsx)(QS,{className:"truncate",children:u.label}):(0,t.jsx)(JR,{asChild:!0,children:u.leading||u.identifier?(0,t.jsxs)(Qe,{to:u.href,onClick:u.onClick,className:"flex items-center gap-1.5",children:[u.leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:u.leading}),(0,t.jsx)(q4,{identifier:u.identifier}),(0,t.jsx)("span",{className:"truncate",children:u.label})]}):(0,t.jsx)(Qe,{to:u.href,onClick:u.onClick,children:u.label})})})]},h)})})})}),c]})}r(aJe,"BreadcrumbBar");var fI=240,$F=208,OF=420,SJ=16;function ET(e){return Math.min(OF,Math.max($F,e))}r(ET,"clampSidebarWidth");function CJ(e){if(typeof window>"u")return fI;try{const s=window.localStorage.getItem(e);if(!s)return fI;const n=Number.parseInt(s,10);return Number.isFinite(n)?ET(n):fI}catch{return fI}}r(CJ,"readStoredSidebarWidth");function _J(e,s){if(!(typeof window>"u"))try{window.localStorage.setItem(e,String(ET(s)))}catch{}}r(_J,"writeStoredSidebarWidth");function iJe({children:e,open:s,collapsed:n=!1,peeking:a=!1,resizable:i=!1,storageKey:o="paperclip.sidebar.width",className:l,onPanelMouseEnter:c,onPanelMouseLeave:d,onPanelFocusCapture:u,onPanelBlurCapture:h}){const[p,x]=(0,m.useState)(()=>CJ(o)),[g,v]=(0,m.useState)(!1),y=(0,m.useRef)(p),j=(0,m.useRef)(null);(0,m.useEffect)(()=>{const T=CJ(o);y.current=T,x(T)},[o]);const S=s?p:0,w=s?n?64:S:0,N=s?n&&!a?64:S:0,_=N>w,I=i&&s&&!n,C=(0,m.useMemo)(()=>({width:`${w}px`}),[w]),A=(0,m.useMemo)(()=>({width:`${N}px`}),[N]),R=(0,m.useCallback)(T=>{const q=ET(T);y.current=q,x(q),_J(o,q)},[o]),E=(0,m.useCallback)(T=>{I&&(T.preventDefault(),T.currentTarget.setPointerCapture(T.pointerId),j.current={startX:T.clientX,startWidth:y.current},v(!0))},[I]),O=(0,m.useCallback)(T=>{if(!j.current)return;const q=ET(j.current.startWidth+T.clientX-j.current.startX);y.current=q,x(q)},[]),L=(0,m.useCallback)(()=>{j.current&&(j.current=null,v(!1),_J(o,y.current))},[o]),$=(0,m.useCallback)(T=>{I&&(T.key==="ArrowLeft"?(T.preventDefault(),R(p-SJ)):T.key==="ArrowRight"?(T.preventDefault(),R(p+SJ)):T.key==="Home"?(T.preventDefault(),R($F)):T.key==="End"&&(T.preventDefault(),R(OF)))},[I,R,p]);return(0,t.jsx)("div",{className:U("relative h-full shrink-0",l),style:C,children:(0,t.jsxs)("div",{className:U("absolute inset-y-0 left-0 flex flex-col overflow-hidden",_?"z-30 border-r border-border bg-background shadow-lg":"z-0"),style:A,"data-sidebar-overlay":_?"":void 0,onMouseEnter:c,onMouseLeave:d,onFocusCapture:u,onBlurCapture:h,children:[e,I?(0,t.jsx)("div",{role:"separator","aria-label":"Resize sidebar","aria-orientation":"vertical","aria-valuemin":$F,"aria-valuemax":OF,"aria-valuenow":p,tabIndex:0,className:U("absolute inset-y-0 right-0 z-20 w-3 cursor-col-resize touch-none outline-none","before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-transparent before:transition-colors","hover:before:bg-border focus-visible:before:bg-ring",g&&"before:bg-ring"),onPointerDown:E,onPointerMove:O,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:L,onKeyDown:$}):null]})})}r(iJe,"SidebarShell");function oJe({children:e,className:s}){return(0,t.jsx)("div",{"data-secondary-sidebar":"",className:U("h-full w-60 shrink-0 overflow-y-auto border-r border-border bg-background",s),children:(0,t.jsx)($Ye,{children:e})})}r(oJe,"SecondarySidebar");var lJe="/company/settings/instance/profile",cJe="https://docs.paperclip.ing/",dJe="https://paperclip.ing/feedback";function uJe(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?`${s[0]?.[0]??""}${s[s.length-1]?.[0]??""}`.toUpperCase():e.slice(0,2).toUpperCase()}r(uJe,"deriveInitials$1");function mJe(e,s,n){const a=[e,s?.split("@")[0],s,n];for(const i of a){const o=i?.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(o)return o}return"me"}r(mJe,"deriveUserSlug");function z4({label:e,description:s,icon:n,onClick:a,href:i,external:o=!1}){const l="flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-accent/60",c=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(n,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:e}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:s})]})]});return i?o?(0,t.jsx)("a",{href:i,target:"_blank",rel:"noreferrer",className:l,onClick:a,children:c}):(0,t.jsx)(Qe,{to:i,className:l,onClick:a,children:c}):(0,t.jsx)("button",{type:"button",className:l,onClick:a,children:c})}r(z4,"MenuAction");function IJ({deploymentMode:e,open:s,onOpenChange:n}){const a=!!Vc(),[i,o]=(0,m.useState)(!1),{isMobile:l,setSidebarOpen:c,collapsed:d,peeking:u}=$a(),h=d&&!u,p=s??i,x=n??o,{data:g}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),v=Hw({onSignedOut:N}),y=g?.user.name?.trim()||"Board",j=g?.user.email?.trim()||(e==="authenticated"?"Signed in":"Local workspace board"),S=uJe(y),w=`/u/${mJe(g?.user.name,g?.user.email,g?.user.id)}`;function N(){x(!1),l&&c(!1)}r(N,"closeNavigationChrome");function _(){v.mutate()}return r(_,"handleSignOut"),(0,t.jsx)("div",{className:"border-t border-r border-border bg-background px-3 py-2",children:(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",!h&&"px-2"),children:[(0,t.jsxs)(sr,{open:p,onOpenChange:x,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:U("flex min-w-0 items-center gap-2.5 rounded-lg text-left text-(length:--text-compact) font-medium text-foreground/80 transition-colors hover:bg-accent/50 hover:text-foreground",h?"w-full px-3 py-2":"flex-1 px-2 py-1.5"),"aria-label":"Open account menu",children:[(0,t.jsxs)(Yi,{size:"sm",children:[g?.user.image?(0,t.jsx)(zc,{src:g.user.image,alt:y}):null,(0,t.jsx)(Ji,{children:S})]}),(0,t.jsx)("span",{className:U("min-w-0 flex-1 truncate",h&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),children:y})]})}),(0,t.jsxs)(Gn,{side:"top",align:"start",sideOffset:10,className:"w-(--sz-277px) max-w-(--sz-calc-24) overflow-hidden rounded-t-2xl rounded-b-none border-border p-0 shadow-2xl",children:[(0,t.jsx)("div",{className:"h-24 bg-(image:--gradient-extract-25)"}),(0,t.jsxs)("div",{className:"-mt-8 px-4 pb-4",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"rounded-2xl border-4 border-popover bg-popover p-0.5 shadow-sm",children:(0,t.jsxs)(Yi,{size:"lg",children:[g?.user.image?(0,t.jsx)(zc,{src:g.user.image,alt:y}):null,(0,t.jsx)(Ji,{children:S})]})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 pt-1",children:[(0,t.jsx)("h2",{className:"truncate text-base font-semibold text-foreground",children:y}),(0,t.jsx)("p",{className:"truncate text-sm text-muted-foreground",children:j})]})]}),(0,t.jsxs)("div",{className:"mt-4 space-y-1",children:[(0,t.jsx)(z4,{label:"View profile",description:"Open your activity, task, and usage ledger.",icon:pu,href:w,onClick:N}),(0,t.jsx)(z4,{label:"Edit profile",description:"Update your display name and avatar.",icon:p1,href:lJe,onClick:N}),(0,t.jsx)(z4,{label:"Documentation",description:"Open Paperclip docs in a new tab.",icon:Uw,href:cJe,external:!0,onClick:r(()=>x(!1),"onClick")}),(0,t.jsx)(Cj,{variant:"menu-action",onAfterToggle:r(()=>x(!1),"onAfterToggle")}),e==="authenticated"?(0,t.jsxs)("button",{type:"button",className:U("flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-destructive/10",v.isPending&&"cursor-not-allowed opacity-60"),onClick:_,disabled:v.isPending,children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:v.isPending?"Signing out...":"Sign out"}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:"End this browser session."})]})]}):null,(0,t.jsx)(Cxe,{})]})]})]})]}),!h&&!a?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("a",{href:dJe,target:"_blank",rel:"noreferrer","aria-label":"Share feedback",className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground/50 transition-colors hover:bg-accent/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:(0,t.jsx)(_x,{className:"h-4 w-4","aria-hidden":"true"})})}),(0,t.jsx)(Kn,{side:"top",children:"Share feedback"})]}):null]})})}r(IJ,"SidebarAccountMenu");function hJe(e,s){return qxe(e,s)[0]?.toLowerCase()??null}r(hJe,"getCompanyRouteSegment");function qxe(e,s){if(!s)return[];const n=e.split("/").filter(Boolean);return n.length<2?[]:n[0]?.toUpperCase()!==s.toUpperCase()?[]:n.slice(1)}r(qxe,"getCompanyPathSegments");var pJe=new Set(["browse","connections","connect","chat","review","attention","gateways","advanced","app"]);function fJe(e,s){const n=e.split("/").filter(Boolean);return n[0]?.toLowerCase()==="skills"?!0:s?n[0]?.toUpperCase()===s.toUpperCase()&&n[1]?.toLowerCase()==="skills":!1}r(fJe,"isSkillsStoreRoute");function xJe(){const{sidebarOpen:e,setSidebarOpen:s,toggleSidebar:n,collapsed:a,peeking:i,setPeeking:o,isMobile:l,setForceCollapsed:c}=$a(),{openNewIssue:d,openOnboarding:u}=Lo(),{togglePanelVisible:h}=uf(),p=Nc()?.pushToast??null,{companies:x,loading:g,selectedCompany:v,selectedCompanyId:y,selectionSource:j,setSelectedCompanyId:S}=fs(),{companyPrefix:w,pluginRoutePath:N}=ja(),_=Wn(),I=Zr(),C=J3(),A=["/company/settings","/company/export","/company/import"].some(rt=>I.pathname.includes(rt)),R=qxe(I.pathname,w),E=R[0]?.toLowerCase()==="tools",O=R[0]?.toLowerCase()==="apps",L=O&&R[1]&&!pJe.has(R[1].toLowerCase())?R[1]:null,$=O&&R[1]?.toLowerCase()==="app"&&R[2]?R[2]:null,T=fJe(I.pathname,w),q=(0,m.useRef)(!1),B=(0,m.useRef)(0),K=(0,m.useRef)(null),z=(0,m.useRef)(null),D=(0,m.useRef)(new Ode),V=(0,m.useRef)(I.key),[H,Z]=(0,m.useState)(!0),[Y,ie]=(0,m.useState)(!1),se=(0,m.useMemo)(()=>{if(!w)return null;const rt=w.toUpperCase();return x.find(jt=>jt.issuePrefix.toUpperCase()===rt)??null},[x,w]),X=!!w&&!g&&x.length>0&&!se,le=(0,m.useMemo)(()=>N?.toLowerCase()??hJe(I.pathname,w),[w,I.pathname,N]),oe=se?.id??null,te=se?.issuePrefix??null,{slots:J}=Kc({slotTypes:["page","routeSidebar"],companyId:oe,enabled:!!(oe&&le)}),Q=(0,m.useMemo)(()=>Fz(J,le),[le,J]),pe=(0,m.useMemo)(()=>({companyId:oe,companyPrefix:te}),[oe,te]),re=A?(0,t.jsx)(ZYe,{}):L?(0,t.jsx)(kJ,{kind:"connection",connectionId:L}):$?(0,t.jsx)(kJ,{kind:"application",applicationId:$}):O||E?(0,t.jsx)(eJe,{}):Q?(0,t.jsx)(fu,{slot:Q,context:pe,className:"h-full w-full",missingBehavior:"placeholder"}):null,ne=re!=null,{data:ae}=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1,refetchInterval:r(rt=>rt.state.data?.devServer?.enabled?2e3:!1,"refetchInterval"),refetchIntervalInBackground:!1}),me=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn")}).data?.keyboardShortcuts===!0,he=ne||T;(0,m.useLayoutEffect)(()=>(c(he),()=>c(!1)),[he,c]),(0,m.useEffect)(()=>{g||q.current||ae?.deploymentMode!=="authenticated"&&(ae?.cloud||x.length===0&&(q.current=!0,u()))},[x,g,u,ae?.cloud,ae?.deploymentMode]),(0,m.useEffect)(()=>{if(!w||g||x.length===0)return;if(!se){const jt=(y?x.find(st=>st.id===y):null)??x[0]??null;jt&&y!==jt.id&&S(jt.id,{source:"route_sync"});return}if(w!==se.issuePrefix){const jt=I.pathname.replace(/^\/[^/]+/,"");_(`/${se.issuePrefix}${jt}${I.search}`,{replace:!0});return}const rt=Exe({matchedCompany:se,selectedCompanyId:y,companies:x});if(rt){p?.({title:`${se.name} is archived`,body:`Switched to ${rt.name}.`,tone:"info",dedupeKey:`archived-company-bounce:${se.id}`}),S(rt.id,{source:"route_sync"}),_(`/${rt.issuePrefix}/dashboard`,{replace:!0});return}Pxe({selectionSource:j,selectedCompanyId:y,routeCompanyId:se.id})&&S(se.id,{source:"route_sync"})},[w,x,g,se,I.pathname,I.search,_,p,j,y,S]);const Ie=h,de=(0,m.useCallback)(()=>{document.dispatchEvent(new KeyboardEvent("keydown",{key:"k",metaKey:!0,bubbles:!0,cancelable:!0}))},[]),ve=(0,m.useRef)(null),Te=(0,m.useRef)(!1),fe=(0,m.useRef)(!1),Ce=(0,m.useCallback)(()=>{ve.current!==null&&(window.clearTimeout(ve.current),ve.current=null)},[]),Xe=(0,m.useCallback)(()=>{Ce(),ve.current=window.setTimeout(()=>o(!0),50)},[Ce,o]),Oe=(0,m.useCallback)(()=>{Ce(),o(!0)},[Ce,o]),tt=(0,m.useCallback)(()=>{Ce(),ve.current=window.setTimeout(()=>o(!1),120)},[Ce,o]),ce=(0,m.useCallback)(()=>{Te.current=!0,a&&!fe.current&&Xe()},[a,Xe]),$e=(0,m.useCallback)(()=>{Te.current=!1,fe.current=!1,tt()},[tt]),mt=(0,m.useCallback)(()=>{fe.current||Oe()},[Oe]),it=(0,m.useCallback)(()=>{Te.current||tt()},[tt]);(0,m.useEffect)(()=>Ce,[Ce]);const Ke=(0,m.useRef)(a);(0,m.useEffect)(()=>{a!==Ke.current&&(a?(Ce(),o(!1),fe.current=Te.current):fe.current=!1,Ke.current=a)},[a,Ce,o]),(0,m.useEffect)(()=>{if(!i)return;const rt=r(jt=>{jt.key==="Escape"&&(Ce(),o(!1))},"onKeyDown");return window.addEventListener("keydown",rt),()=>window.removeEventListener("keydown",rt)},[i,Ce,o]),Txe(),_xe({enabled:me,onNewIssue:r(()=>d(),"onNewIssue"),onSearch:de,onToggleSidebar:n,onTogglePanel:Ie,onShowShortcuts:r(()=>ie(!0),"onShowShortcuts"),onGoToInbox:r(()=>_("/inbox"),"onGoToInbox")}),(0,m.useEffect)(()=>{if(!l){Z(!0);return}B.current=0,Z(!0)},[l]),(0,m.useEffect)(()=>{if(!l)return;const rt=30,jt=50,st=75;let Nt=0,at=0;const Ee=r(He=>{const St=He.touches[0];Nt=St.clientX,at=St.clientY},"onTouchStart"),Ne=r(He=>{const St=He.changedTouches[0],Ft=St.clientX-Nt;if(!(Math.abs(St.clientY-at)>st)){if(!e&&Nt<rt&&Ft>jt){s(!0);return}e&&Ft<-50&&s(!1)}},"onTouchEnd");return document.addEventListener("touchstart",Ee,{passive:!0}),document.addEventListener("touchend",Ne,{passive:!0}),()=>{document.removeEventListener("touchstart",Ee),document.removeEventListener("touchend",Ne)}},[l,e,s]);const Ge=(0,m.useCallback)(rt=>{const jt=rt-B.current;rt<=24?Z(!0):jt>8?Z(!1):jt<-8&&Z(!0),B.current=rt},[]);return(0,m.useEffect)(()=>{if(!l){Z(!0),B.current=0;return}const rt=r(()=>{Ge(window.scrollY||document.documentElement.scrollTop||0)},"onScroll");return rt(),window.addEventListener("scroll",rt,{passive:!0}),()=>{window.removeEventListener("scroll",rt)}},[l,Ge]),(0,m.useEffect)(()=>{const rt=document.body.style.overflow;return document.body.style.overflow=l?"visible":"clip",()=>{document.body.style.overflow=rt}},[l]),(0,m.useEffect)(()=>{if(!l)return Dxe()},[l]),(0,m.useEffect)(()=>{if(typeof document>"u")return;const rt=z.current;return Mxe(rt)},[I.pathname]),(0,m.useEffect)(()=>{const rt=z.current;if(!rt)return;const jt=r(()=>{D.current.remember(V.current,rt.scrollTop)},"recordScroll");return rt.addEventListener("scroll",jt,{passive:!0}),()=>rt.removeEventListener("scroll",jt)},[]),(0,m.useLayoutEffect)(()=>{const rt=z.current,jt=$de({previousPathname:K.current,pathname:I.pathname,navigationType:C,state:I.state});K.current=I.pathname;const st=C==="POP",Nt=st?D.current.recall(I.key):0;if(V.current=I.key,st){UR(rt,Nt);const at=requestAnimationFrame(()=>UR(rt,Nt));return()=>cancelAnimationFrame(at)}jt&&Fde(rt)},[I.key,I.pathname,I.state,C]),(0,t.jsx)(Lde,{children:(0,t.jsx)(Wle,{value:{keyboardShortcutsEnabled:me},children:(0,t.jsxs)("div",{className:U("bg-background text-foreground pt-(--sz-safe-top)",l?"min-h-dvh overflow-x-clip":"flex h-dvh flex-col overflow-clip"),children:[(0,t.jsx)("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-(--z-200) focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Skip to Main Content"}),(0,t.jsx)(jxe,{}),(0,t.jsx)(wxe,{devServer:ae?.devServer}),(0,t.jsxs)("div",{className:U("min-h-0 flex-1",l?"w-full":"flex overflow-clip"),children:[l&&e&&(0,t.jsx)("button",{type:"button",className:"fixed inset-0 z-40 bg-black/50",onClick:r(()=>s(!1),"onClick"),"aria-label":"Close sidebar"}),l?(0,t.jsxs)("div",{className:U("fixed inset-y-0 left-0 z-50 flex flex-col overflow-hidden pt-(--sz-safe-top) transition-transform duration-100 ease-out",e?"translate-x-0":"-translate-x-full"),children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:(0,t.jsx)("div",{className:"w-60 shrink-0 overflow-hidden",children:ne?re:(0,t.jsx)(NJ,{})})}),(0,t.jsx)(IJ,{deploymentMode:ae?.deploymentMode})]}):(0,t.jsxs)(iJe,{open:e,collapsed:a,peeking:i,resizable:!0,onPanelMouseEnter:ce,onPanelMouseLeave:$e,onPanelFocusCapture:a?mt:void 0,onPanelBlurCapture:a?it:void 0,children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0",children:(0,t.jsx)(NJ,{})}),(0,t.jsx)(IJ,{deploymentMode:ae?.deploymentMode})]}),!l&&ne?(0,t.jsx)(oJe,{children:re}):null,(0,t.jsxs)("div",{className:U("flex min-w-0 flex-col",l?"w-full":"h-full flex-1"),children:[(0,t.jsxs)("div",{className:U(l&&"sticky top-0 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85"),children:[(0,t.jsx)(MF,{mobile:l}),(0,t.jsx)(aJe,{}),l&&A?(0,t.jsx)("div",{className:"border-b border-border px-4 pb-3",children:(0,t.jsx)(ime,{})}):null]}),(0,t.jsxs)("div",{className:U(l?"block":"flex flex-1 min-h-0"),children:[(0,t.jsx)("main",{id:"main-content",ref:z,tabIndex:-1,style:l?{"--tc-composer-bottom":H?"var(--sz-calc-14)":"var(--sz-calc-8)"}:void 0,className:U("flex-1 p-4 outline-none md:p-6",l?"overflow-visible pb-(--sz-calc-14)":"overflow-auto [scrollbar-gutter:stable]"),children:X?(0,t.jsx)(uu,{scope:"invalid_company_prefix",requestedPrefix:w??v?.issuePrefix}):(0,t.jsx)(Sxe,{children:(0,t.jsx)(n0,{})})}),(0,t.jsx)(bme,{})]})]})]}),l&&(0,t.jsx)(yxe,{visible:H}),(0,t.jsx)(jme,{}),(0,t.jsx)(Eme,{}),(0,t.jsx)(mxe,{}),(0,t.jsx)(fxe,{}),(0,t.jsx)(xxe,{}),(0,t.jsx)(gxe,{open:Y,onOpenChange:ie}),(0,t.jsx)(bxe,{}),(0,t.jsx)(vxe,{localTrusted:ae?.deploymentMode==="local_trusted"})]})})})}r(xJe,"Layout");var AJ=null;function gJe(){return AJ??=new JC,AJ}r(gJe,"getDetachedClient");function bJe(){const e=(0,m.useContext)(H3),{data:s,isFetched:n}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),enabled:e!=null},e??gJe());return e?{enabled:s?.enableConferenceRoomChat===!0,loaded:n}:{enabled:!1,loaded:!0}}r(bJe,"useConferenceRoomChatEnabled");function vJe(){const{enabled:e,loaded:s}=bJe();return s?e?(0,t.jsx)(n0,{}):(0,t.jsx)(vn,{to:"/dashboard",replace:!0}):null}r(vJe,"ConferenceRoomChatGate");var yJe=["session-start","human-message","agent-message","thinking","responding","responding-burst","tool-call","diff","working","running","completed","activity-phases","awaiting-approval","plan-todo","interrupted","refused","truncated","live-token-cost"],jJe={"session-start":{id:"session-start",label:"Session start",tier:"live",surface:"thread",protocol:'acpx.session → TranscriptEntry kind:"init"'},"human-message":{id:"human-message",label:"Human message",tier:"live",surface:"thread",protocol:'IssueComment authorType:"user"'},"agent-message":{id:"agent-message",label:"Final response",tier:"live",surface:"thread",protocol:'PRP item.delta kind:"agentMessage" channel:"final"'},thinking:{id:"thinking",label:"Thinking",tier:"live",surface:"thread",protocol:"text_delta stream:thought (ACP agent_thought_chunk)"},responding:{id:"responding",label:"Progress update (streaming)",tier:"live",surface:"thread",protocol:'PRP item.delta kind:"agentMessage" channel:"progress"'},"responding-burst":{id:"responding-burst",label:"Progress update burst",tier:"live",surface:"thread",protocol:"text_delta stream:output ×N, tool calls between (PAP-368 dwell)"},"tool-call":{id:"tool-call",label:"Tool call",tier:"live",surface:"thread",protocol:"acpx.tool_call (ACP tool_call / tool_call_update)"},diff:{id:"diff",label:"Diff",tier:"live",surface:"thread",protocol:'ToolCallContent type:"diff" → TranscriptEntry kind:"diff"'},working:{id:"working",label:"Working",tier:"live",surface:"thread",protocol:"heartbeat.run.progress + acpx.status"},running:{id:"running",label:"Running",tier:"live",surface:"thread",protocol:'message.status.type === "running"'},completed:{id:"completed",label:"Completed (collapsed)",tier:"live",surface:"thread",protocol:"acpx.result (StopReason in subtype)"},"activity-phases":{id:"activity-phases",label:"Long-run activity phases",tier:"live",surface:"thread",protocol:"assistant boundaries + chronological tool calls"},"awaiting-approval":{id:"awaiting-approval",label:"Awaiting approval",tier:"tier-b",surface:"thread",protocol:"ACP RequestPermissionRequest + PermissionOptionKind"},"plan-todo":{id:"plan-todo",label:"Plan / todo",tier:"tier-b",surface:"plan",protocol:"ACP Plan { entries: PlanEntry[] }, PlanEntryStatus"},interrupted:{id:"interrupted",label:"Interrupted",tier:"tier-b",surface:"thread",protocol:'AcpRuntimeTurnResult.status:"cancelled" / StopReason "cancelled"'},refused:{id:"refused",label:"Refused",tier:"tier-b",surface:"thread",protocol:'StopReason "refusal"'},truncated:{id:"truncated",label:"Truncated",tier:"tier-b",surface:"thread",protocol:'StopReason "max_tokens" | "max_turn_requests"'},"live-token-cost":{id:"live-token-cost",label:"Live token / cost",tier:"tier-b",surface:"thread",protocol:"ACP UsageUpdate { used, size, cost }"}},b8t=yJe.map(e=>jJe[e]);function zxe({item:e}){return(0,t.jsx)("article",{className:"rounded-lg border border-border bg-card p-3","aria-label":`Project created: ${e.name}`,children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(C3e,{className:"mt-0.5 size-4 shrink-0 text-muted-foreground","aria-hidden":!0}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Project created"}),(0,t.jsx)(Qe,{to:`/projects/${e.projectId}`,className:"break-words text-sm font-medium hover:underline focus-visible:underline",children:e.name}),e.description&&(0,t.jsx)("p",{className:"line-clamp-3 text-sm text-muted-foreground",children:e.description}),e.repositories.length>0&&(0,t.jsx)("ul",{className:"space-y-1 pt-1",children:e.repositories.map(s=>(0,t.jsxs)("li",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[(0,t.jsx)(sl,{className:"size-3 shrink-0","aria-hidden":!0}),(0,t.jsx)("a",{className:"truncate hover:underline focus-visible:underline",href:s.url,target:"_blank",rel:"noreferrer",children:s.name})]},s.id))})]})]})})}r(zxe,"TaskChatProjectCreatedCard");function wJe({item:e,onOpen:s}){return(0,t.jsx)("article",{className:"rounded-lg border border-border bg-card p-3","aria-label":`Skill created: ${e.name}`,children:(0,t.jsxs)("button",{type:"button",className:"flex w-full items-start gap-3 text-left",onClick:r(()=>s?.(e.skillId,e.name),"onClick"),children:[(0,t.jsx)(fx,{className:"mt-0.5 size-4 shrink-0 text-muted-foreground","aria-hidden":!0}),(0,t.jsxs)("span",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:"Skill created"}),(0,t.jsx)("span",{className:"block break-words text-sm font-medium hover:underline focus-visible:underline",children:e.name}),e.description?(0,t.jsx)("span",{className:"block line-clamp-3 text-sm text-muted-foreground",children:e.description}):null]})]})})}r(wJe,"TaskChatSkillCreatedCard");var Uxe=(0,m.createContext)("streamlined");function NJe({mode:e,children:s}){return(0,t.jsx)(Uxe.Provider,{value:e,children:s})}r(NJe,"TaskChatPresentationProvider");function Xh(){return(0,m.useContext)(Uxe)==="streamlined"}r(Xh,"useStreamlinedTaskChatPresentation");function kJe(e){return(0,t.jsxs)("svg",{viewBox:"0 0 180 180",fill:"none",stroke:"currentColor",strokeWidth:14,strokeLinecap:"round",xmlns:"http://www.w3.org/2000/svg",...e,children:[(0,t.jsx)("path",{d:"M18 84.8528L85.8822 16.9706C95.2548 7.59798 110.451 7.59798 119.823 16.9706C129.196 26.3431 129.196 41.5391 119.823 50.9117L68.5581 102.177"}),(0,t.jsx)("path",{d:"M69.2652 101.47L119.823 50.9117C129.196 41.5391 144.392 41.5391 153.765 50.9117L154.118 51.2652C163.491 60.6378 163.491 75.8338 154.118 85.2063L92.7248 146.6C89.6006 149.724 89.6006 154.789 92.7248 157.913L105.331 170.52"}),(0,t.jsx)("path",{d:"M102.853 33.9411L52.6482 84.1457C43.2756 93.5183 43.2756 108.714 52.6482 118.087C62.0208 127.459 77.2167 127.459 86.5893 118.087L136.794 67.8822"})]})}r(kJe,"McpIcon");var SJe=new Set(["tool","tool call","tool_call","acp_tool"]);function _d(e){const s=(e??"").trim().toLowerCase().replace(/\s*\((?:pending|in[_ -]?progress|completed|failed|cancelled|canceled)\)$/,"");return!s||SJe.has(s)}r(_d,"isGenericToolName");function cK(e){const s=e.match(/^mcp__(.+?)__(.+)$/i);if(s)return{namespace:s[1],name:s[2]};const n=e.match(/^mcp\.([^.]+)\.(.+)$/i);return n?{namespace:n[1],name:n[2]}:null}r(cK,"mcpToolIdentity");function dK(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().toLowerCase().split(/\s+/).filter(Boolean)}r(dK,"identifierWords");function Kxe(e){if(e.length===0)return"";const s=e.map(n=>["api","id","lsp","mcp","pr","url"].includes(n)?n.toUpperCase():n).join(" ");return s.charAt(0).toUpperCase()+s.slice(1)}r(Kxe,"sentenceCase");function _j(e){const s=(e??"").trim();return _d(s)?"Unnamed tool":Kxe(dK(cK(s)?.name??s))}r(_j,"humanizeToolName");var td=r((e,s,n)=>({key:e,singular:s,plural:n}),"group"),CJe={bash:{action:"run"},terminal:{action:"run"},shell:{action:"run"},command:{action:"run"},run:{action:"run"},execute:{action:"run"},exec_command:{action:"run"},apply_patch:{action:"update",running:"Applying a patch",completed:"Applied a patch"},read:{action:"read",running:"Reading a file",completed:"Read a file"},write:{action:"update",running:"Writing a file",completed:"Wrote a file"},edit:{action:"update",running:"Editing a file",completed:"Edited a file"},notebook_read:{action:"read",running:"Reading a notebook",completed:"Read a notebook"},notebook_edit:{action:"update",running:"Editing a notebook",completed:"Edited a notebook"},glob:{action:"search",running:"Searching files",completed:"Searched files"},grep:{action:"search",running:"Searching file contents",completed:"Searched file contents",family:"grep"},tool_search:{action:"search",running:"Searching available tools",completed:"Searched available tools",group:td("tool_search","tool search","tool searches")},web_search:{action:"search",running:"Searching the web",completed:"Searched the web",family:"web"},web_fetch:{action:"fetch",running:"Fetching a web page",completed:"Fetched a web page",family:"web"},todo_write:{action:"update",running:"Updating the task list",completed:"Updated the task list",family:"plan",group:td("task_operation","task operation","task operations")},task_create:{action:"create",running:"Creating a task",completed:"Created a task",family:"plan",group:td("task_operation","task operation","task operations")},task_update:{action:"update",running:"Updating a task",completed:"Updated a task",family:"plan",group:td("task_operation","task operation","task operations")},task_list:{action:"list",running:"Listing tasks",completed:"Listed tasks",family:"plan",group:td("task_operation","task operation","task operations")},task_get:{action:"read",running:"Reading a task",completed:"Read a task",family:"plan",group:td("task_operation","task operation","task operations")},enter_plan_mode:{action:"switch",running:"Entering plan mode",completed:"Entered plan mode",family:"plan"},exit_plan_mode:{action:"switch",running:"Leaving plan mode",completed:"Left plan mode",family:"plan"},skill:{action:"read",running:"Loading a skill",completed:"Loaded a skill"},ask_user_question:{action:"request",running:"Requesting input",completed:"Requested input",family:"question"},request_human_input:{action:"request",running:"Requesting input",completed:"Requested input",family:"question",group:td("task_operation","task operation","task operations")},agent:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},task:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},task_output:{action:"read",running:"Checking subagent progress",completed:"Checked subagent progress",family:"agent"},task_stop:{action:"stop",running:"Stopping a subagent",completed:"Stopped a subagent",family:"agent"},send_message:{action:"post",running:"Messaging a subagent",completed:"Messaged a subagent",family:"agent"},spawn_agent:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},wait_agent:{action:"wait",running:"Checking subagent progress",completed:"Checked subagent progress",family:"agent"},wait_threads:{action:"wait",running:"Checking task progress",completed:"Checked task progress",family:"agent"},interrupt_agent:{action:"stop",running:"Interrupting a subagent",completed:"Interrupted a subagent",family:"agent"},report_findings:{action:"post",running:"Reporting findings",completed:"Reported findings",family:"safety"},guardian_review:{action:"think",running:"Reviewing safety",completed:"Reviewed safety",family:"safety"},lsp:{action:"read",running:"Inspecting code intelligence",completed:"Inspected code intelligence"},compact_conversation:{action:"think",running:"Compacting context",completed:"Compacted context"},image_generation:{action:"create",running:"Generating an image",completed:"Generated an image",family:"image"},view_image:{action:"read",running:"Viewing an image",completed:"Viewed an image",family:"image"},multi_tool_use_parallel:{action:"run",running:"Running tools in parallel",completed:"Ran tools in parallel"},get_task_context:{action:"read",running:"Reading task context",completed:"Read task context"},get_task_history:{action:"read",running:"Reading task history",completed:"Read task history"},list_documents:{action:"list",running:"Listing documents",completed:"Listed documents"},read_document:{action:"read",running:"Reading a document",completed:"Read a document"},list_document_revisions:{action:"list",running:"Listing document revisions",completed:"Listed document revisions"},report_progress:{action:"post",running:"Reporting progress",completed:"Reported progress"},answer_status_question:{action:"post",running:"Answering a status question",completed:"Answered a status question"},write_document:{action:"update",running:"Writing a document",completed:"Wrote a document"},register_deliverable:{action:"create",running:"Registering a deliverable",completed:"Registered a deliverable"},finish_task:{action:"finish",running:"Reporting completion",completed:"Reported completion"},paperclip_finish:{action:"finish",running:"Reporting completion",completed:"Reported completion"},block_task:{action:"block",running:"Reporting a blocker",completed:"Reported a blocker"},paperclip_block:{action:"block",running:"Reporting a blocker",completed:"Reported a blocker"},request_review:{action:"request",running:"Requesting review",completed:"Requested review"},list_agents:{action:"list",running:"Listing agents",completed:"Listed agents"},get_agent:{action:"read",running:"Reading agent details",completed:"Read agent details"},search_tasks:{action:"search",running:"Searching tasks",completed:"Searched tasks"},list_approvals:{action:"list",running:"Listing approvals",completed:"Listed approvals"},get_approval:{action:"read",running:"Reading an approval",completed:"Read an approval"},get_approval_context:{action:"read",running:"Reading approval context",completed:"Read approval context"},get_workspace_runtime:{action:"read",running:"Reading workspace status",completed:"Read workspace status"},control_workspace_service:{action:"run",running:"Controlling a workspace service",completed:"Controlled a workspace service"},set_dependencies:{action:"update",running:"Updating task dependencies",completed:"Updated task dependencies"},create_task:{action:"create",running:"Creating a task",completed:"Created a task"},request_approval:{action:"request",running:"Requesting approval",completed:"Requested approval"},decide_approval:{action:"update",running:"Deciding an approval",completed:"Decided an approval"},comment_on_approval:{action:"post",running:"Commenting on an approval",completed:"Commented on an approval"},schedule_wake:{action:"create",running:"Scheduling a wake-up",completed:"Scheduled a wake-up",family:"wait"},generic_api_request:{action:"request",running:"Calling the Paperclip API",completed:"Called the Paperclip API"}},_Je={read:["get","read","inspect","view"],list:["list","glob"],search:["find","search","grep","query","lookup"],fetch:["fetch","browse"],open:["open"],update:["write","edit","update","set","patch","upsert","sync"],create:["create","add","register","upload"],delete:["delete","remove"],move:["move","rename"],run:["run","execute","bash","shell","command"],request:["request","ask","prompt"],post:["send","message","comment","report","answer"],start:["start","spawn","delegate"],stop:["stop","cancel","interrupt"],wait:["wait","sleep","poll"],finish:["finish","complete"],block:["block"],think:["think","reason","compact","review"],switch:["switch","enter","exit"],other:[]},IJe={read:"read",edit:"update",delete:"delete",move:"move",search:"search",list:"list",execute:"run",think:"think",fetch:"fetch",switch_mode:"switch"};function AJe(e){return dK(e).join("_")}r(AJe,"normalizedKey");function RJe(e){const s=e[0];if(!s)return null;for(const[n,a]of Object.entries(_Je))if(a.includes(s))return n;return null}r(RJe,"inferredAction");function TJe(e){return e==="run"?"terminal":e==="read"||e==="list"?"read":e==="search"?"search":e==="fetch"||e==="open"?"web":["update","create","delete","move"].includes(e)?"edit":e==="request"?"question":e==="start"||e==="stop"?"agent":e==="wait"?"wait":"other"}r(TJe,"actionFamily");var EJe={terminal:zb,grep:nEe,search:pa,read:Uw,edit:m5,web:ATe,plan:m1,question:Rd,agent:Kb,safety:Ai,image:lde,wait:Xm,mcp:kJe,other:fx};function PJe(e,s){const n=s?` ${s}`:"";switch(e){case"read":return{running:`Reading${n||" data"}`,completed:`Read${n||" data"}`};case"list":return{running:`Listing${n||" items"}`,completed:`Listed${n||" items"}`};case"search":return{running:`Searching${n||""}`,completed:`Searched${n||""}`};case"fetch":return{running:`Fetching${n||" data"}`,completed:`Fetched${n||" data"}`};case"open":return{running:`Opening${n||" an item"}`,completed:`Opened${n||" an item"}`};case"update":return{running:`Updating${n||" data"}`,completed:`Updated${n||" data"}`};case"create":return{running:`Creating${n||" an item"}`,completed:`Created${n||" an item"}`};case"delete":return{running:`Deleting${n||" an item"}`,completed:`Deleted${n||" an item"}`};case"move":return{running:`Moving${n||" an item"}`,completed:`Moved${n||" an item"}`};case"run":return{running:"Running a command",completed:"Ran a command"};case"request":return{running:`Requesting${n||" input"}`,completed:`Requested${n||" input"}`};case"post":return{running:`Posting${n||" an update"}`,completed:`Posted${n||" an update"}`};case"start":return{running:`Starting${n||" an operation"}`,completed:`Started${n||" an operation"}`};case"stop":return{running:`Stopping${n||" an operation"}`,completed:`Stopped${n||" an operation"}`};case"wait":return{running:"Waiting",completed:"Finished waiting"};case"finish":return{running:"Reporting completion",completed:"Reported completion"};case"block":return{running:"Reporting a blocker",completed:"Reported a blocker"};case"think":return{running:"Thinking",completed:"Finished thinking"};case"switch":return{running:`Switching${n||" mode"}`,completed:`Switched${n||" mode"}`};case"other":return{running:"Running",completed:"Ran"}}}r(PJe,"actionCopy");function MJe(e){switch(e){case"run":return td("command","command","commands");case"read":case"list":return td("read","read","reads");case"search":return td("search","search","searches");case"update":case"create":case"delete":case"move":return td("file_change","file change","file changes");case"start":case"stop":return td("delegation","delegation","delegations");case"wait":return td("wait","wait","waits");default:return td("tool_action","tool action","tool actions")}}r(MJe,"defaultSummaryGroup");function DJe(e){return e==="read"||e==="list"?td("paperclip_read","Paperclip read","Paperclip reads"):td("task_operation","task operation","task operations")}r(DJe,"paperclipSummaryGroup");function ev(e){const s=(e.name??"").trim(),n=cK(s),a=(e.namespace??n?.namespace??"").trim(),i=(n?"mcp":e.transport??"builtin").toLowerCase(),o=(n?.name??s).trim(),l=dK(o),c=AJe(o),d=CJe[c],u=IJe[(e.operation??"").trim().toLowerCase()],h=RJe(l),p=d?.action??u??h??"other",x=d?"exact":u?"kind":h?"inferred":_d(o)?"unnamed":"fallback",g=_d(o)?"Unnamed tool":_j(o),v=/^[A-Za-z][A-Za-z0-9_.:-]*$/.test(o),y=h&&v&&l.length>1?l.slice(1):[],j=y.length?Kxe(y).replace(/^./,C=>C.toLowerCase()):void 0,S=d?.running&&d.completed?{running:d.running,completed:d.completed}:p==="other"?_d(o)?{running:"Running an unnamed tool",completed:"Ran an unnamed tool"}:{running:`Running ${g}`,completed:`Ran ${g}`}:PJe(p,d?void 0:j),w=d?.family??TJe(p),N=i==="mcp"?"mcp":w,_=a?_j(a):i==="mcp"?"MCP":void 0,I=a.toLowerCase()==="paperclip"?DJe(p):d?.group??MJe(p);return{icon:EJe[N],family:N,runningLabel:S.running,completedLabel:S.completed,failedLabel:`${S.completed} · failed`,interruptedLabel:`${S.running} · stopped`,displayName:g,sourceLabel:_,technicalName:s||void 0,confidence:x,summaryGroup:I}}r(ev,"toolActivityPresentation");function eE(e){const s=ev({name:e});return{family:s.family,icon:s.icon,verbLabel:s.runningLabel}}r(eE,"toolTaxonomy");function LJe(e){const s=(e??"").trim().toLowerCase();return s==="thinking"?Tg:s==="responding"||s.startsWith("responding (")?x5e:null}r(LJe,"statusLabelIcon");var U4=["Clipping","Organizing","Sorting","Synthesizing","Analyzing","Filing","Collating","Stapling","Indexing","Annotating","Drafting","Proofreading","Alphabetizing","Photocopying","Laminating","Hole-punching","Bookmarking","Highlighting","Typing","Trimming","Aligning","Combining","Whiteboarding","Diagramming","Sketching","Labeling","Sticky-noting"],K4=["Brewing","Tinkering","Distilling","Deliberating"],RJ=(()=>{const e=[],s=Math.max(U4.length,K4.length);for(let n=0;n<s;n++)n<U4.length&&e.push(U4[n]),n<K4.length&&e.push(K4[n]);return e})(),$Je=1e4;function OJe(e){const s=(e??"").trim().toLowerCase();return s==="running"||s==="working"}r(OJe,"isGenericStatusLabel");function FJe(e){let s=2166136261;for(let n=0;n<e.length;n++)s^=e.charCodeAt(n),s=Math.imul(s,16777619);return s>>>0}r(FJe,"fnv1a");function BJe(e,s=0){const n=Math.floor(Math.max(0,s)/$Je);return RJ[(FJe(e)+n)%RJ.length]}r(BJe,"whimsyWord");var qJe=[{name:"--motion-ease-out-expo",group:"Easing",kind:"easing"},{name:"--motion-ease-standard",group:"Easing",kind:"easing"},{name:"--motion-ease-out",group:"Easing",kind:"easing"},{name:"--motion-ease-scroll-pill-in",group:"Easing",kind:"easing"},{name:"--motion-ease-scroll-pill-out",group:"Easing",kind:"easing"},{name:"--motion-ease-in",group:"Easing",kind:"easing"},{name:"--motion-duration-instant",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-fast",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-base",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-slow",group:"Durations",kind:"time",min:0,max:1500,step:10},{name:"--motion-duration-deliberate",group:"Durations",kind:"time",min:0,max:2e3,step:10},{name:"--motion-duration-enter",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-exit",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-swap",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-marker-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-bubble-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-cot-line-stagger",group:"States",kind:"time",min:0,max:300,step:5},{name:"--motion-cot-collapse",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-tool-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-diff-reveal",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-status-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-status-exit",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-approval-pulse",group:"States",kind:"time",min:0,max:3e3,step:20},{name:"--motion-plan-entry-stagger",group:"States",kind:"time",min:0,max:300,step:5},{name:"--motion-plan-check",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-question-page-enter",group:"States",kind:"time",min:0,max:1e3,step:10},{name:"--motion-count-tween",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-streaming-cursor-blink",group:"States",kind:"time",min:0,max:3e3,step:20},{name:"--motion-turn-fold",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-turn-meta",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-line-scroll",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-interstitial-dwell",group:"States",kind:"time",min:0,max:1e4,step:100},{name:"--motion-scroll-pill-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-scroll-pill-exit",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-scrollbar-idle-delay",group:"States",kind:"time",min:0,max:2e3,step:10},{name:"--motion-pane-glide",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-side-panel-tab",group:"States",kind:"time",min:0,max:1500,step:10}],v8t=Array.from(new Set(qJe.map(e=>e.group)));function Vxe(e){const s=e.trim();if(s.endsWith("ms"))return parseFloat(s);if(s.endsWith("s"))return parseFloat(s)*1e3;const n=parseFloat(s);return Number.isFinite(n)?n:0}r(Vxe,"parseCssTimeMs");function zJe(e){if(e==null)return null;const s=Math.round(e/1e3);return s<60?`${s}s`:`${Math.floor(s/60)}m ${s%60}s`}r(zJe,"elapsedLabel");function UJe(e){if(e==null)return null;const s=Math.max(0,e)/1e3;return s<60?`${s.toFixed(1)}s`:`${Math.floor(s/60)}m ${(s%60).toFixed(1)}s`}r(UJe,"liveElapsedLabel");function KJe(e,s){const[n,a]=(0,m.useState)(()=>Date.now());return(0,m.useEffect)(()=>{if(e==null||!s)return;const i=window.setInterval(()=>a(Date.now()),100);return()=>window.clearInterval(i)},[e,s]),e==null?void 0:Math.max(0,n-e)}r(KJe,"useLiveElapsedMs");function VJe(e,s){return!Number.isFinite(e)||!Number.isFinite(s)||s<=0?0:Math.max(0,Math.round(e/s)-1)}r(VJe,"lineScrollOffset");function C2(e){const s=getComputedStyle(document.documentElement).getPropertyValue(e),n=Vxe(s);return Number.isFinite(n)?n:0}r(C2,"motionTokenMs");function WJe({text:e,streaming:s,leaving:n}){const a=(0,m.useRef)(null),[i,o]=(0,m.useState)(0),[l,c]=(0,m.useState)(!1),[d,u]=(0,m.useState)(!1);(0,m.useLayoutEffect)(()=>{const p=a.current;if(!p)return;const x=r(()=>{const v=parseFloat(window.getComputedStyle(p).lineHeight);o(VJe(p.scrollHeight,v))},"measure");if(x(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(x);return g.observe(p),()=>g.disconnect()},[e,s]),(0,m.useEffect)(()=>{const p=requestAnimationFrame(()=>c(!0)),x=window.setTimeout(()=>u(!0),C2("--motion-line-scroll"));return()=>{cancelAnimationFrame(p),window.clearTimeout(x)}},[]);const h=l?n?-1:s?-i:0:1;return(0,t.jsx)("span",{className:"tc-line-scroll min-w-0 flex-1","data-testid":"task-chat-live-self-talk","data-streaming":s||void 0,"data-leaving":n||void 0,children:(0,t.jsx)("span",{ref:a,className:U("tc-line-scroll-inner block",!s&&"truncate"),style:{transform:h!==0?`translateY(calc(${h} * 1lh))`:void 0,transition:d&&!n?"none":void 0},children:e})})}r(WJe,"LiveSelfTalkLine");function HJe(e,s){const[n,a]=(0,m.useState)(null),i=(0,m.useRef)(n),o=(0,m.useRef)(null),l=(0,m.useRef)(e),c=(0,m.useRef)(0),d=(0,m.useRef)(null),u=(0,m.useRef)(null),h=(0,m.useRef)(null);return l.current=e,(0,m.useEffect)(()=>{const p=r(j=>{j.current!=null&&(window.clearTimeout(j.current),j.current=null)},"clear"),x=r(j=>{i.current=j,a(j)},"show"),g=r(()=>{p(u),p(h),u.current=window.setTimeout(()=>{if(u.current=null,o.current!=null)return;const j=i.current;j==null||j.streaming||(x({...j,leaving:!0}),h.current=window.setTimeout(()=>{h.current=null,i.current?.leaving&&x(null)},C2("--motion-line-scroll")))},C2("--motion-interstitial-dwell"))},"scheduleLeave"),v=r((j,S)=>{p(u),p(h),c.current=Date.now(),x({text:j,streaming:S,swapKey:(i.current?.swapKey??0)+1}),S||g()},"swapIn");if(!s){p(d),p(u),p(h),o.current=null,i.current&&x(null);return}const y=i.current;if(e==null){y?.streaming&&(x({...y,streaming:!1}),g());return}if(y==null){v(e,!0);return}if(y.streaming){y.text!==e&&x({...y,text:e});return}if(o.current=e,d.current==null){const j=C2("--motion-interstitial-dwell"),S=Math.max(0,c.current+j-Date.now());d.current=window.setTimeout(()=>{d.current=null;const w=o.current;o.current=null,w!=null&&v(w,l.current!=null)},S)}},[e,s]),(0,m.useEffect)(()=>()=>{d.current!=null&&window.clearTimeout(d.current),u.current!=null&&window.clearTimeout(u.current),h.current!=null&&window.clearTimeout(h.current)},[]),n}r(HJe,"useHeldSelfTalk");var QJe={running:{Icon:ot,spin:!0,tone:"text-(--status-agent-running)"},working:{Icon:ot,spin:!0,tone:"text-(--status-agent-running)"},awaiting_approval:{Icon:Vw,spin:!1,tone:"text-primary"},interrupted:{Icon:yz,spin:!1,tone:"text-destructive"},refused:{Icon:qu,spin:!1,tone:"text-destructive"},truncated:{Icon:Z5e,spin:!1,tone:"text-(--status-agent-paused)"}};function Wxe({item:e,onApprovalDecision:s,chevronOpen:n,onToggle:a}){const{Icon:i,spin:o,tone:l}=QJe[e.status],c=e.status==="awaiting_approval",d=e.status==="running"||e.status==="working",u=KJe(e.startedAtMs,d),h=HJe(d?e.selfTalk:void 0,d),p=zJe(e.elapsedMs);if(d){const x=UJe(u??e.elapsedMs),g=e.selfTalk!=null,v=e.toolName?eE(e.toolName).icon:g?null:LJe(e.label),y=g||OJe(e.label)?BJe(e.id,u??e.elapsedMs??0):e.label,j=(0,t.jsxs)("div",{className:"tc-enter-status flex items-center gap-2 py-0.5 text-xs text-muted-foreground",children:[n!==void 0?(0,t.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center","data-testid":"task-chat-status-caret-slot",children:(0,t.jsx)(mn,{className:U("h-3 w-3 transition-transform",n?"rotate-90":null),"aria-hidden":!0})}):null,(0,t.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center","data-testid":"task-chat-status-dot-slot",children:(0,t.jsx)("span",{"aria-hidden":!0,className:"h-2 w-2 animate-pulse rounded-full bg-(--status-agent-running)"})}),v?(0,t.jsx)(v,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null,(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-baseline gap-2",children:[(0,t.jsxs)("span",{className:"shimmer-text shimmer-text-muted shrink-0 font-medium",children:[y,"…"]}),x?(0,t.jsx)("span",{className:"shrink-0 font-mono tabular-nums text-(length:--text-micro)",children:x}):null,e.detail?(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-(length:--text-micro)",children:e.detail}):null,e.tokens?(0,t.jsxs)("span",{className:"ml-auto shrink-0 font-mono text-(length:--text-micro)",children:[e.tokens.used.toLocaleString(),"/",e.tokens.size.toLocaleString()," ctx"]}):null]})]});return(0,t.jsxs)("div",{className:"flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 py-0.5 text-xs text-muted-foreground","data-testid":"task-chat-interstitial-row",children:[(0,t.jsx)("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 shrink-0"}),h?(0,t.jsx)(WJe,{text:h.text,streaming:h.streaming,leaving:h.leaving},h.swapKey):(0,t.jsx)("span",{"aria-hidden":!0,className:"tc-line-scroll min-w-0 flex-1"})]}),a?(0,t.jsx)("button",{type:"button",onClick:a,"aria-expanded":n,className:"-mx-1.5 block w-full rounded-sm px-1.5 text-left transition-colors hover:bg-muted/60","data-testid":"task-chat-live-turn",children:j}):j]})}return(0,t.jsxs)("div",{className:U("tc-enter-status flex flex-col gap-2 rounded-lg border px-3 py-2 text-sm",c?"tc-approval border-primary/40 bg-primary/5":"border-border bg-muted/40"),children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,t.jsx)(i,{className:U("h-4 w-4 shrink-0",l,o&&"animate-spin")}),(0,t.jsx)("span",{className:"min-w-0 truncate font-medium",children:e.label}),(0,t.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[p?(0,t.jsx)("span",{children:p}):null,e.tokens?(0,t.jsxs)("span",{children:[e.tokens.used.toLocaleString(),"/",e.tokens.size.toLocaleString()," ctx"]}):null]})]}),e.detail?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e.detail}):null,c&&e.approval?(0,t.jsx)("div",{className:"flex flex-wrap justify-end gap-2 pt-1",children:e.approval.options.map(x=>{const g=x.kind.startsWith("reject");return(0,t.jsx)("button",{type:"button",onClick:r(()=>s?.(x.id),"onClick"),className:U("rounded-md border px-2.5 py-1 text-xs font-medium transition-colors",g?"border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground":"border-primary bg-primary text-primary-foreground hover:bg-primary/90"),children:x.label},x.id)})}):null]})}r(Wxe,"TaskChatStatusPill");function Hxe(e,s){const n=URL.createObjectURL(s),a=document.createElement("a");a.href=n,a.download=e,a.rel="noreferrer",a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}r(Hxe,"downloadBlob$1");function GJe(e,s,n){Hxe(e,new Blob([s],{type:`${n};charset=utf-8`}))}r(GJe,"downloadTextFile");var V4="flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50";function Qxe({issueId:e,documentKey:s,title:n,format:a,body:i,className:o}){const[l,c]=(0,m.useState)(null),[d,u]=(0,m.useState)(null),[h,p]=(0,m.useState)(null),{copy:x,copied:g,failed:v}=nf(),y=(0,m.useRef)(void 0);(0,m.useEffect)(()=>()=>clearTimeout(y.current),[]);const j=(0,m.useCallback)(async(C,A)=>{c(C),p(null);try{await A(),u(C)}catch(R){u(null),p(R instanceof Error?R.message:"Export failed")}finally{c(null)}clearTimeout(y.current),y.current=setTimeout(()=>{u(null),p(null)},2e3)},[]),S=(0,m.useCallback)(async()=>i??(await Tt.getDocument(e,s)).body,[i,s,e]),w=(0,m.useCallback)(()=>{c("copy"),p(null),(async()=>{try{await x(await S())==="failed"&&p("Copy failed")}catch(C){p(C instanceof Error?C.message:"Copy failed")}finally{c(null)}})()},[x,S]),N=v||h==="Copy failed"?"Copy failed":g?"Copied!":"Copy full content",_=d==="download"?"Downloaded!":"Download source",I=d==="pdf"?"Downloaded!":"Export to PDF";return(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",o),"data-testid":"document-export-actions",children:[(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Copy full content",title:N,"data-testid":"document-export-copy",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),w()},"onClick"),children:g?(0,t.jsx)(xs,{"aria-hidden":"true",className:"h-3.5 w-3.5"}):(0,t.jsx)(jr,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Download source",title:_,"data-testid":"document-export-download",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),j("download",async()=>{const A=J2e(a);GJe(eH(n,A),await S(),A==="md"?"text/markdown":"text/plain")})},"onClick"),children:(0,t.jsx)(Ko,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Export to PDF",title:I,"data-testid":"document-export-pdf",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),j("pdf",async()=>{Hxe(eH(n,"pdf"),await Tt.getDocumentPdf(e,s))})},"onClick"),children:(0,t.jsx)(u3e,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("span",{className:"sr-only",role:"status","aria-live":"polite",children:h??(g?"Copied!":v?"Copy failed":d?"Downloaded!":"")})]})}r(Qxe,"DocumentExportActions");function cC({children:e,className:s}){return(0,t.jsx)("div",{className:U("relative aspect-video w-full overflow-hidden bg-accent/20",s),children:e})}r(cC,"PreviewFrame");function PT({label:e}){return(0,t.jsx)(cC,{className:"flex items-center justify-center",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5 text-muted-foreground/50",children:[(0,t.jsx)(zl,{className:"h-7 w-7","aria-hidden":"true"}),e?(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide",children:e}):null]})})}r(PT,"PlaceholderPreview");function YJe({artifact:e}){const[s,n]=(0,m.useState)(!1);return s||!e.contentPath?(0,t.jsx)(PT,{label:"Image"}):(0,t.jsx)(cC,{children:(0,t.jsx)("img",{src:e.contentPath,alt:e.title,loading:"lazy",className:"h-full w-full object-cover",onError:r(()=>n(!0),"onError")})})}r(YJe,"ImagePreview");function JJe({artifact:e}){const[s,n]=(0,m.useState)(!1),[a,i]=(0,m.useState)(!1),o=(0,m.useRef)(!1),l=(0,m.useRef)(null);if((0,m.useEffect)(()=>()=>{l.current!==null&&window.clearTimeout(l.current)},[]),s||!e.contentPath)return(0,t.jsx)(cC,{className:"flex items-center justify-center bg-black/80",children:(0,t.jsx)("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-white/15",children:(0,t.jsx)(_o,{className:"h-5 w-5 translate-x-0.5 text-white","aria-hidden":"true"})})});const c=r(()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),i(!0)},"markFrameReady"),d=r(()=>{l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(c,3e3)},"scheduleFrameReadyFallback"),u=r(p=>{if(o.current)return;o.current=!0;const x=p.currentTarget,g=Number.isFinite(x.duration)&&x.duration>0?x.duration:0,v=g>0?Math.min(1,g/4):.05;try{Math.abs(x.currentTime-v)>.001?(x.currentTime=v,d()):c()}catch{c()}},"loadThumbnailFrame"),h=r(p=>{(o.current||p.currentTarget.currentTime>0)&&c()},"handleLoadedData");return(0,t.jsxs)(cC,{className:"bg-black",children:[(0,t.jsx)("video",{src:e.contentPath,preload:"metadata",muted:!0,playsInline:!0,"data-frame-ready":a?"true":"false",className:U("h-full w-full object-contain transition-opacity",a?"opacity-100":"opacity-0"),onLoadedMetadata:u,onLoadedData:h,onSeeked:c,onError:r(()=>n(!0),"onError")}),(0,t.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:(0,t.jsx)("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-black/55",children:(0,t.jsx)(_o,{className:"h-5 w-5 translate-x-0.5 text-white","aria-hidden":"true"})})})]})}r(JJe,"VideoPreview");function XJe({artifact:e}){const s=e.previewText?.trim();return s?(0,t.jsxs)(cC,{className:"bg-card",children:[(0,t.jsx)("div",{className:"absolute inset-0 overflow-hidden p-3",children:(0,t.jsx)("p",{className:"max-h-full overflow-hidden whitespace-pre-wrap break-words text-base leading-6 text-muted-foreground/75",children:s})}),(0,t.jsx)("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-10 bg-gradient-to-t from-card to-transparent"})]}):(0,t.jsx)(PT,{label:e.source==="document"?"Document":"Text"})}r(XJe,"TextPreview");function T1({artifact:e}){switch(e.mediaKind){case"image":return(0,t.jsx)(YJe,{artifact:e},e.contentPath);case"video":return(0,t.jsx)(JJe,{artifact:e},e.contentPath);case"text":case"document":return(0,t.jsx)(XJe,{artifact:e});case"file":return(0,t.jsx)(PT,{label:"File"});default:return(0,t.jsx)(PT,{})}}r(T1,"ArtifactPreview");function TJ({href:e,download:s,title:n,children:a}){return(0,t.jsx)("a",{href:e,...s?{download:""}:{target:"_blank",rel:"noreferrer"},title:n,"aria-label":n,onClick:r(i=>i.stopPropagation(),"onClick"),className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:a})}r(TJ,"SecondaryAction");function ZJe({artifact:e}){return(0,t.jsxs)(Qe,{to:e.href,disableIssueQuicklook:!0,"data-testid":"artifact-card","data-media-kind":e.mediaKind,className:"group flex flex-col overflow-hidden rounded-lg border border-border bg-card cursor-pointer transition-colors hover:border-foreground/20 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,t.jsx)(T1,{artifact:e}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1 p-3",children:[(0,t.jsxs)("div",{className:"flex h-7 items-start justify-between gap-2",children:[(0,t.jsx)("h3",{className:"min-w-0 flex-1 truncate text-sm font-medium leading-7 text-foreground/85",title:e.title,children:e.title}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100",children:[e.source==="document"&&e.documentKey?(0,t.jsx)(Qxe,{issueId:e.issue.id,documentKey:e.documentKey,title:e.title}):null,e.openPath?(0,t.jsx)(TJ,{href:e.openPath,title:"Open file in new tab",children:(0,t.jsx)(xr,{className:"h-3.5 w-3.5"})}):null,e.downloadPath?(0,t.jsx)(TJ,{href:e.downloadPath,download:!0,title:"Download file",children:(0,t.jsx)(Ko,{className:"h-3.5 w-3.5"})}):null]})]}),(0,t.jsxs)("div",{className:"mt-0.5 flex items-center gap-1.5 text-(length:--text-micro) text-muted-foreground/65",children:[(0,t.jsxs)("span",{children:["Last edited ",cu(e.updatedAt)]}),e.createdByAgent?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"text-muted-foreground/50",children:"·"}),(0,t.jsx)("span",{className:"truncate",children:e.createdByAgent.name})]}):null]})]})]})}r(ZJe,"ArtifactCard");function Zw(e){if(!Number.isFinite(e)||e<0)return"0 B";if(e<1024)return`${Math.round(e)} B`;const s=["KB","MB","GB","TB"];let n=e/1024,a=0;for(;n>=1024&&a<s.length-1;)n/=1024,a+=1;const i=n.toFixed(1);return`${i.endsWith(".0")?i.slice(0,-2):i} ${s[a]}`}r(Zw,"formatBytes$5");var MT=new Set(["application/octet-stream","binary/octet-stream","application/x-binary"]),eXe=[".mp4",".m4v",".webm",".mov",".qt",".quicktime"],tXe=[".png",".jpg",".jpeg",".gif",".webp",".avif",".bmp",".svg",".ico"],sXe=new Set(["application/wasm"]),nXe=new Set(["application/zip","application/x-zip","application/x-zip-compressed"]),Gxe=new Set(["text/markdown","text/x-markdown","application/markdown","application/x-markdown"]),rXe=new Set(["application/csv","application/ecmascript","application/graphql","application/html","application/javascript","application/json","application/ld+json","application/sql","application/toml","application/x-httpd-php","application/x-javascript","application/x-python","application/x-sh","application/x-yaml","application/xhtml+xml","application/xml","application/yaml"]),aXe=[".csv",".css",".graphql",".htm",".html",".js",".json",".jsx",".log",".markdown",".md",".mdx",".php",".py",".sh",".sql",".toml",".ts",".tsx",".txt",".xml",".yaml",".yml"];function E1(e){return(e??"").toLowerCase().split(";")[0]?.trim()??""}r(E1,"normalizeOutputContentType");function iXe(e){const s=(e??"").trim().toLowerCase();return s?aXe.some(n=>s.endsWith(n)):!1}r(iXe,"hasDocumentLikeFilename");function Yxe(e){return nXe.has(e)||e.endsWith("+zip")}r(Yxe,"isZipContentType");function oXe(e){return e?!!(e.startsWith("text/")||Gxe.has(e)||rXe.has(e)||e.startsWith("application/")&&(e.endsWith("+json")||e.endsWith("+xml"))):!1}r(oXe,"isDocumentLikeOutputContentType");function lXe(e,s){const n=E1(e);return!n||oXe(n)||MT.has(n)&&iXe(s)?!1:n.startsWith("video/")||n.startsWith("image/")||n==="application/pdf"||sXe.has(n)||Yxe(n)||MT.has(n)}r(lXe,"isOutputEligibleContentType");function cXe(e){const s=E1(e);if(s.startsWith("video/")){const n=s.slice(6);return n==="quicktime"?{label:"MOV",tone:"video"}:{label:(n||"vid").toUpperCase().slice(0,4),tone:"video"}}return s==="application/pdf"?{label:"PDF",tone:"pdf"}:Yxe(s)?{label:"ZIP",tone:"zip"}:s.startsWith("image/")?{label:"IMG",tone:"image"}:Gxe.has(s)?{label:"MD",tone:"bin"}:s==="text/plain"?{label:"TXT",tone:"bin"}:s==="text/csv"||s==="application/csv"?{label:"CSV",tone:"bin"}:s==="text/html"||s==="application/html"||s==="application/xhtml+xml"?{label:"HTML",tone:"bin"}:s==="application/json"||s.endsWith("+json")?{label:"JSON",tone:"bin"}:s==="application/xml"||s==="text/xml"||s.endsWith("+xml")?{label:"XML",tone:"bin"}:s==="application/wasm"?{label:"WASM",tone:"bin"}:{label:"BIN",tone:"bin"}}r(cXe,"getOutputFileGlyph");function Ld(e,s){const n=E1(e);if(n.startsWith("video/"))return!0;if(!MT.has(n))return!1;const a=(s??"").trim().toLowerCase();return eXe.some(i=>a.endsWith(i))}r(Ld,"isVideoLikeOutput");function pw(e){return E1(e).startsWith("image/")}r(pw,"isImageContentType");function dC(e,s){const n=E1(e);if(pw(n))return!0;if(n&&!MT.has(n))return!1;const a=(s??"").trim().toLowerCase();return tXe.some(i=>a.endsWith(i))}r(dC,"isImageLikeOutput");function EJ(e){const s=new Date(e).getTime();return Number.isNaN(s)?0:s}r(EJ,"toTime");function tE(e){const s=(e??[]).filter(n=>n.type==="artifact"&&n.provider==="paperclip").flatMap(n=>{const a=vIe.safeParse(n.metadata);return a.success&&!lXe(a.data.contentType,a.data.originalFilename)?[]:[{id:n.id,title:n.title,status:typeof n.status=="string"?n.status:"active",isPrimary:!!n.isPrimary,createdAt:n.createdAt,metadata:a.success?a.data:null,degraded:!a.success,workProduct:n}]});return s.sort((n,a)=>n.isPrimary!==a.isPrimary?n.isPrimary?-1:1:EJ(a.createdAt)-EJ(n.createdAt)),{items:s,primary:s[0]??null,rest:s.slice(1),count:s.length}}r(tE,"getIssueOutputs");function uK(e){return e.metadata?.originalFilename||e.title||"output"}r(uK,"outputFilename");function Jxe(e){return new Set(tE(e).items.flatMap(s=>{const n=s.metadata?.attachmentId;return n?[n]:[]}))}r(Jxe,"getPromotedOutputAttachmentIds");var jh={connect:r((e,s)=>Re.post(`/companies/${e}/email/connections`,s),"connect"),inspectSaved:r((e,s)=>Re.post(`/companies/${e}/email/connections/${s}/inspect`,{}),"inspectSaved"),list:r(e=>Re.get(`/companies/${e}/email/inboxes`),"list"),setup:r((e,s)=>Re.post(`/companies/${e}/email/inboxes`,s),"setup"),inspect:r((e,s)=>Re.post(`/companies/${e}/email/inspect`,{apiKey:s}),"inspect"),control:r((e,s)=>Re.post(`/email/inboxes/${e}/control`,{action:s}),"control"),reconnect:r((e,s,n)=>Re.post(`/email/inboxes/${e}/reconnect`,{apiKey:s,receiveMode:n}),"reconnect"),resolve:r((e,s,n,a)=>Re.post(`/companies/${e}/email/deliveries/${s}/resolve`,{outcome:n,providerMessageId:a}),"resolve"),thread:r((e,s)=>Re.get(`/companies/${e}/email/tasks/${s}`),"thread"),send:r((e,s)=>Re.post(`/companies/${e}/email/send`,s),"send")},Xxe=(0,m.createContext)(null);function dXe({companyId:e,issueId:s,children:n}){const{enabled:a}=Tx(),i=ee({queryKey:["email-thread",e,s],queryFn:r(()=>jh.thread(e,s),"queryFn"),enabled:a,refetchInterval:a?3e3:!1});return(0,t.jsx)(Xxe.Provider,{value:i.data??null,children:n})}r(dXe,"EmailThreadProvider");function Zxe(e){const s=(0,m.useContext)(Xxe),n=s?.messages.find(a=>a.commentId===e);return n&&s?(0,t.jsx)(ege,{message:n,publication:s.publications.find(a=>a.providerMessageId===n.providerMessageId),issueId:s.issueId}):null}r(Zxe,"useEmailComment");function ege({message:e,publication:s,issueId:n}){const a=ee({queryKey:["email-attachments",n],queryFn:r(()=>Tt.listAttachments(n),"queryFn"),enabled:e.attachmentIds.length>0});return(0,t.jsxs)("article",{"aria-label":e.direction==="inbound"?"Email received":"Email sent",className:"space-y-4 rounded-xl border border-border bg-card p-5",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-sm font-semibold",children:[(0,t.jsx)(hce,{className:"size-4"}),e.direction==="inbound"?"Email received":"Email sent"]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium",children:[e.from,e.direction==="inbound"&&(0,t.jsx)("span",{className:"ml-2 rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground",children:"External"})]}),(0,t.jsxs)("p",{className:"break-words text-xs text-muted-foreground",children:["To: ",e.to.join(", ")]}),!!e.cc?.length&&(0,t.jsxs)("p",{className:"break-words text-xs text-muted-foreground",children:["Cc: ",e.cc.join(", ")]}),(0,t.jsx)("p",{className:"text-sm font-semibold",children:e.subject})]}),(0,t.jsx)("div",{className:"whitespace-pre-wrap break-words text-sm",children:e.text||"(No text body)"}),!!e.attachmentIds.length&&(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:e.attachmentIds.map(i=>{const o=a.data?.find(l=>l.id===i);return(0,t.jsxs)("a",{href:`/api/attachments/${i}/content`,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 rounded-md border border-border px-3 py-2 text-xs",children:[(0,t.jsx)(zl,{className:"size-3.5"}),o?.originalFilename??"Open attachment"]},i)})}),(0,t.jsxs)("details",{className:"text-xs text-muted-foreground",children:[(0,t.jsx)("summary",{className:"cursor-pointer",children:"Email details"}),(0,t.jsxs)("div",{className:"space-y-2 pt-3",children:[!!e.bcc?.length&&(0,t.jsxs)("p",{children:["Bcc: ",e.bcc.join(", ")]}),(0,t.jsxs)("p",{className:"break-all",children:["Message ID: ",e.providerMessageId]}),e.fullText!==e.text&&(0,t.jsx)("div",{className:"whitespace-pre-wrap break-words",children:e.fullText})]})]}),s&&(0,t.jsxs)("p",{className:"border-t border-border pt-3 text-xs text-muted-foreground",children:[s.outcome==="delivered"?"Delivered":s.outcome==="failed"?"Delivery failed":s.outcome==="uncertain"?"Delivery uncertain":s.outcome==="queued"?"Queued":"Sent",s.error?` · ${s.error}`:""]}),a.error&&(0,t.jsx)("p",{role:"alert",className:"text-xs text-destructive",children:"Attachments could not be loaded."})]})}r(ege,"EmailMessageCard");var Ij=(0,m.createContext)(null);function uXe(e){return e.contentType.toLowerCase().split(";")[0]?.trim()??""}r(uXe,"normalizedContentType$1");function P1(e){return e.originalFilename??e.id}r(P1,"attachmentFilename");function mK(e){return e.openPath??e.contentPath}r(mK,"attachmentOpenPath");function sE(e){return e.downloadPath??`${e.contentPath}?download=1`}r(sE,"attachmentDownloadPath");function tge(e){const s=uXe(e);return dC(s,e.originalFilename)&&!/^image\/hei[cf](?:-sequence)?$/.test(s)}r(tge,"isImageAttachment$2");function sge(e){return Ld(e.contentType,e.originalFilename)}r(sge,"isVideoAttachment");function mXe(e){return z_e(e)}r(mXe,"isMarkdownAttachment");function eN({items:e,initialIndex:s,open:n,onOpenChange:a}){const[i,o]=(0,m.useState)(s),l=(0,m.useRef)(null),c=(0,m.useCallback)(v=>{l.current=v},[]);(0,m.useEffect)(()=>{n&&o(s)},[n,s]);const d=(0,m.useCallback)(()=>{o(v=>(v+1)%e.length)},[e.length]),u=(0,m.useCallback)(()=>{o(v=>(v-1+e.length)%e.length)},[e.length]);(0,m.useEffect)(()=>{i<e.length||o(0)},[i,e.length]),(0,m.useEffect)(()=>{if(!n)return;const v=r(y=>{y.key==="ArrowRight"?d():y.key==="ArrowLeft"?u():y.key==="Escape"&&a(!1)},"handler");return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[n,d,u,a]);const h=(0,m.useCallback)(v=>{const y=v.target;y.closest("button")||y.closest("a")||y===l.current||a(!1)},[a]);if(e.length===0)return null;const p=e[i];if(!p)return null;const x=P1(p),g=Ld(p.contentType,p.originalFilename);return(0,t.jsx)(r2e,{open:n,onOpenChange:a,children:(0,t.jsxs)(ZAe,{children:[(0,t.jsx)(e2e,{className:"fixed inset-0 z-50 bg-black/90 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200"}),(0,t.jsxs)(s2e,{className:"fixed inset-0 z-50 flex flex-col outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200",onClick:h,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 text-white/80 text-sm shrink-0",children:[(0,t.jsx)("span",{className:"truncate max-w-(--pct-50) font-medium",title:x,children:x}),(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("span",{className:"text-white/40 tabular-nums text-xs",children:[i+1," / ",e.length]}),(0,t.jsx)("a",{href:sE(p),download:x,className:"text-white/50 hover:text-white transition-colors",title:"Download","aria-label":`Download ${x}`,onClick:r(v=>v.stopPropagation(),"onClick"),children:(0,t.jsx)(Ko,{className:"h-4.5 w-4.5"})}),(0,t.jsx)("button",{type:"button",onClick:r(()=>a(!1),"onClick"),className:"text-white/50 hover:text-white transition-colors",title:"Close",children:(0,t.jsx)(nr,{className:"h-5 w-5"})})]})]}),(0,t.jsxs)("div",{className:"flex-1 flex items-center min-h-0",children:[(0,t.jsx)("div",{className:"w-16 md:w-24 shrink-0 flex items-center justify-center h-full",children:e.length>1&&(0,t.jsx)("button",{type:"button",onClick:u,className:"rounded-full bg-white/10 p-3 text-white/60 hover:text-white hover:bg-white/20 transition-colors",title:"Previous",children:(0,t.jsx)(hu,{className:"h-7 w-7"})})}),(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center min-w-0 min-h-0 h-full px-2",children:g?(0,t.jsx)("video",{ref:c,src:p.contentPath,className:"max-w-full max-h-full rounded-lg",controls:!0,playsInline:!0}):(0,t.jsx)("img",{ref:c,src:p.contentPath,alt:x,className:"max-w-full max-h-full object-contain select-none rounded-lg",draggable:!1})}),(0,t.jsx)("div",{className:"w-16 md:w-24 shrink-0 flex items-center justify-center h-full",children:e.length>1&&(0,t.jsx)("button",{type:"button",onClick:d,className:"rounded-full bg-white/10 p-3 text-white/60 hover:text-white hover:bg-white/20 transition-colors",title:"Next",children:(0,t.jsx)(mn,{className:"h-7 w-7"})})})]}),(0,t.jsx)("div",{className:"h-6 shrink-0"})]})]})})}r(eN,"ImageGalleryModal");function FF(e,s){if(e&&!s)return e;if(!e&&s)return s;if(e||s)return{...e,...s}}r(FF,"mergeObjects");var hK={};function pK(e,s,n,a,i){if(!n&&!a&&!i&&!e)return DT(s);let o=DT(e);return s&&(o=Ek(o,s)),n&&(o=Ek(o,n)),a&&(o=Ek(o,a)),i&&(o=Ek(o,i)),o}r(pK,"mergeProps");function hXe(e){if(e.length===0)return hK;if(e.length===1)return DT(e[0]);let s=DT(e[0]);for(let n=1;n<e.length;n+=1)s=Ek(s,e[n]);return s}r(hXe,"mergePropsN");function DT(e){return fK(e)?{...rge(e,hK)}:pXe(e)}r(DT,"createInitialMergedProps");function Ek(e,s){return fK(s)?rge(s,e):fXe(e,s)}r(Ek,"mergeInto");function pXe(e){const s={...e};for(const n in s){const a=s[n];nge(n,a)&&(s[n]=age(a))}return s}r(pXe,"copyInitialProps");function fXe(e,s){if(!s)return e;for(const n in s){const a=s[n];switch(n){case"style":e[n]=FF(e.style,a);break;case"className":e[n]=oge(e.className,a);break;default:nge(n,a)?e[n]=xXe(e[n],a):e[n]=a}}return e}r(fXe,"mutablyMergeInto");function nge(e,s){const n=e.charCodeAt(0),a=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&a===110&&i>=65&&i<=90&&(typeof s=="function"||typeof s>"u")}r(nge,"isEventHandler");function fK(e){return typeof e=="function"}r(fK,"isPropsGetter");function rge(e,s){return fK(e)?e(s):e??hK}r(rge,"resolvePropsGetter");function xXe(e,s){return s?e?(...n)=>{const a=n[0];if(lge(a)){const o=a;ige(o);const l=s(...n);return o.baseUIHandlerPrevented||e?.(...n),l}const i=s(...n);return e?.(...n),i}:age(s):e}r(xXe,"mergeEventHandlers");function age(e){return e&&((...s)=>{const n=s[0];return lge(n)&&ige(n),e(...s)})}r(age,"wrapEventHandler");function ige(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}r(ige,"makeEventPreventable");function oge(e,s){return s?e?s+" "+e:s:e}r(oge,"mergeClassNames");function lge(e){return e!=null&&typeof e=="object"&&"nativeEvent"in e}r(lge,"isSyntheticEvent");function gXe(e,s){return r(function(a,...i){const o=new URL(e);return o.searchParams.set("code",a.toString()),i.forEach(l=>o.searchParams.append("args[]",l)),`${s} error #${a}; visit ${o} for the full message.`},"formatErrorMessage")}r(gXe,"createFormatErrorMessage");var bXe=gXe("https://base-ui.com/production-error","Base UI"),PJ={};function cge(e,s){const n=m.useRef(PJ);return n.current===PJ&&(n.current=e(s)),n}r(cge,"useRefWithInit");function MJ(e,s,n,a){const i=cge(dge).current;return yXe(i,e,s,n,a)&&uge(i,[e,s,n,a]),i.callback}r(MJ,"useMergedRefs");function vXe(e){const s=cge(dge).current;return jXe(s,e)&&uge(s,e),s.callback}r(vXe,"useMergedRefsN");function dge(){return{callback:null,cleanup:null,refs:[]}}r(dge,"createForkRef");function yXe(e,s,n,a,i){return e.refs[0]!==s||e.refs[1]!==n||e.refs[2]!==a||e.refs[3]!==i}r(yXe,"didChange");function jXe(e,s){return e.refs.length!==s.length||e.refs.some((n,a)=>n!==s[a])}r(jXe,"didChangeN");function uge(e,s){if(e.refs=s,s.every(n=>n==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&(e.cleanup(),e.cleanup=null),n!=null){const a=Array(s.length).fill(null);for(let i=0;i<s.length;i+=1){const o=s[i];if(o!=null)switch(typeof o){case"function":{const l=o(n);typeof l=="function"&&(a[i]=l);break}case"object":o.current=n}}e.cleanup=()=>{for(let i=0;i<s.length;i+=1){const o=s[i];if(o!=null)switch(typeof o){case"function":{const l=a[i];typeof l=="function"?l():o(null);break}case"object":o.current=null}}}}}}r(uge,"update");var wXe=parseInt("19.2.8",10);function NXe(e){return wXe>=e}r(NXe,"isReactVersionAtLeast");function DJ(e){if(!m.isValidElement(e))return null;const s=e,n=s.props;return(NXe(19)?n?.ref:s.ref)??null}r(DJ,"getReactElementRef");var y8t=Object.freeze([]),Pk=Object.freeze({});function kXe(e,s){const n={};for(const a in e){const i=e[a];if(s?.hasOwnProperty(a)){const o=s[a](i);o!=null&&Object.assign(n,o);continue}i===!0?n[`data-${a.toLowerCase()}`]="":i&&(n[`data-${a.toLowerCase()}`]=i.toString())}return n}r(kXe,"getStateAttributesProps");function SXe(e,s){return typeof e=="function"?e(s):e}r(SXe,"resolveClassName");function CXe(e,s){return typeof e=="function"?e(s):e}r(CXe,"resolveStyle");function _Xe(e,s,n={}){const a=s.render,i=IXe(s,n);return n.enabled===!1?null:TXe(e,a,i,n.state??Pk)}r(_Xe,"useRenderElement");function IXe(e,s={}){const{className:n,style:a,render:i}=e,{state:o=Pk,ref:l,props:c,stateAttributesMapping:d,enabled:u=!0}=s,h=u?SXe(n,o):void 0,p=u?CXe(a,o):void 0,x=u?kXe(o,d):Pk,g=u&&c?AXe(c):void 0,v=u?FF(x,g)??{}:Pk;return typeof document<"u"&&(u?Array.isArray(l)?v.ref=vXe([v.ref,DJ(i),...l]):v.ref=MJ(v.ref,DJ(i),l):MJ(null,null)),u?(h!==void 0&&(v.className=oge(v.className,h)),p!==void 0&&(v.style=FF(v.style,p)),v):Pk}r(IXe,"useRenderElementProps");function AXe(e){return Array.isArray(e)?hXe(e):pK(void 0,e)}r(AXe,"resolveRenderFunctionProps");var RXe=Symbol.for("react.lazy");function TXe(e,s,n,a){if(s){if(typeof s=="function")return s(n,a);const i=pK(n,s.props);i.ref=n.ref;let o=s;return o?.$$typeof===RXe&&(o=m.Children.toArray(s)[0]),m.cloneElement(o,i)}if(e&&typeof e=="string")return EXe(e,n);throw new Error(bXe(8))}r(TXe,"evaluateRenderProp");function EXe(e,s){return e==="button"?(0,m.createElement)("button",{type:"button",...s,key:s.key}):e==="img"?(0,m.createElement)("img",{alt:"",...s,key:s.key}):m.createElement(e,s)}r(EXe,"renderTag");function PXe(e){return _Xe(e.defaultTagName??"div",e,e)}r(PXe,"useRender");var MXe=lz("group/attachment relative flex w-fit max-w-full min-w-0 shrink-0 flex-wrap rounded-none border bg-card text-card-foreground transition-colors focus-within:ring-1 focus-within:ring-ring/50 has-[>a,>button]:hover:bg-muted/50 data-[state=error]:border-destructive/30 data-[state=idle]:border-dashed",{variants:{size:{default:"gap-2 text-xs has-data-[slot=attachment-content]:px-2 has-data-[slot=attachment-content]:py-1.5 has-data-[slot=attachment-media]:p-1.5",sm:"gap-2.5 text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1",xs:"gap-1.5 rounded-none text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1"},orientation:{horizontal:"min-w-40 items-center",vertical:"w-24 flex-col has-data-[slot=attachment-content]:w-30"}}});function mge({className:e,state:s="done",size:n="default",orientation:a="horizontal",...i}){return(0,t.jsx)("div",{"data-slot":"attachment","data-state":s,"data-size":n,"data-orientation":a,className:U(MXe({size:n,orientation:a}),e),...i})}r(mge,"Attachment");var DXe=lz("relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-none bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=xs]/attachment:rounded-none group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5",{variants:{variant:{icon:"",image:"opacity-60 group-data-[state=done]/attachment:opacity-100 group-data-[state=idle]/attachment:opacity-100 *:[img]:aspect-square *:[img]:w-full *:[img]:object-cover"}},defaultVariants:{variant:"icon"}});function hge({className:e,variant:s="icon",...n}){return(0,t.jsx)("div",{"data-slot":"attachment-media","data-variant":s,className:U(DXe({variant:s}),e),...n})}r(hge,"AttachmentMedia");function pge({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-content",className:U("max-w-full min-w-0 flex-1 leading-tight group-data-[orientation=vertical]/attachment:px-1",e),...s})}r(pge,"AttachmentContent");function fge({className:e,...s}){return(0,t.jsx)("span",{"data-slot":"attachment-title",className:U("block max-w-full min-w-0 truncate font-medium group-data-[state=processing]/attachment:shimmer group-data-[state=uploading]/attachment:shimmer",e),...s})}r(fge,"AttachmentTitle");function xge({className:e,...s}){return(0,t.jsx)("span",{"data-slot":"attachment-description",className:U("mt-0.5 block min-w-0 truncate text-xs text-muted-foreground group-data-[state=error]/attachment:text-destructive/80","max-w-full",e),...s})}r(xge,"AttachmentDescription");function LXe({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-actions",className:U("relative z-20 flex shrink-0 items-center group-data-[orientation=vertical]/attachment:absolute group-data-[orientation=vertical]/attachment:top-3 group-data-[orientation=vertical]/attachment:right-3 group-data-[orientation=vertical]/attachment:gap-1",e),...s})}r(LXe,"AttachmentActions$1");function $Xe({className:e,variant:s,size:n="icon-xs",...a}){return(0,t.jsx)(F,{"data-slot":"attachment-action",variant:s??"ghost",size:n,className:U(e),...a})}r($Xe,"AttachmentAction");function OXe({className:e,render:s,type:n,...a}){return PXe({defaultTagName:"button",props:pK({type:s?n:n??"button",className:U("absolute inset-0 z-10 outline-none",e)},a),render:s,state:{slot:"attachment-trigger"}})}r(OXe,"AttachmentTrigger");function gge({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-group",className:U("flex min-w-0 scroll-fade-x snap-x snap-mandatory scroll-px-1 scrollbar-none gap-3 overflow-x-auto overscroll-x-contain py-1 *:data-[slot=attachment]:flex-none *:data-[slot=attachment]:snap-start",e),...s})}r(gge,"AttachmentGroup");var FXe=new Set(["png","jpg","jpeg","gif","webp","svg","avif","bmp","ico","heic"]),BXe={pdf:{icon:pi,label:"PDF"},doc:{icon:pi,label:"Doc"},docx:{icon:pi,label:"Doc"},txt:{icon:pi,label:"Text"},md:{icon:pi,label:"Markdown"},rtf:{icon:pi,label:"Text"},csv:{icon:Sk,label:"CSV"},tsv:{icon:Sk,label:"TSV"},xls:{icon:Sk,label:"Sheet"},xlsx:{icon:Sk,label:"Sheet"},zip:{icon:Q0,label:"ZIP"},gz:{icon:Q0,label:"Archive"},tar:{icon:Q0,label:"Archive"},tgz:{icon:Q0,label:"Archive"},rar:{icon:Q0,label:"Archive"},"7z":{icon:Q0,label:"Archive"},mp3:{icon:kk,label:"Audio"},wav:{icon:kk,label:"Audio"},m4a:{icon:kk,label:"Audio"},ogg:{icon:kk,label:"Audio"},mp4:{icon:t2,label:"Video"},mov:{icon:t2,label:"Video"},webm:{icon:t2,label:"Video"},json:{icon:vl,label:"JSON"},yaml:{icon:vl,label:"YAML"},yml:{icon:vl,label:"YAML"},xml:{icon:vl,label:"XML"},html:{icon:vl,label:"HTML"},css:{icon:vl,label:"CSS"},js:{icon:vl,label:"Code"},jsx:{icon:vl,label:"Code"},ts:{icon:vl,label:"Code"},tsx:{icon:vl,label:"Code"},py:{icon:vl,label:"Code"},rb:{icon:vl,label:"Code"},go:{icon:vl,label:"Code"},rs:{icon:vl,label:"Code"},sh:{icon:vl,label:"Code"},sql:{icon:vl,label:"SQL"},log:{icon:pi,label:"Log"},patch:{icon:vl,label:"Patch"},diff:{icon:vl,label:"Patch"}};function bge(e){const s=/\.([a-z0-9]+)$/i.exec(e.trim());return s?s[1].toLowerCase():""}r(bge,"extensionOf");function LJ(e){return FXe.has(bge(e))}r(LJ,"isImageFilename");function vge(e){return(e??"").toLowerCase().split(";")[0]?.trim()??""}r(vge,"normalizedContentType");function xI(e){const s=vge(e.contentType);return s.startsWith("image/")?!0:s&&s!=="application/octet-stream"?!1:LJ(e.name)||LJ(e.url.split("?")[0])}r(xI,"isImageAttachment$1");function yge(e){return BXe[bge(e)]??{icon:aO,label:"File"}}r(yge,"fileKindForName");function qXe(e){const s=yge(e.name);if(s.label!=="File")return s;const n=vge(e.contentType);return n==="application/pdf"?{icon:pi,label:"PDF"}:n==="application/json"||n.endsWith("+json")?{icon:vl,label:"JSON"}:n==="text/csv"||n==="application/csv"?{icon:Sk,label:"CSV"}:n.startsWith("text/")?{icon:pi,label:"Text"}:n.startsWith("audio/")?{icon:kk,label:"Audio"}:n.startsWith("video/")?{icon:t2,label:"Video"}:n.includes("zip")||n.includes("archive")?{icon:Q0,label:"Archive"}:s}r(qXe,"fileKindForAttachment");function jge(e){return e===void 0||!Number.isFinite(e)||e<=0?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}r(jge,"formatFileSize");function zXe(e){return/\/api\/(?:attachments|assets)\/([^/?]+)\/content/.exec(e)?.[1]??null}r(zXe,"attachmentIdFromUrl");function $J(e,s){const n=new Map(s.map(i=>[i.id,i])),a=new Map(s.flatMap(i=>[[i.contentPath,i],...i.openPath?[[i.openPath,i]]:[]]));return e.map(i=>{const o=i.url.split("?")[0],l=a.get(o)??n.get(zXe(i.url)??"");return l?{...i,id:l.id,name:l.originalFilename?.trim()||i.name,contentType:l.contentType,byteSize:l.byteSize,openPath:l.openPath,downloadPath:l.downloadPath}:i})}r($J,"hydrateAttachmentRefs");var OJ=/(?<!!)\[((?:\\.|[^\]\\])+)\]\((\/api\/(?:attachments|assets)\/[^()\s]+\/content(?:\?[^()\s]*)?)\)/g,wge=/!\[((?:\\.|[^\]\\])*)\]\(([^()\s]+)\)/g;function Nge(e){return e.replace(wge,"").trim().length===0&&e.trim().length>0}r(Nge,"isStandaloneImageEmbedLine");function UXe(e){const s=[],n=new Set;for(const a of e.split(`
336
+ `)}`:void 0}r(cYe,"sanitizeComponentStack");function dYe(e){const s=cYe(e.componentStack),n={};if(typeof document<"u"){try{const a=document.readyState;(a==="loading"||a==="interactive"||a==="complete")&&(n.ready_state=a)}catch{}try{const a=document.visibilityState;(a==="visible"||a==="hidden")&&(n.visibility_state=a)}catch{}try{const a=document.documentElement.classList;n.translation_marker=a.contains("translated-ltr")||a.contains("translated-rtl")}catch{}}return{tags:{react_error_boundary:e.boundary},contexts:{react:s?{componentStack:s}:{},browser_state:n}}}r(dYe,"buildBrowserErrorContext");var xJ=Promise.resolve();function lK(e){const s=xJ.then(e);return xJ=s.catch(()=>{}),s}r(lK,"enqueue");var hw=null;function uYe(e,s){return lK(async()=>{if(!hw)try{const n=await gc(()=>import("./prod-COP_vZWu.js"),__vite__mapDeps([4,5]));n.init(hYe(e,s)),hw=n}catch{}})}r(uYe,"initBrowserErrorMonitoring");function mYe(){return lK(async()=>{const e=hw;if(hw=null,!e)return;const s=e.getClient();try{e.getCurrentScope().setClient(void 0)}catch{}try{await s?.close(2e3)}catch{}})}r(mYe,"teardownBrowserErrorMonitoring");function kxe(e,s){let n;try{s&&(n=dYe(s))}catch{}lK(async()=>{try{n?hw?.captureException(e,n):hw?.captureException(e)}catch{}})}r(kxe,"captureBrowserException");function hYe(e,s){return{dsn:e,environment:s??void 0,release:"952974efe5f0b9b722c252c3d111c60d1d2c0606",tracesSampleRate:0,sendDefaultPii:!1,integrations:r(n=>n.filter(a=>a.name!=="HttpContext"&&a.name!=="Breadcrumbs"),"integrations")}}r(hYe,"buildBrowserSentryInitOptions");var pYe=class extends m.Component{static{r(this,"RouteErrorBoundaryInner")}state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,s){kxe(e,{boundary:"route",componentStack:s.componentStack})}componentDidUpdate(e){this.state.error&&e.resetKey!==this.props.resetKey&&this.setState({error:null})}render(){const{error:e}=this.state;return e?(0,t.jsxs)("div",{className:"mx-auto max-w-2xl space-y-4 px-4 py-10",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"This page hit an error"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Something went wrong while rendering this page. You can go back and try again, or reload."})]}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-wrap",children:e.message}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(F,{variant:"outline",size:"sm",onClick:this.props.onReset,children:"Go back"}),(0,t.jsx)(F,{size:"sm",onClick:r(()=>window.location.reload(),"onClick"),children:"Reload page"})]})]}):this.props.children}};function Sxe({children:e}){const s=Zr(),n=Wn(),a=`${s.pathname}${s.search}`;return(0,t.jsx)(pYe,{resetKey:a,onReset:r(()=>n(-1),"onReset"),children:e})}r(Sxe,"RouteErrorBoundary");var mI=240,DF=208,LF=420,gJ=16;function TT(e){return Math.min(LF,Math.max(DF,e))}r(TT,"clampSidebarWidth$1");function bJ(e){if(typeof window>"u")return mI;try{const s=window.localStorage.getItem(e);if(!s)return mI;const n=Number.parseInt(s,10);return Number.isFinite(n)?TT(n):mI}catch{return mI}}r(bJ,"readStoredSidebarWidth$1");function vJ(e,s){if(!(typeof window>"u"))try{window.localStorage.setItem(e,String(TT(s)))}catch{}}r(vJ,"writeStoredSidebarWidth$1");function fYe({children:e,open:s,collapsed:n=!1,peeking:a=!1,resizable:i=!1,storageKey:o="paperclip.sidebar.width",className:l,onPanelMouseEnter:c,onPanelMouseLeave:d,onPanelFocusCapture:u,onPanelBlurCapture:h}){const[p,x]=(0,m.useState)(()=>bJ(o)),[g,v]=(0,m.useState)(!1),y=(0,m.useRef)(p),j=(0,m.useRef)(null);(0,m.useEffect)(()=>{const T=bJ(o);y.current=T,x(T)},[o]);const S=s?p:0,w=s?n?64:S:0,N=s?n&&!a?64:S:0,_=N>w,I=i&&s&&!n,C=(0,m.useMemo)(()=>({width:`${w}px`}),[w]),A=(0,m.useMemo)(()=>({width:`${N}px`}),[N]),R=(0,m.useCallback)(T=>{const q=TT(T);y.current=q,x(q),vJ(o,q)},[o]),E=(0,m.useCallback)(T=>{I&&(T.preventDefault(),T.currentTarget.setPointerCapture(T.pointerId),j.current={startX:T.clientX,startWidth:y.current},v(!0))},[I]),O=(0,m.useCallback)(T=>{if(!j.current)return;const q=TT(j.current.startWidth+T.clientX-j.current.startX);y.current=q,x(q)},[]),L=(0,m.useCallback)(()=>{j.current&&(j.current=null,v(!1),vJ(o,y.current))},[o]),$=(0,m.useCallback)(T=>{I&&(T.key==="ArrowLeft"?(T.preventDefault(),R(p-gJ)):T.key==="ArrowRight"?(T.preventDefault(),R(p+gJ)):T.key==="Home"?(T.preventDefault(),R(DF)):T.key==="End"&&(T.preventDefault(),R(LF)))},[I,R,p]);return(0,t.jsxs)("div",{className:U("relative h-full shrink-0",l),style:C,children:[(0,t.jsx)("div",{className:U("absolute inset-y-0 left-0 flex flex-col overflow-hidden",_?"z-30 border-r border-border bg-background shadow-lg":"z-0"),style:A,"data-sidebar-overlay":_?"":void 0,onMouseEnter:c,onMouseLeave:d,onFocusCapture:u,onBlurCapture:h,children:e}),I?(0,t.jsx)("div",{role:"separator","aria-label":"Resize sidebar","aria-orientation":"vertical","aria-valuemin":DF,"aria-valuemax":LF,"aria-valuenow":p,tabIndex:0,"data-dragging":g?"":void 0,className:"group absolute inset-y-0 z-20 cursor-col-resize touch-none outline-none",style:{right:-4,width:8},onPointerDown:E,onPointerMove:O,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:L,onKeyDown:$,children:(0,t.jsx)("div",{className:U("mx-auto h-full w-0.5 transition-colors",g?"bg-ring":"bg-transparent group-hover:bg-ring group-focus-visible:bg-ring")})}):null]})}r(fYe,"SidebarShell$1");function hI({children:e,className:s}){return(0,t.jsx)("div",{"data-secondary-sidebar":"",className:U("h-full w-full min-w-0 overflow-hidden",s),children:(0,t.jsx)(qde,{children:e})})}r(hI,"SecondarySidebar$1");var xYe="Toggle the app appearance.";function Cj({className:e,variant:s="icon",onAfterToggle:n}){const{theme:a,toggleTheme:i}=F2e(),o=a==="dark",l=o?"Switch to light mode":"Switch to dark mode",c=o?wde:fde;function d(){i(),n?.()}return r(d,"handleClick"),s==="compact-menu-action"?(0,t.jsxs)("button",{type:"button",className:U("flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-accent",e),onClick:d,"aria-label":l,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(c,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:l})]}):s==="menu-action"?(0,t.jsxs)("button",{type:"button",className:U("flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-accent/60",e),onClick:d,"aria-label":l,children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(c,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:l}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:xYe})]})]}):(0,t.jsx)(F,{type:"button",variant:"ghost",size:"icon-sm",onClick:d,"aria-label":l,title:l,className:U("text-muted-foreground",e),children:(0,t.jsx)(c,{})})}r(Cj,"ThemeToggle");function gYe(e){if(!e)return"Unavailable";const s=new Date(e);return Number.isNaN(s.getTime())?"Unavailable":new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(s)}r(gYe,"formatTimestamp$2");function bYe(e){return!!e&&!Number.isNaN(new Date(e).getTime())}r(bYe,"isValidTimestamp");function vYe(e){return e?.devServer?.lastRestartAt??e?.serverInfo?.processStartedAt??null}r(vYe,"restartTimestamp");function yYe(e){const s=e?.serverInfo?.git;return s?.available?`${s.shortSha} · ${s.subject}`:"Commit unavailable"}r(yYe,"commitLabel");function jYe(e){const s=e?.serverInfo?.git;if(!s?.available)return"Unavailable";const n=s.localChanges;if(!n||!n.available)return"Change status unavailable";if(!n.hasLocalChanges)return"Clean checkout";const a=[[n.stagedFileCount,"staged"],[n.unstagedFileCount,"unstaged"],[n.untrackedFileCount,"untracked"]].filter(([i])=>Number(i)>0).map(([i,o])=>`${i} ${o}`);return a.length>0?`Local changes present (${a.join(", ")})`:"Local changes present"}r(jYe,"localChangesLabel");function F4({icon:e,label:s,value:n,dateTime:a}){return(0,t.jsxs)("div",{className:"flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left",children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(e,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:s}),a?(0,t.jsx)("time",{dateTime:a,className:"block break-words text-xs text-muted-foreground",children:n}):(0,t.jsx)("span",{className:"block break-words text-xs text-muted-foreground",children:n})]})]})}r(F4,"ServerInfoRow");function Cxe(){const e=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")}).data?.enableServerInfoDebugView===!0,s=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),enabled:e,refetchOnMount:"always",refetchInterval:r(h=>h.state.data?.devServer?.enabled?2e3:!1,"refetchInterval")});if(!e)return null;const n=s.data,a=s.isLoading&&!n,i=s.isError,o=vYe(n),l=bYe(o),c=i?"Health unavailable":a?"Loading...":gYe(o),d=i?"Health unavailable":a?"Loading...":yYe(n),u=i?"Health unavailable":a?"Loading...":jYe(n);return(0,t.jsxs)("div",{className:"mt-2 border-t border-border pt-2",children:[(0,t.jsx)("p",{className:"px-3 pb-1 pt-1 text-(length:--text-micro) font-medium uppercase tracking-wide text-muted-foreground",children:"Server"}),(0,t.jsx)(F4,{icon:Xm,label:"Last restarted",value:c,dateTime:!i&&!a&&l?o:null}),(0,t.jsx)(F4,{icon:ade,label:"Running commit",value:d}),(0,t.jsx)(F4,{icon:c3e,label:"Checkout state",value:u})]})}r(Cxe,"SidebarServerInfo");var wYe="/company/settings/instance/profile",NYe="https://docs.paperclip.ing/",kYe="https://paperclip.ing/feedback";function SYe(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?`${s[0]?.[0]??""}${s[s.length-1]?.[0]??""}`.toUpperCase():e.slice(0,2).toUpperCase()}r(SYe,"deriveInitials$2");function CYe(e,s,n){const a=[e,s?.split("@")[0],s,n];for(const i of a){const o=i?.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(o)return o}return"me"}r(CYe,"deriveUserSlug$1");function pI({label:e,icon:s,onClick:n,href:a,external:i=!1}){const o="flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-accent",l=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(s,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e})]});return a?i?(0,t.jsx)("a",{href:a,target:"_blank",rel:"noreferrer",className:o,onClick:n,children:l}):(0,t.jsx)(Qe,{to:a,className:o,onClick:n,children:l}):(0,t.jsx)("button",{type:"button",className:o,onClick:n,children:l})}r(pI,"MenuAction$1");function yJ({deploymentMode:e,open:s,onOpenChange:n,forceExpanded:a=!1}){const i=!!Vc(),[o,l]=(0,m.useState)(!1),{isMobile:c,setSidebarOpen:d,collapsed:u,peeking:h}=$a(),p=u&&!h&&!a,x=s??o,g=n??l,{data:v}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),y=Hw({onSignedOut:_}),j=v?.user.name?.trim()||"Board",S=v?.user.email?.trim()||(e==="authenticated"?"Signed in":"Local workspace board"),w=SYe(j),N=`/u/${CYe(v?.user.name,v?.user.email,v?.user.id)}`;function _(){g(!1),c&&d(!1)}r(_,"closeNavigationChrome");function I(){y.mutate()}return r(I,"handleSignOut"),(0,t.jsx)("div",{className:"bg-border/50 px-3 py-2 dark:bg-muted",children:(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",!p&&"px-2"),children:[(0,t.jsxs)(sr,{open:x,onOpenChange:g,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:U("flex min-w-0 items-center gap-2.5 rounded-lg text-left text-(length:--text-compact) font-medium text-foreground/80 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",p?"w-full px-3 py-2":"flex-1 px-2 py-1.5"),"aria-label":"Open account menu",children:[(0,t.jsxs)(Yi,{size:"sm",children:[v?.user.image?(0,t.jsx)(zc,{src:v.user.image,alt:j}):null,(0,t.jsx)(Ji,{children:w})]}),(0,t.jsx)("span",{className:U("min-w-0 flex-1 truncate",p&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),children:j})]})}),(0,t.jsxs)(Gn,{side:"top",align:"start",sideOffset:10,className:"min-h-(--profile-popover-min-height) w-(--profile-popover-width) max-w-(--sz-calc-24) overflow-hidden rounded-xl border-border bg-popover p-0 shadow-(--shadow-profile-popover)",children:[(0,t.jsxs)("div",{className:"flex h-(--profile-popover-header-height) shrink-0 items-center gap-2.5 px-3.5",children:[(0,t.jsxs)(Yi,{className:"size-9",children:[v?.user.image?(0,t.jsx)(zc,{src:v.user.image,alt:j}):null,(0,t.jsx)(Ji,{className:"text-xs text-foreground",children:w})]}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("h2",{className:"truncate text-sm font-semibold leading-(--profile-popover-label-line-height) text-foreground",children:j}),(0,t.jsx)("p",{className:"truncate text-(length:--text-micro) leading-(--profile-popover-meta-line-height) text-muted-foreground",children:S})]})]}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-0.5 border-t border-border px-2.5 pb-2.5 pt-2",children:[(0,t.jsx)(pI,{label:"Settings",icon:Dd,href:"/company/settings",onClick:_}),(0,t.jsx)(pI,{label:"View profile",icon:pu,href:N,onClick:_}),(0,t.jsx)(pI,{label:"Edit profile",icon:p1,href:wYe,onClick:_}),(0,t.jsx)(pI,{label:"Documentation",icon:Uw,href:NYe,external:!0,onClick:r(()=>g(!1),"onClick")}),(0,t.jsx)(Cj,{variant:"compact-menu-action",onAfterToggle:r(()=>g(!1),"onAfterToggle")}),e==="authenticated"?(0,t.jsxs)("button",{type:"button",className:U("flex h-(--profile-popover-row-height) w-full items-center gap-(--profile-popover-row-gap) rounded-lg px-2.5 text-left text-(length:--text-compact) font-medium leading-(--profile-popover-label-line-height) text-foreground transition-colors hover:bg-destructive/10",y.isPending&&"cursor-not-allowed opacity-60"),onClick:I,disabled:y.isPending,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:y.isPending?"Signing out...":"Sign out"})]}):null,(0,t.jsx)(Cxe,{})]})]})]}),!p&&!i?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("a",{href:kYe,target:"_blank",rel:"noreferrer","aria-label":"Share feedback",className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground/50 transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:(0,t.jsx)(_x,{className:"h-4 w-4","aria-hidden":"true"})})}),(0,t.jsx)(Kn,{side:"top",children:"Share feedback"})]}):null]})})}r(yJ,"SidebarAccountMenu$1");function _xe({enabled:e=!0,onNewIssue:s,onSearch:n,onToggleSidebar:a,onTogglePanel:i,onShowShortcuts:o,onGoToInbox:l}){(0,m.useEffect)(()=>{if(!e)return;let c=!1,d=null;const u=r(()=>{d!==null&&(window.clearTimeout(d),d=null)},"clearGoChordTimeout"),h=r(()=>{c=!1,u()},"disarmGoChord"),p=r(()=>{c=!0,u(),d=window.setTimeout(()=>{c=!1,d=null},1200)},"armGoChord");function x(y){if(y.defaultPrevented){h();return}if(l){const j=Kle({armed:c,defaultPrevented:y.defaultPrevented,key:y.key,metaKey:y.metaKey,ctrlKey:y.ctrlKey,altKey:y.altKey,target:y.target,hasOpenDialog:Rh()});if(j==="arm"){p();return}if(j==="navigate_inbox"){h(),y.preventDefault(),l();return}if(j==="focus_comment"||j==="open_file_viewer"){h(),y.preventDefault();return}j==="disarm"&&h()}if(!QC(y.target)){if(y.key==="/"&&!y.metaKey&&!y.ctrlKey&&!y.altKey){if(Rh())return;y.preventDefault(),AAe()||n?.();return}if(y.key==="?"&&!y.metaKey&&!y.ctrlKey&&!y.altKey){y.preventDefault(),o?.();return}y.key==="c"&&!y.metaKey&&!y.ctrlKey&&!y.altKey&&(y.preventDefault(),s?.()),y.key==="["&&!y.metaKey&&!y.ctrlKey&&(y.preventDefault(),a?.()),y.key==="]"&&!y.metaKey&&!y.ctrlKey&&(y.preventDefault(),i?.())}}r(x,"handleKeyDown");const g=r(()=>h(),"handlePointerDown"),v=r(y=>{y.target instanceof HTMLElement&&y.target!==document.body&&h()},"handleFocusIn");return document.addEventListener("pointerdown",g,!0),document.addEventListener("focusin",v,!0),document.addEventListener("keydown",x),()=>{h(),document.removeEventListener("pointerdown",g,!0),document.removeEventListener("focusin",v,!0),document.removeEventListener("keydown",x)}},[e,s,n,a,i,o,l])}r(_xe,"useKeyboardShortcuts");var _Ye=new Set(["auth","invite","board-claim","cli-auth","docs"]);function Ixe(e){const s=(e.split("?")[0]??"").split("/").filter(Boolean);if(s.length===0)return!0;const[n]=s;return!_Ye.has(n)}r(Ixe,"isRememberableCompanyPath");function IYe(e){const s=qb(e.companyPrefix);return e.companies.find(n=>qb(n.issuePrefix)===s)??null}r(IYe,"findCompanyByPrefix");function AYe(e){const s=Y6(e.pathname);return s?IYe({companies:e.companies,companyPrefix:s})?.id??null:e.fallbackCompanyId}r(AYe,"getRememberedPathOwnerCompanyId");function RYe(e){const s=e.path?X3(e.path):"/dashboard";if(!Ixe(s))return"/dashboard";const[n,a]=(s.split("?")[0]??"").split("/").filter(Boolean);if(n==="issues"&&a){const i=/^([A-Za-z]+)-\d+$/.exec(a);if(i&&qb(i[1]??"")!==qb(e.companyPrefix))return"/dashboard"}return s}r(RYe,"sanitizeRememberedPathForCompany");var Axe="paperclip.companyPaths";function Rxe(){try{const e=localStorage.getItem(Axe);if(e)return JSON.parse(e)}catch{}return{}}r(Rxe,"getCompanyPaths");function TYe(e,s){const n=Rxe();n[e]=s,localStorage.setItem(Axe,JSON.stringify(n))}r(TYe,"saveCompanyPath");function Txe(){const{companies:e,selectedCompanyId:s,selectedCompany:n,selectionSource:a}=fs(),i=Zr(),o=Wn(),l=(0,m.useRef)(s),c=(0,m.useMemo)(()=>AYe({companies:e,pathname:i.pathname,fallbackCompanyId:l.current}),[e,i.pathname]),d=i.pathname+i.search;(0,m.useEffect)(()=>{const u=c,h=X3(d);u&&Ixe(h)&&TYe(u,h)},[d,c]),(0,m.useEffect)(()=>{if(s){if(l.current!==null&&s!==l.current&&a!=="route_sync"&&n){const u=Rxe(),h=RYe({path:u[s],companyPrefix:n.issuePrefix});o(`/${n.issuePrefix}${h}`,{replace:!0})}l.current=s}},[n,s,a,o])}r(Txe,"useCompanyPageMemory");function Exe(e){const{matchedCompany:s,selectedCompanyId:n,companies:a}=e;return!s||s.status!=="archived"||n===s.id?null:a.find(i=>i.id===n&&i.status!=="archived")??a.find(i=>i.status!=="archived")??null}r(Exe,"resolveArchivedCompanyBounce");function EYe(e){const{archivedCompanyId:s,companies:n,cloudPortfolioUrl:a}=e,i=n.find(o=>o.id!==s&&o.status!=="archived");return i?{kind:"company",company:i}:a?{kind:"cloud_portfolio",url:a}:{kind:"companies_list"}}r(EYe,"resolveCompanyArchiveDeparture");function Pxe(e){const{selectionSource:s,selectedCompanyId:n,routeCompanyId:a}=e;return!(n===a||s==="manual"&&n)}r(Pxe,"shouldSyncCompanySelectionFromRoute");function PYe(e,s){return e instanceof HTMLElement?!(s instanceof HTMLElement)||!document.contains(s)||s===document.body||s===document.documentElement?!0:!e.contains(s):!1}r(PYe,"shouldFocusMainContentAfterNavigation");function Mxe(e){if(!(e instanceof HTMLElement))return()=>{};const s=window.requestAnimationFrame(()=>{PYe(e,document.activeElement)&&e.focus({preventScroll:!0})});return()=>window.cancelAnimationFrame(s)}r(Mxe,"scheduleMainContentFocus");function Dxe(e=document,s=window){const n=r(()=>{e.documentElement.scrollTop!==0&&(e.documentElement.scrollTop=0),e.body.scrollTop!==0&&(e.body.scrollTop=0)},"onScroll");return s.addEventListener("scroll",n,{capture:!0}),()=>s.removeEventListener("scroll",n,{capture:!0})}r(Dxe,"pinDocumentScrollToZero");function uu({scope:e="global",requestedPrefix:s}){const n=Zr(),{setBreadcrumbs:a}=$n(),{companies:i,selectedCompany:o}=fs();(0,m.useEffect)(()=>{a([{label:"Not Found"}])},[a]);const l=o??i[0]??null,c=l?`/${l.issuePrefix}/dashboard`:"/",d=`${n.pathname}${n.search}${n.hash}`,u=s?.toUpperCase(),h=e==="invalid_company_prefix"?"Organization not found":"Page not found",p=e==="invalid_company_prefix"?`No organization matches prefix "${u??"unknown"}".`:"This route does not exist.";return(0,t.jsx)("div",{className:"mx-auto max-w-2xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 p-2",children:(0,t.jsx)(Is,{className:"h-5 w-5 text-destructive"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:h}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:p})]})]}),(0,t.jsxs)("div",{className:"mt-4 rounded-md border border-border bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:["Requested path: ",(0,t.jsx)("code",{className:"font-mono",children:d})]}),(0,t.jsxs)("div",{className:"mt-5 flex flex-wrap gap-2",children:[(0,t.jsx)(F,{asChild:!0,children:(0,t.jsxs)(Qe,{to:c,children:[(0,t.jsx)(CR,{className:"mr-1.5 h-4 w-4"}),"Open dashboard"]})}),(0,t.jsx)(F,{variant:"outline",asChild:!0,children:(0,t.jsx)(Qe,{to:"/",children:"Go home"})})]})]})})}r(uu,"NotFoundPage");function MYe(e,s){return nme(e,s)[0]?.toLowerCase()??null}r(MYe,"getCompanyRouteSegment$1");var DYe=new Set(["browse","connections","connect","chat","vercel-connect","review","attention","gateways","advanced","app"]);function LYe({sidebarSections:e}){const{sidebarOpen:s,setSidebarOpen:n,toggleSidebar:a,collapsed:i,peeking:o,setPeeking:l,isMobile:c,setForceCollapsed:d}=$a(),{openNewIssue:u,openOnboarding:h}=Lo(),{togglePanelVisible:p}=uf(),x=Nc()?.pushToast??null,{companies:g,loading:v,selectedCompany:y,selectedCompanyId:j,selectionSource:S,setSelectedCompanyId:w}=fs(),{companyPrefix:N,pluginRoutePath:_,agentId:I,routineId:C}=ja(),A=Wn(),R=Zr(),E=J3(),{enabled:O}=wc(),L=X$e(R.pathname,N),$=L.builtInContextualSurface==="settings",T=L.companySegments,q=L.isTaskDetail,B=O&&q,K=T[0]?.toLowerCase()==="tools",z=T[0]?.toLowerCase()==="apps",D=z&&T[1]&&!DYe.has(T[1].toLowerCase())?T[1]:null,V=z&&T[1]?.toLowerCase()==="app"&&T[2]?T[2]:null,H=(0,m.useRef)(!1),Z=(0,m.useRef)(0),Y=(0,m.useRef)(null),ie=(0,m.useRef)(null),se=(0,m.useRef)(new Ode),X=(0,m.useRef)(R.key),[le,oe]=(0,m.useState)(!0),[te,J]=(0,m.useState)(!1),Q=(0,m.useMemo)(()=>{if(!N)return null;const Ot=N.toUpperCase();return g.find(Be=>Be.issuePrefix.toUpperCase()===Ot)??null},[g,N]),pe=!!N&&!v&&g.length>0&&!Q,re=(0,m.useMemo)(()=>_?.toLowerCase()??MYe(R.pathname,N),[N,R.pathname,_]),ne=Q?.id??null,ae=Q?.issuePrefix??null,{slots:me}=Kc({slotTypes:["page","routeSidebar"],companyId:ne,enabled:!!(ne&&re)}),he=(0,m.useMemo)(()=>Fz(me,re),[re,me]),Ie=(0,m.useMemo)(()=>({companyId:ne,companyPrefix:ae}),[ne,ae]),de=$?(0,t.jsx)(sOe,{}):!O&&L.builtInContextualSurface==="skills"?(0,t.jsx)(cQ,{}):D?(0,t.jsx)(oQ,{kind:"connection",connectionId:D}):V?(0,t.jsx)(oQ,{kind:"application",applicationId:V}):z||K?(0,t.jsx)(cOe,{}):he?O?(0,t.jsx)(v1,{surface:`plugin:${he.id}`,title:he.displayName,children:(0,t.jsx)(fu,{slot:he,context:Ie,className:"min-h-0 flex-1",missingBehavior:"placeholder"})}):(0,t.jsx)(fu,{slot:he,context:Ie,className:"h-full w-full",missingBehavior:"placeholder"}):null,ve=L.builtInContextualSurface==="agent"&&I?(0,t.jsx)(kOe,{agentRef:I}):O&&L.builtInContextualSurface==="routine"&&C?(0,t.jsx)(I4e,{children:(0,t.jsx)(_Oe,{routineId:C})}):O&&L.builtInContextualSurface==="skills"?(0,t.jsx)(cQ,{}):de,Te=ve!=null,fe=O&&Te&&(L.builtInContextualSurface==="skills"||L.builtInContextualSurface==="agent"||L.builtInContextualSurface==="routine"||z||K),Ce=O&&Te&&!fe,Xe=Te&&(!O||fe),Oe=!O||!Te?null:he&&!L.builtInContextualSurface?`plugin:${he.id}`:L.builtInContextualSurface,tt=(0,m.useRef)(null),{data:ce}=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1,refetchInterval:r(Ot=>Ot.state.data?.devServer?.enabled?2e3:!1,"refetchInterval"),refetchIntervalInBackground:!1}),$e=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn")}).data?.keyboardShortcuts===!0;(0,m.useLayoutEffect)(()=>(d(!O&&Te),()=>d(!1)),[Te,d,O]),(0,m.useEffect)(()=>{const Ot=tt.current;Oe&&N&&Ot&&Ot.surface!==Oe&&Ot.pathname!==R.pathname&&Z$e({surface:Oe,companyPrefix:N,previousPathname:Ot.pathname}),tt.current={pathname:R.pathname,surface:Oe}},[N,Oe,R.pathname]),(0,m.useEffect)(()=>{v||H.current||ce?.deploymentMode!=="authenticated"&&(ce?.cloud||g.length===0&&(H.current=!0,h()))},[g,v,h,ce?.cloud,ce?.deploymentMode]),(0,m.useEffect)(()=>{if(!N||v||g.length===0)return;if(!Q){const Be=(j?g.find(Ve=>Ve.id===j):null)??g[0]??null;Be&&j!==Be.id&&w(Be.id,{source:"route_sync"});return}if(N!==Q.issuePrefix){const Be=R.pathname.replace(/^\/[^/]+/,"");A(`/${Q.issuePrefix}${Be}${R.search}`,{replace:!0});return}const Ot=Exe({matchedCompany:Q,selectedCompanyId:j,companies:g});if(Ot){x?.({title:`${Q.name} is archived`,body:`Switched to ${Ot.name}.`,tone:"info",dedupeKey:`archived-company-bounce:${Q.id}`}),w(Ot.id,{source:"route_sync"}),A(`/${Ot.issuePrefix}/dashboard`,{replace:!0});return}Pxe({selectionSource:S,selectedCompanyId:j,routeCompanyId:Q.id})&&w(Q.id,{source:"route_sync"})},[N,g,v,Q,R.pathname,R.search,A,x,S,j,w]);const mt=p,it=(0,m.useCallback)(()=>{document.dispatchEvent(new KeyboardEvent("keydown",{key:"k",metaKey:!0,bubbles:!0,cancelable:!0}))},[]),Ke=(0,m.useRef)(null),Ge=(0,m.useRef)(!1),rt=(0,m.useRef)(!1),jt=(0,m.useCallback)(()=>{Ke.current!==null&&(window.clearTimeout(Ke.current),Ke.current=null)},[]),st=(0,m.useCallback)(()=>{jt(),Ke.current=window.setTimeout(()=>l(!0),50)},[jt,l]),Nt=(0,m.useCallback)(()=>{jt(),l(!0)},[jt,l]),at=(0,m.useCallback)(()=>{jt(),Ke.current=window.setTimeout(()=>l(!1),120)},[jt,l]),Ee=(0,m.useCallback)(()=>{Ge.current=!0,i&&!rt.current&&st()},[i,st]),Ne=(0,m.useCallback)(()=>{Ge.current=!1,rt.current=!1,at()},[at]),He=(0,m.useCallback)(()=>{rt.current||Nt()},[Nt]),St=(0,m.useCallback)(()=>{Ge.current||at()},[at]);(0,m.useEffect)(()=>jt,[jt]);const Ft=(0,m.useRef)(i);(0,m.useEffect)(()=>{i!==Ft.current&&(i?(jt(),l(!1),rt.current=Ge.current):rt.current=!1,Ft.current=i)},[i,jt,l]),(0,m.useEffect)(()=>{if(!o)return;const Ot=r(Be=>{Be.key==="Escape"&&(jt(),l(!1))},"onKeyDown");return window.addEventListener("keydown",Ot),()=>window.removeEventListener("keydown",Ot)},[o,jt,l]),Txe(),_xe({enabled:$e,onNewIssue:r(()=>u(),"onNewIssue"),onSearch:it,onToggleSidebar:a,onTogglePanel:mt,onShowShortcuts:r(()=>J(!0),"onShowShortcuts"),onGoToInbox:r(()=>A("/inbox"),"onGoToInbox")}),(0,m.useEffect)(()=>{if(!c){oe(!0);return}Z.current=0,oe(!0)},[c]),(0,m.useEffect)(()=>{if(!c)return;const Ot=30,Be=50,Ve=75;let ut=0,qe=0;const Gt=r($t=>{const Dt=$t.touches[0];ut=Dt.clientX,qe=Dt.clientY},"onTouchStart"),We=r($t=>{const Dt=$t.changedTouches[0],Cs=Dt.clientX-ut;if(!(Math.abs(Dt.clientY-qe)>Ve)){if(!s&&ut<Ot&&Cs>Be){n(!0);return}s&&Cs<-50&&n(!1)}},"onTouchEnd");return document.addEventListener("touchstart",Gt,{passive:!0}),document.addEventListener("touchend",We,{passive:!0}),()=>{document.removeEventListener("touchstart",Gt),document.removeEventListener("touchend",We)}},[c,s,n]);const ts=(0,m.useCallback)(Ot=>{const Be=Ot-Z.current;Ot<=24?oe(!0):Be>8?oe(!1):Be<-8&&oe(!0),Z.current=Ot},[]);return(0,m.useEffect)(()=>{if(!c){oe(!0),Z.current=0;return}const Ot=r(()=>{ts(window.scrollY||document.documentElement.scrollTop||0)},"onScroll");return Ot(),window.addEventListener("scroll",Ot,{passive:!0}),()=>{window.removeEventListener("scroll",Ot)}},[c,ts]),(0,m.useEffect)(()=>{const Ot=document.body.style.overflow;return document.body.style.overflow=c?"visible":"clip",()=>{document.body.style.overflow=Ot}},[c]),(0,m.useEffect)(()=>{if(!c)return Dxe()},[c]),(0,m.useEffect)(()=>{if(typeof document>"u")return;const Ot=ie.current;return Mxe(Ot)},[R.pathname]),(0,m.useEffect)(()=>{const Ot=ie.current;if(!Ot)return;const Be=r(()=>{se.current.remember(X.current,Ot.scrollTop)},"recordScroll");return Ot.addEventListener("scroll",Be,{passive:!0}),()=>Ot.removeEventListener("scroll",Be)},[]),(0,m.useLayoutEffect)(()=>{const Ot=ie.current,Be=$de({previousPathname:Y.current,pathname:R.pathname,navigationType:E,state:R.state});Y.current=R.pathname;const Ve=E==="POP",ut=Ve?se.current.recall(R.key):0;if(X.current=R.key,Ve){UR(Ot,ut);const qe=requestAnimationFrame(()=>UR(Ot,ut));return()=>cancelAnimationFrame(qe)}Be&&Fde(Ot)},[R.key,R.pathname,R.state,E]),(0,t.jsx)(Lde,{children:(0,t.jsx)(Wle,{value:{keyboardShortcutsEnabled:$e},children:(0,t.jsxs)("div",{className:U("bg-background text-foreground pt-(--sz-safe-top)",c?"min-h-dvh overflow-x-clip":"flex h-dvh flex-col overflow-clip"),children:[(0,t.jsx)("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-(--z-200) focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Skip to Main Content"}),(0,t.jsx)(jxe,{}),(0,t.jsx)(wxe,{devServer:ce?.devServer}),(0,t.jsxs)("div",{className:U("min-h-0 flex-1",c?"w-full":"flex overflow-clip"),children:[c&&s&&(0,t.jsx)("button",{type:"button",className:"fixed inset-0 z-40 bg-black/50",onClick:r(()=>n(!1),"onClick"),"aria-label":"Close sidebar"}),c?(0,t.jsxs)("div",{className:U("fixed inset-y-0 left-0 z-50 flex flex-col overflow-hidden pt-(--sz-safe-top) transition-transform duration-100 ease-out",s?"translate-x-0":"-translate-x-full"),children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:(0,t.jsx)("div",{className:"w-60 shrink-0 overflow-hidden",children:Te?(0,t.jsx)(hI,{children:ve}):(0,t.jsx)(nQ,{children:e})})}),(0,t.jsx)(yJ,{deploymentMode:ce?.deploymentMode,forceExpanded:Ce})]}):(0,t.jsxs)(fYe,{open:s,collapsed:Ce?!1:i,peeking:Ce?!1:o,resizable:!0,onPanelMouseEnter:Ce?void 0:Ee,onPanelMouseLeave:Ce?void 0:Ne,onPanelFocusCapture:!Ce&&i?He:void 0,onPanelBlurCapture:!Ce&&i?St:void 0,children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0",children:Ce?(0,t.jsx)(hI,{children:ve}):(0,t.jsx)(nQ,{children:e})}),(0,t.jsx)(yJ,{deploymentMode:ce?.deploymentMode,forceExpanded:Ce})]}),!c&&Xe&&!fe?(0,t.jsx)(hI,{className:"w-60 shrink-0",children:ve}):null,(0,t.jsxs)("div",{className:U("flex min-w-0 flex-col",c?"w-full":"h-full flex-1"),children:[(0,t.jsxs)("div",{className:U(!c&&B&&"hidden",c&&"sticky top-0 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85"),children:[(0,t.jsx)(MF,{mobile:c}),(0,t.jsx)(uQ,{}),c&&$?(0,t.jsx)("div",{className:"border-b border-border px-4 pb-3",children:(0,t.jsx)(ime,{})}):null]}),(0,t.jsxs)("div",{className:U(c?"block":"flex flex-1 min-h-0",!c&&B&&"streamlined-task-detail-surface"),children:[!c&&fe?(0,t.jsx)(hI,{className:"w-60 shrink-0 bg-background",children:ve}):null,(0,t.jsxs)("div",{className:U(!c&&B?"flex min-w-0 flex-1 flex-col":"contents"),children:[!c&&B?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(MF,{mobile:!1}),(0,t.jsx)(uQ,{taskDetailLayout:!0})]}):null,(0,t.jsx)("main",{id:"main-content",ref:ie,tabIndex:-1,style:c?{"--tc-composer-bottom":le?"var(--sz-calc-14)":"var(--tc-composer-hidden-nav-offset)"}:void 0,className:U("flex-1 p-4 outline-none md:p-6",!c&&B&&"pt-0 md:pt-0",c?q&&!le?"overflow-visible pb-(--tc-composer-hidden-nav-offset)":"overflow-visible pb-(--sz-calc-14)":"overflow-auto [scrollbar-gutter:stable]"),children:pe?(0,t.jsx)(uu,{scope:"invalid_company_prefix",requestedPrefix:N??y?.issuePrefix}):(0,t.jsx)(Sxe,{children:(0,t.jsx)(n0,{})})})]}),(0,t.jsx)(bme,{taskDetailLayout:!c&&B})]})]})]}),c&&(0,t.jsx)(yxe,{visible:le}),(0,t.jsx)(jme,{}),(0,t.jsx)(Eme,{}),(0,t.jsx)(mxe,{}),(0,t.jsx)(fxe,{}),(0,t.jsx)(xxe,{}),(0,t.jsx)(gxe,{open:te,onOpenChange:J}),(0,t.jsx)(bxe,{}),(0,t.jsx)(KGe,{health:ce}),(0,t.jsx)(vxe,{localTrusted:ce?.deploymentMode==="local_trusted"})]})})})}r(LYe,"Layout$1");var Lxe=(0,m.createContext)(!1);function $Ye({children:e}){return(0,t.jsx)(Lxe.Provider,{value:!0,children:e})}r($Ye,"SidebarNavExpandedProvider");function OYe(){return(0,m.useContext)(Lxe)}r(OYe,"useSidebarNavExpanded");function Ha({to:e,label:s,icon:n,iconNode:a,end:i,className:o,labelClassName:l,badge:c,badgeTone:d="default",badgeLabel:u,textBadge:h,textBadgeTone:p="default",alert:x=!1,liveCount:g,active:v,trailing:y,trailingLabel:j,liveAccessory:S}){const{isMobile:w,setSidebarOpen:N,collapsed:_,peeking:I}=$a(),C=OYe(),A=_&&!I&&!C,R=c!=null&&c>0,E=g!=null&&g>0,O=E?`${g} live`:R?`${c}${u?` ${u}`:""}`:x?"attention needed":void 0,L=!A||!O&&!j?void 0:`${s}${O?`, ${O}`:""}${j?`, ${j}`:""}`,$=(0,t.jsxs)(r0,{to:e,state:lf,end:i,"aria-label":L,onClick:r(()=>{w&&N(!1)},"onClick"),className:r(({isActive:T})=>U("flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium transition-colors",v??T?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground",o),"className"),children:[(0,t.jsxs)("span",{className:"relative shrink-0",children:[a??(n?(0,t.jsx)(n,{className:"h-4 w-4"}):null),x&&(0,t.jsx)("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-red-500 shadow-(--shadow-extract-12)","aria-hidden":"true"}),A&&!x&&E&&(0,t.jsxs)("span",{className:"absolute -right-0.5 -top-0.5 flex h-2 w-2","aria-hidden":"true",children:[(0,t.jsx)("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-600 dark:bg-blue-400 shadow-(--shadow-extract-12)"})]}),A&&!x&&!E&&R&&(0,t.jsx)("span",{className:U("absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full shadow-(--shadow-extract-12)",d==="danger"?"bg-red-600":d==="warning"?"bg-amber-500":"bg-primary"),"aria-hidden":"true"})]}),(0,t.jsx)("span",{className:A?bv:U("min-w-0 flex-1 truncate",l),children:s}),!A&&y,!A&&h&&(0,t.jsx)(dt,{variant:"ghost",className:U("ml-auto px-1.5 text-(length:--text-nano) leading-none",p==="amber"?"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400":"bg-muted text-muted-foreground"),children:h}),!A&&(E||S)&&(0,t.jsxs)("span",{className:"ml-auto flex items-center gap-1.5",children:[S,E&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-600 dark:bg-blue-400"})]}),(0,t.jsxs)("span",{className:"text-(length:--text-micro) font-medium text-blue-600 dark:text-blue-400",children:[g," live"]})]})]}),!A&&R&&(0,t.jsx)(dt,{variant:"ghost",className:U("ml-auto px-1.5 leading-none",d==="danger"?"bg-red-600/90 text-red-50":d==="warning"?"bg-amber-500/90 text-amber-50":"bg-primary text-primary-foreground"),children:c})]});return A?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("div",{children:$})}),(0,t.jsx)(Kn,{side:"right",children:s})]}):$}r(Ha,"SidebarNavItem");var FYe=3,jJ=12e4,BYe=[{value:"top",label:"Top"},{value:"alphabetical",label:"Alphabetical"},{value:"recent",label:"Recent"}];function my(e,s){const n=e[s];if(!n)return 0;const a=new Date(n).getTime();return Number.isFinite(a)?a:0}r(my,"agentTimestamp");function wJ(e,s){if(s==="top")return e;const n=[...e];return s==="alphabetical"?(n.sort((a,i)=>a.name.localeCompare(i.name,void 0,{sensitivity:"base"})),n):(n.sort((a,i)=>{const o=my(i,"lastHeartbeatAt")-my(a,"lastHeartbeatAt");if(o!==0)return o;const l=my(i,"updatedAt")-my(a,"updatedAt");if(l!==0)return l;const c=my(i,"createdAt")-my(a,"createdAt");return c!==0?c:a.name.localeCompare(i.name,void 0,{sensitivity:"base"})}),n)}r(wJ,"sortAgents");var qYe="opacity-0 transition-opacity group-hover/agent:opacity-100 group-focus-within/agent:opacity-100";function zYe({activeAgentId:e,activeTab:s,agent:n,disabled:a,isMobile:i,leaving:o,onLeaveAgent:l,onPauseResume:c,rail:d,runCount:u,setSidebarOpen:h,builtInStatus:p,starred:x=!1,onToggleStar:g,starPending:v=!1}){const y=vc(n),j=s?`${Ku(n)}/${s}`:Ku(n),S=`${Ku(n)}/configuration`,w=e===y,N=n.status==="paused",_=N&&n.pauseReason==="budget",I=n.orgChainHealth?.status==="invalid_org_chain",C=N?"Resume agent":"Pause agent",A=a||n.status==="pending_approval"||_||N&&I,R=a?"Updating...":_?"Budget paused":N&&I?"Invalid org chain":C,E=p==="needs_setup"||p==="pending_approval",O=[E?`Built-in agent ${p.replace(/_/g," ")}`:null,I?"Invalid reporting chain":null].filter(Boolean).join(", ")||void 0,L=(0,t.jsx)(Ha,{to:j,label:n.name,iconNode:(0,t.jsx)(hr,{agent:n,size:16,className:"shrink-0 h-4 w-4"}),active:w,liveCount:u,labelClassName:E?"min-w-(--sz-4_5rem) flex-initial":void 0,className:U("min-w-0 flex-1",x&&!i?"pr-14":"pr-8"),trailing:E||I?(0,t.jsxs)("span",{className:"ml-1 flex shrink-0 items-center gap-1",children:[E?(0,t.jsx)(vj,{status:p,compact:!0}):null,I?(0,t.jsx)(Is,{className:"h-3.5 w-3.5 shrink-0 text-amber-500","aria-label":"Invalid reporting chain"}):null]}):void 0,trailingLabel:O,liveAccessory:n.pauseReason==="budget"?(0,t.jsx)(x1,{title:"Agent paused by budget"}):void 0});return d?L:(0,t.jsxs)("div",{className:"group/agent relative flex items-center",children:[L,x&&!i&&g?(0,t.jsx)("span",{className:"absolute right-10 top-1/2 -translate-y-1/2",children:(0,t.jsx)(o0,{size:"row",quiet:!0,starred:!0,pending:v,resourceName:n.name,onToggle:r(()=>g(n,!1),"onToggle"),revealClassName:qYe})}):null,(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:U("absolute right-3 top-1/2 h-6 w-6 -translate-y-1/2 transition-opacity data-[state=open]:pointer-events-auto data-[state=open]:opacity-100",i?"opacity-100":"pointer-events-none opacity-0 group-hover/agent:pointer-events-auto group-hover/agent:opacity-100 group-focus-within/agent:pointer-events-auto group-focus-within/agent:opacity-100"),"aria-label":`Open actions for ${n.name}`,children:(0,t.jsx)(Pi,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(ga,{align:"end",className:"w-48",children:[g?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(ps,{onClick:r(()=>{v||g(n,!x)},"onClick"),disabled:v,children:[v?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Th,{className:U("size-4",x&&"fill-amber-500 text-amber-500")}),(0,t.jsx)("span",{children:x?"Remove from starred":"Star agent"})]}),(0,t.jsx)(hi,{})]}):null,(0,t.jsx)(ps,{asChild:!0,children:(0,t.jsxs)(Qe,{to:S,onClick:r(()=>{i&&h(!1)},"onClick"),children:[(0,t.jsx)(ql,{className:"size-4"}),(0,t.jsx)("span",{children:"Edit agent"})]})}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{A||c(n,N?"resume":"pause")},"onClick"),disabled:A,title:_?"Agent was paused by budget limits":void 0,children:[N?(0,t.jsx)(u1,{className:"size-4"}):(0,t.jsx)(ld,{className:"size-4"}),(0,t.jsx)("span",{children:R})]}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{o||l(n)},"onClick"),disabled:o,children:[o?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Yh,{className:"size-4"}),(0,t.jsx)("span",{children:o?"Leaving...":"Leave agent"})]})]})]})]})}r(zYe,"SidebarAgentItem");function UYe({streamlined:e=!1}={}){const[s,n]=(0,m.useState)(!0),[a,i]=(0,m.useState)(()=>new Set),[o,l]=(0,m.useState)(0),c=(0,m.useRef)(new Map),d=Ht(),{selectedCompanyId:u}=fs(),{openNewAgent:h}=Lo(),{isMobile:p,setSidebarOpen:x,collapsed:g,peeking:v}=$a(),y=g&&!v,{pushToast:j}=ua(),S=Zr(),{data:w}=ee({queryKey:P.agents.list(u),queryFn:r(()=>Wt.list(u),"queryFn"),enabled:!!u}),{data:N}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),enabled:!!u}),_=N?.enableBuiltInAgents===!0,{data:I}=ee({queryKey:P.builtInAgents.list(u),queryFn:r(()=>fh.list(u),"queryFn"),enabled:!!u&&_}),C=(0,m.useMemo)(()=>{const fe=new Map;if(!_)return fe;for(const Ce of I??[])Ce.agentId&&fe.set(Ce.agentId,Ce.status);return fe},[I,_]),{data:A}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn")}),R=cf(u),E=df(u),O=P.liveRuns(u),L=mo({companyId:u,resourceKey:"live-runs",queryKey:O,enabled:!!u,refetchInterval:!1,leaderOnly:!0}),{data:$,dataUpdatedAt:T}=ee({queryKey:O,queryFn:r(()=>Xr.liveRunsForCompany(u),"queryFn"),enabled:L.enabled,refetchInterval:L.refetchInterval});ho(L,$,T);const q=(0,m.useMemo)(()=>{const fe=new Map;for(const Ce of $??[])fe.set(Ce.agentId,(fe.get(Ce.agentId)??0)+1);return fe},[$]),B=(0,m.useMemo)(()=>{const fe=new Set;for(const[Ce,Xe]of q)Xe>0&&fe.add(Ce);return fe},[q]),K=(0,m.useMemo)(()=>(w??[]).filter(fe=>fe.status!=="terminated"&&(!R.isSuccess||vx(R.data,"agent",fe.id)!=="left")),[w,R.data,R.isSuccess]),z=A?.user?.id??A?.session?.userId??null,D=(0,m.useMemo)(()=>u?Qde(u,z):null,[z,u]),[V,H]=(0,m.useState)(()=>D?yj(D):"top"),{orderedAgents:Z}=Jde({agents:K,companyId:u,userId:z}),Y=(0,m.useMemo)(()=>wJ(Z,V),[Z,V]),ie=(0,m.useMemo)(()=>new Set(Y.map(fe=>fe.id)),[Y]);(0,m.useEffect)(()=>{const fe=Date.now();for(const Ce of B)c.current.set(Ce,fe);for(const Ce of c.current.keys())ie.has(Ce)||c.current.delete(Ce)},[B,ie]);const se=(0,m.useMemo)(()=>{const fe=Date.now(),Ce=c.current;return Y.filter(Xe=>{if((q.get(Xe.id)??0)>0)return!0;const Oe=Ce.get(Xe.id);return Oe!==void 0&&fe-Oe<=jJ})},[q,o,Y]),X=se.length>0,le=e?X?se:Y.slice(0,FYe):Y,oe=e&&Y.length>0,te=S.pathname.match(/^\/(?:[^/]+\/)?agents\/([^/]+)(?:\/([^/]+))?/),J=te?.[1]??null,Q=te?.[2]??null;(0,m.useEffect)(()=>{if(!D){H("top");return}H(yj(D))},[D]),(0,m.useEffect)(()=>{if(!D)return;const fe=r(Xe=>{Xe.key===D&&H(yj(D))},"onStorage"),Ce=r(Xe=>{const Oe=Xe.detail;!Oe||Oe.storageKey!==D||H(Oe.sortMode)},"onCustomEvent");return window.addEventListener("storage",fe),window.addEventListener(US,Ce),()=>{window.removeEventListener("storage",fe),window.removeEventListener(US,Ce)}},[D]),(0,m.useEffect)(()=>{if(!e)return;const fe=Date.now();let Ce=null;for(const Oe of Y){if((q.get(Oe.id)??0)>0)continue;const tt=c.current.get(Oe.id);if(tt===void 0)continue;const ce=tt+jJ;ce<fe||(Ce=Ce===null?ce:Math.min(Ce,ce))}if(Ce===null)return;const Xe=window.setTimeout(()=>{l(Oe=>Oe+1)},Math.max(0,Ce-fe+1));return()=>{window.clearTimeout(Xe)}},[e,Y,q,o]);const pe=(0,m.useCallback)(fe=>{const Ce=fe==="alphabetical"||fe==="recent"?fe:"top";H(Ce),D&&Yde(D,Ce)},[D]),re=ye({mutationFn:r(({agent:fe,action:Ce})=>Ce==="pause"?Wt.pause(fe.id,u??void 0):Wt.resume(fe.id,u??void 0),"mutationFn"),onMutate:r(({agent:fe})=>{i(Ce=>{const Xe=new Set(Ce);return Xe.add(fe.id),Xe})},"onMutate"),onSuccess:r(async(fe,{agent:Ce,action:Xe})=>{u&&await Promise.all([d.invalidateQueries({queryKey:P.agents.list(u)}),d.invalidateQueries({queryKey:P.liveRuns(u)}),d.invalidateQueries({queryKey:P.dashboard(u)})]),await Promise.all([d.invalidateQueries({queryKey:P.agents.detail(Ce.id)}),d.invalidateQueries({queryKey:P.agents.detail(vc(Ce))})]),j({title:Xe==="pause"?"Agent paused":"Agent resumed",body:Ce.name,tone:"success"})},"onSuccess"),onError:r((fe,{agent:Ce,action:Xe})=>{j({title:Xe==="pause"?"Could not pause agent":"Could not resume agent",body:fe instanceof Error?fe.message:Ce.name,tone:"error"})},"onError"),onSettled:r((fe,Ce,{agent:Xe})=>{i(Oe=>{const tt=new Set(Oe);return tt.delete(Xe.id),tt})},"onSettled")}),ne=(0,m.useCallback)(fe=>E.mutate({resourceType:"agent",resourceId:fe.id,resourceName:fe.name,state:"left"}),[E]),ae=(0,m.useCallback)(fe=>E.isPending&&E.variables?.resourceType==="agent"&&E.variables.resourceId===fe.id,[E.isPending,E.variables]),me=(0,m.useCallback)((fe,Ce)=>E.mutate({resourceType:"agent",resourceId:fe.id,resourceName:fe.name,starred:Ce}),[E]),he=(0,m.useCallback)(fe=>E.isPending&&E.variables?.resourceType==="agent"&&E.variables.resourceId===fe.id&&E.variables.starred!==void 0,[E.isPending,E.variables]),Ie=(0,m.useMemo)(()=>new Set(y5(R.data,"agent")),[R.data]),de=(0,m.useMemo)(()=>wJ(K.filter(fe=>Ie.has(fe.id)),"alphabetical"),[K,Ie]),ve=(0,m.useMemo)(()=>le.filter(fe=>!Ie.has(fe.id)),[le,Ie]),Te=r((fe,Ce)=>(0,t.jsx)(zYe,{activeAgentId:J,activeTab:Q,agent:fe,disabled:a.has(fe.id),isMobile:p,leaving:ae(fe),onLeaveAgent:ne,onPauseResume:r((Xe,Oe)=>re.mutate({agent:Xe,action:Oe}),"onPauseResume"),rail:y,runCount:q.get(fe.id)??0,setSidebarOpen:x,builtInStatus:C.get(fe.id),starred:Ce||i0(R.data,"agent",fe.id),onToggleStar:me,starPending:he(fe)},fe.id),"renderAgentRow");return(0,t.jsxs)(cx,{label:"Agents",collapsible:{open:s,onOpenChange:n},headerAction:{ariaLabel:"New agent",icon:xn,onClick:h},menu:{ariaLabel:"Agents section actions",actions:[{type:"item",label:"Browse agents",icon:Xo,href:"/agents/all"},{type:"separator"}],radioLabel:"Agent sort",radioChoices:BYe,radioValue:V,onRadioValueChange:pe},children:[de.map(fe=>Te(fe,!0)),ve.map(fe=>Te(fe,!1)),oe&&(()=>{const fe=(0,t.jsxs)(Qe,{to:"/agents/all",state:lf,"aria-label":y?"See all agents":void 0,onClick:r(()=>{p&&x(!1)},"onClick"),className:"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(Xo,{className:"shrink-0 h-4 w-4"}),(0,t.jsx)("span",{className:y?"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none":void 0,children:"See all agents"})]});return y?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:fe}),(0,t.jsx)(Kn,{side:"right",children:"See all agents"})]}):fe})()]})}r(UYe,"SidebarAgents");var KYe="opacity-0 transition-opacity group-hover/starred-project:opacity-100 group-focus-within/starred-project:opacity-100";function VYe(){const{selectedCompanyId:e}=fs(),{isMobile:s,setSidebarOpen:n,collapsed:a,peeking:i}=$a(),o=a&&!i,l=Zr(),{data:c}=ee({queryKey:P.projects.list(e),queryFn:r(()=>oa.list(e),"queryFn"),enabled:!!e}),d=cf(e),u=df(e),h=l.pathname.match(/^\/(?:[^/]+\/)?projects\/([^/]+)/)?.[1]??null,p=(0,m.useMemo)(()=>{if(!d.isSuccess)return[];const y=new Set(y5(d.data,"project"));if(y.size===0)return[];const j=new Map((c??[]).map(S=>[S.id,S]));return Array.from(y).map(S=>j.get(S)).filter(S=>!!S).sort((S,w)=>S.name.localeCompare(w.name,void 0,{sensitivity:"base"}))},[d.data,d.isSuccess,c]),x=(0,m.useCallback)(y=>u.mutate({resourceType:"project",resourceId:y.id,resourceName:y.name,starred:!1}),[u]),g=(0,m.useCallback)(y=>u.mutate({resourceType:"project",resourceId:y.id,resourceName:y.name,state:"left"}),[u]),v=(0,m.useCallback)(y=>u.isPending&&u.variables?.resourceType==="project"&&u.variables.resourceId===y.id,[u.isPending,u.variables]);return!d.isSuccess||p.length===0?null:(0,t.jsx)("div",{className:"flex flex-col gap-0.5","aria-label":"Starred projects",children:p.map(y=>{const j=s0(y),S=h===j||h===y.id,w=v(y),N=w&&u.variables?.starred===!1,_=w&&u.variables?.state==="left",I=i0(d.data,"project",y.id),C=(0,t.jsxs)(r0,{to:`/projects/${j}/issues`,state:lf,onClick:r(()=>{s&&n(!1)},"onClick"),className:U("flex min-w-0 flex-1 items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 pr-8 text-(length:--text-compact) font-medium transition-colors",!o&&"pl-6",S?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground"),children:[(0,t.jsx)(Km,{color:y.color??null,icon:y.icon??null,size:"xs"}),(0,t.jsx)("span",{className:o?bv:"flex-1 truncate",children:y.name}),!o&&y.pauseReason==="budget"?(0,t.jsx)(x1,{title:"Project paused by budget"}):null]});return(0,t.jsxs)("div",{className:"group/starred-project relative flex items-center",children:[o?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("div",{className:"min-w-0 flex-1",children:C})}),(0,t.jsx)(Kn,{side:"right",children:y.name})]}):C,!o&&!s?(0,t.jsx)("span",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:(0,t.jsx)(o0,{size:"row",quiet:!0,starred:I,pending:N,resourceName:y.name,onToggle:r(()=>x(y),"onToggle"),revealClassName:KYe})}):null,!o&&s?(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",className:"absolute right-3 top-1/2 h-6 w-6 -translate-y-1/2 opacity-100","aria-label":`Open actions for ${y.name}`,children:(0,t.jsx)(Pi,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(ga,{align:"end",className:"w-48",children:[(0,t.jsxs)(ps,{onClick:r(()=>{w||x(y)},"onClick"),disabled:w,children:[N?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Th,{className:"size-4 fill-amber-500 text-amber-500"}),(0,t.jsx)("span",{children:"Remove from starred"})]}),(0,t.jsx)(hi,{}),(0,t.jsxs)(ps,{onClick:r(()=>{w||g(y)},"onClick"),disabled:w,children:[_?(0,t.jsx)(ot,{className:"size-4 motion-safe:animate-spin"}):(0,t.jsx)(Yh,{className:"size-4"}),(0,t.jsx)("span",{children:"Leave project"})]})]})]}):null]},y.id)})})}r(VYe,"SidebarStarredProjects");var $xe="size-5 shrink-0 rounded-md text-(length:--text-micro)",Oxe="size-(--organization-popover-avatar-size) shrink-0 rounded-lg text-(length:--text-micro)",Fxe="h-(--organization-popover-company-row-height) min-w-0 gap-(--organization-popover-row-gap) rounded-lg px-2.5 py-0 text-(length:--text-compact) focus:bg-accent/50 focus:text-foreground",B4="h-(--organization-popover-action-row-height) gap-(--organization-popover-row-gap) rounded-lg px-2.5 py-0 text-(length:--text-compact) font-medium leading-(--organization-popover-action-line-height) text-foreground focus:bg-accent/50 focus:text-foreground";function Bxe({company:e,inPopover:s=!1}){return(0,t.jsx)(Rx,{companyName:e.name,logoUrl:e.logoUrl,className:s?Oxe:$xe})}r(Bxe,"WorkspaceIcon");function WYe({displayName:e}){return(0,t.jsx)(Rx,{companyName:e,className:Oxe})}r(WYe,"StackIcon");function HYe({displayName:e,company:s}){return(0,t.jsx)(Rx,{companyName:e,logoUrl:s?.logoUrl,className:$xe})}r(HYe,"CurrentStackIcon");function QYe({stack:e,isSelected:s,onSelect:n}){return(0,t.jsxs)(ps,{onSelect:r(()=>n(e),"onSelect"),className:Fxe,children:[(0,t.jsx)(WYe,{displayName:e.displayName}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block truncate font-medium leading-(--organization-popover-name-line-height)",title:e.displayName,children:e.displayName}),(0,t.jsx)("span",{className:"block truncate text-(length:--text-nano) leading-(--organization-popover-prefix-line-height) text-muted-foreground",title:e.stackSlug,children:e.stackSlug})]}),(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center",children:s?(0,t.jsx)(xs,{className:"size-4 text-foreground"}):null})]})}r(QYe,"CloudStackItem");function GYe({company:e,isEditing:s,isSelected:n,onSelect:a}){const{attributes:i,listeners:o,setActivatorNodeRef:l,setNodeRef:c,transform:d,transition:u,isDragging:h}=Lw({id:e.id,disabled:!s});return(0,t.jsxs)(ps,{ref:c,style:{transform:Pw.Transform.toString(d),transition:u,zIndex:h?10:void 0},onSelect:r(p=>{if(s){p.preventDefault();return}a(e)},"onSelect"),className:U(Fxe,s&&"cursor-grab",h&&"opacity-80"),children:[(0,t.jsx)(Bxe,{company:e,inPopover:!0}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block truncate font-medium leading-(--organization-popover-name-line-height)",children:e.name}),s?null:(0,t.jsx)("span",{className:"block truncate text-(length:--text-nano) leading-(--organization-popover-prefix-line-height) text-muted-foreground",children:e.issuePrefix})]}),s?(0,t.jsx)("button",{type:"button",ref:l,"aria-label":`Reorder ${e.name}`,className:"inline-flex size-8 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-(length:--rad-2) focus-visible:ring-ring",onClick:r(p=>{p.preventDefault(),p.stopPropagation()},"onClick"),...i,...o,children:(0,t.jsx)(fz,{className:"size-4","aria-hidden":"true"})}):(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center",children:n?(0,t.jsx)(xs,{className:"size-4 text-foreground"}):null})]})}r(GYe,"SortableCompanyItem");function YYe(e={}){return(0,t.jsx)(Jue,{...e,children:(0,t.jsx)(JYe,{...e})})}r(YYe,"SidebarCompanyMenu");function JYe({open:e,onOpenChange:s}){const[n,a]=(0,m.useState)(!1),[i,o]=(0,m.useState)(!1),{companies:l,selectedCompany:c,setSelectedCompanyId:d,companyListUnavailable:u,retryCompanies:h}=fs(),{openOnboarding:p}=Lo(),{isMobile:x,setSidebarOpen:g,collapsed:v,peeking:y}=$a(),j=v&&!y,S=Zr(),w=Wn(),N=e??n,_=s??a,I=Dw(Yp(Z6,{activationConstraint:{distance:8}}),Yp(Hle,{activationConstraint:{delay:180,tolerance:6}})),C=(0,m.useMemo)(()=>l.filter(Q=>Q.status!=="archived"),[l]),{data:A}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),R=A?.user?.id??A?.session?.userId??null,{orderedCompanies:E,persistOrder:O}=Gue({companies:C,userId:R}),L=Vc(),$=!!L,{hidden:T,loaded:q}=Ym(),B=q&&!LS(T,"company.members")&&!LS(T,"company.invites"),K=L?.cloudBaseUrl??null,z=ee({queryKey:P.cloud.stacks,queryFn:r(()=>Hue.listStacks(),"queryFn"),enabled:$,staleTime:3e4,retry:!1}),D=z.data?.stacks??[],V=$?D.find(Q=>Q.isCurrent)??D.find(Q=>!!L?.stackSlug&&Q.stackSlug===L?.stackSlug)??null:null,H=$?C5(K):null,Z=$?"organization":"company",Y=$?V?.displayName??L?.stackDisplayName??L?.stackSlug??null:c?.name??null,ie=Hw({onSignedOut:X});function se(Q){Q||o(!1),_(Q)}r(se,"handleOpenChange");function X(){_(!1),o(!1),x&&g(!1)}r(X,"closeNavigationChrome");function le(Q){const pe=S.pathname.split("/")[1]?.toUpperCase(),re=C.some(ae=>ae.issuePrefix.toUpperCase()===pe),ne=Q.id!==c?.id&&(S.pathname.startsWith("/instance/")||re);d(Q.id),_(!1),x&&g(!1),ne&&w(`/${Q.issuePrefix}/dashboard`)}r(le,"selectCompany");function oe(Q){if(_(!1),x&&g(!1),Q.stackSlug===V?.stackSlug)return;const pe=Yue(K,Q.stackSlug);pe&&jc(pe)}r(oe,"selectStack");function te(){if(_(!1),x&&g(!1),$){H&&jc(H);return}p({initialStep:1})}r(te,"addCompany");const J=(0,m.useCallback)(Q=>{const{active:pe,over:re}=Q;if(!re||pe.id===re.id)return;const ne=E.map(he=>he.id),ae=ne.indexOf(pe.id),me=ne.indexOf(re.id);ae===-1||me===-1||O(Z3(ne,ae,me))},[E,O]);return(0,t.jsxs)(xa,{open:N,onOpenChange:se,children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsxs)(F,{variant:"ghost",className:"h-9 min-w-0 flex-1 justify-start gap-2 px-4 text-left hover:bg-accent/50 hover:text-foreground has-[>svg]:px-4 dark:hover:bg-accent/50","aria-label":Y?`Open ${Y} ${Z} switcher`:`Open ${Z} switcher`,children:[(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[$?Y?(0,t.jsx)(HYe,{displayName:Y,company:c}):null:c?(0,t.jsx)(Bxe,{company:c}):null,(0,t.jsx)("span",{className:U("min-w-0 truncate text-sm font-bold text-foreground",j&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),title:Y??void 0,children:Y??($?"Select organization":"Select company")})]}),!j&&(0,t.jsx)(i5,{className:"size-3.5 shrink-0 text-muted-foreground"})]})}),(0,t.jsxs)(ga,{align:"start",sideOffset:8,className:"ml-2 w-(--organization-popover-width) max-w-(--sz-calc-24) overflow-hidden rounded-xl border-border bg-popover p-0 shadow-(--shadow-profile-popover)",children:[(0,t.jsxs)("div",{className:"flex h-(--organization-popover-header-height) items-center justify-between gap-2 px-3.5",children:[(0,t.jsx)(Ow,{className:"p-0 text-(length:--text-compact) font-semibold text-foreground",children:"Organizations"}),$?null:(0,t.jsx)("button",{type:"button",onClick:r(Q=>{Q.preventDefault(),Q.stopPropagation(),o(pe=>!pe)},"onClick"),className:"rounded px-1.5 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:i?"Done":"Edit"})]}),(0,t.jsx)("div",{className:"flex max-h-96 flex-col gap-0.5 overflow-y-auto px-2.5 pb-2 pt-1",children:$?(0,t.jsxs)(t.Fragment,{children:[D.map(Q=>(0,t.jsx)(QYe,{stack:Q,isSelected:Q.stackSlug===V?.stackSlug,onSelect:oe},Q.stackSlug)),D.length===0?(0,t.jsx)(ps,{disabled:!0,children:z.isLoading?"Loading organizations...":z.isError?"Could not load organizations":"No organizations"}):null]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ew,{sensors:I,collisionDetection:GC,onDragEnd:J,children:(0,t.jsx)(Tw,{items:E.map(Q=>Q.id),strategy:HC,children:E.map(Q=>(0,t.jsx)(GYe,{company:Q,isEditing:i,isSelected:Q.id===c?.id,onSelect:le},Q.id))})}),E.length===0?u?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ps,{disabled:!0,children:"Couldn't load companies"}),(0,t.jsxs)(ps,{onSelect:r(Q=>{Q.preventDefault(),h()},"onSelect"),children:[(0,t.jsx)(zi,{className:"h-4 w-4 mr-2"}),"Try again"]})]}):(0,t.jsx)(ps,{disabled:!0,children:"No companies"}):null]})}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5 border-t border-border px-2.5 pb-2.5 pt-2",children:[$&&!H?null:(0,t.jsxs)(ps,{onClick:te,className:B4,disabled:i,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(xn,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:"Create organization"})]}),B?(0,t.jsx)(ps,{asChild:!0,disabled:i,className:B4,children:(0,t.jsxs)(Qe,{to:"/company/settings/invites",onClick:r(Q=>{if(i){Q.preventDefault();return}X()},"onClick"),children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Sv,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Y?`Invite people to ${Y}`:"Invite people"})]})}):null,A?.session?(0,t.jsxs)(ps,{className:B4,onClick:r(()=>ie.mutate(),"onClick"),disabled:i||ie.isPending,children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:ie.isPending?"Signing out...":"Sign out"})]}):null]})]})]})}r(JYe,"BuiltinCompanyMenu");function NJ(){const{openNewIssue:e}=Lo(),[s,n]=(0,m.useState)(!0),[a,i]=(0,m.useState)(!0),{selectedCompanyId:o,selectedCompany:l}=fs(),{collapsed:c,peeking:d}=$a(),u=c&&!d,h=Hz(o),{data:p}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")}),x=P.liveRuns(o),g=mo({companyId:o,resourceKey:"live-runs",queryKey:x,enabled:!!o,refetchInterval:!1,leaderOnly:!0}),{data:v,dataUpdatedAt:y}=ee({queryKey:x,queryFn:r(()=>Xr.liveRunsForCompany(o),"queryFn"),enabled:g.enabled,refetchInterval:g.refetchInterval});ho(g,v,y);const j=v?.length??0,S=p?.enableIsolatedWorkspaces===!0,w=p?.enableApps===!0,N=p?.enablePipelines===!0,_=p?.enableStatusCards===!0,I=p===void 0,C=p?.enableGoalsSidebarLink===!0,A=p?.enableDecisions===!0,{data:R}=ee({queryKey:P.attention(o),queryFn:r(()=>k5.list(o),"queryFn"),enabled:!!o&&A,refetchInterval:6e4}),E=kue(R),O=p?.enableCases===!0,L=!0,$=p?.enableConferenceRoomChat===!0,T={companyId:o,companyPrefix:l?.issuePrefix??null};return(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsx)("div",{className:"flex items-center gap-1 px-3 h-12 shrink-0",children:(0,t.jsx)(YYe,{})}),(0,t.jsxs)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide flex flex-col gap-4 pointer-coarse:gap-3 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(()=>{const q=(0,t.jsxs)("button",{onClick:r(()=>e(),"onClick"),"data-slot":"icon-button","aria-label":u?"New Task":void 0,className:"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium text-foreground/80 hover:bg-accent/50 hover:text-foreground transition-colors",children:[(0,t.jsx)(h1,{className:"h-4 w-4 shrink-0"}),(0,t.jsx)("span",{className:u?bv:"truncate",children:"New Task"})]});return u?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:q}),(0,t.jsx)(Kn,{side:"right",children:"New Task"})]}):q})(),(0,t.jsx)(Ha,{to:"/search",label:"Search",icon:pa}),(0,t.jsx)(Ha,{to:"/dashboard",label:"Dashboard",icon:lx,liveCount:j}),(0,t.jsx)(Ha,{to:"/inbox",label:"Inbox",icon:Td,badge:h.inbox,badgeLabel:"unread",badgeTone:h.failedRuns>0?"danger":"default",alert:h.failedRuns>0}),A?(0,t.jsx)(Ha,{to:"/decisions",label:"Decisions",icon:m1,badge:E,badgeLabel:"decisions"}):null,_?(0,t.jsx)(Ha,{to:"/status",label:"Status",icon:Kw,textBadge:"beta"}):null,$?(0,t.jsx)(Ha,{to:"/board-chat",label:"Conference Room",icon:hde}):null]}),(0,t.jsxs)(cx,{label:"Work",collapsible:{open:s,onOpenChange:n},children:[(0,t.jsx)(Ha,{to:"/issues",label:"Tasks",icon:ad}),O?(0,t.jsx)(Ha,{to:"/cases",label:"Cases",icon:hl,textBadge:"beta"}):null,(0,t.jsx)(Ha,{to:"/routines",label:"Routines",icon:du}),N?(0,t.jsx)(Ha,{to:"/pipelines",label:"Pipelines",icon:sl}):null,C?(0,t.jsx)(Ha,{to:"/goals",label:"Goals",icon:px}):I?(0,t.jsx)("div",{"data-testid":"sidebar-goals-placeholder",className:"h-8 pointer-coarse:h-7","aria-hidden":"true"}):null,(0,t.jsx)(Ha,{to:"/artifacts",label:"Artifacts",icon:Eh}),(0,t.jsx)(Ha,{to:"/skills",label:"Skills",icon:Bl}),S?(0,t.jsx)(Ha,{to:"/workspaces",label:"Workspaces",icon:sl}):null,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Ha,{to:"/projects",label:"Projects",icon:Io}),(0,t.jsx)(VYe,{})]}),(0,t.jsx)(zh,{slotTypes:["sidebar"],context:T,className:"flex flex-col gap-0.5",itemClassName:"text-(length:--text-compact) font-medium",missingBehavior:"placeholder"}),(0,t.jsx)(Ww,{placementZones:["sidebar"],context:T,className:"flex flex-col gap-0.5",itemClassName:"text-(length:--text-compact) font-medium"})]}),null,(0,t.jsx)(UYe,{streamlined:L}),(0,t.jsxs)(cx,{label:"Company",collapsible:{open:a,onOpenChange:i},children:[(0,t.jsx)(Ha,{to:"/org",label:"Org",icon:Kb}),w?(0,t.jsx)(Ha,{to:"/apps",label:"Connectors",icon:qR}):null,(0,t.jsx)(Ha,{to:"/timeline",label:"Timeline",icon:vg}),(0,t.jsx)(Ha,{to:"/costs",label:"Costs",icon:_h}),(0,t.jsx)(Ha,{to:"/activity",label:"Activity",icon:Nl}),(0,t.jsx)(Ha,{to:"/company/settings",label:"Settings",icon:Dd})]}),(0,t.jsx)(zh,{slotTypes:["sidebarPanel"],context:T,className:"flex flex-col gap-3",itemClassName:"rounded-lg border border-border p-3",missingBehavior:"placeholder"})]})]})}r(NJ,"Sidebar");function XYe(e){const s=e.manifestJson.environmentDrivers??[];return s.length===0?!1:s.every(n=>n.kind==="sandbox_provider")}r(XYe,"isSandboxProviderOnly");function ZYe(){const{selectedCompany:e,selectedCompanyId:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),{hidden:i}=Ym(),o=r(x=>!i.has(x),"showPage"),l=o("instance.plugins"),c=!!Vc(),{slots:d}=Kc({slotTypes:["companySettingsPage"],companyId:s,enabled:!!s}),{data:u}=ee({queryKey:s?P.sidebarBadges(s):["sidebar-badges","__disabled__"],queryFn:r(async()=>{try{return await sme.get(s)}catch(x){if(x instanceof Nn&&(x.status===401||x.status===403))return null;throw x}},"queryFn"),enabled:!!s,retry:!1,refetchInterval:15e3}),{data:h}=ee({queryKey:P.plugins.all,queryFn:r(()=>Jo.list(),"queryFn"),enabled:l}),p=(h??[]).filter(x=>!XYe(x));return(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsx)("div",{className:"flex flex-col gap-1 px-3 py-3 shrink-0",children:(0,t.jsxs)(Qe,{to:"/dashboard",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:e?.name??"Company"})]})}),(0,t.jsx)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide px-3 py-2",children:(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/company/settings",label:"General",icon:Xu,end:!0}),o("instance.profile")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/profile",label:"Profile",icon:p1,end:!0}),o("company.members")&&(0,t.jsx)(Ha,{to:"/company/settings/members",label:"Members",icon:Xo,badge:u?.joinRequests??0,end:!0}),d.filter(x=>x.routePath).map(x=>(0,t.jsx)(Ha,{to:`/company/settings/${x.routePath}`,label:x.displayName,icon:Eg,end:!0},`${x.pluginKey}:${x.id}`)),o("company.invites")&&(0,t.jsx)(Ha,{to:"/company/settings/invites",label:"Invites",icon:i5e,end:!0}),o("company.secrets")&&(0,t.jsx)(Ha,{to:"/company/settings/secrets",label:"Secrets",icon:ji,end:!0}),o("instance.environments")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/environments",label:"Environments",icon:pde,end:!0}),o("instance.access")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/access",label:"Access",icon:r5,end:!0}),o("instance.heartbeats")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/heartbeats",label:"Heartbeats",icon:Xm,end:!0}),o("company.export")&&(0,t.jsx)(Ha,{to:"/company/export",label:"Export",icon:Ko}),!c&&o("company.import")&&(0,t.jsx)(Ha,{to:"/company/import",label:"Import",icon:Yj,end:!0}),o("instance.experimental")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/experimental",label:"Experimental",icon:Gu}),l&&(0,t.jsx)(Ha,{to:"/company/settings/instance/plugins",label:"Plugins",icon:Eg}),l&&p.length>0?(0,t.jsx)("div",{className:"ml-4 mt-1 flex flex-col gap-0.5 border-l border-border/70 pl-3",children:p.map(x=>(0,t.jsx)(r0,{to:`${xh}/plugins/${x.id}`,state:lf,className:r(({isActive:g})=>["rounded-md px-2 py-1.5 text-xs transition-colors",g?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"].join(" "),"className"),children:x.manifestJson.displayName??x.packageName},x.id))}):null,o("instance.adapters")&&(0,t.jsx)(Ha,{to:"/company/settings/instance/adapters",label:"Adapters",icon:Pm})]})})]})}r(ZYe,"CompanySettingsSidebar");function eJe(){const{pathname:e}=Zr(),{selectedCompany:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),i=cme(),{enabled:o}=_5(),l=Xz.filter(d=>!lme(d.key)||o);if(e.endsWith("/apps/chat/connect"))return(0,t.jsx)(Iz,{});const c=e.match(/\/apps\/chat\/([^/]+)(?:\/(?:settings|access|reviews|conversations|activity))?\/?$/);return c?(0,t.jsx)(ome,{endpointId:c[1],NavItem:Ha}):(0,t.jsxs)("aside",{className:"w-full h-full min-h-0 border-r border-border bg-background flex flex-col",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 px-3 py-3 shrink-0",children:[(0,t.jsxs)(Qe,{to:"/dashboard",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:s?.name??"Company"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1",children:[(0,t.jsx)(aH,{className:"h-4 w-4 text-muted-foreground shrink-0"}),(0,t.jsx)("span",{className:"flex-1 truncate text-sm font-bold text-foreground",children:"Connectors"})]})]}),(0,t.jsxs)("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide px-3 py-2",children:[(0,t.jsx)("div",{className:"px-3 pb-1 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Connectors"}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/apps",label:"Browse",icon:qS,end:!0}),(0,t.jsx)(Ha,{to:"/apps/review",label:"Review",icon:Vw,badge:i>0?i:void 0,badgeTone:"warning",badgeLabel:"waiting for your OK"})]}),(0,t.jsx)("div",{className:"px-3 pb-1 pt-4 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Developer"}),(0,t.jsx)("p",{className:"px-3 pb-1.5 text-(length:--text-micro) leading-snug text-muted-foreground/70",children:"Advanced setup for developers. Most teams never open this."}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)(Ha,{to:"/apps/connections",label:"Connections",icon:aH,end:!0}),l.map(d=>(0,t.jsx)(Ha,{to:Mg(d.key),label:d.label,icon:d.icon,end:!0},d.key))]})]})]})}r(eJe,"AppsSidebar");function kJ(e){const{selectedCompanyId:s}=fs(),{isMobile:n,setSidebarOpen:a}=$a(),i=ee({queryKey:P.tools.connection(e.kind==="connection"?e.connectionId:"__none__"),queryFn:r(()=>us.getConnection(e.kind==="connection"?e.connectionId:""),"queryFn"),enabled:e.kind==="connection"&&!!e.connectionId}),o=ee({queryKey:P.tools.applications(s??"__none__"),queryFn:r(()=>us.listApplications(s),"queryFn"),enabled:e.kind==="application"&&!!s}),l=ee({queryKey:P.tools.connections(s??"__none__"),queryFn:r(()=>us.listConnections(s),"queryFn"),enabled:e.kind==="application"&&!!s}),c=ee({queryKey:P.apps.gallery(s??"__none__"),queryFn:r(()=>us.listGallery(s),"queryFn"),enabled:!!s}),d=ee({queryKey:P.apps.attention(s??"__none__"),queryFn:r(()=>us.listAppsAttention(s),"queryFn"),enabled:!!s,refetchInterval:3e4}),u=i.data,h=e.kind==="application"?(o.data?.applications??[]).find(S=>S.id===e.applicationId):null,p=nJe(e.kind==="application"?(l.data?.connections??[]).filter(S=>S.applicationId===e.applicationId):[]),x=u?Zp(u):h?.name??"App",g=sJe(c.data?.apps??[],u,h??void 0),v=u?.id??p?.id??null,y=v?d.data?.apps.find(S=>S.connection.id===v):null,j=(y?.pendingActionRequestCount??0)+((y?.quarantinedCatalogEntryCount??0)>0?1:0);return(0,t.jsxs)("aside",{className:"flex h-full min-h-0 w-full flex-col border-r border-border bg-background",children:[(0,t.jsxs)("div",{className:"flex shrink-0 flex-col gap-3 px-3 py-3",children:[(0,t.jsxs)(Qe,{to:"/apps/connections",onClick:r(()=>{n&&a(!1)},"onClick"),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[(0,t.jsx)(hu,{className:"h-3.5 w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:"All apps"})]}),(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2 px-2 py-1",children:[(0,t.jsx)(bc,{name:x,logoUrl:y1(g),size:28}),(0,t.jsx)("span",{className:"flex-1 truncate text-sm font-bold text-foreground",children:x})]})]}),(0,t.jsx)("nav",{className:"scrollbar-auto-hide min-h-0 flex-1 overflow-y-auto px-3 py-2",children:(0,t.jsx)("div",{className:"flex flex-col gap-0.5",children:I5.map(S=>(0,t.jsx)(Ha,{to:tJe(e,S.key),label:S.label,icon:S.icon,end:!0,badge:S.key==="review"&&j>0?j:void 0,badgeTone:"danger",badgeLabel:"needing review"},S.key))})})]})}r(kJ,"AppDetailSidebar");function tJe(e,s){return e.kind==="connection"?Bu(e.connectionId,s):iS(e.applicationId,s)}r(tJe,"tabHref");function sJe(e,s,n){if(n?.applicationKey){const i=e.find(o=>$c(o)===n.applicationKey);if(i)return i}const a=(s?.name??n?.name)?.toLowerCase();return a?e.find(i=>Gg(i).toLowerCase()===a)??e.find(i=>$c(i)===a)??null:null}r(sJe,"galleryEntryFor$1");function nJe(e){const s=e.filter(n=>n.status==="archived");return s.length===0?null:s.reduce((n,a)=>{const i=new Date(n.updatedAt??n.createdAt??0).getTime();return new Date(a.updatedAt??a.createdAt??0).getTime()>i?a:n})}r(nJe,"latestArchivedConnection$1");function q4({identifier:e}){return e?(0,t.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:e}):null}r(q4,"CrumbIdentifier");function rJe({context:e}){const{slots:s}=Kc({slotTypes:["globalToolbarButton"],companyId:e.companyId}),{launchers:n}=Qz({placementZones:["globalToolbarButton"],companyId:e.companyId,enabled:!!e.companyId});return(0,t.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-1 pl-2 empty:hidden",children:[s.length>0?(0,t.jsx)(zh,{slotTypes:["globalToolbarButton"],context:e,className:"flex items-center gap-1"}):null,n.length>0?(0,t.jsx)(Ww,{placementZones:["globalToolbarButton"],context:e,className:"flex items-center gap-1"}):null]})}r(rJe,"GlobalToolbar");function aJe(){const{breadcrumbs:e,mobileToolbar:s}=$n(),{toggleSidebar:n,isMobile:a}=$a(),{selectedCompanyId:i,selectedCompany:o}=fs(),l=(0,m.useMemo)(()=>({companyId:i??null,companyPrefix:o?.issuePrefix??null}),[i,o?.issuePrefix]),c=(0,t.jsx)(rJe,{context:l});if(a&&s)return(0,t.jsx)("div",{className:"border-b border-border px-2 h-12 shrink-0 flex items-center",children:s});if(e.length===0)return(0,t.jsx)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center justify-end",children:c});const d=a&&(0,t.jsx)(F,{variant:"ghost",size:"icon-sm",className:"mr-2 shrink-0",onClick:n,"aria-label":"Open sidebar",children:(0,t.jsx)(ude,{className:"h-5 w-5"})});return e.length===1?(0,t.jsxs)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center",children:[d,(0,t.jsx)("div",{className:"min-w-0 overflow-hidden flex-1",children:e[0].leading||e[0].identifier?(0,t.jsxs)("h1",{className:"flex items-center gap-1.5 text-sm font-semibold uppercase tracking-wider",children:[e[0].leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:e[0].leading}),(0,t.jsx)(q4,{identifier:e[0].identifier}),(0,t.jsx)("span",{className:"truncate",children:e[0].label})]}):(0,t.jsx)("h1",{className:"text-sm font-semibold uppercase tracking-wider truncate",children:e[0].label})}),c]}):(0,t.jsxs)("div",{className:"border-b border-border px-4 md:px-6 h-12 shrink-0 flex items-center",children:[d,(0,t.jsx)("div",{className:"min-w-0 overflow-hidden flex-1",children:(0,t.jsx)(Zz,{className:"min-w-0 overflow-hidden",children:(0,t.jsx)(eU,{className:"flex-nowrap",children:e.map((u,h)=>{const p=h===e.length-1;return(0,t.jsxs)(m.Fragment,{children:[h>0&&(0,t.jsx)(XR,{}),(0,t.jsx)(oS,{className:p?"min-w-0":"shrink-0",children:p||!u.href?u.leading||u.identifier?(0,t.jsxs)(QS,{className:"flex min-w-0 items-center gap-1.5",children:[u.leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:u.leading}),(0,t.jsx)(q4,{identifier:u.identifier}),(0,t.jsx)("span",{className:"truncate",children:u.label})]}):(0,t.jsx)(QS,{className:"truncate",children:u.label}):(0,t.jsx)(JR,{asChild:!0,children:u.leading||u.identifier?(0,t.jsxs)(Qe,{to:u.href,onClick:u.onClick,className:"flex items-center gap-1.5",children:[u.leading&&(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:u.leading}),(0,t.jsx)(q4,{identifier:u.identifier}),(0,t.jsx)("span",{className:"truncate",children:u.label})]}):(0,t.jsx)(Qe,{to:u.href,onClick:u.onClick,children:u.label})})})]},h)})})})}),c]})}r(aJe,"BreadcrumbBar");var fI=240,$F=208,OF=420,SJ=16;function ET(e){return Math.min(OF,Math.max($F,e))}r(ET,"clampSidebarWidth");function CJ(e){if(typeof window>"u")return fI;try{const s=window.localStorage.getItem(e);if(!s)return fI;const n=Number.parseInt(s,10);return Number.isFinite(n)?ET(n):fI}catch{return fI}}r(CJ,"readStoredSidebarWidth");function _J(e,s){if(!(typeof window>"u"))try{window.localStorage.setItem(e,String(ET(s)))}catch{}}r(_J,"writeStoredSidebarWidth");function iJe({children:e,open:s,collapsed:n=!1,peeking:a=!1,resizable:i=!1,storageKey:o="paperclip.sidebar.width",className:l,onPanelMouseEnter:c,onPanelMouseLeave:d,onPanelFocusCapture:u,onPanelBlurCapture:h}){const[p,x]=(0,m.useState)(()=>CJ(o)),[g,v]=(0,m.useState)(!1),y=(0,m.useRef)(p),j=(0,m.useRef)(null);(0,m.useEffect)(()=>{const T=CJ(o);y.current=T,x(T)},[o]);const S=s?p:0,w=s?n?64:S:0,N=s?n&&!a?64:S:0,_=N>w,I=i&&s&&!n,C=(0,m.useMemo)(()=>({width:`${w}px`}),[w]),A=(0,m.useMemo)(()=>({width:`${N}px`}),[N]),R=(0,m.useCallback)(T=>{const q=ET(T);y.current=q,x(q),_J(o,q)},[o]),E=(0,m.useCallback)(T=>{I&&(T.preventDefault(),T.currentTarget.setPointerCapture(T.pointerId),j.current={startX:T.clientX,startWidth:y.current},v(!0))},[I]),O=(0,m.useCallback)(T=>{if(!j.current)return;const q=ET(j.current.startWidth+T.clientX-j.current.startX);y.current=q,x(q)},[]),L=(0,m.useCallback)(()=>{j.current&&(j.current=null,v(!1),_J(o,y.current))},[o]),$=(0,m.useCallback)(T=>{I&&(T.key==="ArrowLeft"?(T.preventDefault(),R(p-SJ)):T.key==="ArrowRight"?(T.preventDefault(),R(p+SJ)):T.key==="Home"?(T.preventDefault(),R($F)):T.key==="End"&&(T.preventDefault(),R(OF)))},[I,R,p]);return(0,t.jsx)("div",{className:U("relative h-full shrink-0",l),style:C,children:(0,t.jsxs)("div",{className:U("absolute inset-y-0 left-0 flex flex-col overflow-hidden",_?"z-30 border-r border-border bg-background shadow-lg":"z-0"),style:A,"data-sidebar-overlay":_?"":void 0,onMouseEnter:c,onMouseLeave:d,onFocusCapture:u,onBlurCapture:h,children:[e,I?(0,t.jsx)("div",{role:"separator","aria-label":"Resize sidebar","aria-orientation":"vertical","aria-valuemin":$F,"aria-valuemax":OF,"aria-valuenow":p,tabIndex:0,className:U("absolute inset-y-0 right-0 z-20 w-3 cursor-col-resize touch-none outline-none","before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-transparent before:transition-colors","hover:before:bg-border focus-visible:before:bg-ring",g&&"before:bg-ring"),onPointerDown:E,onPointerMove:O,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:L,onKeyDown:$}):null]})})}r(iJe,"SidebarShell");function oJe({children:e,className:s}){return(0,t.jsx)("div",{"data-secondary-sidebar":"",className:U("h-full w-60 shrink-0 overflow-y-auto border-r border-border bg-background",s),children:(0,t.jsx)($Ye,{children:e})})}r(oJe,"SecondarySidebar");var lJe="/company/settings/instance/profile",cJe="https://docs.paperclip.ing/",dJe="https://paperclip.ing/feedback";function uJe(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?`${s[0]?.[0]??""}${s[s.length-1]?.[0]??""}`.toUpperCase():e.slice(0,2).toUpperCase()}r(uJe,"deriveInitials$1");function mJe(e,s,n){const a=[e,s?.split("@")[0],s,n];for(const i of a){const o=i?.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(o)return o}return"me"}r(mJe,"deriveUserSlug");function z4({label:e,description:s,icon:n,onClick:a,href:i,external:o=!1}){const l="flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-accent/60",c=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(n,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:e}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:s})]})]});return i?o?(0,t.jsx)("a",{href:i,target:"_blank",rel:"noreferrer",className:l,onClick:a,children:c}):(0,t.jsx)(Qe,{to:i,className:l,onClick:a,children:c}):(0,t.jsx)("button",{type:"button",className:l,onClick:a,children:c})}r(z4,"MenuAction");function IJ({deploymentMode:e,open:s,onOpenChange:n}){const a=!!Vc(),[i,o]=(0,m.useState)(!1),{isMobile:l,setSidebarOpen:c,collapsed:d,peeking:u}=$a(),h=d&&!u,p=s??i,x=n??o,{data:g}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),v=Hw({onSignedOut:N}),y=g?.user.name?.trim()||"Board",j=g?.user.email?.trim()||(e==="authenticated"?"Signed in":"Local workspace board"),S=uJe(y),w=`/u/${mJe(g?.user.name,g?.user.email,g?.user.id)}`;function N(){x(!1),l&&c(!1)}r(N,"closeNavigationChrome");function _(){v.mutate()}return r(_,"handleSignOut"),(0,t.jsx)("div",{className:"border-t border-r border-border bg-background px-3 py-2",children:(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",!h&&"px-2"),children:[(0,t.jsxs)(sr,{open:p,onOpenChange:x,children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:U("flex min-w-0 items-center gap-2.5 rounded-lg text-left text-(length:--text-compact) font-medium text-foreground/80 transition-colors hover:bg-accent/50 hover:text-foreground",h?"w-full px-3 py-2":"flex-1 px-2 py-1.5"),"aria-label":"Open account menu",children:[(0,t.jsxs)(Yi,{size:"sm",children:[g?.user.image?(0,t.jsx)(zc,{src:g.user.image,alt:y}):null,(0,t.jsx)(Ji,{children:S})]}),(0,t.jsx)("span",{className:U("min-w-0 flex-1 truncate",h&&"block w-0 min-w-0 overflow-hidden whitespace-nowrap text-transparent select-none"),children:y})]})}),(0,t.jsxs)(Gn,{side:"top",align:"start",sideOffset:10,className:"w-(--sz-277px) max-w-(--sz-calc-24) overflow-hidden rounded-t-2xl rounded-b-none border-border p-0 shadow-2xl",children:[(0,t.jsx)("div",{className:"h-24 bg-(image:--gradient-extract-25)"}),(0,t.jsxs)("div",{className:"-mt-8 px-4 pb-4",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"rounded-2xl border-4 border-popover bg-popover p-0.5 shadow-sm",children:(0,t.jsxs)(Yi,{size:"lg",children:[g?.user.image?(0,t.jsx)(zc,{src:g.user.image,alt:y}):null,(0,t.jsx)(Ji,{children:S})]})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 pt-1",children:[(0,t.jsx)("h2",{className:"truncate text-base font-semibold text-foreground",children:y}),(0,t.jsx)("p",{className:"truncate text-sm text-muted-foreground",children:j})]})]}),(0,t.jsxs)("div",{className:"mt-4 space-y-1",children:[(0,t.jsx)(z4,{label:"View profile",description:"Open your activity, task, and usage ledger.",icon:pu,href:w,onClick:N}),(0,t.jsx)(z4,{label:"Edit profile",description:"Update your display name and avatar.",icon:p1,href:lJe,onClick:N}),(0,t.jsx)(z4,{label:"Documentation",description:"Open Paperclip docs in a new tab.",icon:Uw,href:cJe,external:!0,onClick:r(()=>x(!1),"onClick")}),(0,t.jsx)(Cj,{variant:"menu-action",onAfterToggle:r(()=>x(!1),"onAfterToggle")}),e==="authenticated"?(0,t.jsxs)("button",{type:"button",className:U("flex w-full items-start gap-3 rounded-xl px-3 py-3 text-left transition-colors hover:bg-destructive/10",v.isPending&&"cursor-not-allowed opacity-60"),onClick:_,disabled:v.isPending,children:[(0,t.jsx)("span",{className:"mt-0.5 rounded-lg border border-border bg-background/70 p-2 text-muted-foreground",children:(0,t.jsx)(Yh,{className:"size-4"})}),(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium text-foreground",children:v.isPending?"Signing out...":"Sign out"}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:"End this browser session."})]})]}):null,(0,t.jsx)(Cxe,{})]})]})]})]}),!h&&!a?(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("a",{href:dJe,target:"_blank",rel:"noreferrer","aria-label":"Share feedback",className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground/50 transition-colors hover:bg-accent/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:(0,t.jsx)(_x,{className:"h-4 w-4","aria-hidden":"true"})})}),(0,t.jsx)(Kn,{side:"top",children:"Share feedback"})]}):null]})})}r(IJ,"SidebarAccountMenu");function hJe(e,s){return qxe(e,s)[0]?.toLowerCase()??null}r(hJe,"getCompanyRouteSegment");function qxe(e,s){if(!s)return[];const n=e.split("/").filter(Boolean);return n.length<2?[]:n[0]?.toUpperCase()!==s.toUpperCase()?[]:n.slice(1)}r(qxe,"getCompanyPathSegments");var pJe=new Set(["browse","connections","connect","chat","review","attention","gateways","advanced","app"]);function fJe(e,s){const n=e.split("/").filter(Boolean);return n[0]?.toLowerCase()==="skills"?!0:s?n[0]?.toUpperCase()===s.toUpperCase()&&n[1]?.toLowerCase()==="skills":!1}r(fJe,"isSkillsStoreRoute");function xJe(){const{sidebarOpen:e,setSidebarOpen:s,toggleSidebar:n,collapsed:a,peeking:i,setPeeking:o,isMobile:l,setForceCollapsed:c}=$a(),{openNewIssue:d,openOnboarding:u}=Lo(),{togglePanelVisible:h}=uf(),p=Nc()?.pushToast??null,{companies:x,loading:g,selectedCompany:v,selectedCompanyId:y,selectionSource:j,setSelectedCompanyId:S}=fs(),{companyPrefix:w,pluginRoutePath:N}=ja(),_=Wn(),I=Zr(),C=J3(),A=["/company/settings","/company/export","/company/import"].some(rt=>I.pathname.includes(rt)),R=qxe(I.pathname,w),E=R[0]?.toLowerCase()==="tools",O=R[0]?.toLowerCase()==="apps",L=O&&R[1]&&!pJe.has(R[1].toLowerCase())?R[1]:null,$=O&&R[1]?.toLowerCase()==="app"&&R[2]?R[2]:null,T=fJe(I.pathname,w),q=(0,m.useRef)(!1),B=(0,m.useRef)(0),K=(0,m.useRef)(null),z=(0,m.useRef)(null),D=(0,m.useRef)(new Ode),V=(0,m.useRef)(I.key),[H,Z]=(0,m.useState)(!0),[Y,ie]=(0,m.useState)(!1),se=(0,m.useMemo)(()=>{if(!w)return null;const rt=w.toUpperCase();return x.find(jt=>jt.issuePrefix.toUpperCase()===rt)??null},[x,w]),X=!!w&&!g&&x.length>0&&!se,le=(0,m.useMemo)(()=>N?.toLowerCase()??hJe(I.pathname,w),[w,I.pathname,N]),oe=se?.id??null,te=se?.issuePrefix??null,{slots:J}=Kc({slotTypes:["page","routeSidebar"],companyId:oe,enabled:!!(oe&&le)}),Q=(0,m.useMemo)(()=>Fz(J,le),[le,J]),pe=(0,m.useMemo)(()=>({companyId:oe,companyPrefix:te}),[oe,te]),re=A?(0,t.jsx)(ZYe,{}):L?(0,t.jsx)(kJ,{kind:"connection",connectionId:L}):$?(0,t.jsx)(kJ,{kind:"application",applicationId:$}):O||E?(0,t.jsx)(eJe,{}):Q?(0,t.jsx)(fu,{slot:Q,context:pe,className:"h-full w-full",missingBehavior:"placeholder"}):null,ne=re!=null,{data:ae}=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1,refetchInterval:r(rt=>rt.state.data?.devServer?.enabled?2e3:!1,"refetchInterval"),refetchIntervalInBackground:!1}),me=ee({queryKey:P.instance.generalSettings,queryFn:r(()=>Tr.getGeneral(),"queryFn")}).data?.keyboardShortcuts===!0,he=ne||T;(0,m.useLayoutEffect)(()=>(c(he),()=>c(!1)),[he,c]),(0,m.useEffect)(()=>{g||q.current||ae?.deploymentMode!=="authenticated"&&(ae?.cloud||x.length===0&&(q.current=!0,u()))},[x,g,u,ae?.cloud,ae?.deploymentMode]),(0,m.useEffect)(()=>{if(!w||g||x.length===0)return;if(!se){const jt=(y?x.find(st=>st.id===y):null)??x[0]??null;jt&&y!==jt.id&&S(jt.id,{source:"route_sync"});return}if(w!==se.issuePrefix){const jt=I.pathname.replace(/^\/[^/]+/,"");_(`/${se.issuePrefix}${jt}${I.search}`,{replace:!0});return}const rt=Exe({matchedCompany:se,selectedCompanyId:y,companies:x});if(rt){p?.({title:`${se.name} is archived`,body:`Switched to ${rt.name}.`,tone:"info",dedupeKey:`archived-company-bounce:${se.id}`}),S(rt.id,{source:"route_sync"}),_(`/${rt.issuePrefix}/dashboard`,{replace:!0});return}Pxe({selectionSource:j,selectedCompanyId:y,routeCompanyId:se.id})&&S(se.id,{source:"route_sync"})},[w,x,g,se,I.pathname,I.search,_,p,j,y,S]);const Ie=h,de=(0,m.useCallback)(()=>{document.dispatchEvent(new KeyboardEvent("keydown",{key:"k",metaKey:!0,bubbles:!0,cancelable:!0}))},[]),ve=(0,m.useRef)(null),Te=(0,m.useRef)(!1),fe=(0,m.useRef)(!1),Ce=(0,m.useCallback)(()=>{ve.current!==null&&(window.clearTimeout(ve.current),ve.current=null)},[]),Xe=(0,m.useCallback)(()=>{Ce(),ve.current=window.setTimeout(()=>o(!0),50)},[Ce,o]),Oe=(0,m.useCallback)(()=>{Ce(),o(!0)},[Ce,o]),tt=(0,m.useCallback)(()=>{Ce(),ve.current=window.setTimeout(()=>o(!1),120)},[Ce,o]),ce=(0,m.useCallback)(()=>{Te.current=!0,a&&!fe.current&&Xe()},[a,Xe]),$e=(0,m.useCallback)(()=>{Te.current=!1,fe.current=!1,tt()},[tt]),mt=(0,m.useCallback)(()=>{fe.current||Oe()},[Oe]),it=(0,m.useCallback)(()=>{Te.current||tt()},[tt]);(0,m.useEffect)(()=>Ce,[Ce]);const Ke=(0,m.useRef)(a);(0,m.useEffect)(()=>{a!==Ke.current&&(a?(Ce(),o(!1),fe.current=Te.current):fe.current=!1,Ke.current=a)},[a,Ce,o]),(0,m.useEffect)(()=>{if(!i)return;const rt=r(jt=>{jt.key==="Escape"&&(Ce(),o(!1))},"onKeyDown");return window.addEventListener("keydown",rt),()=>window.removeEventListener("keydown",rt)},[i,Ce,o]),Txe(),_xe({enabled:me,onNewIssue:r(()=>d(),"onNewIssue"),onSearch:de,onToggleSidebar:n,onTogglePanel:Ie,onShowShortcuts:r(()=>ie(!0),"onShowShortcuts"),onGoToInbox:r(()=>_("/inbox"),"onGoToInbox")}),(0,m.useEffect)(()=>{if(!l){Z(!0);return}B.current=0,Z(!0)},[l]),(0,m.useEffect)(()=>{if(!l)return;const rt=30,jt=50,st=75;let Nt=0,at=0;const Ee=r(He=>{const St=He.touches[0];Nt=St.clientX,at=St.clientY},"onTouchStart"),Ne=r(He=>{const St=He.changedTouches[0],Ft=St.clientX-Nt;if(!(Math.abs(St.clientY-at)>st)){if(!e&&Nt<rt&&Ft>jt){s(!0);return}e&&Ft<-50&&s(!1)}},"onTouchEnd");return document.addEventListener("touchstart",Ee,{passive:!0}),document.addEventListener("touchend",Ne,{passive:!0}),()=>{document.removeEventListener("touchstart",Ee),document.removeEventListener("touchend",Ne)}},[l,e,s]);const Ge=(0,m.useCallback)(rt=>{const jt=rt-B.current;rt<=24?Z(!0):jt>8?Z(!1):jt<-8&&Z(!0),B.current=rt},[]);return(0,m.useEffect)(()=>{if(!l){Z(!0),B.current=0;return}const rt=r(()=>{Ge(window.scrollY||document.documentElement.scrollTop||0)},"onScroll");return rt(),window.addEventListener("scroll",rt,{passive:!0}),()=>{window.removeEventListener("scroll",rt)}},[l,Ge]),(0,m.useEffect)(()=>{const rt=document.body.style.overflow;return document.body.style.overflow=l?"visible":"clip",()=>{document.body.style.overflow=rt}},[l]),(0,m.useEffect)(()=>{if(!l)return Dxe()},[l]),(0,m.useEffect)(()=>{if(typeof document>"u")return;const rt=z.current;return Mxe(rt)},[I.pathname]),(0,m.useEffect)(()=>{const rt=z.current;if(!rt)return;const jt=r(()=>{D.current.remember(V.current,rt.scrollTop)},"recordScroll");return rt.addEventListener("scroll",jt,{passive:!0}),()=>rt.removeEventListener("scroll",jt)},[]),(0,m.useLayoutEffect)(()=>{const rt=z.current,jt=$de({previousPathname:K.current,pathname:I.pathname,navigationType:C,state:I.state});K.current=I.pathname;const st=C==="POP",Nt=st?D.current.recall(I.key):0;if(V.current=I.key,st){UR(rt,Nt);const at=requestAnimationFrame(()=>UR(rt,Nt));return()=>cancelAnimationFrame(at)}jt&&Fde(rt)},[I.key,I.pathname,I.state,C]),(0,t.jsx)(Lde,{children:(0,t.jsx)(Wle,{value:{keyboardShortcutsEnabled:me},children:(0,t.jsxs)("div",{className:U("bg-background text-foreground pt-(--sz-safe-top)",l?"min-h-dvh overflow-x-clip":"flex h-dvh flex-col overflow-clip"),children:[(0,t.jsx)("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-(--z-200) focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Skip to Main Content"}),(0,t.jsx)(jxe,{}),(0,t.jsx)(wxe,{devServer:ae?.devServer}),(0,t.jsxs)("div",{className:U("min-h-0 flex-1",l?"w-full":"flex overflow-clip"),children:[l&&e&&(0,t.jsx)("button",{type:"button",className:"fixed inset-0 z-40 bg-black/50",onClick:r(()=>s(!1),"onClick"),"aria-label":"Close sidebar"}),l?(0,t.jsxs)("div",{className:U("fixed inset-y-0 left-0 z-50 flex flex-col overflow-hidden pt-(--sz-safe-top) transition-transform duration-100 ease-out",e?"translate-x-0":"-translate-x-full"),children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:(0,t.jsx)("div",{className:"w-60 shrink-0 overflow-hidden",children:ne?re:(0,t.jsx)(NJ,{})})}),(0,t.jsx)(IJ,{deploymentMode:ae?.deploymentMode})]}):(0,t.jsxs)(iJe,{open:e,collapsed:a,peeking:i,resizable:!0,onPanelMouseEnter:ce,onPanelMouseLeave:$e,onPanelFocusCapture:a?mt:void 0,onPanelBlurCapture:a?it:void 0,children:[(0,t.jsx)("div",{className:"flex flex-1 min-h-0",children:(0,t.jsx)(NJ,{})}),(0,t.jsx)(IJ,{deploymentMode:ae?.deploymentMode})]}),!l&&ne?(0,t.jsx)(oJe,{children:re}):null,(0,t.jsxs)("div",{className:U("flex min-w-0 flex-col",l?"w-full":"h-full flex-1"),children:[(0,t.jsxs)("div",{className:U(l&&"sticky top-0 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85"),children:[(0,t.jsx)(MF,{mobile:l}),(0,t.jsx)(aJe,{}),l&&A?(0,t.jsx)("div",{className:"border-b border-border px-4 pb-3",children:(0,t.jsx)(ime,{})}):null]}),(0,t.jsxs)("div",{className:U(l?"block":"flex flex-1 min-h-0"),children:[(0,t.jsx)("main",{id:"main-content",ref:z,tabIndex:-1,style:l?{"--tc-composer-bottom":H?"var(--sz-calc-14)":"var(--sz-calc-8)"}:void 0,className:U("flex-1 p-4 outline-none md:p-6",l?"overflow-visible pb-(--sz-calc-14)":"overflow-auto [scrollbar-gutter:stable]"),children:X?(0,t.jsx)(uu,{scope:"invalid_company_prefix",requestedPrefix:w??v?.issuePrefix}):(0,t.jsx)(Sxe,{children:(0,t.jsx)(n0,{})})}),(0,t.jsx)(bme,{})]})]})]}),l&&(0,t.jsx)(yxe,{visible:H}),(0,t.jsx)(jme,{}),(0,t.jsx)(Eme,{}),(0,t.jsx)(mxe,{}),(0,t.jsx)(fxe,{}),(0,t.jsx)(xxe,{}),(0,t.jsx)(gxe,{open:Y,onOpenChange:ie}),(0,t.jsx)(bxe,{}),(0,t.jsx)(vxe,{localTrusted:ae?.deploymentMode==="local_trusted"})]})})})}r(xJe,"Layout");var AJ=null;function gJe(){return AJ??=new JC,AJ}r(gJe,"getDetachedClient");function bJe(){const e=(0,m.useContext)(H3),{data:s,isFetched:n}=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn"),enabled:e!=null},e??gJe());return e?{enabled:s?.enableConferenceRoomChat===!0,loaded:n}:{enabled:!1,loaded:!0}}r(bJe,"useConferenceRoomChatEnabled");function vJe(){const{enabled:e,loaded:s}=bJe();return s?e?(0,t.jsx)(n0,{}):(0,t.jsx)(vn,{to:"/dashboard",replace:!0}):null}r(vJe,"ConferenceRoomChatGate");var yJe=["session-start","human-message","agent-message","thinking","responding","responding-burst","tool-call","diff","working","running","completed","activity-phases","awaiting-approval","plan-todo","interrupted","refused","truncated","live-token-cost"],jJe={"session-start":{id:"session-start",label:"Session start",tier:"live",surface:"thread",protocol:'acpx.session → TranscriptEntry kind:"init"'},"human-message":{id:"human-message",label:"Human message",tier:"live",surface:"thread",protocol:'IssueComment authorType:"user"'},"agent-message":{id:"agent-message",label:"Final response",tier:"live",surface:"thread",protocol:'PRP item.delta kind:"agentMessage" channel:"final"'},thinking:{id:"thinking",label:"Thinking",tier:"live",surface:"thread",protocol:"text_delta stream:thought (ACP agent_thought_chunk)"},responding:{id:"responding",label:"Progress update (streaming)",tier:"live",surface:"thread",protocol:'PRP item.delta kind:"agentMessage" channel:"progress"'},"responding-burst":{id:"responding-burst",label:"Progress update burst",tier:"live",surface:"thread",protocol:"text_delta stream:output ×N, tool calls between (PAP-368 dwell)"},"tool-call":{id:"tool-call",label:"Tool call",tier:"live",surface:"thread",protocol:"acpx.tool_call (ACP tool_call / tool_call_update)"},diff:{id:"diff",label:"Diff",tier:"live",surface:"thread",protocol:'ToolCallContent type:"diff" → TranscriptEntry kind:"diff"'},working:{id:"working",label:"Working",tier:"live",surface:"thread",protocol:"heartbeat.run.progress + acpx.status"},running:{id:"running",label:"Running",tier:"live",surface:"thread",protocol:'message.status.type === "running"'},completed:{id:"completed",label:"Completed (collapsed)",tier:"live",surface:"thread",protocol:"acpx.result (StopReason in subtype)"},"activity-phases":{id:"activity-phases",label:"Long-run activity phases",tier:"live",surface:"thread",protocol:"assistant boundaries + chronological tool calls"},"awaiting-approval":{id:"awaiting-approval",label:"Awaiting approval",tier:"tier-b",surface:"thread",protocol:"ACP RequestPermissionRequest + PermissionOptionKind"},"plan-todo":{id:"plan-todo",label:"Plan / todo",tier:"tier-b",surface:"plan",protocol:"ACP Plan { entries: PlanEntry[] }, PlanEntryStatus"},interrupted:{id:"interrupted",label:"Interrupted",tier:"tier-b",surface:"thread",protocol:'AcpRuntimeTurnResult.status:"cancelled" / StopReason "cancelled"'},refused:{id:"refused",label:"Refused",tier:"tier-b",surface:"thread",protocol:'StopReason "refusal"'},truncated:{id:"truncated",label:"Truncated",tier:"tier-b",surface:"thread",protocol:'StopReason "max_tokens" | "max_turn_requests"'},"live-token-cost":{id:"live-token-cost",label:"Live token / cost",tier:"tier-b",surface:"thread",protocol:"ACP UsageUpdate { used, size, cost }"}},b8t=yJe.map(e=>jJe[e]);function zxe({item:e}){return(0,t.jsx)("article",{className:"rounded-lg border border-border bg-card p-3","aria-label":`Project created: ${e.name}`,children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(C3e,{className:"mt-0.5 size-4 shrink-0 text-muted-foreground","aria-hidden":!0}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Project created"}),(0,t.jsx)(Qe,{to:`/projects/${e.projectId}`,className:"break-words text-sm font-medium hover:underline focus-visible:underline",children:e.name}),e.description&&(0,t.jsx)("p",{className:"line-clamp-3 text-sm text-muted-foreground",children:e.description}),e.repositories.length>0&&(0,t.jsx)("ul",{className:"space-y-1 pt-1",children:e.repositories.map(s=>(0,t.jsxs)("li",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[(0,t.jsx)(sl,{className:"size-3 shrink-0","aria-hidden":!0}),(0,t.jsx)("a",{className:"truncate hover:underline focus-visible:underline",href:s.url,target:"_blank",rel:"noreferrer",children:s.name})]},s.id))})]})]})})}r(zxe,"TaskChatProjectCreatedCard");function wJe({item:e,onOpen:s}){return(0,t.jsx)("article",{className:"rounded-lg border border-border bg-card p-3","aria-label":`Skill created: ${e.name}`,children:(0,t.jsxs)("button",{type:"button",className:"flex w-full items-start gap-3 text-left",onClick:r(()=>s?.(e.skillId,e.name),"onClick"),children:[(0,t.jsx)(fx,{className:"mt-0.5 size-4 shrink-0 text-muted-foreground","aria-hidden":!0}),(0,t.jsxs)("span",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:"Skill created"}),(0,t.jsx)("span",{className:"block break-words text-sm font-medium hover:underline focus-visible:underline",children:e.name}),e.description?(0,t.jsx)("span",{className:"block line-clamp-3 text-sm text-muted-foreground",children:e.description}):null]})]})})}r(wJe,"TaskChatSkillCreatedCard");var Uxe=(0,m.createContext)("streamlined");function NJe({mode:e,children:s}){return(0,t.jsx)(Uxe.Provider,{value:e,children:s})}r(NJe,"TaskChatPresentationProvider");function Xh(){return(0,m.useContext)(Uxe)==="streamlined"}r(Xh,"useStreamlinedTaskChatPresentation");function kJe(e){return(0,t.jsxs)("svg",{viewBox:"0 0 180 180",fill:"none",stroke:"currentColor",strokeWidth:14,strokeLinecap:"round",xmlns:"http://www.w3.org/2000/svg",...e,children:[(0,t.jsx)("path",{d:"M18 84.8528L85.8822 16.9706C95.2548 7.59798 110.451 7.59798 119.823 16.9706C129.196 26.3431 129.196 41.5391 119.823 50.9117L68.5581 102.177"}),(0,t.jsx)("path",{d:"M69.2652 101.47L119.823 50.9117C129.196 41.5391 144.392 41.5391 153.765 50.9117L154.118 51.2652C163.491 60.6378 163.491 75.8338 154.118 85.2063L92.7248 146.6C89.6006 149.724 89.6006 154.789 92.7248 157.913L105.331 170.52"}),(0,t.jsx)("path",{d:"M102.853 33.9411L52.6482 84.1457C43.2756 93.5183 43.2756 108.714 52.6482 118.087C62.0208 127.459 77.2167 127.459 86.5893 118.087L136.794 67.8822"})]})}r(kJe,"McpIcon");var SJe=new Set(["tool","tool call","tool_call","acp_tool"]);function _d(e){const s=(e??"").trim().toLowerCase().replace(/\s*\((?:pending|in[_ -]?progress|completed|failed|cancelled|canceled)\)$/,"");return!s||SJe.has(s)}r(_d,"isGenericToolName");function cK(e){const s=e.match(/^mcp__(.+?)__(.+)$/i);if(s)return{namespace:s[1],name:s[2]};const n=e.match(/^mcp\.([^.]+)\.(.+)$/i);return n?{namespace:n[1],name:n[2]}:null}r(cK,"mcpToolIdentity");function dK(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().toLowerCase().split(/\s+/).filter(Boolean)}r(dK,"identifierWords");function Kxe(e){if(e.length===0)return"";const s=e.map(n=>["api","id","lsp","mcp","pr","url"].includes(n)?n.toUpperCase():n).join(" ");return s.charAt(0).toUpperCase()+s.slice(1)}r(Kxe,"sentenceCase");function _j(e){const s=(e??"").trim();return _d(s)?"Unnamed tool":Kxe(dK(cK(s)?.name??s))}r(_j,"humanizeToolName");var td=r((e,s,n)=>({key:e,singular:s,plural:n}),"group"),CJe={bash:{action:"run"},terminal:{action:"run"},shell:{action:"run"},command:{action:"run"},run:{action:"run"},execute:{action:"run"},exec_command:{action:"run"},apply_patch:{action:"update",running:"Applying a patch",completed:"Applied a patch"},read:{action:"read",running:"Reading a file",completed:"Read a file"},write:{action:"update",running:"Writing a file",completed:"Wrote a file"},edit:{action:"update",running:"Editing a file",completed:"Edited a file"},notebook_read:{action:"read",running:"Reading a notebook",completed:"Read a notebook"},notebook_edit:{action:"update",running:"Editing a notebook",completed:"Edited a notebook"},glob:{action:"search",running:"Searching files",completed:"Searched files"},grep:{action:"search",running:"Searching file contents",completed:"Searched file contents",family:"grep"},tool_search:{action:"search",running:"Searching available tools",completed:"Searched available tools",group:td("tool_search","tool search","tool searches")},web_search:{action:"search",running:"Searching the web",completed:"Searched the web",family:"web"},web_fetch:{action:"fetch",running:"Fetching a web page",completed:"Fetched a web page",family:"web"},todo_write:{action:"update",running:"Updating the task list",completed:"Updated the task list",family:"plan",group:td("task_operation","task operation","task operations")},task_create:{action:"create",running:"Creating a task",completed:"Created a task",family:"plan",group:td("task_operation","task operation","task operations")},task_update:{action:"update",running:"Updating a task",completed:"Updated a task",family:"plan",group:td("task_operation","task operation","task operations")},task_list:{action:"list",running:"Listing tasks",completed:"Listed tasks",family:"plan",group:td("task_operation","task operation","task operations")},task_get:{action:"read",running:"Reading a task",completed:"Read a task",family:"plan",group:td("task_operation","task operation","task operations")},enter_plan_mode:{action:"switch",running:"Entering plan mode",completed:"Entered plan mode",family:"plan"},exit_plan_mode:{action:"switch",running:"Leaving plan mode",completed:"Left plan mode",family:"plan"},skill:{action:"read",running:"Loading a skill",completed:"Loaded a skill"},ask_user_question:{action:"request",running:"Requesting input",completed:"Requested input",family:"question"},request_human_input:{action:"request",running:"Requesting input",completed:"Requested input",family:"question",group:td("task_operation","task operation","task operations")},agent:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},task:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},task_output:{action:"read",running:"Checking subagent progress",completed:"Checked subagent progress",family:"agent"},task_stop:{action:"stop",running:"Stopping a subagent",completed:"Stopped a subagent",family:"agent"},send_message:{action:"post",running:"Messaging a subagent",completed:"Messaged a subagent",family:"agent"},spawn_agent:{action:"start",running:"Starting a subagent",completed:"Started a subagent",family:"agent"},wait_agent:{action:"wait",running:"Checking subagent progress",completed:"Checked subagent progress",family:"agent"},wait_threads:{action:"wait",running:"Checking task progress",completed:"Checked task progress",family:"agent"},interrupt_agent:{action:"stop",running:"Interrupting a subagent",completed:"Interrupted a subagent",family:"agent"},report_findings:{action:"post",running:"Reporting findings",completed:"Reported findings",family:"safety"},guardian_review:{action:"think",running:"Reviewing safety",completed:"Reviewed safety",family:"safety"},lsp:{action:"read",running:"Inspecting code intelligence",completed:"Inspected code intelligence"},compact_conversation:{action:"think",running:"Compacting context",completed:"Compacted context"},image_generation:{action:"create",running:"Generating an image",completed:"Generated an image",family:"image"},view_image:{action:"read",running:"Viewing an image",completed:"Viewed an image",family:"image"},multi_tool_use_parallel:{action:"run",running:"Running tools in parallel",completed:"Ran tools in parallel"},get_task_context:{action:"read",running:"Reading task context",completed:"Read task context"},get_task_history:{action:"read",running:"Reading task history",completed:"Read task history"},list_documents:{action:"list",running:"Listing documents",completed:"Listed documents"},read_document:{action:"read",running:"Reading a document",completed:"Read a document"},list_document_revisions:{action:"list",running:"Listing document revisions",completed:"Listed document revisions"},report_progress:{action:"post",running:"Reporting progress",completed:"Reported progress"},answer_status_question:{action:"post",running:"Answering a status question",completed:"Answered a status question"},write_document:{action:"update",running:"Writing a document",completed:"Wrote a document"},register_deliverable:{action:"create",running:"Registering a deliverable",completed:"Registered a deliverable"},finish_task:{action:"finish",running:"Reporting completion",completed:"Reported completion"},paperclip_finish:{action:"finish",running:"Reporting completion",completed:"Reported completion"},block_task:{action:"block",running:"Reporting a blocker",completed:"Reported a blocker"},paperclip_block:{action:"block",running:"Reporting a blocker",completed:"Reported a blocker"},request_review:{action:"request",running:"Requesting review",completed:"Requested review"},list_agents:{action:"list",running:"Listing agents",completed:"Listed agents"},get_agent:{action:"read",running:"Reading agent details",completed:"Read agent details"},search_tasks:{action:"search",running:"Searching tasks",completed:"Searched tasks"},list_approvals:{action:"list",running:"Listing approvals",completed:"Listed approvals"},get_approval:{action:"read",running:"Reading an approval",completed:"Read an approval"},get_approval_context:{action:"read",running:"Reading approval context",completed:"Read approval context"},get_workspace_runtime:{action:"read",running:"Reading workspace status",completed:"Read workspace status"},control_workspace_service:{action:"run",running:"Controlling a workspace service",completed:"Controlled a workspace service"},set_dependencies:{action:"update",running:"Updating task dependencies",completed:"Updated task dependencies"},create_task:{action:"create",running:"Creating a task",completed:"Created a task"},request_approval:{action:"request",running:"Requesting approval",completed:"Requested approval"},decide_approval:{action:"update",running:"Deciding an approval",completed:"Decided an approval"},comment_on_approval:{action:"post",running:"Commenting on an approval",completed:"Commented on an approval"},schedule_wake:{action:"create",running:"Scheduling a wake-up",completed:"Scheduled a wake-up",family:"wait"},generic_api_request:{action:"request",running:"Calling the Paperclip API",completed:"Called the Paperclip API"}},_Je={read:["get","read","inspect","view"],list:["list","glob"],search:["find","search","grep","query","lookup"],fetch:["fetch","browse"],open:["open"],update:["write","edit","update","set","patch","upsert","sync"],create:["create","add","register","upload"],delete:["delete","remove"],move:["move","rename"],run:["run","execute","bash","shell","command"],request:["request","ask","prompt"],post:["send","message","comment","report","answer"],start:["start","spawn","delegate"],stop:["stop","cancel","interrupt"],wait:["wait","sleep","poll"],finish:["finish","complete"],block:["block"],think:["think","reason","compact","review"],switch:["switch","enter","exit"],other:[]},IJe={read:"read",edit:"update",delete:"delete",move:"move",search:"search",list:"list",execute:"run",think:"think",fetch:"fetch",switch_mode:"switch"};function AJe(e){return dK(e).join("_")}r(AJe,"normalizedKey");function RJe(e){const s=e[0];if(!s)return null;for(const[n,a]of Object.entries(_Je))if(a.includes(s))return n;return null}r(RJe,"inferredAction");function TJe(e){return e==="run"?"terminal":e==="read"||e==="list"?"read":e==="search"?"search":e==="fetch"||e==="open"?"web":["update","create","delete","move"].includes(e)?"edit":e==="request"?"question":e==="start"||e==="stop"?"agent":e==="wait"?"wait":"other"}r(TJe,"actionFamily");var EJe={terminal:zb,grep:nEe,search:pa,read:Uw,edit:m5,web:ATe,plan:m1,question:Rd,agent:Kb,safety:Ai,image:lde,wait:Xm,mcp:kJe,other:fx};function PJe(e,s){const n=s?` ${s}`:"";switch(e){case"read":return{running:`Reading${n||" data"}`,completed:`Read${n||" data"}`};case"list":return{running:`Listing${n||" items"}`,completed:`Listed${n||" items"}`};case"search":return{running:`Searching${n||""}`,completed:`Searched${n||""}`};case"fetch":return{running:`Fetching${n||" data"}`,completed:`Fetched${n||" data"}`};case"open":return{running:`Opening${n||" an item"}`,completed:`Opened${n||" an item"}`};case"update":return{running:`Updating${n||" data"}`,completed:`Updated${n||" data"}`};case"create":return{running:`Creating${n||" an item"}`,completed:`Created${n||" an item"}`};case"delete":return{running:`Deleting${n||" an item"}`,completed:`Deleted${n||" an item"}`};case"move":return{running:`Moving${n||" an item"}`,completed:`Moved${n||" an item"}`};case"run":return{running:"Running a command",completed:"Ran a command"};case"request":return{running:`Requesting${n||" input"}`,completed:`Requested${n||" input"}`};case"post":return{running:`Posting${n||" an update"}`,completed:`Posted${n||" an update"}`};case"start":return{running:`Starting${n||" an operation"}`,completed:`Started${n||" an operation"}`};case"stop":return{running:`Stopping${n||" an operation"}`,completed:`Stopped${n||" an operation"}`};case"wait":return{running:"Waiting",completed:"Finished waiting"};case"finish":return{running:"Reporting completion",completed:"Reported completion"};case"block":return{running:"Reporting a blocker",completed:"Reported a blocker"};case"think":return{running:"Thinking",completed:"Finished thinking"};case"switch":return{running:`Switching${n||" mode"}`,completed:`Switched${n||" mode"}`};case"other":return{running:"Running",completed:"Ran"}}}r(PJe,"actionCopy");function MJe(e){switch(e){case"run":return td("command","command","commands");case"read":case"list":return td("read","read","reads");case"search":return td("search","search","searches");case"update":case"create":case"delete":case"move":return td("file_change","file change","file changes");case"start":case"stop":return td("delegation","delegation","delegations");case"wait":return td("wait","wait","waits");default:return td("tool_action","tool action","tool actions")}}r(MJe,"defaultSummaryGroup");function DJe(e){return e==="read"||e==="list"?td("paperclip_read","Paperclip read","Paperclip reads"):td("task_operation","task operation","task operations")}r(DJe,"paperclipSummaryGroup");function ev(e){const s=(e.name??"").trim(),n=cK(s),a=(e.namespace??n?.namespace??"").trim(),i=(n?"mcp":e.transport??"builtin").toLowerCase(),o=(n?.name??s).trim(),l=dK(o),c=AJe(o),d=CJe[c],u=IJe[(e.operation??"").trim().toLowerCase()],h=RJe(l),p=d?.action??u??h??"other",x=d?"exact":u?"kind":h?"inferred":_d(o)?"unnamed":"fallback",g=_d(o)?"Unnamed tool":_j(o),v=/^[A-Za-z][A-Za-z0-9_.:-]*$/.test(o),y=h&&v&&l.length>1?l.slice(1):[],j=y.length?Kxe(y).replace(/^./,C=>C.toLowerCase()):void 0,S=d?.running&&d.completed?{running:d.running,completed:d.completed}:p==="other"?_d(o)?{running:"Running an unnamed tool",completed:"Ran an unnamed tool"}:{running:`Running ${g}`,completed:`Ran ${g}`}:PJe(p,d?void 0:j),w=d?.family??TJe(p),N=i==="mcp"?"mcp":w,_=a?_j(a):i==="mcp"?"MCP":void 0,I=a.toLowerCase()==="paperclip"?DJe(p):d?.group??MJe(p);return{icon:EJe[N],family:N,runningLabel:S.running,completedLabel:S.completed,failedLabel:`${S.completed} · failed`,interruptedLabel:`${S.running} · stopped`,displayName:g,sourceLabel:_,technicalName:s||void 0,confidence:x,summaryGroup:I}}r(ev,"toolActivityPresentation");function eE(e){const s=ev({name:e});return{family:s.family,icon:s.icon,verbLabel:s.runningLabel}}r(eE,"toolTaxonomy");function LJe(e){const s=(e??"").trim().toLowerCase();return s==="thinking"?Tg:s==="responding"||s.startsWith("responding (")?x5e:null}r(LJe,"statusLabelIcon");var U4=["Clipping","Organizing","Sorting","Synthesizing","Analyzing","Filing","Collating","Stapling","Indexing","Annotating","Drafting","Proofreading","Alphabetizing","Photocopying","Laminating","Hole-punching","Bookmarking","Highlighting","Typing","Trimming","Aligning","Combining","Whiteboarding","Diagramming","Sketching","Labeling","Sticky-noting"],K4=["Brewing","Tinkering","Distilling","Deliberating"],RJ=(()=>{const e=[],s=Math.max(U4.length,K4.length);for(let n=0;n<s;n++)n<U4.length&&e.push(U4[n]),n<K4.length&&e.push(K4[n]);return e})(),$Je=1e4;function OJe(e){const s=(e??"").trim().toLowerCase();return s==="running"||s==="working"}r(OJe,"isGenericStatusLabel");function FJe(e){let s=2166136261;for(let n=0;n<e.length;n++)s^=e.charCodeAt(n),s=Math.imul(s,16777619);return s>>>0}r(FJe,"fnv1a");function BJe(e,s=0){const n=Math.floor(Math.max(0,s)/$Je);return RJ[(FJe(e)+n)%RJ.length]}r(BJe,"whimsyWord");var qJe=[{name:"--motion-ease-out-expo",group:"Easing",kind:"easing"},{name:"--motion-ease-standard",group:"Easing",kind:"easing"},{name:"--motion-ease-out",group:"Easing",kind:"easing"},{name:"--motion-ease-scroll-pill-in",group:"Easing",kind:"easing"},{name:"--motion-ease-scroll-pill-out",group:"Easing",kind:"easing"},{name:"--motion-ease-in",group:"Easing",kind:"easing"},{name:"--motion-duration-instant",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-fast",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-base",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-slow",group:"Durations",kind:"time",min:0,max:1500,step:10},{name:"--motion-duration-deliberate",group:"Durations",kind:"time",min:0,max:2e3,step:10},{name:"--motion-duration-enter",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-exit",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-duration-swap",group:"Durations",kind:"time",min:0,max:1e3,step:10},{name:"--motion-marker-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-bubble-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-cot-line-stagger",group:"States",kind:"time",min:0,max:300,step:5},{name:"--motion-cot-collapse",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-tool-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-diff-reveal",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-status-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-status-exit",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-approval-pulse",group:"States",kind:"time",min:0,max:3e3,step:20},{name:"--motion-plan-entry-stagger",group:"States",kind:"time",min:0,max:300,step:5},{name:"--motion-plan-check",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-question-page-enter",group:"States",kind:"time",min:0,max:1e3,step:10},{name:"--motion-count-tween",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-streaming-cursor-blink",group:"States",kind:"time",min:0,max:3e3,step:20},{name:"--motion-turn-fold",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-turn-meta",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-line-scroll",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-interstitial-dwell",group:"States",kind:"time",min:0,max:1e4,step:100},{name:"--motion-scroll-pill-enter",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-scroll-pill-exit",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-scrollbar-idle-delay",group:"States",kind:"time",min:0,max:2e3,step:10},{name:"--motion-pane-glide",group:"States",kind:"time",min:0,max:1500,step:10},{name:"--motion-side-panel-tab",group:"States",kind:"time",min:0,max:1500,step:10}],v8t=Array.from(new Set(qJe.map(e=>e.group)));function Vxe(e){const s=e.trim();if(s.endsWith("ms"))return parseFloat(s);if(s.endsWith("s"))return parseFloat(s)*1e3;const n=parseFloat(s);return Number.isFinite(n)?n:0}r(Vxe,"parseCssTimeMs");function zJe(e){if(e==null)return null;const s=Math.round(e/1e3);return s<60?`${s}s`:`${Math.floor(s/60)}m ${s%60}s`}r(zJe,"elapsedLabel");function UJe(e){if(e==null)return null;const s=Math.max(0,e)/1e3;return s<60?`${s.toFixed(1)}s`:`${Math.floor(s/60)}m ${(s%60).toFixed(1)}s`}r(UJe,"liveElapsedLabel");function KJe(e,s){const[n,a]=(0,m.useState)(()=>Date.now());return(0,m.useEffect)(()=>{if(e==null||!s)return;const i=window.setInterval(()=>a(Date.now()),100);return()=>window.clearInterval(i)},[e,s]),e==null?void 0:Math.max(0,n-e)}r(KJe,"useLiveElapsedMs");function VJe(e,s){return!Number.isFinite(e)||!Number.isFinite(s)||s<=0?0:Math.max(0,Math.round(e/s)-1)}r(VJe,"lineScrollOffset");function C2(e){const s=getComputedStyle(document.documentElement).getPropertyValue(e),n=Vxe(s);return Number.isFinite(n)?n:0}r(C2,"motionTokenMs");function WJe({text:e,streaming:s,leaving:n}){const a=(0,m.useRef)(null),[i,o]=(0,m.useState)(0),[l,c]=(0,m.useState)(!1),[d,u]=(0,m.useState)(!1);(0,m.useLayoutEffect)(()=>{const p=a.current;if(!p)return;const x=r(()=>{const v=parseFloat(window.getComputedStyle(p).lineHeight);o(VJe(p.scrollHeight,v))},"measure");if(x(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(x);return g.observe(p),()=>g.disconnect()},[e,s]),(0,m.useEffect)(()=>{const p=requestAnimationFrame(()=>c(!0)),x=window.setTimeout(()=>u(!0),C2("--motion-line-scroll"));return()=>{cancelAnimationFrame(p),window.clearTimeout(x)}},[]);const h=l?n?-1:s?-i:0:1;return(0,t.jsx)("span",{className:"tc-line-scroll min-w-0 flex-1","data-testid":"task-chat-live-self-talk","data-streaming":s||void 0,"data-leaving":n||void 0,children:(0,t.jsx)("span",{ref:a,className:U("tc-line-scroll-inner block",!s&&"truncate"),style:{transform:h!==0?`translateY(calc(${h} * 1lh))`:void 0,transition:d&&!n?"none":void 0},children:e})})}r(WJe,"LiveSelfTalkLine");function HJe(e,s){const[n,a]=(0,m.useState)(null),i=(0,m.useRef)(n),o=(0,m.useRef)(null),l=(0,m.useRef)(e),c=(0,m.useRef)(0),d=(0,m.useRef)(null),u=(0,m.useRef)(null),h=(0,m.useRef)(null);return l.current=e,(0,m.useEffect)(()=>{const p=r(j=>{j.current!=null&&(window.clearTimeout(j.current),j.current=null)},"clear"),x=r(j=>{i.current=j,a(j)},"show"),g=r(()=>{p(u),p(h),u.current=window.setTimeout(()=>{if(u.current=null,o.current!=null)return;const j=i.current;j==null||j.streaming||(x({...j,leaving:!0}),h.current=window.setTimeout(()=>{h.current=null,i.current?.leaving&&x(null)},C2("--motion-line-scroll")))},C2("--motion-interstitial-dwell"))},"scheduleLeave"),v=r((j,S)=>{p(u),p(h),c.current=Date.now(),x({text:j,streaming:S,swapKey:(i.current?.swapKey??0)+1}),S||g()},"swapIn");if(!s){p(d),p(u),p(h),o.current=null,i.current&&x(null);return}const y=i.current;if(e==null){y?.streaming&&(x({...y,streaming:!1}),g());return}if(y==null){v(e,!0);return}if(y.streaming){y.text!==e&&x({...y,text:e});return}if(o.current=e,d.current==null){const j=C2("--motion-interstitial-dwell"),S=Math.max(0,c.current+j-Date.now());d.current=window.setTimeout(()=>{d.current=null;const w=o.current;o.current=null,w!=null&&v(w,l.current!=null)},S)}},[e,s]),(0,m.useEffect)(()=>()=>{d.current!=null&&window.clearTimeout(d.current),u.current!=null&&window.clearTimeout(u.current),h.current!=null&&window.clearTimeout(h.current)},[]),n}r(HJe,"useHeldSelfTalk");var QJe={running:{Icon:ot,spin:!0,tone:"text-(--status-agent-running)"},working:{Icon:ot,spin:!0,tone:"text-(--status-agent-running)"},awaiting_approval:{Icon:Vw,spin:!1,tone:"text-primary"},interrupted:{Icon:yz,spin:!1,tone:"text-destructive"},refused:{Icon:qu,spin:!1,tone:"text-destructive"},truncated:{Icon:Z5e,spin:!1,tone:"text-(--status-agent-paused)"}};function Wxe({item:e,onApprovalDecision:s,chevronOpen:n,onToggle:a}){const{Icon:i,spin:o,tone:l}=QJe[e.status],c=e.status==="awaiting_approval",d=e.status==="running"||e.status==="working",u=KJe(e.startedAtMs,d),h=HJe(d?e.selfTalk:void 0,d),p=zJe(e.elapsedMs);if(d){const x=UJe(u??e.elapsedMs),g=e.selfTalk!=null,v=e.toolName?eE(e.toolName).icon:g?null:LJe(e.label),y=g||OJe(e.label)?BJe(e.id,u??e.elapsedMs??0):e.label,j=(0,t.jsxs)("div",{className:"tc-enter-status flex items-center gap-2 py-0.5 text-xs text-muted-foreground",children:[n!==void 0?(0,t.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center","data-testid":"task-chat-status-caret-slot",children:(0,t.jsx)(mn,{className:U("h-3 w-3 transition-transform",n?"rotate-90":null),"aria-hidden":!0})}):null,(0,t.jsx)("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center","data-testid":"task-chat-status-dot-slot",children:(0,t.jsx)("span",{"aria-hidden":!0,className:"h-2 w-2 animate-pulse rounded-full bg-(--status-agent-running)"})}),v?(0,t.jsx)(v,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null,(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 items-baseline gap-2",children:[(0,t.jsxs)("span",{className:"shimmer-text shimmer-text-muted shrink-0 font-medium",children:[y,"…"]}),x?(0,t.jsx)("span",{className:"shrink-0 font-mono tabular-nums text-(length:--text-micro)",children:x}):null,e.detail?(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-(length:--text-micro)",children:e.detail}):null,e.tokens?(0,t.jsxs)("span",{className:"ml-auto shrink-0 font-mono text-(length:--text-micro)",children:[e.tokens.used.toLocaleString(),"/",e.tokens.size.toLocaleString()," ctx"]}):null]})]});return(0,t.jsxs)("div",{className:"flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 py-0.5 text-xs text-muted-foreground","data-testid":"task-chat-interstitial-row",children:[(0,t.jsx)("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 shrink-0"}),h?(0,t.jsx)(WJe,{text:h.text,streaming:h.streaming,leaving:h.leaving},h.swapKey):(0,t.jsx)("span",{"aria-hidden":!0,className:"tc-line-scroll min-w-0 flex-1"})]}),a?(0,t.jsx)("button",{type:"button",onClick:a,"aria-expanded":n,className:"-mx-1.5 block w-full rounded-sm px-1.5 text-left transition-colors hover:bg-muted/60","data-testid":"task-chat-live-turn",children:j}):j]})}return(0,t.jsxs)("div",{className:U("tc-enter-status flex flex-col gap-2 rounded-lg border px-3 py-2 text-sm",c?"tc-approval border-primary/40 bg-primary/5":"border-border bg-muted/40"),children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,t.jsx)(i,{className:U("h-4 w-4 shrink-0",l,o&&"animate-spin")}),(0,t.jsx)("span",{className:"min-w-0 truncate font-medium",children:e.label}),(0,t.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[p?(0,t.jsx)("span",{children:p}):null,e.tokens?(0,t.jsxs)("span",{children:[e.tokens.used.toLocaleString(),"/",e.tokens.size.toLocaleString()," ctx"]}):null]})]}),e.detail?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e.detail}):null,c&&e.approval?(0,t.jsx)("div",{className:"flex flex-wrap justify-end gap-2 pt-1",children:e.approval.options.map(x=>{const g=x.kind.startsWith("reject");return(0,t.jsx)("button",{type:"button",onClick:r(()=>s?.(x.id),"onClick"),className:U("rounded-md border px-2.5 py-1 text-xs font-medium transition-colors",g?"border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground":"border-primary bg-primary text-primary-foreground hover:bg-primary/90"),children:x.label},x.id)})}):null]})}r(Wxe,"TaskChatStatusPill");function Hxe(e,s){const n=URL.createObjectURL(s),a=document.createElement("a");a.href=n,a.download=e,a.rel="noreferrer",a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}r(Hxe,"downloadBlob$1");function GJe(e,s,n){Hxe(e,new Blob([s],{type:`${n};charset=utf-8`}))}r(GJe,"downloadTextFile");var V4="flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50";function Qxe({issueId:e,documentKey:s,title:n,format:a,body:i,className:o}){const[l,c]=(0,m.useState)(null),[d,u]=(0,m.useState)(null),[h,p]=(0,m.useState)(null),{copy:x,copied:g,failed:v}=nf(),y=(0,m.useRef)(void 0);(0,m.useEffect)(()=>()=>clearTimeout(y.current),[]);const j=(0,m.useCallback)(async(C,A)=>{c(C),p(null);try{await A(),u(C)}catch(R){u(null),p(R instanceof Error?R.message:"Export failed")}finally{c(null)}clearTimeout(y.current),y.current=setTimeout(()=>{u(null),p(null)},2e3)},[]),S=(0,m.useCallback)(async()=>i??(await Tt.getDocument(e,s)).body,[i,s,e]),w=(0,m.useCallback)(()=>{c("copy"),p(null),(async()=>{try{await x(await S())==="failed"&&p("Copy failed")}catch(C){p(C instanceof Error?C.message:"Copy failed")}finally{c(null)}})()},[x,S]),N=v||h==="Copy failed"?"Copy failed":g?"Copied!":"Copy full content",_=d==="download"?"Downloaded!":"Download source",I=d==="pdf"?"Downloaded!":"Export to PDF";return(0,t.jsxs)("div",{className:U("flex items-center gap-0.5",o),"data-testid":"document-export-actions",children:[(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Copy full content",title:N,"data-testid":"document-export-copy",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),w()},"onClick"),children:g?(0,t.jsx)(xs,{"aria-hidden":"true",className:"h-3.5 w-3.5"}):(0,t.jsx)(jr,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Download source",title:_,"data-testid":"document-export-download",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),j("download",async()=>{const A=J2e(a);GJe(eH(n,A),await S(),A==="md"?"text/markdown":"text/plain")})},"onClick"),children:(0,t.jsx)(Ko,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{type:"button",className:V4,disabled:l!==null,"aria-label":"Export to PDF",title:I,"data-testid":"document-export-pdf",onClick:r(C=>{C.preventDefault(),C.stopPropagation(),j("pdf",async()=>{Hxe(eH(n,"pdf"),await Tt.getDocumentPdf(e,s))})},"onClick"),children:(0,t.jsx)(u3e,{"aria-hidden":"true",className:"h-3.5 w-3.5"})}),(0,t.jsx)("span",{className:"sr-only",role:"status","aria-live":"polite",children:h??(g?"Copied!":v?"Copy failed":d?"Downloaded!":"")})]})}r(Qxe,"DocumentExportActions");function cC({children:e,className:s}){return(0,t.jsx)("div",{className:U("relative aspect-video w-full overflow-hidden bg-accent/20",s),children:e})}r(cC,"PreviewFrame");function PT({label:e}){return(0,t.jsx)(cC,{className:"flex items-center justify-center",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5 text-muted-foreground/50",children:[(0,t.jsx)(zl,{className:"h-7 w-7","aria-hidden":"true"}),e?(0,t.jsx)("span",{className:"text-(length:--text-micro) font-medium uppercase tracking-wide",children:e}):null]})})}r(PT,"PlaceholderPreview");function YJe({artifact:e}){const[s,n]=(0,m.useState)(!1);return s||!e.contentPath?(0,t.jsx)(PT,{label:"Image"}):(0,t.jsx)(cC,{children:(0,t.jsx)("img",{src:e.contentPath,alt:e.title,loading:"lazy",className:"h-full w-full object-cover",onError:r(()=>n(!0),"onError")})})}r(YJe,"ImagePreview");function JJe({artifact:e}){const[s,n]=(0,m.useState)(!1),[a,i]=(0,m.useState)(!1),o=(0,m.useRef)(!1),l=(0,m.useRef)(null);if((0,m.useEffect)(()=>()=>{l.current!==null&&window.clearTimeout(l.current)},[]),s||!e.contentPath)return(0,t.jsx)(cC,{className:"flex items-center justify-center bg-black/80",children:(0,t.jsx)("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-white/15",children:(0,t.jsx)(_o,{className:"h-5 w-5 translate-x-0.5 text-white","aria-hidden":"true"})})});const c=r(()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),i(!0)},"markFrameReady"),d=r(()=>{l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(c,3e3)},"scheduleFrameReadyFallback"),u=r(p=>{if(o.current)return;o.current=!0;const x=p.currentTarget,g=Number.isFinite(x.duration)&&x.duration>0?x.duration:0,v=g>0?Math.min(1,g/4):.05;try{Math.abs(x.currentTime-v)>.001?(x.currentTime=v,d()):c()}catch{c()}},"loadThumbnailFrame"),h=r(p=>{(o.current||p.currentTarget.currentTime>0)&&c()},"handleLoadedData");return(0,t.jsxs)(cC,{className:"bg-black",children:[(0,t.jsx)("video",{src:e.contentPath,preload:"metadata",muted:!0,playsInline:!0,"data-frame-ready":a?"true":"false",className:U("h-full w-full object-contain transition-opacity",a?"opacity-100":"opacity-0"),onLoadedMetadata:u,onLoadedData:h,onSeeked:c,onError:r(()=>n(!0),"onError")}),(0,t.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:(0,t.jsx)("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-black/55",children:(0,t.jsx)(_o,{className:"h-5 w-5 translate-x-0.5 text-white","aria-hidden":"true"})})})]})}r(JJe,"VideoPreview");function XJe({artifact:e}){const s=e.previewText?.trim();return s?(0,t.jsxs)(cC,{className:"bg-card",children:[(0,t.jsx)("div",{className:"absolute inset-0 overflow-hidden p-3",children:(0,t.jsx)("p",{className:"max-h-full overflow-hidden whitespace-pre-wrap break-words text-base leading-6 text-muted-foreground/75",children:s})}),(0,t.jsx)("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-10 bg-gradient-to-t from-card to-transparent"})]}):(0,t.jsx)(PT,{label:e.source==="document"?"Document":"Text"})}r(XJe,"TextPreview");function T1({artifact:e}){switch(e.mediaKind){case"image":return(0,t.jsx)(YJe,{artifact:e},e.contentPath);case"video":return(0,t.jsx)(JJe,{artifact:e},e.contentPath);case"text":case"document":return(0,t.jsx)(XJe,{artifact:e});case"file":return(0,t.jsx)(PT,{label:"File"});default:return(0,t.jsx)(PT,{})}}r(T1,"ArtifactPreview");function TJ({href:e,download:s,title:n,children:a}){return(0,t.jsx)("a",{href:e,...s?{download:""}:{target:"_blank",rel:"noreferrer"},title:n,"aria-label":n,onClick:r(i=>i.stopPropagation(),"onClick"),className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:a})}r(TJ,"SecondaryAction");function ZJe({artifact:e}){return(0,t.jsxs)(Qe,{to:e.href,disableIssueQuicklook:!0,"data-testid":"artifact-card","data-media-kind":e.mediaKind,className:"group flex flex-col overflow-hidden rounded-lg border border-border bg-card cursor-pointer transition-colors hover:border-foreground/20 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,t.jsx)(T1,{artifact:e}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1 p-3",children:[(0,t.jsxs)("div",{className:"flex h-7 items-start justify-between gap-2",children:[(0,t.jsx)("h3",{className:"min-w-0 flex-1 truncate text-sm font-medium leading-7 text-foreground/85",title:e.title,children:e.title}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100",children:[e.source==="document"&&e.documentKey?(0,t.jsx)(Qxe,{issueId:e.issue.id,documentKey:e.documentKey,title:e.title}):null,e.openPath?(0,t.jsx)(TJ,{href:e.openPath,title:"Open file in new tab",children:(0,t.jsx)(xr,{className:"h-3.5 w-3.5"})}):null,e.downloadPath?(0,t.jsx)(TJ,{href:e.downloadPath,download:!0,title:"Download file",children:(0,t.jsx)(Ko,{className:"h-3.5 w-3.5"})}):null]})]}),(0,t.jsxs)("div",{className:"mt-0.5 flex items-center gap-1.5 text-(length:--text-micro) text-muted-foreground/65",children:[(0,t.jsxs)("span",{children:["Last edited ",cu(e.updatedAt)]}),e.createdByAgent?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"text-muted-foreground/50",children:"·"}),(0,t.jsx)("span",{className:"truncate",children:e.createdByAgent.name})]}):null]})]})]})}r(ZJe,"ArtifactCard");function Zw(e){if(!Number.isFinite(e)||e<0)return"0 B";if(e<1024)return`${Math.round(e)} B`;const s=["KB","MB","GB","TB"];let n=e/1024,a=0;for(;n>=1024&&a<s.length-1;)n/=1024,a+=1;const i=n.toFixed(1);return`${i.endsWith(".0")?i.slice(0,-2):i} ${s[a]}`}r(Zw,"formatBytes$5");var MT=new Set(["application/octet-stream","binary/octet-stream","application/x-binary"]),eXe=[".mp4",".m4v",".webm",".mov",".qt",".quicktime"],tXe=[".png",".jpg",".jpeg",".gif",".webp",".avif",".bmp",".svg",".ico"],sXe=new Set(["application/wasm"]),nXe=new Set(["application/zip","application/x-zip","application/x-zip-compressed"]),Gxe=new Set(["text/markdown","text/x-markdown","application/markdown","application/x-markdown"]),rXe=new Set(["application/csv","application/ecmascript","application/graphql","application/html","application/javascript","application/json","application/ld+json","application/sql","application/toml","application/x-httpd-php","application/x-javascript","application/x-python","application/x-sh","application/x-yaml","application/xhtml+xml","application/xml","application/yaml"]),aXe=[".csv",".css",".graphql",".htm",".html",".js",".json",".jsx",".log",".markdown",".md",".mdx",".php",".py",".sh",".sql",".toml",".ts",".tsx",".txt",".xml",".yaml",".yml"];function E1(e){return(e??"").toLowerCase().split(";")[0]?.trim()??""}r(E1,"normalizeOutputContentType");function iXe(e){const s=(e??"").trim().toLowerCase();return s?aXe.some(n=>s.endsWith(n)):!1}r(iXe,"hasDocumentLikeFilename");function Yxe(e){return nXe.has(e)||e.endsWith("+zip")}r(Yxe,"isZipContentType");function oXe(e){return e?!!(e.startsWith("text/")||Gxe.has(e)||rXe.has(e)||e.startsWith("application/")&&(e.endsWith("+json")||e.endsWith("+xml"))):!1}r(oXe,"isDocumentLikeOutputContentType");function lXe(e,s){const n=E1(e);return!n||oXe(n)||MT.has(n)&&iXe(s)?!1:n.startsWith("video/")||n.startsWith("image/")||n==="application/pdf"||sXe.has(n)||Yxe(n)||MT.has(n)}r(lXe,"isOutputEligibleContentType");function cXe(e){const s=E1(e);if(s.startsWith("video/")){const n=s.slice(6);return n==="quicktime"?{label:"MOV",tone:"video"}:{label:(n||"vid").toUpperCase().slice(0,4),tone:"video"}}return s==="application/pdf"?{label:"PDF",tone:"pdf"}:Yxe(s)?{label:"ZIP",tone:"zip"}:s.startsWith("image/")?{label:"IMG",tone:"image"}:Gxe.has(s)?{label:"MD",tone:"bin"}:s==="text/plain"?{label:"TXT",tone:"bin"}:s==="text/csv"||s==="application/csv"?{label:"CSV",tone:"bin"}:s==="text/html"||s==="application/html"||s==="application/xhtml+xml"?{label:"HTML",tone:"bin"}:s==="application/json"||s.endsWith("+json")?{label:"JSON",tone:"bin"}:s==="application/xml"||s==="text/xml"||s.endsWith("+xml")?{label:"XML",tone:"bin"}:s==="application/wasm"?{label:"WASM",tone:"bin"}:{label:"BIN",tone:"bin"}}r(cXe,"getOutputFileGlyph");function Ld(e,s){const n=E1(e);if(n.startsWith("video/"))return!0;if(!MT.has(n))return!1;const a=(s??"").trim().toLowerCase();return eXe.some(i=>a.endsWith(i))}r(Ld,"isVideoLikeOutput");function pw(e){return E1(e).startsWith("image/")}r(pw,"isImageContentType");function dC(e,s){const n=E1(e);if(pw(n))return!0;if(n&&!MT.has(n))return!1;const a=(s??"").trim().toLowerCase();return tXe.some(i=>a.endsWith(i))}r(dC,"isImageLikeOutput");function EJ(e){const s=new Date(e).getTime();return Number.isNaN(s)?0:s}r(EJ,"toTime");function tE(e){const s=(e??[]).filter(n=>n.type==="artifact"&&n.provider==="paperclip").flatMap(n=>{const a=vIe.safeParse(n.metadata);return a.success&&!lXe(a.data.contentType,a.data.originalFilename)?[]:[{id:n.id,title:n.title,status:typeof n.status=="string"?n.status:"active",isPrimary:!!n.isPrimary,createdAt:n.createdAt,metadata:a.success?a.data:null,degraded:!a.success,workProduct:n}]});return s.sort((n,a)=>n.isPrimary!==a.isPrimary?n.isPrimary?-1:1:EJ(a.createdAt)-EJ(n.createdAt)),{items:s,primary:s[0]??null,rest:s.slice(1),count:s.length}}r(tE,"getIssueOutputs");function uK(e){return e.metadata?.originalFilename||e.title||"output"}r(uK,"outputFilename");function Jxe(e){return new Set(tE(e).items.flatMap(s=>{const n=s.metadata?.attachmentId;return n?[n]:[]}))}r(Jxe,"getPromotedOutputAttachmentIds");var jh={connect:r((e,s)=>Re.post(`/companies/${e}/email/connections`,s),"connect"),inspectSaved:r((e,s)=>Re.post(`/companies/${e}/email/connections/${s}/inspect`,{}),"inspectSaved"),list:r(e=>Re.get(`/companies/${e}/email/inboxes`),"list"),setup:r((e,s)=>Re.post(`/companies/${e}/email/inboxes`,s),"setup"),inspect:r((e,s)=>Re.post(`/companies/${e}/email/inspect`,{apiKey:s}),"inspect"),control:r((e,s)=>Re.post(`/email/inboxes/${e}/control`,{action:s}),"control"),reconnect:r((e,s,n)=>Re.post(`/email/inboxes/${e}/reconnect`,{apiKey:s,receiveMode:n}),"reconnect"),resolve:r((e,s,n,a)=>Re.post(`/companies/${e}/email/deliveries/${s}/resolve`,{outcome:n,providerMessageId:a}),"resolve"),thread:r((e,s)=>Re.get(`/companies/${e}/email/tasks/${s}`),"thread"),send:r((e,s)=>Re.post(`/companies/${e}/email/send`,s),"send")},Xxe=(0,m.createContext)(null);function dXe({companyId:e,issueId:s,children:n}){const{enabled:a}=Tx(),i=ee({queryKey:["email-thread",e,s],queryFn:r(()=>jh.thread(e,s),"queryFn"),enabled:a,refetchInterval:a?3e3:!1});return(0,t.jsx)(Xxe.Provider,{value:i.data??null,children:n})}r(dXe,"EmailThreadProvider");function Zxe(e){const s=(0,m.useContext)(Xxe),n=s?.messages.find(a=>a.commentId===e);return n&&s?(0,t.jsx)(ege,{message:n,publication:s.publications.find(a=>a.providerMessageId===n.providerMessageId),issueId:s.issueId}):null}r(Zxe,"useEmailComment");function ege({message:e,publication:s,issueId:n}){const a=ee({queryKey:["email-attachments",n],queryFn:r(()=>Tt.listAttachments(n),"queryFn"),enabled:e.attachmentIds.length>0});return(0,t.jsxs)("article",{"aria-label":e.direction==="inbound"?"Email received":"Email sent",className:"space-y-4 rounded-xl border border-border bg-card p-5",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,t.jsxs)("span",{className:"flex items-center gap-2 text-sm font-semibold",children:[(0,t.jsx)(hce,{className:"size-4"}),e.direction==="inbound"?"Email received":"Email sent"]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium",children:[e.from,e.direction==="inbound"&&(0,t.jsx)("span",{className:"ml-2 rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground",children:"External"})]}),(0,t.jsxs)("p",{className:"break-words text-xs text-muted-foreground",children:["To: ",e.to.join(", ")]}),!!e.cc?.length&&(0,t.jsxs)("p",{className:"break-words text-xs text-muted-foreground",children:["Cc: ",e.cc.join(", ")]}),(0,t.jsx)("p",{className:"text-sm font-semibold",children:e.subject})]}),(0,t.jsx)("div",{className:"whitespace-pre-wrap break-words text-sm",children:e.text||"(No text body)"}),!!e.attachmentIds.length&&(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:e.attachmentIds.map(i=>{const o=a.data?.find(l=>l.id===i);return(0,t.jsxs)("a",{href:`/api/attachments/${i}/content`,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 rounded-md border border-border px-3 py-2 text-xs",children:[(0,t.jsx)(zl,{className:"size-3.5"}),o?.originalFilename??"Open attachment"]},i)})}),(0,t.jsxs)("details",{className:"text-xs text-muted-foreground",children:[(0,t.jsx)("summary",{className:"cursor-pointer",children:"Email details"}),(0,t.jsxs)("div",{className:"space-y-2 pt-3",children:[!!e.bcc?.length&&(0,t.jsxs)("p",{children:["Bcc: ",e.bcc.join(", ")]}),(0,t.jsxs)("p",{className:"break-all",children:["Message ID: ",e.providerMessageId]}),e.fullText!==e.text&&(0,t.jsx)("div",{className:"whitespace-pre-wrap break-words",children:e.fullText})]})]}),s&&(0,t.jsxs)("p",{className:"border-t border-border pt-3 text-xs text-muted-foreground",children:[s.outcome==="delivered"?"Delivered":s.outcome==="failed"?"Delivery failed":s.outcome==="uncertain"?"Delivery uncertain":s.outcome==="queued"?"Queued":"Sent",s.error?` · ${s.error}`:""]}),a.error&&(0,t.jsx)("p",{role:"alert",className:"text-xs text-destructive",children:"Attachments could not be loaded."})]})}r(ege,"EmailMessageCard");var Ij=(0,m.createContext)(null);function uXe(e){return e.contentType.toLowerCase().split(";")[0]?.trim()??""}r(uXe,"normalizedContentType$1");function P1(e){return e.originalFilename??e.id}r(P1,"attachmentFilename");function mK(e){return e.openPath??e.contentPath}r(mK,"attachmentOpenPath");function sE(e){return e.downloadPath??`${e.contentPath}?download=1`}r(sE,"attachmentDownloadPath");function tge(e){const s=uXe(e);return dC(s,e.originalFilename)&&!/^image\/hei[cf](?:-sequence)?$/.test(s)}r(tge,"isImageAttachment$2");function sge(e){return Ld(e.contentType,e.originalFilename)}r(sge,"isVideoAttachment");function mXe(e){return z_e(e)}r(mXe,"isMarkdownAttachment");function eN({items:e,initialIndex:s,open:n,onOpenChange:a}){const[i,o]=(0,m.useState)(s),l=(0,m.useRef)(null),c=(0,m.useCallback)(v=>{l.current=v},[]);(0,m.useEffect)(()=>{n&&o(s)},[n,s]);const d=(0,m.useCallback)(()=>{o(v=>(v+1)%e.length)},[e.length]),u=(0,m.useCallback)(()=>{o(v=>(v-1+e.length)%e.length)},[e.length]);(0,m.useEffect)(()=>{i<e.length||o(0)},[i,e.length]),(0,m.useEffect)(()=>{if(!n)return;const v=r(y=>{y.key==="ArrowRight"?d():y.key==="ArrowLeft"?u():y.key==="Escape"&&a(!1)},"handler");return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[n,d,u,a]);const h=(0,m.useCallback)(v=>{const y=v.target;y.closest("button")||y.closest("a")||y===l.current||a(!1)},[a]);if(e.length===0)return null;const p=e[i];if(!p)return null;const x=P1(p),g=Ld(p.contentType,p.originalFilename);return(0,t.jsx)(r2e,{open:n,onOpenChange:a,children:(0,t.jsxs)(ZAe,{children:[(0,t.jsx)(e2e,{className:"fixed inset-0 z-50 bg-black/90 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200"}),(0,t.jsxs)(s2e,{className:"fixed inset-0 z-50 flex flex-col outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200",onClick:h,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 text-white/80 text-sm shrink-0",children:[(0,t.jsx)("span",{className:"truncate max-w-(--pct-50) font-medium",title:x,children:x}),(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("span",{className:"text-white/40 tabular-nums text-xs",children:[i+1," / ",e.length]}),(0,t.jsx)("a",{href:sE(p),download:x,className:"text-white/50 hover:text-white transition-colors",title:"Download","aria-label":`Download ${x}`,onClick:r(v=>v.stopPropagation(),"onClick"),children:(0,t.jsx)(Ko,{className:"h-4.5 w-4.5"})}),(0,t.jsx)("button",{type:"button",onClick:r(()=>a(!1),"onClick"),className:"text-white/50 hover:text-white transition-colors",title:"Close",children:(0,t.jsx)(nr,{className:"h-5 w-5"})})]})]}),(0,t.jsxs)("div",{className:"flex-1 flex items-center min-h-0",children:[(0,t.jsx)("div",{className:"w-16 md:w-24 shrink-0 flex items-center justify-center h-full",children:e.length>1&&(0,t.jsx)("button",{type:"button",onClick:u,className:"rounded-full bg-white/10 p-3 text-white/60 hover:text-white hover:bg-white/20 transition-colors",title:"Previous",children:(0,t.jsx)(hu,{className:"h-7 w-7"})})}),(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center min-w-0 min-h-0 h-full px-2",children:g?(0,t.jsx)("video",{ref:c,src:p.contentPath,className:"max-w-full max-h-full rounded-lg",controls:!0,playsInline:!0}):(0,t.jsx)("img",{ref:c,src:p.contentPath,alt:x,className:"max-w-full max-h-full object-contain select-none rounded-lg",draggable:!1})}),(0,t.jsx)("div",{className:"w-16 md:w-24 shrink-0 flex items-center justify-center h-full",children:e.length>1&&(0,t.jsx)("button",{type:"button",onClick:d,className:"rounded-full bg-white/10 p-3 text-white/60 hover:text-white hover:bg-white/20 transition-colors",title:"Next",children:(0,t.jsx)(mn,{className:"h-7 w-7"})})})]}),(0,t.jsx)("div",{className:"h-6 shrink-0"})]})]})})}r(eN,"ImageGalleryModal");function FF(e,s){if(e&&!s)return e;if(!e&&s)return s;if(e||s)return{...e,...s}}r(FF,"mergeObjects");var hK={};function pK(e,s,n,a,i){if(!n&&!a&&!i&&!e)return DT(s);let o=DT(e);return s&&(o=Ek(o,s)),n&&(o=Ek(o,n)),a&&(o=Ek(o,a)),i&&(o=Ek(o,i)),o}r(pK,"mergeProps");function hXe(e){if(e.length===0)return hK;if(e.length===1)return DT(e[0]);let s=DT(e[0]);for(let n=1;n<e.length;n+=1)s=Ek(s,e[n]);return s}r(hXe,"mergePropsN");function DT(e){return fK(e)?{...rge(e,hK)}:pXe(e)}r(DT,"createInitialMergedProps");function Ek(e,s){return fK(s)?rge(s,e):fXe(e,s)}r(Ek,"mergeInto");function pXe(e){const s={...e};for(const n in s){const a=s[n];nge(n,a)&&(s[n]=age(a))}return s}r(pXe,"copyInitialProps");function fXe(e,s){if(!s)return e;for(const n in s){const a=s[n];switch(n){case"style":e[n]=FF(e.style,a);break;case"className":e[n]=oge(e.className,a);break;default:nge(n,a)?e[n]=xXe(e[n],a):e[n]=a}}return e}r(fXe,"mutablyMergeInto");function nge(e,s){const n=e.charCodeAt(0),a=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&a===110&&i>=65&&i<=90&&(typeof s=="function"||typeof s>"u")}r(nge,"isEventHandler");function fK(e){return typeof e=="function"}r(fK,"isPropsGetter");function rge(e,s){return fK(e)?e(s):e??hK}r(rge,"resolvePropsGetter");function xXe(e,s){return s?e?(...n)=>{const a=n[0];if(lge(a)){const o=a;ige(o);const l=s(...n);return o.baseUIHandlerPrevented||e?.(...n),l}const i=s(...n);return e?.(...n),i}:age(s):e}r(xXe,"mergeEventHandlers");function age(e){return e&&((...s)=>{const n=s[0];return lge(n)&&ige(n),e(...s)})}r(age,"wrapEventHandler");function ige(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}r(ige,"makeEventPreventable");function oge(e,s){return s?e?s+" "+e:s:e}r(oge,"mergeClassNames");function lge(e){return e!=null&&typeof e=="object"&&"nativeEvent"in e}r(lge,"isSyntheticEvent");function gXe(e,s){return r(function(a,...i){const o=new URL(e);return o.searchParams.set("code",a.toString()),i.forEach(l=>o.searchParams.append("args[]",l)),`${s} error #${a}; visit ${o} for the full message.`},"formatErrorMessage")}r(gXe,"createFormatErrorMessage");var bXe=gXe("https://base-ui.com/production-error","Base UI"),PJ={};function cge(e,s){const n=m.useRef(PJ);return n.current===PJ&&(n.current=e(s)),n}r(cge,"useRefWithInit");function MJ(e,s,n,a){const i=cge(dge).current;return yXe(i,e,s,n,a)&&uge(i,[e,s,n,a]),i.callback}r(MJ,"useMergedRefs");function vXe(e){const s=cge(dge).current;return jXe(s,e)&&uge(s,e),s.callback}r(vXe,"useMergedRefsN");function dge(){return{callback:null,cleanup:null,refs:[]}}r(dge,"createForkRef");function yXe(e,s,n,a,i){return e.refs[0]!==s||e.refs[1]!==n||e.refs[2]!==a||e.refs[3]!==i}r(yXe,"didChange");function jXe(e,s){return e.refs.length!==s.length||e.refs.some((n,a)=>n!==s[a])}r(jXe,"didChangeN");function uge(e,s){if(e.refs=s,s.every(n=>n==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&(e.cleanup(),e.cleanup=null),n!=null){const a=Array(s.length).fill(null);for(let i=0;i<s.length;i+=1){const o=s[i];if(o!=null)switch(typeof o){case"function":{const l=o(n);typeof l=="function"&&(a[i]=l);break}case"object":o.current=n}}e.cleanup=()=>{for(let i=0;i<s.length;i+=1){const o=s[i];if(o!=null)switch(typeof o){case"function":{const l=a[i];typeof l=="function"?l():o(null);break}case"object":o.current=null}}}}}}r(uge,"update");var wXe=parseInt("19.2.8",10);function NXe(e){return wXe>=e}r(NXe,"isReactVersionAtLeast");function DJ(e){if(!m.isValidElement(e))return null;const s=e,n=s.props;return(NXe(19)?n?.ref:s.ref)??null}r(DJ,"getReactElementRef");var y8t=Object.freeze([]),Pk=Object.freeze({});function kXe(e,s){const n={};for(const a in e){const i=e[a];if(s?.hasOwnProperty(a)){const o=s[a](i);o!=null&&Object.assign(n,o);continue}i===!0?n[`data-${a.toLowerCase()}`]="":i&&(n[`data-${a.toLowerCase()}`]=i.toString())}return n}r(kXe,"getStateAttributesProps");function SXe(e,s){return typeof e=="function"?e(s):e}r(SXe,"resolveClassName");function CXe(e,s){return typeof e=="function"?e(s):e}r(CXe,"resolveStyle");function _Xe(e,s,n={}){const a=s.render,i=IXe(s,n);return n.enabled===!1?null:TXe(e,a,i,n.state??Pk)}r(_Xe,"useRenderElement");function IXe(e,s={}){const{className:n,style:a,render:i}=e,{state:o=Pk,ref:l,props:c,stateAttributesMapping:d,enabled:u=!0}=s,h=u?SXe(n,o):void 0,p=u?CXe(a,o):void 0,x=u?kXe(o,d):Pk,g=u&&c?AXe(c):void 0,v=u?FF(x,g)??{}:Pk;return typeof document<"u"&&(u?Array.isArray(l)?v.ref=vXe([v.ref,DJ(i),...l]):v.ref=MJ(v.ref,DJ(i),l):MJ(null,null)),u?(h!==void 0&&(v.className=oge(v.className,h)),p!==void 0&&(v.style=FF(v.style,p)),v):Pk}r(IXe,"useRenderElementProps");function AXe(e){return Array.isArray(e)?hXe(e):pK(void 0,e)}r(AXe,"resolveRenderFunctionProps");var RXe=Symbol.for("react.lazy");function TXe(e,s,n,a){if(s){if(typeof s=="function")return s(n,a);const i=pK(n,s.props);i.ref=n.ref;let o=s;return o?.$$typeof===RXe&&(o=m.Children.toArray(s)[0]),m.cloneElement(o,i)}if(e&&typeof e=="string")return EXe(e,n);throw new Error(bXe(8))}r(TXe,"evaluateRenderProp");function EXe(e,s){return e==="button"?(0,m.createElement)("button",{type:"button",...s,key:s.key}):e==="img"?(0,m.createElement)("img",{alt:"",...s,key:s.key}):m.createElement(e,s)}r(EXe,"renderTag");function PXe(e){return _Xe(e.defaultTagName??"div",e,e)}r(PXe,"useRender");var MXe=lz("group/attachment relative flex w-fit max-w-full min-w-0 shrink-0 flex-wrap rounded-none border bg-card text-card-foreground transition-colors focus-within:ring-1 focus-within:ring-ring/50 has-[>a,>button]:hover:bg-muted/50 data-[state=error]:border-destructive/30 data-[state=idle]:border-dashed",{variants:{size:{default:"gap-2 text-xs has-data-[slot=attachment-content]:px-2 has-data-[slot=attachment-content]:py-1.5 has-data-[slot=attachment-media]:p-1.5",sm:"gap-2.5 text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1",xs:"gap-1.5 rounded-none text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1"},orientation:{horizontal:"min-w-40 items-center",vertical:"w-24 flex-col has-data-[slot=attachment-content]:w-30"}}});function mge({className:e,state:s="done",size:n="default",orientation:a="horizontal",...i}){return(0,t.jsx)("div",{"data-slot":"attachment","data-state":s,"data-size":n,"data-orientation":a,className:U(MXe({size:n,orientation:a}),e),...i})}r(mge,"Attachment");var DXe=lz("relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-none bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=xs]/attachment:rounded-none group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5",{variants:{variant:{icon:"",image:"opacity-60 group-data-[state=done]/attachment:opacity-100 group-data-[state=idle]/attachment:opacity-100 *:[img]:aspect-square *:[img]:w-full *:[img]:object-cover"}},defaultVariants:{variant:"icon"}});function hge({className:e,variant:s="icon",...n}){return(0,t.jsx)("div",{"data-slot":"attachment-media","data-variant":s,className:U(DXe({variant:s}),e),...n})}r(hge,"AttachmentMedia");function pge({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-content",className:U("max-w-full min-w-0 flex-1 leading-tight group-data-[orientation=vertical]/attachment:px-1",e),...s})}r(pge,"AttachmentContent");function fge({className:e,...s}){return(0,t.jsx)("span",{"data-slot":"attachment-title",className:U("block max-w-full min-w-0 truncate font-medium group-data-[state=processing]/attachment:shimmer group-data-[state=uploading]/attachment:shimmer",e),...s})}r(fge,"AttachmentTitle");function xge({className:e,...s}){return(0,t.jsx)("span",{"data-slot":"attachment-description",className:U("mt-0.5 block min-w-0 truncate text-xs text-muted-foreground group-data-[state=error]/attachment:text-destructive/80","max-w-full",e),...s})}r(xge,"AttachmentDescription");function LXe({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-actions",className:U("relative z-20 flex shrink-0 items-center group-data-[orientation=vertical]/attachment:absolute group-data-[orientation=vertical]/attachment:top-3 group-data-[orientation=vertical]/attachment:right-3 group-data-[orientation=vertical]/attachment:gap-1",e),...s})}r(LXe,"AttachmentActions$1");function $Xe({className:e,variant:s,size:n="icon-xs",...a}){return(0,t.jsx)(F,{"data-slot":"attachment-action",variant:s??"ghost",size:n,className:U(e),...a})}r($Xe,"AttachmentAction");function OXe({className:e,render:s,type:n,...a}){return PXe({defaultTagName:"button",props:pK({type:s?n:n??"button",className:U("absolute inset-0 z-10 outline-none",e)},a),render:s,state:{slot:"attachment-trigger"}})}r(OXe,"AttachmentTrigger");function gge({className:e,...s}){return(0,t.jsx)("div",{"data-slot":"attachment-group",className:U("flex min-w-0 scroll-fade-x snap-x snap-mandatory scroll-px-1 scrollbar-none gap-3 overflow-x-auto overscroll-x-contain py-1 *:data-[slot=attachment]:flex-none *:data-[slot=attachment]:snap-start",e),...s})}r(gge,"AttachmentGroup");var FXe=new Set(["png","jpg","jpeg","gif","webp","svg","avif","bmp","ico","heic"]),BXe={pdf:{icon:pi,label:"PDF"},doc:{icon:pi,label:"Doc"},docx:{icon:pi,label:"Doc"},txt:{icon:pi,label:"Text"},md:{icon:pi,label:"Markdown"},rtf:{icon:pi,label:"Text"},csv:{icon:Sk,label:"CSV"},tsv:{icon:Sk,label:"TSV"},xls:{icon:Sk,label:"Sheet"},xlsx:{icon:Sk,label:"Sheet"},zip:{icon:Q0,label:"ZIP"},gz:{icon:Q0,label:"Archive"},tar:{icon:Q0,label:"Archive"},tgz:{icon:Q0,label:"Archive"},rar:{icon:Q0,label:"Archive"},"7z":{icon:Q0,label:"Archive"},mp3:{icon:kk,label:"Audio"},wav:{icon:kk,label:"Audio"},m4a:{icon:kk,label:"Audio"},ogg:{icon:kk,label:"Audio"},mp4:{icon:t2,label:"Video"},mov:{icon:t2,label:"Video"},webm:{icon:t2,label:"Video"},json:{icon:vl,label:"JSON"},yaml:{icon:vl,label:"YAML"},yml:{icon:vl,label:"YAML"},xml:{icon:vl,label:"XML"},html:{icon:vl,label:"HTML"},css:{icon:vl,label:"CSS"},js:{icon:vl,label:"Code"},jsx:{icon:vl,label:"Code"},ts:{icon:vl,label:"Code"},tsx:{icon:vl,label:"Code"},py:{icon:vl,label:"Code"},rb:{icon:vl,label:"Code"},go:{icon:vl,label:"Code"},rs:{icon:vl,label:"Code"},sh:{icon:vl,label:"Code"},sql:{icon:vl,label:"SQL"},log:{icon:pi,label:"Log"},patch:{icon:vl,label:"Patch"},diff:{icon:vl,label:"Patch"}};function bge(e){const s=/\.([a-z0-9]+)$/i.exec(e.trim());return s?s[1].toLowerCase():""}r(bge,"extensionOf");function LJ(e){return FXe.has(bge(e))}r(LJ,"isImageFilename");function vge(e){return(e??"").toLowerCase().split(";")[0]?.trim()??""}r(vge,"normalizedContentType");function xI(e){const s=vge(e.contentType);return s.startsWith("image/")?!0:s&&s!=="application/octet-stream"?!1:LJ(e.name)||LJ(e.url.split("?")[0])}r(xI,"isImageAttachment$1");function yge(e){return BXe[bge(e)]??{icon:aO,label:"File"}}r(yge,"fileKindForName");function qXe(e){const s=yge(e.name);if(s.label!=="File")return s;const n=vge(e.contentType);return n==="application/pdf"?{icon:pi,label:"PDF"}:n==="application/json"||n.endsWith("+json")?{icon:vl,label:"JSON"}:n==="text/csv"||n==="application/csv"?{icon:Sk,label:"CSV"}:n.startsWith("text/")?{icon:pi,label:"Text"}:n.startsWith("audio/")?{icon:kk,label:"Audio"}:n.startsWith("video/")?{icon:t2,label:"Video"}:n.includes("zip")||n.includes("archive")?{icon:Q0,label:"Archive"}:s}r(qXe,"fileKindForAttachment");function jge(e){return e===void 0||!Number.isFinite(e)||e<=0?"":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}r(jge,"formatFileSize");function zXe(e){return/\/api\/(?:attachments|assets)\/([^/?]+)\/content/.exec(e)?.[1]??null}r(zXe,"attachmentIdFromUrl");function $J(e,s){const n=new Map(s.map(i=>[i.id,i])),a=new Map(s.flatMap(i=>[[i.contentPath,i],...i.openPath?[[i.openPath,i]]:[]]));return e.map(i=>{const o=i.url.split("?")[0],l=a.get(o)??n.get(zXe(i.url)??"");return l?{...i,id:l.id,name:l.originalFilename?.trim()||i.name,contentType:l.contentType,byteSize:l.byteSize,openPath:l.openPath,downloadPath:l.downloadPath}:i})}r($J,"hydrateAttachmentRefs");var OJ=/(?<!!)\[((?:\\.|[^\]\\])+)\]\((\/api\/(?:attachments|assets)\/[^()\s]+\/content(?:\?[^()\s]*)?)\)/g,wge=/!\[((?:\\.|[^\]\\])*)\]\(([^()\s]+)\)/g;function Nge(e){return e.replace(wge,"").trim().length===0&&e.trim().length>0}r(Nge,"isStandaloneImageEmbedLine");function UXe(e){const s=[],n=new Set;for(const a of e.split(`
337
337
  `))if(Nge(a))for(const i of a.matchAll(wge)){const[,o,l]=i;n.has(l)||(n.add(l),s.push({name:o.replace(/\\([[\]])/g,"$1"),url:l}))}return s}r(UXe,"extractImageRefs");function KXe(e){return e.split(`
338
338
  `).filter(s=>!Nge(s)).join(`
339
339
  `).replace(/\n{3,}/g,`
@@ -722,7 +722,7 @@ Last resolved: user values resolve per member`;return(0,t.jsxs)("div",{role:"row
722
722
  | Stage | Qualified |
723
723
  | Owner | growth-bot |`,argumentsSummaryJson:JSON.stringify({spreadsheetId:"1AbC…xyz",range:"Leads!A2:D2",values:[["Priya Anand","Northwind","Qualified","growth-bot"]],apiKey:"[redacted]"},null,2),argumentsHash:"sha256:9f2c1a7be4d0c8a3",expiresAt:U7(42)};function Fv(e){const{toolAction:s,payload:n,...a}=e;return al({id:"interaction-tool-action-default",title:void 0,summary:void 0,createdByAgentId:"agent-codex",payload:{version:1,prompt:"Approve running this tool call?",acceptLabel:"Approve & run",rejectLabel:"Decline",...n,toolAction:{...A6t,...s}},...a})}r(Fv,"createToolActionConfirmationInteraction");var c7t=Fv({id:"interaction-tool-action-pending-write"}),d7t=Fv({id:"interaction-tool-action-pending-destructive",toolAction:{actionRequestId:"aaaaaaa5-5555-4555-8555-5555555555a5",invocationId:"bbbbbbb6-6666-4666-8666-6666666666b6",toolName:"google_sheets.delete_rows",toolDisplayName:"Delete rows from spreadsheet",risk:"destructive",previewMarkdown:"**Permanently delete 12 rows** (rows 30–41) from the **Q3 Growth Leads** sheet. This cannot be undone.",argumentsSummaryJson:JSON.stringify({spreadsheetId:"1AbC…xyz",range:"Leads!A30:D41",rowCount:12},null,2),argumentsHash:"sha256:1c4e77aa90b3f2d1",expiresAt:U7(4)}}),u7t=Fv({id:"interaction-tool-action-running",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:00.000Z"),result:{version:1,outcome:"accepted",toolAction:{version:1,status:"approved",updatedAt:"2026-04-20T15:02:00.000Z"}}}),m7t=Fv({id:"interaction-tool-action-executed",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:12.000Z"),result:{version:1,outcome:"accepted",toolAction:{version:1,status:"executed",resultSummary:"Row 42 added to “Q3 Growth Leads”.",resultHref:"https://docs.google.com/spreadsheets/d/1AbCxyz/edit#gid=0&range=A42",updatedAt:"2026-04-20T15:02:12.000Z"}}}),h7t=Fv({id:"interaction-tool-action-failed",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:09.000Z"),result:{version:1,outcome:"accepted",toolAction:{version:1,status:"failed",errorCode:"insufficient_permission",errorMessage:"The caller does not have permission to edit this spreadsheet (Google API 403). Ask the sheet owner to grant edit access to the connected account.",updatedAt:"2026-04-20T15:02:09.000Z"}}}),p7t=Fv({id:"interaction-tool-action-declined",status:"rejected",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:01:00.000Z"),updatedAt:new Date("2026-04-20T15:01:00.000Z"),result:{version:1,outcome:"rejected",reason:"We don't add leads to this sheet manually — use the CRM sync instead."}}),f7t=Fv({id:"interaction-tool-action-expired",status:"expired",updatedAt:new Date("2026-04-20T16:00:00.000Z"),resolvedAt:new Date("2026-04-20T16:00:00.000Z"),toolAction:{expiresAt:"2026-04-20T16:00:00.000Z"},result:{version:1,outcome:"superseded_by_comment",toolAction:{version:1,status:"expired",updatedAt:"2026-04-20T16:00:00.000Z"}}}),R6t={version:1,proposalId:"eeeeeee5-5555-4555-8555-5555555555e5",sourceSecretLabel:"OpenAI API key",configPath:"access.evals_openai_api_key",targetAgentId:"ffffffff-6666-4666-8666-6666666666f6",targetAgentName:"EvalsEngineer",justification:"The evaluation runner needs the existing credential under its canonical config name.",expiresAt:U7(20160)};function X1(e){const{secretProposal:s,payload:n,...a}=e;return al({id:"interaction-secret-proposal-default",title:void 0,summary:"Review a proposed alias for an existing secret binding.",createdByAgentId:"agent-codex",resolverPolicy:"human_only",requestedResolverPolicy:"human_only",effectiveResolverPolicy:"human_only",payload:{version:1,prompt:"Approve this secret binding?",acceptLabel:"Approve & bind",rejectLabel:"Reject",allowDeclineReason:!0,...n,secretProposal:{...R6t,...s}},...a})}r(X1,"createSecretProposalConfirmationInteraction");var x7t=X1({id:"interaction-secret-proposal-pending"});function BCe(e={}){const{payload:s,...n}=e;return al({id:"interaction-connection-authorization-default",title:"Connect your Gmail to continue",summary:"Outreach Agent needs your Gmail identity for work running as you.",createdByAgentId:"agent-codex",addresseeUserId:Lr.currentUserId,resolverPolicy:"human_only",requestedResolverPolicy:"human_only",effectiveResolverPolicy:"human_only",payload:{version:1,prompt:"Connect your Gmail to continue",acceptLabel:"Connect Gmail",rejectLabel:"Not now",...s,connectionAuthorization:{version:1,providerName:"Gmail",connectionName:null,requestingAgentName:"Outreach Agent"},target:{type:"custom",key:"connection:gmail-abc:user:user-dotta",label:"Connect Gmail",href:"https://accounts.google.com/o/oauth2/v2/auth?client_id=paperclip"}},...n})}r(BCe,"createConnectionAuthorizationInteraction");var g7t=BCe({id:"interaction-connection-authorization-pending"}),b7t=BCe({id:"interaction-connection-authorization-resolved",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:03.000Z"),result:{version:1,outcome:"accepted"}});function Bv(e={}){return{id:"interaction-connection-intent-default",companyId:Lr.companyId,issueId:Lr.issueId,kind:"connection_intent",title:"Connect Notion",summary:"Researcher needs this connection to continue.",status:"pending",continuationPolicy:"wake_assignee",createdByAgentId:"11111111-1111-4111-8111-111111111111",createdByUserId:null,resolvedByAgentId:null,resolvedByUserId:null,addresseeUserId:Lr.currentUserId,createdAt:new Date("2026-04-20T15:08:00.000Z"),updatedAt:new Date("2026-04-20T15:08:00.000Z"),resolvedAt:null,payload:{version:1,serviceSlug:"notion",serviceName:"Notion",serviceLogoUrl:null,requestingAgentId:"11111111-1111-4111-8111-111111111111",requestingAgentName:"Researcher",phase:"requested"},result:null,resolverPolicy:"human_only",requestedResolverPolicy:"human_only",effectiveResolverPolicy:"human_only",resolverPolicyProvenance:"explicit",effectiveResolverPolicySource:"governed_action",legacyResolverPolicyAliases:{requested:"board_only",effective:"board_only"},...e}}r(Bv,"createConnectionIntentInteraction");var T6t=Bv(),E6t=Bv({id:"interaction-connection-intent-retry",payload:{version:1,serviceSlug:"notion",serviceName:"Notion",serviceLogoUrl:null,requestingAgentId:"11111111-1111-4111-8111-111111111111",requestingAgentName:"Researcher",phase:"needs_retry"}}),v7t=Bv({id:"interaction-connection-intent-authorizing",payload:{version:1,serviceSlug:"notion",serviceName:"Notion",serviceLogoUrl:null,requestingAgentId:"11111111-1111-4111-8111-111111111111",requestingAgentName:"Researcher",phase:"authorizing"}}),P6t=Bv({id:"interaction-connection-intent-connected",status:"accepted",result:{version:1,outcome:"connected",connectionId:"22222222-2222-4222-8222-222222222222"},resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:12:00.000Z")}),y7t=Bv({id:"interaction-connection-intent-declined",status:"rejected",result:{version:1,outcome:"declined",reason:"Not right now"},resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:12:00.000Z")}),j7t=Bv({id:"interaction-connection-intent-superseded",status:"expired",result:{version:1,outcome:"superseded"},resolvedAt:new Date("2026-04-20T15:12:00.000Z")}),w7t=Bv({id:"interaction-connection-intent-expired",status:"expired",result:{version:1,outcome:"expired"},resolvedAt:new Date("2026-04-20T15:12:00.000Z")}),N7t=X1({id:"interaction-secret-proposal-executed",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:03.000Z"),result:{version:1,outcome:"accepted",secretProposal:{version:1,status:"executed",updatedAt:"2026-04-20T15:02:03.000Z"}}}),k7t=X1({id:"interaction-secret-proposal-failed",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:03.000Z"),result:{version:1,outcome:"accepted",secretProposal:{version:1,status:"failed",errorCode:"binding_snapshot_stale",updatedAt:"2026-04-20T15:02:03.000Z"}}}),S7t=X1({id:"interaction-secret-proposal-rejected",status:"rejected",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:00.000Z"),result:{version:1,outcome:"rejected",reason:"Use the project-scoped credential instead.",secretProposal:{version:1,status:"rejected",updatedAt:"2026-04-20T15:02:00.000Z"}}}),C7t=X1({id:"interaction-secret-proposal-expired",status:"expired",resolvedAt:new Date("2026-05-04T15:02:00.000Z"),updatedAt:new Date("2026-05-04T15:02:00.000Z"),secretProposal:{expiresAt:"2026-05-04T15:02:00.000Z"},result:{version:1,outcome:"superseded_by_newer_request",secretProposal:{version:1,status:"expired",updatedAt:"2026-05-04T15:02:00.000Z"}}}),_7t=al({id:"interaction-confirmation-expired-comment",status:"expired",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T14:38:00.000Z"),updatedAt:new Date("2026-04-20T14:38:00.000Z"),result:{version:1,outcome:"superseded_by_comment",commentId:"22222222-2222-4222-8222-222222222222"}}),I7t=al({id:"interaction-confirmation-expired-target",status:"expired",resolvedByAgentId:"agent-codex",resolvedAt:new Date("2026-04-20T14:40:00.000Z"),updatedAt:new Date("2026-04-20T14:40:00.000Z"),payload:{version:1,prompt:"Approve the plan and let the responsible start implementation?",acceptLabel:"Approve plan",rejectLabel:"Request revisions",rejectRequiresReason:!0,target:{type:"issue_document",issueId:Lr.issueId,key:"plan",revisionId:"44444444-4444-4444-8444-444444444444",revisionNumber:4}},result:{version:1,outcome:"stale_target",staleTarget:{type:"issue_document",issueId:Lr.issueId,key:"plan",revisionId:"11111111-1111-4111-8111-111111111111",revisionNumber:3}}}),A7t=al({id:"interaction-confirmation-failed",status:"failed",updatedAt:new Date("2026-04-20T14:42:00.000Z")}),R7t=al({id:"interaction-confirmation-agent-addressed",title:"Confirm the deploy window with the release agent",summary:"Directed to the release agent, who owns this response without waiting on the board.",addresseeAgentId:"agent-codex"}),T7t=al({id:"interaction-confirmation-not-creator",title:"Independent review of the migration plan",summary:"Asked for a second pair of eyes, so the agent that wrote the plan cannot approve it.",requestedResolverPolicy:"not_creator"}),E7t=al({id:"interaction-confirmation-human-only",title:"Approve the customer-facing announcement",summary:"Reserved for a human on the board because it commits the organization publicly.",requestedResolverPolicy:"human_only"}),P7t=al({id:"interaction-confirmation-company-capped",title:"Confirm the data retention change",summary:"Asked for an open audience; the organization caps this kind at a human decision.",requestedResolverPolicy:"anyone",effectiveResolverPolicy:"human_only",effectiveResolverPolicySource:"company_cap"}),M7t=al({id:"interaction-confirmation-legacy-restricted",title:"Confirm the archived cleanup batch",summary:"Created before Anyone became the default, so it stays restricted until re-created.",requestedResolverPolicy:"not_creator",resolverPolicyProvenance:"legacy_inherited_restriction"}),D7t=al({id:"interaction-confirmation-agent-resolved",title:"Approved by the release agent",status:"accepted",createdByAgentId:"agent-codex",resolvedByAgentId:"agent-codex",resolvedByRunId:"run-agent-resolve-1",resolvedAt:new Date("2026-04-20T15:05:00.000Z"),updatedAt:new Date("2026-04-20T15:05:00.000Z"),result:{version:1,outcome:"accepted"}}),L7t=al({id:"interaction-confirmation-withdrawn",title:"Withdrawn: approve the plan",status:"cancelled",createdByAgentId:"agent-codex",resolvedByAgentId:"agent-codex",resolvedByRunId:"run-agent-withdraw-1",resolvedAt:new Date("2026-04-20T15:10:00.000Z"),updatedAt:new Date("2026-04-20T15:10:00.000Z"),result:{version:1,outcome:"withdrawn",reason:"Plan superseded by a newer revision; no board decision needed."}}),$7t=al({id:"interaction-confirmation-issue-closed",title:"Expired: confirm the migration cutover",status:"expired",resolvedAt:new Date(2026,3,20,15,12,0,0),updatedAt:new Date(2026,3,20,15,12,0,0),result:{version:1,outcome:"issue_closed",reason:"Issue was closed before the confirmation was resolved."}}),O7t=Ov({}),F7t=Ov({id:"interaction-checkbox-bounded",title:"Pick the regions to deploy first",summary:"Choose between two and three regions for the Phase 1 rollout.",payload:{version:1,prompt:"Which regions should we deploy to initially?",detailsMarkdown:"Select at least 2 and at most 3 regions.",options:[{id:"us-west",label:"US West (Oregon)",description:"Lowest latency for our primary user base."},{id:"us-east",label:"US East (Virginia)",description:"Redundancy and east coast coverage."},{id:"eu-west",label:"EU West (Ireland)",description:"GDPR compliance and European users."},{id:"ap-southeast",label:"AP Southeast (Singapore)",description:"Asia-Pacific expansion."}],defaultSelectedOptionIds:["us-west","us-east"],minSelected:2,maxSelected:3,acceptLabel:"Confirm regions",rejectLabel:"Reconsider",rejectRequiresReason:!0,rejectReasonLabel:"What should change about the region set?"}}),B7t=Ov({id:"interaction-checkbox-accepted",status:"accepted",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T14:49:00.000Z"),updatedAt:new Date("2026-04-20T14:49:00.000Z"),result:{version:1,outcome:"accepted",selectedOptionIds:["draft-march-report","draft-spec-v1"]}}),qCe=Array.from({length:100},(e,s)=>{const n=s+1;return{id:`record-${n}`,label:`Customer record #${n}`,description:n%4===0?"Flagged as a possible duplicate during the last import.":void 0}}),M6t=Ov({id:"interaction-checkbox-many",title:"Select the customer records to archive",summary:"The cleanup job found 100 stale customer records. Confirm which ones to archive.",payload:{version:1,prompt:"Check every customer record you want archived.",detailsMarkdown:"The list scrolls. Use Select all / Clear selection to move quickly.",options:qCe,defaultSelectedOptionIds:[],minSelected:0,maxSelected:null,acceptLabel:"Archive selected",rejectLabel:"Reject",rejectRequiresReason:!1}}),q7t=Ov({id:"interaction-checkbox-many-accepted",status:"accepted",title:"Select the customer records to archive",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T14:52:00.000Z"),updatedAt:new Date("2026-04-20T14:52:00.000Z"),payload:M6t.payload,result:{version:1,outcome:"accepted",selectedOptionIds:qCe.slice(0,42).map(e=>e.id)}}),z7t=Ov({id:"interaction-checkbox-rejected",status:"rejected",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T14:50:00.000Z"),updatedAt:new Date("2026-04-20T14:50:00.000Z"),result:{version:1,outcome:"rejected",reason:"Don't delete anything yet — let me confirm with the data owner first."}}),U7t=Ov({id:"interaction-checkbox-stale",status:"expired",resolvedByAgentId:"agent-codex",resolvedAt:new Date("2026-04-20T14:51:00.000Z"),updatedAt:new Date("2026-04-20T14:51:00.000Z"),payload:{version:1,prompt:"Check the draft documents you want me to delete.",acceptLabel:"Delete selected",rejectLabel:"Reject",options:[{id:"draft-march-report",label:"Old draft report"},{id:"draft-spec-v1",label:"Spec v1 (superseded)"}],target:{type:"issue_document",issueId:Lr.issueId,key:"plan",revisionId:"44444444-4444-4444-8444-444444444444",revisionNumber:4}},result:{version:1,outcome:"stale_target",staleTarget:{type:"issue_document",issueId:Lr.issueId,key:"plan",revisionId:"11111111-1111-4111-8111-111111111111",revisionNumber:3}}});function Z1(e){return{id:"interaction-verdicts-default",companyId:Lr.companyId,issueId:Lr.issueId,kind:"request_item_verdicts",title:"Review 5 blog posts",summary:"This task drafted five blog posts. Approve the ones that are ready and reject the rest with a reason — each decision fans out on its own.",status:"pending",continuationPolicy:"wake_assignee",createdByAgentId:"agent-codex",createdByUserId:null,resolvedByAgentId:null,resolvedByUserId:null,createdAt:new Date("2026-04-20T15:02:00.000Z"),updatedAt:new Date("2026-04-20T15:02:00.000Z"),resolvedAt:null,payload:{version:1,prompt:"Review the 5 blog posts this task drafted.",detailsMarkdown:"Each approved post publishes immediately; rejected posts go back for a revision pass with your reason attached.",items:[{id:"post-spring-recap",label:"Spring launch recap",description:"820 words · product marketing",previewMarkdown:"**Spring launch recap** — a warm retrospective on the Q1 launch and what shipped.",href:"/PAP/issues/PAP-9001"},{id:"post-changelog-digest",label:"Monthly changelog digest",description:"540 words · engineering",previewMarkdown:"A tidy digest of the month's shipped changes, grouped by area.",href:"/PAP/issues/PAP-9002"},{id:"post-founder-note",label:"Founder's note on reliability",description:"1,100 words · leadership",previewMarkdown:"A candid note on the reliability push and the road ahead.",href:"/PAP/issues/PAP-9003"},{id:"post-customer-story",label:"Customer story: Northwind",description:"760 words · customer marketing",previewMarkdown:"How Northwind cut review time in half with the new workflow.",href:"/PAP/issues/PAP-9004"},{id:"post-hiring-push",label:"We're hiring: platform engineers",description:"420 words · recruiting",previewMarkdown:"An open call for platform engineers to join the team.",href:"/PAP/issues/PAP-9005"}],verdicts:["approve","reject"],requireReasonOn:["reject"],reasonLabel:"Why reject?",allowBulkApprove:!0,supersedeOnUserComment:!0},result:null,...e,...J1(e)}}r(Z1,"createRequestItemVerdictsInteraction");var K7t=Z1({}),V7t=Z1({id:"interaction-verdicts-partial",updatedAt:new Date("2026-04-20T15:08:00.000Z"),result:{version:1,outcome:"resolved",complete:!1,items:[{id:"post-spring-recap",verdict:"approve",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")},{id:"post-changelog-digest",verdict:"reject",reason:"Tone is off-brand — too dry. Warm it up and re-submit.",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")}]}}),W7t=Z1({id:"interaction-verdicts-complete",status:"answered",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:14:00.000Z"),updatedAt:new Date("2026-04-20T15:14:00.000Z"),result:{version:1,outcome:"resolved",complete:!0,items:[{id:"post-spring-recap",verdict:"approve",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")},{id:"post-changelog-digest",verdict:"reject",reason:"Tone is off-brand — too dry. Warm it up and re-submit.",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")},{id:"post-founder-note",verdict:"approve",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:14:00.000Z")},{id:"post-customer-story",verdict:"approve",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:14:00.000Z")},{id:"post-hiring-push",verdict:"reject",reason:"Hold the recruiting post until the req is approved.",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:14:00.000Z")}]}}),H7t=Z1({id:"interaction-verdicts-superseded",status:"expired",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:16:00.000Z"),updatedAt:new Date("2026-04-20T15:16:00.000Z"),result:{version:1,outcome:"superseded_by_comment",complete:!1,commentId:"33333333-3333-4333-8333-333333333333",items:[{id:"post-spring-recap",verdict:"approve",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")},{id:"post-changelog-digest",verdict:"reject",reason:"Tone is off-brand — too dry. Warm it up and re-submit.",resolvedByUserId:Lr.currentUserId,resolvedAt:new Date("2026-04-20T15:08:00.000Z")}]}}),D6t=Array.from({length:24},(e,s)=>{const n=s+1;return{id:`draft-post-${n}`,label:`Draft post #${n}`,description:`${300+n*17} words · auto-generated series`}}),Q7t=Z1({id:"interaction-verdicts-many",title:"Review 24 generated posts",summary:"A batch-generation task produced 24 posts. Decide them in passes; the card stays until all are decided.",payload:{version:1,prompt:"Review the 24 posts this batch produced.",detailsMarkdown:"The expanded list scrolls. Approve all to accept the batch, or decide item by item.",items:D6t,verdicts:["approve","reject"],requireReasonOn:["reject"],reasonLabel:"Why reject?",allowBulkApprove:!0,supersedeOnUserComment:!0}}),G7t=[hoe({id:"comment-thread-board",body:"Pressure-test first-class issue-thread interactions before we touch persistence. I want to see the cards in the real feed, not in a disconnected mock.",createdAt:new Date("2026-04-20T14:02:00.000Z"),updatedAt:new Date("2026-04-20T14:02:00.000Z")}),hoe({id:"comment-thread-agent",authorAgentId:"agent-codex",authorUserId:null,body:"I found the existing issue chat surface and I am adding prototype-only interaction records so the Storybook review can happen before persistence work.",createdAt:new Date("2026-04-20T14:09:00.000Z"),updatedAt:new Date("2026-04-20T14:09:00.000Z"),runId:"run-thread-interaction",runAgentId:"agent-codex"})],Y7t=[{id:"event-thread-checkout",createdAt:new Date("2026-04-20T14:01:00.000Z"),actorType:"user",actorId:Lr.currentUserId,statusChange:{from:"todo",to:"in_progress"}}],L6t=new Set(["local_path","agent_package"]);function z3(e){return L6t.has(e.type)?"unsupported_in_ui":e.pinned?"ok":"unpinned"}r(z3,"sourceWarningCode");function $6t(e){let s="safe";for(const n of e.sourceRefs){const a=z3(n);if(a==="unsupported_in_ui")return"blocked";a==="unpinned"&&(s="has_warnings")}return s}r($6t,"teamRisk");function O6t(e){return e.counts.localSkills+e.counts.catalogSkills+e.counts.externalSkillSources}r(O6t,"skillCount");function poe(e){return e.replace(/[-_/]+/g," ").replace(/\b\w/g,s=>s.toUpperCase()).trim()}r(poe,"titleCase");var F6t={markdown_only:{label:"Markdown only",tip:"Contains only markdown and references. No executable content.",tone:"text-emerald-600 dark:text-emerald-300 border-emerald-500/30",Icon:Ai},assets:{label:"Assets",tip:"Includes static assets (images, fixtures). No executable content.",tone:"text-emerald-600 dark:text-emerald-300 border-emerald-500/30",Icon:Ai},scripts_executables:{label:"Scripts",tip:"Includes executable scripts that were security-reviewed before bundling.",tone:"text-amber-600 dark:text-amber-300 border-amber-500/30",Icon:Is},external_sources:{label:"External sources",tip:"References external sources resolved at install time.",tone:"text-amber-600 dark:text-amber-300 border-amber-500/30",Icon:Is}};function zCe({level:e,iconOnly:s=!1}){const n=F6t[e],{Icon:a}=n;return(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsxs)(dt,{variant:"outline",className:U("px-1.5 text-(length:--text-micro)",n.tone),children:[(0,t.jsx)(a,{className:"h-3 w-3"}),!s&&n.label]})}),(0,t.jsx)(Kn,{children:n.tip})]})}r(zCe,"TrustChip");function UCe(e){switch(e){case"github":return kd;case"url":return nc;case"local_path":return qc;case"agent_package":return Eh;case"skills_sh":return Bl;default:return nc}}r(UCe,"sourceKindIcon");function B6t({team:e}){const s=new Set(e.rootAgentSlugs),n=e.agentSlugs.filter(i=>!s.has(i)),a=e.rootAgentSlugs.length>0;return(0,t.jsx)("div",{className:"max-h-72 overflow-auto rounded-md border border-border",children:(0,t.jsxs)("ul",{className:"divide-y divide-border/60",children:[e.rootAgentSlugs.map(i=>(0,t.jsxs)("li",{className:U("flex items-center gap-2 px-3 py-2 text-sm",a&&"border-l-2 border-amber-500/50"),children:[(0,t.jsx)(JAe,{className:"h-3.5 w-3.5 text-amber-500"}),(0,t.jsx)("span",{className:"font-medium",children:poe(i)}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"root agent"})]},i)),n.map(i=>(0,t.jsxs)("li",{className:"flex items-center gap-2 px-3 py-2 pl-7 text-sm",children:[(0,t.jsx)(gj,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{children:poe(i)})]},i)),e.agentSlugs.length===0&&(0,t.jsx)("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No agents in this team."})]})})}r(B6t,"TeamHierarchyPreview");function q6t({children:e}){return(0,t.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e})}r(q6t,"SectionHeader");function z6t({skills:e}){return e.length===0?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No required skills."}):(0,t.jsx)("ul",{className:"space-y-1",children:e.map(s=>(0,t.jsxs)("li",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm",children:[(0,t.jsx)(Bl,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-mono text-xs",children:s.ref}),(0,t.jsx)(dt,{variant:"outline",className:"ml-auto text-(length:--text-nano)",children:s.type}),s.resolved?(0,t.jsx)(dt,{variant:"outline",className:"text-(length:--text-nano) text-emerald-600 dark:text-emerald-300 border-emerald-500/30",children:"resolved"}):(0,t.jsx)(dt,{variant:"outline",className:"text-(length:--text-nano) text-amber-600 dark:text-amber-300 border-amber-500/30",children:"external"})]},`${s.type}:${s.ref}`))})}r(z6t,"RequiredSkillsList");function U6t({inputs:e}){return e.length===0?null:(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(q6t,{children:"Secrets & env inputs"}),(0,t.jsx)("ul",{className:"space-y-1",children:e.map(s=>(0,t.jsxs)("li",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm",children:[(0,t.jsx)(ji,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-mono text-xs uppercase tracking-wide",children:s.key}),(0,t.jsx)(dt,{variant:"outline",className:U("ml-auto text-(length:--text-nano)",s.kind==="secret"?"text-rose-600 dark:text-rose-300 border-rose-500/30":"text-muted-foreground"),children:s.kind}),s.requirement==="required"&&(0,t.jsx)(dt,{variant:"outline",className:"text-(length:--text-nano)",children:"required"})]},s.key))})]})}r(U6t,"EnvInputsList");function K6t({sources:e}){const s=e.filter(i=>i.type!=="include"),[n,a]=(0,m.useState)(!1);return s.length===0?null:(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("button",{type:"button",onClick:r(()=>a(i=>!i),"onClick"),className:"flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[n?(0,t.jsx)(en,{className:"h-3 w-3"}):(0,t.jsx)(mn,{className:"h-3 w-3"}),"External sources · ",s.length]}),n&&(0,t.jsx)("ul",{className:"divide-y divide-border rounded-md border border-border",children:s.map(i=>{const o=UCe(i.type),l=z3(i);return(0,t.jsxs)("li",{className:"flex items-center gap-2 px-3 py-2 text-sm",children:[(0,t.jsx)(o,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-mono text-xs truncate",children:i.ref}),(0,t.jsxs)("span",{className:"ml-auto text-(length:--text-micro)",children:[l==="ok"&&(0,t.jsx)("span",{className:"text-emerald-600 dark:text-emerald-300",children:"Pinned"}),l==="unpinned"&&(0,t.jsx)("span",{className:"text-amber-600 dark:text-amber-300",children:"Unpinned"}),l==="unsupported_in_ui"&&(0,t.jsx)("span",{className:"text-rose-600 dark:text-rose-300",children:"Unsupported in browser install"})]})]},`${i.type}:${i.ref}`)})})]})}r(K6t,"ExternalSourcesList");function V6t({team:e,allowExternalSources:s,allowUnpinnedOptionalSources:n,allowLocalPathSources:a,onChange:i}){const o=e.sourceRefs.filter(c=>c.type!=="include"),l=o.some(c=>z3(c)==="unsupported_in_ui");return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{role:"alert",className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-sm text-amber-700 dark:text-amber-300",children:["This team references ",o.length," external source",o.length===1?"":"s",". Review each one and decide what to allow before continuing."]}),(0,t.jsx)("ul",{className:"divide-y divide-border rounded-md border border-border",children:o.map(c=>{const d=UCe(c.type),u=z3(c);return(0,t.jsxs)("li",{className:"flex items-center gap-2 px-3 py-2.5 text-sm",children:[(0,t.jsx)(d,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"font-mono text-xs truncate",children:c.ref}),(0,t.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:[u==="ok"&&"pinned",u==="unpinned"&&"unpinned reference",u==="unsupported_in_ui"&&"not installable from the browser"]})]}),(0,t.jsx)(dt,{variant:"outline",className:U("ml-auto text-(length:--text-nano)",u==="unsupported_in_ui"?"text-rose-600 dark:text-rose-300 border-rose-500/30":u==="unpinned"?"text-amber-600 dark:text-amber-300 border-amber-500/30":"text-emerald-600 dark:text-emerald-300 border-emerald-500/30"),children:c.type})]},`${c.type}:${c.ref}`)})}),(0,t.jsxs)("div",{className:"space-y-2.5 rounded-md border border-border p-3",children:[(0,t.jsx)(O$,{label:"Allow external sources",description:"Resolve github/url skill and team sources at install time.",checked:s,onChange:r(c=>i("external",c),"onChange")}),(0,t.jsx)(O$,{label:"Allow unpinned optional sources",description:"Permit optional sources that are not pinned to a ref or checksum.",checked:n,onChange:r(c=>i("unpinned",c),"onChange")}),(0,t.jsx)(O$,{label:"Allow local-path sources",description:"Required for local_path / agent_package sources. Development use only.",checked:a,onChange:r(c=>i("localPath",c),"onChange")})]}),l&&!a&&(0,t.jsx)("p",{className:"text-xs text-rose-600 dark:text-rose-300",children:"This team has local-path sources. Enable “Allow local-path sources” to continue, or install it from the CLI."})]})}r(V6t,"StepSourcePolicy");function O$({label:e,description:s,checked:n,onChange:a}){return(0,t.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:e}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:s})]}),(0,t.jsx)(Ei,{checked:n,onCheckedChange:a})]})}r(O$,"PolicyToggle");var W6t={already_in_package:{label:"Bundled in package",tone:"text-emerald-600 dark:text-emerald-300 border-emerald-500/30"},catalog_install_required:{label:"Will install from catalog",tone:"text-blue-600 dark:text-blue-300 border-blue-500/30"},external_import_required:{label:"Will import from source",tone:"text-amber-600 dark:text-amber-300 border-amber-500/30"},blocked:{label:"Blocked",tone:"text-rose-600 dark:text-rose-300 border-rose-500/30"}};function H6t({team:e,preparations:s}){return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{role:"alert",className:"rounded-md border border-blue-500/30 bg-blue-500/10 px-3 py-2.5 text-sm text-blue-700 dark:text-blue-300",children:"Before agents are imported, the catalog resolves the skills they depend on. This is the resolution plan."}),(0,t.jsx)("ul",{className:"divide-y divide-border rounded-md border border-border",children:(s??e.requiredSkills.map(Q6t)).map(n=>{const a=W6t[n.action];return(0,t.jsxs)("li",{className:"flex items-center gap-2 px-3 py-2.5 text-sm",children:[(0,t.jsx)(Bl,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"font-mono text-xs truncate",children:n.ref}),n.reason&&(0,t.jsx)("p",{className:"text-(length:--text-micro) text-muted-foreground",children:n.reason})]}),(0,t.jsx)(dt,{variant:"outline",className:U("ml-auto text-(length:--text-nano)",a.tone),children:a.label})]},`${n.type}:${n.ref}`)})})]})}r(H6t,"StepSkillPlan");function Q6t(e){return{type:e.type,ref:e.ref,agentSlugs:e.agentSlugs,action:e.type==="catalog"?"catalog_install_required":e.resolved?"already_in_package":"external_import_required",catalogSkillId:e.catalogSkillId??null,catalogSkillKey:e.catalogSkillKey??null,sourceLocator:e.sourceLocator??null,sourceRef:e.sourceRef??null,reason:null}}r(Q6t,"toPreparation");function VA({team:e,selected:s,onSelect:n,installed:a}){const i=$6t(e),o=!!a?.outOfDate;return(0,t.jsxs)("button",{type:"button",onClick:n,className:U("flex w-full flex-col gap-1 border-b border-border/60 px-3 py-2.5 text-left transition-colors hover:bg-accent/30",s&&"bg-accent/40"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(gj,{className:U("h-3.5 w-3.5 text-muted-foreground",e.kind==="optional"&&"opacity-70")}),(0,t.jsx)("span",{className:U("line-clamp-2 text-(length:--text-compact) font-medium",s&&"text-foreground"),children:e.name}),o&&(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)("span",{"aria-label":"Update available",className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full border border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-300",children:(0,t.jsx)(r1,{className:"h-3 w-3"})})}),(0,t.jsx)(Kn,{children:"Update available — installed team is out of date"})]}),i!=="safe"&&(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(Is,{className:U("ml-auto h-3.5 w-3.5",i==="blocked"?"text-rose-500":"text-amber-500")})}),(0,t.jsx)(Kn,{children:"Has external sources"})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-(length:--text-micro) text-muted-foreground",children:[(0,t.jsxs)("span",{children:[e.counts.agents,"a · ",e.counts.projects,"p · ",e.counts.routines,"r · ",O6t(e),"s"]}),(0,t.jsx)(zCe,{level:e.trustLevel,iconOnly:!0})]})]})}r(VA,"TeamRow");function G6t({team:e,selected:s=!1,onSelect:n}){return(0,t.jsxs)("button",{type:"button",onClick:n,"aria-pressed":s,className:U("flex aspect-square w-full flex-col gap-2 rounded-lg border border-border bg-card p-4 text-left transition-colors hover:bg-accent/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",s&&"ring-2 ring-ring"),children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsx)("span",{className:"flex h-8 w-8 items-center justify-center rounded-md border border-border bg-background",children:(0,t.jsx)(gj,{className:"h-4 w-4 text-muted-foreground"})}),e.trustLevel!=="markdown_only"&&(0,t.jsx)(zCe,{level:e.trustLevel,iconOnly:!0})]}),(0,t.jsxs)("div",{className:"space-y-0.5",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold leading-snug",children:e.name}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.counts.agents," agent",e.counts.agents===1?"":"s"," ·"," ",e.counts.projects," project",e.counts.projects===1?"":"s"," ·"," ",e.counts.routines," routine",e.counts.routines===1?"":"s"]})]}),e.description&&(0,t.jsx)("p",{className:"line-clamp-3 text-xs text-muted-foreground",children:e.description}),e.tags.length>0&&(0,t.jsx)("div",{className:"mt-auto flex flex-wrap gap-1",children:e.tags.map(a=>(0,t.jsx)(dt,{variant:"outline",className:"text-(length:--text-nano)",children:a},a))})]})}r(G6t,"TeamCard");var fc={id:"paperclipai:bundled:company-defaults:core-exec-team",key:"paperclipai/bundled/company-defaults/core-exec-team",kind:"bundled",category:"company-defaults",slug:"core-exec-team",name:"Core Exec Team",description:"A starter executive team: a CEO who manages a CTO and a CMO, plus a launch project and a weekly standup routine. Installs ready-to-run agents you can customize.",path:"catalog/bundled/company-defaults/core-exec-team",entrypoint:"TEAM.md",schema:"agentcompanies/v1",defaultInstall:!0,recommendedForCompanyTypes:["company-root"],tags:["exec","starter"],counts:{agents:3,projects:1,tasks:1,routines:1,localSkills:1,catalogSkills:1,externalSkillSources:1},rootAgentSlugs:["ceo"],agentSlugs:["ceo","cto","cmo"],projectSlugs:["launch"],requiredSkills:[{type:"catalog",ref:"engineering/code-review",agentSlugs:["cto"],resolved:!0,catalogSkillKey:"engineering/code-review"},{type:"github",ref:"acme/growth-playbook@v1.2.0",agentSlugs:["cmo"],resolved:!1,sourceRef:"v1.2.0"}],envInputs:[{key:"OPENAI_API_KEY",agentSlug:"cto",projectSlug:null,kind:"secret",requirement:"required"},{key:"DEFAULT_TIMEZONE",agentSlug:null,projectSlug:"launch",kind:"plain",requirement:"optional"}],sourceRefs:[{type:"github",ref:"acme/growth-playbook@v1.2.0",pinned:!0},{type:"url",ref:"https://example.com/policies/brand.md",pinned:!1}],files:[{path:"TEAM.md",kind:"team",sizeBytes:2144,sha256:"a1"},{path:"README.md",kind:"readme",sizeBytes:980,sha256:"a2"},{path:"agents/ceo/AGENTS.md",kind:"agent",sizeBytes:1200,sha256:"a3"},{path:"agents/cto/AGENTS.md",kind:"agent",sizeBytes:1100,sha256:"a4"},{path:"agents/cmo/AGENTS.md",kind:"agent",sizeBytes:1050,sha256:"a5"},{path:"projects/launch/PROJECT.md",kind:"project",sizeBytes:640,sha256:"a6"}],trustLevel:"external_sources",compatibility:"compatible",contentHash:"sha256:deadbeefdeadbeefdeadbeefdeadbeef",packageName:"@tickernelz/paperclip-pro-teams-catalog",packageVersion:"0.1.0"},Y6t={...fc,id:"paperclipai:optional:software-development:platform-pod",key:"paperclipai/optional/software-development/platform-pod",kind:"optional",category:"software-development",slug:"platform-pod",name:"Platform Engineering Pod",description:"An optional platform pod with a tech lead and two engineers.",recommendedForCompanyTypes:[],counts:{...fc.counts,agents:4,routines:2},rootAgentSlugs:["tech-lead"],agentSlugs:["tech-lead","eng-1","eng-2","sre"],trustLevel:"markdown_only",sourceRefs:[]},foe={...fc,id:"paperclipai:optional:research:lab-with-local-source",slug:"lab-with-local-source",name:"Research Lab (local source)",kind:"optional",category:"research",trustLevel:"scripts_executables",sourceRefs:[{type:"url",ref:"https://example.com/unpinned.md",pinned:!1},{type:"local_path",ref:"/Users/dev/skills/secret-sauce",pinned:!1}]},KCe={catalogId:fc.id,catalogKey:fc.key,present:!0,currentContentHash:fc.contentHash,installedOriginHashes:["sha256:0000older0000older0000older"],agentCount:3,outOfDate:!0},J6t={...KCe,installedOriginHashes:[fc.contentHash],outOfDate:!1},X6t=[{type:"catalog",ref:"engineering/code-review",agentSlugs:["cto"],action:"already_in_package",catalogSkillId:"skill-1",catalogSkillKey:"engineering/code-review",sourceLocator:null,sourceRef:null,reason:null},{type:"github",ref:"acme/growth-playbook@v1.2.0",agentSlugs:["cmo"],action:"external_import_required",catalogSkillId:null,catalogSkillKey:null,sourceLocator:"github.com/acme/growth-playbook",sourceRef:"v1.2.0",reason:"Resolved from GitHub at install time"}],xoe=[{...fc,trustLevel:"markdown_only",sourceRefs:[],requiredSkills:[],counts:{...fc.counts,localSkills:0,catalogSkills:0,externalSkillSources:0}},{...fc,id:"paperclipai:bundled:company-defaults:growth-pod",key:"paperclipai/bundled/company-defaults/growth-pod",slug:"growth-pod",name:"Growth Pod",description:"A lean growth squad: a head of growth managing a content marketer and a data analyst, wired to a launch project and a weekly metrics routine.",tags:["growth","marketing","starter"],counts:{agents:3,projects:1,tasks:0,routines:1,localSkills:0,catalogSkills:0,externalSkillSources:0},rootAgentSlugs:["head-of-growth"],agentSlugs:["head-of-growth","content-marketer","data-analyst"],trustLevel:"assets",sourceRefs:[],requiredSkills:[]},{...fc,id:"paperclipai:bundled:company-defaults:support-pod",key:"paperclipai/bundled/company-defaults/support-pod",slug:"support-pod",name:"Support Pod",description:"A two-person support desk with a lead and an agent, plus a triage routine.",tags:["support","ops"],counts:{agents:2,projects:0,tasks:0,routines:1,localSkills:0,catalogSkills:0,externalSkillSources:0},rootAgentSlugs:["support-lead"],agentSlugs:["support-lead","support-agent"],projectSlugs:[],trustLevel:"markdown_only",sourceRefs:[],requiredSkills:[]}];function F6(e,s,n,a,i){const o=`/api/attachments/${s}/content`;return{id:e,companyId:"demo-company",projectId:null,issueId:"demo-issue",executionWorkspaceId:null,runtimeServiceId:null,type:"artifact",provider:"paperclip",externalId:null,title:a,url:null,status:"active",reviewState:"none",isPrimary:!!i.isPrimary,healthStatus:"unknown",summary:null,createdByRunId:null,createdAt:new Date(i.createdAt),updatedAt:new Date(i.createdAt),metadata:{attachmentId:s,contentType:n,byteSize:i.byteSize,contentPath:o,openPath:o,downloadPath:`${o}?download=1`,originalFilename:a}}}r(F6,"sampleOutput");var Z6t=[F6("wp-vid","aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa","video/mp4","q3-summary.mp4",{byteSize:19293798,isPrimary:!0,createdAt:"2026-05-30T12:00:00Z"}),F6("wp-pdf","bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb","application/pdf","talking-points.pdf",{byteSize:421888,createdAt:"2026-05-30T11:52:00Z"})],ezt=[{...F6("wp-broken","cccccccc-cccc-4ccc-8ccc-cccccccccccc","video/mp4","corrupt-output.mp4",{byteSize:0,isPrimary:!0,createdAt:"2026-05-30T12:01:00Z"}),metadata:{attachmentId:"cccccccc-cccc-4ccc-8ccc-cccccccccccc",contentType:"video/mp4"}}],WA={id:"design-guide-task",identifier:"PAP-427",title:"Reconcile the navigation model across operator surfaces",status:"in_progress",priority:"medium",blockerAttention:!1};function $r({title:e,children:s}){return(0,t.jsxs)("section",{className:"space-y-4",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:e}),(0,t.jsx)(ml,{}),s]})}r($r,"Section");function er({title:e,children:s}){return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h4",{className:"text-sm font-medium",children:e}),s]})}r(er,"SubSection");function tzt(){const[e,s]=(0,m.useState)(xoe[0]?.id??null);return(0,t.jsx)("div",{className:"grid max-w-2xl gap-4 md:grid-cols-2 lg:grid-cols-3",children:xoe.map(n=>(0,t.jsx)(G6t,{team:n,selected:n.id===e,onSelect:r(()=>s(n.id),"onSelect")},n.id))})}r(tzt,"TeamCardShowcase");var goe=[{id:"dg-github",companyId:"dg",scope:"company",ownerUserId:null,userSecretDefinitionId:null,key:"github_token",name:"GITHUB_TOKEN",provider:"local_encrypted",status:"active",managedMode:"paperclip_managed",externalRef:null,providerConfigId:null,providerMetadata:null,latestVersion:3,description:null,lastResolvedAt:null,lastRotatedAt:null,deletedAt:null,createdByAgentId:null,createdByUserId:null,createdAt:new Date("2026-03-01T10:00:00.000Z"),updatedAt:new Date("2026-03-01T10:00:00.000Z")},{id:"dg-db",companyId:"dg",scope:"company",ownerUserId:null,userSecretDefinitionId:null,key:"db_connection",name:"DB_CONNECTION",provider:"local_encrypted",status:"active",managedMode:"paperclip_managed",externalRef:null,providerConfigId:null,providerMetadata:null,latestVersion:3,description:null,lastResolvedAt:null,lastRotatedAt:null,deletedAt:null,createdByAgentId:null,createdByUserId:null,createdAt:new Date("2026-03-01T10:00:00.000Z"),updatedAt:new Date("2026-03-01T10:00:00.000Z")}];function szt(){const[e,s]=(0,m.useState)({NODE_ENV:{type:"plain",value:"production"},GH_TOKEN:{type:"secret_ref",secretId:"dg-github",version:"latest"},DB_URL:{type:"secret_ref",secretId:"dg-db",version:3},STRIPE_API_KEY:{type:"plain",value:"sk-live-51H8xL0aBcDeFgHiJkLmNoPq"}});return(0,t.jsx)("div",{className:"max-w-(--sz-640px) rounded-md border border-border p-4",children:(0,t.jsx)(Zb,{value:e,secrets:goe,onChange:r(n=>s(n??{}),"onChange"),onCreateSecret:r(async n=>({...goe[0],id:`dg-${n}`,key:n,name:n.toUpperCase(),latestVersion:1}),"onCreateSecret")})})}r(szt,"EnvironmentVariablesEditorShowcase");function Yl({name:e,cssVar:s}){return(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-md border border-border shrink-0",style:{backgroundColor:`var(${s})`}}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs font-mono",children:s}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e})]})]})}r(Yl,"Swatch");function nzt(){const[e,s]=(0,m.useState)(!0),[n,a]=(0,m.useState)(null),[i,o]=(0,m.useState)(!0);return(0,t.jsxs)("div",{className:"max-w-xl space-y-4",children:[(0,t.jsx)("div",{className:"w-52 rounded-md border border-border p-1",children:(0,t.jsx)(Nwe,{scope:"subtree",canPause:e,canResume:!e,canCancel:!0,canRestore:!e,onPause:r(()=>s(!1),"onPause"),onResume:r(()=>a("resume"),"onResume"),onCancel:r(()=>a("cancel"),"onCancel"),onRestore:r(()=>a("restore"),"onRestore")})}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:e?"Running: type to switch Stop to Send.":"Paused: resume from the menu."}),(0,t.jsx)(zxe,{item:{id:"design-project",kind:"project_created",projectId:"example-project",name:"Onboarding improvements",description:"Help new teams reach their first useful result.",timestamp:"2026-09-11T00:00:00Z",repositories:[{id:"1",name:"paperclipai/paperclip",url:"https://github.com/paperclipai/paperclip"}]}}),e?null:(0,t.jsx)(Ige,{item:{id:"design-cancelled",kind:"marker",variant:"interrupted",tone:"neutral",label:"Run cancelled",detail:"The run was cancelled before returning an answer.",collapsible:!0}}),(0,t.jsx)(nwe,{pause:e?null:{scope:"subtree",onResume:r(()=>a("resume"),"onResume")},onAdd:r(async()=>{},"onAdd"),workMode:"standard",stopScope:"subtree",onStop:e?async()=>s(!1):void 0}),(0,t.jsx)(kwe,{open:n!==null,onOpenChange:r(l=>{l||a(null)},"onOpenChange"),mode:n??"cancel",scope:"subtree",affectedCount:3,affectedAgentCount:2,loading:!1,pending:!1,valid:!0,wakeAgents:i,onWakeAgentsChange:o,onRetry:r(()=>{},"onRetry"),onApply:r(()=>{s(n!=="cancel"&&i),a(null)},"onApply")})]})}r(nzt,"TaskExecutionControlsExample");function rzt(){const[e,s]=(0,m.useState)("closed");return(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>s("empty"),"onClick"),children:"Empty picker"}),(0,t.jsx)(F,{variant:"outline",onClick:r(()=>s("loading"),"onClick"),children:"Loading picker"}),(0,t.jsx)(F,{variant:"outline",onClick:r(()=>s("error"),"onClick"),children:"Failed picker"}),(0,t.jsx)(xue,{agents:[],open:e!=="closed",onOpenChange:r(n=>{n||s("closed")},"onOpenChange"),onSelect:r(()=>{},"onSelect"),loading:e==="loading",error:e==="error"?new Error("Unavailable"):null,onRetry:r(()=>s("empty"),"onRetry")})]})}r(rzt,"AgentChatPickerExample");function azt(){const[e,s]=(0,m.useState)(0),[n,a]=(0,m.useState)("todo"),[i,o]=(0,m.useState)("medium"),[l,c]=(0,m.useState)("in_progress"),[d,u]=(0,m.useState)(!0),[h,p]=(0,m.useState)(!1),[x,g]=(0,m.useState)("Click to edit this text"),[v,y]=(0,m.useState)("Editable Title"),[j,S]=(0,m.useState)("This is an editable description. Click to edit it — the textarea auto-sizes to fit the content without layout shift."),[w,N]=(0,m.useState)([{key:"status",label:"Status",value:"Active"}]),[_,I]=(0,m.useState)(!1),[C,A]=(0,m.useState)(!1),[R,E]=(0,m.useState)(!1);return(0,t.jsxs)("div",{className:"space-y-10 max-w-4xl",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-xl font-bold",children:"Design Guide"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Every component, style, and pattern used across Paperclip."})]}),(0,t.jsxs)($r,{title:"Component Coverage",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"This page should be updated when new UI primitives or app-level patterns ship."}),(0,t.jsxs)("div",{className:"grid gap-6 md:grid-cols-2",children:[(0,t.jsx)(er,{title:"UI primitives",children:(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:["avatar","badge","breadcrumb","button","card","checkbox","collapsible","command","dialog","dropdown-menu","input","label","popover","resizable-panels","scroll-area","select","separator","sheet","skeleton","tabs","textarea","tooltip"].map(O=>(0,t.jsx)(dt,{variant:"outline",className:"font-mono text-(length:--text-nano)",children:O},O))})}),(0,t.jsx)(er,{title:"App components",children:(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:["StatusBadge","StatusIcon","PriorityIcon","EntityRow","EmptyState","MetricCard","FilterBar","InlineEditor","PageSkeleton","Identity","CommentThread","MarkdownEditor","PropertiesPanel","Sidebar","CommandPalette","EnvironmentVariablesEditor","InlineBanner","BuiltInAgentGate","BuiltInLifecycleChip","CollectionToolbar","IssueRow","ContextualSidebarFrame"].map(O=>(0,t.jsx)(dt,{variant:"ghost",className:"font-mono text-(length:--text-nano)",children:O},O))})})]})]}),(0,t.jsx)($r,{title:"Announcements",children:(0,t.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,t.jsx)(S2,{announcement:g6t,imageSrc:"/announcement-preview.svg",animationSrc:b6t,onDismiss:r(()=>{},"onDismiss")}),(0,t.jsx)(S2,{announcement:$6,imageSrc:"/announcement-preview.svg",onDismiss:r(()=>{},"onDismiss")}),(0,t.jsx)(S2,{announcement:{...$6,image:void 0,secondaryLink:void 0},onDismiss:r(()=>{},"onDismiss")})]})}),(0,t.jsx)($r,{title:"Task Execution Controls",children:(0,t.jsx)(nzt,{})}),(0,t.jsxs)($r,{title:"Task Collection",children:[(0,t.jsx)("p",{className:"max-w-prose text-sm text-muted-foreground",children:"CollectionToolbar owns shared geometry while each page owns its state and behavior. The canonical task row is opt-in during migration: status leads, unread work uses title emphasis, metadata remains stable, and the task identifier trails."}),(0,t.jsx)(lce,{context:(0,t.jsx)("span",{className:"text-sm font-medium",children:"Recent tasks"}),search:(0,t.jsx)(Rt,{"aria-label":"Search task collection example",placeholder:"Search tasks..."}),controls:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Filter"}),actions:(0,t.jsx)(F,{size:"sm",children:"New task"}),feedback:(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"1 task · Updated newest first"})}),(0,t.jsx)("div",{className:"overflow-hidden rounded-lg border border-border",children:(0,t.jsx)(vv,{issue:WA,presentation:"task",unreadState:"visible",metadata:(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Updated 12m ago"}),actions:(0,t.jsx)(F,{variant:"ghost",size:"xs",children:"More"})})})]}),(0,t.jsx)($r,{title:"Theme Toggle",children:(0,t.jsx)(er,{title:"Variants",children:(0,t.jsxs)("div",{className:"flex max-w-sm flex-col items-start gap-3",children:[(0,t.jsx)(Cj,{}),(0,t.jsx)(Cj,{variant:"menu-action"}),(0,t.jsx)(Cj,{variant:"compact-menu-action"})]})})}),(0,t.jsxs)($r,{title:"Colors",children:[(0,t.jsx)(er,{title:"Core",children:(0,t.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[(0,t.jsx)(Yl,{name:"Background",cssVar:"--background"}),(0,t.jsx)(Yl,{name:"Foreground",cssVar:"--foreground"}),(0,t.jsx)(Yl,{name:"Card",cssVar:"--card"}),(0,t.jsx)(Yl,{name:"Primary",cssVar:"--primary"}),(0,t.jsx)(Yl,{name:"Primary foreground",cssVar:"--primary-foreground"}),(0,t.jsx)(Yl,{name:"Secondary",cssVar:"--secondary"}),(0,t.jsx)(Yl,{name:"Muted",cssVar:"--muted"}),(0,t.jsx)(Yl,{name:"Muted foreground",cssVar:"--muted-foreground"}),(0,t.jsx)(Yl,{name:"Accent",cssVar:"--accent"}),(0,t.jsx)(Yl,{name:"Destructive",cssVar:"--destructive"}),(0,t.jsx)(Yl,{name:"Border",cssVar:"--border"}),(0,t.jsx)(Yl,{name:"Ring",cssVar:"--ring"})]})}),(0,t.jsx)(er,{title:"Sidebar",children:(0,t.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[(0,t.jsx)(Yl,{name:"Sidebar",cssVar:"--sidebar"}),(0,t.jsx)(Yl,{name:"Sidebar border",cssVar:"--sidebar-border"})]})}),(0,t.jsx)(er,{title:"Chart",children:(0,t.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[(0,t.jsx)(Yl,{name:"Chart 1",cssVar:"--chart-1"}),(0,t.jsx)(Yl,{name:"Chart 2",cssVar:"--chart-2"}),(0,t.jsx)(Yl,{name:"Chart 3",cssVar:"--chart-3"}),(0,t.jsx)(Yl,{name:"Chart 4",cssVar:"--chart-4"}),(0,t.jsx)(Yl,{name:"Chart 5",cssVar:"--chart-5"})]})})]}),(0,t.jsxs)($r,{title:"Runner activity",children:[(0,t.jsx)(uC,{item:{id:"design-runner-activity",kind:"activity_phase",active:!0,summary:"",interstitial:{id:"design-runner-commentary",kind:"message",author:"agent",text:"I’ll inspect the activity feed and check the layout.",interstitial:!0},items:[{id:"design-runner-read",kind:"tool",name:"read",target:"TaskChatRunnerTurn.tsx",status:"completed",detail:"Found the activity groups."},{id:"design-runner-check",kind:"tool",name:"exec_command",target:"pnpm check:token-gates",status:"in_progress"}]}}),(0,t.jsx)(uC,{item:{id:"design-runner-completed",kind:"activity_phase",active:!1,summary:"",items:[{id:"design-completed-read",kind:"tool",name:"read",target:"TaskChatRunnerTurn.tsx",status:"completed",detail:"Read the activity groups."},{id:"design-completed-check",kind:"tool",name:"exec_command",target:"pnpm check:token-gates",status:"failed",detail:"A token check needs another pass."}]}})]}),(0,t.jsx)($r,{title:"Typography",children:(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-xl font-bold",children:"Page Title — text-xl font-bold"}),(0,t.jsx)("h2",{className:"text-lg font-semibold",children:"Section Title — text-lg font-semibold"}),(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Section Heading — text-sm font-semibold uppercase tracking-wide"}),(0,t.jsx)("p",{className:"text-sm font-medium",children:"Card Title — text-sm font-medium"}),(0,t.jsx)("p",{className:"text-sm font-semibold",children:"Card Title Alt — text-sm font-semibold"}),(0,t.jsx)("p",{className:"text-sm",children:"Body text — text-sm"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Muted description — text-sm text-muted-foreground"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Tiny label — text-xs text-muted-foreground"}),(0,t.jsx)("p",{className:"text-sm font-mono text-muted-foreground",children:"Mono identifier — text-sm font-mono text-muted-foreground"}),(0,t.jsx)("p",{className:"text-2xl font-bold",children:"Large stat — text-2xl font-bold"}),(0,t.jsx)("p",{className:"font-mono text-xs",children:"Log/code text — font-mono text-xs"})]})}),(0,t.jsx)($r,{title:"Radius",children:(0,t.jsx)("div",{className:"flex items-end gap-4 flex-wrap",children:[["sm","var(--radius-sm)"],["md","var(--radius-md)"],["lg","var(--radius-lg)"],["xl","var(--radius-xl)"],["full","9999px"]].map(([O,L])=>(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,t.jsx)("div",{className:"h-12 w-12 bg-primary",style:{borderRadius:L}}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:O})]},O))})}),(0,t.jsxs)($r,{title:"Buttons",children:[(0,t.jsx)(er,{title:"Variants",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(F,{variant:"default",children:"Default"}),(0,t.jsx)(F,{variant:"secondary",children:"Secondary"}),(0,t.jsx)(F,{variant:"outline",children:"Outline"}),(0,t.jsx)(F,{variant:"ghost",children:"Ghost"}),(0,t.jsx)(F,{variant:"destructive",children:"Destructive"}),(0,t.jsx)(F,{variant:"link",children:"Link"})]})}),(0,t.jsx)(er,{title:"Sizes",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(F,{size:"xs",children:"Extra Small"}),(0,t.jsx)(F,{size:"sm",children:"Small"}),(0,t.jsx)(F,{size:"default",children:"Default"}),(0,t.jsx)(F,{size:"lg",children:"Large"})]})}),(0,t.jsx)(er,{title:"Icon buttons",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(F,{variant:"ghost",size:"icon-xs",children:(0,t.jsx)(pa,{})}),(0,t.jsx)(F,{variant:"ghost",size:"icon-sm",children:(0,t.jsx)(pa,{})}),(0,t.jsx)(F,{variant:"outline",size:"icon",children:(0,t.jsx)(pa,{})}),(0,t.jsx)(F,{variant:"outline",size:"icon-lg",children:(0,t.jsx)(pa,{})})]})}),(0,t.jsx)(er,{title:"With icons",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsxs)(F,{children:[(0,t.jsx)(xn,{})," New Issue"]}),(0,t.jsxs)(F,{variant:"outline",children:[(0,t.jsx)(Yj,{})," Upload"]}),(0,t.jsxs)(F,{variant:"destructive",children:[(0,t.jsx)(Na,{})," Delete"]}),(0,t.jsxs)(F,{size:"sm",children:[(0,t.jsx)(xn,{})," Add"]})]})}),(0,t.jsx)(er,{title:"States",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(F,{disabled:!0,children:"Disabled"}),(0,t.jsx)(F,{variant:"outline",disabled:!0,children:"Disabled Outline"})]})})]}),(0,t.jsx)($r,{title:"Badges",children:(0,t.jsx)(er,{title:"Variants",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(dt,{variant:"default",children:"Default"}),(0,t.jsx)(dt,{variant:"secondary",children:"Secondary"}),(0,t.jsx)(dt,{variant:"outline",children:"Outline"}),(0,t.jsx)(dt,{variant:"destructive",children:"Destructive"}),(0,t.jsx)(dt,{variant:"ghost",children:"Ghost"})]})})}),(0,t.jsxs)($r,{title:"Status System",children:[(0,t.jsx)(er,{title:"StatusBadge (all statuses)",children:(0,t.jsx)("div",{className:"flex items-center gap-2 flex-wrap",children:["active","running","paused","idle","archived","planned","achieved","completed","failed","timed_out","succeeded","error","pending_approval","backlog","todo","in_progress","in_review","blocked","done","terminated","cancelled","pending","revision_requested","approved","rejected"].map(O=>(0,t.jsx)(ti,{status:O},O))})}),(0,t.jsx)(er,{title:"IssueStatusBadge (brand chip + glyph — PAP-75)",children:(0,t.jsx)("div",{className:"flex items-center gap-2 flex-wrap",children:["backlog","todo","in_progress","in_review","done","blocked","cancelled"].map(O=>(0,t.jsx)(kp,{status:O},O))})}),(0,t.jsxs)(er,{title:"Idle Slack conversation",children:[(0,t.jsx)(Gi,{status:"in_review",externalConversationState:"waiting",showLabel:!0}),(0,t.jsx)(kp,{status:"in_review",externalConversationState:"waiting"})]}),(0,t.jsxs)(er,{title:"StatusIcon (interactive)",children:[(0,t.jsx)("div",{className:"flex items-center gap-3 flex-wrap",children:["backlog","todo","in_progress","in_review","done","cancelled","blocked"].map(O=>(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(Gi,{status:O}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:O})]},O))}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mt-2",children:[(0,t.jsx)(Gi,{status:n,onChange:a}),(0,t.jsxs)("span",{className:"text-sm",children:["Click the icon to change status (current: ",n,")"]})]})]}),!1,(0,t.jsx)(er,{title:"Agent status dots",children:(0,t.jsx)("div",{className:"flex items-center gap-4 flex-wrap",children:["running","active","paused","error","archived"].map(O=>(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"relative flex h-2.5 w-2.5",children:(0,t.jsx)("span",{className:`inline-flex h-full w-full rounded-full ${S2e[O]??"bg-neutral-400"}`})}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:O})]},O))})}),(0,t.jsx)(er,{title:"Run invocation badges",children:(0,t.jsx)("div",{className:"flex items-center gap-2 flex-wrap",children:[["timer","bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300"],["assignment","bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300"],["on_demand","bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300"],["automation","bg-muted text-muted-foreground"]].map(([O,L])=>(0,t.jsx)(dt,{variant:"ghost",className:`px-1.5 text-(length:--text-nano) ${L}`,children:O},O))})}),(0,t.jsxs)(er,{title:"IssueReferencePill",children:[(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Used wherever a task is referenced — in markdown, the Related Work tab, and activity summaries. Pass ",(0,t.jsx)("code",{className:"font-mono",children:"status"})," to show the target issue's state at a glance. Use ",(0,t.jsx)("code",{className:"font-mono",children:'variant="property"'})," for compact badges with direct navigation. Pass ",(0,t.jsx)("code",{className:"font-mono",children:"onRemove"})," for a separate blocker removal control with reserved space. Use ",(0,t.jsx)("code",{className:"font-mono",children:"strikethrough"}),' for "removed" contexts.']}),(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)(nd,{issue:{id:"demo-1",identifier:"PAP-123",title:"Identifier only — no status yet"}}),(0,t.jsx)(nd,{issue:{id:"demo-2",identifier:"PAP-456",title:"With in_progress status",status:"in_progress"}}),(0,t.jsx)(nd,{issue:{id:"demo-3",identifier:"PAP-789",title:"Done status",status:"done"}}),(0,t.jsx)(nd,{issue:{id:"demo-4",identifier:"PAP-101",title:"Blocked status",status:"blocked"}}),(0,t.jsx)(nd,{onRemove:r(()=>window.alert("Blocker removed"),"onRemove"),issue:{id:"demo-blocker",identifier:"PAP-303",title:"Hover or focus to remove blocker",status:"in_review"}}),(0,t.jsx)(nd,{strikethrough:!0,issue:{id:"demo-5",identifier:"PAP-202",title:"Removed (strikethrough)",status:"todo"}})]})]})]}),(0,t.jsxs)($r,{title:"Agent Capsule",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground max-w-prose",children:['The brand "capsule is the agent" motif. A single agent reads as a tall pill that moves through three states as it comes to life. The online fill uses the live brand agent-gradient tokens (',(0,t.jsx)("code",{className:"font-mono",children:"--agent-Na"})," →"," ",(0,t.jsx)("code",{className:"font-mono",children:"--agent-Nb"}),"); ",(0,t.jsx)("code",{className:"font-mono",children:"prefers-reduced-motion"})," ","skips the liquid rise and pulses and renders the final state."]}),(0,t.jsx)(er,{title:"States",children:(0,t.jsxs)("div",{className:"flex items-end gap-10",children:[(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"slot"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"slot"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"configured"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"configured"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",gradient:5}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"online"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",gradient:5,glow:"blue"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"online · blue glow"})]})]})}),(0,t.jsx)(er,{title:"Sizes",children:(0,t.jsxs)("div",{className:"flex items-end gap-8",children:[(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",size:"sm",gradient:1}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"sm"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",size:"md",gradient:4}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"md"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",size:"lg",gradient:8}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"lg"})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(Kf,{state:"online",size:{width:28,height:96},gradient:6}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"custom px"})]})]})}),(0,t.jsx)(er,{title:"Gradients",children:(0,t.jsx)("div",{className:"flex items-end gap-3 flex-wrap",children:Array.from({length:10},(O,L)=>(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5",children:[(0,t.jsx)(Kf,{state:"online",size:"sm",gradient:L+1}),(0,t.jsx)("span",{className:"text-(length:--text-nano) font-mono text-muted-foreground",children:L+1})]},L))})})]}),(0,t.jsx)($r,{title:"Form Elements",children:(0,t.jsxs)("div",{className:"grid gap-6 md:grid-cols-2",children:[(0,t.jsxs)(er,{title:"Input",children:[(0,t.jsx)(Rt,{placeholder:"Default input"}),(0,t.jsx)(Rt,{placeholder:"Disabled input",disabled:!0,className:"mt-2"})]}),(0,t.jsx)(er,{title:"Textarea",children:(0,t.jsx)(An,{placeholder:"Write something..."})}),(0,t.jsx)(er,{title:"Checkbox & Label",children:(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Ki,{id:"check1",defaultChecked:!0}),(0,t.jsx)(Vs,{htmlFor:"check1",children:"Checked item"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Ki,{id:"check2"}),(0,t.jsx)(Vs,{htmlFor:"check2",children:"Unchecked item"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Ki,{id:"check3",disabled:!0}),(0,t.jsx)(Vs,{htmlFor:"check3",children:"Disabled item"})]})]})}),(0,t.jsx)(er,{title:"Inline Editor",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-1",children:"Title (single-line)"}),(0,t.jsx)(Ah,{value:v,onSave:y,as:"h2",className:"text-xl font-bold"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-1",children:"Body text (single-line)"}),(0,t.jsx)(Ah,{value:x,onSave:g,as:"p",className:"text-sm"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-1",children:"Description (multiline, auto-sizing)"}),(0,t.jsx)(Ah,{value:j,onSave:S,as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0})]})]})})]})}),(0,t.jsx)($r,{title:"Select",children:(0,t.jsxs)("div",{className:"grid gap-6 md:grid-cols-2",children:[(0,t.jsxs)(er,{title:"Default size",children:[(0,t.jsxs)(Ra,{value:l,onValueChange:c,children:[(0,t.jsx)(Aa,{className:"w-full",children:(0,t.jsx)(_a,{placeholder:"Select status"})}),(0,t.jsxs)(Ia,{children:[(0,t.jsx)(yn,{value:"backlog",children:"Backlog"}),(0,t.jsx)(yn,{value:"todo",children:"Todo"}),(0,t.jsx)(yn,{value:"in_progress",children:"In Progress"}),(0,t.jsx)(yn,{value:"in_review",children:"In Review"}),(0,t.jsx)(yn,{value:"done",children:"Done"})]})]}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Current value: ",l]})]}),(0,t.jsx)(er,{title:"Small trigger",children:(0,t.jsxs)(Ra,{defaultValue:"high",children:[(0,t.jsx)(Aa,{size:"sm",className:"w-full",children:(0,t.jsx)(_a,{})}),(0,t.jsxs)(Ia,{children:[(0,t.jsx)(yn,{value:"critical",children:"Critical"}),(0,t.jsx)(yn,{value:"high",children:"High"}),(0,t.jsx)(yn,{value:"medium",children:"Medium"}),(0,t.jsx)(yn,{value:"low",children:"Low"})]})]})})]})}),(0,t.jsx)($r,{title:"Dropdown Menu",children:(0,t.jsxs)(xa,{children:[(0,t.jsx)(fa,{asChild:!0,children:(0,t.jsxs)(F,{variant:"outline",size:"sm",children:["Quick Actions",(0,t.jsx)(en,{className:"h-4 w-4"})]})}),(0,t.jsxs)(ga,{align:"start",className:"w-56",children:[(0,t.jsxs)(ps,{children:[(0,t.jsx)(xs,{className:"h-4 w-4"}),"Mark as done",(0,t.jsx)(d2e,{children:"⌘D"})]}),(0,t.jsxs)(ps,{children:[(0,t.jsx)(Uw,{className:"h-4 w-4"}),"Open docs"]}),(0,t.jsx)(hi,{}),(0,t.jsx)(iz,{checked:d,onCheckedChange:r(O=>u(O===!0),"onCheckedChange"),children:"Watch issue"}),(0,t.jsxs)(ps,{variant:"destructive",children:[(0,t.jsx)(Na,{className:"h-4 w-4"}),"Delete issue"]})]})]})}),(0,t.jsx)($r,{title:"Popover",children:(0,t.jsxs)(sr,{children:[(0,t.jsx)(pr,{asChild:!0,children:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Open Popover"})}),(0,t.jsxs)(Gn,{className:"space-y-2",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Agent heartbeat"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Last run succeeded 24s ago. Next timer run in 9m."}),(0,t.jsx)(F,{size:"xs",children:"Wake now"})]})]})}),(0,t.jsx)($r,{title:"Collapsible",children:(0,t.jsxs)(el,{open:h,onOpenChange:p,className:"space-y-2",children:[(0,t.jsx)(Ul,{asChild:!0,children:(0,t.jsxs)(F,{variant:"outline",size:"sm",children:[h?"Hide":"Show"," advanced filters"]})}),(0,t.jsx)(tl,{className:"rounded-md border border-border p-3",children:(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(Vs,{htmlFor:"owner-filter",children:"Owner"}),(0,t.jsx)(Rt,{id:"owner-filter",placeholder:"Filter by agent name"})]})})]})}),(0,t.jsx)($r,{title:"Sheet",children:(0,t.jsxs)(Gh,{children:[(0,t.jsx)(xce,{asChild:!0,children:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Open Side Panel"})}),(0,t.jsxs)(Qh,{side:"right",children:[(0,t.jsxs)(Fh,{children:[(0,t.jsx)(Wm,{children:"Issue Properties"}),(0,t.jsx)(FS,{children:"Edit metadata without leaving the current page."})]}),(0,t.jsxs)("div",{className:"space-y-4 px-4",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"sheet-title",children:"Title"}),(0,t.jsx)(Rt,{id:"sheet-title",defaultValue:"Improve onboarding docs"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(Vs,{htmlFor:"sheet-description",children:"Description"}),(0,t.jsx)(An,{id:"sheet-description",defaultValue:"Capture setup pitfalls and screenshots."})]})]}),(0,t.jsxs)(fce,{children:[(0,t.jsx)(F,{variant:"outline",children:"Cancel"}),(0,t.jsx)(F,{children:"Save"})]})]})]})}),(0,t.jsx)($r,{title:"Scroll Area",children:(0,t.jsx)(Zf,{className:"h-36 rounded-md border border-border",children:(0,t.jsx)("div",{className:"space-y-2 p-3",children:Array.from({length:12}).map((O,L)=>(0,t.jsxs)("div",{className:"rounded-md border border-border p-2 text-sm",children:["Heartbeat run #",L+1,": completed successfully"]},L))})})}),(0,t.jsx)($r,{title:"Command (CMDK)",children:(0,t.jsx)("div",{className:"rounded-md border border-border",children:(0,t.jsxs)(o5,{children:[(0,t.jsx)(s1,{placeholder:"Type a command or search..."}),(0,t.jsxs)(t1,{children:[(0,t.jsx)(e1,{children:"No results found."}),(0,t.jsxs)(Ou,{heading:"Pages",children:[(0,t.jsxs)(To,{children:[(0,t.jsx)(lx,{className:"h-4 w-4"}),"Dashboard"]}),(0,t.jsxs)(To,{children:[(0,t.jsx)(ad,{className:"h-4 w-4"}),"Issues"]})]}),(0,t.jsx)(Qf,{}),(0,t.jsxs)(Ou,{heading:"Actions",children:[(0,t.jsxs)(To,{children:[(0,t.jsx)(WTe,{className:"h-4 w-4"}),"Open command palette"]}),(0,t.jsxs)(To,{children:[(0,t.jsx)(xn,{className:"h-4 w-4"}),"Create new issue"]})]})]})]})})}),(0,t.jsx)($r,{title:"Breadcrumb",children:(0,t.jsx)(Zz,{children:(0,t.jsxs)(eU,{children:[(0,t.jsx)(oS,{children:(0,t.jsx)(JR,{href:"#",children:"Projects"})}),(0,t.jsx)(XR,{}),(0,t.jsx)(oS,{children:(0,t.jsx)(JR,{href:"#",children:"Paperclip App"})}),(0,t.jsx)(XR,{}),(0,t.jsx)(oS,{children:(0,t.jsx)(QS,{children:"Issue List"})})]})})}),(0,t.jsxs)($r,{title:"Cards",children:[(0,t.jsxs)(er,{title:"Dashboard agent runs",children:[(0,t.jsx)("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:["running","queued","succeeded","failed","timed_out","cancelled","interrupted"].map(O=>(0,t.jsx)(wye,{companyId:"design-guide",run:{id:`design-guide-${O}`,agentId:"design-guide-agent",agentName:"CodexCoder",status:O,adapterType:"codex_local",invocationSource:"on_demand",triggerDetail:"manual",startedAt:null,finishedAt:null,createdAt:"2026-09-11T12:00:00Z",issueId:"design-guide-task"},issue:{identifier:"PAP-559",title:"Recreate this wireframe on pages Paperclip",status:O==="succeeded"?"done":"in_progress"}},O))}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"The dashboard and Live runs page use the same compact cards. In-progress task icons animate across the app, including between runs, to represent task workflow status. Live indicators report active execution. Open a run to view its status and transcript."})]}),(0,t.jsx)(er,{title:"Standard Card",children:(0,t.jsxs)(Gs,{children:[(0,t.jsxs)(Zi,{children:[(0,t.jsx)(uo,{children:"Card Title"}),(0,t.jsx)(jl,{children:"Card description with supporting text."})]}),(0,t.jsx)(za,{children:(0,t.jsx)("p",{className:"text-sm",children:"Card content goes here. This is the main body area."})}),(0,t.jsxs)(U2e,{className:"gap-2",children:[(0,t.jsx)(F,{size:"sm",children:"Action"}),(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Cancel"})]})]})}),(0,t.jsx)(er,{title:"Metric Cards",children:(0,t.jsxs)("div",{className:"grid md:grid-cols-2 xl:grid-cols-4 gap-4",children:[(0,t.jsx)(Sg,{icon:Xi,value:12,label:"Active Agents",description:"+3 this week"}),(0,t.jsx)(Sg,{icon:ad,value:48,label:"Open Issues"}),(0,t.jsx)(Sg,{icon:_h,value:"$1,234",label:"Monthly Cost",description:"Under budget"}),(0,t.jsx)(Sg,{icon:XW,value:"99.9%",label:"Uptime"})]})})]}),(0,t.jsxs)($r,{title:"Tabs",children:[(0,t.jsx)(er,{title:"Default (pill) variant",children:(0,t.jsxs)(Ci,{defaultValue:"overview",children:[(0,t.jsxs)(Bc,{children:[(0,t.jsx)(Ca,{value:"overview",children:"Overview"}),(0,t.jsx)(Ca,{value:"runs",children:"Runs"}),(0,t.jsx)(Ca,{value:"config",children:"Config"}),(0,t.jsx)(Ca,{value:"costs",children:"Costs"})]}),(0,t.jsx)(ia,{value:"overview",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Overview tab content."})}),(0,t.jsx)(ia,{value:"runs",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Runs tab content."})}),(0,t.jsx)(ia,{value:"config",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Config tab content."})}),(0,t.jsx)(ia,{value:"costs",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Costs tab content."})})]})}),(0,t.jsx)(er,{title:"Line variant",children:(0,t.jsxs)(Ci,{defaultValue:"summary",children:[(0,t.jsxs)(Bc,{variant:"line",children:[(0,t.jsx)(Ca,{value:"summary",children:"Summary"}),(0,t.jsx)(Ca,{value:"details",children:"Details"}),(0,t.jsx)(Ca,{value:"comments",children:"Comments"})]}),(0,t.jsx)(ia,{value:"summary",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Summary content with underline tabs."})}),(0,t.jsx)(ia,{value:"details",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Details content."})}),(0,t.jsx)(ia,{value:"comments",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4",children:"Comments content."})})]})})]}),(0,t.jsxs)($r,{title:"Entity Rows",children:[(0,t.jsxs)("div",{className:"border border-border rounded-md",children:[(0,t.jsx)(Xc,{leading:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Gi,{status:"in_progress"}),!1]}),identifier:"PAP-001",title:"Implement authentication flow",subtitle:"Responsible: Agent Alpha",trailing:(0,t.jsx)(kp,{status:"in_progress"}),onClick:r(()=>{},"onClick")}),(0,t.jsx)(Xc,{leading:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Gi,{status:"done"}),!1]}),identifier:"PAP-002",title:"Set up CI/CD pipeline",subtitle:"Completed 2 days ago",trailing:(0,t.jsx)(kp,{status:"done"}),onClick:r(()=>{},"onClick")}),(0,t.jsx)(Xc,{leading:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Gi,{status:"todo"}),!1]}),identifier:"PAP-003",title:"Write API documentation",trailing:(0,t.jsx)(kp,{status:"todo"}),onClick:r(()=>{},"onClick")}),(0,t.jsx)(Xc,{leading:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Gi,{status:"blocked"}),!1]}),identifier:"PAP-004",title:"Deploy to production",subtitle:"Blocked by PAP-001",trailing:(0,t.jsx)(kp,{status:"blocked"}),selected:!0})]}),(0,t.jsx)(er,{title:"Membership action",children:(0,t.jsxs)("div",{className:"border border-border rounded-md",children:[(0,t.jsx)(Xc,{title:"Joined resource",subtitle:"Hover or focus the row to reveal the reserved action slot.",className:"group",trailing:(0,t.jsx)(Ig,{state:"joined",resourceName:"Joined resource",onJoin:r(()=>{},"onJoin"),onLeave:r(()=>{},"onLeave")})}),(0,t.jsx)(Xc,{title:"Left resource",subtitle:"Persistent action with dimmed row content.",className:"group text-foreground/55",trailing:(0,t.jsx)(Ig,{state:"left",resourceName:"Left resource",onJoin:r(()=>{},"onJoin"),onLeave:r(()=>{},"onLeave")})}),(0,t.jsx)(Xc,{title:"Leaving resource",subtitle:"Disabled while the optimistic mutation is pending.",className:"group text-foreground/55",trailing:(0,t.jsx)(Ig,{state:"left",pending:!0,pendingState:"left",resourceName:"Leaving resource",onJoin:r(()=>{},"onJoin"),onLeave:r(()=>{},"onLeave")})}),(0,t.jsx)(Xc,{title:"Joining resource",subtitle:"The target state is visible immediately while the server confirms.",className:"group",trailing:(0,t.jsx)(Ig,{state:"joined",pending:!0,pendingState:"joined",resourceName:"Joining resource",onJoin:r(()=>{},"onJoin"),onLeave:r(()=>{},"onLeave")})})]})})]}),(0,t.jsxs)($r,{title:"Filter Bar",children:[(0,t.jsx)(NK,{filters:w,onRemove:r(O=>N(L=>L.filter($=>$.key!==O)),"onRemove"),onClear:r(()=>N([]),"onClear")}),w.length===0&&(0,t.jsx)(F,{variant:"outline",size:"sm",onClick:r(()=>N([{key:"status",label:"Status",value:"Active"}]),"onClick"),children:"Reset filters"})]}),(0,t.jsxs)($r,{title:"Avatars",children:[(0,t.jsx)(er,{title:"Sizes",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(Yi,{size:"sm",children:(0,t.jsx)(Ji,{children:"SM"})}),(0,t.jsx)(Yi,{children:(0,t.jsx)(Ji,{children:"DF"})}),(0,t.jsx)(Yi,{size:"lg",children:(0,t.jsx)(Ji,{children:"LG"})})]})}),(0,t.jsx)(er,{title:"Group",children:(0,t.jsxs)(gce,{children:[(0,t.jsx)(Yi,{children:(0,t.jsx)(Ji,{children:"A1"})}),(0,t.jsx)(Yi,{children:(0,t.jsx)(Ji,{children:"A2"})}),(0,t.jsx)(Yi,{children:(0,t.jsx)(Ji,{children:"A3"})}),(0,t.jsx)(i2e,{children:"+5"})]})})]}),(0,t.jsx)($r,{title:"App logos",children:(0,t.jsx)(er,{title:"Official marks and runtime fallback",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(bc,{name:"Notion",logoUrl:"/brands/apps/notion.svg",darkLogoUrl:"/brands/apps/notion-dark.svg",size:36}),(0,t.jsx)(bc,{name:"Jira",logoUrl:"/brands/apps/jira.svg",darkLogoUrl:"/brands/apps/jira-dark.svg",size:44}),(0,t.jsx)(bc,{name:"Fallback",logoUrl:"/brands/apps/does-not-exist.svg",size:36})]})})}),(0,t.jsxs)($r,{title:"Agent personas",children:[(0,t.jsx)(er,{title:"Stable palette identities",children:(0,t.jsx)("div",{className:"flex flex-wrap gap-3",children:uIe.map(O=>(0,t.jsx)(hr,{appearance:hIe(O),size:48,label:O},O))})}),(0,t.jsxs)(er,{title:"Onboarding and live character",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Place one live character beside the agent name. Onboarding uses a larger padded frame. Onboarding and agent headers follow the pointer across the page; other placements track within their region. Full-page examples are in Storybook under Agents / Personas / Full pages."}),(0,t.jsxs)("div",{className:"flex gap-4",children:[(0,t.jsx)(oC,{muted:!0,state:"sleepy",motion:"still",size:128}),(0,t.jsx)(oC,{size:128})]})]})]}),(0,t.jsxs)($r,{title:"Human identity",children:[(0,t.jsx)(er,{title:"Sizes",children:(0,t.jsxs)("div",{className:"flex items-center gap-6",children:[(0,t.jsx)(Ll,{name:"Alex Morgan",size:"sm"}),(0,t.jsx)(Ll,{name:"Alex Morgan"}),(0,t.jsx)(Ll,{name:"Alex Morgan",size:"lg"})]})}),(0,t.jsx)(er,{title:"Initials derivation",children:(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,t.jsx)(Ll,{name:"Casey Jordan",size:"sm"}),(0,t.jsx)(Ll,{name:"Alpha",size:"sm"}),(0,t.jsx)(Ll,{name:"Quinn Lee",size:"sm"})]})}),(0,t.jsx)(er,{title:"Custom initials",children:(0,t.jsx)(Ll,{name:"Backend Service",initials:"BS",size:"sm"})})]}),(0,t.jsx)($r,{title:"Tooltips",children:(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Hover me"})}),(0,t.jsx)(Kn,{children:"This is a tooltip"})]}),(0,t.jsxs)(zn,{children:[(0,t.jsx)(Un,{asChild:!0,children:(0,t.jsx)(F,{variant:"ghost",size:"icon-sm",children:(0,t.jsx)(Dd,{})})}),(0,t.jsx)(Kn,{children:"Settings"})]})]})}),(0,t.jsx)($r,{title:"Dialog",children:(0,t.jsxs)(Xs,{children:[(0,t.jsx)(Fw,{asChild:!0,children:(0,t.jsx)(F,{variant:"outline",children:"Open Dialog"})}),(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Dialog Title"}),(0,t.jsx)(Dn,{children:"This is a sample dialog showing the standard layout with header, content, and footer."})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(Vs,{children:"Name"}),(0,t.jsx)(Rt,{placeholder:"Enter a name",className:"mt-1.5"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(Vs,{children:"Description"}),(0,t.jsx)(An,{placeholder:"Describe...",className:"mt-1.5"})]})]}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",children:"Cancel"}),(0,t.jsx)(F,{children:"Save"})]})]})]})}),(0,t.jsx)($r,{title:"Empty State",children:(0,t.jsx)("div",{className:"border border-border rounded-md",children:(0,t.jsx)(In,{icon:Td,message:"No items to show. Create your first one to get started.",action:"Create Item",onAction:r(()=>{},"onAction")})})}),(0,t.jsx)($r,{title:"Progress Bars (Budget)",children:(0,t.jsx)("div",{className:"space-y-3",children:[{label:"Under budget (40%)",pct:40,color:"bg-green-400"},{label:"Warning (75%)",pct:75,color:"bg-yellow-400"},{label:"Over budget (95%)",pct:95,color:"bg-red-400"}].map(({label:O,pct:L,color:$})=>(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:O}),(0,t.jsxs)("span",{className:"text-xs font-mono",children:[L,"%"]})]}),(0,t.jsx)("div",{className:"w-full h-2 bg-muted rounded-full overflow-hidden",children:(0,t.jsx)("div",{className:`h-full rounded-full transition-(--tp-width-background-color) duration-150 ${$}`,style:{width:`${L}%`}})})]},O))})}),(0,t.jsx)($r,{title:"Log Viewer",children:(0,t.jsxs)("div",{className:"bg-neutral-950 rounded-lg p-3 font-mono text-xs max-h-80 overflow-y-auto",children:[(0,t.jsx)("div",{className:"text-foreground",children:"[12:00:01] INFO Agent started successfully"}),(0,t.jsx)("div",{className:"text-foreground",children:"[12:00:02] INFO Processing task PAP-001"}),(0,t.jsx)("div",{className:"text-yellow-400",children:"[12:00:05] WARN Rate limit approaching (80%)"}),(0,t.jsx)("div",{className:"text-foreground",children:"[12:00:08] INFO Task PAP-001 completed"}),(0,t.jsx)("div",{className:"text-red-400",children:"[12:00:12] ERROR Connection timeout to upstream service"}),(0,t.jsx)("div",{className:"text-blue-300",children:"[12:00:12] SYS Retrying connection in 5s..."}),(0,t.jsx)("div",{className:"text-foreground",children:"[12:00:17] INFO Reconnected successfully"}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsxs)("span",{className:"relative flex h-1.5 w-1.5",children:[(0,t.jsx)("span",{className:"absolute inline-flex h-full w-full rounded-full bg-blue-400 animate-pulse"}),(0,t.jsx)("span",{className:"inline-flex h-full w-full rounded-full bg-blue-500"})]}),(0,t.jsx)("span",{className:"text-blue-600 dark:text-blue-400",children:"Live"})]})]})}),(0,t.jsx)($r,{title:"Property Row Pattern",children:(0,t.jsxs)("div",{className:"border border-border rounded-md p-4 space-y-1 max-w-sm",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between py-1.5",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Status"}),(0,t.jsx)(ti,{status:"active"})]}),!1,(0,t.jsxs)("div",{className:"flex items-center justify-between py-1.5",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Responsible"}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(Yi,{size:"sm",children:(0,t.jsx)(Ji,{children:"A"})}),(0,t.jsx)("span",{className:"text-xs",children:"Agent Alpha"})]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between py-1.5",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Created"}),(0,t.jsx)("span",{className:"text-xs",children:"Jan 15, 2025"})]})]})}),(0,t.jsxs)($r,{title:"Navigation Patterns",children:[(0,t.jsxs)(er,{title:"Independent MCP connections",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Zapier, Arcade, Composio and Executor each own a connection. Their controlled setup views share Access → Connect. Tool discovery completes setup. Saved connections reuse the standard Permissions action list and per-action Test dialog. Storybook’s Apps / Connections groups use in-memory provider fixtures."}),(0,t.jsx)(f6t,{})]}),(0,t.jsxs)(er,{title:"Setup wizard",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Shared by connection setup and trigger previews. Setup navigation takes over the section sidebar; each step owns a single footer."}),(0,t.jsxs)("div",{className:"max-w-sm space-y-6",children:[(0,t.jsx)(v5,{inline:!0,labels:["Choose trigger","Configure","Review"],step:e,availableStep:2,onSelect:s}),(0,t.jsx)(Wb,{onSaveExit:r(()=>s(0),"onSaveExit"),children:(0,t.jsx)(F,{onClick:r(()=>s((e+1)%3),"onClick"),children:"Continue"})})]})]}),(0,t.jsx)(er,{title:"Agent chat picker",children:(0,t.jsx)(rzt,{})}),(0,t.jsxs)(er,{title:"Sidebar nav items",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Layout accepts sidebarSections to compose additional SidebarSection groups inside the shared sidebar. Use SidebarNavItem for each row, with sibling action buttons for starring or menus. The Chats section shows starred agents, the earliest-created agent when unstarred, then four recent agents without duplicates. Compose and star controls share a vertical column. Compose appears on hover or keyboard focus and remains visible on touch; starred icons remain visible. The picker searches all company agents by name or role without a subtitle, count, continuation labels, or footer. Task breadcrumbs support leading identity and trailing actions beside the label, including single-item task headers; see the Agent chat Storybook."}),(0,t.jsxs)(Gs,{className:"block w-60 p-3 space-y-0.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium bg-accent text-accent-foreground",children:[(0,t.jsx)(lx,{className:"h-4 w-4"}),"Dashboard"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[(0,t.jsx)(ad,{className:"h-4 w-4"}),"Issues",(0,t.jsx)(dt,{variant:"ghost",className:"ml-auto bg-primary text-primary-foreground px-1.5",children:"12"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[(0,t.jsx)(Xi,{className:"h-4 w-4"}),"Agents"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[(0,t.jsx)(Ad,{className:"h-4 w-4"}),"Projects"]})]})]}),(0,t.jsx)(er,{title:"View toggle",children:(0,t.jsxs)("div",{className:"flex items-center border border-border rounded-md w-fit",children:[(0,t.jsxs)("button",{className:"px-3 py-1.5 text-xs font-medium bg-accent text-foreground rounded-l-md",children:[(0,t.jsx)(lH,{className:"h-3.5 w-3.5 inline mr-1"}),"List"]}),(0,t.jsxs)("button",{className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-accent/50 rounded-r-md",children:[(0,t.jsx)(px,{className:"h-3.5 w-3.5 inline mr-1"}),"Org"]})]})})]}),(0,t.jsx)($r,{title:"Grouped List (Issues pattern)",children:(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 bg-muted/50 rounded-t-md",children:[(0,t.jsx)(Gi,{status:"in_progress"}),(0,t.jsx)("span",{className:"text-sm font-medium",children:"In Progress"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground ml-1",children:"2"})]}),(0,t.jsxs)("div",{className:"border border-border rounded-b-md",children:[(0,t.jsx)(Xc,{leading:void 0,identifier:"PAP-101",title:"Build agent heartbeat system",onClick:r(()=>{},"onClick")}),(0,t.jsx)(Xc,{leading:void 0,identifier:"PAP-102",title:"Add cost tracking dashboard",onClick:r(()=>{},"onClick")})]})]})}),(0,t.jsx)($r,{title:"Comment Thread Pattern",children:(0,t.jsxs)("div",{className:"space-y-3 max-w-2xl",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold",children:"Comments (2)"}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Jan 15, 2025"})]}),(0,t.jsx)("p",{className:"text-sm",children:"Started working on the authentication module. Will need API keys configured."})]}),(0,t.jsxs)("div",{className:"rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Human"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"Jan 16, 2025"})]}),(0,t.jsx)("p",{className:"text-sm",children:"API keys have been added to the vault. Please proceed."})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(An,{placeholder:"Leave a comment...",rows:3}),(0,t.jsx)(F,{size:"sm",children:"Comment"})]})]})}),(0,t.jsx)($r,{title:"Cost Table Pattern",children:(0,t.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,t.jsxs)("table",{className:"w-full text-xs",children:[(0,t.jsx)("thead",{className:"border-b border-border bg-accent/20",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Model"}),(0,t.jsx)("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Tokens"}),(0,t.jsx)("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Cost"})]})}),(0,t.jsxs)("tbody",{children:[(0,t.jsxs)("tr",{className:"border-b border-border",children:[(0,t.jsx)("td",{className:"px-3 py-2",children:"claude-sonnet-4-20250514"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono",children:"1.2M"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono",children:"$18.00"})]}),(0,t.jsxs)("tr",{className:"border-b border-border",children:[(0,t.jsx)("td",{className:"px-3 py-2",children:"claude-haiku-4-20250506"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono",children:"500k"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono",children:"$1.25"})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{className:"px-3 py-2 font-medium",children:"Total"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono",children:"1.7M"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono font-medium",children:"$19.25"})]})]})]})})}),(0,t.jsxs)($r,{title:"Skeletons",children:[(0,t.jsx)(er,{title:"Individual",children:(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(fn,{className:"h-4 w-48"}),(0,t.jsx)(fn,{className:"h-8 w-full max-w-sm"}),(0,t.jsx)(fn,{className:"h-20 w-full"})]})}),(0,t.jsx)(er,{title:"Page Skeleton (list)",children:(0,t.jsx)("div",{className:"border border-border rounded-md p-4",children:(0,t.jsx)(ya,{variant:"list"})})}),(0,t.jsx)(er,{title:"Page Skeleton (detail)",children:(0,t.jsx)("div",{className:"border border-border rounded-md p-4",children:(0,t.jsx)(ya,{variant:"detail"})})})]}),(0,t.jsx)($r,{title:"Separator",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Horizontal"}),(0,t.jsx)(ml,{}),(0,t.jsxs)("div",{className:"flex items-center gap-4 h-8",children:[(0,t.jsx)("span",{className:"text-sm",children:"Left"}),(0,t.jsx)(ml,{orientation:"vertical"}),(0,t.jsx)("span",{className:"text-sm",children:"Right"})]})]})}),(0,t.jsxs)($r,{title:"Team Catalog",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Components from the Team Catalog browse/install surface (",(0,t.jsx)("code",{className:"font-mono text-xs",children:"/teams-catalog"}),"). Fixtures are shared with the Storybook stories."]}),(0,t.jsxs)(er,{title:"TeamRow (browse list)",children:[(0,t.jsxs)("div",{className:"w-(--sz-28rem) rounded-md border border-border",children:[(0,t.jsx)("div",{className:"px-3 py-2 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Bundled · 1"}),(0,t.jsx)(VA,{team:fc,selected:!0,onSelect:r(()=>{},"onSelect")}),(0,t.jsx)("div",{className:"px-3 py-2 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Optional · 2"}),(0,t.jsx)(VA,{team:Y6t,selected:!1,onSelect:r(()=>{},"onSelect")}),(0,t.jsx)("div",{className:"px-3 py-2 text-(length:--text-micro) font-semibold uppercase tracking-wide text-muted-foreground",children:"Installed · 2"}),(0,t.jsx)(VA,{team:fc,selected:!1,onSelect:r(()=>{},"onSelect"),installed:KCe}),(0,t.jsx)(VA,{team:foe,selected:!1,onSelect:r(()=>{},"onSelect"),installed:J6t})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Installed teams collapse under ",(0,t.jsx)("code",{className:"font-mono",children:"INSTALLED · N"}),"; an out-of-date install (server ",(0,t.jsx)("code",{className:"font-mono",children:"originHash"})," ≠ catalog ",(0,t.jsx)("code",{className:"font-mono",children:"contentHash"}),") shows the amber ",(0,t.jsx)("code",{className:"font-mono",children:"↑"})," badge (PAP-10256)."]})]}),(0,t.jsxs)(er,{title:"TeamCard (onboarding grid)",children:[(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Square tile for the onboarding “Pick a starter team” grid. Selected tile gets"," ",(0,t.jsx)("code",{className:"font-mono",children:"ring-2 ring-ring"}),". Drives the"," ",(0,t.jsx)("code",{className:"font-mono",children:"useInstallTeamCatalogEntry"})," simplified flow."]}),(0,t.jsx)(tzt,{})]}),(0,t.jsx)(er,{title:"TeamHierarchyPreview",children:(0,t.jsx)("div",{className:"max-w-md",children:(0,t.jsx)(B6t,{team:fc})})}),(0,t.jsx)(er,{title:"RequiredSkillsList",children:(0,t.jsx)("div",{className:"max-w-xl",children:(0,t.jsx)(z6t,{skills:fc.requiredSkills})})}),(0,t.jsx)(er,{title:"EnvInputsList",children:(0,t.jsx)("div",{className:"max-w-xl",children:(0,t.jsx)(U6t,{inputs:fc.envInputs})})}),(0,t.jsx)(er,{title:"ExternalSourcesList",children:(0,t.jsx)("div",{className:"max-w-xl",children:(0,t.jsx)(K6t,{sources:fc.sourceRefs})})}),(0,t.jsx)(er,{title:"Source policy step (StepSourcePolicy)",children:(0,t.jsx)("div",{className:"max-w-xl rounded-md border border-border p-4",children:(0,t.jsx)(V6t,{team:foe,allowExternalSources:_,allowUnpinnedOptionalSources:C,allowLocalPathSources:R,onChange:r((O,L)=>{O==="external"&&I(L),O==="unpinned"&&A(L),O==="localPath"&&E(L)},"onChange")})})}),(0,t.jsx)(er,{title:"Skill plan step (StepSkillPlan)",children:(0,t.jsx)("div",{className:"max-w-xl rounded-md border border-border p-4",children:(0,t.jsx)(H6t,{team:fc,preparations:X6t})})})]}),(0,t.jsx)($r,{title:"Common Icons (Lucide)",children:(0,t.jsx)("div",{className:"grid grid-cols-4 md:grid-cols-6 gap-4",children:[["Inbox",Td],["ListTodo",lH],["CircleDot",ad],["Hexagon",Ad],["Target",px],["LayoutDashboard",lx],["Bot",Xi],["DollarSign",_h],["History",Nl],["Search",pa],["Plus",xn],["Trash2",Na],["Settings",Dd],["User",xc],["Mail",hce],["Upload",Yj],["Zap",XW]].map(([O,L])=>(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5 p-2",children:[(0,t.jsx)(L,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground font-mono",children:O})]},O))})}),(0,t.jsx)($r,{title:"Keyboard Shortcuts",children:(0,t.jsx)("div",{className:"border border-border rounded-md divide-y divide-border text-sm",children:[["Cmd+K / Ctrl+K","Open Command Palette"],["C","New Issue (outside inputs)"],["[","Toggle Sidebar"],["]","Toggle Properties Panel"],["Cmd+Enter / Ctrl+Enter","Submit markdown comment"]].map(([O,L])=>(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:L}),(0,t.jsx)("kbd",{className:"px-2 py-0.5 text-xs font-mono bg-muted rounded border border-border",children:O})]},O))})}),(0,t.jsxs)($r,{title:"Issue Output Surface",children:[(0,t.jsx)(er,{title:"Multiple outputs (primary video + 'Also produced')",children:(0,t.jsx)(x3,{workProducts:Z6t})}),(0,t.jsx)(er,{title:"Degraded output (invalid / failed attachment metadata)",children:(0,t.jsx)(x3,{workProducts:ezt})}),(0,t.jsx)(er,{title:"Empty state",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"When an issue has produced no artifact work products, the Output section renders nothing at all (no placeholder card)."})})]}),(0,t.jsxs)($r,{title:"Tools & Access",children:[(0,t.jsxs)(er,{title:"EnforcementBanner — default / denied-detected",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)(cb,{companyId:"",forceVariant:"default",recentDenialCount:0}),(0,t.jsx)(cb,{companyId:"",forceVariant:"denied-detected",recentDenialCount:3})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Persistent at the top of the Tools & Access surface. Tints to ",(0,t.jsx)("code",{children:"denied-detected"})," when governed tool calls were denied or failed in the last hour. Observability only — enforcement lives in the tool gateway."]})]}),(0,t.jsxs)(er,{title:"EnforcementBanner — presentational tones (info / warning / error)",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)(cb,{tone:"info",title:"Effective access — server resolved.",body:"This is exactly what the tool gateway will accept. Profile and policy edits reflect within ~5s; the prompt cannot expand it."}),(0,t.jsx)(cb,{tone:"warning",title:"Local stdio is local code execution, not a security sandbox.",body:"A local-stdio slot runs with the orchestrator's privileges. Only bind trusted commands; quarantine anything you would not run yourself."}),(0,t.jsx)(cb,{tone:"error",title:"Runtime failed closed.",body:"The supervisor is restarting (attempt 2/3). The gateway returns runtime-error and the agent does not see partial output."})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Static governance copy with a tone. Used for the PAP-10400 trust-tier banner on Runtime and the effective-access banner on Agent → Tools. Pass ",(0,t.jsx)("code",{children:"title"}),"/",(0,t.jsx)("code",{children:"body"})," and an optional"," ",(0,t.jsx)("code",{children:"icon"}),"."]})]}),(0,t.jsxs)(er,{title:"Action approval card — pending / stale (surfaces 11/12)",children:[(0,t.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,t.jsx)(O6,{toolName:"slack.post_message",risk:"medium",isWrite:!0,binding:{application:"Slack",manifestVersion:"2.4.1",connection:"https://slack.com/api · acme-workspace",catalogSha256:"sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",payloadSha256:"sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"},input:{channel:"#launch",text:"Deploy v2 is live 🎉",unfurl_links:!1},reason:"This tool can write to your workspace, so a human signs off before the agent posts.",policyNumber:7,expiresInLabel:"expires in 23h 51m"}),(0,t.jsx)(O6,{variant:"stale",toolName:"slack.post_message",risk:"medium",isWrite:!0,binding:{application:"Slack",manifestVersion:"2.4.1",connection:"https://slack.com/api · acme-workspace",catalogSha256:"sha256:7d793037a0760186574b0282f2f435e7a4b1b2b0b822cd15d6c15b0f00a0e3f1",previousCatalogSha256:"sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",payloadSha256:"sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"},input:{channel:"#launch",text:"Deploy v2 is live 🎉",unfurl_links:!1},reason:"This tool can write to your workspace, so a human signs off before the agent posts.",policyNumber:7,expiresInLabel:"expires in 18h 02m"})]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Signed payload sha256 + expiry surface on every variant (PAP-10400). The"," ",(0,t.jsx)("code",{children:"stale"})," variant tints the border amber, banners the catalog-hash mismatch, strikes through the previous hash next to the current one, and renders ",(0,t.jsx)("code",{children:"Approve"})," disabled until the request is re-issued."]})]}),(0,t.jsxs)(er,{title:"Action approval card — mobile (390×844, surface 99)",children:[(0,t.jsx)("div",{className:"w-(--sz-390px) max-w-full rounded-xl border border-border bg-background p-3",children:(0,t.jsx)(_6t,{toolName:"slack.post_message",risk:"medium",isWrite:!0,binding:{application:"Slack",manifestVersion:"2.4.1",connection:"https://slack.com/api · acme-workspace",catalogSha256:"sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",payloadSha256:"sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"},input:{channel:"#launch",text:"Deploy v2 is live 🎉"},reason:"This tool can write to your workspace, so a human signs off before the agent posts.",policyNumber:7,expiresInLabel:"expires in 23h 51m"})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Identical content; the three buttons stack full-width in the order Approve / Deny / Edit & re-sign, and the bindings table uses a 70px label column."})]}),(0,t.jsxs)(er,{title:"BindingsTable (reused in the audit row drilldown)",children:[(0,t.jsx)(FCe,{rows:[{label:"Application",value:"Slack · manifest v2.4.1"},{label:"Connection",value:"https://slack.com/api · acme-workspace",mono:!0},{label:"Catalog",value:"sha256:9f86d081…f00a08",mono:!0},{label:"Payload",value:"sha256:2c26b46b…66e7ae",mono:!0}]}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Two-column key/value block with mono values. Lives inside ",(0,t.jsx)("code",{children:"ActionCard"})," and is reused standalone in the audit row drilldown."]})]}),(0,t.jsxs)(er,{title:"Tool-access status keys (StatusBadge)",children:[(0,t.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:["allowed","denied","block","require-approval","redacted","rate-limit","deferred","hidden","quarantined","healthy","degraded","runtime-error","unchecked"].map(O=>(0,t.jsx)(ti,{status:O},O))}),(0,t.jsxs)("p",{className:"mt-2 text-xs text-muted-foreground",children:["Policy decisions, connection/runtime health, and catalog quarantine all route through the canonical"," ",(0,t.jsx)("code",{children:"StatusBadge"})," keys defined in ",(0,t.jsx)("code",{children:"lib/status-colors"}),"."]})]}),(0,t.jsx)(er,{title:"EmptyState (canonical, with description + action)",children:(0,t.jsx)(In,{icon:Td,message:"No connections yet",description:"Add a connection to an application to configure credentials and discover its tools.",action:"New connection",onAction:r(()=>{},"onAction")})})]}),(0,t.jsxs)($r,{title:"Source Repositories",children:[(0,t.jsx)(er,{title:"Empty and disconnected",children:(0,t.jsx)(DO,{selected:[],onChange:r(()=>{},"onChange"),state:"disconnected",onConnect:r(()=>{},"onConnect"),onRetry:r(()=>{},"onRetry")})}),(0,t.jsx)(er,{title:"Selected and searchable",children:(0,t.jsx)(DO,{selected:[{id:"1",fullName:"paperclipai/paperclip",url:"https://github.com/paperclipai/paperclip",connections:["Your GitHub"]}],available:[{id:"2",fullName:"paperclipai/docs",url:"https://github.com/paperclipai/docs",connections:["Company GitHub"]}],onChange:r(()=>{},"onChange"),onConnect:r(()=>{},"onConnect"),onRetry:r(()=>{},"onRetry")})}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading, errors, empty search, mobile, and short viewports are covered in the Project repos Storybook stories."})]}),(0,t.jsxs)($r,{title:"Environment Variables Editor",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Reusable env-var editor (agents, projects, environments, routines). One shared grid, an in-field Text/Secret source switch, a fuzzy secret picker with a pinned “Create secret” item, automatic sensitive-value detection, and inline secret-health warnings. See the Storybook ",(0,t.jsx)("span",{className:"font-mono",children:"Product/Environment Variables Editor"})," stories for all 10 states."]}),(0,t.jsx)(szt,{})]}),(0,t.jsxs)($r,{title:"Tasks created from a task",children:[(0,t.jsx)(er,{title:"Subtasks and created work are independent",children:(0,t.jsx)("div",{className:"max-w-xl",children:(0,t.jsx)(Ok,{subtasks:[WA],createdTasks:[{...WA,projectId:"design-board",project:{id:"design-board",name:"Board UI"}},{...WA,id:"design-followup",identifier:"PAP-428",title:"Write release notes",status:"todo",projectId:null}],projects:[]})})}),(0,t.jsxs)(er,{title:"Empty, loading and failed",children:[(0,t.jsx)(Ok,{subtasks:[],createdTasks:[],projects:[]}),(0,t.jsx)(Ok,{subtasks:[],createdTasks:[],projects:[],isLoading:!0}),(0,t.jsx)(Ok,{subtasks:[],createdTasks:[],projects:[],hasError:!0,onRetry:r(()=>{},"onRetry")})]})]}),(0,t.jsx)($r,{title:"Execution recovery",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Recovery runs in the background. Task lists keep their ordinary status without execution badges. Active transcript headers keep saying Working during automatic recovery. Recovery decisions and attempts belong in the run log; there is no execution status card or reconciliation form."})}),(0,t.jsxs)($r,{title:"Saved provider API keys",children:[(0,t.jsx)(Nj,{options:[{id:"example",label:"Claude API key (Your key)",binding:{type:"user_secret_ref",key:"ANTHROPIC_API_KEY",version:"latest"}}],value:"example",onChange:r(()=>{},"onChange"),loading:!1,error:!1}),(0,t.jsx)(Nj,{options:[],value:"",onChange:r(()=>{},"onChange"),loading:!0,error:!1}),(0,t.jsx)(Nj,{options:[],value:"",onChange:r(()=>{},"onChange"),loading:!1,error:!0})]}),(0,t.jsxs)($r,{title:"Connection Intent",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"The task card is the dialog host for the shared connection setup flow. Provider forms, validation, OAuth, access selection, and completion come from the same feature module as the full-page Apps setup; this card owns only audience, dialog, and task refresh behavior. Pending connections stay in the timeline beside a usable composer. The independently addressable Connections/In-task connections stories cover access, OAuth recovery, narrow layouts, completion, and historical outcomes."}),(0,t.jsxs)("div",{className:"grid gap-4 xl:grid-cols-3",children:[(0,t.jsx)(Hp,{interaction:T6t,currentUserId:Lr.currentUserId}),(0,t.jsx)(Hp,{interaction:E6t,currentUserId:Lr.currentUserId}),(0,t.jsx)(Hp,{interaction:P6t,currentUserId:Lr.currentUserId})]})]}),(0,t.jsxs)($r,{title:"Resizable Panels",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Design-system wrapper over ",(0,t.jsx)("span",{className:"font-mono",children:"react-resizable-panels"})," ","(Skill Studio D2). Drag a handle to resize; panels accept percentage or pixel (",(0,t.jsx)("span",{className:"font-mono",children:'minSize="240px"'}),") constraints and the middle panel is collapsible. Use anywhere a split view is needed."]}),(0,t.jsx)("div",{className:"h-48 max-w-2xl overflow-hidden rounded-md border border-border",children:(0,t.jsxs)(L7,{children:[(0,t.jsx)($b,{id:"a",minSize:"120px",className:"bg-muted/30",children:(0,t.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-muted-foreground",children:"Panel A"})}),(0,t.jsx)(qC,{}),(0,t.jsx)($b,{id:"b",minSize:"120px",collapsible:!0,collapsedSize:"40px",className:"bg-muted/10",children:(0,t.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-muted-foreground",children:"Panel B (collapsible)"})}),(0,t.jsx)(qC,{}),(0,t.jsx)($b,{id:"c",minSize:"120px",className:"bg-muted/30",children:(0,t.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-muted-foreground",children:"Panel C"})})]})})]}),(0,t.jsx)($r,{title:"Webhook URL warnings",children:(0,t.jsx)("div",{className:"space-y-3",children:["http://localhost:3100","https://paperclip.internal","https://paperclip.example-tailnet.ts.net","http://paperclip.example.com","not-a-url"].map(O=>(0,t.jsx)(t7,{url:O},O))})}),(0,t.jsxs)($r,{title:"Inline Banner",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Token-backed full-width notice (",(0,t.jsx)("span",{className:"font-mono",children:"brandBanner"})," tones). Use"," ",(0,t.jsx)("span",{className:"font-mono",children:"info"})," for provenance/context and"," ",(0,t.jsx)("span",{className:"font-mono",children:"warning"})," for paused/attention. Supports an optional bold title and a trailing actions slot. Replaces hand-rolled"," ",(0,t.jsx)("span",{className:"font-mono",children:"bg-yellow-*"}),"/",(0,t.jsx)("span",{className:"font-mono",children:"bg-blue-*"})," ","banners."]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)(ri,{tone:"info",title:"Built-in agent",actions:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Reset to defaults"}),children:["Ships with Paperclip and powers ",(0,t.jsx)("strong",{children:"Briefs"}),". It can be paused but not deleted."]}),(0,t.jsx)(ri,{tone:"warning",title:"Briefs is paused.",actions:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(F,{variant:"ghost",size:"sm",children:"View agent"}),(0,t.jsx)(F,{size:"sm",children:"Resume agent"})]}),children:"Its built-in agent was paused 2 days ago, so new briefs aren't being generated."}),(0,t.jsx)(ri,{tone:"danger",title:"Summary generation failed.",actions:(0,t.jsx)(F,{size:"sm",children:"Retry"}),children:"The linked issue reached a terminal state before a summary was written."}),(0,t.jsx)(ri,{tone:"info",compact:!0,children:"Compact variant for embedding inside dialogs and modals."})]})]}),(0,t.jsxs)($r,{title:"Media artifacts",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Images and videos use gallery tiles. The whole tile opens the task gallery; files and links keep compact, fully clickable rows. Task/Artifact Gallery in Storybook covers playable videos, mixed files, narrow panels, and unavailable previews."}),(0,t.jsxs)("div",{className:"grid max-w-2xl grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,t.jsx)($T,{id:"design-image",title:"Launch artwork",contentPath:"/announcement-preview.svg",contentType:"image/svg+xml",originalFilename:"launch.svg",detail:"Image"}),(0,t.jsx)($T,{id:"design-video",title:"Video preview unavailable",contentPath:"",contentType:"video/mp4",originalFilename:"preview.mp4",detail:"Video"})]})]}),(0,t.jsx)($r,{title:"AI Connections",children:(0,t.jsx)(y6t,{})}),(0,t.jsxs)($r,{title:"Built-in Agent Lifecycle Chips",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["A derived lifecycle chip (amber) for attention states. The lifecycle chip is separate from the agent status vocabulary and only shows for"," ",(0,t.jsx)("span",{className:"font-mono",children:"needs_setup"})," / ",(0,t.jsx)("span",{className:"font-mono",children:"pending_approval"}),"."]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,t.jsx)(vj,{status:"needs_setup"}),(0,t.jsx)(vj,{status:"pending_approval"}),(0,t.jsx)(vj,{status:"needs_setup",compact:!0})]}),(0,t.jsxs)("p",{className:"mt-3 text-sm text-muted-foreground",children:[(0,t.jsx)("span",{className:"font-mono",children:"<BuiltInAgentGate agentKey>"})," composes"," ",(0,t.jsx)("span",{className:"font-mono",children:"PageSkeleton"})," + ",(0,t.jsx)("span",{className:"font-mono",children:"EmptyState"})," ","+ ",(0,t.jsx)("span",{className:"font-mono",children:"InlineBanner"})," to render the loading / setup / pending-approval / paused / ready states of a feature that depends on a built-in agent."]})]})]})}r(azt,"DesignGuide");function izt(e,s){return e?.enableWorktreeRunExecution!==!0?{kind:"off"}:e.worktreeRunExecutionActivatedAt?s?e.worktreeRunExecutionActivationInstanceId!==s?{kind:"fail_closed",reason:"instance_mismatch"}:{kind:"armed",activatedAt:e.worktreeRunExecutionActivatedAt}:{kind:"fail_closed",reason:"missing_instance_id"}:{kind:"fail_closed",reason:"missing_cutoff"}}r(izt,"resolveWorktreeRunExecutionDisplayState");function ozt(e){const s=new Date(e);return Number.isNaN(s.getTime())?e:s.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}r(ozt,"formatActivationTimestamp");function VCe(){return(0,t.jsxs)(dt,{variant:"outline",className:"text-muted-foreground",children:[(0,t.jsx)(Pd,{"aria-hidden":"true"}),"Managed by Paperclip Cloud"]})}r(VCe,"ManagedByCloudBadge");function Co({title:e,description:s,footnote:n,checked:a,onCheckedChange:i,disabled:o,settingKey:l,managed:c,ariaLabel:d}){const{hidden:u}=Ym(),h=c?.managed===!0;return u.has(dle(l))?null:(0,t.jsx)(Gs,{className:"block bg-transparent p-5",children:(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold",children:e}),h?(0,t.jsx)(VCe,{}):null]}),(0,t.jsx)("p",{className:"max-w-2xl text-sm text-muted-foreground",children:s}),n?(0,t.jsx)("p",{className:"max-w-2xl text-xs text-muted-foreground",children:n}):null]}),(0,t.jsx)(Ei,{checked:a,onCheckedChange:r(p=>{h||i(p)},"onCheckedChange"),disabled:o||h,"aria-label":d})]})})}r(Co,"ExperimentalToggleCard");function lzt(){const{setBreadcrumbs:e}=$n(),s=Ht(),{hidden:n}=Ym(),[a,i]=(0,m.useState)(null);(0,m.useEffect)(()=>{e([{label:"Settings",href:"/company/settings"},{label:"Experimental"}])},[e]);const o=ee({queryKey:P.instance.experimentalSettings,queryFn:r(()=>Tr.getExperimental(),"queryFn")}),l=ye({mutationFn:r(async te=>Tr.updateExperimental(te),"mutationFn"),onMutate:r(async te=>{await s.cancelQueries({queryKey:P.instance.experimentalSettings});const J=s.getQueryData(P.instance.experimentalSettings);return J&&s.setQueryData(P.instance.experimentalSettings,{...J,...te}),{previousSettings:J}},"onMutate"),onSuccess:r(async te=>{i(null),s.setQueryData(P.instance.experimentalSettings,te),await Promise.all([s.invalidateQueries({queryKey:P.instance.experimentalSettings}),s.invalidateQueries({queryKey:P.adapters.all}),s.invalidateQueries({queryKey:["built-in-agents"]}),s.invalidateQueries({queryKey:P.health}),s.invalidateQueries({queryKey:["apps"]})])},"onSuccess"),onError:r((te,J,Q)=>{Q?.previousSettings&&s.setQueryData(P.instance.experimentalSettings,Q.previousSettings),i(te instanceof Error?te.message:"Failed to update experimental settings.")},"onError")});if(o.isLoading)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading experimental settings..."});if(o.error)return(0,t.jsx)("div",{className:"text-sm text-destructive",children:o.error instanceof Error?o.error.message:"Failed to load experimental settings."});const c=ZGe(),d=o.data?.managedKeys??{},u=o.data?.enableWorktreeRunExecution===!0,h=d.enableWorktreeRunExecution?.managed===!0,p=izt(o.data,eYe()),x=o.data?.enableEnvironments===!0,g=o.data?.enableNativeRunner===!0,v=o.data?.enableChatConnectors===!0,y=o.data?.enableManagedSandboxOnly===!0,j=o.data?.enableIsolatedWorkspaces===!0,S=o.data?.enableIsolatedWorkspacesByDefault===!0,w=o.data?.enableStreamlinedUi!==!1;o.data?.enableConferenceRoomChat;const N=o.data?.enableClassicTaskInterface===!0,_=o.data?.enableIssuePlanDecompositions===!0,I=o.data?.enableExperimentalFileViewer===!0,C=o.data?.enableExternalObjects===!0,A=o.data?.enableBuiltInAgents===!0,R=o.data?.enableBetaSkills===!0,E=o.data?.enableSummaries===!0,O=o.data?.enableStatusCards===!0,L=d.enableSummaries?.managed===!0,$=d.enableStatusCards?.managed===!0,T=L&&!E,q=$&&O,B=o.data?.enableDecisions===!0,K=o.data?.enableGoalsSidebarLink===!0,z=o.data?.enableCases===!0,D=o.data?.enableServerInfoDebugView===!0,V=o.data?.enablePaperclipDeveloperMode===!0,H=o.data?.enableSimplifiedEnglishInteractions===!0,Z=o.data?.enableFirstTaskPlanProposal===!0,Y=o.data?.enableSmokeLab===!0,ie=o.data?.autoRestartDevServerWhenIdle===!0,se=r(te=>!n.has(dle(te)),"isVisible"),X=c&&se("enableWorktreeRunExecution"),le=X||["autoRestartDevServerWhenIdle","enableManagedSandboxOnly","enablePaperclipDeveloperMode","enableServerInfoDebugView","enableSmokeLab","enableIssuePlanDecompositions"].some(se),oe=se("enableClassicTaskInterface")||se("enableGoalsSidebarLink");return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Gu,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Experimental"})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Opt into features that are still being evaluated before they become default behavior."})]}),(0,t.jsx)("div",{role:"alert",className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(Is,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),(0,t.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"Experimental features may break at any time."}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"These features are opt-in and come with no compatibility guarantees. They may change, break, or be removed without notice. Avoid relying on them for critical or production workflows."})]})]})}),a&&(0,t.jsx)("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:a}),(0,t.jsxs)("section",{className:"space-y-3","aria-labelledby":"experimental-features-heading",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("h2",{id:"experimental-features-heading",className:"text-sm font-semibold",children:"Experimental features"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Optional product features that are still being evaluated."})]}),(0,t.jsx)(Co,{title:"Agent Chat",description:"Talk to each agent in one ongoing conversation. Clarify goals and create tasks for execution.",footnote:"Turning this off preserves conversations and lets active runs finish, but prevents new messages.",checked:o.data?.enableAgentChat??!1,onCheckedChange:r(te=>l.mutate({enableAgentChat:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableAgentChat",managed:d.enableAgentChat,ariaLabel:"Toggle agent chat experimental setting"}),(0,t.jsx)(Co,{title:"Beta skills",description:"Allow agents to pin beta releases of the Paperclip core skill. Disabling this returns every agent to the default live skill without removing saved pins.",checked:R,onCheckedChange:r(te=>l.mutate({enableBetaSkills:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableBetaSkills",managed:d.enableBetaSkills,ariaLabel:"Toggle beta skills experimental setting"}),(0,t.jsx)(Co,{title:"Built-in Agents",description:"Show Paperclip-managed built-in agent surfaces, including built-in roster badges, the Built-in agents tab, and built-in agent setup controls.",checked:A,onCheckedChange:r(te=>l.mutate({enableBuiltInAgents:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableBuiltInAgents",managed:d.enableBuiltInAgents,ariaLabel:"Toggle built-in agents experimental setting"}),(0,t.jsx)(Co,{title:"Cases",description:"Durable work products (blog posts, tweet storms…) that tasks create and iterate on. Adds the Cases tab and the agent case API.",footnote:"Turning Cases off hides the tab and blocks the case API; existing case data is kept.",checked:z,onCheckedChange:r(te=>l.mutate({enableCases:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableCases",managed:d.enableCases,ariaLabel:"Toggle cases experimental setting"}),(0,t.jsx)(Co,{title:"Chat connectors",description:"Connect agents to Slack, GitHub, Discord, Microsoft Teams, and Telegram conversations.",footnote:"Turning this off hides chat setup, channels, and connected-task controls. Existing chat connections keep running. GitHub and other tool connectors stay available.",checked:v,onCheckedChange:r(te=>l.mutate({enableChatConnectors:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableChatConnectors",managed:d.enableChatConnectors,ariaLabel:"Toggle chat connectors experimental setting"}),null,(0,t.jsx)(Co,{title:"Decisions",description:"Show the Decisions item in the main sidebar — the attention home that surfaces the tasks awaiting your input — while the surface is still being evaluated.",checked:B,onCheckedChange:r(te=>l.mutate({enableDecisions:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableDecisions",managed:d.enableDecisions,ariaLabel:"Toggle decisions experimental setting"}),(0,t.jsx)(Co,{title:"Enable Environments",description:"Show environment management in company settings and allow project and agent environment assignment controls.",checked:x,onCheckedChange:r(te=>l.mutate({enableEnvironments:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableEnvironments",managed:d.enableEnvironments,ariaLabel:"Toggle environments experimental setting"}),(0,t.jsx)(Co,{title:"Enable External Objects",description:"Detect external URLs in issues and show resolved status for pull requests, tickets, and other referenced work objects.",checked:C,onCheckedChange:r(te=>l.mutate({enableExternalObjects:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableExternalObjects",managed:d.enableExternalObjects,ariaLabel:"Toggle external objects experimental setting"}),(0,t.jsx)(Co,{title:"Enable Isolated Workspaces",description:"Show execution workspace controls in project configuration and allow isolated workspace behavior for new and existing task runs.",checked:j,onCheckedChange:r(te=>l.mutate({enableIsolatedWorkspaces:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableIsolatedWorkspaces",managed:d.enableIsolatedWorkspaces,ariaLabel:"Toggle isolated workspaces experimental setting"}),(0,t.jsx)(Co,{title:"Experimental File Viewer",description:"Show task detail controls for browsing and previewing workspace files relative to a task.",checked:I,onCheckedChange:r(te=>l.mutate({enableExperimentalFileViewer:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableExperimentalFileViewer",managed:d.enableExperimentalFileViewer,ariaLabel:"Toggle experimental file viewer setting"}),(0,t.jsx)(Co,{title:"First task: propose with a plan document",description:"When the user's first request is a single task, the chief of staff writes a short plan document and a checkbox card instead of a one-card confirmation. Applies to organizations created after the toggle is flipped.",checked:Z,onCheckedChange:r(te=>l.mutate({enableFirstTaskPlanProposal:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableFirstTaskPlanProposal",managed:d.enableFirstTaskPlanProposal,ariaLabel:"Toggle first task plan proposal experimental setting"}),(0,t.jsx)(Co,{title:"MCP aggregators",description:"Connect Zapier, Arcade, Composio Connect, and Executor through their MCP servers.",footnote:"Turning this off hides setup for these connectors. Existing MCP connections keep running.",checked:o.data?.enableMcpAggregators===!0,onCheckedChange:r(te=>l.mutate({enableMcpAggregators:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableMcpAggregators",managed:d.enableMcpAggregators,ariaLabel:"Toggle MCP aggregators experimental setting"}),(0,t.jsx)(Co,{title:"Paperclip Runner",description:"Allow new Codex agents to select the experimental Rust Paperclip Runner, including authenticated runner ingress when a sandbox requires it. Onboarding continues to use legacy adapters. Turning this off hides the choice without affecting existing native runs.",checked:g,onCheckedChange:r(te=>l.mutate({enableNativeRunner:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableNativeRunner",managed:d.enableNativeRunner,ariaLabel:"Toggle Paperclip Runner experimental setting"}),(0,t.jsx)(Co,{title:"Simplified English Interactions",description:"Instruct agents to write user interactions (plan confirmations, questions, suggested tasks, checkbox prompts) in ASD-STE100 Simplified Technical English, with brief context on what information the decision needs and what happens for each choice.",checked:H,onCheckedChange:r(te=>l.mutate({enableSimplifiedEnglishInteractions:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableSimplifiedEnglishInteractions",managed:d.enableSimplifiedEnglishInteractions,ariaLabel:"Toggle simplified english interactions experimental setting"}),(0,t.jsx)(Co,{title:"Status Cards",description:"Enable the experimental shared status-card board and its gated API. Existing card data is kept when this is disabled.",footnote:"Enabling Status Cards also enables Summaries.",checked:O,onCheckedChange:r(te=>l.mutate(te?{enableSummaries:!0,enableStatusCards:!0}:{enableStatusCards:!1}),"onCheckedChange"),disabled:l.isPending||T,settingKey:"enableStatusCards",managed:d.enableStatusCards,ariaLabel:"Toggle status cards experimental setting"}),(0,t.jsx)(Co,{title:"Streamlined UI",description:"Use the simplified main sidebar, shared Tasks and Inbox presentation, focused task detail layout, and contextual navigation across Agents, Routines, Skills, and Settings.",footnote:"Turning this off restores the legacy shell and navigation. Task and page data are unchanged.",checked:w,onCheckedChange:r(te=>l.mutate({enableStreamlinedUi:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableStreamlinedUi",managed:d.enableStreamlinedUi,ariaLabel:"Toggle Streamlined UI experimental setting"}),(0,t.jsx)(Co,{title:"Summaries",description:"Show Summarizer-generated status slots on project and workspace pages, with on-demand refresh and revision history. Existing summary data is kept when this is disabled.",footnote:"Status Cards requires Summaries. Disabling Summaries also disables Status Cards.",checked:E,onCheckedChange:r(te=>l.mutate(te||!O?{enableSummaries:te}:{enableSummaries:!1,enableStatusCards:!1}),"onCheckedChange"),disabled:l.isPending||q,settingKey:"enableSummaries",managed:d.enableSummaries,ariaLabel:"Toggle summaries experimental setting"}),j&&(0,t.jsx)(Co,{title:"Use Isolated Workspaces By Default",description:"Treat a project that has no execution workspace policy of its own as if it selected isolated workspaces, so its tasks get a per-task worktree instead of sharing the project checkout. A project that carries its own policy keeps it.",checked:S,onCheckedChange:r(te=>l.mutate({enableIsolatedWorkspacesByDefault:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableIsolatedWorkspacesByDefault",managed:d.enableIsolatedWorkspacesByDefault,ariaLabel:"Toggle isolated workspaces by default experimental setting"})]}),le?(0,t.jsxs)("section",{className:"space-y-3","aria-labelledby":"developer-mode-heading",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("h2",{id:"developer-mode-heading",className:"text-sm font-semibold",children:"Paperclip Developer Mode"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Internal tools for developing, testing, and debugging Paperclip."})]}),(0,t.jsx)(Co,{title:"Auto-Restart Dev Server When Idle",description:"In `pnpm dev:once`, wait for all queued and running local agent runs to finish, then restart the server automatically when backend changes or migrations make the current boot stale.",checked:ie,onCheckedChange:r(te=>l.mutate({autoRestartDevServerWhenIdle:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"autoRestartDevServerWhenIdle",managed:d.autoRestartDevServerWhenIdle,ariaLabel:"Toggle guarded dev-server auto-restart"}),(0,t.jsx)(Co,{title:"Managed Environment Only",description:"Hide the local environment and run all agents in the platform-managed environment.",checked:y,onCheckedChange:r(te=>l.mutate({enableManagedSandboxOnly:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableManagedSandboxOnly",managed:d.enableManagedSandboxOnly,ariaLabel:"Toggle managed environment only experimental setting"}),(0,t.jsx)(Co,{title:"Paperclip Developer Mode",description:"Show internal Paperclip maintainer tools and observability links, including Honeycomb trace queries on run pages.",checked:V,onCheckedChange:r(te=>l.mutate({enablePaperclipDeveloperMode:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enablePaperclipDeveloperMode",managed:d.enablePaperclipDeveloperMode,ariaLabel:"Toggle Paperclip developer mode experimental setting"}),X?(0,t.jsx)(Gs,{className:"block bg-transparent p-5",children:(0,t.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold",children:"Run tasks in this worktree"}),h?(0,t.jsx)(VCe,{}):null]}),(0,t.jsx)("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"This is an isolated git-worktree preview instance. Turn this on to let the scheduler execute runs here. Only tasks created after enabling will run automatically — copied/pre-existing tasks stay parked. Toggling off and on resets the cutoff."})]}),(0,t.jsx)(Ei,{checked:u,onCheckedChange:r(te=>{h||l.mutate({enableWorktreeRunExecution:te})},"onCheckedChange"),disabled:l.isPending||h,"aria-label":"Toggle worktree run execution setting"})]}),p.kind==="armed"?(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-sm text-foreground",children:[(0,t.jsx)(_o,{className:"h-4 w-4 shrink-0 text-emerald-600"}),(0,t.jsxs)("span",{children:["Running tasks created after"," ",(0,t.jsx)("span",{className:"font-medium",children:ozt(p.activatedAt)}),"."]})]}):null,p.kind==="fail_closed"?(0,t.jsxs)("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-sm",children:[(0,t.jsx)(Is,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),(0,t.jsxs)("div",{className:"space-y-0.5",children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"Execution is suppressed — effectively off."}),(0,t.jsxs)("p",{className:"text-muted-foreground",children:[p.reason==="instance_mismatch"?"This setting was armed in a different instance and copied here, so no tasks run automatically.":"This setting is missing its activation cutoff, so no tasks run automatically."," ","Toggle it off and back on to arm execution for tasks created here."]})]})]}):null]})}):null,(0,t.jsx)(Co,{title:"Server Info Debug View",description:'Show a "Server" section in the account drawer with the current server restart time and running commit.',checked:D,onCheckedChange:r(te=>l.mutate({enableServerInfoDebugView:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableServerInfoDebugView",managed:d.enableServerInfoDebugView,ariaLabel:"Toggle server info debug view experimental setting"}),(0,t.jsx)(Co,{title:"Smoke Lab",description:'Add a "Smoke Lab" tab under Apps → Developer and an "Integration smoke" card on the dashboard for exercising every integration path against deterministic local fixtures (fake OAuth provider + loopback MCP servers). Private (non-public) deployments only.',checked:Y,onCheckedChange:r(te=>l.mutate({enableSmokeLab:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableSmokeLab",managed:d.enableSmokeLab,ariaLabel:"Toggle smoke lab experimental setting"}),(0,t.jsx)(Co,{title:"Task Plan Decomposition",description:"Show accepted-plan decomposition history on task detail pages. Intended for debugging and validating subtask creation behavior while the presentation is still being refined.",checked:_,onCheckedChange:r(te=>l.mutate({enableIssuePlanDecompositions:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableIssuePlanDecompositions",managed:d.enableIssuePlanDecompositions,ariaLabel:"Toggle task plan decomposition panel experimental setting"})]}):null,oe?(0,t.jsxs)("section",{className:"space-y-3","aria-labelledby":"legacy-heading",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("h2",{id:"legacy-heading",className:"text-sm font-semibold",children:"Legacy"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"These features are going to be removed."})]}),(0,t.jsx)(Co,{title:"Classic Task Interface",description:"Restores the previous task detail page: the page-level header with inline description editing, the plain comment thread, and the fixed Properties sidebar. Chat-only features — streaming activity folding, inline plan and question cards, the three-mode composer — are unavailable in the classic view.",footnote:"Switching takes effect immediately. No task data is affected.",checked:N,onCheckedChange:r(te=>l.mutate({enableClassicTaskInterface:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableClassicTaskInterface",managed:d.enableClassicTaskInterface,ariaLabel:"Toggle classic task interface experimental setting"}),(0,t.jsx)(Co,{title:"Goals Sidebar Link",description:"Restore the Goals item in the main sidebar while the goals surface is being evaluated.",checked:K,onCheckedChange:r(te=>l.mutate({enableGoalsSidebarLink:te}),"onCheckedChange"),disabled:l.isPending,settingKey:"enableGoalsSidebarLink",managed:d.enableGoalsSidebarLink,ariaLabel:"Toggle goals sidebar link experimental setting"})]}):null]})}r(lzt,"InstanceExperimentalSettings");function czt(){const{userId:e,settled:s}=G3(),{setBreadcrumbs:n}=$n(),{pushToast:a}=Mi(),i=Ht(),[o,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(null),[u,h]=(0,m.useState)(new Set);(0,m.useEffect)(()=>{n([{label:"Settings",href:"/company/settings"},{label:"Instance settings",href:"/company/settings/instance/general"},{label:"Access"}])},[n]);const p=ee({queryKey:P.access.adminUsers(o),queryFn:r(()=>fr.searchAdminUsers(o),"queryFn")}),x=ee({...N_e(e),enabled:s&&p.isSuccess}),g=x.data??[],v=(0,m.useMemo)(()=>p.data?.find(w=>w.id===c)??null,[c,p.data]),y=ee({queryKey:P.access.userCompanyAccess(c??""),queryFn:r(()=>fr.getUserCompanyAccess(c),"queryFn"),enabled:!!c});(0,m.useEffect)(()=>{!c&&p.data?.[0]&&d(p.data[0].id)},[c,p.data]),(0,m.useEffect)(()=>{y.data&&h(new Set(y.data.companyAccess.filter(w=>w.status==="active").map(w=>w.companyId)))},[y.data]);const j=ye({mutationFn:r(()=>fr.setUserCompanyAccess(c,[...u]),"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.userCompanyAccess(c)}),await i.invalidateQueries({queryKey:P.access.adminUsers(o)}),await i.invalidateQueries({queryKey:P.companies.all}),a({title:"Organization access updated",tone:"success"})},"onSuccess")}),S=ye({mutationFn:r(async w=>{if(!c)throw new Error("No user selected");return w?fr.promoteInstanceAdmin(c):fr.demoteInstanceAdmin(c)},"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.adminUsers(o)}),c&&await i.invalidateQueries({queryKey:P.access.userCompanyAccess(c)}),a({title:"Instance role updated",tone:"success"})},"onSuccess")});if(p.isLoading||!s||p.isSuccess&&x.isPending)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading instance access…"});if(p.error){const w=p.error instanceof Nn&&p.error.status===403?"Instance admin access is required to manage users.":p.error instanceof Error?p.error.message:"Failed to load users.";return(0,t.jsx)("div",{className:"text-sm text-destructive",children:w})}return x.error?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("p",{className:"text-sm text-destructive",children:"Failed to load organizations. Try again before changing access."}),(0,t.jsx)(F,{onClick:r(()=>{x.refetch()},"onClick"),children:"Try again"})]}):(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(r5,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Instance Access"})]}),(0,t.jsx)("p",{className:"max-w-3xl text-sm text-muted-foreground",children:"Search users, manage instance-admin status, and control which organizations they can access."})]}),(0,t.jsxs)("div",{className:"grid gap-6 lg:grid-cols-(--gtc-34)",children:[(0,t.jsxs)(Gs,{className:"block space-y-4 p-4",children:[(0,t.jsxs)("label",{className:"block space-y-2 text-sm",children:[(0,t.jsx)("span",{className:"font-medium",children:"Search users"}),(0,t.jsx)("input",{className:"w-full rounded-md border border-border bg-background px-3 py-2",value:o,onChange:r(w=>l(w.target.value),"onChange"),placeholder:"Search by name or email"})]}),(0,t.jsx)("div",{className:"space-y-2",children:(p.data??[]).map(w=>(0,t.jsxs)("button",{type:"button",onClick:r(()=>d(w.id),"onClick"),className:`w-full rounded-lg border px-3 py-3 text-left transition-colors ${w.id===c?"border-foreground bg-accent":"border-border hover:bg-accent/40"}`,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"truncate font-medium",children:w.name||w.email||w.id}),(0,t.jsx)("div",{className:"truncate text-sm text-muted-foreground",children:w.email||w.id})]}),w.isInstanceAdmin?(0,t.jsx)(Ai,{className:"h-4 w-4 text-emerald-600"}):null]}),(0,t.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground",children:[w.activeCompanyMembershipCount," active organization memberships"]})]},w.id))})]}),(0,t.jsx)(Gs,{className:"block space-y-4 p-5",children:c?y.isLoading?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading user access…"}):y.error?(0,t.jsx)("div",{className:"text-sm text-destructive",children:y.error instanceof Error?y.error.message:"Failed to load user access."}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-lg font-semibold",children:v?.name||v?.email||c}),(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:v?.email||c})]}),(0,t.jsx)(F,{variant:v?.isInstanceAdmin?"outline":"default",onClick:r(()=>S.mutate(!(v?.isInstanceAdmin??!1)),"onClick"),disabled:S.isPending,children:v?.isInstanceAdmin?"Remove instance admin":"Promote to instance admin"})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-sm font-semibold",children:"Organization access"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Toggle organization membership for this user. New access defaults to an active operator membership."})]}),(0,t.jsx)("div",{className:"grid gap-3 md:grid-cols-2",children:g.map(w=>(0,t.jsxs)("label",{className:"flex items-start gap-3 rounded-lg border border-border px-3 py-3",children:[(0,t.jsx)(Ki,{checked:u.has(w.id),onCheckedChange:r(N=>{h(_=>{const I=new Set(_);return N?I.add(w.id):I.delete(w.id),I})},"onCheckedChange")}),(0,t.jsxs)("span",{className:"space-y-1",children:[(0,t.jsx)("span",{className:"block text-sm font-medium",children:w.name}),(0,t.jsx)("span",{className:"block text-xs text-muted-foreground",children:w.issuePrefix})]})]},w.id))}),(0,t.jsx)("div",{className:"flex justify-end",children:(0,t.jsx)(F,{onClick:r(()=>j.mutate(),"onClick"),disabled:j.isPending,children:j.isPending?"Saving…":"Save organization access"})})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold",children:"Current memberships"}),(0,t.jsx)("div",{className:"space-y-2",children:(y.data?.companyAccess??[]).map(w=>(0,t.jsxs)("div",{className:"flex items-center justify-between rounded-lg border border-border px-3 py-2 text-sm",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"font-medium",children:w.companyName||w.companyId}),(0,t.jsxs)("div",{className:"text-muted-foreground",children:[w.membershipRole||"unset"," • ",w.status]})]}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:new Date(w.updatedAt).toLocaleDateString()})]},w.id))})]})]}):(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Select a user to inspect instance access."})})]})]})}r(czt,"InstanceAccess");var boe={getMine:r(e=>Re.get(`/companies/${e}/users/me/inbox-agent-policy`),"getMine"),updateMine:r((e,s)=>Re.put(`/companies/${e}/users/me/inbox-agent-policy`,s),"updateMine")},dzt=[{value:"open",title:"Any of my agents",description:"Let any agent you manage archive tasks out of your inbox."},{value:"allowlist",title:"Only chosen agents",description:"Restrict inbox tidying to the agents you pick below."},{value:"disabled",title:"Off",description:"Agents can never archive tasks from your inbox."}];function HA(e,s){return`${e}:${[...s].sort().join(",")}`}r(HA,"policyKey");function uzt({companyId:e}){const s=Ht(),[n,a]=(0,m.useState)(null),i=(0,m.useRef)(null),o=ee({queryKey:e?P.inboxAgentPolicy.mine(e):["inbox-agent-policy","none"],queryFn:r(()=>boe.getMine(e),"queryFn"),enabled:!!e}),l=o.data,c=ee({queryKey:e?P.agents.list(e):["agents","none"],queryFn:r(()=>Wt.list(e),"queryFn"),enabled:!!e}),d=(0,m.useMemo)(()=>(c.data??[]).filter(Xp),[c.data]),u=(0,m.useMemo)(()=>d.map(g=>({id:g.id,name:g.name,title:g.title??g.role,icon:g.icon})),[d]),h=(0,m.useMemo)(()=>new Set(n?.allowedAgentIds??[]),[n?.allowedAgentIds]);(0,m.useEffect)(()=>{if(!l)return;const g=HA(l.mode,l.allowedAgentIds);a(v=>v===null||HA(v.mode,v.allowedAgentIds)===i.current?{mode:l.mode,allowedAgentIds:l.allowedAgentIds}:v),i.current=g},[l]);const p=ye({mutationFn:r(g=>boe.updateMine(e,{mode:g.mode,allowedAgentIds:g.mode==="allowlist"?g.allowedAgentIds:[]}),"mutationFn"),onSuccess:r(g=>{s.setQueryData(P.inboxAgentPolicy.mine(e),g)},"onSuccess")}),x=!!(n&&l&&HA(n.mode,n.allowedAgentIds)!==HA(l.mode,l.allowedAgentIds));return o.error?(0,t.jsx)("div",{className:"text-sm text-destructive",children:o.error instanceof Error?o.error.message:"Failed to load inbox agent policy."}):o.isLoading||!n?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading inbox agent policy…"}):(0,t.jsxs)("section",{className:"space-y-4","aria-label":"Let agents tidy my inbox",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Td,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Let agents tidy my inbox"})]}),(0,t.jsx)("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Choose whether the agents you manage may archive tasks out of your inbox on your behalf. You can undo any archive, and every agent archive is attributed in the task's properties."})]}),(0,t.jsx)(iu,{ariaLabel:"Inbox agent archiving policy",value:n.mode,onValueChange:r(g=>a(v=>v&&{...v,mode:g}),"onValueChange"),options:dzt,className:"max-w-2xl"}),n.mode==="allowlist"?(0,t.jsxs)("div",{className:"max-w-2xl space-y-2",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:"Agents allowed to tidy my inbox"}),(0,t.jsx)(_v,{agents:u,selectedAgentIds:h,onChange:r(g=>a(v=>v&&{...v,allowedAgentIds:[...g]}),"onChange"),triggerLabel:h.size===0?"Select agents":`${h.size} ${h.size===1?"agent":"agents"} selected`,triggerFullWidth:!1,showSelectionPreview:!1,emptyMessage:"You don’t manage any agents yet."})]}):null,p.error?(0,t.jsx)("div",{className:"max-w-2xl rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:p.error instanceof Error?p.error.message:"Failed to save inbox agent policy."}):null,(0,t.jsxs)("div",{className:"flex max-w-2xl items-center justify-end gap-3",children:[p.isSuccess&&!x?(0,t.jsx)("span",{className:"text-xs text-muted-foreground",role:"status",children:"Saved"}):null,(0,t.jsxs)(F,{type:"button",disabled:!x||p.isPending,onClick:r(()=>n&&p.mutate(n),"onClick"),children:[p.isPending?(0,t.jsx)(ot,{className:"size-4 animate-spin"}):(0,t.jsx)(Bp,{className:"size-4"}),p.isPending?"Saving…":"Save"]})]})]})}r(uzt,"InboxAgentPolicyControl");function mzt(e){const s=e.trim().split(/\s+/).filter(Boolean);return s.length>=2?`${s[0]?.[0]??""}${s[s.length-1]?.[0]??""}`.toUpperCase():e.slice(0,2).toUpperCase()}r(mzt,"deriveInitials");function hzt(){const{setBreadcrumbs:e}=$n(),{selectedCompanyId:s,selectedCompany:n}=fs(),a=Ht(),i=(0,m.useId)(),o=(0,m.useRef)(null),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(null),x=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1});(0,m.useEffect)(()=>{e([{label:"Settings",href:"/company/settings"},{label:"Profile"}])},[e]),(0,m.useEffect)(()=>{const R=x.data;R&&(c(R.user.name??""),u(R.user.image??""))},[x.data]);function g(R){a.setQueryData(P.auth.session,E=>E&&{...E,user:{...E.user,...R}})}r(g,"syncSessionProfile");async function v(R){const E=await Pa.updateProfile(R);return g(E),E}r(v,"persistProfile");function y(){return l.trim()||x.data?.user.name||"Board"}r(y,"resolveProfileName");const j=ye({mutationFn:r(R=>v(R),"mutationFn"),onSuccess:r(R=>{p(null),c(R.name??""),u(R.image??"")},"onSuccess"),onError:r(R=>{p(R instanceof Error?R.message:"Failed to update profile.")},"onError")}),S=ye({mutationFn:r(async R=>{if(!s)throw new Error("Select an organization before uploading a profile avatar.");const E=await c0.uploadImage(s,R,`profiles/${x.data?.user.id??"board-user"}`);return v({name:y(),image:E.contentPath})},"mutationFn"),onSuccess:r(R=>{p(null),c(R.name??""),u(R.image??"")},"onSuccess"),onError:r(R=>{p(R instanceof Error?R.message:"Failed to upload avatar.")},"onError")}),w=ye({mutationFn:r(()=>v({name:y(),image:null}),"mutationFn"),onSuccess:r(R=>{p(null),c(R.name??""),u(R.image??"")},"onSuccess"),onError:r(R=>{p(R instanceof Error?R.message:"Failed to remove avatar.")},"onError")});if(x.isLoading)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading profile..."});if(x.error||!x.data)return(0,t.jsx)("div",{className:"text-sm text-destructive",children:x.error instanceof Error?x.error.message:"Failed to load profile."});const N=l.trim()||x.data.user.name||"Board",_=d.trim()||null,I=mzt(N),C=j.isPending||S.isPending||w.isPending,A=n?`Stored in Paperclip file storage for ${n.name}.`:"Select an organization to upload an avatar into Paperclip storage.";return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(p1,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Profile"})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Control how your account appears in the sidebar and other board surfaces."})]}),h?(0,t.jsx)("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:h}):null,(0,t.jsxs)("section",{className:"space-y-8",children:[(0,t.jsxs)(Gs,{className:"block relative overflow-hidden rounded-(--rad-28) border-border/70",children:[(0,t.jsx)("div",{className:"absolute inset-x-0 top-0 h-32 bg-(image:--gradient-extract-26)"}),(0,t.jsx)("div",{className:"absolute inset-0 bg-(image:--gradient-extract-7)"}),(0,t.jsx)("div",{className:"relative p-6 pt-10",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-end gap-5 rounded-(--rad-24) border border-border/70 bg-background/92 p-5 shadow-(--shadow-extract-18) backdrop-blur-sm",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("label",{htmlFor:i,className:"group relative block cursor-pointer rounded-full focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background",children:[(0,t.jsx)("input",{ref:o,id:i,type:"file",accept:"image/*",className:"sr-only",disabled:!s||C,onChange:r(R=>{const E=R.target.files?.[0];E&&(S.mutate(E),R.target.value="")},"onChange")}),(0,t.jsx)("span",{className:"absolute inset-0 z-10 rounded-full bg-black/0 transition-colors group-hover:bg-black/14 group-focus-within:bg-black/14"}),(0,t.jsx)("span",{className:"absolute bottom-1 right-1 z-20 flex size-9 items-center justify-center rounded-full border border-background bg-primary text-primary-foreground shadow-sm",children:S.isPending?(0,t.jsx)(ot,{className:"size-4 animate-spin"}):(0,t.jsx)(iH,{className:"size-4"})}),(0,t.jsxs)(Yi,{size:"lg",className:"data-[size=lg]:size-24 ring-4 ring-background shadow-xl",children:[_?(0,t.jsx)(zc,{src:_,alt:N}):null,(0,t.jsx)(Ji,{children:I})]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsxs)(F,{type:"button",variant:"secondary",onClick:r(()=>o.current?.click(),"onClick"),disabled:!s||C,children:[S.isPending?(0,t.jsx)(ot,{className:"size-4 animate-spin"}):(0,t.jsx)(iH,{className:"size-4"}),_?"Change photo":"Upload photo"]}),_?(0,t.jsxs)(F,{type:"button",variant:"outline",onClick:r(()=>w.mutate(),"onClick"),disabled:C,children:[w.isPending?(0,t.jsx)(ot,{className:"size-4 animate-spin"}):(0,t.jsx)(Na,{className:"size-4"}),"Remove"]}):null]})]}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-2 pb-1",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"truncate text-2xl font-semibold text-foreground",children:N}),(0,t.jsx)("p",{className:"truncate text-sm text-muted-foreground",children:x.data.user.email??"No email"})]}),(0,t.jsxs)("p",{className:"max-w-2xl text-sm leading-6 text-muted-foreground",children:["Click the avatar to upload a new image. ",A]})]})]})})]}),(0,t.jsxs)("form",{className:"grid gap-6 md:grid-cols-2",onSubmit:r(R=>{R.preventDefault(),j.mutate({name:y(),image:d.trim()||null})},"onSubmit"),children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(Vs,{htmlFor:"profile-name",children:"Display name"}),(0,t.jsx)(Rt,{id:"profile-name",value:l,onChange:r(R=>c(R.target.value),"onChange"),maxLength:120,placeholder:"Board"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Shown in the sidebar account footer and comment author surfaces."})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(Vs,{htmlFor:"profile-email",children:"Email"}),(0,t.jsx)(Rt,{id:"profile-email",value:x.data.user.email??"",readOnly:!0,disabled:!0}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Email is managed by your auth session and is read-only here."})]}),(0,t.jsx)("div",{className:"md:col-span-2 flex justify-end",children:(0,t.jsxs)(F,{type:"submit",disabled:C||!l.trim(),children:[j.isPending?(0,t.jsx)(ot,{className:"size-4 animate-spin"}):(0,t.jsx)(Bp,{className:"size-4"}),j.isPending?"Saving...":"Save profile"]})})]}),(0,t.jsx)(uzt,{companyId:s})]})]})}r(hzt,"ProfileSettings");function pzt(e){return e?e.split(/\r?\n/).map(s=>s.trim()).find(Boolean)??null:null}r(pzt,"firstNonEmptyLine");function voe(e){return pzt(e.lastError)??"Plugin entered an error state without a stored error message."}r(voe,"getPluginErrorSummary");function yoe(e){if(e.bundledExperimental)return!0;const s=e.packageName??"",n=e.packagePath??"";return s.includes("sandbox")||n.includes("sandbox")?!0:e.manifestJson?.environmentDrivers?.some(a=>a.kind==="sandbox_provider")===!0}r(yoe,"isExperimentalPluginIdentity");function joe(){return(0,t.jsx)(dt,{variant:"outline",className:"border-amber-500/30 bg-amber-500/10 text-amber-700 hover:bg-amber-500/10 dark:text-amber-200",children:"Experimental"})}r(joe,"ExperimentalBadge");function fzt(){const{selectedCompany:e}=fs(),{setBreadcrumbs:s}=$n(),n=Ht(),{pushToast:a}=ua(),[i,o]=(0,m.useState)(""),[l,c]=(0,m.useState)(!1),[d,u]=(0,m.useState)(null),[h,p]=(0,m.useState)(""),[x,g]=(0,m.useState)(null);(0,m.useEffect)(()=>{s([{label:e?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Plugins"}])},[e?.name,s]);const{data:v,isLoading:y,error:j}=ee({queryKey:P.plugins.all,queryFn:r(()=>Jo.list(),"queryFn")}),S=ee({queryKey:P.plugins.examples,queryFn:r(()=>Jo.listBundled(),"queryFn")}),w=r(()=>{n.invalidateQueries({queryKey:P.plugins.all}),n.invalidateQueries({queryKey:P.plugins.examples}),n.invalidateQueries({queryKey:P.plugins.uiContributions})},"invalidatePluginQueries"),N=ye({mutationFn:r(T=>Jo.install(T),"mutationFn"),onSuccess:r(()=>{w(),c(!1),o(""),a({title:"Plugin installed successfully",tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Failed to install plugin",body:T.message,tone:"error"})},"onError")}),_=ye({mutationFn:r(T=>Jo.uninstall(T),"mutationFn"),onSuccess:r(()=>{w(),a({title:"Plugin uninstalled successfully",tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Failed to uninstall plugin",body:T.message,tone:"error"})},"onError")}),I=ye({mutationFn:r(T=>Jo.enable(T),"mutationFn"),onSuccess:r(()=>{w(),a({title:"Plugin enabled",tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Failed to enable plugin",body:T.message,tone:"error"})},"onError")}),C=ye({mutationFn:r(T=>Jo.disable(T),"mutationFn"),onSuccess:r(()=>{w(),a({title:"Plugin disabled",tone:"info"})},"onSuccess"),onError:r(T=>{a({title:"Failed to disable plugin",body:T.message,tone:"error"})},"onError")}),A=v??[],R=S.data??[],E=new Map(A.map(T=>[T.packageName,T])),O=new Map(R.map(T=>[T.packageName,T])),L=N.variables?.isLocalPath?N.error?.message??null:null,$=(0,m.useMemo)(()=>new Map(A.map(T=>[T.id,voe(T)])),[A]);return y?(0,t.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading plugins..."}):j?(0,t.jsx)("div",{className:"p-4 text-sm text-destructive",children:"Failed to load plugins."}):(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Eg,{className:"h-6 w-6 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Plugin Manager"})]}),(0,t.jsxs)(Xs,{open:l,onOpenChange:c,children:[(0,t.jsx)(Fw,{asChild:!0,children:(0,t.jsxs)(F,{size:"sm",className:"gap-2",children:[(0,t.jsx)(xn,{className:"h-4 w-4"}),"Install Plugin"]})}),(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Install Plugin"}),(0,t.jsx)(Dn,{children:"Enter the npm package name of the plugin you wish to install."})]}),(0,t.jsx)("div",{className:"grid gap-4 py-4",children:(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsx)(Vs,{htmlFor:"packageName",children:"npm Package Name"}),(0,t.jsx)(Rt,{id:"packageName",placeholder:"@tickernelz/paperclip-pro-plugin-example",value:i,onChange:r(T=>o(T.target.value),"onChange")})]})}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>c(!1),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{onClick:r(()=>N.mutate({packageName:i}),"onClick"),disabled:!i||N.isPending,children:N.isPending?"Installing...":"Install"})]})]})]})]}),(0,t.jsx)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(Is,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),(0,t.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"Plugins are alpha."}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"The plugin runtime and API surface are still changing. Expect breaking changes while this feature settles."})]})]})}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Gu,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Available Plugins"}),(0,t.jsx)(dt,{variant:"outline",children:"Bundled"})]}),L&&(0,t.jsx)("div",{className:"rounded-md border border-destructive/25 bg-destructive/[0.06] px-4 py-3 text-sm text-destructive whitespace-pre-wrap break-words",children:L}),S.isLoading?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading bundled plugins..."}):S.error?(0,t.jsx)("div",{className:"text-sm text-destructive",children:"Failed to load bundled plugins."}):R.length===0?(0,t.jsx)("div",{className:"rounded-md border border-dashed px-4 py-3 text-sm text-muted-foreground",children:"No bundled plugins were found in this checkout."}):(0,t.jsx)(Gs,{className:"block py-0",children:(0,t.jsx)("ul",{className:"divide-y",children:R.map(T=>{const q=E.get(T.packageName),B=N.isPending&&N.variables?.isLocalPath&&N.variables.packageName===T.localPath;return(0,t.jsx)("li",{children:(0,t.jsxs)("div",{className:"flex items-center gap-4 px-4 py-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"font-medium",children:T.displayName}),(0,t.jsx)(dt,{variant:"outline",children:T.tag==="first-party"?"First-party":"Example"}),yoe({packageName:T.packageName,packagePath:T.localPath,bundledExperimental:T.experimental})&&(0,t.jsx)(joe,{}),q?(0,t.jsx)(dt,{variant:q.status==="ready"?"default":"secondary",className:q.status==="ready"?"bg-green-600 hover:bg-green-700":"",children:q.status}):(0,t.jsx)(dt,{variant:"secondary",children:"Not installed"})]}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:T.description}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:T.packageName}),B&&!T.hasBuiltEntrypoints&&(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Building plugin..."})]}),(0,t.jsx)("div",{className:"flex items-center gap-2 shrink-0",children:q?(0,t.jsxs)(t.Fragment,{children:[q.status!=="ready"&&(0,t.jsx)(F,{variant:"outline",size:"sm",disabled:I.isPending,onClick:r(()=>I.mutate(q.id),"onClick"),children:"Enable"}),(0,t.jsx)(F,{variant:"outline",size:"sm",asChild:!0,children:(0,t.jsx)(Qe,{to:`/company/settings/instance/plugins/${q.id}`,children:q.status==="ready"?"Open Settings":"Review"})})]}):(0,t.jsx)(F,{size:"sm",disabled:B||N.isPending,onClick:r(()=>N.mutate({packageName:T.localPath,isLocalPath:!0}),"onClick"),children:B?"Installing...":"Install"})})]})},T.packageName)})})})]}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Eg,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Installed Plugins"})]}),A.length?(0,t.jsx)(Gs,{className:"block py-0",children:(0,t.jsx)("ul",{className:"divide-y",children:A.map(T=>(0,t.jsx)("li",{children:(0,t.jsxs)("div",{className:"flex items-start gap-4 px-4 py-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(Qe,{to:`/company/settings/instance/plugins/${T.id}`,className:"font-medium hover:underline truncate block",title:T.manifestJson.displayName??T.packageName,children:T.manifestJson.displayName??T.packageName}),O.has(T.packageName)&&(0,t.jsx)(dt,{variant:"outline",children:O.get(T.packageName)?.tag==="first-party"?"First-party":"Example"}),yoe({packageName:T.packageName,packagePath:T.packagePath,manifestJson:T.manifestJson,bundledExperimental:O.get(T.packageName)?.experimental})&&(0,t.jsx)(joe,{})]}),(0,t.jsx)("div",{children:(0,t.jsxs)("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",title:T.packageName,children:[T.packageName," · v",T.manifestJson.version??T.version]})}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground truncate mt-0.5",title:T.manifestJson.description,children:T.manifestJson.description||"No description provided."}),T.status==="error"&&(0,t.jsx)("div",{className:"mt-3 rounded-md border border-red-500/25 bg-red-500/[0.06] px-3 py-2",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-start gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-red-700 dark:text-red-300",children:[(0,t.jsx)(Is,{className:"h-4 w-4 shrink-0"}),(0,t.jsx)("span",{children:"Plugin error"})]}),(0,t.jsx)("p",{className:"mt-1 text-sm text-red-700/90 dark:text-red-200/90 break-words",title:T.lastError??void 0,children:$.get(T.id)})]}),(0,t.jsx)(F,{variant:"outline",size:"sm",className:"border-red-500/30 bg-background/60 text-red-700 hover:bg-red-500/10 hover:text-red-800 dark:text-red-200 dark:hover:text-red-100",onClick:r(()=>g(T),"onClick"),children:"View full error"})]})})]}),(0,t.jsx)("div",{className:"flex shrink-0 self-center",children:(0,t.jsxs)("div",{className:"flex flex-col items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(dt,{variant:T.status==="ready"?"default":T.status==="error"?"destructive":"secondary",className:U("shrink-0",T.status==="ready"?"bg-green-600 hover:bg-green-700":""),children:T.status}),(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8",title:T.status==="ready"?"Disable":"Enable",onClick:r(()=>{T.status==="ready"?C.mutate(T.id):I.mutate(T.id)},"onClick"),disabled:I.isPending||C.isPending,children:(0,t.jsx)(jz,{className:U("h-4 w-4",T.status==="ready"?"text-green-600":"")})}),(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8 text-destructive hover:text-destructive",title:"Uninstall",onClick:r(()=>{u(T.id),p(T.manifestJson.displayName??T.packageName)},"onClick"),disabled:_.isPending,children:(0,t.jsx)(MEe,{className:"h-4 w-4"})})]}),(0,t.jsx)(F,{variant:"outline",size:"sm",className:"mt-2 h-8",asChild:!0,children:(0,t.jsxs)(Qe,{to:`/company/settings/instance/plugins/${T.id}`,children:[(0,t.jsx)(Dd,{className:"h-4 w-4"}),"Configure"]})})]})})]})},T.id))})}):(0,t.jsx)(Gs,{className:"bg-muted/30",children:(0,t.jsxs)(za,{className:"flex flex-col items-center justify-center py-10",children:[(0,t.jsx)(Eg,{className:"h-10 w-10 text-muted-foreground mb-4"}),(0,t.jsx)("p",{className:"text-sm font-medium",children:"No plugins installed"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"Install a plugin to extend functionality."})]})})]}),(0,t.jsx)(Xs,{open:d!==null,onOpenChange:r(T=>{T||u(null)},"onOpenChange"),children:(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Uninstall Plugin"}),(0,t.jsxs)(Dn,{children:["Are you sure you want to uninstall ",(0,t.jsx)("strong",{children:h}),"? This action cannot be undone."]})]}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>u(null),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{variant:"destructive",disabled:_.isPending,onClick:r(()=>{d&&_.mutate(d,{onSettled:r(()=>u(null),"onSettled")})},"onClick"),children:_.isPending?"Uninstalling...":"Uninstall"})]})]})}),(0,t.jsx)(Xs,{open:x!==null,onOpenChange:r(T=>{T||g(null)},"onOpenChange"),children:(0,t.jsxs)(Zs,{className:"sm:max-w-2xl",children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Error Details"}),(0,t.jsxs)(Dn,{children:[x?.manifestJson.displayName??x?.packageName??"Plugin"," hit an error state."]})]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"rounded-md border border-red-500/25 bg-red-500/[0.06] px-4 py-3",children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(Is,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-700 dark:text-red-300"}),(0,t.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,t.jsx)("p",{className:"font-medium text-red-700 dark:text-red-300",children:"What errored"}),(0,t.jsx)("p",{className:"text-red-700/90 dark:text-red-200/90 break-words",children:x?voe(x):"No error summary available."})]})]})}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Full error output"}),(0,t.jsx)("pre",{className:"max-h-(--sz-50vh) overflow-auto rounded-md border bg-muted/40 p-3 text-xs leading-5 whitespace-pre-wrap break-words",children:x?.lastError??"No stored error message."})]})]}),(0,t.jsx)(yr,{children:(0,t.jsx)(F,{variant:"outline",onClick:r(()=>g(null),"onClick"),children:"Close"})})]})})]})}r(fzt,"PluginManager");function xzt(){const{selectedCompany:e,selectedCompanyId:s}=fs(),{setBreadcrumbs:n}=$n(),{companyPrefix:a,pluginId:i}=ja(),{hideHostPaths:o}=L1(),[l,c]=(0,m.useState)("configuration"),{data:d,isLoading:u}=ee({queryKey:P.plugins.detail(i),queryFn:r(()=>Jo.get(i),"queryFn"),enabled:!!i}),{data:h,isLoading:p}=ee({queryKey:P.plugins.health(i),queryFn:r(()=>Jo.health(i),"queryFn"),enabled:!!i&&d?.status==="ready",refetchInterval:3e4}),{data:x}=ee({queryKey:P.plugins.dashboard(i),queryFn:r(()=>Jo.dashboard(i),"queryFn"),enabled:!!i,refetchInterval:3e4}),{data:g}=ee({queryKey:P.plugins.logs(i),queryFn:r(()=>Jo.logs(i,{limit:50}),"queryFn"),enabled:!!i&&d?.status==="ready",refetchInterval:3e4}),v=d?.manifestJson?.instanceConfigSchema,y=v&&v.properties&&Object.keys(v.properties).length>0,j=i&&s?P.plugins.config(i,s):["plugins",i??"__missing_plugin__","companies","__missing_company__","config"],{data:S,isLoading:w}=ee({queryKey:j,queryFn:r(()=>Jo.getConfig(i,s),"queryFn"),enabled:!!i&&!!y&&!!s}),{slots:N}=Kc({slotTypes:["settingsPage"],companyId:s,enabled:!!s}),_=N.filter(q=>q.pluginId===i),I=_.length>0;if((0,m.useEffect)(()=>{n([{label:e?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Plugins",href:"/company/settings/instance/plugins"},{label:d?.manifestJson?.displayName??d?.packageName??"Plugin Details"}])},[e?.name,n,a,d]),(0,m.useEffect)(()=>{c("configuration")},[i]),u)return(0,t.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading plugin details..."});if(!d)return(0,t.jsx)(vn,{to:"/company/settings/instance/plugins",replace:!0});const C=d.status,A=d.status==="ready"?"default":d.status==="error"?"destructive":"secondary",R=d.manifestJson.description||"No description provided.",E=d.manifestJson.capabilities??[],O=d.manifestJson.environmentDrivers??[],L=d.manifestJson.localFolders??[],$=L.length>0&&!o,T=O.map(q=>q.displayName?.trim()||q.driverKey).filter((q,B,K)=>K.indexOf(q)===B).join(", ");return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsx)(Qe,{to:"/company/settings/instance/plugins",children:(0,t.jsx)(F,{variant:"outline",size:"icon",className:"h-8 w-8",children:(0,t.jsx)(sc,{className:"h-4 w-4"})})}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Eg,{className:"h-6 w-6 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-xl font-semibold",children:d.manifestJson.displayName??d.packageName}),(0,t.jsx)(dt,{variant:A,className:"ml-2",children:C}),(0,t.jsxs)(dt,{variant:"outline",className:"ml-1",children:["v",d.manifestJson.version??d.version]})]})]}),(0,t.jsxs)(Ci,{value:l,onValueChange:r(q=>c(q),"onValueChange"),className:"space-y-6",children:[(0,t.jsx)(tc,{align:"start",items:[{value:"configuration",label:"Configuration"},{value:"status",label:"Status"}],value:l,onValueChange:r(q=>c(q),"onValueChange")}),(0,t.jsx)(ia,{value:"configuration",className:"space-y-6",children:(0,t.jsxs)("div",{className:"space-y-8",children:[(0,t.jsxs)("section",{className:"space-y-5",children:[(0,t.jsx)("h2",{className:"text-base font-semibold",children:"About"}),(0,t.jsxs)("div",{className:"grid gap-8 lg:grid-cols-(--gtc-52)",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h3",{className:"text-sm font-medium text-muted-foreground",children:"Description"}),(0,t.jsx)("p",{className:"text-sm leading-6 text-foreground/90",children:R})]}),(0,t.jsxs)("div",{className:"space-y-4 text-sm",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("h3",{className:"font-medium text-muted-foreground",children:"Author"}),(0,t.jsx)("p",{className:"text-foreground",children:d.manifestJson.author})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h3",{className:"font-medium text-muted-foreground",children:"Categories"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:d.categories.length>0?d.categories.map(q=>(0,t.jsx)(dt,{variant:"outline",className:"capitalize",children:q},q)):(0,t.jsx)("span",{className:"text-foreground",children:"None"})})]})]})]})]}),(0,t.jsx)(ml,{}),(0,t.jsxs)("section",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"space-y-1",children:(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Settings"})}),$?(0,t.jsx)(gzt,{pluginId:i,companyId:s,declarations:L}):null,I?(0,t.jsx)("div",{className:"space-y-3",children:_.map(q=>(0,t.jsx)(fu,{slot:q,context:{companyId:s,companyPrefix:a??null},missingBehavior:"placeholder"},`${q.pluginKey}:${q.id}`))}):y?(0,t.jsx)(wzt,{pluginId:i,companyId:s,schema:v,initialValues:S?.configJson,isLoading:w,pluginStatus:d.status,supportsConfigTest:d.supportsConfigTest===!0}):O.length>0?(0,t.jsxs)("div",{className:"rounded-md border border-border/60 bg-muted/20 px-4 py-3 text-sm",children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"Configure this plugin from Settings → Environments."}),(0,t.jsxs)("p",{className:"mt-1 text-muted-foreground",children:[T||"This plugin"," registers environment runtime settings there so the execution target stays instance-scoped while secret bindings still resolve through the selected organization context."]}),(0,t.jsx)("div",{className:"mt-3",children:(0,t.jsx)(Qe,{to:"/company/settings/instance/environments",children:(0,t.jsx)(F,{variant:"outline",size:"sm",children:"Open Environments"})})})]}):$?null:(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"This plugin does not require any settings."})]})]})}),(0,t.jsx)(ia,{value:"status",className:"space-y-6",children:(0,t.jsxs)("div",{className:"grid gap-6 xl:grid-cols-(--gtc-39)",children:[(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)(Gs,{children:[(0,t.jsxs)(Zi,{children:[(0,t.jsxs)(uo,{className:"text-base flex items-center gap-1.5",children:[(0,t.jsx)(Pm,{className:"h-4 w-4"}),"Runtime Dashboard"]}),(0,t.jsx)(jl,{children:"Worker process, scheduled jobs, and webhook deliveries"})]}),(0,t.jsx)(za,{className:"space-y-6",children:x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[(0,t.jsx)(Pm,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Worker Process"]}),x.worker?(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Status"}),(0,t.jsx)(dt,{variant:x.worker.status==="running"?"default":"secondary",children:x.worker.status})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"PID"}),(0,t.jsx)("span",{className:"font-mono text-xs",children:x.worker.pid??"—"})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Uptime"}),(0,t.jsx)("span",{className:"text-xs",children:Nzt(x.worker.uptime)})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Pending RPCs"}),(0,t.jsx)("span",{className:"text-xs",children:x.worker.pendingRequests})]}),x.worker.totalCrashes>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex justify-between col-span-2",children:[(0,t.jsxs)("span",{className:"text-muted-foreground flex items-center gap-1",children:[(0,t.jsx)(Is,{className:"h-3 w-3 text-amber-500"}),"Crashes"]}),(0,t.jsxs)("span",{className:"text-xs",children:[x.worker.consecutiveCrashes," consecutive / ",x.worker.totalCrashes," total"]})]}),x.worker.lastCrashAt&&(0,t.jsxs)("div",{className:"flex justify-between col-span-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Last Crash"}),(0,t.jsx)("span",{className:"text-xs",children:kzt(x.worker.lastCrashAt)})]})]})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground italic",children:"No worker process registered."})]}),(0,t.jsx)(ml,{}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[(0,t.jsx)(Vg,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Recent Job Runs"]}),x.recentJobRuns.length>0?(0,t.jsx)("div",{className:"space-y-2",children:x.recentJobRuns.map(q=>(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md bg-muted/50 px-2 py-1.5 text-sm",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,t.jsx)(Szt,{status:q.status}),(0,t.jsx)("span",{className:"truncate font-mono text-xs",title:q.jobKey??q.jobId,children:q.jobKey??q.jobId.slice(0,8)}),(0,t.jsx)(dt,{variant:"outline",className:"px-1 py-0 text-(length:--text-nano)",children:q.trigger})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[q.durationMs!=null?(0,t.jsx)("span",{children:Noe(q.durationMs)}):null,(0,t.jsx)("span",{title:q.createdAt,children:koe(q.createdAt)})]})]},q.id))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground italic",children:"No job runs recorded yet."})]}),(0,t.jsx)(ml,{}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[(0,t.jsx)(Sz,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Recent Webhook Deliveries"]}),x.recentWebhookDeliveries.length>0?(0,t.jsx)("div",{className:"space-y-2",children:x.recentWebhookDeliveries.map(q=>(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md bg-muted/50 px-2 py-1.5 text-sm",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,t.jsx)(Czt,{status:q.status}),(0,t.jsx)("span",{className:"truncate font-mono text-xs",title:q.webhookKey,children:q.webhookKey})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[q.durationMs!=null?(0,t.jsx)("span",{children:Noe(q.durationMs)}):null,(0,t.jsx)("span",{title:q.createdAt,children:koe(q.createdAt)})]})]},q.id))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground italic",children:"No webhook deliveries recorded yet."})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 border-t border-border/50 pt-2 text-xs text-muted-foreground",children:[(0,t.jsx)(fo,{className:"h-3 w-3"}),"Last checked: ",new Date(x.checkedAt).toLocaleTimeString()]})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Runtime diagnostics are unavailable right now."})})]}),g&&g.length>0?(0,t.jsxs)(Gs,{children:[(0,t.jsxs)(Zi,{children:[(0,t.jsxs)(uo,{className:"text-base flex items-center gap-1.5",children:[(0,t.jsx)(cH,{className:"h-4 w-4"}),"Recent Logs"]}),(0,t.jsxs)(jl,{children:["Last ",g.length," log entries"]})]}),(0,t.jsx)(za,{children:(0,t.jsx)("div",{className:"max-h-64 space-y-1 overflow-y-auto font-mono text-xs",children:g.map(q=>(0,t.jsxs)("div",{className:`flex gap-2 py-0.5 ${q.level==="error"?"text-destructive":q.level==="warn"?"text-yellow-600 dark:text-yellow-400":q.level==="debug"?"text-muted-foreground/60":"text-muted-foreground"}`,children:[(0,t.jsx)("span",{className:"shrink-0 text-muted-foreground/50",children:new Date(q.createdAt).toLocaleTimeString()}),(0,t.jsx)(dt,{variant:"outline",className:"h-4 shrink-0 px-1 text-(length:--text-nano)",children:q.level}),(0,t.jsx)("span",{className:"truncate",title:q.message,children:q.message})]},q.id))})})]}):null]}),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)(Gs,{children:[(0,t.jsx)(Zi,{children:(0,t.jsxs)(uo,{className:"text-base flex items-center gap-1.5",children:[(0,t.jsx)(cH,{className:"h-4 w-4"}),"Health Status"]})}),(0,t.jsx)(za,{children:p?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Checking health..."}):h?(0,t.jsxs)("div",{className:"space-y-4 text-sm",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Overall"}),(0,t.jsx)(dt,{variant:h.healthy?"default":"destructive",children:h.status})]}),h.checks.length>0?(0,t.jsx)("div",{className:"space-y-2 border-t border-border/50 pt-2",children:h.checks.map((q,B)=>(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsx)("span",{className:"truncate text-muted-foreground",title:q.name,children:q.name}),q.passed?(0,t.jsx)(ETe,{className:"h-4 w-4 shrink-0 text-green-500"}):(0,t.jsx)(ec,{className:"h-4 w-4 shrink-0 text-destructive"})]},B))}):null,h.lastError?(0,t.jsx)("div",{className:"break-words rounded border border-destructive/20 bg-destructive/10 p-2 text-xs text-destructive",children:h.lastError}):null]}):(0,t.jsxs)("div",{className:"space-y-3 text-sm text-muted-foreground",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{children:"Lifecycle"}),(0,t.jsx)(dt,{variant:A,children:C})]}),(0,t.jsx)("p",{children:"Health checks run once the plugin is ready."}),d.lastError?(0,t.jsx)("div",{className:"break-words rounded border border-destructive/20 bg-destructive/10 p-2 text-xs text-destructive",children:d.lastError}):null]})})]}),(0,t.jsxs)(Gs,{children:[(0,t.jsx)(Zi,{children:(0,t.jsx)(uo,{className:"text-base",children:"Details"})}),(0,t.jsxs)(za,{className:"space-y-3 text-sm text-muted-foreground",children:[(0,t.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,t.jsx)("span",{children:"Plugin ID"}),(0,t.jsx)("span",{className:"font-mono text-xs text-right",children:d.id})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,t.jsx)("span",{children:"Plugin Key"}),(0,t.jsx)("span",{className:"font-mono text-xs text-right",children:d.pluginKey})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,t.jsx)("span",{children:"NPM Package"}),(0,t.jsx)("span",{className:"max-w-(--sz-170px) truncate text-right text-xs",title:d.packageName,children:d.packageName})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,t.jsx)("span",{children:"Version"}),(0,t.jsxs)("span",{className:"text-right text-foreground",children:["v",d.manifestJson.version??d.version]})]})]})]}),(0,t.jsxs)(Gs,{children:[(0,t.jsx)(Zi,{children:(0,t.jsxs)(uo,{className:"text-base flex items-center gap-1.5",children:[(0,t.jsx)(wl,{className:"h-4 w-4"}),"Permissions"]})}),(0,t.jsx)(za,{children:E.length>0?(0,t.jsx)("ul",{className:"space-y-2 text-sm text-muted-foreground",children:E.map(q=>(0,t.jsx)("li",{className:"rounded-md bg-muted/40 px-2.5 py-2 font-mono text-xs text-foreground/85",children:q},q))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground italic",children:"No special permissions requested."})})]})]})]})})]})]})}r(xzt,"PluginSettings");function gzt({pluginId:e,companyId:s,declarations:n}){const{data:a,isLoading:i,error:o}=ee({queryKey:s?P.plugins.localFolders(e,s):["plugins",e,"companies","none","local-folders"],queryFn:r(()=>Jo.listLocalFolders(e,s),"queryFn"),enabled:!!s}),l=new Map((a?.folders??[]).map(c=>[c.folderKey,c]));return s?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Io,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("h3",{className:"text-sm font-medium",children:"Local folders"})]}),o?(0,t.jsx)("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:o.message||"Failed to load local folder settings."}):null,i?(0,t.jsxs)("div",{className:"flex items-center gap-2 py-3 text-sm text-muted-foreground",children:[(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}),"Loading local folders..."]}):(0,t.jsx)("div",{className:"space-y-3",children:n.map(c=>(0,t.jsx)(bzt,{pluginId:e,companyId:s,declaration:c,status:l.get(c.folderKey)},c.folderKey))})]}):(0,t.jsx)("div",{className:"rounded-md border border-border/60 bg-muted/20 px-4 py-3 text-sm text-muted-foreground",children:"Select an organization to configure this plugin's local folders."})}r(gzt,"PluginLocalFoldersSettings");function bzt({pluginId:e,companyId:s,declaration:n,status:a}){const i=Ht(),o=a?.path??"",[l,c]=(0,m.useState)(o),[d,u]=(0,m.useState)(null);(0,m.useEffect)(()=>{c(o),u(null)},[o,n.folderKey]);const h=ye({mutationFn:r(y=>Jo.configureLocalFolder(e,s,n.folderKey,{path:y,access:n.access,requiredDirectories:n.requiredDirectories,requiredFiles:n.requiredFiles}),"mutationFn"),onSuccess:r(y=>{u({type:y.healthy?"success":"error",text:y.healthy?"Local folder saved.":"Local folder saved, but validation still needs attention."}),i.invalidateQueries({queryKey:P.plugins.localFolders(e,s)})},"onSuccess"),onError:r(y=>{u({type:"error",text:y.message||"Failed to save local folder."})},"onError")}),p=l.trim(),x=p!==o,g=a?.access??n.access??"readWrite",v=(0,m.useCallback)(()=>{if(!p){u({type:"error",text:"Local folder path is required."});return}if(!jzt(p)){u({type:"error",text:"Local folder must be a full absolute path."});return}u(null),h.mutate(p)},[h,p]);return(0,t.jsxs)("div",{className:"space-y-4 rounded-md border border-border/70 bg-background px-4 py-4",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("h4",{className:"text-sm font-medium",children:n.displayName}),(0,t.jsx)(dt,{variant:"outline",className:"font-mono text-(length:--text-nano)",children:n.folderKey}),(0,t.jsx)(dt,{variant:a?.healthy?"default":"secondary",children:a?.healthy?"Healthy":"Needs attention"})]}),n.description?(0,t.jsx)("p",{className:"max-w-3xl text-sm leading-5 text-muted-foreground",children:n.description}):null]}),(0,t.jsx)(dt,{variant:g==="readWrite"?"default":"outline",children:g==="readWrite"?"Read/write":"Read only"})]}),(0,t.jsxs)("div",{className:"grid gap-3 text-sm sm:grid-cols-3",children:[(0,t.jsx)(F$,{label:"Configured",value:a?.configured?"Yes":"No",ok:!!a?.configured}),(0,t.jsx)(F$,{label:"Readable",value:a?.readable?"Yes":"No",ok:!!a?.readable}),(0,t.jsx)(F$,{label:"Writable",value:g==="read"?"Not requested":a?.writable?"Yes":"No",ok:g==="read"||!!a?.writable})]}),a?.path?(0,t.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,t.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Configured path"}),(0,t.jsx)("div",{className:"break-all rounded-md bg-muted/60 px-2 py-1.5 font-mono text-xs text-foreground",children:a.path})]}):null,(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("label",{className:"text-xs font-medium text-muted-foreground",htmlFor:`local-folder-${n.folderKey}`,children:"Local folder path"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("input",{id:`local-folder-${n.folderKey}`,className:"min-w-0 flex-1 rounded-md border border-border bg-background px-2.5 py-1.5 font-mono text-sm outline-none focus:border-foreground/40 focus:ring-2 focus:ring-ring/20",value:l,onChange:r(y=>{c(y.target.value),u(null)},"onChange"),placeholder:"/absolute/path/to/folder"}),(0,t.jsx)(ud,{className:"h-8"}),(0,t.jsxs)(F,{size:"sm",onClick:v,disabled:h.isPending||!x||!s,children:[h.isPending?(0,t.jsx)(ot,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(Bp,{className:"h-3.5 w-3.5"}),"Save"]})]})]}),(0,t.jsx)(vzt,{status:a,declaration:n}),a?.problems?.length?(0,t.jsxs)("div",{className:"space-y-2 rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:[(0,t.jsx)("div",{className:"font-medium",children:"Validation problems"}),(0,t.jsx)("ul",{className:"space-y-1",children:a.problems.map((y,j)=>(0,t.jsxs)("li",{children:[y.message,y.path?(0,t.jsxs)("span",{className:"font-mono",children:[" ",y.path]}):null]},`${y.code}:${y.path??""}:${j}`))})]}):null,d?(0,t.jsx)("div",{className:`rounded-md border px-3 py-2 text-sm ${d.type==="success"?"border-green-200 bg-green-50 text-green-700 dark:border-green-900 dark:bg-green-950/30 dark:text-green-400":"border-destructive/20 bg-destructive/10 text-destructive"}`,children:d.text}):null]})}r(bzt,"PluginLocalFolderRow");function F$({label:e,value:s,ok:n}){return(0,t.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border/60 px-2.5 py-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:e}),(0,t.jsx)(dt,{variant:n?"default":"secondary",children:s})]})}r(F$,"FolderStatusMetric");function vzt({status:e,declaration:s}){const n=e?.requiredDirectories??s.requiredDirectories??[],a=e?.requiredFiles??s.requiredFiles??[],i=e?.missingDirectories??n,o=e?.missingFiles??a,l=yzt(e);return n.length===0&&a.length===0?null:(0,t.jsxs)("div",{className:"grid gap-3 text-sm md:grid-cols-2",children:[(0,t.jsx)(woe,{title:"Required directories",items:n,missingItems:i,missingLabel:"Missing directories",inspectionUnavailable:l}),(0,t.jsx)(woe,{title:"Required files",items:a,missingItems:o,missingLabel:"Missing files",inspectionUnavailable:l})]})}r(vzt,"FolderRequirements");function yzt(e){return!e?.configured||e.readable?!1:e.problems.some(s=>s.code==="missing"||s.code==="not_readable"||s.code==="not_directory")}r(yzt,"isRootNotInspected");function woe({title:e,items:s,missingItems:n,missingLabel:a,inspectionUnavailable:i}){return(0,t.jsxs)("div",{className:"space-y-2 rounded-md border border-border/60 px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:e}),i?(0,t.jsx)(dt,{variant:"secondary",className:"text-(length:--text-nano)",children:"Not inspected"}):n.length>0?(0,t.jsxs)(dt,{variant:"destructive",className:"text-(length:--text-nano)",children:[n.length," missing"]}):(0,t.jsx)(dt,{variant:"outline",className:"text-(length:--text-nano)",children:"Present"})]}),s.length>0?(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:s.map(o=>{const l=n.includes(o);return(0,t.jsx)("span",{className:`rounded border px-1.5 py-0.5 font-mono text-(length:--text-micro) ${i?"border-amber-300/60 bg-amber-50 text-amber-700 dark:border-amber-800/70 dark:bg-amber-950/30 dark:text-amber-300":l?"border-destructive/30 bg-destructive/10 text-destructive":"border-border bg-muted/50 text-foreground/80"}`,children:o},o)})}):(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"None declared."}),i?(0,t.jsx)("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:"Configured root was not inspected."}):n.length>0?(0,t.jsxs)("p",{className:"text-xs text-destructive",children:[a,": ",n.join(", ")]}):null]})}r(woe,"RequirementList");function jzt(e){return e.startsWith("/")||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith("\\\\")}r(jzt,"isLikelyAbsolutePath");function wzt({pluginId:e,companyId:s,schema:n,initialValues:a,isLoading:i,pluginStatus:o,supportsConfigTest:l}){const c=Ht(),[d,u]=(0,m.useState)(()=>({...Dp(n),...a??{}})),h=(0,m.useRef)(!1);(0,m.useEffect)(()=>{h.current=!1,u(Dp(n))},[s,e,n]),(0,m.useEffect)(()=>{a&&!h.current&&(h.current=!0,u({...Dp(n),...a}))},[a,n]);const[p,x]=(0,m.useState)({}),[g,v]=(0,m.useState)(null),[y,j]=(0,m.useState)(null),S=JSON.stringify(d)!==JSON.stringify({...Dp(n),...a??{}}),w=ye({mutationFn:r(A=>{if(!s)throw new Error("Select an organization before saving plugin configuration.");return Jo.saveConfig(e,s,A)},"mutationFn"),onSuccess:r(()=>{v({type:"success",text:"Configuration saved."}),j(null),s&&c.invalidateQueries({queryKey:P.plugins.config(e,s)}),setTimeout(()=>v(null),3e3)},"onSuccess"),onError:r(A=>{v({type:"error",text:A.message||"Failed to save configuration."})},"onError")}),N=ye({mutationFn:r(A=>{if(!s)throw new Error("Select an organization before testing plugin configuration.");return Jo.testConfig(e,s,A)},"mutationFn"),onSuccess:r(A=>{A.valid?j({type:"success",text:"Configuration test passed."}):j({type:"error",text:A.message||"Configuration test failed."})},"onSuccess"),onError:r(A=>{j({type:"error",text:A.message||"Configuration test failed."})},"onError")}),_=(0,m.useCallback)(A=>{u(A),x({}),v(null)},[]),I=(0,m.useCallback)(()=>{const A=Yb(n,d);if(Object.keys(A).length>0){x(A);return}x({}),w.mutate(d)},[n,d,w]),C=(0,m.useCallback)(()=>{const A=Yb(n,d);if(Object.keys(A).length>0){x(A);return}x({}),j(null),N.mutate(d)},[n,d,N]);return i?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4",children:[(0,t.jsx)(ot,{className:"h-4 w-4 animate-spin"}),"Loading configuration..."]}):(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(N1,{schema:n,values:d,onChange:_,errors:p,disabled:w.isPending}),g&&(0,t.jsx)("div",{className:`text-sm p-2 rounded border ${g.type==="success"?"text-green-700 bg-green-50 border-green-200 dark:text-green-400 dark:bg-green-950/30 dark:border-green-900":"text-destructive bg-destructive/10 border-destructive/20"}`,children:g.text}),y&&(0,t.jsx)("div",{className:`text-sm p-2 rounded border ${y.type==="success"?"text-green-700 bg-green-50 border-green-200 dark:text-green-400 dark:bg-green-950/30 dark:border-green-900":"text-destructive bg-destructive/10 border-destructive/20"}`,children:y.text}),(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-2",children:[(0,t.jsx)(F,{onClick:I,disabled:w.isPending||!S,size:"sm",children:w.isPending?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ot,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):"Save Configuration"}),o==="ready"&&l&&(0,t.jsx)(F,{variant:"outline",onClick:C,disabled:N.isPending||!s,size:"sm",children:N.isPending?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ot,{className:"h-3.5 w-3.5 animate-spin"}),"Testing..."]}):"Test Configuration"})]})]})}r(wzt,"PluginConfigForm");function Nzt(e){if(e==null)return"—";const s=Math.floor(e/1e3);if(s<60)return`${s}s`;const n=Math.floor(s/60);if(n<60)return`${n}m ${s%60}s`;const a=Math.floor(n/60);return a<24?`${a}h ${n%60}m`:`${Math.floor(a/24)}d ${a%24}h`}r(Nzt,"formatUptime");function Noe(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}r(Noe,"formatDuration");function koe(e){const s=Date.now()-new Date(e).getTime();if(s<0)return"just now";const n=Math.floor(s/1e3);if(n<60)return`${n}s ago`;const a=Math.floor(n/60);if(a<60)return`${a}m ago`;const i=Math.floor(a/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}r(koe,"formatRelativeTime");function kzt(e){return new Date(e).toLocaleString()}r(kzt,"formatTimestamp");function Szt({status:e}){return(0,t.jsx)("span",{className:`inline-block h-2 w-2 rounded-full shrink-0 ${e==="success"||e==="succeeded"?"bg-green-500":e==="failed"?"bg-red-500":e==="running"?"bg-blue-500 animate-pulse":e==="cancelled"?"bg-gray-400":"bg-amber-500"}`,title:e})}r(Szt,"JobStatusDot");function Czt({status:e}){return(0,t.jsx)("span",{className:`inline-block h-2 w-2 rounded-full shrink-0 ${e==="processed"||e==="success"?"bg-green-500":e==="failed"?"bg-red-500":e==="received"?"bg-blue-500":"bg-amber-500"}`,title:e})}r(Czt,"DeliveryStatusDot");function B$({adapter:e,canRemove:s,onToggle:n,onRemove:a,onReload:i,onReinstall:o,isToggling:l,isReloading:c,isReinstalling:d,overriddenBy:u,toggleTitleEnabled:h,toggleTitleDisabled:p,disabledBadgeLabel:x}){return(0,t.jsx)("li",{children:(0,t.jsxs)("div",{className:"flex items-center gap-4 px-4 py-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:U("font-medium",e.disabled&&"text-muted-foreground line-through"),children:e.label&&e.label!==e.type?e.label:sf(e.type)}),(0,t.jsx)(dt,{variant:"outline",children:e.source==="external"?"External":"Built-in"}),e.source==="external"&&(e.isLocalPath?(0,t.jsx)("span",{title:"Installed from local path",children:(0,t.jsx)(Io,{className:"h-4 w-4 text-amber-500"})}):(0,t.jsx)("span",{title:"Installed from npm",children:(0,t.jsx)(Eh,{className:"h-4 w-4 text-red-500"})})),e.version&&(0,t.jsxs)(dt,{variant:"secondary",className:"font-mono text-(length:--text-nano)",children:["v",e.version]}),e.overriddenBuiltin&&(0,t.jsx)(dt,{variant:"secondary",className:"text-blue-600 border-blue-400",children:"Overrides built-in"}),u&&(0,t.jsxs)(dt,{variant:"secondary",className:"text-blue-600 border-blue-400",children:["Overridden by ",u]}),e.disabled&&(0,t.jsx)(dt,{variant:"secondary",className:"text-amber-600 border-amber-400",children:x??"Hidden from menus"})]}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground mt-0.5",children:[e.type,e.packageName&&e.packageName!==e.type&&(0,t.jsxs)(t.Fragment,{children:[" · ",e.packageName]})," · ",e.modelsCount," models"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[o&&(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8",title:"Reinstall adapter (pull latest from npm)",disabled:d,onClick:r(()=>o(e.type),"onClick"),children:(0,t.jsx)(Ko,{className:U("h-4 w-4",d&&"animate-bounce")})}),i&&(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8",title:"Reload adapter (hot-swap)",disabled:c,onClick:r(()=>i(e.type),"onClick"),children:(0,t.jsx)(zi,{className:U("h-4 w-4",c&&"animate-spin")})}),(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8",title:e.disabled?h??"Show in agent menus":p??"Hide from agent menus",disabled:l,onClick:r(()=>n(e.type,!e.disabled),"onClick"),children:(0,t.jsx)(jz,{className:U("h-4 w-4",e.disabled?"text-muted-foreground":"text-green-600")})}),s&&(0,t.jsx)(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8 text-destructive hover:text-destructive",title:"Remove adapter",onClick:r(()=>a(e.type),"onClick"),children:(0,t.jsx)(Na,{className:"h-4 w-4"})})]})]})})}r(B$,"AdapterRow");function _zt(e){return fetch(`https://registry.npmjs.org/${encodeURIComponent(e)}/latest`,{signal:AbortSignal.timeout(5e3)}).then(s=>s.json()).then(s=>typeof s?.version=="string"?s.version:null).catch(()=>null)}r(_zt,"fetchNpmLatestVersion");function Izt({adapter:e,open:s,isReinstalling:n,onConfirm:a,onCancel:i}){const{data:o,isLoading:l}=ee({queryKey:["npm-latest-version",e?.packageName],queryFn:r(()=>e?.packageName?_zt(e.packageName):null,"queryFn"),enabled:s&&!!e?.packageName,staleTime:6e4}),c=e?.version&&o&&e.version===o;return(0,t.jsx)(Xs,{open:s,onOpenChange:r(d=>{d||i()},"onOpenChange"),children:(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Reinstall Adapter"}),(0,t.jsxs)(Dn,{children:["This will pull the latest version of"," ",(0,t.jsx)("strong",{children:e?.packageName})," from npm and hot-swap the running adapter module. Existing agents will use the new version on their next run."]})]}),(0,t.jsxs)("div",{className:"rounded-md border bg-muted/50 px-4 py-3 text-sm space-y-1",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Package"}),(0,t.jsx)("span",{className:"font-mono",children:e?.packageName})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Current"}),(0,t.jsx)("span",{className:"font-mono",children:e?.version?`v${e.version}`:"unknown"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Latest on npm"}),(0,t.jsx)("span",{className:"font-mono",children:l?"checking...":o?`v${o}`:"unavailable"})]}),c&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground pt-1",children:"Already on the latest version."})]}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",onClick:i,disabled:n,children:"Cancel"}),(0,t.jsx)(F,{disabled:n,onClick:a,children:n?"Reinstalling...":"Reinstall"})]})]})})}r(Izt,"ReinstallDialog");function Soe(){const{selectedCompany:e}=fs(),{setBreadcrumbs:s}=$n(),n=Ht(),{pushToast:a}=ua(),[i,o]=(0,m.useState)(""),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(!1),[h,p]=(0,m.useState)(!1),[x,g]=(0,m.useState)(null),[v,y]=(0,m.useState)(null);(0,m.useEffect)(()=>{s([{label:e?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Adapters"}])},[e?.name,s]);const{data:j,isLoading:S}=ee({queryKey:P.adapters.all,queryFn:r(()=>Cm.list(),"queryFn")}),w=r(()=>{n.invalidateQueries({queryKey:P.adapters.all})},"invalidate"),N=ye({mutationFn:r(T=>Cm.install(T),"mutationFn"),onSuccess:r(T=>{w(),p(!1),o(""),c(""),u(!1),a({title:"Adapter installed",body:`Type "${T.type}" registered successfully.${T.version?` (v${T.version})`:""}`,tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Install failed",body:T.message,tone:"error"})},"onError")}),_=ye({mutationFn:r(T=>Cm.remove(T),"mutationFn"),onSuccess:r(()=>{w(),a({title:"Adapter removed",tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Removal failed",body:T.message,tone:"error"})},"onError")}),I=ye({mutationFn:r(({type:T,disabled:q})=>Cm.setDisabled(T,q),"mutationFn"),onSuccess:r(()=>{w()},"onSuccess"),onError:r(T=>{a({title:"Toggle failed",body:T.message,tone:"error"})},"onError")}),C=ye({mutationFn:r(({type:T,paused:q})=>Cm.setOverridePaused(T,q),"mutationFn"),onSuccess:r(()=>{w()},"onSuccess"),onError:r(T=>{a({title:"Override toggle failed",body:T.message,tone:"error"})},"onError")}),A=ye({mutationFn:r(T=>Cm.reload(T),"mutationFn"),onSuccess:r(T=>{w(),vF(T.type),aY(T.type),a({title:"Adapter reloaded",body:`Type "${T.type}" reloaded.${T.version?` (v${T.version})`:""}`,tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Reload failed",body:T.message,tone:"error"})},"onError")}),R=ye({mutationFn:r(T=>Cm.reinstall(T),"mutationFn"),onSuccess:r(T=>{w(),vF(T.type),aY(T.type),a({title:"Adapter reinstalled",body:`Type "${T.type}" updated from npm.${T.version?` (v${T.version})`:""}`,tone:"success"})},"onSuccess"),onError:r(T=>{a({title:"Reinstall failed",body:T.message,tone:"error"})},"onError")}),E=(j??[]).filter(T=>T.source==="builtin"),O=(j??[]).filter(T=>T.source==="external"),L=(j??[]).filter(T=>T.source==="external"&&T.overriddenBuiltin).filter(T=>!E.some(q=>q.type===T.type)).map(T=>({type:T.type,label:sf(T.type),overriddenBy:[T.packageName,T.version?`v${T.version}`:void 0].filter(Boolean).join(" "),overridePaused:!!T.overridePaused,menuDisabled:!!T.disabled}));if(S)return(0,t.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading adapters..."});const $=N.isPending||_.isPending||I.isPending||C.isPending||A.isPending||R.isPending;return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Pm,{className:"h-6 w-6 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Adapters"}),(0,t.jsx)(dt,{variant:"outline",className:"text-amber-600 border-amber-400",children:"Alpha"})]}),(0,t.jsxs)(Xs,{open:h,onOpenChange:p,children:[(0,t.jsx)(Fw,{asChild:!0,children:(0,t.jsxs)(F,{size:"sm",className:"gap-2",children:[(0,t.jsx)(xn,{className:"h-4 w-4"}),"Install Adapter"]})}),(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Install External Adapter"}),(0,t.jsxs)(Dn,{children:["Add an adapter from npm or a local path. The adapter package must export ",(0,t.jsx)("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:"createServerAdapter()"}),"."]})]}),(0,t.jsxs)("div",{className:"grid gap-4 py-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("button",{type:"button",className:U("inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors",d?"border-border text-muted-foreground hover:text-foreground hover:bg-accent/50":"border-foreground bg-accent text-foreground"),onClick:r(()=>u(!1),"onClick"),children:[(0,t.jsx)(Eh,{className:"h-3.5 w-3.5"}),"npm package"]}),(0,t.jsxs)("button",{type:"button",className:U("inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors",d?"border-foreground bg-accent text-foreground":"border-border text-muted-foreground hover:text-foreground hover:bg-accent/50"),onClick:r(()=>u(!0),"onClick"),children:[(0,t.jsx)(Io,{className:"h-3.5 w-3.5"}),"Local path"]})]}),d?(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsx)(Vs,{htmlFor:"adapterLocalPath",children:"Path to adapter package"}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(Rt,{id:"adapterLocalPath",className:"flex-1 font-mono text-xs",placeholder:"/mnt/e/Projects/my-adapter or E:\\Projects\\my-adapter",value:i,onChange:r(T=>o(T.target.value),"onChange")}),(0,t.jsx)(ud,{})]}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Accepts Linux, WSL, and Windows paths. Windows paths are auto-converted."})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsx)(Vs,{htmlFor:"adapterPackageName",children:"Package Name"}),(0,t.jsx)(Rt,{id:"adapterPackageName",placeholder:"my-paperclip-adapter",value:i,onChange:r(T=>o(T.target.value),"onChange")})]}),(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsx)(Vs,{htmlFor:"adapterVersion",children:"Version (optional)"}),(0,t.jsx)(Rt,{id:"adapterVersion",placeholder:"latest",value:l,onChange:r(T=>c(T.target.value),"onChange")})]})]})]}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>p(!1),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{onClick:r(()=>N.mutate({packageName:i,version:l||void 0,isLocalPath:d}),"onClick"),disabled:!i||N.isPending,children:N.isPending?"Installing...":"Install"})]})]})]})]}),(0,t.jsx)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)(Is,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),(0,t.jsxs)("div",{className:"space-y-1 text-sm",children:[(0,t.jsx)("p",{className:"font-medium text-foreground",children:"External adapters are alpha."}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"The adapter plugin system is under active development. APIs and storage format may change. Use the power icon to hide adapters from agent menus without removing them."})]})]})}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Pm,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h2",{className:"text-base font-semibold",children:"External Adapters"})]}),O.length===0?(0,t.jsx)(Gs,{className:"bg-muted/30",children:(0,t.jsxs)(za,{className:"flex flex-col items-center justify-center py-10",children:[(0,t.jsx)(Pm,{className:"h-10 w-10 text-muted-foreground mb-4"}),(0,t.jsx)("p",{className:"text-sm font-medium",children:"No external adapters installed"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:"Install an adapter package to extend model support."})]})}):(0,t.jsx)(Gs,{className:"block py-0",children:(0,t.jsx)("ul",{className:"divide-y",children:O.map(T=>{const q=T.overriddenBuiltin,B=q&&!!T.overridePaused,K=q?{...T,disabled:B??!1}:T;return(0,t.jsx)(B$,{adapter:K,canRemove:!0,onToggle:q?(z,D)=>C.mutate({type:z,paused:D}):(z,D)=>I.mutate({type:z,disabled:D}),onRemove:r(z=>g(z),"onRemove"),onReload:r(z=>A.mutate(z),"onReload"),onReinstall:T.isLocalPath?void 0:z=>y(T),isToggling:q?C.isPending:I.isPending,isReloading:A.isPending,isReinstalling:R.isPending,toggleTitleDisabled:q?"Pause external override":void 0,toggleTitleEnabled:q?"Resume external override":void 0,disabledBadgeLabel:q?"Override paused":void 0},T.type)})})})]}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(Pm,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Built-in Adapters"})]}),E.length===0&&L.length===0?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"No built-in adapters found."}):(0,t.jsx)(Gs,{className:"block py-0",children:(0,t.jsxs)("ul",{className:"divide-y",children:[E.map(T=>(0,t.jsx)(B$,{adapter:T,canRemove:!1,onToggle:r((q,B)=>I.mutate({type:q,disabled:B}),"onToggle"),onRemove:r(()=>{},"onRemove"),isToggling:$},T.type)),L.map(T=>(0,t.jsx)(B$,{adapter:{type:T.type,label:T.label,source:"builtin",modelsCount:0,loaded:!0,disabled:T.menuDisabled,capabilities:{supportsInstructionsBundle:!1,supportsSkills:!1,supportsLocalAgentJwt:!1,requiresMaterializedRuntimeSkills:!1,supportsAcp:!1}},canRemove:!1,onToggle:r((q,B)=>I.mutate({type:q,disabled:B}),"onToggle"),onRemove:r(()=>{},"onRemove"),isToggling:$,overriddenBy:T.overridePaused?void 0:T.overriddenBy},T.type))]})})]}),(0,t.jsx)(Xs,{open:x!==null,onOpenChange:r(T=>{T||g(null)},"onOpenChange"),children:(0,t.jsxs)(Zs,{children:[(0,t.jsxs)(Sn,{children:[(0,t.jsx)(rn,{children:"Remove Adapter"}),(0,t.jsxs)(Dn,{children:["Are you sure you want to remove the ",(0,t.jsx)("strong",{children:x})," adapter? It will be unregistered and removed from the adapter store.",x&&j?.find(T=>T.type===x)?.packageName&&(0,t.jsx)(t.Fragment,{children:" npm packages will be cleaned up from disk."})," ","This action cannot be undone."]})]}),(0,t.jsxs)(yr,{children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>g(null),"onClick"),children:"Cancel"}),(0,t.jsx)(F,{variant:"destructive",disabled:_.isPending,onClick:r(()=>{x&&_.mutate(x,{onSettled:r(()=>g(null),"onSettled")})},"onClick"),children:_.isPending?"Removing...":"Remove"})]})]})}),(0,t.jsx)(Izt,{adapter:v,open:v!==null,isReinstalling:R.isPending,onConfirm:r(()=>{v&&R.mutate(v.type,{onSettled:r(()=>y(null),"onSettled")})},"onConfirm"),onCancel:r(()=>y(null),"onCancel")})]})}r(Soe,"AdapterManager");function Coe(){const e=ja(),{companyPrefix:s,pluginId:n,pluginRoutePath:a}=e,i=e["*"],{companies:o,selectedCompanyId:l}=fs(),{setBreadcrumbs:c}=$n(),d=(0,m.useMemo)(()=>{if(!s)return null;const j=s.toUpperCase();return o.find(S=>S.issuePrefix.toUpperCase()===j)??null},[o,s]),u=!!s&&!d,h=(0,m.useMemo)(()=>d?d.id:s?null:l??null,[d,s,l]),p=(0,m.useMemo)(()=>h?o.find(j=>j.id===h)?.issuePrefix??null:null,[o,h]),{data:x}=ee({queryKey:P.plugins.uiContributions,queryFn:r(()=>Jo.listUiContributions(),"queryFn"),enabled:!!h&&(!!n||!!a)}),g=(0,m.useMemo)(()=>{if(!x)return null;if(n){const S=x.find(N=>N.pluginId===n);if(!S)return null;const w=S.slots.find(N=>N.type==="page");return w?{...w,pluginId:S.pluginId,pluginKey:S.pluginKey,pluginDisplayName:S.displayName,pluginVersion:S.version}:null}if(!a)return null;const j=x.flatMap(S=>{const w=S.slots.find(N=>N.type==="page"&&N.routePath===a);return w?[{...w,pluginId:S.pluginId,pluginKey:S.pluginKey,pluginDisplayName:S.displayName,pluginVersion:S.version}]:[]});return j.length!==1?null:j[0]??null},[n,a,x]),v=(0,m.useMemo)(()=>({companyId:h??null,companyPrefix:p}),[h,p]),y=(0,m.useMemo)(()=>{if(!a||!x)return!1;const j=x.flatMap(S=>S.slots.map(w=>({...w,pluginId:S.pluginId,pluginKey:S.pluginKey,pluginDisplayName:S.displayName,pluginVersion:S.version})));return Fz(j,a)!==null},[x,a]);if((0,m.useEffect)(()=>{if(g){if(y){c([{label:Azt(g,i)}]);return}c([{label:"Plugins",href:"/company/settings/instance/plugins"},{label:g.pluginDisplayName}])}},[g,i,c,y]),!h)return u?(0,t.jsx)(uu,{scope:"invalid_company_prefix",requestedPrefix:s}):(0,t.jsx)("div",{className:"space-y-4",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select an organization to view this page."})});if(!x)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading…"});if(!n&&a&&x.filter(j=>j.slots.some(S=>S.type==="page"&&S.routePath===a)).length>1)return(0,t.jsxs)("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:["Multiple plugins declare the route ",(0,t.jsx)("code",{children:a}),". Use the plugin-id route until the conflict is resolved."]});if(!g){if(a)return(0,t.jsx)(uu,{scope:"board"});const j=n?`/company/settings/instance/plugins/${n}`:"/company/settings/instance/plugins";return(0,t.jsx)(vn,{to:j,replace:!0})}return(0,t.jsxs)("div",{className:"space-y-4",children:[!y&&(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)(F,{variant:"ghost",size:"sm",asChild:!0,children:(0,t.jsxs)(Qe,{to:p?`/${p}/dashboard`:"/dashboard",children:[(0,t.jsx)(sc,{className:"h-4 w-4 mr-1"}),"Back"]})})}),(0,t.jsx)(fu,{slot:g,context:v,className:"min-h-(--sz-200px)",missingBehavior:"placeholder"})]})}r(Coe,"PluginPage");function Azt(e,s){return Rzt(s)??e.displayName??e.pluginDisplayName}r(Azt,"resolveRouteSidebarPageTitle");function Rzt(e){const s=(e??"").split("/").filter(Boolean).map(Tzt);return s.length===0?null:s[0]==="page"&&s.length>1?_oe(s.slice(1).join("/"),{preserveCase:!0}):_oe(s[0]??null)}r(Rzt,"titleFromRouteSplat");function _oe(e,s={}){const n=e?.trim();if(!n)return null;const a=n.split("/").filter(Boolean).at(-1)??n,i=(a.split("::").at(-1)??a).replace(/\.[^.]+$/,"").replace(/[-_]+/g," ").trim();return i?s.preserveCase?i:i.replace(/\b\w/g,o=>o.toUpperCase()):null}r(_oe,"titleFromPath");function Tzt(e){try{return decodeURIComponent(e)}catch{return e}}r(Tzt,"decodeRouteSegment");var QA="w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-sm leading-5 outline-none focus-visible:ring-2 focus-visible:ring-ring",Ioe=r(e=>e.status==="fail"||e.checks.some(s=>s.code==="adapter_auth_missing"),"blocking");function Ezt(){const{selectedCompanyId:e}=fs(),[s]=Ri();return e?(0,t.jsx)(Pzt,{companyId:e,name:s.get("name")??"",adapterType:s.get("adapterType")??"",runnerProvider:s.get("runnerProvider")??"codex",createdAgentId:s.get("createdAgentId")},`${e}:${s.get("name")}:${s.get("adapterType")}:${s.get("runnerProvider")}`):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select an organization to create an agent."})}r(Ezt,"NewAgentSetup");function Pzt({companyId:e,name:s,adapterType:n,runnerProvider:a,createdAgentId:i}){const o=Wn(),l=Ht(),{openNewIssue:c}=Lo(),d=Gfe(`${e}:new-agent`),u=n==="paperclip_runner",h=u?a==="claude"?"claude_local":a==="opencode"?"opencode_local":"codex_local":n,p=h==="claude_local"||h==="codex_local"||h==="grok_local"?h:null,x=h==="opencode_local"||h==="pi_local",g=P8e(h),v=x||h==="hermes_local",y=v||!!tY[n],j=!["cursor_cloud","hermes_gateway"].includes(n),[S,w]=(0,m.useState)(""),[N,_]=(0,m.useState)(""),[I,C]=(0,m.useState)(""),[A,R]=(0,m.useState)("kimi"),[E,O]=(0,m.useState)(i?"saved":p?"connect":"runtime"),[L,$]=(0,m.useState)(""),T=u?[]:jT(n,L),[q,B]=(0,m.useState)(""),[K,z]=(0,m.useState)(!1),[D,V]=(0,m.useState)(""),[H,Z]=(0,m.useState)("openrouter"),[Y,ie]=(0,m.useState)(""),[se,X]=(0,m.useState)(null),[le,oe]=(0,m.useState)(()=>h==="opencode_local"?{provider:"openrouter",method:"api_key",mode:"responsible_user"}:void 0),[te,J]=(0,m.useState)(null),Q=le??te?.aiConnection,[pe,re]=(0,m.useState)(""),[ne,ae]=(0,m.useState)(""),[me,he]=(0,m.useState)(null),Ie=ee({queryKey:P.agents.detail(i??"new"),queryFn:r(()=>Wt.get(i,e),"queryFn"),enabled:!!i,retry:!1}),de=me??(Ie.data?.companyId===e?Ie.data:null),[ve,Te]=(0,m.useState)(!1),[fe,Ce]=(0,m.useState)("idle"),[Xe,Oe]=(0,m.useState)(null),[tt,ce]=(0,m.useState)(null),$e=(0,m.useRef)(0),mt=(0,m.useRef)(!1);(0,m.useEffect)(()=>()=>{$e.current++},[]);const it=r(()=>{$e.current++,Oe(null),Ce("idle"),ce(null)},"resetTest"),Ke=ee({queryKey:P.adapters.all,queryFn:Cm.list}),Ge=ee({queryKey:P.agents.list(e),queryFn:r(()=>Wt.list(e),"queryFn")}),rt=ee({queryKey:P.environments.list(e),queryFn:r(()=>_i.list(e),"queryFn")}),jt=ee({queryKey:P.instance.settings,queryFn:Tr.get}),st=ee({queryKey:P.instance.experimentalSettings,queryFn:Tr.getExperimental}),Nt=ee({queryKey:P.instance.generalSettings,queryFn:Tr.getGeneral}),at=ee({queryKey:P.environments.capabilities(e),queryFn:r(()=>_i.capabilities(e),"queryFn")}),Ee=ee({queryKey:P.agents.adapterModels(e,h,null,Q?.provider),queryFn:r(()=>Wt.adapterModels(e,h,{provider:Q?.provider}),"queryFn"),enabled:!!h&&j,retry:!1}),Ne=ee({queryKey:P.secrets.list(e),queryFn:r(()=>mr.list(e),"queryFn"),enabled:y&&n!=="cursor_cloud"}),He=ee({queryKey:P.secrets.myUserSecrets(e),queryFn:r(()=>mr.listMyUserSecrets(e),"queryFn"),enabled:y&&n!=="cursor_cloud",retry:!1}),St=ZU(Nt.data?.executionMode,rt.data??[]),Ft=st.data?.enableManagedSandboxOnly===!0;let ts=null,Ot=null;try{ts=St.forced?St.kubernetesEnvironment?.id??null:iw({agentDefaultEnvironmentId:D||null,instanceDefaultEnvironmentId:jt.data?.defaultEnvironmentId??null,localDefaultEnvironmentId:lw(rt.data??[]),managedSandboxOnly:Ft,managedSandboxEnvironmentId:ow(rt.data??[]),visibleEnvironmentIds:(rt.data??[]).map(Me=>Me.id)})}catch(Me){Ot=Me instanceof Error?Me.message:"Could not resolve the environment."}const Be=rt.data?.find(Me=>Me.id===ts),Ve=typeof Be?.config?.provider=="string"?Be.config.provider:"",ut=Be?.driver==="sandbox"&&at.data?.sandboxProviders?.[Ve]?.supportsLoginPty===!0,qe=tY[n]??g[H]??"API_KEY",Gt=He.data?.find(Me=>Me.definition.key===qe&&Me.secret),We=Ne.data?.find(Me=>Me.key===qe&&Me.status==="active"),$t=n==="cursor_cloud"?null:se??(We?{type:"secret_ref",secretId:We.id,version:"latest"}:Gt?{type:"user_secret_ref",key:qe,version:"latest"}:null),Dt=n==="kimi_local"&&!!(Y.trim()||$t),Cs=!!Vc(),ze=Yfe(n,{cloud:Cs,nativeRunnerEnabled:st.data?.enableNativeRunner===!0})&&Ke.data?.some(Me=>Me.type===n&&Me.loaded&&!Me.disabled&&!Fm(n).comingSoon),ct=!!(ze&&!Ot&&!rt.isPending&&!jt.isPending&&!st.isPending&&!Nt.isPending&&!Ge.isPending&&!at.isPending&&!rt.error&&!jt.error&&!st.error&&!Nt.error&&!Ge.error&&!at.error&&(!(Ft||St.forced)||ts)),Pt=fe==="running"||ve;function ke(Me=te,bt=$t){const ft={...Xg,adapterType:n,model:L||(h==="codex_local"?tw:""),thinkingEffort:q,dangerouslyBypassSandbox:n==="codex_local",envBindings:Me?.env??{},...u?{adapterSchemaValues:{provider:a==="claude"?"acpx":a,...a==="claude"?{acpxAgent:"claude"}:{}}}:{}},Ye=Xw(n).buildAdapterConfig(ft);return u&&Object.assign(Ye,{provider:a==="claude"?"acpx":a,...a==="claude"?{acpxAgent:"claude"}:{},...L?{model:L}:{}}),!Q&&!Me?.aiConnection&&y&&bt&&(n==="hermes_gateway"?Ye.apiKey=bt:Ye.env={...Ye.env??{},[qe]:bt}),n==="cursor_cloud"&&Object.assign(Ye,{repoUrl:pe.trim(),...ne.trim()?{repoStartingRef:ne.trim()}:{}}),n==="hermes_gateway"&&(Ye.apiBaseUrl=S.trim()),Dt&&(delete Ye.model,Ye.env={...Ye.env??{},KIMI_MODEL_NAME:{type:"plain",value:N.trim()},KIMI_MODEL_PROVIDER_TYPE:{type:"plain",value:A},...I.trim()?{KIMI_MODEL_BASE_URL:{type:"plain",value:I.trim()}}:{}}),Ye}r(ke,"buildConfig");function ys(Me=te){if(x&&(!L.trim()||!L.includes("/")))throw new Error("Choose or enter a model in provider/model format.");if(n==="cursor_cloud"&&!/^https:\/\/github\.com\/[^/]+\/[^/]+/.test(pe.trim()))throw new Error("Enter a GitHub repository URL.");if(["cursor_cloud","hermes_gateway"].includes(n)&&!Y.trim()&&!$t)throw new Error(n==="cursor_cloud"?"Enter a Cursor API key.":`Enter ${qe} or select an organization secret.`);if(n==="hermes_gateway")try{const bt=new URL(S.trim());if(!["https:","http:"].includes(bt.protocol))throw new Error}catch{throw new Error("Enter the Hermes API base URL.")}if(Dt&&!N.trim())throw new Error("Enter the Kimi API model name.");return ke(Me)}r(ys,"preparedConfig");function wt(Me=te){return Q||Me?.aiConnection?{}:{...Me?.credentials,...y&&Y.trim()?{[qe]:Y.trim()}:{}}}r(wt,"pendingCredentials");async function Ut(Me=te){if(!ct)return!1;const bt=++$e.current;Ce("running"),Oe(null),ce(null);try{const ft=await ys(Me),Ye=await Upe({companyId:e,adapterType:n,providerAdapter:h,adapterConfig:ft,testCredentials:wt(Me),aiConnection:le??Me?.aiConnection,environmentId:ts});return bt!==$e.current?!1:(Oe(Ye),Ce(Ioe(Ye)?"fail":Ye.status),!Ioe(Ye)&&(!p||Ye.checks.some(gs=>gs.code.endsWith("hello_probe_passed"))))}catch(ft){return bt===$e.current&&(ce(ft instanceof Error?ft.message:"Could not test the agent."),Ce("fail")),!1}}r(Ut,"runTest");async function De(){if(mt.current||i||de||!ct||!s.trim()||fe==="running"||fe==="fail"||p&&!te)return;mt.current=!0,Te(!0),ce(null);const Me=[];let bt=!1;try{const ft=ys(),Ye=wt();if(Object.keys(Ye).length&&!await Ut())return;for(const[_t,Xt]of Object.entries(Ye)){const zs=await(p?Vpe:T8e)(e,_t,Xt);Me.push(zs),n==="hermes_gateway"&&_t==="API_SERVER_KEY"?ft.apiKey=zs.binding:ft.env={...ft.env??{},[_t]:zs.binding}}const gs=Ge.data??[],Ct=gs.find(_t=>_t.role==="ceo"&&_t.status!=="terminated"),os=await Wt.hire(e,{name:s.trim(),appearance:d.appearance,role:gs.length?"general":"ceo",...Ct?{reportsTo:Ct.id}:{},adapterType:n,adapterConfig:ft,defaultEnvironmentId:D||(St.forced||Ft?ts:null),runtimeConfig:{...K0e({heartbeatEnabled:!1}),...Q?{aiConnection:Q}:{}},budgetMonthlyCents:0,...te?.storedSessionId?{storedSessionId:te.storedSessionId}:{},...te?.applyStoredClaudeLogin?{applyStoredClaudeLogin:!0}:{}});bt=!0,ie(""),J(null),he(os.agent),d.clear(),O("saved"),o(`/agents/new?${new URLSearchParams({name:os.agent.name,adapterType:n,runnerProvider:a,createdAgentId:os.agent.id})}`,{replace:!0}),l.setQueryData(P.agents.detail(os.agent.id),os.agent),await Promise.all([l.invalidateQueries({queryKey:P.agents.list(e)}),l.invalidateQueries({queryKey:P.approvals.list(e)})])}catch(ft){ce(ft instanceof Error?ft.message:"Could not create the agent.")}finally{if(!bt)try{await Promise.all(Me.map(ft=>ft.remove()))}catch{ce(ft=>`${ft?`${ft} `:""}Could not remove an unused setup credential. Remove it from Secrets before retrying.`)}l.invalidateQueries({queryKey:P.secrets.myUserSecrets(e)}),l.invalidateQueries({queryKey:P.secrets.list(e)}),mt.current=!1,Te(!1)}}if(r(De,"finish"),i&&!de)return(0,t.jsx)("p",{role:Ie.error?"alert":"status",className:"text-sm text-muted-foreground",children:Ie.error?"Could not load the created agent. Return to Agents to view it.":"Loading your agent…"});if(!s||!n)return(0,t.jsx)(Jfe,{open:!0,initialAdapter:n,onClose:r(()=>o("/agents/all"),"onClose"),onContinue:r(Me=>o(`/agents/new?${new URLSearchParams(Me)}`,{replace:!0}),"onContinue")});const Se=[...p?["connect"]:[],"runtime","saved"],nt={connect:"Connect",runtime:"Configure",saved:"Confirmation"},xt=de?.defaultEnvironmentId?rt.data?.find(Me=>Me.id===de.defaultEnvironmentId):Be,ms=de?.adapterConfig?.env?.KIMI_MODEL_NAME,ht=de?.adapterConfig?.model||(typeof ms=="string"?ms:ms?.value)||L||"Default",zt=n==="cursor_cloud"?"Cursor Cloud":n==="hermes_gateway"?"Hermes Gateway":xt?cw(xt):"Local machine",as=Ke.error??rt.error??jt.error??st.error??Nt.error??Ge.error??at.error;return(0,t.jsx)(Ipe,{reducedMotion:"user",children:(0,t.jsxs)("div",{className:"mx-auto flex max-w-5xl flex-col gap-8 py-6",children:[(0,t.jsxs)("header",{className:"flex items-center gap-4",children:[(0,t.jsx)(oC,{appearance:de?.appearance??d.appearance,size:256,className:"size-48",trackingScope:"page",state:de||fe==="pass"?"success":fe==="running"?"loading":"sleepy",muted:!de&&fe!=="pass"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",children:s}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(sK,{type:h}),(0,t.jsx)("span",{children:Fm(h).label}),u&&(0,t.jsxs)("span",{children:["·"," ",a==="codex"?"Native app server runner":"Paperclip Runner"]})]})]})]}),Ot&&!rt.isPending&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:Ot}),as&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:as.message}),Ke.data&&!ze&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:"This adapter is unavailable. Choose an enabled adapter."}),(Ft||St.forced)&&!rt.isPending&&!ts&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:"No managed environment is available. Configure an environment before continuing."}),(0,t.jsxs)("div",{className:"flex flex-col gap-8 md:flex-row",children:[(0,t.jsx)("nav",{"aria-label":"Agent setup steps",className:"shrink-0 md:w-44",children:(0,t.jsx)("ol",{className:"flex flex-wrap gap-2 md:flex-col",children:Se.map((Me,bt)=>(0,t.jsx)("li",{children:(0,t.jsxs)("button",{type:"button","aria-current":Me===E?"step":void 0,disabled:Pt||!!de||bt>Se.indexOf(E),onClick:r(()=>O(Me),"onClick"),className:U("flex w-full items-center gap-3 rounded-md px-3 py-3 text-left text-sm",Me===E?"bg-accent font-medium":"text-muted-foreground"),children:[(0,t.jsx)("span",{className:U("flex size-6 shrink-0 items-center justify-center rounded-full border text-xs",Me===E?"border-foreground bg-foreground text-background":"border-border"),children:bt+1}),nt[Me]]})},Me))})}),(0,t.jsx)("div",{className:"min-w-0 flex-1",children:(0,t.jsx)(Jw,{mode:"wait",initial:!1,children:(0,t.jsx)(Yo.div,{...G8e,children:E==="connect"&&p?(0,t.jsxs)(Lnt,{className:"mx-auto",children:[(0,t.jsx)("div",{className:"mb-8",children:(0,t.jsx)(V0e,{title:"Connect a model",lede:`Connect ${s} to ${p==="claude_local"?"Claude":p==="grok_local"?"Grok":"OpenAI"}.`,center:!0})}),(0,t.jsx)(txe,{companyId:e,adapterType:p,environmentId:ts,canLogin:ut,localEnvironment:Be?.driver==="local",onBack:r(()=>o("/agents/all"),"onBack"),testConnection:Ut,testError:tt??(Xe?.checks.find(Me=>Me.level==="error")??Xe?.checks.find(Me=>Me.code.includes("hello_probe")&&Me.level==="warn"))?.message,onConnected:r(Me=>{J(Me),it(),O("runtime")},"onConnected")},ts??"local")]}):E==="saved"&&de?(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-6 rounded-lg border border-border p-6",children:[(0,t.jsxs)("h2",{className:"flex items-center gap-3 text-lg font-semibold",children:[(0,t.jsx)(xs,{className:"size-5"}),de.status==="pending_approval"?"Agent submitted for approval":"Your agent is ready"]}),(0,t.jsxs)("dl",{className:"grid grid-cols-2 gap-4 text-sm",children:[(0,t.jsx)("dt",{className:"text-muted-foreground",children:"Adapter"}),(0,t.jsx)("dd",{children:Fm(n).label}),j&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dt",{className:"text-muted-foreground",children:"Model"}),(0,t.jsx)("dd",{className:"break-all",children:String(ht)})]}),(0,t.jsx)("dt",{className:"text-muted-foreground",children:"Environment"}),(0,t.jsx)("dd",{children:zt})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:de.status==="pending_approval"?"An organization administrator must approve this agent before it can work.":"Assign a task when you’re ready for this agent to work."})]}),(0,t.jsxs)("div",{className:"flex flex-wrap justify-between gap-3",children:[(0,t.jsxs)(F,{variant:"outline",onClick:r(()=>o(`${Ku(de)}/runtime`),"onClick"),children:[(0,t.jsx)(wz,{className:"size-4"}),"Edit configuration"]}),(0,t.jsxs)(F,{disabled:de.status==="pending_approval",onClick:r(()=>c({assigneeAgentId:de.id,status:"todo"}),"onClick"),children:["Assign ",de.name," a Task",(0,t.jsx)(Zo,{className:"size-4"})]})]})]}):(0,t.jsxs)("form",{className:"space-y-8",onSubmit:r(Me=>{Me.preventDefault(),De()},"onSubmit"),children:[(0,t.jsx)("h2",{className:"text-xl font-semibold",children:"Configure your agent"}),(0,t.jsxs)("fieldset",{disabled:Pt,className:"space-y-8",children:[(0,t.jsxs)("section",{className:"space-y-5",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold",children:"Runtime"}),qU(h)&&(te&&!Q?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Using the connection selected in the Connect step."}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>O("connect"),"onClick"),children:"Change connection"})]}):(0,t.jsx)(zpe,{companyId:e,agentName:s,adapterType:h,model:L,environmentId:ts??void 0,value:Q,onChange:r(Me=>{oe(Me),it()},"onChange")})),Ee.error&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:"Could not load models. Retry or enter a model ID manually."}),(j&&!Dt||T.length>0)&&(0,t.jsxs)("div",{className:"grid items-start gap-5 sm:grid-cols-2",children:[j&&!Dt&&(0,t.jsx)(tK,{models:Ee.data??[],value:L,onChange:r(Me=>{$(Me),q&&!jT(n,Me).includes(q)&&B("");const bt=Me.split("/")[0];x&&Kpe[bt]&&bt!==H&&(Z(bt),ie(""),X(null)),it()},"onChange"),open:K,onOpenChange:z,allowDefault:!x,required:x,creatable:!0,groupByProvider:x}),T.length>0&&(0,t.jsx)(Ss,{label:"Thinking effort",children:(0,t.jsxs)("select",{"aria-label":"Thinking effort",className:QA,value:q,onChange:r(Me=>{B(Me.target.value),it()},"onChange"),children:[(0,t.jsx)("option",{value:"",children:"Auto"}),T.map(Me=>(0,t.jsx)("option",{value:Me,children:Me},Me))]})})]}),sY[n]&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:sY[n]}),j&&Ee.error&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Couldn’t load models. You can enter a model ID manually."}),y&&!Q&&(0,t.jsxs)("div",{className:"grid gap-5 sm:grid-cols-2",children:[v&&(0,t.jsx)(Ss,{label:"API key provider",children:(0,t.jsx)("select",{"aria-label":"API key provider",className:QA,value:H,onChange:r(Me=>{Z(Me.target.value),$(""),ie(""),X(null),it()},"onChange"),children:Object.keys(g).map(Me=>(0,t.jsx)("option",{value:Me,children:Me==="openrouter"?"OpenRouter":Me==="openai"?"OpenAI":Me==="anthropic"?"Anthropic":{google:"Google",xai:"xAI",groq:"Groq",opencode:"OpenCode"}[Me]??Me},Me))})}),(0,t.jsx)("div",{className:n==="cursor_cloud"?"sm:col-span-2":void 0,children:(0,t.jsx)(Ss,{label:qe,children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(Rt,{"aria-label":qe,type:"password",autoComplete:"off",value:Y,onChange:r(Me=>{ie(Me.target.value),X(null),it()},"onChange"),placeholder:$t?"Using saved key":["cursor_cloud","hermes_gateway"].includes(n)?"Required":"Optional if already configured"}),n==="cursor_cloud"&&(0,t.jsx)("a",{href:"https://cursor.com/dashboard/api?section=user-keys#user-api-keys",target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground",children:"get api key"})]})})}),n!=="cursor_cloud"&&(0,t.jsx)("div",{className:v?"sm:col-span-2":void 0,children:(0,t.jsx)(Ss,{label:"Or use an organization secret",children:(0,t.jsx)(QU,{secretId:$t&&typeof $t=="object"&&$t.type==="secret_ref"?$t.secretId:"",secrets:Ne.data??[],disabled:Pt,onSelect:r(Me=>{X({type:"secret_ref",secretId:Me,version:"latest"}),ie(""),it()},"onSelect")})})}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground sm:col-span-2",children:["New keys are saved as organization secrets when you finish setup.",x&&` Use a ${H}/model ID.`]})]}),n==="hermes_gateway"&&(0,t.jsx)(Ss,{label:"Hermes API base URL",children:(0,t.jsx)(Rt,{"aria-label":"Hermes API base URL",value:S,onChange:r(Me=>{w(Me.target.value),it()},"onChange"),placeholder:"https://hermes.example.com"})}),Dt&&(0,t.jsxs)("div",{className:"grid gap-5 sm:grid-cols-2",children:[(0,t.jsx)(Ss,{label:"Kimi API model name",children:(0,t.jsx)(Rt,{"aria-label":"Kimi API model name",value:N,onChange:r(Me=>{_(Me.target.value),it()},"onChange"),placeholder:"kimi-for-coding"})}),(0,t.jsx)(Ss,{label:"Kimi API protocol",children:(0,t.jsx)("select",{"aria-label":"Kimi API protocol",className:QA,value:A,onChange:r(Me=>{R(Me.target.value),it()},"onChange"),children:["kimi","anthropic","openai"].map(Me=>(0,t.jsx)("option",{children:Me},Me))})}),(0,t.jsx)(Ss,{label:"Kimi API base URL",hint:"Optional override for your provider endpoint.",children:(0,t.jsx)(Rt,{"aria-label":"Kimi API base URL",value:I,onChange:r(Me=>{C(Me.target.value),it()},"onChange"),placeholder:"Provider default"})})]}),n==="cursor_cloud"&&(0,t.jsxs)("div",{className:"grid gap-5 sm:grid-cols-2",children:[(0,t.jsx)(Ss,{label:"GitHub repository",children:(0,t.jsx)(Rt,{"aria-label":"GitHub repository",value:pe,onChange:r(Me=>{re(Me.target.value),it()},"onChange"),placeholder:"https://github.com/your-org/repo"})}),(0,t.jsx)(Ss,{label:"Branch",children:(0,t.jsx)(Rt,{"aria-label":"Branch",placeholder:"Repository default",value:ne,onChange:r(Me=>{ae(Me.target.value),it()},"onChange")})})]})]}),!["cursor_cloud","hermes_gateway"].includes(n)&&(0,t.jsxs)("section",{className:"space-y-5",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold",children:"Environment"}),(0,t.jsxs)("select",{"aria-label":"Environment",className:QA,value:D,disabled:St.forced||Ft,onChange:r(Me=>{V(Me.target.value),J(null),it(),p&&O("connect")},"onChange"),children:[(0,t.jsxs)("option",{value:"",children:["Default: ",zt]}),(rt.data??[]).filter(Me=>Me.status==="active").map(Me=>(0,t.jsx)("option",{value:Me.id,children:cw(Me)},Me.id))]})]})]}),(0,t.jsx)(Wpe,{state:fe,result:Xe,error:tt,disabled:!ct||Pt,onTest:r(()=>{Ut()},"onTest")}),tt&&fe!=="fail"&&(0,t.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:tt}),(0,t.jsxs)("div",{className:"flex justify-between border-t border-border py-5",children:[p?(0,t.jsxs)(F,{type:"button",variant:"ghost",disabled:Pt,onClick:r(()=>O("connect"),"onClick"),children:[(0,t.jsx)(sc,{className:"size-4"}),"Connection"]}):(0,t.jsx)("span",{}),(0,t.jsxs)(F,{type:"submit",disabled:!ct||Pt||fe==="fail"||!!(p&&!te),children:[ve?"Creating…":"Finish setup",(0,t.jsx)(xs,{className:"size-4"})]})]})]})},E)})})]})]})})}r(Pzt,"Setup");function Mzt(){const{setBreadcrumbs:e}=$n();return(0,m.useEffect)(()=>{e([{label:"Agents",href:"/agents"},{label:"New agent"}])},[e]),(0,t.jsx)(Ezt,{})}r(Mzt,"NewAgent");var U3="paperclip:pending-invite-token";function K7(){return typeof window<"u"&&typeof window.localStorage<"u"}r(K7,"canUseStorage");function Aoe(e){const s=e.trim();if(!(!s||!K7()))try{window.localStorage.setItem(U3,s)}catch{}}r(Aoe,"rememberPendingInviteToken");function GA(e){if(K7())try{const s=window.localStorage.getItem(U3);if(e&&s!==e.trim())return;window.localStorage.removeItem(U3)}catch{}}r(GA,"clearPendingInviteToken");function Dzt(){if(!K7())return null;try{const e=window.localStorage.getItem(U3)?.trim();return e?`/invite/${e}`:null}catch{return null}}r(Dzt,"getRememberedInvitePath");var Roe=[" ",".","·","▪","▫","○"],Lzt=1e3/24,YA=[[" ╭────╮ "," ╭╯╭──╮│ "," │ │ ││ "," │ │ ││ "," │ │ ││ "," │ │ ││ "," │ ╰──╯│ "," ╰─────╯ "],[" ╭─────╮ "," │╭──╮╰╮ "," ││ │ │ "," ││ │ │ "," ││ │ │ "," ││ │ │ "," │╰──╯ │ "," ╰────╯ "]];function Toe(e){const s=document.createElement("span");s.textContent="M",s.style.cssText="position:absolute;visibility:hidden;white-space:pre;font-size:11px;font-family:monospace;line-height:1;",e.appendChild(s);const n=s.getBoundingClientRect();return e.removeChild(s),{w:n.width,h:n.height}}r(Toe,"measureChar");function $zt(e){let s=0;for(const n of e)s=Math.max(s,n.length);return{width:s,height:e.length}}r($zt,"spriteSize");function Ozt(){const e=(0,m.useRef)(null),s=(0,m.useRef)(null);return(0,m.useEffect)(()=>{if(!e.current)return;const n=e.current,a=window.matchMedia("(prefers-reduced-motion: reduce)");let i=document.visibilityState!=="hidden",o=!1,l=0,c=0,d=0,u=0,h=7,p=11,x=new Float32Array(0),g=new Float32Array(0),v=new Float32Array(0),y=new Uint16Array(0),j=[],S="";function w(T){const q=Math.floor(Math.max(0,Math.min(.999,T))*Roe.length);return Roe[q]??" "}r(w,"toGlyph");function N(){const T=Math.max(0,Math.ceil(n.clientWidth/Math.max(1,h))),q=Math.max(0,Math.ceil(n.clientHeight/Math.max(1,p)));if(T===d&&q===u)return;d=T,u=q;const B=d*u;x=new Float32Array(B),g=new Float32Array(d),v=new Float32Array(u),y=new Uint16Array(B),j=j.filter(K=>K.x>-K.width-2&&K.x<d+2&&K.y>-K.height-2&&K.y<u+2),S=""}r(N,"rebuildGrid");function _(){if(d<=0||u<=0){n.textContent="";return}const T=Array.from({length:u},()=>Array.from({length:d},()=>" "));for(let z=0;z<u;z++)for(let D=0;D<d;D++){const V=(Math.sin(D*.11+z*.04)+Math.cos(z*.08-D*.02))*.18+.22;T[z][D]=w(V)}const q=18,B=13;for(let z=1;z<u-9;z+=B){const D=Math.floor(z/B)%2===0?2:10;for(let V=D;V<d-10;V+=q){const H=YA[(V+z)%YA.length];for(let Z=0;Z<H.length;Z++){const Y=H[Z];for(let ie=0;ie<Y.length;ie++){const se=Y[ie]??" ";if(se===" ")continue;const X=z+Z,le=V+ie;X<0||X>=u||le<0||le>=d||(T[X][le]=se)}}}}const K=T.map(z=>z.join("")).join(`
724
724
  `);n.textContent=K,S=K}r(_,"drawStaticFrame");function I(){const T=YA[Math.floor(Math.random()*YA.length)],q=$zt(T),B=Math.random();let K=0,z=0,D=0,V=0;B<.68?(K=Math.random()<.5?-q.width-1:d+1,z=Math.random()*Math.max(1,u-q.height),D=K<0?.04+Math.random()*.05:-(.04+Math.random()*.05),V=(Math.random()-.5)*.014):(K=Math.random()*Math.max(1,d-q.width),z=Math.random()<.5?-q.height-1:u+1,D=(Math.random()-.5)*.014,V=z<0?.028+Math.random()*.034:-(.028+Math.random()*.034)),j.push({x:K,y:z,vx:D,vy:V,life:0,maxLife:260+Math.random()*220,drift:(Math.random()-.5)*1.2,sprite:T,width:q.width,height:q.height})}r(I,"spawnClip");function C(T,q){const B=Math.round(T.x),K=Math.round(T.y);for(let z=0;z<T.sprite.length;z++){const D=T.sprite[z],V=K+z;if(!(V<0||V>=u))for(let H=0;H<D.length;H++){const Z=D[H]??" ";if(Z===" ")continue;const Y=B+H;if(Y<0||Y>=d)continue;const ie=V*d+Y,se=Z==="│"||Z==="─"?.8:.92;x[ie]=Math.max(x[ie]??0,q*se),y[ie]=Z.charCodeAt(0)}}}r(C,"stampClip");function A(T){if(!o||(s.current=requestAnimationFrame(A),T-l<Lzt||d<=0||u<=0))return;const q=Math.min(2,l===0?1:(T-l)/16.6667);l=T,c+=q;const B=d*u,K=Math.max(3,Math.floor(B/2200));for(;j.length<K;)I();for(let D=0;D<x.length;D++)x[D]*=.92;y.fill(0);for(let D=j.length-1;D>=0;D--){const V=j[D];V.life+=q;const H=Math.sin((V.y+V.drift+c*.12)*.09)*.0018,Z=Math.cos((V.x-V.drift-c*.09)*.08)*.0014;if(V.vx=(V.vx+H)*.998,V.vy=(V.vy+Z)*.998,V.x+=V.vx*q,V.y+=V.vy*q,V.life>=V.maxLife||V.x<-V.width-2||V.x>d+2||V.y<-V.height-2||V.y>u+2){j.splice(D,1);continue}const Y=V.life/V.maxLife;C(V,Y<.12?Y/.12:Y>.88?(1-Y)/.12:1)}for(let D=0;D<d;D++)g[D]=Math.sin(D*.08+c*.06);for(let D=0;D<u;D++)v[D]=Math.cos(D*.1-c*.05);let z="";for(let D=0;D<u;D++){for(let V=0;V<d;V++){const H=D*d+V,Z=y[H];if(Z>0){z+=String.fromCharCode(Z);continue}const Y=(g[V]+v[D])*.08+.1,ie=Math.max(x[H]??0,Y*.45);z+=w(ie)}D<u-1&&(z+=`
725
- `)}z!==S&&(n.textContent=z,S=z)}r(A,"step");function R(){const T=d>0&&u>0;if(a.matches){o&&(o=!1,s.current!==null&&cancelAnimationFrame(s.current),s.current=null),T&&_();return}if(!i||!T){o&&(o=!1,s.current!==null&&cancelAnimationFrame(s.current),s.current=null);return}o||(o=!0,l=0,s.current=requestAnimationFrame(A))}r(R,"syncLoop");const E=new ResizeObserver(()=>{const T=Toe(n);h=T.w,p=T.h,N(),R()});E.observe(n);const O=r(()=>{i=document.visibilityState!=="hidden",R()},"onVisibilityChange");document.addEventListener("visibilitychange",O);const L=r(()=>{R()},"onMotionChange");a.addEventListener("change",L);const $=Toe(n);return h=$.w,p=$.h,N(),R(),()=>{o=!1,s.current!==null&&cancelAnimationFrame(s.current),E.disconnect(),document.removeEventListener("visibilitychange",O),a.removeEventListener("change",L)}},[]),(0,t.jsx)("pre",{ref:e,className:"w-full h-full m-0 p-0 overflow-hidden text-muted-foreground/60 select-none leading-none",style:{fontSize:"var(--text-micro)",fontFamily:"monospace"},"aria-hidden":"true"})}r(Ozt,"AsciiArtAnimation");function Fzt({decorative:e=!1,title:s="Paperclip",className:n,...a}){return(0,t.jsxs)("svg",{...a,className:n,viewBox:"22.5 22.5 121 27",fill:"currentColor",role:e?void 0:"img","aria-hidden":e?!0:void 0,"aria-label":e?void 0:s,focusable:"false",children:[(0,t.jsx)("path",{d:"M131.15 48.4902V31.9902H133.922V33.9775H134.094C134.237 33.6911 134.441 33.3831 134.706 33.0537C134.971 32.7171 135.329 32.4307 135.78 32.1943C136.239 31.958 136.822 31.8398 137.531 31.8398C138.455 31.8398 139.289 32.0762 140.034 32.5488C140.779 33.0215 141.37 33.7161 141.807 34.6328C142.251 35.5495 142.473 36.6774 142.473 38.0166C142.473 39.3343 142.258 40.4551 141.828 41.3789C141.398 42.3027 140.808 43.0081 140.056 43.4951C139.311 43.9749 138.466 44.2148 137.521 44.2148C136.84 44.2148 136.271 44.1003 135.812 43.8711C135.361 43.6348 134.996 43.3555 134.717 43.0332C134.445 42.7038 134.237 42.3923 134.094 42.0986H133.976V48.4902H131.15ZM136.747 41.8945C137.37 41.8945 137.889 41.7262 138.305 41.3896C138.727 41.0531 139.046 40.5911 139.261 40.0039C139.476 39.4167 139.583 38.7507 139.583 38.0059C139.583 37.2611 139.476 36.5986 139.261 36.0186C139.046 35.4385 138.731 34.9837 138.315 34.6543C137.9 34.3249 137.377 34.1602 136.747 34.1602C136.138 34.1602 135.623 34.3177 135.2 34.6328C134.785 34.9479 134.466 35.3955 134.244 35.9756C134.029 36.5485 133.922 37.2253 133.922 38.0059C133.922 38.7793 134.029 39.4596 134.244 40.0469C134.466 40.627 134.788 41.0817 135.211 41.4111C135.633 41.7334 136.146 41.8945 136.747 41.8945Z"}),(0,t.jsx)("path",{d:"M126.451 44V31.9902H129.276V44H126.451ZM127.869 30.3037C127.417 30.3037 127.031 30.1533 126.708 29.8525C126.386 29.5518 126.225 29.1901 126.225 28.7676C126.225 28.3379 126.386 27.9727 126.708 27.6719C127.031 27.3711 127.417 27.2207 127.869 27.2207C128.313 27.2207 128.696 27.3711 129.018 27.6719C129.34 27.9727 129.501 28.3343 129.501 28.7568C129.501 29.1865 129.34 29.5518 129.018 29.8525C128.696 30.1533 128.313 30.3037 127.869 30.3037Z"}),(0,t.jsx)("path",{d:"M124.576 27.9941V44H121.75V27.9941H124.576Z"}),(0,t.jsx)("path",{d:"M115.3 44.2363C114.104 44.2363 113.076 43.9749 112.217 43.4521C111.357 42.9222 110.699 42.1917 110.24 41.2607C109.782 40.3298 109.553 39.2591 109.553 38.0488C109.553 36.8242 109.785 35.7464 110.251 34.8154C110.716 33.8844 111.379 33.1576 112.238 32.6348C113.098 32.1048 114.111 31.8398 115.278 31.8398C116.259 31.8398 117.126 32.0189 117.878 32.377C118.63 32.735 119.228 33.2399 119.672 33.8916C120.123 34.5361 120.381 35.2917 120.445 36.1582H117.738C117.667 35.7715 117.527 35.4242 117.319 35.1162C117.112 34.8083 116.84 34.5648 116.503 34.3857C116.174 34.2067 115.78 34.1172 115.321 34.1172C114.741 34.1172 114.233 34.2747 113.796 34.5898C113.366 34.8978 113.03 35.3418 112.786 35.9219C112.543 36.502 112.421 37.1966 112.421 38.0059C112.421 38.8223 112.539 39.5277 112.775 40.1221C113.012 40.7093 113.348 41.1641 113.785 41.4863C114.222 41.8014 114.734 41.959 115.321 41.959C115.944 41.959 116.471 41.7764 116.9 41.4111C117.337 41.0459 117.617 40.541 117.738 39.8965H120.445C120.381 40.7487 120.13 41.5007 119.693 42.1523C119.257 42.804 118.666 43.3161 117.921 43.6885C117.176 44.0537 116.302 44.2363 115.3 44.2363Z"}),(0,t.jsx)("path",{d:"M102.876 44V31.9902H105.615V34.0098H105.744C105.959 33.3079 106.335 32.7708 106.872 32.3984C107.409 32.0189 108.021 31.8291 108.709 31.8291C108.859 31.8291 109.031 31.8363 109.225 31.8506C109.425 31.8649 109.59 31.8828 109.719 31.9043V34.5039C109.597 34.4609 109.407 34.4251 109.149 34.3965C108.892 34.3678 108.645 34.3535 108.408 34.3535C107.885 34.3535 107.42 34.4645 107.012 34.6865C106.604 34.9085 106.281 35.2129 106.045 35.5996C105.816 35.9863 105.701 36.4375 105.701 36.9531V44H102.876Z"}),(0,t.jsx)("path",{d:"M96.2319 44.2363C95.0288 44.2363 93.9904 43.9857 93.1167 43.4844C92.243 42.9759 91.5698 42.2598 91.0972 41.3359C90.6317 40.4121 90.3989 39.3236 90.3989 38.0703C90.3989 36.8314 90.6317 35.7464 91.0972 34.8154C91.5627 33.8773 92.2179 33.1468 93.063 32.624C93.908 32.1012 94.9035 31.8398 96.0493 31.8398C96.7869 31.8398 97.4852 31.958 98.144 32.1943C98.8101 32.4307 99.3973 32.7959 99.9058 33.29C100.421 33.7842 100.826 34.4144 101.12 35.1807C101.413 35.9398 101.56 36.8457 101.56 37.8984V38.7793H91.7202V36.8779H100.153L98.8315 37.4365C98.8315 36.7562 98.7277 36.1654 98.52 35.6641C98.3123 35.1556 98.0044 34.7581 97.5962 34.4717C97.188 34.1852 96.6795 34.042 96.0708 34.042C95.4621 34.042 94.9429 34.1852 94.5132 34.4717C94.0835 34.7581 93.7576 35.1449 93.5356 35.6318C93.3136 36.1117 93.2026 36.6488 93.2026 37.2432V38.5645C93.2026 39.2949 93.328 39.9215 93.5786 40.4443C93.8364 40.96 94.1945 41.3538 94.6528 41.626C95.1183 41.8981 95.659 42.0342 96.2749 42.0342C96.6759 42.0342 97.0412 41.9769 97.3706 41.8623C97.7072 41.7477 97.9937 41.5758 98.23 41.3467C98.4735 41.1104 98.6597 40.8203 98.7886 40.4766L101.431 40.7881C101.259 41.4827 100.941 42.0915 100.475 42.6143C100.017 43.1299 99.4259 43.5309 98.7026 43.8174C97.9865 44.0967 97.1629 44.2363 96.2319 44.2363Z"}),(0,t.jsx)("path",{d:"M78.2437 48.4902V31.9902H81.0151V33.9775H81.187C81.3302 33.6911 81.5343 33.3831 81.7993 33.0537C82.0643 32.7171 82.4224 32.4307 82.8735 32.1943C83.3319 31.958 83.9155 31.8398 84.6245 31.8398C85.5483 31.8398 86.3826 32.0762 87.1274 32.5488C87.8722 33.0215 88.4631 33.7161 88.8999 34.6328C89.3439 35.5495 89.5659 36.6774 89.5659 38.0166C89.5659 39.3343 89.3511 40.4551 88.9214 41.3789C88.4917 42.3027 87.9009 43.0081 87.1489 43.4951C86.4041 43.9749 85.5591 44.2148 84.6138 44.2148C83.9334 44.2148 83.3641 44.1003 82.9058 43.8711C82.4546 43.6348 82.0894 43.3555 81.8101 43.0332C81.5379 42.7038 81.3302 42.3923 81.187 42.0986H81.0688V48.4902H78.2437ZM83.8403 41.8945C84.4634 41.8945 84.9826 41.7262 85.3979 41.3896C85.8205 41.0531 86.1392 40.5911 86.354 40.0039C86.5688 39.4167 86.6763 38.7507 86.6763 38.0059C86.6763 37.2611 86.5688 36.5986 86.354 36.0186C86.1392 35.4385 85.8241 34.9837 85.4087 34.6543C84.9933 34.3249 84.4705 34.1602 83.8403 34.1602C83.2316 34.1602 82.716 34.3177 82.2935 34.6328C81.8781 34.9479 81.5594 35.3955 81.3374 35.9756C81.1226 36.5485 81.0151 37.2253 81.0151 38.0059C81.0151 38.7793 81.1226 39.4596 81.3374 40.0469C81.5594 40.627 81.8817 41.0817 82.3042 41.4111C82.7267 41.7334 83.2388 41.8945 83.8403 41.8945Z"}),(0,t.jsx)("path",{d:"M70.042 44.2471C69.2757 44.2471 68.5882 44.111 67.9795 43.8389C67.3708 43.5596 66.891 43.1514 66.54 42.6143C66.1891 42.0771 66.0137 41.4147 66.0137 40.627C66.0137 39.9538 66.139 39.3952 66.3896 38.9512C66.6403 38.5072 66.9805 38.1527 67.4102 37.8877C67.847 37.6227 68.3376 37.4222 68.8818 37.2861C69.4261 37.1429 69.9883 37.0426 70.5684 36.9854C71.2773 36.9066 71.8503 36.8385 72.2871 36.7812C72.724 36.724 73.0391 36.6309 73.2324 36.502C73.4329 36.373 73.5332 36.1725 73.5332 35.9004V35.8467C73.5332 35.2666 73.3613 34.8154 73.0176 34.4932C72.6738 34.1709 72.1725 34.0098 71.5137 34.0098C70.819 34.0098 70.2676 34.1602 69.8594 34.4609C69.4583 34.7617 69.1862 35.1162 69.043 35.5244L66.4111 35.1484C66.6188 34.418 66.9626 33.8092 67.4424 33.3223C67.9222 32.8281 68.5059 32.4593 69.1934 32.2158C69.888 31.9652 70.6543 31.8398 71.4922 31.8398C72.0651 31.8398 72.638 31.9079 73.2109 32.0439C73.7839 32.1729 74.3102 32.3949 74.79 32.71C75.2699 33.0251 75.653 33.4476 75.9395 33.9775C76.2259 34.5075 76.3691 35.1699 76.3691 35.9648V44H73.6514V42.3457H73.5654C73.3936 42.6751 73.1501 42.9867 72.835 43.2803C72.527 43.5667 72.1403 43.7995 71.6748 43.9785C71.2165 44.1576 70.6722 44.2471 70.042 44.2471ZM70.7617 42.1631C71.3346 42.1631 71.8288 42.0521 72.2441 41.8301C72.6595 41.6009 72.9818 41.3001 73.2109 40.9277C73.4401 40.5482 73.5547 40.1364 73.5547 39.6924V38.2852C73.4616 38.3568 73.3112 38.4248 73.1035 38.4893C72.8958 38.5465 72.6595 38.6003 72.3945 38.6504C72.1296 38.7005 71.8682 38.7435 71.6104 38.7793C71.3597 38.8151 71.1413 38.8438 70.9551 38.8652C70.5326 38.9225 70.153 39.0192 69.8164 39.1553C69.487 39.2842 69.2256 39.4632 69.0322 39.6924C68.8389 39.9215 68.7422 40.2188 68.7422 40.584C68.7422 41.1068 68.932 41.5007 69.3115 41.7656C69.6911 42.0306 70.1745 42.1631 70.7617 42.1631Z"}),(0,t.jsx)("path",{d:"M53.7939 44V27.9941H59.7988C61.0306 27.9941 62.0618 28.2233 62.8926 28.6816C63.7305 29.14 64.3643 29.7702 64.7939 30.5723C65.2236 31.3743 65.4385 32.2839 65.4385 33.3008C65.4385 34.3249 65.2201 35.238 64.7832 36.04C64.3535 36.835 63.7161 37.4616 62.8711 37.9199C62.026 38.3711 60.9876 38.5967 59.7559 38.5967H55.7812V36.2119H59.3584C60.0817 36.2119 60.6725 36.0902 61.1309 35.8467C61.5964 35.596 61.9365 35.2523 62.1514 34.8154C62.3734 34.3714 62.4844 33.8665 62.4844 33.3008C62.4844 32.7279 62.3734 32.2266 62.1514 31.7969C61.9365 31.36 61.5964 31.0234 61.1309 30.7871C60.6725 30.5436 60.0781 30.4219 59.3477 30.4219H56.6943V44H53.7939Z"}),(0,t.jsx)("path",{d:"M46.2611 33.6556L34.7307 44.6408C32.7445 46.5331 29.5205 46.5323 27.5303 44.6361C25.5404 42.74 25.54 39.669 27.5261 37.7768L39.0565 26.7916C40.2474 25.657 42.1811 25.6567 43.3752 26.7943C44.5693 27.9319 44.5689 29.7742 43.378 30.9088L31.849 41.8954C31.4528 42.2728 30.8077 42.273 30.4092 41.8933C30.011 41.5136 30.0117 40.8996 30.4078 40.5223L41.9382 29.5371C42.336 29.1581 42.336 28.5437 41.9382 28.1647C41.5404 27.786 40.8954 27.7858 40.4977 28.1647L28.9673 39.1499C27.7742 40.2866 27.7764 42.1295 28.9687 43.2657C30.1613 44.402 32.0963 44.4046 33.2895 43.2678L44.8192 32.2805C46.8068 30.3865 46.8038 27.3159 44.8157 25.4219C42.8275 23.5277 39.6039 23.5253 37.616 25.4192L26.0856 36.4044C23.3024 39.056 23.3058 43.3558 26.0898 46.0085C28.8741 48.6612 33.388 48.6649 36.1712 46.0132L47.7017 35.028C48.0994 34.649 48.0994 34.0346 47.7017 33.6556C47.3039 33.2766 46.6589 33.2766 46.2611 33.6556Z"})]})}r(Fzt,"PaperclipLockup");function Bzt(){const e=Ht(),s=Wn(),[n]=Ri(),[a,i]=(0,m.useState)("sign_in"),[o,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(""),[u,h]=(0,m.useState)(""),[p,x]=(0,m.useState)(null),g="auth-error",v=(0,m.useMemo)(()=>n.get("next")||Dzt()||"/",[n]),{data:y,isLoading:j}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1});(0,m.useEffect)(()=>{y&&s(v,{replace:!0})},[y,s,v]);const S=ye({mutationFn:r(async()=>{if(a==="sign_in"){await Pa.signInEmail({email:c.trim(),password:u});return}await Pa.signUpEmail({name:o.trim(),email:c.trim(),password:u})},"mutationFn"),onSuccess:r(async()=>{x(null),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.resetQueries({queryKey:P.companies.all}),s(v,{replace:!0})},"onSuccess"),onError:r(N=>{x(N instanceof Error?N.message:"Authentication failed")},"onError")}),w=c.trim().length>0&&u.trim().length>0&&(a==="sign_in"||o.trim().length>0&&u.trim().length>=8);return j?(0,t.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,t.jsx)(Qm,{className:"min-h-0"})}):(0,t.jsxs)("div",{className:"fixed inset-0 flex bg-background",children:[(0,t.jsx)("div",{className:"absolute top-4 right-4 z-10",children:(0,t.jsx)(Cj,{})}),(0,t.jsx)("div",{className:"w-full md:w-1/2 flex flex-col overflow-y-auto",children:(0,t.jsxs)("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12",children:[(0,t.jsx)("div",{className:"mb-8",children:(0,t.jsx)(Fzt,{className:"h-5 w-auto"})}),(0,t.jsx)("h1",{className:"text-xl font-semibold",children:a==="sign_in"?"Sign in to Paperclip":"Create your Paperclip account"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:a==="sign_in"?"Use your email and password to access this instance.":"Create an account for this instance. Email confirmation is not required in v1."}),(0,t.jsxs)("form",{className:"mt-6 space-y-4",method:"post",action:a==="sign_up"?"/api/auth/sign-up/email":"/api/auth/sign-in/email",onSubmit:r(N=>{if(N.preventDefault(),!S.isPending){if(!w){x("Please fill in all required fields.");return}S.mutate()}},"onSubmit"),children:[a==="sign_up"&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"name",className:"text-xs text-muted-foreground mb-1 block",children:"Name"}),(0,t.jsx)("input",{id:"name",name:"name",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",value:o,onChange:r(N=>l(N.target.value),"onChange"),autoComplete:"name",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0,autoFocus:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"email",className:"text-xs text-muted-foreground mb-1 block",children:"Email"}),(0,t.jsx)("input",{id:"email",name:"email",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"email",value:c,onChange:r(N=>d(N.target.value),"onChange"),autoComplete:"username",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0,autoFocus:a==="sign_in"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"password",className:"text-xs text-muted-foreground mb-1 block",children:"Password"}),(0,t.jsx)("input",{id:"password",name:"password",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"password",value:u,onChange:r(N=>h(N.target.value),"onChange"),autoComplete:a==="sign_in"?"current-password":"new-password",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0})]}),p&&(0,t.jsx)("p",{id:g,role:"alert",className:"text-xs text-destructive",children:p}),(0,t.jsx)(F,{type:"submit",disabled:S.isPending,"aria-disabled":!w||S.isPending,className:`w-full ${!w&&!S.isPending?"opacity-50":""}`,children:S.isPending?"Working…":a==="sign_in"?"Sign In":"Create Account"})]}),(0,t.jsxs)("div",{className:"mt-5 text-sm text-muted-foreground",children:[a==="sign_in"?"Need an account?":"Already have an account?"," ",(0,t.jsx)("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2",onClick:r(()=>{x(null),i(a==="sign_in"?"sign_up":"sign_in")},"onClick"),children:a==="sign_in"?"Create one":"Sign in"})]})]})}),(0,t.jsx)("div",{className:"hidden md:block w-1/2 overflow-hidden",children:(0,t.jsx)(Ozt,{})})]})}r(Bzt,"AuthPage");function qzt(){const e=Ht(),s=ja(),[n]=Ri(),a=(s.token??"").trim(),i=(n.get("code")??"").trim(),o=(0,m.useMemo)(()=>`/board-claim/${encodeURIComponent(a)}${i?`?code=${encodeURIComponent(i)}`:""}`,[a,i]),l=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),c=ee({queryKey:["board-claim",a,i],queryFn:r(()=>fr.getBoardClaimStatus(a,i),"queryFn"),enabled:a.length>0&&i.length>0,retry:!1}),d=ye({mutationFn:r(()=>fr.claimBoard(a,i),"mutationFn"),onSuccess:r(async()=>{await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.invalidateQueries({queryKey:P.companies.all}),await e.invalidateQueries({queryKey:P.companies.stats}),await c.refetch()},"onSuccess")});if(!a||!i)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid board claim URL."});if(c.isLoading||l.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading claim challenge..."});if(c.error)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Claim challenge unavailable"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:c.error instanceof Error?c.error.message:"Challenge is invalid or expired."})]})});const u=c.data;return u?u.status==="claimed"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Board ownership claimed"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This instance is now linked to your authenticated user."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})]})}):l.data?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Claim Board ownership"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This will promote your user to instance admin and migrate organization ownership access from local trusted mode."}),d.error&&(0,t.jsx)("p",{className:"mt-3 text-sm text-destructive",children:d.error instanceof Error?d.error.message:"Failed to claim board ownership"}),(0,t.jsx)(F,{className:"mt-5",onClick:r(()=>d.mutate(),"onClick"),disabled:d.isPending,children:d.isPending?"Claiming…":"Claim ownership"})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Sign in required"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to claim Board ownership."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:`/auth?next=${encodeURIComponent(o)}`,children:"Sign in / Create account"})})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Claim challenge unavailable."})}r(qzt,"BoardClaimPage");function zzt(){const e=Ht(),s=ja(),[n]=Ri(),a=(s.id??"").trim(),i=(n.get("token")??"").trim(),o=(0,m.useMemo)(()=>`/cli-auth/${encodeURIComponent(a)}${i?`?token=${encodeURIComponent(i)}`:""}`,[a,i]),l=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),c=ee({queryKey:["cli-auth-challenge",a,i],queryFn:r(()=>fr.getCliAuthChallenge(a,i),"queryFn"),enabled:a.length>0&&i.length>0,retry:!1}),d=ye({mutationFn:r(()=>fr.approveCliAuthChallenge(a,i),"mutationFn"),onSuccess:r(async()=>{await e.invalidateQueries({queryKey:P.auth.session}),await c.refetch()},"onSuccess")}),u=ye({mutationFn:r(()=>fr.cancelCliAuthChallenge(a,i),"mutationFn"),onSuccess:r(async()=>{await c.refetch()},"onSuccess")});if(!a||!i)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid CLI auth URL."});if(l.isLoading||c.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading CLI auth challenge..."});if(c.error)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"CLI auth challenge unavailable"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:c.error instanceof Error?c.error.message:"Challenge is invalid or expired."})]})});const h=c.data;return h?h.status==="approved"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"CLI access approved"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"The Paperclip CLI can now finish authentication on the requesting machine."}),(0,t.jsxs)("p",{className:"mt-4 text-sm text-muted-foreground",children:["Command: ",(0,t.jsx)("span",{className:"font-mono text-foreground",children:h.command})]})]})}):h.status==="cancelled"||h.status==="expired"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:h.status==="expired"?"CLI auth challenge expired":"CLI auth challenge cancelled"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Start the CLI auth flow again from your terminal to generate a new approval request."})]})}):h.requiresSignIn||!l.data?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Sign in required"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to approve the CLI access request."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:`/auth?next=${encodeURIComponent(o)}`,children:"Sign in / Create account"})})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Approve Paperclip CLI access"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"A local Paperclip CLI process is requesting board access to this instance."}),(0,t.jsxs)("div",{className:"mt-5 space-y-3 text-sm",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Command"}),(0,t.jsx)("div",{className:"font-mono text-foreground",children:h.command})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Client"}),(0,t.jsx)("div",{className:"text-foreground",children:h.clientName??"paperclip-pro cli"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Requested access"}),(0,t.jsx)("div",{className:"text-foreground",children:h.requestedAccess==="instance_admin_required"?"Instance admin":"Board"})]}),h.requestedCompanyName&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Requested organization"}),(0,t.jsx)("div",{className:"text-foreground",children:h.requestedCompanyName})]})]}),(d.error||u.error)&&(0,t.jsx)("p",{className:"mt-4 text-sm text-destructive",children:(d.error??u.error)instanceof Error?(d.error??u.error).message:"Failed to update CLI auth challenge"}),!h.canApprove&&(0,t.jsx)("p",{className:"mt-4 text-sm text-destructive",children:"This challenge requires instance-admin access. Sign in with an instance admin account to approve it."}),(0,t.jsxs)("div",{className:"mt-5 flex gap-3",children:[(0,t.jsx)(F,{onClick:r(()=>d.mutate(),"onClick"),disabled:!h.canApprove||d.isPending||u.isPending,children:d.isPending?"Approving...":"Approve CLI access"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>u.mutate(),"onClick"),disabled:d.isPending||u.isPending,children:u.isPending?"Cancelling...":"Cancel"})]})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"CLI auth challenge unavailable."})}r(zzt,"CliAuthPage");var Uzt=gIe.filter(e=>e!=="paperclip_runner"),Eoe=new Set(["claude_local","codex_local","gemini_local","kimi_local","opencode_local","pi_local","cursor"]);function Kzt(e,s){let n=e;for(const a of s){if(!n||typeof n!="object")return null;n=n[a]}return typeof n=="string"&&n.trim().length>0?n:null}r(Kzt,"readNestedString");var $y="w-full border border-zinc-800 bg-zinc-950 px-3 py-2 text-sm text-zinc-100 outline-none focus:border-zinc-500",Poe="border border-zinc-800 bg-zinc-950/95 p-6",Moe="flex-1 border px-3 py-2 text-sm transition-colors";function Vzt(e){return e?e.charAt(0).toUpperCase()+e.slice(1):null}r(Vzt,"formatHumanRole");function WCe(e){if(!e||typeof e!="object")return null;const s=e.code;return typeof s=="string"&&s.trim().length>0?s:null}r(WCe,"getAuthErrorCode");function Wzt(e){if(!(e instanceof Error))return null;const s=e.message.trim();return s.length>0?s:null}r(Wzt,"getAuthErrorMessage");function Hzt(e,s,n){const a=WCe(e),i=Wzt(e),o=n.trim().length>0?n.trim():"that email";return a==="USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL"?{tone:"info",message:`An account already exists for ${o}. Sign in below to continue with this invite.`}:a==="INVALID_EMAIL_OR_PASSWORD"?{tone:"error",message:"That email and password did not match an existing Paperclip account. Check both fields, or create an account first if you are new here."}:s==="sign_in"&&i==="Request failed: 401"?{tone:"error",message:"That email and password did not match an existing Paperclip account. Check both fields, or create an account first if you are new here."}:s==="sign_up"&&i==="Request failed: 422"?{tone:"info",message:`An account may already exist for ${o}. Try signing in instead.`}:{tone:"error",message:i??"Authentication failed"}}r(Hzt,"mapInviteAuthFeedback");function Doe(e){return!!(e&&typeof e=="object"&&"bootstrapAccepted"in e)}r(Doe,"isBootstrapAcceptancePayload");function Qzt(e,s){return!e||typeof e!="object"||s?!1:e.status==="approved"}r(Qzt,"isApprovedHumanJoinPayload");function B6({companyDisplayName:e,companyLogoUrl:s,className:n}){return(0,t.jsx)(Rx,{companyName:e,logoUrl:s,logoFit:"contain",className:n})}r(B6,"InviteCompanyLogo");function Loe({companyDisplayName:e,companyLogoUrl:s,invitedByUserName:n,claimSecret:a=null,claimApiKeyPath:i=null,onboardingTextUrl:o=null}){return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6","data-testid":"invite-pending-approval",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(B6,{companyDisplayName:e,companyLogoUrl:s,className:"h-12 w-12 border border-zinc-800 rounded-none"}),(0,t.jsxs)("h1",{className:"text-lg font-semibold",children:["Request to join ",e]})]}),(0,t.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,t.jsxs)("p",{className:"text-sm text-zinc-400",children:["Your request is still awaiting approval. ",n??"An organization admin"," must approve your request to join."]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("p",{className:"text-xs text-zinc-500 mb-1",children:"Approval page"}),(0,t.jsx)("p",{className:"text-sm text-zinc-200",children:"Settings → Members"})]}),(0,t.jsxs)("p",{className:"text-sm text-zinc-400",children:["Ask them to visit ",(0,t.jsx)("span",{className:"text-zinc-200",children:"Settings → Members"})," to approve your request."]}),(0,t.jsx)("p",{className:"text-xs text-zinc-500",children:"Refresh this page after you've been approved — you'll be redirected automatically."})]}),a&&i?(0,t.jsxs)("div",{className:"mt-4 space-y-1 border border-zinc-800 p-3 text-xs text-zinc-400",children:[(0,t.jsx)("div",{className:"text-zinc-200",children:"Claim secret"}),(0,t.jsx)("div",{className:"font-mono break-all",children:a}),(0,t.jsxs)("div",{className:"font-mono break-all",children:["POST ",i]})]}):null,o?(0,t.jsxs)("div",{className:"mt-4 text-xs text-zinc-400",children:["Onboarding: ",(0,t.jsx)("span",{className:"font-mono break-all",children:o})]}):null]})})}r(Loe,"AwaitingJoinApprovalPanel");function Gzt(){const e=Ht(),s=Wn(),{setSelectedCompanyId:n}=fs(),a=(ja().token??"").trim(),[i,o]=(0,m.useState)("sign_up"),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(""),[x,g]=(0,m.useState)(""),[v,y]=(0,m.useState)("claude_local"),[j,S]=(0,m.useState)(""),[w,N]=(0,m.useState)(null),[_,I]=(0,m.useState)(null),[C,A]=(0,m.useState)(null),[R,E]=(0,m.useState)(!1),O="invite-auth-error",L=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1}),$=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),T=ee({queryKey:P.access.invite(a),queryFn:r(()=>fr.getInvite(a),"queryFn"),enabled:a.length>0,retry:!1}),q=z6({enabled:!!$.data&&!!T.data?.companyId,staleTime:0}),B=L.data?.deploymentMode!=="local_trusted"?q.isFetchedAfterMount:!0,K=B?q.data?.companies??[]:[];(0,m.useEffect)(()=>{a&&Aoe(a)},[a]),(0,m.useEffect)(()=>{E(!1)},[a]),(0,m.useEffect)(()=>{if(!B)return;const he=q.data?.companies;!he||!T.data?.companyId||he.some(Ie=>Ie.id===T.data.companyId)&&GA(a)},[q.data,T.data,B,a]);const z=T.data,D=!!$.data&&!!z?.companyId&&!B,V=!!z?.companyId&&K.some(he=>he.id===z?.companyId),H=z?.companyName?.trim()||"this Paperclip company",Z=z?.companyLogoUrl?.trim()||null,Y=z?.invitedByUserName?.trim()||null,ie=z?.inviteMessage?.trim()||null,se=Vzt(z?.humanRole),X=z?.joinRequestStatus??null,le=z?.joinRequestType??null,oe=le==="human"&&(X==="pending_approval"||X==="approved"),te=L.data?.deploymentMode==="authenticated"&&!$.data&&z?.allowedJoinTypes!=="agent",J=z?.inviteType!=="bootstrap_ceo"&&z?.allowedJoinTypes==="agent",Q=!!$.data&&!J&&z?.inviteType!=="bootstrap_ceo"&&(!X||oe)&&!D&&!V&&!w&&_===null,pe=$.data?.user.name?.trim()||$.data?.user.email?.trim()||"this account",re=d.trim().length>0&&h.trim().length>0&&(i==="sign_in"||l.trim().length>0&&h.trim().length>=8),ne=ye({mutationFn:r(async()=>{if(!z)throw new Error("Invite not found");if(D)throw new Error("Checking your organization access. Try again in a moment.");if(V)throw new Error("This account already belongs to the organization.");return z.inviteType==="bootstrap_ceo"||z.allowedJoinTypes!=="agent"?fr.acceptInvite(a,{requestType:"human"}):fr.acceptInvite(a,{requestType:"agent",agentName:x.trim(),adapterType:v,capabilities:j.trim()||null})},"mutationFn"),onSuccess:r(async he=>{I(null),GA(a);const Ie=Doe(he);N({kind:Ie?"bootstrap":"join",payload:he}),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.access.currentBoardAccess}),await e.invalidateQueries({queryKey:P.companies.all}),z?.companyId&&Qzt(he,J)&&(n(z.companyId,{source:"manual"}),s("/",{replace:!0}))},"onSuccess"),onError:r(he=>{I(he instanceof Error?he.message:"Failed to accept invite")},"onError")});(0,m.useEffect)(()=>{!Q||R||ne.isPending||(E(!0),I(null),ne.mutate())},[ne,R,Q]);const ae=ye({mutationFn:r(async()=>{if(i==="sign_in"){await Pa.signInEmail({email:d.trim(),password:h});return}await Pa.signUpEmail({name:l.trim(),email:d.trim(),password:h})},"mutationFn"),onSuccess:r(async()=>{A(null),Aoe(a),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.invalidateQueries({queryKey:P.access.currentBoardAccess});const{companies:he}=await I_e(e);if(z?.companyId&&he.some(Ie=>Ie.id===z.companyId)){GA(a),n(z.companyId,{source:"manual"}),s("/",{replace:!0});return}if(!(!z||z.inviteType!=="bootstrap_ceo"))try{Doe(await ne.mutateAsync())&&s("/",{replace:!0})}catch{return}},"onSuccess"),onError:r(he=>{const Ie=Hzt(he,i,d);WCe(he)==="USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL"&&(o("sign_in"),p("")),A(Ie)},"onError")}),me=(0,m.useMemo)(()=>z?V?"Open organization":z.inviteType==="bootstrap_ceo"?"Accept invite":J?"Submit request":$.data?"Accept invite":"Continue":"Continue",[z,V,$.data,J]);if(!a)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid invite token."});if(T.isLoading||L.isLoading||$.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading invite..."});if(D)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Checking your access..."});if(T.error||!z)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"border border-border bg-card p-6","data-testid":"invite-error",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Invite not available"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This invite may be expired, revoked, or already used."})]})});if(X==="approved"&&le==="human"&&V)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Opening organization..."});if(X==="pending_approval"&&!oe)return(0,t.jsx)(Loe,{companyDisplayName:H,companyLogoUrl:Z,invitedByUserName:Y});if(X&&!oe)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"border border-border bg-card p-6","data-testid":"invite-error",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Invite not available"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:X==="rejected"?"This join request was not approved.":"This invite has already been used."})]})});if(w?.kind==="bootstrap")return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Bootstrap complete"}),(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(F,{asChild:!0,className:"rounded-none",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})})]})});if(w?.kind==="join"){const he=w.payload,Ie=typeof he.claimSecret=="string"?he.claimSecret:null,de=typeof he.claimApiKeyPath=="string"?he.claimApiKeyPath:null,ve=Kzt(he.onboarding,["textInstructions","url"]);return!J&&he.status==="approved"?(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(B6,{companyDisplayName:H,companyLogoUrl:Z,className:"h-12 w-12 border border-zinc-800 rounded-none"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"You joined the organization"})]}),(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(F,{asChild:!0,className:"w-full rounded-none",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})})]})}):(0,t.jsx)(Loe,{companyDisplayName:H,companyLogoUrl:Z,invitedByUserName:Y,claimSecret:Ie,claimApiKeyPath:de,onboardingTextUrl:ve})}return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsx)("div",{className:"mx-auto max-w-5xl",children:(0,t.jsxs)("div",{className:"grid gap-6 lg:grid-cols-(--gtc-36)",children:[(0,t.jsxs)("section",{className:`${Poe} space-y-6`,children:[(0,t.jsxs)("div",{className:"flex items-start gap-4",children:[(0,t.jsx)(B6,{companyDisplayName:H,companyLogoUrl:Z,className:"h-16 w-16 rounded-none border border-zinc-800"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"You've been invited to join Paperclip"}),(0,t.jsx)("h1",{className:"mt-2 text-2xl font-semibold",children:z.inviteType==="bootstrap_ceo"?"Set up Paperclip":`Join ${H}`}),(0,t.jsx)("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-zinc-300",children:J?"Review the invite details, then submit the agent information below to start the join request.":te?"Create your Paperclip account first. If you already have one, switch to sign in and continue the invite with the same email.":"Your account is ready. Review the invite details, then accept it to continue."})]})]}),(0,t.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Organization"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:H})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Invited by"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:Y??"Paperclip board"})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Requested access"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:J?"Agent join request":se??"Organization access"})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Invite expires"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:cu(z.expiresAt)})]})]}),ie?(0,t.jsxs)("div",{className:"border border-amber-500/40 bg-amber-500/10 p-4",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-amber-200/80",children:"Message from inviter"}),(0,t.jsx)("p",{className:"mt-2 text-sm leading-6 text-amber-50",children:ie})]}):null,$.data?(0,t.jsxs)("div",{className:"border border-emerald-500/40 bg-emerald-500/10 p-4 text-sm text-emerald-50",children:["Signed in as ",(0,t.jsx)("span",{className:"font-medium",children:pe}),"."]}):null]}),(0,t.jsx)("section",{className:`${Poe} h-fit`,children:J?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:"Submit agent details"}),(0,t.jsxs)("p",{className:"mt-1 text-sm text-zinc-400",children:["This invite will create an approval request for a new agent in ",H,"."]})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Agent name"}),(0,t.jsx)("input",{className:$y,value:x,onChange:r(he=>g(he.target.value),"onChange")})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Adapter type"}),(0,t.jsx)("select",{className:$y,value:v,onChange:r(he=>y(he.target.value),"onChange"),children:Uzt.map(he=>(0,t.jsxs)("option",{value:he,disabled:!Eoe.has(he),children:[sf(he),Eoe.has(he)?"":" (Coming soon)"]},he))})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Capabilities"}),(0,t.jsx)("textarea",{className:$y,rows:4,value:j,onChange:r(he=>S(he.target.value),"onChange")})]}),_?(0,t.jsx)("p",{className:"text-xs text-red-400",children:_}):null,(0,t.jsx)(F,{className:"w-full rounded-none",disabled:ne.isPending||x.trim().length===0,onClick:r(()=>ne.mutate(),"onClick"),children:ne.isPending?"Working...":me})]}):te?(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:i==="sign_up"?"Create your account":"Sign in to continue"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:i==="sign_up"?`Start with a Paperclip account. After that, you'll come right back here to accept the invite for ${H}.`:"Use the Paperclip account that already matches this invite. If you do not have one yet, switch back to create account."})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("button",{type:"button",className:`${Moe} ${i==="sign_up"?"border-zinc-100 bg-zinc-100 text-zinc-950":"border-zinc-800 text-zinc-300 hover:border-zinc-600"}`,onClick:r(()=>{A(null),o("sign_up")},"onClick"),children:"Create account"}),(0,t.jsx)("button",{type:"button",className:`${Moe} ${i==="sign_in"?"border-zinc-100 bg-zinc-100 text-zinc-950":"border-zinc-800 text-zinc-300 hover:border-zinc-600"}`,onClick:r(()=>{A(null),o("sign_in")},"onClick"),children:"I already have an account"})]}),(0,t.jsxs)("form",{className:"space-y-4",method:"post",action:i==="sign_up"?"/api/auth/sign-up/email":"/api/auth/sign-in/email",onSubmit:r(he=>{if(he.preventDefault(),!ae.isPending){if(!re){A({tone:"error",message:"Please fill in all required fields."});return}ae.mutate()}},"onSubmit"),"data-testid":"invite-inline-auth",children:[i==="sign_up"?(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-name",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Name"}),(0,t.jsx)("input",{id:"invite-name",name:"name",className:$y,value:l,onChange:r(he=>{c(he.target.value),A(null)},"onChange"),autoComplete:"name",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0,autoFocus:!0})]}):null,(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-email",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Email"}),(0,t.jsx)("input",{id:"invite-email",name:"email",type:"email",className:$y,value:d,onChange:r(he=>{u(he.target.value),A(null)},"onChange"),autoComplete:"username",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0,autoFocus:i==="sign_in"})]}),(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-password",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Password"}),(0,t.jsx)("input",{id:"invite-password",name:"password",type:"password",className:$y,value:h,onChange:r(he=>{p(he.target.value),A(null)},"onChange"),autoComplete:i==="sign_in"?"current-password":"new-password",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0})]}),C?(0,t.jsx)("p",{id:O,role:"alert",className:`text-xs ${C.tone==="info"?"text-amber-300":"text-red-400"}`,children:C.message}):null,(0,t.jsx)(F,{type:"submit",className:"w-full rounded-none",disabled:ae.isPending,"aria-disabled":!re||ae.isPending,children:ae.isPending?"Working...":i==="sign_in"?"Sign in and continue":"Create account and continue"})]}),(0,t.jsx)("p",{className:"text-xs leading-5 text-zinc-500",children:i==="sign_up"?"Already signed up before? Use the existing-account option instead so the invite lands on the right Paperclip user.":"No account yet? Switch back to create account so you can accept the invite with a new login."})]}):(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:V?"Already in this organization":Q?"Completing organization access":z.inviteType==="bootstrap_ceo"?"Accept bootstrap invite":"Accept organization invite"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:Q?`Granting your access to ${H}.`:V?`This account already belongs to ${H}.`:`This will ${z.inviteType==="bootstrap_ceo"?"finish setting up Paperclip":`grant or complete your access to ${H}`}.`})]}),_?(0,t.jsx)("p",{className:"text-xs text-red-400",children:_}):null,Q?(0,t.jsx)("div",{className:"text-sm text-zinc-400",children:ne.isPending?"Submitting request...":"Finishing sign-in..."}):(0,t.jsx)(F,{className:"w-full rounded-none",disabled:ne.isPending,onClick:r(()=>{if(V&&z.companyId){GA(a),n(z.companyId,{source:"manual"}),s("/",{replace:!0});return}ne.mutate()},"onClick"),children:ne.isPending?"Working...":me})]})})]})})})}r(Gzt,"InviteLandingPage");function Yzt(){const{selectedCompany:e,selectedCompanyId:s}=fs(),{setBreadcrumbs:n}=$n(),{pushToast:a}=Mi(),i=Ht(),[o,l]=(0,m.useState)("pending_approval"),[c,d]=(0,m.useState)("all");(0,m.useEffect)(()=>{n([{label:e?.name??"Organization",href:"/dashboard"},{label:"Inbox",href:"/inbox"},{label:"Join Requests"}])},[e?.name,n]);const u=ee({queryKey:P.access.joinRequests(s??"",`${o}:${c}`),queryFn:r(()=>fr.listJoinRequests(s,o,c==="all"?void 0:c),"queryFn"),enabled:!!s}),h=ye({mutationFn:r(x=>fr.approveJoinRequest(s,x),"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.joinRequests(s,`${o}:${c}`)}),await i.invalidateQueries({queryKey:P.access.companyMembers(s)}),await i.invalidateQueries({queryKey:P.access.companyUserDirectory(s)}),a({title:"Join request approved",tone:"success"})},"onSuccess")}),p=ye({mutationFn:r(x=>fr.rejectJoinRequest(s,x),"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.joinRequests(s,`${o}:${c}`)}),a({title:"Join request rejected",tone:"success"})},"onSuccess")});if(!s)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Select an organization to review join requests."});if(u.isLoading)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading join requests…"});if(u.error){const x=u.error instanceof Nn&&u.error.status===403?"You do not have permission to review join requests for this organization.":u.error instanceof Error?u.error.message:"Failed to load join requests.";return(0,t.jsx)("div",{className:"text-sm text-destructive",children:x})}return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(YEe,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Join Request Queue"})]}),(0,t.jsx)("p",{className:"max-w-3xl text-sm text-muted-foreground",children:"Review human and agent join requests outside the mixed inbox feed. This queue uses the same approval mutations as the inline inbox cards."})]}),(0,t.jsxs)(Gs,{className:"flex-row flex-wrap gap-3 p-4",children:[(0,t.jsxs)("label",{className:"space-y-2 text-sm",children:[(0,t.jsx)("span",{className:"font-medium",children:"Status"}),(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:o,onChange:r(x=>l(x.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"pending_approval",children:"Pending approval"}),(0,t.jsx)("option",{value:"approved",children:"Approved"}),(0,t.jsx)("option",{value:"rejected",children:"Rejected"})]})]}),(0,t.jsxs)("label",{className:"space-y-2 text-sm",children:[(0,t.jsx)("span",{className:"font-medium",children:"Request type"}),(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:c,onChange:r(x=>d(x.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"all",children:"All"}),(0,t.jsx)("option",{value:"human",children:"Human"}),(0,t.jsx)("option",{value:"agent",children:"Agent"})]})]})]}),(0,t.jsx)("div",{className:"space-y-4",children:(u.data??[]).length===0?(0,t.jsx)("div",{className:"rounded-xl border border-dashed border-border px-4 py-8 text-sm text-muted-foreground",children:"No join requests match the current filters."}):u.data.map(x=>(0,t.jsxs)(Gs,{className:"block p-4",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(dt,{variant:x.status==="pending_approval"?"secondary":x.status==="approved"?"outline":"destructive",children:x.status.replace("_"," ")}),(0,t.jsx)(dt,{variant:"outline",children:x.requestType}),x.adapterType?(0,t.jsx)(dt,{variant:"outline",children:x.adapterType}):null]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-base font-medium",children:x.requestType==="human"?x.requesterUser?.name||x.requestEmailSnapshot||x.requestingUserId||"Unknown human requester":x.agentName||"Unknown agent requester"}),(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:x.requestType==="human"?x.requesterUser?.email||x.requestEmailSnapshot||x.requestingUserId:x.capabilities||x.requestIp})]})]}),x.status==="pending_approval"?(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>p.mutate(x.id),"onClick"),disabled:p.isPending,children:"Reject"}),(0,t.jsx)(F,{onClick:r(()=>h.mutate(x.id),"onClick"),disabled:h.isPending,children:"Approve"})]}):null]}),(0,t.jsxs)("div",{className:"mt-4 grid gap-3 text-sm text-muted-foreground md:grid-cols-2",children:[(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-background px-3 py-2",children:[(0,t.jsx)("div",{className:"text-xs font-medium uppercase tracking-wide",children:"Invite context"}),(0,t.jsx)("div",{className:"mt-2",children:x.invite?`${x.invite.allowedJoinTypes} join invite${x.invite.humanRole?` • default role ${x.invite.humanRole}`:""}`:"Invite metadata unavailable"}),x.invite?.inviteMessage?(0,t.jsx)("div",{className:"mt-2 text-foreground",children:x.invite.inviteMessage}):null]}),(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-background px-3 py-2",children:[(0,t.jsx)("div",{className:"text-xs font-medium uppercase tracking-wide",children:"Request details"}),(0,t.jsxs)("div",{className:"mt-2",children:["Submitted ",new Date(x.createdAt).toLocaleString()]}),(0,t.jsxs)("div",{children:["Source IP ",x.requestIp]}),x.requestType==="agent"&&x.capabilities?(0,t.jsx)("div",{children:x.capabilities}):null]})]})]},x.id))})]})}r(Yzt,"JoinRequestQueue");var Jzt=(0,m.lazy)(()=>gc(()=>import("./CompanyExport-CrTwKkGN.js").then(e=>({default:e.CompanyExport})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]))),Xzt=(0,m.lazy)(()=>gc(()=>import("./Agents.production-CSsrqqG3.js").then(e=>({default:e.Agents})),__vite__mapDeps([26,5,7,9,8,10,11,12,13,27,28,29,15,30,31,32,33,24,25]))),Zzt=(0,m.lazy)(()=>gc(()=>import("./Routines.production-BLDTlRLI.js").then(e=>({default:e.Routines})),__vite__mapDeps([34,5,7,8,9,10,11,12,13,35,14,15,36,37,29,27,38,39,40,21,41,42,16,17,18,19,43,44,30,45,46,23,31,47,33,48,49,50,51,24,25,28]))),$oe=(0,m.lazy)(()=>gc(()=>import("./RoutineDetail.production-BJLGGgbv.js").then(e=>({default:e.RoutineDetail})),__vite__mapDeps([52,5,7,8,9,10,11,12,13,35,14,15,36,37,29,27,38,39,40,21,41,42,16,17,18,19,43,44,30,45,46,23,31,47,33,48,49,50,51,24,25,53]))),eUt=(0,m.lazy)(()=>gc(()=>import("./CompanySkills.production-22PSRfdH.js").then(e=>({default:e.CompanySkills})),__vite__mapDeps([54,5,7,8,9,10,11,12,13,14,15,36,37,29,27,38,39,40,21,41,28,16,17,18,19,55,53,31,44,22,20,56,47,48,50,24,25]))),tUt=(0,m.lazy)(()=>gc(()=>import("./CompanyActivity.production-C3D5uiX9.js").then(e=>({default:e.CompanyActivity})),__vite__mapDeps([57,5,7,8,9,10,11,12,13,27,28,29,43,37,21,44,48,49,51]))),sUt=(0,m.lazy)(()=>gc(()=>import("./Costs.production-hPGllSho.js").then(e=>({default:e.Costs})),__vite__mapDeps([58,5,7,28,29,13,12,44,41,50,27,51,24,25]))),nUt=(0,m.lazy)(()=>gc(()=>import("./OrgChart.production-yz5AfR-F.js").then(e=>({default:e.OrgChart})),__vite__mapDeps([59,5,7,8,9,10,11,12,13,27,45,46,51,24,25])));function pg({children:e}){return(0,t.jsx)(m.Suspense,{fallback:(0,t.jsx)(Qm,{}),children:e})}r(pg,"ProductionSurface");function rUt(e){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{index:!0,element:(0,t.jsx)(vn,{to:"dashboard",replace:!0})}),(0,t.jsx)(lt,{path:"dashboard",element:(0,t.jsx)(Bht,{})}),(0,t.jsx)(lt,{path:"dashboard/live",element:(0,t.jsx)(qht,{})}),(0,t.jsx)(lt,{path:"timeline",element:e?(0,t.jsx)(hp,{to:"/activity/timeline"}):(0,t.jsx)(Pye,{})}),(0,t.jsx)(lt,{path:"onboarding",element:(0,t.jsx)(GCe,{})}),(0,t.jsx)(lt,{path:"companies",element:(0,t.jsx)(_pt,{})}),(0,t.jsx)(lt,{path:"company/settings",element:(0,t.jsx)(LTt,{})}),(0,t.jsx)(lt,{path:"company/settings/environments",element:(0,t.jsx)(vn,{to:"/company/settings/instance/environments",replace:!0})}),(0,t.jsx)(lt,{path:"company/settings/cloud-upstream",element:(0,t.jsx)(vn,{to:"/company/export",replace:!0})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.members"}),children:[(0,t.jsx)(lt,{path:"company/settings/members",element:(0,t.jsx)(rMt,{})}),(0,t.jsx)(lt,{path:"company/settings/access",element:(0,t.jsx)(aMt,{})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.invites"}),children:(0,t.jsx)(lt,{path:"company/settings/invites",element:(0,t.jsx)(vn,{to:"/company/settings/members?tab=invites",replace:!0})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.export"}),children:(0,t.jsx)(lt,{path:"company/export/*",element:(0,t.jsx)(m.Suspense,{fallback:(0,t.jsx)(Qm,{}),children:(0,t.jsx)(Jzt,{})})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Eet,{}),children:(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.import"}),children:(0,t.jsx)(lt,{path:"company/import",element:(0,t.jsx)(h6t,{})})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.secrets"}),children:(0,t.jsx)(lt,{path:"company/settings/secrets",element:(0,t.jsx)(lqt,{})})}),(0,t.jsx)(lt,{path:"company/settings/tools",element:(0,t.jsx)(Foe,{})}),(0,t.jsx)(lt,{path:"company/settings/tools/:tab",element:(0,t.jsx)(Foe,{})}),(0,t.jsx)(lt,{path:"tools",element:(0,t.jsx)(Boe,{})}),(0,t.jsx)(lt,{path:"tools/:tab",element:(0,t.jsx)(Boe,{})}),(0,t.jsx)(lt,{path:"apps",element:(0,t.jsx)(z4t,{})}),(0,t.jsx)(lt,{path:"apps/browse",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/connections",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/byo",element:(0,t.jsx)(wSe,{byoOnly:!0})}),(0,t.jsx)(lt,{path:"apps/vercel-connect",element:(0,t.jsx)(Ooe,{credentialSource:"vercel_connect"})}),(0,t.jsx)(lt,{path:"apps/connect",element:(0,t.jsx)(Ooe,{})}),(0,t.jsx)(lt,{path:"apps/chat/connect",element:(0,t.jsx)(f$,{children:(0,t.jsx)(fDt,{})})}),(0,t.jsx)(lt,{path:"apps/chat/:endpointId",element:(0,t.jsx)(f$,{children:(0,t.jsx)(vn,{to:"settings",replace:!0})})}),(0,t.jsx)(lt,{path:"apps/chat/:endpointId/:tab",element:(0,t.jsx)(f$,{children:(0,t.jsx)(PDt,{})})}),(0,t.jsx)(lt,{path:"apps/connect/:appKey",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/connect/:appKey/:stage",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/review",element:(0,t.jsx)(BDt,{})}),(0,t.jsx)(lt,{path:"apps/attention",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/gateways",element:(0,t.jsx)(Qae,{})}),(0,t.jsx)(lt,{path:"apps/gateways/:gatewayId",element:(0,t.jsx)(vn,{to:"overview",replace:!0})}),(0,t.jsx)(lt,{path:"apps/gateways/:gatewayId/:tab",element:(0,t.jsx)(MLt,{})}),(0,t.jsx)(lt,{path:"apps/advanced",element:(0,t.jsx)(Rae,{})}),(0,t.jsx)(lt,{path:"apps/advanced/gateways",element:(0,t.jsx)(Qae,{})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/new",element:(0,t.jsx)(Dae,{mode:"new"})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/:profileId/edit",element:(0,t.jsx)(Dae,{mode:"edit"})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/:profileId",element:(0,t.jsx)(S4t,{})}),(0,t.jsx)(lt,{path:"apps/advanced/audit",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/advanced/run-your-own",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/advanced/:tab",element:(0,t.jsx)(Rae,{})}),(0,t.jsx)(lt,{path:"apps/app/:applicationId",element:(0,t.jsx)(Vae,{})}),(0,t.jsx)(lt,{path:"apps/app/:applicationId/:tab",element:(0,t.jsx)(Vae,{})}),(0,t.jsx)(lt,{path:"apps/:connectionId",element:(0,t.jsx)(vn,{to:"permissions",replace:!0})}),(0,t.jsx)(lt,{path:"apps/:connectionId/:tab",element:(0,t.jsx)(QDt,{})}),(0,t.jsx)(lt,{path:"company/settings/instance",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.profile"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/profile",element:(0,t.jsx)(hzt,{})})}),(0,t.jsx)(lt,{path:"company/settings/instance/general",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsx)(lt,{path:"company/settings/instance/heartbeats",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.environments"}),children:[(0,t.jsx)(lt,{path:"company/settings/instance/environments",element:(0,t.jsx)(r$,{})}),(0,t.jsx)(lt,{path:"company/settings/instance/environments/new",element:(0,t.jsx)(r$,{mode:"create"})}),(0,t.jsx)(lt,{path:"company/settings/instance/environments/:environmentId/edit",element:(0,t.jsx)(r$,{mode:"edit"})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.access"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/access",element:(0,t.jsx)(czt,{})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.experimental"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/experimental",element:(0,t.jsx)(lzt,{})})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.plugins"}),children:[(0,t.jsx)(lt,{path:"company/settings/instance/plugins",element:(0,t.jsx)(fzt,{})}),(0,t.jsx)(lt,{path:"company/settings/instance/plugins/:pluginId",element:(0,t.jsx)(xzt,{})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.adapters"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/adapters",element:(0,t.jsx)(Soe,{})})}),(0,t.jsx)(lt,{path:"company/settings/:settingsRoutePath/*",element:(0,t.jsx)(JPt,{})}),(0,t.jsx)(lt,{path:"skills/studio",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/studio/new",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/studio/:skillId",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/:skillId/studio",element:(0,t.jsx)(HCe,{})}),(0,t.jsx)(lt,{path:"skills/*",element:e?(0,t.jsx)(G$t,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(eUt,{})})}),(0,t.jsx)(lt,{path:"settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"plugins/:pluginId",element:(0,t.jsx)(Coe,{})}),(0,t.jsx)(lt,{path:"org",element:e?(0,t.jsx)(vn,{to:"/agents/all",replace:!0}):(0,t.jsx)(pg,{children:(0,t.jsx)(nUt,{})})}),(0,t.jsx)(lt,{path:"agents",element:(0,t.jsx)(vn,{to:"/agents/all",replace:!0})}),b8.map(s=>(0,t.jsx)(lt,{path:`agents/${s}`,element:e?(0,t.jsx)(Xpt,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(Xzt,{})})},s)),(0,t.jsx)(lt,{path:"agents/new",element:(0,t.jsx)(Mzt,{})}),(0,t.jsx)(lt,{path:"agents/:agentId",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/:tab",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/runs/:runId",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"projects",element:(0,t.jsx)(d0t,{})}),(0,t.jsx)(lt,{path:"projects/:projectId",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/overview",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues/:filter",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsx)(lt,{path:"projects/:projectId/workspaces/:workspaceId",element:(0,t.jsx)(nvt,{})})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/configuration",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/budget",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsx)(lt,{path:"workspaces",element:(0,t.jsx)(ivt,{})})}),(0,t.jsx)(lt,{path:"issues",element:(0,t.jsx)(pvt,{})}),(0,t.jsx)(lt,{path:"tasks",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"search",element:(0,t.jsx)(Bvt,{})}),(0,t.jsx)(lt,{path:"issues/all",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/active",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/backlog",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/done",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/recent",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"chats/:agentRef",element:(0,t.jsx)(akt,{})}),(0,t.jsx)(lt,{path:"issues/:issueId",element:(0,t.jsx)(nkt,{})}),null,(0,t.jsx)(lt,{path:"routines",element:e?(0,t.jsx)(Okt,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(Zzt,{})})}),(0,t.jsx)(lt,{path:"cases",element:(0,t.jsx)(XJ,{children:(0,t.jsx)(Xet,{})})}),(0,t.jsx)(lt,{path:"cases/:caseIdentifier",element:(0,t.jsx)(XJ,{children:(0,t.jsx)(jnt,{})})}),(0,t.jsx)(lt,{path:"status",element:(0,t.jsx)(ZJ,{children:(0,t.jsx)(one,{})})}),(0,t.jsx)(lt,{path:"status/:cardId",element:(0,t.jsx)(ZJ,{children:(0,t.jsx)(one,{})})}),(0,t.jsx)(lt,{path:"status-cards",element:(0,t.jsx)(qoe,{})}),(0,t.jsx)(lt,{path:"status-cards/:cardId",element:(0,t.jsx)(qoe,{})}),(0,t.jsx)(lt,{path:"review-queue",element:(0,t.jsx)(ng,{children:(0,t.jsx)(s1t,{})})}),(0,t.jsx)(lt,{path:"learnings",element:(0,t.jsx)(ng,{children:(0,t.jsx)(r1t,{})})}),(0,t.jsx)(lt,{path:"pipelines",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/add",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/settings",element:(0,t.jsx)(ng,{children:(0,t.jsx)(J1t,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/items/:caseId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(wCt,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/cases/:caseId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(vCt,{})})}),(0,t.jsx)(lt,{path:"routines/:routineId",element:e?(0,t.jsx)(jne,{}):(0,t.jsx)(pg,{children:(0,t.jsx)($oe,{})})}),(0,t.jsx)(lt,{path:"routines/:routineId/:section",element:e?(0,t.jsx)(jne,{}):(0,t.jsx)(pg,{children:(0,t.jsx)($oe,{})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsxs)(lt,{element:(0,t.jsx)(Met,{}),children:[(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/services",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/configuration",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/runtime-logs",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/issues",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/routines",element:(0,t.jsx)(Ty,{})})]})}),(0,t.jsx)(lt,{path:"goals",element:(0,t.jsx)(fAt,{})}),(0,t.jsx)(lt,{path:"goals/:goalId",element:(0,t.jsx)(AAt,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(Sne,{})}),(0,t.jsx)(lt,{path:"approvals",element:(0,t.jsx)(vn,{to:"/approvals/pending",replace:!0})}),(0,t.jsx)(lt,{path:"approvals/pending",element:(0,t.jsx)(_ne,{})}),(0,t.jsx)(lt,{path:"approvals/all",element:(0,t.jsx)(_ne,{})}),(0,t.jsx)(lt,{path:"approvals/:approvalId",element:(0,t.jsx)(RAt,{})}),(0,t.jsx)(lt,{path:"activity",element:e?(0,t.jsx)(g2t,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(tUt,{})})}),e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"activity/runs",element:(0,t.jsx)(zk,{section:"runs"})}),(0,t.jsx)(lt,{path:"activity/costs",element:(0,t.jsx)(zk,{section:"costs"})}),(0,t.jsx)(lt,{path:"activity/budgets",element:(0,t.jsx)(zk,{section:"budgets"})}),(0,t.jsx)(lt,{path:"activity/timeline",element:(0,t.jsx)(zk,{section:"timeline"})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(hp,{to:"/activity",forceAgentMode:!0})}),(0,t.jsx)(lt,{path:"audit/activity",element:(0,t.jsx)(hp,{to:"/activity"})}),(0,t.jsx)(lt,{path:"audit/runs",element:(0,t.jsx)(hp,{to:"/activity/runs"})}),(0,t.jsx)(lt,{path:"audit/costs",element:(0,t.jsx)(hp,{to:"/activity/costs"})}),(0,t.jsx)(lt,{path:"audit/budgets",element:(0,t.jsx)(hp,{to:"/activity/budgets"})}),(0,t.jsx)(lt,{path:"audit/timeline",element:(0,t.jsx)(hp,{to:"/activity/timeline"})}),(0,t.jsx)(lt,{path:"runs",element:(0,t.jsx)(hp,{to:"/activity/runs"})}),(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(hp,{to:"/activity/costs"})}),(0,t.jsx)(lt,{path:"budgets",element:(0,t.jsx)(hp,{to:"/activity/budgets"})})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(pg,{children:(0,t.jsx)(sUt,{})})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(vn,{to:"/activity?mode=agents",replace:!0})})]}),(0,t.jsxs)(lt,{element:(0,t.jsx)(vJe,{}),children:[(0,t.jsx)(lt,{path:"board-chat",element:(0,t.jsx)(kTt,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(Sne,{})})]}),null,(0,t.jsx)(lt,{path:"decisions",element:(0,t.jsx)(GRt,{})}),(0,t.jsx)(lt,{path:"decisions/queues/:key",element:(0,t.jsx)(ZRt,{})}),(0,t.jsx)(lt,{path:"inbox",element:(0,t.jsx)(aUt,{})}),(0,t.jsx)(lt,{path:"inbox/mine",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/recent",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/unread",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/blocked",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/all",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/requests",element:(0,t.jsx)(Yzt,{})}),(0,t.jsx)(lt,{path:"inbox/new",element:(0,t.jsx)(vn,{to:"/inbox/mine",replace:!0})}),(0,t.jsx)(lt,{path:"u/:userSlug",element:(0,t.jsx)(UIt,{})}),(0,t.jsx)(lt,{path:"design-guide",element:(0,t.jsx)(azt,{})}),(0,t.jsx)(lt,{path:"instance/settings/adapters",element:(0,t.jsx)(Soe,{})}),(0,t.jsx)(lt,{path:":pluginRoutePath/*",element:(0,t.jsx)(Coe,{})}),(0,t.jsx)(lt,{path:"*",element:(0,t.jsx)(uu,{scope:"board"})})]})}r(rUt,"boardRoutes");function Ooe({credentialSource:e="paperclip_vault"}={}){const s=Zr(),n=new URLSearchParams(s.search),{enabled:a}=Tx();return VQe(n,{chatConnectorsEnabled:a})?(0,t.jsx)(wSe,{credentialSource:e}):(0,t.jsx)(vn,{to:"/apps",replace:!0})}r(Ooe,"AppsConnectEntryRoute");function aUt(){return(0,t.jsx)(vn,{to:`/inbox/${kAe()}`,replace:!0})}r(aUt,"InboxRootRedirect");function HCe(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs(),{companyPrefix:i,skillId:o}=ja();if(a)return null;const l=(i?s.find(c=>c.issuePrefix.toUpperCase()===i.toUpperCase()):null)??n??s[0]??null;return!l||!o?(0,t.jsx)(vn,{to:"/skills/studio",replace:!0}):(0,t.jsx)(vn,{to:`/${l.issuePrefix}/skills/studio/${encodeURIComponent(o)}${e.search}${e.hash}`,replace:!0})}r(HCe,"LegacySkillStudioRedirect");function hb(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs(),{companyPrefix:i}=ja(),{hidden:o}=Ym();if(a)return(0,t.jsx)(Qm,{});const l=(i?s.find(d=>d.issuePrefix.toUpperCase()===i.toUpperCase()):null)??n??s[0]??null;if(!l)return oK({pathname:e.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{});const c=PDe(iue(`${e.pathname}${e.search}${e.hash}`),o);return(0,t.jsx)(vn,{to:`/${l.issuePrefix}${c}`,replace:!0})}r(hb,"LegacySettingsRedirect");function Foe(){const{tab:e}=ja();return(0,t.jsx)(vn,{to:QCe(e),replace:!0})}r(Foe,"LegacyToolsSettingsRedirect");function Boe(){const{tab:e}=ja();return(0,t.jsx)(vn,{to:QCe(e),replace:!0})}r(Boe,"LegacyToolsRedirect");function QCe(e){return e?e==="applications"||e==="connections"||e==="overview"||e==="examples"||e==="runtime"||e==="audit"?"/apps":e==="policies"?"/apps/advanced/profiles":`/apps/advanced/${e}`:"/apps/advanced/profiles"}r(QCe,"legacyToolsRedirectTarget");function GCe(){const{companies:e}=fs(),{openOnboarding:s}=Lo(),{t:n}=Mde(),a=Vc(),i=C5(a?.cloudBaseUrl??null),{onboardingOpen:o,onboardingRouteDismissed:l}=c5(),{companyPrefix:c}=ja(),d=c?e.find(p=>p.issuePrefix.toUpperCase()===c.toUpperCase())??null:null;if(GGe({onboardingOpen:o,routeDismissed:l}))return null;const u=d?`Add another agent to ${d.name}`:e.length>0?"Create another organization":"Create your first organization",h=d?"Run onboarding again to add an agent and a starter task for this organization.":e.length>0?"Run onboarding again to create another organization and seed its first agent.":"Get started by creating an organization and your first agent.";return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-card p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:u}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:h}),(0,t.jsx)("div",{className:"mt-4",children:!d&&a&&!i?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:n("app.cloudCreateUnavailable",{defaultValue:"Organizations are created in Paperclip Cloud. This instance can't reach it right now — try again from your Cloud portfolio."})}):(0,t.jsx)(F,{onClick:r(()=>d?s({initialStep:RT(),companyId:d.id}):a&&i?jc(i):s(),"onClick"),children:d?"Add Agent":"Start Onboarding"})})]})})}r(GCe,"OnboardingRoutePage");function iUt(){const{companies:e,selectedCompany:s,loading:n}=fs(),a=Zr();if(n)return(0,t.jsx)(Qm,{});const i=s??e[0]??null;return i?(0,t.jsx)(vn,{to:`/${i.issuePrefix}/dashboard`,replace:!0}):oK({pathname:a.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{})}r(iUt,"CompanyRootRedirect");function qoe(){const{cardId:e}=ja(),s=PIe(),n=s?`/${s}`:"";return(0,t.jsx)(vn,{to:`${n}/status${e?`/${e}`:""}`,replace:!0})}r(qoe,"StatusCardsLegacyRedirect");function hp({to:e,forceAgentMode:s=!1}){const n=Zr(),a=new URLSearchParams(n.search);s&&a.set("mode","agents");const i=a.toString();return(0,t.jsx)(vn,{to:`${e}${i?`?${i}`:""}${n.hash}`,replace:!0})}r(hp,"AuditCompatibilityRedirect");function ba(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs();if(a)return(0,t.jsx)(Qm,{});const i=n??s[0]??null;return i?(0,t.jsx)(vn,{to:`/${i.issuePrefix}${e.pathname}${e.search}${e.hash}`,replace:!0}):oK({pathname:e.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{})}r(ba,"UnprefixedBoardRedirect");function V7(){const{openOnboarding:e}=Lo(),{t:s}=Mde(),n=Vc(),a=C5(n?.cloudBaseUrl??null);return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-card p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:s("app.noCompanies.title",{defaultValue:"Create your first organization"})}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:s("app.noCompanies.description",{defaultValue:"Get started by creating an organization."})}),(0,t.jsx)("div",{className:"mt-4",children:n&&!a?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:s("app.cloudCreateUnavailable",{defaultValue:"Organizations are created in Paperclip Cloud. This instance can't reach it right now — try again from your Cloud portfolio."})}):(0,t.jsx)(F,{onClick:r(()=>n&&a?jc(a):e(),"onClick"),children:s("app.noCompanies.newCompany",{defaultValue:"New Organization"})})})]})})}r(V7,"NoCompaniesStartPage");function oUt(){const{enabled:e,loaded:s}=wc();return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(LIe,{children:[(0,t.jsx)(lt,{path:"oauth-handoff",element:(0,t.jsx)(mLt,{})}),(0,t.jsx)(lt,{path:"auth",element:(0,t.jsx)(Bzt,{})}),(0,t.jsx)(lt,{path:"board-claim/:token",element:(0,t.jsx)(qzt,{})}),(0,t.jsx)(lt,{path:"cli-auth/:id",element:(0,t.jsx)(zzt,{})}),(0,t.jsx)(lt,{path:"invite/:token",element:(0,t.jsx)(Gzt,{})}),(0,t.jsx)(lt,{element:s?(0,t.jsx)(VX,{allowMembershipRequest:!0}):(0,t.jsx)(Qm,{}),children:(0,t.jsx)(lt,{path:"chat-identity/confirm",element:(0,t.jsx)(ODt,{})})}),(0,t.jsx)(lt,{path:"tests/perf/long-thread",element:(0,t.jsx)(xkt,{})}),(0,t.jsx)(lt,{path:"ux-lab/bootstrap-setup",element:(0,t.jsx)(HPt,{})}),(0,t.jsx)(lt,{path:"ux-lab/responsible-user-denial",element:(0,t.jsx)(QPt,{})}),(0,t.jsx)(lt,{path:"ux-lab/cross-issue-collaboration",element:(0,t.jsx)(YPt,{})}),(0,t.jsxs)(lt,{element:s?(0,t.jsx)(VX,{}):(0,t.jsx)(Qm,{}),children:[(0,t.jsx)(lt,{index:!0,element:(0,t.jsx)(iUt,{})}),(0,t.jsx)(lt,{path:"onboarding",element:(0,t.jsx)(GCe,{})}),(0,t.jsx)(lt,{path:"instance",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"instance/settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"instance/settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"companies",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"issues",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"tasks",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"issues/:issueId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"routines",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"routines/:routineId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"review-queue",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"learnings",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"cases",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"cases/:caseIdentifier",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status/:cardId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status-cards",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status-cards/:cardId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/add",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/settings",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/items/:caseId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/cases/:caseId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(ba,{})}),e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"audit/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"activity",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"activity/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"runs",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"budgets",element:(0,t.jsx)(ba,{})})]}):null,(0,t.jsx)(lt,{path:"decisions",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"u/:userSlug",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio/new",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio/:skillId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/:skillId/studio",element:(0,t.jsx)(HCe,{})}),(0,t.jsx)(lt,{path:"skills/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"agents",element:(0,t.jsx)(ba,{})}),b8.map(n=>(0,t.jsx)(lt,{path:`agents/${n}`,element:(0,t.jsx)(ba,{})},n)),(0,t.jsx)(lt,{path:"agents/new",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/:tab",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/runs/:runId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/overview",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues/:filter",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces/:workspaceId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/configuration",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"workspaces",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/services",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/configuration",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/runtime-logs",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/issues",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/routines",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:":companyPrefix",element:e?(0,t.jsx)(LYe,{}):(0,t.jsx)(xJe,{}),children:rUt(e)}),(0,t.jsx)(lt,{path:"*",element:(0,t.jsx)(uu,{scope:"global"})})]})]}),(0,t.jsx)(Ynt,{})]})}r(oUt,"App");var lUt=class extends m.Component{static{r(this,"AppErrorBoundary")}state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,s){kxe(e,{boundary:"app",componentStack:s.componentStack})}render(){const{error:e}=this.state;return e?(0,t.jsxs)("div",{className:"mx-auto flex min-h-screen max-w-2xl flex-col justify-center space-y-4 px-4 py-10",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Paperclip hit an error"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Something went wrong while running the app. Reloading usually fixes this."})]}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-wrap",children:e.message}),(0,t.jsx)("div",{children:(0,t.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium shadow-sm hover:bg-accent hover:text-accent-foreground",onClick:r(()=>window.location.reload(),"onClick"),children:"Reload page"})})]}):this.props.children}};function cUt(){const{data:e}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),s=e?.sentryDsn,n=e?.sentryEnvironment??void 0;return(0,m.useEffect)(()=>{if(s)return uYe(s,n),()=>{mYe()}},[s,n]),null}r(cUt,"SentryGate");function dUt(e){return{id:e.key,title:e.title,status:e.status,projectId:e.projectId??null,assigneeAgentId:e.assigneeAgentId??null,lastRun:e.lastRunAt||e.lastRunStatus?{triggeredAt:e.lastRunAt??null,status:e.lastRunStatus??null}:null}}r(dUt,"managedRoutineToRow");function uUt({routines:e,agents:s=[],projects:n=[],pluginDisplayName:a=null,emptyMessage:i="No managed routines.",runningRoutineKey:o=null,statusMutationRoutineKey:l=null,reconcilingRoutineKey:c=null,resettingRoutineKey:d=null,onRunNow:u,onToggleEnabled:h,onReconcile:p,onReset:x}){const g=new Map(s.map(y=>[y.id,y])),v=new Map(n.map(y=>[y.id,{name:y.name,color:y.color}]));return e.length===0?(0,t.jsx)("div",{className:"rounded-lg border border-border px-3 py-8 text-center text-sm text-muted-foreground",children:i}):(0,t.jsx)("div",{className:"rounded-lg border border-border",children:e.map(y=>{const j=dUt(y),S=y.href??(y.routineId?`/routines/${y.routineId}`:"/routines"),w=y.missingRefs??[],N=!!(y.routineId&&y.resourceKey&&w.length===0),_=y.managedByPluginDisplayName??a,I=!!(p||x);return(0,t.jsxs)("div",{className:"last:[&_a]:border-b-0",children:[(0,t.jsx)(Ewe,{routine:j,projectById:v,agentById:g,runningRoutineId:o,statusMutationRoutineId:l,href:S,configureLabel:"Configure",managedByLabel:_?`Managed by ${_}`:null,runNowButton:!0,hideArchiveAction:!0,disableRunNow:!N,disableToggle:!N,secondaryDetails:(0,t.jsxs)("span",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[y.resourceKey?(0,t.jsx)("span",{children:y.resourceKey}):null,y.cronExpression?(0,t.jsxs)("span",{children:["Schedule ",y.cronExpression]}):null]}),onRunNow:r(()=>u?.(y),"onRunNow"),onToggleEnabled:r(()=>h?.(y,j.status==="active"),"onToggleEnabled")}),I?(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 pb-3 text-xs text-muted-foreground last:border-b-0",onClick:r(C=>{C.preventDefault(),C.stopPropagation()},"onClick"),children:[(0,t.jsx)("span",{children:w.length?`Missing ${w.map(C=>`${C.resourceKind}:${C.resourceKey}`).join(", ")}`:"Routine defaults can be repaired."}),(0,t.jsxs)("span",{className:"flex items-center gap-2",children:[p?(0,t.jsx)(F,{size:"sm",variant:"ghost",disabled:c===y.key,onClick:r(()=>p(y),"onClick"),children:c===y.key?"Reconciling...":"Reconcile"}):null,x?(0,t.jsx)(F,{size:"sm",variant:"ghost",disabled:d===y.key,onClick:r(()=>x(y),"onClick"),children:d===y.key?"Resetting...":"Reset"}):null]})]}):null]},y.key)})})}r(uUt,"ManagedRoutinesList");function zoe(e){return new Set(e??[])}r(zoe,"toPathSet");function mUt({expandedPaths:e,checkedPaths:s,selectedFile:n=null,showCheckboxes:a=!1,onToggleDir:i,onSelectFile:o,...l}){return(0,m.createElement)(q1,{...l,selectedFile:n,expandedDirs:zoe(e),checkedFiles:s?zoe(s):void 0,showCheckboxes:a,onToggleDir:i??(()=>{}),onSelectFile:o??(()=>{})})}r(mUt,"PluginSdkFileTree");function hUt(e){const[s,n]=(0,m.useState)(null);return(0,m.useEffect)(()=>{let a=!1;return gc(()=>import("./MarkdownEditor-B3NYD32f.js").then(i=>i.n).then(i=>{a||n(()=>i.MarkdownEditor)}),__vite__mapDeps([36,5,7,9,14,10,15,37,29,27,38])),()=>{a=!0}},[]),s?(0,m.createElement)(s,e):(0,m.createElement)("textarea",{className:e.className,value:e.value,placeholder:e.placeholder,readOnly:e.readOnly,onBlur:e.onBlur,onChange:r(a=>e.onChange(a.currentTarget.value),"onChange")})}r(hUt,"PluginSdkMarkdownEditor");function pUt(e){return Object.fromEntries(Object.entries(e).filter(([,s])=>s!=null&&s!==""&&s!==!1))}r(pUt,"compactIssueFilters");function fUt({companyId:e,projectId:s=null,filters:n,viewStateKey:a="paperclip:plugin-issues-view",initialSearch:i,createIssueLabel:o,searchWithinLoadedIssues:l=!0}){const c=Ht(),d=(0,m.useMemo)(()=>pUt({...n??{},projectId:n?.projectId??s??void 0}),[n,s]),u=d.originKindPrefix??null,h=d.projectId??s??null,p=(0,m.useMemo)(()=>["plugins","sdk-ui","issues-list",e??"__no-company__",d],[e,d]),{data:x}=ee({queryKey:P.agents.list(e??"__no-company__"),queryFn:r(()=>Wt.list(e),"queryFn"),enabled:!!e}),{data:g}=ee({queryKey:P.projects.list(e??"__no-company__",{includeArchived:!0}),queryFn:r(()=>oa.list(e,{includeArchived:!0}),"queryFn"),enabled:!!e}),v=P.liveRuns(e??"__no-company__"),y=mo({companyId:e,resourceKey:"live-runs",queryKey:v,enabled:!!e,refetchInterval:!1,leaderOnly:!0}),{data:j,dataUpdatedAt:S}=ee({queryKey:v,queryFn:r(()=>Xr.liveRunsForCompany(e),"queryFn"),enabled:y.enabled,refetchInterval:y.refetchInterval});ho(y,j,S);const{data:w,isLoading:N,error:_}=ee({queryKey:p,queryFn:r(()=>Tt.list(e,d),"queryFn"),enabled:!!e}),I=(0,m.useMemo)(()=>Sx(j,w),[w,j]),C=ye({mutationFn:r(({id:A,data:R})=>Tt.update(A,R),"mutationFn"),onSuccess:r(()=>{e&&(c.invalidateQueries({queryKey:["plugins","sdk-ui","issues-list",e]}),c.invalidateQueries({queryKey:P.issues.list(e)}),h&&(c.invalidateQueries({queryKey:P.issues.listByProject(e,h)}),u&&c.invalidateQueries({queryKey:P.issues.listPluginOperationsByProject(e,h,u)})))},"onSuccess")});return e?(0,m.createElement)(hx,{issues:w??[],isLoading:N,error:_,agents:x,projects:g,liveIssueIds:I,projectId:h??void 0,viewStateKey:a,initialSearch:i,createIssueLabel:o,searchWithinLoadedIssues:l,onUpdateIssue:r((A,R)=>C.mutate({id:A,data:R}),"onUpdateIssue")}):(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},"Select an organization to view tasks.")}r(fUt,"PluginSdkIssuesList");function xUt({companyId:e,value:s,onChange:n,placeholder:a="Responsible",noneLabel:i="No responsible",searchPlaceholder:o="Search responsible...",emptyMessage:l="No responsible found.",includeUsers:c=!0,includeTerminatedAgents:d=!1,className:u,onConfirm:h}){const p=Oz(),x=e??p.companyId??null,{data:g}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),enabled:c}),v=g?.user?.id??g?.session?.userId??null,{data:y}=ee({queryKey:P.agents.list(x??"__no-company__"),queryFn:r(()=>Wt.list(x),"queryFn"),enabled:!!x}),{data:j}=ee({queryKey:P.access.companyUserDirectory(x??"__no-company__"),queryFn:r(()=>fr.listUserDirectory(x),"queryFn"),enabled:!!x&&c}),S=(0,m.useMemo)(()=>aAe(),[]),w=(0,m.useMemo)(()=>S.map(A=>A.startsWith("agent:")?A.slice(6):null).filter(A=>!!A),[S]),N=(0,m.useMemo)(()=>Ug((y??[]).filter(A=>d||A.status!=="terminated"),w),[y,d,w]),_=(0,m.useMemo)(()=>[...c?tce(v):[],...c?zw(j?.users,{excludeUserIds:[v]}):[],...N.map(A=>({id:Rm({assigneeAgentId:A.id}),label:A.name,searchText:`${A.name} ${A.role} ${A.title??""}`}))],[j?.users,v,c,N]),I=Pc(s),C=I.assigneeAgentId?N.find(A=>A.id===I.assigneeAgentId):null;return(0,m.createElement)($l,{value:s,options:_,recentOptionIds:S,placeholder:a,noneLabel:i,searchPlaceholder:o,emptyMessage:l,className:u,onConfirm:h,onChange:r(A=>{const R=Pc(A);R.assigneeAgentId&&YC(R.assigneeAgentId),R.assigneeUserId&&Dle(R.assigneeUserId),n(A,R)},"onChange"),renderTriggerValue:r(A=>A?C?(0,m.createElement)(K3,null,(0,m.createElement)(ew,{icon:C.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,m.createElement)("span",{className:"truncate"},A.label)):(0,m.createElement)("span",{className:"truncate"},A.label):(0,m.createElement)("span",{className:"text-muted-foreground"},a),"renderTriggerValue"),renderOption:r(A=>{if(!A.id)return(0,m.createElement)("span",{className:"truncate"},A.label);const R=Pc(A.id),E=R.assigneeAgentId?N.find(O=>O.id===R.assigneeAgentId):null;return(0,m.createElement)(K3,null,E?(0,m.createElement)(ew,{icon:E.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,m.createElement)(xc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,m.createElement)("span",{className:"truncate"},A.label))},"renderOption")})}r(xUt,"PluginSdkAssigneePicker");function gUt({companyId:e,value:s,onChange:n,placeholder:a="Project",noneLabel:i="No project",searchPlaceholder:o="Search projects...",emptyMessage:l="No projects found.",includeArchived:c=!1,className:d,onConfirm:u}){const h=Oz(),p=e??h.companyId??null,{data:x}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn")}),g=x?.user?.id??x?.session?.userId??null,{data:v}=ee({queryKey:P.projects.list(p??"__no-company__",{includeArchived:c}),queryFn:r(()=>oa.list(p,{includeArchived:c}),"queryFn"),enabled:!!p}),y=(0,m.useMemo)(()=>(v??[]).filter(_=>c||!_.archivedAt),[c,v]),{orderedProjects:j}=Cv({projects:y,companyId:p,userId:g}),S=(0,m.useMemo)(()=>$w(),[]),w=(0,m.useMemo)(()=>j.map(_=>({id:_.id,label:_.name,searchText:_.description??""})),[j]),N=j.find(_=>_.id===s)??null;return(0,m.createElement)($l,{value:s,options:w,recentOptionIds:S,placeholder:a,noneLabel:i,searchPlaceholder:o,emptyMessage:l,className:d,onConfirm:u,onChange:r(_=>{_&&Mw(_),n(_)},"onChange"),renderTriggerValue:r(_=>!_||!N?(0,m.createElement)("span",{className:"text-muted-foreground"},a):(0,m.createElement)(K3,null,(0,m.createElement)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:N.color??"#6366f1"}}),(0,m.createElement)("span",{className:"truncate"},_.label)),"renderTriggerValue"),renderOption:r(_=>{if(!_.id)return(0,m.createElement)("span",{className:"truncate"},_.label);const I=j.find(C=>C.id===_.id);return(0,m.createElement)(K3,null,(0,m.createElement)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:I?.color??"#6366f1"}}),(0,m.createElement)("span",{className:"truncate"},_.label))},"renderOption")})}r(gUt,"PluginSdkProjectPicker");function K3({children:e}){return(0,m.createElement)("span",{className:"contents"},e)}r(K3,"FragmentSafe");function bUt({label:e,status:s}){const n={ok:"border-emerald-300 bg-emerald-50 text-emerald-700",warning:"border-amber-300 bg-amber-50 text-amber-800",error:"border-red-300 bg-red-50 text-red-700",info:"border-slate-300 bg-slate-50 text-slate-700",pending:"border-slate-300 bg-slate-50 text-slate-600"}[s];return(0,m.createElement)("span",{className:`inline-flex w-fit items-center rounded-full border px-2 py-0.5 text-xs font-medium ${n}`},e)}r(bUt,"PluginSdkStatusBadge");function vUt({columns:e,rows:s,loading:n,emptyMessage:a="No rows."}){if(n)return(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},"Loading...");if(!s.length)return(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},a);const i=e.map(o=>o.width??"minmax(0, 1fr)").join(" ");return(0,m.createElement)("div",{className:"overflow-hidden rounded-md border"},(0,m.createElement)("div",{className:"hidden border-b bg-muted/35 px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground md:grid md:[grid-template-columns:var(--plugin-grid-cols)]",style:{"--plugin-grid-cols":i}},e.map(o=>(0,m.createElement)("div",{key:o.key},o.header))),(0,m.createElement)("div",{className:"divide-y"},s.map((o,l)=>(0,m.createElement)("div",{key:String(o.id??l),className:"grid gap-2 px-3 py-3 md:items-center md:[grid-template-columns:var(--plugin-grid-cols)]",style:{"--plugin-grid-cols":i}},e.map(c=>(0,m.createElement)("div",{key:c.key,className:"min-w-0 text-sm"},(0,m.createElement)("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground md:hidden"},c.header),c.render?c.render(o[c.key],o):String(o[c.key]??"")))))))}r(vUt,"PluginSdkDataTable");function yUt({pairs:e}){return(0,m.createElement)("dl",{className:"grid gap-x-4 gap-y-1 text-sm sm:grid-cols-[max-content_minmax(0,1fr)]"},e.flatMap(s=>[(0,m.createElement)("dt",{key:`${s.label}:label`,className:"text-muted-foreground"},s.label),(0,m.createElement)("dd",{key:`${s.label}:value`,className:"min-w-0"},s.value)]))}r(yUt,"PluginSdkKeyValueList");function jUt({label:e,value:s,unit:n}){return(0,m.createElement)("div",{className:"rounded-md border bg-card p-3"},(0,m.createElement)("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground"},e),(0,m.createElement)("div",{className:"mt-1 text-lg font-semibold"},`${s}${n??""}`))}r(jUt,"PluginSdkMetricCard");function wUt({data:e}){return(0,m.createElement)("pre",{className:"max-h-80 overflow-auto rounded-md border bg-muted/30 p-2 text-xs"},JSON.stringify(e,null,2))}r(wUt,"PluginSdkJsonTree");function NUt({label:e="Loading"}){return(0,m.createElement)("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-muted-foreground/30 border-t-foreground align-middle",role:"status","aria-label":e})}r(NUt,"PluginSdkSpinner");var kUt=class extends m.Component{static{r(this,"PluginSdkErrorBoundary")}state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback??(0,m.createElement)("div",{className:"rounded-md border border-destructive/30 p-3 text-sm text-destructive"},"Plugin UI failed to render."):this.props.children}};function SUt(e,s){globalThis.__paperclipPluginBridge__={react:e,reactJsxRuntime:t,reactDom:s,sdkUi:{usePluginData:zDe,usePluginAction:UDe,useHostContext:Oz,useHostLocation:VDe,useHostNavigation:KDe,usePluginStream:HDe,usePluginToast:WDe,copyTextToClipboard:Gr,MarkdownBlock:r(({content:n,className:a,enableWikiLinks:i,wikiLinkRoot:o,resolveWikiLinkHref:l})=>(0,m.createElement)(Rn,{className:a,softBreaks:!1,enableWikiLinks:i,wikiLinkRoot:o,resolveWikiLinkHref:l,children:n}),"MarkdownBlock"),MetricCard:jUt,StatusBadge:bUt,DataTable:vUt,KeyValueList:yUt,JsonTree:wUt,Spinner:NUt,ErrorBoundary:kUt,MarkdownEditor:hUt,FileTree:mUt,IssuesList:fUt,AssigneePicker:xUt,ProjectPicker:gUt,ManagedRoutinesList:uUt}}}r(SUt,"initPluginBridge");var CUt=1e4;function _Ut(e=CUt){if(typeof performance>"u"||typeof performance.clearMeasures!="function")return()=>{};const n=setInterval(r(()=>{globalThis.__paperclipKeepPerfMeasures||performance.clearMeasures()},"reap"),e);return()=>clearInterval(n)}r(_Ut,"startPerfMeasureReaper");var IUt=gv((e=>{function s(K,z){var D=K.length;K.push(z);e:for(;0<D;){var V=D-1>>>1,H=K[V];if(0<i(H,z))K[V]=z,K[D]=H,D=V;else break e}}r(s,"push");function n(K){return K.length===0?null:K[0]}r(n,"peek");function a(K){if(K.length===0)return null;var z=K[0],D=K.pop();if(D!==z){K[0]=D;e:for(var V=0,H=K.length,Z=H>>>1;V<Z;){var Y=2*(V+1)-1,ie=K[Y],se=Y+1,X=K[se];if(0>i(ie,D))se<H&&0>i(X,ie)?(K[V]=X,K[se]=D,V=se):(K[V]=ie,K[Y]=D,V=Y);else if(se<H&&0>i(X,D))K[V]=X,K[se]=D,V=se;else break e}}return z}r(a,"pop");function i(K,z){var D=K.sortIndex-z.sortIndex;return D!==0?D:K.id-z.id}if(r(i,"compare"),e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var o=performance;e.unstable_now=function(){return o.now()}}else{var l=Date,c=l.now();e.unstable_now=function(){return l.now()-c}}var d=[],u=[],h=1,p=null,x=3,g=!1,v=!1,y=!1,j=!1,S=typeof setTimeout=="function"?setTimeout:null,w=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;function _(K){for(var z=n(u);z!==null;){if(z.callback===null)a(u);else if(z.startTime<=K)a(u),z.sortIndex=z.expirationTime,s(d,z);else break;z=n(u)}}r(_,"advanceTimers");function I(K){if(y=!1,_(K),!v)if(n(d)!==null)v=!0,C||(C=!0,$());else{var z=n(u);z!==null&&B(I,z.startTime-K)}}r(I,"handleTimeout");var C=!1,A=-1,R=5,E=-1;function O(){return j?!0:!(e.unstable_now()-E<R)}r(O,"shouldYieldToHost");function L(){if(j=!1,C){var K=e.unstable_now();E=K;var z=!0;try{e:{v=!1,y&&(y=!1,w(A),A=-1),g=!0;var D=x;try{t:{for(_(K),p=n(d);p!==null&&!(p.expirationTime>K&&O());){var V=p.callback;if(typeof V=="function"){p.callback=null,x=p.priorityLevel;var H=V(p.expirationTime<=K);if(K=e.unstable_now(),typeof H=="function"){p.callback=H,_(K),z=!0;break t}p===n(d)&&a(d),_(K)}else a(d);p=n(d)}if(p!==null)z=!0;else{var Z=n(u);Z!==null&&B(I,Z.startTime-K),z=!1}}break e}finally{p=null,x=D,g=!1}z=void 0}}finally{z?$():C=!1}}}r(L,"performWorkUntilDeadline");var $;if(typeof N=="function")$=r(function(){N(L)},"schedulePerformWorkUntilDeadline");else if(typeof MessageChannel<"u"){var T=new MessageChannel,q=T.port2;T.port1.onmessage=L,$=r(function(){q.postMessage(null)},"schedulePerformWorkUntilDeadline")}else $=r(function(){S(L,0)},"schedulePerformWorkUntilDeadline");function B(K,z){A=S(function(){K(e.unstable_now())},z)}r(B,"requestHostTimeout"),e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(K){K.callback=null},e.unstable_forceFrameRate=function(K){0>K||125<K||(R=0<K?Math.floor(1e3/K):5)},e.unstable_getCurrentPriorityLevel=function(){return x},e.unstable_next=function(K){switch(x){case 1:case 2:case 3:var z=3;break;default:z=x}var D=x;x=z;try{return K()}finally{x=D}},e.unstable_requestPaint=function(){j=!0},e.unstable_runWithPriority=function(K,z){switch(K){case 1:case 2:case 3:case 4:case 5:break;default:K=3}var D=x;x=K;try{return z()}finally{x=D}},e.unstable_scheduleCallback=function(K,z,D){var V=e.unstable_now();switch(typeof D=="object"&&D!==null?(D=D.delay,D=typeof D=="number"&&0<D?V+D:V):D=V,K){case 1:var H=-1;break;case 2:H=250;break;case 5:H=1073741823;break;case 4:H=1e4;break;default:H=5e3}return H=D+H,K={id:h++,callback:z,priorityLevel:K,startTime:D,expirationTime:H,sortIndex:-1},D>V?(K.sortIndex=D,s(u,K),n(d)===null&&K===n(u)&&(y?(w(A),A=-1):y=!0,B(I,D-V))):(K.sortIndex=H,s(d,K),v||g||(v=!0,C||(C=!0,$()))),K},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(K){var z=x;return function(){var D=x;x=z;try{return K.apply(this,arguments)}finally{x=D}}}})),AUt=gv(((e,s)=>{s.exports=IUt()})),RUt=gv((e=>{var s=AUt(),n=U6(),a=Xoe();function i(f){var b="https://react.dev/errors/"+f;if(1<arguments.length){b+="?args[]="+encodeURIComponent(arguments[1]);for(var k=2;k<arguments.length;k++)b+="&args[]="+encodeURIComponent(arguments[k])}return"Minified React error #"+f+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}r(i,"formatProdErrorMessage");function o(f){return!(!f||f.nodeType!==1&&f.nodeType!==9&&f.nodeType!==11)}r(o,"isValidContainer");function l(f){var b=f,k=f;if(f.alternate)for(;b.return;)b=b.return;else{f=b;do b=f,(b.flags&4098)!==0&&(k=b.return),f=b.return;while(f)}return b.tag===3?k:null}r(l,"getNearestMountedFiber");function c(f){if(f.tag===13){var b=f.memoizedState;if(b===null&&(f=f.alternate,f!==null&&(b=f.memoizedState)),b!==null)return b.dehydrated}return null}r(c,"getSuspenseInstanceFromFiber");function d(f){if(f.tag===31){var b=f.memoizedState;if(b===null&&(f=f.alternate,f!==null&&(b=f.memoizedState)),b!==null)return b.dehydrated}return null}r(d,"getActivityInstanceFromFiber");function u(f){if(l(f)!==f)throw Error(i(188))}r(u,"assertIsMounted");function h(f){var b=f.alternate;if(!b){if(b=l(f),b===null)throw Error(i(188));return b!==f?null:f}for(var k=f,M=b;;){var W=k.return;if(W===null)break;var G=W.alternate;if(G===null){if(M=W.return,M!==null){k=M;continue}break}if(W.child===G.child){for(G=W.child;G;){if(G===k)return u(W),f;if(G===M)return u(W),b;G=G.sibling}throw Error(i(188))}if(k.return!==M.return)k=W,M=G;else{for(var xe=!1,Le=W.child;Le;){if(Le===k){xe=!0,k=W,M=G;break}if(Le===M){xe=!0,M=W,k=G;break}Le=Le.sibling}if(!xe){for(Le=G.child;Le;){if(Le===k){xe=!0,k=G,M=W;break}if(Le===M){xe=!0,M=G,k=W;break}Le=Le.sibling}if(!xe)throw Error(i(189))}}if(k.alternate!==M)throw Error(i(190))}if(k.tag!==3)throw Error(i(188));return k.stateNode.current===k?f:b}r(h,"findCurrentFiberUsingSlowPath");function p(f){var b=f.tag;if(b===5||b===26||b===27||b===6)return f;for(f=f.child;f!==null;){if(b=p(f),b!==null)return b;f=f.sibling}return null}r(p,"findCurrentHostFiberImpl");var x=Object.assign,g=Symbol.for("react.element"),v=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),_=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),A=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),L=Symbol.for("react.memo_cache_sentinel"),$=Symbol.iterator;function T(f){return f===null||typeof f!="object"?null:(f=$&&f[$]||f["@@iterator"],typeof f=="function"?f:null)}r(T,"getIteratorFn");var q=Symbol.for("react.client.reference");function B(f){if(f==null)return null;if(typeof f=="function")return f.$$typeof===q?null:f.displayName||f.name||null;if(typeof f=="string")return f;switch(f){case j:return"Fragment";case w:return"Profiler";case S:return"StrictMode";case C:return"Suspense";case A:return"SuspenseList";case O:return"Activity"}if(typeof f=="object")switch(f.$$typeof){case y:return"Portal";case _:return f.displayName||"Context";case N:return(f._context.displayName||"Context")+".Consumer";case I:var b=f.render;return f=f.displayName,f||(f=b.displayName||b.name||"",f=f!==""?"ForwardRef("+f+")":"ForwardRef"),f;case R:return b=f.displayName||null,b!==null?b:B(f.type)||"Memo";case E:b=f._payload,f=f._init;try{return B(f(b))}catch{}}return null}r(B,"getComponentNameFromType");var K=Array.isArray,z=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=a.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V={pending:!1,data:null,method:null,action:null},H=[],Z=-1;function Y(f){return{current:f}}r(Y,"createCursor");function ie(f){0>Z||(f.current=H[Z],H[Z]=null,Z--)}r(ie,"pop");function se(f,b){Z++,H[Z]=f.current,f.current=b}r(se,"push");var X=Y(null),le=Y(null),oe=Y(null),te=Y(null);function J(f,b){switch(se(oe,b),se(le,f),se(X,null),b.nodeType){case 9:case 11:f=(f=b.documentElement)&&(f=f.namespaceURI)?JV(f):0;break;default:if(f=b.tagName,b=b.namespaceURI)b=JV(b),f=XV(b,f);else switch(f){case"svg":f=1;break;case"math":f=2;break;default:f=0}}ie(X),se(X,f)}r(J,"pushHostContainer");function Q(){ie(X),ie(le),ie(oe)}r(Q,"popHostContainer");function pe(f){f.memoizedState!==null&&se(te,f);var b=X.current,k=XV(b,f.type);b!==k&&(se(le,f),se(X,k))}r(pe,"pushHostContext");function re(f){le.current===f&&(ie(X),ie(le)),te.current===f&&(ie(te),MN._currentValue=V)}r(re,"popHostContext");var ne,ae;function me(f){if(ne===void 0)try{throw Error()}catch(k){var b=k.stack.trim().match(/\n( *(at )?)/);ne=b&&b[1]||"",ae=-1<k.stack.indexOf(`
725
+ `)}z!==S&&(n.textContent=z,S=z)}r(A,"step");function R(){const T=d>0&&u>0;if(a.matches){o&&(o=!1,s.current!==null&&cancelAnimationFrame(s.current),s.current=null),T&&_();return}if(!i||!T){o&&(o=!1,s.current!==null&&cancelAnimationFrame(s.current),s.current=null);return}o||(o=!0,l=0,s.current=requestAnimationFrame(A))}r(R,"syncLoop");const E=new ResizeObserver(()=>{const T=Toe(n);h=T.w,p=T.h,N(),R()});E.observe(n);const O=r(()=>{i=document.visibilityState!=="hidden",R()},"onVisibilityChange");document.addEventListener("visibilitychange",O);const L=r(()=>{R()},"onMotionChange");a.addEventListener("change",L);const $=Toe(n);return h=$.w,p=$.h,N(),R(),()=>{o=!1,s.current!==null&&cancelAnimationFrame(s.current),E.disconnect(),document.removeEventListener("visibilitychange",O),a.removeEventListener("change",L)}},[]),(0,t.jsx)("pre",{ref:e,className:"w-full h-full m-0 p-0 overflow-hidden text-muted-foreground/60 select-none leading-none",style:{fontSize:"var(--text-micro)",fontFamily:"monospace"},"aria-hidden":"true"})}r(Ozt,"AsciiArtAnimation");function Fzt({decorative:e=!1,title:s="Paperclip",className:n,...a}){return(0,t.jsxs)("svg",{...a,className:n,viewBox:"22.5 22.5 121 27",fill:"currentColor",role:e?void 0:"img","aria-hidden":e?!0:void 0,"aria-label":e?void 0:s,focusable:"false",children:[(0,t.jsx)("path",{d:"M131.15 48.4902V31.9902H133.922V33.9775H134.094C134.237 33.6911 134.441 33.3831 134.706 33.0537C134.971 32.7171 135.329 32.4307 135.78 32.1943C136.239 31.958 136.822 31.8398 137.531 31.8398C138.455 31.8398 139.289 32.0762 140.034 32.5488C140.779 33.0215 141.37 33.7161 141.807 34.6328C142.251 35.5495 142.473 36.6774 142.473 38.0166C142.473 39.3343 142.258 40.4551 141.828 41.3789C141.398 42.3027 140.808 43.0081 140.056 43.4951C139.311 43.9749 138.466 44.2148 137.521 44.2148C136.84 44.2148 136.271 44.1003 135.812 43.8711C135.361 43.6348 134.996 43.3555 134.717 43.0332C134.445 42.7038 134.237 42.3923 134.094 42.0986H133.976V48.4902H131.15ZM136.747 41.8945C137.37 41.8945 137.889 41.7262 138.305 41.3896C138.727 41.0531 139.046 40.5911 139.261 40.0039C139.476 39.4167 139.583 38.7507 139.583 38.0059C139.583 37.2611 139.476 36.5986 139.261 36.0186C139.046 35.4385 138.731 34.9837 138.315 34.6543C137.9 34.3249 137.377 34.1602 136.747 34.1602C136.138 34.1602 135.623 34.3177 135.2 34.6328C134.785 34.9479 134.466 35.3955 134.244 35.9756C134.029 36.5485 133.922 37.2253 133.922 38.0059C133.922 38.7793 134.029 39.4596 134.244 40.0469C134.466 40.627 134.788 41.0817 135.211 41.4111C135.633 41.7334 136.146 41.8945 136.747 41.8945Z"}),(0,t.jsx)("path",{d:"M126.451 44V31.9902H129.276V44H126.451ZM127.869 30.3037C127.417 30.3037 127.031 30.1533 126.708 29.8525C126.386 29.5518 126.225 29.1901 126.225 28.7676C126.225 28.3379 126.386 27.9727 126.708 27.6719C127.031 27.3711 127.417 27.2207 127.869 27.2207C128.313 27.2207 128.696 27.3711 129.018 27.6719C129.34 27.9727 129.501 28.3343 129.501 28.7568C129.501 29.1865 129.34 29.5518 129.018 29.8525C128.696 30.1533 128.313 30.3037 127.869 30.3037Z"}),(0,t.jsx)("path",{d:"M124.576 27.9941V44H121.75V27.9941H124.576Z"}),(0,t.jsx)("path",{d:"M115.3 44.2363C114.104 44.2363 113.076 43.9749 112.217 43.4521C111.357 42.9222 110.699 42.1917 110.24 41.2607C109.782 40.3298 109.553 39.2591 109.553 38.0488C109.553 36.8242 109.785 35.7464 110.251 34.8154C110.716 33.8844 111.379 33.1576 112.238 32.6348C113.098 32.1048 114.111 31.8398 115.278 31.8398C116.259 31.8398 117.126 32.0189 117.878 32.377C118.63 32.735 119.228 33.2399 119.672 33.8916C120.123 34.5361 120.381 35.2917 120.445 36.1582H117.738C117.667 35.7715 117.527 35.4242 117.319 35.1162C117.112 34.8083 116.84 34.5648 116.503 34.3857C116.174 34.2067 115.78 34.1172 115.321 34.1172C114.741 34.1172 114.233 34.2747 113.796 34.5898C113.366 34.8978 113.03 35.3418 112.786 35.9219C112.543 36.502 112.421 37.1966 112.421 38.0059C112.421 38.8223 112.539 39.5277 112.775 40.1221C113.012 40.7093 113.348 41.1641 113.785 41.4863C114.222 41.8014 114.734 41.959 115.321 41.959C115.944 41.959 116.471 41.7764 116.9 41.4111C117.337 41.0459 117.617 40.541 117.738 39.8965H120.445C120.381 40.7487 120.13 41.5007 119.693 42.1523C119.257 42.804 118.666 43.3161 117.921 43.6885C117.176 44.0537 116.302 44.2363 115.3 44.2363Z"}),(0,t.jsx)("path",{d:"M102.876 44V31.9902H105.615V34.0098H105.744C105.959 33.3079 106.335 32.7708 106.872 32.3984C107.409 32.0189 108.021 31.8291 108.709 31.8291C108.859 31.8291 109.031 31.8363 109.225 31.8506C109.425 31.8649 109.59 31.8828 109.719 31.9043V34.5039C109.597 34.4609 109.407 34.4251 109.149 34.3965C108.892 34.3678 108.645 34.3535 108.408 34.3535C107.885 34.3535 107.42 34.4645 107.012 34.6865C106.604 34.9085 106.281 35.2129 106.045 35.5996C105.816 35.9863 105.701 36.4375 105.701 36.9531V44H102.876Z"}),(0,t.jsx)("path",{d:"M96.2319 44.2363C95.0288 44.2363 93.9904 43.9857 93.1167 43.4844C92.243 42.9759 91.5698 42.2598 91.0972 41.3359C90.6317 40.4121 90.3989 39.3236 90.3989 38.0703C90.3989 36.8314 90.6317 35.7464 91.0972 34.8154C91.5627 33.8773 92.2179 33.1468 93.063 32.624C93.908 32.1012 94.9035 31.8398 96.0493 31.8398C96.7869 31.8398 97.4852 31.958 98.144 32.1943C98.8101 32.4307 99.3973 32.7959 99.9058 33.29C100.421 33.7842 100.826 34.4144 101.12 35.1807C101.413 35.9398 101.56 36.8457 101.56 37.8984V38.7793H91.7202V36.8779H100.153L98.8315 37.4365C98.8315 36.7562 98.7277 36.1654 98.52 35.6641C98.3123 35.1556 98.0044 34.7581 97.5962 34.4717C97.188 34.1852 96.6795 34.042 96.0708 34.042C95.4621 34.042 94.9429 34.1852 94.5132 34.4717C94.0835 34.7581 93.7576 35.1449 93.5356 35.6318C93.3136 36.1117 93.2026 36.6488 93.2026 37.2432V38.5645C93.2026 39.2949 93.328 39.9215 93.5786 40.4443C93.8364 40.96 94.1945 41.3538 94.6528 41.626C95.1183 41.8981 95.659 42.0342 96.2749 42.0342C96.6759 42.0342 97.0412 41.9769 97.3706 41.8623C97.7072 41.7477 97.9937 41.5758 98.23 41.3467C98.4735 41.1104 98.6597 40.8203 98.7886 40.4766L101.431 40.7881C101.259 41.4827 100.941 42.0915 100.475 42.6143C100.017 43.1299 99.4259 43.5309 98.7026 43.8174C97.9865 44.0967 97.1629 44.2363 96.2319 44.2363Z"}),(0,t.jsx)("path",{d:"M78.2437 48.4902V31.9902H81.0151V33.9775H81.187C81.3302 33.6911 81.5343 33.3831 81.7993 33.0537C82.0643 32.7171 82.4224 32.4307 82.8735 32.1943C83.3319 31.958 83.9155 31.8398 84.6245 31.8398C85.5483 31.8398 86.3826 32.0762 87.1274 32.5488C87.8722 33.0215 88.4631 33.7161 88.8999 34.6328C89.3439 35.5495 89.5659 36.6774 89.5659 38.0166C89.5659 39.3343 89.3511 40.4551 88.9214 41.3789C88.4917 42.3027 87.9009 43.0081 87.1489 43.4951C86.4041 43.9749 85.5591 44.2148 84.6138 44.2148C83.9334 44.2148 83.3641 44.1003 82.9058 43.8711C82.4546 43.6348 82.0894 43.3555 81.8101 43.0332C81.5379 42.7038 81.3302 42.3923 81.187 42.0986H81.0688V48.4902H78.2437ZM83.8403 41.8945C84.4634 41.8945 84.9826 41.7262 85.3979 41.3896C85.8205 41.0531 86.1392 40.5911 86.354 40.0039C86.5688 39.4167 86.6763 38.7507 86.6763 38.0059C86.6763 37.2611 86.5688 36.5986 86.354 36.0186C86.1392 35.4385 85.8241 34.9837 85.4087 34.6543C84.9933 34.3249 84.4705 34.1602 83.8403 34.1602C83.2316 34.1602 82.716 34.3177 82.2935 34.6328C81.8781 34.9479 81.5594 35.3955 81.3374 35.9756C81.1226 36.5485 81.0151 37.2253 81.0151 38.0059C81.0151 38.7793 81.1226 39.4596 81.3374 40.0469C81.5594 40.627 81.8817 41.0817 82.3042 41.4111C82.7267 41.7334 83.2388 41.8945 83.8403 41.8945Z"}),(0,t.jsx)("path",{d:"M70.042 44.2471C69.2757 44.2471 68.5882 44.111 67.9795 43.8389C67.3708 43.5596 66.891 43.1514 66.54 42.6143C66.1891 42.0771 66.0137 41.4147 66.0137 40.627C66.0137 39.9538 66.139 39.3952 66.3896 38.9512C66.6403 38.5072 66.9805 38.1527 67.4102 37.8877C67.847 37.6227 68.3376 37.4222 68.8818 37.2861C69.4261 37.1429 69.9883 37.0426 70.5684 36.9854C71.2773 36.9066 71.8503 36.8385 72.2871 36.7812C72.724 36.724 73.0391 36.6309 73.2324 36.502C73.4329 36.373 73.5332 36.1725 73.5332 35.9004V35.8467C73.5332 35.2666 73.3613 34.8154 73.0176 34.4932C72.6738 34.1709 72.1725 34.0098 71.5137 34.0098C70.819 34.0098 70.2676 34.1602 69.8594 34.4609C69.4583 34.7617 69.1862 35.1162 69.043 35.5244L66.4111 35.1484C66.6188 34.418 66.9626 33.8092 67.4424 33.3223C67.9222 32.8281 68.5059 32.4593 69.1934 32.2158C69.888 31.9652 70.6543 31.8398 71.4922 31.8398C72.0651 31.8398 72.638 31.9079 73.2109 32.0439C73.7839 32.1729 74.3102 32.3949 74.79 32.71C75.2699 33.0251 75.653 33.4476 75.9395 33.9775C76.2259 34.5075 76.3691 35.1699 76.3691 35.9648V44H73.6514V42.3457H73.5654C73.3936 42.6751 73.1501 42.9867 72.835 43.2803C72.527 43.5667 72.1403 43.7995 71.6748 43.9785C71.2165 44.1576 70.6722 44.2471 70.042 44.2471ZM70.7617 42.1631C71.3346 42.1631 71.8288 42.0521 72.2441 41.8301C72.6595 41.6009 72.9818 41.3001 73.2109 40.9277C73.4401 40.5482 73.5547 40.1364 73.5547 39.6924V38.2852C73.4616 38.3568 73.3112 38.4248 73.1035 38.4893C72.8958 38.5465 72.6595 38.6003 72.3945 38.6504C72.1296 38.7005 71.8682 38.7435 71.6104 38.7793C71.3597 38.8151 71.1413 38.8438 70.9551 38.8652C70.5326 38.9225 70.153 39.0192 69.8164 39.1553C69.487 39.2842 69.2256 39.4632 69.0322 39.6924C68.8389 39.9215 68.7422 40.2188 68.7422 40.584C68.7422 41.1068 68.932 41.5007 69.3115 41.7656C69.6911 42.0306 70.1745 42.1631 70.7617 42.1631Z"}),(0,t.jsx)("path",{d:"M53.7939 44V27.9941H59.7988C61.0306 27.9941 62.0618 28.2233 62.8926 28.6816C63.7305 29.14 64.3643 29.7702 64.7939 30.5723C65.2236 31.3743 65.4385 32.2839 65.4385 33.3008C65.4385 34.3249 65.2201 35.238 64.7832 36.04C64.3535 36.835 63.7161 37.4616 62.8711 37.9199C62.026 38.3711 60.9876 38.5967 59.7559 38.5967H55.7812V36.2119H59.3584C60.0817 36.2119 60.6725 36.0902 61.1309 35.8467C61.5964 35.596 61.9365 35.2523 62.1514 34.8154C62.3734 34.3714 62.4844 33.8665 62.4844 33.3008C62.4844 32.7279 62.3734 32.2266 62.1514 31.7969C61.9365 31.36 61.5964 31.0234 61.1309 30.7871C60.6725 30.5436 60.0781 30.4219 59.3477 30.4219H56.6943V44H53.7939Z"}),(0,t.jsx)("path",{d:"M46.2611 33.6556L34.7307 44.6408C32.7445 46.5331 29.5205 46.5323 27.5303 44.6361C25.5404 42.74 25.54 39.669 27.5261 37.7768L39.0565 26.7916C40.2474 25.657 42.1811 25.6567 43.3752 26.7943C44.5693 27.9319 44.5689 29.7742 43.378 30.9088L31.849 41.8954C31.4528 42.2728 30.8077 42.273 30.4092 41.8933C30.011 41.5136 30.0117 40.8996 30.4078 40.5223L41.9382 29.5371C42.336 29.1581 42.336 28.5437 41.9382 28.1647C41.5404 27.786 40.8954 27.7858 40.4977 28.1647L28.9673 39.1499C27.7742 40.2866 27.7764 42.1295 28.9687 43.2657C30.1613 44.402 32.0963 44.4046 33.2895 43.2678L44.8192 32.2805C46.8068 30.3865 46.8038 27.3159 44.8157 25.4219C42.8275 23.5277 39.6039 23.5253 37.616 25.4192L26.0856 36.4044C23.3024 39.056 23.3058 43.3558 26.0898 46.0085C28.8741 48.6612 33.388 48.6649 36.1712 46.0132L47.7017 35.028C48.0994 34.649 48.0994 34.0346 47.7017 33.6556C47.3039 33.2766 46.6589 33.2766 46.2611 33.6556Z"})]})}r(Fzt,"PaperclipLockup");function Bzt(){const e=Ht(),s=Wn(),[n]=Ri(),[a,i]=(0,m.useState)("sign_in"),[o,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(""),[u,h]=(0,m.useState)(""),[p,x]=(0,m.useState)(null),g="auth-error",v=(0,m.useMemo)(()=>n.get("next")||Dzt()||"/",[n]),{data:y,isLoading:j}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1});(0,m.useEffect)(()=>{y&&s(v,{replace:!0})},[y,s,v]);const S=ye({mutationFn:r(async()=>{if(a==="sign_in"){await Pa.signInEmail({email:c.trim(),password:u});return}await Pa.signUpEmail({name:o.trim(),email:c.trim(),password:u})},"mutationFn"),onSuccess:r(async()=>{x(null),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.resetQueries({queryKey:P.companies.all}),s(v,{replace:!0})},"onSuccess"),onError:r(N=>{x(N instanceof Error?N.message:"Authentication failed")},"onError")}),w=c.trim().length>0&&u.trim().length>0&&(a==="sign_in"||o.trim().length>0&&u.trim().length>=8);return j?(0,t.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,t.jsx)(Qm,{className:"min-h-0"})}):(0,t.jsxs)("div",{className:"fixed inset-0 flex bg-background",children:[(0,t.jsx)("div",{className:"absolute top-4 right-4 z-10",children:(0,t.jsx)(Cj,{})}),(0,t.jsx)("div",{className:"w-full md:w-1/2 flex flex-col overflow-y-auto",children:(0,t.jsxs)("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12",children:[(0,t.jsx)("div",{className:"mb-8",children:(0,t.jsx)(Fzt,{className:"h-5 w-auto"})}),(0,t.jsx)("h1",{className:"text-xl font-semibold",children:a==="sign_in"?"Sign in to Paperclip":"Create your Paperclip account"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:a==="sign_in"?"Use your email and password to access this instance.":"Create an account for this instance. Email confirmation is not required in v1."}),(0,t.jsxs)("form",{className:"mt-6 space-y-4",method:"post",action:a==="sign_up"?"/api/auth/sign-up/email":"/api/auth/sign-in/email",onSubmit:r(N=>{if(N.preventDefault(),!S.isPending){if(!w){x("Please fill in all required fields.");return}S.mutate()}},"onSubmit"),children:[a==="sign_up"&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"name",className:"text-xs text-muted-foreground mb-1 block",children:"Name"}),(0,t.jsx)("input",{id:"name",name:"name",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",value:o,onChange:r(N=>l(N.target.value),"onChange"),autoComplete:"name",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0,autoFocus:!0})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"email",className:"text-xs text-muted-foreground mb-1 block",children:"Email"}),(0,t.jsx)("input",{id:"email",name:"email",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"email",value:c,onChange:r(N=>d(N.target.value),"onChange"),autoComplete:"username",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0,autoFocus:a==="sign_in"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{htmlFor:"password",className:"text-xs text-muted-foreground mb-1 block",children:"Password"}),(0,t.jsx)("input",{id:"password",name:"password",className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"password",value:u,onChange:r(N=>h(N.target.value),"onChange"),autoComplete:a==="sign_in"?"current-password":"new-password",required:!0,"aria-required":"true","aria-invalid":p?!0:void 0,"aria-describedby":p?g:void 0})]}),p&&(0,t.jsx)("p",{id:g,role:"alert",className:"text-xs text-destructive",children:p}),(0,t.jsx)(F,{type:"submit",disabled:S.isPending,"aria-disabled":!w||S.isPending,className:`w-full ${!w&&!S.isPending?"opacity-50":""}`,children:S.isPending?"Working…":a==="sign_in"?"Sign In":"Create Account"})]}),(0,t.jsxs)("div",{className:"mt-5 text-sm text-muted-foreground",children:[a==="sign_in"?"Need an account?":"Already have an account?"," ",(0,t.jsx)("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2",onClick:r(()=>{x(null),i(a==="sign_in"?"sign_up":"sign_in")},"onClick"),children:a==="sign_in"?"Create one":"Sign in"})]})]})}),(0,t.jsx)("div",{className:"hidden md:block w-1/2 overflow-hidden",children:(0,t.jsx)(Ozt,{})})]})}r(Bzt,"AuthPage");function qzt(){const e=Ht(),s=ja(),[n]=Ri(),a=(s.token??"").trim(),i=(n.get("code")??"").trim(),o=(0,m.useMemo)(()=>`/board-claim/${encodeURIComponent(a)}${i?`?code=${encodeURIComponent(i)}`:""}`,[a,i]),l=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),c=ee({queryKey:["board-claim",a,i],queryFn:r(()=>fr.getBoardClaimStatus(a,i),"queryFn"),enabled:a.length>0&&i.length>0,retry:!1}),d=ye({mutationFn:r(()=>fr.claimBoard(a,i),"mutationFn"),onSuccess:r(async()=>{await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.invalidateQueries({queryKey:P.companies.all}),await e.invalidateQueries({queryKey:P.companies.stats}),await c.refetch()},"onSuccess")});if(!a||!i)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid board claim URL."});if(c.isLoading||l.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading claim challenge..."});if(c.error)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Claim challenge unavailable"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:c.error instanceof Error?c.error.message:"Challenge is invalid or expired."})]})});const u=c.data;return u?u.status==="claimed"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Board ownership claimed"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This instance is now linked to your authenticated user."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})]})}):l.data?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Claim Board ownership"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This will promote your user to instance admin and migrate organization ownership access from local trusted mode."}),d.error&&(0,t.jsx)("p",{className:"mt-3 text-sm text-destructive",children:d.error instanceof Error?d.error.message:"Failed to claim board ownership"}),(0,t.jsx)(F,{className:"mt-5",onClick:r(()=>d.mutate(),"onClick"),disabled:d.isPending,children:d.isPending?"Claiming…":"Claim ownership"})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Sign in required"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to claim Board ownership."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:`/auth?next=${encodeURIComponent(o)}`,children:"Sign in / Create account"})})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Claim challenge unavailable."})}r(qzt,"BoardClaimPage");function zzt(){const e=Ht(),s=ja(),[n]=Ri(),a=(s.id??"").trim(),i=(n.get("token")??"").trim(),o=(0,m.useMemo)(()=>`/cli-auth/${encodeURIComponent(a)}${i?`?token=${encodeURIComponent(i)}`:""}`,[a,i]),l=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),c=ee({queryKey:["cli-auth-challenge",a,i],queryFn:r(()=>fr.getCliAuthChallenge(a,i),"queryFn"),enabled:a.length>0&&i.length>0,retry:!1}),d=ye({mutationFn:r(()=>fr.approveCliAuthChallenge(a,i),"mutationFn"),onSuccess:r(async()=>{await e.invalidateQueries({queryKey:P.auth.session}),await c.refetch()},"onSuccess")}),u=ye({mutationFn:r(()=>fr.cancelCliAuthChallenge(a,i),"mutationFn"),onSuccess:r(async()=>{await c.refetch()},"onSuccess")});if(!a||!i)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid CLI auth URL."});if(l.isLoading||c.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading CLI auth challenge..."});if(c.error)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"CLI auth challenge unavailable"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:c.error instanceof Error?c.error.message:"Challenge is invalid or expired."})]})});const h=c.data;return h?h.status==="approved"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"CLI access approved"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"The Paperclip CLI can now finish authentication on the requesting machine."}),(0,t.jsxs)("p",{className:"mt-4 text-sm text-muted-foreground",children:["Command: ",(0,t.jsx)("span",{className:"font-mono text-foreground",children:h.command})]})]})}):h.status==="cancelled"||h.status==="expired"?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:h.status==="expired"?"CLI auth challenge expired":"CLI auth challenge cancelled"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Start the CLI auth flow again from your terminal to generate a new approval request."})]})}):h.requiresSignIn||!l.data?(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Sign in required"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to approve the CLI access request."}),(0,t.jsx)(F,{asChild:!0,className:"mt-4",children:(0,t.jsx)(Qe,{to:`/auth?next=${encodeURIComponent(o)}`,children:"Sign in / Create account"})})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)(Gs,{className:"block p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:"Approve Paperclip CLI access"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"A local Paperclip CLI process is requesting board access to this instance."}),(0,t.jsxs)("div",{className:"mt-5 space-y-3 text-sm",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Command"}),(0,t.jsx)("div",{className:"font-mono text-foreground",children:h.command})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Client"}),(0,t.jsx)("div",{className:"text-foreground",children:h.clientName??"paperclip-pro cli"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Requested access"}),(0,t.jsx)("div",{className:"text-foreground",children:h.requestedAccess==="instance_admin_required"?"Instance admin":"Board"})]}),h.requestedCompanyName&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Requested organization"}),(0,t.jsx)("div",{className:"text-foreground",children:h.requestedCompanyName})]})]}),(d.error||u.error)&&(0,t.jsx)("p",{className:"mt-4 text-sm text-destructive",children:(d.error??u.error)instanceof Error?(d.error??u.error).message:"Failed to update CLI auth challenge"}),!h.canApprove&&(0,t.jsx)("p",{className:"mt-4 text-sm text-destructive",children:"This challenge requires instance-admin access. Sign in with an instance admin account to approve it."}),(0,t.jsxs)("div",{className:"mt-5 flex gap-3",children:[(0,t.jsx)(F,{onClick:r(()=>d.mutate(),"onClick"),disabled:!h.canApprove||d.isPending||u.isPending,children:d.isPending?"Approving...":"Approve CLI access"}),(0,t.jsx)(F,{type:"button",variant:"outline",onClick:r(()=>u.mutate(),"onClick"),disabled:d.isPending||u.isPending,children:u.isPending?"Cancelling...":"Cancel"})]})]})}):(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"CLI auth challenge unavailable."})}r(zzt,"CliAuthPage");var Uzt=gIe.filter(e=>e!=="paperclip_runner"),Eoe=new Set(["claude_local","codex_local","gemini_local","kimi_local","opencode_local","pi_local","cursor"]);function Kzt(e,s){let n=e;for(const a of s){if(!n||typeof n!="object")return null;n=n[a]}return typeof n=="string"&&n.trim().length>0?n:null}r(Kzt,"readNestedString");var $y="w-full border border-zinc-800 bg-zinc-950 px-3 py-2 text-sm text-zinc-100 outline-none focus:border-zinc-500",Poe="border border-zinc-800 bg-zinc-950/95 p-6",Moe="flex-1 border px-3 py-2 text-sm transition-colors";function Vzt(e){return e?e.charAt(0).toUpperCase()+e.slice(1):null}r(Vzt,"formatHumanRole");function WCe(e){if(!e||typeof e!="object")return null;const s=e.code;return typeof s=="string"&&s.trim().length>0?s:null}r(WCe,"getAuthErrorCode");function Wzt(e){if(!(e instanceof Error))return null;const s=e.message.trim();return s.length>0?s:null}r(Wzt,"getAuthErrorMessage");function Hzt(e,s,n){const a=WCe(e),i=Wzt(e),o=n.trim().length>0?n.trim():"that email";return a==="USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL"?{tone:"info",message:`An account already exists for ${o}. Sign in below to continue with this invite.`}:a==="INVALID_EMAIL_OR_PASSWORD"?{tone:"error",message:"That email and password did not match an existing Paperclip account. Check both fields, or create an account first if you are new here."}:s==="sign_in"&&i==="Request failed: 401"?{tone:"error",message:"That email and password did not match an existing Paperclip account. Check both fields, or create an account first if you are new here."}:s==="sign_up"&&i==="Request failed: 422"?{tone:"info",message:`An account may already exist for ${o}. Try signing in instead.`}:{tone:"error",message:i??"Authentication failed"}}r(Hzt,"mapInviteAuthFeedback");function Doe(e){return!!(e&&typeof e=="object"&&"bootstrapAccepted"in e)}r(Doe,"isBootstrapAcceptancePayload");function Qzt(e,s){return!e||typeof e!="object"||s?!1:e.status==="approved"}r(Qzt,"isApprovedHumanJoinPayload");function B6({companyDisplayName:e,companyLogoUrl:s,className:n}){return(0,t.jsx)(Rx,{companyName:e,logoUrl:s,logoFit:"contain",className:n})}r(B6,"InviteCompanyLogo");function Loe({companyDisplayName:e,companyLogoUrl:s,invitedByUserName:n,claimSecret:a=null,claimApiKeyPath:i=null,onboardingTextUrl:o=null}){return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6","data-testid":"invite-pending-approval",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(B6,{companyDisplayName:e,companyLogoUrl:s,className:"h-12 w-12 border border-zinc-800 rounded-none"}),(0,t.jsxs)("h1",{className:"text-lg font-semibold",children:["Request to join ",e]})]}),(0,t.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,t.jsxs)("p",{className:"text-sm text-zinc-400",children:["Your request is still awaiting approval. ",n??"An organization admin"," must approve your request to join."]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("p",{className:"text-xs text-zinc-500 mb-1",children:"Approval page"}),(0,t.jsx)("p",{className:"text-sm text-zinc-200",children:"Settings → Members"})]}),(0,t.jsxs)("p",{className:"text-sm text-zinc-400",children:["Ask them to visit ",(0,t.jsx)("span",{className:"text-zinc-200",children:"Settings → Members"})," to approve your request."]}),(0,t.jsx)("p",{className:"text-xs text-zinc-500",children:"Refresh this page after you've been approved — you'll be redirected automatically."})]}),a&&i?(0,t.jsxs)("div",{className:"mt-4 space-y-1 border border-zinc-800 p-3 text-xs text-zinc-400",children:[(0,t.jsx)("div",{className:"text-zinc-200",children:"Claim secret"}),(0,t.jsx)("div",{className:"font-mono break-all",children:a}),(0,t.jsxs)("div",{className:"font-mono break-all",children:["POST ",i]})]}):null,o?(0,t.jsxs)("div",{className:"mt-4 text-xs text-zinc-400",children:["Onboarding: ",(0,t.jsx)("span",{className:"font-mono break-all",children:o})]}):null]})})}r(Loe,"AwaitingJoinApprovalPanel");function Gzt(){const e=Ht(),s=Wn(),{setSelectedCompanyId:n}=fs(),a=(ja().token??"").trim(),[i,o]=(0,m.useState)("sign_up"),[l,c]=(0,m.useState)(""),[d,u]=(0,m.useState)(""),[h,p]=(0,m.useState)(""),[x,g]=(0,m.useState)(""),[v,y]=(0,m.useState)("claude_local"),[j,S]=(0,m.useState)(""),[w,N]=(0,m.useState)(null),[_,I]=(0,m.useState)(null),[C,A]=(0,m.useState)(null),[R,E]=(0,m.useState)(!1),O="invite-auth-error",L=ee({queryKey:P.health,queryFn:r(()=>Ju.get(),"queryFn"),retry:!1}),$=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),T=ee({queryKey:P.access.invite(a),queryFn:r(()=>fr.getInvite(a),"queryFn"),enabled:a.length>0,retry:!1}),q=z6({enabled:!!$.data&&!!T.data?.companyId,staleTime:0}),B=L.data?.deploymentMode!=="local_trusted"?q.isFetchedAfterMount:!0,K=B?q.data?.companies??[]:[];(0,m.useEffect)(()=>{a&&Aoe(a)},[a]),(0,m.useEffect)(()=>{E(!1)},[a]),(0,m.useEffect)(()=>{if(!B)return;const he=q.data?.companies;!he||!T.data?.companyId||he.some(Ie=>Ie.id===T.data.companyId)&&GA(a)},[q.data,T.data,B,a]);const z=T.data,D=!!$.data&&!!z?.companyId&&!B,V=!!z?.companyId&&K.some(he=>he.id===z?.companyId),H=z?.companyName?.trim()||"this Paperclip company",Z=z?.companyLogoUrl?.trim()||null,Y=z?.invitedByUserName?.trim()||null,ie=z?.inviteMessage?.trim()||null,se=Vzt(z?.humanRole),X=z?.joinRequestStatus??null,le=z?.joinRequestType??null,oe=le==="human"&&(X==="pending_approval"||X==="approved"),te=L.data?.deploymentMode==="authenticated"&&!$.data&&z?.allowedJoinTypes!=="agent",J=z?.inviteType!=="bootstrap_ceo"&&z?.allowedJoinTypes==="agent",Q=!!$.data&&!J&&z?.inviteType!=="bootstrap_ceo"&&(!X||oe)&&!D&&!V&&!w&&_===null,pe=$.data?.user.name?.trim()||$.data?.user.email?.trim()||"this account",re=d.trim().length>0&&h.trim().length>0&&(i==="sign_in"||l.trim().length>0&&h.trim().length>=8),ne=ye({mutationFn:r(async()=>{if(!z)throw new Error("Invite not found");if(D)throw new Error("Checking your organization access. Try again in a moment.");if(V)throw new Error("This account already belongs to the organization.");return z.inviteType==="bootstrap_ceo"||z.allowedJoinTypes!=="agent"?fr.acceptInvite(a,{requestType:"human"}):fr.acceptInvite(a,{requestType:"agent",agentName:x.trim(),adapterType:v,capabilities:j.trim()||null})},"mutationFn"),onSuccess:r(async he=>{I(null),GA(a);const Ie=Doe(he);N({kind:Ie?"bootstrap":"join",payload:he}),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.access.currentBoardAccess}),await e.invalidateQueries({queryKey:P.companies.all}),z?.companyId&&Qzt(he,J)&&(n(z.companyId,{source:"manual"}),s("/",{replace:!0}))},"onSuccess"),onError:r(he=>{I(he instanceof Error?he.message:"Failed to accept invite")},"onError")});(0,m.useEffect)(()=>{!Q||R||ne.isPending||(E(!0),I(null),ne.mutate())},[ne,R,Q]);const ae=ye({mutationFn:r(async()=>{if(i==="sign_in"){await Pa.signInEmail({email:d.trim(),password:h});return}await Pa.signUpEmail({name:l.trim(),email:d.trim(),password:h})},"mutationFn"),onSuccess:r(async()=>{A(null),Aoe(a),await e.invalidateQueries({queryKey:P.auth.session}),await e.invalidateQueries({queryKey:P.health}),await e.invalidateQueries({queryKey:P.access.currentBoardAccess});const{companies:he}=await I_e(e);if(z?.companyId&&he.some(Ie=>Ie.id===z.companyId)){GA(a),n(z.companyId,{source:"manual"}),s("/",{replace:!0});return}if(!(!z||z.inviteType!=="bootstrap_ceo"))try{Doe(await ne.mutateAsync())&&s("/",{replace:!0})}catch{return}},"onSuccess"),onError:r(he=>{const Ie=Hzt(he,i,d);WCe(he)==="USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL"&&(o("sign_in"),p("")),A(Ie)},"onError")}),me=(0,m.useMemo)(()=>z?V?"Open organization":z.inviteType==="bootstrap_ceo"?"Accept invite":J?"Submit request":$.data?"Accept invite":"Continue":"Continue",[z,V,$.data,J]);if(!a)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid invite token."});if(T.isLoading||L.isLoading||$.isLoading)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading invite..."});if(D)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Checking your access..."});if(T.error||!z)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"border border-border bg-card p-6","data-testid":"invite-error",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Invite not available"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:"This invite may be expired, revoked, or already used."})]})});if(X==="approved"&&le==="human"&&V)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Opening organization..."});if(X==="pending_approval"&&!oe)return(0,t.jsx)(Loe,{companyDisplayName:H,companyLogoUrl:Z,invitedByUserName:Y});if(X&&!oe)return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"border border-border bg-card p-6","data-testid":"invite-error",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Invite not available"}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:X==="rejected"?"This join request was not approved.":"This invite has already been used."})]})});if(w?.kind==="bootstrap")return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6",children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Bootstrap complete"}),(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(F,{asChild:!0,className:"rounded-none",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})})]})});if(w?.kind==="join"){const he=w.payload,Ie=typeof he.claimSecret=="string"?he.claimSecret:null,de=typeof he.claimApiKeyPath=="string"?he.claimApiKeyPath:null,ve=Kzt(he.onboarding,["textInstructions","url"]);return!J&&he.status==="approved"?(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsxs)("div",{className:"mx-auto max-w-md border border-zinc-800 bg-zinc-950 p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(B6,{companyDisplayName:H,companyLogoUrl:Z,className:"h-12 w-12 border border-zinc-800 rounded-none"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"You joined the organization"})]}),(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(F,{asChild:!0,className:"w-full rounded-none",children:(0,t.jsx)(Qe,{to:"/",children:"Open board"})})})]})}):(0,t.jsx)(Loe,{companyDisplayName:H,companyLogoUrl:Z,invitedByUserName:Y,claimSecret:Ie,claimApiKeyPath:de,onboardingTextUrl:ve})}return(0,t.jsx)("div",{className:"min-h-screen bg-zinc-950 px-6 py-12 text-zinc-100",children:(0,t.jsx)("div",{className:"mx-auto max-w-5xl",children:(0,t.jsxs)("div",{className:"grid gap-6 lg:grid-cols-(--gtc-36)",children:[(0,t.jsxs)("section",{className:`${Poe} space-y-6`,children:[(0,t.jsxs)("div",{className:"flex items-start gap-4",children:[(0,t.jsx)(B6,{companyDisplayName:H,companyLogoUrl:Z,className:"h-16 w-16 rounded-none border border-zinc-800"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"You've been invited to join Paperclip"}),(0,t.jsx)("h1",{className:"mt-2 text-2xl font-semibold",children:z.inviteType==="bootstrap_ceo"?"Set up Paperclip":`Join ${H}`}),(0,t.jsx)("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-zinc-300",children:J?"Review the invite details, then submit the agent information below to start the join request.":te?"Create your Paperclip account first. If you already have one, switch to sign in and continue the invite with the same email.":"Your account is ready. Review the invite details, then accept it to continue."})]})]}),(0,t.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Organization"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:H})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Invited by"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:Y??"Paperclip board"})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Requested access"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:J?"Agent join request":se??"Organization access"})]}),(0,t.jsxs)("div",{className:"border border-zinc-800 p-3",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-zinc-500",children:"Invite expires"}),(0,t.jsx)("div",{className:"mt-1 text-sm text-zinc-100",children:cu(z.expiresAt)})]})]}),ie?(0,t.jsxs)("div",{className:"border border-amber-500/40 bg-amber-500/10 p-4",children:[(0,t.jsx)("div",{className:"text-xs uppercase tracking-(--tracking-caps) text-amber-200/80",children:"Message from inviter"}),(0,t.jsx)("p",{className:"mt-2 text-sm leading-6 text-amber-50",children:ie})]}):null,$.data?(0,t.jsxs)("div",{className:"border border-emerald-500/40 bg-emerald-500/10 p-4 text-sm text-emerald-50",children:["Signed in as ",(0,t.jsx)("span",{className:"font-medium",children:pe}),"."]}):null]}),(0,t.jsx)("section",{className:`${Poe} h-fit`,children:J?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:"Submit agent details"}),(0,t.jsxs)("p",{className:"mt-1 text-sm text-zinc-400",children:["This invite will create an approval request for a new agent in ",H,"."]})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Agent name"}),(0,t.jsx)("input",{className:$y,value:x,onChange:r(he=>g(he.target.value),"onChange")})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Adapter type"}),(0,t.jsx)("select",{className:$y,value:v,onChange:r(he=>y(he.target.value),"onChange"),children:Uzt.map(he=>(0,t.jsxs)("option",{value:he,disabled:!Eoe.has(he),children:[sf(he),Eoe.has(he)?"":" (Coming soon)"]},he))})]}),(0,t.jsxs)("label",{className:"block text-sm",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Capabilities"}),(0,t.jsx)("textarea",{className:$y,rows:4,value:j,onChange:r(he=>S(he.target.value),"onChange")})]}),_?(0,t.jsx)("p",{className:"text-xs text-red-400",children:_}):null,(0,t.jsx)(F,{className:"w-full rounded-none",disabled:ne.isPending||x.trim().length===0,onClick:r(()=>ne.mutate(),"onClick"),children:ne.isPending?"Working...":me})]}):te?(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:i==="sign_up"?"Create your account":"Sign in to continue"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:i==="sign_up"?`Start with a Paperclip account. After that, you'll come right back here to accept the invite for ${H}.`:"Use the Paperclip account that already matches this invite. If you do not have one yet, switch back to create account."})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("button",{type:"button",className:`${Moe} ${i==="sign_up"?"border-zinc-100 bg-zinc-100 text-zinc-950":"border-zinc-800 text-zinc-300 hover:border-zinc-600"}`,onClick:r(()=>{A(null),o("sign_up")},"onClick"),children:"Create account"}),(0,t.jsx)("button",{type:"button",className:`${Moe} ${i==="sign_in"?"border-zinc-100 bg-zinc-100 text-zinc-950":"border-zinc-800 text-zinc-300 hover:border-zinc-600"}`,onClick:r(()=>{A(null),o("sign_in")},"onClick"),children:"I already have an account"})]}),(0,t.jsxs)("form",{className:"space-y-4",method:"post",action:i==="sign_up"?"/api/auth/sign-up/email":"/api/auth/sign-in/email",onSubmit:r(he=>{if(he.preventDefault(),!ae.isPending){if(!re){A({tone:"error",message:"Please fill in all required fields."});return}ae.mutate()}},"onSubmit"),"data-testid":"invite-inline-auth",children:[i==="sign_up"?(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-name",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Name"}),(0,t.jsx)("input",{id:"invite-name",name:"name",className:$y,value:l,onChange:r(he=>{c(he.target.value),A(null)},"onChange"),autoComplete:"name",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0,autoFocus:!0})]}):null,(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-email",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Email"}),(0,t.jsx)("input",{id:"invite-email",name:"email",type:"email",className:$y,value:d,onChange:r(he=>{u(he.target.value),A(null)},"onChange"),autoComplete:"username",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0,autoFocus:i==="sign_in"})]}),(0,t.jsxs)("label",{className:"block text-sm",htmlFor:"invite-password",children:[(0,t.jsx)("span",{className:"mb-1 block text-zinc-400",children:"Password"}),(0,t.jsx)("input",{id:"invite-password",name:"password",type:"password",className:$y,value:h,onChange:r(he=>{p(he.target.value),A(null)},"onChange"),autoComplete:i==="sign_in"?"current-password":"new-password",required:!0,"aria-required":"true","aria-invalid":C?.tone==="error"?!0:void 0,"aria-describedby":C?O:void 0})]}),C?(0,t.jsx)("p",{id:O,role:"alert",className:`text-xs ${C.tone==="info"?"text-amber-300":"text-red-400"}`,children:C.message}):null,(0,t.jsx)(F,{type:"submit",className:"w-full rounded-none",disabled:ae.isPending,"aria-disabled":!re||ae.isPending,children:ae.isPending?"Working...":i==="sign_in"?"Sign in and continue":"Create account and continue"})]}),(0,t.jsx)("p",{className:"text-xs leading-5 text-zinc-500",children:i==="sign_up"?"Already signed up before? Use the existing-account option instead so the invite lands on the right Paperclip user.":"No account yet? Switch back to create account so you can accept the invite with a new login."})]}):(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:V?"Already in this organization":Q?"Completing organization access":z.inviteType==="bootstrap_ceo"?"Accept bootstrap invite":"Accept organization invite"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-zinc-400",children:Q?`Granting your access to ${H}.`:V?`This account already belongs to ${H}.`:`This will ${z.inviteType==="bootstrap_ceo"?"finish setting up Paperclip":`grant or complete your access to ${H}`}.`})]}),_?(0,t.jsx)("p",{className:"text-xs text-red-400",children:_}):null,Q?(0,t.jsx)("div",{className:"text-sm text-zinc-400",children:ne.isPending?"Submitting request...":"Finishing sign-in..."}):(0,t.jsx)(F,{className:"w-full rounded-none",disabled:ne.isPending,onClick:r(()=>{if(V&&z.companyId){GA(a),n(z.companyId,{source:"manual"}),s("/",{replace:!0});return}ne.mutate()},"onClick"),children:ne.isPending?"Working...":me})]})})]})})})}r(Gzt,"InviteLandingPage");function Yzt(){const{selectedCompany:e,selectedCompanyId:s}=fs(),{setBreadcrumbs:n}=$n(),{pushToast:a}=Mi(),i=Ht(),[o,l]=(0,m.useState)("pending_approval"),[c,d]=(0,m.useState)("all");(0,m.useEffect)(()=>{n([{label:e?.name??"Organization",href:"/dashboard"},{label:"Inbox",href:"/inbox"},{label:"Join Requests"}])},[e?.name,n]);const u=ee({queryKey:P.access.joinRequests(s??"",`${o}:${c}`),queryFn:r(()=>fr.listJoinRequests(s,o,c==="all"?void 0:c),"queryFn"),enabled:!!s}),h=ye({mutationFn:r(x=>fr.approveJoinRequest(s,x),"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.joinRequests(s,`${o}:${c}`)}),await i.invalidateQueries({queryKey:P.access.companyMembers(s)}),await i.invalidateQueries({queryKey:P.access.companyUserDirectory(s)}),a({title:"Join request approved",tone:"success"})},"onSuccess")}),p=ye({mutationFn:r(x=>fr.rejectJoinRequest(s,x),"mutationFn"),onSuccess:r(async()=>{await i.invalidateQueries({queryKey:P.access.joinRequests(s,`${o}:${c}`)}),a({title:"Join request rejected",tone:"success"})},"onSuccess")});if(!s)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Select an organization to review join requests."});if(u.isLoading)return(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading join requests…"});if(u.error){const x=u.error instanceof Nn&&u.error.status===403?"You do not have permission to review join requests for this organization.":u.error instanceof Error?u.error.message:"Failed to load join requests.";return(0,t.jsx)("div",{className:"text-sm text-destructive",children:x})}return(0,t.jsxs)("div",{className:"max-w-6xl space-y-6",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(YEe,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Join Request Queue"})]}),(0,t.jsx)("p",{className:"max-w-3xl text-sm text-muted-foreground",children:"Review human and agent join requests outside the mixed inbox feed. This queue uses the same approval mutations as the inline inbox cards."})]}),(0,t.jsxs)(Gs,{className:"flex-row flex-wrap gap-3 p-4",children:[(0,t.jsxs)("label",{className:"space-y-2 text-sm",children:[(0,t.jsx)("span",{className:"font-medium",children:"Status"}),(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:o,onChange:r(x=>l(x.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"pending_approval",children:"Pending approval"}),(0,t.jsx)("option",{value:"approved",children:"Approved"}),(0,t.jsx)("option",{value:"rejected",children:"Rejected"})]})]}),(0,t.jsxs)("label",{className:"space-y-2 text-sm",children:[(0,t.jsx)("span",{className:"font-medium",children:"Request type"}),(0,t.jsxs)("select",{className:"rounded-md border border-border bg-background px-3 py-2",value:c,onChange:r(x=>d(x.target.value),"onChange"),children:[(0,t.jsx)("option",{value:"all",children:"All"}),(0,t.jsx)("option",{value:"human",children:"Human"}),(0,t.jsx)("option",{value:"agent",children:"Agent"})]})]})]}),(0,t.jsx)("div",{className:"space-y-4",children:(u.data??[]).length===0?(0,t.jsx)("div",{className:"rounded-xl border border-dashed border-border px-4 py-8 text-sm text-muted-foreground",children:"No join requests match the current filters."}):u.data.map(x=>(0,t.jsxs)(Gs,{className:"block p-4",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(dt,{variant:x.status==="pending_approval"?"secondary":x.status==="approved"?"outline":"destructive",children:x.status.replace("_"," ")}),(0,t.jsx)(dt,{variant:"outline",children:x.requestType}),x.adapterType?(0,t.jsx)(dt,{variant:"outline",children:x.adapterType}):null]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-base font-medium",children:x.requestType==="human"?x.requesterUser?.name||x.requestEmailSnapshot||x.requestingUserId||"Unknown human requester":x.agentName||"Unknown agent requester"}),(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:x.requestType==="human"?x.requesterUser?.email||x.requestEmailSnapshot||x.requestingUserId:x.capabilities||x.requestIp})]})]}),x.status==="pending_approval"?(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(F,{variant:"outline",onClick:r(()=>p.mutate(x.id),"onClick"),disabled:p.isPending,children:"Reject"}),(0,t.jsx)(F,{onClick:r(()=>h.mutate(x.id),"onClick"),disabled:h.isPending,children:"Approve"})]}):null]}),(0,t.jsxs)("div",{className:"mt-4 grid gap-3 text-sm text-muted-foreground md:grid-cols-2",children:[(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-background px-3 py-2",children:[(0,t.jsx)("div",{className:"text-xs font-medium uppercase tracking-wide",children:"Invite context"}),(0,t.jsx)("div",{className:"mt-2",children:x.invite?`${x.invite.allowedJoinTypes} join invite${x.invite.humanRole?` • default role ${x.invite.humanRole}`:""}`:"Invite metadata unavailable"}),x.invite?.inviteMessage?(0,t.jsx)("div",{className:"mt-2 text-foreground",children:x.invite.inviteMessage}):null]}),(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-background px-3 py-2",children:[(0,t.jsx)("div",{className:"text-xs font-medium uppercase tracking-wide",children:"Request details"}),(0,t.jsxs)("div",{className:"mt-2",children:["Submitted ",new Date(x.createdAt).toLocaleString()]}),(0,t.jsxs)("div",{children:["Source IP ",x.requestIp]}),x.requestType==="agent"&&x.capabilities?(0,t.jsx)("div",{children:x.capabilities}):null]})]})]},x.id))})]})}r(Yzt,"JoinRequestQueue");var Jzt=(0,m.lazy)(()=>gc(()=>import("./CompanyExport-D-L3aIBA.js").then(e=>({default:e.CompanyExport})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]))),Xzt=(0,m.lazy)(()=>gc(()=>import("./Agents.production-C9UfcX_l.js").then(e=>({default:e.Agents})),__vite__mapDeps([26,5,7,9,8,10,11,12,13,27,28,29,15,30,31,32,33,24,25]))),Zzt=(0,m.lazy)(()=>gc(()=>import("./Routines.production-Cx0jBxDn.js").then(e=>({default:e.Routines})),__vite__mapDeps([34,5,7,8,9,10,11,12,13,35,14,15,36,37,29,27,38,39,40,21,41,42,16,17,18,19,43,44,30,45,46,23,31,47,33,48,49,50,51,24,25,28]))),$oe=(0,m.lazy)(()=>gc(()=>import("./RoutineDetail.production-BbeeGNoZ.js").then(e=>({default:e.RoutineDetail})),__vite__mapDeps([52,5,7,8,9,10,11,12,13,35,14,15,36,37,29,27,38,39,40,21,41,42,16,17,18,19,43,44,30,45,46,23,31,47,33,48,49,50,51,24,25,53]))),eUt=(0,m.lazy)(()=>gc(()=>import("./CompanySkills.production-i-yIgrn5.js").then(e=>({default:e.CompanySkills})),__vite__mapDeps([54,5,7,8,9,10,11,12,13,14,15,36,37,29,27,38,39,40,21,41,28,16,17,18,19,55,53,31,44,22,20,56,47,48,50,24,25]))),tUt=(0,m.lazy)(()=>gc(()=>import("./CompanyActivity.production-BrGxzr9C.js").then(e=>({default:e.CompanyActivity})),__vite__mapDeps([57,5,7,8,9,10,11,12,13,27,28,29,43,37,21,44,48,49,51]))),sUt=(0,m.lazy)(()=>gc(()=>import("./Costs.production-Bds9QYE3.js").then(e=>({default:e.Costs})),__vite__mapDeps([58,5,7,28,29,13,12,44,41,50,27,51,24,25]))),nUt=(0,m.lazy)(()=>gc(()=>import("./OrgChart.production-Cgr0byQj.js").then(e=>({default:e.OrgChart})),__vite__mapDeps([59,5,7,8,9,10,11,12,13,27,45,46,51,24,25])));function pg({children:e}){return(0,t.jsx)(m.Suspense,{fallback:(0,t.jsx)(Qm,{}),children:e})}r(pg,"ProductionSurface");function rUt(e){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{index:!0,element:(0,t.jsx)(vn,{to:"dashboard",replace:!0})}),(0,t.jsx)(lt,{path:"dashboard",element:(0,t.jsx)(Bht,{})}),(0,t.jsx)(lt,{path:"dashboard/live",element:(0,t.jsx)(qht,{})}),(0,t.jsx)(lt,{path:"timeline",element:e?(0,t.jsx)(hp,{to:"/activity/timeline"}):(0,t.jsx)(Pye,{})}),(0,t.jsx)(lt,{path:"onboarding",element:(0,t.jsx)(GCe,{})}),(0,t.jsx)(lt,{path:"companies",element:(0,t.jsx)(_pt,{})}),(0,t.jsx)(lt,{path:"company/settings",element:(0,t.jsx)(LTt,{})}),(0,t.jsx)(lt,{path:"company/settings/environments",element:(0,t.jsx)(vn,{to:"/company/settings/instance/environments",replace:!0})}),(0,t.jsx)(lt,{path:"company/settings/cloud-upstream",element:(0,t.jsx)(vn,{to:"/company/export",replace:!0})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.members"}),children:[(0,t.jsx)(lt,{path:"company/settings/members",element:(0,t.jsx)(rMt,{})}),(0,t.jsx)(lt,{path:"company/settings/access",element:(0,t.jsx)(aMt,{})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.invites"}),children:(0,t.jsx)(lt,{path:"company/settings/invites",element:(0,t.jsx)(vn,{to:"/company/settings/members?tab=invites",replace:!0})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.export"}),children:(0,t.jsx)(lt,{path:"company/export/*",element:(0,t.jsx)(m.Suspense,{fallback:(0,t.jsx)(Qm,{}),children:(0,t.jsx)(Jzt,{})})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Eet,{}),children:(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.import"}),children:(0,t.jsx)(lt,{path:"company/import",element:(0,t.jsx)(h6t,{})})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"company.secrets"}),children:(0,t.jsx)(lt,{path:"company/settings/secrets",element:(0,t.jsx)(lqt,{})})}),(0,t.jsx)(lt,{path:"company/settings/tools",element:(0,t.jsx)(Foe,{})}),(0,t.jsx)(lt,{path:"company/settings/tools/:tab",element:(0,t.jsx)(Foe,{})}),(0,t.jsx)(lt,{path:"tools",element:(0,t.jsx)(Boe,{})}),(0,t.jsx)(lt,{path:"tools/:tab",element:(0,t.jsx)(Boe,{})}),(0,t.jsx)(lt,{path:"apps",element:(0,t.jsx)(z4t,{})}),(0,t.jsx)(lt,{path:"apps/browse",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/connections",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/byo",element:(0,t.jsx)(wSe,{byoOnly:!0})}),(0,t.jsx)(lt,{path:"apps/vercel-connect",element:(0,t.jsx)(Ooe,{credentialSource:"vercel_connect"})}),(0,t.jsx)(lt,{path:"apps/connect",element:(0,t.jsx)(Ooe,{})}),(0,t.jsx)(lt,{path:"apps/chat/connect",element:(0,t.jsx)(f$,{children:(0,t.jsx)(fDt,{})})}),(0,t.jsx)(lt,{path:"apps/chat/:endpointId",element:(0,t.jsx)(f$,{children:(0,t.jsx)(vn,{to:"settings",replace:!0})})}),(0,t.jsx)(lt,{path:"apps/chat/:endpointId/:tab",element:(0,t.jsx)(f$,{children:(0,t.jsx)(PDt,{})})}),(0,t.jsx)(lt,{path:"apps/connect/:appKey",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/connect/:appKey/:stage",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/review",element:(0,t.jsx)(BDt,{})}),(0,t.jsx)(lt,{path:"apps/attention",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/gateways",element:(0,t.jsx)(Qae,{})}),(0,t.jsx)(lt,{path:"apps/gateways/:gatewayId",element:(0,t.jsx)(vn,{to:"overview",replace:!0})}),(0,t.jsx)(lt,{path:"apps/gateways/:gatewayId/:tab",element:(0,t.jsx)(MLt,{})}),(0,t.jsx)(lt,{path:"apps/advanced",element:(0,t.jsx)(Rae,{})}),(0,t.jsx)(lt,{path:"apps/advanced/gateways",element:(0,t.jsx)(Qae,{})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/new",element:(0,t.jsx)(Dae,{mode:"new"})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/:profileId/edit",element:(0,t.jsx)(Dae,{mode:"edit"})}),(0,t.jsx)(lt,{path:"apps/advanced/profiles/:profileId",element:(0,t.jsx)(S4t,{})}),(0,t.jsx)(lt,{path:"apps/advanced/audit",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/advanced/run-your-own",element:(0,t.jsx)(vn,{to:"/apps",replace:!0})}),(0,t.jsx)(lt,{path:"apps/advanced/:tab",element:(0,t.jsx)(Rae,{})}),(0,t.jsx)(lt,{path:"apps/app/:applicationId",element:(0,t.jsx)(Vae,{})}),(0,t.jsx)(lt,{path:"apps/app/:applicationId/:tab",element:(0,t.jsx)(Vae,{})}),(0,t.jsx)(lt,{path:"apps/:connectionId",element:(0,t.jsx)(vn,{to:"permissions",replace:!0})}),(0,t.jsx)(lt,{path:"apps/:connectionId/:tab",element:(0,t.jsx)(QDt,{})}),(0,t.jsx)(lt,{path:"company/settings/instance",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.profile"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/profile",element:(0,t.jsx)(hzt,{})})}),(0,t.jsx)(lt,{path:"company/settings/instance/general",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsx)(lt,{path:"company/settings/instance/heartbeats",element:(0,t.jsx)(vn,{to:"/company/settings",replace:!0})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.environments"}),children:[(0,t.jsx)(lt,{path:"company/settings/instance/environments",element:(0,t.jsx)(r$,{})}),(0,t.jsx)(lt,{path:"company/settings/instance/environments/new",element:(0,t.jsx)(r$,{mode:"create"})}),(0,t.jsx)(lt,{path:"company/settings/instance/environments/:environmentId/edit",element:(0,t.jsx)(r$,{mode:"edit"})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.access"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/access",element:(0,t.jsx)(czt,{})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.experimental"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/experimental",element:(0,t.jsx)(lzt,{})})}),(0,t.jsxs)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.plugins"}),children:[(0,t.jsx)(lt,{path:"company/settings/instance/plugins",element:(0,t.jsx)(fzt,{})}),(0,t.jsx)(lt,{path:"company/settings/instance/plugins/:pluginId",element:(0,t.jsx)(xzt,{})})]}),(0,t.jsx)(lt,{element:(0,t.jsx)(ch,{pageKey:"instance.adapters"}),children:(0,t.jsx)(lt,{path:"company/settings/instance/adapters",element:(0,t.jsx)(Soe,{})})}),(0,t.jsx)(lt,{path:"company/settings/:settingsRoutePath/*",element:(0,t.jsx)(JPt,{})}),(0,t.jsx)(lt,{path:"skills/studio",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/studio/new",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/studio/:skillId",element:(0,t.jsx)(A$,{})}),(0,t.jsx)(lt,{path:"skills/:skillId/studio",element:(0,t.jsx)(HCe,{})}),(0,t.jsx)(lt,{path:"skills/*",element:e?(0,t.jsx)(G$t,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(eUt,{})})}),(0,t.jsx)(lt,{path:"settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"plugins/:pluginId",element:(0,t.jsx)(Coe,{})}),(0,t.jsx)(lt,{path:"org",element:e?(0,t.jsx)(vn,{to:"/agents/all",replace:!0}):(0,t.jsx)(pg,{children:(0,t.jsx)(nUt,{})})}),(0,t.jsx)(lt,{path:"agents",element:(0,t.jsx)(vn,{to:"/agents/all",replace:!0})}),b8.map(s=>(0,t.jsx)(lt,{path:`agents/${s}`,element:e?(0,t.jsx)(Xpt,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(Xzt,{})})},s)),(0,t.jsx)(lt,{path:"agents/new",element:(0,t.jsx)(Mzt,{})}),(0,t.jsx)(lt,{path:"agents/:agentId",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/:tab",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/runs/:runId",element:(0,t.jsx)(VD,{})}),(0,t.jsx)(lt,{path:"projects",element:(0,t.jsx)(d0t,{})}),(0,t.jsx)(lt,{path:"projects/:projectId",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/overview",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues/:filter",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsx)(lt,{path:"projects/:projectId/workspaces/:workspaceId",element:(0,t.jsx)(nvt,{})})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/configuration",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/budget",element:(0,t.jsx)(F0,{})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsx)(lt,{path:"workspaces",element:(0,t.jsx)(ivt,{})})}),(0,t.jsx)(lt,{path:"issues",element:(0,t.jsx)(pvt,{})}),(0,t.jsx)(lt,{path:"tasks",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"search",element:(0,t.jsx)(Bvt,{})}),(0,t.jsx)(lt,{path:"issues/all",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/active",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/backlog",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/done",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"issues/recent",element:(0,t.jsx)(vn,{to:"/issues",replace:!0})}),(0,t.jsx)(lt,{path:"chats/:agentRef",element:(0,t.jsx)(akt,{})}),(0,t.jsx)(lt,{path:"issues/:issueId",element:(0,t.jsx)(nkt,{})}),null,(0,t.jsx)(lt,{path:"routines",element:e?(0,t.jsx)(Okt,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(Zzt,{})})}),(0,t.jsx)(lt,{path:"cases",element:(0,t.jsx)(XJ,{children:(0,t.jsx)(Xet,{})})}),(0,t.jsx)(lt,{path:"cases/:caseIdentifier",element:(0,t.jsx)(XJ,{children:(0,t.jsx)(jnt,{})})}),(0,t.jsx)(lt,{path:"status",element:(0,t.jsx)(ZJ,{children:(0,t.jsx)(one,{})})}),(0,t.jsx)(lt,{path:"status/:cardId",element:(0,t.jsx)(ZJ,{children:(0,t.jsx)(one,{})})}),(0,t.jsx)(lt,{path:"status-cards",element:(0,t.jsx)(qoe,{})}),(0,t.jsx)(lt,{path:"status-cards/:cardId",element:(0,t.jsx)(qoe,{})}),(0,t.jsx)(lt,{path:"review-queue",element:(0,t.jsx)(ng,{children:(0,t.jsx)(s1t,{})})}),(0,t.jsx)(lt,{path:"learnings",element:(0,t.jsx)(ng,{children:(0,t.jsx)(r1t,{})})}),(0,t.jsx)(lt,{path:"pipelines",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/add",element:(0,t.jsx)(ng,{children:(0,t.jsx)(SL,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/settings",element:(0,t.jsx)(ng,{children:(0,t.jsx)(J1t,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/items/:caseId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(wCt,{})})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/cases/:caseId",element:(0,t.jsx)(ng,{children:(0,t.jsx)(vCt,{})})}),(0,t.jsx)(lt,{path:"routines/:routineId",element:e?(0,t.jsx)(jne,{}):(0,t.jsx)(pg,{children:(0,t.jsx)($oe,{})})}),(0,t.jsx)(lt,{path:"routines/:routineId/:section",element:e?(0,t.jsx)(jne,{}):(0,t.jsx)(pg,{children:(0,t.jsx)($oe,{})})}),(0,t.jsx)(lt,{element:(0,t.jsx)(Y4,{}),children:(0,t.jsxs)(lt,{element:(0,t.jsx)(Met,{}),children:[(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/services",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/configuration",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/runtime-logs",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/issues",element:(0,t.jsx)(Ty,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/routines",element:(0,t.jsx)(Ty,{})})]})}),(0,t.jsx)(lt,{path:"goals",element:(0,t.jsx)(fAt,{})}),(0,t.jsx)(lt,{path:"goals/:goalId",element:(0,t.jsx)(AAt,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(Sne,{})}),(0,t.jsx)(lt,{path:"approvals",element:(0,t.jsx)(vn,{to:"/approvals/pending",replace:!0})}),(0,t.jsx)(lt,{path:"approvals/pending",element:(0,t.jsx)(_ne,{})}),(0,t.jsx)(lt,{path:"approvals/all",element:(0,t.jsx)(_ne,{})}),(0,t.jsx)(lt,{path:"approvals/:approvalId",element:(0,t.jsx)(RAt,{})}),(0,t.jsx)(lt,{path:"activity",element:e?(0,t.jsx)(g2t,{}):(0,t.jsx)(pg,{children:(0,t.jsx)(tUt,{})})}),e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"activity/runs",element:(0,t.jsx)(zk,{section:"runs"})}),(0,t.jsx)(lt,{path:"activity/costs",element:(0,t.jsx)(zk,{section:"costs"})}),(0,t.jsx)(lt,{path:"activity/budgets",element:(0,t.jsx)(zk,{section:"budgets"})}),(0,t.jsx)(lt,{path:"activity/timeline",element:(0,t.jsx)(zk,{section:"timeline"})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(hp,{to:"/activity",forceAgentMode:!0})}),(0,t.jsx)(lt,{path:"audit/activity",element:(0,t.jsx)(hp,{to:"/activity"})}),(0,t.jsx)(lt,{path:"audit/runs",element:(0,t.jsx)(hp,{to:"/activity/runs"})}),(0,t.jsx)(lt,{path:"audit/costs",element:(0,t.jsx)(hp,{to:"/activity/costs"})}),(0,t.jsx)(lt,{path:"audit/budgets",element:(0,t.jsx)(hp,{to:"/activity/budgets"})}),(0,t.jsx)(lt,{path:"audit/timeline",element:(0,t.jsx)(hp,{to:"/activity/timeline"})}),(0,t.jsx)(lt,{path:"runs",element:(0,t.jsx)(hp,{to:"/activity/runs"})}),(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(hp,{to:"/activity/costs"})}),(0,t.jsx)(lt,{path:"budgets",element:(0,t.jsx)(hp,{to:"/activity/budgets"})})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(pg,{children:(0,t.jsx)(sUt,{})})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(vn,{to:"/activity?mode=agents",replace:!0})})]}),(0,t.jsxs)(lt,{element:(0,t.jsx)(vJe,{}),children:[(0,t.jsx)(lt,{path:"board-chat",element:(0,t.jsx)(kTt,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(Sne,{})})]}),null,(0,t.jsx)(lt,{path:"decisions",element:(0,t.jsx)(GRt,{})}),(0,t.jsx)(lt,{path:"decisions/queues/:key",element:(0,t.jsx)(ZRt,{})}),(0,t.jsx)(lt,{path:"inbox",element:(0,t.jsx)(aUt,{})}),(0,t.jsx)(lt,{path:"inbox/mine",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/recent",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/unread",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/blocked",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/all",element:(0,t.jsx)(uk,{})}),(0,t.jsx)(lt,{path:"inbox/requests",element:(0,t.jsx)(Yzt,{})}),(0,t.jsx)(lt,{path:"inbox/new",element:(0,t.jsx)(vn,{to:"/inbox/mine",replace:!0})}),(0,t.jsx)(lt,{path:"u/:userSlug",element:(0,t.jsx)(UIt,{})}),(0,t.jsx)(lt,{path:"design-guide",element:(0,t.jsx)(azt,{})}),(0,t.jsx)(lt,{path:"instance/settings/adapters",element:(0,t.jsx)(Soe,{})}),(0,t.jsx)(lt,{path:":pluginRoutePath/*",element:(0,t.jsx)(Coe,{})}),(0,t.jsx)(lt,{path:"*",element:(0,t.jsx)(uu,{scope:"board"})})]})}r(rUt,"boardRoutes");function Ooe({credentialSource:e="paperclip_vault"}={}){const s=Zr(),n=new URLSearchParams(s.search),{enabled:a}=Tx();return VQe(n,{chatConnectorsEnabled:a})?(0,t.jsx)(wSe,{credentialSource:e}):(0,t.jsx)(vn,{to:"/apps",replace:!0})}r(Ooe,"AppsConnectEntryRoute");function aUt(){return(0,t.jsx)(vn,{to:`/inbox/${kAe()}`,replace:!0})}r(aUt,"InboxRootRedirect");function HCe(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs(),{companyPrefix:i,skillId:o}=ja();if(a)return null;const l=(i?s.find(c=>c.issuePrefix.toUpperCase()===i.toUpperCase()):null)??n??s[0]??null;return!l||!o?(0,t.jsx)(vn,{to:"/skills/studio",replace:!0}):(0,t.jsx)(vn,{to:`/${l.issuePrefix}/skills/studio/${encodeURIComponent(o)}${e.search}${e.hash}`,replace:!0})}r(HCe,"LegacySkillStudioRedirect");function hb(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs(),{companyPrefix:i}=ja(),{hidden:o}=Ym();if(a)return(0,t.jsx)(Qm,{});const l=(i?s.find(d=>d.issuePrefix.toUpperCase()===i.toUpperCase()):null)??n??s[0]??null;if(!l)return oK({pathname:e.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{});const c=PDe(iue(`${e.pathname}${e.search}${e.hash}`),o);return(0,t.jsx)(vn,{to:`/${l.issuePrefix}${c}`,replace:!0})}r(hb,"LegacySettingsRedirect");function Foe(){const{tab:e}=ja();return(0,t.jsx)(vn,{to:QCe(e),replace:!0})}r(Foe,"LegacyToolsSettingsRedirect");function Boe(){const{tab:e}=ja();return(0,t.jsx)(vn,{to:QCe(e),replace:!0})}r(Boe,"LegacyToolsRedirect");function QCe(e){return e?e==="applications"||e==="connections"||e==="overview"||e==="examples"||e==="runtime"||e==="audit"?"/apps":e==="policies"?"/apps/advanced/profiles":`/apps/advanced/${e}`:"/apps/advanced/profiles"}r(QCe,"legacyToolsRedirectTarget");function GCe(){const{companies:e}=fs(),{openOnboarding:s}=Lo(),{t:n}=Mde(),a=Vc(),i=C5(a?.cloudBaseUrl??null),{onboardingOpen:o,onboardingRouteDismissed:l}=c5(),{companyPrefix:c}=ja(),d=c?e.find(p=>p.issuePrefix.toUpperCase()===c.toUpperCase())??null:null;if(GGe({onboardingOpen:o,routeDismissed:l}))return null;const u=d?`Add another agent to ${d.name}`:e.length>0?"Create another organization":"Create your first organization",h=d?"Run onboarding again to add an agent and a starter task for this organization.":e.length>0?"Run onboarding again to create another organization and seed its first agent.":"Get started by creating an organization and your first agent.";return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-card p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:u}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:h}),(0,t.jsx)("div",{className:"mt-4",children:!d&&a&&!i?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:n("app.cloudCreateUnavailable",{defaultValue:"Organizations are created in Paperclip Cloud. This instance can't reach it right now — try again from your Cloud portfolio."})}):(0,t.jsx)(F,{onClick:r(()=>d?s({initialStep:RT(),companyId:d.id}):a&&i?jc(i):s(),"onClick"),children:d?"Add Agent":"Start Onboarding"})})]})})}r(GCe,"OnboardingRoutePage");function iUt(){const{companies:e,selectedCompany:s,loading:n}=fs(),a=Zr();if(n)return(0,t.jsx)(Qm,{});const i=s??e[0]??null;return i?(0,t.jsx)(vn,{to:`/${i.issuePrefix}/dashboard`,replace:!0}):oK({pathname:a.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{})}r(iUt,"CompanyRootRedirect");function qoe(){const{cardId:e}=ja(),s=PIe(),n=s?`/${s}`:"";return(0,t.jsx)(vn,{to:`${n}/status${e?`/${e}`:""}`,replace:!0})}r(qoe,"StatusCardsLegacyRedirect");function hp({to:e,forceAgentMode:s=!1}){const n=Zr(),a=new URLSearchParams(n.search);s&&a.set("mode","agents");const i=a.toString();return(0,t.jsx)(vn,{to:`${e}${i?`?${i}`:""}${n.hash}`,replace:!0})}r(hp,"AuditCompatibilityRedirect");function ba(){const e=Zr(),{companies:s,selectedCompany:n,loading:a}=fs();if(a)return(0,t.jsx)(Qm,{});const i=n??s[0]??null;return i?(0,t.jsx)(vn,{to:`/${i.issuePrefix}${e.pathname}${e.search}${e.hash}`,replace:!0}):oK({pathname:e.pathname,hasCompanies:!1})?(0,t.jsx)(vn,{to:"/onboarding",replace:!0}):(0,t.jsx)(V7,{})}r(ba,"UnprefixedBoardRedirect");function V7(){const{openOnboarding:e}=Lo(),{t:s}=Mde(),n=Vc(),a=C5(n?.cloudBaseUrl??null);return(0,t.jsx)("div",{className:"mx-auto max-w-xl py-10",children:(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-card p-6",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold",children:s("app.noCompanies.title",{defaultValue:"Create your first organization"})}),(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground",children:s("app.noCompanies.description",{defaultValue:"Get started by creating an organization."})}),(0,t.jsx)("div",{className:"mt-4",children:n&&!a?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:s("app.cloudCreateUnavailable",{defaultValue:"Organizations are created in Paperclip Cloud. This instance can't reach it right now — try again from your Cloud portfolio."})}):(0,t.jsx)(F,{onClick:r(()=>n&&a?jc(a):e(),"onClick"),children:s("app.noCompanies.newCompany",{defaultValue:"New Organization"})})})]})})}r(V7,"NoCompaniesStartPage");function oUt(){const{enabled:e,loaded:s}=wc();return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(LIe,{children:[(0,t.jsx)(lt,{path:"oauth-handoff",element:(0,t.jsx)(mLt,{})}),(0,t.jsx)(lt,{path:"auth",element:(0,t.jsx)(Bzt,{})}),(0,t.jsx)(lt,{path:"board-claim/:token",element:(0,t.jsx)(qzt,{})}),(0,t.jsx)(lt,{path:"cli-auth/:id",element:(0,t.jsx)(zzt,{})}),(0,t.jsx)(lt,{path:"invite/:token",element:(0,t.jsx)(Gzt,{})}),(0,t.jsx)(lt,{element:s?(0,t.jsx)(VX,{allowMembershipRequest:!0}):(0,t.jsx)(Qm,{}),children:(0,t.jsx)(lt,{path:"chat-identity/confirm",element:(0,t.jsx)(ODt,{})})}),(0,t.jsx)(lt,{path:"tests/perf/long-thread",element:(0,t.jsx)(xkt,{})}),(0,t.jsx)(lt,{path:"ux-lab/bootstrap-setup",element:(0,t.jsx)(HPt,{})}),(0,t.jsx)(lt,{path:"ux-lab/responsible-user-denial",element:(0,t.jsx)(QPt,{})}),(0,t.jsx)(lt,{path:"ux-lab/cross-issue-collaboration",element:(0,t.jsx)(YPt,{})}),(0,t.jsxs)(lt,{element:s?(0,t.jsx)(VX,{}):(0,t.jsx)(Qm,{}),children:[(0,t.jsx)(lt,{index:!0,element:(0,t.jsx)(iUt,{})}),(0,t.jsx)(lt,{path:"onboarding",element:(0,t.jsx)(GCe,{})}),(0,t.jsx)(lt,{path:"instance",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"instance/settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"instance/settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"companies",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"issues",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"tasks",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"issues/:issueId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"routines",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"routines/:routineId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"review-queue",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"learnings",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"cases",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"cases/:caseIdentifier",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status/:cardId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status-cards",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"status-cards/:cardId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/add",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/settings",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/items/:caseId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"pipelines/:pipelineId/cases/:caseId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"artifacts",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"audit",element:(0,t.jsx)(ba,{})}),e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(lt,{path:"audit/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"activity",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"activity/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"runs",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"costs",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"budgets",element:(0,t.jsx)(ba,{})})]}):null,(0,t.jsx)(lt,{path:"decisions",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"u/:userSlug",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio/new",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/studio/:skillId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"skills/:skillId/studio",element:(0,t.jsx)(HCe,{})}),(0,t.jsx)(lt,{path:"skills/*",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"settings",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"settings/*",element:(0,t.jsx)(hb,{})}),(0,t.jsx)(lt,{path:"agents",element:(0,t.jsx)(ba,{})}),b8.map(n=>(0,t.jsx)(lt,{path:`agents/${n}`,element:(0,t.jsx)(ba,{})},n)),(0,t.jsx)(lt,{path:"agents/new",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/:tab",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"agents/:agentId/runs/:runId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/overview",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/issues/:filter",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/workspaces/:workspaceId",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"projects/:projectId/configuration",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"workspaces",element:(0,t.jsx)(ba,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/services",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/configuration",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/runtime-logs",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/issues",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:"execution-workspaces/:workspaceId/routines",element:(0,t.jsx)(fy,{})}),(0,t.jsx)(lt,{path:":companyPrefix",element:e?(0,t.jsx)(LYe,{}):(0,t.jsx)(xJe,{}),children:rUt(e)}),(0,t.jsx)(lt,{path:"*",element:(0,t.jsx)(uu,{scope:"global"})})]})]}),(0,t.jsx)(Ynt,{})]})}r(oUt,"App");var lUt=class extends m.Component{static{r(this,"AppErrorBoundary")}state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,s){kxe(e,{boundary:"app",componentStack:s.componentStack})}render(){const{error:e}=this.state;return e?(0,t.jsxs)("div",{className:"mx-auto flex min-h-screen max-w-2xl flex-col justify-center space-y-4 px-4 py-10",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-semibold",children:"Paperclip hit an error"}),(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Something went wrong while running the app. Reloading usually fixes this."})]}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-wrap",children:e.message}),(0,t.jsx)("div",{children:(0,t.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium shadow-sm hover:bg-accent hover:text-accent-foreground",onClick:r(()=>window.location.reload(),"onClick"),children:"Reload page"})})]}):this.props.children}};function cUt(){const{data:e}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),retry:!1}),s=e?.sentryDsn,n=e?.sentryEnvironment??void 0;return(0,m.useEffect)(()=>{if(s)return uYe(s,n),()=>{mYe()}},[s,n]),null}r(cUt,"SentryGate");function dUt(e){return{id:e.key,title:e.title,status:e.status,projectId:e.projectId??null,assigneeAgentId:e.assigneeAgentId??null,lastRun:e.lastRunAt||e.lastRunStatus?{triggeredAt:e.lastRunAt??null,status:e.lastRunStatus??null}:null}}r(dUt,"managedRoutineToRow");function uUt({routines:e,agents:s=[],projects:n=[],pluginDisplayName:a=null,emptyMessage:i="No managed routines.",runningRoutineKey:o=null,statusMutationRoutineKey:l=null,reconcilingRoutineKey:c=null,resettingRoutineKey:d=null,onRunNow:u,onToggleEnabled:h,onReconcile:p,onReset:x}){const g=new Map(s.map(y=>[y.id,y])),v=new Map(n.map(y=>[y.id,{name:y.name,color:y.color}]));return e.length===0?(0,t.jsx)("div",{className:"rounded-lg border border-border px-3 py-8 text-center text-sm text-muted-foreground",children:i}):(0,t.jsx)("div",{className:"rounded-lg border border-border",children:e.map(y=>{const j=dUt(y),S=y.href??(y.routineId?`/routines/${y.routineId}`:"/routines"),w=y.missingRefs??[],N=!!(y.routineId&&y.resourceKey&&w.length===0),_=y.managedByPluginDisplayName??a,I=!!(p||x);return(0,t.jsxs)("div",{className:"last:[&_a]:border-b-0",children:[(0,t.jsx)(Ewe,{routine:j,projectById:v,agentById:g,runningRoutineId:o,statusMutationRoutineId:l,href:S,configureLabel:"Configure",managedByLabel:_?`Managed by ${_}`:null,runNowButton:!0,hideArchiveAction:!0,disableRunNow:!N,disableToggle:!N,secondaryDetails:(0,t.jsxs)("span",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[y.resourceKey?(0,t.jsx)("span",{children:y.resourceKey}):null,y.cronExpression?(0,t.jsxs)("span",{children:["Schedule ",y.cronExpression]}):null]}),onRunNow:r(()=>u?.(y),"onRunNow"),onToggleEnabled:r(()=>h?.(y,j.status==="active"),"onToggleEnabled")}),I?(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 pb-3 text-xs text-muted-foreground last:border-b-0",onClick:r(C=>{C.preventDefault(),C.stopPropagation()},"onClick"),children:[(0,t.jsx)("span",{children:w.length?`Missing ${w.map(C=>`${C.resourceKind}:${C.resourceKey}`).join(", ")}`:"Routine defaults can be repaired."}),(0,t.jsxs)("span",{className:"flex items-center gap-2",children:[p?(0,t.jsx)(F,{size:"sm",variant:"ghost",disabled:c===y.key,onClick:r(()=>p(y),"onClick"),children:c===y.key?"Reconciling...":"Reconcile"}):null,x?(0,t.jsx)(F,{size:"sm",variant:"ghost",disabled:d===y.key,onClick:r(()=>x(y),"onClick"),children:d===y.key?"Resetting...":"Reset"}):null]})]}):null]},y.key)})})}r(uUt,"ManagedRoutinesList");function zoe(e){return new Set(e??[])}r(zoe,"toPathSet");function mUt({expandedPaths:e,checkedPaths:s,selectedFile:n=null,showCheckboxes:a=!1,onToggleDir:i,onSelectFile:o,...l}){return(0,m.createElement)(q1,{...l,selectedFile:n,expandedDirs:zoe(e),checkedFiles:s?zoe(s):void 0,showCheckboxes:a,onToggleDir:i??(()=>{}),onSelectFile:o??(()=>{})})}r(mUt,"PluginSdkFileTree");function hUt(e){const[s,n]=(0,m.useState)(null);return(0,m.useEffect)(()=>{let a=!1;return gc(()=>import("./MarkdownEditor-B3NYD32f.js").then(i=>i.n).then(i=>{a||n(()=>i.MarkdownEditor)}),__vite__mapDeps([36,5,7,9,14,10,15,37,29,27,38])),()=>{a=!0}},[]),s?(0,m.createElement)(s,e):(0,m.createElement)("textarea",{className:e.className,value:e.value,placeholder:e.placeholder,readOnly:e.readOnly,onBlur:e.onBlur,onChange:r(a=>e.onChange(a.currentTarget.value),"onChange")})}r(hUt,"PluginSdkMarkdownEditor");function pUt(e){return Object.fromEntries(Object.entries(e).filter(([,s])=>s!=null&&s!==""&&s!==!1))}r(pUt,"compactIssueFilters");function fUt({companyId:e,projectId:s=null,filters:n,viewStateKey:a="paperclip:plugin-issues-view",initialSearch:i,createIssueLabel:o,searchWithinLoadedIssues:l=!0}){const c=Ht(),d=(0,m.useMemo)(()=>pUt({...n??{},projectId:n?.projectId??s??void 0}),[n,s]),u=d.originKindPrefix??null,h=d.projectId??s??null,p=(0,m.useMemo)(()=>["plugins","sdk-ui","issues-list",e??"__no-company__",d],[e,d]),{data:x}=ee({queryKey:P.agents.list(e??"__no-company__"),queryFn:r(()=>Wt.list(e),"queryFn"),enabled:!!e}),{data:g}=ee({queryKey:P.projects.list(e??"__no-company__",{includeArchived:!0}),queryFn:r(()=>oa.list(e,{includeArchived:!0}),"queryFn"),enabled:!!e}),v=P.liveRuns(e??"__no-company__"),y=mo({companyId:e,resourceKey:"live-runs",queryKey:v,enabled:!!e,refetchInterval:!1,leaderOnly:!0}),{data:j,dataUpdatedAt:S}=ee({queryKey:v,queryFn:r(()=>Xr.liveRunsForCompany(e),"queryFn"),enabled:y.enabled,refetchInterval:y.refetchInterval});ho(y,j,S);const{data:w,isLoading:N,error:_}=ee({queryKey:p,queryFn:r(()=>Tt.list(e,d),"queryFn"),enabled:!!e}),I=(0,m.useMemo)(()=>Sx(j,w),[w,j]),C=ye({mutationFn:r(({id:A,data:R})=>Tt.update(A,R),"mutationFn"),onSuccess:r(()=>{e&&(c.invalidateQueries({queryKey:["plugins","sdk-ui","issues-list",e]}),c.invalidateQueries({queryKey:P.issues.list(e)}),h&&(c.invalidateQueries({queryKey:P.issues.listByProject(e,h)}),u&&c.invalidateQueries({queryKey:P.issues.listPluginOperationsByProject(e,h,u)})))},"onSuccess")});return e?(0,m.createElement)(hx,{issues:w??[],isLoading:N,error:_,agents:x,projects:g,liveIssueIds:I,projectId:h??void 0,viewStateKey:a,initialSearch:i,createIssueLabel:o,searchWithinLoadedIssues:l,onUpdateIssue:r((A,R)=>C.mutate({id:A,data:R}),"onUpdateIssue")}):(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},"Select an organization to view tasks.")}r(fUt,"PluginSdkIssuesList");function xUt({companyId:e,value:s,onChange:n,placeholder:a="Responsible",noneLabel:i="No responsible",searchPlaceholder:o="Search responsible...",emptyMessage:l="No responsible found.",includeUsers:c=!0,includeTerminatedAgents:d=!1,className:u,onConfirm:h}){const p=Oz(),x=e??p.companyId??null,{data:g}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn"),enabled:c}),v=g?.user?.id??g?.session?.userId??null,{data:y}=ee({queryKey:P.agents.list(x??"__no-company__"),queryFn:r(()=>Wt.list(x),"queryFn"),enabled:!!x}),{data:j}=ee({queryKey:P.access.companyUserDirectory(x??"__no-company__"),queryFn:r(()=>fr.listUserDirectory(x),"queryFn"),enabled:!!x&&c}),S=(0,m.useMemo)(()=>aAe(),[]),w=(0,m.useMemo)(()=>S.map(A=>A.startsWith("agent:")?A.slice(6):null).filter(A=>!!A),[S]),N=(0,m.useMemo)(()=>Ug((y??[]).filter(A=>d||A.status!=="terminated"),w),[y,d,w]),_=(0,m.useMemo)(()=>[...c?tce(v):[],...c?zw(j?.users,{excludeUserIds:[v]}):[],...N.map(A=>({id:Rm({assigneeAgentId:A.id}),label:A.name,searchText:`${A.name} ${A.role} ${A.title??""}`}))],[j?.users,v,c,N]),I=Pc(s),C=I.assigneeAgentId?N.find(A=>A.id===I.assigneeAgentId):null;return(0,m.createElement)($l,{value:s,options:_,recentOptionIds:S,placeholder:a,noneLabel:i,searchPlaceholder:o,emptyMessage:l,className:u,onConfirm:h,onChange:r(A=>{const R=Pc(A);R.assigneeAgentId&&YC(R.assigneeAgentId),R.assigneeUserId&&Dle(R.assigneeUserId),n(A,R)},"onChange"),renderTriggerValue:r(A=>A?C?(0,m.createElement)(K3,null,(0,m.createElement)(ew,{icon:C.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,m.createElement)("span",{className:"truncate"},A.label)):(0,m.createElement)("span",{className:"truncate"},A.label):(0,m.createElement)("span",{className:"text-muted-foreground"},a),"renderTriggerValue"),renderOption:r(A=>{if(!A.id)return(0,m.createElement)("span",{className:"truncate"},A.label);const R=Pc(A.id),E=R.assigneeAgentId?N.find(O=>O.id===R.assigneeAgentId):null;return(0,m.createElement)(K3,null,E?(0,m.createElement)(ew,{icon:E.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,m.createElement)(xc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,m.createElement)("span",{className:"truncate"},A.label))},"renderOption")})}r(xUt,"PluginSdkAssigneePicker");function gUt({companyId:e,value:s,onChange:n,placeholder:a="Project",noneLabel:i="No project",searchPlaceholder:o="Search projects...",emptyMessage:l="No projects found.",includeArchived:c=!1,className:d,onConfirm:u}){const h=Oz(),p=e??h.companyId??null,{data:x}=ee({queryKey:P.auth.session,queryFn:r(()=>Pa.getSession(),"queryFn")}),g=x?.user?.id??x?.session?.userId??null,{data:v}=ee({queryKey:P.projects.list(p??"__no-company__",{includeArchived:c}),queryFn:r(()=>oa.list(p,{includeArchived:c}),"queryFn"),enabled:!!p}),y=(0,m.useMemo)(()=>(v??[]).filter(_=>c||!_.archivedAt),[c,v]),{orderedProjects:j}=Cv({projects:y,companyId:p,userId:g}),S=(0,m.useMemo)(()=>$w(),[]),w=(0,m.useMemo)(()=>j.map(_=>({id:_.id,label:_.name,searchText:_.description??""})),[j]),N=j.find(_=>_.id===s)??null;return(0,m.createElement)($l,{value:s,options:w,recentOptionIds:S,placeholder:a,noneLabel:i,searchPlaceholder:o,emptyMessage:l,className:d,onConfirm:u,onChange:r(_=>{_&&Mw(_),n(_)},"onChange"),renderTriggerValue:r(_=>!_||!N?(0,m.createElement)("span",{className:"text-muted-foreground"},a):(0,m.createElement)(K3,null,(0,m.createElement)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:N.color??"#6366f1"}}),(0,m.createElement)("span",{className:"truncate"},_.label)),"renderTriggerValue"),renderOption:r(_=>{if(!_.id)return(0,m.createElement)("span",{className:"truncate"},_.label);const I=j.find(C=>C.id===_.id);return(0,m.createElement)(K3,null,(0,m.createElement)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:I?.color??"#6366f1"}}),(0,m.createElement)("span",{className:"truncate"},_.label))},"renderOption")})}r(gUt,"PluginSdkProjectPicker");function K3({children:e}){return(0,m.createElement)("span",{className:"contents"},e)}r(K3,"FragmentSafe");function bUt({label:e,status:s}){const n={ok:"border-emerald-300 bg-emerald-50 text-emerald-700",warning:"border-amber-300 bg-amber-50 text-amber-800",error:"border-red-300 bg-red-50 text-red-700",info:"border-slate-300 bg-slate-50 text-slate-700",pending:"border-slate-300 bg-slate-50 text-slate-600"}[s];return(0,m.createElement)("span",{className:`inline-flex w-fit items-center rounded-full border px-2 py-0.5 text-xs font-medium ${n}`},e)}r(bUt,"PluginSdkStatusBadge");function vUt({columns:e,rows:s,loading:n,emptyMessage:a="No rows."}){if(n)return(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},"Loading...");if(!s.length)return(0,m.createElement)("div",{className:"text-sm text-muted-foreground"},a);const i=e.map(o=>o.width??"minmax(0, 1fr)").join(" ");return(0,m.createElement)("div",{className:"overflow-hidden rounded-md border"},(0,m.createElement)("div",{className:"hidden border-b bg-muted/35 px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground md:grid md:[grid-template-columns:var(--plugin-grid-cols)]",style:{"--plugin-grid-cols":i}},e.map(o=>(0,m.createElement)("div",{key:o.key},o.header))),(0,m.createElement)("div",{className:"divide-y"},s.map((o,l)=>(0,m.createElement)("div",{key:String(o.id??l),className:"grid gap-2 px-3 py-3 md:items-center md:[grid-template-columns:var(--plugin-grid-cols)]",style:{"--plugin-grid-cols":i}},e.map(c=>(0,m.createElement)("div",{key:c.key,className:"min-w-0 text-sm"},(0,m.createElement)("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground md:hidden"},c.header),c.render?c.render(o[c.key],o):String(o[c.key]??"")))))))}r(vUt,"PluginSdkDataTable");function yUt({pairs:e}){return(0,m.createElement)("dl",{className:"grid gap-x-4 gap-y-1 text-sm sm:grid-cols-[max-content_minmax(0,1fr)]"},e.flatMap(s=>[(0,m.createElement)("dt",{key:`${s.label}:label`,className:"text-muted-foreground"},s.label),(0,m.createElement)("dd",{key:`${s.label}:value`,className:"min-w-0"},s.value)]))}r(yUt,"PluginSdkKeyValueList");function jUt({label:e,value:s,unit:n}){return(0,m.createElement)("div",{className:"rounded-md border bg-card p-3"},(0,m.createElement)("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground"},e),(0,m.createElement)("div",{className:"mt-1 text-lg font-semibold"},`${s}${n??""}`))}r(jUt,"PluginSdkMetricCard");function wUt({data:e}){return(0,m.createElement)("pre",{className:"max-h-80 overflow-auto rounded-md border bg-muted/30 p-2 text-xs"},JSON.stringify(e,null,2))}r(wUt,"PluginSdkJsonTree");function NUt({label:e="Loading"}){return(0,m.createElement)("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-muted-foreground/30 border-t-foreground align-middle",role:"status","aria-label":e})}r(NUt,"PluginSdkSpinner");var kUt=class extends m.Component{static{r(this,"PluginSdkErrorBoundary")}state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback??(0,m.createElement)("div",{className:"rounded-md border border-destructive/30 p-3 text-sm text-destructive"},"Plugin UI failed to render."):this.props.children}};function SUt(e,s){globalThis.__paperclipPluginBridge__={react:e,reactJsxRuntime:t,reactDom:s,sdkUi:{usePluginData:zDe,usePluginAction:UDe,useHostContext:Oz,useHostLocation:VDe,useHostNavigation:KDe,usePluginStream:HDe,usePluginToast:WDe,copyTextToClipboard:Gr,MarkdownBlock:r(({content:n,className:a,enableWikiLinks:i,wikiLinkRoot:o,resolveWikiLinkHref:l})=>(0,m.createElement)(Rn,{className:a,softBreaks:!1,enableWikiLinks:i,wikiLinkRoot:o,resolveWikiLinkHref:l,children:n}),"MarkdownBlock"),MetricCard:jUt,StatusBadge:bUt,DataTable:vUt,KeyValueList:yUt,JsonTree:wUt,Spinner:NUt,ErrorBoundary:kUt,MarkdownEditor:hUt,FileTree:mUt,IssuesList:fUt,AssigneePicker:xUt,ProjectPicker:gUt,ManagedRoutinesList:uUt}}}r(SUt,"initPluginBridge");var CUt=1e4;function _Ut(e=CUt){if(typeof performance>"u"||typeof performance.clearMeasures!="function")return()=>{};const n=setInterval(r(()=>{globalThis.__paperclipKeepPerfMeasures||performance.clearMeasures()},"reap"),e);return()=>clearInterval(n)}r(_Ut,"startPerfMeasureReaper");var IUt=gv((e=>{function s(K,z){var D=K.length;K.push(z);e:for(;0<D;){var V=D-1>>>1,H=K[V];if(0<i(H,z))K[V]=z,K[D]=H,D=V;else break e}}r(s,"push");function n(K){return K.length===0?null:K[0]}r(n,"peek");function a(K){if(K.length===0)return null;var z=K[0],D=K.pop();if(D!==z){K[0]=D;e:for(var V=0,H=K.length,Z=H>>>1;V<Z;){var Y=2*(V+1)-1,ie=K[Y],se=Y+1,X=K[se];if(0>i(ie,D))se<H&&0>i(X,ie)?(K[V]=X,K[se]=D,V=se):(K[V]=ie,K[Y]=D,V=Y);else if(se<H&&0>i(X,D))K[V]=X,K[se]=D,V=se;else break e}}return z}r(a,"pop");function i(K,z){var D=K.sortIndex-z.sortIndex;return D!==0?D:K.id-z.id}if(r(i,"compare"),e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var o=performance;e.unstable_now=function(){return o.now()}}else{var l=Date,c=l.now();e.unstable_now=function(){return l.now()-c}}var d=[],u=[],h=1,p=null,x=3,g=!1,v=!1,y=!1,j=!1,S=typeof setTimeout=="function"?setTimeout:null,w=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;function _(K){for(var z=n(u);z!==null;){if(z.callback===null)a(u);else if(z.startTime<=K)a(u),z.sortIndex=z.expirationTime,s(d,z);else break;z=n(u)}}r(_,"advanceTimers");function I(K){if(y=!1,_(K),!v)if(n(d)!==null)v=!0,C||(C=!0,$());else{var z=n(u);z!==null&&B(I,z.startTime-K)}}r(I,"handleTimeout");var C=!1,A=-1,R=5,E=-1;function O(){return j?!0:!(e.unstable_now()-E<R)}r(O,"shouldYieldToHost");function L(){if(j=!1,C){var K=e.unstable_now();E=K;var z=!0;try{e:{v=!1,y&&(y=!1,w(A),A=-1),g=!0;var D=x;try{t:{for(_(K),p=n(d);p!==null&&!(p.expirationTime>K&&O());){var V=p.callback;if(typeof V=="function"){p.callback=null,x=p.priorityLevel;var H=V(p.expirationTime<=K);if(K=e.unstable_now(),typeof H=="function"){p.callback=H,_(K),z=!0;break t}p===n(d)&&a(d),_(K)}else a(d);p=n(d)}if(p!==null)z=!0;else{var Z=n(u);Z!==null&&B(I,Z.startTime-K),z=!1}}break e}finally{p=null,x=D,g=!1}z=void 0}}finally{z?$():C=!1}}}r(L,"performWorkUntilDeadline");var $;if(typeof N=="function")$=r(function(){N(L)},"schedulePerformWorkUntilDeadline");else if(typeof MessageChannel<"u"){var T=new MessageChannel,q=T.port2;T.port1.onmessage=L,$=r(function(){q.postMessage(null)},"schedulePerformWorkUntilDeadline")}else $=r(function(){S(L,0)},"schedulePerformWorkUntilDeadline");function B(K,z){A=S(function(){K(e.unstable_now())},z)}r(B,"requestHostTimeout"),e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(K){K.callback=null},e.unstable_forceFrameRate=function(K){0>K||125<K||(R=0<K?Math.floor(1e3/K):5)},e.unstable_getCurrentPriorityLevel=function(){return x},e.unstable_next=function(K){switch(x){case 1:case 2:case 3:var z=3;break;default:z=x}var D=x;x=z;try{return K()}finally{x=D}},e.unstable_requestPaint=function(){j=!0},e.unstable_runWithPriority=function(K,z){switch(K){case 1:case 2:case 3:case 4:case 5:break;default:K=3}var D=x;x=K;try{return z()}finally{x=D}},e.unstable_scheduleCallback=function(K,z,D){var V=e.unstable_now();switch(typeof D=="object"&&D!==null?(D=D.delay,D=typeof D=="number"&&0<D?V+D:V):D=V,K){case 1:var H=-1;break;case 2:H=250;break;case 5:H=1073741823;break;case 4:H=1e4;break;default:H=5e3}return H=D+H,K={id:h++,callback:z,priorityLevel:K,startTime:D,expirationTime:H,sortIndex:-1},D>V?(K.sortIndex=D,s(u,K),n(d)===null&&K===n(u)&&(y?(w(A),A=-1):y=!0,B(I,D-V))):(K.sortIndex=H,s(d,K),v||g||(v=!0,C||(C=!0,$()))),K},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(K){var z=x;return function(){var D=x;x=z;try{return K.apply(this,arguments)}finally{x=D}}}})),AUt=gv(((e,s)=>{s.exports=IUt()})),RUt=gv((e=>{var s=AUt(),n=U6(),a=Xoe();function i(f){var b="https://react.dev/errors/"+f;if(1<arguments.length){b+="?args[]="+encodeURIComponent(arguments[1]);for(var k=2;k<arguments.length;k++)b+="&args[]="+encodeURIComponent(arguments[k])}return"Minified React error #"+f+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}r(i,"formatProdErrorMessage");function o(f){return!(!f||f.nodeType!==1&&f.nodeType!==9&&f.nodeType!==11)}r(o,"isValidContainer");function l(f){var b=f,k=f;if(f.alternate)for(;b.return;)b=b.return;else{f=b;do b=f,(b.flags&4098)!==0&&(k=b.return),f=b.return;while(f)}return b.tag===3?k:null}r(l,"getNearestMountedFiber");function c(f){if(f.tag===13){var b=f.memoizedState;if(b===null&&(f=f.alternate,f!==null&&(b=f.memoizedState)),b!==null)return b.dehydrated}return null}r(c,"getSuspenseInstanceFromFiber");function d(f){if(f.tag===31){var b=f.memoizedState;if(b===null&&(f=f.alternate,f!==null&&(b=f.memoizedState)),b!==null)return b.dehydrated}return null}r(d,"getActivityInstanceFromFiber");function u(f){if(l(f)!==f)throw Error(i(188))}r(u,"assertIsMounted");function h(f){var b=f.alternate;if(!b){if(b=l(f),b===null)throw Error(i(188));return b!==f?null:f}for(var k=f,M=b;;){var W=k.return;if(W===null)break;var G=W.alternate;if(G===null){if(M=W.return,M!==null){k=M;continue}break}if(W.child===G.child){for(G=W.child;G;){if(G===k)return u(W),f;if(G===M)return u(W),b;G=G.sibling}throw Error(i(188))}if(k.return!==M.return)k=W,M=G;else{for(var xe=!1,Le=W.child;Le;){if(Le===k){xe=!0,k=W,M=G;break}if(Le===M){xe=!0,M=W,k=G;break}Le=Le.sibling}if(!xe){for(Le=G.child;Le;){if(Le===k){xe=!0,k=G,M=W;break}if(Le===M){xe=!0,M=G,k=W;break}Le=Le.sibling}if(!xe)throw Error(i(189))}}if(k.alternate!==M)throw Error(i(190))}if(k.tag!==3)throw Error(i(188));return k.stateNode.current===k?f:b}r(h,"findCurrentFiberUsingSlowPath");function p(f){var b=f.tag;if(b===5||b===26||b===27||b===6)return f;for(f=f.child;f!==null;){if(b=p(f),b!==null)return b;f=f.sibling}return null}r(p,"findCurrentHostFiberImpl");var x=Object.assign,g=Symbol.for("react.element"),v=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),_=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),A=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),L=Symbol.for("react.memo_cache_sentinel"),$=Symbol.iterator;function T(f){return f===null||typeof f!="object"?null:(f=$&&f[$]||f["@@iterator"],typeof f=="function"?f:null)}r(T,"getIteratorFn");var q=Symbol.for("react.client.reference");function B(f){if(f==null)return null;if(typeof f=="function")return f.$$typeof===q?null:f.displayName||f.name||null;if(typeof f=="string")return f;switch(f){case j:return"Fragment";case w:return"Profiler";case S:return"StrictMode";case C:return"Suspense";case A:return"SuspenseList";case O:return"Activity"}if(typeof f=="object")switch(f.$$typeof){case y:return"Portal";case _:return f.displayName||"Context";case N:return(f._context.displayName||"Context")+".Consumer";case I:var b=f.render;return f=f.displayName,f||(f=b.displayName||b.name||"",f=f!==""?"ForwardRef("+f+")":"ForwardRef"),f;case R:return b=f.displayName||null,b!==null?b:B(f.type)||"Memo";case E:b=f._payload,f=f._init;try{return B(f(b))}catch{}}return null}r(B,"getComponentNameFromType");var K=Array.isArray,z=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=a.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,V={pending:!1,data:null,method:null,action:null},H=[],Z=-1;function Y(f){return{current:f}}r(Y,"createCursor");function ie(f){0>Z||(f.current=H[Z],H[Z]=null,Z--)}r(ie,"pop");function se(f,b){Z++,H[Z]=f.current,f.current=b}r(se,"push");var X=Y(null),le=Y(null),oe=Y(null),te=Y(null);function J(f,b){switch(se(oe,b),se(le,f),se(X,null),b.nodeType){case 9:case 11:f=(f=b.documentElement)&&(f=f.namespaceURI)?JV(f):0;break;default:if(f=b.tagName,b=b.namespaceURI)b=JV(b),f=XV(b,f);else switch(f){case"svg":f=1;break;case"math":f=2;break;default:f=0}}ie(X),se(X,f)}r(J,"pushHostContainer");function Q(){ie(X),ie(le),ie(oe)}r(Q,"popHostContainer");function pe(f){f.memoizedState!==null&&se(te,f);var b=X.current,k=XV(b,f.type);b!==k&&(se(le,f),se(X,k))}r(pe,"pushHostContext");function re(f){le.current===f&&(ie(X),ie(le)),te.current===f&&(ie(te),MN._currentValue=V)}r(re,"popHostContext");var ne,ae;function me(f){if(ne===void 0)try{throw Error()}catch(k){var b=k.stack.trim().match(/\n( *(at )?)/);ne=b&&b[1]||"",ae=-1<k.stack.indexOf(`
726
726
  at`)?" (<anonymous>)":-1<k.stack.indexOf("@")?"@unknown:0:0":""}return`
727
727
  `+ne+f+ae}r(me,"describeBuiltInComponentFrame");var he=!1;function Ie(f,b){if(!f||he)return"";he=!0;var k=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var M={DetermineComponentFrameRoot:r(function(){try{if(b){var Rs=r(function(){throw Error()},"Fake");if(Object.defineProperty(Rs.prototype,"props",{set:r(function(){throw Error()},"set")}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Rs,[])}catch(cs){var ns=cs}Reflect.construct(f,[],Rs)}else{try{Rs.call()}catch(cs){ns=cs}f.call(Rs.prototype)}}else{try{throw Error()}catch(cs){ns=cs}(Rs=f())&&typeof Rs.catch=="function"&&Rs.catch(function(){})}}catch(cs){if(cs&&ns&&typeof cs.stack=="string")return[cs.stack,ns.stack]}return[null,null]},"DetermineComponentFrameRoot")};M.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var W=Object.getOwnPropertyDescriptor(M.DetermineComponentFrameRoot,"name");W&&W.configurable&&Object.defineProperty(M.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var G=M.DetermineComponentFrameRoot(),xe=G[0],Le=G[1];if(xe&&Le){var vt=xe.split(`
728
728
  `),es=Le.split(`