@sentry/junior-dashboard 0.280.0 → 0.281.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/app.js +23 -30
  2. package/dist/client-manifest.json +1 -1
  3. package/dist/index.js +23 -30
  4. package/dist/public/chunks/{AdminPage-YEKZOKH6.js → AdminPage-M5RBVZFN.js} +1 -1
  5. package/dist/public/chunks/{AutomationPage-5GS3IUAK.js → AutomationPage-WALCREDT.js} +1 -1
  6. package/dist/public/chunks/{AutomationRunsPage-IPYEZU4L.js → AutomationRunsPage-CV47E4UX.js} +1 -1
  7. package/dist/public/chunks/{AutomationsPage-HSAYPC3C.js → AutomationsPage-57L3AQVJ.js} +1 -1
  8. package/dist/public/chunks/{CodePage-IPFKXWFB.js → CodePage-XJUYMFJH.js} +1 -1
  9. package/dist/public/chunks/{ConnectionsPage-5XUEK6FS.js → ConnectionsPage-3QQAGYWF.js} +1 -1
  10. package/dist/public/chunks/{LocationDetailPage-27ETUGR6.js → LocationDetailPage-4IL5HQML.js} +1 -1
  11. package/dist/public/chunks/{LocationsPage-WOKMQAGM.js → LocationsPage-D2DUQAHJ.js} +1 -1
  12. package/dist/public/chunks/{PeoplePage-6YQLDOUL.js → PeoplePage-6F5GPQ7C.js} +1 -1
  13. package/dist/public/chunks/{PersonProfilePage-GYMAZFIK.js → PersonProfilePage-SPAYQPTD.js} +1 -1
  14. package/dist/public/chunks/{PersonalTokensPage-4BCR744B.js → PersonalTokensPage-SHAUJ74M.js} +1 -1
  15. package/dist/public/chunks/{PluginUserPage-IP6WL7MD.js → PluginUserPage-64FIWD7M.js} +1 -1
  16. package/dist/public/chunks/{RepositoryPage-TRD44LQ3.js → RepositoryPage-L7IHOXSN.js} +1 -1
  17. package/dist/public/chunks/{SettingsPage-4E3SLQ36.js → SettingsPage-U7WG4FHE.js} +1 -1
  18. package/dist/public/chunks/{SystemPage-C3XBKXKW.js → SystemPage-ZBC43OJH.js} +1 -1
  19. package/dist/public/chunks/{WorkspaceFormPage-2LS2X67Q.js → WorkspaceFormPage-3NVIIZ4P.js} +1 -1
  20. package/dist/public/chunks/{WorkspacesPage-5WB3CUTX.js → WorkspacesPage-G73HPBDD.js} +1 -1
  21. package/dist/public/chunks/{chunk-VFEBNOPX.js → chunk-2J3LGF5Q.js} +1 -1
  22. package/dist/public/chunks/chunk-2NNKHSZE.js +1 -0
  23. package/dist/public/chunks/chunk-4TQSTCIN.js +13 -0
  24. package/dist/public/chunks/chunk-64GPEGGE.js +1 -0
  25. package/dist/public/chunks/{chunk-WZVO3HG4.js → chunk-6FHY65EQ.js} +1 -1
  26. package/dist/public/chunks/{chunk-YYNMZ4WC.js → chunk-DEEO4D4N.js} +1 -1
  27. package/dist/public/chunks/{chunk-SDKV3OID.js → chunk-FSGVY7HB.js} +1 -1
  28. package/dist/public/chunks/chunk-GZBMHYYU.js +1 -0
  29. package/dist/public/chunks/{chunk-NQMDED2R.js → chunk-II4NXLSQ.js} +1 -1
  30. package/dist/public/chunks/{chunk-B6HGRBBX.js → chunk-ILH47V7O.js} +1 -1
  31. package/dist/public/chunks/{chunk-GRMX2HX6.js → chunk-JPL2NRWK.js} +1 -1
  32. package/dist/public/chunks/{chunk-NQOJAZFQ.js → chunk-JVJ5UWIK.js} +1 -1
  33. package/dist/public/chunks/{chunk-V5UDSIRA.js → chunk-K4TYMAA3.js} +1 -1
  34. package/dist/public/chunks/{chunk-EFEREKX4.js → chunk-KDUTK357.js} +1 -1
  35. package/dist/public/chunks/{chunk-RHIXHBS5.js → chunk-LZYAHJVQ.js} +1 -1
  36. package/dist/public/chunks/{chunk-5GZDBGAR.js → chunk-MKKFXRYO.js} +1 -1
  37. package/dist/public/chunks/{chunk-PEQNT5MO.js → chunk-NGQRNS3C.js} +1 -1
  38. package/dist/public/chunks/{chunk-IA6BJDKN.js → chunk-ONDKE72P.js} +1 -1
  39. package/dist/public/chunks/{chunk-WJ3OXMVX.js → chunk-PG7M7L24.js} +1 -1
  40. package/dist/public/chunks/{chunk-6GQL3EVJ.js → chunk-QQUFROWT.js} +1 -1
  41. package/dist/public/chunks/{chunk-UAH6DWNS.js → chunk-RB5FBDEY.js} +1 -1
  42. package/dist/public/chunks/{chunk-A2QWWA7O.js → chunk-RGXXD4DM.js} +1 -1
  43. package/dist/public/chunks/{chunk-AYXSBMWA.js → chunk-TC7TU4GK.js} +1 -1
  44. package/dist/public/chunks/chunk-WLIOZO3W.js +1 -0
  45. package/dist/public/chunks/{chunk-VXT3FIVL.js → chunk-XDUSY26N.js} +11 -11
  46. package/dist/public/client-4OAAOHF4.js +68 -0
  47. package/dist/tailwind.css +1 -1
  48. package/package.json +4 -4
  49. package/src/client/components/BottomSheet.tsx +1 -1
  50. package/src/client/components/DetailsPanel.tsx +2 -1
  51. package/src/client/conversations/ConversationBrief.tsx +129 -65
  52. package/src/client/conversations/ConversationDetails.tsx +13 -14
  53. package/src/client/conversations/ConversationEventLog.tsx +20 -97
  54. package/src/client/conversations/ConversationHeader.tsx +41 -26
  55. package/src/client/conversations/ConversationHeaderActions.tsx +3 -1
  56. package/src/client/conversations/ConversationLinkedWork.tsx +30 -10
  57. package/src/client/conversations/ConversationMeta.tsx +15 -15
  58. package/src/client/conversations/ConversationPage.tsx +31 -7
  59. package/src/client/conversations/ConversationTranscript.tsx +234 -186
  60. package/src/client/conversations/ConversationUsageBreakdown.tsx +142 -64
  61. package/src/client/conversations/DetailsList.tsx +7 -1
  62. package/src/client/conversations/PendingMailboxStack.tsx +88 -44
  63. package/src/client/conversations/TranscriptActivityGroup.tsx +7 -14
  64. package/src/client/conversations/TranscriptEventView.tsx +7 -3
  65. package/src/client/conversations/TranscriptReasoningView.tsx +4 -2
  66. package/src/client/conversations/TranscriptRows.tsx +37 -5
  67. package/src/client/conversations/TranscriptView.tsx +4 -0
  68. package/src/client/conversations/queries.ts +74 -43
  69. package/src/client/conversations/transcriptBottomPinning.ts +13 -5
  70. package/src/client/conversations/transcriptListRows.ts +215 -0
  71. package/src/client/conversations/virtualRows.ts +168 -0
  72. package/src/client/http.ts +6 -5
  73. package/src/client/sentry.ts +53 -3
  74. package/src/conversation-cache.ts +8 -10
  75. package/src/mock-reporting/fixtures.ts +0 -8
  76. package/dist/public/chunks/chunk-GO45RQDL.js +0 -1
  77. package/dist/public/chunks/chunk-N4AONKD3.js +0 -1
  78. package/dist/public/chunks/chunk-QNA7F7QB.js +0 -1
  79. package/dist/public/chunks/chunk-R4ORRE77.js +0 -1
  80. package/dist/public/chunks/chunk-Z2JPRGFT.js +0 -1
  81. package/dist/public/client-TYC7JKRE.js +0 -91
@@ -1 +1 @@
1
- import{a as T}from"./chunk-UK2V4UBT.js";import{a as B}from"./chunk-XNR4RZEC.js";import{a as g}from"./chunk-2BCS5AQL.js";import{g as I}from"./chunk-NQMDED2R.js";import"./chunk-MTBUV2GJ.js";import{d as x,g as N,i as h,n as R,q as z,r as E}from"./chunk-GO45RQDL.js";import{Aa as k,Ba as $,Ja as c,za as P}from"./chunk-VXT3FIVL.js";import{M as D,o as S,s as L}from"./chunk-6PHJZPWD.js";import{b as v}from"./chunk-CR2ICLSH.js";import{Pb as w,Sc as Q,b as l,cb as A,kb as C}from"./chunk-YPMUHXYT.js";import{c as m}from"./chunk-7SZRL6FY.js";var n=m(l(),1),O=["dashboard","service-accounts"];function F(i){return`/api/service-accounts/${encodeURIComponent(i)}`}function U(){return N({queryKey:O,queryFn:({signal:i})=>E(P,"/api/service-accounts",i),refetchOnWindowFocus:!0,retry:!1})}function K(i){let o=i.userOAuth?`People who have not connected their own ${i.displayName} account use this account.`:`Everyone uses this account. People cannot connect their own ${i.displayName} account.`;return i.connected?`Connected by ${i.connectedBy??"the CLI"} ${I(i.connectedAt)}. ${o}`:`Not connected.${i.userOAuth?"":` ${i.displayName} is not available until you connect it.`} ${o} Sign in as the shared account, not as yourself.`}function q(i){let{accountsQuery:o}=i,d=x(),r=h({mutationFn:e=>R(k,F(e.provider),{}),onSuccess:({authorizationUrl:e},{popup:a})=>{if(!a){window.location.assign(e);return}a.closed||(a.opener=null,a.location.href=e)},onError:(e,{popup:a})=>{a?.close()}}),s=h({mutationFn:e=>z($,F(e.provider)),onSuccess:()=>d.invalidateQueries({queryKey:O})}),f=o.data?.serviceAccounts??[];if(o.isSuccess&&f.length===0)return null;let y=r.isPending||s.isPending,u=r.isPending?r.variables?.provider:s.isPending?s.variables?.provider:void 0,p=!o.data&&o.isError,b=r.isError?"Could not start the sign-in. Try again.":s.isError?"Could not disconnect the account. Try again.":p?"Could not load service accounts. Try again.":void 0;return(0,n.jsxs)(c,{as:"section",padding:"md",children:[(0,n.jsx)("h2",{className:"m-0 font-display text-base font-medium text-dashboard-text",children:"Service accounts"}),(0,n.jsxs)("p",{className:"mt-1 mb-4 text-sm text-dashboard-text-muted",children:["A shared account that Junior uses for a plugin. It can do only what its plugin allows, usually read. Everyone who can talk to"," ",L()," can use it, so give it only access that all of them may have."]}),b?(0,n.jsx)(B,{className:p?void 0:"mb-4",children:b}):null,p?null:o.isPending?(0,n.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"Loading service accounts\u2026"}):(0,n.jsx)("div",{className:"space-y-2",children:f.map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-dashboard-border-strong p-3",children:[(0,n.jsx)(w,{"aria-hidden":"true",className:"shrink-0 text-dashboard-accent",size:16}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"m-0 truncate text-sm font-semibold",children:e.displayName}),(0,n.jsx)(g,{size:"compact",tone:e.connected?"success":e.userOAuth?"neutral":"warning",children:e.connected?"connected":"not connected"}),e.userOAuth?null:(0,n.jsx)(g,{size:"compact",tone:"neutral",children:"shared only"})]}),(0,n.jsx)("p",{className:"mt-1 mb-0 break-words text-xs text-dashboard-text-muted",children:K(e)}),(0,n.jsx)("p",{className:"mt-1 mb-0 break-words font-mono text-xs text-dashboard-text-faint",children:e.tools.join(", ")})]}),e.connected?(0,n.jsx)(v,{"aria-busy":s.isPending&&u===e.provider,"aria-label":`Disconnect the ${e.displayName} service account`,disabled:y,onClick:()=>{r.reset(),s.mutate(e)},variant:"danger",children:"Disconnect"}):null,(0,n.jsx)(v,{"aria-busy":r.isPending&&u===e.provider,"aria-label":`${e.connected?"Reconnect":"Connect"} the ${e.displayName} service account`,disabled:y,onClick:()=>{s.reset();let a=window.open("about:blank","_blank");r.mutate({provider:e.provider,popup:a})},children:r.isPending&&u===e.provider?"Connecting\u2026":e.connected?"Reconnect":"Connect"})]},e.provider))})]})}var t=m(l(),1);function ae(i){let o=i.pages.filter(s=>s.navigation==="admin"),d=U(),r=o.length===0&&d.data?.serviceAccounts.length===0;return(0,t.jsx)("div",{className:`${Q} px-4 py-8 md:px-8`,children:(0,t.jsxs)("section",{className:"mx-auto grid w-full max-w-3xl gap-6",children:[(0,t.jsx)(D,{description:(0,t.jsxs)(t.Fragment,{children:["Setup that only Junior admins can see. Change who is an admin with"," ",(0,t.jsx)("code",{children:"junior admin grant <email>"})," and"," ",(0,t.jsx)("code",{children:"junior admin revoke <email>"}),"."]}),title:"Admin"}),(0,t.jsx)(q,{accountsQuery:d}),r?(0,t.jsx)(c,{padding:"md",children:(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsx)("div",{className:"grid size-10 shrink-0 place-items-center rounded-md border border-dashboard-border bg-dashboard-fill-soft text-dashboard-text-muted",children:(0,t.jsx)(A,{"aria-hidden":"true",size:17})}),(0,t.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No plugin has admin setup."})]})}):o.length===0?null:(0,t.jsx)("div",{className:"grid gap-3",children:o.map(s=>(0,t.jsx)(S,{className:"no-underline",to:T(s.pluginName,s.id),children:(0,t.jsx)(c,{padding:"md",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"font-sans font-medium text-xs text-dashboard-text-muted",children:s.pluginDisplayName}),(0,t.jsx)("h2",{className:"mt-1 mb-0 font-display text-base font-medium text-dashboard-text",children:s.label}),(0,t.jsx)("p",{className:"mt-1 mb-0 text-sm text-dashboard-text-muted",children:s.description})]}),(0,t.jsx)(C,{"aria-hidden":"true",className:"shrink-0 text-dashboard-text-muted",size:16})]})})},`${s.pluginName}:${s.id}`))})]})})}export{ae as AdminPage};
1
+ import{a as T}from"./chunk-UK2V4UBT.js";import{a as B}from"./chunk-XNR4RZEC.js";import{a as g}from"./chunk-2BCS5AQL.js";import{g as I}from"./chunk-II4NXLSQ.js";import"./chunk-MTBUV2GJ.js";import{d as x,g as N,i as h,r as R,u as z,v as E}from"./chunk-4TQSTCIN.js";import{Aa as P,Ba as k,Ca as $,Ka as c}from"./chunk-XDUSY26N.js";import{M as D,o as S,s as L}from"./chunk-6PHJZPWD.js";import{b as v}from"./chunk-CR2ICLSH.js";import{Pb as w,Sc as Q,b as l,cb as A,kb as C}from"./chunk-YPMUHXYT.js";import{c as m}from"./chunk-7SZRL6FY.js";var n=m(l(),1),O=["dashboard","service-accounts"];function F(i){return`/api/service-accounts/${encodeURIComponent(i)}`}function U(){return N({queryKey:O,queryFn:({signal:i})=>E(P,"/api/service-accounts",i),refetchOnWindowFocus:!0,retry:!1})}function K(i){let o=i.userOAuth?`People who have not connected their own ${i.displayName} account use this account.`:`Everyone uses this account. People cannot connect their own ${i.displayName} account.`;return i.connected?`Connected by ${i.connectedBy??"the CLI"} ${I(i.connectedAt)}. ${o}`:`Not connected.${i.userOAuth?"":` ${i.displayName} is not available until you connect it.`} ${o} Sign in as the shared account, not as yourself.`}function q(i){let{accountsQuery:o}=i,d=x(),r=h({mutationFn:e=>R(k,F(e.provider),{}),onSuccess:({authorizationUrl:e},{popup:a})=>{if(!a){window.location.assign(e);return}a.closed||(a.opener=null,a.location.href=e)},onError:(e,{popup:a})=>{a?.close()}}),s=h({mutationFn:e=>z($,F(e.provider)),onSuccess:()=>d.invalidateQueries({queryKey:O})}),f=o.data?.serviceAccounts??[];if(o.isSuccess&&f.length===0)return null;let y=r.isPending||s.isPending,u=r.isPending?r.variables?.provider:s.isPending?s.variables?.provider:void 0,p=!o.data&&o.isError,b=r.isError?"Could not start the sign-in. Try again.":s.isError?"Could not disconnect the account. Try again.":p?"Could not load service accounts. Try again.":void 0;return(0,n.jsxs)(c,{as:"section",padding:"md",children:[(0,n.jsx)("h2",{className:"m-0 font-display text-base font-medium text-dashboard-text",children:"Service accounts"}),(0,n.jsxs)("p",{className:"mt-1 mb-4 text-sm text-dashboard-text-muted",children:["A shared account that Junior uses for a plugin. It can do only what its plugin allows, usually read. Everyone who can talk to"," ",L()," can use it, so give it only access that all of them may have."]}),b?(0,n.jsx)(B,{className:p?void 0:"mb-4",children:b}):null,p?null:o.isPending?(0,n.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"Loading service accounts\u2026"}):(0,n.jsx)("div",{className:"space-y-2",children:f.map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-dashboard-border-strong p-3",children:[(0,n.jsx)(w,{"aria-hidden":"true",className:"shrink-0 text-dashboard-accent",size:16}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"m-0 truncate text-sm font-semibold",children:e.displayName}),(0,n.jsx)(g,{size:"compact",tone:e.connected?"success":e.userOAuth?"neutral":"warning",children:e.connected?"connected":"not connected"}),e.userOAuth?null:(0,n.jsx)(g,{size:"compact",tone:"neutral",children:"shared only"})]}),(0,n.jsx)("p",{className:"mt-1 mb-0 break-words text-xs text-dashboard-text-muted",children:K(e)}),(0,n.jsx)("p",{className:"mt-1 mb-0 break-words font-mono text-xs text-dashboard-text-faint",children:e.tools.join(", ")})]}),e.connected?(0,n.jsx)(v,{"aria-busy":s.isPending&&u===e.provider,"aria-label":`Disconnect the ${e.displayName} service account`,disabled:y,onClick:()=>{r.reset(),s.mutate(e)},variant:"danger",children:"Disconnect"}):null,(0,n.jsx)(v,{"aria-busy":r.isPending&&u===e.provider,"aria-label":`${e.connected?"Reconnect":"Connect"} the ${e.displayName} service account`,disabled:y,onClick:()=>{s.reset();let a=window.open("about:blank","_blank");r.mutate({provider:e.provider,popup:a})},children:r.isPending&&u===e.provider?"Connecting\u2026":e.connected?"Reconnect":"Connect"})]},e.provider))})]})}var t=m(l(),1);function ae(i){let o=i.pages.filter(s=>s.navigation==="admin"),d=U(),r=o.length===0&&d.data?.serviceAccounts.length===0;return(0,t.jsx)("div",{className:`${Q} px-4 py-8 md:px-8`,children:(0,t.jsxs)("section",{className:"mx-auto grid w-full max-w-3xl gap-6",children:[(0,t.jsx)(D,{description:(0,t.jsxs)(t.Fragment,{children:["Setup that only Junior admins can see. Change who is an admin with"," ",(0,t.jsx)("code",{children:"junior admin grant <email>"})," and"," ",(0,t.jsx)("code",{children:"junior admin revoke <email>"}),"."]}),title:"Admin"}),(0,t.jsx)(q,{accountsQuery:d}),r?(0,t.jsx)(c,{padding:"md",children:(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsx)("div",{className:"grid size-10 shrink-0 place-items-center rounded-md border border-dashboard-border bg-dashboard-fill-soft text-dashboard-text-muted",children:(0,t.jsx)(A,{"aria-hidden":"true",size:17})}),(0,t.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No plugin has admin setup."})]})}):o.length===0?null:(0,t.jsx)("div",{className:"grid gap-3",children:o.map(s=>(0,t.jsx)(S,{className:"no-underline",to:T(s.pluginName,s.id),children:(0,t.jsx)(c,{padding:"md",children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"font-sans font-medium text-xs text-dashboard-text-muted",children:s.pluginDisplayName}),(0,t.jsx)("h2",{className:"mt-1 mb-0 font-display text-base font-medium text-dashboard-text",children:s.label}),(0,t.jsx)("p",{className:"mt-1 mb-0 text-sm text-dashboard-text-muted",children:s.description})]}),(0,t.jsx)(C,{"aria-hidden":"true",className:"shrink-0 text-dashboard-text-muted",size:16})]})})},`${s.pluginName}:${s.id}`))})]})})}export{ae as AdminPage};
@@ -1,3 +1,3 @@
1
- import{a as B}from"./chunk-BKOACADP.js";import{a as ca,b as ua,c as ga,d as fa,e as pa,f as Lt}from"./chunk-UAH6DWNS.js";import{a as da,b as X,c as la,d as ma}from"./chunk-SDKV3OID.js";import{a as sa}from"./chunk-SIOW7OOW.js";import{a as he}from"./chunk-4UGZNVJM.js";import{c as ra}from"./chunk-VFEBNOPX.js";import{a as aa}from"./chunk-SUX4QBVF.js";import{a as Go,c as Qo,f as Zo,o as Xo,p as ea,q as ta,t as oa,w as na,x as ia}from"./chunk-V5UDSIRA.js";import{a as Ho,b as pt,c as ht}from"./chunk-HCLRG2EC.js";import{a as q,b as j,c as Je,d as tt,e as Wo}from"./chunk-PQPAPPEI.js";import{b as Le}from"./chunk-GYRM5ZIV.js";import{a as Oo,b as $o,c as Vo,e as Bo}from"./chunk-ZIJ6SJDN.js";import{a as Be,b as _e,c as Ue,d as ze,e as qe,f as je,g as He}from"./chunk-5GZDBGAR.js";import"./chunk-Z2JPRGFT.js";import"./chunk-NQOJAZFQ.js";import{a as We}from"./chunk-XNR4RZEC.js";import"./chunk-FE522UEA.js";import"./chunk-G5NWYJTV.js";import{a as ut}from"./chunk-5ZA674OU.js";import{l as ft}from"./chunk-A2QWWA7O.js";import{j as Yo}from"./chunk-TFJOEF3Q.js";import{a as et,b as $e}from"./chunk-EFEREKX4.js";import{a as _o,b as Uo,c as gt,d as zo,e as qo,f as jo}from"./chunk-6FSJ3W2W.js";import{a as Ce}from"./chunk-2BCS5AQL.js";import"./chunk-QOX5RMLM.js";import"./chunk-H76B43OQ.js";import{h as To,j as Oe,k as mt}from"./chunk-QNA7F7QB.js";import"./chunk-B6HGRBBX.js";import{K as Eo,O as se,g as we,k as ct,r as Do,z as Ve}from"./chunk-NQMDED2R.js";import"./chunk-PXHLJIOT.js";import{i as co,j as uo,l as go}from"./chunk-GMZIELFU.js";import{l as Z}from"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import{d as pe,g as Fe,i as ge,l as oe,m as So,n as Me,p as Ro,r as ce}from"./chunk-GO45RQDL.js";import{Ja as Q,T as re,U as No,V as wo,W as Co,X as ko,k as fo,l as po,m as ho,n as vo,o as bo,p as xo,q as yo,r as Ao}from"./chunk-VXT3FIVL.js";import"./chunk-QPBLZSNX.js";import{a as ke,c as bt}from"./chunk-RHMZNAJX.js";import{a as It}from"./chunk-GOTQ4D6W.js";import{C as Lo,D as Mo,G as Jo,K as vt,L as Ko,M as Pt,b as nt,d as Pe,f as it,g as Yt,i as Gt,k as Et,o as W,q as Qt,u as Po,x as Io}from"./chunk-6PHJZPWD.js";import"./chunk-T4M53QQT.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import{a as Ie,b as T}from"./chunk-CR2ICLSH.js";import{Ga as eo,Hc as lt,Ia as me,N as Xt,Na as to,Qa as Ze,Qc as Ft,Rc as V,Tc as Xe,Xa as oo,Xc as Fo,_a as ao,a as Y,b as k,d as Zt,fb as no,g as rt,h as st,ib as io,j as dt,lb as ro,lc as lo,pc as mo,sb as so}from"./chunk-YPMUHXYT.js";import{b as ln,c as v}from"./chunk-7SZRL6FY.js";var Dt=v(Y(),1);var M=v(k(),1);function ha({automation:e,editPath:t,editVariant:o,onDelete:a}){let n=Le(),i=pe(),r=e.status==="completed",s=e.status==="paused",f=e.status==="blocked",w=!r,D=s||f?"resume":"pause",u=ge({mutationFn:async()=>{let p=`/api/automations/${encodeURIComponent(e.id)}`,R=await ce(re,`${p}/edit`);if(R.status!==e.status)throw new Error("The Automation changed. Reload the page before trying again.");return Me(re,`${p}/lifecycle`,{action:D,revision:R.revision})},onSuccess:async p=>{await i.invalidateQueries({queryKey:["dashboard","automations"]}),n.add({title:p.status==="blocked"?"Automation is still blocked":D==="pause"?"Automation paused":"Automation resumed",description:p.status==="blocked"?"Fix the reported requirement before resuming again.":D==="pause"?"Work already queued or running may finish.":"Future triggers are enabled.",type:p.status==="blocked"?"warning":"success"})}});return(0,M.jsxs)("div",{className:"grid min-w-0 justify-items-stretch gap-3 md:justify-items-end",children:[(0,M.jsxs)("div",{"aria-label":"Automation actions",className:"flex flex-wrap items-center gap-2",role:"group",children:[r?null:(0,M.jsxs)(W,{className:Ie({variant:o}),to:t,children:[(0,M.jsx)(lo,{"aria-hidden":"true",size:14}),"Edit automation"]}),w?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(T,{disabled:u.isPending,onClick:()=>u.mutate(),children:u.isPending?"Updating\u2026":D==="pause"?"Pause":"Resume"}),(0,M.jsxs)(Oo,{children:[(0,M.jsx)($o,{render:(0,M.jsx)(T,{"aria-label":"About pausing",size:"icon"}),children:(0,M.jsx)(so,{"aria-hidden":"true",size:16})}),(0,M.jsx)(Vo,{side:"bottom",align:"end","aria-label":"About pausing",children:(0,M.jsxs)(Bo,{children:["Pausing stops new runs. Work already queued or running may finish. Resuming skips missed runs and waits for the next scheduled time or new event.",s&&e.statusReason?" Removing the pause keeps the block until you fix it and resume again.":""]})})]})]}):null,(0,M.jsxs)(co,{children:[(0,M.jsx)(uo,{render:(0,M.jsx)(T,{focusableWhenDisabled:!0,"aria-label":"Delete automation",size:"icon",variant:"danger",onClick:p=>a(p.currentTarget),disabled:u.isPending,children:(0,M.jsx)(lt,{"aria-hidden":"true",size:16})})}),(0,M.jsx)(go,{size:"compact",children:"Delete automation"})]})]}),u.error?(0,M.jsx)("div",{className:"max-w-sm",children:(0,M.jsx)(B,{tone:"error",title:"Could not update this automation.",children:u.error instanceof oe?u.error.apiError??"Try again.":u.error.message})}):null]})}var va=v(Y(),1);var de=v(k(),1);function ba(e){let[t,o]=(0,va.useState)(!0),a=pe(),n=Le(),i=ge({mutationFn:()=>Ro(`/api/automations/${encodeURIComponent(e.automation.id)}`),onSuccess:async()=>{await a.invalidateQueries({queryKey:["dashboard","automations"]}),e.onDeleted(),n.add({title:"Automation deleted",description:e.automation.title,type:"success"}),o(!1)}});return(0,de.jsx)(Be,{open:t,onOpenChange:(r,s)=>{i.isPending?s.cancel():o(r)},onOpenChangeComplete:r=>{r||e.onClose()},children:(0,de.jsxs)(_e,{finalFocus:e.returnFocus,children:[(0,de.jsx)(Ue,{children:"Delete automation?"}),(0,de.jsxs)(ze,{children:["Delete"," ",(0,de.jsx)("strong",{className:"font-medium text-dashboard-text",children:e.automation.title}),"? This removes the Automation and stops future triggers. Work already queued or running may finish."]}),i.error?(0,de.jsx)(B,{tone:"error",title:"The automation could not be deleted. Try again."}):null,(0,de.jsxs)(qe,{children:[(0,de.jsx)(He,{disabled:i.isPending,children:"Cancel"}),(0,de.jsx)(je,{variant:"danger",disabled:i.isPending,onClick:()=>i.mutate(),children:i.isPending?"Deleting\u2026":"Delete automation"})]})]})})}var ee=v(Y(),1);function Se(e,t){return typeof e.destination=="string"?e.destination==="task_creator"?"Creator \xB7 Direct message":`${t.label} \xB7 ${t.visibility}`:e.destination.channelId===t.channelId&&e.destination.teamId===t.teamId?`${t.label} \xB7 ${t.visibility}`:`Saved destination \xB7 ${e.destination.channelId}`}var xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];function Re(e){return{title:e.title??"",instruction:e.instruction,credentialMode:e.credentialMode,outcomes:e.outcomes,trigger:e.kind==="event"?e.trigger:void 0}}function Ke(e){let t=e.schedule.recurrence;if(e.schedule.kind==="recurring"&&t){let{time:o,weekdays:a,...n}=t;return{kind:"recurring",...n,timezone:e.schedule.timezone,time:`${String(o.hour).padStart(2,"0")}:${String(o.minute).padStart(2,"0")}`,weekdays:a?.flatMap(i=>xt[i]??[])}}if(e.nextRunAtMs){let o=new Intl.DateTimeFormat("en-CA",{timeZone:e.schedule.timezone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e.nextRunAtMs),a=n=>o.find(i=>i.type===n)?.value??"";return{kind:"one_off",timezone:e.schedule.timezone,timing:{type:"at",date:`${a("year")}-${a("month")}-${a("day")}`,time:`${a("hour")}:${a("minute")}`}}}return{kind:"recurring",frequency:"daily",time:"09:00",timezone:e.schedule.timezone}}function xa(e,t){let o={};return t.title!==(e.title??"")&&(o.title=t.title),t.instruction!==e.instruction&&(o.instruction=t.instruction),t.credentialMode!==e.credentialMode&&(o.credentialMode=t.credentialMode),JSON.stringify(t.outcomes)!==JSON.stringify(e.outcomes)&&(o.outcomes=t.outcomes),e.kind==="scheduled"&&t.schedule&&(o.schedule=t.schedule),e.kind==="event"&&JSON.stringify(t.trigger)!==JSON.stringify(e.trigger)&&(o.trigger=t.trigger),o}var J=v(k(),1),Mt={title:"Title",instruction:"Instruction",schedule:"Schedule",trigger:"Trigger",outcomes:"Where results go",credentialMode:"Credentials"};function ya(e){let t=Object.keys(Mt).filter(n=>e.changes[n]!==void 0),o=mn(e.original),a=(n,i)=>cn(n,i,e.summary);return(0,J.jsx)("aside",{"aria-label":"Your changes",className:V("min-w-0 lg:sticky lg:top-4 lg:self-start",t.length===0&&"max-lg:hidden"),children:(0,J.jsxs)(Q,{padding:"sm",children:[(0,J.jsx)("h2",{className:"m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted",children:"Your changes"}),t.length===0?(0,J.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No changes yet. Edit a section to see it here."}):(0,J.jsx)("ul",{className:"m-0 grid list-none gap-3 p-0",children:t.map(n=>(0,J.jsxs)("li",{className:"grid min-w-0 gap-1 text-sm",children:[(0,J.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,J.jsx)("span",{className:"font-medium",children:Mt[n]}),(0,J.jsx)(T,{"aria-label":`Undo ${Mt[n].toLowerCase()} change`,disabled:e.disabled,onClick:()=>e.onUndo(n),children:"Undo"})]}),(0,J.jsxs)("p",{className:"m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs text-dashboard-text-muted line-through decoration-dashboard-text-muted/50",children:[(0,J.jsx)("span",{className:"sr-only",children:"Saved: "}),a(o,n)]}),(0,J.jsxs)("p",{className:"m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs",children:[(0,J.jsx)("span",{className:"sr-only",children:"New: "}),a(e.changes,n)]})]},n))}),(0,J.jsx)("p",{className:"mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted",children:"Saving creates a new version. It does not run this automation."})]})})}function mn(e){let t=Re(e);return e.kind==="scheduled"?{...t,schedule:Ke(e)}:t}function cn(e,t,o){switch(t){case"title":return e.title||"First line of the instruction";case"instruction":return e.instruction||"Empty";case"credentialMode":return e.credentialMode==="creator"?o.ownedByViewer?"Your connected accounts":`${o.createdBy}'s connected accounts`:"System credentials only";case"outcomes":return e.outcomes?.length?e.outcomes.map(a=>Se(a,o.destination)).join(", "):"No success message";case"schedule":return e.schedule?gn(e.schedule):"Not set";case"trigger":{let a=e.trigger;if(!a)return"Not set";let n=a.identifier?`${a.label} \xB7 ${a.identifier}`:`Any ${a.label}`,i=Object.keys(a.match??{}).length;return[n,a.events.join(", "),i?`${i} ${i===1?"filter":"filters"}`:""].filter(Boolean).join(" \xB7 ")}}}var un={daily:"day",weekly:"week",monthly:"month",yearly:"year"};function gn(e){if(e.kind==="one_off")return`Once on ${e.timing.date} at ${e.timing.time} (${e.timezone})`;let t=e.interval??1,o=un[e.frequency],a=t===1?o:`${t} ${o}s`,n=e.frequency==="weekly"&&e.weekdays?.length?` on ${e.weekdays.map(i=>i.slice(0,1).toUpperCase()+i.slice(1,3)).join(", ")}`:e.frequency==="monthly"&&e.dayOfMonth?` on day ${e.dayOfMonth}`:e.frequency==="yearly"&&e.month&&e.dayOfMonth?` on ${String(e.month).padStart(2,"0")}-${String(e.dayOfMonth).padStart(2,"0")}`:"";return`Every ${a}${n} at ${e.time} (${e.timezone})`}var ve=v(k(),1);function ae(e){return(0,ve.jsxs)("section",{className:V("grid min-w-0 gap-5 border-t border-dashboard-border-emphasis py-8 md:grid-cols-[12rem_minmax(0,1fr)] md:gap-10",e.changed&&"-ml-4 pl-4 shadow-[inset_2px_0_0_var(--color-dashboard-accent)] sm:-ml-5 sm:pl-5"),children:[(0,ve.jsxs)("div",{children:[(0,ve.jsx)("h2",{className:"m-0 font-display text-lg font-medium",children:e.title}),e.changed?(0,ve.jsx)("p",{className:"mt-1 mb-0 text-xs text-dashboard-accent-text",children:"Unsaved changes"}):null,e.detail?(0,ve.jsx)("p",{className:"mt-2 mb-0 text-sm leading-relaxed text-dashboard-text-muted",children:e.detail}):null]}),(0,ve.jsx)("div",{className:"grid min-w-0 content-start gap-5",children:e.children})]})}var yt=v(Y(),1);var g=v(k(),1);function Aa(e){let t=e.value??Ke(e.automation),[o,a]=(0,yt.useState)(e.value);(0,yt.useEffect)(()=>{let u=setTimeout(()=>a(e.value),300);return()=>clearTimeout(u)},[e.value]);let n=Co.safeParse(o),i=Fe({queryKey:["dashboard","automation-schedule-preview",e.automation.id,o],enabled:!!o&&n.success,retry:!1,queryFn:()=>Me(ko,`/api/automations/${encodeURIComponent(e.automation.id)}/preview`,o)}),r=t.kind==="recurring"?t.frequency:"once",s=t.kind==="recurring"?t.time:t.timing.time,f=e.value?i.data?.nextRunAtMs:e.automation.nextRunAtMs,w=e.value!==o||i.isFetching,D=i.error instanceof oe?i.error.apiError:i.error?"Schedule preview could not be loaded. Try again.":e.value&&!n.success&&!w?n.error.issues[0]?.message:void 0;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"grid grid-cols-1 items-start gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-frequency",children:"Repeat"}),(0,g.jsxs)(he,{id:"schedule-frequency",value:r,onChange:u=>{let p=u.target.value;p!=="once"&&p!=="daily"&&p!=="weekly"&&p!=="monthly"&&p!=="yearly"||e.onChange(p==="once"?{kind:"one_off",timezone:t.timezone??e.automation.schedule.timezone,timing:{type:"at",date:"",time:s}}:{kind:"recurring",timezone:t.timezone,time:s,frequency:p,interval:1,weekdays:p==="weekly"?["monday"]:void 0,dayOfMonth:["monthly","yearly"].includes(p)?1:void 0,month:p==="yearly"?1:void 0})},children:[(0,g.jsx)("option",{value:"once",children:"Once"}),(0,g.jsx)("option",{value:"daily",children:"Every day"}),(0,g.jsx)("option",{value:"weekly",children:"Every week"}),(0,g.jsx)("option",{value:"monthly",children:"Every month"}),(0,g.jsx)("option",{value:"yearly",children:"Every year"})]})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-time",children:"Time"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-time",type:"time",value:s,onChange:u=>e.onChange(t.kind==="recurring"?{...t,time:u.target.value}:{...t,timing:{type:"at",date:t.timing.date,time:u.target.value}})})]})]}),t.kind==="recurring"?(0,g.jsxs)(g.Fragment,{children:[t.frequency==="weekly"?(0,g.jsxs)("fieldset",{children:[(0,g.jsx)("legend",{className:"mb-2 text-sm font-semibold",children:"On"}),(0,g.jsx)(Lo,{className:"grid grid-cols-7 gap-1.5",multiple:!0,onValueChange:u=>e.onChange({...t,weekdays:u}),value:t.weekdays??[],children:[...xt.slice(1),xt[0]].map(u=>(0,g.jsx)(Mo,{"aria-label":u,className:"h-auto min-h-11 min-w-0 border-dashboard-border-emphasis px-1 capitalize data-pressed:border-dashboard-focus/50 data-pressed:bg-dashboard-focus/10 data-pressed:text-dashboard-focus sm:min-h-10 sm:text-sm",value:u,children:u.slice(0,3)},u))})]}):null,(0,g.jsxs)("div",{className:"grid grid-cols-1 items-start gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-interval",children:"Interval"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-interval",type:"number",min:1,max:365,value:t.interval??1,onChange:u=>e.onChange({...t,interval:u.target.valueAsNumber})}),(0,g.jsx)(Je,{id:"schedule-interval-help",children:"Number of calendar periods between runs."})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-start",children:"Start date"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-start",type:"date",value:t.startDate??"",onChange:u=>e.onChange({...t,startDate:u.target.value||void 0})})]})]}),t.frequency==="monthly"||t.frequency==="yearly"?(0,g.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-day",children:"Day of month"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-day",type:"number",min:1,max:31,value:t.dayOfMonth??1,onChange:u=>e.onChange({...t,dayOfMonth:u.target.valueAsNumber})})]}),t.frequency==="yearly"?(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-month",children:"Month"}),(0,g.jsx)(he,{id:"schedule-month",value:t.month??1,onChange:u=>e.onChange({...t,month:Number(u.target.value)}),children:Array.from({length:12},(u,p)=>(0,g.jsx)("option",{value:p+1,children:new Intl.DateTimeFormat("en",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2026,p,1)))},p))})]}):null]}):null]}):(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-date",children:"Date"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-date",type:"date",value:t.timing.date,onChange:u=>e.onChange({...t,timing:{type:"at",time:s,date:u.target.value}})})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-timezone",children:"Timezone"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-timezone",list:"automation-timezones",value:t.timezone??"",onChange:u=>e.onChange({...t,timezone:u.target.value})}),(0,g.jsx)("datalist",{id:"automation-timezones",children:["UTC",...Intl.supportedValuesOf("timeZone")].map(u=>(0,g.jsx)("option",{children:u},u))}),(0,g.jsx)(Je,{id:"schedule-timezone-help",children:"Use an IANA timezone. The schedule follows local time, including daylight saving time."})]}),(0,g.jsxs)("div",{role:"status",className:"flex gap-3 rounded-md bg-dashboard-fill-soft p-3 text-sm leading-relaxed",children:[(0,g.jsx)(no,{"aria-hidden":!0,size:17,className:"mt-0.5 shrink-0 text-dashboard-text-muted"}),(0,g.jsx)("div",{children:w?"Checking schedule\u2026":D?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("span",{className:"text-rose-300",children:D}),i.error?(0,g.jsx)(T,{onClick:()=>{i.refetch()},children:"Try again"}):null]}):f?(0,g.jsxs)(g.Fragment,{children:["Next run"," ",new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short",timeZone:e.value?i.data?.schedule.timezone??"UTC":e.automation.schedule.timezone}).format(f)]}):"No next run."})]}),e.value?(0,g.jsx)(T,{className:"w-fit",onClick:()=>e.onChange(void 0),children:"Keep saved schedule"}):null]})}var wa=v(Y(),1);var Te=v(k(),1);function Ye(e){return e.filters.length===0?(0,Te.jsx)("p",{className:"m-0 mt-1 text-xs text-dashboard-text-muted",children:"No filters. Runs on every selected event."}):(0,Te.jsxs)("div",{className:"mt-1 text-xs text-dashboard-text-muted",children:[(0,Te.jsx)("p",{className:"m-0",children:"Every filter must match:"}),(0,Te.jsx)("ul",{className:"m-0 list-disc pl-5",children:e.filters.map(t=>(0,Te.jsx)("li",{className:"break-words",children:t},t))})]})}var c=v(k(),1),At="*",fn={resourceTypes:[],events:{},anyResourceFields:{}};function Na(e,t){let o=e.events[t]?.reach;if(typeof o!="object")return;let a=o.anyOf.map(n=>e.anyResourceFields[n]?.description??n);return a.length===1?`needs a filter: ${a[0]}`:`needs one of these filters: ${a.join("; or ")}`}function Ca(e){let[t,o]=(0,wa.useState)(),a=Fe({queryKey:["dashboard","automation-event-catalog"],queryFn:({signal:m})=>ce(wo,"/api/automations/event-catalog",m),retry:!1}),n=a.data?.find(m=>m.namespace===e.value.namespace),i=n??fn,r=n?.displayName??e.value.namespace,s=e.value.resourceType===void 0,f=ho(i,e.value),w=a.data?vo(i,e.value):[],D=!f||w.some(m=>m.reason!=="field_not_set"&&m.reason!=="filter_required"),u=a.data?.filter(m=>fo(m).length>0)??[],p=Object.entries(f?.fields??{}),R=p.filter(([m,b])=>e.value.match?.[m]!==void 0||po(b,e.value.events).length===0),z=(m,b)=>{let C={...e.value.match};b===void 0?delete C[m]:C[m]=b,e.onChange({...e.value,match:C})};return(0,c.jsxs)(c.Fragment,{children:[a.error?(0,c.jsxs)(B,{title:"Event choices could not be loaded.",children:["Saved values are kept."," ",(0,c.jsx)(T,{onClick:()=>{a.refetch()},children:"Try again"})]}):a.isPending?(0,c.jsx)("p",{role:"status",children:"Loading event choices\u2026"}):null,D&&a.data?(0,c.jsxs)(B,{title:"Saved trigger \xB7 Kept unchanged",children:["Some saved values are not in the current catalog. You can edit other fields, or select a new resource type to replace the trigger.",(0,c.jsx)(pn,{displayName:r,source:i,trigger:e.value})]}):null,(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-resource",children:D?"Replace trigger":"Resource type"}),(0,c.jsxs)(he,{id:"trigger-resource",value:D?"":`${e.value.namespace}:${e.value.resourceType??At}`,onChange:m=>{let[b,C]=m.target.value.split(":");if(C===At&&b){o({namespace:b,label:"",events:[]});return}let E=a.data?.find(x=>x.namespace===b)?.resourceTypes.find(x=>x.type===C);!b||!E||o({namespace:b,resourceType:E.type,identifier:"",label:"",events:[]})},children:[(0,c.jsx)("option",{value:"",disabled:!0,children:"Keep saved trigger"}),u.map(m=>(0,c.jsxs)("option",{value:`${m.namespace}:${At}`,children:[m.displayName," \xB7 any resource"]},`${m.namespace}:${At}`)),a.data?.flatMap(m=>m.resourceTypes.map(b=>(0,c.jsxs)("option",{value:`${m.namespace}:${b.type}`,children:[m.displayName," \xB7 ",b.type.replaceAll("_"," ")]},`${m.namespace}:${b.type}`)))]})]}),(0,c.jsx)(Be,{onOpenChange:m=>{m||o(void 0)},open:t!==void 0,children:(0,c.jsxs)(_e,{children:[(0,c.jsx)(Ue,{children:"Replace the saved trigger?"}),(0,c.jsx)(ze,{children:"Its resource, events, and filters will be cleared."}),(0,c.jsxs)(qe,{children:[(0,c.jsx)(He,{children:"Cancel"}),(0,c.jsx)(je,{onClick:()=>{t&&e.onChange(t),o(void 0)},variant:"primary",children:"Replace trigger"})]})]})}),!D&&f?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-label",children:s?"Trigger name":"Resource name"}),(0,c.jsx)(Z,{size:"comfortable",id:"trigger-label",value:e.value.label,onChange:m=>e.onChange({...e.value,label:m.target.value})})]}),s?(0,c.jsx)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:"Runs for every resource that the filters match."}):(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-identifier",children:"Resource identifier"}),(0,c.jsx)(Z,{size:"comfortable",id:"trigger-identifier",value:e.value.identifier??"",onChange:m=>e.onChange({...e.value,identifier:m.target.value})}),(0,c.jsx)(Je,{id:"trigger-identifier-help",children:"Use the exact provider resource identifier, not its display name."})]}),(0,c.jsxs)("fieldset",{children:[(0,c.jsx)("legend",{className:"mb-2 text-sm font-semibold",children:"Run on these events"}),(0,c.jsx)("div",{className:"divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis",children:f.events.map(m=>(0,c.jsxs)("label",{className:"flex min-h-11 cursor-pointer items-start gap-3 px-3 py-3 text-sm",children:[(0,c.jsx)(Ho,{className:"mt-0.5",checked:e.value.events.includes(m),disabled:e.disabled,onCheckedChange:()=>e.onChange({...e.value,events:e.value.events.includes(m)?e.value.events.filter(b=>b!==m):[...e.value.events,m]})}),(0,c.jsxs)("span",{className:"min-w-0 break-words",children:[bo(m),s&&Na(i,m)?(0,c.jsxs)("span",{className:"text-dashboard-text-muted",children:[" ","\xB7 ",Na(i,m)]}):null]})]},m))})]}),p.length?(0,c.jsxs)("fieldset",{className:"grid gap-4",children:[(0,c.jsx)("legend",{className:"mb-3 text-sm font-semibold",children:"Filters"}),(0,c.jsxs)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:["Every filter must match. Leave a filter blank to match any value.",R.length<p.length?" Filters that a selected event does not set are hidden.":null]}),R.map(([m,b])=>{let C=e.value.match?.[m],E=w.find(x=>x.field===m);return(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:`match-${m}`,children:m}),Array.isArray(C)?(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"break-all",children:xo(m,b,C)})," ",(0,c.jsx)(T,{onClick:()=>z(m,void 0),children:"Remove filter"})]}):b.kind==="boolean"||b.enum?(0,c.jsxs)(he,{id:`match-${m}`,value:C===void 0?"":String(C),onChange:x=>z(m,x.target.value===""?void 0:b.kind==="boolean"?x.target.value==="true":x.target.value),children:[(0,c.jsx)("option",{value:"",children:"Any value"}),(b.enum??["true","false"]).map(x=>(0,c.jsx)("option",{children:x},x))]}):(0,c.jsx)(Z,{size:"comfortable",id:`match-${m}`,type:b.kind==="number"?"number":"text",step:"any",value:C===void 0?"":String(C),onChange:x=>z(m,x.target.value===""?void 0:b.kind==="number"?x.target.valueAsNumber:x.target.value)}),b.description?(0,c.jsx)(Je,{id:`match-${m}-help`,children:b.description}):null,E?(0,c.jsx)(tt,{children:E.message}):null]},m)})]}):null]}):null,JSON.stringify(e.value)!==JSON.stringify(e.original)?(0,c.jsx)(T,{className:"w-fit",onClick:()=>e.onChange(e.original),children:"Keep saved trigger"}):null]})}function pn(e){let t=yo(e.source,e.trigger);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("ul",{className:"my-2 list-disc pl-5",children:t.problems.map(o=>(0,c.jsx)("li",{children:o},o))}),(0,c.jsxs)("div",{className:"text-xs",children:[(0,c.jsxs)("p",{className:"m-0 break-words",children:[e.displayName," \xB7"," ",e.trigger.resourceType?.replaceAll("_"," ")??"any resource",e.trigger.identifier?` \xB7 ${e.trigger.identifier}`:null]}),(0,c.jsx)("p",{className:"m-0 mt-1 break-words text-dashboard-text-muted",children:t.events.join(", ")}),(0,c.jsx)(Ye,{filters:t.filters})]})]})}var F=v(k(),1);function ka(e){return e.outcomes.length?(0,F.jsx)("ol",{className:"m-0 grid list-decimal gap-2 pl-5 text-sm",children:e.outcomes.map((t,o)=>(0,F.jsx)("li",{children:Se(t,e.destination)},o))}):(0,F.jsx)("p",{className:"m-0 text-sm",children:"No success message"})}function Sa(e){let t=e.original.length?e.original:[{action:"send_message",destination:"current_conversation"}],o=[...e.original.flatMap((a,n)=>typeof a.destination=="string"?[]:[{value:`saved:${n}`,label:Se(a,e.destination),outcome:a}]),{value:"current_conversation",label:`${e.destination.label} \xB7 ${e.destination.visibility}`,outcome:{action:"send_message",destination:"current_conversation"}},{value:"task_creator",label:"Creator \xB7 Direct message",outcome:{action:"send_message",destination:"task_creator"}}];return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(pt,{"aria-label":"Success messages",disabled:e.disabled,className:"flex flex-wrap gap-x-6 gap-y-3",onValueChange:a=>e.onChange(a?t:[]),value:e.value.length>0,children:[!0,!1].map(a=>(0,F.jsxs)("label",{className:"inline-flex min-h-8 cursor-pointer items-center gap-2 text-sm",children:[(0,F.jsx)(ht,{value:a}),a?"Send a message":"No success message"]},String(a)))}),e.value.length?(0,F.jsxs)("div",{className:"grid gap-4 sm:gap-2",children:[e.value.map((a,n)=>{let i=e.original.findIndex(r=>JSON.stringify(r)===JSON.stringify(a));return(0,F.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,F.jsxs)("span",{className:"w-4 text-xs text-dashboard-text-muted",children:[n+1,"."]}),(0,F.jsx)("div",{className:V("min-w-0 flex-1",e.value.length>1&&"order-last basis-full sm:order-none sm:basis-auto"),children:(0,F.jsx)(he,{"aria-label":`Message ${n+1} destination`,value:typeof a.destination=="string"?a.destination:`saved:${i}`,onChange:r=>{let s=o.find(f=>f.value===r.target.value);s&&e.onChange(e.value.map((f,w)=>w===n?s.outcome:f))},children:o.map(r=>(0,F.jsx)("option",{value:r.value,children:r.label},r.value))})}),e.value.length>1?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(T,{size:"icon",className:"ml-auto sm:ml-0","aria-label":`Move message ${n+1} up`,disabled:n===0,onClick:()=>{let r=[...e.value],s=r[n-1];s&&(r[n-1]=a,r[n]=s,e.onChange(r))},children:(0,F.jsx)(ao,{size:16})}),(0,F.jsx)(T,{size:"icon","aria-label":`Remove message ${n+1}`,onClick:()=>e.onChange(e.value.filter((r,s)=>s!==n)),children:(0,F.jsx)(lt,{size:16})})]}):null]},n)}),e.value.length<5?(0,F.jsxs)(T,{className:"w-fit",onClick:()=>e.onChange([...e.value,{action:"send_message",destination:"task_creator"}]),children:[(0,F.jsx)(mo,{size:15}),"Add message"]}):null]}):(0,F.jsx)("p",{className:"m-0 text-sm leading-relaxed text-dashboard-text-muted",children:"Junior still does the work. No message is sent after success."}),(0,F.jsxs)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:[e.value.length?"Messages are sent in this order. ":"","This does not limit actions in the instruction."]})]})}var d=v(k(),1);function Ta(e){let t=Le(),[o,a]=(0,ee.useState)(e.automation),[n,i]=(0,ee.useState)(()=>Re(e.automation)),[r,s]=(0,ee.useState)({}),[f,w]=(0,ee.useState)(),[D,u]=(0,ee.useState)(0),p=(0,ee.useRef)(null),R=(0,ee.useRef)(!1),z=it(),m=pe(),b=xa(o,n),C=Object.keys(b).length>0,E={kind:o.kind,revision:o.revision,...b},x=Gt(()=>C&&!R.current),I=(0,ee.useRef)(null);(0,ee.useEffect)(()=>{x.state==="blocked"&&I.current?.focus()},[x.state]);let O=`/api/automations/${encodeURIComponent(o.id)}`;(0,ee.useEffect)(()=>{let y=U=>{C&&!R.current&&(U.preventDefault(),U.returnValue="")};return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[C]);let ne=()=>requestAnimationFrame(()=>(p.current?.querySelector('[aria-invalid="true"]')??p.current?.querySelector("[data-save-error]"))?.focus()),L=ge({mutationFn:()=>So(re,O,E),onSuccess:async()=>{R.current=!0,await m.invalidateQueries({queryKey:["dashboard","automations"]}),t.add({title:"Automation saved",description:"Changes apply to future work.",type:"success"}),z(e.returnPath)},onError:y=>{s(y instanceof oe?y.fields??{}:{}),ne()}});function $(y){f&&(i(y?{...Re(f),...b}:Re(f)),a(f),w(void 0),L.reset(),s({}))}let ie=ge({mutationFn:()=>ce(re,`${O}/edit`),onSuccess:w}),K=L.error instanceof oe&&L.error.code==="conflict",_=y=>i(U=>({...U,...y})),Ne=y=>{_({[y]:Re(o)[y]}),u(U=>U+1)},G=y=>Object.entries(r).filter(([U])=>U===y||U.startsWith(`${y}.`)).flatMap(([,U])=>U).join(" ")||void 0,le=o.kind==="scheduled"?"schedule":"trigger",te=o.ownedByViewer,fe=e.summary.createdBy,De=!te&&o.credentialMode==="creator"&&(b.instruction!==void 0||b[le]!==void 0||b.outcomes!==void 0),Ee=G(le),ot=y=>({"aria-invalid":!!G(y)||void 0,"aria-describedby":G(y)?`${y}-error`:void 0});return(0,d.jsxs)("form",{ref:p,noValidate:!0,onSubmit:y=>{if(y.preventDefault(),L.isPending||K||!C)return;let U=No.safeParse(E);if(!U.success){let at={};for(let Kt of U.error.issues)(at[Kt.path.join(".")]??=[]).push(Kt.message);s(at),ne();return}s({}),L.mutate()},children:[x.state==="blocked"?(0,d.jsx)("div",{tabIndex:-1,ref:I,className:"mb-6 outline-none",children:(0,d.jsxs)(B,{title:"Discard unsaved changes?",children:[(0,d.jsx)("p",{children:"Your changes have not been saved."}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(T,{onClick:()=>x.reset(),children:"Keep editing"}),(0,d.jsx)(T,{onClick:()=>x.proceed(),children:"Discard changes"})]})]})}):null,L.error||Object.keys(r).length?(0,d.jsx)("div",{tabIndex:-1,"data-save-error":!0,className:"mb-6 outline-none",children:(0,d.jsxs)(B,{tone:K?"warning":"error",title:K?"This automation changed while you were editing.":"Changes could not be saved.",children:[(0,d.jsxs)("p",{className:"mt-1",children:["Your edits are still here."," ",K?"Review the latest version before saving again.":L.error instanceof oe?L.error.apiError:"Check the fields below, or try again."]}),K?(0,d.jsx)(T,{disabled:ie.isPending,onClick:()=>ie.mutate(),children:ie.isPending?"Loading\u2026":"Review latest version"}):null,ie.error?(0,d.jsx)("p",{role:"alert",children:"The latest version could not be loaded. Try again."}):null]})}):null,f?(0,d.jsx)("div",{className:"mb-6",children:(0,d.jsxs)(B,{title:"Compare your edits with the latest saved version",children:[(0,d.jsx)("p",{children:"Only the fields you changed are shown. Keeping your edits will replace these fields. Other saved fields stay unchanged."}),Object.entries(b).map(([y,U])=>(0,d.jsxs)("section",{className:"my-4",children:[(0,d.jsx)("h3",{className:"text-sm font-semibold capitalize",children:y==="credentialMode"?"Credentials":y}),(0,d.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{children:"Latest saved"}),(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm",children:Ra(y==="schedule"&&f.kind==="scheduled"?Ke(f):f[y])})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{children:"Your edit"}),(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm",children:Ra(U)})]})]})]},y)),(0,d.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,d.jsx)(T,{onClick:()=>$(!0),children:"Keep my changed fields"}),(0,d.jsx)(T,{onClick:()=>$(!1),children:"Use latest saved version"})]})]})}):null,te?null:(0,d.jsxs)("p",{className:"mt-0 mb-6 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted",children:[fe," created this automation. You can edit it because it is in a public channel. Only ",fe," can turn on their connected accounts. Version history keeps every saved change."]}),(0,d.jsxs)("div",{className:"grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10",children:[(0,d.jsxs)("fieldset",{disabled:L.isPending,className:"min-w-0 [&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",children:[(0,d.jsxs)(ae,{changed:b.title!==void 0||b.instruction!==void 0,title:"What to do",detail:"Give Junior a clear instruction and a name you can find later.",children:[(0,d.jsxs)(q,{children:[(0,d.jsx)(j,{htmlFor:"title",children:"Title"}),(0,d.jsx)(Z,{size:"comfortable",id:"title",value:n.title,placeholder:e.summary.title,onChange:y=>_({title:y.target.value}),...ot("title")}),(0,d.jsx)(tt,{id:"title-error",children:G("title")})]}),(0,d.jsxs)(q,{children:[(0,d.jsx)(j,{htmlFor:"instruction",children:"Instruction"}),(0,d.jsx)(Wo,{id:"instruction",rows:8,value:n.instruction,onChange:y=>_({instruction:y.target.value}),...ot("instruction"),className:"resize-y text-base leading-relaxed sm:text-sm"}),(0,d.jsxs)("p",{className:"m-0 text-right text-xs text-dashboard-text-muted",children:[n.instruction.length.toLocaleString()," / 4,000"]}),(0,d.jsx)(tt,{id:"instruction-error",children:G("instruction")})]})]}),(0,d.jsx)(ae,{changed:b[le]!==void 0,title:"When to run",detail:o.kind==="scheduled"?"Choose a schedule in a specific timezone.":"Run when a matching event occurs.",children:(0,d.jsxs)("div",{id:`${le}-error`,tabIndex:-1,"aria-invalid":!!Ee||void 0,className:"grid min-w-0 gap-5 outline-none",children:[Ee?(0,d.jsx)("p",{role:"alert",className:"m-0 text-sm text-rose-300",children:Ee}):null,o.kind==="scheduled"?(0,d.jsx)(Aa,{automation:o,value:n.schedule,onChange:y=>_({schedule:y})}):(0,d.jsx)(Ca,{value:n.trigger??o.trigger,original:o.trigger,disabled:L.isPending,onChange:y=>_({trigger:y})})]})}),(0,d.jsxs)(ae,{changed:b.outcomes!==void 0,title:"Where results go",detail:"Choose who gets a message after successful work.",children:[G("outcomes")?(0,d.jsx)("p",{role:"alert",className:"m-0 text-sm text-rose-300",children:G("outcomes")}):null,(0,d.jsx)(Sa,{value:n.outcomes,original:o.outcomes,destination:e.summary.destination,disabled:L.isPending,onChange:y=>_({outcomes:y})})]}),(0,d.jsxs)(ae,{changed:b.credentialMode!==void 0,title:"Credentials",detail:"Choose which connected accounts Junior can use.",children:[(0,d.jsx)(pt,{"aria-label":"Credential mode",disabled:L.isPending,className:"divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis",onValueChange:y=>_({credentialMode:y}),value:De?"system":n.credentialMode,children:[["creator",te?"Your connected accounts":`${fe}\u2019s connected accounts`,te?"Uses accounts connected by you, the creator.":`Uses accounts connected by ${fe}. Only ${fe} can turn this on.`],["system","System credentials only",te?"Does not use your connected accounts. Some work may not be possible.":"Does not use anyone\u2019s connected accounts. Some work may not be possible."]].map(([y,U,at])=>(0,d.jsxs)("label",{className:"flex cursor-pointer items-start gap-3 px-4 py-4 has-data-checked:bg-dashboard-fill-soft has-data-disabled:cursor-not-allowed has-data-disabled:opacity-60",children:[(0,d.jsx)(ht,{className:"mt-0.5",value:y,disabled:y==="creator"&&!te&&(o.credentialMode!=="creator"||De)}),(0,d.jsxs)("span",{children:[(0,d.jsx)("span",{className:"block text-sm font-medium",children:U}),(0,d.jsx)("span",{className:"mt-1 block text-xs leading-relaxed text-dashboard-text-muted",children:at})]})]},y))}),De?(0,d.jsxs)(B,{title:"Saving switches this automation to system credentials.",children:["Only ",fe," can let a changed instruction,",o.kind==="event"?" trigger,":" schedule,"," or result destination use their connected accounts."]}):null,G("credentialMode")?(0,d.jsx)("p",{role:"alert",children:G("credentialMode")}):null]})]},D),(0,d.jsx)(ya,{changes:b,disabled:L.isPending,onUndo:Ne,original:o,summary:e.summary})]}),(0,d.jsx)("p",{className:"mb-5 text-xs leading-relaxed text-dashboard-text-muted sm:hidden",children:"Changes apply to future work. Saving does not run this automation."}),(0,d.jsx)("div",{className:"sticky bottom-0 z-20 -mx-4 border-t border-dashboard-border-emphasis bg-dashboard-bg px-4 py-4 sm:-mx-8 sm:px-8",children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,d.jsxs)("div",{className:"min-w-0 flex-1",role:"status",children:[(0,d.jsx)("p",{className:"m-0 text-xs font-medium sm:text-sm",children:L.isPending?"Saving\u2026":C?"Unsaved changes":"Unchanged"}),(0,d.jsx)("p",{className:"mt-1 mb-0 hidden text-xs text-dashboard-text-muted sm:block",children:"Changes apply to future work. Saving does not run it."})]}),(0,d.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,d.jsx)(W,{to:e.returnPath,className:"inline-flex min-h-11 items-center rounded-md border border-dashboard-border-emphasis px-3 text-sm text-dashboard-text no-underline sm:min-h-9",children:"Cancel"}),(0,d.jsx)(T,{type:"submit",variant:"primary",className:"min-h-11 sm:min-h-9",disabled:!C||L.isPending||K,children:"Save changes"})]})]})})]})}function Ra(e){return e==null?"Not set":typeof e=="string"?e:JSON.stringify(e,null,2)}var Ge=v(k(),1);function Da(){return(0,Ge.jsx)("div",{role:"status","aria-label":"Loading automation editor",children:["What to do","When to run","Where results go","Credentials"].map((e,t)=>(0,Ge.jsxs)(ae,{title:e,children:[(0,Ge.jsx)(et,{className:"h-4 w-24"}),(0,Ge.jsx)(et,{className:t===0?"h-48 w-full":"h-20 w-full"})]},e))})}var P=v(k(),1);function Ea({automation:e}){let t=Oe(!0,e.id),o=t.data?.executions.slice(0,3)??[];return(0,P.jsxs)("section",{"aria-label":"Recent runs",className:"grid min-w-0 gap-2.5",children:[(0,P.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,P.jsx)("h3",{className:"m-0 text-xs font-medium text-dashboard-text-muted",children:"Recent runs"}),e.totalRuns>0||o.length>0?(0,P.jsx)(W,{className:`${Xe} text-xs`,to:se(e.id,"runs"),children:"View all runs"}):null]}),t.isPending?(0,P.jsxs)("div",{"aria-busy":"true",role:"status",className:"grid gap-2",children:[(0,P.jsx)("span",{className:"sr-only",children:"Loading recent runs"}),Array.from({length:3},(a,n)=>(0,P.jsx)(et,{className:"h-14 rounded-md"},n))]}):null,t.error?(0,P.jsxs)(We,{children:["Recent runs could not be loaded."," ",(0,P.jsx)(T,{onClick:()=>{t.refetch()},children:"Try again"})]}):null,t.data&&o.length===0?(0,P.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:e.totalRuns===0?"No runs yet. Results will appear here after the first run.":"No recent runs are available. Older run details may have expired."}):null,o.length>0?(0,P.jsx)("ol",{className:"m-0 list-none divide-y divide-dashboard-border-subtle p-0",children:o.map(a=>{let n=[a.durationMs!==void 0?ct(a.durationMs):void 0,a.costUsd!==void 0?Ve({total:a.costUsd}):void 0].filter(Boolean).join(" \xB7 "),i=a.title!==e.title?a.title:void 0,r=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[(0,P.jsx)(Ce,{size:"compact",tone:a.status==="completed"?"success":a.status==="failed"?"danger":"warning",children:a.status}),(0,P.jsx)("time",{className:"text-xs text-dashboard-text-muted",dateTime:a.executedAt,title:X(a.executedAt),children:we(a.executedAt)})]}),i||n?(0,P.jsxs)("div",{className:"flex min-w-0 items-baseline justify-between gap-3 text-xs text-dashboard-text-muted",children:[i?(0,P.jsx)("p",{className:"m-0 min-w-0 truncate text-dashboard-text",title:i,children:i}):null,n?(0,P.jsx)("p",{className:"m-0 shrink-0 tabular-nums",children:n}):null]}):null,a.conversationId?null:(0,P.jsx)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:"No Conversation recorded"})]}),s="grid min-w-0 gap-1 rounded-md px-2 py-2.5";return(0,P.jsx)("li",{children:a.conversationId?(0,P.jsx)(W,{"aria-label":`Open ${a.status} run from ${X(a.executedAt)}`,className:`${s} text-inherit no-underline transition-colors hover:bg-dashboard-fill-hover focus-visible:outline-2 focus-visible:outline-dashboard-focus`,to:ut(a.conversationId),children:r}):(0,P.jsx)("div",{className:s,children:r})},a.executionId)})}):null]})}var Ae={};ln(Ae,{Header:()=>Oa,Item:()=>La,Panel:()=>za,Root:()=>Fa,Trigger:()=>Va});var be=v(Y(),1);var Nt=v(Y(),1),Ot=Nt.createContext(void 0);function wt(){let e=Nt.useContext(Ot);if(e===void 0)throw new Error(st(10));return e}var $t=v(k(),1),hn={value:()=>null},Fa=be.forwardRef(function(t,o){let{render:a,className:n,disabled:i=!1,hiddenUntilFound:r,keepMounted:s,loopFocus:f,onValueChange:w,multiple:D=!1,orientation:u="vertical",value:p,defaultValue:R,style:z,...m}=t,b=R??Zt,C=be.useRef([]),[E,x]=Fo({controlled:p,default:b,name:"Accordion",state:"value"}),I=dt(($,ie,K)=>{let _;D?ie?_=[...E,$]:_=E.filter(Ne=>Ne!==$):_=E[0]===$?[]:[$],w?.(_,K),!K.isCanceled&&x(_)}),O=be.useMemo(()=>({value:E,disabled:i,orientation:u}),[E,i,u]),ne=be.useMemo(()=>({disabled:i,handleValueChange:I,hiddenUntilFound:r??!1,keepMounted:s??!1,state:O,value:E}),[i,I,r,s,O,E]),L=me("div",t,{state:O,ref:o,props:m,stateAttributesMapping:hn});return(0,$t.jsx)(Ot.Provider,{value:ne,children:(0,$t.jsx)(Io,{elementsRef:C,children:L})})});var ye=v(Y(),1);var Ct=v(Y(),1),Vt=Ct.createContext(void 0);function Qe(){let e=Ct.useContext(Vt);if(e===void 0)throw new Error(st(9));return e}var Pa="data-index";var xe={...qo,index:e=>({[Pa]:String(e)}),...Xt,value:()=>null};var Bt=v(k(),1),La=ye.forwardRef(function(t,o){let{className:a,disabled:n=!1,onOpenChange:i,render:r,value:s,style:f,...w}=t,{ref:D,index:u}=Po(),{disabled:p,handleValueChange:R,state:z,value:m}=wt(),b=Ft(),C=s??b,E=n||p,x=m.includes(C),I=dt((le,te)=>{i?.(le,te),!te.isCanceled&&R(C,le,te)}),O=_o({open:x,onOpenChange:I,disabled:E}),ne=ye.useMemo(()=>({...O,onOpenChange:I,state:{open:O.open,disabled:O.disabled,transitionStatus:O.transitionStatus}}),[O,I]),L=ye.useMemo(()=>({...z,hidden:!x&&!O.mounted,index:u,disabled:E,open:x}),[O.mounted,E,u,x,z]),$=Ft(),[ie,K]=ye.useState(),_=ie===null?void 0:ie??$,Ne=ye.useMemo(()=>({defaultTriggerId:$,open:x,state:L,setTriggerId:K,triggerId:_}),[$,x,L,K,_]),G=me("div",t,{state:L,ref:[o,D],props:w,stateAttributesMapping:xe});return(0,Bt.jsx)(Uo.Provider,{value:ne,children:(0,Bt.jsx)(Vt.Provider,{value:Ne,children:G})})});var Ma=v(Y(),1);var Oa=Ma.forwardRef(function(t,o){let{render:a,className:n,style:i,...r}=t,{state:s}=Qe();return me("h3",t,{state:s,ref:o,props:r,stateAttributesMapping:xe})});var $a=v(Y(),1);var vn={...xe,...zo},Va=$a.forwardRef(function(t,o){let{disabled:a,className:n,id:i,render:r,nativeButton:s=!0,style:f,...w}=t,{panelId:D,open:u,handleTrigger:p,disabled:R}=gt(),z=a||R,{getButtonProps:m,buttonRef:b}=to({disabled:z,native:s}),{defaultTriggerId:C,state:E,setTriggerId:x}=Qe(),I=i||void 0,O=I??C;return rt(()=>(x($=>I??($===null?void 0:$)),()=>{x($=>$===I?null:$)}),[I,x]),me("button",t,{state:E,ref:[o,b],props:[{"aria-controls":u?D:void 0,"aria-expanded":u,id:O,onClick:p},w,m],stateAttributesMapping:vn})});var _t=v(Y(),1);var Ba="--accordion-panel-height",_a="--accordion-panel-width";var za=_t.forwardRef(function(t,o){let{className:a,hiddenUntilFound:n,keepMounted:i,id:r,render:s,style:f,...w}=t,{hiddenUntilFound:D,keepMounted:u}=wt(),{defaultPanelId:p,mounted:R,onOpenChange:z,open:m,setMounted:b,setOpen:C,setPanelIdState:E,transitionStatus:x}=gt(),I=n??D,O=i??u,ne=r||void 0,L=r??p;rt(()=>(E(y=>ne??(y===null?void 0:y)),()=>{E(y=>y===ne?null:y)}),[ne,E]);let{height:$,props:ie,ref:K,shouldPreventOpenAnimation:_,shouldRender:Ne,transitionStatus:G,width:le}=jo({externalRef:o,hiddenUntilFound:I,id:L,keepMounted:O,mounted:R,onOpenChange:z,open:m,setMounted:b,setOpen:C,transitionStatus:x}),{state:te,triggerId:fe}=Qe(),De={...te,transitionStatus:G},Ee=eo(f,De),ot=me("div",{...t,style:void 0},{state:De,ref:K,props:[ie,{"aria-labelledby":fe,role:"region",style:{[Ba]:$===void 0?"auto":`${$}px`,[_a]:le===void 0?"auto":`${le}px`}},w,Ee?{style:Ee}:void 0,_?{style:{animationName:"none"}}:void 0],stateAttributesMapping:xe});return Ne?ot:null});var ue=v(k(),1);function qa({className:e,...t}){return(0,ue.jsx)(Ae.Root,{"data-slot":"accordion",className:Ze("flex w-full flex-col",e),...t})}function ja({className:e,...t}){return(0,ue.jsx)(Ae.Item,{"data-slot":"accordion-item",className:Ze("not-last:border-b not-last:border-dashboard-border-subtle",e),...t})}function Ha({className:e,children:t,...o}){return(0,ue.jsx)(Ae.Header,{className:"flex",children:(0,ue.jsxs)(Ae.Trigger,{"data-slot":"accordion-trigger",className:Ze("group/accordion-trigger relative flex min-w-0 flex-1 cursor-pointer items-center justify-between gap-3 rounded-sm py-2.5 text-left font-sans text-sm font-medium text-dashboard-text transition-colors hover:text-dashboard-text-solid outline-none focus-visible:outline-2 focus-visible:outline-dashboard-focus aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-dashboard-text-muted",e),...o,children:[t,(0,ue.jsx)(io,{"data-slot":"accordion-trigger-icon",className:"pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"}),(0,ue.jsx)(ro,{"data-slot":"accordion-trigger-icon",className:"pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline"})]})})}function Wa({className:e,children:t,...o}){return(0,ue.jsx)(Ae.Panel,{"data-slot":"accordion-content",className:"h-(--accordion-panel-height) overflow-hidden text-sm transition-[height] duration-180 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",...o,children:(0,ue.jsx)("div",{className:Ze("pt-0 pb-2.5",e),children:t})})}var S=v(k(),1);function Ja({automation:e}){let t=e.kind==="event"&&e.trigger.problems.length>0;return(0,S.jsx)("span",{"aria-label":"Automation state","aria-live":"polite",role:"status",children:(0,S.jsx)(Ce,{size:"compact",tone:e.status==="paused"||e.status==="completed"?"neutral":e.status==="blocked"||t?"warning":"success",children:e.status==="active"&&t?"Trigger unavailable":e.status})})}function Ka({automation:e}){let t=e.lastRunStatus?`Last run ${e.lastRunStatus}`:"Last run";return(0,S.jsxs)("div",{className:"grid gap-1.5",children:[(0,S.jsx)(bn,{automation:e}),(0,S.jsx)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:e.lastRunAt?(0,S.jsxs)(S.Fragment,{children:[t," \xB7"," ",(0,S.jsx)("time",{dateTime:e.lastRunAt,title:X(e.lastRunAt),children:we(e.lastRunAt)})]}):e.lastRunStatus?`${t} \xB7 time not recorded`:e.totalRuns===0?"No runs yet":"Last run time not recorded"})]})}function Ya(e){if(e.status==="blocked"||e.status==="paused"&&e.statusReason)return"fix";if(e.kind==="event"&&e.trigger.problems.length>0)return"trigger";if(e.lastRunStatus==="failed"||e.lastRunStatus==="blocked")return"last_run"}function Ga(e){return Ya(e)!==void 0}function Qa({automation:e,editPath:t}){let o=Ya(e);if(!o)return null;let a=e.status==="paused",n=e.kind==="event"?e.trigger.problems:[],i=o==="fix",r=n.length>0,s=o==="last_run";return(0,S.jsxs)(B,{title:i?"Fix this before resuming":r?"Trigger unavailable":"Check the last run",children:[i?(0,S.jsxs)("p",{className:"m-0 break-words",children:[e.statusReason??"Check the last run to see what needs fixing."," ",!e.ownedByViewer&&e.credentialMode==="creator"?`It uses accounts connected by ${e.createdBy}. Ask them to resume it, or switch it to Junior's credentials first.`:null]}):null,r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("ul",{className:"my-1 list-disc pl-5",children:n.map(f=>(0,S.jsx)("li",{className:"break-words",children:f},f))}),(0,S.jsx)("p",{className:"m-0",children:"Edit the trigger, or enable its plugin again."})]}):null,s&&!i&&!r?(0,S.jsx)("p",{className:"m-0",children:e.status==="active"?"Future runs are still on.":a?"Review the last result before resuming.":"Review the last result for details."}):null,r?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:t,children:"Change trigger"}):e.lastConversationId?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:ut(e.lastConversationId),children:"Open last run"}):e.totalRuns>0?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:se(e.id,"runs"),children:"View run history"}):null]})}function bn({automation:e}){let t;if(e.status==="completed")t="No future runs";else if(e.status==="paused")t="No new runs while paused";else if(e.status==="blocked")t="New runs are blocked until this is fixed";else if(e.kind==="event")t=e.trigger.problems.length===0?"Waiting for a matching event":"Waiting for a trigger fix";else if(e.nextRunAt){let o=Intl.DateTimeFormat().resolvedOptions().timeZone,a=X(e.nextRunAt,e.timezone),n=X(e.nextRunAt,o),i=Date.parse(e.nextRunAt)<=Date.now()?"Run was due":"Next run";return(0,S.jsx)(qa,{children:(0,S.jsxs)(ja,{value:"next-run",children:[(0,S.jsx)(Ha,{className:"py-1 text-sm font-normal",children:(0,S.jsxs)("span",{children:[i," ",(0,S.jsx)("time",{dateTime:e.nextRunAt,children:we(e.nextRunAt)})]})}),(0,S.jsx)(Wa,{children:(0,S.jsxs)("dl",{className:"m-0 mt-1 grid gap-1 border-l border-dashboard-border pl-3 text-xs leading-relaxed",children:[(0,S.jsx)("dt",{className:"text-dashboard-text-muted",children:"Schedule time"}),(0,S.jsx)("dd",{className:"m-0",children:(0,S.jsx)("time",{dateTime:e.nextRunAt,children:a})}),n!==a?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("dt",{className:"mt-1 text-dashboard-text-muted",children:"Your time"}),(0,S.jsx)("dd",{className:"m-0",children:(0,S.jsx)("time",{dateTime:e.nextRunAt,children:n})})]}):null]})})]})})}else t="Next run not scheduled";return(0,S.jsx)("p",{className:"m-0 text-sm text-dashboard-text",children:t})}var h=v(k(),1);function Xa(e){let{automation:t}=e;return(0,h.jsxs)("div",{className:"grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10",children:[(0,h.jsxs)("div",{className:"grid min-w-0 content-start gap-6",children:[(0,h.jsx)(Qa,{automation:t,editPath:e.editPath}),(0,h.jsx)(xn,{automation:t}),(0,h.jsx)(Q,{padding:"sm",children:(0,h.jsx)(Ea,{automation:t})}),(0,h.jsx)("div",{className:"lg:hidden",children:(0,h.jsx)(Za,{automation:t})})]}),(0,h.jsxs)("aside",{"aria-label":"Automation status",className:"grid min-w-0 content-start gap-3 max-lg:row-start-1",children:[(0,h.jsx)(Ut,{title:"Status",children:(0,h.jsx)(Ka,{automation:t})}),(0,h.jsx)(yn,{automation:t,range:e.range}),(0,h.jsx)("div",{className:"max-lg:hidden",children:(0,h.jsx)(Za,{automation:t})})]})]})}function xn(e){let{automation:t}=e,o=t.ownedByViewer?"you":t.createdBy;return(0,h.jsxs)("div",{className:"min-w-0 [&>section:first-child]:border-t-0 [&>section:first-child]:pt-0",children:[(0,h.jsx)(ae,{title:"What to do",children:(0,h.jsx)("div",{className:"text-base leading-relaxed [overflow-wrap:anywhere]",children:(0,h.jsx)(ft,{mentions:t.mentions??[],text:t.instruction})})}),(0,h.jsx)(ae,{title:"When to run",children:t.kind==="scheduled"?(0,h.jsx)("p",{className:"m-0 text-sm",children:da(t)}):(0,h.jsxs)("div",{className:"grid gap-1 text-sm",children:[(0,h.jsx)("p",{className:"m-0 break-words",children:t.resource}),(0,h.jsx)("p",{className:"m-0 break-words text-dashboard-text-muted",children:t.trigger.events.join(", ")}),(0,h.jsx)(Ye,{filters:t.trigger.filters})]})}),(0,h.jsx)(ae,{title:"Where results go",children:(0,h.jsx)(ka,{outcomes:t.outcomes,destination:t.destination})}),(0,h.jsx)(ae,{title:"Credentials",children:(0,h.jsx)("p",{className:"m-0 text-sm",children:t.credentialMode==="creator"?`Uses accounts connected by ${o}.`:"System credentials only. Junior does not use anyone\u2019s connected accounts."})})]})}function yn(e){let{automation:t,range:o}=e,a=Oe(!0,t.id),n=a.data?vt({days:a.data.executionDays,hours:a.data.executionHours,sixHours:a.data.executionSixHours,range:o}).reduce((i,r)=>({blocked:i.blocked+r.blocked,failed:i.failed+r.failed}),{blocked:0,failed:0}):void 0;return(0,h.jsx)(Ut,{title:o===1?"Last 24 hours":`Last ${o} days`,children:(0,h.jsxs)("dl",{className:"m-0 grid grid-cols-2 gap-x-4 gap-y-3",children:[(0,h.jsx)(kt,{label:"Runs",value:t.runs[o]}),(0,h.jsx)(kt,{label:"Spend",value:Ve({total:t.costUsd[o]})}),(0,h.jsx)(kt,{label:"Failed",value:n?.failed??"\u2014"}),(0,h.jsx)(kt,{label:"Blocked",value:n?.blocked??"\u2014"})]})})}function Za(e){let{automation:t}=e,o=Pe(),n=mt(!0,t.id).data?.activeVersion;return(0,h.jsxs)(Ut,{title:"About",children:[(0,h.jsxs)("dl",{className:"m-0 grid gap-3 text-sm",children:[(0,h.jsx)(St,{label:"Created by",children:t.createdByEmail?(0,h.jsx)(W,{className:Xe,to:Eo(t.createdByEmail),children:t.ownedByViewer?"You":t.createdBy}):t.ownedByViewer?"You":t.createdBy}),(0,h.jsx)(St,{label:"Created",children:X(t.createdAt)}),(0,h.jsxs)(St,{label:"Destination",children:[t.destination.label," \xB7"," ",t.destination.visibility==="private"?"private":"public"]}),(0,h.jsx)(St,{label:"Version",children:(0,h.jsx)(W,{className:Xe,to:ke(se(t.id,"versions"),o.search),children:n?`Version ${n}`:"Version history"})})]}),t.ownedByViewer?null:(0,h.jsxs)("p",{className:"mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted",children:[t.destination.visibility==="private"?null:"You can edit, pause, or delete it because it is in a public channel. ","Only ",t.createdBy," can turn on their connected accounts, or resume or run it while it uses them."]})]})}function Ut(e){return(0,h.jsxs)(Q,{as:"section",padding:"sm",children:[(0,h.jsx)("h2",{className:"m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted",children:e.title}),e.children]})}function kt(e){return(0,h.jsxs)("div",{className:"min-w-0",children:[(0,h.jsx)("dt",{className:"text-xs text-dashboard-text-muted",children:e.label}),(0,h.jsx)("dd",{className:"m-0 mt-0.5 font-display text-xl font-light tabular-nums text-dashboard-text",children:e.value})]})}function St(e){return(0,h.jsxs)("div",{className:"grid min-w-0 gap-0.5",children:[(0,h.jsx)("dt",{className:"text-xs text-dashboard-text-muted",children:e.label}),(0,h.jsx)("dd",{className:"m-0 min-w-0 break-words",children:e.children})]})}var Rt=v(Y(),1);var H=v(k(),1),zt=[{color:"var(--color-emerald-300)",key:"completed",label:"Completed"},{color:"var(--color-rose-300)",key:"failed",label:"Failed"},{color:"var(--color-amber-300)",key:"blocked",label:"Blocked"}],An=Object.fromEntries(zt.map(e=>[e.key,{color:e.color,label:e.label}]));function en(e){let t=e.bucketUnit??"day",o=e.days,a=o.map(r=>r.completed+r.failed+r.blocked),n=Math.max(1,...a),i=a.some(r=>r>0);return(0,H.jsxs)(Q,{className:"min-h-[15rem] p-4 sm:p-5",children:[(0,H.jsxs)("div",{children:[(0,H.jsx)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:"Runs over time"}),(0,H.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:t==="hour"?"Terminal runs for this automation each hour.":t==="6hour"?"Terminal runs for this automation each 6 hours.":"Terminal runs for this automation each day."})]}),(0,H.jsx)(aa,{ariaLabel:"Automation execution status legend",items:zt}),(0,H.jsxs)("div",{className:"relative mt-3 overflow-hidden",children:[(0,H.jsx)(na,{className:"aspect-auto h-55 w-full",config:An,children:(0,H.jsxs)(Zo,{"aria-label":`Automation executions during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:o,margin:Xo,role:"img",children:[(0,H.jsx)(Go,{strokeDasharray:"3 5",vertical:!1}),(0,H.jsx)(ta,{maximum:n}),(0,H.jsx)(ea,{keys:o.map(r=>r.date)}),(0,H.jsx)(ia,{content:(0,H.jsx)(oa,{rows:r=>[["completed",r.completed],["failed",r.failed],["blocked",r.blocked],["total",r.completed+r.failed+r.blocked]]})}),zt.map(r=>(0,H.jsx)(Qo,{dataKey:r.key,fill:`var(--color-${r.key})`,fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,stackId:"status"},r.key))]})}),i?null:(0,H.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No automation executions in this period."})]})]})}var A=v(k(),1),jt="result",Nn=["","completed","failed","blocked"],tn="grid-cols-[minmax(0,1fr)_5.5rem_5.5rem_5.5rem_auto_2rem]";function on(e){let{automation:t}=e,o=Oe(!0,t.id),[a,n]=bt(jt,"",Nn),i=(0,Rt.useMemo)(()=>(o.data?.executions??[]).filter(f=>!a||f.status===a),[o.data,a]),r=(0,Rt.useMemo)(()=>(o.data?.executions??[]).map(f=>({...f,automationId:t.id,automationTitle:t.title,kind:t.kind})),[t,o.data]),s=ua(i.map(f=>f.executionId));return(0,A.jsxs)(ga,{details:s.runId?(0,A.jsx)(pa,{loading:!o.data&&!o.error,onClose:s.close,run:r.find(f=>f.executionId===s.runId),showAutomation:!1},s.runId):null,label:"Runs list",listRef:s.listRef,children:[e.header,o.data?(0,A.jsx)(wn,{data:o.data,executions:i,onResultChange:n,onRowsKeyDown:s.onRowsKeyDown,onSelect:s.toggle,range:e.range,result:a,selectedRunId:s.runId}):o.error?(0,A.jsxs)(We,{children:["Runs could not be loaded."," ",(0,A.jsx)(T,{onClick:()=>{o.refetch()},children:"Try again"})]}):(0,A.jsx)($e,{label:"Loading runs",variant:"list"})]})}function wn(e){let{data:t,range:o}=e,a=(0,Rt.useMemo)(()=>kn(t.executions),[t.executions]);return(0,A.jsxs)(A.Fragment,{children:[t.executionDays.length>0?(0,A.jsx)(en,{bucketUnit:Jo(o),days:vt({days:t.executionDays,hours:t.executionHours,sixHours:t.executionSixHours,range:o,emptySixHour:n=>({blocked:0,completed:0,date:n,failed:0})}),range:o}):null,(0,A.jsxs)("div",{className:"flex flex-wrap items-end justify-between gap-x-5 gap-y-3",children:[(0,A.jsx)(ra,{ariaLabel:"Run result",items:[{count:t.executions.length,label:"All",value:""},{count:a.completed,label:"Completed",value:"completed"},{count:a.failed,label:"Failed",value:"failed"},{count:a.blocked,label:"Blocked",value:"blocked"}],onChange:n=>e.onResultChange(n),value:e.result}),(0,A.jsxs)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:[t.automation.totalRuns," total \xB7 newest first"]})]}),e.executions.length===0?(0,A.jsx)(Q,{padding:"md",children:(0,A.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:t.executions.length===0?"This automation has not run yet.":`No ${e.result} runs in the loaded history.`})}):(0,A.jsx)(Q,{children:(0,A.jsx)("div",{className:"min-w-0 overflow-x-auto",children:(0,A.jsxs)("div",{className:"min-w-[36rem]",children:[(0,A.jsxs)("div",{"aria-hidden":"true",className:V("sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid",tn),children:[(0,A.jsx)("div",{children:"Run"}),(0,A.jsx)("div",{children:"Duration"}),(0,A.jsx)("div",{children:"Tokens"}),(0,A.jsx)("div",{children:"Cost"})]}),(0,A.jsx)("div",{className:"min-w-0",onKeyDown:e.onRowsKeyDown,role:"list",children:e.executions.map(n=>(0,A.jsx)(Cn,{execution:n,fallbackTitle:t.automation.title,onSelect:()=>e.onSelect(n.executionId),selected:e.selectedRunId===n.executionId},n.executionId))})]})})}),t.truncated?(0,A.jsx)("p",{className:"m-0 text-center text-xs text-dashboard-text-muted",children:"Showing the 100 most recent runs."}):null]})}function Cn(e){let{execution:t}=e,o=Ve(t.costUsd===void 0?void 0:{total:t.costUsd})||"\u2014",a=ct(t.durationMs)||"\u2014",n=t.totalTokens===void 0?"\u2014":Do(t.totalTokens),i=la(t.status);return(0,A.jsx)("div",{className:"border-b border-dashboard-border-subtle last:border-b-0","data-run-id":t.executionId,role:"listitem",children:(0,A.jsxs)(sa,{className:V("grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5",tn),onSelect:e.onSelect,selected:e.selected,children:[(0,A.jsxs)("button",{"aria-expanded":e.selected,className:"block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",onClick:e.onSelect,type:"button",children:[(0,A.jsxs)("span",{className:"flex min-w-0 items-center gap-2 overflow-hidden",children:[(0,A.jsx)(Lt,{className:"md:hidden",label:t.status,tone:i}),(0,A.jsx)("span",{className:"min-w-0 truncate text-sm font-medium leading-snug text-dashboard-text",children:ma(t,e.fallbackTitle)})]}),(0,A.jsxs)("span",{className:"mt-1 block truncate text-xs leading-relaxed text-dashboard-text-muted",children:[X(t.executedAt),t.automationVersion?` \xB7 Version ${t.automationVersion}`:null]}),t.error?(0,A.jsx)("span",{className:"mt-1 block truncate text-xs leading-relaxed text-rose-300",title:t.error,children:t.error}):null]}),(0,A.jsx)(qt,{label:"Duration",value:a}),(0,A.jsx)(qt,{label:"Tokens",value:n}),(0,A.jsx)(qt,{label:"Cost",value:o}),(0,A.jsx)("div",{className:"hidden justify-self-center md:block",children:(0,A.jsx)(Lt,{label:t.status,tone:i})}),(0,A.jsx)("div",{className:"max-md:hidden",children:(0,A.jsx)(fa,{conversationId:t.conversationId})})]})})}function qt(e){return(0,A.jsxs)("div",{className:"min-w-0 max-md:flex max-md:items-center max-md:gap-2",children:[(0,A.jsx)("div",{"aria-hidden":"true",className:"mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block",children:e.label}),(0,A.jsxs)("div",{className:"truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text",children:[(0,A.jsxs)("span",{className:"sr-only",children:[e.label,": "]}),e.value]})]})}function kn(e){return e.reduce((t,o)=>(t[o.status]+=1,t),{blocked:0,completed:0,failed:0})}var Wt=v(Y(),1);var l=v(k(),1),Tt="version";function an(e){let t=mt(!0,e.automation.id);return t.error?(0,l.jsxs)(We,{children:["Version history could not be loaded."," ",(0,l.jsx)(T,{onClick:()=>{t.refetch()},children:"Try again"})]}):t.data?(0,l.jsx)(Sn,{automation:e.automation,data:t.data}):(0,l.jsx)($e,{label:"Loading version history",variant:"list"})}function Sn(e){let{automation:t,data:o}=e,[a,n]=Qt(),i=pe(),[r,s]=(0,Wt.useState)(),[f,w]=(0,Wt.useState)(!1),D=t.status!=="completed",u=Number(a.get(Tt)),p=Math.max(0,o.versions.findIndex(x=>x.version===u)),R=o.versions[p],z=o.versions[p+1],m=x=>n(I=>{let O=new URLSearchParams(I);return O.set(Tt,String(x)),O},{replace:!0}),b=`/api/automations/${encodeURIComponent(t.id)}`,C=ge({mutationFn:async x=>{let I=await ce(re,`${b}/edit`);return Me(re,`${b}/versions/${x}/activate`,{revision:I.revision})},onMutate:()=>s(void 0),onSuccess:async(x,I)=>{s(I),await i.invalidateQueries({queryKey:["dashboard","automations"]})}});if(!R)return(0,l.jsx)(Q,{padding:"md",children:(0,l.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No versions are saved yet. Junior saves a version each time the settings change."})});let E=R.version===o.activeVersion;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"m-0 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted",children:D?"Each save creates a version. Making a version active saves its settings as a new version. It does not run the automation.":"This automation has completed. Its versions are read-only."}),r!==void 0?(0,l.jsxs)("p",{role:"status",className:"m-0 text-sm text-emerald-300",children:["Version ",r," is active again. It was saved as a new version."]}):null,(0,l.jsxs)("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[17rem_minmax(0,1fr)] lg:gap-6",children:[(0,l.jsxs)("nav",{"aria-label":"Versions",className:"min-w-0",children:[(0,l.jsx)("ol",{className:"m-0 grid list-none gap-1 p-0 max-lg:max-h-64 max-lg:overflow-y-auto",children:o.versions.map((x,I)=>(0,l.jsx)("li",{children:(0,l.jsx)(Rn,{active:x.version===o.activeVersion,changes:Fn(x,o.versions[I+1],o.truncated),onSelect:()=>m(x.version),selected:x.version===R.version,version:x})},x.version))}),o.truncated?(0,l.jsx)("p",{className:"m-0 mt-2 px-3 text-xs text-dashboard-text-muted",children:"Showing the 100 most recent versions."}):null]}),(0,l.jsxs)(Q,{as:"section",className:"min-w-0",padding:"none",variant:"default",children:[(0,l.jsxs)("header",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-dashboard-border-subtle px-4 py-4 sm:px-5",children:[(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsxs)("h2",{className:"m-0 font-display text-lg font-medium",children:["Version ",R.version]}),E?(0,l.jsx)(Ce,{size:"compact",tone:"success",children:"Active"}):null]}),(0,l.jsxs)("p",{className:"mt-1 mb-0 text-xs text-dashboard-text-muted",children:[nn(R)," \xB7"," ",X(R.createdAt),z?` \xB7 Compared with version ${z.version}`:""]})]}),D&&!E?(0,l.jsx)(T,{"aria-label":`Make version ${R.version} active`,disabled:C.isPending,onClick:()=>w(!0),children:C.isPending&&C.variables===R.version?"Saving\u2026":"Make active"}):null]}),C.error&&C.variables===R.version?(0,l.jsx)("div",{className:"px-4 pt-4 sm:px-5",children:(0,l.jsx)(B,{tone:"error",title:"This version could not be made active.",children:C.error instanceof oe?C.error.code==="conflict"?"The automation changed. Try again.":C.error.apiError??"Try again.":"Try again."})}):null,(0,l.jsx)(Tn,{automation:t,previous:z,version:R})]})]}),(0,l.jsx)(Be,{onOpenChange:w,open:f,children:(0,l.jsxs)(_e,{children:[(0,l.jsxs)(Ue,{children:["Make version ",R.version," active?"]}),(0,l.jsxs)(ze,{children:["Junior saves these settings as a new version. Future runs use them.",t.ownedByViewer?null:` Only ${t.createdBy} can turn on their connected accounts.`]}),(0,l.jsxs)(qe,{children:[(0,l.jsx)(He,{children:"Cancel"}),(0,l.jsx)(je,{onClick:()=>{C.mutate(R.version),w(!1)},variant:"primary",children:"Make active"})]})]})})]})}function Rn(e){let{version:t}=e;return(0,l.jsxs)("button",{"aria-current":e.selected?"true":void 0,className:V("grid w-full min-w-0 cursor-pointer gap-0.5 rounded-md border-0 px-3 py-2.5 text-left transition-colors focus-visible:outline-2 focus-visible:outline-dashboard-focus",e.selected?"bg-dashboard-accent/[0.08] text-dashboard-text":"bg-transparent text-dashboard-text hover:bg-dashboard-fill-soft"),onClick:e.onSelect,type:"button",children:[(0,l.jsxs)("span",{className:"flex items-center gap-2 text-sm font-medium",children:["Version ",t.version,e.active?(0,l.jsx)(Ce,{size:"compact",tone:"success",children:"Active"}):null]}),(0,l.jsxs)("span",{className:"truncate text-xs text-dashboard-text-muted",children:[nn(t)," \xB7"," ",(0,l.jsx)("time",{dateTime:t.createdAt,children:we(t.createdAt)})]}),e.changes?(0,l.jsx)("span",{className:"truncate text-xs text-dashboard-text-muted",children:e.changes}):null]})}var Jt=[{key:"title",label:"Title"},{key:"instruction",label:"What to do"},{key:"when",label:"When to run"},{key:"destination",label:"Destination"},{key:"outcomes",label:"Where results go"},{key:"credentialMode",label:"Credentials"}];function Tn(e){let{automation:t,previous:o,version:a}=e,n=o?rn(o,a):[];return(0,l.jsx)("dl",{className:"m-0 divide-y divide-dashboard-border-subtle",children:Jt.map(({key:i,label:r})=>{let s=n.includes(i);return(0,l.jsxs)("div",{className:V("grid min-w-0 gap-2 px-4 py-4 sm:grid-cols-[9rem_minmax(0,1fr)] sm:gap-6 sm:px-5",s&&"shadow-[inset_2px_0_0_var(--color-dashboard-accent)]"),children:[(0,l.jsxs)("dt",{className:"text-xs font-medium text-dashboard-text-muted",children:[r,s?(0,l.jsx)("span",{className:"mt-1 block font-normal text-dashboard-accent-text",children:"Changed"}):null]}),(0,l.jsx)("dd",{className:"m-0 min-w-0 text-sm leading-relaxed break-words",children:s&&o&&i==="instruction"?(0,l.jsx)(Dn,{after:a.definition.instruction,before:o.definition.instruction}):s&&o?(0,l.jsxs)("div",{className:"grid gap-2",children:[(0,l.jsxs)("div",{className:"text-dashboard-text-muted line-through decoration-dashboard-text-muted/50",children:[(0,l.jsx)("span",{className:"sr-only",children:"Before: "}),Ht(i,t,o)]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"sr-only",children:"After: "}),Ht(i,t,a)]})]}):Ht(i,t,a)})]},i)})})}function Ht(e,t,o){let{definition:a}=o;switch(e){case"title":return a.title??"First line of the instruction";case"instruction":return(0,l.jsx)(ft,{mentions:t.mentions,text:a.instruction});case"when":if(o.kind==="scheduled"){let{description:n,timezone:i}=o.definition.schedule;return n.includes(i)?n:`${n} (${i})`}return(0,l.jsxs)(l.Fragment,{children:[o.definition.trigger.label,o.definition.trigger.identifier?` \xB7 ${o.definition.trigger.identifier}`:null,(0,l.jsx)("br",{}),o.trigger.events.join(", "),(0,l.jsx)(Ye,{filters:o.trigger.filters})]});case"destination":return a.destination.channelId===t.destination.channelId&&a.destination.teamId===t.destination.teamId?t.destination.label:`Another destination \xB7 ${a.destination.channelId}`;case"outcomes":return a.outcomes.length?(0,l.jsx)("ol",{className:"m-0 grid list-decimal gap-1 pl-5",children:a.outcomes.map((n,i)=>(0,l.jsx)("li",{children:Se(n,t.destination)},i))}):"No message on success";case"credentialMode":return a.credentialMode==="creator"?`Uses accounts connected by ${t.ownedByViewer?"you":t.createdBy}.`:"System credentials only"}}function Dn(e){return(0,l.jsx)("div",{className:"grid overflow-hidden rounded-md border border-dashboard-border-subtle font-mono text-xs leading-relaxed",children:En(e.before,e.after).map((t,o)=>(0,l.jsxs)("div",{className:V("grid grid-cols-[1.5rem_minmax(0,1fr)] whitespace-pre-wrap px-2 py-0.5",t.kind==="added"&&"bg-emerald-500/10 text-emerald-200",t.kind==="removed"&&"bg-rose-500/10 text-rose-200"),children:[(0,l.jsx)("span",{"aria-hidden":"true",className:"select-none opacity-60",children:t.kind==="added"?"+":t.kind==="removed"?"\u2212":""}),(0,l.jsxs)("span",{children:[t.kind==="same"?null:(0,l.jsx)("span",{className:"sr-only",children:t.kind==="added"?"Added: ":"Removed: "}),t.value||" "]})]},o))})}function En(e,t){let o=e.split(`
1
+ import{a as B}from"./chunk-BKOACADP.js";import{a as ca,b as ua,c as ga,d as fa,e as pa,f as Lt}from"./chunk-RB5FBDEY.js";import{a as da,b as X,c as la,d as ma}from"./chunk-FSGVY7HB.js";import{a as sa}from"./chunk-SIOW7OOW.js";import{a as he}from"./chunk-4UGZNVJM.js";import{c as ra}from"./chunk-2J3LGF5Q.js";import{a as aa}from"./chunk-SUX4QBVF.js";import{a as Go,c as Qo,f as Zo,o as Xo,p as ea,q as ta,t as oa,w as na,x as ia}from"./chunk-K4TYMAA3.js";import{a as Ho,b as pt,c as ht}from"./chunk-HCLRG2EC.js";import{a as q,b as j,c as Je,d as tt,e as Wo}from"./chunk-PQPAPPEI.js";import{b as Le}from"./chunk-GYRM5ZIV.js";import{a as Oo,b as $o,c as Vo,e as Bo}from"./chunk-ZIJ6SJDN.js";import{a as Be,b as _e,c as Ue,d as ze,e as qe,f as je,g as He}from"./chunk-MKKFXRYO.js";import"./chunk-WLIOZO3W.js";import"./chunk-JVJ5UWIK.js";import{a as We}from"./chunk-XNR4RZEC.js";import"./chunk-FE522UEA.js";import"./chunk-G5NWYJTV.js";import{a as ut}from"./chunk-5ZA674OU.js";import{l as ft}from"./chunk-RGXXD4DM.js";import{j as Yo}from"./chunk-TFJOEF3Q.js";import{a as et,b as $e}from"./chunk-KDUTK357.js";import{a as _o,b as Uo,c as gt,d as zo,e as qo,f as jo}from"./chunk-6FSJ3W2W.js";import{a as Ce}from"./chunk-2BCS5AQL.js";import"./chunk-QOX5RMLM.js";import"./chunk-H76B43OQ.js";import{h as To,j as Oe,k as mt}from"./chunk-64GPEGGE.js";import"./chunk-ILH47V7O.js";import{K as Eo,O as se,g as we,k as ct,r as Do,z as Ve}from"./chunk-II4NXLSQ.js";import"./chunk-PXHLJIOT.js";import{i as co,j as uo,l as go}from"./chunk-GMZIELFU.js";import{l as Z}from"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import{d as pe,g as Fe,i as ge,p as oe,q as So,r as Me,t as Ro,v as ce}from"./chunk-4TQSTCIN.js";import{Ka as Q,U as re,V as No,W as wo,X as Co,Y as ko,l as fo,m as po,n as ho,o as vo,p as bo,q as xo,r as yo,s as Ao}from"./chunk-XDUSY26N.js";import"./chunk-QPBLZSNX.js";import{a as ke,c as bt}from"./chunk-RHMZNAJX.js";import{a as It}from"./chunk-GOTQ4D6W.js";import{C as Lo,D as Mo,G as Jo,K as vt,L as Ko,M as Pt,b as nt,d as Pe,f as it,g as Yt,i as Gt,k as Et,o as W,q as Qt,u as Po,x as Io}from"./chunk-6PHJZPWD.js";import"./chunk-T4M53QQT.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import{a as Ie,b as T}from"./chunk-CR2ICLSH.js";import{Ga as eo,Hc as lt,Ia as me,N as Xt,Na as to,Qa as Ze,Qc as Ft,Rc as V,Tc as Xe,Xa as oo,Xc as Fo,_a as ao,a as Y,b as k,d as Zt,fb as no,g as rt,h as st,ib as io,j as dt,lb as ro,lc as lo,pc as mo,sb as so}from"./chunk-YPMUHXYT.js";import{b as ln,c as v}from"./chunk-7SZRL6FY.js";var Dt=v(Y(),1);var M=v(k(),1);function ha({automation:e,editPath:t,editVariant:o,onDelete:a}){let n=Le(),i=pe(),r=e.status==="completed",s=e.status==="paused",f=e.status==="blocked",w=!r,D=s||f?"resume":"pause",u=ge({mutationFn:async()=>{let p=`/api/automations/${encodeURIComponent(e.id)}`,R=await ce(re,`${p}/edit`);if(R.status!==e.status)throw new Error("The Automation changed. Reload the page before trying again.");return Me(re,`${p}/lifecycle`,{action:D,revision:R.revision})},onSuccess:async p=>{await i.invalidateQueries({queryKey:["dashboard","automations"]}),n.add({title:p.status==="blocked"?"Automation is still blocked":D==="pause"?"Automation paused":"Automation resumed",description:p.status==="blocked"?"Fix the reported requirement before resuming again.":D==="pause"?"Work already queued or running may finish.":"Future triggers are enabled.",type:p.status==="blocked"?"warning":"success"})}});return(0,M.jsxs)("div",{className:"grid min-w-0 justify-items-stretch gap-3 md:justify-items-end",children:[(0,M.jsxs)("div",{"aria-label":"Automation actions",className:"flex flex-wrap items-center gap-2",role:"group",children:[r?null:(0,M.jsxs)(W,{className:Ie({variant:o}),to:t,children:[(0,M.jsx)(lo,{"aria-hidden":"true",size:14}),"Edit automation"]}),w?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(T,{disabled:u.isPending,onClick:()=>u.mutate(),children:u.isPending?"Updating\u2026":D==="pause"?"Pause":"Resume"}),(0,M.jsxs)(Oo,{children:[(0,M.jsx)($o,{render:(0,M.jsx)(T,{"aria-label":"About pausing",size:"icon"}),children:(0,M.jsx)(so,{"aria-hidden":"true",size:16})}),(0,M.jsx)(Vo,{side:"bottom",align:"end","aria-label":"About pausing",children:(0,M.jsxs)(Bo,{children:["Pausing stops new runs. Work already queued or running may finish. Resuming skips missed runs and waits for the next scheduled time or new event.",s&&e.statusReason?" Removing the pause keeps the block until you fix it and resume again.":""]})})]})]}):null,(0,M.jsxs)(co,{children:[(0,M.jsx)(uo,{render:(0,M.jsx)(T,{focusableWhenDisabled:!0,"aria-label":"Delete automation",size:"icon",variant:"danger",onClick:p=>a(p.currentTarget),disabled:u.isPending,children:(0,M.jsx)(lt,{"aria-hidden":"true",size:16})})}),(0,M.jsx)(go,{size:"compact",children:"Delete automation"})]})]}),u.error?(0,M.jsx)("div",{className:"max-w-sm",children:(0,M.jsx)(B,{tone:"error",title:"Could not update this automation.",children:u.error instanceof oe?u.error.apiError??"Try again.":u.error.message})}):null]})}var va=v(Y(),1);var de=v(k(),1);function ba(e){let[t,o]=(0,va.useState)(!0),a=pe(),n=Le(),i=ge({mutationFn:()=>Ro(`/api/automations/${encodeURIComponent(e.automation.id)}`),onSuccess:async()=>{await a.invalidateQueries({queryKey:["dashboard","automations"]}),e.onDeleted(),n.add({title:"Automation deleted",description:e.automation.title,type:"success"}),o(!1)}});return(0,de.jsx)(Be,{open:t,onOpenChange:(r,s)=>{i.isPending?s.cancel():o(r)},onOpenChangeComplete:r=>{r||e.onClose()},children:(0,de.jsxs)(_e,{finalFocus:e.returnFocus,children:[(0,de.jsx)(Ue,{children:"Delete automation?"}),(0,de.jsxs)(ze,{children:["Delete"," ",(0,de.jsx)("strong",{className:"font-medium text-dashboard-text",children:e.automation.title}),"? This removes the Automation and stops future triggers. Work already queued or running may finish."]}),i.error?(0,de.jsx)(B,{tone:"error",title:"The automation could not be deleted. Try again."}):null,(0,de.jsxs)(qe,{children:[(0,de.jsx)(He,{disabled:i.isPending,children:"Cancel"}),(0,de.jsx)(je,{variant:"danger",disabled:i.isPending,onClick:()=>i.mutate(),children:i.isPending?"Deleting\u2026":"Delete automation"})]})]})})}var ee=v(Y(),1);function Se(e,t){return typeof e.destination=="string"?e.destination==="task_creator"?"Creator \xB7 Direct message":`${t.label} \xB7 ${t.visibility}`:e.destination.channelId===t.channelId&&e.destination.teamId===t.teamId?`${t.label} \xB7 ${t.visibility}`:`Saved destination \xB7 ${e.destination.channelId}`}var xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];function Re(e){return{title:e.title??"",instruction:e.instruction,credentialMode:e.credentialMode,outcomes:e.outcomes,trigger:e.kind==="event"?e.trigger:void 0}}function Ke(e){let t=e.schedule.recurrence;if(e.schedule.kind==="recurring"&&t){let{time:o,weekdays:a,...n}=t;return{kind:"recurring",...n,timezone:e.schedule.timezone,time:`${String(o.hour).padStart(2,"0")}:${String(o.minute).padStart(2,"0")}`,weekdays:a?.flatMap(i=>xt[i]??[])}}if(e.nextRunAtMs){let o=new Intl.DateTimeFormat("en-CA",{timeZone:e.schedule.timezone,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e.nextRunAtMs),a=n=>o.find(i=>i.type===n)?.value??"";return{kind:"one_off",timezone:e.schedule.timezone,timing:{type:"at",date:`${a("year")}-${a("month")}-${a("day")}`,time:`${a("hour")}:${a("minute")}`}}}return{kind:"recurring",frequency:"daily",time:"09:00",timezone:e.schedule.timezone}}function xa(e,t){let o={};return t.title!==(e.title??"")&&(o.title=t.title),t.instruction!==e.instruction&&(o.instruction=t.instruction),t.credentialMode!==e.credentialMode&&(o.credentialMode=t.credentialMode),JSON.stringify(t.outcomes)!==JSON.stringify(e.outcomes)&&(o.outcomes=t.outcomes),e.kind==="scheduled"&&t.schedule&&(o.schedule=t.schedule),e.kind==="event"&&JSON.stringify(t.trigger)!==JSON.stringify(e.trigger)&&(o.trigger=t.trigger),o}var J=v(k(),1),Mt={title:"Title",instruction:"Instruction",schedule:"Schedule",trigger:"Trigger",outcomes:"Where results go",credentialMode:"Credentials"};function ya(e){let t=Object.keys(Mt).filter(n=>e.changes[n]!==void 0),o=mn(e.original),a=(n,i)=>cn(n,i,e.summary);return(0,J.jsx)("aside",{"aria-label":"Your changes",className:V("min-w-0 lg:sticky lg:top-4 lg:self-start",t.length===0&&"max-lg:hidden"),children:(0,J.jsxs)(Q,{padding:"sm",children:[(0,J.jsx)("h2",{className:"m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted",children:"Your changes"}),t.length===0?(0,J.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No changes yet. Edit a section to see it here."}):(0,J.jsx)("ul",{className:"m-0 grid list-none gap-3 p-0",children:t.map(n=>(0,J.jsxs)("li",{className:"grid min-w-0 gap-1 text-sm",children:[(0,J.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,J.jsx)("span",{className:"font-medium",children:Mt[n]}),(0,J.jsx)(T,{"aria-label":`Undo ${Mt[n].toLowerCase()} change`,disabled:e.disabled,onClick:()=>e.onUndo(n),children:"Undo"})]}),(0,J.jsxs)("p",{className:"m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs text-dashboard-text-muted line-through decoration-dashboard-text-muted/50",children:[(0,J.jsx)("span",{className:"sr-only",children:"Saved: "}),a(o,n)]}),(0,J.jsxs)("p",{className:"m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs",children:[(0,J.jsx)("span",{className:"sr-only",children:"New: "}),a(e.changes,n)]})]},n))}),(0,J.jsx)("p",{className:"mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted",children:"Saving creates a new version. It does not run this automation."})]})})}function mn(e){let t=Re(e);return e.kind==="scheduled"?{...t,schedule:Ke(e)}:t}function cn(e,t,o){switch(t){case"title":return e.title||"First line of the instruction";case"instruction":return e.instruction||"Empty";case"credentialMode":return e.credentialMode==="creator"?o.ownedByViewer?"Your connected accounts":`${o.createdBy}'s connected accounts`:"System credentials only";case"outcomes":return e.outcomes?.length?e.outcomes.map(a=>Se(a,o.destination)).join(", "):"No success message";case"schedule":return e.schedule?gn(e.schedule):"Not set";case"trigger":{let a=e.trigger;if(!a)return"Not set";let n=a.identifier?`${a.label} \xB7 ${a.identifier}`:`Any ${a.label}`,i=Object.keys(a.match??{}).length;return[n,a.events.join(", "),i?`${i} ${i===1?"filter":"filters"}`:""].filter(Boolean).join(" \xB7 ")}}}var un={daily:"day",weekly:"week",monthly:"month",yearly:"year"};function gn(e){if(e.kind==="one_off")return`Once on ${e.timing.date} at ${e.timing.time} (${e.timezone})`;let t=e.interval??1,o=un[e.frequency],a=t===1?o:`${t} ${o}s`,n=e.frequency==="weekly"&&e.weekdays?.length?` on ${e.weekdays.map(i=>i.slice(0,1).toUpperCase()+i.slice(1,3)).join(", ")}`:e.frequency==="monthly"&&e.dayOfMonth?` on day ${e.dayOfMonth}`:e.frequency==="yearly"&&e.month&&e.dayOfMonth?` on ${String(e.month).padStart(2,"0")}-${String(e.dayOfMonth).padStart(2,"0")}`:"";return`Every ${a}${n} at ${e.time} (${e.timezone})`}var ve=v(k(),1);function ae(e){return(0,ve.jsxs)("section",{className:V("grid min-w-0 gap-5 border-t border-dashboard-border-emphasis py-8 md:grid-cols-[12rem_minmax(0,1fr)] md:gap-10",e.changed&&"-ml-4 pl-4 shadow-[inset_2px_0_0_var(--color-dashboard-accent)] sm:-ml-5 sm:pl-5"),children:[(0,ve.jsxs)("div",{children:[(0,ve.jsx)("h2",{className:"m-0 font-display text-lg font-medium",children:e.title}),e.changed?(0,ve.jsx)("p",{className:"mt-1 mb-0 text-xs text-dashboard-accent-text",children:"Unsaved changes"}):null,e.detail?(0,ve.jsx)("p",{className:"mt-2 mb-0 text-sm leading-relaxed text-dashboard-text-muted",children:e.detail}):null]}),(0,ve.jsx)("div",{className:"grid min-w-0 content-start gap-5",children:e.children})]})}var yt=v(Y(),1);var g=v(k(),1);function Aa(e){let t=e.value??Ke(e.automation),[o,a]=(0,yt.useState)(e.value);(0,yt.useEffect)(()=>{let u=setTimeout(()=>a(e.value),300);return()=>clearTimeout(u)},[e.value]);let n=Co.safeParse(o),i=Fe({queryKey:["dashboard","automation-schedule-preview",e.automation.id,o],enabled:!!o&&n.success,retry:!1,queryFn:()=>Me(ko,`/api/automations/${encodeURIComponent(e.automation.id)}/preview`,o)}),r=t.kind==="recurring"?t.frequency:"once",s=t.kind==="recurring"?t.time:t.timing.time,f=e.value?i.data?.nextRunAtMs:e.automation.nextRunAtMs,w=e.value!==o||i.isFetching,D=i.error instanceof oe?i.error.apiError:i.error?"Schedule preview could not be loaded. Try again.":e.value&&!n.success&&!w?n.error.issues[0]?.message:void 0;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"grid grid-cols-1 items-start gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-frequency",children:"Repeat"}),(0,g.jsxs)(he,{id:"schedule-frequency",value:r,onChange:u=>{let p=u.target.value;p!=="once"&&p!=="daily"&&p!=="weekly"&&p!=="monthly"&&p!=="yearly"||e.onChange(p==="once"?{kind:"one_off",timezone:t.timezone??e.automation.schedule.timezone,timing:{type:"at",date:"",time:s}}:{kind:"recurring",timezone:t.timezone,time:s,frequency:p,interval:1,weekdays:p==="weekly"?["monday"]:void 0,dayOfMonth:["monthly","yearly"].includes(p)?1:void 0,month:p==="yearly"?1:void 0})},children:[(0,g.jsx)("option",{value:"once",children:"Once"}),(0,g.jsx)("option",{value:"daily",children:"Every day"}),(0,g.jsx)("option",{value:"weekly",children:"Every week"}),(0,g.jsx)("option",{value:"monthly",children:"Every month"}),(0,g.jsx)("option",{value:"yearly",children:"Every year"})]})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-time",children:"Time"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-time",type:"time",value:s,onChange:u=>e.onChange(t.kind==="recurring"?{...t,time:u.target.value}:{...t,timing:{type:"at",date:t.timing.date,time:u.target.value}})})]})]}),t.kind==="recurring"?(0,g.jsxs)(g.Fragment,{children:[t.frequency==="weekly"?(0,g.jsxs)("fieldset",{children:[(0,g.jsx)("legend",{className:"mb-2 text-sm font-semibold",children:"On"}),(0,g.jsx)(Lo,{className:"grid grid-cols-7 gap-1.5",multiple:!0,onValueChange:u=>e.onChange({...t,weekdays:u}),value:t.weekdays??[],children:[...xt.slice(1),xt[0]].map(u=>(0,g.jsx)(Mo,{"aria-label":u,className:"h-auto min-h-11 min-w-0 border-dashboard-border-emphasis px-1 capitalize data-pressed:border-dashboard-focus/50 data-pressed:bg-dashboard-focus/10 data-pressed:text-dashboard-focus sm:min-h-10 sm:text-sm",value:u,children:u.slice(0,3)},u))})]}):null,(0,g.jsxs)("div",{className:"grid grid-cols-1 items-start gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-interval",children:"Interval"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-interval",type:"number",min:1,max:365,value:t.interval??1,onChange:u=>e.onChange({...t,interval:u.target.valueAsNumber})}),(0,g.jsx)(Je,{id:"schedule-interval-help",children:"Number of calendar periods between runs."})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-start",children:"Start date"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-start",type:"date",value:t.startDate??"",onChange:u=>e.onChange({...t,startDate:u.target.value||void 0})})]})]}),t.frequency==="monthly"||t.frequency==="yearly"?(0,g.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-day",children:"Day of month"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-day",type:"number",min:1,max:31,value:t.dayOfMonth??1,onChange:u=>e.onChange({...t,dayOfMonth:u.target.valueAsNumber})})]}),t.frequency==="yearly"?(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-month",children:"Month"}),(0,g.jsx)(he,{id:"schedule-month",value:t.month??1,onChange:u=>e.onChange({...t,month:Number(u.target.value)}),children:Array.from({length:12},(u,p)=>(0,g.jsx)("option",{value:p+1,children:new Intl.DateTimeFormat("en",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2026,p,1)))},p))})]}):null]}):null]}):(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-date",children:"Date"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-date",type:"date",value:t.timing.date,onChange:u=>e.onChange({...t,timing:{type:"at",time:s,date:u.target.value}})})]}),(0,g.jsxs)(q,{children:[(0,g.jsx)(j,{htmlFor:"schedule-timezone",children:"Timezone"}),(0,g.jsx)(Z,{size:"comfortable",id:"schedule-timezone",list:"automation-timezones",value:t.timezone??"",onChange:u=>e.onChange({...t,timezone:u.target.value})}),(0,g.jsx)("datalist",{id:"automation-timezones",children:["UTC",...Intl.supportedValuesOf("timeZone")].map(u=>(0,g.jsx)("option",{children:u},u))}),(0,g.jsx)(Je,{id:"schedule-timezone-help",children:"Use an IANA timezone. The schedule follows local time, including daylight saving time."})]}),(0,g.jsxs)("div",{role:"status",className:"flex gap-3 rounded-md bg-dashboard-fill-soft p-3 text-sm leading-relaxed",children:[(0,g.jsx)(no,{"aria-hidden":!0,size:17,className:"mt-0.5 shrink-0 text-dashboard-text-muted"}),(0,g.jsx)("div",{children:w?"Checking schedule\u2026":D?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("span",{className:"text-rose-300",children:D}),i.error?(0,g.jsx)(T,{onClick:()=>{i.refetch()},children:"Try again"}):null]}):f?(0,g.jsxs)(g.Fragment,{children:["Next run"," ",new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short",timeZone:e.value?i.data?.schedule.timezone??"UTC":e.automation.schedule.timezone}).format(f)]}):"No next run."})]}),e.value?(0,g.jsx)(T,{className:"w-fit",onClick:()=>e.onChange(void 0),children:"Keep saved schedule"}):null]})}var wa=v(Y(),1);var Te=v(k(),1);function Ye(e){return e.filters.length===0?(0,Te.jsx)("p",{className:"m-0 mt-1 text-xs text-dashboard-text-muted",children:"No filters. Runs on every selected event."}):(0,Te.jsxs)("div",{className:"mt-1 text-xs text-dashboard-text-muted",children:[(0,Te.jsx)("p",{className:"m-0",children:"Every filter must match:"}),(0,Te.jsx)("ul",{className:"m-0 list-disc pl-5",children:e.filters.map(t=>(0,Te.jsx)("li",{className:"break-words",children:t},t))})]})}var c=v(k(),1),At="*",fn={resourceTypes:[],events:{},anyResourceFields:{}};function Na(e,t){let o=e.events[t]?.reach;if(typeof o!="object")return;let a=o.anyOf.map(n=>e.anyResourceFields[n]?.description??n);return a.length===1?`needs a filter: ${a[0]}`:`needs one of these filters: ${a.join("; or ")}`}function Ca(e){let[t,o]=(0,wa.useState)(),a=Fe({queryKey:["dashboard","automation-event-catalog"],queryFn:({signal:m})=>ce(wo,"/api/automations/event-catalog",m),retry:!1}),n=a.data?.find(m=>m.namespace===e.value.namespace),i=n??fn,r=n?.displayName??e.value.namespace,s=e.value.resourceType===void 0,f=ho(i,e.value),w=a.data?vo(i,e.value):[],D=!f||w.some(m=>m.reason!=="field_not_set"&&m.reason!=="filter_required"),u=a.data?.filter(m=>fo(m).length>0)??[],p=Object.entries(f?.fields??{}),R=p.filter(([m,b])=>e.value.match?.[m]!==void 0||po(b,e.value.events).length===0),z=(m,b)=>{let C={...e.value.match};b===void 0?delete C[m]:C[m]=b,e.onChange({...e.value,match:C})};return(0,c.jsxs)(c.Fragment,{children:[a.error?(0,c.jsxs)(B,{title:"Event choices could not be loaded.",children:["Saved values are kept."," ",(0,c.jsx)(T,{onClick:()=>{a.refetch()},children:"Try again"})]}):a.isPending?(0,c.jsx)("p",{role:"status",children:"Loading event choices\u2026"}):null,D&&a.data?(0,c.jsxs)(B,{title:"Saved trigger \xB7 Kept unchanged",children:["Some saved values are not in the current catalog. You can edit other fields, or select a new resource type to replace the trigger.",(0,c.jsx)(pn,{displayName:r,source:i,trigger:e.value})]}):null,(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-resource",children:D?"Replace trigger":"Resource type"}),(0,c.jsxs)(he,{id:"trigger-resource",value:D?"":`${e.value.namespace}:${e.value.resourceType??At}`,onChange:m=>{let[b,C]=m.target.value.split(":");if(C===At&&b){o({namespace:b,label:"",events:[]});return}let E=a.data?.find(x=>x.namespace===b)?.resourceTypes.find(x=>x.type===C);!b||!E||o({namespace:b,resourceType:E.type,identifier:"",label:"",events:[]})},children:[(0,c.jsx)("option",{value:"",disabled:!0,children:"Keep saved trigger"}),u.map(m=>(0,c.jsxs)("option",{value:`${m.namespace}:${At}`,children:[m.displayName," \xB7 any resource"]},`${m.namespace}:${At}`)),a.data?.flatMap(m=>m.resourceTypes.map(b=>(0,c.jsxs)("option",{value:`${m.namespace}:${b.type}`,children:[m.displayName," \xB7 ",b.type.replaceAll("_"," ")]},`${m.namespace}:${b.type}`)))]})]}),(0,c.jsx)(Be,{onOpenChange:m=>{m||o(void 0)},open:t!==void 0,children:(0,c.jsxs)(_e,{children:[(0,c.jsx)(Ue,{children:"Replace the saved trigger?"}),(0,c.jsx)(ze,{children:"Its resource, events, and filters will be cleared."}),(0,c.jsxs)(qe,{children:[(0,c.jsx)(He,{children:"Cancel"}),(0,c.jsx)(je,{onClick:()=>{t&&e.onChange(t),o(void 0)},variant:"primary",children:"Replace trigger"})]})]})}),!D&&f?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-label",children:s?"Trigger name":"Resource name"}),(0,c.jsx)(Z,{size:"comfortable",id:"trigger-label",value:e.value.label,onChange:m=>e.onChange({...e.value,label:m.target.value})})]}),s?(0,c.jsx)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:"Runs for every resource that the filters match."}):(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:"trigger-identifier",children:"Resource identifier"}),(0,c.jsx)(Z,{size:"comfortable",id:"trigger-identifier",value:e.value.identifier??"",onChange:m=>e.onChange({...e.value,identifier:m.target.value})}),(0,c.jsx)(Je,{id:"trigger-identifier-help",children:"Use the exact provider resource identifier, not its display name."})]}),(0,c.jsxs)("fieldset",{children:[(0,c.jsx)("legend",{className:"mb-2 text-sm font-semibold",children:"Run on these events"}),(0,c.jsx)("div",{className:"divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis",children:f.events.map(m=>(0,c.jsxs)("label",{className:"flex min-h-11 cursor-pointer items-start gap-3 px-3 py-3 text-sm",children:[(0,c.jsx)(Ho,{className:"mt-0.5",checked:e.value.events.includes(m),disabled:e.disabled,onCheckedChange:()=>e.onChange({...e.value,events:e.value.events.includes(m)?e.value.events.filter(b=>b!==m):[...e.value.events,m]})}),(0,c.jsxs)("span",{className:"min-w-0 break-words",children:[bo(m),s&&Na(i,m)?(0,c.jsxs)("span",{className:"text-dashboard-text-muted",children:[" ","\xB7 ",Na(i,m)]}):null]})]},m))})]}),p.length?(0,c.jsxs)("fieldset",{className:"grid gap-4",children:[(0,c.jsx)("legend",{className:"mb-3 text-sm font-semibold",children:"Filters"}),(0,c.jsxs)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:["Every filter must match. Leave a filter blank to match any value.",R.length<p.length?" Filters that a selected event does not set are hidden.":null]}),R.map(([m,b])=>{let C=e.value.match?.[m],E=w.find(x=>x.field===m);return(0,c.jsxs)(q,{children:[(0,c.jsx)(j,{htmlFor:`match-${m}`,children:m}),Array.isArray(C)?(0,c.jsxs)("div",{className:"text-sm",children:[(0,c.jsx)("span",{className:"break-all",children:xo(m,b,C)})," ",(0,c.jsx)(T,{onClick:()=>z(m,void 0),children:"Remove filter"})]}):b.kind==="boolean"||b.enum?(0,c.jsxs)(he,{id:`match-${m}`,value:C===void 0?"":String(C),onChange:x=>z(m,x.target.value===""?void 0:b.kind==="boolean"?x.target.value==="true":x.target.value),children:[(0,c.jsx)("option",{value:"",children:"Any value"}),(b.enum??["true","false"]).map(x=>(0,c.jsx)("option",{children:x},x))]}):(0,c.jsx)(Z,{size:"comfortable",id:`match-${m}`,type:b.kind==="number"?"number":"text",step:"any",value:C===void 0?"":String(C),onChange:x=>z(m,x.target.value===""?void 0:b.kind==="number"?x.target.valueAsNumber:x.target.value)}),b.description?(0,c.jsx)(Je,{id:`match-${m}-help`,children:b.description}):null,E?(0,c.jsx)(tt,{children:E.message}):null]},m)})]}):null]}):null,JSON.stringify(e.value)!==JSON.stringify(e.original)?(0,c.jsx)(T,{className:"w-fit",onClick:()=>e.onChange(e.original),children:"Keep saved trigger"}):null]})}function pn(e){let t=yo(e.source,e.trigger);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("ul",{className:"my-2 list-disc pl-5",children:t.problems.map(o=>(0,c.jsx)("li",{children:o},o))}),(0,c.jsxs)("div",{className:"text-xs",children:[(0,c.jsxs)("p",{className:"m-0 break-words",children:[e.displayName," \xB7"," ",e.trigger.resourceType?.replaceAll("_"," ")??"any resource",e.trigger.identifier?` \xB7 ${e.trigger.identifier}`:null]}),(0,c.jsx)("p",{className:"m-0 mt-1 break-words text-dashboard-text-muted",children:t.events.join(", ")}),(0,c.jsx)(Ye,{filters:t.filters})]})]})}var F=v(k(),1);function ka(e){return e.outcomes.length?(0,F.jsx)("ol",{className:"m-0 grid list-decimal gap-2 pl-5 text-sm",children:e.outcomes.map((t,o)=>(0,F.jsx)("li",{children:Se(t,e.destination)},o))}):(0,F.jsx)("p",{className:"m-0 text-sm",children:"No success message"})}function Sa(e){let t=e.original.length?e.original:[{action:"send_message",destination:"current_conversation"}],o=[...e.original.flatMap((a,n)=>typeof a.destination=="string"?[]:[{value:`saved:${n}`,label:Se(a,e.destination),outcome:a}]),{value:"current_conversation",label:`${e.destination.label} \xB7 ${e.destination.visibility}`,outcome:{action:"send_message",destination:"current_conversation"}},{value:"task_creator",label:"Creator \xB7 Direct message",outcome:{action:"send_message",destination:"task_creator"}}];return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(pt,{"aria-label":"Success messages",disabled:e.disabled,className:"flex flex-wrap gap-x-6 gap-y-3",onValueChange:a=>e.onChange(a?t:[]),value:e.value.length>0,children:[!0,!1].map(a=>(0,F.jsxs)("label",{className:"inline-flex min-h-8 cursor-pointer items-center gap-2 text-sm",children:[(0,F.jsx)(ht,{value:a}),a?"Send a message":"No success message"]},String(a)))}),e.value.length?(0,F.jsxs)("div",{className:"grid gap-4 sm:gap-2",children:[e.value.map((a,n)=>{let i=e.original.findIndex(r=>JSON.stringify(r)===JSON.stringify(a));return(0,F.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,F.jsxs)("span",{className:"w-4 text-xs text-dashboard-text-muted",children:[n+1,"."]}),(0,F.jsx)("div",{className:V("min-w-0 flex-1",e.value.length>1&&"order-last basis-full sm:order-none sm:basis-auto"),children:(0,F.jsx)(he,{"aria-label":`Message ${n+1} destination`,value:typeof a.destination=="string"?a.destination:`saved:${i}`,onChange:r=>{let s=o.find(f=>f.value===r.target.value);s&&e.onChange(e.value.map((f,w)=>w===n?s.outcome:f))},children:o.map(r=>(0,F.jsx)("option",{value:r.value,children:r.label},r.value))})}),e.value.length>1?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(T,{size:"icon",className:"ml-auto sm:ml-0","aria-label":`Move message ${n+1} up`,disabled:n===0,onClick:()=>{let r=[...e.value],s=r[n-1];s&&(r[n-1]=a,r[n]=s,e.onChange(r))},children:(0,F.jsx)(ao,{size:16})}),(0,F.jsx)(T,{size:"icon","aria-label":`Remove message ${n+1}`,onClick:()=>e.onChange(e.value.filter((r,s)=>s!==n)),children:(0,F.jsx)(lt,{size:16})})]}):null]},n)}),e.value.length<5?(0,F.jsxs)(T,{className:"w-fit",onClick:()=>e.onChange([...e.value,{action:"send_message",destination:"task_creator"}]),children:[(0,F.jsx)(mo,{size:15}),"Add message"]}):null]}):(0,F.jsx)("p",{className:"m-0 text-sm leading-relaxed text-dashboard-text-muted",children:"Junior still does the work. No message is sent after success."}),(0,F.jsxs)("p",{className:"m-0 text-xs leading-relaxed text-dashboard-text-muted",children:[e.value.length?"Messages are sent in this order. ":"","This does not limit actions in the instruction."]})]})}var d=v(k(),1);function Ta(e){let t=Le(),[o,a]=(0,ee.useState)(e.automation),[n,i]=(0,ee.useState)(()=>Re(e.automation)),[r,s]=(0,ee.useState)({}),[f,w]=(0,ee.useState)(),[D,u]=(0,ee.useState)(0),p=(0,ee.useRef)(null),R=(0,ee.useRef)(!1),z=it(),m=pe(),b=xa(o,n),C=Object.keys(b).length>0,E={kind:o.kind,revision:o.revision,...b},x=Gt(()=>C&&!R.current),I=(0,ee.useRef)(null);(0,ee.useEffect)(()=>{x.state==="blocked"&&I.current?.focus()},[x.state]);let O=`/api/automations/${encodeURIComponent(o.id)}`;(0,ee.useEffect)(()=>{let y=U=>{C&&!R.current&&(U.preventDefault(),U.returnValue="")};return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[C]);let ne=()=>requestAnimationFrame(()=>(p.current?.querySelector('[aria-invalid="true"]')??p.current?.querySelector("[data-save-error]"))?.focus()),L=ge({mutationFn:()=>So(re,O,E),onSuccess:async()=>{R.current=!0,await m.invalidateQueries({queryKey:["dashboard","automations"]}),t.add({title:"Automation saved",description:"Changes apply to future work.",type:"success"}),z(e.returnPath)},onError:y=>{s(y instanceof oe?y.fields??{}:{}),ne()}});function $(y){f&&(i(y?{...Re(f),...b}:Re(f)),a(f),w(void 0),L.reset(),s({}))}let ie=ge({mutationFn:()=>ce(re,`${O}/edit`),onSuccess:w}),K=L.error instanceof oe&&L.error.code==="conflict",_=y=>i(U=>({...U,...y})),Ne=y=>{_({[y]:Re(o)[y]}),u(U=>U+1)},G=y=>Object.entries(r).filter(([U])=>U===y||U.startsWith(`${y}.`)).flatMap(([,U])=>U).join(" ")||void 0,le=o.kind==="scheduled"?"schedule":"trigger",te=o.ownedByViewer,fe=e.summary.createdBy,De=!te&&o.credentialMode==="creator"&&(b.instruction!==void 0||b[le]!==void 0||b.outcomes!==void 0),Ee=G(le),ot=y=>({"aria-invalid":!!G(y)||void 0,"aria-describedby":G(y)?`${y}-error`:void 0});return(0,d.jsxs)("form",{ref:p,noValidate:!0,onSubmit:y=>{if(y.preventDefault(),L.isPending||K||!C)return;let U=No.safeParse(E);if(!U.success){let at={};for(let Kt of U.error.issues)(at[Kt.path.join(".")]??=[]).push(Kt.message);s(at),ne();return}s({}),L.mutate()},children:[x.state==="blocked"?(0,d.jsx)("div",{tabIndex:-1,ref:I,className:"mb-6 outline-none",children:(0,d.jsxs)(B,{title:"Discard unsaved changes?",children:[(0,d.jsx)("p",{children:"Your changes have not been saved."}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(T,{onClick:()=>x.reset(),children:"Keep editing"}),(0,d.jsx)(T,{onClick:()=>x.proceed(),children:"Discard changes"})]})]})}):null,L.error||Object.keys(r).length?(0,d.jsx)("div",{tabIndex:-1,"data-save-error":!0,className:"mb-6 outline-none",children:(0,d.jsxs)(B,{tone:K?"warning":"error",title:K?"This automation changed while you were editing.":"Changes could not be saved.",children:[(0,d.jsxs)("p",{className:"mt-1",children:["Your edits are still here."," ",K?"Review the latest version before saving again.":L.error instanceof oe?L.error.apiError:"Check the fields below, or try again."]}),K?(0,d.jsx)(T,{disabled:ie.isPending,onClick:()=>ie.mutate(),children:ie.isPending?"Loading\u2026":"Review latest version"}):null,ie.error?(0,d.jsx)("p",{role:"alert",children:"The latest version could not be loaded. Try again."}):null]})}):null,f?(0,d.jsx)("div",{className:"mb-6",children:(0,d.jsxs)(B,{title:"Compare your edits with the latest saved version",children:[(0,d.jsx)("p",{children:"Only the fields you changed are shown. Keeping your edits will replace these fields. Other saved fields stay unchanged."}),Object.entries(b).map(([y,U])=>(0,d.jsxs)("section",{className:"my-4",children:[(0,d.jsx)("h3",{className:"text-sm font-semibold capitalize",children:y==="credentialMode"?"Credentials":y}),(0,d.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{children:"Latest saved"}),(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm",children:Ra(y==="schedule"&&f.kind==="scheduled"?Ke(f):f[y])})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("p",{children:"Your edit"}),(0,d.jsx)("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm",children:Ra(U)})]})]})]},y)),(0,d.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,d.jsx)(T,{onClick:()=>$(!0),children:"Keep my changed fields"}),(0,d.jsx)(T,{onClick:()=>$(!1),children:"Use latest saved version"})]})]})}):null,te?null:(0,d.jsxs)("p",{className:"mt-0 mb-6 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted",children:[fe," created this automation. You can edit it because it is in a public channel. Only ",fe," can turn on their connected accounts. Version history keeps every saved change."]}),(0,d.jsxs)("div",{className:"grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10",children:[(0,d.jsxs)("fieldset",{disabled:L.isPending,className:"min-w-0 [&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",children:[(0,d.jsxs)(ae,{changed:b.title!==void 0||b.instruction!==void 0,title:"What to do",detail:"Give Junior a clear instruction and a name you can find later.",children:[(0,d.jsxs)(q,{children:[(0,d.jsx)(j,{htmlFor:"title",children:"Title"}),(0,d.jsx)(Z,{size:"comfortable",id:"title",value:n.title,placeholder:e.summary.title,onChange:y=>_({title:y.target.value}),...ot("title")}),(0,d.jsx)(tt,{id:"title-error",children:G("title")})]}),(0,d.jsxs)(q,{children:[(0,d.jsx)(j,{htmlFor:"instruction",children:"Instruction"}),(0,d.jsx)(Wo,{id:"instruction",rows:8,value:n.instruction,onChange:y=>_({instruction:y.target.value}),...ot("instruction"),className:"resize-y text-base leading-relaxed sm:text-sm"}),(0,d.jsxs)("p",{className:"m-0 text-right text-xs text-dashboard-text-muted",children:[n.instruction.length.toLocaleString()," / 4,000"]}),(0,d.jsx)(tt,{id:"instruction-error",children:G("instruction")})]})]}),(0,d.jsx)(ae,{changed:b[le]!==void 0,title:"When to run",detail:o.kind==="scheduled"?"Choose a schedule in a specific timezone.":"Run when a matching event occurs.",children:(0,d.jsxs)("div",{id:`${le}-error`,tabIndex:-1,"aria-invalid":!!Ee||void 0,className:"grid min-w-0 gap-5 outline-none",children:[Ee?(0,d.jsx)("p",{role:"alert",className:"m-0 text-sm text-rose-300",children:Ee}):null,o.kind==="scheduled"?(0,d.jsx)(Aa,{automation:o,value:n.schedule,onChange:y=>_({schedule:y})}):(0,d.jsx)(Ca,{value:n.trigger??o.trigger,original:o.trigger,disabled:L.isPending,onChange:y=>_({trigger:y})})]})}),(0,d.jsxs)(ae,{changed:b.outcomes!==void 0,title:"Where results go",detail:"Choose who gets a message after successful work.",children:[G("outcomes")?(0,d.jsx)("p",{role:"alert",className:"m-0 text-sm text-rose-300",children:G("outcomes")}):null,(0,d.jsx)(Sa,{value:n.outcomes,original:o.outcomes,destination:e.summary.destination,disabled:L.isPending,onChange:y=>_({outcomes:y})})]}),(0,d.jsxs)(ae,{changed:b.credentialMode!==void 0,title:"Credentials",detail:"Choose which connected accounts Junior can use.",children:[(0,d.jsx)(pt,{"aria-label":"Credential mode",disabled:L.isPending,className:"divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis",onValueChange:y=>_({credentialMode:y}),value:De?"system":n.credentialMode,children:[["creator",te?"Your connected accounts":`${fe}\u2019s connected accounts`,te?"Uses accounts connected by you, the creator.":`Uses accounts connected by ${fe}. Only ${fe} can turn this on.`],["system","System credentials only",te?"Does not use your connected accounts. Some work may not be possible.":"Does not use anyone\u2019s connected accounts. Some work may not be possible."]].map(([y,U,at])=>(0,d.jsxs)("label",{className:"flex cursor-pointer items-start gap-3 px-4 py-4 has-data-checked:bg-dashboard-fill-soft has-data-disabled:cursor-not-allowed has-data-disabled:opacity-60",children:[(0,d.jsx)(ht,{className:"mt-0.5",value:y,disabled:y==="creator"&&!te&&(o.credentialMode!=="creator"||De)}),(0,d.jsxs)("span",{children:[(0,d.jsx)("span",{className:"block text-sm font-medium",children:U}),(0,d.jsx)("span",{className:"mt-1 block text-xs leading-relaxed text-dashboard-text-muted",children:at})]})]},y))}),De?(0,d.jsxs)(B,{title:"Saving switches this automation to system credentials.",children:["Only ",fe," can let a changed instruction,",o.kind==="event"?" trigger,":" schedule,"," or result destination use their connected accounts."]}):null,G("credentialMode")?(0,d.jsx)("p",{role:"alert",children:G("credentialMode")}):null]})]},D),(0,d.jsx)(ya,{changes:b,disabled:L.isPending,onUndo:Ne,original:o,summary:e.summary})]}),(0,d.jsx)("p",{className:"mb-5 text-xs leading-relaxed text-dashboard-text-muted sm:hidden",children:"Changes apply to future work. Saving does not run this automation."}),(0,d.jsx)("div",{className:"sticky bottom-0 z-20 -mx-4 border-t border-dashboard-border-emphasis bg-dashboard-bg px-4 py-4 sm:-mx-8 sm:px-8",children:(0,d.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,d.jsxs)("div",{className:"min-w-0 flex-1",role:"status",children:[(0,d.jsx)("p",{className:"m-0 text-xs font-medium sm:text-sm",children:L.isPending?"Saving\u2026":C?"Unsaved changes":"Unchanged"}),(0,d.jsx)("p",{className:"mt-1 mb-0 hidden text-xs text-dashboard-text-muted sm:block",children:"Changes apply to future work. Saving does not run it."})]}),(0,d.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,d.jsx)(W,{to:e.returnPath,className:"inline-flex min-h-11 items-center rounded-md border border-dashboard-border-emphasis px-3 text-sm text-dashboard-text no-underline sm:min-h-9",children:"Cancel"}),(0,d.jsx)(T,{type:"submit",variant:"primary",className:"min-h-11 sm:min-h-9",disabled:!C||L.isPending||K,children:"Save changes"})]})]})})]})}function Ra(e){return e==null?"Not set":typeof e=="string"?e:JSON.stringify(e,null,2)}var Ge=v(k(),1);function Da(){return(0,Ge.jsx)("div",{role:"status","aria-label":"Loading automation editor",children:["What to do","When to run","Where results go","Credentials"].map((e,t)=>(0,Ge.jsxs)(ae,{title:e,children:[(0,Ge.jsx)(et,{className:"h-4 w-24"}),(0,Ge.jsx)(et,{className:t===0?"h-48 w-full":"h-20 w-full"})]},e))})}var P=v(k(),1);function Ea({automation:e}){let t=Oe(!0,e.id),o=t.data?.executions.slice(0,3)??[];return(0,P.jsxs)("section",{"aria-label":"Recent runs",className:"grid min-w-0 gap-2.5",children:[(0,P.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,P.jsx)("h3",{className:"m-0 text-xs font-medium text-dashboard-text-muted",children:"Recent runs"}),e.totalRuns>0||o.length>0?(0,P.jsx)(W,{className:`${Xe} text-xs`,to:se(e.id,"runs"),children:"View all runs"}):null]}),t.isPending?(0,P.jsxs)("div",{"aria-busy":"true",role:"status",className:"grid gap-2",children:[(0,P.jsx)("span",{className:"sr-only",children:"Loading recent runs"}),Array.from({length:3},(a,n)=>(0,P.jsx)(et,{className:"h-14 rounded-md"},n))]}):null,t.error?(0,P.jsxs)(We,{children:["Recent runs could not be loaded."," ",(0,P.jsx)(T,{onClick:()=>{t.refetch()},children:"Try again"})]}):null,t.data&&o.length===0?(0,P.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:e.totalRuns===0?"No runs yet. Results will appear here after the first run.":"No recent runs are available. Older run details may have expired."}):null,o.length>0?(0,P.jsx)("ol",{className:"m-0 list-none divide-y divide-dashboard-border-subtle p-0",children:o.map(a=>{let n=[a.durationMs!==void 0?ct(a.durationMs):void 0,a.costUsd!==void 0?Ve({total:a.costUsd}):void 0].filter(Boolean).join(" \xB7 "),i=a.title!==e.title?a.title:void 0,r=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[(0,P.jsx)(Ce,{size:"compact",tone:a.status==="completed"?"success":a.status==="failed"?"danger":"warning",children:a.status}),(0,P.jsx)("time",{className:"text-xs text-dashboard-text-muted",dateTime:a.executedAt,title:X(a.executedAt),children:we(a.executedAt)})]}),i||n?(0,P.jsxs)("div",{className:"flex min-w-0 items-baseline justify-between gap-3 text-xs text-dashboard-text-muted",children:[i?(0,P.jsx)("p",{className:"m-0 min-w-0 truncate text-dashboard-text",title:i,children:i}):null,n?(0,P.jsx)("p",{className:"m-0 shrink-0 tabular-nums",children:n}):null]}):null,a.conversationId?null:(0,P.jsx)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:"No Conversation recorded"})]}),s="grid min-w-0 gap-1 rounded-md px-2 py-2.5";return(0,P.jsx)("li",{children:a.conversationId?(0,P.jsx)(W,{"aria-label":`Open ${a.status} run from ${X(a.executedAt)}`,className:`${s} text-inherit no-underline transition-colors hover:bg-dashboard-fill-hover focus-visible:outline-2 focus-visible:outline-dashboard-focus`,to:ut(a.conversationId),children:r}):(0,P.jsx)("div",{className:s,children:r})},a.executionId)})}):null]})}var Ae={};ln(Ae,{Header:()=>Oa,Item:()=>La,Panel:()=>za,Root:()=>Fa,Trigger:()=>Va});var be=v(Y(),1);var Nt=v(Y(),1),Ot=Nt.createContext(void 0);function wt(){let e=Nt.useContext(Ot);if(e===void 0)throw new Error(st(10));return e}var $t=v(k(),1),hn={value:()=>null},Fa=be.forwardRef(function(t,o){let{render:a,className:n,disabled:i=!1,hiddenUntilFound:r,keepMounted:s,loopFocus:f,onValueChange:w,multiple:D=!1,orientation:u="vertical",value:p,defaultValue:R,style:z,...m}=t,b=R??Zt,C=be.useRef([]),[E,x]=Fo({controlled:p,default:b,name:"Accordion",state:"value"}),I=dt(($,ie,K)=>{let _;D?ie?_=[...E,$]:_=E.filter(Ne=>Ne!==$):_=E[0]===$?[]:[$],w?.(_,K),!K.isCanceled&&x(_)}),O=be.useMemo(()=>({value:E,disabled:i,orientation:u}),[E,i,u]),ne=be.useMemo(()=>({disabled:i,handleValueChange:I,hiddenUntilFound:r??!1,keepMounted:s??!1,state:O,value:E}),[i,I,r,s,O,E]),L=me("div",t,{state:O,ref:o,props:m,stateAttributesMapping:hn});return(0,$t.jsx)(Ot.Provider,{value:ne,children:(0,$t.jsx)(Io,{elementsRef:C,children:L})})});var ye=v(Y(),1);var Ct=v(Y(),1),Vt=Ct.createContext(void 0);function Qe(){let e=Ct.useContext(Vt);if(e===void 0)throw new Error(st(9));return e}var Pa="data-index";var xe={...qo,index:e=>({[Pa]:String(e)}),...Xt,value:()=>null};var Bt=v(k(),1),La=ye.forwardRef(function(t,o){let{className:a,disabled:n=!1,onOpenChange:i,render:r,value:s,style:f,...w}=t,{ref:D,index:u}=Po(),{disabled:p,handleValueChange:R,state:z,value:m}=wt(),b=Ft(),C=s??b,E=n||p,x=m.includes(C),I=dt((le,te)=>{i?.(le,te),!te.isCanceled&&R(C,le,te)}),O=_o({open:x,onOpenChange:I,disabled:E}),ne=ye.useMemo(()=>({...O,onOpenChange:I,state:{open:O.open,disabled:O.disabled,transitionStatus:O.transitionStatus}}),[O,I]),L=ye.useMemo(()=>({...z,hidden:!x&&!O.mounted,index:u,disabled:E,open:x}),[O.mounted,E,u,x,z]),$=Ft(),[ie,K]=ye.useState(),_=ie===null?void 0:ie??$,Ne=ye.useMemo(()=>({defaultTriggerId:$,open:x,state:L,setTriggerId:K,triggerId:_}),[$,x,L,K,_]),G=me("div",t,{state:L,ref:[o,D],props:w,stateAttributesMapping:xe});return(0,Bt.jsx)(Uo.Provider,{value:ne,children:(0,Bt.jsx)(Vt.Provider,{value:Ne,children:G})})});var Ma=v(Y(),1);var Oa=Ma.forwardRef(function(t,o){let{render:a,className:n,style:i,...r}=t,{state:s}=Qe();return me("h3",t,{state:s,ref:o,props:r,stateAttributesMapping:xe})});var $a=v(Y(),1);var vn={...xe,...zo},Va=$a.forwardRef(function(t,o){let{disabled:a,className:n,id:i,render:r,nativeButton:s=!0,style:f,...w}=t,{panelId:D,open:u,handleTrigger:p,disabled:R}=gt(),z=a||R,{getButtonProps:m,buttonRef:b}=to({disabled:z,native:s}),{defaultTriggerId:C,state:E,setTriggerId:x}=Qe(),I=i||void 0,O=I??C;return rt(()=>(x($=>I??($===null?void 0:$)),()=>{x($=>$===I?null:$)}),[I,x]),me("button",t,{state:E,ref:[o,b],props:[{"aria-controls":u?D:void 0,"aria-expanded":u,id:O,onClick:p},w,m],stateAttributesMapping:vn})});var _t=v(Y(),1);var Ba="--accordion-panel-height",_a="--accordion-panel-width";var za=_t.forwardRef(function(t,o){let{className:a,hiddenUntilFound:n,keepMounted:i,id:r,render:s,style:f,...w}=t,{hiddenUntilFound:D,keepMounted:u}=wt(),{defaultPanelId:p,mounted:R,onOpenChange:z,open:m,setMounted:b,setOpen:C,setPanelIdState:E,transitionStatus:x}=gt(),I=n??D,O=i??u,ne=r||void 0,L=r??p;rt(()=>(E(y=>ne??(y===null?void 0:y)),()=>{E(y=>y===ne?null:y)}),[ne,E]);let{height:$,props:ie,ref:K,shouldPreventOpenAnimation:_,shouldRender:Ne,transitionStatus:G,width:le}=jo({externalRef:o,hiddenUntilFound:I,id:L,keepMounted:O,mounted:R,onOpenChange:z,open:m,setMounted:b,setOpen:C,transitionStatus:x}),{state:te,triggerId:fe}=Qe(),De={...te,transitionStatus:G},Ee=eo(f,De),ot=me("div",{...t,style:void 0},{state:De,ref:K,props:[ie,{"aria-labelledby":fe,role:"region",style:{[Ba]:$===void 0?"auto":`${$}px`,[_a]:le===void 0?"auto":`${le}px`}},w,Ee?{style:Ee}:void 0,_?{style:{animationName:"none"}}:void 0],stateAttributesMapping:xe});return Ne?ot:null});var ue=v(k(),1);function qa({className:e,...t}){return(0,ue.jsx)(Ae.Root,{"data-slot":"accordion",className:Ze("flex w-full flex-col",e),...t})}function ja({className:e,...t}){return(0,ue.jsx)(Ae.Item,{"data-slot":"accordion-item",className:Ze("not-last:border-b not-last:border-dashboard-border-subtle",e),...t})}function Ha({className:e,children:t,...o}){return(0,ue.jsx)(Ae.Header,{className:"flex",children:(0,ue.jsxs)(Ae.Trigger,{"data-slot":"accordion-trigger",className:Ze("group/accordion-trigger relative flex min-w-0 flex-1 cursor-pointer items-center justify-between gap-3 rounded-sm py-2.5 text-left font-sans text-sm font-medium text-dashboard-text transition-colors hover:text-dashboard-text-solid outline-none focus-visible:outline-2 focus-visible:outline-dashboard-focus aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-dashboard-text-muted",e),...o,children:[t,(0,ue.jsx)(io,{"data-slot":"accordion-trigger-icon",className:"pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"}),(0,ue.jsx)(ro,{"data-slot":"accordion-trigger-icon",className:"pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline"})]})})}function Wa({className:e,children:t,...o}){return(0,ue.jsx)(Ae.Panel,{"data-slot":"accordion-content",className:"h-(--accordion-panel-height) overflow-hidden text-sm transition-[height] duration-180 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",...o,children:(0,ue.jsx)("div",{className:Ze("pt-0 pb-2.5",e),children:t})})}var S=v(k(),1);function Ja({automation:e}){let t=e.kind==="event"&&e.trigger.problems.length>0;return(0,S.jsx)("span",{"aria-label":"Automation state","aria-live":"polite",role:"status",children:(0,S.jsx)(Ce,{size:"compact",tone:e.status==="paused"||e.status==="completed"?"neutral":e.status==="blocked"||t?"warning":"success",children:e.status==="active"&&t?"Trigger unavailable":e.status})})}function Ka({automation:e}){let t=e.lastRunStatus?`Last run ${e.lastRunStatus}`:"Last run";return(0,S.jsxs)("div",{className:"grid gap-1.5",children:[(0,S.jsx)(bn,{automation:e}),(0,S.jsx)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:e.lastRunAt?(0,S.jsxs)(S.Fragment,{children:[t," \xB7"," ",(0,S.jsx)("time",{dateTime:e.lastRunAt,title:X(e.lastRunAt),children:we(e.lastRunAt)})]}):e.lastRunStatus?`${t} \xB7 time not recorded`:e.totalRuns===0?"No runs yet":"Last run time not recorded"})]})}function Ya(e){if(e.status==="blocked"||e.status==="paused"&&e.statusReason)return"fix";if(e.kind==="event"&&e.trigger.problems.length>0)return"trigger";if(e.lastRunStatus==="failed"||e.lastRunStatus==="blocked")return"last_run"}function Ga(e){return Ya(e)!==void 0}function Qa({automation:e,editPath:t}){let o=Ya(e);if(!o)return null;let a=e.status==="paused",n=e.kind==="event"?e.trigger.problems:[],i=o==="fix",r=n.length>0,s=o==="last_run";return(0,S.jsxs)(B,{title:i?"Fix this before resuming":r?"Trigger unavailable":"Check the last run",children:[i?(0,S.jsxs)("p",{className:"m-0 break-words",children:[e.statusReason??"Check the last run to see what needs fixing."," ",!e.ownedByViewer&&e.credentialMode==="creator"?`It uses accounts connected by ${e.createdBy}. Ask them to resume it, or switch it to Junior's credentials first.`:null]}):null,r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("ul",{className:"my-1 list-disc pl-5",children:n.map(f=>(0,S.jsx)("li",{className:"break-words",children:f},f))}),(0,S.jsx)("p",{className:"m-0",children:"Edit the trigger, or enable its plugin again."})]}):null,s&&!i&&!r?(0,S.jsx)("p",{className:"m-0",children:e.status==="active"?"Future runs are still on.":a?"Review the last result before resuming.":"Review the last result for details."}):null,r?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:t,children:"Change trigger"}):e.lastConversationId?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:ut(e.lastConversationId),children:"Open last run"}):e.totalRuns>0?(0,S.jsx)(W,{className:V(Ie({variant:"primary"}),"mt-3"),to:se(e.id,"runs"),children:"View run history"}):null]})}function bn({automation:e}){let t;if(e.status==="completed")t="No future runs";else if(e.status==="paused")t="No new runs while paused";else if(e.status==="blocked")t="New runs are blocked until this is fixed";else if(e.kind==="event")t=e.trigger.problems.length===0?"Waiting for a matching event":"Waiting for a trigger fix";else if(e.nextRunAt){let o=Intl.DateTimeFormat().resolvedOptions().timeZone,a=X(e.nextRunAt,e.timezone),n=X(e.nextRunAt,o),i=Date.parse(e.nextRunAt)<=Date.now()?"Run was due":"Next run";return(0,S.jsx)(qa,{children:(0,S.jsxs)(ja,{value:"next-run",children:[(0,S.jsx)(Ha,{className:"py-1 text-sm font-normal",children:(0,S.jsxs)("span",{children:[i," ",(0,S.jsx)("time",{dateTime:e.nextRunAt,children:we(e.nextRunAt)})]})}),(0,S.jsx)(Wa,{children:(0,S.jsxs)("dl",{className:"m-0 mt-1 grid gap-1 border-l border-dashboard-border pl-3 text-xs leading-relaxed",children:[(0,S.jsx)("dt",{className:"text-dashboard-text-muted",children:"Schedule time"}),(0,S.jsx)("dd",{className:"m-0",children:(0,S.jsx)("time",{dateTime:e.nextRunAt,children:a})}),n!==a?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("dt",{className:"mt-1 text-dashboard-text-muted",children:"Your time"}),(0,S.jsx)("dd",{className:"m-0",children:(0,S.jsx)("time",{dateTime:e.nextRunAt,children:n})})]}):null]})})]})})}else t="Next run not scheduled";return(0,S.jsx)("p",{className:"m-0 text-sm text-dashboard-text",children:t})}var h=v(k(),1);function Xa(e){let{automation:t}=e;return(0,h.jsxs)("div",{className:"grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10",children:[(0,h.jsxs)("div",{className:"grid min-w-0 content-start gap-6",children:[(0,h.jsx)(Qa,{automation:t,editPath:e.editPath}),(0,h.jsx)(xn,{automation:t}),(0,h.jsx)(Q,{padding:"sm",children:(0,h.jsx)(Ea,{automation:t})}),(0,h.jsx)("div",{className:"lg:hidden",children:(0,h.jsx)(Za,{automation:t})})]}),(0,h.jsxs)("aside",{"aria-label":"Automation status",className:"grid min-w-0 content-start gap-3 max-lg:row-start-1",children:[(0,h.jsx)(Ut,{title:"Status",children:(0,h.jsx)(Ka,{automation:t})}),(0,h.jsx)(yn,{automation:t,range:e.range}),(0,h.jsx)("div",{className:"max-lg:hidden",children:(0,h.jsx)(Za,{automation:t})})]})]})}function xn(e){let{automation:t}=e,o=t.ownedByViewer?"you":t.createdBy;return(0,h.jsxs)("div",{className:"min-w-0 [&>section:first-child]:border-t-0 [&>section:first-child]:pt-0",children:[(0,h.jsx)(ae,{title:"What to do",children:(0,h.jsx)("div",{className:"text-base leading-relaxed [overflow-wrap:anywhere]",children:(0,h.jsx)(ft,{mentions:t.mentions??[],text:t.instruction})})}),(0,h.jsx)(ae,{title:"When to run",children:t.kind==="scheduled"?(0,h.jsx)("p",{className:"m-0 text-sm",children:da(t)}):(0,h.jsxs)("div",{className:"grid gap-1 text-sm",children:[(0,h.jsx)("p",{className:"m-0 break-words",children:t.resource}),(0,h.jsx)("p",{className:"m-0 break-words text-dashboard-text-muted",children:t.trigger.events.join(", ")}),(0,h.jsx)(Ye,{filters:t.trigger.filters})]})}),(0,h.jsx)(ae,{title:"Where results go",children:(0,h.jsx)(ka,{outcomes:t.outcomes,destination:t.destination})}),(0,h.jsx)(ae,{title:"Credentials",children:(0,h.jsx)("p",{className:"m-0 text-sm",children:t.credentialMode==="creator"?`Uses accounts connected by ${o}.`:"System credentials only. Junior does not use anyone\u2019s connected accounts."})})]})}function yn(e){let{automation:t,range:o}=e,a=Oe(!0,t.id),n=a.data?vt({days:a.data.executionDays,hours:a.data.executionHours,sixHours:a.data.executionSixHours,range:o}).reduce((i,r)=>({blocked:i.blocked+r.blocked,failed:i.failed+r.failed}),{blocked:0,failed:0}):void 0;return(0,h.jsx)(Ut,{title:o===1?"Last 24 hours":`Last ${o} days`,children:(0,h.jsxs)("dl",{className:"m-0 grid grid-cols-2 gap-x-4 gap-y-3",children:[(0,h.jsx)(kt,{label:"Runs",value:t.runs[o]}),(0,h.jsx)(kt,{label:"Spend",value:Ve({total:t.costUsd[o]})}),(0,h.jsx)(kt,{label:"Failed",value:n?.failed??"\u2014"}),(0,h.jsx)(kt,{label:"Blocked",value:n?.blocked??"\u2014"})]})})}function Za(e){let{automation:t}=e,o=Pe(),n=mt(!0,t.id).data?.activeVersion;return(0,h.jsxs)(Ut,{title:"About",children:[(0,h.jsxs)("dl",{className:"m-0 grid gap-3 text-sm",children:[(0,h.jsx)(St,{label:"Created by",children:t.createdByEmail?(0,h.jsx)(W,{className:Xe,to:Eo(t.createdByEmail),children:t.ownedByViewer?"You":t.createdBy}):t.ownedByViewer?"You":t.createdBy}),(0,h.jsx)(St,{label:"Created",children:X(t.createdAt)}),(0,h.jsxs)(St,{label:"Destination",children:[t.destination.label," \xB7"," ",t.destination.visibility==="private"?"private":"public"]}),(0,h.jsx)(St,{label:"Version",children:(0,h.jsx)(W,{className:Xe,to:ke(se(t.id,"versions"),o.search),children:n?`Version ${n}`:"Version history"})})]}),t.ownedByViewer?null:(0,h.jsxs)("p",{className:"mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted",children:[t.destination.visibility==="private"?null:"You can edit, pause, or delete it because it is in a public channel. ","Only ",t.createdBy," can turn on their connected accounts, or resume or run it while it uses them."]})]})}function Ut(e){return(0,h.jsxs)(Q,{as:"section",padding:"sm",children:[(0,h.jsx)("h2",{className:"m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted",children:e.title}),e.children]})}function kt(e){return(0,h.jsxs)("div",{className:"min-w-0",children:[(0,h.jsx)("dt",{className:"text-xs text-dashboard-text-muted",children:e.label}),(0,h.jsx)("dd",{className:"m-0 mt-0.5 font-display text-xl font-light tabular-nums text-dashboard-text",children:e.value})]})}function St(e){return(0,h.jsxs)("div",{className:"grid min-w-0 gap-0.5",children:[(0,h.jsx)("dt",{className:"text-xs text-dashboard-text-muted",children:e.label}),(0,h.jsx)("dd",{className:"m-0 min-w-0 break-words",children:e.children})]})}var Rt=v(Y(),1);var H=v(k(),1),zt=[{color:"var(--color-emerald-300)",key:"completed",label:"Completed"},{color:"var(--color-rose-300)",key:"failed",label:"Failed"},{color:"var(--color-amber-300)",key:"blocked",label:"Blocked"}],An=Object.fromEntries(zt.map(e=>[e.key,{color:e.color,label:e.label}]));function en(e){let t=e.bucketUnit??"day",o=e.days,a=o.map(r=>r.completed+r.failed+r.blocked),n=Math.max(1,...a),i=a.some(r=>r>0);return(0,H.jsxs)(Q,{className:"min-h-[15rem] p-4 sm:p-5",children:[(0,H.jsxs)("div",{children:[(0,H.jsx)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:"Runs over time"}),(0,H.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:t==="hour"?"Terminal runs for this automation each hour.":t==="6hour"?"Terminal runs for this automation each 6 hours.":"Terminal runs for this automation each day."})]}),(0,H.jsx)(aa,{ariaLabel:"Automation execution status legend",items:zt}),(0,H.jsxs)("div",{className:"relative mt-3 overflow-hidden",children:[(0,H.jsx)(na,{className:"aspect-auto h-55 w-full",config:An,children:(0,H.jsxs)(Zo,{"aria-label":`Automation executions during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:o,margin:Xo,role:"img",children:[(0,H.jsx)(Go,{strokeDasharray:"3 5",vertical:!1}),(0,H.jsx)(ta,{maximum:n}),(0,H.jsx)(ea,{keys:o.map(r=>r.date)}),(0,H.jsx)(ia,{content:(0,H.jsx)(oa,{rows:r=>[["completed",r.completed],["failed",r.failed],["blocked",r.blocked],["total",r.completed+r.failed+r.blocked]]})}),zt.map(r=>(0,H.jsx)(Qo,{dataKey:r.key,fill:`var(--color-${r.key})`,fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,stackId:"status"},r.key))]})}),i?null:(0,H.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No automation executions in this period."})]})]})}var A=v(k(),1),jt="result",Nn=["","completed","failed","blocked"],tn="grid-cols-[minmax(0,1fr)_5.5rem_5.5rem_5.5rem_auto_2rem]";function on(e){let{automation:t}=e,o=Oe(!0,t.id),[a,n]=bt(jt,"",Nn),i=(0,Rt.useMemo)(()=>(o.data?.executions??[]).filter(f=>!a||f.status===a),[o.data,a]),r=(0,Rt.useMemo)(()=>(o.data?.executions??[]).map(f=>({...f,automationId:t.id,automationTitle:t.title,kind:t.kind})),[t,o.data]),s=ua(i.map(f=>f.executionId));return(0,A.jsxs)(ga,{details:s.runId?(0,A.jsx)(pa,{loading:!o.data&&!o.error,onClose:s.close,run:r.find(f=>f.executionId===s.runId),showAutomation:!1},s.runId):null,label:"Runs list",listRef:s.listRef,children:[e.header,o.data?(0,A.jsx)(wn,{data:o.data,executions:i,onResultChange:n,onRowsKeyDown:s.onRowsKeyDown,onSelect:s.toggle,range:e.range,result:a,selectedRunId:s.runId}):o.error?(0,A.jsxs)(We,{children:["Runs could not be loaded."," ",(0,A.jsx)(T,{onClick:()=>{o.refetch()},children:"Try again"})]}):(0,A.jsx)($e,{label:"Loading runs",variant:"list"})]})}function wn(e){let{data:t,range:o}=e,a=(0,Rt.useMemo)(()=>kn(t.executions),[t.executions]);return(0,A.jsxs)(A.Fragment,{children:[t.executionDays.length>0?(0,A.jsx)(en,{bucketUnit:Jo(o),days:vt({days:t.executionDays,hours:t.executionHours,sixHours:t.executionSixHours,range:o,emptySixHour:n=>({blocked:0,completed:0,date:n,failed:0})}),range:o}):null,(0,A.jsxs)("div",{className:"flex flex-wrap items-end justify-between gap-x-5 gap-y-3",children:[(0,A.jsx)(ra,{ariaLabel:"Run result",items:[{count:t.executions.length,label:"All",value:""},{count:a.completed,label:"Completed",value:"completed"},{count:a.failed,label:"Failed",value:"failed"},{count:a.blocked,label:"Blocked",value:"blocked"}],onChange:n=>e.onResultChange(n),value:e.result}),(0,A.jsxs)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:[t.automation.totalRuns," total \xB7 newest first"]})]}),e.executions.length===0?(0,A.jsx)(Q,{padding:"md",children:(0,A.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:t.executions.length===0?"This automation has not run yet.":`No ${e.result} runs in the loaded history.`})}):(0,A.jsx)(Q,{children:(0,A.jsx)("div",{className:"min-w-0 overflow-x-auto",children:(0,A.jsxs)("div",{className:"min-w-[36rem]",children:[(0,A.jsxs)("div",{"aria-hidden":"true",className:V("sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid",tn),children:[(0,A.jsx)("div",{children:"Run"}),(0,A.jsx)("div",{children:"Duration"}),(0,A.jsx)("div",{children:"Tokens"}),(0,A.jsx)("div",{children:"Cost"})]}),(0,A.jsx)("div",{className:"min-w-0",onKeyDown:e.onRowsKeyDown,role:"list",children:e.executions.map(n=>(0,A.jsx)(Cn,{execution:n,fallbackTitle:t.automation.title,onSelect:()=>e.onSelect(n.executionId),selected:e.selectedRunId===n.executionId},n.executionId))})]})})}),t.truncated?(0,A.jsx)("p",{className:"m-0 text-center text-xs text-dashboard-text-muted",children:"Showing the 100 most recent runs."}):null]})}function Cn(e){let{execution:t}=e,o=Ve(t.costUsd===void 0?void 0:{total:t.costUsd})||"\u2014",a=ct(t.durationMs)||"\u2014",n=t.totalTokens===void 0?"\u2014":Do(t.totalTokens),i=la(t.status);return(0,A.jsx)("div",{className:"border-b border-dashboard-border-subtle last:border-b-0","data-run-id":t.executionId,role:"listitem",children:(0,A.jsxs)(sa,{className:V("grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5",tn),onSelect:e.onSelect,selected:e.selected,children:[(0,A.jsxs)("button",{"aria-expanded":e.selected,className:"block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",onClick:e.onSelect,type:"button",children:[(0,A.jsxs)("span",{className:"flex min-w-0 items-center gap-2 overflow-hidden",children:[(0,A.jsx)(Lt,{className:"md:hidden",label:t.status,tone:i}),(0,A.jsx)("span",{className:"min-w-0 truncate text-sm font-medium leading-snug text-dashboard-text",children:ma(t,e.fallbackTitle)})]}),(0,A.jsxs)("span",{className:"mt-1 block truncate text-xs leading-relaxed text-dashboard-text-muted",children:[X(t.executedAt),t.automationVersion?` \xB7 Version ${t.automationVersion}`:null]}),t.error?(0,A.jsx)("span",{className:"mt-1 block truncate text-xs leading-relaxed text-rose-300",title:t.error,children:t.error}):null]}),(0,A.jsx)(qt,{label:"Duration",value:a}),(0,A.jsx)(qt,{label:"Tokens",value:n}),(0,A.jsx)(qt,{label:"Cost",value:o}),(0,A.jsx)("div",{className:"hidden justify-self-center md:block",children:(0,A.jsx)(Lt,{label:t.status,tone:i})}),(0,A.jsx)("div",{className:"max-md:hidden",children:(0,A.jsx)(fa,{conversationId:t.conversationId})})]})})}function qt(e){return(0,A.jsxs)("div",{className:"min-w-0 max-md:flex max-md:items-center max-md:gap-2",children:[(0,A.jsx)("div",{"aria-hidden":"true",className:"mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block",children:e.label}),(0,A.jsxs)("div",{className:"truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text",children:[(0,A.jsxs)("span",{className:"sr-only",children:[e.label,": "]}),e.value]})]})}function kn(e){return e.reduce((t,o)=>(t[o.status]+=1,t),{blocked:0,completed:0,failed:0})}var Wt=v(Y(),1);var l=v(k(),1),Tt="version";function an(e){let t=mt(!0,e.automation.id);return t.error?(0,l.jsxs)(We,{children:["Version history could not be loaded."," ",(0,l.jsx)(T,{onClick:()=>{t.refetch()},children:"Try again"})]}):t.data?(0,l.jsx)(Sn,{automation:e.automation,data:t.data}):(0,l.jsx)($e,{label:"Loading version history",variant:"list"})}function Sn(e){let{automation:t,data:o}=e,[a,n]=Qt(),i=pe(),[r,s]=(0,Wt.useState)(),[f,w]=(0,Wt.useState)(!1),D=t.status!=="completed",u=Number(a.get(Tt)),p=Math.max(0,o.versions.findIndex(x=>x.version===u)),R=o.versions[p],z=o.versions[p+1],m=x=>n(I=>{let O=new URLSearchParams(I);return O.set(Tt,String(x)),O},{replace:!0}),b=`/api/automations/${encodeURIComponent(t.id)}`,C=ge({mutationFn:async x=>{let I=await ce(re,`${b}/edit`);return Me(re,`${b}/versions/${x}/activate`,{revision:I.revision})},onMutate:()=>s(void 0),onSuccess:async(x,I)=>{s(I),await i.invalidateQueries({queryKey:["dashboard","automations"]})}});if(!R)return(0,l.jsx)(Q,{padding:"md",children:(0,l.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No versions are saved yet. Junior saves a version each time the settings change."})});let E=R.version===o.activeVersion;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"m-0 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted",children:D?"Each save creates a version. Making a version active saves its settings as a new version. It does not run the automation.":"This automation has completed. Its versions are read-only."}),r!==void 0?(0,l.jsxs)("p",{role:"status",className:"m-0 text-sm text-emerald-300",children:["Version ",r," is active again. It was saved as a new version."]}):null,(0,l.jsxs)("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[17rem_minmax(0,1fr)] lg:gap-6",children:[(0,l.jsxs)("nav",{"aria-label":"Versions",className:"min-w-0",children:[(0,l.jsx)("ol",{className:"m-0 grid list-none gap-1 p-0 max-lg:max-h-64 max-lg:overflow-y-auto",children:o.versions.map((x,I)=>(0,l.jsx)("li",{children:(0,l.jsx)(Rn,{active:x.version===o.activeVersion,changes:Fn(x,o.versions[I+1],o.truncated),onSelect:()=>m(x.version),selected:x.version===R.version,version:x})},x.version))}),o.truncated?(0,l.jsx)("p",{className:"m-0 mt-2 px-3 text-xs text-dashboard-text-muted",children:"Showing the 100 most recent versions."}):null]}),(0,l.jsxs)(Q,{as:"section",className:"min-w-0",padding:"none",variant:"default",children:[(0,l.jsxs)("header",{className:"flex flex-wrap items-start justify-between gap-3 border-b border-dashboard-border-subtle px-4 py-4 sm:px-5",children:[(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsxs)("h2",{className:"m-0 font-display text-lg font-medium",children:["Version ",R.version]}),E?(0,l.jsx)(Ce,{size:"compact",tone:"success",children:"Active"}):null]}),(0,l.jsxs)("p",{className:"mt-1 mb-0 text-xs text-dashboard-text-muted",children:[nn(R)," \xB7"," ",X(R.createdAt),z?` \xB7 Compared with version ${z.version}`:""]})]}),D&&!E?(0,l.jsx)(T,{"aria-label":`Make version ${R.version} active`,disabled:C.isPending,onClick:()=>w(!0),children:C.isPending&&C.variables===R.version?"Saving\u2026":"Make active"}):null]}),C.error&&C.variables===R.version?(0,l.jsx)("div",{className:"px-4 pt-4 sm:px-5",children:(0,l.jsx)(B,{tone:"error",title:"This version could not be made active.",children:C.error instanceof oe?C.error.code==="conflict"?"The automation changed. Try again.":C.error.apiError??"Try again.":"Try again."})}):null,(0,l.jsx)(Tn,{automation:t,previous:z,version:R})]})]}),(0,l.jsx)(Be,{onOpenChange:w,open:f,children:(0,l.jsxs)(_e,{children:[(0,l.jsxs)(Ue,{children:["Make version ",R.version," active?"]}),(0,l.jsxs)(ze,{children:["Junior saves these settings as a new version. Future runs use them.",t.ownedByViewer?null:` Only ${t.createdBy} can turn on their connected accounts.`]}),(0,l.jsxs)(qe,{children:[(0,l.jsx)(He,{children:"Cancel"}),(0,l.jsx)(je,{onClick:()=>{C.mutate(R.version),w(!1)},variant:"primary",children:"Make active"})]})]})})]})}function Rn(e){let{version:t}=e;return(0,l.jsxs)("button",{"aria-current":e.selected?"true":void 0,className:V("grid w-full min-w-0 cursor-pointer gap-0.5 rounded-md border-0 px-3 py-2.5 text-left transition-colors focus-visible:outline-2 focus-visible:outline-dashboard-focus",e.selected?"bg-dashboard-accent/[0.08] text-dashboard-text":"bg-transparent text-dashboard-text hover:bg-dashboard-fill-soft"),onClick:e.onSelect,type:"button",children:[(0,l.jsxs)("span",{className:"flex items-center gap-2 text-sm font-medium",children:["Version ",t.version,e.active?(0,l.jsx)(Ce,{size:"compact",tone:"success",children:"Active"}):null]}),(0,l.jsxs)("span",{className:"truncate text-xs text-dashboard-text-muted",children:[nn(t)," \xB7"," ",(0,l.jsx)("time",{dateTime:t.createdAt,children:we(t.createdAt)})]}),e.changes?(0,l.jsx)("span",{className:"truncate text-xs text-dashboard-text-muted",children:e.changes}):null]})}var Jt=[{key:"title",label:"Title"},{key:"instruction",label:"What to do"},{key:"when",label:"When to run"},{key:"destination",label:"Destination"},{key:"outcomes",label:"Where results go"},{key:"credentialMode",label:"Credentials"}];function Tn(e){let{automation:t,previous:o,version:a}=e,n=o?rn(o,a):[];return(0,l.jsx)("dl",{className:"m-0 divide-y divide-dashboard-border-subtle",children:Jt.map(({key:i,label:r})=>{let s=n.includes(i);return(0,l.jsxs)("div",{className:V("grid min-w-0 gap-2 px-4 py-4 sm:grid-cols-[9rem_minmax(0,1fr)] sm:gap-6 sm:px-5",s&&"shadow-[inset_2px_0_0_var(--color-dashboard-accent)]"),children:[(0,l.jsxs)("dt",{className:"text-xs font-medium text-dashboard-text-muted",children:[r,s?(0,l.jsx)("span",{className:"mt-1 block font-normal text-dashboard-accent-text",children:"Changed"}):null]}),(0,l.jsx)("dd",{className:"m-0 min-w-0 text-sm leading-relaxed break-words",children:s&&o&&i==="instruction"?(0,l.jsx)(Dn,{after:a.definition.instruction,before:o.definition.instruction}):s&&o?(0,l.jsxs)("div",{className:"grid gap-2",children:[(0,l.jsxs)("div",{className:"text-dashboard-text-muted line-through decoration-dashboard-text-muted/50",children:[(0,l.jsx)("span",{className:"sr-only",children:"Before: "}),Ht(i,t,o)]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"sr-only",children:"After: "}),Ht(i,t,a)]})]}):Ht(i,t,a)})]},i)})})}function Ht(e,t,o){let{definition:a}=o;switch(e){case"title":return a.title??"First line of the instruction";case"instruction":return(0,l.jsx)(ft,{mentions:t.mentions,text:a.instruction});case"when":if(o.kind==="scheduled"){let{description:n,timezone:i}=o.definition.schedule;return n.includes(i)?n:`${n} (${i})`}return(0,l.jsxs)(l.Fragment,{children:[o.definition.trigger.label,o.definition.trigger.identifier?` \xB7 ${o.definition.trigger.identifier}`:null,(0,l.jsx)("br",{}),o.trigger.events.join(", "),(0,l.jsx)(Ye,{filters:o.trigger.filters})]});case"destination":return a.destination.channelId===t.destination.channelId&&a.destination.teamId===t.destination.teamId?t.destination.label:`Another destination \xB7 ${a.destination.channelId}`;case"outcomes":return a.outcomes.length?(0,l.jsx)("ol",{className:"m-0 grid list-decimal gap-1 pl-5",children:a.outcomes.map((n,i)=>(0,l.jsx)("li",{children:Se(n,t.destination)},i))}):"No message on success";case"credentialMode":return a.credentialMode==="creator"?`Uses accounts connected by ${t.ownedByViewer?"you":t.createdBy}.`:"System credentials only"}}function Dn(e){return(0,l.jsx)("div",{className:"grid overflow-hidden rounded-md border border-dashboard-border-subtle font-mono text-xs leading-relaxed",children:En(e.before,e.after).map((t,o)=>(0,l.jsxs)("div",{className:V("grid grid-cols-[1.5rem_minmax(0,1fr)] whitespace-pre-wrap px-2 py-0.5",t.kind==="added"&&"bg-emerald-500/10 text-emerald-200",t.kind==="removed"&&"bg-rose-500/10 text-rose-200"),children:[(0,l.jsx)("span",{"aria-hidden":"true",className:"select-none opacity-60",children:t.kind==="added"?"+":t.kind==="removed"?"\u2212":""}),(0,l.jsxs)("span",{children:[t.kind==="same"?null:(0,l.jsx)("span",{className:"sr-only",children:t.kind==="added"?"Added: ":"Removed: "}),t.value||" "]})]},o))})}function En(e,t){let o=e.split(`
2
2
  `),a=t.split(`
3
3
  `),n=Array.from({length:o.length+1},()=>Array.from({length:a.length+1},()=>0));for(let f=o.length-1;f>=0;f--)for(let w=a.length-1;w>=0;w--)n[f][w]=o[f]===a[w]?n[f+1][w+1]+1:Math.max(n[f+1][w],n[f][w+1]);let i=[],r=0,s=0;for(;r<o.length&&s<a.length;)o[r]===a[s]?(i.push({kind:"same",value:o[r]}),r++,s++):n[r+1][s]>=n[r][s+1]?i.push({kind:"removed",value:o[r++]}):i.push({kind:"added",value:a[s++]});for(;r<o.length;)i.push({kind:"removed",value:o[r++]});for(;s<a.length;)i.push({kind:"added",value:a[s++]});return i}function nn(e){return e.editedBy?e.editedBy.fullName??e.editedBy.userName??e.editedBy.slackUserId:"Editor unknown"}function Fn(e,t,o){if(!t)return e.version===1||!o?"First saved version":void 0;let a=rn(t,e);return a.length===0?"No setting changes":`Changed ${Jt.filter(({key:i})=>a.includes(i)).map(({label:i})=>i.toLowerCase()).join(", ")}`}function rn(e,t){let o=e.definition,a=t.definition,n=i=>JSON.stringify(o[i])!==JSON.stringify(a[i]);return Jt.flatMap(({key:i})=>(i==="when"?n("schedule")||n("trigger"):n(i))?[i]:[])}var N=v(k(),1),Pn=["1","7","30","90"],In=[jt,ca,Tt],sn={edit:"Edit",overview:"Overview",runs:"Runs",versions:"Versions"};function ll(e){let{automationId:t}=Yt(),o=Pe(),a=To(e.enabled,t),[n,i]=bt("range","30",Pn),r=Number(n);if(!t)return(0,N.jsx)(Et,{replace:!0,to:"/automations/list"});let s=new URLSearchParams(o.search);for(let p of In)s.delete(p);let f=ke("/automations/list",s),w=a.data,D=["overview","runs","versions"].map(p=>({label:sn[p],to:se(t,p),isActive:R=>p==="overview"?!!(nt("/automations/:automationId",R)||nt("/automations/:automationId/edit",R)):!!nt(`/automations/:automationId/${p}`,R)})),u=e.tab==="runs"&&!!w;return(0,N.jsx)(Yo,{ariaLabel:"Automation navigation",className:u?"grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)] md:grid-rows-[minmax(0,1fr)]":void 0,items:D,children:w?(0,N.jsx)(Ln,{automation:w,listPath:f,onRangeChange:p=>i(String(p)),range:r,tab:e.tab}):(0,N.jsxs)(It,{children:[(0,N.jsx)(dn,{to:f}),(0,N.jsx)(Pt,{description:"Settings, runs, and versions for one automation.",title:"Automation"}),a.error?(0,N.jsxs)(B,{tone:"error",title:"Automation could not be loaded.",children:[a.error instanceof oe&&a.error.status===404?"This automation was not found or is not visible to you.":"Try again."," ",(0,N.jsx)(T,{onClick:()=>{a.refetch()},children:"Try again"})]}):(0,N.jsx)($e,{label:"Loading automation",variant:"list"})]})})}function Ln(e){let{automation:t,tab:o}=e,a=Pe(),n=it(),[i,r]=(0,Dt.useState)(!1),s=(0,Dt.useRef)(null),f=t.status==="completed";if(o==="edit"&&f)return(0,N.jsx)(Et,{replace:!0,to:ke(se(t.id),a.search)});let w=ke(se(t.id,"edit"),a.search),D=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(dn,{to:e.listPath}),(0,N.jsx)(Pt,{actions:o==="edit"?void 0:(0,N.jsxs)("div",{className:"flex flex-wrap items-start gap-2 md:justify-end",children:[o==="overview"||o==="runs"?(0,N.jsx)(Ko,{onChange:e.onRangeChange,value:e.range}):null,(0,N.jsx)(ha,{automation:t,editPath:w,editVariant:o==="overview"&&Ga(t)?"default":"primary",onDelete:p=>{s.current=p,r(!0)}})]}),description:(0,N.jsx)(On,{automation:t}),documentTitle:o==="overview"?t.title:`${t.title} \xB7 ${sn[o]}`,title:t.title})]}),u=i?(0,N.jsx)(ba,{automation:t,onClose:()=>r(!1),onDeleted:()=>{s.current=null,n(e.listPath)},returnFocus:()=>s.current?.isConnected?s.current:!1}):null;return o==="runs"?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(on,{automation:t,header:D,range:e.range}),u]}):(0,N.jsxs)(It,{children:[D,o==="overview"?(0,N.jsx)(Xa,{automation:t,editPath:w,range:e.range}):null,o==="edit"?(0,N.jsx)(Mn,{automation:t}):null,o==="versions"?(0,N.jsx)(an,{automation:t}):null,u]})}function Mn(e){let{automation:t}=e,o=Pe(),a=Fe({queryKey:["dashboard","automations","edit",t.id],retry:!1,queryFn:({signal:n})=>ce(re,`/api/automations/${encodeURIComponent(t.id)}/edit`,n)});return a.error&&!a.data?(0,N.jsxs)(B,{tone:"error",title:"Automation could not be loaded.",children:["It may no longer be available, or you may not have access."," ",(0,N.jsx)(T,{onClick:()=>{a.refetch()},children:"Try again"})]}):a.data?(0,N.jsx)(Ta,{automation:a.data,summary:t,returnPath:ke(se(t.id),o.search)},t.id):(0,N.jsx)(Da,{})}function On(e){let{automation:t}=e,a=[t.kind==="scheduled"?t.schedule:Ao(t.resource,t.trigger),t.destination.label,`Created by ${t.ownedByViewer?"you":t.createdBy}`];return(0,N.jsx)("span",{className:"block min-w-0 overflow-hidden",children:(0,N.jsxs)("span",{className:"-ml-4 flex min-w-0 flex-wrap items-center gap-y-1",children:[(0,N.jsxs)("span",{className:"flex items-center",children:[(0,N.jsx)("span",{"aria-hidden":"true",className:"inline-block w-4"}),(0,N.jsx)(Ja,{automation:t})]}),a.map((n,i)=>(0,N.jsxs)("span",{className:"min-w-0 break-words",children:[(0,N.jsx)("span",{"aria-hidden":"true",className:V("inline-block w-4 text-center opacity-45",i===0&&"invisible"),children:"\xB7"}),n]},i))]})})}function dn(e){return(0,N.jsxs)(W,{className:"flex w-fit items-center gap-2 font-display text-sm font-medium text-dashboard-text-muted no-underline transition-colors hover:text-dashboard-text",to:e.to,children:[(0,N.jsx)(oo,{"aria-hidden":"true",size:15,strokeWidth:1.8}),"All automations"]})}export{ll as AutomationPage};
@@ -1 +1 @@
1
- import{b as q,c as H,d as Q,e as W,f as Y}from"./chunk-UAH6DWNS.js";import{b as V,c as Z,d as $}from"./chunk-SDKV3OID.js";import{a as B}from"./chunk-SIOW7OOW.js";import{a as j,b as N}from"./chunk-VFEBNOPX.js";import"./chunk-Z2JPRGFT.js";import"./chunk-NQOJAZFQ.js";import{a as L}from"./chunk-XNR4RZEC.js";import"./chunk-G5NWYJTV.js";import"./chunk-5ZA674OU.js";import{b as U,c as E,d as K}from"./chunk-3Y3ICT6K.js";import{b as P}from"./chunk-EFEREKX4.js";import"./chunk-2BCS5AQL.js";import"./chunk-H76B43OQ.js";import{i as _}from"./chunk-QNA7F7QB.js";import"./chunk-B6HGRBBX.js";import{k as D,r as F,z as G}from"./chunk-NQMDED2R.js";import"./chunk-GMZIELFU.js";import"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import"./chunk-GO45RQDL.js";import{Ja as c}from"./chunk-VXT3FIVL.js";import{b as M,c as R}from"./chunk-RHMZNAJX.js";import"./chunk-GOTQ4D6W.js";import{C as h,D as v,M as z}from"./chunk-6PHJZPWD.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import"./chunk-CR2ICLSH.js";import{Pc as A,Rc as g,a as ne,b as T,fb as C}from"./chunk-YPMUHXYT.js";import{c as x}from"./chunk-7SZRL6FY.js";var r=x(ne(),1);var e=x(T(),1),k=25,J=["all","scheduled","event"],O=["all","completed","failed","blocked"],se=[],X="grid-cols-[minmax(0,1.4fr)_minmax(0,1.2fr)_5.5rem_5.5rem_5.5rem_2rem]";function Ie(o){let a=_(o.enabled),[n,b]=R("type","all",J),[i,ee]=R("status","all",O),[te,ae,S]=M(),[l,p]=(0,r.useState)(1),m=S.toLowerCase(),f=a.data?.runs??se,d=(0,r.useMemo)(()=>f.filter(t=>n!=="all"&&t.kind!==n||i!=="all"&&t.status!==i?!1:m?[t.kind,t.status,t.automationTitle,t.title,t.conversationId].filter(Boolean).join(" ").toLowerCase().includes(m):!0),[n,f,m,i]),u=E(d.length,k),w=(0,r.useMemo)(()=>U(d,l,k),[l,d]);(0,r.useEffect)(()=>{p(1)},[n,S,i]),(0,r.useEffect)(()=>{l>u&&p(u)},[l,u]);let I=!a.data&&!a.error,s=q(w.map(t=>t.executionId)),oe=s.runId?f.find(t=>t.executionId===s.runId):void 0;return(0,e.jsxs)(H,{details:s.runId?(0,e.jsx)(W,{loading:I,onClose:s.close,run:oe,showAutomation:!0},s.runId):null,label:"Runs list",listRef:s.listRef,children:[(0,e.jsx)(z,{description:"Newest runs across your automations and automations in public destinations.",title:"Runs"}),I?(0,e.jsx)(P,{label:"Loading automation runs",variant:"list"}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(j,{search:{label:"Search runs",onChange:ae,placeholder:"Automation, conversation, or status",value:te},children:[(0,e.jsx)(N,{label:"Type",children:(0,e.jsx)(h,{className:"flex-wrap gap-2",onValueChange:([t])=>{t&&b(t)},value:[n],children:J.map(t=>(0,e.jsx)(v,{value:t,variant:"pill",children:t},t))})}),(0,e.jsx)(N,{label:"Status",children:(0,e.jsx)(h,{className:"flex-wrap gap-2",onValueChange:([t])=>{t&&ee(t)},value:[i],children:O.map(t=>(0,e.jsx)(v,{value:t,variant:"pill",children:t},t))})})]}),(0,e.jsx)("div",{className:"flex flex-wrap items-baseline justify-between gap-x-5 gap-y-1 border-b border-dashboard-border-subtle pb-3",children:(0,e.jsxs)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:[d.length," ",d.length===1?"run":"runs",(0,e.jsxs)("span",{className:"text-dashboard-text-muted/70",children:[" ","\xB7 newest first"]})]})}),a.error?(0,e.jsx)(c,{padding:"md",children:(0,e.jsx)(L,{children:"Automation runs could not be loaded. Try again."})}):d.length===0?(0,e.jsx)(c,{padding:"md",children:(0,e.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:ie({kind:n,search:m,status:i})})}):(0,e.jsx)(c,{children:(0,e.jsx)("div",{className:"min-w-0 overflow-x-auto",children:(0,e.jsxs)("div",{className:"min-w-[44rem]",children:[(0,e.jsxs)("div",{"aria-hidden":"true",className:g("sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid",X),children:[(0,e.jsx)("div",{children:"Run"}),(0,e.jsx)("div",{children:"Automation"}),(0,e.jsx)("div",{children:"Duration"}),(0,e.jsx)("div",{children:"Tokens"}),(0,e.jsx)("div",{children:"Cost"})]}),(0,e.jsx)("div",{className:"min-w-0",onKeyDown:s.onRowsKeyDown,role:"list",children:w.map(t=>(0,e.jsx)(re,{onSelect:()=>s.toggle(t.executionId),run:t,selected:s.runId===t.executionId},`${t.kind}:${t.executionId}`))})]})})}),(0,e.jsx)(K,{onPageChange:p,page:l,pageCount:u,pageSize:k,total:d.length}),a.data?.truncated?(0,e.jsx)("p",{className:"m-0 text-center text-xs text-dashboard-text-muted",children:"Showing the 100 most recent runs."}):null]})]})}function ie(o){return o.search||o.kind!=="all"||o.status!=="all"?"No runs matched these filters.":"No visible automations have run yet."}function re(o){let{run:a}=o,n=G(a.costUsd===void 0?void 0:{total:a.costUsd})||"\u2014",b=D(a.durationMs)||"\u2014",i=a.totalTokens===void 0?"\u2014":F(a.totalTokens);return(0,e.jsx)("div",{className:"border-b border-dashboard-border-subtle last:border-b-0","data-run-id":a.executionId,role:"listitem",children:(0,e.jsxs)(B,{className:g("grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5",X),onSelect:o.onSelect,selected:o.selected,children:[(0,e.jsxs)("button",{"aria-expanded":o.selected,className:"block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",onClick:o.onSelect,type:"button",children:[(0,e.jsx)("span",{className:"block truncate text-sm font-medium leading-snug text-dashboard-text",children:$(a,a.automationTitle)}),(0,e.jsx)("span",{className:"mt-1 block truncate text-xs text-dashboard-text-muted",children:V(a.executedAt)})]}),(0,e.jsxs)("div",{className:"min-w-0 overflow-hidden",children:[(0,e.jsx)("div",{className:"truncate text-sm text-dashboard-text",children:a.automationTitle}),(0,e.jsxs)("div",{className:"mt-1 flex min-w-0 items-center gap-1.5 overflow-hidden text-dashboard-text-muted",children:[(0,e.jsx)(de,{kind:a.kind}),(0,e.jsx)(Y,{label:a.status,tone:Z(a.status)}),(0,e.jsx)("span",{className:"truncate text-xs text-dashboard-text-muted",children:a.status})]})]}),(0,e.jsx)(y,{label:"Duration",value:b}),(0,e.jsx)(y,{label:"Tokens",value:i}),(0,e.jsx)(y,{label:"Cost",value:n}),(0,e.jsx)("div",{className:"max-md:hidden",children:(0,e.jsx)(Q,{conversationId:a.conversationId})})]})})}function y(o){return(0,e.jsxs)("div",{className:"min-w-0 max-md:flex max-md:items-center max-md:gap-2",children:[(0,e.jsx)("div",{"aria-hidden":"true",className:"mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block",children:o.label}),(0,e.jsxs)("div",{className:"truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text",children:[(0,e.jsxs)("span",{className:"sr-only",children:[o.label,": "]}),o.value]})]})}function de(o){let a=o.kind==="scheduled"?C:A,n=o.kind==="scheduled"?"Scheduled automation":"Event automation";return(0,e.jsx)("span",{"aria-label":n,className:"inline-flex size-3.5 shrink-0 items-center justify-center text-dashboard-accent/80",role:"img",title:n,children:(0,e.jsx)(a,{"aria-hidden":"true",className:"size-3.5",strokeWidth:1.8})})}export{Ie as AutomationRunsPage};
1
+ import{b as q,c as H,d as Q,e as W,f as Y}from"./chunk-RB5FBDEY.js";import{b as V,c as Z,d as $}from"./chunk-FSGVY7HB.js";import{a as B}from"./chunk-SIOW7OOW.js";import{a as j,b as N}from"./chunk-2J3LGF5Q.js";import"./chunk-WLIOZO3W.js";import"./chunk-JVJ5UWIK.js";import{a as L}from"./chunk-XNR4RZEC.js";import"./chunk-G5NWYJTV.js";import"./chunk-5ZA674OU.js";import{b as U,c as E,d as K}from"./chunk-3Y3ICT6K.js";import{b as P}from"./chunk-KDUTK357.js";import"./chunk-2BCS5AQL.js";import"./chunk-H76B43OQ.js";import{i as _}from"./chunk-64GPEGGE.js";import"./chunk-ILH47V7O.js";import{k as D,r as F,z as G}from"./chunk-II4NXLSQ.js";import"./chunk-GMZIELFU.js";import"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import"./chunk-4TQSTCIN.js";import{Ka as c}from"./chunk-XDUSY26N.js";import{b as M,c as R}from"./chunk-RHMZNAJX.js";import"./chunk-GOTQ4D6W.js";import{C as h,D as v,M as z}from"./chunk-6PHJZPWD.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import"./chunk-CR2ICLSH.js";import{Pc as A,Rc as g,a as ne,b as T,fb as C}from"./chunk-YPMUHXYT.js";import{c as x}from"./chunk-7SZRL6FY.js";var r=x(ne(),1);var e=x(T(),1),k=25,J=["all","scheduled","event"],O=["all","completed","failed","blocked"],se=[],X="grid-cols-[minmax(0,1.4fr)_minmax(0,1.2fr)_5.5rem_5.5rem_5.5rem_2rem]";function Ie(o){let a=_(o.enabled),[n,b]=R("type","all",J),[i,ee]=R("status","all",O),[te,ae,S]=M(),[l,p]=(0,r.useState)(1),m=S.toLowerCase(),f=a.data?.runs??se,d=(0,r.useMemo)(()=>f.filter(t=>n!=="all"&&t.kind!==n||i!=="all"&&t.status!==i?!1:m?[t.kind,t.status,t.automationTitle,t.title,t.conversationId].filter(Boolean).join(" ").toLowerCase().includes(m):!0),[n,f,m,i]),u=E(d.length,k),w=(0,r.useMemo)(()=>U(d,l,k),[l,d]);(0,r.useEffect)(()=>{p(1)},[n,S,i]),(0,r.useEffect)(()=>{l>u&&p(u)},[l,u]);let I=!a.data&&!a.error,s=q(w.map(t=>t.executionId)),oe=s.runId?f.find(t=>t.executionId===s.runId):void 0;return(0,e.jsxs)(H,{details:s.runId?(0,e.jsx)(W,{loading:I,onClose:s.close,run:oe,showAutomation:!0},s.runId):null,label:"Runs list",listRef:s.listRef,children:[(0,e.jsx)(z,{description:"Newest runs across your automations and automations in public destinations.",title:"Runs"}),I?(0,e.jsx)(P,{label:"Loading automation runs",variant:"list"}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(j,{search:{label:"Search runs",onChange:ae,placeholder:"Automation, conversation, or status",value:te},children:[(0,e.jsx)(N,{label:"Type",children:(0,e.jsx)(h,{className:"flex-wrap gap-2",onValueChange:([t])=>{t&&b(t)},value:[n],children:J.map(t=>(0,e.jsx)(v,{value:t,variant:"pill",children:t},t))})}),(0,e.jsx)(N,{label:"Status",children:(0,e.jsx)(h,{className:"flex-wrap gap-2",onValueChange:([t])=>{t&&ee(t)},value:[i],children:O.map(t=>(0,e.jsx)(v,{value:t,variant:"pill",children:t},t))})})]}),(0,e.jsx)("div",{className:"flex flex-wrap items-baseline justify-between gap-x-5 gap-y-1 border-b border-dashboard-border-subtle pb-3",children:(0,e.jsxs)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:[d.length," ",d.length===1?"run":"runs",(0,e.jsxs)("span",{className:"text-dashboard-text-muted/70",children:[" ","\xB7 newest first"]})]})}),a.error?(0,e.jsx)(c,{padding:"md",children:(0,e.jsx)(L,{children:"Automation runs could not be loaded. Try again."})}):d.length===0?(0,e.jsx)(c,{padding:"md",children:(0,e.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:ie({kind:n,search:m,status:i})})}):(0,e.jsx)(c,{children:(0,e.jsx)("div",{className:"min-w-0 overflow-x-auto",children:(0,e.jsxs)("div",{className:"min-w-[44rem]",children:[(0,e.jsxs)("div",{"aria-hidden":"true",className:g("sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid",X),children:[(0,e.jsx)("div",{children:"Run"}),(0,e.jsx)("div",{children:"Automation"}),(0,e.jsx)("div",{children:"Duration"}),(0,e.jsx)("div",{children:"Tokens"}),(0,e.jsx)("div",{children:"Cost"})]}),(0,e.jsx)("div",{className:"min-w-0",onKeyDown:s.onRowsKeyDown,role:"list",children:w.map(t=>(0,e.jsx)(re,{onSelect:()=>s.toggle(t.executionId),run:t,selected:s.runId===t.executionId},`${t.kind}:${t.executionId}`))})]})})}),(0,e.jsx)(K,{onPageChange:p,page:l,pageCount:u,pageSize:k,total:d.length}),a.data?.truncated?(0,e.jsx)("p",{className:"m-0 text-center text-xs text-dashboard-text-muted",children:"Showing the 100 most recent runs."}):null]})]})}function ie(o){return o.search||o.kind!=="all"||o.status!=="all"?"No runs matched these filters.":"No visible automations have run yet."}function re(o){let{run:a}=o,n=G(a.costUsd===void 0?void 0:{total:a.costUsd})||"\u2014",b=D(a.durationMs)||"\u2014",i=a.totalTokens===void 0?"\u2014":F(a.totalTokens);return(0,e.jsx)("div",{className:"border-b border-dashboard-border-subtle last:border-b-0","data-run-id":a.executionId,role:"listitem",children:(0,e.jsxs)(B,{className:g("grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5",X),onSelect:o.onSelect,selected:o.selected,children:[(0,e.jsxs)("button",{"aria-expanded":o.selected,className:"block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",onClick:o.onSelect,type:"button",children:[(0,e.jsx)("span",{className:"block truncate text-sm font-medium leading-snug text-dashboard-text",children:$(a,a.automationTitle)}),(0,e.jsx)("span",{className:"mt-1 block truncate text-xs text-dashboard-text-muted",children:V(a.executedAt)})]}),(0,e.jsxs)("div",{className:"min-w-0 overflow-hidden",children:[(0,e.jsx)("div",{className:"truncate text-sm text-dashboard-text",children:a.automationTitle}),(0,e.jsxs)("div",{className:"mt-1 flex min-w-0 items-center gap-1.5 overflow-hidden text-dashboard-text-muted",children:[(0,e.jsx)(de,{kind:a.kind}),(0,e.jsx)(Y,{label:a.status,tone:Z(a.status)}),(0,e.jsx)("span",{className:"truncate text-xs text-dashboard-text-muted",children:a.status})]})]}),(0,e.jsx)(y,{label:"Duration",value:b}),(0,e.jsx)(y,{label:"Tokens",value:i}),(0,e.jsx)(y,{label:"Cost",value:n}),(0,e.jsx)("div",{className:"max-md:hidden",children:(0,e.jsx)(Q,{conversationId:a.conversationId})})]})})}function y(o){return(0,e.jsxs)("div",{className:"min-w-0 max-md:flex max-md:items-center max-md:gap-2",children:[(0,e.jsx)("div",{"aria-hidden":"true",className:"mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block",children:o.label}),(0,e.jsxs)("div",{className:"truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text",children:[(0,e.jsxs)("span",{className:"sr-only",children:[o.label,": "]}),o.value]})]})}function de(o){let a=o.kind==="scheduled"?C:A,n=o.kind==="scheduled"?"Scheduled automation":"Event automation";return(0,e.jsx)("span",{"aria-label":n,className:"inline-flex size-3.5 shrink-0 items-center justify-center text-dashboard-accent/80",role:"img",title:n,children:(0,e.jsx)(a,{"aria-hidden":"true",className:"size-3.5",strokeWidth:1.8})})}export{Ie as AutomationRunsPage};
@@ -1 +1 @@
1
- import{a as Ie,b as Z}from"./chunk-SDKV3OID.js";import{a as $e}from"./chunk-SIOW7OOW.js";import{a as Oe}from"./chunk-5ISD3QSC.js";import{a as Fe}from"./chunk-4UGZNVJM.js";import{b as X}from"./chunk-VFEBNOPX.js";import{a as w}from"./chunk-WJ3OXMVX.js";import{a as B,c as D,f as E,o as F,p as O,q as $,r as I,s as M,t as z,w as G,x as H}from"./chunk-V5UDSIRA.js";import{a as be,b as ye,c as xe,d as Ae}from"./chunk-ZIJ6SJDN.js";import{g as Te}from"./chunk-NQOJAZFQ.js";import{a as we}from"./chunk-XNR4RZEC.js";import"./chunk-G5NWYJTV.js";import{d as ke}from"./chunk-FVX42XAD.js";import{c as Se,d as Ne}from"./chunk-3Y3ICT6K.js";import{b as ve}from"./chunk-EFEREKX4.js";import{a as Re}from"./chunk-2BCS5AQL.js";import{a as Ce}from"./chunk-H76B43OQ.js";import{g as ge}from"./chunk-QNA7F7QB.js";import"./chunk-B6HGRBBX.js";import{K as fe,O as L,g as P,s as he,z as Y}from"./chunk-NQMDED2R.js";import"./chunk-GMZIELFU.js";import"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import"./chunk-GO45RQDL.js";import{Ja as S,O as Q,r as pe}from"./chunk-VXT3FIVL.js";import{a as Be,b as De,c as Ee}from"./chunk-RHMZNAJX.js";import{C as j,D as q,E as Pe,G as V,H as U,K as Le,M as Ue,d as ie,f as ne,o as T,q as oe}from"./chunk-6PHJZPWD.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import{b as k}from"./chunk-CR2ICLSH.js";import{Ab as se,Ac as me,Kc as ce,Oc as ue,Pc as de,Tb as le,Wb as R,a as ae,b as x,fb as re}from"./chunk-YPMUHXYT.js";import{c as f}from"./chunk-7SZRL6FY.js";var je=f(ae(),1);var _=f(ae(),1);var i=f(x(),1),Me="(min-width: 768px)",ze=[{value:"active",label:"Active"},{value:"blocked",label:"Blocked"},{value:"paused",label:"Paused"},{value:"unavailable",label:"Trigger unavailable"},{value:"completed",label:"Completed"}];function nt(e){let t=window.matchMedia(Me);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function ot(){return window.matchMedia(Me).matches}function Ge(e){let{filters:t,data:r,onChange:a}=e,[b,g]=(0,_.useState)(!1),A=(0,_.useSyncExternalStore)(nt,ot,()=>!1),c=[{key:"type",label:"Type",value:t.type==="all"?"":t.type,valueLabel:t.type==="scheduled"?"Scheduled":"Event"},{key:"creator",label:"Creator",value:t.creator,valueLabel:r?.creators.find(m=>m.value===t.creator)?.label??t.creator},{key:"destination",label:"Destination",value:t.destination,valueLabel:r?.destinations.find(m=>m.value===t.destination)?.label??t.destination},{key:"state",label:"State",value:t.state==="all"?"":t.state,valueLabel:ze.find(m=>m.value===t.state)?.label}].filter(m=>m.value),u=(0,i.jsxs)(k,{className:"h-11 shrink-0","aria-expanded":b,"aria-haspopup":"dialog",onClick:A?void 0:()=>g(!0),children:[(0,i.jsx)(me,{"aria-hidden":"true",size:14})," Filters",c.length?` (${c.length})`:""]}),C=(0,i.jsx)(rt,{filters:t,data:r,onChange:a});return(0,i.jsxs)("div",{className:"grid gap-3",children:[(0,i.jsxs)("div",{className:"grid gap-2 lg:grid-cols-[auto_minmax(16rem,1fr)] lg:items-center lg:gap-4",children:[(0,i.jsx)(j,{"aria-label":"Scope",className:"flex-wrap gap-2",onValueChange:([m])=>{m&&a("scope",m)},value:[t.scope],children:[["all","All"],["mine","Mine"],["public","Public"],["attention","Needs attention"]].map(([m,y])=>(0,i.jsxs)(q,{className:"min-h-11 lg:min-h-9",value:m,variant:"pill",children:[y,r&&m!=="attention"?(0,i.jsx)("span",{className:"ml-1.5 opacity-65",children:r.counts[m]}):null]},m))}),(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(Ce,{className:"flex-1",size:"default",label:"Search automations",placeholder:"Search automations",value:e.searchText,onChange:e.onSearch}),A?(0,i.jsxs)(be,{open:b,onOpenChange:g,children:[(0,i.jsx)(ye,{render:u}),(0,i.jsxs)(xe,{align:"end",className:"w-80",children:[(0,i.jsx)(Ae,{children:"Filters"}),(0,i.jsx)("div",{className:"mt-4",children:C})]})]}):u]})]}),c.length>0?(0,i.jsx)("div",{"aria-label":"Active filters",role:"group",className:"flex min-w-0 flex-wrap gap-2",children:c.map(m=>(0,i.jsxs)(k,{"aria-label":`Remove ${m.key} filter`,className:"min-h-9 max-w-full text-xs",title:`${m.label}: ${m.valueLabel}`,onClick:()=>a(m.key,""),children:[(0,i.jsxs)("span",{className:"truncate",children:[m.label,": ",m.valueLabel]}),(0,i.jsx)(ue,{"aria-hidden":"true",className:"shrink-0",size:12})]},m.key))}):null,!A&&b?(0,i.jsx)(Te,{label:"Filters",size:"content",onClose:()=>g(!1),children:(0,i.jsx)("div",{className:"p-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:C})}):null]})}function rt({filters:e,data:t,onChange:r}){return(0,i.jsxs)("div",{className:"grid gap-4",children:[(0,i.jsx)(X,{label:"Type",children:(0,i.jsx)(j,{className:"flex-wrap gap-2",onValueChange:([a])=>{a&&r("type",a)},value:[e.type],children:["all","scheduled","event"].map(a=>(0,i.jsx)(q,{className:"min-h-9",value:a,variant:"pill",children:a},a))})}),(0,i.jsx)(W,{label:"Creator",emptyLabel:"All",value:e.creator??"",options:t?.creators??[],onChange:a=>r("creator",a)}),(0,i.jsx)(W,{label:"Destination",emptyLabel:"All",value:e.destination??"",options:t?.destinations??[],onChange:a=>r("destination",a)}),(0,i.jsx)(W,{label:"State",emptyLabel:"All",value:e.state==="all"?"":e.state,options:ze,onChange:a=>r("state",a)})]})}function He(e){return(0,i.jsx)(Oe,{ariaLabel:"Sort automations",onChange:e.onChange,options:[{value:"newest",label:"Recently created"},{value:"oldest",label:"Oldest created"},{value:"title",label:"Title A\u2013Z"}],value:e.value})}function W(e){return(0,i.jsx)(X,{label:e.label,children:(0,i.jsxs)(Fe,{"aria-label":e.ariaLabel??`Filter by ${e.label.toLowerCase()}`,variant:"filter",value:e.value,onChange:t=>e.onChange(t.currentTarget.value),children:[e.emptyLabel?(0,i.jsx)("option",{value:"",children:e.emptyLabel}):null,e.value&&!e.options.some(t=>t.value===e.value)?(0,i.jsx)("option",{value:e.value,children:e.value}):null,e.options.map(t=>(0,i.jsx)("option",{value:t.value,children:t.label},t.value))]})})}var n=f(x(),1);function Ke(e){let{automation:t}=e,r=st(t),a=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ke,{imageUrl:t.createdByAvatarUrl,name:t.createdBy,size:"list"}),(0,n.jsx)("span",{className:"truncate",children:t.createdBy})]});return(0,n.jsx)("article",{className:"min-w-0 rounded-lg border border-dashboard-border-subtle bg-dashboard-fill-faint","data-automation-id":t.id,role:"listitem",children:(0,n.jsx)($e,{className:"flex items-start gap-3 rounded-lg px-4 py-3.5",onSelect:e.onSelect,selected:!1,children:(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)(T,{"aria-label":`Open automation: ${t.title}`,className:"block w-full min-w-0 rounded-md text-left no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",to:e.to,children:[(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-2",children:[(0,n.jsx)("span",{className:"truncate font-display text-base font-medium text-dashboard-text",title:t.title,children:t.title}),r?(0,n.jsx)(Re,{className:"shrink-0",size:"compact",tone:r==="completed"||r==="paused"?"neutral":"warning",children:r}):null]}),(0,n.jsx)(lt,{automation:t})]}),(0,n.jsxs)("div",{className:"mt-2.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-dashboard-text-muted",children:[t.createdByEmail?(0,n.jsx)(T,{className:"inline-flex min-w-0 max-w-full items-center gap-2 rounded-md text-dashboard-text no-underline hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",title:t.createdBy,to:fe(t.createdByEmail),children:a}):(0,n.jsx)("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2 text-dashboard-text",title:t.createdBy,children:a}),(0,n.jsx)(mt,{automation:t})]})]})})})}function st(e){return e.kind==="scheduled"?e.status==="active"?void 0:e.status:e.status!=="active"?e.status:e.trigger.problems.length===0?void 0:"Trigger unavailable"}function lt({automation:e}){let t=e.kind==="scheduled",r=t?re:de,a=e.kind==="scheduled"?e.schedule:pe(e.resource,e.trigger),b=e.kind==="scheduled"?Ie(e):a;return(0,n.jsxs)("span",{className:"mt-1 flex min-w-0 items-center gap-1.5 text-xs text-dashboard-text-muted",children:[(0,n.jsx)(r,{"aria-label":t?"Scheduled automation":`${e.source} event automation`,className:"shrink-0",role:"img",size:13}),(0,n.jsx)("span",{className:"min-w-0 truncate",title:b,children:a}),(0,n.jsx)("span",{"aria-hidden":"true",className:"shrink-0 opacity-45",children:"\xB7"}),e.destination.visibility==="private"?(0,n.jsx)(R,{"aria-label":"Private destination",className:"shrink-0",role:"img",size:12}):null,(0,n.jsx)("span",{className:"min-w-0 max-w-[45%] truncate",title:e.destination.label,children:e.destination.label})]})}function mt({automation:e}){let t=e.kind==="scheduled"&&e.status==="active"?e.nextRunAt:void 0,r=e.lastRunAt?Z(e.lastRunAt):void 0,a=e.lastRunStatus==="failed"||e.lastRunStatus==="blocked";return(0,n.jsxs)(n.Fragment,{children:[t?(0,n.jsxs)(_e,{title:Z(t),children:["Next run ",P(t)]}):null,(0,n.jsx)(_e,{title:r,children:a?(0,n.jsxs)(T,{className:"text-amber-300 underline",to:L(e.id,"runs"),children:["Last run ",e.lastRunStatus,e.lastRunAt?` ${P(e.lastRunAt)}`:null]}):e.lastRunAt?`Last run ${P(e.lastRunAt)}`:"Never run"})]})}function _e(e){return(0,n.jsxs)("span",{className:"whitespace-nowrap",title:e.title,children:[(0,n.jsx)("span",{"aria-hidden":"true",className:"mr-2 opacity-45",children:"\xB7"}),e.children]})}var d=f(x(),1),ct={costUsd:{color:"var(--color-cyan-300)",label:"Spend"}};function J(e){return Y({total:e})}function Qe(e){let t=e.bucketUnit??"day",r=e.days,a=r.map(u=>u.costUsd),b=a.reduce((u,C)=>u+C,0),g=Math.max(.01,...a),A=I(a),c=a.some(u=>u>0);return(0,d.jsxs)(S,{className:"min-h-[17rem] p-4 sm:p-5",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:Y({total:b})||"$0.00"}),(0,d.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:"Spend from conversations linked to completed automation executions."})]}),(0,d.jsxs)("div",{className:"relative mt-5 overflow-hidden",children:[(0,d.jsx)(G,{className:"aspect-auto h-50 w-full",config:ct,children:(0,d.jsxs)(E,{"aria-label":`Automation execution spend during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:r,margin:F,role:"img",children:[(0,d.jsx)(B,{strokeDasharray:"3 5",vertical:!1}),(0,d.jsx)($,{format:J,maximum:g}),(0,d.jsx)(O,{keys:r.map(u=>u.date)}),(0,d.jsx)(H,{content:(0,d.jsx)(z,{rows:u=>[["spend",J(u.costUsd)]]})}),(0,d.jsx)(D,{dataKey:"costUsd",fill:"var(--color-costUsd)",fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,radius:1}),(0,d.jsx)(M,{unit:U(t),average:A,format:J,stroke:"var(--color-slate-200)"})]})}),c?null:(0,d.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No linked spend in this period."})]})]})}var p=f(x(),1),ut={total:{color:"var(--color-amber-400)",label:"Executions"}};function Ye(e){let t=e.bucketUnit??"day",r=e.days.map(c=>({date:c.date,total:c.scheduled+c.event})),a=r.map(c=>c.total),b=Math.max(1,...a),g=I(a),A=a.some(c=>c>0);return(0,p.jsxs)(S,{className:"min-h-[17rem] p-4 sm:p-5",children:[(0,p.jsxs)("div",{children:[(0,p.jsxs)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:[a.reduce((c,u)=>c+u,0).toLocaleString()," runs"]}),(0,p.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:"Completed automation executions over time."})]}),(0,p.jsxs)("div",{className:"relative mt-5 overflow-hidden",children:[(0,p.jsx)(G,{className:"aspect-auto h-50 w-full",config:ut,children:(0,p.jsxs)(E,{"aria-label":`Automation executions during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:r,margin:F,role:"img",children:[(0,p.jsx)(B,{strokeDasharray:"3 5",vertical:!1}),(0,p.jsx)($,{maximum:b}),(0,p.jsx)(O,{keys:r.map(c=>c.date)}),(0,p.jsx)(H,{content:(0,p.jsx)(z,{rows:c=>[["executions",c.total]]})}),(0,p.jsx)(D,{dataKey:"total",fill:"var(--color-total)",fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,radius:1}),(0,p.jsx)(M,{unit:U(t),average:g,format:he,stroke:"var(--color-slate-200)"})]})}),A?null:(0,p.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No automation executions in this period."})]})]})}var o=f(x(),1),dt=["1","7","30","90"];function pt(e){let t=Number(e);return t===1||t===7||t===30||t===90?t:30}var gt=[];function pa(e){let t=ne(),r=ie(),[a,b]=Ee("range","30",dt),g=pt(a),A=l=>b(String(l)),[c,u]=oe(),[C,m]=De("q",{resetPage:!0}),y=Q.parse(Object.fromEntries(Object.entries(Q.shape).flatMap(([l,v])=>{let h=v.safeParse(c.get(l)??void 0);return h.success&&h.data!==void 0?[[l,h.data]]:[]}))),qe=new URLSearchParams(Object.entries(y).map(([l,v])=>[l,String(v)])),s=ge(e.enabled,e.view==="list"?qe.toString():""),ee=(l,v)=>{let h=new URLSearchParams(window.location.search);h.delete("page"),v?h.set(l,v):h.delete(l),u(h,{replace:!0})},Ve=l=>u(v=>{let h=new URLSearchParams(v);return l===1?h.delete("page"):h.set("page",String(l)),h}),te=l=>Be(L(l),r.search),Xe=s.data?.automations??gt,Ze=s.data?.counts.mine??0,We=s.data?.counts.public??0,Je=s.data?.counts.private??0,N=s.data?.total??0,et=Se(N,y.pageSize),tt=s.data?.page??y.page;Pe(e.view==="list"?"All automations":void 0),(0,je.useEffect)(()=>{e.view!=="list"||!s.data||s.isPlaceholderData||s.isFetching||s.data.page===y.page||u(l=>{let v=new URLSearchParams(l);return v.set("page",String(s.data.page)),v},{replace:!0})},[y.page,e.view,s.data,s.isFetching,s.isPlaceholderData,u]);let at=!s.data&&!s.error,K=s.data?.executionDays?.length?Le({days:s.data.executionDays,hours:s.data.executionHours,sixHours:s.data.executionSixHours,range:g,emptySixHour:l=>({costUsd:0,date:l,event:0,scheduled:0})}):[],it=K.length>0;return(0,o.jsxs)(o.Fragment,{children:[e.view==="overview"?(0,o.jsx)(Ue,{description:"Scheduled and event-driven work created by users.",onRangeChange:A,range:g,title:"Automations"}):(0,o.jsx)("h2",{className:"m-0 font-display text-2xl font-light tracking-tight text-dashboard-text sm:text-3xl",children:"All automations"}),e.view==="list"?(0,o.jsx)(Ge,{filters:y,data:s.data,onChange:ee,searchText:C,onSearch:m}):null,at?(0,o.jsx)(ve,{label:"Loading automations",variant:e.view==="overview"?"stats":"list"}):null,s.error?(0,o.jsxs)(we,{children:["Automations could not be loaded."," ",(0,o.jsx)(k,{onClick:()=>{s.refetch()},children:"Try again"})]}):null,s.data&&e.view==="overview"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-4",children:[(0,o.jsx)(w,{detail:"All automations you can access",icon:le,label:"Total automations",value:s.data?.counts.all??0}),(0,o.jsx)(w,{detail:"Created by you",icon:ce,label:"Your automations",value:Ze}),(0,o.jsx)(w,{detail:"In shared destinations",icon:se,label:"Public automations",value:We}),(0,o.jsx)(w,{detail:"Visible only to you",icon:R,label:"Private automations",value:Je})]}),it?(0,o.jsxs)("section",{className:"grid gap-4 xl:grid-cols-2",children:[(0,o.jsx)(Ye,{bucketUnit:V(g),days:K,range:g}),(0,o.jsx)(Qe,{bucketUnit:V(g),days:K,range:g})]}):null]}):null,s.data&&e.view==="list"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-x-5 gap-y-2",children:[(0,o.jsxs)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:[N," ",N===1?"automation":"automations",s.isFetching?(0,o.jsx)("span",{className:"ml-3",role:"status",children:"Updating results\u2026"}):null]}),(0,o.jsx)(He,{value:y.sort,onChange:l=>ee("sort",l)})]}),!s.error&&N===0?(0,o.jsx)(S,{padding:"md",children:(0,o.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No automations matched these filters."})}):(0,o.jsx)("div",{className:"grid grid-cols-[minmax(0,1fr)] gap-2",role:"list",children:Xe.map(l=>{let v=`${l.kind}:${l.id}`;return(0,o.jsx)(Ke,{onSelect:()=>t(te(l.id)),automation:l,to:te(l.id)},v)})}),(0,o.jsx)(Ne,{onPageChange:Ve,page:tt,pageCount:et,pageSize:y.pageSize,total:N})]}):null]})}export{pa as AutomationsPage};
1
+ import{a as Ie,b as Z}from"./chunk-FSGVY7HB.js";import{a as $e}from"./chunk-SIOW7OOW.js";import{a as Oe}from"./chunk-5ISD3QSC.js";import{a as Fe}from"./chunk-4UGZNVJM.js";import{b as X}from"./chunk-2J3LGF5Q.js";import{a as w}from"./chunk-PG7M7L24.js";import{a as B,c as D,f as E,o as F,p as O,q as $,r as I,s as M,t as z,w as G,x as H}from"./chunk-K4TYMAA3.js";import{a as be,b as ye,c as xe,d as Ae}from"./chunk-ZIJ6SJDN.js";import{g as Te}from"./chunk-JVJ5UWIK.js";import{a as we}from"./chunk-XNR4RZEC.js";import"./chunk-G5NWYJTV.js";import{d as ke}from"./chunk-FVX42XAD.js";import{c as Se,d as Ne}from"./chunk-3Y3ICT6K.js";import{b as ve}from"./chunk-KDUTK357.js";import{a as Re}from"./chunk-2BCS5AQL.js";import{a as Ce}from"./chunk-H76B43OQ.js";import{g as ge}from"./chunk-64GPEGGE.js";import"./chunk-ILH47V7O.js";import{K as fe,O as L,g as P,s as he,z as Y}from"./chunk-II4NXLSQ.js";import"./chunk-GMZIELFU.js";import"./chunk-MEHLQZDG.js";import"./chunk-MTBUV2GJ.js";import"./chunk-4TQSTCIN.js";import{Ka as S,P as Q,s as pe}from"./chunk-XDUSY26N.js";import{a as Be,b as De,c as Ee}from"./chunk-RHMZNAJX.js";import{C as j,D as q,E as Pe,G as V,H as U,K as Le,M as Ue,d as ie,f as ne,o as T,q as oe}from"./chunk-6PHJZPWD.js";import"./chunk-IZWTFLCC.js";import"./chunk-JAZABOBA.js";import"./chunk-WRXMQB7X.js";import"./chunk-CQY6BYUB.js";import"./chunk-VC6IS564.js";import"./chunk-B5ZN3SWQ.js";import{b as k}from"./chunk-CR2ICLSH.js";import{Ab as se,Ac as me,Kc as ce,Oc as ue,Pc as de,Tb as le,Wb as R,a as ae,b as x,fb as re}from"./chunk-YPMUHXYT.js";import{c as f}from"./chunk-7SZRL6FY.js";var je=f(ae(),1);var _=f(ae(),1);var i=f(x(),1),Me="(min-width: 768px)",ze=[{value:"active",label:"Active"},{value:"blocked",label:"Blocked"},{value:"paused",label:"Paused"},{value:"unavailable",label:"Trigger unavailable"},{value:"completed",label:"Completed"}];function nt(e){let t=window.matchMedia(Me);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function ot(){return window.matchMedia(Me).matches}function Ge(e){let{filters:t,data:r,onChange:a}=e,[b,g]=(0,_.useState)(!1),A=(0,_.useSyncExternalStore)(nt,ot,()=>!1),c=[{key:"type",label:"Type",value:t.type==="all"?"":t.type,valueLabel:t.type==="scheduled"?"Scheduled":"Event"},{key:"creator",label:"Creator",value:t.creator,valueLabel:r?.creators.find(m=>m.value===t.creator)?.label??t.creator},{key:"destination",label:"Destination",value:t.destination,valueLabel:r?.destinations.find(m=>m.value===t.destination)?.label??t.destination},{key:"state",label:"State",value:t.state==="all"?"":t.state,valueLabel:ze.find(m=>m.value===t.state)?.label}].filter(m=>m.value),u=(0,i.jsxs)(k,{className:"h-11 shrink-0","aria-expanded":b,"aria-haspopup":"dialog",onClick:A?void 0:()=>g(!0),children:[(0,i.jsx)(me,{"aria-hidden":"true",size:14})," Filters",c.length?` (${c.length})`:""]}),C=(0,i.jsx)(rt,{filters:t,data:r,onChange:a});return(0,i.jsxs)("div",{className:"grid gap-3",children:[(0,i.jsxs)("div",{className:"grid gap-2 lg:grid-cols-[auto_minmax(16rem,1fr)] lg:items-center lg:gap-4",children:[(0,i.jsx)(j,{"aria-label":"Scope",className:"flex-wrap gap-2",onValueChange:([m])=>{m&&a("scope",m)},value:[t.scope],children:[["all","All"],["mine","Mine"],["public","Public"],["attention","Needs attention"]].map(([m,y])=>(0,i.jsxs)(q,{className:"min-h-11 lg:min-h-9",value:m,variant:"pill",children:[y,r&&m!=="attention"?(0,i.jsx)("span",{className:"ml-1.5 opacity-65",children:r.counts[m]}):null]},m))}),(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(Ce,{className:"flex-1",size:"default",label:"Search automations",placeholder:"Search automations",value:e.searchText,onChange:e.onSearch}),A?(0,i.jsxs)(be,{open:b,onOpenChange:g,children:[(0,i.jsx)(ye,{render:u}),(0,i.jsxs)(xe,{align:"end",className:"w-80",children:[(0,i.jsx)(Ae,{children:"Filters"}),(0,i.jsx)("div",{className:"mt-4",children:C})]})]}):u]})]}),c.length>0?(0,i.jsx)("div",{"aria-label":"Active filters",role:"group",className:"flex min-w-0 flex-wrap gap-2",children:c.map(m=>(0,i.jsxs)(k,{"aria-label":`Remove ${m.key} filter`,className:"min-h-9 max-w-full text-xs",title:`${m.label}: ${m.valueLabel}`,onClick:()=>a(m.key,""),children:[(0,i.jsxs)("span",{className:"truncate",children:[m.label,": ",m.valueLabel]}),(0,i.jsx)(ue,{"aria-hidden":"true",className:"shrink-0",size:12})]},m.key))}):null,!A&&b?(0,i.jsx)(Te,{label:"Filters",size:"content",onClose:()=>g(!1),children:(0,i.jsx)("div",{className:"p-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:C})}):null]})}function rt({filters:e,data:t,onChange:r}){return(0,i.jsxs)("div",{className:"grid gap-4",children:[(0,i.jsx)(X,{label:"Type",children:(0,i.jsx)(j,{className:"flex-wrap gap-2",onValueChange:([a])=>{a&&r("type",a)},value:[e.type],children:["all","scheduled","event"].map(a=>(0,i.jsx)(q,{className:"min-h-9",value:a,variant:"pill",children:a},a))})}),(0,i.jsx)(W,{label:"Creator",emptyLabel:"All",value:e.creator??"",options:t?.creators??[],onChange:a=>r("creator",a)}),(0,i.jsx)(W,{label:"Destination",emptyLabel:"All",value:e.destination??"",options:t?.destinations??[],onChange:a=>r("destination",a)}),(0,i.jsx)(W,{label:"State",emptyLabel:"All",value:e.state==="all"?"":e.state,options:ze,onChange:a=>r("state",a)})]})}function He(e){return(0,i.jsx)(Oe,{ariaLabel:"Sort automations",onChange:e.onChange,options:[{value:"newest",label:"Recently created"},{value:"oldest",label:"Oldest created"},{value:"title",label:"Title A\u2013Z"}],value:e.value})}function W(e){return(0,i.jsx)(X,{label:e.label,children:(0,i.jsxs)(Fe,{"aria-label":e.ariaLabel??`Filter by ${e.label.toLowerCase()}`,variant:"filter",value:e.value,onChange:t=>e.onChange(t.currentTarget.value),children:[e.emptyLabel?(0,i.jsx)("option",{value:"",children:e.emptyLabel}):null,e.value&&!e.options.some(t=>t.value===e.value)?(0,i.jsx)("option",{value:e.value,children:e.value}):null,e.options.map(t=>(0,i.jsx)("option",{value:t.value,children:t.label},t.value))]})})}var n=f(x(),1);function Ke(e){let{automation:t}=e,r=st(t),a=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ke,{imageUrl:t.createdByAvatarUrl,name:t.createdBy,size:"list"}),(0,n.jsx)("span",{className:"truncate",children:t.createdBy})]});return(0,n.jsx)("article",{className:"min-w-0 rounded-lg border border-dashboard-border-subtle bg-dashboard-fill-faint","data-automation-id":t.id,role:"listitem",children:(0,n.jsx)($e,{className:"flex items-start gap-3 rounded-lg px-4 py-3.5",onSelect:e.onSelect,selected:!1,children:(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)(T,{"aria-label":`Open automation: ${t.title}`,className:"block w-full min-w-0 rounded-md text-left no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",to:e.to,children:[(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-2",children:[(0,n.jsx)("span",{className:"truncate font-display text-base font-medium text-dashboard-text",title:t.title,children:t.title}),r?(0,n.jsx)(Re,{className:"shrink-0",size:"compact",tone:r==="completed"||r==="paused"?"neutral":"warning",children:r}):null]}),(0,n.jsx)(lt,{automation:t})]}),(0,n.jsxs)("div",{className:"mt-2.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-dashboard-text-muted",children:[t.createdByEmail?(0,n.jsx)(T,{className:"inline-flex min-w-0 max-w-full items-center gap-2 rounded-md text-dashboard-text no-underline hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",title:t.createdBy,to:fe(t.createdByEmail),children:a}):(0,n.jsx)("span",{className:"inline-flex min-w-0 max-w-full items-center gap-2 text-dashboard-text",title:t.createdBy,children:a}),(0,n.jsx)(mt,{automation:t})]})]})})})}function st(e){return e.kind==="scheduled"?e.status==="active"?void 0:e.status:e.status!=="active"?e.status:e.trigger.problems.length===0?void 0:"Trigger unavailable"}function lt({automation:e}){let t=e.kind==="scheduled",r=t?re:de,a=e.kind==="scheduled"?e.schedule:pe(e.resource,e.trigger),b=e.kind==="scheduled"?Ie(e):a;return(0,n.jsxs)("span",{className:"mt-1 flex min-w-0 items-center gap-1.5 text-xs text-dashboard-text-muted",children:[(0,n.jsx)(r,{"aria-label":t?"Scheduled automation":`${e.source} event automation`,className:"shrink-0",role:"img",size:13}),(0,n.jsx)("span",{className:"min-w-0 truncate",title:b,children:a}),(0,n.jsx)("span",{"aria-hidden":"true",className:"shrink-0 opacity-45",children:"\xB7"}),e.destination.visibility==="private"?(0,n.jsx)(R,{"aria-label":"Private destination",className:"shrink-0",role:"img",size:12}):null,(0,n.jsx)("span",{className:"min-w-0 max-w-[45%] truncate",title:e.destination.label,children:e.destination.label})]})}function mt({automation:e}){let t=e.kind==="scheduled"&&e.status==="active"?e.nextRunAt:void 0,r=e.lastRunAt?Z(e.lastRunAt):void 0,a=e.lastRunStatus==="failed"||e.lastRunStatus==="blocked";return(0,n.jsxs)(n.Fragment,{children:[t?(0,n.jsxs)(_e,{title:Z(t),children:["Next run ",P(t)]}):null,(0,n.jsx)(_e,{title:r,children:a?(0,n.jsxs)(T,{className:"text-amber-300 underline",to:L(e.id,"runs"),children:["Last run ",e.lastRunStatus,e.lastRunAt?` ${P(e.lastRunAt)}`:null]}):e.lastRunAt?`Last run ${P(e.lastRunAt)}`:"Never run"})]})}function _e(e){return(0,n.jsxs)("span",{className:"whitespace-nowrap",title:e.title,children:[(0,n.jsx)("span",{"aria-hidden":"true",className:"mr-2 opacity-45",children:"\xB7"}),e.children]})}var d=f(x(),1),ct={costUsd:{color:"var(--color-cyan-300)",label:"Spend"}};function J(e){return Y({total:e})}function Qe(e){let t=e.bucketUnit??"day",r=e.days,a=r.map(u=>u.costUsd),b=a.reduce((u,C)=>u+C,0),g=Math.max(.01,...a),A=I(a),c=a.some(u=>u>0);return(0,d.jsxs)(S,{className:"min-h-[17rem] p-4 sm:p-5",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:Y({total:b})||"$0.00"}),(0,d.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:"Spend from conversations linked to completed automation executions."})]}),(0,d.jsxs)("div",{className:"relative mt-5 overflow-hidden",children:[(0,d.jsx)(G,{className:"aspect-auto h-50 w-full",config:ct,children:(0,d.jsxs)(E,{"aria-label":`Automation execution spend during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:r,margin:F,role:"img",children:[(0,d.jsx)(B,{strokeDasharray:"3 5",vertical:!1}),(0,d.jsx)($,{format:J,maximum:g}),(0,d.jsx)(O,{keys:r.map(u=>u.date)}),(0,d.jsx)(H,{content:(0,d.jsx)(z,{rows:u=>[["spend",J(u.costUsd)]]})}),(0,d.jsx)(D,{dataKey:"costUsd",fill:"var(--color-costUsd)",fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,radius:1}),(0,d.jsx)(M,{unit:U(t),average:A,format:J,stroke:"var(--color-slate-200)"})]})}),c?null:(0,d.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No linked spend in this period."})]})]})}var p=f(x(),1),ut={total:{color:"var(--color-amber-400)",label:"Executions"}};function Ye(e){let t=e.bucketUnit??"day",r=e.days.map(c=>({date:c.date,total:c.scheduled+c.event})),a=r.map(c=>c.total),b=Math.max(1,...a),g=I(a),A=a.some(c=>c>0);return(0,p.jsxs)(S,{className:"min-h-[17rem] p-4 sm:p-5",children:[(0,p.jsxs)("div",{children:[(0,p.jsxs)("h2",{className:"m-0 font-display text-xl font-medium text-dashboard-text",children:[a.reduce((c,u)=>c+u,0).toLocaleString()," runs"]}),(0,p.jsx)("p",{className:"mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted",children:"Completed automation executions over time."})]}),(0,p.jsxs)("div",{className:"relative mt-5 overflow-hidden",children:[(0,p.jsx)(G,{className:"aspect-auto h-50 w-full",config:ut,children:(0,p.jsxs)(E,{"aria-label":`Automation executions during the last ${e.range===1?"24 hours":`${e.range} days`}`,data:r,margin:F,role:"img",children:[(0,p.jsx)(B,{strokeDasharray:"3 5",vertical:!1}),(0,p.jsx)($,{maximum:b}),(0,p.jsx)(O,{keys:r.map(c=>c.date)}),(0,p.jsx)(H,{content:(0,p.jsx)(z,{rows:c=>[["executions",c.total]]})}),(0,p.jsx)(D,{dataKey:"total",fill:"var(--color-total)",fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,radius:1}),(0,p.jsx)(M,{unit:U(t),average:g,format:he,stroke:"var(--color-slate-200)"})]})}),A?null:(0,p.jsx)("div",{className:"pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted",children:"No automation executions in this period."})]})]})}var o=f(x(),1),dt=["1","7","30","90"];function pt(e){let t=Number(e);return t===1||t===7||t===30||t===90?t:30}var gt=[];function pa(e){let t=ne(),r=ie(),[a,b]=Ee("range","30",dt),g=pt(a),A=l=>b(String(l)),[c,u]=oe(),[C,m]=De("q",{resetPage:!0}),y=Q.parse(Object.fromEntries(Object.entries(Q.shape).flatMap(([l,v])=>{let h=v.safeParse(c.get(l)??void 0);return h.success&&h.data!==void 0?[[l,h.data]]:[]}))),qe=new URLSearchParams(Object.entries(y).map(([l,v])=>[l,String(v)])),s=ge(e.enabled,e.view==="list"?qe.toString():""),ee=(l,v)=>{let h=new URLSearchParams(window.location.search);h.delete("page"),v?h.set(l,v):h.delete(l),u(h,{replace:!0})},Ve=l=>u(v=>{let h=new URLSearchParams(v);return l===1?h.delete("page"):h.set("page",String(l)),h}),te=l=>Be(L(l),r.search),Xe=s.data?.automations??gt,Ze=s.data?.counts.mine??0,We=s.data?.counts.public??0,Je=s.data?.counts.private??0,N=s.data?.total??0,et=Se(N,y.pageSize),tt=s.data?.page??y.page;Pe(e.view==="list"?"All automations":void 0),(0,je.useEffect)(()=>{e.view!=="list"||!s.data||s.isPlaceholderData||s.isFetching||s.data.page===y.page||u(l=>{let v=new URLSearchParams(l);return v.set("page",String(s.data.page)),v},{replace:!0})},[y.page,e.view,s.data,s.isFetching,s.isPlaceholderData,u]);let at=!s.data&&!s.error,K=s.data?.executionDays?.length?Le({days:s.data.executionDays,hours:s.data.executionHours,sixHours:s.data.executionSixHours,range:g,emptySixHour:l=>({costUsd:0,date:l,event:0,scheduled:0})}):[],it=K.length>0;return(0,o.jsxs)(o.Fragment,{children:[e.view==="overview"?(0,o.jsx)(Ue,{description:"Scheduled and event-driven work created by users.",onRangeChange:A,range:g,title:"Automations"}):(0,o.jsx)("h2",{className:"m-0 font-display text-2xl font-light tracking-tight text-dashboard-text sm:text-3xl",children:"All automations"}),e.view==="list"?(0,o.jsx)(Ge,{filters:y,data:s.data,onChange:ee,searchText:C,onSearch:m}):null,at?(0,o.jsx)(ve,{label:"Loading automations",variant:e.view==="overview"?"stats":"list"}):null,s.error?(0,o.jsxs)(we,{children:["Automations could not be loaded."," ",(0,o.jsx)(k,{onClick:()=>{s.refetch()},children:"Try again"})]}):null,s.data&&e.view==="overview"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-4",children:[(0,o.jsx)(w,{detail:"All automations you can access",icon:le,label:"Total automations",value:s.data?.counts.all??0}),(0,o.jsx)(w,{detail:"Created by you",icon:ce,label:"Your automations",value:Ze}),(0,o.jsx)(w,{detail:"In shared destinations",icon:se,label:"Public automations",value:We}),(0,o.jsx)(w,{detail:"Visible only to you",icon:R,label:"Private automations",value:Je})]}),it?(0,o.jsxs)("section",{className:"grid gap-4 xl:grid-cols-2",children:[(0,o.jsx)(Ye,{bucketUnit:V(g),days:K,range:g}),(0,o.jsx)(Qe,{bucketUnit:V(g),days:K,range:g})]}):null]}):null,s.data&&e.view==="list"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-x-5 gap-y-2",children:[(0,o.jsxs)("p",{className:"m-0 text-xs text-dashboard-text-muted",children:[N," ",N===1?"automation":"automations",s.isFetching?(0,o.jsx)("span",{className:"ml-3",role:"status",children:"Updating results\u2026"}):null]}),(0,o.jsx)(He,{value:y.sort,onChange:l=>ee("sort",l)})]}),!s.error&&N===0?(0,o.jsx)(S,{padding:"md",children:(0,o.jsx)("p",{className:"m-0 text-sm text-dashboard-text-muted",children:"No automations matched these filters."})}):(0,o.jsx)("div",{className:"grid grid-cols-[minmax(0,1fr)] gap-2",role:"list",children:Xe.map(l=>{let v=`${l.kind}:${l.id}`;return(0,o.jsx)(Ke,{onSelect:()=>t(te(l.id)),automation:l,to:te(l.id)},v)})}),(0,o.jsx)(Ne,{onPageChange:Ve,page:tt,pageCount:et,pageSize:y.pageSize,total:N})]}):null]})}export{pa as AutomationsPage};