@lobu/runtime-server 20.1.0 → 21.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/connectors/README.md +15 -16
  3. package/dist/connectors/chat-user-identity.ts +41 -0
  4. package/dist/connectors/github.ts +15 -9
  5. package/dist/connectors/google-identity.ts +11 -0
  6. package/dist/connectors/google_calendar.ts +21 -31
  7. package/dist/connectors/google_drive.ts +106 -131
  8. package/dist/connectors/google_gmail.ts +53 -30
  9. package/dist/connectors/hackernews.ts +2 -5
  10. package/dist/connectors/jira.ts +62 -27
  11. package/dist/connectors/linear.ts +55 -21
  12. package/dist/connectors/microsoft_outlook.ts +151 -110
  13. package/dist/connectors/postgres.ts +19 -11
  14. package/dist/connectors/producthunt.ts +8 -6
  15. package/dist/connectors/reddit.ts +2 -2
  16. package/dist/connectors/rss.ts +2 -2
  17. package/dist/connectors/slack-identity.ts +19 -0
  18. package/dist/connectors/whatsapp_web.ts +5 -4
  19. package/dist/connectors/x.ts +32 -17
  20. package/dist/connectors/youtube.ts +18 -5
  21. package/dist/db/migrations/20260915030000_owner_dm_delivery_request_platform.sql +51 -0
  22. package/dist/db/migrations/20260917000000_views.sql +271 -0
  23. package/dist/db/migrations/20260917000001_views_attach_index.sql +14 -0
  24. package/dist/db/migrations/20260918000000_runs_turn_tool_event_uniq.sql +51 -0
  25. package/dist/db/migrations/20260923230000_runs_connector_artifact_hash.sql +32 -0
  26. package/dist/db/migrations/20260924000000_resource_source_files.sql +17 -0
  27. package/dist/dependencies.bun.lock +122 -113
  28. package/dist/guest.bundle.js +78 -10
  29. package/dist/owletto/dist/assets/_-CwFknmeA.js +1 -0
  30. package/dist/owletto/dist/assets/_-DrcppoWh.js +2 -0
  31. package/dist/owletto/dist/assets/_agentId-Cr57JKYx.js +1 -0
  32. package/dist/owletto/dist/assets/_agentId-HNcmgH56.js +1 -0
  33. package/dist/owletto/dist/assets/_automationId-BCfrLnUS.js +1 -0
  34. package/dist/owletto/dist/assets/{_connectorKey._connectionId-NQf43Ew3.js → _connectorKey._connectionId-126-iG9w.js} +1 -1
  35. package/dist/owletto/dist/assets/{_connectorKey.index-D-0ZNsgM.js → _connectorKey.index-CywE9A3N.js} +1 -1
  36. package/dist/owletto/dist/assets/_conversationId-CNETA_rY.js +1 -0
  37. package/dist/owletto/dist/assets/_deploymentId-CAVpXf8s.js +1 -0
  38. package/dist/owletto/dist/assets/_name-BP7OlVxL.js +1 -0
  39. package/dist/owletto/dist/assets/_owner-D2eh4R90.js +1 -0
  40. package/dist/owletto/dist/assets/_shape-BqV8tSfw.js +1 -0
  41. package/dist/owletto/dist/assets/_skillKey-2xTjhL_C.js +1 -0
  42. package/dist/owletto/dist/assets/_slug-DoIaJBbh.js +1 -0
  43. package/dist/owletto/dist/assets/_viewKey-8ePnWEg-.js +1 -0
  44. package/dist/owletto/dist/assets/_viewKey-D8rjUFLV.js +1 -0
  45. package/dist/owletto/dist/assets/_viewKey-DhVOkzYd.js +1 -0
  46. package/dist/owletto/dist/assets/accept-invitation-BWRiEUsd.js +1 -0
  47. package/dist/owletto/dist/assets/activity-route-view-rVdTeVXN.js +1 -0
  48. package/dist/owletto/dist/assets/{agent-card-controls-VJgcB5-0.js → agent-card-controls-JubkhcHt.js} +1 -1
  49. package/dist/owletto/dist/assets/{agent-client-setup-list-C5KRNRw3.js → agent-client-setup-list-Btcy4Cu1.js} +1 -1
  50. package/dist/owletto/dist/assets/{agent-connect-pages-BFSb6vmW.js → agent-connect-pages-Chfqn8iL.js} +1 -1
  51. package/dist/owletto/dist/assets/{agent-editor-form-CajEehVn.js → agent-editor-form-BrOkwfg8.js} +1 -1
  52. package/dist/owletto/dist/assets/{agent-guardrails-route-CZ_rXj-3.js → agent-guardrails-route-CHM7JbIl.js} +1 -1
  53. package/dist/owletto/dist/assets/{agent-loading-shells-Dczhk067.js → agent-loading-shells-DsiGx1fn.js} +1 -1
  54. package/dist/owletto/dist/assets/{agent-permissions-matrix-DIVHvpZG.js → agent-permissions-matrix-L_gFvSu1.js} +1 -1
  55. package/dist/owletto/dist/assets/{agent-skill-context-CxglCznW.js → agent-skill-context-D7tOJ8Pb.js} +1 -1
  56. package/dist/owletto/dist/assets/{agent-skills-route-CatU8soC.js → agent-skills-route-AylS-B9v.js} +1 -1
  57. package/dist/owletto/dist/assets/{agent-subpage-shell-DVSUdIBn.js → agent-subpage-shell-B7tCQ9zd.js} +1 -1
  58. package/dist/owletto/dist/assets/agent-thread-DOYh7WLW.js +8 -0
  59. package/dist/owletto/dist/assets/agents-0ncYwbz6.js +1 -0
  60. package/dist/owletto/dist/assets/agents-workbench-DOwn78eL.js +1 -0
  61. package/dist/owletto/dist/assets/app-bridge-BH3g2mKG.js +127 -0
  62. package/dist/owletto/dist/assets/{app._appId-BXmITXO7.js → app._appId-fJ_RRn1Z.js} +1 -1
  63. package/dist/owletto/dist/assets/automation-detail-content-CMprQht5.js +1 -0
  64. package/dist/owletto/dist/assets/automations-0ncYwbz6.js +1 -0
  65. package/dist/owletto/dist/assets/{calendar-taCoBmAh.js → calendar-BbD1N97u.js} +1 -1
  66. package/dist/owletto/dist/assets/{callback-CJxC8u_x.js → callback-PELM84Lh.js} +1 -1
  67. package/dist/owletto/dist/assets/{card-kpw3EaKC.js → card-DpLjEqIc.js} +1 -1
  68. package/dist/owletto/dist/assets/{claim-DLHRN0bA.js → claim-BLLvLOBM.js} +1 -1
  69. package/dist/owletto/dist/assets/clients-Bd8WpHSV.js +1 -0
  70. package/dist/owletto/dist/assets/{code-editor-D3X0yQdI.js → code-editor-DGJQDoHD.js} +1 -1
  71. package/dist/owletto/dist/assets/connect-Cx49f4J0.js +1 -0
  72. package/dist/owletto/dist/assets/connect._clientId-BDFBqKSA.js +1 -0
  73. package/dist/owletto/dist/assets/connected._clientId-BYGmFRCF.js +1 -0
  74. package/dist/owletto/dist/assets/{connection-DdBkXNbX.js → connection-B0O8OZuK.js} +1 -1
  75. package/dist/owletto/dist/assets/{connection-feed-detail-DF93zx0A.js → connection-feed-detail-DZjtoEfm.js} +1 -1
  76. package/dist/owletto/dist/assets/{connector-provenance-N3sc0nbo.js → connector-provenance-D_g9gGXU.js} +1 -1
  77. package/dist/owletto/dist/assets/{connectors-Ckn_aoNE.js → connectors-BiMMm_QQ.js} +1 -1
  78. package/dist/owletto/dist/assets/{consent-Bi6KCVtT.js → consent-CIzW-960.js} +1 -1
  79. package/dist/owletto/dist/assets/{core.esm-CFYXLQXH.js → core.esm-Ds4Nuq9d.js} +1 -1
  80. package/dist/owletto/dist/assets/create--fsxroj2.js +1 -0
  81. package/dist/owletto/dist/assets/create-BqL-ahEf.js +1 -0
  82. package/dist/owletto/dist/assets/{create-BiHpu2f4.js → create-BvCaqhwK.js} +1 -1
  83. package/dist/owletto/dist/assets/create-automation-form-DN2w080o.js +2 -0
  84. package/dist/owletto/dist/assets/{create._connectorKey-Qynix_hA.js → create._connectorKey--qDi1h6S.js} +1 -1
  85. package/dist/owletto/dist/assets/{cronstrue-D7xlYtGk.js → cronstrue-h8_zIyZD.js} +1 -1
  86. package/dist/owletto/dist/assets/deployments-BROg1Te8.js +1 -0
  87. package/dist/owletto/dist/assets/deployments-ICDss7yS.js +1 -0
  88. package/dist/owletto/dist/assets/deployments-body-DulCUAMt.js +1 -0
  89. package/dist/owletto/dist/assets/device-kTL2l_cz.js +1 -0
  90. package/dist/owletto/dist/assets/{device-pin-tombstone-DrTJYNKG.js → device-pin-tombstone-BmD4pv_e.js} +1 -1
  91. package/dist/owletto/dist/assets/device-rows-BqudjhFu.js +1 -0
  92. package/dist/owletto/dist/assets/{device._deviceId-CIe7taim.js → device._deviceId-CsLJJ6jv.js} +1 -1
  93. package/dist/owletto/dist/assets/entity-options-ErxYvMDH.js +1 -0
  94. package/dist/owletto/dist/assets/entity-page-CYRAwUGO.js +1 -0
  95. package/dist/owletto/dist/assets/entity-type-page-BlAizGlz.js +1 -0
  96. package/dist/owletto/dist/assets/event-page-DTXPxc-E.js +1 -0
  97. package/dist/owletto/dist/assets/events-feed-L3c-LLiJ.js +1 -0
  98. package/dist/owletto/dist/assets/{full-page-spinner-DTSqneUO.js → full-page-spinner-BxcYpJXx.js} +1 -1
  99. package/dist/owletto/dist/assets/guardrails-Dh4adTXY.js +1 -0
  100. package/dist/owletto/dist/assets/identity-B8lKn0je.js +1 -0
  101. package/dist/owletto/dist/assets/{index-jGZeANLE.js → index--lEHrFE4.js} +1 -1
  102. package/dist/owletto/dist/assets/{index-CMOHHdFH.js → index-13rywWam.js} +1 -1
  103. package/dist/owletto/dist/assets/{index-Bq4m-sK0.js → index-BRvT0VV9.js} +1 -1
  104. package/dist/owletto/dist/assets/index-BUp24ZJr.js +1 -0
  105. package/dist/owletto/dist/assets/index-B_-MLsof.js +1 -0
  106. package/dist/owletto/dist/assets/index-Bq-q4Y7E.js +1 -0
  107. package/dist/owletto/dist/assets/index-C8CR2-Ck.css +1 -0
  108. package/dist/owletto/dist/assets/{index-OUb5Mlez.js → index-CDz3-ieP.js} +10 -10
  109. package/dist/owletto/dist/assets/index-CFkj9iR_.js +1 -0
  110. package/dist/owletto/dist/assets/index-CgBgOElA.js +1 -0
  111. package/dist/owletto/dist/assets/{index-DkKALC2l.js → index-CheCJomo.js} +1 -1
  112. package/dist/owletto/dist/assets/index-CpiW66xK.js +1 -0
  113. package/dist/owletto/dist/assets/index-DAv5S2aK.js +1 -0
  114. package/dist/owletto/dist/assets/index-DBi2Xr3i.js +1 -0
  115. package/dist/owletto/dist/assets/index-DHOha5OJ.js +1 -0
  116. package/dist/owletto/dist/assets/index-DdGjY1Hb.js +7898 -0
  117. package/dist/owletto/dist/assets/index-Dkyl7l6E.js +1 -0
  118. package/dist/owletto/dist/assets/{index-DYe_DVHa.js → index-QcHQZI87.js} +1 -1
  119. package/dist/owletto/dist/assets/index-kq4537-S.js +1 -0
  120. package/dist/owletto/dist/assets/{json-diff-CANZD4MQ.js → json-diff-BV2STDGj.js} +2 -2
  121. package/dist/owletto/dist/assets/{list-skeleton-DZTUxpBx.js → list-skeleton-CT5n4ND_.js} +1 -1
  122. package/dist/owletto/dist/assets/login-DKsgABYt.js +1 -0
  123. package/dist/owletto/dist/assets/logout-D_CP-emw.js +1 -0
  124. package/dist/owletto/dist/assets/member-scope-gate-BTgmlfFJ.js +1 -0
  125. package/dist/owletto/dist/assets/memory-browse-page-FHaJC3ML.js +101 -0
  126. package/dist/owletto/dist/assets/missing-view-Bve6pJP-.js +1 -0
  127. package/dist/owletto/dist/assets/{model-selector-CvU3VP90.js → model-selector-BLCEahny.js} +1 -1
  128. package/dist/owletto/dist/assets/models-C4N7LQAW.js +1 -0
  129. package/dist/owletto/dist/assets/new-BAIGSdfp.js +1 -0
  130. package/dist/owletto/dist/assets/{new-DIjOVXrQ.js → new-CirOK0Sw.js} +1 -1
  131. package/dist/owletto/dist/assets/new-DzapH2sV.js +1 -0
  132. package/dist/owletto/dist/assets/{oauth-workspace-access-DWfiekRz.js → oauth-workspace-access-BF7jaswv.js} +1 -1
  133. package/dist/owletto/dist/assets/{organization-DHEC7kDq.js → organization-D9RPsWG-.js} +1 -1
  134. package/dist/owletto/dist/assets/{permissions-i7iwnE1a.js → permissions-BlRONw-u.js} +1 -1
  135. package/dist/owletto/dist/assets/{proposal-review-shell-C_LcyUEF.js → proposal-review-shell-uskeFIUr.js} +1 -1
  136. package/dist/owletto/dist/assets/{recent-By19_Buq.js → recent-CmJ4Is6V.js} +1 -1
  137. package/dist/owletto/dist/assets/{renderer-B1UThnk2.js → renderer-Dyf4t8kR.js} +2 -2
  138. package/dist/owletto/dist/assets/{reset-password-Dsz5-Xeo.js → reset-password-BVIeE1Zm.js} +1 -1
  139. package/dist/owletto/dist/assets/runs-CzBeUzlQ.js +1 -0
  140. package/dist/owletto/dist/assets/{runs-panel-wkV1aGD9.js → runs-panel-D7l1uLGm.js} +1 -1
  141. package/dist/owletto/dist/assets/runs-table-dATyiBg2.js +1 -0
  142. package/dist/owletto/dist/assets/{schema-value-normalization--DhnhJNf.js → schema-value-normalization-DgMkyVVE.js} +1 -1
  143. package/dist/owletto/dist/assets/settings-BK1GHmzb.js +1 -0
  144. package/dist/owletto/dist/assets/{settings-Bu239SXe.js → settings-Co1wj_m6.js} +1 -1
  145. package/dist/owletto/dist/assets/skills-DF53JcYt.js +1 -0
  146. package/dist/owletto/dist/assets/{switch-CCKllS7w.js → switch-DDkPrV3p.js} +1 -1
  147. package/dist/owletto/dist/assets/use-applied-views-DELwQQh7.js +1 -0
  148. package/dist/owletto/dist/assets/{use-mention-search-CldNZTiT.js → use-mention-search-CGA3AaKm.js} +1 -1
  149. package/dist/owletto/dist/assets/view-frame-DDr-Xtet.js +1 -0
  150. package/dist/owletto/dist/index.html +2 -2
  151. package/dist/server-main.bundle.mjs +16460 -12976
  152. package/npm-shrinkwrap.json +593 -559
  153. package/package.json +5 -2
  154. package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
  155. package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
  156. package/vendor/connector-sdk/dist/connector-types.d.ts +28 -13
  157. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
  158. package/vendor/connector-sdk/dist/define-connector.js +4 -1
  159. package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
  160. package/vendor/connector-sdk/dist/http-client.js +15 -13
  161. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  162. package/vendor/connector-sdk/dist/retry.d.ts +15 -3
  163. package/vendor/connector-sdk/dist/retry.js +40 -64
  164. package/vendor/connector-sdk/package.json +1 -1
  165. package/vendor/core/dist/agent-policy.js +3 -0
  166. package/vendor/core/dist/connector-query-errors.d.ts +3 -3
  167. package/vendor/core/dist/connector-query-errors.js +8 -3
  168. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
  169. package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
  170. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
  171. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
  172. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
  173. package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
  174. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
  175. package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
  176. package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
  177. package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
  178. package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
  179. package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
  180. package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
  181. package/vendor/core/dist/contracts/tools/source-files.js +55 -0
  182. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
  183. package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
  184. package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
  185. package/vendor/core/dist/contracts/tools/view-path.js +24 -0
  186. package/vendor/core/dist/contracts/worker/protocol.d.ts +73 -8
  187. package/vendor/core/dist/contracts/worker/protocol.js +58 -9
  188. package/vendor/core/dist/credentials.d.ts +16 -1
  189. package/vendor/core/dist/credentials.js +10 -1
  190. package/vendor/core/dist/reserved.d.ts +3 -3
  191. package/vendor/core/dist/reserved.js +9 -1
  192. package/vendor/core/dist/utils/secret-redaction.js +2 -0
  193. package/vendor/core/package.json +25 -5
  194. package/vendor/views/dist/api.d.ts +179 -0
  195. package/vendor/views/dist/api.js +406 -0
  196. package/vendor/views/dist/bridge.d.ts +141 -0
  197. package/vendor/views/dist/bridge.js +330 -0
  198. package/vendor/views/dist/index.d.ts +12 -0
  199. package/vendor/views/dist/index.js +10 -0
  200. package/vendor/views/package.json +35 -0
  201. package/dist/owletto/dist/assets/_-CfcfHJO8.js +0 -1
  202. package/dist/owletto/dist/assets/_-DdvHIadV.js +0 -2
  203. package/dist/owletto/dist/assets/_agentId-BTmFhpb6.js +0 -1
  204. package/dist/owletto/dist/assets/_agentId-DbTBU4KZ.js +0 -1
  205. package/dist/owletto/dist/assets/_automationId-C7dZzg6X.js +0 -1
  206. package/dist/owletto/dist/assets/_conversationId-F5YmyLV9.js +0 -1
  207. package/dist/owletto/dist/assets/_deploymentId-3LTMi0ZT.js +0 -1
  208. package/dist/owletto/dist/assets/_name-BKeZbc-h.js +0 -1
  209. package/dist/owletto/dist/assets/_owner-DglbbDEx.js +0 -1
  210. package/dist/owletto/dist/assets/_skillKey-DhiGYYFq.js +0 -1
  211. package/dist/owletto/dist/assets/_slug-CnQDfsCE.js +0 -1
  212. package/dist/owletto/dist/assets/accept-invitation-Dgoyublh.js +0 -1
  213. package/dist/owletto/dist/assets/activity-route-view-BNzKO6aD.js +0 -1
  214. package/dist/owletto/dist/assets/agent-thread-DnLUOzXk.js +0 -134
  215. package/dist/owletto/dist/assets/agents-OLmcj-qM.js +0 -1
  216. package/dist/owletto/dist/assets/agents-workbench-BOKifKIO.js +0 -1
  217. package/dist/owletto/dist/assets/automation-detail-content-wJC9hhmA.js +0 -1
  218. package/dist/owletto/dist/assets/automations-OLmcj-qM.js +0 -1
  219. package/dist/owletto/dist/assets/clients-R4JsT_Fz.js +0 -1
  220. package/dist/owletto/dist/assets/connect-1ysEq9l0.js +0 -1
  221. package/dist/owletto/dist/assets/connect._clientId-BbMPs6l3.js +0 -1
  222. package/dist/owletto/dist/assets/connected._clientId-ByH4etku.js +0 -1
  223. package/dist/owletto/dist/assets/create-C37QtjbJ.js +0 -1
  224. package/dist/owletto/dist/assets/create-automation-form-Cv2RHsQ6.js +0 -1
  225. package/dist/owletto/dist/assets/create-kAQa5_Q7.js +0 -1
  226. package/dist/owletto/dist/assets/deployments-C5kSeowq.js +0 -1
  227. package/dist/owletto/dist/assets/deployments-body-BPCALbQe.js +0 -1
  228. package/dist/owletto/dist/assets/device-DToHXxDM.js +0 -1
  229. package/dist/owletto/dist/assets/device-rows-fVm-zAiU.js +0 -1
  230. package/dist/owletto/dist/assets/entity-options-DOGD_EyZ.js +0 -1
  231. package/dist/owletto/dist/assets/entity-page-C8oDszRY.js +0 -1
  232. package/dist/owletto/dist/assets/entity-type-page-BfxIgJLq.js +0 -1
  233. package/dist/owletto/dist/assets/events-feed-B9OqmSBy.js +0 -1
  234. package/dist/owletto/dist/assets/guardrails-9Mr6avxk.js +0 -1
  235. package/dist/owletto/dist/assets/identity-DMfCjdBz.js +0 -1
  236. package/dist/owletto/dist/assets/index-Bfux0kHb.js +0 -7898
  237. package/dist/owletto/dist/assets/index-CK2-iHcz.js +0 -1
  238. package/dist/owletto/dist/assets/index-COgBJ_ab.js +0 -1
  239. package/dist/owletto/dist/assets/index-ChcQMdod.css +0 -1
  240. package/dist/owletto/dist/assets/index-CkwwaMrx.js +0 -1
  241. package/dist/owletto/dist/assets/index-D0lZrXrY.js +0 -1
  242. package/dist/owletto/dist/assets/index-DZadnZpq.js +0 -1
  243. package/dist/owletto/dist/assets/index-DcWyuLQS.js +0 -1
  244. package/dist/owletto/dist/assets/index-DlqjyZKQ.js +0 -1
  245. package/dist/owletto/dist/assets/index-Dv0huHrO.js +0 -1
  246. package/dist/owletto/dist/assets/index-DxIDxgPJ.js +0 -1
  247. package/dist/owletto/dist/assets/index-bKUccXCc.js +0 -1
  248. package/dist/owletto/dist/assets/login-D53geSP7.js +0 -1
  249. package/dist/owletto/dist/assets/logout-DKQS25qd.js +0 -1
  250. package/dist/owletto/dist/assets/member-scope-gate-C4QyRm2Q.js +0 -1
  251. package/dist/owletto/dist/assets/memory-browse-page-DOpV3vht.js +0 -101
  252. package/dist/owletto/dist/assets/models-ooBIWFuB.js +0 -1
  253. package/dist/owletto/dist/assets/new-B8_sRMYD.js +0 -1
  254. package/dist/owletto/dist/assets/new-Df1q7GEj.js +0 -1
  255. package/dist/owletto/dist/assets/runs-BQ11PAQT.js +0 -1
  256. package/dist/owletto/dist/assets/runs-table-DzSWYkaf.js +0 -1
  257. package/dist/owletto/dist/assets/settings-FxbIvOhH.js +0 -1
  258. package/dist/owletto/dist/assets/skills-MBZ5ilDK.js +0 -1
  259. package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
  260. package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
@@ -1 +0,0 @@
1
- import{j as t,a0 as o}from"./index-Bfux0kHb.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +0,0 @@
1
- import{j as s,cN as N,cO as $,cP as L,aj as x,cQ as M,cR as I,a2 as b,a3 as S,Y as j,bM as k,bv as w,r as O,a0 as P,gi as W,gj as D,cZ as R,gk as E,gl as F,a1 as y,g as G,L as H,p as U}from"./index-Bfux0kHb.js";import{A as _}from"./agent-editor-form-CajEehVn.js";import{P as z}from"./proposal-review-shell-C_LcyUEF.js";function Q({identity:e,sections:n,activeSection:t,activeItem:o,onSectionSelect:r,sectionLabel:c,highlightSection:l=!0,className:g}){const a=o??n.find(i=>i.key===t)??n[0];if(!a)return null;const d=a.icon;return s.jsx("div",{className:x("flex shrink-0 flex-col items-center px-4 lg:px-6",g),children:s.jsxs("div",{className:"flex min-w-0 max-w-full flex-wrap items-center justify-center gap-x-3 gap-y-2",children:[e,s.jsxs(N,{children:[s.jsx($,{asChild:!0,children:s.jsxs("button",{type:"button",className:x("inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-sm transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring",l?"bg-muted font-medium text-foreground":"text-muted-foreground hover:bg-muted/60 hover:text-foreground"),"aria-label":c,children:[s.jsx(d,{className:"h-3.5 w-3.5 shrink-0"}),a.label,s.jsx(L,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),s.jsx(M,{align:"center",className:"min-w-[11rem]",children:n.map(({key:i,label:u,icon:m})=>s.jsxs(I,{className:x(i===t&&"bg-accent font-medium"),onSelect:()=>r(i),children:[s.jsx(m,{className:"h-4 w-4"}),s.jsx("span",{children:u})]},i))})]})]})})}const p=[{key:"skills",label:"Skills",icon:W},{key:"guardrails",label:"Guardrails",icon:D},{key:"permissions",label:"Permissions",icon:R,adminOnly:!0},{key:"models",label:"Models",icon:E},{key:"settings",label:"Settings",icon:F}];function T(e){return p.filter(n=>!n.adminOnly||e)}function Y(e,n){if(n===`${e}/conversations`||n.startsWith(`${e}/conversations/`))return null;for(const{key:t}of p)if(n===`${e}/${t}`||n.startsWith(`${e}/${t}/`))return t;return n===`${e}/identity`||n===`${e}/identity/`?"settings":null}function Z(e){return e.trim().charAt(0).toUpperCase()||"?"}function q({owner:e,agentId:n,agentName:t,activeDest:o}){const r=b(),{orgContext:c}=y(),{isAdmin:l}=G(c.organizationId),g=T(!!l),a=o??"settings",d=p.find(i=>i.key===a);return s.jsx(Q,{identity:s.jsxs(H,{to:"/$owner/agents/$agentId/settings",params:{owner:e,agentId:n},search:{run_id:void 0},className:"flex min-w-0 items-center gap-2 rounded-md outline-none transition-colors hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring",title:"Agent settings",children:[s.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-muted text-xs font-semibold text-foreground",children:Z(t)}),s.jsx("h1",{className:"min-w-0 truncate text-base font-semibold tracking-tight",children:t})]}),sections:g,activeSection:a,activeItem:d,sectionLabel:"Agent section",highlightSection:o!==null,onSectionSelect:i=>{r({to:`/$owner/agents/$agentId/${i}`,params:{owner:e,agentId:n}})}})}function X({owner:e,agentId:n}){const t=b(),{pathname:o}=S(),{isAuthenticated:r}=j(),{isMember:c}=k(),l=r&&c,{data:g=[],isLoading:a}=w({enabled:l}),d=g.find(C=>C.agentId===n)??null,i=!d&&!a&&l,u=`/${e}/agents/${n}`,m=`${u}/conversations`,f=o===m||o.startsWith(`${m}/`),h=Y(u,o);O.useEffect(()=>{i&&t({to:"/$owner",params:{owner:e},replace:!0})},[i,t,e]);const A=d?.name??"Agent";return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-hidden py-4 md:py-6",children:[s.jsx(q,{owner:e,agentId:n,agentName:A,activeDest:h}),s.jsx("div",{className:x("flex min-h-0 min-w-0 flex-1 flex-col px-4 lg:px-6",f?"overflow-hidden":"overflow-y-auto"),children:s.jsx(P,{})})]})}function B({agent:e,tab:n,runId:t}){return s.jsx("div",{className:"mx-auto w-full max-w-3xl pb-6",children:s.jsx(z,{resource:{kind:"agent",agentId:e.agentId},runId:t,children:({reviewMode:o,proposal:r,controlsDisabled:c})=>s.jsx(_,{mode:{kind:"edit",agent:e},section:n,reviewMode:o,reviewProposal:r,reviewControlsDisabled:c},e.agentId)})})}function ee({owner:e,agentId:n,tab:t,runId:o}){const{orgContext:r,hasOrgContext:c}=y(),{isLoading:l}=U(`/${e}`,r),{isAuthenticated:g}=j(),{isMember:a,isLoading:d}=k(),i=g&&a,{data:u=[],isLoading:m}=w({enabled:i}),v=i?!c||l||m||d:l||d,f=u.find(h=>h.agentId===n)??null;return v||!f?null:s.jsx(B,{agent:f,tab:t,runId:o})}export{X as A,ee as a};
@@ -1 +0,0 @@
1
- import{ed as R,ee as P,ef as E,eg as L,eh as M,r as A,ei as D,J as B,j as s,cx as U,G as N,a1 as F,p as J,Y as H,bM as K,S as I,ej as V,ek as _,B as $,L as S,e5 as T,aj as W,aS as Y,ce as z}from"./index-Bfux0kHb.js";import{C as G,A as X}from"./create-automation-form-Cv2RHsQ6.js";import{P as q}from"./proposal-review-shell-C_LcyUEF.js";import{A as Q}from"./agent-loading-shells-Dczhk067.js";import{b as Z,a as ee,s as te,h as ne,R as oe,A as re}from"./agent-thread-DnLUOzXk.js";import{E as se}from"./events-feed-B9OqmSBy.js";import{J as ie}from"./json-diff-CANZD4MQ.js";const k=Symbol("trusted-automation-interaction");function j(e){return Object.defineProperty(e,k,{value:!0}),e}function ae(e){return{title:`${e} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${e} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${e} proposals.`},{id:"reject-all",label:"Keep all separate",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${e} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${e} proposals.`}]}}const le=new Set(["entity-merge-approval","automation-approval-batch","entity-merge-result"]);function b(e){return new Promise(r=>{e({onSettled:(n,o)=>r(!!o)})})}function C(e){try{return new URL(e,window.location.origin).origin===window.location.origin}catch{return!1}}function ue(){const e=R(),r=P(),n=E(),o=L(),u=M();return A.useMemo(()=>({toolNames:le,resolve:(f,m)=>{if(!m||typeof m!="object"||m[k]!==!0)return null;const t=m;if(f==="automation-approval-batch"){const p=typeof t.runId=="number"&&Number.isSafeInteger(t.runId)&&t.runId>0?t.runId:null,l=typeof t.count=="number"&&Number.isSafeInteger(t.count)&&t.count>1?t.count:null,a=Array.isArray(t.runIds)?t.runIds.filter(c=>typeof c=="number"&&Number.isSafeInteger(c)&&c>0):[];return p===null||l===null||a.length!==l||new Set(a).size!==l?null:{view:ae(l),handlers:{manage_operations:c=>c.action!=="approve"&&c.action!=="reject"?Promise.resolve(!0):b(v=>c.action==="approve"?e.mutate({run_id:p,run_ids:a},v):r.mutate({run_id:p,run_ids:a},v))}}}if(f==="entity-merge-approval"){const p=typeof t.runId=="number"&&Number.isSafeInteger(t.runId)&&t.runId>0?t.runId:null;if(p===null||t.action!=="merge"||t.resourceKind!=="entity")return null;const l=Z(t),a=(t.status??"pending")==="pending";return{view:l.view,handlers:{open_review_link:c=>{const v=typeof c.url=="string"?c.url:"";return!l.reviewUrls.has(v)||!C(v)?Promise.resolve(!0):(window.open(v,"_blank","noopener,noreferrer"),Promise.resolve(!1))},...a?{manage_operations:c=>c.action==="approve"?b(v=>n.mutate({run_id:p},v)):c.action==="reject"?b(v=>o.mutate({run_id:p},v)):Promise.resolve(!0)}:{}}}}if(f!=="entity-merge-result")return null;const h=t.loser&&typeof t.loser=="object"?t.loser:null,i=typeof h?.id=="number"?h.id:null;if(i===null)return null;const g=ee(t);return{view:g.view,handlers:{open_review_link:p=>{const l=typeof p.url=="string"?p.url:"";return!g.reviewUrls.has(l)||!C(l)?Promise.resolve(!0):(window.open(l,"_blank","noopener,noreferrer"),Promise.resolve(!1))},manage_entity:()=>b(p=>u.mutate({entityId:i},p))}}}}),[n,e,o,r,u])}function ce(e){const r=[];return e.forEach((n,o)=>{r.push({id:`sep:${n.runId}`,role:"system",parts:[{type:"text",text:de(n,o)}],createdAt:n.completedAt?new Date(n.completedAt).getTime():void 0});for(const u of n.messages)r.push({...u,id:`r${n.runId}:${u.id}`})}),r}function de(e,r){const n=(e.pendingActionCount??0)>0?`Waiting for you (${e.pendingActionCount})`:e.status==="completed"?"Completed":e.status??"Completed",o=(e.autoAppliedCount??0)>0?` · ${e.autoAppliedCount} applied automatically`:"",u=e.completedAt?new Date(e.completedAt).toLocaleString():null;return u?`Run ${r+1} · ${n}${o} · ${u}`:`Run ${r+1} · ${n}${o}`}const pe=/(?:^|\n)Run this Automation now/;function me(e){return e.role==="user"&&e.parts.some(r=>r.type==="text"&&pe.test(r.text))}function ge(e){return`history-interaction:${e.runId}:${e.eventId??"error"}`}function fe({agentId:e,automationId:r,ownerSlug:n,runId:o}){const{data:u,isLoading:f}=D(e,r,{orgSlug:n}),m=ue(),t=B(),h=A.useCallback(g=>{t?.open({href:`/${n}/automations/${r}?run_id=${g}`,title:`Automation run #${g}`,runId:g})},[t,n,e,r]),i=A.useMemo(()=>{const g=u?.runs??[],l=(o!=null?g.filter(a=>a.runId===o):g).slice().reverse();return ce(l.map(a=>{const c=a.messages.map(d=>te(d,{showToolCalls:!0})).filter(d=>d!==null&&!me(d));a.task?.trim()&&c.unshift({id:"task",role:"user",parts:[{type:"text",text:a.task.trim()}]});for(const d of a.automaticActions??[]){const x=y=>U(n,[...y.parentEntityType&&y.parentSlug?[{entity_type:y.parentEntityType,slug:y.parentSlug}]:[],{entity_type:y.entityType,slug:y.slug}]);c.push({id:`automatic-action:${d.operationId}`,role:"assistant",parts:[{type:"tool-call",toolCallId:`automatic-action-${d.operationId}`,toolName:"entity-merge-result",args:j({...d,loserHref:x(d.loser),winnerHref:x(d.winner)})}]})}const v=a.actions??[],w=v.filter(d=>d.status==="pending");if(w.length>1){const d=w.map(x=>x.runId).sort((x,y)=>x-y);c.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${a.runId}`,toolName:"automation-approval-batch",args:j({runId:a.runId,count:w.length,runIds:d})}]})}for(const d of v){const x=ne([d],{workspaceSlug:n,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin});x&&c.push({...x,id:ge(d),parts:x.parts.map(y=>y.type==="tool-call"&&y.toolName==="tool-approval"&&d.action==="merge"&&d.resourceKind==="entity"?{...y,toolName:"entity-merge-approval",args:j({...y.args})}:y)})}return{runId:a.runId,completedAt:a.completedAt,status:a.status,pendingActionCount:a.pendingActionCount,autoAppliedCount:a.autoAppliedCount,messages:c}}))},[e,u,n,o]);return f?s.jsx(Q,{readOnly:!0}):i.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):s.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:s.jsx(oe,{messages:i,children:s.jsx(re,{readOnly:!0,readerPositionMode:"runs",interactionExtension:m,onRunSelect:o==null&&t?h:void 0})})})}function O(e){const{orgContext:r,hasOrgContext:n}=F(),{data:o,isLoading:u}=J(`/${e}`,r),{isAuthenticated:f}=H(),{isMember:m,isLoading:t}=K(),h=f&&m,i=o?.workspace,g=h?!n||u||t:u||t;return{organizationId:i?.id??"",isLoading:g}}function Ie(e){return O(e)}function he({owner:e,automationId:r,organizationId:n}){const{data:o,isLoading:u}=V(r,n),f=o?.length??0,m=f>_,t=Math.min(f,_),h=new Set(o?.map(a=>a.entity_type).filter(Boolean)??[]),i=!m&&h.size===1?[...h][0]:null;if(u)return s.jsx(I,{className:"h-10 w-full rounded-lg"});if(t===0)return null;const g=m?`${_}+`:String(t),p=i!=null?`${g} ${i} ${t===1?"entity":"entities"} built by this automation`:`${g} ${t===1?"entity":"entities"} built by this automation`,l=i!=null?z(e,i):{to:"/$owner/memory",params:{owner:e},search:{}};return s.jsxs("div",{className:W(Y,"flex flex-wrap items-center justify-between gap-2 px-3 py-2.5 text-sm"),children:[s.jsx("span",{className:"text-muted-foreground",children:p}),s.jsx($,{asChild:!0,variant:"ghost",size:"sm",className:"h-7 gap-1",children:s.jsxs(S,{to:l.to,params:l.params,search:l.search,children:["View in Memory",s.jsx(T,{className:"h-3.5 w-3.5"})]})})]})}function ye({owner:e,automationId:r,organizationId:n}){const o=Number(r),u=A.useMemo(()=>({producedByAutomationId:o}),[o]);return Number.isFinite(o)?s.jsxs("section",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h3",{className:"font-medium text-sm",children:"Produced by this Automation"}),s.jsx($,{asChild:!0,variant:"ghost",size:"sm",className:"h-7 gap-1",children:s.jsxs(S,{to:"/$owner/memory",params:{owner:e},search:{produced_by:String(o)},children:["Open in Memory",s.jsx(T,{className:"h-3.5 w-3.5"})]})})]}),s.jsx(se,{organizationId:n,ownerSlug:e,filters:u,emptyState:s.jsx("p",{className:"py-6 text-sm text-muted-foreground",children:"This Automation hasn't written anything yet. Events it creates, entities it changes and notifications it sends will appear here."})})]}):null}function ve({agentId:e,owner:r,automationId:n,organizationId:o}){return s.jsxs("div",{className:"space-y-4",children:[o?s.jsx(he,{owner:r,automationId:n,organizationId:o}):null,e?s.jsx(fe,{agentId:e,automationId:n,ownerSlug:r}):s.jsx("p",{className:"rounded-lg border border-border/60 px-3 py-2.5 text-sm text-muted-foreground",children:"Runs execute on the automation's executor, so there is no agent transcript to show. What it produced is below."}),o?s.jsx(ye,{owner:r,automationId:n,organizationId:o}):null]})}function xe({agentId:e,automationId:r,runId:n,organizationId:o,onDone:u}){const[f,m]=A.useState({ready:!1,triggers:[]}),t=A.useCallback(l=>{m(a=>JSON.stringify(a)===JSON.stringify(l)?a:l)},[]),h=N(r,void 0,o,{includeVersions:!0}),i=h.data?.automation,g=s.jsx("div",{className:"flex flex-col gap-4",children:[0,1,2].map(l=>s.jsx(I,{className:"h-16 w-full rounded-lg"},l))}),p=h.isLoading?g:i?s.jsx(G,{organizationId:o,prefillAgentId:e??void 0,editingAutomation:{automation_id:i.automation_id,name:i.automation_name,slug:i.slug,description:i.description,prompt:i.prompt,sources:i.sources,reaction_script:i.reaction_script,managed_agent_id:i.managed_agent_id,device_worker_id:i.device_worker_id,agent_kind:i.agent_kind,execution_config:i.execution_config??void 0,classifiers:i.classifiers,keying_config:i.keying_config,reactions_guidance:i.reactions_guidance,triggers:i.triggers},createFields:{triggers:f.triggers},triggerFields:s.jsx(X,{organizationId:o,initialTriggers:i.triggers??[],onChange:t},JSON.stringify(i.triggers??[])),hideHeader:!0,hideCancel:!0,submitDisabled:!f.ready,onClose:u,onSuccess:u}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Automation not found. It may have been removed."});return e?s.jsx(q,{resource:{kind:"automation",agentId:e,automationId:r},runId:n,onDone:u,children:({reviewMode:l,proposal:a})=>l==="active"?s.jsx(ie,{before:a?.current??null,after:{...a?.current??{},...a?.proposedAfter??{}}}):l==="loading"?g:l==="error"?null:p}):p}function $e({owner:e,agentId:r,automationId:n,view:o,runId:u,onDone:f}){const{organizationId:m}=O(e),t=N(n,void 0,m),h=r??t.data?.automation?.managed_agent_id??null;return u||o==="definition"?s.jsx(xe,{agentId:h,automationId:n,runId:u,organizationId:m,onDone:f}):s.jsx(ve,{agentId:h,owner:e,automationId:n,organizationId:m})}export{fe as A,$e as a,Ie as u};
@@ -1 +0,0 @@
1
- import{j as t,a0 as o}from"./index-Bfux0kHb.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +0,0 @@
1
- import{dc as c,cE as u,cU as d,cV as p,aD as r,an as o,eJ as i,ag as m}from"./index-Bfux0kHb.js";function l(t,s="",e){const n=`${m}/api/${t}/clients${s}`,a=e?.toString();return a?`${n}?${a}`:n}function h(t,s){const{slug:e}=c();return u({queryKey:["connected-clients",e,t??null],queryFn:async()=>{if(!e)throw new Error("Workspace required");const n=new URLSearchParams;t&&n.set("agentId",t);const a=await o(l(e,"",n),{credentials:"include"});return await i(a,"Failed to load connected clients"),(await a.json()).clients??[]},enabled:!!e&&(s?.enabled??!0),staleTime:15e3,refetchInterval:s?.refetchInterval})}function y(){const{slug:t}=c(),s=d();return p({mutationFn:async e=>{if(!t)throw new Error("Workspace required");const n=new URLSearchParams;e.scope==="all"&&n.set("scope","all");const a=await o(l(t,`/mcp/${encodeURIComponent(e.clientId)}`,n),{method:"DELETE",credentials:"include"});return await i(a,"Failed to revoke client"),await a.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["connected-clients",t]}),r.success("App access revoked")},onError:e=>{r.error(e.message||"Failed to revoke app access")}})}export{y as a,h as u};
@@ -1 +0,0 @@
1
- import{j as t,a0 as o}from"./index-Bfux0kHb.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +0,0 @@
1
- import{ho as r,j as t,aV as a}from"./index-Bfux0kHb.js";import{a as s}from"./agent-connect-pages-BFSb6vmW.js";import"./agent-client-setup-list-C5KRNRw3.js";import"./clients-R4JsT_Fz.js";import"./client-rows-EJSKR6z1.js";function x(){const{owner:e,clientId:o}=r.useParams();return t.jsx(a,{owner:e,children:({ownerSlug:n})=>t.jsx(s,{owner:n,clientId:o})})}export{x as component};
@@ -1 +0,0 @@
1
- import{a2 as E,j as e,cy as _,cz as $,cA as w,cB as c,cC as M,cD as o,L as b,af as z,x as H,V as K,a1 as G,g as V,r as m,dL as I,S,ct as O,fi as f,B as y,s as Q,gH as W,g2 as q,bP as F,g3 as J,g4 as X,hn as Y,aV as Z}from"./index-Bfux0kHb.js";import{u as P,a as ee}from"./clients-R4JsT_Fz.js";import{g as B,r as se}from"./client-rows-EJSKR6z1.js";function A(a,n){return{client_ids:a.join(","),mcp_activity_id:n}}function L(a){const n=a.title?.trim();return n||(a.activityKind==="session"?"MCP session":a.clientId)}function R({scopes:a,clientIds:n}){const l=E(),d=t=>{l({to:"/$owner/events",params:{owner:"me"},search:A(n,t.activityId)})};return e.jsx("div",{className:"rounded-lg border",children:e.jsxs(_,{children:[e.jsx($,{children:e.jsxs(w,{children:[e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Conversation"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Calls"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Last action"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Last active"}),e.jsx(c,{className:"w-8 px-3 py-1.5"})]})}),e.jsx(M,{children:a.map(t=>e.jsxs(w,{className:"cursor-pointer transition-colors hover:bg-accent/50",onClick:()=>d(t),children:[e.jsxs(o,{className:"max-w-0 truncate px-3 py-2 text-xs font-medium",children:[e.jsx(b,{to:"/$owner/events",params:{owner:"me"},search:A(n,t.activityId),onClick:r=>r.stopPropagation(),className:"hover:underline",children:L(t)}),t.unreadNotificationCount>0?e.jsxs(z,{variant:"secondary",className:"ml-2 text-[10px]",children:[t.unreadNotificationCount," unread"]}):null]}),e.jsx(o,{className:"px-3 py-2 font-mono text-xs text-muted-foreground",children:t.callCount}),e.jsx(o,{className:"max-w-0 truncate px-3 py-2 text-xs text-muted-foreground",children:t.lastAction||"—"}),e.jsx(o,{className:"px-3 py-2 text-xs text-muted-foreground",children:H(t.lastCallAt)}),e.jsx(o,{className:"px-3 py-2 text-right",children:e.jsx("button",{type:"button","aria-label":`View ${L(t)} activity`,className:"text-muted-foreground hover:text-foreground",tabIndex:-1,children:e.jsx(K,{className:"h-3.5 w-3.5"})})})]},`${t.clientId}:${t.activityId}`))})]})})}function te({ownerSlug:a,clientId:n}){const{orgContext:l}=G(),{isAdmin:d}=V(l.organizationId),{data:t=[],isLoading:r}=P(null),x=ee(),[T,h]=m.useState(!1),s=m.useMemo(()=>B(t),[t]).find(i=>i.clientIds.includes(n)),N=s?.clientIds??[],g=I({enabled:!!s,limit:100,clientIds:N,activityKind:"conversation"}),p=I({enabled:!!s,limit:100,clientIds:N,activityKind:"session"}),u=g.data??[],v=p.data??[],U=m.useMemo(()=>t.filter(i=>s?.clientIds.includes(i.id)),[t,s]);if(r)return e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{className:"h-16 w-full rounded-lg"}),e.jsx(S,{className:"h-24 w-full rounded-lg"})]});if(!s)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"This app isn't connected to this workspace, so its details aren't available."});const j=U[0],C=j?.details?.redirectUris??[],k=s.linkedUserEntitySlug?O(a,[{entity_type:"$member",slug:s.linkedUserEntitySlug}]):null,D=[{label:"Registered",value:s.title},{label:s.clientIds.length===1?"Client ID":"Client IDs",value:e.jsx("div",{className:"space-y-1",children:s.clientIds.map(i=>e.jsx("code",{className:"block break-all",children:i},i))})},...s.drivenBy&&s.drivenBy!==s.title?[{label:"Driven by",value:s.drivenBy}]:[],...j?.platform?[{label:"Software",value:j.platform}]:[],...C.length>0?[{label:"Redirects",value:C.join(", ")}]:[],{label:"Granted by",value:k&&s.linkedUser?e.jsx(b,{to:k,className:"font-medium text-primary hover:underline",children:s.linkedUser}):s.linkedUser??"—"},{label:"Last active",value:s.connected?se(s.lastSeenAt):"disconnected"},{label:"Registrations",value:String(s.clientIds.length)}];return e.jsxs("div",{className:"space-y-7",children:[e.jsx(f,{title:"Settings",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"overflow-hidden rounded-lg border text-xs",children:e.jsx("dl",{className:"divide-y",children:D.map(i=>e.jsxs("div",{className:"flex gap-3 px-3 py-2",children:[e.jsx("dt",{className:"w-28 shrink-0 text-muted-foreground",children:i.label}),e.jsx("dd",{className:"min-w-0 flex-1 break-words",children:i.value})]},i.label))})}),d&&s.connected?e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Revoking disconnects every registration this app holds",s.clientIds.length>1?` (${s.clientIds.length} of them)`:""," ","and kills its live sessions. It can reconnect by authorizing again."]}),T?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"destructive",size:"sm",className:"h-7 px-2 text-xs",disabled:x.isPending,onClick:()=>x.mutate({clientId:s.clientIds[0],scope:"all"},{onSettled:()=>h(!1)}),children:x.isPending?"Revoking…":"Confirm revoke"}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:x.isPending,onClick:()=>h(!1),children:"Cancel"})]}):e.jsx(y,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs text-destructive hover:text-destructive",onClick:()=>h(!0),children:"Revoke"})]}):null]})}),e.jsx(f,{title:"Conversations",count:u.length>0?String(u.length):void 0,children:g.isLoading||p.isLoading?e.jsxs("div",{className:"flex items-center py-4 text-xs text-muted-foreground",children:[e.jsx(Q,{className:"mr-2"})," Loading client activity…"]}):g.isError||p.isError?e.jsx("p",{className:"py-3 text-xs text-destructive",children:"Could not load this app's activity."}):u.length===0?e.jsx("p",{className:"py-3 text-xs text-muted-foreground",children:"No recent conversations."}):e.jsx(R,{scopes:u,clientIds:s.clientIds})}),v.length>0?e.jsx(f,{title:"Sessions",count:String(v.length),children:e.jsx(R,{scopes:v,clientIds:s.clientIds})}):null]})}const ne="flex min-h-0 flex-1 flex-col gap-3 px-4 pt-4 pb-8 lg:px-6";function ae({owner:a,clientId:n}){const{data:l=[]}=P(null),t=m.useMemo(()=>B(l).find(r=>r.clientIds.includes(n)),[n,l])?.title??"Connected agent";return e.jsx("div",{className:ne,children:e.jsx(W,{header:e.jsx(q,{breadcrumb:e.jsx(J,{crumbs:[e.jsx(b,{to:"/$owner/agents",params:{owner:a},className:X,children:"Agents"},"agents")]}),icon:e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border",children:e.jsx(F,{name:t})}),title:t,caption:"An external agent connected to this workspace through Lobu. Review its Lobu conversations, activity, and access."}),children:e.jsx(te,{ownerSlug:a,clientId:n},n)})})}function oe(){const{owner:a,clientId:n}=Y.useParams();return e.jsx(Z,{owner:a,children:({ownerSlug:l})=>e.jsx(ae,{owner:l,clientId:n})})}export{oe as component};
@@ -1 +0,0 @@
1
- import{hB as o,j as e}from"./index-Bfux0kHb.js";import{a}from"./agent-guardrails-route-CZ_rXj-3.js";import"./model-selector-CvU3VP90.js";import"./agent-subpage-shell-DVSUdIBn.js";import"./agent-loading-shells-Dczhk067.js";import"./agent-card-controls-VJgcB5-0.js";import"./switch-CCKllS7w.js";function x(){const{owner:r,agentId:t}=o.useParams();return e.jsx(a,{owner:r,agentId:t})}export{x as component};
@@ -1 +0,0 @@
1
- import{r as i,j as e,bY as me,bZ as he,b_ as xe,b$ as pe,c0 as P,ab as ae,B as z,X as Jt,a as us,dI as ds,cb as Gt,el as ms,em as hs,S as kt,aa as y,aj as T,aS as Je,en as St,dz as xs,dB as ps,eo as gs,cP as Ht,dC as fs,bx as wt,ep as vs,de as tt,df as $e,aO as et,eq as gt,bw as Yt,P as Ge,cE as ys,an as js,ag as _s,er as Ns,es as bs,et as ks,eu as Ss,ev as ws,af as Cs,L as Es,a1 as Xt,ew as Os,bv as As,bb as Fs,cq as Ct,ex as Ps,ey as Ms,d5 as Ls,ea as Ts,c2 as ht,s as Rs,ez as Ds,eA as Is,eB as qs,eC as $s,eD as Ks,eE as Ws,eF as Bs,eG as zs,eH as Us,by as Vs,c7 as Qs}from"./index-Bfux0kHb.js";import{c as Js}from"./cronstrue-D7xlYtGk.js";import{C as Gs,f as Hs}from"./entity-options-DOGD_EyZ.js";import{S as Ys}from"./switch-CCKllS7w.js";import{a as Xs,A as Zs}from"./device-automation-BIjs7DZJ.js";import{M as en}from"./model-selector-CvU3VP90.js";import{b as tn}from"./skill-editor-D_W3QlRz.js";import{C as Ze}from"./code-editor-D3X0yQdI.js";import{u as sn,M as Et,a as Ot,s as nn,o as an,b as on,c as rn,d as cn,e as ln,v as un,r as dn}from"./use-mention-search-CldNZTiT.js";const Xe=[{value:"*/15 * * * *",label:"Every 15 minutes"},{value:"0 * * * *",label:"Every hour"},{value:"0 */6 * * *",label:"Every 6 hours"},{value:"0 9 * * *",label:"Daily at 9:00 AM"},{value:"0 18 * * *",label:"Daily at 6:00 PM"},{value:"0 9 * * 1-5",label:"Weekdays at 9:00 AM"},{value:"0 9 * * 1",label:"Weekly · Monday 9:00 AM"},{value:"0 9 1 * *",label:"Monthly · 1st at 9:00 AM"},{value:"custom",label:"Custom cron…"}];function mn(n){const t=n.trim();if(!t)return null;try{return Js.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function hn({value:n,onChange:t,placeholder:s="No schedule",className:d}){const u=n??"",m=Xe.some(f=>f.value===u),[c,o]=i.useState(!m&&u!==""),r=f=>{f==="custom"?o(!0):(o(!1),t(f))},j=u?mn(u):null,R=u?e.jsx("p",{className:j?"text-xs text-muted-foreground":"text-xs text-destructive",children:j??"Not a valid cron expression."}):null;return!u&&!c?e.jsxs(me,{onValueChange:r,children:[e.jsx(he,{className:d??"w-full",children:e.jsx(xe,{placeholder:s})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(ae,{placeholder:"0 */6 * * *",value:u,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(me,{value:u,onValueChange:r,children:[e.jsx(he,{className:d??"w-full flex-1",children:e.jsx(xe,{children:Xe.find(f=>f.value===u)?.label??u})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),t("")},children:e.jsx(Jt,{className:"h-4 w-4"})})]}),R]})}const lt="__all_workspace_event_types__",xn=[],pn={};function At(n,t,s){const d=new Map;if(!t)for(const[m,c]of Object.entries(s??{}))d.set(m,{key:m,label:wt(m),description:c.description});const u=[...n].filter(m=>!t||m.slug===t).sort((m,c)=>m.slug.localeCompare(c.slug));for(const m of u)for(const[c,o]of Object.entries(m.event_kinds??{})){const r=d.get(c);if(r){!r.description&&o.description&&(r.description=o.description),JSON.stringify(r.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(r.metadataSchema=void 0);continue}d.set(c,{key:c,label:wt(c),description:o.description,metadataSchema:o.metadataSchema})}return[...d.values()].sort((m,c)=>m.label.localeCompare(c.label))}function Ft(n){const t=n[0];if(!t)return;const s=u=>JSON.stringify(Object.keys(u?.properties??{}).sort()),d=s(t);return n.every(u=>s(u)===d)?t:void 0}function Pt(n,t,s){const d=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([u])=>!d.has(u))),...s}}function Ie(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Mt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Lt(n,t,s){const d=new Set(Object.keys(t?.properties??{})),u=new Set(s.flatMap(m=>Object.keys(m.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(vs(n)).filter(([m])=>m==="resource_ref"||m==="resource_type"||!u.has(m)||d.has(m)))}function gn({value:n,options:t,onChange:s}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:t.map(d=>e.jsx("button",{type:"button","aria-pressed":n===d.value,onClick:()=>s(d.value),className:T("rounded px-3 py-1 transition-colors",n===d.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:d.label},d.value))})}function Tt({events:n,selectedKeys:t,onToggle:s,ariaLabel:d="Events"}){const u=i.useId(),m=n.filter(o=>t.includes(o.key)).map(o=>o.label),c=m.length===0?"Choose events":m.length===1?m[0]:`${m.length} events selected`;return e.jsx(tt,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-label":d,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:T(m.length===0&&"text-muted-foreground"),children:c}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,r)=>{const j=t.includes(o.key),R=`${u}-${r}-state`;return e.jsxs($e,{value:`${o.label} ${o.key}`,onSelect:()=>s(o.key),"aria-label":o.label,"aria-describedby":R,className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",j?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:R,className:"sr-only",children:j?"Selected":"Not selected"})]},o.key)})})}function fn({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:d,showSectionHeader:u=!0,fieldIdPrefix:m="automation-trigger-"}){const c=us(n,{status:"active",limit:500}),o=ds(n),r=Gt({organizationId:n}),j=ms({organizationId:n}),R=c.data??[],f=o.data??[],B=r.data??xn,h=j.data??pn,v=i.useMemo(()=>B.filter(l=>l.organization_id===n),[B,n]),_=t?.kind==="event"&&t?.source==="workspace",O=_||t===void 0,D=d?.length?[...d]:["event","time","manual"],b=D.join("|"),J=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return D.includes(l)?l:D[0]??"event"})(),[g,M]=i.useState(J),[G,Se]=i.useState(_?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),N=G==="workspace",oe=N?"":G,[k,we]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),Fe=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[C,re]=i.useState(()=>Fe.filter(l=>typeof l=="string")),[H,te]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[be,Pe]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),ce=typeof t?.timezone=="string"?t.timezone:void 0,[$,ge]=i.useState(t?.kind==="schedule"||O&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[Y,V]=i.useState(Qe($,t?.output==="reply_to_source"?"reply_to_source":"silent")),[Q,se]=i.useState(t?.kind==="schedule"||O&&t?.active_run!=="queue"?"coalesce":Ie($,Y,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[ke,Ee]=i.useState(t?.skip_if_unchanged!==!1),[x,K]=i.useState(!1);i.useEffect(()=>{const l=b.split("|");if(!l.includes(g)){const p=l[0]??"event";M(p),ge(p==="time"||p==="event"&&N?"window":"turn"),se(p==="time"||p==="event"&&N?"coalesce":"queue"),V("silent")}},[b,g,N]);const A=R.find(l=>String(l.id)===oe),ie=c.isLoading||o.isLoading,X=r.isLoading,fe=typeof t?.connector_key=="string"?t.connector_key:void 0,U=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===oe&&!A,ye=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&fe!==void 0&&oe==="",Oe=f.find(l=>l.key===(A?.connector_key??(ye?fe:void 0))),le=Oe?.automation_events??[],I=le.filter(l=>C.includes(l.key)),je=I[0],Me=v.find(l=>l.slug===k),Ae=[...v.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===k),...k&&!Me?[{slug:k,name:k}]:[]],ue=i.useMemo(()=>At(v,k||void 0,h),[v,k,h]),Le=ue.filter(l=>C.includes(l.key)),We=Le[0],ve=Ft(I.map(l=>l.filterSchema)),de=Ft(Le.map(l=>l.metadataSchema)),Be=!!(N&&k&&!Me),Te=U||ye,Ce=(g==="event"?N?C.length>0&&!Be:!!(C.length>0&&(oe&&A||Te)):g==="time"?!!be.trim():!0)&&(g!=="event"||!hs(H));i.useEffect(()=>{let l;if(Ce&&g==="event"&&!N){const p=Lt(H,ve,Oe?.automation_events??[]);A||ye?l={kind:"event",source:"connector",connector_key:A?.connector_key??fe,...A?{connection_id:Number(oe)}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Ie($,Y,Q),output:Qe($,Y),skip_if_unchanged:ke}:U&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&g==="event"&&N){const p=Lt(H,de,ue.map(S=>({filterSchema:S.metadataSchema})));l={kind:"event",source:"workspace",...k?{entity_type:k}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Q==="queue"?"queue":"coalesce"}}else Ce&&g==="time"&&(l={kind:"schedule",cron:be.trim(),...ce?{timezone:ce}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:ke});s({ready:Ce,kind:g,trigger:l})},[Q,oe,A,be,Oe,C,$,H,g,fe,ce,t,N,s,Y,Ce,ve,de,ke,k,ue,ye,U]);const nt=l=>{const p=R.find(w=>String(w.id)===l),S=f.find(w=>w.key===p?.connector_key),Z=C.filter(w=>S?.automation_events?.some(De=>De.key===w)),E=S?.automation_events?.find(w=>w.key===Z[0]),_e=p?.connector_key!==(A?.connector_key??fe);if(Se(l),re(Z),!E)te(Mt);else if(_e){const w=E.defaults?.execution??"turn",De=E.defaults?.activeRun??"queue",Ve=Qe(w,E.defaults?.output??"silent");te(Mt),ge(w),se(Ie(w,Ve,De)),V(Ve)}},at=l=>{if(l==="workspace"){Se("workspace"),re(p=>p.filter(S=>ue.some(Z=>Z.key===S))),te({}),ge("window"),se("coalesce"),V("silent");return}nt(l)},ze=l=>{const p=C.includes(l)?C.filter(w=>w!==l):le.map(w=>w.key).filter(w=>w===l||C.includes(w));if(re(p),p[0]===C[0])return;const S=le.find(w=>w.key===p[0]),Z=S?.defaults?.execution??"turn",E=S?.defaults?.activeRun??"queue",_e=Qe(Z,S?.defaults?.output??"silent");ge(Z),se(Ie(Z,_e,E)),V(_e)},He=l=>{const p=l===lt?"":l,S=v.find(E=>E.slug===p),Z=At(v,S?.slug,h);we(p),re(E=>E.filter(_e=>Z.some(w=>w.key===_e))),te({})},Ue=l=>{re(p=>p.includes(l)?p.filter(S=>S!==l):ue.map(S=>S.key).filter(S=>S===l||p.includes(S)))},Re=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>D.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[u?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"When"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose what starts this Automation. Its goal and context stay reusable."})]}):null,Re.length>1?e.jsx(gn,{value:g,options:Re,onChange:l=>{M(l),ge(l==="time"||l==="event"&&N?"window":"turn"),se(l==="time"||l==="event"&&N?"coalesce":"queue"),V("silent")}}):null,g==="event"?ie||N&&X?e.jsxs("div",{className:"space-y-2",children:[e.jsx(kt,{className:"h-9 w-full"}),e.jsx(kt,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Source"}),e.jsx(Gs,{connections:R,value:G,onValueChange:at,disabled:Te,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),U?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This shared connection is managed outside this organization. Other Automation fields can still be edited."}):ye?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(t?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),N?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx(Tt,{events:ue,selectedKeys:C,onToggle:Ue}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:k?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),We?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:We.description}):null,Be?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",k,"”, which no longer exists in this workspace. Clear the Entity type filter under Trigger options to save."]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only declared Automation outputs in the current workspace can trigger this Automation. Ordinary saved events remain data."})]}),de?e.jsx(St,{schema:de,values:H,onValuesChange:l=>te(p=>Pt(p,de,l)),fieldIdPrefix:`${m}workspace-`},`${k||"workspace"}:${C.join(",")}`):null]}):A||ye?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:le.length>1?"Events":"Event"}),le.length?e.jsx(Tt,{events:le,selectedKeys:C,onToggle:ze}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),je?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:je.description}):null]}),typeof H.resource_ref=="string"||ve?e.jsxs("div",{className:"space-y-3",children:[typeof H.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Resource"}),e.jsx("div",{className:T(Je,"px-3 py-2 text-sm"),children:H.resource_ref})]}):null,ve?e.jsx(St,{schema:ve,values:H,onValuesChange:l=>te(p=>Pt(p,ve,l)),fieldIdPrefix:m},C.join(",")):null]}):null]}):G?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):g==="time"?e.jsx(hn,{value:be,onChange:Pe}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),g!=="manual"&&!Te?e.jsxs(xs,{open:x,onOpenChange:K,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(z,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 py-1 text-muted-foreground hover:bg-transparent hover:text-foreground",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm",children:[e.jsx(gs,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",$==="turn"?"Each event":"Window"," ·"," ",g==="time"?"Combine":N?Q==="queue"?"Queue":"Combine":Q==="queue"?"Queue":Q==="coalesce"?"Combine":"Update current run",g==="event"&&!N?` · ${$==="turn"&&Y==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",x&&"rotate-180")})]})}),e.jsxs(fs,{className:"space-y-4 pt-3",children:[g==="event"&&N?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity type filter"}),e.jsxs(me,{value:k||lt,onValueChange:He,children:[e.jsx(he,{"aria-label":"Entity type filter",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:lt,children:"All event types"}),Ae.map(l=>e.jsx(P,{value:l.slug,children:l.name},l.slug))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Limit selected events to outputs linked to this entity type."})]}):null,g==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Run"}),e.jsxs(me,{value:$,onValueChange:l=>{const p=l,S=Qe(p,Y);ge(p),V(S),se(Ie(p,S,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"turn",children:"Start a run for each event"}),e.jsx(P,{value:"window",children:"Batch events into a window"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"When busy"}),e.jsxs(me,{value:Q,onValueChange:l=>se(l),children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"queue",children:"Queue"}),e.jsx(P,{value:"coalesce",children:"Combine waiting events"}),!N&&$==="turn"&&Y==="reply_to_source"&&je?.capabilities?.steering?e.jsx(P,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,$==="window"&&(g==="time"||!N)?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Skip unchanged windows"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No source changes means no agent run or LLM call."})]}),e.jsx(Ys,{"aria-label":"Skip unchanged windows",checked:ke,onCheckedChange:Ee})]}):null,g==="event"&&!N&&$==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Result"}),e.jsxs(me,{value:Y,onValueChange:l=>{const p=l;V(p),se(Ie($,p,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[je?.capabilities?.replyToSource?e.jsx(P,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(P,{value:"silent",children:"Save in Lobu"})]})]}),je?.capabilities?.replyToSource?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages matching this trigger run the Automation; anything else in the conversation stays with the connected agent."}):null]}):null]})]}):null]})}const vn=16;function qe(){return crypto.randomUUID()}function yn(n){return n===void 0?[{key:qe(),initial:void 0}]:n.length===0?[{key:qe(),initial:null}]:n.map(t=>({key:qe(),initial:t}))}function Zt(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function jn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function _n(n,t){const s=n.map(o=>t[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const u=s.filter(Zt).length;return{ready:!s.some(o=>o.kind==="manual")&&u<=1&&s.length>0&&s.every(o=>o.ready&&o.trigger),triggers:s.filter(o=>o.trigger).map(o=>o.trigger)}}function Yn({organizationId:n,initialTriggers:t,onChange:s}){const d=i.useId(),[u,m]=i.useState(()=>yn(t)),[c,o]=i.useState({}),r=i.useRef("");i.useEffect(()=>{const h=_n(u,c),v=JSON.stringify(h);v!==r.current&&(r.current=v,s(h))},[u,c,s]);const j=u.find(h=>Zt(c[h.key]))?.key??u.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,R=i.useCallback((h,v)=>{o(_=>jn(_[h],v)?_:{..._,[h]:v})},[]),f=()=>{const h=u[0],v=h?c[h.key]:void 0;if(u.length===1&&(v?.kind==="manual"||h?.initial===null)){const _=qe();o({}),m([{key:_,initial:void 0}]);return}m(_=>[..._,{key:qe(),initial:void 0}])},B=h=>{if(u.length<=1){const v=qe();o({}),m([{key:v,initial:null}]);return}o(v=>{const _={...v};return delete _[h],_}),m(v=>v.filter(_=>_.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${d}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${d}-heading`,className:"text-sm font-medium",children:"When"}),u.length>1?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each trigger can start this Automation independently (OR). At most one schedule. If several match the same event, the first listed wins for run options."}):null]}),e.jsx("div",{className:"space-y-3",children:u.map((h,v)=>{const _=u.length>1,O=_?j&&j!==h.key?["event"]:["event","time"]:["event","time","manual"],D=c[h.key],b=_||(D?D.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:T("space-y-3 rounded-lg border bg-card/40 p-3",_&&"relative"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:_?`Trigger ${v+1}`:"Trigger"}),b?e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":_?`Remove trigger ${v+1}`:"Clear trigger",onClick:()=>B(h.key),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Nn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:O,fieldIdPrefix:`${d}-${h.key}-`,onChange:R})]},h.key)})}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:u.length>=vn,children:[e.jsx(Ge,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Nn({slotKey:n,organizationId:t,initial:s,kinds:d,fieldIdPrefix:u,onChange:m}){const c=i.useCallback(o=>m(n,o),[m,n]);return e.jsx(fn,{organizationId:t,initialTrigger:s,allowedKinds:d,showSectionHeader:!1,fieldIdPrefix:u,onChange:c})}const Rt={agents:!0,lobuEmbedded:!1};function bn(){const{data:n}=ys({queryKey:["features"],queryFn:async()=>{const t=await js(`${_s}/api/features`);return t.ok?t.json():Rt},staleTime:3e4,refetchInterval:6e4});return n??Rt}const Dt=4096;function kn({open:n,onOpenChange:t,initial:s,onSubmit:d}){const[u,m]=i.useState(""),[c,o]=i.useState(""),[r,j]=i.useState(null);i.useEffect(()=>{n&&(m(s?.name??""),o(s?.query??""),j(null))},[n,s]);const R=()=>{const B=u.trim(),h=c.trim();if(!B){j("Give the SQL source a name.");return}if(!h){j("Enter a query.");return}if(h.length>Dt){j(`Query is too long (${h.length} chars, max ${Dt}).`);return}d({name:B,query:h}),t(!1)},f=!!s;return e.jsx(Ns,{open:n,onOpenChange:t,children:e.jsxs(bs,{className:"max-w-2xl",children:[e.jsxs(ks,{children:[e.jsx(Ss,{children:f?"Edit SQL source":"SQL source"}),e.jsx(ws,{children:"Write a query the automation runs each period. It becomes a reference in the prompt — the query travels with the chip."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(ae,{id:"sql-source-name",value:u,onChange:B=>m(B.target.value),placeholder:"recent_cancellations",autoFocus:!f}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The output-field name this source fills."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(Ze,{value:c,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),r?e.jsx("p",{className:"text-sm text-destructive",children:r}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(z,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(z,{onClick:R,children:f?"Save":"Add source"})]})]})})}const Sn=["skill","feed","connection","connector","metric","entity_type"];function wn({value:n,onChange:t,library:s,pinned:d,required:u,error:m,owner:c,agentId:o,sources:r,onAddSources:j}){const R=sn(Sn,Et,{skills:s,skillAgentId:o||null}),f=i.useRef(null),[B,h]=i.useState(null),v=i.useMemo(()=>{if(!r)return[];const b=new Set(r.map(J=>J.query.trim()));return Ot(n).filter(J=>!b.has(J.query.trim()))},[n,r]),_=nn(n),O=an(d.filter(b=>_.includes(b.name)),s),D=s.length>0;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"automation-prompt",children:["Instructions"," ",u?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),_.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[_.length,"/",Et," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(on,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:R,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(b,J)=>h({initial:b,pos:J}),placeholder:D?"What should this Automation do? Type @ to pull in a skill or a data source.":"What should this Automation do? Type @ to pull in a data source.",className:"[&_.ProseMirror]:min-h-[7rem] [&_.ProseMirror]:max-h-72 [&_.ProseMirror]:overflow-y-auto"})}),e.jsx(kn,{open:B!==null,onOpenChange:b=>{b||h(null)},initial:B?.initial,onSubmit:b=>{f.current?.insertSql(b,B?.pos),h(null)}}),v.length>0&&j?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-dashed p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.length===1?`"${v[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${v.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>j(Ot(n,r)),children:v.length===1?"Add as a source":"Add as sources"})]}):null,_.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:_.map(b=>{const J=O.includes(b),g=!s.some(M=>M.name===b);return e.jsxs(Cs,{variant:g?"destructive":"secondary",className:"font-normal",children:[b,g?" · unavailable":J?" · newer text":null]},b)})}):null,O.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[O.length===1?`"${O[0]}" has been edited since this Automation pinned it.`:`${O.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,m?e.jsx("p",{className:"text-xs text-destructive",children:m}):null,!D&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Es,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:o},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):m?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:D?"Type @ to pull in a skill, a feed, connection, connector, metric, entity type, or a SQL query. Skill text is saved with this version, so later edits to the skill do not change this Automation until you update it.":"Type @ to pull in a feed, connection, connector, metric, entity type, or a SQL query this Automation should read."})]})}const Cn=["connection","connector","feed","metric","entity_type"];function En({sources:n,onChange:t,disabled:s}){const{currentOwner:d,resolvedOrganizationId:u}=Xt(),[m,c]=i.useState(""),{refs:o}=rn({owner:d,organizationId:u,kinds:Cn,query:m,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(r=>e.jsxs("li",{className:"flex items-start gap-2 rounded-lg border bg-background p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-mono text-xs font-medium",children:r.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:r.query})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${r.name}`,disabled:s,onClick:()=>t(n.filter(j=>j.query!==r.query)),children:e.jsx(Jt,{className:"h-3.5 w-3.5"})})]},r.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(tt,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(z,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Ge,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:r=>o.map(j=>e.jsxs($e,{value:`${j.label} ${j.kind}`,onSelect:()=>{t(cn(j,n)),r()},children:[e.jsx("span",{className:"truncate text-sm",children:j.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:j.kind})]},`${j.kind}:${j.id}`))})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Data handed to the agent alongside its instructions, and what change detection is measured against. Editing an Automation does not re-read the instructions for these — this list is what runs. To add a SQL source, write it with @ in the instructions above. Automation-owned; skills never add or remove sources."})]})}function On({organizationId:n,value:t,onChange:s,className:d}){const{data:u=[]}=Os(n),m=Hs(u),c=m.find(o=>o.id===t);return e.jsx(tt,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(z,{variant:"outline",role:"combobox","aria-expanded":o,className:T("w-full justify-between",d),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs($e,{value:"all workspace",onSelect:()=>{s(void 0),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),m.map(r=>e.jsxs($e,{value:`${r.name} ${r.entityType}`,onSelect:()=>{s(r.id),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===r.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[r.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",r.entityType,")"]})]})]},r.id))]})})}function xt(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const t=n.slice(1,-1);return t?t.split(",").map(s=>s.trim()):[]}return[]}const An=Xs.map(n=>({value:n,label:Zs[n]})),It=[{value:"agent",label:"Agent",hint:"An agent reads the window and follows your instructions."},{value:"code",label:"Code",hint:"A deterministic script processes each completed window."},{value:"both",label:"Agent + code",hint:"An agent extracts per your instructions, then the script runs."}];function qt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(d=>d.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const Fn=["text","number","date","boolean","json"],Pn=[{value:"key",label:"Key"},{value:"searchable",label:"Searchable"},{value:"plain",label:"Plain"}],ut=[{value:"plan",label:"Plan first"},{value:"auto",label:"Auto"},{value:"acceptEdits",label:"Accept edits"},{value:"dontAsk",label:"Don't ask"},{value:"bypassPermissions",label:"Bypass permissions"}];let $t=0;function Mn(){return $t+=1,`field-${$t}`}function pt(n={}){return{id:Mn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function Ln(n){return n.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())}function Ke(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Tn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Rn(n){return n?n.every(t=>!t||typeof t!="object"||Array.isArray(t)?!1:Object.keys(t).every(s=>["slug","name","source_path","value_field"].includes(s))):!0}function Kt(n){return n?Tn(n.keying_config)&&Rn(n.classifiers)?"fields":"json":"fields"}function Wt(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Bt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function zt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const d of s){if(typeof d!="string")continue;const u=Ke(d);u&&t.set(u,pt({name:u,role:"key"}))}for(const d of n?.classifiers??[]){if(!d||typeof d!="object"||Array.isArray(d))continue;const u=d.value_field;if(typeof u!="string")continue;const m=Ke(u);!m||t.has(m)||t.set(m,pt({name:m,role:"searchable"}))}return Array.from(t.values())}function Ne(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Ut(n,t,s){const d=n?.execution_config?.[t];return typeof d=="string"&&s.includes(d)?d:""}function dt(n,t){const s=n.trim();if(!s)return{};const d=Number(s);return Number.isFinite(d)?{value:d}:{error:`${t} must be a number.`}}function Vt({entityType:n,entityPath:t,fields:s}){const d=s.map(r=>({...r,name:Ke(r.name)})).filter(r=>r.name),u=d.filter(r=>r.role==="key").map(r=>r.name),m=d.filter(r=>r.role==="searchable"),c=Ke(n),o=t.trim()||"$";return u.length>0&&!c?{error:"Key fields need an output entity type."}:(u.length>0||m.length>0,{keyingConfig:u.length>0?{entity_type:c,entity_path:o,key_fields:u,key_output_field:`${c}_key`}:void 0,classifiers:m.length>0?m.map(r=>({slug:r.name,name:Ln(r.name),source_path:o,value_field:r.name})):void 0})}function Dn(n,t){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})}function Qt(n){return!!(n?.classifiers?.length||n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||xt(n?.tags).length)}function In({organizationId:n,entityId:t,prefill:s,onSubmit:d,isSubmitting:u,error:m,isEditing:c,onCancel:o,triggerFields:r,submitLabel:j="Create Automation",submitDisabled:R=!1,triggers:f}){const{lobuEmbedded:B}=bn(),{currentOwner:h}=Xt(),{data:v=[]}=As(),{data:_=[]}=Fs(),[O,D]=i.useState(s?.managed_agent_id??""),b=!!s?.managed_agent_id&&!c,[J,g]=i.useState(s?.device_worker_id??""),[M,G]=i.useState(s?.device_worker_id?"device":"agent"),[Se,N]=i.useState(s?.agent_kind??""),{data:oe=[]}=Gt({organizationId:n}),[k,we]=i.useState(s?.name??""),[Fe,C]=i.useState(s?.slug??""),[re,H]=i.useState(!!s?.slug),[te,be]=i.useState(s?.description??""),[Pe,ce]=i.useState(s?.prompt??""),[$,ge]=i.useState(!1),Y=s?.skills??[],[V,Q]=i.useState(s?.sources??[]),[se,ke]=i.useState(s?.entity_id??t),[Ee,x]=i.useState(s?.reaction_script??""),[K,A]=i.useState(()=>qt(s)),[ie,X]=i.useState(s?.classifiers?JSON.stringify(s.classifiers,null,2):""),[fe,U]=i.useState(null),[ye,Oe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[le,I]=i.useState(null),[je,Me]=i.useState(()=>Kt(s)),[Ae,ue]=i.useState(()=>Wt(s)),[Le,We]=i.useState(()=>Bt(s)),[ve,de]=i.useState(()=>zt(s)),[Be,Te]=i.useState(s?.reactions_guidance??""),[st,Ce]=i.useState(()=>Ne(s,"timeout_seconds")),[nt,at]=i.useState(()=>Ne(s,"max_budget_usd")),[ze,He]=i.useState(()=>Ne(s,"model")),[Ue,ot]=i.useState(()=>Ut(s,"permission_mode",ut.map(a=>a.value))),[Re,l]=i.useState(()=>Ne(s,"effort")),[p,S]=i.useState(()=>Ne(s,"finalize_nudges")),[Z,E]=i.useState(null),[_e,w]=i.useState(xt(s?.tags).join(", ")),[De,Ve]=i.useState(""),[rt,ft]=i.useState(!!(c||Qt(s)));i.useEffect(()=>{s&&(we(s.name??""),C(s.slug??""),H(!!s.slug),be(s.description??""),ce(s.prompt??""),ge(!1),Q(s.sources??[]),ke(s.entity_id??t),g(s.device_worker_id??""),G(s.device_worker_id?"device":"agent"),N(s.agent_kind??""),x(s.reaction_script??""),A(qt(s)),X(s.classifiers?JSON.stringify(s.classifiers,null,2):""),U(null),Oe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),I(null),Me(Kt(s)),ue(Wt(s)),We(Bt(s)),de(zt(s)),Te(s.reactions_guidance??""),Ce(Ne(s,"timeout_seconds")),at(Ne(s,"max_budget_usd")),He(Ne(s,"model")),ot(Ut(s,"permission_mode",ut.map(a=>a.value))),l(Ne(s,"effort")),S(Ne(s,"finalize_nudges")),E(null),w(xt(s.tags).join(", ")),Ve(""),D(s.managed_agent_id??""),ft(!!(c||Qt(s))))},[s,t,c]);const es=re?Fe:Ct(k),{data:ts}=Ps(O||null),{data:ss}=Ms(O||null,{enabled:!!O}),ct=tn(ts??null,ss?.catalog??[]),ns=ln(f),it=Ee.trim().length>0,Ye=!c&&K==="code"?"":Pe,as=!c&&K==="agent"?void 0:Ee.trim()||void 0,vt=(c||K==="code")&&it,yt=un(Ye,ct,f,vt),os=$||Ye.trim()!==""?yt:null,jt=dn(Ye,ct),_t=!c&&K!=="agent",Nt=!!k.trim()&&!yt&&(!_t||it),rs=ns&&!vt&&jt.length===0,cs=()=>{if(!Nt)return;let a,F;if(je==="fields"){const ne=Vt({entityType:Ae,entityPath:Le,fields:ve});if(ne.error){I(ne.error);return}a=ne.classifiers,F=ne.keyingConfig,U(null),I(null)}else{if(ie.trim())try{const ne=JSON.parse(ie);if(!Array.isArray(ne)){U("Classifiers must be a JSON array.");return}a=ne}catch{U("Invalid JSON. Please check the syntax.");return}if(U(null),ye.trim())try{const ne=JSON.parse(ye);if(typeof ne!="object"||Array.isArray(ne)){I("Keying config must be a JSON object.");return}F=ne}catch{I("Invalid JSON. Please check the syntax.");return}I(null)}const L=dt(st,"Timeout");if(L.error){E(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<1)){E("Timeout must be a whole number greater than 0.");return}const q=dt(nt,"Budget");if(q.error){E(q.error);return}if(q.value!==void 0&&q.value<0){E("Budget cannot be negative.");return}const ee=dt(p,"Finalize nudges");if(ee.error){E(ee.error);return}if(ee.value!==void 0&&(!Number.isInteger(ee.value)||ee.value<0||ee.value>5)){E("Finalize nudges must be a whole number from 0 to 5.");return}const W={...L.value!==void 0?{timeout_seconds:L.value}:{},...q.value!==void 0?{max_budget_usd:q.value}:{},...ze.trim()?{model:ze.trim()}:{},...Ue?{permission_mode:Ue}:{},...Re.trim()?{effort:Re.trim()}:{},...ee.value!==void 0?{finalize_nudges:ee.value}:{}},is=Object.keys(W).length>0||c?W:void 0;E(null);const ls=_e.trim()?_e.split(",").map(ne=>ne.trim()).filter(Boolean):void 0;d({slug:es,name:k.trim(),description:te.trim()||void 0,prompt:Ye,skills:jt,entity_id:se,sources:V,reaction_script:as,classifiers:a,keying_config:F,reactions_guidance:Be.trim()||void 0,execution_config:is,tags:ls,change_notes:De.trim()||void 0,managed_agent_id:M==="agent"&&O.trim()||null,device_worker_id:M==="device"&&J.trim()||null,agent_kind:M==="device"&&Se.trim()||null})},bt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",_t?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(Ze,{value:Ee,onChange:x,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),c?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Runs deterministically on every completed window, after agent extraction. Declare an ",e.jsx("code",{children:"input"})," export to set the window's extraction contract."]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>H(!re),className:"text-xs text-muted-foreground hover:text-foreground",children:re?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:k,onChange:a=>we(a.target.value),placeholder:"e.g., Escalation signals"}),!c&&re?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:Fe,onChange:a=>C(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:Ct(k)||"custom-slug"})]}):null]})}),c?null:e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"How does this run?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:It.map(a=>e.jsx("button",{type:"button","aria-pressed":K===a.value,onClick:()=>A(a.value),className:T("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",K===a.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:a.label},a.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:It.find(a=>a.value===K)?.hint})]}),c||K!=="code"?e.jsx(wn,{value:Pe,onChange:a=>{ge(!0),ce(a)},library:ct,pinned:Y,required:rs,error:os,owner:h??"",agentId:O,sources:c?V:void 0,onAddSources:c?Q:void 0}):null,!c&&K!=="agent"?bt:null,c?e.jsx(En,{sources:V,onChange:Q,disabled:u}):null,e.jsx("div",{className:"space-y-4",children:r}),e.jsxs(z,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":rt,"aria-controls":"automation-advanced-settings",onClick:()=>ft(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ls,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",rt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:T("space-y-4",!rt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-description",children:"Description"}),e.jsx(ae,{id:"scratch-description",value:te,onChange:a=>be(a.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity scope"}),e.jsx(On,{organizationId:n,value:se,onChange:ke}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?bt:null,e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(y,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys. Searchable fields become classifiers."})]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(je==="fields"){const a=Vt({entityType:Ae,entityPath:Le,fields:ve});if(a.error){I(a.error);return}X(a.classifiers?JSON.stringify(a.classifiers,null,2):""),Oe(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Me("json")}else Me("fields");U(null),I(null)},children:je==="fields"?"Edit JSON":"Use fields"})]}),je==="fields"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(tt,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-expanded":a,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:T("truncate",!Ae&&"text-muted-foreground"),children:Ae||"Select entity type"}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,F)=>{const L=Ke(F),q=oe.filter(W=>!W.backing_sql),ee=q.some(W=>W.slug===L);return e.jsxs(e.Fragment,{children:[q.map(W=>e.jsxs($e,{value:`${W.name??W.slug} ${W.slug}`,onSelect:()=>{ue(W.slug),I(null),a()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",Ae===W.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:W.slug}),W.name&&W.name!==W.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:W.name})]})]},W.slug)),L&&!ee&&e.jsxs($e,{value:F,onSelect:()=>{ue(L),I(null),a()},className:"cursor-pointer",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:L})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(ae,{id:"scratch-output-path",value:Le,onChange:a=>{We(a.target.value),I(null)},placeholder:"$.items[*]",className:"font-mono text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(y,{children:"Fields"}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{de(a=>[...a,pt()]),U(null),I(null)},children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),ve.length===0?e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:ve.map(a=>e.jsxs("div",{className:T(Je,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:F=>{const L=Ke(F.target.value);de(q=>q.map(ee=>ee.id===a.id?{...ee,name:L}:ee)),U(null),I(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(me,{value:a.type,onValueChange:F=>{de(L=>L.map(q=>q.id===a.id?{...q,type:F}:q))},children:[e.jsx(he,{"aria-label":"Output field type",children:e.jsx(xe,{})}),e.jsx(pe,{children:Fn.map(F=>e.jsx(P,{value:F,children:F},F))})]}),e.jsx("div",{className:"grid grid-cols-3 rounded-md border border-input bg-background p-1",children:Pn.map(F=>e.jsx("button",{type:"button",onClick:()=>{de(L=>L.map(q=>q.id===a.id?{...q,role:F.value}:q)),U(null),I(null)},className:T("rounded-sm px-2 py-1 text-xs transition-colors",a.role===F.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:F.label},F.value))}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{de(F=>F.filter(L=>L.id!==a.id)),U(null),I(null)},"aria-label":"Remove output field",children:e.jsx(Yt,{className:"h-4 w-4"})})]},a.id))})]}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-classifiers",children:"Classifiers (JSON)"}),e.jsx(Ze,{value:ie,onChange:a=>{X(a),U(null)},language:"json",placeholder:'[{ "slug": "sentiment", "name": "Sentiment", "source_path": "$.analysis[*]", "value_field": "sentiment" }]',minHeight:"80px"}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(Ze,{value:ye,onChange:a=>{Oe(a),I(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(Ts,{id:"scratch-reactions-guidance",value:Be,onChange:a=>Te(a.target.value),placeholder:"Guidance text for the reaction system (e.g., when to alert, severity thresholds)...",className:"font-mono text-xs min-h-[80px]"})]}),e.jsxs("div",{className:"space-y-4",children:[Dn("Run settings","Choose where the automation runs and the budget it can use."),!b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(me,{value:M,onValueChange:a=>G(a),children:[e.jsx(he,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"agent",children:"Managed agent"}),e.jsx(P,{value:"device",children:"On a device"}),e.jsx(P,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M==="agent"?"Automated runs dispatch to a managed Lobu agent.":M==="device"?"Automated runs are claimed and executed locally by a device worker (Mac app, remote worker).":"No executor — this automation runs only when started manually by a connected client."})]}),!b&&M==="agent"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-agent-id",children:"Agent"}),B?e.jsxs(me,{value:O||"__unselected__",onValueChange:a=>{D(a==="__unselected__"?"":a)},children:[e.jsx(he,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a Lobu agent"})}),e.jsx(pe,{children:v.map(a=>e.jsxs(P,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:O,onChange:a=>{D(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(me,{value:J||"__unselected__",onValueChange:a=>g(a==="__unselected__"?"":a),children:[e.jsx(he,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a device worker"})}),e.jsx(pe,{children:_.map(a=>e.jsx(P,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(me,{value:Se||"__default__",onValueChange:a=>N(a==="__default__"?"":a),children:[e.jsx(he,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(xe,{placeholder:"Device default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Device default"}),An.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Device default uses that device's preferred local agent. Availability is checked again when a run is claimed, so a run stays queued if its selected runtime is no longer available."})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Model"}),e.jsx(en,{value:ze,onChange:a=>{He(a),E(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(ae,{id:"scratch-timeout",type:"number",min:1,max:86400,value:st,onChange:a=>{Ce(a.target.value),E(null)},placeholder:"600"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(me,{value:Ue||"__default__",onValueChange:a=>{ot(a==="__default__"?"":a),E(null)},children:[e.jsx(he,{id:"scratch-permission-mode",children:e.jsx(xe,{placeholder:"Default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Default"}),ut.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(ae,{id:"scratch-effort",value:Re,onChange:a=>{l(a.target.value),E(null)},placeholder:"Default","aria-describedby":"scratch-effort-help"}),e.jsx("p",{id:"scratch-effort-help",className:"text-xs text-muted-foreground",children:"For device runs, use a value supported by the selected CLI and model. Leave empty for its default."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(ae,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:p,onChange:a=>{S(a.target.value),E(null)},placeholder:"Default"})]})]}),Z&&e.jsx("p",{className:"text-xs text-destructive",children:Z})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(ae,{id:"scratch-tags",value:_e,onChange:a=>w(a.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(ae,{id:"scratch-change-notes",value:De,onChange:a=>Ve(a.target.value),placeholder:"What changed in this version?"})]})]})]}),m&&!fe&&!le&&!Z&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:m}),e.jsx(ht,{onCancel:o,children:e.jsx(z,{onClick:cs,disabled:!Nt||u||R,children:u?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":j})})]})}function qn(n){const t=n.detail??{};return{name:n.name,slug:t.slug,description:t.description??n.description??void 0,prompt:t.prompt,triggers:t.triggers,sources:t.sources,classifiers:t.classifiers,keying_config:t.keying_config,reactions_guidance:t.reactions_guidance,reaction_script:t.reaction_script,model_config:t.model_config,execution_config:t.execution_config,tags:t.tags}}function Xn({onClose:n,hideCancel:t=!1,hideHeader:s=!1,organizationId:d,entityId:u,entityName:m,prefillAgentId:c,onSuccess:o,editingAutomation:r,catalogPrefill:j,onDraft:R,triggerFields:f,submitLabel:B,submitDisabled:h,createFields:v,onPrefillTriggers:_}){const O=Ds(),D=Is(),b=qs(),J=$s(),g=!!r,[M,G]=i.useState("template"),[Se,N]=i.useState(void 0),[oe,k]=i.useState(void 0),{data:we=[],isLoading:Fe}=Ks(),[C,re]=i.useState(""),H=i.useMemo(()=>c?{managed_agent_id:c}:void 0,[c]),te=i.useMemo(()=>we.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[we]),be=i.useMemo(()=>te.filter(x=>x.name.toLowerCase().includes(C.toLowerCase())||x.description.toLowerCase().includes(C.toLowerCase())),[te,C]),Pe=x=>{const K=we.find(ie=>ie.id===x.key);if(!K)return;const A=qn(K);k(c?{...A,managed_agent_id:c}:A),_?.(A.triggers??[]),G("scratch")},ce=()=>{O.reset(),D.reset(),G("template"),N(void 0),k(void 0),n()},$=g?v?.triggers??r.triggers??[]:v?.triggers??oe?.triggers??j?.triggers??[],ge=async x=>{try{if(R){await R(x);return}if(g){const K=v?.triggers??r.triggers??[],A=r.reaction_script??"",ie=x.reaction_script??"";ie&&ie!==A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:ie}),await D.mutateAsync({automation_id:r.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:K,classifiers:x.classifiers,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!ie&&A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:""});const X={};x.model_config!==void 0&&(X.model_config=x.model_config),x.execution_config!==void 0&&(X.execution_config=x.execution_config),x.tags!==void 0&&(X.tags=x.tags),x.managed_agent_id!==void 0&&(X.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(X.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(X.device_worker_id=x.device_worker_id||null),Object.keys(X).length>0&&await J.mutateAsync({automation_id:r.automation_id,...X}),ce(),o?.(r.automation_id)}else{const K=v?.triggers??oe?.triggers??j?.triggers??[],A=await O.mutateAsync({...x,managed_agent_id:x.managed_agent_id??void 0,device_worker_id:x.device_worker_id??void 0,agent_kind:x.agent_kind??void 0,triggers:K});ce(),A.automation_id&&o?.(A.automation_id)}}catch{}},Y=g?D:O;let V="Add an automation";g?V="Edit automation configuration (saves as a new version)":m&&(V=`Add an automation for ${m}`);const Q=r?{entity_id:r.entity_id,name:r.name,slug:r.slug,description:r.description,prompt:r.prompt,sources:r.sources,reaction_script:r.reaction_script,device_worker_id:r.device_worker_id??void 0,agent_kind:r.agent_kind??void 0,classifiers:r.classifiers,keying_config:r.keying_config,reactions_guidance:r.reactions_guidance,model_config:r.model_config,execution_config:r.execution_config,tags:r.tags,managed_agent_id:r.managed_agent_id??void 0}:void 0,se=g?"Edit Automation":"Create Automation",ke=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:se}),e.jsx("p",{className:"text-sm text-muted-foreground",children:V})]}),Ee=e.jsxs("div",{className:"py-6 space-y-6",children:[!g&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(mt,{active:M==="template",onClick:()=>G("template"),icon:e.jsx(Ws,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(mt,{active:M==="scratch",onClick:()=>{G("scratch"),N(void 0),k(void 0)},icon:e.jsx(Ge,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(mt,{active:M==="clone",onClick:()=>G("clone"),icon:e.jsx(Bs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!g&&M==="template"?e.jsxs(e.Fragment,{children:[Fe?e.jsx(zs,{}):e.jsx(Us,{items:be,searchQuery:C,onSearchChange:re,onSelect:Pe,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:te.length===0?"No automation templates available.":void 0}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):!g&&M==="clone"&&!Se?e.jsxs(e.Fragment,{children:[e.jsx($n,{organizationId:d,onSelect:x=>{N(x),_?.(x.triggers??[]),G("scratch")}}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):e.jsx(In,{organizationId:d,entityId:u,prefill:Q??Se??oe??j??H,onSubmit:ge,isSubmitting:Y.isPending,error:Y.error?Y.error.message:null,isEditing:g,onCancel:t?void 0:ce,triggerFields:f,submitLabel:B,submitDisabled:h,triggers:$})]});return e.jsxs("div",{className:"flex flex-col",children:[s?null:ke,Ee]})}function mt({active:n,onClick:t,icon:s,label:d}){return e.jsxs("button",{type:"button",onClick:t,className:T("flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors",n?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground hover:border-muted-foreground/30 hover:text-foreground"),children:[s,d]})}function $n({organizationId:n,onSelect:t}){const{data:s,isLoading:d}=Vs(n),[u,m]=i.useState(""),c=(s||[]).filter(o=>o.name?.toLowerCase().includes(u.toLowerCase()));return d?e.jsx(Qs,{label:"automations",variant:"list-picker",rows:4}):!s||s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No existing automations to clone."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:o=>m(o.target.value),placeholder:"Search automations...",className:"w-full rounded-md border px-3 py-2 text-sm bg-background"}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[c.map(o=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,classifiers:o.classifiers,keying_config:o.keying_config,triggers:o.triggers,sources:o.sources}),className:"w-full text-left rounded-md border p-3 hover:border-primary/50 hover:bg-primary/5 transition-colors",children:[e.jsx("p",{className:"text-sm font-medium",children:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{Yn as A,Xn as C};
@@ -1 +0,0 @@
1
- import{hz as r,j as e}from"./index-Bfux0kHb.js";import{a as m}from"./agent-skills-route-CatU8soC.js";import"./agent-subpage-shell-DVSUdIBn.js";import"./agent-skill-context-CxglCznW.js";import"./core.esm-CFYXLQXH.js";import"./skill-editor-D_W3QlRz.js";import"./agent-loading-shells-Dczhk067.js";import"./agent-card-controls-VJgcB5-0.js";import"./switch-CCKllS7w.js";function c(){const{owner:t,agentId:o}=r.useParams();return e.jsx(m,{owner:t,agentId:o})}export{c as component};
@@ -1 +0,0 @@
1
- import{j as t,a0 as o}from"./index-Bfux0kHb.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +0,0 @@
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-Bfux0kHb.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 +0,0 @@
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-Bfux0kHb.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-DWfiekRz.js";import{C as J,a as K,b as Q,d as X,c as be}from"./card-kpw3EaKC.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 +0,0 @@
1
- import{d8 as u,fj as l,bq as f}from"./index-Bfux0kHb.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 +0,0 @@
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-Bfux0kHb.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 +0,0 @@
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-Bfux0kHb.js";import{a as W,c as X,S as et,D as tt,E as st}from"./schema-value-normalization--DhnhJNf.js";import{J as L}from"./renderer-B1UThnk2.js";import"./calendar-taCoBmAh.js";import"./card-kpw3EaKC.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 +0,0 @@
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-Bfux0kHb.js";import{J as B}from"./json-diff-CANZD4MQ.js";import{C as ce}from"./code-editor-D3X0yQdI.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 +0,0 @@
1
- import{r as N,j as e,L as B,dU as $e,cx as ve,an as Pe,ag as Oe,eJ as Ie,J as De,a1 as Fe,aD as le,t as Me,af as J,z as Le,ci as ze,cj as Be,B as k,ck as Ue,dl as qe,dm as He,E as Ne,dn as Je,eK as be,eL as ae,cP as oe,eM as Ve,aj as We,bM as Y,G as _e,eN as Ke,eO as Qe,s as K,eP as Ge,eQ as Ye,k as Xe,eR as Ze,bE as et,F as tt,en as nt,cs as st,eS as rt,aO as it,eT as at,X as ot,bP as lt,Y as dt,dI as ct,dJ as ut,dQ as mt,dR as pt,eU as xt,eV as ht,S as gt,c8 as ft,bm as yt,I as jt,dz as xe,dB as he,aW as vt,dC as ge,x as we,eW as ke,eX as Nt}from"./index-Bfux0kHb.js";import{u as bt}from"./clients-R4JsT_Fz.js";import{J as _t}from"./renderer-B1UThnk2.js";function wt({onIntersect:n,enabled:t,rootMargin:s="400px"}){const r=N.useRef(null),a=N.useRef(n);return a.current=n,N.useEffect(()=>{const m=r.current;if(!m||!t)return;const y=new IntersectionObserver(o=>{o[0]?.isIntersecting&&a.current()},{rootMargin:s});return y.observe(m),()=>y.disconnect()},[t,s]),r}function kt(n,t){const s=t.parentEntityType&&t.parentEntitySlug?[{entity_type:t.parentEntityType,slug:t.parentEntitySlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}];return ve(n,s)}function Ct({ownerSlug:n,entity:t,className:s}){const r=kt(n,t);return e.jsxs(B,{to:r,className:`flex items-center gap-1 text-primary hover:underline group ${s??""}`,children:[e.jsx("span",{className:"font-medium",children:t.entityName}),e.jsx($e,{className:"h-3 w-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}async function St(n,t,s,r){const a=await Pe(`${Oe}/api/${encodeURIComponent(n)}/events/${t}/actions/${encodeURIComponent(s.action)}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:s.value,interaction_id:r})});return await Ie(a,"Could not record interaction"),a.json()}function w(n){if(typeof n!="string")return;const t=n.trim();return t.length>0?t:void 0}function de(n){return typeof n=="boolean"?n:void 0}function Rt(n,t,s){const r=(s??"").toLowerCase();return!!(r==="prepare_comment"||r==="verify_staged_comment"||r.includes("prepare_")||r.includes("verify_staged")||t?.prepared===!0||typeof t?.verified=="boolean"||w(t?.reason_preview)&&w(t?.message)||w(n?.body)&&(w(n?.post_url)||w(n?.activity_id)))}function At(n,t,s){if(!Rt(n,t,s))return null;const r=(s??"").toLowerCase(),a=w(t?.body)??w(n?.body),m=w(t?.reason_preview)??w(n?.reason),y=w(t?.post_url)??w(n?.post_url)??(w(n?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${w(n?.activity_id)}`:void 0),o=de(t?.prepared),x=de(t?.verified),p=de(t?.banner_shown),f=w(t?.message),d=t?.match&&typeof t.match=="object"?t.match:null,b=w(d?.text_preview),c=w(d?.author);let h="generic";r==="verify_staged_comment"||r.includes("verify")||typeof x=="boolean"?h="verify":(r==="prepare_comment"||r.includes("prepare")||o===!0||a&&y)&&(h="prepare");const g=[];return o===!0&&g.push("Staged — not posted"),o===!1&&g.push("Not staged"),x===!0&&g.push("Verified posted"),x===!1&&g.push("Not verified as posted"),p===!0&&g.push("In-page banner"),p===!1&&g.push("No banner"),{kind:h,message:f,reason:m,body:a,postUrl:y,prepared:o,bannerShown:p,verified:x,matchPreview:b,matchAuthor:c,chips:g}}const Tt={};function te(n){return n.replace(/_/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}const Et={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function $t(n){return n.author_name?n.author_name:n.platform?te(n.platform):n.origin_type?Et[n.origin_type]??te(n.origin_type):null}function fe(n){return n==null?"":typeof n=="string"?n:typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):Array.isArray(n)?n.length===0?"":n.every(t=>typeof t!="object")?n.map(t=>String(t)).join(", "):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)}):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)})}const ce=1e5;function Pt({value:n}){const t=JSON.stringify(n,null,2)??"null",s=t.length>ce;return e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/40 p-3 font-mono text-xs",children:s?t.slice(0,ce):t}),s&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",ce.toLocaleString()," of"," ",t.length.toLocaleString()," characters."]})]})}function Ot(n){return Object.entries(n).filter(([,t])=>t==null?!1:typeof t=="string"?t.trim().length>0:Array.isArray(t)?t.length>0:typeof t=="object"?Object.keys(t).length>0:!0).sort(([t],[s])=>t.localeCompare(s))}function It({breakdown:n}){if(!n)return null;const t=[{label:"Engagement",value:n.engagement,max:100},{label:"Criticality",value:n.criticality,max:100},{label:"Depth",value:n.depth,max:100},{label:"Authority",value:n.authority,max:100},{label:"Recency",value:n.recency,max:100},{label:"Quality",value:n.quality,max:100}];return e.jsx("div",{className:"space-y-2 text-sm",children:t.map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-20 text-muted-foreground",children:s.label}),e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${s.value/s.max*100}%`}})}),e.jsx("span",{className:"w-8 text-right",children:s.value})]},s.label))})}function Dt({slug:n,value:t,isManual:s}){return e.jsxs(J,{variant:"secondary",className:"text-xs",children:[n,": ",t,s&&e.jsx(be,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function Ft(n){if(n&&typeof n=="object"){const t=n;if(Array.isArray(t.values))return{values:t.values.map(s=>String(s)).filter(s=>s.length>0),isManual:t.is_manual===!0};if(t.value!==void 0&&t.value!==null)return{values:[String(t.value)],isManual:t.is_manual===!0};if(typeof t.values=="string"&&t.values.length>0)return{values:[t.values],isManual:t.is_manual===!0}}return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?{values:[String(n)],isManual:!1}:{values:[],isManual:!1}}function Mt(n,t){if(n)switch(n){case"pending":return"pending_approval";case"approved":return"confirmed";case"rejected":return"rejected";case"completed":return"completed";case"failed":return"failed";default:return n}return t||"pending_approval"}function O(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function ye(n){return n==null||n===""?"Not set":typeof n=="string"?n:JSON.stringify(n,null,2)}function Lt(n){return n.replace(/\s+[—-]\s+pending approval$/i,"")}function W(n){return n.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}function Ce(n,t,s){return n?.kind==="agent_session"&&n.agent_id?n.client_id?`${n.agent_id} via ${n.client_id}`:n.agent_id:n?.kind==="user"?"a person":t==="agent"?"an agent":s?`Automation ${s}`:"an Automation"}function zt({initiator:n,clientName:t,fallback:s}){const{org:r}=Y(),a=r?.slug,m=n?.client_id??t,o=bt(void 0,{enabled:!!(a&&m)}).data?.find(d=>d.id===m)?.title,x=n&&n.kind!=="user"?Ce(n,void 0,n.automation_id===void 0?void 0:String(n.automation_id)):s,p="font-medium text-foreground",f=`${p} underline-offset-4 hover:underline`;return a&&n?.kind==="automation"&&n.automation_id?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:a,automationId:String(n.automation_id)},search:{view:"definition",run_id:void 0},className:f,children:x}):a&&n?.kind==="agent_session"&&n.agent_id?e.jsx(B,{to:"/$owner/agents/$agentId",params:{owner:a,agentId:String(n.agent_id)},className:f,children:x}):a&&m?e.jsxs(B,{to:"/$owner/agents/connected/$clientId",params:{owner:a,clientId:m},className:`${f} inline-flex items-center gap-1 align-middle`,children:[e.jsx(lt,{name:o??t??m}),o??x]}):e.jsx("span",{className:p,children:x})}function Bt(n){const t=Object.keys(n.fields),s=t.map(W).join(", ")||"field",r=t.length===1?"field":"fields";return`Update ${n.entityType?W(n.entityType).toLowerCase():"entity"} ${r}: ${s}`}function Ut(n,t){const s=O(t.fields);if(!s||Object.keys(s).length===0||t.action_key!=="entity_field_change"&&t.tool!=="entity_field_change")return null;const r=O(t.current)??{},a=n;return{fields:s,current:r,reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??a.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function qt(n){return!n||!Array.isArray(n.evidence)?[]:n.evidence.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]})}function je(n){return Array.isArray(n)?n.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]}):[]}function Ht(n){const t=O(n?.evidence_change);if(t&&!(!Array.isArray(t.dropped)||!Array.isArray(t.gained)))return{dropped:je(t.dropped),gained:je(t.gained)}}function P(n){return typeof n=="string"?n:void 0}function Jt(n){const t=O(n.current),s=O(n.proposal),r=O(t?.winner),a=O(t?.loser),m=Array.isArray(t?.duplicates)?t.duplicates.map(O):[],o=(m.length>0?m:a?[a]:[]).flatMap(c=>{const h=P(c?.name),g=c?.id;return h&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:h,slug:P(c?.slug),entityType:P(c?.entity_type),parentSlug:P(c?.parent_slug),parentEntityType:P(c?.parent_entity_type)}]:[]}),x=Array.isArray(s?.entity_ids)?s.entity_ids:[],p=Array.isArray(s?.names)?s.names.flatMap((c,h)=>{const g=x[h];return typeof c=="string"&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:c}]:[]}):[],f=P(s?.name),d=s?.entity_id,b=o.length>0?o:p.length>0?p:f&&(typeof d=="string"||typeof d=="number")?[{key:String(d),name:f}]:[];return{winnerName:P(r?.name)??P(s?.winner_name),winnerSlug:P(r?.slug),winnerEntityType:P(r?.entity_type),winnerParentSlug:P(r?.parent_slug),winnerParentEntityType:P(r?.parent_entity_type),losers:b,matchEvidence:qt(s),evidenceChange:Ht(s)}}function Vt(n){const t=n.entityType?W(n.entityType).toLowerCase():"entity";if(n.operation==="merge"){const s=n.merge?.losers??[];return s.length>1?`Merge ${s.length} duplicate ${t}s`:`Merge duplicate ${t}`}return`${W(n.operation)} ${t}`}function Wt(n,t){if(t.action_key!=="entity_change"&&t.tool!=="entity_change")return null;const s=t.action;if(s!=="create"&&s!=="delete"&&s!=="merge")return null;const r=n;return{operation:s,merge:s==="merge"?Jt(t):void 0,proposal:O(t.proposal),current:O(t.current),reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??r.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,proposerRationale:typeof t.proposer_rationale=="string"?t.proposer_rationale:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function ue(n,t){return!n||!t.entityType||!t.entitySlug?null:ve(n,t.parentEntityType&&t.parentSlug?[{entity_type:t.parentEntityType,slug:t.parentSlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}])}function Se({runId:n,details:t}){const{org:s}=Y(),a=_e(t.automationId,void 0,s?.id,{includeVersions:!1}).data?.automation,m=Ce(t.initiator,t.attribution,t.automationId),y=a?.automation_name??t.automationName??m,o=s?.slug;return e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",o&&t.automationId?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:o,automationId:t.automationId},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:y}):e.jsx("span",{className:"font-medium text-foreground",children:y}),o&&n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:" · "}),e.jsxs(B,{to:"/$owner/events",params:{owner:o},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",children:["Run #",n]})]})]})}function Re({details:n}){const{org:t}=Y(),s=ue(t?.slug,n);return n.entityName?e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Entity"}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:s?e.jsx(B,{to:s,className:"underline-offset-4 hover:underline",children:n.entityName}):n.entityName})]}):null}function Ae({label:n,before:t,after:s}){return e.jsxs("div",{className:"rounded-md border border-border/70 overflow-hidden",children:[e.jsx("div",{className:"border-b border-border/70 px-3 py-2 text-xs font-medium",children:n}),e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Current"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(t)})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposed"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(s)})]})]})]})}function Kt({runId:n,details:t}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),e.jsx(Re,{details:t}),Object.entries(t.fields).map(([s,r])=>e.jsx(Ae,{label:W(s),before:t.current[s],after:r},s)),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Qt({merge:n,status:t}){const{org:s}=Y(),r=ue(s?.slug,{entityType:n.winnerEntityType,entitySlug:n.winnerSlug,parentEntityType:n.winnerParentEntityType,parentSlug:n.winnerParentSlug}),a=n.losers.length,m=t==="rejected"||t==="failed",y=t==="completed";return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg border border-border/70 overflow-hidden",children:e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?"Would have kept":"Kept"}),e.jsx("div",{className:"text-sm font-medium leading-relaxed",children:n.winnerName?r?e.jsx(B,{to:r,className:"underline-offset-4 hover:underline",children:n.winnerName}):n.winnerName:e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?a>1?`Kept separate (${a})`:"Kept separate":y?a>1?`Merged away (${a})`:"Merged away":a>1?`To merge away (${a})`:"To merge away"}),e.jsx("div",{className:"space-y-0.5 text-sm leading-relaxed",children:a>0?n.losers.map(o=>{const x=ue(s?.slug,{entityType:o.entityType,entitySlug:o.slug,parentEntityType:o.parentEntityType,parentSlug:o.parentSlug}),p=y?"line-through decoration-muted-foreground/60":"";return e.jsx("div",{className:"break-words",children:x?e.jsx(B,{to:x,className:`${p} underline-offset-4 hover:underline`,children:o.name}):e.jsx("span",{className:p,children:o.name})},o.key)}):e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]})]})}),n.evidenceChange&&e.jsxs("div",{className:n.evidenceChange.dropped.length>0?"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2":"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.evidenceChange.dropped.length>0?"What changed since you reviewed this":"Evidence re-checked"}),e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1",children:[n.evidenceChange.dropped.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-amber-700 dark:text-amber-400",children:"No longer proven"}),W(o.kind),": ",o.identifier]},`dropped-${o.kind}:${o.identifier}`)),n.evidenceChange.gained.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-emerald-700 dark:text-emerald-400",children:"Newly proven"}),W(o.kind),": ",o.identifier]},`gained-${o.kind}:${o.identifier}`)),n.evidenceChange.dropped.length===0&&n.evidenceChange.gained.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"The recorded match evidence did not change."})]})]}),n.matchEvidence.length>0&&e.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Match evidence"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:n.matchEvidence.map(o=>e.jsxs(J,{variant:"outline",className:"text-[10px] font-normal",children:[W(o.kind),": ",o.identifier]},`${o.kind}:${o.identifier}`))})]})]})}function Gt({runId:n,details:t,status:s}){const r=t.operation==="merge";return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),r&&t.merge?e.jsx(Qt,{merge:t.merge,status:s}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{details:t}),e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Change"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.operation==="create"?"Create a new entity after approval.":"Delete this entity after approval."})]})]}),!r&&t.proposal&&e.jsxs("div",{className:"rounded-md border border-border/70 p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposal"}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-xs leading-relaxed",children:JSON.stringify(t.proposal,null,2)})]}),t.proposerRationale&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t.attribution==="agent"?"The agent's reasoning":"The Automation's reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.proposerRationale})]}),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:r?"Why this needs approval":"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Yt({summary:n}){return e.jsxs("div",{className:"space-y-2 rounded-md border border-border/70 bg-muted/30 p-3 text-sm",children:[n.chips.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.chips.map(t=>e.jsx(J,{variant:"outline",className:"text-[10px] font-normal",children:t},t))}),n.message&&e.jsx("p",{className:"leading-relaxed text-foreground",children:n.message}),n.reason&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Why"}),e.jsx("div",{className:"mt-0.5 leading-relaxed",children:n.reason})]}),n.body&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.kind==="verify"?"Expected comment":"Draft"}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed",children:n.body})]}),n.matchPreview&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsxs("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:["Matched comment",n.matchAuthor?` · ${n.matchAuthor}`:""]}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed text-muted-foreground",children:n.matchPreview})]}),n.postUrl&&e.jsxs("a",{href:n.postUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open post",e.jsx(Ne,{className:"h-3 w-3"})]})]})}function Xt({content:n}){const t=n.metadata||{},s=n.run_id??void 0,r=Ut(n,t),a=Wt(n,t),m=(r?Bt(r):a?Vt(a):void 0)||t.operation_name||t.action_name||(n.title?Lt(n.title):void 0)||"Action",y=t.connection_name,o=t.operation_key||t.action_key||null,x=n.interaction_input_schema||t.input_schema||null,p=N.useMemo(()=>n.interaction_input||t.action_input||t.operation_input||Tt,[n.interaction_input,t.action_input,t.operation_input]),f=n.interaction_output||t.action_output||void 0,d=At(p,f??null,o),b=n.interaction_error||t.error_message||void 0,c=Mt(n.interaction_status,t.status),h=t.reviewed_by_name||t.reviewed_by_id||void 0,g=t.reject_reason||void 0,R=t.initiator,D=Ge(),v=Ye(),A=Xe(n.id,Ze(x,p),x),{values:F,setValues:U}=A,[I,q]=N.useState(null),[_,M]=N.useState(!1),[E,l]=N.useState(""),S=c==="pending_approval",L=typeof t.source_run_id=="number";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"font-medium",children:m}),y&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",y]}),c==="confirmed"&&e.jsxs(J,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:[e.jsx(K,{size:"xs",className:"mr-1"}),"Executing"]}),c==="completed"&&e.jsx(J,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),c==="failed"&&e.jsx(J,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),c==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!r&&!a&&(n.author_name||h)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-xs text-muted-foreground",children:[n.author_name&&e.jsxs("span",{children:["Requested by"," ",e.jsx(zt,{initiator:R,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&h&&e.jsx("span",{children:"·"}),h&&e.jsxs("span",{children:[c==="rejected"?"Rejected":"Approved"," by"," ",e.jsx("span",{className:"font-medium text-foreground",children:h})]})]}),r&&e.jsx(Kt,{runId:s,details:r}),!r&&a&&e.jsx(Gt,{runId:s,details:a,status:c}),c==="rejected"&&g&&e.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Reason:"})," ",g]}),d&&e.jsx(Yt,{summary:d}),(S?A.revision:x)&&(S||Object.keys(p).length>0)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:d?"Full input":"Input"}),S?e.jsxs(e.Fragment,{children:[e.jsx(tt,{visible:A.hasConflict,onReload:A.reset}),e.jsx(nt,{schema:A.revision,values:F,onValuesChange:U,fieldIdPrefix:`action-${n.id}-`},`action-${n.id}`)]}):d?e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw input"}),e.jsx("pre",{className:"mt-1 bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}):e.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&!d&&e.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-950/30 p-3 text-sm space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-green-700 dark:text-green-400 font-medium",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Output"]}),e.jsx("pre",{className:"text-xs text-green-800 dark:text-green-300 font-mono whitespace-pre-wrap",children:JSON.stringify(f,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&d&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw output"}),e.jsx("pre",{className:"mt-1 rounded bg-green-50 p-2 font-mono dark:bg-green-950/30 overflow-auto max-h-32",children:JSON.stringify(f,null,2)})]}),c==="failed"&&b&&e.jsxs("div",{className:"rounded-md bg-red-50 dark:bg-red-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-red-700 dark:text-red-400 font-medium",children:[e.jsx(rt,{className:"h-3.5 w-3.5"}),"Error"]}),e.jsx("p",{className:"text-xs text-red-800 dark:text-red-300 font-mono mt-1",children:b})]}),I==="confirmed"&&e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-blue-700 dark:text-blue-400 font-medium",children:[e.jsx(K,{size:"md"}),"Confirmed — executing..."]}),e.jsx("p",{className:"text-xs text-blue-800 dark:text-blue-300 mt-1",children:"The worker will execute this action shortly. Redirecting..."})]}),I==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-xs",children:"Rejected — redirecting..."}),S&&!I&&L&&e.jsx("div",{className:"pt-1 text-xs text-muted-foreground",children:"Part of an Automation run — approve or reject it from the run's change-set above."}),S&&s&&!I&&!L&&e.jsx("div",{className:"flex items-center gap-2 pt-1",children:_?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"Reason (optional)",value:E,onChange:$=>l($.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>v.mutate({run_id:s,reason:E||void 0},{onSuccess:()=>{q("rejected")}}),disabled:v.isPending,children:[v.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{M(!1),l("")},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>D.mutate({run_id:s,input:at(F)},{onSuccess:()=>{q("confirmed")}}),disabled:!A.canSubmit||D.isPending||v.isPending,children:[D.isPending?e.jsx(K,{size:"sm",className:"mr-1"}):e.jsx(it,{className:"h-3 w-3 mr-1"}),"Confirm"]}),e.jsxs(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>M(!0),disabled:D.isPending||v.isPending,children:[e.jsx(ot,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function Zt({content:n}){const t=n.metadata||{},s=t.kind,r=n.run_id??null,a=typeof t.automation_id=="number"?t.automation_id:null,{org:m}=Y(),y=m?.slug,p=_e(a!=null?String(a):void 0,void 0,m?.id,{includeVersions:!1}).data?.automation?.automation_name??(a!=null?`Automation ${a}`:"An Automation"),f=Ke(),d=Qe(),[b,c]=N.useState(!1),[h,g]=N.useState(""),[R,D]=N.useState(null);if(s==="automation_batch_reject"){const l=t.reason||void 0;return e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Proposals rejected"}),l&&e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:l}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Ask the agent to revise its proposals with this feedback."})]})}const v=Array.isArray(t.changes)?t.changes:[],A=typeof t.created_count=="number"?t.created_count:v.filter(l=>l.kind==="created").length,F=typeof t.updated_count=="number"?t.updated_count:v.filter(l=>l.kind==="updated").length,U=typeof t.denied_count=="number"?t.denied_count:v.filter(l=>l.kind==="denied").length,I=v.filter(l=>l.kind==="denied"),q=v.filter(l=>l.kind==="updated"&&Object.keys(l.applied||{}).length>0),_=typeof t.pending_proposal_count=="number"?t.pending_proposal_count:null,M=_==null||_>0,E=M?"proposed":"applied";return e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[e.jsxs("div",{className:"text-sm font-medium",children:[E==="proposed"?"Proposed":"Applied"," ",A," ","new + ",F," updated",U>0&&e.jsxs(e.Fragment,{children:[" + ",U," denied"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[y&&a!=null?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:y,automationId:String(a)},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:p}):e.jsx("span",{className:"font-medium text-foreground",children:p}),r!=null&&e.jsxs("span",{children:[" · run #",r]}),_!=null&&_>0&&e.jsxs("span",{children:[" · ",_," pending"]})]})]}),q.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:q.map(l=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:l.name}),Object.entries(l.applied).map(([S,L])=>e.jsx(Ae,{label:S,before:L.old,after:L.new},S))]},l.entityId))}),I.length>0&&e.jsx("div",{className:"mt-3 space-y-1.5",children:I.map(l=>e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-2.5 py-2",children:[e.jsxs("div",{className:"text-xs font-medium",children:[l.name," — not written"]}),l.denied&&e.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[l.denied.reason,e.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",l.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${l.entityId}-${l.name}`))}),r!=null&&R==null&&M&&e.jsx("div",{className:"mt-3 border-t border-border/70 pt-3",children:b?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"What should the agent change?",value:h,onChange:l=>g(l.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:r,reason:h||void 0},{onSuccess:()=>D("rejected")}),disabled:d.isPending,children:[d.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Reject all"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{c(!1),g("")},children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>f.mutate({run_id:r},{onSuccess:()=>D("approved")}),disabled:f.isPending||d.isPending,children:[f.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),e.jsx(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>c(!0),disabled:f.isPending||d.isPending,children:"Reject with feedback"})]})}),R==="approved"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals approved."}),R==="rejected"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Proposals rejected — ask the agent to revise them."}),r!=null&&R==null&&!M&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function ie({ownerSlug:n,content:t,isReply:s,showParentContext:r,connectorDefinitions:a}){const[m,y]=N.useState(!1),[o,x]=N.useState(!1),p=De(),{currentOwner:f}=Fe(),d=n??f,b=d==="me"?null:d,c=N.useCallback(async i=>{if(!b){le.error("Open this event inside a workspace to interact with it.");return}try{await St(b,Number(t.id),i,crypto.randomUUID()),le.success("Recorded")}catch(u){le.error(u instanceof Error?u.message:"Could not record that interaction.")}},[t.id,b]),h=t.payload_data??{},g=t.semantic_type==="audit"&&t.origin_type==="tool_invocation",R=g&&(h.request!==void 0||h.request_status==="too_large"),v=g&&h.request_status==="complete"&&d?`/${d}/events?content_ids=${t.id}`:!d||d==="me"?null:t.run_id!=null?`/${d}/events?run_ids=${t.run_id}`:null,A=!!(p&&v&&Me(v)),F=()=>{!p||!v||p.open({href:v,title:t.title??(t.run_id!=null?`Run #${t.run_id}`:"Event"),runId:t.run_id??void 0})},U=i=>{const u=i.target;if(!(u instanceof Element))return!1;const j=u.closest('a,button,input,select,textarea,[role="button"],[role="radio"]');return j!==null&&j!==i.currentTarget},I=i=>{U(i)||F()},q=i=>{i.key!=="Enter"&&i.key!==" "||U(i)||(i.preventDefault(),F())},_=t.metadata||{};if(t.semantic_type==="change_set")return e.jsx(Zt,{content:t});if(t.interaction_type==="approval"||t.semantic_type==="operation"||_.status!=null||_.action_key!=null)return e.jsx(Xt,{content:t});const E=Number.isFinite(t.score)?Math.round(t.score):"-",l=t.payload_type||"text",S=t.text_content||"",L=(l==="text"||l==="markdown")&&S.length>500,$=L&&!m?`${S.slice(0,500)}...`:S,Q=_.thumbnail_url||_.thumbnail,H=_.media_url,G=Ot(_),ne=Object.entries(t.classifications||{}).flatMap(([i,u])=>{const j=Ft(u);return j.values.map(T=>({slug:i,value:T,isManual:j.isManual}))}),X=(()=>{const i=t.metadata??{},u=t.platform||(typeof i.platform=="string"?i.platform:null),j=t.connection_id!=null?t.connection_id:i.source_connection_id!=null?Number(i.source_connection_id):null;return{...t,platform:u,connection_id:j!=null&&Number.isFinite(j)?j:null}})();return e.jsxs("div",{className:We(s?"border-l-2 border-l-muted pl-4":"",A&&"-mx-2 cursor-pointer rounded-lg px-2 py-1 transition-colors hover:bg-accent/40"),...A?{role:"button",tabIndex:0,onClick:I,onKeyDown:q}:{},children:[r&&t.parent_context&&e.jsxs("div",{className:"mb-3 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Replying to:"}),e.jsx("div",{className:"font-medium",children:t.parent_context.author_name}),e.jsx("div",{className:"text-muted-foreground line-clamp-2",children:t.parent_context.text_content})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[t.title&&e.jsx("h4",{className:"font-medium line-clamp-2 mb-1",children:t.title}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(()=>{const i=$t(t),u=!!t.platform&&i!==te(t.platform);return e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{className:"font-medium",children:i}),u&&e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{children:"·"}),e.jsx(J,{variant:"outline",className:"text-xs",children:t.platform})]})]})})()}),d?e.jsx(Le,{owner:d,source:X,connectorDefinitions:a,className:"mt-0.5 text-xs"}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.score_breakdown?e.jsxs(ze,{children:[e.jsx(Be,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",children:e.jsx("span",{className:"font-medium",children:E})})}),e.jsx(Ue,{className:"w-64",align:"end",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"Score Breakdown"}),e.jsx(It,{breakdown:t.score_breakdown})]})})]}):e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",disabled:!0,children:e.jsx("span",{className:"font-medium",children:E})}),t.source_url&&e.jsxs(qe,{children:[e.jsx(He,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7",asChild:!0,children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})})}),e.jsx(Je,{children:"View original"})]})]})]}),t.rating&&e.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(i=>e.jsx(be,{className:`h-4 w-4 ${i<=Number(t.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},i))}),Q&&e.jsx("a",{href:H||t.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:e.jsx("img",{src:Q,alt:"",className:`rounded-md object-cover ${l==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),t.excerpt&&e.jsx("div",{className:"text-sm italic text-muted-foreground border-l-2 border-primary/40 pl-2 mb-1",children:t.excerpt}),(()=>{switch(l){case"markdown":if($)return e.jsx("div",{className:"max-w-none text-sm space-y-2",children:e.jsx(Ve,{text:$})});break;case"json_template":{const i=t.payload_template;if(i?.root)return e.jsx(_t,{template:{root:i.root},data:t.payload_data||{},onAction:c,interactions:i.interactions});if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}case"media":return e.jsxs("div",{className:"space-y-3",children:[!Q&&H&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:H}),$&&e.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:$})]});case"empty":return e.jsxs("div",{className:"space-y-3",children:[R&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(k,{variant:"outline",size:"sm","aria-expanded":o,onClick:()=>x(i=>!i),children:[o?e.jsx(ae,{className:"h-3.5 w-3.5"}):e.jsx(oe,{className:"h-3.5 w-3.5"}),"Request"]}),o&&(h.request_status==="too_large"?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof h.request_bytes=="number"?` (${h.request_bytes.toLocaleString()} bytes).`:"."]}):e.jsx(Pt,{value:h.request}))]}),G.length>0?e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"})]});default:if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}return e.jsxs("div",{className:"space-y-3",children:[H&&!Q&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:H}),G.length>0&&e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))})]})})(),L&&e.jsx(k,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>y(!m),children:m?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3 w-3 mr-1"})," Show less"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3 mr-1"})," Show more"]})}),ne.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:ne.map(i=>e.jsx(Dt,{slug:i.slug,value:i.value||"",isManual:i.isManual},i.slug))})]})}function en({occurredAt:n,isLast:t,children:s}){return e.jsxs("div",{className:"relative flex gap-4 pb-6",children:[e.jsxs("div",{className:"relative flex w-2.5 shrink-0 justify-center",children:[!t&&e.jsx("div",{className:"absolute top-1 bottom-[-1.5rem] left-1/2 w-px -translate-x-1/2 bg-border","aria-hidden":!0}),e.jsx("div",{className:"relative z-10 mt-1 h-2.5 w-2.5 rounded-full border-2 border-background bg-muted-foreground/60"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[n&&e.jsx("time",{dateTime:new Date(n).toISOString(),title:ke(n),className:"mb-1 block text-xs leading-none text-muted-foreground",children:we(n)}),s]})]})}function rn({organizationId:n,ownerSlug:t,entityId:s,filters:r,showEntityLinks:a=!1,emptyState:m,dense:y=!1}){const{isAuthenticated:o,isReady:x}=dt(),{isMember:p,isLoading:f}=Y(),d=t==="me",b=!d&&x&&o&&p,c=!d&&x&&(!o||!f&&!p),{data:h=[]}=ct(x&&b?n:null),{data:g=[]}=ut(c?t:null),R=b?h:g,D=mt(x&&b?n:null,s,r,t),v=pt(c?t:null,s,r),A=c?v:D,{data:F,isLoading:U,error:I,fetchNextPage:q,hasNextPage:_,isFetchingNextPage:M}=A,E=N.useMemo(()=>F?.pages.flatMap(i=>i.content)??[],[F]),l=wt({onIntersect:()=>q(),enabled:!!_&&!M}),S=N.useMemo(()=>{const i=xt(E),u=i.map(V=>V.head),j=new Map(i.map(V=>[V.head.id,V])),T=ht(u);return Array.from(T.entries()).map(([V,Z])=>{const se=Z.root||Z.replies[0],ee=se?j.get(se.id):void 0;return{rootId:V,group:Z,history:ee?.history??[],runId:ee?.runId??null}})},[E]),[L,$]=N.useState(new Set),[Q,H]=N.useState(new Set),[G,ne]=N.useState(new Set),X=(i,u)=>i(j=>{const T=new Set(j);return T.has(u)?T.delete(u):T.add(u),T});return U&&E.length===0?e.jsx("div",{className:"space-y-4",children:["s1","s2","s3"].map(i=>e.jsx(gt,{className:"h-32 rounded-lg"},i))}):I?e.jsx(ft,{label:"events"}):E.length===0?m??e.jsx(yt,{icon:jt,title:"Nothing here yet",description:"No events match this view."}):e.jsxs("div",{className:y?"":"pt-1",children:[S.map(({rootId:i,group:u,history:j,runId:T},V,Z)=>{const se=u.replies.length>0,ee=L.has(i),me=G.has(i),pe=Q.has(i),Te=u.replies.filter(C=>C.depth<=3),re=u.replies.filter(C=>C.depth>3),Ee=!u.root&&u.replies.length>0,z=u.root||u.replies[0];return z?e.jsxs(en,{occurredAt:z.occurred_at,isLast:V===Z.length-1,children:[a&&t&&z.entity_name&&z.entity_type&&z.entity_slug&&e.jsx("div",{className:"mb-2",children:e.jsx(Ct,{ownerSlug:t,entity:{entityName:z.entity_name,entityType:z.entity_type,entitySlug:z.entity_slug}})}),e.jsx(ie,{ownerSlug:t,content:z,showParentContext:Ee&&!!z.parent_context,connectorDefinitions:R}),j.length>0&&e.jsxs(xe,{open:pe,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-1 h-7 gap-1 text-xs text-muted-foreground",onClick:()=>X(H,i),children:[e.jsx(vt,{className:"h-3.5 w-3.5"}),pe?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",T!=null?`run #${T} `:"","history"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),T!=null?`Run #${T} · ${j.length===1?"1 earlier step":`${j.length} earlier steps`}`:j.length===1?"1 earlier state":`${j.length} earlier states`]})]})}),e.jsx(ge,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:j.map(C=>e.jsxs("div",{children:[e.jsx("time",{dateTime:new Date(C.occurred_at).toISOString(),title:ke(C.occurred_at),className:"mb-1 block text-xs text-muted-foreground",children:we(C.occurred_at)}),e.jsx(ie,{ownerSlug:t,content:C,connectorDefinitions:R})]},C.id))})]}),se&&e.jsxs(xe,{open:ee,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-2 ml-6 gap-1",onClick:()=>X($,i),children:[e.jsx(Nt,{className:"h-3.5 w-3.5"}),ee?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",u.replies.length," replies"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"Show ",u.replies.length," replies"]})]})}),e.jsxs(ge,{className:"space-y-2 mt-2",children:[Te.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id)),re.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"ghost",size:"sm",className:"ml-12",onClick:()=>X(ne,i),children:me?e.jsxs(e.Fragment,{children:["Hide ",re.length," nested replies"]}):e.jsxs(e.Fragment,{children:["Show ",re.length," nested replies"]})}),me&&re.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id))]})]})]})]},i):null}),e.jsx("div",{ref:l,className:"h-1"}),M&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(K,{size:"xl",className:"text-muted-foreground"})})]})}export{rn as E};
@@ -1 +0,0 @@
1
- import{j as t,a0 as o}from"./index-Bfux0kHb.js";function a(){return t.jsx(o,{})}export{a as component};
@@ -1 +0,0 @@
1
- import{ht as t,j as n}from"./index-Bfux0kHb.js";import{a as i}from"./agents-workbench-BOKifKIO.js";import"./agent-editor-form-CajEehVn.js";import"./model-selector-CvU3VP90.js";import"./proposal-review-shell-C_LcyUEF.js";import"./runs-BQ11PAQT.js";function d(){const{owner:o,agentId:r}=t.useParams(),e=t.useSearch();return n.jsx(i,{owner:o,agentId:r,tab:"identity",runId:e.run_id})}export{d as component};