@lobu/runtime-server 24.7.0 → 24.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/catalogs/connectors.json +199 -316
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/imessage.ts +953 -0
  4. package/dist/connectors/linkedin.ts +20 -377
  5. package/dist/dependencies.bun.lock +124 -92
  6. package/dist/embeddings-server.mjs +14 -2
  7. package/dist/owletto/dist/assets/_-B0tmXZ86.js +2 -0
  8. package/dist/owletto/dist/assets/_-DwXULq4r.js +3 -0
  9. package/dist/owletto/dist/assets/_agentId-B1dNkhnr.js +2 -0
  10. package/dist/owletto/dist/assets/_agentId-sYjvnBaB.js +2 -0
  11. package/dist/owletto/dist/assets/_automationId-Bnw_CnT_.js +2 -0
  12. package/dist/owletto/dist/assets/_connectorKey._connectionId-D7Z8DQ-B.js +2 -0
  13. package/dist/owletto/dist/assets/_connectorKey.index-DM5MTO8c.js +2 -0
  14. package/dist/owletto/dist/assets/_conversationId-OJrZjd0o.js +2 -0
  15. package/dist/owletto/dist/assets/_eventId-CfB0_2zK.js +2 -0
  16. package/dist/owletto/dist/assets/_owner-BDvTUY0a.js +3 -0
  17. package/dist/owletto/dist/assets/_shape-BZidoJMB.js +2 -0
  18. package/dist/owletto/dist/assets/_slug-R989vOiM.js +2 -0
  19. package/dist/owletto/dist/assets/_viewKey-BDUSrpe5.js +2 -0
  20. package/dist/owletto/dist/assets/_viewKey-BnFqh5-t.js +2 -0
  21. package/dist/owletto/dist/assets/{accept-invitation-CX7Egv-p.js → accept-invitation-BC-ZIsrf.js} +2 -2
  22. package/dist/owletto/dist/assets/activity-route-view-CN2dOiCD.js +2 -0
  23. package/dist/owletto/dist/assets/agent-connect-pages-CdDjrHjn.js +4 -0
  24. package/dist/owletto/dist/assets/agent-editor-form-CDAHRNWl.js +2 -0
  25. package/dist/owletto/dist/assets/{agent-loading-shells-DHvKiEUB.js → agent-loading-shells-BupiSjR-.js} +2 -2
  26. package/dist/owletto/dist/assets/agent-permissions-matrix-ju7L2M0l.js +2 -0
  27. package/dist/owletto/dist/assets/{agent-skill-context-DF5q0Dfr.js → agent-skill-context-B0ZYVE3n.js} +2 -2
  28. package/dist/owletto/dist/assets/{agent-subpage-shell-Pi5cECga.js → agent-subpage-shell-ByU0xhXn.js} +2 -2
  29. package/dist/owletto/dist/assets/{agent-thread-B1ZepGZc.js → agent-thread-DiVKn1WX.js} +4 -4
  30. package/dist/owletto/dist/assets/agent-thread-storage-Bx2-WBHQ.js +2 -0
  31. package/dist/owletto/dist/assets/app._appId-BQWElSoP.js +2 -0
  32. package/dist/owletto/dist/assets/assist-composer-igTXq3DL.js +2 -0
  33. package/dist/owletto/dist/assets/automation-detail-content-BJwRU6qT.js +2 -0
  34. package/dist/owletto/dist/assets/{callback-Ckrxv0eo.js → callback-Dmaio9CX.js} +2 -2
  35. package/dist/owletto/dist/assets/{card-DT9mSjSp.js → card-rE4Ctuy6.js} +2 -2
  36. package/dist/owletto/dist/assets/{claim-Bzby28tT.js → claim-BN17CPYh.js} +2 -2
  37. package/dist/owletto/dist/assets/{client-activity-scopes-DoIErdUy.js → client-activity-scopes-B7xVaUA-.js} +2 -2
  38. package/dist/owletto/dist/assets/{client-rows-BbVQy5Ti.js → client-rows-B3LULJxW.js} +2 -2
  39. package/dist/owletto/dist/assets/clients-CydgUHrc.js +2 -0
  40. package/dist/owletto/dist/assets/code-editor-UppEMWpt.js +26 -0
  41. package/dist/owletto/dist/assets/connect-OdHpIVV9.js +2 -0
  42. package/dist/owletto/dist/assets/connect-menu-B9u86bb2.js +2 -0
  43. package/dist/owletto/dist/assets/connect._clientId-EI1tcdSE.js +2 -0
  44. package/dist/owletto/dist/assets/connected._clientId-CaF-ZWlZ.js +2 -0
  45. package/dist/owletto/dist/assets/{connection-BOaMa324.js → connection-D8ZAMHBT.js} +2 -2
  46. package/dist/owletto/dist/assets/connection-feed-detail-CJYqryAV.js +2 -0
  47. package/dist/owletto/dist/assets/connector-boxes-BWPXijAk.js +2 -0
  48. package/dist/owletto/dist/assets/connector-page-shell-C23dWdKz.js +2 -0
  49. package/dist/owletto/dist/assets/connector-provenance-CW4CXtCz.js +2 -0
  50. package/dist/owletto/dist/assets/{connectors-D5F5rHxX.js → connectors-Bp08_KPq.js} +2 -2
  51. package/dist/owletto/dist/assets/consent-_PpYI1cT.js +2 -0
  52. package/dist/owletto/dist/assets/copy-button-1ALlvZU1.js +2 -0
  53. package/dist/owletto/dist/assets/{core.esm-BIE97rfo.js → core.esm-6koO33th.js} +2 -2
  54. package/dist/owletto/dist/assets/create-DULVO0HS.js +2 -0
  55. package/dist/owletto/dist/assets/create-Drx9tcnG.js +2 -0
  56. package/dist/owletto/dist/assets/{create-automation-form-B12yTrmj.js → create-automation-form-BhujNbRr.js} +3 -3
  57. package/dist/owletto/dist/assets/{create-BPxsKwk7.js → create-kUevP9Xx.js} +2 -2
  58. package/dist/owletto/dist/assets/create._connectorKey-N6fhcIPy.js +2 -0
  59. package/dist/owletto/dist/assets/{custom-guardrail-edits-B9plaLBN.js → custom-guardrail-edits-B_aCgvoZ.js} +2 -2
  60. package/dist/owletto/dist/assets/definition-comparison-3zKUSTt8.js +2 -0
  61. package/dist/owletto/dist/assets/{detail-page-skeleton-I5_7FkKx.js → detail-page-skeleton-BmxqqIsH.js} +2 -2
  62. package/dist/owletto/dist/assets/{device-CadaiNF4.js → device-D2eUt_nr.js} +2 -2
  63. package/dist/owletto/dist/assets/device-pin-tombstone-BFPbTM_o.js +2 -0
  64. package/dist/owletto/dist/assets/device._deviceId-Dqtmb1Xp.js +2 -0
  65. package/dist/owletto/dist/assets/dynamic-schema-form-D3KnzCsW.js +2 -0
  66. package/dist/owletto/dist/assets/entity-options-IUdQ-64R.js +2 -0
  67. package/dist/owletto/dist/assets/entity-page-B3Im65EI.js +2 -0
  68. package/dist/owletto/dist/assets/entity-pages-DJNSQrfB.js +2 -0
  69. package/dist/owletto/dist/assets/entity-type-page-CouHZbc9.js +2 -0
  70. package/dist/owletto/dist/assets/event-detail-CvaRN1qB.js +2 -0
  71. package/dist/owletto/dist/assets/event-kind-options-fHAIXu24.js +2 -0
  72. package/dist/owletto/dist/assets/events-feed-DwOkLk6A.js +2 -0
  73. package/dist/owletto/dist/assets/filter-editors-DQ5V4Cvh.js +2 -0
  74. package/dist/owletto/dist/assets/{full-page-spinner-CCU4PkRv.js → full-page-spinner-B7A6Ycyi.js} +2 -2
  75. package/dist/owletto/dist/assets/home-stream-Bg97PUBJ.js +2 -0
  76. package/dist/owletto/dist/assets/home-toolbar-CpCcHA6z.js +2 -0
  77. package/dist/owletto/dist/assets/index-9PGnv4-5.js +2 -0
  78. package/dist/owletto/dist/assets/{index-pmr1WUoG.js → index-B-dZruj6.js} +2 -2
  79. package/dist/owletto/dist/assets/index-BztXeLBN.js +2 -0
  80. package/dist/owletto/dist/assets/{index-B-Ab8srM.js → index-C2TCKJDP.js} +1599 -1597
  81. package/dist/owletto/dist/assets/index-C7QM3aqU.js +2 -0
  82. package/dist/owletto/dist/assets/index-CWn46a4y.js +2 -0
  83. package/dist/owletto/dist/assets/index-CxJONizf.js +2 -0
  84. package/dist/owletto/dist/assets/index-DJhb3li3.js +2 -0
  85. package/dist/owletto/dist/assets/{index-B72KYdN1.js → index-DXfYVs5m.js} +2 -2
  86. package/dist/owletto/dist/assets/{index-BYFDMIQC.js → index-DY-YGnCe.js} +2 -2
  87. package/dist/owletto/dist/assets/index-j3v7ITPb.js +2 -0
  88. package/dist/owletto/dist/assets/index-oiy6ygaI.js +2 -0
  89. package/dist/owletto/dist/assets/index-pEgtAY1t.js +2 -0
  90. package/dist/owletto/dist/assets/index-xAvK3IyQ.css +1 -0
  91. package/dist/owletto/dist/assets/json-diff-CJK-gzCt.js +4 -0
  92. package/dist/owletto/dist/assets/{list-skeleton-BAqT0vxo.js → list-skeleton-bQAZ0hQp.js} +2 -2
  93. package/dist/owletto/dist/assets/{login-D5bIjMtf.js → login-DLqL54Rk.js} +2 -2
  94. package/dist/owletto/dist/assets/{logout-JYZvxz8v.js → logout-H0F3IfiO.js} +2 -2
  95. package/dist/owletto/dist/assets/member-scope-gate-Doic_6qX.js +2 -0
  96. package/dist/owletto/dist/assets/memory-browse-page-CUea2Llz.js +74 -0
  97. package/dist/owletto/dist/assets/model-selector-BrfaDwIg.js +2 -0
  98. package/dist/owletto/dist/assets/new-5GkxlOuQ.js +2 -0
  99. package/dist/owletto/dist/assets/{new-B-Jd-vBl.js → new-BiA4DGoN.js} +2 -2
  100. package/dist/owletto/dist/assets/new-M-MX_T5C.js +2 -0
  101. package/dist/owletto/dist/assets/organization-CLrcmgNK.js +2 -0
  102. package/dist/owletto/dist/assets/peek-pane-content-B29OcHwm.js +2 -0
  103. package/dist/owletto/dist/assets/{pending-seed-CoFPQ835.js → pending-seed-DYYOoCvj.js} +2 -2
  104. package/dist/owletto/dist/assets/proposal-review-shell-BVwOMoq9.js +2 -0
  105. package/dist/owletto/dist/assets/public-shell-ready-BbjPgh3k.js +2 -0
  106. package/dist/owletto/dist/assets/record-activity-BCpNKaUo.js +2 -0
  107. package/dist/owletto/dist/assets/{record-session-Bpx4_LGk.js → record-session-KuEDuF3S.js} +2 -2
  108. package/dist/owletto/dist/assets/{renderer-CgaQKMoG.js → renderer-ucwCQmBk.js} +2 -2
  109. package/dist/owletto/dist/assets/{reset-password-C-4Jnuqk.js → reset-password-BkiAmXZW.js} +2 -2
  110. package/dist/owletto/dist/assets/run-initiator-8vdkq-3o.js +2 -0
  111. package/dist/owletto/dist/assets/{runs-BMzp7j7j.js → runs-B_iywKWb.js} +2 -2
  112. package/dist/owletto/dist/assets/runs-list-CJJFRhTl.js +2 -0
  113. package/dist/owletto/dist/assets/schema-type-editor-panel-C4e8pq1A.js +2 -0
  114. package/dist/owletto/dist/assets/{schema-value-BUgC0Ro8.js → schema-value-CefbtPIY.js} +3 -3
  115. package/dist/owletto/dist/assets/scoped-feed-bar-CapleZvS.js +2 -0
  116. package/dist/owletto/dist/assets/{settings-DYYvrrZ4.js → settings-DvzkRYQy.js} +2 -2
  117. package/dist/owletto/dist/assets/source-record-panels-LJIWGtHb.js +2 -0
  118. package/dist/owletto/dist/assets/{status-variants-DT61YfsU.js → status-variants-BxHtpMOj.js} +2 -2
  119. package/dist/owletto/dist/assets/subDays-DwIOMzYC.js +2 -0
  120. package/dist/owletto/dist/assets/{table-B6yimlsZ.js → table-1O-ik4_O.js} +2 -2
  121. package/dist/owletto/dist/assets/{use-automations-II_YJWtN.js → use-automations-lV8PuE8L.js} +2 -2
  122. package/dist/owletto/dist/assets/use-login-redirect-CfCbEeJR.js +2 -0
  123. package/dist/owletto/dist/assets/use-mention-search-CA-evCDf.js +91 -0
  124. package/dist/owletto/dist/assets/{view-param-filters-DYlqBocg.js → view-param-filters-Bp84PUMd.js} +2 -2
  125. package/dist/owletto/dist/assets/{views-access-required-BVtMfgLh.js → views-access-required-BerT4Z1d.js} +2 -2
  126. package/dist/owletto/dist/index.html +2 -2
  127. package/dist/server-main.bundle.mjs +274 -136
  128. package/npm-shrinkwrap.json +540 -447
  129. package/package.json +4 -2
  130. package/vendor/connector-sdk/package.json +1 -1
  131. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  132. package/vendor/core/dist/connector-query-errors.js +4 -0
  133. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -0
  134. package/vendor/core/dist/contracts/tools/manage-entity.js +7 -0
  135. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +2 -0
  136. package/vendor/core/dist/contracts/tools/manage-feeds.js +3 -0
  137. package/vendor/core/dist/contracts/tools/view-host.js +2 -0
  138. package/vendor/core/dist/error-report.js +1 -0
  139. package/vendor/core/package.json +1 -1
  140. package/vendor/views/package.json +1 -1
  141. package/dist/connectors/linkedin-takeout.ts +0 -577
  142. package/dist/connectors/takeout-utils.ts +0 -240
  143. package/dist/owletto/dist/assets/_-CZgmjLR9.js +0 -2
  144. package/dist/owletto/dist/assets/_-Cm5OgtYD.js +0 -3
  145. package/dist/owletto/dist/assets/_-DtqBFgK5.js +0 -2
  146. package/dist/owletto/dist/assets/_agentId-Cci6NFc1.js +0 -2
  147. package/dist/owletto/dist/assets/_agentId-GhWTlPO2.js +0 -2
  148. package/dist/owletto/dist/assets/_automationId-KUlxSTK2.js +0 -2
  149. package/dist/owletto/dist/assets/_connectorKey._connectionId-Zpy7Hvml.js +0 -2
  150. package/dist/owletto/dist/assets/_connectorKey.index-CYDRp9UX.js +0 -2
  151. package/dist/owletto/dist/assets/_conversationId-NNqDdije.js +0 -2
  152. package/dist/owletto/dist/assets/_eventId-0BSX6VHj.js +0 -2
  153. package/dist/owletto/dist/assets/_owner-C-CD22NB.js +0 -3
  154. package/dist/owletto/dist/assets/_shape-CvXp4omb.js +0 -2
  155. package/dist/owletto/dist/assets/_slug-DgK7zpKA.js +0 -2
  156. package/dist/owletto/dist/assets/_viewKey-cH54P0zY.js +0 -2
  157. package/dist/owletto/dist/assets/_viewKey-m0B5j7L9.js +0 -2
  158. package/dist/owletto/dist/assets/activity-link-rXNpmppV.js +0 -2
  159. package/dist/owletto/dist/assets/activity-route-view-B0m7_g9q.js +0 -2
  160. package/dist/owletto/dist/assets/agent-client-setup-list-BmD3-_Ox.js +0 -4
  161. package/dist/owletto/dist/assets/agent-connect-pages-BtOTCsTU.js +0 -2
  162. package/dist/owletto/dist/assets/agent-editor-form-CirqCpcM.js +0 -2
  163. package/dist/owletto/dist/assets/agent-list-row-SyACVYX7.js +0 -2
  164. package/dist/owletto/dist/assets/agent-permissions-matrix-Dsc26dyW.js +0 -2
  165. package/dist/owletto/dist/assets/agent-thread-storage-U6htL3ad.js +0 -2
  166. package/dist/owletto/dist/assets/agents-D1FHZ0jR.js +0 -2
  167. package/dist/owletto/dist/assets/app._appId-01I0CJal.js +0 -2
  168. package/dist/owletto/dist/assets/assist-composer-BD9msDk3.js +0 -2
  169. package/dist/owletto/dist/assets/automation-detail-content-BFv1TglZ.js +0 -2
  170. package/dist/owletto/dist/assets/automation-row-CmTpAD4r.js +0 -2
  171. package/dist/owletto/dist/assets/automation-source-list-D8ZSavQU.js +0 -2
  172. package/dist/owletto/dist/assets/automations-D1FHZ0jR.js +0 -2
  173. package/dist/owletto/dist/assets/change-summary-CGrKEJ04.js +0 -2
  174. package/dist/owletto/dist/assets/clients-6aJvabvS.js +0 -2
  175. package/dist/owletto/dist/assets/connect-BmDziBzI.js +0 -2
  176. package/dist/owletto/dist/assets/connect-menu-Bs8mxsga.js +0 -2
  177. package/dist/owletto/dist/assets/connect._clientId-t5aKu3aa.js +0 -2
  178. package/dist/owletto/dist/assets/connected._clientId-DswMAw8l.js +0 -2
  179. package/dist/owletto/dist/assets/connection-feed-detail-BLCjhP-H.js +0 -2
  180. package/dist/owletto/dist/assets/connector-boxes-BAP_f77M.js +0 -2
  181. package/dist/owletto/dist/assets/connector-page-shell-ClOmVPJr.js +0 -2
  182. package/dist/owletto/dist/assets/connector-provenance-wmYu5jwO.js +0 -2
  183. package/dist/owletto/dist/assets/consent-RqHNkmm8.js +0 -2
  184. package/dist/owletto/dist/assets/copy-button-D6zpsZLi.js +0 -2
  185. package/dist/owletto/dist/assets/create-GT8_yF0R.js +0 -2
  186. package/dist/owletto/dist/assets/create-Yx2qBMBy.js +0 -2
  187. package/dist/owletto/dist/assets/create._connectorKey-CzXqSkuI.js +0 -2
  188. package/dist/owletto/dist/assets/definition-comparison-C3k6Wa9B.js +0 -2
  189. package/dist/owletto/dist/assets/device-pin-tombstone-U7Bx05P6.js +0 -2
  190. package/dist/owletto/dist/assets/device._deviceId-DTZqj1HS.js +0 -2
  191. package/dist/owletto/dist/assets/dynamic-schema-form-DyT_9iVE.js +0 -2
  192. package/dist/owletto/dist/assets/entity-options-CGTjLlcS.js +0 -2
  193. package/dist/owletto/dist/assets/entity-page-DHHMmA8V.js +0 -2
  194. package/dist/owletto/dist/assets/entity-pages-eYbG2FDT.js +0 -2
  195. package/dist/owletto/dist/assets/entity-type-page-CjFqxSdL.js +0 -2
  196. package/dist/owletto/dist/assets/event-card-BtTUuf2q.js +0 -2
  197. package/dist/owletto/dist/assets/event-detail-8xHiplt_.js +0 -2
  198. package/dist/owletto/dist/assets/events-feed-zFnTSE27.js +0 -2
  199. package/dist/owletto/dist/assets/filter-editors-Dd5R2Etd.js +0 -2
  200. package/dist/owletto/dist/assets/home-stream-IVsNEkwp.js +0 -2
  201. package/dist/owletto/dist/assets/index-2oaMOFKe.js +0 -2
  202. package/dist/owletto/dist/assets/index-B4RZgvvI.js +0 -2
  203. package/dist/owletto/dist/assets/index-BBZM53p8.js +0 -2
  204. package/dist/owletto/dist/assets/index-BOb0a5f9.js +0 -2
  205. package/dist/owletto/dist/assets/index-BwnFQcMe.js +0 -2
  206. package/dist/owletto/dist/assets/index-CvYsWYlF.js +0 -2
  207. package/dist/owletto/dist/assets/index-DIXIvtnM.js +0 -2
  208. package/dist/owletto/dist/assets/index-DLwokXHW.js +0 -2
  209. package/dist/owletto/dist/assets/index-_nlPHus1.js +0 -2
  210. package/dist/owletto/dist/assets/index-cwOgj4-i.js +0 -2
  211. package/dist/owletto/dist/assets/index-pp4qmhkA.js +0 -2
  212. package/dist/owletto/dist/assets/index-tTbno-PX.css +0 -1
  213. package/dist/owletto/dist/assets/json-diff-B-1Swv_y.js +0 -28
  214. package/dist/owletto/dist/assets/member-scope-gate-Lj9m4RL2.js +0 -2
  215. package/dist/owletto/dist/assets/memory-browse-page-rAKfVdQ_.js +0 -74
  216. package/dist/owletto/dist/assets/model-selector-onvGA9Ww.js +0 -2
  217. package/dist/owletto/dist/assets/new-BmehH1uR.js +0 -2
  218. package/dist/owletto/dist/assets/new-KDi15LWZ.js +0 -2
  219. package/dist/owletto/dist/assets/organization-B9bh20Xo.js +0 -2
  220. package/dist/owletto/dist/assets/peek-pane-content-Bqus80Mq.js +0 -2
  221. package/dist/owletto/dist/assets/proposal-review-shell-CnACXCUg.js +0 -2
  222. package/dist/owletto/dist/assets/public-shell-ready-Dlh-eWz0.js +0 -2
  223. package/dist/owletto/dist/assets/record-activity-6CfR95Ul.js +0 -2
  224. package/dist/owletto/dist/assets/run-initiator-BvruBM5H.js +0 -2
  225. package/dist/owletto/dist/assets/runs-list-DVhrTr3v.js +0 -2
  226. package/dist/owletto/dist/assets/schema-type-editor-panel-Bdeumkux.js +0 -2
  227. package/dist/owletto/dist/assets/source-record-panels-CBV9tsR3.js +0 -2
  228. package/dist/owletto/dist/assets/use-login-redirect-BqtEilid.js +0 -2
  229. package/dist/owletto/dist/assets/use-mention-search-Bxlpd6Dp.js +0 -96
@@ -1,2 +0,0 @@
1
- import{j as e,S as o,q as c,at as d,w as u,b2 as h,dG as b,B as p,L as x,y as g}from"./index-B-Ab8srM.js";function j({rows:t=5}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading members",children:Array.from({length:t}).map((n,s)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg px-3 py-2",children:[e.jsx(o,{className:"h-8 w-8 shrink-0 rounded-full"}),e.jsx(o,{className:"h-4 w-40"})]},s))})}function l({title:t,body:n,ctaLabel:s,showCta:a,callbackUrl:r}){return e.jsx(h,{icon:b,title:t,description:n,children:s&&a?e.jsx(p,{asChild:!0,className:"mt-4",children:e.jsx(x,{to:"/auth/login",search:g({callbackUrl:r,intent:"sign-in"}),children:s})}):null})}function y({children:t}){const{isAuthenticated:n,isReady:s}=c(),{isMember:a,isLoading:r}=d(),i=u({select:m=>m.href});return!s||r?e.jsx(j,{}):n?a?e.jsx(e.Fragment,{children:t}):e.jsx(l,{title:"Join to see members",body:"Emails and member details are only visible to members of this workspace. Use the banner above to join.",callbackUrl:i}):e.jsx(l,{title:"Sign in to see members",body:"The members of this workspace are only visible to people who have signed in.",ctaLabel:"Sign in",showCta:!0,callbackUrl:i})}export{y as M};
2
- //# sourceMappingURL=member-scope-gate-Lj9m4RL2.js.map
@@ -1,74 +0,0 @@
1
- import{r as w,j as n,B as V,dc as ct,fa as js,fb as Es,c6 as Cs,i as oe,db as Ct,S as Be,bA as _s,fc as Ms,em as Ts,bl as Ls,d9 as Rs,fd as Is,v as De,fe as Kt,ff as $s,fg as Os,fh as As,H as Ae,bt as $t,bu as Ot,bv as At,bw as Pt,bx as mt,fi as Ps,I as tt,fj as Ds,bV as On,fk as An,fl as Pn,fm as Fs,l as _t,fn as zs,c as nt,u as Jt,ed as Dn,aH as Ws,aI as Bs,cF as Hs,fo as Vs,aB as Us,fp as Fn,b4 as qs,bb as Gs,c4 as zn,$ as Ys,L as Pe,X as Ks,el as Wn,c8 as Js,c9 as Qs,fq as Xs,fr as Zs,eW as er,cd as tr,bB as Bn,fs as Hn,ft as Ze,fu as xt,fv as nr,fw as sr,fx as Qt,fy as rr,fz as Bt,fA as Ht,fB as or,fC as ar,cT as Vn,cU as bt,dP as ir,cK as cr,bT as lr,eh as dr,eU as ur,dY as mr,b2 as Un,fD as qn,eL as fr,f4 as pr,e2 as hr,V as Vt,cV as Gn,fE as gr,dm as yr,d0 as xr,dM as Yn,dO as Kn,e1 as Jn,dN as Qn,dQ as br,dR as vr,dS as wr,dT as kr,cX as un,fF as Nr,fG as Sr,cY as jr,Y as Er,fH as Xn,fI as Zn,aq as Cr,fJ as _r,E as es,fK as Mr,cn as Ve,k as ts,fL as Dt,fM as Tr,fN as Lr,d3 as mn,fO as Ft,fP as Rr,fQ as Ir,fR as $r,eI as Or,fS as Ar,fT as Pr,br as Dr,fU as Fr,a as zr,fV as Wr,fW as Br,ak as Hr,az as Vr}from"./index-B-Ab8srM.js";import{P as Ur}from"./public-shell-ready-Dlh-eWz0.js";import{f as qr,a as Gr,d as fn,e as Yr,A as Kr}from"./connector-boxes-BAP_f77M.js";import{u as Jr}from"./use-automations-II_YJWtN.js";import{f as Qr}from"./feed-event-kinds-BYuZCoU4.js";import{S as Xr}from"./schema-type-editor-panel-Bdeumkux.js";import{D as Zr,c as eo}from"./dynamic-schema-form-DyT_9iVE.js";import{S as to,E as ns,a as no,e as so,b as ro,c as oo}from"./entity-pages-eYbG2FDT.js";import{F as ao}from"./filter-editors-Dd5R2Etd.js";import{l as io,p as Mt,e as ss,a as co,S as lo,J as uo}from"./renderer-CgaQKMoG.js";import{u as mo,a as fo,D as po,P as ho,b as rs,c as go,C as yo}from"./core.esm-BIE97rfo.js";import{v as xo,V as os,M as as,a as is,w as bo,b as vo}from"./view-param-filters-DYlqBocg.js";import{E as wo}from"./entity-type-page-CjFqxSdL.js";import{M as ko}from"./member-scope-gate-Lj9m4RL2.js";function pn(e){let t=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const c of e)t=Math.min(t,c.x-c.w/2),r=Math.max(r,c.x+c.w/2),s=Math.min(s,c.y-c.h/2),o=Math.max(o,c.y+c.h/2);return Number.isFinite(t)?{x0:t,y0:s,x1:r,y1:o}:null}const vt=(e,t,s)=>e<t?t:e>s?s:e;function No(e,t,s,{padding:r=.12,minZoom:o=.2,maxZoom:c=1.2}={}){const a=Math.max(1,e.x1-e.x0),l=Math.max(1,e.y1-e.y0),h=vt(Math.min(t/(a*(1+r)),s/(l*(1+r))),o,c);return{z:h,x:t/2-(e.x0+e.x1)/2*h,y:s/2-(e.y0+e.y1)/2*h}}function So(e,t,s=0){if(e===t){const v=e.x+e.w/2,N=e.y-e.h/2;return[{x:v-30,y:N},{x:v-30,y:N-26},{x:v+22,y:N-26},{x:v+22,y:e.y-6},{x:v,y:e.y-6}]}const r=s*8,o=e.x+e.w/2,c=e.y+vt(r,-e.h/2+6,e.h/2-6),a=t.x-t.w/2,l=t.y+vt(r,-t.h/2+6,t.h/2-6);if(a-o>=40){const v=(o+a)/2+r;return[{x:o,y:c},{x:v,y:c},{x:v,y:l},{x:a,y:l}]}const h=Math.max(e.y+e.h/2,t.y+t.h/2)+24+Math.abs(r),i=Math.min(e.y-e.h/2,t.y-t.h/2)-24-Math.abs(r),g=(c+l)/2,p=Math.abs(h-g)<=Math.abs(i-g)?h:i,f=o+24+Math.abs(r),m=a-24-Math.abs(r);return[{x:o,y:c},{x:f,y:c},{x:f,y:p},{x:m,y:p},{x:m,y:l},{x:a,y:l}]}function jo(e,t,s){const r=s.x-t.x,o=s.y-t.y,c=r*r+o*o,a=c?vt(((e.x-t.x)*r+(e.y-t.y)*o)/c,0,1):0;return Math.hypot(e.x-(t.x+a*r),e.y-(t.y+a*o))}function Eo(e,t){let s=Number.POSITIVE_INFINITY;for(let r=0;r<t.length-1;r++)s=Math.min(s,jo(e,t[r],t[r+1]));return s}function Co(e,t){return Math.abs(t.x-e.x)<=e.w/2&&Math.abs(t.y-e.y)<=e.h/2}class Xe{cells=new Set;static CELL_W=12;static CELL_H=16;keys(t){const s=[],r=Math.floor(t.x0/Xe.CELL_W),o=Math.floor(t.x1/Xe.CELL_W),c=Math.floor(t.y0/Xe.CELL_H),a=Math.floor(t.y1/Xe.CELL_H);for(let l=r;l<=o;l++)for(let h=c;h<=a;h++)s.push(l*1e5+h);return s}isFree(t){return this.keys(t).every(s=>!this.cells.has(s))}reserve(t){for(const s of this.keys(t))this.cells.add(s)}}function _o(e,t,s,r,o){const c=e.slice(0,-1).map((p,f)=>({i:f,length:Math.hypot(e[f+1].x-p.x,e[f+1].y-p.y)})).sort((p,f)=>f.length-p.length);if(c.length===0)return null;const a=p=>({x0:p.x-t/2,x1:p.x+t/2,y0:p.y-s/2,y1:p.y+s/2}),l=p=>({x:(e[p].x+e[p+1].x)/2,y:(e[p].y+e[p+1].y)/2});for(const{i:p,length:f}of c){if(!o&&f<t*.7)break;const m=l(p);if(r.isFree(a(m)))return r.reserve(a(m)),m}if(!o)return null;const h=l(c[0].i),g=[-1,1,-1.6,1.6].map(p=>({x:h.x,y:h.y+p*(s+12)})).find(p=>r.isFree(a(p)))??h;return r.reserve(a(g)),g}const Mo=e=>n.jsx(Ct,{icon:e||null,className:"h-4 w-4"}),To='600 14px "DM Sans", system-ui, sans-serif',Lo='400 11px "DM Sans", system-ui, sans-serif',Ro='500 9px "DM Sans", system-ui, sans-serif',Io='500 11px "DM Sans", system-ui, sans-serif',at=18,hn=8;function gn(e){const t=getComputedStyle(e),s=(r,o)=>t.getPropertyValue(r).trim()||o;return{foreground:s("--foreground","#141414"),muted:s("--muted-foreground","#545454"),card:s("--card","#ffffff"),background:s("--background","#fcfcfb"),border:s("--border","#e7e4dc"),primary:s("--primary","#2f63e8"),mutedSurface:s("--muted","#f3f1ea")}}function ft(e,t,s){if(e.measureText(t).width<=s)return t;let r=0,o=t.length;for(;r<o;){const c=Math.ceil((r+o)/2);e.measureText(`${t.slice(0,c)}…`).width<=s?r=c:o=c-1}return`${t.slice(0,r)}…`}function $o(e,t,s,r){const o=Math.hypot(s.x-t.x,s.y-t.y);if(o<1)return;const c=(s.x-t.x)/o,a=(s.y-t.y)/o;e.moveTo(s.x-c*r-a*r*.55,s.y-a*r+c*r*.55),e.lineTo(s.x,s.y),e.lineTo(s.x-c*r+a*r*.55,s.y-a*r-c*r*.55)}function cs({boxes:e,edges:t,label:s,onOpenBox:r,openLabel:o,onConnect:c,renderIcon:a=Mo,className:l}){const h=w.useRef(null),i=w.useRef(null),g=w.useRef(null),p=w.useRef({z:1,x:0,y:0}),f=w.useRef({w:0,h:0,dpr:1}),m=w.useRef(!0),v=w.useRef(new Map),N=w.useRef(null),d=w.useRef(null),j=w.useRef(new Map),S=w.useRef(null),E=w.useRef(""),k=w.useRef(!1),[y,x]=w.useState(()=>new Map),[T,$]=w.useState(null),[F,A]=w.useState(null),[K,H]=w.useState(null),[se,W]=w.useState(null),[ge,ne]=w.useState(0),{placed:U,movedIds:Ce}=w.useMemo(()=>{const C=new Map,u=new Set;for(const M of e){const b=y.get(M.id);b&&b.from.x===M.x&&b.from.y===M.y?(C.set(M.id,{...M,x:b.at.x,y:b.at.y}),u.add(M.id)):C.set(M.id,M)}return{placed:C,movedIds:u}},[e,y]),ue=w.useMemo(()=>{const C=new Map;for(const M of t){const b=[M.source,M.target].sort().join("|");C.set(b,[...C.get(b)??[],M])}const u=new Map;for(const M of t){const b=U.get(M.source),_=U.get(M.target);if(!b||!_)continue;if(M.route&&!Ce.has(b.id)&&!Ce.has(_.id)){u.set(M.id,M.route);continue}const L=C.get([M.source,M.target].sort().join("|"))??[M];u.set(M.id,So(b,_,L.indexOf(M)-(L.length-1)/2))}return u},[t,U,Ce]),Q=w.useCallback(()=>{m.current=!0},[]),ee=w.useCallback(()=>{const C=pn([...U.values()]),{w:u,h:M}=f.current;!C||!u||!M||(p.current=No(C,u,M),k.current=!0,Q())},[U,Q]),me=C=>{p.current=C,k.current=!1,Q()},_e=C=>{const u=pn(C),{w:M,h:b}=f.current;if(!u||!M||!b)return;const _=p.current,L=24;u.x0*_.z+_.x>=L&&u.y0*_.z+_.y>=L&&u.x1*_.z+_.x<=M-L&&u.y1*_.z+_.y<=b-L||me({..._,x:M/2-(u.x0+u.x1)/2*_.z,y:b/2-(u.y0+u.y1)/2*_.z})},Ue=C=>{W(C);const u=U.get(C);u&&_e([u])},ae=e.map(C=>`${C.id}@${Math.round(C.x)},${Math.round(C.y)}`).join(";");w.useEffect(()=>{!ae||E.current===ae||f.current.w&&(E.current=ae,ee())},[ae,ee]);const ve=w.useRef(ee);ve.current=ee;const Fe=w.useRef(ae);Fe.current=ae,w.useEffect(()=>{const C=h.current,u=i.current;if(!C||!u||typeof ResizeObserver>"u")return;const M=()=>{const _=window.devicePixelRatio||1,L=C.clientWidth,z=C.clientHeight;f.current={w:L,h:z,dpr:_},u.width=Math.round(L*_),u.height=Math.round(z*_);const P=Fe.current;P&&L&&z&&(E.current!==P||k.current)&&(E.current=P,ve.current()),Q()};M();const b=new ResizeObserver(M);return b.observe(C),()=>b.disconnect()},[Q]);const[Me,Te]=w.useState(0);w.useEffect(()=>{const C=g.current,u=i.current;if(!C||!u)return;const M=gn(u).muted;for(const b of C.querySelectorAll("[data-icon-key]")){const _=b.dataset.iconKey??"";if(v.current.has(_))continue;const L=b.querySelector("svg"),z=L?null:b.querySelector("img")?.src;if(!L&&!z){v.current.set(_,b.textContent??"");continue}const P=new Image;if(P.onload=Q,P.onerror=()=>{v.current.delete(_),Te(O=>O+1)},L){const O=L.cloneNode(!0);O.getAttribute("width")||O.setAttribute("width","24"),O.getAttribute("height")||O.setAttribute("height","24");const D=new XMLSerializer().serializeToString(O).replaceAll("currentColor",M);P.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(D)}`}else z&&(P.src=z);v.current.set(_,P)}},[e,ge,Me,Q]);const we=(C,u)=>{const M=p.current;return{x:(C-M.x)/M.z,y:(u-M.y)/M.z}},ze=(C,u)=>{const M=p.current,b=we(C,u),_=T&&T.kind!=="edge"?U.get(T.box.id):void 0;if(_&&c){const O=yn(_);if(Math.hypot(O.x*M.z+M.x-C,O.y*M.z+M.y-u)<=hn+3)return{kind:"handle",box:_}}const L=[...U.values()];for(let O=L.length-1;O>=0;O--)if(Co(L[O],b))return{kind:"box",box:L[O]};let z=null,P=7/M.z;for(const O of t){const D=ue.get(O.id);if(!D)continue;const ie=Eo(b,D);ie<P&&(P=ie,z=O)}return z?{kind:"edge",edge:z}:null},fe=w.useMemo(()=>{const C=new Set;for(const M of[F,K])M&&C.add(M);T?.kind==="edge"&&C.add(T.edge.id);const u=T&&T.kind!=="edge"?T.box.id:se;if(u)for(const M of t)(M.source===u||M.target===u)&&C.add(M.id);for(const M of t)M.dimmed&&C.delete(M.id);return C},[t,T,F,K,se]);w.useEffect(Q,[U,ue,fe,T,se,Q]);const ke=w.useCallback(()=>{const C=i.current,u=C?.getContext("2d");if(!C||!u)return;const{w:M,h:b,dpr:_}=f.current,L=gn(C),z=getComputedStyle(C),P=new Map,O=I=>{let G=P.get(I);return G===void 0&&(G=z.getPropertyValue(I).trim(),P.set(I,G)),G},{z:D,x:ie,y:re}=p.current,be=I=>({x:I.x*D+ie,y:I.y*D+re});u.setTransform(_,0,0,_,0,0),u.clearRect(0,0,M,b);const Ie=T&&T.kind!=="edge"?T.box.id:null;u.lineJoin="round";for(const I of t){const G=ue.get(I.id);if(!G)continue;const J=G.map(be),B=fe.has(I.id);u.globalAlpha=I.dimmed?.15:B?.95:.55,u.strokeStyle=B?L.foreground:L.muted,u.lineWidth=B?1.75:1.25,u.beginPath(),u.moveTo(J[0].x,J[0].y);for(const X of J.slice(1))u.lineTo(X.x,X.y);I.directed&&$o(u,J[J.length-2],J[J.length-1],8),u.stroke()}const Ge=new Xe;for(const I of U.values()){const G=be(I),J=I.w*D,B=I.h*D,X=G.x-J/2,q=G.y-B/2;if(Ge.reserve({x0:X,y0:q,x1:X+J,y1:q+B}),X>M||q>b||X+J<0||q+B<0)continue;const Oe=Ie===I.id||S.current?.over?.id===I.id;u.globalAlpha=I.dimmed?.25:1,u.beginPath(),u.roundRect(X,q,J,B,8*D),u.fillStyle=I.muted?L.mutedSurface:L.card,u.fill(),u.lineWidth=Oe||se===I.id?1.5:1,u.strokeStyle=Oe||se===I.id?L.primary:L.border,u.stroke();const te=I.accent&&O(I.accent);if(te&&(u.save(),u.clip(),u.fillStyle=te,u.fillRect(X,q,3*D,B),u.restore()),14*D<5)continue;const de=12*D,Z=16*D,ce=I.meta?q+B/2-8*D:q+B/2,je=v.current.get(I.icon??"");je instanceof HTMLImageElement&&je.complete&&je.naturalWidth>0?u.drawImage(je,X+de,ce-Z/2,Z,Z):typeof je=="string"&&je&&(u.font=`${14*D}px system-ui, sans-serif`,u.textBaseline="middle",u.textAlign="left",u.fillText(je,X+de,ce));const We=X+de+Z+8*D,st=12*D;u.textBaseline="middle",u.textAlign="left";let Je=X+J-st-We;if(I.badge){u.font=Ro.replace("9px",`${9*D}px`);const rt=ft(u,I.badge.toUpperCase(),Je*.35),Qe=u.measureText(rt).width+8*D,ot=X+J-st-Qe;u.strokeStyle=L.border,u.lineWidth=1,u.beginPath(),u.roundRect(ot,ce-7*D,Qe,14*D,3*D),u.stroke(),u.fillStyle=L.muted,u.fillText(rt,ot+4*D,ce+.5),Je-=Qe+6*D}u.font=To.replace("14px",`${14*D}px`),u.fillStyle=L.foreground,u.fillText(ft(u,I.title,Je),We,ce+.5),I.meta&&(u.font=Lo.replace("11px",`${11*D}px`),u.fillStyle=L.muted,u.fillText(ft(u,I.meta,X+J-de-We),We,q+B/2+10*D))}const $e=S.current,Ye=$e?.from??(Ie?U.get(Ie):void 0);if(c&&Ye&&Ye.w*D>=60){const I=be(yn(Ye));if(u.globalAlpha=1,$e){const G=be($e.to);u.strokeStyle=L.primary,u.lineWidth=2,u.setLineDash([6,4]),u.beginPath(),u.moveTo(I.x,I.y),u.lineTo(G.x,G.y),u.stroke(),u.setLineDash([])}u.fillStyle=L.card,u.strokeStyle=L.primary,u.lineWidth=1.5,u.beginPath(),u.arc(I.x,I.y,hn,0,Math.PI*2),u.fill(),u.stroke(),u.beginPath(),u.moveTo(I.x-4,I.y),u.lineTo(I.x+4,I.y),u.moveTo(I.x,I.y-4),u.lineTo(I.x,I.y+4),u.stroke()}u.font=Io,u.textAlign="center",u.textBaseline="middle";const Ke=(I,G,J,B)=>{u.globalAlpha=1,u.fillStyle=L.background,u.strokeStyle=J?L.foreground:L.border,u.lineWidth=1,u.beginPath(),u.roundRect(I.x-B/2,I.y-at/2,B,at,5),u.fill(),u.stroke(),u.fillStyle=J?L.foreground:L.muted,u.fillText(G,I.x,I.y+.5)},Tt=[...t].sort((I,G)=>Number(fe.has(G.id))-Number(fe.has(I.id)));for(const I of Tt){const G=ue.get(I.id);if(!G||I.dimmed&&!fe.has(I.id))continue;const J=G.map(be),B=fe.has(I.id),q=(B?I.details:[I.summary]).map(Z=>ft(u,Z,200)),Oe=Math.max(...q.map(Z=>u.measureText(Z).width))+14,te=q.length*(at+2);if(!B&&D<.45)continue;const de=_o(J,Oe,te,Ge,B);de&&q.forEach((Z,ce)=>{Ke({x:de.x,y:de.y-te/2+(at+2)*ce+at/2},Z,B,Oe)})}u.globalAlpha=1},[t,ue,U,fe,T,se,c]);w.useEffect(()=>{let C=0;const u=()=>{C=requestAnimationFrame(u),m.current&&(m.current=!1,ke())};return C=requestAnimationFrame(u),document.addEventListener("visibilitychange",Q),()=>{cancelAnimationFrame(C),document.removeEventListener("visibilitychange",Q)}},[ke,Q]),w.useEffect(()=>{const C=new MutationObserver(()=>{v.current.clear(),ne(u=>u+1),Q()});return C.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),()=>C.disconnect()},[Q]);const ye=(C,u,M)=>{const b=p.current,_=Math.min(3,Math.max(.15,b.z*C));me({z:_,x:u-(u-b.x)*(_/b.z),y:M-(M-b.y)*(_/b.z)})},Ne=C=>{const u=i.current?.getBoundingClientRect();return{x:C.clientX-(u?.left??0),y:C.clientY-(u?.top??0)}},le=C=>{if(C.button!==0&&C.pointerType==="mouse")return;C.currentTarget.setPointerCapture(C.pointerId);const u=Ne(C);if(C.pointerType==="touch"&&(j.current.set(C.pointerId,u),j.current.size===2)){const[_,L]=[...j.current.values()];N.current=null,S.current=null,d.current={d:Math.hypot(_.x-L.x,_.y-L.y)||1,mid:{x:(_.x+L.x)/2,y:(_.y+L.y)/2}};return}const M=ze(u.x,u.y),b={start:u,last:u,hit:M,moved:!1};if(M?.kind==="handle")S.current={from:M.box,to:we(u.x,u.y),over:null};else if(M?.kind==="box"){const _=we(u.x,u.y);b.grab={x:M.box.x-_.x,y:M.box.y-_.y}}N.current=b},Le=C=>{const u=Ne(C);j.current.has(C.pointerId)&&j.current.set(C.pointerId,u);const M=d.current;if(M&&j.current.size===2){const[O,D]=[...j.current.values()],ie=Math.hypot(O.x-D.x,O.y-D.y)||1,re={x:(O.x+D.x)/2,y:(O.y+D.y)/2};me({...p.current,x:p.current.x+re.x-M.mid.x,y:p.current.y+re.y-M.mid.y}),ye(ie/M.d,re.x,re.y),d.current={d:ie,mid:re};return}const b=N.current;if(!b){const O=ze(u.x,u.y);$(ie=>Oo(ie,O)?ie:O);const D=i.current;D&&(D.style.cursor=O?.kind==="handle"?"crosshair":O?"pointer":"grab");return}const _=u.x-b.last.x,L=u.y-b.last.y;if(b.last=u,!b.moved&&Math.hypot(u.x-b.start.x,u.y-b.start.y)>4&&(b.moved=!0),!b.moved)return;const z=S.current;if(z){z.to=we(u.x,u.y);const O=ze(u.x,u.y);z.over=O?.kind==="box"?O.box:null,Q();return}const P=b.hit;if(P?.kind==="box"&&b.grab){const O=we(u.x,u.y),D=e.find(re=>re.id===P.box.id);if(!D)return;const ie={x:O.x+b.grab.x,y:O.y+b.grab.y};x(re=>new Map(re).set(D.id,{at:ie,from:{x:D.x,y:D.y}}));return}me({...p.current,x:p.current.x+_,y:p.current.y+L}),i.current&&(i.current.style.cursor="grabbing")},Se=C=>{if(j.current.delete(C.pointerId),d.current){j.current.size<2&&(d.current=null),N.current=null;return}const u=N.current;N.current=null;const M=S.current;if(S.current=null,!u)return;if(i.current&&(i.current.style.cursor="grab"),M){Q(),M.over&&c&&c(M.from.id,M.over.id);return}if(u.moved)return;const b=u.hit;b?.kind==="box"?r(b.box.id):b?.kind==="edge"?A(_=>_===b.edge.id?null:b.edge.id):A(null)},xe=C=>{j.current.delete(C.pointerId),d.current=null,N.current=null,S.current=null,Q()};w.useEffect(()=>{const C=i.current;if(!C)return;const u=M=>{M.preventDefault();const b=Ne(M);M.ctrlKey||M.metaKey?ye(Math.exp(-M.deltaY*(M.ctrlKey?.01:.002)),b.x,b.y):me({...p.current,x:p.current.x-M.deltaX,y:p.current.y-M.deltaY})};return C.addEventListener("wheel",u,{passive:!1}),()=>C.removeEventListener("wheel",u)});const qe=C=>ye(C,f.current.w/2,f.current.h/2),Re=[...new Set(e.map(C=>C.icon??""))];return n.jsxs("div",{ref:h,className:oe("relative h-full w-full overflow-hidden",l),children:[n.jsx("canvas",{ref:i,"aria-hidden":"true",className:"block h-full w-full cursor-grab touch-none",onPointerDown:le,onPointerMove:Le,onPointerUp:Se,onPointerCancel:xe,onPointerLeave:()=>{N.current||$(null)}}),n.jsxs("ul",{ref:g,"aria-label":s,className:"sr-only",children:[Re.map(C=>n.jsx("li",{"aria-hidden":"true","data-icon-key":C,children:a(C)},`icon:${C}`)),e.map(C=>n.jsx("li",{children:n.jsx("button",{type:"button",onClick:()=>r(C.id),onFocus:()=>Ue(C.id),onBlur:()=>W(null),children:o(C)})},C.id)),t.map(C=>n.jsx("li",{"data-revealed":fe.has(C.id)||void 0,children:n.jsx("button",{type:"button","aria-pressed":F===C.id,onClick:()=>A(u=>u===C.id?null:C.id),onFocus:()=>{H(C.id);const u=ue.get(C.id);u&&_e(u.map(M=>({...M,w:0,h:0})))},onBlur:()=>H(null),children:C.ariaLabel})},C.id))]}),n.jsxs("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:[n.jsx(V,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom in",onClick:()=>qe(1.25),children:n.jsx(ct,{className:"h-3.5 w-3.5"})}),n.jsx(V,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom out",onClick:()=>qe(.8),children:n.jsx(js,{className:"h-3.5 w-3.5"})}),n.jsx(V,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Fit to view",onClick:ee,children:n.jsx(Es,{className:"h-3.5 w-3.5"})}),Ce.size>0?n.jsx(V,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Reset layout",onClick:()=>x(new Map),children:n.jsx(Cs,{className:"h-3.5 w-3.5"})}):null]})]})}const yn=e=>({x:e.x+e.w/2,y:e.y});function Oo(e,t){return!e||!t?e===t:e.kind==="edge"||t.kind==="edge"?e.kind==="edge"&&t.kind==="edge"&&e.edge.id===t.edge.id:e.kind===t.kind&&e.box.id===t.box.id}function Xt({label:e,fill:t=!1,schemaActions:s=!1}){return n.jsxs("div",{role:"status","aria-label":e,"aria-busy":"true",className:oe("flex min-w-0 flex-col gap-3",t&&"min-h-0 flex-1"),children:[n.jsx("div",{"aria-hidden":"true",children:n.jsx(Be,{className:"h-5 w-3/4 max-w-xl rounded-none"})}),n.jsxs("div",{className:oe("relative flex min-h-0 flex-col",t&&"flex-1"),"aria-hidden":"true",children:[s?n.jsxs("div",{className:"z-10 flex flex-wrap justify-end gap-2 lg:absolute lg:top-0 lg:right-0",children:[n.jsx(Be,{className:"h-8 w-40 rounded-none"}),n.jsx(Be,{className:"h-8 w-36 rounded-none"})]}):null,n.jsxs("div",{className:oe("relative min-h-[420px]",t?"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(Be,{className:"h-4 w-4 shrink-0 rounded-none"}),n.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[n.jsx(Be,{className:"h-3.5 w-24 rounded-none"}),n.jsx(Be,{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(Be,{className:"h-3 w-3 rounded-none"})},r))})]})]})]})}function pt(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var zt={exports:{}},xn;function Ao(){return xn||(xn=1,(function(e,t){(function(s){e.exports=s()})(function(){return(function(){function s(r,o,c){function a(i,g){if(!o[i]){if(!r[i]){var p=typeof pt=="function"&&pt;if(!g&&p)return p(i,!0);if(l)return l(i,!0);var f=new Error("Cannot find module '"+i+"'");throw f.code="MODULE_NOT_FOUND",f}var m=o[i]={exports:{}};r[i][0].call(m.exports,function(v){var N=r[i][1][v];return a(N||v)},m,m.exports,s,r,o,c)}return o[i].exports}for(var l=typeof pt=="function"&&pt,h=0;h<c.length;h++)a(c[h]);return a}return s})()({1:[function(s,r,o){Object.defineProperty(o,"__esModule",{value:!0}),o.default=void 0;function c(f){"@babel/helpers - typeof";return c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(m){return typeof m}:function(m){return m&&typeof Symbol=="function"&&m.constructor===Symbol&&m!==Symbol.prototype?"symbol":typeof m},c(f)}function a(f,m){if(!(f instanceof m))throw new TypeError("Cannot call a class as a function")}function l(f,m){for(var v=0;v<m.length;v++){var N=m[v];N.enumerable=N.enumerable||!1,N.configurable=!0,"value"in N&&(N.writable=!0),Object.defineProperty(f,i(N.key),N)}}function h(f,m,v){return m&&l(f.prototype,m),Object.defineProperty(f,"prototype",{writable:!1}),f}function i(f){var m=g(f,"string");return c(m)=="symbol"?m:m+""}function g(f,m){if(c(f)!="object"||!f)return f;var v=f[Symbol.toPrimitive];if(v!==void 0){var N=v.call(f,m);if(c(N)!="object")return N;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(f)}o.default=(function(){function f(){var m=this,v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},N=v.defaultLayoutOptions,d=N===void 0?{}:N,j=v.algorithms,S=j===void 0?["layered","stress","mrtree","radial","force","disco","sporeOverlap","sporeCompaction","rectpacking"]:j,E=v.workerFactory,k=v.workerUrl;if(a(this,f),this.defaultLayoutOptions=d,this.initialized=!1,typeof k>"u"&&typeof E>"u")throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");var y=E;typeof k<"u"&&typeof E>"u"&&(y=function($){return new Worker($)});var x=y(k);if(typeof x.postMessage!="function")throw new TypeError("Created worker does not provide the required 'postMessage' function.");this.worker=new p(x),this.worker.postMessage({cmd:"register",algorithms:S}).then(function(T){return m.initialized=!0}).catch(console.err)}return h(f,[{key:"layout",value:function(v){var N=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d=N.layoutOptions,j=d===void 0?this.defaultLayoutOptions:d,S=N.logging,E=S===void 0?!1:S,k=N.measureExecutionTime,y=k===void 0?!1:k;return v?this.worker.postMessage({cmd:"layout",graph:v,layoutOptions:j,options:{logging:E,measureExecutionTime:y}}):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 p=(function(){function f(m){var v=this;if(a(this,f),m===void 0)throw new Error("Missing mandatory parameter 'worker'.");this.resolvers={},this.worker=m,this.worker.onmessage=function(N){setTimeout(function(){v.receive(v,N)},0)}}return h(f,[{key:"postMessage",value:function(v){var N=this.id||0;this.id=N+1,v.id=N;var d=this;return new Promise(function(j,S){d.resolvers[N]=function(E,k){E?(d.convertGwtStyleError(E),S(E)):j(k)},d.worker.postMessage(v)})}},{key:"receive",value:function(v,N){var d=N.data,j=v.resolvers[d.id];j&&(delete v.resolvers[d.id],d.error?j(d.error):j(null,d.data))}},{key:"terminate",value:function(){this.worker&&this.worker.terminate()}},{key:"convertGwtStyleError",value:function(v){if(v){var N=v.__java$exception;N&&(N.cause&&N.cause.backingJsObject&&(v.cause=N.cause.backingJsObject,this.convertGwtStyleError(v.cause)),delete v.__java$exception)}}}])})()},{}],2:[function(s,r,o){var c=s("./elk-api.js").default;Object.defineProperty(r.exports,"__esModule",{value:!0}),r.exports=c,c.default=c},{"./elk-api.js":1}]},{},[2])(2)})})(zt)),zt.exports}var Po=Ao();const Do=_s(Po);function Fo(e){return new Worker("/assets/elk-worker.min-BENGc9gn.js",{name:e?.name})}const zo=200,Wo=320,et=56,Bo=7.4,Ho=5.9,Vo=84,Uo=48;function lt(e,t){return Math.round(Math.min(Wo,Math.max(zo,Vo+e.length*Bo,Uo+t.length*Ho)))}function qo(e,t){const s=[];return e>0&&s.push(`${e} ${e===1?"field":"fields"}`),typeof t=="number"&&s.push(`${t.toLocaleString()} ${t===1?"record":"records"}`),s.join(" · ")}function bn(e,t){return e.slug<t.slug?-1:e.slug>t.slug?1:0}function ls(e,t){const s=new Set;return e.filter(r=>r.status!=="active"||r.organization_slug&&r.organization_slug!==t||s.has(r.slug)?!1:(s.add(r.slug),!0))}function Go(e){const t=e.metadata_schema;if(!t||typeof t!="object")return 0;const s=t.properties;return!s||typeof s!="object"?0:Object.keys(s).length}function ds(e){const{entityTypes:t,relationshipTypes:s,rulesBySlug:r}=e,o=e.ownerSlug??"",c=[...t].sort(bn),a=ls(s,o).sort(bn),l=y=>!y.organization_slug||y.organization_slug===o,h=y=>y.organization_slug||o,i=new Map;for(const y of c)i.set(y.slug,[...i.get(y.slug)??[],y]);const g=y=>(i.get(y.slug)?.length??0)>1?`${h(y)}:${y.slug}`:y.slug,p=new Set(c.filter(l).map(g)),f=y=>{const x=i.get(y)??[];return x.find(l)??(x.length===1?x[0]:void 0)},m=new Set(p),v=a.flatMap(y=>[...r[y.slug]??[]].sort((x,T)=>x.id-T.id).flatMap(x=>{const T=f(x.source_entity_type_slug),$=f(x.target_entity_type_slug);if(!T||!$)return[];const F=g(T),A=g($);return!p.has(F)&&!p.has(A)?[]:(m.add(F),m.add(A),[{rt:y,source:F,target:A}])})),N=c.filter(y=>m.has(g(y))),d=[],j=new Map,S=new Map;for(const{rt:y,source:x,target:T}of v){const $=`${y.slug}|${x}|${T}`,F=S.get($);if(F){F.ruleCount+=1;continue}const A={slug:y.slug,label:y.name||y.slug,ruleCount:1};S.set($,A);const K=`${x}|${T}`,H=j.get(K);if(H){H.data.relationships.push(A),H.data.isSymmetric=H.data.isSymmetric&&y.is_symmetric;continue}const se={id:`pair:${x}|${T}`,source:x,target:T,data:{relationships:[A],isSymmetric:y.is_symmetric}};j.set(K,se),d.push(se)}const E=new Map;for(const{rt:y,source:x,target:T}of v){const $=E.get(y.slug)??new Set;$.add(`${x}|${T}`),E.set(y.slug,$)}for(const{rt:y}of v)if(E.get(y.slug)?.size===1&&typeof y.relationship_count=="number")for(const x of S.values())x.slug===y.slug&&(x.linkCount=y.relationship_count);return{nodes:N.map(y=>{const x=y.name||y.slug,T=Go(y),$=qo(T,y.entity_count);return{id:g(y),width:lt(x,$),height:et,data:{slug:y.slug,label:x,icon:y.icon,isSystem:Ms(y),organizationSlug:l(y)?void 0:h(y),metaLabel:$}}}),edges:d}}const He=24,Yo=72,Ko=16;let vn=null;function Jo(){return vn??=new Do({workerFactory:()=>new Fo}),vn}const Wt={"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 Zt(e,{elk:t=Jo(),targetAspect:s}={}){const r=new Set;for(const d of e.edges)r.add(d.source),r.add(d.target);const o=e.nodes.some(d=>d.lane!==void 0),c=e.nodes.filter(d=>o||r.has(d.id)),a=e.nodes.filter(d=>!o&&!r.has(d.id)),l=a.reduce((d,j)=>Math.max(d,j.width),0),h=a.length>0?He+l+Yo:0,i=d=>({x:d.x+He+h,y:d.y+He});let g=[];const p=new Map;if(c.length>0){const d=e.edges.filter(y=>y.source!==y.target),j=y=>t.layout({id:"root",layoutOptions:o?{...y,"elk.partitioning.activate":"true"}:y,children:c.map(x=>({id:x.id,width:x.width,height:x.height,...o?{layoutOptions:{"elk.partitioning.partition":String(x.lane??1)}}:{}})),edges:d.map(x=>({id:x.id,sources:[x.layoutReversed?x.target:x.source],targets:[x.layoutReversed?x.source:x.target]}))});let S=await j(Wt);const E=s&&S.width&&S.height?s*S.width/S.height:1;if(E>1.08){const y=Number(Wt["elk.spacing.nodeNode"]),x=Math.min(E,2.2);S=await j({...Wt,"elk.spacing.nodeNode":String(Math.round(Math.min(180,y*x+et*(x-1))))})}const k=new Map((S.children??[]).map(y=>[y.id,y]));g=c.map(y=>{const x=k.get(y.id);return{...y,position:i({x:x?.x??0,y:x?.y??0})}});for(const y of S.edges??[]){const x=(y.sections??[]).flatMap($=>[$.startPoint,...$.bendPoints??[],$.endPoint]);if(x.length<2)continue;const T=e.edges.find($=>$.id===y.id)?.layoutReversed;p.set(y.id,(T?[...x].reverse():x).map(i))}}let f=He;const m=a.map(d=>{const j={x:He,y:f};return f+=d.height+Ko,{...d,position:j}}),v=new Map([...g,...m].map(d=>[d.id,d]));return{nodes:e.nodes.map(d=>v.get(d.id)??{...d,position:{x:He,y:He}}),edges:e.edges.map(d=>({...d,route:p.get(d.id)??null}))}}function Qo(e,t){return Zt(ds(e),t)}const Ut="connector:",wn=e=>`${Ut}${e}`,Xo={event:"Zap",schedule:"CalendarClock",manual:"Hand"},Zo=0,ea=1,kn=2;function ta(e,t){const s=new Map;for(const{kind:r,targets:o}of Qr(e?.feeds_schema?.[t]))for(const{entityType:c,creates:a}of o){const l=s.get(c)??{creates:!1,eventKinds:new Set};l.creates||=a,l.eventKinds.add(r),s.set(c,l)}return s}function na(e,t){const s=new Map(e.connectorDefs.map(d=>[d.key,d])),r=new Map(e.connectorDefs.map(d=>[d.key,d.name])),o=new Map(e.connections.map(d=>[d.id,d])),c=qr(e.feeds),a=d=>`connection:${d}`,l=d=>`automation:${d}`,h=[],i=new Set,g=(d,j,S,E,k=!1)=>{h.push({id:`flow:${d}->${j}`,source:d,target:j,layoutReversed:k,data:{relationships:[],isSymmetric:!1,flow:{summary:S,details:E}}}),i.add(d),i.add(j)},p=new Set(e.connections.map(d=>d.id));for(const d of e.connections){const j=new Map;for(const S of c.get(d.id)??[]){const E=ta(s.get(d.connector_key),S.feed_key);for(const[k,y]of E){const x=j.get(k)??{creates:!1,eventKinds:new Set};x.creates||=y.creates;for(const T of y.eventKinds)x.eventKinds.add(T);j.set(k,x)}}for(const[S,E]of j){const k=t.get(S);k&&g(a(d.id),k,E.creates?"creates records":"links records",[`From ${[...E.eventKinds].sort().join(", ")} events`])}}const f=Gr(e.automations);for(const[d,j]of f)if(p.has(d))for(const{automation:S,reason:E,eventTypes:k}of j){const y=l(S.automation_id);E==="trigger"?g(a(d),y,fn.trigger,k.length>0?[`On ${[...k].sort().join(", ")}`]:[]):g(y,a(d),fn.delivery,[],!0)}const m=[];for(const d of e.automations){const j=l(d.automation_id),S=d.entity_type?t.get(d.entity_type):void 0;S&&g(S,j,"anchored here",[d.entity_name?`On ${d.entity_name}`:""].filter(Boolean));const E=Ts(d,r,o),k=Ls(d),y=d.health==="degraded"?"Needs attention":void 0;m.push({id:j,lane:kn,width:lt(`${E.does} ${y??""}`,E.when),height:et,data:{slug:j,label:E.does,icon:k?wn(k):Xo[E.kind],isSystem:!1,badge:y,metaLabel:E.when,ref:{kind:"automation",automationId:d.automation_id}}})}const v=[];for(const d of e.metrics){const j=t.get(d.typeSlug);if(!j)continue;const S=`metric:${d.typeSlug}:${d.name}`;g(j,S,"measures",[d.description].filter(Boolean)),v.push({id:S,lane:kn,width:lt(d.name,d.agg),height:et,data:{slug:S,label:d.name,icon:"ChartColumn",isSystem:!1,metaLabel:d.agg,ref:{kind:"metric",typeSlug:d.typeSlug,name:d.name}}})}return{nodes:[...e.connections.filter(d=>i.has(a(d.id))).map(d=>{const j=Rs(d),S=Is(d,s.get(d.connector_key)),E=Yr({feeds:c.get(d.id)?.length||d.feed_count,actions:d.operations_summary?.total??0,automations:f.get(d.id)?.length??0}),k=S.needsAttention?"Needs attention":d.device_label??void 0;return{id:a(d.id),lane:Zo,width:lt(`${j} ${k??""}`,E),height:et,data:{slug:a(d.id),label:j,icon:wn(d.connector_key),isSystem:!1,badge:k,metaLabel:E,ref:{kind:"connection",connectorKey:d.connector_key,connectionId:d.id}}}}),...m,...v],edges:h}}function it(e){switch(e.data.ref?.kind){case"connection":return"connections";case"automation":return"automations";case"metric":return"metrics";default:return"entities"}}function sa(e,t){const s=new Map;for(const g of e.nodes)(!g.data.organizationSlug||!s.has(g.data.slug))&&s.set(g.data.slug,g.id);const r=na(t,s),{layers:o}=t,c=[...r.nodes,...e.nodes.map(g=>({...g,lane:ea}))],a=new Set(c.filter(g=>o[it(g)]).map(g=>g.id)),l=[...e.edges,...r.edges].filter(g=>a.has(g.source)&&a.has(g.target)),h=new Set(l.flatMap(g=>[g.source,g.target]));return{graph:{nodes:c.filter(g=>a.has(g.id)&&(it(g)==="entities"||it(g)==="automations"||h.has(g.id))),edges:l},hidden:{connections:o.connections?t.connections.length-r.nodes.filter(g=>it(g)==="connections").length:0}}}const Nn="__new__";function Sn(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}function ra({entityTypes:e,initialSource:t="",initialTarget:s="",onDone:r}){const o=w.useId(),c=`${o}-relationship`,a=`${o}-name`,l=`${o}-symmetric`,h=`${o}-source`,i=`${o}-target`,{orgContext:g}=De(),{data:p=[]}=Kt(g),f=$s(),m=Os(),[v,N]=w.useState(""),[d,j]=w.useState(""),[S,E]=w.useState(!1),[k,y]=w.useState(t),[x,T]=w.useState(s),[$,F]=w.useState(null),A=v===Nn,K=p.filter(W=>W.status==="active"&&W.purpose!==As&&(!W.organization_slug||W.organization_slug===g?.slug)),H=f.isPending||m.isPending,se=async()=>{if(F(null),!v)return F("Pick a relationship");if(!k||!x)return F("Pick both ends");try{let W=v;if(A){const ge=d.trim();if(!ge)return F("Name the relationship");const ne=Sn(ge);if(!ne)return F("Name must contain a letter or number");W=(await f.mutateAsync({slug:ne,name:ge,is_symmetric:S})).relationship_type.slug,N(W)}await m.mutateAsync({slug:W,source_entity_type_slug:k,target_entity_type_slug:x}),r()}catch(W){F(W instanceof Error?W.message:"Could not save")}};return n.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-muted/30 p-3",children:[n.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Relationships are defined once for the workspace, then paired with the types they connect."}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Ae,{htmlFor:c,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"Relationship"}),n.jsxs($t,{value:v,onValueChange:N,children:[n.jsx(Ot,{id:c,className:"h-8 text-xs",children:n.jsx(At,{placeholder:"Pick or define one"})}),n.jsxs(Pt,{children:[K.map(W=>n.jsx(mt,{value:W.slug,children:W.name||W.slug},W.slug)),K.length>0?n.jsx(Ps,{}):null,n.jsx(mt,{value:Nn,children:"Define a new one…"})]})]})]}),A?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Ae,{htmlFor:a,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"Name"}),n.jsx(tt,{id:a,value:d,onChange:W=>j(W.target.value),placeholder:"works at",className:"h-8 text-xs"}),d.trim()?n.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Slug: ",n.jsx("code",{children:Sn(d)||"—"})]}):null]}),n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs(Ae,{htmlFor:l,className:"text-xs font-normal",children:["Symmetric",n.jsx("span",{className:"mt-0.5 block text-[11px] text-muted-foreground",children:"Both ends mean the same thing, like “connected with”."})]}),n.jsx(Ds,{id:l,checked:S,onCheckedChange:E})]})]}):null,n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Ae,{htmlFor:h,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"From"}),n.jsxs($t,{value:k,onValueChange:y,children:[n.jsx(Ot,{id:h,className:"h-8 text-xs",children:n.jsx(At,{placeholder:"Type"})}),n.jsx(Pt,{children:e.map(W=>n.jsx(mt,{value:W.slug,children:W.label},W.slug))})]})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(Ae,{htmlFor:i,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"To"}),n.jsxs($t,{value:x,onValueChange:T,children:[n.jsx(Ot,{id:i,className:"h-8 text-xs",children:n.jsx(At,{placeholder:"Type"})}),n.jsx(Pt,{children:e.map(W=>n.jsx(mt,{value:W.slug,children:W.label},W.slug))})]})]}),$?n.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:$}):null,n.jsx(On,{onCancel:r,cancelDisabled:H,className:"[&>button]:h-7 [&>button]:px-3 [&>button]:text-xs",children:n.jsx(V,{type:"button",size:"sm",onClick:se,disabled:H,children:H?"Saving…":"Add relationship"})})]})}const us=288,oa=440,wt=240,kt=720,aa=320,en="lobu.schema-panel-width:v1";function Nt(e,t){if(!Number.isFinite(e))return us;const s=Math.max(wt,Math.min(kt,t-aa));return Math.round(Math.min(s,Math.max(wt,e)))}function ia(){const e=An(en);if(e===null)return null;const t=Number.parseInt(e,10);return!Number.isFinite(t)||t<wt||t>kt?null:t}function ca(e){Pn(en,String(Math.round(e)))}function la(){Fs(en)}const jn={nodes:[],edges:[]};function da(e,t,s){const{orgContext:r}=De(),{data:o=[],isLoading:c,isError:a}=_t(r),{data:l=[],isLoading:h,isError:i}=Kt(r),g=w.useMemo(()=>ls(l,e),[l,e]),{data:p,isLoading:f,isError:m}=zs(r),v=w.useMemo(()=>{const k=new Map(g.map(x=>[x.id,x.slug])),y={};for(const x of p??[]){const T=k.get(x.relationship_type_id);T&&(y[T]??=[]).push(x)}return y},[p,g]),N=w.useMemo(()=>({entityTypes:o,relationshipTypes:g,rulesBySlug:v,ownerSlug:e,targetAspect:t,flow:s}),[o,g,v,e,t,s]),[d,j]=w.useState(null),S=c||h||f,E=a||i||m;return w.useEffect(()=>{if(S||E)return;let k=!1;const y={targetAspect:N.targetAspect};let x,T;if(N.flow){const $=sa(ds(N),N.flow);x=$.hidden,T=Zt($.graph,y)}else T=Qo(N,y);return T.then($=>{k||j({graph:$,isError:!1,hidden:x})}).catch(()=>{k||j({graph:jn,isError:!0})}),()=>{k=!0}},[N,S,E]),{graph:d?.graph??jn,hidden:d?.hidden,isLoading:!E&&!d,isError:E||d?.isError===!0}}function En(e){const t=e.ruleCount>1?` ×${e.ruleCount}`:"",s=typeof e.linkCount=="number"?` · ${e.linkCount.toLocaleString()}`:"";return`${e.label}${t}${s}`}const qt={connections:"--chart-3",entities:"--chart-5",automations:"--chart-2",metrics:"--chart-4"};function ua(e,t){const s=e.nodes.some(a=>a.data.ref),r=new Map(e.nodes.map(a=>[a.id,a.data.label])),o=e.nodes.map(a=>({id:a.id,x:a.position.x+a.width/2,y:a.position.y+a.height/2,w:a.width,h:a.height,title:a.data.label,meta:a.data.metaLabel,icon:a.data.icon,badge:a.data.badge??a.data.organizationSlug,muted:a.data.isSystem,dimmed:t?!t.nodes.has(a.id):!1,accent:s?qt[it(a)]:void 0})),c=e.edges.map(a=>{const{relationships:l,isSymmetric:h,flow:i}=a.data;if(i)return{id:a.id,source:a.source,target:a.target,route:a.route??null,summary:i.summary,details:[i.summary,...i.details],directed:!0,dimmed:t?!t.edges.has(a.id):!1,ariaLabel:`${r.get(a.source)??a.source} to ${r.get(a.target)??a.target}: ${i.summary}`};const g=l.map(p=>p.label).join(", ");return{id:a.id,source:a.source,target:a.target,route:a.route??null,summary:l.length===1?En(l[0]):`${l.length} relationships`,details:l.map(En),directed:!h,dimmed:t?!t.edges.has(a.id):!1,ariaLabel:`${r.get(a.source)??a.source} ${h?"and":"to"} ${r.get(a.target)??a.target}: ${g}`}});return{boxes:o,edges:c}}const Cn=[{key:"connections",label:"Connections"},{key:"entities",label:"Entities"},{key:"automations",label:"Automations"},{key:"metrics",label:"Metrics"}],ma={count:"Count",count_distinct:"Distinct count",sum:"Sum",min:"Minimum",max:"Maximum"};function fa({metric:e,ownerSlug:t}){const s=(r,o)=>o.length>0?n.jsxs("section",{className:"flex flex-col gap-1.5",children:[n.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r}),n.jsx("ul",{className:"flex flex-col gap-1 text-sm",children:o.map(c=>n.jsxs("li",{children:[n.jsx("span",{className:"font-medium",children:c.name}),c.description?n.jsx("span",{className:"text-muted-foreground",children:` · ${c.description}`}):null]},c.name))})]}):null;return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"flex flex-col gap-1",children:[n.jsxs("p",{className:"text-sm",children:[ma[e.agg]??e.agg," of"," ",n.jsx("code",{className:"rounded bg-muted px-1 text-xs",children:e.eventSet})," ","events, per ",e.typeLabel]}),e.description?n.jsx("p",{className:"text-sm text-muted-foreground",children:e.description}):null]}),s("Data from",e.sources.map(r=>({name:r,description:""}))),s("Group by",e.dimensions),s("Segments",e.segments),n.jsx(V,{asChild:!0,variant:"outline",size:"sm",className:"self-start",children:n.jsxs(Pe,{to:"/$owner/$entityType",params:{owner:t,entityType:e.typeSlug},children:["Open ",e.typeLabel]})})]})}function pa({ownerSlug:e,metric:t,endpointOptions:s,canAuthor:r,mode:o,onModeChange:c}){const a=()=>c({kind:"index"});return o.kind==="metric"?t?n.jsx(fa,{metric:t,ownerSlug:e}):null:r?o.kind==="create-type"?n.jsx(Xr,{slug:null,onClose:a}):o.kind==="new-relationship"?n.jsx(ra,{entityTypes:s,initialSource:o.source,initialTarget:o.target,onDone:a},`${o.source??""}|${o.target??""}`):null:null}function ha(e){const{mode:t,canAuthor:s,onModeChange:r,isPeekOpen:o}=e,c=s&&t.kind==="create-type",a=t.kind==="metric"?t.name:s&&t.kind==="new-relationship"?"New relationship":c?"New entity type":"Schema",l=w.useRef(null),h=JSON.stringify(t),i=w.useRef(h);return w.useEffect(()=>{i.current!==h&&(i.current=h,l.current?.focus({preventScroll:!0}))},[h]),n.jsx("aside",{style:{"--schema-panel-width":`${e.width}px`},className:oe("order-first flex w-full shrink-0 flex-col lg:order-none lg:w-[var(--schema-panel-width)]",t.kind==="index"?"lg:absolute lg:top-0 lg:right-6 lg:z-10 lg:w-max lg:max-w-[calc(100%-3rem)] lg:max-h-[calc(100%-2rem)]":"bg-background lg:relative",o&&"lg:hidden"),children:n.jsxs("div",{className:oe("flex min-h-0 flex-1 flex-col",t.kind!=="index"&&"lg:absolute lg:inset-0"),children:[n.jsxs("div",{className:t.kind==="index"?"sr-only":"flex h-11 shrink-0 items-center gap-1 border-b border-border px-3",children:[n.jsx("h2",{ref:l,tabIndex:-1,className:"min-w-0 flex-1 truncate text-sm font-medium text-foreground outline-none",children:a}),t.kind!=="index"?n.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"size-7 shrink-0 text-muted-foreground hover:text-foreground","aria-label":"Close",onClick:()=>r({kind:"index"}),children:n.jsx(Ks,{className:"h-4 w-4"})}):null]}),n.jsx("div",{className:oe("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto",t.kind==="index"?"pb-1":"p-4"),children:n.jsx(pa,{...e})})]})})}function ms(e){const t=e.previousElementSibling,s=e.nextElementSibling;if(t instanceof HTMLElement&&s instanceof HTMLElement){const r=t.clientWidth+s.clientWidth;if(r>0)return r}return 0}function ga({width:e,maxWidth:t,onResize:s,onCommit:r,onReset:o,className:c}){const[a,l]=w.useState(!1),h=w.useRef(0),i=f=>{const m=ms(f);return m>0?m:f.parentElement?.clientWidth??0},g=f=>{if(f.button!==0)return;const m=f.currentTarget;if(!m.parentElement)return;f.preventDefault(),h.current=i(m);const N=f.clientX,d=e;l(!0),m.setPointerCapture(f.pointerId);const j=y=>Nt(d-(y-N),h.current);let S=d;const E=y=>{S=j(y.clientX),s(S)},k=y=>{m.removeEventListener("pointermove",E),m.removeEventListener("pointerup",k),m.removeEventListener("pointercancel",k),l(!1),r(y.type==="pointercancel"?S:j(y.clientX))};m.addEventListener("pointermove",E),m.addEventListener("pointerup",k),m.addEventListener("pointercancel",k)},p=f=>{const m=i(f.currentTarget),v=N=>{f.preventDefault(),r(Nt(e+N,m))};f.key==="ArrowLeft"?v(16):f.key==="ArrowRight"?v(-16):f.key==="Home"&&(f.preventDefault(),o())};return n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize schema panel","aria-valuenow":e,"aria-valuemin":wt,"aria-valuemax":t,tabIndex:0,onPointerDown:g,onKeyDown:p,onDoubleClick:o,className:oe("group hidden shrink-0 cursor-col-resize touch-none items-stretch justify-center px-1.5 outline-none lg:flex",a&&"cursor-col-resize",c),children:n.jsx("div",{className:oe("w-px rounded-full bg-border transition-[background-color,width] group-hover:w-0.5 group-hover:bg-primary/60 group-focus-visible:w-0.5 group-focus-visible:bg-primary",a&&"w-0.5 bg-primary")})})}function ya({ownerSlug:e}){const t=nt(),s=Jt(),r=s?.item!=null,{orgContext:o}=De(),{isAdmin:c}=Dn(o.organizationId),[a,l]=w.useState({connections:!0,entities:!0,automations:!0,metrics:!0}),[h,i]=w.useState({kind:"index"}),g=s?.close,p=w.useCallback(b=>{b.kind!=="index"&&r&&g?.(),i(b)},[r,g]),[f,m]=w.useState(),v=w.useRef(null),N=w.useCallback(b=>{if(v.current?.disconnect(),v.current=null,!b||typeof ResizeObserver>"u")return;const _=()=>{if(!b.clientWidth||!b.clientHeight)return;const z=Math.round(b.clientHeight/b.clientWidth*10)/10;m(P=>P===z?P:z)};_();const L=new ResizeObserver(_);L.observe(b),v.current=L},[]),d=o.organizationId,j=Ws(d),S=Bs(d),E=Hs(d),k=Jr(d??void 0),{data:y}=_t(o),x=w.useMemo(()=>y?.filter(b=>Vs(b,e)),[y,e]),T=w.useMemo(()=>(x??[]).flatMap(b=>Object.entries(b.metrics_config?.measures??{}).map(([_,L])=>({typeSlug:b.slug,name:_,agg:L.agg,description:L.description}))),[x]),$=j.isLoading||S.isLoading||E.isLoading||k.isLoading,F=w.useMemo(()=>$?null:{connections:j.data??[],feeds:S.data??[],connectorDefs:E.data??[],automations:k.data??[],metrics:T,layers:a},[$,j.data,S.data,E.data,k.data,T,a]),{graph:A,isLoading:K,isError:H,hidden:se}=da(e,f,F),W=K||$,ge={connections:!$&&(j.data??[]).length===0,entities:!1,automations:!$&&(k.data??[]).length===0,metrics:!$&&T.length===0},ne=h.kind==="metric"?h:null,U=w.useMemo(()=>{if(!ne)return null;const b=`metric:${ne.typeSlug}:${ne.name}`,_=A.edges.find(P=>P.target===b);if(!_)return null;const L=_.source,z=A.edges.filter(P=>P.target===L&&A.nodes.find(O=>O.id===P.source)?.data.ref?.kind==="connection");return{typeId:L,nodes:new Set([b,L,...z.map(P=>P.source)]),edges:new Set([_.id,...z.map(P=>P.id)]),sources:z.map(P=>A.nodes.find(O=>O.id===P.source)?.data.label??P.source)}},[ne,A]),{boxes:Ce,edges:ue}=w.useMemo(()=>ua(A,U),[A,U]),Q=w.useMemo(()=>{if(!ne)return null;const b=x?.find(z=>z.slug===ne.typeSlug),_=b?.metrics_config,L=_?.measures?.[ne.name];return!b||!L?null:{name:ne.name,typeSlug:b.slug,typeLabel:b.name||b.slug,agg:L.agg,eventSet:L.eventSet,description:L.description,dimensions:Object.entries(_?.dimensions??{}).map(([z,P])=>({name:z,description:P.description})),segments:Object.entries(_?.segments??{}).map(([z,P])=>({name:z,description:P.description})),sources:U?.sources??[]}},[ne,x,U]),ee=w.useMemo(()=>new Map(A.nodes.map(b=>[b.id,b.data.slug])),[A.nodes]),me=w.useMemo(()=>new Map(A.nodes.flatMap(b=>b.data.ref?[[b.id,b.data.ref]]:[])),[A.nodes]),{data:_e=[]}=Us(o.organizationId),Ue=w.useMemo(()=>{const b=new Map;for(const _ of A.nodes)_.data.ref||(!_.data.organizationSlug||!b.has(_.data.slug))&&b.set(_.data.slug,{slug:_.data.slug,label:_.data.label});return[...b.values()]},[A.nodes]),ae=w.useCallback(b=>{const _=me.get(b);if(_?.kind==="connection"){t({to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:e,connectorKey:_.connectorKey,connectionId:String(_.connectionId)},search:{}});return}if(_?.kind==="metric"){p({kind:"metric",typeSlug:_.typeSlug,name:_.name});return}if(_?.kind==="automation"){t({to:"/$owner/automations/$automationId",params:{owner:e,automationId:_.automationId},search:{view:"activity",run_id:void 0}});return}t(Fn(e,ee.get(b)??b))},[t,e,ee,me,p]),ve=w.useCallback((b,_)=>{me.has(b)||me.has(_)||p({kind:"new-relationship",source:ee.get(b)??b,target:ee.get(_)??_})},[ee,me,p]),Fe=A.nodes.some(b=>!b.data.ref&&!b.data.isSystem&&!b.data.organizationSlug),Me=A.nodes.some(b=>b.data.ref),Te="size-6 text-muted-foreground hover:text-foreground",we={connections:n.jsx(Kr,{ownerSlug:e,catalog:_e,trigger:n.jsx(V,{type:"button",variant:"ghost",size:"icon",className:Te,"aria-label":"New connector",title:"New connector",children:n.jsx(ct,{className:"size-3.5"})})}),entities:n.jsx(V,{type:"button",variant:"ghost",size:"icon",className:Te,"aria-label":"Create entity type",title:"Create entity type",onClick:()=>p({kind:"create-type"}),children:n.jsx(ct,{className:"size-3.5"})}),automations:n.jsx(V,{asChild:!0,variant:"ghost",size:"icon",className:Te,children:n.jsx(Pe,{to:"/$owner/automations/new",params:{owner:e},"aria-label":"New Automation",title:"New Automation",children:n.jsx(ct,{className:"size-3.5"})})})},ze=w.useCallback(b=>{const _=b.startsWith(Ut)?b.slice(Ut.length):null;if(!_)return n.jsx(Ct,{icon:b||null,className:"h-4 w-4"});const L=qs(_,E.data??[],{name:j.data?.find(z=>z.connector_key===_)?.connector_name??_});return n.jsx(Gs,{plain:!0,icon:L.icon,iconUrl:L.iconUrl,name:L.name,faviconDomain:L.faviconDomain})},[E.data,j.data]),fe=c&&h.kind==="create-type",ke=h.kind==="metric"||c&&h.kind!=="index",[ye,Ne]=w.useState(()=>ia()),le=ye??(fe?oa:us),[Le,Se]=w.useState(null),xe=w.useRef(null),qe=w.useCallback(b=>{if(xe.current?.disconnect(),xe.current=null,!b||typeof ResizeObserver>"u")return;const _=b.children[1];if(!_)return;const L=()=>{const P=ms(_);P>0&&Se(O=>O===P?O:P)};L();const z=new ResizeObserver(L);z.observe(b),xe.current=z},[]),Re=Le===null?le:Nt(le,Le),C=Le===null?kt:Nt(kt,Le),u=w.useCallback(b=>{Ne(b),ca(b)},[]),M=w.useCallback(()=>{Ne(null),la()},[]);return W?n.jsx(Xt,{label:"Loading workspace schema",fill:!0,schemaActions:c}):H?n.jsx(zn,{label:"workspace schema"}):n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[n.jsxs("div",{className:oe("flex flex-wrap items-center justify-between gap-3",ke&&"hidden lg:flex"),children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:Me?`Where records come from, the types they land in, and what uses them. Click a box to open it${c?", or drag a type's ⊕ onto another to relate them":""}. Only stored links are drawn${se?.connections?`; ${se.connections} connections have none yet`:""}.`:Fe?A.edges.length>0?`Your workspace schema. Hover a type or select a line to name its relationships, click a type to open it${c?", or drag its ⊕ to relate types.":"."}`:"Your workspace schema. Click a type to open it — relationships appear here once you add one to a type.":c?"Member is already here: everyone in this workspace. Create the first type of record you track — a company, a deal, a ticket — then drag its ⊕ onto Member to relate them.":"Member is already here: everyone in this workspace. An admin can add the types of record this workspace tracks."}),n.jsxs("fieldset",{className:"m-0 flex min-w-0 shrink-0 flex-wrap items-center gap-x-4 gap-y-1 border-0 p-0 text-sm",children:[n.jsx("legend",{className:"sr-only",children:"Show on the map"}),Cn.map(({key:b,label:_})=>{const L=`memory-map-show-${b}`,z=a[b]&&!ge[b]&&Cn.filter(({key:P})=>a[P]&&!ge[P]).length===1;return n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx(Ys,{id:L,checked:a[b],disabled:z,style:{borderColor:`var(${qt[b]})`,backgroundColor:a[b]?`var(${qt[b]})`:void 0},onCheckedChange:P=>l(O=>({...O,[b]:P===!0}))}),n.jsx("label",{htmlFor:L,className:"inline-flex cursor-pointer select-none items-center",children:_}),c?we[b]:null]},b)})]})]}),n.jsxs("div",{ref:qe,className:"relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 lg:-mr-6 lg:-mb-8 lg:flex-row lg:gap-0",children:[n.jsx("div",{className:oe("flex min-w-0 flex-1 flex-col lg:pb-8",ke&&"hidden lg:flex"),children:n.jsx("div",{ref:N,className:"min-h-[420px] min-w-0 flex-1 overflow-hidden rounded-lg bg-background",children:n.jsx(cs,{boxes:Ce,edges:ue,label:"Workspace schema",onOpenBox:ae,openLabel:b=>`Open ${b.title}`,onConnect:c?ve:void 0,renderIcon:ze})})}),n.jsx(ga,{width:Re,maxWidth:C,onResize:Ne,onCommit:u,onReset:M,className:r||h.kind==="index"?"lg:hidden":void 0}),n.jsx(ha,{width:Re,metric:Q,ownerSlug:e,endpointOptions:Ue,canAuthor:c,mode:h,onModeChange:p,isPeekOpen:r})]})]})}function xa({onClose:e,entityTypeSlug:t,orgContext:s,onSuccess:r}){const{data:o,isLoading:c}=Wn(t,s),a=`${s.organizationId??s.slug}:${t}`,l=Js(a,{name:"",customSlug:"",useCustomSlug:!1,metadata:{}},o?.metadata_schema),[h,i]=l.field("name"),[g,p]=l.field("customSlug"),[f,m]=l.field("useCustomSlug"),[v,N]=l.field("metadata"),[d,j]=Qs(a,null),S=Xs(),E=f?g:Zs(h),k=async F=>{if(F.preventDefault(),!l.canSubmit)return;if(j(null),!h.trim()){j("Name is required");return}const A=eo(v),K={entityType:t,name:h.trim(),slug:f?g:void 0,metadata:Object.keys(A).length>0?A:void 0};try{const H=await S.mutateAsync(K);if(e(),H.approval_queued||!H.entity){Bn.info("Create queued for approval");return}typeof H.entity.id=="number"&&r?.(H.entity.id)}catch(H){j(H instanceof Error?H.message:"Failed to create entity")}},y=o?.name||t,x=l.revision,T=`Create ${y}`,$=`Add a new ${y.toLowerCase()} to your workspace.`;return c?n.jsx(er,{rows:6}):n.jsxs("form",{onSubmit:k,children:[n.jsx(tr,{visible:l.hasConflict,onReload:l.reset}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:T}),n.jsx("p",{className:"text-sm text-muted-foreground",children:$})]}),n.jsxs("div",{className:"grid gap-4 py-4",children:[n.jsxs("div",{className:"grid gap-2",children:[n.jsxs(Ae,{htmlFor:"name",children:["Name ",n.jsx("span",{className:"text-destructive",children:"*"})]}),n.jsx(tt,{id:"name",value:h,onChange:F=>i(F.target.value),placeholder:`Enter ${y.toLowerCase()} name`,autoFocus:!0})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(Ae,{htmlFor:"slug",children:"URL Slug"}),n.jsx("button",{type:"button",onClick:()=>m(!f),className:"text-xs text-muted-foreground hover:text-foreground",children:f?"Auto-generate":"Customize"})]}),f?n.jsx(tt,{id:"slug",value:g,onChange:F=>p(F.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"custom-slug"}):n.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm text-muted-foreground",children:E||"slug-preview"})]}),x&&Object.keys(x).length>0?n.jsxs(n.Fragment,{children:[n.jsx(to,{className:"my-2"}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(Ae,{className:"text-sm font-medium",children:"Additional Fields"}),n.jsx(Zr,{schema:l.revision,values:v,onValuesChange:N,orgContext:s})]})]}):null,d&&n.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:d})]}),n.jsx(On,{onCancel:e,cancelDisabled:S.isPending,className:"mt-2",children:n.jsx(V,{type:"submit",disabled:!l.canSubmit||S.isPending||!h.trim(),children:S.isPending?"Creating...":`Create ${y}`})})]})}function ba(e){const t=e?.properties??{},s=or(e);return Object.entries(t).flatMap(([r,o])=>{const c=s.find(p=>p.field===r);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)||!o||o.const!==void 0||o["x-table-column"]!==!0&&o["x-facet"]!==!0&&!c)return[];const a=[o,...Array.isArray(o.anyOf)?o.anyOf:[]],l=c?.options??[],h=l.find(p=>p.value!==null)?.value,i=a.find(p=>["string","number","integer","boolean"].includes(String(p.type)))??(h===void 0?void 0:{type:typeof h});if(!i)return[];const g=o.format==="date-time"||i.format==="date-time"?"datetime-local":o.format==="date"||i.format==="date"?"date":i.type==="number"||i.type==="integer"?"number":i.type==="boolean"?"boolean":"string";return[{field:r,label:String(o["x-table-label"]??o.title??r.replaceAll("_"," ")),type:g,options:g==="boolean"&&!l.some(p=>typeof p.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...l]:l}]})}function va(e){const t=e?.[Ht];return t===void 0?{}:Qt(t)}function wa(e,t,s){try{const r=va(t),o=e[Hn],c=o===void 0?void 0:r.presets?.find(g=>g.key===o);if(o!==void 0&&!c)throw new Error("This saved filter is unavailable. Choose another filter.");if(c&&!s&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const a=c&&e[Ze]===void 0?{collection:xt(c)}:nr(e,s);if(a.error)throw a.error;const l=e[sr],h=l===void 0?c?.table??r.table??{}:Qt({table:typeof l=="string"?JSON.parse(l):l}).table??{},i=!!c&&(_n(a.collection)!==_n(xt(c))||St(h)!==St(c.table??r.table??{}));return{...a,presentation:r,preset:c,table:h,edited:i}}catch(r){return{collection:{},presentation:{},table:{},edited:!1,error:r instanceof Error?r:new Error("Invalid collection configuration")}}}function _n(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(gt)])}function gt(e){return JSON.stringify([e.field,e.op,e.value])}function St(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function ka(e,t){return t?{[Hn]:t,[Ze]:Bt(e)[Ze]??"{}"}:Bt(e)}function Na(e,t,s,r,o=new Date){let c=t.filters??[],a=e.relativeDate;if(a){const l=(xt({...e,selection:{}},o).filters??[]).map(gt),h=c.map(gt);l.every(i=>h.includes(i))?c=c.filter(i=>!l.includes(gt(i))):a=void 0}return{key:e.key,label:e.label,selection:{...t.search?{search:t.search}:{},...c.length?{filters:c}:{},...t.segment?{segment:t.segment}:{}},...St(s)!==St(r.table??{})?{table:s}:{},...a?{relativeDate:a}:{}}}function Sa(e,t,s){const r=[...e.filters??[]],o=s??(t.length===1&&t[0].op==="eq"?r.findIndex(a=>a.field===t[0].field&&a.op==="eq"):-1),c=o>=0?[...r.slice(0,o),...t,...r.slice(o+1)]:[...r,...t];return{...e,filters:ar({filters:c}).filters}}function ja(e,t){return{...e,filters:e.filters?.filter((s,r)=>r!==t)}}function Ea(e,t){return{...typeof e.$preset=="string"?e[Ze]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[Ze]:String(rr(e[Ze]))}:Bt(t),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const Ca=[{field:"name",label:"Name"},{field:"created_at",label:"Created"},{field:"total_content",label:"Activity count"},{field:"active_connections",label:"Connections"},{field:"automations_count",label:"Automations"},{field:"children_count",label:"Children"}];function _a(e){return e.sort&&Ca.some(t=>t.field===e.sort?.field)?e.sort:{field:"created_at",order:"desc"}}function Ma(e,t,s,r,o){const c={...r,filters:r.filters?.filter(a=>a.field!==s)};return Vn({queryKey:["collection-facets",e,t,s,c],enabled:!!t&&!!s,staleTime:3e4,retry:!1,queryFn:async({signal:a})=>{const l=await bt("query_sdk",{title:`Value counts query for ${s}`,script:`const input = ${JSON.stringify({field:s,collection:c})};
2
- ${t}`},e,{signal:a}),h=l.return_value;if(!l.success||typeof h?.connection!="string"||typeof h.sql!="string")throw new Error(l.error?.message??"Value distribution is unavailable");if(a.aborted)throw new DOMException("Aborted","AbortError");const i=await bt("query_sql",{title:`Value counts for ${s}`,connection:h.connection,sql:h.sql,limit:51},e,{signal:a});if(i.error)throw new Error(i.error);if(!Array.isArray(i.rows))throw new Error("Source did not return value counts");const g=i.rows.map(p=>{const f=p,m=typeof f.count=="string"&&/^\d+$/.test(f.count)?Number(f.count):f.count;if(!(f.value===null||["string","number","boolean"].includes(typeof f.value))||typeof m!="number"||!Number.isSafeInteger(m)||m<0)throw new Error("Source returned an invalid value distribution");return{value:f.value,count:m}});return{values:g.slice(0,50),truncated:g.length>50||i.truncated===!0}}})}const Ta=300;function La({label:e,search:t,onSearch:s,className:r}){const o=t??"",[c,a]=w.useState(o),l=w.useRef({search:t,onSearch:s});l.current={search:t,onSearch:s};const h=w.useRef(void 0);w.useEffect(()=>{const g=()=>{clearTimeout(h.current),a(l.current.search??"")};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[]);const i=w.useRef(o);return w.useEffect(()=>{o!==i.current&&(i.current=o,a(o))},[o]),w.useEffect(()=>{if(c===(l.current.search??""))return;const g=setTimeout(()=>{const p=l.current.onSearch;i.current=c,p(c||void 0,!0)},Ta);return h.current=g,()=>clearTimeout(g)},[c]),n.jsxs("div",{className:`relative${r?` ${r}`:""}`,children:[n.jsx(cr,{"aria-hidden":"true",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),n.jsx(tt,{type:"search","aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}...`,maxLength:512,value:c,onChange:g=>a(g.target.value),className:"pl-9"})]})}const Ra={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function Ia({field:e,initial:t,org:s,facetQuery:r,collection:o,onApply:c,close:a}){const[l,h]=w.useState(t?.op??"eq"),[i,g]=w.useState(t?.value==null?"":String(t.value)),[p,f]=w.useState(""),[m,v]=w.useState(!1),[N,d]=w.useState(),j=e.type==="date"||e.type==="datetime-local"||e.type==="number"?e.type:"text",S=Ma(s,r,e.field,o),E=x=>{try{const T=m?[{field:e.field,op:"gte",value:e.type==="number"?Number(i):i},{field:e.field,op:"lte",value:e.type==="number"?Number(p):p}]:[{field:e.field,op:l,value:x}];if(e.type==="datetime-local")for(const A of T)typeof A.value=="string"&&(A.value=new Date(A.value).toISOString());if(T.some(A=>typeof A.value=="number"&&!Number.isFinite(A.value)))throw new Error("Enter a valid number.");const $=T[0].value,F=T[1]?.value;if(m&&$!=null&&F!=null&&$>F)throw new Error("The lower bound must be before the upper bound.");c(T),a()}catch(T){d(T instanceof Error?T.message:"Could not apply filter")}},k=[...e.options];for(const x of S.data?.values??[])k.some(T=>T.value===x.value)||k.push({value:x.value,label:x.value===null?"Not supplied":String(x.value)});const y=Math.max(1,...S.data?.values.map(x=>x.count)??[]);return n.jsxs("div",{className:"min-w-0 space-y-3 p-3",children:[n.jsxs("select",{"aria-label":"Filter operator",className:"h-8 w-full rounded-md border bg-background px-2 text-sm",value:m?"range":l,onChange:x=>{v(x.target.value==="range"),x.target.value!=="range"&&h(x.target.value)},children:[n.jsx("option",{value:"eq",children:"is"}),n.jsx("option",{value:"neq",children:"is not"}),(e.type==="number"||e.type==="date"||e.type==="datetime-local")&&n.jsxs(n.Fragment,{children:[n.jsx("option",{value:"lt",children:"less than / before"}),n.jsx("option",{value:"lte",children:"at most / on or before"}),n.jsx("option",{value:"gt",children:"greater than / after"}),n.jsx("option",{value:"gte",children:"at least / on or after"}),t?null:n.jsx("option",{value:"range",children:"between"})]})]}),e.type!=="boolean"&&n.jsxs("form",{className:"space-y-2",onSubmit:x=>{x.preventDefault(),E(e.type==="number"?Number(i):i)},children:[n.jsx(tt,{required:!0,"aria-label":m?"From value":"Filter value",type:j,step:e.type==="number"?"any":void 0,value:i,onChange:x=>g(x.target.value),placeholder:"Enter a value…"}),m&&n.jsx(tt,{required:!0,"aria-label":"To value",type:j,step:e.type==="number"?"any":void 0,value:p,onChange:x=>f(x.target.value)}),n.jsx(V,{size:"sm",type:"submit",className:"w-full",children:"Apply filter"})]}),!m&&(l==="eq"||l==="neq")&&n.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto",children:k.filter(x=>!i||x.label.toLowerCase().includes(i.toLowerCase())).map(x=>{const T=S.data?.values.find($=>$.value===x.value)?.count;return n.jsxs("button",{type:"button","aria-label":x.label,onClick:()=>E(x.value),className:"relative flex w-full items-center justify-between gap-3 overflow-hidden rounded px-2 py-1.5 text-left text-sm hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[T!==void 0&&n.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-primary/10",style:{width:`${T/y*100}%`}}),n.jsx("span",{className:"relative truncate",children:x.label}),n.jsx("span",{className:"relative text-xs tabular-nums text-muted-foreground",children:T?.toLocaleString()})]},JSON.stringify(x.value))})}),r&&S.isFetching&&n.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Loading distribution…"}),S.isError&&n.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Counts unavailable. You can still enter a value."}),S.data?.truncated&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"Top 50 values. Enter any other value above."}),N&&n.jsx("p",{role:"alert",className:"text-xs text-destructive",children:N})]})}function $a({collection:e,schema:t,label:s,onChange:r,org:o,facetQuery:c,segmentChip:a,viewFilters:l,onClearAll:h}){const i=ba(t),g=(v,N)=>({kind:"custom",className:"w-80",render:d=>n.jsx(Ia,{field:v,initial:N==null?void 0:e.filters?.[N],org:o,facetQuery:c,collection:e,onApply:j=>r(Sa(e,j,N)),close:d})}),p=i.map(v=>({key:v.field,label:v.label,icon:n.jsx(ir,{className:"h-4 w-4"}),editor:g(v)})),f=new Map,m=(e.filters??[]).map((v,N)=>{const d=`${v.field}:${v.op}:${JSON.stringify(v.value)}`,j=f.get(d)??0;f.set(d,j+1);const S=i.find(k=>k.field===v.field),E=S?.options.find(k=>k.value===v.value)?.label??String(v.value??"Not supplied");return{id:`${d}:${j}`,label:S?.label??v.field,op:Ra[v.op],value:E,editor:S?g(S,N):void 0,onRemove:()=>r(ja(e,N))}});if(a&&m.unshift(a),l?.fields.length){for(const v of p)v.group=s;p.push(...l.fields),m.push(...l.chips)}return!p.length&&!m.length?null:n.jsx(ao,{label:`${s} filters`,fields:p,chips:m,onClearAll:h??(()=>r({...e,filters:[],segment:void 0}))})}const jt=120,Ee=12;function Mn(e,t){return typeof e.linkId=="number"&&typeof t.linkId=="number"?e.linkId-t.linkId:String(e.linkId).localeCompare(String(t.linkId))}function Oa(e){const t=e.records.slice(0,jt),s=i=>e.types.get(i)??{label:i},r=new Map;for(const i of t)r.set(String(i.id),{source:i.source,entityType:e.typeSlug,slug:i.slug,name:i.name,isFocus:!0,hasMoreLinks:!1});const o=new Map;for(const i of e.links){if(!r.has(String(i.recordId)))continue;const g=o.get(i.recordId)??new Map;g.set(i.linkId,i),o.set(i.recordId,g)}const c=new Map;for(const[i,g]of o){const p=[...g.values()].sort(Mn),f=r.get(String(i));f&&p.length>Ee&&(f.hasMoreLinks=!0);for(const m of p.slice(0,Ee)){c.set(m.linkId,m);const v=String(m.peer.id);r.has(v)||r.set(v,{source:m.peer.source,...m.peer.remote?{remote:m.peer.remote}:{},entityType:m.peer.type,slug:m.peer.slug,name:m.peer.name,isFocus:!1,hasMoreLinks:!1})}}const a=[];for(const[i,g]of r){const p=g.remote?{label:g.entityType}:s(g.entityType),f=g.name||g.slug,m=g.hasMoreLinks?`${p.label} · ${Ee}+ links`:p.label;a.push({id:i,data:{slug:g.slug,label:f,icon:p.icon,isSystem:!1,metaLabel:m},width:lt(f,m),height:et})}const l=new Map;for(const i of[...c.values()].sort(Mn)){const g=String(i.fromId),p=String(i.toId),f=JSON.stringify([g,p]),m=l.get(f)??{source:g,target:p,rels:new Map,symmetric:!0};m.symmetric&&=i.isSymmetric,m.rels.has(i.relSlug)||m.rels.set(i.relSlug,{slug:i.relSlug,label:i.relName,ruleCount:1}),l.set(f,m)}const h=[...l.entries()].map(([i,g])=>({id:`link:${i}`,source:g.source,target:g.target,data:{relationships:[...g.rels.values()],isSymmetric:g.symmetric}}));return{nodes:a,edges:h,records:r,hasMoreRecords:e.hasMore===!0||e.records.length>jt,listedCount:t.length,focusCount:t.length}}async function Aa(e,t){const s=Oa(e);return{...await Zt({nodes:s.nodes,edges:s.edges},t),records:s.records,hasMoreRecords:s.hasMoreRecords,listedCount:s.listedCount,focusCount:s.focusCount}}const Pa=8,Da=3,Fa=4;function yt(e){return`source:${JSON.stringify([e.type,e.key])}`}function za(e,t){return t.map(s=>{const r={type:e,key:s.slug};return{...s,id:yt(r),source:r}})}function Tn(e){return JSON.stringify([e.relationship_type,e.direction,e.entity_type,e.key])}async function Wa(e,t,s){const r=e.slice(0,Pa),o=[];let c=0;return await Promise.all(Array.from({length:Math.min(Da,r.length)},async()=>{for(;c<r.length;){const a=c++,l=r[a];try{if(s?.aborted)throw s.reason;const h=await t(l),i=new Map(l.links.map(d=>[Tn(d),d]));for(const d of h.record_links){const j=Tn(d),S=i.get(j);(!S||S.occurred_at<d.occurred_at)&&i.set(j,d)}const g=new Map((l.relationships??[]).map(d=>[d.id,d]));for(const d of h.relationships??[])g.set(d.id,d);const p=[...g.values()].slice(0,Ee+1),f=[...i.values()].slice(0,Ee+1),m=(l.pagesRead??0)+1,v=!!h.next_cursor&&m>=Fa,N=h.record_failures.length>0||!!h.relationship_failures?.length||v;o[a]={read:{record:l.record,links:f,failed:N,entityId:l.entityId,relationships:p},...!v&&(N||h.next_cursor&&f.length+p.length<=Ee)?{next:{record:l.record,entityId:l.entityId,relationships:p,pagesRead:m,cursor:h.next_cursor??l.cursor,links:f}}:{}}}catch(h){if(s?.aborted)throw h;o[a]={read:{record:l.record,links:l.links,failed:!0,entityId:l.entityId,relationships:l.relationships},next:{...l,cursor:h instanceof lr&&h.status===400?null:l.cursor}}}}})),{reads:o.map(a=>a.read),pending:[...o.flatMap(a=>a.next?[a.next]:[]),...e.slice(r.length)]}}function Ba(e,t){const s=new Map;for(const c of e)for(const a of c.reads)s.set(String(a.entityId??yt(a.record)),a);const r=new Map(t.map(c=>[c.slug,c])),o=[];for(const[c,a]of s){for(const l of a.relationships??[]){const h=(d,j,S)=>S?`remote:${S}`:typeof d=="number"?d:yt({type:j,key:d}),i=h(l.from_entity_id,l.from_entity_type,l.from_entity_url),g=h(l.to_entity_id,l.to_entity_type,l.to_entity_url),p=String(i)===c,f=p?g:i,m=p?l.to_entity_id:l.from_entity_id,v=p?l.to_entity_url:l.from_entity_url,N=(p?l.to_entity_type:l.from_entity_type)??"";o.push({recordId:c,linkId:l.id,fromId:i,toId:g,relSlug:l.relationship_type_slug,relName:l.relationship_type_name,isSymmetric:l.is_symmetric,peer:{id:f,name:(p?l.to_entity_name:l.from_entity_name)??String(m),slug:(p?l.to_entity_slug:l.from_entity_slug)??String(m),type:N,...v?{remote:{url:dr(v)}}:typeof m=="string"?{source:{type:N,key:m}}:{}}})}for(const l of a.links){const h={type:l.entity_type,key:l.key},i=yt(h),g=r.get(l.relationship_type);let p=l.direction==="incoming"?i:c,f=l.direction==="incoming"?c:i;g?.is_symmetric&&p>f&&([p,f]=[f,p]),o.push({recordId:c,linkId:JSON.stringify([p,f,l.relationship_type]),fromId:p,toId:f,relSlug:l.relationship_type,relName:g?.name||l.relationship_type.replaceAll("_"," "),isSymmetric:g?.is_symmetric??!1,peer:{id:i,name:l.name||l.key,slug:l.key,type:l.entity_type,source:h}})}}return{links:o,checked:s.size,failed:[...s.values()].filter(c=>c.failed).length}}function Ha(e,t,s,r,o,c=!1){const{orgContext:a}=De(),l=_t(a),h=Kt(a),i=w.useMemo(()=>c?za(t,s):s,[c,t,s]),g=w.useMemo(()=>i.slice(0,jt).flatMap(k=>k.source?[{record:k.source,cursor:null,links:[]}]:typeof k.id=="number"?[{entityId:k.id,record:{type:t,key:k.slug},cursor:null,links:[]}]:[]),[i,t]),p=ur({queryKey:["source-records-graph",a.organizationId,e,t,g.map(k=>[k.record,k.entityId])],enabled:!0,initialPageParam:g,queryFn:({pageParam:k,signal:y})=>Wa(k,async x=>{const T=await bt("manage_entity",{action:"list_links",...x.entityId===void 0?{record:x.record,cursor:x.cursor}:{entity_id:x.entityId,offset:Number(x.cursor??0)},limit:Ee+1},e,{signal:y});return{...T,record_links:T.record_links??[],record_failures:T.record_failures??[],next_cursor:x.entityId===void 0?T.next_cursor:T.metadata?.has_more?String(Number(x.cursor??0)+Ee+1):null}},y),getNextPageParam:k=>k.pending.length?k.pending:void 0,staleTime:3e4,retry:!1}),f=w.useMemo(()=>p.data?Ba(p.data.pages,h.data??[]):void 0,[p.data,h.data]),m=f?.links,v=p.isError,N=JSON.stringify([a.organizationId,e,t,c,i.map(k=>[k.id,k.name,k.slug]),r]),d=w.useMemo(()=>new Map((l.data??[]).map(k=>[k.slug,{label:k.name||k.slug,icon:k.icon}])),[l.data]),[j,S]=w.useState(null);w.useEffect(()=>{if(!m)return;let k=!1;return Aa({typeSlug:t,records:i,hasMore:r,links:m,types:d},{targetAspect:o}).then(y=>{k||S({graph:y,key:N,isError:!1})}).catch(()=>{k||S({graph:null,key:N,isError:!0})}),()=>{k=!0}},[m,t,i,r,d,o,N]);const E=j?.key===N?j:null;return{graph:E?.graph??null,isLoading:!v&&!E,isError:v||E?.isError===!0,sourceProgress:{checked:f?.checked??0,total:Math.min(s.length,jt),failed:f?.failed??0,hasMore:!!p.hasNextPage,isFetching:p.isFetching,loadMore:()=>{p.isFetching||p.fetchNextPage()}}}}function Va(e){const t=new Map(e.nodes.map(o=>[o.id,o.data.label])),s=e.nodes.map(o=>({id:o.id,x:o.position.x+o.width/2,y:o.position.y+o.height/2,w:o.width,h:o.height,title:o.data.label,meta:o.data.metaLabel,icon:o.data.icon,muted:e.records.get(o.id)?.isFocus===!1})),r=e.edges.map(o=>{const{relationships:c,isSymmetric:a}=o.data,l=c.map(h=>h.label);return{id:o.id,source:o.source,target:o.target,route:o.route??null,summary:l.length===1?l[0]:`${l.length} relationships`,details:l,directed:!a,ariaLabel:`${t.get(o.source)??o.source} ${a?"and":"to"} ${t.get(o.target)??o.target}: ${l.join(", ")}`}});return{boxes:s,edges:r}}function Ua({ownerSlug:e,typeSlug:t,records:s,hasMore:r,sourceBacked:o=!1}){const c=nt(),a=Jt(),{orgContext:l}=De(),{data:h=[]}=_t(l),i=h.find(y=>y.slug===t)?.name??t,[g,p]=w.useState(),f=w.useRef(null),m=w.useCallback(y=>{if(f.current?.disconnect(),f.current=null,!y||typeof ResizeObserver>"u")return;const x=()=>{if(!y.clientWidth||!y.clientHeight)return;const $=Math.round(y.clientHeight/y.clientWidth*10)/10;p(F=>F===$?F:$)};x();const T=new ResizeObserver(x);T.observe(y),f.current=T},[]),{graph:v,isLoading:N,isError:d,sourceProgress:j}=Ha(e,t,s,r,g,o),S=w.useMemo(()=>v?Va(v):null,[v]),E=w.useCallback(y=>{const x=v?.records.get(y);if(x){if(x.remote){x.remote.url&&window.open(x.remote.url,"_blank","noopener,noreferrer");return}if(a){a.open(io({...x.source?{record:x.source}:{entityId:Number(y)},ownerSlug:e,orgContext:l,name:x.name||x.slug}));return}c({to:mr(e,[{entity_type:x.entityType,slug:x.slug}])})}},[v,e,l,a,c]);if(d)return n.jsx(zn,{label:`${i} graph`});if(N||!v||!S)return n.jsx(Xt,{label:`Loading ${i} graph`});const k=j?n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[n.jsxs("div",{className:"text-sm text-muted-foreground",role:"status",children:[n.jsxs("p",{children:["Checked ",j.checked," of ",j.total," records. Up to ",Ee," relationships per record."]}),j.failed>0?n.jsx("p",{role:"alert",children:"Some sources could not be read. These relationships are incomplete."}):null]}),j.hasMore?n.jsx(V,{variant:"outline",size:"sm",disabled:j.isFetching,onClick:j.loadMore,children:j.isFetching?"Loading…":j.failed>0?"Retry sources":"Load more relationships"}):null]}):null;return v.focusCount===0?n.jsxs("div",{className:"space-y-3",children:[k,n.jsx(Un,{icon:qn,title:`No ${i} records match`,description:"Change the search or filters to see records here."})]}):n.jsxs("div",{className:"flex flex-col gap-2",children:[k,n.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",v.hasMoreRecords?"the first ":"",v.focusCount," ",i," record",v.focusCount===1?"":"s",". Click a record to see it."]}),n.jsx("div",{ref:m,className:"h-[70vh] min-h-[420px] min-w-0 overflow-hidden",children:n.jsx(cs,{boxes:S.boxes,edges:S.edges,label:`${i} records`,onOpenBox:E,openLabel:y=>`Show ${y.title}`})})]})}function qa(e){return String(e??"").replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function fs(e){return e["x-lobu"]?.role||e["x-lobu-role"]}function tn(e){const t=e?.properties;if(!t)return null;const o=fr(t).find(([,i])=>fs(i)==="workflowState");if(!o)return null;const[c,a]=o,l=a["x-lobu"]?.states,h=Array.isArray(l)&&l.length>0?l:(a.enum??[]).map(i=>({value:i}));return h.length===0||h.some(i=>typeof i.value!="string")?null:{field:c,states:h.map(i=>({...i,label:i.label||pr(a,i.value)||qa(i.value),terminal:i.terminal??["done","complete","completed","closed","archived"].includes(i.value.toLowerCase())}))}}function Ga(e){const t=e?.properties;if(!t)return null;const s=Object.entries(t),r=s.find(([,a])=>fs(a)==="sortRank"),o=s.find(([a])=>["rank","sort_rank","order"].includes(a)),c=r??o;return c?{field:c[0]}:null}function Ya(e,{isDerived:t}){const s=e?.["x-lobu"]?.defaultView;return(s==="table"||s==="board")&&!(t&&s!=="table")?s:t?"table":tn(e)?"board":"table"}const ps={version:1,root:{type:"entity-table",props:{state:"{{tableState}}"}}},Ka={version:1,root:{type:"entity-board",props:{state:"{{boardState}}",onUpdate:"@updateEntity"}}};function Ja(e){const{canShowBoard:t,builtinData:s,builtInLabels:r}=e,o=["table",...t?["board"]:[]],c={table:ps,board:Ka};return o.map(a=>({id:a,label:r[a],builtInMode:a,template:c[a],data:s}))}function Gt(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Et(e,t){if(!t)return e.created_at??String(e.id);const s=Mt(e.metadata);return String(s[t.field]??e.created_at??e.id)}function Qa(e,t){const s=e?Number(e):Number.NaN,r=t?Number(t):Number.NaN;return Number.isFinite(s)&&Number.isFinite(r)&&s<r?String((s+r)/2):Number.isFinite(s)?String(s+1):Number.isFinite(r)?String(r-1):String(Date.now())}function Yt(e,t){const s=Mt(e.metadata);return String(s[t]??"")}function hs(e,t){return[...e].sort((s,r)=>Et(s,t).localeCompare(Et(r,t)))}function Xa(e,t,s,r,o){if(!t.startsWith("card:")||!s)return null;const c=Number(t.slice(5)),a=e.find(S=>S.id===c);if(!a)return null;const l=s.startsWith("column:")?s.slice(7):Yt(e.find(S=>`card:${S.id}`===s)??a,r.field);if(!l)return null;const h=hs(e.filter(S=>S.id!==c&&Yt(S,r.field)===l),o),i=s.startsWith("card:")?h.findIndex(S=>`card:${S.id}`===s):h.length,g=i>=0?i:h.length,p=g>0?h[g-1]:void 0,f=h[g],m=o?Qa(p?Et(p,o):void 0,f?Et(f,o):void 0):void 0,v=Mt(a.metadata),N={[r.field]:l,...o&&m?{[o.field]:m}:{}};r.states.find(S=>S.value===l)?.terminal&&!v.completed_at&&(N.completed_at=new Date().toISOString());const j={...v,...N};return{entityId:c,changedMetadata:N,nextMetadata:j}}function Ln(e,t,s){return e.map(r=>r.id===t?{...r,metadata:s}:r)}function Za({id:e,children:t,className:s}){const{setNodeRef:r,isOver:o}=rs({id:`column:${e}`});return n.jsx("div",{ref:r,className:oe("min-h-[220px] rounded-lg bg-card p-2 transition-colors",o?"bg-accent/50":"",s),children:t})}function ei({entity:e,owner:t,statusField:s,entityTypeIcon:r,schema:o,didDragRef:c}){const a=Mt(e.metadata),{attributes:l,listeners:h,setNodeRef:i,transform:g,isDragging:p}=go({id:`card:${e.id}`}),{setNodeRef:f,isOver:m}=rs({id:`card:${e.id}`}),v=Gn(t,ss(e)),N=d=>{c.current&&(d.preventDefault(),d.stopPropagation())};return n.jsx("div",{ref:d=>{i(d),f(d)},style:{transform:yo.Translate.toString(g)},className:oe(yr,"p-3 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",p?"opacity-60":"",m?"ring-1 ring-ring":""),children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("button",{type:"button",className:"mt-0.5 shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing","aria-label":`Drag ${e.name}`,...l,...h,children:n.jsx(gr,{className:"h-4 w-4"})}),n.jsx(ns,{metadata:a,metadataSchema:o,name:e.name,typeIcon:r,className:"mt-0.5 h-6 w-6 shrink-0",initialsFallback:!0}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx(Pe,{to:v,className:"font-medium text-foreground hover:underline",onClick:N,children:e.name}),n.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[typeof a.priority=="string"&&a.priority?n.jsx(Vt,{variant:"outline",className:"text-xs",children:Gt(a.priority)}):null,typeof a[s]=="string"&&a[s]?n.jsx(Vt,{variant:"secondary",className:"text-xs",children:Gt(String(a[s]))}):null]})]})]})})}function ti({owner:e,entities:t,totalCount:s,schema:r,entityTypeIcon:o,onUpdate:c}){const a=w.useMemo(()=>tn(r),[r]),l=w.useMemo(()=>Ga(r),[r]),[h,i]=w.useState(t),[g,p]=w.useState(()=>new Set),f=w.useRef(!1),m=mo(fo(ho,{activationConstraint:{distance:6}})),v=w.useCallback(()=>{window.setTimeout(()=>{f.current=!1},0)},[]);w.useEffect(()=>{i(t)},[t]);const N=w.useMemo(()=>{if(!a)return new Map;const E=new Map(a.states.map(k=>[k.value,[]]));for(const k of h){const y=Yt(k,a.field),x=E.has(y)?y:a.states[0]?.value;x&&E.get(x)?.push(k)}for(const[k,y]of E)E.set(k,hs(y,l));return E},[h,l,a]);if(!a)return null;const d=E=>{p(k=>{const y=new Set(k);return y.has(E)?y.delete(E):y.add(E),y})},j=()=>{f.current=!0},S=E=>{const k=String(E.active.id),y=E.over?String(E.over.id):null,x=Xa(h,k,y,a,l);if(!x){v();return}const{entityId:T,changedMetadata:$,nextMetadata:F}=x,K=h.find(H=>H.id===T)?.metadata;i(H=>Ln(H,T,F)),c(T,$).catch(()=>{i(H=>Ln(H,T,K))}),v()};return n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-base font-semibold",children:"Board"}),n.jsxs("p",{className:"text-sm text-muted-foreground",children:["Grouped by ",Gt(a.field),typeof s=="number"&&s>h.length?n.jsxs(n.Fragment,{children:[" · ",n.jsxs("span",{className:"text-amber-600 dark:text-amber-500",children:["showing first ",h.length," of ",s," — narrow with search"]})]}):null]})]}),n.jsx(po,{sensors:m,onDragStart:j,onDragEnd:S,children:n.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:a.states.map(E=>{const k=N.get(E.value)??[],y=E.collapsed??E.terminal,x=y&&!g.has(E.value);return n.jsxs(Za,{id:E.value,children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[E.terminal?n.jsx(hr,{className:"h-4 w-4 text-muted-foreground"}):null,n.jsx("h3",{className:"text-sm font-medium",children:E.label})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(Vt,{variant:"secondary",className:"text-xs",children:k.length}),y?n.jsx(V,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",onClick:()=>d(E.value),children:x?"Show":"Hide"}):null]})]}),x?n.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:[k.length," hidden ",E.label?.toLowerCase()," item",k.length===1?"":"s"]}):n.jsx("div",{className:"space-y-2",children:k.length>0?k.map(T=>n.jsx(ei,{entity:T,owner:e,statusField:a.field,entityTypeIcon:o,schema:r,didDragRef:f},T.id)):n.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:["No ",E.label?.toLowerCase()," items"]})})]},E.value)})})})]})}const ni=w.memo(ti);function si(e){let t=0;for(let s=0;s<e.length;s++)t=(t<<5)-t+e.charCodeAt(s),t|=0;return t.toString(36)}function gs(e,t){return{queryKey:["metric_series",e,si(t)],queryFn:()=>bt("metric_series",{sql:t},{slug:e}),staleTime:6e4}}function ys(e,t){const s=!!e&&!!t,r=gs(e??"",t??"");return Vn({...r,enabled:s})}ys.queryOptions=(e,t)=>gs(e,t);function ri(e,t){if(!e?.columns?.length||!e.rows)return[];const s=e.columns.indexOf(t);return s<0?[]:e.rows.map(r=>Number(r[s])||0)}const Rn=/^[a-z][a-z0-9_]*$/;function oi(e){const t=Object.entries(e);for(const[o,c]of t){if(!Rn.test(o))throw new Error(`lifecycleCumulativeStatsSql: unsafe column name '${o}'`);if(!Rn.test(c))throw new Error(`lifecycleCumulativeStatsSql: unsafe entity_type '${c}'`)}const s=t.flatMap(([o,c])=>[`COUNT(*) FILTER (
3
- WHERE semantic_type = 'change'
4
- AND metadata->>'category' = 'lifecycle'
5
- AND metadata->>'entity_type' = '${c}'
6
- AND metadata->>'op' = 'created'
7
- ) AS ${o}_added`,`COUNT(*) FILTER (
8
- WHERE semantic_type = 'change'
9
- AND metadata->>'category' = 'lifecycle'
10
- AND metadata->>'entity_type' = '${c}'
11
- AND metadata->>'op' = 'deleted'
12
- ) AS ${o}_removed`]).join(`,
13
- `),r=t.map(([o])=>` SUM(COALESCE(b.${o}_added, 0) - COALESCE(b.${o}_removed, 0))
14
- OVER (ORDER BY d.bucket) AS ${o}`).join(`,
15
- `);return`
16
- WITH days AS (
17
- SELECT generate_series(
18
- date_trunc('day', now() - interval '13 days'),
19
- date_trunc('day', now()),
20
- interval '1 day'
21
- ) AS bucket
22
- ),
23
- buckets AS (
24
- SELECT
25
- date_trunc('day', created_at) AS bucket,
26
- ${s}
27
- FROM events
28
- WHERE created_at > now() - interval '14 days'
29
- GROUP BY 1
30
- )
31
- SELECT d.bucket,
32
- ${r}
33
- FROM days d
34
- LEFT JOIN buckets b ON b.bucket = d.bucket
35
- ORDER BY d.bucket
36
- `}const ai={"memory-activity":`
37
- WITH days AS (
38
- SELECT generate_series(
39
- date_trunc('day', now() - interval '13 days'),
40
- date_trunc('day', now()),
41
- interval '1 day'
42
- ) AS bucket
43
- ),
44
- buckets AS (
45
- SELECT
46
- date_trunc('day', created_at) AS bucket,
47
- COUNT(*) FILTER (
48
- WHERE semantic_type NOT IN ('change', 'audit', 'operation')
49
- ) AS events_count,
50
- COUNT(*) FILTER (
51
- WHERE semantic_type = 'change'
52
- AND metadata->>'category' = 'lifecycle'
53
- AND metadata->>'entity_type' = 'connection'
54
- AND metadata->>'op' = 'created'
55
- ) AS connections_added,
56
- COUNT(*) FILTER (
57
- WHERE semantic_type = 'change'
58
- AND metadata->>'category' = 'lifecycle'
59
- AND metadata->>'entity_type' = 'connection'
60
- AND metadata->>'op' = 'deleted'
61
- ) AS connections_removed
62
- FROM events
63
- WHERE created_at > now() - interval '14 days'
64
- GROUP BY 1
65
- )
66
- SELECT d.bucket,
67
- COALESCE(b.events_count, 0)::int AS events,
68
- SUM(COALESCE(b.connections_added, 0) - COALESCE(b.connections_removed, 0))
69
- OVER (ORDER BY d.bucket) AS connections
70
- FROM days d
71
- LEFT JOIN buckets b ON b.bucket = d.bucket
72
- ORDER BY d.bucket
73
- `};function ii(e){if(typeof e.sql=="string"&&e.sql.trim())return e.sql;if(e.lifecycle&&typeof e.lifecycle=="object"){const t=Object.fromEntries(Object.entries(e.lifecycle).map(([s,r])=>[s,String(r)]));if(Object.keys(t).length>0)try{return oi(t)}catch{return null}}return typeof e.preset=="string"?ai[e.preset]??null:null}function ci({owner:e,sql:t,lifecycle:s,preset:r,column:o,chart:c,height:a,width:l,color:h,label:i,className:g}){const p=w.useMemo(()=>ii({sql:t,lifecycle:s,preset:r}),[t,s,r]),f=typeof e=="string"&&e?e:null,{data:m}=ys(f,p),v=String(o??""),N=w.useMemo(()=>ri(m,v),[m,v]),d=w.useMemo(()=>!m?.columns?.length||!m.rows?[]:m.rows.map((S,E)=>({label:String(S[0]??"").slice(0,10),value:N[E]??0})),[m,N]);if(!f||!p||!v)return null;const j=c==="line"?n.jsx(co,{data:d,height:typeof a=="number"?a:void 0}):n.jsx(lo,{data:N,height:typeof a=="number"?a:void 0,width:typeof l=="number"?l:void 0,color:typeof h=="string"?h:void 0});return i==null?n.jsx("div",{className:g,children:j}):n.jsxs("div",{className:g,children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:String(i)}),j]})}function li({metadata:e,metadataSchema:t,name:s,typeIcon:r,initialsFallback:o,className:c}){return n.jsx(ns,{metadata:e,metadataSchema:t,name:String(s??""),typeIcon:r,initialsFallback:!!o,className:c})}function di({entity:e,owner:t,className:s,onClick:r,children:o}){const c=e;if(!c)return n.jsx(n.Fragment,{children:o});const a=Gn(String(t??""),ss(c));return n.jsx(Pe,{to:a,className:s,onClick:r,children:o})}function ui({state:e}){return e?n.jsx(no,{...e}):null}function mi({state:e,onUpdate:t}){return e?n.jsx(ni,{...e,onUpdate:t}):null}const fi={"entity-avatar":li,"entity-link":di,"entity-table":ui,"entity-board":mi,"metric-series":ci};function pi({ownerSlug:e,typeSlug:t,title:s,shape:r}){const[o,c]=w.useState(!1),a=nt(),{visible:l,system:h,isTypesLoading:i}=xr(e),g=f=>{c(!1);const m=`/${e}/${Xn(f)}`;a({to:r?`${m}/${Zn}/${r}`:m})},p=f=>n.jsxs(jr,{value:`${f.name} ${f.slug}`,onSelect:()=>g(f.slug),children:[n.jsx(Ct,{icon:f.icon,className:"mr-2 h-4 w-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate",children:f.name||f.slug}),f.slug===t?n.jsx(Er,{className:"ml-2 h-3.5 w-3.5 shrink-0","aria-label":"Current"}):null,f.entity_count!=null?n.jsx("span",{className:"ml-2 shrink-0 text-xs tabular-nums text-muted-foreground",children:f.entity_count.toLocaleString()}):null]},f.slug);return n.jsxs(Yn,{open:o,onOpenChange:c,children:[n.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:n.jsx(Kn,{asChild:!0,children:n.jsxs(V,{type:"button",variant:"ghost",className:"-ml-2 h-auto gap-1.5 px-2 py-1 text-2xl font-semibold tracking-tight",children:[s,n.jsx(Jn,{className:"h-5 w-5 text-muted-foreground"})]})})}),n.jsx(Qn,{align:"start",className:"w-72 p-0",children:n.jsxs(br,{children:[n.jsx(vr,{autoFocus:!0,placeholder:"Find a type…"}),n.jsxs(wr,{children:[n.jsx(kr,{children:i?"Loading types…":"No type matches."}),l.length>0?n.jsx(un,{heading:"Types",children:l.map(p)}):null,h.length>0?n.jsx(un,{heading:"System",children:h.map(p)}):null]}),n.jsx(Nr,{}),n.jsxs(Pe,{to:"/$owner/data",params:{owner:e},onClick:()=>c(!1),className:"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:text-foreground",children:[n.jsx(Sr,{className:"h-4 w-4"}),"Schema map"]})]})})]})}function hi(e){return Object.entries(e?.metrics_config?.segments??{}).filter(([,t])=>t.on==="entity").map(([t,s])=>({name:t,description:s.description}))}const ht={table:{label:"Table",icon:$r},board:{label:"Board",icon:Ir},graph:{label:"Graph",icon:qn}},xs=(e,t)=>`lobu.record-shape:v1:${e}/${t}`,gi=new Set(["table","board","graph"]);function yi(e,t){const s=An(xs(e,t));return s&&gi.has(s)?s:void 0}function xi(e,t,s){Pn(xs(e,t),s)}const In=":records";function bi({ownerSlug:e,entityTypeSlug:t,create:s,onCreateChange:r,viewKey:o,shape:c}){const{orgContext:a,hasOrgContext:l}=De(),h=Wn(t,a),{data:i,isLoading:g,error:p}=h;Cr(`/${e}`,a);const f=_r(),[m,v]=w.useState({key:"",page:0}),N=es({strict:!1}),d=nt(),j=Jt(),S=`/${e}/${Xn(t)}`,E=!g&&i?.slug===t,{collection:k,error:y,presentation:x,preset:T,edited:$,table:F}=w.useMemo(()=>wa(N,i?.metadata_schema,!!o),[N,i?.metadata_schema,o]),A=E?y:void 0,K=w.useMemo(()=>Ea(N,k),[N,k]),[H,se]=w.useState(!1),[W,ge]=w.useState(0),ne=k.search??"",U=k.segment,Ce=JSON.stringify(k),ue=U?hi(i).find(R=>R.name===U)??{name:U,description:""}:null,Q=R=>void d({to:".",search:{...Ve(R),...K},replace:!0}),ee=Mr(h.data),me=ee?F.sort:_a(F),_e=me?.field,Ue=me?.order,ae=w.useMemo(()=>_e?[{id:_e,desc:Ue==="desc"}]:[],[_e,Ue]),ve=w.useCallback(R=>void d({to:".",search:{...o?Ve(N):{},...K,$table:JSON.stringify(R)},replace:!0}),[d,o,N,K]),Fe=w.useCallback(R=>{const Y=typeof R=="function"?R(ae):R;Y[0]&&ve({...F,sort:{field:Y[0].id,order:Y[0].desc?"desc":"asc"}})},[ae,ve,F]),Me=s===!0,Te=()=>r(!0),we=()=>r(!1),ze=ae[0]?.id,fe=ae[0]?ae[0].desc?"desc":"asc":void 0,ke=h.data?.metadata_schema,ye=!!tn(ke)&&!ee,Ne=Ya(ke,{isDerived:ee}),le=ts(a),Le=Dt(le.data??[],t,k),Se=(R,Y=!1,he=Ve(N))=>{const pe=!o||!le.data||Dt(le.data,t,R).some(dt=>dt.key===o);d({to:pe?".":S,search:{...pe&&o?he:{},...ka(R,T?.key),$table:JSON.stringify(F)},replace:Y})},xe=R=>{const Y=R?xt(R):{},he=!o||Dt(le.data??[],t,Y).some(pe=>pe.key===o);se(!1),ge(pe=>pe+1),d({to:he?".":S,search:R?{$preset:R.key}:{}})},{isAdmin:qe}=Dn(a.organizationId),Re=Tr(a),C=qe&&!!i&&!h.isPlaceholderData,u=w.useRef(N);u.current=N;const M=async()=>{if(!T)return;const R=JSON.stringify(N),{data:Y}=await h.refetch(),he=Y?.metadata_schema,pe=he?Qt(he[Ht]??{}):void 0,dt=pe?.presets?.find(ut=>ut.key===T.key);if(!Y||!he||!pe||!dt){Bn.error("This saved filter changed. Reload and try again.");return}const It=Na(dt,k,F,pe);await Re.mutateAsync({slug:Y.slug,metadata_schema:{...he,[Ht]:{...pe,presets:pe.presets?.map(ut=>ut.key===It.key?It:ut)}}}).then(()=>!0,()=>!1)&&(await h.refetch(),JSON.stringify(u.current)===R&&xe(It))},b=w.useMemo(()=>yi(e,t),[e,t]),_=Lr(le.data??[],t,{viewKey:o,shape:c??(o?void 0:b)},Ne,k),L=_.kind==="builtin"?_.mode==="board"&&!ye?"table":_.mode:null,z=L==="graph";w.useEffect(()=>{c&&E&&L&&xi(e,t,L)},[c,E,L,e,t]);const P=["table",...ye?["board"]:[],"graph"],O=_.kind==="view"?_.view:null,D=_.kind==="missing"?_.key:null,ie=_.kind==="inapplicable"?_:null,re=L==="table"?50:200,be=`${t}?${Ce}&sort=${JSON.stringify(F.sort)}&size=${re}`,Ie=m.key===be?m.page:0,Ge=w.useCallback(R=>v(Y=>({key:be,page:R(Y.key===be?Y.page:0)})),[be]),$e=mn(t,a,{limit:re,offset:Ie*re,search:ne.trim()||void 0,sortBy:ze,sortOrder:fe,segment:U,filters:k.filters,enabled:E&&!o&&!A}),Ye=mn(t,a,{limit:1,offset:0,parentId:null,search:ne.trim()||void 0,segment:U,filters:k.filters,enabled:E&&!o&&!A&&!ee}),{data:Ke,error:Tt}=$e,I=$e.isLoading||$e.isPending&&$e.fetchStatus==="paused",G=A||p||(o?null:Tt),J=!!o&&le.data===void 0&&le.isError,B=Ke?.entities??[],X=Ke?.metadata?.has_more??!1,q=Ke?.metadata?.total_count??0,Oe=B.length>0||ne.trim().length>0||Ie>0||!!U||!!k.filters?.length,te=i?.name?.trim()||Ft(t),de=i?.icon||void 0,Z=ee,ce=ke,je=!A&&(!l||!E||(o?le.data===void 0&&!le.isError:I||!ee&&Ye.isLoading)),We=Ke?.linked_entities??{},st=Ye.data?.metadata?.total_count,Je=q>0&&typeof st=="number"?st<q:!1,rt=w.useMemo(()=>i?.measure_columns??[],[i?.measure_columns]),Qe=w.useCallback(R=>ve({...F,columns:R}),[ve,F]),ot=w.useMemo(()=>({entities:B,owner:e,schema:ce,entityTypeIcon:de,isDerived:Z,measureColumns:rt,linkedEntityLookups:We,hasAnyParents:Je,sorting:ae,onSortingChange:Fe,visibleColumns:F.columns,columnChoices:so(ce,Z,B),onVisibleColumnsChange:Qe,page:Ie,pageSize:re,totalCount:q,hasMore:X,pageTitle:te,onPrevPage:()=>Ge(R=>Math.max(0,R-1)),onNextPage:()=>Ge(R=>R+1)}),[B,e,ce,de,Z,rt,We,Je,ae,F.columns,Qe,Fe,Ge,Ie,re,q,X,te]),nn=q>B.length,sn=`showing first ${B.length} of ${q} — narrow with search`,rn=w.useMemo(()=>({owner:e,entityType:i,entities:B,totalCount:q,schema:ce,entityTypeIcon:de}),[e,i,B,q,ce,de]),Lt=w.useMemo(()=>({tableState:ot,boardState:rn,owner:e,schema:ce,entityType:i,entityTypeIcon:de,totalCount:q,isTruncated:nn,truncationNotice:sn,canCreate:!Z,addLabel:`Add ${i?.name||Ft(t)}`}),[ot,rn,e,ce,i,de,q,nn,sn,Z,t]),bs=w.useMemo(()=>Ja({canShowBoard:ye,builtinData:Lt,builtInLabels:{table:ht.table.label,board:ht.board.label}}),[ye,Lt]),on=L?bs.find(R=>R.id===L)??null:null,vs=on?.template??ps,ws=on?.data??Lt,an=R=>void d({to:R===In?S:`${S}${Pr(R)}`,search:K}),Rt=Ve(N),ks=xo(O?.params,Rt,R=>void d({to:".",search:{...Ve(R),...K}})),Ns=()=>Se({...k,filters:[],segment:void 0},!1,bo(O?.params,Rt)),cn=`Moved on ${i?.name||i?.slug||t} board`,ln=w.useMemo(()=>(R,Y)=>f.mutateAsync({entityId:R,metadata:Y,field_note:cn}),[f,cn]),Ss=w.useMemo(()=>({updateEntity:ln,openCreate:()=>r(!0)}),[ln,r]),dn=R=>j?n.jsx(V,{type:"button",variant:"ghost",size:"icon",className:oe("size-8 text-muted-foreground hover:text-foreground",R),"aria-label":"Edit type",title:"Edit type",onClick:()=>j.open({href:Ar(e,t),title:te}),children:n.jsx(Or,{className:"h-4 w-4"})}):null;return n.jsx(ro,{title:n.jsx(pi,{ownerSlug:e,typeSlug:t,title:te,shape:o?null:L}),actions:dn(Me||!E?"":"hidden @lg:inline-flex"),controls:n.jsxs(n.Fragment,{children:[Me?n.jsx("div",{className:"max-w-3xl",children:n.jsx(xa,{onClose:we,entityTypeSlug:t,orgContext:a})}):null,!Me&&E&&n.jsxs("nav",{className:"mb-4 flex flex-wrap items-center gap-x-3 gap-y-2","aria-label":`${te} views`,children:[dn("-mr-1 @lg:hidden"),!o&&P.length>1&&n.jsx("fieldset",{className:"flex items-center rounded-md border p-0.5","aria-label":"Record layout",children:P.map(R=>{const Y=ht[R].icon,he=L===R;return n.jsx(V,{type:"button",variant:"ghost",size:"sm","aria-pressed":he,title:ht[R].label,"data-testid":`shape-${R}`,className:oe("h-7 px-2",he&&"bg-accent text-accent-foreground"),onClick:()=>void d({to:`${S}/${Zn}/${R}`,search:K,replace:!0}),children:n.jsx(Y,{className:"h-4 w-4"})},R)})}),o&&n.jsx(V,{variant:"ghost",onClick:()=>an(In),children:"Records"}),!!x.presets?.length&&n.jsxs(Yn,{open:H,onOpenChange:se,children:[n.jsx(Kn,{asChild:!0,children:n.jsxs(V,{variant:"outline",className:oe("gap-2",$&&"border-dashed border-primary"),"data-edited":$||void 0,title:"Choose saved filter",children:[T?.label??(k.filters?.length||k.search?"Custom filter":"All records"),$?n.jsx("span",{className:"text-xs font-normal text-primary",children:"Edited"}):null,n.jsx(Jn,{className:"h-4 w-4 text-muted-foreground"})]})}),n.jsxs(Qn,{align:"start",className:"w-60 p-1",children:[n.jsx(V,{variant:T?"ghost":"secondary",className:"w-full justify-start",onClick:()=>xe(),children:"All records"}),x.presets.map(R=>n.jsx(V,{variant:T?.key===R.key?"secondary":"ghost",className:"w-full justify-start",onClick:()=>xe(R),children:R.label},R.key))]})]}),T&&$?n.jsxs("div",{className:"-ml-2 mr-2 inline-flex items-center gap-1",children:[n.jsx(V,{variant:"ghost",size:"sm",onClick:()=>xe(T),children:"Reset"}),C?n.jsx(V,{size:"sm",disabled:Re.isPending,onClick:()=>void M(),children:Re.isPending?"Saving…":"Save"}):null]}):null,!A&&n.jsx($a,{collection:k,schema:ce,label:te,org:a??"",facetQuery:x.facetQuery,onChange:Se,viewFilters:ks,onClearAll:Ns,segmentChip:ue?{id:"segment",label:"Segment",op:"is",value:Ft(ue.name),title:ue.description||void 0,editor:ue.description?{kind:"custom",render:()=>n.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:ue.description})}:void 0,onRemove:()=>Se({...k,segment:void 0})}:void 0},`filters:${t}:${W}`),Le.map(R=>n.jsx(V,{"data-testid":`tab-${R.key}`,variant:o===R.key?"secondary":"ghost","aria-pressed":o===R.key,onClick:()=>an(R.key),children:R.name},R.key)),n.jsx(La,{label:te,search:k.search,onSearch:(R,Y)=>Se({...k,search:R},Y),className:"ml-auto min-w-40 max-w-64 flex-1"},`search:${t}:${W}`),!Z&&!o?n.jsxs(V,{size:"sm","aria-label":`Add ${te||"entity"}`,onClick:()=>Te(),children:[n.jsx(ct,{className:"mr-2 h-4 w-4"}),"Add"]}):null]})]}),children:Me?null:je?z?n.jsx(Xt,{label:`Loading ${te} graph`}):n.jsx(oo,{}):G?n.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[G.message||`Failed to load ${te.toLowerCase()}.`,A&&n.jsx(V,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>Se({}),children:"Clear filters"})]}):J?n.jsx(os,{onRetry:()=>void le.refetch()}):ie?n.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"inapplicable-view",children:[n.jsxs("h2",{className:"text-lg font-semibold",children:["“",ie.view.name,"” doesn’t apply to the current filters"]}),n.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["It appears when the selection includes"," ",Object.entries(ie.when).map(([R,Y])=>`${R} is ${Y===null?"not supplied":String(Y)}`).join(" and "),"."]}),n.jsx(Pe,{to:S,search:K,className:"mt-4 text-sm font-medium underline underline-offset-4",children:`Back to ${te}`})]}):D?n.jsx(as,{viewKey:D,backTo:S,backLabel:`Back to ${te}`}):O?n.jsx(is,{orgSlug:e,viewKey:O.key,scope:{type:t,collection:k},params:Rt,onParamsChange:Q,contentHash:O.content_hash,title:O.name,minHeight:320}):z&&Oe?n.jsx(Ua,{ownerSlug:e,typeSlug:t,sourceBacked:ee,records:B.map(R=>({...R,id:R.id??JSON.stringify([R.entity_type,R.slug])})),hasMore:X}):Oe?n.jsx(uo,{template:vs,data:ws,actions:Ss,components:fi}):n.jsx(Un,{icon:Rr,iconElement:n.jsx(Ct,{icon:i?.icon,className:"mb-4 h-12 w-12 opacity-50"}),title:`No ${te.toLowerCase()} yet`,description:Z?"This view has no rows yet. They appear as the underlying data arrives.":`Get started by creating your first ${i?.name?.toLowerCase()||"entity"}.`,actionLabel:Z?void 0:`Add ${i?.name||"Entity"}`,onAction:Z?void 0:()=>Te()})})}function vi(e,t){return oe("inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",t,e?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground")}function wi({ownerSlug:e,typeScope:t,create:s,createType:r=!1,viewKey:o,shape:c}){const a=nt(),{orgContext:l}=De(),h=es({strict:!1}),i=t?Dr(t):void 0,g=i==="$member",p=()=>{a({to:"/$owner/data",params:{owner:e},search:{}})},f=v=>{if(!i)return;const N=Fn(e,i);a({to:N.to,params:N.params,search:v?{create:!0}:{},replace:!0})},m=r?n.jsx("div",{className:"mx-auto w-full max-w-3xl",children:n.jsx(wo,{entityType:null,orgContext:l,onClose:p})}):i?n.jsx(bi,{ownerSlug:e,entityTypeSlug:i,create:s,onCreateChange:f,viewKey:o,shape:c}):n.jsx(ki,{ownerSlug:e,viewKey:o,search:h});return n.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:g?n.jsx(ko,{children:m}):m})}function ki({ownerSlug:e,viewKey:t,search:s}){const r=nt(),{orgContext:o}=De(),{data:c,isError:a,error:l,refetch:h}=ts(o),i=Fr(c??[],t),g=zr(),p=Wr(c??[]),f=a?Br(l,{subject:"Views"}):null;return t&&c===void 0?a?n.jsx(os,{error:l,onRetry:()=>void h()}):null:i.kind==="missing"?n.jsx(as,{viewKey:i.key,backTo:`/${e}/data`,backLabel:"Back to Memory"}):n.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:[g&&p.length>0?n.jsxs("nav",{"aria-label":"Workspace views",className:"flex shrink-0 flex-wrap gap-1",children:[n.jsx(Pe,{to:"/$owner/data",params:{owner:e},search:{},activeOptions:{exact:!0},"aria-current":t?void 0:"page",className:$n(!t),children:"Overview"}),p.map(m=>n.jsx(Pe,{to:"/$owner/data/-/views/$viewKey",params:{owner:e,viewKey:m.key},search:{},activeOptions:{exact:!0},"aria-current":t===m.key?"page":void 0,className:$n(t===m.key),children:m.name},m.key))]}):null,g&&f?n.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:[f.title,"."," ",f.retryable?n.jsx("button",{type:"button",onClick:()=>void h(),className:"underline underline-offset-4",children:"Retry"}):null]}):null,i.kind==="view"?n.jsxs(n.Fragment,{children:[n.jsx(vo,{decls:i.view.params,params:Ve(s),onParamsChange:m=>void r({to:".",search:m})}),n.jsx(is,{orgSlug:e,viewKey:i.view.key,scope:{},params:Ve(s),onParamsChange:m=>void r({to:".",search:m,replace:!0}),contentHash:i.view.content_hash,title:i.view.name,minHeight:400})]}):n.jsx(ya,{ownerSlug:e})]})}const $n=e=>vi(e,"min-h-10 max-w-full gap-2 px-3 text-sm break-words");function Di({ownerSlug:e,typeScope:t,create:s,createType:r=!1,viewKey:o,shape:c}){return n.jsxs(Hr,{className:"gap-6 pt-2.5 pb-8",children:[n.jsx(Ur,{}),n.jsx(Vr,{owner:e,children:a=>n.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:n.jsx(wi,{ownerSlug:a.ownerSlug,typeScope:t,create:s,createType:r,viewKey:o,shape:c})})})]})}export{Di as M};
74
- //# sourceMappingURL=memory-browse-page-rAKfVdQ_.js.map
@@ -1,2 +0,0 @@
1
- import{aD as v,aE as N,j as s,gk as y,cY as u,Y as p,i as f,B as w,gm as b}from"./index-B-Ab8srM.js";function D(o,r){const l=new Map(r.map(e=>[e.slug,e])),i=new Map,d=e=>{const a=e.model?.trim();if(!a)return;const t=`${e.slug}/${a}`;i.has(t)||i.set(t,{value:t,provider:e.provider,model:a,isDefault:e.isDefault})};for(const e of o){const a=l.get(e.kind)??l.get(e.slug),t={slug:e.slug,provider:e.displayName||e.slug,isDefault:e.isDefault};d({...t,model:e.capabilities.text?.model}),d({...t,model:a?.defaultModel});for(const x of a?.models??[])d({...t,model:x})}for(const e of r){if(!e.systemAvailable)continue;const a={slug:e.slug,provider:e.displayName||e.slug,isDefault:!1};d({...a,model:e.defaultModel});for(const t of e.models)d({...a,model:t})}return[...i.values()]}function M(o,r){const l=o.trim();return l.length>0&&l!=="auto"&&!r.some(i=>i.value===l)}function S({value:o,onChange:r,placeholder:l,disabled:i,className:d}){const{data:e=[]}=v(),{data:a=[]}=N(),t=D(e,a),x=t.find(c=>c.value===o),h=o==="auto"?"auto":x?.value??o;return s.jsx(y,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:c=>s.jsxs(w,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:i,className:f("w-full justify-between font-normal",o?"":"text-muted-foreground",d),children:[s.jsx("span",{className:"truncate",children:o?h:l}),s.jsx(b,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(c,j)=>{const m=j.trim(),g=M(m,t);return s.jsxs(s.Fragment,{children:[s.jsxs(u,{value:"__inherit__ use default inherit",onSelect:()=>{r(""),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===""?"opacity-100":"opacity-0")}),s.jsx("span",{className:"text-muted-foreground",children:l})]}),s.jsxs(u,{value:"auto newest latest",onSelect:()=>{r("auto"),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o==="auto"?"opacity-100":"opacity-0")}),s.jsxs("span",{children:["auto"," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:"(newest for the provider)"})]})]}),t.map(n=>s.jsxs(u,{value:`${n.provider} ${n.model} ${n.value}`,onSelect:()=>{r(n.value),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===n.value?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"truncate",children:[n.provider," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:n.model}),n.isDefault?s.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},n.value)),g?s.jsxs(u,{value:`__custom__ ${m}`,onSelect:()=>{r(m),c()},className:"cursor-pointer",children:[s.jsx(p,{className:"mr-2 h-4 w-4 opacity-0"}),s.jsxs("span",{children:["Use ",s.jsx("span",{className:"font-mono text-xs",children:m})]})]}):null]})}})}export{S as M,D as b,M as s};
2
- //# sourceMappingURL=model-selector-onvGA9Ww.js.map
@@ -1,2 +0,0 @@
1
- import{ht as o,c as d,a6 as x,q as b,at as h,bf as w,j as a,ak as f,al as j,gF as A,b3 as L,gG as C,L as N,gH as S,eW as k,b2 as y,cb as E}from"./index-B-Ab8srM.js";import{A as O}from"./agent-editor-form-CirqCpcM.js";import"./definition-comparison-C3k6Wa9B.js";import"./automation-source-list-D8ZSavQU.js";import"./schema-value-BUgC0Ro8.js";import"./json-diff-B-1Swv_y.js";import"./index-Vcq4gwWv.js";import"./model-selector-onvGA9Ww.js";function M(){const{owner:e}=o.useParams(),t=o.useSearch(),r=d(),i=x(),{isAuthenticated:c}=b(),{isMember:g,isLoading:m}=h(),n=c&&g,{data:u=[],isLoading:l}=w({enabled:n});return a.jsx(f,{className:"gap-3 pt-2.5 pb-8",children:a.jsxs(j,{className:"flex flex-1 flex-col gap-6",children:[a.jsx(A,{breadcrumb:a.jsx(C,{crumbs:[a.jsx(N,{to:"/$owner/agents",params:{owner:e},className:S,children:"Agents"},"agents")]}),icon:a.jsx(L.agents.icon,{className:"h-6 w-6"}),title:"Build a managed agent",caption:"Create an agent that Lobu runs and manages for this workspace."}),m||n&&l?a.jsx(k,{rows:1}):n?a.jsx(O,{mode:{kind:"create"},existingAgentIds:u.map(s=>s.agentId),onCreated:async s=>{const p=["agents",e];if(await i.refetchQueries({queryKey:p,exact:!0}),t.platform&&t.listen){await r({to:"/$owner/automations/new",params:{owner:e},search:{...t,agent:s}});return}await r({to:"/$owner/agents/$agentId",params:{owner:e,agentId:s}})}}):a.jsx(y,{icon:E,title:"Workspace membership required",description:"Only workspace members can build managed agents."})]})})}export{M as component};
2
- //# sourceMappingURL=new-BmehH1uR.js.map
@@ -1,2 +0,0 @@
1
- import{c as S,at as C,aH as k,aB as A,bf as T,r as g,j as e,ak as L,al as B,gG as P,L as f,gH as R,d5 as $,S as p,hb as w,az as I}from"./index-B-Ab8srM.js";import{C as O,A as D}from"./create-automation-form-B12yTrmj.js";import"./entity-options-CGTjLlcS.js";import"./use-automations-II_YJWtN.js";import"./device-automation-Dp3faMvp.js";import"./model-selector-onvGA9Ww.js";import"./skill-editor-D_W3QlRz.js";import"./json-diff-B-1Swv_y.js";import"./index-Vcq4gwWv.js";import"./use-mention-search-Bxlpd6Dp.js";import"./automation-source-list-D8ZSavQU.js";function E(n){return n.includes(":")?n.slice(n.indexOf(":")+1):n}function F({prefillAgentId:n,onCancel:t,initialTriggers:l,conversationSetup:h}){const{org:a}=C(),[c,d]=g.useState({ready:!1,triggers:[]}),[u,N]=g.useState(),o=g.useCallback(s=>{d(m=>JSON.stringify(m)===JSON.stringify(s)?m:s)},[]),r=u??l;return e.jsx(O,{startFromScratch:!!l,organizationId:a?.id??"",prefillAgentId:n,conversationSetup:h,onClose:t,onPrefillTriggers:s=>N(s.length>0?s:void 0),onSuccess:t,hideHeader:!0,hideCancel:!0,submitLabel:"Create Automation",submitDisabled:!c.ready,createFields:{triggers:c.triggers},triggerFields:e.jsx(D,{organizationId:a?.id??null,initialTriggers:r,onChange:o},JSON.stringify(r??"new"))})}function z({owner:n,prefilled:t}){const l=S(),{org:h}=C(),a=k(h?.id??null,{status:"active",limit:500}),c=A(h?.id??null),{data:d=[]}=T(),u=!!(t?.platform&&(t.listen||t.resource)),N=u&&(a.isLoading||c.isLoading),o=g.useMemo(()=>{if(!t?.platform||!t.listen&&!t.resource)return;const x=a.data??[],j=t.connection?x.find(i=>i.slug===t.connection):(()=>{const i=x.filter(v=>v.connector_key!==t.platform?!1:t.resource?!0:v.facets.chat&&(v.external_tenant_id??"")===(t.team??""));return i.length===1?i[0]:void 0})();if(t.connection&&!j)return;const b=t.events?.split(",").map(i=>i.trim()).filter(Boolean)??[];return[{kind:"event",source:"connector",connector_key:t.platform,...j?{connection_id:j.id}:{},event_types:b.length>0?b:t.listen?["message.created"]:[],match:t.resource?{resource_ref:t.resource,...t.resource_type?{resource_type:t.resource_type}:{}}:{channel_id:E(t.listen??"")},execution:"turn",active_run:t.listen?"steer":"queue",output:t.listen?"reply_to_source":"silent",skip_if_unchanged:!t.listen}]},[a.data,t]),r=c.data?.find(x=>x.key===t?.platform)?.name,s=t?.label??t?.listen,m=g.useMemo(()=>t?.listen&&o&&s?{name:r?`${r}: ${s}`:s}:void 0,[s,r,o,t?.listen]),y=()=>void l({to:"/$owner/automations",params:{owner:n}}),_=o?t?.resource?`React to changes on ${t.label??t.resource}.`:`React to messages in ${t?.label??t?.listen}.`:u&&!a.isLoading?"Choose the matching connection and event, then define the reaction.":"Start from a template, from scratch, or clone an existing Automation.";return e.jsx(L,{className:"gap-6 pt-2.5 pb-8",children:e.jsxs(B,{className:"flex min-w-0 flex-col gap-4",children:[e.jsx(P,{crumbs:[e.jsx(f,{to:"/$owner/automations",params:{owner:n},className:R,children:"Automations"},"automations")],current:"New automation"}),e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("h1",{className:"flex min-w-0 items-center gap-2 truncate font-display text-xl font-semibold",children:[e.jsx($,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),"New automation"]})})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:_}),m&&!t?.agent?e.jsxs("p",{className:"text-sm text-muted-foreground",children:[d.length===0?"This workspace has no agents yet. ":"Choose the agent that answers here, or ",e.jsx(f,{to:"/$owner/agents/new",params:{owner:n},search:t,className:"underline underline-offset-4",children:d.length===0?"Create an agent":"create an agent"})," ","and come back to finish this setup."]}):null,N?e.jsxs("div",{className:"space-y-3",children:[e.jsx(p,{className:"h-10 w-full"}),e.jsx(p,{className:"h-32 w-full"})]}):u&&t?.connection&&!o?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"This connection is no longer available. Reopen setup from your conversation."}):e.jsx(F,{prefillAgentId:t?.agent,onCancel:y,initialTriggers:o,conversationSetup:m})]})})}function Z(){const{owner:n}=w.useParams(),t=w.useSearch();return e.jsx(I,{owner:n,children:()=>e.jsx(z,{owner:n,prefilled:t})})}export{Z as component};
2
- //# sourceMappingURL=new-KDi15LWZ.js.map
@@ -1,2 +0,0 @@
1
- import{a6 as ge,r as j,bP as Ie,bQ as Be,bR as Ke,bS as Me,bT as be,j as e,bU as Y,B as C,bV as Ve,b2 as He,bW as Ue,bX as Ge,bY as Ye,bZ as Je,b_ as Ze,b$ as Xe,c0 as es,c1 as ve,bB as ie,c2 as ss,c3 as ts,c4 as ns,c5 as me,c6 as is,c7 as as,c as os,a1 as Le,v as rs,c8 as cs,c9 as ne,ca as ls,H as je,I as Ne,cb as ds,cc as us,cd as ms,ab as Ce,bg as hs,S as O,J as le,ce as ps,cf as _e,cg as ke,ch as gs,K as xs,ci as Se,w as fs,cj as ys,ak as bs,al as vs,ck as js,i as Ns,cl as Cs}from"./index-B-Ab8srM.js";import{P as he,a as We,A as _s}from"./agent-permissions-matrix-Dsc26dyW.js";import{C as we,a as Ae,b as ze,c as Oe}from"./card-DT9mSjSp.js";const Pe=["auto","approval","deny"],ks={matched_rule:"Matching policy rules apply.",default_approval:"No rule matches; approval is required.",unresolved_principal:"The requesting agent or Automation could not be identified.",parent_approval:"Approval is inherited from the parent action.",unavailable_operation:"This action is unavailable on the connection."},De={read:"Reads",write:"Writes",destructive:"Destructive writes",non_destructive:"Non-destructive writes",unknown:"Unclassified writes"};function pe(s){return{operation_key:s.operation_key??null,connector_key:s.connector_key??null,connection_id:s.connection_id??null,operation_category:s.operation_category??null}}const de=s=>JSON.stringify(pe(s)),$e=s=>({...s,effect:s.effects.execute??"approval"});function F({label:s,value:n,onChange:o,children:r,disabled:h}){return e.jsxs("label",{className:"flex min-w-0 flex-col gap-1 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),e.jsx("select",{"aria-label":s,value:n,onChange:c=>o(c.target.value),disabled:h,className:"h-9 w-full rounded-lg border bg-background px-2 text-foreground",children:r})]})}function Ss(s,n){const o=n.connections?.find(r=>r.id===s.connection_id);return s.connection_id?`Connection: ${o?.display_name||o?.connector_key||"Unavailable"} (#${s.connection_id})`:s.connector_key?`Connector: ${n.connectors?.find(r=>r.key===s.connector_key)?.name||s.connector_key}`:"All connectors"}function ws(s,n){return s.operation_key?n.connector_operations.find(o=>o.operation_key===s.operation_key)?.name||s.operation_key:s.operation_category?De[s.operation_category]:"All actions"}function ue(s,n){return`${Ss(s,n)} · ${ws(s,n)}`}function Ee(s){return s.connection_id?`connection:${s.connection_id}`:s.connector_key?`connector:${s.connector_key}`:"all"}function Te({catalog:s}){return e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"all",children:"All connectors"}),e.jsx("optgroup",{label:"Connectors",children:s.connectors?.map(n=>e.jsx("option",{value:`connector:${n.key}`,children:n.name},n.key))}),e.jsx("optgroup",{label:"Connections",children:s.connections?.map(n=>e.jsxs("option",{value:`connection:${n.id}`,children:[n.display_name||n.connector_key," (#",n.id,")"]},n.id))})]})}function As({label:s,ariaLabel:n,disabled:o,onRemove:r}){const[h,c]=j.useState(!1);return h?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(C,{type:"button",variant:"destructive",size:"sm",disabled:o,"aria-label":"Confirm removal",onClick:async()=>{await r()&&c(!1)},children:"Confirm"}),e.jsx(C,{type:"button",variant:"ghost",size:"sm",disabled:o,onClick:()=>c(!1),children:"Cancel"})]}):e.jsx(C,{type:"button",variant:"ghost",size:"sm",disabled:o,"aria-label":n,onClick:()=>c(!0),children:s})}function zs({owner:s,connector:n,connection:o,agent:r}){const h=ge(),[c,b]=j.useState(r??""),y=Ie(s),l=y.data,u=l?.agents.some(t=>t.id===c)?c:"",m=Be(s,u),i=Ke(s,!u),[P,_]=j.useState(o?`connection:${o}`:n?`connector:${n}`:"all"),[M,J]=j.useState(P),[I,L]=j.useState(!1),[k,W]=j.useState(""),[A,V]=j.useState("all"),[Z,E]=j.useState("approval"),[g,S]=j.useState(!1),[D,T]=j.useState(null),[H,X]=j.useState(o?String(o):""),[U,Q]=j.useState(""),R=l?.connections?.some(t=>String(t.id)===H)?H:"",w=Me(s,R?Number(R):void 0,U,u||void 0);async function G(t,f){S(!0),T(null);try{if(u){const d={resource_class:"connector_action",...pe(t)};f?await Ye(s,u,{...d,effects:{execute:f}}):await Je(s,u,d)||T("This rule was already removed. The list has been refreshed.")}else{const d=i.data;if(!d)return;const K=d.rules.filter(qe=>de(qe)!==de(t));f&&K.push({...pe(t),effect:f});const ce=await Ze(s,{revision:d.revision,rules:K});h.setQueryData(Xe(s),ce)}return await Promise.all(["write-permissions","agent-permissions","available-operations","connector-operations","policy-explanation"].map(d=>h.invalidateQueries({queryKey:[d]}))),t}catch(d){d instanceof be&&d.status===409?(T("Policies changed in another session. Review the refreshed rules before saving again."),await i.refetch()):T(d instanceof Error?d.message:"Could not save policy.")}finally{S(!1)}}const q=y.error||(u?m.error:i.error);if(q instanceof be&&q.status===403)return e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Only organization owners and admins can manage policies."});if(q)return e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Could not load policies. ",String(q)]});if(!l||(u?!m.data:!i.data))return e.jsx(Y,{label:"policies",rows:2});const v=t=>t==="all"||l.connectors?.some(f=>`connector:${f.key}`===t)||l.connections?.some(f=>`connection:${f.id}`===t)?t:"all",a=v(P),p=v(M),N=l.connections?.find(t=>`connection:${t.id}`===p),$=N?.connector_key??(p.startsWith("connector:")?p.slice(10):void 0),x=t=>p==="all"||Ee(t)==="all"?!0:t.connection_id?N?t.connection_id===N.id:l.connections?.some(f=>f.id===t.connection_id&&f.connector_key===$):t.connector_key===$;function B(t){return u?t.principal_kind==="agent"&&t.principal_id===u:!t.principal_kind}const ee=a.startsWith("connector:")?a.slice(10):a.startsWith("connection:")?l.connections?.find(t=>t.id===Number(a.slice(11)))?.connector_key:void 0,z=l.connector_operations.filter(t=>!ee||t.connector_key===ee),se=l.connections?.find(t=>t.id===Number(R))?.connector_key,ae=l.connector_operations.filter(t=>t.connector_key===se),oe=u?(m.data?.agent??[]).filter(t=>t.resource_class==="connector_action").map($e):i.data?.rules??[],te=(m.data?.floor??[]).filter(t=>t.resource_class==="connector_action"&&x(t)).map($e),Qe={connector_key:a.startsWith("connector:")?a.slice(10):a==="all"&&A==="specific"?z.find(t=>t.operation_key===k)?.connector_key??null:null,connection_id:a.startsWith("connection:")?Number(a.slice(11)):null,operation_key:A==="specific"?k:null,operation_category:A.startsWith("category:")?A.slice(9):null},re=oe.filter(x);function fe(){_(p),V("all"),W(""),E("approval"),L(!0)}const ye=(t,f=!1)=>e.jsx("div",{className:"divide-y rounded-lg border",children:t.map(d=>{const K=!f&&B(d);return e.jsxs(We,{controls:e.jsxs(e.Fragment,{children:[e.jsx(he,{options:Pe,value:d.effect,floor:"auto",compact:!0,disabled:g||!K,ariaLabel:`Policy for ${ue(d,l)}`,onChange:ce=>void G(d,ce)}),K&&e.jsx(As,{label:"Remove",disabled:g,ariaLabel:`Remove rule: ${ue(d,l)}`,onRemove:()=>G(d)})]}),children:[e.jsx("p",{className:"text-sm break-words",children:ue(d,l)}),!K&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d.principal_kind==="agent"&&!d.principal_id?"All agents":"Inherited restriction"})]},JSON.stringify([d.principal_kind,d.principal_id,de(d)]))})});return e.jsxs("div",{className:"space-y-4",children:[(p!==M||u!==c)&&e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"The requested scope is unavailable. Showing organization rules; install the connector or choose an available scope."}),e.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[e.jsx("p",{children:"Auto runs immediately. Ask waits for human approval. Block prevents execution and hides the action from agents. Authentication and guardrails still apply."}),e.jsxs("details",{className:"space-y-2",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-foreground",children:"How rules combine"}),e.jsx("p",{children:"A rule overrides another when it is narrower in target or actions and at least as narrow in the other. When rules are narrower in different ways, or use different categories, the stricter choice wins: Block, then Ask, then Auto. With no matching rule, the result is Ask. Impact categories apply only to writes."}),e.jsx("p",{children:"A connection-wide Auto does not override an organization-wide destructive Block. Add a destructive rule for that connection to make an exception."}),e.jsx("p",{children:"Agents and their Automations can only tighten organization policy. Internal browser steps inherit the parent approval; an explicit browser Block still wins."})]})]}),e.jsxs(F,{label:"Policy owner",value:u,onChange:b,disabled:g,children:[e.jsx("option",{value:"",children:"Organization"}),l.agents.map(t=>e.jsxs("option",{value:t.id,children:["Agent: ",t.name]},t.id))]}),u&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Auto adds no restriction for this agent. It inherits organization policy and cannot bypass Ask or Block."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u?"Without a matching restriction, this agent inherits organization policy.":"Without a matching rule, actions require approval (Ask)."}),e.jsx(F,{label:"Show rules for",value:p,onChange:J,disabled:g,children:e.jsx(Te,{catalog:l})}),u&&te.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Inherited organization rules"}),ye(te,!0)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:u?"Saved restrictions":"Saved rules"}),!I&&re.length>0&&e.jsx(C,{variant:"outline",size:"sm",disabled:g,onClick:fe,children:"Add rule"})]}),I&&e.jsxs("form",{className:"space-y-3 border-t pt-4",onSubmit:t=>{t.preventDefault(),!g&&(A!=="specific"||k)&&G(Qe,Z).then(f=>{f&&(L(!1),J(Ee(f)))})},children:[e.jsx("h3",{className:"text-sm font-medium",children:"Add rule"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(F,{label:"Applies to",value:a,onChange:t=>{_(t),V("all"),W("")},disabled:g,children:e.jsx(Te,{catalog:l})}),e.jsxs(F,{label:"Actions",value:A,onChange:V,disabled:g,children:[e.jsx("option",{value:"all",children:"All actions"}),e.jsx("optgroup",{label:"Categories",children:l.operation_categories?.map(t=>e.jsx("option",{value:`category:${t}`,children:De[t]},t))}),e.jsx("option",{value:"specific",children:"Specific action"})]})]}),A==="specific"&&e.jsxs(F,{label:"Specific action",value:k,onChange:W,disabled:g,children:[e.jsx("option",{value:"",children:"Choose action"}),z.map(t=>e.jsxs("option",{value:t.operation_key,children:[t.connector_name,": ",t.name]},t.operation_key))]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(he,{options:Pe,value:Z,floor:"auto",compact:!0,disabled:g,ariaLabel:"New rule decision",onChange:E}),e.jsx(Ve,{onCancel:()=>L(!1),cancelDisabled:g,children:e.jsx(C,{type:"submit",disabled:g||A==="specific"&&!k,children:g?"Saving…":"Save rule"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saving an existing scope replaces its decision. Removing a rule reveals the next matching rule."})]}),re.length?ye(re):!I&&e.jsx(He,{icon:Ue,title:"No saved rules in this scope",description:"Add a rule for all actions, a category, or a specific action.",actionLabel:"Add rule",onAction:fe})]}),D&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsxs("details",{className:"space-y-3 border-t pt-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Check an action"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs(F,{label:"Check connection",value:R,onChange:t=>{X(t),Q("")},children:[e.jsx("option",{value:"",children:"Choose connection"}),l.connections?.map(t=>e.jsxs("option",{value:String(t.id),children:[t.display_name||t.connector_key," (#",t.id,")"]},t.id))]}),e.jsxs(F,{label:"Check action",value:U,onChange:Q,disabled:!R,children:[e.jsx("option",{value:"",children:"Choose action"}),ae.map(t=>e.jsx("option",{value:t.operation_key.slice(t.connector_key.length+2),children:t.name},t.operation_key))]})]}),w.error?e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Could not check policy. ",String(w.error)]}):e.jsx("p",{"aria-live":"polite",className:"text-sm",children:U?w.isPending?"Checking…":w.data?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:Ge[w.data.effect]})," ·"," ",ks[w.data.reason]??"The server evaluated this action.",w.data.rule_ids.length>0?` · Rules ${w.data.rule_ids.map(t=>`#${t}`).join(", ")}`:""]}):"":""})]})]})}const Os=[{action:"create_type",label:"Create entity types",description:"Add a new type and its initial fields."},{action:"update_type",label:"Edit entity types",description:"Change fields, write rules, event kinds, or type metadata."},{action:"delete_type",label:"Delete entity types",description:"Remove an entity-type definition."}],Ps=[{action:"create_relationship_type",label:"Create relationship types",description:"Add a new kind of link between entity types."},{action:"update_relationship_type",label:"Edit relationship types",description:"Change a definition, or which types it may connect."},{action:"delete_relationship_type",label:"Delete relationship types",description:"Remove a relationship-type definition."}];function xe(s){return s.resource_class==="entity_schema"&&s.principal_kind===null&&s.entity_type_slug===null&&s.operation_key===null&&s.target_agent_id===null}function $s(s){return s.agent.find(xe)}function Es(s,n){return{...s,agent:[...s.agent.filter(o=>!xe(o)),n]}}function Ts(s){return{...s,agent:s.agent.filter(n=>!xe(n))}}function Rs({label:s,description:n,action:o,value:r,pending:h,onChange:c}){return e.jsxs(We,{controls:e.jsx(he,{options:as("entity_schema",o),value:r,floor:"auto",disabled:h,compact:!0,ariaLabel:s,onChange:c}),children:[e.jsx("p",{children:s}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:n})]})}function Re({title:s,actions:n,effects:o,pending:r,onChange:h}){return e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s}),e.jsx("div",{className:"divide-y overflow-hidden rounded-lg border",children:n.map(({action:c,label:b,description:y})=>e.jsx(Rs,{action:c,label:b,description:y,value:o[c]??me.entity_schema[c]??"deny",pending:r,onChange:l=>h(c,l)},c))})]})}function Fs({owner:s}){const n=ge(),o=es(s),r=Ie(s),h=ve({mutationFn:m=>ss(s,{resource_class:"entity_schema",effects:m}),onSuccess:m=>{n.setQueryData(o,i=>i&&Es(i,m)),n.invalidateQueries({queryKey:o})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to save schema policy")}}),c=ve({mutationFn:()=>ts(s,{resource_class:"entity_schema"}),onSuccess:()=>{n.setQueryData(o,m=>m&&Ts(m)),n.invalidateQueries({queryKey:o})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to reset schema policy")}});if(r.isLoading)return e.jsx(Y,{label:"schema policy",variant:"cards",cards:1});if(r.isError||!r.data)return e.jsx(ns,{label:"schema policy"});const b=$s(r.data),y=b?.effects??me.entity_schema,l=h.isPending||c.isPending,u=(m,i)=>{h.mutate({...b?.effects??me.entity_schema,[m]:i})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:b?"Custom policy":"Workspace defaults"}),b?e.jsxs(C,{type:"button",variant:"outline",size:"sm",disabled:l,onClick:()=>c.mutate(),children:[e.jsx(is,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove custom policy"]}):null]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{title:"Entity types",actions:Os,effects:y,pending:l,onChange:u}),e.jsx(Re,{title:"Relationship types",actions:Ps,effects:y,pending:l,onChange:u})]})]})}function Fe(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Is(s,n,o){const r=s.split("/");return r[1]===n?(r[1]=o,r.join("/")||"/"):`/${o}`}function Ls({section:s}){return s==="policies"?e.jsx(Y,{label:"policies",rows:2}):s==="governance"?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Agent write defaults"}),e.jsx(Y,{label:"agent write defaults",variant:"table",rows:3})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Schema governance"}),e.jsx(Y,{label:"schema governance",rows:3})]})]}):e.jsxs("div",{role:"status","aria-label":"Loading general settings","aria-busy":"true",className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Identity"}),e.jsxs("div",{"aria-hidden":"true",className:"space-y-4",children:[["name","slug"].map(n=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{className:"h-3.5 w-12 rounded-none"}),e.jsx("div",{className:"flex h-9 items-center border border-input bg-background px-3",children:e.jsx(O,{className:"h-4 w-32 rounded-none"})})]},n)),e.jsx(O,{className:"h-3 w-4/5 rounded-none"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Workspace visibility"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose who can browse this workspace and its public pages."})]}),e.jsx("div",{"aria-hidden":"true",className:"grid gap-2 sm:grid-cols-2",children:["private","public"].map(n=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-3",children:[e.jsx(O,{className:"mt-0.5 h-4 w-4 shrink-0 rounded-none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(O,{className:"h-4 w-16 rounded-none"}),e.jsx(O,{className:"h-3 w-full rounded-none"}),e.jsx(O,{className:"h-3 w-2/3 rounded-none"})]})]},n))})]}),e.jsxs("div",{"aria-hidden":"true",className:"flex justify-end gap-2",children:[e.jsx(O,{className:"h-9 w-20 rounded-none"}),e.jsx(O,{className:"h-9 w-28 rounded-none"})]})]})}function Ws({owner:s,section:n="general",connector:o,connection:r,agent:h}){const c=os(),b=ge(),{data:y,error:l}=Le(),{activeOrg:u,urlOrgSlug:m}=rs(),i=(y??[]).find(a=>a.slug===s&&a.is_member)??null,P=i?.id??s,_=cs(P,{name:i?.name??"",slug:i?.slug??"",visibility:i?.visibility??"private"}),[M,J]=_.field("name"),[I,L]=_.field("slug"),[k,W]=_.field("visibility"),[A,V]=ne(P,!!i),[Z,E]=ne(P,!1),[g,S]=ne(P,null),[D,T]=j.useState(!1),[H,X]=j.useState(!1),[U,Q]=ne(P,!1);if(ls(l)&&y===void 0)return e.jsxs(we,{role:"alert",children:[e.jsx(Ae,{children:e.jsx(ze,{children:"Couldn't load organizations"})}),e.jsx(Oe,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again in a moment."})})]});if(y===void 0)return e.jsx(Ls,{section:n});if(!i)return e.jsxs(we,{children:[e.jsx(Ae,{children:e.jsx(ze,{children:"Organization not found"})}),e.jsx(Oe,{children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["You aren't a member of an organization at"," ",e.jsx("span",{className:"font-mono",children:s}),", or it has been deleted."]})})]});if(n==="policies")return e.jsx("div",{className:"space-y-6",children:e.jsxs("section",{id:"policies",className:"scroll-mt-6 space-y-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control connector actions across the organization. Changes to existing rules save automatically."})}),e.jsx(zs,{owner:s,connector:o,connection:r,agent:h},`${s}:${h??""}:${o??""}:${r??""}`)]})});if(n==="governance")return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Agent write defaults"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the defaults agents inherit for entities and agents. Changes save automatically; agents can only tighten them."})]}),e.jsx(_s,{owner:s,variant:"org-floor"})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Schema governance"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control structural changes by agents and connected AI clients. Changes save automatically."})]}),e.jsx(Fs,{owner:s})]})]});const R=a=>{const p=xs(a);if(p.kind==="cross-host"){window.location.assign(p.href);return}c({to:p.to})},w=a=>{if(a==="public"&&i.visibility!=="public"){E(!0);return}W(a),E(!1)},G=async()=>{if(!_.canSubmit)return;const a=M.trim();if(!a){S("Name is required");return}const p=I.trim()||Fe(a);if(!p){S("Slug is required");return}T(!0),S(null);try{const N=a!==i.name||p!==i.slug,$=k!==i.visibility;let x=i.slug;if(N){const z=await le.update({organizationId:i.id,data:{name:a,slug:p}});if(z.error){S(z.error.message||"Failed to update organization");return}x=z.data?.slug??p}$&&(x=(await ps(x,k)).slug),(N||$)&&(_.accept(_.values,{name:a,slug:x,visibility:k}),await b.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization updated"));const B=u?.id===i.id||m===i.slug,ee=x!==i.slug;if(B&&ee){const z=_e(),se=ke();if(z===i.slug&&se){const oe=gs(window.location.pathname,i.slug)||"/",te=`${window.location.protocol}//${x}.${se}${oe}${window.location.search}${window.location.hash}`;window.location.assign(te);return}const ae=Is(window.location.pathname,i.slug,x);c({to:`${ae}${window.location.search}${window.location.hash}`});return}}catch(N){S(N instanceof Error?N.message:"Failed to update organization")}finally{T(!1)}},q=async()=>{X(!0),S(null);try{const a=await le.delete({organizationId:i.id});if(a.error){S(a.error.message||"Failed to delete organization");return}await b.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization deleted");const N=(y??[]).filter(x=>x.is_member).find(x=>x.id!==i.id)??null,$=u?.id===i.id||m===i.slug;if($&&N){await le.setActive({organizationId:N.id}),R(N.slug);return}if($){const x=_e(),B=ke();if(x===i.slug&&B){window.location.assign(`${window.location.protocol}//app.${B}/`);return}c({to:"/"});return}c({to:"/"})}catch(a){S(a instanceof Error?a.message:"Failed to delete organization")}finally{X(!1),Q(!1)}},v=D||H;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Identity"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(je,{htmlFor:"org-name",children:"Name"}),e.jsx(Ne,{id:"org-name",value:M,onChange:a=>{J(a.target.value),A||L(Fe(a.target.value))},placeholder:"e.g. My Team",disabled:v})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(je,{htmlFor:"org-slug",children:"Slug"}),e.jsx(Ne,{id:"org-slug",value:I,onChange:a=>{V(!0),L(a.target.value)},placeholder:"e.g. my-team",disabled:v}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Changing the slug rewrites this workspace's URL. Existing links to"," ",e.jsxs("span",{className:"font-mono",children:["/",i.slug]})," redirect for a grace period."]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Workspace visibility"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose who can browse this workspace and its public pages."})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>w("private"),disabled:v,className:`flex items-start gap-3 rounded-lg border p-3 text-left transition-colors ${k==="private"?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[e.jsx(ds,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Private"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only members can access this workspace."})]})]}),e.jsxs("button",{type:"button",onClick:()=>w("public"),disabled:v,className:`flex items-start gap-3 rounded-lg border p-3 text-left transition-colors ${k==="public"?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[e.jsx(us,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Public"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Anyone can browse public pages for this workspace."})]})]})]}),Z&&e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-sm",children:[e.jsx("p",{className:"text-foreground",children:"Make this workspace public? Catalog-style content may become visible outside the membership."}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(C,{type:"button",size:"sm",onClick:()=>{W("public"),E(!1)},disabled:v,children:"Confirm public"}),e.jsx(C,{type:"button",size:"sm",variant:"ghost",onClick:()=>E(!1),disabled:v,children:"Cancel"})]})]})]}),g&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:g}),e.jsx(ms,{visible:_.hasConflict,onReload:_.reset}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",onClick:()=>void c({to:`/${s}`}),disabled:v,children:"Cancel"}),e.jsxs(C,{onClick:G,disabled:v||!_.canSubmit,children:[D?e.jsx(Ce,{size:"lg",className:"mr-1.5"}):null,D?"Saving...":"Save changes"]})]}),e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:[e.jsx("p",{className:"text-sm font-medium",children:i.is_personal?"Personal workspace":"Delete this organization"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i.is_personal?"Your personal workspace can't be deleted — your devices and personal connections are bound to it.":"Permanently removes the organization and all members' workspace access. This cannot be undone."}),!i.is_personal&&e.jsx("div",{className:"mt-3",children:U?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{variant:"destructive",size:"sm",onClick:q,disabled:v,children:[H?e.jsx(Ce,{className:"mr-1.5"}):null,"Confirm delete"]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>Q(!1),disabled:v,children:"Cancel"})]}):e.jsxs(C,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>Q(!0),disabled:v,children:[e.jsx(hs,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete organization"]})})]})]})}function Bs(){const{owner:s}=Se.useParams(),n=Se.useSearch(),{hash:o}=fs(),r=ys(n,o),h={general:"General",policies:"Policies",governance:"Governance"}[r],{data:c}=Le(),b=(c??[]).find(y=>y.slug===s&&y.is_member)?.name;return e.jsx(bs,{className:"pt-2.5 pb-8",children:e.jsxs(vs,{className:Ns("flex flex-1 flex-col gap-6",Cs(r)),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(js,{className:"h-7 w-7"}),e.jsx("h1",{className:"text-3xl font-semibold leading-tight",children:h})]}),b?e.jsx("p",{className:"text-base font-medium text-foreground",children:b}):null]}),e.jsx(Ws,{owner:s,...n,section:r})]})})}export{Bs as component};
2
- //# sourceMappingURL=organization-B9bh20Xo.js.map
@@ -1,2 +0,0 @@
1
- import{j as e,dB as q,jq as A,jr as H,js as D,jt as V,ju as U,r as f,jv as G,u as T,aB as W,aH as Q,S as b,hW as Y,iW as Z,B as N,jw as J,jx as _,jy as X,d7 as ee,gb as te,o as C,aq as z,cu as B,ab as S,ed as se,v as ne,l as re,fH as ie,w as oe,L as R,jz as ae,fp as ce,fK as de,fD as le,jA as ue,fS as E,iq as me,az as pe,jB as xe,at as he,k as fe,jC as ye,cT as ge,e5 as je,cU as ve,p as Ne,eq as we,jD as be,ec as ke,er as Ae,ex as Ce,a0 as Se,jE as Ie,jF as Pe}from"./index-B-Ab8srM.js";import{u as Le,A as _e}from"./automation-detail-content-BFv1TglZ.js";import{A as Te}from"./agent-loading-shells-DHvKiEUB.js";import{s as $e,h as Re,R as Ee,A as Oe}from"./agent-thread-B1ZepGZc.js";import{C as De,b as ze,A as Be}from"./connection-feed-detail-BLCjhP-H.js";import{O as Fe}from"./connect-menu-Bs8mxsga.js";import{S as Me}from"./source-record-panels-CBV9tsR3.js";import{E as $}from"./events-feed-zFnTSE27.js";import{S as Ke}from"./schema-type-editor-panel-Bdeumkux.js";import{c as qe,s as He,k as Ve}from"./renderer-CgaQKMoG.js";import{E as Ue}from"./event-detail-8xHiplt_.js";import{V as Ge,R as We}from"./views-access-required-BVtMfgLh.js";import{R as Qe,b as Ye}from"./event-card-BtTUuf2q.js";import{V as Ze,a as Je}from"./view-param-filters-DYlqBocg.js";import{S as Xe,g as et}from"./status-variants-DT61YfsU.js";import{b as tt}from"./use-automations-II_YJWtN.js";import"./home-stream-IVsNEkwp.js";import"./list-skeleton-BAqT0vxo.js";import"./clients-6aJvabvS.js";import"./client-activity-scopes-DoIErdUy.js";import"./client-rows-BbVQy5Ti.js";import"./create-automation-form-B12yTrmj.js";import"./entity-options-CGTjLlcS.js";import"./device-automation-Dp3faMvp.js";import"./model-selector-onvGA9Ww.js";import"./skill-editor-D_W3QlRz.js";import"./json-diff-B-1Swv_y.js";import"./index-Vcq4gwWv.js";import"./use-mention-search-Bxlpd6Dp.js";import"./automation-source-list-D8ZSavQU.js";import"./proposal-review-shell-CnACXCUg.js";import"./runs-BMzp7j7j.js";import"./definition-comparison-C3k6Wa9B.js";import"./schema-value-BUgC0Ro8.js";import"./app-bridge-C4nPtae3.js";import"./pending-seed-CoFPQ835.js";import"./runs-list-DVhrTr3v.js";import"./run-initiator-BvruBM5H.js";import"./feed-event-kinds-BYuZCoU4.js";import"./entity-type-page-CjFqxSdL.js";import"./change-summary-CGrKEJ04.js";import"./card-DT9mSjSp.js";import"./table-B6yimlsZ.js";import"./dynamic-schema-form-DyT_9iVE.js";import"./record-session-Bpx4_LGk.js";import"./copy-button-D6zpsZLi.js";import"./agent-list-row-SyACVYX7.js";import"./automation-row-CmTpAD4r.js";import"./filter-editors-Dd5R2Etd.js";function st(t){if(!t||typeof t!="object")return[];const s=t.properties;if(!s)return[];const r=Array.isArray(t.required)?new Set(t.required.map(String)):new Set;return Object.entries(s).map(([n,i])=>({name:n,type:String(i.type??"any"),required:r.has(n),description:typeof i.description=="string"?i.description:void 0}))}function nt({fields:t}){return t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No fields."}):e.jsx("ul",{className:"space-y-2",children:t.map(s=>e.jsxs("li",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("code",{className:"text-xs font-medium text-foreground",children:s.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:s.type}),s.required?e.jsx("span",{className:"text-[10px] font-medium text-amber-600 dark:text-amber-400",children:"required"}):null]}),s.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description}):null]},s.name))})}function I({item:t,hideHeading:s=!1}){const r=t.schemaSections;return r?e.jsxs("article",{className:s?"space-y-4":"space-y-4 px-5 py-5",children:[!s&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(q,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h2",{className:"text-base font-medium text-foreground",children:t.title}),r.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:r.description}):null]})]}),r.sections.map(n=>{const i=st(n.schema);return e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n.title}),n.description?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:n.description}):null]}),e.jsx(nt,{fields:i})]},n.title)})]}):null}function rt({actions:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,action:i}});return e.jsx(A,{entries:s,label:"actions",renderDetail:({name:r,action:n})=>e.jsx(I,{hideHeading:!0,item:{href:"",title:r,schemaSections:D(n)}})})}function it({feeds:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,feed:i}});return e.jsx(A,{entries:s,label:"feed types",renderDetail:({name:r,feed:n})=>e.jsx(I,{hideHeading:!0,item:{href:"",title:r,schemaSections:H(n)}})})}function ot(t){const s=[];return t.forEach((r,n)=>{s.push({id:`sep:${r.runId}`,role:"system",parts:[{type:"text",text:at(r,n)}],createdAt:r.completedAt?new Date(r.completedAt).getTime():void 0});for(const i of r.messages)s.push({...i,id:`r${r.runId}:${i.id}`})}),s}function at(t,s){const r=(t.pendingActionCount??0)>0?`Waiting for you (${t.pendingActionCount})`:t.status==="completed"?"Completed":t.status??"Completed",n=(t.autoAppliedCount??0)>0?` · ${t.autoAppliedCount} applied automatically`:"",i=t.completedAt?new Date(t.completedAt).toLocaleString():null;return i?`Run ${s+1} · ${r}${n} · ${i}`:`Run ${s+1} · ${r}${n}`}const F=Symbol("trusted-automation-interaction");function ct(t){return Object.defineProperty(t,F,{value:!0}),t}function dt(t){return{title:`${t} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${t} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${t} proposals.`},{id:"reject-all",label:"Reject all",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${t} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${t} proposals.`}]}}const lt=new Set(["automation-approval-batch"]);function ut(t){return new Promise(s=>{t({onSettled:(r,n)=>s(!!n)})})}function mt(){const t=V(),s=U();return f.useMemo(()=>({toolNames:lt,resolve:(r,n)=>{if(!n||typeof n!="object"||n[F]!==!0)return null;const i=n;if(r==="automation-approval-batch"){const o=typeof i.runId=="number"&&Number.isSafeInteger(i.runId)&&i.runId>0?i.runId:null,c=typeof i.count=="number"&&Number.isSafeInteger(i.count)&&i.count>1?i.count:null,a=Array.isArray(i.runIds)?i.runIds.filter(d=>typeof d=="number"&&Number.isSafeInteger(d)&&d>0):[];return o===null||c===null||a.length!==c||new Set(a).size!==c?null:{view:dt(c),handlers:{manage_operations:d=>d.action!=="approve"&&d.action!=="reject"?Promise.resolve(!0):ut(p=>d.action==="approve"?t.mutate({run_id:o,run_ids:a},p):s.mutate({run_id:o,run_ids:a},p))}}}return null}}),[t,s])}const pt=/(?:^|\n)Run this Automation now/;function xt(t){return t.role==="user"&&t.parts.some(s=>s.type==="text"&&pt.test(s.text))}function ht(t){return`history-interaction:${t.runId}:${t.eventId??"error"}`}function ft({agentId:t,automationId:s,ownerSlug:r,runId:n}){const{data:i,isLoading:o}=G(t,s,{orgSlug:r,...n!=null?{runId:n}:{}}),c=mt(),a=T(),d=f.useCallback(l=>{a?.open({href:`/${r}/automations/${s}?view=activity&run_id=${l}`,title:`Automation run #${l}`,runId:l})},[a,r,s]),p=f.useMemo(()=>{const l=i?.runs??[],j=(n!=null?l.filter(m=>m.runId===n):l).slice().reverse();return ot(j.map(m=>{const g=m.messages.map(u=>$e(u,{showToolCalls:!0})).filter(u=>u!==null&&!xt(u));m.task?.trim()&&g.unshift({id:"task",role:"user",parts:[{type:"text",text:m.task.trim()}]});const v=m.actions??[],h=v.filter(u=>u.status==="pending");if(h.length>1){const u=h.map(x=>x.runId).sort((x,k)=>x-k);g.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${m.runId}`,toolName:"automation-approval-batch",args:ct({runId:m.runId,count:h.length,runIds:u})}]})}for(const u of v){const x=Re([u],{workspaceSlug:r,agentId:t,webOrigin:typeof window>"u"?null:window.location.origin});x&&g.push({...x,id:ht(u)})}return{runId:m.runId,completedAt:m.completedAt,status:m.status,pendingActionCount:m.pendingActionCount,autoAppliedCount:m.autoAppliedCount,messages:g}}))},[t,i,r,n]);return o?e.jsx(Te,{readOnly:!0}):p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):e.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:e.jsx(Ee,{messages:p,workspaceSlug:r,children:e.jsx(Oe,{readOnly:!0,readerPositionMode:"runs",interactionExtension:c,onRunSelect:n==null&&a?d:void 0})})})}function yt({panel:t}){const s=W(t.organizationId),r=t.section==="connections"||!!t.connectionId,n=Q(t.organizationId,{connectorKey:t.connectorKey,connectionIds:t.connectionId?[t.connectionId]:void 0,enabled:r}),i=s.data?.find(c=>c.key===t.connectorKey),o=n.data?.find(c=>c.id===t.connectionId&&c.connector_key===t.connectorKey);return s.isLoading||r&&n.isLoading?e.jsx("div",{className:"p-5",children:e.jsx(b,{className:"h-28 w-full"})}):s.isError||r&&n.isError?e.jsx("p",{role:"alert",className:"p-5 text-sm",children:"Could not load this connector. Close the pane and try again."}):t.connectionId&&!o||!i&&!o&&t.section!=="connections"?e.jsx("p",{className:"p-5 text-sm",children:"This connection is no longer available."}):e.jsx("div",{className:"p-5",children:t.section==="connections"?e.jsx(Y,{connections:n.data??[],connector:i,connectorKey:t.connectorKey,ownerSlug:t.ownerSlug}):o?e.jsx(vt,{connection:o,connector:i,panel:t}):i?t.section==="oauth-apps"?e.jsx(Fe,{connector:i,organizationId:t.organizationId,newApp:!!t.newApp}):t.section==="feeds"?e.jsx(gt,{connector:i}):i.installed===!1?e.jsx(jt,{connector:i,ownerSlug:t.ownerSlug}):e.jsx(wt,{connector:i,ownerSlug:t.ownerSlug}):null},`${t.connectorKey}:${t.connectionId??"connector"}:${t.section}`)}function gt({connector:t}){return e.jsx(it,{feeds:t.feeds_schema??{}})}function jt({connector:t,ownerSlug:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection."," ",e.jsx(_,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(rt,{actions:t.actions_schema??{}})]})}function vt({connection:t,connector:s,panel:r}){const[n,i]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:n,children:r.section==="feeds"?e.jsx(Nt,{connection:t,connector:s,ownerSlug:r.ownerSlug}):e.jsx(Z,{connection:t,ownerSlug:r.ownerSlug,inPeek:!0,onReviewPermissions:s?()=>i(!0):void 0})}),n&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>i(!1),children:"Back to actions"}),e.jsx("h2",{className:"text-base font-semibold",children:"Provider permissions"}),e.jsx(J,{connection:t,connectorDef:s})]})]})}function Nt({connection:t,connector:s,ownerSlug:r}){const{data:n=[],isLoading:i,isError:o}=ee(t.id),[c,a]=f.useState(!1),d=t.facets?.chat??!1;if(i)return e.jsx(b,{className:"h-28 w-full"});if(o)return e.jsx("p",{role:"alert",children:"Could not load sources. Close the pane and try again."});const p=n.map(l=>({id:String(l.id),name:l.display_name||l.feed_key,status:te(l)??(l.operations.includes("sync")?"Sync enabled":"Live access"),feed:l}));return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:c,children:e.jsx(A,{entries:p,label:d?"channels":"feeds",action:Object.keys(s?.feeds_schema??{}).length>0?e.jsx(N,{size:"sm",variant:"outline",onClick:()=>a(!0),children:d?"Add channel":"Add feed"}):void 0,renderDetail:({feed:l})=>l.store==="channel_messages"?e.jsx(De,{feed:l,hideHeader:!0}):e.jsx(ze,{feed:l,connectorDef:s,ownerSlug:r})})}),c&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold",children:d?"Add channel":"Add feed"}),e.jsx(Be,{organizationId:t.organization_id,connections:[t],connectorDefinitions:[s],onClose:()=>a(!1)})]})]})}function wt({connector:t,ownerSlug:s}){const{data:r=[],isLoading:n,isError:i}=X(t.key);if(n)return e.jsx(b,{className:"h-28 w-full"});if(i)return e.jsx("p",{role:"alert",children:"Could not load actions. Close the pane and try again."});const o=t.actions_schema??{},c=r.map(a=>({id:a.operation_key,name:a.name??a.operation_key,description:a.description,operation:a}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection. Click an action to inspect its inputs."," ",e.jsx(_,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(A,{entries:c,label:"actions",renderControl:()=>e.jsx(_,{ownerSlug:s,connectorKey:t.key}),renderDetail:({operation:a,name:d})=>o[a.operation_key]?e.jsx(I,{hideHeading:!0,item:{href:"",title:d,schemaSections:D(o[a.operation_key])}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No input fields."})})]})}function bt({owner:t,path:s}){const{data:r,isLoading:n}=C(t,{slug:t}),i=r?.workspace,o=i?.type==="organization"?i.id:null,c=o?{slug:t}:void 0,{data:a,isLoading:d}=z(`/${t}/${B(s)}`,c),p=a?.entity,l=p?.id;return n||d?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(S,{className:"mr-2"})," Loading…"]}):o?l==null?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't find this record. It may have been deleted, or it may live in a workspace you can't access."}):p?.is_derived?e.jsx(Me,{record:{type:p.entity_type,key:p.slug},orgContext:c}):e.jsx("div",{className:"px-4 py-4",children:e.jsx($,{organizationId:o,ownerSlug:t,entityId:typeof l=="number"?l:void 0,filters:{sortBy:"date",sortOrder:"desc"},emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to this record yet."})})}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."})}function kt(t){if(Array.isArray(t.enum))return`One of ${t.enum.length}`;if(t.format==="date"||t.format==="date-time")return"Date";if(t.format==="uri")return"Link";if(t.format==="email")return"Email";const s=Array.isArray(t.type)?t.type[0]:t.type;return s==="array"?"List":s==="object"?"Group":s==="integer"||s==="number"?"Number":s==="boolean"?"Yes / no":"Text"}function At({owner:t,typeSlug:s,view:r}){const{data:n,isLoading:i}=C(t,{slug:t}),o=n?.workspace,c=o?.type==="organization"?o.id:null,{isAdmin:a}=se(c??void 0),{orgContext:d}=ne(),{data:p,isSuccess:l}=re(d),y=(p??[]).find(w=>w.slug===s),j=l&&!y,m=`/${t}/${ie(s)}`,{pathname:g}=oe(),v=g===m||g===`${m}/`||g.startsWith(`${m}/-/`),h=f.useMemo(()=>qe(y?.metadata_schema),[y?.metadata_schema]),u=T(),x=u?.close;f.useEffect(()=>{j&&x?.()},[j,x]);const k=f.useMemo(()=>({entityTypes:[s],sortBy:"date",sortOrder:"desc"}),[s]);if(i)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(S,{className:"mr-2"})," Loading…"]});if(j)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This entity type no longer exists."});if(!c)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."});const K=y?.name??s;return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-2.5",children:[v?null:e.jsx(N,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(R,{...ce(t,s),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Browse records"]})}),y&&!v&&!de(y)&&y.entity_count!==0?e.jsx(N,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(R,{to:"/$owner/$entityType/-/$shape",params:{owner:t,entityType:s,shape:"graph"},search:ue(E(t,s)),children:[e.jsx(le,{className:"mr-1.5 h-3.5 w-3.5"}),"Graph"]})}):null,r!=="activity"&&u?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"ml-auto h-8 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>u.open({href:E(t,s,"activity"),title:`${K} activity`}),children:[e.jsx(me,{className:"h-3.5 w-3.5"}),"Activity"]}):null]}),r==="activity"?e.jsx("div",{className:"px-4 py-4",children:e.jsx($,{organizationId:c,ownerSlug:t,filters:k,showEntityLinks:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to these records yet."})})}):a?e.jsx("div",{className:"p-4",children:e.jsx(Ke,{slug:s,onClose:()=>x?.()})}):h.length>0?e.jsxs("section",{"aria-labelledby":"entity-type-peek-fields",className:"px-4 py-4",children:[e.jsx("h3",{id:"entity-type-peek-fields",className:"mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("dl",{className:"divide-y divide-border/60 text-sm",children:h.map(w=>e.jsxs("div",{className:"flex items-baseline justify-between gap-3 py-1.5",title:w.prop.description,children:[e.jsx("dt",{className:"min-w-0 truncate",children:He(w)}),e.jsx("dd",{className:"shrink-0 text-xs text-muted-foreground",children:kt(w.prop)})]},w.key))})]}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This type has no fields yet."})]})}function Ct({owner:t,eventId:s,viewKey:r}){const n=T(),i=(o,c)=>e.jsx(Ue,{owner:c,organizationId:o,eventId:s,viewKey:r,dense:!0,onSelectView:n?a=>n.retarget(a):void 0},`${c}/${s}/${r??""}`);return e.jsx("div",{className:"px-4 py-4",children:t==="me"?i(null,t):e.jsx(pe,{owner:t,children:({organizationId:o,ownerSlug:c})=>o?i(o,c):e.jsx("div",{className:"h-40 animate-pulse rounded-md bg-muted/40"})})})}function P({owner:t,runId:s,runIds:r,contentIds:n}){const{data:i,isLoading:o}=C(t==="me"?null:t,{slug:t}),c=i?.workspace,a=t!=="me"&&c?.type==="organization"?c.id:null,d=f.useMemo(()=>{if(t==="me")return n?.length?{contentIds:n,sortBy:"date",sortOrder:"desc"}:void 0;const l=r??(s!=null?[s]:void 0);if(!(!l?.length&&!n?.length))return{...l?.length?{runIds:l}:{},...n?.length?{contentIds:n}:{}}},[t,n,s,r]),p=d!=null;return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(S,{className:"mr-2"})," Loading…"]}):t!=="me"&&a==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):p?e.jsx("div",{className:"px-4 py-4",children:e.jsx($,{presentation:"detail",organizationId:a,ownerSlug:t,filters:d,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s!=null||r?.length?"No matching events from this run yet.":"No matching events yet."})})}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing to preview."})}const L=25;function St({target:t}){const[s,r]=f.useState(0),{data:n,isLoading:i,isError:o,refetch:c}=xe(t.entityId,t.orgContext,{relationshipType:t.relationshipType,limit:L,offset:s}),a=n?.total;return e.jsxs("div",{className:"space-y-3 px-5 py-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.label," · ",t.entityName,a!==void 0?` · ${a} current ${a===1?"link":"links"}`:n?` · ${n.rows.length} shown`:""]}),e.jsx(Qe,{count:n?.failures?.length??0,onRetry:()=>void c()}),i?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{className:"h-6 w-full"}),e.jsx(b,{className:"h-6 w-full"})]}):o||!n?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load these links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void c(),children:"Retry"})]}):n.rows.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links on this page."}):e.jsx("ul",{className:"divide-y divide-border",children:n.rows.map(d=>e.jsx("li",{className:"flex items-center justify-between gap-3 py-1.5",children:e.jsx(Ye,{row:d,entityId:t.entityId,ownerSlug:t.ownerSlug,orgContext:t.orgContext})},d.id))}),n&&(s>0||n.hasMore)?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(N,{type:"button",variant:"outline",size:"sm",disabled:s===0,onClick:()=>r(Math.max(0,s-L)),children:"Previous"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[n.rows.length," shown",a===void 0?"":` of ${a}`]}),e.jsx(N,{type:"button",variant:"outline",size:"sm",disabled:!n.hasMore,onClick:()=>r(s+L),children:"Next"})]}):null]})}function It({owner:t,path:s,viewKey:r}){const[n,i]=f.useState({}),{data:o,isLoading:c}=C(t,{slug:t}),a=o?.workspace,d=a?.type==="organization"?a.id:null,p=d?{slug:t,organizationId:d}:void 0,{data:l,isLoading:y}=z(`/${t}/${B(s)}`,p),{isMember:j,isPublic:m,isLoading:g}=he(t),v=j||m,h=fe({slug:t,organizationId:j?d:null}),u=l?.entity;if(c||y||g||v&&h.isLoading)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(S,{className:"mr-2"})," Loading…"]});if(!v)return e.jsx(Ge,{});if(h.isError)return e.jsx(Ze,{onRetry:()=>void h.refetch()});const x=u?ye(h.data??[],{type:u.entity_type,id:u.id??u.slug}).find(k=>k.key===r):void 0;return!d||!u||!x?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This view isn't attached to this record any more."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(Je,{orgSlug:t,viewKey:x.key,scope:{type:u.entity_type,entity:u.is_derived?u.slug:u.id??u.slug},params:n,onParamsChange:i,contentHash:x.content_hash,title:x.name,minHeight:320})})}function M({owner:t,runId:s}){const r=ge({queryKey:["run-outcome",t,s],queryFn:async()=>{const i=await ve("manage_operations",{action:"get_run",run_id:s},{slug:t});if(!i.run)throw new Error(i.error||"Run not found");return i.run},enabled:t!=="me",staleTime:15e3,refetchInterval:i=>["pending","claimed","running"].includes(i.state.data?.status??"")?5e3:!1});if(t==="me")return null;if(r.isLoading)return e.jsx("p",{role:"status",className:"px-4 pt-4 text-xs text-muted-foreground",children:"Loading run…"});if(!r.data)return e.jsx("p",{role:"alert",className:"px-4 pt-4 text-sm text-destructive",children:"Could not load this run."});const n=r.data;return e.jsxs("section",{"aria-label":"Run outcome",className:"space-y-2 border-b px-4 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Xe,{status:et(n.status),children:n.status}),e.jsx("time",{dateTime:n.created_at,className:"text-xs text-muted-foreground",children:je(n.created_at)})]}),n.connection_display_name?e.jsx("p",{className:"text-sm",children:n.connection_display_name}):null,n.error_message?e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm text-destructive",children:n.error_message}):null,r.isError?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Could not refresh this run. Showing its last known outcome."}):null]})}function Cs({item:t}){if(t.connectorPanel)return e.jsx(yt,{panel:t.connectorPanel});if(t.schemaSections)return e.jsx(I,{item:t});if(t.recordField)return e.jsx(We,{target:t.recordField});if(t.recordPeer)return e.jsx(Ve,{target:t.recordPeer});if(t.recordLinks)return e.jsx(St,{target:t.recordLinks});if(typeof t.browserUrl=="string"&&t.browserUrl.length>0)return e.jsx(O,{item:t});const s=t.href?Ne(t.href):null;return s?s.kind==="memory"?"runId"in s?e.jsxs(e.Fragment,{children:[e.jsx(M,{owner:s.owner,runId:s.runId}),e.jsx(P,{owner:s.owner,runId:s.runId})]}):"runIds"in s?e.jsx(P,{owner:s.owner,runIds:s.runIds}):e.jsx(P,{owner:s.owner,contentIds:s.contentIds}):s.kind==="entity"?e.jsx(bt,{owner:s.owner,path:s.path}):s.kind==="entity-type"?e.jsx(At,{owner:s.owner,typeSlug:s.typeSlug,view:s.view}):s.kind==="record-view"?e.jsx(It,{owner:s.owner,path:s.path,viewKey:s.viewKey}):s.kind==="event"?e.jsx(Ct,{owner:s.owner,eventId:s.eventId,viewKey:s.viewKey}):t.runId?e.jsx(Pt,{owner:s.owner,automationId:s.automationId,runId:t.runId}):e.jsx(Lt,{owner:s.owner,automationId:s.automationId}):e.jsx(O,{item:t})}function O({item:t}){const s=t.body,r=t.notificationType??"generic",n=t.createdAt,i=t.browserUrl??null,o=t.browserHandoff??null;return e.jsxs("article",{className:"space-y-4 px-5 py-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(we,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:be(r)}),n?e.jsx("span",{children:ke(n)}):null]})]}),s?e.jsx("div",{className:"text-sm leading-6 text-foreground/90",children:e.jsx(Ae,{text:s,linkPolicy:r==="action_approval_needed"?"app-links":"strip"})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No additional details were provided."}),t.owner&&t.sourceAttribution?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground/80",children:"Generated from"}),e.jsx(Ce,{owner:t.owner,source:t.sourceAttribution,className:"text-xs"})]}):null,i?e.jsx("div",{className:"space-y-2",children:o?.state==="expired"?e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:o.error_message??"This draft expired before the page was opened."}):o?.state==="completed"||o?.state==="preparing"?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.state==="preparing"?"Preparing draft — keep your browser tab open.":"Draft prepared — review and post in your browser."}):e.jsxs(N,{type:"button",size:"sm",className:"h-8 text-sm",onClick:()=>{Ie(i)},children:[e.jsx(Se,{className:"mr-1.5 h-3.5 w-3.5"}),"Open post"]})}):null]})}function Pt({owner:t,automationId:s,runId:r}){const{organizationId:n}=Le(t),i=tt(s,void 0,n),o=Pe(i.data?.automation);return o?e.jsx(ft,{agentId:o,automationId:s,ownerSlug:t,runId:r}):i.isLoading?e.jsx(b,{className:"h-24 w-full rounded-lg"}):e.jsx(M,{owner:t,runId:r})}function Lt({owner:t,automationId:s}){return e.jsx("div",{className:"px-4 py-4",children:e.jsx(_e,{owner:t,agentId:null,automationId:s,view:"activity",onDone:()=>{}})})}export{Cs as PeekPaneContent};
2
- //# sourceMappingURL=peek-pane-content-Bqus80Mq.js.map
@@ -1,2 +0,0 @@
1
- import{hs as f,g_ as w,g$ as y,r as C,j as e,W as N,B as d,H as P,eA as k}from"./index-B-Ab8srM.js";import{a as A}from"./runs-BMzp7j7j.js";function _({resource:g,runId:r,children:h,onDone:l}){const c=!!r,{data:a,isLoading:E,isError:u,refetch:v}=A(g,c?r:void 0),s=f({isReview:c,isError:u,status:a?.status}),m=a?.status==="pending"?a.proposal:null,n=w(),i=y(),[p,x]=C.useState(""),o=n.isPending||i.isPending,j=s==="active"||s==="loading"||s==="error",b=()=>{r&&n.mutate({run_id:r},{onSuccess:()=>l?.()})},R=()=>{if(!r)return;const t=p.trim();i.mutate({run_id:r,...t?{reason:t}:{}},{onSuccess:()=>l?.()})};return e.jsxs("div",{className:"grid content-start gap-4",children:[s==="active"?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-3 text-sm text-amber-950 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-100",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(N,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("p",{children:["Review the change the builder agent proposed. Compare Current and Proposed, then ",e.jsx("strong",{children:"Approve"})," to apply, or"," ",e.jsx("strong",{children:"Reject"}),"."]})]})}):null,s==="gone"?e.jsx("div",{className:"rounded-lg border bg-muted/30 p-3 text-sm text-muted-foreground",children:"This change is no longer pending (it may have been approved or rejected already)."}):null,s==="error"?e.jsx("div",{className:"rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"text-destructive",children:"Couldn't load the proposed change to review. Editing is disabled until it loads — retry, or reopen the link."}),e.jsx(d,{type:"button",variant:"outline",size:"sm",onClick:()=>void v(),children:"Retry"})]})}):null,h({reviewMode:s,proposal:m,controlsDisabled:j}),s==="active"?e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(P,{htmlFor:"review-reject-reason",children:"Reason (optional)"}),e.jsx(k,{id:"review-reject-reason",rows:2,value:p,onChange:t=>x(t.target.value),placeholder:"Why you're rejecting — shared back to the requester.",disabled:o})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:justify-end",children:[e.jsx(d,{type:"button",variant:"outline",onClick:R,disabled:o,children:i.isPending?"Rejecting...":"Reject"}),e.jsx(d,{type:"button",onClick:b,disabled:o,children:n.isPending?"Approving...":"Approve"})]})]}):null]})}export{_ as P};
2
- //# sourceMappingURL=proposal-review-shell-CnACXCUg.js.map
@@ -1,2 +0,0 @@
1
- import{r as e,dF as l}from"./index-B-Ab8srM.js";function a(){return e.useEffect(()=>{l()},[]),null}export{a as P};
2
- //# sourceMappingURL=public-shell-ready-Dlh-eWz0.js.map