@lobu/runtime-server 24.9.0 → 24.11.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 (233) hide show
  1. package/dist/catalogs/automations.json +2 -2
  2. package/dist/catalogs/connectors.json +16 -4
  3. package/dist/catalogs/skills.json +1 -1
  4. package/dist/component.json +1 -1
  5. package/dist/connectors/linkedin-inbox-adapter.js +13 -3
  6. package/dist/connectors/postgres.ts +39 -24
  7. package/dist/connectors/whatsapp-web-adapter.js +54 -22
  8. package/dist/connectors/whatsapp-web-helpers.ts +48 -2
  9. package/dist/connectors/whatsapp_web.ts +23 -7
  10. package/dist/connectors/x-dm-adapter.js +17 -3
  11. package/dist/db/migrations/20261112210000_instance_identity.sql +18 -0
  12. package/dist/db/migrations/20261113170000_member_sql_rls.sql +254 -0
  13. package/dist/db/migrations/20261113180000_member_sql_rls_parallel_plans.sql +192 -0
  14. package/dist/db/migrations/20261113190000_member_sql_schema_usage.sql +24 -0
  15. package/dist/db/migrations/20261114120000_events_owner_only_visibility.sql +39 -0
  16. package/dist/dependencies.bun.lock +66 -64
  17. package/dist/embeddings-server.mjs +39 -6
  18. package/dist/guest.bundle.js +1 -1
  19. package/dist/owletto/dist/assets/_-BDMUN9XZ.js +2 -0
  20. package/dist/owletto/dist/assets/_-CF5X4ANe.js +3 -0
  21. package/dist/owletto/dist/assets/{_agentId-bna2tPsW.js → _agentId-CGScf8z_.js} +2 -2
  22. package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +2 -0
  23. package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +2 -0
  24. package/dist/owletto/dist/assets/_connectorKey._connectionId-DcI29kGy.js +2 -0
  25. package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +2 -0
  26. package/dist/owletto/dist/assets/{_conversationId-zcs-S3dY.js → _conversationId-CnmLYlVS.js} +2 -2
  27. package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +2 -0
  28. package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +3 -0
  29. package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +2 -0
  30. package/dist/owletto/dist/assets/_slug-COPpRXLt.js +2 -0
  31. package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +2 -0
  32. package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +2 -0
  33. package/dist/owletto/dist/assets/accept-invitation-BKeIzZXE.js +2 -0
  34. package/dist/owletto/dist/assets/activity-route-location-sLvKaSCa.js +2 -0
  35. package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +2 -0
  36. package/dist/owletto/dist/assets/agent-connect-pages-DVq9nAR7.js +4 -0
  37. package/dist/owletto/dist/assets/{agent-editor-form-Bnc_q5WD.js → agent-editor-form-DVFyyMyd.js} +2 -2
  38. package/dist/owletto/dist/assets/{agent-loading-shells-xteN-pyK.js → agent-loading-shells-BLNHIy-r.js} +2 -2
  39. package/dist/owletto/dist/assets/agent-permissions-matrix-UBKRR5vs.js +2 -0
  40. package/dist/owletto/dist/assets/{agent-skill-context-r0O0BVOu.js → agent-skill-context-fqedKd0D.js} +2 -2
  41. package/dist/owletto/dist/assets/{agent-subpage-shell-C2KpYdu3.js → agent-subpage-shell-BUCoY2Nf.js} +2 -2
  42. package/dist/owletto/dist/assets/{agent-thread-Bv_chdPy.js → agent-thread-Cqf9ITrT.js} +3 -3
  43. package/dist/owletto/dist/assets/app-bridge-B-L0rGz9.js +121 -0
  44. package/dist/owletto/dist/assets/{app._appId-BUcNaSMS.js → app._appId-ByIypCL9.js} +2 -2
  45. package/dist/owletto/dist/assets/{assist-composer-B1LykXpD.js → assist-composer-kG_heHXo.js} +2 -2
  46. package/dist/owletto/dist/assets/automation-run-now-C5XTS00o.js +2 -0
  47. package/dist/owletto/dist/assets/{callback-kSLa4n5s.js → callback-Pz5uS-k7.js} +2 -2
  48. package/dist/owletto/dist/assets/{card-C01y1O-W.js → card-CAPpY9P5.js} +2 -2
  49. package/dist/owletto/dist/assets/{claim-Dnux9Lqf.js → claim-DgWWK0KI.js} +2 -2
  50. package/dist/owletto/dist/assets/{client-activity-scopes-BBIq16tG.js → client-activity-scopes-Aqdo6Pdr.js} +2 -2
  51. package/dist/owletto/dist/assets/{client-rows-DGh1O-Fu.js → client-rows-Dd5YV8vn.js} +2 -2
  52. package/dist/owletto/dist/assets/clients-Bf7ZgGro.js +2 -0
  53. package/dist/owletto/dist/assets/{code-editor-BdRMYojw.js → code-editor-z1Sy_hiX.js} +2 -2
  54. package/dist/owletto/dist/assets/connect-BFNp1y_s.js +2 -0
  55. package/dist/owletto/dist/assets/connect-menu-BWrAhMqO.js +2 -0
  56. package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +2 -0
  57. package/dist/owletto/dist/assets/{connected._clientId-BsDzltNz.js → connected._clientId-CuOeHafK.js} +2 -2
  58. package/dist/owletto/dist/assets/connection-CVeHmDLs.js +2 -0
  59. package/dist/owletto/dist/assets/{connection-feed-detail-CJju0qiw.js → connection-feed-detail-BYo7zdVD.js} +2 -2
  60. package/dist/owletto/dist/assets/connector-page-shell-an3SYLim.js +2 -0
  61. package/dist/owletto/dist/assets/{connector-provenance-B2C2cjBg.js → connector-provenance-mSZCOud-.js} +2 -2
  62. package/dist/owletto/dist/assets/connectors-DBEM9QQz.js +2 -0
  63. package/dist/owletto/dist/assets/consent-1ulwyJ3k.js +2 -0
  64. package/dist/owletto/dist/assets/{copy-button-BhXeXLIm.js → copy-button-Xhh7ZnjO.js} +2 -2
  65. package/dist/owletto/dist/assets/{core.esm-CJUp2aNZ.js → core.esm-Ctg_pXLe.js} +3 -3
  66. package/dist/owletto/dist/assets/create-CGuoqPh8.js +2 -0
  67. package/dist/owletto/dist/assets/create-Ccb5R-S4.js +2 -0
  68. package/dist/owletto/dist/assets/{create-DUlRsFNn.js → create-DmhbacIa.js} +2 -2
  69. package/dist/owletto/dist/assets/{create-automation-form-D141prEG.js → create-automation-form-CD6jSlWL.js} +3 -3
  70. package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +2 -0
  71. package/dist/owletto/dist/assets/{custom-guardrail-edits-DuQ28xv3.js → custom-guardrail-edits-Ce_BwiwD.js} +2 -2
  72. package/dist/owletto/dist/assets/{definition-comparison-BUDNuAN_.js → definition-comparison-D_qP25jR.js} +2 -2
  73. package/dist/owletto/dist/assets/{detail-page-skeleton-BRHaq5Sj.js → detail-page-skeleton-CPAfZLG0.js} +2 -2
  74. package/dist/owletto/dist/assets/device-DDl5XKvt.js +2 -0
  75. package/dist/owletto/dist/assets/{device-pin-tombstone-BIM-ziCH.js → device-pin-tombstone-Dkj7hrBE.js} +2 -2
  76. package/dist/owletto/dist/assets/{device._deviceId-BnPqTgK1.js → device._deviceId-bNhTcops.js} +2 -2
  77. package/dist/owletto/dist/assets/{dynamic-schema-form-OkIZImgp.js → dynamic-schema-form-CRyUchXo.js} +2 -2
  78. package/dist/owletto/dist/assets/{entity-options-CpeX7iiX.js → entity-options-D4t-NAcg.js} +2 -2
  79. package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +2 -0
  80. package/dist/owletto/dist/assets/entity-pages-_nuesgnp.js +2 -0
  81. package/dist/owletto/dist/assets/entity-schema-graph-Cq96SJ3c.js +2 -0
  82. package/dist/owletto/dist/assets/{entity-type-page-MgZ7_0oh.js → entity-type-page-CkCSbkBx.js} +2 -2
  83. package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +2 -0
  84. package/dist/owletto/dist/assets/events-feed-DcKTkJVe.js +2 -0
  85. package/dist/owletto/dist/assets/{filter-editors-DDTwyYt0.js → filter-editors-DGVl9U4D.js} +3 -3
  86. package/dist/owletto/dist/assets/{full-page-spinner-DWo519BU.js → full-page-spinner-CtVlF8GQ.js} +2 -2
  87. package/dist/owletto/dist/assets/{index-BYcFrinP.js → index-BUlkNJzX.js} +2 -2
  88. package/dist/owletto/dist/assets/{index-Cd8jMsz8.js → index-BifR-LE9.js} +2 -2
  89. package/dist/owletto/dist/assets/{index-CdDNNAx2.js → index-BoqrvLHQ.js} +1427 -1427
  90. package/dist/owletto/dist/assets/index-CA9mW_ZM.js +2 -0
  91. package/dist/owletto/dist/assets/index-CH0GzG4i.js +2 -0
  92. package/dist/owletto/dist/assets/{index-DznAbTOF.js → index-CK5GDX4B.js} +2 -2
  93. package/dist/owletto/dist/assets/index-CtI5Eomq.js +2 -0
  94. package/dist/owletto/dist/assets/{index-BW7IFKXC.js → index-DbjbHlDe.js} +2 -2
  95. package/dist/owletto/dist/assets/index-DmtQ0bds.js +2 -0
  96. package/dist/owletto/dist/assets/index-Du_J8hnx.js +2 -0
  97. package/dist/owletto/dist/assets/{index-DmqnKGqW.js → index-DvuJ_S_o.js} +2 -2
  98. package/dist/owletto/dist/assets/index-Pae_f9LM.css +1 -0
  99. package/dist/owletto/dist/assets/{index-D1UCJQl1.js → index-XETZnN7L.js} +2 -2
  100. package/dist/owletto/dist/assets/{json-diff-C-WQqyIf.js → json-diff-OjtREegr.js} +2 -2
  101. package/dist/owletto/dist/assets/{list-skeleton-0B1bTrAK.js → list-skeleton-CH0qQBYk.js} +2 -2
  102. package/dist/owletto/dist/assets/login-DG0b9uSC.js +2 -0
  103. package/dist/owletto/dist/assets/{logout-D474YsYQ.js → logout-DfdgOLoM.js} +2 -2
  104. package/dist/owletto/dist/assets/{member-scope-gate-CH_0jHiM.js → member-scope-gate-Cxg2zGQT.js} +2 -2
  105. package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +74 -0
  106. package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +2 -0
  107. package/dist/owletto/dist/assets/{model-selector-XYmk7Iru.js → model-selector-D2OpDkwH.js} +2 -2
  108. package/dist/owletto/dist/assets/{needs-you-list-Bd4iiiqm.js → needs-you-list-3uMsWcDv.js} +2 -2
  109. package/dist/owletto/dist/assets/new-AdGV6a8R.js +2 -0
  110. package/dist/owletto/dist/assets/new-BdtIhBpo.js +2 -0
  111. package/dist/owletto/dist/assets/new-BjGwX6s6.js +2 -0
  112. package/dist/owletto/dist/assets/{new-CJ6TF3Vc.js → new-D-iMjV74.js} +2 -2
  113. package/dist/owletto/dist/assets/organization-qaIpEiQg.js +2 -0
  114. package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +2 -0
  115. package/dist/owletto/dist/assets/{pending-seed-D7-ld7as.js → pending-seed-BBACroge.js} +2 -2
  116. package/dist/owletto/dist/assets/{proposal-review-shell-BWRJidwb.js → proposal-review-shell-C8ZfIAYn.js} +2 -2
  117. package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +2 -0
  118. package/dist/owletto/dist/assets/{record-session-ClKBr1_C.js → record-session-BrM9cdXu.js} +2 -2
  119. package/dist/owletto/dist/assets/{renderer-DZ0w2k2r.js → renderer-CTKNMcXP.js} +5 -5
  120. package/dist/owletto/dist/assets/reset-password-DKBEneyR.js +2 -0
  121. package/dist/owletto/dist/assets/{run-initiator-B8IRlRd-.js → run-initiator-BKSgI1o0.js} +2 -2
  122. package/dist/owletto/dist/assets/runs-k2NpbZm8.js +2 -0
  123. package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +2 -0
  124. package/dist/owletto/dist/assets/{schema-value-k19Ata7u.js → schema-value-wjqGxXhv.js} +3 -3
  125. package/dist/owletto/dist/assets/{scoped-feed-bar-L7h-Ca4u.js → scoped-feed-bar-DNFL0sYX.js} +2 -2
  126. package/dist/owletto/dist/assets/{settings-BZqntV3E.js → settings-V0m5Om5j.js} +2 -2
  127. package/dist/owletto/dist/assets/source-record-panels-BMut9YIA.js +2 -0
  128. package/dist/owletto/dist/assets/{status-variants-BR_iGWN5.js → status-variants-SzXYYedJ.js} +2 -2
  129. package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +2 -0
  130. package/dist/owletto/dist/assets/{table-C3DMoL4K.js → table-ZuYMOjVR.js} +2 -2
  131. package/dist/owletto/dist/assets/use-automations-DfBtVzGa.js +2 -0
  132. package/dist/owletto/dist/assets/use-login-redirect-BDiS3eyl.js +2 -0
  133. package/dist/owletto/dist/assets/{use-mention-search-CtbixPEE.js → use-mention-search-khySpz_V.js} +2 -2
  134. package/dist/owletto/dist/assets/view-card-DiHWlypr.js +2 -0
  135. package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +2 -0
  136. package/dist/owletto/dist/assets/{views-access-required-CvIIxdS_.js → views-access-required-HA-PiOwA.js} +2 -2
  137. package/dist/owletto/dist/index.html +2 -2
  138. package/dist/server-main.bundle.mjs +3778 -2326
  139. package/npm-shrinkwrap.json +251 -234
  140. package/package.json +1 -1
  141. package/vendor/connector-sdk/dist/connector-types.d.ts +6 -0
  142. package/vendor/connector-sdk/dist/index.d.ts +1 -0
  143. package/vendor/connector-sdk/dist/index.js +1 -0
  144. package/vendor/connector-sdk/dist/ip-reachability.d.ts +1 -1
  145. package/vendor/connector-sdk/dist/ip-reachability.js +1 -1
  146. package/vendor/connector-sdk/dist/logger.d.ts +1 -1
  147. package/vendor/connector-sdk/dist/logger.js +1 -1
  148. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +3 -1
  149. package/vendor/connector-sdk/dist/retry.d.ts +1 -1
  150. package/vendor/connector-sdk/dist/retry.js +1 -1
  151. package/vendor/connector-sdk/dist/source-withheld-error.d.ts +16 -0
  152. package/vendor/connector-sdk/dist/source-withheld-error.js +19 -0
  153. package/vendor/connector-sdk/package.json +1 -1
  154. package/vendor/core/dist/classify-error.d.ts +1 -1
  155. package/vendor/core/dist/classify-error.js +2 -2
  156. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +28 -3
  157. package/vendor/core/dist/contracts/tools/manage-automations.js +27 -8
  158. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +8 -0
  159. package/vendor/core/dist/contracts/tools/manage-entity.js +11 -3
  160. package/vendor/core/dist/contracts/tools/save-memory.d.ts +11 -1
  161. package/vendor/core/dist/contracts/tools/save-memory.js +25 -3
  162. package/vendor/core/dist/contracts/tools/search-memory.js +1 -1
  163. package/vendor/core/dist/credentials.d.ts +12 -0
  164. package/vendor/core/dist/credentials.js +1 -0
  165. package/vendor/core/dist/errors.js +2 -2
  166. package/vendor/core/dist/worker/auth.d.ts +5 -0
  167. package/vendor/core/dist/worker/auth.js +15 -4
  168. package/vendor/core/package.json +1 -1
  169. package/vendor/postgres/cf/src/connection.js +7 -2
  170. package/vendor/postgres/cjs/src/connection.js +7 -2
  171. package/vendor/postgres/src/connection.js +7 -2
  172. package/vendor/views/dist/native.d.ts +33 -1
  173. package/vendor/views/dist/native.js +3 -0
  174. package/vendor/views/package.json +1 -1
  175. package/dist/owletto/dist/assets/_-B2C9B2RM.js +0 -2
  176. package/dist/owletto/dist/assets/_-CjyiGzwB.js +0 -3
  177. package/dist/owletto/dist/assets/_agentId-DKHXGvS2.js +0 -2
  178. package/dist/owletto/dist/assets/_automationId-CowRFD4E.js +0 -2
  179. package/dist/owletto/dist/assets/_connectorKey._connectionId-dE6im18z.js +0 -2
  180. package/dist/owletto/dist/assets/_connectorKey.index-DqwSv8Zs.js +0 -2
  181. package/dist/owletto/dist/assets/_eventId-BVOVizs4.js +0 -2
  182. package/dist/owletto/dist/assets/_owner-DsvIC94q.js +0 -3
  183. package/dist/owletto/dist/assets/_shape-CWjpzcvv.js +0 -2
  184. package/dist/owletto/dist/assets/_slug-DuCxYsJk.js +0 -2
  185. package/dist/owletto/dist/assets/_viewKey-BqVeHB6Z.js +0 -2
  186. package/dist/owletto/dist/assets/_viewKey-DzyOCG5U.js +0 -2
  187. package/dist/owletto/dist/assets/accept-invitation-k1u3zBcn.js +0 -2
  188. package/dist/owletto/dist/assets/activity-route-view-jTBMW7a9.js +0 -2
  189. package/dist/owletto/dist/assets/agent-connect-pages-D3mVM_q4.js +0 -4
  190. package/dist/owletto/dist/assets/agent-permissions-matrix-C_ayr0pd.js +0 -2
  191. package/dist/owletto/dist/assets/app-bridge-C4nPtae3.js +0 -121
  192. package/dist/owletto/dist/assets/automation-run-now-CjkJIkaZ.js +0 -2
  193. package/dist/owletto/dist/assets/clients-BCvjAJDT.js +0 -2
  194. package/dist/owletto/dist/assets/connect-DZeFSGIH.js +0 -2
  195. package/dist/owletto/dist/assets/connect-menu-D4w-JhJW.js +0 -2
  196. package/dist/owletto/dist/assets/connect._clientId-IZEMQJ64.js +0 -2
  197. package/dist/owletto/dist/assets/connection-C7glVpPE.js +0 -2
  198. package/dist/owletto/dist/assets/connector-page-shell-BeuyjiB2.js +0 -2
  199. package/dist/owletto/dist/assets/connectors-DSQ5AWPf.js +0 -2
  200. package/dist/owletto/dist/assets/consent-B6Aw_89N.js +0 -2
  201. package/dist/owletto/dist/assets/create-CWcza8NT.js +0 -2
  202. package/dist/owletto/dist/assets/create-bGOYifof.js +0 -2
  203. package/dist/owletto/dist/assets/create._connectorKey-Ds4tpwHP.js +0 -2
  204. package/dist/owletto/dist/assets/device-D3fzoIrM.js +0 -2
  205. package/dist/owletto/dist/assets/entity-page-Cjc8oXA2.js +0 -2
  206. package/dist/owletto/dist/assets/entity-pages-18xSANrS.js +0 -2
  207. package/dist/owletto/dist/assets/entity-schema-graph-uwZ-P0t8.js +0 -2
  208. package/dist/owletto/dist/assets/event-detail-D6AH6a2C.js +0 -2
  209. package/dist/owletto/dist/assets/events-feed-BI7wNRUY.js +0 -2
  210. package/dist/owletto/dist/assets/index-9tTjJo_J.css +0 -1
  211. package/dist/owletto/dist/assets/index-BhJsTy-C.js +0 -2
  212. package/dist/owletto/dist/assets/index-CEcsgXDj.js +0 -2
  213. package/dist/owletto/dist/assets/index-CPscKk2u.js +0 -2
  214. package/dist/owletto/dist/assets/index-CfJ2-EpK.js +0 -2
  215. package/dist/owletto/dist/assets/index-D5DM4g2w.js +0 -2
  216. package/dist/owletto/dist/assets/login-CH7P2AyR.js +0 -2
  217. package/dist/owletto/dist/assets/memory-browse-page-Ba4aYavw.js +0 -74
  218. package/dist/owletto/dist/assets/new-BOsrRqp8.js +0 -2
  219. package/dist/owletto/dist/assets/new-DGPOjak2.js +0 -2
  220. package/dist/owletto/dist/assets/new-Q0XqiZq2.js +0 -2
  221. package/dist/owletto/dist/assets/organization-hD_Z6TSd.js +0 -2
  222. package/dist/owletto/dist/assets/peek-pane-content-Cc8YX1oy.js +0 -2
  223. package/dist/owletto/dist/assets/public-shell-ready-CRyAZATw.js +0 -2
  224. package/dist/owletto/dist/assets/record-activity-9ux6SfCd.js +0 -2
  225. package/dist/owletto/dist/assets/reset-password-D2RfrEVZ.js +0 -2
  226. package/dist/owletto/dist/assets/runs-CuC7WMtd.js +0 -2
  227. package/dist/owletto/dist/assets/runs-list-8gUPWjP4.js +0 -2
  228. package/dist/owletto/dist/assets/source-record-panels-C4UItfdk.js +0 -2
  229. package/dist/owletto/dist/assets/subDays-hOwerOLo.js +0 -2
  230. package/dist/owletto/dist/assets/use-automations-CdtiVLCv.js +0 -2
  231. package/dist/owletto/dist/assets/use-login-redirect-CYlVkAhE.js +0 -2
  232. package/dist/owletto/dist/assets/view-param-filters-BdN8OU35.js +0 -2
  233. /package/vendor/postgres/{.bun-tag-c81dacd34e959a7a → .bun-tag-652f2580b8090d71} +0 -0
@@ -1,2 +0,0 @@
1
- import{c as Ne,ad as Ce,z as Se,ae as Ee,M as Le,r as s,af as Ue,ag as Fe,ah as ae,j as e,ai as b,aj as ce,ak as q,al as Pe,am as Me,an as Ie,aa as ze,$ as Ae,ab as Re,ao as oe}from"./index-CdDNNAx2.js";import{s as $e}from"./index-Cd8jMsz8.js";import{C as qe,c as Be}from"./card-C01y1O-W.js";function B(l){if(!l||typeof l!="object")return null;const f=l.error;if(typeof f=="string")return f;if(f&&typeof f=="object"){const y=f.message;if(typeof y=="string"&&y.length>0)return y}const m=l.message;return typeof m=="string"&&m.length>0?m:null}async function le(l,f){if(typeof window>"u")return;const m=window.PasswordCredential;if(!(!m||!navigator.credentials?.store))try{const y=new m({id:l,password:f});await navigator.credentials.store(y)}catch{}}function Oe({domain:l}){const[f,m]=s.useState(!1);return!(l.length>0&&l.length<=253&&/^[A-Za-z0-9.-]+$/.test(l))||f?e.jsx(ce,{className:"w-4 h-4"}):e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${encodeURIComponent(l)}&sz=32`,alt:"",width:16,height:16,className:"h-4 w-4",onError:()=>m(!0)})}function E(l){return l?l.toLowerCase().replaceAll("_"," ").trim().includes("account not linked")?"This social account matches an existing Lobu user. Sign in with a magic link to verify ownership, then continue.":l:null}function He(){const l=Ne(),f=Ce(),{session:m,isReady:y}=Se(),{data:a,isLoading:U,error:O}=Ee(),i=Le({from:"/auth/login"}),de=i.invitationOrg,[p,j]=s.useState("social"),[d,P]=s.useState(i.intent??"sign-in"),[T,ue]=s.useState(""),[o,W]=s.useState(()=>i.loginHint??""),[k,me]=s.useState(""),[N,ge]=s.useState(""),[M,V]=s.useState(""),[fe,J]=s.useState(!1),[c,u]=s.useState(null),[I,r]=s.useState(null),[Q,G]=s.useState(!1),[pe,K]=s.useState(!1),[Z,he]=s.useState(!1),X=s.useRef(!1),L=i.callbackUrl?Ue(i.callbackUrl):void 0,z=Fe(de,i.loginHint),Y=i.mode==="extension",D=i.error==="account_not_linked",ee=E(i.errorDescription||i.error),A=Object.values(a?.social??{}).some(Boolean),w=!!a?.magicLink,R=!!a?.phone,h=!!a?.emailPassword,te=!!a?.passkey,x=!!a?.singleUserMode,ne=!!a?.hasUser,H=x,F=p==="magic-link"&&w&&Q,v=s.useMemo(()=>{const t=[];return h&&t.push("email-password"),A&&t.push("social"),w&&t.push("magic-link"),R&&t.push("whatsapp"),t},[h,w,A,R]),xe=s.useMemo(()=>h?v.filter(t=>t!=="magic-link"&&t!=="social"):v,[v,h]),_=O instanceof Error?O.message:O?"Unable to load sign-in options.":null;s.useEffect(()=>{if(m){const t=ae(L);L?window.location.href=t:l({to:"/"})}},[m,l,L]),s.useEffect(()=>{!a||v.length===0||v.includes(p)||j(v[0])},[a,p,v]),s.useEffect(()=>{!w||!D||(j("magic-link"),i.loginHint&&!o&&W(i.loginHint))},[w,D,i.loginHint,o]),s.useEffect(()=>{i.intent&&P(i.intent)},[i.intent]),s.useEffect(()=>{if(!x||!a)return;const t=ne?"sign-in":"sign-up";d!==t&&P(t)},[x,ne,a,d]);const C=()=>L?ae(L):"/",se=async(t,{quiet:n=!1}={})=>{u(t),r(null);try{const g=await q.social({provider:t,callbackURL:C(),newUserCallbackURL:L?C():`/?onboard_provider=${encodeURIComponent(t)}`}),S=B(g);if(S&&!n){const $=E(S);$?.toLowerCase().includes("magic link")&&j("magic-link"),r($)}}catch(g){if(n)return;r(E(g instanceof Error?g.message:`Failed to sign in with ${t}`))}finally{u(null)}};s.useEffect(()=>{if(X.current||!y||m||U||!a||i.error)return;const t=i.provider;if(!t)return;X.current=!0;const n=Object.hasOwn(a.social??{},t)&&!!a.social?.[t];se(t,{quiet:!n})},[a,U,m,y,i.provider,i.error]);const re=async()=>{if(o){u("magic-link"),r(null);try{return await q.magicLink({email:o,callbackURL:C()}),G(!0),!0}catch(t){return r(t instanceof Error?t.message:"Failed to send magic link"),!1}finally{u(null)}}},be=async t=>{t.preventDefault(),await re()},ye=async t=>{if(t.preventDefault(),!(!o||!k)){u("email-password"),r(null);try{if(d==="sign-up"){const n=await Me.email({email:o,password:k,name:T||o.split("@")[0]||"User",callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(await le(o,k),await f.invalidateQueries({queryKey:["organizations"]}),x&&te)try{await Ie.passkey.addPasskey({name:T||`${navigator.platform||"This device"}`})}catch{}}else{const n=await q.email({email:o,password:k,callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(!n?.data){r("Invalid email or password");return}await le(o,k)}}catch(n){const g=n instanceof Error?n.message:typeof n=="string"?n:B(n);r(g||"Authentication failed")}finally{u(null)}}},ie=async()=>{r(null),he(!0),u("local");try{const t=await Pe();if(!t.ok){const n=await t.json().catch(()=>null);r(n?.error_description??"Could not sign in to your local install.");return}window.location.href=C()}catch(t){r(t instanceof Error?t.message:"Could not sign in to your local install.")}finally{u(null)}};s.useEffect(()=>{H&&a&&!m&&!Z&&ie()},[H,a,m,Z]);const je=async()=>{if(!o){r("Enter your email address first to reset your password.");return}u("reset-password-request"),r(null);try{const t=`${window.location.origin}/auth/reset-password`,n=await ze(`${Ae}/api/auth/request-password-reset`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:o,redirectTo:t})});if(!n.ok)throw await Re(n);K(!0)}catch(t){r(t instanceof Error?t.message:"Failed to send password reset email")}finally{u(null)}},we=async t=>{if(t.preventDefault(),!!N){u("phone"),r(null);try{await oe.sendOtp({phoneNumber:N}),J(!0)}catch(n){r(n instanceof Error?n.message:"Failed to send verification code")}finally{u(null)}}},ve=async t=>{if(t.preventDefault(),!(!N||!M)){u("verify"),r(null);try{await oe.verify({phoneNumber:N,code:M})}catch(n){r(n instanceof Error?n.message:"Invalid verification code"),u(null)}}};return e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-md p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("img",{src:"/lobu-logo.svg",alt:"Lobu",className:"mx-auto mb-6 h-8 w-auto"}),e.jsx("h1",{className:"text-2xl font-bold",children:z?z.title:x&&d==="sign-up"?"Set up your local install":x?"Welcome back":d==="sign-up"?"Create your account":"Sign in"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:z?z.detail:x&&d==="sign-up"?"This account stays on this machine. Email is just an identifier — pick anything you’ll remember.":x?"Sign in to your local install.":Y?"Sign in to connect the browser extension":d==="sign-up"?"Choose a sign-up method":"Choose your preferred sign-in method"}),x&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-muted text-muted-foreground rounded-full text-xs",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),"Local install · nothing sent to lobu.ai"]}),Y&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-primary/10 text-primary rounded-full text-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})}),"Browser Extension"]})]}),e.jsx(qe,{children:e.jsx(Be,{children:H?e.jsx("div",{className:"space-y-4",children:I?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:I}),e.jsx("button",{type:"button",disabled:c!==null,onClick:ie,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:"Try again"})]}):e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Signing you into your local install…"})]})}):e.jsxs(e.Fragment,{children:[U&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Loading sign-in options…"})]}),!U&&_&&e.jsxs("div",{className:"text-sm text-destructive",children:["Failed to load sign-in options. ",_]}),!U&&!_&&v.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"No sign-in methods are configured. Contact support for access."}),h&&!F&&e.jsxs("div",{className:"mb-4 flex rounded-lg border p-1",children:[e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-in"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-in"),children:"Sign In"}),e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-up"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-up"),children:"Sign Up"})]}),!F&&xe.length>1&&e.jsxs("div",{className:"mb-6 flex rounded-lg border p-1",children:[h&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="email-password"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("email-password"),children:"Email + Password"}),A&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="social"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("social"),children:"Social"}),!h&&w&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="magic-link"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("magic-link"),children:"Magic Link"}),R&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="whatsapp"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("whatsapp"),children:"WhatsApp"})]}),D&&e.jsx("div",{className:"mb-4 rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900",children:"We found an existing account for this identity. To protect the account, verify with a magic link before linking social sign-in."}),ee&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:ee}),I&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:I}),!F&&(h||p==="social")&&A&&e.jsxs("div",{className:"space-y-3",children:[Object.entries(a?.social??{}).filter(([,t])=>t).map(([t])=>{const n=$e.find(ke=>ke.provider===t),g=n?.icon,S=a?.socialMeta?.[t],$=n?.name??S?.name??t.charAt(0).toUpperCase()+t.slice(1);return e.jsxs("button",{type:"button",onClick:()=>se(t),disabled:c!==null,className:"w-full flex items-center justify-center gap-3 h-10 px-4 border border-input rounded-lg bg-background hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-50",children:[c===t?e.jsx(b,{size:"lg"}):g?e.jsx(g,{className:"w-4 h-4"}):S?.faviconDomain?e.jsx(Oe,{domain:S.faviconDomain},S.faviconDomain):e.jsx(ce,{className:"w-4 h-4"}),"Continue with ",$]},t)}),h&&e.jsxs("div",{className:"relative my-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"or"})})]})]}),!F&&h&&e.jsxs("form",{onSubmit:ye,className:"space-y-4",children:[d==="sign-up"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"full-name",className:"block text-sm font-medium",children:"Full name"}),e.jsx("input",{id:"full-name",type:"text",value:T,onChange:t=>ue(t.target.value),placeholder:"Jane Doe",className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email-password-email",type:"email",value:o,onChange:t=>{W(t.target.value),K(!1)},placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-password",className:"block text-sm font-medium",children:"Password"}),e.jsx("input",{id:"email-password-password",type:"password",value:k,onChange:t=>me(t.target.value),placeholder:"Enter a password",required:!0,minLength:8,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o||!k,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="email-password"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:d==="sign-up"?"Creating account...":"Signing in..."})]}):d==="sign-up"?x?"Create local account":"Create Account":"Sign In"}),d==="sign-in"&&te&&e.jsx("button",{type:"button",disabled:c!==null,onClick:async()=>{r(null),u("passkey");try{const t=await q.passkey();if(t?.error){const n=t.error.message??"Passkey sign-in failed.";r(E(n)??n);return}window.location.href=C()}catch(t){const n=t instanceof Error?t.message:String(t);r(E(n)??n)}finally{u(null)}},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="passkey"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Waiting for passkey…"})]}):"Sign in with passkey"}),d==="sign-in"&&w&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:async()=>{await re()&&j("magic-link")},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending magic link..."})]}):"Send me a magic link instead"}),d==="sign-in"&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:je,className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="reset-password-request"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending reset email..."})]}):"Forgot password?"}),d==="sign-in"&&pe&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"If this email exists, we sent a password reset link."})]}),p==="magic-link"&&w&&(Q?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx("svg",{className:"h-12 w-12 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}),e.jsx("h2",{className:"text-lg font-medium",children:"Check your email"}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["We sent a magic link to ",e.jsx("strong",{children:o}),".",e.jsx("br",{}),"Click the link in the email to sign in."]}),e.jsx("button",{type:"button",className:"mt-4 text-sm text-primary hover:underline",onClick:()=>G(!1),children:"Use a different email"})]}):e.jsxs("form",{onSubmit:be,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email",type:"email",value:o,onChange:t=>W(t.target.value),placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Magic Link"})]})),!F&&p==="whatsapp"&&R&&(fe?e.jsxs("form",{onSubmit:ve,className:"space-y-4",children:[e.jsxs("div",{className:"text-center text-sm text-muted-foreground",children:["Enter the 6-digit code sent to ",e.jsx("strong",{children:N})]}),e.jsx("div",{children:e.jsx("input",{type:"text",value:M,onChange:t=>V(t.target.value),placeholder:"000000",maxLength:6,pattern:"[0-9]{6}",required:!0,className:"block h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-xl tracking-widest placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})}),e.jsx("button",{type:"submit",disabled:c!==null||M.length!==6,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="verify"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Verifying..."})]}):"Verify & Sign In"}),e.jsx("button",{type:"button",className:"w-full text-sm text-primary hover:underline",onClick:()=>{J(!1),V("")},children:"Use a different number"})]}):e.jsxs("form",{onSubmit:we,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"phone",className:"block text-sm font-medium",children:"WhatsApp Number"}),e.jsx("input",{id:"phone",type:"tel",value:N,onChange:t=>ge(t.target.value),placeholder:"+1234567890",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Include country code (e.g., +1 for US)"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!N,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="phone"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Code via WhatsApp"})]}))]})})})]})})}export{He as component};
2
- //# sourceMappingURL=login-CH7P2AyR.js.map
@@ -1,74 +0,0 @@
1
- import{eI as Tt,c6 as Is,c7 as As,g2 as Ps,g3 as Fs,j as s,dy as Ds,cb as Vs,T as Ve,U as se,bT as Bs,B as R,bz as It,g4 as At,g5 as te,g6 as je,g7 as qs,g8 as Us,g9 as Qe,ga as Hs,gb as Ue,gc as He,gd as zs,ge as Gs,gf as Js,dA as Pt,dM as Ne,r as x,dc as Ws,ez as Ys,bR as Qs,eF as Ks,G as Ee,x as Ft,cD as Xs,g0 as Zs,c as ne,u as Dt,fg as en,c2 as tn,bd as Vt,db as Bt,fI as sn,f_ as nn,f0 as an,a2 as ze,i as ie,dP as qt,gg as rn,L as ke,e8 as on,d2 as ln,aF as Ut,aG as Ht,dj as zt,aI as Gt,aJ as cn,aK as dn,aL as un,aM as mn,aN as wt,aR as pn,cY as fn,aP as hn,cT as Jt,a4 as gn,gh as Wt,gi as Yt,ax as yn,gj as xn,M as Qt,z as bn,gk as vn,cl as K,w as Kt,gl as Be,cN as jn,gm as Nn,gn as Sn,dW as Et,go as qe,gp as Cn,gq as wn,da as En,cU as kn,cJ as _n,cK as $n,cj as Ge,dI as Rn,gr as Ln,gs as Je,gt as Mn,gu as On,gv as Tn,bp as In,gw as An,gx as Pn,gy as Fn,a as Dn,gz as Vn,gA as Bn,gB as qn,gC as Un,cS as Hn,ar as zn,aT as Gn}from"./index-CdDNNAx2.js";import{P as Jn}from"./public-shell-ready-CRyAZATw.js";import{D as Wn,c as Yn}from"./dynamic-schema-form-OkIZImgp.js";import{S as Qn,E as Xt,a as Kn,e as Xn,b as Zn,c as ea}from"./entity-pages-18xSANrS.js";import{b as ta,F as sa}from"./filter-editors-DDTwyYt0.js";import{l as na,H as aa,n as ra,G as Zt,c as oa}from"./entity-schema-graph-uwZ-P0t8.js";import{l as ia,p as _e,e as es,a as la,S as ca,J as da}from"./renderer-DZ0w2k2r.js";import{u as ua,a as ma,D as pa,P as fa,b as ts,c as ha,C as ga}from"./core.esm-CJUp2aNZ.js";import{v as ya,V as ss,M as ns,a as as,w as xa,b as ba}from"./view-param-filters-BdN8OU35.js";import{M as va}from"./member-scope-gate-CH_0jHiM.js";function ja({onClose:e,entityTypeSlug:t,orgContext:r,onSuccess:l}){const{data:n,isLoading:d}=Tt(t,r),i=`${r.organizationId??r.slug}:${t}`,a=Is(i,{name:"",customSlug:"",useCustomSlug:!1,metadata:{}},n?.metadata_schema),[u,o]=a.field("name"),[c,m]=a.field("customSlug"),[p,f]=a.field("useCustomSlug"),[y,N]=a.field("metadata"),[v,w]=As(i,null),b=Ps(),C=p?c:Fs(u),j=async L=>{if(L.preventDefault(),!a.canSubmit)return;if(w(null),!u.trim()){w("Name is required");return}const O=Yn(y),X={entityType:t,name:u.trim(),slug:p?c:void 0,metadata:Object.keys(O).length>0?O:void 0};try{const $=await b.mutateAsync(X);if(e(),$.approval_queued||!$.entity){It.info("Create queued for approval");return}typeof $.entity.id=="number"&&l?.($.entity.id)}catch($){w($ instanceof Error?$.message:"Failed to create entity")}},S=n?.name||t,g=a.revision,E=`Create ${S}`,k=`Add a new ${S.toLowerCase()} to your workspace.`;return d?s.jsx(Ds,{rows:6}):s.jsxs("form",{onSubmit:j,children:[s.jsx(Vs,{visible:a.hasConflict,onReload:a.reset}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:E}),s.jsx("p",{className:"text-sm text-muted-foreground",children:k})]}),s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsxs(Ve,{htmlFor:"name",children:["Name ",s.jsx("span",{className:"text-destructive",children:"*"})]}),s.jsx(se,{id:"name",value:u,onChange:L=>o(L.target.value),placeholder:`Enter ${S.toLowerCase()} name`,autoFocus:!0})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Ve,{htmlFor:"slug",children:"URL Slug"}),s.jsx("button",{type:"button",onClick:()=>f(!p),className:"text-xs text-muted-foreground hover:text-foreground",children:p?"Auto-generate":"Customize"})]}),p?s.jsx(se,{id:"slug",value:c,onChange:L=>m(L.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"custom-slug"}):s.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm text-muted-foreground",children:C||"slug-preview"})]}),g&&Object.keys(g).length>0?s.jsxs(s.Fragment,{children:[s.jsx(Qn,{className:"my-2"}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(Ve,{className:"text-sm font-medium",children:"Additional Fields"}),s.jsx(Wn,{schema:a.revision,values:y,onValuesChange:N,orgContext:r})]})]}):null,v&&s.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:v})]}),s.jsx(Bs,{onCancel:e,cancelDisabled:b.isPending,className:"mt-2",children:s.jsx(R,{type:"submit",disabled:!a.canSubmit||b.isPending||!u.trim(),children:b.isPending?"Creating...":`Create ${S}`})})]})}function Na(e){const t=e?.properties??{},r=zs(e);return Object.entries(t).flatMap(([l,n])=>{const d=r.find(m=>m.field===l);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(l)||!n||n.const!==void 0||n["x-table-column"]!==!0&&n["x-facet"]!==!0&&!d)return[];const i=[n,...Array.isArray(n.anyOf)?n.anyOf:[]],a=d?.options??Gs(n),u=a.find(m=>m.value!==null)?.value,o=i.find(m=>["string","number","integer","boolean"].includes(String(m.type)))??(u===void 0?void 0:{type:typeof u});if(!o)return[];const c=n.format==="date-time"||o.format==="date-time"?"datetime-local":n.format==="date"||o.format==="date"?"date":o.type==="number"||o.type==="integer"?"number":o.type==="boolean"?"boolean":"string";return[{field:l,label:String(n["x-table-label"]??n.title??l.replaceAll("_"," ")),type:c,options:c==="boolean"&&!a.some(m=>typeof m.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...a]:a}]})}const kt={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function Sa(e,t){return e.value===null&&e.op==="neq"?{op:kt.eq,value:"set"}:{op:kt[e.op],value:t?.options.find(r=>r.value===e.value)?.label??String(e.value)}}function Ca(e){const t=e?.[He];return t===void 0?{}:Qe(t)}function wa(e,t){return(e.presets??[]).filter(r=>!r.viewer||!!t?.email)}function Ea(e,t,r,l){try{const n=Ca(t),d=wa(n,l),i=e[At],a=i===void 0?void 0:d.find(p=>p.key===i);if(i!==void 0&&!a)throw new Error("This saved filter is unavailable. Choose another filter.");if(a&&!r&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const u=a&&e[te]===void 0?{collection:je(a,void 0,l)}:qs(e,r);if(u.error)throw u.error;const o=e[Us],c=o===void 0?a?.table??n.table??{}:Qe({table:typeof o=="string"?JSON.parse(o):o}).table??{},m=!!a&&(_t(u.collection)!==_t(je(a,void 0,l))||Se(c)!==Se(a.table??n.table??{}));return{...u,presentation:n,presets:d,preset:a,table:c,edited:m}}catch(n){return{collection:{},presentation:{},presets:[],table:{},edited:!1,error:n instanceof Error?n:new Error("Invalid collection configuration")}}}function _t(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(Q)])}function Q(e){return JSON.stringify([e.field,e.op,e.value])}function Se(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function ka(e,t){return t?{[At]:t,[te]:Ue(e)[te]??"{}"}:Ue(e)}function _a(e,t,r,l,n=new Date,d){let i=t.filters??[],a=e.viewer;if(a){const o=d?.email?Q({field:a.field,op:"eq",value:d.email.toLowerCase()}):void 0;o&&i.some(c=>Q(c)===o)?i=i.filter(c=>Q(c)!==o):a=void 0}let u=e.relativeDate;if(u){const o=(je({...e,viewer:void 0,selection:{}},n).filters??[]).map(Q),c=i.map(Q);o.every(m=>c.includes(m))?i=i.filter(m=>!o.includes(Q(m))):u=void 0}return{key:e.key,label:e.label,selection:{...t.search?{search:t.search}:{},...i.length?{filters:i}:{},...t.segment?{segment:t.segment}:{}},...Se(r)!==Se(l.table??{})?{table:r}:{},...u?{relativeDate:u}:{},...a?{viewer:a}:{}}}function $a(e,t,r){const l=[...e.filters??[]],n=r??(t.length===1&&t[0].op==="eq"?l.findIndex(i=>i.field===t[0].field&&i.op==="eq"):-1),d=n>=0?[...l.slice(0,n),...t,...l.slice(n+1)]:[...l,...t];return{...e,filters:Js({filters:d}).filters}}function Ra(e,t){return{...e,filters:e.filters?.filter((r,l)=>l!==t)}}function La(e,t){return{...typeof e.$preset=="string"?e[te]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[te]:String(Hs(e[te]))}:Ue(t),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const Ma=[{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 Oa(e){return e.sort&&Ma.some(t=>t.field===e.sort?.field)?e.sort:{field:"created_at",order:"desc"}}function Ta(e,t,r,l,n){const d={...l,filters:l.filters?.filter(i=>i.field!==r)};return Pt({queryKey:["collection-facets",e,t,r,d],enabled:!!t&&!!r,staleTime:3e4,retry:!1,queryFn:async({signal:i})=>{const a=await Ne("query_sdk",{title:`Value counts query for ${r}`,script:`const input = ${JSON.stringify({field:r,collection:d})};
2
- ${t}`},e,{signal:i}),u=a.return_value;if(!a.success||typeof u?.connection!="string"||typeof u.sql!="string")throw new Error(a.error?.message??"Value distribution is unavailable");if(i.aborted)throw new DOMException("Aborted","AbortError");const o=await Ne("query_sql",{title:`Value counts for ${r}`,connection:u.connection,sql:u.sql,limit:51},e,{signal:i});if(o.error)throw new Error(o.error);if(!Array.isArray(o.rows))throw new Error("Source did not return value counts");const c=o.rows.map(m=>{const p=m,f=typeof p.count=="string"&&/^\d+$/.test(p.count)?Number(p.count):p.count;if(!(p.value===null||["string","number","boolean"].includes(typeof p.value))||typeof f!="number"||!Number.isSafeInteger(f)||f<0)throw new Error("Source returned an invalid value distribution");return{value:p.value,count:f}});return{values:c.slice(0,50),truncated:c.length>50||o.truncated===!0}}})}const Ia=300;function Aa({label:e,search:t,onSearch:r,className:l}){const n=t??"",[d,i]=x.useState(n),a=x.useRef({search:t,onSearch:r});a.current={search:t,onSearch:r};const u=x.useRef(void 0);x.useEffect(()=>{const c=()=>{clearTimeout(u.current),i(a.current.search??"")};return window.addEventListener("popstate",c),()=>window.removeEventListener("popstate",c)},[]);const o=x.useRef(n);return x.useEffect(()=>{n!==o.current&&(o.current=n,i(n))},[n]),x.useEffect(()=>{if(d===(a.current.search??""))return;const c=setTimeout(()=>{const m=a.current.onSearch;o.current=d,m(d||void 0,!0)},Ia);return u.current=c,()=>clearTimeout(c)},[d]),s.jsxs("div",{className:`relative${l?` ${l}`:""}`,children:[s.jsx(Ws,{"aria-hidden":"true",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(se,{type:"search","aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}...`,maxLength:512,value:d,onChange:c=>i(c.target.value),className:"pl-9"})]})}function Pa({field:e,initial:t,org:r,facetQuery:l,collection:n,onApply:d,close:i}){const[a,u]=x.useState(t?.op??"eq"),[o,c]=x.useState(t?.value==null?"":String(t.value)),[m,p]=x.useState(""),[f,y]=x.useState(!1),[N,v]=x.useState(),w=e.type==="date"||e.type==="datetime-local"||e.type==="number"?e.type:"text",b=Ta(r,l,e.field,n),C=g=>{try{const E=f?[{field:e.field,op:"gte",value:e.type==="number"?Number(o):o},{field:e.field,op:"lte",value:e.type==="number"?Number(m):m}]:[{field:e.field,op:a,value:g}];if(e.type==="datetime-local")for(const O of E)typeof O.value=="string"&&(O.value=new Date(O.value).toISOString());if(E.some(O=>typeof O.value=="number"&&!Number.isFinite(O.value)))throw new Error("Enter a valid number.");const k=E[0].value,L=E[1]?.value;if(f&&k!=null&&L!=null&&k>L)throw new Error("The lower bound must be before the upper bound.");d(E),i()}catch(E){v(E instanceof Error?E.message:"Could not apply filter")}},j=[...e.options];for(const g of b.data?.values??[])j.some(E=>E.value===g.value)||j.push({value:g.value,label:g.value===null?"Not supplied":String(g.value)});const S=Math.max(1,...b.data?.values.map(g=>g.count)??[]);return s.jsxs("div",{className:"min-w-0 space-y-3 p-3",children:[s.jsxs("select",{"aria-label":"Filter operator",className:"h-8 w-full rounded-md border bg-background px-2 text-sm",value:f?"range":a,onChange:g=>{y(g.target.value==="range"),g.target.value!=="range"&&u(g.target.value)},children:[s.jsx("option",{value:"eq",children:"is"}),s.jsx("option",{value:"neq",children:"is not"}),(e.type==="number"||e.type==="date"||e.type==="datetime-local")&&s.jsxs(s.Fragment,{children:[s.jsx("option",{value:"lt",children:"less than / before"}),s.jsx("option",{value:"lte",children:"at most / on or before"}),s.jsx("option",{value:"gt",children:"greater than / after"}),s.jsx("option",{value:"gte",children:"at least / on or after"}),t?null:s.jsx("option",{value:"range",children:"between"})]})]}),e.type!=="boolean"&&s.jsxs("form",{className:"space-y-2",onSubmit:g=>{g.preventDefault(),C(e.type==="number"?Number(o):o)},children:[s.jsx(se,{required:!0,"aria-label":f?"From value":"Filter value",type:w,step:e.type==="number"?"any":void 0,value:o,onChange:g=>c(g.target.value),placeholder:"Enter a value…"}),f&&s.jsx(se,{required:!0,"aria-label":"To value",type:w,step:e.type==="number"?"any":void 0,value:m,onChange:g=>p(g.target.value)}),s.jsx(R,{size:"sm",type:"submit",className:"w-full",children:"Apply filter"})]}),!f&&(a==="eq"||a==="neq")&&s.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto",children:j.filter(g=>!o||g.label.toLowerCase().includes(o.toLowerCase())).map(g=>{const E=b.data?.values.find(k=>k.value===g.value)?.count;return s.jsxs("button",{type:"button","aria-label":g.label,onClick:()=>C(g.value),className:"relative flex w-full items-center justify-between gap-3 overflow-hidden rounded px-2 py-1.5 text-left text-sm hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[E!==void 0&&s.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-primary/10",style:{width:`${E/S*100}%`}}),s.jsx("span",{className:"relative truncate",children:g.label}),s.jsx("span",{className:"relative text-xs tabular-nums text-muted-foreground",children:E?.toLocaleString()})]},JSON.stringify(g.value))})}),l&&b.isFetching&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Loading distribution…"}),b.isError&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Counts unavailable. You can still enter a value."}),b.data?.truncated&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"Top 50 values. Enter any other value above."}),N&&s.jsx("p",{role:"alert",className:"text-xs text-destructive",children:N})]})}function rs({collection:e,schema:t,label:r,onChange:l,org:n,facetQuery:d,segmentChip:i,viewFilters:a,onClearAll:u}){const o=Na(t),c=(y,N)=>({kind:"custom",className:"w-80",render:v=>s.jsx(Pa,{field:y,initial:N==null?void 0:e.filters?.[N],org:n,facetQuery:d,collection:e,onApply:w=>l($a(e,w,N)),close:v})}),m=o.map(y=>({key:y.field,label:y.label,icon:s.jsx(Ys,{className:"h-4 w-4"}),editor:c(y)})),p=new Map,f=(e.filters??[]).map((y,N)=>{const v=`${y.field}:${y.op}:${JSON.stringify(y.value)}`,w=p.get(v)??0;p.set(v,w+1);const b=o.find(C=>C.field===y.field);return{id:`${v}:${w}`,label:b?.label??y.field,...Sa(y,b),editor:b?c(b,N):void 0,onRemove:()=>l(Ra(e,N))}});if(i&&f.unshift(i),a?.fields.length){for(const y of m)y.group=r;m.push(...a.fields),f.push(...a.chips)}return!m.length&&!f.length?{fields:m,chips:f,clearAll:()=>{}}:{fields:m,chips:f,clearAll:u??(()=>l({...e,filters:[],segment:void 0}))}}function Fa(e){const{fields:t}=rs(e);return t.length?s.jsx(ta,{fields:t}):null}function Da(e){const{chips:t,clearAll:r}=rs(e);return t.length?s.jsx(sa,{label:`${e.label} filters`,fields:[],chips:t,onClearAll:r,className:"mb-4"}):null}const Ce=120,U=12;function $t(e,t){return typeof e.linkId=="number"&&typeof t.linkId=="number"?e.linkId-t.linkId:String(e.linkId).localeCompare(String(t.linkId))}function Va(e){const t=e.records.slice(0,Ce),r=o=>e.types.get(o)??{label:o},l=new Map;for(const o of t)l.set(String(o.id),{source:o.source,entityType:e.typeSlug,slug:o.slug,name:o.name,isFocus:!0,hasMoreLinks:!1});const n=new Map;for(const o of e.links){if(!l.has(String(o.recordId)))continue;const c=n.get(o.recordId)??new Map;c.set(o.linkId,o),n.set(o.recordId,c)}const d=new Map;for(const[o,c]of n){const m=[...c.values()].sort($t),p=l.get(String(o));p&&m.length>U&&(p.hasMoreLinks=!0);for(const f of m.slice(0,U)){d.set(f.linkId,f);const y=String(f.peer.id);l.has(y)||l.set(y,{source:f.peer.source,...f.peer.remote?{remote:f.peer.remote}:{},entityType:f.peer.type,slug:f.peer.slug,name:f.peer.name,isFocus:!1,hasMoreLinks:!1})}}const i=[];for(const[o,c]of l){const m=c.remote?{label:c.entityType}:r(c.entityType),p=c.name||c.slug,f=c.hasMoreLinks?`${m.label} · ${U}+ links`:m.label;i.push({id:o,data:{slug:c.slug,label:p,icon:m.icon,isSystem:!1,metaLabel:f},width:ra(p,f),height:aa})}const a=new Map;for(const o of[...d.values()].sort($t)){const c=String(o.fromId),m=String(o.toId),p=JSON.stringify([c,m]),f=a.get(p)??{source:c,target:m,rels:new Map,symmetric:!0};f.symmetric&&=o.isSymmetric,f.rels.has(o.relSlug)||f.rels.set(o.relSlug,{slug:o.relSlug,label:o.relName,ruleCount:1}),a.set(p,f)}const u=[...a.entries()].map(([o,c])=>({id:`link:${o}`,source:c.source,target:c.target,data:{relationships:[...c.rels.values()],isSymmetric:c.symmetric}}));return{nodes:i,edges:u,records:l,hasMoreRecords:e.hasMore===!0||e.records.length>Ce,listedCount:t.length,focusCount:t.length}}async function Ba(e,t){const r=Va(e);return{...await na({nodes:r.nodes,edges:r.edges},t),records:r.records,hasMoreRecords:r.hasMoreRecords,listedCount:r.listedCount,focusCount:r.focusCount}}const qa=8,Ua=3,Ha=4;function ve(e){return`source:${JSON.stringify([e.type,e.key])}`}function za(e,t){return t.map(r=>{const l={type:e,key:r.slug};return{...r,id:ve(l),source:l}})}function Rt(e){return JSON.stringify([e.relationship_type,e.direction,e.entity_type,e.key])}async function Ga(e,t,r){const l=e.slice(0,qa),n=[];let d=0;return await Promise.all(Array.from({length:Math.min(Ua,l.length)},async()=>{for(;d<l.length;){const i=d++,a=l[i];try{if(r?.aborted)throw r.reason;const u=await t(a),o=new Map(a.links.map(v=>[Rt(v),v]));for(const v of u.record_links){const w=Rt(v),b=o.get(w);(!b||b.occurred_at<v.occurred_at)&&o.set(w,v)}const c=new Map((a.relationships??[]).map(v=>[v.id,v]));for(const v of u.relationships??[])c.set(v.id,v);const m=[...c.values()].slice(0,U+1),p=[...o.values()].slice(0,U+1),f=(a.pagesRead??0)+1,y=!!u.next_cursor&&f>=Ha,N=u.record_failures.length>0||!!u.relationship_failures?.length||y;n[i]={read:{record:a.record,links:p,failed:N,entityId:a.entityId,relationships:m},...!y&&(N||u.next_cursor&&p.length+m.length<=U)?{next:{record:a.record,entityId:a.entityId,relationships:m,pagesRead:f,cursor:u.next_cursor??a.cursor,links:p}}:{}}}catch(u){if(r?.aborted)throw u;n[i]={read:{record:a.record,links:a.links,failed:!0,entityId:a.entityId,relationships:a.relationships},next:{...a,cursor:u instanceof Qs&&u.status===400?null:a.cursor}}}}})),{reads:n.map(i=>i.read),pending:[...n.flatMap(i=>i.next?[i.next]:[]),...e.slice(l.length)]}}function Ja(e,t){const r=new Map;for(const d of e)for(const i of d.reads)r.set(String(i.entityId??ve(i.record)),i);const l=new Map(t.map(d=>[d.slug,d])),n=[];for(const[d,i]of r){for(const a of i.relationships??[]){const u=(v,w,b)=>b?`remote:${b}`:typeof v=="number"?v:ve({type:w,key:v}),o=u(a.from_entity_id,a.from_entity_type,a.from_entity_url),c=u(a.to_entity_id,a.to_entity_type,a.to_entity_url),m=String(o)===d,p=m?c:o,f=m?a.to_entity_id:a.from_entity_id,y=m?a.to_entity_url:a.from_entity_url,N=(m?a.to_entity_type:a.from_entity_type)??"";n.push({recordId:d,linkId:a.id,fromId:o,toId:c,relSlug:a.relationship_type_slug,relName:a.relationship_type_name,isSymmetric:a.is_symmetric,peer:{id:p,name:(m?a.to_entity_name:a.from_entity_name)??String(f),slug:(m?a.to_entity_slug:a.from_entity_slug)??String(f),type:N,...y?{remote:{url:Ks(y)}}:typeof f=="string"?{source:{type:N,key:f}}:{}}})}for(const a of i.links){const u={type:a.entity_type,key:a.key},o=ve(u),c=l.get(a.relationship_type);let m=a.direction==="incoming"?o:d,p=a.direction==="incoming"?d:o;c?.is_symmetric&&m>p&&([m,p]=[p,m]),n.push({recordId:d,linkId:JSON.stringify([m,p,a.relationship_type]),fromId:m,toId:p,relSlug:a.relationship_type,relName:c?.name||a.relationship_type.replaceAll("_"," "),isSymmetric:c?.is_symmetric??!1,peer:{id:o,name:a.name||a.key,slug:a.key,type:a.entity_type,source:u}})}}return{links:n,checked:r.size,failed:[...r.values()].filter(d=>d.failed).length}}function Wa(e,t,r,l,n,d=!1){const{orgContext:i}=Ee(),a=Ft(i),u=Xs(i),o=x.useMemo(()=>d?za(t,r):r,[d,t,r]),c=x.useMemo(()=>o.slice(0,Ce).flatMap(j=>j.source?[{record:j.source,cursor:null,links:[]}]:typeof j.id=="number"?[{entityId:j.id,record:{type:t,key:j.slug},cursor:null,links:[]}]:[]),[o,t]),m=Zs({queryKey:["source-records-graph",i.organizationId,e,t,c.map(j=>[j.record,j.entityId])],enabled:!0,initialPageParam:c,queryFn:({pageParam:j,signal:S})=>Ga(j,async g=>{const E=await Ne("manage_entity",{action:"list_links",...g.entityId===void 0?{record:g.record,cursor:g.cursor}:{entity_id:g.entityId,offset:Number(g.cursor??0)},limit:U+1},e,{signal:S});return{...E,record_links:E.record_links??[],record_failures:E.record_failures??[],next_cursor:g.entityId===void 0?E.next_cursor:E.metadata?.has_more?String(Number(g.cursor??0)+U+1):null}},S),getNextPageParam:j=>j.pending.length?j.pending:void 0,staleTime:3e4,retry:!1}),p=x.useMemo(()=>m.data?Ja(m.data.pages,u.data??[]):void 0,[m.data,u.data]),f=p?.links,y=m.isError,N=JSON.stringify([i.organizationId,e,t,d,o.map(j=>[j.id,j.name,j.slug]),l]),v=x.useMemo(()=>new Map((a.data??[]).map(j=>[j.slug,{label:j.name||j.slug,icon:j.icon}])),[a.data]),[w,b]=x.useState(null);x.useEffect(()=>{if(!f)return;let j=!1;return Ba({typeSlug:t,records:o,hasMore:l,links:f,types:v},{targetAspect:n}).then(S=>{j||b({graph:S,key:N,isError:!1})}).catch(()=>{j||b({graph:null,key:N,isError:!0})}),()=>{j=!0}},[f,t,o,l,v,n,N]);const C=w?.key===N?w:null;return{graph:C?.graph??null,isLoading:!y&&!C,isError:y||C?.isError===!0,sourceProgress:{checked:p?.checked??0,total:Math.min(r.length,Ce),failed:p?.failed??0,hasMore:!!m.hasNextPage,isFetching:m.isFetching,loadMore:()=>{m.isFetching||m.fetchNextPage()}}}}function Ya(e){const t=new Map(e.nodes.map(n=>[n.id,n.data.label])),r=e.nodes.map(n=>({id:n.id,x:n.position.x+n.width/2,y:n.position.y+n.height/2,w:n.width,h:n.height,title:n.data.label,meta:n.data.metaLabel,icon:n.data.icon,muted:e.records.get(n.id)?.isFocus===!1})),l=e.edges.map(n=>{const{relationships:d,isSymmetric:i}=n.data,a=d.map(u=>u.label);return{id:n.id,source:n.source,target:n.target,route:n.route??null,summary:a.length===1?a[0]:`${a.length} relationships`,details:a,directed:!i,ariaLabel:`${t.get(n.source)??n.source} ${i?"and":"to"} ${t.get(n.target)??n.target}: ${a.join(", ")}`}});return{boxes:r,edges:l}}function Qa({ownerSlug:e,typeSlug:t,records:r,hasMore:l,sourceBacked:n=!1}){const d=ne(),i=Dt(),{orgContext:a}=Ee(),{data:u=[]}=Ft(a),o=u.find(S=>S.slug===t)?.name??t,[c,m]=x.useState(),p=x.useRef(null),f=x.useCallback(S=>{if(p.current?.disconnect(),p.current=null,!S||typeof ResizeObserver>"u")return;const g=()=>{if(!S.clientWidth||!S.clientHeight)return;const k=Math.round(S.clientHeight/S.clientWidth*10)/10;m(L=>L===k?L:k)};g();const E=new ResizeObserver(g);E.observe(S),p.current=E},[]),{graph:y,isLoading:N,isError:v,sourceProgress:w}=Wa(e,t,r,l,c,n),b=x.useMemo(()=>y?Ya(y):null,[y]),C=x.useCallback(S=>{const g=y?.records.get(S);if(g){if(g.remote){g.remote.url&&window.open(g.remote.url,"_blank","noopener,noreferrer");return}if(i){i.open(ia({...g.source?{record:g.source}:{entityId:Number(S)},ownerSlug:e,orgContext:a,name:g.name||g.slug}));return}d({to:en(e,[{entity_type:g.entityType,slug:g.slug}])})}},[y,e,a,i,d]);if(v)return s.jsx(tn,{label:`${o} graph`});if(N||!y||!b)return s.jsx(Zt,{label:`Loading ${o} graph`});const j=w?s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"text-sm text-muted-foreground",role:"status",children:[s.jsxs("p",{children:["Checked ",w.checked," of ",w.total," records. Up to ",U," relationships per record."]}),w.failed>0?s.jsx("p",{role:"alert",children:"Some sources could not be read. These relationships are incomplete."}):null]}),w.hasMore?s.jsx(R,{variant:"outline",size:"sm",disabled:w.isFetching,onClick:w.loadMore,children:w.isFetching?"Loading…":w.failed>0?"Retry sources":"Load more relationships"}):null]}):null;return y.focusCount===0?s.jsxs("div",{className:"space-y-3",children:[j,s.jsx(Vt,{icon:Bt,title:`No ${o} records match`,description:"Change the search or filters to see records here."})]}):s.jsxs("div",{className:"flex flex-col gap-2",children:[j,s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",y.hasMoreRecords?"the first ":"",y.focusCount," ",o," record",y.focusCount===1?"":"s",". Click a record to see it."]}),s.jsx("div",{ref:f,className:"h-[70vh] min-h-[420px] min-w-0 overflow-hidden",children:s.jsx(oa,{boxes:b.boxes,edges:b.edges,label:`${o} records`,onOpenBox:C,openLabel:S=>`Show ${S.title}`})})]})}function Ka(e){return String(e??"").replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function os(e){return e["x-lobu"]?.role||e["x-lobu-role"]}function Ke(e){const t=e?.properties;if(!t)return null;const n=sn(t).find(([,o])=>os(o)==="workflowState");if(!n)return null;const[d,i]=n,a=i["x-lobu"]?.states,u=Array.isArray(a)&&a.length>0?a:(i.enum??[]).map(o=>({value:o}));return u.length===0||u.some(o=>typeof o.value!="string")?null:{field:d,states:u.map(o=>({...o,label:o.label||nn(i,o.value)||Ka(o.value),terminal:o.terminal??["done","complete","completed","closed","archived"].includes(o.value.toLowerCase())}))}}function Xa(e){const t=e?.properties;if(!t)return null;const r=Object.entries(t),l=r.find(([,i])=>os(i)==="sortRank"),n=r.find(([i])=>["rank","sort_rank","order"].includes(i)),d=l??n;return d?{field:d[0]}:null}function Za(e,{isDerived:t}){const r=e?.["x-lobu"]?.defaultView;return(r==="table"||r==="board")&&!(t&&r!=="table")?r:t?"table":Ke(e)?"board":"table"}const is={version:1,root:{type:"entity-table",props:{state:"{{tableState}}"}}},er={version:1,root:{type:"entity-board",props:{state:"{{boardState}}",onUpdate:"@updateEntity"}}};function tr(e){const{canShowBoard:t,builtinData:r,builtInLabels:l}=e,n=["table",...t?["board"]:[]],d={table:is,board:er};return n.map(i=>({id:i,label:l[i],builtInMode:i,template:d[i],data:r}))}function We(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function we(e,t){if(!t)return e.created_at??String(e.id);const r=_e(e.metadata);return String(r[t.field]??e.created_at??e.id)}function sr(e,t){const r=e?Number(e):Number.NaN,l=t?Number(t):Number.NaN;return Number.isFinite(r)&&Number.isFinite(l)&&r<l?String((r+l)/2):Number.isFinite(r)?String(r+1):Number.isFinite(l)?String(l-1):String(Date.now())}function Ye(e,t){const r=_e(e.metadata);return String(r[t]??"")}function ls(e,t){return[...e].sort((r,l)=>we(r,t).localeCompare(we(l,t)))}function nr(e,t,r,l,n){if(!t.startsWith("card:")||!r)return null;const d=Number(t.slice(5)),i=e.find(b=>b.id===d);if(!i)return null;const a=r.startsWith("column:")?r.slice(7):Ye(e.find(b=>`card:${b.id}`===r)??i,l.field);if(!a)return null;const u=ls(e.filter(b=>b.id!==d&&Ye(b,l.field)===a),n),o=r.startsWith("card:")?u.findIndex(b=>`card:${b.id}`===r):u.length,c=o>=0?o:u.length,m=c>0?u[c-1]:void 0,p=u[c],f=n?sr(m?we(m,n):void 0,p?we(p,n):void 0):void 0,y=_e(i.metadata),N={[l.field]:a,...n&&f?{[n.field]:f}:{}};l.states.find(b=>b.value===a)?.terminal&&!y.completed_at&&(N.completed_at=new Date().toISOString());const w={...y,...N};return{entityId:d,changedMetadata:N,nextMetadata:w}}function Lt(e,t,r){return e.map(l=>l.id===t?{...l,metadata:r}:l)}function ar({id:e,children:t,className:r}){const{setNodeRef:l,isOver:n}=ts({id:`column:${e}`});return s.jsx("div",{ref:l,className:ie("min-h-[220px] rounded-lg bg-card p-2 transition-colors",n?"bg-accent/50":"",r),children:t})}function rr({entity:e,owner:t,statusField:r,entityTypeIcon:l,schema:n,didDragRef:d}){const i=_e(e.metadata),{attributes:a,listeners:u,setNodeRef:o,transform:c,isDragging:m}=ha({id:`card:${e.id}`}),{setNodeRef:p,isOver:f}=ts({id:`card:${e.id}`}),y=qt(t,es(e)),N=v=>{d.current&&(v.preventDefault(),v.stopPropagation())};return s.jsx("div",{ref:v=>{o(v),p(v)},style:{transform:ga.Translate.toString(c)},className:ie(on,"p-3 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",m?"opacity-60":"",f?"ring-1 ring-ring":""),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("button",{type:"button",className:"mt-0.5 shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing","aria-label":`Drag ${e.name}`,...a,...u,children:s.jsx(rn,{className:"h-4 w-4"})}),s.jsx(Xt,{metadata:i,metadataSchema:n,name:e.name,typeIcon:l,className:"mt-0.5 h-6 w-6 shrink-0",initialsFallback:!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx(ke,{to:y,className:"font-medium text-foreground hover:underline",onClick:N,children:e.name}),s.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[typeof i.priority=="string"&&i.priority?s.jsx(ze,{variant:"outline",className:"text-xs",children:We(i.priority)}):null,typeof i[r]=="string"&&i[r]?s.jsx(ze,{variant:"secondary",className:"text-xs",children:We(String(i[r]))}):null]})]})]})})}function or({owner:e,entities:t,totalCount:r,schema:l,entityTypeIcon:n,onUpdate:d}){const i=x.useMemo(()=>Ke(l),[l]),a=x.useMemo(()=>Xa(l),[l]),[u,o]=x.useState(t),[c,m]=x.useState(()=>new Set),p=x.useRef(!1),f=ua(ma(fa,{activationConstraint:{distance:6}})),y=x.useCallback(()=>{window.setTimeout(()=>{p.current=!1},0)},[]);x.useEffect(()=>{o(t)},[t]);const N=x.useMemo(()=>{if(!i)return new Map;const C=new Map(i.states.map(j=>[j.value,[]]));for(const j of u){const S=Ye(j,i.field),g=C.has(S)?S:i.states[0]?.value;g&&C.get(g)?.push(j)}for(const[j,S]of C)C.set(j,ls(S,a));return C},[u,a,i]);if(!i)return null;const v=C=>{m(j=>{const S=new Set(j);return S.has(C)?S.delete(C):S.add(C),S})},w=()=>{p.current=!0},b=C=>{const j=String(C.active.id),S=C.over?String(C.over.id):null,g=nr(u,j,S,i,a);if(!g){y();return}const{entityId:E,changedMetadata:k,nextMetadata:L}=g,X=u.find($=>$.id===E)?.metadata;o($=>Lt($,E,L)),d(E,k).catch(()=>{o($=>Lt($,E,X))}),y()};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-base font-semibold",children:"Board"}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Grouped by ",We(i.field),typeof r=="number"&&r>u.length?s.jsxs(s.Fragment,{children:[" · ",s.jsxs("span",{className:"text-amber-600 dark:text-amber-500",children:["showing first ",u.length," of ",r," — narrow with search"]})]}):null]})]}),s.jsx(pa,{sensors:f,onDragStart:w,onDragEnd:b,children:s.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:i.states.map(C=>{const j=N.get(C.value)??[],S=C.collapsed??C.terminal,g=S&&!c.has(C.value);return s.jsxs(ar,{id:C.value,children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[C.terminal?s.jsx(an,{className:"h-4 w-4 text-muted-foreground"}):null,s.jsx("h3",{className:"text-sm font-medium",children:C.label})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(ze,{variant:"secondary",className:"text-xs",children:j.length}),S?s.jsx(R,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",onClick:()=>v(C.value),children:g?"Show":"Hide"}):null]})]}),g?s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:[j.length," hidden ",C.label?.toLowerCase()," item",j.length===1?"":"s"]}):s.jsx("div",{className:"space-y-2",children:j.length>0?j.map(E=>s.jsx(rr,{entity:E,owner:e,statusField:i.field,entityTypeIcon:n,schema:l,didDragRef:p},E.id)):s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:["No ",C.label?.toLowerCase()," items"]})})]},C.value)})})})]})}const ir=x.memo(or);function lr(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t.toString(36)}function cs(e,t){return{queryKey:["metric_series",e,lr(t)],queryFn:()=>Ne("metric_series",{sql:t},{slug:e}),staleTime:6e4}}function ds(e,t){const r=!!e&&!!t,l=cs(e??"",t??"");return Pt({...l,enabled:r})}ds.queryOptions=(e,t)=>cs(e,t);function cr(e,t){if(!e?.columns?.length||!e.rows)return[];const r=e.columns.indexOf(t);return r<0?[]:e.rows.map(l=>Number(l[r])||0)}const Mt=/^[a-z][a-z0-9_]*$/;function dr(e){const t=Object.entries(e);for(const[n,d]of t){if(!Mt.test(n))throw new Error(`lifecycleCumulativeStatsSql: unsafe column name '${n}'`);if(!Mt.test(d))throw new Error(`lifecycleCumulativeStatsSql: unsafe entity_type '${d}'`)}const r=t.flatMap(([n,d])=>[`COUNT(*) FILTER (
3
- WHERE semantic_type = 'change'
4
- AND metadata->>'category' = 'lifecycle'
5
- AND metadata->>'entity_type' = '${d}'
6
- AND metadata->>'op' = 'created'
7
- ) AS ${n}_added`,`COUNT(*) FILTER (
8
- WHERE semantic_type = 'change'
9
- AND metadata->>'category' = 'lifecycle'
10
- AND metadata->>'entity_type' = '${d}'
11
- AND metadata->>'op' = 'deleted'
12
- ) AS ${n}_removed`]).join(`,
13
- `),l=t.map(([n])=>` SUM(COALESCE(b.${n}_added, 0) - COALESCE(b.${n}_removed, 0))
14
- OVER (ORDER BY d.bucket) AS ${n}`).join(`,
15
- `);return`
16
- WITH days AS (
17
- SELECT generate_series(
18
- date_trunc('day', now() - interval '13 days'),
19
- date_trunc('day', now()),
20
- interval '1 day'
21
- ) AS bucket
22
- ),
23
- buckets AS (
24
- SELECT
25
- date_trunc('day', created_at) AS bucket,
26
- ${r}
27
- FROM events
28
- WHERE created_at > now() - interval '14 days'
29
- GROUP BY 1
30
- )
31
- SELECT d.bucket,
32
- ${l}
33
- FROM days d
34
- LEFT JOIN buckets b ON b.bucket = d.bucket
35
- ORDER BY d.bucket
36
- `}const ur={"memory-activity":`
37
- WITH days AS (
38
- SELECT generate_series(
39
- date_trunc('day', now() - interval '13 days'),
40
- date_trunc('day', now()),
41
- interval '1 day'
42
- ) AS bucket
43
- ),
44
- buckets AS (
45
- SELECT
46
- date_trunc('day', created_at) AS bucket,
47
- COUNT(*) FILTER (
48
- WHERE semantic_type NOT IN ('change', 'audit', 'operation')
49
- ) AS events_count,
50
- COUNT(*) FILTER (
51
- WHERE semantic_type = 'change'
52
- AND metadata->>'category' = 'lifecycle'
53
- AND metadata->>'entity_type' = 'connection'
54
- AND metadata->>'op' = 'created'
55
- ) AS connections_added,
56
- COUNT(*) FILTER (
57
- WHERE semantic_type = 'change'
58
- AND metadata->>'category' = 'lifecycle'
59
- AND metadata->>'entity_type' = 'connection'
60
- AND metadata->>'op' = 'deleted'
61
- ) AS connections_removed
62
- FROM events
63
- WHERE created_at > now() - interval '14 days'
64
- GROUP BY 1
65
- )
66
- SELECT d.bucket,
67
- COALESCE(b.events_count, 0)::int AS events,
68
- SUM(COALESCE(b.connections_added, 0) - COALESCE(b.connections_removed, 0))
69
- OVER (ORDER BY d.bucket) AS connections
70
- FROM days d
71
- LEFT JOIN buckets b ON b.bucket = d.bucket
72
- ORDER BY d.bucket
73
- `};function mr(e){if(typeof e.sql=="string"&&e.sql.trim())return e.sql;if(e.lifecycle&&typeof e.lifecycle=="object"){const t=Object.fromEntries(Object.entries(e.lifecycle).map(([r,l])=>[r,String(l)]));if(Object.keys(t).length>0)try{return dr(t)}catch{return null}}return typeof e.preset=="string"?ur[e.preset]??null:null}function pr({owner:e,sql:t,lifecycle:r,preset:l,column:n,chart:d,height:i,width:a,color:u,label:o,className:c}){const m=x.useMemo(()=>mr({sql:t,lifecycle:r,preset:l}),[t,r,l]),p=typeof e=="string"&&e?e:null,{data:f}=ds(p,m),y=String(n??""),N=x.useMemo(()=>cr(f,y),[f,y]),v=x.useMemo(()=>!f?.columns?.length||!f.rows?[]:f.rows.map((b,C)=>({label:String(b[0]??"").slice(0,10),value:N[C]??0})),[f,N]);if(!p||!m||!y)return null;const w=d==="line"?s.jsx(la,{data:v,height:typeof i=="number"?i:void 0}):s.jsx(ca,{data:N,height:typeof i=="number"?i:void 0,width:typeof a=="number"?a:void 0,color:typeof u=="string"?u:void 0});return o==null?s.jsx("div",{className:c,children:w}):s.jsxs("div",{className:c,children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:String(o)}),w]})}function fr({metadata:e,metadataSchema:t,name:r,typeIcon:l,initialsFallback:n,className:d}){return s.jsx(Xt,{metadata:e,metadataSchema:t,name:String(r??""),typeIcon:l,initialsFallback:!!n,className:d})}function hr({entity:e,owner:t,className:r,onClick:l,children:n}){const d=e;if(!d)return s.jsx(s.Fragment,{children:n});const i=qt(String(t??""),es(d));return s.jsx(ke,{to:i,className:r,onClick:l,children:n})}function gr({state:e}){return e?s.jsx(Kn,{...e}):null}function yr({state:e,onUpdate:t}){return e?s.jsx(ir,{...e,onUpdate:t}):null}const xr={"entity-avatar":fr,"entity-link":hr,"entity-table":gr,"entity-board":yr,"metric-series":pr};function br({ownerSlug:e,typeSlug:t,title:r,shape:l}){const[n,d]=x.useState(!1),i=ne(),{visible:a,system:u,isTypesLoading:o}=ln(e),c=p=>{d(!1);const f=`/${e}/${Wt(p)}`;i({to:l?`${f}/${Yt}/${l}`:f})},m=p=>s.jsxs(hn,{value:`${p.name} ${p.slug}`,onSelect:()=>c(p.slug),children:[s.jsx(Jt,{icon:p.icon,className:"mr-2 h-4 w-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate",children:p.name||p.slug}),p.slug===t?s.jsx(gn,{className:"ml-2 h-3.5 w-3.5 shrink-0","aria-label":"Current"}):null,p.entity_count!=null?s.jsx("span",{className:"ml-2 shrink-0 text-xs tabular-nums text-muted-foreground",children:p.entity_count.toLocaleString()}):null]},p.slug);return s.jsxs(Ut,{open:n,onOpenChange:d,children:[s.jsx("h1",{className:"flex min-w-0 items-center text-lg font-semibold tracking-tight @sm:text-2xl",children:s.jsx(Ht,{asChild:!0,children:s.jsxs(R,{type:"button",variant:"ghost",title:r,className:"-ml-2 h-auto min-w-0 gap-1 px-2 py-1 text-lg font-semibold tracking-tight @sm:gap-1.5 @sm:text-2xl",children:[s.jsx("span",{className:"truncate",children:r}),s.jsx(zt,{className:"h-5 w-5 shrink-0 text-muted-foreground"})]})})}),s.jsx(Gt,{align:"start",className:"w-72 p-0",children:s.jsxs(cn,{children:[s.jsx(dn,{autoFocus:!0,placeholder:"Find a type…"}),s.jsxs(un,{children:[s.jsx(mn,{children:o?"Loading types…":"No type matches."}),a.length>0?s.jsx(wt,{heading:"Types",children:a.map(m)}):null,u.length>0?s.jsx(wt,{heading:"System",children:u.map(m)}):null]}),s.jsx(pn,{}),s.jsxs(ke,{to:"/$owner",params:{owner:e},search:{layout:"graph"},onClick:()=>d(!1),className:"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:text-foreground",children:[s.jsx(fn,{className:"h-4 w-4"}),"Data map"]})]})})]})}function vr(e){return Object.entries(e?.metrics_config?.segments??{}).filter(([,t])=>t.on==="entity").map(([t,r])=>({name:t,description:r.description}))}const be={table:{label:"Table",icon:En},board:{label:"Board",icon:wn},graph:{label:"Graph",icon:Bt}},us=(e,t)=>`lobu.record-shape:v1:${e}/${t}`,jr=new Set(["table","board","graph"]);function Nr(e,t){const r=_n(us(e,t));return r&&jr.has(r)?r:void 0}function Sr(e,t,r){$n(us(e,t),r)}const Ot=":records";function Cr({ownerSlug:e,entityTypeSlug:t,create:r,onCreateChange:l,viewKey:n,shape:d}){const{orgContext:i,hasOrgContext:a}=Ee(),u=Tt(t,i),{data:o,isLoading:c,error:m}=u;yn(`/${e}`,i);const p=xn(),[f,y]=x.useState({key:"",page:0}),N=Qt({strict:!1}),v=ne(),w=Dt(),b=`/${e}/${Wt(t)}`,{session:C,isReady:j}=bn(),S=j&&!c&&o?.slug===t,g=C?.user?.email,E=x.useMemo(()=>g?{email:g}:void 0,[g]),{collection:k,error:L,presentation:O,presets:X,preset:$,edited:le,table:I}=x.useMemo(()=>Ea(N,o?.metadata_schema,!!n,E),[N,o?.metadata_schema,n,E]),z=S?L:void 0,G=x.useMemo(()=>La(N,k),[N,k]),[ms,Xe]=x.useState(!1),[$e,ps]=x.useState(0),Re=k.search??"",Z=k.segment,fs=JSON.stringify(k),ae=Z?vr(o).find(h=>h.name===Z)??{name:Z,description:""}:null,hs=h=>void v({to:".",search:_=>({...Ge(_,K(h)),...G}),replace:!0}),J=vn(u.data),Ze=J?I.sort:Oa(I),Le=Ze?.field,et=Ze?.order,W=x.useMemo(()=>Le?[{id:Le,desc:et==="desc"}]:[],[Le,et]),ce=x.useCallback(h=>void v({to:".",search:{...n?K(N):{},...G,$table:JSON.stringify(h)},replace:!0}),[v,n,N,G]),tt=x.useCallback(h=>{const _=typeof h=="function"?h(W):h;_[0]&&ce({...I,sort:{field:_[0].id,order:_[0].desc?"desc":"asc"}})},[W,ce,I]),de=r===!0,st=()=>l(!0),gs=()=>l(!1),ys=W[0]?.id,xs=W[0]?W[0].desc?"desc":"asc":void 0,Me=u.data?.metadata_schema,ue=!!Ke(Me)&&!J,bs=Za(Me,{isDerived:J}),P=Kt(i),vs=Be(P.data??[],t,k),re=(h,_=!1,A=K(N))=>{const T=!n||!P.data||Be(P.data,t,h).some(ye=>ye.key===n);v({to:T?".":b,search:{...T&&n?A:{},...ka(h,$?.key),$table:JSON.stringify(I)},replace:_})},me=h=>{const _=h?je(h,void 0,E):{},A=!n||Be(P.data??[],t,_).some(T=>T.key===n);Xe(!1),ps(T=>T+1),v({to:A?".":b,search:h?{$preset:h.key}:{}})},{isAdmin:js}=jn(i.organizationId),Oe=Nn(i),Ns=js&&!!o&&!u.isPlaceholderData,nt=x.useRef(N);nt.current=N;const Ss=async()=>{if(!$)return;const h=JSON.stringify(N),{data:_}=await u.refetch(),A=_?.metadata_schema,T=A?Qe(A[He]??{}):void 0,ye=T?.presets?.find(xe=>xe.key===$.key);if(!_||!A||!T||!ye){It.error("This saved filter changed. Reload and try again.");return}const De=_a(ye,k,I,T,void 0,E);await Oe.mutateAsync({slug:_.slug,metadata_schema:{...A,[He]:{...T,presets:T.presets?.map(xe=>xe.key===De.key?De:xe)}}}).then(()=>!0,()=>!1)&&(await u.refetch(),JSON.stringify(nt.current)===h&&me(De))},Cs=x.useMemo(()=>Nr(e,t),[e,t]),D=Sn(P.data??[],t,{viewKey:n,shape:d??(n?void 0:Cs)},bs,k),V=D.kind==="builtin"?D.mode==="board"&&!ue?"table":D.mode:null,at=V==="graph";x.useEffect(()=>{d&&S&&V&&Sr(e,t,V)},[d,S,V,e,t]);const rt=["table",...ue?["board"]:[],"graph"],Y=D.kind==="view"?D.view:null,ot=D.kind==="missing"?D.key:null,Te=D.kind==="inapplicable"?D:null,oe=V==="table"?50:200,pe=`${t}?${fs}&sort=${JSON.stringify(I.sort)}&size=${oe}`,fe=f.key===pe?f.page:0,Ie=x.useCallback(h=>y(_=>({key:pe,page:h(_.key===pe?_.page:0)})),[pe]),he=Et(t,i,{limit:oe,offset:fe*oe,search:Re.trim()||void 0,sortBy:ys,sortOrder:xs,segment:Z,filters:k.filters,enabled:S&&!n&&!z}),it=Et(t,i,{limit:1,offset:0,parentId:null,search:Re.trim()||void 0,segment:Z,filters:k.filters,enabled:S&&!n&&!z&&!J}),{data:ge,error:ws}=he,Es=he.isLoading||he.isPending&&he.fetchStatus==="paused",lt=z||m||(n?null:ws),ks=!!n&&P.data===void 0&&P.isError,B=ge?.entities??[],Ae=ge?.metadata?.has_more??!1,F=ge?.metadata?.total_count??0,ct=B.length>0||Re.trim().length>0||fe>0||!!Z||!!k.filters?.length,M=o?.name?.trim()||qe(t),ee=o?.icon||void 0,q=J,H=Me,_s=!z&&(!a||!S||(n?P.data===void 0&&!P.isError:Es||!J&&it.isLoading)),dt=ge?.linked_entities??{},ut=it.data?.metadata?.total_count,mt=F>0&&typeof ut=="number"?ut<F:!1,pt=x.useMemo(()=>o?.measure_columns??[],[o?.measure_columns]),ft=x.useCallback(h=>ce({...I,columns:h}),[ce,I]),ht=x.useMemo(()=>({entities:B,owner:e,schema:H,entityTypeIcon:ee,isDerived:q,measureColumns:pt,linkedEntityLookups:dt,hasAnyParents:mt,sorting:W,onSortingChange:tt,visibleColumns:I.columns,columnChoices:Xn(H,q,B),onVisibleColumnsChange:ft,page:fe,pageSize:oe,totalCount:F,hasMore:Ae,pageTitle:M,onPrevPage:()=>Ie(h=>Math.max(0,h-1)),onNextPage:()=>Ie(h=>h+1)}),[B,e,H,ee,q,pt,dt,mt,W,I.columns,ft,tt,Ie,fe,oe,F,Ae,M]),gt=F>B.length,yt=`showing first ${B.length} of ${F} — narrow with search`,xt=x.useMemo(()=>({owner:e,entityType:o,entities:B,totalCount:F,schema:H,entityTypeIcon:ee}),[e,o,B,F,H,ee]),Pe=x.useMemo(()=>({tableState:ht,boardState:xt,owner:e,schema:H,entityType:o,entityTypeIcon:ee,totalCount:F,isTruncated:gt,truncationNotice:yt,canCreate:!q,addLabel:`Add ${o?.name||qe(t)}`}),[ht,xt,e,H,o,ee,F,gt,yt,q,t]),$s=x.useMemo(()=>tr({canShowBoard:ue,builtinData:Pe,builtInLabels:{table:be.table.label,board:be.board.label}}),[ue,Pe]),bt=V?$s.find(h=>h.id===V)??null:null,Rs=bt?.template??is,Ls=bt?.data??Pe,vt=h=>void v({to:h===Ot?b:`${b}${Je(h)}`,search:G}),Fe=K(N),Ms=ya(Y?.params,Fe,h=>void v({to:".",search:{...K(h),...G}})),Os=()=>re({...k,filters:[],segment:void 0},!1,xa(Y?.params,Fe)),jt={collection:k,schema:H,label:M,org:i??"",facetQuery:O.facetQuery,onChange:re,viewFilters:Ms,onClearAll:Os,segmentChip:ae?{id:"segment",label:"Segment",op:"is",value:qe(ae.name),title:ae.description||void 0,editor:ae.description?{kind:"custom",render:()=>s.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:ae.description})}:void 0,onRemove:()=>re({...k,segment:void 0})}:void 0},Nt=`Moved on ${o?.name||o?.slug||t} board`,St=x.useMemo(()=>(h,_)=>p.mutateAsync({entityId:h,metadata:_,field_note:Nt}),[p,Nt]),Ts=x.useMemo(()=>({updateEntity:St,openCreate:()=>l(!0)}),[St,l]),Ct=h=>w?s.jsx("span",{className:h,children:s.jsx(R,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground","aria-label":"Edit type",title:"Edit type",onClick:()=>w.open({href:Ln(e,t),title:M}),children:s.jsx(Rn,{className:"h-4 w-4"})})}):null;return s.jsx(Zn,{title:s.jsx(br,{ownerSlug:e,typeSlug:t,title:M,shape:n?null:V}),actions:Ct("hidden @sm:contents"),controls:s.jsxs(s.Fragment,{children:[de?s.jsx("div",{className:"max-w-3xl",children:s.jsx(ja,{onClose:gs,entityTypeSlug:t,orgContext:i})}):null,!de&&S&&s.jsxs("nav",{className:"mb-4 flex flex-wrap items-center gap-x-3 gap-y-2","aria-label":`${M} views`,children:[Ct("-mr-1 @sm:hidden"),!n&&rt.length>1&&s.jsx("fieldset",{className:"flex items-center rounded-md border p-0.5","aria-label":"Record layout",children:rt.map(h=>{const _=be[h].icon,A=V===h;return s.jsx(R,{type:"button",variant:"ghost",size:"sm","aria-pressed":A,title:be[h].label,"data-testid":`shape-${h}`,className:ie("h-7 px-2",A&&"bg-accent text-accent-foreground"),onClick:()=>void v({to:`${b}/${Yt}/${h}`,search:G,replace:!0}),children:s.jsx(_,{className:"h-4 w-4"})},h)})}),n&&s.jsx(R,{variant:"ghost",onClick:()=>vt(Ot),children:"Records"}),!!X.length&&s.jsxs(Ut,{open:ms,onOpenChange:Xe,children:[s.jsx(Ht,{asChild:!0,children:s.jsxs(R,{variant:"outline",className:ie("gap-2",le&&"border-dashed border-primary"),"data-edited":le||void 0,title:"Choose saved filter",children:[$?.label??(k.filters?.length||k.search?"Custom filter":"All records"),le?s.jsx("span",{className:"text-xs font-normal text-primary",children:"Edited"}):null,s.jsx(zt,{className:"h-4 w-4 text-muted-foreground"})]})}),s.jsxs(Gt,{align:"start",className:"w-60 p-1",children:[s.jsx(R,{variant:$?"ghost":"secondary",className:"w-full justify-start",onClick:()=>me(),children:"All records"}),X.map(h=>s.jsx(R,{variant:$?.key===h.key?"secondary":"ghost",className:"w-full justify-start",onClick:()=>me(h),children:h.label},h.key))]})]}),$&&le?s.jsxs("div",{className:"-ml-2 mr-2 inline-flex items-center gap-1",children:[s.jsx(R,{variant:"ghost",size:"sm",onClick:()=>me($),children:"Reset"}),Ns?s.jsx(R,{size:"sm",disabled:Oe.isPending,onClick:()=>void Ss(),children:Oe.isPending?"Saving…":"Save"}):null]}):null,vs.map(h=>s.jsx(R,{"data-testid":`tab-${h.key}`,variant:n===h.key?"secondary":"ghost","aria-pressed":n===h.key,onClick:()=>vt(h.key),children:h.name},h.key)),!z&&s.jsx(Fa,{...jt},`filters:${t}:${$e}`),s.jsxs("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-x-3 gap-y-2",children:[s.jsx(Aa,{label:M,search:k.search,onSearch:(h,_)=>re({...k,search:h},_),className:"w-64 max-w-full"},`search:${t}:${$e}`),!q&&!n?s.jsxs(R,{size:"sm","aria-label":`Add ${M||"entity"}`,onClick:()=>st(),children:[s.jsx(kn,{className:"mr-2 h-4 w-4"}),"Add"]}):null]})]}),!de&&S&&!z?s.jsx(Da,{...jt},`applied:${t}:${$e}`):null]}),children:de?null:_s?at?s.jsx(Zt,{label:`Loading ${M} graph`}):s.jsx(ea,{}):lt?s.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[lt.message||`Failed to load ${M.toLowerCase()}.`,z&&s.jsx(R,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>re({}),children:"Clear filters"})]}):ks?s.jsx(ss,{onRetry:()=>void P.refetch()}):Te?s.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"inapplicable-view",children:[s.jsxs("h2",{className:"text-lg font-semibold",children:["“",Te.view.name,"” doesn’t apply to the current filters"]}),s.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["It appears when the selection includes"," ",Object.entries(Te.when).map(([h,_])=>`${h} is ${_===null?"not supplied":String(_)}`).join(" and "),"."]}),s.jsx(ke,{to:b,search:G,className:"mt-4 text-sm font-medium underline underline-offset-4",children:`Back to ${M}`})]}):ot?s.jsx(ns,{viewKey:ot,backTo:b,backLabel:`Back to ${M}`}):Y?s.jsx(as,{orgSlug:e,viewKey:Y.key,scope:{type:t,collection:k},params:Fe,onParamsChange:hs,paramDecls:Y.params,contentHash:Y.content_hash,title:Y.name,minHeight:320}):at&&ct?s.jsx(Qa,{ownerSlug:e,typeSlug:t,sourceBacked:J,records:B.map(h=>({...h,id:h.id??JSON.stringify([h.entity_type,h.slug])})),hasMore:Ae}):ct?s.jsx(da,{template:Rs,data:Ls,actions:Ts,components:xr}):s.jsx(Vt,{icon:Cn,iconElement:s.jsx(Jt,{icon:o?.icon,className:"mb-4 h-12 w-12 opacity-50"}),title:`No ${M.toLowerCase()} yet`,description:q?"This view has no rows yet. They appear as the underlying data arrives.":`Get started by creating your first ${o?.name?.toLowerCase()||"entity"}.`,actionLabel:q?void 0:`Add ${o?.name||"Entity"}`,onAction:q?void 0:()=>st()})})}function wr(e,t){return ie("inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",t,e?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground")}const Er=12,kr=50;function _r({navigation:e,views:t,currentKey:r}){const l=ne(),[n,d]=x.useState(""),i=x.useMemo(()=>e.filter(c=>!c.external&&c.href.includes("/-/views/")),[e]),a=Mn(i,t,n,n.trim()?kr:Er),u=On(i,t,n),o=c=>{c.key==="Enter"&&a[0]&&(c.preventDefault(),l({href:a[0].href}))};return s.jsxs("nav",{"aria-label":"Workspace views",className:"flex shrink-0 flex-col gap-2",children:[s.jsx(se,{type:"search","aria-label":"Find a view",placeholder:"Find a view",value:n,onChange:c=>d(c.target.value),onKeyDown:o,className:"h-8 max-w-sm"}),a.length>0?s.jsx("ul",{className:"flex flex-wrap items-center gap-1",children:a.map(c=>{const m=c.key===r;return s.jsx("li",{children:s.jsxs(Tn,{item:{id:c.key,label:c.label,href:c.href,children:[]},active:m,className:wr(m,"min-h-8 max-w-full gap-2 px-3 text-sm break-words"),children:[s.jsx("span",{children:c.label}),c.trail.length>0&&c.trail[0]!=="Views"?s.jsx("span",{className:"ml-1.5 text-xs text-muted-foreground",children:c.trail.join(" › ")}):null]})},c.key)})}):s.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["No view matches “",n.trim(),"”."]}),u>a.length?s.jsxs("p",{role:"status",className:"text-xs text-muted-foreground",children:["Showing ",a.length," of ",u,". Type to narrow the list."]}):null]})}function $r({ownerSlug:e,typeScope:t,create:r,viewKey:l,shape:n}){const d=ne(),i=Qt({strict:!1}),a=t?In(t):void 0,u=a==="$member",o=m=>{if(!a)return;const p=Hn(e,a);d({to:p.to,params:p.params,search:m?{create:!0}:{},replace:!0})},c=a?s.jsx(Cr,{ownerSlug:e,entityTypeSlug:a,create:r,onCreateChange:o,viewKey:l,shape:n}):l?s.jsx(Rr,{ownerSlug:e,viewKey:l,search:i}):null;return s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:u?s.jsx(va,{children:c}):c})}function Rr({ownerSlug:e,viewKey:t,search:r}){const l=ne(),{orgContext:n}=Ee(),{data:d,isError:i,error:a,refetch:u}=Kt(n),o=An(n),c=Pn(e,`/${e}/data`),m=Fn(d??[],t),p=Dn(),f=Vn(d??[]),y=i?Bn(a,{subject:"Views"}):null;if(d===void 0)return i?s.jsx(ss,{error:a,onRetry:()=>void u()}):null;if(m.kind==="missing")return s.jsx(ns,{viewKey:m.key,backTo:`/${e}`,backLabel:"Back to Home"});const N=qn(o.data??[]),v=f.some(b=>!N.has(`/${e}/data${Je(b.key)}`)),w=f.length>0&&(p||o.data!==void 0&&v);return s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:[w?s.jsx(_r,{navigation:c.navigation,views:c.views,currentKey:Un(`/${e}/data${Je(t)}`,r)}):null,p&&y?s.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:[y.title,"."," ",y.retryable?s.jsx("button",{type:"button",onClick:()=>void u(),className:"underline underline-offset-4",children:"Retry"}):null]}):null,s.jsx(ba,{decls:m.view.params,params:K(r),onParamsChange:b=>void l({to:".",search:C=>Ge(C,b)})}),s.jsx(as,{orgSlug:e,viewKey:m.view.key,scope:{},params:K(r),onParamsChange:b=>void l({to:".",search:C=>Ge(C,b),replace:!0}),paramDecls:m.view.params,contentHash:m.view.content_hash,title:m.view.name,minHeight:400})]})}function qr({ownerSlug:e,typeScope:t,create:r,viewKey:l,shape:n}){return s.jsxs(zn,{inset:l?"flush":"page",className:l?"gap-0 pt-0 pb-0":"gap-6 pt-2.5 pb-8",children:[s.jsx(Jn,{}),s.jsx(Gn,{owner:e,children:d=>s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:s.jsx($r,{ownerSlug:d.ownerSlug,typeScope:t,create:r,viewKey:l,shape:n})})})]})}export{qr as M};
74
- //# sourceMappingURL=memory-browse-page-Ba4aYavw.js.map
@@ -1,2 +0,0 @@
1
- import{dp as s,G as n,c as r,j as t,ar as p,as as i}from"./index-CdDNNAx2.js";import{E as m}from"./entity-type-page-MgZ7_0oh.js";import"./event-kind-options-fHAIXu24.js";import"./code-editor-BdRMYojw.js";import"./index-Vcq4gwWv.js";function y(){const{owner:e}=s.useParams(),{orgContext:a}=n(),o=r();return t.jsx(p,{className:"gap-4 pt-2.5 pb-8",children:t.jsx(i,{children:t.jsx(m,{entityType:null,orgContext:a,onClose:()=>{o({to:"/$owner",params:{owner:e},search:{layout:"graph"}})}})})})}export{y as component};
2
- //# sourceMappingURL=new-BOsrRqp8.js.map
@@ -1,2 +0,0 @@
1
- import{c as R,z as U,Q as F,r,j as e,T as v,U as S,B as L,V as N,W as E}from"./index-CdDNNAx2.js";import{C as T,a as A,b as I,c as k}from"./card-C01y1O-W.js";import{F as B}from"./full-page-spinner-DWo519BU.js";function c(l){return l.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function H(){const l=R(),{session:u,isReady:d}=U(),{slug:n,name:i}=F.useSearch(),[m,y]=r.useState(i||n||""),[g,h]=r.useState(n||(i?c(i):"")),[b,C]=r.useState(!!n),[x,o]=r.useState(null),[f,p]=r.useState(!1),j=r.useRef(!1);if(r.useEffect(()=>{if(!d||u||j.current)return;j.current=!0;const a=new URL("/orgs/new",window.location.origin);n&&a.searchParams.set("slug",n),i&&a.searchParams.set("name",i);const s=new URL("/auth/login",window.location.origin);s.searchParams.set("callbackUrl",`${a.pathname}${a.search}`),window.location.assign(s.toString())},[d,u,n,i]),!d||!u)return e.jsx(B,{});const P=a=>{const s=E(a);if(s.kind==="cross-host"){window.location.assign(s.href);return}l({to:s.to})},z=async a=>{a.preventDefault(),o(null);const s=m.trim(),w=(g.trim()||c(s)).trim();if(!s){o("Name is required");return}if(!w){o("Slug is required");return}p(!0);try{const t=await N.create({name:s,slug:w});if(t.error){o(t.error.message||"Failed to create organization");return}t.data&&(await N.setActive({organizationId:t.data.id}),P(t.data.slug))}catch(t){o(t instanceof Error?t.message:"An error occurred")}finally{p(!1)}};return e.jsx("div",{className:"container mx-auto max-w-md px-4 py-10",children:e.jsxs(T,{children:[e.jsx(A,{children:e.jsx(I,{children:"Create organization"})}),e.jsx(k,{children:e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[x&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:x}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(v,{htmlFor:"org-name",children:["Name",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(S,{id:"org-name",value:m,onChange:a=>{y(a.target.value),b||h(c(a.target.value))},placeholder:"Acme Inc.",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(v,{htmlFor:"org-slug",children:["Slug",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(S,{id:"org-slug",value:g,onChange:a=>{C(!0),h(c(a.target.value))},placeholder:"acme"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Used in URLs and as the org id in ",e.jsx("code",{children:"lobu.toml"}),". Lowercase letters, numbers, and hyphens."]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(L,{type:"submit",disabled:f,children:f?"Creating…":"Create organization"})})]})})]})})}export{H as component};
2
- //# sourceMappingURL=new-DGPOjak2.js.map
@@ -1,2 +0,0 @@
1
- import{i7 as o,c as l,ad as x,z as h,n as b,s as w,j as a,ar as j,as as A,dt as L,be as f,dv as C,L as N,dw as S,dy as y,bd as k,c9 as E}from"./index-CdDNNAx2.js";import{A as O}from"./agent-editor-form-Bnc_q5WD.js";import"./definition-comparison-BUDNuAN_.js";import"./json-diff-C-WQqyIf.js";import"./code-editor-BdRMYojw.js";import"./index-Vcq4gwWv.js";import"./schema-value-k19Ata7u.js";import"./model-selector-XYmk7Iru.js";function W(){const{owner:e}=o.useParams(),t=o.useSearch(),r=l(),i=x(),{isAuthenticated:c}=h(),{isMember:m,isLoading:g}=b(),n=c&&m,{data:d=[],isLoading:u}=w({enabled:n});return a.jsx(j,{className:"gap-3 pt-2.5 pb-8",children:a.jsxs(A,{className:"flex flex-1 flex-col gap-6",children:[a.jsx(L,{breadcrumb:a.jsx(C,{crumbs:[a.jsx(N,{to:"/$owner",params:{owner:e},search:{section:"agent"},className:S,children:"Agents"},"agents")]}),icon:a.jsx(f.agents.icon,{className:"h-6 w-6"}),title:"Build a managed agent",caption:"Create an agent that Lobu runs and manages for this workspace."}),g||n&&u?a.jsx(y,{rows:1}):n?a.jsx(O,{mode:{kind:"create"},existingAgentIds:d.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(k,{icon:E,title:"Workspace membership required",description:"Only workspace members can build managed agents."})]})})}export{W as component};
2
- //# sourceMappingURL=new-Q0XqiZq2.js.map
@@ -1,2 +0,0 @@
1
- import{ad as ge,r as v,bN as Ie,bO as Be,bP as Ke,bQ as Me,bR as be,j as e,bS as Y,B as N,bT as Ve,bd as Ue,bU as Ge,bV as He,bW as Ye,bX as Je,bY as Ze,bZ as Xe,b_ as es,b$ as ve,bz as ie,c0 as ss,c1 as ts,c2 as ns,c3 as me,c4 as is,c5 as as,c as os,a8 as We,G as rs,c6 as cs,c7 as ne,c8 as ls,T as je,U as Ne,c9 as ds,ca as us,cb as ms,ai as Ce,cc as hs,m as z,V as le,cd as ps,ce as _e,cf as ke,cg as gs,W as xs,ch as Se,ar as fs,as as ys,S as bs,i as vs,ci as js}from"./index-CdDNNAx2.js";import{P as he,a as De,A as Ns}from"./agent-permissions-matrix-C_ayr0pd.js";import{C as we,a as Ae,b as Oe,c as ze}from"./card-C01y1O-W.js";const Pe=["auto","approval","deny"],Cs={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."},Le={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:a,children:c,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:r=>a(r.target.value),disabled:h,className:"h-9 w-full rounded-lg border bg-background px-2 text-foreground",children:c})]})}function _s(s,n){const a=n.connections?.find(c=>c.id===s.connection_id);return s.connection_id?`Connection: ${a?.display_name||a?.connector_key||"Unavailable"} (#${s.connection_id})`:s.connector_key?`Connector: ${n.connectors?.find(c=>c.key===s.connector_key)?.name||s.connector_key}`:"All connectors"}function ks(s,n){return s.operation_key?n.connector_operations.find(a=>a.operation_key===s.operation_key)?.name||s.operation_key:s.operation_category?Le[s.operation_category]:"All actions"}function ue(s,n){return`${_s(s,n)} · ${ks(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 Ss({label:s,ariaLabel:n,disabled:a,onRemove:c}){const[h,r]=v.useState(!1);return h?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(N,{type:"button",variant:"destructive",size:"sm",disabled:a,"aria-label":"Confirm removal",onClick:async()=>{await c()&&r(!1)},children:"Confirm"}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",disabled:a,onClick:()=>r(!1),children:"Cancel"})]}):e.jsx(N,{type:"button",variant:"ghost",size:"sm",disabled:a,"aria-label":n,onClick:()=>r(!0),children:s})}function ws({owner:s,connector:n,connection:a,agent:c}){const h=ge(),[r,y]=v.useState(c??""),C=Ie(s),l=C.data,u=l?.agents.some(t=>t.id===r)?r:"",m=Be(s,u),i=Ke(s,!u),[P,_]=v.useState(a?`connection:${a}`:n?`connector:${n}`:"all"),[M,J]=v.useState(P),[I,W]=v.useState(!1),[k,D]=v.useState(""),[A,V]=v.useState("all"),[Z,E]=v.useState("approval"),[g,S]=v.useState(!1),[L,T]=v.useState(null),[U,X]=v.useState(a?String(a):""),[G,Q]=v.useState(""),R=l?.connections?.some(t=>String(t.id)===U)?U:"",w=Me(s,R?Number(R):void 0,G,u||void 0);async function H(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=C.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 b=t=>t==="all"||l.connectors?.some(f=>`connector:${f.key}`===t)||l.connections?.some(f=>`connection:${f.id}`===t)?t:"all",o=b(P),p=b(M),j=l.connections?.find(t=>`connection:${t.id}`===p),$=j?.connector_key??(p.startsWith("connector:")?p.slice(10):void 0),x=t=>p==="all"||Ee(t)==="all"?!0:t.connection_id?j?t.connection_id===j.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=o.startsWith("connector:")?o.slice(10):o.startsWith("connection:")?l.connections?.find(t=>t.id===Number(o.slice(11)))?.connector_key:void 0,O=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:o.startsWith("connector:")?o.slice(10):o==="all"&&A==="specific"?O.find(t=>t.operation_key===k)?.connector_key??null:null,connection_id:o.startsWith("connection:")?Number(o.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"),D(""),E("approval"),W(!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(De,{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 H(d,ce)}),K&&e.jsx(Ss,{label:"Remove",disabled:g,ariaLabel:`Remove rule: ${ue(d,l)}`,onRemove:()=>H(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!==r)&&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:y,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(N,{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)&&H(Qe,Z).then(f=>{f&&(W(!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:o,onChange:t=>{_(t),V("all"),D("")},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:Le[t]},t))}),e.jsx("option",{value:"specific",children:"Specific action"})]})]}),A==="specific"&&e.jsxs(F,{label:"Specific action",value:k,onChange:D,disabled:g,children:[e.jsx("option",{value:"",children:"Choose action"}),O.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:()=>W(!1),cancelDisabled:g,children:e.jsx(N,{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(Ue,{icon:Ge,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})]}),L&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:L}),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:G,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:G?w.isPending?"Checking…":w.data?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:He[w.data.effect]})," ·"," ",Cs[w.data.reason]??"The server evaluated this action.",w.data.rule_ids.length>0?` · Rules ${w.data.rule_ids.map(t=>`#${t}`).join(", ")}`:""]}):"":""})]})]})}const As=[{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."}],Os=[{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 zs(s){return s.agent.find(xe)}function Ps(s,n){return{...s,agent:[...s.agent.filter(a=>!xe(a)),n]}}function $s(s){return{...s,agent:s.agent.filter(n=>!xe(n))}}function Es({label:s,description:n,action:a,value:c,pending:h,onChange:r}){return e.jsxs(De,{controls:e.jsx(he,{options:as("entity_schema",a),value:c,floor:"auto",disabled:h,compact:!0,ariaLabel:s,onChange:r}),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:a,pending:c,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:r,label:y,description:C})=>e.jsx(Es,{action:r,label:y,description:C,value:a[r]??me.entity_schema[r]??"deny",pending:c,onChange:l=>h(r,l)},r))})]})}function Ts({owner:s}){const n=ge(),a=es(s),c=Ie(s),h=ve({mutationFn:m=>ss(s,{resource_class:"entity_schema",effects:m}),onSuccess:m=>{n.setQueryData(a,i=>i&&Ps(i,m)),n.invalidateQueries({queryKey:a})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to save schema policy")}}),r=ve({mutationFn:()=>ts(s,{resource_class:"entity_schema"}),onSuccess:()=>{n.setQueryData(a,m=>m&&$s(m)),n.invalidateQueries({queryKey:a})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to reset schema policy")}});if(c.isLoading)return e.jsx(Y,{label:"schema policy",variant:"cards",cards:1});if(c.isError||!c.data)return e.jsx(ns,{label:"schema policy"});const y=zs(c.data),C=y?.effects??me.entity_schema,l=h.isPending||r.isPending,u=(m,i)=>{h.mutate({...y?.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:y?"Custom policy":"Workspace defaults"}),y?e.jsxs(N,{type:"button",variant:"outline",size:"sm",disabled:l,onClick:()=>r.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:As,effects:C,pending:l,onChange:u}),e.jsx(Re,{title:"Relationship types",actions:Os,effects:C,pending:l,onChange:u})]})]})}function Fe(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Rs(s,n,a){const c=s.split("/");return c[1]===n?(c[1]=a,c.join("/")||"/"):`/${a}`}function Fs({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(z,{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(z,{className:"h-4 w-32 rounded-none"})})]},n)),e.jsx(z,{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(z,{className:"mt-0.5 h-4 w-4 shrink-0 rounded-none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(z,{className:"h-4 w-16 rounded-none"}),e.jsx(z,{className:"h-3 w-full rounded-none"}),e.jsx(z,{className:"h-3 w-2/3 rounded-none"})]})]},n))})]}),e.jsxs("div",{"aria-hidden":"true",className:"flex justify-end gap-2",children:[e.jsx(z,{className:"h-9 w-20 rounded-none"}),e.jsx(z,{className:"h-9 w-28 rounded-none"})]})]})}function Is({owner:s,section:n="general",connector:a,connection:c,agent:h}){const r=os(),y=ge(),{data:C,error:l}=We(),{activeOrg:u,urlOrgSlug:m}=rs(),i=(C??[]).find(o=>o.slug===s&&o.is_member)??null,P=i?.id??s,_=cs(P,{name:i?.name??"",slug:i?.slug??"",visibility:i?.visibility??"private"}),[M,J]=_.field("name"),[I,W]=_.field("slug"),[k,D]=_.field("visibility"),[A,V]=ne(P,!!i),[Z,E]=ne(P,!1),[g,S]=ne(P,null),[L,T]=v.useState(!1),[U,X]=v.useState(!1),[G,Q]=ne(P,!1);if(ls(l)&&C===void 0)return e.jsxs(we,{role:"alert",children:[e.jsx(Ae,{children:e.jsx(Oe,{children:"Couldn't load organizations"})}),e.jsx(ze,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again in a moment."})})]});if(C===void 0)return e.jsx(Fs,{section:n});if(!i)return e.jsxs(we,{children:[e.jsx(Ae,{children:e.jsx(Oe,{children:"Organization not found"})}),e.jsx(ze,{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(ws,{owner:s,connector:a,connection:c,agent:h},`${s}:${h??""}:${a??""}:${c??""}`)]})});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(Ns,{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(Ts,{owner:s})]})]});const R=o=>{const p=xs(o);if(p.kind==="cross-host"){window.location.assign(p.href);return}r({to:p.to})},w=o=>{if(o==="public"&&i.visibility!=="public"){E(!0);return}D(o),E(!1)},H=async()=>{if(!_.canSubmit)return;const o=M.trim();if(!o){S("Name is required");return}const p=I.trim()||Fe(o);if(!p){S("Slug is required");return}T(!0),S(null);try{const j=o!==i.name||p!==i.slug,$=k!==i.visibility;let x=i.slug;if(j){const O=await le.update({organizationId:i.id,data:{name:o,slug:p}});if(O.error){S(O.error.message||"Failed to update organization");return}x=O.data?.slug??p}$&&(x=(await ps(x,k)).slug),(j||$)&&(_.accept(_.values,{name:o,slug:x,visibility:k}),await y.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization updated"));const B=u?.id===i.id||m===i.slug,ee=x!==i.slug;if(B&&ee){const O=_e(),se=ke();if(O===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=Rs(window.location.pathname,i.slug,x);r({to:`${ae}${window.location.search}${window.location.hash}`});return}}catch(j){S(j instanceof Error?j.message:"Failed to update organization")}finally{T(!1)}},q=async()=>{X(!0),S(null);try{const o=await le.delete({organizationId:i.id});if(o.error){S(o.error.message||"Failed to delete organization");return}await y.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization deleted");const j=(C??[]).filter(x=>x.is_member).find(x=>x.id!==i.id)??null,$=u?.id===i.id||m===i.slug;if($&&j){await le.setActive({organizationId:j.id}),R(j.slug);return}if($){const x=_e(),B=ke();if(x===i.slug&&B){window.location.assign(`${window.location.protocol}//app.${B}/`);return}r({to:"/"});return}r({to:"/"})}catch(o){S(o instanceof Error?o.message:"Failed to delete organization")}finally{X(!1),Q(!1)}},b=L||U;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:o=>{J(o.target.value),A||W(Fe(o.target.value))},placeholder:"e.g. My Team",disabled:b})]}),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:o=>{V(!0),W(o.target.value)},placeholder:"e.g. my-team",disabled:b}),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:b,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:b,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(N,{type:"button",size:"sm",onClick:()=>{D("public"),E(!1)},disabled:b,children:"Confirm public"}),e.jsx(N,{type:"button",size:"sm",variant:"ghost",onClick:()=>E(!1),disabled:b,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(N,{variant:"outline",onClick:()=>void r({to:`/${s}`}),disabled:b,children:"Cancel"}),e.jsxs(N,{onClick:H,disabled:b||!_.canSubmit,children:[L?e.jsx(Ce,{size:"lg",className:"mr-1.5"}):null,L?"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:G?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(N,{variant:"destructive",size:"sm",onClick:q,disabled:b,children:[U?e.jsx(Ce,{className:"mr-1.5"}):null,"Confirm delete"]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>Q(!1),disabled:b,children:"Cancel"})]}):e.jsxs(N,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>Q(!0),disabled:b,children:[e.jsx(hs,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete organization"]})})]})]})}function Qs(){const{owner:s}=Se.useParams(),n=Se.useSearch(),a=n.section??"general",c={general:"General",policies:"Policies",governance:"Governance"}[a],{data:h}=We(),r=(h??[]).find(y=>y.slug===s&&y.is_member)?.name;return e.jsx(fs,{className:"pt-2.5 pb-8",children:e.jsxs(ys,{className:vs("flex flex-1 flex-col gap-6",js(a)),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bs,{className:"h-7 w-7"}),e.jsx("h1",{className:"text-3xl font-semibold leading-tight",children:c})]}),r?e.jsx("p",{className:"text-base font-medium text-foreground",children:r}):null]}),e.jsx(Is,{owner:s,...n,section:a})]})})}export{Qs as component};
2
- //# sourceMappingURL=organization-hD_Z6TSd.js.map
@@ -1,2 +0,0 @@
1
- import{j as e,el as de,jV as z,jW as ue,jX as ee,jY as me,jZ as pe,r as g,j_ as xe,u as D,aV as he,cO as fe,m as $,iC as ge,jq as ye,B as w,j$ as je,k0 as K,k1 as ve,dZ as Ne,k2 as ke,y as L,ai as R,ax as te,cu as se,G as ne,dr as we,bS as be,c2 as Ae,ds as Ce,cN as Se,x as Ie,gh as $e,H as Le,L as H,k3 as Re,cS as Te,gk as Pe,db as _e,k4 as Ee,gr as G,fn as Oe,aT as ze,k5 as De,n as Me,w as Fe,gG as Be,eY as Ke,fl as He,fo as Ve,fu as E,p as Ue,k6 as We,k7 as qe,ex as Ge,k8 as Ye,f2 as Ze,a7 as Qe,k9 as Xe,A as Je,ka as et}from"./index-CdDNNAx2.js";import{b as re,u as tt,a as st,A as nt}from"./automation-run-now-CjkJIkaZ.js";import{A as rt}from"./agent-loading-shells-xteN-pyK.js";import{s as it,h as at,R as ot,A as ct}from"./agent-thread-Bv_chdPy.js";import{C as lt,a as dt,c as ut,A as mt}from"./connection-feed-detail-CJju0qiw.js";import{O as pt}from"./connect-menu-D4w-JhJW.js";import{E as T,R as xt,b as ht,s as Y,p as Z,e as ft,f as gt}from"./events-feed-BI7wNRUY.js";import{S as yt}from"./source-record-panels-C4UItfdk.js";import{E as Q}from"./entity-type-page-MgZ7_0oh.js";import{c as jt,s as vt,k as Nt}from"./renderer-DZ0w2k2r.js";import{E as kt}from"./event-detail-D6AH6a2C.js";import{V as wt,R as bt}from"./views-access-required-CvIIxdS_.js";import{V as At,a as Ct}from"./view-param-filters-BdN8OU35.js";import{S as St,g as It}from"./status-variants-BR_iGWN5.js";import{a as $t}from"./runs-CuC7WMtd.js";import{a as ie}from"./use-automations-CdtiVLCv.js";import"./needs-you-list-Bd4iiiqm.js";import"./scoped-feed-bar-L7h-Ca4u.js";import"./event-kind-options-fHAIXu24.js";import"./filter-editors-DDTwyYt0.js";import"./subDays-hOwerOLo.js";import"./create-automation-form-D141prEG.js";import"./entity-options-CpeX7iiX.js";import"./device-automation-Dp3faMvp.js";import"./model-selector-XYmk7Iru.js";import"./skill-editor-D_W3QlRz.js";import"./code-editor-BdRMYojw.js";import"./index-Vcq4gwWv.js";import"./json-diff-C-WQqyIf.js";import"./use-mention-search-CtbixPEE.js";import"./proposal-review-shell-BWRJidwb.js";import"./definition-comparison-BUDNuAN_.js";import"./schema-value-k19Ata7u.js";import"./runs-list-8gUPWjP4.js";import"./run-initiator-B8IRlRd-.js";import"./list-skeleton-0B1bTrAK.js";import"./clients-BCvjAJDT.js";import"./app-bridge-C4nPtae3.js";import"./pending-seed-D7-ld7as.js";import"./feed-event-kinds-BYuZCoU4.js";import"./copy-button-BhXeXLIm.js";import"./card-C01y1O-W.js";import"./table-C3DMoL4K.js";import"./dynamic-schema-form-OkIZImgp.js";import"./record-session-ClKBr1_C.js";function Lt(t){if(!t||typeof t!="object")return[];const s=t.properties;if(!s)return[];const r=Array.isArray(t.required)?new Set(t.required.map(String)):new Set;return Object.entries(s).map(([n,i])=>({name:n,type:String(i.type??"any"),required:r.has(n),description:typeof i.description=="string"?i.description:void 0}))}function Rt({fields:t}){return t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No fields."}):e.jsx("ul",{className:"space-y-2",children:t.map(s=>e.jsxs("li",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("code",{className:"text-xs font-medium text-foreground",children:s.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:s.type}),s.required?e.jsx("span",{className:"text-[10px] font-medium text-amber-600 dark:text-amber-400",children:"required"}):null]}),s.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description}):null]},s.name))})}function M({item:t,hideHeading:s=!1}){const r=t.schemaSections;return r?e.jsxs("article",{className:s?"space-y-4":"space-y-4 px-5 py-5",children:[!s&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(de,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h2",{className:"text-base font-medium text-foreground",children:t.title}),r.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:r.description}):null]})]}),r.sections.map(n=>{const i=Lt(n.schema);return e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n.title}),n.description?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:n.description}):null]}),e.jsx(Rt,{fields:i})]},n.title)})]}):null}function Tt({actions:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,action:i}});return e.jsx(z,{entries:s,label:"actions",renderDetail:({name:r,action:n})=>e.jsx(M,{hideHeading:!0,item:{href:"",title:r,schemaSections:ee(n)}})})}function Pt({feeds:t}){const s=Object.entries(t).map(([r,n])=>{const i=n;return{id:r,name:i.name??r,description:i.description,feed:i}});return e.jsx(z,{entries:s,label:"feed types",renderDetail:({name:r,feed:n})=>e.jsx(M,{hideHeading:!0,item:{href:"",title:r,schemaSections:ue(n)}})})}function _t(t){const s=[];return t.forEach((r,n)=>{s.push({id:`sep:${r.runId}`,role:"system",parts:[{type:"text",text:Et(r,n)}],createdAt:r.completedAt?new Date(r.completedAt).getTime():void 0});for(const i of r.messages)s.push({...i,id:`r${r.runId}:${i.id}`})}),s}function Et(t,s){const r=(t.pendingActionCount??0)>0?`Waiting for you (${t.pendingActionCount})`:t.status==="completed"?"Completed":t.status??"Completed",n=(t.autoAppliedCount??0)>0?` · ${t.autoAppliedCount} applied automatically`:"",i=t.completedAt?new Date(t.completedAt).toLocaleString():null;return i?`Run ${s+1} · ${r}${n} · ${i}`:`Run ${s+1} · ${r}${n}`}const ae=Symbol("trusted-automation-interaction");function Ot(t){return Object.defineProperty(t,ae,{value:!0}),t}function zt(t){return{title:`${t} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${t} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${t} proposals.`},{id:"reject-all",label:"Reject all",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${t} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${t} proposals.`}]}}const Dt=new Set(["automation-approval-batch"]);function Mt(t){return new Promise(s=>{t({onSettled:(r,n)=>s(!!n)})})}function Ft(){const t=me(),s=pe();return g.useMemo(()=>({toolNames:Dt,resolve:(r,n)=>{if(!n||typeof n!="object"||n[ae]!==!0)return null;const i=n;if(r==="automation-approval-batch"){const o=typeof i.runId=="number"&&Number.isSafeInteger(i.runId)&&i.runId>0?i.runId:null,c=typeof i.count=="number"&&Number.isSafeInteger(i.count)&&i.count>1?i.count:null,a=Array.isArray(i.runIds)?i.runIds.filter(d=>typeof d=="number"&&Number.isSafeInteger(d)&&d>0):[];return o===null||c===null||a.length!==c||new Set(a).size!==c?null:{view:zt(c),handlers:{manage_operations:d=>d.action!=="approve"&&d.action!=="reject"?Promise.resolve(!0):Mt(p=>d.action==="approve"?t.mutate({run_id:o,run_ids:a},p):s.mutate({run_id:o,run_ids:a},p))}}}return null}}),[t,s])}const Bt=/(?:^|\n)Run this Automation now/;function Kt(t){return t.role==="user"&&t.parts.some(s=>s.type==="text"&&Bt.test(s.text))}function Ht(t){return`history-interaction:${t.runId}:${t.eventId??"error"}`}function Vt({agentId:t,automationId:s,ownerSlug:r,runId:n}){const{data:i,isLoading:o}=xe(t,s,{orgSlug:r,...n!=null?{runId:n}:{}}),c=Ft(),a=D(),d=g.useCallback(m=>{a?.open({href:`/${r}/automations/${s}?view=activity&run_id=${m}`,title:`Automation run #${m}`,runId:m})},[a,r,s]),p=g.useMemo(()=>{const m=i?.runs??[],b=(n!=null?m.filter(x=>x.runId===n):m).slice().reverse();return _t(b.map(x=>{const y=x.messages.map(u=>it(u,{showToolCalls:!0})).filter(u=>u!==null&&!Kt(u));x.task?.trim()&&y.unshift({id:"task",role:"user",parts:[{type:"text",text:x.task.trim()}]});const N=x.actions??[],j=N.filter(u=>u.status==="pending");if(j.length>1){const u=j.map(h=>h.runId).sort((h,C)=>h-C);y.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${x.runId}`,toolName:"automation-approval-batch",args:Ot({runId:x.runId,count:j.length,runIds:u})}]})}for(const u of N){const h=at([u],{workspaceSlug:r,agentId:t,webOrigin:typeof window>"u"?null:window.location.origin});h&&y.push({...h,id:Ht(u)})}return{runId:x.runId,completedAt:x.completedAt,status:x.status,pendingActionCount:x.pendingActionCount,autoAppliedCount:x.autoAppliedCount,messages:y}}))},[t,i,r,n]);return o?e.jsx(rt,{readOnly:!0}):p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):e.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:e.jsx(ot,{messages:p,workspaceSlug:r,children:e.jsx(ct,{readOnly:!0,readerPositionMode:"runs",interactionExtension:c,onRunSelect:n==null&&a?d:void 0})})})}function Ut({panel:t}){const s=he(t.organizationId),r=t.section==="connections"||!!t.connectionId,n=fe(t.organizationId,{connectorKey:t.connectorKey,connectionIds:t.connectionId?[t.connectionId]:void 0,enabled:r}),i=s.data?.find(c=>c.key===t.connectorKey),o=n.data?.find(c=>c.id===t.connectionId&&c.connector_key===t.connectorKey);return s.isLoading||r&&n.isLoading?e.jsx("div",{className:"p-5",children:e.jsx($,{className:"h-28 w-full"})}):s.isError||r&&n.isError?e.jsx("p",{role:"alert",className:"p-5 text-sm",children:"Could not load this connector. Close the pane and try again."}):t.connectionId&&!o||!i&&!o&&t.section!=="connections"?e.jsx("p",{className:"p-5 text-sm",children:"This connection is no longer available."}):e.jsx("div",{className:"p-5",children:t.section==="connections"?e.jsx(ge,{connections:n.data??[],connector:i,connectorKey:t.connectorKey,ownerSlug:t.ownerSlug}):o&&t.section==="data"?e.jsx(lt,{connection:o,ownerSlug:t.ownerSlug}):o?e.jsx(Gt,{connection:o,connector:i,panel:t}):i?t.section==="oauth-apps"?e.jsx(pt,{connector:i,organizationId:t.organizationId,newApp:!!t.newApp}):t.section==="feeds"?e.jsx(Wt,{connector:i}):i.installed===!1?e.jsx(qt,{connector:i,ownerSlug:t.ownerSlug}):e.jsx(Zt,{connector:i,ownerSlug:t.ownerSlug}):null},`${t.connectorKey}:${t.connectionId??"connector"}:${t.section}`)}function Wt({connector:t}){return e.jsx(Pt,{feeds:t.feeds_schema??{}})}function qt({connector:t,ownerSlug:s}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection."," ",e.jsx(K,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(Tt,{actions:t.actions_schema??{}})]})}function Gt({connection:t,connector:s,panel:r}){const[n,i]=g.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:n,children:r.section==="feeds"?e.jsx(Yt,{connection:t,connector:s,ownerSlug:r.ownerSlug}):e.jsx(ye,{connection:t,ownerSlug:r.ownerSlug,inPeek:!0,onReviewPermissions:s?()=>i(!0):void 0})}),n&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>i(!1),children:"Back to actions"}),e.jsx("h2",{className:"text-base font-semibold",children:"Provider permissions"}),e.jsx(je,{connection:t,connectorDef:s})]})]})}function Yt({connection:t,connector:s,ownerSlug:r}){const{data:n=[],isLoading:i,isError:o}=Ne(t.id),[c,a]=g.useState(!1),d=t.facets?.chat??!1;if(i)return e.jsx($,{className:"h-28 w-full"});if(o)return e.jsx("p",{role:"alert",children:"Could not load sources. Close the pane and try again."});const p=n.map(m=>({id:String(m.id),name:m.display_name||m.feed_key,status:ke(m)??(m.operations.includes("sync")?"Sync enabled":"Live access"),feed:m}));return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:c,children:e.jsx(z,{entries:p,label:d?"channels":"feeds",action:Object.keys(s?.feeds_schema??{}).length>0?e.jsx(w,{size:"sm",variant:"outline",onClick:()=>a(!0),children:d?"Add channel":"Add feed"}):void 0,renderDetail:({feed:m})=>m.store==="channel_messages"?e.jsx(dt,{feed:m,hideHeader:!0}):e.jsx(ut,{feed:m,connectorDef:s,ownerSlug:r})})}),c&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold",children:d?"Add channel":"Add feed"}),e.jsx(mt,{organizationId:t.organization_id,connections:[t],connectorDefinitions:[s],onClose:()=>a(!1)})]})]})}function Zt({connector:t,ownerSlug:s}){const{data:r=[],isLoading:n,isError:i}=ve(t.key);if(n)return e.jsx($,{className:"h-28 w-full"});if(i)return e.jsx("p",{role:"alert",children:"Could not load actions. Close the pane and try again."});const o=t.actions_schema??{},c=r.map(a=>({id:a.operation_key,name:a.name??a.operation_key,description:a.description,operation:a}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection. Click an action to inspect its inputs."," ",e.jsx(K,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(z,{entries:c,label:"actions",renderControl:()=>e.jsx(K,{ownerSlug:s,connectorKey:t.key}),renderDetail:({operation:a,name:d})=>o[a.operation_key]?e.jsx(M,{hideHeading:!0,item:{href:"",title:d,schemaSections:ee(o[a.operation_key])}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No input fields."})})]})}function Qt({owner:t,name:s,agentId:r,clientIds:n}){const{data:i,isLoading:o}=L(t==="me"?null:t,{slug:t}),c=i?.workspace,a=t!=="me"&&c?.type==="organization"?c.id:null,d=n?.join(",")??"",p=g.useMemo(()=>({sortBy:"date",sortOrder:"desc",...r?{agentId:r}:{clientIds:d.split(",").filter(Boolean)}}),[r,d]);return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):e.jsx("div",{className:"space-y-3 px-4 py-4",children:e.jsx(T,{organizationId:a,ownerSlug:t,filters:p,hideOriginator:!0,groupStretches:!0,emptyState:e.jsxs("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:["No activity from ",s," yet."]})})})}function Xt({owner:t,path:s}){const{data:r,isLoading:n}=L(t,{slug:t}),i=r?.workspace,o=i?.type==="organization"?i.id:null,c=o?{slug:t}:void 0,{data:a,isLoading:d}=te(`/${t}/${se(s)}`,c),p=a?.entity,m=p?.id;return n||d?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):o?m==null?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't find this record. It may have been deleted, or it may live in a workspace you can't access."}):p?.is_derived?e.jsx(yt,{record:{type:p.entity_type,key:p.slug},orgContext:c}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(T,{organizationId:o,ownerSlug:t,entityId:typeof m=="number"?m:void 0,filters:{sortBy:"date",sortOrder:"desc"},emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to this record yet."})})}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."})}function Jt({slug:t,onClose:s}){const{orgContext:r}=ne(),{data:n=[],isLoading:i,isError:o}=we(r);if(t===null)return e.jsx(Q,{entityType:null,orgContext:r,onClose:s,compact:!0});if(i)return e.jsx(be,{label:"entity type",variant:"panel"});if(o)return e.jsx(Ae,{label:"entity type"});const c=n.find(a=>a.slug===t)??null;return c?e.jsx(Q,{entityType:c,orgContext:r,hideDelete:Ce(c),onClose:s,compact:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Entity type not found."})}function es(t){if(Array.isArray(t.enum))return`One of ${t.enum.length}`;if(t.format==="date"||t.format==="date-time")return"Date";if(t.format==="uri")return"Link";if(t.format==="email")return"Email";const s=Array.isArray(t.type)?t.type[0]:t.type;return s==="array"?"List":s==="object"?"Group":s==="integer"||s==="number"?"Number":s==="boolean"?"Yes / no":"Text"}function ts({owner:t,typeSlug:s,view:r}){const{data:n,isLoading:i}=L(t,{slug:t}),o=n?.workspace,c=o?.type==="organization"?o.id:null,{isAdmin:a}=Se(c??void 0),{orgContext:d}=ne(),{data:p,isSuccess:m}=Ie(d),v=(p??[]).find(A=>A.slug===s),b=m&&!v,x=`/${t}/${$e(s)}`,{pathname:y}=Le(),N=y===x||y===`${x}/`||y.startsWith(`${x}/-/`),j=g.useMemo(()=>jt(v?.metadata_schema),[v?.metadata_schema]),u=D(),h=u?.close;g.useEffect(()=>{b&&h?.()},[b,h]);const C=g.useMemo(()=>({entityTypes:[s],sortBy:"date",sortOrder:"desc"}),[s]);if(i)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]});if(b)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This entity type no longer exists."});if(!c)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."});const P=v?.name??s;return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-2.5",children:[N?null:e.jsx(w,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(H,{...Te(t,s),children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),"Browse records"]})}),v&&!N&&!Pe(v)&&v.entity_count!==0?e.jsx(w,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs(H,{to:"/$owner/$entityType/-/$shape",params:{owner:t,entityType:s,shape:"graph"},search:Ee(G(t,s)),children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"}),"Graph"]})}):null,r!=="activity"&&u?e.jsxs(w,{type:"button",variant:"ghost",size:"sm",className:"ml-auto h-8 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>u.open({href:G(t,s,"activity"),title:`${P} activity`}),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Activity"]}):null]}),r==="activity"?e.jsx("div",{className:"px-4 py-4",children:e.jsx(T,{organizationId:c,ownerSlug:t,filters:C,showEntityLinks:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to these records yet."})})}):a?e.jsx("div",{className:"p-4",children:e.jsx(Jt,{slug:s,onClose:()=>h?.()})}):j.length>0?e.jsxs("section",{"aria-labelledby":"entity-type-peek-fields",className:"px-4 py-4",children:[e.jsx("h3",{id:"entity-type-peek-fields",className:"mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("dl",{className:"divide-y divide-border/60 text-sm",children:j.map(A=>e.jsxs("div",{className:"flex items-baseline justify-between gap-3 py-1.5",title:A.prop.description,children:[e.jsx("dt",{className:"min-w-0 truncate",children:vt(A)}),e.jsx("dd",{className:"shrink-0 text-xs text-muted-foreground",children:es(A.prop)})]},A.key))})]}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This type has no fields yet."})]})}function ss({owner:t,eventId:s,viewKey:r}){const n=D(),i=(o,c)=>e.jsx(kt,{owner:c,organizationId:o,eventId:s,viewKey:r,dense:!0,onSelectView:n?a=>n.retarget(a):void 0},`${c}/${s}/${r??""}`);return e.jsx("div",{className:"px-4 py-4",children:t==="me"?i(null,t):e.jsx(ze,{owner:t,children:({organizationId:o,ownerSlug:c})=>o?i(o,c):e.jsx("div",{className:"h-40 animate-pulse rounded-md bg-muted/40"})})})}function ns({owner:t,feedId:s,semanticTypes:r}){const{data:n,isLoading:i}=L(t==="me"?null:t,{slug:t}),o=n?.workspace,c=t!=="me"&&o?.type==="organization"?o.id:null,a=g.useMemo(()=>({feedIds:[s],...r?.length?{semanticTypes:r}:{},sortBy:"date",sortOrder:"desc"}),[s,r]);return t!=="me"&&i?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):c==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(T,{organizationId:c,ownerSlug:t,filters:a,showEntityLinks:!0,hideOriginator:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:r?.length===1?`No ${r[0]} events from this feed yet.`:"No matching events from this feed yet."})})})}function O({owner:t,runId:s,runIds:r,contentIds:n}){const{data:i,isLoading:o}=L(t==="me"?null:t,{slug:t}),c=i?.workspace,a=t!=="me"&&c?.type==="organization"?c.id:null,d=g.useMemo(()=>{if(t==="me")return n?.length?{contentIds:n,sortBy:"date",sortOrder:"desc"}:void 0;const m=r??(s!=null?[s]:void 0);if(!(!m?.length&&!n?.length))return{...m?.length?{runIds:m}:{},...n?.length?{contentIds:n}:{}}},[t,n,s,r]),p=d!=null;return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]}):t!=="me"&&a==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):p?e.jsx("div",{className:"px-4 py-4",children:e.jsx(T,{presentation:"detail",organizationId:a,ownerSlug:t,filters:d,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s!=null||r?.length?"No matching events from this run yet.":"No matching events yet."})})}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing to preview."})}const F=25;function rs({target:t}){const[s,r]=g.useState(0),{data:n,isLoading:i,isError:o,refetch:c}=De(t.entityId,t.orgContext,{relationshipType:t.relationshipType,limit:F,offset:s}),a=n?.total;return e.jsxs("div",{className:"space-y-3 px-5 py-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.label," · ",t.entityName,a!==void 0?` · ${a} current ${a===1?"link":"links"}`:n?` · ${n.rows.length} shown`:""]}),e.jsx(xt,{count:n?.failures?.length??0,onRetry:()=>void c()}),i?e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{className:"h-6 w-full"}),e.jsx($,{className:"h-6 w-full"})]}):o||!n?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load these links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void c(),children:"Retry"})]}):n.rows.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links on this page."}):e.jsx("ul",{className:"divide-y divide-border",children:n.rows.map(d=>e.jsx("li",{className:"flex items-center justify-between gap-3 py-1.5",children:e.jsx(ht,{row:d,entityId:t.entityId,ownerSlug:t.ownerSlug,orgContext:t.orgContext})},d.id))}),n&&(s>0||n.hasMore)?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(w,{type:"button",variant:"outline",size:"sm",disabled:s===0,onClick:()=>r(Math.max(0,s-F)),children:"Previous"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[n.rows.length," shown",a===void 0?"":` of ${a}`]}),e.jsx(w,{type:"button",variant:"outline",size:"sm",disabled:!n.hasMore,onClick:()=>r(s+F),children:"Next"})]}):null]})}function is({owner:t,path:s,viewKey:r}){const[n,i]=g.useState({}),{data:o,isLoading:c}=L(t,{slug:t}),a=o?.workspace,d=a?.type==="organization"?a.id:null,p=d?{slug:t,organizationId:d}:void 0,{data:m,isLoading:v}=te(`/${t}/${se(s)}`,p),{isMember:b,isPublic:x,isLoading:y}=Me(t),N=b||x,j=Fe({slug:t,organizationId:b?d:null}),u=m?.entity;if(c||v||y||N&&j.isLoading)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(R,{className:"mr-2"})," Loading…"]});if(!N)return e.jsx(wt,{});if(j.isError)return e.jsx(At,{onRetry:()=>void j.refetch()});const h=u?Be(j.data??[],{type:u.entity_type,id:u.id??u.slug}).find(C=>C.key===r):void 0;return!d||!u||!h?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This view isn't attached to this record any more."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(Ct,{orgSlug:t,viewKey:h.key,scope:{type:u.entity_type,entity:u.is_derived?u.slug:u.id??u.slug},params:n,onParamsChange:i,paramDecls:h.params,contentHash:h.content_hash,title:h.name,minHeight:320})})}function oe({owner:t,runId:s}){const r=$t(t,s);if(t==="me")return null;if(r.isLoading)return e.jsx("p",{role:"status",className:"px-4 pt-4 text-xs text-muted-foreground",children:"Loading run…"});if(!r.data)return e.jsx("p",{role:"alert",className:"px-4 pt-4 text-sm text-destructive",children:"Could not load this run."});const n=r.data;return e.jsxs("section",{"aria-label":"Run outcome",className:"space-y-2 border-b px-4 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(St,{status:It(n.status),children:n.status}),e.jsx("time",{dateTime:n.created_at,className:"text-xs text-muted-foreground",children:Ke(n.created_at)})]}),n.connection_display_name?e.jsx("p",{className:"text-sm",children:n.connection_display_name}):null,n.error_message?e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm text-destructive",children:n.error_message}):null,r.isError?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Could not refresh this run. Showing its last known outcome."}):null]})}const X=30;function I({label:t,children:s}){return e.jsxs("section",{className:"border-t px-4 py-3 first:border-t-0",children:[e.jsx("h3",{className:"mb-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t}),s]})}function B({label:t,detail:s}){return e.jsxs("div",{className:"flex items-baseline gap-3 py-0.5 text-sm",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("span",{className:"shrink-0 truncate text-xs text-muted-foreground",children:s})]})}function as({stretch:t,ownerSlug:s,connectorDefinitions:r,connectionName:n,sourceConnection:i,showEntity:o}){const c=D(),a=g.useMemo(()=>He(t),[t]),d=g.useMemo(()=>Ve(t),[t]),[p,m]=g.useState(!1),[v,b]=g.useState(new Set),x=l=>e.jsx("li",{children:e.jsx(gt,{content:l,ownerSlug:s,connectorDefinitions:r,connectionName:n,showEntity:o})},l.id),y=l=>e.jsx("ul",{className:"-mx-1 divide-y overflow-hidden rounded-lg border",children:l.map(x)}),N=[...a.failedCalls.map(l=>l.content),...a.failedOperations.flatMap(l=>E(l)??[])],j=t.changes.flatMap(l=>E(l)??[]),u=[...t.calls.map(l=>l.content),...t.operations.flatMap(l=>E(l)??[])].sort((l,f)=>new Date(f.occurred_at).getTime()-new Date(l.occurred_at).getTime()),h=p?u:u.slice(0,X),C=(l,f)=>e.jsxs(w,{variant:"ghost",size:"sm",className:"mt-2",onClick:f,children:["Show all ",l]});if(t.source){const{source:l}=t,f=t.flagged.flatMap(k=>E(k)??[]),le=d.reduce((k,W)=>k+W.items.length,0),_=i?.(l.connectionId)??null;return e.jsxs("div",{className:"pb-4",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-4 pt-3 pb-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:l.name}),e.jsxs("span",{children:["· ",Y(t)]}),e.jsxs("span",{children:["· ",Z(le,"item")]}),f.length>0?e.jsxs("span",{children:["· ",f.length," failed"]}):null,_&&c?e.jsxs(w,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>c.open({href:`/${s}/connectors/${encodeURIComponent(_.connectorKey)}/${l.connectionId}`,key:`connection:${l.connectionId}`,title:l.name,connectorPanel:{section:"data",connectorKey:_.connectorKey,connectionId:l.connectionId,organizationId:_.organizationId,ownerSlug:s}}),children:["All data from ",l.name]}):null]}),f.length>0?e.jsx(I,{label:`Failed · ${f.length}`,children:y(f)}):null,d.map(k=>{const q=v.has(k.type)?k.items:k.items.slice(0,X);return e.jsxs(I,{label:k.label,children:[y(q),k.items.length>q.length?C(k.items.length,()=>b(new Set([...v,k.type]))):null]},k.type)})]})}const P=a.did.reduce((l,f)=>l+f.count,0),A=a.lookedAt.reduce((l,f)=>l+f.count,0),S=t.apps.length===1?t.apps[0]:null,U=S?.key.startsWith("client:")?`/${s}/events?client_ids=${encodeURIComponent(S.key.slice(7))}`:S?.key.startsWith("agent:")?`/${s}/events?agent=${encodeURIComponent(S.key.slice(6))}`:null;return e.jsxs("div",{className:"pb-4",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-4 pt-3 pb-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:ft(t)}),e.jsxs("span",{children:["· ",Y(t)]}),e.jsxs("span",{children:["· ",Z(t.calls.length,"call")]}),e.jsxs("span",{children:["· ",N.length," failed"]}),U&&S&&c?e.jsxs(w,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>c.open({href:U,title:S.name}),children:["All activity from ",S.name]}):null]}),N.length>0?e.jsx(I,{label:`Failed · ${N.length}`,children:y(N)}):null,t.kind==="background"?null:e.jsxs(I,{label:`Changed · ${j.length||a.changeSteps.reduce((l,f)=>l+f.count,0)}`,children:[j.length>0?y(j):null,a.changeSteps.map(l=>e.jsx(B,{label:l.title,detail:`${l.methods.join(" · ")} · ${l.count}`},l.title)),j.length===0&&a.changeSteps.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nothing changed."}):null]}),P>0?e.jsx(I,{label:`Did · ${P}`,children:a.did.map(l=>e.jsx(B,{label:l.group,detail:l.items.length>0?l.items.slice(0,5).map(f=>`${f.item} ${f.count}`).join(" · ")+(l.items.length>5?` · ${l.items.length-5} more`:""):String(l.count)},l.group))}):null,A>0?e.jsx(I,{label:`Looked at · ${A}`,children:a.lookedAt.map(l=>e.jsx(B,{label:l.title,detail:`${l.methods.join(" · ")} · ${l.count}`},l.title))}):null,e.jsxs(I,{label:`Raw calls · ${u.length}`,children:[y(h),u.length>h.length?C(u.length,()=>m(!0)):null]})]})}function en({item:t}){if(t.connectorPanel)return e.jsx(Ut,{panel:t.connectorPanel});if(t.schemaSections)return e.jsx(M,{item:t});if(t.recordField)return e.jsx(bt,{target:t.recordField});if(t.recordPeer)return e.jsx(Nt,{target:t.recordPeer});if(t.recordLinks)return e.jsx(rs,{target:t.recordLinks});if(t.workStretch)return e.jsx(as,{...t.workStretch});if(typeof t.browserUrl=="string"&&t.browserUrl.length>0)return e.jsx(J,{item:t});const s=t.href?Ue(t.href):null;return s?s.kind==="memory"?"runId"in s?e.jsxs(e.Fragment,{children:[e.jsx(oe,{owner:s.owner,runId:s.runId}),e.jsx(V,{title:"What it produced",children:e.jsx(O,{owner:s.owner,runId:s.runId})}),e.jsx(ce,{owner:s.owner,runId:s.runId})]}):"runIds"in s?e.jsx(O,{owner:s.owner,runIds:s.runIds}):e.jsx(O,{owner:s.owner,contentIds:s.contentIds}):s.kind==="entity"?e.jsx(Xt,{owner:s.owner,path:s.path}):s.kind==="entity-type"?e.jsx(ts,{owner:s.owner,typeSlug:s.typeSlug,view:s.view}):s.kind==="record-view"?e.jsx(is,{owner:s.owner,path:s.path,viewKey:s.viewKey}):s.kind==="event"?e.jsx(ss,{owner:s.owner,eventId:s.eventId,viewKey:s.viewKey}):s.kind==="feed"?e.jsx(ns,{owner:s.owner,feedId:s.feedId,semanticTypes:s.semanticTypes}):s.kind==="agent"?e.jsx(Qt,{owner:s.owner,name:t.title,agentId:s.agentId,clientIds:s.clientIds}):t.runId?e.jsx(os,{owner:s.owner,automationId:s.automationId,runId:t.runId}):e.jsx(cs,{owner:s.owner,automationId:s.automationId}):e.jsx(J,{item:t})}function J({item:t}){const s=t.body,r=t.notificationType??"generic",n=t.createdAt,i=t.browserUrl??null,o=t.browserHandoff??null;return e.jsxs("article",{className:"space-y-4 px-5 py-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(We,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:qe(r)}),n?e.jsx("span",{children:Ge(n)}):null]})]}),s?e.jsx("div",{className:"text-sm leading-6 text-foreground/90",children:e.jsx(Ye,{text:s,linkPolicy:r==="action_approval_needed"?"app-links":"strip"})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No additional details were provided."}),t.owner&&t.sourceAttribution?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground/80",children:"Generated from"}),e.jsx(Ze,{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(w,{type:"button",size:"sm",className:"h-8 text-sm",onClick:()=>{Xe(i)},children:[e.jsx(Qe,{className:"mr-1.5 h-3.5 w-3.5"}),"Open post"]})}):null]})}function V({title:t,children:s}){return e.jsxs("section",{"aria-label":t,className:"border-b",children:[e.jsx("h2",{className:"px-4 pt-4 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t}),s]})}function ce({owner:t,runId:s}){return t==="me"?null:e.jsx("div",{className:"px-4 py-3",children:e.jsxs(H,{to:"/$owner/events",params:{owner:t},search:{run_ids:String(s)},className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:["Open in Activity",e.jsx(Je,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]})})}function os({owner:t,automationId:s,runId:r}){const{organizationId:n}=re(t),i=ie(s,void 0,n),o=et(i.data?.automation);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{owner:t,runId:r}),e.jsx(V,{title:"What it produced",children:e.jsx(O,{owner:t,runId:r})}),o?e.jsx(V,{title:"How it ran",children:e.jsx(Vt,{agentId:o,automationId:s,ownerSlug:t,runId:r})}):i.isLoading?e.jsx($,{className:"m-4 h-24 rounded-lg"}):null,e.jsx(ce,{owner:t,runId:r})]})}function cs({owner:t,automationId:s}){const{organizationId:r}=re(t),n=ie(s,void 0,r),i=tt(t,s,n.data?.automation);return e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsx(st,{runNow:i}),e.jsx(nt,{owner:t,agentId:null,automationId:s,view:"activity",onDone:()=>{}})]})}export{en as PeekPaneContent};
2
- //# sourceMappingURL=peek-pane-content-Cc8YX1oy.js.map
@@ -1,2 +0,0 @@
1
- import{r as e,eq as l}from"./index-CdDNNAx2.js";function a(){return e.useEffect(()=>{l()},[]),null}export{a as P};
2
- //# sourceMappingURL=public-shell-ready-CRyAZATw.js.map
@@ -1,2 +0,0 @@
1
- import{aU as ds,j as e,r as j,c as K,H as te,dN as us,dA as bt,dM as jt,L as ke,a7 as ms,dP as fs,S as kt,dQ as ps,d7 as hs,aN as Ct,aP as T,bp as rt,dR as vs,dS as ys,av as gs,dT as xs,au as bs,d2 as js,dU as ee,cv as ks,dV as St,dW as Cs,ax as Ss,dX as Ns,s as _s,dl as Es,aC as ge,dY as Is,dZ as Ts,n as Nt,cP as _t,d_ as As,cB as ct,d$ as Fs,cT as Rs,cU as Et,e0 as Ps,e1 as ws,cy as Ms,aQ as Ls,dc as $s,U as Os,i as xe,X as Ds,e2 as Bs,e3 as Ks,bU as Gs,e4 as Us,e5 as Vs,e6 as It,br as Qs,bs as Ws,bt as Hs,bu as zs,bv as Ys,e7 as Zs,e8 as Tt,e9 as lt,z as qs,ea as Xs,eb as Re,ec as dt,cQ as Js,ed as en,x as tn,cO as sn,ee as nn,ef as on,t as an,eg as rn,eh as cn,ei as ln,c2 as dn,ej as un,ek as mn,dE as fn,bd as ut,el as mt,em as At,en as Pe,dn as Ft,B as Rt,eo as pn,ep as we}from"./index-CdDNNAx2.js";import{S as D,F as ft,o as X,d as hn,r as vn,f as yn,a as gn}from"./filter-editors-DDTwyYt0.js";import{u as xn}from"./runs-CuC7WMtd.js";import{e as bn,f as Ae,C as Pt,c as jn}from"./event-kind-options-fHAIXu24.js";import{S as kn}from"./source-record-panels-C4UItfdk.js";import{u as Cn}from"./clients-BCvjAJDT.js";import{u as Sn}from"./client-activity-scopes-BBIq16tG.js";import{g as Nn}from"./client-rows-DGh1O-Fu.js";import{E as _n}from"./events-feed-BI7wNRUY.js";import{E as En}from"./run-initiator-B8IRlRd-.js";import{L as In,u as Tn}from"./renderer-DZ0w2k2r.js";import{E as An}from"./agent-loading-shells-xteN-pyK.js";import{M as Fn}from"./member-scope-gate-CH_0jHiM.js";const Oe=j.createContext(null);function Rn({organizationId:t,isWorkspaceLoading:s,children:a}){const{data:n=[],isLoading:o}=ds(t);return e.jsx(Oe.Provider,{value:{groups:n,isLoading:!!s||o},children:a})}function Pn(){const t=j.useContext(Oe);if(!t)throw new Error("useMemoryConnectorGroups must be used within MemoryConnectorGroupsProvider");return t}function wn(){return j.useContext(Oe)}function wt(t){const{parse:s,serialize:a,filterKeys:n,clearClassifications:o=!0,replace:i=!0,merge:l}=t,y=K(),d=te(),r=j.useMemo(()=>{const u=new URLSearchParams;for(const[f,p]of Object.entries(d.search||{}))p!=null&&u.set(f,typeof p=="object"&&!Array.isArray(p)?JSON.stringify(p):String(p));return s(u)},[d.search,s]),c=j.useCallback((u,f)=>{const p=l?l(r,u):{...r,...u},v=a(p),k={};for(const[x,S]of Object.entries(d.search||{}))S!=null&&(k[x]=S);for(const x of n)delete k[x];if(o)for(const x of Object.keys(k))x.startsWith("clf_")&&delete k[x];for(const[x,S]of Object.entries(v))S!==void 0&&(k[x]=S);y({to:d.pathname,search:k,replace:f?.replace??i})},[r,a,n,o,l,y,d,i]),g=j.useCallback(()=>{const u={};for(const[f,p]of Object.entries(d.search||{}))p!=null&&(n.includes(f)||o&&f.startsWith("clf_")||(u[f]=p));y({to:d.pathname,search:u,replace:i})},[y,d.pathname,d.search,n,o,i]);return{filters:r,updateFilters:c,clearFilters:g}}function Mn(t){const{slug:s}=us();return bt({queryKey:["schedules",s,t],queryFn:async()=>((await jt("manage_schedules",{action:"list",action_type:"wake_agent",include_paused:!0})).schedules??[]).filter(n=>n.action_args?.agent_id===t),enabled:!!s&&!!t,staleTime:3e4})}function Ln(t,s){return{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:t,connectorKey:s.connector_key,connectionId:String(s.connection_id)},search:{feedId:s.id}}}function $n(t,s){return{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:t,connectorKey:s.connector_key,connectionId:String(s.id)}}}function On(t,s){return{to:"/$owner/agents/connected/$clientId",params:{owner:t,clientId:s}}}function Dn(t,s){return{to:"/$owner/automations/$automationId",params:{owner:t,automationId:s}}}function Bn(t,s,a){return{to:"/$owner/events",params:{owner:t},search:{agent:s,schedule:a}}}function fe({id:t,label:s,value:a,sourceLink:n,details:o,onRemove:i}){return{id:t,label:s,op:"is",value:a,onRemove:i,editor:n||o?{kind:"custom",className:"w-80",render:()=>e.jsxs("div",{className:"flex flex-col gap-2 p-3 text-sm",children:[n?e.jsxs(ke,{to:n.to,params:n.params,search:n.search,className:"inline-flex min-w-0 items-center gap-1.5 font-medium text-foreground hover:underline",children:[e.jsx("span",{className:"truncate",children:a}),e.jsx(ms,{className:"h-3 w-3 shrink-0 text-muted-foreground"})]}):e.jsx("span",{className:"font-medium",children:a}),o]})}:void 0}}function Kn({ownerSlug:t,clientIds:s,linkedUser:a,linkedUserEntitySlug:n}){const o=t&&n?fs(t,[{entity_type:"$member",slug:n}]):null;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"inline-flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.length===1?"Client ID":"Client IDs"}),s.map(i=>e.jsx("code",{className:"break-all text-foreground",children:i},i))]}),a?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:["Granted by",o?e.jsx(ke,{to:o,className:"font-medium text-foreground hover:underline",children:a}):e.jsx("span",{className:"font-medium text-foreground",children:a})]}):null]})}function Gn(t,s=!0){return bt({queryKey:["automations-list","activity",t],queryFn:async()=>{const a=await Promise.all(["active","archived"].map(n=>jt("manage_automations",{action:"list",status:n,include_details:!1},{slug:t})));return[...new Map(a.flatMap(n=>n.automations).map(n=>[Number(n.automation_id),n])).values()].sort((n,o)=>n.name.localeCompare(o.name))},enabled:s&&!!t,staleTime:3e4})}function J({to:t,params:s,search:a,label:n}){return e.jsx(ke,{to:t,params:s,search:a,onClick:o=>o.stopPropagation(),onPointerDown:o=>o.stopPropagation(),className:"shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100 focus-visible:opacity-100","aria-label":`Manage ${n}`,children:e.jsx(kt,{className:"h-3.5 w-3.5"})})}const Me=["produced","analyzed"],be=t=>t==="produced"?"Produced by":"Analyzed by";function Un({enabled:t,...s}){const a=Vn(s,t);if(!t)return{fields:[],chips:[]};const n=Qn(s);return{fields:[a.field,n.field],chips:[...a.chips,...n.chips]}}function Vn({ownerSlug:t,filters:s,onFiltersChange:a},n){const o=Gn(t,n),i=o.data??[],l=c=>c==="produced"?s.producedByAutomationId:s.automationId,y=c=>i.find(g=>Number(g.automation_id)===c)?.name??`#${c}`,d=Me.flatMap(c=>{const g=l(c);return g==null?[]:[{id:`automation-${c}`,field:"automation",label:be(c),value:y(g),onRemove:()=>a(c==="produced"?{producedByAutomationId:null}:{automationId:null})}]}),r={kind:"list",className:"w-80",searchPlaceholder:"Search Automations...",emptyText:o.isLoading?"Loading Automations...":"No Automations found",items:c=>e.jsxs(e.Fragment,{children:[Me.map(g=>{const u=l(g),f=i.map(v=>({id:Number(v.automation_id),label:`${v.name}${v.status==="archived"?" (archived)":""}`}));u!=null&&!f.some(v=>v.id===u)&&f.unshift({id:u,label:`Automation #${u} (selected)`});const p=v=>{a(g==="produced"?{producedByAutomationId:v}:{automationId:v}),c()};return e.jsx(Ct,{heading:be(g),children:f.map(v=>e.jsxs(T,{"aria-label":v.label,value:`${g} ${v.label} ${v.id}`,onSelect:()=>p(v.id),className:"group",children:[e.jsx(D,{selected:u===v.id}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:v.label}),e.jsx(J,{...Dn(t,String(v.id)),label:v.label})]},v.id))},g)}),o.isError?e.jsx(T,{forceMount:!0,onSelect:()=>void o.refetch(),children:"Could not load Automations. Retry"}):null]})};return{chips:d,field:{key:"automation",label:"Automation",group:"Scope",icon:e.jsx(ps,{className:"h-4 w-4"}),editor:r}}}function Qn(t){const{filters:s,onFiltersChange:a}=t,n=[];s.runIds?.length&&n.push({id:"run-produced",field:"run",label:"Produced by run",value:s.runIds.map(i=>`#${i}`).join(", "),onRemove:()=>a({runIds:null})}),s.runId!=null&&n.push({id:"run-analyzed",field:"run",label:"Analyzed by run",value:`#${s.runId}`,onRemove:()=>a({runId:null})});const o={kind:"list",className:"w-96",searchPlaceholder:"Search runs or enter a run ID...",emptyText:"No matching runs. Enter an exact run ID or load more.",items:(i,l)=>Me.map(y=>e.jsx(Wn,{...t,mode:y,query:l,close:i},y))};return{chips:n,field:{key:"run",label:"Run",group:"Scope",icon:e.jsx(hs,{className:"h-4 w-4"}),editor:o}}}function Wn({ownerSlug:t,filters:s,onFiltersChange:a,mode:n,query:o,close:i}){const l=n==="produced"?s.producedByAutomationId:s.automationId,y=xn({workspace:!0},{automationIds:l==null?void 0:[l],runTypes:n==="analyzed"?["automation"]:void 0,connectionIds:n==="produced"?s.connectionIds??void 0:void 0,feedIds:n==="produced"?s.feedIds??void 0:void 0},t),d=n==="produced"?s.runIds??[]:s.runId==null?[]:[s.runId],r=y.data?.pages.flatMap(f=>f.runs)??[],c=[...new Map(r.map(f=>[f.id,{id:f.id,label:`Run #${f.id} · ${f.feed_display_name??f.operation_key??f.run_type} · ${f.status}`}])).values()];for(const f of d)c.some(p=>p.id===f)||c.unshift({id:f,label:`Run #${f} (selected)`});const g=f=>{if(n==="produced"){const p=d.includes(f)?d.filter(v=>v!==f):[...d,f];a({runIds:p.length?p:null})}else a({runId:f}),i()},u=/^\d+$/.test(o.trim())?Number(o.trim()):0;return e.jsxs(Ct,{heading:be(n),children:[c.map(f=>e.jsxs(T,{value:`${n} ${f.label}`,onSelect:()=>g(f.id),children:[e.jsx(D,{selected:d.includes(f.id)}),e.jsx("span",{className:"truncate",children:f.label})]},f.id)),Number.isSafeInteger(u)&&u>0&&!c.some(f=>f.id===u)?e.jsxs(T,{value:`${n} ${u}`,onSelect:()=>g(u),children:[be(n)," run #",u]}):null,y.isLoading?e.jsx(T,{disabled:!0,forceMount:!0,children:"Loading runs..."}):null,y.isError?e.jsx(T,{forceMount:!0,onSelect:()=>void(y.isFetchNextPageError?y.fetchNextPage():y.refetch()),children:"Could not load runs. Retry"}):null,!y.isLoading&&!y.isError&&!c.length?e.jsx(T,{disabled:!0,forceMount:!0,children:"No runs found"}):null,y.hasNextPage?e.jsx(T,{forceMount:!0,disabled:y.isFetching,onSelect:()=>void y.fetchNextPage(),children:y.isFetchingNextPage?"Loading more runs...":"Load more runs"}):null]})}const De="Scope",Fe="Source",V="h-4 w-4";function se(){return te().search??{}}function Mt(t){const{pathname:s}=te(),a=s.startsWith(`/${t}/events/`),n=gs(s,a?1:0),o=!!(n&&!a&&!xs(n.split("/")[0]));return{pathname:s,embedded:o,recordPath:o?bs(n)?.entityPath:a?n:void 0}}function Lt(t){const s=se(),{recordPath:a,pathname:n,embedded:o}=Mt(t);return i=>{const l=ee(t,s,i,a);return o?{to:n,search:l.search}:l}}const pt=t=>new Set((t??"").split(",").map(s=>s.trim()).filter(Boolean));function Hn({ownerSlug:t,sourceRead:s=!1,filters:a,onFiltersChange:n}){const o=se(),{recordPath:i,embedded:l}=Mt(t),y=i?i.split("/").at(-2):void 0,d=typeof o.type=="string"&&o.type.trim()?o.type.trim():void 0,r=(y?rt(y):void 0)??(d?rt(d):void 0),c=vs(o),g=ys(o),u=typeof o.feed_ids=="string"?o.feed_ids:typeof o.feed_ids=="number"?String(o.feed_ids):void 0,f=zn(t,r,!l),p=Yn(t,r,i,l),v=Zn(t,c,!s),k=Un({ownerSlug:t,filters:a,onFiltersChange:n,enabled:!s}),x=qn(t,g,u);return[f,p,v,k,x].reduce((S,M)=>({fields:[...S.fields,...M.fields],chips:[...S.chips,...M.chips]}),{fields:[],chips:[]})}function zn(t,s,a){const n=K(),o=se(),{visible:i}=js(t);if(!a)return{fields:[],chips:[]};const l=i.find(d=>d.slug===s),y={kind:"list",searchPlaceholder:"Search types...",emptyText:"No entity types",items:d=>e.jsxs(e.Fragment,{children:[i.map(r=>e.jsxs(T,{onSelect:()=>{n(ee(t,o,{entity:void 0,create:void 0,type:r.slug})),d()},className:"group gap-2",children:[e.jsx(D,{selected:r.slug===s}),e.jsx(Rs,{icon:r.icon,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r.name}),typeof r.entity_count=="number"?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:r.entity_count}):null,e.jsx(J,{to:"/$owner/entity-types/$slug",params:{owner:t,slug:r.slug},label:r.name})]},r.id)),e.jsxs(T,{onSelect:()=>{n(Ps(t)),d()},className:"text-muted-foreground",children:[e.jsx(Et,{className:"h-4 w-4 shrink-0"}),"Add entity type"]})]})};return{fields:[{key:"type",label:"Entity type",group:De,icon:e.jsx(ks,{className:V}),editor:y}],chips:s?[{id:"type",label:"Entity type",op:"is",value:l?.name??s,onRemove:()=>void n(ee(t,o,{type:void 0}))}]:[]}}function Yn(t,s,a,n){const o=K(),i=se(),[l,y]=j.useState(""),[d,r]=j.useState(0),c=St(l,250),g={slug:t},{data:u,isLoading:f,isError:p,refetch:v}=Cs(s??"",g,{search:c,offset:d,limit:30,enabled:!n&&!!s}),{data:k}=Ss(a?`/${t}/${a}`:"",g),x=a?k?.entity:void 0,S=x?.name??(a?a.split("/").at(-1):void 0);if(n)return{fields:[],chips:S?[{id:"entity",label:"Entity",op:"is",value:S}]:[]};if(!s)return{fields:[],chips:[]};const M={kind:"list",searchPlaceholder:"Search entities...",emptyText:f?"Loading entities...":"No matching entities",className:"w-80",onQueryChange:F=>{y(F),r(0)},items:F=>e.jsxs(e.Fragment,{children:[p?e.jsx(T,{onSelect:()=>void v(),children:"Could not load entities. Retry"}):u?.entities.map(E=>e.jsxs(T,{value:E.slug,onSelect:()=>{const R=ws([...E.parent_slug&&E.parent_entity_type?[{entity_type:E.parent_entity_type,slug:E.parent_slug}]:[],{entity_type:E.entity_type,slug:E.slug}]);o(ee(t,i,{type:s},R)),F()},children:[e.jsx(D,{selected:x?.slug===E.slug}),E.name]},E.slug)),d>0&&e.jsx(T,{onSelect:()=>r(Math.max(0,d-30)),children:"Previous entities"}),u?.metadata.has_more&&e.jsx(T,{disabled:f,onSelect:()=>r(d+30),children:"More entities"})]})};return{fields:[{key:"entity",label:"Entity",group:De,icon:e.jsx(Ns,{className:V}),editor:M}],chips:S?[{id:"entity",label:"Entity",op:"is",value:S,onRemove:()=>void o(ee(t,i,{type:s}))}]:[]}}function Zn(t,s,a){const n=K(),o=Lt(t),{data:i=[]}=_s(),l=j.useMemo(()=>[...i].sort((r,c)=>r.name.localeCompare(c.name)),[i]);if(!a)return{fields:[],chips:[]};const y=l.find(r=>r.agentId===s),d={kind:"list",searchPlaceholder:"Search agents...",emptyText:"No agents",items:r=>l.map(c=>e.jsxs(T,{onSelect:()=>{n(o({agent:c.agentId,schedule:void 0})),r()},className:"gap-2",children:[e.jsx(D,{selected:c.agentId===s}),e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md bg-muted text-[10px] font-medium",children:c.name.trim().charAt(0).toUpperCase()||"?"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:c.name})]},c.agentId))};return{fields:[{key:"agent",label:"Agent",group:De,icon:e.jsx(Es,{className:V}),editor:d}],chips:s?[{id:"agent",label:"Agent",op:"is",value:y?.name??s,onRemove:()=>void n(o({agent:void 0,schedule:void 0}))}]:[]}}function qn(t,s,a){const n=K(),o=Lt(t),{groups:i}=Pn(),l=se(),y=ge({platforms:String(l.platforms??l.platform??"")}).platforms??[],d=j.useMemo(()=>pt(s),[s]),r=j.useMemo(()=>pt(a),[a]),c=y.length===1?y[0]:Is(i,d),g=i.find(I=>I.connector_key===c),u=d.size===1?Number([...d][0]):void 0,f=Ts(u),{org:p}=Nt(),v=_t(p?.id,{feedIds:[...r].map(Number),enabled:u==null&&r.size>0}),k=u==null?v:f,x=k.data??[],S={platforms:void 0,platform:void 0,connection_ids:void 0,feed_ids:void 0},M={kind:"list",searchPlaceholder:"Search connectors...",emptyText:"No connectors",items:I=>e.jsxs(e.Fragment,{children:[i.map(N=>{const A=N.connector_name??N.connector_key;return e.jsxs(T,{disabled:N.connections.length===0,onSelect:()=>{n(o({...S,platforms:N.connector_key})),I()},className:"group gap-2",children:[e.jsx(D,{selected:N.connector_key===g?.connector_key}),e.jsx(Ls,{plain:!0,name:A,faviconDomain:N.favicon_domain,className:"h-5 w-5 shrink-0 rounded-md text-[10px]"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:A}),N.connection_count>0?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:N.connection_count}):null,e.jsx(J,{to:"/$owner/connectors/$connectorKey",params:{owner:t,connectorKey:N.connector_key},label:A})]},N.connector_key)}),e.jsx(T,{asChild:!0,onSelect:I,className:"text-muted-foreground",children:e.jsxs(ke,{to:"/$owner/connectors/create",params:{owner:t},className:"flex items-center gap-2",children:[e.jsx(Et,{className:"h-4 w-4 shrink-0"}),"Add connector"]})})]})},F=[{key:"connector",label:"Connector",group:Fe,icon:e.jsx(Ms,{className:V}),editor:M}],E=[],R=g?.connector_name??g?.connector_key??(y.join(", ")||(d.size?`Connections ${[...d].join(", ")}`:void 0));if(R&&E.push({id:"connector",label:"Connector",op:"is",value:R,onRemove:()=>void n(o(S))}),g){F.push({key:"connection",label:"Connection",group:Fe,icon:e.jsx(As,{className:V}),editor:Q(g)});const I=d.size===1?g.connections.find(N=>d.has(String(N.id))):void 0;I&&E.push({id:"connection",label:"Connection",op:"is",value:ct({display_name:I.display_name,connector_name:g.connector_name,connector_key:g.connector_key}),onRemove:()=>void n(o({...S,platforms:g.connector_key}))})}if((u||a)&&F.push({key:"feed",label:"Feed",group:Fe,icon:e.jsx(Fs,{className:V}),editor:G()}),r.size>0){const I=r.size===1?x.find(N=>r.has(String(N.id))):void 0;E.push({id:"feed",label:"Feed",op:"is",value:I?pe(I):`#${a}`,onRemove:()=>void n(o({...u!=null?{connection_ids:String(u)}:{},feed_ids:void 0}))})}return{fields:F,chips:E};function Q(I){return{kind:"list",searchPlaceholder:"Search connections...",emptyText:"No connections",items:N=>I.connections.map(A=>{const b=ct({display_name:A.display_name,connector_name:I.connector_name,connector_key:I.connector_key});return e.jsxs(T,{onSelect:()=>{n(o({connection_ids:String(A.id),feed_ids:void 0})),N()},className:"group gap-2",children:[e.jsx(D,{selected:d.has(String(A.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b}),A.feed_count>0?e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:A.feed_count}):null,e.jsx(J,{...$n(t,{id:A.id,connector_key:I.connector_key}),label:b})]},A.id)})}}function G(){return{kind:"list",searchPlaceholder:"Search feeds...",emptyText:k.isLoading?"Loading feeds...":"No feeds",items:I=>x.map(N=>e.jsxs(T,{"aria-label":pe(N),onSelect:()=>{n(o({...u!=null?{connection_ids:String(u)}:{},feed_ids:String(N.id)})),I()},className:"group gap-2",children:[e.jsx(D,{selected:r.has(String(N.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:pe(N)}),e.jsx(J,{...Ln(t,N),label:pe(N)})]},N.id))}}}function pe(t){return t.display_name?.trim()||t.feed_key}const je=[{value:"date-desc",label:"Newest first"},{value:"date-asc",label:"Oldest first"},{value:"score-desc",label:"Highest score"},{value:"score-asc",label:"Lowest score"}];function Xn({value:t,onChange:s}){const a=je.find(n=>n.value===t)?.label??"Newest first";return e.jsxs(Qs,{value:t,onValueChange:s,children:[e.jsxs(Ws,{"aria-label":"Sort",className:"h-8 w-auto shrink-0 gap-2 bg-muted px-2.5",children:[e.jsx(It,{"aria-hidden":"true",className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Hs,{children:a})]}),e.jsx(zs,{align:"end",className:"min-w-40",children:je.map(n=>e.jsx(Ys,{value:n.value,children:n.label},n.value))})]})}const ht=[{value:"user",label:"Manual review"},{value:"system",label:"Auto-classified"},{value:"llm",label:"LLM-classified"}],vt=[{value:"pending",label:"Pending approval"},{value:"approved",label:"Approved"},{value:"rejected",label:"Rejected"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}],he=0,ve=100,q="Event",U="h-4 w-4";function Jn(t,s,a){const n=t.engagementRange??[he,ve],o=t.reviewStatus,i=t.interactionStatus,l=t.semanticTypes??[],y=[{key:"kind",label:"Event kind",group:q,icon:e.jsx(Bs,{className:U}),editor:X({searchPlaceholder:"Search event kinds...",emptyText:"No event kinds found",options:bn(a,l).map(c=>({value:c,label:Ae(c)})),selected:l,multiple:!0,onSelect:c=>{const g=l.includes(c)?l.filter(u=>u!==c):[...l,c];s({semanticTypes:g.length>0?g:void 0})}})},{key:"date",label:"Date",group:q,icon:e.jsx(Ks,{className:U}),editor:hn({value:t.dateRange??void 0,onApply:c=>s({dateRange:c})})},{key:"approval",label:"Approval",group:q,icon:e.jsx(Gs,{className:U}),editor:X({searchPlaceholder:"Search statuses...",options:[...vt],selected:i?[i]:[],onSelect:c=>s({interactionStatus:c})})},{key:"review",label:"Reviewed by",group:q,icon:e.jsx(Us,{className:U}),editor:X({searchPlaceholder:"Search reviewers...",options:[...ht],selected:o&&o!=="all"?[o]:[],onSelect:c=>s({reviewStatus:c})})},{key:"score",label:"Engagement score",group:q,icon:e.jsx(Vs,{className:U}),editor:vn({value:n,min:he,max:ve,onApply:c=>s({engagementRange:c})})}],d=[],r=t.eventCategory!=null&&l.length===1&&l[0]===Pt;return l.length&&!r&&d.push({id:"kind",label:"Kind",value:l.length<=2?l.map(Ae).join(", "):`${l.length} kinds`,title:l.map(Ae).join(", "),onRemove:()=>s({semanticTypes:void 0})}),t.dateRange&&d.push({id:"date",label:"Date",op:"is",value:yn(t.dateRange),onRemove:()=>s({dateRange:null})}),i&&d.push({id:"approval",label:"Approval",op:"is",value:vt.find(c=>c.value===i)?.label??i,onRemove:()=>s({interactionStatus:null})}),o&&o!=="all"&&d.push({id:"review",label:"Reviewed by",op:"is",value:ht.find(c=>c.value===o)?.label??o,onRemove:()=>s({reviewStatus:void 0})}),(n[0]!==he||n[1]!==ve)&&d.push({id:"score",label:"Engagement score",value:gn(n,he,ve),onRemove:()=>s({engagementRange:void 0})}),{fields:y,chips:d}}function $t({filters:t,onFiltersChange:s,eventKinds:a=[],searchQuery:n,onSearchChange:o,scope:i,extraFields:l=[],drillChips:y=[],sourceRead:d=!1,filterTrailing:r,filterActions:c,quickFilters:g,toolbar:u=!1,onClearFilters:f}){const p=n.trim().length>0,v=d?{fields:[],chips:[]}:Jn(t,s,a),k=`${t.sortBy??"date"}-${t.sortOrder??"desc"}`,x=R=>{const[Q,G]=R.split("-");s({sortBy:Q,sortOrder:G})},S=u&&!d?{fields:[{key:"sort",label:"Order",group:"Order",icon:e.jsx(It,{className:U}),editor:X({searchPlaceholder:"Search orders...",options:[...je],selected:[k],onSelect:x})}],chips:k==="date-desc"?[]:[{id:"sort",label:"Order",value:je.find(R=>R.value===k)?.label??k,onRemove:()=>s({sortBy:"date",sortOrder:"desc"})}]}:{fields:[],chips:[]},M=[...g?.fields??[],...v.fields,...i?.fields??[],...l,...S.fields],F=[...g?.chips??[],...i?.chips??[],...y,...v.chips,...S.chips],E=d?null:e.jsxs("div",{className:xe("relative min-w-0",u?"w-64 max-w-full":"flex-1"),children:[e.jsx($s,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Os,{type:"search","aria-label":"Search events",placeholder:"Search events...",value:n,onChange:R=>o(R.target.value),className:xe("h-8 pl-9",p&&"pr-9")}),p&&e.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>o(""),className:"absolute right-0.5 top-1/2 flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",children:e.jsx(Ds,{className:"h-3.5 w-3.5"})})]});return u?e.jsx(ft,{label:"Event filters",clearAllMin:2,fields:M,chips:F,actions:c,trailing:e.jsxs(e.Fragment,{children:[r,E]}),onClearAll:f,hasClearableState:p,className:"w-full"}):e.jsxs("div",{className:"w-full space-y-2.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[E,!d&&e.jsx(Xn,{value:k,onChange:x})]}),e.jsx(ft,{label:"Event filters",fields:M,chips:F,actions:c,trailing:r,onClearAll:f,hasClearableState:p})]})}function Ot({ownerSlug:t,...s}){const a=Hn({ownerSlug:t,sourceRead:s.sourceRead,filters:s.filters,onFiltersChange:s.onFiltersChange});return e.jsx($t,{...s,scope:a})}const Le=3600*1e3,yt=24*Le;function gt(t){const s=t instanceof Date?t:new Date(String(t));return Number.isNaN(s.getTime())?null:s}function xt(t){return t.toISOString().split("T")[0]}function $e(t){return t.toLocaleDateString(void 0,{timeZone:"UTC",month:"short",day:"numeric"})}function eo(t){const a=t[t.length-1].date.getTime()-t[0].date.getTime()>180*yt,n=new Map;for(const o of t){const i=new Date(o.date);a&&i.setUTCDate(i.getUTCDate()-i.getUTCDay()),n.set(i.getTime(),(n.get(i.getTime())??0)+o.count)}return[...n.entries()].sort(([o],[i])=>o-i).map(([o,i])=>{const l=new Date(o);return{start:l,end:new Date(o+(a?7:1)*yt),count:i,label:`${l.getUTCMonth()+1}/${l.getUTCDate()}`,tooltip:a?`Week of ${$e(l)}`:$e(l)}})}function to(t){const s=l=>{const y=new Date(l);return y.setMinutes(0,0,0),y.getTime()},a=new Map;for(const l of t)a.set(s(l),(a.get(s(l))??0)+1);const n=Math.min(...a.keys()),o=Math.max(...a.keys()),i=[];for(let l=n;l<=o;l+=Le){const y=new Date(l);i.push({start:y,end:new Date(l+Le),count:a.get(l)??0,label:lt(y,"HH:mm"),tooltip:lt(y,"MMM d, HH:mm")})}return i}function so({entityId:t,organizationId:s,ownerSlug:a,eventTimes:n,selectedRange:o,onSelectRange:i}){const{data:l,isLoading:y,error:d}=Zs(s,{entityId:t},{slug:a}),r=j.useMemo(()=>(l??[]).map(p=>{const v=gt(p.date);return v?{date:v,count:p.count}:null}).filter(p=>p!==null).sort((p,v)=>p.date.getTime()-v.date.getTime()),[l]),c=j.useMemo(()=>{if(r.length===0)return[];if(r.length>1)return eo(r);const[p]=r,v=xt(p.date),k=(n??[]).map(gt).filter(x=>x!==null&&xt(x)===v);return k.length===p.count?to(k):[]},[r,n]),g=j.useCallback(p=>{const v=c[p.dataIndex];v&&i&&i(v.start,v.end)},[c,i]),u=j.useCallback(p=>{if(i&&p.startValue!==void 0&&p.endValue!==void 0){const v=new Date(p.startValue),k=new Date(p.endValue);i(v,k)}},[i]),f=j.useMemo(()=>{if(c.length<2)return null;let p;if(o){const[v,k]=o,x=c.filter(S=>S.start<k&&S.end>v);x.length>0&&(p=[[{xAxis:x[0].label},{xAxis:x[x.length-1].label}]])}return{tooltip:{trigger:"axis",axisPointer:{type:"line"},formatter:v=>{const k=v[0];return`${c[k.dataIndex]?.tooltip}: ${k.value} items`}},grid:{left:50,right:20,top:20,bottom:60},xAxis:{type:"category",boundaryGap:!1,data:c.map(v=>v.label)},yAxis:{type:"value",minInterval:1,splitLine:{lineStyle:{color:"rgba(0,0,0,0.05)"}}},dataZoom:[{type:"slider",start:0,end:100,height:20,bottom:10,borderColor:"transparent",backgroundColor:"rgba(0,0,0,0.02)",fillerColor:"rgba(99, 102, 241, 0.1)",handleStyle:{color:"#6366f1"}}],series:[{type:"line",smooth:!0,areaStyle:{opacity:.3,color:new In(0,0,0,1,[{offset:0,color:"rgba(99, 102, 241, 0.5)"},{offset:1,color:"rgba(99, 102, 241, 0.05)"}])},lineStyle:{width:2,color:"#6366f1"},itemStyle:{color:"#6366f1"},showSymbol:!1,data:c.map(v=>v.count),markLine:{silent:!0,symbol:"none",label:{position:"insideEndTop",formatter:"avg: {c}",fontSize:10,color:"#9ca3af"},lineStyle:{color:"#d1d5db",type:"dashed",width:1},data:[{type:"average",name:"Average"}]},markArea:p?{silent:!0,itemStyle:{color:"rgba(99, 102, 241, 0.1)"},data:p}:void 0}]}},[c,o]);if(y||d)return e.jsx("div",{className:xe(Tt,"p-4"),children:e.jsx("div",{className:"flex h-48 w-full items-center justify-center",children:y?e.jsx(An,{}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load timeline"})})});if(r.length===0)return null;if(!f){const[p]=r;return e.jsxs("p",{className:"text-xs text-muted-foreground",children:[p.count===1?"1 event":`All ${p.count} events`," on"," ",$e(p.date),"."]})}return e.jsx(no,{option:f,onClick:g,onDataZoom:u})}function no({option:t,onClick:s,onDataZoom:a}){const{chartRef:n,setOption:o}=Tn({onClick:s,onDataZoom:a});return j.useEffect(()=>{o(t,!0)},[t,o]),e.jsx("div",{"data-testid":"events-timeline",className:xe(Tt,"p-4 relative"),children:e.jsx("div",{ref:n,className:"h-48 w-full"})})}const ye={config:"Configuration",deployment:"Applies"};function oo({organizationId:t,ownerSlug:s,entityId:a,hideSourceFilter:n=!1,scopedEntityTypes:o,pinned:i,emptyState:l,toolbar:y=!1}){const{isAuthenticated:d,isReady:r}=qs(),{isMember:c,isLoading:g}=Nt(),u=r&&d&&c,f=r&&(!d||!g&&!c),p=K(),v=te(),k=Xs(),{filters:x,updateFilters:S,clearFilters:M}=wt({parse:ge,serialize:Pe,filterKeys:Ft,replace:!1,merge:At}),[F,E]=j.useState(x.searchQuery||""),[R,Q]=j.useState(Re(x)||n&&(a!=null||!!o?.length)),G=F.trim(),I=G.length>=3?G:void 0,N=St(I,1e3),A=j.useRef(!1);j.useEffect(()=>k.history.subscribe(({location:m,action:h})=>{const C=ge(new URLSearchParams(m.search)).searchQuery??"";!(h.type==="BACK"||h.type==="FORWARD"||h.type==="GO")&&A.current&&(C===(x.searchQuery??"")||C===(I??""))||(A.current=!1,E(C))}),[k.history,I,x.searchQuery]);const b=j.useMemo(()=>{const{afterOccurredAt:m,afterId:h,...C}=x;return dt({...C,...o?.length?{entityTypes:o}:{}})},[x,o]),P=S;j.useEffect(()=>{A.current&&(x.searchQuery||void 0)!==N&&S({searchQuery:N})},[N,S,x.searchQuery]);const Be=()=>{A.current=!1,E(""),n&&s?p({...we(s,v.search??{}),...a!==void 0&&!v.pathname.startsWith(`/${s}/events/`)?{to:v.pathname}:{}}):M()},ne=Re(dt(x)),Ce=a===void 0,{data:Dt=[]}=Js(r&&u?t:null),{data:Bt=[]}=en(f?s:null),Ke=u?Dt:Bt,{data:Ge=[]}=tn(u&&t?{organizationId:t}:void 0),oe=wn(),ae=b.connectionIds,Se=(ae?.length??0)>0,{data:Ue=[]}=sn(r&&u?t??"":"",{connectionIds:ae??void 0,enabled:!oe&&r&&u&&Se}),Ve=b.feedIds,Ne=(Ve?.length??0)>0,{data:Qe=[]}=_t(r&&u?t:null,{feedIds:Ve??void 0,enabled:r&&u&&Ne}),We=j.useMemo(()=>oe?oe.groups.flatMap(m=>m.connections.map(h=>({id:h.id,display_name:h.display_name,connector_name:m.connector_name,connector_key:m.connector_key}))):Ue,[Ue,oe]),_e=j.useMemo(()=>{const m=new Set(ae??[]);return[...new Set([...b.platforms??[],...We.filter(h=>m.has(h.id)).map(h=>h.connector_key)])]},[ae,We,b.platforms]),Ee=j.useMemo(()=>Qe.map(m=>({connectorKey:m.connector_key,feedKey:m.feed_key})),[Qe]),Kt=j.useMemo(()=>Se&&_e.length===0||Ne&&Ee.length===0?[]:jn({connectors:Ke,entityTypes:Ge,selectedPlatforms:_e,selectedFeeds:Ee,selectedEntityTypes:b.entityTypes}),[Ke,b.entityTypes,Se,Ne,_e,Ee,Ge]),w=b.clientIds,ie=(w?.length??0)>0,{data:He=[]}=Cn(null,{enabled:r&&u&&ie}),re=j.useMemo(()=>{if(!w)return[];const m=new Set(w);return Nn(He).filter(h=>h.clientIds.some(C=>m.has(C)))},[w,He]),ze=j.useMemo(()=>{if(!ie||!w)return null;const m=re.map(h=>h.title);return m.length>0?m.join(", "):w.length>1?`${w.length} client registrations`:"Client registration"},[re,w,ie]),ce=re.length===1?re[0]:null,Gt=s&&ce?On(s,ce.clientId):void 0,le=b.mcpActivityId??null,{data:Ye=[]}=Sn({enabled:r&&u&&ie&&!!le,clientIds:w??[],limit:100}),Ze=j.useMemo(()=>{if(!le)return null;const m=Ye.find(C=>C.activityId===le);if(!m)return"Selected conversation";const h=m.title?.trim();return h||(m.activityKind==="session"?"MCP session":m.clientId)},[le,Ye]),W=b.agentId,H=b.schedule,{data:qe=[]}=Mn(W??void 0),Xe=j.useMemo(()=>!H||!W?null:qe.find(h=>h.id===H)?.description?.trim()||"Scheduled task",[W,H,qe]),{data:Ut}=nn(r&&u?t:null,a),{data:Vt}=on(f&&!Ce?s:null,a),Je=u?Ut:Vt,de=j.useMemo(()=>{const m=new Map;for(const h of Je||[]){const C=h.automation_name??"__global__";let _=m.get(C);_||(_={automationName:h.automation_name??null,classifiers:[]},m.set(C,_));const $=h.attribute_values||{},L=Object.keys($);let me=null;const z={};for(const[Y,B]of Object.entries($))if(B.parent)for(const[Te,Z]of Object.entries(B.parent))me=Te,z[Z]||(z[Z]=[]),z[Z].push(Y);const O=_.classifiers.find(Y=>Y.slug===h.slug);if(O){const Y=new Set([...O.values,...L]);O.values=[...Y];for(const[B,Te]of Object.entries(z)){O.valuesByParentValue[B]||(O.valuesByParentValue[B]=[]);const Z=new Set([...O.valuesByParentValue[B],...Te]);O.valuesByParentValue[B]=[...Z]}me&&(O.parentSlug=me)}else _.classifiers.push({slug:h.slug,name:h.name,values:L,parentSlug:me,valuesByParentValue:z})}for(const h of m.values())h.classifiers.sort((C,_)=>C.parentSlug===null&&_.parentSlug!==null?-1:C.parentSlug!==null&&_.parentSlug===null?1:0);return[...m.values()]},[Je]),Qt=an(r&&u?t:null,a,b,s),Wt=rn(f?s:null,a,b),Ht=f?Wt:Qt,{data:Ie,isLoading:zt,error:Yt}=Ht,Zt=j.useMemo(()=>Ie?.pages.flatMap(m=>m.content.map(h=>h.occurred_at)),[Ie]),et=Ie?.pages[0],qt=(et?.content.length??0)>0,tt=de.some(m=>m.classifiers.length>0),Xt=cn(r&&u&&tt?t:null,a,b,s),Jt=ln(f&&tt?s:null,a,b),es=(f?Jt:Xt).data?.classification_stats,ts=j.useCallback(()=>{P({beforeOccurredAt:void 0,beforeId:void 0,afterOccurredAt:void 0,afterId:void 0}),window.scrollTo({top:0,behavior:"smooth"})},[P]),ss=(m,h)=>{P({dateRange:[m,h]})},st=(m,h)=>{const C={...b.classificationFilters||{}};if(h.length>0)C[m]=h;else{delete C[m];for(const _ of de)for(const $ of _.classifiers)$.parentSlug===m&&delete C[$.slug]}P({classificationFilters:C})},ns=(m,h)=>{const C=b.classificationFilters?.[m]||[];st(m,C.includes(h)?C.filter(_=>_!==h):[...C,h])},os=m=>st(m,[]);if(Yt)return e.jsx(dn,{label:"knowledge"});const nt=!r||d&&g||u&&!t||zt,ue={fields:[],chips:[]};for(const m of de)for(const h of m.classifiers){const C=b.classificationFilters?.[h.slug]??[],_=h.parentSlug?b.classificationFilters?.[h.parentSlug]??[]:void 0,$=_?[...new Set(_.flatMap(L=>h.valuesByParentValue[L]??[]))]:h.values;$.length>0&&ue.fields.push({key:`clf:${h.slug}`,label:h.name,group:m.automationName??"Classifiers",icon:e.jsx(un,{className:"h-4 w-4"}),editor:X({searchPlaceholder:`Search ${h.name.toLowerCase()}...`,options:$.map(L=>({value:L,label:L,count:es?.[h.slug]?.[L]})),selected:C,multiple:!0,onSelect:L=>ns(h.slug,L)})})}for(const[m,h]of Object.entries(b.classificationFilters??{})){if(h.length===0)continue;const C=de.flatMap(_=>_.classifiers).find(_=>_.slug===m);ue.chips.push({id:`clf:${m}`,field:`clf:${m}`,label:C?.name??m,op:h.length>1?"is any of":"is",value:h.join(", "),onRemove:()=>os(m)})}const as=[b.contentIds?.length?fe({id:"contentIds",label:b.contentIds.length>1?"Events":"Event",value:`#${b.contentIds.join(", #")}`,onRemove:()=>P({contentIds:void 0})}):null,Ze?fe({id:"mcpActivityId",label:"Conversation",value:Ze,onRemove:()=>P({mcpActivityId:void 0})}):null,ze?fe({id:"clientIds",label:"Connected app",value:ze,sourceLink:Gt,details:w&&w.length>0?e.jsx(Kn,{ownerSlug:s,clientIds:w,linkedUser:ce?.linkedUser,linkedUserEntitySlug:ce?.linkedUserEntitySlug}):void 0,onRemove:()=>P({clientIds:void 0})}):null,Xe?fe({id:"schedule",label:"Schedule",value:Xe,sourceLink:s&&W&&H?Bn(s,W,H):void 0,onRemove:()=>P({schedule:void 0,runIds:void 0})}):null,...b.eventCategory?[ye[b.eventCategory]?{id:"event-category",label:ye[b.eventCategory],value:"",onRemove:()=>P({eventCategory:void 0,semanticTypes:void 0})}:{id:"event-category",label:"Category",op:"is",value:b.eventCategory,onRemove:()=>P({eventCategory:void 0})}]:[],...b.resourceKind||b.resourceId?[{id:"resource",label:"Resource",op:"is",value:`${b.resourceKind}: ${b.resourceId}`,onRemove:()=>P({resourceKind:void 0,resourceId:void 0})}]:[],...ue.chips].filter(m=>m!=null),is=!!(u&&a&&t),rs=ne?null:i?.rows,ot={fields:[],chips:[]};if(Ce&&u)for(const[m,h,C]of[["config",ye.config,kt],["deployment",ye.deployment,mn]]){const _=x.eventCategory===m;ot.fields.push({key:`category:${m}`,label:h,icon:e.jsx(C,{className:"h-4 w-4"}),editor:{kind:"toggle",checked:_,onToggle:()=>P({eventCategory:_?void 0:m,semanticTypes:_?void 0:[Pt],resourceKind:void 0,resourceId:void 0})}})}const at={quickFilters:ot,toolbar:y,filterTrailing:is?e.jsxs(Rt,{variant:"ghost",size:"sm",className:"h-8 text-muted-foreground","aria-pressed":R,onClick:()=>Q(m=>!m),children:[e.jsx(pn,{className:"mr-1.5 h-3.5 w-3.5"}),"Timeline"]}):void 0,onClearFilters:Be,filters:b,onFiltersChange:P,eventKinds:Kt,searchQuery:F,onSearchChange:m=>{A.current=!0,E(m)},extraFields:ue.fields,drillChips:as},cs=!nt&&!!et&&!qt&&!ne,ls=d?u?"Activity is the workspace's live feed — every message, email, file, and record a connector pulls in lands here as an event. Connect your data to start collecting.":"Activity is the workspace's live feed of connector events. Join this workspace to add connectors and collect knowledge here.":"No public knowledge items are available yet",it=!!(u&&s);return e.jsx(fn,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:n?"sticky top-0 z-10 -mx-4 bg-background px-4 pb-2 lg:-mx-6 lg:px-6":void 0,children:n&&s?e.jsx(Ot,{...at,ownerSlug:s}):e.jsx($t,{...at})}),R&&u&&a&&t&&e.jsx(so,{entityId:a,organizationId:t,ownerSlug:s||"",eventTimes:Zt,selectedRange:b.dateRange||void 0,onSelectRange:ss}),i?.needsYou,rs,nt?e.jsx(En,{}):cs?l??e.jsx(ut,{icon:mt,title:"No activity yet",description:ls,actionLabel:it?"Add a connector":void 0,onAction:it&&s?()=>void p({to:"/$owner/connectors/create",params:{owner:s}}):void 0}):e.jsx(_n,{organizationId:t,ownerSlug:s,entityId:a,filters:b,showEntityLinks:Ce,groupStretches:!0,onGoToLatest:b.beforeOccurredAt?ts:void 0,hiddenPinned:i?.hidden,emptyState:e.jsx(ut,{icon:mt,title:"No results found",description:"Try adjusting your filters to find what you are looking for",actionLabel:ne?"Clear filters":void 0,onAction:ne?Be:void 0})})]})})}function ao({record:t,ownerSlug:s}){const a=te(),n=K(),{filters:o,updateFilters:i}=wt({parse:ge,serialize:Pe,filterKeys:Ft,replace:!1,merge:At}),l=Re({...o,platforms:void 0,connectionIds:void 0,feedIds:void 0})||o.sortBy!=null&&o.sortBy!=="date"||o.sortOrder!=null&&o.sortOrder!=="desc",y=()=>{n({...we(s,a.search??{}),...a.pathname.startsWith(`/${s}/events/`)?{}:{to:a.pathname}})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ot,{ownerSlug:s,sourceRead:!0,filters:o,onFiltersChange:i,searchQuery:o.searchQuery??"",onSearchChange:d=>i({searchQuery:d}),onClearFilters:y}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Live activity supports connector, connection and feed filters. Search and other event filters are available for saved activity."}),l?e.jsxs("div",{role:"alert",className:"space-y-2 rounded-md border p-3 text-sm",children:[e.jsx("p",{children:"Some selected filters aren't supported for live activity. Clear them to see results."}),e.jsx(Rt,{variant:"outline",size:"sm",onClick:()=>{const d=Pe({platforms:o.platforms,connectionIds:o.connectionIds,feedIds:o.feedIds}),r={...we(s,a.search??{}).search,...d};n({to:a.pathname,search:r})},children:"Clear unsupported filters"})]}):e.jsx(kn,{record:t,orgContext:{slug:s},filters:o})]})}function ko({entity:t,organizationId:s,ownerSlug:a}){const n=t.is_derived?e.jsx(ao,{ownerSlug:a,record:{type:t.entity_type,key:t.slug}}):e.jsx(oo,{organizationId:s,ownerSlug:a,entityId:typeof t.id=="number"?t.id:void 0,hideSourceFilter:!0});return e.jsx(Rn,{organizationId:s,children:t.entity_type==="$member"?e.jsx(Fn,{children:n}):n})}export{oo as E,Rn as M,ko as R};
2
- //# sourceMappingURL=record-activity-9ux6SfCd.js.map
@@ -1,2 +0,0 @@
1
- import{a9 as v,r as a,j as e,L as h,aa as j,$ as y,ab as N}from"./index-CdDNNAx2.js";import{C as k,a as C,b as S,c as L}from"./card-C01y1O-W.js";function R(){const{token:n,error:x}=v.useSearch(),[o,p]=a.useState(""),[i,f]=a.useState(""),[d,s]=a.useState(null),[l,c]=a.useState(!1),[u,g]=a.useState(!1),w=async t=>{if(t.preventDefault(),!n){s("This reset link is invalid or expired.");return}if(o.length<8){s("Password must be at least 8 characters.");return}if(o!==i){s("Passwords do not match.");return}c(!0),s(null);try{const r=await j(`${y}/api/auth/reset-password`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:n,newPassword:o})});if(!r.ok)throw await N(r);g(!0)}catch(r){s(r instanceof Error?r.message:"Failed to reset password")}finally{c(!1)}},b=!n||x==="INVALID_TOKEN",m={callbackUrl:void 0,mode:void 0,error:void 0,errorDescription:void 0,loginHint:void 0,invitationOrg:void 0,intent:void 0};return e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-md p-8",children:[e.jsx("img",{src:"/lobu-logo.svg",alt:"Lobu",className:"mx-auto mb-6 h-8 w-auto"}),e.jsxs(k,{children:[e.jsx(C,{children:e.jsx(S,{asChild:!0,children:e.jsx("h1",{className:"text-center text-2xl",children:"Reset your password"})})}),e.jsx(L,{children:b&&!u?e.jsxs("div",{className:"mt-6 space-y-4 text-center",children:[e.jsx("p",{className:"text-sm text-destructive",children:"This reset link is invalid or expired."}),e.jsx(h,{to:"/auth/login",search:m,className:"text-sm text-primary hover:underline",children:"Back to sign in"})]}):u?e.jsxs("div",{className:"mt-6 space-y-4 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your password has been reset successfully."}),e.jsx(h,{to:"/auth/login",search:m,className:"text-sm text-primary hover:underline",children:"Continue to sign in"})]}):e.jsxs("form",{onSubmit:w,className:"mt-6 space-y-4",children:[d&&e.jsx("div",{className:"p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:d}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"new-password",className:"block text-sm font-medium",children:"New password"}),e.jsx("input",{id:"new-password",type:"password",value:o,onChange:t=>p(t.target.value),minLength:8,required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium",children:"Confirm new password"}),e.jsx("input",{id:"confirm-password",type:"password",value:i,onChange:t=>f(t.target.value),minLength:8,required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:l,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:l?"Resetting password...":"Reset password"})]})})]})]})})}export{R as component};
2
- //# sourceMappingURL=reset-password-D2RfrEVZ.js.map