@lobu/runtime-server 20.0.0 → 20.0.1

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 (194) hide show
  1. package/dist/catalogs/connectors.json +165 -15
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/chat-automation-events.ts +33 -0
  4. package/dist/connectors/discord.ts +2 -0
  5. package/dist/connectors/gchat.ts +2 -0
  6. package/dist/connectors/google_drive.ts +210 -40
  7. package/dist/connectors/slack-automation-events.ts +0 -31
  8. package/dist/connectors/slack.ts +2 -2
  9. package/dist/connectors/teams.ts +2 -0
  10. package/dist/connectors/telegram.ts +2 -0
  11. package/dist/connectors/whatsapp.ts +2 -0
  12. package/dist/dependencies.bun.lock +4 -4
  13. package/dist/guest.bundle.js +13 -1
  14. package/dist/owletto/dist/apple-touch-icon.png +0 -0
  15. package/dist/owletto/dist/assets/{_-WVpKI9q9.js → _-BTmsEMQo.js} +2 -2
  16. package/dist/owletto/dist/assets/_-ea0K1u_g.js +1 -0
  17. package/dist/owletto/dist/assets/{_agentId-U2D1yGV_.js → _agentId-DON3NuNk.js} +1 -1
  18. package/dist/owletto/dist/assets/_agentId-qF8hi8Cf.js +1 -0
  19. package/dist/owletto/dist/assets/{_automationId-BggDSfkK.js → _automationId-Bprfhhg8.js} +1 -1
  20. package/dist/owletto/dist/assets/{_connectorKey._connectionId-BalfcgLi.js → _connectorKey._connectionId-75LMK1pB.js} +1 -1
  21. package/dist/owletto/dist/assets/{_connectorKey.index-IRfifXtO.js → _connectorKey.index-N0fJPz8N.js} +1 -1
  22. package/dist/owletto/dist/assets/{_conversationId-1GSbJquw.js → _conversationId-BY5q9MHG.js} +1 -1
  23. package/dist/owletto/dist/assets/{_deploymentId-DpMLDfMN.js → _deploymentId-DFh2d5Pm.js} +1 -1
  24. package/dist/owletto/dist/assets/_name-OY_X_Zm-.js +1 -0
  25. package/dist/owletto/dist/assets/{_owner-CZwj2Fc5.js → _owner-B92z-CVu.js} +1 -1
  26. package/dist/owletto/dist/assets/_skillKey-CeEE23_w.js +1 -0
  27. package/dist/owletto/dist/assets/{_slug-5SDJ_Zlr.js → _slug-CvHxtUEf.js} +1 -1
  28. package/dist/owletto/dist/assets/accept-invitation-CXSrxBJN.js +1 -0
  29. package/dist/owletto/dist/assets/activity-route-view-C9W2Ipni.js +1 -0
  30. package/dist/owletto/dist/assets/{agent-card-controls-Duh-6QNV.js → agent-card-controls-CLupkefQ.js} +1 -1
  31. package/dist/owletto/dist/assets/{agent-client-setup-list-u6MIKBDe.js → agent-client-setup-list-DgFv4h0W.js} +1 -1
  32. package/dist/owletto/dist/assets/{agent-connect-pages-22bJIutE.js → agent-connect-pages-DT8R_qnj.js} +1 -1
  33. package/dist/owletto/dist/assets/{agent-editor-form-DIo7SWp4.js → agent-editor-form-ayUg3Ws1.js} +1 -1
  34. package/dist/owletto/dist/assets/{agent-guardrails-route-Duv7Rpd9.js → agent-guardrails-route-D-b6CIt2.js} +1 -1
  35. package/dist/owletto/dist/assets/{agent-loading-shells-D6mLqg3d.js → agent-loading-shells-DjMpSoub.js} +1 -1
  36. package/dist/owletto/dist/assets/agent-permissions-matrix-BuGatiEq.js +1 -0
  37. package/dist/owletto/dist/assets/{agent-skill-context-DjPLOCBS.js → agent-skill-context-DKpIFmCh.js} +1 -1
  38. package/dist/owletto/dist/assets/{agent-skills-route-CdCVU8ZJ.js → agent-skills-route-DqIMttMK.js} +1 -1
  39. package/dist/owletto/dist/assets/{agent-subpage-shell-BfomD6m2.js → agent-subpage-shell-Bojgj1uq.js} +1 -1
  40. package/dist/owletto/dist/assets/{agent-thread-COEinkFo.js → agent-thread-R8Pego9t.js} +2 -2
  41. package/dist/owletto/dist/assets/agents-C9x76gSX.js +1 -0
  42. package/dist/owletto/dist/assets/{agents-workbench-BuIaYVFK.js → agents-workbench-BojDv6gX.js} +1 -1
  43. package/dist/owletto/dist/assets/{app._appId-BULz-FRp.js → app._appId-DNNB5FaI.js} +1 -1
  44. package/dist/owletto/dist/assets/{automation-detail-content-Ck6YhKpX.js → automation-detail-content-CzqrHc4P.js} +1 -1
  45. package/dist/owletto/dist/assets/automations-C9x76gSX.js +1 -0
  46. package/dist/owletto/dist/assets/{calendar-BZSx-Jno.js → calendar-VAaxHxss.js} +1 -1
  47. package/dist/owletto/dist/assets/{callback-DTbt2OS1.js → callback-0VB9tUCF.js} +1 -1
  48. package/dist/owletto/dist/assets/{card-BsWGRkun.js → card-HMQT7vU5.js} +1 -1
  49. package/dist/owletto/dist/assets/{claim-6BXg-jBt.js → claim-C2-YTMw-.js} +1 -1
  50. package/dist/owletto/dist/assets/{clients-CJI4gT-V.js → clients-C0I3V7XE.js} +1 -1
  51. package/dist/owletto/dist/assets/{code-editor-C104Bzj2.js → code-editor-hOZHdlxM.js} +1 -1
  52. package/dist/owletto/dist/assets/connect-DSr_gD8x.js +1 -0
  53. package/dist/owletto/dist/assets/connect._clientId-CTamwGrw.js +1 -0
  54. package/dist/owletto/dist/assets/{connected._clientId-L6cpG1ip.js → connected._clientId-BFuU4-8j.js} +1 -1
  55. package/dist/owletto/dist/assets/{connection-CqXJ7EAc.js → connection-De_2AD46.js} +1 -1
  56. package/dist/owletto/dist/assets/{connection-feed-detail-DgZF0nux.js → connection-feed-detail-Cbn85fG9.js} +1 -1
  57. package/dist/owletto/dist/assets/{connector-provenance-DyEHCwrM.js → connector-provenance-B17-ze5S.js} +1 -1
  58. package/dist/owletto/dist/assets/{connectors-zM9Yv-LM.js → connectors-KnNED_-4.js} +1 -1
  59. package/dist/owletto/dist/assets/{consent-CvL2QShm.js → consent-BOYb4pNu.js} +1 -1
  60. package/dist/owletto/dist/assets/{core.esm-DUExfZp5.js → core.esm-COW6Pfy6.js} +1 -1
  61. package/dist/owletto/dist/assets/{create-BiERXyJD.js → create-BFpUZ_mU.js} +1 -1
  62. package/dist/owletto/dist/assets/create-CblXKFGZ.js +1 -0
  63. package/dist/owletto/dist/assets/create-ChUbSYvl.js +1 -0
  64. package/dist/owletto/dist/assets/create-automation-form-CRenA7Ix.js +1 -0
  65. package/dist/owletto/dist/assets/{create._connectorKey-DWUsdgk7.js → create._connectorKey-D4dIDQIQ.js} +1 -1
  66. package/dist/owletto/dist/assets/{cronstrue-Bmga7mGH.js → cronstrue-BrlFh5Jy.js} +1 -1
  67. package/dist/owletto/dist/assets/deployments-DTFrUY7p.js +1 -0
  68. package/dist/owletto/dist/assets/{deployments-body-Cw9tB9-c.js → deployments-body-CXqfjLqj.js} +1 -1
  69. package/dist/owletto/dist/assets/{device-Dy4u9FiS.js → device-B0BBIdVx.js} +1 -1
  70. package/dist/owletto/dist/assets/{device-pin-tombstone-CmAxFq2z.js → device-pin-tombstone-BBYes4en.js} +1 -1
  71. package/dist/owletto/dist/assets/{device-rows-CVv5-okl.js → device-rows-E63OZ9Cp.js} +1 -1
  72. package/dist/owletto/dist/assets/{device._deviceId-DNKPNnE2.js → device._deviceId-JN0cUCGe.js} +1 -1
  73. package/dist/owletto/dist/assets/{entity-options-C5Mj2ZVk.js → entity-options-qan9-Ycm.js} +1 -1
  74. package/dist/owletto/dist/assets/{entity-page-BdTxty8B.js → entity-page-CozUOlVP.js} +1 -1
  75. package/dist/owletto/dist/assets/{entity-type-page-jhiER8wM.js → entity-type-page-xISySjVW.js} +1 -1
  76. package/dist/owletto/dist/assets/{events-feed-CEQj2uAu.js → events-feed-DmZ3Ig3X.js} +1 -1
  77. package/dist/owletto/dist/assets/{full-page-spinner-BSp5F0ls.js → full-page-spinner-Q_J5Wcop.js} +1 -1
  78. package/dist/owletto/dist/assets/guardrails-BB9iOxE3.js +1 -0
  79. package/dist/owletto/dist/assets/identity-DYbfG4hU.js +1 -0
  80. package/dist/owletto/dist/assets/index-7d9B918E.js +1 -0
  81. package/dist/owletto/dist/assets/{index-C2YGEKPo.js → index-BKZMzuMS.js} +7 -7
  82. package/dist/owletto/dist/assets/index-BsDA0XzK.js +1 -0
  83. package/dist/owletto/dist/assets/{index-1D5YJuZt.js → index-BwN9pHNs.js} +1 -1
  84. package/dist/owletto/dist/assets/{index-DFD8r981.js → index-BwVojwkg.js} +1 -1
  85. package/dist/owletto/dist/assets/index-C4Lz_gB-.js +1 -0
  86. package/dist/owletto/dist/assets/{index-BO8P4P_v.js → index-C78ucWDF.js} +1 -1
  87. package/dist/owletto/dist/assets/{index-D6nIYLM-.js → index-C9Dtjaoi.js} +1 -1
  88. package/dist/owletto/dist/assets/{index-CKWRiFJL.js → index-CGx4og7r.js} +1 -1
  89. package/dist/owletto/dist/assets/index-CO65Rkad.js +1 -0
  90. package/dist/owletto/dist/assets/index-CT_kxGkR.js +1 -0
  91. package/dist/owletto/dist/assets/index-ChcQMdod.css +1 -0
  92. package/dist/owletto/dist/assets/index-CrKgNtiq.js +1 -0
  93. package/dist/owletto/dist/assets/{index-CLQ-2wO3.js → index-DLZbFRSM.js} +1 -1
  94. package/dist/owletto/dist/assets/index-DUIbfL6x.js +1 -0
  95. package/dist/owletto/dist/assets/{index-DtRraJyI.js → index-DmB-3GhU.js} +1 -1
  96. package/dist/owletto/dist/assets/{index-CyT-Rwip.js → index-pKfsEvLt.js} +1 -1
  97. package/dist/owletto/dist/assets/{json-diff-gsOHOgl7.js → json-diff-1FNS_wGA.js} +1 -1
  98. package/dist/owletto/dist/assets/{list-skeleton-Cs18bNnk.js → list-skeleton-B6gjzr8t.js} +1 -1
  99. package/dist/owletto/dist/assets/login-S9EGV_EA.js +1 -0
  100. package/dist/owletto/dist/assets/{logout-DKUiKENJ.js → logout-BOXPSr57.js} +1 -1
  101. package/dist/owletto/dist/assets/{member-scope-gate-g7uB6GYE.js → member-scope-gate-yGr4lrGD.js} +1 -1
  102. package/dist/owletto/dist/assets/{memory-browse-page-BUwnO2o2.js → memory-browse-page-5n3MvqdS.js} +2 -2
  103. package/dist/owletto/dist/assets/{model-selector-DfsEq1db.js → model-selector-9ZRlR7Sa.js} +1 -1
  104. package/dist/owletto/dist/assets/models-LOhfJ0sb.js +1 -0
  105. package/dist/owletto/dist/assets/{new-BWw3u5jE.js → new-BeZJOJgR.js} +1 -1
  106. package/dist/owletto/dist/assets/{new-CW9MfqPX.js → new-D4wlbvAZ.js} +1 -1
  107. package/dist/owletto/dist/assets/{new-BSo83s7P.js → new-Dxn1qrmS.js} +1 -1
  108. package/dist/owletto/dist/assets/{oauth-workspace-access-DM3uXXPM.js → oauth-workspace-access-DoE-9F42.js} +1 -1
  109. package/dist/owletto/dist/assets/{organization-DJtG7bUJ.js → organization-BezNEJK7.js} +1 -1
  110. package/dist/owletto/dist/assets/{permissions-DcYSiYWQ.js → permissions-GkKtC6a5.js} +1 -1
  111. package/dist/owletto/dist/assets/{proposal-review-shell-CLrF2OFP.js → proposal-review-shell-Bk9D_9YN.js} +1 -1
  112. package/dist/owletto/dist/assets/{recent-BAuh77AP.js → recent-BVvscz1V.js} +1 -1
  113. package/dist/owletto/dist/assets/{renderer-BdAH16jE.js → renderer-CAyr3B3s.js} +2 -2
  114. package/dist/owletto/dist/assets/reset-password-atCMI5uQ.js +1 -0
  115. package/dist/owletto/dist/assets/{runs-tK0NlrM5.js → runs-CftQDTkq.js} +1 -1
  116. package/dist/owletto/dist/assets/runs-panel-BkRtr_C4.js +1 -0
  117. package/dist/owletto/dist/assets/{runs-table-BQACrHq5.js → runs-table-CWCl38L5.js} +1 -1
  118. package/dist/owletto/dist/assets/{schema-value-normalization-Dr5Osu6u.js → schema-value-normalization-C9Lm83-q.js} +1 -1
  119. package/dist/owletto/dist/assets/settings-BKMOjfYf.js +1 -0
  120. package/dist/owletto/dist/assets/{settings-D9ezdxp8.js → settings-CgTgofgd.js} +1 -1
  121. package/dist/owletto/dist/assets/skills-DWr8qR3U.js +1 -0
  122. package/dist/owletto/dist/assets/{switch-C1vQiKIo.js → switch-BOGbkDQb.js} +1 -1
  123. package/dist/owletto/dist/assets/{use-mention-search-CCqN_8wM.js → use-mention-search-C9ckRw0s.js} +2 -2
  124. package/dist/owletto/dist/favicon.ico +0 -0
  125. package/dist/owletto/dist/favicon.svg +5 -6
  126. package/dist/owletto/dist/fonts/dm-mono-latin-500-normal.woff2 +0 -0
  127. package/dist/owletto/dist/fonts/dm-sans-latin-400-normal.woff2 +0 -0
  128. package/dist/owletto/dist/fonts/dm-sans-latin-600-normal.woff2 +0 -0
  129. package/dist/owletto/dist/index.html +8 -8
  130. package/dist/owletto/dist/lobu-logo.svg +16 -0
  131. package/dist/server-main.bundle.mjs +2415 -1268
  132. package/npm-shrinkwrap.json +17 -17
  133. package/package.json +1 -1
  134. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  135. package/vendor/connector-sdk/dist/logger.js +4 -1
  136. package/vendor/connector-sdk/dist/reaction-sdk.d.ts +9 -0
  137. package/vendor/connector-sdk/package.json +1 -1
  138. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +16 -0
  139. package/vendor/core/dist/contracts/tools/manage-automations.js +12 -3
  140. package/vendor/core/dist/contracts/worker/protocol.d.ts +9 -0
  141. package/vendor/core/dist/contracts/worker/protocol.js +10 -1
  142. package/vendor/core/dist/logger.js +4 -2
  143. package/vendor/core/package.json +1 -1
  144. package/dist/owletto/dist/assets/_-BjTOSrPW.js +0 -1
  145. package/dist/owletto/dist/assets/_agentId-E5FuvQ_W.js +0 -1
  146. package/dist/owletto/dist/assets/_name-Ca5sRv2h.js +0 -1
  147. package/dist/owletto/dist/assets/_skillKey-BnDO8aEk.js +0 -1
  148. package/dist/owletto/dist/assets/accept-invitation-tMqF2W59.js +0 -1
  149. package/dist/owletto/dist/assets/activity-route-view-DSJj0TBg.js +0 -1
  150. package/dist/owletto/dist/assets/agent-permissions-matrix-QvA6xL8Q.js +0 -1
  151. package/dist/owletto/dist/assets/agents-DztpCplG.js +0 -1
  152. package/dist/owletto/dist/assets/automations-DztpCplG.js +0 -1
  153. package/dist/owletto/dist/assets/connect-9tegWawc.js +0 -1
  154. package/dist/owletto/dist/assets/connect._clientId-Dh6e0n6A.js +0 -1
  155. package/dist/owletto/dist/assets/create-BL_WcDoF.js +0 -1
  156. package/dist/owletto/dist/assets/create-Dyz5QbON.js +0 -1
  157. package/dist/owletto/dist/assets/create-automation-form-DCYFtK4q.js +0 -1
  158. package/dist/owletto/dist/assets/deployments-h8jIWEVy.js +0 -1
  159. package/dist/owletto/dist/assets/guardrails-DrOhJHr5.js +0 -1
  160. package/dist/owletto/dist/assets/identity-BTE8ZlL9.js +0 -1
  161. package/dist/owletto/dist/assets/index-Be4XiWxU.js +0 -1
  162. package/dist/owletto/dist/assets/index-CPqabIYs.css +0 -1
  163. package/dist/owletto/dist/assets/index-CS1UPepo.js +0 -1
  164. package/dist/owletto/dist/assets/index-DGinfBZr.js +0 -1
  165. package/dist/owletto/dist/assets/index-DJs1EEbu.js +0 -1
  166. package/dist/owletto/dist/assets/index-DZb_utnT.js +0 -1
  167. package/dist/owletto/dist/assets/index-RH7aiqHs.js +0 -1
  168. package/dist/owletto/dist/assets/index-xwlLZWva.js +0 -1
  169. package/dist/owletto/dist/assets/login-B3RTCs3p.js +0 -1
  170. package/dist/owletto/dist/assets/models-CZZt4VcZ.js +0 -1
  171. package/dist/owletto/dist/assets/reset-password-DjgDJAYG.js +0 -1
  172. package/dist/owletto/dist/assets/runs-panel-Dqq-0G9H.js +0 -1
  173. package/dist/owletto/dist/assets/settings-DZifZxa5.js +0 -1
  174. package/dist/owletto/dist/assets/skills-CNtoLPU_.js +0 -1
  175. package/dist/owletto/dist/fonts/geist-pixel-square.woff2 +0 -0
  176. package/dist/owletto/dist/fonts/inter-latin-400-normal.woff2 +0 -0
  177. package/dist/owletto/dist/fonts/inter-latin-500-normal.woff2 +0 -0
  178. package/dist/owletto/dist/fonts/inter-latin-600-normal.woff2 +0 -0
  179. package/dist/owletto/dist/fonts/jizBRFtNs2ka5fXjeivQ4LroWlx-6zUTjnTLgNs.woff2 +0 -0
  180. package/dist/owletto/dist/fonts/jizBRFtNs2ka5fXjeivQ4LroWlx-6zsTjnTLgNuZ5w.woff2 +0 -0
  181. package/dist/owletto/dist/fonts/jizHRFtNs2ka5fXjeivQ4LroWlx-6zAjgn7Motmp5r61.woff2 +0 -0
  182. package/dist/owletto/dist/fonts/jizHRFtNs2ka5fXjeivQ4LroWlx-6zAjjH7Motmp5g.woff2 +0 -0
  183. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD0OwGtT0rU3BE.woff2 +0 -0
  184. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD1OwGtT0rU3BE.woff2 +0 -0
  185. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD2OwGtT0rU3BE.woff2 +0 -0
  186. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD4OwGtT0rU3BE.woff2 +0 -0
  187. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD7OwGtT0rU.woff2 +0 -0
  188. package/dist/owletto/dist/fonts/tDbV2o-flEEny0FZhsfKu5WU4xD_OwGtT0rU3BE.woff2 +0 -0
  189. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-Cw2nSGjW7BDEAQ.woff2 +0 -0
  190. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-Cw6nSGjW7BDEAQ.woff2 +0 -0
  191. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-CwCnSGjW7BDEAQ.woff2 +0 -0
  192. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-CwOnSGjW7BA.woff2 +0 -0
  193. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-CwenSGjW7BDEAQ.woff2 +0 -0
  194. package/dist/owletto/dist/fonts/tDbX2o-flEEny0FZhsfKu5WU4xD-CwynSGjW7BDEAQ.woff2 +0 -0
@@ -1 +1 @@
1
- import{dc as i,fq as y,an as d,eJ as c,ag as g,cE as m,j as a,c7 as j,c8 as w,bm as N,gn as f,B as $,x as p,L as x,go as b,af as r}from"./index-C2YGEKPo.js";function o(e,t=""){return`${g}/api/${e}/deployments${t}`}const v=50;function S(){const{slug:e}=i();return y({queryKey:["deployments-feed",e],queryFn:async({pageParam:t})=>{const n=new URLSearchParams({limit:String(v)});t!==null&&n.set("before_id",String(t));const s=await d(o(e,`?${n.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await c(s,"Failed to fetch deployments"),await s.json())},initialPageParam:null,getNextPageParam:t=>t.has_more?t.items[t.items.length-1]?.id:void 0,enabled:!!e,staleTime:15e3,retry:!1})}function T(e){const{slug:t}=i();return m({queryKey:["deployment-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch deployment"),await n.json())},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function q(e){const{slug:t}=i();return m({queryKey:["deployment-change-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/changes/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch change"),(await n.json()).change)},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function B(e){return e==="partial_failure"?a.jsx(r,{variant:"destructive",children:"Partial failure"}):e==="succeeded"?a.jsx(r,{variant:"secondary",children:"Succeeded"}):null}function D(e){switch(e){case"created":return a.jsx(r,{variant:"default",children:"Created"});case"updated":return a.jsx(r,{variant:"secondary",children:"Updated"});case"deleted":return a.jsx(r,{variant:"destructive",children:"Deleted"});default:return null}}function P(e){if(!e)return null;const t=[e.create?`${e.create} created`:null,e.update?`${e.update} updated`:null,e.delete?`${e.delete} deleted`:null].filter(n=>n!==null);return t.length>0?t.join(" · "):"no changes"}const h="flex items-start gap-3 px-3 py-2.5 transition-colors hover:bg-accent/50";function E({owner:e}){const t=S(),n=t.data?.pages.flatMap(s=>s.items)??[];return t.isLoading?a.jsx("div",{className:"max-w-3xl",children:a.jsx(j,{label:"deployments"})}):t.isError?a.jsx(w,{label:"deployments"}):n.length===0?a.jsx(N,{icon:f,title:"No deployments yet",description:"lobu apply runs and settings edits will appear here as an audit trail."}):a.jsxs("div",{className:"max-w-3xl space-y-3",children:[a.jsx("div",{className:"overflow-hidden rounded-lg border",children:n.map((s,l)=>{const u=l===n.length-1;return s.type==="deployment"?a.jsx(F,{item:s,owner:e,isLast:u},s.id):a.jsx(L,{item:s,owner:e,isLast:u},s.id)})}),t.hasNextPage?a.jsx($,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:t.isFetchingNextPage,onClick:()=>t.fetchNextPage(),children:t.isFetchingNextPage?"Loading...":"Load more"}):null]})}function F({item:e,owner:t,isLast:n}){const l=[P(e.counts),e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:e.applyId??String(e.id)},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(f,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"truncate text-sm font-medium",children:"Deployment"}),B(e.status),e.gitSha?a.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.gitSha.slice(0,7)}):null]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:l})]})]})}function L({item:e,owner:t,isLast:n}){const s=[e.actorSource?`via ${e.actorSource}`:null,e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:`change-${e.id}`},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(b,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("span",{className:"truncate text-sm font-medium",children:[e.resourceKind??"config",e.resourceId?a.jsxs("span",{className:"text-muted-foreground",children:[" ",e.resourceId]}):null]}),D(e.op)]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s})]})]})}export{E as D,q as a,D as c,B as d,T as u};
1
+ import{dc as i,fq as y,an as d,eJ as c,ag as g,cE as m,j as a,c7 as j,c8 as w,bm as N,gn as f,B as $,x as p,L as x,go as b,af as r}from"./index-BKZMzuMS.js";function o(e,t=""){return`${g}/api/${e}/deployments${t}`}const v=50;function S(){const{slug:e}=i();return y({queryKey:["deployments-feed",e],queryFn:async({pageParam:t})=>{const n=new URLSearchParams({limit:String(v)});t!==null&&n.set("before_id",String(t));const s=await d(o(e,`?${n.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await c(s,"Failed to fetch deployments"),await s.json())},initialPageParam:null,getNextPageParam:t=>t.has_more?t.items[t.items.length-1]?.id:void 0,enabled:!!e,staleTime:15e3,retry:!1})}function T(e){const{slug:t}=i();return m({queryKey:["deployment-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch deployment"),await n.json())},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function q(e){const{slug:t}=i();return m({queryKey:["deployment-change-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/changes/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch change"),(await n.json()).change)},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function B(e){return e==="partial_failure"?a.jsx(r,{variant:"destructive",children:"Partial failure"}):e==="succeeded"?a.jsx(r,{variant:"secondary",children:"Succeeded"}):null}function D(e){switch(e){case"created":return a.jsx(r,{variant:"default",children:"Created"});case"updated":return a.jsx(r,{variant:"secondary",children:"Updated"});case"deleted":return a.jsx(r,{variant:"destructive",children:"Deleted"});default:return null}}function P(e){if(!e)return null;const t=[e.create?`${e.create} created`:null,e.update?`${e.update} updated`:null,e.delete?`${e.delete} deleted`:null].filter(n=>n!==null);return t.length>0?t.join(" · "):"no changes"}const h="flex items-start gap-3 px-3 py-2.5 transition-colors hover:bg-accent/50";function E({owner:e}){const t=S(),n=t.data?.pages.flatMap(s=>s.items)??[];return t.isLoading?a.jsx("div",{className:"max-w-3xl",children:a.jsx(j,{label:"deployments"})}):t.isError?a.jsx(w,{label:"deployments"}):n.length===0?a.jsx(N,{icon:f,title:"No deployments yet",description:"lobu apply runs and settings edits will appear here as an audit trail."}):a.jsxs("div",{className:"max-w-3xl space-y-3",children:[a.jsx("div",{className:"overflow-hidden rounded-lg border",children:n.map((s,l)=>{const u=l===n.length-1;return s.type==="deployment"?a.jsx(F,{item:s,owner:e,isLast:u},s.id):a.jsx(L,{item:s,owner:e,isLast:u},s.id)})}),t.hasNextPage?a.jsx($,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:t.isFetchingNextPage,onClick:()=>t.fetchNextPage(),children:t.isFetchingNextPage?"Loading...":"Load more"}):null]})}function F({item:e,owner:t,isLast:n}){const l=[P(e.counts),e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:e.applyId??String(e.id)},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(f,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"truncate text-sm font-medium",children:"Deployment"}),B(e.status),e.gitSha?a.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.gitSha.slice(0,7)}):null]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:l})]})]})}function L({item:e,owner:t,isLast:n}){const s=[e.actorSource?`via ${e.actorSource}`:null,e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:`change-${e.id}`},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(b,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("span",{className:"truncate text-sm font-medium",children:[e.resourceKind??"config",e.resourceId?a.jsxs("span",{className:"text-muted-foreground",children:[" ",e.resourceId]}):null]}),D(e.op)]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s})]})]})}export{E as D,q as a,D as c,B as d,T as u};
@@ -1 +1 @@
1
- import{ae as pe,Y as he,r as n,j as e,ab as me,B as A,af as H,ag as ee}from"./index-C2YGEKPo.js";import{s as fe,g as ge,u as xe,a as ve,b as ye,A as we,W as je}from"./oauth-workspace-access-DM3uXXPM.js";import{C as J,a as K,b as Q,d as X,c as be}from"./card-BsWGRkun.js";async function ke(r){const a=await fetch(`${ee}/oauth/device/info?user_code=${encodeURIComponent(r)}`,{credentials:"include"}),N=await a.json().catch(()=>null);return{response:a,data:N}}function Z(r,a){return typeof r?.error_description=="string"&&r.error_description||typeof r?.error=="string"&&r.error||a}function Ne(){const r=pe.useSearch(),{session:a,isReady:N}=he(),w=!N,[z,se]=n.useState(r.user_code||""),[o,m]=n.useState(null),[D,i]=n.useState(null),[f,re]=n.useState(null),[P,R]=n.useState(null),[_,L]=n.useState(null),[E,U]=n.useState(!1),u=n.useRef(0),g=r.return_to,O=g?"app":"terminal",te=!!r.user_code,j=z.trim().toUpperCase(),l=P?.code===j?P:null,d=l!==null,x=l?.scopes??[],ne=n.useMemo(()=>fe(x,_),[_,x]),M=x.some(s=>s.startsWith("mcp:")),b=x.includes("device_worker:run"),oe=x.includes("connections:token"),T=b||oe,k=ge(l?.resource),v=d&&M&&!k,I=l?.multiWorkspaceGrantsEnabled===!0,{orgList:F,workspaceAccess:ce,setWorkspaceAccess:ae,selectedOrgIds:B,toggleSelectedOrgId:ie,resetWorkspaceSelection:le,personalOrgId:de,orgsLoading:W,orgsError:C,retryOrgs:V,workspaceSelectionReady:ue}=xe({requirePersonal:v&&b,allowMultiple:I}),p=F.find(s=>s.id===de)??null,S=d&&b&&!k,$=v?ue:!S||!W&&!C&&p!==null,q=n.useCallback(async s=>{const h=++u.current;m("verify"),i(null),U(!1);try{const{response:t,data:c}=await ke(s);if(h!==u.current)return;if(t.status===401){const G=new URL("/auth/login",window.location.origin);G.searchParams.set("callbackUrl",window.location.href),window.location.href=G.toString();return}if(!t.ok||!c)throw new Error(Z(c,"Failed to verify device authorization code"));const y=Array.isArray(c.scopes)?c.scopes:[];R({code:s,clientName:c.client_name??null,scopes:y,resource:typeof c.resource=="string"?c.resource:null,multiWorkspaceGrantsEnabled:c.multi_workspace_grants_enabled===!0}),L(ve(y))}catch(t){if(h!==u.current)return;R(null),i(t instanceof Error?t.message:"Unexpected error")}finally{h===u.current&&m(null)}},[]);ye(!!a,w),n.useEffect(()=>{if(!(w||!a||!r.user_code))return q(r.user_code.trim().toUpperCase()),()=>{u.current+=1}},[a,w,r.user_code,q]);const Y=async s=>{const h=j;if(!h){i(`Please enter the code shown in your ${O}.`);return}if(!d){i("Verify the device code before approving or denying access.");return}if(s&&T&&!E){i("Confirm that you initiated this request and that the device code matches.");return}if(s&&!$){i(C?"Workspaces could not be loaded. Retry before approving.":S&&!p?"Your personal workspace is required before this device can be approved.":"Choose at least one workspace before approving.");return}m(s?"approve":"deny"),i(null);try{const t=await fetch(`${ee}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:h,approved:s,...s?{scope:ne.join(" ")}:{},...s&&v?{workspace_access:ce,organization_ids:B}:{},...s&&S&&p?{organization_id:p.id}:{}})}),c=await t.json().catch(()=>null);if(t.status===401){const y=new URL("/auth/login",window.location.origin);y.searchParams.set("callbackUrl",window.location.href),window.location.href=y.toString();return}if(!t.ok)throw new Error(Z(c,"Failed to process device authorization"));re(s?"approved":"denied")}catch(t){m(null),i(t instanceof Error?t.message:"Unexpected error")}};return n.useEffect(()=>{if(f!=="approved"||!g)return;const s=window.setTimeout(()=>{window.location.href=g},600);return()=>window.clearTimeout(s)},[f,g]),w||!a?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking authentication..."})}):f?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsx(J,{className:"w-full max-w-lg",children:e.jsxs(K,{children:[e.jsx(Q,{children:f==="approved"?te?"Access Authorized":"Device Authorized":"Authorization Denied"}),e.jsx(X,{children:f==="approved"?g?"Returning you to the app...":"You can close this tab and return to your terminal.":"The device was not authorized. You can close this tab."})]})})}):e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(J,{className:"w-full max-w-lg",children:[e.jsxs(K,{children:[e.jsx(Q,{asChild:!0,children:e.jsx("h1",{children:d?"Authorize application":"Connect a device"})}),e.jsx(X,{children:d?"Review the application, access level, and workspaces.":`Enter the code shown in your ${O}.`})]}),e.jsxs(be,{className:"space-y-5","aria-busy":o!==null,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"user-code",className:"text-sm font-medium",children:"Device code"}),e.jsx(me,{id:"user-code",value:z,disabled:o==="approve"||o==="deny",onChange:s=>{u.current+=1,se(s.target.value.toUpperCase()),R(null),L(null),le(),U(!1),m(null),i(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!r.user_code})]}),l&&e.jsx(we,{idPrefix:"oauth-device",clientName:l.clientName,requestedScopes:l.scopes,accessLevel:_,onAccessLevelChange:L,sensitiveScopesAcknowledged:E,onSensitiveScopesAcknowledgedChange:U,disabled:o!==null}),v&&e.jsx(je,{idPrefix:"oauth-device",allowMultiple:I,orgList:F,selectedOrgIds:B,onWorkspaceAccessChange:ae,onSelectedOrgChange:ie,orgsLoading:W,orgsError:C,onRetry:V,disabled:o!==null,personalRequired:b}),d&&M&&k&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["Workspace access: only ",k]}),e.jsx("p",{className:"text-muted-foreground",children:"This request is fixed to the workspace in the MCP resource URL."})]}),S&&!v&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-2",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Device home"}),W?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your personal workspace..."}):C?e.jsxs("div",{role:"alert",className:"space-y-2 text-destructive",children:[e.jsx("p",{children:"Workspaces could not be loaded. Approval is unavailable until they load."}),e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:V,children:"Retry"})]}):p?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:p.name}),e.jsx(H,{variant:"outline",children:"Personal"}),e.jsx(H,{variant:"secondary",children:"Required"})]}),e.jsx("p",{className:"text-muted-foreground",children:"Device data stays in your personal workspace."})]}):e.jsx("p",{role:"alert",className:"text-destructive",children:"A personal workspace is required to authorize this device."})]}),D&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx("div",{className:"flex items-center justify-end gap-3",children:d?e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"button",variant:"outline",onClick:()=>Y(!1),disabled:o!==null,children:o==="deny"?"Denying...":"Deny"}),e.jsx(A,{type:"button",onClick:()=>Y(!0),disabled:o!==null||!$||T&&!E,children:o==="approve"?"Approving...":"Approve"})]}):e.jsx(A,{type:"button",onClick:()=>q(j),disabled:o!==null||!j,children:o==="verify"?"Verifying...":"Continue"})})]})]})})}export{Ne as component};
1
+ import{ae as pe,Y as he,r as n,j as e,ab as me,B as A,af as H,ag as ee}from"./index-BKZMzuMS.js";import{s as fe,g as ge,u as xe,a as ve,b as ye,A as we,W as je}from"./oauth-workspace-access-DoE-9F42.js";import{C as J,a as K,b as Q,d as X,c as be}from"./card-HMQT7vU5.js";async function ke(r){const a=await fetch(`${ee}/oauth/device/info?user_code=${encodeURIComponent(r)}`,{credentials:"include"}),N=await a.json().catch(()=>null);return{response:a,data:N}}function Z(r,a){return typeof r?.error_description=="string"&&r.error_description||typeof r?.error=="string"&&r.error||a}function Ne(){const r=pe.useSearch(),{session:a,isReady:N}=he(),w=!N,[z,se]=n.useState(r.user_code||""),[o,m]=n.useState(null),[D,i]=n.useState(null),[f,re]=n.useState(null),[P,R]=n.useState(null),[_,L]=n.useState(null),[E,U]=n.useState(!1),u=n.useRef(0),g=r.return_to,O=g?"app":"terminal",te=!!r.user_code,j=z.trim().toUpperCase(),l=P?.code===j?P:null,d=l!==null,x=l?.scopes??[],ne=n.useMemo(()=>fe(x,_),[_,x]),M=x.some(s=>s.startsWith("mcp:")),b=x.includes("device_worker:run"),oe=x.includes("connections:token"),T=b||oe,k=ge(l?.resource),v=d&&M&&!k,I=l?.multiWorkspaceGrantsEnabled===!0,{orgList:F,workspaceAccess:ce,setWorkspaceAccess:ae,selectedOrgIds:B,toggleSelectedOrgId:ie,resetWorkspaceSelection:le,personalOrgId:de,orgsLoading:W,orgsError:C,retryOrgs:V,workspaceSelectionReady:ue}=xe({requirePersonal:v&&b,allowMultiple:I}),p=F.find(s=>s.id===de)??null,S=d&&b&&!k,$=v?ue:!S||!W&&!C&&p!==null,q=n.useCallback(async s=>{const h=++u.current;m("verify"),i(null),U(!1);try{const{response:t,data:c}=await ke(s);if(h!==u.current)return;if(t.status===401){const G=new URL("/auth/login",window.location.origin);G.searchParams.set("callbackUrl",window.location.href),window.location.href=G.toString();return}if(!t.ok||!c)throw new Error(Z(c,"Failed to verify device authorization code"));const y=Array.isArray(c.scopes)?c.scopes:[];R({code:s,clientName:c.client_name??null,scopes:y,resource:typeof c.resource=="string"?c.resource:null,multiWorkspaceGrantsEnabled:c.multi_workspace_grants_enabled===!0}),L(ve(y))}catch(t){if(h!==u.current)return;R(null),i(t instanceof Error?t.message:"Unexpected error")}finally{h===u.current&&m(null)}},[]);ye(!!a,w),n.useEffect(()=>{if(!(w||!a||!r.user_code))return q(r.user_code.trim().toUpperCase()),()=>{u.current+=1}},[a,w,r.user_code,q]);const Y=async s=>{const h=j;if(!h){i(`Please enter the code shown in your ${O}.`);return}if(!d){i("Verify the device code before approving or denying access.");return}if(s&&T&&!E){i("Confirm that you initiated this request and that the device code matches.");return}if(s&&!$){i(C?"Workspaces could not be loaded. Retry before approving.":S&&!p?"Your personal workspace is required before this device can be approved.":"Choose at least one workspace before approving.");return}m(s?"approve":"deny"),i(null);try{const t=await fetch(`${ee}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:h,approved:s,...s?{scope:ne.join(" ")}:{},...s&&v?{workspace_access:ce,organization_ids:B}:{},...s&&S&&p?{organization_id:p.id}:{}})}),c=await t.json().catch(()=>null);if(t.status===401){const y=new URL("/auth/login",window.location.origin);y.searchParams.set("callbackUrl",window.location.href),window.location.href=y.toString();return}if(!t.ok)throw new Error(Z(c,"Failed to process device authorization"));re(s?"approved":"denied")}catch(t){m(null),i(t instanceof Error?t.message:"Unexpected error")}};return n.useEffect(()=>{if(f!=="approved"||!g)return;const s=window.setTimeout(()=>{window.location.href=g},600);return()=>window.clearTimeout(s)},[f,g]),w||!a?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking authentication..."})}):f?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsx(J,{className:"w-full max-w-lg",children:e.jsxs(K,{children:[e.jsx(Q,{children:f==="approved"?te?"Access Authorized":"Device Authorized":"Authorization Denied"}),e.jsx(X,{children:f==="approved"?g?"Returning you to the app...":"You can close this tab and return to your terminal.":"The device was not authorized. You can close this tab."})]})})}):e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(J,{className:"w-full max-w-lg",children:[e.jsxs(K,{children:[e.jsx(Q,{asChild:!0,children:e.jsx("h1",{children:d?"Authorize application":"Connect a device"})}),e.jsx(X,{children:d?"Review the application, access level, and workspaces.":`Enter the code shown in your ${O}.`})]}),e.jsxs(be,{className:"space-y-5","aria-busy":o!==null,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"user-code",className:"text-sm font-medium",children:"Device code"}),e.jsx(me,{id:"user-code",value:z,disabled:o==="approve"||o==="deny",onChange:s=>{u.current+=1,se(s.target.value.toUpperCase()),R(null),L(null),le(),U(!1),m(null),i(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!r.user_code})]}),l&&e.jsx(we,{idPrefix:"oauth-device",clientName:l.clientName,requestedScopes:l.scopes,accessLevel:_,onAccessLevelChange:L,sensitiveScopesAcknowledged:E,onSensitiveScopesAcknowledgedChange:U,disabled:o!==null}),v&&e.jsx(je,{idPrefix:"oauth-device",allowMultiple:I,orgList:F,selectedOrgIds:B,onWorkspaceAccessChange:ae,onSelectedOrgChange:ie,orgsLoading:W,orgsError:C,onRetry:V,disabled:o!==null,personalRequired:b}),d&&M&&k&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["Workspace access: only ",k]}),e.jsx("p",{className:"text-muted-foreground",children:"This request is fixed to the workspace in the MCP resource URL."})]}),S&&!v&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-2",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Device home"}),W?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your personal workspace..."}):C?e.jsxs("div",{role:"alert",className:"space-y-2 text-destructive",children:[e.jsx("p",{children:"Workspaces could not be loaded. Approval is unavailable until they load."}),e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:V,children:"Retry"})]}):p?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:p.name}),e.jsx(H,{variant:"outline",children:"Personal"}),e.jsx(H,{variant:"secondary",children:"Required"})]}),e.jsx("p",{className:"text-muted-foreground",children:"Device data stays in your personal workspace."})]}):e.jsx("p",{role:"alert",className:"text-destructive",children:"A personal workspace is required to authorize this device."})]}),D&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx("div",{className:"flex items-center justify-end gap-3",children:d?e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"button",variant:"outline",onClick:()=>Y(!1),disabled:o!==null,children:o==="deny"?"Denying...":"Deny"}),e.jsx(A,{type:"button",onClick:()=>Y(!0),disabled:o!==null||!$||T&&!E,children:o==="approve"?"Approving...":"Approve"})]}):e.jsx(A,{type:"button",onClick:()=>q(j),disabled:o!==null||!j,children:o==="verify"?"Verifying...":"Continue"})})]})]})})}export{Ne as component};
@@ -1 +1 @@
1
- import{j as e,cr as C,n as w,h9 as k,r as x,s as b,bm as F,ha as v,B as u,hb as L,x as A,bw as S,aj as I,aS as P,hc as y,aD as R,hd as E,he as $,fi as _,L as O,P as z,b as B,hf as T,hg as D,J as K,hh as V,fk as q}from"./index-C2YGEKPo.js";import{a as M,R as H}from"./runs-panel-Dqq-0G9H.js";import{S as J,g as U,c as N,b as X,d as G}from"./runs-table-BQACrHq5.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(M,{}),e.jsx(C,{rows:s})]})}function Q(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function W({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=k(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),R("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const m=t.config?.folder_id;typeof m=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(m)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(b,{size:"lg"})}):i.length===0?e.jsx(F,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(u,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:I(P,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:Q(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${A(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(J,{status:U(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(S,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,m=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(E,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx($,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),m==="local.directory"&&e.jsx(W,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(u,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(O,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:m,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(X,{connection:s,ownerSlug:n,connectorKey:m,connectorDef:a})}):e.jsx(G,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(B,{connection:s}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(T,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(H,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=K(),{data:o=[],isLoading:c,isError:r}=V(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
1
+ import{j as e,cr as C,n as w,h9 as b,r as x,s as k,bm as F,ha as v,B as u,hb as L,x as A,bw as S,aj as I,aS as P,hc as y,aD as R,hd as E,he as $,fi as _,L as O,P as z,b as B,hf as T,hg as D,J as K,hh as V,fk as q}from"./index-BKZMzuMS.js";import{a as M,R as H}from"./runs-panel-BkRtr_C4.js";import{S as J,g as U,c as N,b as X,d as G}from"./runs-table-CWCl38L5.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(M,{}),e.jsx(C,{rows:s})]})}function Q(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function W({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=b(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),R("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const m=t.config?.folder_id;typeof m=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(m)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{size:"lg"})}):i.length===0?e.jsx(F,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(u,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:I(P,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:Q(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${A(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(J,{status:U(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(S,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,m=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(E,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx($,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),m==="local.directory"&&e.jsx(W,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(u,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(O,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:m,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(X,{connection:s,ownerSlug:n,connectorKey:m,connectorDef:a})}):e.jsx(G,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(B,{connection:s}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(T,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(H,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=K(),{data:o=[],isLoading:c,isError:r}=V(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
@@ -1 +1 @@
1
- import{d8 as u,fj as l,bq as f}from"./index-C2YGEKPo.js";function p(n){return l(n)&&n.required_capability!=="os.files"}const m={data:!1,chat:!1,actions:!1,audience:!1,inference:!1,runtime:!0};function d(n){return n==="macos"?"macOS":n==="ios"?"iOS":n==="chrome-extension"?"Chrome":n??"Unknown platform"}function y(n,c,o){const s=new Map(c.map(e=>[e.connector_key,e]));return n.map(e=>{const i={...m};for(const r of e.connectors){if(r.organization_slug!==o)continue;const a=s.get(r.connector_key);if(a?.connections.some(t=>t.id===r.connection_id))for(const t of Object.keys(i))i[t]||=a.facets[t]}return{device:e,facets:i,connector:{key:`device-row:${e.id}`,name:u(e),description:null,version:"",auth_schema:null,feeds_schema:null,actions_schema:null,options_schema:null,status:e.online?"active":"inactive",login_enabled:!1,installed:!0}}})}function b(n){const c=d(f(n)),o=n.connector_count,s=`${o} ${o===1?"connector":"connectors"}`;return[c,s,n.online?"online":"offline"].join(" · ")}export{y as b,p as c,b as d};
1
+ import{d8 as u,fj as l,bq as f}from"./index-BKZMzuMS.js";function p(n){return l(n)&&n.required_capability!=="os.files"}const m={data:!1,chat:!1,actions:!1,audience:!1,inference:!1,runtime:!0};function d(n){return n==="macos"?"macOS":n==="ios"?"iOS":n==="chrome-extension"?"Chrome":n??"Unknown platform"}function y(n,c,o){const s=new Map(c.map(e=>[e.connector_key,e]));return n.map(e=>{const i={...m};for(const r of e.connectors){if(r.organization_slug!==o)continue;const a=s.get(r.connector_key);if(a?.connections.some(t=>t.id===r.connection_id))for(const t of Object.keys(i))i[t]||=a.facets[t]}return{device:e,facets:i,connector:{key:`device-row:${e.id}`,name:u(e),description:null,version:"",auth_schema:null,feeds_schema:null,actions_schema:null,options_schema:null,status:e.online?"active":"inactive",login_enabled:!1,installed:!0}}})}function b(n){const c=d(f(n)),o=n.connector_count,s=`${o} ${o===1?"connector":"connectors"}`;return[c,s,n.online?"online":"offline"].join(" · ")}export{y as b,p as c,b as d};
@@ -1 +1 @@
1
- import{dI as K,h1 as O,j as e,fi as N,S as _,B as j,bq as E,L as w,dU as A,r as b,dz as F,dB as H,dC as V,a as q,a2 as U,bb as W,h2 as Y,h3 as G,h4 as J,b7 as Q,bc as P,h5 as X,h6 as Z,gH as ee,bF as se,g2 as ne,h7 as L,ab as te,d8 as R,s as $,bw as ae,H as ie,bp as ce,g3 as oe,g4 as re,x as le,h8 as B,aV as de}from"./index-C2YGEKPo.js";import{c as me,C as xe,R as ue}from"./device-pin-tombstone-CmAxFq2z.js";import{R as he}from"./runs-panel-Dqq-0G9H.js";import{S as pe,g as fe}from"./runs-table-BQACrHq5.js";import{c as ge}from"./connection-label-BobuYiAG.js";import{c as je}from"./device-rows-CVv5-okl.js";import"./runs-tK0NlrM5.js";function ve({device:t,organizationId:s,ownerSlug:r,selectedConnection:p,openSettings:u}){const{data:d=[],isLoading:g,isError:h,refetch:l}=K(s),c=new Map(d.map(i=>[i.key,i])),a=new Map,m=[];for(const i of t.connectors){if(i.organization_slug!==r)continue;const o=c.get(i.connector_key);if(!o||!je(o)){m.push(i);continue}const v=o.required_capability??`connector:${o.key}`,f=a.get(v)??{key:v,name:o.name,connections:[]};f.name=O[v]??o.name,f.connections.push(i),a.set(v,f)}return e.jsxs(e.Fragment,{children:[e.jsxs(N,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),t.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!s||g?e.jsx(_,{className:"h-24 w-full"}):h?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void l(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(i=>e.jsx(be,{group:i,deviceId:t.id,organizationId:s,ownerSlug:r,definitionsByKey:c,selectedConnection:p,openSettings:u},i.key))}),E(t)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),s&&m.length>0&&!g&&!h?e.jsxs(N,{title:"Connections",count:String(m.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:m.map(i=>e.jsxs(w,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:r,connectorKey:i.connector_key,connectionId:String(i.connection_id)},search:{},className:"flex items-center gap-3 py-3 text-sm hover:text-primary",children:[e.jsx("span",{className:"min-w-0 flex-1",children:i.display_name||c.get(i.connector_key)?.name||i.connector_key}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.status}),e.jsx(A,{className:"size-3.5 text-muted-foreground"})]},i.connection_id))})]}):null]})}function be({group:t,deviceId:s,organizationId:r,ownerSlug:p,definitionsByKey:u,selectedConnection:d,openSettings:g}){const h=t.connections.some(a=>a.connection_id===d),[l,c]=b.useState(h);return b.useEffect(()=>{h&&d!==void 0&&c(!0)},[h,d]),e.jsxs(F,{open:l,onOpenChange:c,children:[e.jsxs(H,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(A,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:t.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:t.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":t.connections.length>1?`${t.connections.length} connections`:"Configured"})]}),e.jsx(V,{forceMount:!0,hidden:!l,className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:t.connections.map(a=>e.jsx(Ne,{summary:a,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u.get(a.connector_key),openSettings:a.connection_id===d&&g},a.connection_id))})})]})}function Ne({summary:t,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u,openSettings:d}){const{data:g=[],isLoading:h,isError:l,refetch:c}=q(r,{connectionIds:[t.connection_id]}),a=g.find(o=>o.id===t.connection_id&&o.device_worker_id===s),m=u?.name??t.connector_key,i=a?me(a):null;return e.jsxs("section",{id:`connection-${t.connection_id}`,"aria-label":m,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:ge(a)}),e.jsx("span",{children:a.status})]}):null,h||!r?e.jsx(_,{className:"h-24 w-full"}):l?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void c(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[i?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:i}):null,e.jsx(xe,{connection:a,connectorDef:u,ownerSlug:p,openSettings:d,showActivity:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function _e({ownerSlug:t,deviceId:s,organizationId:r,selectedConnection:p,openSettings:u}){const d=U(),{data:g=[],isLoading:h}=W(),l=Y(),c=G(),[a,m]=b.useState(!1),[i,o]=b.useState(!1),[v,f]=b.useState(""),n=J(g,s),y=n?.id??s,{data:k=[]}=Q(r,{profileKind:"browser_session"}),C=b.useMemo(()=>k.filter(x=>x.device_worker_id===y&&x.status!=="revoked"),[k,y]),D=n?.label?.trim()??"";if(b.useEffect(()=>{i||f(D)},[D,i]),h)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"h-6 w-6 rounded"}),e.jsx(_,{className:"h-5 w-40"})]}),e.jsx(ue,{})]});if(!n)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const I=E(n),z=X(n.app_version),T=Z(n,z),S=()=>{const x=v.trim(),M=n.label?.trim()??"";if(x===M){o(!1);return}c.mutate({deviceWorkerId:n.id,label:x.length===0?null:x},{onSuccess:()=>o(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(ee,{header:e.jsx(ne,{breadcrumb:e.jsx(oe,{crumbs:[e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:re,children:"Connectors"},"connectors")]}),icon:e.jsx(ce,{platform:I,className:"h-5 w-5"}),title:i?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{"aria-label":"Device name",value:v,onChange:x=>f(x.target.value),placeholder:R({...n,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),a||S()):x.key==="Escape"&&(m(!1),f(n.label?.trim()??""),o(!1))}}),a?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",n.connector_count>0?`and un-pins ${n.connector_count} connector${n.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(j,{variant:"destructive",size:"sm",disabled:l.isPending,onClick:()=>l.mutate(n.id,{onSuccess:()=>{m(!1),d({to:"/$owner/connectors",params:{owner:t},search:{}})}}),children:[l.isPending?e.jsx($,{className:"mr-1.5"}):null,l.isPending?"Removing...":"Confirm remove"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:l.isPending,onClick:()=>m(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",onClick:S,disabled:c.isPending,children:[c.isPending?e.jsx($,{className:"mr-1.5"}):null,c.isPending?"Saving...":"Save"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:c.isPending,onClick:()=>{f(n.label?.trim()??""),o(!1)},children:"Cancel"}),e.jsxs(j,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:c.isPending||l.isPending,onClick:()=>m(!0),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[R(n),e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{m(!1),f(n.label?.trim()??""),o(!0)},children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${n.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),n.online?n.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:T||void 0,caption:`Last seen ${L(new Date(n.last_seen_at),{addSuffix:!0})}${n.last_sync_at?` · Last sync ${L(new Date(n.last_sync_at),{addSuffix:!0})}`:""}`}),children:[n.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(se,{className:"h-3.5 w-3.5 shrink-0"}),n.connector_error_count," connector",n.connector_error_count===1?"":"s"," pinned to this device ",n.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(ve,{device:n,organizationId:r,ownerSlug:t,selectedConnection:p,openSettings:u}),C.length>0?e.jsx(N,{title:"Browser auth profiles",children:e.jsx(ye,{profiles:C})}):null,e.jsx(N,{title:"Runs",children:e.jsx(he,{scope:{deviceId:y},ownerSlug:t})})]})})}function ye({profiles:t}){return t.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:t.map(s=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:s.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.connector_key??"Any connector"}),s.browser_kind?e.jsxs("span",{children:["· ",s.browser_kind]}):null,s.captured_at?e.jsxs("span",{title:s.captured_at,children:["· captured ",le(s.captured_at)]}):null,typeof s.cookie_count=="number"?e.jsxs("span",{children:["· ",s.cookie_count," cookie",s.cookie_count===1?"":"s"]}):null]})]}),e.jsx(pe,{status:s.is_expired?"error":fe(s.status),showDot:!0,children:s.is_expired?"expired":s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},s.id))})})}function Re(){const{owner:t,deviceId:s}=B.useParams(),{connection:r,settings:p}=B.useSearch();return e.jsx(de,{owner:t,children:({ownerSlug:u,organizationId:d})=>e.jsx(_e,{ownerSlug:u,deviceId:s,organizationId:d,selectedConnection:r,openSettings:p})})}export{Re as component};
1
+ import{dI as K,h1 as O,j as e,fi as N,S as _,B as j,bq as E,L as w,dU as A,r as b,dz as F,dB as H,dC as V,a as q,a2 as U,bb as W,h2 as Y,h3 as G,h4 as J,b7 as Q,bc as P,h5 as X,h6 as Z,gH as ee,bF as se,g2 as ne,h7 as L,ab as te,d8 as R,s as $,bw as ae,H as ie,bp as ce,g3 as oe,g4 as re,x as le,h8 as B,aV as de}from"./index-BKZMzuMS.js";import{c as me,C as xe,R as ue}from"./device-pin-tombstone-BBYes4en.js";import{R as he}from"./runs-panel-BkRtr_C4.js";import{S as pe,g as fe}from"./runs-table-CWCl38L5.js";import{c as ge}from"./connection-label-BobuYiAG.js";import{c as je}from"./device-rows-E63OZ9Cp.js";import"./runs-CftQDTkq.js";function ve({device:t,organizationId:s,ownerSlug:r,selectedConnection:p,openSettings:u}){const{data:d=[],isLoading:g,isError:h,refetch:l}=K(s),c=new Map(d.map(i=>[i.key,i])),a=new Map,m=[];for(const i of t.connectors){if(i.organization_slug!==r)continue;const o=c.get(i.connector_key);if(!o||!je(o)){m.push(i);continue}const v=o.required_capability??`connector:${o.key}`,f=a.get(v)??{key:v,name:o.name,connections:[]};f.name=O[v]??o.name,f.connections.push(i),a.set(v,f)}return e.jsxs(e.Fragment,{children:[e.jsxs(N,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),t.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!s||g?e.jsx(_,{className:"h-24 w-full"}):h?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void l(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(i=>e.jsx(be,{group:i,deviceId:t.id,organizationId:s,ownerSlug:r,definitionsByKey:c,selectedConnection:p,openSettings:u},i.key))}),E(t)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),s&&m.length>0&&!g&&!h?e.jsxs(N,{title:"Connections",count:String(m.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:m.map(i=>e.jsxs(w,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:r,connectorKey:i.connector_key,connectionId:String(i.connection_id)},search:{},className:"flex items-center gap-3 py-3 text-sm hover:text-primary",children:[e.jsx("span",{className:"min-w-0 flex-1",children:i.display_name||c.get(i.connector_key)?.name||i.connector_key}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.status}),e.jsx(A,{className:"size-3.5 text-muted-foreground"})]},i.connection_id))})]}):null]})}function be({group:t,deviceId:s,organizationId:r,ownerSlug:p,definitionsByKey:u,selectedConnection:d,openSettings:g}){const h=t.connections.some(a=>a.connection_id===d),[l,c]=b.useState(h);return b.useEffect(()=>{h&&d!==void 0&&c(!0)},[h,d]),e.jsxs(F,{open:l,onOpenChange:c,children:[e.jsxs(H,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(A,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:t.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:t.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":t.connections.length>1?`${t.connections.length} connections`:"Configured"})]}),e.jsx(V,{forceMount:!0,hidden:!l,className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:t.connections.map(a=>e.jsx(Ne,{summary:a,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u.get(a.connector_key),openSettings:a.connection_id===d&&g},a.connection_id))})})]})}function Ne({summary:t,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u,openSettings:d}){const{data:g=[],isLoading:h,isError:l,refetch:c}=q(r,{connectionIds:[t.connection_id]}),a=g.find(o=>o.id===t.connection_id&&o.device_worker_id===s),m=u?.name??t.connector_key,i=a?me(a):null;return e.jsxs("section",{id:`connection-${t.connection_id}`,"aria-label":m,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:ge(a)}),e.jsx("span",{children:a.status})]}):null,h||!r?e.jsx(_,{className:"h-24 w-full"}):l?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void c(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[i?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:i}):null,e.jsx(xe,{connection:a,connectorDef:u,ownerSlug:p,openSettings:d,showActivity:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function _e({ownerSlug:t,deviceId:s,organizationId:r,selectedConnection:p,openSettings:u}){const d=U(),{data:g=[],isLoading:h}=W(),l=Y(),c=G(),[a,m]=b.useState(!1),[i,o]=b.useState(!1),[v,f]=b.useState(""),n=J(g,s),y=n?.id??s,{data:k=[]}=Q(r,{profileKind:"browser_session"}),C=b.useMemo(()=>k.filter(x=>x.device_worker_id===y&&x.status!=="revoked"),[k,y]),D=n?.label?.trim()??"";if(b.useEffect(()=>{i||f(D)},[D,i]),h)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"h-6 w-6 rounded"}),e.jsx(_,{className:"h-5 w-40"})]}),e.jsx(ue,{})]});if(!n)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const I=E(n),z=X(n.app_version),T=Z(n,z),S=()=>{const x=v.trim(),M=n.label?.trim()??"";if(x===M){o(!1);return}c.mutate({deviceWorkerId:n.id,label:x.length===0?null:x},{onSuccess:()=>o(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(ee,{header:e.jsx(ne,{breadcrumb:e.jsx(oe,{crumbs:[e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:re,children:"Connectors"},"connectors")]}),icon:e.jsx(ce,{platform:I,className:"h-5 w-5"}),title:i?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{"aria-label":"Device name",value:v,onChange:x=>f(x.target.value),placeholder:R({...n,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),a||S()):x.key==="Escape"&&(m(!1),f(n.label?.trim()??""),o(!1))}}),a?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",n.connector_count>0?`and un-pins ${n.connector_count} connector${n.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(j,{variant:"destructive",size:"sm",disabled:l.isPending,onClick:()=>l.mutate(n.id,{onSuccess:()=>{m(!1),d({to:"/$owner/connectors",params:{owner:t},search:{}})}}),children:[l.isPending?e.jsx($,{className:"mr-1.5"}):null,l.isPending?"Removing...":"Confirm remove"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:l.isPending,onClick:()=>m(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",onClick:S,disabled:c.isPending,children:[c.isPending?e.jsx($,{className:"mr-1.5"}):null,c.isPending?"Saving...":"Save"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:c.isPending,onClick:()=>{f(n.label?.trim()??""),o(!1)},children:"Cancel"}),e.jsxs(j,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:c.isPending||l.isPending,onClick:()=>m(!0),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[R(n),e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{m(!1),f(n.label?.trim()??""),o(!0)},children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${n.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),n.online?n.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:T||void 0,caption:`Last seen ${L(new Date(n.last_seen_at),{addSuffix:!0})}${n.last_sync_at?` · Last sync ${L(new Date(n.last_sync_at),{addSuffix:!0})}`:""}`}),children:[n.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(se,{className:"h-3.5 w-3.5 shrink-0"}),n.connector_error_count," connector",n.connector_error_count===1?"":"s"," pinned to this device ",n.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(ve,{device:n,organizationId:r,ownerSlug:t,selectedConnection:p,openSettings:u}),C.length>0?e.jsx(N,{title:"Browser auth profiles",children:e.jsx(ye,{profiles:C})}):null,e.jsx(N,{title:"Runs",children:e.jsx(he,{scope:{deviceId:y},ownerSlug:t})})]})})}function ye({profiles:t}){return t.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:t.map(s=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:s.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.connector_key??"Any connector"}),s.browser_kind?e.jsxs("span",{children:["· ",s.browser_kind]}):null,s.captured_at?e.jsxs("span",{title:s.captured_at,children:["· captured ",le(s.captured_at)]}):null,typeof s.cookie_count=="number"?e.jsxs("span",{children:["· ",s.cookie_count," cookie",s.cookie_count===1?"":"s"]}):null]})]}),e.jsx(pe,{status:s.is_expired?"error":fe(s.status),showDot:!0,children:s.is_expired?"expired":s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},s.id))})})}function Re(){const{owner:t,deviceId:s}=B.useParams(),{connection:r,settings:p}=B.useSearch();return e.jsx(de,{owner:t,children:({ownerSlug:u,organizationId:d})=>e.jsx(_e,{ownerSlug:u,deviceId:s,organizationId:d,selectedConnection:r,openSettings:p})})}export{Re as component};
@@ -1 +1 @@
1
- import{a2 as x,bM as _,j as e,bY as C,bZ as m,b_ as S,b$ as b,c0 as o,c1 as u}from"./index-C2YGEKPo.js";import{c as w}from"./connection-label-BobuYiAG.js";const h="__connection_picker_create_new__";function y({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:i=!1,ariaLabel:p="Connection"}){const f=x(),l=_().org?.slug,c=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(C,{value:r,onValueChange:j,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[i?e.jsxs(e.Fragment,{children:[e.jsx(o,{value:"workspace",children:"Current workspace"}),c.length>0?e.jsx(u,{}):null]}):null,c.map(t=>e.jsx(o,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[c.length>0||i?e.jsx(u,{}):null,e.jsx(o,{value:h,children:"Connect an app…"})]}):null]})]})}function v(s){const r=[];for(const n of s)r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...v(n.children));return r}export{y as C,v as f};
1
+ import{a2 as x,bM as _,j as e,bY as C,bZ as m,b_ as S,b$ as b,c0 as o,c1 as u}from"./index-BKZMzuMS.js";import{c as w}from"./connection-label-BobuYiAG.js";const h="__connection_picker_create_new__";function y({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:i=!1,ariaLabel:p="Connection"}){const f=x(),l=_().org?.slug,c=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(C,{value:r,onValueChange:j,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[i?e.jsxs(e.Fragment,{children:[e.jsx(o,{value:"workspace",children:"Current workspace"}),c.length>0?e.jsx(u,{}):null]}):null,c.map(t=>e.jsx(o,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[c.length>0||i?e.jsx(u,{}):null,e.jsx(o,{value:h,children:"Connect an app…"})]}):null]})]})}function v(s){const r=[];for(const n of s)r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...v(n.children));return r}export{y as C,v as f};
@@ -1 +1 @@
1
- import{a1 as Y,hF as ye,r as g,j as e,S as P,a2 as Q,hG as _e,af as Z,aj as _,cF as Ne,hH as we,cx as M,dv as Ce,dr as Se,aE as C,hI as Te,hJ as Ee,hK as ke,ds as R,hL as Ie,aH as De,hM as ee,cy as Fe,cC as Pe,cA as Re,cD as K,cv as Ae,cw as Le,g as Me,cn as te,cG as $e,hN as Oe,k as ze,co as w,cr as Ve,F as Be,aa as A,ab as q,ea as Ge,bF as Je,B as v,eT as Ue,L as He,fa as Ke,hO as qe,J as We,hP as Xe,eh as Ye,cX as Qe,aS as Ze}from"./index-C2YGEKPo.js";import{a as W,c as X,S as et,D as tt,E as st}from"./schema-value-normalization-Dr5Osu6u.js";import{J as L}from"./renderer-BdAH16jE.js";import"./calendar-BZSx-Jno.js";import"./card-BsWGRkun.js";function at({entityId:t,ownerSlug:s}){const{orgContext:n}=Y(),{data:i,isLoading:a}=ye(t,n),o=g.useMemo(()=>{if(!i)return[];const r=new Map;for(const l of i.rows){const u=r.get(l.relationship_type_slug);u?u.rows.push(l):r.set(l.relationship_type_slug,{slug:l.relationship_type_slug,label:l.relationship_type_name,rows:[l]})}return[...r.values()]},[i]);return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"h-4 w-32"}),e.jsx(P,{className:"h-12 w-full rounded-lg"}),e.jsx(P,{className:"h-12 w-full rounded-lg"})]}):!i||i.rows.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No relationships for this entity yet."}):e.jsx("div",{className:"space-y-3",children:o.map(({slug:r,label:l,rows:u})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u.length})]}),e.jsx("ul",{className:"space-y-1",children:u.map(c=>e.jsx(nt,{entityId:t,row:c,ownerSlug:s},c.id))})]},r))})}function nt({entityId:t,row:s,ownerSlug:n}){const i=Q(),{orgContext:a}=Y(),[o,r]=g.useState(!1),[l,u]=g.useState(!1),c=s.from_entity_id===s.to_entity_id,d=s.from_entity_id===t,x=c?"this entity":d?s.to_entity_name??`Entity #${s.to_entity_id}`:s.from_entity_name??`Entity #${s.from_entity_id}`,p=d?s.to_entity_type:s.from_entity_type,T=d?s.to_entity_id:s.from_entity_id,m=p?`${p} · ${x}`:x;async function f(){r(!0),u(!1);try{const N=[],j=new Set;let b=T;for(;b!==null;){if(j.has(b))throw new Error("Cyclic entity ancestry");j.add(b);const{entity:y}=await Ne("manage_entity",{action:"get",entity_id:b},we(a));N.unshift({entity_type:y.entity_type,slug:y.slug}),b=y.parent_id}await i({to:M(n,N)})}catch{u(!0)}finally{r(!1)}}return e.jsxs("li",{className:_("flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"),children:[e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c||!p?e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:m}):e.jsxs("button",{type:"button",onClick:f,disabled:o,"aria-busy":o,className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-sm hover:underline",children:m}),p?e.jsx(Z,{variant:"outline",className:"shrink-0 text-[9px] px-1.5 py-0 h-4 text-muted-foreground",children:p}):null]}),l?e.jsx("span",{role:"alert",className:"text-xs text-destructive",children:"Could not open this record. Try again."}):null]})}var S="Tabs",[it]=De(S,[ee]),se=ee(),[rt,z]=it(S),ae=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,onValueChange:a,defaultValue:o,orientation:r="horizontal",dir:l,activationMode:u="automatic",...c}=t,d=Ce(l),[x,p]=Se({prop:i,onChange:a,defaultProp:o??"",caller:S});return e.jsx(rt,{scope:n,baseId:Te(),value:x,onValueChange:p,orientation:r,dir:d,activationMode:u,children:e.jsx(C.div,{dir:d,"data-orientation":r,...c,ref:s})})});ae.displayName=S;var ne="TabsList",ie=g.forwardRef((t,s)=>{const{__scopeTabs:n,loop:i=!0,...a}=t,o=z(ne,n),r=se(n);return e.jsx(Ee,{asChild:!0,...r,orientation:o.orientation,dir:o.dir,loop:i,children:e.jsx(C.div,{role:"tablist","aria-orientation":o.orientation,...a,ref:s})})});ie.displayName=ne;var re="TabsTrigger",oe=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,disabled:a=!1,...o}=t,r=z(re,n),l=se(n),u=de(r.baseId,i),c=me(r.baseId,i),d=i===r.value;return e.jsx(ke,{asChild:!0,...l,focusable:!a,active:d,children:e.jsx(C.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":c,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...o,ref:s,onMouseDown:R(t.onMouseDown,x=>{!a&&x.button===0&&x.ctrlKey===!1?r.onValueChange(i):x.preventDefault()}),onKeyDown:R(t.onKeyDown,x=>{[" ","Enter"].includes(x.key)&&r.onValueChange(i)}),onFocus:R(t.onFocus,()=>{const x=r.activationMode!=="manual";!d&&!a&&x&&r.onValueChange(i)})})})});oe.displayName=re;var le="TabsContent",ce=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,forceMount:a,children:o,...r}=t,l=z(le,n),u=de(l.baseId,i),c=me(l.baseId,i),d=i===l.value,x=g.useRef(d);return g.useEffect(()=>{const p=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(p)},[]),e.jsx(Ie,{present:a||d,children:({present:p})=>e.jsx(C.div,{"data-state":d?"active":"inactive","data-orientation":l.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:c,tabIndex:0,...r,ref:s,style:{...t.style,animationDuration:x.current?"0s":void 0},children:p&&o})})});ce.displayName=le;function de(t,s){return`${t}-trigger-${s}`}function me(t,s){return`${t}-content-${s}`}var ot=ae,ue=ie,xe=oe,ge=ce;const lt=ot,pe=g.forwardRef(({className:t,...s},n)=>e.jsx(ue,{ref:n,className:_("inline-flex h-9 items-center justify-start gap-1 border-b border-border bg-transparent p-0",t),...s}));pe.displayName=ue.displayName;const $=g.forwardRef(({className:t,...s},n)=>e.jsx(xe,{ref:n,className:_("inline-flex items-center justify-center whitespace-nowrap px-3 pb-2 pt-1 text-sm font-medium text-muted-foreground transition-all","border-b-2 border-transparent","hover:text-foreground","data-[state=active]:border-foreground data-[state=active]:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50",t),...s}));$.displayName=xe.displayName;const O=g.forwardRef(({className:t,...s},n)=>e.jsx(ge,{ref:n,className:_("mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),...s}));O.displayName=ge.displayName;function ct(t,s){const n=new Set([...Object.keys(t),...Object.keys(s)]);let i=!1;const a={};for(const o of n){const r=o in t,l=o in s;if(!r&&l){a[o]=s[o];continue}r&&(a[o]=t[o],(!l||JSON.stringify(t[o])!==JSON.stringify(s[o]))&&(i=!0))}return i?a:void 0}function dt({entity:t,entityTypeSlug:s,orgContext:n,onDeleted:i}){const{isAdmin:a,isLoading:o}=Me(n.organizationId),r=a&&!o,{data:l,isLoading:u}=te(s,n),c=$e(),d=Oe(),x=l?.metadata_schema,p=t.field_controls,T=g.useMemo(()=>W(t.metadata??{},x),[t.metadata,x]),m=ze(t.id,{name:t.name,slug:t.slug,metadata:T},x),[f,N]=m.field("name"),[j,b]=m.field("slug"),[y,he]=m.field("metadata"),[V,B]=w(t.id,""),[G,E]=w(t.id,null),[fe,k]=w(t.id,!1),[J,I]=w(t.id,null),D=g.useMemo(()=>m.hasInvalidInput?void 0:ct(X(y),X(m.baseline.metadata)),[m.baseline.metadata,y,m.hasInvalidInput]),F=D!==void 0,ve=f!==m.baseline.name||j!==m.baseline.slug||F,je=async h=>{if(h.preventDefault(),!(!r||!m.canSubmit)){if(E(null),!f.trim()){E("Name is required");return}try{await c.mutateAsync({entityId:t.id,name:f.trim()!==m.baseline.name.trim()?f.trim():void 0,slug:j,metadata:D,field_note:F&&V.trim()||void 0}),m.accept(m.values,{name:f.trim(),slug:j,metadata:W({...Ue(m.baseline.metadata),...D},x)}),B("")}catch(H){E(H instanceof Error?H.message:"Failed to update entity")}}},be=async()=>{if(r){I(null);try{await d.mutateAsync({entityId:t.id}),k(!1),i?.()}catch(h){I(h instanceof Error?h.message:"Failed to delete entity")}}},U=[t.total_content>0&&`${t.total_content} content item${t.total_content===1?"":"s"}`,t.automations_count>0&&`${t.automations_count} Automation${t.automations_count===1?"":"s"}`,t.active_connections>0&&`${t.active_connections} connector${t.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return u?e.jsx(Ve,{rows:6}):e.jsxs("form",{onSubmit:je,className:"space-y-4",children:[e.jsx(Be,{visible:m.hasConflict,onReload:m.reset}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",role:"status",children:o?"Checking edit permissions…":"You can view this record. Ask a workspace owner or admin to make changes."}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(A,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(q,{id:"sidebar-name",readOnly:!r,value:f,onChange:h=>N(h.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(q,{id:"sidebar-slug",readOnly:!r,value:j,onChange:h=>b(h.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),m.revision&&Object.keys(m.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(et,{}),e.jsx(tt,{schema:m.revision,values:y,onValuesChange:he,readonly:!r,fieldControls:p,orgContext:n})]}),r&&F&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:V,onChange:h=>B(h.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),G&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:G}),r&&(fe?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Je,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',t.name,'"?']}),U&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",U,". This cannot be easily undone."]})]})]}),J&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:J}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>{k(!1),I(null)},children:"Cancel"}),e.jsx(v,{type:"button",variant:"destructive",size:"sm",onClick:be,disabled:d.isPending,children:d.isPending?"Deleting...":`Delete ${l?.name||"entity"}`})]})]}):e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>k(!0),children:"Delete"}),e.jsx(v,{type:"submit",size:"sm",disabled:!m.canSubmit||!ve||c.isPending||!f.trim(),children:c.isPending?"Saving...":"Save"})]}))]})}function mt({entity:t}){const s=new Set(t.measure_columns??[]),n=t.metadata??{},i=Object.keys(n).filter(a=>a!=="id"&&a!=="slug"&&a!=="name");return e.jsx("div",{className:"mt-4 max-w-2xl",children:e.jsx("div",{className:"rounded-lg border",children:e.jsx(Fe,{children:e.jsx(Pe,{children:i.map(a=>{const o=s.has(a);return e.jsxs(Re,{children:[e.jsx(K,{className:"w-44 align-top font-medium text-muted-foreground",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[o?a:Ae(a.replace(/_/g," ")),o&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]})}),e.jsx(K,{className:_("break-words align-top",o?"text-right tabular-nums":""),children:Le(n[a])})]},a)})})})})})}function ut({namespace:t,entity:s,onDeleted:n}){if(s.is_derived)return e.jsx(mt,{entity:s});const i={...s.metadata,...s.template_data??{},name:s.name,entity_type:s.entity_type,total_content:s.total_content,active_connections:s.active_connections,automations_count:s.automations_count},a=s.tabs??[],o=a.length>0,r=!o&&s.json_template_version==null,l=e.jsx(dt,{entity:s,entityTypeSlug:s.entity_type,orgContext:{slug:t.slug,organizationId:t.id},onDeleted:n}),u=s.is_derived?null:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Relationships"}),e.jsx(at,{entityId:s.id,ownerSlug:t.slug})]});return r?e.jsxs("div",{className:"mt-4 max-w-xl",children:[u,e.jsx("div",{className:"mt-4",children:l})]}):e.jsxs("div",{className:"mt-4 grid gap-6 xl:grid-cols-[minmax(0,1.5fr)_460px]",children:[e.jsx("div",{className:"space-y-6",children:o?e.jsxs(lt,{defaultValue:s.json_template?"__default__":a[0]?.tab_name,children:[e.jsxs(pe,{children:[s.json_template&&e.jsx($,{value:"__default__",children:"Overview"}),a.map(c=>e.jsx($,{value:c.tab_name,children:c.tab_name},c.tab_name))]}),s.json_template&&e.jsx(O,{value:"__default__",children:e.jsx(L,{template:{root:s.json_template},data:i})}),a.map(c=>e.jsx(O,{value:c.tab_name,children:e.jsx(L,{template:{root:c.json_template},data:{...i,...c.template_data??{}}})},c.tab_name))]}):e.jsx(L,{template:{root:s.json_template},data:i})}),e.jsxs("div",{className:"space-y-4",children:[u,l]})]})}function xt(t){return typeof t=="string"?t:t===null?"None":JSON.stringify(t)??String(t)}function gt({records:t}){const s=Ye(),[n,i]=g.useState(null);return t.length===0?null:e.jsxs("details",{className:_(Ze,"px-4 py-3"),children:[e.jsxs("summary",{className:"cursor-pointer text-sm font-medium",children:["Merged records (",t.length,")"]}),e.jsx("div",{className:"mt-3 space-y-3",children:t.map(a=>e.jsxs("div",{className:"rounded-lg bg-background p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Merged ",new Date(a.merged_at).toLocaleString()]})]}),a.can_unmerge?n===a.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{type:"button",variant:"destructive",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({entityId:a.id},{onSettled:()=>i(null)}),children:"Confirm undo"}),e.jsx(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(null),children:"Cancel"})]}):e.jsxs(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(a.id),children:[e.jsx(Qe,{className:"mr-1.5 size-3.5"}),"Undo merge"]}):null]}),Object.keys(a.metadata).length>0?e.jsx("dl",{className:"mt-3 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2",children:Object.entries(a.metadata).map(([o,r])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground",children:o}),e.jsx("dd",{className:"break-words",children:xt(r)})]},o))}):null]},a.id))})]})}function pt(t){return t?.trim()?t:void 0}function ht({ownerSlug:t,entityName:s,activityHref:n}){const i=We();return e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>i?.open({href:n,title:`${s} · Activity`,owner:t}),disabled:!i,children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"See activity"]})}function _t({namespace:t,path:s,entity:n,mergedFrom:i}){const a=Q(),{data:o}=te(n.entity_type,{slug:t.slug}),r=pt(o?.icon),l=s.map(d=>({entity_type:d.entity_type,slug:d.slug})),u=`/${t.slug}/${n.entity_type}`,c=s.length>1?M(t.slug,l.slice(0,-1)):u;return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-6 lg:px-6",children:[i?e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsx("strong",{children:i})," was merged into this canonical record."]}):null,e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx(v,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-7 w-fit px-2 text-muted-foreground hover:text-foreground",children:e.jsxs(He,{to:c,children:[e.jsx(Ke,{className:"mr-1 h-4 w-4"}),"Back"]})}),!n.is_derived&&e.jsx("div",{className:"ml-auto",children:e.jsx(ht,{ownerSlug:t.slug,entityName:n.name,activityHref:`/${t.slug}/events/${qe(l)}`})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(st,{metadata:n.metadata,metadataSchema:o?.metadata_schema,name:n.name,typeIcon:r,className:"h-6 w-6"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n.name})]})]}),e.jsx(gt,{records:n.merged_records??[]}),e.jsx(ut,{namespace:t,entity:n,onDeleted:()=>{const d=s.slice(0,-1);d.length>0?a({to:M(t.slug,d)}):a({to:u})}})]})}export{_t as EntityPage};
1
+ import{a1 as Y,hF as ye,r as g,j as e,S as P,a2 as Q,hG as _e,af as Z,aj as _,cF as Ne,hH as we,cx as M,dv as Ce,dr as Se,aE as C,hI as Te,hJ as Ee,hK as ke,ds as R,hL as Ie,aH as De,hM as ee,cy as Fe,cC as Pe,cA as Re,cD as K,cv as Ae,cw as Le,g as Me,cn as te,cG as $e,hN as Oe,k as ze,co as w,cr as Ve,F as Be,aa as A,ab as q,ea as Ge,bF as Je,B as v,eT as Ue,L as He,fa as Ke,hO as qe,J as We,hP as Xe,eh as Ye,cX as Qe,aS as Ze}from"./index-BKZMzuMS.js";import{a as W,c as X,S as et,D as tt,E as st}from"./schema-value-normalization-C9Lm83-q.js";import{J as L}from"./renderer-CAyr3B3s.js";import"./calendar-VAaxHxss.js";import"./card-HMQT7vU5.js";function at({entityId:t,ownerSlug:s}){const{orgContext:n}=Y(),{data:i,isLoading:a}=ye(t,n),o=g.useMemo(()=>{if(!i)return[];const r=new Map;for(const l of i.rows){const u=r.get(l.relationship_type_slug);u?u.rows.push(l):r.set(l.relationship_type_slug,{slug:l.relationship_type_slug,label:l.relationship_type_name,rows:[l]})}return[...r.values()]},[i]);return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"h-4 w-32"}),e.jsx(P,{className:"h-12 w-full rounded-lg"}),e.jsx(P,{className:"h-12 w-full rounded-lg"})]}):!i||i.rows.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No relationships for this entity yet."}):e.jsx("div",{className:"space-y-3",children:o.map(({slug:r,label:l,rows:u})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u.length})]}),e.jsx("ul",{className:"space-y-1",children:u.map(c=>e.jsx(nt,{entityId:t,row:c,ownerSlug:s},c.id))})]},r))})}function nt({entityId:t,row:s,ownerSlug:n}){const i=Q(),{orgContext:a}=Y(),[o,r]=g.useState(!1),[l,u]=g.useState(!1),c=s.from_entity_id===s.to_entity_id,d=s.from_entity_id===t,x=c?"this entity":d?s.to_entity_name??`Entity #${s.to_entity_id}`:s.from_entity_name??`Entity #${s.from_entity_id}`,p=d?s.to_entity_type:s.from_entity_type,T=d?s.to_entity_id:s.from_entity_id,m=p?`${p} · ${x}`:x;async function f(){r(!0),u(!1);try{const N=[],j=new Set;let b=T;for(;b!==null;){if(j.has(b))throw new Error("Cyclic entity ancestry");j.add(b);const{entity:y}=await Ne("manage_entity",{action:"get",entity_id:b},we(a));N.unshift({entity_type:y.entity_type,slug:y.slug}),b=y.parent_id}await i({to:M(n,N)})}catch{u(!0)}finally{r(!1)}}return e.jsxs("li",{className:_("flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"),children:[e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c||!p?e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:m}):e.jsxs("button",{type:"button",onClick:f,disabled:o,"aria-busy":o,className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-sm hover:underline",children:m}),p?e.jsx(Z,{variant:"outline",className:"shrink-0 text-[9px] px-1.5 py-0 h-4 text-muted-foreground",children:p}):null]}),l?e.jsx("span",{role:"alert",className:"text-xs text-destructive",children:"Could not open this record. Try again."}):null]})}var S="Tabs",[it]=De(S,[ee]),se=ee(),[rt,z]=it(S),ae=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,onValueChange:a,defaultValue:o,orientation:r="horizontal",dir:l,activationMode:u="automatic",...c}=t,d=Ce(l),[x,p]=Se({prop:i,onChange:a,defaultProp:o??"",caller:S});return e.jsx(rt,{scope:n,baseId:Te(),value:x,onValueChange:p,orientation:r,dir:d,activationMode:u,children:e.jsx(C.div,{dir:d,"data-orientation":r,...c,ref:s})})});ae.displayName=S;var ne="TabsList",ie=g.forwardRef((t,s)=>{const{__scopeTabs:n,loop:i=!0,...a}=t,o=z(ne,n),r=se(n);return e.jsx(Ee,{asChild:!0,...r,orientation:o.orientation,dir:o.dir,loop:i,children:e.jsx(C.div,{role:"tablist","aria-orientation":o.orientation,...a,ref:s})})});ie.displayName=ne;var re="TabsTrigger",oe=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,disabled:a=!1,...o}=t,r=z(re,n),l=se(n),u=de(r.baseId,i),c=me(r.baseId,i),d=i===r.value;return e.jsx(ke,{asChild:!0,...l,focusable:!a,active:d,children:e.jsx(C.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":c,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...o,ref:s,onMouseDown:R(t.onMouseDown,x=>{!a&&x.button===0&&x.ctrlKey===!1?r.onValueChange(i):x.preventDefault()}),onKeyDown:R(t.onKeyDown,x=>{[" ","Enter"].includes(x.key)&&r.onValueChange(i)}),onFocus:R(t.onFocus,()=>{const x=r.activationMode!=="manual";!d&&!a&&x&&r.onValueChange(i)})})})});oe.displayName=re;var le="TabsContent",ce=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,forceMount:a,children:o,...r}=t,l=z(le,n),u=de(l.baseId,i),c=me(l.baseId,i),d=i===l.value,x=g.useRef(d);return g.useEffect(()=>{const p=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(p)},[]),e.jsx(Ie,{present:a||d,children:({present:p})=>e.jsx(C.div,{"data-state":d?"active":"inactive","data-orientation":l.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:c,tabIndex:0,...r,ref:s,style:{...t.style,animationDuration:x.current?"0s":void 0},children:p&&o})})});ce.displayName=le;function de(t,s){return`${t}-trigger-${s}`}function me(t,s){return`${t}-content-${s}`}var ot=ae,ue=ie,xe=oe,ge=ce;const lt=ot,pe=g.forwardRef(({className:t,...s},n)=>e.jsx(ue,{ref:n,className:_("inline-flex h-9 items-center justify-start gap-1 border-b border-border bg-transparent p-0",t),...s}));pe.displayName=ue.displayName;const $=g.forwardRef(({className:t,...s},n)=>e.jsx(xe,{ref:n,className:_("inline-flex items-center justify-center whitespace-nowrap px-3 pb-2 pt-1 text-sm font-medium text-muted-foreground transition-all","border-b-2 border-transparent","hover:text-foreground","data-[state=active]:border-foreground data-[state=active]:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50",t),...s}));$.displayName=xe.displayName;const O=g.forwardRef(({className:t,...s},n)=>e.jsx(ge,{ref:n,className:_("mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),...s}));O.displayName=ge.displayName;function ct(t,s){const n=new Set([...Object.keys(t),...Object.keys(s)]);let i=!1;const a={};for(const o of n){const r=o in t,l=o in s;if(!r&&l){a[o]=s[o];continue}r&&(a[o]=t[o],(!l||JSON.stringify(t[o])!==JSON.stringify(s[o]))&&(i=!0))}return i?a:void 0}function dt({entity:t,entityTypeSlug:s,orgContext:n,onDeleted:i}){const{isAdmin:a,isLoading:o}=Me(n.organizationId),r=a&&!o,{data:l,isLoading:u}=te(s,n),c=$e(),d=Oe(),x=l?.metadata_schema,p=t.field_controls,T=g.useMemo(()=>W(t.metadata??{},x),[t.metadata,x]),m=ze(t.id,{name:t.name,slug:t.slug,metadata:T},x),[f,N]=m.field("name"),[j,b]=m.field("slug"),[y,he]=m.field("metadata"),[V,B]=w(t.id,""),[G,E]=w(t.id,null),[fe,k]=w(t.id,!1),[J,I]=w(t.id,null),D=g.useMemo(()=>m.hasInvalidInput?void 0:ct(X(y),X(m.baseline.metadata)),[m.baseline.metadata,y,m.hasInvalidInput]),F=D!==void 0,ve=f!==m.baseline.name||j!==m.baseline.slug||F,je=async h=>{if(h.preventDefault(),!(!r||!m.canSubmit)){if(E(null),!f.trim()){E("Name is required");return}try{await c.mutateAsync({entityId:t.id,name:f.trim()!==m.baseline.name.trim()?f.trim():void 0,slug:j,metadata:D,field_note:F&&V.trim()||void 0}),m.accept(m.values,{name:f.trim(),slug:j,metadata:W({...Ue(m.baseline.metadata),...D},x)}),B("")}catch(H){E(H instanceof Error?H.message:"Failed to update entity")}}},be=async()=>{if(r){I(null);try{await d.mutateAsync({entityId:t.id}),k(!1),i?.()}catch(h){I(h instanceof Error?h.message:"Failed to delete entity")}}},U=[t.total_content>0&&`${t.total_content} content item${t.total_content===1?"":"s"}`,t.automations_count>0&&`${t.automations_count} Automation${t.automations_count===1?"":"s"}`,t.active_connections>0&&`${t.active_connections} connector${t.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return u?e.jsx(Ve,{rows:6}):e.jsxs("form",{onSubmit:je,className:"space-y-4",children:[e.jsx(Be,{visible:m.hasConflict,onReload:m.reset}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",role:"status",children:o?"Checking edit permissions…":"You can view this record. Ask a workspace owner or admin to make changes."}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(A,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(q,{id:"sidebar-name",readOnly:!r,value:f,onChange:h=>N(h.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(q,{id:"sidebar-slug",readOnly:!r,value:j,onChange:h=>b(h.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),m.revision&&Object.keys(m.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(et,{}),e.jsx(tt,{schema:m.revision,values:y,onValuesChange:he,readonly:!r,fieldControls:p,orgContext:n})]}),r&&F&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:V,onChange:h=>B(h.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),G&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:G}),r&&(fe?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Je,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',t.name,'"?']}),U&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",U,". This cannot be easily undone."]})]})]}),J&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:J}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>{k(!1),I(null)},children:"Cancel"}),e.jsx(v,{type:"button",variant:"destructive",size:"sm",onClick:be,disabled:d.isPending,children:d.isPending?"Deleting...":`Delete ${l?.name||"entity"}`})]})]}):e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>k(!0),children:"Delete"}),e.jsx(v,{type:"submit",size:"sm",disabled:!m.canSubmit||!ve||c.isPending||!f.trim(),children:c.isPending?"Saving...":"Save"})]}))]})}function mt({entity:t}){const s=new Set(t.measure_columns??[]),n=t.metadata??{},i=Object.keys(n).filter(a=>a!=="id"&&a!=="slug"&&a!=="name");return e.jsx("div",{className:"mt-4 max-w-2xl",children:e.jsx("div",{className:"rounded-lg border",children:e.jsx(Fe,{children:e.jsx(Pe,{children:i.map(a=>{const o=s.has(a);return e.jsxs(Re,{children:[e.jsx(K,{className:"w-44 align-top font-medium text-muted-foreground",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[o?a:Ae(a.replace(/_/g," ")),o&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]})}),e.jsx(K,{className:_("break-words align-top",o?"text-right tabular-nums":""),children:Le(n[a])})]},a)})})})})})}function ut({namespace:t,entity:s,onDeleted:n}){if(s.is_derived)return e.jsx(mt,{entity:s});const i={...s.metadata,...s.template_data??{},name:s.name,entity_type:s.entity_type,total_content:s.total_content,active_connections:s.active_connections,automations_count:s.automations_count},a=s.tabs??[],o=a.length>0,r=!o&&s.json_template_version==null,l=e.jsx(dt,{entity:s,entityTypeSlug:s.entity_type,orgContext:{slug:t.slug,organizationId:t.id},onDeleted:n}),u=s.is_derived?null:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Relationships"}),e.jsx(at,{entityId:s.id,ownerSlug:t.slug})]});return r?e.jsxs("div",{className:"mt-4 max-w-xl",children:[u,e.jsx("div",{className:"mt-4",children:l})]}):e.jsxs("div",{className:"mt-4 grid gap-6 xl:grid-cols-[minmax(0,1.5fr)_460px]",children:[e.jsx("div",{className:"space-y-6",children:o?e.jsxs(lt,{defaultValue:s.json_template?"__default__":a[0]?.tab_name,children:[e.jsxs(pe,{children:[s.json_template&&e.jsx($,{value:"__default__",children:"Overview"}),a.map(c=>e.jsx($,{value:c.tab_name,children:c.tab_name},c.tab_name))]}),s.json_template&&e.jsx(O,{value:"__default__",children:e.jsx(L,{template:{root:s.json_template},data:i})}),a.map(c=>e.jsx(O,{value:c.tab_name,children:e.jsx(L,{template:{root:c.json_template},data:{...i,...c.template_data??{}}})},c.tab_name))]}):e.jsx(L,{template:{root:s.json_template},data:i})}),e.jsxs("div",{className:"space-y-4",children:[u,l]})]})}function xt(t){return typeof t=="string"?t:t===null?"None":JSON.stringify(t)??String(t)}function gt({records:t}){const s=Ye(),[n,i]=g.useState(null);return t.length===0?null:e.jsxs("details",{className:_(Ze,"px-4 py-3"),children:[e.jsxs("summary",{className:"cursor-pointer text-sm font-medium",children:["Merged records (",t.length,")"]}),e.jsx("div",{className:"mt-3 space-y-3",children:t.map(a=>e.jsxs("div",{className:"rounded-lg bg-background p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Merged ",new Date(a.merged_at).toLocaleString()]})]}),a.can_unmerge?n===a.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{type:"button",variant:"destructive",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({entityId:a.id},{onSettled:()=>i(null)}),children:"Confirm undo"}),e.jsx(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(null),children:"Cancel"})]}):e.jsxs(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(a.id),children:[e.jsx(Qe,{className:"mr-1.5 size-3.5"}),"Undo merge"]}):null]}),Object.keys(a.metadata).length>0?e.jsx("dl",{className:"mt-3 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2",children:Object.entries(a.metadata).map(([o,r])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground",children:o}),e.jsx("dd",{className:"break-words",children:xt(r)})]},o))}):null]},a.id))})]})}function pt(t){return t?.trim()?t:void 0}function ht({ownerSlug:t,entityName:s,activityHref:n}){const i=We();return e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>i?.open({href:n,title:`${s} · Activity`,owner:t}),disabled:!i,children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"See activity"]})}function _t({namespace:t,path:s,entity:n,mergedFrom:i}){const a=Q(),{data:o}=te(n.entity_type,{slug:t.slug}),r=pt(o?.icon),l=s.map(d=>({entity_type:d.entity_type,slug:d.slug})),u=`/${t.slug}/${n.entity_type}`,c=s.length>1?M(t.slug,l.slice(0,-1)):u;return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-6 lg:px-6",children:[i?e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsx("strong",{children:i})," was merged into this canonical record."]}):null,e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx(v,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-7 w-fit px-2 text-muted-foreground hover:text-foreground",children:e.jsxs(He,{to:c,children:[e.jsx(Ke,{className:"mr-1 h-4 w-4"}),"Back"]})}),!n.is_derived&&e.jsx("div",{className:"ml-auto",children:e.jsx(ht,{ownerSlug:t.slug,entityName:n.name,activityHref:`/${t.slug}/events/${qe(l)}`})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(st,{metadata:n.metadata,metadataSchema:o?.metadata_schema,name:n.name,typeIcon:r,className:"h-6 w-6"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n.name})]})]}),e.jsx(gt,{records:n.merged_records??[]}),e.jsx(ut,{namespace:t,entity:n,onDeleted:()=>{const d=s.slice(0,-1);d.length>0?a({to:M(t.slug,d)}):a({to:u})}})]})}export{_t as EntityPage};
@@ -1 +1 @@
1
- import{j as e,af as $,a1 as W,bU as me,c6 as xe,bX as G,c7 as ae,r as x,bV as he,bW as pe,ci as ge,cj as fe,B as f,P as U,ck as je,aa as C,bY as q,bZ as P,b_ as M,b$ as L,c0 as k,ab as T,s as ve,cd as Ne,e4 as ye,e5 as be,X as H,cP as ne,dU as re,ak as we,bw as le,e6 as ie,e7 as Se,bF as oe,e8 as Ce,e9 as ke,k as Ee,co as K,F as _e,ea as Re,c2 as Te,eb as Oe,ec as De,aj as X}from"./index-C2YGEKPo.js";import{J as B}from"./json-diff-gsOHOgl7.js";import{C as ce}from"./code-editor-C104Bzj2.js";function Ae(s){switch(s){case"create":return"default";case"update":return"secondary";case"delete":return"destructive";default:return"outline"}}function Fe(s){switch(s){case"create":return"Created";case"update":return"Updated";case"delete":return"Deleted";default:return s}}function ze(s){try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}catch{return s}}function qe({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:Ae(s.action),children:Fe(s.action)}),s.actor&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.actor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ze(s.created_at)}),s.action==="update"&&e.jsx(B,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(B,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(B,{before:s.before_payload,after:null})]})]})}function Pe({entityType:s}){const{orgContext:a}=W(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==G),d=i.filter(m=>m.purpose===G),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ie,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Me,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Me({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=W(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx($,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx($,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Le,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Le({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(H,{className:"h-3 w-3"})})})]})}function Ie({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=W(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[E,_]=x.useState(""),[D,w]=x.useState(!1),[A,R]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),_(""),w(!1),R(null)},O=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),V=async()=>{R(null);try{let l=h;if(o==="new"){if(!g.trim()){R("Name is required");return}const Y=E.trim()||F(g);if(!Y){R("Slug is required");return}l=(await u.mutateAsync({slug:Y,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){R("Select a relationship type");return}if(!S){R("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),O(!1)}catch(l){R(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:O,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),E||_("")}}),e.jsx(T,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:E,onChange:l=>_(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:V,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"integer",label:"Integer"},{value:"boolean",label:"Boolean"},{value:"enum",label:"Enum"}];function Be({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}function Je({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(T,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ue,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(T,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(T,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Be,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Q(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function $e(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"||a==="gallery"?a:"auto"}function We({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Q(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=$e(u,p),O=u.some(F=>F.name.trim());m(O?JSON.stringify(v,null,2):""),a(O?v:void 0)},[a]),E=x.useCallback(u=>{i(u),j(u,o)},[j,o]),_=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Q(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{E([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,E(v)},R=u=>{E(t.filter((p,v)=>v!==u))};return c?e.jsx(Z,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Je,{field:u,onChange:v=>A(p,v),onDelete:()=>R(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, an image field → gallery)."})]}),e.jsxs(q,{value:o,onValueChange:u=>_(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"}),e.jsx(k,{value:"gallery",children:"Gallery"})]})]})]})]}):e.jsx(Z,{value:h,onChange:D,error:S})]})}function He(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ye({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,E]=o.field("color"),[_,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[R,u]=K(i,n),[p,v]=K(i,null),O=w.trim().length>0,F=l=>{h(l),!n&&!R&&S(He(l))},V=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=O?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(T,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(T,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(T,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"et-color",value:j,onChange:l=>E(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),O?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(We,{value:_,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Pe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Te,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:V,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Oe(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,E=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},_=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:_}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ye,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"History"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(qe,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:E,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};
1
+ import{j as e,af as $,a1 as W,bU as me,c6 as xe,bX as G,c7 as ae,r as x,bV as he,bW as pe,ci as ge,cj as fe,B as f,P as U,ck as je,aa as C,bY as q,bZ as P,b_ as M,b$ as L,c0 as k,ab as T,s as ve,cd as Ne,e4 as ye,e5 as be,X as H,cP as ne,dU as re,ak as we,bw as le,e6 as ie,e7 as Se,bF as oe,e8 as Ce,e9 as ke,k as Ee,co as K,F as _e,ea as Re,c2 as Te,eb as Oe,ec as De,aj as X}from"./index-BKZMzuMS.js";import{J as B}from"./json-diff-1FNS_wGA.js";import{C as ce}from"./code-editor-hOZHdlxM.js";function Ae(s){switch(s){case"create":return"default";case"update":return"secondary";case"delete":return"destructive";default:return"outline"}}function Fe(s){switch(s){case"create":return"Created";case"update":return"Updated";case"delete":return"Deleted";default:return s}}function ze(s){try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}catch{return s}}function qe({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:Ae(s.action),children:Fe(s.action)}),s.actor&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.actor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ze(s.created_at)}),s.action==="update"&&e.jsx(B,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(B,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(B,{before:s.before_payload,after:null})]})]})}function Pe({entityType:s}){const{orgContext:a}=W(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==G),d=i.filter(m=>m.purpose===G),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ie,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Me,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Me({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=W(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx($,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx($,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Le,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Le({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(H,{className:"h-3 w-3"})})})]})}function Ie({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=W(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[E,_]=x.useState(""),[D,w]=x.useState(!1),[A,R]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),_(""),w(!1),R(null)},O=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),V=async()=>{R(null);try{let l=h;if(o==="new"){if(!g.trim()){R("Name is required");return}const Y=E.trim()||F(g);if(!Y){R("Slug is required");return}l=(await u.mutateAsync({slug:Y,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){R("Select a relationship type");return}if(!S){R("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),O(!1)}catch(l){R(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:O,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),E||_("")}}),e.jsx(T,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:E,onChange:l=>_(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:V,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"integer",label:"Integer"},{value:"boolean",label:"Boolean"},{value:"enum",label:"Enum"}];function Be({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}function Je({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(T,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ue,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(T,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(T,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Be,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Q(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function $e(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"||a==="gallery"?a:"auto"}function We({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Q(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=$e(u,p),O=u.some(F=>F.name.trim());m(O?JSON.stringify(v,null,2):""),a(O?v:void 0)},[a]),E=x.useCallback(u=>{i(u),j(u,o)},[j,o]),_=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Q(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{E([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,E(v)},R=u=>{E(t.filter((p,v)=>v!==u))};return c?e.jsx(Z,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Je,{field:u,onChange:v=>A(p,v),onDelete:()=>R(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, an image field → gallery)."})]}),e.jsxs(q,{value:o,onValueChange:u=>_(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"}),e.jsx(k,{value:"gallery",children:"Gallery"})]})]})]})]}):e.jsx(Z,{value:h,onChange:D,error:S})]})}function He(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ye({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,E]=o.field("color"),[_,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[R,u]=K(i,n),[p,v]=K(i,null),O=w.trim().length>0,F=l=>{h(l),!n&&!R&&S(He(l))},V=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=O?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(T,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(T,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(T,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"et-color",value:j,onChange:l=>E(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),O?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(We,{value:_,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Pe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Te,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:V,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Oe(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,E=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},_=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:_}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ye,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"History"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(qe,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:E,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};