@lobu/runtime-server 24.3.0 → 24.4.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 (211) hide show
  1. package/dist/catalogs/skills.json +1 -1
  2. package/dist/component.json +1 -1
  3. package/dist/db/migrations/20261101010000_public_source_type_references.sql +157 -0
  4. package/dist/dependencies.bun.lock +59 -57
  5. package/dist/owletto/dist/assets/_-DIK0ae_S.js +2 -0
  6. package/dist/owletto/dist/assets/_-gTbcArpS.js +3 -0
  7. package/dist/owletto/dist/assets/_agentId-DOmcJZfk.js +2 -0
  8. package/dist/owletto/dist/assets/_agentId-DW6wRCVC.js +2 -0
  9. package/dist/owletto/dist/assets/{_automationId-CfFFAYK1.js → _automationId-B9IcDYBu.js} +2 -2
  10. package/dist/owletto/dist/assets/_connectorKey._connectionId-C6PmMPTA.js +2 -0
  11. package/dist/owletto/dist/assets/_connectorKey.index-BrJ8Pzze.js +2 -0
  12. package/dist/owletto/dist/assets/{_conversationId-D3vuAQPe.js → _conversationId-BpJAeYYW.js} +2 -2
  13. package/dist/owletto/dist/assets/_eventId-DarQJo0G.js +2 -0
  14. package/dist/owletto/dist/assets/_name-DtmNTcUm.js +2 -0
  15. package/dist/owletto/dist/assets/{_owner-oBX68rb9.js → _owner-Db8at3hk.js} +3 -3
  16. package/dist/owletto/dist/assets/_shape-6iFA8A86.js +2 -0
  17. package/dist/owletto/dist/assets/_skillKey-CXkHn3Nl.js +2 -0
  18. package/dist/owletto/dist/assets/{_slug-B2g5qzn3.js → _slug-DBOuBLoX.js} +2 -2
  19. package/dist/owletto/dist/assets/_viewKey-DC27aIN9.js +2 -0
  20. package/dist/owletto/dist/assets/_viewKey-DuYDieln.js +2 -0
  21. package/dist/owletto/dist/assets/{accept-invitation-38lHBvjO.js → accept-invitation-BbDCVvur.js} +2 -2
  22. package/dist/owletto/dist/assets/activity-route-view-V4ftmSN7.js +2 -0
  23. package/dist/owletto/dist/assets/{agent-card-controls-DiU7Un5w.js → agent-card-controls-99mG6H5k.js} +2 -2
  24. package/dist/owletto/dist/assets/agent-client-setup-list-kMmqQSrf.js +4 -0
  25. package/dist/owletto/dist/assets/agent-connect-pages-B-NPTFs6.js +2 -0
  26. package/dist/owletto/dist/assets/{agent-editor-form-QrIDroFL.js → agent-editor-form-DfMTSIvj.js} +2 -2
  27. package/dist/owletto/dist/assets/{agent-guardrails-route-CyoGSxcZ.js → agent-guardrails-route-BvGgfd-h.js} +2 -2
  28. package/dist/owletto/dist/assets/{agent-loading-shells-CamDtzHY.js → agent-loading-shells-Dnmb6W5Y.js} +2 -2
  29. package/dist/owletto/dist/assets/{agent-permissions-matrix-CgsQ8BK_.js → agent-permissions-matrix-CbhXlbgY.js} +2 -2
  30. package/dist/owletto/dist/assets/{agent-skill-context-lWbXKEm1.js → agent-skill-context-V__2i6Vl.js} +2 -2
  31. package/dist/owletto/dist/assets/{agent-skills-route-D-w3tY_2.js → agent-skills-route-DFXr_bHp.js} +2 -2
  32. package/dist/owletto/dist/assets/{agent-subpage-shell-CLqpn5Tb.js → agent-subpage-shell-DWzljvFb.js} +2 -2
  33. package/dist/owletto/dist/assets/{agent-thread-CsRexwTv.js → agent-thread-DQIr20H-.js} +4 -4
  34. package/dist/owletto/dist/assets/agents-CLbeiqTR.js +2 -0
  35. package/dist/owletto/dist/assets/{agents-workbench-CmGrMvPC.js → agents-workbench-C8bTa2rv.js} +2 -2
  36. package/dist/owletto/dist/assets/{app._appId-BO7G38fL.js → app._appId-Bsq40nak.js} +2 -2
  37. package/dist/owletto/dist/assets/{automation-detail-content-DMYxs6F6.js → automation-detail-content-C9Cgr5Zj.js} +2 -2
  38. package/dist/owletto/dist/assets/automations-CLbeiqTR.js +2 -0
  39. package/dist/owletto/dist/assets/{calendar-DDCCSPW6.js → calendar-DMq3Dtqy.js} +2 -2
  40. package/dist/owletto/dist/assets/{callback-DFciMR8u.js → callback-B-CAz-bK.js} +2 -2
  41. package/dist/owletto/dist/assets/{card-BCsbrdGs.js → card-SFtxv9f2.js} +2 -2
  42. package/dist/owletto/dist/assets/{claim-BRua2b_7.js → claim-DrxIRWKt.js} +2 -2
  43. package/dist/owletto/dist/assets/client-activity-scopes-boZOHuPW.js +2 -0
  44. package/dist/owletto/dist/assets/{client-rows-DiJQ5D1z.js → client-rows-BJ2PxM4J.js} +2 -2
  45. package/dist/owletto/dist/assets/clients-C7Lnuc3S.js +2 -0
  46. package/dist/owletto/dist/assets/{code-editor-BFZa4EIt.js → code-editor-rX0t1g5C.js} +2 -2
  47. package/dist/owletto/dist/assets/connect-BcwgytDV.js +2 -0
  48. package/dist/owletto/dist/assets/{connect-menu-D2K4tmvW.js → connect-menu-BF-AlunU.js} +2 -2
  49. package/dist/owletto/dist/assets/connect._clientId-sDypRDeN.js +2 -0
  50. package/dist/owletto/dist/assets/connected._clientId-C9OkW1tv.js +2 -0
  51. package/dist/owletto/dist/assets/connected._clientId.activity-Dc6HYr55.js +2 -0
  52. package/dist/owletto/dist/assets/{connected._clientId.index-BTI5JXA3.js → connected._clientId.index-C6qbqgwF.js} +2 -2
  53. package/dist/owletto/dist/assets/connection-88YzIBK9.js +2 -0
  54. package/dist/owletto/dist/assets/connection-feed-detail-D7pnWaFB.js +2 -0
  55. package/dist/owletto/dist/assets/{connections-browser-BMV8bf54.js → connections-browser-DDJQh8Na.js} +2 -2
  56. package/dist/owletto/dist/assets/{connector-boxes-DqZA-FdG.js → connector-boxes-DDX7Ebc4.js} +2 -2
  57. package/dist/owletto/dist/assets/connector-provenance-Th8ymGec.js +2 -0
  58. package/dist/owletto/dist/assets/{connector-scope-lists-CJYz53YF.js → connector-scope-lists-BibdzKl1.js} +2 -2
  59. package/dist/owletto/dist/assets/{connectors-BroKpwhB.js → connectors-BqwgLUUK.js} +2 -2
  60. package/dist/owletto/dist/assets/consent-BR5U7dwb.js +2 -0
  61. package/dist/owletto/dist/assets/copy-button-2swYh4jb.js +2 -0
  62. package/dist/owletto/dist/assets/{core.esm-A1UnFbGs.js → core.esm-CHnfRiEM.js} +2 -2
  63. package/dist/owletto/dist/assets/{create-c94SPL21.js → create-BsPVnRpG.js} +2 -2
  64. package/dist/owletto/dist/assets/create-CVPYVOR5.js +2 -0
  65. package/dist/owletto/dist/assets/create-QFjmhOEU.js +2 -0
  66. package/dist/owletto/dist/assets/{create-automation-form-DHW6OUoS.js → create-automation-form-DmCOFbRT.js} +3 -3
  67. package/dist/owletto/dist/assets/create._connectorKey-DLDDVtLS.js +2 -0
  68. package/dist/owletto/dist/assets/{cronstrue-xxpD1P2-.js → cronstrue-CKwjNYgj.js} +2 -2
  69. package/dist/owletto/dist/assets/device-CKup7kvB.js +2 -0
  70. package/dist/owletto/dist/assets/{device-pin-tombstone-B_te59GE.js → device-pin-tombstone-xGhCTU5_.js} +2 -2
  71. package/dist/owletto/dist/assets/{device._deviceId-ZU09qrot.js → device._deviceId-B1H_ivDT.js} +2 -2
  72. package/dist/owletto/dist/assets/{entity-avatar-CEV4ttUQ.js → entity-avatar-HloBoalJ.js} +2 -2
  73. package/dist/owletto/dist/assets/{entity-options-DJv2EhVV.js → entity-options-BSW_EG0W.js} +2 -2
  74. package/dist/owletto/dist/assets/entity-page-D-WDWrAe.js +2 -0
  75. package/dist/owletto/dist/assets/entity-type-page-BCBdFndu.js +2 -0
  76. package/dist/owletto/dist/assets/{event-card-CBlsG32u.js → event-card-Mcxv56DG.js} +2 -2
  77. package/dist/owletto/dist/assets/event-detail-DXifj49J.js +2 -0
  78. package/dist/owletto/dist/assets/{events-feed-VfU4csn2.js → events-feed-BysC9HgU.js} +2 -2
  79. package/dist/owletto/dist/assets/{filter-bar-COU0sBFQ.js → filter-bar-BQm-ubB1.js} +2 -2
  80. package/dist/owletto/dist/assets/{full-page-spinner-C1Q_jEzD.js → full-page-spinner-BMiXl54z.js} +2 -2
  81. package/dist/owletto/dist/assets/guardrails-D7W80sJO.js +2 -0
  82. package/dist/owletto/dist/assets/identity-N0cAO9BR.js +2 -0
  83. package/dist/owletto/dist/assets/{index-008wj-Pz.js → index-4gCDI7m4.js} +1601 -1601
  84. package/dist/owletto/dist/assets/{index-DQxzeM37.js → index-B4wXJwQY.js} +2 -2
  85. package/dist/owletto/dist/assets/{index-BrDP4PCs.js → index-BNaI5GpS.js} +2 -2
  86. package/dist/owletto/dist/assets/index-BUUrHuJJ.js +2 -0
  87. package/dist/owletto/dist/assets/index-BqrvJmLh.js +2 -0
  88. package/dist/owletto/dist/assets/{index-DNtYqkiA.js → index-C-WaHj1Y.js} +2 -2
  89. package/dist/owletto/dist/assets/index-CnvQEA5V.js +2 -0
  90. package/dist/owletto/dist/assets/index-Cq7P2c_E.js +2 -0
  91. package/dist/owletto/dist/assets/{index-DFyBbp7b.js → index-CzoK57xp.js} +2 -2
  92. package/dist/owletto/dist/assets/index-D3omC3Us.js +2 -0
  93. package/dist/owletto/dist/assets/{index-yIub2xUM.js → index-D4-uel59.js} +2 -2
  94. package/dist/owletto/dist/assets/index-DDGdlQrt.css +1 -0
  95. package/dist/owletto/dist/assets/index-DFEW7hMg.js +2 -0
  96. package/dist/owletto/dist/assets/index-DVV-WWuT.js +2 -0
  97. package/dist/owletto/dist/assets/{index-CAVcR9za.js → index-DduQ_e9q.js} +2 -2
  98. package/dist/owletto/dist/assets/index-DutlI1d-.js +2 -0
  99. package/dist/owletto/dist/assets/{json-diff-LE_vNZrM.js → json-diff-E5D-NGYT.js} +2 -2
  100. package/dist/owletto/dist/assets/{list-skeleton-Kzxi2OXB.js → list-skeleton-Bp4HNgJ9.js} +2 -2
  101. package/dist/owletto/dist/assets/login-7F48UJGx.js +2 -0
  102. package/dist/owletto/dist/assets/{logout-Dt_VDilG.js → logout-DxmfsVKD.js} +2 -2
  103. package/dist/owletto/dist/assets/{member-scope-gate-De75CR7W.js → member-scope-gate-vp3FihBD.js} +2 -2
  104. package/dist/owletto/dist/assets/memory-browse-page-CfDmjhDl.js +74 -0
  105. package/dist/owletto/dist/assets/{model-udnQ_S43.js → model-Dn40BUzs.js} +2 -2
  106. package/dist/owletto/dist/assets/{model-selector-3l9lY50C.js → model-selector-88PJnyTq.js} +2 -2
  107. package/dist/owletto/dist/assets/models-BBK_n2RP.js +2 -0
  108. package/dist/owletto/dist/assets/{new-BOwIHkre.js → new-4ruWHLR5.js} +2 -2
  109. package/dist/owletto/dist/assets/{new-BbdwuJPm.js → new-CvX8_gIb.js} +2 -2
  110. package/dist/owletto/dist/assets/new-gMD1PHTL.js +2 -0
  111. package/dist/owletto/dist/assets/oauth-workspace-access-D9BNmyMY.js +2 -0
  112. package/dist/owletto/dist/assets/organization-BHcp5Pzg.js +2 -0
  113. package/dist/owletto/dist/assets/peek-pane-content-0sa10jER.js +2 -0
  114. package/dist/owletto/dist/assets/{permissions-CfoY4WFY.js → permissions-hhxosugv.js} +2 -2
  115. package/dist/owletto/dist/assets/proposal-review-shell-B4CSiyLB.js +2 -0
  116. package/dist/owletto/dist/assets/public-shell-ready-CsenJeXa.js +2 -0
  117. package/dist/owletto/dist/assets/record-activity-D7bRaMk2.js +2 -0
  118. package/dist/owletto/dist/assets/{record-session-D07szzqN.js → record-session-CWXnCVln.js} +2 -2
  119. package/dist/owletto/dist/assets/{renderer-AJxSmE3-.js → renderer-7EGgTVX0.js} +2 -2
  120. package/dist/owletto/dist/assets/reset-password-CFUzxH7m.js +2 -0
  121. package/dist/owletto/dist/assets/runs-BPtQBTRN.js +2 -0
  122. package/dist/owletto/dist/assets/{runs-panel-LnGpHCAQ.js → runs-panel-Bj63_hb9.js} +2 -2
  123. package/dist/owletto/dist/assets/{schema-type-editor-panel-C_Es0qDf.js → schema-type-editor-panel-CAhOB648.js} +2 -2
  124. package/dist/owletto/dist/assets/{settings-gGYXbFfd.js → settings-Dg6nxKyw.js} +2 -2
  125. package/dist/owletto/dist/assets/settings-KJJ6WihO.js +2 -0
  126. package/dist/owletto/dist/assets/skills-ayt06_o2.js +2 -0
  127. package/dist/owletto/dist/assets/{source-record-panels-CjFPgKKJ.js → source-record-panels-Bh5F4C5K.js} +2 -2
  128. package/dist/owletto/dist/assets/{status-dot-CSBtKT4g.js → status-dot-D3FoDRcc.js} +2 -2
  129. package/dist/owletto/dist/assets/{table-DHM-vCxP.js → table-DFcJRNk7.js} +2 -2
  130. package/dist/owletto/dist/assets/{use-automations-C4TSie1i.js → use-automations-BHoV0dLs.js} +2 -2
  131. package/dist/owletto/dist/assets/{use-mention-search-PfZrNbu_.js → use-mention-search-C3rWLuKm.js} +2 -2
  132. package/dist/owletto/dist/assets/{use-scroll-sentinel-D-fJx_Md.js → use-scroll-sentinel-Ct-jt7O0.js} +2 -2
  133. package/dist/owletto/dist/assets/view-param-filters-mKoqDsaD.js +2 -0
  134. package/dist/owletto/dist/assets/{views-access-required-2ubIf_3N.js → views-access-required-DHrDO333.js} +2 -2
  135. package/dist/owletto/dist/index.html +2 -2
  136. package/dist/server-main.bundle.mjs +1978 -1199
  137. package/npm-shrinkwrap.json +286 -272
  138. package/package.json +1 -1
  139. package/vendor/connector-sdk/package.json +1 -1
  140. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +45 -20
  141. package/vendor/core/dist/contracts/tools/manage-entity.js +17 -5
  142. package/vendor/core/dist/index.d.ts +1 -0
  143. package/vendor/core/dist/index.js +4 -1
  144. package/vendor/core/dist/logger.js +8 -2
  145. package/vendor/core/dist/otel.d.ts +13 -2
  146. package/vendor/core/dist/otel.js +67 -41
  147. package/vendor/core/dist/trace-context.d.ts +12 -0
  148. package/vendor/core/dist/trace-context.js +50 -0
  149. package/vendor/core/package.json +1 -1
  150. package/vendor/views/package.json +1 -1
  151. package/dist/owletto/dist/assets/_-XKF0m81R.js +0 -3
  152. package/dist/owletto/dist/assets/_-e8MbEBtw.js +0 -2
  153. package/dist/owletto/dist/assets/_agentId-Cv9goIFf.js +0 -2
  154. package/dist/owletto/dist/assets/_agentId-emObu67X.js +0 -2
  155. package/dist/owletto/dist/assets/_connectorKey._connectionId-D6NKXSOE.js +0 -2
  156. package/dist/owletto/dist/assets/_connectorKey.index-DFrkLLTU.js +0 -2
  157. package/dist/owletto/dist/assets/_eventId-BV5SQaUA.js +0 -2
  158. package/dist/owletto/dist/assets/_name-DjtJMop4.js +0 -2
  159. package/dist/owletto/dist/assets/_shape-C4lLPAwI.js +0 -2
  160. package/dist/owletto/dist/assets/_skillKey-Cw-7q6hI.js +0 -2
  161. package/dist/owletto/dist/assets/_viewKey-CIKGCtdK.js +0 -2
  162. package/dist/owletto/dist/assets/_viewKey-Dx4kJo7o.js +0 -2
  163. package/dist/owletto/dist/assets/activity-route-view-voRYSM3a.js +0 -2
  164. package/dist/owletto/dist/assets/agent-client-setup-list-Bkyw22GW.js +0 -5
  165. package/dist/owletto/dist/assets/agent-connect-pages-CpBxQCpx.js +0 -2
  166. package/dist/owletto/dist/assets/agents-DzH_FFKU.js +0 -2
  167. package/dist/owletto/dist/assets/automations-DzH_FFKU.js +0 -2
  168. package/dist/owletto/dist/assets/client-activity-scopes-BLIy1Zc3.js +0 -2
  169. package/dist/owletto/dist/assets/clients-8-EpRjsm.js +0 -2
  170. package/dist/owletto/dist/assets/connect-C0cHE9Xl.js +0 -2
  171. package/dist/owletto/dist/assets/connect._clientId-D4EG5a0v.js +0 -2
  172. package/dist/owletto/dist/assets/connected._clientId-DhoCT6sT.js +0 -2
  173. package/dist/owletto/dist/assets/connected._clientId.activity-Dn4qw2Us.js +0 -2
  174. package/dist/owletto/dist/assets/connection-X9VU9Ijm.js +0 -2
  175. package/dist/owletto/dist/assets/connection-feed-detail-B6ydKasK.js +0 -2
  176. package/dist/owletto/dist/assets/connector-provenance-BIg8P8WY.js +0 -2
  177. package/dist/owletto/dist/assets/consent-fzLN-Qy7.js +0 -2
  178. package/dist/owletto/dist/assets/copy-button-Df7QXE0w.js +0 -2
  179. package/dist/owletto/dist/assets/create-BjwsYarn.js +0 -2
  180. package/dist/owletto/dist/assets/create-Dzr4mlr0.js +0 -2
  181. package/dist/owletto/dist/assets/create._connectorKey-DLLn2nej.js +0 -2
  182. package/dist/owletto/dist/assets/device-C3AEoL5c.js +0 -2
  183. package/dist/owletto/dist/assets/entity-page-BUghWZ1s.js +0 -2
  184. package/dist/owletto/dist/assets/entity-type-page-Lf6ONdpf.js +0 -2
  185. package/dist/owletto/dist/assets/event-detail-BKSGEOdW.js +0 -2
  186. package/dist/owletto/dist/assets/guardrails-6ZJv1uzM.js +0 -2
  187. package/dist/owletto/dist/assets/identity-BaFLmbSo.js +0 -2
  188. package/dist/owletto/dist/assets/index-BaetvYLa.js +0 -2
  189. package/dist/owletto/dist/assets/index-BiEf5xOE.css +0 -1
  190. package/dist/owletto/dist/assets/index-BuXIeK7D.js +0 -2
  191. package/dist/owletto/dist/assets/index-CMLfWGPU.js +0 -2
  192. package/dist/owletto/dist/assets/index-D0YEYP7N.js +0 -2
  193. package/dist/owletto/dist/assets/index-DkO0nPex.js +0 -2
  194. package/dist/owletto/dist/assets/index-KlRId0g6.js +0 -2
  195. package/dist/owletto/dist/assets/index-Ywnqi4A6.js +0 -2
  196. package/dist/owletto/dist/assets/index-xnxhf3Op.js +0 -2
  197. package/dist/owletto/dist/assets/login-DWOT6jtS.js +0 -2
  198. package/dist/owletto/dist/assets/memory-browse-page-p2vIbfkC.js +0 -74
  199. package/dist/owletto/dist/assets/models-CQj7GIOp.js +0 -2
  200. package/dist/owletto/dist/assets/new-DTuFCQhV.js +0 -2
  201. package/dist/owletto/dist/assets/oauth-workspace-access-QPo4YwRX.js +0 -2
  202. package/dist/owletto/dist/assets/organization-BDzjnqPf.js +0 -2
  203. package/dist/owletto/dist/assets/peek-pane-content-D7yt0PrA.js +0 -2
  204. package/dist/owletto/dist/assets/proposal-review-shell-CVkLnnKo.js +0 -2
  205. package/dist/owletto/dist/assets/public-shell-ready-DXUTTGGp.js +0 -2
  206. package/dist/owletto/dist/assets/record-activity-BXhvJbd9.js +0 -2
  207. package/dist/owletto/dist/assets/reset-password-kRYyQuTY.js +0 -2
  208. package/dist/owletto/dist/assets/runs-lG2ChtOt.js +0 -2
  209. package/dist/owletto/dist/assets/settings-CEAOg7fr.js +0 -2
  210. package/dist/owletto/dist/assets/skills-BOL5c_Tk.js +0 -2
  211. package/dist/owletto/dist/assets/view-param-filters-DkX4YdDT.js +0 -2
@@ -1,74 +0,0 @@
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 +0,0 @@
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
@@ -1,2 +0,0 @@
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 +0,0 @@
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
@@ -1,2 +0,0 @@
1
- import{a2 as ge,r as j,bA as Ie,bB as Be,bC as Ke,bD as Me,bE as be,j as e,bF as Y,B as C,bG as He,a$ as Ve,bH as Ge,bI as Ue,bJ as Ye,bK as Je,bL as Ze,bM as Xe,bN as es,bO as ve,bP as ie,bQ as ss,bR as ts,bS as ns,bT as me,bU as is,bV as as,v as os,Y as Le,t as rs,bW as cs,bX as ne,q as ls,H as je,I as Ne,bY as ds,bZ as us,b_ as ms,a5 as Ce,b9 as hs,S as z,J as le,b$ as ps,c0 as _e,c1 as ke,c2 as gs,K as xs,c3 as Se,w as fs,c4 as ys,c5 as bs}from"./index-008wj-Pz.js";import{P as he,a as De,A as vs}from"./agent-permissions-matrix-CgsQ8BK_.js";import{C as we,a as Ae,b as Oe,c as ze}from"./card-BCsbrdGs.js";const Pe=["auto","approval","deny"],js={matched_rule:"Matching policy rules apply.",default_approval:"No rule matches; approval is required.",unresolved_principal:"The requesting agent or Automation could not be identified.",parent_approval:"Approval is inherited from the parent action.",unavailable_operation:"This action is unavailable on the connection."},We={read:"Reads",write:"Writes",destructive:"Destructive writes",non_destructive:"Non-destructive writes",unknown:"Unclassified writes"};function pe(s){return{operation_key:s.operation_key??null,connector_key:s.connector_key??null,connection_id:s.connection_id??null,operation_category:s.operation_category??null}}const de=s=>JSON.stringify(pe(s)),$e=s=>({...s,effect:s.effects.execute??"approval"});function F({label:s,value:n,onChange:o,children:r,disabled:h}){return e.jsxs("label",{className:"flex min-w-0 flex-col gap-1 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),e.jsx("select",{"aria-label":s,value:n,onChange:c=>o(c.target.value),disabled:h,className:"h-9 w-full rounded-lg border bg-background px-2 text-foreground",children:r})]})}function Ns(s,n){const o=n.connections?.find(r=>r.id===s.connection_id);return s.connection_id?`Connection: ${o?.display_name||o?.connector_key||"Unavailable"} (#${s.connection_id})`:s.connector_key?`Connector: ${n.connectors?.find(r=>r.key===s.connector_key)?.name||s.connector_key}`:"All connectors"}function Cs(s,n){return s.operation_key?n.connector_operations.find(o=>o.operation_key===s.operation_key)?.name||s.operation_key:s.operation_category?We[s.operation_category]:"All actions"}function ue(s,n){return`${Ns(s,n)} · ${Cs(s,n)}`}function Ee(s){return s.connection_id?`connection:${s.connection_id}`:s.connector_key?`connector:${s.connector_key}`:"all"}function Te({catalog:s}){return e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"all",children:"All connectors"}),e.jsx("optgroup",{label:"Connectors",children:s.connectors?.map(n=>e.jsx("option",{value:`connector:${n.key}`,children:n.name},n.key))}),e.jsx("optgroup",{label:"Connections",children:s.connections?.map(n=>e.jsxs("option",{value:`connection:${n.id}`,children:[n.display_name||n.connector_key," (#",n.id,")"]},n.id))})]})}function _s({label:s,ariaLabel:n,disabled:o,onRemove:r}){const[h,c]=j.useState(!1);return h?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(C,{type:"button",variant:"destructive",size:"sm",disabled:o,"aria-label":"Confirm removal",onClick:async()=>{await r()&&c(!1)},children:"Confirm"}),e.jsx(C,{type:"button",variant:"ghost",size:"sm",disabled:o,onClick:()=>c(!1),children:"Cancel"})]}):e.jsx(C,{type:"button",variant:"ghost",size:"sm",disabled:o,"aria-label":n,onClick:()=>c(!0),children:s})}function ks({owner:s,connector:n,connection:o,agent:r}){const h=ge(),[c,b]=j.useState(r??""),y=Ie(s),l=y.data,u=l?.agents.some(t=>t.id===c)?c:"",m=Be(s,u),i=Ke(s,!u),[P,_]=j.useState(o?`connection:${o}`:n?`connector:${n}`:"all"),[M,J]=j.useState(P),[I,L]=j.useState(!1),[k,D]=j.useState(""),[A,H]=j.useState("all"),[Z,E]=j.useState("approval"),[g,S]=j.useState(!1),[W,T]=j.useState(null),[V,X]=j.useState(o?String(o):""),[G,q]=j.useState(""),R=l?.connections?.some(t=>String(t.id)===V)?V:"",w=Me(s,R?Number(R):void 0,G,u||void 0);async function U(t,f){S(!0),T(null);try{if(u){const d={resource_class:"connector_action",...pe(t)};f?await Ye(s,u,{...d,effects:{execute:f}}):await Je(s,u,d)||T("This rule was already removed. The list has been refreshed.")}else{const d=i.data;if(!d)return;const K=d.rules.filter(Qe=>de(Qe)!==de(t));f&&K.push({...pe(t),effect:f});const ce=await Ze(s,{revision:d.revision,rules:K});h.setQueryData(Xe(s),ce)}return await Promise.all(["write-permissions","agent-permissions","available-operations","connector-operations","policy-explanation"].map(d=>h.invalidateQueries({queryKey:[d]}))),t}catch(d){d instanceof be&&d.status===409?(T("Policies changed in another session. Review the refreshed rules before saving again."),await i.refetch()):T(d instanceof Error?d.message:"Could not save policy.")}finally{S(!1)}}const Q=y.error||(u?m.error:i.error);if(Q instanceof be&&Q.status===403)return e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Only organization owners and admins can manage policies."});if(Q)return e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Could not load policies. ",String(Q)]});if(!l||(u?!m.data:!i.data))return e.jsx(Y,{label:"policies",rows:2});const v=t=>t==="all"||l.connectors?.some(f=>`connector:${f.key}`===t)||l.connections?.some(f=>`connection:${f.id}`===t)?t:"all",a=v(P),p=v(M),N=l.connections?.find(t=>`connection:${t.id}`===p),$=N?.connector_key??(p.startsWith("connector:")?p.slice(10):void 0),x=t=>p==="all"||Ee(t)==="all"?!0:t.connection_id?N?t.connection_id===N.id:l.connections?.some(f=>f.id===t.connection_id&&f.connector_key===$):t.connector_key===$;function B(t){return u?t.principal_kind==="agent"&&t.principal_id===u:!t.principal_kind}const ee=a.startsWith("connector:")?a.slice(10):a.startsWith("connection:")?l.connections?.find(t=>t.id===Number(a.slice(11)))?.connector_key:void 0,O=l.connector_operations.filter(t=>!ee||t.connector_key===ee),se=l.connections?.find(t=>t.id===Number(R))?.connector_key,ae=l.connector_operations.filter(t=>t.connector_key===se),oe=u?(m.data?.agent??[]).filter(t=>t.resource_class==="connector_action").map($e):i.data?.rules??[],te=(m.data?.floor??[]).filter(t=>t.resource_class==="connector_action"&&x(t)).map($e),qe={connector_key:a.startsWith("connector:")?a.slice(10):a==="all"&&A==="specific"?O.find(t=>t.operation_key===k)?.connector_key??null:null,connection_id:a.startsWith("connection:")?Number(a.slice(11)):null,operation_key:A==="specific"?k:null,operation_category:A.startsWith("category:")?A.slice(9):null},re=oe.filter(x);function fe(){_(p),H("all"),D(""),E("approval"),L(!0)}const ye=(t,f=!1)=>e.jsx("div",{className:"divide-y rounded-lg border",children:t.map(d=>{const K=!f&&B(d);return e.jsxs(De,{controls:e.jsxs(e.Fragment,{children:[e.jsx(he,{options:Pe,value:d.effect,floor:"auto",compact:!0,disabled:g||!K,ariaLabel:`Policy for ${ue(d,l)}`,onChange:ce=>void U(d,ce)}),K&&e.jsx(_s,{label:"Remove",disabled:g,ariaLabel:`Remove rule: ${ue(d,l)}`,onRemove:()=>U(d)})]}),children:[e.jsx("p",{className:"text-sm break-words",children:ue(d,l)}),!K&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d.principal_kind==="agent"&&!d.principal_id?"All agents":"Inherited restriction"})]},JSON.stringify([d.principal_kind,d.principal_id,de(d)]))})});return e.jsxs("div",{className:"space-y-4",children:[(p!==M||u!==c)&&e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"The requested scope is unavailable. Showing organization rules; install the connector or choose an available scope."}),e.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[e.jsx("p",{children:"Auto runs immediately. Ask waits for human approval. Block prevents execution and hides the action from agents. Authentication and guardrails still apply."}),e.jsxs("details",{className:"space-y-2",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-foreground",children:"How rules combine"}),e.jsx("p",{children:"A rule overrides another when it is narrower in target or actions and at least as narrow in the other. When rules are narrower in different ways, or use different categories, the stricter choice wins: Block, then Ask, then Auto. With no matching rule, the result is Ask. Impact categories apply only to writes."}),e.jsx("p",{children:"A connection-wide Auto does not override an organization-wide destructive Block. Add a destructive rule for that connection to make an exception."}),e.jsx("p",{children:"Agents and their Automations can only tighten organization policy. Internal browser steps inherit the parent approval; an explicit browser Block still wins."})]})]}),e.jsxs(F,{label:"Policy owner",value:u,onChange:b,disabled:g,children:[e.jsx("option",{value:"",children:"Organization"}),l.agents.map(t=>e.jsxs("option",{value:t.id,children:["Agent: ",t.name]},t.id))]}),u&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Auto adds no restriction for this agent. It inherits organization policy and cannot bypass Ask or Block."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u?"Without a matching restriction, this agent inherits organization policy.":"Without a matching rule, actions require approval (Ask)."}),e.jsx(F,{label:"Show rules for",value:p,onChange:J,disabled:g,children:e.jsx(Te,{catalog:l})}),u&&te.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Inherited organization rules"}),ye(te,!0)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:u?"Saved restrictions":"Saved rules"}),!I&&re.length>0&&e.jsx(C,{variant:"outline",size:"sm",disabled:g,onClick:fe,children:"Add rule"})]}),I&&e.jsxs("form",{className:"space-y-3 border-t pt-4",onSubmit:t=>{t.preventDefault(),!g&&(A!=="specific"||k)&&U(qe,Z).then(f=>{f&&(L(!1),J(Ee(f)))})},children:[e.jsx("h3",{className:"text-sm font-medium",children:"Add rule"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(F,{label:"Applies to",value:a,onChange:t=>{_(t),H("all"),D("")},disabled:g,children:e.jsx(Te,{catalog:l})}),e.jsxs(F,{label:"Actions",value:A,onChange:H,disabled:g,children:[e.jsx("option",{value:"all",children:"All actions"}),e.jsx("optgroup",{label:"Categories",children:l.operation_categories?.map(t=>e.jsx("option",{value:`category:${t}`,children:We[t]},t))}),e.jsx("option",{value:"specific",children:"Specific action"})]})]}),A==="specific"&&e.jsxs(F,{label:"Specific action",value:k,onChange:D,disabled:g,children:[e.jsx("option",{value:"",children:"Choose action"}),O.map(t=>e.jsxs("option",{value:t.operation_key,children:[t.connector_name,": ",t.name]},t.operation_key))]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(he,{options:Pe,value:Z,floor:"auto",compact:!0,disabled:g,ariaLabel:"New rule decision",onChange:E}),e.jsx(He,{onCancel:()=>L(!1),cancelDisabled:g,children:e.jsx(C,{type:"submit",disabled:g||A==="specific"&&!k,children:g?"Saving…":"Save rule"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saving an existing scope replaces its decision. Removing a rule reveals the next matching rule."})]}),re.length?ye(re):!I&&e.jsx(Ve,{icon:Ge,title:"No saved rules in this scope",description:"Add a rule for all actions, a category, or a specific action.",actionLabel:"Add rule",onAction:fe})]}),W&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:W}),e.jsxs("details",{className:"space-y-3 border-t pt-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Check an action"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs(F,{label:"Check connection",value:R,onChange:t=>{X(t),q("")},children:[e.jsx("option",{value:"",children:"Choose connection"}),l.connections?.map(t=>e.jsxs("option",{value:String(t.id),children:[t.display_name||t.connector_key," (#",t.id,")"]},t.id))]}),e.jsxs(F,{label:"Check action",value:G,onChange:q,disabled:!R,children:[e.jsx("option",{value:"",children:"Choose action"}),ae.map(t=>e.jsx("option",{value:t.operation_key.slice(t.connector_key.length+2),children:t.name},t.operation_key))]})]}),w.error?e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Could not check policy. ",String(w.error)]}):e.jsx("p",{"aria-live":"polite",className:"text-sm",children:G?w.isPending?"Checking…":w.data?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:Ue[w.data.effect]})," ·"," ",js[w.data.reason]??"The server evaluated this action.",w.data.rule_ids.length>0?` · Rules ${w.data.rule_ids.map(t=>`#${t}`).join(", ")}`:""]}):"":""})]})]})}const Ss=[{action:"create_type",label:"Create entity types",description:"Add a new type and its initial fields."},{action:"update_type",label:"Edit entity types",description:"Change fields, write rules, event kinds, or type metadata."},{action:"delete_type",label:"Delete entity types",description:"Remove an entity-type definition."}],ws=[{action:"create_relationship_type",label:"Create relationship types",description:"Add a new kind of link between entity types."},{action:"update_relationship_type",label:"Edit relationship types",description:"Change a definition, or which types it may connect."},{action:"delete_relationship_type",label:"Delete relationship types",description:"Remove a relationship-type definition."}];function xe(s){return s.resource_class==="entity_schema"&&s.principal_kind===null&&s.entity_type_slug===null&&s.operation_key===null&&s.target_agent_id===null}function As(s){return s.agent.find(xe)}function Os(s,n){return{...s,agent:[...s.agent.filter(o=>!xe(o)),n]}}function zs(s){return{...s,agent:s.agent.filter(n=>!xe(n))}}function Ps({label:s,description:n,action:o,value:r,pending:h,onChange:c}){return e.jsxs(De,{controls:e.jsx(he,{options:as("entity_schema",o),value:r,floor:"auto",disabled:h,compact:!0,ariaLabel:s,onChange:c}),children:[e.jsx("p",{children:s}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:n})]})}function Re({title:s,actions:n,effects:o,pending:r,onChange:h}){return e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s}),e.jsx("div",{className:"divide-y overflow-hidden rounded-lg border",children:n.map(({action:c,label:b,description:y})=>e.jsx(Ps,{action:c,label:b,description:y,value:o[c]??me.entity_schema[c]??"deny",pending:r,onChange:l=>h(c,l)},c))})]})}function $s({owner:s}){const n=ge(),o=es(s),r=Ie(s),h=ve({mutationFn:m=>ss(s,{resource_class:"entity_schema",effects:m}),onSuccess:m=>{n.setQueryData(o,i=>i&&Os(i,m)),n.invalidateQueries({queryKey:o})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to save schema policy")}}),c=ve({mutationFn:()=>ts(s,{resource_class:"entity_schema"}),onSuccess:()=>{n.setQueryData(o,m=>m&&zs(m)),n.invalidateQueries({queryKey:o})},onError:m=>{ie.error(m instanceof Error?m.message:"Failed to reset schema policy")}});if(r.isLoading)return e.jsx(Y,{label:"schema policy",variant:"cards",cards:1});if(r.isError||!r.data)return e.jsx(ns,{label:"schema policy"});const b=As(r.data),y=b?.effects??me.entity_schema,l=h.isPending||c.isPending,u=(m,i)=>{h.mutate({...b?.effects??me.entity_schema,[m]:i})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:b?"Custom policy":"Workspace defaults"}),b?e.jsxs(C,{type:"button",variant:"outline",size:"sm",disabled:l,onClick:()=>c.mutate(),children:[e.jsx(is,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove custom policy"]}):null]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{title:"Entity types",actions:Ss,effects:y,pending:l,onChange:u}),e.jsx(Re,{title:"Relationship types",actions:ws,effects:y,pending:l,onChange:u})]})]})}function Fe(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Es(s,n,o){const r=s.split("/");return r[1]===n?(r[1]=o,r.join("/")||"/"):`/${o}`}function Ts({section:s}){return s==="policies"?e.jsx(Y,{label:"policies",rows:2}):s==="governance"?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Agent write defaults"}),e.jsx(Y,{label:"agent write defaults",variant:"table",rows:3})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Schema governance"}),e.jsx(Y,{label:"schema governance",rows:3})]})]}):e.jsxs("div",{role:"status","aria-label":"Loading general settings","aria-busy":"true",className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Identity"}),e.jsxs("div",{"aria-hidden":"true",className:"space-y-4",children:[["name","slug"].map(n=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(z,{className:"h-3.5 w-12 rounded-none"}),e.jsx("div",{className:"flex h-9 items-center border border-input bg-background px-3",children:e.jsx(z,{className:"h-4 w-32 rounded-none"})})]},n)),e.jsx(z,{className:"h-3 w-4/5 rounded-none"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Workspace visibility"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose who can browse this workspace and its public pages."})]}),e.jsx("div",{"aria-hidden":"true",className:"grid gap-2 sm:grid-cols-2",children:["private","public"].map(n=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-3",children:[e.jsx(z,{className:"mt-0.5 h-4 w-4 shrink-0 rounded-none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(z,{className:"h-4 w-16 rounded-none"}),e.jsx(z,{className:"h-3 w-full rounded-none"}),e.jsx(z,{className:"h-3 w-2/3 rounded-none"})]})]},n))})]}),e.jsxs("div",{"aria-hidden":"true",className:"flex justify-end gap-2",children:[e.jsx(z,{className:"h-9 w-20 rounded-none"}),e.jsx(z,{className:"h-9 w-28 rounded-none"})]})]})}function Rs({owner:s,section:n="general",connector:o,connection:r,agent:h}){const c=os(),b=ge(),{data:y,error:l}=Le(),{activeOrg:u,urlOrgSlug:m}=rs(),i=(y??[]).find(a=>a.slug===s&&a.is_member)??null,P=i?.id??s,_=cs(P,{name:i?.name??"",slug:i?.slug??"",visibility:i?.visibility??"private"}),[M,J]=_.field("name"),[I,L]=_.field("slug"),[k,D]=_.field("visibility"),[A,H]=ne(P,!!i),[Z,E]=ne(P,!1),[g,S]=ne(P,null),[W,T]=j.useState(!1),[V,X]=j.useState(!1),[G,q]=ne(P,!1);if(ls(l)&&y===void 0)return e.jsxs(we,{role:"alert",children:[e.jsx(Ae,{children:e.jsx(Oe,{children:"Couldn't load organizations"})}),e.jsx(ze,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again in a moment."})})]});if(y===void 0)return e.jsx(Ts,{section:n});if(!i)return e.jsxs(we,{children:[e.jsx(Ae,{children:e.jsx(Oe,{children:"Organization not found"})}),e.jsx(ze,{children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["You aren't a member of an organization at"," ",e.jsx("span",{className:"font-mono",children:s}),", or it has been deleted."]})})]});if(n==="policies")return e.jsx("div",{className:"space-y-6",children:e.jsxs("section",{id:"policies",className:"scroll-mt-6 space-y-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control connector actions across the organization. Changes to existing rules save automatically."})}),e.jsx(ks,{owner:s,connector:o,connection:r,agent:h},`${s}:${h??""}:${o??""}:${r??""}`)]})});if(n==="governance")return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Agent write defaults"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the defaults agents inherit for entities and agents. Changes save automatically; agents can only tighten them."})]}),e.jsx(vs,{owner:s,variant:"org-floor"})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Schema governance"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control structural changes by agents and connected AI clients. Changes save automatically."})]}),e.jsx($s,{owner:s})]})]});const R=a=>{const p=xs(a);if(p.kind==="cross-host"){window.location.assign(p.href);return}c({to:p.to})},w=a=>{if(a==="public"&&i.visibility!=="public"){E(!0);return}D(a),E(!1)},U=async()=>{if(!_.canSubmit)return;const a=M.trim();if(!a){S("Name is required");return}const p=I.trim()||Fe(a);if(!p){S("Slug is required");return}T(!0),S(null);try{const N=a!==i.name||p!==i.slug,$=k!==i.visibility;let x=i.slug;if(N){const O=await le.update({organizationId:i.id,data:{name:a,slug:p}});if(O.error){S(O.error.message||"Failed to update organization");return}x=O.data?.slug??p}$&&(x=(await ps(x,k)).slug),(N||$)&&(_.accept(_.values,{name:a,slug:x,visibility:k}),await b.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization updated"));const B=u?.id===i.id||m===i.slug,ee=x!==i.slug;if(B&&ee){const O=_e(),se=ke();if(O===i.slug&&se){const oe=gs(window.location.pathname,i.slug)||"/",te=`${window.location.protocol}//${x}.${se}${oe}${window.location.search}${window.location.hash}`;window.location.assign(te);return}const ae=Es(window.location.pathname,i.slug,x);c({to:`${ae}${window.location.search}${window.location.hash}`});return}}catch(N){S(N instanceof Error?N.message:"Failed to update organization")}finally{T(!1)}},Q=async()=>{X(!0),S(null);try{const a=await le.delete({organizationId:i.id});if(a.error){S(a.error.message||"Failed to delete organization");return}await b.invalidateQueries({queryKey:["organizations"]}),ie.success("Organization deleted");const N=(y??[]).filter(x=>x.is_member).find(x=>x.id!==i.id)??null,$=u?.id===i.id||m===i.slug;if($&&N){await le.setActive({organizationId:N.id}),R(N.slug);return}if($){const x=_e(),B=ke();if(x===i.slug&&B){window.location.assign(`${window.location.protocol}//app.${B}/`);return}c({to:"/"});return}c({to:"/"})}catch(a){S(a instanceof Error?a.message:"Failed to delete organization")}finally{X(!1),q(!1)}},v=W||V;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Identity"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(je,{htmlFor:"org-name",children:"Name"}),e.jsx(Ne,{id:"org-name",value:M,onChange:a=>{J(a.target.value),A||L(Fe(a.target.value))},placeholder:"e.g. My Team",disabled:v})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(je,{htmlFor:"org-slug",children:"Slug"}),e.jsx(Ne,{id:"org-slug",value:I,onChange:a=>{H(!0),L(a.target.value)},placeholder:"e.g. my-team",disabled:v}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Changing the slug rewrites this workspace's URL. Existing links to"," ",e.jsxs("span",{className:"font-mono",children:["/",i.slug]})," redirect for a grace period."]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold leading-none",children:"Workspace visibility"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose who can browse this workspace and its public pages."})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>w("private"),disabled:v,className:`flex items-start gap-3 rounded-lg border p-3 text-left transition-colors ${k==="private"?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[e.jsx(ds,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Private"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only members can access this workspace."})]})]}),e.jsxs("button",{type:"button",onClick:()=>w("public"),disabled:v,className:`flex items-start gap-3 rounded-lg border p-3 text-left transition-colors ${k==="public"?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[e.jsx(us,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Public"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Anyone can browse public pages for this workspace."})]})]})]}),Z&&e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-sm",children:[e.jsx("p",{className:"text-foreground",children:"Make this workspace public? Catalog-style content may become visible outside the membership."}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(C,{type:"button",size:"sm",onClick:()=>{D("public"),E(!1)},disabled:v,children:"Confirm public"}),e.jsx(C,{type:"button",size:"sm",variant:"ghost",onClick:()=>E(!1),disabled:v,children:"Cancel"})]})]})]}),g&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:g}),e.jsx(ms,{visible:_.hasConflict,onReload:_.reset}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",onClick:()=>void c({to:`/${s}`}),disabled:v,children:"Cancel"}),e.jsxs(C,{onClick:U,disabled:v||!_.canSubmit,children:[W?e.jsx(Ce,{size:"lg",className:"mr-1.5"}):null,W?"Saving...":"Save changes"]})]}),e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:[e.jsx("p",{className:"text-sm font-medium",children:i.is_personal?"Personal workspace":"Delete this organization"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i.is_personal?"Your personal workspace can't be deleted — your devices and personal connections are bound to it.":"Permanently removes the organization and all members' workspace access. This cannot be undone."}),!i.is_personal&&e.jsx("div",{className:"mt-3",children:G?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{variant:"destructive",size:"sm",onClick:Q,disabled:v,children:[V?e.jsx(Ce,{className:"mr-1.5"}):null,"Confirm delete"]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>q(!1),disabled:v,children:"Cancel"})]}):e.jsxs(C,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>q(!0),disabled:v,children:[e.jsx(hs,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete organization"]})})]})]})}function Ds(){const{owner:s}=Se.useParams(),n=Se.useSearch(),{hash:o}=fs(),r=ys(n,o),h={general:"General",policies:"Policies",governance:"Governance"}[r],{data:c}=Le(),b=(c??[]).find(y=>y.slug===s&&y.is_member)?.name;return e.jsx("div",{className:"flex flex-1 flex-col px-4 pt-2.5 pb-8 lg:px-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bs,{className:"h-7 w-7"}),e.jsx("h1",{className:"text-3xl font-semibold leading-tight",children:h})]}),b?e.jsx("p",{className:"text-base font-medium text-foreground",children:b}):null]}),e.jsx(Rs,{owner:s,...n,section:r})]})})}export{Ds as component};
2
- //# sourceMappingURL=organization-BDzjnqPf.js.map
@@ -1,2 +0,0 @@
1
- import{j9 as H,ja as V,r as f,he as q,u as T,j as e,dz as U,ax as G,aD as W,S as b,is as Q,B as N,jb as Z,jc as k,jd as Y,je as L,jf as z,jg as J,d6 as X,n as A,am as D,cy as F,a5 as C,et as ee,t as te,k as se,fF as ne,w as re,L as $,jh as ie,fk as oe,fI as ae,fA as ce,ji as de,fO as E,iw as le,av as ue,jj as me,ap as pe,i as xe,jk as he,co as fe,dZ as ye,cT as ge,p as je,eo as ve,jl as Ne,bk as we,jm as be,es as ke,cU as Ae,jn as Ce,bg as Se}from"./index-008wj-Pz.js";import{u as Ie,A as Pe}from"./automation-detail-content-DMYxs6F6.js";import{A as _e}from"./agent-loading-shells-CamDtzHY.js";import{s as Le,h as Te,R as Re,A as $e}from"./agent-thread-CsRexwTv.js";import{C as Ee,b as Oe,A as ze}from"./connection-feed-detail-B6ydKasK.js";import{R as De,S as Fe,g as Me}from"./runs-panel-LnGpHCAQ.js";import{O as Be}from"./connect-menu-D2K4tmvW.js";import{a as Ke}from"./connections-browser-BMV8bf54.js";import{f as He}from"./connector-scope-lists-CJYz53YF.js";import{S as Ve}from"./source-record-panels-CjFPgKKJ.js";import{E as R}from"./events-feed-VfU4csn2.js";import{S as qe}from"./schema-type-editor-panel-C_Es0qDf.js";import{h as Ue,s as Ge,i as We}from"./renderer-AJxSmE3-.js";import{E as Qe}from"./event-detail-BKSGEOdW.js";import{V as Ze,R as Ye}from"./views-access-required-2ubIf_3N.js";import{R as Je,b as Xe}from"./event-card-CBlsG32u.js";import{V as et,a as tt}from"./view-param-filters-DkX4YdDT.js";import{b as st}from"./use-automations-C4TSie1i.js";import"./create-automation-form-DHW6OUoS.js";import"./cronstrue-xxpD1P2-.js";import"./entity-options-DJv2EhVV.js";import"./connection-label-BobuYiAG.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";import"./proposal-review-shell-CVkLnnKo.js";import"./runs-lG2ChtOt.js";import"./json-diff-LE_vNZrM.js";import"./app-bridge-C4nPtae3.js";import"./feed-event-kinds-BYuZCoU4.js";import"./use-scroll-sentinel-D-fJx_Md.js";import"./clients-8-EpRjsm.js";import"./filter-bar-COU0sBFQ.js";import"./calendar-DDCCSPW6.js";import"./table-DHM-vCxP.js";import"./status-dot-CSBtKT4g.js";import"./client-activity-scopes-BLIy1Zc3.js";import"./client-rows-DiJQ5D1z.js";import"./entity-type-page-Lf6ONdpf.js";import"./card-BCsbrdGs.js";import"./record-session-D07szzqN.js";import"./copy-button-Df7QXE0w.js";const M=Symbol("trusted-automation-interaction");function nt(t){return Object.defineProperty(t,M,{value:!0}),t}function rt(t){return{title:`${t} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${t} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${t} proposals.`},{id:"reject-all",label:"Reject all",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${t} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${t} proposals.`}]}}const it=new Set(["automation-approval-batch"]);function ot(t){return new Promise(s=>{t({onSettled:(i,n)=>s(!!n)})})}function at(){const t=H(),s=V();return f.useMemo(()=>({toolNames:it,resolve:(i,n)=>{if(!n||typeof n!="object"||n[M]!==!0)return null;const r=n;if(i==="automation-approval-batch"){const o=typeof r.runId=="number"&&Number.isSafeInteger(r.runId)&&r.runId>0?r.runId:null,a=typeof r.count=="number"&&Number.isSafeInteger(r.count)&&r.count>1?r.count:null,c=Array.isArray(r.runIds)?r.runIds.filter(d=>typeof d=="number"&&Number.isSafeInteger(d)&&d>0):[];return o===null||a===null||c.length!==a||new Set(c).size!==a?null:{view:rt(a),handlers:{manage_operations:d=>d.action!=="approve"&&d.action!=="reject"?Promise.resolve(!0):ot(m=>d.action==="approve"?t.mutate({run_id:o,run_ids:c},m):s.mutate({run_id:o,run_ids:c},m))}}}return null}}),[t,s])}function ct(t){const s=[];return t.forEach((i,n)=>{s.push({id:`sep:${i.runId}`,role:"system",parts:[{type:"text",text:dt(i,n)}],createdAt:i.completedAt?new Date(i.completedAt).getTime():void 0});for(const r of i.messages)s.push({...r,id:`r${i.runId}:${r.id}`})}),s}function dt(t,s){const i=(t.pendingActionCount??0)>0?`Waiting for you (${t.pendingActionCount})`:t.status==="completed"?"Completed":t.status??"Completed",n=(t.autoAppliedCount??0)>0?` · ${t.autoAppliedCount} applied automatically`:"",r=t.completedAt?new Date(t.completedAt).toLocaleString():null;return r?`Run ${s+1} · ${i}${n} · ${r}`:`Run ${s+1} · ${i}${n}`}const lt=/(?:^|\n)Run this Automation now/;function ut(t){return t.role==="user"&&t.parts.some(s=>s.type==="text"&&lt.test(s.text))}function mt(t){return`history-interaction:${t.runId}:${t.eventId??"error"}`}function pt({agentId:t,automationId:s,ownerSlug:i,runId:n}){const{data:r,isLoading:o}=q(t,s,{orgSlug:i,...n!=null?{runId:n}:{}}),a=at(),c=T(),d=f.useCallback(l=>{c?.open({href:`/${i}/automations/${s}?run_id=${l}`,title:`Automation run #${l}`,runId:l})},[c,i,s]),m=f.useMemo(()=>{const l=r?.runs??[],v=(n!=null?l.filter(u=>u.runId===n):l).slice().reverse();return ct(v.map(u=>{const h=u.messages.map(p=>Le(p,{showToolCalls:!0})).filter(p=>p!==null&&!ut(p));u.task?.trim()&&h.unshift({id:"task",role:"user",parts:[{type:"text",text:u.task.trim()}]});const x=u.actions??[],y=x.filter(p=>p.status==="pending");if(y.length>1){const p=y.map(j=>j.runId).sort((j,I)=>j-I);h.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${u.runId}`,toolName:"automation-approval-batch",args:nt({runId:u.runId,count:y.length,runIds:p})}]})}for(const p of x){const j=Te([p],{workspaceSlug:i,agentId:t,webOrigin:typeof window>"u"?null:window.location.origin});j&&h.push({...j,id:mt(p)})}return{runId:u.runId,completedAt:u.completedAt,status:u.status,pendingActionCount:u.pendingActionCount,autoAppliedCount:u.autoAppliedCount,messages:h}}))},[t,r,i,n]);return o?e.jsx(_e,{readOnly:!0}):m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):e.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:e.jsx(Re,{messages:m,workspaceSlug:i,children:e.jsx($e,{readOnly:!0,readerPositionMode:"runs",interactionExtension:a,onRunSelect:n==null&&c?d:void 0})})})}function xt(t){if(!t||typeof t!="object")return[];const s=t.properties;if(!s)return[];const i=Array.isArray(t.required)?new Set(t.required.map(String)):new Set;return Object.entries(s).map(([n,r])=>({name:n,type:String(r.type??"any"),required:i.has(n),description:typeof r.description=="string"?r.description:void 0}))}function ht({fields:t}){return t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No fields."}):e.jsx("ul",{className:"space-y-2",children:t.map(s=>e.jsxs("li",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("code",{className:"text-xs font-medium text-foreground",children:s.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:s.type}),s.required?e.jsx("span",{className:"text-[10px] font-medium text-amber-600 dark:text-amber-400",children:"required"}):null]}),s.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description}):null]},s.name))})}function S({item:t,hideHeading:s=!1}){const i=t.schemaSections;return i?e.jsxs("article",{className:s?"space-y-4":"space-y-4 px-5 py-5",children:[!s&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(U,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h2",{className:"text-base font-medium text-foreground",children:t.title}),i.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:i.description}):null]})]}),i.sections.map(n=>{const r=xt(n.schema);return e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n.title}),n.description?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:n.description}):null]}),e.jsx(ht,{fields:r})]},n.title)})]}):null}function ft({panel:t}){const s=G(t.organizationId),i=t.section==="connections"||!!t.connectionId,n=W(t.organizationId,{connectorKey:t.connectorKey,connectionIds:t.connectionId?[t.connectionId]:void 0,enabled:i}),r=s.data?.find(a=>a.key===t.connectorKey),o=n.data?.find(a=>a.id===t.connectionId&&a.connector_key===t.connectorKey);return s.isLoading||i&&n.isLoading?e.jsx("div",{className:"p-5",children:e.jsx(b,{className:"h-28 w-full"})}):s.isError||i&&n.isError?e.jsx("p",{role:"alert",className:"p-5 text-sm",children:"Could not load this connector. Close the pane and try again."}):t.connectionId&&!o||!r&&!o&&t.section!=="connections"?e.jsx("p",{className:"p-5 text-sm",children:"This connection is no longer available."}):e.jsx("div",{className:"p-5",children:t.section==="runs"?e.jsx(De,{scope:{connectorKey:t.connectorKey},ownerSlug:t.ownerSlug}):t.section==="connections"?e.jsx(Ke,{connections:n.data??[],connector:r,connectorKey:t.connectorKey,ownerSlug:t.ownerSlug}):o?e.jsx(jt,{connection:o,connector:r,panel:t}):r?t.section==="oauth-apps"?e.jsx(Be,{connector:r,organizationId:t.organizationId,newApp:!!t.newApp}):t.section==="feeds"?e.jsx(yt,{connector:r}):r.installed===!1?e.jsx(gt,{connector:r,ownerSlug:t.ownerSlug}):e.jsx(Nt,{connector:r,ownerSlug:t.ownerSlug}):null},`${t.connectorKey}:${t.connectionId??"connector"}:${t.section}`)}function yt({connector:t}){const s=Object.entries(t.feeds_schema??{}).map(([i,n])=>{const r=n;return{id:i,name:r.name??i,description:r.description,feed:r}});return e.jsx(k,{entries:s,label:"feed types",renderDetail:({name:i,feed:n})=>e.jsx(S,{item:{href:"",title:i,schemaSections:Y(n)},hideHeading:!0})})}function gt({connector:t,ownerSlug:s}){const i=Object.entries(t.actions_schema??{}).map(([n,r])=>{const o=r;return{id:n,name:o.name??n,description:o.description,action:o}});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection."," ",e.jsx(L,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(k,{entries:i,label:"actions",renderDetail:({name:n,action:r})=>e.jsx(S,{hideHeading:!0,item:{href:"",title:n,schemaSections:z(r)}})})]})}function jt({connection:t,connector:s,panel:i}){const[n,r]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:n,children:i.section==="feeds"?e.jsx(vt,{connection:t,connector:s,ownerSlug:i.ownerSlug}):e.jsx(Q,{connection:t,ownerSlug:i.ownerSlug,inPeek:!0,onReviewPermissions:s?()=>r(!0):void 0})}),n&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Back to actions"}),e.jsx("h2",{className:"text-base font-semibold",children:"Provider permissions"}),e.jsx(Z,{connection:t,connectorDef:s})]})]})}function vt({connection:t,connector:s,ownerSlug:i}){const{data:n=[],isLoading:r,isError:o}=X(t.id),[a,c]=f.useState(!1),d=t.facets?.chat??!1;if(r)return e.jsx(b,{className:"h-28 w-full"});if(o)return e.jsx("p",{role:"alert",children:"Could not load sources. Close the pane and try again."});const m=n.map(l=>({id:String(l.id),name:l.display_name||l.feed_key,status:He(l)??(l.operations.includes("sync")?"Sync enabled":"Live access"),feed:l}));return e.jsxs(e.Fragment,{children:[e.jsx("div",{hidden:a,children:e.jsx(k,{entries:m,label:d?"channels":"feeds",action:Object.keys(s?.feeds_schema??{}).length>0?e.jsx(N,{size:"sm",variant:"outline",onClick:()=>c(!0),children:d?"Add channel":"Add feed"}):void 0,renderDetail:({feed:l})=>l.store==="channel_messages"?e.jsx(Ee,{feed:l,hideHeader:!0}):e.jsx(Oe,{feed:l,connectorDef:s,ownerSlug:i})})}),a&&s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-base font-semibold",children:d?"Add channel":"Add feed"}),e.jsx(ze,{organizationId:t.organization_id,connections:[t],connectorDefinitions:[s],onClose:()=>c(!1)})]})]})}function Nt({connector:t,ownerSlug:s}){const{data:i=[],isLoading:n,isError:r}=J(t.key);if(n)return e.jsx(b,{className:"h-28 w-full"});if(r)return e.jsx("p",{role:"alert",children:"Could not load actions. Close the pane and try again."});const o=t.actions_schema??{},a=i.map(c=>({id:c.operation_key,name:c.name??c.operation_key,description:c.description,operation:c}));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Policy depends on connection. Click an action to inspect its inputs."," ",e.jsx(L,{ownerSlug:s,connectorKey:t.key})]}),e.jsx(k,{entries:a,label:"actions",renderControl:()=>e.jsx(L,{ownerSlug:s,connectorKey:t.key}),renderDetail:({operation:c,name:d})=>o[c.operation_key]?e.jsx(S,{hideHeading:!0,item:{href:"",title:d,schemaSections:z(o[c.operation_key])}}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No input fields."})})]})}function wt({owner:t,path:s}){const{data:i,isLoading:n}=A(t,{slug:t}),r=i?.workspace,o=r?.type==="organization"?r.id:null,a=o?{slug:t}:void 0,{data:c,isLoading:d}=D(`/${t}/${F(s)}`,a),m=c?.entity,l=m?.id;return n||d?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(C,{className:"mr-2"})," Loading…"]}):o?l==null?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't find this record. It may have been deleted, or it may live in a workspace you can't access."}):m?.is_derived?e.jsx(Ve,{record:{type:m.entity_type,key:m.slug},orgContext:a}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(R,{organizationId:o,ownerSlug:t,entityId:typeof l=="number"?l:void 0,filters:{sortBy:"date",sortOrder:"desc"},emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to this record yet."})})}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."})}function bt(t){if(Array.isArray(t.enum))return`One of ${t.enum.length}`;if(t.format==="date"||t.format==="date-time")return"Date";if(t.format==="uri")return"Link";if(t.format==="email")return"Email";const s=Array.isArray(t.type)?t.type[0]:t.type;return s==="array"?"List":s==="object"?"Group":s==="integer"||s==="number"?"Number":s==="boolean"?"Yes / no":"Text"}function kt({owner:t,typeSlug:s,view:i}){const{data:n,isLoading:r}=A(t,{slug:t}),o=n?.workspace,a=o?.type==="organization"?o.id:null,{isAdmin:c}=ee(a??void 0),{orgContext:d}=te(),{data:m,isSuccess:l}=se(d),g=(m??[]).find(w=>w.slug===s),v=l&&!g,u=`/${t}/${ne(s)}`,{pathname:h}=re(),x=h===u||h===`${u}/`||h.startsWith(`${u}/-/`),y=f.useMemo(()=>Ue(g?.metadata_schema),[g?.metadata_schema]),p=T(),j=p?.close;f.useEffect(()=>{v&&j?.()},[v,j]);const I=f.useMemo(()=>({entityTypes:[s],sortBy:"date",sortOrder:"desc"}),[s]);if(r)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(C,{className:"mr-2"})," Loading…"]});if(v)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This entity type no longer exists."});if(!a)return e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."});const K=g?.name??s;return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-4 py-2.5",children:[x?null:e.jsx(N,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs($,{...oe(t,s),children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Browse records"]})}),g&&!x&&!ae(g)&&g.entity_count!==0?e.jsx(N,{asChild:!0,variant:"outline",size:"sm",className:"h-8 text-xs",children:e.jsxs($,{to:"/$owner/$entityType/-/$shape",params:{owner:t,entityType:s,shape:"graph"},search:de(E(t,s)),children:[e.jsx(ce,{className:"mr-1.5 h-3.5 w-3.5"}),"Graph"]})}):null,i!=="activity"&&p?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"ml-auto h-8 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>p.open({href:E(t,s,"activity"),title:`${K} activity`}),children:[e.jsx(le,{className:"h-3.5 w-3.5"}),"Activity"]}):null]}),i==="activity"?e.jsx("div",{className:"px-4 py-4",children:e.jsx(R,{organizationId:a,ownerSlug:t,filters:I,showEntityLinks:!0,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing has happened to these records yet."})})}):c?e.jsx("div",{className:"p-4",children:e.jsx(qe,{slug:s,onClose:()=>j?.()})}):y.length>0?e.jsxs("section",{"aria-labelledby":"entity-type-peek-fields",className:"px-4 py-4",children:[e.jsx("h3",{id:"entity-type-peek-fields",className:"mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("dl",{className:"divide-y divide-border/60 text-sm",children:y.map(w=>e.jsxs("div",{className:"flex items-baseline justify-between gap-3 py-1.5",title:w.prop.description,children:[e.jsx("dt",{className:"min-w-0 truncate",children:Ge(w)}),e.jsx("dd",{className:"shrink-0 text-xs text-muted-foreground",children:bt(w.prop)})]},w.key))})]}):e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This type has no fields yet."})]})}function At({owner:t,eventId:s,viewKey:i}){const n=T(),r=(o,a)=>e.jsx(Qe,{owner:a,organizationId:o,eventId:s,viewKey:i,dense:!0,onSelectView:n?c=>n.retarget(c):void 0},`${a}/${s}/${i??""}`);return e.jsx("div",{className:"px-4 py-4",children:t==="me"?r(null,t):e.jsx(ue,{owner:t,children:({organizationId:o,ownerSlug:a})=>o?r(o,a):e.jsx("div",{className:"h-40 animate-pulse rounded-md bg-muted/40"})})})}function P({owner:t,runId:s,runIds:i,contentIds:n}){const{data:r,isLoading:o}=A(t==="me"?null:t,{slug:t}),a=r?.workspace,c=t!=="me"&&a?.type==="organization"?a.id:null,d=f.useMemo(()=>{if(t==="me")return n?.length?{contentIds:n,sortBy:"date",sortOrder:"desc"}:void 0;const l=i??(s!=null?[s]:void 0);if(!(!l?.length&&!n?.length))return{...l?.length?{runIds:l}:{},...n?.length?{contentIds:n}:{}}},[t,n,s,i]),m=d!=null;return t!=="me"&&o?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(C,{className:"mr-2"})," Loading…"]}):t!=="me"&&c==null?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't resolve this workspace."}):m?e.jsx("div",{className:"px-4 py-4",children:e.jsx(R,{presentation:"detail",organizationId:c,ownerSlug:t,filters:d,emptyState:e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:s!=null||i?.length?"No matching events from this run yet.":"No matching events yet."})})}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Nothing to preview."})}const _=25;function Ct({target:t}){const[s,i]=f.useState(0),{data:n,isLoading:r,isError:o,refetch:a}=me(t.entityId,t.orgContext,{relationshipType:t.relationshipType,limit:_,offset:s}),c=n?.total;return e.jsxs("div",{className:"space-y-3 px-5 py-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.label," · ",t.entityName,c!==void 0?` · ${c} current ${c===1?"link":"links"}`:n?` · ${n.rows.length} shown`:""]}),e.jsx(Je,{count:n?.failures?.length??0,onRetry:()=>void a()}),r?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{className:"h-6 w-full"}),e.jsx(b,{className:"h-6 w-full"})]}):o||!n?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load these links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void a(),children:"Retry"})]}):n.rows.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links on this page."}):e.jsx("ul",{className:"divide-y divide-border",children:n.rows.map(d=>e.jsx("li",{className:"flex items-center justify-between gap-3 py-1.5",children:e.jsx(Xe,{row:d,entityId:t.entityId,ownerSlug:t.ownerSlug,orgContext:t.orgContext})},d.id))}),n&&(s>0||n.hasMore)?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(N,{type:"button",variant:"outline",size:"sm",disabled:s===0,onClick:()=>i(Math.max(0,s-_)),children:"Previous"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[n.rows.length," shown",c===void 0?"":` of ${c}`]}),e.jsx(N,{type:"button",variant:"outline",size:"sm",disabled:!n.hasMore,onClick:()=>i(s+_),children:"Next"})]}):null]})}function St({owner:t,path:s,viewKey:i}){const[n,r]=f.useState({}),{data:o,isLoading:a}=A(t,{slug:t}),c=o?.workspace,d=c?.type==="organization"?c.id:null,m=d?{slug:t,organizationId:d}:void 0,{data:l,isLoading:g}=D(`/${t}/${F(s)}`,m),{isMember:v,isLoading:u}=pe(t),h=xe({slug:t,organizationId:v?d:null}),x=l?.entity;if(a||g||u||v&&h.isLoading)return e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(C,{className:"mr-2"})," Loading…"]});if(!v)return e.jsx(Ze,{});if(h.isError)return e.jsx(et,{onRetry:()=>void h.refetch()});const y=x?he(h.data??[],{type:x.entity_type,id:x.id??x.slug}).find(p=>p.key===i):void 0;return!d||!x||!y?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"This view isn't attached to this record any more."}):e.jsx("div",{className:"px-4 py-4",children:e.jsx(tt,{orgSlug:t,viewKey:y.key,scope:{type:x.entity_type,entity:x.is_derived?x.slug:x.id??x.slug},params:n,onParamsChange:r,contentHash:y.content_hash,title:y.name,minHeight:320})})}function B({owner:t,runId:s}){const i=fe({queryKey:["run-outcome",t,s],queryFn:async()=>{const r=await ge("manage_operations",{action:"get_run",run_id:s},{slug:t});if(!r.run)throw new Error(r.error||"Run not found");return r.run},enabled:t!=="me",staleTime:15e3,refetchInterval:r=>["pending","claimed","running"].includes(r.state.data?.status??"")?5e3:!1});if(t==="me")return null;if(i.isLoading)return e.jsx("p",{role:"status",className:"px-4 pt-4 text-xs text-muted-foreground",children:"Loading run…"});if(!i.data)return e.jsx("p",{role:"alert",className:"px-4 pt-4 text-sm text-destructive",children:"Could not load this run."});const n=i.data;return e.jsxs("section",{"aria-label":"Run outcome",className:"space-y-2 border-b px-4 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Fe,{status:Me(n.status),children:n.status}),e.jsx("time",{dateTime:n.created_at,className:"text-xs text-muted-foreground",children:ye(n.created_at)})]}),n.connection_display_name?e.jsx("p",{className:"text-sm",children:n.connection_display_name}):null,n.error_message?e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm text-destructive",children:n.error_message}):null,i.isError?e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:"Could not refresh this run. Showing its last known outcome."}):null]})}function vs({item:t}){if(t.connectorPanel)return e.jsx(ft,{panel:t.connectorPanel});if(t.schemaSections)return e.jsx(S,{item:t});if(t.recordField)return e.jsx(Ye,{target:t.recordField});if(t.recordPeer)return e.jsx(We,{target:t.recordPeer});if(t.recordLinks)return e.jsx(Ct,{target:t.recordLinks});if(typeof t.browserUrl=="string"&&t.browserUrl.length>0)return e.jsx(O,{item:t});const s=t.href?je(t.href):null;return s?s.kind==="memory"?"runId"in s?e.jsxs(e.Fragment,{children:[e.jsx(B,{owner:s.owner,runId:s.runId}),e.jsx(P,{owner:s.owner,runId:s.runId})]}):"runIds"in s?e.jsx(P,{owner:s.owner,runIds:s.runIds}):e.jsx(P,{owner:s.owner,contentIds:s.contentIds}):s.kind==="entity"?e.jsx(wt,{owner:s.owner,path:s.path}):s.kind==="entity-type"?e.jsx(kt,{owner:s.owner,typeSlug:s.typeSlug,view:s.view}):s.kind==="record-view"?e.jsx(St,{owner:s.owner,path:s.path,viewKey:s.viewKey}):s.kind==="event"?e.jsx(At,{owner:s.owner,eventId:s.eventId,viewKey:s.viewKey}):t.runId?e.jsx(It,{owner:s.owner,automationId:s.automationId,runId:t.runId}):e.jsx(Pt,{owner:s.owner,automationId:s.automationId,initialView:s.view??"activity",runId:s.runId}):e.jsx(O,{item:t})}function O({item:t}){const s=t.body,i=t.notificationType??"generic",n=t.createdAt,r=t.browserUrl??null,o=t.browserHandoff??null;return e.jsxs("article",{className:"space-y-4 px-5 py-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:Ne(i)}),n?e.jsx("span",{children:we(n)}):null]})]}),s?e.jsx("div",{className:"text-sm leading-6 text-foreground/90",children:e.jsx(be,{text:s,linkPolicy:i==="action_approval_needed"?"app-links":"strip"})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No additional details were provided."}),t.owner&&t.sourceAttribution?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground/80",children:"Generated from"}),e.jsx(ke,{owner:t.owner,source:t.sourceAttribution,className:"text-xs"})]}):null,r?e.jsx("div",{className:"space-y-2",children:o?.state==="expired"?e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:o.error_message??"This draft expired before the page was opened."}):o?.state==="completed"||o?.state==="preparing"?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.state==="preparing"?"Preparing draft — keep your browser tab open.":"Draft prepared — review and post in your browser."}):e.jsxs(N,{type:"button",size:"sm",className:"h-8 text-sm",onClick:()=>{Ce(r)},children:[e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Open post"]})}):null]})}function It({owner:t,automationId:s,runId:i}){const{organizationId:n}=Ie(t),r=st(s,void 0,n),o=r.data?.automation?.managed_agent_id??null;return o?e.jsx(pt,{agentId:o,automationId:s,ownerSlug:t,runId:i}):r.isLoading?e.jsx(b,{className:"h-24 w-full rounded-lg"}):e.jsx(B,{owner:t,runId:i})}function Pt({owner:t,automationId:s,initialView:i,runId:n}){const[r,o]=f.useState(i),a=r==="definition";return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 gap-1.5 text-muted-foreground hover:text-foreground",onClick:()=>o(a?"activity":"definition"),children:a?"Done":e.jsxs(e.Fragment,{children:[e.jsx(Se,{className:"h-3.5 w-3.5"}),"Edit"]})})}),e.jsx(Pe,{owner:t,agentId:null,automationId:s,view:r,runId:n,onDone:()=>o("activity")})]})}export{vs as PeekPaneContent};
2
- //# sourceMappingURL=peek-pane-content-D7yt0PrA.js.map
@@ -1,2 +0,0 @@
1
- import{hf as w,gO as R,gP as y,r as N,j as e,bf as P,B as d,H as k,ew as C}from"./index-008wj-Pz.js";import{a as A}from"./runs-lG2ChtOt.js";function B({resource:g,runId:t,children:h,onDone:l}){const c=!!t,{data:a,isLoading:E,isError:u,refetch:v}=A(g,c?t:void 0),s=w({isReview:c,isError:u,status:a?.status}),m=a?.status==="pending"?a.proposal:null,n=R(),i=y(),[p,x]=N.useState(""),o=n.isPending||i.isPending,j=s==="active"||s==="loading"||s==="error",b=()=>{t&&n.mutate({run_id:t},{onSuccess:()=>l?.()})},f=()=>{if(!t)return;const r=p.trim();i.mutate({run_id:t,...r?{reason:r}:{}},{onSuccess:()=>l?.()})};return e.jsxs("div",{className:"grid content-start gap-4",children:[s==="active"?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-3 text-sm text-amber-950 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-100",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("p",{children:["Review the change the builder agent proposed. The values below show the proposed change — ",e.jsx("strong",{children:"Approve"})," to apply, or"," ",e.jsx("strong",{children:"Reject"}),"."]})]})}):null,s==="gone"?e.jsx("div",{className:"rounded-lg border bg-muted/30 p-3 text-sm text-muted-foreground",children:"This change is no longer pending (it may have been approved or rejected already)."}):null,s==="error"?e.jsx("div",{className:"rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"text-destructive",children:"Couldn't load the proposed change to review. Editing is disabled until it loads — retry, or reopen the link."}),e.jsx(d,{type:"button",variant:"outline",size:"sm",onClick:()=>void v(),children:"Retry"})]})}):null,h({reviewMode:s,proposal:m,controlsDisabled:j}),s==="active"?e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"review-reject-reason",children:"Reason (optional)"}),e.jsx(C,{id:"review-reject-reason",rows:2,value:p,onChange:r=>x(r.target.value),placeholder:"Why you're rejecting — shared back to the requester.",disabled:o})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:justify-end",children:[e.jsx(d,{type:"button",variant:"outline",onClick:f,disabled:o,children:i.isPending?"Rejecting...":"Reject"}),e.jsx(d,{type:"button",onClick:b,disabled:o,children:n.isPending?"Approving...":"Approve"})]})]}):null]})}export{B as P};
2
- //# sourceMappingURL=proposal-review-shell-CVkLnnKo.js.map
@@ -1,2 +0,0 @@
1
- import{r as e,dD as l}from"./index-008wj-Pz.js";function a(){return e.useEffect(()=>{l()},[]),null}export{a as P};
2
- //# sourceMappingURL=public-shell-ready-DXUTTGGp.js.map