@lobu/runtime-server 24.2.0 → 24.3.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 (252) hide show
  1. package/dist/catalogs/connectors.json +24 -2
  2. package/dist/catalogs/skills.json +1 -1
  3. package/dist/component.json +1 -1
  4. package/dist/connectors/gchat.ts +31 -1
  5. package/dist/connectors/postgres.ts +9 -5
  6. package/dist/dependencies.bun.lock +104 -167
  7. package/dist/owletto/dist/assets/_-XKF0m81R.js +3 -0
  8. package/dist/owletto/dist/assets/_-e8MbEBtw.js +2 -0
  9. package/dist/owletto/dist/assets/_agentId-Cv9goIFf.js +2 -0
  10. package/dist/owletto/dist/assets/_agentId-emObu67X.js +2 -0
  11. package/dist/owletto/dist/assets/_automationId-CfFFAYK1.js +2 -0
  12. package/dist/owletto/dist/assets/_connectorKey._connectionId-D6NKXSOE.js +2 -0
  13. package/dist/owletto/dist/assets/_connectorKey.index-DFrkLLTU.js +2 -0
  14. package/dist/owletto/dist/assets/_conversationId-D3vuAQPe.js +2 -0
  15. package/dist/owletto/dist/assets/_eventId-BV5SQaUA.js +2 -0
  16. package/dist/owletto/dist/assets/_name-DjtJMop4.js +2 -0
  17. package/dist/owletto/dist/assets/_owner-oBX68rb9.js +3 -0
  18. package/dist/owletto/dist/assets/_shape-C4lLPAwI.js +2 -0
  19. package/dist/owletto/dist/assets/_skillKey-Cw-7q6hI.js +2 -0
  20. package/dist/owletto/dist/assets/{_slug-MHQU8ftJ.js → _slug-B2g5qzn3.js} +2 -2
  21. package/dist/owletto/dist/assets/_viewKey-CIKGCtdK.js +2 -0
  22. package/dist/owletto/dist/assets/_viewKey-Dx4kJo7o.js +2 -0
  23. package/dist/owletto/dist/assets/{accept-invitation-D2T_a2dj.js → accept-invitation-38lHBvjO.js} +2 -2
  24. package/dist/owletto/dist/assets/{activity-route-view-_G_lDz5K.js → activity-route-view-voRYSM3a.js} +2 -2
  25. package/dist/owletto/dist/assets/{agent-card-controls-ColL5rdd.js → agent-card-controls-DiU7Un5w.js} +2 -2
  26. package/dist/owletto/dist/assets/{agent-client-setup-list-BgyLhJCo.js → agent-client-setup-list-Bkyw22GW.js} +4 -4
  27. package/dist/owletto/dist/assets/agent-connect-pages-CpBxQCpx.js +2 -0
  28. package/dist/owletto/dist/assets/{agent-editor-form-C24p9LLg.js → agent-editor-form-QrIDroFL.js} +2 -2
  29. package/dist/owletto/dist/assets/agent-guardrails-route-CyoGSxcZ.js +2 -0
  30. package/dist/owletto/dist/assets/{agent-loading-shells-jkf9DjdO.js → agent-loading-shells-CamDtzHY.js} +2 -2
  31. package/dist/owletto/dist/assets/{agent-permissions-matrix-C8j8kRB1.js → agent-permissions-matrix-CgsQ8BK_.js} +2 -2
  32. package/dist/owletto/dist/assets/{agent-skill-context-B9giw2u2.js → agent-skill-context-lWbXKEm1.js} +2 -2
  33. package/dist/owletto/dist/assets/{agent-skills-route-BMZ3r1bP.js → agent-skills-route-D-w3tY_2.js} +2 -2
  34. package/dist/owletto/dist/assets/{agent-subpage-shell-D49f-bzP.js → agent-subpage-shell-CLqpn5Tb.js} +2 -2
  35. package/dist/owletto/dist/assets/{agent-thread-BGHYHWDO.js → agent-thread-CsRexwTv.js} +4 -4
  36. package/dist/owletto/dist/assets/agents-DzH_FFKU.js +2 -0
  37. package/dist/owletto/dist/assets/agents-workbench-CmGrMvPC.js +2 -0
  38. package/dist/owletto/dist/assets/app-bridge-C4nPtae3.js +121 -0
  39. package/dist/owletto/dist/assets/{app._appId-A51tx2jU.js → app._appId-BO7G38fL.js} +2 -2
  40. package/dist/owletto/dist/assets/{automation-detail-content-DCAZBKle.js → automation-detail-content-DMYxs6F6.js} +2 -2
  41. package/dist/owletto/dist/assets/automations-DzH_FFKU.js +2 -0
  42. package/dist/owletto/dist/assets/calendar-DDCCSPW6.js +2 -0
  43. package/dist/owletto/dist/assets/{callback-WmyCei3R.js → callback-DFciMR8u.js} +2 -2
  44. package/dist/owletto/dist/assets/{card-Cspo-4M6.js → card-BCsbrdGs.js} +2 -2
  45. package/dist/owletto/dist/assets/{claim-CCKdBtFt.js → claim-BRua2b_7.js} +2 -2
  46. package/dist/owletto/dist/assets/{client-activity-scopes-CmK3DkSP.js → client-activity-scopes-BLIy1Zc3.js} +2 -2
  47. package/dist/owletto/dist/assets/client-rows-DiJQ5D1z.js +2 -0
  48. package/dist/owletto/dist/assets/clients-8-EpRjsm.js +2 -0
  49. package/dist/owletto/dist/assets/{code-editor-C8FJbT2P.js → code-editor-BFZa4EIt.js} +2 -2
  50. package/dist/owletto/dist/assets/connect-C0cHE9Xl.js +2 -0
  51. package/dist/owletto/dist/assets/connect-menu-D2K4tmvW.js +2 -0
  52. package/dist/owletto/dist/assets/connect._clientId-D4EG5a0v.js +2 -0
  53. package/dist/owletto/dist/assets/connected._clientId-DhoCT6sT.js +2 -0
  54. package/dist/owletto/dist/assets/connected._clientId.activity-Dn4qw2Us.js +2 -0
  55. package/dist/owletto/dist/assets/connected._clientId.index-BTI5JXA3.js +2 -0
  56. package/dist/owletto/dist/assets/connection-X9VU9Ijm.js +2 -0
  57. package/dist/owletto/dist/assets/connection-feed-detail-B6ydKasK.js +2 -0
  58. package/dist/owletto/dist/assets/connections-browser-BMV8bf54.js +2 -0
  59. package/dist/owletto/dist/assets/connector-boxes-DqZA-FdG.js +2 -0
  60. package/dist/owletto/dist/assets/{connector-provenance-bmBJJ9B4.js → connector-provenance-BIg8P8WY.js} +2 -2
  61. package/dist/owletto/dist/assets/{connector-scope-lists-B44Q9W-j.js → connector-scope-lists-CJYz53YF.js} +2 -2
  62. package/dist/owletto/dist/assets/{connectors-CTWPDH8f.js → connectors-BroKpwhB.js} +2 -2
  63. package/dist/owletto/dist/assets/{consent-C_WBfmQ8.js → consent-fzLN-Qy7.js} +2 -2
  64. package/dist/owletto/dist/assets/copy-button-Df7QXE0w.js +2 -0
  65. package/dist/owletto/dist/assets/{core.esm-CoJ5Splc.js → core.esm-A1UnFbGs.js} +2 -2
  66. package/dist/owletto/dist/assets/create-BjwsYarn.js +2 -0
  67. package/dist/owletto/dist/assets/create-Dzr4mlr0.js +2 -0
  68. package/dist/owletto/dist/assets/create-automation-form-DHW6OUoS.js +3 -0
  69. package/dist/owletto/dist/assets/create-c94SPL21.js +2 -0
  70. package/dist/owletto/dist/assets/create._connectorKey-DLLn2nej.js +2 -0
  71. package/dist/owletto/dist/assets/{cronstrue-CeUS_78Q.js → cronstrue-xxpD1P2-.js} +2 -2
  72. package/dist/owletto/dist/assets/{device-Br9JHadR.js → device-C3AEoL5c.js} +2 -2
  73. package/dist/owletto/dist/assets/device-pin-tombstone-B_te59GE.js +2 -0
  74. package/dist/owletto/dist/assets/device._deviceId-ZU09qrot.js +2 -0
  75. package/dist/owletto/dist/assets/{entity-avatar-BZIa-7i5.js → entity-avatar-CEV4ttUQ.js} +2 -2
  76. package/dist/owletto/dist/assets/entity-options-DJv2EhVV.js +2 -0
  77. package/dist/owletto/dist/assets/entity-page-BUghWZ1s.js +2 -0
  78. package/dist/owletto/dist/assets/entity-type-page-Lf6ONdpf.js +2 -0
  79. package/dist/owletto/dist/assets/event-card-CBlsG32u.js +2 -0
  80. package/dist/owletto/dist/assets/event-detail-BKSGEOdW.js +2 -0
  81. package/dist/owletto/dist/assets/events-feed-VfU4csn2.js +2 -0
  82. package/dist/owletto/dist/assets/feed-event-kinds-BYuZCoU4.js +2 -0
  83. package/dist/owletto/dist/assets/filter-bar-COU0sBFQ.js +2 -0
  84. package/dist/owletto/dist/assets/{full-page-spinner-DtmqQmgl.js → full-page-spinner-C1Q_jEzD.js} +2 -2
  85. package/dist/owletto/dist/assets/guardrails-6ZJv1uzM.js +2 -0
  86. package/dist/owletto/dist/assets/identity-BaFLmbSo.js +2 -0
  87. package/dist/owletto/dist/assets/index-008wj-Pz.js +7950 -0
  88. package/dist/owletto/dist/assets/index-BaetvYLa.js +2 -0
  89. package/dist/owletto/dist/assets/index-BiEf5xOE.css +1 -0
  90. package/dist/owletto/dist/assets/index-BrDP4PCs.js +2 -0
  91. package/dist/owletto/dist/assets/index-BuXIeK7D.js +2 -0
  92. package/dist/owletto/dist/assets/index-CAVcR9za.js +2 -0
  93. package/dist/owletto/dist/assets/index-CMLfWGPU.js +2 -0
  94. package/dist/owletto/dist/assets/index-D0YEYP7N.js +2 -0
  95. package/dist/owletto/dist/assets/{index-BhBYXtEN.js → index-DFyBbp7b.js} +2 -2
  96. package/dist/owletto/dist/assets/{index-DRbaESbJ.js → index-DNtYqkiA.js} +2 -2
  97. package/dist/owletto/dist/assets/index-DQxzeM37.js +2 -0
  98. package/dist/owletto/dist/assets/index-DkO0nPex.js +2 -0
  99. package/dist/owletto/dist/assets/index-KlRId0g6.js +2 -0
  100. package/dist/owletto/dist/assets/index-Ywnqi4A6.js +2 -0
  101. package/dist/owletto/dist/assets/index-xnxhf3Op.js +2 -0
  102. package/dist/owletto/dist/assets/{index-Bhop_otG.js → index-yIub2xUM.js} +2 -2
  103. package/dist/owletto/dist/assets/{json-diff-4sMmayDd.js → json-diff-LE_vNZrM.js} +4 -4
  104. package/dist/owletto/dist/assets/{list-skeleton-BafzvpOM.js → list-skeleton-Kzxi2OXB.js} +2 -2
  105. package/dist/owletto/dist/assets/login-DWOT6jtS.js +2 -0
  106. package/dist/owletto/dist/assets/logout-Dt_VDilG.js +2 -0
  107. package/dist/owletto/dist/assets/{member-scope-gate-Dit3MXBQ.js → member-scope-gate-De75CR7W.js} +2 -2
  108. package/dist/owletto/dist/assets/memory-browse-page-p2vIbfkC.js +74 -0
  109. package/dist/owletto/dist/assets/{model-selector-BeFuFH7p.js → model-selector-3l9lY50C.js} +2 -2
  110. package/dist/owletto/dist/assets/model-udnQ_S43.js +2 -0
  111. package/dist/owletto/dist/assets/models-CQj7GIOp.js +2 -0
  112. package/dist/owletto/dist/assets/new-BOwIHkre.js +2 -0
  113. package/dist/owletto/dist/assets/{new-ChwqLmVY.js → new-BbdwuJPm.js} +2 -2
  114. package/dist/owletto/dist/assets/new-DTuFCQhV.js +2 -0
  115. package/dist/owletto/dist/assets/{oauth-workspace-access-D15LYKSe.js → oauth-workspace-access-QPo4YwRX.js} +2 -2
  116. package/dist/owletto/dist/assets/{organization-CoUJYXx7.js → organization-BDzjnqPf.js} +2 -2
  117. package/dist/owletto/dist/assets/peek-pane-content-D7yt0PrA.js +2 -0
  118. package/dist/owletto/dist/assets/{permissions-C6UFdvz2.js → permissions-CfoY4WFY.js} +2 -2
  119. package/dist/owletto/dist/assets/{proposal-review-shell-CmLy1MZf.js → proposal-review-shell-CVkLnnKo.js} +2 -2
  120. package/dist/owletto/dist/assets/public-shell-ready-DXUTTGGp.js +2 -0
  121. package/dist/owletto/dist/assets/record-activity-BXhvJbd9.js +2 -0
  122. package/dist/owletto/dist/assets/{record-session-CJzFoVKc.js → record-session-D07szzqN.js} +2 -2
  123. package/dist/owletto/dist/assets/{linked-record-peek-B0_B4PnF.js → renderer-AJxSmE3-.js} +30 -30
  124. package/dist/owletto/dist/assets/reset-password-kRYyQuTY.js +2 -0
  125. package/dist/owletto/dist/assets/{runs-B0zVYb-w.js → runs-lG2ChtOt.js} +2 -2
  126. package/dist/owletto/dist/assets/runs-panel-LnGpHCAQ.js +2 -0
  127. package/dist/owletto/dist/assets/{schema-type-editor-panel-DcJqbCrU.js → schema-type-editor-panel-C_Es0qDf.js} +2 -2
  128. package/dist/owletto/dist/assets/settings-CEAOg7fr.js +2 -0
  129. package/dist/owletto/dist/assets/{settings-Dg0D_l_w.js → settings-gGYXbFfd.js} +2 -2
  130. package/dist/owletto/dist/assets/skills-BOL5c_Tk.js +2 -0
  131. package/dist/owletto/dist/assets/source-record-panels-CjFPgKKJ.js +2 -0
  132. package/dist/owletto/dist/assets/{status-dot-_LQZmEIX.js → status-dot-CSBtKT4g.js} +2 -2
  133. package/dist/owletto/dist/assets/table-DHM-vCxP.js +2 -0
  134. package/dist/owletto/dist/assets/use-automations-C4TSie1i.js +2 -0
  135. package/dist/owletto/dist/assets/{use-mention-search-CAFbh-Dk.js → use-mention-search-PfZrNbu_.js} +2 -2
  136. package/dist/owletto/dist/assets/use-scroll-sentinel-D-fJx_Md.js +2 -0
  137. package/dist/owletto/dist/assets/view-param-filters-DkX4YdDT.js +2 -0
  138. package/dist/owletto/dist/assets/views-access-required-2ubIf_3N.js +2 -0
  139. package/dist/owletto/dist/index.html +2 -2
  140. package/dist/server-main.bundle.mjs +99167 -97912
  141. package/npm-shrinkwrap.json +537 -896
  142. package/package.json +7 -10
  143. package/vendor/@better-auth-kysely-adapter/.bun-tag-abf95749a412716 +0 -0
  144. package/vendor/@better-auth-kysely-adapter/LICENSE.md +20 -0
  145. package/vendor/@better-auth-kysely-adapter/README.md +17 -0
  146. package/vendor/@better-auth-kysely-adapter/dist/bun-sqlite-dialect-DoOVo4ja.mjs +123 -0
  147. package/vendor/@better-auth-kysely-adapter/dist/d1-sqlite-dialect-Cru74LbR.mjs +133 -0
  148. package/vendor/@better-auth-kysely-adapter/dist/index.d.mts +116 -0
  149. package/vendor/@better-auth-kysely-adapter/dist/index.mjs +719 -0
  150. package/vendor/@better-auth-kysely-adapter/dist/node-sqlite-dialect.d.mts +27 -0
  151. package/vendor/@better-auth-kysely-adapter/dist/node-sqlite-dialect.mjs +123 -0
  152. package/vendor/@better-auth-kysely-adapter/dist/sqlite-introspector-DSCAP82F.mjs +90 -0
  153. package/vendor/@better-auth-kysely-adapter/package.json +52 -0
  154. package/vendor/connector-sdk/dist/connector-types.d.ts +29 -0
  155. package/vendor/connector-sdk/dist/index.d.ts +3 -1
  156. package/vendor/connector-sdk/dist/index.js +4 -0
  157. package/vendor/connector-sdk/dist/redact.d.ts +10 -0
  158. package/vendor/connector-sdk/dist/redact.js +130 -0
  159. package/vendor/connector-sdk/dist/types.d.ts +2 -1
  160. package/vendor/connector-sdk/package.json +6 -1
  161. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  162. package/vendor/core/dist/connector-query-errors.js +4 -0
  163. package/vendor/core/dist/contracts/tools/manage-automations.js +1 -1
  164. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  165. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +4 -0
  166. package/vendor/core/dist/contracts/tools/manage-entity.js +6 -0
  167. package/vendor/core/dist/contracts/worker/device-automation.d.ts +1 -1
  168. package/vendor/core/dist/contracts/worker/device-automation.js +1 -1
  169. package/vendor/core/dist/errors.d.ts +0 -20
  170. package/vendor/core/dist/errors.js +1 -25
  171. package/vendor/core/dist/otel.js +38 -10
  172. package/vendor/core/dist/utils/ajv.js +3 -1
  173. package/vendor/core/package.json +26 -5
  174. package/vendor/views/package.json +1 -1
  175. package/dist/owletto/dist/assets/_-Cjvw31gU.js +0 -2
  176. package/dist/owletto/dist/assets/_-iToIRRFt.js +0 -3
  177. package/dist/owletto/dist/assets/_agentId-CLdj0X7j.js +0 -2
  178. package/dist/owletto/dist/assets/_agentId-D5cAWjrP.js +0 -2
  179. package/dist/owletto/dist/assets/_automationId-BhEZmkJU.js +0 -2
  180. package/dist/owletto/dist/assets/_connectorKey._connectionId-DZtLc3WW.js +0 -2
  181. package/dist/owletto/dist/assets/_connectorKey.index-BoYpah_l.js +0 -2
  182. package/dist/owletto/dist/assets/_conversationId-ML2TjCwN.js +0 -2
  183. package/dist/owletto/dist/assets/_eventId-BYc3I2EL.js +0 -2
  184. package/dist/owletto/dist/assets/_name-BsOZmvlH.js +0 -2
  185. package/dist/owletto/dist/assets/_owner-UuyQLJ-0.js +0 -3
  186. package/dist/owletto/dist/assets/_shape-BpnVAYWH.js +0 -2
  187. package/dist/owletto/dist/assets/_skillKey-CYrGvNn-.js +0 -2
  188. package/dist/owletto/dist/assets/_viewKey-CGAJ1ucr.js +0 -2
  189. package/dist/owletto/dist/assets/_viewKey-CMkhfs1k.js +0 -2
  190. package/dist/owletto/dist/assets/agent-connect-pages-BryZas7Z.js +0 -2
  191. package/dist/owletto/dist/assets/agent-guardrails-route-D9PpDgR-.js +0 -2
  192. package/dist/owletto/dist/assets/agents-C05k-Xw6.js +0 -2
  193. package/dist/owletto/dist/assets/agents-workbench-D1YL3VAB.js +0 -2
  194. package/dist/owletto/dist/assets/app-bridge-BCm4muqj.js +0 -128
  195. package/dist/owletto/dist/assets/automations-C05k-Xw6.js +0 -2
  196. package/dist/owletto/dist/assets/client-rows-fFuxzFtE.js +0 -2
  197. package/dist/owletto/dist/assets/connect-BmCUJ3lr.js +0 -2
  198. package/dist/owletto/dist/assets/connect._clientId-B6StGCPK.js +0 -2
  199. package/dist/owletto/dist/assets/connected._clientId-CPiMA6Bx.js +0 -2
  200. package/dist/owletto/dist/assets/connected._clientId.activity-BialEDmu.js +0 -2
  201. package/dist/owletto/dist/assets/connected._clientId.index-X1wVi6v0.js +0 -2
  202. package/dist/owletto/dist/assets/connection-DJd9bnEc.js +0 -2
  203. package/dist/owletto/dist/assets/connection-feed-detail-IO6G5QjL.js +0 -2
  204. package/dist/owletto/dist/assets/connections-browser-CzdcZeiU.js +0 -2
  205. package/dist/owletto/dist/assets/copy-button-kcjg8Giw.js +0 -2
  206. package/dist/owletto/dist/assets/create-CQE5rD0i.js +0 -2
  207. package/dist/owletto/dist/assets/create-DQNlRTUX.js +0 -2
  208. package/dist/owletto/dist/assets/create-automation-form-y3tq2QIJ.js +0 -3
  209. package/dist/owletto/dist/assets/create-lOFSQV_5.js +0 -2
  210. package/dist/owletto/dist/assets/create._connectorKey-icyNicvn.js +0 -2
  211. package/dist/owletto/dist/assets/device-pin-tombstone-7UpeD4Sq.js +0 -2
  212. package/dist/owletto/dist/assets/device._deviceId-DGMmjr01.js +0 -2
  213. package/dist/owletto/dist/assets/entity-options-BcTafZ2e.js +0 -2
  214. package/dist/owletto/dist/assets/entity-page-CY7PF3X9.js +0 -2
  215. package/dist/owletto/dist/assets/entity-type-page-BzMZttzh.js +0 -2
  216. package/dist/owletto/dist/assets/event-detail-C25TvOb_.js +0 -2
  217. package/dist/owletto/dist/assets/events-feed-C4VrjIc1.js +0 -2
  218. package/dist/owletto/dist/assets/filter-editors-oNjBX9a2.js +0 -2
  219. package/dist/owletto/dist/assets/guardrails-Acfam-JF.js +0 -2
  220. package/dist/owletto/dist/assets/identity-BkK8ggdp.js +0 -2
  221. package/dist/owletto/dist/assets/index-Bw5iV_J7.js +0 -2
  222. package/dist/owletto/dist/assets/index-C3dpyynY.js +0 -2
  223. package/dist/owletto/dist/assets/index-C3zAbslo.js +0 -2
  224. package/dist/owletto/dist/assets/index-CGKN_WN_.js +0 -2
  225. package/dist/owletto/dist/assets/index-CgRaCOzW.js +0 -2
  226. package/dist/owletto/dist/assets/index-DfIoxD5Q.js +0 -2
  227. package/dist/owletto/dist/assets/index-DijuudSs.js +0 -2
  228. package/dist/owletto/dist/assets/index-Dr7bouPX.css +0 -1
  229. package/dist/owletto/dist/assets/index-JmEl29py.js +0 -7950
  230. package/dist/owletto/dist/assets/index-NK2VKPoL.js +0 -2
  231. package/dist/owletto/dist/assets/index-_5qsmBkt.js +0 -2
  232. package/dist/owletto/dist/assets/index-qkOKpRYs.js +0 -2
  233. package/dist/owletto/dist/assets/index-wzYkECAe.js +0 -2
  234. package/dist/owletto/dist/assets/login-XL5XxN6y.js +0 -2
  235. package/dist/owletto/dist/assets/logout-CMxdhLbM.js +0 -2
  236. package/dist/owletto/dist/assets/memory-browse-page-DTlM_9MY.js +0 -74
  237. package/dist/owletto/dist/assets/models-BAVaDnKN.js +0 -2
  238. package/dist/owletto/dist/assets/new-1QLuS1o-.js +0 -2
  239. package/dist/owletto/dist/assets/new-D21LGMl6.js +0 -2
  240. package/dist/owletto/dist/assets/peek-pane-content-BvkYk72J.js +0 -2
  241. package/dist/owletto/dist/assets/public-shell-ready-_awBxu2Y.js +0 -2
  242. package/dist/owletto/dist/assets/record-activity-Doeu5kPO.js +0 -2
  243. package/dist/owletto/dist/assets/reset-password-Y-WO77iR.js +0 -2
  244. package/dist/owletto/dist/assets/runs-panel-Dkyybqos.js +0 -2
  245. package/dist/owletto/dist/assets/runs-table-9OVdfPXZ.js +0 -2
  246. package/dist/owletto/dist/assets/settings-Cfy9tCOF.js +0 -2
  247. package/dist/owletto/dist/assets/skills-oxA7P5Fe.js +0 -2
  248. package/dist/owletto/dist/assets/source-record-panels-BeAZeMLy.js +0 -2
  249. package/dist/owletto/dist/assets/use-automations-DS3uz3pb.js +0 -2
  250. package/dist/owletto/dist/assets/use-scroll-sentinel-BpQ70c28.js +0 -2
  251. package/dist/owletto/dist/assets/view-param-filters-FuOZyjMg.js +0 -2
  252. package/dist/owletto/dist/assets/views-access-required-CWwlobOd.js +0 -2
@@ -1,2 +1,2 @@
1
- import{j as s,S as e}from"./index-JmEl29py.js";function m({label:r,actions:l=!1}){return s.jsx("div",{className:"overflow-hidden rounded-lg border",role:"status","aria-label":r,children:Array.from({length:4},(d,a)=>s.jsxs("div",{className:`flex items-center gap-3 px-3 py-2.5 ${a===3?"":"border-b"}`,children:[s.jsx(e,{className:"h-7 w-7 shrink-0 rounded-md"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[s.jsx(e,{className:"h-4 w-40"}),s.jsx(e,{className:"h-3 w-24"})]}),l?s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(e,{className:"h-8 w-8 rounded-md"}),s.jsx(e,{className:"h-8 w-8 rounded-md"})]}):null]},a))})}export{m as L};
2
- //# sourceMappingURL=list-skeleton-BafzvpOM.js.map
1
+ import{j as s,S as e}from"./index-008wj-Pz.js";function m({label:r,actions:l=!1}){return s.jsx("div",{className:"overflow-hidden rounded-lg border",role:"status","aria-label":r,children:Array.from({length:4},(d,a)=>s.jsxs("div",{className:`flex items-center gap-3 px-3 py-2.5 ${a===3?"":"border-b"}`,children:[s.jsx(e,{className:"h-7 w-7 shrink-0 rounded-md"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[s.jsx(e,{className:"h-4 w-40"}),s.jsx(e,{className:"h-3 w-24"})]}),l?s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(e,{className:"h-8 w-8 rounded-md"}),s.jsx(e,{className:"h-8 w-8 rounded-md"})]}):null]},a))})}export{m as L};
2
+ //# sourceMappingURL=list-skeleton-Kzxi2OXB.js.map
@@ -0,0 +1,2 @@
1
+ import{v as ke,a2 as Ne,o as Se,a3 as Ce,E as Ee,r as s,a4 as ae,j as e,a5 as b,a6 as Le,a7 as ce,a8 as $,a9 as Fe,aa as Ue,ab as Pe,$ as Me,Q as Ie,a0 as ze,ac as oe}from"./index-008wj-Pz.js";import{C as Ae,c as Re}from"./card-BCsbrdGs.js";function q(o){if(!o||typeof o!="object")return null;const f=o.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=o.message;return typeof m=="string"&&m.length>0?m:null}async function le(o,f){if(typeof window>"u")return;const m=window.PasswordCredential;if(!(!m||!navigator.credentials?.store))try{const y=new m({id:o,password:f});await navigator.credentials.store(y)}catch{}}function $e({domain:o}){const[f,m]=s.useState(!1);return!(o.length>0&&o.length<=253&&/^[A-Za-z0-9.-]+$/.test(o))||f?e.jsx(ce,{className:"w-4 h-4"}):e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${encodeURIComponent(o)}&sz=32`,alt:"",width:16,height:16,className:"h-4 w-4",onError:()=>m(!0)})}function E(o){return o?o.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.":o:null}function Oe(){const o=ke(),f=Ne(),{session:m,isReady:y}=Se(),{data:i,isLoading:F,error:B}=Ce(),l=Ee({from:"/auth/login"}),O=l.invitationOrg,[p,j]=s.useState("social"),[d,P]=s.useState(l.intent??"sign-in"),[T,de]=s.useState(""),[a,W]=s.useState(()=>l.loginHint??""),[k,ue]=s.useState(""),[N,me]=s.useState(""),[M,V]=s.useState(""),[ge,Q]=s.useState(!1),[c,u]=s.useState(null),[I,r]=s.useState(null),[J,G]=s.useState(!1),[fe,K]=s.useState(!1),[Z,pe]=s.useState(!1),X=s.useRef(!1),L=l.callbackUrl,Y=l.mode==="extension",D=l.error==="account_not_linked",ee=E(l.errorDescription||l.error),z=Object.values(i?.social??{}).some(Boolean),w=!!i?.magicLink,A=!!i?.phone,h=!!i?.emailPassword,te=!!i?.passkey,x=!!i?.singleUserMode,ne=!!i?.hasUser,H=x,U=p==="magic-link"&&w&&J,v=s.useMemo(()=>{const t=[];return h&&t.push("email-password"),z&&t.push("social"),w&&t.push("magic-link"),A&&t.push("whatsapp"),t},[h,w,z,A]),he=s.useMemo(()=>h?v.filter(t=>t!=="magic-link"&&t!=="social"):v,[v,h]),_=B instanceof Error?B.message:B?"Unable to load sign-in options.":null;s.useEffect(()=>{if(m){const t=ae(L);L?window.location.href=t:o({to:"/"})}},[m,o,L]),s.useEffect(()=>{!i||v.length===0||v.includes(p)||j(v[0])},[i,p,v]),s.useEffect(()=>{!w||!D||(j("magic-link"),l.loginHint&&!a&&W(l.loginHint))},[w,D,l.loginHint,a]),s.useEffect(()=>{l.intent&&P(l.intent)},[l.intent]),s.useEffect(()=>{if(!x||!i)return;const t=ne?"sign-in":"sign-up";d!==t&&P(t)},[x,ne,i,d]);const S=()=>L?ae(L):"/",se=async(t,{quiet:n=!1}={})=>{u(t),r(null);try{const g=await $.social({provider:t,callbackURL:S(),newUserCallbackURL:L?S():`/?onboard_provider=${encodeURIComponent(t)}`}),C=q(g);if(C&&!n){const R=E(C);R?.toLowerCase().includes("magic link")&&j("magic-link"),r(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||F||!i||l.error)return;const t=l.provider;if(!t)return;X.current=!0;const n=Object.hasOwn(i.social??{},t)&&!!i.social?.[t];se(t,{quiet:!n})},[i,F,m,y,l.provider,l.error]);const re=async()=>{if(a){u("magic-link"),r(null);try{return await $.magicLink({email:a,callbackURL:S()}),G(!0),!0}catch(t){return r(t instanceof Error?t.message:"Failed to send magic link"),!1}finally{u(null)}}},xe=async t=>{t.preventDefault(),await re()},be=async t=>{if(t.preventDefault(),!(!a||!k)){u("email-password"),r(null);try{if(d==="sign-up"){const n=await Ue.email({email:a,password:k,name:T||a.split("@")[0]||"User",callbackURL:S()}),g=q(n);if(g){r(E(g));return}if(await le(a,k),await f.invalidateQueries({queryKey:["organizations"]}),x&&te)try{await Pe.passkey.addPasskey({name:T||`${navigator.platform||"This device"}`})}catch{}}else{const n=await $.email({email:a,password:k,callbackURL:S()}),g=q(n);if(g){r(E(g));return}if(!n?.data){r("Invalid email or password");return}await le(a,k)}}catch(n){const g=n instanceof Error?n.message:typeof n=="string"?n:q(n);r(g||"Authentication failed")}finally{u(null)}}},ie=async()=>{r(null),pe(!0),u("local");try{const t=await Fe();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=S()}catch(t){r(t instanceof Error?t.message:"Could not sign in to your local install.")}finally{u(null)}};s.useEffect(()=>{H&&i&&!m&&!Z&&ie()},[H,i,m,Z]);const ye=async()=>{if(!a){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 Me(`${Ie}/api/auth/request-password-reset`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:a,redirectTo:t})});if(!n.ok)throw await ze(n);K(!0)}catch(t){r(t instanceof Error?t.message:"Failed to send password reset email")}finally{u(null)}},je=async t=>{if(t.preventDefault(),!!N){u("phone"),r(null);try{await oe.sendOtp({phoneNumber:N}),Q(!0)}catch(n){r(n instanceof Error?n.message:"Failed to send verification code")}finally{u(null)}}},we=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:O?`Sign in to join ${O}`: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:O?"Sign in with the email your invitation was sent to.":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(Ae,{children:e.jsx(Re,{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:[F&&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…"})]}),!F&&_&&e.jsxs("div",{className:"text-sm text-destructive",children:["Failed to load sign-in options. ",_]}),!F&&!_&&v.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"No sign-in methods are configured. Contact support for access."}),h&&!U&&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"})]}),!U&&he.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"}),z&&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"}),A&&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}),!U&&(h||p==="social")&&z&&e.jsxs("div",{className:"space-y-3",children:[Object.entries(i?.social??{}).filter(([,t])=>t).map(([t])=>{const n=Le.find(ve=>ve.provider===t),g=n?.icon,C=i?.socialMeta?.[t],R=n?.name??C?.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"}):C?.faviconDomain?e.jsx($e,{domain:C.faviconDomain},C.faviconDomain):e.jsx(ce,{className:"w-4 h-4"}),"Continue with ",R]},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"})})]})]}),!U&&h&&e.jsxs("form",{onSubmit:be,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=>de(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:a,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=>ue(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||!a||!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 $.passkey();if(t?.error){const n=t.error.message??"Passkey sign-in failed.";r(E(n)??n);return}window.location.href=S()}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||!a,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||!a,onClick:ye,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"&&fe&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"If this email exists, we sent a password reset link."})]}),p==="magic-link"&&w&&(J?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:a}),".",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:xe,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:a,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||!a,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"})]})),!U&&p==="whatsapp"&&A&&(ge?e.jsxs("form",{onSubmit:we,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:()=>{Q(!1),V("")},children:"Use a different number"})]}):e.jsxs("form",{onSubmit:je,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=>me(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{Oe as component};
2
+ //# sourceMappingURL=login-DWOT6jtS.js.map
@@ -0,0 +1,2 @@
1
+ import{r as n,a1 as o,j as e}from"./index-008wj-Pz.js";function s(){return n.useEffect(()=>{o().catch(t=>console.error("Sign out failed:",t)).finally(()=>{window.location.href="/"})},[]),e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Signing out..."})})}export{s as component};
2
+ //# sourceMappingURL=logout-Dt_VDilG.js.map
@@ -1,2 +1,2 @@
1
- import{j as e,S as o,k as c,an as d,s as u,aR as h,dA as b,B as p,L as x,v as g}from"./index-JmEl29py.js";function j({rows:t=5}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading members",children:Array.from({length:t}).map((n,s)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg px-3 py-2",children:[e.jsx(o,{className:"h-8 w-8 shrink-0 rounded-full"}),e.jsx(o,{className:"h-4 w-40"})]},s))})}function l({title:t,body:n,ctaLabel:s,showCta:a,callbackUrl:r}){return e.jsx(h,{icon:b,title:t,description:n,children:s&&a?e.jsx(p,{asChild:!0,className:"mt-4",children:e.jsx(x,{to:"/auth/login",search:g({callbackUrl:r,intent:"sign-in"}),children:s})}):null})}function y({children:t}){const{isAuthenticated:n,isReady:s}=c(),{isMember:a,isLoading:r}=d(),i=u({select:m=>m.href});return!s||r?e.jsx(j,{}):n?a?e.jsx(e.Fragment,{children:t}):e.jsx(l,{title:"Join to see members",body:"Emails and member details are only visible to members of this workspace. Use the banner above to join.",callbackUrl:i}):e.jsx(l,{title:"Sign in to see members",body:"The members of this workspace are only visible to people who have signed in.",ctaLabel:"Sign in",showCta:!0,callbackUrl:i})}export{y as M};
2
- //# sourceMappingURL=member-scope-gate-Dit3MXBQ.js.map
1
+ import{j as e,S as o,o as c,ap as d,w as u,a$ as h,dE as b,B as p,L as x,y as g}from"./index-008wj-Pz.js";function j({rows:t=5}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading members",children:Array.from({length:t}).map((a,s)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg px-3 py-2",children:[e.jsx(o,{className:"h-8 w-8 shrink-0 rounded-full"}),e.jsx(o,{className:"h-4 w-40"})]},s))})}function l({title:t,body:a,ctaLabel:s,showCta:n,callbackUrl:r}){return e.jsx(h,{icon:b,title:t,description:a,children:s&&n?e.jsx(p,{asChild:!0,className:"mt-4",children:e.jsx(x,{to:"/auth/login",search:g({callbackUrl:r,intent:"sign-in"}),children:s})}):null})}function y({children:t}){const{isAuthenticated:a,isReady:s}=c(),{isMember:n,isLoading:r}=d(),i=u({select:m=>m.href});return!s||r?e.jsx(j,{}):a?n?e.jsx(e.Fragment,{children:t}):e.jsx(l,{title:"Join to see members",body:"Emails and member details are only visible to members of this workspace. Use the banner above to join.",callbackUrl:i}):e.jsx(l,{title:"Sign in to see members",body:"The members of this workspace are only visible to people who have signed in.",ctaLabel:"Sign in",showCta:!0,callbackUrl:i})}export{y as M};
2
+ //# sourceMappingURL=member-scope-gate-De75CR7W.js.map
@@ -0,0 +1,74 @@
1
+ import{r as b,j as t,B as Y,d9 as mt,f5 as Os,f6 as $s,bU as As,h as de,d8 as Rt,S as ve,f7 as Ps,f8 as Ds,t as De,f9 as en,fa as Fs,fb as zs,fc as Ws,H as Pe,bv as Ft,bw as zt,bx as Wt,by as Bt,bz as yt,fd as Bs,I as rt,fe as Hs,bG as qn,ff as Gn,fg as Kn,fh as Vs,k as It,ei as Us,fi as qs,v as at,u as tn,et as Yn,aD as Gs,aE as Ks,cn as Ys,fj as Js,ax as Qs,fk as Jn,b1 as Xs,b5 as Zs,bS as Qn,W as er,L as we,X as tr,em as Xn,bW as nr,bX as sr,fl as rr,fm as ar,fn as or,b_ as ir,bP as Zn,fo as es,fp as tt,fq as jt,fr as cr,fs as lr,ft as nn,fu as dr,fv as Kt,fw as Yt,fx as ur,fy as mr,co as ts,cT as Nt,dL as fr,dd as hr,dI as sn,dK as rn,fz as ns,dJ as an,bE as pr,f1 as gr,dR as ss,a$ as rs,fA as as,eG as os,fB as qe,eT as yr,cV as nt,V as ht,eH as xr,dW as br,fC as vr,dk as wr,d0 as kr,cL as is,dM as jr,dN as Nr,dO as Sr,dP as Er,cX as vn,fD as Cr,fE as _r,cY as Mr,dF as Tr,fF as cs,fG as ls,am as Lr,fH as Rr,E as ds,fI as Ir,c7 as Ue,i as us,fJ as Ht,fK as Or,fL as $r,d3 as wn,fM as Ar,fN as Pr,bg as Dr,fO as Fr,fP as zr,bt as Wr,fQ as Br,a as Hr,fR as Vr,av as Ur}from"./index-008wj-Pz.js";import{P as qr}from"./public-shell-ready-DXUTTGGp.js";import{f as Gr,a as Kr,c as kn,d as Yr,A as Jr}from"./connector-boxes-DqZA-FdG.js";import{u as Qr}from"./use-automations-C4TSie1i.js";import{c as Xr}from"./connections-browser-BMV8bf54.js";import{d as Zr,e as ea}from"./model-udnQ_S43.js";import{c as ta}from"./connection-label-BobuYiAG.js";import{f as na}from"./feed-event-kinds-BYuZCoU4.js";import{S as sa}from"./schema-type-editor-panel-C_Es0qDf.js";import{D as ra,c as aa,l as oa,p as Ee,S as jn,n as ia,e as Ot,a as ca,g as la,f as Nn,b as da,d as ua,J as ma}from"./renderer-AJxSmE3-.js";import{S as fa,E as on}from"./entity-avatar-CEV4ttUQ.js";import{F as ha}from"./filter-bar-COU0sBFQ.js";import{T as pa,a as ga,b as Vt,c as Sn,d as ya,e as Ut}from"./table-DHM-vCxP.js";import{u as xa,a as ba,D as va,P as wa,b as ms,c as ka,C as ja}from"./core.esm-A1UnFbGs.js";import{v as Na,V as fs,M as hs,a as ps,w as Sa,b as Ea}from"./view-param-filters-DkX4YdDT.js";import{E as Ca}from"./entity-type-page-Lf6ONdpf.js";import{M as _a}from"./member-scope-gate-De75CR7W.js";function En(e){let n=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(const i of e)n=Math.min(n,i.x-i.w/2),a=Math.max(a,i.x+i.w/2),s=Math.min(s,i.y-i.h/2),r=Math.max(r,i.y+i.h/2);return Number.isFinite(n)?{x0:n,y0:s,x1:a,y1:r}:null}const St=(e,n,s)=>e<n?n:e>s?s:e;function Ma(e,n,s,{padding:a=.12,minZoom:r=.2,maxZoom:i=1.2}={}){const o=Math.max(1,e.x1-e.x0),l=Math.max(1,e.y1-e.y0),y=St(Math.min(n/(o*(1+a)),s/(l*(1+a))),r,i);return{z:y,x:n/2-(e.x0+e.x1)/2*y,y:s/2-(e.y0+e.y1)/2*y}}function Ta(e,n,s=0){if(e===n){const v=e.x+e.w/2,j=e.y-e.h/2;return[{x:v-30,y:j},{x:v-30,y:j-26},{x:v+22,y:j-26},{x:v+22,y:e.y-6},{x:v,y:e.y-6}]}const a=s*8,r=e.x+e.w/2,i=e.y+St(a,-e.h/2+6,e.h/2-6),o=n.x-n.w/2,l=n.y+St(a,-n.h/2+6,n.h/2-6);if(o-r>=40){const v=(r+o)/2+a;return[{x:r,y:i},{x:v,y:i},{x:v,y:l},{x:o,y:l}]}const y=Math.max(e.y+e.h/2,n.y+n.h/2)+24+Math.abs(a),c=Math.min(e.y-e.h/2,n.y-n.h/2)-24-Math.abs(a),x=(i+l)/2,m=Math.abs(y-x)<=Math.abs(c-x)?y:c,h=r+24+Math.abs(a),p=o-24-Math.abs(a);return[{x:r,y:i},{x:h,y:i},{x:h,y:m},{x:p,y:m},{x:p,y:l},{x:o,y:l}]}function La(e,n,s){const a=s.x-n.x,r=s.y-n.y,i=a*a+r*r,o=i?St(((e.x-n.x)*a+(e.y-n.y)*r)/i,0,1):0;return Math.hypot(e.x-(n.x+o*a),e.y-(n.y+o*r))}function Ra(e,n){let s=Number.POSITIVE_INFINITY;for(let a=0;a<n.length-1;a++)s=Math.min(s,La(e,n[a],n[a+1]));return s}function Ia(e,n){return Math.abs(n.x-e.x)<=e.w/2&&Math.abs(n.y-e.y)<=e.h/2}class et{cells=new Set;static CELL_W=12;static CELL_H=16;keys(n){const s=[],a=Math.floor(n.x0/et.CELL_W),r=Math.floor(n.x1/et.CELL_W),i=Math.floor(n.y0/et.CELL_H),o=Math.floor(n.y1/et.CELL_H);for(let l=a;l<=r;l++)for(let y=i;y<=o;y++)s.push(l*1e5+y);return s}isFree(n){return this.keys(n).every(s=>!this.cells.has(s))}reserve(n){for(const s of this.keys(n))this.cells.add(s)}}function Oa(e,n,s,a,r){const i=e.slice(0,-1).map((m,h)=>({i:h,length:Math.hypot(e[h+1].x-m.x,e[h+1].y-m.y)})).sort((m,h)=>h.length-m.length);if(i.length===0)return null;const o=m=>({x0:m.x-n/2,x1:m.x+n/2,y0:m.y-s/2,y1:m.y+s/2}),l=m=>({x:(e[m].x+e[m+1].x)/2,y:(e[m].y+e[m+1].y)/2});for(const{i:m,length:h}of i){if(!r&&h<n*.7)break;const p=l(m);if(a.isFree(o(p)))return a.reserve(o(p)),p}if(!r)return null;const y=l(i[0].i),x=[-1,1,-1.6,1.6].map(m=>({x:y.x,y:y.y+m*(s+12)})).find(m=>a.isFree(o(m)))??y;return a.reserve(o(x)),x}const $a=e=>t.jsx(Rt,{icon:e||null,className:"h-4 w-4"}),Aa='600 14px "DM Sans", system-ui, sans-serif',Pa='400 11px "DM Sans", system-ui, sans-serif',Da='500 9px "DM Sans", system-ui, sans-serif',Fa='500 11px "DM Sans", system-ui, sans-serif',dt=18,Cn=8;function _n(e){const n=getComputedStyle(e),s=(a,r)=>n.getPropertyValue(a).trim()||r;return{foreground:s("--foreground","#141414"),muted:s("--muted-foreground","#545454"),card:s("--card","#ffffff"),background:s("--background","#fcfcfb"),border:s("--border","#e7e4dc"),primary:s("--primary","#2f63e8"),mutedSurface:s("--muted","#f3f1ea")}}function xt(e,n,s){if(e.measureText(n).width<=s)return n;let a=0,r=n.length;for(;a<r;){const i=Math.ceil((a+r)/2);e.measureText(`${n.slice(0,i)}…`).width<=s?a=i:r=i-1}return`${n.slice(0,a)}…`}function za(e,n,s,a){const r=Math.hypot(s.x-n.x,s.y-n.y);if(r<1)return;const i=(s.x-n.x)/r,o=(s.y-n.y)/r;e.moveTo(s.x-i*a-o*a*.55,s.y-o*a+i*a*.55),e.lineTo(s.x,s.y),e.lineTo(s.x-i*a+o*a*.55,s.y-o*a-i*a*.55)}function gs({boxes:e,edges:n,label:s,onOpenBox:a,openLabel:r,onConnect:i,renderIcon:o=$a,className:l}){const y=b.useRef(null),c=b.useRef(null),x=b.useRef(null),m=b.useRef({z:1,x:0,y:0}),h=b.useRef({w:0,h:0,dpr:1}),p=b.useRef(!0),v=b.useRef(new Map),j=b.useRef(null),d=b.useRef(null),S=b.useRef(new Map),N=b.useRef(null),C=b.useRef(""),k=b.useRef(!1),[g,w]=b.useState(()=>new Map),[M,A]=b.useState(null),[P,D]=b.useState(null),[J,q]=b.useState(null),[se,V]=b.useState(null),[ne,he]=b.useState(0),{placed:O,movedIds:I}=b.useMemo(()=>{const _=new Map,u=new Set;for(const f of e){const E=g.get(f.id);E&&E.from.x===f.x&&E.from.y===f.y?(_.set(f.id,{...f,x:E.at.x,y:E.at.y}),u.add(f.id)):_.set(f.id,f)}return{placed:_,movedIds:u}},[e,g]),U=b.useMemo(()=>{const _=new Map;for(const f of n){const E=[f.source,f.target].sort().join("|");_.set(E,[..._.get(E)??[],f])}const u=new Map;for(const f of n){const E=O.get(f.source),T=O.get(f.target);if(!E||!T)continue;if(f.route&&!I.has(E.id)&&!I.has(T.id)){u.set(f.id,f.route);continue}const L=_.get([f.source,f.target].sort().join("|"))??[f];u.set(f.id,Ta(E,T,L.indexOf(f)-(L.length-1)/2))}return u},[n,O,I]),H=b.useCallback(()=>{p.current=!0},[]),W=b.useCallback(()=>{const _=En([...O.values()]),{w:u,h:f}=h.current;!_||!u||!f||(m.current=Ma(_,u,f),k.current=!0,H())},[O,H]),Q=_=>{m.current=_,k.current=!1,H()},re=_=>{const u=En(_),{w:f,h:E}=h.current;if(!u||!f||!E)return;const T=m.current,L=24;u.x0*T.z+T.x>=L&&u.y0*T.z+T.y>=L&&u.x1*T.z+T.x<=f-L&&u.y1*T.z+T.y<=E-L||Q({...T,x:f/2-(u.x0+u.x1)/2*T.z,y:E/2-(u.y0+u.y1)/2*T.z})},pe=_=>{V(_);const u=O.get(_);u&&re([u])},ue=e.map(_=>`${_.id}@${Math.round(_.x)},${Math.round(_.y)}`).join(";");b.useEffect(()=>{!ue||C.current===ue||h.current.w&&(C.current=ue,W())},[ue,W]);const Ce=b.useRef(W);Ce.current=W;const Fe=b.useRef(ue);Fe.current=ue,b.useEffect(()=>{const _=y.current,u=c.current;if(!_||!u||typeof ResizeObserver>"u")return;const f=()=>{const T=window.devicePixelRatio||1,L=_.clientWidth,z=_.clientHeight;h.current={w:L,h:z,dpr:T},u.width=Math.round(L*T),u.height=Math.round(z*T);const G=Fe.current;G&&L&&z&&(C.current!==G||k.current)&&(C.current=G,Ce.current()),H()};f();const E=new ResizeObserver(f);return E.observe(_),()=>E.disconnect()},[H]);const[Ne,Ge]=b.useState(0);b.useEffect(()=>{const _=x.current,u=c.current;if(!_||!u)return;const f=_n(u).muted;for(const E of _.querySelectorAll("[data-icon-key]")){const T=E.dataset.iconKey??"";if(v.current.has(T))continue;const L=E.querySelector("svg"),z=L?null:E.querySelector("img")?.src;if(!L&&!z){v.current.set(T,E.textContent??"");continue}const G=new Image;if(G.onload=H,G.onerror=()=>{v.current.delete(T),Ge(B=>B+1)},L){const B=L.cloneNode(!0);B.getAttribute("width")||B.setAttribute("width","24"),B.getAttribute("height")||B.setAttribute("height","24");const F=new XMLSerializer().serializeToString(B).replaceAll("currentColor",f);G.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(F)}`}else z&&(G.src=z);v.current.set(T,G)}},[e,ne,Ne,H]);const _e=(_,u)=>{const f=m.current;return{x:(_-f.x)/f.z,y:(u-f.y)/f.z}},ze=(_,u)=>{const f=m.current,E=_e(_,u),T=M&&M.kind!=="edge"?O.get(M.box.id):void 0;if(T&&i){const B=Mn(T);if(Math.hypot(B.x*f.z+f.x-_,B.y*f.z+f.y-u)<=Cn+3)return{kind:"handle",box:T}}const L=[...O.values()];for(let B=L.length-1;B>=0;B--)if(Ia(L[B],E))return{kind:"box",box:L[B]};let z=null,G=7/f.z;for(const B of n){const F=U.get(B.id);if(!F)continue;const me=Ra(E,F);me<G&&(G=me,z=B)}return z?{kind:"edge",edge:z}:null},ye=b.useMemo(()=>{const _=new Set;for(const f of[P,J])f&&_.add(f);M?.kind==="edge"&&_.add(M.edge.id);const u=M&&M.kind!=="edge"?M.box.id:se;if(u)for(const f of n)(f.source===u||f.target===u)&&_.add(f.id);for(const f of n)f.dimmed&&_.delete(f.id);return _},[n,M,P,J,se]);b.useEffect(H,[O,U,ye,M,se,H]);const Le=b.useCallback(()=>{const _=c.current,u=_?.getContext("2d");if(!_||!u)return;const{w:f,h:E,dpr:T}=h.current,L=_n(_),z=getComputedStyle(_),G=new Map,B=$=>{let Z=G.get($);return Z===void 0&&(Z=z.getPropertyValue($).trim(),G.set($,Z)),Z},{z:F,x:me,y:le}=m.current,Se=$=>({x:$.x*F+me,y:$.y*F+le});u.setTransform(T,0,0,T,0,0),u.clearRect(0,0,f,E);const Oe=M&&M.kind!=="edge"?M.box.id:null;u.lineJoin="round";for(const $ of n){const Z=U.get($.id);if(!Z)continue;const te=Z.map(Se),K=ye.has($.id);u.globalAlpha=$.dimmed?.15:K?.95:.55,u.strokeStyle=K?L.foreground:L.muted,u.lineWidth=K?1.75:1.25,u.beginPath(),u.moveTo(te[0].x,te[0].y);for(const ae of te.slice(1))u.lineTo(ae.x,ae.y);$.directed&&za(u,te[te.length-2],te[te.length-1],8),u.stroke()}const Ke=new et;for(const $ of O.values()){const Z=Se($),te=$.w*F,K=$.h*F,ae=Z.x-te/2,X=Z.y-K/2;if(Ke.reserve({x0:ae,y0:X,x1:ae+te,y1:X+K}),ae>f||X>E||ae+te<0||X+K<0)continue;const Ae=Oe===$.id||N.current?.over?.id===$.id;u.globalAlpha=$.dimmed?.25:1,u.beginPath(),u.roundRect(ae,X,te,K,8*F),u.fillStyle=$.muted?L.mutedSurface:L.card,u.fill(),u.lineWidth=Ae||se===$.id?1.5:1,u.strokeStyle=Ae||se===$.id?L.primary:L.border,u.stroke();const ie=$.accent&&B($.accent);if(ie&&(u.save(),u.clip(),u.fillStyle=ie,u.fillRect(ae,X,3*F,K),u.restore()),14*F<5)continue;const ge=12*F,oe=16*F,fe=$.meta?X+K/2-8*F:X+K/2,Me=v.current.get($.icon??"");Me instanceof HTMLImageElement&&Me.complete&&Me.naturalWidth>0?u.drawImage(Me,ae+ge,fe-oe/2,oe,oe):typeof Me=="string"&&Me&&(u.font=`${14*F}px system-ui, sans-serif`,u.textBaseline="middle",u.textAlign="left",u.fillText(Me,ae+ge,fe));const He=ae+ge+oe+8*F,it=12*F;u.textBaseline="middle",u.textAlign="left";let Qe=ae+te-it-He;if($.badge){u.font=Da.replace("9px",`${9*F}px`);const ct=xt(u,$.badge.toUpperCase(),Qe*.35),Xe=u.measureText(ct).width+8*F,lt=ae+te-it-Xe;u.strokeStyle=L.border,u.lineWidth=1,u.beginPath(),u.roundRect(lt,fe-7*F,Xe,14*F,3*F),u.stroke(),u.fillStyle=L.muted,u.fillText(ct,lt+4*F,fe+.5),Qe-=Xe+6*F}u.font=Aa.replace("14px",`${14*F}px`),u.fillStyle=L.foreground,u.fillText(xt(u,$.title,Qe),He,fe+.5),$.meta&&(u.font=Pa.replace("11px",`${11*F}px`),u.fillStyle=L.muted,u.fillText(xt(u,$.meta,ae+te-ge-He),He,X+K/2+10*F))}const $e=N.current,Ye=$e?.from??(Oe?O.get(Oe):void 0);if(i&&Ye&&Ye.w*F>=60){const $=Se(Mn(Ye));if(u.globalAlpha=1,$e){const Z=Se($e.to);u.strokeStyle=L.primary,u.lineWidth=2,u.setLineDash([6,4]),u.beginPath(),u.moveTo($.x,$.y),u.lineTo(Z.x,Z.y),u.stroke(),u.setLineDash([])}u.fillStyle=L.card,u.strokeStyle=L.primary,u.lineWidth=1.5,u.beginPath(),u.arc($.x,$.y,Cn,0,Math.PI*2),u.fill(),u.stroke(),u.beginPath(),u.moveTo($.x-4,$.y),u.lineTo($.x+4,$.y),u.moveTo($.x,$.y-4),u.lineTo($.x,$.y+4),u.stroke()}u.font=Fa,u.textAlign="center",u.textBaseline="middle";const Je=($,Z,te,K)=>{u.globalAlpha=1,u.fillStyle=L.background,u.strokeStyle=te?L.foreground:L.border,u.lineWidth=1,u.beginPath(),u.roundRect($.x-K/2,$.y-dt/2,K,dt,5),u.fill(),u.stroke(),u.fillStyle=te?L.foreground:L.muted,u.fillText(Z,$.x,$.y+.5)},$t=[...n].sort(($,Z)=>Number(ye.has(Z.id))-Number(ye.has($.id)));for(const $ of $t){const Z=U.get($.id);if(!Z||$.dimmed&&!ye.has($.id))continue;const te=Z.map(Se),K=ye.has($.id),X=(K?$.details:[$.summary]).map(oe=>xt(u,oe,200)),Ae=Math.max(...X.map(oe=>u.measureText(oe).width))+14,ie=X.length*(dt+2);if(!K&&F<.45)continue;const ge=Oa(te,Ae,ie,Ke,K);ge&&X.forEach((oe,fe)=>{Je({x:ge.x,y:ge.y-ie/2+(dt+2)*fe+dt/2},oe,K,Ae)})}u.globalAlpha=1},[n,U,O,ye,M,se,i]);b.useEffect(()=>{let _=0;const u=()=>{_=requestAnimationFrame(u),p.current&&(p.current=!1,Le())};return _=requestAnimationFrame(u),document.addEventListener("visibilitychange",H),()=>{cancelAnimationFrame(_),document.removeEventListener("visibilitychange",H)}},[Le,H]),b.useEffect(()=>{const _=new MutationObserver(()=>{v.current.clear(),he(u=>u+1),H()});return _.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),()=>_.disconnect()},[H]);const xe=(_,u,f)=>{const E=m.current,T=Math.min(3,Math.max(.15,E.z*_));Q({z:T,x:u-(u-E.x)*(T/E.z),y:f-(f-E.y)*(T/E.z)})},Re=_=>{const u=c.current?.getBoundingClientRect();return{x:_.clientX-(u?.left??0),y:_.clientY-(u?.top??0)}},ce=_=>{if(_.button!==0&&_.pointerType==="mouse")return;_.currentTarget.setPointerCapture(_.pointerId);const u=Re(_);if(_.pointerType==="touch"&&(S.current.set(_.pointerId,u),S.current.size===2)){const[T,L]=[...S.current.values()];j.current=null,N.current=null,d.current={d:Math.hypot(T.x-L.x,T.y-L.y)||1,mid:{x:(T.x+L.x)/2,y:(T.y+L.y)/2}};return}const f=ze(u.x,u.y),E={start:u,last:u,hit:f,moved:!1};if(f?.kind==="handle")N.current={from:f.box,to:_e(u.x,u.y),over:null};else if(f?.kind==="box"){const T=_e(u.x,u.y);E.grab={x:f.box.x-T.x,y:f.box.y-T.y}}j.current=E},ot=_=>{const u=Re(_);S.current.has(_.pointerId)&&S.current.set(_.pointerId,u);const f=d.current;if(f&&S.current.size===2){const[B,F]=[...S.current.values()],me=Math.hypot(B.x-F.x,B.y-F.y)||1,le={x:(B.x+F.x)/2,y:(B.y+F.y)/2};Q({...m.current,x:m.current.x+le.x-f.mid.x,y:m.current.y+le.y-f.mid.y}),xe(me/f.d,le.x,le.y),d.current={d:me,mid:le};return}const E=j.current;if(!E){const B=ze(u.x,u.y);A(me=>Wa(me,B)?me:B);const F=c.current;F&&(F.style.cursor=B?.kind==="handle"?"crosshair":B?"pointer":"grab");return}const T=u.x-E.last.x,L=u.y-E.last.y;if(E.last=u,!E.moved&&Math.hypot(u.x-E.start.x,u.y-E.start.y)>4&&(E.moved=!0),!E.moved)return;const z=N.current;if(z){z.to=_e(u.x,u.y);const B=ze(u.x,u.y);z.over=B?.kind==="box"?B.box:null,H();return}const G=E.hit;if(G?.kind==="box"&&E.grab){const B=_e(u.x,u.y),F=e.find(le=>le.id===G.box.id);if(!F)return;const me={x:B.x+E.grab.x,y:B.y+E.grab.y};w(le=>new Map(le).set(F.id,{at:me,from:{x:F.x,y:F.y}}));return}Q({...m.current,x:m.current.x+T,y:m.current.y+L}),c.current&&(c.current.style.cursor="grabbing")},ke=_=>{if(S.current.delete(_.pointerId),d.current){S.current.size<2&&(d.current=null),j.current=null;return}const u=j.current;j.current=null;const f=N.current;if(N.current=null,!u)return;if(c.current&&(c.current.style.cursor="grab"),f){H(),f.over&&i&&i(f.from.id,f.over.id);return}if(u.moved)return;const E=u.hit;E?.kind==="box"?a(E.box.id):E?.kind==="edge"?D(T=>T===E.edge.id?null:E.edge.id):D(null)},Ie=_=>{S.current.delete(_.pointerId),d.current=null,j.current=null,N.current=null,H()};b.useEffect(()=>{const _=c.current;if(!_)return;const u=f=>{f.preventDefault();const E=Re(f);f.ctrlKey||f.metaKey?xe(Math.exp(-f.deltaY*(f.ctrlKey?.01:.002)),E.x,E.y):Q({...m.current,x:m.current.x-f.deltaX,y:m.current.y-f.deltaY})};return _.addEventListener("wheel",u,{passive:!1}),()=>_.removeEventListener("wheel",u)});const We=_=>xe(_,h.current.w/2,h.current.h/2),Be=[...new Set(e.map(_=>_.icon??""))];return t.jsxs("div",{ref:y,className:de("relative h-full w-full overflow-hidden",l),children:[t.jsx("canvas",{ref:c,"aria-hidden":"true",className:"block h-full w-full cursor-grab touch-none",onPointerDown:ce,onPointerMove:ot,onPointerUp:ke,onPointerCancel:Ie,onPointerLeave:()=>{j.current||A(null)}}),t.jsxs("ul",{ref:x,"aria-label":s,className:"sr-only",children:[Be.map(_=>t.jsx("li",{"aria-hidden":"true","data-icon-key":_,children:o(_)},`icon:${_}`)),e.map(_=>t.jsx("li",{children:t.jsx("button",{type:"button",onClick:()=>a(_.id),onFocus:()=>pe(_.id),onBlur:()=>V(null),children:r(_)})},_.id)),n.map(_=>t.jsx("li",{"data-revealed":ye.has(_.id)||void 0,children:t.jsx("button",{type:"button","aria-pressed":P===_.id,onClick:()=>D(u=>u===_.id?null:_.id),onFocus:()=>{q(_.id);const u=U.get(_.id);u&&re(u.map(f=>({...f,w:0,h:0})))},onBlur:()=>q(null),children:_.ariaLabel})},_.id))]}),t.jsxs("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:[t.jsx(Y,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom in",onClick:()=>We(1.25),children:t.jsx(mt,{className:"h-3.5 w-3.5"})}),t.jsx(Y,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom out",onClick:()=>We(.8),children:t.jsx(Os,{className:"h-3.5 w-3.5"})}),t.jsx(Y,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Fit to view",onClick:W,children:t.jsx($s,{className:"h-3.5 w-3.5"})}),I.size>0?t.jsx(Y,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Reset layout",onClick:()=>w(new Map),children:t.jsx(As,{className:"h-3.5 w-3.5"})}):null]})]})}const Mn=e=>({x:e.x+e.w/2,y:e.y});function Wa(e,n){return!e||!n?e===n:e.kind==="edge"||n.kind==="edge"?e.kind==="edge"&&n.kind==="edge"&&e.edge.id===n.edge.id:e.kind===n.kind&&e.box.id===n.box.id}function cn({label:e,fill:n=!1,schemaActions:s=!1}){return t.jsxs("div",{role:"status","aria-label":e,"aria-busy":"true",className:de("flex min-w-0 flex-col gap-3",n&&"min-h-0 flex-1"),children:[t.jsx("div",{"aria-hidden":"true",children:t.jsx(ve,{className:"h-5 w-3/4 max-w-xl rounded-none"})}),t.jsxs("div",{className:de("relative flex min-h-0 flex-col",n&&"flex-1"),"aria-hidden":"true",children:[s?t.jsxs("div",{className:"z-10 flex flex-wrap justify-end gap-2 lg:absolute lg:top-0 lg:right-0",children:[t.jsx(ve,{className:"h-8 w-40 rounded-none"}),t.jsx(ve,{className:"h-8 w-36 rounded-none"})]}):null,t.jsxs("div",{className:de("relative min-h-[420px]",n?"flex-1":"h-[70vh]"),children:[t.jsxs("div",{className:"absolute top-1/2 left-1/2 flex h-16 w-52 -translate-x-1/2 -translate-y-1/2 items-center gap-3 rounded-xl border border-border bg-card px-4",children:[t.jsx(ve,{className:"h-4 w-4 shrink-0 rounded-none"}),t.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[t.jsx(ve,{className:"h-3.5 w-24 rounded-none"}),t.jsx(ve,{className:"h-2.5 w-32 rounded-none"})]})]}),t.jsx("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:["in","out","fit"].map(a=>t.jsx("div",{className:"flex h-7 w-7 items-center justify-center border border-input bg-background",children:t.jsx(ve,{className:"h-3 w-3 rounded-none"})},a))})]})]})]})}function bt(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var qt={exports:{}},Tn;function Ba(){return Tn||(Tn=1,(function(e,n){(function(s){e.exports=s()})(function(){return(function(){function s(a,r,i){function o(c,x){if(!r[c]){if(!a[c]){var m=typeof bt=="function"&&bt;if(!x&&m)return m(c,!0);if(l)return l(c,!0);var h=new Error("Cannot find module '"+c+"'");throw h.code="MODULE_NOT_FOUND",h}var p=r[c]={exports:{}};a[c][0].call(p.exports,function(v){var j=a[c][1][v];return o(j||v)},p,p.exports,s,a,r,i)}return r[c].exports}for(var l=typeof bt=="function"&&bt,y=0;y<i.length;y++)o(i[y]);return o}return s})()({1:[function(s,a,r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;function i(h){"@babel/helpers - typeof";return i=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(p){return typeof p}:function(p){return p&&typeof Symbol=="function"&&p.constructor===Symbol&&p!==Symbol.prototype?"symbol":typeof p},i(h)}function o(h,p){if(!(h instanceof p))throw new TypeError("Cannot call a class as a function")}function l(h,p){for(var v=0;v<p.length;v++){var j=p[v];j.enumerable=j.enumerable||!1,j.configurable=!0,"value"in j&&(j.writable=!0),Object.defineProperty(h,c(j.key),j)}}function y(h,p,v){return p&&l(h.prototype,p),Object.defineProperty(h,"prototype",{writable:!1}),h}function c(h){var p=x(h,"string");return i(p)=="symbol"?p:p+""}function x(h,p){if(i(h)!="object"||!h)return h;var v=h[Symbol.toPrimitive];if(v!==void 0){var j=v.call(h,p);if(i(j)!="object")return j;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(h)}r.default=(function(){function h(){var p=this,v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},j=v.defaultLayoutOptions,d=j===void 0?{}:j,S=v.algorithms,N=S===void 0?["layered","stress","mrtree","radial","force","disco","sporeOverlap","sporeCompaction","rectpacking"]:S,C=v.workerFactory,k=v.workerUrl;if(o(this,h),this.defaultLayoutOptions=d,this.initialized=!1,typeof k>"u"&&typeof C>"u")throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");var g=C;typeof k<"u"&&typeof C>"u"&&(g=function(A){return new Worker(A)});var w=g(k);if(typeof w.postMessage!="function")throw new TypeError("Created worker does not provide the required 'postMessage' function.");this.worker=new m(w),this.worker.postMessage({cmd:"register",algorithms:N}).then(function(M){return p.initialized=!0}).catch(console.err)}return y(h,[{key:"layout",value:function(v){var j=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d=j.layoutOptions,S=d===void 0?this.defaultLayoutOptions:d,N=j.logging,C=N===void 0?!1:N,k=j.measureExecutionTime,g=k===void 0?!1:k;return v?this.worker.postMessage({cmd:"layout",graph:v,layoutOptions:S,options:{logging:C,measureExecutionTime:g}}):Promise.reject(new Error("Missing mandatory parameter 'graph'."))}},{key:"knownLayoutAlgorithms",value:function(){return this.worker.postMessage({cmd:"algorithms"})}},{key:"knownLayoutOptions",value:function(){return this.worker.postMessage({cmd:"options"})}},{key:"knownLayoutCategories",value:function(){return this.worker.postMessage({cmd:"categories"})}},{key:"terminateWorker",value:function(){this.worker&&this.worker.terminate()}}])})();var m=(function(){function h(p){var v=this;if(o(this,h),p===void 0)throw new Error("Missing mandatory parameter 'worker'.");this.resolvers={},this.worker=p,this.worker.onmessage=function(j){setTimeout(function(){v.receive(v,j)},0)}}return y(h,[{key:"postMessage",value:function(v){var j=this.id||0;this.id=j+1,v.id=j;var d=this;return new Promise(function(S,N){d.resolvers[j]=function(C,k){C?(d.convertGwtStyleError(C),N(C)):S(k)},d.worker.postMessage(v)})}},{key:"receive",value:function(v,j){var d=j.data,S=v.resolvers[d.id];S&&(delete v.resolvers[d.id],d.error?S(d.error):S(null,d.data))}},{key:"terminate",value:function(){this.worker&&this.worker.terminate()}},{key:"convertGwtStyleError",value:function(v){if(v){var j=v.__java$exception;j&&(j.cause&&j.cause.backingJsObject&&(v.cause=j.cause.backingJsObject,this.convertGwtStyleError(v.cause)),delete v.__java$exception)}}}])})()},{}],2:[function(s,a,r){var i=s("./elk-api.js").default;Object.defineProperty(a.exports,"__esModule",{value:!0}),a.exports=i,i.default=i},{"./elk-api.js":1}]},{},[2])(2)})})(qt)),qt.exports}var Ha=Ba();const Va=Ps(Ha);function Ua(e){return new Worker("/assets/elk-worker.min-BENGc9gn.js",{name:e?.name})}const qa=200,Ga=320,st=56,Ka=7.4,Ya=5.9,Ja=84,Qa=48;function ft(e,n){return Math.round(Math.min(Ga,Math.max(qa,Ja+e.length*Ka,Qa+n.length*Ya)))}function Xa(e,n){const s=[];return e>0&&s.push(`${e} ${e===1?"field":"fields"}`),typeof n=="number"&&s.push(`${n.toLocaleString()} ${n===1?"record":"records"}`),s.join(" · ")}function Ln(e,n){return e.slug<n.slug?-1:e.slug>n.slug?1:0}function ys(e,n){const s=new Set;return e.filter(a=>a.status!=="active"||a.organization_slug&&a.organization_slug!==n||s.has(a.slug)?!1:(s.add(a.slug),!0))}function Za(e){const n=e.metadata_schema;if(!n||typeof n!="object")return 0;const s=n.properties;return!s||typeof s!="object"?0:Object.keys(s).length}function xs(e){const{entityTypes:n,relationshipTypes:s,rulesBySlug:a}=e,r=e.ownerSlug??"",i=[...n].sort(Ln),o=ys(s,r).sort(Ln),l=g=>!g.organization_slug||g.organization_slug===r,y=g=>g.organization_slug||r,c=new Map;for(const g of i)c.set(g.slug,[...c.get(g.slug)??[],g]);const x=g=>(c.get(g.slug)?.length??0)>1?`${y(g)}:${g.slug}`:g.slug,m=new Set(i.filter(l).map(x)),h=g=>{const w=c.get(g)??[];return w.find(l)??(w.length===1?w[0]:void 0)},p=new Set(m),v=o.flatMap(g=>[...a[g.slug]??[]].sort((w,M)=>w.id-M.id).flatMap(w=>{const M=h(w.source_entity_type_slug),A=h(w.target_entity_type_slug);if(!M||!A)return[];const P=x(M),D=x(A);return!m.has(P)&&!m.has(D)?[]:(p.add(P),p.add(D),[{rt:g,source:P,target:D}])})),j=i.filter(g=>p.has(x(g))),d=[],S=new Map,N=new Map;for(const{rt:g,source:w,target:M}of v){const A=`${g.slug}|${w}|${M}`,P=N.get(A);if(P){P.ruleCount+=1;continue}const D={slug:g.slug,label:g.name||g.slug,ruleCount:1};N.set(A,D);const J=`${w}|${M}`,q=S.get(J);if(q){q.data.relationships.push(D),q.data.isSymmetric=q.data.isSymmetric&&g.is_symmetric;continue}const se={id:`pair:${w}|${M}`,source:w,target:M,data:{relationships:[D],isSymmetric:g.is_symmetric}};S.set(J,se),d.push(se)}const C=new Map;for(const{rt:g,source:w,target:M}of v){const A=C.get(g.slug)??new Set;A.add(`${w}|${M}`),C.set(g.slug,A)}for(const{rt:g}of v)if(C.get(g.slug)?.size===1&&typeof g.relationship_count=="number")for(const w of N.values())w.slug===g.slug&&(w.linkCount=g.relationship_count);return{nodes:j.map(g=>{const w=g.name||g.slug,M=Za(g),A=Xa(M,g.entity_count);return{id:x(g),width:ft(w,A),height:st,data:{slug:g.slug,label:w,icon:g.icon,isSystem:Ds(g),organizationSlug:l(g)?void 0:y(g),metaLabel:A}}}),edges:d}}const Ve=24,eo=72,to=16;let Rn=null;function no(){return Rn??=new Va({workerFactory:()=>new Ua}),Rn}const Gt={"elk.algorithm":"layered","elk.direction":"RIGHT","elk.edgeRouting":"ORTHOGONAL","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"24","elk.layered.spacing.nodeNodeBetweenLayers":"80","elk.spacing.nodeNode":"48","elk.spacing.edgeEdge":"14","elk.spacing.edgeNode":"24","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.crossingMinimization.semiInteractive":"true"};async function ln(e,{elk:n=no(),targetAspect:s}={}){const a=new Set;for(const d of e.edges)a.add(d.source),a.add(d.target);const r=e.nodes.some(d=>d.lane!==void 0),i=e.nodes.filter(d=>r||a.has(d.id)),o=e.nodes.filter(d=>!r&&!a.has(d.id)),l=o.reduce((d,S)=>Math.max(d,S.width),0),y=o.length>0?Ve+l+eo:0,c=d=>({x:d.x+Ve+y,y:d.y+Ve});let x=[];const m=new Map;if(i.length>0){const d=e.edges.filter(g=>g.source!==g.target),S=g=>n.layout({id:"root",layoutOptions:r?{...g,"elk.partitioning.activate":"true"}:g,children:i.map(w=>({id:w.id,width:w.width,height:w.height,...r?{layoutOptions:{"elk.partitioning.partition":String(w.lane??1)}}:{}})),edges:d.map(w=>({id:w.id,sources:[w.layoutReversed?w.target:w.source],targets:[w.layoutReversed?w.source:w.target]}))});let N=await S(Gt);const C=s&&N.width&&N.height?s*N.width/N.height:1;if(C>1.08){const g=Number(Gt["elk.spacing.nodeNode"]),w=Math.min(C,2.2);N=await S({...Gt,"elk.spacing.nodeNode":String(Math.round(Math.min(180,g*w+st*(w-1))))})}const k=new Map((N.children??[]).map(g=>[g.id,g]));x=i.map(g=>{const w=k.get(g.id);return{...g,position:c({x:w?.x??0,y:w?.y??0})}});for(const g of N.edges??[]){const w=(g.sections??[]).flatMap(A=>[A.startPoint,...A.bendPoints??[],A.endPoint]);if(w.length<2)continue;const M=e.edges.find(A=>A.id===g.id)?.layoutReversed;m.set(g.id,(M?[...w].reverse():w).map(c))}}let h=Ve;const p=o.map(d=>{const S={x:Ve,y:h};return h+=d.height+to,{...d,position:S}}),v=new Map([...x,...p].map(d=>[d.id,d]));return{nodes:e.nodes.map(d=>v.get(d.id)??{...d,position:{x:Ve,y:Ve}}),edges:e.edges.map(d=>({...d,route:m.get(d.id)??null}))}}function so(e,n){return ln(xs(e),n)}const Jt="connector:",In=e=>`${Jt}${e}`,ro={event:"Zap",schedule:"CalendarClock",manual:"Hand"},ao=0,oo=1,On=2;function io(e,n){const s=new Map;for(const{kind:a,targets:r}of na(e?.feeds_schema?.[n]))for(const{entityType:i,creates:o}of r){const l=s.get(i)??{creates:!1,eventKinds:new Set};l.creates||=o,l.eventKinds.add(a),s.set(i,l)}return s}function co(e,n){const s=new Map(e.connectorDefs.map(d=>[d.key,d])),a=new Map(e.connectorDefs.map(d=>[d.key,d.name])),r=new Map(e.connections.map(d=>[d.id,d])),i=Gr(e.feeds),o=d=>`connection:${d}`,l=d=>`automation:${d}`,y=[],c=new Set,x=(d,S,N,C,k=!1)=>{y.push({id:`flow:${d}->${S}`,source:d,target:S,layoutReversed:k,data:{relationships:[],isSymmetric:!1,flow:{summary:N,details:C}}}),c.add(d),c.add(S)},m=new Set(e.connections.map(d=>d.id));for(const d of e.connections){const S=new Map;for(const N of i.get(d.id)??[]){const C=io(s.get(d.connector_key),N.feed_key);for(const[k,g]of C){const w=S.get(k)??{creates:!1,eventKinds:new Set};w.creates||=g.creates;for(const M of g.eventKinds)w.eventKinds.add(M);S.set(k,w)}}for(const[N,C]of S){const k=n.get(N);k&&x(o(d.id),k,C.creates?"creates records":"links records",[`From ${[...C.eventKinds].sort().join(", ")} events`])}}const h=Kr(e.automations);for(const[d,S]of h)if(m.has(d))for(const{automation:N,reason:C,eventTypes:k}of S){const g=l(N.automation_id);C==="trigger"?x(o(d),g,kn.trigger,k.length>0?[`On ${[...k].sort().join(", ")}`]:[]):x(g,o(d),kn.delivery,[],!0)}const p=[];for(const d of e.automations){const S=l(d.automation_id),N=d.entity_type?n.get(d.entity_type):void 0;N&&x(N,S,"anchored here",[d.entity_name?`On ${d.entity_name}`:""].filter(Boolean));const C=Zr(d,a,r),k=ea(d),g=d.health==="degraded"?"Needs attention":void 0;p.push({id:S,lane:On,width:ft(`${C.does} ${g??""}`,C.when),height:st,data:{slug:S,label:C.does,icon:k?In(k):ro[C.kind],isSystem:!1,badge:g,metaLabel:C.when,ref:{kind:"automation",automationId:d.automation_id}}})}const v=[];for(const d of e.metrics){const S=n.get(d.typeSlug);if(!S)continue;const N=`metric:${d.typeSlug}:${d.name}`;x(S,N,"measures",[d.description].filter(Boolean)),v.push({id:N,lane:On,width:ft(d.name,d.agg),height:st,data:{slug:N,label:d.name,icon:"ChartColumn",isSystem:!1,metaLabel:d.agg,ref:{kind:"metric",typeSlug:d.typeSlug,name:d.name}}})}return{nodes:[...e.connections.filter(d=>c.has(o(d.id))).map(d=>{const S=ta(d),N=Xr(d,s.get(d.connector_key)),C=Yr({feeds:i.get(d.id)?.length||d.feed_count,actions:d.operations_summary?.total??0,automations:h.get(d.id)?.length??0}),k=N.needsAttention?"Needs attention":d.device_label??void 0;return{id:o(d.id),lane:ao,width:ft(`${S} ${k??""}`,C),height:st,data:{slug:o(d.id),label:S,icon:In(d.connector_key),isSystem:!1,badge:k,metaLabel:C,ref:{kind:"connection",connectorKey:d.connector_key,connectionId:d.id}}}}),...p,...v],edges:y}}function ut(e){switch(e.data.ref?.kind){case"connection":return"connections";case"automation":return"automations";case"metric":return"metrics";default:return"entities"}}function lo(e,n){const s=new Map;for(const x of e.nodes)(!x.data.organizationSlug||!s.has(x.data.slug))&&s.set(x.data.slug,x.id);const a=co(n,s),{layers:r}=n,i=[...a.nodes,...e.nodes.map(x=>({...x,lane:oo}))],o=new Set(i.filter(x=>r[ut(x)]).map(x=>x.id)),l=[...e.edges,...a.edges].filter(x=>o.has(x.source)&&o.has(x.target)),y=new Set(l.flatMap(x=>[x.source,x.target]));return{graph:{nodes:i.filter(x=>o.has(x.id)&&(ut(x)==="entities"||ut(x)==="automations"||y.has(x.id))),edges:l},hidden:{connections:r.connections?n.connections.length-a.nodes.filter(x=>ut(x)==="connections").length:0}}}const $n="__new__";function An(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}function uo({entityTypes:e,initialSource:n="",initialTarget:s="",onDone:a}){const r=b.useId(),i=`${r}-relationship`,o=`${r}-name`,l=`${r}-symmetric`,y=`${r}-source`,c=`${r}-target`,{orgContext:x}=De(),{data:m=[]}=en(x),h=Fs(),p=zs(),[v,j]=b.useState(""),[d,S]=b.useState(""),[N,C]=b.useState(!1),[k,g]=b.useState(n),[w,M]=b.useState(s),[A,P]=b.useState(null),D=v===$n,J=m.filter(V=>V.status==="active"&&V.purpose!==Ws&&(!V.organization_slug||V.organization_slug===x?.slug)),q=h.isPending||p.isPending,se=async()=>{if(P(null),!v)return P("Pick a relationship");if(!k||!w)return P("Pick both ends");try{let V=v;if(D){const ne=d.trim();if(!ne)return P("Name the relationship");const he=An(ne);if(!he)return P("Name must contain a letter or number");V=(await h.mutateAsync({slug:he,name:ne,is_symmetric:N})).relationship_type.slug,j(V)}await p.mutateAsync({slug:V,source_entity_type_slug:k,target_entity_type_slug:w}),a()}catch(V){P(V instanceof Error?V.message:"Could not save")}};return t.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-muted/30 p-3",children:[t.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Relationships are defined once for the workspace, then paired with the types they connect."}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Pe,{htmlFor:i,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"Relationship"}),t.jsxs(Ft,{value:v,onValueChange:j,children:[t.jsx(zt,{id:i,className:"h-8 text-xs",children:t.jsx(Wt,{placeholder:"Pick or define one"})}),t.jsxs(Bt,{children:[J.map(V=>t.jsx(yt,{value:V.slug,children:V.name||V.slug},V.slug)),J.length>0?t.jsx(Bs,{}):null,t.jsx(yt,{value:$n,children:"Define a new one…"})]})]})]}),D?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Pe,{htmlFor:o,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"Name"}),t.jsx(rt,{id:o,value:d,onChange:V=>S(V.target.value),placeholder:"works at",className:"h-8 text-xs"}),d.trim()?t.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Slug: ",t.jsx("code",{children:An(d)||"—"})]}):null]}),t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs(Pe,{htmlFor:l,className:"text-xs font-normal",children:["Symmetric",t.jsx("span",{className:"mt-0.5 block text-[11px] text-muted-foreground",children:"Both ends mean the same thing, like “connected with”."})]}),t.jsx(Hs,{id:l,checked:N,onCheckedChange:C})]})]}):null,t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Pe,{htmlFor:y,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"From"}),t.jsxs(Ft,{value:k,onValueChange:g,children:[t.jsx(zt,{id:y,className:"h-8 text-xs",children:t.jsx(Wt,{placeholder:"Type"})}),t.jsx(Bt,{children:e.map(V=>t.jsx(yt,{value:V.slug,children:V.label},V.slug))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Pe,{htmlFor:c,className:"text-xs after:ml-1 after:text-destructive after:content-['*']",children:"To"}),t.jsxs(Ft,{value:w,onValueChange:M,children:[t.jsx(zt,{id:c,className:"h-8 text-xs",children:t.jsx(Wt,{placeholder:"Type"})}),t.jsx(Bt,{children:e.map(V=>t.jsx(yt,{value:V.slug,children:V.label},V.slug))})]})]}),A?t.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:A}):null,t.jsx(qn,{onCancel:a,cancelDisabled:q,className:"[&>button]:h-7 [&>button]:px-3 [&>button]:text-xs",children:t.jsx(Y,{type:"button",size:"sm",onClick:se,disabled:q,children:q?"Saving…":"Add relationship"})})]})}const bs=288,mo=440,Et=240,Ct=720,fo=320,dn="lobu.schema-panel-width:v1";function _t(e,n){if(!Number.isFinite(e))return bs;const s=Math.max(Et,Math.min(Ct,n-fo));return Math.round(Math.min(s,Math.max(Et,e)))}function ho(){const e=Gn(dn);if(e===null)return null;const n=Number.parseInt(e,10);return!Number.isFinite(n)||n<Et||n>Ct?null:n}function po(e){Kn(dn,String(Math.round(e)))}function go(){Vs(dn)}const Pn={nodes:[],edges:[]};function yo(e,n,s){const{orgContext:a,hasOrgContext:r}=De(),{data:i=[],isLoading:o,isError:l}=It(a),{data:y=[],isLoading:c,isError:x}=en(a),m=b.useMemo(()=>ys(y,e),[y,e]),h=b.useCallback(g=>{const w={};return m.forEach((M,A)=>{const P=g[A]?.data;P?.length&&(w[M.slug]=P)}),{rulesBySlug:w,isRulesLoading:g.some(M=>M.isLoading),isRulesError:g.some(M=>M.isError)}},[m]),{rulesBySlug:p,isRulesLoading:v,isRulesError:j}=Us({queries:m.map(g=>({...qs.queryOptions(g.slug,a),enabled:r})),combine:h}),d=b.useMemo(()=>({entityTypes:i,relationshipTypes:m,rulesBySlug:p,ownerSlug:e,targetAspect:n,flow:s}),[i,m,p,e,n,s]),[S,N]=b.useState(null),C=o||c||v,k=l||x||j;return b.useEffect(()=>{if(C||k)return;let g=!1;const w={targetAspect:d.targetAspect};let M,A;if(d.flow){const P=lo(xs(d),d.flow);M=P.hidden,A=ln(P.graph,w)}else A=so(d,w);return A.then(P=>{g||N({graph:P,isError:!1,hidden:M})}).catch(()=>{g||N({graph:Pn,isError:!0})}),()=>{g=!0}},[d,C,k]),{graph:S?.graph??Pn,hidden:S?.hidden,isLoading:!k&&!S,isError:k||S?.isError===!0}}function Dn(e){const n=e.ruleCount>1?` ×${e.ruleCount}`:"",s=typeof e.linkCount=="number"?` · ${e.linkCount.toLocaleString()}`:"";return`${e.label}${n}${s}`}const vs={connections:"--chart-3",entities:"--chart-5",automations:"--chart-2",metrics:"--chart-4"};function xo(e,n){const s=e.nodes.some(o=>o.data.ref),a=new Map(e.nodes.map(o=>[o.id,o.data.label])),r=e.nodes.map(o=>({id:o.id,x:o.position.x+o.width/2,y:o.position.y+o.height/2,w:o.width,h:o.height,title:o.data.label,meta:o.data.metaLabel,icon:o.data.icon,badge:o.data.badge??o.data.organizationSlug,muted:o.data.isSystem,dimmed:n?!n.nodes.has(o.id):!1,accent:s?vs[ut(o)]:void 0})),i=e.edges.map(o=>{const{relationships:l,isSymmetric:y,flow:c}=o.data;if(c)return{id:o.id,source:o.source,target:o.target,route:o.route??null,summary:c.summary,details:[c.summary,...c.details],directed:!0,dimmed:n?!n.edges.has(o.id):!1,ariaLabel:`${a.get(o.source)??o.source} to ${a.get(o.target)??o.target}: ${c.summary}`};const x=l.map(m=>m.label).join(", ");return{id:o.id,source:o.source,target:o.target,route:o.route??null,summary:l.length===1?Dn(l[0]):`${l.length} relationships`,details:l.map(Dn),directed:!y,dimmed:n?!n.edges.has(o.id):!1,ariaLabel:`${a.get(o.source)??o.source} ${y?"and":"to"} ${a.get(o.target)??o.target}: ${x}`}});return{boxes:r,edges:i}}const bo=[{key:"connections",label:"Connections"},{key:"entities",label:"Entities"},{key:"automations",label:"Automations"},{key:"metrics",label:"Metrics"}],vo={count:"Count",count_distinct:"Distinct count",sum:"Sum",min:"Minimum",max:"Maximum"};function wo({metric:e,ownerSlug:n}){const s=(a,r)=>r.length>0?t.jsxs("section",{className:"flex flex-col gap-1.5",children:[t.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a}),t.jsx("ul",{className:"flex flex-col gap-1 text-sm",children:r.map(i=>t.jsxs("li",{children:[t.jsx("span",{className:"font-medium",children:i.name}),i.description?t.jsx("span",{className:"text-muted-foreground",children:` · ${i.description}`}):null]},i.name))})]}):null;return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"flex flex-col gap-1",children:[t.jsxs("p",{className:"text-sm",children:[vo[e.agg]??e.agg," of"," ",t.jsx("code",{className:"rounded bg-muted px-1 text-xs",children:e.eventSet})," ","events, per ",e.typeLabel]}),e.description?t.jsx("p",{className:"text-sm text-muted-foreground",children:e.description}):null]}),s("Data from",e.sources.map(a=>({name:a,description:""}))),s("Group by",e.dimensions),s("Segments",e.segments),t.jsx(Y,{asChild:!0,variant:"outline",size:"sm",className:"self-start",children:t.jsxs(we,{to:"/$owner/$entityType",params:{owner:n,entityType:e.typeSlug},children:["Open ",e.typeLabel]})})]})}function ko({ownerSlug:e,metric:n,endpointOptions:s,canAuthor:a,mode:r,onModeChange:i}){const o=()=>i({kind:"index"});return r.kind==="metric"?n?t.jsx(wo,{metric:n,ownerSlug:e}):null:a?r.kind==="create-type"?t.jsx(sa,{slug:null,onClose:o}):r.kind==="new-relationship"?t.jsx(uo,{entityTypes:s,initialSource:r.source,initialTarget:r.target,onDone:o},`${r.source??""}|${r.target??""}`):null:null}function jo(e){const{mode:n,canAuthor:s,onModeChange:a,isPeekOpen:r}=e,i=s&&n.kind==="create-type",o=n.kind==="metric"?n.name:s&&n.kind==="new-relationship"?"New relationship":i?"New entity type":"Schema",l=b.useRef(null),y=JSON.stringify(n),c=b.useRef(y);return b.useEffect(()=>{c.current!==y&&(c.current=y,l.current?.focus({preventScroll:!0}))},[y]),t.jsx("aside",{style:{"--schema-panel-width":`${e.width}px`},className:de("order-first flex w-full shrink-0 flex-col lg:order-none lg:w-[var(--schema-panel-width)]",n.kind==="index"?"lg:absolute lg:top-0 lg:right-6 lg:z-10 lg:w-max lg:max-w-[calc(100%-3rem)] lg:max-h-[calc(100%-2rem)]":"bg-background lg:relative",r&&"lg:hidden"),children:t.jsxs("div",{className:de("flex min-h-0 flex-1 flex-col",n.kind!=="index"&&"lg:absolute lg:inset-0"),children:[t.jsxs("div",{className:n.kind==="index"?"sr-only":"flex h-11 shrink-0 items-center gap-1 border-b border-border px-3",children:[t.jsx("h2",{ref:l,tabIndex:-1,className:"min-w-0 flex-1 truncate text-sm font-medium text-foreground outline-none",children:o}),n.kind!=="index"?t.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:"size-7 shrink-0 text-muted-foreground hover:text-foreground","aria-label":"Close",onClick:()=>a({kind:"index"}),children:t.jsx(tr,{className:"h-4 w-4"})}):null]}),t.jsx("div",{className:de("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto",n.kind==="index"?"pb-1":"p-4"),children:t.jsx(ko,{...e})})]})})}function ws(e){const n=e.previousElementSibling,s=e.nextElementSibling;if(n instanceof HTMLElement&&s instanceof HTMLElement){const a=n.clientWidth+s.clientWidth;if(a>0)return a}return 0}function No({width:e,maxWidth:n,onResize:s,onCommit:a,onReset:r,className:i}){const[o,l]=b.useState(!1),y=b.useRef(0),c=h=>{const p=ws(h);return p>0?p:h.parentElement?.clientWidth??0},x=h=>{if(h.button!==0)return;const p=h.currentTarget;if(!p.parentElement)return;h.preventDefault(),y.current=c(p);const j=h.clientX,d=e;l(!0),p.setPointerCapture(h.pointerId);const S=g=>_t(d-(g-j),y.current);let N=d;const C=g=>{N=S(g.clientX),s(N)},k=g=>{p.removeEventListener("pointermove",C),p.removeEventListener("pointerup",k),p.removeEventListener("pointercancel",k),l(!1),a(g.type==="pointercancel"?N:S(g.clientX))};p.addEventListener("pointermove",C),p.addEventListener("pointerup",k),p.addEventListener("pointercancel",k)},m=h=>{const p=c(h.currentTarget),v=j=>{h.preventDefault(),a(_t(e+j,p))};h.key==="ArrowLeft"?v(16):h.key==="ArrowRight"?v(-16):h.key==="Home"&&(h.preventDefault(),r())};return t.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize schema panel","aria-valuenow":e,"aria-valuemin":Et,"aria-valuemax":n,tabIndex:0,onPointerDown:x,onKeyDown:m,onDoubleClick:r,className:de("group hidden shrink-0 cursor-col-resize touch-none items-stretch justify-center px-1.5 outline-none lg:flex",o&&"cursor-col-resize",i),children:t.jsx("div",{className:de("w-px rounded-full bg-border transition-[background-color,width] group-hover:w-0.5 group-hover:bg-primary/60 group-focus-visible:w-0.5 group-focus-visible:bg-primary",o&&"w-0.5 bg-primary")})})}function So({ownerSlug:e}){const n=at(),s=tn(),a=s?.item!=null,{orgContext:r}=De(),{isAdmin:i}=Yn(r.organizationId),[o,l]=b.useState({connections:!0,entities:!0,automations:!0,metrics:!0}),[y,c]=b.useState({kind:"index"}),x=s?.close,m=b.useCallback(f=>{f.kind!=="index"&&a&&x?.(),c(f)},[a,x]),[h,p]=b.useState(),v=b.useRef(null),j=b.useCallback(f=>{if(v.current?.disconnect(),v.current=null,!f||typeof ResizeObserver>"u")return;const E=()=>{if(!f.clientWidth||!f.clientHeight)return;const L=Math.round(f.clientHeight/f.clientWidth*10)/10;p(z=>z===L?z:L)};E();const T=new ResizeObserver(E);T.observe(f),v.current=T},[]),d=r.organizationId,S=Gs(d),N=Ks(d),C=Ys(d),k=Qr(d??void 0),{data:g}=It(r),w=b.useMemo(()=>g?.filter(f=>Js(f,e)),[g,e]),M=b.useMemo(()=>(w??[]).flatMap(f=>Object.entries(f.metrics_config?.measures??{}).map(([E,T])=>({typeSlug:f.slug,name:E,agg:T.agg,description:T.description}))),[w]),A=S.isLoading||N.isLoading||C.isLoading||k.isLoading,P=b.useMemo(()=>A?null:{connections:S.data??[],feeds:N.data??[],connectorDefs:C.data??[],automations:k.data??[],metrics:M,layers:o},[A,S.data,N.data,C.data,k.data,M,o]),{graph:D,isLoading:J,isError:q,hidden:se}=yo(e,h,P),V=J||A,ne=y.kind==="metric"?y:null,he=b.useMemo(()=>{if(!ne)return null;const f=`metric:${ne.typeSlug}:${ne.name}`,E=D.edges.find(z=>z.target===f);if(!E)return null;const T=E.source,L=D.edges.filter(z=>z.target===T&&D.nodes.find(G=>G.id===z.source)?.data.ref?.kind==="connection");return{typeId:T,nodes:new Set([f,T,...L.map(z=>z.source)]),edges:new Set([E.id,...L.map(z=>z.id)]),sources:L.map(z=>D.nodes.find(G=>G.id===z.source)?.data.label??z.source)}},[ne,D]),{boxes:O,edges:I}=b.useMemo(()=>xo(D,he),[D,he]),U=b.useMemo(()=>{if(!ne)return null;const f=w?.find(L=>L.slug===ne.typeSlug),E=f?.metrics_config,T=E?.measures?.[ne.name];return!f||!T?null:{name:ne.name,typeSlug:f.slug,typeLabel:f.name||f.slug,agg:T.agg,eventSet:T.eventSet,description:T.description,dimensions:Object.entries(E?.dimensions??{}).map(([L,z])=>({name:L,description:z.description})),segments:Object.entries(E?.segments??{}).map(([L,z])=>({name:L,description:z.description})),sources:he?.sources??[]}},[ne,w,he]),H=b.useMemo(()=>new Map(D.nodes.map(f=>[f.id,f.data.slug])),[D.nodes]),W=b.useMemo(()=>new Map(D.nodes.flatMap(f=>f.data.ref?[[f.id,f.data.ref]]:[])),[D.nodes]),{data:Q=[]}=Qs(r.organizationId),re=b.useMemo(()=>{const f=new Map;for(const E of D.nodes)E.data.ref||(!E.data.organizationSlug||!f.has(E.data.slug))&&f.set(E.data.slug,{slug:E.data.slug,label:E.data.label});return[...f.values()]},[D.nodes]),pe=b.useCallback(f=>{const E=W.get(f);if(E?.kind==="connection"){n({to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:e,connectorKey:E.connectorKey,connectionId:String(E.connectionId)},search:{}});return}if(E?.kind==="metric"){m({kind:"metric",typeSlug:E.typeSlug,name:E.name});return}if(E?.kind==="automation"){n({to:"/$owner/automations/$automationId",params:{owner:e,automationId:E.automationId},search:{view:"activity",run_id:void 0}});return}n(Jn(e,H.get(f)??f))},[n,e,H,W,m]),ue=b.useCallback((f,E)=>{W.has(f)||W.has(E)||m({kind:"new-relationship",source:H.get(f)??f,target:H.get(E)??E})},[H,W,m]),Ce=D.nodes.some(f=>!f.data.ref&&!f.data.isSystem&&!f.data.organizationSlug),Fe=D.nodes.some(f=>f.data.ref),Ne="size-6 text-muted-foreground hover:text-foreground",Ge={connections:t.jsx(Jr,{ownerSlug:e,catalog:Q,trigger:t.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:Ne,"aria-label":"New connector",title:"New connector",children:t.jsx(mt,{className:"size-3.5"})})}),entities:t.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:Ne,"aria-label":"Create entity type",title:"Create entity type",onClick:()=>m({kind:"create-type"}),children:t.jsx(mt,{className:"size-3.5"})}),automations:t.jsx(Y,{asChild:!0,variant:"ghost",size:"icon",className:Ne,children:t.jsx(we,{to:"/$owner/automations/new",params:{owner:e},"aria-label":"New Automation",title:"New Automation",children:t.jsx(mt,{className:"size-3.5"})})})},_e=b.useCallback(f=>{const E=f.startsWith(Jt)?f.slice(Jt.length):null;if(!E)return t.jsx(Rt,{icon:f||null,className:"h-4 w-4"});const T=Xs(E,C.data??[],{name:S.data?.find(L=>L.connector_key===E)?.connector_name??E});return t.jsx(Zs,{plain:!0,icon:T.icon,iconUrl:T.iconUrl,name:T.name,faviconDomain:T.faviconDomain})},[C.data,S.data]),ze=i&&y.kind==="create-type",ye=y.kind==="metric"||i&&y.kind!=="index",[Le,xe]=b.useState(()=>ho()),Re=Le??(ze?mo:bs),[ce,ot]=b.useState(null),ke=b.useRef(null),Ie=b.useCallback(f=>{if(ke.current?.disconnect(),ke.current=null,!f||typeof ResizeObserver>"u")return;const E=f.children[1];if(!E)return;const T=()=>{const z=ws(E);z>0&&ot(G=>G===z?G:z)};T();const L=new ResizeObserver(T);L.observe(f),ke.current=L},[]),We=ce===null?Re:_t(Re,ce),Be=ce===null?Ct:_t(Ct,ce),_=b.useCallback(f=>{xe(f),po(f)},[]),u=b.useCallback(()=>{xe(null),go()},[]);return V?t.jsx(cn,{label:"Loading workspace schema",fill:!0,schemaActions:i}):q?t.jsx(Qn,{label:"workspace schema"}):t.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[t.jsxs("div",{className:de("flex flex-wrap items-center justify-between gap-3",ye&&"hidden lg:flex"),children:[t.jsx("p",{className:"text-sm text-muted-foreground",children:Fe?`Where records come from, the types they land in, and what uses them. Click a box to open it${i?", or drag a type's ⊕ onto another to relate them":""}. Only stored links are drawn${se?.connections?`; ${se.connections} connections have none yet`:""}.`:Ce?D.edges.length>0?`Your workspace schema. Hover a type or select a line to name its relationships, click a type to open it${i?", or drag its ⊕ to relate types.":"."}`:"Your workspace schema. Click a type to open it — relationships appear here once you add one to a type.":i?"Member is already here: everyone in this workspace. Create the first type of record you track — a company, a deal, a ticket — then drag its ⊕ onto Member to relate them.":"Member is already here: everyone in this workspace. An admin can add the types of record this workspace tracks."}),t.jsxs("fieldset",{className:"m-0 flex min-w-0 shrink-0 flex-wrap items-center gap-x-4 gap-y-1 border-0 p-0 text-sm",children:[t.jsx("legend",{className:"sr-only",children:"Show on the map"}),bo.map(({key:f,label:E})=>{const T=`memory-map-show-${f}`,L=o[f]&&Object.values(o).filter(Boolean).length===1;return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(er,{id:T,checked:o[f],disabled:L,onCheckedChange:z=>l(G=>({...G,[f]:z===!0}))}),t.jsxs("label",{htmlFor:T,className:"inline-flex cursor-pointer select-none items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:"size-2 rounded-full",style:{background:`var(${vs[f]})`}}),E]}),i?Ge[f]:null]},f)})]})]}),t.jsxs("div",{ref:Ie,className:"relative flex min-h-0 min-w-0 flex-1 flex-col gap-3 lg:-mr-6 lg:-mb-8 lg:flex-row lg:gap-0",children:[t.jsx("div",{className:de("flex min-w-0 flex-1 flex-col lg:pb-8",ye&&"hidden lg:flex"),children:t.jsx("div",{ref:j,className:"min-h-[420px] min-w-0 flex-1 overflow-hidden rounded-lg bg-background",children:t.jsx(gs,{boxes:O,edges:I,label:"Workspace schema",onOpenBox:pe,openLabel:f=>`Open ${f.title}`,onConnect:i?ue:void 0,renderIcon:_e})})}),t.jsx(No,{width:We,maxWidth:Be,onResize:xe,onCommit:_,onReset:u,className:a||y.kind==="index"?"lg:hidden":void 0}),t.jsx(jo,{width:We,metric:U,ownerSlug:e,endpointOptions:re,canAuthor:i,mode:y,onModeChange:m,isPeekOpen:a})]})]})}function Eo({onClose:e,entityTypeSlug:n,orgContext:s,onSuccess:a}){const{data:r,isLoading:i}=Xn(n,s),o=`${s.organizationId??s.slug}:${n}`,l=nr(o,{name:"",customSlug:"",useCustomSlug:!1,metadata:{}},r?.metadata_schema),[y,c]=l.field("name"),[x,m]=l.field("customSlug"),[h,p]=l.field("useCustomSlug"),[v,j]=l.field("metadata"),[d,S]=sr(o,null),N=rr(),C=h?x:ar(y),k=async P=>{if(P.preventDefault(),!l.canSubmit)return;if(S(null),!y.trim()){S("Name is required");return}const D=aa(v),J={entityType:n,name:y.trim(),slug:h?x:void 0,metadata:Object.keys(D).length>0?D:void 0};try{const q=await N.mutateAsync(J);if(e(),q.approval_queued||!q.entity){Zn.info("Create queued for approval");return}typeof q.entity.id=="number"&&a?.(q.entity.id)}catch(q){S(q instanceof Error?q.message:"Failed to create entity")}},g=r?.name||n,w=l.revision,M=`Create ${g}`,A=`Add a new ${g.toLowerCase()} to your workspace.`;return i?t.jsx(or,{rows:6}):t.jsxs("form",{onSubmit:k,children:[t.jsx(ir,{visible:l.hasConflict,onReload:l.reset}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:M}),t.jsx("p",{className:"text-sm text-muted-foreground",children:A})]}),t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsxs(Pe,{htmlFor:"name",children:["Name ",t.jsx("span",{className:"text-destructive",children:"*"})]}),t.jsx(rt,{id:"name",value:y,onChange:P=>c(P.target.value),placeholder:`Enter ${g.toLowerCase()} name`,autoFocus:!0})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(Pe,{htmlFor:"slug",children:"URL Slug"}),t.jsx("button",{type:"button",onClick:()=>p(!h),className:"text-xs text-muted-foreground hover:text-foreground",children:h?"Auto-generate":"Customize"})]}),h?t.jsx(rt,{id:"slug",value:x,onChange:P=>m(P.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"custom-slug"}):t.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"})]}),w&&Object.keys(w).length>0?t.jsxs(t.Fragment,{children:[t.jsx(fa,{className:"my-2"}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(Pe,{className:"text-sm font-medium",children:"Additional Fields"}),t.jsx(ra,{schema:l.revision,values:v,onValuesChange:j,orgContext:s})]})]}):null,d&&t.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:d})]}),t.jsx(qn,{onCancel:e,cancelDisabled:N.isPending,className:"mt-2",children:t.jsx(Y,{type:"submit",disabled:!l.canSubmit||N.isPending||!y.trim(),children:N.isPending?"Creating...":`Create ${g}`})})]})}function Co(e){const n=e?.properties??{},s=ur(e);return Object.entries(n).flatMap(([a,r])=>{const i=s.find(m=>m.field===a);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(a)||!r||r.const!==void 0||r["x-table-column"]!==!0&&r["x-facet"]!==!0&&!i)return[];const o=[r,...Array.isArray(r.anyOf)?r.anyOf:[]],l=i?.options??[],y=l.find(m=>m.value!==null)?.value,c=o.find(m=>["string","number","integer","boolean"].includes(String(m.type)))??(y===void 0?void 0:{type:typeof y});if(!c)return[];const x=r.format==="date-time"||c.format==="date-time"?"datetime-local":r.format==="date"||c.format==="date"?"date":c.type==="number"||c.type==="integer"?"number":c.type==="boolean"?"boolean":"string";return[{field:a,label:String(r["x-table-label"]??r.title??a.replaceAll("_"," ")),type:x,options:x==="boolean"&&!l.some(m=>typeof m.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...l]:l}]})}function _o(e){const n=e?.[Yt];return n===void 0?{}:nn(n)}function Mo(e,n,s){try{const a=_o(n),r=e[es],i=r===void 0?void 0:a.presets?.find(x=>x.key===r);if(r!==void 0&&!i)throw new Error("This saved filter is unavailable. Choose another filter.");if(i&&!s&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const o=i&&e[tt]===void 0?{collection:jt(i)}:cr(e,s);if(o.error)throw o.error;const l=e[lr],y=l===void 0?i?.table??a.table??{}:nn({table:typeof l=="string"?JSON.parse(l):l}).table??{},c=!!i&&(Fn(o.collection)!==Fn(jt(i))||Mt(y)!==Mt(i.table??a.table??{}));return{...o,presentation:a,preset:i,table:y,edited:c}}catch(a){return{collection:{},presentation:{},table:{},edited:!1,error:a instanceof Error?a:new Error("Invalid collection configuration")}}}function Fn(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(wt)])}function wt(e){return JSON.stringify([e.field,e.op,e.value])}function Mt(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function To(e,n){return n?{[es]:n,[tt]:Kt(e)[tt]??"{}"}:Kt(e)}function Lo(e,n,s,a,r=new Date){let i=n.filters??[],o=e.relativeDate;if(o){const l=(jt({...e,selection:{}},r).filters??[]).map(wt),y=i.map(wt);l.every(c=>y.includes(c))?i=i.filter(c=>!l.includes(wt(c))):o=void 0}return{key:e.key,label:e.label,selection:{...n.search?{search:n.search}:{},...i.length?{filters:i}:{},...n.segment?{segment:n.segment}:{}},...Mt(s)!==Mt(a.table??{})?{table:s}:{},...o?{relativeDate:o}:{}}}function Ro(e,n,s){const a=[...e.filters??[]],r=s??(n.length===1&&n[0].op==="eq"?a.findIndex(o=>o.field===n[0].field&&o.op==="eq"):-1),i=r>=0?[...a.slice(0,r),...n,...a.slice(r+1)]:[...a,...n];return{...e,filters:mr({filters:i}).filters}}function Io(e,n){return{...e,filters:e.filters?.filter((s,a)=>a!==n)}}function Oo(e,n){return{...typeof e.$preset=="string"?e[tt]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[tt]:String(dr(e[tt]))}:Kt(n),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const $o=[{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 Ao(e){return e.sort&&$o.some(n=>n.field===e.sort?.field)?e.sort:{field:"created_at",order:"desc"}}function Po(e,n,s,a,r){const i={...a,filters:a.filters?.filter(o=>o.field!==s)};return ts({queryKey:["collection-facets",e,n,s,i],enabled:!!n&&!!s,staleTime:3e4,retry:!1,queryFn:async({signal:o})=>{const l=await Nt("query_sdk",{title:`Value counts query for ${s}`,script:`const input = ${JSON.stringify({field:s,collection:i})};
2
+ ${n}`},e,{signal:o}),y=l.return_value;if(!l.success||typeof y?.connection!="string"||typeof y.sql!="string")throw new Error(l.error?.message??"Value distribution is unavailable");if(o.aborted)throw new DOMException("Aborted","AbortError");const c=await Nt("query_sql",{title:`Value counts for ${s}`,connection:y.connection,sql:y.sql,limit:51},e,{signal:o});if(c.error)throw new Error(c.error);if(!Array.isArray(c.rows))throw new Error("Source did not return value counts");const x=c.rows.map(m=>{const h=m,p=typeof h.count=="string"&&/^\d+$/.test(h.count)?Number(h.count):h.count;if(!(h.value===null||["string","number","boolean"].includes(typeof h.value))||typeof p!="number"||!Number.isSafeInteger(p)||p<0)throw new Error("Source returned an invalid value distribution");return{value:h.value,count:p}});return{values:x.slice(0,50),truncated:x.length>50||c.truncated===!0}}})}const Do=300;function Fo({label:e,search:n,onSearch:s,className:a}){const r=n??"",[i,o]=b.useState(r),l=b.useRef({search:n,onSearch:s});l.current={search:n,onSearch:s};const y=b.useRef(void 0);b.useEffect(()=>{const x=()=>{clearTimeout(y.current),o(l.current.search??"")};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[]);const c=b.useRef(r);return b.useEffect(()=>{r!==c.current&&(c.current=r,o(r))},[r]),b.useEffect(()=>{if(i===(l.current.search??""))return;const x=setTimeout(()=>{const m=l.current.onSearch;c.current=i,m(i||void 0,!0)},Do);return y.current=x,()=>clearTimeout(x)},[i]),t.jsxs("div",{className:`relative${a?` ${a}`:""}`,children:[t.jsx(hr,{"aria-hidden":"true",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(rt,{type:"search","aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}...`,maxLength:512,value:i,onChange:x=>o(x.target.value),className:"pl-9"})]})}const zo={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function Wo({field:e,initial:n,org:s,facetQuery:a,collection:r,onApply:i,close:o}){const[l,y]=b.useState(n?.op??"eq"),[c,x]=b.useState(n?.value==null?"":String(n.value)),[m,h]=b.useState(""),[p,v]=b.useState(!1),[j,d]=b.useState(),S=e.type==="date"||e.type==="datetime-local"||e.type==="number"?e.type:"text",N=Po(s,a,e.field,r),C=w=>{try{const M=p?[{field:e.field,op:"gte",value:e.type==="number"?Number(c):c},{field:e.field,op:"lte",value:e.type==="number"?Number(m):m}]:[{field:e.field,op:l,value:w}];if(e.type==="datetime-local")for(const D of M)typeof D.value=="string"&&(D.value=new Date(D.value).toISOString());if(M.some(D=>typeof D.value=="number"&&!Number.isFinite(D.value)))throw new Error("Enter a valid number.");const A=M[0].value,P=M[1]?.value;if(p&&A!=null&&P!=null&&A>P)throw new Error("The lower bound must be before the upper bound.");i(M),o()}catch(M){d(M instanceof Error?M.message:"Could not apply filter")}},k=[...e.options];for(const w of N.data?.values??[])k.some(M=>M.value===w.value)||k.push({value:w.value,label:w.value===null?"Not supplied":String(w.value)});const g=Math.max(1,...N.data?.values.map(w=>w.count)??[]);return t.jsxs("div",{className:"min-w-0 space-y-3 p-3",children:[t.jsxs("select",{"aria-label":"Filter operator",className:"h-8 w-full rounded-md border bg-background px-2 text-sm",value:p?"range":l,onChange:w=>{v(w.target.value==="range"),w.target.value!=="range"&&y(w.target.value)},children:[t.jsx("option",{value:"eq",children:"is"}),t.jsx("option",{value:"neq",children:"is not"}),(e.type==="number"||e.type==="date"||e.type==="datetime-local")&&t.jsxs(t.Fragment,{children:[t.jsx("option",{value:"lt",children:"less than / before"}),t.jsx("option",{value:"lte",children:"at most / on or before"}),t.jsx("option",{value:"gt",children:"greater than / after"}),t.jsx("option",{value:"gte",children:"at least / on or after"}),n?null:t.jsx("option",{value:"range",children:"between"})]})]}),e.type!=="boolean"&&t.jsxs("form",{className:"space-y-2",onSubmit:w=>{w.preventDefault(),C(e.type==="number"?Number(c):c)},children:[t.jsx(rt,{required:!0,"aria-label":p?"From value":"Filter value",type:S,step:e.type==="number"?"any":void 0,value:c,onChange:w=>x(w.target.value),placeholder:"Enter a value…"}),p&&t.jsx(rt,{required:!0,"aria-label":"To value",type:S,step:e.type==="number"?"any":void 0,value:m,onChange:w=>h(w.target.value)}),t.jsx(Y,{size:"sm",type:"submit",className:"w-full",children:"Apply filter"})]}),!p&&(l==="eq"||l==="neq")&&t.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto",children:k.filter(w=>!c||w.label.toLowerCase().includes(c.toLowerCase())).map(w=>{const M=N.data?.values.find(A=>A.value===w.value)?.count;return t.jsxs("button",{type:"button","aria-label":w.label,onClick:()=>C(w.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:[M!==void 0&&t.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-primary/10",style:{width:`${M/g*100}%`}}),t.jsx("span",{className:"relative truncate",children:w.label}),t.jsx("span",{className:"relative text-xs tabular-nums text-muted-foreground",children:M?.toLocaleString()})]},JSON.stringify(w.value))})}),a&&N.isFetching&&t.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Loading distribution…"}),N.isError&&t.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Counts unavailable. You can still enter a value."}),N.data?.truncated&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Top 50 values. Enter any other value above."}),j&&t.jsx("p",{role:"alert",className:"text-xs text-destructive",children:j})]})}function Bo({choices:e,visible:n,onChange:s}){return t.jsxs(sn,{children:[t.jsx(rn,{asChild:!0,children:t.jsx(Y,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:t.jsx(ns,{className:"h-4 w-4"})})}),t.jsxs(an,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[t.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),e.map(a=>t.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[t.jsx("input",{type:"checkbox",checked:!n||n.includes(a.field),onChange:r=>{const i=n??e.map(o=>o.field);s(r.target.checked?[...i,a.field]:i.filter(o=>o!==a.field))}}),a.label]},a.field))]})]})}function Ho({collection:e,schema:n,label:s,onChange:a,org:r,facetQuery:i,segmentChip:o,viewFilters:l,onClearAll:y}){const c=Co(n),x=(v,j)=>({kind:"custom",className:"w-80",render:d=>t.jsx(Wo,{field:v,initial:j==null?void 0:e.filters?.[j],org:r,facetQuery:i,collection:e,onApply:S=>a(Ro(e,S,j)),close:d})}),m=c.map(v=>({key:v.field,label:v.label,icon:t.jsx(fr,{className:"h-4 w-4"}),editor:x(v)})),h=new Map,p=(e.filters??[]).map((v,j)=>{const d=`${v.field}:${v.op}:${JSON.stringify(v.value)}`,S=h.get(d)??0;h.set(d,S+1);const N=c.find(k=>k.field===v.field),C=N?.options.find(k=>k.value===v.value)?.label??String(v.value??"Not supplied");return{id:`${d}:${S}`,label:N?.label??v.field,op:zo[v.op],value:C,editor:N?x(N,j):void 0,onRemove:()=>a(Io(e,j))}});if(o&&p.unshift(o),l?.fields.length){for(const v of m)v.group=s;m.push(...l.fields),p.push(...l.chips)}return!m.length&&!p.length?null:t.jsx(ha,{label:`${s} filters`,fields:m,chips:p,onClearAll:y??(()=>a({...e,filters:[],segment:void 0}))})}const Tt=120,Te=12;function zn(e,n){return typeof e.linkId=="number"&&typeof n.linkId=="number"?e.linkId-n.linkId:String(e.linkId).localeCompare(String(n.linkId))}function Vo(e){const n=e.records.slice(0,Tt),s=c=>e.types.get(c)??{label:c},a=new Map;for(const c of n)a.set(String(c.id),{source:c.source,entityType:e.typeSlug,slug:c.slug,name:c.name,isFocus:!0,hasMoreLinks:!1});const r=new Map;for(const c of e.links){if(!a.has(String(c.recordId)))continue;const x=r.get(c.recordId)??new Map;x.set(c.linkId,c),r.set(c.recordId,x)}const i=new Map;for(const[c,x]of r){const m=[...x.values()].sort(zn),h=a.get(String(c));h&&m.length>Te&&(h.hasMoreLinks=!0);for(const p of m.slice(0,Te)){i.set(p.linkId,p);const v=String(p.peer.id);a.has(v)||a.set(v,{source:p.peer.source,entityType:p.peer.type,slug:p.peer.slug,name:p.peer.name,isFocus:!1,hasMoreLinks:!1})}}const o=[];for(const[c,x]of a){const m=s(x.entityType),h=x.name||x.slug,p=x.hasMoreLinks?`${m.label} · ${Te}+ links`:m.label;o.push({id:c,data:{slug:x.slug,label:h,icon:m.icon,isSystem:!1,metaLabel:p},width:ft(h,p),height:st})}const l=new Map;for(const c of[...i.values()].sort(zn)){const x=String(c.fromId),m=String(c.toId),h=JSON.stringify([x,m]),p=l.get(h)??{source:x,target:m,rels:new Map,symmetric:!0};p.symmetric&&=c.isSymmetric,p.rels.has(c.relSlug)||p.rels.set(c.relSlug,{slug:c.relSlug,label:c.relName,ruleCount:1}),l.set(h,p)}const y=[...l.entries()].map(([c,x])=>({id:`link:${c}`,source:x.source,target:x.target,data:{relationships:[...x.rels.values()],isSymmetric:x.symmetric}}));return{nodes:o,edges:y,records:a,hasMoreRecords:e.hasMore===!0||e.records.length>Tt,listedCount:n.length,focusCount:n.length}}async function Uo(e,n){const s=Vo(e);return{...await ln({nodes:s.nodes,edges:s.edges},n),records:s.records,hasMoreRecords:s.hasMoreRecords,listedCount:s.listedCount,focusCount:s.focusCount}}const qo=8,Go=3,Ko=4;function kt(e){return`source:${JSON.stringify([e.type,e.key])}`}function Yo(e,n){return n.map(s=>{const a={type:e,key:s.slug};return{...s,id:kt(a),source:a}})}function Wn(e){return JSON.stringify([e.relationship_type,e.direction,e.entity_type,e.key])}async function Jo(e,n,s){const a=e.slice(0,qo),r=[];let i=0;return await Promise.all(Array.from({length:Math.min(Go,a.length)},async()=>{for(;i<a.length;){const o=i++,l=a[o];try{if(s?.aborted)throw s.reason;const y=await n(l),c=new Map(l.links.map(d=>[Wn(d),d]));for(const d of y.record_links){const S=Wn(d),N=c.get(S);(!N||N.occurred_at<d.occurred_at)&&c.set(S,d)}const x=new Map((l.relationships??[]).map(d=>[d.id,d]));for(const d of y.relationships??[])x.set(d.id,d);const m=[...x.values()].slice(0,Te+1),h=[...c.values()].slice(0,Te+1),p=(l.pagesRead??0)+1,v=!!y.next_cursor&&p>=Ko,j=y.record_failures.length>0||!!y.relationship_failures?.length||v;r[o]={read:{record:l.record,links:h,failed:j,entityId:l.entityId,relationships:m},...!v&&(j||y.next_cursor&&h.length+m.length<=Te)?{next:{record:l.record,entityId:l.entityId,relationships:m,pagesRead:p,cursor:y.next_cursor??l.cursor,links:h}}:{}}}catch(y){if(s?.aborted)throw y;r[o]={read:{record:l.record,links:l.links,failed:!0,entityId:l.entityId,relationships:l.relationships},next:{...l,cursor:y instanceof pr&&y.status===400?null:l.cursor}}}}})),{reads:r.map(o=>o.read),pending:[...r.flatMap(o=>o.next?[o.next]:[]),...e.slice(a.length)]}}function Qo(e,n){const s=new Map;for(const i of e)for(const o of i.reads)s.set(String(o.entityId??kt(o.record)),o);const a=new Map(n.map(i=>[i.slug,i])),r=[];for(const[i,o]of s){for(const l of o.relationships??[]){const y=(j,d)=>typeof j=="number"?j:kt({type:d,key:j}),c=y(l.from_entity_id,l.from_entity_type),x=y(l.to_entity_id,l.to_entity_type),m=String(c)===i,h=m?x:c,p=m?l.to_entity_id:l.from_entity_id,v=(m?l.to_entity_type:l.from_entity_type)??"";r.push({recordId:i,linkId:l.id,fromId:c,toId:x,relSlug:l.relationship_type_slug,relName:l.relationship_type_name,isSymmetric:l.is_symmetric,peer:{id:h,name:(m?l.to_entity_name:l.from_entity_name)??String(p),slug:(m?l.to_entity_slug:l.from_entity_slug)??String(p),type:v,...typeof p=="string"?{source:{type:v,key:p}}:{}}})}for(const l of o.links){const y={type:l.entity_type,key:l.key},c=kt(y),x=a.get(l.relationship_type);let m=l.direction==="incoming"?c:i,h=l.direction==="incoming"?i:c;x?.is_symmetric&&m>h&&([m,h]=[h,m]),r.push({recordId:i,linkId:JSON.stringify([m,h,l.relationship_type]),fromId:m,toId:h,relSlug:l.relationship_type,relName:x?.name||l.relationship_type.replaceAll("_"," "),isSymmetric:x?.is_symmetric??!1,peer:{id:c,name:l.name||l.key,slug:l.key,type:l.entity_type,source:y}})}}return{links:r,checked:s.size,failed:[...s.values()].filter(i=>i.failed).length}}function Xo(e,n,s,a,r,i=!1){const{orgContext:o}=De(),l=It(o),y=en(o),c=b.useMemo(()=>i?Yo(n,s):s,[i,n,s]),x=b.useMemo(()=>c.slice(0,Tt).flatMap(k=>k.source?[{record:k.source,cursor:null,links:[]}]:typeof k.id=="number"?[{entityId:k.id,record:{type:n,key:k.slug},cursor:null,links:[]}]:[]),[c,n]),m=gr({queryKey:["source-records-graph",o.organizationId,e,n,x.map(k=>[k.record,k.entityId])],enabled:!0,initialPageParam:x,queryFn:({pageParam:k,signal:g})=>Jo(k,async w=>{const M=await Nt("manage_entity",{action:"list_links",...w.entityId===void 0?{record:w.record,cursor:w.cursor}:{entity_id:w.entityId,offset:Number(w.cursor??0)},limit:Te+1},e,{signal:g});return{...M,record_links:M.record_links??[],record_failures:M.record_failures??[],next_cursor:w.entityId===void 0?M.next_cursor:M.metadata?.has_more?String(Number(w.cursor??0)+Te+1):null}},g),getNextPageParam:k=>k.pending.length?k.pending:void 0,staleTime:3e4,retry:!1}),h=b.useMemo(()=>m.data?Qo(m.data.pages,y.data??[]):void 0,[m.data,y.data]),p=h?.links,v=m.isError,j=JSON.stringify([o.organizationId,e,n,i,c.map(k=>[k.id,k.name,k.slug]),a]),d=b.useMemo(()=>new Map((l.data??[]).map(k=>[k.slug,{label:k.name||k.slug,icon:k.icon}])),[l.data]),[S,N]=b.useState(null);b.useEffect(()=>{if(!p)return;let k=!1;return Uo({typeSlug:n,records:c,hasMore:a,links:p,types:d},{targetAspect:r}).then(g=>{k||N({graph:g,key:j,isError:!1})}).catch(()=>{k||N({graph:null,key:j,isError:!0})}),()=>{k=!0}},[p,n,c,a,d,r,j]);const C=S?.key===j?S:null;return{graph:C?.graph??null,isLoading:!v&&!C,isError:v||C?.isError===!0,sourceProgress:{checked:h?.checked??0,total:Math.min(s.length,Tt),failed:h?.failed??0,hasMore:!!m.hasNextPage,isFetching:m.isFetching,loadMore:()=>{m.isFetching||m.fetchNextPage()}}}}function Zo(e){const n=new Map(e.nodes.map(r=>[r.id,r.data.label])),s=e.nodes.map(r=>({id:r.id,x:r.position.x+r.width/2,y:r.position.y+r.height/2,w:r.width,h:r.height,title:r.data.label,meta:r.data.metaLabel,icon:r.data.icon,muted:e.records.get(r.id)?.isFocus===!1})),a=e.edges.map(r=>{const{relationships:i,isSymmetric:o}=r.data,l=i.map(y=>y.label);return{id:r.id,source:r.source,target:r.target,route:r.route??null,summary:l.length===1?l[0]:`${l.length} relationships`,details:l,directed:!o,ariaLabel:`${n.get(r.source)??r.source} ${o?"and":"to"} ${n.get(r.target)??r.target}: ${l.join(", ")}`}});return{boxes:s,edges:a}}function ei({ownerSlug:e,typeSlug:n,records:s,hasMore:a,sourceBacked:r=!1}){const i=at(),o=tn(),{orgContext:l}=De(),{data:y=[]}=It(l),c=y.find(g=>g.slug===n)?.name??n,[x,m]=b.useState(),h=b.useRef(null),p=b.useCallback(g=>{if(h.current?.disconnect(),h.current=null,!g||typeof ResizeObserver>"u")return;const w=()=>{if(!g.clientWidth||!g.clientHeight)return;const A=Math.round(g.clientHeight/g.clientWidth*10)/10;m(P=>P===A?P:A)};w();const M=new ResizeObserver(w);M.observe(g),h.current=M},[]),{graph:v,isLoading:j,isError:d,sourceProgress:S}=Xo(e,n,s,a,x,r),N=b.useMemo(()=>v?Zo(v):null,[v]),C=b.useCallback(g=>{const w=v?.records.get(g);if(w){if(o){o.open(oa({...w.source?{record:w.source}:{entityId:Number(g)},ownerSlug:e,orgContext:l,name:w.name||w.slug}));return}i({to:ss(e,[{entity_type:w.entityType,slug:w.slug}])})}},[v,e,l,o,i]);if(d)return t.jsx(Qn,{label:`${c} graph`});if(j||!v||!N)return t.jsx(cn,{label:`Loading ${c} graph`});const k=S?t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[t.jsxs("div",{className:"text-sm text-muted-foreground",role:"status",children:[t.jsxs("p",{children:["Checked ",S.checked," of ",S.total," records. Up to ",Te," relationships per record."]}),S.failed>0?t.jsx("p",{role:"alert",children:"Some sources could not be read. These relationships are incomplete."}):null]}),S.hasMore?t.jsx(Y,{variant:"outline",size:"sm",disabled:S.isFetching,onClick:S.loadMore,children:S.isFetching?"Loading…":S.failed>0?"Retry sources":"Load more relationships"}):null]}):null;return v.focusCount===0?t.jsxs("div",{className:"space-y-3",children:[k,t.jsx(rs,{icon:as,title:`No ${c} records match`,description:"Change the search or filters to see records here."})]}):t.jsxs("div",{className:"flex flex-col gap-2",children:[k,t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",v.hasMoreRecords?"the first ":"",v.focusCount," ",c," record",v.focusCount===1?"":"s",". Click a record to see it."]}),t.jsx("div",{ref:p,className:"h-[70vh] min-h-[420px] min-w-0 overflow-hidden",children:t.jsx(gs,{boxes:N.boxes,edges:N.edges,label:`${c} records`,onOpenBox:C,openLabel:g=>`Show ${g.title}`})})]})}function ti({direction:e}){return e?t.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[t.jsx("title",{children:e==="asc"?"Sort ascending":"Sort descending"}),e==="asc"?t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):t.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[t.jsx("title",{children:"Sort"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function Ze({column:e,children:n,alignRight:s=!1}){return t.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${s?" ml-auto":""}`,onClick:()=>e.toggleSorting(e.getIsSorted()==="asc"),children:[n,t.jsx(ti,{direction:e.getIsSorted()})]})}function Qt(e,n,s){const a=os(e?.properties).filter(([i,o])=>(!n||i!=="name")&&!o["x-image"]&&o["x-table-column"]===!0);if(a.length)return a.map(([i,o])=>({field:i,label:o["x-table-label"]??qe(i.replaceAll("_"," "))}));if(!n)return[];const r=s.find(i=>Object.keys(Ee(i.metadata)).length>0);return Object.keys(Ee(r?.metadata)).filter(i=>i!=="id"&&i!=="slug"&&i!=="name"&&!yr(e?.properties?.[i])).map(i=>({field:i,label:qe(i.replaceAll("_"," "))}))}function ni(e){return e.some(n=>Object.hasOwn(Ee(n.metadata),"name"))}function si(e,n){return nt(e,Ot(n))}function ri(e){return`${e.entityType}:${e.lookupField}`}const ai=new Set(["stage","category","round_type","investor_type"]);function oi(e,n){const s=e.toLowerCase();return s==="mrr"||s==="arr"||s==="revenue"||s==="valuation"||s==="funding_raised"||s==="fund_size"||s.endsWith("_usd")||n.description?.toLowerCase().includes("usd")===!0}function ii(e,n){if(oi(e,n))return"currency";if(ai.has(e)||e.endsWith("_slug"))return"enum"}function ci({entities:e,owner:n,schema:s,entityTypeIcon:a,isDerived:r,measureColumns:i,linkedEntityLookups:o,hasAnyParents:l,sorting:y,onSortingChange:c,visibleColumns:x,columnChoices:m,onVisibleColumnsChange:h,page:p,pageSize:v,totalCount:j,hasMore:d,pageTitle:S,onPrevPage:N,onNextPage:C}){const k=m?.length&&h?t.jsx(Bo,{choices:m,visible:x,onChange:h}):null,g=s?.properties,w=!r||ni(e),M=b.useMemo(()=>g?Object.fromEntries(Object.entries(g).flatMap(([O,I])=>I["x-link-entity-type"]?[[O,{entityType:I["x-link-entity-type"],lookupField:I["x-link-lookup-field"]||"slug"}]]:[])):{},[g]),A=b.useMemo(()=>g?Qt({properties:g},r,[]).map(({field:I})=>[I,g[I]]).map(([I,U])=>{const H=M[I],W=H?o[ri(H)]:void 0;return{id:r?I:`meta_${I}`,accessorFn:Q=>{const re=Ee(Q.metadata);return ia(re[I],U.enum)},header:({column:Q})=>{const re=U["x-table-label"]||U.title||U.description||qe(I.replace(/_/g," "));return r?t.jsx(Ze,{column:Q,children:re}):re},cell:({getValue:Q})=>t.jsx(jn,{value:Q(),prop:U,format:ii(I,U),className:"text-muted-foreground",resolveLink:W?re=>{const pe=W[re];return pe?{label:pe.name,to:nt(n,[{entity_type:pe.entity_type,slug:pe.slug}])}:void 0}:void 0})}}):[],[r,M,o,n,g]),P=b.useMemo(()=>new Set(i),[i]),D=b.useMemo(()=>!r||A.length>0?[]:Qt({properties:g},!0,e).map(({field:I})=>I).map(I=>{const U=P.has(I);return{id:I,accessorFn:H=>Ee(H.metadata)[I],header:({column:H})=>t.jsxs(Ze,{column:H,children:[U?I:qe(I.replace(/_/g," ")),U&&t.jsx(ht,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:H})=>t.jsx(jn,{value:H(),prop:g?.[I],className:U?"tabular-nums":"text-muted-foreground"}),meta:U?{align:"right"}:void 0}}),[r,A,e,P,g]),J=b.useMemo(()=>{const O=s?.["x-table-relationships"];return!O||O.length===0?[]:O.map(I=>({id:`rel_${I.relationship_type}`,accessorFn:U=>U.relationships?.[I.relationship_type]??[],header:I.label,cell:({getValue:U})=>{const H=U();return!H||H.length===0?t.jsx("span",{className:"text-muted-foreground",children:"-"}):t.jsx("div",{className:"flex flex-wrap gap-1",children:H.map((W,Q)=>{const re=nt(n,[{entity_type:W.entity_type,slug:W.slug}]);return t.jsxs("span",{children:[t.jsx(we,{to:re,className:"text-primary hover:underline",onClick:pe=>pe.stopPropagation(),children:W.name}),Q<H.length-1&&","]},W.id)})})}}))},[n,s]),q=b.useMemo(()=>l||e.some(I=>I.parent_name&&I.parent_slug&&I.parent_entity_type)?[{id:"parent",accessorFn:I=>I.parent_name,header:"Parent",cell:({row:I})=>{if(!I.original.parent_name||!I.original.parent_slug||!I.original.parent_entity_type)return t.jsx("span",{className:"text-muted-foreground",children:"-"});const U=nt(n,[{entity_type:I.original.parent_entity_type,slug:I.original.parent_slug}]);return t.jsx(we,{to:U,className:"text-primary hover:underline",children:I.original.parent_name})}}]:[],[e,l,n]),se=b.useMemo(()=>{const O=[],I=e.some(W=>(W.total_content??0)>0),U=e.some(W=>(W.active_connections??0)>0),H=e.some(W=>(W.automations_count??0)>0);return I&&O.push({accessorKey:"total_content",header:({column:W})=>t.jsx(Ze,{column:W,alignRight:!0,children:"Activity"}),cell:({row:W,getValue:Q})=>{const re=Q()??0;if(re===0)return t.jsx("span",{className:"tabular-nums",children:"0"});const pe=Ot(W.original);return t.jsx(we,{to:ss(n,pe),className:"tabular-nums hover:underline",children:re})},meta:{align:"right"}}),U&&O.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:W})=>{const Q=W();return Q&&Q>0?t.jsxs(ht,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[Q," active"]}):t.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),H&&O.push({accessorKey:"automations_count",header:({column:W})=>t.jsx(Ze,{column:W,alignRight:!0,children:"Automations"}),cell:({getValue:W})=>t.jsx("span",{className:"tabular-nums",children:W()??0}),meta:{align:"right"}}),O},[e,n]),V=b.useMemo(()=>[{accessorKey:"name",header:({column:O})=>w?t.jsx(Ze,{column:O,children:"Name"}):"Name",cell:({row:O})=>{const I=Ee(O.original.metadata);return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(on,{metadata:I,metadataSchema:s,name:O.original.name,typeIcon:a,className:"h-6 w-6 shrink-0"}),t.jsx("div",{className:"min-w-0",children:(()=>{const U=si(n,O.original);return t.jsx(we,{to:U,className:"block max-w-56 truncate font-medium hover:underline",title:O.original.name,children:O.original.name})})()})]})}},...q,...A,...D,...J,...se,...r?[]:[{accessorKey:"created_at",header:({column:O})=>t.jsx(Ze,{column:O,children:"Created"}),cell:({getValue:O})=>t.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(O()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[n,q,A,D,J,se,s,a,r,w]),ne=ca({data:e,columns:V,state:{sorting:y,columnVisibility:Object.fromEntries([...A,...D].flatMap(O=>O.id?[[O.id,!x||x.includes(r?O.id:O.id.replace(/^meta_/,""))]]:[]))},onSortingChange:c,getCoreRowModel:la(),manualSorting:!0,enableSortingRemoval:!1}),he=e.length>0||p>0;return t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"rounded-lg border",children:t.jsxs(pa,{className:"min-w-[48rem]",children:[t.jsx(ga,{children:ne.getHeaderGroups().map(O=>t.jsxs(Vt,{children:[O.headers.map(I=>t.jsx(Sn,{"aria-sort":I.column.getIsSorted()==="asc"?"ascending":I.column.getIsSorted()==="desc"?"descending":void 0,className:I.column.columnDef.meta?.align==="right"?"text-right":"",children:I.isPlaceholder?null:Nn(I.column.columnDef.header,I.getContext())},I.id)),k?t.jsx(Sn,{className:"w-10 pr-2 text-right",children:k}):null]},O.id))}),t.jsx(ya,{children:ne.getRowModel().rows.length?ne.getRowModel().rows.map(O=>t.jsxs(Vt,{children:[O.getVisibleCells().map(I=>t.jsx(Ut,{className:I.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:Nn(I.column.columnDef.cell,I.getContext())},I.id)),k?t.jsx(Ut,{}):null]},O.id)):t.jsx(Vt,{children:t.jsx(Ut,{colSpan:V.length+(k?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),he&&t.jsxs("div",{className:"mt-4 flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{children:["Showing ",e.length," of ",j," ",S.toLowerCase()]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{children:["Page ",p+1," of ",Math.max(1,Math.ceil(j/v))]}),t.jsx(Y,{variant:"outline",size:"sm",onClick:N,disabled:p===0,children:"Previous"}),t.jsx(Y,{variant:"outline",size:"sm",onClick:C,disabled:!d,children:"Next"})]})]})]})}function li(e){return String(e??"").replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function ks(e){return e["x-lobu"]?.role||e["x-lobu-role"]}function un(e){const n=e?.properties;if(!n)return null;const r=os(n).find(([,c])=>ks(c)==="workflowState");if(!r)return null;const[i,o]=r,l=o["x-lobu"]?.states,y=Array.isArray(l)&&l.length>0?l:(o.enum??[]).map(c=>({value:c}));return y.length===0||y.some(c=>typeof c.value!="string")?null:{field:i,states:y.map(c=>({...c,label:c.label||xr(o,c.value)||li(c.value),terminal:c.terminal??["done","complete","completed","closed","archived"].includes(c.value.toLowerCase())}))}}function di(e){const n=e?.properties;if(!n)return null;const s=Object.entries(n),a=s.find(([,o])=>ks(o)==="sortRank"),r=s.find(([o])=>["rank","sort_rank","order"].includes(o)),i=a??r;return i?{field:i[0]}:null}function ui(e,{isDerived:n}){const s=e?.["x-lobu"]?.defaultView;return(s==="table"||s==="board")&&!(n&&s!=="table")?s:n?"table":un(e)?"board":"table"}const js={version:1,root:{type:"entity-table",props:{state:"{{tableState}}"}}},mi={version:1,root:{type:"entity-board",props:{state:"{{boardState}}",onUpdate:"@updateEntity"}}};function fi(e){const{canShowBoard:n,builtinData:s,builtInLabels:a}=e,r=["table",...n?["board"]:[]],i={table:js,board:mi};return r.map(o=>({id:o,label:a[o],builtInMode:o,template:i[o],data:s}))}function Xt(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Lt(e,n){if(!n)return e.created_at??String(e.id);const s=Ee(e.metadata);return String(s[n.field]??e.created_at??e.id)}function hi(e,n){const s=e?Number(e):Number.NaN,a=n?Number(n):Number.NaN;return Number.isFinite(s)&&Number.isFinite(a)&&s<a?String((s+a)/2):Number.isFinite(s)?String(s+1):Number.isFinite(a)?String(a-1):String(Date.now())}function Zt(e,n){const s=Ee(e.metadata);return String(s[n]??"")}function Ns(e,n){return[...e].sort((s,a)=>Lt(s,n).localeCompare(Lt(a,n)))}function pi(e,n,s,a,r){if(!n.startsWith("card:")||!s)return null;const i=Number(n.slice(5)),o=e.find(N=>N.id===i);if(!o)return null;const l=s.startsWith("column:")?s.slice(7):Zt(e.find(N=>`card:${N.id}`===s)??o,a.field);if(!l)return null;const y=Ns(e.filter(N=>N.id!==i&&Zt(N,a.field)===l),r),c=s.startsWith("card:")?y.findIndex(N=>`card:${N.id}`===s):y.length,x=c>=0?c:y.length,m=x>0?y[x-1]:void 0,h=y[x],p=r?hi(m?Lt(m,r):void 0,h?Lt(h,r):void 0):void 0,v=Ee(o.metadata),j={[a.field]:l,...r&&p?{[r.field]:p}:{}};a.states.find(N=>N.value===l)?.terminal&&!v.completed_at&&(j.completed_at=new Date().toISOString());const S={...v,...j};return{entityId:i,changedMetadata:j,nextMetadata:S}}function Bn(e,n,s){return e.map(a=>a.id===n?{...a,metadata:s}:a)}function gi({id:e,children:n,className:s}){const{setNodeRef:a,isOver:r}=ms({id:`column:${e}`});return t.jsx("div",{ref:a,className:de("min-h-[220px] rounded-lg bg-card p-2 transition-colors",r?"bg-accent/50":"",s),children:n})}function yi({entity:e,owner:n,statusField:s,entityTypeIcon:a,schema:r,didDragRef:i}){const o=Ee(e.metadata),{attributes:l,listeners:y,setNodeRef:c,transform:x,isDragging:m}=ka({id:`card:${e.id}`}),{setNodeRef:h,isOver:p}=ms({id:`card:${e.id}`}),v=nt(n,Ot(e)),j=d=>{i.current&&(d.preventDefault(),d.stopPropagation())};return t.jsx("div",{ref:d=>{c(d),h(d)},style:{transform:ja.Translate.toString(x)},className:de(wr,"p-3 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",m?"opacity-60":"",p?"ring-1 ring-ring":""),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("button",{type:"button",className:"mt-0.5 shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing","aria-label":`Drag ${e.name}`,...l,...y,children:t.jsx(vr,{className:"h-4 w-4"})}),t.jsx(on,{metadata:o,metadataSchema:r,name:e.name,typeIcon:a,className:"mt-0.5 h-6 w-6 shrink-0",initialsFallback:!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx(we,{to:v,className:"font-medium text-foreground hover:underline",onClick:j,children:e.name}),t.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[typeof o.priority=="string"&&o.priority?t.jsx(ht,{variant:"outline",className:"text-xs",children:Xt(o.priority)}):null,typeof o[s]=="string"&&o[s]?t.jsx(ht,{variant:"secondary",className:"text-xs",children:Xt(String(o[s]))}):null]})]})]})})}function xi({owner:e,entities:n,totalCount:s,schema:a,entityTypeIcon:r,onUpdate:i}){const o=b.useMemo(()=>un(a),[a]),l=b.useMemo(()=>di(a),[a]),[y,c]=b.useState(n),[x,m]=b.useState(()=>new Set),h=b.useRef(!1),p=xa(ba(wa,{activationConstraint:{distance:6}})),v=b.useCallback(()=>{window.setTimeout(()=>{h.current=!1},0)},[]);b.useEffect(()=>{c(n)},[n]);const j=b.useMemo(()=>{if(!o)return new Map;const C=new Map(o.states.map(k=>[k.value,[]]));for(const k of y){const g=Zt(k,o.field),w=C.has(g)?g:o.states[0]?.value;w&&C.get(w)?.push(k)}for(const[k,g]of C)C.set(k,Ns(g,l));return C},[y,l,o]);if(!o)return null;const d=C=>{m(k=>{const g=new Set(k);return g.has(C)?g.delete(C):g.add(C),g})},S=()=>{h.current=!0},N=C=>{const k=String(C.active.id),g=C.over?String(C.over.id):null,w=pi(y,k,g,o,l);if(!w){v();return}const{entityId:M,changedMetadata:A,nextMetadata:P}=w,J=y.find(q=>q.id===M)?.metadata;c(q=>Bn(q,M,P)),i(M,A).catch(()=>{c(q=>Bn(q,M,J))}),v()};return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-base font-semibold",children:"Board"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Grouped by ",Xt(o.field),typeof s=="number"&&s>y.length?t.jsxs(t.Fragment,{children:[" · ",t.jsxs("span",{className:"text-amber-600 dark:text-amber-500",children:["showing first ",y.length," of ",s," — narrow with search"]})]}):null]})]}),t.jsx(va,{sensors:p,onDragStart:S,onDragEnd:N,children:t.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:o.states.map(C=>{const k=j.get(C.value)??[],g=C.collapsed??C.terminal,w=g&&!x.has(C.value);return t.jsxs(gi,{id:C.value,children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[C.terminal?t.jsx(br,{className:"h-4 w-4 text-muted-foreground"}):null,t.jsx("h3",{className:"text-sm font-medium",children:C.label})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ht,{variant:"secondary",className:"text-xs",children:k.length}),g?t.jsx(Y,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",onClick:()=>d(C.value),children:w?"Show":"Hide"}):null]})]}),w?t.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:[k.length," hidden ",C.label?.toLowerCase()," item",k.length===1?"":"s"]}):t.jsx("div",{className:"space-y-2",children:k.length>0?k.map(M=>t.jsx(yi,{entity:M,owner:e,statusField:o.field,entityTypeIcon:r,schema:a,didDragRef:h},M.id)):t.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:["No ",C.label?.toLowerCase()," items"]})})]},C.value)})})})]})}const bi=b.memo(xi);function vi(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s),n|=0;return n.toString(36)}function Ss(e,n){return{queryKey:["metric_series",e,vi(n)],queryFn:()=>Nt("metric_series",{sql:n},{slug:e}),staleTime:6e4}}function Es(e,n){const s=!!e&&!!n,a=Ss(e??"",n??"");return ts({...a,enabled:s})}Es.queryOptions=(e,n)=>Ss(e,n);function wi(e,n){if(!e?.columns?.length||!e.rows)return[];const s=e.columns.indexOf(n);return s<0?[]:e.rows.map(a=>Number(a[s])||0)}const Hn=/^[a-z][a-z0-9_]*$/;function ki(e){const n=Object.entries(e);for(const[r,i]of n){if(!Hn.test(r))throw new Error(`lifecycleCumulativeStatsSql: unsafe column name '${r}'`);if(!Hn.test(i))throw new Error(`lifecycleCumulativeStatsSql: unsafe entity_type '${i}'`)}const s=n.flatMap(([r,i])=>[`COUNT(*) FILTER (
3
+ WHERE semantic_type = 'change'
4
+ AND metadata->>'category' = 'lifecycle'
5
+ AND metadata->>'entity_type' = '${i}'
6
+ AND metadata->>'op' = 'created'
7
+ ) AS ${r}_added`,`COUNT(*) FILTER (
8
+ WHERE semantic_type = 'change'
9
+ AND metadata->>'category' = 'lifecycle'
10
+ AND metadata->>'entity_type' = '${i}'
11
+ AND metadata->>'op' = 'deleted'
12
+ ) AS ${r}_removed`]).join(`,
13
+ `),a=n.map(([r])=>` SUM(COALESCE(b.${r}_added, 0) - COALESCE(b.${r}_removed, 0))
14
+ OVER (ORDER BY d.bucket) AS ${r}`).join(`,
15
+ `);return`
16
+ WITH days AS (
17
+ SELECT generate_series(
18
+ date_trunc('day', now() - interval '13 days'),
19
+ date_trunc('day', now()),
20
+ interval '1 day'
21
+ ) AS bucket
22
+ ),
23
+ buckets AS (
24
+ SELECT
25
+ date_trunc('day', created_at) AS bucket,
26
+ ${s}
27
+ FROM events
28
+ WHERE created_at > now() - interval '14 days'
29
+ GROUP BY 1
30
+ )
31
+ SELECT d.bucket,
32
+ ${a}
33
+ FROM days d
34
+ LEFT JOIN buckets b ON b.bucket = d.bucket
35
+ ORDER BY d.bucket
36
+ `}const ji={"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 Ni(e){if(typeof e.sql=="string"&&e.sql.trim())return e.sql;if(e.lifecycle&&typeof e.lifecycle=="object"){const n=Object.fromEntries(Object.entries(e.lifecycle).map(([s,a])=>[s,String(a)]));if(Object.keys(n).length>0)try{return ki(n)}catch{return null}}return typeof e.preset=="string"?ji[e.preset]??null:null}function Si({owner:e,sql:n,lifecycle:s,preset:a,column:r,chart:i,height:o,width:l,color:y,label:c,className:x}){const m=b.useMemo(()=>Ni({sql:n,lifecycle:s,preset:a}),[n,s,a]),h=typeof e=="string"&&e?e:null,{data:p}=Es(h,m),v=String(r??""),j=b.useMemo(()=>wi(p,v),[p,v]),d=b.useMemo(()=>!p?.columns?.length||!p.rows?[]:p.rows.map((N,C)=>({label:String(N[0]??"").slice(0,10),value:j[C]??0})),[p,j]);if(!h||!m||!v)return null;const S=i==="line"?t.jsx(da,{data:d,height:typeof o=="number"?o:void 0}):t.jsx(ua,{data:j,height:typeof o=="number"?o:void 0,width:typeof l=="number"?l:void 0,color:typeof y=="string"?y:void 0});return c==null?t.jsx("div",{className:x,children:S}):t.jsxs("div",{className:x,children:[t.jsx("p",{className:"text-sm text-muted-foreground",children:String(c)}),S]})}function Ei({metadata:e,metadataSchema:n,name:s,typeIcon:a,initialsFallback:r,className:i}){return t.jsx(on,{metadata:e,metadataSchema:n,name:String(s??""),typeIcon:a,initialsFallback:!!r,className:i})}function Ci({entity:e,owner:n,className:s,onClick:a,children:r}){const i=e;if(!i)return t.jsx(t.Fragment,{children:r});const o=nt(String(n??""),Ot(i));return t.jsx(we,{to:o,className:s,onClick:a,children:r})}function _i({state:e}){return e?t.jsx(ci,{...e}):null}function Mi({state:e,onUpdate:n}){return e?t.jsx(bi,{...e,onUpdate:n}):null}const Ti={"entity-avatar":Ei,"entity-link":Ci,"entity-table":_i,"entity-board":Mi,"metric-series":Si};function Li({ownerSlug:e,typeSlug:n,title:s,shape:a}){const[r,i]=b.useState(!1),o=at(),{visible:l,system:y,isTypesLoading:c}=kr(e),x=h=>{i(!1);const p=`/${e}/${cs(h)}`;o({to:a?`${p}/${ls}/${a}`:p})},m=h=>t.jsxs(Mr,{value:`${h.name} ${h.slug}`,onSelect:()=>x(h.slug),children:[t.jsx(Rt,{icon:h.icon,className:"mr-2 h-4 w-4 shrink-0"}),t.jsx("span",{className:"flex-1 truncate",children:h.name||h.slug}),h.slug===n?t.jsx(Tr,{className:"ml-2 h-3.5 w-3.5 shrink-0","aria-label":"Current"}):null,h.entity_count!=null?t.jsx("span",{className:"ml-2 shrink-0 text-xs tabular-nums text-muted-foreground",children:h.entity_count.toLocaleString()}):null]},h.slug);return t.jsxs(sn,{open:r,onOpenChange:i,children:[t.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:t.jsx(rn,{asChild:!0,children:t.jsxs(Y,{type:"button",variant:"ghost",className:"-ml-2 h-auto gap-1.5 px-2 py-1 text-2xl font-semibold tracking-tight",children:[s,t.jsx(is,{className:"h-5 w-5 text-muted-foreground"})]})})}),t.jsx(an,{align:"start",className:"w-72 p-0",children:t.jsxs(jr,{children:[t.jsx(Nr,{autoFocus:!0,placeholder:"Find a type…"}),t.jsxs(Sr,{children:[t.jsx(Er,{children:c?"Loading types…":"No type matches."}),l.length>0?t.jsx(vn,{heading:"Types",children:l.map(m)}):null,y.length>0?t.jsx(vn,{heading:"System",children:y.map(m)}):null]}),t.jsx(Cr,{}),t.jsxs(we,{to:"/$owner/data",params:{owner:e},onClick:()=>i(!1),className:"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:text-foreground",children:[t.jsx(_r,{className:"h-4 w-4"}),"Schema map"]})]})})]})}function Ri(e){return Object.entries(e?.metrics_config?.segments??{}).filter(([,n])=>n.on==="entity").map(([n,s])=>({name:n,description:s.description}))}const vt={table:{label:"Table",icon:Ar},board:{label:"Board",icon:ns},graph:{label:"Graph",icon:as}},Cs=(e,n)=>`lobu.record-shape:v1:${e}/${n}`,Ii=new Set(["table","board","graph"]);function Oi(e,n){const s=Gn(Cs(e,n));return s&&Ii.has(s)?s:void 0}function $i(e,n,s){Kn(Cs(e,n),s)}const Vn=":records";function Ai({ownerSlug:e,entityTypeSlug:n,create:s,onCreateChange:a,viewKey:r,shape:i}){const{orgContext:o,hasOrgContext:l}=De(),y=Xn(n,o),{data:c,isLoading:x,error:m}=y;Lr(`/${e}`,o);const h=Rr(),[p,v]=b.useState({key:"",page:0}),j=ds({strict:!1}),d=at(),S=tn(),N=`/${e}/${cs(n)}`,C=!x&&c?.slug===n,{collection:k,error:g,presentation:w,preset:M,edited:A,table:P}=b.useMemo(()=>Mo(j,c?.metadata_schema,!!r),[j,c?.metadata_schema,r]),D=C?g:void 0,J=b.useMemo(()=>Oo(j,k),[j,k]),[q,se]=b.useState(!1),[V,ne]=b.useState(0),he=k.search??"",O=k.segment,I=JSON.stringify(k),U=O?Ri(c).find(R=>R.name===O)??{name:O,description:""}:null,H=R=>void d({to:".",search:{...Ue(R),...J},replace:!0}),W=Ir(y.data),Q=W?P.sort:Ao(P),re=Q?.field,pe=Q?.order,ue=b.useMemo(()=>re?[{id:re,desc:pe==="desc"}]:[],[re,pe]),Ce=b.useCallback(R=>void d({to:".",search:{...r?Ue(j):{},...J,$table:JSON.stringify(R)},replace:!0}),[d,r,j,J]),Fe=b.useCallback(R=>{const ee=typeof R=="function"?R(ue):R;ee[0]&&Ce({...P,sort:{field:ee[0].id,order:ee[0].desc?"desc":"asc"}})},[ue,Ce,P]),Ne=s===!0,Ge=()=>a(!0),_e=()=>a(!1),ze=ue[0]?.id,ye=ue[0]?ue[0].desc?"desc":"asc":void 0,Le=y.data?.metadata_schema,xe=!!un(Le)&&!W,Re=ui(Le,{isDerived:W}),ce=us(o),ot=Ht(ce.data??[],n,k),ke=(R,ee=!1,je=Ue(j))=>{const be=!r||!ce.data||Ht(ce.data,n,R).some(pt=>pt.key===r);d({to:be?".":N,search:{...be&&r?je:{},...To(R,M?.key),$table:JSON.stringify(P)},replace:ee})},Ie=R=>{const ee=R?jt(R):{},je=!r||Ht(ce.data??[],n,ee).some(be=>be.key===r);se(!1),ne(be=>be+1),d({to:je?".":N,search:R?{$preset:R.key}:{}})},{isAdmin:We}=Yn(o.organizationId),Be=Or(o),_=We&&!!c&&!y.isPlaceholderData,u=b.useRef(j);u.current=j;const f=async()=>{if(!M)return;const R=JSON.stringify(j),{data:ee}=await y.refetch(),je=ee?.metadata_schema,be=je?nn(je[Yt]??{}):void 0,pt=be?.presets?.find(gt=>gt.key===M.key);if(!ee||!je||!be||!pt){Zn.error("This saved filter changed. Reload and try again.");return}const Dt=Lo(pt,k,P,be);await Be.mutateAsync({slug:ee.slug,metadata_schema:{...je,[Yt]:{...be,presets:be.presets?.map(gt=>gt.key===Dt.key?Dt:gt)}}}).then(()=>!0,()=>!1)&&(await y.refetch(),JSON.stringify(u.current)===R&&Ie(Dt))},E=b.useMemo(()=>Oi(e,n),[e,n]),T=$r(ce.data??[],n,{viewKey:r,shape:i??(r?void 0:E)},Re,k),L=T.kind==="builtin"?T.mode==="board"&&!xe?"table":T.mode:null,z=L==="graph";b.useEffect(()=>{i&&C&&L&&$i(e,n,L)},[i,C,L,e,n]);const G=["table",...xe?["board"]:[],"graph"],B=T.kind==="view"?T.view:null,F=T.kind==="missing"?T.key:null,me=T.kind==="inapplicable"?T:null,le=L==="table"?50:200,Se=`${n}?${I}&sort=${JSON.stringify(P.sort)}&size=${le}`,Oe=p.key===Se?p.page:0,Ke=b.useCallback(R=>v(ee=>({key:Se,page:R(ee.key===Se?ee.page:0)})),[Se]),$e=wn(n,o,{limit:le,offset:Oe*le,search:he.trim()||void 0,sortBy:ze,sortOrder:ye,segment:O,filters:k.filters,enabled:C&&!r&&!D}),Ye=wn(n,o,{limit:1,offset:0,parentId:null,search:he.trim()||void 0,segment:O,filters:k.filters,enabled:C&&!r&&!D&&!W}),{data:Je,error:$t}=$e,$=$e.isLoading||$e.isPending&&$e.fetchStatus==="paused",Z=D||m||(r?null:$t),te=!!r&&ce.data===void 0&&ce.isError,K=Je?.entities??[],ae=Je?.metadata?.has_more??!1,X=Je?.metadata?.total_count??0,Ae=K.length>0||he.trim().length>0||Oe>0||!!O||!!k.filters?.length,ie=c?.name?.trim()||qe(n),ge=c?.icon||void 0,oe=W,fe=Le,Me=!D&&(!l||!C||(r?ce.data===void 0&&!ce.isError:$||!W&&Ye.isLoading)),He=Je?.linked_entities??{},it=Ye.data?.metadata?.total_count,Qe=X>0&&typeof it=="number"?it<X:!1,ct=b.useMemo(()=>c?.measure_columns??[],[c?.measure_columns]),Xe=b.useCallback(R=>Ce({...P,columns:R}),[Ce,P]),lt=b.useMemo(()=>({entities:K,owner:e,schema:fe,entityTypeIcon:ge,isDerived:oe,measureColumns:ct,linkedEntityLookups:He,hasAnyParents:Qe,sorting:ue,onSortingChange:Fe,visibleColumns:P.columns,columnChoices:Qt(fe,oe,K),onVisibleColumnsChange:Xe,page:Oe,pageSize:le,totalCount:X,hasMore:ae,pageTitle:ie,onPrevPage:()=>Ke(R=>Math.max(0,R-1)),onNextPage:()=>Ke(R=>R+1)}),[K,e,fe,ge,oe,ct,He,Qe,ue,P.columns,Xe,Fe,Ke,Oe,le,X,ae,ie]),mn=X>K.length,fn=`showing first ${K.length} of ${X} — narrow with search`,hn=b.useMemo(()=>({owner:e,entityType:c,entities:K,totalCount:X,schema:fe,entityTypeIcon:ge}),[e,c,K,X,fe,ge]),At=b.useMemo(()=>({tableState:lt,boardState:hn,owner:e,schema:fe,entityType:c,entityTypeIcon:ge,totalCount:X,isTruncated:mn,truncationNotice:fn,canCreate:!oe,addLabel:`Add ${c?.name||qe(n)}`}),[lt,hn,e,fe,c,ge,X,mn,fn,oe,n]),_s=b.useMemo(()=>fi({canShowBoard:xe,builtinData:At,builtInLabels:{table:vt.table.label,board:vt.board.label}}),[xe,At]),pn=L?_s.find(R=>R.id===L)??null:null,Ms=pn?.template??js,Ts=pn?.data??At,gn=R=>void d({to:R===Vn?N:`${N}${zr(R)}`,search:J}),Pt=Ue(j),Ls=Na(B?.params,Pt,R=>void d({to:".",search:{...Ue(R),...J}})),Rs=()=>ke({...k,filters:[],segment:void 0},!1,Sa(B?.params,Pt)),yn=`Moved on ${c?.name||c?.slug||n} board`,xn=b.useMemo(()=>(R,ee)=>h.mutateAsync({entityId:R,metadata:ee,field_note:yn}),[h,yn]),Is=b.useMemo(()=>({updateEntity:xn,openCreate:()=>a(!0)}),[xn,a]),bn=R=>S?t.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:de("size-8 text-muted-foreground hover:text-foreground",R),"aria-label":"Edit type",title:"Edit type",onClick:()=>S.open({href:Fr(e,n),title:ie}),children:t.jsx(Dr,{className:"h-4 w-4"})}):null;return t.jsxs("div",{className:"@container space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Li,{ownerSlug:e,typeSlug:n,title:ie,shape:r?null:L}),bn(Ne||!C?"":"hidden @lg:inline-flex")]}),t.jsxs("div",{children:[Ne?t.jsx("div",{className:"max-w-3xl",children:t.jsx(Eo,{onClose:_e,entityTypeSlug:n,orgContext:o})}):null,!Ne&&C&&t.jsxs("nav",{className:"mb-4 flex flex-wrap items-center gap-x-3 gap-y-2","aria-label":`${ie} views`,children:[bn("-mr-1 @lg:hidden"),!r&&G.length>1&&t.jsx("fieldset",{className:"flex items-center rounded-md border p-0.5","aria-label":"Record layout",children:G.map(R=>{const ee=vt[R].icon,je=L===R;return t.jsx(Y,{type:"button",variant:"ghost",size:"sm","aria-pressed":je,title:vt[R].label,"data-testid":`shape-${R}`,className:de("h-7 px-2",je&&"bg-accent text-accent-foreground"),onClick:()=>void d({to:`${N}/${ls}/${R}`,search:J,replace:!0}),children:t.jsx(ee,{className:"h-4 w-4"})},R)})}),r&&t.jsx(Y,{variant:"ghost",onClick:()=>gn(Vn),children:"Records"}),!!w.presets?.length&&t.jsxs(sn,{open:q,onOpenChange:se,children:[t.jsx(rn,{asChild:!0,children:t.jsxs(Y,{variant:"outline",className:de("gap-2",A&&"border-dashed border-primary"),"data-edited":A||void 0,title:"Choose saved filter",children:[M?.label??(k.filters?.length||k.search?"Custom filter":"All records"),A?t.jsx("span",{className:"text-xs font-normal text-primary",children:"Edited"}):null,t.jsx(is,{className:"h-4 w-4 text-muted-foreground"})]})}),t.jsxs(an,{align:"start",className:"w-60 p-1",children:[t.jsx(Y,{variant:M?"ghost":"secondary",className:"w-full justify-start",onClick:()=>Ie(),children:"All records"}),w.presets.map(R=>t.jsx(Y,{variant:M?.key===R.key?"secondary":"ghost",className:"w-full justify-start",onClick:()=>Ie(R),children:R.label},R.key))]})]}),M&&A?t.jsxs("div",{className:"-ml-2 mr-2 inline-flex items-center gap-1",children:[t.jsx(Y,{variant:"ghost",size:"sm",onClick:()=>Ie(M),children:"Reset"}),_?t.jsx(Y,{size:"sm",disabled:Be.isPending,onClick:()=>void f(),children:Be.isPending?"Saving…":"Save"}):null]}):null,!D&&t.jsx(Ho,{collection:k,schema:fe,label:ie,org:o??"",facetQuery:w.facetQuery,onChange:ke,viewFilters:Ls,onClearAll:Rs,segmentChip:U?{id:"segment",label:"Segment",op:"is",value:qe(U.name),title:U.description||void 0,editor:U.description?{kind:"custom",render:()=>t.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:U.description})}:void 0,onRemove:()=>ke({...k,segment:void 0})}:void 0},`filters:${n}:${V}`),ot.map(R=>t.jsx(Y,{"data-testid":`tab-${R.key}`,variant:r===R.key?"secondary":"ghost","aria-pressed":r===R.key,onClick:()=>gn(R.key),children:R.name},R.key)),t.jsx(Fo,{label:ie,search:k.search,onSearch:(R,ee)=>ke({...k,search:R},ee),className:"ml-auto min-w-40 max-w-64 flex-1"},`search:${n}:${V}`),!oe&&!r?t.jsxs(Y,{size:"sm","aria-label":`Add ${ie||"entity"}`,onClick:()=>Ge(),children:[t.jsx(mt,{className:"mr-2 h-4 w-4"}),"Add"]}):null]}),Ne?null:Me?z?t.jsx(cn,{label:`Loading ${ie} graph`}):t.jsx(Pi,{}):Z?t.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[Z.message||`Failed to load ${ie.toLowerCase()}.`,D&&t.jsx(Y,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>ke({}),children:"Clear filters"})]}):te?t.jsx(fs,{onRetry:()=>void ce.refetch()}):me?t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"inapplicable-view",children:[t.jsxs("h2",{className:"text-lg font-semibold",children:["“",me.view.name,"” doesn’t apply to the current filters"]}),t.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["It appears when the selection includes"," ",Object.entries(me.when).map(([R,ee])=>`${R} is ${ee===null?"not supplied":String(ee)}`).join(" and "),"."]}),t.jsx(we,{to:N,search:J,className:"mt-4 text-sm font-medium underline underline-offset-4",children:`Back to ${ie}`})]}):F?t.jsx(hs,{viewKey:F,backTo:N,backLabel:`Back to ${ie}`}):B?t.jsx(ps,{orgSlug:e,viewKey:B.key,scope:{type:n,collection:k},params:Pt,onParamsChange:H,contentHash:B.content_hash,title:B.name,minHeight:320}):z&&Ae?t.jsx(ei,{ownerSlug:e,typeSlug:n,sourceBacked:W,records:K.map(R=>({...R,id:R.id??JSON.stringify([R.entity_type,R.slug])})),hasMore:ae}):Ae?t.jsx(ma,{template:Ms,data:Ts,actions:Is,components:Ti}):t.jsx(rs,{icon:Pr,iconElement:t.jsx(Rt,{icon:c?.icon,className:"mb-4 h-12 w-12 opacity-50"}),title:`No ${ie.toLowerCase()} yet`,description:oe?"This view has no rows yet. They appear as the underlying data arrives.":`Get started by creating your first ${c?.name?.toLowerCase()||"entity"}.`,actionLabel:oe?void 0:`Add ${c?.name||"Entity"}`,onAction:oe?void 0:()=>Ge()})]})]})}function Pi(){return t.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx(ve,{className:"h-9 max-w-sm flex-1"}),t.jsx(ve,{className:"h-9 w-28"})]}),t.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[t.jsx("div",{className:"border-b px-4 py-3",children:t.jsx(ve,{className:"h-3 w-1/3"})}),t.jsx("div",{className:"divide-y",children:Array.from({length:5}).map((e,n)=>t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[t.jsx(ve,{className:"h-3 flex-1"}),t.jsx(ve,{className:"h-3 w-16 shrink-0"})]},n))})]})]})}function Di({ownerSlug:e,typeScope:n,create:s,createType:a=!1,viewKey:r,shape:i}){const o=at(),{orgContext:l}=De(),y=ds({strict:!1}),c=n?Wr(n):void 0,x=c==="$member",m=()=>{o({to:"/$owner/data",params:{owner:e},search:{}})},h=v=>{if(!c)return;const j=Jn(e,c);o({to:j.to,params:j.params,search:v?{create:!0}:{},replace:!0})},p=a?t.jsx("div",{className:"mx-auto w-full max-w-3xl",children:t.jsx(Ca,{entityType:null,orgContext:l,onClose:m})}):c?t.jsx(Ai,{ownerSlug:e,entityTypeSlug:c,create:s,onCreateChange:h,viewKey:r,shape:i}):t.jsx(Fi,{ownerSlug:e,viewKey:r,search:y});return t.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:x?t.jsx(_a,{children:p}):p})}function Fi({ownerSlug:e,viewKey:n,search:s}){const a=at(),{orgContext:r}=De(),{data:i,isError:o,refetch:l}=us(r),y=Br(i??[],n),c=Hr(),x=Vr(i??[]);return n&&i===void 0?o?t.jsx(fs,{onRetry:()=>void l()}):null:y.kind==="missing"?t.jsx(hs,{viewKey:y.key,backTo:`/${e}/data`,backLabel:"Back to Memory"}):t.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:[c&&x.length>0?t.jsxs("nav",{"aria-label":"Workspace views",className:"flex shrink-0 flex-wrap gap-1",children:[t.jsx(we,{to:"/$owner/data",params:{owner:e},search:{},activeOptions:{exact:!0},"aria-current":n?void 0:"page",className:Un(!n),children:"Overview"}),x.map(m=>t.jsx(we,{to:"/$owner/data/-/views/$viewKey",params:{owner:e,viewKey:m.key},search:{},activeOptions:{exact:!0},"aria-current":n===m.key?"page":void 0,className:Un(n===m.key),children:m.name},m.key))]}):null,c&&o?t.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Couldn’t load views."," ",t.jsx("button",{type:"button",onClick:()=>void l(),className:"underline underline-offset-4",children:"Retry"})]}):null,y.kind==="view"?t.jsxs(t.Fragment,{children:[t.jsx(Ea,{decls:y.view.params,params:Ue(s),onParamsChange:m=>void a({to:".",search:m})}),t.jsx(ps,{orgSlug:e,viewKey:y.view.key,scope:{},params:Ue(s),onParamsChange:m=>void a({to:".",search:m,replace:!0}),contentHash:y.view.content_hash,title:y.view.name,minHeight:400})]}):t.jsx(So,{ownerSlug:e})]})}const Un=e=>de("inline-flex min-h-10 max-w-full items-center rounded-md px-3 text-sm font-medium break-words focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",e?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground");function rc({ownerSlug:e,typeScope:n,create:s,createType:a=!1,viewKey:r,shape:i}){return t.jsxs("div",{className:"flex flex-1 flex-col gap-6 px-4 pt-2.5 pb-8 lg:px-6",children:[t.jsx(qr,{}),t.jsx(Ur,{owner:e,children:o=>t.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:t.jsx(Di,{ownerSlug:o.ownerSlug,typeScope:n,create:s,createType:a,viewKey:r,shape:i})})})]})}export{rc as M};
74
+ //# sourceMappingURL=memory-browse-page-p2vIbfkC.js.map
@@ -1,2 +1,2 @@
1
- import{ax as g,ay as y,j as s,eJ as N,cS as m,dK as p,T as f,B as w,eL as b}from"./index-JmEl29py.js";function M(o,r){const l=new Map(r.map(e=>[e.slug,e])),i=new Map,d=e=>{const a=e.model?.trim();if(!a)return;const t=`${e.slug}/${a}`;i.has(t)||i.set(t,{value:t,provider:e.provider,model:a,isDefault:e.isDefault})};for(const e of o){const a=l.get(e.kind)??l.get(e.slug),t={slug:e.slug,provider:e.displayName||e.slug,isDefault:e.isDefault};d({...t,model:e.capabilities.text?.model}),d({...t,model:a?.defaultModel});for(const x of a?.models??[])d({...t,model:x})}for(const e of r){if(!e.systemAvailable)continue;const a={slug:e.slug,provider:e.displayName||e.slug,isDefault:!1};d({...a,model:e.defaultModel});for(const t of e.models)d({...a,model:t})}return[...i.values()]}function S(o,r){const l=o.trim();return l.length>0&&l!=="auto"&&!r.some(i=>i.value===l)}function D({value:o,onChange:r,placeholder:l,disabled:i,className:d}){const{data:e=[]}=g(),{data:a=[]}=y(),t=M(e,a),x=t.find(c=>c.value===o),h=o==="auto"?"auto":x?.value??o;return s.jsx(N,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:c=>s.jsxs(w,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:i,className:f("w-full justify-between font-normal",o?"":"text-muted-foreground",d),children:[s.jsx("span",{className:"truncate",children:o?h:l}),s.jsx(b,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(c,j)=>{const u=j.trim(),v=S(u,t);return s.jsxs(s.Fragment,{children:[s.jsxs(m,{value:"__inherit__ use default inherit",onSelect:()=>{r(""),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===""?"opacity-100":"opacity-0")}),s.jsx("span",{className:"text-muted-foreground",children:l})]}),s.jsxs(m,{value:"auto newest latest",onSelect:()=>{r("auto"),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o==="auto"?"opacity-100":"opacity-0")}),s.jsxs("span",{children:["auto"," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:"(newest for the provider)"})]})]}),t.map(n=>s.jsxs(m,{value:`${n.provider} ${n.model} ${n.value}`,onSelect:()=>{r(n.value),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===n.value?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"truncate",children:[n.provider," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:n.model}),n.isDefault?s.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},n.value)),v?s.jsxs(m,{value:`__custom__ ${u}`,onSelect:()=>{r(u),c()},className:"cursor-pointer",children:[s.jsx(p,{className:"mr-2 h-4 w-4 opacity-0"}),s.jsxs("span",{children:["Use ",s.jsx("span",{className:"font-mono text-xs",children:u})]})]}):null]})}})}export{D as M,M as b,S as s};
2
- //# sourceMappingURL=model-selector-BeFuFH7p.js.map
1
+ import{az as g,aA as N,j as s,eP as y,cY as m,dF as p,h as f,B as w,eR as b}from"./index-008wj-Pz.js";function M(o,r){const l=new Map(r.map(e=>[e.slug,e])),i=new Map,d=e=>{const a=e.model?.trim();if(!a)return;const t=`${e.slug}/${a}`;i.has(t)||i.set(t,{value:t,provider:e.provider,model:a,isDefault:e.isDefault})};for(const e of o){const a=l.get(e.kind)??l.get(e.slug),t={slug:e.slug,provider:e.displayName||e.slug,isDefault:e.isDefault};d({...t,model:e.capabilities.text?.model}),d({...t,model:a?.defaultModel});for(const x of a?.models??[])d({...t,model:x})}for(const e of r){if(!e.systemAvailable)continue;const a={slug:e.slug,provider:e.displayName||e.slug,isDefault:!1};d({...a,model:e.defaultModel});for(const t of e.models)d({...a,model:t})}return[...i.values()]}function _(o,r){const l=o.trim();return l.length>0&&l!=="auto"&&!r.some(i=>i.value===l)}function S({value:o,onChange:r,placeholder:l,disabled:i,className:d}){const{data:e=[]}=g(),{data:a=[]}=N(),t=M(e,a),x=t.find(c=>c.value===o),h=o==="auto"?"auto":x?.value??o;return s.jsx(y,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:c=>s.jsxs(w,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:i,className:f("w-full justify-between font-normal",o?"":"text-muted-foreground",d),children:[s.jsx("span",{className:"truncate",children:o?h:l}),s.jsx(b,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(c,j)=>{const u=j.trim(),v=_(u,t);return s.jsxs(s.Fragment,{children:[s.jsxs(m,{value:"__inherit__ use default inherit",onSelect:()=>{r(""),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===""?"opacity-100":"opacity-0")}),s.jsx("span",{className:"text-muted-foreground",children:l})]}),s.jsxs(m,{value:"auto newest latest",onSelect:()=>{r("auto"),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o==="auto"?"opacity-100":"opacity-0")}),s.jsxs("span",{children:["auto"," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:"(newest for the provider)"})]})]}),t.map(n=>s.jsxs(m,{value:`${n.provider} ${n.model} ${n.value}`,onSelect:()=>{r(n.value),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===n.value?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"truncate",children:[n.provider," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:n.model}),n.isDefault?s.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},n.value)),v?s.jsxs(m,{value:`__custom__ ${u}`,onSelect:()=>{r(u),c()},className:"cursor-pointer",children:[s.jsx(p,{className:"mr-2 h-4 w-4 opacity-0"}),s.jsxs("span",{children:["Use ",s.jsx("span",{className:"font-mono text-xs",children:u})]})]}):null]})}})}export{S as M,M as b,_ as s};
2
+ //# sourceMappingURL=model-selector-3l9lY50C.js.map
@@ -0,0 +1,2 @@
1
+ import{c as f}from"./cronstrue-xxpD1P2-.js";import{g7 as d}from"./index-008wj-Pz.js";function m(e){try{return f.toString(e.trim(),{throwExceptionOnParseError:!0})}catch{return`On schedule ${e.trim()}`}}function _(e,t){return t.get(e)??e}function k(e){return d(e.replace(/^\$/,""))}function h(e,t){const n=t?.display_name?.trim();return n&&t?.external_tenant_id===e?n:`#${e}`}function v(e,t){if(!e||typeof e!="object"||Array.isArray(e))return"";const n=e;return typeof n.repository=="string"?` in ${n.repository}`:typeof n.channel_id=="string"?` in ${h(n.channel_id,t)}`:typeof n.resource_ref=="string"?` for ${n.resource_ref}`:""}function $(e){return Array.isArray(e.triggers)?e.triggers.filter(t=>!!t&&typeof t=="object"):[]}function A(e,t,n){if(e.kind==="schedule"&&typeof e.cron=="string")return m(e.cron);if(e.kind==="event"&&e.source!=="workspace"&&typeof e.connector_key=="string"){const r=Array.isArray(e.event_types)?e.event_types.filter(u=>typeof u=="string"):[],o=r.length>0?r.join(" or "):"an event",i=typeof e.connection_id=="number"?n.get(e.connection_id):void 0;return`${_(e.connector_key,t)} sends ${o}${v(e.match,i)}`}if(e.kind==="event"&&e.source==="workspace"){const r=Array.isArray(e.event_types)?e.event_types.filter(u=>typeof u=="string"):[],o=r.length>0?r.join(" or "):"an event",i=typeof e.entity_type=="string"?` on ${k(e.entity_type)}`:"";return`another Automation writes ${o}${i}`}return null}function T(e){return e.health==="degraded"?"error":"enabled"}function w(e,t=new Map,n=new Map){const r=$(e),o=e.name?.trim()||"Untitled automation",i=r.some(s=>s.kind==="event"),u=r.some(s=>s.kind==="schedule"),p=i?"event":u?"schedule":"manual",c=r.map(s=>A(s,t,n)).filter(s=>!!s);let l="When started manually";c.length===1?l=`When ${c[0]}`:c.length>1&&(l=`When ${c[0]}${c.slice(1).map(s=>`, or when ${s}`).join("")}`);const y=r.some(s=>s.kind==="event"&&s.output==="reply_to_source")?"source":"silent";return{key:`automation:${e.automation_id}`,kind:p,when:l,does:o,output:{destination:y},state:T(e),sortTime:e.next_run_at?Date.parse(e.next_run_at):null,automation:e}}const a={event:0,schedule:1,manual:2};function S(e,t=new Map,n=new Map){return e.map(r=>w(r,t,n)).sort((r,o)=>r.state!==o.state?r.state==="enabled"?-1:1:a[r.kind]!==a[o.kind]?a[r.kind]-a[o.kind]:r.sortTime!==o.sortTime?r.sortTime===null?1:o.sortTime===null?-1:r.sortTime-o.sortTime:r.when.localeCompare(o.when)||r.key.localeCompare(o.key))}const j={kind:"all",output:"any",state:"any"};function E(e,t){return e.filter(n=>(t.kind==="all"||n.kind===t.kind)&&(t.output==="any"||(t.output==="reply"?n.output.destination==="source":n.output.destination==="silent"))&&(t.state==="any"||(t.state==="active"?n.state==="enabled":n.state==="error")))}function L(e){const t=Array.isArray(e.triggers)?e.triggers:[];for(const n of t)if(n&&typeof n=="object"&&n.kind==="event"&&n.source!=="workspace"&&typeof n.connector_key=="string")return n.connector_key;return null}export{j as D,w as d,L as e,E as f,S as m};
2
+ //# sourceMappingURL=model-udnQ_S43.js.map
@@ -0,0 +1,2 @@
1
+ import{iP as e,j as r}from"./index-008wj-Pz.js";import{a as m}from"./agents-workbench-CmGrMvPC.js";import"./agent-editor-form-QrIDroFL.js";import"./model-selector-3l9lY50C.js";import"./proposal-review-shell-CVkLnnKo.js";import"./runs-lG2ChtOt.js";function g(){const{owner:o,agentId:t}=e.useParams();return r.jsx(m,{owner:o,agentId:t,tab:"models"})}export{g as component};
2
+ //# sourceMappingURL=models-CQj7GIOp.js.map
@@ -0,0 +1,2 @@
1
+ import{v as S,ap as y,aD as k,ax as A,b8 as T,r as g,j as e,gs as L,L as p,gt as B,bi as R,S as b,h0 as w,av as $}from"./index-008wj-Pz.js";import{C as D,A as I}from"./create-automation-form-DHW6OUoS.js";import"./cronstrue-xxpD1P2-.js";import"./entity-options-DJv2EhVV.js";import"./connection-label-BobuYiAG.js";import"./use-automations-C4TSie1i.js";import"./model-selector-3l9lY50C.js";import"./skill-editor-D_W3QlRz.js";import"./code-editor-BFZa4EIt.js";import"./index-wHFQv1aT.js";import"./use-mention-search-PfZrNbu_.js";function O(n){return n.includes(":")?n.slice(n.indexOf(":")+1):n}function P({prefillAgentId:n,onCancel:t,initialTriggers:l,conversationSetup:x}){const{org:o}=y(),[c,h]=g.useState({ready:!1,triggers:[]}),[u,v]=g.useState(),a=g.useCallback(s=>{h(m=>JSON.stringify(m)===JSON.stringify(s)?m:s)},[]),r=u??l;return e.jsx(D,{startFromScratch:!!l,organizationId:o?.id??"",prefillAgentId:n,conversationSetup:x,onClose:t,onPrefillTriggers:s=>v(s.length>0?s:void 0),onSuccess:t,hideHeader:!0,hideCancel:!0,submitLabel:"Create Automation",submitDisabled:!c.ready,createFields:{triggers:c.triggers},triggerFields:e.jsx(I,{organizationId:o?.id??null,initialTriggers:r,onChange:a},JSON.stringify(r??"new"))})}function E({owner:n,prefilled:t}){const l=S(),{org:x}=y(),o=k(x?.id??null,{status:"active",limit:500}),c=A(x?.id??null),{data:h=[]}=T(),u=!!(t?.platform&&(t.listen||t.resource)),v=u&&(o.isLoading||c.isLoading),a=g.useMemo(()=>{if(!t?.platform||!t.listen&&!t.resource)return;const d=o.data??[],N=t.connection?d.find(i=>i.slug===t.connection):(()=>{const i=d.filter(f=>f.connector_key!==t.platform?!1:t.resource?!0:f.facets.chat&&(f.external_tenant_id??"")===(t.team??""));return i.length===1?i[0]:void 0})();if(t.connection&&!N)return;const j=t.events?.split(",").map(i=>i.trim()).filter(Boolean)??[];return[{kind:"event",source:"connector",connector_key:t.platform,...N?{connection_id:N.id}:{},event_types:j.length>0?j:t.listen?["message.created"]:[],match:t.resource?{resource_ref:t.resource,...t.resource_type?{resource_type:t.resource_type}:{}}:{channel_id:O(t.listen??"")},execution:"turn",active_run:t.listen?"steer":"queue",output:t.listen?"reply_to_source":"silent",skip_if_unchanged:!t.listen}]},[o.data,t]),r=c.data?.find(d=>d.key===t?.platform)?.name,s=t?.label??t?.listen,m=g.useMemo(()=>t?.listen&&a&&s?{name:r?`${r}: ${s}`:s}:void 0,[s,r,a,t?.listen]),C=()=>void l({to:"/$owner/automations",params:{owner:n}}),_=a?t?.resource?`React to changes on ${t.label??t.resource}.`:`React to messages in ${t?.label??t?.listen}.`:u&&!o.isLoading?"Choose the matching connection and event, then define the reaction.":"Start from a template, from scratch, or clone an existing Automation.";return e.jsx("div",{className:"flex flex-1 flex-col gap-6 px-4 pt-2.5 pb-8 lg:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full min-w-0 max-w-3xl flex-col gap-4",children:[e.jsx(L,{crumbs:[e.jsx(p,{to:"/$owner/automations",params:{owner:n},className:B,children:"Automations"},"automations")],current:"New automation"}),e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("h1",{className:"flex min-w-0 items-center gap-2 truncate font-display text-xl font-semibold",children:[e.jsx(R,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),"New automation"]})})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:_}),m&&!t?.agent?e.jsxs("p",{className:"text-sm text-muted-foreground",children:[h.length===0?"This workspace has no agents yet. ":"Choose the agent that answers here, or ",e.jsx(p,{to:"/$owner/agents/new",params:{owner:n},search:t,className:"underline underline-offset-4",children:h.length===0?"Create an agent":"create an agent"})," ","and come back to finish this setup."]}):null,v?e.jsxs("div",{className:"space-y-3",children:[e.jsx(b,{className:"h-10 w-full"}),e.jsx(b,{className:"h-32 w-full"})]}):u&&t?.connection&&!a?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"This connection is no longer available. Reopen setup from your conversation."}):e.jsx(P,{prefillAgentId:t?.agent,onCancel:C,initialTriggers:a,conversationSetup:m})]})})}function X(){const{owner:n}=w.useParams(),t=w.useSearch();return e.jsx($,{owner:n,children:()=>e.jsx(E,{owner:n,prefilled:t})})}export{X as component};
2
+ //# sourceMappingURL=new-BOwIHkre.js.map
@@ -1,2 +1,2 @@
1
- import{q as R,k as F,z as E,r,j as e,E as v,I as S,B as L,F as N,G as U}from"./index-JmEl29py.js";import{C as I,a as k,b as A,c as T}from"./card-Cspo-4M6.js";import{F as q}from"./full-page-spinner-DtmqQmgl.js";function c(l){return l.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function H(){const l=R(),{session:u,isReady:d}=F(),{slug:n,name:i}=E.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(q,{});const P=a=>{const s=U(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(I,{children:[e.jsx(k,{children:e.jsx(A,{children:"Create organization"})}),e.jsx(T,{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-ChwqLmVY.js.map
1
+ import{v as z,o as F,G as L,r,j as e,H as w,I as S,B as U,J as N,K as E}from"./index-008wj-Pz.js";import{C as I,a as A,b as T,c as k}from"./card-BCsbrdGs.js";import{F as B}from"./full-page-spinner-C1Q_jEzD.js";function c(l){return l.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function q(){const l=z(),{session:u,isReady:d}=F(),{slug:n,name:i}=L.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})},R=async a=>{a.preventDefault(),o(null);const s=m.trim(),v=(g.trim()||c(s)).trim();if(!s){o("Name is required");return}if(!v){o("Slug is required");return}p(!0);try{const t=await N.create({name:s,slug:v});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(I,{children:[e.jsx(A,{children:e.jsx(T,{children:"Create organization"})}),e.jsx(k,{children:e.jsxs("form",{onSubmit:R,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(w,{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(w,{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(U,{type:"submit",disabled:f,children:f?"Creating…":"Create organization"})})]})})]})})}export{q as component};
2
+ //# sourceMappingURL=new-BbdwuJPm.js.map
@@ -0,0 +1,2 @@
1
+ import{hg as o,v as p,a2 as x,o as h,ap as b,b8 as f,j as a,aG as w,gr as A,b0 as L,gs as j,L as C,gt as S,fn as N,a$ as k,bY as y}from"./index-008wj-Pz.js";import{A as E}from"./agent-editor-form-QrIDroFL.js";import"./model-selector-3l9lY50C.js";const v="flex min-h-0 flex-1 flex-col gap-3 px-4 pt-2.5 pb-8 lg:px-6";function _(){const{owner:e}=o.useParams(),t=o.useSearch(),r=p(),i=x(),{isAuthenticated:c}=h(),{isMember:g,isLoading:m}=b(),n=c&&g,{data:u=[],isLoading:d}=f({enabled:n});return a.jsx("div",{className:v,children:a.jsxs(w,{className:"flex flex-1 flex-col gap-6",children:[a.jsx(A,{breadcrumb:a.jsx(j,{crumbs:[a.jsx(C,{to:"/$owner/agents",params:{owner:e},className:S,children:"Agents"},"agents")]}),icon:a.jsx(L.agents.icon,{className:"h-6 w-6"}),title:"Build a managed agent",caption:"Create an agent that Lobu runs and manages for this workspace."}),m||n&&d?a.jsx(N,{rows:1}):n?a.jsx(E,{mode:{kind:"create"},existingAgentIds:u.map(s=>s.agentId),onCreated:async s=>{const l=["agents",e];if(await i.refetchQueries({queryKey:l,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/settings",params:{owner:e,agentId:s},search:{run_id:void 0}})}}):a.jsx(k,{icon:y,title:"Workspace membership required",description:"Only workspace members can build managed agents."})]})})}export{_ as component};
2
+ //# sourceMappingURL=new-DTuFCQhV.js.map
@@ -1,2 +1,2 @@
1
- import{j as e,Q as y,T as $,U as E,B as R,r as u,V as z}from"./index-JmEl29py.js";const W=["mcp:read","mcp:write","mcp:admin"],F=[{value:"read",title:"Read only",description:"Search and view authorized workspace data."},{value:"write",title:"Read and make changes",description:"Includes read access. Create and update authorized workspace data."},{value:"admin",title:"Administer workspaces",description:"Includes read and write access. Manage administrator-only settings.",risk:"high"}],S={read:0,write:1,admin:2};function I(s){return s.includes("mcp:admin")?"admin":s.includes("mcp:write")?"write":s.includes("mcp:read")?"read":null}function D(s,a){const r=s.filter(x=>!W.includes(x));if(!a)return r;const i=I(s);return!i||S[a]>S[i]?r:["mcp:read",...a==="write"||a==="admin"?["mcp:write"]:[],...a==="admin"?["mcp:admin"]:[],...r]}function H({idPrefix:s,clientName:a,requestedScopes:r,accessLevel:i,onAccessLevelChange:x,sensitiveScopesAcknowledged:v=!1,onSensitiveScopesAcknowledgedChange:g,disabled:b=!1}){const k=I(r),f=r.includes("profile:read"),p=r.includes("device_worker:run"),o=r.includes("connections:token"),j=p||o,c=r.filter(n=>!W.includes(n)&&n!=="profile:read"&&n!=="device_worker:run"&&n!=="connections:token");return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{"aria-labelledby":`${s}-application`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-application`,className:"text-sm font-medium",children:"Application"}),e.jsx("div",{className:"rounded-lg border p-4",children:e.jsx("span",{className:"text-sm font-semibold text-foreground",children:a||"Unnamed application"})})]}),k&&e.jsxs("fieldset",{className:"space-y-2",disabled:b,children:[e.jsx("legend",{className:"text-sm font-medium",children:"Access level"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose the maximum access this application should receive."}),e.jsx("div",{className:"space-y-2",children:F.filter(n=>S[n.value]<=S[k]).map(n=>{const l=`${s}-access-${n.value}`,h=i===n.value;return e.jsxs("label",{htmlFor:l,className:$("flex cursor-pointer items-start gap-3 rounded-md border p-3 transition-colors",h&&"border-primary bg-primary/5"),children:[e.jsx("input",{id:l,type:"radio",name:`${s}-access-level`,value:n.value,checked:h,onChange:()=>x(n.value),className:"mt-1 h-4 w-4 accent-primary"}),e.jsxs("span",{className:"min-w-0 space-y-0.5",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[n.title,n.risk==="high"&&e.jsx(y,{variant:"destructive",children:"High risk"})]}),e.jsx("span",{className:"block text-sm text-muted-foreground",children:n.description})]})]},n.value)})})]}),f&&e.jsxs("section",{"aria-labelledby":`${s}-profile`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-profile`,className:"text-sm font-medium",children:"Account information"}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:["Basic profile",e.jsx(y,{variant:"secondary",children:"Included"})]}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:"See your basic Lobu identity and the names and slugs of workspaces you belong to."})]})]}),c.length>0&&e.jsxs("section",{"aria-labelledby":`${s}-additional`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-additional`,className:"text-sm font-medium",children:"Additional permissions"}),e.jsx("ul",{className:"space-y-2",children:c.map(n=>e.jsx("li",{className:"rounded-md border p-3 font-mono text-xs text-foreground",children:n},n))})]}),j&&e.jsxs("section",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Device capabilities"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"These capabilities are fixed by the device request and cannot be reduced here."})]}),e.jsxs("ul",{className:"space-y-2",children:[p&&e.jsxs("li",{className:"rounded-md bg-background/70 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Operate this device"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run jobs and Automations through capabilities advertised by this device."})]}),o&&e.jsxs("li",{className:"rounded-md bg-background/70 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Use connected services"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Request short-lived access for services you connected to Lobu."})]})]}),e.jsxs("div",{className:"flex items-start gap-3 rounded-md border bg-background p-3",children:[e.jsx(E,{id:`${s}-sensitive-acknowledgement`,checked:v,disabled:b,onCheckedChange:n=>g?.(n===!0),className:"mt-0.5"}),e.jsx("label",{htmlFor:`${s}-sensitive-acknowledgement`,className:"cursor-pointer text-sm font-medium text-foreground",children:"I initiated this request and confirmed that the device code matches."})]})]})]})}function T({idPrefix:s,orgList:a,selectedOrgIds:r,onWorkspaceAccessChange:i,onSelectedOrgChange:x,orgsLoading:v,orgsError:g,onRetry:b,disabled:k=!1,deviceHomeOrgId:f=null,allowMultiple:p}){const o=`${s}-workspace-access-legend`,j=r.length===a.length;return v?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsx("p",{role:"status","aria-live":"polite",className:"text-sm text-muted-foreground",children:"Loading your workspaces..."})]}):g?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsxs("div",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:[e.jsx("p",{children:"Workspaces could not be loaded. Approval is unavailable until they load."}),e.jsx(R,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:b,children:"Retry"})]})]}):a.length===0?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:"No member workspaces are available for this connection."})]}):e.jsxs("fieldset",{className:"space-y-3",disabled:k,children:[e.jsx("legend",{id:o,className:"sr-only",children:"Workspace access"}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Workspaces"}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:p?"Choose where this application can operate.":"Choose one workspace this application can access."})]}),p&&!j&&e.jsxs(R,{type:"button",variant:"outline",size:"sm",onClick:()=>i("all_current"),children:["Select all ",a.length]})]}),f&&e.jsx("p",{className:"text-sm text-muted-foreground",children:p?"The device workspace is always included. Additional workspaces grant MCP access only.":"MCP access follows the device workspace."}),e.jsx("div",{className:"space-y-2",children:a.map(c=>{const n=`${s}-workspace-${c.id}`,l=c.id===f,h=r.includes(c.id);return e.jsxs("div",{className:$("flex items-start gap-3 rounded-md border p-3 transition-colors",h&&"border-primary/40 bg-primary/5"),children:[e.jsx(E,{id:n,checked:h,disabled:k||l||f!==null&&!p,onCheckedChange:N=>x(c.id,N===!0),className:"mt-0.5"}),e.jsxs("label",{htmlFor:n,className:"min-w-0 flex-1 cursor-pointer space-y-0.5",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[c.name,c.isPersonal&&e.jsx(y,{variant:"outline",children:"Personal"}),l&&e.jsx(y,{variant:"secondary",children:"Device workspace"})]}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:c.slug})]})]},c.id)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[e.jsxs("p",{"aria-live":"polite",children:[r.length," of ",a.length," workspaces selected."]}),j&&e.jsx(y,{variant:"secondary",children:"All currently available"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Workspaces you join later are not added automatically."}),r.length===0&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Choose at least one workspace."})]})}function V(s,a){u.useEffect(()=>{if(a||s)return;const r=new URL("/auth/login",window.location.origin);r.searchParams.set("callbackUrl",window.location.href),window.location.href=r.toString()},[s,a])}function P(s,a){return s.length===a.length&&s.every((r,i)=>r===a[i])}function q(s={}){const{requireDeviceHome:a=!1,deviceHomeOrgId:r=null,allowMultiple:i=!0}=s,{data:x,error:v,isPending:g,refetch:b}=z(),[k,f]=u.useState("selected"),[p,o]=u.useState([]),j=u.useRef(!1),c=u.useMemo(()=>x?x.filter(t=>t.is_member).map(t=>({id:t.id,name:t.name,slug:t.slug,isPersonal:t.is_personal===!0})):[],[x]),n=c.find(t=>t.isPersonal)?.id??null,l=a?r&&c.some(t=>t.id===r)?r:n:null,h=u.useRef(c);h.current=c;const N=v instanceof Error?v.message:v?"Unable to load workspaces":null;u.useEffect(()=>{if(g||N)return;const t=c.map(d=>d.id),m=new Set(t);o(d=>{const C=j.current?d.filter(A=>m.has(A)):[n??t[0]].filter(A=>!!A);return j.current=!0,P(d,C)?d:C})},[c,N,g,n]);const L=u.useCallback(t=>{if(t==="all_current"){if(!i)return;o(h.current.map(m=>m.id))}f(t)},[i]),M=u.useCallback((t,m)=>{h.current.some(d=>d.id===t)&&(a&&(t===l||!i)||(f("selected"),o(d=>m?i?d.includes(t)?d:[...d,t]:[t]:d.filter(C=>C!==t))))},[i,l,a]),w=u.useMemo(()=>{if(a&&l&&!i)return[l];const t=new Set(p);return a&&l&&t.add(l),c.filter(m=>t.has(m.id)).map(m=>m.id)},[i,p,l,c,a]),_=u.useCallback(()=>{const t=h.current,m=t.find(d=>d.isPersonal)?.id??t[0]?.id;j.current=t.length>0,f("selected"),o(m?[m]:[])},[]),O=!g&&!N&&c.length>0&&w.length>0&&(i||w.length===1)&&(!a||l!==null&&w.includes(l)),U=u.useCallback(()=>{b()},[b]);return{orgList:c,workspaceAccess:k,setWorkspaceAccess:L,selectedOrgIds:w,toggleSelectedOrgId:M,resetWorkspaceSelection:_,personalOrgId:n,deviceHomeOrgId:l,orgsLoading:g,orgsError:N,retryOrgs:U,workspaceSelectionReady:O}}function K(s){if(!s)return null;try{return new URL(s).pathname.match(/^\/mcp\/([^/]+)$/)?.[1]?.trim()||null}catch{return null}}export{H as A,T as W,I as a,V as b,K as g,D as s,q as u};
2
- //# sourceMappingURL=oauth-workspace-access-D15LYKSe.js.map
1
+ import{j as e,V as y,h as W,W as $,B as R,r as u,Y as U}from"./index-008wj-Pz.js";const E=["mcp:read","mcp:write","mcp:admin"],F=[{value:"read",title:"Read only",description:"Search and view authorized workspace data."},{value:"write",title:"Read and make changes",description:"Includes read access. Create and update authorized workspace data."},{value:"admin",title:"Administer workspaces",description:"Includes read and write access. Manage administrator-only settings.",risk:"high"}],S={read:0,write:1,admin:2};function I(s){return s.includes("mcp:admin")?"admin":s.includes("mcp:write")?"write":s.includes("mcp:read")?"read":null}function D(s,a){const r=s.filter(x=>!E.includes(x));if(!a)return r;const i=I(s);return!i||S[a]>S[i]?r:["mcp:read",...a==="write"||a==="admin"?["mcp:write"]:[],...a==="admin"?["mcp:admin"]:[],...r]}function H({idPrefix:s,clientName:a,requestedScopes:r,accessLevel:i,onAccessLevelChange:x,sensitiveScopesAcknowledged:v=!1,onSensitiveScopesAcknowledgedChange:g,disabled:b=!1}){const k=I(r),f=r.includes("profile:read"),p=r.includes("device_worker:run"),o=r.includes("connections:token"),j=p||o,c=r.filter(n=>!E.includes(n)&&n!=="profile:read"&&n!=="device_worker:run"&&n!=="connections:token");return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{"aria-labelledby":`${s}-application`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-application`,className:"text-sm font-medium",children:"Application"}),e.jsx("div",{className:"rounded-lg border p-4",children:e.jsx("span",{className:"text-sm font-semibold text-foreground",children:a||"Unnamed application"})})]}),k&&e.jsxs("fieldset",{className:"space-y-2",disabled:b,children:[e.jsx("legend",{className:"text-sm font-medium",children:"Access level"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose the maximum access this application should receive."}),e.jsx("div",{className:"space-y-2",children:F.filter(n=>S[n.value]<=S[k]).map(n=>{const l=`${s}-access-${n.value}`,h=i===n.value;return e.jsxs("label",{htmlFor:l,className:W("flex cursor-pointer items-start gap-3 rounded-md border p-3 transition-colors",h&&"border-primary bg-primary/5"),children:[e.jsx("input",{id:l,type:"radio",name:`${s}-access-level`,value:n.value,checked:h,onChange:()=>x(n.value),className:"mt-1 h-4 w-4 accent-primary"}),e.jsxs("span",{className:"min-w-0 space-y-0.5",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[n.title,n.risk==="high"&&e.jsx(y,{variant:"destructive",children:"High risk"})]}),e.jsx("span",{className:"block text-sm text-muted-foreground",children:n.description})]})]},n.value)})})]}),f&&e.jsxs("section",{"aria-labelledby":`${s}-profile`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-profile`,className:"text-sm font-medium",children:"Account information"}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:["Basic profile",e.jsx(y,{variant:"secondary",children:"Included"})]}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:"See your basic Lobu identity and the names and slugs of workspaces you belong to."})]})]}),c.length>0&&e.jsxs("section",{"aria-labelledby":`${s}-additional`,className:"space-y-2",children:[e.jsx("p",{id:`${s}-additional`,className:"text-sm font-medium",children:"Additional permissions"}),e.jsx("ul",{className:"space-y-2",children:c.map(n=>e.jsx("li",{className:"rounded-md border p-3 font-mono text-xs text-foreground",children:n},n))})]}),j&&e.jsxs("section",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Device capabilities"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"These capabilities are fixed by the device request and cannot be reduced here."})]}),e.jsxs("ul",{className:"space-y-2",children:[p&&e.jsxs("li",{className:"rounded-md bg-background/70 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Operate this device"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run jobs and Automations through capabilities advertised by this device."})]}),o&&e.jsxs("li",{className:"rounded-md bg-background/70 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Use connected services"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Request short-lived access for services you connected to Lobu."})]})]}),e.jsxs("div",{className:"flex items-start gap-3 rounded-md border bg-background p-3",children:[e.jsx($,{id:`${s}-sensitive-acknowledgement`,checked:v,disabled:b,onCheckedChange:n=>g?.(n===!0),className:"mt-0.5"}),e.jsx("label",{htmlFor:`${s}-sensitive-acknowledgement`,className:"cursor-pointer text-sm font-medium text-foreground",children:"I initiated this request and confirmed that the device code matches."})]})]})]})}function V({idPrefix:s,orgList:a,selectedOrgIds:r,onWorkspaceAccessChange:i,onSelectedOrgChange:x,orgsLoading:v,orgsError:g,onRetry:b,disabled:k=!1,deviceHomeOrgId:f=null,allowMultiple:p}){const o=`${s}-workspace-access-legend`,j=r.length===a.length;return v?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsx("p",{role:"status","aria-live":"polite",className:"text-sm text-muted-foreground",children:"Loading your workspaces..."})]}):g?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsxs("div",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:[e.jsx("p",{children:"Workspaces could not be loaded. Approval is unavailable until they load."}),e.jsx(R,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:b,children:"Retry"})]})]}):a.length===0?e.jsxs("section",{"aria-labelledby":o,className:"space-y-2",children:[e.jsx("p",{id:o,className:"text-sm font-medium",children:"Workspace access"}),e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:"No member workspaces are available for this connection."})]}):e.jsxs("fieldset",{className:"space-y-3",disabled:k,children:[e.jsx("legend",{id:o,className:"sr-only",children:"Workspace access"}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Workspaces"}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:p?"Choose where this application can operate.":"Choose one workspace this application can access."})]}),p&&!j&&e.jsxs(R,{type:"button",variant:"outline",size:"sm",onClick:()=>i("all_current"),children:["Select all ",a.length]})]}),f&&e.jsx("p",{className:"text-sm text-muted-foreground",children:p?"The device workspace is always included. Additional workspaces grant MCP access only.":"MCP access follows the device workspace."}),e.jsx("div",{className:"space-y-2",children:a.map(c=>{const n=`${s}-workspace-${c.id}`,l=c.id===f,h=r.includes(c.id);return e.jsxs("div",{className:W("flex items-start gap-3 rounded-md border p-3 transition-colors",h&&"border-primary/40 bg-primary/5"),children:[e.jsx($,{id:n,checked:h,disabled:k||l||f!==null&&!p,onCheckedChange:N=>x(c.id,N===!0),className:"mt-0.5"}),e.jsxs("label",{htmlFor:n,className:"min-w-0 flex-1 cursor-pointer space-y-0.5",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[c.name,c.isPersonal&&e.jsx(y,{variant:"outline",children:"Personal"}),l&&e.jsx(y,{variant:"secondary",children:"Device workspace"})]}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:c.slug})]})]},c.id)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[e.jsxs("p",{"aria-live":"polite",children:[r.length," of ",a.length," workspaces selected."]}),j&&e.jsx(y,{variant:"secondary",children:"All currently available"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Workspaces you join later are not added automatically."}),r.length===0&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Choose at least one workspace."})]})}function q(s,a){u.useEffect(()=>{if(a||s)return;const r=new URL("/auth/login",window.location.origin);r.searchParams.set("callbackUrl",window.location.href),window.location.href=r.toString()},[s,a])}function P(s,a){return s.length===a.length&&s.every((r,i)=>r===a[i])}function T(s={}){const{requireDeviceHome:a=!1,deviceHomeOrgId:r=null,allowMultiple:i=!0}=s,{data:x,error:v,isPending:g,refetch:b}=U(),[k,f]=u.useState("selected"),[p,o]=u.useState([]),j=u.useRef(!1),c=u.useMemo(()=>x?x.filter(t=>t.is_member).map(t=>({id:t.id,name:t.name,slug:t.slug,isPersonal:t.is_personal===!0})):[],[x]),n=c.find(t=>t.isPersonal)?.id??null,l=a?r&&c.some(t=>t.id===r)?r:n:null,h=u.useRef(c);h.current=c;const N=v instanceof Error?v.message:v?"Unable to load workspaces":null;u.useEffect(()=>{if(g||N)return;const t=c.map(d=>d.id),m=new Set(t);o(d=>{const C=j.current?d.filter(A=>m.has(A)):[n??t[0]].filter(A=>!!A);return j.current=!0,P(d,C)?d:C})},[c,N,g,n]);const L=u.useCallback(t=>{if(t==="all_current"){if(!i)return;o(h.current.map(m=>m.id))}f(t)},[i]),M=u.useCallback((t,m)=>{h.current.some(d=>d.id===t)&&(a&&(t===l||!i)||(f("selected"),o(d=>m?i?d.includes(t)?d:[...d,t]:[t]:d.filter(C=>C!==t))))},[i,l,a]),w=u.useMemo(()=>{if(a&&l&&!i)return[l];const t=new Set(p);return a&&l&&t.add(l),c.filter(m=>t.has(m.id)).map(m=>m.id)},[i,p,l,c,a]),_=u.useCallback(()=>{const t=h.current,m=t.find(d=>d.isPersonal)?.id??t[0]?.id;j.current=t.length>0,f("selected"),o(m?[m]:[])},[]),O=!g&&!N&&c.length>0&&w.length>0&&(i||w.length===1)&&(!a||l!==null&&w.includes(l)),z=u.useCallback(()=>{b()},[b]);return{orgList:c,workspaceAccess:k,setWorkspaceAccess:L,selectedOrgIds:w,toggleSelectedOrgId:M,resetWorkspaceSelection:_,personalOrgId:n,deviceHomeOrgId:l,orgsLoading:g,orgsError:N,retryOrgs:z,workspaceSelectionReady:O}}function K(s){if(!s)return null;try{return new URL(s).pathname.match(/^\/mcp\/([^/]+)$/)?.[1]?.trim()||null}catch{return null}}export{H as A,V as W,I as a,q as b,K as g,D as s,T as u};
2
+ //# sourceMappingURL=oauth-workspace-access-QPo4YwRX.js.map