@lobu/runtime-server 24.7.0 → 24.8.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 (229) hide show
  1. package/dist/catalogs/connectors.json +199 -316
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/imessage.ts +953 -0
  4. package/dist/connectors/linkedin.ts +20 -377
  5. package/dist/dependencies.bun.lock +124 -92
  6. package/dist/embeddings-server.mjs +14 -2
  7. package/dist/owletto/dist/assets/_-B0tmXZ86.js +2 -0
  8. package/dist/owletto/dist/assets/_-DwXULq4r.js +3 -0
  9. package/dist/owletto/dist/assets/_agentId-B1dNkhnr.js +2 -0
  10. package/dist/owletto/dist/assets/_agentId-sYjvnBaB.js +2 -0
  11. package/dist/owletto/dist/assets/_automationId-Bnw_CnT_.js +2 -0
  12. package/dist/owletto/dist/assets/_connectorKey._connectionId-D7Z8DQ-B.js +2 -0
  13. package/dist/owletto/dist/assets/_connectorKey.index-DM5MTO8c.js +2 -0
  14. package/dist/owletto/dist/assets/_conversationId-OJrZjd0o.js +2 -0
  15. package/dist/owletto/dist/assets/_eventId-CfB0_2zK.js +2 -0
  16. package/dist/owletto/dist/assets/_owner-BDvTUY0a.js +3 -0
  17. package/dist/owletto/dist/assets/_shape-BZidoJMB.js +2 -0
  18. package/dist/owletto/dist/assets/_slug-R989vOiM.js +2 -0
  19. package/dist/owletto/dist/assets/_viewKey-BDUSrpe5.js +2 -0
  20. package/dist/owletto/dist/assets/_viewKey-BnFqh5-t.js +2 -0
  21. package/dist/owletto/dist/assets/{accept-invitation-CX7Egv-p.js → accept-invitation-BC-ZIsrf.js} +2 -2
  22. package/dist/owletto/dist/assets/activity-route-view-CN2dOiCD.js +2 -0
  23. package/dist/owletto/dist/assets/agent-connect-pages-CdDjrHjn.js +4 -0
  24. package/dist/owletto/dist/assets/agent-editor-form-CDAHRNWl.js +2 -0
  25. package/dist/owletto/dist/assets/{agent-loading-shells-DHvKiEUB.js → agent-loading-shells-BupiSjR-.js} +2 -2
  26. package/dist/owletto/dist/assets/agent-permissions-matrix-ju7L2M0l.js +2 -0
  27. package/dist/owletto/dist/assets/{agent-skill-context-DF5q0Dfr.js → agent-skill-context-B0ZYVE3n.js} +2 -2
  28. package/dist/owletto/dist/assets/{agent-subpage-shell-Pi5cECga.js → agent-subpage-shell-ByU0xhXn.js} +2 -2
  29. package/dist/owletto/dist/assets/{agent-thread-B1ZepGZc.js → agent-thread-DiVKn1WX.js} +4 -4
  30. package/dist/owletto/dist/assets/agent-thread-storage-Bx2-WBHQ.js +2 -0
  31. package/dist/owletto/dist/assets/app._appId-BQWElSoP.js +2 -0
  32. package/dist/owletto/dist/assets/assist-composer-igTXq3DL.js +2 -0
  33. package/dist/owletto/dist/assets/automation-detail-content-BJwRU6qT.js +2 -0
  34. package/dist/owletto/dist/assets/{callback-Ckrxv0eo.js → callback-Dmaio9CX.js} +2 -2
  35. package/dist/owletto/dist/assets/{card-DT9mSjSp.js → card-rE4Ctuy6.js} +2 -2
  36. package/dist/owletto/dist/assets/{claim-Bzby28tT.js → claim-BN17CPYh.js} +2 -2
  37. package/dist/owletto/dist/assets/{client-activity-scopes-DoIErdUy.js → client-activity-scopes-B7xVaUA-.js} +2 -2
  38. package/dist/owletto/dist/assets/{client-rows-BbVQy5Ti.js → client-rows-B3LULJxW.js} +2 -2
  39. package/dist/owletto/dist/assets/clients-CydgUHrc.js +2 -0
  40. package/dist/owletto/dist/assets/code-editor-UppEMWpt.js +26 -0
  41. package/dist/owletto/dist/assets/connect-OdHpIVV9.js +2 -0
  42. package/dist/owletto/dist/assets/connect-menu-B9u86bb2.js +2 -0
  43. package/dist/owletto/dist/assets/connect._clientId-EI1tcdSE.js +2 -0
  44. package/dist/owletto/dist/assets/connected._clientId-CaF-ZWlZ.js +2 -0
  45. package/dist/owletto/dist/assets/{connection-BOaMa324.js → connection-D8ZAMHBT.js} +2 -2
  46. package/dist/owletto/dist/assets/connection-feed-detail-CJYqryAV.js +2 -0
  47. package/dist/owletto/dist/assets/connector-boxes-BWPXijAk.js +2 -0
  48. package/dist/owletto/dist/assets/connector-page-shell-C23dWdKz.js +2 -0
  49. package/dist/owletto/dist/assets/connector-provenance-CW4CXtCz.js +2 -0
  50. package/dist/owletto/dist/assets/{connectors-D5F5rHxX.js → connectors-Bp08_KPq.js} +2 -2
  51. package/dist/owletto/dist/assets/consent-_PpYI1cT.js +2 -0
  52. package/dist/owletto/dist/assets/copy-button-1ALlvZU1.js +2 -0
  53. package/dist/owletto/dist/assets/{core.esm-BIE97rfo.js → core.esm-6koO33th.js} +2 -2
  54. package/dist/owletto/dist/assets/create-DULVO0HS.js +2 -0
  55. package/dist/owletto/dist/assets/create-Drx9tcnG.js +2 -0
  56. package/dist/owletto/dist/assets/{create-automation-form-B12yTrmj.js → create-automation-form-BhujNbRr.js} +3 -3
  57. package/dist/owletto/dist/assets/{create-BPxsKwk7.js → create-kUevP9Xx.js} +2 -2
  58. package/dist/owletto/dist/assets/create._connectorKey-N6fhcIPy.js +2 -0
  59. package/dist/owletto/dist/assets/{custom-guardrail-edits-B9plaLBN.js → custom-guardrail-edits-B_aCgvoZ.js} +2 -2
  60. package/dist/owletto/dist/assets/definition-comparison-3zKUSTt8.js +2 -0
  61. package/dist/owletto/dist/assets/{detail-page-skeleton-I5_7FkKx.js → detail-page-skeleton-BmxqqIsH.js} +2 -2
  62. package/dist/owletto/dist/assets/{device-CadaiNF4.js → device-D2eUt_nr.js} +2 -2
  63. package/dist/owletto/dist/assets/device-pin-tombstone-BFPbTM_o.js +2 -0
  64. package/dist/owletto/dist/assets/device._deviceId-Dqtmb1Xp.js +2 -0
  65. package/dist/owletto/dist/assets/dynamic-schema-form-D3KnzCsW.js +2 -0
  66. package/dist/owletto/dist/assets/entity-options-IUdQ-64R.js +2 -0
  67. package/dist/owletto/dist/assets/entity-page-B3Im65EI.js +2 -0
  68. package/dist/owletto/dist/assets/entity-pages-DJNSQrfB.js +2 -0
  69. package/dist/owletto/dist/assets/entity-type-page-CouHZbc9.js +2 -0
  70. package/dist/owletto/dist/assets/event-detail-CvaRN1qB.js +2 -0
  71. package/dist/owletto/dist/assets/event-kind-options-fHAIXu24.js +2 -0
  72. package/dist/owletto/dist/assets/events-feed-DwOkLk6A.js +2 -0
  73. package/dist/owletto/dist/assets/filter-editors-DQ5V4Cvh.js +2 -0
  74. package/dist/owletto/dist/assets/{full-page-spinner-CCU4PkRv.js → full-page-spinner-B7A6Ycyi.js} +2 -2
  75. package/dist/owletto/dist/assets/home-stream-Bg97PUBJ.js +2 -0
  76. package/dist/owletto/dist/assets/home-toolbar-CpCcHA6z.js +2 -0
  77. package/dist/owletto/dist/assets/index-9PGnv4-5.js +2 -0
  78. package/dist/owletto/dist/assets/{index-pmr1WUoG.js → index-B-dZruj6.js} +2 -2
  79. package/dist/owletto/dist/assets/index-BztXeLBN.js +2 -0
  80. package/dist/owletto/dist/assets/{index-B-Ab8srM.js → index-C2TCKJDP.js} +1599 -1597
  81. package/dist/owletto/dist/assets/index-C7QM3aqU.js +2 -0
  82. package/dist/owletto/dist/assets/index-CWn46a4y.js +2 -0
  83. package/dist/owletto/dist/assets/index-CxJONizf.js +2 -0
  84. package/dist/owletto/dist/assets/index-DJhb3li3.js +2 -0
  85. package/dist/owletto/dist/assets/{index-B72KYdN1.js → index-DXfYVs5m.js} +2 -2
  86. package/dist/owletto/dist/assets/{index-BYFDMIQC.js → index-DY-YGnCe.js} +2 -2
  87. package/dist/owletto/dist/assets/index-j3v7ITPb.js +2 -0
  88. package/dist/owletto/dist/assets/index-oiy6ygaI.js +2 -0
  89. package/dist/owletto/dist/assets/index-pEgtAY1t.js +2 -0
  90. package/dist/owletto/dist/assets/index-xAvK3IyQ.css +1 -0
  91. package/dist/owletto/dist/assets/json-diff-CJK-gzCt.js +4 -0
  92. package/dist/owletto/dist/assets/{list-skeleton-BAqT0vxo.js → list-skeleton-bQAZ0hQp.js} +2 -2
  93. package/dist/owletto/dist/assets/{login-D5bIjMtf.js → login-DLqL54Rk.js} +2 -2
  94. package/dist/owletto/dist/assets/{logout-JYZvxz8v.js → logout-H0F3IfiO.js} +2 -2
  95. package/dist/owletto/dist/assets/member-scope-gate-Doic_6qX.js +2 -0
  96. package/dist/owletto/dist/assets/memory-browse-page-CUea2Llz.js +74 -0
  97. package/dist/owletto/dist/assets/model-selector-BrfaDwIg.js +2 -0
  98. package/dist/owletto/dist/assets/new-5GkxlOuQ.js +2 -0
  99. package/dist/owletto/dist/assets/{new-B-Jd-vBl.js → new-BiA4DGoN.js} +2 -2
  100. package/dist/owletto/dist/assets/new-M-MX_T5C.js +2 -0
  101. package/dist/owletto/dist/assets/organization-CLrcmgNK.js +2 -0
  102. package/dist/owletto/dist/assets/peek-pane-content-B29OcHwm.js +2 -0
  103. package/dist/owletto/dist/assets/{pending-seed-CoFPQ835.js → pending-seed-DYYOoCvj.js} +2 -2
  104. package/dist/owletto/dist/assets/proposal-review-shell-BVwOMoq9.js +2 -0
  105. package/dist/owletto/dist/assets/public-shell-ready-BbjPgh3k.js +2 -0
  106. package/dist/owletto/dist/assets/record-activity-BCpNKaUo.js +2 -0
  107. package/dist/owletto/dist/assets/{record-session-Bpx4_LGk.js → record-session-KuEDuF3S.js} +2 -2
  108. package/dist/owletto/dist/assets/{renderer-CgaQKMoG.js → renderer-ucwCQmBk.js} +2 -2
  109. package/dist/owletto/dist/assets/{reset-password-C-4Jnuqk.js → reset-password-BkiAmXZW.js} +2 -2
  110. package/dist/owletto/dist/assets/run-initiator-8vdkq-3o.js +2 -0
  111. package/dist/owletto/dist/assets/{runs-BMzp7j7j.js → runs-B_iywKWb.js} +2 -2
  112. package/dist/owletto/dist/assets/runs-list-CJJFRhTl.js +2 -0
  113. package/dist/owletto/dist/assets/schema-type-editor-panel-C4e8pq1A.js +2 -0
  114. package/dist/owletto/dist/assets/{schema-value-BUgC0Ro8.js → schema-value-CefbtPIY.js} +3 -3
  115. package/dist/owletto/dist/assets/scoped-feed-bar-CapleZvS.js +2 -0
  116. package/dist/owletto/dist/assets/{settings-DYYvrrZ4.js → settings-DvzkRYQy.js} +2 -2
  117. package/dist/owletto/dist/assets/source-record-panels-LJIWGtHb.js +2 -0
  118. package/dist/owletto/dist/assets/{status-variants-DT61YfsU.js → status-variants-BxHtpMOj.js} +2 -2
  119. package/dist/owletto/dist/assets/subDays-DwIOMzYC.js +2 -0
  120. package/dist/owletto/dist/assets/{table-B6yimlsZ.js → table-1O-ik4_O.js} +2 -2
  121. package/dist/owletto/dist/assets/{use-automations-II_YJWtN.js → use-automations-lV8PuE8L.js} +2 -2
  122. package/dist/owletto/dist/assets/use-login-redirect-CfCbEeJR.js +2 -0
  123. package/dist/owletto/dist/assets/use-mention-search-CA-evCDf.js +91 -0
  124. package/dist/owletto/dist/assets/{view-param-filters-DYlqBocg.js → view-param-filters-Bp84PUMd.js} +2 -2
  125. package/dist/owletto/dist/assets/{views-access-required-BVtMfgLh.js → views-access-required-BerT4Z1d.js} +2 -2
  126. package/dist/owletto/dist/index.html +2 -2
  127. package/dist/server-main.bundle.mjs +274 -136
  128. package/npm-shrinkwrap.json +540 -447
  129. package/package.json +4 -2
  130. package/vendor/connector-sdk/package.json +1 -1
  131. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  132. package/vendor/core/dist/connector-query-errors.js +4 -0
  133. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -0
  134. package/vendor/core/dist/contracts/tools/manage-entity.js +7 -0
  135. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +2 -0
  136. package/vendor/core/dist/contracts/tools/manage-feeds.js +3 -0
  137. package/vendor/core/dist/contracts/tools/view-host.js +2 -0
  138. package/vendor/core/dist/error-report.js +1 -0
  139. package/vendor/core/package.json +1 -1
  140. package/vendor/views/package.json +1 -1
  141. package/dist/connectors/linkedin-takeout.ts +0 -577
  142. package/dist/connectors/takeout-utils.ts +0 -240
  143. package/dist/owletto/dist/assets/_-CZgmjLR9.js +0 -2
  144. package/dist/owletto/dist/assets/_-Cm5OgtYD.js +0 -3
  145. package/dist/owletto/dist/assets/_-DtqBFgK5.js +0 -2
  146. package/dist/owletto/dist/assets/_agentId-Cci6NFc1.js +0 -2
  147. package/dist/owletto/dist/assets/_agentId-GhWTlPO2.js +0 -2
  148. package/dist/owletto/dist/assets/_automationId-KUlxSTK2.js +0 -2
  149. package/dist/owletto/dist/assets/_connectorKey._connectionId-Zpy7Hvml.js +0 -2
  150. package/dist/owletto/dist/assets/_connectorKey.index-CYDRp9UX.js +0 -2
  151. package/dist/owletto/dist/assets/_conversationId-NNqDdije.js +0 -2
  152. package/dist/owletto/dist/assets/_eventId-0BSX6VHj.js +0 -2
  153. package/dist/owletto/dist/assets/_owner-C-CD22NB.js +0 -3
  154. package/dist/owletto/dist/assets/_shape-CvXp4omb.js +0 -2
  155. package/dist/owletto/dist/assets/_slug-DgK7zpKA.js +0 -2
  156. package/dist/owletto/dist/assets/_viewKey-cH54P0zY.js +0 -2
  157. package/dist/owletto/dist/assets/_viewKey-m0B5j7L9.js +0 -2
  158. package/dist/owletto/dist/assets/activity-link-rXNpmppV.js +0 -2
  159. package/dist/owletto/dist/assets/activity-route-view-B0m7_g9q.js +0 -2
  160. package/dist/owletto/dist/assets/agent-client-setup-list-BmD3-_Ox.js +0 -4
  161. package/dist/owletto/dist/assets/agent-connect-pages-BtOTCsTU.js +0 -2
  162. package/dist/owletto/dist/assets/agent-editor-form-CirqCpcM.js +0 -2
  163. package/dist/owletto/dist/assets/agent-list-row-SyACVYX7.js +0 -2
  164. package/dist/owletto/dist/assets/agent-permissions-matrix-Dsc26dyW.js +0 -2
  165. package/dist/owletto/dist/assets/agent-thread-storage-U6htL3ad.js +0 -2
  166. package/dist/owletto/dist/assets/agents-D1FHZ0jR.js +0 -2
  167. package/dist/owletto/dist/assets/app._appId-01I0CJal.js +0 -2
  168. package/dist/owletto/dist/assets/assist-composer-BD9msDk3.js +0 -2
  169. package/dist/owletto/dist/assets/automation-detail-content-BFv1TglZ.js +0 -2
  170. package/dist/owletto/dist/assets/automation-row-CmTpAD4r.js +0 -2
  171. package/dist/owletto/dist/assets/automation-source-list-D8ZSavQU.js +0 -2
  172. package/dist/owletto/dist/assets/automations-D1FHZ0jR.js +0 -2
  173. package/dist/owletto/dist/assets/change-summary-CGrKEJ04.js +0 -2
  174. package/dist/owletto/dist/assets/clients-6aJvabvS.js +0 -2
  175. package/dist/owletto/dist/assets/connect-BmDziBzI.js +0 -2
  176. package/dist/owletto/dist/assets/connect-menu-Bs8mxsga.js +0 -2
  177. package/dist/owletto/dist/assets/connect._clientId-t5aKu3aa.js +0 -2
  178. package/dist/owletto/dist/assets/connected._clientId-DswMAw8l.js +0 -2
  179. package/dist/owletto/dist/assets/connection-feed-detail-BLCjhP-H.js +0 -2
  180. package/dist/owletto/dist/assets/connector-boxes-BAP_f77M.js +0 -2
  181. package/dist/owletto/dist/assets/connector-page-shell-ClOmVPJr.js +0 -2
  182. package/dist/owletto/dist/assets/connector-provenance-wmYu5jwO.js +0 -2
  183. package/dist/owletto/dist/assets/consent-RqHNkmm8.js +0 -2
  184. package/dist/owletto/dist/assets/copy-button-D6zpsZLi.js +0 -2
  185. package/dist/owletto/dist/assets/create-GT8_yF0R.js +0 -2
  186. package/dist/owletto/dist/assets/create-Yx2qBMBy.js +0 -2
  187. package/dist/owletto/dist/assets/create._connectorKey-CzXqSkuI.js +0 -2
  188. package/dist/owletto/dist/assets/definition-comparison-C3k6Wa9B.js +0 -2
  189. package/dist/owletto/dist/assets/device-pin-tombstone-U7Bx05P6.js +0 -2
  190. package/dist/owletto/dist/assets/device._deviceId-DTZqj1HS.js +0 -2
  191. package/dist/owletto/dist/assets/dynamic-schema-form-DyT_9iVE.js +0 -2
  192. package/dist/owletto/dist/assets/entity-options-CGTjLlcS.js +0 -2
  193. package/dist/owletto/dist/assets/entity-page-DHHMmA8V.js +0 -2
  194. package/dist/owletto/dist/assets/entity-pages-eYbG2FDT.js +0 -2
  195. package/dist/owletto/dist/assets/entity-type-page-CjFqxSdL.js +0 -2
  196. package/dist/owletto/dist/assets/event-card-BtTUuf2q.js +0 -2
  197. package/dist/owletto/dist/assets/event-detail-8xHiplt_.js +0 -2
  198. package/dist/owletto/dist/assets/events-feed-zFnTSE27.js +0 -2
  199. package/dist/owletto/dist/assets/filter-editors-Dd5R2Etd.js +0 -2
  200. package/dist/owletto/dist/assets/home-stream-IVsNEkwp.js +0 -2
  201. package/dist/owletto/dist/assets/index-2oaMOFKe.js +0 -2
  202. package/dist/owletto/dist/assets/index-B4RZgvvI.js +0 -2
  203. package/dist/owletto/dist/assets/index-BBZM53p8.js +0 -2
  204. package/dist/owletto/dist/assets/index-BOb0a5f9.js +0 -2
  205. package/dist/owletto/dist/assets/index-BwnFQcMe.js +0 -2
  206. package/dist/owletto/dist/assets/index-CvYsWYlF.js +0 -2
  207. package/dist/owletto/dist/assets/index-DIXIvtnM.js +0 -2
  208. package/dist/owletto/dist/assets/index-DLwokXHW.js +0 -2
  209. package/dist/owletto/dist/assets/index-_nlPHus1.js +0 -2
  210. package/dist/owletto/dist/assets/index-cwOgj4-i.js +0 -2
  211. package/dist/owletto/dist/assets/index-pp4qmhkA.js +0 -2
  212. package/dist/owletto/dist/assets/index-tTbno-PX.css +0 -1
  213. package/dist/owletto/dist/assets/json-diff-B-1Swv_y.js +0 -28
  214. package/dist/owletto/dist/assets/member-scope-gate-Lj9m4RL2.js +0 -2
  215. package/dist/owletto/dist/assets/memory-browse-page-rAKfVdQ_.js +0 -74
  216. package/dist/owletto/dist/assets/model-selector-onvGA9Ww.js +0 -2
  217. package/dist/owletto/dist/assets/new-BmehH1uR.js +0 -2
  218. package/dist/owletto/dist/assets/new-KDi15LWZ.js +0 -2
  219. package/dist/owletto/dist/assets/organization-B9bh20Xo.js +0 -2
  220. package/dist/owletto/dist/assets/peek-pane-content-Bqus80Mq.js +0 -2
  221. package/dist/owletto/dist/assets/proposal-review-shell-CnACXCUg.js +0 -2
  222. package/dist/owletto/dist/assets/public-shell-ready-Dlh-eWz0.js +0 -2
  223. package/dist/owletto/dist/assets/record-activity-6CfR95Ul.js +0 -2
  224. package/dist/owletto/dist/assets/run-initiator-BvruBM5H.js +0 -2
  225. package/dist/owletto/dist/assets/runs-list-DVhrTr3v.js +0 -2
  226. package/dist/owletto/dist/assets/schema-type-editor-panel-Bdeumkux.js +0 -2
  227. package/dist/owletto/dist/assets/source-record-panels-CBV9tsR3.js +0 -2
  228. package/dist/owletto/dist/assets/use-login-redirect-BqtEilid.js +0 -2
  229. package/dist/owletto/dist/assets/use-mention-search-Bxlpd6Dp.js +0 -96
@@ -0,0 +1,2 @@
1
+ import{aU as F,iU as ne,iV as U,r as v,j as e,iW as P,B as b,ai as L,iX as C,ct as V,aH as te,hV as z,m as Y,b8 as M,h3 as ae,h4 as ie,C as ce,h6 as oe,dC as re,iY as le,a8 as de,c as me,aM as ue,iZ as xe,i_ as he,i$ as pe,aN as fe,aI as ge,as as A,b7 as T,L as E,j0 as je,j1 as ve,a_ as ye,j2 as be,j3 as Ne,a3 as _e,cu as ke,iQ as q,U as we,c1 as Ce,cL as Se,cw as $e,cx as K,d3 as De,j4 as O,aF as Pe}from"./index-C2TCKJDP.js";import{C as Le}from"./connector-page-shell-C23dWdKz.js";import{D as ze,R as Ie}from"./detail-page-skeleton-BmxqqIsH.js";import{S as Ae,g as Ee}from"./status-variants-BxHtpMOj.js";import{c as G,C as Re}from"./device-pin-tombstone-BFPbTM_o.js";import{w as R}from"./workspace-label-o_QfBuCM.js";import"./list-skeleton-bQAZ0hQp.js";import"./runs-B_iywKWb.js";import"./filter-editors-DQ5V4Cvh.js";import"./subDays-DwIOMzYC.js";import"./runs-list-CJJFRhTl.js";import"./run-initiator-8vdkq-3o.js";import"./use-automations-lV8PuE8L.js";import"./clients-CydgUHrc.js";function Me(s,n,o){const h=new Set(s.capabilities??[]),m=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key)),r=new Set(Q(s,o).map(t=>t.connector_key));return n.filter(t=>F(t)&&!!t.required_capability&&h.has(t.required_capability)&&!m.has(t.key)&&!r.has(t.key))}function Q(s,n){return s.organization_slug===n?s.update_required:[]}function Be(s,n,o){const h=s.organization_slug;if(!h||h===o)return[];const m=new Set(n.map(t=>t.key)),r=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key));return s.connectors.filter(t=>t.organization_slug!==h||m.has(t.connector_key)||r.has(t.connector_key)?!1:(r.add(t.connector_key),!0))}function Te({device:s,organizationId:n,ownerSlug:o,connectable:h,unavailable:m}){const r=ne(),t=U(),[u,p]=v.useState(null),[g,a]=v.useState(null),[f,N]=v.useState(null),[j,d]=v.useState([]),x=s.organization_id===n,y=async i=>{p(null),N(null),a(i.key);try{x||await t.mutateAsync({deviceWorkerId:s.id,organizationId:n});const w=await r.mutateAsync({connector_key:i.key,device_worker_id:s.id}),S=w.connection_id??w.connection?.id;if(S===void 0)throw new Error(w.instructions??"The connection was not created.");d($=>[...$.filter(D=>D.connectorKey!==i.key),{connectorKey:i.key,name:i.name,connectionId:S,instructions:w.status==="setup_required"?w.instructions:void 0}])}catch(w){N({key:i.key,message:w instanceof Error?w.message:"Could not connect."})}finally{a(null)}},_=new Set(j.map(i=>i.connectorKey)),l=Q(s,o),c=h.filter(i=>!_.has(i.key));return e.jsxs("div",{className:"mt-4 space-y-3",children:[j.map(i=>e.jsx(qe,{outcome:i,device:s,organizationId:n},i.connectorKey)),c.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Supported by this device"}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Not connected in this workspace yet.",x?null:" Connecting one moves the device here; you will be asked to confirm first."]}),e.jsx("div",{className:"divide-y border-y",children:c.map(i=>e.jsxs("div",{className:"space-y-2 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-sm font-medium",children:[i.name,i.required_capability&&P[i.required_capability]&&P[i.required_capability]!==i.name?e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:P[i.required_capability]}):null]}),e.jsxs(b,{size:"sm",variant:"outline","aria-label":`Connect ${i.name}`,disabled:g!==null,onClick:()=>x?void y(i):p(i.key),children:[g===i.key?e.jsx(L,{className:"mr-1.5"}):null,"Connect"]})]}),u===i.key?e.jsx(X,{device:s,ownerSlug:o,title:"Move device to this workspace",intro:`${C(s)} lives in ${s.organization_name??"another workspace"}. A device serves one workspace at a time, so it has to move here before it can be connected.`,confirmLabel:"Move here and connect",onConfirm:()=>void y(i),onCancel:()=>p(null)}):null,f?.key===i.key?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.message}):null]},i.key))})]}):null,l.length>0?e.jsxs("div",{role:"status",children:[e.jsx("p",{className:"text-xs font-medium",children:"Update Lobu on this device"}),e.jsx("ul",{className:"mt-1 space-y-1 text-xs text-muted-foreground",children:l.map(i=>e.jsx("li",{children:`${i.display_name} — this device has ${i.device_version}, this workspace uses ${i.workspace_version}`},i.connector_key))})]}):null,m.length>0?e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:m.map(i=>e.jsx("li",{children:`${i.display_name} — set up on this device in ${s.organization_name??"its home workspace"}, not available in this workspace yet`},i.connector_key))}):null]})}function X({device:s,ownerSlug:n,title:o,intro:h,aftermath:m,confirmLabel:r,pending:t=!1,onConfirm:u,onCancel:p}){const g=s.connector_count,a=s.connectors.filter(f=>f.organization_slug===n).length;return e.jsxs("div",{role:"alertdialog","aria-label":o,className:"space-y-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs",children:[e.jsx("p",{children:h}),e.jsxs("p",{className:"text-muted-foreground",children:[g>0?`Moving pauses and unpins all ${g} connection${g===1?"":"s"} pinned to it${a>0?`, including ${a} in this workspace`:""}. They stay paused until you reconnect them.`:"It has no pinned connections, so nothing is paused.",m?` ${m}`:null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{size:"sm",disabled:t,onClick:u,children:[t?e.jsx(L,{className:"mr-1.5"}):null,r]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:t,onClick:p,children:"Cancel"})]})]})}function qe({outcome:s,device:n,organizationId:o}){const{data:h=[],isLoading:m}=V(o,{connectionIds:[s.connectionId]}),r=h.find(p=>p.id===s.connectionId),t=C(n);if(m)return e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Checking ",s.name,"…"]});const u=[];if(!r)u.push(`${s.name} was created but could not be loaded yet.`);else if(r.status!=="active"){const p=G(r);u.push(`${s.name} is ${r.status}${p?`: ${p}`:"."}`)}return s.instructions&&u.push(s.instructions),n.online||u.push(`${t} is offline. ${s.name} runs once it reconnects.`),e.jsx("div",{role:"status",className:"rounded-lg border px-3 py-2 text-sm",children:u.length===0?e.jsxs("p",{children:[s.name," is ready on ",t,"."]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium",children:[s.name," connected, not ready yet"]}),e.jsx("ul",{className:"mt-1 list-disc pl-4 text-xs text-muted-foreground",children:u.map(p=>e.jsx("li",{children:p},p))})]})})}function H({device:s,organizationId:n,ownerSlug:o,selectedConnection:h,openSettings:m}){const{data:r=[],isLoading:t,isError:u,refetch:p}=te(n),g=new Map(r.map(d=>[d.key,d])),a=new Map,f=[];for(const d of s.connectors){if(d.organization_slug!==o)continue;const x=g.get(d.connector_key);if(!x||!F(x)){f.push(d);continue}const y=x.required_capability??`connector:${x.key}`,_=a.get(y)??{key:y,name:x.name,connections:[]};_.name=P[y]??x.name,_.connections.push(d),a.set(y,_)}const N=Me(s,r,o),j=Be(s,r,o);return e.jsxs(e.Fragment,{children:[e.jsxs(z,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),s.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!n||t?e.jsx(Y,{className:"h-24 w-full"}):u?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void p(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(d=>e.jsx(W,{group:d,deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d.key))}),n&&!t&&!u?e.jsx(Te,{device:s,organizationId:n,ownerSlug:o,connectable:N,unavailable:j}):null,M(s)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),n&&f.length>0&&!t&&!u?e.jsxs(z,{title:"Apps and sources",count:String(f.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:[...new Set(f.map(d=>d.connector_key))].map(d=>e.jsx(W,{group:{key:d,name:g.get(d)?.name??d,connections:f.filter(x=>x.connector_key===d)},deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d))})]}):null]})}function W({group:s,deviceId:n,organizationId:o,ownerSlug:h,definitionsByKey:m,selectedConnection:r,openSettings:t}){const u=s.connections.some(a=>a.connection_id===r),[p,g]=v.useState(u);return v.useEffect(()=>{u&&r!==void 0&&g(!0)},[u,r]),e.jsxs(ae,{open:p,onOpenChange:g,children:[e.jsxs(ie,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(ce,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:s.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:s.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":s.connections.length>1?`${s.connections.length} connections`:"Configured"})]}),e.jsx(oe,{className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:s.connections.map(a=>e.jsx(Ke,{summary:a,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m.get(a.connector_key),openSettings:a.connection_id===r&&t},a.connection_id))})})]})}function Ke({summary:s,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m,openSettings:r}){const{data:t=[],isLoading:u,isError:p,refetch:g}=V(o,{connectionIds:[s.connection_id]}),a=t.find(j=>j.id===s.connection_id&&j.device_worker_id===n),f=m?.name??s.connector_key,N=a?G(a):null;return e.jsxs("section",{id:`connection-${s.connection_id}`,"aria-label":f,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:re(a)}),e.jsx("span",{children:a.status})]}):null,u||!o?e.jsx(Y,{className:"h-24 w-full"}):p?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[N?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:N}):null,e.jsx("div",{className:"mb-4",children:e.jsx(le,{connection:a})}),e.jsx(Re,{connection:a,connectorDef:m,ownerSlug:h,openSettings:r,showActivity:!1,showShare:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function Oe({device:s,ownerSlug:n}){const o=v.useId(),{data:h=[]}=de(),m=U(),[r,t]=v.useState(!1),[u,p]=v.useState(null),[g,a]=v.useState(null),f=h.filter(l=>l.is_member).map(l=>({id:l.id,name:l.name,isPersonal:l.is_personal===!0})),N=f.find(l=>l.id===s.organization_id),j=N?R(N):s.organization_name??"No workspace",d=f.filter(l=>l.id!==s.organization_id),x=d.find(l=>l.id===u)??null,y=()=>{t(!1),p(null)},_=async l=>{a(null);try{await m.mutateAsync({deviceWorkerId:s.id,organizationId:l}),y()}catch(c){a(c instanceof Error?c.message:"Could not move the device.")}};return e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace: "}),j]}),!r&&d.length>0?e.jsx(b,{size:"sm",variant:"outline",onClick:()=>{a(null),t(!0)},children:"Change workspace"}):null]}),r?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:o,className:"text-xs text-muted-foreground",children:"Move to"}),e.jsxs("select",{id:o,value:u??"",disabled:m.isPending,onChange:l=>p(l.target.value||null),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Choose a workspace"}),d.map(l=>e.jsx("option",{value:l.id,children:R(l)},l.id))]}),x?null:e.jsx(b,{size:"sm",variant:"ghost",onClick:y,children:"Cancel"})]}):null,x?e.jsx(X,{device:s,ownerSlug:n,title:`Move device to ${x.name}`,intro:`Move ${C(s)} from ${j} to ${R(x)}?`,aftermath:`It is set up fresh in ${x.name}, with its connections there private to you until you share them.`,confirmLabel:"Move device",pending:m.isPending,onConfirm:()=>void _(x.id),onCancel:y}):null,g?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:g}):null]})}function He({ownerSlug:s,deviceId:n,organizationId:o,selectedConnection:h,openSettings:m}){const r=me(),{data:t=[],isLoading:u,isError:p,refetch:g}=ue(),a=xe(),f=he(),[N,j]=v.useState(!1),[d,x]=v.useState(!1),[y,_]=v.useState(""),l=pe(t,n),c=l&&fe(l,s)?l:void 0,i=c?.id??n,{data:w=[]}=ge(o,{profileKind:"browser_session"}),S=v.useMemo(()=>w.filter(k=>k.device_worker_id===i&&k.status!=="revoked"),[w,i]),$=c?.label?.trim()??"";if(v.useEffect(()=>{d||_($)},[$,d]),u)return e.jsx(ze,{label:"Loading device"});if(p)return e.jsx(A,{children:e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{children:"Could not load this device."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]})});if(!c&&l&&o)return e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{platform:M(l),className:"h-5 w-5"}),e.jsx("h1",{className:"text-base font-semibold",children:C(l)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device lives in"," ",l.organization_name??"another workspace",", not this workspace."]}),e.jsx(H,{device:l,organizationId:o,ownerSlug:s})]});if(!c)return e.jsxs(A,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const D=je(c),I=D?ve(s,D,ye()):void 0,Z=M(c),J=be(c.app_version),ee=Ne(c,J),B=()=>{const k=y.trim(),se=c.label?.trim()??"";if(k===se){x(!1);return}f.mutate({deviceWorkerId:c.id,label:k.length===0?null:k},{onSuccess:()=>x(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(Le,{header:e.jsx(ke,{breadcrumb:e.jsx($e,{crumbs:[e.jsx(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:K,children:"Connectors"},"connectors"),...I?[e.jsx(E,{to:"/$owner/connectors/app/$appId",params:{owner:s,appId:I.id},className:K,children:I.name},"app")]:[]]}),icon:e.jsx(T,{platform:Z,className:"h-5 w-5"}),title:d?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(we,{"aria-label":"Device name",value:y,onChange:k=>_(k.target.value),placeholder:C({...c,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:k=>{k.key==="Enter"?(k.preventDefault(),N||B()):k.key==="Escape"&&(j(!1),_(c.label?.trim()??""),x(!1))}}),N?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",c.connector_count>0?`and un-pins ${c.connector_count} connector${c.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(b,{variant:"destructive",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(c.id,{onSuccess:()=>{j(!1),r({to:"/$owner/connectors",params:{owner:s},search:{}})}}),children:[a.isPending?e.jsx(L,{className:"mr-1.5"}):null,a.isPending?"Removing...":"Confirm remove"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:a.isPending,onClick:()=>j(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{size:"sm",onClick:B,disabled:f.isPending,children:[f.isPending?e.jsx(L,{className:"mr-1.5"}):null,f.isPending?"Saving...":"Save"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>{_(c.label?.trim()??""),x(!1)},children:"Cancel"}),e.jsxs(b,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:f.isPending||a.isPending,onClick:()=>j(!0),children:[e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[C(c),e.jsx(b,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{j(!1),_(c.label?.trim()??""),x(!0)},children:e.jsx(Se,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${c.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),c.online?c.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:ee||void 0,caption:`Last seen ${q(new Date(c.last_seen_at),{addSuffix:!0})}${c.last_sync_at?` · Last sync ${q(new Date(c.last_sync_at),{addSuffix:!0})}`:""}`}),children:[e.jsx(Oe,{device:c,ownerSlug:s}),c.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0"}),c.connector_error_count," connector",c.connector_error_count===1?"":"s"," pinned to this device ",c.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(H,{device:c,organizationId:o,ownerSlug:s,selectedConnection:h,openSettings:m}),S.length>0?e.jsx(z,{title:"Browser auth profiles",children:e.jsx(We,{profiles:S})}):null,e.jsx(z,{title:"Runs",children:e.jsx(Ie,{scope:{deviceId:i},ownerSlug:s})})]})})}function We({profiles:s}){return s.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:s.map(n=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:n.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:n.connector_key??"Any connector"}),n.browser_kind?e.jsxs("span",{children:["· ",n.browser_kind]}):null,n.captured_at?e.jsxs("span",{title:n.captured_at,children:["· captured ",De(n.captured_at)]}):null,typeof n.cookie_count=="number"?e.jsxs("span",{children:["· ",n.cookie_count," cookie",n.cookie_count===1?"":"s"]}):null]})]}),e.jsx(Ae,{status:n.is_expired?"error":Ee(n.status),showDot:!0,children:n.is_expired?"expired":n.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},n.id))})})}function is(){const{owner:s,deviceId:n}=O.useParams(),{connection:o,settings:h}=O.useSearch();return e.jsx(Pe,{owner:s,children:({ownerSlug:m,organizationId:r})=>e.jsx(He,{ownerSlug:m,deviceId:n,organizationId:r,selectedConnection:o,openSettings:h})})}export{is as component};
2
+ //# sourceMappingURL=device._deviceId-Dqtmb1Xp.js.map
@@ -0,0 +1,2 @@
1
+ import{j as e,fi as M,T as q,a6 as ae,bg as ie,bh as re,bi as ne,bj as le,bk as ce,fC as de,gz as me,gA as E,gB as H,gC as oe,gD as k,gE as ue,B as O,c1 as U,dh as G,U as L,dx as xe,fk as be,gF as je,dq as Q,gG as fe,a4 as ye,i as z,gH as he,r as Z,e3 as Ne,e4 as ge,gI as we,e7 as Se,ec as $e,dO as R}from"./index-C2TCKJDP.js";import{d as I,h as ve,F as Oe,i as J,j as Te}from"./renderer-ucwCQmBk.js";import{T as Be,a as De,b as C,c as X,d as Ee,e as P}from"./table-1O-ik4_O.js";import{p as K,a as Ae}from"./schema-value-CefbtPIY.js";function ee(l){return l.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ie(l,r=!1){return l?Ae(l,r):r?"Pick a date and time":"Pick a date"}function V(l){if(!l)return"";const r=K(l);if(Number.isNaN(r.getTime()))return"";const s=r.getTimezoneOffset()*6e4;return new Date(r.getTime()-s).toISOString().slice(0,16)}function W(l){if(!l)return;const r=new Date(l);if(!Number.isNaN(r.getTime()))return r.toISOString()}function A(l,r){const s=r==="slug"?l.slug:l.metadata?.[r];return s==null?"":String(s)}function Y({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,includeTime:N=!1,clearable:j}){const d=r?K(r):void 0,[m,u]=Z.useState(()=>V(r).slice(11));return Z.useEffect(()=>{u(V(r).slice(11))},[r]),e.jsx("div",{className:"relative",children:e.jsxs(Ne,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",disabled:a,className:z("w-full justify-start rounded-md bg-muted px-3 text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(we,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:Ie(r,N)})]})}),e.jsxs(Se,{className:"w-auto space-y-3 p-0",align:"start",children:[e.jsx($e,{mode:"single",selected:d,defaultMonth:d,onSelect:i=>{if(!i)return;if(!N){s(R(i,"yyyy-MM-dd"));return}const t=m||"00:00";s(W(`${R(i,"yyyy-MM-dd")}T${t}`))},initialFocus:!0}),N?e.jsxs("div",{className:"border-t p-3 pt-0",children:[e.jsx(q,{htmlFor:`${l}-time`,className:"text-xs text-muted-foreground",children:"Time"}),e.jsx(L,{id:`${l}-time`,type:"time",value:m,onChange:i=>{u(i.target.value);const t=r?V(r).slice(0,10):d?R(d,"yyyy-MM-dd"):"";t&&s(W(`${t}T${i.target.value}`))},disabled:a})]}):null,j&&r?e.jsx("div",{className:"border-t p-2",children:e.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:()=>s(void 0),children:"Clear"})}):null]})]})})}function Fe({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,entityType:N,lookupField:j,numeric:d=!1,orgContext:m}){const u=o=>{if(o===void 0||o==="")return s(void 0);if(!d)return s(o);const x=Number(o);s(Number.isFinite(x)?x:o)},{data:i}=xe(N,m,{limit:be}),t=(i?.entities??[]).filter(o=>A(o,j)!==""),S=r==null?"":String(r),v=t.find(o=>A(o,j)===S);return m?a?e.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm",children:v?.name||S||"-"}):e.jsx(je,{contentClassName:"w-[320px]",searchPlaceholder:`Search ${J(N).toLowerCase()}...`,emptyText:`No ${N} found.`,trigger:o=>e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsx("span",{className:z("truncate",!S&&"text-muted-foreground"),children:v?.name||S||`Select ${J(N).toLowerCase()}`}),e.jsx(he,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,x)=>{const n=x.trim(),f=n.length>0&&!t.some(y=>A(y,j)===n);return e.jsxs(e.Fragment,{children:[f?e.jsxs(Q,{value:`use ${n}`,onSelect:()=>{u(n),o()},children:[e.jsx(fe,{className:"mr-2 h-3.5 w-3.5 opacity-60"}),e.jsxs("span",{className:"truncate",children:["Use ",e.jsx("span",{className:"font-medium",children:n})]})]}):null,t.map(y=>{const h=A(y,j),T=h===S;return e.jsxs(Q,{value:`${y.name} ${y.slug} ${y.entity_type} ${h}`,onSelect:()=>{u(h||void 0),o()},children:[e.jsx(ye,{className:z("mr-2 h-4 w-4",T?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:y.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.slug})]})]},`${y.id}-${h}`)})]})}}):e.jsx(L,{id:l,"aria-label":c,"aria-describedby":w,type:d?"number":"text",value:S,onChange:o=>u(o.target.value||void 0),disabled:a})}function se({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:j,ariaLabel:d,helpId:m}){const u=I(r,s),i=ee(l),t=N||s.readOnly===!0,S=s.type==="object"||!!s.properties,v=s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties),o=s.type==="array"&&!!s.items&&(s.items?.type==="string"||s.items?.type==="number"||s.items?.type==="integer"||s.items?.type==="boolean");if(s.type==="boolean")return e.jsx(ae,{id:i,"aria-label":d,"aria-describedby":m,checked:a??!1,onCheckedChange:n=>c(n),disabled:t});let x;if(s.enum&&Array.isArray(s.enum))x=e.jsxs(ie,{value:a==null?"":String(a),onValueChange:n=>c(n===""?void 0:s.type==="number"||s.type==="integer"?Number(n):n),disabled:t,children:[e.jsx(re,{id:i,"aria-label":d,"aria-describedby":m,children:e.jsx(ne,{placeholder:`Select ${u.toLowerCase()}`})}),e.jsx(le,{children:s.enum.map(n=>{const f=String(n);return e.jsx(ce,{value:f,children:de(s,n)??J(f)},f)})})]});else if(s["x-link-entity-type"])x=e.jsx(Fe,{id:i,value:a,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,entityType:s["x-link-entity-type"],lookupField:s["x-link-lookup-field"]||"slug",numeric:s.type==="number"||s.type==="integer",orgContext:j});else if(s.type==="number"||s.type==="integer")x=e.jsx(me,{id:i,ariaLabel:d,ariaDescribedBy:m,value:a,onChange:c,integer:s.type==="integer",placeholder:`Enter ${u.toLowerCase()}`,readOnly:t});else if(S){const n=M(s.properties),f=new Set(s.required??[]),y=E(a)?a:{};x=Object.keys(s.properties??{}).length===0||!E(a)&&a!==void 0&&a!==null?e.jsx(H,{id:i,value:a,ariaLabel:`${u} JSON object`,ariaDescribedBy:m,readOnly:t,onChange:c}):e.jsx("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3 rounded-md border p-3",children:n.map(([h,T])=>e.jsx(te,{fieldPath:`${l}.${h}`,fieldKey:h,prop:T,value:y[h],onChange:$=>{const b={...y};$===void 0?delete b[h]:b[h]=$,c(b)},isRequired:f.has(h),readonly:t,orgContext:j},h))})}else if(o)x=a!=null&&!oe(a)?e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c}):e.jsx(ue,{id:i,value:a,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,ariaLabel:d,ariaDescribedBy:m,readOnly:t,showHelp:!d,onChange:c});else if(v&&s.items){const n=Array.isArray(a)?a:[],f=M(s.items.properties),y=new Set(s.items.required??[]),h=s.maxItems===void 0||n.length<s.maxItems,T=s.minItems===void 0||n.length>s.minItems;x=!Array.isArray(a)&&a!==void 0&&a!==null||Object.keys(s.items.properties??{}).length>0&&n.some($=>!E($))?e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:"object",minItems:s.minItems,maxItems:s.maxItems,onChange:c}):Object.keys(s.items.properties??{}).length===0?e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No rows"}):n.map(($,b)=>e.jsxs("fieldset",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("legend",{className:"px-1 text-xs font-medium text-muted-foreground",children:["Row ",b+1]}),e.jsx(H,{id:`${i}-${b}-json`,value:$,ariaLabel:`${u} row ${b+1} JSON object`,readOnly:t,onChange:B=>{const g=[...n];g[b]=B,c(g)}}),t?null:e.jsxs(O,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((B,g)=>g!==b)),children:[e.jsx(U,{className:"mr-1.5 h-4 w-4"}),"Remove row"]})]},`${l}.${b}`)),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]}):e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Be,{children:[e.jsx(De,{children:e.jsxs(C,{children:[f.map(([$,b])=>e.jsxs(X,{children:[I($,b),y.has($)?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]},$)),t?null:e.jsx(X,{className:"w-12"})]})}),e.jsx(Ee,{children:n.length===0?e.jsx(C,{children:e.jsx(P,{colSpan:f.length+(t?0:1),className:"text-sm text-muted-foreground",children:"No rows"})}):n.map(($,b)=>{const B=E($)?$:{};return e.jsxs(C,{children:[f.map(([g,D])=>e.jsx(P,{className:"align-top",children:e.jsx(se,{fieldPath:`${l}.${b}.${g}`,fieldKey:g,prop:D,ariaLabel:I(g,D),value:B[g],onChange:_=>{const p=[...n],F={...B};_===void 0?delete F[g]:F[g]=_,p[b]=F,c(p)},isRequired:y.has(g),readonly:t,orgContext:j})},g)),t?null:e.jsx(P,{className:"align-top",children:e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((g,D)=>D!==b)),children:e.jsx(U,{className:"h-4 w-4"})})})]},`${l}.${b}`)})})]})}),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]})}else if(s.type==="array")x=e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c});else if(s.format==="date")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,clearable:!w});else if(s.format==="date-time")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,includeTime:!0,clearable:!w});else{const n=s.format==="uri"||s.format==="url";x=e.jsx(L,{id:i,"aria-label":d,"aria-describedby":m,type:n?"url":"text",value:a??"",onChange:f=>c(f.target.value||void 0),placeholder:n?"https://example.com":`Enter ${u.toLowerCase()}`,disabled:t})}return x}function te({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,control:j,orgContext:d,customControl:m}){const u=I(r,s),i=ve(s),t=ee(l),S=i?`${t}-description`:void 0,v=i?e.jsx("p",{id:S,className:"text-xs text-muted-foreground",children:i}):null,o=j?e.jsx(Oe,{control:j}):null,x=m??e.jsx(se,{fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:d,helpId:S});if(s.type==="boolean"){const f=e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[x,e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5 font-normal",children:[u,o]})]});return v?e.jsxs("div",{className:"space-y-1",children:[f,v]}):f}const n=s.type==="object"||!!s.properties||s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties);return e.jsxs("div",{className:"space-y-1.5",children:[n?e.jsxs("p",{id:`${t}-label`,className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}):e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}),x,v]})}function Ve(l){const r={};for(const[s,a]of Object.entries(l)){const c=Te(a);c!==void 0&&(r[s]=c)}return r}function Me({schema:l,values:r,onValuesChange:s,readonly:a=!1,fieldControls:c,orgContext:w,renderControl:N}){const j=l,d=j?.properties,m=new Set(j?.required??[]),u=(i,t)=>{s({...r,[i]:t})};return!d||Object.keys(d).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:M(d).map(([i,t])=>"x-measure"in t||"x-dimension"in t?null:e.jsx(te,{fieldPath:i,fieldKey:i,prop:t,value:r[i],onChange:S=>u(i,S),isRequired:m.has(i),readonly:a,control:c?.[i],orgContext:w,customControl:N?.(i,t,r[i])},i))})}export{Me as D,se as S,Ve as c};
2
+ //# sourceMappingURL=dynamic-schema-form-D3KnzCsW.js.map
@@ -0,0 +1,2 @@
1
+ import{c as x,n as C,j as e,bg as _,bh as m,bi as S,bj as b,bk as c,fM as u,dC as w}from"./index-C2TCKJDP.js";const h="__connection_picker_create_new__";function E({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:o=!1,ariaLabel:p="Connection"}){const f=x(),l=C().org?.slug,i=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(_,{value:r,onValueChange:j,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[o?e.jsxs(e.Fragment,{children:[e.jsx(c,{value:"workspace",children:"Current workspace"}),i.length>0?e.jsx(u,{}):null]}):null,i.map(t=>e.jsx(c,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[i.length>0||o?e.jsx(u,{}):null,e.jsx(c,{value:h,children:"Connect an app…"})]}):null]})]})}function k(s){const r=[];for(const n of s)typeof n.id=="number"&&r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...k(n.children));return r}export{E as C,k as f};
2
+ //# sourceMappingURL=entity-options-IUdQ-64R.js.map
@@ -0,0 +1,2 @@
1
+ import{dP as we,r as E,bX as Se,j_ as S,ga as Re,ej as te,j as e,B as N,u as Q,jS as Ee,m as se,gk as me,j$ as Fe,M as De,c as he,b as Ce,bY as B,n as Le,w as Be,el as X,eH as Pe,jT as Te,k0 as Ve,cL as $e,c9 as ae,fB as Me,gf as Oe,cz as Ie,hy as Ae,hz as ze,hA as Ue,hB as He,hC as Ke,k1 as We,c0 as qe,T as K,U as ne,eK as Ge,a3 as Xe,g8 as ie,eV as W,cw as Ye,L as q,cx as G}from"./index-C2TCKJDP.js";import{N as Qe,d as Je,f as Ze,g as et,S as tt,h as st}from"./entity-pages-DJNSQrfB.js";import{R as at}from"./record-activity-BCpNKaUo.js";import{D as nt}from"./dynamic-schema-form-D3KnzCsW.js";import{r as it,V as ot}from"./views-access-required-BerT4Z1d.js";import{a as pe,V as oe,M as rt,b as lt}from"./view-param-filters-Bp84PUMd.js";import{m as ct,j as Y,d as dt,o as re,c as fe,R as xe,q as ut,r as mt}from"./renderer-ucwCQmBk.js";import"./table-1O-ik4_O.js";import{a as ht}from"./source-record-panels-LJIWGtHb.js";import{r as pt,R as le,b as ft}from"./events-feed-DwOkLk6A.js";import{a as xt}from"./record-session-KuEDuF3S.js";import"./schema-value-CefbtPIY.js";import"./home-toolbar-CpCcHA6z.js";import"./filter-editors-DQ5V4Cvh.js";import"./subDays-DwIOMzYC.js";import"./runs-B_iywKWb.js";import"./event-kind-options-fHAIXu24.js";import"./clients-CydgUHrc.js";import"./client-activity-scopes-B7xVaUA-.js";import"./client-rows-B3LULJxW.js";import"./run-initiator-8vdkq-3o.js";import"./list-skeleton-bQAZ0hQp.js";import"./use-automations-lV8PuE8L.js";import"./agent-loading-shells-BupiSjR-.js";import"./member-scope-gate-Doic_6qX.js";import"./app-bridge-C4nPtae3.js";import"./card-rE4Ctuy6.js";import"./definition-comparison-3zKUSTt8.js";import"./json-diff-CJK-gzCt.js";import"./code-editor-UppEMWpt.js";import"./index-Vcq4gwWv.js";import"./copy-button-1ALlvZU1.js";import"./device-automation-Dp3faMvp.js";function gt(t,s){if(t===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in t)return t;if(typeof t=="function")return{shouldBlockFn:async()=>await t(),enableBeforeUnload:!0,withResolver:!1};const i=!!(t.condition??!0),n=t.blockerFn;return{shouldBlockFn:async()=>i&&n!==void 0?await n():i,enableBeforeUnload:i,withResolver:n===void 0}}function vt(t,s){const{shouldBlockFn:i,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:c=!1}=gt(t),o=we(),{history:r}=o,[u,x]=E.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return E.useEffect(()=>{const p=async f=>{function l(j){const b=o.parseLocation(j),v=o.getMatchedRoutes(b.pathname);return v.foundRoute===void 0?{routeId:"__notFound__",fullPath:b.pathname,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}:{routeId:v.foundRoute.id,fullPath:v.foundRoute.fullPath,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}}const m=l(f.currentLocation),d=l(f.nextLocation);if(m.routeId==="__notFound__"&&d.routeId!=="__notFound__")return!1;const h=await i({action:f.action,current:m,next:d});if(!c)return h;if(!h)return!1;const k=await new Promise(j=>{x({status:"blocked",current:m,next:d,action:f.action,proceed:()=>j(!1),reset:()=>j(!0)})});return x({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),k};return a?void 0:r.block({blockerFn:p,enableBeforeUnload:n})},[i,n,a,c,r,o]),u}function U(t,s){return te(Y(t))===te(Y(s))}function jt(t,s){const i={};for(const n of new Set([...Object.keys(t),...Object.keys(s)]))U(t[n],s[n])||(i[n]=Y(t[n])??null);return Object.keys(i).length>0?i:void 0}function yt(t,s){return[...new Set([...Object.keys(t),...Object.keys(s)])].filter(i=>{try{return!U(t[i],s[i])}catch{return!0}})}function ce(t,s){return{name:t.name,slug:t.slug,metadata:ct(t.metadata??{},s)}}function bt(t,s,i){const n=new Set(i),a={},c={},o=new Set([...Object.keys(t.values.metadata),...Object.keys(t.baseline.metadata),...Object.keys(s.metadata)]);for(const r of o){const u=n.has(r),x=u?t.values.metadata[r]:t.baseline.metadata[r],p=U(x,s.metadata[r])?x:s.metadata[r];p!==void 0&&(a[r]=p);let f=!1;if(!u)try{f=!U(t.values.metadata[r],t.baseline.metadata[r])}catch{f=!0}const l=f?t.values.metadata[r]:p;l!==void 0&&(c[r]=l)}return{baseline:{name:s.name,slug:s.slug,metadata:a},values:{name:s.name,slug:s.slug,metadata:c}}}function kt({entity:t,schema:s,orgContext:i}){const n=E.useMemo(()=>ce(t,s),[t,s]),a=Se(S(t),n,s),c=Re(i),{values:o,baseline:r,commit:u}=a,x=E.useMemo(()=>yt(o.metadata,r.metadata),[o.metadata,r.metadata]),p=o.name!==r.name||o.slug!==r.slug,f=E.useCallback((m,d)=>a.setValues(h=>({...h,metadata:{...h.metadata,[m]:d}})),[a.setValues]),l=async({note:m}={})=>{if(typeof t.id!="number")throw new Error("Source records are read-only");if(!a.canSubmit)return null;const d=jt(o.metadata,r.metadata),h=o.name.trim()!==r.name.trim();if(!d&&!p)return null;const k=await c.mutateAsync({entityId:t.id,name:h?o.name.trim():void 0,slug:o.slug,metadata:d,field_note:d&&m?.trim()||void 0}),j=ce(k.entity,s);return u(b=>bt(b,j,Object.keys(d??{})),j),{held:k.blocked_fields??[],approvalUrl:k.approval_url}};return{values:o,baseline:r,revision:a.revision,setValues:a.setValues,setMetadataField:f,reset:a.reset,save:l,saving:c.isPending,dirtyKeys:x,identityDirty:p,isDirty:p||x.length>0,canSubmit:a.canSubmit,hasConflict:a.hasConflict,hasInvalidInput:a.hasInvalidInput}}const _t=3,Nt=50;function ge(t){const s=E.useRef(null);return E.useEffect(()=>{t&&(s.current?.scrollIntoView?.({block:"start"}),s.current?.focus())},[t]),s}function T({headingRef:t,children:s}){return e.jsx("h3",{ref:t,tabIndex:-1,className:"text-xs font-medium uppercase tracking-wide text-muted-foreground outline-none",children:s})}function wt({entityId:t,entityName:s,ownerSlug:i,orgContext:n,focus:a,collapsed:c=!1}){const o=Q(),r=ge(a),{data:u,isLoading:x,isError:p,refetch:f}=Ee(t,n,{limit:Nt});if(t===void 0)return null;if(x)return e.jsxs("section",{className:"space-y-2","aria-busy":"true",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(se,{className:"h-4 w-24"}),e.jsx(se,{className:"h-6 w-full rounded-md"})]});if(p||!u)return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Could not load this record's links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void f(),children:"Retry"})]})]});if(u.countsByType.length===0&&!u.hasMore&&!u.failures?.length)return a?e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No links to other records yet."})]}):null;if(c){const l=u.countsByType.flatMap(m=>{const d=m.count===1?u.rows.find(h=>h.relationship_type_slug===m.relationship_type_slug):void 0;return d?[pt(d,m.relationship_type_name)]:[m.relationship_type_name,String(m.count)]});return e.jsxs("section",{className:"space-y-1","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),e.jsx("p",{"data-testid":"linked-summary",className:"truncate text-sm text-muted-foreground",children:l.join(" · ")})]})}return e.jsxs("section",{className:"space-y-3","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),u.hasMore&&o?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>o.open({href:"",key:`record-links:${t}`,title:"Linked records",recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,label:"Linked records"}}),children:"Browse linked records"}):null,u.countsByType.map(l=>{const m=u.rows.filter(h=>h.relationship_type_slug===l.relationship_type_slug).slice(0,_t),d=l.count>m.length;return e.jsxs("div",{className:"space-y-1 text-sm",children:[d||m.length===0?e.jsxs("p",{className:"text-muted-foreground",children:[l.relationship_type_name,d?e.jsxs("span",{className:"tabular-nums text-muted-foreground/70",children:[" ","· ",l.count,u.countsScope==="page"?" shown":""]}):null]}):null,e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[m.map(h=>e.jsx(ft,{row:h,label:l.relationship_type_name,entityId:t,ownerSlug:i,orgContext:n},h.id)),d&&o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary",onClick:()=>o.open({href:"",key:`record-links:${t}:${l.relationship_type_slug}`,title:`${l.relationship_type_name} · ${l.count}`,recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,relationshipType:l.relationship_type_slug,label:l.relationship_type_name}}),children:["Show all ",l.count]}):null]})]},l.relationship_type_slug)})]})}function St({record:t,ownerSlug:s,orgContext:i,focus:n}){const[a,c]=E.useState(n),o=ge(n);return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:o,children:"Linked"}),a?e.jsx(ht,{record:t,ownerSlug:s,orgContext:i}):e.jsx(N,{type:"button",variant:"outline",size:"sm",className:"h-7",onClick:()=>c(!0),children:"Find linked records"})]})}const Rt="$name";function ve({outcome:t,schema:s}){if(!t||t.held.length===0)return null;const i=s?.properties??{},n=t.held.map(a=>a===Rt?"Name":dt(a,i[a]??{}));return e.jsxs("div",{role:"status",className:"rounded-md bg-amber-500/10 px-3 py-2 text-sm text-amber-700 dark:text-amber-300",children:[n.join(", ")," ",n.length===1?"needs":"need"," approval before ",n.length===1?"it changes":"they change",".",t.approvalUrl?e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:t.approvalUrl,className:"underline",children:"Review"})]}):null]})}const Et=320,Ft={},Dt=()=>{};function Ct({view:t,orgSlug:s,recordUrl:i,scope:n}){const a=Q(),c=`${i}${me(t.key)}`,o=a?()=>a.open({href:c,title:t.name}):void 0;return e.jsxs("section",{className:"min-w-0 rounded-lg border","data-testid":"view-card","data-view":t.key,children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium",children:t.name}),t.description?e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.description}):null]}),o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:o,"aria-label":`Open ${t.name}`,children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),"Open"]}):null]}),e.jsx("div",{className:"px-4 pb-3",children:e.jsx(pe,{orgSlug:s,viewKey:t.key,scope:n,params:Ft,onParamsChange:Dt,contentHash:t.content_hash,title:t.name,minHeight:64,displayMode:"inline",maxHeight:Et,onRequestDisplayMode:o?r=>{r==="fullscreen"&&o()}:void 0})})]})}function Lt({recordUrl:t,dirty:s,onDiscard:i}){const n=vt({disabled:!s,enableBeforeUnload:s,withResolver:!0,shouldBlockFn:({next:c})=>c.pathname!==t&&!c.pathname.startsWith(`${t}${me("")}`)}),a=n.status==="blocked";return e.jsx(Ae,{open:a,onOpenChange:c=>{!c&&a&&n.reset()},children:e.jsxs(ze,{className:"max-w-sm",children:[e.jsxs(Ue,{children:[e.jsx(He,{children:"Discard unsaved changes?"}),e.jsx(Ke,{children:"This record has edits that are not saved. Leaving discards them."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>a&&n.reset(),children:"Keep editing"}),e.jsx(N,{type:"button",variant:"destructive",onClick:()=>{a&&(i(),n.proceed())},children:"Discard"})]})]})})}const de=6;function Bt({entity:t,ownerSlug:s,orgContext:i,recordUrl:n,schema:a,entityTypeName:c,isTypeLoading:o,record:r,canEdit:u,editing:x,onEditingChange:p,outcome:f,onSaved:l,formId:m,fieldLimit:d,onDeleted:h}){const k=x&&u,j=Q(),b={entity:{id:S(t),name:t.name,entity_type:t.entity_type},ownerSlug:s,orgContext:i,schema:a,record:r,editing:k};xt(b);const v=j?.item?.recordField,D={ownerSlug:s,orgContext:i,controls:t.field_controls,dirtyKeys:r.dirtyKeys,openField:j?L=>j.open(it(b,L.key)):void 0,openFieldKey:v?.entityId===S(t)?v.field:void 0},C=e.jsx(Lt,{recordUrl:n,dirty:k&&r.isDirty,onDiscard:()=>{r.reset(),p(!1)}});if(o)return e.jsx(Ie,{rows:6});if(k)return e.jsxs(e.Fragment,{children:[C,e.jsx(Pt,{formId:m,entity:t,entityTypeName:c,schema:a,record:r,orgContext:i,renderControl:(L,P,F)=>ut(P)?e.jsx(mt,{field:{key:L,prop:P},value:F,context:D}):void 0,onSaved:l,onDeleted:h,onDone:()=>p(!1)})]});const R=fe(r.revision);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ve,{outcome:f,schema:a}),e.jsx(xe,{fields:R,fieldLimit:d,values:r.values.metadata,context:D})]})}function Pt({formId:t,entity:s,entityTypeName:i,schema:n,record:a,orgContext:c,renderControl:o,onSaved:r,onDeleted:u,onDone:x}){const p=We(),f=s.field_controls,{name:l,slug:m,metadata:d}=a.values,h=g=>a.setValues(y=>({...y,name:g})),k=g=>a.setValues(y=>({...y,slug:g})),j=g=>a.setValues(y=>({...y,metadata:g})),[b,v]=B(S(s),""),[D,C]=B(S(s),null),[R,L]=B(S(s),null),[P,F]=B(S(s),!1),[w,V]=B(S(s),null),$=a.dirtyKeys.length>0,I=async g=>{if(g.preventDefault(),!!a.canSubmit){if(C(null),!l.trim()){C("Name is required");return}try{const y=await a.save({note:b});L(y),r(y),v(""),y?.held.length||x()}catch(y){C(y instanceof Error?y.message:"Failed to update entity")}}},H=async()=>{V(null);try{if(typeof s.id!="number")throw new Error("Source records are read-only");await p.mutateAsync({entityId:s.id}),F(!1),u?.()}catch(g){V(g instanceof Error?g.message:"Failed to delete entity")}},A=[s.total_content>0&&`${s.total_content} content item${s.total_content===1?"":"s"}`,s.automations_count>0&&`${s.automations_count} Automation${s.automations_count===1?"":"s"}`,s.active_connections>0&&`${s.active_connections} connector${s.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return e.jsxs("form",{id:t,onSubmit:I,className:"space-y-4",children:[e.jsx(qe,{visible:a.hasConflict,onReload:a.reset}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(K,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ne,{id:"sidebar-name",value:l,onChange:g=>h(g.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(ne,{id:"sidebar-slug",value:m,onChange:g=>k(g.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),a.revision&&Object.keys(a.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{}),e.jsx(nt,{schema:a.revision,values:d,onValuesChange:j,fieldControls:f,orgContext:c,renderControl:o})]}),$&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:b,onChange:g=>v(g.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),D&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx(ve,{outcome:R,schema:n}),P?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Xe,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',s.name,'"?']}),A&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",A,". This cannot be easily undone."]})]})]}),w&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:w}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{F(!1),V(null)},children:"Cancel"}),e.jsx(N,{type:"button",variant:"destructive",size:"sm",onClick:H,disabled:p.isPending,children:p.isPending?"Deleting...":`Delete ${i||"entity"}`})]})]}):e.jsx("div",{className:"pt-2",children:e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>F(!0),children:"Delete"})})]})}function je(t,s){const i=new Set(t.measure_columns??[]),n=s?.properties??{};return Object.keys(t.metadata??{}).filter(a=>a!=="id"&&a!=="slug"&&a!=="name"&&!Me(n[a])&&n[a]?.const===void 0).map(a=>({key:a,prop:n[a]??{},label:n[a]?.["x-table-label"]??(i.has(a)?a:Oe(a.replace(/_/g," "))),numeric:i.has(a)}))}function Tt({entity:t,schema:s,ownerSlug:i,fieldLimit:n}){const a=je(t,s);return e.jsxs("div",{children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Managed by the source"}),e.jsx(xe,{fields:a,fieldLimit:n,values:t.metadata??{},context:{ownerSlug:i}})]})}const ue="owletto:record-details-expanded";function Vt(){const[t,s]=E.useState(()=>{try{return window.localStorage.getItem(ue)==="1"}catch{return!1}});return[t,n=>{s(n);try{window.localStorage.setItem(ue,n?"1":"0")}catch{}}]}function $t({namespace:t,entity:s,recordUrl:i,viewKey:n,title:a,onDeleted:c}){const o=De({strict:!1}),r=he(),u=E.useRef(null),x=Ce(u,Qe),[p,f]=Vt(),[l,m]=B(S(s),!1),d={slug:t.slug,organizationId:t.id},{isMember:h,isPublic:k,isLoading:j}=Le(t.slug),b=h||k,v=Be({...d,organizationId:h?t.id:null}),{data:D,isLoading:C}=X(s.entity_type,d),R=D?.metadata_schema,{isAdmin:L,isLoading:P}=Pe(h?d.organizationId:void 0),F=h&&L&&!P&&!s.is_derived,w=kt({entity:s,schema:R,orgContext:d}),[V,$]=B(S(s),null),I=`record-form-${s.id}`,H=l&&F,A=b?v.data??[]:[],g=Te(A,{type:s.entity_type,id:S(s)}),y=Ve(g,n),z=!n&&o.tab==="relationships",ye=_=>void r({to:".",search:_,replace:!0}),J={type:s.entity_type,entity:s.is_derived?s.slug:s.id??s.slug},M=x&&!p&&!l&&!z,Z=s.is_derived?re(je(s,R),s.metadata??{}).length:re(fe(w.revision),w.values.metadata).length,ee=M?de:void 0,be=e.jsxs("div",{className:"space-y-6",children:[s.is_derived?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{entity:s,schema:R,ownerSlug:t.slug,fieldLimit:ee}),e.jsx(St,{record:{type:s.entity_type,key:s.slug},ownerSlug:t.slug,orgContext:d,focus:z})]}):e.jsxs(e.Fragment,{children:[e.jsx(Bt,{entity:s,ownerSlug:t.slug,orgContext:d,recordUrl:i,schema:R,entityTypeName:D?.name,isTypeLoading:C,record:w,canEdit:F,editing:l,onEditingChange:m,outcome:V,onSaved:$,formId:I,fieldLimit:ee,onDeleted:c}),e.jsx(wt,{entityId:typeof s.id=="number"?s.id:void 0,entityName:s.name,ownerSlug:t.slug,orgContext:d,focus:z,collapsed:M})]}),x&&!l&&!z?e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary","aria-expanded":!M,onClick:()=>f(M),children:M?Z>de?`Show all ${Z} fields`:"Show all details":"Show fewer"}):null]}),ke=_=>e.jsx(Ze,{rootRef:u,narrow:x,details:be,summary:e.jsx(et,{entity:s,schema:R}),children:_}),_e=H?e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{w.reset(),$(null),m(!1)},children:"Cancel"}),e.jsx(N,{type:"submit",form:I,size:"sm",disabled:!w.canSubmit||!w.isDirty||w.saving||!w.values.name.trim(),children:w.saving?"Saving...":"Save"})]}):F&&!C?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:()=>{$(null),m(!0)},children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"Edit"]}):null,O=_=>e.jsx(Je,{entity:s,owner:t.slug,schema:R,title:a??null,actions:_e,layout:"content",children:_});if(n&&!b)return O(j?null:e.jsx(ot,{}));if(n&&v.data===void 0)return O(v.isError?e.jsx(oe,{onRetry:()=>void v.refetch()}):null);if(y.kind==="missing")return O(e.jsx(rt,{viewKey:y.key,backTo:i,backLabel:`Back to ${s.name}`}));if(y.kind==="view"){const{view:_}=y;return O(e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx(lt,{decls:_.params,params:ae(o),onParamsChange:Ne=>void r({to:".",search:Ne})}),e.jsx(pe,{orgSlug:t.slug,viewKey:_.key,scope:J,params:ae(o),onParamsChange:ye,contentHash:_.content_hash,title:_.name,minHeight:320})]}))}return O(ke(e.jsxs("div",{className:"min-w-0 space-y-4",children:[b&&v.isError&&e.jsx(oe,{onRetry:()=>void v.refetch()}),g.map(_=>e.jsx(Ct,{view:_,orgSlug:t.slug,recordUrl:i,scope:J},_.key)),e.jsxs("section",{"aria-labelledby":"record-activity-heading",className:"min-w-0",children:[e.jsx("h2",{id:"record-activity-heading",className:"mb-2 text-sm font-medium text-muted-foreground",children:"Activity"}),e.jsx(at,{entity:s,organizationId:t.id,ownerSlug:t.slug})]})]})))}function Mt(t){return t?.trim()?t:void 0}function vs({namespace:t,path:s,entity:i,viewKey:n}){const a=he(),{data:c}=X(i.entity_type,{slug:t.slug}),o=s[0]?.entity_type??i.entity_type,{data:r}=X(o,{slug:t.slug}),u=Mt(c?.icon),x=s.map(l=>({entity_type:l.entity_type,slug:l.slug})),p=`/${t.slug}/${ie(i.entity_type)}`,f=W(t.slug,x);return e.jsxs("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:[e.jsx(Ye,{crumbs:[...o==="$member"?[]:[e.jsx(q,{to:"/$owner/data",params:{owner:t.slug},className:G,children:"Memory"},"memory")],e.jsx(q,{to:`/${t.slug}/${ie(o)}`,className:G,children:o==="$member"?"Team":r?.name??o},"type"),...s.slice(0,-1).map((l,m)=>e.jsx(q,{to:W(t.slug,x.slice(0,m+1)),className:G,children:l.name},l.id))],current:i.name}),e.jsx($t,{namespace:t,entity:i,recordUrl:f,viewKey:n,title:e.jsx(st,{entity:i,schema:c?.metadata_schema,icon:u}),onDeleted:()=>{const l=s.slice(0,-1);l.length>0?a({to:W(t.slug,l)}):a({to:p})}})]})}export{vs as EntityPage};
2
+ //# sourceMappingURL=entity-page-B3Im65EI.js.map
@@ -0,0 +1,2 @@
1
+ import{r as x,j as e,bp as ue,i as H,e3 as me,e4 as xe,B as T,gh as he,e7 as pe,dE as ge,fi as ne,gf as F,fB as fe,dm as P,a2 as q,L as A,eV as je,b as ve,m as E}from"./index-C2TCKJDP.js";import{p as S,n as be,e as re,b as ye,g as Ne,f as J,R as we,c as _e}from"./renderer-ucwCQmBk.js";import{S as U}from"./schema-value-CefbtPIY.js";import{T as Se,a as ke,b as $,c as Y,d as Ce,e as K}from"./table-1O-ik4_O.js";var Ee="Separator",ee="horizontal",Re=["horizontal","vertical"],ae=x.forwardRef((t,s)=>{const{decorative:n,orientation:a=ee,...i}=t,o=Le(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,...i,ref:s})});ae.displayName=Ee;function Le(t){return Re.includes(t)}var oe=ae;const Me=x.forwardRef(({className:t,orientation:s="horizontal",decorative:n=!0,...a},i)=>e.jsx(oe,{ref:i,decorative:n,orientation:s,className:H("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(T,{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:i=>{const o=s??t.map(c=>c.field);n(i.target.checked?[...o,a.field]:o.filter(c=>c!==a.field))}}),a.label]},a.field))]})]})}function Pe({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 Te(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 i=0;for(let o=0;o<s.length;o++)i=i*31+s.charCodeAt(o)>>>0;return{initials:a.toUpperCase()||"?",hue:i%360}}function Fe(t){const[s,n]=x.useState();return x.useEffect(()=>{if(!t||!globalThis.crypto?.subtle){n(void 0);return}let a=!1;const i=t.trim().toLowerCase();return crypto.subtle.digest("SHA-256",new TextEncoder().encode(i)).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 ie({metadata:t,metadataSchema:s,name:n,typeIcon:a,className:i="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=Fe(y?void 0:v),w=y||N,[k,R]=x.useState(!1);if(x.useEffect(()=>{R(!1)},[w]),w&&!k)return e.jsx("img",{src:w,alt:n,referrerPolicy:"no-referrer",onError:()=>R(!0),className:H("rounded-full object-cover border border-border",i)});if(c){const L=n.trim()||v||Oe(t,s)||n,{initials:O,hue:z}=Te(L);return e.jsx("span",{role:"img","aria-label":n,className:H("inline-grid place-items-center rounded-full border border-border font-semibold text-white select-none",i),style:{background:`oklch(0.55 0.13 ${z})`,fontSize:"0.85em"},children:O})}return e.jsx(ge,{icon:a,className:o})}function Oe(t,s){if(!t)return;const n=s?.properties,a=["email","handle","username","login","github","x_handle","slug"],i=Object.keys(n||t);for(const o of i)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(Pe,{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"]??F(o.replaceAll("_"," "))}));if(!s)return[];const i=n.find(o=>Object.keys(S(o.metadata)).length>0);return Object.keys(S(i?.metadata)).filter(o=>o!=="id"&&o!=="slug"&&o!=="name"&&!fe(t?.properties?.[o])).map(o=>({field:o,label:F(o.replaceAll("_"," "))}))}function ze(t){return t.some(s=>Object.hasOwn(S(s.metadata),"name"))}function Ie(t,s){return P(t,re(s))}function Be(t){return`${t.entityType}:${t.lookupField}`}const $e=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 He(t,s){if(Ke(t,s))return"currency";if($e.has(t)||t.endsWith("_slug"))return"enum"}function Ue({entities:t,owner:s,schema:n,entityTypeIcon:a,isDerived:i,measureColumns:o,linkedEntityLookups:c,hasAnyParents:h,sorting:j,onSortingChange:y,visibleColumns:v,columnChoices:N,onVisibleColumnsChange:w,page:k,pageSize:R,totalCount:L,hasMore:O,pageTitle:z,onPrevPage:le,onNextPage:ce}){const M=N?.length&&w?e.jsx(Ae,{choices:N,visible:v,onChange:w}):null,f=n?.properties,V=!i||ze(t),W=x.useMemo(()=>f?Object.fromEntries(Object.entries(f).flatMap(([l,r])=>r["x-link-entity-type"]?[[l,{entityType:r["x-link-entity-type"],lookupField:r["x-link-lookup-field"]||"slug"}]]:[])):{},[f]),C=x.useMemo(()=>f?se({properties:f},i,[]).map(({field:r})=>[r,f[r]]).map(([r,u])=>{const m=W[r],d=m?c[Be(m)]:void 0;return{id:i?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||F(r.replace(/_/g," "));return i?e.jsx(_,{column:p,children:g}):g},cell:({getValue:p})=>e.jsx(U,{value:p(),prop:u,format:He(r,u),className:"text-muted-foreground",resolveLink:d?g=>{const b=d[g];return b?{label:b.name,to:P(s,[{entity_type:b.entity_type,slug:b.slug}])}:void 0}:void 0})}}):[],[i,W,c,s,f]),D=x.useMemo(()=>new Set(o),[o]),I=x.useMemo(()=>!i||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:F(r.replace(/_/g," ")),u&&e.jsx(q,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:m})=>e.jsx(U,{value:m(),prop:f?.[r],className:u?"tabular-nums":"text-muted-foreground"}),meta:u?{align:"right"}:void 0}}),[i,C,t,D,f]),G=x.useMemo(()=>{const l=n?.["x-table-relationships"];return!l||l.length===0?[]:l.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=P(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]),Q=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=P(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 l=[],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&&l.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&&l.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:d})=>{const p=d();return p&&p>0?e.jsxs(q,{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&&l.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"}}),l},[t,s]),Z=x.useMemo(()=>[{accessorKey:"name",header:({column:l})=>V?e.jsx(_,{column:l,children:"Name"}):"Name",cell:({row:l})=>{const r=S(l.original.metadata);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{metadata:r,metadataSchema:n,name:l.original.name,typeIcon:a,className:"h-6 w-6 shrink-0"}),e.jsx("div",{className:"min-w-0",children:(()=>{const u=Ie(s,l.original);return e.jsx(A,{to:u,className:"block max-w-56 truncate font-medium hover:underline",title:l.original.name,children:l.original.name})})()})]})}},...Q,...C,...I,...G,...X,...i?[]:[{accessorKey:"created_at",header:({column:l})=>e.jsx(_,{column:l,children:"Created"}),cell:({getValue:l})=>e.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(l()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[s,Q,C,I,G,X,n,a,i,V]),B=ye({data:t,columns:Z,state:{sorting:j,columnVisibility:Object.fromEntries([...C,...I].flatMap(l=>l.id?[[l.id,!v||v.includes(i?l.id:l.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:B.getHeaderGroups().map(l=>e.jsxs($,{children:[l.headers.map(r=>e.jsx(Y,{"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:J(r.column.columnDef.header,r.getContext())},r.id)),M?e.jsx(Y,{className:"w-10 pr-2 text-right",children:M}):null]},l.id))}),e.jsx(Ce,{children:B.getRowModel().rows.length?B.getRowModel().rows.map(l=>e.jsxs($,{children:[l.getVisibleCells().map(r=>e.jsx(K,{className:r.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:J(r.column.columnDef.cell,r.getContext())},r.id)),M?e.jsx(K,{}):null]},l.id)):e.jsx($,{children:e.jsx(K,{colSpan:Z.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 ",L," ",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(L/R))]}),e.jsx(T,{variant:"outline",size:"sm",onClick:le,disabled:k===0,children:"Previous"}),e.jsx(T,{variant:"outline",size:"sm",onClick:ce,disabled:!O,children:"Next"})]})]})]})}const Ve=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:i,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(T,{className:"ml-3",variant:"outline",size:"sm",onClick:h,children:"Retry"}):null]}):i!==void 0?i:a?e.jsx(Ue,{...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 Ge({entity:t,schema:s,icon:n}){return e.jsxs(e.Fragment,{children:[e.jsx(ie,{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 Qe({entity:t,schema:s}){const n=_e(s?{...s}:void 0).filter(({key:a,prop:i})=>i["x-table-column"]===!0&&!i["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:i},o)=>e.jsxs("span",{children:[o>0?" · ":null,e.jsx(U,{value:t.metadata?.[a],prop:i})]},a))}):null}function Xe({details:t,summary:s,children:n,rootRef:a,narrow:i}){return e.jsx("div",{ref:a,className:"min-w-0 space-y-4",children:i?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:i,details:o,summary:c,children:h,layout:j="record"}){const y=x.useRef(null),v=ve(y,Ve),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(Ge,{entity:t,schema:n}):a}),i]}),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(Qe,{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{ie as E,Ve as N,Me as S,Ue as a,et as b,We as c,tt as d,se as e,Xe as f,Qe as g,Ge as h};
2
+ //# sourceMappingURL=entity-pages-DJNSQrfB.js.map
@@ -0,0 +1,2 @@
1
+ import{G as $,fI as de,cr as ue,fL as W,j as e,bH as me,r as h,fJ as xe,fK as he,e3 as pe,e4 as ge,B as g,dh as V,e7 as fe,T as S,bg as q,bh as P,bi as M,bj as L,bk as k,U as E,ai as je,go as ve,gp as Ne,a2 as Y,cZ as ye,X as K,e6 as be,C as we,a6 as Se,c1 as ae,e_ as ne,gq as Ce,a3 as re,gr as ke,gd as Ee,bX as _e,bY as G,c0 as Te,eK as Re,bI as Oe,gs as De,i as X,cG as Ae,cH as Fe,cI as ze,L as le,cJ as qe,cK as Pe,A as Me}from"./index-C2TCKJDP.js";import{f as J}from"./event-kind-options-fHAIXu24.js";import{C as ie}from"./code-editor-UppEMWpt.js";function Le({entityType:s}){const{orgContext:a}=$(),{data:o,isLoading:n}=de(a),{data:r}=ue(a),t=(o||[]).filter(u=>u.status==="active"),i=t.filter(u=>!u.organization_slug||u.organization_slug===a?.slug),c=i.filter(u=>u.purpose!==W),d=i.filter(u=>u.purpose===W),x=t.filter(u=>u.organization_slug&&u.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(me,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:c,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})]}),x.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:x,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ue,{entityTypeSlug:s.slug,relationshipTypes:c,allEntityTypes:r||[]})]})})}function B({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Ie,{relationshipType:r,entityTypeSlug:s,allEntityTypes:o,readOnly:n},r.id))})}function Ie({relationshipType:s,entityTypeSlug:a,allEntityTypes:o,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=ve(s.slug,r),i=Ne(),c=(t||[]).filter(x=>x.source_entity_type_slug===a||x.target_entity_type_slug===a);if(c.length===0)return null;const d=new Map(o.map(x=>[x.slug,x.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(Y,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(Y,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),c.map(x=>e.jsx(Ve,{rule:x,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(x.id),isRemoving:i.isPending,readOnly:n},x.id))]})}function Ve({rule:s,entityTypeSlug:a,entityTypeNameMap:o,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,c]=h.useState(!1),d=s.source_entity_type_slug===a,x=d?s.target_entity_type_slug:s.source_entity_type_slug,u=o.get(x)||x;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":u}),e.jsx(ye,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?u:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(g,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>c(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>c(!0),disabled:r,children:e.jsx(K,{className:"h-3 w-3"})})})]})}function Ue({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o}){const{orgContext:n}=$(),r=o.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=h.useState(!1),[c,d]=h.useState("existing"),[x,u]=h.useState(""),[N,b]=h.useState(""),[w,y]=h.useState("source"),[v,f]=h.useState(""),[T,R]=h.useState(""),[D,O]=h.useState(!1),[A,C]=h.useState(null),m=xe(),p=he(),j=()=>{d("existing"),u(""),b(""),y("source"),f(""),R(""),O(!1),C(null)},_=l=>{i(l),l||j()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),U=async()=>{C(null);try{let l=x;if(c==="new"){if(!v.trim()){C("Name is required");return}const H=T.trim()||F(v);if(!H){C("Slug is required");return}l=(await m.mutateAsync({slug:H,name:v.trim(),is_symmetric:D})).relationship_type.slug}if(!l){C("Select a relationship type");return}if(!N){C("Select a target entity type");return}const I=w==="source"?s:N,oe=w==="source"?N:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:oe}),_(!1)}catch(l){C(l instanceof Error?l.message:"An error occurred")}},z=m.isPending||p.isPending;return e.jsxs(pe,{open:t,onOpenChange:_,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(g,{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(fe,{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(S,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(g,{variant:c==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(g,{variant:c==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),c==="existing"?e.jsxs(q,{value:x,onValueChange:u,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(k,{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(E,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:v,onChange:l=>{f(l.target.value),T||R("")}}),e.jsx(E,{placeholder:v?F(v)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:T,onChange:l=>R(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=>O(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:w,onValueChange:l=>y(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(S,{className:"text-xs",children:[w==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:N,onValueChange:b,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(k,{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(g,{size:"sm",className:"w-full",onClick:U,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Je({options:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const i=o.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((c,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,c)=>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(c),className:"text-muted-foreground hover:text-foreground",children:e.jsx(K,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}const Be=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function $e({examples:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const t=o.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((c,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(K,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}function Ke({field:s,onChange:a,onDelete:o}){const[n,r]=h.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(be,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsx(E,{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:Be.map(t=>e.jsx(k,{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(Se,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:o,children:e.jsx(ae,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Je,{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(E,{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(E,{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(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{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($e,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:o,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{value:s,onChange:a,readonly:o,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 o of Object.values(a)){if(!o||typeof o!="object")return!1;const n=o,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 ce(){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||{},o=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,c={id:ce(),name:n,required:o.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?{...c,type:"enum",enumOptions:r.enum||[]}:{...c,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const o=Number(s);return Number.isNaN(o)?s:o}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function He(s,a="auto"){const o={},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(c=>se(c,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(c=>({value:c,label:c.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(c.toLowerCase())}))}:{}}),o[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:o};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 We({value:s,onChange:a,readonly:o=!1}){const[n,r]=h.useState("visual"),[t,i]=h.useState([]),[c,d]=h.useState("auto"),[x,u]=h.useState(""),[N,b]=h.useState(null),[w,y]=h.useState(!1),v=h.useRef(!1);h.useEffect(()=>{if(v.current){v.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),u(""),y(!1);return}const m=JSON.stringify(s,null,2);u(m),d(te(s)),Q(s)?(i(ee(s)),y(!1)):(y(!0),r("json"))},[s]);const f=h.useCallback((m,p)=>{v.current=!0;const j=He(m,p),_=m.some(F=>F.name.trim());u(_?JSON.stringify(j,null,2):""),a(_?j:void 0)},[a]),T=h.useCallback(m=>{i(m),f(m,c)},[f,c]),R=h.useCallback(m=>{d(m),f(t,m)},[f,t]),D=h.useCallback(m=>{if(v.current=!0,u(m),!m.trim()){b(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(m);b(null),d(te(p)),Q(p)?(i(ee(p)),y(!1)):y(!0),a(p)}catch(p){b(p instanceof Error?p.message:"Invalid JSON")}},[a]),O=()=>{T([...t,{id:ce(),name:"",type:"string",required:!1}])},A=(m,p)=>{const j=[...t];j[m]=p,T(j)},C=m=>{T(t.filter((p,j)=>j!==m))};return o?e.jsx(Z,{value:x,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!w&&r("visual"),disabled:w,className:"h-7 text-xs",children:[e.jsx(ne,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(g,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),w&&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(re,{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((m,p)=>e.jsx(Ke,{field:m,onChange:j=>A(p,j),onDelete:()=>C(p)},m.id)),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:O,className:"w-full",children:[e.jsx(V,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(m=>m.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:c,onValueChange:m=>R(m),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"})]})]})]})]}):e.jsx(Z,{value:x,onChange:D,error:N})]})}function Ye(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ge({entityType:s,onCancel:a,onSaved:o}){const n=!!s,r=ke(),t=Ee(),i=s?.slug??"new",c=_e(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,x]=c.field("name"),[u,N]=c.field("slug"),[b,w]=c.field("description"),[y,v]=c.field("icon"),[f,T]=c.field("color"),[R,D]=c.field("metadataSchema"),[O,A]=c.field("backingSql"),[C,m]=G(i,n),[p,j]=G(i,null),_=O.trim().length>0,F=l=>{x(l),!n&&!C&&N(Ye(l))},U=async()=>{if(!c.canSubmit)return;if(j(null),!d.trim()){j("Name is required");return}if(!n&&!u.trim()){j("Slug is required");return}const l=_?{sql:O.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:R,backing:l}):await r.mutateAsync({slug:u.trim(),name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:R,backing:l}),o()}catch(I){j(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(Te,{visible:c.hasConflict,onReload:c.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-name",children:"Name"}),e.jsx(E,{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(S,{htmlFor:"et-slug",children:"Slug"}),e.jsx(E,{id:"et-slug",value:u,onChange:l=>{m(!0),N(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(S,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:b,onChange:l=>w(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(S,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(E,{id:"et-icon",value:y,onChange:l=>v(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{id:"et-color",value:f,onChange:l=>T(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),f&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:f}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{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(ie,{value:O,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),_?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(ne,{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(S,{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(S,{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(We,{value:R,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Le,{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(g,{onClick:U,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function as({entityType:s,onClose:a,orgContext:o,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,c]=h.useState(!1),[d,x]=h.useState(null),u=De(),N=s?.entity_count??0,b=N>0,w=async()=>{if(s){x(null);try{await u.mutateAsync(s.slug),a()}catch(f){x(f instanceof Error?f.message:"Failed to delete")}}},y=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",v=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:y}),t&&o.slug&&s?e.jsx(Xe,{owner:o.slug,typeSlug:s.slug}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:v})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ge,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[o.slug&&s?e.jsx(Ze,{owner:o.slug,entityType:s}):null,!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:i?e.jsxs("div",{className:"space-y-3",children:[b?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(re,{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 ",N===1?"is":"are"," ",N," entit",N===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.']}),d&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:d}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>{c(!1),x(null)},children:"Cancel"}),e.jsx(g,{variant:"destructive",size:"sm",onClick:w,disabled:b||u.isPending,children:u.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(g,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>c(!0),children:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}function Xe({owner:s,typeSlug:a}){return e.jsx(Ae,{delayDuration:200,children:e.jsxs(Fe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(g,{asChild:!0,variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground",children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a},children:[e.jsx(qe,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Activity"})]})})}),e.jsx(Pe,{children:"Activity"})]})})}function Ze({owner:s,entityType:a}){const o=Object.entries(a.event_kinds??{}).sort(([n],[r])=>J(n).localeCompare(J(r)));return e.jsxs("section",{"aria-label":"Event kinds",className:"border-t border-border pt-4 space-y-2",children:[e.jsxs("h2",{className:"text-sm font-medium",children:["Event kinds on ",a.name]}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"This type declares no event kinds."}):e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:o.map(([n,r])=>e.jsx("li",{children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a.slug,semantic_types:n},className:"flex items-center gap-3 px-3 py-2 text-sm transition-colors hover:bg-accent/50",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-medium",children:J(n)}),r?.description?e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:r.description}):null]}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:["View in Activity",e.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":"true"})]})]})},n))})]})}export{as as E};
2
+ //# sourceMappingURL=entity-type-page-CouHZbc9.js.map
@@ -0,0 +1,2 @@
1
+ import{w as R,r as E,gY as $,gZ as G,cP as z,bG as Y,z as Z,a8 as J,g_ as K,gv as W,j as a,c8 as T,L as X}from"./index-C2TCKJDP.js";import{E as ee}from"./events-feed-DwOkLk6A.js";import{b as se,a as te,V as ne,M as ae}from"./view-param-filters-Bp84PUMd.js";function ie(e,l,n){return{queryKey:["event-view-match",e,l.key,l.content_hash,n],queryFn:async()=>{try{const o=(await z("open_view",{key:l.key,scope:{event:n}},{slug:e})).scope?.event;if(!Number.isSafeInteger(o)||(o??0)<1)throw new Error("The view did not resolve its event subject");return o}catch(s){if(s instanceof Y&&(s.status===400||s.status===404))return null;throw s}},staleTime:6e4}}function re(e,l){const n=R(e??{slug:null,organizationId:null}),s=e?.slug??null,o=E.useMemo(()=>s?$(n.data??[]):[],[s,n.data]),c=G({queries:o.map(i=>ie(s,i,l))});return s?{views:o.flatMap((i,v)=>{const h=c[v]?.data;return h?[{...i,eventId:h}]:[]}),isLoading:n.data===void 0?!n.isError:c.some(i=>i.isPending),isError:n.isError||c.some(i=>i.isError),refetch:()=>{n.refetch();for(const i of c)i.isError&&i.refetch()}}:{views:[],isLoading:!1,isError:!1,refetch:()=>{}}}const le={},oe="calc(100dvh - 120px)";function me({owner:e,organizationId:l,eventId:n,viewKey:s,params:o,onParamsChange:c,onSelectView:i,dense:v=!1,fullBleed:h=!1}){const{isAuthenticated:x,isReady:k}=Z(),{data:B,isLoading:b}=J(),D=B?.some(r=>r.id===l&&r.is_member),m=e!=="me"&&l!==null&&k&&x&&!b&&D,d=re(m?{slug:e,organizationId:l}:null,n),[j,L]=E.useState(le),[O,V]=E.useState(null),f=K(d.views,s),t=m&&!d.isLoading&&!d.isError&&f.kind==="view"?f.view:null,p=t?`${W(e,t.key)}/${t.content_hash}/${t.eventId}`:null,y=t!==null&&O===p,F=T(e,n),_=e!=="me"&&(!k||x&&(b||d.isLoading)),A=t!==null&&!y&&!_,g=h&&A,U=(h||v)&&A,M=_?a.jsx("div",{role:"status",className:"py-8 text-sm text-muted-foreground",children:"Loading event view…"}):t&&!y?a.jsxs(a.Fragment,{children:[a.jsx(se,{decls:t.params,params:o??j,onParamsChange:r=>c?c(t.key,r,{replace:!1}):L(r)}),a.jsx(te,{orgSlug:e,viewKey:t.key,scope:{event:t.eventId},params:o??j,onParamsChange:r=>c?c(t.key,r):L(r),onLoadError:()=>V(p),contentHash:t.content_hash,title:t.name,minHeight:v?240:320,fixedHeight:U?oe:void 0},p)]}):void 0;return a.jsxs("div",{className:g?"w-full space-y-3":"mx-auto w-full max-w-3xl space-y-3",...g?{"data-testid":"event-view-fullbleed"}:{},children:[m&&d.isError&&a.jsx(ne,{onRetry:d.refetch}),(m||e==="me"&&s)&&!d.isLoading&&!d.isError&&f.kind==="missing"&&a.jsx(ae,{viewKey:f.key,backTo:F,backLabel:"Back to the event"}),y&&a.jsxs("div",{role:"alert",className:"rounded-md border p-3 text-sm",children:[a.jsx("p",{children:"The custom view couldn’t load. The event content is shown below."}),a.jsx("button",{type:"button",className:"mt-2 underline",onClick:()=>V(null),children:"Retry custom view"})]}),a.jsx(ee,{presentation:"detail",organizationId:l,ownerSlug:e,filters:{contentIds:[n],...e==="me"?{sortBy:"date",sortOrder:"desc"}:{}},hideDetails:v,renderDetail:r=>{const w=M!=null&&(r==null||!!s),N=(m?d.views:[]).filter(u=>!w||u.key!==t?.key).map(u=>({key:u.key,name:u.name,href:T(e,n,u.key)})),H=u=>u.length?a.jsx("nav",{"aria-label":"Event views",className:"flex flex-wrap gap-3 text-sm",children:u.map(({key:C,name:I,href:S})=>a.jsx(X,{to:S,className:"underline",onClick:i?Q=>{Q.preventDefault(),i(S)}:void 0,children:I},C))}):null,q=[...N],P=[...N];return m&&s&&r!=null&&P.unshift({key:":event",name:"Event details",href:F}),{content:w?M:r,nativeHeading:!w&&r!=null,headingAside:g?H(q):void 0,links:g?null:H(P)}}})]})}export{me as E};
2
+ //# sourceMappingURL=event-detail-CvaRN1qB.js.map
@@ -0,0 +1,2 @@
1
+ function a(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function u(t,o,i){const s=new Set;for(const[k,c]of Object.entries(t.feeds_schema??{})){if(i&&!i.has(k))continue;const d=a(a(c)?.eventKinds);if(d)for(const[f,r]of Object.entries(d)){if(!o){s.add(f);continue}const e=a(r)?.attributions;Array.isArray(e)&&e.some(n=>{const y=a(a(n)?.target);return typeof y?.entityType=="string"&&o.has(y.entityType)})&&s.add(f)}}return s}function h({connectors:t,entityTypes:o,selectedPlatforms:i=[],selectedFeeds:s=[],selectedEntityTypes:k=[]}){const c=new Set,d=new Set(i),f=new Set(k),r=new Map;for(const e of s){const n=r.get(e.connectorKey)??new Set;n.add(e.feedKey),r.set(e.connectorKey,n)}if(r.size>0)for(const e of t){const n=r.get(e.key);if(n)for(const y of u(e,void 0,n))c.add(y)}else if(d.size>0){for(const e of t)if(d.has(e.key))for(const n of u(e))c.add(n)}else if(f.size>0){for(const e of o)if(f.has(e.slug))for(const n of Object.keys(e.event_kinds??{}))c.add(n);for(const e of t)for(const n of u(e,f))c.add(n)}else{for(const e of o)for(const n of Object.keys(e.event_kinds??{}))c.add(n);for(const e of t)for(const n of u(e))c.add(n)}return[...c].sort((e,n)=>e.localeCompare(n))}const K=["notification","note","summary","decision","observation","fact","change","preference","identity"],l="change";function p(t){const o=t.replace(/[_-]+/g," ").trim();return o.length>0?`${o.charAt(0).toUpperCase()}${o.slice(1)}`:t}function g(t,o=[]){return[...new Set([...t.length>0?t:K,l,...o])].sort((i,s)=>p(i).localeCompare(p(s)))}export{l as C,h as c,g as e,p as f};
2
+ //# sourceMappingURL=event-kind-options-fHAIXu24.js.map
@@ -0,0 +1,2 @@
1
+ import{eh as xn,j as t,aa as hn,$ as gn,cR as yn,u as Pe,ei as jn,i as G,cZ as $t,ej as ct,r as j,ek as Ot,el as vn,d3 as bn,a2 as H,dk as Je,L as W,b4 as Le,b5 as Qe,em as _n,co as Nn,en as wn,eo as kn,dj as Pt,ep as Cn,eq as An,b9 as Rn,er as Sn,dC as $n,q as In,es as Tn,bG as Re,z as et,et as gt,cC as Ye,I as En,cP as Ae,eu as Bt,ev as Ut,ew as Ge,ex as zt,c8 as Kt,ey as Mn,ez as Dn,eA as Fn,eB as Ln,B as O,eC as dt,e6 as ut,eD as qt,eE as Vt,eF as On,e3 as Ht,e4 as Wt,e7 as Jt,cH as Pn,cI as Bn,a7 as Qt,cK as Un,eG as zn,c as Kn,H as qn,G as Vn,bo as Ue,eH as Hn,ad as Wn,eI as mt,eJ as Jn,U as Qn,eK as Yn,bI as Gn,ai as Ne,eL as Yt,dl as yt,e5 as Zn,eM as Xn,eN as es,eO as ts,eP as ns,bX as ss,eQ as rs,c0 as as,eR as is,a4 as os,eS as ls,X as cs,cL as ds,c1 as us,eT as ms,eU as ps,eV as fs,v as xs,eW as hs,dO as Se,eX as Gt,eY as gs,eZ as ys,e_ as js,e$ as vs,f0 as bs,f1 as _s,f2 as Ns,n as ws,d5 as ks,dS as Cs,ct as As,s as Rs,t as Ss,dV as $s,f3 as Is,f4 as Ts,f5 as Es,f6 as It,f7 as Ms,f8 as Ds,f9 as Fs,bT as Ls,fa as ze,fb as Os,fc as Ps,fd as Bs}from"./index-C2TCKJDP.js";import{D as Us,A as zs,a as Ks,T as qs,b as Vs,c as Hs,d as Ws}from"./definition-comparison-3zKUSTt8.js";import{R as Js,p as Qs,a as Ys,i as Gs,b as Zs}from"./run-initiator-8vdkq-3o.js";import{a as Zt}from"./use-automations-lV8PuE8L.js";import{l as Xs,s as er,J as tr}from"./renderer-ucwCQmBk.js";import{S as nr}from"./schema-value-CefbtPIY.js";import{J as We}from"./json-diff-CJK-gzCt.js";import{C as Tt}from"./copy-button-1ALlvZU1.js";import{A as Et}from"./device-automation-Dp3faMvp.js";function Xt(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 a=n.find(i=>i&&typeof i=="object"&&"id"in i&&i.id===s);return{id:String(s??"unknown"),name:typeof a?.name=="string"?a.name:`Record ${String(s??"unknown")}`}})}function en(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 za(e){const n=Xt(e.proposal);return{title:e.action==="link"?"Link records":"Unlink records",icon:"entity",impact:{level:"normal"},tone:"default",blocks:[...n.map((s,r)=>({type:"text",label:r===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:en(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 rt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function sr(e){const n=rt(e.proposal);if(!n)return null;const s=rt(e.current);if(e.tool==="manage_agents"){if(!["create","update","delete"].includes(String(n.action)))return null;const r=xn({current:s,proposal:n});return{kind:"agent",current:n.action==="create"?null:r.current,proposed:n.action==="delete"?null:r.proposed}}if(e.tool==="manage_automations"){const r=rt(n.args);if(!r||!["create","update","create_version","set_reaction_script"].includes(String(r.action)))return null;const{action:a,automation_id:i,expected_version:c,...o}=r;return{kind:"automation",current:a==="create"?null:s,proposed:{...a==="create"?null:s,...o}}}return null}function rr({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(Us,{current:e.current,proposed:e.proposed,render:n=>e.kind==="agent"?t.jsx(zs,{value:n}):t.jsx(Ks,{value:n})})]})}async function ar(e,n,s,r){const a=await hn(`${gn}/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:r})});return await yn(a,"Could not record interaction"),a.json()}function U(e){if(typeof e!="string")return;const n=e.trim();return n.length>0?n:void 0}function at(e){return typeof e=="boolean"?e:void 0}function ir(e,n,s){const r=(s??"").toLowerCase();return!!(r==="prepare_comment"||r==="verify_staged_comment"||r.includes("prepare_")||r.includes("verify_staged")||n?.prepared===!0||typeof n?.verified=="boolean"||U(n?.reason_preview)&&U(n?.message)||U(e?.body)&&(U(e?.post_url)||U(e?.activity_id)))}function or(e,n,s){if(!ir(e,n,s))return null;const r=(s??"").toLowerCase(),a=U(n?.body)??U(e?.body),i=U(n?.reason_preview)??U(e?.reason),c=U(n?.post_url)??U(e?.post_url)??(U(e?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${U(e?.activity_id)}`:void 0),o=at(n?.prepared),l=at(n?.verified),d=at(n?.banner_shown),p=U(n?.message),u=n?.match&&typeof n.match=="object"?n.match:null,m=U(u?.text_preview),_=U(u?.author);let w="generic";r==="verify_staged_comment"||r.includes("verify")||typeof l=="boolean"?w="verify":(r==="prepare_comment"||r.includes("prepare")||o===!0||a&&c)&&(w="prepare");const h=[];return o===!0&&h.push("Staged — not posted"),o===!1&&h.push("Not staged"),l===!0&&h.push("Verified posted"),l===!1&&h.push("Not verified as posted"),d===!0&&h.push("In-page banner"),d===!1&&h.push("No banner"),{kind:w,message:p,reason:i,body:a,postUrl:c,prepared:o,bannerShown:d,verified:l,matchPreview:m,matchAuthor:_,chips:h}}const Ke="inline-flex max-w-full items-center truncate rounded-md border border-border px-1.5 py-0.5 text-xs";function tn({peer:e,ownerSlug:n,orgContext:s}){const r=Pe();if(e.url&&!e.self&&e.type){const i=jn(e.url);return i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:G(Ke,"hover:bg-muted"),title:e.type,onClick:c=>c.stopPropagation(),children:t.jsx("span",{className:"truncate",children:e.name})}):t.jsx("span",{className:G(Ke,"text-muted-foreground"),children:e.name})}if(e.self||!e.type||!r)return t.jsx("span",{className:G(Ke,"text-muted-foreground"),children:e.name});const a=r.item?.recordPeer?.entityId===e.id;return t.jsx("button",{type:"button","aria-pressed":a,title:e.type,className:G(Ke,"hover:bg-muted",a&&"ring-1 ring-primary"),onClick:i=>{i.stopPropagation(),r.open(Xs({...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 Ka(e,n=e.relationship_type_name){const s=e.from_entity_name??`Record #${e.from_entity_id}`,r=e.to_entity_name??`Record #${e.to_entity_id}`;return e.is_symmetric?`${s} ${n} ${r}`:`${s} → ${n} → ${r}`}function qa({row:e,entityId:n,entityType:s,ownerSlug:r,orgContext:a,label:i=e.relationship_type_name}){const c=(o,l,d,p)=>t.jsx(tn,{peer:{id:o,name:l??`Record #${o}`,type:d,url:p,self:!p&&o===n&&(typeof o=="number"||d===s)},ownerSlug:r,orgContext:a});return t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1 text-xs",children:[c(e.from_entity_id,e.from_entity_name,e.from_entity_type,e.from_entity_url),!e.is_symmetric&&t.jsx($t,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"text-muted-foreground",children:i}),!e.is_symmetric&&t.jsx($t,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),c(e.to_entity_id,e.to_entity_name,e.to_entity_type,e.to_entity_url)]})}function Va({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 nn={name:"Name",slug:"URL slug",parent_id:"Parent",content:"Content changed"};function be(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function qe(e){return e==null||e===""}function lr(e,n){return ct(e??null)===ct(n??null)}function cr(e){return!!(e?.type==="array"&&(e.items?.type==="object"||e.items?.properties))}function dr(e){return!!(e&&(e.type==="object"||e.properties)&&e.type!=="array")}function jt(e,n){return er({key:e,prop:n??{}})}function ur(e,n){return e?.properties?.[n]}function pt(e,n,s,r,a){if(lr(n,s))return;const i=l=>Array.isArray(l)?l:[];if((Array.isArray(n)||qe(n))&&(Array.isArray(s)||qe(s))&&(Array.isArray(n)||Array.isArray(s)||r?.type==="array")){const l=i(n),d=i(s);if(cr(r)||[...l,...d].some(v=>be(v))){const v=Math.min(l.length,d.length);for(let R=0;R<v;R++)pt([...e,`item ${R+1}`],l[R],d[R],r?.items,a);const N=Math.max(0,d.length-l.length),k=Math.max(0,l.length-d.length);(N||k)&&a.push({kind:"items",path:e,added:N,removed:k});return}const u=v=>ct(v),m=new Set(l.map(u)),_=new Set(d.map(u)),w=d.filter(v=>!m.has(u(v))),h=l.filter(v=>!_.has(u(v)));a.push(w.length||h.length?{kind:"values",path:e,added:w,removed:h,prop:r?.items}:{kind:"reordered",path:e});return}if((be(n)||qe(n))&&(be(s)||qe(s))&&(be(n)||be(s)||dr(r))){const l=be(n)?n:{},d=be(s)?s:{},p=[...new Set([...Object.keys(r?.properties??{}),...Object.keys(l),...Object.keys(d)])];for(const u of p){const m=ur(r,u);pt([...e,jt(u,m)],l[u],d[u],m,a)}return}a.push({kind:"set",path:e,old:n,new:s,prop:r})}function mr(e,n){const s=nn[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 r=n?.properties?.[e.field],a=[];return pt([jt(e.field,r)],e.old,e.new,r,a),a}function pr(e,n){const s=n?.properties;return e.map(r=>r.field==="content"?"Content":nn[r.field]??jt(r.field,s?.[r.field]))}const fr="entity.updated",xr=new Set(["link","unlink","update_link"]);function Mt(e){const n=typeof e=="string"||typeof e=="number"?Number(e):Number.NaN;return Number.isSafeInteger(n)&&n>0?n:null}function hr(e){const n=e.split("_").join(" ").trim();return n?`${n.charAt(0).toUpperCase()}${n.slice(1)}`:e}function gr(e){const n=e.metadata;if(e.semantic_type!=="change"||!n||n._lobu_relationship_change!==!0||typeof n.op!="string"||!xr.has(n.op))return null;const s=Mt(n.fromEntityId),r=Mt(n.toEntityId);if(s==null||r==null)return null;const a=typeof n.relationshipTypeSlug=="string"?n.relationshipTypeSlug:null,i=Array.isArray(n.changes)?n.changes:[];return{op:n.op,fromId:s,toId:r,typeLabel:a?hr(a):"relationship",changedFields:i.flatMap(c=>c&&typeof c=="object"&&typeof c.field=="string"?[c.field]:[])}}function ft({id:e,ownerSlug:n}){const s={slug:n},{data:r,isLoading:a,isError:i}=Ot(e,s);return a?t.jsxs("span",{className:"text-xs text-muted-foreground",children:["Record #",e]}):i||!r?t.jsx("span",{className:"text-xs text-muted-foreground",title:"Deleted, or you do not have access to it",children:"Unavailable record"}):t.jsx(tn,{peer:{id:e,name:r.name,type:r.entity_type},ownerSlug:n,orgContext:s})}function yr({change:e,ownerSlug:n}){const s=e.op==="link"?`Linked as ${e.typeLabel}`:e.op==="unlink"?`Unlinked ${e.typeLabel}`:`Updated ${e.typeLabel} link`;return t.jsxs("span",{"data-testid":"relationship-change",className:"inline-flex flex-wrap items-center gap-1.5",children:[t.jsx(ft,{id:e.fromId,ownerSlug:n}),t.jsx("span",{children:s}),t.jsx("span",{"aria-hidden":"true",children:"→"}),t.jsx(ft,{id:e.toId,ownerSlug:n}),e.op==="update_link"&&e.changedFields.length>0?t.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",e.changedFields.join(", ")]}):null]})}function jr(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:r,old:a,new:i}=s;n.push({field:r,old:a??null,new:i??null})}return n}function vr(e){const n=gr(e);if(n)return{kind:"relationship",change:n};const s=e.metadata;if(e.semantic_type!=="change"||!s)return null;const r=s._lobu_event_type;if(r!==fr&&(r!==void 0||s.category))return null;const a=jr(s.changes);if(!a)return null;const i=e.entity_ids?.[0];return{kind:"fields",entityId:typeof i=="number"?i:null,changes:a}}function sn(e,n){const s={slug:n},{data:r}=Ot(e.entityType?void 0:e.entityId??void 0,s),{data:a}=vn(e.entityType??r?.entity_type??"",s);return a?.metadata_schema}const br=4;function Ve({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(nr,{value:e,prop:n,empty:t.jsx("span",{className:"italic",children:"empty"})})})}function Dt({id:e,ownerSlug:n}){const s=typeof e=="number"||typeof e=="string"?Number(e):Number.NaN;return Number.isSafeInteger(s)&&s>0?t.jsx(ft,{id:s,ownerSlug:n}):t.jsx("span",{className:"italic text-muted-foreground",children:"empty"})}function xt(e,n){return`${e} ${n}${e===1?"":"s"}`}function _r({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(Ve,{value:e.old,prop:e.prop})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(Ve,{value:e.new,prop:e.prop})]});case"parent":return t.jsxs(t.Fragment,{children:[s,": ",t.jsx(Dt,{id:e.old,ownerSlug:n})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(Dt,{id:e.new,ownerSlug:n})]});case"items":return t.jsxs(t.Fragment,{children:[s,":"," ",[e.added?`${xt(e.added,"item")} added`:null,e.removed?`${xt(e.removed,"item")} removed`:null].filter(Boolean).join(", ")]});case"values":return t.jsxs(t.Fragment,{children:[s,":",e.added.map((r,a)=>t.jsxs("span",{className:"ml-1.5",children:["+",t.jsx(Ve,{value:r,prop:e.prop})]},`+${a}`)),e.removed.map((r,a)=>t.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["−",t.jsx(Ve,{value:r,prop:e.prop})]},`-${a}`))]});case"reordered":return t.jsxs(t.Fragment,{children:[s,": reordered"]})}}function Nr({change:e,ownerSlug:n}){const s=sn(e,n);return t.jsxs(t.Fragment,{children:["Updated ",pr(e.changes,s).join(", ")]})}function vt({changes:e,entityId:n,entityType:s,ownerSlug:r,showAll:a=!1}){const i=sn({entityId:n,entityType:s},r),[c,o]=j.useState(a),l=e.flatMap(u=>mr(u,i)),d=c?l:l.slice(0,br),p=l.length-d.length;return t.jsxs("ul",{"data-testid":"field-changes",className:"space-y-0.5 text-sm",children:[d.map((u,m)=>t.jsx("li",{className:"min-w-0 truncate",children:t.jsx(_r,{line:u,ownerSlug:r})},m)),p>0?t.jsx("li",{children:t.jsxs("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:u=>{u.stopPropagation(),o(!0)},children:["+",xt(p,"more change")]})}):null]})}function wr({event:e,ownerSlug:n}){return e.kind==="relationship"?t.jsx(yr,{change:e.change,ownerSlug:n}):t.jsx(Nr,{change:e,ownerSlug:n})}function kr({event:e,ownerSlug:n}){return e.kind==="fields"?t.jsx(vt,{changes:e.changes,entityId:e.entityId,ownerSlug:n}):null}function Cr({operation:e}){switch(e){case"create":case"created":return t.jsx(H,{variant:"default",children:"Created"});case"update":case"updated":return t.jsx(H,{variant:"secondary",children:"Updated"});case"delete":case"deleted":return t.jsx(H,{variant:"destructive",children:"Deleted"});default:return t.jsx(H,{variant:"outline",children:e||"Change"})}}function Ar({operation:e,actor:n,createdAt:s,resource:r,changedFields:a}){return t.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?t.jsx("span",{className:"break-words text-sm font-medium",children:r}):null,t.jsx(Cr,{operation:e}),t.jsx("time",{dateTime:s,title:s,className:"ml-auto text-xs text-muted-foreground",children:bn(s)})]}),t.jsxs("p",{className:"break-words text-xs text-muted-foreground",children:["by ",n||"unknown"]}),a?.length?t.jsxs("p",{className:"break-words text-xs text-muted-foreground",children:["Changed: ",a.join(", ")]}):null]})}function Rr(e){return e.semantic_type==="change"&&(e.metadata?.category==="config"||e.metadata?.category==="deployment")}function _e(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Sr({content:e}){const n=e.metadata??{},s=e.payload_data??{},r=n.category==="deployment",a=typeof n.apply_id=="string"?n.apply_id:null,i=_e(s.manifest),c=a&&/^apl_[A-Za-z0-9-]{1,48}$/.test(a)&&e.origin_type==="deployment"&&e.origin_id===`deployment_${a}`&&(n.status==="succeeded"||n.status==="partial_failure")&&_e(i?.state);return t.jsxs("div",{className:"space-y-3","data-testid":"config-change-event",children:[t.jsx(Ar,{operation:r?String(n.status??"Apply"):typeof n.op=="string"?n.op:null,actor:e.author_name??(typeof n.actor_source=="string"?n.actor_source:null),createdAt:e.occurred_at??e.created_at,resource:r?"Configuration apply":`${n.resource_kind??"Configuration"} · ${n.resource_id??""}`,changedFields:Array.isArray(n.changed_fields)?n.changed_fields.filter(o=>typeof o=="string"):void 0}),a?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 ",a]}),t.jsx(Tt,{text:a,label:"Copy apply ID"})]}):null,r?t.jsxs(t.Fragment,{children:[typeof n.rollback_of=="string"?t.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["Restores apply ",n.rollback_of]}):null,_e(n.counts)?t.jsx("dl",{className:"flex flex-wrap gap-4 text-xs",children:Object.entries(_e(n.counts)??{}).map(([o,l])=>t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o}),t.jsx("dd",{children:String(l)})]},o))}):null,typeof s.error=="string"?t.jsx("p",{className:"text-sm text-destructive",children:s.error}):null,c?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 ",a]}),t.jsx(Tt,{text:`lobu rollback ${a}`,label:"restore command",iconOnly:!0})]})]}):null,t.jsx(We,{before:null,after:i})]}):Object.hasOwn(s,"before")?t.jsx(We,{before:_e(s.before),after:_e(s.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(We,{before:null,after:_e(s.state)})]})]})}const $r={slack:"Slack",telegram:"Telegram",whatsapp:"WhatsApp",discord:"Discord",gchat:"Google Chat",teams:"Microsoft Teams",web:"Web"};function Ir(e){return $r[e]??null}function Tr(e){return e?e.kind==="automation"?`Ran ${e.automationName}`:e.platform==="web"?"Chatted in Lobu":`Replied on ${Ir(e.platform)??e.platform}`:"No activity yet"}function Er({owner:e,item:n,last:s,appearance:r="row"}){const a=r==="inline",i=a?"inline-flex items-center gap-1.5 rounded-md bg-accent px-1.5 py-0.5 text-sm font-medium":G(Je,!s&&"border-b");if(n.kind==="managed"){const l=n.agent,d=[l.lastActivity===void 0?null:Tr(l.lastActivity),l.connectionCount===void 0?null:`${l.connectionCount} ${l.connectionCount===1?"connection":"connections"}`,l.userCount===void 0?null:`${l.userCount} ${l.userCount===1?"user":"users"}`].filter(u=>!!u),p=t.jsx(Nn,{className:"h-4 w-4 text-muted-foreground"});return t.jsx(W,{to:"/$owner/agents/$agentId",params:{owner:e,agentId:l.agentId},className:i,children:a?t.jsxs(t.Fragment,{children:[p,l.name]}):t.jsx(Le,{mark:p,name:l.name,details:t.jsx(Qe,{parts:d.length>0?d:[l.description]}),at:l.lastActivity?Date.parse(l.lastActivity.at):void 0})})}const c=n.group,o=t.jsx(_n,{name:c.title});return t.jsx(W,{to:"/$owner/agents/connected/$clientId",params:{owner:e,clientId:c.clientId},className:i,children:a?t.jsxs(t.Fragment,{children:[o,c.title]}):t.jsx(Le,{mark:o,name:c.title,details:t.jsx(Qe,{parts:[c.connected?"Connected app":"Disconnected",c.linkedUser,c.drivenBy&&c.drivenBy!==c.title?`via ${c.drivenBy}`:null]}),at:c.lastSeenAt})})}const Mr={event:{label:"Event",icon:Pt},schedule:{label:"Schedule",icon:kn},manual:{label:"Manual",icon:wn}};function Dr(e,n,s){switch(Sn(e)){case"script":return["Script"];case"external":case"manual":return["Outside client"];case"device":{const r=e.agent_kind,a=r&&r in Et?Et[r]:r;return[n,s,a].filter(i=>!!i)}case"agent":return[n??"Agent","Hosted"]}}function Fr({automation:e,agentName:n,deviceLabel:s,connectorDisplay:r,owner:a,actions:i,rowClass:c,appearance:o="row"}){const l=e.automation,d=l.automation_id,p=Mr[e.kind];if(o==="inline")return t.jsxs(W,{to:"/$owner/automations/$automationId",params:{owner:a,automationId:d},search:{view:"definition",run_id:void 0},className:"inline-flex items-center gap-1.5 rounded-md bg-accent px-1.5 py-0.5 text-sm font-medium",children:[t.jsx(p.icon,{className:"h-3.5 w-3.5 shrink-0"}),e.does,l.status==="archived"?t.jsx(H,{variant:"outline",children:"Archived"}):null]});const u=Cn(e,Date.now()),m=l.processing_client_count??0,_=l.entity_name&&l.entity_type?`${l.entity_name} · ${l.entity_type}`:null;return t.jsxs("div",{className:c,children:[t.jsx(W,{to:"/$owner/automations/$automationId",params:{owner:a,automationId:d},search:{view:"definition",run_id:void 0},className:"flex min-w-0 flex-1 items-center gap-3",children:t.jsx(Le,{mark:r?t.jsx(Rn,{icon:r.icon,iconUrl:r.iconUrl,name:r.name,faviconDomain:r.faviconDomain,className:"h-7 w-7 text-[10px]"}):t.jsx(p.icon,{className:"h-4 w-4 text-muted-foreground"}),name:e.does,badge:l.status==="archived"?t.jsx(H,{variant:"outline",children:"Archived"}):null,tone:u.problem?"destructive":null,details:t.jsx(Qe,{parts:[u.text,...Dr(l,n,s),m>0?`${m} ${m===1?"client":"clients"}`:null,An(e.when),_]}),at:u.at})}),i]})}function Lr({record:e,workspace:n,appearance:s}){return t.jsx(Fr,{automation:In(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 Or({agent:e,workspace:n,appearance:s}){return t.jsx(Er,{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 Pr({connector:e,connection:n,workspace:s,appearance:r}){const a=e.key,i=t.jsx(Tn,{connector:e,showDescription:r!=="inline"});return t.jsx("div",{className:r==="inline"?"inline-flex items-center gap-2":"rounded-lg border p-3",children:n?t.jsxs(W,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:s,connectorKey:a,connectionId:String(n.id)},search:{},children:[i,t.jsx("span",{className:"text-xs text-muted-foreground",children:$n(n)})]}):t.jsx(W,{to:"/$owner/connectors/$connectorKey",params:{owner:s,connectorKey:a},children:i})})}function He(e,n){return typeof e=="string"&&e.trim().length>0&&e.length<=n}function bt(e,n){if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n;if(s.mode!=="live"||!He(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 r={mode:"live",workspace:s.workspace,appearance:s.appearance??"row"};return e==="automation-ref"?!He(s.automationId,128)||!/^[1-9][0-9]*$/.test(s.automationId)||!Number.isSafeInteger(Number(s.automationId))?null:{...r,automationId:s.automationId}:e==="connector-ref"?!He(s.connectorKey,128)||s.connectionId!==void 0&&(typeof s.connectionId!="number"||!Number.isSafeInteger(s.connectionId)||s.connectionId<=0)?null:{...r,connectorKey:s.connectorKey,...s.connectionId!==void 0?{connectionId:s.connectionId}:{}}:He(s.agentId,128)?{...r,agentId:s.agentId}:null}const Br=4,Ur=128;let it=0;const De=[];async function zr(e,n){if(e.aborted)throw e.reason;await new Promise((s,r)=>{const a=()=>{const c=De.indexOf(i);c>=0&&De.splice(c,1),r(e.reason)},i=()=>{e.removeEventListener("abort",a),it++,s()};it<Br?i():De.length>=Ur?r(new Error("Reference read capacity exceeded")):(De.push(i),e.addEventListener("abort",a,{once:!0}))});try{if(e.aborted)throw e.reason;return await n()}finally{it--,De.shift()?.()}}const Ze={retry:!1,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchOnReconnect:"always"};function we({error:e}){const n=e instanceof Re&&(e.status===401||e.status===403)?"Access required to view this reference.":e instanceof Re&&e.status===404?"Reference not found.":"Reference unavailable.";return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:n})}function _t(){return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:"Loading reference…"})}function Kr({workspace:e,automationId:n,appearance:s}){const{session:r,isReady:a}=et(),i=gt(),c=Ye({...Ze,enabled:a&&!i,queryKey:["automations-list",e,"native-reference",r?.user.id??null,n],queryFn:({signal:l})=>zr(l,async()=>{let d;for(const u of["active","archived"])if(d=(await Ae("manage_automations",{action:"list",automation_id:n,status:u,include_details:!1,limit:1},{slug:e},{signal:l})).automations?.find(_=>_.automation_id===n),d)break;if(!d)throw new Re("Reference not found",404);const p=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:p&&typeof p=="object"?{executor:{kind:p.kind}}:void 0},d})});if(i)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(c.isPending||c.isFetching)return t.jsx(_t,{});if(c.error||!c.data)return t.jsx(we,{error:c.error});const o=c.data;return t.jsx(Lr,{record:o,workspace:e,appearance:s})}function qr({workspace:e,connectorKey:n,connectionId:s,appearance:r}){const{session:a,isReady:i}=et(),c=gt(),o=Ye({...Ze,enabled:i&&!c,queryKey:["connector-definitions",e,"native-reference",a?.user.id??null],queryFn:async({signal:u})=>(await En({slug:e},{signal:u})).map(m=>({key:m.key,name:m.name,description:m.description,icon:m.icon}))}),l=Ye({...Ze,enabled:i&&!c&&s!==void 0,queryKey:["connections",e,"native-reference",a?.user.id??null,n,s??null],queryFn:async({signal:u})=>{const m=s===void 0?void 0:(await Ae("manage_connections",{action:"list",connection_ids:[s],connector_key:n,limit:1},{slug:e},{signal:u})).connections?.find(_=>_.id===s);if(s!==void 0&&(!m||m.id!==s||m.connector_key!==n))throw new Re("Reference not found",404);return{connection:m?{id:m.id,connector_key:m.connector_key,display_name:m.display_name,connector_name:m.connector_name,auth_profile_name:m.auth_profile_name,auth_profile_slug:m.auth_profile_slug}:void 0}}});if(c)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(o.isPending||o.isFetching||s!==void 0&&(l.isPending||l.isFetching))return t.jsx(_t,{});if(o.error||s!==void 0&&(l.error||!l.data))return t.jsx(we,{error:o.error||l.error});const d=o.data?.find(u=>u.key===n);if(!d)return t.jsx(we,{error:new Re("Reference not found",404)});const p=l.data?.connection;return t.jsx(Pr,{connector:d,connection:p,workspace:e,appearance:r})}function Vr({workspace:e,agentId:n,appearance:s}){const{session:r,isReady:a}=et(),i=gt(),c=Ye({...Ze,enabled:a&&!i,queryKey:["agents",e,"native-reference",r?.user.id??null,n],queryFn:async({signal:l})=>{const d=await Ae("manage_agents",{action:"get",agent_id:n},{slug:e},{signal:l});if(d.agent?.id!==n)throw new Re("Reference not found",404);return{id:d.agent.id,name:d.agent.name,description:d.agent.description}}});if(i)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(c.isPending||c.isFetching)return t.jsx(_t,{});if(c.error||!c.data)return t.jsx(we,{error:c.error});const o=c.data;return t.jsx(Or,{agent:o,workspace:e,appearance:s})}function Hr(e){const n=bt("automation-ref",e);return n?t.jsx(Kr,{...n}):t.jsx(we,{})}function Wr(e){const n=bt("connector-ref",e);return n?t.jsx(qr,{...n}):t.jsx(we,{})}function Jr(e){const n=bt("agent-ref",e);return n?t.jsx(Vr,{...n}):t.jsx(we,{})}const ot=e=>typeof e=="string"&&e.trim().length>0&&e.length<=128,Qr={tabs:({defaultValue:e,children:n})=>ot(e)?t.jsx(Ws,{defaultValue:e,children:n}):null,"tabs-list":({label:e,children:n})=>t.jsx(Hs,{label:typeof e=="string"&&e.length<=200?e:void 0,children:n}),"tabs-trigger":({value:e,children:n})=>ot(e)?t.jsx(Vs,{value:e,children:n}):null,"tabs-content":({value:e,children:n})=>ot(e)?t.jsx(qs,{value:e,children:n}):null,"automation-ref":Hr,"connector-ref":Wr,"agent-ref":Jr,"json-diff":(({before:e,after:n})=>{const s=r=>r!==null&&typeof r=="object"&&!Array.isArray(r)?r:null;return t.jsx(We,{before:s(e),after:s(n)})})};function Fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Yr({template:e,data:n,onAction:s}){const[r,a]=j.useState(null),[i,c]=j.useState(!1),[o,l]=j.useState(null),[d,p]=j.useState(!1),u=j.useRef(!1),m=j.useRef(!0);j.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]);const _=async w=>{if(!(!s||u.current)){u.current=!0,c(!0),l(null),p(!1);try{const h=await s(w);if(!m.current)return;if(Fe(h)&&h.kind==="sdk"){const v=h.result;if(!Fe(v)||v.success!==!0){const N=Fe(v)&&Fe(v.error)?v.error.message:null;throw new Error(typeof N=="string"?N:"Could not update this event.")}if(v.return_truncated||!Fe(v.return_value))throw new Error("The update did not return a complete data object.");a(v.return_value),p(!0)}}catch(h){m.current&&l(h instanceof Error?h.message:"Could not update this event.")}finally{u.current=!1,m.current&&c(!1)}}};return t.jsxs("div",{className:"space-y-2",children:[i?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,o?t.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:[o," Previous data is still shown."]}):null,t.jsx("div",{"aria-busy":i,className:"min-w-0",children:t.jsx(tr,{template:{root:e.root},data:r??n,onAction:s?_:void 0,interactions:e.interactions,components:Qr,actionsDisabled:!s||i})})]})}function rn(e){return{audit:Yt(e),operation:e.interaction_type==="approval"||e.semantic_type==="operation",changeSet:e.semantic_type==="change_set"}}const Gr={},Zr={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function Xr(e){return e.author_name?e.author_name:e.platform?Ge(e.platform):e.origin_type?Zr[e.origin_type]??Ge(e.origin_type):null}function ea(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 lt=1e5;function Ft({value:e}){const n=JSON.stringify(e,null,2)??"null",s=n.length>lt;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,lt):n}),s&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",lt.toLocaleString()," of"," ",n.length.toLocaleString()," characters."]})]})}function ta(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 na({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 sa({slug:e,value:n,isManual:s}){return t.jsxs(H,{variant:"secondary",className:"text-xs",children:[e,": ",n,s&&t.jsx(zt,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function ra(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 an(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 ht(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function aa(e){return e.replace(/\s+[—-]\s+pending approval$/i,"")}function Xe(e){return e.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,n=>n.toUpperCase())}function ia(e){const n=Object.keys(e.fields),s=n.map(Xe).join(", ")||"field",r=n.length===1?"field":"fields";return`Update ${e.entityType?Xe(e.entityType).toLowerCase():"entity"} ${r}: ${s}`}function oa(e,n){const s=ht(n.fields);if(!s||Object.keys(s).length===0||n.action_key!=="entity_field_change"&&n.tool!=="entity_field_change")return null;const r=ht(n.current)??{},a=e;return{fields:s,current:r,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,initiator:n.initiator&&typeof n.initiator=="object"?n.initiator:void 0}}function la(e){const n=e.entityType?Xe(e.entityType).toLowerCase():"entity";return`${Xe(e.operation)} ${n}`}function ca(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 r=e;return{operation:s,proposal:ht(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)??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,proposerRationale:typeof n.proposer_rationale=="string"?n.proposer_rationale:void 0,initiator:n.initiator&&typeof n.initiator=="object"?n.initiator:void 0}}function da(e,n){return!n.entityType||!n.entitySlug?null:fs(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 on({ownerSlug:e,runId:n,details:s}){const a=Zt(s.automationId,void 0,void 0,{ownerSlug:e,includeVersions:!1}).data?.automation,i=Pe(),c=Qs(s.initiator,s.attribution,s.automationId),o=a?.automation_name??s.automationName??c;return t.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",s.automationId?t.jsx(W,{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:o}):t.jsx("span",{className:"font-medium text-foreground",children:o}),n&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:" · "}),t.jsxs(W,{to:"/$owner/events",params:{owner:e},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",onClick:l=>{!i||l.button!==0||l.metaKey||l.ctrlKey||l.shiftKey||l.altKey||(l.preventDefault(),i.open({href:`/${e}/events?run_ids=${n}`,title:`Run #${n}`,runId:n}))},children:["Run #",n]})]})]})}function ln({ownerSlug:e,details:n}){const s=da(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(W,{to:s,className:"underline-offset-4 hover:underline",children:n.entityName}):n.entityName})]}):null}function ua({ownerSlug:e,runId:n,details:s}){return t.jsxs("div",{className:"space-y-3",children:[t.jsx(on,{ownerSlug:e,runId:n,details:s}),t.jsx(ln,{ownerSlug:e,details:s}),t.jsx("div",{className:"rounded-md border border-border/70 px-3 py-2",children:t.jsx(vt,{changes:Object.entries(s.fields).map(([r,a])=>({field:r,old:s.current[r]??null,new:a??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 ma({ownerSlug:e,runId:n,details:s,status:r}){const{operation:a}=s,i=a==="link"||a==="unlink";return t.jsxs("div",{className:"space-y-3",children:[t.jsx(on,{ownerSlug:e,runId:n,details:s}),!i&&t.jsx(ln,{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:i?en(a,r):a==="create"?"Create a new entity after approval.":"Delete this entity after approval."}),i&&t.jsxs("div",{className:"mt-2 space-y-1 text-sm",children:[Xt(s.proposal).map((c,o)=>t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:o===0?"From: ":"To: "}),c.name]},c.id)),t.jsxs("div",{className:"text-muted-foreground",children:["Relationship:"," ",String(s.proposal?.relationship_type??s.proposal?.relationship_type_slug??"Relationship")]})]})]}),!i&&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 pa({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(H,{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(Qt,{className:"h-3 w-3"})]})]})}function fa({ownerSlug:e,content:n,batchReview:s}){const r=n.metadata||{},a=n.run_id??void 0,i=sr(r),c=oa(n,r),o=ca(n,r),l=(c?ia(c):o?la(o):void 0)||r.operation_name||r.action_name||(n.title?aa(n.title):void 0)||"Action",d=r.connection_name,p=r.operation_key||r.action_key||null,u=n.interaction_input_schema||r.input_schema||null,m=j.useMemo(()=>n.interaction_input||r.action_input||r.operation_input||Gr,[n.interaction_input,r.action_input,r.operation_input]),_=n.interaction_output||r.action_output||void 0,w=or(m,_??null,p),h=n.interaction_error||r.error_message||void 0,v=an(n.interaction_status,r.status),N=r.reviewed_by_name||r.reviewed_by_id||void 0,k=r.reject_reason||void 0,R=r.initiator,A=ts({slug:e}),T=ns({slug:e}),E=ss(n.id,rs(u,m),u),{values:M,setValues:S}=E,[D,x]=j.useState(null),[B,V]=j.useState(!1),[P,y]=j.useState(""),L=v==="pending_approval"&&D?D:v,F=L==="pending_approval",Z=typeof r.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(Pt,{className:"h-4 w-4 text-yellow-500"}),t.jsx("span",{className:"font-medium",children:l}),d&&t.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",d]}),L==="confirmed"&&t.jsx(H,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:"Approved"}),L==="completed"&&t.jsx(H,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),L==="failed"&&t.jsx(H,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),L==="rejected"&&t.jsx(H,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!c&&!o&&(n.author_name||N)&&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(Js,{ownerSlug:e,initiator:R,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&N&&t.jsx("span",{children:"·"}),N&&t.jsxs("span",{children:[L==="rejected"?"Rejected":"Approved"," by"," ",t.jsx("span",{className:"font-medium text-foreground",children:N})]})]}),c&&t.jsx(ua,{ownerSlug:e,runId:a,details:c}),!c&&o&&t.jsx(ma,{ownerSlug:e,runId:a,details:o,status:L}),L==="rejected"&&k&&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:"})," ",k]}),w&&t.jsx(pa,{summary:w}),i&&t.jsx(rr,{proposal:i}),!i&&(F?E.revision:u)&&(F||Object.keys(m).length>0)&&t.jsxs("div",{children:[t.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:w?"Full input":"Input"}),F?t.jsxs(t.Fragment,{children:[t.jsx(as,{visible:E.hasConflict,onReload:E.reset}),t.jsx(is,{schema:E.revision,values:M,onValuesChange:S,fieldIdPrefix:`action-${n.id}-`},`action-${n.id}`)]}):w?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(m,null,2)})]}):t.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(m,null,2)})]}),L==="completed"&&_&&Object.keys(_).length>0&&!w&&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(Vt,{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(_,null,2)})]}),L==="completed"&&_&&Object.keys(_).length>0&&w&&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(_,null,2)})]}),L==="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(qt,{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})]}),F&&!D&&Z&&t.jsxs("div",{className:"pt-1 text-xs text-muted-foreground",children:["Review this proposal with the other changes in its Automation run.",s]}),F&&a&&!D&&!Z&&t.jsx("div",{className:"flex items-center gap-2 pt-1",children:B?t.jsxs("div",{className:"flex items-center gap-2 w-full",children:[t.jsx("input",{type:"text",placeholder:"Reason (optional)",value:P,onChange:le=>y(le.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(O,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>T.mutate({run_id:a,reason:P||void 0},{onSuccess:()=>{x("rejected")}}),disabled:T.isPending,children:[T.isPending&&t.jsx(Ne,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),t.jsx(O,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{V(!1),y("")},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[t.jsxs(O,{size:"sm",className:"h-7 text-xs",onClick:()=>A.mutate({run_id:a,...i?{}:{input:ls(M)}},{onSuccess:()=>{x("confirmed")}}),disabled:!i&&!E.canSubmit||A.isPending||T.isPending,children:[A.isPending?t.jsx(Ne,{size:"sm",className:"mr-1"}):t.jsx(os,{className:"h-3 w-3 mr-1"}),i?"Approve":"Confirm"]}),t.jsxs(O,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>V(!0),disabled:A.isPending||T.isPending,children:[t.jsx(cs,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function xa({content:e,ownerSlug:n}){const s=e.metadata||{},r=s.kind,a=e.run_id??null,i=typeof s.automation_id=="number"?s.automation_id:null,l=Zt(i!=null?String(i):void 0,void 0,void 0,{includeVersions:!1,ownerSlug:n}).data?.automation?.automation_name??(i!=null?`Automation ${i}`:"An Automation"),d=Xn({slug:n}),p=es({slug:n}),[u,m]=j.useState(!1),[_,w]=j.useState(""),[h,v]=j.useState(null);if(r==="automation_batch_reject"){const x=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"}),x&&t.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:x}),t.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Ask the agent to revise its proposals with this feedback."})]})}const N=Array.isArray(s.changes)?s.changes:[],k=typeof s.created_count=="number"?s.created_count:N.filter(x=>x.kind==="created").length,R=typeof s.updated_count=="number"?s.updated_count:N.filter(x=>x.kind==="updated").length,A=typeof s.denied_count=="number"?s.denied_count:N.filter(x=>x.kind==="denied").length,T=N.filter(x=>x.kind==="denied"),E=N.filter(x=>x.kind==="updated"&&Object.keys(x.applied||{}).length>0),M=typeof s.pending_proposal_count=="number"?s.pending_proposal_count:null,S=M==null||M>0,D=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:[D==="proposed"?"Proposed":"Applied"," ",k," ","new + ",R," updated",A>0&&t.jsxs(t.Fragment,{children:[" + ",A," denied"]})]}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[i!=null?t.jsx(W,{to:"/$owner/automations/$automationId",params:{owner:n,automationId:String(i)},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}),a!=null&&t.jsxs("span",{children:[" · run #",a]}),M!=null&&M>0&&t.jsxs("span",{children:[" · ",M," pending"]})]})]}),E.length>0&&t.jsx("div",{className:"mt-3 space-y-2",children:E.map(x=>t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:x.name}),t.jsx(vt,{changes:Object.entries(x.applied).map(([B,V])=>({field:B,old:V.old??null,new:V.new??null})),entityId:x.entityId,ownerSlug:n,showAll:!0})]},x.entityId))}),T.length>0&&t.jsx("div",{className:"mt-3 space-y-1.5",children:T.map(x=>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:[x.name," — not written"]}),x.denied&&t.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[x.denied.reason,t.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",x.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${x.entityId}-${x.name}`))}),a!=null&&h==null&&S&&t.jsx("div",{className:"mt-3 border-t border-border/70 pt-3",children:u?t.jsxs("div",{className:"flex items-center gap-2 w-full",children:[t.jsx("input",{type:"text",placeholder:"What should the agent change?",value:_,onChange:x=>w(x.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(O,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>p.mutate({run_id:a,reason:_||void 0},{onSuccess:()=>v("rejected")}),disabled:p.isPending,children:[p.isPending&&t.jsx(Ne,{size:"sm",className:"mr-1"}),"Reject all"]}),t.jsx(O,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{m(!1),w("")},children:"Cancel"})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(O,{size:"sm",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:a},{onSuccess:()=>v("approved")}),disabled:d.isPending||p.isPending,children:[d.isPending&&t.jsx(Ne,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),t.jsx(O,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>m(!0),disabled:d.isPending||p.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."}),a!=null&&h==null&&!S&&t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function ha(e){if(!e)return;const n={};for(const[s,r]of Object.entries(e))s==="_lobu_idempotency_key"||s==="agent_id"||(n[s]=r);return Object.keys(n).length>0?n:void 0}function ga({renderDetail:e,ownerSlug:n,content:s,connectorDefinitions:r,hideDetails:a=!1}){const[i,c]=j.useState(null),[o,l]=j.useState(!1),[d,p]=j.useState(!1),[u,m]=j.useState(!1),[_,w]=j.useState(!1),[h,v]=j.useState(!1),[N,k]=j.useState(null),[R,A]=j.useState(s.title??""),[T,E]=j.useState(s.text_content??""),M=Kn(),S=qn(),D=Pe(),{currentOwner:x,allOrgs:B,isAuthenticated:V}=Vn(),P=n??x,y=P==="me"?null:P,L=j.useCallback(async g=>{if(!y){Ue.error("Open this event inside a workspace to interact with it.");return}const $=await ar(y,Number(s.id),g,crypto.randomUUID());return"event_id"in $&&Ue.success("Recorded"),$},[s.id,y]),F=s.payload_data??{},{audit:Z,operation:le,changeSet:J}=rn(s),pe=Z&&(F.request!==void 0||F.request_status==="too_large"),Q=Z&&Array.isArray(F.sdk_call_trace)&&F.sdk_call_trace.length>0,X=V&&y?(B??[]).find(g=>g.slug===y):void 0,ce=s.semantic_type==="guidance",{isAdmin:fe,isLoading:ee}=Hn(ce?X?.id:void 0),ne=Wn(),je=Rr(s),Y=mt(D?.item?.href.split(/[?#]/)[0]??""),se=Y?.owner===P&&Y?.eventId===Number(s.id),re=(g,$,K)=>{D?D.open({href:g,title:$,...K==null?{}:{runId:K}}):M({to:g})},ae=(g,$)=>{if(!y)return null;const K=`/${y}/events?run_ids=${g}`;if(D?.item?.href===K)return null;const ge=()=>re(K,`Run #${g}`,g),Me="Show everything this run recorded";return $?t.jsxs(O,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:ge,title:Me,children:[t.jsx(Zn,{className:"h-3.5 w-3.5"}),$]}):t.jsxs("button",{type:"button",className:"hover:text-foreground hover:underline",onClick:ge,title:Me,children:["Run #",g]})},ie=s.run_id!=null&&!(D&&y&&s.automation_id!=null)?ae(s.run_id):null,de=Jn(s),ue=s.automation_id,xe=D&&y&&de!=null&&ue!=null?()=>D.open({href:`/${y}/automations/${ue}?view=activity&run_id=${de}`,title:`${s.automation_name??`Automation ${ue}`} · Run #${de}`,runId:de}):void 0,te=s.metadata?.source_run_id,z=vr(s),ve=(!s.platform||s.platform==="lobu")&&s.connection_id==null&&s.feed_id==null&&s.origin_type==null&&s.automation_id==null&&!Z&&!le&&!J&&!je&&z==null&&s.semantic_type!=="tombstone"&&s.semantic_type!=="notification"&&s.metadata?.tombstone!==!0&&s.interaction_type!=="approval"&&s.interaction_status==null&&!s.is_superseded&&s.superseded_by==null,ke=!!(y&&X&&ve&&(!ce||!ee&&fe)),b=ke&&s.payload_type!=="json_template"&&s.payload_type!=="media",I=()=>{ne.invalidateQueries({queryKey:[ms]}),ne.invalidateQueries({queryKey:[ps]}),ne.invalidateQueries({queryKey:["search-memory"]})},me=async()=>{if(!(!y||!b)){if(w(!1),k(null),s.payload_truncated){p(!0);try{const $=(await Ae("read_knowledge",{content_ids:[Number(s.id)]},{slug:y})).content?.find(K=>Number(K.id)===Number(s.id));A($?.title??s.title??""),E($?.text_content??$?.payload_text??s.text_content??""),l(!0)}catch(g){k(g instanceof Error?g.message:"Failed to load full memory.")}finally{p(!1)}return}A(s.title??""),E(s.text_content??""),l(!0)}},$e=async()=>{if(!y||u)return;if(!T.trim()){k("Memory content cannot be empty.");return}m(!0),k(null);try{const $=s.payload_type==="markdown"||s.payload_type==="text"?s.payload_type:"text",K=ha(s.metadata);await Ae("save_memory",{supersedes_event_id:Number(s.id),semantic_type:s.semantic_type||"note",payload_type:$,title:R.trim()||void 0,content:T,...Array.isArray(s.entity_ids)&&s.entity_ids.length>0?{entity_ids:s.entity_ids}:{},...s.source_url?{source_url:s.source_url}:{},...s.author_name?{author:s.author_name}:{},...s.occurred_at?{occurred_at:s.occurred_at}:{},...s.payload_data&&Object.keys(s.payload_data).length>0?{payload_data:s.payload_data}:{},...K?{metadata:K}:{}},{slug:y}),l(!1),I(),Ue.success("Memory updated")}catch($){k($ instanceof Error?$.message:"Failed to update memory.")}finally{m(!1)}},Ie=async()=>{if(!(!y||h)){v(!0),k(null);try{const g=Number(s.id),$=await Ae("run_sdk",{title:"Delete memory",script:`export default async (_ctx, client) => client.knowledge.delete(${JSON.stringify({content_id:g,reason:"Deleted from web UI"})});`},{slug:y});if($?.success===!1){const ge=typeof $.error=="string"?$.error:$.error?.message||"Failed to delete memory.";throw new Error(ge)}w(!1),se&&D?.close();const K=mt(S.pathname);K?.owner===y&&K.eventId===g&&M({to:"/$owner/events",params:{owner:y}}),I(),Ue.success("Memory deleted")}catch(g){k(g instanceof Error?g.message:"Failed to delete memory.")}finally{v(!1)}}},Te=ke&&!o?_?t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsxs(O,{type:"button",variant:"destructive",size:"sm",className:"h-7 px-2.5 text-xs",disabled:h,onClick:()=>void Ie(),children:[h&&t.jsx(Ne,{size:"xs",className:"mr-1.5"}),h?"Deleting...":"Delete"]}),t.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:h,onClick:()=>{w(!1),k(null)},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[b&&t.jsxs(O,{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:d||h,onClick:()=>void me(),children:[d?t.jsx(Ne,{size:"xs"}):t.jsx(ds,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:d?"Loading...":"Edit"})]}),t.jsxs(O,{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:d,onClick:()=>{k(null),w(!0)},children:[t.jsx(us,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"Delete"})]})]}):null,tt=o?t.jsxs("form",{className:"mt-2 space-y-3 rounded-lg border bg-background p-3 text-foreground",onSubmit:g=>{g.preventDefault(),$e()},children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{htmlFor:`memory-title-${s.id}`,className:"block text-xs font-medium text-muted-foreground",children:"Title"}),t.jsx(Qn,{id:`memory-title-${s.id}`,"aria-label":"Memory title",value:R,onChange:g=>A(g.target.value),placeholder:"Optional short summary",disabled:u})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{htmlFor:`memory-content-${s.id}`,className:"block text-xs font-medium text-muted-foreground",children:["Content",t.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),t.jsx(Yn,{id:`memory-content-${s.id}`,"aria-label":"Memory content",value:T,onChange:g=>E(g.target.value),rows:5,disabled:u})]}),N&&t.jsx("div",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:N}),t.jsx(Gn,{onCancel:()=>{l(!1),k(null)},cancelDisabled:u,children:t.jsxs(O,{type:"submit",disabled:u||T.trim().length===0,children:[u&&t.jsx(Ne,{size:"xs",className:"mr-1.5"}),u?"Saving...":"Save"]})})]}):null,Be=!o&&N?t.jsx("div",{role:"alert",className:"mt-2 rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:N}):null,Ee=je?t.jsx(Sr,{content:s}):y?J?t.jsx(xa,{content:s,ownerSlug:y}):le?t.jsx(fa,{ownerSlug:y,content:s,batchReview:typeof te=="number"?ae(te,"Review run"):null}):void 0:void 0,he=e?e(Ee):{content:Ee,nativeHeading:Ee!=null};return t.jsx(va,{primaryContent:he.content,nativeHeading:he.nativeHeading,heading:z&&y?t.jsx(wr,{event:z,ownerSlug:y}):void 0,body:tt??(z&&y?t.jsx(kr,{event:z,ownerSlug:y}):void 0),detailLinks:he.links,headingAside:he.headingAside,hideDetails:a,presentation:"detail",content:s,ownerSlug:P??void 0,connectorDefinitions:r,onRenderedAction:y?L:void 0,runAction:ie,memoryActions:Te,memoryFeedback:Be,runId:de??s.run_id??null,onRunSelect:xe,auditDetails:(pe||Q)&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-2",children:[{key:"request",label:"Request",available:pe},{key:"calls",label:"SDK calls",available:Q}].map(g=>g.available?t.jsxs(O,{variant:"outline",size:"sm","aria-expanded":i===g.key,onClick:()=>c($=>$===g.key?null:g.key),children:[i===g.key?t.jsx(dt,{className:"h-3.5 w-3.5"}):t.jsx(ut,{className:"h-3.5 w-3.5"}),g.label]},g.key):null)}),i==="request"&&(F.request_status==="too_large"?t.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof F.request_bytes=="number"?` (${F.request_bytes.toLocaleString()} bytes).`:"."]}):t.jsx(Ft,{value:F.request})),i==="calls"&&t.jsx(Ft,{value:F.sdk_call_trace})]})})}function ya(e,n){const s=e.payload_data??{},r=e.metadata??{};if(n.audit&&typeof s.success=="boolean")return s.success?"completed":"failed";if(n.changeSet)return r.kind==="automation_batch_reject"?"rejected":typeof r.pending_proposal_count!="number"?void 0:r.pending_proposal_count>0?"pending_approval":"completed";if(n.operation)return an(e.interaction_status,typeof r.status=="string"?r.status:void 0)}function ja(e){return e==="pending_approval"?"Needs approval":e==="confirmed"?"Approved":e?Ge(e):null}function va({presentation:e,primaryContent:n,nativeHeading:s=!1,heading:r,body:a,detailLinks:i,headingAside:c,content:o,ownerSlug:l,connectorDefinitions:d,onRenderedAction:p,runAction:u,memoryActions:m,memoryFeedback:_,auditDetails:w,runId:h,onRunSelect:v,hideDetails:N=!1}){const[k,R]=j.useState(!1),A=o.metadata??{},T=typeof o.score=="number"&&Number.isFinite(o.score)?Math.round(o.score):"-",E=o.payload_type||"text",M=E==="text"&&(o.semantic_type==="notification"||o.automation_id!=null)?"markdown":E,S=o.text_content||"",D=e==null&&(M==="text"||M==="markdown")&&S.length>500,x=D&&!k?`${S.slice(0,500)}...`:S,B=o.payload_data??{},V=rn(o),{audit:P,operation:y}=V,L=ya(o,V),F=ja(L),Z=(P?Bt(o).title:null)??o.title,le=P&&B.error&&typeof B.error=="object"?B.error.message:void 0,[J,pe]=j.useState(P&&n==null&&i==null),Q=P?B.duration_ms:A.duration_ms,X=typeof Q=="number"&&Number.isFinite(Q)&&Q>=0?Q:null,ce=P&&typeof B.sdk_call_count=="number"&&Number.isSafeInteger(B.sdk_call_count)&&B.sdk_call_count>=0?B.sdk_call_count:null,fe=A.thumbnail_url||A.thumbnail,ee=A.media_url,ne=ta(A),je=Object.entries(o.classifications||{}).flatMap(([b,I])=>{const me=ra(I);return me.values.map($e=>({slug:b,value:$e,isManual:me.isManual}))}),Y=(()=>{const b=o.platform||(typeof A.platform=="string"?A.platform:null),I=o.connection_id!=null?o.connection_id:A.source_connection_id!=null?Number(A.source_connection_id):null;return{...o,platform:b,connection_id:I!=null&&Number.isFinite(I)?I:null}})(),se=(()=>{const b=o.source_url??A.browser_url;if(typeof b!="string"||!URL.canParse(b))return null;const I=new URL(b);return I.protocol==="https:"||I.protocol==="http:"?I:null})(),re=o.occurred_at?new Date(o.occurred_at):null,{KindIcon:ae,kindLabel:ie}=Ut(o),de=t.jsx(yt,{source:Y,connectorDefinitions:d,sourceUrl:se,label:ie,fallback:t.jsx(ae,{className:"h-4 w-4"})}),ue=ne.length>0?t.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:ne.map(([b,I])=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{className:"text-muted-foreground",children:Ge(b)}),t.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:ea(I)})]},b))}):null,xe=a?t.jsx("div",{className:"mt-1",children:a}):t.jsxs(t.Fragment,{children:[o.rating&&t.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(b=>t.jsx(zt,{className:`h-4 w-4 ${b<=Number(o.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},b))}),fe&&t.jsx("a",{href:ee||o.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:t.jsx("img",{src:fe,alt:"",className:`rounded-md object-cover ${M==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),(()=>{switch(M){case"markdown":if(x)return t.jsx("div",{className:"max-w-none text-sm space-y-2",children:t.jsx(Mn,{text:x})});break;case"json_template":{const b=o.payload_data;if(b?._truncated===!0&&typeof b.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."}),l?t.jsx(W,{to:Kt(l,Number(o.id)),className:"underline underline-offset-4",children:"Open full report"}):null]});const I=o.payload_template;if(I?.root)return t.jsx(Yr,{template:I,data:o.payload_data||{},onAction:n?void 0:p},`${l}:${o.id}`);if(x)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:x});break}case"media":return t.jsxs("div",{className:"space-y-3",children:[!fe&&ee&&t.jsx("a",{href:ee,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:ee}),x&&t.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:x})]});case"empty":return t.jsxs("div",{className:"space-y-3",children:[w,ue??(w?null:t.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"}))]});default:if(x)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:x});break}return t.jsxs("div",{className:"space-y-3",children:[ee&&!fe&&t.jsx("a",{href:ee,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:ee}),ue]})})()]}),te=n!=null||e==="detail"&&P,z=c!==void 0,ve=te||i!=null,ke=!!(F&&!s||ce!=null||X!=null||!z&&m!=null||T!=="-"&&o.score_breakdown!=null||se!=null);return j.useEffect(()=>{if(!z||!J)return;const b=I=>{I.key==="Escape"&&(I.preventDefault(),pe(!1))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[z,J]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:G("flex gap-3",e==="detail"&&"mb-5",z&&"relative"),children:[t.jsx(Dn,{children:de}),t.jsxs("div",{className:"min-w-0 flex-1",children:[e==="detail"&&(()=>{const b={semantic_types:o.semantic_type,...typeof o.automation_id=="number"?{produced_by:String(o.automation_id)}:{},...typeof o.run_id=="number"?{run_ids:String(o.run_id)}:{}};return t.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[o.semantic_type?l?t.jsx(W,{to:"/$owner/events",params:{owner:l},search:b,className:"hover:underline",title:`Show all ${ie} events`,children:ie}):t.jsx("span",{children:ie}):t.jsx("span",{children:ie}),re&&t.jsx("time",{dateTime:re.toISOString(),children:Fn(re)}),u]})})(),t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[(r??Z)&&!s&&t.jsx("h4",{className:G("min-w-0 font-medium",e==="detail"?"text-xl leading-snug":"line-clamp-2 text-sm"),children:r??Z}),e!=="detail"&&re&&t.jsx(Ln,{at:re}),z&&t.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-1 pt-0.5",children:[c,m,ve&&t.jsxs(O,{type:"button",variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-muted-foreground hover:text-foreground","aria-expanded":J,onClick:()=>pe(b=>!b),children:["Details",J?t.jsx(dt,{className:"h-3.5 w-3.5"}):t.jsx(ut,{className:"h-3.5 w-3.5"})]})]})]}),ke&&t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[F&&!s&&t.jsxs(H,{variant:L==="failed"?"destructive":"secondary",className:"gap-1 text-xs",children:[L==="failed"?t.jsx(qt,{className:"h-3 w-3"}):L==="completed"?t.jsx(Vt,{className:"h-3 w-3"}):null,F]}),ce!=null&&t.jsxs("span",{children:[ce," SDK ",ce===1?"call":"calls"]}),X!=null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(On,{className:"h-3 w-3"}),X<1e3?`${Math.round(X)}ms`:`${Number((X/1e3).toFixed(2))}s`]}),T==="-"?null:o.score_breakdown?t.jsxs(Ht,{children:[t.jsx(Wt,{asChild:!0,children:t.jsx(O,{variant:"ghost",size:"sm",className:"h-7 px-2",children:t.jsx("span",{className:"font-medium",children:T})})}),t.jsx(Jt,{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(na,{breakdown:o.score_breakdown})]})})]}):null,se&&t.jsxs(Pn,{children:[t.jsx(Bn,{asChild:!0,children:t.jsx(O,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-1",asChild:!0,children:t.jsxs("a",{href:se.href,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(Qt,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"View original"})]})})}),t.jsx(Un,{children:"View original"})]}),!z&&m]}),_,l&&!(e==="detail"&&y)&&t.jsx(zn,{owner:l,source:Y,connectorDefinitions:d,variant:"chips",className:"mt-2 text-xs",runId:h,onRunSelect:v}),(o.author_name||!l)&&!(e==="detail"&&y)&&t.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:o.author_name||Xr(o)})]}),z&&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:[i,te&&xe]})]}),typeof le=="string"&&t.jsx("p",{className:"mb-2 text-sm whitespace-pre-wrap text-destructive",children:le}),n,!te&&xe,(te||i!=null)&&c===void 0&&!(N&&n!=null)&&t.jsxs("details",{className:"mt-5 border-t pt-3",open:J,onToggle:b=>pe(b.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:[i,te&&xe]})]}),D&&t.jsx(O,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>R(!k),children:k?t.jsxs(t.Fragment,{children:[t.jsx(dt,{className:"h-3 w-3 mr-1"})," Show less"]}):t.jsxs(t.Fragment,{children:[t.jsx(ut,{className:"h-3 w-3 mr-1"})," Show more"]})}),je.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:je.map(b=>t.jsx(sa,{slug:b.slug,value:b.value||"",isManual:b.isManual},b.slug))})]})}function ba(e,n){const s=e.metadata??{},r=Yt(e)?Bt(e,n):null,{KindIcon:a,kindLabel:i}=Ut(e),c=xs(e,n),o=e.interaction_error??(typeof s.error_message=="string"?s.error_message:r?.failed?"Failed":null),l=e.platform||(typeof s.platform=="string"?s.platform:null);return{title:c,kindLabel:i,error:o,KindIcon:a,platform:l}}function _a(e,n){const s=hs(e);return s&&n?n(s):null}function Na({content:e,ownerSlug:n,connectorDefinitions:s,hideOriginator:r=!1,showEntity:a=!1,connectionName:i,callerName:c,extra:o,unread:l=!1,onOpen:d}){const p=Pe(),{title:u,kindLabel:m,error:_,KindIcon:w,platform:h}=ba(e,i),v=e.interaction_status==="pending",N=!!_||e.interaction_status==="failed",k=n?Kt(n,Number(e.id)):null,R=mt(p?.item?.href.split(/[?#]/)[0]??""),A=R!=null&&R.owner===n&&R.eventId===Number(e.id),T=[m,a?e.entity_name:null,e.automation_name,r?null:e.connection_name??e.feed_name,e.agent_name??e.client_name??e.device_label??_a(e,c),o],E=t.jsx(Le,{mark:t.jsx(yt,{source:{...e,platform:h},connectorDefinitions:s,label:m,fallback:t.jsx(w,{className:"h-4 w-4 text-muted-foreground"})}),name:u,badge:l&&!N?t.jsx("span",{className:"sr-only",children:"Unread"}):null,tone:v||l&&!N?"amber":N?"destructive":null,details:t.jsx(Qe,{parts:T}),at:e.occurred_at?new Date(e.occurred_at).getTime():null});if(!k)return t.jsx("div",{className:G(Je,"cursor-default"),children:E});const M=S=>{d?.(),!(!p||S.metaKey||S.ctrlKey||S.shiftKey||S.altKey||S.button!==0)&&(S.preventDefault(),p.open({href:k,title:u}))};return t.jsx(W,{to:k,"aria-current":A?"true":void 0,className:G(Je,A&&"bg-accent"),onClick:M,children:E})}function Oe(e,n,s=`${n}s`){return`${e} ${e===1?n:s}`}function Nt(e){const n=[...new Set(e.apps.map(r=>r.name))];if(n.length>1)return Oe(e.apps.length,"app");const s=n[0]??"Unknown app";return e.apps.length>1?`${s} (${e.apps.length})`:s}function Lt(e){const{oldestAt:n,newestAt:s}=e;if(n==null||s==null)return null;const r=Ns(n,s),a=Se(n,r?"p":"d MMM p"),i=Se(s,r?"p":"d MMM p");return a===i?a:`${a}–${i}`}function cn(e){const n=new Map;for(const s of e.calls)n.set(s.call.title,(n.get(s.call.title)??0)+1);return[...n].map(([s,r])=>({title:s,count:r})).sort((s,r)=>r.count-s.count)}function dn(e){const n=cn(e)[0]?.title??"Ran background checks";return`${Nt(e)} ${n.charAt(0).toLowerCase()}${n.slice(1)}`}function un(e){return cn(e).slice(1).map(n=>`${n.title.charAt(0).toLowerCase()}${n.title.slice(1)} ${n.count}×`)}function wa(e,n){if(e.source)return e.source.name;if(e.kind==="background")return dn(e);if(n.idle)return"Looked around, changed nothing";const{topAction:s}=n;return n.changed[0]??(s?`${s.title}${s.count>1?` · ${s.count}×`:""}`:null)??n.explicitTitles[0]??Nt(e)}function ka(e){return[e.reads>0?Oe(e.reads,"read"):null,e.actions>0?Oe(e.actions,"action"):null].filter(Boolean).join(" · ")}function Ca({summary:e,headline:n}){const s=ka(e),r=e.changed[0]===n?e.changed.slice(1):e.changed;if(r.length===0){const c=e.idle?e.explicitTitles.slice(0,2):[];return t.jsx("span",{className:"block truncate",children:[...c,s].filter(Boolean).join(" · ")})}const a=r.slice(0,2),i=r.length-a.length;return t.jsxs("span",{className:"block truncate text-foreground/80",children:["Changed: ",a.join(" · "),i>0?` · ${i} more`:"",s?t.jsxs("span",{className:"text-muted-foreground",children:[" — ",s]}):null]})}function Aa({stretch:e,ownerSlug:n,connectorDefinitions:s,connectionName:r,sourceConnection:a,showEntity:i=!1},c){const o=Pe();return!o||!n?{open:null,selected:!1}:{selected:o.item?.key===e.key,open:()=>o.open({href:"",key:e.key,title:c,workStretch:{stretch:e,ownerSlug:n,connectorDefinitions:s,connectionName:r,sourceConnection:a,showEntity:i}})}}function Ra(e){if(e.length<2)return null;const n=Math.max(...e)-Math.min(...e),s=Math.round(n/(e.length-1)/1e3);return s<1?null:s<90?`every ${s}s`:`every ${Math.round(s/60)} min`}function Sa(e){const n=new Map;for(const s of e.calls){const r=_s(s.content),a=n.get(r.key)??{name:r.name,titles:new Map,ats:[]};a.titles.set(s.call.title,(a.titles.get(s.call.title)??0)+1),s.at!=null&&a.ats.push(s.at),n.set(r.key,a)}return[...n].map(([s,{name:r,titles:a,ats:i}])=>({key:s,name:r,checks:[...a].sort((c,o)=>o[1]-c[1]).map(([c,o])=>`${c} · ${o}×`),every:Ra(i),lastAt:i.length>0?Math.max(...i):null}))}function $a({stretch:e}){const n=dn(e),s=un(e),r=[`${n} · ${e.calls.length}×`,e.oldestAt!=null?`since ${Se(e.oldestAt,"p")}`:null,...s].filter(Boolean).join(" · ");return t.jsxs(Ht,{children:[t.jsx(Wt,{asChild:!0,children:t.jsxs("button",{type:"button",className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1 text-left text-xs text-muted-foreground hover:bg-accent/50 data-[state=open]:bg-accent data-[state=open]:text-foreground",children:[t.jsx(Gt,{"aria-hidden":"true",className:"h-3 w-3 shrink-0"}),t.jsx("span",{className:"truncate",children:r})]})}),t.jsxs(Jt,{align:"start",className:"w-80 p-0",children:[t.jsx("p",{className:"border-b border-border px-3 py-2 text-xs text-muted-foreground",children:"Apps checking in today. Background, not work they did."}),t.jsx("ul",{className:"divide-y divide-border",children:Sa(e).map(a=>t.jsxs("li",{className:"px-3 py-2",children:[t.jsx("div",{className:"text-sm font-medium",children:a.name}),t.jsx("div",{className:"text-xs text-muted-foreground",children:[...a.checks,a.every,a.lastAt!=null?`last checked ${gs(a.lastAt,{addSuffix:!0})}`:null].filter(Boolean).join(" · ")})]},a.key))})]})]})}function Ia({hideOriginator:e=!1,...n}){const{stretch:s,connectorDefinitions:r,sourceConnection:a}=n,i=j.useMemo(()=>ys(s),[s]),c=wa(s,i),{open:o,selected:l}=Aa(n,c),d=s.kind==="background",{source:p}=s,u=i.failedCalls.length+i.failedOperations.length+s.flagged.length,m=!u&&!p&&(d||i.idle),_=d?Gt:i.idle&&!p?js:vs,w=p?[Lt(s),Oe(s.items.length,"item"),u>0?`${u} failed`:null]:d?[s.oldestAt!=null?`since ${Se(s.oldestAt,"p")}`:null,...un(s)]:[e?null:Nt(s),Oe(s.calls.length,"call"),Lt(s),u>0?`${u} failed`:null],h=t.jsx(Le,{mark:p?t.jsx(yt,{source:{platform:a?.(p.connectionId)?.connectorKey??s.items[0]?.group.root?.platform??null},connectorDefinitions:r,label:p.name,fallback:t.jsx(_,{className:"h-4 w-4 text-muted-foreground"})}):t.jsx(_,{className:"h-4 w-4 text-muted-foreground"}),name:c,badge:d?t.jsxs("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:[s.calls.length,"×"]}):null,tone:u>0?"destructive":null,details:t.jsxs(t.Fragment,{children:[p?t.jsx("span",{className:"block truncate text-foreground/80",children:bs(s).map(N=>N.label).join(" · ")}):d?null:t.jsx(Ca,{summary:i,headline:c}),t.jsx("span",{className:"block truncate",children:w.filter(Boolean).join(" · ")})]}),at:s.newestAt}),v=G(Je,m&&"opacity-60");return o?t.jsx("button",{type:"button","aria-current":l?"true":void 0,className:G(v,l&&"bg-accent opacity-100"),onClick:o,children:h}):t.jsx("div",{className:G(v,"cursor-default"),children:h})}function Ha({presentation:e="summary",renderDetail:n,hideDetails:s=!1,organizationId:r,ownerSlug:a,entityId:i,filters:c,showEntityLinks:o=!1,hideOriginator:l=!1,emptyState:d,groupStretches:p=!1,foldRunSatellites:u=!0,renderLead:m,hiddenApprovalRunIds:_,unreadNotices:w,onMarkRead:h,extraRows:v,onGoToLatest:N}){const{isAuthenticated:k,isReady:R,session:A}=et(),{isMember:T,isLoading:E}=ws(),M=a==="me",S=!M&&R&&k&&T,D=!M&&R&&(!k||!E&&!T),{data:x=[]}=ks(R&&S?r:null),{data:B=[]}=Cs(D?a:null),V=S?x:B,{data:P}=As(p&&R&&S?r:null),y=j.useMemo(()=>{const f=new Map((P??[]).map(C=>[C.id,C.display_name??C.connector_name]));return C=>f.get(C)??null},[P]),{data:L}=Rs({enabled:R&&S}),F=A?.user?.id??null,Z=j.useCallback(f=>f.kind==="user"?f.userId===F?"You":null:L?.find(C=>C.agentId===f.agentId)?.name??f.agentId,[L,F]),le=j.useMemo(()=>{const f=new Map((P??[]).map(C=>[C.id,C.connector_key]));return C=>{const q=f.get(C);return q&&r?{connectorKey:q,organizationId:r}:null}},[P,r]),J=Ss(R&&S?r:null,i,c,a),pe=$s(D?a:null,i,c),Q=D?pe:J,{data:X,isLoading:ce,error:fe,fetchNextPage:ee,hasNextPage:ne,isFetchingNextPage:je}=Q,Y=j.useMemo(()=>X?.pages.flatMap(f=>f.content)??[],[X]),se=j.useMemo(()=>{const f=Is(Y,{foldRunSatellites:u}),C=f.map(oe=>oe.head),q=new Map(f.map(oe=>[oe.head.id,oe])),ye=Ts(C),Ce=Array.from(ye.entries()).map(([oe,st])=>{const Rt=st.root||st.replies[0],St=Rt?q.get(Rt.id):void 0;return{rootId:oe,group:st,history:St?.history??[],runId:St?.runId??null}});return _?Es(Ce,_):Ce},[Y,u,_]),re=m?se[0]:void 0,ae=re?It(re)??void 0:void 0,ie=ae?se.slice(1):se,de=f=>w?.(f)??[],ue=p&&Ms(c),xe=`${r}:${i}:${JSON.stringify(Ds(c))}:${c.beforeOccurredAt}:${c.beforeId}`,[te,z]=j.useState(null),ve=()=>{let f=Number.NEGATIVE_INFINITY;for(const C of Y){const q=Date.parse(C.occurred_at);q>f&&(f=q)}z({scope:xe,ids:new Set(Y.map(C=>C.id)),newestAt:f})},ke=ue&&Y.length>0&&!Q.isFetching,b=te?.scope!==xe;j.useEffect(()=>{ke&&b&&ve()});const I=j.useRef(null),me=ue?Fs(ie,b?null:te,f=>Os(f,{connectionName:y,groupSources:!Ps(c,i)})):{entries:ie.map(f=>({kind:"single",node:f})),pending:[]},$e=new Date().toDateString(),Ie=f=>f.kind==="stretch"&&f.stretch.kind==="background"&&f.stretch.newestAt!=null&&new Date(f.stretch.newestAt).toDateString()===$e,Te=[...me.entries,...me.pending].find(Ie),tt=me.entries.filter(f=>!Ie(f)),Be=me.pending.filter(f=>!Ie(f)).length,Ee=!M&&(!R||k&&E||S&&Q.isPending);if(fe)return t.jsx(Ls,{label:"events"});const he=e==="detail",g=(f,C,q={})=>{const ye=de(f);return{key:C,occurredAt:f.occurred_at,content:t.jsx(Na,{content:f,ownerSlug:a,connectorDefinitions:V,connectionName:y,callerName:Z,hideOriginator:l,showEntity:o,extra:q.extra,unread:ye.length>0,onOpen:ye.length>0&&h?()=>h(ye):void 0})}},$=f=>{if(f.kind==="stretch"){const{stretch:oe}=f;return[{key:oe.key,occurredAt:oe.newestAt,content:t.jsx(Ia,{stretch:oe,ownerSlug:a,connectorDefinitions:V,connectionName:y,sourceConnection:le,hideOriginator:l,showEntity:o})}]}const{rootId:C,group:q}=f.node,ye=q.root||q.replies[0];if(!ye)return[];const Ce=q.root?q.replies.length:q.replies.length-1;return[g(ye,C,{extra:Ce>0?`${Ce} ${Ce===1?"reply":"replies"}`:null})]},K=f=>{if(f.kind!=="single")return[];const C=It(f.node);return C?[{key:f.node.rootId,occurredAt:C.occurred_at,content:t.jsx(ga,{ownerSlug:a,content:C,renderDetail:n,connectorDefinitions:V,hideDetails:s})}]:[]},ge=tt.flatMap(he?K:$),Me=Y.at(-1)?.occurred_at,wt=(v??[]).filter(f=>!ne||Me==null||(ze(f.occurredAt)??0)>=(ze(Me)??0)),kt=wt.length>0&&(ge.length>0||ae)?[...ge,...wt].sort((f,C)=>(ze(C.occurredAt)??0)-(ze(f.occurredAt)??0)):ge,mn=t.jsx(Ys,{rows:!he,groupByDate:!he,isLoading:ce||Ee,emptyState:ae||Te?.kind==="stretch"?null:d,hasNextPage:!!ne,isFetching:Q.isFetching,isFetchingNextPage:je,onLoadMore:()=>void ee(),items:kt}),pn=Be>0?t.jsx("div",{className:"pointer-events-none sticky top-2 z-10 flex h-0 justify-center overflow-visible",children:t.jsxs(O,{size:"sm",className:"pointer-events-auto h-7 rounded-full px-3 text-xs shadow-md",onClick:()=>{ve(),I.current?.scrollIntoView?.({block:"start",behavior:"smooth"})},children:[Be," new"]})}):null,Ct=Te?.kind==="stretch"?t.jsx($a,{stretch:Te.stretch}):null,nt=c.beforeOccurredAt?Ta(c.beforeOccurredAt):null,fn=Ct||nt||N?t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:Ct}),nt?t.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:["From ",nt]}):null,N&&t.jsxs(O,{variant:"ghost",size:"sm",className:"h-7 shrink-0 gap-1.5 px-2 text-xs font-normal text-muted-foreground",onClick:N,children:[t.jsx(Bs,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Back to latest"]})]}):null,At=t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:I,className:"scroll-mt-4"}),pn,fn,mn]});return!ae||!m?At:t.jsxs(t.Fragment,{children:[m(ae,{hasEarlier:kt.length>0||!!ne}),At]})}function Ta(e){const n=new Date(e);return Number.isNaN(n.getTime())?null:Gs(n)?Se(n,"p"):Se(n,Zs(n)?"d MMM, p":"d MMM yyyy, p")}export{Ha as E,Va as R,va as a,qa as b,za as c,Ir as d,Nt as e,Na as f,Oe as p,Ka as r,Lt as s};
2
+ //# sourceMappingURL=events-feed-DwOkLk6A.js.map
@@ -0,0 +1,2 @@
1
+ import{r as f,j as e,e3 as C,e4 as S,e5 as w,e6 as B,i as b,B as g,e7 as F,k as I,e8 as D,e9 as E,ea as L,eb as $,dp as R,dq as M,a4 as T,X as _,a6 as Q,dO as v,ec as U,ed as N,ee as p,U as y,ef as q}from"./index-C2TCKJDP.js";import{s as k}from"./subDays-DwIOMzYC.js";function O(s){return s&&s.kind!=="toggle"?s:void 0}const P="w-72";function z({editor:s,close:t,header:r,footer:i}){const[u,a]=f.useState("");return e.jsxs(e.Fragment,{children:[r,s.kind==="list"?e.jsxs(D,{shouldFilter:!s.onQueryChange,children:[e.jsx(E,{autoFocus:!0,placeholder:s.searchPlaceholder,value:u,onValueChange:d=>{a(d),s.onQueryChange?.(d)}}),e.jsxs(L,{children:[e.jsx($,{children:s.emptyText}),e.jsx(R,{children:s.items(t,u)})]})]}):s.render(t),i]})}function H({chip:s,editor:t}){const[r,i]=f.useState(!1),u=s.onRemove!=null,a=s.value?s.op?[s.label,s.op,s.value].join(" "):`${s.label}: ${s.value}`:s.label,d=s.value?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:s.op?s.label:`${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})]}):e.jsx("span",{className:"min-w-0 truncate font-medium",children:s.label}),l=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:r,onOpenChange:i,children:[e.jsxs("div",{"data-filter-chip":s.id,title:s.title,className:b("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":u?"bg-muted":"border-dashed bg-transparent",r&&"ring-1 ring-ring",!u&&"pr-1.5"),children:[l,u?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(_,{className:"h-3.5 w-3.5"})}):null]}),t?e.jsx(F,{align:"start",className:b("p-0",P,t.className),children:e.jsx(z,{editor:t,close:()=>i(!1),footer:u?e.jsx("div",{className:"border-t p-1",children:e.jsx(g,{variant:"ghost",size:"sm",className:"w-full justify-start text-destructive hover:text-destructive",onClick:()=>{i(!1),s.onRemove?.()},children:"Remove filter"})}):null})}):null]})}function V({fields:s,triggerClassName:t}){const r=s.filter(o=>o.inMenu!==!1),[i,u]=f.useState(!1),[a,d]=f.useState(),l=r.find(o=>o.key===a),c=O(l?.editor),x=r.filter(o=>o.editor.kind==="toggle"&&o.editor.checked).length,m=[...new Set(r.map(o=>o.group??""))],h=()=>{u(!1),d(void 0)};return e.jsxs(C,{open:i,onOpenChange:o=>{u(o),o||d(void 0)},children:[e.jsx(S,{asChild:!0,children:t?e.jsxs("button",{type:"button",className:b("flex shrink-0 items-center gap-1.5 px-2.5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",t),children:[e.jsx(w,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Filter",x>0?e.jsx("span",{className:"tabular-nums text-foreground",children:x}):null,e.jsx(B,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]}):e.jsxs(g,{variant:"outline",size:"sm",className:"h-8 gap-1.5 font-normal text-muted-foreground",children:[e.jsx(w,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(F,{align:t?"end":"start",className:b("p-0",P,c?.className),children:l&&c?e.jsx(z,{editor:c,close:h,header:e.jsxs("div",{className:"flex items-center gap-1 border-b px-1 py-1 text-sm font-medium",children:[e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Back to filters",onClick:()=>d(void 0),children:e.jsx(I,{className:"h-4 w-4"})}),l.label]})},l.key):e.jsxs(D,{children:[e.jsx(E,{autoFocus:!0,placeholder:"Filter by…"}),e.jsxs(L,{children:[e.jsx($,{children:"No matching filter"}),m.map(o=>e.jsx(R,{heading:o||void 0,children:r.filter(n=>(n.group??"")===o).map(n=>e.jsxs(M,{value:`${n.label} ${n.key}`,onSelect:()=>n.editor.kind==="toggle"?n.editor.onToggle():d(n.key),"aria-checked":n.editor.kind==="toggle"?n.editor.checked:void 0,className:"gap-2",children:[n.icon?e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground",children:n.icon}):null,e.jsx("span",{className:"min-w-0 flex-1 truncate",children:n.label}),n.editor.kind==="toggle"?e.jsxs(e.Fragment,{children:[n.editor.count!=null?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:n.editor.count.toLocaleString()}):null,e.jsx(T,{"aria-hidden":"true",className:b("h-4 w-4 shrink-0",!n.editor.checked&&"invisible")})]}):null]},n.key))},o))]})]})})]})}function Z({fields:s,chips:t,meta:r,actions:i,trailing:u,onClearAll:a,hasClearableState:d=!1,className:l,label:c="Filters",menu:x=!0,clearAllMin:m=1}){const h=s.filter(n=>n.inMenu!==!1),o=t.filter(n=>n.onRemove).length;return e.jsxs("div",{role:"search","aria-label":c,className:b("flex min-w-0 flex-wrap items-center gap-2",l),children:[t.map(n=>e.jsx(H,{chip:n,editor:O(n.editor??s.find(j=>j.key===(n.field??n.id))?.editor)},n.id)),x&&h.length>0?e.jsx(V,{fields:h}):null,i,e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[r?e.jsx("span",{className:"text-sm text-muted-foreground",children:r}):null,a&&o+(d?1:0)>=m?e.jsx(g,{variant:"ghost",size:"sm",className:"h-8 text-muted-foreground",onClick:a,children:"Clear all"}):null,u]})]})}function A({selected:s}){return e.jsx(T,{className:b("h-4 w-4 shrink-0",s?"opacity-100":"opacity-0")})}function ee({searchPlaceholder:s,emptyText:t="No options",options:r,selected:i,multiple:u=!1,onSelect:a}){return{kind:"list",searchPlaceholder:s,emptyText:t,items:d=>r.map(l=>{const c=i.includes(l.value);return e.jsxs(M,{value:`${l.label} ${l.keywords??l.value}`,onSelect:()=>{a(l.value),u||d()},"aria-label":l.label,className:"group gap-2",children:[u?e.jsx(Q,{checked:c,className:"mr-1"}):e.jsx(A,{selected:c}),l.icon,e.jsx("span",{className:"min-w-0 flex-1 truncate",children:l.label}),l.count!=null?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:l.count.toLocaleString()}):null,l.action]},l.value)})}}function se([s,t],r,i){return s<=r?`≤ ${t}`:t>=i?`≥ ${s}`:`${s}–${t}`}function G({value:s,min:t,max:r,onApply:i,close:u}){const[a,d]=f.useState(String(s?.[0]??t)),[l,c]=f.useState(String(s?.[1]??r)),[x,m]=f.useState(),h=o=>{o.preventDefault();const n=Number(a),j=Number(l);if(!Number.isFinite(n)||!Number.isFinite(j)){m("Enter a number.");return}if(n<t||j>r){m(`Use values between ${t} and ${r}.`);return}if(n>j){m("The lower bound must not exceed the upper bound.");return}i([n,j]),u()};return e.jsxs("form",{className:"space-y-3 p-3",onSubmit:h,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:r,value:a,onChange:o=>d(o.target.value)}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"to"}),e.jsx(y,{"aria-label":"To",type:"number",min:t,max:r,value:l,onChange:o=>c(o.target.value)})]}),x?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x}):null,e.jsx(g,{type:"submit",size:"sm",className:"w-full",children:"Apply"})]})}function te(s){return{kind:"custom",render:t=>e.jsx(G,{...s,close:t})}}const W=[{label:"Today",range:()=>[N(new Date),p(new Date)]},{label:"Last 7 days",range:()=>[N(k(new Date,6)),p(new Date)]},{label:"Last 30 days",range:()=>[N(k(new Date,29)),p(new Date)]},{label:"This month",range:()=>[q(new Date),p(new Date)]}];function ne([s,t]){return v(s,"yyyy-MM-dd")===v(t,"yyyy-MM-dd")?v(s,"LLL d, y"):`${v(s,"LLL d")} – ${v(t,"LLL d, y")}`}function X({value:s,onApply:t,close:r}){const[i,u]=f.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(g,{variant:"ghost",size:"sm",className:"justify-start font-normal",onClick:()=>{t(a.range()),r()},children:a.label},a.label))}),e.jsx(U,{mode:"range",defaultMonth:i?.from,selected:i,onSelect:a=>{u(a),a?.from&&a.to&&a.from!==a.to&&(t([N(a.from),p(a.to)]),r())},numberOfMonths:1})]})}function ae(s){return{kind:"custom",className:"w-auto",render:t=>e.jsx(X,{...s,close:t})}}function J({type:s,label:t,value:r,onApply:i,close:u}){const[a,d]=f.useState(r==null?"":String(r)),[l,c]=f.useState(),x=m=>{if(m.preventDefault(),s==="number"){const h=Number(a);if(a.trim()===""||!Number.isFinite(h)){c("Enter a number.");return}i(h)}else i(a);u()};return e.jsxs("form",{className:"space-y-3 p-3",onSubmit:x,children:[e.jsx(y,{autoFocus:!0,"aria-label":t,type:s,step:s==="number"?"any":void 0,value:a,onChange:m=>d(m.target.value),placeholder:"Enter a value…"}),l?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:l}):null,e.jsx(g,{type:"submit",size:"sm",className:"w-full",children:"Apply"})]})}function re(s){return{kind:"custom",render:t=>e.jsx(J,{...s,close:t})}}export{V as F,A as S,Z as a,se as b,ae as d,ne as f,ee as o,te as r,re as v};
2
+ //# sourceMappingURL=filter-editors-DQ5V4Cvh.js.map
@@ -1,2 +1,2 @@
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
1
+ import{r,j as t,i as u}from"./index-C2TCKJDP.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-B7A6Ycyi.js.map