@tickernelz/paperclip-pro-ui 2026.1006.2 → 2026.1006.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/assets/{AgentAvatar-lnkDMHMh.js → AgentAvatar-CrnNGelJ.js} +1 -1
  2. package/dist/assets/{AgentIdentity-Cpb2VddX.js → AgentIdentity-Bl7KfJ-S.js} +1 -1
  3. package/dist/assets/{Agents.production-pGUwDC7r.js → Agents.production-Bcypo-FZ.js} +2 -2
  4. package/dist/assets/{CompanyActivity.production-ZGgxxisV.js → CompanyActivity.production-CkDNJ7NU.js} +1 -1
  5. package/dist/assets/{CompanyExport-GeY3_TXI.js → CompanyExport-BaU0-Roc.js} +1 -1
  6. package/dist/assets/{CompanySkills.production-BN9MKK7o.js → CompanySkills.production-BXQFLRhu.js} +1 -1
  7. package/dist/assets/{Costs.production-B4oABBSg.js → Costs.production-BttYsMtZ.js} +1 -1
  8. package/dist/assets/{EmptyState-CqqJOoXs.js → EmptyState-ClZXiygF.js} +1 -1
  9. package/dist/assets/{MarkdownBody-CEnh9lVM.js → MarkdownBody-Usks4GYV.js} +1 -1
  10. package/dist/assets/{MarkdownEditor-seU_oAfy.js → MarkdownEditor-D0uqxShB.js} +1 -1
  11. package/dist/assets/{OrgChart.production-JOfw43w3.js → OrgChart.production-Ckrirkif.js} +1 -1
  12. package/dist/assets/{PageSkeleton-C9WV_Qyq.js → PageSkeleton-DQuX4FJP.js} +1 -1
  13. package/dist/assets/{RoutineDetail.production-A472lDXj.js → RoutineDetail.production-BOwgaQbA.js} +1 -1
  14. package/dist/assets/{RoutineRunVariablesDialog-yR5DLc68.js → RoutineRunVariablesDialog--quGEm4y.js} +1 -1
  15. package/dist/assets/{Routines.production-LvomJjv8.js → Routines.production-C_9YzHgt.js} +1 -1
  16. package/dist/assets/{SidebarContext-Dpto7Kf2.js → SidebarContext-DHnDudYw.js} +1 -1
  17. package/dist/assets/{StatusIcon-BtBa0xK_.js → StatusIcon-D__DIZlm.js} +1 -1
  18. package/dist/assets/{agent-avatar-url-270oGkoO.js → agent-avatar-url-CiVC72zn.js} +1 -1
  19. package/dist/assets/{agents-BlxRXAz3.js → agents-BGdf-J_C.js} +1 -1
  20. package/dist/assets/{badge-D0Ti-OuU.js → badge-Dwnb7bwc.js} +1 -1
  21. package/dist/assets/{bot-CGOpwPIZ.js → bot-DyYJ3E4C.js} +1 -1
  22. package/dist/assets/{boxes-xBZV8xLw.js → boxes-BGSl5NUN.js} +1 -1
  23. package/dist/assets/{button-DLWREze0.js → button-BmDU7YzH.js} +1 -1
  24. package/dist/assets/{card-Qk8smcrQ.js → card-V5O2wbgV.js} +1 -1
  25. package/dist/assets/{check-5Tuqm2aI.js → check-B3EECTO-.js} +1 -1
  26. package/dist/assets/{checkbox-SNvdBfci.js → checkbox-SdYP--OH.js} +1 -1
  27. package/dist/assets/{chevron-down-ZMnYk9j3.js → chevron-down-wArmbnHu.js} +1 -1
  28. package/dist/assets/{chevron-right-Dv6dHZgu.js → chevron-right-BhU5OvzN.js} +1 -1
  29. package/dist/assets/{clipboard-BPoFQAy2.js → clipboard-CATj6OsB.js} +1 -1
  30. package/dist/assets/{company-members-BKdmkDTe.js → company-members-c2ldQ5sU.js} +1 -1
  31. package/dist/assets/{definition-DTQCzcR3.js → definition-TaH5T5zB.js} +1 -1
  32. package/dist/assets/{dist-DvMfIbJ9.js → dist-DA-GP1EK.js} +1 -1
  33. package/dist/assets/{dist-BzPgY729.js → dist-bLGzOSwF.js} +1 -1
  34. package/dist/assets/{environments-BNSxsEsE.js → environments-12KK8Hvb.js} +1 -1
  35. package/dist/assets/{external-link-rfTzFbSd.js → external-link-CGgtFJT7.js} +1 -1
  36. package/dist/assets/{file-text-dks7zWRZ.js → file-text-BehN_jnQ.js} +1 -1
  37. package/dist/assets/{health-DsHGAxc8.js → health-BqfpMlIG.js} +1 -1
  38. package/dist/assets/{heartbeats-DWUL5tSL.js → heartbeats-By7EcEMQ.js} +1 -1
  39. package/dist/assets/{index-DTMtHDxt.js → index-DcHMTMN0.js} +5 -5
  40. package/dist/assets/{input-BWYuMr4z.js → input-CfZ7FdDr.js} +1 -1
  41. package/dist/assets/{label-TkPoSJhK.js → label-CA4aszl3.js} +1 -1
  42. package/dist/assets/{loader-circle-DiqjntTX.js → loader-circle-B6QmcXd3.js} +1 -1
  43. package/dist/assets/{mention-chips-B_zVTnHY.js → mention-chips-3yfCFzXQ.js} +1 -1
  44. package/dist/assets/{octagon-alert-HfSAYnSC.js → octagon-alert-CAPjvRAd.js} +1 -1
  45. package/dist/assets/{rotate-ccw-C9ZF1aqD.js → rotate-ccw-qAsLpcfW.js} +1 -1
  46. package/dist/assets/{router-BC2Duaf5.js → router-CGbOrhXy.js} +1 -1
  47. package/dist/assets/{save-yPNdO-t7.js → save-dnfn3gBp.js} +1 -1
  48. package/dist/assets/{select-DsMS_Sad.js → select-Db0ppga4.js} +1 -1
  49. package/dist/assets/{sheet-CFbmpBhA.js → sheet-CqcQLexE.js} +1 -1
  50. package/dist/assets/{skeleton-DtakB_VA.js → skeleton-tce5L2Bu.js} +1 -1
  51. package/dist/assets/{tabs-DCzsHrwQ.js → tabs-Bs8GGKXg.js} +1 -1
  52. package/dist/assets/{triangle-alert-CrLKyTUa.js → triangle-alert-BSwSeDrD.js} +1 -1
  53. package/dist/assets/{use-adapter-capabilities-CVwppNII.js → use-adapter-capabilities-h7tUuKwM.js} +1 -1
  54. package/dist/assets/{useHiddenSettings-COOnS4sa.js → useHiddenSettings-DwCbKddT.js} +1 -1
  55. package/dist/index.html +45 -45
  56. package/dist/sw.js +1 -1
  57. package/package.json +1 -1
@@ -1 +1 @@
1
- var i=Object.defineProperty;var r=(l,c)=>i(l,"name",{value:c,configurable:!0});import{i as d}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as x}from"./agent-avatar-url-270oGkoO.js";import{t as e}from"./skeleton-DtakB_VA.js";var s=d(x(),1);function t({variant:l="list"}){return l==="dashboard"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)(e,{className:"h-32 w-full border border-border"}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 xl:grid-cols-4",children:Array.from({length:4}).map((c,a)=>(0,s.jsx)(e,{className:"h-24 w-full"},a))}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:Array.from({length:4}).map((c,a)=>(0,s.jsx)(e,{className:"h-44 w-full"},a))}),(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsx)(e,{className:"h-72 w-full"}),(0,s.jsx)(e,{className:"h-72 w-full"})]})]}):l==="approvals"?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{className:"flex items-center justify-between",children:(0,s.jsx)(e,{className:"h-9 w-44"})}),(0,s.jsx)("div",{className:"grid gap-3",children:Array.from({length:3}).map((c,a)=>(0,s.jsx)(e,{className:"h-36 w-full"},a))})]}):l==="costs"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:Array.from({length:6}).map((c,a)=>(0,s.jsx)(e,{className:"h-9 w-28"},a))}),(0,s.jsx)(e,{className:"h-40 w-full"}),(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsx)(e,{className:"h-72 w-full"}),(0,s.jsx)(e,{className:"h-72 w-full"})]})]}):l==="inbox"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-56"}),(0,s.jsx)(e,{className:"h-8 w-40"})]}),(0,s.jsx)("div",{className:"space-y-5",children:Array.from({length:3}).map((c,a)=>(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(e,{className:"h-4 w-40"}),(0,s.jsx)("div",{className:"space-y-1 border border-border",children:Array.from({length:3}).map((h,m)=>(0,s.jsx)(e,{className:"h-14 w-full rounded-none"},m))})]},a))})]}):l==="org-chart"?(0,s.jsx)("div",{className:"space-y-4",children:(0,s.jsx)(e,{className:"h-(--sz-calc-17) w-full rounded-lg border border-border"})}):l==="detail"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(e,{className:"h-3 w-64"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-6 w-6"}),(0,s.jsx)(e,{className:"h-6 w-6"}),(0,s.jsx)(e,{className:"h-7 w-48"})]}),(0,s.jsx)(e,{className:"h-4 w-40"})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(e,{className:"h-10 w-full"}),(0,s.jsx)(e,{className:"h-32 w-full"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-24"}),(0,s.jsx)(e,{className:"h-8 w-24"}),(0,s.jsx)(e,{className:"h-8 w-24"})]}),(0,s.jsx)(e,{className:"h-24 w-full"}),(0,s.jsx)(e,{className:"h-24 w-full"})]})]}):l==="issues-list"?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-64"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-24"})]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(e,{className:"h-4 w-40"}),(0,s.jsx)("div",{className:"space-y-1",children:Array.from({length:8}).map((c,a)=>(0,s.jsx)(e,{className:"h-11 w-full rounded-none"},a))})]})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-44"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-20"}),(0,s.jsx)(e,{className:"h-8 w-24"})]})]}),(0,s.jsx)("div",{className:"space-y-1",children:Array.from({length:7}).map((c,a)=>(0,s.jsx)(e,{className:"h-11 w-full rounded-none"},a))})]})}r(t,"PageSkeleton");export{t};
1
+ var i=Object.defineProperty;var r=(l,c)=>i(l,"name",{value:c,configurable:!0});import{i as d}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as x}from"./agent-avatar-url-CiVC72zn.js";import{t as e}from"./skeleton-tce5L2Bu.js";var s=d(x(),1);function t({variant:l="list"}){return l==="dashboard"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)(e,{className:"h-32 w-full border border-border"}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 xl:grid-cols-4",children:Array.from({length:4}).map((c,a)=>(0,s.jsx)(e,{className:"h-24 w-full"},a))}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:Array.from({length:4}).map((c,a)=>(0,s.jsx)(e,{className:"h-44 w-full"},a))}),(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsx)(e,{className:"h-72 w-full"}),(0,s.jsx)(e,{className:"h-72 w-full"})]})]}):l==="approvals"?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{className:"flex items-center justify-between",children:(0,s.jsx)(e,{className:"h-9 w-44"})}),(0,s.jsx)("div",{className:"grid gap-3",children:Array.from({length:3}).map((c,a)=>(0,s.jsx)(e,{className:"h-36 w-full"},a))})]}):l==="costs"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:Array.from({length:6}).map((c,a)=>(0,s.jsx)(e,{className:"h-9 w-28"},a))}),(0,s.jsx)(e,{className:"h-40 w-full"}),(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsx)(e,{className:"h-72 w-full"}),(0,s.jsx)(e,{className:"h-72 w-full"})]})]}):l==="inbox"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-56"}),(0,s.jsx)(e,{className:"h-8 w-40"})]}),(0,s.jsx)("div",{className:"space-y-5",children:Array.from({length:3}).map((c,a)=>(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(e,{className:"h-4 w-40"}),(0,s.jsx)("div",{className:"space-y-1 border border-border",children:Array.from({length:3}).map((h,m)=>(0,s.jsx)(e,{className:"h-14 w-full rounded-none"},m))})]},a))})]}):l==="org-chart"?(0,s.jsx)("div",{className:"space-y-4",children:(0,s.jsx)(e,{className:"h-(--sz-calc-17) w-full rounded-lg border border-border"})}):l==="detail"?(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(e,{className:"h-3 w-64"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-6 w-6"}),(0,s.jsx)(e,{className:"h-6 w-6"}),(0,s.jsx)(e,{className:"h-7 w-48"})]}),(0,s.jsx)(e,{className:"h-4 w-40"})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(e,{className:"h-10 w-full"}),(0,s.jsx)(e,{className:"h-32 w-full"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-24"}),(0,s.jsx)(e,{className:"h-8 w-24"}),(0,s.jsx)(e,{className:"h-8 w-24"})]}),(0,s.jsx)(e,{className:"h-24 w-full"}),(0,s.jsx)(e,{className:"h-24 w-full"})]})]}):l==="issues-list"?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-64"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-16"}),(0,s.jsx)(e,{className:"h-8 w-24"})]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(e,{className:"h-4 w-40"}),(0,s.jsx)("div",{className:"space-y-1",children:Array.from({length:8}).map((c,a)=>(0,s.jsx)(e,{className:"h-11 w-full rounded-none"},a))})]})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)(e,{className:"h-9 w-44"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e,{className:"h-8 w-20"}),(0,s.jsx)(e,{className:"h-8 w-24"})]})]}),(0,s.jsx)("div",{className:"space-y-1",children:Array.from({length:7}).map((c,a)=>(0,s.jsx)(e,{className:"h-11 w-full rounded-none"},a))})]})}r(t,"PageSkeleton");export{t};
@@ -1 +1 @@
1
- var ot=Object.defineProperty;var i=(s,a)=>ot(s,"name",{value:a,configurable:!0});import{i as Le}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as ct,Ei as lt,Ir as dt,Jr as L,S as ut,U as mt,X as p,ki as pt,qr as U}from"./agent-avatar-url-270oGkoO.js";import{Ht as ht,Mt as Ee,b as gt,o as xt,r as oe}from"./router-BC2Duaf5.js";import{Ct as yt,St as vt,bt as ft,dt as Oe,t as bt,ur as jt,vt as wt,yt as Nt}from"./RoutineRunVariablesDialog-yR5DLc68.js";import{Z as kt}from"./mention-chips-B_zVTnHY.js";import{l as T,t as De}from"./MarkdownEditor-seU_oAfy.js";import{v as St}from"./sheet-CFbmpBhA.js";import{t as _e}from"./AgentAvatar-lnkDMHMh.js";import{k as It}from"./checkbox-SNvdBfci.js";import{_ as Ct,s as At,t as O}from"./label-TkPoSJhK.js";import{r as Pt,t as Rt}from"./agents-BlxRXAz3.js";import{g as Tt}from"./StatusIcon-BtBa0xK_.js";import{r as Et,t as te}from"./EmptyState-CqqJOoXs.js";import{c as de,i as ue,n as me,s as pe,t as he}from"./select-DsMS_Sad.js";import{r as Ot,t as Dt}from"./save-yPNdO-t7.js";import{k as _t,t as E}from"./button-DLWREze0.js";import{n as Mt,t as qt}from"./clipboard-BPoFQAy2.js";import{t as Ft}from"./heartbeats-DWUL5tSL.js";import{t as xe}from"./badge-D0Ti-OuU.js";import{t as G}from"./input-BWYuMr4z.js";import{i as Kt,o as Lt}from"./company-members-BKdmkDTe.js";import{r as Ut,t as Wt}from"./card-Qk8smcrQ.js";import{t as $t}from"./PageSkeleton-C9WV_Qyq.js";import{B as Gt,Bn as ye,Dt as Vt,F as zt,G as Me,Gn as ve,H as Qt,I as Bt,J as Ue,K as We,L as Ht,M as Jt,N as Yt,P as $e,Qt as X,R as Zt,Tn as Xt,U as es,Un as ts,Ut as ss,V as is,W as ns,Wt as as,Y as rs,Yt as os,en as qe,hn as cs,j as ls,mn as ds,q as z,z as us}from"./index-DTMtHDxt.js";var u=Le(pt(),1);function ms(s,a,n){const c={label:a.label.trim()||null};return s.kind==="schedule"&&(c.cronExpression=a.cronExpression.trim(),c.timezone=s.timezone??n),s.kind==="webhook"&&(c.signingMode=a.signingMode,c.replayWindowSec=Number(a.replayWindowSec||"300")),c}i(ms,"buildRoutineTriggerPatch");var e=Le(ct(),1),ps=["app_webhook","bearer","hmac_sha256","github_hmac","none"],hs=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function gs(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(gs,"getLocalTimezone$1");function xs({trigger:s,onSave:a,onRotate:n,onDelete:c,disabled:r}){const[m,l]=(0,u.useState)({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)});(0,u.useEffect)(()=>{l({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)})},[s]);const k=s.kind==="schedule"?ye:s.kind==="webhook"?cs:gt,I=s.kind==="schedule"?Bt(m.cronExpression):null,M=/fail|error/i.test(s.lastResult??""),C=s.lastResult?.startsWith("Created execution issue ")?"Task created":s.lastResult;return(0,e.jsxs)("form",{"aria-label":`Trigger: ${s.label??s.kind}`,className:"space-y-4 rounded-lg border border-border p-4",onSubmit:i(x=>x.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)(k,{className:"h-3.5 w-3.5 shrink-0"}),(0,e.jsx)("span",{className:"truncate",children:s.label??s.kind})]}),I?(0,e.jsx)("p",{id:`cron-readable-${s.id}`,className:"text-xs text-muted-foreground",children:I}):null]}),(0,e.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[s.lastResult?(0,e.jsx)(xe,{variant:M?"destructive":"secondary",children:C}):null,(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.kind==="schedule"&&s.nextRunAt?`Next: ${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)(O,{htmlFor:`webhook-url-${s.id}`,className:"text-xs",children:"Webhook URL"}),(0,e.jsx)(G,{id:`webhook-url-${s.id}`,value:s.webhookUrl,readOnly:!0,onFocus:i(x=>x.target.select(),"onFocus")}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"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)(O,{className:"text-xs",children:"Label"}),(0,e.jsx)(G,{value:m.label,disabled:r,onChange:i(x=>l(S=>({...S,label:x.target.value})),"onChange")})]}),s.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(O,{className:"text-xs",children:"Schedule"}),(0,e.jsx)($e,{value:m.cronExpression,onChange:i(x=>l(S=>({...S,cronExpression:x})),"onChange")})]}),s.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Signing mode"}),(0,e.jsxs)(he,{value:m.signingMode,onValueChange:i(x=>l(S=>({...S,signingMode:x})),"onValueChange"),disabled:r,children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:ps.map(x=>(0,e.jsx)(ue,{value:x,children:x},x))})]})]}),!hs.has(m.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Replay window (seconds)"}),(0,e.jsx)(G,{value:m.replayWindowSec,disabled:r,onChange:i(x=>l(S=>({...S,replayWindowSec:x.target.value})),"onChange")})]})]})]}),!r&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsxs)(E,{variant:"ghost",size:"sm",className:"mr-auto text-muted-foreground hover:text-destructive",onClick:i(()=>c(s.id),"onClick"),children:[(0,e.jsx)(It,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete"]}),s.kind==="webhook"&&(0,e.jsxs)(E,{variant:"outline",size:"sm",onClick:i(()=>n(s.id),"onClick"),children:[(0,e.jsx)(St,{className:"mr-1.5 h-3.5 w-3.5"}),"Rotate secret"]}),(0,e.jsxs)(E,{variant:"outline",size:"sm",onClick:i(()=>a(s.id,ms(s,m,gs())),"onClick"),children:[(0,e.jsx)(Dt,{className:"mr-1.5 h-3.5 w-3.5"}),"Save trigger"]})]})]})}i(xs,"RoutineTriggerCard");var ys=[{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."}],vs=[{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."}],fs=[{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."}],bs=[{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."}],js=["schedule","webhook"],ws=["app_webhook","bearer","hmac_sha256","github_hmac","none"],Ns={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."},ks=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function Ss({defaultDescriptionAnnotationsOpen:s=!1}={}){const{routine:a,editDraft:n,setEditDraft:c,assigneeOptions:r,projectOptions:m,recentAssigneeIds:l,recentProjectIds:k,agentById:I,projectById:M,currentAssignee:C,currentProject:x,mentionOptions:S,assigneeSelectorRef:D,projectSelectorRef:q,descriptionEditorRef:A,routineRuns:g,activity:b,saveRoutine:j,saveConflict:se,isSectionDirty:f,navigateToSection:P}=z(),[w,_]=(0,u.useState)(s),o=a.triggers.length,Q=(0,u.useMemo)(()=>{const d=a.triggers.filter(y=>y.kind==="schedule"&&y.nextRunAt).map(y=>new Date(y.nextRunAt)).sort((y,V)=>y.getTime()-V.getTime())[0];return d?d.toLocaleString():null},[a.triggers]),W=n.env?Object.keys(n.env).length:0,R=(g??[])[0]??null,B=(b??[]).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:"For"}),(0,e.jsx)(Oe,{ref:D,value:n.assigneeAgentId,options:r,recentOptionIds:l,placeholder:"Responsible",noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:"No responsible found.",onChange:i(d=>c(y=>({...y,assigneeAgentId:d})),"onChange"),onConfirm:i(()=>{n.projectId?A.current?.focus():q.current?.focus()},"onConfirm"),renderTriggerValue:i(d=>d?C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(_e,{agent:C,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,e.jsx)("span",{className:"truncate",children:d.label})]}):(0,e.jsx)("span",{className:"truncate",children:d.label}):(0,e.jsx)("span",{className:"text-muted-foreground",children:"Responsible"}),"renderTriggerValue"),renderOption:i(d=>{if(!d.id)return(0,e.jsx)("span",{className:"truncate",children:d.label});const y=I.get(d.id);return(0,e.jsxs)(e.Fragment,{children:[y?(0,e.jsx)(_e,{agent:y,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,e.jsx)("span",{className:"truncate",children:d.label})]})},"renderOption")}),(0,e.jsx)("span",{children:"in"}),(0,e.jsx)(Oe,{ref:q,value:n.projectId,options:m,recentOptionIds:k,placeholder:"Project",noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:"No projects found.",onChange:i(d=>c(y=>({...y,projectId:d})),"onChange"),onConfirm:i(()=>A.current?.focus(),"onConfirm"),renderTriggerValue:i(d=>d&&x?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:x.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:d.label})]}):(0,e.jsx)("span",{className:"text-muted-foreground",children:"Project"}),"renderTriggerValue"),renderOption:i(d=>{if(!d.id)return(0,e.jsx)("span",{className:"truncate",children:d.label});const y=M.get(d.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:d.label})]})},"renderOption")})]})}),a.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:"Default agent required. This routine can stay as a draft and still run manually, but automation stays paused until you assign a default agent."}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("div",{className:"flex items-center justify-end",children:a.descriptionDocument?(0,e.jsx)(ss,{issueId:a.id,docKey:"description",target:{kind:"routine",routineId:a.id,documentKey:"description"},panelOpen:w,onToggle:i(()=>_(d=>!d),"onToggle")}):null}),a.descriptionDocument?(0,e.jsx)(as,{issueId:a.id,doc:a.descriptionDocument,target:{kind:"routine",routineId:a.id,documentKey:"description"},bodyMarkdown:n.description,draftDirty:f("overview")||j.isPending,draftConflicted:se,historicalPreview:!1,locationHash:typeof window>"u"?"":window.location.hash,panelOpen:w,onPanelOpenChange:_,children:(0,e.jsx)(De,{ref:A,value:n.description,onChange:i(d=>c(y=>({...y,description:d})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:S,onSubmit:i(()=>{!j.isPending&&n.title.trim()&&j.mutate()},"onSubmit")})}):(0,e.jsx)(De,{ref:A,value:n.description,onChange:i(d=>c(y=>({...y,description:d})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:S,onSubmit:i(()=>{!j.isPending&&n.title.trim()&&j.mutate()},"onSubmit")})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(rs,{}),(0,e.jsx)(Ue,{title:n.title,description:n.description,value:n.variables,onChange:i(d=>c(y=>({...y,variables:d})),"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsx)(ce,{icon:ye,label:"Triggers",value:o===0?"None":`${o} active`,hint:Q?`Next fire ${Q}`:"No schedule",to:i(()=>P("triggers"),"to"),ariaLabel:`${o} triggers. Open triggers.`}),(0,e.jsx)(ce,{icon:Mt,label:"Secrets",value:W===0?"None":`${W} bound`,hint:"Manage bound secrets",to:i(()=>P("secrets"),"to"),ariaLabel:`${W} secrets bound. Open secrets.`}),(0,e.jsx)(ce,{icon:Ct,label:"Last run",value:R?R.status.replaceAll("_"," "):"No runs",hint:R?Ee(R.triggeredAt):"Trigger a run",to:i(()=>P("runs"),"to"),ariaLabel:R?`Last run ${R.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:"Recent activity"}),B.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"No activity yet."}):(0,e.jsxs)("div",{className:"divide-y divide-border/60",children:[B.map(d=>(0,e.jsxs)("div",{className:"flex items-center gap-2 py-1.5 text-xs",children:[(0,e.jsx)(xe,{variant:"outline",className:"shrink-0 font-mono",children:d.action}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:d.details&&Object.keys(d.details).length>0?Object.keys(d.details).slice(0,3).join(" · "):""}),(0,e.jsx)("span",{className:"shrink-0 text-muted-foreground/60",children:Ee(d.createdAt)})]},d.id)),(0,e.jsxs)("button",{type:"button",onClick:i(()=>P("activity"),"onClick"),className:"flex items-center gap-1 pt-2 text-xs text-muted-foreground hover:text-foreground",children:["View all activity ",(0,e.jsx)(ve,{className:"h-3 w-3"})]})]})]})]})}i(Ss,"OverviewSection");function ce({icon:s,label:a,value:n,hint:c,to:r,ariaLabel:m}){return(0,e.jsx)("button",{type:"button",onClick:r,"aria-label":m,className:"text-left",children:(0,e.jsx)(Wt,{className:"gap-2 p-4 transition-colors hover:border-border hover:bg-accent/30",children:(0,e.jsxs)(Ut,{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"}),a,(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:n}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:c})]})})})}i(ce,"SummaryCard");function Is(){const{routine:s,newTrigger:a,setNewTrigger:n,createTrigger:c,updateTrigger:r,deleteTrigger:m,rotateTrigger:l,secretMessage:k,copySecretValue:I,setSecretMessage:M}=z(),[C,x]=(0,u.useState)(!1),[S,D]=(0,u.useState)(!0),q=(0,u.useMemo)(()=>a.kind==="schedule"?zt(a.cronExpression):null,[a.cronExpression,a.kind]),A=c.isPending||(q?!q.valid||!S:!1);return(0,u.useEffect)(()=>{a.kind!=="schedule"&&D(!0)},[a.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)(E,{size:"sm",variant:C?"secondary":"default",onClick:i(()=>x(g=>!g),"onClick"),"aria-expanded":C,children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(kt,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(_t,{className:"mr-1.5 h-3.5 w-3.5"}),"New trigger"]})})]}),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:"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)(O,{className:"text-xs",children:"Kind"}),(0,e.jsxs)(he,{value:a.kind,onValueChange:i(g=>n(b=>({...b,kind:g})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:js.map(g=>(0,e.jsx)(ue,{value:g,children:g},g))})]})]}),a.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(O,{className:"text-xs",children:"Schedule"}),(0,e.jsx)($e,{value:a.cronExpression,onChange:i(g=>n(b=>({...b,cronExpression:g})),"onChange"),onValidityChange:D})]}),a.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Signing mode"}),(0,e.jsxs)(he,{value:a.signingMode,onValueChange:i(g=>n(b=>({...b,signingMode:g})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:ws.map(g=>(0,e.jsx)(ue,{value:g,children:g},g))})]}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:Ns[a.signingMode]})]}),!ks.has(a.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Replay window (seconds)"}),(0,e.jsx)(G,{value:a.replayWindowSec,onChange:i(g=>n(b=>({...b,replayWindowSec:g.target.value})),"onChange")})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)(E,{size:"sm",variant:"ghost",onClick:i(()=>x(!1),"onClick"),children:"Cancel"}),(0,e.jsx)(E,{size:"sm",onClick:i(()=>c.mutate(void 0,{onSuccess:i(()=>{n(We()),x(!1)},"onSuccess")}),"onClick"),disabled:A,children:c.isPending?"Adding...":"Add trigger"})]})]}):null,k?(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:k.title}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Save this now. Paperclip will not show the secret value again."})]}),(0,e.jsx)("div",{className:"space-y-3",children:k.entries.map((g,b)=>(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(G,{"aria-label":"New webhook URL",value:g.webhookUrl,readOnly:!0,className:"flex-1"}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>I("Webhook URL",g.webhookUrl),"onClick"),children:"URL"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(G,{"aria-label":"New webhook secret",value:g.webhookSecret,readOnly:!0,className:"flex-1"}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>I("Webhook secret",g.webhookSecret),"onClick"),children:"Secret"})]})]},`${g.webhookUrl}-${b}`))}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>M(null),"onClick"),children:"Done"})]}):null,s.triggers.length===0?(0,e.jsx)(te,{icon:ye,message:"No triggers yet.",action:"Add a trigger",onAction:i(()=>x(!0),"onAction")}):(0,e.jsx)("div",{className:"space-y-3",children:s.triggers.map(g=>(0,e.jsx)(xs,{trigger:g,onSave:i((b,j)=>r.mutate({id:b,patch:j}),"onSave"),onRotate:i(b=>l.mutate(b),"onRotate"),onDelete:i(b=>m.mutate(b),"onDelete")},g.id))})]})}i(Is,"TriggersSection");function Cs(){const{editDraft:s,setEditDraft:a,navigateToSection:n}=z(),c=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:["Variables are auto-detected from ",(0,e.jsx)("code",{className:"font-mono",children:"{{placeholders}}"})," in the title & instructions. The variable name is read-only — rename by editing the placeholder."]}),(0,e.jsxs)(E,{variant:"secondary",size:"sm",onClick:i(()=>n("overview"),"onClick"),children:[(0,e.jsx)(Xt,{className:"mr-1.5 h-3.5 w-3.5"}),"Edit instructions"]})]}),c?(0,e.jsx)(Ue,{title:s.title,description:s.description,value:s.variables,onChange:i(r=>a(m=>({...m,variables:r})),"onChange")}):(0,e.jsx)(te,{icon:ts,message:"No variables yet. Add a {{placeholder}} in the title or instructions to create one.",action:"Edit instructions",onAction:i(()=>n("overview"),"onAction")})]})}i(Cs,"VariablesSection");function As(){const{editDraft:s,setEditDraft:a,availableSecrets:n,createSecret:c}=z(),r=(0,u.useMemo)(()=>[...n].filter(m=>m.status==="active").sort((m,l)=>{const k=(l.referenceCount??0)-(m.referenceCount??0);return k!==0?k:new Date(l.updatedAt).getTime()-new Date(m.updatedAt).getTime()}).slice(0,8),[n]);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:["Routine secrets apply to every task this routine creates. They override matching keys in project and agent env. ",(0,e.jsx)("span",{className:"font-mono",children:"PAPERCLIP_*"})," names are reserved."]}),(0,e.jsx)(os,{value:s.env??{},secrets:n,recentlyUsedSecrets:r,onCreateSecret:i(async(m,l)=>c.mutateAsync({name:m,value:l}),"onCreateSecret"),onChange:i(m=>a(l=>({...l,env:m??null})),"onChange")})]})}i(As,"SecretsSection");function Ps(){const{editDraft:s,setEditDraft:a,routine:n}=z(),c=n.triggers.some(m=>m.kind==="schedule"),r=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:"Concurrency"}),(0,e.jsx)(X,{ariaLabel:"Concurrency policy",value:s.concurrencyPolicy,onValueChange:i(m=>a(l=>({...l,concurrencyPolicy:m})),"onValueChange"),options:ys})]}),(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:"Catch-up"}),(0,e.jsx)(X,{ariaLabel:"Catch-up policy",value:s.catchUpPolicy,onValueChange:i(m=>a(l=>({...l,catchUpPolicy:m})),"onValueChange"),options:vs})]}),(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:"Advanced run policy"}),(0,e.jsx)(X,{ariaLabel:"Advanced run policy",value:s.activityGatePolicy,onValueChange:i(m=>a(l=>({...l,activityGatePolicy:m})),"onValueChange"),options:fs,disabled:!c}),c?r?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-border p-3",children:[(0,e.jsx)(O,{className:"text-xs font-medium",children:"Activity scope"}),(0,e.jsx)(X,{ariaLabel:"Activity gate scope",value:s.activityGateScope,onValueChange:i(m=>a(l=>({...l,activityGateScope:m})),"onValueChange"),options:bs})]}):null:(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Add a schedule trigger to gate runs on activity. Webhook, manual, and API fires always run."})]}),(0,e.jsx)(Ts,{triggers:n.triggers,concurrencyPolicy:s.concurrencyPolicy})]})}i(Ps,"DeliverySection");var Rs={queued:"text-emerald-600 dark:text-emerald-400",coalesced:"text-amber-600 dark:text-amber-400",skipped:"text-muted-foreground"};function Ts({triggers:s,concurrencyPolicy:a}){const n=(0,u.useMemo)(()=>{const c=s.filter(r=>r.kind==="schedule"&&r.enabled&&r.cronExpression).map(r=>({trigger:r,fires:Ht(r.cronExpression,5,{timeZone:r.timezone??"UTC"})})).filter(r=>r.fires.length>0).sort((r,m)=>r.fires[0].getTime()-m.fires[0].getTime())[0];return c?{timeZone:c.trigger.timezone??"UTC",entries:Zt(c.fires,a)}:null},[s,a]);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:"Next 5 fires"}),n?(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:n.entries.map((c,r)=>(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:Es(c.at,n.timeZone)}),(0,e.jsx)(ve,{className:"h-3 w-3 shrink-0 text-muted-foreground/50"}),(0,e.jsx)("span",{className:ut("font-medium",Rs[c.disposition]),children:c.label}),c.note?(0,e.jsxs)("span",{className:"truncate text-muted-foreground/60",children:["(",c.note,")"]}):null]},r))}),(0,e.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/60",children:["Preview assumes the previous run is still in flight when the next fires. Times shown in"," ",n.timeZone,"."]})]}):(0,e.jsx)("p",{className:"rounded-lg border border-dashed border-border p-3 text-xs text-muted-foreground",children:"No enabled schedule trigger to preview. Add a schedule in Triggers to see how this policy treats upcoming fires."})]})}i(Ts,"NextFiresPreview");function Es(s,a){try{return new Intl.DateTimeFormat(void 0,{timeZone:a,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(s).replace(",","")}catch{return s.toISOString()}}i(Es,"formatFireTime");var ge="paperclip.routineLastSection";function Os(s){return s.filter(a=>!a.archivedAt).map(a=>({id:a.id,label:a.name,searchText:a.description??""}))}i(Os,"buildRoutineProjectOptions");var Ds={overview:"Overview",triggers:"Triggers",variables:"Variables",secrets:"Secrets",delivery:"Delivery",runs:"Runs",activity:"Activity",history:"History"};function ee(s){return s!=null&&es.includes(s)}i(ee,"isRoutineSection");function _s(s){try{const a=localStorage.getItem(ge);if(!a)return null;const n=JSON.parse(a)[s];return ee(n)?n:null}catch{return null}}i(_s,"readLastSection");function le(s,a){try{const n=localStorage.getItem(ge),c=n?JSON.parse(n):{};c[s]=a,localStorage.setItem(ge,JSON.stringify(c))}catch{}}i(le,"writeLastSection");var Fe={triggers:"triggers",runs:"runs",activity:"activity",secrets:"secrets",history:"history"};function Ke(s){s&&(s.style.height="auto",s.style.height=`${s.scrollHeight}px`)}i(Ke,"autoResizeTextarea");function Ms(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(Ms,"getLocalTimezone");function qs(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(qs,"buildRoutineMutationPayload");function li(){const{routineId:s,section:a}=ht(),{selectedCompanyId:n}=mt(),{setBreadcrumbs:c}=Et(),r=lt(),m=xt(),{pushToast:l}=ds(),k=(0,u.useRef)(null),I=(0,u.useRef)(null),M=(0,u.useRef)(null),C=(0,u.useRef)(null),x=(0,u.useRef)(null),[S,D]=(0,u.useState)(null),[q,A]=(0,u.useState)(!1),[g,b]=(0,u.useState)(!1),[j,se]=(0,u.useState)(We),[f,P]=(0,u.useState)({title:"",description:"",projectId:"",assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",activityGatePolicy:"always",activityGateScope:"company",variables:[],env:null}),w=ee(a)?a:"overview",_=(0,u.useCallback)((t,h)=>{s&&(le(s,t),m(`/routines/${s}/${t}`,{replace:h?.replace??!0}))},[m,s]),{data:o,isLoading:Q,error:W}=L({queryKey:p.routines.detail(s),queryFn:i(()=>T.get(s),"queryFn"),enabled:!!s}),R=o?.activeIssue?.id,{data:B}=L({queryKey:p.issues.liveRuns(R),queryFn:i(()=>Ft.liveRunsForIssue(R),"queryFn"),enabled:!!R,refetchInterval:3e3}),d=(B??[]).length>0,{data:y}=L({queryKey:p.routines.runs(s),queryFn:i(()=>T.listRuns(s),"queryFn"),enabled:!!s,refetchInterval:d?3e3:!1}),V=(0,u.useMemo)(()=>({triggerIds:o?.triggers.map(t=>t.id)??[],runIds:y?.map(t=>t.id)??[]}),[o?.triggers,y]),{data:Ge}=L({queryKey:[...p.routines.activity(n,s),V.triggerIds.join(","),V.runIds.join(",")],queryFn:i(()=>T.activity(n,s,V),"queryFn"),enabled:!!n&&!!s&&!!o}),{data:F}=L({queryKey:p.agents.list(n),queryFn:i(()=>Rt.list(n),"queryFn"),enabled:!!n}),{data:K}=L({queryKey:p.projects.list(n,{includeArchived:!0}),queryFn:i(()=>Tt.list(n,{includeArchived:!0}),"queryFn"),enabled:!!n}),{data:fe}=L({queryKey:p.access.companyUserDirectory(n),queryFn:i(()=>Lt.listUserDirectory(n),"queryFn"),enabled:!!n}),{data:Ve=[]}=L({queryKey:n?p.secrets.list(n):["secrets","none"],queryFn:i(()=>qe.list(n),"queryFn"),enabled:!!n}),ze=U({mutationFn:i(t=>{if(!n)throw new Error("Select a company to create secrets");return qe.create(n,t)},"mutationFn"),onSuccess:i(()=>{n&&r.invalidateQueries({queryKey:p.secrets.list(n)})},"onSuccess")}),v=(0,u.useMemo)(()=>o?{title:o.title,description:o.description??"",projectId:o.projectId??"",assigneeAgentId:o.assigneeAgentId??"",priority:o.priority,concurrencyPolicy:o.concurrencyPolicy,catchUpPolicy:o.catchUpPolicy,activityGatePolicy:o.activityGatePolicy,activityGateScope:o.activityGateScope,variables:o.variables,env:o.env??null}:null,[o]),H=(0,u.useMemo)(()=>{if(!v)return[];const t=[];return f.title!==v.title&&t.push({key:"title",label:"the title"}),f.description!==v.description&&t.push({key:"description",label:"the description"}),f.projectId!==v.projectId&&t.push({key:"projectId",label:"the project"}),f.assigneeAgentId!==v.assigneeAgentId&&t.push({key:"assigneeAgentId",label:"the default agent"}),f.priority!==v.priority&&t.push({key:"priority",label:"the priority"}),f.concurrencyPolicy!==v.concurrencyPolicy&&t.push({key:"concurrencyPolicy",label:"the concurrency policy"}),f.catchUpPolicy!==v.catchUpPolicy&&t.push({key:"catchUpPolicy",label:"the catch-up policy"}),f.activityGatePolicy!==v.activityGatePolicy&&t.push({key:"activityGatePolicy",label:"the advanced run policy"}),f.activityGateScope!==v.activityGateScope&&t.push({key:"activityGateScope",label:"the activity gate scope"}),JSON.stringify(f.variables)!==JSON.stringify(v.variables)&&t.push({key:"variables",label:"the variables"}),JSON.stringify(f.env??null)!==JSON.stringify(v.env??null)&&t.push({key:"env",label:"the secrets"}),t},[f,v]),ie=H.length>0,J=(0,u.useCallback)(t=>{const h=Me[t];return h?H.filter(N=>h.includes(N.key)):[]},[H]),ne=(0,u.useCallback)(t=>J(t).length>0,[J]),be=(0,u.useCallback)(t=>{if(!v)return;const h=Me[t];h&&P(N=>{const Re={...N};for(const Te of h)Re[Te]=v[Te];return Re})},[v]);(0,u.useEffect)(()=>{o&&(c([{label:"Routines",href:"/routines"},{label:o.title}]),v&&(k.current!==o.id||!ie)&&(P(v),k.current=o.id))},[o,v,ie,c]),(0,u.useEffect)(()=>{Ke(I.current)},[f.title,o?.id]),(0,u.useEffect)(()=>{s&&ee(a)&&le(s,a)},[s,a]);const Qe=(0,u.useCallback)(async(t,h)=>{try{await qt(h),l({title:`${t} copied`,tone:"success"})}catch(N){l({title:`Failed to copy ${t.toLowerCase()}`,body:N instanceof Error?N.message:"Clipboard access was denied.",tone:"error"})}},[l]),Y=U({mutationFn:i(()=>{const t=qs(f),h=o?.latestRevisionId??null;return T.update(s,{...t,...h?{baseRevisionId:h}:{}})},"mutationFn"),onSuccess:i(async()=>{A(!1),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)}),r.invalidateQueries({queryKey:p.routines.revisions(s)})])},"onSuccess"),onError:i(t=>{if(t instanceof dt&&t.status===409){A(!0),l({title:"Routine changed",body:"Someone else updated this routine. Reload to see the latest revision.",tone:"warn"});return}l({title:"Failed to save routine",body:t instanceof Error?t.message:"Paperclip could not save the routine.",tone:"error"})},"onError")}),Z=U({mutationFn:i(t=>T.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:"Routine run started",tone:"success"}),b(!1),_("runs"),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.runs(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Routine run failed",body:t instanceof Error?t.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),je=U({mutationFn:i(t=>T.update(s,{status:t}),"mutationFn"),onSuccess:i(async(t,h)=>{l({title:"Routine saved",body:h==="paused"?"Automation paused.":"Automation enabled.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to update routine",body:t instanceof Error?t.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Be=U({mutationFn:i(async()=>{const t=(o?.triggers??[]).filter(N=>N.kind===j.kind).length,h=t>0?`${j.kind}-${t+1}`:j.kind;return T.createTrigger(s,{kind:j.kind,label:h,...j.kind==="schedule"?{cronExpression:j.cronExpression.trim(),timezone:Ms()}:{},...j.kind==="webhook"?{signingMode:j.signingMode,replayWindowSec:Number(j.replayWindowSec||"300")}:{}})},"mutationFn"),onSuccess:i(async t=>{t.secretMaterial?D({title:"Webhook trigger created",entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}):l({title:"Trigger added",body:"The routine schedule was saved.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to add trigger",body:t instanceof Error?t.message:"Paperclip could not create the trigger.",tone:"error"})},"onError")}),He=U({mutationFn:i(({id:t,patch:h})=>T.updateTrigger(t,h),"mutationFn"),onSuccess:i(async()=>{l({title:"Trigger saved",body:"The routine cadence update was saved.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to update trigger",body:t instanceof Error?t.message:"Paperclip could not update the trigger.",tone:"error"})},"onError")}),Je=U({mutationFn:i(t=>T.deleteTrigger(t),"mutationFn"),onSuccess:i(async()=>{l({title:"Trigger deleted",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to delete trigger",body:t instanceof Error?t.message:"Paperclip could not delete the trigger.",tone:"error"})},"onError")}),Ye=U({mutationFn:i(t=>T.rotateTriggerSecret(t),"mutationFn"),onSuccess:i(async t=>{D({title:"Webhook secret rotated",entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to rotate webhook secret",body:t instanceof Error?t.message:"Paperclip could not rotate the webhook secret.",tone:"error"})},"onError")}),we=(0,u.useMemo)(()=>new Map((F??[]).map(t=>[t.id,t])),[F]),Ne=(0,u.useMemo)(()=>new Map((K??[]).map(t=>[t.id,t])),[K]),ae=(0,u.useMemo)(()=>ft(),[o?.id]),Ze=(0,u.useMemo)(()=>wt(),[o?.id]),Xe=(0,u.useMemo)(()=>vt((F??[]).filter(t=>t.status!=="terminated"),ae).map(t=>({id:t.id,label:t.name,searchText:`${t.name} ${t.role} ${t.title??""}`})),[F,ae]),et=(0,u.useMemo)(()=>Os(K??[]),[K]),tt=(0,u.useMemo)(()=>Kt({agents:F,projects:(K??[]).filter(t=>!t.archivedAt),members:fe?.users}),[F,fe?.users,K]),st=(0,u.useCallback)(t=>{P(h=>{const N=typeof t=="function"?t(h):t;return N.assigneeAgentId&&N.assigneeAgentId!==h.assigneeAgentId&&yt(N.assigneeAgentId),N.projectId&&N.projectId!==h.projectId&&Nt(N.projectId),N})},[]),it=f.assigneeAgentId?we.get(f.assigneeAgentId)??null:null,nt=f.projectId?Ne.get(f.projectId)??null:null,ke=(0,u.useCallback)(()=>{A(!1),v&&P(v),r.invalidateQueries({queryKey:p.routines.detail(s)})},[r,v,s]),at=(0,u.useCallback)(t=>{t.secretMaterials.length>0&&(_("triggers"),D({title:t.secretMaterials.length===1?"Webhook trigger restored":`${t.secretMaterials.length} webhook triggers restored`,entries:t.secretMaterials.map(h=>({webhookUrl:h.webhookUrl,webhookSecret:h.webhookSecret}))}))},[_]),rt=(0,u.useCallback)(t=>{A(!1),r.setQueryData(p.routines.detail(s),h=>h&&{...h,...t.routine,latestRevisionId:t.revision.id,latestRevisionNumber:t.revision.revisionNumber}),P({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}),k.current=t.routine.id},[r,s]);if(!n)return(0,e.jsx)(te,{icon:jt,message:"Select a company to view routines."});const re=new URLSearchParams(window.location.search).get("tab");if(s&&re&&Fe[re])return(0,e.jsx)(oe,{to:`/routines/${s}/${Fe[re]}`,replace:!0});if(s&&!a){const t=_s(s)??"overview";return(0,e.jsx)(oe,{to:`/routines/${s}/${t}`,replace:!0})}if(s&&a&&!ee(a))return(0,e.jsx)(oe,{to:`/routines/${s}/overview`,replace:!0});if(Q)return(0,e.jsx)($t,{variant:"issues-list"});if(W||!o||!v)return(0,e.jsx)(te,{icon:Ot,message:W instanceof Error?W.message:"We couldn't load this routine."});const $=o.status==="active",Se=je.isPending||o.status==="archived",Ie=o.status==="archived"?"Archived":o.assigneeAgentId?$?"Active":"Paused":"Draft",Ce=o.status==="archived"?"text-muted-foreground":$?"text-emerald-400":"text-muted-foreground",Ae={routine:o,routineId:s,companyId:o.companyId,editDraft:f,setEditDraft:st,routineDefaults:v,dirtyFields:H,isEditDirty:ie,sectionDirtyFields:J,isSectionDirty:ne,discardSection:be,saveRoutine:Y,saveConflict:q,reloadLatest:ke,automationEnabled:$,automationLabel:Ie,automationLabelClassName:Ce,automationToggleDisabled:Se,onToggleAutomation:i(()=>{if(!$&&!o.assigneeAgentId){l({title:"Default agent required",body:"Set a default agent before enabling routine automation.",tone:"warn"});return}je.mutate($?"paused":"active")},"onToggleAutomation"),onOpenRunDialog:i(()=>b(!0),"onOpenRunDialog"),runRoutinePending:Z.isPending,newTrigger:j,setNewTrigger:se,createTrigger:Be,updateTrigger:He,deleteTrigger:Je,rotateTrigger:Ye,secretMessage:S,setSecretMessage:D,copySecretValue:Qe,availableSecrets:Ve,createSecret:ze,agents:F??[],projects:K??[],agentById:we,projectById:Ne,assigneeOptions:Xe,projectOptions:et,recentAssigneeIds:ae,recentProjectIds:Ze,mentionOptions:tt,currentAssignee:it,currentProject:nt,routineRuns:y,activity:Ge,hasLiveRun:d,activeIssueId:R,titleInputRef:I,descriptionEditorRef:M,assigneeSelectorRef:C,projectSelectorRef:x,onHistoryRestoreSecretMaterials:at,onHistoryRestored:rt,navigateToSection:_},Pe=Qt.includes(w);return(0,e.jsxs)(ns.Provider,{value:Ae,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:"Skip to section"}),(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:I,"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:"Routine title",rows:1,value:f.title,onChange:i(t=>{P(h=>({...h,title:t.target.value})),Ke(t.target)},"onChange"),onKeyDown:i(t=>{t.key==="Enter"&&!t.metaKey&&!t.ctrlKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),w==="overview"?M.current?.focus():_("overview"))},"onKeyDown")}),o.managedByPlugin?(0,e.jsxs)(xe,{variant:"outline",className:"hidden shrink-0 gap-1.5 text-xs text-muted-foreground sm:inline-flex",children:[(0,e.jsx)(Pt,{className:"h-3 w-3"}),o.managedByPlugin.pluginDisplayName,(0,e.jsx)("span",{className:"font-mono text-(length:--text-nano)",children:o.managedByPlugin.resourceKey})]}):null]}),(0,e.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-3",children:[(0,e.jsx)(Vt,{onClick:i(()=>b(!0),"onClick"),disabled:Z.isPending}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(At,{size:"default",checked:$,onCheckedChange:Ae.onToggleAutomation,disabled:Se,"aria-label":$?"Pause automatic triggers":"Enable automatic triggers"}),(0,e.jsx)("span",{className:`text-sm font-medium ${Ce}`,children:Ie})]})]})]}),(0,e.jsx)(Gt,{activeSection:w,onNavigate:_,isSectionDirty:ne}),(0,e.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,e.jsx)(is,{activeSection:w,hrefFor:i(t=>`/routines/${s}/${t}`,"hrefFor"),isSectionDirty:ne,hasLiveRun:d,onNavigate:i(t=>le(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:Pe?"mx-auto w-full max-w-3xl":"w-full",children:[(0,e.jsx)("h2",{id:"routine-section-title",className:"mb-4 text-lg font-semibold",children:Ds[w]}),w==="overview"&&(0,e.jsx)(Ss,{}),w==="triggers"&&(0,e.jsx)(Is,{}),w==="variables"&&(0,e.jsx)(Cs,{}),w==="secrets"&&(0,e.jsx)(As,{}),w==="delivery"&&(0,e.jsx)(Ps,{}),w==="runs"&&(0,e.jsx)(Yt,{}),w==="activity"&&(0,e.jsx)(ls,{}),w==="history"&&(0,e.jsx)(Jt,{}),Pe?(0,e.jsx)(us,{dirtyFields:J(w),isSaving:Y.isPending,saveConflict:q,onSave:i(()=>{!Y.isPending&&f.title.trim()&&Y.mutate()},"onSave"),onDiscard:i(()=>be(w),"onDiscard"),onReload:ke}):null]})})]})]}),(0,e.jsx)(bt,{open:g,onOpenChange:b,companyId:o.companyId,routineName:o.title,agents:F??[],projects:K??[],defaultProjectId:o.projectId,defaultAssigneeAgentId:o.assigneeAgentId,variables:o.variables??[],isPending:Z.isPending,onSubmit:i(t=>Z.mutate(t),"onSubmit")})]})}i(li,"RoutineDetail");export{li as RoutineDetail};
1
+ var ot=Object.defineProperty;var i=(s,a)=>ot(s,"name",{value:a,configurable:!0});import{i as Le}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as ct,Ei as lt,Ir as dt,Jr as L,S as ut,U as mt,X as p,ki as pt,qr as U}from"./agent-avatar-url-CiVC72zn.js";import{Ht as ht,Mt as Ee,b as gt,o as xt,r as oe}from"./router-CGbOrhXy.js";import{Ct as yt,St as vt,bt as ft,dt as Oe,t as bt,ur as jt,vt as wt,yt as Nt}from"./RoutineRunVariablesDialog--quGEm4y.js";import{Z as kt}from"./mention-chips-3yfCFzXQ.js";import{l as T,t as De}from"./MarkdownEditor-D0uqxShB.js";import{v as St}from"./sheet-CqcQLexE.js";import{t as _e}from"./AgentAvatar-CrnNGelJ.js";import{k as It}from"./checkbox-SdYP--OH.js";import{_ as Ct,s as At,t as O}from"./label-CA4aszl3.js";import{r as Pt,t as Rt}from"./agents-BGdf-J_C.js";import{g as Tt}from"./StatusIcon-D__DIZlm.js";import{r as Et,t as te}from"./EmptyState-ClZXiygF.js";import{c as de,i as ue,n as me,s as pe,t as he}from"./select-Db0ppga4.js";import{r as Ot,t as Dt}from"./save-dnfn3gBp.js";import{k as _t,t as E}from"./button-BmDU7YzH.js";import{n as Mt,t as qt}from"./clipboard-CATj6OsB.js";import{t as Ft}from"./heartbeats-By7EcEMQ.js";import{t as xe}from"./badge-Dwnb7bwc.js";import{t as G}from"./input-CfZ7FdDr.js";import{i as Kt,o as Lt}from"./company-members-c2ldQ5sU.js";import{r as Ut,t as Wt}from"./card-V5O2wbgV.js";import{t as $t}from"./PageSkeleton-DQuX4FJP.js";import{B as Gt,Bn as ye,Dt as Vt,F as zt,G as Me,Gn as ve,H as Qt,I as Bt,J as Ue,K as We,L as Ht,M as Jt,N as Yt,P as $e,Qt as X,R as Zt,Tn as Xt,U as es,Un as ts,Ut as ss,V as is,W as ns,Wt as as,Y as rs,Yt as os,en as qe,hn as cs,j as ls,mn as ds,q as z,z as us}from"./index-DcHMTMN0.js";var u=Le(pt(),1);function ms(s,a,n){const c={label:a.label.trim()||null};return s.kind==="schedule"&&(c.cronExpression=a.cronExpression.trim(),c.timezone=s.timezone??n),s.kind==="webhook"&&(c.signingMode=a.signingMode,c.replayWindowSec=Number(a.replayWindowSec||"300")),c}i(ms,"buildRoutineTriggerPatch");var e=Le(ct(),1),ps=["app_webhook","bearer","hmac_sha256","github_hmac","none"],hs=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function gs(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(gs,"getLocalTimezone$1");function xs({trigger:s,onSave:a,onRotate:n,onDelete:c,disabled:r}){const[m,l]=(0,u.useState)({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)});(0,u.useEffect)(()=>{l({label:s.label??"",cronExpression:s.cronExpression??"",signingMode:s.signingMode??"bearer",replayWindowSec:String(s.replayWindowSec??300)})},[s]);const k=s.kind==="schedule"?ye:s.kind==="webhook"?cs:gt,I=s.kind==="schedule"?Bt(m.cronExpression):null,M=/fail|error/i.test(s.lastResult??""),C=s.lastResult?.startsWith("Created execution issue ")?"Task created":s.lastResult;return(0,e.jsxs)("form",{"aria-label":`Trigger: ${s.label??s.kind}`,className:"space-y-4 rounded-lg border border-border p-4",onSubmit:i(x=>x.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)(k,{className:"h-3.5 w-3.5 shrink-0"}),(0,e.jsx)("span",{className:"truncate",children:s.label??s.kind})]}),I?(0,e.jsx)("p",{id:`cron-readable-${s.id}`,className:"text-xs text-muted-foreground",children:I}):null]}),(0,e.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[s.lastResult?(0,e.jsx)(xe,{variant:M?"destructive":"secondary",children:C}):null,(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:s.kind==="schedule"&&s.nextRunAt?`Next: ${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)(O,{htmlFor:`webhook-url-${s.id}`,className:"text-xs",children:"Webhook URL"}),(0,e.jsx)(G,{id:`webhook-url-${s.id}`,value:s.webhookUrl,readOnly:!0,onFocus:i(x=>x.target.select(),"onFocus")}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"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)(O,{className:"text-xs",children:"Label"}),(0,e.jsx)(G,{value:m.label,disabled:r,onChange:i(x=>l(S=>({...S,label:x.target.value})),"onChange")})]}),s.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(O,{className:"text-xs",children:"Schedule"}),(0,e.jsx)($e,{value:m.cronExpression,onChange:i(x=>l(S=>({...S,cronExpression:x})),"onChange")})]}),s.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Signing mode"}),(0,e.jsxs)(he,{value:m.signingMode,onValueChange:i(x=>l(S=>({...S,signingMode:x})),"onValueChange"),disabled:r,children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:ps.map(x=>(0,e.jsx)(ue,{value:x,children:x},x))})]})]}),!hs.has(m.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Replay window (seconds)"}),(0,e.jsx)(G,{value:m.replayWindowSec,disabled:r,onChange:i(x=>l(S=>({...S,replayWindowSec:x.target.value})),"onChange")})]})]})]}),!r&&(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,e.jsxs)(E,{variant:"ghost",size:"sm",className:"mr-auto text-muted-foreground hover:text-destructive",onClick:i(()=>c(s.id),"onClick"),children:[(0,e.jsx)(It,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete"]}),s.kind==="webhook"&&(0,e.jsxs)(E,{variant:"outline",size:"sm",onClick:i(()=>n(s.id),"onClick"),children:[(0,e.jsx)(St,{className:"mr-1.5 h-3.5 w-3.5"}),"Rotate secret"]}),(0,e.jsxs)(E,{variant:"outline",size:"sm",onClick:i(()=>a(s.id,ms(s,m,gs())),"onClick"),children:[(0,e.jsx)(Dt,{className:"mr-1.5 h-3.5 w-3.5"}),"Save trigger"]})]})]})}i(xs,"RoutineTriggerCard");var ys=[{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."}],vs=[{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."}],fs=[{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."}],bs=[{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."}],js=["schedule","webhook"],ws=["app_webhook","bearer","hmac_sha256","github_hmac","none"],Ns={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."},ks=new Set(["app_webhook","bearer","github_hmac","fireflies_hmac","none"]);function Ss({defaultDescriptionAnnotationsOpen:s=!1}={}){const{routine:a,editDraft:n,setEditDraft:c,assigneeOptions:r,projectOptions:m,recentAssigneeIds:l,recentProjectIds:k,agentById:I,projectById:M,currentAssignee:C,currentProject:x,mentionOptions:S,assigneeSelectorRef:D,projectSelectorRef:q,descriptionEditorRef:A,routineRuns:g,activity:b,saveRoutine:j,saveConflict:se,isSectionDirty:f,navigateToSection:P}=z(),[w,_]=(0,u.useState)(s),o=a.triggers.length,Q=(0,u.useMemo)(()=>{const d=a.triggers.filter(y=>y.kind==="schedule"&&y.nextRunAt).map(y=>new Date(y.nextRunAt)).sort((y,V)=>y.getTime()-V.getTime())[0];return d?d.toLocaleString():null},[a.triggers]),W=n.env?Object.keys(n.env).length:0,R=(g??[])[0]??null,B=(b??[]).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:"For"}),(0,e.jsx)(Oe,{ref:D,value:n.assigneeAgentId,options:r,recentOptionIds:l,placeholder:"Responsible",noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:"No responsible found.",onChange:i(d=>c(y=>({...y,assigneeAgentId:d})),"onChange"),onConfirm:i(()=>{n.projectId?A.current?.focus():q.current?.focus()},"onConfirm"),renderTriggerValue:i(d=>d?C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(_e,{agent:C,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,e.jsx)("span",{className:"truncate",children:d.label})]}):(0,e.jsx)("span",{className:"truncate",children:d.label}):(0,e.jsx)("span",{className:"text-muted-foreground",children:"Responsible"}),"renderTriggerValue"),renderOption:i(d=>{if(!d.id)return(0,e.jsx)("span",{className:"truncate",children:d.label});const y=I.get(d.id);return(0,e.jsxs)(e.Fragment,{children:[y?(0,e.jsx)(_e,{agent:y,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,e.jsx)("span",{className:"truncate",children:d.label})]})},"renderOption")}),(0,e.jsx)("span",{children:"in"}),(0,e.jsx)(Oe,{ref:q,value:n.projectId,options:m,recentOptionIds:k,placeholder:"Project",noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:"No projects found.",onChange:i(d=>c(y=>({...y,projectId:d})),"onChange"),onConfirm:i(()=>A.current?.focus(),"onConfirm"),renderTriggerValue:i(d=>d&&x?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:x.color??"var(--project-none)"}}),(0,e.jsx)("span",{className:"truncate",children:d.label})]}):(0,e.jsx)("span",{className:"text-muted-foreground",children:"Project"}),"renderTriggerValue"),renderOption:i(d=>{if(!d.id)return(0,e.jsx)("span",{className:"truncate",children:d.label});const y=M.get(d.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:d.label})]})},"renderOption")})]})}),a.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:"Default agent required. This routine can stay as a draft and still run manually, but automation stays paused until you assign a default agent."}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("div",{className:"flex items-center justify-end",children:a.descriptionDocument?(0,e.jsx)(ss,{issueId:a.id,docKey:"description",target:{kind:"routine",routineId:a.id,documentKey:"description"},panelOpen:w,onToggle:i(()=>_(d=>!d),"onToggle")}):null}),a.descriptionDocument?(0,e.jsx)(as,{issueId:a.id,doc:a.descriptionDocument,target:{kind:"routine",routineId:a.id,documentKey:"description"},bodyMarkdown:n.description,draftDirty:f("overview")||j.isPending,draftConflicted:se,historicalPreview:!1,locationHash:typeof window>"u"?"":window.location.hash,panelOpen:w,onPanelOpenChange:_,children:(0,e.jsx)(De,{ref:A,value:n.description,onChange:i(d=>c(y=>({...y,description:d})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:S,onSubmit:i(()=>{!j.isPending&&n.title.trim()&&j.mutate()},"onSubmit")})}):(0,e.jsx)(De,{ref:A,value:n.description,onChange:i(d=>c(y=>({...y,description:d})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-120px) text-sm leading-7",mentions:S,onSubmit:i(()=>{!j.isPending&&n.title.trim()&&j.mutate()},"onSubmit")})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsx)(rs,{}),(0,e.jsx)(Ue,{title:n.title,description:n.description,value:n.variables,onChange:i(d=>c(y=>({...y,variables:d})),"onChange")})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsx)(ce,{icon:ye,label:"Triggers",value:o===0?"None":`${o} active`,hint:Q?`Next fire ${Q}`:"No schedule",to:i(()=>P("triggers"),"to"),ariaLabel:`${o} triggers. Open triggers.`}),(0,e.jsx)(ce,{icon:Mt,label:"Secrets",value:W===0?"None":`${W} bound`,hint:"Manage bound secrets",to:i(()=>P("secrets"),"to"),ariaLabel:`${W} secrets bound. Open secrets.`}),(0,e.jsx)(ce,{icon:Ct,label:"Last run",value:R?R.status.replaceAll("_"," "):"No runs",hint:R?Ee(R.triggeredAt):"Trigger a run",to:i(()=>P("runs"),"to"),ariaLabel:R?`Last run ${R.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:"Recent activity"}),B.length===0?(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"No activity yet."}):(0,e.jsxs)("div",{className:"divide-y divide-border/60",children:[B.map(d=>(0,e.jsxs)("div",{className:"flex items-center gap-2 py-1.5 text-xs",children:[(0,e.jsx)(xe,{variant:"outline",className:"shrink-0 font-mono",children:d.action}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:d.details&&Object.keys(d.details).length>0?Object.keys(d.details).slice(0,3).join(" · "):""}),(0,e.jsx)("span",{className:"shrink-0 text-muted-foreground/60",children:Ee(d.createdAt)})]},d.id)),(0,e.jsxs)("button",{type:"button",onClick:i(()=>P("activity"),"onClick"),className:"flex items-center gap-1 pt-2 text-xs text-muted-foreground hover:text-foreground",children:["View all activity ",(0,e.jsx)(ve,{className:"h-3 w-3"})]})]})]})]})}i(Ss,"OverviewSection");function ce({icon:s,label:a,value:n,hint:c,to:r,ariaLabel:m}){return(0,e.jsx)("button",{type:"button",onClick:r,"aria-label":m,className:"text-left",children:(0,e.jsx)(Wt,{className:"gap-2 p-4 transition-colors hover:border-border hover:bg-accent/30",children:(0,e.jsxs)(Ut,{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"}),a,(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:n}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:c})]})})})}i(ce,"SummaryCard");function Is(){const{routine:s,newTrigger:a,setNewTrigger:n,createTrigger:c,updateTrigger:r,deleteTrigger:m,rotateTrigger:l,secretMessage:k,copySecretValue:I,setSecretMessage:M}=z(),[C,x]=(0,u.useState)(!1),[S,D]=(0,u.useState)(!0),q=(0,u.useMemo)(()=>a.kind==="schedule"?zt(a.cronExpression):null,[a.cronExpression,a.kind]),A=c.isPending||(q?!q.valid||!S:!1);return(0,u.useEffect)(()=>{a.kind!=="schedule"&&D(!0)},[a.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)(E,{size:"sm",variant:C?"secondary":"default",onClick:i(()=>x(g=>!g),"onClick"),"aria-expanded":C,children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(kt,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(_t,{className:"mr-1.5 h-3.5 w-3.5"}),"New trigger"]})})]}),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:"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)(O,{className:"text-xs",children:"Kind"}),(0,e.jsxs)(he,{value:a.kind,onValueChange:i(g=>n(b=>({...b,kind:g})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:js.map(g=>(0,e.jsx)(ue,{value:g,children:g},g))})]})]}),a.kind==="schedule"&&(0,e.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,e.jsx)(O,{className:"text-xs",children:"Schedule"}),(0,e.jsx)($e,{value:a.cronExpression,onChange:i(g=>n(b=>({...b,cronExpression:g})),"onChange"),onValidityChange:D})]}),a.kind==="webhook"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Signing mode"}),(0,e.jsxs)(he,{value:a.signingMode,onValueChange:i(g=>n(b=>({...b,signingMode:g})),"onValueChange"),children:[(0,e.jsx)(pe,{children:(0,e.jsx)(de,{})}),(0,e.jsx)(me,{children:ws.map(g=>(0,e.jsx)(ue,{value:g,children:g},g))})]}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:Ns[a.signingMode]})]}),!ks.has(a.signingMode)&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)(O,{className:"text-xs",children:"Replay window (seconds)"}),(0,e.jsx)(G,{value:a.replayWindowSec,onChange:i(g=>n(b=>({...b,replayWindowSec:g.target.value})),"onChange")})]})]})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)(E,{size:"sm",variant:"ghost",onClick:i(()=>x(!1),"onClick"),children:"Cancel"}),(0,e.jsx)(E,{size:"sm",onClick:i(()=>c.mutate(void 0,{onSuccess:i(()=>{n(We()),x(!1)},"onSuccess")}),"onClick"),disabled:A,children:c.isPending?"Adding...":"Add trigger"})]})]}):null,k?(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:k.title}),(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Save this now. Paperclip will not show the secret value again."})]}),(0,e.jsx)("div",{className:"space-y-3",children:k.entries.map((g,b)=>(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(G,{"aria-label":"New webhook URL",value:g.webhookUrl,readOnly:!0,className:"flex-1"}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>I("Webhook URL",g.webhookUrl),"onClick"),children:"URL"})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(G,{"aria-label":"New webhook secret",value:g.webhookSecret,readOnly:!0,className:"flex-1"}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>I("Webhook secret",g.webhookSecret),"onClick"),children:"Secret"})]})]},`${g.webhookUrl}-${b}`))}),(0,e.jsx)(E,{variant:"outline",size:"sm",onClick:i(()=>M(null),"onClick"),children:"Done"})]}):null,s.triggers.length===0?(0,e.jsx)(te,{icon:ye,message:"No triggers yet.",action:"Add a trigger",onAction:i(()=>x(!0),"onAction")}):(0,e.jsx)("div",{className:"space-y-3",children:s.triggers.map(g=>(0,e.jsx)(xs,{trigger:g,onSave:i((b,j)=>r.mutate({id:b,patch:j}),"onSave"),onRotate:i(b=>l.mutate(b),"onRotate"),onDelete:i(b=>m.mutate(b),"onDelete")},g.id))})]})}i(Is,"TriggersSection");function Cs(){const{editDraft:s,setEditDraft:a,navigateToSection:n}=z(),c=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:["Variables are auto-detected from ",(0,e.jsx)("code",{className:"font-mono",children:"{{placeholders}}"})," in the title & instructions. The variable name is read-only — rename by editing the placeholder."]}),(0,e.jsxs)(E,{variant:"secondary",size:"sm",onClick:i(()=>n("overview"),"onClick"),children:[(0,e.jsx)(Xt,{className:"mr-1.5 h-3.5 w-3.5"}),"Edit instructions"]})]}),c?(0,e.jsx)(Ue,{title:s.title,description:s.description,value:s.variables,onChange:i(r=>a(m=>({...m,variables:r})),"onChange")}):(0,e.jsx)(te,{icon:ts,message:"No variables yet. Add a {{placeholder}} in the title or instructions to create one.",action:"Edit instructions",onAction:i(()=>n("overview"),"onAction")})]})}i(Cs,"VariablesSection");function As(){const{editDraft:s,setEditDraft:a,availableSecrets:n,createSecret:c}=z(),r=(0,u.useMemo)(()=>[...n].filter(m=>m.status==="active").sort((m,l)=>{const k=(l.referenceCount??0)-(m.referenceCount??0);return k!==0?k:new Date(l.updatedAt).getTime()-new Date(m.updatedAt).getTime()}).slice(0,8),[n]);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:["Routine secrets apply to every task this routine creates. They override matching keys in project and agent env. ",(0,e.jsx)("span",{className:"font-mono",children:"PAPERCLIP_*"})," names are reserved."]}),(0,e.jsx)(os,{value:s.env??{},secrets:n,recentlyUsedSecrets:r,onCreateSecret:i(async(m,l)=>c.mutateAsync({name:m,value:l}),"onCreateSecret"),onChange:i(m=>a(l=>({...l,env:m??null})),"onChange")})]})}i(As,"SecretsSection");function Ps(){const{editDraft:s,setEditDraft:a,routine:n}=z(),c=n.triggers.some(m=>m.kind==="schedule"),r=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:"Concurrency"}),(0,e.jsx)(X,{ariaLabel:"Concurrency policy",value:s.concurrencyPolicy,onValueChange:i(m=>a(l=>({...l,concurrencyPolicy:m})),"onValueChange"),options:ys})]}),(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:"Catch-up"}),(0,e.jsx)(X,{ariaLabel:"Catch-up policy",value:s.catchUpPolicy,onValueChange:i(m=>a(l=>({...l,catchUpPolicy:m})),"onValueChange"),options:vs})]}),(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:"Advanced run policy"}),(0,e.jsx)(X,{ariaLabel:"Advanced run policy",value:s.activityGatePolicy,onValueChange:i(m=>a(l=>({...l,activityGatePolicy:m})),"onValueChange"),options:fs,disabled:!c}),c?r?(0,e.jsxs)("div",{className:"space-y-2 rounded-lg border border-border p-3",children:[(0,e.jsx)(O,{className:"text-xs font-medium",children:"Activity scope"}),(0,e.jsx)(X,{ariaLabel:"Activity gate scope",value:s.activityGateScope,onValueChange:i(m=>a(l=>({...l,activityGateScope:m})),"onValueChange"),options:bs})]}):null:(0,e.jsx)("p",{className:"text-xs text-muted-foreground",children:"Add a schedule trigger to gate runs on activity. Webhook, manual, and API fires always run."})]}),(0,e.jsx)(Ts,{triggers:n.triggers,concurrencyPolicy:s.concurrencyPolicy})]})}i(Ps,"DeliverySection");var Rs={queued:"text-emerald-600 dark:text-emerald-400",coalesced:"text-amber-600 dark:text-amber-400",skipped:"text-muted-foreground"};function Ts({triggers:s,concurrencyPolicy:a}){const n=(0,u.useMemo)(()=>{const c=s.filter(r=>r.kind==="schedule"&&r.enabled&&r.cronExpression).map(r=>({trigger:r,fires:Ht(r.cronExpression,5,{timeZone:r.timezone??"UTC"})})).filter(r=>r.fires.length>0).sort((r,m)=>r.fires[0].getTime()-m.fires[0].getTime())[0];return c?{timeZone:c.trigger.timezone??"UTC",entries:Zt(c.fires,a)}:null},[s,a]);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:"Next 5 fires"}),n?(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:n.entries.map((c,r)=>(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:Es(c.at,n.timeZone)}),(0,e.jsx)(ve,{className:"h-3 w-3 shrink-0 text-muted-foreground/50"}),(0,e.jsx)("span",{className:ut("font-medium",Rs[c.disposition]),children:c.label}),c.note?(0,e.jsxs)("span",{className:"truncate text-muted-foreground/60",children:["(",c.note,")"]}):null]},r))}),(0,e.jsxs)("p",{className:"text-(length:--text-micro) text-muted-foreground/60",children:["Preview assumes the previous run is still in flight when the next fires. Times shown in"," ",n.timeZone,"."]})]}):(0,e.jsx)("p",{className:"rounded-lg border border-dashed border-border p-3 text-xs text-muted-foreground",children:"No enabled schedule trigger to preview. Add a schedule in Triggers to see how this policy treats upcoming fires."})]})}i(Ts,"NextFiresPreview");function Es(s,a){try{return new Intl.DateTimeFormat(void 0,{timeZone:a,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(s).replace(",","")}catch{return s.toISOString()}}i(Es,"formatFireTime");var ge="paperclip.routineLastSection";function Os(s){return s.filter(a=>!a.archivedAt).map(a=>({id:a.id,label:a.name,searchText:a.description??""}))}i(Os,"buildRoutineProjectOptions");var Ds={overview:"Overview",triggers:"Triggers",variables:"Variables",secrets:"Secrets",delivery:"Delivery",runs:"Runs",activity:"Activity",history:"History"};function ee(s){return s!=null&&es.includes(s)}i(ee,"isRoutineSection");function _s(s){try{const a=localStorage.getItem(ge);if(!a)return null;const n=JSON.parse(a)[s];return ee(n)?n:null}catch{return null}}i(_s,"readLastSection");function le(s,a){try{const n=localStorage.getItem(ge),c=n?JSON.parse(n):{};c[s]=a,localStorage.setItem(ge,JSON.stringify(c))}catch{}}i(le,"writeLastSection");var Fe={triggers:"triggers",runs:"runs",activity:"activity",secrets:"secrets",history:"history"};function Ke(s){s&&(s.style.height="auto",s.style.height=`${s.scrollHeight}px`)}i(Ke,"autoResizeTextarea");function Ms(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return"UTC"}}i(Ms,"getLocalTimezone");function qs(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(qs,"buildRoutineMutationPayload");function li(){const{routineId:s,section:a}=ht(),{selectedCompanyId:n}=mt(),{setBreadcrumbs:c}=Et(),r=lt(),m=xt(),{pushToast:l}=ds(),k=(0,u.useRef)(null),I=(0,u.useRef)(null),M=(0,u.useRef)(null),C=(0,u.useRef)(null),x=(0,u.useRef)(null),[S,D]=(0,u.useState)(null),[q,A]=(0,u.useState)(!1),[g,b]=(0,u.useState)(!1),[j,se]=(0,u.useState)(We),[f,P]=(0,u.useState)({title:"",description:"",projectId:"",assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",activityGatePolicy:"always",activityGateScope:"company",variables:[],env:null}),w=ee(a)?a:"overview",_=(0,u.useCallback)((t,h)=>{s&&(le(s,t),m(`/routines/${s}/${t}`,{replace:h?.replace??!0}))},[m,s]),{data:o,isLoading:Q,error:W}=L({queryKey:p.routines.detail(s),queryFn:i(()=>T.get(s),"queryFn"),enabled:!!s}),R=o?.activeIssue?.id,{data:B}=L({queryKey:p.issues.liveRuns(R),queryFn:i(()=>Ft.liveRunsForIssue(R),"queryFn"),enabled:!!R,refetchInterval:3e3}),d=(B??[]).length>0,{data:y}=L({queryKey:p.routines.runs(s),queryFn:i(()=>T.listRuns(s),"queryFn"),enabled:!!s,refetchInterval:d?3e3:!1}),V=(0,u.useMemo)(()=>({triggerIds:o?.triggers.map(t=>t.id)??[],runIds:y?.map(t=>t.id)??[]}),[o?.triggers,y]),{data:Ge}=L({queryKey:[...p.routines.activity(n,s),V.triggerIds.join(","),V.runIds.join(",")],queryFn:i(()=>T.activity(n,s,V),"queryFn"),enabled:!!n&&!!s&&!!o}),{data:F}=L({queryKey:p.agents.list(n),queryFn:i(()=>Rt.list(n),"queryFn"),enabled:!!n}),{data:K}=L({queryKey:p.projects.list(n,{includeArchived:!0}),queryFn:i(()=>Tt.list(n,{includeArchived:!0}),"queryFn"),enabled:!!n}),{data:fe}=L({queryKey:p.access.companyUserDirectory(n),queryFn:i(()=>Lt.listUserDirectory(n),"queryFn"),enabled:!!n}),{data:Ve=[]}=L({queryKey:n?p.secrets.list(n):["secrets","none"],queryFn:i(()=>qe.list(n),"queryFn"),enabled:!!n}),ze=U({mutationFn:i(t=>{if(!n)throw new Error("Select a company to create secrets");return qe.create(n,t)},"mutationFn"),onSuccess:i(()=>{n&&r.invalidateQueries({queryKey:p.secrets.list(n)})},"onSuccess")}),v=(0,u.useMemo)(()=>o?{title:o.title,description:o.description??"",projectId:o.projectId??"",assigneeAgentId:o.assigneeAgentId??"",priority:o.priority,concurrencyPolicy:o.concurrencyPolicy,catchUpPolicy:o.catchUpPolicy,activityGatePolicy:o.activityGatePolicy,activityGateScope:o.activityGateScope,variables:o.variables,env:o.env??null}:null,[o]),H=(0,u.useMemo)(()=>{if(!v)return[];const t=[];return f.title!==v.title&&t.push({key:"title",label:"the title"}),f.description!==v.description&&t.push({key:"description",label:"the description"}),f.projectId!==v.projectId&&t.push({key:"projectId",label:"the project"}),f.assigneeAgentId!==v.assigneeAgentId&&t.push({key:"assigneeAgentId",label:"the default agent"}),f.priority!==v.priority&&t.push({key:"priority",label:"the priority"}),f.concurrencyPolicy!==v.concurrencyPolicy&&t.push({key:"concurrencyPolicy",label:"the concurrency policy"}),f.catchUpPolicy!==v.catchUpPolicy&&t.push({key:"catchUpPolicy",label:"the catch-up policy"}),f.activityGatePolicy!==v.activityGatePolicy&&t.push({key:"activityGatePolicy",label:"the advanced run policy"}),f.activityGateScope!==v.activityGateScope&&t.push({key:"activityGateScope",label:"the activity gate scope"}),JSON.stringify(f.variables)!==JSON.stringify(v.variables)&&t.push({key:"variables",label:"the variables"}),JSON.stringify(f.env??null)!==JSON.stringify(v.env??null)&&t.push({key:"env",label:"the secrets"}),t},[f,v]),ie=H.length>0,J=(0,u.useCallback)(t=>{const h=Me[t];return h?H.filter(N=>h.includes(N.key)):[]},[H]),ne=(0,u.useCallback)(t=>J(t).length>0,[J]),be=(0,u.useCallback)(t=>{if(!v)return;const h=Me[t];h&&P(N=>{const Re={...N};for(const Te of h)Re[Te]=v[Te];return Re})},[v]);(0,u.useEffect)(()=>{o&&(c([{label:"Routines",href:"/routines"},{label:o.title}]),v&&(k.current!==o.id||!ie)&&(P(v),k.current=o.id))},[o,v,ie,c]),(0,u.useEffect)(()=>{Ke(I.current)},[f.title,o?.id]),(0,u.useEffect)(()=>{s&&ee(a)&&le(s,a)},[s,a]);const Qe=(0,u.useCallback)(async(t,h)=>{try{await qt(h),l({title:`${t} copied`,tone:"success"})}catch(N){l({title:`Failed to copy ${t.toLowerCase()}`,body:N instanceof Error?N.message:"Clipboard access was denied.",tone:"error"})}},[l]),Y=U({mutationFn:i(()=>{const t=qs(f),h=o?.latestRevisionId??null;return T.update(s,{...t,...h?{baseRevisionId:h}:{}})},"mutationFn"),onSuccess:i(async()=>{A(!1),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)}),r.invalidateQueries({queryKey:p.routines.revisions(s)})])},"onSuccess"),onError:i(t=>{if(t instanceof dt&&t.status===409){A(!0),l({title:"Routine changed",body:"Someone else updated this routine. Reload to see the latest revision.",tone:"warn"});return}l({title:"Failed to save routine",body:t instanceof Error?t.message:"Paperclip could not save the routine.",tone:"error"})},"onError")}),Z=U({mutationFn:i(t=>T.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:"Routine run started",tone:"success"}),b(!1),_("runs"),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.runs(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Routine run failed",body:t instanceof Error?t.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),je=U({mutationFn:i(t=>T.update(s,{status:t}),"mutationFn"),onSuccess:i(async(t,h)=>{l({title:"Routine saved",body:h==="paused"?"Automation paused.":"Automation enabled.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to update routine",body:t instanceof Error?t.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Be=U({mutationFn:i(async()=>{const t=(o?.triggers??[]).filter(N=>N.kind===j.kind).length,h=t>0?`${j.kind}-${t+1}`:j.kind;return T.createTrigger(s,{kind:j.kind,label:h,...j.kind==="schedule"?{cronExpression:j.cronExpression.trim(),timezone:Ms()}:{},...j.kind==="webhook"?{signingMode:j.signingMode,replayWindowSec:Number(j.replayWindowSec||"300")}:{}})},"mutationFn"),onSuccess:i(async t=>{t.secretMaterial?D({title:"Webhook trigger created",entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}):l({title:"Trigger added",body:"The routine schedule was saved.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to add trigger",body:t instanceof Error?t.message:"Paperclip could not create the trigger.",tone:"error"})},"onError")}),He=U({mutationFn:i(({id:t,patch:h})=>T.updateTrigger(t,h),"mutationFn"),onSuccess:i(async()=>{l({title:"Trigger saved",body:"The routine cadence update was saved.",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to update trigger",body:t instanceof Error?t.message:"Paperclip could not update the trigger.",tone:"error"})},"onError")}),Je=U({mutationFn:i(t=>T.deleteTrigger(t),"mutationFn"),onSuccess:i(async()=>{l({title:"Trigger deleted",tone:"success"}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.list(n)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to delete trigger",body:t instanceof Error?t.message:"Paperclip could not delete the trigger.",tone:"error"})},"onError")}),Ye=U({mutationFn:i(t=>T.rotateTriggerSecret(t),"mutationFn"),onSuccess:i(async t=>{D({title:"Webhook secret rotated",entries:[{webhookUrl:t.secretMaterial.webhookUrl,webhookSecret:t.secretMaterial.webhookSecret}]}),await Promise.all([r.invalidateQueries({queryKey:p.routines.detail(s)}),r.invalidateQueries({queryKey:p.routines.activity(n,s)})])},"onSuccess"),onError:i(t=>{l({title:"Failed to rotate webhook secret",body:t instanceof Error?t.message:"Paperclip could not rotate the webhook secret.",tone:"error"})},"onError")}),we=(0,u.useMemo)(()=>new Map((F??[]).map(t=>[t.id,t])),[F]),Ne=(0,u.useMemo)(()=>new Map((K??[]).map(t=>[t.id,t])),[K]),ae=(0,u.useMemo)(()=>ft(),[o?.id]),Ze=(0,u.useMemo)(()=>wt(),[o?.id]),Xe=(0,u.useMemo)(()=>vt((F??[]).filter(t=>t.status!=="terminated"),ae).map(t=>({id:t.id,label:t.name,searchText:`${t.name} ${t.role} ${t.title??""}`})),[F,ae]),et=(0,u.useMemo)(()=>Os(K??[]),[K]),tt=(0,u.useMemo)(()=>Kt({agents:F,projects:(K??[]).filter(t=>!t.archivedAt),members:fe?.users}),[F,fe?.users,K]),st=(0,u.useCallback)(t=>{P(h=>{const N=typeof t=="function"?t(h):t;return N.assigneeAgentId&&N.assigneeAgentId!==h.assigneeAgentId&&yt(N.assigneeAgentId),N.projectId&&N.projectId!==h.projectId&&Nt(N.projectId),N})},[]),it=f.assigneeAgentId?we.get(f.assigneeAgentId)??null:null,nt=f.projectId?Ne.get(f.projectId)??null:null,ke=(0,u.useCallback)(()=>{A(!1),v&&P(v),r.invalidateQueries({queryKey:p.routines.detail(s)})},[r,v,s]),at=(0,u.useCallback)(t=>{t.secretMaterials.length>0&&(_("triggers"),D({title:t.secretMaterials.length===1?"Webhook trigger restored":`${t.secretMaterials.length} webhook triggers restored`,entries:t.secretMaterials.map(h=>({webhookUrl:h.webhookUrl,webhookSecret:h.webhookSecret}))}))},[_]),rt=(0,u.useCallback)(t=>{A(!1),r.setQueryData(p.routines.detail(s),h=>h&&{...h,...t.routine,latestRevisionId:t.revision.id,latestRevisionNumber:t.revision.revisionNumber}),P({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}),k.current=t.routine.id},[r,s]);if(!n)return(0,e.jsx)(te,{icon:jt,message:"Select a company to view routines."});const re=new URLSearchParams(window.location.search).get("tab");if(s&&re&&Fe[re])return(0,e.jsx)(oe,{to:`/routines/${s}/${Fe[re]}`,replace:!0});if(s&&!a){const t=_s(s)??"overview";return(0,e.jsx)(oe,{to:`/routines/${s}/${t}`,replace:!0})}if(s&&a&&!ee(a))return(0,e.jsx)(oe,{to:`/routines/${s}/overview`,replace:!0});if(Q)return(0,e.jsx)($t,{variant:"issues-list"});if(W||!o||!v)return(0,e.jsx)(te,{icon:Ot,message:W instanceof Error?W.message:"We couldn't load this routine."});const $=o.status==="active",Se=je.isPending||o.status==="archived",Ie=o.status==="archived"?"Archived":o.assigneeAgentId?$?"Active":"Paused":"Draft",Ce=o.status==="archived"?"text-muted-foreground":$?"text-emerald-400":"text-muted-foreground",Ae={routine:o,routineId:s,companyId:o.companyId,editDraft:f,setEditDraft:st,routineDefaults:v,dirtyFields:H,isEditDirty:ie,sectionDirtyFields:J,isSectionDirty:ne,discardSection:be,saveRoutine:Y,saveConflict:q,reloadLatest:ke,automationEnabled:$,automationLabel:Ie,automationLabelClassName:Ce,automationToggleDisabled:Se,onToggleAutomation:i(()=>{if(!$&&!o.assigneeAgentId){l({title:"Default agent required",body:"Set a default agent before enabling routine automation.",tone:"warn"});return}je.mutate($?"paused":"active")},"onToggleAutomation"),onOpenRunDialog:i(()=>b(!0),"onOpenRunDialog"),runRoutinePending:Z.isPending,newTrigger:j,setNewTrigger:se,createTrigger:Be,updateTrigger:He,deleteTrigger:Je,rotateTrigger:Ye,secretMessage:S,setSecretMessage:D,copySecretValue:Qe,availableSecrets:Ve,createSecret:ze,agents:F??[],projects:K??[],agentById:we,projectById:Ne,assigneeOptions:Xe,projectOptions:et,recentAssigneeIds:ae,recentProjectIds:Ze,mentionOptions:tt,currentAssignee:it,currentProject:nt,routineRuns:y,activity:Ge,hasLiveRun:d,activeIssueId:R,titleInputRef:I,descriptionEditorRef:M,assigneeSelectorRef:C,projectSelectorRef:x,onHistoryRestoreSecretMaterials:at,onHistoryRestored:rt,navigateToSection:_},Pe=Qt.includes(w);return(0,e.jsxs)(ns.Provider,{value:Ae,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:"Skip to section"}),(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:I,"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:"Routine title",rows:1,value:f.title,onChange:i(t=>{P(h=>({...h,title:t.target.value})),Ke(t.target)},"onChange"),onKeyDown:i(t=>{t.key==="Enter"&&!t.metaKey&&!t.ctrlKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),w==="overview"?M.current?.focus():_("overview"))},"onKeyDown")}),o.managedByPlugin?(0,e.jsxs)(xe,{variant:"outline",className:"hidden shrink-0 gap-1.5 text-xs text-muted-foreground sm:inline-flex",children:[(0,e.jsx)(Pt,{className:"h-3 w-3"}),o.managedByPlugin.pluginDisplayName,(0,e.jsx)("span",{className:"font-mono text-(length:--text-nano)",children:o.managedByPlugin.resourceKey})]}):null]}),(0,e.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-3",children:[(0,e.jsx)(Vt,{onClick:i(()=>b(!0),"onClick"),disabled:Z.isPending}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(At,{size:"default",checked:$,onCheckedChange:Ae.onToggleAutomation,disabled:Se,"aria-label":$?"Pause automatic triggers":"Enable automatic triggers"}),(0,e.jsx)("span",{className:`text-sm font-medium ${Ce}`,children:Ie})]})]})]}),(0,e.jsx)(Gt,{activeSection:w,onNavigate:_,isSectionDirty:ne}),(0,e.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,e.jsx)(is,{activeSection:w,hrefFor:i(t=>`/routines/${s}/${t}`,"hrefFor"),isSectionDirty:ne,hasLiveRun:d,onNavigate:i(t=>le(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:Pe?"mx-auto w-full max-w-3xl":"w-full",children:[(0,e.jsx)("h2",{id:"routine-section-title",className:"mb-4 text-lg font-semibold",children:Ds[w]}),w==="overview"&&(0,e.jsx)(Ss,{}),w==="triggers"&&(0,e.jsx)(Is,{}),w==="variables"&&(0,e.jsx)(Cs,{}),w==="secrets"&&(0,e.jsx)(As,{}),w==="delivery"&&(0,e.jsx)(Ps,{}),w==="runs"&&(0,e.jsx)(Yt,{}),w==="activity"&&(0,e.jsx)(ls,{}),w==="history"&&(0,e.jsx)(Jt,{}),Pe?(0,e.jsx)(us,{dirtyFields:J(w),isSaving:Y.isPending,saveConflict:q,onSave:i(()=>{!Y.isPending&&f.title.trim()&&Y.mutate()},"onSave"),onDiscard:i(()=>be(w),"onDiscard"),onReload:ke}):null]})})]})]}),(0,e.jsx)(bt,{open:g,onOpenChange:b,companyId:o.companyId,routineName:o.title,agents:F??[],projects:K??[],defaultProjectId:o.projectId,defaultAssigneeAgentId:o.assigneeAgentId,variables:o.variables??[],isPending:Z.isPending,onSubmit:i(t=>Z.mutate(t),"onSubmit")})]})}i(li,"RoutineDetail");export{li as RoutineDetail};
@@ -1,4 +1,4 @@
1
- var nc=Object.defineProperty;var a=(e,t)=>nc(e,"name",{value:t,configurable:!0});import{i as na}from"./rolldown-runtime-ZpX3ckPj.js";import{$r as rc,Ci as sc,Di as ac,Ei as ra,Gr as oc,I as ic,Jr as Me,Lr as ze,M as Fo,O as Ko,Oi as lc,Qr as _a,S as F,Si as cc,U as sa,X as Ie,Xr as uc,Z as zo,Zr as dc,_i as Ea,a as fc,ai as qo,bi as pc,c as mc,di as hc,ei as gc,fi as aa,gi as Ma,hi as Vo,i as xc,ii as bc,ki as vc,l as oa,li as Aa,m as yc,mi as Ra,ni as wc,o as kc,oi as jc,pi as Ic,r as Cc,ri as Sc,s as Nc,t as at,ti as _c,ui as Qe,vi as Et,wi as Ec,xi as Ns,xr as fs,yi as Da}from"./agent-avatar-url-270oGkoO.js";import{Mt as Mc,P as Go,R as Oa,St as pr,X as Ho,ft as Xt,gt as Dn,o as Qo,t as Jt,xt as Xr}from"./router-BC2Duaf5.js";import{Z as tr,s as Ta}from"./mention-chips-B_zVTnHY.js";import{d as dn,p as Ac}from"./MarkdownEditor-seU_oAfy.js";import{b as Rc,v as Dc,y as Oc}from"./sheet-CFbmpBhA.js";import{r as Jr,t as Pa}from"./AgentAvatar-lnkDMHMh.js";import{A as Tc,C as $a,O as Pc,_ as Ba,a as $c,b as Bc,c as Lc,f as _s,g as Wc,h as Es,n as Uc,o as Fc,p as Ms,r as Kc,s as zc,t as _t,u as qc,v as Vc,y as Gc}from"./checkbox-SNvdBfci.js";import{a as Hc,n as Qc,o as Yc,r as Xc,t as As}from"./label-TkPoSJhK.js";import{d as wt,g as kt,i as mr,p as jt}from"./agents-BlxRXAz3.js";import{S as Jc,_ as La,c as Yo,h as Wa,i as Zc,l as eu,n as tu,r as nu,s as ru,t as ht}from"./StatusIcon-BtBa0xK_.js";import{o as Zr,t as Xo}from"./EmptyState-CqqJOoXs.js";import{t as Ua}from"./bot-CGOpwPIZ.js";import{t as en}from"./check-5Tuqm2aI.js";import{t as Mn}from"./chevron-right-Dv6dHZgu.js";import{c as Fa,i as Xn,n as Ka,s as za,t as qa}from"./select-DsMS_Sad.js";import{C as Jo,b as Or,d as su,k as nr,p as au,t as ke}from"./button-DLWREze0.js";import{i as ou,r as iu,t as lu}from"./clipboard-BPoFQAy2.js";import{i as Zo,o as ei}from"./heartbeats-DWUL5tSL.js";import{n as cu,t as uu}from"./useHiddenSettings-COOnS4sa.js";import{t as du}from"./octagon-alert-HfSAYnSC.js";import{t as ti}from"./rotate-ccw-C9ZF1aqD.js";import{t as ia}from"./triangle-alert-CrLKyTUa.js";import{t as Ye}from"./badge-D0Ti-OuU.js";import{n as Pn,t as fu}from"./environments-BNSxsEsE.js";import{t as fn}from"./input-BWYuMr4z.js";import{n as ni,o as ri,r as si}from"./company-members-BKdmkDTe.js";import{t as pn}from"./AgentIdentity-Cpb2VddX.js";import{t as pu}from"./card-Qk8smcrQ.js";import{t as ai}from"./PageSkeleton-C9WV_Qyq.js";var mu=class extends aa{static{a(this,"MutationCache")}#e;#t;#r;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}build(e,t,n){const s=new bc({client:e,mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:n});return this.add(s),s}add(e){this.#e.add(e);const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t);if(n)if(n.length>1){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t)?.find(s=>s.state.status==="pending");return!n||n===e}else return!0}runNext(e){const t=Tr(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Qe.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ma(t,n))}findAll(e={}){return this.getAll().filter(t=>Ma(e,t))}notify(e){Qe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){const e=this.getAll().filter(t=>t.state.isPaused);return Qe.batch(()=>Promise.all(e.map(t=>t.continue().catch(Et))))}};function Tr(e){return e.options.scope?.id}a(Tr,"scopeFor");function Va(e,t){const n=new Set(t);return e.filter(s=>!n.has(s))}a(Va,"difference");var hu=class extends aa{static{a(this,"QueriesObserver")}#e;#t;#r;#a;#n;#s;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#e=e,this.#a=n,this.#r=[],this.#n=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#n.forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#n.forEach(e=>{e.destroy()})}setQueries(e,t){this.#r=e,this.#a=t,Qe.batch(()=>{const n=this.#n,s=this.#f(this.#r);s.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const o=s.map(f=>f.observer),i=o.map(f=>f.getCurrentResult()),l=n.length!==o.length,c=o.some((f,h)=>f!==n[h]),d=l||c,p=d?!0:i.some((f,h)=>{const b=this.#t[h];return!b||!cc(f,b)});!d&&!p||(d&&(this.#c=s,this.#n=o),this.#t=i,this.hasListeners()&&(d&&(Va(n,o).forEach(f=>{f.destroy()}),Va(o,n).forEach(f=>{f.subscribe(h=>{this.#p(f,h)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#n.map(e=>e.getCurrentQuery())}getObservers(){return this.#n}getOptimisticResult(e,t){const n=this.#f(e),s=n.map(i=>i.observer.getOptimisticResult(i.defaultedQueryOptions)),o=n.map(i=>i.defaultedQueryOptions.queryHash);return[s,i=>this.#d(i??s,t,o),()=>this.#u(s,n)]}#u(e,t){const n=new Set;return t.map((s,o)=>{const i=e[o];return s.defaultedQueryOptions.notifyOnChangeProps?i:s.observer.trackResult(i,l=>{n.has(l)||(n.add(l),t.forEach(c=>{c.observer.trackProp(l)}))})})}#d(e,t,n){if(t){const s=this.#l,o=n!==void 0&&s!==void 0&&(s.length!==n.length||n.some((i,l)=>i!==s[l]));return(this.#t!==this.#i||o||t!==this.#o)&&(this.#o=t,this.#i=this.#t,n!==void 0&&(this.#l=n),this.#s=pc(this.#s,t(e))),this.#s}return e}#h(){return!this.#a?.combine||this.#n.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#f(e){const t=new Map;this.#n.forEach(s=>{const o=s.options.queryHash;if(!o)return;const i=t.get(o);i?i.push(s):t.set(o,[s])});const n=[];return e.forEach(s=>{const o=this.#e.defaultQueryOptions(s),i=t.get(o.queryHash)?.shift()??new qo(this.#e,o);n.push({defaultedQueryOptions:o,observer:i})}),n}#p(e,t){const n=this.#n.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#m())}#m(){if(this.hasListeners()){const e=this.#h(),t=this.#s,n=e?t:this.#d(this.#u(this.#t,this.#c),this.#a?.combine);(e||t!==n)&&Qe.batch(()=>{this.listeners.forEach(s=>{s(this.#t)})})}}},gu=class extends aa{static{a(this,"QueryCache")}#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){const s=t.queryKey,o=t.queryHash??Vo(s,t);let i=this.get(o);return i||(i=new jc({client:e,queryKey:s,queryHash:o,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(s)}),this.add(i)),i}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){Qe.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ea(t,n))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>Ea(e,n)):t}notify(e){Qe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Qe.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Qe.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},xu=class{static{a(this,"QueryClient")}#e;#t;#r;#a;#n;#s;#o;#i;constructor(e={}){this.#e=e.queryCache||new gu,this.#t=e.mutationCache||new mu,this.#r=e.defaultOptions||{},this.#a=new Map,this.#n=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#o=hc.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#i=Aa.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===0&&(this.#o?.(),this.#o=void 0,this.#i?.(),this.#i=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=this.#e.build(this,t),s=n.state.data;return s===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Ns(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(s))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:n})=>[t,n.data])}setQueryData(e,t,n){const s=this.defaultQueryOptions({queryKey:e}),o=this.#e.get(s.queryHash)?.state.data,i=Ic(t,o);if(i!==void 0)return this.#e.build(this,s).setData(i,{...n,manual:!0})}setQueriesData(e,t,n){return Qe.batch(()=>this.#e.findAll(e).map(({queryKey:s})=>[s,this.setQueryData(s,t,n)]))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){const t=this.#e;Qe.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=this.#e;return Qe.batch(()=>{const s=n.findAll(e),o=new Set(s);return s.forEach(i=>{i.reset()}),this.refetchQueries({type:"active",predicate:a(i=>o.has(i),"predicate")},t)})}cancelQueries(e,t={}){const n={revert:!0,...t},s=Qe.batch(()=>this.#e.findAll(e).map(o=>o.cancel(n)));return Promise.all(s).then(Et).catch(Et)}invalidateQueries(e,t={}){return Qe.batch(()=>(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none"?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},s=Qe.batch(()=>this.#e.findAll(e).filter(o=>!o.isDisabled()&&!o.isStatic()).map(o=>{let i=o.fetch(void 0,n);return n.throwOnError||(i=i.catch(Et)),o.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(s).then(Et)}async query(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t),s=n.isStaleByTime(Ns(t.staleTime,n))?await n.fetch(t):n.state.data,o=t.select;return o?o(s):s}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t);return n.isStaleByTime(Ns(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Et).catch(Et)}infiniteQuery(e){return e._type="infinite",this.query(e)}fetchInfiniteQuery(e){return e._type="infinite",this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Et).catch(Et)}ensureInfiniteQueryData(e){return e._type="infinite",this.ensureQueryData(e)}resumePausedMutations(){return Aa.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#a.set(Ra(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#a.values()],n={};return t.forEach(s=>{Da(e,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(e,t){this.#n.set(Ra(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#n.values()],n={};return t.forEach(s=>{Da(e,s.mutationKey)&&Object.assign(n,s.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Vo(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===sc&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},u=na(vc(),1);function oi({queries:e,...t},n){const s=ra(n),o=Sc(),i=wc(),l=t.subscribed!==!1,c=u.useMemo(()=>e.map(I=>{const M=s.defaultQueryOptions(I);return M._optimisticResults=o?"isRestoring":l?"optimistic":void 0,M}),[e,s,o,l]);c.forEach(I=>{uc(I);const M=s.getQueryCache().get(I.queryHash);rc(I,i,M)}),_c(i);const[d]=u.useState(()=>new hu(s,c,t)),[p,f,h]=d.getOptimisticResult(c,t.combine),b=!o&&l;u.useSyncExternalStore(u.useCallback(I=>b?d.subscribe(Qe.batchCalls(I)):Et,[d,b]),()=>d.getCurrentResult(),()=>d.getCurrentResult()),u.useEffect(()=>{d.setQueries(c,t)},[c,t,d]);const k=p.some((I,M)=>_a(c[M],I))?p.flatMap((I,M)=>{const R=c[M];if(R&&_a(R,I)){const W=new qo(s,R);return dc(R,W,i)}return[]}):[];if(k.length>0)throw Promise.all(k);const S=p.find((I,M)=>{const R=c[M];return R&&gc({result:I,errorResetBoundary:i,throwOnError:R.throwOnError,query:s.getQueryCache().get(R.queryHash),suspense:R.suspense})});if(S)throw S.error;return f(h())}a(oi,"useQueries");function la(e){return e.createdByUserId?{kind:"user",id:e.createdByUserId}:e.createdByAgentId?e.responsibleUserId?{kind:"user",id:e.responsibleUserId,viaAgentId:e.createdByAgentId}:{kind:"agent",id:e.createdByAgentId}:e.responsibleUserId?{kind:"user",id:e.responsibleUserId}:null}a(la,"deriveOriginatingActor");var bu=["uncertain_provider_action","uncertain_external_action","uncertain_control_plane_action","completed_action_context_missing","continuation_evidence_incomplete","execution_finalization_deadline_exceeded","execution_recovery_budget_exhausted","provider_effect_inventory_unavailable","provider_failure_meaning_unverified","provider_ownership_unverified","native_provider_terminal_failed","native_event_replay_conflict","native_session_cleanup_quarantined","native_session_retry_exhausted","native_restart_recovery_blocked","native_continuation_requires_reconciliation","legacy_execution_requires_reconciliation"];function vu(e){return bu.some(t=>t===e)}a(vu,"requiresExecutionReconciliation");function yu(e,t){return t?e.responsibleUserId?e.responsibleUserId===t:t==="local-board":!1}a(yu,"isHeartbeatRunVisibleInMine");var r=na(ac(),1),wu=Object.defineProperty,hr=a((e,t)=>wu(e,"name",{value:t,configurable:!0}),"__name"),ca="Collapsible",[ku,Cg]=mc(ca),[ju,ua]=ku(ca),Iu=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,open:o,defaultOpen:i,disabled:l,onOpenChange:c,...d}=t,[p,f]=fc({prop:o,defaultProp:i??!1,onChange:c,caller:ca});return(0,r.jsx)(ju,{scope:s,disabled:l,contentId:Cc(),open:p,onOpenToggle:u.useCallback(()=>f(h=>!h),[f]),children:(0,r.jsx)(oa.div,{"data-state":ps(p),"data-disabled":l?"":void 0,...d,ref:n})})},"Collapsible2"),"Collapsible")),Cu="CollapsibleTrigger",Su=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,...o}=t,i=ua(Cu,s);return(0,r.jsx)(oa.button,{type:"button","aria-controls":i.open?i.contentId:void 0,"aria-expanded":i.open||!1,"data-state":ps(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled,...o,ref:n,onClick:Nc(t.onClick,i.onOpenToggle)})},"CollapsibleTrigger2"),"CollapsibleTrigger")),ii="CollapsibleContent",Nu=u.forwardRef(hr(a(function(t,n){const{forceMount:s,...o}=t,i=ua(ii,t.__scopeCollapsible);return(0,r.jsx)(xc,{present:s||i.open,children:a(({present:l})=>(0,r.jsx)(_u,{...o,ref:n,present:l}),"children")})},"CollapsibleContent2"),"CollapsibleContent")),_u=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,present:o,children:i,...l}=t,c=ua(ii,s),[d,p]=u.useState(o),f=u.useRef(null),h=yc(n,f),b=u.useRef(0),k=b.current,S=u.useRef(0),I=S.current,M=c.open||d,R=u.useRef(M),W=u.useRef(void 0);return u.useEffect(()=>{const O=requestAnimationFrame(()=>R.current=!1);return()=>cancelAnimationFrame(O)},[]),kc(()=>{const O=f.current;if(O){W.current=W.current||{transitionDuration:O.style.transitionDuration,animationName:O.style.animationName},O.style.transitionDuration="0s",O.style.animationName="none";const B=O.getBoundingClientRect();b.current=B.height,S.current=B.width,R.current||(O.style.transitionDuration=W.current.transitionDuration,O.style.animationName=W.current.animationName),p(o)}},[c.open,o]),(0,r.jsx)(oa.div,{"data-state":ps(c.open),"data-disabled":c.disabled?"":void 0,id:c.contentId,hidden:!M,...l,ref:h,style:{"--radix-collapsible-content-height":k?`${k}px`:void 0,"--radix-collapsible-content-width":I?`${I}px`:void 0,...t.style},children:M&&i})},"CollapsibleContentImpl2"),"CollapsibleContentImpl"));function ps(e){return e?"open":"closed"}a(ps,"getState");hr(ps,"getState");var Eu=Iu,li={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};li.node;var Mu=at(li),ci={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};ci.node;var ui=at(ci),di={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};di.node;var Au=at(di),fi={name:"chevrons-down-up",size:24,node:[["path",{d:"m7 20 5-5 5 5",key:"13a0gw"}],["path",{d:"m7 4 5 5 5-5",key:"1kwcof"}]]};fi.node;var pi=at(fi),mi={name:"circle-slash-2",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M22 2 2 22",key:"y4kqgn"}]],aliases:["circle-slashed"]};mi.node;var hi=at(mi),gi={name:"columns-3",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],aliases:["panels-left-right"]};gi.node;var Ru=at(gi),xi={name:"file-search",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"11.5",cy:"14.5",r:"2.5",key:"1bq0ko"}],["path",{d:"M13.3 16.3 15 18",key:"2quom7"}]]};xi.node;var Du=at(xi),bi={name:"funnel",size:24,node:[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],aliases:["filter"]};bi.node;var Ou=at(bi),vi={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};vi.node;var Tu=at(vi),yi={name:"list-collapse",size:24,node:[["path",{d:"M10 5h11",key:"1hkqpe"}],["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 19h11",key:"14g2nv"}],["path",{d:"m3 10 3-3-3-3",key:"i7pm08"}],["path",{d:"m3 20 3-3-3-3",key:"20gx1n"}]]};yi.node;var wi=at(yi),ki={name:"list-tree",size:24,node:[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]};ki.node;var ji=at(ki),Ii={name:"panel-top-close",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"m9 16 3-3 3 3",key:"1idcnm"}]]};Ii.node;var Ci=at(Ii),Si={name:"repeat",size:24,node:[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]};Si.node;var Sg=at(Si),Ni={name:"square-kanban",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M8 7v7",key:"1x2jlm"}],["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M16 7v9",key:"1hp2iy"}]],aliases:["kanban-square"]};Ni.node;var _i=at(Ni);function Ei({...e}){return(0,r.jsx)(Eu,{"data-slot":"collapsible",...e})}a(Ei,"Collapsible");function Ng({...e}){return(0,r.jsx)(Su,{"data-slot":"collapsible-trigger",...e})}a(Ng,"CollapsibleTrigger");function Mi({...e}){return(0,r.jsx)(Nu,{"data-slot":"collapsible-content",...e})}a(Mi,"CollapsibleContent");var Jn=na(lc());function Pu(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,u.useMemo)(()=>s=>{t.forEach(o=>o(s))},t)}a(Pu,"useCombinedRefs");var ms=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function $n(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}a($n,"isWindow");function da(e){return"nodeType"in e}a(da,"isNode");function et(e){var t,n;return e?$n(e)?e:da(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}a(et,"getWindow");function fa(e){const{Document:t}=et(e);return e instanceof t}a(fa,"isDocument");function gr(e){return $n(e)?!1:e instanceof et(e).HTMLElement}a(gr,"isHTMLElement");function Ai(e){return e instanceof et(e).SVGElement}a(Ai,"isSVGElement");function Bn(e){return e?$n(e)?e.document:da(e)?fa(e)?e:gr(e)||Ai(e)?e.ownerDocument:document:document:document}a(Bn,"getOwnerDocument");var It=ms?u.useLayoutEffect:u.useEffect;function hs(e){const t=(0,u.useRef)(e);return It(()=>{t.current=e}),(0,u.useCallback)(function(){for(var n=arguments.length,s=new Array(n),o=0;o<n;o++)s[o]=arguments[o];return t.current==null?void 0:t.current(...s)},[])}a(hs,"useEvent");function $u(){const e=(0,u.useRef)(null);return[(0,u.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,u.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}a($u,"useInterval");function or(e,t){t===void 0&&(t=[e]);const n=(0,u.useRef)(e);return It(()=>{n.current!==e&&(n.current=e)},t),n}a(or,"useLatestValue");function xr(e,t){const n=(0,u.useRef)();return(0,u.useMemo)(()=>{const s=e(n.current);return n.current=s,s},[...t])}a(xr,"useLazyMemo");function es(e){const t=hs(e),n=(0,u.useRef)(null);return[n,(0,u.useCallback)(s=>{s!==n.current&&t?.(s,n.current),n.current=s},[])]}a(es,"useNodeRef");function ts(e){const t=(0,u.useRef)();return(0,u.useEffect)(()=>{t.current=e},[e]),t.current}a(ts,"usePrevious");var Rs={};function br(e,t){return(0,u.useMemo)(()=>{if(t)return t;const n=Rs[e]==null?0:Rs[e]+1;return Rs[e]=n,e+"-"+n},[e,t])}a(br,"useUniqueId");function Ri(e){return function(t){for(var n=arguments.length,s=new Array(n>1?n-1:0),o=1;o<n;o++)s[o-1]=arguments[o];return s.reduce((i,l)=>{const c=Object.entries(l);for(const[d,p]of c){const f=i[d];f!=null&&(i[d]=f+e*p)}return i},{...t})}}a(Ri,"createAdjustmentFn");var An=Ri(1),ir=Ri(-1);function Bu(e){return"clientX"in e&&"clientY"in e}a(Bu,"hasViewportRelativeCoordinates");function gs(e){if(!e)return!1;const{KeyboardEvent:t}=et(e.target);return t&&e instanceof t}a(gs,"isKeyboardEvent");function Lu(e){if(!e)return!1;const{TouchEvent:t}=et(e.target);return t&&e instanceof t}a(Lu,"isTouchEvent");function ns(e){if(Lu(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Bu(e)?{x:e.clientX,y:e.clientY}:null}a(ns,"getEventCoordinates");var tn=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[tn.Translate.toString(e),tn.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:s}=e;return t+" "+n+"ms "+s}}}),Ga="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Wu(e){return e.matches(Ga)?e:e.querySelector(Ga)}a(Wu,"findFirstFocusableNode");var Uu={display:"none"};function Fu(e){let{id:t,value:n}=e;return u.createElement("div",{id:t,style:Uu},n)}a(Fu,"HiddenText");function Ku(e){let{id:t,announcement:n,ariaLiveType:s="assertive"}=e;return u.createElement("div",{id:t,style:{position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"},role:"status","aria-live":s,"aria-atomic":!0},n)}a(Ku,"LiveRegion");function zu(){const[e,t]=(0,u.useState)("");return{announce:(0,u.useCallback)(n=>{n!=null&&t(n)},[]),announcement:e}}a(zu,"useAnnouncement");var Di=(0,u.createContext)(null);function qu(e){const t=(0,u.useContext)(Di);(0,u.useEffect)(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}a(qu,"useDndMonitor");function Vu(){const[e]=(0,u.useState)(()=>new Set),t=(0,u.useCallback)(n=>(e.add(n),()=>e.delete(n)),[e]);return[(0,u.useCallback)(n=>{let{type:s,event:o}=n;e.forEach(i=>{var l;return(l=i[s])==null?void 0:l.call(i,o)})},[e]),t]}a(Vu,"useDndMonitorProvider");var Gu={draggable:`
1
+ var nc=Object.defineProperty;var a=(e,t)=>nc(e,"name",{value:t,configurable:!0});import{i as na}from"./rolldown-runtime-ZpX3ckPj.js";import{$r as rc,Ci as sc,Di as ac,Ei as ra,Gr as oc,I as ic,Jr as Me,Lr as ze,M as Fo,O as Ko,Oi as lc,Qr as _a,S as F,Si as cc,U as sa,X as Ie,Xr as uc,Z as zo,Zr as dc,_i as Ea,a as fc,ai as qo,bi as pc,c as mc,di as hc,ei as gc,fi as aa,gi as Ma,hi as Vo,i as xc,ii as bc,ki as vc,l as oa,li as Aa,m as yc,mi as Ra,ni as wc,o as kc,oi as jc,pi as Ic,r as Cc,ri as Sc,s as Nc,t as at,ti as _c,ui as Qe,vi as Et,wi as Ec,xi as Ns,xr as fs,yi as Da}from"./agent-avatar-url-CiVC72zn.js";import{Mt as Mc,P as Go,R as Oa,St as pr,X as Ho,ft as Xt,gt as Dn,o as Qo,t as Jt,xt as Xr}from"./router-CGbOrhXy.js";import{Z as tr,s as Ta}from"./mention-chips-3yfCFzXQ.js";import{d as dn,p as Ac}from"./MarkdownEditor-D0uqxShB.js";import{b as Rc,v as Dc,y as Oc}from"./sheet-CqcQLexE.js";import{r as Jr,t as Pa}from"./AgentAvatar-CrnNGelJ.js";import{A as Tc,C as $a,O as Pc,_ as Ba,a as $c,b as Bc,c as Lc,f as _s,g as Wc,h as Es,n as Uc,o as Fc,p as Ms,r as Kc,s as zc,t as _t,u as qc,v as Vc,y as Gc}from"./checkbox-SdYP--OH.js";import{a as Hc,n as Qc,o as Yc,r as Xc,t as As}from"./label-CA4aszl3.js";import{d as wt,g as kt,i as mr,p as jt}from"./agents-BGdf-J_C.js";import{S as Jc,_ as La,c as Yo,h as Wa,i as Zc,l as eu,n as tu,r as nu,s as ru,t as ht}from"./StatusIcon-D__DIZlm.js";import{o as Zr,t as Xo}from"./EmptyState-ClZXiygF.js";import{t as Ua}from"./bot-DyYJ3E4C.js";import{t as en}from"./check-B3EECTO-.js";import{t as Mn}from"./chevron-right-BhU5OvzN.js";import{c as Fa,i as Xn,n as Ka,s as za,t as qa}from"./select-Db0ppga4.js";import{C as Jo,b as Or,d as su,k as nr,p as au,t as ke}from"./button-BmDU7YzH.js";import{i as ou,r as iu,t as lu}from"./clipboard-CATj6OsB.js";import{i as Zo,o as ei}from"./heartbeats-By7EcEMQ.js";import{n as cu,t as uu}from"./useHiddenSettings-DwCbKddT.js";import{t as du}from"./octagon-alert-CAPjvRAd.js";import{t as ti}from"./rotate-ccw-qAsLpcfW.js";import{t as ia}from"./triangle-alert-BSwSeDrD.js";import{t as Ye}from"./badge-Dwnb7bwc.js";import{n as Pn,t as fu}from"./environments-12KK8Hvb.js";import{t as fn}from"./input-CfZ7FdDr.js";import{n as ni,o as ri,r as si}from"./company-members-c2ldQ5sU.js";import{t as pn}from"./AgentIdentity-Bl7KfJ-S.js";import{t as pu}from"./card-V5O2wbgV.js";import{t as ai}from"./PageSkeleton-DQuX4FJP.js";var mu=class extends aa{static{a(this,"MutationCache")}#e;#t;#r;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}build(e,t,n){const s=new bc({client:e,mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:n});return this.add(s),s}add(e){this.#e.add(e);const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t);if(n)if(n.length>1){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){const t=Tr(e);if(typeof t=="string"){const n=this.#t.get(t)?.find(s=>s.state.status==="pending");return!n||n===e}else return!0}runNext(e){const t=Tr(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Qe.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ma(t,n))}findAll(e={}){return this.getAll().filter(t=>Ma(e,t))}notify(e){Qe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){const e=this.getAll().filter(t=>t.state.isPaused);return Qe.batch(()=>Promise.all(e.map(t=>t.continue().catch(Et))))}};function Tr(e){return e.options.scope?.id}a(Tr,"scopeFor");function Va(e,t){const n=new Set(t);return e.filter(s=>!n.has(s))}a(Va,"difference");var hu=class extends aa{static{a(this,"QueriesObserver")}#e;#t;#r;#a;#n;#s;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#e=e,this.#a=n,this.#r=[],this.#n=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#n.forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#n.forEach(e=>{e.destroy()})}setQueries(e,t){this.#r=e,this.#a=t,Qe.batch(()=>{const n=this.#n,s=this.#f(this.#r);s.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const o=s.map(f=>f.observer),i=o.map(f=>f.getCurrentResult()),l=n.length!==o.length,c=o.some((f,h)=>f!==n[h]),d=l||c,p=d?!0:i.some((f,h)=>{const b=this.#t[h];return!b||!cc(f,b)});!d&&!p||(d&&(this.#c=s,this.#n=o),this.#t=i,this.hasListeners()&&(d&&(Va(n,o).forEach(f=>{f.destroy()}),Va(o,n).forEach(f=>{f.subscribe(h=>{this.#p(f,h)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#n.map(e=>e.getCurrentQuery())}getObservers(){return this.#n}getOptimisticResult(e,t){const n=this.#f(e),s=n.map(i=>i.observer.getOptimisticResult(i.defaultedQueryOptions)),o=n.map(i=>i.defaultedQueryOptions.queryHash);return[s,i=>this.#d(i??s,t,o),()=>this.#u(s,n)]}#u(e,t){const n=new Set;return t.map((s,o)=>{const i=e[o];return s.defaultedQueryOptions.notifyOnChangeProps?i:s.observer.trackResult(i,l=>{n.has(l)||(n.add(l),t.forEach(c=>{c.observer.trackProp(l)}))})})}#d(e,t,n){if(t){const s=this.#l,o=n!==void 0&&s!==void 0&&(s.length!==n.length||n.some((i,l)=>i!==s[l]));return(this.#t!==this.#i||o||t!==this.#o)&&(this.#o=t,this.#i=this.#t,n!==void 0&&(this.#l=n),this.#s=pc(this.#s,t(e))),this.#s}return e}#h(){return!this.#a?.combine||this.#n.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#f(e){const t=new Map;this.#n.forEach(s=>{const o=s.options.queryHash;if(!o)return;const i=t.get(o);i?i.push(s):t.set(o,[s])});const n=[];return e.forEach(s=>{const o=this.#e.defaultQueryOptions(s),i=t.get(o.queryHash)?.shift()??new qo(this.#e,o);n.push({defaultedQueryOptions:o,observer:i})}),n}#p(e,t){const n=this.#n.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#m())}#m(){if(this.hasListeners()){const e=this.#h(),t=this.#s,n=e?t:this.#d(this.#u(this.#t,this.#c),this.#a?.combine);(e||t!==n)&&Qe.batch(()=>{this.listeners.forEach(s=>{s(this.#t)})})}}},gu=class extends aa{static{a(this,"QueryCache")}#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){const s=t.queryKey,o=t.queryHash??Vo(s,t);let i=this.get(o);return i||(i=new jc({client:e,queryKey:s,queryHash:o,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(s)}),this.add(i)),i}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){Qe.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ea(t,n))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>Ea(e,n)):t}notify(e){Qe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Qe.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Qe.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},xu=class{static{a(this,"QueryClient")}#e;#t;#r;#a;#n;#s;#o;#i;constructor(e={}){this.#e=e.queryCache||new gu,this.#t=e.mutationCache||new mu,this.#r=e.defaultOptions||{},this.#a=new Map,this.#n=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#o=hc.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#i=Aa.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===0&&(this.#o?.(),this.#o=void 0,this.#i?.(),this.#i=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=this.#e.build(this,t),s=n.state.data;return s===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Ns(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(s))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:n})=>[t,n.data])}setQueryData(e,t,n){const s=this.defaultQueryOptions({queryKey:e}),o=this.#e.get(s.queryHash)?.state.data,i=Ic(t,o);if(i!==void 0)return this.#e.build(this,s).setData(i,{...n,manual:!0})}setQueriesData(e,t,n){return Qe.batch(()=>this.#e.findAll(e).map(({queryKey:s})=>[s,this.setQueryData(s,t,n)]))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){const t=this.#e;Qe.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=this.#e;return Qe.batch(()=>{const s=n.findAll(e),o=new Set(s);return s.forEach(i=>{i.reset()}),this.refetchQueries({type:"active",predicate:a(i=>o.has(i),"predicate")},t)})}cancelQueries(e,t={}){const n={revert:!0,...t},s=Qe.batch(()=>this.#e.findAll(e).map(o=>o.cancel(n)));return Promise.all(s).then(Et).catch(Et)}invalidateQueries(e,t={}){return Qe.batch(()=>(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none"?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},s=Qe.batch(()=>this.#e.findAll(e).filter(o=>!o.isDisabled()&&!o.isStatic()).map(o=>{let i=o.fetch(void 0,n);return n.throwOnError||(i=i.catch(Et)),o.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(s).then(Et)}async query(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t),s=n.isStaleByTime(Ns(t.staleTime,n))?await n.fetch(t):n.state.data,o=t.select;return o?o(s):s}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t);return n.isStaleByTime(Ns(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Et).catch(Et)}infiniteQuery(e){return e._type="infinite",this.query(e)}fetchInfiniteQuery(e){return e._type="infinite",this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Et).catch(Et)}ensureInfiniteQueryData(e){return e._type="infinite",this.ensureQueryData(e)}resumePausedMutations(){return Aa.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#a.set(Ra(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#a.values()],n={};return t.forEach(s=>{Da(e,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(e,t){this.#n.set(Ra(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#n.values()],n={};return t.forEach(s=>{Da(e,s.mutationKey)&&Object.assign(n,s.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Vo(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===sc&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},u=na(vc(),1);function oi({queries:e,...t},n){const s=ra(n),o=Sc(),i=wc(),l=t.subscribed!==!1,c=u.useMemo(()=>e.map(I=>{const M=s.defaultQueryOptions(I);return M._optimisticResults=o?"isRestoring":l?"optimistic":void 0,M}),[e,s,o,l]);c.forEach(I=>{uc(I);const M=s.getQueryCache().get(I.queryHash);rc(I,i,M)}),_c(i);const[d]=u.useState(()=>new hu(s,c,t)),[p,f,h]=d.getOptimisticResult(c,t.combine),b=!o&&l;u.useSyncExternalStore(u.useCallback(I=>b?d.subscribe(Qe.batchCalls(I)):Et,[d,b]),()=>d.getCurrentResult(),()=>d.getCurrentResult()),u.useEffect(()=>{d.setQueries(c,t)},[c,t,d]);const k=p.some((I,M)=>_a(c[M],I))?p.flatMap((I,M)=>{const R=c[M];if(R&&_a(R,I)){const W=new qo(s,R);return dc(R,W,i)}return[]}):[];if(k.length>0)throw Promise.all(k);const S=p.find((I,M)=>{const R=c[M];return R&&gc({result:I,errorResetBoundary:i,throwOnError:R.throwOnError,query:s.getQueryCache().get(R.queryHash),suspense:R.suspense})});if(S)throw S.error;return f(h())}a(oi,"useQueries");function la(e){return e.createdByUserId?{kind:"user",id:e.createdByUserId}:e.createdByAgentId?e.responsibleUserId?{kind:"user",id:e.responsibleUserId,viaAgentId:e.createdByAgentId}:{kind:"agent",id:e.createdByAgentId}:e.responsibleUserId?{kind:"user",id:e.responsibleUserId}:null}a(la,"deriveOriginatingActor");var bu=["uncertain_provider_action","uncertain_external_action","uncertain_control_plane_action","completed_action_context_missing","continuation_evidence_incomplete","execution_finalization_deadline_exceeded","execution_recovery_budget_exhausted","provider_effect_inventory_unavailable","provider_failure_meaning_unverified","provider_ownership_unverified","native_provider_terminal_failed","native_event_replay_conflict","native_session_cleanup_quarantined","native_session_retry_exhausted","native_restart_recovery_blocked","native_continuation_requires_reconciliation","legacy_execution_requires_reconciliation"];function vu(e){return bu.some(t=>t===e)}a(vu,"requiresExecutionReconciliation");function yu(e,t){return t?e.responsibleUserId?e.responsibleUserId===t:t==="local-board":!1}a(yu,"isHeartbeatRunVisibleInMine");var r=na(ac(),1),wu=Object.defineProperty,hr=a((e,t)=>wu(e,"name",{value:t,configurable:!0}),"__name"),ca="Collapsible",[ku,Cg]=mc(ca),[ju,ua]=ku(ca),Iu=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,open:o,defaultOpen:i,disabled:l,onOpenChange:c,...d}=t,[p,f]=fc({prop:o,defaultProp:i??!1,onChange:c,caller:ca});return(0,r.jsx)(ju,{scope:s,disabled:l,contentId:Cc(),open:p,onOpenToggle:u.useCallback(()=>f(h=>!h),[f]),children:(0,r.jsx)(oa.div,{"data-state":ps(p),"data-disabled":l?"":void 0,...d,ref:n})})},"Collapsible2"),"Collapsible")),Cu="CollapsibleTrigger",Su=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,...o}=t,i=ua(Cu,s);return(0,r.jsx)(oa.button,{type:"button","aria-controls":i.open?i.contentId:void 0,"aria-expanded":i.open||!1,"data-state":ps(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled,...o,ref:n,onClick:Nc(t.onClick,i.onOpenToggle)})},"CollapsibleTrigger2"),"CollapsibleTrigger")),ii="CollapsibleContent",Nu=u.forwardRef(hr(a(function(t,n){const{forceMount:s,...o}=t,i=ua(ii,t.__scopeCollapsible);return(0,r.jsx)(xc,{present:s||i.open,children:a(({present:l})=>(0,r.jsx)(_u,{...o,ref:n,present:l}),"children")})},"CollapsibleContent2"),"CollapsibleContent")),_u=u.forwardRef(hr(a(function(t,n){const{__scopeCollapsible:s,present:o,children:i,...l}=t,c=ua(ii,s),[d,p]=u.useState(o),f=u.useRef(null),h=yc(n,f),b=u.useRef(0),k=b.current,S=u.useRef(0),I=S.current,M=c.open||d,R=u.useRef(M),W=u.useRef(void 0);return u.useEffect(()=>{const O=requestAnimationFrame(()=>R.current=!1);return()=>cancelAnimationFrame(O)},[]),kc(()=>{const O=f.current;if(O){W.current=W.current||{transitionDuration:O.style.transitionDuration,animationName:O.style.animationName},O.style.transitionDuration="0s",O.style.animationName="none";const B=O.getBoundingClientRect();b.current=B.height,S.current=B.width,R.current||(O.style.transitionDuration=W.current.transitionDuration,O.style.animationName=W.current.animationName),p(o)}},[c.open,o]),(0,r.jsx)(oa.div,{"data-state":ps(c.open),"data-disabled":c.disabled?"":void 0,id:c.contentId,hidden:!M,...l,ref:h,style:{"--radix-collapsible-content-height":k?`${k}px`:void 0,"--radix-collapsible-content-width":I?`${I}px`:void 0,...t.style},children:M&&i})},"CollapsibleContentImpl2"),"CollapsibleContentImpl"));function ps(e){return e?"open":"closed"}a(ps,"getState");hr(ps,"getState");var Eu=Iu,li={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};li.node;var Mu=at(li),ci={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};ci.node;var ui=at(ci),di={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};di.node;var Au=at(di),fi={name:"chevrons-down-up",size:24,node:[["path",{d:"m7 20 5-5 5 5",key:"13a0gw"}],["path",{d:"m7 4 5 5 5-5",key:"1kwcof"}]]};fi.node;var pi=at(fi),mi={name:"circle-slash-2",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M22 2 2 22",key:"y4kqgn"}]],aliases:["circle-slashed"]};mi.node;var hi=at(mi),gi={name:"columns-3",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],aliases:["panels-left-right"]};gi.node;var Ru=at(gi),xi={name:"file-search",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"11.5",cy:"14.5",r:"2.5",key:"1bq0ko"}],["path",{d:"M13.3 16.3 15 18",key:"2quom7"}]]};xi.node;var Du=at(xi),bi={name:"funnel",size:24,node:[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],aliases:["filter"]};bi.node;var Ou=at(bi),vi={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};vi.node;var Tu=at(vi),yi={name:"list-collapse",size:24,node:[["path",{d:"M10 5h11",key:"1hkqpe"}],["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 19h11",key:"14g2nv"}],["path",{d:"m3 10 3-3-3-3",key:"i7pm08"}],["path",{d:"m3 20 3-3-3-3",key:"20gx1n"}]]};yi.node;var wi=at(yi),ki={name:"list-tree",size:24,node:[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]};ki.node;var ji=at(ki),Ii={name:"panel-top-close",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"m9 16 3-3 3 3",key:"1idcnm"}]]};Ii.node;var Ci=at(Ii),Si={name:"repeat",size:24,node:[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]};Si.node;var Sg=at(Si),Ni={name:"square-kanban",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M8 7v7",key:"1x2jlm"}],["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M16 7v9",key:"1hp2iy"}]],aliases:["kanban-square"]};Ni.node;var _i=at(Ni);function Ei({...e}){return(0,r.jsx)(Eu,{"data-slot":"collapsible",...e})}a(Ei,"Collapsible");function Ng({...e}){return(0,r.jsx)(Su,{"data-slot":"collapsible-trigger",...e})}a(Ng,"CollapsibleTrigger");function Mi({...e}){return(0,r.jsx)(Nu,{"data-slot":"collapsible-content",...e})}a(Mi,"CollapsibleContent");var Jn=na(lc());function Pu(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,u.useMemo)(()=>s=>{t.forEach(o=>o(s))},t)}a(Pu,"useCombinedRefs");var ms=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function $n(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}a($n,"isWindow");function da(e){return"nodeType"in e}a(da,"isNode");function et(e){var t,n;return e?$n(e)?e:da(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}a(et,"getWindow");function fa(e){const{Document:t}=et(e);return e instanceof t}a(fa,"isDocument");function gr(e){return $n(e)?!1:e instanceof et(e).HTMLElement}a(gr,"isHTMLElement");function Ai(e){return e instanceof et(e).SVGElement}a(Ai,"isSVGElement");function Bn(e){return e?$n(e)?e.document:da(e)?fa(e)?e:gr(e)||Ai(e)?e.ownerDocument:document:document:document}a(Bn,"getOwnerDocument");var It=ms?u.useLayoutEffect:u.useEffect;function hs(e){const t=(0,u.useRef)(e);return It(()=>{t.current=e}),(0,u.useCallback)(function(){for(var n=arguments.length,s=new Array(n),o=0;o<n;o++)s[o]=arguments[o];return t.current==null?void 0:t.current(...s)},[])}a(hs,"useEvent");function $u(){const e=(0,u.useRef)(null);return[(0,u.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,u.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}a($u,"useInterval");function or(e,t){t===void 0&&(t=[e]);const n=(0,u.useRef)(e);return It(()=>{n.current!==e&&(n.current=e)},t),n}a(or,"useLatestValue");function xr(e,t){const n=(0,u.useRef)();return(0,u.useMemo)(()=>{const s=e(n.current);return n.current=s,s},[...t])}a(xr,"useLazyMemo");function es(e){const t=hs(e),n=(0,u.useRef)(null);return[n,(0,u.useCallback)(s=>{s!==n.current&&t?.(s,n.current),n.current=s},[])]}a(es,"useNodeRef");function ts(e){const t=(0,u.useRef)();return(0,u.useEffect)(()=>{t.current=e},[e]),t.current}a(ts,"usePrevious");var Rs={};function br(e,t){return(0,u.useMemo)(()=>{if(t)return t;const n=Rs[e]==null?0:Rs[e]+1;return Rs[e]=n,e+"-"+n},[e,t])}a(br,"useUniqueId");function Ri(e){return function(t){for(var n=arguments.length,s=new Array(n>1?n-1:0),o=1;o<n;o++)s[o-1]=arguments[o];return s.reduce((i,l)=>{const c=Object.entries(l);for(const[d,p]of c){const f=i[d];f!=null&&(i[d]=f+e*p)}return i},{...t})}}a(Ri,"createAdjustmentFn");var An=Ri(1),ir=Ri(-1);function Bu(e){return"clientX"in e&&"clientY"in e}a(Bu,"hasViewportRelativeCoordinates");function gs(e){if(!e)return!1;const{KeyboardEvent:t}=et(e.target);return t&&e instanceof t}a(gs,"isKeyboardEvent");function Lu(e){if(!e)return!1;const{TouchEvent:t}=et(e.target);return t&&e instanceof t}a(Lu,"isTouchEvent");function ns(e){if(Lu(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Bu(e)?{x:e.clientX,y:e.clientY}:null}a(ns,"getEventCoordinates");var tn=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[tn.Translate.toString(e),tn.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:s}=e;return t+" "+n+"ms "+s}}}),Ga="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Wu(e){return e.matches(Ga)?e:e.querySelector(Ga)}a(Wu,"findFirstFocusableNode");var Uu={display:"none"};function Fu(e){let{id:t,value:n}=e;return u.createElement("div",{id:t,style:Uu},n)}a(Fu,"HiddenText");function Ku(e){let{id:t,announcement:n,ariaLiveType:s="assertive"}=e;return u.createElement("div",{id:t,style:{position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"},role:"status","aria-live":s,"aria-atomic":!0},n)}a(Ku,"LiveRegion");function zu(){const[e,t]=(0,u.useState)("");return{announce:(0,u.useCallback)(n=>{n!=null&&t(n)},[]),announcement:e}}a(zu,"useAnnouncement");var Di=(0,u.createContext)(null);function qu(e){const t=(0,u.useContext)(Di);(0,u.useEffect)(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}a(qu,"useDndMonitor");function Vu(){const[e]=(0,u.useState)(()=>new Set),t=(0,u.useCallback)(n=>(e.add(n),()=>e.delete(n)),[e]);return[(0,u.useCallback)(n=>{let{type:s,event:o}=n;e.forEach(i=>{var l;return(l=i[s])==null?void 0:l.call(i,o)})},[e]),t]}a(Vu,"useDndMonitorProvider");var Gu={draggable:`
2
2
  To pick up a draggable item, press the space bar.
3
3
  While dragging, use the arrow keys to move the item.
4
4
  Press space again to drop the item in its new position, or press escape to cancel.
@@ -1 +1 @@
1
- var ks=Object.defineProperty;var t=(n,c)=>ks(n,"name",{value:c,configurable:!0});import{i as as}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as Ps,Ei as As,Jr as A,S as Ms,U as Ds,X as m,ki as Ts,qr as S}from"./agent-avatar-url-270oGkoO.js";import{P as qs,Ut as Ks,ft as ze,ht as Us,o as Es}from"./router-BC2Duaf5.js";import{Ct as Os,O as Ls,St as Qs,_r as Bs,bt as Vs,cr as ls,dt as Ge,or as We,r as $s,sr as He,t as zs,ur as ee,v as he,vt as Gs,yt as Ws}from"./RoutineRunVariablesDialog-yR5DLc68.js";import{l as J,t as Hs}from"./MarkdownEditor-seU_oAfy.js";import{t as Ye}from"./AgentAvatar-lnkDMHMh.js";import{a as Ys,r as Js}from"./checkbox-SNvdBfci.js";import{n as Je,t as Xs}from"./tabs-DCzsHrwQ.js";import{d as Xe,g as Ze,p as es,t as Zs}from"./agents-BlxRXAz3.js";import{g as et}from"./StatusIcon-BtBa0xK_.js";import{r as st,t as je}from"./EmptyState-CqqJOoXs.js";import{t as tt}from"./check-5Tuqm2aI.js";import{t as nt}from"./chevron-down-ZMnYk9j3.js";import{t as cs}from"./chevron-right-Dv6dHZgu.js";import{c as ye,i as X,n as ve,s as be,t as we}from"./select-DsMS_Sad.js";import{k as Z,t as F}from"./button-DLWREze0.js";import{t as rt}from"./heartbeats-DWUL5tSL.js";import{i as it,o as ot}from"./company-members-BKdmkDTe.js";import{r as at,t as lt}from"./card-Qk8smcrQ.js";import{t as ct}from"./PageSkeleton-C9WV_Qyq.js";import{$ as dt,Q as ut,X as mt,Z as pt,_t as M,an as ft,at as gt,et as xt,gt as ht,ht as jt,it as yt,mn as vt,nt as bt,on as wt,ot as Nt,rt as It,st as Rt,tn as _t,tt as Ct}from"./index-DTMtHDxt.js";var l=as(Ts(),1),s=as(Ps(),1),St=["coalesce_if_active","always_enqueue","skip_if_active"],Ft=["skip_missed","enqueue_missed_with_cap"],kt={coalesce_if_active:"If a run is already active, keep just one follow-up run queued.",always_enqueue:"Queue every trigger occurrence, even if the routine is already running.",skip_if_active:"Drop new trigger occurrences while a run is still active."},Pt={skip_missed:"Ignore windows that were missed while the scheduler or routine was paused.",enqueue_missed_with_cap:"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."};function ss(n){n&&(n.style.height="auto",n.style.height=`${n.scrollHeight}px`)}t(ss,"autoResizeTextarea");var At="__built_in_routines",ts={sortField:"title",sortDir:"asc",groupBy:"folder",collapsedGroups:[]};function ns(n){try{const c=localStorage.getItem(n);if(c)return{...ts,...JSON.parse(c)}}catch{}return{...ts}}t(ns,"getRoutineViewState");function Mt(n,c){localStorage.setItem(n,JSON.stringify(c))}t(Mt,"saveRoutineViewState");function q(n){if(!n)return Number.NEGATIVE_INFINITY;const c=new Date(n).getTime();return Number.isFinite(c)?c:Number.NEGATIVE_INFINITY}t(q,"timestampValue");function rs(n,c){return(n??"").localeCompare(c??"",void 0,{sensitivity:"base"})}t(rs,"compareNullableText");function Dt(n){return{...n,description:n.description.trim()||null,projectId:n.projectId||null,folderId:n.folderId||null,assigneeAgentId:n.assigneeAgentId||null}}t(Dt,"buildRoutineMutationPayload");function Tt(n,c,d,b,g){if(c==="none")return[{key:"__all",label:null,items:n}];if(c==="folder"){const i=he(n,o=>o.folderId??"__unfiled");return Object.keys(i).sort((o,j)=>{if(o==="__unfiled"||j==="__unfiled")return o===j?0:o==="__unfiled"?1:-1;const w=g.get(o),I=g.get(j),O=(Number.isFinite(w?.position)?w.position:Number.POSITIVE_INFINITY)-(Number.isFinite(I?.position)?I.position:Number.POSITIVE_INFINITY);return O!==0?O:(w?.name??"Unknown folder").localeCompare(I?.name??"Unknown folder",void 0,{sensitivity:"base"})||o.localeCompare(j)}).map(o=>({key:o,label:o==="__unfiled"?"Unfiled":g.get(o)?.name??"Unknown folder",items:i[o]}))}if(c==="project"){const i=he(n,o=>o.projectId??"__no_project");return Object.keys(i).sort((o,j)=>{const w=o==="__no_project"?"No project":d.get(o)?.name??"Unknown project",I=j==="__no_project"?"No project":d.get(j)?.name??"Unknown project";return w.localeCompare(I)}).map(o=>({key:o,label:o==="__no_project"?"No project":d.get(o)?.name??"Unknown project",items:i[o]}))}const x=he(n,i=>i.assigneeAgentId??"__unassigned");return Object.keys(x).sort((i,o)=>{const j=i==="__unassigned"?"Unassigned":b.get(i)?.name??"Unknown agent",w=o==="__unassigned"?"Unassigned":b.get(o)?.name??"Unknown agent";return j.localeCompare(w)}).map(i=>({key:i,label:i==="__unassigned"?"Unassigned":b.get(i)?.name??"Unknown agent",items:x[i]}))}t(Tt,"buildRoutineGroups");function is(n){return n.originKind==="built_in_agent_bundle"}t(is,"isBuiltInRoutine");function qt(n,c,d,b,g){const x=n.filter(is),i=Tt(n.filter(o=>!is(o)),c,d,b,g).filter(o=>o.items.length>0).map(o=>x.length>0&&c==="none"&&o.key==="__all"?{...o,label:"Custom routines"}:o);return x.length===0?i:[...i,{key:At,label:"Built-in routines",items:x}]}t(qt,"buildRoutineSections");function Kt(n,c,d){const b=d==="asc"?1:-1;return[...n].sort((g,x)=>{let i=0;return c==="title"?i=rs(g.title,x.title):c==="created"?i=q(g.createdAt)-q(x.createdAt):c==="lastRun"?i=q(g.lastRun?.triggeredAt??g.lastTriggeredAt)-q(x.lastRun?.triggeredAt??x.lastTriggeredAt):i=q(g.updatedAt)-q(x.updatedAt),i!==0?i*b:rs(g.title,x.title)})}t(Kt,"sortRoutines");function os(n){return n==="runs"?"/routines?tab=runs":"/routines"}t(os,"buildRoutinesTabHref");function Ut({label:n,count:c,isOpen:d}){return(0,s.jsxs)("div",{className:`flex items-center gap-2 rounded-lg border border-border px-3 py-2${d?" mb-1":""}`,children:[(0,s.jsxs)(ls,{className:"flex items-center gap-1.5",children:[(0,s.jsx)(cs,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),(0,s.jsx)("span",{className:"text-sm font-semibold uppercase tracking-wide",children:n})]}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:c})]})}t(Ut,"RoutineSectionHeader");function cn(){const{selectedCompanyId:n}=Ds(),{setBreadcrumbs:c}=st(),d=As(),b=Es(),[g,x]=Ks(),{pushToast:i}=vt(),o=(0,l.useRef)(null),j=(0,l.useRef)(null),w=(0,l.useRef)(null),I=(0,l.useRef)(null),[O,K]=(0,l.useState)(!1),[se,L]=(0,l.useState)(null),[Q,te]=(0,l.useState)(null),[ds,Ne]=(0,l.useState)(!1),[ne,re]=(0,l.useState)(!1),[B,V]=(0,l.useState)([]),[Ie,Re]=(0,l.useState)([]),[us,_e]=(0,l.useState)(null),[ms,Ce]=(0,l.useState)(null),[k,ie]=(0,l.useState)(null),[$,z]=(0,l.useState)(!1),[Se,oe]=(0,l.useState)(!1),P=g.get("tab")==="runs"?"runs":"routines",[p,R]=(0,l.useState)({title:"",description:"",projectId:"",folderId:null,assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",variables:[]}),G=n?`paperclip:routines-view:${n}`:"paperclip:routines-view",[u,Fe]=(0,l.useState)(()=>ns(G)),f=Nt(g.get("folder"));(0,l.useEffect)(()=>{c([{label:"Routines"}])},[c]),(0,l.useEffect)(()=>{Fe(ns(G))},[G]);const{data:ke,isLoading:ps,error:ae}=A({queryKey:m.routines.list(n),queryFn:t(()=>J.list(n),"queryFn"),enabled:!!n}),{data:h,isLoading:Pe}=A({queryKey:m.folders.list(n,"routine"),queryFn:t(()=>M.list(n,"routine"),"queryFn"),enabled:!!n&&P==="routines"}),{data:_}=A({queryKey:m.agents.list(n),queryFn:t(()=>Zs.list(n),"queryFn"),enabled:!!n}),{data:C}=A({queryKey:m.projects.list(n,{includeArchived:!0}),queryFn:t(()=>et.list(n,{includeArchived:!0}),"queryFn"),enabled:!!n}),{data:Ae}=A({queryKey:m.access.companyUserDirectory(n),queryFn:t(()=>ot.listUserDirectory(n),"queryFn"),enabled:!!n}),{data:le,isLoading:fs,error:gs}=A({queryKey:[...m.issues.list(n),"routine-executions"],queryFn:t(()=>ze.list(n,{originKind:"routine_execution"}),"queryFn"),enabled:!!n&&P==="runs"}),Me=m.liveRuns(n),ce=wt({companyId:n,resourceKey:"live-runs",queryKey:Me,enabled:!!n&&P==="runs",refetchInterval:!1,leaderOnly:!0}),{data:de,dataUpdatedAt:xs}=A({queryKey:Me,queryFn:t(()=>rt.liveRunsForCompany(n),"queryFn"),enabled:ce.enabled,refetchInterval:ce.refetchInterval});ft(ce,de,xs),(0,l.useEffect)(()=>{ss(j.current)},[p.title,$]);const hs=(0,l.useMemo)(()=>it({agents:_,projects:(C??[]).filter(e=>!e.archivedAt),members:Ae?.users}),[_,Ae?.users,C]),N=S({mutationFn:t(()=>J.create(n,Dt(p)),"mutationFn"),onSuccess:t(async e=>{R({title:"",description:"",projectId:"",folderId:null,assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",variables:[]}),z(!1),oe(!1),await d.invalidateQueries({queryKey:m.routines.list(n)}),i({title:"Routine created",body:e.assigneeAgentId?"Add the first trigger to turn it into a live workflow.":"Draft saved. Add a default agent before enabling automation.",tone:"success"}),b(`/routines/${e.id}?tab=triggers`)},"onSuccess")}),De=S({mutationFn:t(e=>M.create(n,{kind:"routine",...e}),"mutationFn"),onSuccess:t(async e=>{if(K(!1),L(null),await d.invalidateQueries({queryKey:m.folders.list(n,"routine")}),Ie.length>0){const r=Ie;Re([]);try{await Promise.all(r.map(a=>M.moveItem(n,{kind:"routine",itemId:a,folderId:e.id}))),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})])}catch(a){i({title:"Folder created, move failed",body:a instanceof Error?a.message:"Paperclip could not move the selected routines.",tone:"error"});return}}else H(e.id);i({title:"Folder created",body:e.name,tone:"success"})},"onSuccess"),onError:t(e=>{i({title:"Failed to save folder",body:e instanceof Error?e.message:"Paperclip could not save the folder.",tone:"error"})},"onError")}),ue=S({mutationFn:t(({folderId:e,payload:r})=>M.update(n,e,r),"mutationFn"),onSuccess:t(async()=>{K(!1),L(null),await d.invalidateQueries({queryKey:m.folders.list(n,"routine")})},"onSuccess"),onError:t(e=>{i({title:"Folder save failed",body:e instanceof Error?e.message:"Paperclip could not update the folder.",tone:"error"})},"onError")}),Te=S({mutationFn:t(e=>M.delete(n,e),"mutationFn"),onSuccess:t(async(e,r)=>{f===r&&H("all"),te(null),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})]),i({title:"Folder deleted",body:"Items moved to Unfiled.",tone:"success"})},"onSuccess"),onError:t(e=>{i({title:"Folder delete failed",body:e instanceof Error?e.message:"Paperclip could not delete the folder.",tone:"error"})},"onError")}),qe=S({mutationFn:t(({itemId:e,folderId:r})=>M.moveItem(n,{kind:"routine",itemId:e,folderId:r}),"mutationFn"),onSuccess:t(async()=>{await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})])},"onSuccess"),onError:t(e=>{i({title:"Move failed",body:e instanceof Error?e.message:"Paperclip could not move the routine.",tone:"error"})},"onError")}),js=S({mutationFn:t(({id:e,data:r})=>ze.update(e,r),"mutationFn"),onSuccess:t(async()=>{await d.invalidateQueries({queryKey:[...m.issues.list(n),"routine-executions"]})},"onSuccess")}),Ke=S({mutationFn:t(({id:e,status:r})=>J.update(e,{status:r}),"mutationFn"),onMutate:t(({id:e})=>{Ce(e)},"onMutate"),onSuccess:t(async(e,r)=>{await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.routines.detail(r.id)})])},"onSuccess"),onSettled:t(()=>{Ce(null)},"onSettled"),onError:t(e=>{i({title:"Failed to update routine",body:e instanceof Error?e.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Ue=S({mutationFn:t(({id:e,data:r})=>J.run(e,{...r?.variables&&Object.keys(r.variables).length>0?{variables:r.variables}:{},...r?.assigneeAgentId!==void 0?{assigneeAgentId:r.assigneeAgentId}:{},...r?.projectId!==void 0?{projectId:r.projectId}:{},...r?.executionWorkspaceId!==void 0?{executionWorkspaceId:r.executionWorkspaceId}:{},...r?.executionWorkspacePreference!==void 0?{executionWorkspacePreference:r.executionWorkspacePreference}:{},...r?.executionWorkspaceSettings!==void 0?{executionWorkspaceSettings:r.executionWorkspaceSettings}:{}}),"mutationFn"),onMutate:t(({id:e})=>{_e(e)},"onMutate"),onSuccess:t(async(e,{id:r})=>{ie(null),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.routines.detail(r)})])},"onSuccess"),onSettled:t(()=>{_e(null)},"onSettled"),onError:t(e=>{i({title:"Routine run failed",body:e instanceof Error?e.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),me=(0,l.useMemo)(()=>Vs(),[$]),ys=(0,l.useMemo)(()=>Gs(),[$]),vs=(0,l.useMemo)(()=>Qs((_??[]).filter(e=>e.status!=="terminated"),me).map(e=>({id:e.id,label:e.name,searchText:`${e.name} ${e.role} ${e.title??""}`})),[_,me]),bs=(0,l.useMemo)(()=>(C??[]).filter(e=>!e.archivedAt).map(e=>({id:e.id,label:e.name,searchText:e.description??""})),[C]),U=(0,l.useMemo)(()=>new Map((_??[]).map(e=>[e.id,e])),[_]),E=(0,l.useMemo)(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),Ee=(0,l.useMemo)(()=>new Map((h?.folders??[]).map(e=>[e.id,e])),[h]),ws=(0,l.useMemo)(()=>Ls(de,le),[de,le]),y=(0,l.useMemo)(()=>(ke??[]).filter(e=>e.status!=="archived"),[ke]),Oe=(0,l.useMemo)(()=>u.groupBy!=="folder"||f==="all"?y:f==="unfiled"?y.filter(e=>!e.folderId):y.filter(e=>e.folderId===f),[f,u.groupBy,y]),pe=(0,l.useMemo)(()=>{if(!h)return h;const e=new Map;let r=0;for(const a of y)a.folderId?e.set(a.folderId,(e.get(a.folderId)??0)+1):r+=1;return{...h,allCount:y.length,unfiledCount:r,folders:h.folders.map(a=>({...a,itemCount:e.get(a.id)??0}))}},[h,y]),D=(0,l.useMemo)(()=>Kt(Oe,u.sortField,u.sortDir),[Oe,u.sortDir,u.sortField]),Ns=(0,l.useMemo)(()=>qt(D,u.groupBy,E,U,Ee),[U,Ee,E,u.groupBy,D]),Is=(0,l.useMemo)(()=>Us("Recent Runs",os("runs"),"issues"),[]),Le=p.assigneeAgentId?U.get(p.assigneeAgentId)??null:null,Qe=p.projectId?E.get(p.projectId)??null:null,Be=Rt(h?.folders??[],f),W=(h?.folders.length??0)>0,fe=P==="routines"&&u.groupBy==="folder"&&W;function ge(e){Fe(r=>{const a={...r,...e};return Mt(G,a),a})}t(ge,"updateRoutineView");function Ve(e){const r=e==="runs"?"runs":"routines";(0,l.startTransition)(()=>{b(os(r))})}t(Ve,"handleTabChange");function H(e){x(r=>{const a=new URLSearchParams(r),v=gt(e);return v?a.set("folder",v):a.delete("folder"),a})}t(H,"setFolderSelection");function T(e=[]){Re(e),L(null),K(!0)}t(T,"openCreateFolder");function $e(){R(e=>({...e,folderId:f==="all"||f==="unfiled"?null:f})),z(!0)}t($e,"openCreateRoutine");async function Rs(e){const r=B;if(r.length!==0)try{await Promise.all(r.map(a=>M.moveItem(n,{kind:"routine",itemId:a,folderId:e}))),V([]),re(!1),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})]),i({title:"Routines moved",body:`${r.length} routine${r.length===1?"":"s"} filed.`,tone:"success"})}catch(a){i({title:"Failed to move routines",body:a instanceof Error?a.message:"Paperclip could not move the selected routines.",tone:"error"})}}t(Rs,"moveSelectedRoutines");function _s(e){ie(e)}t(_s,"handleRunNow");function Cs(e,r){if(!r&&!e.assigneeAgentId){i({title:"Default agent required",body:"Set a default agent before enabling routine automation.",tone:"warn"});return}Ke.mutate({id:e.id,status:ht(e.status,!r)})}t(Cs,"handleToggleEnabled");function Ss(e){Ke.mutate({id:e.id,status:e.status==="archived"?"active":"archived"})}return t(Ss,"handleToggleArchived"),n?ps?(0,s.jsx)(ct,{variant:"issues-list"}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",children:"Routines"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Recurring work definitions that materialize into auditable execution tasks."})]}),(0,s.jsxs)(F,{onClick:$e,children:[(0,s.jsx)(Z,{className:"mr-2 h-4 w-4"}),"Create routine"]})]}),(0,s.jsxs)(Xs,{value:P,onValueChange:Ve,children:[(0,s.jsx)(_t,{align:"start",value:P,onValueChange:Ve,items:[{value:"routines",label:"Routines"},{value:"runs",label:"Recent Runs"}]}),(0,s.jsxs)(Je,{value:"routines",className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[y.length," routine",y.length===1?"":"s"]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsxs)(Xe,{children:[(0,s.jsx)(Ze,{asChild:!0,children:(0,s.jsxs)(F,{variant:"ghost",size:"sm",className:"text-xs",title:"Sort",children:[(0,s.jsx)(Bs,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Sort"})]})}),(0,s.jsx)(es,{align:"end",className:"w-44 p-0",children:(0,s.jsx)("div",{className:"p-2 space-y-0.5",children:[["updated","Updated"],["created","Created"],["lastRun","Last run"],["title","Title"]].map(([e,r])=>(0,s.jsxs)("button",{className:`flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm ${u.sortField===e?"bg-accent/50 text-foreground":"text-muted-foreground hover:bg-accent/50"}`,onClick:t(()=>{ge(u.sortField===e?{sortDir:u.sortDir==="asc"?"desc":"asc"}:{sortField:e,sortDir:e==="title"?"asc":"desc"})},"onClick"),children:[(0,s.jsx)("span",{children:r}),u.sortField===e?(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:u.sortDir==="asc"?"Asc":"Desc"}):null]},e))})})]}),(0,s.jsxs)(Xe,{children:[(0,s.jsx)(Ze,{asChild:!0,children:(0,s.jsxs)(F,{variant:"ghost",size:"sm",className:"text-xs",title:"Group",children:[(0,s.jsx)(qs,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Group"})]})}),(0,s.jsx)(es,{align:"end",className:"w-44 p-0",children:(0,s.jsx)("div",{className:"p-2 space-y-0.5",children:[["folder","Folder"],["project","Project"],["assignee","Agent"],["none","None"]].map(([e,r])=>(0,s.jsxs)("button",{className:`flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm ${u.groupBy===e?"bg-accent/50 text-foreground":"text-muted-foreground hover:bg-accent/50"}`,onClick:t(()=>ge({groupBy:e,collapsedGroups:[]}),"onClick"),children:[(0,s.jsx)("span",{children:r}),u.groupBy===e?(0,s.jsx)(tt,{className:"h-3.5 w-3.5"}):null]},e))})})]}),u.groupBy==="folder"&&!W?(0,s.jsxs)(F,{variant:"outline",size:"sm",onClick:t(()=>T(),"onClick"),children:[(0,s.jsx)(Z,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}):null,fe?(0,s.jsx)(F,{variant:"ghost",size:"sm",className:"text-xs",onClick:t(()=>re(e=>!e),"onClick"),children:ne?"Done":"Select"}):null]})]}),u.groupBy==="folder"?(0,s.jsx)("div",{className:"md:hidden",children:(0,s.jsx)(dt,{result:pe,selection:f,allLabel:"All routines",onClick:t(()=>Ne(!0),"onClick")})}):null]}),(0,s.jsx)(Je,{value:"runs",children:(0,s.jsx)($s,{issues:le??[],isLoading:fs,error:gs,agents:_,projects:C,liveIssueIds:ws,viewStateKey:"paperclip:routine-recent-runs-view",issueLinkState:Is,onUpdateIssue:t((e,r)=>js.mutate({id:e,data:r}),"onUpdateIssue")})})]}),(0,s.jsx)(Js,{open:$,onOpenChange:t(e=>{N.isPending||z(e)},"onOpenChange"),children:(0,s.jsxs)(Ys,{showCloseButton:!1,className:"flex max-h-(--sz-calc-18) max-w-3xl flex-col gap-0 overflow-hidden p-0",children:[(0,s.jsxs)("div",{className:"shrink-0 flex flex-wrap items-center justify-between gap-3 border-b border-border/60 px-5 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"New routine"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define the recurring work first. Default project and agent are optional for draft routines."})]}),(0,s.jsx)(F,{variant:"ghost",size:"sm",onClick:t(()=>{z(!1),oe(!1)},"onClick"),disabled:N.isPending,children:"Cancel"})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,s.jsx)("div",{className:"px-5 pt-5 pb-3",children:(0,s.jsx)("textarea",{ref:j,className:"w-full resize-none overflow-hidden bg-transparent text-xl font-semibold outline-none placeholder:text-muted-foreground/50",placeholder:"Routine title",rows:1,value:p.title,onChange:t(e=>{R(r=>({...r,title:e.target.value})),ss(e.target)},"onChange"),onKeyDown:t(e=>{if(e.key==="Enter"&&!e.metaKey&&!e.ctrlKey&&!e.nativeEvent.isComposing){e.preventDefault(),o.current?.focus();return}e.key==="Tab"&&!e.shiftKey&&(e.preventDefault(),p.assigneeAgentId?p.projectId?o.current?.focus():I.current?.focus():w.current?.focus())},"onKeyDown"),autoFocus:!0})}),(0,s.jsx)("div",{className:"px-5 pb-3",children:(0,s.jsx)("div",{className:"overflow-x-auto overscroll-x-contain",children:(0,s.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,s.jsx)("span",{children:"For"}),(0,s.jsx)(Ge,{ref:w,value:p.assigneeAgentId,options:vs,recentOptionIds:me,placeholder:"Responsible",noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:"No responsible found.",onChange:t(e=>{e&&Os(e),R(r=>({...r,assigneeAgentId:e}))},"onChange"),onConfirm:t(()=>{p.projectId?o.current?.focus():I.current?.focus()},"onConfirm"),renderTriggerValue:t(e=>e?Le?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ye,{agent:Le,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("span",{className:"truncate",children:e.label})]}):(0,s.jsx)("span",{className:"truncate",children:e.label}):(0,s.jsx)("span",{className:"text-muted-foreground",children:"Responsible"}),"renderTriggerValue"),renderOption:t(e=>{if(!e.id)return(0,s.jsx)("span",{className:"truncate",children:e.label});const r=U.get(e.id);return(0,s.jsxs)(s.Fragment,{children:[r?(0,s.jsx)(Ye,{agent:r,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,s.jsx)("span",{className:"truncate",children:e.label})]})},"renderOption")}),(0,s.jsx)("span",{children:"in"}),(0,s.jsx)(Ge,{ref:I,value:p.projectId,options:bs,recentOptionIds:ys,placeholder:"Project",noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:"No projects found.",onChange:t(e=>{e&&Ws(e),R(r=>({...r,projectId:e}))},"onChange"),onConfirm:t(()=>o.current?.focus(),"onConfirm"),renderTriggerValue:t(e=>e&&Qe?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:Qe.color??"var(--project-none)"}}),(0,s.jsx)("span",{className:"truncate",children:e.label})]}):(0,s.jsx)("span",{className:"text-muted-foreground",children:"Project"}),"renderTriggerValue"),renderOption:t(e=>{if(!e.id)return(0,s.jsx)("span",{className:"truncate",children:e.label});const r=E.get(e.id);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:r?.color??"var(--project-none)"}}),(0,s.jsx)("span",{className:"truncate",children:e.label})]})},"renderOption")}),(0,s.jsx)("span",{children:"filed in"}),(0,s.jsxs)(we,{value:p.folderId??"__unfiled",onValueChange:t(e=>R(r=>({...r,folderId:e==="__unfiled"?null:e})),"onValueChange"),children:[(0,s.jsx)(be,{className:"h-8 w-auto min-w-32 border-0 bg-muted/50 px-2 shadow-none",children:(0,s.jsx)(ye,{})}),(0,s.jsxs)(ve,{children:[(0,s.jsx)(X,{value:"__unfiled",children:"Unfiled"}),(h?.folders??[]).map(e=>(0,s.jsx)(X,{value:e.id,children:e.name},e.id))]})]})]})})}),(0,s.jsx)("div",{className:"border-t border-border/60 px-5 py-4",children:(0,s.jsx)(Hs,{ref:o,value:p.description,onChange:t(e=>R(r=>({...r,description:e})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-160px) text-sm text-muted-foreground",mentions:hs,onSubmit:t(()=>{!N.isPending&&p.title.trim()&&p.projectId&&p.assigneeAgentId&&N.mutate()},"onSubmit")})}),(0,s.jsx)("div",{className:"border-t border-border/60 px-5 py-3",children:(0,s.jsxs)(We,{open:Se,onOpenChange:oe,children:[(0,s.jsxs)(ls,{className:"flex w-full items-center justify-between text-left",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"Advanced delivery settings"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Keep policy controls secondary to the work definition."})]}),Se?(0,s.jsx)(nt,{className:"h-4 w-4 text-muted-foreground"}):(0,s.jsx)(cs,{className:"h-4 w-4 text-muted-foreground"})]}),(0,s.jsx)(He,{className:"pt-3",children:(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"Concurrency"}),(0,s.jsxs)(we,{value:p.concurrencyPolicy,onValueChange:t(e=>R(r=>({...r,concurrencyPolicy:e})),"onValueChange"),children:[(0,s.jsx)(be,{children:(0,s.jsx)(ye,{})}),(0,s.jsx)(ve,{children:St.map(e=>(0,s.jsx)(X,{value:e,children:e.replaceAll("_"," ")},e))})]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:kt[p.concurrencyPolicy]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"Catch-up"}),(0,s.jsxs)(we,{value:p.catchUpPolicy,onValueChange:t(e=>R(r=>({...r,catchUpPolicy:e})),"onValueChange"),children:[(0,s.jsx)(be,{children:(0,s.jsx)(ye,{})}),(0,s.jsx)(ve,{children:Ft.map(e=>(0,s.jsx)(X,{value:e,children:e.replaceAll("_"," ")},e))})]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:Pt[p.catchUpPolicy]})]})]})})]})})]}),(0,s.jsxs)("div",{className:"shrink-0 flex flex-col gap-3 border-t border-border/60 px-5 py-4 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)("div",{className:"text-sm text-muted-foreground",children:"After creation, Paperclip takes you straight to trigger setup. Draft routines stay paused until you add a default agent."}),(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:items-end",children:[(0,s.jsxs)(F,{onClick:t(()=>N.mutate(),"onClick"),disabled:N.isPending||!p.title.trim(),children:[(0,s.jsx)(Z,{className:"mr-2 h-4 w-4"}),N.isPending?"Creating...":"Create routine"]}),N.isError?(0,s.jsx)("p",{className:"text-sm text-destructive",children:N.error instanceof Error?N.error.message:"Failed to create routine"}):null]})]})]})}),ae?(0,s.jsx)(lt,{children:(0,s.jsx)(at,{className:"pt-6 text-sm text-destructive",children:ae instanceof Error?ae.message:"Failed to load routines"})}):null,P==="routines"?(0,s.jsxs)("div",{className:Ms(fe&&"flex gap-4"),children:[fe?(0,s.jsx)(Ct,{result:pe,selection:f,allLabel:"All routines",itemLabelPlural:"routines",loading:Pe,onSelect:H,onCreate:t(()=>T(),"onCreate"),onRename:t((e,r)=>ue.mutate({folderId:e.id,payload:{name:r}}),"onRename"),onEdit:t(e=>{L(e),K(!0)},"onEdit"),onDelete:te}):null,(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[u.groupBy==="folder"&&W?(0,s.jsx)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:f==="all"?(0,s.jsx)(Et,{label:"All routines",count:D.length}):(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,s.jsx)(bt,{color:Be?.color}),(0,s.jsx)("span",{className:"truncate font-medium",children:f==="unfiled"?"Unfiled":Be?.name??"Folder"}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[D.length," routine",D.length===1?"":"s"]})]})}):null,u.groupBy==="folder"&&!W&&!Pe&&y.length>0?(0,s.jsx)(mt,{storageKey:`paperclip:routines-folder-nudge:${n??"none"}`,itemLabelPlural:"routines",onCreateFolder:t(()=>T(),"onCreateFolder")}):null,ne?(0,s.jsx)(pt,{selectedCount:B.length,folders:h?.folders??[],onMove:t(e=>{Rs(e)},"onMove"),onCreateAndMove:t(()=>T(B),"onCreateAndMove"),onClear:t(()=>V([]),"onClear"),onDone:t(()=>{re(!1),V([])},"onDone")}):null,y.length===0?(0,s.jsx)("div",{className:"py-12",children:(0,s.jsx)(je,{icon:ee,message:"No active routines. Use Create routine to define the first recurring workflow."})}):D.length===0?(0,s.jsxs)("div",{className:"py-12",children:[(0,s.jsx)(je,{icon:ee,message:f==="all"?"No routines match this view.":"This folder is empty."}),f!=="all"?(0,s.jsx)("div",{className:"mt-3 flex justify-center",children:(0,s.jsxs)(F,{size:"sm",onClick:$e,children:[(0,s.jsx)(Z,{className:"mr-2 h-3.5 w-3.5"}),"New routine in this folder"]})}):null]}):(0,s.jsx)("div",{className:"flex flex-col gap-3",children:Ns.map(e=>{const r=!u.collapsedGroups.includes(e.key);return(0,s.jsxs)(We,{open:r,onOpenChange:t(a=>{ge({collapsedGroups:a?u.collapsedGroups.filter(v=>v!==e.key):[...u.collapsedGroups,e.key]})},"onOpenChange"),children:[e.label?(0,s.jsx)(Ut,{label:e.label,count:e.items.length,isOpen:r}):null,(0,s.jsx)(He,{children:e.items.map(a=>(0,s.jsx)(jt,{routine:a,projectById:E,agentById:U,runningRoutineId:us,statusMutationRoutineId:ms,href:`/routines/${a.id}`,runNowButton:!0,divider:!1,onRunNow:_s,onToggleEnabled:Cs,onToggleArchived:Ss,selectMode:ne,selected:B.includes(a.id),onSelectChange:t((v,xe)=>{V(Y=>xe?Array.from(new Set([...Y,v.id])):Y.filter(Fs=>Fs!==v.id))},"onSelectChange"),extraMenuItems:(0,s.jsx)(yt,{folders:h?.folders??[],currentFolderId:a.folderId??null,onMove:t(v=>{const xe=a.folderId??null;qe.mutate({itemId:a.id,folderId:v}),i({title:"Routine moved",body:v?`Moved "${a.title}" to ${h?.folders.find(Y=>Y.id===v)?.name??"folder"}.`:`Moved "${a.title}" to Unfiled.`,tone:"success",action:{label:"Undo",onClick:t(()=>qe.mutate({itemId:a.id,folderId:xe}),"onClick")}})},"onMove"),onCreateAndMove:t(()=>T([a.id]),"onCreateAndMove")})},a.id))})]},e.key)})})]})]}):null,(0,s.jsx)(xt,{open:O,kind:"routine",folder:se,pending:De.isPending||ue.isPending,onOpenChange:K,onSubmit:t(e=>{se?ue.mutate({folderId:se.id,payload:e}):De.mutate(e)},"onSubmit")}),(0,s.jsx)(ut,{open:Q!==null,folder:Q,itemLabelPlural:"routines",pending:Te.isPending,onOpenChange:t(e=>{e||te(null)},"onOpenChange"),onConfirm:t(()=>{Q&&Te.mutate(Q.id)},"onConfirm")}),(0,s.jsx)(It,{open:ds,onOpenChange:Ne,result:pe,selection:f,allLabel:"All routines",itemLabelPlural:"Routines",onSelect:H,onCreate:t(()=>T(),"onCreate")}),(0,s.jsx)(zs,{open:k!==null,onOpenChange:t(e=>{e||ie(null)},"onOpenChange"),companyId:n,routineName:k?.title??null,agents:_??[],projects:C??[],defaultProjectId:k?.projectId??null,defaultAssigneeAgentId:k?.assigneeAgentId??null,variables:k?.variables??[],isPending:Ue.isPending,onSubmit:t(e=>{k&&Ue.mutate({id:k.id,data:e})},"onSubmit")})]}):(0,s.jsx)(je,{icon:ee,message:"Select a company to view routines."})}t(cn,"Routines");function Et({label:n,count:c}){return(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,s.jsx)(ee,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,s.jsx)("span",{className:"truncate font-medium",children:n}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[c," routine",c===1?"":"s"]})]})}t(Et,"FolderIconHeader");export{cn as Routines};
1
+ var ks=Object.defineProperty;var t=(n,c)=>ks(n,"name",{value:c,configurable:!0});import{i as as}from"./rolldown-runtime-ZpX3ckPj.js";import{Di as Ps,Ei as As,Jr as A,S as Ms,U as Ds,X as m,ki as Ts,qr as S}from"./agent-avatar-url-CiVC72zn.js";import{P as qs,Ut as Ks,ft as ze,ht as Us,o as Es}from"./router-CGbOrhXy.js";import{Ct as Os,O as Ls,St as Qs,_r as Bs,bt as Vs,cr as ls,dt as Ge,or as We,r as $s,sr as He,t as zs,ur as ee,v as he,vt as Gs,yt as Ws}from"./RoutineRunVariablesDialog--quGEm4y.js";import{l as J,t as Hs}from"./MarkdownEditor-D0uqxShB.js";import{t as Ye}from"./AgentAvatar-CrnNGelJ.js";import{a as Ys,r as Js}from"./checkbox-SdYP--OH.js";import{n as Je,t as Xs}from"./tabs-Bs8GGKXg.js";import{d as Xe,g as Ze,p as es,t as Zs}from"./agents-BGdf-J_C.js";import{g as et}from"./StatusIcon-D__DIZlm.js";import{r as st,t as je}from"./EmptyState-ClZXiygF.js";import{t as tt}from"./check-B3EECTO-.js";import{t as nt}from"./chevron-down-wArmbnHu.js";import{t as cs}from"./chevron-right-BhU5OvzN.js";import{c as ye,i as X,n as ve,s as be,t as we}from"./select-Db0ppga4.js";import{k as Z,t as F}from"./button-BmDU7YzH.js";import{t as rt}from"./heartbeats-By7EcEMQ.js";import{i as it,o as ot}from"./company-members-c2ldQ5sU.js";import{r as at,t as lt}from"./card-V5O2wbgV.js";import{t as ct}from"./PageSkeleton-DQuX4FJP.js";import{$ as dt,Q as ut,X as mt,Z as pt,_t as M,an as ft,at as gt,et as xt,gt as ht,ht as jt,it as yt,mn as vt,nt as bt,on as wt,ot as Nt,rt as It,st as Rt,tn as _t,tt as Ct}from"./index-DcHMTMN0.js";var l=as(Ts(),1),s=as(Ps(),1),St=["coalesce_if_active","always_enqueue","skip_if_active"],Ft=["skip_missed","enqueue_missed_with_cap"],kt={coalesce_if_active:"If a run is already active, keep just one follow-up run queued.",always_enqueue:"Queue every trigger occurrence, even if the routine is already running.",skip_if_active:"Drop new trigger occurrences while a run is still active."},Pt={skip_missed:"Ignore windows that were missed while the scheduler or routine was paused.",enqueue_missed_with_cap:"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."};function ss(n){n&&(n.style.height="auto",n.style.height=`${n.scrollHeight}px`)}t(ss,"autoResizeTextarea");var At="__built_in_routines",ts={sortField:"title",sortDir:"asc",groupBy:"folder",collapsedGroups:[]};function ns(n){try{const c=localStorage.getItem(n);if(c)return{...ts,...JSON.parse(c)}}catch{}return{...ts}}t(ns,"getRoutineViewState");function Mt(n,c){localStorage.setItem(n,JSON.stringify(c))}t(Mt,"saveRoutineViewState");function q(n){if(!n)return Number.NEGATIVE_INFINITY;const c=new Date(n).getTime();return Number.isFinite(c)?c:Number.NEGATIVE_INFINITY}t(q,"timestampValue");function rs(n,c){return(n??"").localeCompare(c??"",void 0,{sensitivity:"base"})}t(rs,"compareNullableText");function Dt(n){return{...n,description:n.description.trim()||null,projectId:n.projectId||null,folderId:n.folderId||null,assigneeAgentId:n.assigneeAgentId||null}}t(Dt,"buildRoutineMutationPayload");function Tt(n,c,d,b,g){if(c==="none")return[{key:"__all",label:null,items:n}];if(c==="folder"){const i=he(n,o=>o.folderId??"__unfiled");return Object.keys(i).sort((o,j)=>{if(o==="__unfiled"||j==="__unfiled")return o===j?0:o==="__unfiled"?1:-1;const w=g.get(o),I=g.get(j),O=(Number.isFinite(w?.position)?w.position:Number.POSITIVE_INFINITY)-(Number.isFinite(I?.position)?I.position:Number.POSITIVE_INFINITY);return O!==0?O:(w?.name??"Unknown folder").localeCompare(I?.name??"Unknown folder",void 0,{sensitivity:"base"})||o.localeCompare(j)}).map(o=>({key:o,label:o==="__unfiled"?"Unfiled":g.get(o)?.name??"Unknown folder",items:i[o]}))}if(c==="project"){const i=he(n,o=>o.projectId??"__no_project");return Object.keys(i).sort((o,j)=>{const w=o==="__no_project"?"No project":d.get(o)?.name??"Unknown project",I=j==="__no_project"?"No project":d.get(j)?.name??"Unknown project";return w.localeCompare(I)}).map(o=>({key:o,label:o==="__no_project"?"No project":d.get(o)?.name??"Unknown project",items:i[o]}))}const x=he(n,i=>i.assigneeAgentId??"__unassigned");return Object.keys(x).sort((i,o)=>{const j=i==="__unassigned"?"Unassigned":b.get(i)?.name??"Unknown agent",w=o==="__unassigned"?"Unassigned":b.get(o)?.name??"Unknown agent";return j.localeCompare(w)}).map(i=>({key:i,label:i==="__unassigned"?"Unassigned":b.get(i)?.name??"Unknown agent",items:x[i]}))}t(Tt,"buildRoutineGroups");function is(n){return n.originKind==="built_in_agent_bundle"}t(is,"isBuiltInRoutine");function qt(n,c,d,b,g){const x=n.filter(is),i=Tt(n.filter(o=>!is(o)),c,d,b,g).filter(o=>o.items.length>0).map(o=>x.length>0&&c==="none"&&o.key==="__all"?{...o,label:"Custom routines"}:o);return x.length===0?i:[...i,{key:At,label:"Built-in routines",items:x}]}t(qt,"buildRoutineSections");function Kt(n,c,d){const b=d==="asc"?1:-1;return[...n].sort((g,x)=>{let i=0;return c==="title"?i=rs(g.title,x.title):c==="created"?i=q(g.createdAt)-q(x.createdAt):c==="lastRun"?i=q(g.lastRun?.triggeredAt??g.lastTriggeredAt)-q(x.lastRun?.triggeredAt??x.lastTriggeredAt):i=q(g.updatedAt)-q(x.updatedAt),i!==0?i*b:rs(g.title,x.title)})}t(Kt,"sortRoutines");function os(n){return n==="runs"?"/routines?tab=runs":"/routines"}t(os,"buildRoutinesTabHref");function Ut({label:n,count:c,isOpen:d}){return(0,s.jsxs)("div",{className:`flex items-center gap-2 rounded-lg border border-border px-3 py-2${d?" mb-1":""}`,children:[(0,s.jsxs)(ls,{className:"flex items-center gap-1.5",children:[(0,s.jsx)(cs,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),(0,s.jsx)("span",{className:"text-sm font-semibold uppercase tracking-wide",children:n})]}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:c})]})}t(Ut,"RoutineSectionHeader");function cn(){const{selectedCompanyId:n}=Ds(),{setBreadcrumbs:c}=st(),d=As(),b=Es(),[g,x]=Ks(),{pushToast:i}=vt(),o=(0,l.useRef)(null),j=(0,l.useRef)(null),w=(0,l.useRef)(null),I=(0,l.useRef)(null),[O,K]=(0,l.useState)(!1),[se,L]=(0,l.useState)(null),[Q,te]=(0,l.useState)(null),[ds,Ne]=(0,l.useState)(!1),[ne,re]=(0,l.useState)(!1),[B,V]=(0,l.useState)([]),[Ie,Re]=(0,l.useState)([]),[us,_e]=(0,l.useState)(null),[ms,Ce]=(0,l.useState)(null),[k,ie]=(0,l.useState)(null),[$,z]=(0,l.useState)(!1),[Se,oe]=(0,l.useState)(!1),P=g.get("tab")==="runs"?"runs":"routines",[p,R]=(0,l.useState)({title:"",description:"",projectId:"",folderId:null,assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",variables:[]}),G=n?`paperclip:routines-view:${n}`:"paperclip:routines-view",[u,Fe]=(0,l.useState)(()=>ns(G)),f=Nt(g.get("folder"));(0,l.useEffect)(()=>{c([{label:"Routines"}])},[c]),(0,l.useEffect)(()=>{Fe(ns(G))},[G]);const{data:ke,isLoading:ps,error:ae}=A({queryKey:m.routines.list(n),queryFn:t(()=>J.list(n),"queryFn"),enabled:!!n}),{data:h,isLoading:Pe}=A({queryKey:m.folders.list(n,"routine"),queryFn:t(()=>M.list(n,"routine"),"queryFn"),enabled:!!n&&P==="routines"}),{data:_}=A({queryKey:m.agents.list(n),queryFn:t(()=>Zs.list(n),"queryFn"),enabled:!!n}),{data:C}=A({queryKey:m.projects.list(n,{includeArchived:!0}),queryFn:t(()=>et.list(n,{includeArchived:!0}),"queryFn"),enabled:!!n}),{data:Ae}=A({queryKey:m.access.companyUserDirectory(n),queryFn:t(()=>ot.listUserDirectory(n),"queryFn"),enabled:!!n}),{data:le,isLoading:fs,error:gs}=A({queryKey:[...m.issues.list(n),"routine-executions"],queryFn:t(()=>ze.list(n,{originKind:"routine_execution"}),"queryFn"),enabled:!!n&&P==="runs"}),Me=m.liveRuns(n),ce=wt({companyId:n,resourceKey:"live-runs",queryKey:Me,enabled:!!n&&P==="runs",refetchInterval:!1,leaderOnly:!0}),{data:de,dataUpdatedAt:xs}=A({queryKey:Me,queryFn:t(()=>rt.liveRunsForCompany(n),"queryFn"),enabled:ce.enabled,refetchInterval:ce.refetchInterval});ft(ce,de,xs),(0,l.useEffect)(()=>{ss(j.current)},[p.title,$]);const hs=(0,l.useMemo)(()=>it({agents:_,projects:(C??[]).filter(e=>!e.archivedAt),members:Ae?.users}),[_,Ae?.users,C]),N=S({mutationFn:t(()=>J.create(n,Dt(p)),"mutationFn"),onSuccess:t(async e=>{R({title:"",description:"",projectId:"",folderId:null,assigneeAgentId:"",priority:"medium",concurrencyPolicy:"coalesce_if_active",catchUpPolicy:"skip_missed",variables:[]}),z(!1),oe(!1),await d.invalidateQueries({queryKey:m.routines.list(n)}),i({title:"Routine created",body:e.assigneeAgentId?"Add the first trigger to turn it into a live workflow.":"Draft saved. Add a default agent before enabling automation.",tone:"success"}),b(`/routines/${e.id}?tab=triggers`)},"onSuccess")}),De=S({mutationFn:t(e=>M.create(n,{kind:"routine",...e}),"mutationFn"),onSuccess:t(async e=>{if(K(!1),L(null),await d.invalidateQueries({queryKey:m.folders.list(n,"routine")}),Ie.length>0){const r=Ie;Re([]);try{await Promise.all(r.map(a=>M.moveItem(n,{kind:"routine",itemId:a,folderId:e.id}))),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})])}catch(a){i({title:"Folder created, move failed",body:a instanceof Error?a.message:"Paperclip could not move the selected routines.",tone:"error"});return}}else H(e.id);i({title:"Folder created",body:e.name,tone:"success"})},"onSuccess"),onError:t(e=>{i({title:"Failed to save folder",body:e instanceof Error?e.message:"Paperclip could not save the folder.",tone:"error"})},"onError")}),ue=S({mutationFn:t(({folderId:e,payload:r})=>M.update(n,e,r),"mutationFn"),onSuccess:t(async()=>{K(!1),L(null),await d.invalidateQueries({queryKey:m.folders.list(n,"routine")})},"onSuccess"),onError:t(e=>{i({title:"Folder save failed",body:e instanceof Error?e.message:"Paperclip could not update the folder.",tone:"error"})},"onError")}),Te=S({mutationFn:t(e=>M.delete(n,e),"mutationFn"),onSuccess:t(async(e,r)=>{f===r&&H("all"),te(null),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})]),i({title:"Folder deleted",body:"Items moved to Unfiled.",tone:"success"})},"onSuccess"),onError:t(e=>{i({title:"Folder delete failed",body:e instanceof Error?e.message:"Paperclip could not delete the folder.",tone:"error"})},"onError")}),qe=S({mutationFn:t(({itemId:e,folderId:r})=>M.moveItem(n,{kind:"routine",itemId:e,folderId:r}),"mutationFn"),onSuccess:t(async()=>{await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})])},"onSuccess"),onError:t(e=>{i({title:"Move failed",body:e instanceof Error?e.message:"Paperclip could not move the routine.",tone:"error"})},"onError")}),js=S({mutationFn:t(({id:e,data:r})=>ze.update(e,r),"mutationFn"),onSuccess:t(async()=>{await d.invalidateQueries({queryKey:[...m.issues.list(n),"routine-executions"]})},"onSuccess")}),Ke=S({mutationFn:t(({id:e,status:r})=>J.update(e,{status:r}),"mutationFn"),onMutate:t(({id:e})=>{Ce(e)},"onMutate"),onSuccess:t(async(e,r)=>{await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.routines.detail(r.id)})])},"onSuccess"),onSettled:t(()=>{Ce(null)},"onSettled"),onError:t(e=>{i({title:"Failed to update routine",body:e instanceof Error?e.message:"Paperclip could not update the routine.",tone:"error"})},"onError")}),Ue=S({mutationFn:t(({id:e,data:r})=>J.run(e,{...r?.variables&&Object.keys(r.variables).length>0?{variables:r.variables}:{},...r?.assigneeAgentId!==void 0?{assigneeAgentId:r.assigneeAgentId}:{},...r?.projectId!==void 0?{projectId:r.projectId}:{},...r?.executionWorkspaceId!==void 0?{executionWorkspaceId:r.executionWorkspaceId}:{},...r?.executionWorkspacePreference!==void 0?{executionWorkspacePreference:r.executionWorkspacePreference}:{},...r?.executionWorkspaceSettings!==void 0?{executionWorkspaceSettings:r.executionWorkspaceSettings}:{}}),"mutationFn"),onMutate:t(({id:e})=>{_e(e)},"onMutate"),onSuccess:t(async(e,{id:r})=>{ie(null),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.routines.detail(r)})])},"onSuccess"),onSettled:t(()=>{_e(null)},"onSettled"),onError:t(e=>{i({title:"Routine run failed",body:e instanceof Error?e.message:"Paperclip could not start the routine run.",tone:"error"})},"onError")}),me=(0,l.useMemo)(()=>Vs(),[$]),ys=(0,l.useMemo)(()=>Gs(),[$]),vs=(0,l.useMemo)(()=>Qs((_??[]).filter(e=>e.status!=="terminated"),me).map(e=>({id:e.id,label:e.name,searchText:`${e.name} ${e.role} ${e.title??""}`})),[_,me]),bs=(0,l.useMemo)(()=>(C??[]).filter(e=>!e.archivedAt).map(e=>({id:e.id,label:e.name,searchText:e.description??""})),[C]),U=(0,l.useMemo)(()=>new Map((_??[]).map(e=>[e.id,e])),[_]),E=(0,l.useMemo)(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),Ee=(0,l.useMemo)(()=>new Map((h?.folders??[]).map(e=>[e.id,e])),[h]),ws=(0,l.useMemo)(()=>Ls(de,le),[de,le]),y=(0,l.useMemo)(()=>(ke??[]).filter(e=>e.status!=="archived"),[ke]),Oe=(0,l.useMemo)(()=>u.groupBy!=="folder"||f==="all"?y:f==="unfiled"?y.filter(e=>!e.folderId):y.filter(e=>e.folderId===f),[f,u.groupBy,y]),pe=(0,l.useMemo)(()=>{if(!h)return h;const e=new Map;let r=0;for(const a of y)a.folderId?e.set(a.folderId,(e.get(a.folderId)??0)+1):r+=1;return{...h,allCount:y.length,unfiledCount:r,folders:h.folders.map(a=>({...a,itemCount:e.get(a.id)??0}))}},[h,y]),D=(0,l.useMemo)(()=>Kt(Oe,u.sortField,u.sortDir),[Oe,u.sortDir,u.sortField]),Ns=(0,l.useMemo)(()=>qt(D,u.groupBy,E,U,Ee),[U,Ee,E,u.groupBy,D]),Is=(0,l.useMemo)(()=>Us("Recent Runs",os("runs"),"issues"),[]),Le=p.assigneeAgentId?U.get(p.assigneeAgentId)??null:null,Qe=p.projectId?E.get(p.projectId)??null:null,Be=Rt(h?.folders??[],f),W=(h?.folders.length??0)>0,fe=P==="routines"&&u.groupBy==="folder"&&W;function ge(e){Fe(r=>{const a={...r,...e};return Mt(G,a),a})}t(ge,"updateRoutineView");function Ve(e){const r=e==="runs"?"runs":"routines";(0,l.startTransition)(()=>{b(os(r))})}t(Ve,"handleTabChange");function H(e){x(r=>{const a=new URLSearchParams(r),v=gt(e);return v?a.set("folder",v):a.delete("folder"),a})}t(H,"setFolderSelection");function T(e=[]){Re(e),L(null),K(!0)}t(T,"openCreateFolder");function $e(){R(e=>({...e,folderId:f==="all"||f==="unfiled"?null:f})),z(!0)}t($e,"openCreateRoutine");async function Rs(e){const r=B;if(r.length!==0)try{await Promise.all(r.map(a=>M.moveItem(n,{kind:"routine",itemId:a,folderId:e}))),V([]),re(!1),await Promise.all([d.invalidateQueries({queryKey:m.routines.list(n)}),d.invalidateQueries({queryKey:m.folders.list(n,"routine")})]),i({title:"Routines moved",body:`${r.length} routine${r.length===1?"":"s"} filed.`,tone:"success"})}catch(a){i({title:"Failed to move routines",body:a instanceof Error?a.message:"Paperclip could not move the selected routines.",tone:"error"})}}t(Rs,"moveSelectedRoutines");function _s(e){ie(e)}t(_s,"handleRunNow");function Cs(e,r){if(!r&&!e.assigneeAgentId){i({title:"Default agent required",body:"Set a default agent before enabling routine automation.",tone:"warn"});return}Ke.mutate({id:e.id,status:ht(e.status,!r)})}t(Cs,"handleToggleEnabled");function Ss(e){Ke.mutate({id:e.id,status:e.status==="archived"?"active":"archived"})}return t(Ss,"handleToggleArchived"),n?ps?(0,s.jsx)(ct,{variant:"issues-list"}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",children:"Routines"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Recurring work definitions that materialize into auditable execution tasks."})]}),(0,s.jsxs)(F,{onClick:$e,children:[(0,s.jsx)(Z,{className:"mr-2 h-4 w-4"}),"Create routine"]})]}),(0,s.jsxs)(Xs,{value:P,onValueChange:Ve,children:[(0,s.jsx)(_t,{align:"start",value:P,onValueChange:Ve,items:[{value:"routines",label:"Routines"},{value:"runs",label:"Recent Runs"}]}),(0,s.jsxs)(Je,{value:"routines",className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[y.length," routine",y.length===1?"":"s"]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsxs)(Xe,{children:[(0,s.jsx)(Ze,{asChild:!0,children:(0,s.jsxs)(F,{variant:"ghost",size:"sm",className:"text-xs",title:"Sort",children:[(0,s.jsx)(Bs,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Sort"})]})}),(0,s.jsx)(es,{align:"end",className:"w-44 p-0",children:(0,s.jsx)("div",{className:"p-2 space-y-0.5",children:[["updated","Updated"],["created","Created"],["lastRun","Last run"],["title","Title"]].map(([e,r])=>(0,s.jsxs)("button",{className:`flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm ${u.sortField===e?"bg-accent/50 text-foreground":"text-muted-foreground hover:bg-accent/50"}`,onClick:t(()=>{ge(u.sortField===e?{sortDir:u.sortDir==="asc"?"desc":"asc"}:{sortField:e,sortDir:e==="title"?"asc":"desc"})},"onClick"),children:[(0,s.jsx)("span",{children:r}),u.sortField===e?(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:u.sortDir==="asc"?"Asc":"Desc"}):null]},e))})})]}),(0,s.jsxs)(Xe,{children:[(0,s.jsx)(Ze,{asChild:!0,children:(0,s.jsxs)(F,{variant:"ghost",size:"sm",className:"text-xs",title:"Group",children:[(0,s.jsx)(qs,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Group"})]})}),(0,s.jsx)(es,{align:"end",className:"w-44 p-0",children:(0,s.jsx)("div",{className:"p-2 space-y-0.5",children:[["folder","Folder"],["project","Project"],["assignee","Agent"],["none","None"]].map(([e,r])=>(0,s.jsxs)("button",{className:`flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm ${u.groupBy===e?"bg-accent/50 text-foreground":"text-muted-foreground hover:bg-accent/50"}`,onClick:t(()=>ge({groupBy:e,collapsedGroups:[]}),"onClick"),children:[(0,s.jsx)("span",{children:r}),u.groupBy===e?(0,s.jsx)(tt,{className:"h-3.5 w-3.5"}):null]},e))})})]}),u.groupBy==="folder"&&!W?(0,s.jsxs)(F,{variant:"outline",size:"sm",onClick:t(()=>T(),"onClick"),children:[(0,s.jsx)(Z,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}):null,fe?(0,s.jsx)(F,{variant:"ghost",size:"sm",className:"text-xs",onClick:t(()=>re(e=>!e),"onClick"),children:ne?"Done":"Select"}):null]})]}),u.groupBy==="folder"?(0,s.jsx)("div",{className:"md:hidden",children:(0,s.jsx)(dt,{result:pe,selection:f,allLabel:"All routines",onClick:t(()=>Ne(!0),"onClick")})}):null]}),(0,s.jsx)(Je,{value:"runs",children:(0,s.jsx)($s,{issues:le??[],isLoading:fs,error:gs,agents:_,projects:C,liveIssueIds:ws,viewStateKey:"paperclip:routine-recent-runs-view",issueLinkState:Is,onUpdateIssue:t((e,r)=>js.mutate({id:e,data:r}),"onUpdateIssue")})})]}),(0,s.jsx)(Js,{open:$,onOpenChange:t(e=>{N.isPending||z(e)},"onOpenChange"),children:(0,s.jsxs)(Ys,{showCloseButton:!1,className:"flex max-h-(--sz-calc-18) max-w-3xl flex-col gap-0 overflow-hidden p-0",children:[(0,s.jsxs)("div",{className:"shrink-0 flex flex-wrap items-center justify-between gap-3 border-b border-border/60 px-5 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"New routine"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Define the recurring work first. Default project and agent are optional for draft routines."})]}),(0,s.jsx)(F,{variant:"ghost",size:"sm",onClick:t(()=>{z(!1),oe(!1)},"onClick"),disabled:N.isPending,children:"Cancel"})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,s.jsx)("div",{className:"px-5 pt-5 pb-3",children:(0,s.jsx)("textarea",{ref:j,className:"w-full resize-none overflow-hidden bg-transparent text-xl font-semibold outline-none placeholder:text-muted-foreground/50",placeholder:"Routine title",rows:1,value:p.title,onChange:t(e=>{R(r=>({...r,title:e.target.value})),ss(e.target)},"onChange"),onKeyDown:t(e=>{if(e.key==="Enter"&&!e.metaKey&&!e.ctrlKey&&!e.nativeEvent.isComposing){e.preventDefault(),o.current?.focus();return}e.key==="Tab"&&!e.shiftKey&&(e.preventDefault(),p.assigneeAgentId?p.projectId?o.current?.focus():I.current?.focus():w.current?.focus())},"onKeyDown"),autoFocus:!0})}),(0,s.jsx)("div",{className:"px-5 pb-3",children:(0,s.jsx)("div",{className:"overflow-x-auto overscroll-x-contain",children:(0,s.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,s.jsx)("span",{children:"For"}),(0,s.jsx)(Ge,{ref:w,value:p.assigneeAgentId,options:vs,recentOptionIds:me,placeholder:"Responsible",noneLabel:"No responsible",searchPlaceholder:"Search responsible...",emptyMessage:"No responsible found.",onChange:t(e=>{e&&Os(e),R(r=>({...r,assigneeAgentId:e}))},"onChange"),onConfirm:t(()=>{p.projectId?o.current?.focus():I.current?.focus()},"onConfirm"),renderTriggerValue:t(e=>e?Le?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ye,{agent:Le,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("span",{className:"truncate",children:e.label})]}):(0,s.jsx)("span",{className:"truncate",children:e.label}):(0,s.jsx)("span",{className:"text-muted-foreground",children:"Responsible"}),"renderTriggerValue"),renderOption:t(e=>{if(!e.id)return(0,s.jsx)("span",{className:"truncate",children:e.label});const r=U.get(e.id);return(0,s.jsxs)(s.Fragment,{children:[r?(0,s.jsx)(Ye,{agent:r,size:16,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,(0,s.jsx)("span",{className:"truncate",children:e.label})]})},"renderOption")}),(0,s.jsx)("span",{children:"in"}),(0,s.jsx)(Ge,{ref:I,value:p.projectId,options:bs,recentOptionIds:ys,placeholder:"Project",noneLabel:"No project",searchPlaceholder:"Search projects...",emptyMessage:"No projects found.",onChange:t(e=>{e&&Ws(e),R(r=>({...r,projectId:e}))},"onChange"),onConfirm:t(()=>o.current?.focus(),"onConfirm"),renderTriggerValue:t(e=>e&&Qe?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:Qe.color??"var(--project-none)"}}),(0,s.jsx)("span",{className:"truncate",children:e.label})]}):(0,s.jsx)("span",{className:"text-muted-foreground",children:"Project"}),"renderTriggerValue"),renderOption:t(e=>{if(!e.id)return(0,s.jsx)("span",{className:"truncate",children:e.label});const r=E.get(e.id);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"h-3.5 w-3.5 shrink-0 rounded-sm",style:{backgroundColor:r?.color??"var(--project-none)"}}),(0,s.jsx)("span",{className:"truncate",children:e.label})]})},"renderOption")}),(0,s.jsx)("span",{children:"filed in"}),(0,s.jsxs)(we,{value:p.folderId??"__unfiled",onValueChange:t(e=>R(r=>({...r,folderId:e==="__unfiled"?null:e})),"onValueChange"),children:[(0,s.jsx)(be,{className:"h-8 w-auto min-w-32 border-0 bg-muted/50 px-2 shadow-none",children:(0,s.jsx)(ye,{})}),(0,s.jsxs)(ve,{children:[(0,s.jsx)(X,{value:"__unfiled",children:"Unfiled"}),(h?.folders??[]).map(e=>(0,s.jsx)(X,{value:e.id,children:e.name},e.id))]})]})]})})}),(0,s.jsx)("div",{className:"border-t border-border/60 px-5 py-4",children:(0,s.jsx)(Hs,{ref:o,value:p.description,onChange:t(e=>R(r=>({...r,description:e})),"onChange"),placeholder:"Add instructions...",bordered:!1,contentClassName:"min-h-(--sz-160px) text-sm text-muted-foreground",mentions:hs,onSubmit:t(()=>{!N.isPending&&p.title.trim()&&p.projectId&&p.assigneeAgentId&&N.mutate()},"onSubmit")})}),(0,s.jsx)("div",{className:"border-t border-border/60 px-5 py-3",children:(0,s.jsxs)(We,{open:Se,onOpenChange:oe,children:[(0,s.jsxs)(ls,{className:"flex w-full items-center justify-between text-left",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"Advanced delivery settings"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Keep policy controls secondary to the work definition."})]}),Se?(0,s.jsx)(nt,{className:"h-4 w-4 text-muted-foreground"}):(0,s.jsx)(cs,{className:"h-4 w-4 text-muted-foreground"})]}),(0,s.jsx)(He,{className:"pt-3",children:(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"Concurrency"}),(0,s.jsxs)(we,{value:p.concurrencyPolicy,onValueChange:t(e=>R(r=>({...r,concurrencyPolicy:e})),"onValueChange"),children:[(0,s.jsx)(be,{children:(0,s.jsx)(ye,{})}),(0,s.jsx)(ve,{children:St.map(e=>(0,s.jsx)(X,{value:e,children:e.replaceAll("_"," ")},e))})]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:kt[p.concurrencyPolicy]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-xs font-medium uppercase tracking-(--tracking-caps) text-muted-foreground",children:"Catch-up"}),(0,s.jsxs)(we,{value:p.catchUpPolicy,onValueChange:t(e=>R(r=>({...r,catchUpPolicy:e})),"onValueChange"),children:[(0,s.jsx)(be,{children:(0,s.jsx)(ye,{})}),(0,s.jsx)(ve,{children:Ft.map(e=>(0,s.jsx)(X,{value:e,children:e.replaceAll("_"," ")},e))})]}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:Pt[p.catchUpPolicy]})]})]})})]})})]}),(0,s.jsxs)("div",{className:"shrink-0 flex flex-col gap-3 border-t border-border/60 px-5 py-4 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsx)("div",{className:"text-sm text-muted-foreground",children:"After creation, Paperclip takes you straight to trigger setup. Draft routines stay paused until you add a default agent."}),(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:items-end",children:[(0,s.jsxs)(F,{onClick:t(()=>N.mutate(),"onClick"),disabled:N.isPending||!p.title.trim(),children:[(0,s.jsx)(Z,{className:"mr-2 h-4 w-4"}),N.isPending?"Creating...":"Create routine"]}),N.isError?(0,s.jsx)("p",{className:"text-sm text-destructive",children:N.error instanceof Error?N.error.message:"Failed to create routine"}):null]})]})]})}),ae?(0,s.jsx)(lt,{children:(0,s.jsx)(at,{className:"pt-6 text-sm text-destructive",children:ae instanceof Error?ae.message:"Failed to load routines"})}):null,P==="routines"?(0,s.jsxs)("div",{className:Ms(fe&&"flex gap-4"),children:[fe?(0,s.jsx)(Ct,{result:pe,selection:f,allLabel:"All routines",itemLabelPlural:"routines",loading:Pe,onSelect:H,onCreate:t(()=>T(),"onCreate"),onRename:t((e,r)=>ue.mutate({folderId:e.id,payload:{name:r}}),"onRename"),onEdit:t(e=>{L(e),K(!0)},"onEdit"),onDelete:te}):null,(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[u.groupBy==="folder"&&W?(0,s.jsx)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:f==="all"?(0,s.jsx)(Et,{label:"All routines",count:D.length}):(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,s.jsx)(bt,{color:Be?.color}),(0,s.jsx)("span",{className:"truncate font-medium",children:f==="unfiled"?"Unfiled":Be?.name??"Folder"}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[D.length," routine",D.length===1?"":"s"]})]})}):null,u.groupBy==="folder"&&!W&&!Pe&&y.length>0?(0,s.jsx)(mt,{storageKey:`paperclip:routines-folder-nudge:${n??"none"}`,itemLabelPlural:"routines",onCreateFolder:t(()=>T(),"onCreateFolder")}):null,ne?(0,s.jsx)(pt,{selectedCount:B.length,folders:h?.folders??[],onMove:t(e=>{Rs(e)},"onMove"),onCreateAndMove:t(()=>T(B),"onCreateAndMove"),onClear:t(()=>V([]),"onClear"),onDone:t(()=>{re(!1),V([])},"onDone")}):null,y.length===0?(0,s.jsx)("div",{className:"py-12",children:(0,s.jsx)(je,{icon:ee,message:"No active routines. Use Create routine to define the first recurring workflow."})}):D.length===0?(0,s.jsxs)("div",{className:"py-12",children:[(0,s.jsx)(je,{icon:ee,message:f==="all"?"No routines match this view.":"This folder is empty."}),f!=="all"?(0,s.jsx)("div",{className:"mt-3 flex justify-center",children:(0,s.jsxs)(F,{size:"sm",onClick:$e,children:[(0,s.jsx)(Z,{className:"mr-2 h-3.5 w-3.5"}),"New routine in this folder"]})}):null]}):(0,s.jsx)("div",{className:"flex flex-col gap-3",children:Ns.map(e=>{const r=!u.collapsedGroups.includes(e.key);return(0,s.jsxs)(We,{open:r,onOpenChange:t(a=>{ge({collapsedGroups:a?u.collapsedGroups.filter(v=>v!==e.key):[...u.collapsedGroups,e.key]})},"onOpenChange"),children:[e.label?(0,s.jsx)(Ut,{label:e.label,count:e.items.length,isOpen:r}):null,(0,s.jsx)(He,{children:e.items.map(a=>(0,s.jsx)(jt,{routine:a,projectById:E,agentById:U,runningRoutineId:us,statusMutationRoutineId:ms,href:`/routines/${a.id}`,runNowButton:!0,divider:!1,onRunNow:_s,onToggleEnabled:Cs,onToggleArchived:Ss,selectMode:ne,selected:B.includes(a.id),onSelectChange:t((v,xe)=>{V(Y=>xe?Array.from(new Set([...Y,v.id])):Y.filter(Fs=>Fs!==v.id))},"onSelectChange"),extraMenuItems:(0,s.jsx)(yt,{folders:h?.folders??[],currentFolderId:a.folderId??null,onMove:t(v=>{const xe=a.folderId??null;qe.mutate({itemId:a.id,folderId:v}),i({title:"Routine moved",body:v?`Moved "${a.title}" to ${h?.folders.find(Y=>Y.id===v)?.name??"folder"}.`:`Moved "${a.title}" to Unfiled.`,tone:"success",action:{label:"Undo",onClick:t(()=>qe.mutate({itemId:a.id,folderId:xe}),"onClick")}})},"onMove"),onCreateAndMove:t(()=>T([a.id]),"onCreateAndMove")})},a.id))})]},e.key)})})]})]}):null,(0,s.jsx)(xt,{open:O,kind:"routine",folder:se,pending:De.isPending||ue.isPending,onOpenChange:K,onSubmit:t(e=>{se?ue.mutate({folderId:se.id,payload:e}):De.mutate(e)},"onSubmit")}),(0,s.jsx)(ut,{open:Q!==null,folder:Q,itemLabelPlural:"routines",pending:Te.isPending,onOpenChange:t(e=>{e||te(null)},"onOpenChange"),onConfirm:t(()=>{Q&&Te.mutate(Q.id)},"onConfirm")}),(0,s.jsx)(It,{open:ds,onOpenChange:Ne,result:pe,selection:f,allLabel:"All routines",itemLabelPlural:"Routines",onSelect:H,onCreate:t(()=>T(),"onCreate")}),(0,s.jsx)(zs,{open:k!==null,onOpenChange:t(e=>{e||ie(null)},"onOpenChange"),companyId:n,routineName:k?.title??null,agents:_??[],projects:C??[],defaultProjectId:k?.projectId??null,defaultAssigneeAgentId:k?.assigneeAgentId??null,variables:k?.variables??[],isPending:Ue.isPending,onSubmit:t(e=>{k&&Ue.mutate({id:k.id,data:e})},"onSubmit")})]}):(0,s.jsx)(je,{icon:ee,message:"Select a company to view routines."})}t(cn,"Routines");function Et({label:n,count:c}){return(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-2 text-sm",children:[(0,s.jsx)(ee,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,s.jsx)("span",{className:"truncate font-medium",children:n}),(0,s.jsxs)("span",{className:"text-muted-foreground",children:[c," routine",c===1?"":"s"]})]})}t(Et,"FolderIconHeader");export{cn as Routines};