@lobu/runtime-server 24.11.0 → 24.12.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 (275) hide show
  1. package/dist/catalogs/connectors.json +1113 -107
  2. package/dist/catalogs/skills.json +2 -2
  3. package/dist/component.json +1 -1
  4. package/dist/connectors/README.md +2 -2
  5. package/dist/connectors/chat-transport-actions.ts +50 -0
  6. package/dist/connectors/discord.ts +2 -0
  7. package/dist/connectors/gchat.ts +2 -0
  8. package/dist/connectors/github.ts +4 -4
  9. package/dist/connectors/google_drive.ts +20 -0
  10. package/dist/connectors/google_gmail.ts +49 -8
  11. package/dist/connectors/herdr.ts +1 -1
  12. package/dist/connectors/imessage.ts +1 -0
  13. package/dist/connectors/linkedin-browser-script.ts +11 -0
  14. package/dist/connectors/linkedin-draft-page.js +24 -8
  15. package/dist/connectors/linkedin-inbox-adapter.js +209 -19
  16. package/dist/connectors/linkedin-inbox.ts +152 -4
  17. package/dist/connectors/linkedin-network.ts +788 -0
  18. package/dist/connectors/linkedin-search.ts +1284 -0
  19. package/dist/connectors/linkedin.ts +892 -27
  20. package/dist/connectors/microsoft_outlook.ts +57 -19
  21. package/dist/connectors/rss.ts +179 -33
  22. package/dist/connectors/slack.ts +2 -0
  23. package/dist/connectors/source-file-attachment.ts +46 -0
  24. package/dist/connectors/teams.ts +2 -0
  25. package/dist/connectors/telegram.ts +2 -0
  26. package/dist/connectors/tiktok_web.ts +1 -1
  27. package/dist/connectors/whatsapp.ts +2 -0
  28. package/dist/connectors/whatsapp_web.ts +3 -3
  29. package/dist/connectors/x-dm-adapter.js +8 -10
  30. package/dist/connectors/x.ts +8 -9
  31. package/dist/db/migrations/20261115040000_account_two_factor.sql +20 -0
  32. package/dist/db/migrations/20261115120000_events_unbound_tool_audit_without_bridge.sql +40 -0
  33. package/dist/db/migrations/20261115120001_events_unbound_tool_audit_validate.sql +19 -0
  34. package/dist/db/migrations/20261115120002_drop_events_linked_org_ids.sql +119 -0
  35. package/dist/db/migrations/20261115130000_entities_retired_type_idx.sql +34 -0
  36. package/dist/db/migrations/20261115140000_entity_identities_personal_owner_idx.sql +34 -0
  37. package/dist/db/migrations/20261117090000_write_policy_kind_note.sql +65 -0
  38. package/dist/db/migrations/20261117120000_app_policy_principal.sql +48 -0
  39. package/dist/db/migrations/20261117170000_personal_org_connector_auto_policy_backfill.sql +57 -0
  40. package/dist/db/migrations/20261117190000_org_slug_reserved_paths.sql +29 -0
  41. package/dist/db/migrations/20261118120000_workspace_view_top_level_paths.sql +69 -0
  42. package/dist/db/migrations/preconditions/20261117190000_org_slug_reserved_paths.sql +14 -0
  43. package/dist/db/migrations/preconditions/20261118120000_workspace_view_top_level_paths.sql +21 -0
  44. package/dist/dependencies.bun.lock +51 -46
  45. package/dist/guest.bundle.js +11 -2
  46. package/dist/owletto/dist/assets/_-BC9j6MkU.js +2 -0
  47. package/dist/owletto/dist/assets/_-Z1u1cIe6.js +3 -0
  48. package/dist/owletto/dist/assets/_agentId-B-TFq9TP.js +2 -0
  49. package/dist/owletto/dist/assets/{_agentId-CGScf8z_.js → _agentId-BGatZWsd.js} +2 -2
  50. package/dist/owletto/dist/assets/_automationId-CMUrWPvr.js +2 -0
  51. package/dist/owletto/dist/assets/_connectorKey._connectionId-CUoAoP0_.js +2 -0
  52. package/dist/owletto/dist/assets/_connectorKey.index-Bs49QGGH.js +2 -0
  53. package/dist/owletto/dist/assets/_conversationId-CszP1den.js +2 -0
  54. package/dist/owletto/dist/assets/_eventId-C0AZUBnD.js +2 -0
  55. package/dist/owletto/dist/assets/_owner-B4ydA75k.js +3 -0
  56. package/dist/owletto/dist/assets/_shape-C4-ikE70.js +2 -0
  57. package/dist/owletto/dist/assets/_slug-DE5J3KVu.js +2 -0
  58. package/dist/owletto/dist/assets/_viewKey-Dkcd8JQC.js +2 -0
  59. package/dist/owletto/dist/assets/{accept-invitation-BKeIzZXE.js → accept-invitation-DmrQQu_W.js} +2 -2
  60. package/dist/owletto/dist/assets/{activity-route-location-sLvKaSCa.js → activity-route-location-Bec6fW-t.js} +2 -2
  61. package/dist/owletto/dist/assets/activity-route-view-DCSNBKZU.js +2 -0
  62. package/dist/owletto/dist/assets/agent-client-connections-xvabPpi6.js +4 -0
  63. package/dist/owletto/dist/assets/agent-connect-pages-DDPtkcmq.js +6 -0
  64. package/dist/owletto/dist/assets/{agent-editor-form-DVFyyMyd.js → agent-editor-form-BrhQbHZg.js} +2 -2
  65. package/dist/owletto/dist/assets/{agent-loading-shells-BLNHIy-r.js → agent-loading-shells-D3y98xuO.js} +2 -2
  66. package/dist/owletto/dist/assets/{agent-permissions-matrix-UBKRR5vs.js → agent-permissions-matrix-jQJjSa9i.js} +2 -2
  67. package/dist/owletto/dist/assets/{agent-skill-context-fqedKd0D.js → agent-skill-context-CCcknBYE.js} +2 -2
  68. package/dist/owletto/dist/assets/{agent-subpage-shell-BUCoY2Nf.js → agent-subpage-shell-6f_53cSf.js} +2 -2
  69. package/dist/owletto/dist/assets/agent-thread-v_lSSnJi.js +6 -0
  70. package/dist/owletto/dist/assets/{app._appId-ByIypCL9.js → app._appId-CKWzZ2ic.js} +2 -2
  71. package/dist/owletto/dist/assets/assist-composer-Q9ZJjAta.js +2 -0
  72. package/dist/owletto/dist/assets/automation-run-now-Dl0MKx3N.js +2 -0
  73. package/dist/owletto/dist/assets/{callback-Pz5uS-k7.js → callback-Bentv78L.js} +2 -2
  74. package/dist/owletto/dist/assets/{card-CAPpY9P5.js → card-C4oPCVh6.js} +2 -2
  75. package/dist/owletto/dist/assets/{claim-DgWWK0KI.js → claim-B3C4qIi2.js} +2 -2
  76. package/dist/owletto/dist/assets/client-activity-scopes-DqaFEyir.js +2 -0
  77. package/dist/owletto/dist/assets/{client-rows-Dd5YV8vn.js → client-rows-rse9thnk.js} +2 -2
  78. package/dist/owletto/dist/assets/{clients-Bf7ZgGro.js → clients-BhPMbxHi.js} +2 -2
  79. package/dist/owletto/dist/assets/{code-editor-z1Sy_hiX.js → code-editor-CTdKUDPY.js} +2 -2
  80. package/dist/owletto/dist/assets/connect-D8o7HBlo.js +2 -0
  81. package/dist/owletto/dist/assets/connect-menu-D5EZvSHb.js +2 -0
  82. package/dist/owletto/dist/assets/connect._clientId-Dbagcg9L.js +2 -0
  83. package/dist/owletto/dist/assets/connected._clientId-DALW9S2K.js +2 -0
  84. package/dist/owletto/dist/assets/connection-DyxzSqVE.js +2 -0
  85. package/dist/owletto/dist/assets/connection-feed-detail-LqpxUCdy.js +2 -0
  86. package/dist/owletto/dist/assets/{connector-page-shell-an3SYLim.js → connector-page-shell-DZjKv9zQ.js} +2 -2
  87. package/dist/owletto/dist/assets/{connector-provenance-mSZCOud-.js → connector-provenance-DtTJn1Nk.js} +2 -2
  88. package/dist/owletto/dist/assets/connectors-BVl-AR33.js +2 -0
  89. package/dist/owletto/dist/assets/{consent-1ulwyJ3k.js → consent-XCqsHLxS.js} +2 -2
  90. package/dist/owletto/dist/assets/{core.esm-Ctg_pXLe.js → core.esm-B1du4Zwy.js} +3 -3
  91. package/dist/owletto/dist/assets/create-BYKCtGL4.js +2 -0
  92. package/dist/owletto/dist/assets/create-D6Mmuxcq.js +2 -0
  93. package/dist/owletto/dist/assets/{create-CGuoqPh8.js → create-GHTb6wKX.js} +2 -2
  94. package/dist/owletto/dist/assets/{create-automation-form-CD6jSlWL.js → create-automation-form-CTiy_S9G.js} +3 -3
  95. package/dist/owletto/dist/assets/create._connectorKey-DMH97KkK.js +2 -0
  96. package/dist/owletto/dist/assets/custom-guardrail-edits-DZy66ucV.js +2 -0
  97. package/dist/owletto/dist/assets/definition-comparison-C2mPfIMD.js +2 -0
  98. package/dist/owletto/dist/assets/detail-page-skeleton-DNBL7nyk.js +2 -0
  99. package/dist/owletto/dist/assets/device-CwP1PY8q.js +2 -0
  100. package/dist/owletto/dist/assets/{device-pin-tombstone-Dkj7hrBE.js → device-pin-tombstone-DYTt7kU5.js} +2 -2
  101. package/dist/owletto/dist/assets/device._deviceId-DZ2kqI4Y.js +2 -0
  102. package/dist/owletto/dist/assets/{entity-options-D4t-NAcg.js → entity-options-D9K_5Lcs.js} +2 -2
  103. package/dist/owletto/dist/assets/entity-page-DggKXrcE.js +2 -0
  104. package/dist/owletto/dist/assets/entity-pages-C6M6yKFf.js +2 -0
  105. package/dist/owletto/dist/assets/{entity-schema-graph-Cq96SJ3c.js → entity-schema-graph-B255NKjF.js} +2 -2
  106. package/dist/owletto/dist/assets/entity-type-page-CGBAP2wt.js +2 -0
  107. package/dist/owletto/dist/assets/event-attachments-D8Z8uwv9.js +2 -0
  108. package/dist/owletto/dist/assets/event-detail-CgG3pDLA.js +2 -0
  109. package/dist/owletto/dist/assets/events-feed-ClhEywwV.js +2 -0
  110. package/dist/owletto/dist/assets/{filter-editors-DGVl9U4D.js → filter-editors-D_Sfn0dv.js} +3 -3
  111. package/dist/owletto/dist/assets/{full-page-spinner-CtVlF8GQ.js → full-page-spinner-C1clibUY.js} +2 -2
  112. package/dist/owletto/dist/assets/{index-CK5GDX4B.js → index-04B26s6E.js} +2 -2
  113. package/dist/owletto/dist/assets/index-2HrEO-nl.js +2 -0
  114. package/dist/owletto/dist/assets/index-BU3k9wpw.js +2 -0
  115. package/dist/owletto/dist/assets/{index-DvuJ_S_o.js → index-BXHqp23o.js} +2 -2
  116. package/dist/owletto/dist/assets/index-BdLRUDIR.js +2 -0
  117. package/dist/owletto/dist/assets/index-C2FrGwYN.js +2 -0
  118. package/dist/owletto/dist/assets/index-CB9wGfUm.js +2 -0
  119. package/dist/owletto/dist/assets/index-Caihaftb.js +2 -0
  120. package/dist/owletto/dist/assets/index-CwH59DJV.js +2 -0
  121. package/dist/owletto/dist/assets/index-DB2lVKuV.js +7908 -0
  122. package/dist/owletto/dist/assets/{index-DbjbHlDe.js → index-DTvJRjrM.js} +2 -2
  123. package/dist/owletto/dist/assets/index-SF2ni1Rs.css +1 -0
  124. package/dist/owletto/dist/assets/{index-BifR-LE9.js → index-mSrdbx3C.js} +9 -9
  125. package/dist/owletto/dist/assets/index-uFn-Ilrx.js +2 -0
  126. package/dist/owletto/dist/assets/{json-diff-OjtREegr.js → json-diff-Ce6YAXzY.js} +2 -2
  127. package/dist/owletto/dist/assets/{list-skeleton-CH0qQBYk.js → list-skeleton-DLPBTnbR.js} +2 -2
  128. package/dist/owletto/dist/assets/login-DeWlvogD.js +2 -0
  129. package/dist/owletto/dist/assets/{logout-DfdgOLoM.js → logout-CJY0ceN9.js} +2 -2
  130. package/dist/owletto/dist/assets/{member-scope-gate-Cxg2zGQT.js → member-scope-gate-CBPMprXu.js} +2 -2
  131. package/dist/owletto/dist/assets/memory-browse-page-D5kj1RaR.js +74 -0
  132. package/dist/owletto/dist/assets/{model-selector-D2OpDkwH.js → model-selector-CjkBPpjN.js} +2 -2
  133. package/dist/owletto/dist/assets/new-BKrNkOQD.js +2 -0
  134. package/dist/owletto/dist/assets/new-BetiMuDq.js +2 -0
  135. package/dist/owletto/dist/assets/new-dk_-eXqU.js +2 -0
  136. package/dist/owletto/dist/assets/new-efN--4Wx.js +2 -0
  137. package/dist/owletto/dist/assets/organization-C3rpwx_d.js +2 -0
  138. package/dist/owletto/dist/assets/pdf-document--AN-oCKj.css +1 -0
  139. package/dist/owletto/dist/assets/pdf-document-2W1q0sRA.js +56 -0
  140. package/dist/owletto/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
  141. package/dist/owletto/dist/assets/peek-pane-content-ChsBWO0P.js +3 -0
  142. package/dist/owletto/dist/assets/{pending-seed-BBACroge.js → pending-seed-CTKYdA4X.js} +2 -2
  143. package/dist/owletto/dist/assets/proposal-review-shell-EyGWEYwQ.js +2 -0
  144. package/dist/owletto/dist/assets/public-shell-ready-_KWdfzEM.js +2 -0
  145. package/dist/owletto/dist/assets/record-session-D27VNxP_.js +2 -0
  146. package/dist/owletto/dist/assets/{renderer-CTKNMcXP.js → renderer-B8yZ5lql.js} +34 -33
  147. package/dist/owletto/dist/assets/{reset-password-DKBEneyR.js → reset-password-BGVJIh2I.js} +2 -2
  148. package/dist/owletto/dist/assets/run-initiator-C0sur8lU.js +2 -0
  149. package/dist/owletto/dist/assets/runs-list-CJOFMgpk.js +2 -0
  150. package/dist/owletto/dist/assets/schema-value-DDNHANGs.js +3 -0
  151. package/dist/owletto/dist/assets/{scoped-feed-bar-DNFL0sYX.js → scoped-feed-bar-BTv9mPcR.js} +2 -2
  152. package/dist/owletto/dist/assets/settings-Ponr5XbS.js +3 -0
  153. package/dist/owletto/dist/assets/{status-variants-SzXYYedJ.js → status-variants-mLqVhg5O.js} +2 -2
  154. package/dist/owletto/dist/assets/subDays-BGA_fkig.js +2 -0
  155. package/dist/owletto/dist/assets/two-factor-pqoxGSgL.js +2 -0
  156. package/dist/owletto/dist/assets/{use-automations-DfBtVzGa.js → use-automations-DcdlmVuX.js} +2 -2
  157. package/dist/owletto/dist/assets/{use-login-redirect-BDiS3eyl.js → use-login-redirect-D7HW5Ed6.js} +2 -2
  158. package/dist/owletto/dist/assets/{use-mention-search-khySpz_V.js → use-mention-search-BniE-K2d.js} +3 -3
  159. package/dist/owletto/dist/assets/view-card-Cg6PeEiV.js +2 -0
  160. package/dist/owletto/dist/assets/view-param-filters-CvrKw0mZ.js +2 -0
  161. package/dist/owletto/dist/index.html +2 -2
  162. package/dist/server-main.bundle.mjs +5766 -2999
  163. package/npm-shrinkwrap.json +195 -172
  164. package/package.json +2 -1
  165. package/vendor/connector-sdk/dist/connector-types.d.ts +20 -0
  166. package/vendor/connector-sdk/dist/define-connector.js +2 -0
  167. package/vendor/connector-sdk/dist/extension-dom-scrape.d.ts +2 -0
  168. package/vendor/connector-sdk/dist/extension-dom-scrape.js +5 -0
  169. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +20 -0
  170. package/vendor/connector-sdk/package.json +1 -1
  171. package/vendor/core/dist/contracts/entity-reference.d.ts +2 -0
  172. package/vendor/core/dist/contracts/entity-reference.js +4 -3
  173. package/vendor/core/dist/contracts/tools/entity-list-sort.d.ts +18 -0
  174. package/vendor/core/dist/contracts/tools/entity-list-sort.js +64 -0
  175. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +1 -1
  176. package/vendor/core/dist/contracts/tools/manage-agents.js +3 -3
  177. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +4 -0
  178. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +4 -0
  179. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +4 -0
  180. package/vendor/core/dist/contracts/tools/manage-entity.js +11 -1
  181. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +29 -3
  182. package/vendor/core/dist/contracts/tools/manage-operations.js +24 -2
  183. package/vendor/core/dist/contracts/tools/manage-views.d.ts +36 -0
  184. package/vendor/core/dist/contracts/tools/manage-views.js +15 -2
  185. package/vendor/core/dist/contracts/tools/view-definition.js +7 -2
  186. package/vendor/core/dist/contracts/tools/view-host.js +5 -0
  187. package/vendor/core/dist/contracts/tools/view-path.d.ts +8 -1
  188. package/vendor/core/dist/contracts/tools/view-path.js +11 -1
  189. package/vendor/core/dist/reserved.d.ts +7 -1
  190. package/vendor/core/dist/reserved.js +17 -0
  191. package/vendor/core/package.json +6 -1
  192. package/vendor/views/dist/api.d.ts +19 -3
  193. package/vendor/views/dist/api.js +53 -5
  194. package/vendor/views/dist/components.d.ts +7 -0
  195. package/vendor/views/dist/components.js +223 -2
  196. package/vendor/views/dist/embed.js +13 -2
  197. package/vendor/views/dist/live-gate.d.ts +34 -0
  198. package/vendor/views/dist/live-gate.js +100 -0
  199. package/vendor/views/dist/native.d.ts +43 -1
  200. package/vendor/views/dist/native.js +1 -0
  201. package/vendor/views/package.json +1 -1
  202. package/dist/owletto/dist/assets/_-BDMUN9XZ.js +0 -2
  203. package/dist/owletto/dist/assets/_-CF5X4ANe.js +0 -3
  204. package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +0 -2
  205. package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +0 -2
  206. package/dist/owletto/dist/assets/_connectorKey._connectionId-DcI29kGy.js +0 -2
  207. package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +0 -2
  208. package/dist/owletto/dist/assets/_conversationId-CnmLYlVS.js +0 -2
  209. package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +0 -2
  210. package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +0 -3
  211. package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +0 -2
  212. package/dist/owletto/dist/assets/_slug-COPpRXLt.js +0 -2
  213. package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +0 -2
  214. package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +0 -2
  215. package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +0 -2
  216. package/dist/owletto/dist/assets/agent-connect-pages-DVq9nAR7.js +0 -4
  217. package/dist/owletto/dist/assets/agent-thread-Cqf9ITrT.js +0 -6
  218. package/dist/owletto/dist/assets/assist-composer-kG_heHXo.js +0 -2
  219. package/dist/owletto/dist/assets/automation-run-now-C5XTS00o.js +0 -2
  220. package/dist/owletto/dist/assets/client-activity-scopes-Aqdo6Pdr.js +0 -2
  221. package/dist/owletto/dist/assets/connect-BFNp1y_s.js +0 -2
  222. package/dist/owletto/dist/assets/connect-menu-BWrAhMqO.js +0 -2
  223. package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +0 -2
  224. package/dist/owletto/dist/assets/connected._clientId-CuOeHafK.js +0 -2
  225. package/dist/owletto/dist/assets/connection-CVeHmDLs.js +0 -2
  226. package/dist/owletto/dist/assets/connection-feed-detail-BYo7zdVD.js +0 -2
  227. package/dist/owletto/dist/assets/connectors-DBEM9QQz.js +0 -2
  228. package/dist/owletto/dist/assets/copy-button-Xhh7ZnjO.js +0 -2
  229. package/dist/owletto/dist/assets/create-Ccb5R-S4.js +0 -2
  230. package/dist/owletto/dist/assets/create-DmhbacIa.js +0 -2
  231. package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +0 -2
  232. package/dist/owletto/dist/assets/custom-guardrail-edits-Ce_BwiwD.js +0 -2
  233. package/dist/owletto/dist/assets/definition-comparison-D_qP25jR.js +0 -2
  234. package/dist/owletto/dist/assets/detail-page-skeleton-CPAfZLG0.js +0 -2
  235. package/dist/owletto/dist/assets/device-DDl5XKvt.js +0 -2
  236. package/dist/owletto/dist/assets/device._deviceId-bNhTcops.js +0 -2
  237. package/dist/owletto/dist/assets/dynamic-schema-form-CRyUchXo.js +0 -2
  238. package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +0 -2
  239. package/dist/owletto/dist/assets/entity-pages-_nuesgnp.js +0 -2
  240. package/dist/owletto/dist/assets/entity-type-page-CkCSbkBx.js +0 -2
  241. package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +0 -2
  242. package/dist/owletto/dist/assets/events-feed-DcKTkJVe.js +0 -2
  243. package/dist/owletto/dist/assets/index-BUlkNJzX.js +0 -2
  244. package/dist/owletto/dist/assets/index-BoqrvLHQ.js +0 -7906
  245. package/dist/owletto/dist/assets/index-CA9mW_ZM.js +0 -2
  246. package/dist/owletto/dist/assets/index-CH0GzG4i.js +0 -2
  247. package/dist/owletto/dist/assets/index-CtI5Eomq.js +0 -2
  248. package/dist/owletto/dist/assets/index-DmtQ0bds.js +0 -2
  249. package/dist/owletto/dist/assets/index-Du_J8hnx.js +0 -2
  250. package/dist/owletto/dist/assets/index-Pae_f9LM.css +0 -1
  251. package/dist/owletto/dist/assets/index-XETZnN7L.js +0 -2
  252. package/dist/owletto/dist/assets/login-DG0b9uSC.js +0 -2
  253. package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +0 -74
  254. package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +0 -2
  255. package/dist/owletto/dist/assets/needs-you-list-3uMsWcDv.js +0 -2
  256. package/dist/owletto/dist/assets/new-AdGV6a8R.js +0 -2
  257. package/dist/owletto/dist/assets/new-BdtIhBpo.js +0 -2
  258. package/dist/owletto/dist/assets/new-BjGwX6s6.js +0 -2
  259. package/dist/owletto/dist/assets/new-D-iMjV74.js +0 -2
  260. package/dist/owletto/dist/assets/organization-qaIpEiQg.js +0 -2
  261. package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +0 -2
  262. package/dist/owletto/dist/assets/proposal-review-shell-C8ZfIAYn.js +0 -2
  263. package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +0 -2
  264. package/dist/owletto/dist/assets/record-session-BrM9cdXu.js +0 -2
  265. package/dist/owletto/dist/assets/run-initiator-BKSgI1o0.js +0 -2
  266. package/dist/owletto/dist/assets/runs-k2NpbZm8.js +0 -2
  267. package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +0 -2
  268. package/dist/owletto/dist/assets/schema-value-wjqGxXhv.js +0 -3
  269. package/dist/owletto/dist/assets/settings-V0m5Om5j.js +0 -2
  270. package/dist/owletto/dist/assets/source-record-panels-BMut9YIA.js +0 -2
  271. package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +0 -2
  272. package/dist/owletto/dist/assets/table-ZuYMOjVR.js +0 -2
  273. package/dist/owletto/dist/assets/view-card-DiHWlypr.js +0 -2
  274. package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +0 -2
  275. package/dist/owletto/dist/assets/views-access-required-HA-PiOwA.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{r as j,j as n,bI as _e,i as we,f0 as w,hM as Ee,hN as B,hO as oe,hH as V,hP as Ce,hQ as Oe,hI as le,hJ as Re,hR as ke,hS as Te,eX as Le,aM as Ae,aN as Me,B as A,hz as Pe,aP as Fe,gm as ie,hx as M,gM as Ie,dY as T,a8 as Z,L,eD as $e,hw as ce,gt as ze,gu as Ke,gv as K,gw as G,gz as Ye,gA as Y,b as Be,n as O}from"./index-DB2lVKuV.js";import{p as E,e as ue,b as Ve,g as qe,f as ee,R as De,c as He,d as We}from"./renderer-B8yZ5lql.js";import{S as te}from"./schema-value-DDNHANGs.js";var Je="Separator",ne="horizontal",Ue=["horizontal","vertical"],de=j.forwardRef((e,t)=>{const{decorative:r,orientation:s=ne,...a}=e,l=Qe(s)?s:ne,u=r?{role:"none"}:{"aria-orientation":l==="vertical"?l:void 0,role:"separator"};return n.jsx(_e.div,{"data-orientation":l,...u,...a,ref:t})});de.displayName=Je;function Qe(e){return Ue.includes(e)}var me=de;const Xe=j.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...s},a)=>n.jsx(me,{ref:a,decorative:r,orientation:t,className:we("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...s}));Xe.displayName=me.displayName;const pe=["name","domain","created_at","total_content","active_connections","automations_count","children_count"],P="metadata.";function fe(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const{type:t,format:r,enum:s}=e,a=(Array.isArray(t)?t:[t]).filter(i=>i!=="null"),l=a.length===1?a[0]:void 0;return l===void 0?Array.isArray(s)&&s.some(i=>typeof i=="string")&&s.every(i=>typeof i=="string"||i===null)?"text":null:l==="number"||l==="integer"?"numeric":l==="boolean"?"boolean":l!=="string"?null:r==="date-time"?"timestamptz":r==="date"?"date":"text"}function Ze(e,t){return pe.includes(e)?null:!t||!Object.keys(t).includes(e)?`Sort field '${e}' is neither a built-in sort key nor a declared property`:fe(t[e])?null:`Sort field '${e}' is not a scalar property`}function St(e){const t=e?.properties??{},r=ke(e);return Object.entries(t).flatMap(([s,a])=>{const l=r.find(x=>x.field===s);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(s)||!a||a.const!==void 0||a["x-table-column"]!==!0&&a["x-facet"]!==!0&&!l)return[];const i=[a,...Array.isArray(a.anyOf)?a.anyOf:[]],u=l?.options??Te(a),f=u.find(x=>x.value!==null)?.value,d=i.find(x=>["string","number","integer","boolean"].includes(String(x.type)))??(f===void 0?void 0:{type:typeof f});if(!d)return[];const h=a.format==="date-time"||d.format==="date-time"?"datetime-local":a.format==="date"||d.format==="date"?"date":d.type==="number"||d.type==="integer"?"number":d.type==="boolean"?"boolean":"string";return[{field:s,label:String(a["x-table-label"]??a.title??s.replaceAll("_"," ")),type:h,options:h==="boolean"&&!u.some(x=>typeof x.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...u]:u}]})}const re={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function _t(e,t){return e.value===null&&e.op==="neq"?{op:re.eq,value:"set"}:{op:re[e.op],value:t?.options.find(r=>r.value===e.value)?.label??String(e.value)}}function Ge(e){const t=e?.[Re];return t===void 0?{}:le(t)}function et(e,t){return(e.presets??[]).filter(r=>!r.viewer||!!t?.email)}function wt(e,t,r,s){try{const a=Ge(t),l=et(a,s),i=e[oe],u=i===void 0?void 0:l.find(R=>R.key===i);if(i!==void 0&&!u)throw new Error("This saved filter is unavailable. Choose another filter.");if(u&&!r&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const f=u&&e[w]===void 0?{collection:V(u,void 0,s)}:Ce(e,r);if(f.error)throw f.error;const d=e[Oe],h=d===void 0?u?.table??a.table??{}:le({table:typeof d=="string"?JSON.parse(d):d}).table??{},x=!!u&&(ae(f.collection)!==ae(V(u,void 0,s))||F(h)!==F(u.table??a.table??{}));return{...f,presentation:a,presets:l,preset:u,table:h,edited:x}}catch(a){return{collection:{},presentation:{},presets:[],table:{},edited:!1,error:a instanceof Error?a:new Error("Invalid collection configuration")}}}function ae(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(S)])}function S(e){return JSON.stringify([e.field,e.op,e.value])}function F(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function Et(e,t){return t?{[oe]:t,[w]:B(e)[w]??"{}"}:B(e)}function Ct(e,t,r,s,a=new Date,l){let i=t.filters??[],u=e.viewer;if(u){const d=l?.email?S({field:u.field,op:"eq",value:l.email.toLowerCase()}):void 0;d&&i.some(h=>S(h)===d)?i=i.filter(h=>S(h)!==d):u=void 0}let f=e.relativeDate;if(f){const d=(V({...e,viewer:void 0,selection:{}},a).filters??[]).map(S),h=i.map(S);d.every(x=>h.includes(x))?i=i.filter(x=>!d.includes(S(x))):f=void 0}return{key:e.key,label:e.label,selection:{...t.search?{search:t.search}:{},...i.length?{filters:i}:{},...t.segment?{segment:t.segment}:{}},...F(r)!==F(s.table??{})?{table:r}:{},...f?{relativeDate:f}:{},...u?{viewer:u}:{}}}function Ot(e,t,r){const s=[...e.filters??[]],a=r??(t.length===1&&t[0].op==="eq"?s.findIndex(i=>i.field===t[0].field&&i.op==="eq"):-1),l=a>=0?[...s.slice(0,a),...t,...s.slice(a+1)]:[...s,...t];return{...e,filters:Le({filters:l}).filters}}function Rt(e,t){return{...e,filters:e.filters?.filter((r,s)=>s!==t)}}function kt(e,t){return{...typeof e.$preset=="string"?e[w]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[w]:String(Ee(e[w]))}:B(t),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const xe=e=>pe.includes(e);function Tt(e,t){const r=t?.properties;return e.sort&&!Ze(e.sort.field,r)?e.sort:{field:"created_at",order:"desc"}}function tt(e,t){return!xe(e)&&fe(t)!==null}function Lt(e){return xe(e)?e:`${P}${e}`}function nt(e){return e.startsWith(P)?e.slice(P.length):e}const he=j.createContext(void 0);function At({value:e,children:t}){return n.jsx(he.Provider,{value:e,children:t})}function rt(e){const t=j.useContext(he);if(t)return r=>{r.defaultPrevented||(r.preventDefault(),t(e))}}function at({choices:e,visible:t,onChange:r}){return n.jsxs(Ae,{children:[n.jsx(Me,{asChild:!0,children:n.jsx(A,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:n.jsx(Pe,{className:"h-4 w-4"})})}),n.jsxs(Fe,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[n.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),e.map(s=>n.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[n.jsx("input",{type:"checkbox",checked:!t||t.includes(s.field),onChange:a=>{const l=t??e.map(i=>i.field);r(a.target.checked?[...l,s.field]:l.filter(i=>i!==s.field))}}),s.label]},s.field))]})]})}function st({direction:e}){return e?n.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[n.jsx("title",{children:e==="asc"?"Sort ascending":"Sort descending"}),e==="asc"?n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):n.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[n.jsx("title",{children:"Sort"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function ge(e,t){if(typeof e!="string"||!t||t.length===0)return e;const r=e.trim();if(t.includes(r))return r;try{const s=JSON.parse(r);if(typeof s=="string"&&t.includes(s))return s}catch{}return e}function Mt(e,t){if(!e)return{};const r=t?.properties;return r?Object.fromEntries(Object.entries(e).map(([s,a])=>[s,ge(a,r[s]?.enum)])):{...e}}function _({column:e,children:t,alignRight:r=!1}){return n.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${r?" ml-auto":""}`,onClick:()=>e.toggleSorting(e.getIsSorted()==="asc"),children:[t,n.jsx(st,{direction:e.getIsSorted()})]})}function se(e,t,r){const s=ie(e?.properties).filter(([l,i])=>(!t||l!=="name")&&!i["x-image"]&&i["x-table-column"]===!0);if(s.length)return s.map(([l,i])=>({field:l,label:i["x-table-label"]??M(l.replaceAll("_"," "))}));if(!t)return[];const a=r.find(l=>Object.keys(E(l.metadata)).length>0);return Object.keys(E(a?.metadata)).filter(l=>l!=="id"&&l!=="slug"&&l!=="name"&&!Ie(e?.properties?.[l])).map(l=>({field:l,label:M(l.replaceAll("_"," "))}))}function ot(e){return e.some(t=>Object.hasOwn(E(t.metadata),"name"))}function lt(e,t){return T(e,ue(t))}function it({owner:e,entity:t}){return n.jsx(L,{to:lt(e,t),className:"block max-w-56 truncate font-medium hover:underline",title:t.name,onClick:rt(t),children:t.name})}function ct(e){return`${e.entityType}:${e.lookupField}`}const ut=new Set(["stage","category","round_type","investor_type"]);function dt(e,t){const r=e.toLowerCase();return r==="mrr"||r==="arr"||r==="revenue"||r==="valuation"||r==="funding_raised"||r==="fund_size"||r.endsWith("_usd")||t.description?.toLowerCase().includes("usd")===!0}function mt(e,t){if(dt(e,t))return"currency";if(ut.has(e)||e.endsWith("_slug"))return"enum"}function pt({entities:e,owner:t,schema:r,entityTypeIcon:s,isDerived:a,measureColumns:l,linkedEntityLookups:i,hasAnyParents:u,sorting:f,onSortingChange:d,visibleColumns:h,columnChoices:x,onVisibleColumnsChange:R,page:I,pageSize:ve,totalCount:q,hasMore:je,pageTitle:be,onPrevPage:ye,onNextPage:Ne}){const k=x?.length&&R?n.jsx(at,{choices:x,visible:h,onChange:R}):null,y=r?.properties,D=!a||ot(e),H=j.useMemo(()=>y?Object.fromEntries(Object.entries(y).flatMap(([c,o])=>o["x-link-entity-type"]?[[c,{entityType:o["x-link-entity-type"],lookupField:o["x-link-lookup-field"]||"slug"}]]:[])):{},[y]),C=j.useMemo(()=>y?se({properties:y},a,[]).map(({field:o})=>[o,y[o]]).map(([o,p])=>{const g=H[o],m=g?i[ct(g)]:void 0;return{id:a?o:`${P}${o}`,accessorFn:v=>{const b=E(v.metadata);return ge(b[o],p.enum)},header:({column:v})=>{const b=p["x-table-label"]||p.title||p.description||M(o.replace(/_/g," "));return a||tt(o,p)?n.jsx(_,{column:v,children:b}):b},cell:({getValue:v})=>n.jsx(te,{value:v(),prop:p,format:mt(o,p),className:"text-muted-foreground",resolveLink:m?b=>{const N=m[b];return N?{label:N.name,to:T(t,[{entity_type:N.entity_type,slug:N.slug}])}:void 0}:void 0})}}):[],[a,H,i,t,y]),W=j.useMemo(()=>new Set(l),[l]),$=j.useMemo(()=>!a||C.length>0?[]:se({properties:y},!0,e).map(({field:o})=>o).map(o=>{const p=W.has(o);return{id:o,accessorFn:g=>E(g.metadata)[o],header:({column:g})=>n.jsxs(_,{column:g,children:[p?o:M(o.replace(/_/g," ")),p&&n.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:g})=>n.jsx(te,{value:g(),prop:y?.[o],className:p?"tabular-nums":"text-muted-foreground"}),meta:p?{align:"right"}:void 0}}),[a,C,e,W,y]),J=j.useMemo(()=>{const c=r?.["x-table-relationships"];return!c||c.length===0?[]:c.map(o=>({id:`rel_${o.relationship_type}`,accessorFn:p=>p.relationships?.[o.relationship_type]??[],header:o.label,cell:({getValue:p})=>{const g=p();return!g||g.length===0?n.jsx("span",{className:"text-muted-foreground",children:"-"}):n.jsx("div",{className:"flex flex-wrap gap-1",children:g.map((m,v)=>{const b=T(t,[{entity_type:m.entity_type,slug:m.slug}]);return n.jsxs("span",{children:[n.jsx(L,{to:b,className:"text-primary hover:underline",onClick:N=>N.stopPropagation(),children:m.name}),v<g.length-1&&","]},m.id)})})}}))},[t,r]),U=j.useMemo(()=>u||e.some(o=>o.parent_name&&o.parent_slug&&o.parent_entity_type)?[{id:"parent",accessorFn:o=>o.parent_name,header:"Parent",cell:({row:o})=>{if(!o.original.parent_name||!o.original.parent_slug||!o.original.parent_entity_type)return n.jsx("span",{className:"text-muted-foreground",children:"-"});const p=T(t,[{entity_type:o.original.parent_entity_type,slug:o.original.parent_slug}]);return n.jsx(L,{to:p,className:"text-primary hover:underline",children:o.original.parent_name})}}]:[],[e,u,t]),Q=j.useMemo(()=>{const c=[],o=e.some(m=>(m.total_content??0)>0),p=e.some(m=>(m.active_connections??0)>0),g=e.some(m=>(m.automations_count??0)>0);return o&&c.push({accessorKey:"total_content",header:({column:m})=>n.jsx(_,{column:m,alignRight:!0,children:"Activity"}),cell:({row:m,getValue:v})=>{const b=v()??0;if(b===0)return n.jsx("span",{className:"tabular-nums",children:"0"});const N=ue(m.original);return n.jsx(L,{to:$e(t,N),className:"tabular-nums hover:underline",children:b})},meta:{align:"right"}}),p&&c.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:m})=>{const v=m();return v&&v>0?n.jsxs(Z,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[v," active"]}):n.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),g&&c.push({accessorKey:"automations_count",header:({column:m})=>n.jsx(_,{column:m,alignRight:!0,children:"Automations"}),cell:({getValue:m})=>n.jsx("span",{className:"tabular-nums",children:m()??0}),meta:{align:"right"}}),c},[e,t]),X=j.useMemo(()=>[{accessorKey:"name",header:({column:c})=>D?n.jsx(_,{column:c,children:"Name"}):"Name",cell:({row:c})=>{const o=E(c.original.metadata);return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ce,{metadata:o,metadataSchema:r,name:c.original.name,typeIcon:s,className:"h-6 w-6 shrink-0"}),n.jsx("div",{className:"min-w-0",children:n.jsx(it,{owner:t,entity:c.original})})]})}},...U,...C,...$,...J,...Q,...a?[]:[{accessorKey:"created_at",header:({column:c})=>n.jsx(_,{column:c,children:"Created"}),cell:({getValue:c})=>n.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(c()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[t,U,C,$,J,Q,r,s,a,D]),z=Ve({data:e,columns:X,state:{sorting:f,columnVisibility:Object.fromEntries([...C,...$].flatMap(c=>c.id?[[c.id,!h||h.includes(a?c.id:nt(c.id))]]:[]))},onSortingChange:d,getCoreRowModel:qe(),manualSorting:!0,enableSortingRemoval:!1}),Se=e.length>0||I>0;return n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"rounded-lg border",children:n.jsxs(ze,{className:"min-w-[48rem]",children:[n.jsx(Ke,{children:z.getHeaderGroups().map(c=>n.jsxs(K,{children:[c.headers.map(o=>n.jsx(G,{"aria-sort":o.column.getIsSorted()==="asc"?"ascending":o.column.getIsSorted()==="desc"?"descending":void 0,className:o.column.columnDef.meta?.align==="right"?"text-right":"",children:o.isPlaceholder?null:ee(o.column.columnDef.header,o.getContext())},o.id)),k?n.jsx(G,{className:"w-10 pr-2 text-right",children:k}):null]},c.id))}),n.jsx(Ye,{children:z.getRowModel().rows.length?z.getRowModel().rows.map(c=>n.jsxs(K,{children:[c.getVisibleCells().map(o=>n.jsx(Y,{className:o.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:ee(o.column.columnDef.cell,o.getContext())},o.id)),k?n.jsx(Y,{}):null]},c.id)):n.jsx(K,{children:n.jsx(Y,{colSpan:X.length+(k?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),Se&&n.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:[n.jsxs("div",{children:["Showing ",e.length," of ",q," ",be.toLowerCase()]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{children:["Page ",I+1," of ",Math.max(1,Math.ceil(q/ve))]}),n.jsx(A,{variant:"outline",size:"sm",onClick:ye,disabled:I===0,children:"Previous"}),n.jsx(A,{variant:"outline",size:"sm",onClick:Ne,disabled:!je,children:"Next"})]})]})]})}const ft=720;function xt(){return n.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx(O,{className:"h-9 max-w-sm flex-1"}),n.jsx(O,{className:"h-9 w-28"})]}),n.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[n.jsx("div",{className:"border-b px-4 py-3",children:n.jsx(O,{className:"h-3 w-1/3"})}),n.jsx("div",{className:"divide-y",children:Array.from({length:5},(e,t)=>n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[n.jsx(O,{className:"h-3 flex-1"}),n.jsx(O,{className:"h-3 w-16 shrink-0"})]},t))})]})]})}function Pt({title:e,actions:t,controls:r,table:s,children:a,loading:l=!1,error:i=null,onRetry:u,empty:f=n.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"No records."})}){return n.jsxs("div",{className:"@container space-y-4",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[typeof e=="string"?n.jsx("h2",{className:"text-lg font-semibold",children:e}):e,t]}),n.jsxs("div",{children:[r,l?n.jsx(xt,{}):i!==null?n.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[i,u?n.jsx(A,{className:"ml-3",variant:"outline",size:"sm",onClick:u,children:"Retry"}):null]}):a!==void 0?a:s?n.jsx(pt,{...s}):f]})]})}function ht(e,t){return t?.properties?ie(t.properties).map(([r,s])=>({key:r,prop:s})):Object.keys(e.metadata??{}).map(r=>({key:r,prop:{}}))}function gt({entity:e,schema:t,icon:r}){return n.jsxs(n.Fragment,{children:[n.jsx(ce,{metadata:e.metadata,metadataSchema:t?{...t}:void 0,name:e.name,typeIcon:r,className:"h-6 w-6 shrink-0"}),n.jsx("h2",{className:"truncate text-lg font-semibold leading-tight",children:e.name})]})}function vt({entity:e,schema:t,context:r}){const s=He(t?{...t}:void 0).filter(({key:a,prop:l})=>l["x-table-column"]===!0&&!l["x-image"]&&e.metadata?.[a]!==void 0&&e.metadata[a]!==null&&e.metadata[a]!=="");return s.length?n.jsx("p",{"data-testid":"record-summary",className:"-mt-2 truncate text-sm text-muted-foreground tabular-nums",children:s.map(({key:a,prop:l},i)=>n.jsxs("span",{children:[i>0?" · ":null,n.jsx(We,{field:{key:a,prop:l},value:e.metadata?.[a],context:r})]},a))}):null}function jt({details:e,summary:t,children:r,rootRef:s,narrow:a}){return n.jsx("div",{ref:s,className:"min-w-0 space-y-4",children:a?n.jsxs(n.Fragment,{children:[t,n.jsx("section",{"aria-label":"Details","data-testid":"record-details",children:e}),r]}):n.jsxs("div",{className:"grid grid-cols-[18rem_minmax(0,1fr)] gap-6",children:[n.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:e}),r]})})}function Ft({entity:e,owner:t,schema:r,title:s,actions:a,details:l,summary:i,children:u,layout:f="record"}){const d=j.useRef(null),h=Be(d,ft),x=n.jsxs(n.Fragment,{children:[n.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:[n.jsx("div",{className:"flex min-w-0 items-center gap-2",children:s===void 0?n.jsx(gt,{entity:e,schema:r}):s}),a]}),f==="content"?u:n.jsx(jt,{rootRef:d,narrow:h,details:l===void 0?n.jsx(De,{fields:ht(e,r),values:e.metadata??{},context:{ownerSlug:t}}):l,summary:i===void 0?n.jsx(vt,{entity:e,schema:r,context:{ownerSlug:t}}):i,children:u})]});return f==="content"?x:n.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:x})}export{pt as E,ft as N,At as R,Xe as S,Ot as a,wt as b,St as c,nt as d,se as e,_t as f,Pt as g,xt as h,Lt as i,kt as j,Et as k,Ct as l,Ft as m,Mt as n,jt as o,vt as p,gt as q,Rt as r,Tt as s,rt as u};
2
+ //# sourceMappingURL=entity-pages-C6M6yKFf.js.map
@@ -1,2 +1,2 @@
1
- import{r as _,j as N,B as xe,dg as lt,g1 as ut,g2 as dt,c1 as ft,i as ve,cP as yt,m as ye,bx as ht,cY as mt}from"./index-BoqrvLHQ.js";function Ge(t){let n=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(const c of t)n=Math.min(n,c.x-c.w/2),i=Math.max(i,c.x+c.w/2),r=Math.min(r,c.y-c.h/2),l=Math.max(l,c.y+c.h/2);return Number.isFinite(n)?{x0:n,y0:r,x1:i,y1:l}:null}const be=(t,n,r)=>t<n?n:t>r?r:t;function pt(t,n,r,{padding:i=.12,minZoom:l=.2,maxZoom:c=1.2}={}){const x=Math.max(1,t.x1-t.x0),w=Math.max(1,t.y1-t.y0),E=be(Math.min(n/(x*(1+i)),r/(w*(1+i))),l,c);return{z:E,x:n/2-(t.x0+t.x1)/2*E,y:r/2-(t.y0+t.y1)/2*E}}function xt(t,n,r=0){if(t===n){const h=t.x+t.w/2,p=t.y-t.h/2;return[{x:h-30,y:p},{x:h-30,y:p-26},{x:h+22,y:p-26},{x:h+22,y:t.y-6},{x:h,y:t.y-6}]}const i=r*8,l=t.x+t.w/2,c=t.y+be(i,-t.h/2+6,t.h/2-6),x=n.x-n.w/2,w=n.y+be(i,-n.h/2+6,n.h/2-6);if(x-l>=40){const h=(l+x)/2+i;return[{x:l,y:c},{x:h,y:c},{x:h,y:w},{x,y:w}]}const E=Math.max(t.y+t.h/2,n.y+n.h/2)+24+Math.abs(i),k=Math.min(t.y-t.h/2,n.y-n.h/2)-24-Math.abs(i),g=(c+w)/2,u=Math.abs(E-g)<=Math.abs(k-g)?E:k,f=l+24+Math.abs(i),y=x-24-Math.abs(i);return[{x:l,y:c},{x:f,y:c},{x:f,y:u},{x:y,y:u},{x:y,y:w},{x,y:w}]}function gt(t,n,r){const i=r.x-n.x,l=r.y-n.y,c=i*i+l*l,x=c?be(((t.x-n.x)*i+(t.y-n.y)*l)/c,0,1):0;return Math.hypot(t.x-(n.x+x*i),t.y-(n.y+x*l))}function wt(t,n){let r=Number.POSITIVE_INFINITY;for(let i=0;i<n.length-1;i++)r=Math.min(r,gt(t,n[i],n[i+1]));return r}function vt(t,n){return Math.abs(n.x-t.x)<=t.w/2&&Math.abs(n.y-t.y)<=t.h/2}class ie{cells=new Set;static CELL_W=12;static CELL_H=16;keys(n){const r=[],i=Math.floor(n.x0/ie.CELL_W),l=Math.floor(n.x1/ie.CELL_W),c=Math.floor(n.y0/ie.CELL_H),x=Math.floor(n.y1/ie.CELL_H);for(let w=i;w<=l;w++)for(let E=c;E<=x;E++)r.push(w*1e5+E);return r}isFree(n){return this.keys(n).every(r=>!this.cells.has(r))}reserve(n){for(const r of this.keys(n))this.cells.add(r)}}function bt(t,n,r,i,l){const c=t.slice(0,-1).map((u,f)=>({i:f,length:Math.hypot(t[f+1].x-u.x,t[f+1].y-u.y)})).sort((u,f)=>f.length-u.length);if(c.length===0)return null;const x=u=>({x0:u.x-n/2,x1:u.x+n/2,y0:u.y-r/2,y1:u.y+r/2}),w=u=>({x:(t[u].x+t[u+1].x)/2,y:(t[u].y+t[u+1].y)/2});for(const{i:u,length:f}of c){if(!l&&f<n*.7)break;const y=w(u);if(i.isFree(x(y)))return i.reserve(x(y)),y}if(!l)return null;const E=w(c[0].i),g=[-1,1,-1.6,1.6].map(u=>({x:E.x,y:E.y+u*(r+12)})).find(u=>i.isFree(x(u)))??E;return i.reserve(x(g)),g}const kt=t=>N.jsx(yt,{icon:t||null,className:"h-4 w-4"}),Mt='600 14px "DM Sans", system-ui, sans-serif',Et='400 11px "DM Sans", system-ui, sans-serif',St='500 9px "DM Sans", system-ui, sans-serif',Tt='500 11px "DM Sans", system-ui, sans-serif',he=18,Be=8;function qe(t){const n=getComputedStyle(t),r=(i,l)=>n.getPropertyValue(i).trim()||l;return{foreground:r("--foreground","#141414"),muted:r("--muted-foreground","#545454"),card:r("--card","#ffffff"),background:r("--background","#fcfcfb"),border:r("--border","#e7e4dc"),primary:r("--primary","#2f63e8"),mutedSurface:r("--muted","#f3f1ea")}}function ge(t,n,r){if(t.measureText(n).width<=r)return n;let i=0,l=n.length;for(;i<l;){const c=Math.ceil((i+l)/2);t.measureText(`${n.slice(0,c)}…`).width<=r?i=c:l=c-1}return`${n.slice(0,i)}…`}function _t(t,n,r,i){const l=Math.hypot(r.x-n.x,r.y-n.y);if(l<1)return;const c=(r.x-n.x)/l,x=(r.y-n.y)/l;t.moveTo(r.x-c*i-x*i*.55,r.y-x*i+c*i*.55),t.lineTo(r.x,r.y),t.lineTo(r.x-c*i+x*i*.55,r.y-x*i-c*i*.55)}function tn({boxes:t,edges:n,label:r,onOpenBox:i,openLabel:l,onConnect:c,renderIcon:x=kt,className:w}){const E=_.useRef(null),k=_.useRef(null),g=_.useRef(null),u=_.useRef({z:1,x:0,y:0}),f=_.useRef({w:0,h:0,dpr:1}),y=_.useRef(!0),h=_.useRef(new Map),p=_.useRef(null),L=_.useRef(null),O=_.useRef(new Map),C=_.useRef(null),A=_.useRef(""),q=_.useRef(!1),[a,I]=_.useState(()=>new Map),[S,$]=_.useState(null),[K,R]=_.useState(null),[j,Q]=_.useState(null),[B,Oe]=_.useState(null),[Je,Ze]=_.useState(0),{placed:U,movedIds:me}=_.useMemo(()=>{const o=new Map,e=new Set;for(const s of t){const d=a.get(s.id);d&&d.from.x===s.x&&d.from.y===s.y?(o.set(s.id,{...s,x:d.at.x,y:d.at.y}),e.add(s.id)):o.set(s.id,s)}return{placed:o,movedIds:e}},[t,a]),re=_.useMemo(()=>{const o=new Map;for(const s of n){const d=[s.source,s.target].sort().join("|");o.set(d,[...o.get(d)??[],s])}const e=new Map;for(const s of n){const d=U.get(s.source),v=U.get(s.target);if(!d||!v)continue;if(s.route&&!me.has(d.id)&&!me.has(v.id)){e.set(s.id,s.route);continue}const b=o.get([s.source,s.target].sort().join("|"))??[s];e.set(s.id,xt(d,v,b.indexOf(s)-(b.length-1)/2))}return e},[n,U,me]),F=_.useCallback(()=>{y.current=!0},[]),ce=_.useCallback(()=>{const o=Ge([...U.values()]),{w:e,h:s}=f.current;!o||!e||!s||(u.current=pt(o,e,s),q.current=!0,F())},[U,F]),ae=o=>{u.current=o,q.current=!1,F()},Ce=o=>{const e=Ge(o),{w:s,h:d}=f.current;if(!e||!s||!d)return;const v=u.current,b=24;e.x0*v.z+v.x>=b&&e.y0*v.z+v.y>=b&&e.x1*v.z+v.x<=s-b&&e.y1*v.z+v.y<=d-b||ae({...v,x:s/2-(e.x0+e.x1)/2*v.z,y:d/2-(e.y0+e.y1)/2*v.z})},Qe=o=>{Oe(o);const e=U.get(o);e&&Ce([e])},se=t.map(o=>`${o.id}@${Math.round(o.x)},${Math.round(o.y)}`).join(";");_.useEffect(()=>{!se||A.current===se||f.current.w&&(A.current=se,ce())},[se,ce]);const Ae=_.useRef(ce);Ae.current=ce;const Pe=_.useRef(se);Pe.current=se,_.useEffect(()=>{const o=E.current,e=k.current;if(!o||!e||typeof ResizeObserver>"u")return;const s=()=>{const v=window.devicePixelRatio||1,b=o.clientWidth,H=o.clientHeight;f.current={w:b,h:H,dpr:v},e.width=Math.round(b*v),e.height=Math.round(H*v);const W=Pe.current;W&&b&&H&&(A.current!==W||q.current)&&(A.current=W,Ae.current()),F()};s();const d=new ResizeObserver(s);return d.observe(o),()=>d.disconnect()},[F]);const[et,tt]=_.useState(0);_.useEffect(()=>{const o=g.current,e=k.current;if(!o||!e)return;const s=qe(e).muted;for(const d of o.querySelectorAll("[data-icon-key]")){const v=d.dataset.iconKey??"";if(h.current.has(v))continue;const b=d.querySelector("svg"),H=b?null:d.querySelector("img")?.src;if(!b&&!H){h.current.set(v,d.textContent??"");continue}const W=new Image;if(W.onload=F,W.onerror=()=>{h.current.delete(v),tt(T=>T+1)},b){const T=b.cloneNode(!0);T.getAttribute("width")||T.setAttribute("width","24"),T.getAttribute("height")||T.setAttribute("height","24");const M=new XMLSerializer().serializeToString(T).replaceAll("currentColor",s);W.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(M)}`}else H&&(W.src=H);h.current.set(v,W)}},[t,Je,et,F]);const le=(o,e)=>{const s=u.current;return{x:(o-s.x)/s.z,y:(e-s.y)/s.z}},ke=(o,e)=>{const s=u.current,d=le(o,e),v=S&&S.kind!=="edge"?U.get(S.box.id):void 0;if(v&&c){const T=Ye(v);if(Math.hypot(T.x*s.z+s.x-o,T.y*s.z+s.y-e)<=Be+3)return{kind:"handle",box:v}}const b=[...U.values()];for(let T=b.length-1;T>=0;T--)if(vt(b[T],d))return{kind:"box",box:b[T]};let H=null,W=7/s.z;for(const T of n){const M=re.get(T.id);if(!M)continue;const V=wt(d,M);V<W&&(W=V,H=T)}return H?{kind:"edge",edge:H}:null},ee=_.useMemo(()=>{const o=new Set;for(const s of[K,j])s&&o.add(s);S?.kind==="edge"&&o.add(S.edge.id);const e=S&&S.kind!=="edge"?S.box.id:B;if(e)for(const s of n)(s.source===e||s.target===e)&&o.add(s.id);for(const s of n)s.dimmed&&o.delete(s.id);return o},[n,S,K,j,B]);_.useEffect(F,[U,re,ee,S,B,F]);const ze=_.useCallback(()=>{const o=k.current,e=o?.getContext("2d");if(!o||!e)return;const{w:s,h:d,dpr:v}=f.current,b=qe(o),H=getComputedStyle(o),W=new Map,T=m=>{let P=W.get(m);return P===void 0&&(P=H.getPropertyValue(m).trim(),W.set(m,P)),P},{z:M,x:V,y:X}=u.current,ue=m=>({x:m.x*M+V,y:m.y*M+X});e.setTransform(v,0,0,v,0,0),e.clearRect(0,0,s,d);const Se=S&&S.kind!=="edge"?S.box.id:null;e.lineJoin="round";for(const m of n){const P=re.get(m.id);if(!P)continue;const z=P.map(ue),D=ee.has(m.id);e.globalAlpha=m.dimmed?.15:D?.95:.55,e.strokeStyle=m.accent?T(m.accent):D?b.foreground:b.muted,e.lineWidth=D?1.75:1.25,e.beginPath(),e.moveTo(z[0].x,z[0].y);for(const G of z.slice(1))e.lineTo(G.x,G.y);m.directed&&_t(e,z[z.length-2],z[z.length-1],8),e.stroke()}const $e=new ie;for(const m of U.values()){const P=ue(m),z=m.w*M,D=m.h*M,G=P.x-z/2,Y=P.y-D/2;if($e.reserve({x0:G,y0:Y,x1:G+z,y1:Y+D}),G>s||Y>d||G+z<0||Y+D<0)continue;const de=Se===m.id||C.current?.over?.id===m.id;e.globalAlpha=m.dimmed?.25:1,e.beginPath(),e.roundRect(G,Y,z,D,8*M),e.fillStyle=m.muted?b.mutedSurface:b.card,e.fill(),e.lineWidth=de||B===m.id?1.5:1,e.strokeStyle=de||B===m.id?b.primary:b.border,e.stroke();const fe=m.accent&&T(m.accent);if(fe&&(e.save(),e.clip(),e.fillStyle=fe,e.fillRect(G,Y,3*M,D),e.restore()),14*M<5)continue;const te=12*M,J=16*M,ne=m.meta?Y+D/2-8*M:Y+D/2,oe=h.current.get(m.icon??"");oe instanceof HTMLImageElement&&oe.complete&&oe.naturalWidth>0?e.drawImage(oe,G+te,ne-J/2,J,J):typeof oe=="string"&&oe&&(e.font=`${14*M}px system-ui, sans-serif`,e.textBaseline="middle",e.textAlign="left",e.fillText(oe,G+te,ne));const pe=G+te+J+8*M,We=12*M;e.textBaseline="middle",e.textAlign="left";let Ie=G+z-We-pe;if(m.badge){e.font=St.replace("9px",`${9*M}px`);const Fe=ge(e,m.badge.toUpperCase(),Ie*.35),Ne=e.measureText(Fe).width+8*M,He=G+z-We-Ne;e.strokeStyle=b.border,e.lineWidth=1,e.beginPath(),e.roundRect(He,ne-7*M,Ne,14*M,3*M),e.stroke(),e.fillStyle=b.muted,e.fillText(Fe,He+4*M,ne+.5),Ie-=Ne+6*M}e.font=Mt.replace("14px",`${14*M}px`),e.fillStyle=b.foreground,e.fillText(ge(e,m.title,Ie),pe,ne+.5),m.meta&&(e.font=Et.replace("11px",`${11*M}px`),e.fillStyle=b.muted,e.fillText(ge(e,m.meta,G+z-te-pe),pe,Y+D/2+10*M))}const Te=C.current,_e=Te?.from??(Se?U.get(Se):void 0);if(c&&_e&&_e.w*M>=60){const m=ue(Ye(_e));if(e.globalAlpha=1,Te){const P=ue(Te.to);e.strokeStyle=b.primary,e.lineWidth=2,e.setLineDash([6,4]),e.beginPath(),e.moveTo(m.x,m.y),e.lineTo(P.x,P.y),e.stroke(),e.setLineDash([])}e.fillStyle=b.card,e.strokeStyle=b.primary,e.lineWidth=1.5,e.beginPath(),e.arc(m.x,m.y,Be,0,Math.PI*2),e.fill(),e.stroke(),e.beginPath(),e.moveTo(m.x-4,m.y),e.lineTo(m.x+4,m.y),e.moveTo(m.x,m.y-4),e.lineTo(m.x,m.y+4),e.stroke()}e.font=Tt,e.textAlign="center",e.textBaseline="middle";const ct=(m,P,z,D)=>{e.globalAlpha=1,e.fillStyle=b.background,e.strokeStyle=z?b.foreground:b.border,e.lineWidth=1,e.beginPath(),e.roundRect(m.x-D/2,m.y-he/2,D,he,5),e.fill(),e.stroke(),e.fillStyle=z?b.foreground:b.muted,e.fillText(P,m.x,m.y+.5)},at=[...n].sort((m,P)=>Number(ee.has(P.id))-Number(ee.has(m.id)));for(const m of at){const P=re.get(m.id);if(!P||m.dimmed&&!ee.has(m.id))continue;const z=P.map(ue),D=ee.has(m.id),Y=(D?m.details:[m.summary]).map(J=>ge(e,J,200)),de=Math.max(...Y.map(J=>e.measureText(J).width))+14,fe=Y.length*(he+2);if(!D&&M<.45)continue;const te=bt(z,de,fe,$e,D);te&&Y.forEach((J,ne)=>{ct({x:te.x,y:te.y-fe/2+(he+2)*ne+he/2},J,D,de)})}e.globalAlpha=1},[n,re,U,ee,S,B,c]);_.useEffect(()=>{let o=0;const e=()=>{o=requestAnimationFrame(e),y.current&&(y.current=!1,ze())};return o=requestAnimationFrame(e),document.addEventListener("visibilitychange",F),()=>{cancelAnimationFrame(o),document.removeEventListener("visibilitychange",F)}},[ze,F]),_.useEffect(()=>{const o=new MutationObserver(()=>{h.current.clear(),Ze(e=>e+1),F()});return o.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),()=>o.disconnect()},[F]);const Me=(o,e,s)=>{const d=u.current,v=Math.min(3,Math.max(.15,d.z*o));ae({z:v,x:e-(e-d.x)*(v/d.z),y:s-(s-d.y)*(v/d.z)})},Ee=o=>{const e=k.current?.getBoundingClientRect();return{x:o.clientX-(e?.left??0),y:o.clientY-(e?.top??0)}},nt=o=>{if(o.button!==0&&o.pointerType==="mouse")return;o.currentTarget.setPointerCapture(o.pointerId);const e=Ee(o);if(o.pointerType==="touch"&&(O.current.set(o.pointerId,e),O.current.size===2)){const[v,b]=[...O.current.values()];p.current=null,C.current=null,L.current={d:Math.hypot(v.x-b.x,v.y-b.y)||1,mid:{x:(v.x+b.x)/2,y:(v.y+b.y)/2}};return}const s=ke(e.x,e.y),d={start:e,last:e,hit:s,moved:!1};if(s?.kind==="handle")C.current={from:s.box,to:le(e.x,e.y),over:null};else if(s?.kind==="box"){const v=le(e.x,e.y);d.grab={x:s.box.x-v.x,y:s.box.y-v.y}}p.current=d},ot=o=>{const e=Ee(o);O.current.has(o.pointerId)&&O.current.set(o.pointerId,e);const s=L.current;if(s&&O.current.size===2){const[T,M]=[...O.current.values()],V=Math.hypot(T.x-M.x,T.y-M.y)||1,X={x:(T.x+M.x)/2,y:(T.y+M.y)/2};ae({...u.current,x:u.current.x+X.x-s.mid.x,y:u.current.y+X.y-s.mid.y}),Me(V/s.d,X.x,X.y),L.current={d:V,mid:X};return}const d=p.current;if(!d){const T=ke(e.x,e.y);$(V=>It(V,T)?V:T);const M=k.current;M&&(M.style.cursor=T?.kind==="handle"?"crosshair":T?"pointer":"grab");return}const v=e.x-d.last.x,b=e.y-d.last.y;if(d.last=e,!d.moved&&Math.hypot(e.x-d.start.x,e.y-d.start.y)>4&&(d.moved=!0),!d.moved)return;const H=C.current;if(H){H.to=le(e.x,e.y);const T=ke(e.x,e.y);H.over=T?.kind==="box"?T.box:null,F();return}const W=d.hit;if(W?.kind==="box"&&d.grab){const T=le(e.x,e.y),M=t.find(X=>X.id===W.box.id);if(!M)return;const V={x:T.x+d.grab.x,y:T.y+d.grab.y};I(X=>new Map(X).set(M.id,{at:V,from:{x:M.x,y:M.y}}));return}ae({...u.current,x:u.current.x+v,y:u.current.y+b}),k.current&&(k.current.style.cursor="grabbing")},rt=o=>{if(O.current.delete(o.pointerId),L.current){O.current.size<2&&(L.current=null),p.current=null;return}const e=p.current;p.current=null;const s=C.current;if(C.current=null,!e)return;if(k.current&&(k.current.style.cursor="grab"),s){F(),s.over&&c&&c(s.from.id,s.over.id);return}if(e.moved)return;const d=e.hit;d?.kind==="box"?i(d.box.id):d?.kind==="edge"?R(v=>v===d.edge.id?null:d.edge.id):R(null)},st=o=>{O.current.delete(o.pointerId),L.current=null,p.current=null,C.current=null,F()};_.useEffect(()=>{const o=k.current;if(!o)return;const e=s=>{s.preventDefault();const d=Ee(s);s.ctrlKey||s.metaKey?Me(Math.exp(-s.deltaY*(s.ctrlKey?.01:.002)),d.x,d.y):ae({...u.current,x:u.current.x-s.deltaX,y:u.current.y-s.deltaY})};return o.addEventListener("wheel",e,{passive:!1}),()=>o.removeEventListener("wheel",e)});const De=o=>Me(o,f.current.w/2,f.current.h/2),it=[...new Set(t.map(o=>o.icon??""))];return N.jsxs("div",{ref:E,className:ve("relative h-full w-full overflow-hidden",w),children:[N.jsx("canvas",{ref:k,"aria-hidden":"true",className:"block h-full w-full cursor-grab touch-none",onPointerDown:nt,onPointerMove:ot,onPointerUp:rt,onPointerCancel:st,onPointerLeave:()=>{p.current||$(null)}}),N.jsxs("ul",{ref:g,"aria-label":r,className:"sr-only",children:[it.map(o=>N.jsx("li",{"aria-hidden":"true","data-icon-key":o,children:x(o)},`icon:${o}`)),t.map(o=>N.jsx("li",{children:N.jsx("button",{type:"button",onClick:()=>i(o.id),onFocus:()=>Qe(o.id),onBlur:()=>Oe(null),children:l(o)})},o.id)),n.map(o=>N.jsx("li",{"data-revealed":ee.has(o.id)||void 0,children:N.jsx("button",{type:"button","aria-pressed":K===o.id,onClick:()=>R(e=>e===o.id?null:o.id),onFocus:()=>{Q(o.id);const e=re.get(o.id);e&&Ce(e.map(s=>({...s,w:0,h:0})))},onBlur:()=>Q(null),children:o.ariaLabel})},o.id))]}),N.jsxs("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:[N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom in",onClick:()=>De(1.25),children:N.jsx(lt,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom out",onClick:()=>De(.8),children:N.jsx(ut,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Fit to view",onClick:ce,children:N.jsx(dt,{className:"h-3.5 w-3.5"})}),me.size>0?N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Reset layout",onClick:()=>I(new Map),children:N.jsx(ft,{className:"h-3.5 w-3.5"})}):null]})]})}const Ye=t=>({x:t.x+t.w/2,y:t.y});function It(t,n){return!t||!n?t===n:t.kind==="edge"||n.kind==="edge"?t.kind==="edge"&&n.kind==="edge"&&t.edge.id===n.edge.id:t.kind===n.kind&&t.box.id===n.box.id}function nn({label:t,fill:n=!1}){return N.jsxs("div",{role:"status","aria-label":t,"aria-busy":"true",className:ve("flex min-w-0 flex-col gap-3",n&&"min-h-0 flex-1"),children:[N.jsx("div",{className:"flex min-w-0 items-center gap-3",children:N.jsx("div",{"aria-hidden":"true",className:"min-w-0 flex-1",children:N.jsx(ye,{className:"h-5 w-3/4 max-w-xl rounded-none"})})}),N.jsx("div",{className:ve("relative flex min-h-0 flex-col",n&&"flex-1"),"aria-hidden":"true",children:N.jsxs("div",{className:ve("relative min-h-[420px]",n?"flex-1":"h-[70vh]"),children:[N.jsxs("div",{className:"absolute top-1/2 left-1/2 flex h-16 w-52 -translate-x-1/2 -translate-y-1/2 items-center gap-3 rounded-xl border border-border bg-card px-4",children:[N.jsx(ye,{className:"h-4 w-4 shrink-0 rounded-none"}),N.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[N.jsx(ye,{className:"h-3.5 w-24 rounded-none"}),N.jsx(ye,{className:"h-2.5 w-32 rounded-none"})]})]}),N.jsx("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:["in","out","fit"].map(r=>N.jsx("div",{className:"flex h-7 w-7 items-center justify-center border border-input bg-background",children:N.jsx(ye,{className:"h-3 w-3 rounded-none"})},r))})]})})]})}function we(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Re={exports:{}},Ke;function Nt(){return Ke||(Ke=1,(function(t,n){(function(r){t.exports=r()})(function(){return(function(){function r(i,l,c){function x(k,g){if(!l[k]){if(!i[k]){var u=typeof we=="function"&&we;if(!g&&u)return u(k,!0);if(w)return w(k,!0);var f=new Error("Cannot find module '"+k+"'");throw f.code="MODULE_NOT_FOUND",f}var y=l[k]={exports:{}};i[k][0].call(y.exports,function(h){var p=i[k][1][h];return x(p||h)},y,y.exports,r,i,l,c)}return l[k].exports}for(var w=typeof we=="function"&&we,E=0;E<c.length;E++)x(c[E]);return x}return r})()({1:[function(r,i,l){Object.defineProperty(l,"__esModule",{value:!0}),l.default=void 0;function c(f){"@babel/helpers - typeof";return c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(y){return typeof y}:function(y){return y&&typeof Symbol=="function"&&y.constructor===Symbol&&y!==Symbol.prototype?"symbol":typeof y},c(f)}function x(f,y){if(!(f instanceof y))throw new TypeError("Cannot call a class as a function")}function w(f,y){for(var h=0;h<y.length;h++){var p=y[h];p.enumerable=p.enumerable||!1,p.configurable=!0,"value"in p&&(p.writable=!0),Object.defineProperty(f,k(p.key),p)}}function E(f,y,h){return y&&w(f.prototype,y),Object.defineProperty(f,"prototype",{writable:!1}),f}function k(f){var y=g(f,"string");return c(y)=="symbol"?y:y+""}function g(f,y){if(c(f)!="object"||!f)return f;var h=f[Symbol.toPrimitive];if(h!==void 0){var p=h.call(f,y);if(c(p)!="object")return p;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(f)}l.default=(function(){function f(){var y=this,h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},p=h.defaultLayoutOptions,L=p===void 0?{}:p,O=h.algorithms,C=O===void 0?["layered","stress","mrtree","radial","force","disco","sporeOverlap","sporeCompaction","rectpacking"]:O,A=h.workerFactory,q=h.workerUrl;if(x(this,f),this.defaultLayoutOptions=L,this.initialized=!1,typeof q>"u"&&typeof A>"u")throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");var a=A;typeof q<"u"&&typeof A>"u"&&(a=function($){return new Worker($)});var I=a(q);if(typeof I.postMessage!="function")throw new TypeError("Created worker does not provide the required 'postMessage' function.");this.worker=new u(I),this.worker.postMessage({cmd:"register",algorithms:C}).then(function(S){return y.initialized=!0}).catch(console.err)}return E(f,[{key:"layout",value:function(h){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},L=p.layoutOptions,O=L===void 0?this.defaultLayoutOptions:L,C=p.logging,A=C===void 0?!1:C,q=p.measureExecutionTime,a=q===void 0?!1:q;return h?this.worker.postMessage({cmd:"layout",graph:h,layoutOptions:O,options:{logging:A,measureExecutionTime:a}}):Promise.reject(new Error("Missing mandatory parameter 'graph'."))}},{key:"knownLayoutAlgorithms",value:function(){return this.worker.postMessage({cmd:"algorithms"})}},{key:"knownLayoutOptions",value:function(){return this.worker.postMessage({cmd:"options"})}},{key:"knownLayoutCategories",value:function(){return this.worker.postMessage({cmd:"categories"})}},{key:"terminateWorker",value:function(){this.worker&&this.worker.terminate()}}])})();var u=(function(){function f(y){var h=this;if(x(this,f),y===void 0)throw new Error("Missing mandatory parameter 'worker'.");this.resolvers={},this.worker=y,this.worker.onmessage=function(p){setTimeout(function(){h.receive(h,p)},0)}}return E(f,[{key:"postMessage",value:function(h){var p=this.id||0;this.id=p+1,h.id=p;var L=this;return new Promise(function(O,C){L.resolvers[p]=function(A,q){A?(L.convertGwtStyleError(A),C(A)):O(q)},L.worker.postMessage(h)})}},{key:"receive",value:function(h,p){var L=p.data,O=h.resolvers[L.id];O&&(delete h.resolvers[L.id],L.error?O(L.error):O(null,L.data))}},{key:"terminate",value:function(){this.worker&&this.worker.terminate()}},{key:"convertGwtStyleError",value:function(h){if(h){var p=h.__java$exception;p&&(p.cause&&p.cause.backingJsObject&&(h.cause=p.cause.backingJsObject,this.convertGwtStyleError(h.cause)),delete h.__java$exception)}}}])})()},{}],2:[function(r,i,l){var c=r("./elk-api.js").default;Object.defineProperty(i.exports,"__esModule",{value:!0}),i.exports=c,c.default=c},{"./elk-api.js":1}]},{},[2])(2)})})(Re)),Re.exports}var Rt=Nt();const jt=ht(Rt);function Lt(t){return new Worker("/assets/elk-worker.min-BENGc9gn.js",{name:t?.name})}const Ot=200,Ct=320,Xe=56,At=7.4,Pt=5.9,zt=84,Dt=48;function $t(t,n){return Math.round(Math.min(Ct,Math.max(Ot,zt+t.length*At,Dt+n.length*Pt)))}function Wt(t,n){const r=[];return t>0&&r.push(`${t} ${t===1?"field":"fields"}`),typeof n=="number"&&r.push(`${n.toLocaleString()} ${n===1?"record":"records"}`),r.join(" · ")}function Ue(t,n){return t.slug<n.slug?-1:t.slug>n.slug?1:0}function Ft(t,n){const r=new Set;return t.filter(i=>i.status!=="active"||i.organization_slug&&i.organization_slug!==n||r.has(i.slug)?!1:(r.add(i.slug),!0))}function Ht(t){const n=t.metadata_schema;if(!n||typeof n!="object")return 0;const r=n.properties;return!r||typeof r!="object"?0:Object.keys(r).length}function Gt(t){const{entityTypes:n,relationshipTypes:r,rulesBySlug:i}=t,l=t.ownerSlug??"",c=[...n].sort(Ue),x=Ft(r,l).sort(Ue),w=a=>!a.organization_slug||a.organization_slug===l,E=a=>a.organization_slug||l,k=new Map;for(const a of c)k.set(a.slug,[...k.get(a.slug)??[],a]);const g=a=>(k.get(a.slug)?.length??0)>1?`${E(a)}:${a.slug}`:a.slug,u=new Set(c.filter(w).map(g)),f=a=>{const I=k.get(a)??[];return I.find(w)??(I.length===1?I[0]:void 0)},y=new Set(u),h=x.flatMap(a=>[...i[a.slug]??[]].sort((I,S)=>I.id-S.id).flatMap(I=>{const S=f(I.source_entity_type_slug),$=f(I.target_entity_type_slug);if(!S||!$)return[];const K=g(S),R=g($);return!u.has(K)&&!u.has(R)?[]:(y.add(K),y.add(R),[{rt:a,source:K,target:R}])})),p=c.filter(a=>y.has(g(a))),L=[],O=new Map,C=new Map;for(const{rt:a,source:I,target:S}of h){const $=`${a.slug}|${I}|${S}`,K=C.get($);if(K){K.ruleCount+=1;continue}const R={slug:a.slug,label:a.name||a.slug,ruleCount:1};C.set($,R);const j=`${I}|${S}`,Q=O.get(j);if(Q){Q.data.relationships.push(R),Q.data.isSymmetric=Q.data.isSymmetric&&a.is_symmetric;continue}const B={id:`pair:${I}|${S}`,source:I,target:S,data:{relationships:[R],isSymmetric:a.is_symmetric}};O.set(j,B),L.push(B)}const A=new Map;for(const{rt:a,source:I,target:S}of h){const $=A.get(a.slug)??new Set;$.add(`${I}|${S}`),A.set(a.slug,$)}for(const{rt:a}of h)if(A.get(a.slug)?.size===1&&typeof a.relationship_count=="number")for(const I of C.values())I.slug===a.slug&&(I.linkCount=a.relationship_count);return{nodes:p.map(a=>{const I=a.name||a.slug,S=Ht(a),$=Wt(S,a.entity_count);return{id:g(a),width:$t(I,$),height:Xe,data:{slug:a.slug,label:I,icon:a.icon,isSystem:mt(a),organizationSlug:w(a)?void 0:E(a),metaLabel:$}}}),edges:L}}const Z=24,Bt=72,qt=16,Yt=48,Kt=64,je=16,Ut=720;function Vt(t,n){const r=new Map(t.map(c=>[c.id,c.id])),i=c=>{const x=r.get(c)??c;if(x===c)return c;const w=i(x);return r.set(c,w),w};for(const c of n)r.set(i(c.source),i(c.target));const l=new Map;for(const c of t){const x=i(c.id);l.set(x,[...l.get(x)??[],c])}return[...l.values()].sort((c,x)=>x.length-c.length)}function Xt(t,n,r,i){const l=new Map(t.flatMap((g,u)=>g.map(f=>[f.id,u]))),c=t.map(()=>({top:1/0,bottom:-1/0})),x=(g,u,f)=>{const y=c[l.get(g)??0];y.top=Math.min(y.top,u),y.bottom=Math.max(y.bottom,f)};for(const g of n)x(g.id,g.position.y,g.position.y+g.height);for(const g of r)for(const u of i.get(g.id)??[])x(g.source,u.y,u.y);let w=Z;const E=c.map(({top:g,bottom:u})=>{const f=w-g;return w=u+f+Yt,f}),k=g=>E[l.get(g)??0];for(const g of r){const u=i.get(g.id);u&&i.set(g.id,u.map(f=>({x:f.x,y:f.y+k(g.source)})))}return n.map(g=>({...g,position:{x:g.position.x,y:g.position.y+k(g.id)}}))}function Jt(t,n){const r=Z,i=Math.max(r+Ut,...n.map(w=>w.position.x+w.width));let l=n.length>0?Math.max(...n.map(w=>w.position.y+w.height))+Kt:Z;const c=[...new Set(t.map(w=>w.lane??0))].sort((w,E)=>w-E),x=[];for(const w of c){let E=r,k=0;for(const g of t.filter(u=>(u.lane??0)===w))E>r&&E+g.width>i&&(E=r,l+=k+je,k=0),x.push({...g,position:{x:E,y:l}}),E+=g.width+je,k=Math.max(k,g.height);l+=k+je*2}return x}let Ve=null;function Zt(){return Ve??=new jt({workerFactory:()=>new Lt}),Ve}const Le={"elk.algorithm":"layered","elk.direction":"RIGHT","elk.edgeRouting":"ORTHOGONAL","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"24","elk.layered.spacing.nodeNodeBetweenLayers":"80","elk.spacing.nodeNode":"48","elk.spacing.edgeEdge":"14","elk.spacing.edgeNode":"24","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.crossingMinimization.semiInteractive":"true"};async function Qt(t,{elk:n=Zt(),targetAspect:r}={}){const i=new Set;for(const a of t.edges)i.add(a.source),i.add(a.target);const l=t.nodes.some(a=>a.lane!==void 0),c=t.nodes.filter(a=>i.has(a.id)),x=l?Vt(c,t.edges):[c],w=x.flat(),E=t.nodes.filter(a=>!i.has(a.id)),k=l?[]:E,g=l?E:[],u=k.reduce((a,I)=>Math.max(a,I.width),0),f=k.length>0?Z+u+Bt:0,y=a=>({x:a.x+Z+f,y:a.y+Z});let h=[];const p=new Map;if(w.length>0){const a=t.edges.filter(R=>R.source!==R.target),I=R=>n.layout({id:"root",layoutOptions:l?{...R,"elk.partitioning.activate":"true","elk.separateConnectedComponents":"false"}:R,children:w.map(j=>({id:j.id,width:j.width,height:j.height,...l?{layoutOptions:{"elk.partitioning.partition":String(j.lane??1)}}:{}})),edges:a.map(j=>({id:j.id,sources:[j.layoutReversed?j.target:j.source],targets:[j.layoutReversed?j.source:j.target]}))});let S=await I(Le);const $=r&&S.width&&S.height?r*S.width/S.height:1;if($>1.08){const R=Number(Le["elk.spacing.nodeNode"]),j=Math.min($,2.2);S=await I({...Le,"elk.spacing.nodeNode":String(Math.round(Math.min(180,R*j+Xe*(j-1))))})}const K=new Map((S.children??[]).map(R=>[R.id,R]));h=w.map(R=>{const j=K.get(R.id);return{...R,position:y({x:j?.x??0,y:j?.y??0})}});for(const R of S.edges??[]){const j=(R.sections??[]).flatMap(B=>[B.startPoint,...B.bendPoints??[],B.endPoint]);if(j.length<2)continue;const Q=t.edges.find(B=>B.id===R.id)?.layoutReversed;p.set(R.id,(Q?[...j].reverse():j).map(y))}}let L=Z;const O=k.map(a=>{const I={x:Z,y:L};return L+=a.height+qt,{...a,position:I}});l&&(h=Xt(x,h,t.edges,p));const C=Jt(g,h),A=new Map([...h,...O,...C].map(a=>[a.id,a]));return{nodes:t.nodes.map(a=>A.get(a.id)??{...a,position:{x:Z,y:Z}}),edges:t.edges.map(a=>({...a,route:p.get(a.id)??null}))}}function on(t,n){return Qt(Gt(t),n)}export{nn as G,Xe as H,on as a,Gt as b,tn as c,Qt as l,$t as n,Ft as s};
2
- //# sourceMappingURL=entity-schema-graph-Cq96SJ3c.js.map
1
+ import{r as _,j as N,B as xe,ds as lt,gB as ut,gC as dt,cb as ft,i as ve,cZ as yt,n as ye,bG as ht,d0 as mt}from"./index-DB2lVKuV.js";function Ge(t){let n=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(const c of t)n=Math.min(n,c.x-c.w/2),i=Math.max(i,c.x+c.w/2),r=Math.min(r,c.y-c.h/2),l=Math.max(l,c.y+c.h/2);return Number.isFinite(n)?{x0:n,y0:r,x1:i,y1:l}:null}const be=(t,n,r)=>t<n?n:t>r?r:t;function pt(t,n,r,{padding:i=.12,minZoom:l=.2,maxZoom:c=1.2}={}){const x=Math.max(1,t.x1-t.x0),w=Math.max(1,t.y1-t.y0),E=be(Math.min(n/(x*(1+i)),r/(w*(1+i))),l,c);return{z:E,x:n/2-(t.x0+t.x1)/2*E,y:r/2-(t.y0+t.y1)/2*E}}function xt(t,n,r=0){if(t===n){const h=t.x+t.w/2,p=t.y-t.h/2;return[{x:h-30,y:p},{x:h-30,y:p-26},{x:h+22,y:p-26},{x:h+22,y:t.y-6},{x:h,y:t.y-6}]}const i=r*8,l=t.x+t.w/2,c=t.y+be(i,-t.h/2+6,t.h/2-6),x=n.x-n.w/2,w=n.y+be(i,-n.h/2+6,n.h/2-6);if(x-l>=40){const h=(l+x)/2+i;return[{x:l,y:c},{x:h,y:c},{x:h,y:w},{x,y:w}]}const E=Math.max(t.y+t.h/2,n.y+n.h/2)+24+Math.abs(i),k=Math.min(t.y-t.h/2,n.y-n.h/2)-24-Math.abs(i),g=(c+w)/2,u=Math.abs(E-g)<=Math.abs(k-g)?E:k,f=l+24+Math.abs(i),y=x-24-Math.abs(i);return[{x:l,y:c},{x:f,y:c},{x:f,y:u},{x:y,y:u},{x:y,y:w},{x,y:w}]}function gt(t,n,r){const i=r.x-n.x,l=r.y-n.y,c=i*i+l*l,x=c?be(((t.x-n.x)*i+(t.y-n.y)*l)/c,0,1):0;return Math.hypot(t.x-(n.x+x*i),t.y-(n.y+x*l))}function wt(t,n){let r=Number.POSITIVE_INFINITY;for(let i=0;i<n.length-1;i++)r=Math.min(r,gt(t,n[i],n[i+1]));return r}function vt(t,n){return Math.abs(n.x-t.x)<=t.w/2&&Math.abs(n.y-t.y)<=t.h/2}class ie{cells=new Set;static CELL_W=12;static CELL_H=16;keys(n){const r=[],i=Math.floor(n.x0/ie.CELL_W),l=Math.floor(n.x1/ie.CELL_W),c=Math.floor(n.y0/ie.CELL_H),x=Math.floor(n.y1/ie.CELL_H);for(let w=i;w<=l;w++)for(let E=c;E<=x;E++)r.push(w*1e5+E);return r}isFree(n){return this.keys(n).every(r=>!this.cells.has(r))}reserve(n){for(const r of this.keys(n))this.cells.add(r)}}function bt(t,n,r,i,l){const c=t.slice(0,-1).map((u,f)=>({i:f,length:Math.hypot(t[f+1].x-u.x,t[f+1].y-u.y)})).sort((u,f)=>f.length-u.length);if(c.length===0)return null;const x=u=>({x0:u.x-n/2,x1:u.x+n/2,y0:u.y-r/2,y1:u.y+r/2}),w=u=>({x:(t[u].x+t[u+1].x)/2,y:(t[u].y+t[u+1].y)/2});for(const{i:u,length:f}of c){if(!l&&f<n*.7)break;const y=w(u);if(i.isFree(x(y)))return i.reserve(x(y)),y}if(!l)return null;const E=w(c[0].i),g=[-1,1,-1.6,1.6].map(u=>({x:E.x,y:E.y+u*(r+12)})).find(u=>i.isFree(x(u)))??E;return i.reserve(x(g)),g}const kt=t=>N.jsx(yt,{icon:t||null,className:"h-4 w-4"}),Mt='600 14px "DM Sans", system-ui, sans-serif',Et='400 11px "DM Sans", system-ui, sans-serif',St='500 9px "DM Sans", system-ui, sans-serif',Tt='500 11px "DM Sans", system-ui, sans-serif',he=18,Be=8;function qe(t){const n=getComputedStyle(t),r=(i,l)=>n.getPropertyValue(i).trim()||l;return{foreground:r("--foreground","#141414"),muted:r("--muted-foreground","#545454"),card:r("--card","#ffffff"),background:r("--background","#fcfcfb"),border:r("--border","#e7e4dc"),primary:r("--primary","#2f63e8"),mutedSurface:r("--muted","#f3f1ea")}}function ge(t,n,r){if(t.measureText(n).width<=r)return n;let i=0,l=n.length;for(;i<l;){const c=Math.ceil((i+l)/2);t.measureText(`${n.slice(0,c)}…`).width<=r?i=c:l=c-1}return`${n.slice(0,i)}…`}function _t(t,n,r,i){const l=Math.hypot(r.x-n.x,r.y-n.y);if(l<1)return;const c=(r.x-n.x)/l,x=(r.y-n.y)/l;t.moveTo(r.x-c*i-x*i*.55,r.y-x*i+c*i*.55),t.lineTo(r.x,r.y),t.lineTo(r.x-c*i+x*i*.55,r.y-x*i-c*i*.55)}function tn({boxes:t,edges:n,label:r,onOpenBox:i,openLabel:l,onConnect:c,renderIcon:x=kt,className:w}){const E=_.useRef(null),k=_.useRef(null),g=_.useRef(null),u=_.useRef({z:1,x:0,y:0}),f=_.useRef({w:0,h:0,dpr:1}),y=_.useRef(!0),h=_.useRef(new Map),p=_.useRef(null),L=_.useRef(null),O=_.useRef(new Map),C=_.useRef(null),A=_.useRef(""),q=_.useRef(!1),[a,I]=_.useState(()=>new Map),[S,$]=_.useState(null),[Y,R]=_.useState(null),[j,Q]=_.useState(null),[B,Oe]=_.useState(null),[Je,Ze]=_.useState(0),{placed:U,movedIds:me}=_.useMemo(()=>{const o=new Map,e=new Set;for(const s of t){const d=a.get(s.id);d&&d.from.x===s.x&&d.from.y===s.y?(o.set(s.id,{...s,x:d.at.x,y:d.at.y}),e.add(s.id)):o.set(s.id,s)}return{placed:o,movedIds:e}},[t,a]),re=_.useMemo(()=>{const o=new Map;for(const s of n){const d=[s.source,s.target].sort().join("|");o.set(d,[...o.get(d)??[],s])}const e=new Map;for(const s of n){const d=U.get(s.source),v=U.get(s.target);if(!d||!v)continue;if(s.route&&!me.has(d.id)&&!me.has(v.id)){e.set(s.id,s.route);continue}const b=o.get([s.source,s.target].sort().join("|"))??[s];e.set(s.id,xt(d,v,b.indexOf(s)-(b.length-1)/2))}return e},[n,U,me]),F=_.useCallback(()=>{y.current=!0},[]),ce=_.useCallback(()=>{const o=Ge([...U.values()]),{w:e,h:s}=f.current;!o||!e||!s||(u.current=pt(o,e,s),q.current=!0,F())},[U,F]),ae=o=>{u.current=o,q.current=!1,F()},Ce=o=>{const e=Ge(o),{w:s,h:d}=f.current;if(!e||!s||!d)return;const v=u.current,b=24;e.x0*v.z+v.x>=b&&e.y0*v.z+v.y>=b&&e.x1*v.z+v.x<=s-b&&e.y1*v.z+v.y<=d-b||ae({...v,x:s/2-(e.x0+e.x1)/2*v.z,y:d/2-(e.y0+e.y1)/2*v.z})},Qe=o=>{Oe(o);const e=U.get(o);e&&Ce([e])},se=t.map(o=>`${o.id}@${Math.round(o.x)},${Math.round(o.y)}`).join(";");_.useEffect(()=>{!se||A.current===se||f.current.w&&(A.current=se,ce())},[se,ce]);const Ae=_.useRef(ce);Ae.current=ce;const Pe=_.useRef(se);Pe.current=se,_.useEffect(()=>{const o=E.current,e=k.current;if(!o||!e||typeof ResizeObserver>"u")return;const s=()=>{const v=window.devicePixelRatio||1,b=o.clientWidth,H=o.clientHeight;f.current={w:b,h:H,dpr:v},e.width=Math.round(b*v),e.height=Math.round(H*v);const W=Pe.current;W&&b&&H&&(A.current!==W||q.current)&&(A.current=W,Ae.current()),F()};s();const d=new ResizeObserver(s);return d.observe(o),()=>d.disconnect()},[F]);const[et,tt]=_.useState(0);_.useEffect(()=>{const o=g.current,e=k.current;if(!o||!e)return;const s=qe(e).muted;for(const d of o.querySelectorAll("[data-icon-key]")){const v=d.dataset.iconKey??"";if(h.current.has(v))continue;const b=d.querySelector("svg"),H=b?null:d.querySelector("img")?.src;if(!b&&!H){h.current.set(v,d.textContent??"");continue}const W=new Image;if(W.onload=F,W.onerror=()=>{h.current.delete(v),tt(T=>T+1)},b){const T=b.cloneNode(!0);T.getAttribute("width")||T.setAttribute("width","24"),T.getAttribute("height")||T.setAttribute("height","24");const M=new XMLSerializer().serializeToString(T).replaceAll("currentColor",s);W.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(M)}`}else H&&(W.src=H);h.current.set(v,W)}},[t,Je,et,F]);const le=(o,e)=>{const s=u.current;return{x:(o-s.x)/s.z,y:(e-s.y)/s.z}},ke=(o,e)=>{const s=u.current,d=le(o,e),v=S&&S.kind!=="edge"?U.get(S.box.id):void 0;if(v&&c){const T=Ke(v);if(Math.hypot(T.x*s.z+s.x-o,T.y*s.z+s.y-e)<=Be+3)return{kind:"handle",box:v}}const b=[...U.values()];for(let T=b.length-1;T>=0;T--)if(vt(b[T],d))return{kind:"box",box:b[T]};let H=null,W=7/s.z;for(const T of n){const M=re.get(T.id);if(!M)continue;const V=wt(d,M);V<W&&(W=V,H=T)}return H?{kind:"edge",edge:H}:null},ee=_.useMemo(()=>{const o=new Set;for(const s of[Y,j])s&&o.add(s);S?.kind==="edge"&&o.add(S.edge.id);const e=S&&S.kind!=="edge"?S.box.id:B;if(e)for(const s of n)(s.source===e||s.target===e)&&o.add(s.id);for(const s of n)s.dimmed&&o.delete(s.id);return o},[n,S,Y,j,B]);_.useEffect(F,[U,re,ee,S,B,F]);const ze=_.useCallback(()=>{const o=k.current,e=o?.getContext("2d");if(!o||!e)return;const{w:s,h:d,dpr:v}=f.current,b=qe(o),H=getComputedStyle(o),W=new Map,T=m=>{let P=W.get(m);return P===void 0&&(P=H.getPropertyValue(m).trim(),W.set(m,P)),P},{z:M,x:V,y:X}=u.current,ue=m=>({x:m.x*M+V,y:m.y*M+X});e.setTransform(v,0,0,v,0,0),e.clearRect(0,0,s,d);const Se=S&&S.kind!=="edge"?S.box.id:null;e.lineJoin="round";for(const m of n){const P=re.get(m.id);if(!P)continue;const z=P.map(ue),D=ee.has(m.id);e.globalAlpha=m.dimmed?.15:D?.95:.55,e.strokeStyle=m.accent?T(m.accent):D?b.foreground:b.muted,e.lineWidth=D?1.75:1.25,e.beginPath(),e.moveTo(z[0].x,z[0].y);for(const G of z.slice(1))e.lineTo(G.x,G.y);m.directed&&_t(e,z[z.length-2],z[z.length-1],8),e.stroke()}const $e=new ie;for(const m of U.values()){const P=ue(m),z=m.w*M,D=m.h*M,G=P.x-z/2,K=P.y-D/2;if($e.reserve({x0:G,y0:K,x1:G+z,y1:K+D}),G>s||K>d||G+z<0||K+D<0)continue;const de=Se===m.id||C.current?.over?.id===m.id;e.globalAlpha=m.dimmed?.25:1,e.beginPath(),e.roundRect(G,K,z,D,8*M),e.fillStyle=m.muted?b.mutedSurface:b.card,e.fill(),e.lineWidth=de||B===m.id?1.5:1,e.strokeStyle=de||B===m.id?b.primary:b.border,e.stroke();const fe=m.accent&&T(m.accent);if(fe&&(e.save(),e.clip(),e.fillStyle=fe,e.fillRect(G,K,3*M,D),e.restore()),14*M<5)continue;const te=12*M,J=16*M,ne=m.meta?K+D/2-8*M:K+D/2,oe=h.current.get(m.icon??"");oe instanceof HTMLImageElement&&oe.complete&&oe.naturalWidth>0?e.drawImage(oe,G+te,ne-J/2,J,J):typeof oe=="string"&&oe&&(e.font=`${14*M}px system-ui, sans-serif`,e.textBaseline="middle",e.textAlign="left",e.fillText(oe,G+te,ne));const pe=G+te+J+8*M,We=12*M;e.textBaseline="middle",e.textAlign="left";let Ie=G+z-We-pe;if(m.badge){e.font=St.replace("9px",`${9*M}px`);const Fe=ge(e,m.badge.toUpperCase(),Ie*.35),Ne=e.measureText(Fe).width+8*M,He=G+z-We-Ne;e.strokeStyle=b.border,e.lineWidth=1,e.beginPath(),e.roundRect(He,ne-7*M,Ne,14*M,3*M),e.stroke(),e.fillStyle=b.muted,e.fillText(Fe,He+4*M,ne+.5),Ie-=Ne+6*M}e.font=Mt.replace("14px",`${14*M}px`),e.fillStyle=b.foreground,e.fillText(ge(e,m.title,Ie),pe,ne+.5),m.meta&&(e.font=Et.replace("11px",`${11*M}px`),e.fillStyle=b.muted,e.fillText(ge(e,m.meta,G+z-te-pe),pe,K+D/2+10*M))}const Te=C.current,_e=Te?.from??(Se?U.get(Se):void 0);if(c&&_e&&_e.w*M>=60){const m=ue(Ke(_e));if(e.globalAlpha=1,Te){const P=ue(Te.to);e.strokeStyle=b.primary,e.lineWidth=2,e.setLineDash([6,4]),e.beginPath(),e.moveTo(m.x,m.y),e.lineTo(P.x,P.y),e.stroke(),e.setLineDash([])}e.fillStyle=b.card,e.strokeStyle=b.primary,e.lineWidth=1.5,e.beginPath(),e.arc(m.x,m.y,Be,0,Math.PI*2),e.fill(),e.stroke(),e.beginPath(),e.moveTo(m.x-4,m.y),e.lineTo(m.x+4,m.y),e.moveTo(m.x,m.y-4),e.lineTo(m.x,m.y+4),e.stroke()}e.font=Tt,e.textAlign="center",e.textBaseline="middle";const ct=(m,P,z,D)=>{e.globalAlpha=1,e.fillStyle=b.background,e.strokeStyle=z?b.foreground:b.border,e.lineWidth=1,e.beginPath(),e.roundRect(m.x-D/2,m.y-he/2,D,he,5),e.fill(),e.stroke(),e.fillStyle=z?b.foreground:b.muted,e.fillText(P,m.x,m.y+.5)},at=[...n].sort((m,P)=>Number(ee.has(P.id))-Number(ee.has(m.id)));for(const m of at){const P=re.get(m.id);if(!P||m.dimmed&&!ee.has(m.id))continue;const z=P.map(ue),D=ee.has(m.id),K=(D?m.details:[m.summary]).map(J=>ge(e,J,200)),de=Math.max(...K.map(J=>e.measureText(J).width))+14,fe=K.length*(he+2);if(!D&&M<.45)continue;const te=bt(z,de,fe,$e,D);te&&K.forEach((J,ne)=>{ct({x:te.x,y:te.y-fe/2+(he+2)*ne+he/2},J,D,de)})}e.globalAlpha=1},[n,re,U,ee,S,B,c]);_.useEffect(()=>{let o=0;const e=()=>{o=requestAnimationFrame(e),y.current&&(y.current=!1,ze())};return o=requestAnimationFrame(e),document.addEventListener("visibilitychange",F),()=>{cancelAnimationFrame(o),document.removeEventListener("visibilitychange",F)}},[ze,F]),_.useEffect(()=>{const o=new MutationObserver(()=>{h.current.clear(),Ze(e=>e+1),F()});return o.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),()=>o.disconnect()},[F]);const Me=(o,e,s)=>{const d=u.current,v=Math.min(3,Math.max(.15,d.z*o));ae({z:v,x:e-(e-d.x)*(v/d.z),y:s-(s-d.y)*(v/d.z)})},Ee=o=>{const e=k.current?.getBoundingClientRect();return{x:o.clientX-(e?.left??0),y:o.clientY-(e?.top??0)}},nt=o=>{if(o.button!==0&&o.pointerType==="mouse")return;o.currentTarget.setPointerCapture(o.pointerId);const e=Ee(o);if(o.pointerType==="touch"&&(O.current.set(o.pointerId,e),O.current.size===2)){const[v,b]=[...O.current.values()];p.current=null,C.current=null,L.current={d:Math.hypot(v.x-b.x,v.y-b.y)||1,mid:{x:(v.x+b.x)/2,y:(v.y+b.y)/2}};return}const s=ke(e.x,e.y),d={start:e,last:e,hit:s,moved:!1};if(s?.kind==="handle")C.current={from:s.box,to:le(e.x,e.y),over:null};else if(s?.kind==="box"){const v=le(e.x,e.y);d.grab={x:s.box.x-v.x,y:s.box.y-v.y}}p.current=d},ot=o=>{const e=Ee(o);O.current.has(o.pointerId)&&O.current.set(o.pointerId,e);const s=L.current;if(s&&O.current.size===2){const[T,M]=[...O.current.values()],V=Math.hypot(T.x-M.x,T.y-M.y)||1,X={x:(T.x+M.x)/2,y:(T.y+M.y)/2};ae({...u.current,x:u.current.x+X.x-s.mid.x,y:u.current.y+X.y-s.mid.y}),Me(V/s.d,X.x,X.y),L.current={d:V,mid:X};return}const d=p.current;if(!d){const T=ke(e.x,e.y);$(V=>It(V,T)?V:T);const M=k.current;M&&(M.style.cursor=T?.kind==="handle"?"crosshair":T?"pointer":"grab");return}const v=e.x-d.last.x,b=e.y-d.last.y;if(d.last=e,!d.moved&&Math.hypot(e.x-d.start.x,e.y-d.start.y)>4&&(d.moved=!0),!d.moved)return;const H=C.current;if(H){H.to=le(e.x,e.y);const T=ke(e.x,e.y);H.over=T?.kind==="box"?T.box:null,F();return}const W=d.hit;if(W?.kind==="box"&&d.grab){const T=le(e.x,e.y),M=t.find(X=>X.id===W.box.id);if(!M)return;const V={x:T.x+d.grab.x,y:T.y+d.grab.y};I(X=>new Map(X).set(M.id,{at:V,from:{x:M.x,y:M.y}}));return}ae({...u.current,x:u.current.x+v,y:u.current.y+b}),k.current&&(k.current.style.cursor="grabbing")},rt=o=>{if(O.current.delete(o.pointerId),L.current){O.current.size<2&&(L.current=null),p.current=null;return}const e=p.current;p.current=null;const s=C.current;if(C.current=null,!e)return;if(k.current&&(k.current.style.cursor="grab"),s){F(),s.over&&c&&c(s.from.id,s.over.id);return}if(e.moved)return;const d=e.hit;d?.kind==="box"?i(d.box.id):d?.kind==="edge"?R(v=>v===d.edge.id?null:d.edge.id):R(null)},st=o=>{O.current.delete(o.pointerId),L.current=null,p.current=null,C.current=null,F()};_.useEffect(()=>{const o=k.current;if(!o)return;const e=s=>{s.preventDefault();const d=Ee(s);s.ctrlKey||s.metaKey?Me(Math.exp(-s.deltaY*(s.ctrlKey?.01:.002)),d.x,d.y):ae({...u.current,x:u.current.x-s.deltaX,y:u.current.y-s.deltaY})};return o.addEventListener("wheel",e,{passive:!1}),()=>o.removeEventListener("wheel",e)});const De=o=>Me(o,f.current.w/2,f.current.h/2),it=[...new Set(t.map(o=>o.icon??""))];return N.jsxs("div",{ref:E,className:ve("relative h-full w-full overflow-hidden",w),children:[N.jsx("canvas",{ref:k,"aria-hidden":"true",className:"block h-full w-full cursor-grab touch-none",onPointerDown:nt,onPointerMove:ot,onPointerUp:rt,onPointerCancel:st,onPointerLeave:()=>{p.current||$(null)}}),N.jsxs("ul",{ref:g,"aria-label":r,className:"sr-only",children:[it.map(o=>N.jsx("li",{"aria-hidden":"true","data-icon-key":o,children:x(o)},`icon:${o}`)),t.map(o=>N.jsx("li",{children:N.jsx("button",{type:"button",onClick:()=>i(o.id),onFocus:()=>Qe(o.id),onBlur:()=>Oe(null),children:l(o)})},o.id)),n.map(o=>N.jsx("li",{"data-revealed":ee.has(o.id)||void 0,children:N.jsx("button",{type:"button","aria-pressed":Y===o.id,onClick:()=>R(e=>e===o.id?null:o.id),onFocus:()=>{Q(o.id);const e=re.get(o.id);e&&Ce(e.map(s=>({...s,w:0,h:0})))},onBlur:()=>Q(null),children:o.ariaLabel})},o.id))]}),N.jsxs("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:[N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom in",onClick:()=>De(1.25),children:N.jsx(lt,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom out",onClick:()=>De(.8),children:N.jsx(ut,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Fit to view",onClick:ce,children:N.jsx(dt,{className:"h-3.5 w-3.5"})}),me.size>0?N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Reset layout",onClick:()=>I(new Map),children:N.jsx(ft,{className:"h-3.5 w-3.5"})}):null]})]})}const Ke=t=>({x:t.x+t.w/2,y:t.y});function It(t,n){return!t||!n?t===n:t.kind==="edge"||n.kind==="edge"?t.kind==="edge"&&n.kind==="edge"&&t.edge.id===n.edge.id:t.kind===n.kind&&t.box.id===n.box.id}function nn({label:t,fill:n=!1}){return N.jsxs("div",{role:"status","aria-label":t,"aria-busy":"true",className:ve("flex min-w-0 flex-col gap-3",n&&"min-h-0 flex-1"),children:[N.jsx("div",{className:"flex min-w-0 items-center gap-3",children:N.jsx("div",{"aria-hidden":"true",className:"min-w-0 flex-1",children:N.jsx(ye,{className:"h-5 w-3/4 max-w-xl rounded-none"})})}),N.jsx("div",{className:ve("relative flex min-h-0 flex-col",n&&"flex-1"),"aria-hidden":"true",children:N.jsxs("div",{className:ve("relative min-h-[420px]",n?"flex-1":"h-[70vh]"),children:[N.jsxs("div",{className:"absolute top-1/2 left-1/2 flex h-16 w-52 -translate-x-1/2 -translate-y-1/2 items-center gap-3 rounded-xl border border-border bg-card px-4",children:[N.jsx(ye,{className:"h-4 w-4 shrink-0 rounded-none"}),N.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[N.jsx(ye,{className:"h-3.5 w-24 rounded-none"}),N.jsx(ye,{className:"h-2.5 w-32 rounded-none"})]})]}),N.jsx("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:["in","out","fit"].map(r=>N.jsx("div",{className:"flex h-7 w-7 items-center justify-center border border-input bg-background",children:N.jsx(ye,{className:"h-3 w-3 rounded-none"})},r))})]})})]})}function we(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Re={exports:{}},Ye;function Nt(){return Ye||(Ye=1,(function(t,n){(function(r){t.exports=r()})(function(){return(function(){function r(i,l,c){function x(k,g){if(!l[k]){if(!i[k]){var u=typeof we=="function"&&we;if(!g&&u)return u(k,!0);if(w)return w(k,!0);var f=new Error("Cannot find module '"+k+"'");throw f.code="MODULE_NOT_FOUND",f}var y=l[k]={exports:{}};i[k][0].call(y.exports,function(h){var p=i[k][1][h];return x(p||h)},y,y.exports,r,i,l,c)}return l[k].exports}for(var w=typeof we=="function"&&we,E=0;E<c.length;E++)x(c[E]);return x}return r})()({1:[function(r,i,l){Object.defineProperty(l,"__esModule",{value:!0}),l.default=void 0;function c(f){"@babel/helpers - typeof";return c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(y){return typeof y}:function(y){return y&&typeof Symbol=="function"&&y.constructor===Symbol&&y!==Symbol.prototype?"symbol":typeof y},c(f)}function x(f,y){if(!(f instanceof y))throw new TypeError("Cannot call a class as a function")}function w(f,y){for(var h=0;h<y.length;h++){var p=y[h];p.enumerable=p.enumerable||!1,p.configurable=!0,"value"in p&&(p.writable=!0),Object.defineProperty(f,k(p.key),p)}}function E(f,y,h){return y&&w(f.prototype,y),Object.defineProperty(f,"prototype",{writable:!1}),f}function k(f){var y=g(f,"string");return c(y)=="symbol"?y:y+""}function g(f,y){if(c(f)!="object"||!f)return f;var h=f[Symbol.toPrimitive];if(h!==void 0){var p=h.call(f,y);if(c(p)!="object")return p;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(f)}l.default=(function(){function f(){var y=this,h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},p=h.defaultLayoutOptions,L=p===void 0?{}:p,O=h.algorithms,C=O===void 0?["layered","stress","mrtree","radial","force","disco","sporeOverlap","sporeCompaction","rectpacking"]:O,A=h.workerFactory,q=h.workerUrl;if(x(this,f),this.defaultLayoutOptions=L,this.initialized=!1,typeof q>"u"&&typeof A>"u")throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");var a=A;typeof q<"u"&&typeof A>"u"&&(a=function($){return new Worker($)});var I=a(q);if(typeof I.postMessage!="function")throw new TypeError("Created worker does not provide the required 'postMessage' function.");this.worker=new u(I),this.worker.postMessage({cmd:"register",algorithms:C}).then(function(S){return y.initialized=!0}).catch(console.err)}return E(f,[{key:"layout",value:function(h){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},L=p.layoutOptions,O=L===void 0?this.defaultLayoutOptions:L,C=p.logging,A=C===void 0?!1:C,q=p.measureExecutionTime,a=q===void 0?!1:q;return h?this.worker.postMessage({cmd:"layout",graph:h,layoutOptions:O,options:{logging:A,measureExecutionTime:a}}):Promise.reject(new Error("Missing mandatory parameter 'graph'."))}},{key:"knownLayoutAlgorithms",value:function(){return this.worker.postMessage({cmd:"algorithms"})}},{key:"knownLayoutOptions",value:function(){return this.worker.postMessage({cmd:"options"})}},{key:"knownLayoutCategories",value:function(){return this.worker.postMessage({cmd:"categories"})}},{key:"terminateWorker",value:function(){this.worker&&this.worker.terminate()}}])})();var u=(function(){function f(y){var h=this;if(x(this,f),y===void 0)throw new Error("Missing mandatory parameter 'worker'.");this.resolvers={},this.worker=y,this.worker.onmessage=function(p){setTimeout(function(){h.receive(h,p)},0)}}return E(f,[{key:"postMessage",value:function(h){var p=this.id||0;this.id=p+1,h.id=p;var L=this;return new Promise(function(O,C){L.resolvers[p]=function(A,q){A?(L.convertGwtStyleError(A),C(A)):O(q)},L.worker.postMessage(h)})}},{key:"receive",value:function(h,p){var L=p.data,O=h.resolvers[L.id];O&&(delete h.resolvers[L.id],L.error?O(L.error):O(null,L.data))}},{key:"terminate",value:function(){this.worker&&this.worker.terminate()}},{key:"convertGwtStyleError",value:function(h){if(h){var p=h.__java$exception;p&&(p.cause&&p.cause.backingJsObject&&(h.cause=p.cause.backingJsObject,this.convertGwtStyleError(h.cause)),delete h.__java$exception)}}}])})()},{}],2:[function(r,i,l){var c=r("./elk-api.js").default;Object.defineProperty(i.exports,"__esModule",{value:!0}),i.exports=c,c.default=c},{"./elk-api.js":1}]},{},[2])(2)})})(Re)),Re.exports}var Rt=Nt();const jt=ht(Rt);function Lt(t){return new Worker("/assets/elk-worker.min-BENGc9gn.js",{name:t?.name})}const Ot=200,Ct=320,Xe=56,At=7.4,Pt=5.9,zt=84,Dt=48;function $t(t,n){return Math.round(Math.min(Ct,Math.max(Ot,zt+t.length*At,Dt+n.length*Pt)))}function Wt(t,n){const r=[];return t>0&&r.push(`${t} ${t===1?"field":"fields"}`),typeof n=="number"&&r.push(`${n.toLocaleString()} ${n===1?"record":"records"}`),r.join(" · ")}function Ue(t,n){return t.slug<n.slug?-1:t.slug>n.slug?1:0}function Ft(t,n){const r=new Set;return t.filter(i=>i.status!=="active"||i.organization_slug&&i.organization_slug!==n||r.has(i.slug)?!1:(r.add(i.slug),!0))}function Ht(t){const n=t.metadata_schema;if(!n||typeof n!="object")return 0;const r=n.properties;return!r||typeof r!="object"?0:Object.keys(r).length}function Gt(t){const{entityTypes:n,relationshipTypes:r,rulesBySlug:i}=t,l=t.ownerSlug??"",c=[...n].sort(Ue),x=Ft(r,l).sort(Ue),w=a=>!a.organization_slug||a.organization_slug===l,E=a=>a.organization_slug||l,k=new Map;for(const a of c)k.set(a.slug,[...k.get(a.slug)??[],a]);const g=a=>(k.get(a.slug)?.length??0)>1?`${E(a)}:${a.slug}`:a.slug,u=new Set(c.filter(w).map(g)),f=a=>{const I=k.get(a)??[];return I.find(w)??(I.length===1?I[0]:void 0)},y=new Set(u),h=x.flatMap(a=>[...i[a.slug]??[]].sort((I,S)=>I.id-S.id).flatMap(I=>{const S=f(I.source_entity_type_slug),$=f(I.target_entity_type_slug);if(!S||!$)return[];const Y=g(S),R=g($);return!u.has(Y)&&!u.has(R)?[]:(y.add(Y),y.add(R),[{rt:a,source:Y,target:R}])})),p=c.filter(a=>y.has(g(a))),L=[],O=new Map,C=new Map;for(const{rt:a,source:I,target:S}of h){const $=`${a.slug}|${I}|${S}`,Y=C.get($);if(Y){Y.ruleCount+=1;continue}const R={slug:a.slug,label:a.name||a.slug,ruleCount:1};C.set($,R);const j=`${I}|${S}`,Q=O.get(j);if(Q){Q.data.relationships.push(R),Q.data.isSymmetric=Q.data.isSymmetric&&a.is_symmetric;continue}const B={id:`pair:${I}|${S}`,source:I,target:S,data:{relationships:[R],isSymmetric:a.is_symmetric}};O.set(j,B),L.push(B)}const A=new Map;for(const{rt:a,source:I,target:S}of h){const $=A.get(a.slug)??new Set;$.add(`${I}|${S}`),A.set(a.slug,$)}for(const{rt:a}of h)if(A.get(a.slug)?.size===1&&typeof a.relationship_count=="number")for(const I of C.values())I.slug===a.slug&&(I.linkCount=a.relationship_count);return{nodes:p.map(a=>{const I=a.name||a.slug,S=Ht(a),$=Wt(S,a.entity_count);return{id:g(a),width:$t(I,$),height:Xe,data:{slug:a.slug,label:I,icon:a.icon,isSystem:mt(a),organizationSlug:w(a)?void 0:E(a),metaLabel:$}}}),edges:L}}const Z=24,Bt=72,qt=16,Kt=48,Yt=64,je=16,Ut=720;function Vt(t,n){const r=new Map(t.map(c=>[c.id,c.id])),i=c=>{const x=r.get(c)??c;if(x===c)return c;const w=i(x);return r.set(c,w),w};for(const c of n)r.set(i(c.source),i(c.target));const l=new Map;for(const c of t){const x=i(c.id);l.set(x,[...l.get(x)??[],c])}return[...l.values()].sort((c,x)=>x.length-c.length)}function Xt(t,n,r,i){const l=new Map(t.flatMap((g,u)=>g.map(f=>[f.id,u]))),c=t.map(()=>({top:1/0,bottom:-1/0})),x=(g,u,f)=>{const y=c[l.get(g)??0];y.top=Math.min(y.top,u),y.bottom=Math.max(y.bottom,f)};for(const g of n)x(g.id,g.position.y,g.position.y+g.height);for(const g of r)for(const u of i.get(g.id)??[])x(g.source,u.y,u.y);let w=Z;const E=c.map(({top:g,bottom:u})=>{const f=w-g;return w=u+f+Kt,f}),k=g=>E[l.get(g)??0];for(const g of r){const u=i.get(g.id);u&&i.set(g.id,u.map(f=>({x:f.x,y:f.y+k(g.source)})))}return n.map(g=>({...g,position:{x:g.position.x,y:g.position.y+k(g.id)}}))}function Jt(t,n){const r=Z,i=Math.max(r+Ut,...n.map(w=>w.position.x+w.width));let l=n.length>0?Math.max(...n.map(w=>w.position.y+w.height))+Yt:Z;const c=[...new Set(t.map(w=>w.lane??0))].sort((w,E)=>w-E),x=[];for(const w of c){let E=r,k=0;for(const g of t.filter(u=>(u.lane??0)===w))E>r&&E+g.width>i&&(E=r,l+=k+je,k=0),x.push({...g,position:{x:E,y:l}}),E+=g.width+je,k=Math.max(k,g.height);l+=k+je*2}return x}let Ve=null;function Zt(){return Ve??=new jt({workerFactory:()=>new Lt}),Ve}const Le={"elk.algorithm":"layered","elk.direction":"RIGHT","elk.edgeRouting":"ORTHOGONAL","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"24","elk.layered.spacing.nodeNodeBetweenLayers":"80","elk.spacing.nodeNode":"48","elk.spacing.edgeEdge":"14","elk.spacing.edgeNode":"24","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.crossingMinimization.semiInteractive":"true"};async function Qt(t,{elk:n=Zt(),targetAspect:r}={}){const i=new Set;for(const a of t.edges)i.add(a.source),i.add(a.target);const l=t.nodes.some(a=>a.lane!==void 0),c=t.nodes.filter(a=>i.has(a.id)),x=l?Vt(c,t.edges):[c],w=x.flat(),E=t.nodes.filter(a=>!i.has(a.id)),k=l?[]:E,g=l?E:[],u=k.reduce((a,I)=>Math.max(a,I.width),0),f=k.length>0?Z+u+Bt:0,y=a=>({x:a.x+Z+f,y:a.y+Z});let h=[];const p=new Map;if(w.length>0){const a=t.edges.filter(R=>R.source!==R.target),I=R=>n.layout({id:"root",layoutOptions:l?{...R,"elk.partitioning.activate":"true","elk.separateConnectedComponents":"false"}:R,children:w.map(j=>({id:j.id,width:j.width,height:j.height,...l?{layoutOptions:{"elk.partitioning.partition":String(j.lane??1)}}:{}})),edges:a.map(j=>({id:j.id,sources:[j.layoutReversed?j.target:j.source],targets:[j.layoutReversed?j.source:j.target]}))});let S=await I(Le);const $=r&&S.width&&S.height?r*S.width/S.height:1;if($>1.08){const R=Number(Le["elk.spacing.nodeNode"]),j=Math.min($,2.2);S=await I({...Le,"elk.spacing.nodeNode":String(Math.round(Math.min(180,R*j+Xe*(j-1))))})}const Y=new Map((S.children??[]).map(R=>[R.id,R]));h=w.map(R=>{const j=Y.get(R.id);return{...R,position:y({x:j?.x??0,y:j?.y??0})}});for(const R of S.edges??[]){const j=(R.sections??[]).flatMap(B=>[B.startPoint,...B.bendPoints??[],B.endPoint]);if(j.length<2)continue;const Q=t.edges.find(B=>B.id===R.id)?.layoutReversed;p.set(R.id,(Q?[...j].reverse():j).map(y))}}let L=Z;const O=k.map(a=>{const I={x:Z,y:L};return L+=a.height+qt,{...a,position:I}});l&&(h=Xt(x,h,t.edges,p));const C=Jt(g,h),A=new Map([...h,...O,...C].map(a=>[a.id,a]));return{nodes:t.nodes.map(a=>A.get(a.id)??{...a,position:{x:Z,y:Z}}),edges:t.edges.map(a=>({...a,route:p.get(a.id)??null}))}}function on(t,n){return Qt(Gt(t),n)}export{nn as G,Xe as H,on as a,Gt as b,tn as c,Qt as l,$t as n,Ft as s};
2
+ //# sourceMappingURL=entity-schema-graph-B255NKjF.js.map
@@ -0,0 +1,2 @@
1
+ import{P as $,cJ as de,dG as ue,cM as K,j as e,bZ as me,r as h,cK as xe,cL as he,aM as pe,aN as ge,B as g,ds as V,aP as fe,$ as S,bz as q,bA as P,bB as M,bC as L,bD as k,a0 as E,an as je,i6 as ve,i7 as Ne,a8 as Y,dd as ye,X as W,c_ as be,C as we,ac as Se,cj as ae,g2 as ne,i8 as Ce,a9 as re,i9 as ke,hF as Ee,cd as _e,ce as G,ci as Re,fO as Te,b_ as Oe,ia as De,i as Z,ev as Ae,fH as Fe,fI as ze,L as le,dl as qe,fJ as Pe,A as Me}from"./index-DB2lVKuV.js";import{f as U}from"./event-kind-options-fHAIXu24.js";import{C as ie}from"./code-editor-CTdKUDPY.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!==K),d=i.filter(u=>u.purpose===K),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(Je,{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(W,{className:"h-3 w-3"})})})]})}function Je({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(""),[R,T]=h.useState(""),[D,O]=h.useState(!1),[A,C]=h.useState(null),m=xe(),p=he(),j=()=>{d("existing"),u(""),b(""),y("source"),f(""),T(""),O(!1),C(null)},_=l=>{i(l),l||j()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),J=async()=>{C(null);try{let l=x;if(c==="new"){if(!v.trim()){C("Name is required");return}const H=R.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),R||T("")}}),e.jsx(E,{placeholder:v?F(v)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:R,onChange:l=>T(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:J,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({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(W,{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(W,{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 We({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(Ue,{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 Q({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 X(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 Ke({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)),X(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]),R=h.useCallback(m=>{i(m),f(m,c)},[f,c]),T=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)),X(p)?(i(ee(p)),y(!1)):y(!0),a(p)}catch(p){b(p instanceof Error?p.message:"Invalid JSON")}},[a]),O=()=>{R([...t,{id:ce(),name:"",type:"string",required:!1}])},A=(m,p)=>{const j=[...t];j[m]=p,R(j)},C=m=>{R(t.filter((p,j)=>j!==m))};return o?e.jsx(Q,{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(We,{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=>T(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(Q,{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,R]=c.field("color"),[T,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))},J=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:T,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:T,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(Re,{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(Te,{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=>R(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(Ke,{value:T,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:J,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:Z("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:Z("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:y}),t&&o.slug&&s?e.jsx(Ze,{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(Qe,{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 Ze({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 Qe({owner:s,entityType:a}){const o=Object.entries(a.event_kinds??{}).sort(([n],[r])=>U(n).localeCompare(U(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:U(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-CGBAP2wt.js.map
@@ -0,0 +1,2 @@
1
+ import{H as v,o as g,dW as y,dX as b}from"./index-DB2lVKuV.js";function I(t){const{isAuthenticated:e,isReady:n}=v(),{isMember:i,isLoading:o}=g(),r=t==="me";return{canManageWorkspace:!r&&n&&e&&i,canReadPublicWorkspace:!r&&n&&(!e||!o&&!i)}}function A(t,e){const{org:n}=g(t),{canManageWorkspace:i,canReadPublicWorkspace:o}=I(t),r={contentIds:[e]},c=y(i?n?.id??null:null,void 0,r,t),s=b(o?t:null,void 0,r),{data:a,isPending:u,isError:f}=o?s:c;if(f)return{status:"failed",event:null};if(u)return{status:"loading",event:null};const l=a?.pages[0]?.content.find(h=>Number(h.id)===e);return l?{status:"ready",event:l}:{status:"missing",event:null}}const d="source-";function _(t){return`${d}${t}`}function E(t){if(!t.startsWith(d))return null;const e=t.slice(d.length),n=Number(e);return Number.isSafeInteger(n)&&n>=0&&String(n)===e?n:null}function R(t){if(!t||typeof t!="object"||Array.isArray(t))return;const{operation:e,input:n}=t;if(!(typeof e!="string"||!e||!n||typeof n!="object"||Array.isArray(n)||!Object.values(n).every(o=>typeof o=="string"||typeof o=="number"&&Number.isFinite(o))))return{operation:e,input:n}}const F=[".png",".jpg",".jpeg",".gif",".webp",".avif",".bmp",".svg"];function m(t,e){const n=t.toLowerCase();return e.some(i=>n.endsWith(i))}function p(t){if(typeof t!="string"||!URL.canParse(t))return;const{protocol:e}=new URL(t);return e==="https:"||e==="http:"?t:void 0}function W(t){if(!t)return;const e=new URL(t).pathname.split("/").filter(Boolean).at(-1);if(e)try{return decodeURIComponent(e)}catch{return e}}function S(t){if(!(typeof t!="number"||!Number.isFinite(t)||t<=0))return t<1024?`${t} B`:t<1024*1024?`${Math.round(t/1024)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function N(t,e){if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t,i=p(n.download_url)??p(n.url),r=(typeof n.filename=="string"&&n.filename.trim()?n.filename.trim():void 0)??W(i);if(!r)return null;const c=typeof n.mime_type=="string"?n.mime_type:"",s=typeof n.artifact_id=="string"&&n.artifact_id?n.artifact_id:void 0,a=s?void 0:R(n.open);return{name:r,url:i,artifactId:s,...a?{open:a}:{},fileKey:s??(a?_(e):void 0),size:S(n.size_bytes),isImage:c.startsWith("image/")||!c&&(n.kind==="image"||m(r,F)),isPdf:c==="application/pdf"||!c&&m(r,[".pdf"])}}function j(t,e,n){const i=A(t,e);if(i.status!=="ready")return{status:i.status,attachment:null};const{event:o}=i,r=Array.isArray(o.attachments)?o.attachments:[],s=E(n)??r.findIndex(f=>!!f&&typeof f=="object"&&f.artifact_id===n),a=s>=0&&s<r.length?N(r[s],s):null;if(!a||a.fileKey!==n)return{status:"missing",attachment:null};const u=Number(o.connection_id);return{status:"ready",attachment:a,connectionId:Number.isSafeInteger(u)&&u>0?u:null}}export{j as a,I as b,N as t,A as u};
2
+ //# sourceMappingURL=event-attachments-D8Z8uwv9.js.map
@@ -0,0 +1,2 @@
1
+ import{H as Q,ae as q,gP as I,r as B,gQ as J,f4 as W,j as s,cr as M,L as X}from"./index-DB2lVKuV.js";import{E as Y}from"./events-feed-ClhEywwV.js";import{b as Z,a as z,V as K,M as ee}from"./view-param-filters-CvrKw0mZ.js";const se={},te="calc(100dvh - 120px)";function ie({owner:a,organizationId:o,eventId:c,viewKey:r,params:p,onParamsChange:d,onSelectView:g,dense:h=!1,fullBleed:k=!1}){const{isAuthenticated:y,isReady:E}=Q(),{data:P,isLoading:w}=q(),O=P?.some(t=>t.id===o&&t.is_member),i=a!=="me"&&o!==null&&E&&y&&!w&&O,n=I(i?{slug:a,organizationId:o}:null,c),[j,L]=B.useState(se),[T,b]=B.useState(null),m=J(n.views,r),e=i&&!n.isLoading&&!n.isError&&m.kind==="view"?m.view:null,v=e?`${W(a,e.key)}/${e.content_hash}/${e.eventId}`:null,x=e!==null&&T===v,V=M(a,c),F=a!=="me"&&(!E||y&&(w||n.isLoading)),H=e!==null&&!x&&!F,u=k&&H,U=(k||h)&&H,N=F?s.jsx("div",{role:"status",className:"py-8 text-sm text-muted-foreground",children:"Loading event view…"}):e&&!x?s.jsxs(s.Fragment,{children:[s.jsx(Z,{decls:e.params,params:p??j,onParamsChange:t=>d?d(e.key,t,{replace:!1}):L(t)}),s.jsx(z,{orgSlug:a,viewKey:e.key,scope:{event:e.eventId},params:p??j,onParamsChange:t=>d?d(e.key,t):L(t),paramDecls:e.params,onLoadError:()=>b(v),contentHash:e.content_hash,title:e.name,minHeight:h?240:320,fixedHeight:U?te:void 0},v)]}):void 0;return s.jsxs("div",{className:u?"w-full space-y-3":"mx-auto w-full max-w-3xl space-y-3",...u?{"data-testid":"event-view-fullbleed"}:{},children:[i&&n.isError&&s.jsx(K,{onRetry:n.refetch}),(i||a==="me"&&r)&&!n.isLoading&&!n.isError&&m.kind==="missing"&&s.jsx(ee,{viewKey:m.key,backTo:V,backLabel:"Back to the event"}),x&&s.jsxs("div",{role:"alert",className:"rounded-md border p-3 text-sm",children:[s.jsx("p",{children:"The custom view couldn’t load. The event content is shown below."}),s.jsx("button",{type:"button",className:"mt-2 underline",onClick:()=>b(null),children:"Retry custom view"})]}),s.jsx(Y,{presentation:"detail",organizationId:o,ownerSlug:a,filters:{contentIds:[c],...a==="me"?{sortBy:"date",sortOrder:"desc"}:{}},hideDetails:h,renderDetail:t=>{const f=N!=null&&(t==null||!!r),A=(i?n.views:[]).filter(l=>!f||l.key!==e?.key).map(l=>({key:l.key,name:l.name,href:M(a,c,l.key)})),D=l=>l.length?s.jsx("nav",{"aria-label":"Event views",className:"flex flex-wrap gap-3 text-sm",children:l.map(({key:$,name:C,href:_})=>s.jsx(X,{to:_,className:"underline",onClick:g?G=>{G.preventDefault(),g(_)}:void 0,children:C},$))}):null,R=[...A],S=[...A];return i&&r&&t!=null&&S.unshift({key:":event",name:"Event details",href:V}),{content:f?N:t,nativeHeading:!f&&t!=null,headingAside:u?D(R):void 0,links:u?null:D(S)}}})]})}export{ie as E};
2
+ //# sourceMappingURL=event-detail-CgG3pDLA.js.map
@@ -0,0 +1,2 @@
1
+ import{j as t,fd as An,fe as Cn,y as Fe,eT as Rn,eU as Sn,dT as je,ff as In,u as Pe,fg as $n,fh as Tn,ah as En,a5 as Mn,dV as On,fi as Fn,i as ie,dd as Tt,fj as mt,r as v,fk as zt,fl as Dn,z as qt,bX as Pn,H as He,P as Ht,fm as Ln,cT as Vt,c3 as Bn,c4 as Un,c5 as Kn,K as Se,bH as Oe,eL as zn,a8 as ee,fn as Et,fo as Ze,L as te,bn as ze,bo as et,fp as qn,cF as Hn,fq as Vn,fr as Wn,dn as Wt,fs as Qn,ft as Jn,aX as Gn,eQ as Yn,cH as Xn,s as Zn,fu as es,fv as jt,T as ts,fw as Qt,fx as Jt,fy as tt,cr as Gt,fz as ns,fA as Yt,fB as ss,fC as Mt,eN as rs,fD as as,fE as Xt,fF as Zt,fG as is,aM as en,aN as tn,B as M,aP as nn,fH as os,fI as ls,ad as sn,fJ as cs,fK as pt,c_ as ft,fL as rn,fM as an,dp as _t,c as ds,Q as us,eP as xt,fN as ms,a0 as ps,fO as fs,b_ as xs,an as ye,f7 as hs,fP as gs,fQ as ys,fR as vs,fS as js,cd as _s,fT as bs,ci as Ns,fU as ws,aa as ks,X as As,fV as Cs,cj as Rs,fW as Ss,fX as Is,fY as $s,eD as Ts,dq as Es,v as Ms,fZ as Os,f_ as Fs,ek as De,f$ as on,g0 as Ds,g1 as Ps,g2 as Ls,g3 as Bs,g4 as Us,g5 as Ks,g6 as zs,o as qs,cW as Hs,eo as Vs,cU as Ws,t as Qs,dW as Js,dX as Gs,g7 as Ys,g8 as Xs,g9 as Zs,ga as Ot,gb as er,gc as tr,gd as nr,c9 as sr,eM as Ve,ge as rr,gf as ar,gg as ir}from"./index-DB2lVKuV.js";import{t as ln,b as or}from"./event-attachments-D8Z8uwv9.js";import{D as lr,a as cr,A as dr,T as ur,b as mr,c as pr,d as fr}from"./definition-comparison-C2mPfIMD.js";import{R as xr,p as hr,a as gr,i as yr,b as vr}from"./run-initiator-C0sur8lU.js";import{a as cn}from"./use-automations-DcdlmVuX.js";import{i as jr,r as _r,s as br,J as Nr}from"./renderer-B8yZ5lql.js";import{S as wr}from"./schema-value-DDNHANGs.js";import{J as Xe}from"./json-diff-Ce6YAXzY.js";import{A as Ft}from"./device-automation-Dp3faMvp.js";const kr=({name:e,url:n,imageSrc:s,size:r,onOpen:a})=>{if(s)return t.jsx("a",{href:n??s,target:"_blank",rel:"noreferrer",children:t.jsx("img",{src:s,alt:e,className:"max-h-64 rounded-lg border object-contain"})});const i=t.jsxs(t.Fragment,{children:[t.jsx(Cn,{className:"h-3 w-3 shrink-0"}),t.jsx("span",{className:"max-w-[14rem] truncate",children:e}),r?t.jsx("span",{className:"shrink-0 text-muted-foreground",children:r}):null]}),o="flex min-w-0 items-center gap-1.5 hover:underline";return t.jsxs("div",{className:"flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs",children:[a?t.jsx("button",{type:"button",onClick:a,className:o,children:i}):n?t.jsx("a",{href:n,target:"_blank",rel:"noreferrer",className:o,children:i}):i,a&&n?t.jsx("a",{href:n,target:"_blank",rel:"noreferrer","aria-label":`Download ${e}`,className:"text-muted-foreground hover:text-foreground",children:t.jsx(An,{className:"h-3 w-3"})}):null]})};function Ar(e,n){const s=Fe({queryKey:["available-operations",e,n,"source-files"],queryFn:async()=>(await je("manage_operations",{action:"list_available",connection_id:n,include_input_schema:!1,include_output_schema:!1,limit:In,offset:0},{slug:e})).operations??[],enabled:n!==null,staleTime:3e4}),r=a=>s.data?.find(i=>i.operation_key===a&&i.kind==="read");return{isPending:n!==null&&s.isPending,isError:s.isError,find:r,canRead:a=>r(a)!==void 0}}function Dt(e){const n=Array.isArray(e?.attachments)?e.attachments:[];for(const[s,r]of n.entries()){const a=ln(r,s);if(a?.url)return a}return null}const Pt="The source returned no file to show.";function ji(e,n,s,r){const a=Fe({queryKey:["source-file",e,n,s],queryFn:()=>je("manage_operations",{action:"execute",connection_id:r?.connectionId,operation_key:r?.open.operation,input:r?.open.input},{slug:e}),enabled:r!==null,retry:!1,staleTime:Number.POSITIVE_INFINITY,gcTime:18e5,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),i=a.data,o=i?.run_id&&(i.status==="pending_approval"||i.status==="in_progress")?i.run_id:null,l=Rn(e,o);if(r===null)return{status:"idle"};if(a.isError)return{status:"failed",message:a.error instanceof Error?a.error.message:"The source could not be reached."};if(!i)return{status:"loading"};if(i.error)return{status:"failed",message:i.error};if(i.status==="completed"){const c=Dt(i.output);return c?{status:"ready",file:c}:{status:"failed",message:Pt}}if(o!==null){const c=l.data;if(!c||Sn(c.status))return{status:"waiting",runId:o,approval:c?.approval_status==="pending"||!c&&i.status==="pending_approval"};if(c.approval_status==="rejected")return{status:"declined",runId:o};if(c.status==="completed"){const d=Dt(c.output);return d?{status:"ready",file:d}:{status:"failed",message:Pt}}return{status:"failed",message:c.error_message||"The source could not return this file."}}return{status:"failed",message:i.error_message||i.message||"The source could not return this file."}}function Cr({attachments:e,owner:n,eventId:s,connectionId:r}){const a=Array.isArray(e)?e.flatMap((i,o)=>ln(i,o)??[]):[];return a.length===0?null:n&&s&&Number.isSafeInteger(s)&&s>0?t.jsx(Rr,{items:a,owner:n,eventId:s,connectionId:r??null}):t.jsx(dn,{items:a})}function Rr({items:e,owner:n,eventId:s,connectionId:r}){const a=Pe(),i=Ar(n,e.some(o=>o.open)?r:null);return t.jsx(dn,{items:e,canOpen:o=>o.open?i.canRead(o.open.operation):o.isPdf&&!!o.url,openFile:a?(o,l)=>a.open({href:$n(n,s,l),title:o.name}):void 0})}function dn({items:e,canOpen:n,openFile:s}){return t.jsx("ul",{"aria-label":"Attachments",className:"mt-3 flex flex-wrap gap-2",children:e.map((r,a)=>{const i=r.fileKey,o=s&&i&&n?.(r)?()=>s(r,i):void 0;return t.jsx("li",{children:t.jsx(kr,{name:r.name,url:r.url,size:r.size,imageSrc:r.isImage?r.url:void 0,onOpen:o})},a)})})}function un(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 mn(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 _i(e){const n=un(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:mn(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 ot(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Sr(e){const n=ot(e.proposal);if(!n)return null;const s=ot(e.current);if(e.tool==="manage_agents"){if(!["create","update","delete"].includes(String(n.action)))return null;const r=Tn({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=ot(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:o,...l}=r;return{kind:"automation",current:a==="create"?null:s,proposed:{...a==="create"?null:s,...l}}}return null}function Ir({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(lr,{current:e.current,proposed:e.proposed,render:n=>e.kind==="agent"?t.jsx(cr,{value:n}):t.jsx(dr,{value:n})})]})}async function $r(e,n,s,r){const a=await En(`${Mn}/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 On(a,"Could not record interaction"),a.json()}function V(e){if(typeof e!="string")return;const n=e.trim();return n.length>0?n:void 0}function lt(e){return typeof e=="boolean"?e:void 0}function Tr(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"||V(n?.reason_preview)&&V(n?.message)||V(e?.body)&&(V(e?.post_url)||V(e?.activity_id)))}function Er(e,n,s){if(!Tr(e,n,s))return null;const r=(s??"").toLowerCase(),a=V(n?.body)??V(e?.body),i=V(n?.reason_preview)??V(e?.reason),o=V(n?.post_url)??V(e?.post_url)??(V(e?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${V(e?.activity_id)}`:void 0),l=lt(n?.prepared),c=lt(n?.verified),d=lt(n?.banner_shown),p=V(n?.message),u=n?.match&&typeof n.match=="object"?n.match:null,m=V(u?.text_preview),_=V(u?.author);let w="generic";r==="verify_staged_comment"||r.includes("verify")||typeof c=="boolean"?w="verify":(r==="prepare_comment"||r.includes("prepare")||l===!0||a&&o)&&(w="prepare");const h=[];return l===!0&&h.push("Staged — not posted"),l===!1&&h.push("Not staged"),c===!0&&h.push("Verified posted"),c===!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:o,prepared:l,bannerShown:d,verified:c,matchPreview:m,matchAuthor:_,chips:h}}const We="inline-flex max-w-full items-center truncate rounded-md border border-border px-1.5 py-0.5 text-xs";function pn({peer:e,ownerSlug:n}){const s=Pe();if(e.url&&!e.self&&e.type){const i=Fn(e.url);return i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:ie(We,"hover:bg-muted"),title:e.type,onClick:o=>o.stopPropagation(),children:t.jsx("span",{className:"truncate",children:e.name})}):t.jsx("span",{className:ie(We,"text-muted-foreground"),children:e.name})}if(e.self||!e.type||!s)return t.jsx("span",{className:ie(We,"text-muted-foreground"),children:e.name});const r=typeof e.id=="number"?{owner:n,entityId:e.id}:{owner:n,segments:[{entity_type:e.type,slug:e.id}]},a=jr(s.item,r);return t.jsx("button",{type:"button","aria-pressed":a,title:e.type,className:ie(We,"hover:bg-muted",a&&"ring-1 ring-primary"),onClick:i=>{i.stopPropagation(),s.open(_r(r,e.name))},children:t.jsx("span",{className:"truncate",children:e.name})})}function bi(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 Ni({row:e,entityId:n,entityType:s,ownerSlug:r,label:a=e.relationship_type_name}){const i=(o,l,c,d)=>t.jsx(pn,{peer:{id:o,name:l??`Record #${o}`,type:c,url:d,self:!d&&o===n&&(typeof o=="number"||c===s)},ownerSlug:r});return t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1 text-xs",children:[i(e.from_entity_id,e.from_entity_name,e.from_entity_type,e.from_entity_url),!e.is_symmetric&&t.jsx(Tt,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"text-muted-foreground",children:a}),!e.is_symmetric&&t.jsx(Tt,{"aria-hidden":"true",className:"size-3 shrink-0 text-muted-foreground"}),i(e.to_entity_id,e.to_entity_name,e.to_entity_type,e.to_entity_url)]})}function wi({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 fn={name:"Name",slug:"URL slug",parent_id:"Parent",content:"Content changed"};function Ce(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Qe(e){return e==null||e===""}function Mr(e,n){return mt(e??null)===mt(n??null)}function Or(e){return!!(e?.type==="array"&&(e.items?.type==="object"||e.items?.properties))}function Fr(e){return!!(e&&(e.type==="object"||e.properties)&&e.type!=="array")}function bt(e,n){return br({key:e,prop:n??{}})}function Dr(e,n){return e?.properties?.[n]}function ht(e,n,s,r,a){if(Mr(n,s))return;const i=c=>Array.isArray(c)?c:[];if((Array.isArray(n)||Qe(n))&&(Array.isArray(s)||Qe(s))&&(Array.isArray(n)||Array.isArray(s)||r?.type==="array")){const c=i(n),d=i(s);if(Or(r)||[...c,...d].some(y=>Ce(y))){const y=Math.min(c.length,d.length);for(let A=0;A<y;A++)ht([...e,`item ${A+1}`],c[A],d[A],r?.items,a);const N=Math.max(0,d.length-c.length),C=Math.max(0,c.length-d.length);(N||C)&&a.push({kind:"items",path:e,added:N,removed:C});return}const u=y=>mt(y),m=new Set(c.map(u)),_=new Set(d.map(u)),w=d.filter(y=>!m.has(u(y))),h=c.filter(y=>!_.has(u(y)));a.push(w.length||h.length?{kind:"values",path:e,added:w,removed:h,prop:r?.items}:{kind:"reordered",path:e});return}if((Ce(n)||Qe(n))&&(Ce(s)||Qe(s))&&(Ce(n)||Ce(s)||Fr(r))){const c=Ce(n)?n:{},d=Ce(s)?s:{},p=[...new Set([...Object.keys(r?.properties??{}),...Object.keys(c),...Object.keys(d)])];for(const u of p){const m=Dr(r,u);ht([...e,bt(u,m)],c[u],d[u],m,a)}return}a.push({kind:"set",path:e,old:n,new:s,prop:r})}function Pr(e,n){const s=fn[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 ht([bt(e.field,r)],e.old,e.new,r,a),a}function Lr(e,n){const s=n?.properties;return e.map(r=>r.field==="content"?"Content":fn[r.field]??bt(r.field,s?.[r.field]))}const Br="entity.updated",Ur=new Set(["link","unlink","update_link"]);function Lt(e){const n=typeof e=="string"||typeof e=="number"?Number(e):Number.NaN;return Number.isSafeInteger(n)&&n>0?n:null}function Kr(e){const n=e.split("_").join(" ").trim();return n?`${n.charAt(0).toUpperCase()}${n.slice(1)}`:e}function zr(e){const n=e.metadata;if(e.semantic_type!=="change"||!n||n._lobu_relationship_change!==!0||typeof n.op!="string"||!Ur.has(n.op))return null;const s=Lt(n.fromEntityId),r=Lt(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?Kr(a):"relationship",changedFields:i.flatMap(o=>o&&typeof o=="object"&&typeof o.field=="string"?[o.field]:[])}}function gt({id:e,ownerSlug:n}){const s={slug:n},{data:r,isLoading:a,isError:i}=zt(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(pn,{peer:{id:e,name:r.name,type:r.entity_type},ownerSlug:n})}function qr({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(gt,{id:e.fromId,ownerSlug:n}),t.jsx("span",{children:s}),t.jsx("span",{"aria-hidden":"true",children:"→"}),t.jsx(gt,{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 Hr(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=zr(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!==Br&&(r!==void 0||s.category))return null;const a=Hr(s.changes);if(!a)return null;const i=e.entity_ids?.[0];return{kind:"fields",entityId:typeof i=="number"?i:null,changes:a}}function xn(e,n){const s={slug:n},{data:r}=zt(e.entityType?void 0:e.entityId??void 0,s),{data:a}=Dn(e.entityType??r?.entity_type??"",s);return a?.metadata_schema}const Wr=4;function Je({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(wr,{value:e,prop:n,empty:t.jsx("span",{className:"italic",children:"empty"})})})}function Bt({id:e,ownerSlug:n}){const s=typeof e=="number"||typeof e=="string"?Number(e):Number.NaN;return Number.isSafeInteger(s)&&s>0?t.jsx(gt,{id:s,ownerSlug:n}):t.jsx("span",{className:"italic text-muted-foreground",children:"empty"})}function yt(e,n){return`${e} ${n}${e===1?"":"s"}`}function Qr({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(Je,{value:e.old,prop:e.prop})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(Je,{value:e.new,prop:e.prop})]});case"parent":return t.jsxs(t.Fragment,{children:[s,": ",t.jsx(Bt,{id:e.old,ownerSlug:n})," ",t.jsx("span",{"aria-hidden":"true",children:"→"})," ",t.jsx(Bt,{id:e.new,ownerSlug:n})]});case"items":return t.jsxs(t.Fragment,{children:[s,":"," ",[e.added?`${yt(e.added,"item")} added`:null,e.removed?`${yt(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(Je,{value:r,prop:e.prop})]},`+${a}`)),e.removed.map((r,a)=>t.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["−",t.jsx(Je,{value:r,prop:e.prop})]},`-${a}`))]});case"reordered":return t.jsxs(t.Fragment,{children:[s,": reordered"]})}}function Jr({change:e,ownerSlug:n}){const s=xn(e,n);return t.jsxs(t.Fragment,{children:["Updated ",Lr(e.changes,s).join(", ")]})}function Nt({changes:e,entityId:n,entityType:s,ownerSlug:r,showAll:a=!1}){const i=xn({entityId:n,entityType:s},r),[o,l]=v.useState(a),c=e.flatMap(u=>Pr(u,i)),d=o?c:c.slice(0,Wr),p=c.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(Qr,{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(),l(!0)},children:["+",yt(p,"more change")]})}):null]})}function Gr({event:e,ownerSlug:n}){return e.kind==="relationship"?t.jsx(qr,{change:e.change,ownerSlug:n}):t.jsx(Jr,{change:e,ownerSlug:n})}function Yr({event:e,ownerSlug:n}){return e.kind==="fields"?t.jsx(Nt,{changes:e.changes,entityId:e.entityId,ownerSlug:n}):null}const Xr="lobu-token-exchange";function nt(e){return{connection_id:e.connectionId,operation_key:`${e.connectorKey}::${e.operationKey}`}}function Ge(e,n){const s=nt(n);return e.connection_id===s.connection_id&&e.operation_key===s.operation_key}const Ke=e=>e.kind==="guardrail";function Zr(e,n){return!Ke(e)||e.effect==="auto"?!1:(e.connection_id!=null?e.connection_id===n.connectionId:e.connector_key==null||e.connector_key===n.connectorKey)&&(e.operation_key==null||e.operation_key===nt(n).operation_key)}function ea(e,n){const{session:s}=He(),{allOrgs:r}=Ht(),a=s?.session?.userAgent,i=n&&a!==Xr&&!Ln(),{isAdmin:o}=Vt(i?(r??[]).find(l=>l.slug===e)?.id:void 0);return i&&o}function ta({ownerSlug:e,target:n,policy:s,held:r}){const a=qt(),i=!r&&s?.effect==="auto",l=ea(e,n!==null&&(r||i)),c=Pn(e,l),[d,p]=v.useState(!1),u=c.data?.rules,m=n&&u?u.find(x=>Ke(x)&&Ge(x,n)):void 0,_=new Set((u??[]).map(x=>x.id)),w=n!==null&&(u??[]).some(x=>x.id!==m?.id&&Zr(x,n)),h=n!==null&&(u??[]).some(x=>!Ke(x)&&Ge(x,n)&&x.effect==="auto"),y=l&&r&&u!==void 0&&!w&&(m?m.effect==="approval":!h)&&(s?.reason==="matched_rule"||s?.reason==="guardrail")&&(s.rules??[]).every(x=>_.has(x.id)&&(!Ke(x)||x.id===m?.id)),N=l&&i&&u!==void 0&&!m,C=l&&i&&m?.effect==="approval";async function A(x){const S=c.data;if(!S||!n)return!1;p(!0);try{const I=await Bn(e,{revision:S.revision,rules:x(S.rules,n)});return a.setQueryData(Un(e),I),Kn(a),!0}catch(I){return I instanceof Se&&I.status===409?(Oe.error("Policies changed in another session. Try again."),await c.refetch()):Oe.error(I instanceof Error?I.message:"Could not save the rule."),!1}finally{p(!1)}}return{saving:d,canAlwaysAllow:y,canAskNextTime:N,asksNextTime:C,alwaysAllow:()=>A((x,S)=>[...x.filter(I=>!Ge(I,S)),{...nt(S),effect:"auto"}]),askNextTime:()=>A((x,S)=>[...x.filter(I=>!(Ke(I)&&Ge(I,S))),{...nt(S),effect:"approval",kind:"guardrail"}])}}function na({operation:e}){switch(e){case"create":case"created":return t.jsx(ee,{variant:"default",children:"Created"});case"update":case"updated":return t.jsx(ee,{variant:"secondary",children:"Updated"});case"delete":case"deleted":return t.jsx(ee,{variant:"destructive",children:"Deleted"});default:return t.jsx(ee,{variant:"outline",children:e||"Change"})}}function sa({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(na,{operation:e}),t.jsx("time",{dateTime:s,title:s,className:"ml-auto text-xs text-muted-foreground",children:zn(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 ra(e){return e.semantic_type==="change"&&(e.metadata?.category==="config"||e.metadata?.category==="deployment")}function Re(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function aa({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=Re(s.manifest),o=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")&&Re(i?.state);return t.jsxs("div",{className:"space-y-3","data-testid":"config-change-event",children:[t.jsx(sa,{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(l=>typeof l=="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(Et,{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,Re(n.counts)?t.jsx("dl",{className:"flex flex-wrap gap-4 text-xs",children:Object.entries(Re(n.counts)??{}).map(([l,c])=>t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:l}),t.jsx("dd",{children:String(c)})]},l))}):null,typeof s.error=="string"?t.jsx("p",{className:"text-sm text-destructive",children:s.error}):null,o?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(Et,{text:`lobu rollback ${a}`,label:"restore command",iconOnly:!0})]})]}):null,t.jsx(Xe,{before:null,after:i})]}):Object.hasOwn(s,"before")?t.jsx(Xe,{before:Re(s.before),after:Re(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(Xe,{before:null,after:Re(s.state)})]})]})}const ia={slack:"Slack",telegram:"Telegram",whatsapp:"WhatsApp",discord:"Discord",gchat:"Google Chat",teams:"Microsoft Teams",web:"Web"};function oa(e){return ia[e]??null}function la(e){return e?e.kind==="automation"?`Ran ${e.automationName}`:e.platform==="web"?"Chatted in Lobu":`Replied on ${oa(e.platform)??e.platform}`:"No activity yet"}function ca({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":ie(Ze,!s&&"border-b");if(n.kind==="managed"){const c=n.agent,d=[c.lastActivity===void 0?null:la(c.lastActivity),c.connectionCount===void 0?null:`${c.connectionCount} ${c.connectionCount===1?"connection":"connections"}`,c.userCount===void 0?null:`${c.userCount} ${c.userCount===1?"user":"users"}`].filter(u=>!!u),p=t.jsx(Hn,{className:"h-4 w-4 text-muted-foreground"});return t.jsx(te,{to:"/$owner/agents/$agentId",params:{owner:e,agentId:c.agentId},className:i,children:a?t.jsxs(t.Fragment,{children:[p,c.name]}):t.jsx(ze,{mark:p,name:c.name,details:t.jsx(et,{parts:d.length>0?d:[c.description]}),at:c.lastActivity?Date.parse(c.lastActivity.at):void 0})})}const o=n.group,l=t.jsx(qn,{name:o.title});return t.jsx(te,{to:"/$owner/agents/connected/$clientId",params:{owner:e,clientId:o.clientId},className:i,children:a?t.jsxs(t.Fragment,{children:[l,o.title]}):t.jsx(ze,{mark:l,name:o.title,details:t.jsx(et,{parts:[o.connected?"Connected app":"Disconnected",o.linkedUser,o.drivenBy&&o.drivenBy!==o.title?`via ${o.drivenBy}`:null]}),at:o.lastSeenAt})})}const da={event:{label:"Event",icon:Wt},schedule:{label:"Schedule",icon:Wn},manual:{label:"Manual",icon:Vn}};function ua(e,n,s){switch(Yn(e)){case"script":return["Script"];case"external":case"manual":return["Outside client"];case"device":{const r=e.agent_kind,a=r&&r in Ft?Ft[r]:r;return[n,s,a].filter(i=>!!i)}case"agent":return[n??"Agent","Hosted"]}}function ma({automation:e,agentName:n,deviceLabel:s,connectorDisplay:r,owner:a,actions:i,rowClass:o,appearance:l="row"}){const c=e.automation,d=c.automation_id,p=da[e.kind];if(l==="inline")return t.jsxs(te,{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,c.status==="archived"?t.jsx(ee,{variant:"outline",children:"Archived"}):null]});const u=Qn(e,Date.now()),m=c.processing_client_count??0,_=c.entity_name&&c.entity_type?`${c.entity_name} · ${c.entity_type}`:null;return t.jsxs("div",{className:o,children:[t.jsx(te,{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(ze,{mark:r?t.jsx(Gn,{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:c.status==="archived"?t.jsx(ee,{variant:"outline",children:"Archived"}):null,tone:u.problem?"destructive":null,details:t.jsx(et,{parts:[u.text,...ua(c,n,s),m>0?`${m} ${m===1?"client":"clients"}`:null,Jn(e.when),_]}),at:u.at})}),i]})}function pa({record:e,workspace:n,appearance:s}){return t.jsx(ma,{automation:Zn(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 fa({agent:e,workspace:n,appearance:s}){return t.jsx(ca,{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 xa({connector:e,connection:n,workspace:s,appearance:r}){const a=e.key,i=t.jsx(es,{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(te,{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:Xn(n)})]}):t.jsx(te,{to:"/$owner/connectors/$connectorKey",params:{owner:s,connectorKey:a},children:i})})}function Ye(e,n){return typeof e=="string"&&e.trim().length>0&&e.length<=n}function wt(e,n){if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n;if(s.mode!=="live"||!Ye(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"?!Ye(s.automationId,128)||!/^[1-9][0-9]*$/.test(s.automationId)||!Number.isSafeInteger(Number(s.automationId))?null:{...r,automationId:s.automationId}:e==="connector-ref"?!Ye(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}:{}}:Ye(s.agentId,128)?{...r,agentId:s.agentId}:null}const ha=4,ga=128;let ct=0;const Be=[];async function ya(e,n){if(e.aborted)throw e.reason;await new Promise((s,r)=>{const a=()=>{const o=Be.indexOf(i);o>=0&&Be.splice(o,1),r(e.reason)},i=()=>{e.removeEventListener("abort",a),ct++,s()};ct<ha?i():Be.length>=ga?r(new Error("Reference read capacity exceeded")):(Be.push(i),e.addEventListener("abort",a,{once:!0}))});try{if(e.aborted)throw e.reason;return await n()}finally{ct--,Be.shift()?.()}}const st={retry:!1,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchOnReconnect:"always"};function Ie({error:e}){const n=e instanceof Se&&(e.status===401||e.status===403)?"Access required to view this reference.":e instanceof Se&&e.status===404?"Reference not found.":"Reference unavailable.";return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:n})}function kt(){return t.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:"Loading reference…"})}function va({workspace:e,automationId:n,appearance:s}){const{session:r,isReady:a}=He(),i=jt(),o=Fe({...st,enabled:a&&!i,queryKey:["automations-list",e,"native-reference",r?.user.id??null,n],queryFn:({signal:c})=>ya(c,async()=>{let d;for(const u of["active","archived"])if(d=(await je("manage_automations",{action:"list",automation_id:n,status:u,include_details:!1,limit:1},{slug:e},{signal:c})).automations?.find(_=>_.automation_id===n),d)break;if(!d)throw new Se("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(o.isPending||o.isFetching)return t.jsx(kt,{});if(o.error||!o.data)return t.jsx(Ie,{error:o.error});const l=o.data;return t.jsx(pa,{record:l,workspace:e,appearance:s})}function ja({workspace:e,connectorKey:n,connectionId:s,appearance:r}){const{session:a,isReady:i}=He(),o=jt(),l=Fe({...st,enabled:i&&!o,queryKey:["connector-definitions",e,"native-reference",a?.user.id??null],queryFn:async({signal:u})=>(await ts({slug:e},{signal:u})).map(m=>({key:m.key,name:m.name,description:m.description,icon:m.icon}))}),c=Fe({...st,enabled:i&&!o&&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 je("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 Se("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(o)return t.jsx("span",{role:"status",children:"Unavailable in visitor preview."});if(l.isPending||l.isFetching||s!==void 0&&(c.isPending||c.isFetching))return t.jsx(kt,{});if(l.error||s!==void 0&&(c.error||!c.data))return t.jsx(Ie,{error:l.error||c.error});const d=l.data?.find(u=>u.key===n);if(!d)return t.jsx(Ie,{error:new Se("Reference not found",404)});const p=c.data?.connection;return t.jsx(xa,{connector:d,connection:p,workspace:e,appearance:r})}function _a({workspace:e,agentId:n,appearance:s}){const{session:r,isReady:a}=He(),i=jt(),o=Fe({...st,enabled:a&&!i,queryKey:["agents",e,"native-reference",r?.user.id??null,n],queryFn:async({signal:c})=>{const d=await je("manage_agents",{action:"get",agent_id:n},{slug:e},{signal:c});if(d.agent?.id!==n)throw new Se("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(o.isPending||o.isFetching)return t.jsx(kt,{});if(o.error||!o.data)return t.jsx(Ie,{error:o.error});const l=o.data;return t.jsx(fa,{agent:l,workspace:e,appearance:s})}function ba(e){const n=wt("automation-ref",e);return n?t.jsx(va,{...n}):t.jsx(Ie,{})}function Na(e){const n=wt("connector-ref",e);return n?t.jsx(ja,{...n}):t.jsx(Ie,{})}function wa(e){const n=wt("agent-ref",e);return n?t.jsx(_a,{...n}):t.jsx(Ie,{})}const dt=e=>typeof e=="string"&&e.trim().length>0&&e.length<=128,ka={tabs:({defaultValue:e,children:n})=>dt(e)?t.jsx(fr,{defaultValue:e,children:n}):null,"tabs-list":({label:e,children:n})=>t.jsx(pr,{label:typeof e=="string"&&e.length<=200?e:void 0,children:n}),"tabs-trigger":({value:e,children:n})=>dt(e)?t.jsx(mr,{value:e,children:n}):null,"tabs-content":({value:e,children:n})=>dt(e)?t.jsx(ur,{value:e,children:n}):null,"automation-ref":ba,"connector-ref":Na,"agent-ref":wa,"json-diff":(({before:e,after:n})=>{const s=r=>r!==null&&typeof r=="object"&&!Array.isArray(r)?r:null;return t.jsx(Xe,{before:s(e),after:s(n)})})};function Ue(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Aa({template:e,data:n,onAction:s}){const[r,a]=v.useState(null),[i,o]=v.useState(!1),[l,c]=v.useState(null),[d,p]=v.useState(!1),u=v.useRef(!1),m=v.useRef(!0);v.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]);const _=async w=>{if(!(!s||u.current)){u.current=!0,o(!0),c(null),p(!1);try{const h=await s(w);if(!m.current)return;if(Ue(h)&&h.kind==="sdk"){const y=h.result;if(!Ue(y)||y.success!==!0){const N=Ue(y)&&Ue(y.error)?y.error.message:null;throw new Error(typeof N=="string"?N:"Could not update this event.")}if(y.return_truncated||!Ue(y.return_value))throw new Error("The update did not return a complete data object.");a(y.return_value),p(!0)}}catch(h){m.current&&c(h instanceof Error?h.message:"Could not update this event.")}finally{u.current=!1,m.current&&o(!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,l?t.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:[l," Previous data is still shown."]}):null,t.jsx("div",{"aria-busy":i,className:"min-w-0",children:t.jsx(Nr,{template:{root:e.root},data:r??n,onAction:s?_:void 0,interactions:e.interactions,components:ka,actionsDisabled:!s||i})})]})}function hn(e){return{audit:rn(e),operation:e.interaction_type==="approval"||e.semantic_type==="operation",changeSet:e.semantic_type==="change_set"}}const Ca={},Ra={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function Sa(e){return e.author_name?e.author_name:e.platform?tt(e.platform):e.origin_type?Ra[e.origin_type]??tt(e.origin_type):null}function Ia(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 ut=1e5;function Ut({value:e}){const n=JSON.stringify(e,null,2)??"null",s=n.length>ut;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,ut):n}),s&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",ut.toLocaleString()," of"," ",n.length.toLocaleString()," characters."]})]})}function $a(e){return Object.entries(e).filter(([n,s])=>an(n)||s==null?!1:typeof s=="string"?s.trim().length>0:Array.isArray(s)?s.length>0:typeof s=="object"?Object.keys(s).length>0:!0).sort(([n],[s])=>n.localeCompare(s))}function Ta({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 Ea({slug:e,value:n,isManual:s}){return t.jsxs(ee,{variant:"secondary",className:"text-xs",children:[e,": ",n,s&&t.jsx(Yt,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function Ma(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 gn(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 vt(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Oa(e){return e.replace(/\s+[—-]\s+pending approval$/i,"")}function rt(e){return e.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,n=>n.toUpperCase())}function Fa(e){const n=Object.keys(e.fields),s=n.map(rt).join(", ")||"field",r=n.length===1?"field":"fields";return`Update ${e.entityType?rt(e.entityType).toLowerCase():"entity"} ${r}: ${s}`}function Da(e,n){const s=vt(n.fields);if(!s||Object.keys(s).length===0||n.action_key!=="entity_field_change"&&n.tool!=="entity_field_change")return null;const r=vt(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 Pa(e){const n=e.entityType?rt(e.entityType).toLowerCase():"entity";return`${rt(e.operation)} ${n}`}function La(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:vt(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 Ba(e,n){return!n.entityType||!n.entitySlug?null:Ts(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 yn({ownerSlug:e,runId:n,details:s}){const a=cn(s.automationId,void 0,void 0,{ownerSlug:e,includeVersions:!1}).data?.automation,i=Pe(),o=hr(s.initiator,s.attribution,s.automationId),l=a?.automation_name??s.automationName??o;return t.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",s.automationId?t.jsx(te,{to:"/$owner/automations/$automationId",params:{owner:e,automationId:s.automationId},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:l}):t.jsx("span",{className:"font-medium text-foreground",children:l}),n&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:" · "}),t.jsxs(te,{to:"/$owner/events",params:{owner:e},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",onClick:c=>{!i||c.button!==0||c.metaKey||c.ctrlKey||c.shiftKey||c.altKey||(c.preventDefault(),i.open({href:`/${e}/events?run_ids=${n}`,title:`Run #${n}`,runId:n}))},children:["Run #",n]})]})]})}function vn({ownerSlug:e,details:n}){const s=Ba(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(te,{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(yn,{ownerSlug:e,runId:n,details:s}),t.jsx(vn,{ownerSlug:e,details:s}),t.jsx("div",{className:"rounded-md border border-border/70 px-3 py-2",children:t.jsx(Nt,{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 Ka({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(yn,{ownerSlug:e,runId:n,details:s}),!i&&t.jsx(vn,{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?mn(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:[un(s.proposal).map((o,l)=>t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:l===0?"From: ":"To: "}),o.name]},o.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 za({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(ee,{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(sn,{className:"h-3 w-3"})]})]})}function qa({ownerSlug:e,content:n,batchReview:s}){const r=n.metadata||{},a=n.run_id??void 0,i=Sr(r),o=Da(n,r),l=La(n,r),c=(o?Fa(o):l?Pa(l):void 0)||r.operation_name||r.action_name||(n.title?Oa(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=v.useMemo(()=>n.interaction_input||r.action_input||r.operation_input||Ca,[n.interaction_input,r.action_input,r.operation_input]),_=n.interaction_output||r.action_output||void 0,w=Er(m,_??null,p),h=n.interaction_error||r.error_message||void 0,y=gn(n.interaction_status,r.status),N=r.reviewed_by_name||r.reviewed_by_id||void 0,C=r.reject_reason||void 0,A=r.policy,x=A?.reason==="matched_rule"||A?.reason==="guardrail"?(Array.isArray(A.rules)?A.rules:[]).map(G=>G.note).filter(Boolean):[],S=x.length?x.join(" · "):A?.reason==="guardrail"&&y!=="rejected"?"An organization guardrail requires approval.":void 0,I=r.initiator,T=vs({slug:e}),F=js({slug:e}),R=_s(n.id,bs(u,m),u),{values:g,setValues:B}=R,[U,K]=v.useState(null),[b,ne]=v.useState(!1),[z,oe]=v.useState(""),D=y==="pending_approval"&&U?U:y,P=D==="pending_approval",W=typeof r.source_run_id=="number",L=ta({ownerSlug:e,target:n.connection_id!=null&&n.platform&&p&&!i&&!o&&!l?{connectorKey:n.platform,connectionId:n.connection_id,operationKey:p}:null,policy:A,held:P&&!U&&!W&&a!=null}),[Y,X]=v.useState(!1),le=G=>T.mutate({run_id:a,...i?{}:{input:$s(g)}},{onSuccess:()=>K("confirmed"),onSettled:G}),q=T.isPending||F.isPending||L.saving||Y;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Wt,{className:"h-4 w-4 text-yellow-500"}),t.jsx("span",{className:"font-medium",children:c}),d&&t.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",d]}),D==="confirmed"&&t.jsx(ee,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:"Approved"}),D==="completed"&&t.jsx(ee,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),D==="failed"&&t.jsx(ee,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),D==="rejected"&&t.jsx(ee,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!o&&!l&&(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(xr,{ownerSlug:e,initiator:I,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&N&&t.jsx("span",{children:"·"}),N&&t.jsxs("span",{children:[D==="rejected"?"Rejected":"Approved"," by"," ",t.jsx("span",{className:"font-medium text-foreground",children:N})]})]}),o&&t.jsx(Ua,{ownerSlug:e,runId:a,details:o}),!o&&l&&t.jsx(Ka,{ownerSlug:e,runId:a,details:l,status:D}),(P||D==="rejected"&&!C)&&S&&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:"Policy:"})," ",S]}),D==="rejected"&&C&&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:"})," ",C]}),w&&t.jsx(za,{summary:w}),i&&t.jsx(Ir,{proposal:i}),!i&&(P?R.revision:u)&&(P||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"}),P?t.jsxs(t.Fragment,{children:[t.jsx(Ns,{visible:R.hasConflict,onReload:R.reset}),t.jsx(ws,{valueModel:"request",schema:R.revision,values:g,onValuesChange:B,idPrefix:`action-${n.id}-`,connectorContext:n.connection_id!=null?{connectionId:n.connection_id,orgSlug:e}:void 0},`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)})]}),D==="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(Zt,{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)})]}),D==="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)})]}),D==="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(Xt,{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})]}),L.canAskNextTime&&t.jsx("div",{className:"flex items-center gap-2 pt-1",children:t.jsxs(M,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>L.askNextTime(),disabled:L.saving,children:[L.saving&&t.jsx(ye,{size:"sm",className:"mr-1"}),"Ask next time"]})}),L.asksNextTime&&t.jsxs("p",{className:"pt-1 text-xs text-muted-foreground",children:["Lobu asks before running this again",d?` on ${d}`:"","."]}),P&&!U&&W&&t.jsxs("div",{className:"pt-1 text-xs text-muted-foreground",children:["Review this proposal with the other changes in its Automation run.",s]}),P&&a&&!U&&!W&&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:z,onChange:G=>oe(G.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(M,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>F.mutate({run_id:a,reason:z||void 0},{onSuccess:()=>{K("rejected")}}),disabled:F.isPending,children:[F.isPending&&t.jsx(ye,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),t.jsx(M,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{ne(!1),oe("")},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[t.jsxs(M,{size:"sm",className:"h-7 text-xs",onClick:()=>le(),disabled:!i&&!R.canSubmit||q,children:[T.isPending?t.jsx(ye,{size:"sm",className:"mr-1"}):t.jsx(ks,{className:"h-3 w-3 mr-1"}),i?"Approve":"Confirm"]}),L.canAlwaysAllow&&t.jsxs(M,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:async()=>{X(!0),await L.alwaysAllow()?le(()=>X(!1)):X(!1)},disabled:!R.canSubmit||q,children:[Y&&t.jsx(ye,{size:"sm",className:"mr-1"}),"Always allow",d?` on ${d}`:""]}),t.jsxs(M,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>ne(!0),disabled:q,children:[t.jsx(As,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function Ha({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,c=cn(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=gs({slug:n}),p=ys({slug:n}),[u,m]=v.useState(!1),[_,w]=v.useState(""),[h,y]=v.useState(null);if(r==="automation_batch_reject"){const g=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"}),g&&t.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:g}),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:[],C=typeof s.created_count=="number"?s.created_count:N.filter(g=>g.kind==="created").length,A=typeof s.updated_count=="number"?s.updated_count:N.filter(g=>g.kind==="updated").length,x=typeof s.denied_count=="number"?s.denied_count:N.filter(g=>g.kind==="denied").length,S=N.filter(g=>g.kind==="denied"),I=N.filter(g=>g.kind==="updated"&&Object.keys(g.applied||{}).length>0),T=typeof s.pending_proposal_count=="number"?s.pending_proposal_count:null,F=T==null||T>0,R=F?"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:[R==="proposed"?"Proposed":"Applied"," ",C," ","new + ",A," updated",x>0&&t.jsxs(t.Fragment,{children:[" + ",x," denied"]})]}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[i!=null?t.jsx(te,{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:c}):t.jsx("span",{className:"font-medium text-foreground",children:c}),a!=null&&t.jsxs("span",{children:[" · run #",a]}),T!=null&&T>0&&t.jsxs("span",{children:[" · ",T," pending"]})]})]}),I.length>0&&t.jsx("div",{className:"mt-3 space-y-2",children:I.map(g=>t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:g.name}),t.jsx(Nt,{changes:Object.entries(g.applied).map(([B,U])=>({field:B,old:U.old??null,new:U.new??null})),entityId:g.entityId,ownerSlug:n,showAll:!0})]},g.entityId))}),S.length>0&&t.jsx("div",{className:"mt-3 space-y-1.5",children:S.map(g=>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:[g.name," — not written"]}),g.denied&&t.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[g.denied.reason,t.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",g.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${g.entityId}-${g.name}`))}),a!=null&&h==null&&F&&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:g=>w(g.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),t.jsxs(M,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>p.mutate({run_id:a,reason:_||void 0},{onSuccess:()=>y("rejected")}),disabled:p.isPending,children:[p.isPending&&t.jsx(ye,{size:"sm",className:"mr-1"}),"Reject all"]}),t.jsx(M,{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(M,{size:"sm",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:a},{onSuccess:()=>y("approved")}),disabled:d.isPending||p.isPending,children:[d.isPending&&t.jsx(ye,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),t.jsx(M,{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&&!F&&t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function Va(e){if(!e)return;const n={};for(const[s,r]of Object.entries(e))an(s)||s==="agent_id"||(n[s]=r);return Object.keys(n).length>0?n:void 0}function Wa({renderDetail:e,ownerSlug:n,content:s,connectorDefinitions:r,hideDetails:a=!1}){const[i,o]=v.useState(null),[l,c]=v.useState(!1),[d,p]=v.useState(!1),[u,m]=v.useState(!1),[_,w]=v.useState(!1),[h,y]=v.useState(!1),[N,C]=v.useState(null),[A,x]=v.useState(s.title??""),[S,I]=v.useState(s.text_content??""),T=ds(),F=us(),R=Pe(),{currentOwner:g,allOrgs:B,isAuthenticated:U}=Ht(),K=n??g,b=K==="me"?null:K,ne=v.useCallback(async j=>{if(!b){Oe.error("Open this event inside a workspace to interact with it.");return}const E=await $r(b,Number(s.id),j,crypto.randomUUID());return"event_id"in E&&Oe.success("Recorded"),E},[s.id,b]),z=s.payload_data??{},{audit:oe,operation:D,changeSet:P}=hn(s),W=oe&&(z.request!==void 0||z.request_status==="too_large"),L=oe&&Array.isArray(z.sdk_call_trace)&&z.sdk_call_trace.length>0,Y=U&&b?(B??[]).find(j=>j.slug===b):void 0,X=s.semantic_type==="guidance",{isAdmin:le,isLoading:q}=Vt(X?Y?.id:void 0),G=qt(),se=ra(s),de=xt(R?.item?.href.split(/[?#]/)[0]??""),xe=de?.owner===K&&de?.eventId===Number(s.id),Z=(j,E,H)=>{R?R.open({href:j,title:E,...H==null?{}:{runId:H}}):T({to:j})},_e=(j,E)=>{if(!b)return null;const H=`/${b}/events?run_ids=${j}`;if(R?.item?.href===H)return null;const Ae=()=>Z(H,`Run #${j}`,j),Le="Show everything this run recorded";return E?t.jsxs(M,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:Ae,title:Le,children:[t.jsx(hs,{className:"h-3.5 w-3.5"}),E]}):t.jsxs("button",{type:"button",className:"hover:text-foreground hover:underline",onClick:Ae,title:Le,children:["Run #",j]})},he=s.run_id!=null&&!(R&&b&&s.automation_id!=null)?_e(s.run_id):null,ue=ms(s),me=s.automation_id,be=R&&b&&ue!=null&&me!=null?()=>R.open({href:`/${b}/automations/${me}?view=activity&run_id=${ue}`,title:`${s.automation_name??`Automation ${me}`} · Run #${ue}`,runId:ue}):void 0,$e=s.metadata?.source_run_id,re=Vr(s),Q=(!s.platform||s.platform==="lobu")&&s.connection_id==null&&s.feed_id==null&&s.origin_type==null&&s.automation_id==null&&!oe&&!D&&!P&&!se&&re==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,pe=!!(b&&Y&&Q&&(!X||!q&&le)),ae=pe&&s.payload_type!=="json_template"&&s.payload_type!=="media",ce=()=>{G.invalidateQueries({queryKey:[Ss]}),G.invalidateQueries({queryKey:[Is]}),G.invalidateQueries({queryKey:["search-memory"]})},Ne=async()=>{if(!(!b||!ae)){if(w(!1),C(null),s.payload_truncated){p(!0);try{const E=(await je("read_knowledge",{content_ids:[Number(s.id)]},{slug:b})).content?.find(H=>Number(H.id)===Number(s.id));x(E?.title??s.title??""),I(E?.text_content??E?.payload_text??s.text_content??""),c(!0)}catch(j){C(j instanceof Error?j.message:"Failed to load full memory.")}finally{p(!1)}return}x(s.title??""),I(s.text_content??""),c(!0)}},we=async()=>{if(!b||u)return;if(!S.trim()){C("Memory content cannot be empty.");return}m(!0),C(null);try{const E=s.payload_type==="markdown"||s.payload_type==="text"?s.payload_type:"text",H=Va(s.metadata);await je("save_memory",{supersedes_event_id:Number(s.id),semantic_type:s.semantic_type||"note",payload_type:E,title:A.trim()||void 0,content:S,...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}:{},...H?{metadata:H}:{}},{slug:b}),c(!1),ce(),Oe.success("Memory updated")}catch(E){C(E instanceof Error?E.message:"Failed to update memory.")}finally{m(!1)}},ke=async()=>{if(!(!b||h)){y(!0),C(null);try{const j=Number(s.id),E=await je("run_sdk",{title:"Delete memory",script:`export default async (_ctx, client) => client.knowledge.delete(${JSON.stringify({content_id:j,reason:"Deleted from web UI"})});`},{slug:b});if(E?.success===!1){const Ae=typeof E.error=="string"?E.error:E.error?.message||"Failed to delete memory.";throw new Error(Ae)}w(!1),xe&&R?.close();const H=xt(F.pathname);H?.owner===b&&H.eventId===j&&T({to:"/$owner/events",params:{owner:b}}),ce(),Oe.success("Memory deleted")}catch(j){C(j instanceof Error?j.message:"Failed to delete memory.")}finally{y(!1)}}},k=pe&&!l?_?t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsxs(M,{type:"button",variant:"destructive",size:"sm",className:"h-7 px-2.5 text-xs",disabled:h,onClick:()=>void ke(),children:[h&&t.jsx(ye,{size:"xs",className:"mr-1.5"}),h?"Deleting...":"Delete"]}),t.jsx(M,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:h,onClick:()=>{w(!1),C(null)},children:"Cancel"})]}):t.jsxs(t.Fragment,{children:[ae&&t.jsxs(M,{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 Ne(),children:[d?t.jsx(ye,{size:"xs"}):t.jsx(Cs,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:d?"Loading...":"Edit"})]}),t.jsxs(M,{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:()=>{C(null),w(!0)},children:[t.jsx(Rs,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"Delete"})]})]}):null,O=l?t.jsxs("form",{className:"mt-2 space-y-3 rounded-lg border bg-background p-3 text-foreground",onSubmit:j=>{j.preventDefault(),we()},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(ps,{id:`memory-title-${s.id}`,"aria-label":"Memory title",value:A,onChange:j=>x(j.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(fs,{id:`memory-content-${s.id}`,"aria-label":"Memory content",value:S,onChange:j=>I(j.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(xs,{onCancel:()=>{c(!1),C(null)},cancelDisabled:u,children:t.jsxs(M,{type:"submit",disabled:u||S.trim().length===0,children:[u&&t.jsx(ye,{size:"xs",className:"mr-1.5"}),u?"Saving...":"Save"]})})]}):null,Te=!l&&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,ge=se?t.jsx(aa,{content:s}):b?P?t.jsx(Ha,{content:s,ownerSlug:b}):D?t.jsx(qa,{ownerSlug:b,content:s,batchReview:typeof $e=="number"?_e($e,"Review run"):null}):void 0:void 0,Ee=e?e(ge):{content:ge,nativeHeading:ge!=null};return t.jsx(Ga,{primaryContent:Ee.content,nativeHeading:Ee.nativeHeading,heading:re&&b?t.jsx(Gr,{event:re,ownerSlug:b}):void 0,body:O??(re&&b?t.jsx(Yr,{event:re,ownerSlug:b}):void 0),detailLinks:Ee.links,headingAside:Ee.headingAside,hideDetails:a,presentation:"detail",content:s,ownerSlug:K??void 0,connectorDefinitions:r,onRenderedAction:b?ne:void 0,runAction:he,memoryActions:k,memoryFeedback:Te,runId:ue??s.run_id??null,onRunSelect:be,auditDetails:(W||L)&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-2",children:[{key:"request",label:"Request",available:W},{key:"calls",label:"SDK calls",available:L}].map(j=>j.available?t.jsxs(M,{variant:"outline",size:"sm","aria-expanded":i===j.key,onClick:()=>o(E=>E===j.key?null:j.key),children:[i===j.key?t.jsx(pt,{className:"h-3.5 w-3.5"}):t.jsx(ft,{className:"h-3.5 w-3.5"}),j.label]},j.key):null)}),i==="request"&&(z.request_status==="too_large"?t.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof z.request_bytes=="number"?` (${z.request_bytes.toLocaleString()} bytes).`:"."]}):t.jsx(Ut,{value:z.request})),i==="calls"&&t.jsx(Ut,{value:z.sdk_call_trace})]})})}function Qa(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 gn(e.interaction_status,typeof r.status=="string"?r.status:void 0)}function Ja(e){return e==="pending_approval"?"Needs approval":e==="confirmed"?"Approved":e?tt(e):null}function Ga({presentation:e,primaryContent:n,nativeHeading:s=!1,heading:r,body:a,detailLinks:i,headingAside:o,content:l,ownerSlug:c,connectorDefinitions:d,onRenderedAction:p,runAction:u,memoryActions:m,memoryFeedback:_,auditDetails:w,runId:h,onRunSelect:y,hideDetails:N=!1}){const[C,A]=v.useState(!1),x=l.metadata??{},S=typeof l.score=="number"&&Number.isFinite(l.score)?Math.round(l.score):"-",I=l.payload_type||"text",T=I==="text"&&(l.semantic_type==="notification"||l.automation_id!=null)?"markdown":I,F=l.text_content||"",R=e==null&&(T==="text"||T==="markdown")&&F.length>500,g=R&&!C?`${F.slice(0,500)}...`:F,B=l.payload_data??{},U=hn(l),{audit:K,operation:b}=U,ne=Qa(l,U),z=Ja(ne),oe=(K?Qt(l).title:null)??l.title,D=K&&B.error&&typeof B.error=="object"?B.error.message:void 0,[P,W]=v.useState(K&&n==null&&i==null),L=K?B.duration_ms:x.duration_ms,Y=typeof L=="number"&&Number.isFinite(L)&&L>=0?L:null,X=K&&typeof B.sdk_call_count=="number"&&Number.isSafeInteger(B.sdk_call_count)&&B.sdk_call_count>=0?B.sdk_call_count:null,le=x.thumbnail_url||x.thumbnail,q=x.media_url,G=$a(x),se=Object.entries(l.classifications||{}).flatMap(([k,O])=>{const Te=Ma(O);return Te.values.map(ge=>({slug:k,value:ge,isManual:Te.isManual}))}),de=(()=>{const k=l.platform||(typeof x.platform=="string"?x.platform:null),O=l.connection_id!=null?l.connection_id:x.source_connection_id!=null?Number(x.source_connection_id):null;return{...l,platform:k,connection_id:O!=null&&Number.isFinite(O)?O:null}})(),xe=(()=>{const k=l.source_url??x.browser_url;if(typeof k!="string"||!URL.canParse(k))return null;const O=new URL(k);return O.protocol==="https:"||O.protocol==="http:"?O:null})(),Z=l.occurred_at?new Date(l.occurred_at):null,{KindIcon:_e,kindLabel:he}=Jt(l),ue=t.jsx(_t,{source:de,connectorDefinitions:d,sourceUrl:xe,label:he,fallback:t.jsx(_e,{className:"h-4 w-4"})}),me=G.length>0?t.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([k,O])=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{className:"text-muted-foreground",children:tt(k)}),t.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:Ia(O)})]},k))}):null,be=(()=>{switch(T){case"markdown":if(g)return t.jsx("div",{className:"max-w-none text-sm space-y-2",children:t.jsx(ns,{text:g})});break;case"json_template":{const k=l.payload_data;if(k?._truncated===!0&&typeof k.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."}),c?t.jsx(te,{to:Gt(c,Number(l.id)),className:"underline underline-offset-4",children:"Open full report"}):null]});const O=l.payload_template;if(O?.root)return t.jsx(Aa,{template:O,data:l.payload_data||{},onAction:n?void 0:p},`${c}:${l.id}`);if(g)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:g});break}case"media":return t.jsxs("div",{className:"space-y-3",children:[!le&&q&&t.jsx("a",{href:q,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:q}),g&&t.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:g})]});case"empty":return t.jsxs("div",{className:"space-y-3",children:[w,me??(w?null:t.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"}))]});default:if(g)return t.jsx("div",{className:"text-sm whitespace-pre-wrap",children:g});break}return null})(),$e=T==="empty"||be==null,re=a?t.jsx("div",{className:"mt-1",children:a}):t.jsxs(t.Fragment,{children:[l.rating&&t.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(k=>t.jsx(Yt,{className:`h-4 w-4 ${k<=Number(l.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},k))}),le&&t.jsx("a",{href:q||l.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:t.jsx("img",{src:le,alt:"",className:`rounded-md object-cover ${T==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),be??t.jsxs("div",{className:"space-y-3",children:[q&&!le&&t.jsx("a",{href:q,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:q}),me]})]}),Q=e==="detail",pe=n!=null||Q&&K,ae=o!==void 0,ce=Q&&!a&&!$e?me:null,Ne=pe||i!=null||ce!=null,we=!!(z&&!s||X!=null||Y!=null||!Q&&m!=null||S!=="-"&&l.score_breakdown!=null||xe!=null);v.useEffect(()=>{if(!ae||!P)return;const k=O=>{O.key==="Escape"&&(O.preventDefault(),W(!1))};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[ae,P]);const ke=t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 sm:ml-auto sm:justify-end",children:[o,m,ae&&Ne&&t.jsxs(M,{type:"button",variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-muted-foreground hover:text-foreground","aria-expanded":P,onClick:()=>W(k=>!k),children:["Details",P?t.jsx(pt,{className:"h-3.5 w-3.5"}):t.jsx(ft,{className:"h-3.5 w-3.5"})]})]});return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:ie("flex gap-3",Q&&"mb-5",ae&&"relative"),children:[t.jsx(ss,{children:ue}),t.jsxs("div",{className:"min-w-0 flex-1",children:[Q&&(()=>{const k={semantic_types:l.semantic_type,...typeof l.automation_id=="number"?{produced_by:String(l.automation_id)}:{},...typeof l.run_id=="number"?{run_ids:String(l.run_id)}:{}};return t.jsxs("div",{className:"mb-2 flex flex-wrap items-start gap-x-4 gap-y-2 text-xs text-muted-foreground",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-1 gap-y-1",children:[l.semantic_type?c?t.jsx(te,{to:"/$owner/events",params:{owner:c},search:k,className:"hover:underline",title:`Show all ${he} events`,children:he}):t.jsx("span",{children:he}):t.jsx("span",{children:he}),c&&!b&&t.jsx(Mt,{owner:c,source:de,variant:"byline"}),Z&&t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":!0,className:"text-muted-foreground/50",children:"·"}),t.jsx("time",{dateTime:Z.toISOString(),children:rs(Z)})]}),u]}),ke]})})(),t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[(r??oe)&&!s&&t.jsx("h4",{className:ie("min-w-0 break-words font-medium",Q?"w-full text-xl leading-snug":"line-clamp-2 text-sm"),children:r??oe}),!Q&&Z&&t.jsx(as,{at:Z})]}),we&&t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[z&&!s&&t.jsxs(ee,{variant:ne==="failed"?"destructive":"secondary",className:"gap-1 text-xs",children:[ne==="failed"?t.jsx(Xt,{className:"h-3 w-3"}):ne==="completed"?t.jsx(Zt,{className:"h-3 w-3"}):null,z]}),X!=null&&t.jsxs("span",{children:[X," SDK ",X===1?"call":"calls"]}),Y!=null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(is,{className:"h-3 w-3"}),Y<1e3?`${Math.round(Y)}ms`:`${Number((Y/1e3).toFixed(2))}s`]}),S==="-"?null:l.score_breakdown?t.jsxs(en,{children:[t.jsx(tn,{asChild:!0,children:t.jsx(M,{variant:"ghost",size:"sm",className:"h-7 px-2",children:t.jsx("span",{className:"font-medium",children:S})})}),t.jsx(nn,{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(Ta,{breakdown:l.score_breakdown})]})})]}):null,xe&&t.jsxs(os,{children:[t.jsx(ls,{asChild:!0,children:t.jsx(M,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-1",asChild:!0,children:t.jsxs("a",{href:xe.href,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(sn,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"View original"})]})})}),t.jsx(cs,{children:"View original"})]}),!Q&&m]}),_,c&&!(Q&&b)&&t.jsx(Mt,{owner:c,source:de,connectorDefinitions:d,variant:"chips",hideOriginator:Q,className:"mt-2 text-xs",runId:h,onRunSelect:y}),(l.author_name||!c)&&!(Q&&b)&&t.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:l.author_name||Sa(l)})]}),ae&&P&&Ne&&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,pe&&re,ce]})]}),typeof D=="string"&&t.jsx("p",{className:"mb-2 text-sm whitespace-pre-wrap text-destructive",children:D}),n,!pe&&re,t.jsx(Cr,{attachments:l.attachments,owner:c,eventId:e?Number(l.id):void 0,connectionId:l.connection_id}),Ne&&!ae&&!(N&&n!=null)&&t.jsxs("details",{className:"mt-5 border-t pt-3",open:P,onToggle:k=>W(k.currentTarget.open),children:[t.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground",children:"Details"}),P&&t.jsxs("div",{className:"mt-3 space-y-3",children:[i,pe&&re,ce]})]}),R&&t.jsx(M,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>A(!C),children:C?t.jsxs(t.Fragment,{children:[t.jsx(pt,{className:"h-3 w-3 mr-1"})," Show less"]}):t.jsxs(t.Fragment,{children:[t.jsx(ft,{className:"h-3 w-3 mr-1"})," Show more"]})}),se.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:se.map(k=>t.jsx(Ea,{slug:k.slug,value:k.value||"",isManual:k.isManual},k.slug))})]})}function Ya(e,n){const s=e.metadata??{},r=rn(e)?Qt(e,n):null,{KindIcon:a,kindLabel:i}=Jt(e),o=Ms(e,n),l=e.interaction_error??(typeof s.error_message=="string"?s.error_message:r?.failed?"Failed":null),c=e.platform||(typeof s.platform=="string"?s.platform:null);return{title:o,kindLabel:i,error:l,KindIcon:a,platform:c}}function Xa(e,n){const s=Number(e.metadata?.resource_id);return n!=="me"&&e.semantic_type==="notification"&&e.metadata?.resource_type==="automation"&&Number.isSafeInteger(s)&&s>0?Os(n,String(s)):Gt(n,Number(e.id))}function Za(e){const n=Array.isArray(e)?e.length:0;return n===0?null:n===1?"1 file":`${n} files`}function ei(e,n){const s=Fs(e);return s&&n?n(s):null}function ti({content:e,ownerSlug:n,connectorDefinitions:s,hideOriginator:r=!1,showEntity:a=!1,connectionName:i,callerName:o,extra:l,unread:c=!1,onOpen:d}){const p=Pe(),{title:u,kindLabel:m,error:_,KindIcon:w,platform:h}=Ya(e,i),y=e.interaction_status==="pending",N=!!_||e.interaction_status==="failed",C=n?Xa(e,n):null,A=xt(p?.item?.href.split(/[?#]/)[0]??""),x=A!=null&&A.owner===n&&A.eventId===Number(e.id),S=[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??ei(e,o),Za(e.attachments),l],I=t.jsx(ze,{mark:t.jsx(_t,{source:{...e,platform:h},connectorDefinitions:s,label:m,fallback:t.jsx(w,{className:"h-4 w-4 text-muted-foreground"})}),name:u,badge:c&&!N?t.jsx("span",{className:"sr-only",children:"Unread"}):null,tone:y||c&&!N?"amber":N?"destructive":null,details:t.jsx(et,{parts:S}),at:e.occurred_at?new Date(e.occurred_at).getTime():null});if(!C)return t.jsx("div",{className:ie(Ze,"cursor-default"),children:I});const T=R=>{d?.(),!(!p||R.metaKey||R.ctrlKey||R.shiftKey||R.altKey||R.button!==0)&&(R.preventDefault(),p.open({href:C,title:u}))},F=Es(C);return t.jsx(te,{to:F.pathname,search:F.search,"aria-current":x?"true":void 0,className:ie(Ze,x&&"bg-accent"),onClick:T,children:I})}function qe(e,n,s=`${n}s`){return`${e} ${e===1?n:s}`}function At(e){const n=[...new Set(e.apps.map(r=>r.name))];if(n.length>1)return qe(e.apps.length,"app");const s=n[0]??"Unknown app";return e.apps.length>1?`${s} (${e.apps.length})`:s}function Kt(e){const{oldestAt:n,newestAt:s}=e;if(n==null||s==null)return null;const r=zs(n,s),a=De(n,r?"p":"d MMM p"),i=De(s,r?"p":"d MMM p");return a===i?a:`${a}–${i}`}function jn(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 _n(e){const n=jn(e)[0]?.title??"Ran background checks";return`${At(e)} ${n.charAt(0).toLowerCase()}${n.slice(1)}`}function bn(e){return jn(e).slice(1).map(n=>`${n.title.charAt(0).toLowerCase()}${n.title.slice(1)} ${n.count}×`)}function ni(e,n){if(e.source)return e.source.name;if(e.kind==="background")return _n(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]??At(e)}function si(e){return[e.reads>0?qe(e.reads,"read"):null,e.actions>0?qe(e.actions,"action"):null].filter(Boolean).join(" · ")}function ri({summary:e,headline:n}){const s=si(e),r=e.changed[0]===n?e.changed.slice(1):e.changed;if(r.length===0){const o=e.idle?e.explicitTitles.slice(0,2):[];return t.jsx("span",{className:"block truncate",children:[...o,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 ai({stretch:e,ownerSlug:n,connectorDefinitions:s,connectionName:r,sourceConnection:a,showEntity:i=!1},o){const l=Pe();return!l||!n?{open:null,selected:!1}:{selected:l.item?.key===e.key,open:()=>l.open({href:"",key:e.key,title:o,workStretch:{stretch:e,ownerSlug:n,connectorDefinitions:s,connectionName:r,sourceConnection:a,showEntity:i}})}}function ii(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 oi(e){const n=new Map;for(const s of e.calls){const r=Ks(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((o,l)=>l[1]-o[1]).map(([o,l])=>`${o} · ${l}×`),every:ii(i),lastAt:i.length>0?Math.max(...i):null}))}function li({stretch:e}){const n=_n(e),s=bn(e),r=[`${n} · ${e.calls.length}×`,e.oldestAt!=null?`since ${De(e.oldestAt,"p")}`:null,...s].filter(Boolean).join(" · ");return t.jsxs(en,{children:[t.jsx(tn,{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(on,{"aria-hidden":"true",className:"h-3 w-3 shrink-0"}),t.jsx("span",{className:"truncate",children:r})]})}),t.jsxs(nn,{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:oi(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 ${Ds(a.lastAt,{addSuffix:!0})}`:null].filter(Boolean).join(" · ")})]},a.key))})]})]})}function ci({hideOriginator:e=!1,...n}){const{stretch:s,connectorDefinitions:r,sourceConnection:a}=n,i=v.useMemo(()=>Ps(s),[s]),o=ni(s,i),{open:l,selected:c}=ai(n,o),d=s.kind==="background",{source:p}=s,u=i.failedCalls.length+i.failedOperations.length+s.flagged.length,m=!u&&!p&&(d||i.idle),_=d?on:i.idle&&!p?Ls:Bs,w=p?[Kt(s),qe(s.items.length,"item"),u>0?`${u} failed`:null]:d?[s.oldestAt!=null?`since ${De(s.oldestAt,"p")}`:null,...bn(s)]:[e?null:At(s),qe(s.calls.length,"call"),Kt(s),u>0?`${u} failed`:null],h=t.jsx(ze,{mark:p?t.jsx(_t,{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:o,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:Us(s).map(N=>N.label).join(" · ")}):d?null:t.jsx(ri,{summary:i,headline:o}),t.jsx("span",{className:"block truncate",children:w.filter(Boolean).join(" · ")})]}),at:s.newestAt}),y=ie(Ze,m&&"opacity-60");return l?t.jsx("button",{type:"button","aria-current":c?"true":void 0,className:ie(y,c&&"bg-accent opacity-100"),onClick:l,children:h}):t.jsx("div",{className:ie(y,"cursor-default"),children:h})}function ki({presentation:e="summary",renderDetail:n,hideDetails:s=!1,organizationId:r,ownerSlug:a,entityId:i,filters:o,showEntityLinks:l=!1,hideOriginator:c=!1,emptyState:d,groupStretches:p=!1,foldRunSatellites:u=!0,renderLead:m,hiddenPinned:_,unreadNotices:w,onMarkRead:h,extraRows:y,onGoToLatest:N}){const{isAuthenticated:C,isReady:A,session:x}=He(),{isLoading:S}=qs(),I=a==="me",{canManageWorkspace:T,canReadPublicWorkspace:F}=or(a),{data:R=[]}=Hs(A&&T?r:null),{data:g=[]}=Vs(F?a:null),B=T?R:g,{data:U}=Ws(p&&A&&T?r:null),K=v.useMemo(()=>{const f=new Map((U??[]).map($=>[$.id,$.display_name??$.connector_name]));return $=>f.get($)??null},[U]),{data:b}=Qs({enabled:A&&T}),ne=x?.user?.id??null,z=v.useCallback(f=>f.kind==="user"?f.userId===ne?"You":null:b?.find($=>$.agentId===f.agentId)?.name??f.agentId,[b,ne]),oe=v.useMemo(()=>{const f=new Map((U??[]).map($=>[$.id,$.connector_key]));return $=>{const J=f.get($);return J&&r?{connectorKey:J,organizationId:r}:null}},[U,r]),D=Js(A&&T?r:null,i,o,a),P=Gs(F?a:null,i,o),W=F?P:D,{data:L,isLoading:Y,error:X,fetchNextPage:le,hasNextPage:q,isFetchingNextPage:G}=W,se=v.useMemo(()=>L?.pages.flatMap(f=>f.content)??[],[L]),de=v.useMemo(()=>{const f=Ys(se,{foldRunSatellites:u}),$=f.map(fe=>fe.head),J=new Map(f.map(fe=>[fe.head.id,fe])),ve=Xs($),Me=Array.from(ve.entries()).map(([fe,it])=>{const It=it.root||it.replies[0],$t=It?J.get(It.id):void 0;return{rootId:fe,group:it,history:$t?.history??[],runId:$t?.runId??null}});return _?Zs(Me,_):Me},[se,u,_]),xe=m?de[0]:void 0,Z=xe?Ot(xe)??void 0:void 0,_e=Z?de.slice(1):de,he=f=>w?.(f)??[],ue=p&&er(o),me=`${r}:${i}:${JSON.stringify(tr(o))}:${o.beforeOccurredAt}:${o.beforeId}`,[be,$e]=v.useState(null),re=()=>{let f=Number.NEGATIVE_INFINITY;for(const $ of se){const J=Date.parse($.occurred_at);J>f&&(f=J)}$e({scope:me,ids:new Set(se.map($=>$.id)),newestAt:f})},Q=ue&&se.length>0&&!W.isFetching,pe=be?.scope!==me;v.useEffect(()=>{Q&&pe&&re()});const ae=v.useRef(null),ce=ue?nr(_e,pe?null:be,f=>rr(f,{connectionName:K,groupSources:!ar(o,i)})):{entries:_e.map(f=>({kind:"single",node:f})),pending:[]},Ne=new Date().toDateString(),we=f=>f.kind==="stretch"&&f.stretch.kind==="background"&&f.stretch.newestAt!=null&&new Date(f.stretch.newestAt).toDateString()===Ne,ke=[...ce.entries,...ce.pending].find(we),k=ce.entries.filter(f=>!we(f)),O=ce.pending.filter(f=>!we(f)).length,Te=!I&&(!A||C&&S||T&&W.isPending);if(X)return t.jsx(sr,{label:"events"});const ge=e==="detail",Ee=(f,$,J={})=>{const ve=he(f);return{key:$,occurredAt:f.occurred_at,content:t.jsx(ti,{content:f,ownerSlug:a,connectorDefinitions:B,connectionName:K,callerName:z,hideOriginator:c,showEntity:l,extra:J.extra,unread:ve.length>0,onOpen:ve.length>0&&h?()=>h(ve):void 0})}},j=f=>{if(f.kind==="stretch"){const{stretch:fe}=f;return[{key:fe.key,occurredAt:fe.newestAt,content:t.jsx(ci,{stretch:fe,ownerSlug:a,connectorDefinitions:B,connectionName:K,sourceConnection:oe,hideOriginator:c,showEntity:l})}]}const{rootId:$,group:J}=f.node,ve=J.root||J.replies[0];if(!ve)return[];const Me=J.root?J.replies.length:J.replies.length-1;return[Ee(ve,$,{extra:Me>0?`${Me} ${Me===1?"reply":"replies"}`:null})]},E=f=>{if(f.kind!=="single")return[];const $=Ot(f.node);return $?[{key:f.node.rootId,occurredAt:$.occurred_at,content:t.jsx(Wa,{ownerSlug:a,content:$,renderDetail:n,connectorDefinitions:B,hideDetails:s})}]:[]},H=k.flatMap(ge?E:j),Ae=se.at(-1)?.occurred_at,Le=(y??[]).filter(f=>!q||Ae==null||(Ve(f.occurredAt)??0)>=(Ve(Ae)??0)),Ct=Le.length>0&&(H.length>0||Z)?[...H,...Le].sort((f,$)=>(Ve($.occurredAt)??0)-(Ve(f.occurredAt)??0)):H,Nn=t.jsx(gr,{rows:!ge,groupByDate:!ge,isLoading:Y||Te,emptyState:Z||ke?.kind==="stretch"?null:d,hasNextPage:!!q,isFetching:W.isFetching,isFetchingNextPage:G,onLoadMore:()=>void le(),items:Ct}),wn=O>0?t.jsx("div",{className:"pointer-events-none sticky top-2 z-10 flex h-0 justify-center overflow-visible",children:t.jsxs(M,{size:"sm",className:"pointer-events-auto h-7 rounded-full px-3 text-xs shadow-md",onClick:()=>{re(),ae.current?.scrollIntoView?.({block:"start",behavior:"smooth"})},children:[O," new"]})}):null,Rt=ke?.kind==="stretch"?t.jsx(li,{stretch:ke.stretch}):null,at=o.beforeOccurredAt?di(o.beforeOccurredAt):null,kn=Rt||at||N?t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:Rt}),at?t.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:["From ",at]}):null,N&&t.jsxs(M,{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(ir,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Back to latest"]})]}):null,St=t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:ae,className:"scroll-mt-4"}),wn,kn,Nn]});return!Z||!m?St:t.jsxs(t.Fragment,{children:[m(Z,{hasEarlier:Ct.length>0||!!q}),St]})}function di(e){const n=new Date(e);return Number.isNaN(n.getTime())?null:yr(n)?De(n,"p"):De(n,vr(n)?"d MMM, p":"d MMM yyyy, p")}export{ma as A,ki as E,wi as R,Ga as a,Ni as b,kr as c,_i as d,oa as e,ji as f,At as g,ti as h,qe as p,bi as r,Kt as s,Ar as u};
2
+ //# sourceMappingURL=events-feed-ClhEywwV.js.map