@paperclipai/ui 2026.910.0-beta.0 → 2026.910.0-canary.0

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.
Files changed (60) hide show
  1. package/dist/assets/AgentIconPicker-DzNSp_QB.js +1 -0
  2. package/dist/assets/Agents.production-tw_NfkTM.js +2 -0
  3. package/dist/assets/CompanyActivity.production-DLLFoVT2.js +1 -0
  4. package/dist/assets/{CompanyExport-DpMr2acB.js → CompanyExport-BagXJes-.js} +4 -4
  5. package/dist/assets/{CompanySkills.production-DJSQtP1n.js → CompanySkills.production-Ds8WVp4W.js} +2 -2
  6. package/dist/assets/Costs.production-C8KygSbk.js +1 -0
  7. package/dist/assets/{EmptyState-DQ6jQIUo.js → EmptyState-CRpkk2L_.js} +1 -1
  8. package/dist/assets/{MarkdownBody-B4z4FWw0.js → MarkdownBody-DSalctm6.js} +7 -7
  9. package/dist/assets/{MarkdownEditor-DbDeOZsR.js → MarkdownEditor-CW9mJhsq.js} +1 -1
  10. package/dist/assets/OrgChart.production-hnvVesRi.js +1 -0
  11. package/dist/assets/RoutineDetail.production-Czud66fR.js +1 -0
  12. package/dist/assets/Routines.production-D706vSkC.js +1 -0
  13. package/dist/assets/{StatusIcon-Cr09zfcb.js → StatusIcon-DS8jybSt.js} +1 -1
  14. package/dist/assets/{agent-icons-BHs8hbtZ.js → agent-icons-Dh-YUKuy.js} +1 -1
  15. package/dist/assets/agents-Cqpe1a3D.js +1 -0
  16. package/dist/assets/{alert-dialog-BBNRqUo7.js → alert-dialog-DCeKGamE.js} +1 -1
  17. package/dist/assets/{badge-uyKJmko-.js → badge-iI_yv8iK.js} +1 -1
  18. package/dist/assets/{button-DiOYWNh6.js → button-BM3Hk54-.js} +1 -1
  19. package/dist/assets/{check-IYiAPUhF.js → check-DiFGzw9B.js} +1 -1
  20. package/dist/assets/{checkbox-C5mhspe6.js → checkbox-Cx-ykLn4.js} +1 -1
  21. package/dist/assets/{chevron-down-CbQgN0qe.js → chevron-down-hFmYIITw.js} +1 -1
  22. package/dist/assets/{chevron-right-BfFMFd2_.js → chevron-right-Bdpr93dF.js} +1 -1
  23. package/dist/assets/{clipboard-0ZrE4zyA.js → clipboard-Baok3Ay4.js} +1 -1
  24. package/dist/assets/createLucideIcon-DhmuPH6P.js +88 -0
  25. package/dist/assets/{dist-crZbxMxL.js → dist-5R-K0mtk.js} +1 -1
  26. package/dist/assets/{dist-BnbTm3c1.js → dist-B3TxGcxe.js} +1 -1
  27. package/dist/assets/{external-link-BQc7QIDP.js → external-link-rBi5Vbri.js} +1 -1
  28. package/dist/assets/index-B55AfhK-.css +1 -0
  29. package/dist/assets/{index-BLVof-9y.js → index-CfGm8e4P.js} +145 -216
  30. package/dist/assets/{input-BxPbZoXk.js → input-D0lpi1rq.js} +1 -1
  31. package/dist/assets/{label-DZ-qEIig.js → label-WbbkAQMV.js} +1 -1
  32. package/dist/assets/{loader-circle-DjvEHREF.js → loader-circle-C_Leg-Lw.js} +1 -1
  33. package/dist/assets/{mention-chips-BbJsKS4i.js → mention-chips-BzQtzhDI.js} +1 -1
  34. package/dist/assets/{octagon-alert-D6g3WTQ-.js → octagon-alert-sHxYvMpX.js} +1 -1
  35. package/dist/assets/router-D60XTPrE.js +15 -0
  36. package/dist/assets/{tabs-DaTqeIGs.js → tabs-DCF01K_p.js} +1 -1
  37. package/dist/assets/{zap-TLLlRaEJ.js → zap-DjxJDVfV.js} +2 -2
  38. package/dist/brands/apps/manifest.json +2 -32
  39. package/dist/index.html +29 -34
  40. package/dist/sw.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/assets/AgentIconPicker--qn6E8-Y.js +0 -1
  43. package/dist/assets/Agents.production-BeDdpDfO.js +0 -2
  44. package/dist/assets/CompanyActivity.production-CySHpmR-.js +0 -1
  45. package/dist/assets/Costs.production-CxZ-asMw.js +0 -1
  46. package/dist/assets/OrgChart.production-DBbDq48h.js +0 -1
  47. package/dist/assets/RoutineDetail.production-BliKLRMj.js +0 -1
  48. package/dist/assets/RoutineRunVariablesDialog-CQBB6C-O.js +0 -1
  49. package/dist/assets/Routines.production-TZS7ql2J.js +0 -1
  50. package/dist/assets/agents-3Ls7zIJs.js +0 -1
  51. package/dist/assets/createLucideIcon-D1H8HQGW.js +0 -88
  52. package/dist/assets/environments-BN5N5fEM.js +0 -1
  53. package/dist/assets/index-BexAo8m_.css +0 -1
  54. package/dist/assets/minus-DFidMm1e.js +0 -1
  55. package/dist/assets/router-F2GnEhSM.js +0 -15
  56. package/dist/assets/select-CT-YBnwK.js +0 -1
  57. package/dist/assets/triangle-alert-B-EzjMjf.js +0 -1
  58. package/dist/brands/apps/discord.svg +0 -4
  59. package/dist/brands/apps/microsoft-teams.svg +0 -22
  60. package/dist/brands/apps/telegram.svg +0 -4
@@ -0,0 +1 @@
1
+ import{i as r}from"./rolldown-runtime-BQ-vy_Pv.js";import{dr as i,pr as m}from"./createLucideIcon-DhmuPH6P.js";import"./zap-DjxJDVfV.js";import{t as n}from"./agent-icons-Dh-YUKuy.js";import"./input-D0lpi1rq.js";var f=r(m(),1),a=r(i(),1);function x({icon:t,className:o}){const e=n(t);return(0,a.jsx)(e,{className:o})}export{x as t};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CfGm8e4P.js","assets/rolldown-runtime-BQ-vy_Pv.js","assets/createLucideIcon-DhmuPH6P.js","assets/preload-helper-BATLnrmA.js","assets/router-D60XTPrE.js","assets/zap-DjxJDVfV.js","assets/EmptyState-CRpkk2L_.js","assets/button-BM3Hk54-.js","assets/agents-Cqpe1a3D.js","assets/mention-chips-BzQtzhDI.js","assets/agent-icons-Dh-YUKuy.js","assets/dist-5R-K0mtk.js","assets/dist-B3TxGcxe.js","assets/MarkdownEditor-CW9mJhsq.js","assets/AgentIconPicker-DzNSp_QB.js","assets/input-D0lpi1rq.js","assets/dist-CQw_dTZw.js","assets/dist-gF1wAews.js","assets/alert-dialog-DCeKGamE.js","assets/checkbox-Cx-ykLn4.js","assets/check-DiFGzw9B.js","assets/chevron-right-Bdpr93dF.js","assets/label-WbbkAQMV.js","assets/tabs-DCF01K_p.js","assets/StatusIcon-DS8jybSt.js","assets/clipboard-Baok3Ay4.js","assets/loader-circle-C_Leg-Lw.js","assets/octagon-alert-sHxYvMpX.js","assets/chevron-down-hFmYIITw.js","assets/external-link-rBi5Vbri.js","assets/MarkdownBody-DSalctm6.js","assets/badge-iI_yv8iK.js","assets/index-B55AfhK-.css"])))=>i.map(i=>d[i]);
2
+ import{i as le}from"./rolldown-runtime-BQ-vy_Pv.js";import{Mn as b,S as F,U as Le,Y as j,_ as oe,dr as Pe,g as O,pr as ke,rn as Me,z as qe}from"./createLucideIcon-DhmuPH6P.js";import{t as Be}from"./preload-helper-BATLnrmA.js";import{it as Re,o as Fe,t as ce}from"./router-D60XTPrE.js";import{P as ne,S as $e}from"./zap-DjxJDVfV.js";import{t as Ke}from"./tabs-DCF01K_p.js";import{r as ze,t as ae}from"./EmptyState-CRpkk2L_.js";import{A as De,t as U}from"./button-BM3Hk54-.js";import{t as re}from"./agents-Cqpe1a3D.js";import{An as Oe,Bn as Ue,Bt as de,Fn as He,Gt as Ve,Hn as Ge,Kn as Qe,Kt as ie,Ln as Je,Mn as ue,Nn as H,Pn as Ye,Rn as We,Yn as me,cn as Xe,jn as Ze,kn as ge,ln as V,pr as et,tn as tt,un as pe,wn as st,zn as xe,zt as nt}from"./index-CfGm8e4P.js";var g=le(ke(),1),t=le(Pe(),1),fe=Me,at=(0,g.lazy)(()=>Be(()=>import("./index-CfGm8e4P.js").then(e=>e.Dt).then(e=>({default:e.ConfigureBuiltInAgentModal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),rt=["all","active","paused","error","builtin"],it=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"paused",label:"Paused"},{value:"error",label:"Error"},{value:"builtin",label:"Built-in"}];function lt(e){return rt.includes(e)}var Q={label:"Local",detail:"Paperclip host",title:"Local - Paperclip host"},he={label:"—",detail:"Loading environment",title:"Loading environment"},ve=new Set(["terminated","pending_approval"]);function be(e,n){return n==="all"?!0:n==="active"?e==="active"||e==="running"||e==="idle":n==="paused"?e==="paused":n==="error"?e==="error":!0}function ot(e,n,r){return e.filter(a=>ve.has(a.status)?!1:n==="builtin"?r.has(a.id):be(a.status,n)).sort((a,i)=>a.name.localeCompare(i.name))}function ct(e){const n=e.adapterConfig?.model;if(typeof n!="string")return null;const r=n.trim();return r.length>0?r:null}function dt(e){return e==="ssh"?"SSH":e.charAt(0).toUpperCase()+e.slice(1)}function ut(e,n){const r=typeof e.config.provider=="string"?e.config.provider.trim():"";return r?n?.sandboxProviders?.[r]?.displayName??r:"Sandbox"}function mt(e,n){const r=Ve(e)?"Managed by Paperclip":e.driver==="sandbox"?`${ut(e,n)} sandbox provider`:e.driver==="local"?"Paperclip host":dt(e.driver);return{label:e.name,detail:r,title:`${e.name} - ${r}`}}function gt(e){return{label:"Unknown environment",detail:e.slice(0,8),title:`Unknown environment - ${e}`}}function pt(e,n,r,a){const i=e.defaultEnvironmentId??r;if(!i)return Q;const p=n.get(i);return p?mt(p,a):gt(i)}function je(e,n,r){return e.reduce((a,i)=>{const p=je(i.reports,n,r);return ve.has(i.status)?(a.push(...p),a):(((n==="builtin"?r.has(i.id):be(i.status,n))||p.length>0)&&a.push({...i,reports:p}),a)},[]).sort((a,i)=>a.name.localeCompare(i.name))}function Ct(){const{selectedCompanyId:e}=Le(),{openNewAgent:n}=Ge(),{setBreadcrumbs:r}=ze(),a=Fe(),i=Re(),{isMobile:p}=Qe(),I=i.pathname.split("/").pop()??"all",h=lt(I)?I:"all",[C,u]=(0,g.useState)("org"),S=p,m=S?"list":C,{data:l}=b({queryKey:j.instance.settings,queryFn:()=>Je.get(),enabled:!!e}),d=l?.experimental.enableBuiltInAgents===!0,f=h==="builtin"&&!d?"all":h,$=(0,g.useMemo)(()=>it.filter(s=>s.value!=="builtin"||d),[d]),{data:A}=b({queryKey:j.builtInAgents.list(e),queryFn:()=>Ue.list(e),enabled:!!e&&d}),v=(0,g.useMemo)(()=>{const s=new Map;if(!d)return s;for(const o of A??[])o.agentId&&s.set(o.agentId,o);return s},[A,d]),P=(0,g.useMemo)(()=>new Set(v.keys()),[v]),[N,_]=(0,g.useState)(null),{data:c,isLoading:we,error:J}=b({queryKey:j.agents.list(e),queryFn:()=>re.list(e),enabled:!!e}),{data:E}=b({queryKey:j.org(e),queryFn:()=>re.org(e),enabled:!!e&&m==="org"}),k=l?.experimental.enableEnvironments===!0,{data:T}=b({queryKey:j.environments.list(e),queryFn:()=>ie.list(e),enabled:!!e&&k}),{data:Y}=b({queryKey:j.environments.capabilities(e),queryFn:()=>ie.capabilities(e),enabled:!!e&&k}),W=[...j.liveRuns(e),"agents-page"],K=Ze({companyId:e,resourceKey:"live-runs:agents-page",queryKey:W,enabled:!!e,refetchInterval:15e3,leaderOnly:!0}),{data:z,dataUpdatedAt:Ie}=b({queryKey:W,queryFn:()=>We.liveRunsForCompany(e),enabled:K.enabled,refetchInterval:K.refetchInterval});Oe(K,z,Ie);const M=He(e),x=Ye(e),q=(0,g.useMemo)(()=>{const s=new Map;for(const o of z??[]){if(o.status!=="running"&&o.status!=="queued")continue;const L=s.get(o.agentId);if(L){L.liveCount+=1;continue}s.set(o.agentId,{runId:o.id,liveCount:1})}return s},[z]),Ce=(0,g.useMemo)(()=>{const s=new Map;for(const o of c??[])s.set(o.id,o);return s},[c]),X=(0,g.useMemo)(()=>{const s=new Map;for(const o of T??[])s.set(o.id,o);return s},[T]),Z=(0,g.useMemo)(()=>{const s=new Map;for(const o of c??[])s.set(o.id,pt(o,X,l?.defaultEnvironmentId??null,Y));return s},[c,X,Y,l?.defaultEnvironmentId]);if((0,g.useEffect)(()=>{r([{label:"Agents"}])},[r]),(0,g.useEffect)(()=>{e&&h==="builtin"&&l&&!d&&a("/agents/all",{replace:!0})},[d,l,a,h,e]),!e)return(0,t.jsx)(ae,{icon:ne,message:"Select a company to view agents."});if(we)return(0,t.jsx)(tt,{variant:"list"});const y=ot(c??[],f,P),D=je(E??[],f,P),ee=k&&T===void 0,te=k&&(T===void 0||T.length>1),Se=s=>ee?he:Z.get(s)??Q,Ae=s=>{const o=s.orgChainHealth?.status==="invalid_org_chain",L=x.isPending&&x.variables?.resourceType==="agent"&&x.variables.resourceId===s.id,_e=L&&x.variables?.starred!==void 0,se=L&&x.variables?.starred===void 0,Ee=ue(M.data,"agent",s.id),w=v.get(s.id),Te=w?.status==="needs_setup"||w?.status==="pending_approval",B=w&&Te?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(xe,{status:w.status}),w.status==="needs_setup"&&(0,t.jsx)("span",{onClick:R=>{R.preventDefault(),R.stopPropagation()},children:(0,t.jsx)(U,{size:"xs",variant:"outline",onClick:()=>_(w),children:"Set up"})})]}):null;return(0,t.jsx)(nt,{title:s.name,titleClassName:"flex-1 xl:flex-none xl:w-56",titleTextClassName:"whitespace-normal break-words xl:truncate xl:whitespace-nowrap",subtitleClassName:"whitespace-normal break-words xl:truncate xl:whitespace-nowrap",subtitle:`${fe[s.role]??s.role}${s.title?` - ${s.title}`:""}`,to:oe(s),className:F("group",s.pausedAt&&f!=="paused"?"opacity-50":"",H(M.data,"agent",s.id)==="left"?"sm:text-foreground/55":""),leading:o?(0,t.jsx)(me,{className:"h-3.5 w-3.5 text-amber-500","aria-label":"Invalid reporting chain"}):(0,t.jsx)(pe,{status:s.status}),secondaryRow:B?(0,t.jsx)("div",{className:"xl:hidden flex flex-wrap items-center gap-1.5",children:B}):void 0,meta:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[B&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-1.5",children:B}),(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(ye,{agent:s,environment:Se(s.id),showEnvironment:te})})]}),metaSpacerClassName:"hidden xl:block",trailing:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[q.has(s.id)&&(0,t.jsx)(G,{agentRef:O(s),runId:q.get(s.id).runId,liveCount:q.get(s.id).liveCount}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(V,{status:s.status})}),(0,t.jsx)(ge,{size:"row",starred:Ee,pending:_e,resourceName:s.name,onToggle:R=>x.mutate({resourceType:"agent",resourceId:s.id,resourceName:s.name,starred:R})})]}),(0,t.jsx)(de,{state:H(M.data,"agent",s.id),pending:se,pendingState:se?x.variables?.state??null:null,resourceName:s.name,onJoin:()=>x.mutate({resourceType:"agent",resourceId:s.id,resourceName:s.name,state:"joined"}),onLeave:()=>x.mutate({resourceType:"agent",resourceId:s.id,resourceName:s.name,state:"left"})})]})},s.id)};return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,t.jsx)(Ke,{value:f,onValueChange:s=>a(`/agents/${s}`),children:(0,t.jsx)(st,{items:$,value:f,onValueChange:s=>a(`/agents/${s}`)})}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!S&&(0,t.jsxs)("div",{className:"flex items-center border border-border",role:"group","aria-label":"View mode",children:[(0,t.jsx)("button",{className:F("p-1.5 transition-colors",m==="list"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:()=>u("list"),title:"List view","aria-label":"List view","aria-pressed":m==="list",children:(0,t.jsx)(et,{className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{className:F("p-1.5 transition-colors",m==="org"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:()=>u("org"),title:"Org chart view","aria-label":"Org chart view","aria-pressed":m==="org",children:(0,t.jsx)($e,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)(U,{size:"sm",variant:"outline",onClick:n,children:[(0,t.jsx)(De,{className:"h-3.5 w-3.5 mr-1.5"}),"New Agent"]})]})]}),y.length>0&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[y.length," agent",y.length!==1?"s":""]}),J&&(0,t.jsx)("p",{className:"text-sm text-destructive",children:J.message}),c&&c.length===0&&(0,t.jsx)(ae,{icon:ne,message:"Create your first agent to get started.",action:"New Agent",onAction:n}),m==="list"&&y.length>0&&(0,t.jsx)("div",{children:y.map(Ae)}),m==="list"&&c&&c.length>0&&y.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No agents match the selected status."}),m==="org"&&D.length>0&&(0,t.jsx)("div",{className:"py-1",children:D.map(s=>(0,t.jsx)(Ne,{node:s,depth:0,agentMap:Ce,liveRunByAgent:q,environmentByAgentId:Z,environmentDataLoading:ee,showEnvironment:te,tab:f,memberships:M.data,membershipMutation:x,builtInByAgentId:v,onConfigureBuiltIn:_},s.id))}),m==="org"&&E&&E.length>0&&D.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No agents match the selected status."}),m==="org"&&E&&E.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No organizational hierarchy defined."}),N&&e&&(0,t.jsx)(g.Suspense,{fallback:null,children:(0,t.jsx)(at,{companyId:e,state:N,open:N!==null,onOpenChange:s=>{s||_(null)}})})]})}function Ne({node:e,depth:n,agentMap:r,liveRunByAgent:a,environmentByAgentId:i,environmentDataLoading:p,showEnvironment:I,tab:h,memberships:C,membershipMutation:u,builtInByAgentId:S,onConfigureBuiltIn:m}){const l=r.get(e.id),d=S.get(e.id),f=d?.status==="needs_setup"||d?.status==="pending_approval",$=!!(l&&l.orgChainHealth?.status==="invalid_org_chain"),A=H(C,"agent",e.id),v=u.isPending&&u.variables?.resourceType==="agent"&&u.variables.resourceId===e.id,P=v&&u.variables?.starred!==void 0,N=v&&u.variables?.starred===void 0,_=ue(C,"agent",e.id);return(0,t.jsxs)("div",{style:{paddingLeft:n*24},children:[(0,t.jsxs)(ce,{to:l?oe(l):`/agents/${e.id}`,className:F("group flex items-center gap-3 rounded-lg px-3 py-2 hover:bg-accent/50 transition-colors w-full text-left no-underline text-inherit",l?.pausedAt&&h!=="paused"&&"opacity-50",A==="left"&&"sm:text-foreground/55"),children:[$?(0,t.jsx)(me,{className:"h-3.5 w-3.5 shrink-0 text-amber-500","aria-label":"Invalid reporting chain"}):(0,t.jsx)(pe,{status:e.status}),(0,t.jsxs)("div",{className:"flex-1 min-w-0 flex flex-wrap items-center gap-2",children:[(0,t.jsxs)("div",{className:"min-w-(--sz-7rem) truncate",children:[(0,t.jsx)("span",{className:"text-sm font-medium",children:e.name}),(0,t.jsxs)("span",{className:"text-xs text-muted-foreground ml-2",children:[fe[e.role]??e.role,l?.title?` - ${l.title}`:""]})]}),d&&f&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,t.jsx)(xe,{status:d.status}),d.status==="needs_setup"&&(0,t.jsx)("span",{onClick:c=>{c.preventDefault(),c.stopPropagation()},children:(0,t.jsx)(U,{size:"xs",variant:"outline",onClick:()=>m(d),children:"Set up"})})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[(0,t.jsx)("span",{className:"sm:hidden",children:a.has(e.id)?(0,t.jsx)(G,{agentRef:l?O(l):e.id,runId:a.get(e.id).runId,liveCount:a.get(e.id).liveCount}):(0,t.jsx)(V,{status:e.status})}),(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[a.has(e.id)&&(0,t.jsx)(G,{agentRef:l?O(l):e.id,runId:a.get(e.id).runId,liveCount:a.get(e.id).liveCount}),l&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(ye,{agent:l,environment:p?he:i.get(l.id)??Q,showEnvironment:I})}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(V,{status:e.status})})]}),(0,t.jsx)(de,{state:A,pending:N,pendingState:N?u.variables?.state:null,resourceName:e.name,onJoin:()=>u.mutate({resourceType:"agent",resourceId:e.id,resourceName:e.name,state:"joined"}),onLeave:()=>u.mutate({resourceType:"agent",resourceId:e.id,resourceName:e.name,state:"left"})}),(0,t.jsx)("div",{className:"hidden sm:flex items-center gap-3",children:(0,t.jsx)(ge,{size:"row",starred:_,pending:P,resourceName:e.name,onToggle:c=>u.mutate({resourceType:"agent",resourceId:e.id,resourceName:e.name,starred:c})})})]})]}),e.reports&&e.reports.length>0&&(0,t.jsx)("div",{className:"border-l border-border ml-4",children:e.reports.map(c=>(0,t.jsx)(Ne,{node:c,depth:n+1,agentMap:r,liveRunByAgent:a,environmentByAgentId:i,environmentDataLoading:p,showEnvironment:I,tab:h,memberships:C,membershipMutation:u,builtInByAgentId:S,onConfigureBuiltIn:m},c.id))})]})}function ye({agent:e,environment:n,showEnvironment:r}){const a=ct(e),i=Xe(e.adapterType);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"w-44 min-w-0 leading-tight",children:[(0,t.jsx)("div",{className:"truncate font-mono text-xs text-muted-foreground",title:a??void 0,children:a??"—"}),(0,t.jsx)("div",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground/70",title:i,children:i})]}),r&&(0,t.jsxs)("div",{className:"w-44 min-w-0 leading-tight",children:[(0,t.jsx)("div",{className:"truncate text-xs text-muted-foreground",title:n.title,children:n.label}),(0,t.jsx)("div",{className:"truncate text-(length:--text-micro) text-muted-foreground/70",children:n.detail})]}),(0,t.jsx)("span",{className:"w-24 whitespace-nowrap text-right text-xs text-muted-foreground",children:e.lastHeartbeatAt?qe(e.lastHeartbeatAt):"—"})]})}function G({agentRef:e,runId:n,liveCount:r}){return(0,t.jsxs)(ce,{to:`/agents/${e}/runs/${n}`,className:"flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",onClick:a=>a.stopPropagation(),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-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),(0,t.jsxs)("span",{className:"text-(length:--text-micro) font-medium text-blue-600 dark:text-blue-400",children:["Live",r>1?` (${r})`:""]})]})}export{Ct as Agents};
@@ -0,0 +1 @@
1
+ import{i as ae}from"./rolldown-runtime-BQ-vy_Pv.js";import{En as J,Mn as X,S as me,U as xe,Y,dr as pe,pr as he,z as ge}from"./createLucideIcon-DhmuPH6P.js";import{ct as fe,t as ne}from"./router-D60XTPrE.js";import{i as W,r as ye,t as ve}from"./tabs-DCF01K_p.js";import{r as je,t as be}from"./EmptyState-CRpkk2L_.js";import{t as T}from"./button-BM3Hk54-.js";import{t as Ne}from"./agents-Cqpe1a3D.js";import{t as ee}from"./input-D0lpi1rq.js";import{t as we}from"./AgentIconPicker-DzNSp_QB.js";import{$n as Te,Cn as te,Dn as Ae,Ht as Se,Jt as L,Nr as Ce,O as se,Vn as Ee,Xt as R,Yt as f,Zn as Ie,Zt as _,bn as Ue,in as y,nr as Pe,qt as F,rn as v,yr as De}from"./index-CfGm8e4P.js";var i=ae(he(),1),e=ae(pe(),1),Le=50,n="__all",Re=[{value:n,label:"All actions"},{value:"issue.",label:"Tasks"},{value:"agent.",label:"Agents"},{value:"heartbeat.",label:"Runs"},{value:"approval.",label:"Approvals"},{value:"project.",label:"Projects"},{value:"goal.",label:"Goals"},{value:"tool_gateway.",label:"Tools"},{value:"cost.",label:"Costs"},{value:"company.",label:"Company"}],_e=[{value:n,label:"All entities"},{value:"issue",label:"Task"},{value:"agent",label:"Agent"},{value:"project",label:"Project"},{value:"goal",label:"Goal"},{value:"company",label:"Company"}];function Fe(t){if(!t)return;const a=new Date(`${t}T00:00:00.000Z`);return Number.isNaN(a.getTime())?void 0:a.toISOString()}function ke(t){if(!t)return;const a=new Date(`${t}T23:59:59.999Z`);return Number.isNaN(a.getTime())?void 0:a.toISOString()}function Be({record:t,agentMap:a,userProfileMap:c}){const d=t.agentId??(t.actorType==="agent"?t.actorId:null),o=d?a.get(d):null;if(o)return(0,e.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1.5",title:o.name,children:[(0,e.jsx)("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground",children:(0,e.jsx)(we,{icon:o.icon,className:"h-3 w-3"})}),(0,e.jsx)("span",{className:"truncate font-medium text-foreground",children:o.name})]});if(t.actorType==="user"&&t.actorId){const u=c.get(t.actorId);return(0,e.jsx)(te,{name:u?.label??"User",avatarUrl:u?.image??null,size:"sm",className:"font-medium text-foreground"})}const p=t.actorType==="plugin"?"Plugin":t.actorType==="agent"?"Agent":t.actorType==="user"?"User":"System";return(0,e.jsx)(te,{name:p,size:"sm",className:"font-medium text-foreground"})}function Ve({record:t}){const{issue:a,document:c}=t.entity,d=a?.identifier??a?.id??null;return d?(0,e.jsx)(ne,{to:`/issues/${d}`,className:"font-medium text-primary hover:underline",children:a?.identifier?`${a.identifier}${a.title?` · ${a.title}`:""}`:"the task"}):c?(0,e.jsx)("span",{className:"font-medium text-foreground",children:c.key}):(0,e.jsx)("span",{className:"text-muted-foreground",children:t.entityType})}function $e({record:t,agentMap:a,userProfileMap:c}){const d=Se(t.action,t.details,{agentMap:a,userProfileMap:c}),o=t.responsibleUserId?c.get(t.responsibleUserId):null,p=!!(t.responsibleUserId&&!(t.actorType==="user"&&t.actorId===t.responsibleUserId)),u=o?.label??(t.responsibleUserId?"a user":null),h=t.entity.comment?.excerpt?.trim(),m=t.entity.issue&&t.entity.document?t.entity.document.key:null;return(0,e.jsx)("li",{className:"px-4 py-3 text-sm",children:(0,e.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,e.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-1 text-foreground",children:[(0,e.jsx)(Be,{record:t,agentMap:a,userProfileMap:c}),(0,e.jsx)("span",{className:"text-muted-foreground",children:d}),(0,e.jsx)(Ve,{record:t})]}),h?(0,e.jsxs)("p",{className:"line-clamp-2 border-l-2 border-border pl-2 text-muted-foreground",children:["“",h,"”"]}):null,m?(0,e.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Document ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:m})]}):null,(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[p&&u?(0,e.jsxs)("span",{className:"inline-flex items-center rounded-full bg-muted px-2 py-0.5",children:["on behalf of ",u]}):null,t.runId&&t.agentId?(0,e.jsx)(ne,{to:`/agents/${t.agentId}/runs/${t.runId}`,className:"text-primary hover:underline",children:"View run"}):null,(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro) opacity-70",children:t.action})]})]}),(0,e.jsx)("time",{className:"shrink-0 whitespace-nowrap text-xs text-muted-foreground",dateTime:t.createdAt,title:new Date(t.createdAt).toLocaleString(),children:ge(t.createdAt)})]})})}function qe(){return(0,e.jsx)(v,{children:(0,e.jsxs)(y,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(Ie,{className:"h-10 w-10 text-muted-foreground/50"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Agent audit is a Paperclip Enterprise view"}),(0,e.jsxs)("p",{className:"mx-auto mt-1 max-w-md text-sm text-muted-foreground",children:["The agent audit log gives you a searchable, exportable record of everything your agents did — every comment, task change, approval, and run — with the responsible person for each action. Ask an administrator to grant you the"," ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:"audit:view_agent_actions"})," ","permission to view it."]})]})]})})}function Me({companyId:t,lockedAgentId:a,hideHeader:c,mode:d,onModeChange:o}){const{pushToast:p}=Ee(),[u,h]=(0,i.useState)(n),[m,k]=(0,i.useState)(n),[A,B]=(0,i.useState)(n),[S,V]=(0,i.useState)(n),[C,$]=(0,i.useState)(""),[E,q]=(0,i.useState)(""),[Z,G]=(0,i.useState)(!1),[I,Q]=(0,i.useState)(!1),M=X({queryKey:Y.agents.list(t),queryFn:()=>Ne.list(t)}),z=X({queryKey:Y.access.companyUserDirectory(t),queryFn:()=>Ae.listUserDirectory(t),retry:!1}),re=(0,i.useMemo)(()=>new Map((M.data??[]).map(s=>[s.id,s])),[M.data]),ie=(0,i.useMemo)(()=>Ue(z.data?.users),[z.data]),g=a?"agents":d??"all",l={actorScope:g,agentId:a??(u===n?void 0:u),responsibleUserId:m===n?void 0:m,action:A===n?void 0:A,entityType:S===n?void 0:S,from:Fe(C),to:ke(E)},j=!!(!a&&u!==n||m!==n||A!==n||S!==n||C||E),r=Ce({queryKey:Y.audit.agentActions(t,{actorScope:l.actorScope,agentId:l.agentId,responsibleUserId:l.responsibleUserId,action:l.action,entityType:l.entityType,from:l.from,to:l.to}),queryFn:({pageParam:s})=>se.listAgentActions(t,{...l,limit:Le,cursor:s??void 0}),initialPageParam:null,getNextPageParam:s=>s.nextCursor??void 0,retry:(s,x)=>!(x instanceof J&&x.status===403)&&s<2}),O=r.error instanceof J&&r.error.status===403,U=r.data?.pages.some(s=>s.accessTier==="basic")??!1,le=r.data?.pages.some(s=>s.accessTier==="full")??!1,K=(0,i.useMemo)(()=>{const s=r.data?.pages??[];return(U?s.filter(x=>x.accessTier!=="full"):s).flatMap(x=>x.items)},[r.data,U]),P=U?"basic":r.data?.pages[0]?.accessTier,b=U&&le,oe=a?!0:P==="full",ce=!!(b&&I&&!r.isFetching),D=!!(!a&&!ce&&(O&&j||b)),N=!!(O&&!a&&g==="agents"&&o),de=!!(!a&&o&&!N&&(g==="agents"||P==="full"));(0,i.useEffect)(()=>{N&&o?.("all")},[N,o]),(0,i.useEffect)(()=>{!a&&(P==="basic"||D)&&(h(n),k(n),B(n),V(n),$(""),q(""))},[P,b,a,D]),(0,i.useEffect)(()=>{if(!b){I&&Q(!1);return}I||(Q(!0),r.refetch())},[I,r,b]);const H=()=>{h(n),k(n),B(n),V(n),$(""),q("")},ue=async()=>{G(!0);try{const s=await se.exportAgentActionsCsv(t,{actorScope:l.actorScope,agentId:l.agentId,responsibleUserId:l.responsibleUserId,action:l.action,entityType:l.entityType,from:l.from,to:l.to}),x=URL.createObjectURL(s),w=document.createElement("a");w.href=x,w.download=`${g==="agents"?"agent-audit":"activity"}-${t}.csv`,document.body.appendChild(w),w.click(),w.remove(),window.setTimeout(()=>URL.revokeObjectURL(x),5e3),p({title:"Audit exported",body:"Your CSV download has started.",tone:"success"})}catch(s){p({title:"Export failed",body:s instanceof Error?s.message:"Could not export the audit log.",tone:"error"})}finally{G(!1)}};return O&&!D&&!N?(0,e.jsx)(qe,{}):(0,e.jsxs)("div",{className:"space-y-4",children:[c?null:(0,e.jsx)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Activity"}),(0,e.jsx)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:g==="agents"?"Every recorded agent action, newest first — with the responsible person and run behind each one.":"Everything happening in your company, newest first — people, agents, and the system. Each line is one recorded action."})]})}),de?(0,e.jsx)(ve,{value:g,onValueChange:s=>o?.(s),children:(0,e.jsxs)(ye,{"aria-label":"Activity scope",children:[(0,e.jsx)(W,{value:"all",children:"All activity"}),(0,e.jsx)(W,{value:"agents",children:"Agent actions"})]})}):null,oe?(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[a?null:(0,e.jsxs)(F,{value:u,onValueChange:h,children:[(0,e.jsx)(R,{className:"w-40",children:(0,e.jsx)(_,{placeholder:"Agent"})}),(0,e.jsxs)(L,{children:[(0,e.jsx)(f,{value:n,children:"All agents"}),(M.data??[]).map(s=>(0,e.jsx)(f,{value:s.id,children:s.name},s.id))]})]}),(0,e.jsxs)(F,{value:m,onValueChange:k,children:[(0,e.jsx)(R,{className:"w-52",children:(0,e.jsx)(_,{placeholder:"Responsible user"})}),(0,e.jsxs)(L,{children:[(0,e.jsx)(f,{value:n,children:"All responsible users"}),(z.data?.users??[]).map(s=>(0,e.jsx)(f,{value:s.principalId,children:s.user?.name??s.user?.email??s.principalId.slice(0,8)},s.principalId))]})]}),(0,e.jsxs)(F,{value:A,onValueChange:B,children:[(0,e.jsx)(R,{className:"w-36",children:(0,e.jsx)(_,{placeholder:"Action"})}),(0,e.jsx)(L,{children:Re.map(s=>(0,e.jsx)(f,{value:s.value,children:s.label},s.value))})]}),(0,e.jsxs)(F,{value:S,onValueChange:V,children:[(0,e.jsx)(R,{className:"w-36",children:(0,e.jsx)(_,{placeholder:"Entity"})}),(0,e.jsx)(L,{children:_e.map(s=>(0,e.jsx)(f,{value:s.value,children:s.label},s.value))})]}),(0,e.jsx)(ee,{type:"date","aria-label":"From date",value:C,max:E||void 0,onChange:s=>$(s.target.value),className:"w-36"}),(0,e.jsx)(ee,{type:"date","aria-label":"To date",value:E,min:C||void 0,onChange:s=>q(s.target.value),className:"w-36"}),j?(0,e.jsx)(T,{variant:"ghost",size:"sm",onClick:H,children:"Clear filters"}):null,(0,e.jsxs)(T,{variant:"outline",size:"sm",className:"ml-auto",onClick:ue,disabled:Z||r.isLoading||K.length===0,children:[(0,e.jsx)(De,{className:"mr-1.5 h-4 w-4"}),Z?"Exporting…":"Export CSV"]})]}):null,D||N?(0,e.jsx)(v,{children:(0,e.jsx)(y,{className:"py-14 text-center text-sm text-muted-foreground",children:"Refreshing audit access…"})}):r.isLoading?(0,e.jsx)(v,{children:(0,e.jsx)(y,{className:"py-14 text-center text-sm text-muted-foreground",children:"Loading…"})}):r.error?(0,e.jsx)(v,{children:(0,e.jsxs)(y,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:r.error instanceof Error?r.error.message:"Failed to load the audit log."}),(0,e.jsx)(T,{variant:"outline",size:"sm",onClick:()=>r.refetch(),children:"Try again"})]})}):K.length===0?(0,e.jsx)(v,{children:(0,e.jsxs)(y,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(Te,{className:"h-10 w-10 text-muted-foreground/40"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-medium text-foreground",children:j?"No actions match these filters":"Nothing here yet"}),(0,e.jsx)("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:j?"Try a wider date range or different filters.":g==="agents"?"As soon as your agents start doing things, their actions show up here.":"As soon as anyone in your company does something, it shows up here."})]}),j?(0,e.jsx)(T,{variant:"outline",size:"sm",onClick:H,children:"Clear filters"}):null]})}):(0,e.jsx)(v,{children:(0,e.jsx)(y,{className:"px-0 py-0",children:(0,e.jsx)("ul",{className:me("divide-y divide-border"),children:K.map(s=>(0,e.jsx)($e,{record:s,agentMap:re,userProfileMap:ie},s.id))})})}),r.hasNextPage?(0,e.jsx)("div",{className:"flex justify-center",children:(0,e.jsx)(T,{variant:"outline",size:"sm",onClick:()=>r.fetchNextPage(),disabled:r.isFetchingNextPage,children:r.isFetchingNextPage?"Loading…":"Load more"})}):null,(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Recorded by Paperclip — entries can't be edited. Sensitive values are never stored."})]})}function We(){const{selectedCompanyId:t}=xe(),{setBreadcrumbs:a}=je(),[c,d]=fe(),o=c.get("mode")==="agents"?"agents":"all";(0,i.useEffect)(()=>{a([{label:"Activity"}])},[a]);const p=(0,i.useCallback)(u=>{d(h=>{const m=new URLSearchParams(h);return u==="agents"?m.set("mode","agents"):m.delete("mode"),m},{replace:!0})},[d]);return t?(0,e.jsx)(Me,{companyId:t,mode:o,onModeChange:p}):(0,e.jsx)(be,{icon:Pe,message:"Select a company to view activity."})}export{We as CompanyActivity};
@@ -1,4 +1,4 @@
1
- import{i as be}from"./rolldown-runtime-BQ-vy_Pv.js";import{En as ee,Mn as ue,Nn as Z,S as se,St as Be,U as ze,X as De,Y as G,fr as _e,mr as Ue,tt as We}from"./createLucideIcon-D1H8HQGW.js";import{at as qe,o as Ke,p as Ye}from"./router-F2GnEhSM.js";import{Z as Ze}from"./mention-chips-BbJsKS4i.js";import{l as Ge,p as B}from"./zap-TLLlRaEJ.js";import{g as Xe}from"./StatusIcon-Cr09zfcb.js";import{r as He,t as z}from"./EmptyState-DQ6jQIUo.js";import{t as X}from"./button-DiOYWNh6.js";import{t as pe}from"./MarkdownBody-B4z4FWw0.js";import{t as Je}from"./agents-3Ls7zIJs.js";import{t as Qe}from"./loader-circle-DjvEHREF.js";import{Ct as Ve,En as et,In as fe,Jt as tt,Qn as st,Sn as nt,St as me,Tt as rt,a as ot,bt as at,i as it,mn as ct,n as lt,qt as dt,r as ut,t as we,wt as pt,xt as ft}from"./index-BLVof-9y.js";var m=be(Ue(),1),mt=["agents","projects","skills","routines","tasks","attachments"],ht={agents:"Agents",projects:"Projects",skills:"Skills",routines:"Routines",tasks:"Tasks",attachments:"Attachments"};function xt(){return{agents:!0,projects:!0,skills:!0,routines:!0,tasks:!0,attachments:!0}}function je(e){return e.tasks||e.routines}function ye(e){const o=new Set;for(const a of e){if(!a.recurring)continue;const n=a.path.trim();if(!n)continue;o.add(n);const r=n.lastIndexOf("/");r>=0&&o.add(`${n.slice(0,r+1)}`)}return o}function gt(e,o){for(const a of o)if(e===a||e.startsWith(a))return!0;return!1}function bt(e){const o=new Set,a=new Set;for(const n of e)for(const r of n.attachments??[]){const c=r.sha256.trim().toLowerCase();c&&(n.recurring?o:a).add(c)}return{recurring:o,oneOff:a}}var wt=new Set(["agents","projects","skills","routines","tasks"]);function jt(e){const o=new Map;for(const a of e){const n=a.sha256.trim().toLowerCase();if(!n)continue;const r=o.get(n)??new Set,c=a.ownedBy&&a.ownedBy.length>0?a.ownedBy:["always"];for(const u of c)r.add(u);o.set(n,r)}return o}function yt(e,o){for(const a of e)if(!wt.has(a)||o[a])return!0;return!1}function ve(e,o){return e.startsWith("agents/")?"agents":e.startsWith("projects/")?"projects":e.startsWith("skills/")?"skills":e.startsWith("tasks/")?gt(e,o)?"routines":"tasks":e.startsWith("blobs/")?"attachments":null}function vt(e,o){const a=ye(o),n={agents:0,projects:0,skills:0,routines:0,tasks:0,attachments:0};for(const r of e){const c=ve(r,a);c&&(n[c]+=1)}return n}function St(e){const{filePaths:o,issues:a,categories:n}=e,r=ye(a),c=bt(a),u=jt(e.embeddedAssets??[]),p=n.attachments&&je(n),h=new Set;for(const l of o){const g=ve(l,r);if(g===null){h.add(l);continue}if(g==="attachments"){const i=l.slice(6).trim().toLowerCase(),x=u.get(i);if(x&&yt(x,n)){h.add(l);continue}if(!p)continue;const w=c.recurring.has(i),j=c.oneOff.has(i);!w&&!j?x||h.add(l):(j&&n.tasks||w&&n.routines)&&h.add(l);continue}n[g]&&h.add(l)}return h}function Se(e,o){if(!o.has(e))return o.add(e),e;let a=2;for(;;){const n=`${e}-${a}`;if(!o.has(n))return o.add(n),n;a+=1}}function kt(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=Be(r.name)??"agent";a.set(r.id,Se(c,o))}return a}function Ct(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=We(r.name,r.name);a.set(r.id,Se(c,o))}return a}function Et(e){const o=kt(e.agents),a=Ct(e.projects),n={agents:e.orderedAgents.map(r=>o.get(r.id)).filter(r=>!!r),projects:e.orderedProjects.map(r=>a.get(r.id)).filter(r=>!!r)};return n.agents.length>0||n.projects.length>0?n:void 0}var t=be(_e(),1);function ke(e){const o=new Set,a=new Set,n=new Set;for(const r of e){const c=r.match(/^agents\/([^/]+)\//);c&&o.add(c[1]);const u=r.match(/^projects\/([^/]+)\//);u&&a.add(u[1]);const p=r.match(/^tasks\/([^/]+)\//);p&&n.add(p[1])}return{agents:o,projects:a,tasks:n,routines:new Set(n)}}function Nt(e,o){const a=ke(o),n=e.split(`
2
- `),r=[],c=new Set(["agents","projects","tasks","routines"]),u=new Set(["agents","projects"]);let p=null,h=null,l=!0,g=null,i=null,x=[],w=null,j=[];function R(){i!==null&&x.length>0&&(j.push(i),j.push(...x)),i=null,x=[]}function E(){R(),w!==null&&j.length>0&&(r.push(w),r.push(...j)),w=null,j=[]}for(const b of n){const _=b.match(/^([a-zA-Z_][\w-]*):\s*(.*)$/);if(_&&!b.startsWith(" ")){E(),h=null,l=!0;const C=_[0].split(":")[0];if(c.has(C)){p=C,w=b;continue}else if(C==="sidebar"){p=C,g=null,w=b;continue}else{p=null,r.push(b);continue}}if(p==="sidebar"){const C=b.match(/^ ([\w-]+):\s*$/);if(C&&!b.startsWith(" ")){R();const N=C[1];g=N&&u.has(N)?N:null,i=g?b:null;continue}const T=b.match(/^ - ["']?([^"'\n]+)["']?\s*$/);if(T&&g){const N=T[1],U=a[g];N&&U.has(N)&&x.push(b);continue}if(g){x.push(b);continue}}if(p&&c.has(p)){const C=b.match(/^ ([\w][\w-]*):\s*(.*)$/);if(C&&!b.startsWith(" ")){const T=C[1];h=T,l=a[p].has(T),l&&j.push(b);continue}if(h!==null){l&&j.push(b);continue}j.push(b);continue}r.push(b)}E();let k=r.join(`
3
- `);const D=k.match(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*$/m);return D&&!o.has(D[1])&&(k=k.replace(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*\n?/m,"")),k}function Ce(e,o){if(!o)return e;const a=o.toLowerCase();return e.map(n=>{if(n.kind==="file")return n.name.toLowerCase().includes(a)||n.path.toLowerCase().includes(a)?n:null;const r=Ce(n.children,o);return r.length>0?{...n,children:r}:null}).filter(n=>n!==null)}function At(e,o){const a=new Set,n=o.toLowerCase();function r(c,u){if(c.kind==="file"){if(c.name.toLowerCase().includes(n)||c.path.toLowerCase().includes(n))for(const p of u)a.add(p)}else for(const p of c.children)r(p,[...u,c.path])}for(const c of e)r(c,[]);return a}var he=10;function Pt(e,o,a,n){let r=0,c=0;return{nodes:e.map(u=>{if(u.kind==="dir"&&u.name==="tasks"){r=u.children.length;const p=[],h=[],l=a.toLowerCase();for(const x of u.children){const w=Ve([x],"file"),j=n!==null&&w.has(n),R=a&&(x.name.toLowerCase().includes(l)||x.path.toLowerCase().includes(l)||[...w].some(E=>E.toLowerCase().includes(l)));j||R?p.push(x):h.push(x)}const g=Math.max(0,o-p.length),i=[...p,...h.slice(0,g)];return c=i.length,{...u,children:i}}return u}),totalTaskChildren:r,visibleTaskChildren:c}}function Ee(e,o,a){const n={};for(const r of Object.keys(e))o.has(r)&&(n[r]=a[r]??e[r]);return n}function Rt(e,o,a){const n=Ee(e.files,o,a),r=it(n,e.rootPath),c=new ArrayBuffer(r.byteLength);new Uint8Array(c).set(r);const u=new Blob([c],{type:"application/zip"}),p=URL.createObjectURL(u),h=document.createElement("a");h.href=p,h.download=`${e.rootPath}.zip`,document.body.appendChild(h),h.click(),h.remove(),window.setTimeout(()=>URL.revokeObjectURL(p),1e3)}function Tt({data:e,onSkillClick:o}){return(0,t.jsx)("div",{className:"rounded-md border border-border bg-accent/20 px-4 py-3 mb-4",children:(0,t.jsx)("dl",{className:"grid grid-cols-(--gtc-5) gap-x-4 gap-y-1.5 text-sm",children:Object.entries(e).map(([a,n])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-muted-foreground whitespace-nowrap py-0.5",children:at[a]??a}),(0,t.jsx)("dd",{className:"py-0.5",children:Array.isArray(n)?(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(r=>(0,t.jsx)("button",{type:"button",className:se("inline-flex items-center rounded-md border border-border bg-background px-2 py-0.5 text-xs",a==="skills"&&o&&"cursor-pointer hover:bg-accent/50 hover:border-foreground/30 transition-colors"),onClick:()=>a==="skills"&&o?.(r),children:r},r))}):(0,t.jsx)("span",{children:n})})]},a))})})}var Lt={ceo:"CEO",cto:"CTO",cmo:"CMO",cfo:"CFO",coo:"COO",vp:"VP",manager:"Manager",engineer:"Engineer",agent:"Agent"};function Mt(e,o,a,n){const r=ke(o),c=e.agents.filter(i=>r.agents.has(i.slug)),u=e.projects.filter(i=>r.projects.has(i.slug)),p=e.issues.filter(i=>r.tasks.has(i.slug)),h=e.skills.filter(i=>[...o].some(x=>x.startsWith(`skills/${i.key}/`)||x.startsWith("skills/")&&x.includes(`/${i.slug}/`))),l=[];l.push(`# ${a}`),l.push(""),n&&(l.push(`> ${n}`),l.push("")),c.length>0&&(l.push("![Org Chart](images/org-chart.png)"),l.push("")),l.push("## What's Inside"),l.push(""),l.push("This is an [Agent Company](https://paperclip.ing) package."),l.push("");const g=[];if(c.length>0&&g.push(["Agents",c.length]),u.length>0&&g.push(["Projects",u.length]),h.length>0&&g.push(["Skills",h.length]),p.length>0&&g.push(["Tasks",p.length]),g.length>0){l.push("| Content | Count |"),l.push("|---------|-------|");for(const[i,x]of g)l.push(`| ${i} | ${x} |`);l.push("")}if(c.length>0){l.push("### Agents"),l.push(""),l.push("| Agent | Role | Reports To |"),l.push("|-------|------|------------|");for(const i of c){const x=Lt[i.role]??i.role,w=i.reportsToSlug??"—";l.push(`| ${i.name} | ${x} | ${w} |`)}l.push("")}if(u.length>0){l.push("### Projects"),l.push("");for(const i of u){const x=i.description?` — ${i.description}`:"";l.push(`- **${i.name}**${x}`)}l.push("")}return l.push("## Getting Started"),l.push(""),l.push("```bash"),l.push("npx paperclipai company import this-github-url-or-folder"),l.push("```"),l.push(""),l.push("See [Paperclip](https://paperclip.ing) for more information."),l.push(""),l.push("---"),l.push(`Exported from [Paperclip](https://paperclip.ing) on ${new Date().toISOString().split("T")[0]}`),l.push(""),l.join(`
4
- `)}function Ot(e){const{src:o,selectedFile:a,allFiles:n,orgChartPreviewUrl:r}=e;if(/^(?:https?:|data:)/i.test(o))return null;if(o.replace(/^\.\//,"")==="images/org-chart.png"&&r)return r;const c=(a.includes("/")?a.slice(0,a.lastIndexOf("/")+1):"")+o,u=n[c]??n[o];return u?we(c in n?c:o,u):null}function Ft({selectedFile:e,content:o,allFiles:a,orgChartPreviewUrl:n,onSkillClick:r}){if(!e||o===null)return(0,t.jsx)(z,{icon:B,message:"Select a file to preview its contents."});const c=lt(o),u=e.endsWith(".md")&&c!==null,p=u&&c?rt(c):null,h=ut(e,o)?we(e,o):null,l=u?g=>Ot({src:g,selectedFile:e,allFiles:a,orgChartPreviewUrl:n}):void 0;return(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"border-b border-border px-5 py-3",children:(0,t.jsx)("div",{className:"truncate font-mono text-sm",children:e})}),(0,t.jsx)("div",{className:"min-h-(--sz-560px) px-5 py-5",children:p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Tt,{data:p.data,onSkillClick:r}),p.body.trim()&&(0,t.jsx)(pe,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:p.body})]}):u?(0,t.jsx)(pe,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:c??""}):h?(0,t.jsx)("div",{className:"flex min-h-(--sz-520px) items-center justify-center rounded-lg border border-border bg-accent/10 p-6",children:(0,t.jsx)("img",{src:h,alt:e,className:"max-h-(--sz-480px) max-w-full object-contain"})}):c!==null?(0,t.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words border-0 bg-transparent p-0 font-mono text-sm text-foreground",children:(0,t.jsx)("code",{children:c})}):(0,t.jsx)("div",{className:"rounded-lg border border-border bg-accent/10 px-4 py-3 text-sm text-muted-foreground",children:"Binary asset preview is not available for this file type."})})]})}function xe(e){const o="/company/export/files/",a=Ye(e),n=a.indexOf(o);return n===-1?null:decodeURIComponent(a.slice(n+22))||null}function ge(e){const o=e.split("/").slice(0,-1),a=[];let n="";for(const r of o)n=n?`${n}/${r}`:r,a.push(n);return a}function It(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}function te(e){return e instanceof Error?e.message:"Failed to load export data."}function Xt(){const{selectedCompanyId:e,selectedCompany:o}=ze(),{setBreadcrumbs:a}=He(),{pushToast:n}=et(),r=Ke(),c=qe(),u=(0,m.useRef)(xe(c.pathname)),{data:p}=Z({queryKey:G.auth.session,queryFn:()=>De.getSession()}),{data:h=[]}=Z({queryKey:G.agents.list(e),queryFn:()=>Je.list(e),enabled:!!e}),{data:l=[]}=Z({queryKey:G.projects.list(e),queryFn:()=>Xe.list(e),enabled:!!e}),{data:g}=Z({queryKey:G.companies.exportFidelity(e),queryFn:()=>ee.exportFidelity(e),enabled:!!e}),[i,x]=(0,m.useState)(null),[w,j]=(0,m.useState)(null),[R,E]=(0,m.useState)(new Set),[k,D]=(0,m.useState)(()=>({...xt(),tasks:!1,routines:!1,attachments:!1})),[b,_]=(0,m.useState)(""),[C,T]=(0,m.useState)(he),[N,U]=(0,m.useState)(!1),W=(0,m.useRef)(null),F=(0,m.useRef)(null),M=(0,m.useRef)(0),ne=(0,m.useRef)(null),re=p?.user?.id??p?.session?.userId??null,H=(0,m.useMemo)(()=>h.filter(s=>s.status!=="terminated"),[h]),J=(0,m.useMemo)(()=>l,[l]),{orderedAgents:oe}=nt({agents:H,companyId:e,userId:re}),{orderedProjects:ae}=ct({projects:J,companyId:e,userId:re}),ie=(0,m.useMemo)(()=>Et({agents:H,orderedAgents:oe,projects:J,orderedProjects:ae}),[oe,ae,H,J]),Q=k.tasks||k.routines,V=(0,m.useCallback)((s,d=!1)=>{j(s),s?r(`/company/export/files/${encodeURI(s)}`,{replace:d}):r("/company/export",{replace:d})},[r]);(0,m.useEffect)(()=>{if(!i)return;const s=xe(c.pathname);s&&s in i.files&&s!==w?(j(s),E(d=>{const f=new Set(d);for(const y of ge(s))f.add(y);return f})):!s&&w&&j(null)},[c.pathname,i]),(0,m.useEffect)(()=>{a([{label:o?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Export"}])},[o?.name,a]);const A=ue({mutationFn:({includeIssues:s,includeSkills:d,signal:f})=>ee.exportPreview(e,{include:{company:!0,agents:!0,projects:!0,issues:s,skills:d},sidebarOrder:ie},{signal:f}),onSuccess:(s,d)=>{if(d.requestId!==M.current)return;x(s);const f=me(s.files),y=new Set;for(const v of f)v.kind==="dir"&&v.name!=="tasks"&&y.add(v.path);const S=u.current;if(S&&S in s.files){j(S);const v=ge(S);E(new Set([...y,...v]))}else{const v="README.md"in s.files?"README.md":Object.keys(s.files)[0];v&&V(v,!0),E(y)}},onError:(s,d)=>{d.requestId!==M.current||It(s)||n({tone:"error",title:"Export failed",body:te(s)})}});function O(){if(!e)return;F.current?.abort();const s=new AbortController,d=M.current+1;M.current=d,F.current=s,U(!1),A.mutate({includeIssues:Q,includeSkills:k.skills,requestId:d,signal:s.signal})}const q=ue({mutationFn:()=>ee.exportBundle(e,{include:{company:!0,agents:!0,projects:!0,issues:Q,skills:k.skills},selectedFiles:Array.from(P).sort(),sidebarOrder:ie}),onSuccess:s=>{const d=new Set(Object.keys(s.files));Rt(s,d,s.files),n({tone:"success",title:"Export downloaded",body:`${d.size} file${d.size===1?"":"s"} exported as ${s.rootPath}.zip`})},onError:s=>{n({tone:"error",title:"Export failed",body:s instanceof Error?s.message:"Failed to build export package."})}});(0,m.useEffect)(()=>{e&&(ne.current!==e&&(ne.current=e,x(null),j(null)),O())},[e,Q,k.skills]),(0,m.useEffect)(()=>()=>{M.current+=1,F.current?.abort()},[]);const L=(0,m.useMemo)(()=>i?me(i.files):[],[i]),P=(0,m.useMemo)(()=>i?St({filePaths:Object.keys(i.files),issues:i.manifest.issues,categories:k,embeddedAssets:i.manifest.embeddedAssets??[]}):new Set,[i,k]),Ne=(0,m.useMemo)(()=>i?vt(Object.keys(i.files),i.manifest.issues):null,[i]),{displayTree:Ae,totalTaskChildren:ce,visibleTaskChildren:le}=(0,m.useMemo)(()=>{let s=L;b&&(s=Ce(s,b));const d=Pt(s,C,b,w);return{displayTree:d.nodes,totalTaskChildren:d.totalTaskChildren,visibleTaskChildren:d.visibleTaskChildren}},[L,b,C,w]),Pe=(0,m.useMemo)(()=>{const s={};function d(f){if(f.kind==="file"){const S=P.has(f.path);return S||(s[f.path]="muted"),S}let y=!1;for(const S of f.children)d(S)&&(y=!0);return y||(s[f.path]="muted"),y}for(const f of L)d(f);return s},[L,P]),K=(0,m.useMemo)(()=>{if(!i)return{};const s={...i.files},d=i.paperclipExtensionPath;if(d&&typeof i.files[d]=="string"&&(s[d]=Nt(i.files[d],P)),typeof i.files["README.md"]=="string"){const f=i.manifest.company?.name??o?.name??"Company",y=i.manifest.company?.description??null;s["README.md"]=Mt(i.manifest,P,f,y)}return s},[i,P,o?.name]),Re=(0,m.useMemo)(()=>i?ot(Ee(i.files,P,K),i.rootPath):0,[i,P,K]),de=(0,m.useMemo)(()=>pt(L),[L]),I=P.size,$=(0,m.useMemo)(()=>i?i.warnings.filter(s=>!/terminated agent/i.test(s)):[],[i]);function Te(s){E(d=>{const f=new Set(d);return f.has(s)?f.delete(s):f.add(s),f})}function Le(s){D(d=>({...d,[s]:!d[s]}))}function Me(s){const d=b.length>0,f=s.length>0;if(f&&!d&&(W.current=new Set(R)),_(s),f){const y=At(L,s);E(S=>{const v=new Set(S);for(const Y of y)v.add(Y);return v})}else d&&W.current&&(E(W.current),W.current=null)}function Oe(s){if(!i)return;const d=i.manifest.skills.find(f=>f.key===s||f.slug===s)?.path??`skills/${s}/SKILL.md`;d in i.files&&(V(d),E(f=>{const y=new Set(f);y.add("skills");const S=d.split("/").slice(0,-1);let v="";for(const Y of S)v=v?`${v}/${Y}`:Y,y.add(v);return y}))}function Fe(){!i||P.size===0||q.isPending||q.mutate()}function Ie(){M.current+=1,F.current?.abort(),F.current=null,A.reset(),U(!0)}if(!e)return(0,t.jsx)(z,{icon:B,message:"Select an organization to export."});if(A.isPending&&!i)return(0,t.jsx)(dt,{variant:"detail"});if(N&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview cancelled",message:"The preview request was cancelled. Your export settings are unchanged.",action:"Retry preview",onAction:O,hideActionIcon:!0});if(A.isError&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview failed",message:te(A.error),description:"Retry the preview. You do not need to reload this page.",action:"Retry preview",onAction:O,hideActionIcon:!0});if(!i)return(0,t.jsx)(z,{icon:B,title:"Export preview unavailable",message:"No export preview is loaded.",action:"Load preview",onAction:O,hideActionIcon:!0});const $e=w?K[w]??null:null;return(0,t.jsxs)("div",{className:"max-w-6xl",children:[(0,t.jsx)("div",{className:"sticky top-0 z-10 border-b border-border bg-background px-5 py-3",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4 text-sm",children:[(0,t.jsxs)("span",{className:"font-medium",children:[o?.name??"Organization"," export"]}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:["Exporting ",I.toLocaleString()," of ",de.toLocaleString()," file",de===1?"":"s",I>0&&` (~${tt(Re)})`]}),$.length>0&&(0,t.jsxs)("span",{className:"text-amber-500",children:[$.length," warning",$.length===1?"":"s"]})]}),(0,t.jsxs)(X,{size:"sm",onClick:Fe,disabled:I===0||q.isPending||A.isPending||A.isError||N,children:[(0,t.jsx)(st,{className:"mr-1.5 h-3.5 w-3.5"}),q.isPending?"Building export...":`Export ${I.toLocaleString()} file${I===1?"":"s"}`]})]})}),$.length>0&&(0,t.jsx)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:$.map(s=>(0,t.jsx)("div",{className:"text-xs text-amber-500",children:s},s))}),g&&g.warnings.length>0&&(0,t.jsxs)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:[(0,t.jsx)("h3",{className:"mb-1.5 text-xs font-medium",children:"Not included in this export"}),g.warnings.map(s=>(0,t.jsx)("div",{className:se("text-xs",s.severity==="blocker"?"font-medium text-destructive":"text-amber-500"),children:s.message},s.code))]}),(0,t.jsxs)("div",{className:"grid gap-4 xl:h-(--sz-calc-30) xl:grid-cols-(--gtc-25) xl:gap-0",children:[(0,t.jsxs)("aside",{className:"flex max-h-(--sz-24rem) flex-col overflow-hidden border-b border-border xl:max-h-none xl:border-b-0 xl:border-r",children:[(0,t.jsx)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Package files"})}),(0,t.jsxs)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsx)("h3",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"What to include"}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",role:"group","aria-label":"What to include",children:mt.map(s=>{const d=s==="attachments"&&!je(k),f=k[s]&&!d,y=Ne?.[s]??0,S=i.manifest.includes.issues||s!=="tasks"&&s!=="routines"&&s!=="attachments";return(0,t.jsxs)("label",{className:se("flex items-center gap-2 text-sm",d?"cursor-not-allowed opacity-50":"cursor-pointer"),title:d?"Attachments travel with tasks and routines; re-enable one of them to include attachments.":void 0,children:[(0,t.jsx)("input",{type:"checkbox",checked:f,disabled:d,onChange:()=>Le(s),className:"accent-foreground","data-export-category":s}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:ht[s]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:S?y.toLocaleString():"—"})]},s)})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Task and routine history is opt-in because it can be large."})]}),(0,t.jsx)("div",{className:"border-b border-border px-3 py-2 shrink-0",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2 py-1",children:[(0,t.jsx)(Ge,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("input",{type:"text",value:b,onChange:s=>Me(s.target.value),placeholder:"Search files...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-page-search-target":"true"})]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,t.jsx)(ft,{nodes:Ae,selectedFile:w,expandedDirs:R,onToggleDir:Te,onSelectFile:V,fileTones:Pe,showCheckboxes:!1,wrapLabels:!1}),ce>le&&!b&&(0,t.jsx)("div",{className:"px-4 py-2",children:(0,t.jsxs)("button",{type:"button",onClick:()=>T(s=>s+he),className:"w-full rounded-md border border-border px-3 py-1.5 text-xs text-muted-foreground hover:bg-accent/30 hover:text-foreground transition-colors",children:["Show more tasks (",le," of ",ce,")"]})})]})]}),(0,t.jsxs)("div",{className:"relative min-w-0 overflow-y-auto xl:pl-6",children:[(0,t.jsx)(Ft,{selectedFile:w,content:$e,allFiles:K,orgChartPreviewUrl:`/api/companies/${encodeURIComponent(e)}/org.svg`,onSkillClick:Oe}),A.isPending?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"status","aria-live":"polite","aria-busy":"true","data-export-preview-state":"loading",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsx)(Qe,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Updating export preview…"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large task histories can take a minute. You can untick Tasks or cancel this update."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:Ie,children:[(0,t.jsx)(Ze,{}),"Cancel update"]})]})}):N?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center","data-export-preview-state":"cancelled",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Preview update cancelled"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"The previous preview remains available. Retry when you are ready."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:O,children:[(0,t.jsx)(fe,{}),"Retry preview"]})]})}):A.isError?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"alert","data-export-preview-state":"error",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Export preview failed"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:te(A.error)})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:O,children:[(0,t.jsx)(fe,{}),"Retry preview"]})]})}):null]})]})]})}export{Xt as CompanyExport};
1
+ import{i as be}from"./rolldown-runtime-BQ-vy_Pv.js";import{Mn as Z,S as se,Tn as ee,U as Be,X as ze,Y as G,dr as De,jn as ue,pr as _e,tt as Ue,xt as We}from"./createLucideIcon-DhmuPH6P.js";import{it as qe,o as Ke,p as Ye}from"./router-D60XTPrE.js";import{Z as Ze}from"./mention-chips-BzQtzhDI.js";import{l as Ge,p as B}from"./zap-DjxJDVfV.js";import{g as Xe}from"./StatusIcon-DS8jybSt.js";import{r as He,t as z}from"./EmptyState-CRpkk2L_.js";import{t as X}from"./button-BM3Hk54-.js";import{t as pe}from"./MarkdownBody-DSalctm6.js";import{t as Ve}from"./agents-Cqpe1a3D.js";import{t as Je}from"./loader-circle-C_Leg-Lw.js";import{Ct as fe,Et as Qe,In as et,On as tt,St as st,Tt as nt,Vn as rt,a as ot,i as at,n as it,nn as ct,r as lt,t as we,tn as dt,tr as me,wt as ut,xt as pt,yr as ft}from"./index-CfGm8e4P.js";var m=be(_e(),1),mt=["agents","projects","skills","routines","tasks","attachments"],ht={agents:"Agents",projects:"Projects",skills:"Skills",routines:"Routines",tasks:"Tasks",attachments:"Attachments"};function xt(){return{agents:!0,projects:!0,skills:!0,routines:!0,tasks:!0,attachments:!0}}function je(e){return e.tasks||e.routines}function ye(e){const o=new Set;for(const a of e){if(!a.recurring)continue;const n=a.path.trim();if(!n)continue;o.add(n);const r=n.lastIndexOf("/");r>=0&&o.add(`${n.slice(0,r+1)}`)}return o}function gt(e,o){for(const a of o)if(e===a||e.startsWith(a))return!0;return!1}function bt(e){const o=new Set,a=new Set;for(const n of e)for(const r of n.attachments??[]){const c=r.sha256.trim().toLowerCase();c&&(n.recurring?o:a).add(c)}return{recurring:o,oneOff:a}}var wt=new Set(["agents","projects","skills","routines","tasks"]);function jt(e){const o=new Map;for(const a of e){const n=a.sha256.trim().toLowerCase();if(!n)continue;const r=o.get(n)??new Set,c=a.ownedBy&&a.ownedBy.length>0?a.ownedBy:["always"];for(const u of c)r.add(u);o.set(n,r)}return o}function yt(e,o){for(const a of e)if(!wt.has(a)||o[a])return!0;return!1}function ve(e,o){return e.startsWith("agents/")?"agents":e.startsWith("projects/")?"projects":e.startsWith("skills/")?"skills":e.startsWith("tasks/")?gt(e,o)?"routines":"tasks":e.startsWith("blobs/")?"attachments":null}function vt(e,o){const a=ye(o),n={agents:0,projects:0,skills:0,routines:0,tasks:0,attachments:0};for(const r of e){const c=ve(r,a);c&&(n[c]+=1)}return n}function St(e){const{filePaths:o,issues:a,categories:n}=e,r=ye(a),c=bt(a),u=jt(e.embeddedAssets??[]),p=n.attachments&&je(n),h=new Set;for(const l of o){const g=ve(l,r);if(g===null){h.add(l);continue}if(g==="attachments"){const i=l.slice(6).trim().toLowerCase(),x=u.get(i);if(x&&yt(x,n)){h.add(l);continue}if(!p)continue;const w=c.recurring.has(i),j=c.oneOff.has(i);!w&&!j?x||h.add(l):(j&&n.tasks||w&&n.routines)&&h.add(l);continue}n[g]&&h.add(l)}return h}function Se(e,o){if(!o.has(e))return o.add(e),e;let a=2;for(;;){const n=`${e}-${a}`;if(!o.has(n))return o.add(n),n;a+=1}}function kt(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=We(r.name)??"agent";a.set(r.id,Se(c,o))}return a}function Ct(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=Ue(r.name,r.name);a.set(r.id,Se(c,o))}return a}function Et(e){const o=kt(e.agents),a=Ct(e.projects),n={agents:e.orderedAgents.map(r=>o.get(r.id)).filter(r=>!!r),projects:e.orderedProjects.map(r=>a.get(r.id)).filter(r=>!!r)};return n.agents.length>0||n.projects.length>0?n:void 0}var t=be(De(),1);function ke(e){const o=new Set,a=new Set,n=new Set;for(const r of e){const c=r.match(/^agents\/([^/]+)\//);c&&o.add(c[1]);const u=r.match(/^projects\/([^/]+)\//);u&&a.add(u[1]);const p=r.match(/^tasks\/([^/]+)\//);p&&n.add(p[1])}return{agents:o,projects:a,tasks:n,routines:new Set(n)}}function Nt(e,o){const a=ke(o),n=e.split(`
2
+ `),r=[],c=new Set(["agents","projects","tasks","routines"]),u=new Set(["agents","projects"]);let p=null,h=null,l=!0,g=null,i=null,x=[],w=null,j=[];function T(){i!==null&&x.length>0&&(j.push(i),j.push(...x)),i=null,x=[]}function E(){T(),w!==null&&j.length>0&&(r.push(w),r.push(...j)),w=null,j=[]}for(const b of n){const _=b.match(/^([a-zA-Z_][\w-]*):\s*(.*)$/);if(_&&!b.startsWith(" ")){E(),h=null,l=!0;const C=_[0].split(":")[0];if(c.has(C)){p=C,w=b;continue}else if(C==="sidebar"){p=C,g=null,w=b;continue}else{p=null,r.push(b);continue}}if(p==="sidebar"){const C=b.match(/^ ([\w-]+):\s*$/);if(C&&!b.startsWith(" ")){T();const N=C[1];g=N&&u.has(N)?N:null,i=g?b:null;continue}const R=b.match(/^ - ["']?([^"'\n]+)["']?\s*$/);if(R&&g){const N=R[1],U=a[g];N&&U.has(N)&&x.push(b);continue}if(g){x.push(b);continue}}if(p&&c.has(p)){const C=b.match(/^ ([\w][\w-]*):\s*(.*)$/);if(C&&!b.startsWith(" ")){const R=C[1];h=R,l=a[p].has(R),l&&j.push(b);continue}if(h!==null){l&&j.push(b);continue}j.push(b);continue}r.push(b)}E();let k=r.join(`
3
+ `);const D=k.match(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*$/m);return D&&!o.has(D[1])&&(k=k.replace(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*\n?/m,"")),k}function Ce(e,o){if(!o)return e;const a=o.toLowerCase();return e.map(n=>{if(n.kind==="file")return n.name.toLowerCase().includes(a)||n.path.toLowerCase().includes(a)?n:null;const r=Ce(n.children,o);return r.length>0?{...n,children:r}:null}).filter(n=>n!==null)}function At(e,o){const a=new Set,n=o.toLowerCase();function r(c,u){if(c.kind==="file"){if(c.name.toLowerCase().includes(n)||c.path.toLowerCase().includes(n))for(const p of u)a.add(p)}else for(const p of c.children)r(p,[...u,c.path])}for(const c of e)r(c,[]);return a}var he=10;function Pt(e,o,a,n){let r=0,c=0;return{nodes:e.map(u=>{if(u.kind==="dir"&&u.name==="tasks"){r=u.children.length;const p=[],h=[],l=a.toLowerCase();for(const x of u.children){const w=ut([x],"file"),j=n!==null&&w.has(n),T=a&&(x.name.toLowerCase().includes(l)||x.path.toLowerCase().includes(l)||[...w].some(E=>E.toLowerCase().includes(l)));j||T?p.push(x):h.push(x)}const g=Math.max(0,o-p.length),i=[...p,...h.slice(0,g)];return c=i.length,{...u,children:i}}return u}),totalTaskChildren:r,visibleTaskChildren:c}}function Ee(e,o,a){const n={};for(const r of Object.keys(e))o.has(r)&&(n[r]=a[r]??e[r]);return n}function Tt(e,o,a){const n=Ee(e.files,o,a),r=at(n,e.rootPath),c=new ArrayBuffer(r.byteLength);new Uint8Array(c).set(r);const u=new Blob([c],{type:"application/zip"}),p=URL.createObjectURL(u),h=document.createElement("a");h.href=p,h.download=`${e.rootPath}.zip`,document.body.appendChild(h),h.click(),h.remove(),window.setTimeout(()=>URL.revokeObjectURL(p),1e3)}function Rt({data:e,onSkillClick:o}){return(0,t.jsx)("div",{className:"rounded-md border border-border bg-accent/20 px-4 py-3 mb-4",children:(0,t.jsx)("dl",{className:"grid grid-cols-(--gtc-5) gap-x-4 gap-y-1.5 text-sm",children:Object.entries(e).map(([a,n])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-muted-foreground whitespace-nowrap py-0.5",children:pt[a]??a}),(0,t.jsx)("dd",{className:"py-0.5",children:Array.isArray(n)?(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(r=>(0,t.jsx)("button",{type:"button",className:se("inline-flex items-center rounded-md border border-border bg-background px-2 py-0.5 text-xs",a==="skills"&&o&&"cursor-pointer hover:bg-accent/50 hover:border-foreground/30 transition-colors"),onClick:()=>a==="skills"&&o?.(r),children:r},r))}):(0,t.jsx)("span",{children:n})})]},a))})})}var Ot={ceo:"CEO",cto:"CTO",cmo:"CMO",cfo:"CFO",coo:"COO",vp:"VP",manager:"Manager",engineer:"Engineer",agent:"Agent"};function Lt(e,o,a,n){const r=ke(o),c=e.agents.filter(i=>r.agents.has(i.slug)),u=e.projects.filter(i=>r.projects.has(i.slug)),p=e.issues.filter(i=>r.tasks.has(i.slug)),h=e.skills.filter(i=>[...o].some(x=>x.startsWith(`skills/${i.key}/`)||x.startsWith("skills/")&&x.includes(`/${i.slug}/`))),l=[];l.push(`# ${a}`),l.push(""),n&&(l.push(`> ${n}`),l.push("")),c.length>0&&(l.push("![Org Chart](images/org-chart.png)"),l.push("")),l.push("## What's Inside"),l.push(""),l.push("This is an [Agent Company](https://paperclip.ing) package."),l.push("");const g=[];if(c.length>0&&g.push(["Agents",c.length]),u.length>0&&g.push(["Projects",u.length]),h.length>0&&g.push(["Skills",h.length]),p.length>0&&g.push(["Tasks",p.length]),g.length>0){l.push("| Content | Count |"),l.push("|---------|-------|");for(const[i,x]of g)l.push(`| ${i} | ${x} |`);l.push("")}if(c.length>0){l.push("### Agents"),l.push(""),l.push("| Agent | Role | Reports To |"),l.push("|-------|------|------------|");for(const i of c){const x=Ot[i.role]??i.role,w=i.reportsToSlug??"—";l.push(`| ${i.name} | ${x} | ${w} |`)}l.push("")}if(u.length>0){l.push("### Projects"),l.push("");for(const i of u){const x=i.description?` — ${i.description}`:"";l.push(`- **${i.name}**${x}`)}l.push("")}return l.push("## Getting Started"),l.push(""),l.push("```bash"),l.push("npx paperclipai company import this-github-url-or-folder"),l.push("```"),l.push(""),l.push("See [Paperclip](https://paperclip.ing) for more information."),l.push(""),l.push("---"),l.push(`Exported from [Paperclip](https://paperclip.ing) on ${new Date().toISOString().split("T")[0]}`),l.push(""),l.join(`
4
+ `)}function Mt(e){const{src:o,selectedFile:a,allFiles:n,orgChartPreviewUrl:r}=e;if(/^(?:https?:|data:)/i.test(o))return null;if(o.replace(/^\.\//,"")==="images/org-chart.png"&&r)return r;const c=(a.includes("/")?a.slice(0,a.lastIndexOf("/")+1):"")+o,u=n[c]??n[o];return u?we(c in n?c:o,u):null}function Ft({selectedFile:e,content:o,allFiles:a,orgChartPreviewUrl:n,onSkillClick:r}){if(!e||o===null)return(0,t.jsx)(z,{icon:B,message:"Select a file to preview its contents."});const c=it(o),u=e.endsWith(".md")&&c!==null,p=u&&c?Qe(c):null,h=lt(e,o)?we(e,o):null,l=u?g=>Mt({src:g,selectedFile:e,allFiles:a,orgChartPreviewUrl:n}):void 0;return(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"border-b border-border px-5 py-3",children:(0,t.jsx)("div",{className:"truncate font-mono text-sm",children:e})}),(0,t.jsx)("div",{className:"min-h-(--sz-560px) px-5 py-5",children:p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Rt,{data:p.data,onSkillClick:r}),p.body.trim()&&(0,t.jsx)(pe,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:p.body})]}):u?(0,t.jsx)(pe,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:c??""}):h?(0,t.jsx)("div",{className:"flex min-h-(--sz-520px) items-center justify-center rounded-lg border border-border bg-accent/10 p-6",children:(0,t.jsx)("img",{src:h,alt:e,className:"max-h-(--sz-480px) max-w-full object-contain"})}):c!==null?(0,t.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words border-0 bg-transparent p-0 font-mono text-sm text-foreground",children:(0,t.jsx)("code",{children:c})}):(0,t.jsx)("div",{className:"rounded-lg border border-border bg-accent/10 px-4 py-3 text-sm text-muted-foreground",children:"Binary asset preview is not available for this file type."})})]})}function xe(e){const o="/company/export/files/",a=Ye(e),n=a.indexOf(o);return n===-1?null:decodeURIComponent(a.slice(n+22))||null}function ge(e){const o=e.split("/").slice(0,-1),a=[];let n="";for(const r of o)n=n?`${n}/${r}`:r,a.push(n);return a}function It(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}function te(e){return e instanceof Error?e.message:"Failed to load export data."}function Xt(){const{selectedCompanyId:e,selectedCompany:o}=Be(),{setBreadcrumbs:a}=He(),{pushToast:n}=rt(),r=Ke(),c=qe(),u=(0,m.useRef)(xe(c.pathname)),{data:p}=Z({queryKey:G.auth.session,queryFn:()=>ze.getSession()}),{data:h=[]}=Z({queryKey:G.agents.list(e),queryFn:()=>Ve.list(e),enabled:!!e}),{data:l=[]}=Z({queryKey:G.projects.list(e),queryFn:()=>Xe.list(e),enabled:!!e}),{data:g}=Z({queryKey:G.companies.exportFidelity(e),queryFn:()=>ee.exportFidelity(e),enabled:!!e}),[i,x]=(0,m.useState)(null),[w,j]=(0,m.useState)(null),[T,E]=(0,m.useState)(new Set),[k,D]=(0,m.useState)(()=>({...xt(),tasks:!1,routines:!1,attachments:!1})),[b,_]=(0,m.useState)(""),[C,R]=(0,m.useState)(he),[N,U]=(0,m.useState)(!1),W=(0,m.useRef)(null),F=(0,m.useRef)(null),L=(0,m.useRef)(0),ne=(0,m.useRef)(null),re=p?.user?.id??p?.session?.userId??null,H=(0,m.useMemo)(()=>h.filter(s=>s.status!=="terminated"),[h]),V=(0,m.useMemo)(()=>l,[l]),{orderedAgents:oe}=et({agents:H,companyId:e,userId:re}),{orderedProjects:ae}=tt({projects:V,companyId:e,userId:re}),ie=(0,m.useMemo)(()=>Et({agents:H,orderedAgents:oe,projects:V,orderedProjects:ae}),[oe,ae,H,V]),J=k.tasks||k.routines,Q=(0,m.useCallback)((s,d=!1)=>{j(s),s?r(`/company/export/files/${encodeURI(s)}`,{replace:d}):r("/company/export",{replace:d})},[r]);(0,m.useEffect)(()=>{if(!i)return;const s=xe(c.pathname);s&&s in i.files&&s!==w?(j(s),E(d=>{const f=new Set(d);for(const y of ge(s))f.add(y);return f})):!s&&w&&j(null)},[c.pathname,i]),(0,m.useEffect)(()=>{a([{label:o?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Export"}])},[o?.name,a]);const A=ue({mutationFn:({includeIssues:s,includeSkills:d,signal:f})=>ee.exportPreview(e,{include:{company:!0,agents:!0,projects:!0,issues:s,skills:d},sidebarOrder:ie},{signal:f}),onSuccess:(s,d)=>{if(d.requestId!==L.current)return;x(s);const f=fe(s.files),y=new Set;for(const v of f)v.kind==="dir"&&v.name!=="tasks"&&y.add(v.path);const S=u.current;if(S&&S in s.files){j(S);const v=ge(S);E(new Set([...y,...v]))}else{const v="README.md"in s.files?"README.md":Object.keys(s.files)[0];v&&Q(v,!0),E(y)}},onError:(s,d)=>{d.requestId!==L.current||It(s)||n({tone:"error",title:"Export failed",body:te(s)})}});function M(){if(!e)return;F.current?.abort();const s=new AbortController,d=L.current+1;L.current=d,F.current=s,U(!1),A.mutate({includeIssues:J,includeSkills:k.skills,requestId:d,signal:s.signal})}const q=ue({mutationFn:()=>ee.exportBundle(e,{include:{company:!0,agents:!0,projects:!0,issues:J,skills:k.skills},selectedFiles:Array.from(P).sort(),sidebarOrder:ie}),onSuccess:s=>{const d=new Set(Object.keys(s.files));Tt(s,d,s.files),n({tone:"success",title:"Export downloaded",body:`${d.size} file${d.size===1?"":"s"} exported as ${s.rootPath}.zip`})},onError:s=>{n({tone:"error",title:"Export failed",body:s instanceof Error?s.message:"Failed to build export package."})}});(0,m.useEffect)(()=>{e&&(ne.current!==e&&(ne.current=e,x(null),j(null)),M())},[e,J,k.skills]),(0,m.useEffect)(()=>()=>{L.current+=1,F.current?.abort()},[]);const O=(0,m.useMemo)(()=>i?fe(i.files):[],[i]),P=(0,m.useMemo)(()=>i?St({filePaths:Object.keys(i.files),issues:i.manifest.issues,categories:k,embeddedAssets:i.manifest.embeddedAssets??[]}):new Set,[i,k]),Ne=(0,m.useMemo)(()=>i?vt(Object.keys(i.files),i.manifest.issues):null,[i]),{displayTree:Ae,totalTaskChildren:ce,visibleTaskChildren:le}=(0,m.useMemo)(()=>{let s=O;b&&(s=Ce(s,b));const d=Pt(s,C,b,w);return{displayTree:d.nodes,totalTaskChildren:d.totalTaskChildren,visibleTaskChildren:d.visibleTaskChildren}},[O,b,C,w]),Pe=(0,m.useMemo)(()=>{const s={};function d(f){if(f.kind==="file"){const S=P.has(f.path);return S||(s[f.path]="muted"),S}let y=!1;for(const S of f.children)d(S)&&(y=!0);return y||(s[f.path]="muted"),y}for(const f of O)d(f);return s},[O,P]),K=(0,m.useMemo)(()=>{if(!i)return{};const s={...i.files},d=i.paperclipExtensionPath;if(d&&typeof i.files[d]=="string"&&(s[d]=Nt(i.files[d],P)),typeof i.files["README.md"]=="string"){const f=i.manifest.company?.name??o?.name??"Company",y=i.manifest.company?.description??null;s["README.md"]=Lt(i.manifest,P,f,y)}return s},[i,P,o?.name]),Te=(0,m.useMemo)(()=>i?ot(Ee(i.files,P,K),i.rootPath):0,[i,P,K]),de=(0,m.useMemo)(()=>nt(O),[O]),I=P.size,$=(0,m.useMemo)(()=>i?i.warnings.filter(s=>!/terminated agent/i.test(s)):[],[i]);function Re(s){E(d=>{const f=new Set(d);return f.has(s)?f.delete(s):f.add(s),f})}function Oe(s){D(d=>({...d,[s]:!d[s]}))}function Le(s){const d=b.length>0,f=s.length>0;if(f&&!d&&(W.current=new Set(T)),_(s),f){const y=At(O,s);E(S=>{const v=new Set(S);for(const Y of y)v.add(Y);return v})}else d&&W.current&&(E(W.current),W.current=null)}function Me(s){if(!i)return;const d=i.manifest.skills.find(f=>f.key===s||f.slug===s)?.path??`skills/${s}/SKILL.md`;d in i.files&&(Q(d),E(f=>{const y=new Set(f);y.add("skills");const S=d.split("/").slice(0,-1);let v="";for(const Y of S)v=v?`${v}/${Y}`:Y,y.add(v);return y}))}function Fe(){!i||P.size===0||q.isPending||q.mutate()}function Ie(){L.current+=1,F.current?.abort(),F.current=null,A.reset(),U(!0)}if(!e)return(0,t.jsx)(z,{icon:B,message:"Select an organization to export."});if(A.isPending&&!i)return(0,t.jsx)(dt,{variant:"detail"});if(N&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview cancelled",message:"The preview request was cancelled. Your export settings are unchanged.",action:"Retry preview",onAction:M,hideActionIcon:!0});if(A.isError&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview failed",message:te(A.error),description:"Retry the preview. You do not need to reload this page.",action:"Retry preview",onAction:M,hideActionIcon:!0});if(!i)return(0,t.jsx)(z,{icon:B,title:"Export preview unavailable",message:"No export preview is loaded.",action:"Load preview",onAction:M,hideActionIcon:!0});const $e=w?K[w]??null:null;return(0,t.jsxs)("div",{className:"max-w-6xl",children:[(0,t.jsx)("div",{className:"sticky top-0 z-10 border-b border-border bg-background px-5 py-3",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4 text-sm",children:[(0,t.jsxs)("span",{className:"font-medium",children:[o?.name??"Organization"," export"]}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:["Exporting ",I.toLocaleString()," of ",de.toLocaleString()," file",de===1?"":"s",I>0&&` (~${ct(Te)})`]}),$.length>0&&(0,t.jsxs)("span",{className:"text-amber-500",children:[$.length," warning",$.length===1?"":"s"]})]}),(0,t.jsxs)(X,{size:"sm",onClick:Fe,disabled:I===0||q.isPending||A.isPending||A.isError||N,children:[(0,t.jsx)(ft,{className:"mr-1.5 h-3.5 w-3.5"}),q.isPending?"Building export...":`Export ${I.toLocaleString()} file${I===1?"":"s"}`]})]})}),$.length>0&&(0,t.jsx)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:$.map(s=>(0,t.jsx)("div",{className:"text-xs text-amber-500",children:s},s))}),g&&g.warnings.length>0&&(0,t.jsxs)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:[(0,t.jsx)("h3",{className:"mb-1.5 text-xs font-medium",children:"Not included in this export"}),g.warnings.map(s=>(0,t.jsx)("div",{className:se("text-xs",s.severity==="blocker"?"font-medium text-destructive":"text-amber-500"),children:s.message},s.code))]}),(0,t.jsxs)("div",{className:"grid gap-4 xl:h-(--sz-calc-30) xl:grid-cols-(--gtc-25) xl:gap-0",children:[(0,t.jsxs)("aside",{className:"flex max-h-(--sz-24rem) flex-col overflow-hidden border-b border-border xl:max-h-none xl:border-b-0 xl:border-r",children:[(0,t.jsx)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Package files"})}),(0,t.jsxs)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsx)("h3",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"What to include"}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",role:"group","aria-label":"What to include",children:mt.map(s=>{const d=s==="attachments"&&!je(k),f=k[s]&&!d,y=Ne?.[s]??0,S=i.manifest.includes.issues||s!=="tasks"&&s!=="routines"&&s!=="attachments";return(0,t.jsxs)("label",{className:se("flex items-center gap-2 text-sm",d?"cursor-not-allowed opacity-50":"cursor-pointer"),title:d?"Attachments travel with tasks and routines; re-enable one of them to include attachments.":void 0,children:[(0,t.jsx)("input",{type:"checkbox",checked:f,disabled:d,onChange:()=>Oe(s),className:"accent-foreground","data-export-category":s}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:ht[s]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:S?y.toLocaleString():"—"})]},s)})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Task and routine history is opt-in because it can be large."})]}),(0,t.jsx)("div",{className:"border-b border-border px-3 py-2 shrink-0",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2 py-1",children:[(0,t.jsx)(Ge,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("input",{type:"text",value:b,onChange:s=>Le(s.target.value),placeholder:"Search files...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-page-search-target":"true"})]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,t.jsx)(st,{nodes:Ae,selectedFile:w,expandedDirs:T,onToggleDir:Re,onSelectFile:Q,fileTones:Pe,showCheckboxes:!1,wrapLabels:!1}),ce>le&&!b&&(0,t.jsx)("div",{className:"px-4 py-2",children:(0,t.jsxs)("button",{type:"button",onClick:()=>R(s=>s+he),className:"w-full rounded-md border border-border px-3 py-1.5 text-xs text-muted-foreground hover:bg-accent/30 hover:text-foreground transition-colors",children:["Show more tasks (",le," of ",ce,")"]})})]})]}),(0,t.jsxs)("div",{className:"relative min-w-0 overflow-y-auto xl:pl-6",children:[(0,t.jsx)(Ft,{selectedFile:w,content:$e,allFiles:K,orgChartPreviewUrl:`/api/companies/${encodeURIComponent(e)}/org.svg`,onSkillClick:Me}),A.isPending?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"status","aria-live":"polite","aria-busy":"true","data-export-preview-state":"loading",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsx)(Je,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Updating export preview…"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large task histories can take a minute. You can untick Tasks or cancel this update."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:Ie,children:[(0,t.jsx)(Ze,{}),"Cancel update"]})]})}):N?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center","data-export-preview-state":"cancelled",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Preview update cancelled"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"The previous preview remains available. Retry when you are ready."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:M,children:[(0,t.jsx)(me,{}),"Retry preview"]})]})}):A.isError?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"alert","data-export-preview-state":"error",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Export preview failed"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:te(A.error)})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:M,children:[(0,t.jsx)(me,{}),"Retry preview"]})]})}):null]})]})]})}export{Xt as CompanyExport};