@lobu/runtime-server 24.10.0 → 24.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/catalogs/connectors.json +1 -1
  2. package/dist/catalogs/skills.json +1 -1
  3. package/dist/component.json +1 -1
  4. package/dist/connectors/linkedin-inbox-adapter.js +13 -3
  5. package/dist/connectors/whatsapp-web-adapter.js +14 -13
  6. package/dist/connectors/whatsapp-web-helpers.ts +37 -1
  7. package/dist/connectors/whatsapp_web.ts +5 -5
  8. package/dist/connectors/x-dm-adapter.js +17 -3
  9. package/dist/db/migrations/20261113170000_member_sql_rls.sql +254 -0
  10. package/dist/db/migrations/20261113180000_member_sql_rls_parallel_plans.sql +192 -0
  11. package/dist/db/migrations/20261113190000_member_sql_schema_usage.sql +24 -0
  12. package/dist/db/migrations/20261114120000_events_owner_only_visibility.sql +39 -0
  13. package/dist/db/migrations/20261115120000_events_unbound_tool_audit_without_bridge.sql +40 -0
  14. package/dist/db/migrations/20261115120001_events_unbound_tool_audit_validate.sql +19 -0
  15. package/dist/db/migrations/20261115120002_drop_events_linked_org_ids.sql +119 -0
  16. package/dist/dependencies.bun.lock +10 -10
  17. package/dist/embeddings-server.mjs +1 -1
  18. package/dist/guest.bundle.js +1 -1
  19. package/dist/owletto/dist/assets/_-BDMUN9XZ.js +2 -0
  20. package/dist/owletto/dist/assets/_-CF5X4ANe.js +3 -0
  21. package/dist/owletto/dist/assets/{_agentId-DN0EwMAC.js → _agentId-CGScf8z_.js} +2 -2
  22. package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +2 -0
  23. package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +2 -0
  24. package/dist/owletto/dist/assets/{_connectorKey._connectionId-CVKfL9AG.js → _connectorKey._connectionId-DcI29kGy.js} +2 -2
  25. package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +2 -0
  26. package/dist/owletto/dist/assets/{_conversationId-CPpNySjO.js → _conversationId-CnmLYlVS.js} +2 -2
  27. package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +2 -0
  28. package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +3 -0
  29. package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +2 -0
  30. package/dist/owletto/dist/assets/{_slug-DJx_8fsV.js → _slug-COPpRXLt.js} +2 -2
  31. package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +2 -0
  32. package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +2 -0
  33. package/dist/owletto/dist/assets/{accept-invitation-Dwq1GAnG.js → accept-invitation-BKeIzZXE.js} +2 -2
  34. package/dist/owletto/dist/assets/{activity-route-location-C1jcXC7v.js → activity-route-location-sLvKaSCa.js} +2 -2
  35. package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +2 -0
  36. package/dist/owletto/dist/assets/{agent-connect-pages-DoI9UR0a.js → agent-connect-pages-DVq9nAR7.js} +3 -3
  37. package/dist/owletto/dist/assets/{agent-editor-form-DlavYg2q.js → agent-editor-form-DVFyyMyd.js} +2 -2
  38. package/dist/owletto/dist/assets/{agent-loading-shells-DYqQphN7.js → agent-loading-shells-BLNHIy-r.js} +2 -2
  39. package/dist/owletto/dist/assets/{agent-permissions-matrix-C1L8IcYR.js → agent-permissions-matrix-UBKRR5vs.js} +2 -2
  40. package/dist/owletto/dist/assets/{agent-skill-context-D1nMrVod.js → agent-skill-context-fqedKd0D.js} +2 -2
  41. package/dist/owletto/dist/assets/{agent-subpage-shell-2w7vTeXw.js → agent-subpage-shell-BUCoY2Nf.js} +2 -2
  42. package/dist/owletto/dist/assets/{agent-thread-BopD-2k1.js → agent-thread-Cqf9ITrT.js} +2 -2
  43. package/dist/owletto/dist/assets/app-bridge-B-L0rGz9.js +121 -0
  44. package/dist/owletto/dist/assets/{app._appId-BXeFXW1w.js → app._appId-ByIypCL9.js} +2 -2
  45. package/dist/owletto/dist/assets/{assist-composer-CL5x8pNt.js → assist-composer-kG_heHXo.js} +2 -2
  46. package/dist/owletto/dist/assets/{automation-run-now-MtxUTfzd.js → automation-run-now-C5XTS00o.js} +2 -2
  47. package/dist/owletto/dist/assets/{callback-BgfwP1Eo.js → callback-Pz5uS-k7.js} +2 -2
  48. package/dist/owletto/dist/assets/{card-DtLIFq7D.js → card-CAPpY9P5.js} +2 -2
  49. package/dist/owletto/dist/assets/{claim-CT3hYVMF.js → claim-DgWWK0KI.js} +2 -2
  50. package/dist/owletto/dist/assets/{client-activity-scopes-BPbRX-Pe.js → client-activity-scopes-Aqdo6Pdr.js} +2 -2
  51. package/dist/owletto/dist/assets/{client-rows-vrNA6FLs.js → client-rows-Dd5YV8vn.js} +2 -2
  52. package/dist/owletto/dist/assets/{clients-xnzZeEdZ.js → clients-Bf7ZgGro.js} +2 -2
  53. package/dist/owletto/dist/assets/{code-editor-mrKkAfcE.js → code-editor-z1Sy_hiX.js} +2 -2
  54. package/dist/owletto/dist/assets/connect-BFNp1y_s.js +2 -0
  55. package/dist/owletto/dist/assets/{connect-menu-C6iVtuSo.js → connect-menu-BWrAhMqO.js} +2 -2
  56. package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +2 -0
  57. package/dist/owletto/dist/assets/{connected._clientId-ROfVgp9h.js → connected._clientId-CuOeHafK.js} +2 -2
  58. package/dist/owletto/dist/assets/{connection-BMz740Wi.js → connection-CVeHmDLs.js} +2 -2
  59. package/dist/owletto/dist/assets/{connection-feed-detail-0VAJiZTP.js → connection-feed-detail-BYo7zdVD.js} +2 -2
  60. package/dist/owletto/dist/assets/{connector-page-shell-BFv21yuv.js → connector-page-shell-an3SYLim.js} +2 -2
  61. package/dist/owletto/dist/assets/{connector-provenance-b59RfBtk.js → connector-provenance-mSZCOud-.js} +2 -2
  62. package/dist/owletto/dist/assets/{connectors-nYS31lO2.js → connectors-DBEM9QQz.js} +2 -2
  63. package/dist/owletto/dist/assets/{consent-cPRF9JQv.js → consent-1ulwyJ3k.js} +2 -2
  64. package/dist/owletto/dist/assets/{copy-button-C3wMMv63.js → copy-button-Xhh7ZnjO.js} +2 -2
  65. package/dist/owletto/dist/assets/{core.esm-C9QlSrgK.js → core.esm-Ctg_pXLe.js} +2 -2
  66. package/dist/owletto/dist/assets/{create-CGOWfMk4.js → create-CGuoqPh8.js} +2 -2
  67. package/dist/owletto/dist/assets/create-Ccb5R-S4.js +2 -0
  68. package/dist/owletto/dist/assets/{create-ASRN3Obq.js → create-DmhbacIa.js} +2 -2
  69. package/dist/owletto/dist/assets/{create-automation-form-CLicoPH5.js → create-automation-form-CD6jSlWL.js} +2 -2
  70. package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +2 -0
  71. package/dist/owletto/dist/assets/{custom-guardrail-edits-BUL7nmuO.js → custom-guardrail-edits-Ce_BwiwD.js} +2 -2
  72. package/dist/owletto/dist/assets/{definition-comparison-4UYMI6BK.js → definition-comparison-D_qP25jR.js} +2 -2
  73. package/dist/owletto/dist/assets/{detail-page-skeleton-C8v3rJXK.js → detail-page-skeleton-CPAfZLG0.js} +2 -2
  74. package/dist/owletto/dist/assets/{device-BBwsOi7q.js → device-DDl5XKvt.js} +2 -2
  75. package/dist/owletto/dist/assets/{device-pin-tombstone-Bcpe7nAA.js → device-pin-tombstone-Dkj7hrBE.js} +2 -2
  76. package/dist/owletto/dist/assets/{device._deviceId-DLT4jh0Z.js → device._deviceId-bNhTcops.js} +2 -2
  77. package/dist/owletto/dist/assets/{dynamic-schema-form-BDT8x0Vg.js → dynamic-schema-form-CRyUchXo.js} +2 -2
  78. package/dist/owletto/dist/assets/{entity-options-B9hm9V87.js → entity-options-D4t-NAcg.js} +2 -2
  79. package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +2 -0
  80. package/dist/owletto/dist/assets/{entity-pages-BWBpttz3.js → entity-pages-_nuesgnp.js} +2 -2
  81. package/dist/owletto/dist/assets/{entity-schema-graph-lMMx3HhR.js → entity-schema-graph-Cq96SJ3c.js} +2 -2
  82. package/dist/owletto/dist/assets/{entity-type-page-CkQm0yEu.js → entity-type-page-CkCSbkBx.js} +2 -2
  83. package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +2 -0
  84. package/dist/owletto/dist/assets/{events-feed-DmRzikZW.js → events-feed-DcKTkJVe.js} +2 -2
  85. package/dist/owletto/dist/assets/{filter-editors-CQoSj-20.js → filter-editors-DGVl9U4D.js} +3 -3
  86. package/dist/owletto/dist/assets/{full-page-spinner-CYyCnKve.js → full-page-spinner-CtVlF8GQ.js} +2 -2
  87. package/dist/owletto/dist/assets/index-BUlkNJzX.js +2 -0
  88. package/dist/owletto/dist/assets/{index-BS5Ty3tf.js → index-BifR-LE9.js} +2 -2
  89. package/dist/owletto/dist/assets/{index-DByaMzsG.js → index-BoqrvLHQ.js} +1383 -1383
  90. package/dist/owletto/dist/assets/index-CA9mW_ZM.js +2 -0
  91. package/dist/owletto/dist/assets/index-CH0GzG4i.js +2 -0
  92. package/dist/owletto/dist/assets/index-CK5GDX4B.js +2 -0
  93. package/dist/owletto/dist/assets/index-CtI5Eomq.js +2 -0
  94. package/dist/owletto/dist/assets/{index-CUndAH6o.js → index-DbjbHlDe.js} +2 -2
  95. package/dist/owletto/dist/assets/index-DmtQ0bds.js +2 -0
  96. package/dist/owletto/dist/assets/{index-CDyFQ32o.js → index-Du_J8hnx.js} +2 -2
  97. package/dist/owletto/dist/assets/{index-ittfA0k8.js → index-DvuJ_S_o.js} +2 -2
  98. package/dist/owletto/dist/assets/index-Pae_f9LM.css +1 -0
  99. package/dist/owletto/dist/assets/{index-C3hz9tzx.js → index-XETZnN7L.js} +2 -2
  100. package/dist/owletto/dist/assets/{json-diff-mcDgyct_.js → json-diff-OjtREegr.js} +2 -2
  101. package/dist/owletto/dist/assets/{list-skeleton-DsYGUHxi.js → list-skeleton-CH0qQBYk.js} +2 -2
  102. package/dist/owletto/dist/assets/{login-EoLq136v.js → login-DG0b9uSC.js} +2 -2
  103. package/dist/owletto/dist/assets/{logout-gLgEQOiX.js → logout-DfdgOLoM.js} +2 -2
  104. package/dist/owletto/dist/assets/{member-scope-gate-vvkgSAb2.js → member-scope-gate-Cxg2zGQT.js} +2 -2
  105. package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +74 -0
  106. package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +2 -0
  107. package/dist/owletto/dist/assets/{model-selector-D3vSMLO2.js → model-selector-D2OpDkwH.js} +2 -2
  108. package/dist/owletto/dist/assets/{needs-you-list-B5Bgd05M.js → needs-you-list-3uMsWcDv.js} +2 -2
  109. package/dist/owletto/dist/assets/{new-dLXsCHBd.js → new-AdGV6a8R.js} +2 -2
  110. package/dist/owletto/dist/assets/new-BdtIhBpo.js +2 -0
  111. package/dist/owletto/dist/assets/{new-Bk_flKQO.js → new-BjGwX6s6.js} +2 -2
  112. package/dist/owletto/dist/assets/{new-BPW3V0Y1.js → new-D-iMjV74.js} +2 -2
  113. package/dist/owletto/dist/assets/{organization-DBfgBkzq.js → organization-qaIpEiQg.js} +2 -2
  114. package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +2 -0
  115. package/dist/owletto/dist/assets/{pending-seed-CBhx2Ql-.js → pending-seed-BBACroge.js} +2 -2
  116. package/dist/owletto/dist/assets/{proposal-review-shell-B-jYcKfB.js → proposal-review-shell-C8ZfIAYn.js} +2 -2
  117. package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +2 -0
  118. package/dist/owletto/dist/assets/{record-session-CAmGHMyM.js → record-session-BrM9cdXu.js} +2 -2
  119. package/dist/owletto/dist/assets/{renderer-olRv_HMI.js → renderer-CTKNMcXP.js} +4 -4
  120. package/dist/owletto/dist/assets/{reset-password-B9_xi8Pq.js → reset-password-DKBEneyR.js} +2 -2
  121. package/dist/owletto/dist/assets/{run-initiator-DhE5v4z0.js → run-initiator-BKSgI1o0.js} +2 -2
  122. package/dist/owletto/dist/assets/{runs-C8sZQr4o.js → runs-k2NpbZm8.js} +2 -2
  123. package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +2 -0
  124. package/dist/owletto/dist/assets/{schema-value-zTJGE4eh.js → schema-value-wjqGxXhv.js} +3 -3
  125. package/dist/owletto/dist/assets/{scoped-feed-bar-BKyJSa3_.js → scoped-feed-bar-DNFL0sYX.js} +2 -2
  126. package/dist/owletto/dist/assets/{settings-z02cvVS3.js → settings-V0m5Om5j.js} +2 -2
  127. package/dist/owletto/dist/assets/{source-record-panels-CGmKIJdN.js → source-record-panels-BMut9YIA.js} +2 -2
  128. package/dist/owletto/dist/assets/{status-variants-DyRCXBzM.js → status-variants-SzXYYedJ.js} +2 -2
  129. package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +2 -0
  130. package/dist/owletto/dist/assets/{table-C637cQxG.js → table-ZuYMOjVR.js} +2 -2
  131. package/dist/owletto/dist/assets/{use-automations-CgWNoYio.js → use-automations-DfBtVzGa.js} +2 -2
  132. package/dist/owletto/dist/assets/{use-login-redirect-tDdhXTpt.js → use-login-redirect-BDiS3eyl.js} +2 -2
  133. package/dist/owletto/dist/assets/{use-mention-search-D-kIKchD.js → use-mention-search-khySpz_V.js} +2 -2
  134. package/dist/owletto/dist/assets/view-card-DiHWlypr.js +2 -0
  135. package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +2 -0
  136. package/dist/owletto/dist/assets/{views-access-required-C35Dyt91.js → views-access-required-HA-PiOwA.js} +2 -2
  137. package/dist/owletto/dist/index.html +2 -2
  138. package/dist/server-main.bundle.mjs +1099 -545
  139. package/npm-shrinkwrap.json +38 -38
  140. package/package.json +1 -1
  141. package/vendor/connector-sdk/package.json +1 -1
  142. package/vendor/core/package.json +1 -1
  143. package/vendor/views/package.json +1 -1
  144. package/dist/owletto/dist/assets/_-CYvj1y65.js +0 -3
  145. package/dist/owletto/dist/assets/_-CeLTSYYY.js +0 -2
  146. package/dist/owletto/dist/assets/_agentId-BB5E-L6T.js +0 -2
  147. package/dist/owletto/dist/assets/_automationId-DvUl9CSd.js +0 -2
  148. package/dist/owletto/dist/assets/_connectorKey.index-Cv6FzK1v.js +0 -2
  149. package/dist/owletto/dist/assets/_eventId-DZKicuq6.js +0 -2
  150. package/dist/owletto/dist/assets/_owner-Dauk3YuD.js +0 -3
  151. package/dist/owletto/dist/assets/_shape-cKrEID3T.js +0 -2
  152. package/dist/owletto/dist/assets/_viewKey-CPVzVKEf.js +0 -2
  153. package/dist/owletto/dist/assets/_viewKey-CW8gexOQ.js +0 -2
  154. package/dist/owletto/dist/assets/activity-route-view-D78Wj0RH.js +0 -2
  155. package/dist/owletto/dist/assets/app-bridge-C4nPtae3.js +0 -121
  156. package/dist/owletto/dist/assets/connect-NUCSay8X.js +0 -2
  157. package/dist/owletto/dist/assets/connect._clientId-Cp-d9Q5b.js +0 -2
  158. package/dist/owletto/dist/assets/create-CBcodaSO.js +0 -2
  159. package/dist/owletto/dist/assets/create._connectorKey-s4xkktTC.js +0 -2
  160. package/dist/owletto/dist/assets/entity-page-DZjzQ2V4.js +0 -2
  161. package/dist/owletto/dist/assets/event-detail-CkzfakTK.js +0 -2
  162. package/dist/owletto/dist/assets/index-BE7eb2kE.js +0 -2
  163. package/dist/owletto/dist/assets/index-BFR0uiKY.js +0 -2
  164. package/dist/owletto/dist/assets/index-C38OzBpB.js +0 -2
  165. package/dist/owletto/dist/assets/index-CiKysEhV.js +0 -2
  166. package/dist/owletto/dist/assets/index-DfdinB7B.js +0 -2
  167. package/dist/owletto/dist/assets/index-DgMM4Zt5.css +0 -1
  168. package/dist/owletto/dist/assets/index-Xk711gVC.js +0 -2
  169. package/dist/owletto/dist/assets/memory-browse-page-DvDtwrEI.js +0 -74
  170. package/dist/owletto/dist/assets/new-C5HtQdM_.js +0 -2
  171. package/dist/owletto/dist/assets/peek-pane-content-c2PG3TEX.js +0 -2
  172. package/dist/owletto/dist/assets/public-shell-ready-D8TijlRY.js +0 -2
  173. package/dist/owletto/dist/assets/record-activity-DnRVOrG2.js +0 -2
  174. package/dist/owletto/dist/assets/runs-list-CwtH-wmk.js +0 -2
  175. package/dist/owletto/dist/assets/subDays-D8nHthaS.js +0 -2
  176. package/dist/owletto/dist/assets/view-param-filters-CUCj9Df-.js +0 -2
@@ -1,74 +0,0 @@
1
- import{eG as Tt,c3 as Is,c4 as As,g0 as Ps,g1 as Fs,j as s,dv as Ds,c8 as Vs,Z as Ve,$ as se,bR as Bs,B as R,by as It,g2 as At,g3 as te,g4 as je,g5 as qs,g6 as Hs,g7 as Qe,g8 as Us,g9 as He,ga as Ue,gb as zs,gc as Gs,gd as Js,z as Pt,dI as Ne,r as x,d9 as Ws,ex as Ys,K as Qs,eD as Zs,M as Ee,x as Ft,cz as Ks,f_ as Xs,c as ne,u as Dt,fe as en,b$ as tn,bc as Vt,d8 as Bt,fG as sn,fY as nn,e_ as an,a7 as ze,i as ie,dL as qt,ge as rn,L as ke,e6 as on,c_ as ln,aE as Ht,aF as Ut,dh as zt,aH as Gt,aI as cn,aJ as dn,aK as un,aL as mn,aM as Ct,aQ as pn,cT as fn,aO as hn,cP as Jt,a9 as gn,gf as Wt,gg as Yt,aw as yn,gh as xn,V as Qt,H as bn,gi as vn,ci as Z,w as Zt,gj as Be,cJ as jn,gk as Nn,gl as Sn,dU as Et,gm as qe,gn as wn,go as Cn,d7 as En,dg as kn,cF as _n,cG as $n,cg as Ge,dE as Rn,gp as Ln,gq as Je,gr as On,gs as Mn,d4 as Tn,bo as In,cZ as An,gt as Pn,gu as Fn,a as Dn,gv as Vn,gw as Bn,gx as qn,gy as Hn,cO as Un,at as zn,aS as Gn}from"./index-DByaMzsG.js";import{P as Jn}from"./public-shell-ready-D8TijlRY.js";import{D as Wn,c as Yn}from"./dynamic-schema-form-BDT8x0Vg.js";import{S as Qn,E as Kt,a as Zn,e as Kn,b as Xn,c as ea}from"./entity-pages-BWBpttz3.js";import{b as ta,F as sa}from"./filter-editors-CQoSj-20.js";import{l as na,H as aa,n as ra,G as Xt,c as oa}from"./entity-schema-graph-lMMx3HhR.js";import{l as ia,p as _e,e as es,a as la,S as ca,J as da}from"./renderer-olRv_HMI.js";import{u as ua,a as ma,D as pa,P as fa,b as ts,c as ha,C as ga}from"./core.esm-C9QlSrgK.js";import{v as ya,V as ss,M as ns,a as as,w as xa,b as ba}from"./view-param-filters-CUCj9Df-.js";import{M as va}from"./member-scope-gate-vvkgSAb2.js";function ja({onClose:e,entityTypeSlug:t,orgContext:r,onSuccess:l}){const{data:n,isLoading:d}=Tt(t,r),i=`${r.organizationId??r.slug}:${t}`,a=Is(i,{name:"",customSlug:"",useCustomSlug:!1,metadata:{}},n?.metadata_schema),[u,o]=a.field("name"),[c,m]=a.field("customSlug"),[p,f]=a.field("useCustomSlug"),[y,N]=a.field("metadata"),[v,C]=As(i,null),b=Ps(),w=p?c:Fs(u),j=async L=>{if(L.preventDefault(),!a.canSubmit)return;if(C(null),!u.trim()){C("Name is required");return}const M=Yn(y),K={entityType:t,name:u.trim(),slug:p?c:void 0,metadata:Object.keys(M).length>0?M:void 0};try{const $=await b.mutateAsync(K);if(e(),$.approval_queued||!$.entity){It.info("Create queued for approval");return}typeof $.entity.id=="number"&&l?.($.entity.id)}catch($){C($ instanceof Error?$.message:"Failed to create entity")}},S=n?.name||t,g=a.revision,E=`Create ${S}`,k=`Add a new ${S.toLowerCase()} to your workspace.`;return d?s.jsx(Ds,{rows:6}):s.jsxs("form",{onSubmit:j,children:[s.jsx(Vs,{visible:a.hasConflict,onReload:a.reset}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:E}),s.jsx("p",{className:"text-sm text-muted-foreground",children:k})]}),s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsxs(Ve,{htmlFor:"name",children:["Name ",s.jsx("span",{className:"text-destructive",children:"*"})]}),s.jsx(se,{id:"name",value:u,onChange:L=>o(L.target.value),placeholder:`Enter ${S.toLowerCase()} name`,autoFocus:!0})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Ve,{htmlFor:"slug",children:"URL Slug"}),s.jsx("button",{type:"button",onClick:()=>f(!p),className:"text-xs text-muted-foreground hover:text-foreground",children:p?"Auto-generate":"Customize"})]}),p?s.jsx(se,{id:"slug",value:c,onChange:L=>m(L.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"custom-slug"}):s.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm text-muted-foreground",children:w||"slug-preview"})]}),g&&Object.keys(g).length>0?s.jsxs(s.Fragment,{children:[s.jsx(Qn,{className:"my-2"}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(Ve,{className:"text-sm font-medium",children:"Additional Fields"}),s.jsx(Wn,{schema:a.revision,values:y,onValuesChange:N,orgContext:r})]})]}):null,v&&s.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:v})]}),s.jsx(Bs,{onCancel:e,cancelDisabled:b.isPending,className:"mt-2",children:s.jsx(R,{type:"submit",disabled:!a.canSubmit||b.isPending||!u.trim(),children:b.isPending?"Creating...":`Create ${S}`})})]})}function Na(e){const t=e?.properties??{},r=zs(e);return Object.entries(t).flatMap(([l,n])=>{const d=r.find(m=>m.field===l);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(l)||!n||n.const!==void 0||n["x-table-column"]!==!0&&n["x-facet"]!==!0&&!d)return[];const i=[n,...Array.isArray(n.anyOf)?n.anyOf:[]],a=d?.options??Gs(n),u=a.find(m=>m.value!==null)?.value,o=i.find(m=>["string","number","integer","boolean"].includes(String(m.type)))??(u===void 0?void 0:{type:typeof u});if(!o)return[];const c=n.format==="date-time"||o.format==="date-time"?"datetime-local":n.format==="date"||o.format==="date"?"date":o.type==="number"||o.type==="integer"?"number":o.type==="boolean"?"boolean":"string";return[{field:l,label:String(n["x-table-label"]??n.title??l.replaceAll("_"," ")),type:c,options:c==="boolean"&&!a.some(m=>typeof m.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...a]:a}]})}const kt={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function Sa(e,t){return e.value===null&&e.op==="neq"?{op:kt.eq,value:"set"}:{op:kt[e.op],value:t?.options.find(r=>r.value===e.value)?.label??String(e.value)}}function wa(e){const t=e?.[Ue];return t===void 0?{}:Qe(t)}function Ca(e,t){return(e.presets??[]).filter(r=>!r.viewer||!!t?.email)}function Ea(e,t,r,l){try{const n=wa(t),d=Ca(n,l),i=e[At],a=i===void 0?void 0:d.find(p=>p.key===i);if(i!==void 0&&!a)throw new Error("This saved filter is unavailable. Choose another filter.");if(a&&!r&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const u=a&&e[te]===void 0?{collection:je(a,void 0,l)}:qs(e,r);if(u.error)throw u.error;const o=e[Hs],c=o===void 0?a?.table??n.table??{}:Qe({table:typeof o=="string"?JSON.parse(o):o}).table??{},m=!!a&&(_t(u.collection)!==_t(je(a,void 0,l))||Se(c)!==Se(a.table??n.table??{}));return{...u,presentation:n,presets:d,preset:a,table:c,edited:m}}catch(n){return{collection:{},presentation:{},presets:[],table:{},edited:!1,error:n instanceof Error?n:new Error("Invalid collection configuration")}}}function _t(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(Q)])}function Q(e){return JSON.stringify([e.field,e.op,e.value])}function Se(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function ka(e,t){return t?{[At]:t,[te]:He(e)[te]??"{}"}:He(e)}function _a(e,t,r,l,n=new Date,d){let i=t.filters??[],a=e.viewer;if(a){const o=d?.email?Q({field:a.field,op:"eq",value:d.email.toLowerCase()}):void 0;o&&i.some(c=>Q(c)===o)?i=i.filter(c=>Q(c)!==o):a=void 0}let u=e.relativeDate;if(u){const o=(je({...e,viewer:void 0,selection:{}},n).filters??[]).map(Q),c=i.map(Q);o.every(m=>c.includes(m))?i=i.filter(m=>!o.includes(Q(m))):u=void 0}return{key:e.key,label:e.label,selection:{...t.search?{search:t.search}:{},...i.length?{filters:i}:{},...t.segment?{segment:t.segment}:{}},...Se(r)!==Se(l.table??{})?{table:r}:{},...u?{relativeDate:u}:{},...a?{viewer:a}:{}}}function $a(e,t,r){const l=[...e.filters??[]],n=r??(t.length===1&&t[0].op==="eq"?l.findIndex(i=>i.field===t[0].field&&i.op==="eq"):-1),d=n>=0?[...l.slice(0,n),...t,...l.slice(n+1)]:[...l,...t];return{...e,filters:Js({filters:d}).filters}}function Ra(e,t){return{...e,filters:e.filters?.filter((r,l)=>l!==t)}}function La(e,t){return{...typeof e.$preset=="string"?e[te]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[te]:String(Us(e[te]))}:He(t),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const Oa=[{field:"name",label:"Name"},{field:"created_at",label:"Created"},{field:"total_content",label:"Activity count"},{field:"active_connections",label:"Connections"},{field:"automations_count",label:"Automations"},{field:"children_count",label:"Children"}];function Ma(e){return e.sort&&Oa.some(t=>t.field===e.sort?.field)?e.sort:{field:"created_at",order:"desc"}}function Ta(e,t,r,l,n){const d={...l,filters:l.filters?.filter(i=>i.field!==r)};return Pt({queryKey:["collection-facets",e,t,r,d],enabled:!!t&&!!r,staleTime:3e4,retry:!1,queryFn:async({signal:i})=>{const a=await Ne("query_sdk",{title:`Value counts query for ${r}`,script:`const input = ${JSON.stringify({field:r,collection:d})};
2
- ${t}`},e,{signal:i}),u=a.return_value;if(!a.success||typeof u?.connection!="string"||typeof u.sql!="string")throw new Error(a.error?.message??"Value distribution is unavailable");if(i.aborted)throw new DOMException("Aborted","AbortError");const o=await Ne("query_sql",{title:`Value counts for ${r}`,connection:u.connection,sql:u.sql,limit:51},e,{signal:i});if(o.error)throw new Error(o.error);if(!Array.isArray(o.rows))throw new Error("Source did not return value counts");const c=o.rows.map(m=>{const p=m,f=typeof p.count=="string"&&/^\d+$/.test(p.count)?Number(p.count):p.count;if(!(p.value===null||["string","number","boolean"].includes(typeof p.value))||typeof f!="number"||!Number.isSafeInteger(f)||f<0)throw new Error("Source returned an invalid value distribution");return{value:p.value,count:f}});return{values:c.slice(0,50),truncated:c.length>50||o.truncated===!0}}})}const Ia=300;function Aa({label:e,search:t,onSearch:r,className:l}){const n=t??"",[d,i]=x.useState(n),a=x.useRef({search:t,onSearch:r});a.current={search:t,onSearch:r};const u=x.useRef(void 0);x.useEffect(()=>{const c=()=>{clearTimeout(u.current),i(a.current.search??"")};return window.addEventListener("popstate",c),()=>window.removeEventListener("popstate",c)},[]);const o=x.useRef(n);return x.useEffect(()=>{n!==o.current&&(o.current=n,i(n))},[n]),x.useEffect(()=>{if(d===(a.current.search??""))return;const c=setTimeout(()=>{const m=a.current.onSearch;o.current=d,m(d||void 0,!0)},Ia);return u.current=c,()=>clearTimeout(c)},[d]),s.jsxs("div",{className:`relative${l?` ${l}`:""}`,children:[s.jsx(Ws,{"aria-hidden":"true",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(se,{type:"search","aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}...`,maxLength:512,value:d,onChange:c=>i(c.target.value),className:"pl-9"})]})}function Pa({field:e,initial:t,org:r,facetQuery:l,collection:n,onApply:d,close:i}){const[a,u]=x.useState(t?.op??"eq"),[o,c]=x.useState(t?.value==null?"":String(t.value)),[m,p]=x.useState(""),[f,y]=x.useState(!1),[N,v]=x.useState(),C=e.type==="date"||e.type==="datetime-local"||e.type==="number"?e.type:"text",b=Ta(r,l,e.field,n),w=g=>{try{const E=f?[{field:e.field,op:"gte",value:e.type==="number"?Number(o):o},{field:e.field,op:"lte",value:e.type==="number"?Number(m):m}]:[{field:e.field,op:a,value:g}];if(e.type==="datetime-local")for(const M of E)typeof M.value=="string"&&(M.value=new Date(M.value).toISOString());if(E.some(M=>typeof M.value=="number"&&!Number.isFinite(M.value)))throw new Error("Enter a valid number.");const k=E[0].value,L=E[1]?.value;if(f&&k!=null&&L!=null&&k>L)throw new Error("The lower bound must be before the upper bound.");d(E),i()}catch(E){v(E instanceof Error?E.message:"Could not apply filter")}},j=[...e.options];for(const g of b.data?.values??[])j.some(E=>E.value===g.value)||j.push({value:g.value,label:g.value===null?"Not supplied":String(g.value)});const S=Math.max(1,...b.data?.values.map(g=>g.count)??[]);return s.jsxs("div",{className:"min-w-0 space-y-3 p-3",children:[s.jsxs("select",{"aria-label":"Filter operator",className:"h-8 w-full rounded-md border bg-background px-2 text-sm",value:f?"range":a,onChange:g=>{y(g.target.value==="range"),g.target.value!=="range"&&u(g.target.value)},children:[s.jsx("option",{value:"eq",children:"is"}),s.jsx("option",{value:"neq",children:"is not"}),(e.type==="number"||e.type==="date"||e.type==="datetime-local")&&s.jsxs(s.Fragment,{children:[s.jsx("option",{value:"lt",children:"less than / before"}),s.jsx("option",{value:"lte",children:"at most / on or before"}),s.jsx("option",{value:"gt",children:"greater than / after"}),s.jsx("option",{value:"gte",children:"at least / on or after"}),t?null:s.jsx("option",{value:"range",children:"between"})]})]}),e.type!=="boolean"&&s.jsxs("form",{className:"space-y-2",onSubmit:g=>{g.preventDefault(),w(e.type==="number"?Number(o):o)},children:[s.jsx(se,{required:!0,"aria-label":f?"From value":"Filter value",type:C,step:e.type==="number"?"any":void 0,value:o,onChange:g=>c(g.target.value),placeholder:"Enter a value…"}),f&&s.jsx(se,{required:!0,"aria-label":"To value",type:C,step:e.type==="number"?"any":void 0,value:m,onChange:g=>p(g.target.value)}),s.jsx(R,{size:"sm",type:"submit",className:"w-full",children:"Apply filter"})]}),!f&&(a==="eq"||a==="neq")&&s.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto",children:j.filter(g=>!o||g.label.toLowerCase().includes(o.toLowerCase())).map(g=>{const E=b.data?.values.find(k=>k.value===g.value)?.count;return s.jsxs("button",{type:"button","aria-label":g.label,onClick:()=>w(g.value),className:"relative flex w-full items-center justify-between gap-3 overflow-hidden rounded px-2 py-1.5 text-left text-sm hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[E!==void 0&&s.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-primary/10",style:{width:`${E/S*100}%`}}),s.jsx("span",{className:"relative truncate",children:g.label}),s.jsx("span",{className:"relative text-xs tabular-nums text-muted-foreground",children:E?.toLocaleString()})]},JSON.stringify(g.value))})}),l&&b.isFetching&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Loading distribution…"}),b.isError&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Counts unavailable. You can still enter a value."}),b.data?.truncated&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"Top 50 values. Enter any other value above."}),N&&s.jsx("p",{role:"alert",className:"text-xs text-destructive",children:N})]})}function rs({collection:e,schema:t,label:r,onChange:l,org:n,facetQuery:d,segmentChip:i,viewFilters:a,onClearAll:u}){const o=Na(t),c=(y,N)=>({kind:"custom",className:"w-80",render:v=>s.jsx(Pa,{field:y,initial:N==null?void 0:e.filters?.[N],org:n,facetQuery:d,collection:e,onApply:C=>l($a(e,C,N)),close:v})}),m=o.map(y=>({key:y.field,label:y.label,icon:s.jsx(Ys,{className:"h-4 w-4"}),editor:c(y)})),p=new Map,f=(e.filters??[]).map((y,N)=>{const v=`${y.field}:${y.op}:${JSON.stringify(y.value)}`,C=p.get(v)??0;p.set(v,C+1);const b=o.find(w=>w.field===y.field);return{id:`${v}:${C}`,label:b?.label??y.field,...Sa(y,b),editor:b?c(b,N):void 0,onRemove:()=>l(Ra(e,N))}});if(i&&f.unshift(i),a?.fields.length){for(const y of m)y.group=r;m.push(...a.fields),f.push(...a.chips)}return!m.length&&!f.length?{fields:m,chips:f,clearAll:()=>{}}:{fields:m,chips:f,clearAll:u??(()=>l({...e,filters:[],segment:void 0}))}}function Fa(e){const{fields:t}=rs(e);return t.length?s.jsx(ta,{fields:t}):null}function Da(e){const{chips:t,clearAll:r}=rs(e);return t.length?s.jsx(sa,{label:`${e.label} filters`,fields:[],chips:t,onClearAll:r,className:"mb-4"}):null}const we=120,H=12;function $t(e,t){return typeof e.linkId=="number"&&typeof t.linkId=="number"?e.linkId-t.linkId:String(e.linkId).localeCompare(String(t.linkId))}function Va(e){const t=e.records.slice(0,we),r=o=>e.types.get(o)??{label:o},l=new Map;for(const o of t)l.set(String(o.id),{source:o.source,entityType:e.typeSlug,slug:o.slug,name:o.name,isFocus:!0,hasMoreLinks:!1});const n=new Map;for(const o of e.links){if(!l.has(String(o.recordId)))continue;const c=n.get(o.recordId)??new Map;c.set(o.linkId,o),n.set(o.recordId,c)}const d=new Map;for(const[o,c]of n){const m=[...c.values()].sort($t),p=l.get(String(o));p&&m.length>H&&(p.hasMoreLinks=!0);for(const f of m.slice(0,H)){d.set(f.linkId,f);const y=String(f.peer.id);l.has(y)||l.set(y,{source:f.peer.source,...f.peer.remote?{remote:f.peer.remote}:{},entityType:f.peer.type,slug:f.peer.slug,name:f.peer.name,isFocus:!1,hasMoreLinks:!1})}}const i=[];for(const[o,c]of l){const m=c.remote?{label:c.entityType}:r(c.entityType),p=c.name||c.slug,f=c.hasMoreLinks?`${m.label} · ${H}+ links`:m.label;i.push({id:o,data:{slug:c.slug,label:p,icon:m.icon,isSystem:!1,metaLabel:f},width:ra(p,f),height:aa})}const a=new Map;for(const o of[...d.values()].sort($t)){const c=String(o.fromId),m=String(o.toId),p=JSON.stringify([c,m]),f=a.get(p)??{source:c,target:m,rels:new Map,symmetric:!0};f.symmetric&&=o.isSymmetric,f.rels.has(o.relSlug)||f.rels.set(o.relSlug,{slug:o.relSlug,label:o.relName,ruleCount:1}),a.set(p,f)}const u=[...a.entries()].map(([o,c])=>({id:`link:${o}`,source:c.source,target:c.target,data:{relationships:[...c.rels.values()],isSymmetric:c.symmetric}}));return{nodes:i,edges:u,records:l,hasMoreRecords:e.hasMore===!0||e.records.length>we,listedCount:t.length,focusCount:t.length}}async function Ba(e,t){const r=Va(e);return{...await na({nodes:r.nodes,edges:r.edges},t),records:r.records,hasMoreRecords:r.hasMoreRecords,listedCount:r.listedCount,focusCount:r.focusCount}}const qa=8,Ha=3,Ua=4;function ve(e){return`source:${JSON.stringify([e.type,e.key])}`}function za(e,t){return t.map(r=>{const l={type:e,key:r.slug};return{...r,id:ve(l),source:l}})}function Rt(e){return JSON.stringify([e.relationship_type,e.direction,e.entity_type,e.key])}async function Ga(e,t,r){const l=e.slice(0,qa),n=[];let d=0;return await Promise.all(Array.from({length:Math.min(Ha,l.length)},async()=>{for(;d<l.length;){const i=d++,a=l[i];try{if(r?.aborted)throw r.reason;const u=await t(a),o=new Map(a.links.map(v=>[Rt(v),v]));for(const v of u.record_links){const C=Rt(v),b=o.get(C);(!b||b.occurred_at<v.occurred_at)&&o.set(C,v)}const c=new Map((a.relationships??[]).map(v=>[v.id,v]));for(const v of u.relationships??[])c.set(v.id,v);const m=[...c.values()].slice(0,H+1),p=[...o.values()].slice(0,H+1),f=(a.pagesRead??0)+1,y=!!u.next_cursor&&f>=Ua,N=u.record_failures.some(v=>v.code!=="withheld")||!!u.relationship_failures?.length||y;n[i]={read:{record:a.record,links:p,failed:N,entityId:a.entityId,relationships:m},...!y&&(N||u.next_cursor&&p.length+m.length<=H)?{next:{record:a.record,entityId:a.entityId,relationships:m,pagesRead:f,cursor:u.next_cursor??a.cursor,links:p}}:{}}}catch(u){if(r?.aborted)throw u;n[i]={read:{record:a.record,links:a.links,failed:!0,entityId:a.entityId,relationships:a.relationships},next:{...a,cursor:u instanceof Qs&&u.status===400?null:a.cursor}}}}})),{reads:n.map(i=>i.read),pending:[...n.flatMap(i=>i.next?[i.next]:[]),...e.slice(l.length)]}}function Ja(e,t){const r=new Map;for(const d of e)for(const i of d.reads)r.set(String(i.entityId??ve(i.record)),i);const l=new Map(t.map(d=>[d.slug,d])),n=[];for(const[d,i]of r){for(const a of i.relationships??[]){const u=(v,C,b)=>b?`remote:${b}`:typeof v=="number"?v:ve({type:C,key:v}),o=u(a.from_entity_id,a.from_entity_type,a.from_entity_url),c=u(a.to_entity_id,a.to_entity_type,a.to_entity_url),m=String(o)===d,p=m?c:o,f=m?a.to_entity_id:a.from_entity_id,y=m?a.to_entity_url:a.from_entity_url,N=(m?a.to_entity_type:a.from_entity_type)??"";n.push({recordId:d,linkId:a.id,fromId:o,toId:c,relSlug:a.relationship_type_slug,relName:a.relationship_type_name,isSymmetric:a.is_symmetric,peer:{id:p,name:(m?a.to_entity_name:a.from_entity_name)??String(f),slug:(m?a.to_entity_slug:a.from_entity_slug)??String(f),type:N,...y?{remote:{url:Zs(y)}}:typeof f=="string"?{source:{type:N,key:f}}:{}}})}for(const a of i.links){const u={type:a.entity_type,key:a.key},o=ve(u),c=l.get(a.relationship_type);let m=a.direction==="incoming"?o:d,p=a.direction==="incoming"?d:o;c?.is_symmetric&&m>p&&([m,p]=[p,m]),n.push({recordId:d,linkId:JSON.stringify([m,p,a.relationship_type]),fromId:m,toId:p,relSlug:a.relationship_type,relName:c?.name||a.relationship_type.replaceAll("_"," "),isSymmetric:c?.is_symmetric??!1,peer:{id:o,name:a.name||a.key,slug:a.key,type:a.entity_type,source:u}})}}return{links:n,checked:r.size,failed:[...r.values()].filter(d=>d.failed).length}}function Wa(e,t,r,l,n,d=!1){const{orgContext:i}=Ee(),a=Ft(i),u=Ks(i),o=x.useMemo(()=>d?za(t,r):r,[d,t,r]),c=x.useMemo(()=>o.slice(0,we).flatMap(j=>j.source?[{record:j.source,cursor:null,links:[]}]:typeof j.id=="number"?[{entityId:j.id,record:{type:t,key:j.slug},cursor:null,links:[]}]:[]),[o,t]),m=Xs({queryKey:["source-records-graph",i.organizationId,e,t,c.map(j=>[j.record,j.entityId])],enabled:!0,initialPageParam:c,queryFn:({pageParam:j,signal:S})=>Ga(j,async g=>{const E=await Ne("manage_entity",{action:"list_links",...g.entityId===void 0?{record:g.record,cursor:g.cursor}:{entity_id:g.entityId,offset:Number(g.cursor??0)},limit:H+1},e,{signal:S});return{...E,record_links:E.record_links??[],record_failures:E.record_failures??[],next_cursor:g.entityId===void 0?E.next_cursor:E.metadata?.has_more?String(Number(g.cursor??0)+H+1):null}},S),getNextPageParam:j=>j.pending.length?j.pending:void 0,staleTime:3e4,retry:!1}),p=x.useMemo(()=>m.data?Ja(m.data.pages,u.data??[]):void 0,[m.data,u.data]),f=p?.links,y=m.isError,N=JSON.stringify([i.organizationId,e,t,d,o.map(j=>[j.id,j.name,j.slug]),l]),v=x.useMemo(()=>new Map((a.data??[]).map(j=>[j.slug,{label:j.name||j.slug,icon:j.icon}])),[a.data]),[C,b]=x.useState(null);x.useEffect(()=>{if(!f)return;let j=!1;return Ba({typeSlug:t,records:o,hasMore:l,links:f,types:v},{targetAspect:n}).then(S=>{j||b({graph:S,key:N,isError:!1})}).catch(()=>{j||b({graph:null,key:N,isError:!0})}),()=>{j=!0}},[f,t,o,l,v,n,N]);const w=C?.key===N?C:null;return{graph:w?.graph??null,isLoading:!y&&!w,isError:y||w?.isError===!0,sourceProgress:{checked:p?.checked??0,total:Math.min(r.length,we),failed:p?.failed??0,hasMore:!!m.hasNextPage,isFetching:m.isFetching,loadMore:()=>{m.isFetching||m.fetchNextPage()}}}}function Ya(e){const t=new Map(e.nodes.map(n=>[n.id,n.data.label])),r=e.nodes.map(n=>({id:n.id,x:n.position.x+n.width/2,y:n.position.y+n.height/2,w:n.width,h:n.height,title:n.data.label,meta:n.data.metaLabel,icon:n.data.icon,muted:e.records.get(n.id)?.isFocus===!1})),l=e.edges.map(n=>{const{relationships:d,isSymmetric:i}=n.data,a=d.map(u=>u.label);return{id:n.id,source:n.source,target:n.target,route:n.route??null,summary:a.length===1?a[0]:`${a.length} relationships`,details:a,directed:!i,ariaLabel:`${t.get(n.source)??n.source} ${i?"and":"to"} ${t.get(n.target)??n.target}: ${a.join(", ")}`}});return{boxes:r,edges:l}}function Qa({ownerSlug:e,typeSlug:t,records:r,hasMore:l,sourceBacked:n=!1}){const d=ne(),i=Dt(),{orgContext:a}=Ee(),{data:u=[]}=Ft(a),o=u.find(S=>S.slug===t)?.name??t,[c,m]=x.useState(),p=x.useRef(null),f=x.useCallback(S=>{if(p.current?.disconnect(),p.current=null,!S||typeof ResizeObserver>"u")return;const g=()=>{if(!S.clientWidth||!S.clientHeight)return;const k=Math.round(S.clientHeight/S.clientWidth*10)/10;m(L=>L===k?L:k)};g();const E=new ResizeObserver(g);E.observe(S),p.current=E},[]),{graph:y,isLoading:N,isError:v,sourceProgress:C}=Wa(e,t,r,l,c,n),b=x.useMemo(()=>y?Ya(y):null,[y]),w=x.useCallback(S=>{const g=y?.records.get(S);if(g){if(g.remote){g.remote.url&&window.open(g.remote.url,"_blank","noopener,noreferrer");return}if(i){i.open(ia({...g.source?{record:g.source}:{entityId:Number(S)},ownerSlug:e,orgContext:a,name:g.name||g.slug}));return}d({to:en(e,[{entity_type:g.entityType,slug:g.slug}])})}},[y,e,a,i,d]);if(v)return s.jsx(tn,{label:`${o} graph`});if(N||!y||!b)return s.jsx(Xt,{label:`Loading ${o} graph`});const j=C?s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"text-sm text-muted-foreground",role:"status",children:[s.jsxs("p",{children:["Checked ",C.checked," of ",C.total," records. Up to ",H," relationships per record."]}),C.failed>0?s.jsx("p",{role:"alert",children:"Some sources could not be read. These relationships are incomplete."}):null]}),C.hasMore?s.jsx(R,{variant:"outline",size:"sm",disabled:C.isFetching,onClick:C.loadMore,children:C.isFetching?"Loading…":C.failed>0?"Retry sources":"Load more relationships"}):null]}):null;return y.focusCount===0?s.jsxs("div",{className:"space-y-3",children:[j,s.jsx(Vt,{icon:Bt,title:`No ${o} records match`,description:"Change the search or filters to see records here."})]}):s.jsxs("div",{className:"flex flex-col gap-2",children:[j,s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",y.hasMoreRecords?"the first ":"",y.focusCount," ",o," record",y.focusCount===1?"":"s",". Click a record to see it."]}),s.jsx("div",{ref:f,className:"h-[70vh] min-h-[420px] min-w-0 overflow-hidden",children:s.jsx(oa,{boxes:b.boxes,edges:b.edges,label:`${o} records`,onOpenBox:w,openLabel:S=>`Show ${S.title}`})})]})}function Za(e){return String(e??"").replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function os(e){return e["x-lobu"]?.role||e["x-lobu-role"]}function Ze(e){const t=e?.properties;if(!t)return null;const n=sn(t).find(([,o])=>os(o)==="workflowState");if(!n)return null;const[d,i]=n,a=i["x-lobu"]?.states,u=Array.isArray(a)&&a.length>0?a:(i.enum??[]).map(o=>({value:o}));return u.length===0||u.some(o=>typeof o.value!="string")?null:{field:d,states:u.map(o=>({...o,label:o.label||nn(i,o.value)||Za(o.value),terminal:o.terminal??["done","complete","completed","closed","archived"].includes(o.value.toLowerCase())}))}}function Ka(e){const t=e?.properties;if(!t)return null;const r=Object.entries(t),l=r.find(([,i])=>os(i)==="sortRank"),n=r.find(([i])=>["rank","sort_rank","order"].includes(i)),d=l??n;return d?{field:d[0]}:null}function Xa(e,{isDerived:t}){const r=e?.["x-lobu"]?.defaultView;return(r==="table"||r==="board")&&!(t&&r!=="table")?r:t?"table":Ze(e)?"board":"table"}const is={version:1,root:{type:"entity-table",props:{state:"{{tableState}}"}}},er={version:1,root:{type:"entity-board",props:{state:"{{boardState}}",onUpdate:"@updateEntity"}}};function tr(e){const{canShowBoard:t,builtinData:r,builtInLabels:l}=e,n=["table",...t?["board"]:[]],d={table:is,board:er};return n.map(i=>({id:i,label:l[i],builtInMode:i,template:d[i],data:r}))}function We(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Ce(e,t){if(!t)return e.created_at??String(e.id);const r=_e(e.metadata);return String(r[t.field]??e.created_at??e.id)}function sr(e,t){const r=e?Number(e):Number.NaN,l=t?Number(t):Number.NaN;return Number.isFinite(r)&&Number.isFinite(l)&&r<l?String((r+l)/2):Number.isFinite(r)?String(r+1):Number.isFinite(l)?String(l-1):String(Date.now())}function Ye(e,t){const r=_e(e.metadata);return String(r[t]??"")}function ls(e,t){return[...e].sort((r,l)=>Ce(r,t).localeCompare(Ce(l,t)))}function nr(e,t,r,l,n){if(!t.startsWith("card:")||!r)return null;const d=Number(t.slice(5)),i=e.find(b=>b.id===d);if(!i)return null;const a=r.startsWith("column:")?r.slice(7):Ye(e.find(b=>`card:${b.id}`===r)??i,l.field);if(!a)return null;const u=ls(e.filter(b=>b.id!==d&&Ye(b,l.field)===a),n),o=r.startsWith("card:")?u.findIndex(b=>`card:${b.id}`===r):u.length,c=o>=0?o:u.length,m=c>0?u[c-1]:void 0,p=u[c],f=n?sr(m?Ce(m,n):void 0,p?Ce(p,n):void 0):void 0,y=_e(i.metadata),N={[l.field]:a,...n&&f?{[n.field]:f}:{}};l.states.find(b=>b.value===a)?.terminal&&!y.completed_at&&(N.completed_at=new Date().toISOString());const C={...y,...N};return{entityId:d,changedMetadata:N,nextMetadata:C}}function Lt(e,t,r){return e.map(l=>l.id===t?{...l,metadata:r}:l)}function ar({id:e,children:t,className:r}){const{setNodeRef:l,isOver:n}=ts({id:`column:${e}`});return s.jsx("div",{ref:l,className:ie("min-h-[220px] rounded-lg bg-card p-2 transition-colors",n?"bg-accent/50":"",r),children:t})}function rr({entity:e,owner:t,statusField:r,entityTypeIcon:l,schema:n,didDragRef:d}){const i=_e(e.metadata),{attributes:a,listeners:u,setNodeRef:o,transform:c,isDragging:m}=ha({id:`card:${e.id}`}),{setNodeRef:p,isOver:f}=ts({id:`card:${e.id}`}),y=qt(t,es(e)),N=v=>{d.current&&(v.preventDefault(),v.stopPropagation())};return s.jsx("div",{ref:v=>{o(v),p(v)},style:{transform:ga.Translate.toString(c)},className:ie(on,"p-3 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",m?"opacity-60":"",f?"ring-1 ring-ring":""),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("button",{type:"button",className:"mt-0.5 shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing","aria-label":`Drag ${e.name}`,...a,...u,children:s.jsx(rn,{className:"h-4 w-4"})}),s.jsx(Kt,{metadata:i,metadataSchema:n,name:e.name,typeIcon:l,className:"mt-0.5 h-6 w-6 shrink-0",initialsFallback:!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx(ke,{to:y,className:"font-medium text-foreground hover:underline",onClick:N,children:e.name}),s.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[typeof i.priority=="string"&&i.priority?s.jsx(ze,{variant:"outline",className:"text-xs",children:We(i.priority)}):null,typeof i[r]=="string"&&i[r]?s.jsx(ze,{variant:"secondary",className:"text-xs",children:We(String(i[r]))}):null]})]})]})})}function or({owner:e,entities:t,totalCount:r,schema:l,entityTypeIcon:n,onUpdate:d}){const i=x.useMemo(()=>Ze(l),[l]),a=x.useMemo(()=>Ka(l),[l]),[u,o]=x.useState(t),[c,m]=x.useState(()=>new Set),p=x.useRef(!1),f=ua(ma(fa,{activationConstraint:{distance:6}})),y=x.useCallback(()=>{window.setTimeout(()=>{p.current=!1},0)},[]);x.useEffect(()=>{o(t)},[t]);const N=x.useMemo(()=>{if(!i)return new Map;const w=new Map(i.states.map(j=>[j.value,[]]));for(const j of u){const S=Ye(j,i.field),g=w.has(S)?S:i.states[0]?.value;g&&w.get(g)?.push(j)}for(const[j,S]of w)w.set(j,ls(S,a));return w},[u,a,i]);if(!i)return null;const v=w=>{m(j=>{const S=new Set(j);return S.has(w)?S.delete(w):S.add(w),S})},C=()=>{p.current=!0},b=w=>{const j=String(w.active.id),S=w.over?String(w.over.id):null,g=nr(u,j,S,i,a);if(!g){y();return}const{entityId:E,changedMetadata:k,nextMetadata:L}=g,K=u.find($=>$.id===E)?.metadata;o($=>Lt($,E,L)),d(E,k).catch(()=>{o($=>Lt($,E,K))}),y()};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-base font-semibold",children:"Board"}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Grouped by ",We(i.field),typeof r=="number"&&r>u.length?s.jsxs(s.Fragment,{children:[" · ",s.jsxs("span",{className:"text-amber-600 dark:text-amber-500",children:["showing first ",u.length," of ",r," — narrow with search"]})]}):null]})]}),s.jsx(pa,{sensors:f,onDragStart:C,onDragEnd:b,children:s.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:i.states.map(w=>{const j=N.get(w.value)??[],S=w.collapsed??w.terminal,g=S&&!c.has(w.value);return s.jsxs(ar,{id:w.value,children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[w.terminal?s.jsx(an,{className:"h-4 w-4 text-muted-foreground"}):null,s.jsx("h3",{className:"text-sm font-medium",children:w.label})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(ze,{variant:"secondary",className:"text-xs",children:j.length}),S?s.jsx(R,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",onClick:()=>v(w.value),children:g?"Show":"Hide"}):null]})]}),g?s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:[j.length," hidden ",w.label?.toLowerCase()," item",j.length===1?"":"s"]}):s.jsx("div",{className:"space-y-2",children:j.length>0?j.map(E=>s.jsx(rr,{entity:E,owner:e,statusField:i.field,entityTypeIcon:n,schema:l,didDragRef:p},E.id)):s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:["No ",w.label?.toLowerCase()," items"]})})]},w.value)})})})]})}const ir=x.memo(or);function lr(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t.toString(36)}function cs(e,t){return{queryKey:["metric_series",e,lr(t)],queryFn:()=>Ne("metric_series",{sql:t},{slug:e}),staleTime:6e4}}function ds(e,t){const r=!!e&&!!t,l=cs(e??"",t??"");return Pt({...l,enabled:r})}ds.queryOptions=(e,t)=>cs(e,t);function cr(e,t){if(!e?.columns?.length||!e.rows)return[];const r=e.columns.indexOf(t);return r<0?[]:e.rows.map(l=>Number(l[r])||0)}const Ot=/^[a-z][a-z0-9_]*$/;function dr(e){const t=Object.entries(e);for(const[n,d]of t){if(!Ot.test(n))throw new Error(`lifecycleCumulativeStatsSql: unsafe column name '${n}'`);if(!Ot.test(d))throw new Error(`lifecycleCumulativeStatsSql: unsafe entity_type '${d}'`)}const r=t.flatMap(([n,d])=>[`COUNT(*) FILTER (
3
- WHERE semantic_type = 'change'
4
- AND metadata->>'category' = 'lifecycle'
5
- AND metadata->>'entity_type' = '${d}'
6
- AND metadata->>'op' = 'created'
7
- ) AS ${n}_added`,`COUNT(*) FILTER (
8
- WHERE semantic_type = 'change'
9
- AND metadata->>'category' = 'lifecycle'
10
- AND metadata->>'entity_type' = '${d}'
11
- AND metadata->>'op' = 'deleted'
12
- ) AS ${n}_removed`]).join(`,
13
- `),l=t.map(([n])=>` SUM(COALESCE(b.${n}_added, 0) - COALESCE(b.${n}_removed, 0))
14
- OVER (ORDER BY d.bucket) AS ${n}`).join(`,
15
- `);return`
16
- WITH days AS (
17
- SELECT generate_series(
18
- date_trunc('day', now() - interval '13 days'),
19
- date_trunc('day', now()),
20
- interval '1 day'
21
- ) AS bucket
22
- ),
23
- buckets AS (
24
- SELECT
25
- date_trunc('day', created_at) AS bucket,
26
- ${r}
27
- FROM events
28
- WHERE created_at > now() - interval '14 days'
29
- GROUP BY 1
30
- )
31
- SELECT d.bucket,
32
- ${l}
33
- FROM days d
34
- LEFT JOIN buckets b ON b.bucket = d.bucket
35
- ORDER BY d.bucket
36
- `}const ur={"memory-activity":`
37
- WITH days AS (
38
- SELECT generate_series(
39
- date_trunc('day', now() - interval '13 days'),
40
- date_trunc('day', now()),
41
- interval '1 day'
42
- ) AS bucket
43
- ),
44
- buckets AS (
45
- SELECT
46
- date_trunc('day', created_at) AS bucket,
47
- COUNT(*) FILTER (
48
- WHERE semantic_type NOT IN ('change', 'audit', 'operation')
49
- ) AS events_count,
50
- COUNT(*) FILTER (
51
- WHERE semantic_type = 'change'
52
- AND metadata->>'category' = 'lifecycle'
53
- AND metadata->>'entity_type' = 'connection'
54
- AND metadata->>'op' = 'created'
55
- ) AS connections_added,
56
- COUNT(*) FILTER (
57
- WHERE semantic_type = 'change'
58
- AND metadata->>'category' = 'lifecycle'
59
- AND metadata->>'entity_type' = 'connection'
60
- AND metadata->>'op' = 'deleted'
61
- ) AS connections_removed
62
- FROM events
63
- WHERE created_at > now() - interval '14 days'
64
- GROUP BY 1
65
- )
66
- SELECT d.bucket,
67
- COALESCE(b.events_count, 0)::int AS events,
68
- SUM(COALESCE(b.connections_added, 0) - COALESCE(b.connections_removed, 0))
69
- OVER (ORDER BY d.bucket) AS connections
70
- FROM days d
71
- LEFT JOIN buckets b ON b.bucket = d.bucket
72
- ORDER BY d.bucket
73
- `};function mr(e){if(typeof e.sql=="string"&&e.sql.trim())return e.sql;if(e.lifecycle&&typeof e.lifecycle=="object"){const t=Object.fromEntries(Object.entries(e.lifecycle).map(([r,l])=>[r,String(l)]));if(Object.keys(t).length>0)try{return dr(t)}catch{return null}}return typeof e.preset=="string"?ur[e.preset]??null:null}function pr({owner:e,sql:t,lifecycle:r,preset:l,column:n,chart:d,height:i,width:a,color:u,label:o,className:c}){const m=x.useMemo(()=>mr({sql:t,lifecycle:r,preset:l}),[t,r,l]),p=typeof e=="string"&&e?e:null,{data:f}=ds(p,m),y=String(n??""),N=x.useMemo(()=>cr(f,y),[f,y]),v=x.useMemo(()=>!f?.columns?.length||!f.rows?[]:f.rows.map((b,w)=>({label:String(b[0]??"").slice(0,10),value:N[w]??0})),[f,N]);if(!p||!m||!y)return null;const C=d==="line"?s.jsx(la,{data:v,height:typeof i=="number"?i:void 0}):s.jsx(ca,{data:N,height:typeof i=="number"?i:void 0,width:typeof a=="number"?a:void 0,color:typeof u=="string"?u:void 0});return o==null?s.jsx("div",{className:c,children:C}):s.jsxs("div",{className:c,children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:String(o)}),C]})}function fr({metadata:e,metadataSchema:t,name:r,typeIcon:l,initialsFallback:n,className:d}){return s.jsx(Kt,{metadata:e,metadataSchema:t,name:String(r??""),typeIcon:l,initialsFallback:!!n,className:d})}function hr({entity:e,owner:t,className:r,onClick:l,children:n}){const d=e;if(!d)return s.jsx(s.Fragment,{children:n});const i=qt(String(t??""),es(d));return s.jsx(ke,{to:i,className:r,onClick:l,children:n})}function gr({state:e}){return e?s.jsx(Zn,{...e}):null}function yr({state:e,onUpdate:t}){return e?s.jsx(ir,{...e,onUpdate:t}):null}const xr={"entity-avatar":fr,"entity-link":hr,"entity-table":gr,"entity-board":yr,"metric-series":pr};function br({ownerSlug:e,typeSlug:t,title:r,shape:l}){const[n,d]=x.useState(!1),i=ne(),{visible:a,system:u,isTypesLoading:o}=ln(e),c=p=>{d(!1);const f=`/${e}/${Wt(p)}`;i({to:l?`${f}/${Yt}/${l}`:f})},m=p=>s.jsxs(hn,{value:`${p.name} ${p.slug}`,onSelect:()=>c(p.slug),children:[s.jsx(Jt,{icon:p.icon,className:"mr-2 h-4 w-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate",children:p.name||p.slug}),p.slug===t?s.jsx(gn,{className:"ml-2 h-3.5 w-3.5 shrink-0","aria-label":"Current"}):null,p.entity_count!=null?s.jsx("span",{className:"ml-2 shrink-0 text-xs tabular-nums text-muted-foreground",children:p.entity_count.toLocaleString()}):null]},p.slug);return s.jsxs(Ht,{open:n,onOpenChange:d,children:[s.jsx("h1",{className:"flex min-w-0 items-center text-lg font-semibold tracking-tight @sm:text-2xl",children:s.jsx(Ut,{asChild:!0,children:s.jsxs(R,{type:"button",variant:"ghost",title:r,className:"-ml-2 h-auto min-w-0 gap-1 px-2 py-1 text-lg font-semibold tracking-tight @sm:gap-1.5 @sm:text-2xl",children:[s.jsx("span",{className:"truncate",children:r}),s.jsx(zt,{className:"h-5 w-5 shrink-0 text-muted-foreground"})]})})}),s.jsx(Gt,{align:"start",className:"w-72 p-0",children:s.jsxs(cn,{children:[s.jsx(dn,{autoFocus:!0,placeholder:"Find a type…"}),s.jsxs(un,{children:[s.jsx(mn,{children:o?"Loading types…":"No type matches."}),a.length>0?s.jsx(Ct,{heading:"Types",children:a.map(m)}):null,u.length>0?s.jsx(Ct,{heading:"System",children:u.map(m)}):null]}),s.jsx(pn,{}),s.jsxs(ke,{to:"/$owner",params:{owner:e},search:{layout:"graph"},onClick:()=>d(!1),className:"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:text-foreground",children:[s.jsx(fn,{className:"h-4 w-4"}),"Data map"]})]})})]})}function vr(e){return Object.entries(e?.metrics_config?.segments??{}).filter(([,t])=>t.on==="entity").map(([t,r])=>({name:t,description:r.description}))}const be={table:{label:"Table",icon:En},board:{label:"Board",icon:Cn},graph:{label:"Graph",icon:Bt}},us=(e,t)=>`lobu.record-shape:v1:${e}/${t}`,jr=new Set(["table","board","graph"]);function Nr(e,t){const r=_n(us(e,t));return r&&jr.has(r)?r:void 0}function Sr(e,t,r){$n(us(e,t),r)}const Mt=":records";function wr({ownerSlug:e,entityTypeSlug:t,create:r,onCreateChange:l,viewKey:n,shape:d}){const{orgContext:i,hasOrgContext:a}=Ee(),u=Tt(t,i),{data:o,isLoading:c,error:m}=u;yn(`/${e}`,i);const p=xn(),[f,y]=x.useState({key:"",page:0}),N=Qt({strict:!1}),v=ne(),C=Dt(),b=`/${e}/${Wt(t)}`,{session:w,isReady:j}=bn(),S=j&&!c&&o?.slug===t,g=w?.user?.email,E=x.useMemo(()=>g?{email:g}:void 0,[g]),{collection:k,error:L,presentation:M,presets:K,preset:$,edited:le,table:I}=x.useMemo(()=>Ea(N,o?.metadata_schema,!!n,E),[N,o?.metadata_schema,n,E]),z=S?L:void 0,G=x.useMemo(()=>La(N,k),[N,k]),[ms,Ke]=x.useState(!1),[$e,ps]=x.useState(0),Re=k.search??"",X=k.segment,fs=JSON.stringify(k),ae=X?vr(o).find(h=>h.name===X)??{name:X,description:""}:null,hs=h=>void v({to:".",search:_=>({...Ge(_,Z(h)),...G}),replace:!0}),J=vn(u.data),Xe=J?I.sort:Ma(I),Le=Xe?.field,et=Xe?.order,W=x.useMemo(()=>Le?[{id:Le,desc:et==="desc"}]:[],[Le,et]),ce=x.useCallback(h=>void v({to:".",search:{...n?Z(N):{},...G,$table:JSON.stringify(h)},replace:!0}),[v,n,N,G]),tt=x.useCallback(h=>{const _=typeof h=="function"?h(W):h;_[0]&&ce({...I,sort:{field:_[0].id,order:_[0].desc?"desc":"asc"}})},[W,ce,I]),de=r===!0,st=()=>l(!0),gs=()=>l(!1),ys=W[0]?.id,xs=W[0]?W[0].desc?"desc":"asc":void 0,Oe=u.data?.metadata_schema,ue=!!Ze(Oe)&&!J,bs=Xa(Oe,{isDerived:J}),P=Zt(i),vs=Be(P.data??[],t,k),re=(h,_=!1,A=Z(N))=>{const T=!n||!P.data||Be(P.data,t,h).some(ye=>ye.key===n);v({to:T?".":b,search:{...T&&n?A:{},...ka(h,$?.key),$table:JSON.stringify(I)},replace:_})},me=h=>{const _=h?je(h,void 0,E):{},A=!n||Be(P.data??[],t,_).some(T=>T.key===n);Ke(!1),ps(T=>T+1),v({to:A?".":b,search:h?{$preset:h.key}:{}})},{isAdmin:js}=jn(i.organizationId),Me=Nn(i),Ns=js&&!!o&&!u.isPlaceholderData,nt=x.useRef(N);nt.current=N;const Ss=async()=>{if(!$)return;const h=JSON.stringify(N),{data:_}=await u.refetch(),A=_?.metadata_schema,T=A?Qe(A[Ue]??{}):void 0,ye=T?.presets?.find(xe=>xe.key===$.key);if(!_||!A||!T||!ye){It.error("This saved filter changed. Reload and try again.");return}const De=_a(ye,k,I,T,void 0,E);await Me.mutateAsync({slug:_.slug,metadata_schema:{...A,[Ue]:{...T,presets:T.presets?.map(xe=>xe.key===De.key?De:xe)}}}).then(()=>!0,()=>!1)&&(await u.refetch(),JSON.stringify(nt.current)===h&&me(De))},ws=x.useMemo(()=>Nr(e,t),[e,t]),D=Sn(P.data??[],t,{viewKey:n,shape:d??(n?void 0:ws)},bs,k),V=D.kind==="builtin"?D.mode==="board"&&!ue?"table":D.mode:null,at=V==="graph";x.useEffect(()=>{d&&S&&V&&Sr(e,t,V)},[d,S,V,e,t]);const rt=["table",...ue?["board"]:[],"graph"],Y=D.kind==="view"?D.view:null,ot=D.kind==="missing"?D.key:null,Te=D.kind==="inapplicable"?D:null,oe=V==="table"?50:200,pe=`${t}?${fs}&sort=${JSON.stringify(I.sort)}&size=${oe}`,fe=f.key===pe?f.page:0,Ie=x.useCallback(h=>y(_=>({key:pe,page:h(_.key===pe?_.page:0)})),[pe]),he=Et(t,i,{limit:oe,offset:fe*oe,search:Re.trim()||void 0,sortBy:ys,sortOrder:xs,segment:X,filters:k.filters,enabled:S&&!n&&!z}),it=Et(t,i,{limit:1,offset:0,parentId:null,search:Re.trim()||void 0,segment:X,filters:k.filters,enabled:S&&!n&&!z&&!J}),{data:ge,error:Cs}=he,Es=he.isLoading||he.isPending&&he.fetchStatus==="paused",lt=z||m||(n?null:Cs),ks=!!n&&P.data===void 0&&P.isError,B=ge?.entities??[],Ae=ge?.metadata?.has_more??!1,F=ge?.metadata?.total_count??0,ct=B.length>0||Re.trim().length>0||fe>0||!!X||!!k.filters?.length,O=o?.name?.trim()||qe(t),ee=o?.icon||void 0,q=J,U=Oe,_s=!z&&(!a||!S||(n?P.data===void 0&&!P.isError:Es||!J&&it.isLoading)),dt=ge?.linked_entities??{},ut=it.data?.metadata?.total_count,mt=F>0&&typeof ut=="number"?ut<F:!1,pt=x.useMemo(()=>o?.measure_columns??[],[o?.measure_columns]),ft=x.useCallback(h=>ce({...I,columns:h}),[ce,I]),ht=x.useMemo(()=>({entities:B,owner:e,schema:U,entityTypeIcon:ee,isDerived:q,measureColumns:pt,linkedEntityLookups:dt,hasAnyParents:mt,sorting:W,onSortingChange:tt,visibleColumns:I.columns,columnChoices:Kn(U,q,B),onVisibleColumnsChange:ft,page:fe,pageSize:oe,totalCount:F,hasMore:Ae,pageTitle:O,onPrevPage:()=>Ie(h=>Math.max(0,h-1)),onNextPage:()=>Ie(h=>h+1)}),[B,e,U,ee,q,pt,dt,mt,W,I.columns,ft,tt,Ie,fe,oe,F,Ae,O]),gt=F>B.length,yt=`showing first ${B.length} of ${F} — narrow with search`,xt=x.useMemo(()=>({owner:e,entityType:o,entities:B,totalCount:F,schema:U,entityTypeIcon:ee}),[e,o,B,F,U,ee]),Pe=x.useMemo(()=>({tableState:ht,boardState:xt,owner:e,schema:U,entityType:o,entityTypeIcon:ee,totalCount:F,isTruncated:gt,truncationNotice:yt,canCreate:!q,addLabel:`Add ${o?.name||qe(t)}`}),[ht,xt,e,U,o,ee,F,gt,yt,q,t]),$s=x.useMemo(()=>tr({canShowBoard:ue,builtinData:Pe,builtInLabels:{table:be.table.label,board:be.board.label}}),[ue,Pe]),bt=V?$s.find(h=>h.id===V)??null:null,Rs=bt?.template??is,Ls=bt?.data??Pe,vt=h=>void v({to:h===Mt?b:`${b}${Je(h)}`,search:G}),Fe=Z(N),Os=ya(Y?.params,Fe,h=>void v({to:".",search:{...Z(h),...G}})),Ms=()=>re({...k,filters:[],segment:void 0},!1,xa(Y?.params,Fe)),jt={collection:k,schema:U,label:O,org:i??"",facetQuery:M.facetQuery,onChange:re,viewFilters:Os,onClearAll:Ms,segmentChip:ae?{id:"segment",label:"Segment",op:"is",value:qe(ae.name),title:ae.description||void 0,editor:ae.description?{kind:"custom",render:()=>s.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:ae.description})}:void 0,onRemove:()=>re({...k,segment:void 0})}:void 0},Nt=`Moved on ${o?.name||o?.slug||t} board`,St=x.useMemo(()=>(h,_)=>p.mutateAsync({entityId:h,metadata:_,field_note:Nt}),[p,Nt]),Ts=x.useMemo(()=>({updateEntity:St,openCreate:()=>l(!0)}),[St,l]),wt=h=>C?s.jsx("span",{className:h,children:s.jsx(R,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground","aria-label":"Edit type",title:"Edit type",onClick:()=>C.open({href:Ln(e,t),title:O}),children:s.jsx(Rn,{className:"h-4 w-4"})})}):null;return s.jsx(Xn,{title:s.jsx(br,{ownerSlug:e,typeSlug:t,title:O,shape:n?null:V}),actions:wt("hidden @sm:contents"),controls:s.jsxs(s.Fragment,{children:[de?s.jsx("div",{className:"max-w-3xl",children:s.jsx(ja,{onClose:gs,entityTypeSlug:t,orgContext:i})}):null,!de&&S&&s.jsxs("nav",{className:"mb-4 flex flex-wrap items-center gap-x-3 gap-y-2","aria-label":`${O} views`,children:[wt("-mr-1 @sm:hidden"),!n&&rt.length>1&&s.jsx("fieldset",{className:"flex items-center rounded-md border p-0.5","aria-label":"Record layout",children:rt.map(h=>{const _=be[h].icon,A=V===h;return s.jsx(R,{type:"button",variant:"ghost",size:"sm","aria-pressed":A,title:be[h].label,"data-testid":`shape-${h}`,className:ie("h-7 px-2",A&&"bg-accent text-accent-foreground"),onClick:()=>void v({to:`${b}/${Yt}/${h}`,search:G,replace:!0}),children:s.jsx(_,{className:"h-4 w-4"})},h)})}),n&&s.jsx(R,{variant:"ghost",onClick:()=>vt(Mt),children:"Records"}),!!K.length&&s.jsxs(Ht,{open:ms,onOpenChange:Ke,children:[s.jsx(Ut,{asChild:!0,children:s.jsxs(R,{variant:"outline",className:ie("gap-2",le&&"border-dashed border-primary"),"data-edited":le||void 0,title:"Choose saved filter",children:[$?.label??(k.filters?.length||k.search?"Custom filter":"All records"),le?s.jsx("span",{className:"text-xs font-normal text-primary",children:"Edited"}):null,s.jsx(zt,{className:"h-4 w-4 text-muted-foreground"})]})}),s.jsxs(Gt,{align:"start",className:"w-60 p-1",children:[s.jsx(R,{variant:$?"ghost":"secondary",className:"w-full justify-start",onClick:()=>me(),children:"All records"}),K.map(h=>s.jsx(R,{variant:$?.key===h.key?"secondary":"ghost",className:"w-full justify-start",onClick:()=>me(h),children:h.label},h.key))]})]}),$&&le?s.jsxs("div",{className:"-ml-2 mr-2 inline-flex items-center gap-1",children:[s.jsx(R,{variant:"ghost",size:"sm",onClick:()=>me($),children:"Reset"}),Ns?s.jsx(R,{size:"sm",disabled:Me.isPending,onClick:()=>void Ss(),children:Me.isPending?"Saving…":"Save"}):null]}):null,vs.map(h=>s.jsx(R,{"data-testid":`tab-${h.key}`,variant:n===h.key?"secondary":"ghost","aria-pressed":n===h.key,onClick:()=>vt(h.key),children:h.name},h.key)),!z&&s.jsx(Fa,{...jt},`filters:${t}:${$e}`),s.jsxs("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-x-3 gap-y-2",children:[s.jsx(Aa,{label:O,search:k.search,onSearch:(h,_)=>re({...k,search:h},_),className:"w-64 max-w-full"},`search:${t}:${$e}`),!q&&!n?s.jsxs(R,{size:"sm","aria-label":`Add ${O||"entity"}`,onClick:()=>st(),children:[s.jsx(kn,{className:"mr-2 h-4 w-4"}),"Add"]}):null]})]}),!de&&S&&!z?s.jsx(Da,{...jt},`applied:${t}:${$e}`):null]}),children:de?null:_s?at?s.jsx(Xt,{label:`Loading ${O} graph`}):s.jsx(ea,{}):lt?s.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[lt.message||`Failed to load ${O.toLowerCase()}.`,z&&s.jsx(R,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>re({}),children:"Clear filters"})]}):ks?s.jsx(ss,{onRetry:()=>void P.refetch()}):Te?s.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"inapplicable-view",children:[s.jsxs("h2",{className:"text-lg font-semibold",children:["“",Te.view.name,"” doesn’t apply to the current filters"]}),s.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["It appears when the selection includes"," ",Object.entries(Te.when).map(([h,_])=>`${h} is ${_===null?"not supplied":String(_)}`).join(" and "),"."]}),s.jsx(ke,{to:b,search:G,className:"mt-4 text-sm font-medium underline underline-offset-4",children:`Back to ${O}`})]}):ot?s.jsx(ns,{viewKey:ot,backTo:b,backLabel:`Back to ${O}`}):Y?s.jsx(as,{orgSlug:e,viewKey:Y.key,scope:{type:t,collection:k},params:Fe,onParamsChange:hs,paramDecls:Y.params,contentHash:Y.content_hash,title:Y.name,minHeight:320}):at&&ct?s.jsx(Qa,{ownerSlug:e,typeSlug:t,sourceBacked:J,records:B.map(h=>({...h,id:h.id??JSON.stringify([h.entity_type,h.slug])})),hasMore:Ae}):ct?s.jsx(da,{template:Rs,data:Ls,actions:Ts,components:xr}):s.jsx(Vt,{icon:wn,iconElement:s.jsx(Jt,{icon:o?.icon,className:"mb-4 h-12 w-12 opacity-50"}),title:`No ${O.toLowerCase()} yet`,description:q?"This view has no rows yet. They appear as the underlying data arrives.":`Get started by creating your first ${o?.name?.toLowerCase()||"entity"}.`,actionLabel:q?void 0:`Add ${o?.name||"Entity"}`,onAction:q?void 0:()=>st()})})}function Cr(e,t){return ie("inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",t,e?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground")}const Er=12,kr=50;function _r({navigation:e,views:t,currentKey:r}){const l=ne(),[n,d]=x.useState(""),i=x.useMemo(()=>e.filter(c=>!c.external&&c.href.includes("/-/views/")),[e]),a=On(i,t,n,n.trim()?kr:Er),u=Mn(i,t,n),o=c=>{c.key==="Enter"&&a[0]&&(c.preventDefault(),l({href:a[0].href}))};return s.jsxs("nav",{"aria-label":"Workspace views",className:"flex shrink-0 flex-col gap-2",children:[s.jsx(se,{type:"search","aria-label":"Find a view",placeholder:"Find a view",value:n,onChange:c=>d(c.target.value),onKeyDown:o,className:"h-8 max-w-sm"}),a.length>0?s.jsx("ul",{className:"flex flex-wrap items-center gap-1",children:a.map(c=>{const m=c.key===r;return s.jsx("li",{children:s.jsxs(Tn,{item:{id:c.key,label:c.label,href:c.href,children:[]},active:m,className:Cr(m,"min-h-8 max-w-full gap-2 px-3 text-sm break-words"),children:[s.jsx("span",{children:c.label}),c.trail.length>0&&c.trail[0]!=="Views"?s.jsx("span",{className:"ml-1.5 text-xs text-muted-foreground",children:c.trail.join(" › ")}):null]})},c.key)})}):s.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["No view matches “",n.trim(),"”."]}),u>a.length?s.jsxs("p",{role:"status",className:"text-xs text-muted-foreground",children:["Showing ",a.length," of ",u,". Type to narrow the list."]}):null]})}function $r({ownerSlug:e,typeScope:t,create:r,viewKey:l,shape:n}){const d=ne(),i=Qt({strict:!1}),a=t?In(t):void 0,u=a==="$member",o=m=>{if(!a)return;const p=Un(e,a);d({to:p.to,params:p.params,search:m?{create:!0}:{},replace:!0})},c=a?s.jsx(wr,{ownerSlug:e,entityTypeSlug:a,create:r,onCreateChange:o,viewKey:l,shape:n}):l?s.jsx(Rr,{ownerSlug:e,viewKey:l,search:i}):null;return s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:u?s.jsx(va,{children:c}):c})}function Rr({ownerSlug:e,viewKey:t,search:r}){const l=ne(),{orgContext:n}=Ee(),{data:d,isError:i,error:a,refetch:u}=Zt(n),o=An(n),c=Pn(e,`/${e}/data`),m=Fn(d??[],t),p=Dn(),f=Vn(d??[]),y=i?Bn(a,{subject:"Views"}):null;if(d===void 0)return i?s.jsx(ss,{error:a,onRetry:()=>void u()}):null;if(m.kind==="missing")return s.jsx(ns,{viewKey:m.key,backTo:`/${e}`,backLabel:"Back to Home"});const N=qn(o.data??[]),v=f.some(b=>!N.has(`/${e}/data${Je(b.key)}`)),C=f.length>0&&(p||o.data!==void 0&&v);return s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:[C?s.jsx(_r,{navigation:c.navigation,views:c.views,currentKey:Hn(`/${e}/data${Je(t)}`,r)}):null,p&&y?s.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:[y.title,"."," ",y.retryable?s.jsx("button",{type:"button",onClick:()=>void u(),className:"underline underline-offset-4",children:"Retry"}):null]}):null,s.jsx(ba,{decls:m.view.params,params:Z(r),onParamsChange:b=>void l({to:".",search:w=>Ge(w,b)})}),s.jsx(as,{orgSlug:e,viewKey:m.view.key,scope:{},params:Z(r),onParamsChange:b=>void l({to:".",search:w=>Ge(w,b),replace:!0}),paramDecls:m.view.params,contentHash:m.view.content_hash,title:m.view.name,minHeight:400})]})}function qr({ownerSlug:e,typeScope:t,create:r,viewKey:l,shape:n}){return s.jsxs(zn,{inset:l?"flush":"page",className:l?"gap-0 pt-0 pb-0":"gap-6 pt-2.5 pb-8",children:[s.jsx(Jn,{}),s.jsx(Gn,{owner:e,children:d=>s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:s.jsx($r,{ownerSlug:d.ownerSlug,typeScope:t,create:r,viewKey:l,shape:n})})})]})}export{qr as M};
74
- //# sourceMappingURL=memory-browse-page-DvDtwrEI.js.map
@@ -1,2 +0,0 @@
1
- import{dn as s,M as n,c as r,j as t,at as p,au as i}from"./index-DByaMzsG.js";import{E as m}from"./entity-type-page-CkQm0yEu.js";import"./event-kind-options-fHAIXu24.js";import"./code-editor-mrKkAfcE.js";import"./index-Vcq4gwWv.js";function y(){const{owner:e}=s.useParams(),{orgContext:a}=n(),o=r();return t.jsx(p,{className:"gap-4 pt-2.5 pb-8",children:t.jsx(i,{children:t.jsx(m,{entityType:null,orgContext:a,onClose:()=>{o({to:"/$owner",params:{owner:e},search:{layout:"graph"}})}})})})}export{y as component};
2
- //# sourceMappingURL=new-C5HtQdM_.js.map
@@ -1,2 +0,0 @@
1
- import{j as e,ej as de,jR as z,jS as ue,jT as ee,jU as me,jV as pe,r as g,jW as xe,u as D,aU as he,cK as fe,m as $,iy as ge,jm as ye,B as k,jX as je,jY as K,jZ as ve,dX as Ne,j_ as we,G as L,al as R,aw as te,cq as se,M as ne,dq as ke,bQ as be,b$ as Ae,cY as Ce,cJ as Se,x as Ie,gf as $e,P as Le,L as H,j$ as Re,cO as Pe,gi as Te,d8 as _e,k0 as Ee,gp as G,fl as Oe,aS as ze,k1 as De,n as Me,w as Fe,gC as Be,eW as Ke,fj as He,fm as Ue,fs as E,p as Ve,k2 as We,k3 as qe,ev as Ge,k4 as Ye,f0 as Qe,ac as Xe,k5 as Ze,A as Je,k6 as et}from"./index-DByaMzsG.js";import{b as re,u as tt,a as st,A as nt}from"./automation-run-now-MtxUTfzd.js";import{A as rt}from"./agent-loading-shells-DYqQphN7.js";import{s as it,h as at,R as ot,A as ct}from"./agent-thread-BopD-2k1.js";import{C as lt,a as dt,c as ut,A as mt}from"./connection-feed-detail-0VAJiZTP.js";import{O as pt}from"./connect-menu-C6iVtuSo.js";import{E as P,R as xt,b as ht,s as Y,p as Q,e as ft,f as gt}from"./events-feed-DmRzikZW.js";import{S as yt}from"./source-record-panels-CGmKIJdN.js";import{E as X}from"./entity-type-page-CkQm0yEu.js";import{c as jt,s as vt,m as Nt}from"./renderer-olRv_HMI.js";import{E as wt}from"./event-detail-CkzfakTK.js";import{V as kt,R as bt}from"./views-access-required-C35Dyt91.js";import{V as At,a as Ct}from"./view-param-filters-CUCj9Df-.js";import{S as St,g as It}from"./status-variants-DyRCXBzM.js";import{a as $t}from"./runs-C8sZQr4o.js";import{a as ie}from"./use-automations-CgWNoYio.js";import"./needs-you-list-B5Bgd05M.js";import"./scoped-feed-bar-BKyJSa3_.js";import"./event-kind-options-fHAIXu24.js";import"./filter-editors-CQoSj-20.js";import"./subDays-D8nHthaS.js";import"./create-automation-form-CLicoPH5.js";import"./entity-options-B9hm9V87.js";import"./device-automation-Dp3faMvp.js";import"./model-selector-D3vSMLO2.js";import"./skill-editor-D_W3QlRz.js";import"./code-editor-mrKkAfcE.js";import"./index-Vcq4gwWv.js";import"./json-diff-mcDgyct_.js";import"./use-mention-search-D-kIKchD.js";import"./proposal-review-shell-B-jYcKfB.js";import"./definition-comparison-4UYMI6BK.js";import"./schema-value-zTJGE4eh.js";import"./runs-list-CwtH-wmk.js";import"./run-initiator-DhE5v4z0.js";import"./list-skeleton-DsYGUHxi.js";import"./clients-xnzZeEdZ.js";import"./app-bridge-C4nPtae3.js";import"./pending-seed-CBhx2Ql-.js";import"./feed-event-kinds-BYuZCoU4.js";import"./copy-button-C3wMMv63.js";import"./card-DtLIFq7D.js";import"./table-C637cQxG.js";import"./dynamic-schema-form-BDT8x0Vg.js";import"./record-session-CAmGHMyM.js";function Lt(t){if(!t||typeof t!="object")return[];const s=t.properties;if(!s)return[];const r=Array.isArray(t.required)?new Set(t.required.map(String)):new Set;return Object.entries(s).map(([n,i])=>({name:n,type:String(i.type??"any"),required:r.has(n),description:typeof i.description=="string"?i.description:void 0}))}function Rt({fields:t}){return t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No fields."}):e.jsx("ul",{className:"space-y-2",children:t.map(s=>e.jsxs("li",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("code",{className:"text-xs font-medium text-foreground",children:s.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:s.type}),s.required?e.jsx("span",{className:"text-[10px] font-medium text-amber-600 dark:text-amber-400",children:"required"}):null]}),s.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description}):null]},s.name))})}function M({item:t,hideHeading:s=!1}){const r=t.schemaSections;return r?e.jsxs("article",{className:s?"space-y-4":"space-y-4 px-5 py-5",children:[!s&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(de,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h2",{className:"text-base font-medium text-foreground",children:t.title}),r.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:r.description}):null]})]}),r.sections.map(n=>{const i=Lt(n.schema);return e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n.title}),n.description?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:n.description}):null]}),e.jsx(Rt,{fields:i})]},n.title)})]}):null}function Pt({actions:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,action:i}});return e.jsx(z,{entries:s,label:"actions",renderDetail:({name:r,action:n})=>e.jsx(M,{hideHeading:!0,item:{href:"",title:r,schemaSections:ee(n)}})})}function Tt({feeds:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,feed:i}});return e.jsx(z,{entries:s,label:"feed types",renderDetail:({name:r,feed:n})=>e.jsx(M,{hideHeading:!0,item:{href:"",title:r,schemaSections:ue(n)}})})}function _t(t){const s=[];return t.forEach((r,n)=>{s.push({id:`sep:${r.runId}`,role:"system",parts:[{type:"text",text:Et(r,n)}],createdAt:r.completedAt?new Date(r.completedAt).getTime():void 0});for(const i of r.messages)s.push({...i,id:`r${r.runId}:${i.id}`})}),s}function Et(t,s){const r=(t.pendingActionCount??0)>0?`Waiting for you (${t.pendingActionCount})`:t.status==="completed"?"Completed":t.status??"Completed",n=(t.autoAppliedCount??0)>0?` · ${t.autoAppliedCount} applied automatically`:"",i=t.completedAt?new Date(t.completedAt).toLocaleString():null;return i?`Run ${s+1} · ${r}${n} · ${i}`:`Run ${s+1} · ${r}${n}`}const ae=Symbol("trusted-automation-interaction");function Ot(t){return Object.defineProperty(t,ae,{value:!0}),t}function zt(t){return{title:`${t} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${t} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${t} proposals.`},{id:"reject-all",label:"Reject all",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${t} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${t} proposals.`}]}}const Dt=new Set(["automation-approval-batch"]);function Mt(t){return new Promise(s=>{t({onSettled:(r,n)=>s(!!n)})})}function Ft(){const t=me(),s=pe();return g.useMemo(()=>({toolNames:Dt,resolve:(r,n)=>{if(!n||typeof n!="object"||n[ae]!==!0)return null;const i=n;if(r==="automation-approval-batch"){const o=typeof i.runId=="number"&&Number.isSafeInteger(i.runId)&&i.runId>0?i.runId:null,c=typeof i.count=="number"&&Number.isSafeInteger(i.count)&&i.count>1?i.count:null,a=Array.isArray(i.runIds)?i.runIds.filter(d=>typeof d=="number"&&Number.isSafeInteger(d)&&d>0):[];return o===null||c===null||a.length!==c||new Set(a).size!==c?null:{view:zt(c),handlers:{manage_operations:d=>d.action!=="approve"&&d.action!=="reject"?Promise.resolve(!0):Mt(p=>d.action==="approve"?t.mutate({run_id:o,run_ids:a},p):s.mutate({run_id:o,run_ids:a},p))}}}return null}}),[t,s])}const Bt=/(?:^|\n)Run this Automation now/;function Kt(t){return t.role==="user"&&t.parts.some(s=>s.type==="text"&&Bt.test(s.text))}function Ht(t){return`history-interaction:${t.runId}:${t.eventId??"error"}`}function Ut({agentId:t,automationId:s,ownerSlug:r,runId:n}){const{data:i,isLoading:o}=xe(t,s,{orgSlug:r,...n!=null?{runId:n}:{}}),c=Ft(),a=D(),d=g.useCallback(m=>{a?.open({href:`/${r}/automations/${s}?view=activity&run_id=${m}`,title:`Automation run #${m}`,runId:m})},[a,r,s]),p=g.useMemo(()=>{const m=i?.runs??[],b=(n!=null?m.filter(x=>x.runId===n):m).slice().reverse();return _t(b.map(x=>{const y=x.messages.map(u=>it(u,{showToolCalls:!0})).filter(u=>u!==null&&!Kt(u));x.task?.trim()&&y.unshift({id:"task",role:"user",parts:[{type:"text",text:x.task.trim()}]});const N=x.actions??[],j=N.filter(u=>u.status==="pending");if(j.length>1){const u=j.map(h=>h.runId).sort((h,C)=>h-C);y.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${x.runId}`,toolName:"automation-approval-batch",args:Ot({runId:x.runId,count:j.length,runIds:u})}]})}for(const u of N){const h=at([u],{workspaceSlug:r,agentId:t,webOrigin:typeof window>"u"?null:window.location.origin});h&&y.push({...h,id:Ht(u)})}return{runId:x.runId,completedAt:x.completedAt,status:x.status,pendingActionCount:x.pendingActionCount,autoAppliedCount:x.autoAppliedCount,messages:y}}))},[t,i,r,n]);return o?e.jsx(rt,{readOnly:!0}):p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):e.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:e.jsx(ot,{messages:p,workspaceSlug:r,children:e.jsx(ct,{readOnly:!0,readerPositionMode:"runs",interactionExtension:c,onRunSelect:n==null&&a?d:void 0})})})}function Vt({panel:t}){const s=he(t.organizationId),r=t.section==="connections"||!!t.connectionId,n=fe(t.organizationId,{connectorKey:t.connectorKey,connectionIds:t.connectionId?[t.connectionId]:void 0,enabled:r}),i=s.data?.find(c=>c.key===t.connectorKey),o=n.data?.find(c=>c.id===t.connectionId&&c.connector_key===t.connectorKey);return s.isLoading||r&&n.isLoading?e.jsx("div",{className:"p-5",children:e.jsx($,{className:"h-28 w-full"})}):s.isError||r&&n.isError?e.jsx("p",{role:"alert",className:"p-5 text-sm",children:"Could not load this connector. Close the pane and try again."}):t.connectionId&&!o||!i&&!o&&t.section!=="connections"?e.jsx("p",{className:"p-5 text-sm",children:"This connection is no longer available."}):e.jsx("div",{className:"p-5",children:t.section==="connections"?e.jsx(ge,{connections:n.data??[],connector:i,connectorKey:t.connectorKey,ownerSlug:t.ownerSlug}):o&&t.section==="data"?e.jsx(lt,{connection:o,ownerSlug:t.ownerSlug}):o?e.jsx(Gt,{connection:o,connector:i,panel:t}):i?t.section==="oauth-apps"?e.jsx(pt,{connector:i,organizationId:t.organizationId,newApp:!!t.newApp}):t.section==="feeds"?e.jsx(Wt,{connector:i}):i.installed===!1?e.jsx(qt,{connector:i,ownerSlug:t.ownerSlug}):e.jsx(Qt,{connector:i,ownerSlug:t.ownerSlug}):null},`${t.connectorKey}:${t.connectionId??"connector"}:${t.section}`)}function Wt({connector:t}){return e.jsx(Tt,{feeds:t.feeds_schema??{}})}function qt({connector:t,ownerSlug:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection."," ",e.jsx(K,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(Pt,{actions:t.actions_schema??{}})]})}function Gt({connection:t,connector:s,panel:r}){const[n,i]=g.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:n,children:r.section==="feeds"?e.jsx(Yt,{connection:t,connector:s,ownerSlug:r.ownerSlug}):e.jsx(ye,{connection:t,ownerSlug:r.ownerSlug,inPeek:!0,onReviewPermissions:s?()=>i(!0):void 0})}),n&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>i(!1),children:"Back to actions"}),e.jsx("h2",{className:"text-base font-semibold",children:"Provider permissions"}),e.jsx(je,{connection:t,connectorDef:s})]})]})}function Yt({connection:t,connector:s,ownerSlug:r}){const{data:n=[],isLoading:i,isError:o}=Ne(t.id),[c,a]=g.useState(!1),d=t.facets?.chat??!1;if(i)return e.jsx($,{className:"h-28 w-full"});if(o)return e.jsx("p",{role:"alert",children:"Could not load sources. Close the pane and try again."});const p=n.map(m=>({id:String(m.id),name:m.display_name||m.feed_key,status:we(m)??(m.operations.includes("sync")?"Sync enabled":"Live access"),feed:m}));return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:c,children:e.jsx(z,{entries:p,label:d?"channels":"feeds",action:Object.keys(s?.feeds_schema??{}).length>0?e.jsx(k,{size:"sm",variant:"outline",onClick:()=>a(!0),children:d?"Add channel":"Add feed"}):void 0,renderDetail:({feed:m})=>m.store==="channel_messages"?e.jsx(dt,{feed:m,hideHeader:!0}):e.jsx(ut,{feed:m,connectorDef:s,ownerSlug:r})})}),c&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold",children:d?"Add channel":"Add feed"}),e.jsx(mt,{organizationId:t.organization_id,connections:[t],connectorDefinitions:[s],onClose:()=>a(!1)})]})]})}function Qt({connector:t,ownerSlug:s}){const{data:r=[],isLoading:n,isError:i}=ve(t.key);if(n)return e.jsx($,{className:"h-28 w-full"});if(i)return e.jsx("p",{role:"alert",children:"Could not load actions. Close the pane and try again."});const o=t.actions_schema??{},c=r.map(a=>({id:a.operation_key,name:a.name??a.operation_key,description:a.description,operation:a}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection. Click an action to inspect its inputs."," ",e.jsx(K,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(z,{entries:c,label:"actions",renderControl:()=>e.jsx(K,{ownerSlug:s,connectorKey:t.key}),renderDetail:({operation:a,name:d})=>o[a.operation_key]?e.jsx(M,{hideHeading:!0,item:{href:"",title:d,schemaSections:ee(o[a.operation_key])}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No input fields."})})]})}function Xt({owner:t,name:s,agentId:r,clientIds:n}){const{data:i,isLoading:o}=L(t==="me"?null:t,{slug:t}),c=i?.workspace,a=t!=="me"&&c?.type==="organization"?c.id:null,d=n?.join(",")??"",p=g.useMemo(()=>({sortBy:"date",sortOrder:"desc",...r?{agentId:r}:{clientIds:d.split(",").filter(Boolean)}}),[r,d]);return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):e.jsx("div",{className:"space-y-3 px-4 py-4",children:e.jsx(P,{organizationId:a,ownerSlug:t,filters:p,hideOriginator:!0,groupStretches:!0,emptyState:e.jsxs("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:["No activity from ",s," yet."]})})})}function Zt({owner:t,path:s}){const{data:r,isLoading:n}=L(t,{slug:t}),i=r?.workspace,o=i?.type==="organization"?i.id:null,c=o?{slug:t}:void 0,{data:a,isLoading:d}=te(`/${t}/${se(s)}`,c),p=a?.entity,m=p?.id;return n||d?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):o?m==null?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't find this record. It may have been deleted, or it may live in a workspace you can't access."}):p?.is_derived?e.jsx(yt,{record:{type:p.entity_type,key:p.slug},orgContext:c}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(P,{organizationId:o,ownerSlug:t,entityId:typeof m=="number"?m:void 0,filters:{sortBy:"date",sortOrder:"desc"},emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to this record yet."})})}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."})}function Jt({slug:t,onClose:s}){const{orgContext:r}=ne(),{data:n=[],isLoading:i,isError:o}=ke(r);if(t===null)return e.jsx(X,{entityType:null,orgContext:r,onClose:s,compact:!0});if(i)return e.jsx(be,{label:"entity type",variant:"panel"});if(o)return e.jsx(Ae,{label:"entity type"});const c=n.find(a=>a.slug===t)??null;return c?e.jsx(X,{entityType:c,orgContext:r,hideDelete:Ce(c),onClose:s,compact:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Entity type not found."})}function es(t){if(Array.isArray(t.enum))return`One of ${t.enum.length}`;if(t.format==="date"||t.format==="date-time")return"Date";if(t.format==="uri")return"Link";if(t.format==="email")return"Email";const s=Array.isArray(t.type)?t.type[0]:t.type;return s==="array"?"List":s==="object"?"Group":s==="integer"||s==="number"?"Number":s==="boolean"?"Yes / no":"Text"}function ts({owner:t,typeSlug:s,view:r}){const{data:n,isLoading:i}=L(t,{slug:t}),o=n?.workspace,c=o?.type==="organization"?o.id:null,{isAdmin:a}=Se(c??void 0),{orgContext:d}=ne(),{data:p,isSuccess:m}=Ie(d),v=(p??[]).find(A=>A.slug===s),b=m&&!v,x=`/${t}/${$e(s)}`,{pathname:y}=Le(),N=y===x||y===`${x}/`||y.startsWith(`${x}/-/`),j=g.useMemo(()=>jt(v?.metadata_schema),[v?.metadata_schema]),u=D(),h=u?.close;g.useEffect(()=>{b&&h?.()},[b,h]);const C=g.useMemo(()=>({entityTypes:[s],sortBy:"date",sortOrder:"desc"}),[s]);if(i)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]});if(b)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This entity type no longer exists."});if(!c)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."});const T=v?.name??s;return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-2.5",children:[N?null:e.jsx(k,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(H,{...Pe(t,s),children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),"Browse records"]})}),v&&!N&&!Te(v)&&v.entity_count!==0?e.jsx(k,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(H,{to:"/$owner/$entityType/-/$shape",params:{owner:t,entityType:s,shape:"graph"},search:Ee(G(t,s)),children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"}),"Graph"]})}):null,r!=="activity"&&u?e.jsxs(k,{type:"button",variant:"ghost",size:"sm",className:"ml-auto h-8 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>u.open({href:G(t,s,"activity"),title:`${T} activity`}),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Activity"]}):null]}),r==="activity"?e.jsx("div",{className:"px-4 py-4",children:e.jsx(P,{organizationId:c,ownerSlug:t,filters:C,showEntityLinks:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to these records yet."})})}):a?e.jsx("div",{className:"p-4",children:e.jsx(Jt,{slug:s,onClose:()=>h?.()})}):j.length>0?e.jsxs("section",{"aria-labelledby":"entity-type-peek-fields",className:"px-4 py-4",children:[e.jsx("h3",{id:"entity-type-peek-fields",className:"mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("dl",{className:"divide-y divide-border/60 text-sm",children:j.map(A=>e.jsxs("div",{className:"flex items-baseline justify-between gap-3 py-1.5",title:A.prop.description,children:[e.jsx("dt",{className:"min-w-0 truncate",children:vt(A)}),e.jsx("dd",{className:"shrink-0 text-xs text-muted-foreground",children:es(A.prop)})]},A.key))})]}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This type has no fields yet."})]})}function ss({owner:t,eventId:s,viewKey:r}){const n=D(),i=(o,c)=>e.jsx(wt,{owner:c,organizationId:o,eventId:s,viewKey:r,dense:!0,onSelectView:n?a=>n.retarget(a):void 0},`${c}/${s}/${r??""}`);return e.jsx("div",{className:"px-4 py-4",children:t==="me"?i(null,t):e.jsx(ze,{owner:t,children:({organizationId:o,ownerSlug:c})=>o?i(o,c):e.jsx("div",{className:"h-40 animate-pulse rounded-md bg-muted/40"})})})}function ns({owner:t,feedId:s,semanticTypes:r}){const{data:n,isLoading:i}=L(t==="me"?null:t,{slug:t}),o=n?.workspace,c=t!=="me"&&o?.type==="organization"?o.id:null,a=g.useMemo(()=>({feedIds:[s],...r?.length?{semanticTypes:r}:{},sortBy:"date",sortOrder:"desc"}),[s,r]);return t!=="me"&&i?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):c==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(P,{organizationId:c,ownerSlug:t,filters:a,showEntityLinks:!0,hideOriginator:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:r?.length===1?`No ${r[0]} events from this feed yet.`:"No matching events from this feed yet."})})})}function O({owner:t,runId:s,runIds:r,contentIds:n}){const{data:i,isLoading:o}=L(t==="me"?null:t,{slug:t}),c=i?.workspace,a=t!=="me"&&c?.type==="organization"?c.id:null,d=g.useMemo(()=>{if(t==="me")return n?.length?{contentIds:n,sortBy:"date",sortOrder:"desc"}:void 0;const m=r??(s!=null?[s]:void 0);if(!(!m?.length&&!n?.length))return{...m?.length?{runIds:m}:{},...n?.length?{contentIds:n}:{}}},[t,n,s,r]),p=d!=null;return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):t!=="me"&&a==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):p?e.jsx("div",{className:"px-4 py-4",children:e.jsx(P,{presentation:"detail",organizationId:a,ownerSlug:t,filters:d,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s!=null||r?.length?"No matching events from this run yet.":"No matching events yet."})})}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing to preview."})}const F=25;function rs({target:t}){const[s,r]=g.useState(0),{data:n,isLoading:i,isError:o,refetch:c}=De(t.entityId,t.orgContext,{relationshipType:t.relationshipType,limit:F,offset:s}),a=n?.total;return e.jsxs("div",{className:"space-y-3 px-5 py-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.label," · ",t.entityName,a!==void 0?` · ${a} current ${a===1?"link":"links"}`:n?` · ${n.rows.length} shown`:""]}),e.jsx(xt,{count:n?.failures?.length??0,onRetry:()=>void c()}),i?e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{className:"h-6 w-full"}),e.jsx($,{className:"h-6 w-full"})]}):o||!n?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load these links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void c(),children:"Retry"})]}):n.rows.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links on this page."}):e.jsx("ul",{className:"divide-y divide-border",children:n.rows.map(d=>e.jsx("li",{className:"flex items-center justify-between gap-3 py-1.5",children:e.jsx(ht,{row:d,entityId:t.entityId,ownerSlug:t.ownerSlug,orgContext:t.orgContext})},d.id))}),n&&(s>0||n.hasMore)?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(k,{type:"button",variant:"outline",size:"sm",disabled:s===0,onClick:()=>r(Math.max(0,s-F)),children:"Previous"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[n.rows.length," shown",a===void 0?"":` of ${a}`]}),e.jsx(k,{type:"button",variant:"outline",size:"sm",disabled:!n.hasMore,onClick:()=>r(s+F),children:"Next"})]}):null]})}function is({owner:t,path:s,viewKey:r}){const[n,i]=g.useState({}),{data:o,isLoading:c}=L(t,{slug:t}),a=o?.workspace,d=a?.type==="organization"?a.id:null,p=d?{slug:t,organizationId:d}:void 0,{data:m,isLoading:v}=te(`/${t}/${se(s)}`,p),{isMember:b,isPublic:x,isLoading:y}=Me(t),N=b||x,j=Fe({slug:t,organizationId:b?d:null}),u=m?.entity;if(c||v||y||N&&j.isLoading)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]});if(!N)return e.jsx(kt,{});if(j.isError)return e.jsx(At,{onRetry:()=>void j.refetch()});const h=u?Be(j.data??[],{type:u.entity_type,id:u.id??u.slug}).find(C=>C.key===r):void 0;return!d||!u||!h?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This view isn't attached to this record any more."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(Ct,{orgSlug:t,viewKey:h.key,scope:{type:u.entity_type,entity:u.is_derived?u.slug:u.id??u.slug},params:n,onParamsChange:i,paramDecls:h.params,contentHash:h.content_hash,title:h.name,minHeight:320})})}function oe({owner:t,runId:s}){const r=$t(t,s);if(t==="me")return null;if(r.isLoading)return e.jsx("p",{role:"status",className:"px-4 pt-4 text-xs text-muted-foreground",children:"Loading run…"});if(!r.data)return e.jsx("p",{role:"alert",className:"px-4 pt-4 text-sm text-destructive",children:"Could not load this run."});const n=r.data;return e.jsxs("section",{"aria-label":"Run outcome",className:"space-y-2 border-b px-4 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(St,{status:It(n.status),children:n.status}),e.jsx("time",{dateTime:n.created_at,className:"text-xs text-muted-foreground",children:Ke(n.created_at)})]}),n.connection_display_name?e.jsx("p",{className:"text-sm",children:n.connection_display_name}):null,n.error_message?e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm text-destructive",children:n.error_message}):null,r.isError?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Could not refresh this run. Showing its last known outcome."}):null]})}const Z=30;function I({label:t,children:s}){return e.jsxs("section",{className:"border-t px-4 py-3 first:border-t-0",children:[e.jsx("h3",{className:"mb-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t}),s]})}function B({label:t,detail:s}){return e.jsxs("div",{className:"flex items-baseline gap-3 py-0.5 text-sm",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("span",{className:"shrink-0 truncate text-xs text-muted-foreground",children:s})]})}function as({stretch:t,ownerSlug:s,connectorDefinitions:r,connectionName:n,sourceConnection:i,showEntity:o}){const c=D(),a=g.useMemo(()=>He(t),[t]),d=g.useMemo(()=>Ue(t),[t]),[p,m]=g.useState(!1),[v,b]=g.useState(new Set),x=l=>e.jsx("li",{children:e.jsx(gt,{content:l,ownerSlug:s,connectorDefinitions:r,connectionName:n,showEntity:o})},l.id),y=l=>e.jsx("ul",{className:"-mx-1 divide-y overflow-hidden rounded-lg border",children:l.map(x)}),N=[...a.failedCalls.map(l=>l.content),...a.failedOperations.flatMap(l=>E(l)??[])],j=t.changes.flatMap(l=>E(l)??[]),u=[...t.calls.map(l=>l.content),...t.operations.flatMap(l=>E(l)??[])].sort((l,f)=>new Date(f.occurred_at).getTime()-new Date(l.occurred_at).getTime()),h=p?u:u.slice(0,Z),C=(l,f)=>e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-2",onClick:f,children:["Show all ",l]});if(t.source){const{source:l}=t,f=t.flagged.flatMap(w=>E(w)??[]),le=d.reduce((w,W)=>w+W.items.length,0),_=i?.(l.connectionId)??null;return e.jsxs("div",{className:"pb-4",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-4 pt-3 pb-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:l.name}),e.jsxs("span",{children:["· ",Y(t)]}),e.jsxs("span",{children:["· ",Q(le,"item")]}),f.length>0?e.jsxs("span",{children:["· ",f.length," failed"]}):null,_&&c?e.jsxs(k,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>c.open({href:`/${s}/connectors/${encodeURIComponent(_.connectorKey)}/${l.connectionId}`,key:`connection:${l.connectionId}`,title:l.name,connectorPanel:{section:"data",connectorKey:_.connectorKey,connectionId:l.connectionId,organizationId:_.organizationId,ownerSlug:s}}),children:["All data from ",l.name]}):null]}),f.length>0?e.jsx(I,{label:`Failed · ${f.length}`,children:y(f)}):null,d.map(w=>{const q=v.has(w.type)?w.items:w.items.slice(0,Z);return e.jsxs(I,{label:w.label,children:[y(q),w.items.length>q.length?C(w.items.length,()=>b(new Set([...v,w.type]))):null]},w.type)})]})}const T=a.did.reduce((l,f)=>l+f.count,0),A=a.lookedAt.reduce((l,f)=>l+f.count,0),S=t.apps.length===1?t.apps[0]:null,V=S?.key.startsWith("client:")?`/${s}/events?client_ids=${encodeURIComponent(S.key.slice(7))}`:S?.key.startsWith("agent:")?`/${s}/events?agent=${encodeURIComponent(S.key.slice(6))}`:null;return e.jsxs("div",{className:"pb-4",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-4 pt-3 pb-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:ft(t)}),e.jsxs("span",{children:["· ",Y(t)]}),e.jsxs("span",{children:["· ",Q(t.calls.length,"call")]}),e.jsxs("span",{children:["· ",N.length," failed"]}),V&&S&&c?e.jsxs(k,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>c.open({href:V,title:S.name}),children:["All activity from ",S.name]}):null]}),N.length>0?e.jsx(I,{label:`Failed · ${N.length}`,children:y(N)}):null,t.kind==="background"?null:e.jsxs(I,{label:`Changed · ${j.length||a.changeSteps.reduce((l,f)=>l+f.count,0)}`,children:[j.length>0?y(j):null,a.changeSteps.map(l=>e.jsx(B,{label:l.title,detail:`${l.methods.join(" · ")} · ${l.count}`},l.title)),j.length===0&&a.changeSteps.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nothing changed."}):null]}),T>0?e.jsx(I,{label:`Did · ${T}`,children:a.did.map(l=>e.jsx(B,{label:l.group,detail:l.items.length>0?l.items.slice(0,5).map(f=>`${f.item} ${f.count}`).join(" · ")+(l.items.length>5?` · ${l.items.length-5} more`:""):String(l.count)},l.group))}):null,A>0?e.jsx(I,{label:`Looked at · ${A}`,children:a.lookedAt.map(l=>e.jsx(B,{label:l.title,detail:`${l.methods.join(" · ")} · ${l.count}`},l.title))}):null,e.jsxs(I,{label:`Raw calls · ${u.length}`,children:[y(h),u.length>h.length?C(u.length,()=>m(!0)):null]})]})}function en({item:t}){if(t.connectorPanel)return e.jsx(Vt,{panel:t.connectorPanel});if(t.schemaSections)return e.jsx(M,{item:t});if(t.recordField)return e.jsx(bt,{target:t.recordField});if(t.recordPeer)return e.jsx(Nt,{target:t.recordPeer});if(t.recordLinks)return e.jsx(rs,{target:t.recordLinks});if(t.workStretch)return e.jsx(as,{...t.workStretch});if(typeof t.browserUrl=="string"&&t.browserUrl.length>0)return e.jsx(J,{item:t});const s=t.href?Ve(t.href):null;return s?s.kind==="memory"?"runId"in s?e.jsxs(e.Fragment,{children:[e.jsx(oe,{owner:s.owner,runId:s.runId}),e.jsx(U,{title:"What it produced",children:e.jsx(O,{owner:s.owner,runId:s.runId})}),e.jsx(ce,{owner:s.owner,runId:s.runId})]}):"runIds"in s?e.jsx(O,{owner:s.owner,runIds:s.runIds}):e.jsx(O,{owner:s.owner,contentIds:s.contentIds}):s.kind==="entity"?e.jsx(Zt,{owner:s.owner,path:s.path}):s.kind==="entity-type"?e.jsx(ts,{owner:s.owner,typeSlug:s.typeSlug,view:s.view}):s.kind==="record-view"?e.jsx(is,{owner:s.owner,path:s.path,viewKey:s.viewKey}):s.kind==="event"?e.jsx(ss,{owner:s.owner,eventId:s.eventId,viewKey:s.viewKey}):s.kind==="feed"?e.jsx(ns,{owner:s.owner,feedId:s.feedId,semanticTypes:s.semanticTypes}):s.kind==="agent"?e.jsx(Xt,{owner:s.owner,name:t.title,agentId:s.agentId,clientIds:s.clientIds}):t.runId?e.jsx(os,{owner:s.owner,automationId:s.automationId,runId:t.runId}):e.jsx(cs,{owner:s.owner,automationId:s.automationId}):e.jsx(J,{item:t})}function J({item:t}){const s=t.body,r=t.notificationType??"generic",n=t.createdAt,i=t.browserUrl??null,o=t.browserHandoff??null;return e.jsxs("article",{className:"space-y-4 px-5 py-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(We,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:qe(r)}),n?e.jsx("span",{children:Ge(n)}):null]})]}),s?e.jsx("div",{className:"text-sm leading-6 text-foreground/90",children:e.jsx(Ye,{text:s,linkPolicy:r==="action_approval_needed"?"app-links":"strip"})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No additional details were provided."}),t.owner&&t.sourceAttribution?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground/80",children:"Generated from"}),e.jsx(Qe,{owner:t.owner,source:t.sourceAttribution,className:"text-xs"})]}):null,i?e.jsx("div",{className:"space-y-2",children:o?.state==="expired"?e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:o.error_message??"This draft expired before the page was opened."}):o?.state==="completed"||o?.state==="preparing"?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.state==="preparing"?"Preparing draft — keep your browser tab open.":"Draft prepared — review and post in your browser."}):e.jsxs(k,{type:"button",size:"sm",className:"h-8 text-sm",onClick:()=>{Ze(i)},children:[e.jsx(Xe,{className:"mr-1.5 h-3.5 w-3.5"}),"Open post"]})}):null]})}function U({title:t,children:s}){return e.jsxs("section",{"aria-label":t,className:"border-b",children:[e.jsx("h2",{className:"px-4 pt-4 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t}),s]})}function ce({owner:t,runId:s}){return t==="me"?null:e.jsx("div",{className:"px-4 py-3",children:e.jsxs(H,{to:"/$owner/events",params:{owner:t},search:{run_ids:String(s)},className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:["Open in Activity",e.jsx(Je,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]})})}function os({owner:t,automationId:s,runId:r}){const{organizationId:n}=re(t),i=ie(s,void 0,n),o=et(i.data?.automation);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{owner:t,runId:r}),e.jsx(U,{title:"What it produced",children:e.jsx(O,{owner:t,runId:r})}),o?e.jsx(U,{title:"How it ran",children:e.jsx(Ut,{agentId:o,automationId:s,ownerSlug:t,runId:r})}):i.isLoading?e.jsx($,{className:"m-4 h-24 rounded-lg"}):null,e.jsx(ce,{owner:t,runId:r})]})}function cs({owner:t,automationId:s}){const{organizationId:r}=re(t),n=ie(s,void 0,r),i=tt(t,s,n.data?.automation);return e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsx(st,{runNow:i}),e.jsx(nt,{owner:t,agentId:null,automationId:s,view:"activity",onDone:()=>{}})]})}export{en as PeekPaneContent};
2
- //# sourceMappingURL=peek-pane-content-c2PG3TEX.js.map
@@ -1,2 +0,0 @@
1
- import{r as e,eo as l}from"./index-DByaMzsG.js";function a(){return e.useEffect(()=>{l()},[]),null}export{a as P};
2
- //# sourceMappingURL=public-shell-ready-D8TijlRY.js.map
@@ -1,2 +0,0 @@
1
- import{aT as us,j as e,r as j,c as K,P as $e,dJ as ms,z as bt,dI as jt,L as je,ac as fs,dL as ps,S as kt,dM as hs,d5 as vs,aM as Ct,aO as A,bo as rt,dN as ys,dO as gs,dP as xs,dQ as bs,dR as js,c_ as ks,dS as ee,cr as Cs,dT as St,dU as Ss,aw as Ns,dV as _s,s as Is,dj as Es,aB as ye,dW as As,dX as Ts,n as Nt,cL as _t,dY as Fs,cx as ct,dZ as Rs,cP as Ps,dg as It,d_ as Ms,d$ as ws,cu as Ls,aP as $s,d9 as Os,$ as Ds,i as ge,X as Bs,e0 as Ks,e1 as Gs,bS as Vs,e2 as Qs,e3 as Us,e4 as Et,bq as Ws,br as Hs,bs as zs,bt as qs,bu as Ys,e5 as Zs,e6 as At,e7 as lt,H as Xs,e8 as Js,e9 as Fe,ea as dt,cM as en,eb as tn,x as sn,cK as nn,ec as on,ed as an,t as rn,ee as cn,ef as ln,eg as dn,b$ as un,eh as mn,ei as fn,dA as pn,bc as ut,ej as mt,ek as Tt,el as Re,dl as Ft,B as Rt,em as hn,en as Pe}from"./index-DByaMzsG.js";import{S as D,F as ft,o as X,d as vn,r as yn,f as gn,a as xn}from"./filter-editors-CQoSj-20.js";import{u as bn}from"./runs-C8sZQr4o.js";import{u as Pt}from"./activity-route-location-C1jcXC7v.js";import{e as jn,f as Ae,C as Mt,c as kn}from"./event-kind-options-fHAIXu24.js";import{S as Cn}from"./source-record-panels-CGmKIJdN.js";import{u as Sn}from"./clients-xnzZeEdZ.js";import{u as Nn}from"./client-activity-scopes-BPbRX-Pe.js";import{g as _n}from"./client-rows-vrNA6FLs.js";import{E as In}from"./events-feed-DmRzikZW.js";import{E as En}from"./run-initiator-DhE5v4z0.js";import{L as An,u as Tn}from"./renderer-olRv_HMI.js";import{E as Fn}from"./agent-loading-shells-DYqQphN7.js";import{M as Rn}from"./member-scope-gate-vvkgSAb2.js";const Oe=j.createContext(null);function Pn({organizationId:t,isWorkspaceLoading:s,children:a}){const{data:n=[],isLoading:o}=us(t);return e.jsx(Oe.Provider,{value:{groups:n,isLoading:!!s||o},children:a})}function Mn(){const t=j.useContext(Oe);if(!t)throw new Error("useMemoryConnectorGroups must be used within MemoryConnectorGroupsProvider");return t}function wn(){return j.useContext(Oe)}function wt(t){const{parse:s,serialize:a,filterKeys:n,clearClassifications:o=!0,replace:i=!0,merge:l}=t,y=K(),d=$e(),r=j.useMemo(()=>{const u=new URLSearchParams;for(const[f,p]of Object.entries(d.search||{}))p!=null&&u.set(f,typeof p=="object"&&!Array.isArray(p)?JSON.stringify(p):String(p));return s(u)},[d.search,s]),c=j.useCallback((u,f)=>{const p=l?l(r,u):{...r,...u},v=a(p),k={};for(const[x,S]of Object.entries(d.search||{}))S!=null&&(k[x]=S);for(const x of n)delete k[x];if(o)for(const x of Object.keys(k))x.startsWith("clf_")&&delete k[x];for(const[x,S]of Object.entries(v))S!==void 0&&(k[x]=S);y({to:d.pathname,search:k,replace:f?.replace??i})},[r,a,n,o,l,y,d,i]),g=j.useCallback(()=>{const u={};for(const[f,p]of Object.entries(d.search||{}))p!=null&&(n.includes(f)||o&&f.startsWith("clf_")||(u[f]=p));y({to:d.pathname,search:u,replace:i})},[y,d.pathname,d.search,n,o,i]);return{filters:r,updateFilters:c,clearFilters:g}}function Ln(t){const{slug:s}=ms();return bt({queryKey:["schedules",s,t],queryFn:async()=>((await jt("manage_schedules",{action:"list",action_type:"wake_agent",include_paused:!0})).schedules??[]).filter(n=>n.action_args?.agent_id===t),enabled:!!s&&!!t,staleTime:3e4})}function $n(t,s){return{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:t,connectorKey:s.connector_key,connectionId:String(s.connection_id)},search:{feedId:s.id}}}function On(t,s){return{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:t,connectorKey:s.connector_key,connectionId:String(s.id)}}}function Dn(t,s){return{to:"/$owner/agents/connected/$clientId",params:{owner:t,clientId:s}}}function Bn(t,s){return{to:"/$owner/automations/$automationId",params:{owner:t,automationId:s}}}function Kn(t,s,a){return{to:"/$owner/events",params:{owner:t},search:{agent:s,schedule:a}}}function me({id:t,label:s,value:a,sourceLink:n,details:o,onRemove:i}){return{id:t,label:s,op:"is",value:a,onRemove:i,editor:n||o?{kind:"custom",className:"w-80",render:()=>e.jsxs("div",{className:"flex flex-col gap-2 p-3 text-sm",children:[n?e.jsxs(je,{to:n.to,params:n.params,search:n.search,className:"inline-flex min-w-0 items-center gap-1.5 font-medium text-foreground hover:underline",children:[e.jsx("span",{className:"truncate",children:a}),e.jsx(fs,{className:"h-3 w-3 shrink-0 text-muted-foreground"})]}):e.jsx("span",{className:"font-medium",children:a}),o]})}:void 0}}function Gn({ownerSlug:t,clientIds:s,linkedUser:a,linkedUserEntitySlug:n}){const o=t&&n?ps(t,[{entity_type:"$member",slug:n}]):null;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"inline-flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.length===1?"Client ID":"Client IDs"}),s.map(i=>e.jsx("code",{className:"break-all text-foreground",children:i},i))]}),a?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:["Granted by",o?e.jsx(je,{to:o,className:"font-medium text-foreground hover:underline",children:a}):e.jsx("span",{className:"font-medium text-foreground",children:a})]}):null]})}function Vn(t,s=!0){return bt({queryKey:["automations-list","activity",t],queryFn:async()=>{const a=await Promise.all(["active","archived"].map(n=>jt("manage_automations",{action:"list",status:n,include_details:!1},{slug:t})));return[...new Map(a.flatMap(n=>n.automations).map(n=>[Number(n.automation_id),n])).values()].sort((n,o)=>n.name.localeCompare(o.name))},enabled:s&&!!t,staleTime:3e4})}function J({to:t,params:s,search:a,label:n}){return e.jsx(je,{to:t,params:s,search:a,onClick:o=>o.stopPropagation(),onPointerDown:o=>o.stopPropagation(),className:"shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100 focus-visible:opacity-100","aria-label":`Manage ${n}`,children:e.jsx(kt,{className:"h-3.5 w-3.5"})})}const Me=["produced","analyzed"],xe=t=>t==="produced"?"Produced by":"Analyzed by";function Qn({enabled:t,...s}){const a=Un(s,t);if(!t)return{fields:[],chips:[]};const n=Wn(s);return{fields:[a.field,n.field],chips:[...a.chips,...n.chips]}}function Un({ownerSlug:t,filters:s,onFiltersChange:a},n){const o=Vn(t,n),i=o.data??[],l=c=>c==="produced"?s.producedByAutomationId:s.automationId,y=c=>i.find(g=>Number(g.automation_id)===c)?.name??`#${c}`,d=Me.flatMap(c=>{const g=l(c);return g==null?[]:[{id:`automation-${c}`,field:"automation",label:xe(c),value:y(g),onRemove:()=>a(c==="produced"?{producedByAutomationId:null}:{automationId:null})}]}),r={kind:"list",className:"w-80",searchPlaceholder:"Search Automations...",emptyText:o.isLoading?"Loading Automations...":"No Automations found",items:c=>e.jsxs(e.Fragment,{children:[Me.map(g=>{const u=l(g),f=i.map(v=>({id:Number(v.automation_id),label:`${v.name}${v.status==="archived"?" (archived)":""}`}));u!=null&&!f.some(v=>v.id===u)&&f.unshift({id:u,label:`Automation #${u} (selected)`});const p=v=>{a(g==="produced"?{producedByAutomationId:v}:{automationId:v}),c()};return e.jsx(Ct,{heading:xe(g),children:f.map(v=>e.jsxs(A,{"aria-label":v.label,value:`${g} ${v.label} ${v.id}`,onSelect:()=>p(v.id),className:"group",children:[e.jsx(D,{selected:u===v.id}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:v.label}),e.jsx(J,{...Bn(t,String(v.id)),label:v.label})]},v.id))},g)}),o.isError?e.jsx(A,{forceMount:!0,onSelect:()=>void o.refetch(),children:"Could not load Automations. Retry"}):null]})};return{chips:d,field:{key:"automation",label:"Automation",group:"Scope",icon:e.jsx(hs,{className:"h-4 w-4"}),editor:r}}}function Wn(t){const{filters:s,onFiltersChange:a}=t,n=[];s.runIds?.length&&n.push({id:"run-produced",field:"run",label:"Produced by run",value:s.runIds.map(i=>`#${i}`).join(", "),onRemove:()=>a({runIds:null})}),s.runId!=null&&n.push({id:"run-analyzed",field:"run",label:"Analyzed by run",value:`#${s.runId}`,onRemove:()=>a({runId:null})});const o={kind:"list",className:"w-96",searchPlaceholder:"Search runs or enter a run ID...",emptyText:"No matching runs. Enter an exact run ID or load more.",items:(i,l)=>Me.map(y=>e.jsx(Hn,{...t,mode:y,query:l,close:i},y))};return{chips:n,field:{key:"run",label:"Run",group:"Scope",icon:e.jsx(vs,{className:"h-4 w-4"}),editor:o}}}function Hn({ownerSlug:t,filters:s,onFiltersChange:a,mode:n,query:o,close:i}){const l=n==="produced"?s.producedByAutomationId:s.automationId,y=bn({workspace:!0},{automationIds:l==null?void 0:[l],runTypes:n==="analyzed"?["automation"]:void 0,connectionIds:n==="produced"?s.connectionIds??void 0:void 0,feedIds:n==="produced"?s.feedIds??void 0:void 0},t),d=n==="produced"?s.runIds??[]:s.runId==null?[]:[s.runId],r=y.data?.pages.flatMap(f=>f.runs)??[],c=[...new Map(r.map(f=>[f.id,{id:f.id,label:`Run #${f.id} · ${f.feed_display_name??f.operation_key??f.run_type} · ${f.status}`}])).values()];for(const f of d)c.some(p=>p.id===f)||c.unshift({id:f,label:`Run #${f} (selected)`});const g=f=>{if(n==="produced"){const p=d.includes(f)?d.filter(v=>v!==f):[...d,f];a({runIds:p.length?p:null})}else a({runId:f}),i()},u=/^\d+$/.test(o.trim())?Number(o.trim()):0;return e.jsxs(Ct,{heading:xe(n),children:[c.map(f=>e.jsxs(A,{value:`${n} ${f.label}`,onSelect:()=>g(f.id),children:[e.jsx(D,{selected:d.includes(f.id)}),e.jsx("span",{className:"truncate",children:f.label})]},f.id)),Number.isSafeInteger(u)&&u>0&&!c.some(f=>f.id===u)?e.jsxs(A,{value:`${n} ${u}`,onSelect:()=>g(u),children:[xe(n)," run #",u]}):null,y.isLoading?e.jsx(A,{disabled:!0,forceMount:!0,children:"Loading runs..."}):null,y.isError?e.jsx(A,{forceMount:!0,onSelect:()=>void(y.isFetchNextPageError?y.fetchNextPage():y.refetch()),children:"Could not load runs. Retry"}):null,!y.isLoading&&!y.isError&&!c.length?e.jsx(A,{disabled:!0,forceMount:!0,children:"No runs found"}):null,y.hasNextPage?e.jsx(A,{forceMount:!0,disabled:y.isFetching,onSelect:()=>void y.fetchNextPage(),children:y.isFetchingNextPage?"Loading more runs...":"Load more runs"}):null]})}const De="Scope",Te="Source",Q="h-4 w-4";function te(){return Pt().search??{}}function Lt(t){const{pathname:s}=Pt(),a=s.startsWith(`/${t}/events/`),n=xs(s,a?1:0),o=!!(n&&!a&&!bs(n.split("/")[0]));return{pathname:s,embedded:o,recordPath:o?js(n)?.entityPath:a?n:void 0}}function $t(t){const s=te(),{recordPath:a,pathname:n,embedded:o}=Lt(t);return i=>{const l=ee(t,s,i,a);return o?{to:n,search:l.search}:l}}const pt=t=>new Set((t??"").split(",").map(s=>s.trim()).filter(Boolean));function zn({ownerSlug:t,sourceRead:s=!1,filters:a,onFiltersChange:n}){const o=te(),{recordPath:i,embedded:l}=Lt(t),y=i?i.split("/").at(-2):void 0,d=typeof o.type=="string"&&o.type.trim()?o.type.trim():void 0,r=(y?rt(y):void 0)??(d?rt(d):void 0),c=ys(o),g=gs(o),u=typeof o.feed_ids=="string"?o.feed_ids:typeof o.feed_ids=="number"?String(o.feed_ids):void 0,f=qn(t,r,!l),p=Yn(t,r,i,l),v=Zn(t,c,!s),k=Qn({ownerSlug:t,filters:a,onFiltersChange:n,enabled:!s}),x=Xn(t,g,u);return[f,p,v,k,x].reduce((S,w)=>({fields:[...S.fields,...w.fields],chips:[...S.chips,...w.chips]}),{fields:[],chips:[]})}function qn(t,s,a){const n=K(),o=te(),{visible:i}=ks(t);if(!a)return{fields:[],chips:[]};const l=i.find(d=>d.slug===s),y={kind:"list",searchPlaceholder:"Search types...",emptyText:"No entity types",items:d=>e.jsxs(e.Fragment,{children:[i.map(r=>e.jsxs(A,{onSelect:()=>{n(ee(t,o,{entity:void 0,create:void 0,type:r.slug})),d()},className:"group gap-2",children:[e.jsx(D,{selected:r.slug===s}),e.jsx(Ps,{icon:r.icon,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r.name}),typeof r.entity_count=="number"?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:r.entity_count}):null,e.jsx(J,{to:"/$owner/entity-types/$slug",params:{owner:t,slug:r.slug},label:r.name})]},r.id)),e.jsxs(A,{onSelect:()=>{n(Ms(t)),d()},className:"text-muted-foreground",children:[e.jsx(It,{className:"h-4 w-4 shrink-0"}),"Add entity type"]})]})};return{fields:[{key:"type",label:"Entity type",group:De,icon:e.jsx(Cs,{className:Q}),editor:y}],chips:s?[{id:"type",label:"Entity type",op:"is",value:l?.name??s,onRemove:()=>void n(ee(t,o,{type:void 0}))}]:[]}}function Yn(t,s,a,n){const o=K(),i=te(),[l,y]=j.useState(""),[d,r]=j.useState(0),c=St(l,250),g={slug:t},{data:u,isLoading:f,isError:p,refetch:v}=Ss(s??"",g,{search:c,offset:d,limit:30,enabled:!n&&!!s}),{data:k}=Ns(a?`/${t}/${a}`:"",g),x=a?k?.entity:void 0,S=x?.name??(a?a.split("/").at(-1):void 0);if(n)return{fields:[],chips:S?[{id:"entity",label:"Entity",op:"is",value:S}]:[]};if(!s)return{fields:[],chips:[]};const w={kind:"list",searchPlaceholder:"Search entities...",emptyText:f?"Loading entities...":"No matching entities",className:"w-80",onQueryChange:F=>{y(F),r(0)},items:F=>e.jsxs(e.Fragment,{children:[p?e.jsx(A,{onSelect:()=>void v(),children:"Could not load entities. Retry"}):u?.entities.map(I=>e.jsxs(A,{value:I.slug,onSelect:()=>{const R=ws([...I.parent_slug&&I.parent_entity_type?[{entity_type:I.parent_entity_type,slug:I.parent_slug}]:[],{entity_type:I.entity_type,slug:I.slug}]);o(ee(t,i,{type:s},R)),F()},children:[e.jsx(D,{selected:x?.slug===I.slug}),I.name]},I.slug)),d>0&&e.jsx(A,{onSelect:()=>r(Math.max(0,d-30)),children:"Previous entities"}),u?.metadata.has_more&&e.jsx(A,{disabled:f,onSelect:()=>r(d+30),children:"More entities"})]})};return{fields:[{key:"entity",label:"Entity",group:De,icon:e.jsx(_s,{className:Q}),editor:w}],chips:S?[{id:"entity",label:"Entity",op:"is",value:S,onRemove:()=>void o(ee(t,i,{type:s}))}]:[]}}function Zn(t,s,a){const n=K(),o=$t(t),{data:i=[]}=Is(),l=j.useMemo(()=>[...i].sort((r,c)=>r.name.localeCompare(c.name)),[i]);if(!a)return{fields:[],chips:[]};const y=l.find(r=>r.agentId===s),d={kind:"list",searchPlaceholder:"Search agents...",emptyText:"No agents",items:r=>l.map(c=>e.jsxs(A,{onSelect:()=>{n(o({agent:c.agentId,schedule:void 0})),r()},className:"gap-2",children:[e.jsx(D,{selected:c.agentId===s}),e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md bg-muted text-[10px] font-medium",children:c.name.trim().charAt(0).toUpperCase()||"?"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:c.name})]},c.agentId))};return{fields:[{key:"agent",label:"Agent",group:De,icon:e.jsx(Es,{className:Q}),editor:d}],chips:s?[{id:"agent",label:"Agent",op:"is",value:y?.name??s,onRemove:()=>void n(o({agent:void 0,schedule:void 0}))}]:[]}}function Xn(t,s,a){const n=K(),o=$t(t),{groups:i}=Mn(),l=te(),y=ye({platforms:String(l.platforms??l.platform??"")}).platforms??[],d=j.useMemo(()=>pt(s),[s]),r=j.useMemo(()=>pt(a),[a]),c=y.length===1?y[0]:As(i,d),g=i.find(E=>E.connector_key===c),u=d.size===1?Number([...d][0]):void 0,f=Ts(u),{org:p}=Nt(),v=_t(p?.id,{feedIds:[...r].map(Number),enabled:u==null&&r.size>0}),k=u==null?v:f,x=k.data??[],S={platforms:void 0,platform:void 0,connection_ids:void 0,feed_ids:void 0},w={kind:"list",searchPlaceholder:"Search connectors...",emptyText:"No connectors",items:E=>e.jsxs(e.Fragment,{children:[i.map(N=>{const T=N.connector_name??N.connector_key;return e.jsxs(A,{disabled:N.connections.length===0,onSelect:()=>{n(o({...S,platforms:N.connector_key})),E()},className:"group gap-2",children:[e.jsx(D,{selected:N.connector_key===g?.connector_key}),e.jsx($s,{plain:!0,name:T,faviconDomain:N.favicon_domain,className:"h-5 w-5 shrink-0 rounded-md text-[10px]"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:T}),N.connection_count>0?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:N.connection_count}):null,e.jsx(J,{to:"/$owner/connectors/$connectorKey",params:{owner:t,connectorKey:N.connector_key},label:T})]},N.connector_key)}),e.jsx(A,{asChild:!0,onSelect:E,className:"text-muted-foreground",children:e.jsxs(je,{to:"/$owner/connectors/create",params:{owner:t},className:"flex items-center gap-2",children:[e.jsx(It,{className:"h-4 w-4 shrink-0"}),"Add connector"]})})]})},F=[{key:"connector",label:"Connector",group:Te,icon:e.jsx(Ls,{className:Q}),editor:w}],I=[],R=g?.connector_name??g?.connector_key??(y.join(", ")||(d.size?`Connections ${[...d].join(", ")}`:void 0));if(R&&I.push({id:"connector",label:"Connector",op:"is",value:R,onRemove:()=>void n(o(S))}),g){F.push({key:"connection",label:"Connection",group:Te,icon:e.jsx(Fs,{className:Q}),editor:U(g)});const E=d.size===1?g.connections.find(N=>d.has(String(N.id))):void 0;E&&I.push({id:"connection",label:"Connection",op:"is",value:ct({display_name:E.display_name,connector_name:g.connector_name,connector_key:g.connector_key}),onRemove:()=>void n(o({...S,platforms:g.connector_key}))})}if((u||a)&&F.push({key:"feed",label:"Feed",group:Te,icon:e.jsx(Rs,{className:Q}),editor:G()}),r.size>0){const E=r.size===1?x.find(N=>r.has(String(N.id))):void 0;I.push({id:"feed",label:"Feed",op:"is",value:E?fe(E):`#${a}`,onRemove:()=>void n(o({...u!=null?{connection_ids:String(u)}:{},feed_ids:void 0}))})}return{fields:F,chips:I};function U(E){return{kind:"list",searchPlaceholder:"Search connections...",emptyText:"No connections",items:N=>E.connections.map(T=>{const b=ct({display_name:T.display_name,connector_name:E.connector_name,connector_key:E.connector_key});return e.jsxs(A,{onSelect:()=>{n(o({connection_ids:String(T.id),feed_ids:void 0})),N()},className:"group gap-2",children:[e.jsx(D,{selected:d.has(String(T.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b}),T.feed_count>0?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:T.feed_count}):null,e.jsx(J,{...On(t,{id:T.id,connector_key:E.connector_key}),label:b})]},T.id)})}}function G(){return{kind:"list",searchPlaceholder:"Search feeds...",emptyText:k.isLoading?"Loading feeds...":"No feeds",items:E=>x.map(N=>e.jsxs(A,{"aria-label":fe(N),onSelect:()=>{n(o({...u!=null?{connection_ids:String(u)}:{},feed_ids:String(N.id)})),E()},className:"group gap-2",children:[e.jsx(D,{selected:r.has(String(N.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:fe(N)}),e.jsx(J,{...$n(t,N),label:fe(N)})]},N.id))}}}function fe(t){return t.display_name?.trim()||t.feed_key}const be=[{value:"date-desc",label:"Newest first"},{value:"date-asc",label:"Oldest first"},{value:"score-desc",label:"Highest score"},{value:"score-asc",label:"Lowest score"}];function Jn({value:t,onChange:s}){const a=be.find(n=>n.value===t)?.label??"Newest first";return e.jsxs(Ws,{value:t,onValueChange:s,children:[e.jsxs(Hs,{"aria-label":"Sort",className:"h-8 w-auto shrink-0 gap-2 bg-muted px-2.5",children:[e.jsx(Et,{"aria-hidden":"true",className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(zs,{children:a})]}),e.jsx(qs,{align:"end",className:"min-w-40",children:be.map(n=>e.jsx(Ys,{value:n.value,children:n.label},n.value))})]})}const ht=[{value:"user",label:"Manual review"},{value:"system",label:"Auto-classified"},{value:"llm",label:"LLM-classified"}],vt=[{value:"pending",label:"Pending approval"},{value:"approved",label:"Approved"},{value:"rejected",label:"Rejected"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}],pe=0,he=100,Z="Event",V="h-4 w-4";function eo(t,s,a){const n=t.engagementRange??[pe,he],o=t.reviewStatus,i=t.interactionStatus,l=t.semanticTypes??[],y=[{key:"kind",label:"Event kind",group:Z,icon:e.jsx(Ks,{className:V}),editor:X({searchPlaceholder:"Search event kinds...",emptyText:"No event kinds found",options:jn(a,l).map(c=>({value:c,label:Ae(c)})),selected:l,multiple:!0,onSelect:c=>{const g=l.includes(c)?l.filter(u=>u!==c):[...l,c];s({semanticTypes:g.length>0?g:void 0})}})},{key:"date",label:"Date",group:Z,icon:e.jsx(Gs,{className:V}),editor:vn({value:t.dateRange??void 0,onApply:c=>s({dateRange:c})})},{key:"approval",label:"Approval",group:Z,icon:e.jsx(Vs,{className:V}),editor:X({searchPlaceholder:"Search statuses...",options:[...vt],selected:i?[i]:[],onSelect:c=>s({interactionStatus:c})})},{key:"review",label:"Reviewed by",group:Z,icon:e.jsx(Qs,{className:V}),editor:X({searchPlaceholder:"Search reviewers...",options:[...ht],selected:o&&o!=="all"?[o]:[],onSelect:c=>s({reviewStatus:c})})},{key:"score",label:"Engagement score",group:Z,icon:e.jsx(Us,{className:V}),editor:yn({value:n,min:pe,max:he,onApply:c=>s({engagementRange:c})})}],d=[],r=t.eventCategory!=null&&l.length===1&&l[0]===Mt;return l.length&&!r&&d.push({id:"kind",label:"Kind",value:l.length<=2?l.map(Ae).join(", "):`${l.length} kinds`,title:l.map(Ae).join(", "),onRemove:()=>s({semanticTypes:void 0})}),t.dateRange&&d.push({id:"date",label:"Date",op:"is",value:gn(t.dateRange),onRemove:()=>s({dateRange:null})}),i&&d.push({id:"approval",label:"Approval",op:"is",value:vt.find(c=>c.value===i)?.label??i,onRemove:()=>s({interactionStatus:null})}),o&&o!=="all"&&d.push({id:"review",label:"Reviewed by",op:"is",value:ht.find(c=>c.value===o)?.label??o,onRemove:()=>s({reviewStatus:void 0})}),(n[0]!==pe||n[1]!==he)&&d.push({id:"score",label:"Engagement score",value:xn(n,pe,he),onRemove:()=>s({engagementRange:void 0})}),{fields:y,chips:d}}function Ot({filters:t,onFiltersChange:s,eventKinds:a=[],searchQuery:n,onSearchChange:o,scope:i,extraFields:l=[],drillChips:y=[],sourceRead:d=!1,filterTrailing:r,filterActions:c,quickFilters:g,toolbar:u=!1,onClearFilters:f}){const p=n.trim().length>0,v=d?{fields:[],chips:[]}:eo(t,s,a),k=`${t.sortBy??"date"}-${t.sortOrder??"desc"}`,x=R=>{const[U,G]=R.split("-");s({sortBy:U,sortOrder:G})},S=u&&!d?{fields:[{key:"sort",label:"Order",group:"Order",icon:e.jsx(Et,{className:V}),editor:X({searchPlaceholder:"Search orders...",options:[...be],selected:[k],onSelect:x})}],chips:k==="date-desc"?[]:[{id:"sort",label:"Order",value:be.find(R=>R.value===k)?.label??k,onRemove:()=>s({sortBy:"date",sortOrder:"desc"})}]}:{fields:[],chips:[]},w=[...g?.fields??[],...v.fields,...i?.fields??[],...l,...S.fields],F=[...g?.chips??[],...i?.chips??[],...y,...v.chips,...S.chips],I=d?null:e.jsxs("div",{className:ge("relative min-w-0",u?"w-64 max-w-full":"flex-1"),children:[e.jsx(Os,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Ds,{type:"search","aria-label":"Search events",placeholder:"Search events...",value:n,onChange:R=>o(R.target.value),className:ge("h-8 pl-9",p&&"pr-9")}),p&&e.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>o(""),className:"absolute right-0.5 top-1/2 flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",children:e.jsx(Bs,{className:"h-3.5 w-3.5"})})]});return u?e.jsx(ft,{label:"Event filters",clearAllMin:2,fields:w,chips:F,actions:c,trailing:e.jsxs(e.Fragment,{children:[r,I]}),onClearAll:f,hasClearableState:p,className:"w-full"}):e.jsxs("div",{className:"w-full space-y-2.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[I,!d&&e.jsx(Jn,{value:k,onChange:x})]}),e.jsx(ft,{label:"Event filters",fields:w,chips:F,actions:c,trailing:r,onClearAll:f,hasClearableState:p})]})}function Dt({ownerSlug:t,...s}){const a=zn({ownerSlug:t,sourceRead:s.sourceRead,filters:s.filters,onFiltersChange:s.onFiltersChange});return e.jsx(Ot,{...s,scope:a})}const we=3600*1e3,yt=24*we;function gt(t){const s=t instanceof Date?t:new Date(String(t));return Number.isNaN(s.getTime())?null:s}function xt(t){return t.toISOString().split("T")[0]}function Le(t){return t.toLocaleDateString(void 0,{timeZone:"UTC",month:"short",day:"numeric"})}function to(t){const a=t[t.length-1].date.getTime()-t[0].date.getTime()>180*yt,n=new Map;for(const o of t){const i=new Date(o.date);a&&i.setUTCDate(i.getUTCDate()-i.getUTCDay()),n.set(i.getTime(),(n.get(i.getTime())??0)+o.count)}return[...n.entries()].sort(([o],[i])=>o-i).map(([o,i])=>{const l=new Date(o);return{start:l,end:new Date(o+(a?7:1)*yt),count:i,label:`${l.getUTCMonth()+1}/${l.getUTCDate()}`,tooltip:a?`Week of ${Le(l)}`:Le(l)}})}function so(t){const s=l=>{const y=new Date(l);return y.setMinutes(0,0,0),y.getTime()},a=new Map;for(const l of t)a.set(s(l),(a.get(s(l))??0)+1);const n=Math.min(...a.keys()),o=Math.max(...a.keys()),i=[];for(let l=n;l<=o;l+=we){const y=new Date(l);i.push({start:y,end:new Date(l+we),count:a.get(l)??0,label:lt(y,"HH:mm"),tooltip:lt(y,"MMM d, HH:mm")})}return i}function no({entityId:t,organizationId:s,ownerSlug:a,eventTimes:n,selectedRange:o,onSelectRange:i}){const{data:l,isLoading:y,error:d}=Zs(s,{entityId:t},{slug:a}),r=j.useMemo(()=>(l??[]).map(p=>{const v=gt(p.date);return v?{date:v,count:p.count}:null}).filter(p=>p!==null).sort((p,v)=>p.date.getTime()-v.date.getTime()),[l]),c=j.useMemo(()=>{if(r.length===0)return[];if(r.length>1)return to(r);const[p]=r,v=xt(p.date),k=(n??[]).map(gt).filter(x=>x!==null&&xt(x)===v);return k.length===p.count?so(k):[]},[r,n]),g=j.useCallback(p=>{const v=c[p.dataIndex];v&&i&&i(v.start,v.end)},[c,i]),u=j.useCallback(p=>{if(i&&p.startValue!==void 0&&p.endValue!==void 0){const v=new Date(p.startValue),k=new Date(p.endValue);i(v,k)}},[i]),f=j.useMemo(()=>{if(c.length<2)return null;let p;if(o){const[v,k]=o,x=c.filter(S=>S.start<k&&S.end>v);x.length>0&&(p=[[{xAxis:x[0].label},{xAxis:x[x.length-1].label}]])}return{tooltip:{trigger:"axis",axisPointer:{type:"line"},formatter:v=>{const k=v[0];return`${c[k.dataIndex]?.tooltip}: ${k.value} items`}},grid:{left:50,right:20,top:20,bottom:60},xAxis:{type:"category",boundaryGap:!1,data:c.map(v=>v.label)},yAxis:{type:"value",minInterval:1,splitLine:{lineStyle:{color:"rgba(0,0,0,0.05)"}}},dataZoom:[{type:"slider",start:0,end:100,height:20,bottom:10,borderColor:"transparent",backgroundColor:"rgba(0,0,0,0.02)",fillerColor:"rgba(99, 102, 241, 0.1)",handleStyle:{color:"#6366f1"}}],series:[{type:"line",smooth:!0,areaStyle:{opacity:.3,color:new An(0,0,0,1,[{offset:0,color:"rgba(99, 102, 241, 0.5)"},{offset:1,color:"rgba(99, 102, 241, 0.05)"}])},lineStyle:{width:2,color:"#6366f1"},itemStyle:{color:"#6366f1"},showSymbol:!1,data:c.map(v=>v.count),markLine:{silent:!0,symbol:"none",label:{position:"insideEndTop",formatter:"avg: {c}",fontSize:10,color:"#9ca3af"},lineStyle:{color:"#d1d5db",type:"dashed",width:1},data:[{type:"average",name:"Average"}]},markArea:p?{silent:!0,itemStyle:{color:"rgba(99, 102, 241, 0.1)"},data:p}:void 0}]}},[c,o]);if(y||d)return e.jsx("div",{className:ge(At,"p-4"),children:e.jsx("div",{className:"flex h-48 w-full items-center justify-center",children:y?e.jsx(Fn,{}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load timeline"})})});if(r.length===0)return null;if(!f){const[p]=r;return e.jsxs("p",{className:"text-xs text-muted-foreground",children:[p.count===1?"1 event":`All ${p.count} events`," on"," ",Le(p.date),"."]})}return e.jsx(oo,{option:f,onClick:g,onDataZoom:u})}function oo({option:t,onClick:s,onDataZoom:a}){const{chartRef:n,setOption:o}=Tn({onClick:s,onDataZoom:a});return j.useEffect(()=>{o(t,!0)},[t,o]),e.jsx("div",{"data-testid":"events-timeline",className:ge(At,"p-4 relative"),children:e.jsx("div",{ref:n,className:"h-48 w-full"})})}const ve={config:"Configuration",deployment:"Applies"};function ao({organizationId:t,ownerSlug:s,entityId:a,hideSourceFilter:n=!1,scopedEntityTypes:o,pinned:i,emptyState:l,toolbar:y=!1}){const{isAuthenticated:d,isReady:r}=Xs(),{isMember:c,isLoading:g}=Nt(),u=r&&d&&c,f=r&&(!d||!g&&!c),p=K(),v=$e(),k=Js(),{filters:x,updateFilters:S,clearFilters:w}=wt({parse:ye,serialize:Re,filterKeys:Ft,replace:!1,merge:Tt}),[F,I]=j.useState(x.searchQuery||""),[R,U]=j.useState(Fe(x)||n&&(a!=null||!!o?.length)),G=F.trim(),E=G.length>=3?G:void 0,N=St(E,1e3),T=j.useRef(!1);j.useEffect(()=>k.history.subscribe(({location:m,action:h})=>{const C=ye(new URLSearchParams(m.search)).searchQuery??"";!(h.type==="BACK"||h.type==="FORWARD"||h.type==="GO")&&T.current&&(C===(x.searchQuery??"")||C===(E??""))||(T.current=!1,I(C))}),[k.history,E,x.searchQuery]);const b=j.useMemo(()=>{const{afterOccurredAt:m,afterId:h,...C}=x;return dt({...C,...o?.length?{entityTypes:o}:{}})},[x,o]),P=S;j.useEffect(()=>{T.current&&(x.searchQuery||void 0)!==N&&S({searchQuery:N})},[N,S,x.searchQuery]);const Be=()=>{T.current=!1,I(""),n&&s?p({...Pe(s,v.search??{}),...a!==void 0&&!v.pathname.startsWith(`/${s}/events/`)?{to:v.pathname}:{}}):w()},se=Fe(dt(x)),ke=a===void 0,{data:Bt=[]}=en(r&&u?t:null),{data:Kt=[]}=tn(f?s:null),Ke=u?Bt:Kt,{data:Ge=[]}=sn(u&&t?{organizationId:t}:void 0),ne=wn(),oe=b.connectionIds,Ce=(oe?.length??0)>0,{data:Ve=[]}=nn(r&&u?t??"":"",{connectionIds:oe??void 0,enabled:!ne&&r&&u&&Ce}),Qe=b.feedIds,Se=(Qe?.length??0)>0,{data:Ue=[]}=_t(r&&u?t:null,{feedIds:Qe??void 0,enabled:r&&u&&Se}),We=j.useMemo(()=>ne?ne.groups.flatMap(m=>m.connections.map(h=>({id:h.id,display_name:h.display_name,connector_name:m.connector_name,connector_key:m.connector_key}))):Ve,[Ve,ne]),Ne=j.useMemo(()=>{const m=new Set(oe??[]);return[...new Set([...b.platforms??[],...We.filter(h=>m.has(h.id)).map(h=>h.connector_key)])]},[oe,We,b.platforms]),_e=j.useMemo(()=>Ue.map(m=>({connectorKey:m.connector_key,feedKey:m.feed_key})),[Ue]),Gt=j.useMemo(()=>Ce&&Ne.length===0||Se&&_e.length===0?[]:kn({connectors:Ke,entityTypes:Ge,selectedPlatforms:Ne,selectedFeeds:_e,selectedEntityTypes:b.entityTypes}),[Ke,b.entityTypes,Ce,Se,Ne,_e,Ge]),M=b.clientIds,ae=(M?.length??0)>0,{data:He=[]}=Sn(null,{enabled:r&&u&&ae}),ie=j.useMemo(()=>{if(!M)return[];const m=new Set(M);return _n(He).filter(h=>h.clientIds.some(C=>m.has(C)))},[M,He]),ze=j.useMemo(()=>{if(!ae||!M)return null;const m=ie.map(h=>h.title);return m.length>0?m.join(", "):M.length>1?`${M.length} client registrations`:"Client registration"},[ie,M,ae]),re=ie.length===1?ie[0]:null,Vt=s&&re?Dn(s,re.clientId):void 0,ce=b.mcpActivityId??null,{data:qe=[]}=Nn({enabled:r&&u&&ae&&!!ce,clientIds:M??[],limit:100}),Ye=j.useMemo(()=>{if(!ce)return null;const m=qe.find(C=>C.activityId===ce);if(!m)return"Selected conversation";const h=m.title?.trim();return h||(m.activityKind==="session"?"MCP session":m.clientId)},[ce,qe]),W=b.agentId,H=b.schedule,{data:Ze=[]}=Ln(W??void 0),Xe=j.useMemo(()=>!H||!W?null:Ze.find(h=>h.id===H)?.description?.trim()||"Scheduled task",[W,H,Ze]),{data:Qt}=on(r&&u?t:null,a),{data:Ut}=an(f&&!ke?s:null,a),Je=u?Qt:Ut,le=j.useMemo(()=>{const m=new Map;for(const h of Je||[]){const C=h.automation_name??"__global__";let _=m.get(C);_||(_={automationName:h.automation_name??null,classifiers:[]},m.set(C,_));const $=h.attribute_values||{},L=Object.keys($);let ue=null;const z={};for(const[q,B]of Object.entries($))if(B.parent)for(const[Ee,Y]of Object.entries(B.parent))ue=Ee,z[Y]||(z[Y]=[]),z[Y].push(q);const O=_.classifiers.find(q=>q.slug===h.slug);if(O){const q=new Set([...O.values,...L]);O.values=[...q];for(const[B,Ee]of Object.entries(z)){O.valuesByParentValue[B]||(O.valuesByParentValue[B]=[]);const Y=new Set([...O.valuesByParentValue[B],...Ee]);O.valuesByParentValue[B]=[...Y]}ue&&(O.parentSlug=ue)}else _.classifiers.push({slug:h.slug,name:h.name,values:L,parentSlug:ue,valuesByParentValue:z})}for(const h of m.values())h.classifiers.sort((C,_)=>C.parentSlug===null&&_.parentSlug!==null?-1:C.parentSlug!==null&&_.parentSlug===null?1:0);return[...m.values()]},[Je]),Wt=rn(r&&u?t:null,a,b,s),Ht=cn(f?s:null,a,b),zt=f?Ht:Wt,{data:Ie,isLoading:qt,error:Yt}=zt,Zt=j.useMemo(()=>Ie?.pages.flatMap(m=>m.content.map(h=>h.occurred_at)),[Ie]),et=Ie?.pages[0],Xt=(et?.content.length??0)>0,tt=le.some(m=>m.classifiers.length>0),Jt=ln(r&&u&&tt?t:null,a,b,s),es=dn(f&&tt?s:null,a,b),ts=(f?es:Jt).data?.classification_stats,ss=j.useCallback(()=>{P({beforeOccurredAt:void 0,beforeId:void 0,afterOccurredAt:void 0,afterId:void 0}),window.scrollTo({top:0,behavior:"smooth"})},[P]),ns=(m,h)=>{P({dateRange:[m,h]})},st=(m,h)=>{const C={...b.classificationFilters||{}};if(h.length>0)C[m]=h;else{delete C[m];for(const _ of le)for(const $ of _.classifiers)$.parentSlug===m&&delete C[$.slug]}P({classificationFilters:C})},os=(m,h)=>{const C=b.classificationFilters?.[m]||[];st(m,C.includes(h)?C.filter(_=>_!==h):[...C,h])},as=m=>st(m,[]);if(Yt)return e.jsx(un,{label:"knowledge"});const nt=!r||d&&g||u&&!t||qt,de={fields:[],chips:[]};for(const m of le)for(const h of m.classifiers){const C=b.classificationFilters?.[h.slug]??[],_=h.parentSlug?b.classificationFilters?.[h.parentSlug]??[]:void 0,$=_?[...new Set(_.flatMap(L=>h.valuesByParentValue[L]??[]))]:h.values;$.length>0&&de.fields.push({key:`clf:${h.slug}`,label:h.name,group:m.automationName??"Classifiers",icon:e.jsx(mn,{className:"h-4 w-4"}),editor:X({searchPlaceholder:`Search ${h.name.toLowerCase()}...`,options:$.map(L=>({value:L,label:L,count:ts?.[h.slug]?.[L]})),selected:C,multiple:!0,onSelect:L=>os(h.slug,L)})})}for(const[m,h]of Object.entries(b.classificationFilters??{})){if(h.length===0)continue;const C=le.flatMap(_=>_.classifiers).find(_=>_.slug===m);de.chips.push({id:`clf:${m}`,field:`clf:${m}`,label:C?.name??m,op:h.length>1?"is any of":"is",value:h.join(", "),onRemove:()=>as(m)})}const is=[b.contentIds?.length?me({id:"contentIds",label:b.contentIds.length>1?"Events":"Event",value:`#${b.contentIds.join(", #")}`,onRemove:()=>P({contentIds:void 0})}):null,Ye?me({id:"mcpActivityId",label:"Conversation",value:Ye,onRemove:()=>P({mcpActivityId:void 0})}):null,ze?me({id:"clientIds",label:"Connected app",value:ze,sourceLink:Vt,details:M&&M.length>0?e.jsx(Gn,{ownerSlug:s,clientIds:M,linkedUser:re?.linkedUser,linkedUserEntitySlug:re?.linkedUserEntitySlug}):void 0,onRemove:()=>P({clientIds:void 0})}):null,Xe?me({id:"schedule",label:"Schedule",value:Xe,sourceLink:s&&W&&H?Kn(s,W,H):void 0,onRemove:()=>P({schedule:void 0,runIds:void 0})}):null,...b.eventCategory?[ve[b.eventCategory]?{id:"event-category",label:ve[b.eventCategory],value:"",onRemove:()=>P({eventCategory:void 0,semanticTypes:void 0})}:{id:"event-category",label:"Category",op:"is",value:b.eventCategory,onRemove:()=>P({eventCategory:void 0})}]:[],...b.resourceKind||b.resourceId?[{id:"resource",label:"Resource",op:"is",value:`${b.resourceKind}: ${b.resourceId}`,onRemove:()=>P({resourceKind:void 0,resourceId:void 0})}]:[],...de.chips].filter(m=>m!=null),rs=!!(u&&a&&t),cs=se?null:i?.rows,ot={fields:[],chips:[]};if(ke&&u)for(const[m,h,C]of[["config",ve.config,kt],["deployment",ve.deployment,fn]]){const _=x.eventCategory===m;ot.fields.push({key:`category:${m}`,label:h,icon:e.jsx(C,{className:"h-4 w-4"}),editor:{kind:"toggle",checked:_,onToggle:()=>P({eventCategory:_?void 0:m,semanticTypes:_?void 0:[Mt],resourceKind:void 0,resourceId:void 0})}})}const at={quickFilters:ot,toolbar:y,filterTrailing:rs?e.jsxs(Rt,{variant:"ghost",size:"sm",className:"h-8 text-muted-foreground","aria-pressed":R,onClick:()=>U(m=>!m),children:[e.jsx(hn,{className:"mr-1.5 h-3.5 w-3.5"}),"Timeline"]}):void 0,onClearFilters:Be,filters:b,onFiltersChange:P,eventKinds:Gt,searchQuery:F,onSearchChange:m=>{T.current=!0,I(m)},extraFields:de.fields,drillChips:is},ls=!nt&&!!et&&!Xt&&!se,ds=d?u?"Activity is the workspace's live feed — every message, email, file, and record a connector pulls in lands here as an event. Connect your data to start collecting.":"Activity is the workspace's live feed of connector events. Join this workspace to add connectors and collect knowledge here.":"No public knowledge items are available yet",it=!!(u&&s);return e.jsx(pn,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:n?"sticky top-0 z-10 -mx-4 bg-background px-4 pb-2 lg:-mx-6 lg:px-6":void 0,children:n&&s?e.jsx(Dt,{...at,ownerSlug:s}):e.jsx(Ot,{...at})}),R&&u&&a&&t&&e.jsx(no,{entityId:a,organizationId:t,ownerSlug:s||"",eventTimes:Zt,selectedRange:b.dateRange||void 0,onSelectRange:ns}),i?.needsYou,cs,nt?e.jsx(En,{}):ls?l??e.jsx(ut,{icon:mt,title:"No activity yet",description:ds,actionLabel:it?"Add a connector":void 0,onAction:it&&s?()=>void p({to:"/$owner/connectors/create",params:{owner:s}}):void 0}):e.jsx(In,{organizationId:t,ownerSlug:s,entityId:a,filters:b,showEntityLinks:ke,groupStretches:!0,onGoToLatest:b.beforeOccurredAt?ss:void 0,hiddenPinned:i?.hidden,emptyState:e.jsx(ut,{icon:mt,title:"No results found",description:"Try adjusting your filters to find what you are looking for",actionLabel:se?"Clear filters":void 0,onAction:se?Be:void 0})})]})})}function io({record:t,ownerSlug:s}){const a=$e(),n=K(),{filters:o,updateFilters:i}=wt({parse:ye,serialize:Re,filterKeys:Ft,replace:!1,merge:Tt}),l=Fe({...o,platforms:void 0,connectionIds:void 0,feedIds:void 0})||o.sortBy!=null&&o.sortBy!=="date"||o.sortOrder!=null&&o.sortOrder!=="desc",y=()=>{n({...Pe(s,a.search??{}),...a.pathname.startsWith(`/${s}/events/`)?{}:{to:a.pathname}})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Dt,{ownerSlug:s,sourceRead:!0,filters:o,onFiltersChange:i,searchQuery:o.searchQuery??"",onSearchChange:d=>i({searchQuery:d}),onClearFilters:y}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Live activity supports connector, connection and feed filters. Search and other event filters are available for saved activity."}),l?e.jsxs("div",{role:"alert",className:"space-y-2 rounded-md border p-3 text-sm",children:[e.jsx("p",{children:"Some selected filters aren't supported for live activity. Clear them to see results."}),e.jsx(Rt,{variant:"outline",size:"sm",onClick:()=>{const d=Re({platforms:o.platforms,connectionIds:o.connectionIds,feedIds:o.feedIds}),r={...Pe(s,a.search??{}).search,...d};n({to:a.pathname,search:r})},children:"Clear unsupported filters"})]}):e.jsx(Cn,{record:t,orgContext:{slug:s},filters:o})]})}function So({entity:t,organizationId:s,ownerSlug:a}){const n=t.is_derived?e.jsx(io,{ownerSlug:a,record:{type:t.entity_type,key:t.slug}}):e.jsx(ao,{organizationId:s,ownerSlug:a,entityId:typeof t.id=="number"?t.id:void 0,hideSourceFilter:!0});return e.jsx(Pn,{organizationId:s,children:t.entity_type==="$member"?e.jsx(Rn,{children:n}):n})}export{ao as E,Pn as M,So as R};
2
- //# sourceMappingURL=record-activity-DnRVOrG2.js.map
@@ -1,2 +0,0 @@
1
- import{j as t,B as k,L as v,d9 as T,i as h,dB as D,dC as F,dD as M,hY as A,hZ as E,u as I,h_ as p,h$ as K,bf as y,bk as w,eW as P,r as x,aE as b,aF as N,aH as C,e_ as V,as as z,al as O,i0 as U,i1 as J,i2 as _,bg as W,C as Y,e7 as q}from"./index-DByaMzsG.js";import{R as G,a as H}from"./run-initiator-DhE5v4z0.js";function Q(e,s){switch(s.kind){case"connection":return E(e,s.id);case"feed":return A(e,s.id);case"run":return{to:"/$owner/events",params:{owner:e},search:{run_ids:String(s.id)}}}}function X({ownerSlug:e,scope:s,variant:i="outline",iconOnly:a=!1,label:o,className:c,title:n}){const l=Q(e,s),r=n??o??"View in memory",u=t.jsx(k,{asChild:!0,variant:i,size:a?"icon":"sm",className:h(a&&"h-7 w-7",c),children:t.jsxs(v,{to:l.to,params:l.params,search:l.search,children:[t.jsx(T,{className:h("h-3.5 w-3.5",!a&&"mr-1.5")}),!a&&(o??"View in memory")]})});return a?t.jsxs(D,{children:[t.jsx(F,{asChild:!0,children:u}),t.jsx(M,{children:r})]}):u}function Z({status:e}){return e==="completed"?t.jsx(V,{className:"h-4 w-4 text-green-500"}):e==="failed"?t.jsx(z,{className:"h-4 w-4 text-destructive"}):e==="running"?t.jsx(O,{className:"text-blue-500"}):t.jsx(U,{className:"h-4 w-4 text-muted-foreground"})}const ee={completed:"Completed",failed:"Failed",running:"Running",pending:"Queued",claimed:"Starting",timeout:"Timed out",cancelled:"Cancelled"};function $(e){const s=e.split("_").join(" ");return s.charAt(0).toUpperCase()+s.slice(1)}function te({error:e}){const[s,i]=x.useState(!1);return e.length<=80?t.jsx("span",{className:"text-destructive",children:e}):t.jsxs(b,{open:s,onOpenChange:i,children:[t.jsx(N,{asChild:!0,children:t.jsx("button",{type:"button",className:"text-left text-destructive hover:underline",children:e})}),t.jsx(C,{className:"max-h-64 w-96 overflow-auto",children:t.jsx("pre",{className:"whitespace-pre-wrap break-words text-xs text-destructive",children:e})})]})}function se({checkpoint:e}){return t.jsxs(b,{children:[t.jsx(N,{asChild:!0,children:t.jsx(k,{variant:"ghost",size:"icon",title:"Checkpoint","aria-label":"Checkpoint",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(J,{className:"h-4 w-4","aria-hidden":"true"})})}),t.jsx(C,{className:"max-h-64 w-80 overflow-auto",children:t.jsx("pre",{className:"whitespace-pre-wrap break-words text-xs",children:JSON.stringify(e,null,2)})})]})}function R(e){if(e.initiator_kind)return{kind:e.initiator_kind,...e.initiator_ref};if(e.automation_id)return{kind:"automation",automation_id:e.automation_id};if(e.created_by_user_id)return{kind:"user",user_id:e.created_by_user_id}}function ie({run:e,ownerSlug:s}){const i=R(e);return i?i.kind==="system"?t.jsx(t.Fragment,{children:"by the system"}):t.jsxs(t.Fragment,{children:["by"," ",t.jsx(G,{ownerSlug:s,initiator:i,clientName:void 0,fallback:"a person"})]}):null}function ne({parts:e}){return t.jsx(t.Fragment,{children:e.map(([s,i],a)=>t.jsxs(x.Fragment,{children:[a>0?" · ":"",i]},s))})}function j(e,s){return[e.run_type?$(e.run_type):"Run",s.connection?e.connection_display_name:null,s.feed?e.feed_display_name??e.feed_key:null].filter(Boolean).join(" · ")}const ae=3;function g(e,s){const i=p(e.created_at);return e.status==="completed"&&i!=null?`${j(e,s)}|${q(i,"yyyy-MM-dd")}`:null}function re(e,s){const i=new Map;for(const c of e){const n=g(c,s);n&&i.set(n,[...i.get(n)??[],c])}const a=[],o=new Set;for(const c of e){const n=g(c,s),l=n?i.get(n):void 0;!n||!l||l.length<ae?a.push({kind:"run",run:c}):o.has(n)||(o.add(n),a.push({kind:"group",name:j(c,s),runs:l}))}return a}function oe({name:e,runs:s,ownerSlug:i,columns:a}){const[o,c]=x.useState(!1),n=p(s[0].created_at),l=p(s[s.length-1].created_at),r=Date.now(),u=s.reduce((m,S)=>m+(S.items_collected??0),0),d=l!=null?_(l,r):null,f=n!=null?_(n,r):null,B=d&&f&&d!==f?`${d}–${f}`:f;return t.jsxs("div",{children:[t.jsx("button",{type:"button","aria-expanded":o,onClick:()=>c(m=>!m),className:h(w,"rounded-lg transition-colors hover:bg-accent/40"),children:t.jsx(y,{mark:t.jsx(Y,{"aria-hidden":"true",className:h("h-4 w-4 text-muted-foreground transition-transform",o&&"rotate-90")}),name:e,details:t.jsx(W,{parts:[`${s.length} runs`,B,"all completed",u>0?`${u} ${u===1?"item":"items"}`:null]}),at:n})}),o?t.jsx("div",{className:"ml-6 border-l pl-2",children:s.map(m=>t.jsx("div",{className:"mb-1",children:t.jsx(L,{run:m,ownerSlug:i,columns:a})},m.id))}):null]})}function L({run:e,ownerSlug:s,columns:i={}}){const a=I(),o=p(e.created_at),c=p(e.completed_at),n=o!=null&&c!=null?Math.round((c-o)/1e3):null,l=j(e,i),r=i.startedBy&&R(e)?t.jsx(ie,{run:e,ownerSlug:s}):null,u=[["status",ee[e.status]??$(e.status)],e.error_message?["error",t.jsx(te,{error:e.error_message},"error")]:null,e.items_collected!=null&&(e.run_type==="sync"||e.items_collected>0)?["items",`${e.items_collected} ${e.items_collected===1?"item":"items"}`]:null,n!=null?["duration",K(n)]:null,r?["by",r]:null,e.connector_version?["version",`v${e.connector_version}`]:null,["id",`#${e.id}`]].filter(d=>d!==null);return t.jsxs("article",{"aria-label":`Run #${e.id}`,title:P(e.created_at),className:"group relative flex items-center rounded-lg transition-colors hover:bg-accent/40",children:[t.jsx("div",{className:h(w,"min-w-0 flex-1"),children:t.jsx(y,{mark:t.jsx(Z,{status:e.status}),name:t.jsx(v,{to:"/$owner/events",params:{owner:s},search:{run_ids:String(e.id)},"aria-label":`${l} · Run #${e.id}`,className:"hover:underline",onClick:d=>{!a||d.button!==0||d.metaKey||d.ctrlKey||d.shiftKey||d.altKey||(d.preventDefault(),a.open({href:e.run_type==="automation"&&e.automation_id!=null?`/${s}/automations/${e.automation_id}?view=activity&run_id=${e.id}`:`/${s}/events?run_ids=${e.id}`,title:`Run #${e.id}`,runId:e.id}))},children:l}),tone:e.status==="failed"||e.status==="timeout"?"destructive":null,details:t.jsx(ne,{parts:u}),at:o,atClassName:"group-hover:invisible group-focus-within:invisible"})}),t.jsxs("div",{className:"absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100",children:[e.checkpoint?t.jsx(se,{checkpoint:e.checkpoint}):null,t.jsx(X,{ownerSlug:s,scope:{kind:"run",id:e.id},variant:"ghost",iconOnly:!0,title:"View events from this run"})]})]})}function de({runs:e,ownerSlug:s,columns:i={},emptyState:a,hasNextPage:o=!1,isFetching:c=!1,isFetchingNextPage:n=!1,onLoadMore:l=()=>{}}){return t.jsx(H,{items:re(e,i).map(r=>r.kind==="run"?{key:String(r.run.id),occurredAt:r.run.created_at,content:t.jsx(L,{run:r.run,ownerSlug:s,columns:i})}:{key:`group:${r.runs[0].id}`,occurredAt:r.runs[0].created_at,content:t.jsx(oe,{name:r.name,runs:r.runs,ownerSlug:s,columns:i})}),isLoading:!1,emptyState:a,hasNextPage:o,isFetching:c,isFetchingNextPage:n,onLoadMore:l})}export{L as R,X as V,de as a};
2
- //# sourceMappingURL=runs-list-CwtH-wmk.js.map
@@ -1,2 +0,0 @@
1
- import{fF as o}from"./index-DByaMzsG.js";function f(s,a,r){return o(s,-a,r)}export{f as s};
2
- //# sourceMappingURL=subDays-D8nHthaS.js.map