@lobu/runtime-server 24.6.0 → 24.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/owletto/dist/assets/_-CZgmjLR9.js +2 -0
  3. package/dist/owletto/dist/assets/_-Cm5OgtYD.js +3 -0
  4. package/dist/owletto/dist/assets/_agentId-Cci6NFc1.js +2 -0
  5. package/dist/owletto/dist/assets/_agentId-GhWTlPO2.js +2 -0
  6. package/dist/owletto/dist/assets/_automationId-KUlxSTK2.js +2 -0
  7. package/dist/owletto/dist/assets/_connectorKey._connectionId-Zpy7Hvml.js +2 -0
  8. package/dist/owletto/dist/assets/_connectorKey.index-CYDRp9UX.js +2 -0
  9. package/dist/owletto/dist/assets/_conversationId-NNqDdije.js +2 -0
  10. package/dist/owletto/dist/assets/_eventId-0BSX6VHj.js +2 -0
  11. package/dist/owletto/dist/assets/_owner-C-CD22NB.js +3 -0
  12. package/dist/owletto/dist/assets/_shape-CvXp4omb.js +2 -0
  13. package/dist/owletto/dist/assets/_slug-DgK7zpKA.js +2 -0
  14. package/dist/owletto/dist/assets/_viewKey-cH54P0zY.js +2 -0
  15. package/dist/owletto/dist/assets/_viewKey-m0B5j7L9.js +2 -0
  16. package/dist/owletto/dist/assets/{accept-invitation-CQZQ0wwC.js → accept-invitation-CX7Egv-p.js} +2 -2
  17. package/dist/owletto/dist/assets/activity-link-rXNpmppV.js +2 -0
  18. package/dist/owletto/dist/assets/activity-route-view-B0m7_g9q.js +2 -0
  19. package/dist/owletto/dist/assets/{agent-client-setup-list-CpUTAjXf.js → agent-client-setup-list-BmD3-_Ox.js} +2 -2
  20. package/dist/owletto/dist/assets/{agent-connect-pages-Br_ycC0z.js → agent-connect-pages-BtOTCsTU.js} +2 -2
  21. package/dist/owletto/dist/assets/agent-editor-form-CirqCpcM.js +2 -0
  22. package/dist/owletto/dist/assets/agent-list-row-SyACVYX7.js +2 -0
  23. package/dist/owletto/dist/assets/{agent-loading-shells-_18OREnx.js → agent-loading-shells-DHvKiEUB.js} +2 -2
  24. package/dist/owletto/dist/assets/agent-permissions-matrix-Dsc26dyW.js +2 -0
  25. package/dist/owletto/dist/assets/{agent-skill-context-1DBn7Xc_.js → agent-skill-context-DF5q0Dfr.js} +2 -2
  26. package/dist/owletto/dist/assets/agent-subpage-shell-Pi5cECga.js +2 -0
  27. package/dist/owletto/dist/assets/{agent-thread-FyEO-y44.js → agent-thread-B1ZepGZc.js} +4 -4
  28. package/dist/owletto/dist/assets/agents-D1FHZ0jR.js +2 -0
  29. package/dist/owletto/dist/assets/app._appId-01I0CJal.js +2 -0
  30. package/dist/owletto/dist/assets/{assist-composer-Mn9EfX4X.js → assist-composer-BD9msDk3.js} +2 -2
  31. package/dist/owletto/dist/assets/automation-detail-content-BFv1TglZ.js +2 -0
  32. package/dist/owletto/dist/assets/automation-row-CmTpAD4r.js +2 -0
  33. package/dist/owletto/dist/assets/{automation-source-list-Dhucq1sI.js → automation-source-list-D8ZSavQU.js} +2 -2
  34. package/dist/owletto/dist/assets/automations-D1FHZ0jR.js +2 -0
  35. package/dist/owletto/dist/assets/{callback-9xSHyA12.js → callback-Ckrxv0eo.js} +2 -2
  36. package/dist/owletto/dist/assets/{card-g4yxo4Hr.js → card-DT9mSjSp.js} +2 -2
  37. package/dist/owletto/dist/assets/{change-summary-DeuXQEpb.js → change-summary-CGrKEJ04.js} +2 -2
  38. package/dist/owletto/dist/assets/{claim-B98IhDra.js → claim-Bzby28tT.js} +2 -2
  39. package/dist/owletto/dist/assets/{client-activity-scopes-BD2HBo-_.js → client-activity-scopes-DoIErdUy.js} +2 -2
  40. package/dist/owletto/dist/assets/{client-rows-x_CxeWkP.js → client-rows-BbVQy5Ti.js} +2 -2
  41. package/dist/owletto/dist/assets/{clients-Cmp0LmOp.js → clients-6aJvabvS.js} +2 -2
  42. package/dist/owletto/dist/assets/connect-BmDziBzI.js +2 -0
  43. package/dist/owletto/dist/assets/{connect-menu-CezOH3s7.js → connect-menu-Bs8mxsga.js} +2 -2
  44. package/dist/owletto/dist/assets/connect._clientId-t5aKu3aa.js +2 -0
  45. package/dist/owletto/dist/assets/connected._clientId-DswMAw8l.js +2 -0
  46. package/dist/owletto/dist/assets/{connection-B6fM2KHN.js → connection-BOaMa324.js} +2 -2
  47. package/dist/owletto/dist/assets/connection-feed-detail-BLCjhP-H.js +2 -0
  48. package/dist/owletto/dist/assets/connector-boxes-BAP_f77M.js +2 -0
  49. package/dist/owletto/dist/assets/{connector-page-shell-Di6XzkVo.js → connector-page-shell-ClOmVPJr.js} +2 -2
  50. package/dist/owletto/dist/assets/{connector-provenance-BrnasBW4.js → connector-provenance-wmYu5jwO.js} +2 -2
  51. package/dist/owletto/dist/assets/{connectors-DnOUxX_U.js → connectors-D5F5rHxX.js} +2 -2
  52. package/dist/owletto/dist/assets/{consent-Byli4yMs.js → consent-RqHNkmm8.js} +2 -2
  53. package/dist/owletto/dist/assets/{copy-button-Ddf7lBjZ.js → copy-button-D6zpsZLi.js} +2 -2
  54. package/dist/owletto/dist/assets/{core.esm-BsXtvNoI.js → core.esm-BIE97rfo.js} +3 -3
  55. package/dist/owletto/dist/assets/create-BPxsKwk7.js +2 -0
  56. package/dist/owletto/dist/assets/{create-YdAnh3ml.js → create-GT8_yF0R.js} +2 -2
  57. package/dist/owletto/dist/assets/create-Yx2qBMBy.js +2 -0
  58. package/dist/owletto/dist/assets/create-automation-form-B12yTrmj.js +3 -0
  59. package/dist/owletto/dist/assets/create._connectorKey-CzXqSkuI.js +2 -0
  60. package/dist/owletto/dist/assets/custom-guardrail-edits-B9plaLBN.js +2 -0
  61. package/dist/owletto/dist/assets/{definition-comparison-B5WgZILB.js → definition-comparison-C3k6Wa9B.js} +2 -2
  62. package/dist/owletto/dist/assets/detail-page-skeleton-I5_7FkKx.js +2 -0
  63. package/dist/owletto/dist/assets/{device-DdCoCj-Q.js → device-CadaiNF4.js} +2 -2
  64. package/dist/owletto/dist/assets/device-automation-Dp3faMvp.js +2 -0
  65. package/dist/owletto/dist/assets/device-pin-tombstone-U7Bx05P6.js +2 -0
  66. package/dist/owletto/dist/assets/device._deviceId-DTZqj1HS.js +2 -0
  67. package/dist/owletto/dist/assets/dynamic-schema-form-DyT_9iVE.js +2 -0
  68. package/dist/owletto/dist/assets/entity-options-CGTjLlcS.js +2 -0
  69. package/dist/owletto/dist/assets/entity-page-DHHMmA8V.js +2 -0
  70. package/dist/owletto/dist/assets/entity-pages-eYbG2FDT.js +2 -0
  71. package/dist/owletto/dist/assets/{entity-type-page-D0ghgRgq.js → entity-type-page-CjFqxSdL.js} +2 -2
  72. package/dist/owletto/dist/assets/event-card-BtTUuf2q.js +2 -0
  73. package/dist/owletto/dist/assets/event-detail-8xHiplt_.js +2 -0
  74. package/dist/owletto/dist/assets/events-feed-zFnTSE27.js +2 -0
  75. package/dist/owletto/dist/assets/filter-editors-Dd5R2Etd.js +2 -0
  76. package/dist/owletto/dist/assets/{full-page-spinner-B5xXnKtV.js → full-page-spinner-CCU4PkRv.js} +2 -2
  77. package/dist/owletto/dist/assets/home-stream-IVsNEkwp.js +2 -0
  78. package/dist/owletto/dist/assets/index-2oaMOFKe.js +2 -0
  79. package/dist/owletto/dist/assets/index-B-Ab8srM.js +7899 -0
  80. package/dist/owletto/dist/assets/index-B4RZgvvI.js +2 -0
  81. package/dist/owletto/dist/assets/{index-BDl1_w6U.js → index-B72KYdN1.js} +2 -2
  82. package/dist/owletto/dist/assets/index-BBZM53p8.js +2 -0
  83. package/dist/owletto/dist/assets/index-BOb0a5f9.js +2 -0
  84. package/dist/owletto/dist/assets/{index-BdNR51Ua.js → index-BYFDMIQC.js} +2 -2
  85. package/dist/owletto/dist/assets/index-BwnFQcMe.js +2 -0
  86. package/dist/owletto/dist/assets/index-CvYsWYlF.js +2 -0
  87. package/dist/owletto/dist/assets/{index-CkiyxW4w.js → index-DIXIvtnM.js} +2 -2
  88. package/dist/owletto/dist/assets/index-DLwokXHW.js +2 -0
  89. package/dist/owletto/dist/assets/index-_nlPHus1.js +2 -0
  90. package/dist/owletto/dist/assets/index-cwOgj4-i.js +2 -0
  91. package/dist/owletto/dist/assets/{index-TkPy_P_u.js → index-pmr1WUoG.js} +2 -2
  92. package/dist/owletto/dist/assets/index-pp4qmhkA.js +2 -0
  93. package/dist/owletto/dist/assets/index-tTbno-PX.css +1 -0
  94. package/dist/owletto/dist/assets/{json-diff-DtZtra_g.js → json-diff-B-1Swv_y.js} +2 -2
  95. package/dist/owletto/dist/assets/list-skeleton-BAqT0vxo.js +2 -0
  96. package/dist/owletto/dist/assets/{login-TWR0vF4_.js → login-D5bIjMtf.js} +2 -2
  97. package/dist/owletto/dist/assets/{logout-BA5kojS0.js → logout-JYZvxz8v.js} +2 -2
  98. package/dist/owletto/dist/assets/{member-scope-gate-BQiRAqtx.js → member-scope-gate-Lj9m4RL2.js} +2 -2
  99. package/dist/owletto/dist/assets/memory-browse-page-rAKfVdQ_.js +74 -0
  100. package/dist/owletto/dist/assets/{model-selector-B2cjCn0V.js → model-selector-onvGA9Ww.js} +2 -2
  101. package/dist/owletto/dist/assets/{new-Dc5Bbotb.js → new-B-Jd-vBl.js} +2 -2
  102. package/dist/owletto/dist/assets/new-BmehH1uR.js +2 -0
  103. package/dist/owletto/dist/assets/new-KDi15LWZ.js +2 -0
  104. package/dist/owletto/dist/assets/{organization-B9U1L-56.js → organization-B9bh20Xo.js} +2 -2
  105. package/dist/owletto/dist/assets/peek-pane-content-Bqus80Mq.js +2 -0
  106. package/dist/owletto/dist/assets/{pending-seed-BP3xHM2d.js → pending-seed-CoFPQ835.js} +2 -2
  107. package/dist/owletto/dist/assets/{proposal-review-shell-BED-DO9C.js → proposal-review-shell-CnACXCUg.js} +2 -2
  108. package/dist/owletto/dist/assets/public-shell-ready-Dlh-eWz0.js +2 -0
  109. package/dist/owletto/dist/assets/record-activity-6CfR95Ul.js +2 -0
  110. package/dist/owletto/dist/assets/{record-session-DOFgdd43.js → record-session-Bpx4_LGk.js} +2 -2
  111. package/dist/owletto/dist/assets/{renderer-CHPS-1vD.js → renderer-CgaQKMoG.js} +26 -26
  112. package/dist/owletto/dist/assets/{reset-password-BmNM-apc.js → reset-password-C-4Jnuqk.js} +2 -2
  113. package/dist/owletto/dist/assets/run-initiator-BvruBM5H.js +2 -0
  114. package/dist/owletto/dist/assets/{runs-BntGAKQG.js → runs-BMzp7j7j.js} +2 -2
  115. package/dist/owletto/dist/assets/runs-list-DVhrTr3v.js +2 -0
  116. package/dist/owletto/dist/assets/{schema-type-editor-panel-v3nR2Oa2.js → schema-type-editor-panel-Bdeumkux.js} +2 -2
  117. package/dist/owletto/dist/assets/{schema-value-BFb7jCBo.js → schema-value-BUgC0Ro8.js} +2 -2
  118. package/dist/owletto/dist/assets/{settings-DubSpJfg.js → settings-DYYvrrZ4.js} +2 -2
  119. package/dist/owletto/dist/assets/skill-route-key-sF006xiz.js +2 -0
  120. package/dist/owletto/dist/assets/source-record-panels-CBV9tsR3.js +2 -0
  121. package/dist/owletto/dist/assets/status-variants-DT61YfsU.js +2 -0
  122. package/dist/owletto/dist/assets/{table-DALHuXPE.js → table-B6yimlsZ.js} +2 -2
  123. package/dist/owletto/dist/assets/{use-automations-D9hKpufo.js → use-automations-II_YJWtN.js} +2 -2
  124. package/dist/owletto/dist/assets/{use-login-redirect-ciwfc-7A.js → use-login-redirect-BqtEilid.js} +2 -2
  125. package/dist/owletto/dist/assets/{use-mention-search-CJGCatFS.js → use-mention-search-Bxlpd6Dp.js} +3 -3
  126. package/dist/owletto/dist/assets/view-param-filters-DYlqBocg.js +2 -0
  127. package/dist/owletto/dist/assets/{views-access-required-CZ1fvAks.js → views-access-required-BVtMfgLh.js} +2 -2
  128. package/dist/owletto/dist/index.html +2 -2
  129. package/dist/server-main.bundle.mjs +84 -5
  130. package/npm-shrinkwrap.json +5 -5
  131. package/package.json +1 -1
  132. package/vendor/connector-sdk/package.json +1 -1
  133. package/vendor/core/package.json +1 -1
  134. package/vendor/views/package.json +1 -1
  135. package/dist/owletto/dist/assets/_-DT3E3BmS.js +0 -3
  136. package/dist/owletto/dist/assets/_-c1xy7bLu.js +0 -2
  137. package/dist/owletto/dist/assets/_agentId-CTfoi0-7.js +0 -2
  138. package/dist/owletto/dist/assets/_agentId-DV8utajn.js +0 -2
  139. package/dist/owletto/dist/assets/_automationId-DvP3qyYL.js +0 -2
  140. package/dist/owletto/dist/assets/_connectorKey._connectionId-CL5SivCn.js +0 -2
  141. package/dist/owletto/dist/assets/_connectorKey.index-tnMwC67b.js +0 -2
  142. package/dist/owletto/dist/assets/_conversationId-DXN_8m88.js +0 -2
  143. package/dist/owletto/dist/assets/_eventId-SdpFT7jB.js +0 -2
  144. package/dist/owletto/dist/assets/_name-CM1AMywz.js +0 -2
  145. package/dist/owletto/dist/assets/_owner-CaGsXXBW.js +0 -3
  146. package/dist/owletto/dist/assets/_shape-DGAkETDp.js +0 -2
  147. package/dist/owletto/dist/assets/_skillKey-Dd4ZHPY8.js +0 -2
  148. package/dist/owletto/dist/assets/_slug-cRvJQtNo.js +0 -2
  149. package/dist/owletto/dist/assets/_view-B5I7mmkl.js +0 -2
  150. package/dist/owletto/dist/assets/_viewKey-Bwn0dyLo.js +0 -2
  151. package/dist/owletto/dist/assets/_viewKey-YjSYD0wc.js +0 -2
  152. package/dist/owletto/dist/assets/activity-route-view-CZykJXQp.js +0 -2
  153. package/dist/owletto/dist/assets/agent-card-controls-DuQJhtqp.js +0 -2
  154. package/dist/owletto/dist/assets/agent-editor-form-BXQBFHSv.js +0 -2
  155. package/dist/owletto/dist/assets/agent-guardrails-route-CN7vpC0X.js +0 -2
  156. package/dist/owletto/dist/assets/agent-list-row-BnP6r4pm.js +0 -2
  157. package/dist/owletto/dist/assets/agent-permissions-matrix-DSjidWHL.js +0 -2
  158. package/dist/owletto/dist/assets/agent-skills-route-d5jh3oBR.js +0 -2
  159. package/dist/owletto/dist/assets/agent-tab-intro-DKrC3SQt.js +0 -2
  160. package/dist/owletto/dist/assets/agents-kXojozTU.js +0 -2
  161. package/dist/owletto/dist/assets/agents-workbench-CDpJmUVN.js +0 -2
  162. package/dist/owletto/dist/assets/app._appId-DwNeXRJp.js +0 -2
  163. package/dist/owletto/dist/assets/automation-detail-content-Bs3vwAPd.js +0 -2
  164. package/dist/owletto/dist/assets/automation-row-B5Q1B10y.js +0 -2
  165. package/dist/owletto/dist/assets/automations-kXojozTU.js +0 -2
  166. package/dist/owletto/dist/assets/connect-zUot_0kG.js +0 -2
  167. package/dist/owletto/dist/assets/connect._clientId-nsGxe6yO.js +0 -2
  168. package/dist/owletto/dist/assets/connected._clientId-DnclRRXk.js +0 -2
  169. package/dist/owletto/dist/assets/connected._clientId.activity-CDB8atTX.js +0 -2
  170. package/dist/owletto/dist/assets/connected._clientId.index-DBNP2mZo.js +0 -2
  171. package/dist/owletto/dist/assets/connection-feed-detail-Ckq-qEbD.js +0 -2
  172. package/dist/owletto/dist/assets/connection-label-BobuYiAG.js +0 -2
  173. package/dist/owletto/dist/assets/connections-browser-BXsJqieG.js +0 -2
  174. package/dist/owletto/dist/assets/connector-boxes-CbqSFeVm.js +0 -2
  175. package/dist/owletto/dist/assets/connector-scope-lists-dQnZARCD.js +0 -2
  176. package/dist/owletto/dist/assets/create-B34eskZ_.js +0 -2
  177. package/dist/owletto/dist/assets/create-DLB9sXgU.js +0 -2
  178. package/dist/owletto/dist/assets/create-automation-form-C9PMX7N8.js +0 -3
  179. package/dist/owletto/dist/assets/create._connectorKey-Bz4OYRiC.js +0 -2
  180. package/dist/owletto/dist/assets/device-pin-tombstone-B06J7Af1.js +0 -2
  181. package/dist/owletto/dist/assets/device._deviceId-Bh9S4bFp.js +0 -2
  182. package/dist/owletto/dist/assets/dynamic-schema-form-qWSRtOAv.js +0 -2
  183. package/dist/owletto/dist/assets/entity-options-BkU_En_f.js +0 -2
  184. package/dist/owletto/dist/assets/entity-page-BPFDHY8q.js +0 -2
  185. package/dist/owletto/dist/assets/entity-pages-DxgbjLMt.js +0 -2
  186. package/dist/owletto/dist/assets/event-card-CjA_dLzq.js +0 -2
  187. package/dist/owletto/dist/assets/event-detail-CmC-DVrK.js +0 -2
  188. package/dist/owletto/dist/assets/events-feed-CGzA1w3R.js +0 -2
  189. package/dist/owletto/dist/assets/filter-bar-CQ_oE7a9.js +0 -2
  190. package/dist/owletto/dist/assets/guardrails-DkXatmea.js +0 -2
  191. package/dist/owletto/dist/assets/identity-BwJy3ixB.js +0 -2
  192. package/dist/owletto/dist/assets/index-35ehGReZ.js +0 -2
  193. package/dist/owletto/dist/assets/index-B9hYiwBw.js +0 -2
  194. package/dist/owletto/dist/assets/index-BjcZVe7n.js +0 -7899
  195. package/dist/owletto/dist/assets/index-BqAVebvY.js +0 -2
  196. package/dist/owletto/dist/assets/index-BvK1fS1J.js +0 -2
  197. package/dist/owletto/dist/assets/index-CNEpTkgw.css +0 -1
  198. package/dist/owletto/dist/assets/index-CRc73k1t.js +0 -2
  199. package/dist/owletto/dist/assets/index-CYGaSD3y.js +0 -2
  200. package/dist/owletto/dist/assets/index-CfZGe-zn.js +0 -2
  201. package/dist/owletto/dist/assets/index-CzLDNB2E.js +0 -2
  202. package/dist/owletto/dist/assets/index-D-o5iOVd.js +0 -2
  203. package/dist/owletto/dist/assets/index-DjYVV1Ml.js +0 -2
  204. package/dist/owletto/dist/assets/index-VyAX-asP.js +0 -2
  205. package/dist/owletto/dist/assets/list-skeleton-CIHWCi2a.js +0 -2
  206. package/dist/owletto/dist/assets/manage-gear-C-0BAMbC.js +0 -2
  207. package/dist/owletto/dist/assets/memory-browse-page-Ba32-vVL.js +0 -74
  208. package/dist/owletto/dist/assets/model-C2q7WDcS.js +0 -2
  209. package/dist/owletto/dist/assets/models-CZkH5gtj.js +0 -2
  210. package/dist/owletto/dist/assets/nav-pill-Bam6s3jj.js +0 -2
  211. package/dist/owletto/dist/assets/new-BJst6K0b.js +0 -2
  212. package/dist/owletto/dist/assets/new-DgbivfDe.js +0 -2
  213. package/dist/owletto/dist/assets/peek-pane-content-Cq8P38s3.js +0 -2
  214. package/dist/owletto/dist/assets/permissions-BVlbeY4u.js +0 -2
  215. package/dist/owletto/dist/assets/public-shell-ready-Diq15_QW.js +0 -2
  216. package/dist/owletto/dist/assets/record-activity-CTLwq8s1.js +0 -2
  217. package/dist/owletto/dist/assets/run-activity-link-Dh1YyCfk.js +0 -2
  218. package/dist/owletto/dist/assets/run-initiator-CCxNv0rK.js +0 -2
  219. package/dist/owletto/dist/assets/runs-panel-BwTVaRsE.js +0 -2
  220. package/dist/owletto/dist/assets/runs-table-CYS1jDdL.js +0 -2
  221. package/dist/owletto/dist/assets/settings-DBgT60nY.js +0 -2
  222. package/dist/owletto/dist/assets/skills-DDoeRGhJ.js +0 -2
  223. package/dist/owletto/dist/assets/source-record-panels-m8gECt82.js +0 -2
  224. package/dist/owletto/dist/assets/status-dot-BnQPFrcU.js +0 -2
  225. package/dist/owletto/dist/assets/use-scroll-sentinel-BWCrmNIB.js +0 -2
  226. package/dist/owletto/dist/assets/view-param-filters-CDvwie_f.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{r as x,j as e,bC as ue,i as V,dM as me,dO as xe,B as P,fQ as he,dN as pe,db as ge,eL as ne,fO as T,f3 as fe,cV as O,V as Z,L as A,dY as je,b as ve,S as E}from"./index-B-Ab8srM.js";import{p as S,n as be,e as re,b as ye,g as Ne,f as q,R as we,c as _e}from"./renderer-CgaQKMoG.js";import{S as H}from"./schema-value-BUgC0Ro8.js";import{T as Se,a as ke,b as B,c as J,d as Ce,e as K}from"./table-B6yimlsZ.js";var Ee="Separator",ee="horizontal",Le=["horizontal","vertical"],ae=x.forwardRef((t,s)=>{const{decorative:n,orientation:a=ee,...l}=t,o=Re(a)?a:ee,h=n?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return e.jsx(ue.div,{"data-orientation":o,...h,...l,ref:s})});ae.displayName=Ee;function Re(t){return Le.includes(t)}var oe=ae;const Me=x.forwardRef(({className:t,orientation:s="horizontal",decorative:n=!0,...a},l)=>e.jsx(oe,{ref:l,decorative:n,orientation:s,className:V("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...a}));Me.displayName=oe.displayName;function Ae({choices:t,visible:s,onChange:n}){return e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:e.jsx(he,{className:"h-4 w-4"})})}),e.jsxs(pe,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),t.map(a=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[e.jsx("input",{type:"checkbox",checked:!s||s.includes(a.field),onChange:l=>{const o=s??t.map(c=>c.field);n(l.target.checked?[...o,a.field]:o.filter(c=>c!==a.field))}}),a.label]},a.field))]})]})}function Oe({direction:t}){return t?e.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:t==="asc"?"Sort ascending":"Sort descending"}),t==="asc"?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):e.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:"Sort"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function te(t,s){const n=t?.properties;if(n)return Object.entries(n).find(([,a])=>a[s])?.[0]}function Pe(t){const s=t.trim(),n=s.split(/[\s._@/-]+/).filter(Boolean),a=n.length>=2?`${n[0][0]}${n[1][0]}`:(n[0]??s).slice(0,2);let l=0;for(let o=0;o<s.length;o++)l=l*31+s.charCodeAt(o)>>>0;return{initials:a.toUpperCase()||"?",hue:l%360}}function Te(t){const[s,n]=x.useState();return x.useEffect(()=>{if(!t||!globalThis.crypto?.subtle){n(void 0);return}let a=!1;const l=t.trim().toLowerCase();return crypto.subtle.digest("SHA-256",new TextEncoder().encode(l)).then(o=>{a||n(Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join(""))}),()=>{a=!0}},[t]),s?`https://www.gravatar.com/avatar/${s}?d=identicon&s=80`:void 0}function le({metadata:t,metadataSchema:s,name:n,typeIcon:a,className:l="h-6 w-6",iconClassName:o="h-5 w-5",initialsFallback:c=!1}){const h=te(s,"x-image"),j=te(s,"x-email"),y=h&&t?.[h]||void 0,v=j&&t?.[j]||void 0,N=Te(y?void 0:v),w=y||N,[k,L]=x.useState(!1);if(x.useEffect(()=>{L(!1)},[w]),w&&!k)return e.jsx("img",{src:w,alt:n,referrerPolicy:"no-referrer",onError:()=>L(!0),className:V("rounded-full object-cover border border-border",l)});if(c){const R=n.trim()||v||Fe(t,s)||n,{initials:F,hue:z}=Pe(R);return e.jsx("span",{role:"img","aria-label":n,className:V("inline-grid place-items-center rounded-full border border-border font-semibold text-white select-none",l),style:{background:`oklch(0.55 0.13 ${z})`,fontSize:"0.85em"},children:F})}return e.jsx(ge,{icon:a,className:o})}function Fe(t,s){if(!t)return;const n=s?.properties,a=["email","handle","username","login","github","x_handle","slug"],l=Object.keys(n||t);for(const o of l)if(a.includes(o.toLowerCase())){const c=t[o];if(typeof c=="string"&&c.trim())return c}}function _({column:t,children:s,alignRight:n=!1}){return e.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${n?" ml-auto":""}`,onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[s,e.jsx(Oe,{direction:t.getIsSorted()})]})}function se(t,s,n){const a=ne(t?.properties).filter(([o,c])=>(!s||o!=="name")&&!c["x-image"]&&c["x-table-column"]===!0);if(a.length)return a.map(([o,c])=>({field:o,label:c["x-table-label"]??T(o.replaceAll("_"," "))}));if(!s)return[];const l=n.find(o=>Object.keys(S(o.metadata)).length>0);return Object.keys(S(l?.metadata)).filter(o=>o!=="id"&&o!=="slug"&&o!=="name"&&!fe(t?.properties?.[o])).map(o=>({field:o,label:T(o.replaceAll("_"," "))}))}function ze(t){return t.some(s=>Object.hasOwn(S(s.metadata),"name"))}function Ie(t,s){return O(t,re(s))}function $e(t){return`${t.entityType}:${t.lookupField}`}const Be=new Set(["stage","category","round_type","investor_type"]);function Ke(t,s){const n=t.toLowerCase();return n==="mrr"||n==="arr"||n==="revenue"||n==="valuation"||n==="funding_raised"||n==="fund_size"||n.endsWith("_usd")||s.description?.toLowerCase().includes("usd")===!0}function Ve(t,s){if(Ke(t,s))return"currency";if(Be.has(t)||t.endsWith("_slug"))return"enum"}function He({entities:t,owner:s,schema:n,entityTypeIcon:a,isDerived:l,measureColumns:o,linkedEntityLookups:c,hasAnyParents:h,sorting:j,onSortingChange:y,visibleColumns:v,columnChoices:N,onVisibleColumnsChange:w,page:k,pageSize:L,totalCount:R,hasMore:F,pageTitle:z,onPrevPage:ie,onNextPage:ce}){const M=N?.length&&w?e.jsx(Ae,{choices:N,visible:v,onChange:w}):null,f=n?.properties,U=!l||ze(t),W=x.useMemo(()=>f?Object.fromEntries(Object.entries(f).flatMap(([i,r])=>r["x-link-entity-type"]?[[i,{entityType:r["x-link-entity-type"],lookupField:r["x-link-lookup-field"]||"slug"}]]:[])):{},[f]),C=x.useMemo(()=>f?se({properties:f},l,[]).map(({field:r})=>[r,f[r]]).map(([r,u])=>{const m=W[r],d=m?c[$e(m)]:void 0;return{id:l?r:`meta_${r}`,accessorFn:p=>{const g=S(p.metadata);return be(g[r],u.enum)},header:({column:p})=>{const g=u["x-table-label"]||u.title||u.description||T(r.replace(/_/g," "));return l?e.jsx(_,{column:p,children:g}):g},cell:({getValue:p})=>e.jsx(H,{value:p(),prop:u,format:Ve(r,u),className:"text-muted-foreground",resolveLink:d?g=>{const b=d[g];return b?{label:b.name,to:O(s,[{entity_type:b.entity_type,slug:b.slug}])}:void 0}:void 0})}}):[],[l,W,c,s,f]),D=x.useMemo(()=>new Set(o),[o]),I=x.useMemo(()=>!l||C.length>0?[]:se({properties:f},!0,t).map(({field:r})=>r).map(r=>{const u=D.has(r);return{id:r,accessorFn:m=>S(m.metadata)[r],header:({column:m})=>e.jsxs(_,{column:m,children:[u?r:T(r.replace(/_/g," ")),u&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:m})=>e.jsx(H,{value:m(),prop:f?.[r],className:u?"tabular-nums":"text-muted-foreground"}),meta:u?{align:"right"}:void 0}}),[l,C,t,D,f]),Q=x.useMemo(()=>{const i=n?.["x-table-relationships"];return!i||i.length===0?[]:i.map(r=>({id:`rel_${r.relationship_type}`,accessorFn:u=>u.relationships?.[r.relationship_type]??[],header:r.label,cell:({getValue:u})=>{const m=u();return!m||m.length===0?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:m.map((d,p)=>{const g=O(s,[{entity_type:d.entity_type,slug:d.slug}]);return e.jsxs("span",{children:[e.jsx(A,{to:g,className:"text-primary hover:underline",onClick:b=>b.stopPropagation(),children:d.name}),p<m.length-1&&","]},d.id)})})}}))},[s,n]),G=x.useMemo(()=>h||t.some(r=>r.parent_name&&r.parent_slug&&r.parent_entity_type)?[{id:"parent",accessorFn:r=>r.parent_name,header:"Parent",cell:({row:r})=>{if(!r.original.parent_name||!r.original.parent_slug||!r.original.parent_entity_type)return e.jsx("span",{className:"text-muted-foreground",children:"-"});const u=O(s,[{entity_type:r.original.parent_entity_type,slug:r.original.parent_slug}]);return e.jsx(A,{to:u,className:"text-primary hover:underline",children:r.original.parent_name})}}]:[],[t,h,s]),X=x.useMemo(()=>{const i=[],r=t.some(d=>(d.total_content??0)>0),u=t.some(d=>(d.active_connections??0)>0),m=t.some(d=>(d.automations_count??0)>0);return r&&i.push({accessorKey:"total_content",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Activity"}),cell:({row:d,getValue:p})=>{const g=p()??0;if(g===0)return e.jsx("span",{className:"tabular-nums",children:"0"});const b=re(d.original);return e.jsx(A,{to:je(s,b),className:"tabular-nums hover:underline",children:g})},meta:{align:"right"}}),u&&i.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:d})=>{const p=d();return p&&p>0?e.jsxs(Z,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[p," active"]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),m&&i.push({accessorKey:"automations_count",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Automations"}),cell:({getValue:d})=>e.jsx("span",{className:"tabular-nums",children:d()??0}),meta:{align:"right"}}),i},[t,s]),Y=x.useMemo(()=>[{accessorKey:"name",header:({column:i})=>U?e.jsx(_,{column:i,children:"Name"}):"Name",cell:({row:i})=>{const r=S(i.original.metadata);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{metadata:r,metadataSchema:n,name:i.original.name,typeIcon:a,className:"h-6 w-6 shrink-0"}),e.jsx("div",{className:"min-w-0",children:(()=>{const u=Ie(s,i.original);return e.jsx(A,{to:u,className:"block max-w-56 truncate font-medium hover:underline",title:i.original.name,children:i.original.name})})()})]})}},...G,...C,...I,...Q,...X,...l?[]:[{accessorKey:"created_at",header:({column:i})=>e.jsx(_,{column:i,children:"Created"}),cell:({getValue:i})=>e.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(i()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[s,G,C,I,Q,X,n,a,l,U]),$=ye({data:t,columns:Y,state:{sorting:j,columnVisibility:Object.fromEntries([...C,...I].flatMap(i=>i.id?[[i.id,!v||v.includes(l?i.id:i.id.replace(/^meta_/,""))]]:[]))},onSortingChange:y,getCoreRowModel:Ne(),manualSorting:!0,enableSortingRemoval:!1}),de=t.length>0||k>0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border",children:e.jsxs(Se,{className:"min-w-[48rem]",children:[e.jsx(ke,{children:$.getHeaderGroups().map(i=>e.jsxs(B,{children:[i.headers.map(r=>e.jsx(J,{"aria-sort":r.column.getIsSorted()==="asc"?"ascending":r.column.getIsSorted()==="desc"?"descending":void 0,className:r.column.columnDef.meta?.align==="right"?"text-right":"",children:r.isPlaceholder?null:q(r.column.columnDef.header,r.getContext())},r.id)),M?e.jsx(J,{className:"w-10 pr-2 text-right",children:M}):null]},i.id))}),e.jsx(Ce,{children:$.getRowModel().rows.length?$.getRowModel().rows.map(i=>e.jsxs(B,{children:[i.getVisibleCells().map(r=>e.jsx(K,{className:r.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:q(r.column.columnDef.cell,r.getContext())},r.id)),M?e.jsx(K,{}):null]},i.id)):e.jsx(B,{children:e.jsx(K,{colSpan:Y.length+(M?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),de&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:["Showing ",t.length," of ",R," ",z.toLowerCase()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",k+1," of ",Math.max(1,Math.ceil(R/L))]}),e.jsx(P,{variant:"outline",size:"sm",onClick:ie,disabled:k===0,children:"Previous"}),e.jsx(P,{variant:"outline",size:"sm",onClick:ce,disabled:!F,children:"Next"})]})]})]})}const Ue=720;function We(){return e.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(E,{className:"h-9 max-w-sm flex-1"}),e.jsx(E,{className:"h-9 w-28"})]}),e.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[e.jsx("div",{className:"border-b px-4 py-3",children:e.jsx(E,{className:"h-3 w-1/3"})}),e.jsx("div",{className:"divide-y",children:Array.from({length:5},(t,s)=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx(E,{className:"h-3 flex-1"}),e.jsx(E,{className:"h-3 w-16 shrink-0"})]},s))})]})]})}function et({title:t,actions:s,controls:n,table:a,children:l,loading:o=!1,error:c=null,onRetry:h,empty:j=e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"No records."})}){return e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[typeof t=="string"?e.jsx("h2",{className:"text-lg font-semibold",children:t}):t,s]}),e.jsxs("div",{children:[n,o?e.jsx(We,{}):c!==null?e.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[c,h?e.jsx(P,{className:"ml-3",variant:"outline",size:"sm",onClick:h,children:"Retry"}):null]}):l!==void 0?l:a?e.jsx(He,{...a}):j]})]})}function De(t,s){return s?.properties?ne(s.properties).map(([n,a])=>({key:n,prop:a})):Object.keys(t.metadata??{}).map(n=>({key:n,prop:{}}))}function Qe({entity:t,schema:s,icon:n}){return e.jsxs(e.Fragment,{children:[e.jsx(le,{metadata:t.metadata,metadataSchema:s?{...s}:void 0,name:t.name,typeIcon:n,className:"h-6 w-6 shrink-0"}),e.jsx("h2",{className:"truncate text-lg font-semibold leading-tight",children:t.name})]})}function Ge({entity:t,schema:s}){const n=_e(s?{...s}:void 0).filter(({key:a,prop:l})=>l["x-table-column"]===!0&&!l["x-image"]&&t.metadata?.[a]!==void 0&&t.metadata[a]!==null&&t.metadata[a]!=="");return n.length?e.jsx("p",{"data-testid":"record-summary",className:"-mt-2 truncate text-sm text-muted-foreground tabular-nums",children:n.map(({key:a,prop:l},o)=>e.jsxs("span",{children:[o>0?" · ":null,e.jsx(H,{value:t.metadata?.[a],prop:l})]},a))}):null}function Xe({details:t,summary:s,children:n,rootRef:a,narrow:l}){return e.jsx("div",{ref:a,className:"min-w-0 space-y-4",children:l?e.jsxs(e.Fragment,{children:[s,e.jsx("section",{"aria-label":"Details","data-testid":"record-details",children:t}),n]}):e.jsxs("div",{className:"grid grid-cols-[18rem_minmax(0,1fr)] gap-6",children:[e.jsx("aside",{className:"sticky top-12 max-h-[calc(100dvh-7rem)] min-w-0 self-start overflow-y-auto overscroll-contain pr-2 pb-16",children:t}),n]})})}function tt({entity:t,owner:s,schema:n,title:a,actions:l,details:o,summary:c,children:h,layout:j="record"}){const y=x.useRef(null),v=ve(y,Ue),N=e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"record-header",className:"sticky top-0 z-30 -mx-4 flex h-12 items-center justify-between gap-3 bg-background px-4 lg:-mx-6 lg:px-6",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:a===void 0?e.jsx(Qe,{entity:t,schema:n}):a}),l]}),j==="content"?h:e.jsx(Xe,{rootRef:y,narrow:v,details:o===void 0?e.jsx(we,{fields:De(t,n),values:t.metadata??{},context:{ownerSlug:s}}):o,summary:c===void 0?e.jsx(Ge,{entity:t,schema:n}):c,children:h})]});return j==="content"?N:e.jsx("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:N})}export{le as E,Ue as N,Me as S,He as a,et as b,We as c,tt as d,se as e,Xe as f,Ge as g,Qe as h};
2
+ //# sourceMappingURL=entity-pages-eYbG2FDT.js.map
@@ -1,2 +1,2 @@
1
- import{j as e,v as $,fp as me,g6 as xe,fs as Y,bO as ae,r as x,fq as he,fr as pe,dT as ge,dV as fe,B as f,d6 as V,dU as je,H as C,bl as q,bm as P,bn as M,bo as L,bp as R,I as O,ab as ve,g7 as Ne,g8 as ye,V as K,ev as be,X as W,cI as ne,C as re,$ as we,bc as le,g9 as ie,ga as Se,W as oe,gb as Ce,fX as ke,c2 as Ee,c3 as X,c7 as _e,eL as Re,bP as Oe,gc as Te,gd as De,i as G,L as Ae}from"./index-BjcZVe7n.js";import{C as Fe}from"./change-summary-DeuXQEpb.js";import{J as U,C as ce}from"./json-diff-DtZtra_g.js";function ze({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{operation:s.action,actor:s.actor,createdAt:s.created_at}),s.action==="update"&&e.jsx(U,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(U,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(U,{before:s.before_payload,after:null})]})]})}function qe({entityType:s}){const{orgContext:a}=$(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==Y),d=i.filter(m=>m.purpose===Y),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Le,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function B({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Pe,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Pe({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx(K,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(K,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Me,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Me({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(W,{className:"h-3 w-3"})})})]})}function Le({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=$(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[k,E]=x.useState(""),[D,w]=x.useState(!1),[A,_]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),E(""),w(!1),_(null)},T=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),J=async()=>{_(null);try{let l=h;if(o==="new"){if(!g.trim()){_("Name is required");return}const H=k.trim()||F(g);if(!H){_("Slug is required");return}l=(await u.mutateAsync({slug:H,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){_("Select a relationship type");return}if(!S){_("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),T(!1)}catch(l){_(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:T,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(V,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(R,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),k||E("")}}),e.jsx(O,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:k,onChange:l=>E(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"source",children:"This type → other"}),e.jsx(R,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(R,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:J,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ie({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function Je({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}function Ue({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(O,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(R,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ie,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(O,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(O,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"none",children:"None"}),e.jsx(R,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(R,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Je,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Q({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Z(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function Be(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"?a:"auto"}function $e({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Z(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=Be(u,p),T=u.some(F=>F.name.trim());m(T?JSON.stringify(v,null,2):""),a(T?v:void 0)},[a]),k=x.useCallback(u=>{i(u),j(u,o)},[j,o]),E=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Z(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{k([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,k(v)},_=u=>{k(t.filter((p,v)=>v!==u))};return c?e.jsx(Q,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Ue,{field:u,onChange:v=>A(p,v),onDelete:()=>_(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(V,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, otherwise table)."})]}),e.jsxs(q,{value:o,onValueChange:u=>E(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"auto",children:"Auto"}),e.jsx(R,{value:"table",children:"Table"}),e.jsx(R,{value:"board",children:"Board"})]})]})]})]}):e.jsx(Q,{value:h,onChange:D,error:S})]})}function We(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function He({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,k]=o.field("color"),[E,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[_,u]=X(i,n),[p,v]=X(i,null),T=w.trim().length>0,F=l=>{h(l),!n&&!_&&S(We(l))},J=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=T?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(O,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(O,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(O,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{id:"et-color",value:j,onChange:l=>k(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),T?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx($e,{value:E,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(qe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Oe,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:J,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Te(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,k=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},E=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:G("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:G("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:E}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(He,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4 space-y-3",children:[c.slug&&s?e.jsx(Ae,{to:"/$owner/events",params:{owner:c.slug},search:{semantic_types:"change",event_category:"config",resource_kind:"entity-type",resource_id:s.slug},className:"text-sm text-primary underline underline-offset-4",children:"View configuration history in Events"}):null,e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"Schema audit records"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(ze,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:k,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};
2
- //# sourceMappingURL=entity-type-page-D0ghgRgq.js.map
1
+ import{j as e,v as $,fe as me,fX as xe,fh as Y,bU as ae,r as x,ff as he,fg as pe,dM as ge,dO as fe,B as f,dc as I,dN as je,H as C,bt as q,bu as M,bv as P,bw as L,bx as R,I as O,ab as ve,fY as Ne,fZ as ye,V as K,ei as be,X as W,e1 as ne,C as re,$ as we,bg as le,f_ as ie,f$ as Se,W as oe,g0 as Ce,fM as ke,c8 as Ee,c9 as X,cd as _e,eA as Re,bV as Oe,g1 as Te,g2 as De,i as Z,L as Ae}from"./index-B-Ab8srM.js";import{C as Fe}from"./change-summary-CGrKEJ04.js";import{J as U,C as ce}from"./json-diff-B-1Swv_y.js";function ze({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{operation:s.action,actor:s.actor,createdAt:s.created_at}),s.action==="update"&&e.jsx(U,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(U,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(U,{before:s.before_payload,after:null})]})]})}function qe({entityType:s}){const{orgContext:a}=$(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==Y),d=i.filter(m=>m.purpose===Y),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Le,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function B({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Me,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Me({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx(K,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(K,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Pe,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Pe({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(W,{className:"h-3 w-3"})})})]})}function Le({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=$(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[k,E]=x.useState(""),[D,w]=x.useState(!1),[A,_]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),E(""),w(!1),_(null)},T=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),J=async()=>{_(null);try{let l=h;if(o==="new"){if(!g.trim()){_("Name is required");return}const H=k.trim()||F(g);if(!H){_("Slug is required");return}l=(await u.mutateAsync({slug:H,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){_("Select a relationship type");return}if(!S){_("Select a target entity type");return}const V=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:V,target_entity_type_slug:ue}),T(!1)}catch(l){_(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:T,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(I,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(M,{className:"h-8 text-sm",children:e.jsx(P,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(R,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),k||E("")}}),e.jsx(O,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:k,onChange:l=>E(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(M,{className:"h-8 text-sm",children:e.jsx(P,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"source",children:"This type → other"}),e.jsx(R,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(M,{className:"h-8 text-sm",children:e.jsx(P,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(R,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:J,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ve({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(I,{className:"h-3 w-3"})})]})]})}const Ie=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function Je({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(I,{className:"h-3 w-3"})})]})]})}function Ue({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(O,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(M,{className:"h-8 w-32",children:e.jsx(P,{})}),e.jsx(L,{children:Ie.map(t=>e.jsx(R,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ve,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(O,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(O,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(M,{className:"h-7 text-xs mt-0.5",children:e.jsx(P,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"none",children:"None"}),e.jsx(R,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(R,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Je,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function G({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Q(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function Be(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"?a:"auto"}function $e({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Q(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=Be(u,p),T=u.some(F=>F.name.trim());m(T?JSON.stringify(v,null,2):""),a(T?v:void 0)},[a]),k=x.useCallback(u=>{i(u),j(u,o)},[j,o]),E=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Q(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{k([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,k(v)},_=u=>{k(t.filter((p,v)=>v!==u))};return c?e.jsx(G,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Ue,{field:u,onChange:v=>A(p,v),onDelete:()=>_(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(I,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, otherwise table)."})]}),e.jsxs(q,{value:o,onValueChange:u=>E(u),children:[e.jsx(M,{className:"h-8 w-32 text-xs",children:e.jsx(P,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"auto",children:"Auto"}),e.jsx(R,{value:"table",children:"Table"}),e.jsx(R,{value:"board",children:"Board"})]})]})]})]}):e.jsx(G,{value:h,onChange:D,error:S})]})}function We(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function He({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,k]=o.field("color"),[E,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[_,u]=X(i,n),[p,v]=X(i,null),T=w.trim().length>0,F=l=>{h(l),!n&&!_&&S(We(l))},J=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=T?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}),c()}catch(V){v(V instanceof Error?V.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(O,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(O,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(O,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{id:"et-color",value:j,onChange:l=>k(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),T?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx($e,{value:E,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(qe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Oe,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:J,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Ge({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Te(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,k=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},E=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Z("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:Z("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:E}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(He,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4 space-y-3",children:[c.slug&&s?e.jsx(Ae,{to:"/$owner/events",params:{owner:c.slug},search:{semantic_types:"change",event_category:"config",resource_kind:"entity-type",resource_id:s.slug},className:"text-sm text-primary underline underline-offset-4",children:"View configuration history in Events"}):null,e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"Schema audit records"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(ze,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:k,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Ge as E};
2
+ //# sourceMappingURL=entity-type-page-CjFqxSdL.js.map
@@ -0,0 +1,2 @@
1
+ import{ee as Xt,j as t,cU as me,bT as fe,k as Nt,r as _,ef as wt,eg as Zt,a3 as en,Q as tn,dJ as nn,u as kt,eh as sn,i as ne,ei as yt,ej as Ge,ek as Ct,el as rn,L as se,d9 as an,em as on,en as ln,q as at,eo as it,cT as Me,x as dn,d_ as cn,cP as Rt,ep as un,eq as mn,d4 as pn,er as fn,es as At,cm as Xe,et as xn,eu as hn,e5 as yn,ev as gn,B as I,e0 as Ze,e1 as et,V as ue,ew as St,e2 as It,e3 as vn,dM as jn,dO as _n,dN as bn,a$ as Nn,b0 as wn,a0 as Et,b1 as kn,ex as Cn,c as Rn,w as An,v as Sn,bB as Te,ed as In,a6 as En,ey as gt,ez as Tn,I as $n,eA as Pn,bV as On,ab as pe,cR as Dn,dP as Fn,eB as Ln,eC as Mn,eD as Bn,eE as zn,c8 as Un,eF as qn,cd as Vn,eG as Kn,Y as Jn,eH as Hn,X as Qn,eI as Wn,bg as Yn,eJ as Gn,eK as Xn,dY as Zn}from"./index-B-Ab8srM.js";import{D as es,A as ts,a as ns,T as ss,b as rs,c as as,d as is}from"./definition-comparison-C3k6Wa9B.js";import{R as os,p as ls}from"./run-initiator-BvruBM5H.js";import{b as Tt}from"./use-automations-II_YJWtN.js";import{l as ds,s as cs,J as us}from"./renderer-CgaQKMoG.js";import{S as ms}from"./schema-value-BUgC0Ro8.js";import{C as ps}from"./change-summary-CGrKEJ04.js";import{J as Fe}from"./json-diff-B-1Swv_y.js";import{C as vt}from"./copy-button-D6zpsZLi.js";import{A as fs}from"./agent-list-row-SyACVYX7.js";import{A as xs}from"./automation-row-CmTpAD4r.js";function hs(e,n){if(!e||typeof e!="object"||Array.isArray(e))return null;const s=e.title;if(typeof s!="string")return null;const a=s.trim();return a&&a!==n?a:null}function $t(e){const n=Array.isArray(e?.records)?e.records:Array.isArray(e?.current)?e.current:[];return[e?.from_entity_id??e?.entity_id,e?.to_entity_id].map(s=>{const r=n.find(o=>o&&typeof o=="object"&&"id"in o&&o.id===s);return{id:String(s??"unknown"),name:typeof r?.name=="string"?r.name:`Record ${String(s??"unknown")}`}})}function Pt(e,n){return n==="rejected"?"The proposed relationship change was rejected. Both records remain available.":n==="failed"?"The relationship change failed. Both records remain available.":n==="completed"?e==="link"?"The records were linked. Both records remain available.":"The relationship was removed. Both records remain available.":n==="approved"||n==="confirmed"?"The relationship change was approved. Both records remain available.":e==="link"?"If approved, these records will be linked. Both records remain available.":"If approved, this relationship will be removed. Both records remain available."}function Fr(e){const n=$t(e.proposal);return{title:e.action==="link"?"Link records":"Unlink records",icon:"entity",impact:{level:"normal"},tone:"default",blocks:[...n.map((s,a)=>({type:"text",label:a===0?"From":"To",value:s.name})),{type:"text",label:"Relationship",value:String(e.proposal?.relationship_type??e.proposal?.relationship_type_slug??"Relationship")},{type:"text",value:Pt(e.action,typeof e.status=="string"?e.status:void 0),muted:!0},...typeof e.reason=="string"&&e.reason?[{type:"text",label:"Why this needs approval",value:e.reason}]:[]],actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",confirm:e.action==="unlink",confirmPrompt:"Remove this relationship? Both records will remain available.",tool:"manage_operations",args:{action:"approve"},resolvedLabel:"Approval submitted."},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this relationship change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:"Relationship change rejected."}]}}function Je(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function ys(e){const n=Je(e.proposal);if(!n)return null;const s=Je(e.current);if(e.tool==="manage_agents"){if(!["create","update","delete"].includes(String(n.action)))return null;const a=Xt({current:s,proposal:n});return{kind:"agent",current:n.action==="create"?null:a.current,proposed:n.action==="delete"?null:a.proposed}}if(e.tool==="manage_automations"){const a=Je(n.args);if(!a||!["create","update","create_version","set_reaction_script"].includes(String(a.action)))return null;const{action:r,automation_id:o,expected_version:l,...u}=a;return{kind:"automation",current:r==="create"?null:s,proposed:{...r==="create"?null:s,...u}}}return null}function gs({proposal:e}){return t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:"Recorded configuration and requested changes. Fields absent from the snapshot are not shown; creation uses the normal defaults."}),t.jsx(es,{current:e.current,proposed:e.proposed,render:n=>e.kind==="agent"?t.jsx(ts,{value:n}):t.jsx(ns,{value:n})})]})}function Ot(e,n,s){return{queryKey:["event-view-match",e,n.key,n.content_hash,s],queryFn:async()=>{try{const r=(await me("open_view",{key:n.key,scope:{event:s}},{slug:e})).scope?.event;if(!Number.isSafeInteger(r)||(r??0)<1)throw new Error("The view did not resolve its event subject");return r}catch(a){if(a instanceof fe&&(a.status===400||a.status===404))return null;throw a}},staleTime:6e4}}function Lr(e,n){const s=Nt(e??{slug:null,organizationId:null}),a=e?.slug??null,r=_.useMemo(()=>a?wt(s.data??[]):[],[a,s.data]),o=Zt({queries:r.map(l=>Ot(a,l,n))});return a?{views:r.flatMap((l,u)=>{const i=o[u]?.data;return i?[{...l,eventId:i}]:[]}),isLoading:s.data===void 0?!s.isError:o.some(l=>l.isPending),isError:s.isError||o.some(l=>l.isError),refetch:()=>{s.refetch();for(const l of o)l.isError&&l.refetch()}}:{views:[],isLoading:!1,isError:!1,refetch:()=>{}}}async function vs(e,n,s,a){const r=await Promise.all(s.map(o=>e.fetchQuery(Ot(n,o,a))));return s.find((o,l)=>r[l])??null}async function js(e,n,s,a){const r=await en(`${tn}/api/${encodeURIComponent(e)}/events/${n}/actions/${encodeURIComponent(s.action)}`,{method:"POST",timeoutMs:9e4,credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:s.value,interaction_id:a})});return await nn(r,"Could not record interaction"),r.json()}function O(e){if(typeof e!="string")return;const n=e.trim();return n.length>0?n:void 0}function He(e){return typeof e=="boolean"?e:void 0}function _s(e,n,s){const a=(s??"").toLowerCase();return!!(a==="prepare_comment"||a==="verify_staged_comment"||a.includes("prepare_")||a.includes("verify_staged")||n?.prepared===!0||typeof n?.verified=="boolean"||O(n?.reason_preview)&&O(n?.message)||O(e?.body)&&(O(e?.post_url)||O(e?.activity_id)))}function bs(e,n,s){if(!_s(e,n,s))return null;const a=(s??"").toLowerCase(),r=O(n?.body)??O(e?.body),o=O(n?.reason_preview)??O(e?.reason),l=O(n?.post_url)??O(e?.post_url)??(O(e?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${O(e?.activity_id)}`:void 0),u=He(n?.prepared),i=He(n?.verified),d=He(n?.banner_shown),g=O(n?.message),m=n?.match&&typeof n.match=="object"?n.match:null,p=O(m?.text_preview),b=O(m?.author);let C="generic";a==="verify_staged_comment"||a.includes("verify")||typeof i=="boolean"?C="verify":(a==="prepare_comment"||a.includes("prepare")||u===!0||r&&l)&&(C="prepare");const h=[];return u===!0&&h.push("Staged — not posted"),u===!1&&h.push("Not staged"),i===!0&&h.push("Verified posted"),i===!1&&h.push("Not verified as posted"),d===!0&&h.push("In-page banner"),d===!1&&h.push("No banner"),{kind:C,message:g,reason:o,body:r,postUrl:l,prepared:u,bannerShown:d,verified:i,matchPreview:p,matchAuthor:b,chips:h}}const $e="inline-flex max-w-full items-center truncate rounded-md border border-border px-1.5 py-0.5 text-xs";function tt({peer:e,ownerSlug:n,orgContext:s}){const a=kt();if(e.url&&!e.self&&e.type){const o=sn(e.url);return o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:ne($e,"hover:bg-muted"),title:e.type,onClick:l=>l.stopPropagation(),children:t.jsx("span",{className:"truncate",children:e.name})}):t.jsx("span",{className:ne($e,"text-muted-foreground"),children:e.name})}if(e.self||!e.type||!a)return t.jsx("span",{className:ne($e,"text-muted-foreground"),children:e.name});const r=a.item?.recordPeer?.entityId===e.id;return t.jsx("button",{type:"button","aria-pressed":r,title:e.type,className:ne($e,"hover:bg-muted",r&&"ring-1 ring-primary"),onClick:o=>{o.stopPropagation(),a.open(ds({...typeof e.id=="number"?{entityId:e.id}:{record:{type:e.type,key:e.id}},ownerSlug:n,orgContext:s,name:e.name}))},children:t.jsx("span",{className:"truncate",children:e.name})})}function Mr(e,n=e.relationship_type_name){const s=e.from_entity_name??`Record #${e.from_entity_id}`,a=e.to_entity_name??`Record #${e.to_entity_id}`;return e.is_symmetric?`${s} ${n} ${a}`:`${s} → ${n} → ${a}`}function Br({row:e,entityId:n,entityType:s,ownerSlug:a,orgContext:r,label:o=e.relationship_type_name}){const l=(u,i,d,g)=>t.jsx(tt,{peer:{id:u,name:i??`Record #${u}`,type:d,url:g,self:!g&&u===n&&(typeof u=="number"||d===s)},ownerSlug:a,orgContext:r});return t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1 text-xs",children:[l(e.from_entity_id,e.from_entity_name,e.from_entity_type,e.from_entity_url),!e.is_symmetric&&t.jsx(yt,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"text-muted-foreground",children:o}),!e.is_symmetric&&t.jsx(yt,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),l(e.to_entity_id,e.to_entity_name,e.to_entity_type,e.to_entity_url)]})}function zr({count:e,onRetry:n}){return e?t.jsxs("p",{role:"status",className:"text-xs text-muted-foreground",children:["Some linked records could not be read."," ",t.jsx("button",{type:"button",className:"underline",onClick:n,children:"Retry"})]}):null}const Dt={name:"Name",slug:"URL slug",parent_id:"Parent",content:"Content changed"};function de(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Pe(e){return e==null||e===""}function Ns(e,n){return Ge(e??null)===Ge(n??null)}function ws(e){return!!(e?.type==="array"&&(e.items?.type==="object"||e.items?.properties))}function ks(e){return!!(e&&(e.type==="object"||e.properties)&&e.type!=="array")}function ot(e,n){return cs({key:e,prop:n??{}})}function Cs(e,n){return e?.properties?.[n]}function nt(e,n,s,a,r){if(Ns(n,s))return;const o=i=>Array.isArray(i)?i:[];if((Array.isArray(n)||Pe(n))&&(Array.isArray(s)||Pe(s))&&(Array.isArray(n)||Array.isArray(s)||a?.type==="array")){const i=o(n),d=o(s);if(ws(a)||[...i,...d].some(j=>de(j))){const j=Math.min(i.length,d.length);for(let B=0;B<j;B++)nt([...e,`item ${B+1}`],i[B],d[B],a?.items,r);const w=Math.max(0,d.length-i.length),U=Math.max(0,i.length-d.length);(w||U)&&r.push({kind:"items",path:e,added:w,removed:U});return}const m=j=>Ge(j),p=new Set(i.map(m)),b=new Set(d.map(m)),C=d.filter(j=>!p.has(m(j))),h=i.filter(j=>!b.has(m(j)));r.push(C.length||h.length?{kind:"values",path:e,added:C,removed:h,prop:a?.items}:{kind:"reordered",path:e});return}if((de(n)||Pe(n))&&(de(s)||Pe(s))&&(de(n)||de(s)||ks(a))){const i=de(n)?n:{},d=de(s)?s:{},g=[...new Set([...Object.keys(a?.properties??{}),...Object.keys(i),...Object.keys(d)])];for(const m of g){const p=Cs(a,m);nt([...e,ot(m,p)],i[m],d[m],p,r)}return}r.push({kind:"set",path:e,old:n,new:s,prop:a})}function Rs(e,n){const s=Dt[e.field];if(s)return e.field==="content"?[{kind:"note",path:[s]}]:e.field==="parent_id"?[{kind:"parent",path:[s],old:e.old,new:e.new}]:[{kind:"set",path:[s],old:e.old,new:e.new}];const a=n?.properties?.[e.field],r=[];return nt([ot(e.field,a)],e.old,e.new,a,r),r}function As(e,n){const s=n?.properties;return e.map(a=>a.field==="content"?"Content":Dt[a.field]??ot(a.field,s?.[a.field]))}const Ss="entity.updated",Is=new Set(["link","unlink","update_link"]);function jt(e){const n=typeof e=="string"||typeof e=="number"?Number(e):Number.NaN;return Number.isSafeInteger(n)&&n>0?n:null}function Es(e){const n=e.split("_").join(" ").trim();return n?`${n.charAt(0).toUpperCase()}${n.slice(1)}`:e}function Ts(e){const n=e.metadata;if(e.semantic_type!=="change"||!n||n._lobu_relationship_change!==!0||typeof n.op!="string"||!Is.has(n.op))return null;const s=jt(n.fromEntityId),a=jt(n.toEntityId);if(s==null||a==null)return null;const r=typeof n.relationshipTypeSlug=="string"?n.relationshipTypeSlug:null,o=Array.isArray(n.changes)?n.changes:[];return{op:n.op,fromId:s,toId:a,typeLabel:r?Es(r):"relationship",changedFields:o.flatMap(l=>l&&typeof l=="object"&&typeof l.field=="string"?[l.field]:[])}}function Le({id:e,recordId:n,ownerSlug:s}){const a=e===n,r={slug:s},{data:o,isLoading:l,isError:u}=Ct(a?void 0:e,r);return a?t.jsx(tt,{peer:{id:e,name:"this record",type:null,self:!0},ownerSlug:s,orgContext:r}):l?t.jsxs("span",{className:"text-xs text-muted-foreground",children:["Record #",e]}):u||!o?t.jsx("span",{className:"text-xs text-muted-foreground",title:"Deleted, or you do not have access to it",children:"Unavailable record"}):t.jsx(tt,{peer:{id:e,name:o.name,type:o.entity_type},ownerSlug:s,orgContext:r})}function $s({change:e,recordId:n,ownerSlug:s}){const a=e.op==="link"?`Linked as ${e.typeLabel}`:e.op==="unlink"?`Unlinked ${e.typeLabel}`:`Updated ${e.typeLabel} link`,r=n===e.toId&&n!==e.fromId,o=n===e.fromId;return t.jsxs("span",{"data-testid":"relationship-change",className:"inline-flex flex-wrap items-center gap-1.5",children:[!o&&!r?t.jsx(Le,{id:e.fromId,ownerSlug:s}):null,t.jsx("span",{children:r?`${a} from`:a}),r?t.jsx(Le,{id:e.fromId,recordId:n,ownerSlug:s}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"→"}),t.jsx(Le,{id:e.toId,recordId:n,ownerSlug:s})]}),e.op==="update_link"&&e.changedFields.length>0?t.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",e.changedFields.join(", ")]}):null]})}function Ps(e){if(!Array.isArray(e)||e.length===0)return null;const n=[];for(const s of e){if(!s||typeof s!="object"||typeof s.field!="string")return null;const{field:a,old:r,new:o}=s;n.push({field:a,old:r??null,new:o??null})}return n}function Os(e){const n=Ts(e);if(n)return{kind:"relationship",change:n};const s=e.metadata;if(e.semantic_type!=="change"||!s)return null;const a=s._lobu_event_type;if(a!==Ss&&(a!==void 0||s.category))return null;const r=Ps(s.changes);if(!r)return null;const o=e.entity_ids?.[0];return{kind:"fields",entityId:typeof o=="number"?o:null,changes:r}}function Ft(e,n){const s={slug:n},{data:a}=Ct(e.entityType?void 0:e.entityId??void 0,s),{data:r}=rn(e.entityType??a?.entity_type??"",s);return r?.metadata_schema}const Ds=4;function Oe({value:e,prop:n}){return t.jsx("span",{className:"inline-block max-w-[18rem] truncate align-bottom",title:typeof e=="string"?e:void 0,children:t.jsx(ms,{value:e,prop:n,empty:t.jsx("span",{className:"italic",children:"empty"})})})}function _t({id:e,ownerSlug:n}){const s=typeof e=="number"||typeof e=="string"?Number(e):Number.NaN;return Number.isSafeInteger(s)&&s>0?t.jsx(Le,{id:s,ownerSlug:n}):t.jsx("span",{className:"italic text-muted-foreground",children:"empty"})}function st(e,n){return`${e} ${n}${e===1?"":"s"}`}function Fs({line:e,ownerSlug:n}){const s=t.jsx("span",{className:"text-muted-foreground",children:e.path.join(" · ")});switch(e.kind){case"note":return s;case"set":return t.jsxs(t.Fragment,{children:[s,": ",t.jsx(Oe,{value:e.old,prop:e.prop})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(Oe,{value:e.new,prop:e.prop})]});case"parent":return t.jsxs(t.Fragment,{children:[s,": ",t.jsx(_t,{id:e.old,ownerSlug:n})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(_t,{id:e.new,ownerSlug:n})]});case"items":return t.jsxs(t.Fragment,{children:[s,":"," ",[e.added?`${st(e.added,"item")} added`:null,e.removed?`${st(e.removed,"item")} removed`:null].filter(Boolean).join(", ")]});case"values":return t.jsxs(t.Fragment,{children:[s,":",e.added.map((a,r)=>t.jsxs("span",{className:"ml-1.5",children:["+",t.jsx(Oe,{value:a,prop:e.prop})]},`+${r}`)),e.removed.map((a,r)=>t.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["−",t.jsx(Oe,{value:a,prop:e.prop})]},`-${r}`))]});case"reordered":return t.jsxs(t.Fragment,{children:[s,": reordered"]})}}function Ls({change:e,ownerSlug:n}){const s=Ft(e,n);return t.jsxs(t.Fragment,{children:["Updated ",As(e.changes,s).join(", ")]})}function lt({changes:e,entityId:n,entityType:s,ownerSlug:a,showAll:r=!1}){const o=Ft({entityId:n,entityType:s},a),[l,u]=_.useState(r),i=e.flatMap(m=>Rs(m,o)),d=l?i:i.slice(0,Ds),g=i.length-d.length;return t.jsxs("ul",{"data-testid":"field-changes",className:"space-y-0.5 text-sm",children:[d.map((m,p)=>t.jsx("li",{className:"min-w-0 truncate",children:t.jsx(Fs,{line:m,ownerSlug:a})},p)),g>0?t.jsx("li",{children:t.jsxs("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:m=>{m.stopPropagation(),u(!0)},children:["+",st(g,"more change")]})}):null]})}function Ms({event:e,recordId:n,ownerSlug:s}){return e.kind==="relationship"?t.jsx($s,{change:e.change,recordId:n,ownerSlug:s}):t.jsx(Ls,{change:e,ownerSlug:s})}function Bs({event:e,ownerSlug:n}){return e.kind==="fields"?t.jsx(lt,{changes:e.changes,entityId:e.entityId,ownerSlug:n}):null}function zs(e){return e.semantic_type==="change"&&(e.metadata?.category==="config"||e.metadata?.category==="deployment")}function ce(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Us({content:e,detail:n=!1}){const s=e.metadata??{},a=e.payload_data??{},r=s.category==="deployment",o=typeof s.apply_id=="string"?s.apply_id:null,l=ce(a.manifest),u=o&&/^apl_[A-Za-z0-9-]{1,48}$/.test(o)&&e.origin_type==="deployment"&&e.origin_id===`deployment_${o}`&&(s.status==="succeeded"||s.status==="partial_failure")&&ce(l?.state);return t.jsxs("div",{className:"space-y-3","data-testid":"config-change-event",children:[t.jsx(ps,{showAttribution:n,operation:r?String(s.status??"Apply"):typeof s.op=="string"?s.op:null,actor:e.author_name??(typeof s.actor_source=="string"?s.actor_source:null),createdAt:e.occurred_at??e.created_at,resource:r?"Configuration apply":`${s.resource_kind??"Configuration"} · ${s.resource_id??""}`,changedFields:Array.isArray(s.changed_fields)?s.changed_fields.filter(i=>typeof i=="string"):void 0}),o?t.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[t.jsxs("span",{className:"break-all",children:["Apply ",o]}),t.jsx(vt,{text:o,label:"Copy apply ID"})]}):null,n?r?t.jsxs(t.Fragment,{children:[typeof s.rollback_of=="string"?t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["Restores apply ",s.rollback_of]}):null,ce(s.counts)?t.jsx("dl",{className:"flex flex-wrap gap-4 text-xs",children:Object.entries(ce(s.counts)??{}).map(([i,d])=>t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:i}),t.jsx("dd",{children:String(d)})]},i))}):null,typeof a.error=="string"?t.jsx("p",{className:"text-sm text-destructive",children:a.error}):null,u?t.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[t.jsx("p",{className:"text-sm font-medium",children:"Restore this deployment"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Preview restoring this saved configuration with the CLI. Secret values stay unchanged."}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("code",{className:"break-all text-xs",children:["lobu rollback ",o]}),t.jsx(vt,{text:`lobu rollback ${o}`,label:"restore command",iconOnly:!0})]})]}):null,t.jsx(Fe,{before:null,after:l})]}):Object.hasOwn(a,"before")?t.jsx(Fe,{before:ce(a.before),after:ce(a.state)}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:"The earlier state was not recorded for this change."}),t.jsx(Fe,{before:null,after:ce(a.state)})]}):null]})}function qs({record:e,workspace:n,appearance:s}){return t.jsx(xs,{automation:on(e),owner:n,agentName:e.managed_agent_id??null,deviceLabel:e.device_worker_id?"Device-pinned":null,connectorDisplay:null,appearance:s,rowClass:"flex items-center gap-3 rounded-lg border px-3 py-2.5"})}function Vs({agent:e,workspace:n,appearance:s}){return t.jsx(fs,{owner:n,appearance:s,last:!0,item:{kind:"managed",key:e.id,agent:{agentId:e.id,name:e.name,description:e.description??void 0}}})}function Ks({connector:e,connection:n,workspace:s,appearance:a}){const r=e.key,o=t.jsx(ln,{connector:e,showDescription:a!=="inline"});return t.jsx("div",{className:a==="inline"?"inline-flex items-center gap-2":"rounded-lg border p-3",children:n?t.jsxs(se,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:s,connectorKey:r,connectionId:String(n.id)},search:{},children:[o,t.jsx("span",{className:"text-xs text-muted-foreground",children:an(n)})]}):t.jsx(se,{to:"/$owner/connectors/$connectorKey",params:{owner:s,connectorKey:r},children:o})})}function De(e,n){return typeof e=="string"&&e.trim().length>0&&e.length<=n}function dt(e,n){if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n;if(s.mode!=="live"||!De(s.workspace,128)||!/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(s.workspace)||s.appearance!==void 0&&s.appearance!=="inline"&&s.appearance!=="row")return null;const a={mode:"live",workspace:s.workspace,appearance:s.appearance??"row"};return e==="automation-ref"?!De(s.automationId,128)||!/^[1-9][0-9]*$/.test(s.automationId)||!Number.isSafeInteger(Number(s.automationId))?null:{...a,automationId:s.automationId}:e==="connector-ref"?!De(s.connectorKey,128)||s.connectionId!==void 0&&(typeof s.connectionId!="number"||!Number.isSafeInteger(s.connectionId)||s.connectionId<=0)?null:{...a,connectorKey:s.connectorKey,...s.connectionId!==void 0?{connectionId:s.connectionId}:{}}:De(s.agentId,128)?{...a,agentId:s.agentId}:null}const Js=4,Hs=128;let Qe=0;const Ne=[];async function Qs(e,n){if(e.aborted)throw e.reason;await new Promise((s,a)=>{const r=()=>{const l=Ne.indexOf(o);l>=0&&Ne.splice(l,1),a(e.reason)},o=()=>{e.removeEventListener("abort",r),Qe++,s()};Qe<Js?o():Ne.length>=Hs?a(new Error("Reference read capacity exceeded")):(Ne.push(o),e.addEventListener("abort",r,{once:!0}))});try{if(e.aborted)throw e.reason;return await n()}finally{Qe--,Ne.shift()?.()}}const Be={retry:!1,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchOnReconnect:"always"};function xe({error:e}){const n=e instanceof fe&&(e.status===401||e.status===403)?"Access required to view this reference.":e instanceof fe&&e.status===404?"Reference not found.":"Reference unavailable.";return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:n})}function ct(){return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:"Loading reference…"})}function Ws({workspace:e,automationId:n,appearance:s}){const{session:a,isReady:r}=at(),o=it(),l=Me({...Be,enabled:r&&!o,queryKey:["automations-list",e,"native-reference",a?.user.id??null,n],queryFn:({signal:i})=>Qs(i,async()=>{let d;for(const m of["active","archived"])if(d=(await me("manage_automations",{action:"list",automation_id:n,status:m,include_details:!1,limit:1},{slug:e},{signal:i})).automations?.find(b=>b.automation_id===n),d)break;if(!d)throw new fe("Reference not found",404);const g=d.execution_config?.executor;return d={automation_id:d.automation_id,name:d.name,status:d.status,triggers:d.triggers,next_run_at:d.next_run_at,last_fired_at:d.last_fired_at,last_run_completed_at:d.last_run_completed_at,managed_agent_id:d.managed_agent_id,device_worker_id:d.device_worker_id,health:d.health,health_reasons:d.health_reasons,processing_client_count:d.processing_client_count,execution_config:g&&typeof g=="object"?{executor:{kind:g.kind}}:void 0},d})});if(o)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(l.isPending||l.isFetching)return t.jsx(ct,{});if(l.error||!l.data)return t.jsx(xe,{error:l.error});const u=l.data;return t.jsx(qs,{record:u,workspace:e,appearance:s})}function Ys({workspace:e,connectorKey:n,connectionId:s,appearance:a}){const{session:r,isReady:o}=at(),l=it(),u=Me({...Be,enabled:o&&!l,queryKey:["connector-definitions",e,"native-reference",r?.user.id??null],queryFn:async({signal:m})=>(await dn({slug:e},{signal:m})).map(p=>({key:p.key,name:p.name,description:p.description,icon:p.icon}))}),i=Me({...Be,enabled:o&&!l&&s!==void 0,queryKey:["connections",e,"native-reference",r?.user.id??null,n,s??null],queryFn:async({signal:m})=>{const p=s===void 0?void 0:(await me("manage_connections",{action:"list",connection_ids:[s],connector_key:n,limit:1},{slug:e},{signal:m})).connections?.find(b=>b.id===s);if(s!==void 0&&(!p||p.id!==s||p.connector_key!==n))throw new fe("Reference not found",404);return{connection:p?{id:p.id,connector_key:p.connector_key,display_name:p.display_name,connector_name:p.connector_name,auth_profile_name:p.auth_profile_name,auth_profile_slug:p.auth_profile_slug}:void 0}}});if(l)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(u.isPending||u.isFetching||s!==void 0&&(i.isPending||i.isFetching))return t.jsx(ct,{});if(u.error||s!==void 0&&(i.error||!i.data))return t.jsx(xe,{error:u.error||i.error});const d=u.data?.find(m=>m.key===n);if(!d)return t.jsx(xe,{error:new fe("Reference not found",404)});const g=i.data?.connection;return t.jsx(Ks,{connector:d,connection:g,workspace:e,appearance:a})}function Gs({workspace:e,agentId:n,appearance:s}){const{session:a,isReady:r}=at(),o=it(),l=Me({...Be,enabled:r&&!o,queryKey:["agents",e,"native-reference",a?.user.id??null,n],queryFn:async({signal:i})=>{const d=await me("manage_agents",{action:"get",agent_id:n},{slug:e},{signal:i});if(d.agent?.id!==n)throw new fe("Reference not found",404);return{id:d.agent.id,name:d.agent.name,description:d.agent.description}}});if(o)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(l.isPending||l.isFetching)return t.jsx(ct,{});if(l.error||!l.data)return t.jsx(xe,{error:l.error});const u=l.data;return t.jsx(Vs,{agent:u,workspace:e,appearance:s})}function Xs(e){const n=dt("automation-ref",e);return n?t.jsx(Ws,{...n}):t.jsx(xe,{})}function Zs(e){const n=dt("connector-ref",e);return n?t.jsx(Ys,{...n}):t.jsx(xe,{})}function er(e){const n=dt("agent-ref",e);return n?t.jsx(Gs,{...n}):t.jsx(xe,{})}const We=e=>typeof e=="string"&&e.trim().length>0&&e.length<=128,tr={tabs:({defaultValue:e,children:n})=>We(e)?t.jsx(is,{defaultValue:e,children:n}):null,"tabs-list":({label:e,children:n})=>t.jsx(as,{label:typeof e=="string"&&e.length<=200?e:void 0,children:n}),"tabs-trigger":({value:e,children:n})=>We(e)?t.jsx(rs,{value:e,children:n}):null,"tabs-content":({value:e,children:n})=>We(e)?t.jsx(ss,{value:e,children:n}):null,"automation-ref":Xs,"connector-ref":Zs,"agent-ref":er,"json-diff":(({before:e,after:n})=>{const s=a=>a!==null&&typeof a=="object"&&!Array.isArray(a)?a:null;return t.jsx(Fe,{before:s(e),after:s(n)})})};function we(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function nr({template:e,data:n,onAction:s}){const[a,r]=_.useState(null),[o,l]=_.useState(!1),[u,i]=_.useState(null),[d,g]=_.useState(!1),m=_.useRef(!1),p=_.useRef(!0);_.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]);const b=async C=>{if(!(!s||m.current)){m.current=!0,l(!0),i(null),g(!1);try{const h=await s(C);if(!p.current)return;if(we(h)&&h.kind==="sdk"){const j=h.result;if(!we(j)||j.success!==!0){const w=we(j)&&we(j.error)?j.error.message:null;throw new Error(typeof w=="string"?w:"Could not update this event.")}if(j.return_truncated||!we(j.return_value))throw new Error("The update did not return a complete data object.");r(j.return_value),g(!0)}}catch(h){p.current&&i(h instanceof Error?h.message:"Could not update this event.")}finally{m.current=!1,p.current&&l(!1)}}};return t.jsxs("div",{className:"space-y-2",children:[o?t.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Updating…"}):null,d?t.jsx("p",{role:"status",className:"sr-only",children:"Updated"}):null,u?t.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:[u," Previous data is still shown."]}):null,t.jsx("div",{"aria-busy":o,className:"min-w-0",children:t.jsx(us,{template:{root:e.root},data:a??n,onAction:s?b:void 0,interactions:e.interactions,components:tr,actionsDisabled:!s||o})})]})}function Lt(e){return{audit:e.semantic_type==="audit"&&e.origin_type==="tool_invocation",operation:e.interaction_type==="approval"||e.semantic_type==="operation",changeSet:e.semantic_type==="change_set"}}const sr={};function je(e){return e.replace(/_/g," ").replace(/\s+/g," ").trim().replace(/^./,n=>n.toUpperCase())}const rr={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function ar(e){return e.author_name?e.author_name:e.platform?je(e.platform):e.origin_type?rr[e.origin_type]??je(e.origin_type):null}function ir(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):Array.isArray(e)?e.length===0?"":e.every(n=>typeof n!="object")?e.map(n=>String(n)).join(", "):t.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(e,null,2)}):t.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(e,null,2)})}const Ye=1e5;function bt({value:e}){const n=JSON.stringify(e,null,2)??"null",s=n.length>Ye;return t.jsxs(t.Fragment,{children:[t.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/40 p-3 font-mono text-xs",children:s?n.slice(0,Ye):n}),s&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",Ye.toLocaleString()," of"," ",n.length.toLocaleString()," characters."]})]})}function or(e){return Object.entries(e).filter(([,n])=>n==null?!1:typeof n=="string"?n.trim().length>0:Array.isArray(n)?n.length>0:typeof n=="object"?Object.keys(n).length>0:!0).sort(([n],[s])=>n.localeCompare(s))}function lr({breakdown:e}){if(!e)return null;const n=[{label:"Engagement",value:e.engagement,max:100},{label:"Criticality",value:e.criticality,max:100},{label:"Depth",value:e.depth,max:100},{label:"Authority",value:e.authority,max:100},{label:"Recency",value:e.recency,max:100},{label:"Quality",value:e.quality,max:100}];return t.jsx("div",{className:"space-y-2 text-sm",children:n.map(s=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"w-20 text-muted-foreground",children:s.label}),t.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-primary",style:{width:`${s.value/s.max*100}%`}})}),t.jsx("span",{className:"w-8 text-right",children:s.value})]},s.label))})}function dr({slug:e,value:n,isManual:s}){return t.jsxs(ue,{variant:"secondary",className:"text-xs",children:[e,": ",n,s&&t.jsx(At,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function cr(e){if(e&&typeof e=="object"){const n=e;if(Array.isArray(n.values))return{values:n.values.map(s=>String(s)).filter(s=>s.length>0),isManual:n.is_manual===!0};if(n.value!==void 0&&n.value!==null)return{values:[String(n.value)],isManual:n.is_manual===!0};if(typeof n.values=="string"&&n.values.length>0)return{values:[n.values],isManual:n.is_manual===!0}}return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?{values:[String(e)],isManual:!1}:{values:[],isManual:!1}}function Mt(e,n){if(e)switch(e){case"pending":return"pending_approval";case"approved":return"confirmed";case"rejected":return"rejected";case"completed":return"completed";case"failed":return"failed";default:return e}return n||"pending_approval"}function rt(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function ur(e){return e.replace(/\s+[—-]\s+pending approval$/i,"")}function ze(e){return e.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,n=>n.toUpperCase())}function mr(e){const n=Object.keys(e.fields),s=n.map(ze).join(", ")||"field",a=n.length===1?"field":"fields";return`Update ${e.entityType?ze(e.entityType).toLowerCase():"entity"} ${a}: ${s}`}function pr(e,n){const s=rt(n.fields);if(!s||Object.keys(s).length===0||n.action_key!=="entity_field_change"&&n.tool!=="entity_field_change")return null;const a=rt(n.current)??{},r=e;return{fields:s,current:a,reason:typeof n.reason=="string"?n.reason:void 0,automationId:n.automation_id!=null?String(n.automation_id):void 0,automationName:typeof n.automation_name=="string"?n.automation_name:void 0,automationAgentId:typeof n.automation_agent_id=="string"?n.automation_agent_id:void 0,entityType:typeof n.entity_type=="string"?n.entity_type:void 0,entityName:(typeof n.entity_name=="string"?n.entity_name:void 0)??r.entity_name??void 0,entitySlug:typeof n.entity_slug=="string"?n.entity_slug:void 0,parentSlug:typeof n.parent_slug=="string"?n.parent_slug:void 0,parentEntityType:typeof n.parent_entity_type=="string"?n.parent_entity_type:void 0,attribution:typeof n.attribution=="string"?n.attribution:void 0,initiator:n.initiator&&typeof n.initiator=="object"?n.initiator:void 0}}function fr(e){const n=e.entityType?ze(e.entityType).toLowerCase():"entity";return`${ze(e.operation)} ${n}`}function xr(e,n){if(n.action_key!=="entity_change"&&n.tool!=="entity_change")return null;const s=n.action;if(s!=="create"&&s!=="delete"&&s!=="link"&&s!=="unlink")return null;const a=e;return{operation:s,proposal:rt(n.proposal),reason:typeof n.reason=="string"?n.reason:void 0,automationId:n.automation_id!=null?String(n.automation_id):void 0,automationName:typeof n.automation_name=="string"?n.automation_name:void 0,automationAgentId:typeof n.automation_agent_id=="string"?n.automation_agent_id:void 0,entityType:typeof n.entity_type=="string"?n.entity_type:void 0,entityName:(typeof n.entity_name=="string"?n.entity_name:void 0)??a.entity_name??void 0,entitySlug:typeof n.entity_slug=="string"?n.entity_slug:void 0,parentSlug:typeof n.parent_slug=="string"?n.parent_slug:void 0,parentEntityType:typeof n.parent_entity_type=="string"?n.parent_entity_type:void 0,attribution:typeof n.attribution=="string"?n.attribution:void 0,proposerRationale:typeof n.proposer_rationale=="string"?n.proposer_rationale:void 0,initiator:n.initiator&&typeof n.initiator=="object"?n.initiator:void 0}}function hr(e,n){return!n.entityType||!n.entitySlug?null:Zn(e,n.parentEntityType&&n.parentSlug?[{entity_type:n.parentEntityType,slug:n.parentSlug},{entity_type:n.entityType,slug:n.entitySlug}]:[{entity_type:n.entityType,slug:n.entitySlug}])}function Bt({ownerSlug:e,runId:n,details:s}){const r=Tt(s.automationId,void 0,void 0,{ownerSlug:e,includeVersions:!1}).data?.automation,o=ls(s.initiator,s.attribution,s.automationId),l=r?.automation_name??s.automationName??o;return t.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",s.automationId?t.jsx(se,{to:"/$owner/automations/$automationId",params:{owner:e,automationId:s.automationId},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:l}):t.jsx("span",{className:"font-medium text-foreground",children:l}),n&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:" · "}),t.jsxs(se,{to:"/$owner/events",params:{owner:e},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",children:["Run #",n]})]})]})}function zt({ownerSlug:e,details:n}){const s=hr(e,n);return n.entityName?t.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[t.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Entity"}),t.jsx("div",{className:"mt-1 text-sm font-medium",children:s?t.jsx(se,{to:s,className:"underline-offset-4 hover:underline",children:n.entityName}):n.entityName})]}):null}function yr({ownerSlug:e,runId:n,details:s}){return t.jsxs("div",{className:"space-y-3",children:[t.jsx(Bt,{ownerSlug:e,runId:n,details:s}),t.jsx(zt,{ownerSlug:e,details:s}),t.jsx("div",{className:"rounded-md border border-border/70 px-3 py-2",children:t.jsx(lt,{changes:Object.entries(s.fields).map(([a,r])=>({field:a,old:s.current[a]??null,new:r??null})),entityType:s.entityType,ownerSlug:e,showAll:!0})}),s.reason&&t.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[t.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Reasoning"}),t.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:s.reason})]})]})}function gr({ownerSlug:e,runId:n,details:s,status:a}){const{operation:r}=s,o=r==="link"||r==="unlink";return t.jsxs("div",{className:"space-y-3",children:[t.jsx(Bt,{ownerSlug:e,runId:n,details:s}),!o&&t.jsx(zt,{ownerSlug:e,details:s}),t.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Change"}),t.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:o?Pt(r,a):r==="create"?"Create a new entity after approval.":"Delete this entity after approval."}),o&&t.jsxs("div",{className:"mt-2 space-y-1 text-sm",children:[$t(s.proposal).map((l,u)=>t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:u===0?"From: ":"To: "}),l.name]},l.id)),t.jsxs("div",{className:"text-muted-foreground",children:["Relationship:"," ",String(s.proposal?.relationship_type??s.proposal?.relationship_type_slug??"Relationship")]})]})]}),!o&&s.proposal&&t.jsxs("div",{className:"rounded-lg border border-border/70 p-3",children:[t.jsx("div",{className:"mb-1 text-xs font-medium text-muted-foreground",children:"Proposal"}),t.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-xs leading-relaxed",children:JSON.stringify(s.proposal,null,2)})]}),s.proposerRationale&&t.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:s.attribution==="agent"?"The agent's reasoning":"The Automation's reasoning"}),t.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:s.proposerRationale})]}),s.reason&&t.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Why this needs approval"}),t.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:s.reason})]})]})}function vr({summary:e}){return t.jsxs("div",{className:"space-y-2 rounded-md border border-border/70 bg-muted/30 p-3 text-sm",children:[e.chips.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.chips.map(n=>t.jsx(ue,{variant:"outline",className:"text-[10px] font-normal",children:n},n))}),e.message&&t.jsx("p",{className:"leading-relaxed text-foreground",children:e.message}),e.reason&&t.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[t.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Why"}),t.jsx("div",{className:"mt-0.5 leading-relaxed",children:e.reason})]}),e.body&&t.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[t.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:e.kind==="verify"?"Expected comment":"Draft"}),t.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed",children:e.body})]}),e.matchPreview&&t.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[t.jsxs("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:["Matched comment",e.matchAuthor?` · ${e.matchAuthor}`:""]}),t.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed text-muted-foreground",children:e.matchPreview})]}),e.postUrl&&t.jsxs("a",{href:e.postUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open post",t.jsx(Et,{className:"h-3 w-3"})]})]})}function jr({ownerSlug:e,content:n,batchReview:s}){const a=n.metadata||{},r=n.run_id??void 0,o=ys(a),l=pr(n,a),u=xr(n,a),i=(l?mr(l):u?fr(u):void 0)||a.operation_name||a.action_name||(n.title?ur(n.title):void 0)||"Action",d=a.connection_name,g=a.operation_key||a.action_key||null,m=n.interaction_input_schema||a.input_schema||null,p=_.useMemo(()=>n.interaction_input||a.action_input||a.operation_input||sr,[n.interaction_input,a.action_input,a.operation_input]),b=n.interaction_output||a.action_output||void 0,C=bs(p,b??null,g),h=n.interaction_error||a.error_message||void 0,j=Mt(n.interaction_status,a.status),w=a.reviewed_by_name||a.reviewed_by_id||void 0,U=a.reject_reason||void 0,B=a.initiator,D=Bn({slug:e}),A=zn({slug:e}),F=Un(n.id,qn(m,p),m),{values:k,setValues:S}=F,[q,f]=_.useState(null),[z,E]=_.useState(!1),[Y,L]=_.useState(""),v=j==="pending_approval"&&q?q:j,T=v==="pending_approval",$=typeof a.source_run_id=="number";return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Rt,{className:"h-4 w-4 text-yellow-500"}),t.jsx("span",{className:"font-medium",children:i}),d&&t.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",d]}),v==="confirmed"&&t.jsx(ue,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:"Approved"}),v==="completed"&&t.jsx(ue,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),v==="failed"&&t.jsx(ue,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),v==="rejected"&&t.jsx(ue,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!l&&!u&&(n.author_name||w)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-xs text-muted-foreground",children:[n.author_name&&t.jsxs("span",{children:["Requested by"," ",t.jsx(os,{ownerSlug:e,initiator:B,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&w&&t.jsx("span",{children:"·"}),w&&t.jsxs("span",{children:[v==="rejected"?"Rejected":"Approved"," by"," ",t.jsx("span",{className:"font-medium text-foreground",children:w})]})]}),l&&t.jsx(yr,{ownerSlug:e,runId:r,details:l}),!l&&u&&t.jsx(gr,{ownerSlug:e,runId:r,details:u,status:v}),v==="rejected"&&U&&t.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-xs text-muted-foreground",children:[t.jsx("span",{className:"font-medium text-foreground",children:"Reason:"})," ",U]}),C&&t.jsx(vr,{summary:C}),o&&t.jsx(gs,{proposal:o}),!o&&(T?F.revision:m)&&(T||Object.keys(p).length>0)&&t.jsxs("div",{children:[t.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:C?"Full input":"Input"}),T?t.jsxs(t.Fragment,{children:[t.jsx(Vn,{visible:F.hasConflict,onReload:F.reset}),t.jsx(Kn,{schema:F.revision,values:k,onValuesChange:S,fieldIdPrefix:`action-${n.id}-`},`action-${n.id}`)]}):C?t.jsxs("details",{className:"text-xs",children:[t.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw input"}),t.jsx("pre",{className:"mt-1 bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}):t.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}),v==="completed"&&b&&Object.keys(b).length>0&&!C&&t.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-950/30 p-3 text-sm space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-green-700 dark:text-green-400 font-medium",children:[t.jsx(It,{className:"h-3.5 w-3.5"}),"Output"]}),t.jsx("pre",{className:"text-xs text-green-800 dark:text-green-300 font-mono whitespace-pre-wrap",children:JSON.stringify(b,null,2)})]}),v==="completed"&&b&&Object.keys(b).length>0&&C&&t.jsxs("details",{className:"text-xs",children:[t.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw output"}),t.jsx("pre",{className:"mt-1 rounded bg-green-50 p-2 font-mono dark:bg-green-950/30 overflow-auto max-h-32",children:JSON.stringify(b,null,2)})]}),v==="failed"&&h&&t.jsxs("div",{className:"rounded-md bg-red-50 dark:bg-red-950/30 p-3 text-sm",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-red-700 dark:text-red-400 font-medium",children:[t.jsx(St,{className:"h-3.5 w-3.5"}),"Error"]}),t.jsx("p",{className:"text-xs text-red-800 dark:text-red-300 font-mono mt-1",children:h})]}),T&&!q&&$&&t.jsxs("div",{className:"pt-1 text-xs text-muted-foreground",children:["Review this proposal with the other changes in its Automation run.",s]}),T&&r&&!q&&!$&&t.jsx("div",{className:"flex items-center gap-2 pt-1",children:z?t.jsxs("div",{className:"flex items-center gap-2 w-full",children:[t.jsx("input",{type:"text",placeholder:"Reason (optional)",value:Y,onChange:re=>L(re.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(I,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>A.mutate({run_id:r,reason:Y||void 0},{onSuccess:()=>{f("rejected")}}),disabled:A.isPending,children:[A.isPending&&t.jsx(pe,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),t.jsx(I,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{E(!1),L("")},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[t.jsxs(I,{size:"sm",className:"h-7 text-xs",onClick:()=>D.mutate({run_id:r,...o?{}:{input:Hn(k)}},{onSuccess:()=>{f("confirmed")}}),disabled:!o&&!F.canSubmit||D.isPending||A.isPending,children:[D.isPending?t.jsx(pe,{size:"sm",className:"mr-1"}):t.jsx(Jn,{className:"h-3 w-3 mr-1"}),o?"Approve":"Confirm"]}),t.jsxs(I,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>E(!0),disabled:D.isPending||A.isPending,children:[t.jsx(Qn,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function _r({content:e,ownerSlug:n}){const s=e.metadata||{},a=s.kind,r=e.run_id??null,o=typeof s.automation_id=="number"?s.automation_id:null,i=Tt(o!=null?String(o):void 0,void 0,void 0,{includeVersions:!1,ownerSlug:n}).data?.automation?.automation_name??(o!=null?`Automation ${o}`:"An Automation"),d=Ln({slug:n}),g=Mn({slug:n}),[m,p]=_.useState(!1),[b,C]=_.useState(""),[h,j]=_.useState(null);if(a==="automation_batch_reject"){const f=s.reason||void 0;return t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3",children:[t.jsx("div",{className:"text-sm font-medium",children:"Proposals rejected"}),f&&t.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:f}),t.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Ask the agent to revise its proposals with this feedback."})]})}const w=Array.isArray(s.changes)?s.changes:[],U=typeof s.created_count=="number"?s.created_count:w.filter(f=>f.kind==="created").length,B=typeof s.updated_count=="number"?s.updated_count:w.filter(f=>f.kind==="updated").length,D=typeof s.denied_count=="number"?s.denied_count:w.filter(f=>f.kind==="denied").length,A=w.filter(f=>f.kind==="denied"),F=w.filter(f=>f.kind==="updated"&&Object.keys(f.applied||{}).length>0),k=typeof s.pending_proposal_count=="number"?s.pending_proposal_count:null,S=k==null||k>0,q=S?"proposed":"applied";return t.jsxs("div",{className:"rounded-md border p-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[t.jsxs("div",{className:"text-sm font-medium",children:[q==="proposed"?"Proposed":"Applied"," ",U," ","new + ",B," updated",D>0&&t.jsxs(t.Fragment,{children:[" + ",D," denied"]})]}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[o!=null?t.jsx(se,{to:"/$owner/automations/$automationId",params:{owner:n,automationId:String(o)},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:i}):t.jsx("span",{className:"font-medium text-foreground",children:i}),r!=null&&t.jsxs("span",{children:[" · run #",r]}),k!=null&&k>0&&t.jsxs("span",{children:[" · ",k," pending"]})]})]}),F.length>0&&t.jsx("div",{className:"mt-3 space-y-2",children:F.map(f=>t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:f.name}),t.jsx(lt,{changes:Object.entries(f.applied).map(([z,E])=>({field:z,old:E.old??null,new:E.new??null})),entityId:f.entityId,ownerSlug:n,showAll:!0})]},f.entityId))}),A.length>0&&t.jsx("div",{className:"mt-3 space-y-1.5",children:A.map(f=>t.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-2.5 py-2",children:[t.jsxs("div",{className:"text-xs font-medium",children:[f.name," — not written"]}),f.denied&&t.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[f.denied.reason,t.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",f.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${f.entityId}-${f.name}`))}),r!=null&&h==null&&S&&t.jsx("div",{className:"mt-3 border-t border-border/70 pt-3",children:m?t.jsxs("div",{className:"flex items-center gap-2 w-full",children:[t.jsx("input",{type:"text",placeholder:"What should the agent change?",value:b,onChange:f=>C(f.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(I,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>g.mutate({run_id:r,reason:b||void 0},{onSuccess:()=>j("rejected")}),disabled:g.isPending,children:[g.isPending&&t.jsx(pe,{size:"sm",className:"mr-1"}),"Reject all"]}),t.jsx(I,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{p(!1),C("")},children:"Cancel"})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(I,{size:"sm",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:r},{onSuccess:()=>j("approved")}),disabled:d.isPending||g.isPending,children:[d.isPending&&t.jsx(pe,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),t.jsx(I,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>p(!0),disabled:d.isPending||g.isPending,children:"Reject with feedback"})]})}),h==="approved"&&t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals approved."}),h==="rejected"&&t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Proposals rejected — ask the agent to revise them."}),r!=null&&h==null&&!S&&t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function br(e){if(!e)return;const n={};for(const[s,a]of Object.entries(e))s==="_lobu_idempotency_key"||s==="agent_id"||(n[s]=a);return Object.keys(n).length>0?n:void 0}function Ur({presentation:e="summary",renderDetail:n,onFiltersChange:s,ownerSlug:a,content:r,isReply:o,showParentContext:l,connectorDefinitions:u,hideOriginator:i=!1,hideDetails:d=!1,recordId:g}){const[m,p]=_.useState(null),[b,C]=_.useState(!1),[h,j]=_.useState(!1),[w,U]=_.useState(!1),[B,D]=_.useState(!1),[A,F]=_.useState(!1),[k,S]=_.useState(null),[q,f]=_.useState(r.title??""),[z,E]=_.useState(r.text_content??""),Y=Rn(),L=An(),v=e==="detail",T=kt(),{currentOwner:$,allOrgs:re,isAuthenticated:ke}=Sn(),K=a??$,y=K==="me"?null:K,Ce=_.useCallback(async c=>{if(!y){Te.error("Open this event inside a workspace to interact with it.");return}const N=await js(y,Number(r.id),c,crypto.randomUUID());return"event_id"in N&&Te.success("Recorded"),N},[r.id,y]),M=r.payload_data??{},{audit:Q,operation:ae,changeSet:J}=Lt(r),he=Q&&(M.request!==void 0||M.request_status==="too_large"),ie=Q&&Array.isArray(M.sdk_call_trace)&&M.sdk_call_trace.length>0,G=K?Xe(K,Number(r.id)):null,oe=ke&&y?(re??[]).find(c=>c.slug===y):void 0,X=v?void 0:oe,H=r.semantic_type==="guidance",{isAdmin:Re,isLoading:Ae}=In(H?oe?.id:void 0),Z=X?{slug:X.slug,organizationId:X.id}:null,ye=Nt(Z??{slug:null,organizationId:null}),ee=Z?.slug??null,Se=_.useMemo(()=>ee&&!Q?wt(ye.data??[],r.semantic_type):[],[ee,Q,ye.data,r.semantic_type]),V=En(),_e=zs(r),ge=!!(!(ae||J||_e)&&Z&&Se.length>0),W=!v&&!b&&!!G,te=gt(T?.item?.href.split(/[?#]/)[0]??""),ve=te?.owner===K&&te?.eventId===Number(r.id),x=(c,N,P)=>{T?T.open({href:c,title:N,...P==null?{}:{runId:P}}):Y({to:c})},R=(c,N=`Run #${c}`)=>{if(!y)return null;const P=`/${y}/events?run_ids=${c}`;if(T?.item?.href===P)return null;const Ke=L.search.run_ids;return s&&String(Ke??"")===String(c)?null:t.jsxs(I,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>s?s({runIds:[c]}):x(P,"Run activity",c),title:"Show everything this run recorded",children:[t.jsx(Fn,{className:"h-3.5 w-3.5"}),N]})},Ie=r.run_id!=null&&(s||!(T&&y&&r.automation_id!=null))?R(r.run_id):null,le=Tn(r),qe=r.automation_id,Ut=T&&y&&le!=null&&qe!=null?()=>T.open({href:`/${y}/automations/${qe}?view=activity&run_id=${le}`,title:`${r.automation_name??`Automation ${qe}`} · Run #${le}`,runId:le}):void 0,ut=()=>{if(ge&&Z&&y){const c=Number(r.id);vs(V,Z.slug,Se,c).catch(()=>null).then(N=>x(Xe(y,c,N?.key),r.title??"Event"));return}G&&x(G,r.title??"Event")},mt=c=>{const N=c.target;if(!(N instanceof Element))return!1;const P=N.closest('a,button,input,select,textarea,[role="button"],[role="radio"]');return P!==null&&P!==c.currentTarget},qt=c=>{mt(c)||ut()},Vt=c=>{c.key!=="Enter"&&c.key!==" "||mt(c)||(c.preventDefault(),ut())},pt=r.metadata?.source_run_id,be=Os(r),Kt=(!r.platform||r.platform==="lobu")&&r.connection_id==null&&r.feed_id==null&&r.origin_type==null&&r.automation_id==null&&!Q&&!ae&&!J&&!_e&&be==null&&r.semantic_type!=="tombstone"&&r.semantic_type!=="notification"&&r.metadata?.tombstone!==!0&&r.interaction_type!=="approval"&&r.interaction_status==null&&!r.is_superseded&&r.superseded_by==null,ft=!!(y&&oe&&Kt&&(!H||!Ae&&Re)),xt=ft&&r.payload_type!=="json_template"&&r.payload_type!=="media",ht=()=>{V.invalidateQueries({queryKey:[Gn]}),V.invalidateQueries({queryKey:[Xn]}),V.invalidateQueries({queryKey:["search-memory"]})},Jt=async()=>{if(!(!y||!xt)){if(D(!1),S(null),r.payload_truncated){j(!0);try{const N=(await me("read_knowledge",{content_ids:[Number(r.id)]},{slug:y})).content?.find(P=>Number(P.id)===Number(r.id));f(N?.title??r.title??""),E(N?.text_content??N?.payload_text??r.text_content??""),C(!0)}catch(c){S(c instanceof Error?c.message:"Failed to load full memory.")}finally{j(!1)}return}f(r.title??""),E(r.text_content??""),C(!0)}},Ht=async()=>{if(!y||w)return;if(!z.trim()){S("Memory content cannot be empty.");return}U(!0),S(null);try{const N=r.payload_type==="markdown"||r.payload_type==="text"?r.payload_type:"text",P=br(r.metadata);await me("save_memory",{supersedes_event_id:Number(r.id),semantic_type:r.semantic_type||"note",payload_type:N,title:q.trim()||void 0,content:z,...Array.isArray(r.entity_ids)&&r.entity_ids.length>0?{entity_ids:r.entity_ids}:{},...r.source_url?{source_url:r.source_url}:{},...r.author_name?{author:r.author_name}:{},...r.occurred_at?{occurred_at:r.occurred_at}:{},...r.payload_data&&Object.keys(r.payload_data).length>0?{payload_data:r.payload_data}:{},...P?{metadata:P}:{}},{slug:y}),C(!1),ht(),Te.success("Memory updated")}catch(N){S(N instanceof Error?N.message:"Failed to update memory.")}finally{U(!1)}},Qt=async()=>{if(!(!y||A)){F(!0),S(null);try{const c=Number(r.id),N=await me("run_sdk",{title:"Delete memory",script:`export default async (_ctx, client) => client.knowledge.delete(${JSON.stringify({content_id:c,reason:"Deleted from web UI"})});`},{slug:y});if(N?.success===!1){const Ke=typeof N.error=="string"?N.error:N.error?.message||"Failed to delete memory.";throw new Error(Ke)}D(!1),ve&&T?.close();const P=gt(L.pathname);P?.owner===y&&P.eventId===c&&Y({to:"/$owner/events",params:{owner:y}}),ht(),Te.success("Memory deleted")}catch(c){S(c instanceof Error?c.message:"Failed to delete memory.")}finally{F(!1)}}},Wt=ft&&!b?B?t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsxs(I,{type:"button",variant:"destructive",size:"sm",className:"h-7 px-2.5 text-xs",disabled:A,onClick:()=>void Qt(),children:[A&&t.jsx(pe,{size:"xs",className:"mr-1.5"}),A?"Deleting...":"Delete"]}),t.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:A,onClick:()=>{D(!1),S(null)},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[xt&&t.jsxs(I,{type:"button",variant:"ghost",size:"sm","aria-label":"Edit memory",className:"h-7 gap-1 px-2 text-xs text-muted-foreground hover:text-foreground",disabled:h||A,onClick:()=>void Jt(),children:[h?t.jsx(pe,{size:"xs"}):t.jsx(Wn,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:h?"Loading...":"Edit"})]}),t.jsxs(I,{type:"button",variant:"ghost",size:"sm","aria-label":"Delete memory",className:"h-7 gap-1 px-2 text-xs text-muted-foreground hover:text-destructive",disabled:h,onClick:()=>{S(null),D(!0)},children:[t.jsx(Yn,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"Delete"})]})]}):null,Yt=b?t.jsxs("form",{className:"mt-2 space-y-3 rounded-lg border bg-background p-3 text-foreground",onSubmit:c=>{c.preventDefault(),Ht()},children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{htmlFor:`memory-title-${r.id}`,className:"block text-xs font-medium text-muted-foreground",children:"Title"}),t.jsx($n,{id:`memory-title-${r.id}`,"aria-label":"Memory title",value:q,onChange:c=>f(c.target.value),placeholder:"Optional short summary",disabled:w})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{htmlFor:`memory-content-${r.id}`,className:"block text-xs font-medium text-muted-foreground",children:["Content",t.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),t.jsx(Pn,{id:`memory-content-${r.id}`,"aria-label":"Memory content",value:z,onChange:c=>E(c.target.value),rows:5,disabled:w})]}),k&&t.jsx("div",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:k}),t.jsx(On,{onCancel:()=>{C(!1),S(null)},cancelDisabled:w,children:t.jsxs(I,{type:"submit",disabled:w||z.trim().length===0,children:[w&&t.jsx(pe,{size:"xs",className:"mr-1.5"}),w?"Saving...":"Save"]})})]}):null,Gt=!b&&k?t.jsx("div",{role:"alert",className:"mt-2 rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:k}):null,Ve=_e?t.jsx(Us,{content:r,detail:v}):v&&y?J?t.jsx(_r,{content:r,ownerSlug:y}):ae?t.jsx(jr,{ownerSlug:y,content:r,batchReview:typeof pt=="number"?R(pt,"Review run"):null}):void 0:void 0,Ee=v&&n?n(Ve):{content:Ve,nativeHeading:Ve!=null};return t.jsx("div",{className:ne(o?"border-l-2 border-l-muted pl-4":"",W&&"cursor-pointer rounded-lg p-3 transition-colors hover:bg-accent/40",W&&ve&&"bg-accent ring-1 ring-inset ring-primary/20"),...W?{role:"button","aria-current":ve?"true":void 0,tabIndex:0,onClick:qt,onKeyDown:Vt}:{},children:t.jsx(kr,{primaryContent:Ee.content,nativeHeading:Ee.nativeHeading,heading:be&&y?t.jsx(Ms,{event:be,recordId:g,ownerSlug:y}):void 0,body:Yt??(be&&y?t.jsx(Bs,{event:be,ownerSlug:y}):void 0),detailLinks:Ee.links,headingAside:Ee.headingAside,hideDetails:d,onFiltersChange:s,presentation:e,content:r,ownerSlug:K??void 0,showParentContext:l,connectorDefinitions:u,onRenderedAction:y?Ce:void 0,runAction:Ie,memoryActions:Wt,memoryFeedback:Gt,hideOriginator:i,runId:le??r.run_id??null,onRunSelect:Ut,auditDetails:v&&(he||ie)&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-2",children:[{key:"request",label:"Request",available:he},{key:"calls",label:"SDK calls",available:ie}].map(c=>c.available?t.jsxs(I,{variant:"outline",size:"sm","aria-expanded":m===c.key,onClick:()=>p(N=>N===c.key?null:c.key),children:[m===c.key?t.jsx(Ze,{className:"h-3.5 w-3.5"}):t.jsx(et,{className:"h-3.5 w-3.5"}),c.label]},c.key):null)}),m==="request"&&(M.request_status==="too_large"?t.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof M.request_bytes=="number"?` (${M.request_bytes.toLocaleString()} bytes).`:"."]}):t.jsx(bt,{value:M.request})),m==="calls"&&t.jsx(bt,{value:M.sdk_call_trace})]})})})}function Nr(e,n){const s=e.payload_data??{},a=e.metadata??{};if(n.audit&&typeof s.success=="boolean")return s.success?"completed":"failed";if(n.changeSet)return a.kind==="automation_batch_reject"?"rejected":typeof a.pending_proposal_count!="number"?void 0:a.pending_proposal_count>0?"pending_approval":"completed";if(n.operation)return Mt(e.interaction_status,typeof a.status=="string"?a.status:void 0)}function wr(e){return e==="pending_approval"?"Needs approval":e==="confirmed"?"Approved":e?je(e):null}function kr({presentation:e,primaryContent:n,nativeHeading:s=!1,heading:a,body:r,detailLinks:o,headingAside:l,onFiltersChange:u,content:i,ownerSlug:d,showParentContext:g,connectorDefinitions:m,onRenderedAction:p,runAction:b,memoryActions:C,memoryFeedback:h,auditDetails:j,hideOriginator:w=!1,runId:U,onRunSelect:B,hideDetails:D=!1}){const[A,F]=_.useState(!1),k=i.metadata??{},S=typeof i.score=="number"&&Number.isFinite(i.score)?Math.round(i.score):"-",q=i.payload_type||"text",f=q==="text"&&(i.semantic_type==="notification"||i.automation_id!=null)?"markdown":q,z=i.text_content||"",E=e==="summary",Y=e==null&&(f==="text"||f==="markdown")&&z.length>500,L=Y&&!A?`${z.slice(0,500)}...`:z,v=i.payload_data??{},T=Lt(i),{audit:$,operation:re,changeSet:ke}=T,K=Nr(i,T),y=wr(K),Ce=($?hs(v,v.tool_name):null)??(E&&$&&typeof v.tool_name=="string"?je(v.tool_name):i.title),M=$&&v.error&&typeof v.error=="object"?v.error.message:void 0,Q=(typeof M=="string"?M:void 0)??i.interaction_error??(typeof k.error_message=="string"?k.error_message:void 0),ae=Q||($?"":z),[J,he]=_.useState(e!=="summary"&&$&&n==null&&o==null),ie=$?v.duration_ms:k.duration_ms,G=typeof ie=="number"&&Number.isFinite(ie)&&ie>=0?ie:null,oe=$&&typeof v.sdk_call_count=="number"&&Number.isSafeInteger(v.sdk_call_count)&&v.sdk_call_count>=0?v.sdk_call_count:null,X=k.thumbnail_url||k.thumbnail,H=k.media_url,Re=E?[]:or(k),Ae=Object.entries(i.classifications||{}).flatMap(([x,R])=>{const Ie=cr(R);return Ie.values.map(le=>({slug:x,value:le,isManual:Ie.isManual}))}),Z=(()=>{const x=i.platform||(typeof k.platform=="string"?k.platform:null),R=i.connection_id!=null?i.connection_id:k.source_connection_id!=null?Number(k.source_connection_id):null;return{...i,platform:x,connection_id:R!=null&&Number.isFinite(R)?R:null}})(),ye=(()=>{const x=i.source_url??k.browser_url;if(typeof x!="string"||!URL.canParse(x))return null;const R=new URL(x);return R.protocol==="https:"||R.protocol==="http:"?R:null})(),ee=i.occurred_at?new Date(i.occurred_at):null,Se=$?cn:re?Rt:ke?un:i.semantic_type==="notification"?mn:pn,V=$?"SDK call":je(i.semantic_type||i.origin_type||"Event"),_e=t.jsx(Dn,{source:Z,connectorDefinitions:m,sourceUrl:ye,label:V,fallback:t.jsx(Se,{className:"h-4 w-4"})}),Ue=Re.length>0?t.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:Re.map(([x,R])=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{className:"text-muted-foreground",children:je(x)}),t.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:ir(R)})]},x))}):null,ge=r?t.jsx("div",{className:"mt-1",children:r}):E?ae?t.jsx("p",{className:ne("line-clamp-2 text-sm whitespace-pre-wrap",Q&&"text-destructive"),children:f==="markdown"&&!Q?t.jsx(fn,{text:ae.slice(0,320)}):ae.slice(0,320)}):null:t.jsxs(t.Fragment,{children:[i.rating&&t.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(x=>t.jsx(At,{className:`h-4 w-4 ${x<=Number(i.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},x))}),X&&t.jsx("a",{href:H||i.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:t.jsx("img",{src:X,alt:"",className:`rounded-md object-cover ${f==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),(()=>{switch(f){case"markdown":if(L)return t.jsx("div",{className:"max-w-none text-sm space-y-2",children:t.jsx(xn,{text:L})});break;case"json_template":{const x=i.payload_data;if(x?._truncated===!0&&typeof x.bytes=="number")return t.jsxs("div",{className:"space-y-2 text-sm",children:[t.jsx("p",{role:"status",children:"This report is too large for the feed preview. Open the full event to view its complete data."}),d?t.jsx(se,{to:Xe(d,Number(i.id)),className:"underline underline-offset-4",children:"Open full report"}):null]});const R=i.payload_template;if(R?.root)return t.jsx(nr,{template:R,data:i.payload_data||{},onAction:n?void 0:p},`${d}:${i.id}`);if(L)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:L});break}case"media":return t.jsxs("div",{className:"space-y-3",children:[!X&&H&&t.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:H}),L&&t.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:L})]});case"empty":return t.jsxs("div",{className:"space-y-3",children:[j,Ue??(j?null:t.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"}))]});default:if(L)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:L});break}return t.jsxs("div",{className:"space-y-3",children:[H&&!X&&t.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:H}),Ue]})})()]}),W=n!=null||e==="detail"&&$,te=l!==void 0,ve=W||o!=null;return _.useEffect(()=>{if(!te||!J)return;const x=R=>{R.key==="Escape"&&(R.preventDefault(),he(!1))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[te,J]),t.jsxs(t.Fragment,{children:[g&&i.parent_context&&t.jsxs("div",{className:"mb-3 p-2 bg-muted/50 rounded-md text-sm",children:[t.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Replying to:"}),t.jsx("div",{className:"font-medium",children:i.parent_context.author_name}),t.jsx("div",{className:"text-muted-foreground line-clamp-2",children:i.parent_context.text_content})]}),t.jsxs("div",{className:ne("flex gap-3",e==="detail"&&"mb-5",te&&"relative"),children:[t.jsx(hn,{children:_e}),t.jsxs("div",{className:"min-w-0 flex-1",children:[e==="detail"&&(()=>{const x={semanticTypes:[i.semantic_type],...typeof i.automation_id=="number"?{producedByAutomationId:i.automation_id}:{},...typeof i.run_id=="number"?{runIds:[i.run_id]}:{}},R={semantic_types:i.semantic_type,...typeof i.automation_id=="number"?{produced_by:String(i.automation_id)}:{},...typeof i.run_id=="number"?{run_ids:String(i.run_id)}:{}};return t.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[i.semantic_type?u?t.jsx("button",{type:"button",className:"hover:underline",title:`Show all ${V} events`,onClick:()=>u(x),children:V}):d?t.jsx(se,{to:"/$owner/events",params:{owner:d},search:R,className:"hover:underline",title:`Show all ${V} events`,children:V}):t.jsx("span",{children:V}):t.jsx("span",{children:V}),ee&&t.jsx("time",{dateTime:ee.toISOString(),children:yn(ee)})]})})(),t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[(a??Ce)&&!s&&t.jsx("h4",{className:ne("min-w-0 font-medium",e==="detail"?"text-xl leading-snug":"line-clamp-2 text-sm"),children:a??Ce}),e!=="detail"&&ee&&t.jsx(gn,{at:ee}),te&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[l,ve&&t.jsxs(I,{type:"button",variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-muted-foreground hover:text-foreground","aria-expanded":J,onClick:()=>he(x=>!x),children:["Details",J?t.jsx(Ze,{className:"h-3.5 w-3.5"}):t.jsx(et,{className:"h-3.5 w-3.5"})]})]})]}),E&&t.jsx("div",{className:"mt-1 text-muted-foreground",children:ge}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[y&&!s&&t.jsxs(ue,{variant:K==="failed"?"destructive":"secondary",className:"gap-1 text-xs",children:[K==="failed"?t.jsx(St,{className:"h-3 w-3"}):K==="completed"?t.jsx(It,{className:"h-3 w-3"}):null,y]}),oe!=null&&t.jsxs("span",{children:[oe," SDK ",oe===1?"call":"calls"]}),G!=null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(vn,{className:"h-3 w-3"}),G<1e3?`${Math.round(G)}ms`:`${Number((G/1e3).toFixed(2))}s`]}),b,S==="-"||E&&($||re||ke)?null:i.score_breakdown?t.jsxs(jn,{children:[t.jsx(_n,{asChild:!0,children:t.jsx(I,{variant:"ghost",size:"sm",className:"h-7 px-2",children:t.jsx("span",{className:"font-medium",children:S})})}),t.jsx(bn,{className:"w-64",align:"end",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("h4",{className:"font-medium",children:"Score Breakdown"}),t.jsx(lr,{breakdown:i.score_breakdown})]})})]}):null,ye&&t.jsxs(Nn,{children:[t.jsx(wn,{asChild:!0,children:t.jsx(I,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-1",asChild:!0,children:t.jsxs("a",{href:ye.href,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(Et,{className:"h-3.5 w-3.5"}),t.jsx("span",{className:E?"sr-only":void 0,children:"View original"})]})})}),t.jsx(kn,{children:"View original"})]}),C]}),h,d&&t.jsx(Cn,{owner:d,source:Z,connectorDefinitions:m,onFiltersChange:u,variant:"chips",className:"mt-2 text-xs",hideOriginator:w,runId:U,onRunSelect:B}),(i.author_name||!d)&&!(e==="detail"&&re)&&t.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:i.author_name||ar(i)})]}),te&&J&&ve&&t.jsxs("div",{className:"absolute inset-x-0 top-full z-20 mt-2 max-h-[65vh] space-y-3 overflow-y-auto rounded-lg border bg-background p-3 shadow-lg",children:[o,W&&ge]})]}),!E&&typeof M=="string"&&t.jsx("p",{className:"mb-2 text-sm whitespace-pre-wrap text-destructive",children:M}),n,!E&&!W&&ge,(W||o!=null)&&l===void 0&&!(D&&n!=null)&&t.jsxs("details",{className:"mt-5 border-t pt-3",open:J,onToggle:x=>he(x.currentTarget.open),children:[t.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground",children:"Details"}),J&&t.jsxs("div",{className:"mt-3 space-y-3",children:[o,W&&ge]})]}),Y&&t.jsx(I,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>F(!A),children:A?t.jsxs(t.Fragment,{children:[t.jsx(Ze,{className:"h-3 w-3 mr-1"})," Show less"]}):t.jsxs(t.Fragment,{children:[t.jsx(et,{className:"h-3 w-3 mr-1"})," Show more"]})}),Ae.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:Ae.map(x=>t.jsx(dr,{slug:x.slug,value:x.value||"",isManual:x.isManual},x.slug))})]})}export{Ur as E,zr as R,kr as a,Br as b,Fr as c,Mr as r,je as s,hs as t,Lr as u};
2
+ //# sourceMappingURL=event-card-BtTUuf2q.js.map
@@ -0,0 +1,2 @@
1
+ import{q as G,a1 as I,r as B,gD as J,g5 as Q,j as s,cm as M,L as W}from"./index-B-Ab8srM.js";import{E as X}from"./events-feed-zFnTSE27.js";import{b as Y,a as Z,V as z,M as K}from"./view-param-filters-DYlqBocg.js";import{u as ee}from"./event-card-BtTUuf2q.js";const se={},te="calc(100dvh - 120px)";function oe({owner:n,organizationId:o,eventId:c,viewKey:r,params:g,onParamsChange:d,onSelectView:p,dense:h=!1,fullBleed:k=!1}){const{isAuthenticated:y,isReady:E}=G(),{data:O,isLoading:w}=I(),P=O?.some(t=>t.id===o&&t.is_member),i=n!=="me"&&o!==null&&E&&y&&!w&&P,a=ee(i?{slug:n,organizationId:o}:null,c),[j,L]=B.useState(se),[T,b]=B.useState(null),m=J(a.views,r),e=i&&!a.isLoading&&!a.isError&&m.kind==="view"?m.view:null,v=e?`${Q(n,e.key)}/${e.content_hash}/${e.eventId}`:null,x=e!==null&&T===v,V=M(n,c),F=n!=="me"&&(!E||y&&(w||a.isLoading)),H=e!==null&&!x&&!F,u=k&&H,U=(k||h)&&H,N=F?s.jsx("div",{role:"status",className:"py-8 text-sm text-muted-foreground",children:"Loading event view…"}):e&&!x?s.jsxs(s.Fragment,{children:[s.jsx(Y,{decls:e.params,params:g??j,onParamsChange:t=>d?d(e.key,t,{replace:!1}):L(t)}),s.jsx(Z,{orgSlug:n,viewKey:e.key,scope:{event:e.eventId},params:g??j,onParamsChange:t=>d?d(e.key,t):L(t),onLoadError:()=>b(v),contentHash:e.content_hash,title:e.name,minHeight:h?240:320,fixedHeight:U?te:void 0},v)]}):void 0;return s.jsxs("div",{className:u?"w-full space-y-3":"mx-auto w-full max-w-3xl space-y-3",...u?{"data-testid":"event-view-fullbleed"}:{},children:[i&&a.isError&&s.jsx(z,{onRetry:a.refetch}),(i||n==="me"&&r)&&!a.isLoading&&!a.isError&&m.kind==="missing"&&s.jsx(K,{viewKey:m.key,backTo:V,backLabel:"Back to the event"}),x&&s.jsxs("div",{role:"alert",className:"rounded-md border p-3 text-sm",children:[s.jsx("p",{children:"The custom view couldn’t load. The event content is shown below."}),s.jsx("button",{type:"button",className:"mt-2 underline",onClick:()=>b(null),children:"Retry custom view"})]}),s.jsx(X,{presentation:"detail",organizationId:o,ownerSlug:n,filters:{contentIds:[c],...n==="me"?{sortBy:"date",sortOrder:"desc"}:{}},hideDetails:h,renderDetail:t=>{const f=N!=null&&(t==null||!!r),A=(i?a.views:[]).filter(l=>!f||l.key!==e?.key).map(l=>({key:l.key,name:l.name,href:M(n,c,l.key)})),D=l=>l.length?s.jsx("nav",{"aria-label":"Event views",className:"flex flex-wrap gap-3 text-sm",children:l.map(({key:$,name:C,href:_})=>s.jsx(W,{to:_,className:"underline",onClick:p?q=>{q.preventDefault(),p(_)}:void 0,children:C},$))}):null,R=[...A],S=[...A];return i&&r&&t!=null&&S.unshift({key:":event",name:"Event details",href:V}),{content:f?N:t,nativeHeading:!f&&t!=null,headingAside:u?D(R):void 0,links:u?null:D(S)}}})]})}export{oe as E};
2
+ //# sourceMappingURL=event-detail-8xHiplt_.js.map
@@ -0,0 +1,2 @@
1
+ import{j as e,L as $e,C as Pe,dY as Le,dZ as H,d_ as Oe,d$ as $,B as A,e0 as P,e1 as L,V as Be,e2 as ze,e3 as Ge,e4 as O,dn as Z,e5 as R,e6 as We,q as Ke,at as Qe,cF as Ue,ds as qe,dv as Ve,dw as Xe,r as N,e7 as Ye,e8 as Ze,e9 as Je,ea as et,eb as tt,c4 as st,cM as nt,ec as at,cO as ot}from"./index-B-Ab8srM.js";import{s as it,E as F,t as rt}from"./event-card-BtTUuf2q.js";import{u as lt}from"./client-activity-scopes-DoIErdUy.js";import{c as ct}from"./client-rows-BbVQy5Ti.js";import{a as dt}from"./run-initiator-BvruBM5H.js";function mt(n,a){const o=a.parentEntityType&&a.parentEntitySlug?[{entity_type:a.parentEntityType,slug:a.parentEntitySlug},{entity_type:a.entityType,slug:a.entitySlug}]:[{entity_type:a.entityType,slug:a.entitySlug}];return Le(n,o)}function ut({ownerSlug:n,entity:a,className:o}){const d=mt(n,a);return e.jsxs($e,{to:d,className:`flex items-center gap-1 text-primary hover:underline group ${o??""}`,children:[e.jsx("span",{className:"font-medium",children:a.entityName}),e.jsx(Pe,{className:"h-3 w-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}function xt({toolName:n,count:a,titles:o=[],totalDurationMs:d,totalSdkCalls:p,newestAt:m,oldestAt:g,expanded:y,onToggle:b,children:j}){return e.jsx("div",{children:e.jsxs(H,{open:y,children:[e.jsx("div",{className:"rounded-lg p-3",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{"aria-hidden":!0,className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx($,{asChild:!0,children:e.jsxs(A,{variant:"ghost",size:"sm",className:"h-5 min-w-0 gap-1.5 px-0 text-sm text-muted-foreground",onClick:b,children:[e.jsxs("span",{className:"min-w-0 truncate font-medium text-foreground",children:[it(n)," × ",a]}),y?e.jsx(P,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(L,{className:"h-3.5 w-3.5 shrink-0"})]})}),e.jsx(ue,{newestAt:m,oldestAt:g})]}),o.length>0&&e.jsx("p",{className:"mt-0.5 truncate text-sm text-muted-foreground",children:o.join(" · ")}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[e.jsxs(Be,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(ze,{className:"h-3 w-3"}),"Completed"]}),p!=null&&e.jsxs("span",{children:[p," SDK ",p===1?"call":"calls"]}),d!=null&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ge,{className:"h-3 w-3"}),ht(d)]})]})]})]})}),e.jsx(O,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:j})]})})}function ht(n){return n<1e3?`${Math.round(n)}ms`:`${Number((n/1e3).toFixed(2))}s`}function ue({newestAt:n,oldestAt:a}){const o=me(n),d=me(a);return o!=null&&d!=null&&o.getTime()-d.getTime()>pt&&d?e.jsxs("time",{dateTime:o.toISOString(),title:`${R(d)} – ${R(o)}`,className:"shrink-0 pt-0.5 text-xs text-muted-foreground",children:[Z(d,"HH:mm"),"–",Z(o,"HH:mm")]}):o?e.jsx("time",{dateTime:o.toISOString(),title:R(o),className:"shrink-0 pt-0.5 text-xs text-muted-foreground",children:Z(o,"HH:mm")}):null}const pt=300*1e3;function me(n){if(n==null||n==="")return null;const a=new Date(n);return Number.isNaN(a.getTime())?null:a}function gt({organizationId:n,clientId:a,activityId:o,activityKind:d,callCount:p,newestAt:m,oldestAt:g,expanded:y,onToggle:b,children:j}){const{data:B=[]}=lt({limit:100,organizationId:n??null}),k=B.find(C=>C.activityId===o&&(a==null||C.clientId===a))??null,z=k?ct(k):d==="session"?"MCP session":"Conversation",w=k?.clientName??null;return e.jsx("div",{children:e.jsxs(H,{open:y,children:[e.jsx("div",{className:"rounded-lg border bg-muted/40 p-3",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border bg-background",children:e.jsx(We,{name:w})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx($,{asChild:!0,children:e.jsxs(A,{variant:"ghost",size:"sm",className:"h-5 min-w-0 gap-1.5 px-0 text-sm text-muted-foreground",onClick:b,children:[e.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:z}),y?e.jsx(P,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(L,{className:"h-3.5 w-3.5 shrink-0"})]})}),e.jsx(ue,{newestAt:m,oldestAt:g})]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[`${p} ${p===1?"call":"calls"}`,w?` · ${w}`:null]})]})]})}),e.jsx(O,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:j})]})})}function Ct({presentation:n="summary",renderDetail:a,onFiltersChange:o,hideDetails:d=!1,organizationId:p,ownerSlug:m,entityId:g,filters:y,showEntityLinks:b=!1,hideOriginator:j=!1,emptyState:B,foldConsecutiveCalls:k=!1,groupByConversation:z=!1,foldRunSatellites:w=!0,renderLead:C,hiddenApprovalRunIds:G}){const{isAuthenticated:W,isReady:S}=Ke(),{isMember:J,isLoading:ee}=Qe(),K=m==="me",I=!K&&S&&W&&J,Q=!K&&S&&(!W||!ee&&!J),{data:xe=[]}=Ue(S&&I?p:null),{data:he=[]}=qe(Q?m:null),T=I?xe:he,pe=Ve(S&&I?p:null,g,y,m),ge=Xe(Q?m:null,g,y),U=Q?ge:pe,{data:te,isLoading:fe,error:je,fetchNextPage:ye,hasNextPage:se,isFetchingNextPage:Ne}=U,ne=N.useMemo(()=>te?.pages.flatMap(i=>i.content)??[],[te]),q=N.useMemo(()=>{const i=Ye(ne,{foldRunSatellites:w}),t=i.map(u=>u.head),r=new Map(i.map(u=>[u.head.id,u])),l=Ze(t),h=Array.from(l.entries()).map(([u,c])=>{const x=c.root||c.replies[0],D=x?r.get(x.id):void 0;return{rootId:u,group:c,history:D?.history??[],runId:D?.runId??null}});return G?Je(h,G):h},[ne,w,G]),V=C?q[0]:void 0,_=V?V.group.root??V.group.replies[0]:void 0,X=_?q.slice(1):q,[we,Ce]=N.useState(new Set),[ve,be]=N.useState(new Set),[ke,Se]=N.useState(new Set),[Te,De]=N.useState(new Set),[Ee,Fe]=N.useState(new Set),Y=(i,t)=>i(r=>{const l=new Set(r);return l.has(t)?l.delete(t):l.add(t),l}),ae=(i,t)=>t.some(r=>i.has(r)),oe=(i,t)=>i(r=>{const l=new Set(r),h=t.some(u=>l.has(u));for(const u of t)h?l.delete(u):l.add(u);return l}),ie=k?et(X):X.map(i=>({kind:"single",node:i})),Ae=z?tt(ie):ie,Ie=!K&&(!S||W&&ee||I&&U.isPending);if(je)return e.jsx(st,{label:"events"});const re=i=>{if(i.kind==="fold"){const{fold:s}=i,ce=s.nodes.map(E=>E.rootId),He=ae(ve,ce);return[{key:s.key,occurredAt:s.newestAt,content:e.jsx(xt,{toolName:s.toolName,count:s.nodes.length,titles:[...new Set(s.nodes.flatMap(E=>{const v=E.group.root?.payload_data,de=rt(v,v?.tool_name);return de?[de]:[]}))],totalDurationMs:s.totalDurationMs,totalSdkCalls:s.totalSdkCalls,newestAt:s.newestAt,oldestAt:s.oldestAt,expanded:He,onToggle:()=>oe(be,ce),children:s.nodes.map(E=>{const v=E.group.root;return v?e.jsx(F,{presentation:n,recordId:g,onFiltersChange:o,ownerSlug:m,content:v,renderDetail:a,connectorDefinitions:T,hideOriginator:j,hideDetails:d},v.id):null})})}]}const{rootId:t,group:r,history:l,runId:h}=i.node,u=r.replies.length>0,c=we.has(t),x=Ee.has(t),D=Te.has(t),Me=r.replies.filter(s=>s.depth<=3),M=r.replies.filter(s=>s.depth>3),Re=!r.root&&r.replies.length>0,f=r.root||r.replies[0];return f?[{key:t,occurredAt:f.occurred_at,content:e.jsxs(e.Fragment,{children:[b&&m&&f.entity_name&&f.entity_type&&f.entity_slug&&e.jsx("div",{className:"mb-2",children:e.jsx(ut,{ownerSlug:m,entity:{entityName:f.entity_name,entityType:f.entity_type,entitySlug:f.entity_slug}})}),e.jsx(F,{presentation:n,recordId:g,onFiltersChange:o,ownerSlug:m,content:f,renderDetail:a,showParentContext:Re&&!!f.parent_context,connectorDefinitions:T,hideOriginator:j,hideDetails:d}),l.length>0&&e.jsxs(H,{open:D,children:[e.jsx($,{asChild:!0,children:e.jsxs(A,{variant:"ghost",size:"sm",className:"mt-1 h-7 gap-1 text-xs text-muted-foreground",onClick:()=>Y(De,t),children:[e.jsx(nt,{className:"h-3.5 w-3.5"}),D?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-3.5 w-3.5"}),"Hide ",h!=null?`run #${h} `:"","history"]}):e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"h-3.5 w-3.5"}),h!=null?`Run #${h} · ${l.length===1?"1 earlier step":`${l.length} earlier steps`}`:l.length===1?"1 earlier state":`${l.length} earlier states`]})]})}),e.jsx(O,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:l.map(s=>e.jsxs("div",{children:[e.jsx("time",{dateTime:new Date(s.occurred_at).toISOString(),title:R(s.occurred_at),className:"mb-1 block text-xs text-muted-foreground",children:at(s.occurred_at)}),e.jsx(F,{presentation:n,recordId:g,onFiltersChange:o,ownerSlug:m,content:s,connectorDefinitions:T,hideOriginator:j})]},s.id))})]}),u&&e.jsxs(H,{open:c,children:[e.jsx($,{asChild:!0,children:e.jsxs(A,{variant:"ghost",size:"sm",className:"mt-2 ml-6 gap-1",onClick:()=>Y(Ce,t),children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),c?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-3.5 w-3.5"}),"Hide ",r.replies.length," replies"]}):e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"h-3.5 w-3.5"}),"Show ",r.replies.length," replies"]})]})}),e.jsxs(O,{className:"space-y-2 mt-2",children:[Me.map(s=>e.jsx(F,{presentation:n,recordId:g,onFiltersChange:o,ownerSlug:m,content:s,isReply:!0,connectorDefinitions:T,hideOriginator:j},s.id)),M.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"ghost",size:"sm",className:"ml-12",onClick:()=>Y(Fe,t),children:x?e.jsxs(e.Fragment,{children:["Hide ",M.length," nested replies"]}):e.jsxs(e.Fragment,{children:["Show ",M.length," nested replies"]})}),x&&M.map(s=>e.jsx(F,{presentation:n,recordId:g,onFiltersChange:o,ownerSlug:m,content:s,isReply:!0,connectorDefinitions:T,hideOriginator:j},s.id))]})]})]})]})}]:[]},_e=i=>{const{block:t}=i,r=t.entries.flatMap(c=>c.kind==="fold"?c.fold.nodes.map(x=>x.rootId):[c.node.rootId]),l=ae(ke,r),h=t.entries.flatMap(c=>re(c).map(x=>({key:x.key,content:x.content})));if(h.length===0)return[];const u=t.entries.reduce((c,x)=>c+(x.kind==="fold"?x.fold.nodes.length:1),0);return[{key:t.key,occurredAt:t.newestAt,content:e.jsx(gt,{organizationId:p,clientId:t.clientId,activityId:t.activityId,activityKind:t.activityKind,callCount:u,newestAt:t.newestAt,oldestAt:t.oldestAt,expanded:l,onToggle:()=>oe(Se,r),children:h.map(c=>e.jsx(N.Fragment,{children:c.content},c.key))})}]},le=e.jsx(dt,{groupByDate:n==="summary",isLoading:fe||Ie,emptyState:_?null:B,hasNextPage:!!se,isFetching:U.isFetching,isFetchingNextPage:Ne,onLoadMore:()=>void ye(),items:Ae.flatMap(i=>i.kind==="context"?_e(i):re(i))});return!_||!C?le:e.jsxs(e.Fragment,{children:[C(_,{hasEarlier:X.length>0||!!se}),le]})}export{Ct as E};
2
+ //# sourceMappingURL=events-feed-zFnTSE27.js.map
@@ -0,0 +1,2 @@
1
+ import{dL as P,j as e,B as h,i as g,r as m,dM as C,X as O,dN as k,dO as S,dP as z,m as B,dQ as D,dR as F,dS as E,dT as L,cX as $,cY as R,$ as I,dn as j,Y as Q,dU as _,dV as N,dW as b,I as y,dX as U}from"./index-B-Ab8srM.js";function w(s,t,n){return P(s,-t,n)}const M="w-72";function T({editor:s,close:t,header:n,footer:o}){const[l,a]=m.useState("");return e.jsxs(e.Fragment,{children:[n,s.kind==="list"?e.jsxs(D,{shouldFilter:!s.onQueryChange,children:[e.jsx(F,{autoFocus:!0,placeholder:s.searchPlaceholder,value:l,onValueChange:d=>{a(d),s.onQueryChange?.(d)}}),e.jsxs(E,{children:[e.jsx(L,{children:s.emptyText}),e.jsx($,{children:s.items(t,l)})]})]}):s.render(t),o]})}function V({chip:s,editor:t}){const[n,o]=m.useState(!1),l=s.onRemove!=null,a=[s.label,s.op,s.value].filter(Boolean).join(" "),d=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:s.label}),s.op?e.jsx("span",{className:"text-muted-foreground",children:s.op}):null,e.jsx("span",{className:"min-w-0 truncate font-medium",children:s.value})]}),r=t?e.jsx(S,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":`Edit filter: ${a}`,className:"flex min-w-0 items-center gap-1.5 pl-2.5 pr-1 focus-visible:outline-none",children:d})}):e.jsx("span",{className:"flex min-w-0 items-center gap-1.5 pl-2.5 pr-1",children:d});return e.jsxs(C,{open:n,onOpenChange:o,children:[e.jsxs("div",{"data-filter-chip":s.id,title:s.title,className:g("inline-flex h-8 max-w-full items-stretch rounded-md border text-sm",s.tone==="warning"?"border-amber-500/60 bg-amber-500/10":l?"bg-muted":"border-dashed bg-transparent",n&&"ring-1 ring-ring",!l&&"pr-1.5"),children:[r,l?e.jsx("button",{type:"button","aria-label":`Remove filter: ${a}`,onClick:s.onRemove,className:"flex w-7 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",children:e.jsx(O,{className:"h-3.5 w-3.5"})}):null]}),t?e.jsx(k,{align:"start",className:g("p-0",M,t.className),children:e.jsx(T,{editor:t,close:()=>o(!1),footer:l?e.jsx("div",{className:"border-t p-1",children:e.jsx(h,{variant:"ghost",size:"sm",className:"w-full justify-start text-destructive hover:text-destructive",onClick:()=>{o(!1),s.onRemove?.()},children:"Remove filter"})}):null})}):null]})}function X({fields:s}){const[t,n]=m.useState(!1),[o,l]=m.useState(),a=s.find(i=>i.key===o),d=[...new Set(s.map(i=>i.group??""))],r=()=>{n(!1),l(void 0)};return e.jsxs(C,{open:t,onOpenChange:i=>{n(i),i||l(void 0)},children:[e.jsx(S,{asChild:!0,children:e.jsxs(h,{variant:"outline",size:"sm",className:"h-8 gap-1.5 font-normal text-muted-foreground",children:[e.jsx(z,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(k,{align:"start",className:g("p-0",M,a?.editor.className),children:a?e.jsx(T,{editor:a.editor,close:r,header:e.jsxs("div",{className:"flex items-center gap-1 border-b px-1 py-1 text-sm font-medium",children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Back to filters",onClick:()=>l(void 0),children:e.jsx(B,{className:"h-4 w-4"})}),a.label]})},a.key):e.jsxs(D,{children:[e.jsx(F,{autoFocus:!0,placeholder:"Filter by…"}),e.jsxs(E,{children:[e.jsx(L,{children:"No matching filter"}),d.map(i=>e.jsx($,{heading:i||void 0,children:s.filter(c=>(c.group??"")===i).map(c=>e.jsxs(R,{value:`${c.label} ${c.key}`,onSelect:()=>l(c.key),className:"gap-2",children:[c.icon?e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground",children:c.icon}):null,c.label]},c.key))},i))]})]})})]})}function J({fields:s,chips:t,meta:n,actions:o,trailing:l,onClearAll:a,hasClearableState:d=!1,className:r,label:i="Filters"}){const c=s.filter(u=>u.inMenu!==!1),x=t.filter(u=>u.onRemove).length;return e.jsxs("div",{role:"search","aria-label":i,className:g("flex min-w-0 flex-wrap items-center gap-2",r),children:[t.map(u=>e.jsx(V,{chip:u,editor:u.editor??s.find(f=>f.key===(u.field??u.id))?.editor},u.id)),c.length>0?e.jsx(X,{fields:c}):null,o,e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[n?e.jsx("span",{className:"text-sm text-muted-foreground",children:n}):null,a&&(x>0||d)?e.jsx(h,{variant:"ghost",size:"sm",className:"h-8 text-muted-foreground",onClick:a,children:"Clear all"}):null,l]})]})}function A({selected:s}){return e.jsx(Q,{className:g("h-4 w-4 shrink-0",s?"opacity-100":"opacity-0")})}function K({searchPlaceholder:s,emptyText:t="No options",options:n,selected:o,multiple:l=!1,onSelect:a}){return{kind:"list",searchPlaceholder:s,emptyText:t,items:d=>n.map(r=>{const i=o.includes(r.value);return e.jsxs(R,{value:`${r.label} ${r.keywords??r.value}`,onSelect:()=>{a(r.value),l||d()},"aria-label":r.label,className:"group gap-2",children:[l?e.jsx(I,{checked:i,className:"mr-1"}):e.jsx(A,{selected:i}),r.icon,e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r.label}),r.count!=null?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:r.count.toLocaleString()}):null,r.action]},r.value)})}}function Z([s,t],n,o){return s<=n?`≤ ${t}`:t>=o?`≥ ${s}`:`${s}–${t}`}function H({value:s,min:t,max:n,onApply:o,close:l}){const[a,d]=m.useState(String(s?.[0]??t)),[r,i]=m.useState(String(s?.[1]??n)),[c,x]=m.useState(),u=f=>{f.preventDefault();const v=Number(a),p=Number(r);if(!Number.isFinite(v)||!Number.isFinite(p)){x("Enter a number.");return}if(v<t||p>n){x(`Use values between ${t} and ${n}.`);return}if(v>p){x("The lower bound must not exceed the upper bound.");return}o([v,p]),l()};return e.jsxs("form",{className:"space-y-3 p-3",onSubmit:u,children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] items-center gap-2",children:[e.jsx(y,{"aria-label":"From",type:"number",min:t,max:n,value:a,onChange:f=>d(f.target.value)}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"to"}),e.jsx(y,{"aria-label":"To",type:"number",min:t,max:n,value:r,onChange:f=>i(f.target.value)})]}),c?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:c}):null,e.jsx(h,{type:"submit",size:"sm",className:"w-full",children:"Apply"})]})}function ee(s){return{kind:"custom",render:t=>e.jsx(H,{...s,close:t})}}const W=[{label:"Today",range:()=>[N(new Date),b(new Date)]},{label:"Last 7 days",range:()=>[N(w(new Date,6)),b(new Date)]},{label:"Last 30 days",range:()=>[N(w(new Date,29)),b(new Date)]},{label:"This month",range:()=>[U(new Date),b(new Date)]}];function se([s,t]){return j(s,"yyyy-MM-dd")===j(t,"yyyy-MM-dd")?j(s,"LLL d, y"):`${j(s,"LLL d")} – ${j(t,"LLL d, y")}`}function Y({value:s,onApply:t,close:n}){const[o,l]=m.useState(s?{from:s[0],to:s[1]}:void 0);return e.jsxs("div",{className:"flex flex-col sm:flex-row",children:[e.jsx("div",{className:"flex flex-col gap-0.5 border-b p-2 sm:w-36 sm:border-b-0 sm:border-r",children:W.map(a=>e.jsx(h,{variant:"ghost",size:"sm",className:"justify-start font-normal",onClick:()=>{t(a.range()),n()},children:a.label},a.label))}),e.jsx(_,{mode:"range",defaultMonth:o?.from,selected:o,onSelect:a=>{l(a),a?.from&&a.to&&a.from!==a.to&&(t([N(a.from),b(a.to)]),n())},numberOfMonths:1})]})}function te(s){return{kind:"custom",className:"w-auto",render:t=>e.jsx(Y,{...s,close:t})}}function q({type:s,label:t,value:n,onApply:o,close:l}){const[a,d]=m.useState(n==null?"":String(n)),[r,i]=m.useState(),c=x=>{if(x.preventDefault(),s==="number"){const u=Number(a);if(a.trim()===""||!Number.isFinite(u)){i("Enter a number.");return}o(u)}else o(a);l()};return e.jsxs("form",{className:"space-y-3 p-3",onSubmit:c,children:[e.jsx(y,{autoFocus:!0,"aria-label":t,type:s,step:s==="number"?"any":void 0,value:a,onChange:x=>d(x.target.value),placeholder:"Enter a value…"}),r?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:r}):null,e.jsx(h,{type:"submit",size:"sm",className:"w-full",children:"Apply"})]})}function ae(s){return{kind:"custom",render:t=>e.jsx(q,{...s,close:t})}}export{J as F,A as S,Z as a,te as d,se as f,K as o,ee as r,ae as v};
2
+ //# sourceMappingURL=filter-editors-Dd5R2Etd.js.map
@@ -1,2 +1,2 @@
1
- import{r,j as t,i as u}from"./index-BjcZVe7n.js";function l({className:i,delayMs:e=500}){const[s,n]=r.useState(e<=0);return r.useEffect(()=>{if(e<=0)return;const a=setTimeout(()=>n(!0),e);return()=>clearTimeout(a)},[e]),s?t.jsx("div",{className:u("flex min-h-[50vh] items-center justify-center",i),role:"status","aria-label":"Loading",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):null}export{l as F};
2
- //# sourceMappingURL=full-page-spinner-B5xXnKtV.js.map
1
+ import{r,j as t,i as u}from"./index-B-Ab8srM.js";function l({className:i,delayMs:e=500}){const[s,n]=r.useState(e<=0);return r.useEffect(()=>{if(e<=0)return;const a=setTimeout(()=>n(!0),e);return()=>clearTimeout(a)},[e]),s?t.jsx("div",{className:u("flex min-h-[50vh] items-center justify-center",i),role:"status","aria-label":"Loading",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):null}export{l as F};
2
+ //# sourceMappingURL=full-page-spinner-CCU4PkRv.js.map
@@ -0,0 +1,2 @@
1
+ import{bf as q,r as f,cE as Q,at as J,cs as U,aH as W,aI as Z,cF as V,cG as X,cH as z,cI as ee,cJ as te,ct as se,j as e,cK as ne,I as ae,i as H,cL as oe,b2 as ie,cM as re,cw as le,cN as T,S as ce,L as _,cy as de,cO as me,cB as ue,cP as he,cQ as ge,b6 as xe,cR as pe,u as fe,d as je}from"./index-B-Ab8srM.js";import{a as P}from"./list-skeleton-BAqT0vxo.js";import{u as be}from"./use-automations-II_YJWtN.js";import{u as Ne}from"./clients-6aJvabvS.js";import{u as ye}from"./client-activity-scopes-DoIErdUy.js";import{g as ve}from"./client-rows-BbVQy5Ti.js";const I=12,ke=5e3;function Le(n,a){const t=!!n&&!!a.organizationId&&(a.enabled??!0),i=q({enabled:t}),{data:m}=i,u=m??[],c=f.useMemo(()=>u.map(l=>l.agentId),[u]),{threads:o,isLoading:r,isError:d}=Q(n,c,{enabled:t&&c.length>0,limit:I}),N=ye({enabled:t,limit:I,excludeCommandClients:!1,organizationId:a.organizationId,refetchInterval:l=>l?ke:!1}),g=a.organizationId?N.data:void 0;return{items:f.useMemo(()=>[...o.map(l=>({kind:"conversation",at:l.updatedAt,thread:l})),...(g??[]).map(l=>({kind:"mcp",at:l.lastCallAt,conversation:l}))].sort((l,b)=>b.at-l.at),[g,o]),agents:u,isLoading:t&&(i.isLoading||r||N.isLoading),isError:i.isError||d||N.isError}}const we={automation:he,connection:ue,agent:me},Se={automation:"/$owner/automations",connection:"/$owner/connectors",agent:"/$owner/agents"},Ce={automation:"No Automations yet.",connection:"No connections yet.",agent:"No agent activity yet."};function Be({owner:n,organizationId:a,needsYou:t,onNeedsYouChange:i}){const{isMember:m,isPublic:u,isLoading:c}=J(n),o=u&&!m&&!c,r=t&&!o,[d,N]=f.useState(""),g=U(o?null:n),j=be(a??void 0,void 0,{includeDetails:!1}),l=W(a),b=Z(a),{data:v=[],isLoading:K}=V(a),x=Le(n,{organizationId:a,enabled:!o}),k=Ne(null,{enabled:!o}),{sources:S,unattached:C}=f.useMemo(()=>X({owner:n,automations:j.data??[],connections:l.data??[],feeds:b.data??[],connectors:new Map(v.map(s=>[s.key,s])),recentItems:x.items,roster:x.agents,clientGroups:ve(k.data??[]).filter(s=>s.connected),attention:g.attentionCards.map(s=>({card:s,item:z(s)})),now:Date.now()}),[n,j.data,l.data,b.data,v,x.items,x.agents,k.data,g.attentionCards]),$=ee(g.attentionCards),R=s=>{s.length>0&&g.markManyRead.mutateAsync(s)},h=d.trim().toLowerCase(),L=r||h.length>0,E=f.useMemo(()=>te(S.filter(s=>(!r||s.attention.length>0)&&(!h||s.name.toLowerCase().includes(h))),{filtering:L,kinds:o?["automation","connection"]:["automation","connection","agent"]}),[S,r,h,L,o]),w=f.useMemo(()=>C.filter(({item:s})=>!h||s.title.toLowerCase().includes(h)),[C,h]),B=f.useMemo(()=>w.map(({item:s})=>s),[w]),p=se(o?null:a,B),O=new Set(p.pageRows.map(({item:s})=>s.id)),y=r?w.filter(({item:s})=>!O.has(s.id)):[],F={automation:j.isLoading,connection:l.isLoading||b.isLoading||K,agent:!o&&(x.isLoading||k.isLoading)},Y=a==null||j.isLoading||l.isLoading||!o&&(x.isLoading||g.isLoading),G=j.isError||l.isError||b.isError||x.isError||g.isError,A=E.every(s=>s.count===0)&&p.pageRows.length===0&&p.feeds.length===0&&y.length===0;return e.jsxs("section",{"aria-label":"Home",className:"flex min-w-0 flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(ne,{"aria-hidden":"true",className:"absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(ae,{type:"search","aria-label":"Search sources",placeholder:"Search",maxLength:512,value:d,onChange:s=>N(s.target.value),className:"h-8 pl-9"})]}),o?null:e.jsxs("select",{"aria-label":"Show",className:H("h-8 shrink-0 rounded-md border bg-background px-2 text-sm",r&&"border-primary"),value:r?"needs-you":"all",onChange:s=>i(s.target.value==="needs-you"),children:[e.jsx("option",{value:"all",children:"All activity"}),e.jsxs("option",{value:"needs-you",children:["Needs you (",$,")"]})]})]}),r&&!h?e.jsx(oe,{owner:n,showMarkRead:!1}):null,G?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"Some activity could not be loaded. Refresh to try again."}):null,Y&&A?e.jsx(Re,{}):A&&L?e.jsx(ie,{icon:re,title:r&&!h?"All caught up":"Nothing matches",description:r&&!h?"Nothing needs you right now.":"No source matches this search."}):e.jsxs(e.Fragment,{children:[p.pageRows.length>0||p.feeds.length>0?e.jsx("section",{"aria-label":"This page",className:"space-y-1",children:e.jsx(le,{owner:n,organizationId:a,feeds:p.feeds,rows:p.pageRows})}):null,E.map(s=>F[s.kind]?e.jsx(Ee,{label:s.label},s.kind):e.jsx(Ae,{owner:n,organizationId:a,section:s,expanded:r,onMarkRead:R,connectorDefinitions:v},s.kind)),y.length>0?e.jsxs("section",{"aria-label":"Other",className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 px-1 pt-4 pb-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold",children:"Other"}),e.jsx(D,{entries:y,onMarkRead:R})]}),e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:y.map(({item:s,repeats:M})=>e.jsx("li",{children:e.jsx(T,{owner:n,item:s,variant:"row",tag:M>1?`${M}×`:void 0})},s.id))})]}):null]})]})}function D({entries:n,onMarkRead:a,disabled:t=!1}){const i=n.filter(m=>m.unreadIds.length>0);return i.length===0?null:e.jsxs("button",{type:"button",disabled:t,className:"ml-auto inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:()=>a(i.flatMap(m=>m.unreadIds)),children:[e.jsx(de,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Mark ",i.length," read"]})}function Re(){return e.jsx("div",{role:"status","aria-label":"Loading Home",children:[0,1,2].map(n=>e.jsxs("div",{children:[e.jsx("div",{className:"px-1 pt-4 pb-1.5",children:e.jsx(ce,{className:"h-4 w-24"})}),e.jsx("div",{className:"divide-y overflow-hidden rounded-lg border",children:[0,1,2].map(a=>e.jsx(P,{},a))})]},n))})}function Ee({label:n}){return e.jsxs("section",{"aria-label":n,className:"min-w-0",children:[e.jsx("div",{className:"px-1 pt-4 pb-1.5",children:e.jsx("h2",{className:"text-sm font-semibold",children:n})}),e.jsx("div",{role:"status","aria-label":`Loading ${n}`,className:"divide-y overflow-hidden rounded-lg border",children:[0,1,2].map(a=>e.jsx(P,{},a))})]})}function Ae({owner:n,organizationId:a,section:t,expanded:i,onMarkRead:m,connectorDefinitions:u}){const c=i?t.rows.flatMap(o=>o.attention):[];return e.jsxs("section",{"aria-label":t.label,className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 px-1 pt-4 pb-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold",children:t.label}),e.jsxs(_,{to:Se[t.kind],params:{owner:n},className:"text-xs text-muted-foreground hover:text-foreground",children:["See all ",t.count," →"]}),e.jsx(D,{entries:c,onMarkRead:m})]}),t.count===0?e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:Ce[t.kind]}):null,e.jsx("ul",{className:H("overflow-hidden rounded-lg border",t.rows.length===0&&"hidden"),children:t.rows.map(o=>e.jsxs("li",{className:"border-b last:border-b-0",children:[e.jsx(Me,{owner:n,organizationId:a,source:o,itemsShown:i,connectorDefinitions:u}),i&&o.attention.length>0?e.jsx("ul",{className:"divide-y border-t pl-10",children:o.attention.map(({item:r,repeats:d})=>e.jsx("li",{children:e.jsx(T,{owner:n,item:r,variant:"row",showMark:!1,tag:d>1?`${d}×`:void 0})},r.id))}):null]},o.key))})]})}function Me({owner:n,organizationId:a,source:t,itemsShown:i,connectorDefinitions:m}){const u=we[t.kind];return e.jsx(He,{owner:n,organizationId:a,source:t,className:ge,children:e.jsx(xe,{mark:e.jsx(pe,{source:t.mark,connectorDefinitions:m,label:t.name,fallback:e.jsx(u,{className:"h-4 w-4 text-muted-foreground"})}),name:t.name,tone:t.attention.length>0?"amber":t.problem?"destructive":null,details:e.jsxs(e.Fragment,{children:[t.status,i?null:e.jsx(Ie,{attention:t.attention})]}),at:t.at})})}function Ie({attention:n}){const a=n[0];if(!a)return null;const t=n.length-1;return e.jsxs("span",{children:[" · Needs you: ",a.card.title,a.repeats>1?` (${a.repeats}×)`:"",t>0?` +${t} more`:""]})}function He({owner:n,organizationId:a,source:t,className:i,children:m}){const u=fe(),{open:c}=t,o=je(c.href),r=d=>{if(!(!u||c.kind==="page"||d.metaKey||d.ctrlKey||d.shiftKey||d.altKey||d.button!==0)&&!(c.kind==="connection"&&!a)){if(d.preventDefault(),c.kind==="automation"){u.open({href:c.href,title:t.name,owner:n});return}u.open({href:c.href,title:t.name,key:t.key,connectorPanel:{section:c.section,connectorKey:c.connectorKey,connectionId:c.connectionId,organizationId:a,ownerSlug:n}})}};return e.jsx(_,{to:o.pathname,search:o.search,className:i,onClick:r,children:m})}export{Be as H,D as M};
2
+ //# sourceMappingURL=home-stream-IVsNEkwp.js.map
@@ -0,0 +1,2 @@
1
+ import{av as e,aw as s,j as t,ak as p,al as a}from"./index-B-Ab8srM.js";import{A as n}from"./activity-route-view-B0m7_g9q.js";import{E as c}from"./events-feed-zFnTSE27.js";import"./record-activity-6CfR95Ul.js";import"./filter-editors-Dd5R2Etd.js";import"./runs-BMzp7j7j.js";import"./source-record-panels-CBV9tsR3.js";import"./event-card-BtTUuf2q.js";import"./definition-comparison-C3k6Wa9B.js";import"./automation-source-list-D8ZSavQU.js";import"./schema-value-BUgC0Ro8.js";import"./json-diff-B-1Swv_y.js";import"./index-Vcq4gwWv.js";import"./run-initiator-BvruBM5H.js";import"./use-automations-II_YJWtN.js";import"./clients-6aJvabvS.js";import"./renderer-CgaQKMoG.js";import"./card-DT9mSjSp.js";import"./table-B6yimlsZ.js";import"./change-summary-CGrKEJ04.js";import"./copy-button-D6zpsZLi.js";import"./agent-list-row-SyACVYX7.js";import"./automation-row-CmTpAD4r.js";import"./device-automation-Dp3faMvp.js";import"./client-activity-scopes-DoIErdUy.js";import"./client-rows-BbVQy5Ti.js";import"./agent-loading-shells-DHvKiEUB.js";import"./member-scope-gate-Lj9m4RL2.js";import"./home-stream-IVsNEkwp.js";import"./list-skeleton-BAqT0vxo.js";import"./public-shell-ready-Dlh-eWz0.js";function G(){const{owner:r}=e.useParams(),i=e.useSearch();if(r==="me"){const o=s(i),m={sortBy:"date",sortOrder:"desc",...o.contentIds?.length?{contentIds:o.contentIds}:{clientIds:o.clientIds,mcpActivityId:o.mcpActivityId}};return t.jsx(p,{className:"gap-6 pt-2.5 pb-8",children:t.jsxs(a,{className:"flex flex-col gap-6",children:[t.jsx("h1",{className:"text-lg font-semibold",children:"Your MCP activity"}),t.jsx(c,{organizationId:null,ownerSlug:"me",filters:m})]})})}return t.jsx(n,{owner:r,search:i})}export{G as component};
2
+ //# sourceMappingURL=index-2oaMOFKe.js.map