@penclipai/ui 2026.1018.0-beta.0 → 2026.1018.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{Agents.production-6YQPgvxV.js → Agents.production-BmTOyean.js} +2 -2
- package/dist/assets/{CompanyActivity.production-Bmz10hg6.js → CompanyActivity.production-Bl2T4BPB.js} +1 -1
- package/dist/assets/{CompanyExport-DK9kfuFj.js → CompanyExport-Dl3Ufezx.js} +1 -1
- package/dist/assets/{CompanySkills.production-BzbeiOIw.js → CompanySkills.production-DB0MkLfO.js} +1 -1
- package/dist/assets/{OrgChart.production-DN2hGvMu.js → OrgChart.production-0s66cFiu.js} +1 -1
- package/dist/assets/{RoutineDetail.production-CeeDo7Fb.js → RoutineDetail.production-Ct7EKEYL.js} +1 -1
- package/dist/assets/{Routines.production-CGaCh7Rf.js → Routines.production-x8BhoXpx.js} +1 -1
- package/dist/assets/{definition-BswAglFI.js → definition-JhS3KbPG.js} +1 -1
- package/dist/assets/{index-Dt9g_rra.js → index-ChreIWPq.js} +4 -4
- package/dist/index.html +1 -1
- package/dist/sw.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
var Ae=Object.defineProperty;var a=(e,n)=>Ae(e,"name",{value:n,configurable:!0});import{i as ie}from"./rolldown-runtime-ZpX3ckPj.js";import{B as le,Ft as c,G as k,Sa as Se,da as z,ji as j,lt as Ee,mt as _e,ni as Le,ua as Me,xt as y,z as K}from"./agent-avatar-url-CdlBp9p9.js";import{t as Te}from"./preload-helper-Bq-5Tx7W.js";import{Ln as ke,ct as qe,f as Pe,i as V,n as Re,r as se,s as oe,yt as Fe}from"./BreadcrumbContext-NYKl3jAM.js";import{m as ce}from"./alert-dialog-CvROCHSj.js";import{t as ue}from"./AgentAvatar-CTdkXzmh.js";import{t as $e}from"./tabs-B2h2Tuem.js";import{t as ne}from"./bot-DGyCo7vt.js";import{i as Be,o as Ke,t as Ve}from"./heartbeats-CtWMFcNw.js";import{i as De,n as Oe,t as ae}from"./environments-DMLR_apk.js";import{t as re}from"./EmptyState-BUS2fndv.js";import{t as ze}from"./PageSkeleton-DaSQo8P8.js";import{Ft as D,Gt as Ge,Kt as de,Lt as Ue,Ot as He,Rt as Qe,Vt as We,Wt as Xe,Xt as Ye,Yt as me,Zt as Ze,qt as Je}from"./index-Dt9g_rra.js";var m=ie(Se(),1),t=ie(Me(),1),pe=Le,et=(0,m.lazy)(()=>Te(()=>import("./index-Dt9g_rra.js").then(e=>e.gt).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,33,34,35,36,37,38,39,40,41,42]))),tt=["all","active","paused","error","builtin"],st=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"paused",label:"Paused"},{value:"error",label:"Error"},{value:"builtin",label:"Built-in"}];function nt(e){return tt.includes(e)}a(nt,"isFilterTab");var G={label:"Local",detail:"Paperclip host",title:"Local - Paperclip host"},ge={label:"—",detail:"Loading environment",title:"Loading environment"},xe=new Set(["terminated","pending_approval"]);function fe(e,n){return n==="all"?!0:n==="active"?e==="active"||e==="running"||e==="idle":n==="paused"?e==="paused":n==="error"?e==="error":!0}a(fe,"matchesFilter");function at(e,n,i){return e.filter(r=>xe.has(r.status)?!1:n==="builtin"?i.has(r.id):fe(r.status,n)).sort((r,o)=>r.name.localeCompare(o.name))}a(at,"filterAgents");function rt(e){const n=e.adapterConfig?.model;if(typeof n!="string")return null;const i=n.trim();return i.length>0?i:null}a(rt,"getConfiguredModel");function it(e){return e==="ssh"?"SSH":e.charAt(0).toUpperCase()+e.slice(1)}a(it,"formatEnvironmentDriver");function lt(e,n){const i=typeof e.config.provider=="string"?e.config.provider.trim():"";return i?n?.sandboxProviders?.[i]?.displayName??i:"Sandbox"}a(lt,"getSandboxProviderLabel");function ot(e,n){const i=Ue(e)?"Managed by Paperclip":e.driver==="sandbox"?`${lt(e,n)} sandbox provider`:e.driver==="local"?"Paperclip host":it(e.driver);return{label:e.name,detail:i,title:`${e.name} - ${i}`}}a(ot,"describeEnvironment");function ct(e){return{label:"Unknown environment",detail:e.slice(0,8),title:`Unknown environment - ${e}`}}a(ct,"describeMissingEnvironment");function ut(e,n,i,r){const o=e.defaultEnvironmentId??i;if(!o)return G;const p=n.get(o);return p?ot(p,r):ct(o)}a(ut,"resolveAgentEnvironment");function he(e,n,i){return e.reduce((r,o)=>{const p=he(o.reports,n,i);return xe.has(o.status)?(r.push(...p),r):(((n==="builtin"?i.has(o.id):fe(o.status,n))||p.length>0)&&r.push({...o,reports:p}),r)},[]).sort((r,o)=>r.name.localeCompare(o.name))}a(he,"filterOrgTree");function Ct(){z();const{selectedCompanyId:e}=_e(),{openNewAgent:n}=Be(),{setBreadcrumbs:i}=Re(),r=Pe(),o=ke(),{isMobile:p}=De(),w=o.pathname.split("/").pop()??"all",b=nt(w)?w:"all",[E,I]=(0,m.useState)("org"),C=p,l=C?"list":E,{data:d}=j({queryKey:y.instance.settings,queryFn:a(()=>Oe.get(),"queryFn"),enabled:!!e}),g=d?.experimental.enableBuiltInAgents===!0,h=b==="builtin"&&!g?"all":b,q=(0,m.useMemo)(()=>st.filter(s=>s.value!=="builtin"||g),[g]),{data:v}=j({queryKey:y.builtInAgents.list(e),queryFn:a(()=>Ye.list(e),"queryFn"),enabled:!!e&&g}),_=(0,m.useMemo)(()=>{const s=new Map;if(!g)return s;for(const u of v??[])u.agentId&&s.set(u.agentId,u);return s},[v,g]),U=(0,m.useMemo)(()=>new Set(_.keys()),[_]),[P,R]=(0,m.useState)(null),{data:x,isLoading:je,error:H}=j({queryKey:y.agents.list(e),queryFn:a(()=>se.list(e),"queryFn"),enabled:!!e}),{data:A}=j({queryKey:y.org(e),queryFn:a(()=>se.org(e),"queryFn"),enabled:!!e&&l==="org"}),L=d?.experimental.enableEnvironments===!0,{data:S}=j({queryKey:y.environments.list(e),queryFn:a(()=>ae.list(e),"queryFn"),enabled:!!e&&L}),{data:Q}=j({queryKey:y.environments.capabilities(e),queryFn:a(()=>ae.capabilities(e),"queryFn"),enabled:!!e&&L}),W=[...y.liveRuns(e),"agents-page"],F=Ge({companyId:e,resourceKey:"live-runs:agents-page",queryKey:W,enabled:!!e,refetchInterval:15e3,leaderOnly:!0}),{data:$,dataUpdatedAt:ye}=j({queryKey:W,queryFn:a(()=>Ve.liveRunsForCompany(e),"queryFn"),enabled:F.enabled,refetchInterval:F.refetchInterval});Xe(F,$,ye);const X=Je(e),M=(0,m.useMemo)(()=>{const s=new Map;for(const u of $??[]){if(u.status!=="running"&&u.status!=="queued")continue;const f=s.get(u.agentId);if(f){f.liveCount+=1;continue}s.set(u.agentId,{runId:u.id,liveCount:1})}return s},[$]),Ne=(0,m.useMemo)(()=>{const s=new Map;for(const u of x??[])s.set(u.id,u);return s},[x]),Y=(0,m.useMemo)(()=>{const s=new Map;for(const u of S??[])s.set(u.id,u);return s},[S]),Z=(0,m.useMemo)(()=>{const s=new Map;for(const u of x??[])s.set(u.id,ut(u,Y,d?.defaultEnvironmentId??null,Q));return s},[x,Y,Q,d?.defaultEnvironmentId]);if((0,m.useEffect)(()=>{i([{label:c("Agents")}])},[i]),(0,m.useEffect)(()=>{e&&b==="builtin"&&d&&!g&&r("/agents/all",{replace:!0})},[g,d,r,b,e]),!e)return(0,t.jsx)(re,{icon:ne,message:c("Select a company to view agents.")});if(je)return(0,t.jsx)(ze,{variant:"list"});const N=at(x??[],h,U),B=he(A??[],h,U),J=L&&S===void 0,ee=L&&(S===void 0||S.length>1),we=a(s=>J?ge:Z.get(s)??G,"resolveRenderedEnvironment"),Ie=a(s=>{const u=s.orgChainHealth?.status==="invalid_org_chain",f=_.get(s.id),Ce=f?.status==="needs_setup"||f?.status==="pending_approval",T=f&&Ce?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(me,{status:f.status}),f.status==="needs_setup"&&(0,t.jsx)("span",{onClick:a(te=>{te.preventDefault(),te.stopPropagation()},"onClick"),children:(0,t.jsx)(V,{size:"xs",variant:"outline",onClick:a(()=>R(f),"onClick"),children:c("Set up")})})]}):null;return(0,t.jsx)(He,{title:s.name,titleAccessory:(0,t.jsx)(Ze,{agentId:s.id,companyId:s.companyId}),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:`${c(`agentRole.${s.role}`,{defaultValue:pe[s.role]??s.role})}${s.title?` - ${s.title}`:""}`,to:le(s),className:k("group",s.pausedAt&&h!=="paused"?"opacity-50":"",de(X.data,"agent",s.id)==="left"?"sm:text-foreground/55":""),leading:u?(0,t.jsx)(ce,{className:"h-3.5 w-3.5 text-amber-500","aria-label":c("agents.invalidReportingChain")}):(0,t.jsx)(ue,{agent:s,size:32}),secondaryRow:T?(0,t.jsx)("div",{className:"xl:hidden flex flex-wrap items-center gap-1.5",children:T}):void 0,meta:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[T&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-1.5",children:T}),(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(be,{agent:s,environment:we(s.id),showEnvironment:ee})})]}),metaSpacerClassName:"hidden xl:block",trailing:(0,t.jsx)("div",{className:"flex items-center gap-3",children:(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[M.has(s.id)&&(0,t.jsx)(O,{agentRef:K(s),runId:M.get(s.id).runId,liveCount:M.get(s.id).liveCount}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(D,{status:s.status})})]})})},s.id)},"renderAgentRow");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)($e,{value:h,onValueChange:a(s=>r(`/agents/${s}`),"onValueChange"),children:(0,t.jsx)(We,{items:q,value:h,onValueChange:a(s=>r(`/agents/${s}`),"onValueChange")})}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!C&&(0,t.jsxs)("div",{className:"flex items-center border border-border",role:"group","aria-label":c("View mode"),children:[(0,t.jsx)("button",{className:k("p-1.5 transition-colors",l==="list"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:a(()=>I("list"),"onClick"),title:c("List view"),"aria-label":c("List view"),"aria-pressed":l==="list",children:(0,t.jsx)(Ke,{className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{className:k("p-1.5 transition-colors",l==="org"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:a(()=>I("org"),"onClick"),title:c("agents.orgChartView"),"aria-label":c("agents.orgChartView"),"aria-pressed":l==="org",children:(0,t.jsx)(Fe,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)(V,{size:"sm",variant:"outline",onClick:n,children:[(0,t.jsx)(qe,{className:"h-3.5 w-3.5 mr-1.5"}),c("New Agent")]})]})]}),N.length>0&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[N.length," ",c("agent"),N.length!==1?"s":""]}),H&&(0,t.jsx)("p",{className:"text-sm text-destructive",children:H.message}),x&&x.length===0&&(0,t.jsx)(re,{icon:ne,message:c("Create your first agent to get started."),action:c("New Agent"),onAction:n}),l==="list"&&N.length>0&&(0,t.jsx)("div",{children:N.map(Ie)}),l==="list"&&x&&x.length>0&&N.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("agents.noStatusMatches")}),l==="org"&&B.length>0&&(0,t.jsx)("div",{className:"py-1",children:B.map(s=>(0,t.jsx)(ve,{node:s,depth:0,agentMap:Ne,liveRunByAgent:M,environmentByAgentId:Z,environmentDataLoading:J,showEnvironment:ee,tab:h,memberships:X.data,builtInByAgentId:_,onConfigureBuiltIn:R},s.id))}),l==="org"&&A&&A.length>0&&B.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("agents.noStatusMatches")}),l==="org"&&A&&A.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("No organizational hierarchy defined.")}),P&&e&&(0,t.jsx)(m.Suspense,{fallback:null,children:(0,t.jsx)(et,{companyId:e,state:P,open:P!==null,onOpenChange:a(s=>{s||R(null)},"onOpenChange")})})]})}a(Ct,"Agents");function ve({node:e,depth:n,agentMap:i,liveRunByAgent:r,environmentByAgentId:o,environmentDataLoading:p,showEnvironment:w,tab:b,memberships:E,builtInByAgentId:I,onConfigureBuiltIn:C}){z();const l=i.get(e.id),d=I.get(e.id),g=d?.status==="needs_setup"||d?.status==="pending_approval",h=!!(l&&l.orgChainHealth?.status==="invalid_org_chain"),q=de(E,"agent",e.id);return(0,t.jsxs)("div",{style:{paddingLeft:n*24},children:[(0,t.jsxs)(oe,{to:l?le(l):`/agents/${e.id}`,className:k("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&&b!=="paused"&&"opacity-50",q==="left"&&"sm:text-foreground/55"),children:[h?(0,t.jsx)(ce,{className:"h-3.5 w-3.5 shrink-0 text-amber-500","aria-label":c("agents.invalidReportingChain")}):(0,t.jsx)(ue,{agent:l??e,size:24}),(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:[c(`agentRole.${e.role}`,{defaultValue:pe[e.role]??e.role}),l?.title?` - ${l.title}`:""]})]}),d&&g&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,t.jsx)(me,{status:d.status}),d.status==="needs_setup"&&(0,t.jsx)("span",{onClick:a(v=>{v.preventDefault(),v.stopPropagation()},"onClick"),children:(0,t.jsx)(V,{size:"xs",variant:"outline",onClick:a(()=>C(d),"onClick"),children:c("Set up")})})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[(0,t.jsx)("span",{className:"sm:hidden",children:r.has(e.id)?(0,t.jsx)(O,{agentRef:l?K(l):e.id,runId:r.get(e.id).runId,liveCount:r.get(e.id).liveCount}):(0,t.jsx)(D,{status:e.status})}),(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[r.has(e.id)&&(0,t.jsx)(O,{agentRef:l?K(l):e.id,runId:r.get(e.id).runId,liveCount:r.get(e.id).liveCount}),l&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(be,{agent:l,environment:p?ge:o.get(l.id)??G,showEnvironment:w})}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(D,{status:e.status})})]})]})]}),e.reports&&e.reports.length>0&&(0,t.jsx)("div",{className:"border-l border-border ml-4",children:e.reports.map(v=>(0,t.jsx)(ve,{node:v,depth:n+1,agentMap:i,liveRunByAgent:r,environmentByAgentId:o,environmentDataLoading:p,showEnvironment:w,tab:b,memberships:E,builtInByAgentId:I,onConfigureBuiltIn:C},v.id))})]})}a(ve,"OrgTreeNode");function be({agent:e,environment:n,showEnvironment:i}){const r=rt(e),o=Qe(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:r??void 0,children:r??"—"}),(0,t.jsx)("div",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground/70",title:o,children:o})]}),i&&(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?Ee(e.lastHeartbeatAt):"—"})]})}a(be,"AgentMetaColumns");function O({agentRef:e,runId:n,liveCount:i}){return z(),(0,t.jsxs)(oe,{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(r=>r.stopPropagation(),"onClick"),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:[c("Live"),i>1?` (${i})`:""]})]})}a(O,"LiveRunIndicator");export{Ct as Agents};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-ChreIWPq.js","assets/rolldown-runtime-ZpX3ckPj.js","assets/agent-avatar-url-CdlBp9p9.js","assets/preload-helper-Bq-5Tx7W.js","assets/BreadcrumbContext-NYKl3jAM.js","assets/label-D53vUXGD.js","assets/mention-chips-BGwhkP2B.js","assets/dist-C-EpPiIf.js","assets/dist-CX-fdfZ5.js","assets/checkbox-DSDEd9xJ.js","assets/check-DaEgimxq.js","assets/clipboard-BcdF-0DW.js","assets/RoutineRunVariablesDialog-BzNyiJ8N.js","assets/alert-dialog-CvROCHSj.js","assets/AgentAvatar-CTdkXzmh.js","assets/MarkdownEditor-C2xaZOWa.js","assets/dist-DOjxx2DZ.js","assets/dist-BrgyPN31.js","assets/StatusIcon-Cw0scYdd.js","assets/badge-DHxSYw-Q.js","assets/bot-DGyCo7vt.js","assets/select-b1sMyjd5.js","assets/ToastContext-CkRLuVem.js","assets/sheet-0KNjJ51X.js","assets/heartbeats-CtWMFcNw.js","assets/useHiddenSettings-BBSXECTf.js","assets/health-BSUrv7Eo.js","assets/rotate-ccw-x90cC1Uz.js","assets/environments-DMLR_apk.js","assets/input-Fk8aRl_M.js","assets/i18n-labels-Dmmlv1ZF.js","assets/card-DkWQn3lf.js","assets/EmptyState-BUS2fndv.js","assets/PageSkeleton-DaSQo8P8.js","assets/skeleton-BAtpOP8g.js","assets/tabs-B2h2Tuem.js","assets/use-adapter-capabilities-DJmCVgTW.js","assets/use-copy-action-JdR8Lk1e.js","assets/arrow-right-BNgvgYSb.js","assets/external-link-Ch0N0BYy.js","assets/MarkdownBody-BOoEezj0.js","assets/file-text-C38JjRJ1.js","assets/index-CXP7aFCG.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Ae=Object.defineProperty;var a=(e,n)=>Ae(e,"name",{value:n,configurable:!0});import{i as ie}from"./rolldown-runtime-ZpX3ckPj.js";import{B as le,Ft as c,G as k,Sa as Se,da as z,ji as j,lt as Ee,mt as _e,ni as Le,ua as Me,xt as y,z as K}from"./agent-avatar-url-CdlBp9p9.js";import{t as Te}from"./preload-helper-Bq-5Tx7W.js";import{Ln as ke,ct as qe,f as Pe,i as V,n as Re,r as se,s as oe,yt as Fe}from"./BreadcrumbContext-NYKl3jAM.js";import{m as ce}from"./alert-dialog-CvROCHSj.js";import{t as ue}from"./AgentAvatar-CTdkXzmh.js";import{t as $e}from"./tabs-B2h2Tuem.js";import{t as ne}from"./bot-DGyCo7vt.js";import{i as Be,o as Ke,t as Ve}from"./heartbeats-CtWMFcNw.js";import{i as De,n as Oe,t as ae}from"./environments-DMLR_apk.js";import{t as re}from"./EmptyState-BUS2fndv.js";import{t as ze}from"./PageSkeleton-DaSQo8P8.js";import{Ft as D,Gt as Ge,Kt as de,Lt as Ue,Ot as He,Rt as Qe,Vt as We,Wt as Xe,Xt as Ye,Yt as me,Zt as Ze,qt as Je}from"./index-ChreIWPq.js";var m=ie(Se(),1),t=ie(Me(),1),pe=Le,et=(0,m.lazy)(()=>Te(()=>import("./index-ChreIWPq.js").then(e=>e.gt).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,33,34,35,36,37,38,39,40,41,42]))),tt=["all","active","paused","error","builtin"],st=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"paused",label:"Paused"},{value:"error",label:"Error"},{value:"builtin",label:"Built-in"}];function nt(e){return tt.includes(e)}a(nt,"isFilterTab");var G={label:"Local",detail:"Paperclip host",title:"Local - Paperclip host"},ge={label:"—",detail:"Loading environment",title:"Loading environment"},xe=new Set(["terminated","pending_approval"]);function fe(e,n){return n==="all"?!0:n==="active"?e==="active"||e==="running"||e==="idle":n==="paused"?e==="paused":n==="error"?e==="error":!0}a(fe,"matchesFilter");function at(e,n,i){return e.filter(r=>xe.has(r.status)?!1:n==="builtin"?i.has(r.id):fe(r.status,n)).sort((r,o)=>r.name.localeCompare(o.name))}a(at,"filterAgents");function rt(e){const n=e.adapterConfig?.model;if(typeof n!="string")return null;const i=n.trim();return i.length>0?i:null}a(rt,"getConfiguredModel");function it(e){return e==="ssh"?"SSH":e.charAt(0).toUpperCase()+e.slice(1)}a(it,"formatEnvironmentDriver");function lt(e,n){const i=typeof e.config.provider=="string"?e.config.provider.trim():"";return i?n?.sandboxProviders?.[i]?.displayName??i:"Sandbox"}a(lt,"getSandboxProviderLabel");function ot(e,n){const i=Ue(e)?"Managed by Paperclip":e.driver==="sandbox"?`${lt(e,n)} sandbox provider`:e.driver==="local"?"Paperclip host":it(e.driver);return{label:e.name,detail:i,title:`${e.name} - ${i}`}}a(ot,"describeEnvironment");function ct(e){return{label:"Unknown environment",detail:e.slice(0,8),title:`Unknown environment - ${e}`}}a(ct,"describeMissingEnvironment");function ut(e,n,i,r){const o=e.defaultEnvironmentId??i;if(!o)return G;const p=n.get(o);return p?ot(p,r):ct(o)}a(ut,"resolveAgentEnvironment");function he(e,n,i){return e.reduce((r,o)=>{const p=he(o.reports,n,i);return xe.has(o.status)?(r.push(...p),r):(((n==="builtin"?i.has(o.id):fe(o.status,n))||p.length>0)&&r.push({...o,reports:p}),r)},[]).sort((r,o)=>r.name.localeCompare(o.name))}a(he,"filterOrgTree");function Ct(){z();const{selectedCompanyId:e}=_e(),{openNewAgent:n}=Be(),{setBreadcrumbs:i}=Re(),r=Pe(),o=ke(),{isMobile:p}=De(),w=o.pathname.split("/").pop()??"all",b=nt(w)?w:"all",[E,I]=(0,m.useState)("org"),C=p,l=C?"list":E,{data:d}=j({queryKey:y.instance.settings,queryFn:a(()=>Oe.get(),"queryFn"),enabled:!!e}),g=d?.experimental.enableBuiltInAgents===!0,h=b==="builtin"&&!g?"all":b,q=(0,m.useMemo)(()=>st.filter(s=>s.value!=="builtin"||g),[g]),{data:v}=j({queryKey:y.builtInAgents.list(e),queryFn:a(()=>Ye.list(e),"queryFn"),enabled:!!e&&g}),_=(0,m.useMemo)(()=>{const s=new Map;if(!g)return s;for(const u of v??[])u.agentId&&s.set(u.agentId,u);return s},[v,g]),U=(0,m.useMemo)(()=>new Set(_.keys()),[_]),[P,R]=(0,m.useState)(null),{data:x,isLoading:je,error:H}=j({queryKey:y.agents.list(e),queryFn:a(()=>se.list(e),"queryFn"),enabled:!!e}),{data:A}=j({queryKey:y.org(e),queryFn:a(()=>se.org(e),"queryFn"),enabled:!!e&&l==="org"}),L=d?.experimental.enableEnvironments===!0,{data:S}=j({queryKey:y.environments.list(e),queryFn:a(()=>ae.list(e),"queryFn"),enabled:!!e&&L}),{data:Q}=j({queryKey:y.environments.capabilities(e),queryFn:a(()=>ae.capabilities(e),"queryFn"),enabled:!!e&&L}),W=[...y.liveRuns(e),"agents-page"],F=Ge({companyId:e,resourceKey:"live-runs:agents-page",queryKey:W,enabled:!!e,refetchInterval:15e3,leaderOnly:!0}),{data:$,dataUpdatedAt:ye}=j({queryKey:W,queryFn:a(()=>Ve.liveRunsForCompany(e),"queryFn"),enabled:F.enabled,refetchInterval:F.refetchInterval});Xe(F,$,ye);const X=Je(e),M=(0,m.useMemo)(()=>{const s=new Map;for(const u of $??[]){if(u.status!=="running"&&u.status!=="queued")continue;const f=s.get(u.agentId);if(f){f.liveCount+=1;continue}s.set(u.agentId,{runId:u.id,liveCount:1})}return s},[$]),Ne=(0,m.useMemo)(()=>{const s=new Map;for(const u of x??[])s.set(u.id,u);return s},[x]),Y=(0,m.useMemo)(()=>{const s=new Map;for(const u of S??[])s.set(u.id,u);return s},[S]),Z=(0,m.useMemo)(()=>{const s=new Map;for(const u of x??[])s.set(u.id,ut(u,Y,d?.defaultEnvironmentId??null,Q));return s},[x,Y,Q,d?.defaultEnvironmentId]);if((0,m.useEffect)(()=>{i([{label:c("Agents")}])},[i]),(0,m.useEffect)(()=>{e&&b==="builtin"&&d&&!g&&r("/agents/all",{replace:!0})},[g,d,r,b,e]),!e)return(0,t.jsx)(re,{icon:ne,message:c("Select a company to view agents.")});if(je)return(0,t.jsx)(ze,{variant:"list"});const N=at(x??[],h,U),B=he(A??[],h,U),J=L&&S===void 0,ee=L&&(S===void 0||S.length>1),we=a(s=>J?ge:Z.get(s)??G,"resolveRenderedEnvironment"),Ie=a(s=>{const u=s.orgChainHealth?.status==="invalid_org_chain",f=_.get(s.id),Ce=f?.status==="needs_setup"||f?.status==="pending_approval",T=f&&Ce?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(me,{status:f.status}),f.status==="needs_setup"&&(0,t.jsx)("span",{onClick:a(te=>{te.preventDefault(),te.stopPropagation()},"onClick"),children:(0,t.jsx)(V,{size:"xs",variant:"outline",onClick:a(()=>R(f),"onClick"),children:c("Set up")})})]}):null;return(0,t.jsx)(He,{title:s.name,titleAccessory:(0,t.jsx)(Ze,{agentId:s.id,companyId:s.companyId}),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:`${c(`agentRole.${s.role}`,{defaultValue:pe[s.role]??s.role})}${s.title?` - ${s.title}`:""}`,to:le(s),className:k("group",s.pausedAt&&h!=="paused"?"opacity-50":"",de(X.data,"agent",s.id)==="left"?"sm:text-foreground/55":""),leading:u?(0,t.jsx)(ce,{className:"h-3.5 w-3.5 text-amber-500","aria-label":c("agents.invalidReportingChain")}):(0,t.jsx)(ue,{agent:s,size:32}),secondaryRow:T?(0,t.jsx)("div",{className:"xl:hidden flex flex-wrap items-center gap-1.5",children:T}):void 0,meta:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[T&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-1.5",children:T}),(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(be,{agent:s,environment:we(s.id),showEnvironment:ee})})]}),metaSpacerClassName:"hidden xl:block",trailing:(0,t.jsx)("div",{className:"flex items-center gap-3",children:(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[M.has(s.id)&&(0,t.jsx)(O,{agentRef:K(s),runId:M.get(s.id).runId,liveCount:M.get(s.id).liveCount}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(D,{status:s.status})})]})})},s.id)},"renderAgentRow");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)($e,{value:h,onValueChange:a(s=>r(`/agents/${s}`),"onValueChange"),children:(0,t.jsx)(We,{items:q,value:h,onValueChange:a(s=>r(`/agents/${s}`),"onValueChange")})}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!C&&(0,t.jsxs)("div",{className:"flex items-center border border-border",role:"group","aria-label":c("View mode"),children:[(0,t.jsx)("button",{className:k("p-1.5 transition-colors",l==="list"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:a(()=>I("list"),"onClick"),title:c("List view"),"aria-label":c("List view"),"aria-pressed":l==="list",children:(0,t.jsx)(Ke,{className:"h-3.5 w-3.5"})}),(0,t.jsx)("button",{className:k("p-1.5 transition-colors",l==="org"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:a(()=>I("org"),"onClick"),title:c("agents.orgChartView"),"aria-label":c("agents.orgChartView"),"aria-pressed":l==="org",children:(0,t.jsx)(Fe,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)(V,{size:"sm",variant:"outline",onClick:n,children:[(0,t.jsx)(qe,{className:"h-3.5 w-3.5 mr-1.5"}),c("New Agent")]})]})]}),N.length>0&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[N.length," ",c("agent"),N.length!==1?"s":""]}),H&&(0,t.jsx)("p",{className:"text-sm text-destructive",children:H.message}),x&&x.length===0&&(0,t.jsx)(re,{icon:ne,message:c("Create your first agent to get started."),action:c("New Agent"),onAction:n}),l==="list"&&N.length>0&&(0,t.jsx)("div",{children:N.map(Ie)}),l==="list"&&x&&x.length>0&&N.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("agents.noStatusMatches")}),l==="org"&&B.length>0&&(0,t.jsx)("div",{className:"py-1",children:B.map(s=>(0,t.jsx)(ve,{node:s,depth:0,agentMap:Ne,liveRunByAgent:M,environmentByAgentId:Z,environmentDataLoading:J,showEnvironment:ee,tab:h,memberships:X.data,builtInByAgentId:_,onConfigureBuiltIn:R},s.id))}),l==="org"&&A&&A.length>0&&B.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("agents.noStatusMatches")}),l==="org"&&A&&A.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-8",children:c("No organizational hierarchy defined.")}),P&&e&&(0,t.jsx)(m.Suspense,{fallback:null,children:(0,t.jsx)(et,{companyId:e,state:P,open:P!==null,onOpenChange:a(s=>{s||R(null)},"onOpenChange")})})]})}a(Ct,"Agents");function ve({node:e,depth:n,agentMap:i,liveRunByAgent:r,environmentByAgentId:o,environmentDataLoading:p,showEnvironment:w,tab:b,memberships:E,builtInByAgentId:I,onConfigureBuiltIn:C}){z();const l=i.get(e.id),d=I.get(e.id),g=d?.status==="needs_setup"||d?.status==="pending_approval",h=!!(l&&l.orgChainHealth?.status==="invalid_org_chain"),q=de(E,"agent",e.id);return(0,t.jsxs)("div",{style:{paddingLeft:n*24},children:[(0,t.jsxs)(oe,{to:l?le(l):`/agents/${e.id}`,className:k("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&&b!=="paused"&&"opacity-50",q==="left"&&"sm:text-foreground/55"),children:[h?(0,t.jsx)(ce,{className:"h-3.5 w-3.5 shrink-0 text-amber-500","aria-label":c("agents.invalidReportingChain")}):(0,t.jsx)(ue,{agent:l??e,size:24}),(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:[c(`agentRole.${e.role}`,{defaultValue:pe[e.role]??e.role}),l?.title?` - ${l.title}`:""]})]}),d&&g&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,t.jsx)(me,{status:d.status}),d.status==="needs_setup"&&(0,t.jsx)("span",{onClick:a(v=>{v.preventDefault(),v.stopPropagation()},"onClick"),children:(0,t.jsx)(V,{size:"xs",variant:"outline",onClick:a(()=>C(d),"onClick"),children:c("Set up")})})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[(0,t.jsx)("span",{className:"sm:hidden",children:r.has(e.id)?(0,t.jsx)(O,{agentRef:l?K(l):e.id,runId:r.get(e.id).runId,liveCount:r.get(e.id).liveCount}):(0,t.jsx)(D,{status:e.status})}),(0,t.jsxs)("div",{className:"hidden sm:flex items-center gap-3",children:[r.has(e.id)&&(0,t.jsx)(O,{agentRef:l?K(l):e.id,runId:r.get(e.id).runId,liveCount:r.get(e.id).liveCount}),l&&(0,t.jsx)("div",{className:"hidden xl:flex items-center gap-3",children:(0,t.jsx)(be,{agent:l,environment:p?ge:o.get(l.id)??G,showEnvironment:w})}),(0,t.jsx)("span",{className:"w-20 flex justify-end",children:(0,t.jsx)(D,{status:e.status})})]})]})]}),e.reports&&e.reports.length>0&&(0,t.jsx)("div",{className:"border-l border-border ml-4",children:e.reports.map(v=>(0,t.jsx)(ve,{node:v,depth:n+1,agentMap:i,liveRunByAgent:r,environmentByAgentId:o,environmentDataLoading:p,showEnvironment:w,tab:b,memberships:E,builtInByAgentId:I,onConfigureBuiltIn:C},v.id))})]})}a(ve,"OrgTreeNode");function be({agent:e,environment:n,showEnvironment:i}){const r=rt(e),o=Qe(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:r??void 0,children:r??"—"}),(0,t.jsx)("div",{className:"truncate font-mono text-(length:--text-micro) text-muted-foreground/70",title:o,children:o})]}),i&&(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?Ee(e.lastHeartbeatAt):"—"})]})}a(be,"AgentMetaColumns");function O({agentRef:e,runId:n,liveCount:i}){return z(),(0,t.jsxs)(oe,{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(r=>r.stopPropagation(),"onClick"),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:[c("Live"),i>1?` (${i})`:""]})]})}a(O,"LiveRunIndicator");export{Ct as Agents};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ge=Object.defineProperty;var r=(s,n)=>ge(s,"name",{value:n,configurable:!0});import{i as re}from"./rolldown-runtime-ZpX3ckPj.js";import{Ft as t,G as fe,Sa as he,Tt as ee,da as I,ji as te,lt as ye,mt as ve,ua as je,xt as Q}from"./agent-avatar-url-CdlBp9p9.js";import{Vn as be,i as C,n as Ne,r as Te,s as le}from"./BreadcrumbContext-NYKl3jAM.js";import{r as se,t as we}from"./AgentAvatar-CTdkXzmh.js";import{i as ae,r as Ae,t as Se}from"./tabs-B2h2Tuem.js";import{a as Fe}from"./ToastContext-CkRLuVem.js";import{a as b,c as B,l as V,n as k,r as M}from"./select-b1sMyjd5.js";import{t as ne}from"./input-Fk8aRl_M.js";import{n as Ce,s as Ie,u as Ue}from"./i18n-labels-Dmmlv1ZF.js";import{r as N,t as T}from"./card-DkWQn3lf.js";import{t as Ee}from"./EmptyState-BUS2fndv.js";import{b as ie,hn as De,in as Pe,kt as Re,rn as _e,tn as Le,xn as Be}from"./index-Dt9g_rra.js";var u=re(he(),1),e=re(je(),1),Ve=50,i="__all",ke=[{value:i,get label(){return t("auditFeed.allActions")}},{value:"issue.",get label(){return t("sidebar.issues")}},{value:"agent.",get label(){return t("Agents")}},{value:"heartbeat.",get label(){return t("Runs")}},{value:"approval.",get label(){return t("Approvals")}},{value:"project.",get label(){return t("Projects")}},{value:"goal.",get label(){return t("Goals")}},{value:"tool_gateway.",get label(){return t("common.tools")}},{value:"cost.",get label(){return t("Costs")}},{value:"company.",get label(){return t("Company")}}],Me=[{value:i,get label(){return t("auditFeed.allEntities")}},{value:"issue",get label(){return t("Task")}},{value:"agent",get label(){return t("Agent")}},{value:"project",get label(){return t("Project")}},{value:"goal",get label(){return t("Goal")}},{value:"company",get label(){return t("Company")}}];function $e(s){if(!s)return;const n=new Date(`${s}T00:00:00.000Z`);return Number.isNaN(n.getTime())?void 0:n.toISOString()}r($e,"toStartIso");function qe(s){if(!s)return;const n=new Date(`${s}T23:59:59.999Z`);return Number.isNaN(n.getTime())?void 0:n.toISOString()}r(qe,"toEndIso");function ze({record:s,agentMap:n,userProfileMap:c}){const m=s.agentId??(s.actorType==="agent"?s.actorId:null),o=m?n.get(m):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,{agent:o,size:16,className:"h-3 w-3"})}),(0,e.jsx)("span",{className:"truncate font-medium text-foreground",children:o.name})]});if(s.actorType==="user"&&s.actorId){const x=c.get(s.actorId);return(0,e.jsx)(se,{name:x?.label??t("User"),avatarUrl:x?.image??null,size:"sm",className:"font-medium text-foreground"})}const f=s.actorType==="plugin"?t("Plugin"):s.actorType==="agent"?t("Agent"):s.actorType==="user"?t("User"):t("System");return(0,e.jsx)(se,{name:f,size:"sm",className:"font-medium text-foreground"})}r(ze,"AuditActor");function Oe({record:s}){const{t:n}=I(),{issue:c,document:m}=s.entity,o=c?.identifier??c?.id??null;return o?(0,e.jsx)(le,{to:`/issues/${o}`,className:"font-medium text-primary hover:underline",children:c?.identifier?`${c.identifier}${c.title?` · ${c.title}`:""}`:t("auditFeed.taskFallback")}):m?(0,e.jsx)("span",{className:"font-medium text-foreground",children:m.key}):(0,e.jsx)("span",{className:"text-muted-foreground",children:Ce(n,s.entityType)})}r(Oe,"AuditEntityNode");function Ke({record:s,agentMap:n,userProfileMap:c}){const{t:m}=I(),o=Re(s.action,s.details,{agentMap:n,userProfileMap:c}),f=m(o,{defaultValue:o}),x=s.responsibleUserId?c.get(s.responsibleUserId):null,h=!!(s.responsibleUserId&&!(s.actorType==="user"&&s.actorId===s.responsibleUserId)),p=x?.label??(s.responsibleUserId?"a user":null),j=s.entity.comment?.excerpt?.trim(),y=s.entity.issue&&s.entity.document?s.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)(ze,{record:s,agentMap:n,userProfileMap:c}),(0,e.jsx)("span",{className:"text-muted-foreground",children:f}),(0,e.jsx)(Oe,{record:s})]}),j?(0,e.jsxs)("p",{className:"line-clamp-2 border-l-2 border-border pl-2 text-muted-foreground",children:["“",j,"”"]}):null,y?(0,e.jsxs)("p",{className:"text-xs text-muted-foreground",children:[t("activityFormat.document")," ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:y})]}):null,(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[h&&p?(0,e.jsxs)("span",{className:"inline-flex items-center rounded-full bg-muted px-2 py-0.5",children:[t("issueRunLedger.onBehalfOf")," ",p]}):null,s.runId&&s.agentId?(0,e.jsx)(le,{to:`/agents/${s.agentId}/runs/${s.runId}`,className:"text-primary hover:underline",children:t("View run")}):null,(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro) opacity-70",children:s.action})]})]}),(0,e.jsx)("time",{className:"shrink-0 whitespace-nowrap text-xs text-muted-foreground",dateTime:s.createdAt,title:new Date(s.createdAt).toLocaleString(),children:ye(s.createdAt)})]})})}r(Ke,"AuditRow");function Ge(){return I(),(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(Le,{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:t("auditFeed.enterpriseTitle")}),(0,e.jsxs)("p",{className:"mx-auto mt-1 max-w-md text-sm text-muted-foreground",children:[t("auditFeed.permissionPrefix")," ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:"audit:view_agent_actions"})," ",t("auditFeed.permissionSuffix")]})]})]})})}r(Ge,"AuditUpsell");function Ye({companyId:s,lockedAgentId:n,hideHeader:c,mode:m,onModeChange:o}){I();const{pushToast:f}=Fe(),[x,h]=(0,u.useState)(i),[p,j]=(0,u.useState)(i),[y,$]=(0,u.useState)(i),[U,q]=(0,u.useState)(i),[E,z]=(0,u.useState)(""),[D,O]=(0,u.useState)(""),[H,J]=(0,u.useState)(!1),[P,W]=(0,u.useState)(!1),K=te({queryKey:Q.agents.list(s),queryFn:r(()=>Te.list(s),"queryFn")}),G=te({queryKey:Q.access.companyUserDirectory(s),queryFn:r(()=>Ue.listUserDirectory(s),"queryFn"),retry:!1}),oe=(0,u.useMemo)(()=>new Map((K.data??[]).map(a=>[a.id,a])),[K.data]),ce=(0,u.useMemo)(()=>Ie(G.data?.users),[G.data]),v=n?"agents":m??"all",d={actorScope:v,agentId:n??(x===i?void 0:x),responsibleUserId:p===i?void 0:p,action:y===i?void 0:y,entityType:U===i?void 0:U,from:$e(E),to:qe(D)},w=!!(!n&&x!==i||p!==i||y!==i||U!==i||E||D),l=Be({queryKey:Q.audit.agentActions(s,{actorScope:d.actorScope,agentId:d.agentId,responsibleUserId:d.responsibleUserId,action:d.action,entityType:d.entityType,from:d.from,to:d.to}),queryFn:r(({pageParam:a})=>ie.listAgentActions(s,{...d,limit:Ve,cursor:a??void 0}),"queryFn"),initialPageParam:null,getNextPageParam:r(a=>a.nextCursor??void 0,"getNextPageParam"),retry:r((a,g)=>!(g instanceof ee&&g.status===403)&&a<2,"retry")}),Y=l.error instanceof ee&&l.error.status===403,R=l.data?.pages.some(a=>a.accessTier==="basic")??!1,ue=l.data?.pages.some(a=>a.accessTier==="full")??!1,Z=(0,u.useMemo)(()=>{const a=l.data?.pages??[];return(R?a.filter(g=>g.accessTier!=="full"):a).flatMap(g=>g.items)},[l.data,R]),_=R?"basic":l.data?.pages[0]?.accessTier,A=R&&ue,de=n?!0:_==="full",me=!!(A&&P&&!l.isFetching),L=!!(!n&&!me&&(Y&&w||A)),S=!!(Y&&!n&&v==="agents"&&o),xe=!!(!n&&o&&!S&&(v==="agents"||_==="full"));(0,u.useEffect)(()=>{S&&o?.("all")},[S,o]),(0,u.useEffect)(()=>{!n&&(_==="basic"||L)&&(h(i),j(i),$(i),q(i),z(""),O(""))},[_,A,n,L]),(0,u.useEffect)(()=>{if(!A){P&&W(!1);return}P||(W(!0),l.refetch())},[P,l,A]);const X=r(()=>{h(i),j(i),$(i),q(i),z(""),O("")},"clearFilters"),pe=r(async()=>{J(!0);try{const a=await ie.exportAgentActionsCsv(s,{actorScope:d.actorScope,agentId:d.agentId,responsibleUserId:d.responsibleUserId,action:d.action,entityType:d.entityType,from:d.from,to:d.to}),g=URL.createObjectURL(a),F=document.createElement("a");F.href=g,F.download=`${v==="agents"?"agent-audit":"activity"}-${s}.csv`,document.body.appendChild(F),F.click(),F.remove(),window.setTimeout(()=>URL.revokeObjectURL(g),5e3),f({title:t("auditFeed.exportedTitle"),body:"Your CSV download has started.",tone:"success"})}catch(a){f({title:t("companyExport.exportFailedTitle"),body:a instanceof Error?a.message:"Could not export the audit log.",tone:"error"})}finally{J(!1)}},"handleExport");return Y&&!L&&!S?(0,e.jsx)(Ge,{}):(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:t("Activity")}),(0,e.jsx)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:v==="agents"?t("companyActivity.agentDescription"):t("companyActivity.allDescription")})]})}),xe?(0,e.jsx)(Se,{value:v,onValueChange:r(a=>o?.(a),"onValueChange"),children:(0,e.jsxs)(Ae,{"aria-label":t("routineEditor.activityScope"),children:[(0,e.jsx)(ae,{value:"all",children:t("caseComponents.activity.allActivity")}),(0,e.jsx)(ae,{value:"agents",children:t("companyActivity.agentScope")})]})}):null,de?(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[n?null:(0,e.jsxs)(k,{value:x,onValueChange:h,children:[(0,e.jsx)(B,{className:"w-40",children:(0,e.jsx)(V,{placeholder:t("Agent")})}),(0,e.jsxs)(M,{children:[(0,e.jsx)(b,{value:i,children:"All agents"}),(K.data??[]).map(a=>(0,e.jsx)(b,{value:a.id,children:a.name},a.id))]})]}),(0,e.jsxs)(k,{value:p,onValueChange:j,children:[(0,e.jsx)(B,{className:"w-52",children:(0,e.jsx)(V,{placeholder:"Responsible user"})}),(0,e.jsxs)(M,{children:[(0,e.jsx)(b,{value:i,children:t("auditFeed.allResponsibleUsers")}),(G.data?.users??[]).map(a=>(0,e.jsx)(b,{value:a.principalId,children:a.user?.name??a.user?.email??a.principalId.slice(0,8)},a.principalId))]})]}),(0,e.jsxs)(k,{value:y,onValueChange:$,children:[(0,e.jsx)(B,{className:"w-36",children:(0,e.jsx)(V,{placeholder:t("Action")})}),(0,e.jsx)(M,{children:ke.map(a=>(0,e.jsx)(b,{value:a.value,children:a.label},a.value))})]}),(0,e.jsxs)(k,{value:U,onValueChange:q,children:[(0,e.jsx)(B,{className:"w-36",children:(0,e.jsx)(V,{placeholder:t("auditFeed.entity")})}),(0,e.jsx)(M,{children:Me.map(a=>(0,e.jsx)(b,{value:a.value,children:a.label},a.value))})]}),(0,e.jsx)(ne,{type:"date","aria-label":t("auditFeed.fromDate"),value:E,max:D||void 0,onChange:r(a=>z(a.target.value),"onChange"),className:"w-36"}),(0,e.jsx)(ne,{type:"date","aria-label":t("auditFeed.toDate"),value:D,min:E||void 0,onChange:r(a=>O(a.target.value),"onChange"),className:"w-36"}),w?(0,e.jsx)(C,{variant:"ghost",size:"sm",onClick:X,children:t("Clear filters")}):null,(0,e.jsxs)(C,{variant:"outline",size:"sm",className:"ml-auto",onClick:pe,disabled:H||l.isLoading||Z.length===0,children:[(0,e.jsx)(De,{className:"mr-1.5 h-4 w-4"}),H?t("auditFeed.exporting"):t("auditFeed.exportCsv")]})]}):null,L||S?(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"py-14 text-center text-sm text-muted-foreground",children:t("auditFeed.refreshingAccess")})}):l.isLoading?(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"py-14 text-center text-sm text-muted-foreground",children:t("tools.advanced.loading")})}):l.error?(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:l.error instanceof Error?l.error.message:t("auditFeed.loadFailed")}),(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:r(()=>l.refetch(),"onClick"),children:t("Try again")})]})}):Z.length===0?(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(_e,{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:w?t("auditFeed.noMatchingActions"):t("tools.audit.emptyTitle")}),(0,e.jsx)("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:w?t("auditFeed.tryDifferentFilters"):v==="agents"?t("auditFeed.emptyAgentDescription"):t("auditFeed.emptyAllDescription")})]}),w?(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:X,children:t("Clear filters")}):null]})}):(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"px-0 py-0",children:(0,e.jsx)("ul",{className:fe("divide-y divide-border"),children:Z.map(a=>(0,e.jsx)(Ke,{record:a,agentMap:oe,userProfileMap:ce},a.id))})})}),l.hasNextPage?(0,e.jsx)("div",{className:"flex justify-center",children:(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:r(()=>l.fetchNextPage(),"onClick"),disabled:l.isFetchingNextPage,children:l.isFetchingNextPage?t("tools.advanced.loading"):t("common.loadMore")})}):null,(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:t("tools.audit.immutabilityNotice")})]})}r(Ye,"AuditFeed");function lt(){I();const{selectedCompanyId:s}=ve(),{setBreadcrumbs:n}=Ne(),[c,m]=be(),o=c.get("mode")==="agents"?"agents":"all";(0,u.useEffect)(()=>{n([{label:t("Activity")}])},[n]);const f=(0,u.useCallback)(x=>{m(h=>{const p=new URLSearchParams(h);return x==="agents"?p.set("mode","agents"):p.delete("mode"),p},{replace:!0})},[m]);return s?(0,e.jsx)(Ye,{companyId:s,mode:o,onModeChange:f}):(0,e.jsx)(Ee,{icon:Pe,message:t("Select a company to view activity.")})}r(lt,"CompanyActivity");export{lt as CompanyActivity};
|
|
1
|
+
var ge=Object.defineProperty;var r=(s,n)=>ge(s,"name",{value:n,configurable:!0});import{i as re}from"./rolldown-runtime-ZpX3ckPj.js";import{Ft as t,G as fe,Sa as he,Tt as ee,da as I,ji as te,lt as ye,mt as ve,ua as je,xt as Q}from"./agent-avatar-url-CdlBp9p9.js";import{Vn as be,i as C,n as Ne,r as Te,s as le}from"./BreadcrumbContext-NYKl3jAM.js";import{r as se,t as we}from"./AgentAvatar-CTdkXzmh.js";import{i as ae,r as Ae,t as Se}from"./tabs-B2h2Tuem.js";import{a as Fe}from"./ToastContext-CkRLuVem.js";import{a as b,c as B,l as V,n as k,r as M}from"./select-b1sMyjd5.js";import{t as ne}from"./input-Fk8aRl_M.js";import{n as Ce,s as Ie,u as Ue}from"./i18n-labels-Dmmlv1ZF.js";import{r as N,t as T}from"./card-DkWQn3lf.js";import{t as Ee}from"./EmptyState-BUS2fndv.js";import{b as ie,hn as De,in as Pe,kt as Re,rn as _e,tn as Le,xn as Be}from"./index-ChreIWPq.js";var u=re(he(),1),e=re(je(),1),Ve=50,i="__all",ke=[{value:i,get label(){return t("auditFeed.allActions")}},{value:"issue.",get label(){return t("sidebar.issues")}},{value:"agent.",get label(){return t("Agents")}},{value:"heartbeat.",get label(){return t("Runs")}},{value:"approval.",get label(){return t("Approvals")}},{value:"project.",get label(){return t("Projects")}},{value:"goal.",get label(){return t("Goals")}},{value:"tool_gateway.",get label(){return t("common.tools")}},{value:"cost.",get label(){return t("Costs")}},{value:"company.",get label(){return t("Company")}}],Me=[{value:i,get label(){return t("auditFeed.allEntities")}},{value:"issue",get label(){return t("Task")}},{value:"agent",get label(){return t("Agent")}},{value:"project",get label(){return t("Project")}},{value:"goal",get label(){return t("Goal")}},{value:"company",get label(){return t("Company")}}];function $e(s){if(!s)return;const n=new Date(`${s}T00:00:00.000Z`);return Number.isNaN(n.getTime())?void 0:n.toISOString()}r($e,"toStartIso");function qe(s){if(!s)return;const n=new Date(`${s}T23:59:59.999Z`);return Number.isNaN(n.getTime())?void 0:n.toISOString()}r(qe,"toEndIso");function ze({record:s,agentMap:n,userProfileMap:c}){const m=s.agentId??(s.actorType==="agent"?s.actorId:null),o=m?n.get(m):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,{agent:o,size:16,className:"h-3 w-3"})}),(0,e.jsx)("span",{className:"truncate font-medium text-foreground",children:o.name})]});if(s.actorType==="user"&&s.actorId){const x=c.get(s.actorId);return(0,e.jsx)(se,{name:x?.label??t("User"),avatarUrl:x?.image??null,size:"sm",className:"font-medium text-foreground"})}const f=s.actorType==="plugin"?t("Plugin"):s.actorType==="agent"?t("Agent"):s.actorType==="user"?t("User"):t("System");return(0,e.jsx)(se,{name:f,size:"sm",className:"font-medium text-foreground"})}r(ze,"AuditActor");function Oe({record:s}){const{t:n}=I(),{issue:c,document:m}=s.entity,o=c?.identifier??c?.id??null;return o?(0,e.jsx)(le,{to:`/issues/${o}`,className:"font-medium text-primary hover:underline",children:c?.identifier?`${c.identifier}${c.title?` · ${c.title}`:""}`:t("auditFeed.taskFallback")}):m?(0,e.jsx)("span",{className:"font-medium text-foreground",children:m.key}):(0,e.jsx)("span",{className:"text-muted-foreground",children:Ce(n,s.entityType)})}r(Oe,"AuditEntityNode");function Ke({record:s,agentMap:n,userProfileMap:c}){const{t:m}=I(),o=Re(s.action,s.details,{agentMap:n,userProfileMap:c}),f=m(o,{defaultValue:o}),x=s.responsibleUserId?c.get(s.responsibleUserId):null,h=!!(s.responsibleUserId&&!(s.actorType==="user"&&s.actorId===s.responsibleUserId)),p=x?.label??(s.responsibleUserId?"a user":null),j=s.entity.comment?.excerpt?.trim(),y=s.entity.issue&&s.entity.document?s.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)(ze,{record:s,agentMap:n,userProfileMap:c}),(0,e.jsx)("span",{className:"text-muted-foreground",children:f}),(0,e.jsx)(Oe,{record:s})]}),j?(0,e.jsxs)("p",{className:"line-clamp-2 border-l-2 border-border pl-2 text-muted-foreground",children:["“",j,"”"]}):null,y?(0,e.jsxs)("p",{className:"text-xs text-muted-foreground",children:[t("activityFormat.document")," ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:y})]}):null,(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[h&&p?(0,e.jsxs)("span",{className:"inline-flex items-center rounded-full bg-muted px-2 py-0.5",children:[t("issueRunLedger.onBehalfOf")," ",p]}):null,s.runId&&s.agentId?(0,e.jsx)(le,{to:`/agents/${s.agentId}/runs/${s.runId}`,className:"text-primary hover:underline",children:t("View run")}):null,(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro) opacity-70",children:s.action})]})]}),(0,e.jsx)("time",{className:"shrink-0 whitespace-nowrap text-xs text-muted-foreground",dateTime:s.createdAt,title:new Date(s.createdAt).toLocaleString(),children:ye(s.createdAt)})]})})}r(Ke,"AuditRow");function Ge(){return I(),(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(Le,{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:t("auditFeed.enterpriseTitle")}),(0,e.jsxs)("p",{className:"mx-auto mt-1 max-w-md text-sm text-muted-foreground",children:[t("auditFeed.permissionPrefix")," ",(0,e.jsx)("span",{className:"font-mono text-(length:--text-micro)",children:"audit:view_agent_actions"})," ",t("auditFeed.permissionSuffix")]})]})]})})}r(Ge,"AuditUpsell");function Ye({companyId:s,lockedAgentId:n,hideHeader:c,mode:m,onModeChange:o}){I();const{pushToast:f}=Fe(),[x,h]=(0,u.useState)(i),[p,j]=(0,u.useState)(i),[y,$]=(0,u.useState)(i),[U,q]=(0,u.useState)(i),[E,z]=(0,u.useState)(""),[D,O]=(0,u.useState)(""),[H,J]=(0,u.useState)(!1),[P,W]=(0,u.useState)(!1),K=te({queryKey:Q.agents.list(s),queryFn:r(()=>Te.list(s),"queryFn")}),G=te({queryKey:Q.access.companyUserDirectory(s),queryFn:r(()=>Ue.listUserDirectory(s),"queryFn"),retry:!1}),oe=(0,u.useMemo)(()=>new Map((K.data??[]).map(a=>[a.id,a])),[K.data]),ce=(0,u.useMemo)(()=>Ie(G.data?.users),[G.data]),v=n?"agents":m??"all",d={actorScope:v,agentId:n??(x===i?void 0:x),responsibleUserId:p===i?void 0:p,action:y===i?void 0:y,entityType:U===i?void 0:U,from:$e(E),to:qe(D)},w=!!(!n&&x!==i||p!==i||y!==i||U!==i||E||D),l=Be({queryKey:Q.audit.agentActions(s,{actorScope:d.actorScope,agentId:d.agentId,responsibleUserId:d.responsibleUserId,action:d.action,entityType:d.entityType,from:d.from,to:d.to}),queryFn:r(({pageParam:a})=>ie.listAgentActions(s,{...d,limit:Ve,cursor:a??void 0}),"queryFn"),initialPageParam:null,getNextPageParam:r(a=>a.nextCursor??void 0,"getNextPageParam"),retry:r((a,g)=>!(g instanceof ee&&g.status===403)&&a<2,"retry")}),Y=l.error instanceof ee&&l.error.status===403,R=l.data?.pages.some(a=>a.accessTier==="basic")??!1,ue=l.data?.pages.some(a=>a.accessTier==="full")??!1,Z=(0,u.useMemo)(()=>{const a=l.data?.pages??[];return(R?a.filter(g=>g.accessTier!=="full"):a).flatMap(g=>g.items)},[l.data,R]),_=R?"basic":l.data?.pages[0]?.accessTier,A=R&&ue,de=n?!0:_==="full",me=!!(A&&P&&!l.isFetching),L=!!(!n&&!me&&(Y&&w||A)),S=!!(Y&&!n&&v==="agents"&&o),xe=!!(!n&&o&&!S&&(v==="agents"||_==="full"));(0,u.useEffect)(()=>{S&&o?.("all")},[S,o]),(0,u.useEffect)(()=>{!n&&(_==="basic"||L)&&(h(i),j(i),$(i),q(i),z(""),O(""))},[_,A,n,L]),(0,u.useEffect)(()=>{if(!A){P&&W(!1);return}P||(W(!0),l.refetch())},[P,l,A]);const X=r(()=>{h(i),j(i),$(i),q(i),z(""),O("")},"clearFilters"),pe=r(async()=>{J(!0);try{const a=await ie.exportAgentActionsCsv(s,{actorScope:d.actorScope,agentId:d.agentId,responsibleUserId:d.responsibleUserId,action:d.action,entityType:d.entityType,from:d.from,to:d.to}),g=URL.createObjectURL(a),F=document.createElement("a");F.href=g,F.download=`${v==="agents"?"agent-audit":"activity"}-${s}.csv`,document.body.appendChild(F),F.click(),F.remove(),window.setTimeout(()=>URL.revokeObjectURL(g),5e3),f({title:t("auditFeed.exportedTitle"),body:"Your CSV download has started.",tone:"success"})}catch(a){f({title:t("companyExport.exportFailedTitle"),body:a instanceof Error?a.message:"Could not export the audit log.",tone:"error"})}finally{J(!1)}},"handleExport");return Y&&!L&&!S?(0,e.jsx)(Ge,{}):(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:t("Activity")}),(0,e.jsx)("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:v==="agents"?t("companyActivity.agentDescription"):t("companyActivity.allDescription")})]})}),xe?(0,e.jsx)(Se,{value:v,onValueChange:r(a=>o?.(a),"onValueChange"),children:(0,e.jsxs)(Ae,{"aria-label":t("routineEditor.activityScope"),children:[(0,e.jsx)(ae,{value:"all",children:t("caseComponents.activity.allActivity")}),(0,e.jsx)(ae,{value:"agents",children:t("companyActivity.agentScope")})]})}):null,de?(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[n?null:(0,e.jsxs)(k,{value:x,onValueChange:h,children:[(0,e.jsx)(B,{className:"w-40",children:(0,e.jsx)(V,{placeholder:t("Agent")})}),(0,e.jsxs)(M,{children:[(0,e.jsx)(b,{value:i,children:"All agents"}),(K.data??[]).map(a=>(0,e.jsx)(b,{value:a.id,children:a.name},a.id))]})]}),(0,e.jsxs)(k,{value:p,onValueChange:j,children:[(0,e.jsx)(B,{className:"w-52",children:(0,e.jsx)(V,{placeholder:"Responsible user"})}),(0,e.jsxs)(M,{children:[(0,e.jsx)(b,{value:i,children:t("auditFeed.allResponsibleUsers")}),(G.data?.users??[]).map(a=>(0,e.jsx)(b,{value:a.principalId,children:a.user?.name??a.user?.email??a.principalId.slice(0,8)},a.principalId))]})]}),(0,e.jsxs)(k,{value:y,onValueChange:$,children:[(0,e.jsx)(B,{className:"w-36",children:(0,e.jsx)(V,{placeholder:t("Action")})}),(0,e.jsx)(M,{children:ke.map(a=>(0,e.jsx)(b,{value:a.value,children:a.label},a.value))})]}),(0,e.jsxs)(k,{value:U,onValueChange:q,children:[(0,e.jsx)(B,{className:"w-36",children:(0,e.jsx)(V,{placeholder:t("auditFeed.entity")})}),(0,e.jsx)(M,{children:Me.map(a=>(0,e.jsx)(b,{value:a.value,children:a.label},a.value))})]}),(0,e.jsx)(ne,{type:"date","aria-label":t("auditFeed.fromDate"),value:E,max:D||void 0,onChange:r(a=>z(a.target.value),"onChange"),className:"w-36"}),(0,e.jsx)(ne,{type:"date","aria-label":t("auditFeed.toDate"),value:D,min:E||void 0,onChange:r(a=>O(a.target.value),"onChange"),className:"w-36"}),w?(0,e.jsx)(C,{variant:"ghost",size:"sm",onClick:X,children:t("Clear filters")}):null,(0,e.jsxs)(C,{variant:"outline",size:"sm",className:"ml-auto",onClick:pe,disabled:H||l.isLoading||Z.length===0,children:[(0,e.jsx)(De,{className:"mr-1.5 h-4 w-4"}),H?t("auditFeed.exporting"):t("auditFeed.exportCsv")]})]}):null,L||S?(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"py-14 text-center text-sm text-muted-foreground",children:t("auditFeed.refreshingAccess")})}):l.isLoading?(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"py-14 text-center text-sm text-muted-foreground",children:t("tools.advanced.loading")})}):l.error?(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:l.error instanceof Error?l.error.message:t("auditFeed.loadFailed")}),(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:r(()=>l.refetch(),"onClick"),children:t("Try again")})]})}):Z.length===0?(0,e.jsx)(T,{children:(0,e.jsxs)(N,{className:"flex flex-col items-center gap-3 py-14 text-center",children:[(0,e.jsx)(_e,{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:w?t("auditFeed.noMatchingActions"):t("tools.audit.emptyTitle")}),(0,e.jsx)("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:w?t("auditFeed.tryDifferentFilters"):v==="agents"?t("auditFeed.emptyAgentDescription"):t("auditFeed.emptyAllDescription")})]}),w?(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:X,children:t("Clear filters")}):null]})}):(0,e.jsx)(T,{children:(0,e.jsx)(N,{className:"px-0 py-0",children:(0,e.jsx)("ul",{className:fe("divide-y divide-border"),children:Z.map(a=>(0,e.jsx)(Ke,{record:a,agentMap:oe,userProfileMap:ce},a.id))})})}),l.hasNextPage?(0,e.jsx)("div",{className:"flex justify-center",children:(0,e.jsx)(C,{variant:"outline",size:"sm",onClick:r(()=>l.fetchNextPage(),"onClick"),disabled:l.isFetchingNextPage,children:l.isFetchingNextPage?t("tools.advanced.loading"):t("common.loadMore")})}):null,(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:t("tools.audit.immutabilityNotice")})]})}r(Ye,"AuditFeed");function lt(){I();const{selectedCompanyId:s}=ve(),{setBreadcrumbs:n}=Ne(),[c,m]=be(),o=c.get("mode")==="agents"?"agents":"all";(0,u.useEffect)(()=>{n([{label:t("Activity")}])},[n]);const f=(0,u.useCallback)(x=>{m(h=>{const p=new URLSearchParams(h);return x==="agents"?p.set("mode","agents"):p.delete("mode"),p},{replace:!0})},[m]);return s?(0,e.jsx)(Ye,{companyId:s,mode:o,onModeChange:f}):(0,e.jsx)(Ee,{icon:Pe,message:t("Select a company to view activity.")})}r(lt,"CompanyActivity");export{lt as CompanyActivity};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _e=Object.defineProperty;var u=(e,r)=>_e(e,"name",{value:r,configurable:!0});import{i as ye}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as fe,Ft as p,G as re,Sa as Ue,St as qe,cn as We,da as je,ji as X,mr as Ke,mt as Ye,ua as Ge,wt as se,xt as H}from"./agent-avatar-url-CdlBp9p9.js";import{Ln as Ze,f as Xe,i as J,it as He,lt as D,n as Je,r as Ve,y as Qe}from"./BreadcrumbContext-NYKl3jAM.js";import{$ as et}from"./mention-chips-BGwhkP2B.js";import{h as tt}from"./StatusIcon-Cw0scYdd.js";import{a as st}from"./ToastContext-CkRLuVem.js";import{t as me}from"./MarkdownBody-BOoEezj0.js";import{r as nt}from"./badge-DHxSYw-Q.js";import{t as he}from"./rotate-ccw-x90cC1Uz.js";import{t as _}from"./EmptyState-BUS2fndv.js";import{t as rt}from"./PageSkeleton-DaSQo8P8.js";import{Jt as ot,Pt as at,Ut as it,a as ct,dt as lt,ft as xe,hn as ut,ht as dt,i as pt,mt as ft,n as mt,pt as ht,r as xt,t as ve,ut as gt}from"./index-
|
|
1
|
+
var _e=Object.defineProperty;var u=(e,r)=>_e(e,"name",{value:r,configurable:!0});import{i as ye}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as fe,Ft as p,G as re,Sa as Ue,St as qe,cn as We,da as je,ji as X,mr as Ke,mt as Ye,ua as Ge,wt as se,xt as H}from"./agent-avatar-url-CdlBp9p9.js";import{Ln as Ze,f as Xe,i as J,it as He,lt as D,n as Je,r as Ve,y as Qe}from"./BreadcrumbContext-NYKl3jAM.js";import{$ as et}from"./mention-chips-BGwhkP2B.js";import{h as tt}from"./StatusIcon-Cw0scYdd.js";import{a as st}from"./ToastContext-CkRLuVem.js";import{t as me}from"./MarkdownBody-BOoEezj0.js";import{r as nt}from"./badge-DHxSYw-Q.js";import{t as he}from"./rotate-ccw-x90cC1Uz.js";import{t as _}from"./EmptyState-BUS2fndv.js";import{t as rt}from"./PageSkeleton-DaSQo8P8.js";import{Jt as ot,Pt as at,Ut as it,a as ct,dt as lt,ft as xe,hn as ut,ht as dt,i as pt,mt as ft,n as mt,pt as ht,r as xt,t as ve,ut as gt}from"./index-ChreIWPq.js";var x=ye(Ue(),1),bt=["agents","projects","skills","routines","tasks","attachments"],wt={agents:"Agents",projects:"Projects",skills:"Skills",routines:"Routines",tasks:"Tasks",attachments:"Attachments"};function yt(){return{agents:!0,projects:!0,skills:!0,routines:!0,tasks:!0,attachments:!0}}u(yt,"buildDefaultExportCategorySelection");function ke(e){return e.tasks||e.routines}u(ke,"isAttachmentsCategoryEnabled");function Se(e){const r=new Set;for(const a of e){if(!a.recurring)continue;const n=a.path.trim();if(!n)continue;r.add(n);const o=n.lastIndexOf("/");o>=0&&r.add(`${n.slice(0,o+1)}`)}return r}u(Se,"buildRecurringTaskPrefixes");function jt(e,r){for(const a of r)if(e===a||e.startsWith(a))return!0;return!1}u(jt,"isRecurringTaskFile");function vt(e){const r=new Set,a=new Set;for(const n of e)for(const o of n.attachments??[]){const c=o.sha256.trim().toLowerCase();c&&(n.recurring?r:a).add(c)}return{recurring:r,oneOff:a}}u(vt,"buildAttachmentShaOwnership");var kt=new Set(["agents","projects","skills","routines","tasks"]);function St(e){const r=new Map;for(const a of e){const n=a.sha256.trim().toLowerCase();if(!n)continue;const o=r.get(n)??new Set,c=a.ownedBy&&a.ownedBy.length>0?a.ownedBy:["always"];for(const f of c)o.add(f);r.set(n,o)}return r}u(St,"buildEmbeddedAssetShaOwnership");function Et(e,r){for(const a of e)if(!kt.has(a)||r[a])return!0;return!1}u(Et,"isEmbeddedAssetBlobIncluded");function Ee(e,r){return e.startsWith("agents/")?"agents":e.startsWith("projects/")?"projects":e.startsWith("skills/")?"skills":e.startsWith("tasks/")?jt(e,r)?"routines":"tasks":e.startsWith("blobs/")?"attachments":null}u(Ee,"categorizeExportFile");function Ct(e,r){const a=Se(r),n={agents:0,projects:0,skills:0,routines:0,tasks:0,attachments:0};for(const o of e){const c=Ee(o,a);c&&(n[c]+=1)}return n}u(Ct,"countExportFilesByCategory");function Nt(e){const{filePaths:r,issues:a,categories:n}=e,o=Se(a),c=vt(a),f=St(e.embeddedAssets??[]),m=n.attachments&&ke(n),g=new Set;for(const l of r){const w=Ee(l,o);if(w===null){g.add(l);continue}if(w==="attachments"){const i=l.slice(6).trim().toLowerCase(),b=f.get(i);if(b&&Et(b,n)){g.add(l);continue}if(!m)continue;const j=c.recurring.has(i),v=c.oneOff.has(i);!j&&!v?b||g.add(l):(v&&n.tasks||j&&n.routines)&&g.add(l);continue}n[w]&&g.add(l)}return g}u(Nt,"buildExportCheckedFiles");function Ce(e,r){if(!r.has(e))return r.add(e),e;let a=2;for(;;){const n=`${e}-${a}`;if(!r.has(n))return r.add(n),n;a+=1}}u(Ce,"uniqueSlug");function Pt(e){const r=new Set,a=new Map,n=[...e].sort((o,c)=>o.name.localeCompare(c.name));for(const o of n){const c=Ke(o.name)??"agent";a.set(o.id,Ce(c,r))}return a}u(Pt,"buildPortableAgentSlugMap");function At(e){const r=new Set,a=new Map,n=[...e].sort((o,c)=>o.name.localeCompare(c.name));for(const o of n){const c=We(o.name,o.name);a.set(o.id,Ce(c,r))}return a}u(At,"buildPortableProjectSlugMap");function Tt(e){const r=Pt(e.agents),a=At(e.projects),n={agents:e.orderedAgents.map(o=>r.get(o.id)).filter(o=>!!o),projects:e.orderedProjects.map(o=>a.get(o.id)).filter(o=>!!o)};return n.agents.length>0||n.projects.length>0?n:void 0}u(Tt,"buildPortableSidebarOrder");var t=ye(Ge(),1);function Ne(e){const r=new Set,a=new Set,n=new Set;for(const o of e){const c=o.match(/^agents\/([^/]+)\//);c&&r.add(c[1]);const f=o.match(/^projects\/([^/]+)\//);f&&a.add(f[1]);const m=o.match(/^tasks\/([^/]+)\//);m&&n.add(m[1])}return{agents:r,projects:a,tasks:n,routines:new Set(n)}}u(Ne,"checkedSlugs");function Rt(e,r){const a=Ne(r),n=e.split(`
|
|
2
2
|
`),o=[],c=new Set(["agents","projects","tasks","routines"]),f=new Set(["agents","projects"]);let m=null,g=null,l=!0,w=null,i=null,b=[],j=null,v=[];function L(){i!==null&&b.length>0&&(v.push(i),v.push(...b)),i=null,b=[]}u(L,"flushSidebarSection");function P(){L(),j!==null&&v.length>0&&(o.push(j),o.push(...v)),j=null,v=[]}u(P,"flushSection");for(const y of n){const q=y.match(/^([a-zA-Z_][\w-]*):\s*(.*)$/);if(q&&!y.startsWith(" ")){P(),g=null,l=!0;const N=q[0].split(":")[0];if(c.has(N)){m=N,j=y;continue}else if(N==="sidebar"){m=N,w=null,j=y;continue}else{m=null,o.push(y);continue}}if(m==="sidebar"){const N=y.match(/^ ([\w-]+):\s*$/);if(N&&!y.startsWith(" ")){L();const A=N[1];w=A&&f.has(A)?A:null,i=w?y:null;continue}const O=y.match(/^ - ["']?([^"'\n]+)["']?\s*$/);if(O&&w){const A=O[1],W=a[w];A&&W.has(A)&&b.push(y);continue}if(w){b.push(y);continue}}if(m&&c.has(m)){const N=y.match(/^ ([\w][\w-]*):\s*(.*)$/);if(N&&!y.startsWith(" ")){const O=N[1];g=O,l=a[m].has(O),l&&v.push(y);continue}if(g!==null){l&&v.push(y);continue}v.push(y);continue}o.push(y)}P();let C=o.join(`
|
|
3
3
|
`);const U=C.match(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*$/m);return U&&!r.has(U[1])&&(C=C.replace(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*\n?/m,"")),C}u(Rt,"filterPaperclipYaml");function Pe(e,r){if(!r)return e;const a=r.toLowerCase();return e.map(n=>{if(n.kind==="file")return n.name.toLowerCase().includes(a)||n.path.toLowerCase().includes(a)?n:null;const o=Pe(n.children,r);return o.length>0?{...n,children:o}:null}).filter(n=>n!==null)}u(Pe,"filterTree");function Lt(e,r){const a=new Set,n=r.toLowerCase();function o(c,f){if(c.kind==="file"){if(c.name.toLowerCase().includes(n)||c.path.toLowerCase().includes(n))for(const m of f)a.add(m)}else for(const m of c.children)o(m,[...f,c.path])}u(o,"walk");for(const c of e)o(c,[]);return a}u(Lt,"collectMatchedParentDirs");var ge=10;function Ot(e,r,a,n){let o=0,c=0;return{nodes:e.map(f=>{if(f.kind==="dir"&&f.name==="tasks"){o=f.children.length;const m=[],g=[],l=a.toLowerCase();for(const b of f.children){const j=ht([b],"file"),v=n!==null&&j.has(n),L=a&&(b.name.toLowerCase().includes(l)||b.path.toLowerCase().includes(l)||[...j].some(P=>P.toLowerCase().includes(l)));v||L?m.push(b):g.push(b)}const w=Math.max(0,r-m.length),i=[...m,...g.slice(0,w)];return c=i.length,{...f,children:i}}return f}),totalTaskChildren:o,visibleTaskChildren:c}}u(Ot,"paginateTaskNodes");function Ae(e,r,a){const n={};for(const o of Object.keys(e))r.has(o)&&(n[o]=a[o]??e[o]);return n}u(Ae,"filterExportForDownload");function Ft(e,r,a){const n=Ae(e.files,r,a),o=pt(n,e.rootPath),c=new ArrayBuffer(o.byteLength);new Uint8Array(c).set(o);const f=new Blob([c],{type:"application/zip"}),m=URL.createObjectURL(f),g=document.createElement("a");g.href=m,g.download=`${e.rootPath}.zip`,document.body.appendChild(g),g.click(),g.remove(),window.setTimeout(()=>URL.revokeObjectURL(m),1e3)}u(Ft,"downloadZip");function Mt({data:e,onSkillClick:r}){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:gt[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(o=>(0,t.jsx)("button",{type:"button",className:re("inline-flex items-center rounded-md border border-border bg-background px-2 py-0.5 text-xs",a==="skills"&&r&&"cursor-pointer hover:bg-accent/50 hover:border-foreground/30 transition-colors"),onClick:u(()=>a==="skills"&&r?.(o),"onClick"),children:o},o))}):(0,t.jsx)("span",{children:n})})]},a))})})}u(Mt,"FrontmatterCard");var It={ceo:"CEO",cto:"CTO",cmo:"CMO",cfo:"CFO",coo:"COO",vp:"VP",manager:"Manager",engineer:"Engineer",get agent(){return p("Agent")}};function $t(e,r,a,n){const o=Ne(r),c=e.agents.filter(i=>o.agents.has(i.slug)),f=e.projects.filter(i=>o.projects.has(i.slug)),m=e.issues.filter(i=>o.tasks.has(i.slug)),g=e.skills.filter(i=>[...r].some(b=>b.startsWith(`skills/${i.key}/`)||b.startsWith("skills/")&&b.includes(`/${i.slug}/`))),l=[];l.push(`# ${a}`),l.push(""),n&&(l.push(`> ${n}`),l.push("")),c.length>0&&(l.push(""),l.push("")),l.push("## What's Inside"),l.push(""),l.push("This is an [Agent Company](https://paperclip.ing) package."),l.push("");const w=[];if(c.length>0&&w.push([p("Agents"),c.length]),f.length>0&&w.push([p("Projects"),f.length]),g.length>0&&w.push([p("Skills"),g.length]),m.length>0&&w.push(["Tasks",m.length]),w.length>0){l.push("| Content | Count |"),l.push("|---------|-------|");for(const[i,b]of w)l.push(`| ${i} | ${b} |`);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 b=It[i.role]??i.role,j=i.reportsToSlug??"—";l.push(`| ${i.name} | ${b} | ${j} |`)}l.push("")}if(f.length>0){l.push("### Projects"),l.push("");for(const i of f){const b=i.description?` — ${i.description}`:"";l.push(`- **${i.name}**${b}`)}l.push("")}return l.push("## Getting Started"),l.push(""),l.push("```bash"),l.push("npx penclip 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
4
|
`)}u($t,"generateReadmeFromSelection");function zt(e){const{src:r,selectedFile:a,allFiles:n,orgChartPreviewUrl:o}=e;if(/^(?:https?:|data:)/i.test(r))return null;if(r.replace(/^\.\//,"")==="images/org-chart.png"&&o)return o;const c=(a.includes("/")?a.slice(0,a.lastIndexOf("/")+1):"")+r,f=n[c]??n[r];return f?ve(c in n?c:r,f):null}u(zt,"resolveExportPreviewImageSrc");function Bt({selectedFile:e,content:r,allFiles:a,orgChartPreviewUrl:n,onSkillClick:o}){if(je(),!e||r===null)return(0,t.jsx)(_,{icon:D,message:p("companyExport.selectPreview")});const c=mt(r),f=e.endsWith(".md")&&c!==null,m=f&&c?dt(c):null,g=xt(e,r)?ve(e,r):null,l=f?w=>zt({src:w,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:m?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Mt,{data:m.data,onSkillClick:o}),m.body.trim()&&(0,t.jsx)(me,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:m.body})]}):f?(0,t.jsx)(me,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:c??""}):g?(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:g,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:p("companyExport.binaryPreviewUnavailable")})})]})}u(Bt,"ExportPreviewPane");function be(e){const r="/company/export/files/",a=Qe(e),n=a.indexOf(r);return n===-1?null:decodeURIComponent(a.slice(n+22))||null}u(be,"filePathFromLocation");function we(e){const r=e.split("/").slice(0,-1),a=[];let n="";for(const o of r)n=n?`${n}/${o}`:o,a.push(n);return a}u(we,"expandAncestors");function Dt(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}u(Dt,"isAbortError");function ne(e){return e instanceof Error?e.message:"Failed to load export data."}u(ne,"previewErrorMessage");function es(){je();const{selectedCompanyId:e,selectedCompany:r}=Ye(),{setBreadcrumbs:a}=Je(),{pushToast:n}=st(),o=Xe(),c=Ze(),f=(0,x.useRef)(be(c.pathname)),{data:m}=X({queryKey:H.auth.session,queryFn:u(()=>qe.getSession(),"queryFn")}),{data:g=[]}=X({queryKey:H.agents.list(e),queryFn:u(()=>Ve.list(e),"queryFn"),enabled:!!e}),{data:l=[]}=X({queryKey:H.projects.list(e),queryFn:u(()=>tt.list(e),"queryFn"),enabled:!!e}),{data:w}=X({queryKey:H.companies.exportFidelity(e),queryFn:u(()=>se.exportFidelity(e),"queryFn"),enabled:!!e}),[i,b]=(0,x.useState)(null),[j,v]=(0,x.useState)(null),[L,P]=(0,x.useState)(new Set),[C,U]=(0,x.useState)(()=>({...yt(),tasks:!1,routines:!1,attachments:!1})),[y,q]=(0,x.useState)(""),[N,O]=(0,x.useState)(ge),[A,W]=(0,x.useState)(!1),K=(0,x.useRef)(null),$=(0,x.useRef)(null),M=(0,x.useRef)(0),oe=(0,x.useRef)(null),ae=m?.user?.id??m?.session?.userId??null,V=(0,x.useMemo)(()=>g.filter(s=>s.status!=="terminated"),[g]),Q=(0,x.useMemo)(()=>l,[l]),{orderedAgents:ie}=ot({agents:V,companyId:e,userId:ae}),{orderedProjects:ce}=it({projects:Q,companyId:e,userId:ae}),le=(0,x.useMemo)(()=>Tt({agents:V,orderedAgents:ie,projects:Q,orderedProjects:ce}),[ie,ce,V,Q]),ee=C.tasks||C.routines,te=(0,x.useCallback)((s,d=!1)=>{v(s),s?o(`/company/export/files/${encodeURI(s)}`,{replace:d}):o("/company/export",{replace:d})},[o]);(0,x.useEffect)(()=>{if(!i)return;const s=be(c.pathname);s&&s in i.files&&s!==j?(v(s),P(d=>{const h=new Set(d);for(const k of we(s))h.add(k);return h})):!s&&j&&v(null)},[c.pathname,i]),(0,x.useEffect)(()=>{a([{label:r?.name??p("Organization"),href:"/dashboard"},{label:p("Settings"),href:"/company/settings"},{label:p("Export")}])},[r?.name,a]);const T=fe({mutationFn:u(({includeIssues:s,includeSkills:d,signal:h})=>se.exportPreview(e,{include:{company:!0,agents:!0,projects:!0,issues:s,skills:d},sidebarOrder:le},{signal:h}),"mutationFn"),onSuccess:u((s,d)=>{if(d.requestId!==M.current)return;b(s);const h=xe(s.files),k=new Set;for(const S of h)S.kind==="dir"&&S.name!=="tasks"&&k.add(S.path);const E=f.current;if(E&&E in s.files){v(E);const S=we(E);P(new Set([...k,...S]))}else{const S="README.md"in s.files?"README.md":Object.keys(s.files)[0];S&&te(S,!0),P(k)}},"onSuccess"),onError:u((s,d)=>{d.requestId!==M.current||Dt(s)||n({tone:"error",title:p("companyExport.exportFailedTitle"),body:ne(s)})},"onError")});function I(){if(!e)return;$.current?.abort();const s=new AbortController,d=M.current+1;M.current=d,$.current=s,W(!1),T.mutate({includeIssues:ee,includeSkills:C.skills,requestId:d,signal:s.signal})}u(I,"startPreviewRequest");const Y=fe({mutationFn:u(()=>se.exportBundle(e,{include:{company:!0,agents:!0,projects:!0,issues:ee,skills:C.skills},selectedFiles:Array.from(R).sort(),sidebarOrder:le}),"mutationFn"),onSuccess:u(s=>{const d=new Set(Object.keys(s.files));Ft(s,d,s.files),n({tone:"success",title:p("companyExport.exportDownloadedTitle"),body:`${d.size} file${d.size===1?"":"s"} exported as ${s.rootPath}.zip`})},"onSuccess"),onError:u(s=>{n({tone:"error",title:p("companyExport.exportFailedTitle"),body:s instanceof Error?s.message:"Failed to build export package."})},"onError")});(0,x.useEffect)(()=>{e&&(oe.current!==e&&(oe.current=e,b(null),v(null)),I())},[e,ee,C.skills]),(0,x.useEffect)(()=>()=>{M.current+=1,$.current?.abort()},[]);const F=(0,x.useMemo)(()=>i?xe(i.files):[],[i]),R=(0,x.useMemo)(()=>i?Nt({filePaths:Object.keys(i.files),issues:i.manifest.issues,categories:C,embeddedAssets:i.manifest.embeddedAssets??[]}):new Set,[i,C]),Te=(0,x.useMemo)(()=>i?Ct(Object.keys(i.files),i.manifest.issues):null,[i]),{displayTree:Re,totalTaskChildren:ue,visibleTaskChildren:de}=(0,x.useMemo)(()=>{let s=F;y&&(s=Pe(s,y));const d=Ot(s,N,y,j);return{displayTree:d.nodes,totalTaskChildren:d.totalTaskChildren,visibleTaskChildren:d.visibleTaskChildren}},[F,y,N,j]),Le=(0,x.useMemo)(()=>{const s={};function d(h){if(h.kind==="file"){const E=R.has(h.path);return E||(s[h.path]="muted"),E}let k=!1;for(const E of h.children)d(E)&&(k=!0);return k||(s[h.path]="muted"),k}u(d,"walk");for(const h of F)d(h);return s},[F,R]),G=(0,x.useMemo)(()=>{if(!i)return{};const s={...i.files},d=i.paperclipExtensionPath;if(d&&typeof i.files[d]=="string"&&(s[d]=Rt(i.files[d],R)),typeof i.files["README.md"]=="string"){const h=i.manifest.company?.name??r?.name??p("Company"),k=i.manifest.company?.description??null;s["README.md"]=$t(i.manifest,R,h,k)}return s},[i,R,r?.name]),Oe=(0,x.useMemo)(()=>i?ct(Ae(i.files,R,G),i.rootPath):0,[i,R,G]),pe=(0,x.useMemo)(()=>ft(F),[F]),z=R.size,B=(0,x.useMemo)(()=>i?i.warnings.filter(s=>!/terminated agent/i.test(s)):[],[i]);function Fe(s){P(d=>{const h=new Set(d);return h.has(s)?h.delete(s):h.add(s),h})}u(Fe,"handleToggleDir");function Me(s){U(d=>({...d,[s]:!d[s]}))}u(Me,"handleToggleCategory");function Ie(s){const d=y.length>0,h=s.length>0;if(h&&!d&&(K.current=new Set(L)),q(s),h){const k=Lt(F,s);P(E=>{const S=new Set(E);for(const Z of k)S.add(Z);return S})}else d&&K.current&&(P(K.current),K.current=null)}u(Ie,"handleSearchChange");function $e(s){if(!i)return;const d=i.manifest.skills.find(h=>h.key===s||h.slug===s)?.path??`skills/${s}/SKILL.md`;d in i.files&&(te(d),P(h=>{const k=new Set(h);k.add("skills");const E=d.split("/").slice(0,-1);let S="";for(const Z of E)S=S?`${S}/${Z}`:Z,k.add(S);return k}))}u($e,"handleSkillClick");function ze(){!i||R.size===0||Y.isPending||Y.mutate()}u(ze,"handleDownload");function Be(){M.current+=1,$.current?.abort(),$.current=null,T.reset(),W(!0)}if(u(Be,"handleCancelPreview"),!e)return(0,t.jsx)(_,{icon:D,message:p("Select an organization to export.")});if(T.isPending&&!i)return(0,t.jsx)(rt,{variant:"detail"});if(A&&!i)return(0,t.jsx)(_,{icon:D,title:p("Export preview cancelled"),message:p("The preview request was cancelled. Your export settings are unchanged."),action:p("Retry preview"),onAction:I,hideActionIcon:!0});if(T.isError&&!i)return(0,t.jsx)(_,{icon:D,title:p("Export preview failed"),message:ne(T.error),description:p("Retry the preview. You do not need to reload this page."),action:p("Retry preview"),onAction:I,hideActionIcon:!0});if(!i)return(0,t.jsx)(_,{icon:D,title:p("Export preview unavailable"),message:p("No export preview is loaded."),action:"Load preview",onAction:I,hideActionIcon:!0});const De=j?G[j]??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:[r?.name??p("Organization")," ",p("companyExport.exportLabel")]}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:[p(pe===1?"companyExport.exportProgressSingle":"companyExport.exportProgress",{selected:z.toLocaleString(),total:pe.toLocaleString()}),z>0&&` (~${at(Oe)})`]}),B.length>0&&(0,t.jsx)("span",{className:"text-amber-500",children:p(B.length===1?"companyExport.warningCountSingle":"companyExport.warningCount",{count:B.length})})]}),(0,t.jsxs)(J,{size:"sm",onClick:ze,disabled:z===0||Y.isPending||T.isPending||T.isError||A,children:[(0,t.jsx)(ut,{className:"mr-1.5 h-3.5 w-3.5"}),Y.isPending?p("companyExport.building"):`Export ${z.toLocaleString()} file${z===1?"":"s"}`]})]})}),B.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:B.map(s=>(0,t.jsx)("div",{className:"text-xs text-amber-500",children:s},s))}),w&&w.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:p("companyExport.notIncluded")}),w.warnings.map(s=>(0,t.jsx)("div",{className:re("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:p("companyExport.packageFiles")})}),(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:p("companyExport.whatToInclude")}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",role:"group","aria-label":p("companyExport.whatToInclude"),children:bt.map(s=>{const d=s==="attachments"&&!ke(C),h=C[s]&&!d,k=Te?.[s]??0,E=i.manifest.includes.issues||s!=="tasks"&&s!=="routines"&&s!=="attachments";return(0,t.jsxs)("label",{className:re("flex items-center gap-2 text-sm",d?"cursor-not-allowed opacity-50":"cursor-pointer"),title:d?p("companyExport.attachmentsRequireTasksOrRoutines"):void 0,children:[(0,t.jsx)("input",{type:"checkbox",checked:h,disabled:d,onChange:u(()=>Me(s),"onChange"),className:"accent-foreground","data-export-category":s}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:wt[s]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:E?k.toLocaleString():"—"})]},s)})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:p("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)(He,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("input",{type:"text",value:y,onChange:u(s=>Ie(s.target.value),"onChange"),placeholder:p("companyExport.searchFiles"),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)(lt,{nodes:Re,selectedFile:j,expandedDirs:L,onToggleDir:Fe,onSelectFile:te,fileTones:Le,showCheckboxes:!1,wrapLabels:!1}),ue>de&&!y&&(0,t.jsx)("div",{className:"px-4 py-2",children:(0,t.jsxs)("button",{type:"button",onClick:u(()=>O(s=>s+ge),"onClick"),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:[p("companyExport.showMoreTasks"),de," ",p("issueCommon.of")," ",ue,")"]})})]})]}),(0,t.jsxs)("div",{className:"relative min-w-0 overflow-y-auto xl:pl-6",children:[(0,t.jsx)(Bt,{selectedFile:j,content:De,allFiles:G,orgChartPreviewUrl:`/api/companies/${encodeURIComponent(e)}/org.svg`,onSkillClick:$e}),T.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)(nt,{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:p("Updating export preview…")}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:p("Large task histories can take a minute. You can untick Tasks or cancel this update.")})]}),(0,t.jsxs)(J,{type:"button",variant:"outline",size:"sm",onClick:Be,children:[(0,t.jsx)(et,{}),p("Cancel update")]})]})}):A?(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:p("Preview update cancelled")}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:p("The previous preview remains available. Retry when you are ready.")})]}),(0,t.jsxs)(J,{type:"button",variant:"outline",size:"sm",onClick:I,children:[(0,t.jsx)(he,{}),p("Retry preview")]})]})}):T.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:p("Export preview failed")}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:ne(T.error)})]}),(0,t.jsxs)(J,{type:"button",variant:"outline",size:"sm",onClick:I,children:[(0,t.jsx)(he,{}),p("Retry preview")]})]})}):null]})]})]})}u(es,"CompanyExport");export{es as CompanyExport};
|
package/dist/assets/{CompanySkills.production-BzbeiOIw.js → CompanySkills.production-DB0MkLfO.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var bl=Object.defineProperty;var l=(n,i)=>bl(n,"name",{value:i,configurable:!0});import{i as Sn}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as X,Ft as t,G as q,Sa as jl,da as se,ji as pe,la as yl,lt as kl,mt as vl,t as be,ua as Sl,xt as b}from"./agent-avatar-url-CdlBp9p9.js";import{Bn as Nl,Vn as wl,ct as kt,f as Cl,ft as Fl,i as v,it as Il,n as Dl,r as Ws,s as fe,tt as Nn,vt as Ll,xt as Dt}from"./BreadcrumbContext-NYKl3jAM.js";import{$ as Tl}from"./mention-chips-BGwhkP2B.js";import{d as ze,m as wn,p as _e,u as Oe}from"./alert-dialog-CvROCHSj.js";import{t as an}from"./AgentAvatar-CTdkXzmh.js";import{D as Bl,E as Xs,O as Pl,T as Al,_ as pt,a as ys,c as ks,f as Ps,h as es,m as As,n as vt,o as Ms,r as vs,s as St,t as El,u as Ss,v as Bs,w as Es,y as Kl}from"./checkbox-DSDEd9xJ.js";import{c as Ml,i as O,t as ql}from"./MarkdownEditor-C2xaZOWa.js";import{i as Ks,r as Cn,t as Fn}from"./tabs-B2h2Tuem.js";import{p as Lt}from"./StatusIcon-Cw0scYdd.js";import{l as In,o as $l,r as Dn,s as Rl,t as zl}from"./use-adapter-capabilities-DJmCVgTW.js";import{t as Ln}from"./check-DaEgimxq.js";import{a as _l,s as bs}from"./ToastContext-CkRLuVem.js";import{a as Tn,i as Tt,s as Bn}from"./clipboard-BcdF-0DW.js";import{r as gt,t as Ol}from"./use-copy-action-JdR8Lk1e.js";import{n as Vl,t as js}from"./external-link-Ch0N0BYy.js";import{S as Ul,t as Nt}from"./MarkdownBody-BOoEezj0.js";import{t as Bt}from"./file-text-C38JjRJ1.js";import{d as Ql,u as Pn}from"./sheet-0KNjJ51X.js";import{t as oe}from"./badge-DHxSYw-Q.js";import{t as Re}from"./input-Fk8aRl_M.js";import{t as ts}from"./EmptyState-BUS2fndv.js";import{t as Pe}from"./PageSkeleton-DaSQo8P8.js";import{$t as Hl,Ct as Ys,Dt as An,Et as En,G as Gl,H as Wl,J as Yl,K as Xl,Q as Zl,St as Jl,Tt as er,U as sr,W as tr,X as nr,Y as lr,Z as rr,_ as ar,an as ir,at as on,bt as or,c as dr,cn as cr,d as ur,et as mr,f as qs,fn as xr,g as hr,gn as pr,h as gr,hn as wt,in as Kn,it as Mn,jt as fr,l as br,ln as jr,lt as ge,m as qn,mn as $n,nn as yr,nt as kr,o as vr,ot as ss,p as ft,pn as Ns,rt as Sr,s as Nr,sn as Ct,tt as wr,u as Cr,v as Fr,vn as Ft,vt as Ir,wt as bt,xt as jt,y as Dr,yn as dn,yt as Pt}from"./index-
|
|
1
|
+
var bl=Object.defineProperty;var l=(n,i)=>bl(n,"name",{value:i,configurable:!0});import{i as Sn}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as X,Ft as t,G as q,Sa as jl,da as se,ji as pe,la as yl,lt as kl,mt as vl,t as be,ua as Sl,xt as b}from"./agent-avatar-url-CdlBp9p9.js";import{Bn as Nl,Vn as wl,ct as kt,f as Cl,ft as Fl,i as v,it as Il,n as Dl,r as Ws,s as fe,tt as Nn,vt as Ll,xt as Dt}from"./BreadcrumbContext-NYKl3jAM.js";import{$ as Tl}from"./mention-chips-BGwhkP2B.js";import{d as ze,m as wn,p as _e,u as Oe}from"./alert-dialog-CvROCHSj.js";import{t as an}from"./AgentAvatar-CTdkXzmh.js";import{D as Bl,E as Xs,O as Pl,T as Al,_ as pt,a as ys,c as ks,f as Ps,h as es,m as As,n as vt,o as Ms,r as vs,s as St,t as El,u as Ss,v as Bs,w as Es,y as Kl}from"./checkbox-DSDEd9xJ.js";import{c as Ml,i as O,t as ql}from"./MarkdownEditor-C2xaZOWa.js";import{i as Ks,r as Cn,t as Fn}from"./tabs-B2h2Tuem.js";import{p as Lt}from"./StatusIcon-Cw0scYdd.js";import{l as In,o as $l,r as Dn,s as Rl,t as zl}from"./use-adapter-capabilities-DJmCVgTW.js";import{t as Ln}from"./check-DaEgimxq.js";import{a as _l,s as bs}from"./ToastContext-CkRLuVem.js";import{a as Tn,i as Tt,s as Bn}from"./clipboard-BcdF-0DW.js";import{r as gt,t as Ol}from"./use-copy-action-JdR8Lk1e.js";import{n as Vl,t as js}from"./external-link-Ch0N0BYy.js";import{S as Ul,t as Nt}from"./MarkdownBody-BOoEezj0.js";import{t as Bt}from"./file-text-C38JjRJ1.js";import{d as Ql,u as Pn}from"./sheet-0KNjJ51X.js";import{t as oe}from"./badge-DHxSYw-Q.js";import{t as Re}from"./input-Fk8aRl_M.js";import{t as ts}from"./EmptyState-BUS2fndv.js";import{t as Pe}from"./PageSkeleton-DaSQo8P8.js";import{$t as Hl,Ct as Ys,Dt as An,Et as En,G as Gl,H as Wl,J as Yl,K as Xl,Q as Zl,St as Jl,Tt as er,U as sr,W as tr,X as nr,Y as lr,Z as rr,_ as ar,an as ir,at as on,bt as or,c as dr,cn as cr,d as ur,et as mr,f as qs,fn as xr,g as hr,gn as pr,h as gr,hn as wt,in as Kn,it as Mn,jt as fr,l as br,ln as jr,lt as ge,m as qn,mn as $n,nn as yr,nt as kr,o as vr,ot as ss,p as ft,pn as Ns,rt as Sr,s as Nr,sn as Ct,tt as wr,u as Cr,v as Fr,vn as Ft,vt as Ir,wt as bt,xt as jt,y as Dr,yn as dn,yt as Pt}from"./index-ChreIWPq.js";var u=Sn(jl(),1),e=Sn(Sl(),1),cn=16,un=24,mn="min-h-9";function xn(n){return(0,e.jsx)("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",...n,children:(0,e.jsx)("path",{d:"M12 4 21 19H3z"})})}l(xn,"VercelMark");function Rn(n){const i=n.replace(/\r\n/g,`
|
|
2
2
|
`);if(!i.startsWith(`---
|
|
3
3
|
`))return i.trim();const a=i.indexOf(`
|
|
4
4
|
---
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var yt=Object.defineProperty;var u=(e,a)=>yt(e,"name",{value:a,configurable:!0});import{i as at}from"./rolldown-runtime-ZpX3ckPj.js";import{B as bt,Ft as v,Sa as vt,da as wt,ji as V,mt as Ct,ni as jt,ua as Mt,xt as Q}from"./agent-avatar-url-CdlBp9p9.js";import{ct as Nt,f as kt,i as J,n as Pt,r as tt,s as et}from"./BreadcrumbContext-NYKl3jAM.js";import{t as Dt}from"./AgentAvatar-CTdkXzmh.js";import{n as Tt,t as Zt}from"./useHiddenSettings-BBSXECTf.js";import{t as Yt}from"./card-DkWQn3lf.js";import{t as rt}from"./EmptyState-BUS2fndv.js";import{t as Et}from"./PageSkeleton-DaSQo8P8.js";import{Ht as Xt,Rt as _t,dn as $t,en as zt,hn as Rt,un as nt}from"./index-Dt9g_rra.js";var o=at(vt(),1),n=at(Mt(),1),k=200,S=100,$=32,St=80,W=60,Wt=.2,Ht=2,A=6;function Y(e){if(e.reports.length===0)return k;const a=e.reports.reduce((i,x)=>i+Y(x),0),d=(e.reports.length-1)*$;return Math.max(k,a+d)}u(Y,"subtreeWidth");function ct(e,a,d){const i=Y(e),x=[];if(e.reports.length>0){const j=e.reports.reduce((P,D)=>P+Y(D),0),H=(e.reports.length-1)*$;let M=a+(i-j-H)/2;for(const P of e.reports){const D=Y(P);x.push(ct(P,M,d+S+St)),M+=D+$}}return{id:e.id,name:e.name,role:e.role,status:e.status,x:a+(i-k)/2,y:d,children:x}}u(ct,"layoutTree");function Lt(e){if(e.length===0)return[];e.reduce((x,j)=>x+Y(j),0),(e.length-1)*$;let a=W;const d=W,i=[];for(const x of e){const j=Y(x);i.push(ct(x,a,d)),a+=j+$}return i}u(Lt,"layoutForest");function At(e){const a=[];function d(i){a.push(i),i.children.forEach(d)}return u(d,"walk"),e.forEach(d),a}u(At,"flattenLayout");function Ot(e){const a=[];function d(i){for(const x of i.children)a.push({parent:i,child:x}),d(x)}return u(d,"walk"),e.forEach(d),a}u(Ot,"collectEdges");function O(e){return Math.min(Math.max(e,Wt),Ht)}u(O,"clampZoom");function Bt(e){return{x:e.clientX,y:e.clientY}}u(Bt,"touchPoint");function st(e,a){const d=e.clientX-a.clientX,i=e.clientY-a.clientY;return Math.hypot(d,i)}u(st,"touchDistance");function ot(e,a,d){const i=d.getBoundingClientRect();return{x:(e.clientX+a.clientX)/2-i.left,y:(e.clientY+a.clientY)/2-i.top}}u(ot,"touchCenter");var It={running:"var(--hex-22d3ee)",active:"var(--hex-4ade80)",paused:"var(--hex-facc15)",idle:"var(--hex-facc15)",error:"var(--hex-f87171)",terminated:"var(--hex-a3a3a3)"},qt="var(--hex-a3a3a3)";function oe(){wt();const{selectedCompanyId:e}=Ct(),{setBreadcrumbs:a}=Pt(),d=kt(),i=!!Xt(),{hidden:x}=Zt(),j=!i&&!x.has("company.import"),H=!x.has("company.export"),{data:M,isLoading:P}=V({queryKey:Q.org(e),queryFn:u(()=>tt.org(e),"queryFn"),enabled:!!e}),{data:D}=V({queryKey:Q.agents.list(e),queryFn:u(()=>tt.list(e),"queryFn"),enabled:!!e}),it=(0,o.useMemo)(()=>{const t=new Map;for(const r of D??[])t.set(r.id,r);return t},[D]);(0,o.useEffect)(()=>{a([{label:v("Org Chart")}])},[a]);const z=(0,o.useMemo)(()=>Lt(M??[]),[M]),T=(0,o.useMemo)(()=>At(z),[z]),lt=(0,o.useMemo)(()=>Ot(z),[z]),w=(0,o.useMemo)(()=>{if(T.length===0)return{width:800,height:600};let t=0,r=0;for(const s of T)t=Math.max(t,s.x+k),r=Math.max(r,s.y+S);return{width:t+W,height:r+W}},[T]),p=(0,o.useRef)(null),[l,N]=(0,o.useState)({x:0,y:0}),[h,E]=(0,o.useState)(1),[L,B]=(0,o.useState)(!1),X=(0,o.useRef)({x:0,y:0,panX:0,panY:0}),m=(0,o.useRef)({mode:null,startPoint:{x:0,y:0},startPan:{x:0,y:0},startZoom:1,startDistance:0,startCenter:{x:0,y:0},moved:!1}),R=(0,o.useRef)(!1),Z=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{Z.current!==null&&window.clearTimeout(Z.current)},[]);const I=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(I.current||T.length===0||!p.current)return;I.current=!0;const t=p.current,r=t.clientWidth,s=t.clientHeight,c=(r-40)/w.width,f=(s-40)/w.height,g=Math.min(c,f,1),y=w.width*g,C=w.height*g;E(g),N({x:(r-y)/2,y:(s-C)/2})},[T,w]);const ut=(0,o.useCallback)(t=>{t.button===0&&(t.target.closest("[data-org-card]")||(B(!0),X.current={x:t.clientX,y:t.clientY,panX:l.x,panY:l.y}))},[l]),dt=(0,o.useCallback)(t=>{if(!L)return;const r=t.clientX-X.current.x,s=t.clientY-X.current.y;N({x:X.current.panX+r,y:X.current.panY+s})},[L]),q=(0,o.useCallback)(()=>{B(!1)},[]),ht=(0,o.useCallback)(t=>{t.preventDefault();const r=p.current;if(!r)return;const s=r.getBoundingClientRect(),c=t.clientX-s.left,f=t.clientY-s.top,g=t.deltaY<0?1.1:.9,y=O(h*g),C=y/h;N({x:c-C*(c-l.x),y:f-C*(f-l.y)}),E(y)},[h,l]),F=(0,o.useCallback)((t,r)=>{const s=O(t),c=s/h;N({x:r.x-c*(r.x-l.x),y:r.y-c*(r.y-l.y)}),E(s)},[h,l]),mt=(0,o.useCallback)(()=>{if(!p.current)return;const t=p.current.clientWidth,r=p.current.clientHeight,s=(t-40)/w.width,c=(r-40)/w.height,f=Math.min(s,c,1),g=w.width*f,y=w.height*f;E(f),N({x:(t-g)/2,y:(r-y)/2})},[w]),xt=(0,o.useCallback)(t=>{if(t.touches.length>=2&&p.current){const[s,c]=[t.touches[0],t.touches[1]];m.current={mode:"pinch",startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:st(s,c),startCenter:ot(s,c,p.current),moved:!1};return}const r=t.touches[0];r&&(m.current={mode:"pan",startPoint:Bt(r),startPan:l,startZoom:h,startDistance:0,startCenter:{x:0,y:0},moved:!1})},[l,h]),ft=(0,o.useCallback)(t=>{const r=p.current;if(!r||!m.current.mode)return;if(t.touches.length>=2){const[g,y]=[t.touches[0],t.touches[1]],C=st(g,y),_=ot(g,y,r);if(m.current.mode!=="pinch"||m.current.startDistance===0){m.current={mode:"pinch",startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:C,startCenter:_,moved:!1};return}const b=m.current,U=O(b.startZoom*(C/b.startDistance)),K=U/b.startZoom,gt=_.x-b.startCenter.x,pt=_.y-b.startCenter.y;b.moved=b.moved||Math.abs(C-b.startDistance)>A||Math.hypot(gt,pt)>A,E(U),N({x:_.x-K*(b.startCenter.x-b.startPan.x),y:_.y-K*(b.startCenter.y-b.startPan.y)});return}const s=t.touches[0];if(!s||m.current.mode!=="pan")return;const c=s.clientX-m.current.startPoint.x,f=s.clientY-m.current.startPoint.y;m.current.moved=m.current.moved||Math.hypot(c,f)>A,N({x:m.current.startPan.x+c,y:m.current.startPan.y+f})},[l,h]),G=(0,o.useCallback)(()=>{m.current.moved&&(R.current=!0,Z.current!==null&&window.clearTimeout(Z.current),Z.current=window.setTimeout(()=>{R.current=!1,Z.current=null},400)),m.current={mode:null,startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:0,startCenter:{x:0,y:0},moved:!1}},[l,h]);return e?P?(0,n.jsx)(Et,{variant:"org-chart"}):M&&M.length===0?(0,n.jsx)(rt,{icon:nt,message:v("No organizational hierarchy defined.")}):(0,n.jsxs)("div",{className:"flex h-(--sz-calc-38) min-h-(--sz-420px) flex-col md:h-full md:min-h-0",children:[(0,n.jsxs)("div",{className:"mb-2 flex shrink-0 flex-wrap items-center justify-start gap-2",children:[j&&(0,n.jsx)(et,{to:"/company/import",children:(0,n.jsxs)(J,{variant:"outline",size:"sm",children:[(0,n.jsx)(zt,{className:"mr-1.5 h-3.5 w-3.5"}),v("Import company")]})}),H&&(0,n.jsx)(et,{to:"/company/export",children:(0,n.jsxs)(J,{variant:"outline",size:"sm",children:[(0,n.jsx)(Rt,{className:"mr-1.5 h-3.5 w-3.5"}),v("Export company")]})})]}),(0,n.jsxs)("div",{ref:p,"data-testid":"org-chart-viewport",className:"w-full flex-1 min-h-0 overflow-hidden relative bg-muted/20 border border-border rounded-lg",style:{cursor:L?"grabbing":"grab",touchAction:"none",overscrollBehavior:"contain"},onMouseDown:ut,onMouseMove:dt,onMouseUp:q,onMouseLeave:q,onWheel:ht,onTouchStart:xt,onTouchMove:ft,onTouchEnd:G,onTouchCancel:G,children:[(0,n.jsxs)("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1.5",children:[(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-sm transition-colors hover:bg-accent sm:size-7",onClick:u(()=>{const t=p.current;t&&F(h*1.2,{x:t.clientWidth/2,y:t.clientHeight/2})},"onClick"),title:v("Zoom in"),"aria-label":v("Zoom in"),children:(0,n.jsx)(Nt,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})}),(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-sm transition-colors hover:bg-accent sm:size-7",onClick:u(()=>{const t=p.current;t&&F(h*.8,{x:t.clientWidth/2,y:t.clientHeight/2})},"onClick"),title:v("Zoom out"),"aria-label":v("Zoom out"),children:(0,n.jsx)(Tt,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})}),(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-(length:--text-nano) transition-colors hover:bg-accent sm:size-7",onClick:mt,title:v("Fit to screen"),"aria-label":v("Fit chart to screen"),children:(0,n.jsx)($t,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})})]}),(0,n.jsx)("svg",{className:"absolute inset-0 pointer-events-none",style:{width:"100%",height:"100%"},children:(0,n.jsx)("g",{transform:`translate(${l.x}, ${l.y}) scale(${h})`,children:lt.map(({parent:t,child:r})=>{const s=t.x+k/2,c=t.y+S,f=r.x+k/2,g=r.y,y=(c+g)/2;return(0,n.jsx)("path",{d:`M ${s} ${c} L ${s} ${y} L ${f} ${y} L ${f} ${g}`,fill:"none",stroke:"var(--border)",strokeWidth:1.5},`${t.id}-${r.id}`)})})}),(0,n.jsx)("div",{"data-testid":"org-chart-card-layer",className:"absolute inset-0",style:{transform:`translate(${l.x}px, ${l.y}px) scale(${h})`,transformOrigin:"0 0"},children:T.map(t=>{const r=it.get(t.id),s=It[t.status]??qt;return(0,n.jsx)(Yt,{"data-org-card":!0,className:"block absolute py-0 hover:shadow-md hover:border-foreground/20 transition-(--tp-box-shadow-border-color) duration-150 cursor-pointer select-none",style:{left:t.x,top:t.y,width:k,minHeight:S},onClick:u(()=>d(r?bt(r):`/agents/${t.id}`),"onClick"),onClickCapture:u(c=>{R.current&&(R.current=!1,c.preventDefault(),c.stopPropagation())},"onClickCapture"),children:(0,n.jsxs)("div",{className:"flex items-center px-4 py-3 gap-3",children:[(0,n.jsxs)("div",{className:"relative shrink-0",children:[(0,n.jsx)("div",{className:"w-9 h-9 rounded-full bg-muted flex items-center justify-center",children:(0,n.jsx)(Dt,{agent:r,size:16,className:"h-4.5 w-4.5 text-foreground/70"})}),(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-card",style:{backgroundColor:s}})]}),(0,n.jsxs)("div",{className:"flex flex-col items-start min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-foreground leading-tight",children:t.name}),(0,n.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground leading-tight mt-0.5",children:r?.title??Gt(t.role)}),r&&(0,n.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground/60 font-mono leading-tight mt-1",children:_t(r.adapterType)}),r&&r.capabilities&&(0,n.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground/80 leading-tight mt-1 line-clamp-2",children:r.capabilities})]})]})},t.id)})})]})]}):(0,n.jsx)(rt,{icon:nt,message:v("Select a company to view the org chart.")})}u(oe,"OrgChart");var Ft=jt;function Gt(e){return v(`agentRole.${e}`,{defaultValue:Ft[e]??e})}u(Gt,"roleLabel");export{oe as OrgChart};
|
|
1
|
+
var yt=Object.defineProperty;var u=(e,a)=>yt(e,"name",{value:a,configurable:!0});import{i as at}from"./rolldown-runtime-ZpX3ckPj.js";import{B as bt,Ft as v,Sa as vt,da as wt,ji as V,mt as Ct,ni as jt,ua as Mt,xt as Q}from"./agent-avatar-url-CdlBp9p9.js";import{ct as Nt,f as kt,i as J,n as Pt,r as tt,s as et}from"./BreadcrumbContext-NYKl3jAM.js";import{t as Dt}from"./AgentAvatar-CTdkXzmh.js";import{n as Tt,t as Zt}from"./useHiddenSettings-BBSXECTf.js";import{t as Yt}from"./card-DkWQn3lf.js";import{t as rt}from"./EmptyState-BUS2fndv.js";import{t as Et}from"./PageSkeleton-DaSQo8P8.js";import{Ht as Xt,Rt as _t,dn as $t,en as zt,hn as Rt,un as nt}from"./index-ChreIWPq.js";var o=at(vt(),1),n=at(Mt(),1),k=200,S=100,$=32,St=80,W=60,Wt=.2,Ht=2,A=6;function Y(e){if(e.reports.length===0)return k;const a=e.reports.reduce((i,x)=>i+Y(x),0),d=(e.reports.length-1)*$;return Math.max(k,a+d)}u(Y,"subtreeWidth");function ct(e,a,d){const i=Y(e),x=[];if(e.reports.length>0){const j=e.reports.reduce((P,D)=>P+Y(D),0),H=(e.reports.length-1)*$;let M=a+(i-j-H)/2;for(const P of e.reports){const D=Y(P);x.push(ct(P,M,d+S+St)),M+=D+$}}return{id:e.id,name:e.name,role:e.role,status:e.status,x:a+(i-k)/2,y:d,children:x}}u(ct,"layoutTree");function Lt(e){if(e.length===0)return[];e.reduce((x,j)=>x+Y(j),0),(e.length-1)*$;let a=W;const d=W,i=[];for(const x of e){const j=Y(x);i.push(ct(x,a,d)),a+=j+$}return i}u(Lt,"layoutForest");function At(e){const a=[];function d(i){a.push(i),i.children.forEach(d)}return u(d,"walk"),e.forEach(d),a}u(At,"flattenLayout");function Ot(e){const a=[];function d(i){for(const x of i.children)a.push({parent:i,child:x}),d(x)}return u(d,"walk"),e.forEach(d),a}u(Ot,"collectEdges");function O(e){return Math.min(Math.max(e,Wt),Ht)}u(O,"clampZoom");function Bt(e){return{x:e.clientX,y:e.clientY}}u(Bt,"touchPoint");function st(e,a){const d=e.clientX-a.clientX,i=e.clientY-a.clientY;return Math.hypot(d,i)}u(st,"touchDistance");function ot(e,a,d){const i=d.getBoundingClientRect();return{x:(e.clientX+a.clientX)/2-i.left,y:(e.clientY+a.clientY)/2-i.top}}u(ot,"touchCenter");var It={running:"var(--hex-22d3ee)",active:"var(--hex-4ade80)",paused:"var(--hex-facc15)",idle:"var(--hex-facc15)",error:"var(--hex-f87171)",terminated:"var(--hex-a3a3a3)"},qt="var(--hex-a3a3a3)";function oe(){wt();const{selectedCompanyId:e}=Ct(),{setBreadcrumbs:a}=Pt(),d=kt(),i=!!Xt(),{hidden:x}=Zt(),j=!i&&!x.has("company.import"),H=!x.has("company.export"),{data:M,isLoading:P}=V({queryKey:Q.org(e),queryFn:u(()=>tt.org(e),"queryFn"),enabled:!!e}),{data:D}=V({queryKey:Q.agents.list(e),queryFn:u(()=>tt.list(e),"queryFn"),enabled:!!e}),it=(0,o.useMemo)(()=>{const t=new Map;for(const r of D??[])t.set(r.id,r);return t},[D]);(0,o.useEffect)(()=>{a([{label:v("Org Chart")}])},[a]);const z=(0,o.useMemo)(()=>Lt(M??[]),[M]),T=(0,o.useMemo)(()=>At(z),[z]),lt=(0,o.useMemo)(()=>Ot(z),[z]),w=(0,o.useMemo)(()=>{if(T.length===0)return{width:800,height:600};let t=0,r=0;for(const s of T)t=Math.max(t,s.x+k),r=Math.max(r,s.y+S);return{width:t+W,height:r+W}},[T]),p=(0,o.useRef)(null),[l,N]=(0,o.useState)({x:0,y:0}),[h,E]=(0,o.useState)(1),[L,B]=(0,o.useState)(!1),X=(0,o.useRef)({x:0,y:0,panX:0,panY:0}),m=(0,o.useRef)({mode:null,startPoint:{x:0,y:0},startPan:{x:0,y:0},startZoom:1,startDistance:0,startCenter:{x:0,y:0},moved:!1}),R=(0,o.useRef)(!1),Z=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{Z.current!==null&&window.clearTimeout(Z.current)},[]);const I=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(I.current||T.length===0||!p.current)return;I.current=!0;const t=p.current,r=t.clientWidth,s=t.clientHeight,c=(r-40)/w.width,f=(s-40)/w.height,g=Math.min(c,f,1),y=w.width*g,C=w.height*g;E(g),N({x:(r-y)/2,y:(s-C)/2})},[T,w]);const ut=(0,o.useCallback)(t=>{t.button===0&&(t.target.closest("[data-org-card]")||(B(!0),X.current={x:t.clientX,y:t.clientY,panX:l.x,panY:l.y}))},[l]),dt=(0,o.useCallback)(t=>{if(!L)return;const r=t.clientX-X.current.x,s=t.clientY-X.current.y;N({x:X.current.panX+r,y:X.current.panY+s})},[L]),q=(0,o.useCallback)(()=>{B(!1)},[]),ht=(0,o.useCallback)(t=>{t.preventDefault();const r=p.current;if(!r)return;const s=r.getBoundingClientRect(),c=t.clientX-s.left,f=t.clientY-s.top,g=t.deltaY<0?1.1:.9,y=O(h*g),C=y/h;N({x:c-C*(c-l.x),y:f-C*(f-l.y)}),E(y)},[h,l]),F=(0,o.useCallback)((t,r)=>{const s=O(t),c=s/h;N({x:r.x-c*(r.x-l.x),y:r.y-c*(r.y-l.y)}),E(s)},[h,l]),mt=(0,o.useCallback)(()=>{if(!p.current)return;const t=p.current.clientWidth,r=p.current.clientHeight,s=(t-40)/w.width,c=(r-40)/w.height,f=Math.min(s,c,1),g=w.width*f,y=w.height*f;E(f),N({x:(t-g)/2,y:(r-y)/2})},[w]),xt=(0,o.useCallback)(t=>{if(t.touches.length>=2&&p.current){const[s,c]=[t.touches[0],t.touches[1]];m.current={mode:"pinch",startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:st(s,c),startCenter:ot(s,c,p.current),moved:!1};return}const r=t.touches[0];r&&(m.current={mode:"pan",startPoint:Bt(r),startPan:l,startZoom:h,startDistance:0,startCenter:{x:0,y:0},moved:!1})},[l,h]),ft=(0,o.useCallback)(t=>{const r=p.current;if(!r||!m.current.mode)return;if(t.touches.length>=2){const[g,y]=[t.touches[0],t.touches[1]],C=st(g,y),_=ot(g,y,r);if(m.current.mode!=="pinch"||m.current.startDistance===0){m.current={mode:"pinch",startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:C,startCenter:_,moved:!1};return}const b=m.current,U=O(b.startZoom*(C/b.startDistance)),K=U/b.startZoom,gt=_.x-b.startCenter.x,pt=_.y-b.startCenter.y;b.moved=b.moved||Math.abs(C-b.startDistance)>A||Math.hypot(gt,pt)>A,E(U),N({x:_.x-K*(b.startCenter.x-b.startPan.x),y:_.y-K*(b.startCenter.y-b.startPan.y)});return}const s=t.touches[0];if(!s||m.current.mode!=="pan")return;const c=s.clientX-m.current.startPoint.x,f=s.clientY-m.current.startPoint.y;m.current.moved=m.current.moved||Math.hypot(c,f)>A,N({x:m.current.startPan.x+c,y:m.current.startPan.y+f})},[l,h]),G=(0,o.useCallback)(()=>{m.current.moved&&(R.current=!0,Z.current!==null&&window.clearTimeout(Z.current),Z.current=window.setTimeout(()=>{R.current=!1,Z.current=null},400)),m.current={mode:null,startPoint:{x:0,y:0},startPan:l,startZoom:h,startDistance:0,startCenter:{x:0,y:0},moved:!1}},[l,h]);return e?P?(0,n.jsx)(Et,{variant:"org-chart"}):M&&M.length===0?(0,n.jsx)(rt,{icon:nt,message:v("No organizational hierarchy defined.")}):(0,n.jsxs)("div",{className:"flex h-(--sz-calc-38) min-h-(--sz-420px) flex-col md:h-full md:min-h-0",children:[(0,n.jsxs)("div",{className:"mb-2 flex shrink-0 flex-wrap items-center justify-start gap-2",children:[j&&(0,n.jsx)(et,{to:"/company/import",children:(0,n.jsxs)(J,{variant:"outline",size:"sm",children:[(0,n.jsx)(zt,{className:"mr-1.5 h-3.5 w-3.5"}),v("Import company")]})}),H&&(0,n.jsx)(et,{to:"/company/export",children:(0,n.jsxs)(J,{variant:"outline",size:"sm",children:[(0,n.jsx)(Rt,{className:"mr-1.5 h-3.5 w-3.5"}),v("Export company")]})})]}),(0,n.jsxs)("div",{ref:p,"data-testid":"org-chart-viewport",className:"w-full flex-1 min-h-0 overflow-hidden relative bg-muted/20 border border-border rounded-lg",style:{cursor:L?"grabbing":"grab",touchAction:"none",overscrollBehavior:"contain"},onMouseDown:ut,onMouseMove:dt,onMouseUp:q,onMouseLeave:q,onWheel:ht,onTouchStart:xt,onTouchMove:ft,onTouchEnd:G,onTouchCancel:G,children:[(0,n.jsxs)("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1.5",children:[(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-sm transition-colors hover:bg-accent sm:size-7",onClick:u(()=>{const t=p.current;t&&F(h*1.2,{x:t.clientWidth/2,y:t.clientHeight/2})},"onClick"),title:v("Zoom in"),"aria-label":v("Zoom in"),children:(0,n.jsx)(Nt,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})}),(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-sm transition-colors hover:bg-accent sm:size-7",onClick:u(()=>{const t=p.current;t&&F(h*.8,{x:t.clientWidth/2,y:t.clientHeight/2})},"onClick"),title:v("Zoom out"),"aria-label":v("Zoom out"),children:(0,n.jsx)(Tt,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})}),(0,n.jsx)("button",{className:"flex size-9 items-center justify-center rounded border border-border bg-background text-(length:--text-nano) transition-colors hover:bg-accent sm:size-7",onClick:mt,title:v("Fit to screen"),"aria-label":v("Fit chart to screen"),children:(0,n.jsx)($t,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"})})]}),(0,n.jsx)("svg",{className:"absolute inset-0 pointer-events-none",style:{width:"100%",height:"100%"},children:(0,n.jsx)("g",{transform:`translate(${l.x}, ${l.y}) scale(${h})`,children:lt.map(({parent:t,child:r})=>{const s=t.x+k/2,c=t.y+S,f=r.x+k/2,g=r.y,y=(c+g)/2;return(0,n.jsx)("path",{d:`M ${s} ${c} L ${s} ${y} L ${f} ${y} L ${f} ${g}`,fill:"none",stroke:"var(--border)",strokeWidth:1.5},`${t.id}-${r.id}`)})})}),(0,n.jsx)("div",{"data-testid":"org-chart-card-layer",className:"absolute inset-0",style:{transform:`translate(${l.x}px, ${l.y}px) scale(${h})`,transformOrigin:"0 0"},children:T.map(t=>{const r=it.get(t.id),s=It[t.status]??qt;return(0,n.jsx)(Yt,{"data-org-card":!0,className:"block absolute py-0 hover:shadow-md hover:border-foreground/20 transition-(--tp-box-shadow-border-color) duration-150 cursor-pointer select-none",style:{left:t.x,top:t.y,width:k,minHeight:S},onClick:u(()=>d(r?bt(r):`/agents/${t.id}`),"onClick"),onClickCapture:u(c=>{R.current&&(R.current=!1,c.preventDefault(),c.stopPropagation())},"onClickCapture"),children:(0,n.jsxs)("div",{className:"flex items-center px-4 py-3 gap-3",children:[(0,n.jsxs)("div",{className:"relative shrink-0",children:[(0,n.jsx)("div",{className:"w-9 h-9 rounded-full bg-muted flex items-center justify-center",children:(0,n.jsx)(Dt,{agent:r,size:16,className:"h-4.5 w-4.5 text-foreground/70"})}),(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-card",style:{backgroundColor:s}})]}),(0,n.jsxs)("div",{className:"flex flex-col items-start min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-foreground leading-tight",children:t.name}),(0,n.jsx)("span",{className:"text-(length:--text-micro) text-muted-foreground leading-tight mt-0.5",children:r?.title??Gt(t.role)}),r&&(0,n.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground/60 font-mono leading-tight mt-1",children:_t(r.adapterType)}),r&&r.capabilities&&(0,n.jsx)("span",{className:"text-(length:--text-nano) text-muted-foreground/80 leading-tight mt-1 line-clamp-2",children:r.capabilities})]})]})},t.id)})})]})]}):(0,n.jsx)(rt,{icon:nt,message:v("Select a company to view the org chart.")})}u(oe,"OrgChart");var Ft=jt;function Gt(e){return v(`agentRole.${e}`,{defaultValue:Ft[e]??e})}u(Gt,"roleLabel");export{oe as OrgChart};
|
package/dist/assets/{RoutineDetail.production-CeeDo7Fb.js → RoutineDetail.production-Ct7EKEYL.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
var lt=Object.defineProperty;var i=(s,r)=>lt(s,"name",{value:r,configurable:!0});import{i as Ve}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as U,Ft as n,G as dt,Sa as ut,Tt as mt,da as W,ji as V,la as pt,mt as ht,ua as gt,xt as h}from"./agent-avatar-url-CdlBp9p9.js";import{An as Oe,Bn as xt,X as yt,ct as vt,f as ft,i as O,l as le,n as bt,nt as jt,r as wt}from"./BreadcrumbContext-NYKl3jAM.js";import{n as St,t as _,y as Nt}from"./label-D53vUXGD.js";import{St as kt,_t as It,ar as Ct,ht as _e,t as At,vt as Pt,xt as Rt,yt as Dt}from"./RoutineRunVariablesDialog-BzNyiJ8N.js";import{$ as Tt}from"./mention-chips-BGwhkP2B.js";import{t as Me}from"./AgentAvatar-CTdkXzmh.js";import{E as Et,T as Ot}from"./checkbox-DSDEd9xJ.js";import{a as E,t as Fe}from"./MarkdownEditor-C2xaZOWa.js";import{h as _t}from"./StatusIcon-Cw0scYdd.js";import{t as ve}from"./arrow-right-BNgvgYSb.js";import{a as Mt}from"./ToastContext-CkRLuVem.js";import{r as Ft,t as qt}from"./clipboard-BcdF-0DW.js";import{a as me,c as pe,l as he,n as ge,r as xe}from"./select-b1sMyjd5.js";import{i as Kt,r as Lt}from"./use-copy-action-JdR8Lk1e.js";import{t as Ut}from"./heartbeats-CtWMFcNw.js";import{t as fe}from"./badge-DHxSYw-Q.js";import{t as z}from"./input-Fk8aRl_M.js";import{c as Vt,u as Wt}from"./i18n-labels-Dmmlv1ZF.js";import{r as $t,t as Gt}from"./card-DkWQn3lf.js";import{t as ie}from"./EmptyState-BUS2fndv.js";import{t as zt}from"./PageSkeleton-DaSQo8P8.js";import{A as Qt,B as We,Bt as qe,C as Bt,D as Ht,E as Jt,F as Xt,I as Ke,It as Yt,L as $e,M as Zt,Mt as es,N as ts,Nt as ss,O as is,P as ns,Qt as as,R as B,S as rs,T as os,V as cs,_n as be,_t as ls,bn as ds,j as us,k as ms,on as ps,w as Ge,x as hs,z as gs,zt as te}from"./index-Dt9g_rra.js";var m=Ve(ut(),1);function xs(s,r,a){const d={label:r.label.trim()||null};return s.kind==="schedule"&&(d.cronExpression=r.cronExpression.trim(),d.timezone=s.timezone??a),s.kind==="webhook"&&(d.signingMode=r.signingMode,d.replayWindowSec=Number(r.replayWindowSec||"300")),d}i(xs,"buildRoutineTriggerPatch");var e=Ve(gt(),1),ys=["app_webhook","bearer","hmac_sha256","github_hmac","none"],vs=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function fs(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(fs,"getLocalTimezone$1");function bs({trigger:s,onSave:r,onRotate:a,onDelete:d,disabled:o}){const{t:p}=W(),[l,S]=(0,m.useState)({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)});(0,m.useEffect)(()=>{S({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)})},[s]);const T=s.kind==="schedule"?be:s.kind==="webhook"?as:yt,M=s.kind==="schedule"?Jt(l.cronExpression):null,C=/fail|error/i.test(s.lastResult??""),A=s.lastResult?.startsWith("Created execution issue ")?"Task created":s.lastResult;return(0,e.jsxs)("form",{"aria-label":p("routineDetail.triggerAriaLabel",{defaultValue:"Trigger: {{label}}",label:s.label??s.kind}),className:"space-y-4 rounded-lg border border-border p-4",onSubmit:i(b=>b.preventDefault(),"onSubmit"),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 items-center gap-2 text-sm font-medium",children:[(0,e.jsx)(T,{className:"h-3.5 w-3.5 shrink-0"}),(0,e.jsx)("span",{className:"truncate",children:s.label??s.kind})]}),M?(0,e.jsx)("p",{id:`cron-readable-${s.id}`,className:"text-xs text-muted-foreground",children:M}):null]}),(0,e.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[s.lastResult?(0,e.jsx)(fe,{variant:C?"destructive":"secondary",children:A}):null,(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.kind==="schedule"&&s.nextRunAt?p("routineDetail.nextAt",{defaultValue:"Next: {{time}}",time:new Date(s.nextRunAt).toLocaleString()}):s.kind==="webhook"?"Webhook":"API"})]})]}),s.kind==="webhook"&&s.webhookUrl&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{htmlFor:`webhook-url-${s.id}`,className:"text-xs",children:n("Webhook URL")}),(0,e.jsx)(z,{id:`webhook-url-${s.id}`,value:s.webhookUrl,readOnly:!0,onFocus:i(b=>b.target.select(),"onFocus")}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("Send a POST request with Content-Type: application/json. Keep this URL private when signing is disabled.")})]}),(0,e.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("Label",{defaultValue:"Label"})}),(0,e.jsx)(z,{value:l.label,disabled:o,onChange:i(b=>S(k=>({...k,label:b.target.value})),"onChange")})]}),s.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(_,{className:"text-xs",children:p("Schedule",{defaultValue:"Schedule"})}),(0,e.jsx)(Ge,{value:l.cronExpression,onChange:i(b=>S(k=>({...k,cronExpression:b})),"onChange")})]}),s.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("routineDetail.signingMode",{defaultValue:"Signing mode"})}),(0,e.jsxs)(ge,{value:l.signingMode,onValueChange:i(b=>S(k=>({...k,signingMode:b})),"onValueChange"),disabled:o,children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:ys.map(b=>(0,e.jsx)(me,{value:b,children:b},b))})]})]}),!vs.has(l.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("routineDetail.replayWindowSeconds",{defaultValue:"Replay window (seconds)"})}),(0,e.jsx)(z,{value:l.replayWindowSec,disabled:o,onChange:i(b=>S(k=>({...k,replayWindowSec:b.target.value})),"onChange")})]})]})]}),!o&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsxs)(O,{variant:"ghost",size:"sm",className:"mr-auto text-muted-foreground hover:text-destructive",onClick:i(()=>d(s.id),"onClick"),children:[(0,e.jsx)(Ot,{className:"mr-1.5 h-3.5 w-3.5"}),p("Delete",{defaultValue:"Delete"})]}),s.kind==="webhook"&&(0,e.jsxs)(O,{variant:"outline",size:"sm",onClick:i(()=>a(s.id),"onClick"),children:[(0,e.jsx)(Et,{className:"mr-1.5 h-3.5 w-3.5"}),p("routineDetail.rotateSecret",{defaultValue:"Rotate secret"})]}),(0,e.jsxs)(O,{variant:"outline",size:"sm",onClick:i(()=>r(s.id,xs(s,l,fs())),"onClick"),children:[(0,e.jsx)(Lt,{className:"mr-1.5 h-3.5 w-3.5"}),p("routineDetail.saveTrigger",{defaultValue:"Save trigger"})]})]})]})}i(bs,"RoutineTriggerCard");var js=[{value:"coalesce_if_active",title:"Coalesce if active",description:"Keep one follow-up run queued while an active run is still working."},{value:"always_enqueue",title:"Always enqueue",description:"Queue every trigger occurrence, even if several runs stack up."},{value:"skip_if_active",title:"Skip if active",description:"Drop overlapping trigger occurrences while the routine is already active."}],ws=[{value:"skip_missed",title:"Skip missed",description:"Ignore schedule windows that were missed while paused."},{value:"enqueue_missed_with_cap",title:"Enqueue missed with cap",description:"Catch up missed schedule windows after recovery; sub-hourly schedules are combined into one catch-up run, slower schedules replay each missed window up to a cap."}],Ss=[{value:"always",title:"Run on every scheduled tick",description:"Fire on the schedule no matter what — the default behavior."},{value:"require_external_activity",title:"Skip when there's been no activity since the last run",description:"On a scheduled tick, only run if something happened since the last run that finished. Lets a watcher-style routine stay asleep while the system is settled instead of burning tokens."}],Ns=[{value:"company",title:"Company-wide",description:"Any activity across the company counts as a reason to run."},{value:"project",title:"This project",description:"Only activity in the routine's project counts as a reason to run."}],ks=["schedule","webhook"],Is=["app_webhook","bearer","hmac_sha256","github_hmac","none"],Cs={bearer:"Send Authorization: Bearer <secret> with each request.",hmac_sha256:"Send X-Paperclip-Timestamp and X-Paperclip-Signature: sha256=<hex>, signing timestamp + a dot + the exact JSON body.",github_hmac:"Accept GitHub-style X-Hub-Signature-256 header (HMAC over raw body, no timestamp).",app_webhook:"Accept a bearer token or an HMAC-SHA256 signature over the exact request body in X-Hub-Signature or X-Hub-Signature-256.",fireflies_hmac:"Signed webhook (legacy).",none:"No authentication — the webhook URL itself acts as a shared secret."},As=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function Ps({defaultDescriptionAnnotationsOpen:s=!1}={}){W();const{routine:r,editDraft:a,setEditDraft:d,assigneeOptions:o,projectOptions:p,recentAssigneeIds:l,recentProjectIds:S,agentById:T,projectById:M,currentAssignee:C,currentProject:A,mentionOptions:b,assigneeSelectorRef:k,projectSelectorRef:q,descriptionEditorRef:P,routineRuns:x,activity:j,saveRoutine:N,saveConflict:ne,isSectionDirty:v,navigateToSection:R}=B(),[w,F]=(0,m.useState)(s),c=r.triggers.length,H=(0,m.useMemo)(()=>{const u=r.triggers.filter(y=>y.kind==="schedule"&&y.nextRunAt).map(y=>new Date(y.nextRunAt)).sort((y,Q)=>y.getTime()-Q.getTime())[0];return u?u.toLocaleString():null},[r.triggers]),$=a.env?Object.keys(a.env).length:0,D=(x??[])[0]??null,J=(j??[]).slice(0,5);return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsx)("div",{className:"overflow-x-auto overscroll-x-contain",children:(0,e.jsxs)("div",{className:"inline-flex min-w-full flex-wrap items-center gap-2 text-sm text-muted-foreground sm:min-w-max sm:flex-nowrap",children:[(0,e.jsx)("span",{children:n("For")}),(0,e.jsx)(_e,{ref:k,value:a.assigneeAgentId,options:o,recentOptionIds:l,placeholder:n("Responsible"),noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:n("routines.noResponsibleFound"),onChange:i(u=>d(y=>({...y,assigneeAgentId:u})),"onChange"),onConfirm:i(()=>{a.projectId?P.current?.focus():q.current?.focus()},"onConfirm"),renderTriggerValue:i(u=>u?C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Me,{agent:C,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,e.jsx)("span",{className:"truncate",children:u.label})]}):(0,e.jsx)("span",{className:"truncate",children:u.label}):(0,e.jsx)("span",{className:"text-muted-foreground",children:n("Responsible")}),"renderTriggerValue"),renderOption:i(u=>{if(!u.id)return(0,e.jsx)("span",{className:"truncate",children:u.label});const y=T.get(u.id);return(0,e.jsxs)(e.Fragment,{children:[y?(0,e.jsx)(Me,{agent:y,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,e.jsx)("span",{className:"truncate",children:u.label})]})},"renderOption")}),(0,e.jsx)("span",{children:n("in")}),(0,e.jsx)(_e,{ref:q,value:a.projectId,options:p,recentOptionIds:S,placeholder:n("Project"),noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:n("No projects found."),onChange:i(u=>d(y=>({...y,projectId:u})),"onChange"),onConfirm:i(()=>P.current?.focus(),"onConfirm"),renderTriggerValue:i(u=>u&&A?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:A.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:u.label})]}):(0,e.jsx)("span",{className:"text-muted-foreground",children:n("Project")}),"renderTriggerValue"),renderOption:i(u=>{if(!u.id)return(0,e.jsx)("span",{className:"truncate",children:u.label});const y=M.get(u.id);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:y?.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:u.label})]})},"renderOption")})]})}),r.assigneeAgentId?null:(0,e.jsx)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm text-amber-900 dark:text-amber-200",children:n("routineDetail.defaultAgentRequiredNotice")}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("div",{className:"flex items-center justify-end",children:r.descriptionDocument?(0,e.jsx)(es,{issueId:r.id,docKey:"description",target:{kind:"routine",routineId:r.id,documentKey:"description"},panelOpen:w,onToggle:i(()=>F(u=>!u),"onToggle")}):null}),r.descriptionDocument?(0,e.jsx)(ss,{issueId:r.id,doc:r.descriptionDocument,target:{kind:"routine",routineId:r.id,documentKey:"description"},bodyMarkdown:a.description,draftDirty:v("overview")||N.isPending,draftConflicted:ne,historicalPreview:!1,locationHash:typeof window>"u"?"":window.location.hash,panelOpen:w,onPanelOpenChange:F,children:(0,e.jsx)(Fe,{ref:P,value:a.description,onChange:i(u=>d(y=>({...y,description:u})),"onChange"),placeholder:n("Add instructions..."),bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:b,onSubmit:i(()=>{!N.isPending&&a.title.trim()&&N.mutate()},"onSubmit")})}):(0,e.jsx)(Fe,{ref:P,value:a.description,onChange:i(u=>d(y=>({...y,description:u})),"onChange"),placeholder:n("Add instructions..."),bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:b,onSubmit:i(()=>{!N.isPending&&a.title.trim()&&N.mutate()},"onSubmit")})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(cs,{}),(0,e.jsx)(We,{title:a.title,description:a.description,value:a.variables,onChange:i(u=>d(y=>({...y,variables:u})),"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsx)(de,{icon:be,label:n("Triggers"),value:c===0?"None":`${c} active`,hint:H?`Next fire ${H}`:"No schedule",to:i(()=>R("triggers"),"to"),ariaLabel:`${c} triggers. Open triggers.`}),(0,e.jsx)(de,{icon:Ft,label:n("Secrets"),value:$===0?"None":`${$} bound`,hint:"Manage bound secrets",to:i(()=>R("secrets"),"to"),ariaLabel:`${$} secrets bound. Open secrets.`}),(0,e.jsx)(de,{icon:Nt,label:n("Last run"),value:D?D.status.replaceAll("_"," "):"No runs",hint:D?Oe(D.triggeredAt):"Trigger a run",to:i(()=>R("runs"),"to"),ariaLabel:D?`Last run ${D.status}. Open runs.`:"No runs. Open runs."})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("Recent activity")}),J.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("No activity yet.")}):(0,e.jsxs)("div",{className:"divide-y divide-border/60",children:[J.map(u=>(0,e.jsxs)("div",{className:"flex items-center gap-2 py-1.5 text-xs",children:[(0,e.jsx)(fe,{variant:"outline",className:"shrink-0 font-mono",children:u.action}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:u.details&&Object.keys(u.details).length>0?Object.keys(u.details).slice(0,3).join(" · "):""}),(0,e.jsx)("span",{className:"shrink-0 text-muted-foreground/60",children:Oe(u.createdAt)})]},u.id)),(0,e.jsxs)("button",{type:"button",onClick:i(()=>R("activity"),"onClick"),className:"flex items-center gap-1 pt-2 text-xs text-muted-foreground hover:text-foreground",children:[n("routineDetail.viewAllActivity")," ",(0,e.jsx)(ve,{className:"h-3 w-3"})]})]})]})]})}i(Ps,"OverviewSection");function de({icon:s,label:r,value:a,hint:d,to:o,ariaLabel:p}){return(0,e.jsx)("button",{type:"button",onClick:o,"aria-label":p,className:"text-left",children:(0,e.jsx)(Gt,{className:"gap-2 p-4 transition-colors hover:border-border hover:bg-accent/30",children:(0,e.jsxs)($t,{className:"space-y-1 p-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5 text-xs uppercase tracking-wide text-muted-foreground",children:[(0,e.jsx)(s,{className:"h-3.5 w-3.5"}),r,(0,e.jsx)(ve,{className:"ml-auto h-3.5 w-3.5 text-muted-foreground/60"})]}),(0,e.jsx)("p",{className:"text-lg font-semibold",children:a}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:d})]})})})}i(de,"SummaryCard");function Rs(){W();const{routine:s,newTrigger:r,setNewTrigger:a,createTrigger:d,updateTrigger:o,deleteTrigger:p,rotateTrigger:l,secretMessage:S,copySecretValue:T,setSecretMessage:M}=B(),[C,A]=(0,m.useState)(!1),[b,k]=(0,m.useState)(!0),q=(0,m.useMemo)(()=>r.kind==="schedule"?os(r.cronExpression):null,[r.cronExpression,r.kind]),P=d.isPending||(q?!q.valid||!b:!1);return(0,m.useEffect)(()=>{r.kind!=="schedule"&&k(!0)},[r.kind]),(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:s.triggers.length===0?"No triggers yet":`${s.triggers.length} trigger${s.triggers.length===1?"":"s"}`}),(0,e.jsx)(O,{size:"sm",variant:C?"secondary":"default",onClick:i(()=>A(x=>!x),"onClick"),"aria-expanded":C,children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Tt,{className:"mr-1.5 h-3.5 w-3.5"}),n("Cancel")]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(vt,{className:"mr-1.5 h-3.5 w-3.5"}),n("routineDetail.newTrigger")]})})]}),C?(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-border p-4",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:n("Add trigger")}),(0,e.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Kind")}),(0,e.jsxs)(ge,{value:r.kind,onValueChange:i(x=>a(j=>({...j,kind:x})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:ks.map(x=>(0,e.jsx)(me,{value:x,children:x},x))})]})]}),r.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Schedule")}),(0,e.jsx)(Ge,{value:r.cronExpression,onChange:i(x=>a(j=>({...j,cronExpression:x})),"onChange"),onValidityChange:k})]}),r.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Signing mode")}),(0,e.jsxs)(ge,{value:r.signingMode,onValueChange:i(x=>a(j=>({...j,signingMode:x})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:Is.map(x=>(0,e.jsx)(me,{value:x,children:x},x))})]}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:Cs[r.signingMode]})]}),!As.has(r.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Replay window (seconds)")}),(0,e.jsx)(z,{value:r.replayWindowSec,onChange:i(x=>a(j=>({...j,replayWindowSec:x.target.value})),"onChange")})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)(O,{size:"sm",variant:"ghost",onClick:i(()=>A(!1),"onClick"),children:n("Cancel")}),(0,e.jsx)(O,{size:"sm",onClick:i(()=>d.mutate(void 0,{onSuccess:i(()=>{a($e()),A(!1)},"onSuccess")}),"onClick"),disabled:P,children:d.isPending?"Adding...":"Add trigger"})]})]}):null,S?(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-border bg-muted/20 p-4 text-sm",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-medium",children:S.title}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("routineDetail.saveSecretNow")})]}),(0,e.jsx)("div",{className:"space-y-3",children:S.entries.map((x,j)=>(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(z,{"aria-label":n("New webhook URL"),value:x.webhookUrl,readOnly:!0,className:"flex-1"}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>T("Webhook URL",x.webhookUrl),"onClick"),children:"URL"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(z,{"aria-label":n("New webhook secret"),value:x.webhookSecret,readOnly:!0,className:"flex-1"}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>T("Webhook secret",x.webhookSecret),"onClick"),children:n("agentConfig.secret")})]})]},`${x.webhookUrl}-${j}`))}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>M(null),"onClick"),children:n("Done")})]}):null,s.triggers.length===0?(0,e.jsx)(ie,{icon:be,message:n("routineDetail.noTriggersYetPeriod"),action:n("Add a trigger"),onAction:i(()=>A(!0),"onAction")}):(0,e.jsx)("div",{className:"space-y-3",children:s.triggers.map(x=>(0,e.jsx)(bs,{trigger:x,onSave:i((j,N)=>o.mutate({id:j,patch:N}),"onSave"),onRotate:i(j=>l.mutate(j),"onRotate"),onDelete:i(j=>p.mutate(j),"onDelete")},x.id))})]})}i(Rs,"TriggersSection");function Ds(){W();const{editDraft:s,setEditDraft:r,navigateToSection:a}=B(),d=s.variables.length>0;return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-border bg-muted/20 px-4 py-3 text-xs",children:[(0,e.jsxs)("span",{className:"flex-1 text-muted-foreground",children:[n("routineDetail.variablesAutoDetectedPrefix"),(0,e.jsx)("code",{className:"font-mono",children:"{{placeholders}}"})," ",n("in the title & instructions. The variable name is read-only — rename by editing the placeholder.")]}),(0,e.jsxs)(O,{variant:"secondary",size:"sm",onClick:i(()=>a("overview"),"onClick"),children:[(0,e.jsx)(ps,{className:"mr-1.5 h-3.5 w-3.5"}),n("routineDetail.editInstructions")]})]}),d?(0,e.jsx)(We,{title:s.title,description:s.description,value:s.variables,onChange:i(o=>r(p=>({...p,variables:o})),"onChange")}):(0,e.jsx)(ie,{icon:ds,message:"No variables yet. Add a {{placeholder}} in the title or instructions to create one.",action:n("routineDetail.editInstructions"),onAction:i(()=>a("overview"),"onAction")})]})}i(Ds,"VariablesSection");function Ts(){W();const{editDraft:s,setEditDraft:r,availableSecrets:a,createSecret:d}=B(),o=(0,m.useMemo)(()=>[...a].filter(p=>p.status==="active").sort((p,l)=>{const S=(l.referenceCount??0)-(p.referenceCount??0);return S!==0?S:new Date(l.updatedAt).getTime()-new Date(p.updatedAt).getTime()}).slice(0,8),[a]);return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"rounded-md border border-border bg-muted/20 px-4 py-3 text-xs text-muted-foreground",children:[n("routineDetail.secretsApplyPrefix")," ",(0,e.jsx)("span",{className:"font-mono",children:"PAPERCLIP_*"})," ",n("routineDetail.secretsReservedSuffix")]}),(0,e.jsx)(Yt,{value:s.env??{},secrets:a,recentlyUsedSecrets:o,onCreateSecret:i(async(p,l)=>d.mutateAsync({name:p,value:l}),"onCreateSecret"),onChange:i(p=>r(l=>({...l,env:p??null})),"onChange")})]})}i(Ts,"SecretsSection");function Es(){W();const{editDraft:s,setEditDraft:r,routine:a}=B(),d=a.triggers.some(p=>p.kind==="schedule"),o=s.activityGatePolicy==="require_external_activity";return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("Concurrency")}),(0,e.jsx)(te,{ariaLabel:"Concurrency policy",value:s.concurrencyPolicy,onValueChange:i(p=>r(l=>({...l,concurrencyPolicy:p})),"onValueChange"),options:js})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("Catch-up")}),(0,e.jsx)(te,{ariaLabel:"Catch-up policy",value:s.catchUpPolicy,onValueChange:i(p=>r(l=>({...l,catchUpPolicy:p})),"onValueChange"),options:ws})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("agentConfig.advancedRunPolicy")}),(0,e.jsx)(te,{ariaLabel:"Advanced run policy",value:s.activityGatePolicy,onValueChange:i(p=>r(l=>({...l,activityGatePolicy:p})),"onValueChange"),options:Ss,disabled:!d}),d?o?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-border p-3",children:[(0,e.jsx)(_,{className:"text-xs font-medium",children:n("routineEditor.activityScope")}),(0,e.jsx)(te,{ariaLabel:"Activity gate scope",value:s.activityGateScope,onValueChange:i(p=>r(l=>({...l,activityGateScope:p})),"onValueChange"),options:Ns})]}):null:(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("routineEditor.scheduleTriggerHint")})]}),(0,e.jsx)(_s,{triggers:a.triggers,concurrencyPolicy:s.concurrencyPolicy})]})}i(Es,"DeliverySection");var Os={queued:"text-emerald-600 dark:text-emerald-400",coalesced:"text-amber-600 dark:text-amber-400",skipped:"text-muted-foreground"};function _s({triggers:s,concurrencyPolicy:r}){W();const a=(0,m.useMemo)(()=>{const d=s.filter(o=>o.kind==="schedule"&&o.enabled&&o.cronExpression).map(o=>({trigger:o,fires:Ht(o.cronExpression,5,{timeZone:o.timezone??"UTC"})})).filter(o=>o.fires.length>0).sort((o,p)=>o.fires[0].getTime()-p.fires[0].getTime())[0];return d?{timeZone:d.trigger.timezone??"UTC",entries:is(d.fires,r)}:null},[s,r]);return(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("routineDetail.nextFiveFires")}),a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"space-y-1.5 rounded-lg border border-border p-3 font-mono text-xs",children:a.entries.map((d,o)=>(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"text-muted-foreground/40",children:"·"}),(0,e.jsx)("span",{className:"tabular-nums",children:Ms(d.at,a.timeZone)}),(0,e.jsx)(ve,{className:"h-3 w-3 shrink-0 text-muted-foreground/50"}),(0,e.jsx)("span",{className:dt("font-medium",Os[d.disposition]),children:d.label}),d.note?(0,e.jsxs)("span",{className:"truncate text-muted-foreground/60",children:["(",d.note,")"]}):null]},o))}),(0,e.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/60",children:[n("routineDetail.previewAssumesPreviousRun")," ",a.timeZone,n(".")]})]}):(0,e.jsx)("p",{className:"rounded-lg border border-dashed border-border p-3 text-xs text-muted-foreground",children:n("routineDetail.noSchedulePreview")})]})}i(_s,"NextFiresPreview");function Ms(s,r){try{return new Intl.DateTimeFormat(void 0,{timeZone:r,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(s).replace(",","")}catch{return s.toISOString()}}i(Ms,"formatFireTime");var ye="paperclip.routineLastSection";function Fs(s){return s.filter(r=>!r.archivedAt).map(r=>({id:r.id,label:r.name,searchText:r.description??""}))}i(Fs,"buildRoutineProjectOptions");var qs={overview:"Overview",triggers:"Triggers",variables:"Variables",secrets:"Secrets",delivery:"Delivery",runs:"Runs",activity:"Activity",history:"History"};function se(s){return s!=null&&ns.includes(s)}i(se,"isRoutineSection");function Ks(s){try{const r=localStorage.getItem(ye);if(!r)return null;const a=JSON.parse(r)[s];return se(a)?a:null}catch{return null}}i(Ks,"readLastSection");function ue(s,r){try{const a=localStorage.getItem(ye),d=a?JSON.parse(a):{};d[s]=r,localStorage.setItem(ye,JSON.stringify(d))}catch{}}i(ue,"writeLastSection");var Le={triggers:"triggers",runs:"runs",activity:"activity",secrets:"secrets",history:"history"};function Ue(s){s&&(s.style.height="auto",s.style.height=`${s.scrollHeight}px`)}i(Ue,"autoResizeTextarea");function Ls(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(Ls,"getLocalTimezone");function Us(s){return{...s,description:s.description.trim()||null,projectId:s.projectId||null,assigneeAgentId:s.assigneeAgentId||null,env:s.env&&Object.keys(s.env).length>0?s.env:null}}i(Us,"buildRoutineMutationPayload");function mi(){W();const{routineId:s,section:r}=xt(),{selectedCompanyId:a}=ht(),{setBreadcrumbs:d}=bt(),o=pt(),p=ft(),{pushToast:l}=Mt(),S=(0,m.useRef)(null),T=(0,m.useRef)(null),M=(0,m.useRef)(null),C=(0,m.useRef)(null),A=(0,m.useRef)(null),[b,k]=(0,m.useState)(null),[q,P]=(0,m.useState)(!1),[x,j]=(0,m.useState)(!1),[N,ne]=(0,m.useState)($e),[v,R]=(0,m.useState)({title:"",description:"",projectId:"",assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",activityGatePolicy:"always",activityGateScope:"company",variables:[],env:null}),w=se(r)?r:"overview",F=(0,m.useCallback)((t,g)=>{s&&(ue(s,t),p(`/routines/${s}/${t}`,{replace:g?.replace??!0}))},[p,s]),{data:c,isLoading:H,error:$}=V({queryKey:h.routines.detail(s),queryFn:i(()=>E.get(s),"queryFn"),enabled:!!s}),D=c?.activeIssue?.id,{data:J}=V({queryKey:h.issues.liveRuns(D),queryFn:i(()=>Ut.liveRunsForIssue(D),"queryFn"),enabled:!!D,refetchInterval:3e3}),u=(J??[]).length>0,{data:y}=V({queryKey:h.routines.runs(s),queryFn:i(()=>E.listRuns(s),"queryFn"),enabled:!!s,refetchInterval:u?3e3:!1}),Q=(0,m.useMemo)(()=>({triggerIds:c?.triggers.map(t=>t.id)??[],runIds:y?.map(t=>t.id)??[]}),[c?.triggers,y]),{data:ze}=V({queryKey:[...h.routines.activity(a,s),Q.triggerIds.join(","),Q.runIds.join(",")],queryFn:i(()=>E.activity(a,s,Q),"queryFn"),enabled:!!a&&!!s&&!!c}),{data:K}=V({queryKey:h.agents.list(a),queryFn:i(()=>wt.list(a),"queryFn"),enabled:!!a}),{data:L}=V({queryKey:h.projects.list(a,{includeArchived:!0}),queryFn:i(()=>_t.list(a,{includeArchived:!0}),"queryFn"),enabled:!!a}),{data:je}=V({queryKey:h.access.companyUserDirectory(a),queryFn:i(()=>Wt.listUserDirectory(a),"queryFn"),enabled:!!a}),{data:Qe=[]}=V({queryKey:a?h.secrets.list(a):["secrets","none"],queryFn:i(()=>qe.list(a),"queryFn"),enabled:!!a}),Be=U({mutationFn:i(t=>{if(!a)throw new Error("Select a company to create secrets");return qe.create(a,t)},"mutationFn"),onSuccess:i(()=>{a&&o.invalidateQueries({queryKey:h.secrets.list(a)})},"onSuccess")}),f=(0,m.useMemo)(()=>c?{title:c.title,description:c.description??"",projectId:c.projectId??"",assigneeAgentId:c.assigneeAgentId??"",priority:c.priority,concurrencyPolicy:c.concurrencyPolicy,catchUpPolicy:c.catchUpPolicy,activityGatePolicy:c.activityGatePolicy,activityGateScope:c.activityGateScope,variables:c.variables,env:c.env??null}:null,[c]),X=(0,m.useMemo)(()=>{if(!f)return[];const t=[];return v.title!==f.title&&t.push({key:"title",label:n("routineDetail.dirty.title")}),v.description!==f.description&&t.push({key:"description",label:n("routineDetail.dirty.description")}),v.projectId!==f.projectId&&t.push({key:"projectId",label:"the project"}),v.assigneeAgentId!==f.assigneeAgentId&&t.push({key:"assigneeAgentId",label:n("routineDetail.dirty.defaultAgent")}),v.priority!==f.priority&&t.push({key:"priority",label:n("routineDetail.dirty.priority")}),v.concurrencyPolicy!==f.concurrencyPolicy&&t.push({key:"concurrencyPolicy",label:n("routineDetail.dirty.concurrency")}),v.catchUpPolicy!==f.catchUpPolicy&&t.push({key:"catchUpPolicy",label:n("routineDetail.dirty.catchUp")}),v.activityGatePolicy!==f.activityGatePolicy&&t.push({key:"activityGatePolicy",label:n("the advanced run policy")}),v.activityGateScope!==f.activityGateScope&&t.push({key:"activityGateScope",label:n("the activity gate scope")}),JSON.stringify(v.variables)!==JSON.stringify(f.variables)&&t.push({key:"variables",label:n("routineDetail.dirty.variables")}),JSON.stringify(v.env??null)!==JSON.stringify(f.env??null)&&t.push({key:"env",label:n("routineDetail.dirty.secrets")}),t},[v,f]),ae=X.length>0,Y=(0,m.useCallback)(t=>{const g=Ke[t];return g?X.filter(I=>g.includes(I.key)):[]},[X]),re=(0,m.useCallback)(t=>Y(t).length>0,[Y]),we=(0,m.useCallback)(t=>{if(!f)return;const g=Ke[t];g&&R(I=>{const Te={...I};for(const Ee of g)Te[Ee]=f[Ee];return Te})},[f]);(0,m.useEffect)(()=>{c&&(d([{label:n("Routines"),href:"/routines"},{label:c.title}]),f&&(S.current!==c.id||!ae)&&(R(f),S.current=c.id))},[c,f,ae,d]),(0,m.useEffect)(()=>{Ue(T.current)},[v.title,c?.id]),(0,m.useEffect)(()=>{s&&se(r)&&ue(s,r)},[s,r]);const He=(0,m.useCallback)(async(t,g)=>{try{await qt(g),l({title:`${t} copied`,tone:"success"})}catch(I){l({title:`Failed to copy ${t.toLowerCase()}`,body:I instanceof Error?I.message:"Clipboard access was denied.",tone:"error"})}},[l]),Z=U({mutationFn:i(()=>{const t=Us(v),g=c?.latestRevisionId??null;return E.update(s,{...t,...g?{baseRevisionId:g}:{}})},"mutationFn"),onSuccess:i(async()=>{P(!1),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)}),o.invalidateQueries({queryKey:h.routines.revisions(s)})])},"onSuccess"),onError:i(t=>{if(t instanceof mt&&t.status===409){P(!0),l({title:n("routineDetail.routineChanged"),body:"Someone else updated this routine. Reload to see the latest revision.",tone:"warn"});return}l({title:n("Failed to save routine"),body:t instanceof Error?t.message:"Paperclip could not save the routine.",tone:"error"})},"onError")}),ee=U({mutationFn:i(t=>E.run(s,{...t?.variables&&Object.keys(t.variables).length>0?{variables:t.variables}:{},...t?.assigneeAgentId!==void 0?{assigneeAgentId:t.assigneeAgentId}:{},...t?.projectId!==void 0?{projectId:t.projectId}:{},...t?.executionWorkspaceId!==void 0?{executionWorkspaceId:t.executionWorkspaceId}:{},...t?.executionWorkspacePreference!==void 0?{executionWorkspacePreference:t.executionWorkspacePreference}:{},...t?.executionWorkspaceSettings!==void 0?{executionWorkspaceSettings:t.executionWorkspaceSettings}:{}}),"mutationFn"),onSuccess:i(async()=>{l({title:n("Routine run started"),tone:"success"}),j(!1),F("runs"),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.runs(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Routine run failed"),body:t instanceof Error?t.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),Se=U({mutationFn:i(t=>E.update(s,{status:t}),"mutationFn"),onSuccess:i(async(t,g)=>{l({title:n("Routine saved"),body:g==="paused"?"Automation paused.":"Automation enabled.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to update routine"),body:t instanceof Error?t.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Je=U({mutationFn:i(async()=>{const t=(c?.triggers??[]).filter(I=>I.kind===N.kind).length,g=t>0?`${N.kind}-${t+1}`:N.kind;return E.createTrigger(s,{kind:N.kind,label:g,...N.kind==="schedule"?{cronExpression:N.cronExpression.trim(),timezone:Ls()}:{},...N.kind==="webhook"?{signingMode:N.signingMode,replayWindowSec:Number(N.replayWindowSec||"300")}:{}})},"mutationFn"),onSuccess:i(async t=>{t.secretMaterial?k({title:n("Webhook trigger created"),entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}):l({title:n("routineDetail.triggerAdded"),body:"The routine schedule was saved.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to add trigger"),body:t instanceof Error?t.message:"Paperclip could not create the trigger.",tone:"error"})},"onError")}),Xe=U({mutationFn:i(({id:t,patch:g})=>E.updateTrigger(t,g),"mutationFn"),onSuccess:i(async()=>{l({title:n("routineDetail.triggerSaved"),body:"The routine cadence update was saved.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to update trigger"),body:t instanceof Error?t.message:"Paperclip could not update the trigger.",tone:"error"})},"onError")}),Ye=U({mutationFn:i(t=>E.deleteTrigger(t),"mutationFn"),onSuccess:i(async()=>{l({title:n("routineDetail.triggerDeleted"),tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to delete trigger"),body:t instanceof Error?t.message:"Paperclip could not delete the trigger.",tone:"error"})},"onError")}),Ze=U({mutationFn:i(t=>E.rotateTriggerSecret(t),"mutationFn"),onSuccess:i(async t=>{k({title:n("Webhook secret rotated"),entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to rotate webhook secret"),body:t instanceof Error?t.message:"Paperclip could not rotate the webhook secret.",tone:"error"})},"onError")}),Ne=(0,m.useMemo)(()=>new Map((K??[]).map(t=>[t.id,t])),[K]),ke=(0,m.useMemo)(()=>new Map((L??[]).map(t=>[t.id,t])),[L]),oe=(0,m.useMemo)(()=>Dt(),[c?.id]),et=(0,m.useMemo)(()=>It(),[c?.id]),tt=(0,m.useMemo)(()=>Rt((K??[]).filter(t=>t.status!=="terminated"),oe).map(t=>({id:t.id,label:t.name,searchText:`${t.name} ${t.role} ${t.title??""}`})),[K,oe]),st=(0,m.useMemo)(()=>Fs(L??[]),[L]),it=(0,m.useMemo)(()=>Vt({agents:K,projects:(L??[]).filter(t=>!t.archivedAt),members:je?.users}),[K,je?.users,L]),nt=(0,m.useCallback)(t=>{R(g=>{const I=typeof t=="function"?t(g):t;return I.assigneeAgentId&&I.assigneeAgentId!==g.assigneeAgentId&&kt(I.assigneeAgentId),I.projectId&&I.projectId!==g.projectId&&Pt(I.projectId),I})},[]),at=v.assigneeAgentId?Ne.get(v.assigneeAgentId)??null:null,rt=v.projectId?ke.get(v.projectId)??null:null,Ie=(0,m.useCallback)(()=>{P(!1),f&&R(f),o.invalidateQueries({queryKey:h.routines.detail(s)})},[o,f,s]),ot=(0,m.useCallback)(t=>{t.secretMaterials.length>0&&(F("triggers"),k({title:t.secretMaterials.length===1?n("routineDetail.webhookTriggerRestored"):`${t.secretMaterials.length} webhook triggers restored`,entries:t.secretMaterials.map(g=>({webhookUrl:g.webhookUrl,webhookSecret:g.webhookSecret}))}))},[F]),ct=(0,m.useCallback)(t=>{P(!1),o.setQueryData(h.routines.detail(s),g=>g&&{...g,...t.routine,latestRevisionId:t.revision.id,latestRevisionNumber:t.revision.revisionNumber}),R({title:t.routine.title,description:t.routine.description??"",projectId:t.routine.projectId??"",assigneeAgentId:t.routine.assigneeAgentId??"",priority:t.routine.priority,concurrencyPolicy:t.routine.concurrencyPolicy,catchUpPolicy:t.routine.catchUpPolicy,activityGatePolicy:t.routine.activityGatePolicy,activityGateScope:t.routine.activityGateScope,variables:t.routine.variables,env:t.routine.env??null}),S.current=t.routine.id},[o,s]);if(!a)return(0,e.jsx)(ie,{icon:Ct,message:n("Select a company to view routines.")});const ce=new URLSearchParams(window.location.search).get("tab");if(s&&ce&&Le[ce])return(0,e.jsx)(le,{to:`/routines/${s}/${Le[ce]}`,replace:!0});if(s&&!r){const t=Ks(s)??"overview";return(0,e.jsx)(le,{to:`/routines/${s}/${t}`,replace:!0})}if(s&&r&&!se(r))return(0,e.jsx)(le,{to:`/routines/${s}/overview`,replace:!0});if(H)return(0,e.jsx)(zt,{variant:"issues-list"});if($||!c||!f)return(0,e.jsx)(ie,{icon:Kt,message:$ instanceof Error?$.message:n("routineDetail.loadFailedBody")});const G=c.status==="active",Ce=Se.isPending||c.status==="archived",Ae=c.status==="archived"?"Archived":c.assigneeAgentId?G?"Active":"Paused":"Draft",Pe=c.status==="archived"?"text-muted-foreground":G?"text-emerald-400":"text-muted-foreground",Re={routine:c,routineId:s,companyId:c.companyId,editDraft:v,setEditDraft:nt,routineDefaults:f,dirtyFields:X,isEditDirty:ae,sectionDirtyFields:Y,isSectionDirty:re,discardSection:we,saveRoutine:Z,saveConflict:q,reloadLatest:Ie,automationEnabled:G,automationLabel:Ae,automationLabelClassName:Pe,automationToggleDisabled:Ce,onToggleAutomation:i(()=>{if(!G&&!c.assigneeAgentId){l({title:n("Default agent required"),body:"Set a default agent before enabling routine automation.",tone:"warn"});return}Se.mutate(G?"paused":"active")},"onToggleAutomation"),onOpenRunDialog:i(()=>j(!0),"onOpenRunDialog"),runRoutinePending:ee.isPending,newTrigger:N,setNewTrigger:ne,createTrigger:Je,updateTrigger:Xe,deleteTrigger:Ye,rotateTrigger:Ze,secretMessage:b,setSecretMessage:k,copySecretValue:He,availableSecrets:Qe,createSecret:Be,agents:K??[],projects:L??[],agentById:Ne,projectById:ke,assigneeOptions:tt,projectOptions:st,recentAssigneeIds:oe,recentProjectIds:et,mentionOptions:it,currentAssignee:at,currentProject:rt,routineRuns:y,activity:ze,hasLiveRun:u,activeIssueId:D,titleInputRef:T,descriptionEditorRef:M,assigneeSelectorRef:C,projectSelectorRef:A,onHistoryRestoreSecretMaterials:ot,onHistoryRestored:ct,navigateToSection:F},De=ts.includes(w);return(0,e.jsxs)(Xt.Provider,{value:Re,children:[(0,e.jsx)("a",{href:"#routine-section",className:"sr-only focus:not-sr-only focus:absolute focus:left-2 focus:top-2 focus:z-20 focus:rounded focus:bg-background focus:px-3 focus:py-1.5 focus:text-sm",children:n("routineDetail.skipToSection")}),(0,e.jsxs)("div",{className:"-m-4 flex h-full min-h-0 flex-col overflow-hidden md:-m-6",children:[(0,e.jsxs)("header",{className:"flex h-14 shrink-0 items-center gap-3 border-b border-border bg-background px-6",children:[(0,e.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[(0,e.jsx)("textarea",{ref:T,"data-autosize-title":!0,className:"min-w-0 flex-1 resize-none overflow-hidden bg-transparent text-base font-semibold leading-7 outline-none placeholder:text-muted-foreground/50",placeholder:n("Routine title"),rows:1,value:v.title,onChange:i(t=>{R(g=>({...g,title:t.target.value})),Ue(t.target)},"onChange"),onKeyDown:i(t=>{t.key==="Enter"&&!t.metaKey&&!t.ctrlKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),w==="overview"?M.current?.focus():F("overview"))},"onKeyDown")}),c.managedByPlugin?(0,e.jsxs)(fe,{variant:"outline",className:"hidden shrink-0 gap-1.5 text-xs text-muted-foreground sm:inline-flex",children:[(0,e.jsx)(jt,{className:"h-3 w-3"}),c.managedByPlugin.pluginDisplayName,(0,e.jsx)("span",{className:"font-mono text-(length:--text-nano)",children:c.managedByPlugin.resourceKey})]}):null]}),(0,e.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-3",children:[(0,e.jsx)(ls,{onClick:i(()=>j(!0),"onClick"),disabled:ee.isPending}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(St,{size:"default",checked:G,onCheckedChange:Re.onToggleAutomation,disabled:Ce,"aria-label":G?n("Pause automatic triggers"):n("Enable automatic triggers")}),(0,e.jsx)("span",{className:`text-sm font-medium ${Pe}`,children:Ae})]})]})]}),(0,e.jsx)(Qt,{activeSection:w,onNavigate:F,isSectionDirty:re}),(0,e.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,e.jsx)(us,{activeSection:w,hrefFor:i(t=>`/routines/${s}/${t}`,"hrefFor"),isSectionDirty:re,hasLiveRun:u,onNavigate:i(t=>ue(s,t),"onNavigate")}),(0,e.jsx)("main",{id:"routine-section",role:"main",className:"min-h-0 min-w-0 flex-1 overflow-y-auto px-4 pb-6 pt-10 md:px-8",children:(0,e.jsxs)("section",{"aria-labelledby":"routine-section-title",className:De?"mx-auto w-full max-w-3xl":"w-full",children:[(0,e.jsx)(Zt,{title:qs[w],copyText:w==="overview"?gs({editing:!0,draft:v.description,saved:c.description}):null}),w==="overview"&&(0,e.jsx)(Ps,{}),w==="triggers"&&(0,e.jsx)(Rs,{}),w==="variables"&&(0,e.jsx)(Ds,{}),w==="secrets"&&(0,e.jsx)(Ts,{}),w==="delivery"&&(0,e.jsx)(Es,{}),w==="runs"&&(0,e.jsx)(Bt,{}),w==="activity"&&(0,e.jsx)(hs,{}),w==="history"&&(0,e.jsx)(rs,{}),De?(0,e.jsx)(ms,{dirtyFields:Y(w),isSaving:Z.isPending,saveConflict:q,onSave:i(()=>{!Z.isPending&&v.title.trim()&&Z.mutate()},"onSave"),onDiscard:i(()=>we(w),"onDiscard"),onReload:Ie}):null]})})]})]}),(0,e.jsx)(At,{open:x,onOpenChange:j,companyId:c.companyId,routineName:c.title,agents:K??[],projects:L??[],defaultProjectId:c.projectId,defaultAssigneeAgentId:c.assigneeAgentId,variables:c.variables??[],isPending:ee.isPending,onSubmit:i(t=>ee.mutate(t),"onSubmit")})]})}i(mi,"RoutineDetail");export{mi as RoutineDetail};
|
|
1
|
+
var lt=Object.defineProperty;var i=(s,r)=>lt(s,"name",{value:r,configurable:!0});import{i as Ve}from"./rolldown-runtime-ZpX3ckPj.js";import{Ai as U,Ft as n,G as dt,Sa as ut,Tt as mt,da as W,ji as V,la as pt,mt as ht,ua as gt,xt as h}from"./agent-avatar-url-CdlBp9p9.js";import{An as Oe,Bn as xt,X as yt,ct as vt,f as ft,i as O,l as le,n as bt,nt as jt,r as wt}from"./BreadcrumbContext-NYKl3jAM.js";import{n as St,t as _,y as Nt}from"./label-D53vUXGD.js";import{St as kt,_t as It,ar as Ct,ht as _e,t as At,vt as Pt,xt as Rt,yt as Dt}from"./RoutineRunVariablesDialog-BzNyiJ8N.js";import{$ as Tt}from"./mention-chips-BGwhkP2B.js";import{t as Me}from"./AgentAvatar-CTdkXzmh.js";import{E as Et,T as Ot}from"./checkbox-DSDEd9xJ.js";import{a as E,t as Fe}from"./MarkdownEditor-C2xaZOWa.js";import{h as _t}from"./StatusIcon-Cw0scYdd.js";import{t as ve}from"./arrow-right-BNgvgYSb.js";import{a as Mt}from"./ToastContext-CkRLuVem.js";import{r as Ft,t as qt}from"./clipboard-BcdF-0DW.js";import{a as me,c as pe,l as he,n as ge,r as xe}from"./select-b1sMyjd5.js";import{i as Kt,r as Lt}from"./use-copy-action-JdR8Lk1e.js";import{t as Ut}from"./heartbeats-CtWMFcNw.js";import{t as fe}from"./badge-DHxSYw-Q.js";import{t as z}from"./input-Fk8aRl_M.js";import{c as Vt,u as Wt}from"./i18n-labels-Dmmlv1ZF.js";import{r as $t,t as Gt}from"./card-DkWQn3lf.js";import{t as ie}from"./EmptyState-BUS2fndv.js";import{t as zt}from"./PageSkeleton-DaSQo8P8.js";import{A as Qt,B as We,Bt as qe,C as Bt,D as Ht,E as Jt,F as Xt,I as Ke,It as Yt,L as $e,M as Zt,Mt as es,N as ts,Nt as ss,O as is,P as ns,Qt as as,R as B,S as rs,T as os,V as cs,_n as be,_t as ls,bn as ds,j as us,k as ms,on as ps,w as Ge,x as hs,z as gs,zt as te}from"./index-ChreIWPq.js";var m=Ve(ut(),1);function xs(s,r,a){const d={label:r.label.trim()||null};return s.kind==="schedule"&&(d.cronExpression=r.cronExpression.trim(),d.timezone=s.timezone??a),s.kind==="webhook"&&(d.signingMode=r.signingMode,d.replayWindowSec=Number(r.replayWindowSec||"300")),d}i(xs,"buildRoutineTriggerPatch");var e=Ve(gt(),1),ys=["app_webhook","bearer","hmac_sha256","github_hmac","none"],vs=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function fs(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(fs,"getLocalTimezone$1");function bs({trigger:s,onSave:r,onRotate:a,onDelete:d,disabled:o}){const{t:p}=W(),[l,S]=(0,m.useState)({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)});(0,m.useEffect)(()=>{S({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)})},[s]);const T=s.kind==="schedule"?be:s.kind==="webhook"?as:yt,M=s.kind==="schedule"?Jt(l.cronExpression):null,C=/fail|error/i.test(s.lastResult??""),A=s.lastResult?.startsWith("Created execution issue ")?"Task created":s.lastResult;return(0,e.jsxs)("form",{"aria-label":p("routineDetail.triggerAriaLabel",{defaultValue:"Trigger: {{label}}",label:s.label??s.kind}),className:"space-y-4 rounded-lg border border-border p-4",onSubmit:i(b=>b.preventDefault(),"onSubmit"),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 items-center gap-2 text-sm font-medium",children:[(0,e.jsx)(T,{className:"h-3.5 w-3.5 shrink-0"}),(0,e.jsx)("span",{className:"truncate",children:s.label??s.kind})]}),M?(0,e.jsx)("p",{id:`cron-readable-${s.id}`,className:"text-xs text-muted-foreground",children:M}):null]}),(0,e.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[s.lastResult?(0,e.jsx)(fe,{variant:C?"destructive":"secondary",children:A}):null,(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.kind==="schedule"&&s.nextRunAt?p("routineDetail.nextAt",{defaultValue:"Next: {{time}}",time:new Date(s.nextRunAt).toLocaleString()}):s.kind==="webhook"?"Webhook":"API"})]})]}),s.kind==="webhook"&&s.webhookUrl&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{htmlFor:`webhook-url-${s.id}`,className:"text-xs",children:n("Webhook URL")}),(0,e.jsx)(z,{id:`webhook-url-${s.id}`,value:s.webhookUrl,readOnly:!0,onFocus:i(b=>b.target.select(),"onFocus")}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("Send a POST request with Content-Type: application/json. Keep this URL private when signing is disabled.")})]}),(0,e.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("Label",{defaultValue:"Label"})}),(0,e.jsx)(z,{value:l.label,disabled:o,onChange:i(b=>S(k=>({...k,label:b.target.value})),"onChange")})]}),s.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(_,{className:"text-xs",children:p("Schedule",{defaultValue:"Schedule"})}),(0,e.jsx)(Ge,{value:l.cronExpression,onChange:i(b=>S(k=>({...k,cronExpression:b})),"onChange")})]}),s.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("routineDetail.signingMode",{defaultValue:"Signing mode"})}),(0,e.jsxs)(ge,{value:l.signingMode,onValueChange:i(b=>S(k=>({...k,signingMode:b})),"onValueChange"),disabled:o,children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:ys.map(b=>(0,e.jsx)(me,{value:b,children:b},b))})]})]}),!vs.has(l.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:p("routineDetail.replayWindowSeconds",{defaultValue:"Replay window (seconds)"})}),(0,e.jsx)(z,{value:l.replayWindowSec,disabled:o,onChange:i(b=>S(k=>({...k,replayWindowSec:b.target.value})),"onChange")})]})]})]}),!o&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsxs)(O,{variant:"ghost",size:"sm",className:"mr-auto text-muted-foreground hover:text-destructive",onClick:i(()=>d(s.id),"onClick"),children:[(0,e.jsx)(Ot,{className:"mr-1.5 h-3.5 w-3.5"}),p("Delete",{defaultValue:"Delete"})]}),s.kind==="webhook"&&(0,e.jsxs)(O,{variant:"outline",size:"sm",onClick:i(()=>a(s.id),"onClick"),children:[(0,e.jsx)(Et,{className:"mr-1.5 h-3.5 w-3.5"}),p("routineDetail.rotateSecret",{defaultValue:"Rotate secret"})]}),(0,e.jsxs)(O,{variant:"outline",size:"sm",onClick:i(()=>r(s.id,xs(s,l,fs())),"onClick"),children:[(0,e.jsx)(Lt,{className:"mr-1.5 h-3.5 w-3.5"}),p("routineDetail.saveTrigger",{defaultValue:"Save trigger"})]})]})]})}i(bs,"RoutineTriggerCard");var js=[{value:"coalesce_if_active",title:"Coalesce if active",description:"Keep one follow-up run queued while an active run is still working."},{value:"always_enqueue",title:"Always enqueue",description:"Queue every trigger occurrence, even if several runs stack up."},{value:"skip_if_active",title:"Skip if active",description:"Drop overlapping trigger occurrences while the routine is already active."}],ws=[{value:"skip_missed",title:"Skip missed",description:"Ignore schedule windows that were missed while paused."},{value:"enqueue_missed_with_cap",title:"Enqueue missed with cap",description:"Catch up missed schedule windows after recovery; sub-hourly schedules are combined into one catch-up run, slower schedules replay each missed window up to a cap."}],Ss=[{value:"always",title:"Run on every scheduled tick",description:"Fire on the schedule no matter what — the default behavior."},{value:"require_external_activity",title:"Skip when there's been no activity since the last run",description:"On a scheduled tick, only run if something happened since the last run that finished. Lets a watcher-style routine stay asleep while the system is settled instead of burning tokens."}],Ns=[{value:"company",title:"Company-wide",description:"Any activity across the company counts as a reason to run."},{value:"project",title:"This project",description:"Only activity in the routine's project counts as a reason to run."}],ks=["schedule","webhook"],Is=["app_webhook","bearer","hmac_sha256","github_hmac","none"],Cs={bearer:"Send Authorization: Bearer <secret> with each request.",hmac_sha256:"Send X-Paperclip-Timestamp and X-Paperclip-Signature: sha256=<hex>, signing timestamp + a dot + the exact JSON body.",github_hmac:"Accept GitHub-style X-Hub-Signature-256 header (HMAC over raw body, no timestamp).",app_webhook:"Accept a bearer token or an HMAC-SHA256 signature over the exact request body in X-Hub-Signature or X-Hub-Signature-256.",fireflies_hmac:"Signed webhook (legacy).",none:"No authentication — the webhook URL itself acts as a shared secret."},As=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function Ps({defaultDescriptionAnnotationsOpen:s=!1}={}){W();const{routine:r,editDraft:a,setEditDraft:d,assigneeOptions:o,projectOptions:p,recentAssigneeIds:l,recentProjectIds:S,agentById:T,projectById:M,currentAssignee:C,currentProject:A,mentionOptions:b,assigneeSelectorRef:k,projectSelectorRef:q,descriptionEditorRef:P,routineRuns:x,activity:j,saveRoutine:N,saveConflict:ne,isSectionDirty:v,navigateToSection:R}=B(),[w,F]=(0,m.useState)(s),c=r.triggers.length,H=(0,m.useMemo)(()=>{const u=r.triggers.filter(y=>y.kind==="schedule"&&y.nextRunAt).map(y=>new Date(y.nextRunAt)).sort((y,Q)=>y.getTime()-Q.getTime())[0];return u?u.toLocaleString():null},[r.triggers]),$=a.env?Object.keys(a.env).length:0,D=(x??[])[0]??null,J=(j??[]).slice(0,5);return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsx)("div",{className:"overflow-x-auto overscroll-x-contain",children:(0,e.jsxs)("div",{className:"inline-flex min-w-full flex-wrap items-center gap-2 text-sm text-muted-foreground sm:min-w-max sm:flex-nowrap",children:[(0,e.jsx)("span",{children:n("For")}),(0,e.jsx)(_e,{ref:k,value:a.assigneeAgentId,options:o,recentOptionIds:l,placeholder:n("Responsible"),noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:n("routines.noResponsibleFound"),onChange:i(u=>d(y=>({...y,assigneeAgentId:u})),"onChange"),onConfirm:i(()=>{a.projectId?P.current?.focus():q.current?.focus()},"onConfirm"),renderTriggerValue:i(u=>u?C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Me,{agent:C,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,e.jsx)("span",{className:"truncate",children:u.label})]}):(0,e.jsx)("span",{className:"truncate",children:u.label}):(0,e.jsx)("span",{className:"text-muted-foreground",children:n("Responsible")}),"renderTriggerValue"),renderOption:i(u=>{if(!u.id)return(0,e.jsx)("span",{className:"truncate",children:u.label});const y=T.get(u.id);return(0,e.jsxs)(e.Fragment,{children:[y?(0,e.jsx)(Me,{agent:y,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,e.jsx)("span",{className:"truncate",children:u.label})]})},"renderOption")}),(0,e.jsx)("span",{children:n("in")}),(0,e.jsx)(_e,{ref:q,value:a.projectId,options:p,recentOptionIds:S,placeholder:n("Project"),noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:n("No projects found."),onChange:i(u=>d(y=>({...y,projectId:u})),"onChange"),onConfirm:i(()=>P.current?.focus(),"onConfirm"),renderTriggerValue:i(u=>u&&A?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:A.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:u.label})]}):(0,e.jsx)("span",{className:"text-muted-foreground",children:n("Project")}),"renderTriggerValue"),renderOption:i(u=>{if(!u.id)return(0,e.jsx)("span",{className:"truncate",children:u.label});const y=M.get(u.id);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:y?.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:u.label})]})},"renderOption")})]})}),r.assigneeAgentId?null:(0,e.jsx)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm text-amber-900 dark:text-amber-200",children:n("routineDetail.defaultAgentRequiredNotice")}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("div",{className:"flex items-center justify-end",children:r.descriptionDocument?(0,e.jsx)(es,{issueId:r.id,docKey:"description",target:{kind:"routine",routineId:r.id,documentKey:"description"},panelOpen:w,onToggle:i(()=>F(u=>!u),"onToggle")}):null}),r.descriptionDocument?(0,e.jsx)(ss,{issueId:r.id,doc:r.descriptionDocument,target:{kind:"routine",routineId:r.id,documentKey:"description"},bodyMarkdown:a.description,draftDirty:v("overview")||N.isPending,draftConflicted:ne,historicalPreview:!1,locationHash:typeof window>"u"?"":window.location.hash,panelOpen:w,onPanelOpenChange:F,children:(0,e.jsx)(Fe,{ref:P,value:a.description,onChange:i(u=>d(y=>({...y,description:u})),"onChange"),placeholder:n("Add instructions..."),bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:b,onSubmit:i(()=>{!N.isPending&&a.title.trim()&&N.mutate()},"onSubmit")})}):(0,e.jsx)(Fe,{ref:P,value:a.description,onChange:i(u=>d(y=>({...y,description:u})),"onChange"),placeholder:n("Add instructions..."),bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:b,onSubmit:i(()=>{!N.isPending&&a.title.trim()&&N.mutate()},"onSubmit")})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(cs,{}),(0,e.jsx)(We,{title:a.title,description:a.description,value:a.variables,onChange:i(u=>d(y=>({...y,variables:u})),"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsx)(de,{icon:be,label:n("Triggers"),value:c===0?"None":`${c} active`,hint:H?`Next fire ${H}`:"No schedule",to:i(()=>R("triggers"),"to"),ariaLabel:`${c} triggers. Open triggers.`}),(0,e.jsx)(de,{icon:Ft,label:n("Secrets"),value:$===0?"None":`${$} bound`,hint:"Manage bound secrets",to:i(()=>R("secrets"),"to"),ariaLabel:`${$} secrets bound. Open secrets.`}),(0,e.jsx)(de,{icon:Nt,label:n("Last run"),value:D?D.status.replaceAll("_"," "):"No runs",hint:D?Oe(D.triggeredAt):"Trigger a run",to:i(()=>R("runs"),"to"),ariaLabel:D?`Last run ${D.status}. Open runs.`:"No runs. Open runs."})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("Recent activity")}),J.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("No activity yet.")}):(0,e.jsxs)("div",{className:"divide-y divide-border/60",children:[J.map(u=>(0,e.jsxs)("div",{className:"flex items-center gap-2 py-1.5 text-xs",children:[(0,e.jsx)(fe,{variant:"outline",className:"shrink-0 font-mono",children:u.action}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:u.details&&Object.keys(u.details).length>0?Object.keys(u.details).slice(0,3).join(" · "):""}),(0,e.jsx)("span",{className:"shrink-0 text-muted-foreground/60",children:Oe(u.createdAt)})]},u.id)),(0,e.jsxs)("button",{type:"button",onClick:i(()=>R("activity"),"onClick"),className:"flex items-center gap-1 pt-2 text-xs text-muted-foreground hover:text-foreground",children:[n("routineDetail.viewAllActivity")," ",(0,e.jsx)(ve,{className:"h-3 w-3"})]})]})]})]})}i(Ps,"OverviewSection");function de({icon:s,label:r,value:a,hint:d,to:o,ariaLabel:p}){return(0,e.jsx)("button",{type:"button",onClick:o,"aria-label":p,className:"text-left",children:(0,e.jsx)(Gt,{className:"gap-2 p-4 transition-colors hover:border-border hover:bg-accent/30",children:(0,e.jsxs)($t,{className:"space-y-1 p-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5 text-xs uppercase tracking-wide text-muted-foreground",children:[(0,e.jsx)(s,{className:"h-3.5 w-3.5"}),r,(0,e.jsx)(ve,{className:"ml-auto h-3.5 w-3.5 text-muted-foreground/60"})]}),(0,e.jsx)("p",{className:"text-lg font-semibold",children:a}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:d})]})})})}i(de,"SummaryCard");function Rs(){W();const{routine:s,newTrigger:r,setNewTrigger:a,createTrigger:d,updateTrigger:o,deleteTrigger:p,rotateTrigger:l,secretMessage:S,copySecretValue:T,setSecretMessage:M}=B(),[C,A]=(0,m.useState)(!1),[b,k]=(0,m.useState)(!0),q=(0,m.useMemo)(()=>r.kind==="schedule"?os(r.cronExpression):null,[r.cronExpression,r.kind]),P=d.isPending||(q?!q.valid||!b:!1);return(0,m.useEffect)(()=>{r.kind!=="schedule"&&k(!0)},[r.kind]),(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:s.triggers.length===0?"No triggers yet":`${s.triggers.length} trigger${s.triggers.length===1?"":"s"}`}),(0,e.jsx)(O,{size:"sm",variant:C?"secondary":"default",onClick:i(()=>A(x=>!x),"onClick"),"aria-expanded":C,children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Tt,{className:"mr-1.5 h-3.5 w-3.5"}),n("Cancel")]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(vt,{className:"mr-1.5 h-3.5 w-3.5"}),n("routineDetail.newTrigger")]})})]}),C?(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-border p-4",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:n("Add trigger")}),(0,e.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Kind")}),(0,e.jsxs)(ge,{value:r.kind,onValueChange:i(x=>a(j=>({...j,kind:x})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:ks.map(x=>(0,e.jsx)(me,{value:x,children:x},x))})]})]}),r.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Schedule")}),(0,e.jsx)(Ge,{value:r.cronExpression,onChange:i(x=>a(j=>({...j,cronExpression:x})),"onChange"),onValidityChange:k})]}),r.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Signing mode")}),(0,e.jsxs)(ge,{value:r.signingMode,onValueChange:i(x=>a(j=>({...j,signingMode:x})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(he,{})}),(0,e.jsx)(xe,{children:Is.map(x=>(0,e.jsx)(me,{value:x,children:x},x))})]}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:Cs[r.signingMode]})]}),!As.has(r.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(_,{className:"text-xs",children:n("Replay window (seconds)")}),(0,e.jsx)(z,{value:r.replayWindowSec,onChange:i(x=>a(j=>({...j,replayWindowSec:x.target.value})),"onChange")})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)(O,{size:"sm",variant:"ghost",onClick:i(()=>A(!1),"onClick"),children:n("Cancel")}),(0,e.jsx)(O,{size:"sm",onClick:i(()=>d.mutate(void 0,{onSuccess:i(()=>{a($e()),A(!1)},"onSuccess")}),"onClick"),disabled:P,children:d.isPending?"Adding...":"Add trigger"})]})]}):null,S?(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-border bg-muted/20 p-4 text-sm",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-medium",children:S.title}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("routineDetail.saveSecretNow")})]}),(0,e.jsx)("div",{className:"space-y-3",children:S.entries.map((x,j)=>(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(z,{"aria-label":n("New webhook URL"),value:x.webhookUrl,readOnly:!0,className:"flex-1"}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>T("Webhook URL",x.webhookUrl),"onClick"),children:"URL"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(z,{"aria-label":n("New webhook secret"),value:x.webhookSecret,readOnly:!0,className:"flex-1"}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>T("Webhook secret",x.webhookSecret),"onClick"),children:n("agentConfig.secret")})]})]},`${x.webhookUrl}-${j}`))}),(0,e.jsx)(O,{variant:"outline",size:"sm",onClick:i(()=>M(null),"onClick"),children:n("Done")})]}):null,s.triggers.length===0?(0,e.jsx)(ie,{icon:be,message:n("routineDetail.noTriggersYetPeriod"),action:n("Add a trigger"),onAction:i(()=>A(!0),"onAction")}):(0,e.jsx)("div",{className:"space-y-3",children:s.triggers.map(x=>(0,e.jsx)(bs,{trigger:x,onSave:i((j,N)=>o.mutate({id:j,patch:N}),"onSave"),onRotate:i(j=>l.mutate(j),"onRotate"),onDelete:i(j=>p.mutate(j),"onDelete")},x.id))})]})}i(Rs,"TriggersSection");function Ds(){W();const{editDraft:s,setEditDraft:r,navigateToSection:a}=B(),d=s.variables.length>0;return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-border bg-muted/20 px-4 py-3 text-xs",children:[(0,e.jsxs)("span",{className:"flex-1 text-muted-foreground",children:[n("routineDetail.variablesAutoDetectedPrefix"),(0,e.jsx)("code",{className:"font-mono",children:"{{placeholders}}"})," ",n("in the title & instructions. The variable name is read-only — rename by editing the placeholder.")]}),(0,e.jsxs)(O,{variant:"secondary",size:"sm",onClick:i(()=>a("overview"),"onClick"),children:[(0,e.jsx)(ps,{className:"mr-1.5 h-3.5 w-3.5"}),n("routineDetail.editInstructions")]})]}),d?(0,e.jsx)(We,{title:s.title,description:s.description,value:s.variables,onChange:i(o=>r(p=>({...p,variables:o})),"onChange")}):(0,e.jsx)(ie,{icon:ds,message:"No variables yet. Add a {{placeholder}} in the title or instructions to create one.",action:n("routineDetail.editInstructions"),onAction:i(()=>a("overview"),"onAction")})]})}i(Ds,"VariablesSection");function Ts(){W();const{editDraft:s,setEditDraft:r,availableSecrets:a,createSecret:d}=B(),o=(0,m.useMemo)(()=>[...a].filter(p=>p.status==="active").sort((p,l)=>{const S=(l.referenceCount??0)-(p.referenceCount??0);return S!==0?S:new Date(l.updatedAt).getTime()-new Date(p.updatedAt).getTime()}).slice(0,8),[a]);return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"rounded-md border border-border bg-muted/20 px-4 py-3 text-xs text-muted-foreground",children:[n("routineDetail.secretsApplyPrefix")," ",(0,e.jsx)("span",{className:"font-mono",children:"PAPERCLIP_*"})," ",n("routineDetail.secretsReservedSuffix")]}),(0,e.jsx)(Yt,{value:s.env??{},secrets:a,recentlyUsedSecrets:o,onCreateSecret:i(async(p,l)=>d.mutateAsync({name:p,value:l}),"onCreateSecret"),onChange:i(p=>r(l=>({...l,env:p??null})),"onChange")})]})}i(Ts,"SecretsSection");function Es(){W();const{editDraft:s,setEditDraft:r,routine:a}=B(),d=a.triggers.some(p=>p.kind==="schedule"),o=s.activityGatePolicy==="require_external_activity";return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("Concurrency")}),(0,e.jsx)(te,{ariaLabel:"Concurrency policy",value:s.concurrencyPolicy,onValueChange:i(p=>r(l=>({...l,concurrencyPolicy:p})),"onValueChange"),options:js})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("Catch-up")}),(0,e.jsx)(te,{ariaLabel:"Catch-up policy",value:s.catchUpPolicy,onValueChange:i(p=>r(l=>({...l,catchUpPolicy:p})),"onValueChange"),options:ws})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("agentConfig.advancedRunPolicy")}),(0,e.jsx)(te,{ariaLabel:"Advanced run policy",value:s.activityGatePolicy,onValueChange:i(p=>r(l=>({...l,activityGatePolicy:p})),"onValueChange"),options:Ss,disabled:!d}),d?o?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-border p-3",children:[(0,e.jsx)(_,{className:"text-xs font-medium",children:n("routineEditor.activityScope")}),(0,e.jsx)(te,{ariaLabel:"Activity gate scope",value:s.activityGateScope,onValueChange:i(p=>r(l=>({...l,activityGateScope:p})),"onValueChange"),options:Ns})]}):null:(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:n("routineEditor.scheduleTriggerHint")})]}),(0,e.jsx)(_s,{triggers:a.triggers,concurrencyPolicy:s.concurrencyPolicy})]})}i(Es,"DeliverySection");var Os={queued:"text-emerald-600 dark:text-emerald-400",coalesced:"text-amber-600 dark:text-amber-400",skipped:"text-muted-foreground"};function _s({triggers:s,concurrencyPolicy:r}){W();const a=(0,m.useMemo)(()=>{const d=s.filter(o=>o.kind==="schedule"&&o.enabled&&o.cronExpression).map(o=>({trigger:o,fires:Ht(o.cronExpression,5,{timeZone:o.timezone??"UTC"})})).filter(o=>o.fires.length>0).sort((o,p)=>o.fires[0].getTime()-p.fires[0].getTime())[0];return d?{timeZone:d.trigger.timezone??"UTC",entries:is(d.fires,r)}:null},[s,r]);return(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:n("routineDetail.nextFiveFires")}),a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"space-y-1.5 rounded-lg border border-border p-3 font-mono text-xs",children:a.entries.map((d,o)=>(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"text-muted-foreground/40",children:"·"}),(0,e.jsx)("span",{className:"tabular-nums",children:Ms(d.at,a.timeZone)}),(0,e.jsx)(ve,{className:"h-3 w-3 shrink-0 text-muted-foreground/50"}),(0,e.jsx)("span",{className:dt("font-medium",Os[d.disposition]),children:d.label}),d.note?(0,e.jsxs)("span",{className:"truncate text-muted-foreground/60",children:["(",d.note,")"]}):null]},o))}),(0,e.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/60",children:[n("routineDetail.previewAssumesPreviousRun")," ",a.timeZone,n(".")]})]}):(0,e.jsx)("p",{className:"rounded-lg border border-dashed border-border p-3 text-xs text-muted-foreground",children:n("routineDetail.noSchedulePreview")})]})}i(_s,"NextFiresPreview");function Ms(s,r){try{return new Intl.DateTimeFormat(void 0,{timeZone:r,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(s).replace(",","")}catch{return s.toISOString()}}i(Ms,"formatFireTime");var ye="paperclip.routineLastSection";function Fs(s){return s.filter(r=>!r.archivedAt).map(r=>({id:r.id,label:r.name,searchText:r.description??""}))}i(Fs,"buildRoutineProjectOptions");var qs={overview:"Overview",triggers:"Triggers",variables:"Variables",secrets:"Secrets",delivery:"Delivery",runs:"Runs",activity:"Activity",history:"History"};function se(s){return s!=null&&ns.includes(s)}i(se,"isRoutineSection");function Ks(s){try{const r=localStorage.getItem(ye);if(!r)return null;const a=JSON.parse(r)[s];return se(a)?a:null}catch{return null}}i(Ks,"readLastSection");function ue(s,r){try{const a=localStorage.getItem(ye),d=a?JSON.parse(a):{};d[s]=r,localStorage.setItem(ye,JSON.stringify(d))}catch{}}i(ue,"writeLastSection");var Le={triggers:"triggers",runs:"runs",activity:"activity",secrets:"secrets",history:"history"};function Ue(s){s&&(s.style.height="auto",s.style.height=`${s.scrollHeight}px`)}i(Ue,"autoResizeTextarea");function Ls(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(Ls,"getLocalTimezone");function Us(s){return{...s,description:s.description.trim()||null,projectId:s.projectId||null,assigneeAgentId:s.assigneeAgentId||null,env:s.env&&Object.keys(s.env).length>0?s.env:null}}i(Us,"buildRoutineMutationPayload");function mi(){W();const{routineId:s,section:r}=xt(),{selectedCompanyId:a}=ht(),{setBreadcrumbs:d}=bt(),o=pt(),p=ft(),{pushToast:l}=Mt(),S=(0,m.useRef)(null),T=(0,m.useRef)(null),M=(0,m.useRef)(null),C=(0,m.useRef)(null),A=(0,m.useRef)(null),[b,k]=(0,m.useState)(null),[q,P]=(0,m.useState)(!1),[x,j]=(0,m.useState)(!1),[N,ne]=(0,m.useState)($e),[v,R]=(0,m.useState)({title:"",description:"",projectId:"",assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",activityGatePolicy:"always",activityGateScope:"company",variables:[],env:null}),w=se(r)?r:"overview",F=(0,m.useCallback)((t,g)=>{s&&(ue(s,t),p(`/routines/${s}/${t}`,{replace:g?.replace??!0}))},[p,s]),{data:c,isLoading:H,error:$}=V({queryKey:h.routines.detail(s),queryFn:i(()=>E.get(s),"queryFn"),enabled:!!s}),D=c?.activeIssue?.id,{data:J}=V({queryKey:h.issues.liveRuns(D),queryFn:i(()=>Ut.liveRunsForIssue(D),"queryFn"),enabled:!!D,refetchInterval:3e3}),u=(J??[]).length>0,{data:y}=V({queryKey:h.routines.runs(s),queryFn:i(()=>E.listRuns(s),"queryFn"),enabled:!!s,refetchInterval:u?3e3:!1}),Q=(0,m.useMemo)(()=>({triggerIds:c?.triggers.map(t=>t.id)??[],runIds:y?.map(t=>t.id)??[]}),[c?.triggers,y]),{data:ze}=V({queryKey:[...h.routines.activity(a,s),Q.triggerIds.join(","),Q.runIds.join(",")],queryFn:i(()=>E.activity(a,s,Q),"queryFn"),enabled:!!a&&!!s&&!!c}),{data:K}=V({queryKey:h.agents.list(a),queryFn:i(()=>wt.list(a),"queryFn"),enabled:!!a}),{data:L}=V({queryKey:h.projects.list(a,{includeArchived:!0}),queryFn:i(()=>_t.list(a,{includeArchived:!0}),"queryFn"),enabled:!!a}),{data:je}=V({queryKey:h.access.companyUserDirectory(a),queryFn:i(()=>Wt.listUserDirectory(a),"queryFn"),enabled:!!a}),{data:Qe=[]}=V({queryKey:a?h.secrets.list(a):["secrets","none"],queryFn:i(()=>qe.list(a),"queryFn"),enabled:!!a}),Be=U({mutationFn:i(t=>{if(!a)throw new Error("Select a company to create secrets");return qe.create(a,t)},"mutationFn"),onSuccess:i(()=>{a&&o.invalidateQueries({queryKey:h.secrets.list(a)})},"onSuccess")}),f=(0,m.useMemo)(()=>c?{title:c.title,description:c.description??"",projectId:c.projectId??"",assigneeAgentId:c.assigneeAgentId??"",priority:c.priority,concurrencyPolicy:c.concurrencyPolicy,catchUpPolicy:c.catchUpPolicy,activityGatePolicy:c.activityGatePolicy,activityGateScope:c.activityGateScope,variables:c.variables,env:c.env??null}:null,[c]),X=(0,m.useMemo)(()=>{if(!f)return[];const t=[];return v.title!==f.title&&t.push({key:"title",label:n("routineDetail.dirty.title")}),v.description!==f.description&&t.push({key:"description",label:n("routineDetail.dirty.description")}),v.projectId!==f.projectId&&t.push({key:"projectId",label:"the project"}),v.assigneeAgentId!==f.assigneeAgentId&&t.push({key:"assigneeAgentId",label:n("routineDetail.dirty.defaultAgent")}),v.priority!==f.priority&&t.push({key:"priority",label:n("routineDetail.dirty.priority")}),v.concurrencyPolicy!==f.concurrencyPolicy&&t.push({key:"concurrencyPolicy",label:n("routineDetail.dirty.concurrency")}),v.catchUpPolicy!==f.catchUpPolicy&&t.push({key:"catchUpPolicy",label:n("routineDetail.dirty.catchUp")}),v.activityGatePolicy!==f.activityGatePolicy&&t.push({key:"activityGatePolicy",label:n("the advanced run policy")}),v.activityGateScope!==f.activityGateScope&&t.push({key:"activityGateScope",label:n("the activity gate scope")}),JSON.stringify(v.variables)!==JSON.stringify(f.variables)&&t.push({key:"variables",label:n("routineDetail.dirty.variables")}),JSON.stringify(v.env??null)!==JSON.stringify(f.env??null)&&t.push({key:"env",label:n("routineDetail.dirty.secrets")}),t},[v,f]),ae=X.length>0,Y=(0,m.useCallback)(t=>{const g=Ke[t];return g?X.filter(I=>g.includes(I.key)):[]},[X]),re=(0,m.useCallback)(t=>Y(t).length>0,[Y]),we=(0,m.useCallback)(t=>{if(!f)return;const g=Ke[t];g&&R(I=>{const Te={...I};for(const Ee of g)Te[Ee]=f[Ee];return Te})},[f]);(0,m.useEffect)(()=>{c&&(d([{label:n("Routines"),href:"/routines"},{label:c.title}]),f&&(S.current!==c.id||!ae)&&(R(f),S.current=c.id))},[c,f,ae,d]),(0,m.useEffect)(()=>{Ue(T.current)},[v.title,c?.id]),(0,m.useEffect)(()=>{s&&se(r)&&ue(s,r)},[s,r]);const He=(0,m.useCallback)(async(t,g)=>{try{await qt(g),l({title:`${t} copied`,tone:"success"})}catch(I){l({title:`Failed to copy ${t.toLowerCase()}`,body:I instanceof Error?I.message:"Clipboard access was denied.",tone:"error"})}},[l]),Z=U({mutationFn:i(()=>{const t=Us(v),g=c?.latestRevisionId??null;return E.update(s,{...t,...g?{baseRevisionId:g}:{}})},"mutationFn"),onSuccess:i(async()=>{P(!1),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)}),o.invalidateQueries({queryKey:h.routines.revisions(s)})])},"onSuccess"),onError:i(t=>{if(t instanceof mt&&t.status===409){P(!0),l({title:n("routineDetail.routineChanged"),body:"Someone else updated this routine. Reload to see the latest revision.",tone:"warn"});return}l({title:n("Failed to save routine"),body:t instanceof Error?t.message:"Paperclip could not save the routine.",tone:"error"})},"onError")}),ee=U({mutationFn:i(t=>E.run(s,{...t?.variables&&Object.keys(t.variables).length>0?{variables:t.variables}:{},...t?.assigneeAgentId!==void 0?{assigneeAgentId:t.assigneeAgentId}:{},...t?.projectId!==void 0?{projectId:t.projectId}:{},...t?.executionWorkspaceId!==void 0?{executionWorkspaceId:t.executionWorkspaceId}:{},...t?.executionWorkspacePreference!==void 0?{executionWorkspacePreference:t.executionWorkspacePreference}:{},...t?.executionWorkspaceSettings!==void 0?{executionWorkspaceSettings:t.executionWorkspaceSettings}:{}}),"mutationFn"),onSuccess:i(async()=>{l({title:n("Routine run started"),tone:"success"}),j(!1),F("runs"),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.runs(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Routine run failed"),body:t instanceof Error?t.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),Se=U({mutationFn:i(t=>E.update(s,{status:t}),"mutationFn"),onSuccess:i(async(t,g)=>{l({title:n("Routine saved"),body:g==="paused"?"Automation paused.":"Automation enabled.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to update routine"),body:t instanceof Error?t.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Je=U({mutationFn:i(async()=>{const t=(c?.triggers??[]).filter(I=>I.kind===N.kind).length,g=t>0?`${N.kind}-${t+1}`:N.kind;return E.createTrigger(s,{kind:N.kind,label:g,...N.kind==="schedule"?{cronExpression:N.cronExpression.trim(),timezone:Ls()}:{},...N.kind==="webhook"?{signingMode:N.signingMode,replayWindowSec:Number(N.replayWindowSec||"300")}:{}})},"mutationFn"),onSuccess:i(async t=>{t.secretMaterial?k({title:n("Webhook trigger created"),entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}):l({title:n("routineDetail.triggerAdded"),body:"The routine schedule was saved.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to add trigger"),body:t instanceof Error?t.message:"Paperclip could not create the trigger.",tone:"error"})},"onError")}),Xe=U({mutationFn:i(({id:t,patch:g})=>E.updateTrigger(t,g),"mutationFn"),onSuccess:i(async()=>{l({title:n("routineDetail.triggerSaved"),body:"The routine cadence update was saved.",tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to update trigger"),body:t instanceof Error?t.message:"Paperclip could not update the trigger.",tone:"error"})},"onError")}),Ye=U({mutationFn:i(t=>E.deleteTrigger(t),"mutationFn"),onSuccess:i(async()=>{l({title:n("routineDetail.triggerDeleted"),tone:"success"}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.list(a)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to delete trigger"),body:t instanceof Error?t.message:"Paperclip could not delete the trigger.",tone:"error"})},"onError")}),Ze=U({mutationFn:i(t=>E.rotateTriggerSecret(t),"mutationFn"),onSuccess:i(async t=>{k({title:n("Webhook secret rotated"),entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}),await Promise.all([o.invalidateQueries({queryKey:h.routines.detail(s)}),o.invalidateQueries({queryKey:h.routines.activity(a,s)})])},"onSuccess"),onError:i(t=>{l({title:n("Failed to rotate webhook secret"),body:t instanceof Error?t.message:"Paperclip could not rotate the webhook secret.",tone:"error"})},"onError")}),Ne=(0,m.useMemo)(()=>new Map((K??[]).map(t=>[t.id,t])),[K]),ke=(0,m.useMemo)(()=>new Map((L??[]).map(t=>[t.id,t])),[L]),oe=(0,m.useMemo)(()=>Dt(),[c?.id]),et=(0,m.useMemo)(()=>It(),[c?.id]),tt=(0,m.useMemo)(()=>Rt((K??[]).filter(t=>t.status!=="terminated"),oe).map(t=>({id:t.id,label:t.name,searchText:`${t.name} ${t.role} ${t.title??""}`})),[K,oe]),st=(0,m.useMemo)(()=>Fs(L??[]),[L]),it=(0,m.useMemo)(()=>Vt({agents:K,projects:(L??[]).filter(t=>!t.archivedAt),members:je?.users}),[K,je?.users,L]),nt=(0,m.useCallback)(t=>{R(g=>{const I=typeof t=="function"?t(g):t;return I.assigneeAgentId&&I.assigneeAgentId!==g.assigneeAgentId&&kt(I.assigneeAgentId),I.projectId&&I.projectId!==g.projectId&&Pt(I.projectId),I})},[]),at=v.assigneeAgentId?Ne.get(v.assigneeAgentId)??null:null,rt=v.projectId?ke.get(v.projectId)??null:null,Ie=(0,m.useCallback)(()=>{P(!1),f&&R(f),o.invalidateQueries({queryKey:h.routines.detail(s)})},[o,f,s]),ot=(0,m.useCallback)(t=>{t.secretMaterials.length>0&&(F("triggers"),k({title:t.secretMaterials.length===1?n("routineDetail.webhookTriggerRestored"):`${t.secretMaterials.length} webhook triggers restored`,entries:t.secretMaterials.map(g=>({webhookUrl:g.webhookUrl,webhookSecret:g.webhookSecret}))}))},[F]),ct=(0,m.useCallback)(t=>{P(!1),o.setQueryData(h.routines.detail(s),g=>g&&{...g,...t.routine,latestRevisionId:t.revision.id,latestRevisionNumber:t.revision.revisionNumber}),R({title:t.routine.title,description:t.routine.description??"",projectId:t.routine.projectId??"",assigneeAgentId:t.routine.assigneeAgentId??"",priority:t.routine.priority,concurrencyPolicy:t.routine.concurrencyPolicy,catchUpPolicy:t.routine.catchUpPolicy,activityGatePolicy:t.routine.activityGatePolicy,activityGateScope:t.routine.activityGateScope,variables:t.routine.variables,env:t.routine.env??null}),S.current=t.routine.id},[o,s]);if(!a)return(0,e.jsx)(ie,{icon:Ct,message:n("Select a company to view routines.")});const ce=new URLSearchParams(window.location.search).get("tab");if(s&&ce&&Le[ce])return(0,e.jsx)(le,{to:`/routines/${s}/${Le[ce]}`,replace:!0});if(s&&!r){const t=Ks(s)??"overview";return(0,e.jsx)(le,{to:`/routines/${s}/${t}`,replace:!0})}if(s&&r&&!se(r))return(0,e.jsx)(le,{to:`/routines/${s}/overview`,replace:!0});if(H)return(0,e.jsx)(zt,{variant:"issues-list"});if($||!c||!f)return(0,e.jsx)(ie,{icon:Kt,message:$ instanceof Error?$.message:n("routineDetail.loadFailedBody")});const G=c.status==="active",Ce=Se.isPending||c.status==="archived",Ae=c.status==="archived"?"Archived":c.assigneeAgentId?G?"Active":"Paused":"Draft",Pe=c.status==="archived"?"text-muted-foreground":G?"text-emerald-400":"text-muted-foreground",Re={routine:c,routineId:s,companyId:c.companyId,editDraft:v,setEditDraft:nt,routineDefaults:f,dirtyFields:X,isEditDirty:ae,sectionDirtyFields:Y,isSectionDirty:re,discardSection:we,saveRoutine:Z,saveConflict:q,reloadLatest:Ie,automationEnabled:G,automationLabel:Ae,automationLabelClassName:Pe,automationToggleDisabled:Ce,onToggleAutomation:i(()=>{if(!G&&!c.assigneeAgentId){l({title:n("Default agent required"),body:"Set a default agent before enabling routine automation.",tone:"warn"});return}Se.mutate(G?"paused":"active")},"onToggleAutomation"),onOpenRunDialog:i(()=>j(!0),"onOpenRunDialog"),runRoutinePending:ee.isPending,newTrigger:N,setNewTrigger:ne,createTrigger:Je,updateTrigger:Xe,deleteTrigger:Ye,rotateTrigger:Ze,secretMessage:b,setSecretMessage:k,copySecretValue:He,availableSecrets:Qe,createSecret:Be,agents:K??[],projects:L??[],agentById:Ne,projectById:ke,assigneeOptions:tt,projectOptions:st,recentAssigneeIds:oe,recentProjectIds:et,mentionOptions:it,currentAssignee:at,currentProject:rt,routineRuns:y,activity:ze,hasLiveRun:u,activeIssueId:D,titleInputRef:T,descriptionEditorRef:M,assigneeSelectorRef:C,projectSelectorRef:A,onHistoryRestoreSecretMaterials:ot,onHistoryRestored:ct,navigateToSection:F},De=ts.includes(w);return(0,e.jsxs)(Xt.Provider,{value:Re,children:[(0,e.jsx)("a",{href:"#routine-section",className:"sr-only focus:not-sr-only focus:absolute focus:left-2 focus:top-2 focus:z-20 focus:rounded focus:bg-background focus:px-3 focus:py-1.5 focus:text-sm",children:n("routineDetail.skipToSection")}),(0,e.jsxs)("div",{className:"-m-4 flex h-full min-h-0 flex-col overflow-hidden md:-m-6",children:[(0,e.jsxs)("header",{className:"flex h-14 shrink-0 items-center gap-3 border-b border-border bg-background px-6",children:[(0,e.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[(0,e.jsx)("textarea",{ref:T,"data-autosize-title":!0,className:"min-w-0 flex-1 resize-none overflow-hidden bg-transparent text-base font-semibold leading-7 outline-none placeholder:text-muted-foreground/50",placeholder:n("Routine title"),rows:1,value:v.title,onChange:i(t=>{R(g=>({...g,title:t.target.value})),Ue(t.target)},"onChange"),onKeyDown:i(t=>{t.key==="Enter"&&!t.metaKey&&!t.ctrlKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),w==="overview"?M.current?.focus():F("overview"))},"onKeyDown")}),c.managedByPlugin?(0,e.jsxs)(fe,{variant:"outline",className:"hidden shrink-0 gap-1.5 text-xs text-muted-foreground sm:inline-flex",children:[(0,e.jsx)(jt,{className:"h-3 w-3"}),c.managedByPlugin.pluginDisplayName,(0,e.jsx)("span",{className:"font-mono text-(length:--text-nano)",children:c.managedByPlugin.resourceKey})]}):null]}),(0,e.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-3",children:[(0,e.jsx)(ls,{onClick:i(()=>j(!0),"onClick"),disabled:ee.isPending}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(St,{size:"default",checked:G,onCheckedChange:Re.onToggleAutomation,disabled:Ce,"aria-label":G?n("Pause automatic triggers"):n("Enable automatic triggers")}),(0,e.jsx)("span",{className:`text-sm font-medium ${Pe}`,children:Ae})]})]})]}),(0,e.jsx)(Qt,{activeSection:w,onNavigate:F,isSectionDirty:re}),(0,e.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,e.jsx)(us,{activeSection:w,hrefFor:i(t=>`/routines/${s}/${t}`,"hrefFor"),isSectionDirty:re,hasLiveRun:u,onNavigate:i(t=>ue(s,t),"onNavigate")}),(0,e.jsx)("main",{id:"routine-section",role:"main",className:"min-h-0 min-w-0 flex-1 overflow-y-auto px-4 pb-6 pt-10 md:px-8",children:(0,e.jsxs)("section",{"aria-labelledby":"routine-section-title",className:De?"mx-auto w-full max-w-3xl":"w-full",children:[(0,e.jsx)(Zt,{title:qs[w],copyText:w==="overview"?gs({editing:!0,draft:v.description,saved:c.description}):null}),w==="overview"&&(0,e.jsx)(Ps,{}),w==="triggers"&&(0,e.jsx)(Rs,{}),w==="variables"&&(0,e.jsx)(Ds,{}),w==="secrets"&&(0,e.jsx)(Ts,{}),w==="delivery"&&(0,e.jsx)(Es,{}),w==="runs"&&(0,e.jsx)(Bt,{}),w==="activity"&&(0,e.jsx)(hs,{}),w==="history"&&(0,e.jsx)(rs,{}),De?(0,e.jsx)(ms,{dirtyFields:Y(w),isSaving:Z.isPending,saveConflict:q,onSave:i(()=>{!Z.isPending&&v.title.trim()&&Z.mutate()},"onSave"),onDiscard:i(()=>we(w),"onDiscard"),onReload:Ie}):null]})})]})]}),(0,e.jsx)(At,{open:x,onOpenChange:j,companyId:c.companyId,routineName:c.title,agents:K??[],projects:L??[],defaultProjectId:c.projectId,defaultAssigneeAgentId:c.assigneeAgentId,variables:c.variables??[],isPending:ee.isPending,onSubmit:i(t=>ee.mutate(t),"onSubmit")})]})}i(mi,"RoutineDetail");export{mi as RoutineDetail};
|