@lobu/runtime-server 21.2.1 → 23.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 (420) hide show
  1. package/dist/catalogs/automations.json +40 -13
  2. package/dist/catalogs/connectors.json +18435 -1259
  3. package/dist/catalogs/skills.json +1 -1
  4. package/dist/component.json +1 -1
  5. package/dist/connectors/README.md +21 -6
  6. package/dist/connectors/_google/actions.ts +270 -0
  7. package/dist/connectors/_google/discovery/calendar_v3.json +1 -0
  8. package/dist/connectors/_google/discovery/chat_v1.json +1 -0
  9. package/dist/connectors/_google/discovery/docs_v1.json +1 -0
  10. package/dist/connectors/_google/discovery/drive_v3.json +1 -0
  11. package/dist/connectors/_google/discovery/gmail_v1.json +1 -0
  12. package/dist/connectors/_google/discovery/people_v1.json +1 -0
  13. package/dist/connectors/_google/discovery/sheets_v4.json +1 -0
  14. package/dist/connectors/_google/discovery/tasks_v1.json +1 -0
  15. package/dist/connectors/_google/discovery/youtube_v3.json +1 -0
  16. package/dist/connectors/_google/discovery.ts +442 -0
  17. package/dist/connectors/_google/errors.ts +91 -0
  18. package/dist/connectors/_google/list-feed.ts +223 -0
  19. package/dist/connectors/_google/policies.ts +127 -0
  20. package/dist/connectors/agentid.ts +43 -0
  21. package/dist/connectors/chat-user-identity.ts +2 -1
  22. package/dist/connectors/github-automation-events.ts +9 -0
  23. package/dist/connectors/github-identity.ts +28 -3
  24. package/dist/connectors/github.ts +101 -59
  25. package/dist/connectors/google_calendar.ts +207 -719
  26. package/dist/connectors/google_drive.ts +16 -2
  27. package/dist/connectors/google_gmail.ts +52 -33
  28. package/dist/connectors/herdr.ts +406 -0
  29. package/dist/connectors/jira-helpers.ts +313 -0
  30. package/dist/connectors/jira.ts +35 -227
  31. package/dist/connectors/linear.ts +7 -4
  32. package/dist/connectors/linkedin-browser-script.ts +13 -0
  33. package/dist/connectors/linkedin-draft-page.js +104 -0
  34. package/dist/connectors/linkedin-drafts.ts +73 -0
  35. package/dist/connectors/linkedin-identity.ts +32 -0
  36. package/dist/connectors/linkedin-inbox-adapter.js +1185 -0
  37. package/dist/connectors/linkedin-inbox.ts +156 -0
  38. package/dist/connectors/linkedin-like.ts +114 -0
  39. package/dist/connectors/linkedin-takeout.ts +577 -0
  40. package/dist/connectors/linkedin.ts +3998 -0
  41. package/dist/connectors/postgres.ts +27 -2
  42. package/dist/connectors/takeout-utils.ts +240 -0
  43. package/dist/connectors/tiktok-inbox-page.js +230 -0
  44. package/dist/connectors/tiktok-web-page.js +217 -0
  45. package/dist/connectors/tiktok_web.ts +319 -0
  46. package/dist/connectors/whatsapp-web-adapter.js +285 -567
  47. package/dist/connectors/whatsapp-web-helpers.ts +74 -455
  48. package/dist/connectors/whatsapp-web-identity.ts +135 -0
  49. package/dist/connectors/whatsapp_web.ts +159 -618
  50. package/dist/connectors/x-dm-adapter.js +556 -0
  51. package/dist/connectors/x-identity.ts +31 -2
  52. package/dist/connectors/x.ts +539 -253
  53. package/dist/db/migrations/20261005150000_retire_agent_tool_config.sql +31 -0
  54. package/dist/db/migrations/20261005173700_drop_retired_agent_tool_config.sql +29 -0
  55. package/dist/db/migrations/20261007010000_identity_association_guards.sql +242 -0
  56. package/dist/db/migrations/20261007010001_identity_association_indexes.sql +35 -0
  57. package/dist/db/migrations/20261007012000_connector_browser_requirement.sql +7 -0
  58. package/dist/db/migrations/20261009010000_identity_member_decision_indexes.sql +22 -0
  59. package/dist/db/migrations/20261009015900_retire_remaining_physical_merges.sql +196 -0
  60. package/dist/db/migrations/20261009020000_retire_physical_entity_merge.sql +82 -0
  61. package/dist/db/migrations/20261009030000_retire_physical_merge_indexes.sql +39 -0
  62. package/dist/db/migrations/20261009030001_drop_physical_entity_redirect.sql +62 -0
  63. package/dist/db/migrations/20261009040000_normalize_identity_decisions.sql +60 -0
  64. package/dist/db/migrations/20261010220000_notification_targets_user_event_order.sql +53 -0
  65. package/dist/db/migrations/20261010223000_device_workers_user_fresh_cover.sql +39 -0
  66. package/dist/db/migrations/20261010223001_runs_org_default_view.sql +41 -0
  67. package/dist/db/migrations/20261010223002_events_org_guidance.sql +42 -0
  68. package/dist/db/migrations/20261011002000_finish_product_eval_retirement.sql +37 -0
  69. package/dist/db/migrations/20261011160000_mcp_conversation_workspaces.sql +97 -0
  70. package/dist/db/migrations/20261013120000_events_live_org_effective_date.sql +42 -0
  71. package/dist/db/migrations/20261013150000_events_live_linked_org_ids_gin.sql +41 -0
  72. package/dist/db/migrations/20261014120000_clear_team_device_auto_pause.sql +34 -0
  73. package/dist/db/migrations/20261014150000_connector_webhook_event_type_backfill.sql +30 -0
  74. package/dist/db/migrations/20261014170000_retire_atlassian_mcp_webhook_refresh.sql +51 -0
  75. package/dist/db/migrations/20261015010000_connection_auth_profile_fk_set_null_column.sql +53 -0
  76. package/dist/db/migrations/20261015120000_personal_org_connector_auto_policy.sql +38 -0
  77. package/dist/db/migrations/20261017120000_drop_feeds_kind_virtual.sql +26 -0
  78. package/dist/db/migrations/20261017130000_drop_retired_dead_code_columns.sql +46 -0
  79. package/dist/db/migrations/preconditions/20261005150000_retire_agent_tool_config.sql +22 -0
  80. package/dist/db/migrations/preconditions/20261005173700_drop_retired_agent_tool_config.sql +13 -0
  81. package/dist/db/migrations/preconditions/20261009020000_retire_physical_entity_merge.sql +26 -0
  82. package/dist/db/migrations/preconditions/20261011002000_finish_product_eval_retirement.sql +14 -0
  83. package/dist/dependencies.bun.lock +144 -137
  84. package/dist/guest.bundle.js +416 -330
  85. package/dist/owletto/dist/assets/_-3J-IrxWk.js +2 -0
  86. package/dist/owletto/dist/assets/_-DYUE3ix4.js +3 -0
  87. package/dist/owletto/dist/assets/_-DtqBFgK5.js +1 -0
  88. package/dist/owletto/dist/assets/_agentId-Bn2IAjIy.js +2 -0
  89. package/dist/owletto/dist/assets/_agentId-Cam7Z0N7.js +2 -0
  90. package/dist/owletto/dist/assets/_automationId-CXEiKVZJ.js +2 -0
  91. package/dist/owletto/dist/assets/_connectorKey._connectionId-CS85l61t.js +2 -0
  92. package/dist/owletto/dist/assets/_connectorKey.index-clVDIyW0.js +2 -0
  93. package/dist/owletto/dist/assets/_conversationId-Ci2k-BuN.js +2 -0
  94. package/dist/owletto/dist/assets/_deploymentId-BuUzGtVL.js +2 -0
  95. package/dist/owletto/dist/assets/_eventId-B0662F8h.js +2 -0
  96. package/dist/owletto/dist/assets/_name-CwWePlOl.js +2 -0
  97. package/dist/owletto/dist/assets/_owner-dTWkrKsK.js +3 -0
  98. package/dist/owletto/dist/assets/_shape-BtS3y4M9.js +2 -0
  99. package/dist/owletto/dist/assets/_skillKey-Dc9m-nlR.js +2 -0
  100. package/dist/owletto/dist/assets/_slug-DQHutM41.js +2 -0
  101. package/dist/owletto/dist/assets/_threadId-DtqBFgK5.js +1 -0
  102. package/dist/owletto/dist/assets/_viewKey-B30ik8ma.js +2 -0
  103. package/dist/owletto/dist/assets/_viewKey-CUHypQnF.js +2 -0
  104. package/dist/owletto/dist/assets/accept-invitation-w17IFTtf.js +2 -0
  105. package/dist/owletto/dist/assets/activity-route-view-CMqYiiKM.js +2 -0
  106. package/dist/owletto/dist/assets/agent-card-controls-mnTN2AZt.js +2 -0
  107. package/dist/owletto/dist/assets/{agent-client-setup-list-BFtgRwe8.js → agent-client-setup-list-Bg3hBfUV.js} +4 -3
  108. package/dist/owletto/dist/assets/agent-connect-pages-B_vrqLVc.js +2 -0
  109. package/dist/owletto/dist/assets/agent-editor-form-hTs7eO_U.js +2 -0
  110. package/dist/owletto/dist/assets/agent-guardrails-route-BOrCXcAl.js +2 -0
  111. package/dist/owletto/dist/assets/agent-loading-shells-Dqcvky-k.js +2 -0
  112. package/dist/owletto/dist/assets/agent-permissions-matrix-BOo_4r_4.js +2 -0
  113. package/dist/owletto/dist/assets/{agent-skill-context-BAr2Dw3F.js → agent-skill-context-CCdvtlmH.js} +2 -1
  114. package/dist/owletto/dist/assets/agent-skills-route-BUxIswuq.js +2 -0
  115. package/dist/owletto/dist/assets/agent-subpage-shell-D92imvSt.js +2 -0
  116. package/dist/owletto/dist/assets/agent-thread-BJOijbT0.js +6 -0
  117. package/dist/owletto/dist/assets/agents-9XjpDj_S.js +2 -0
  118. package/dist/owletto/dist/assets/agents-workbench-Bt5QCYQ7.js +2 -0
  119. package/dist/owletto/dist/assets/app-bridge-BCm4muqj.js +128 -0
  120. package/dist/owletto/dist/assets/app._appId-CKv7_squ.js +2 -0
  121. package/dist/owletto/dist/assets/automation-detail-content-vUwVumXf.js +2 -0
  122. package/dist/owletto/dist/assets/automations-9XjpDj_S.js +2 -0
  123. package/dist/owletto/dist/assets/{callback-CaRe2TOT.js → callback-BRgcL8gz.js} +2 -1
  124. package/dist/owletto/dist/assets/{card-CMmh2mzo.js → card-Djgp00r_.js} +2 -1
  125. package/dist/owletto/dist/assets/claim-BYUZnyMp.js +2 -0
  126. package/dist/owletto/dist/assets/client-rows-EJSKR6z1.js +1 -0
  127. package/dist/owletto/dist/assets/clients-D3Zbjxin.js +2 -0
  128. package/dist/owletto/dist/assets/code-editor-DHeyRGZI.js +16 -0
  129. package/dist/owletto/dist/assets/connect-CfsFsy9P.js +2 -0
  130. package/dist/owletto/dist/assets/connect._clientId-DkiC8xos.js +2 -0
  131. package/dist/owletto/dist/assets/connected._clientId-CIXrGOsT.js +2 -0
  132. package/dist/owletto/dist/assets/connected._clientId.activity-Ckdz6I0y.js +2 -0
  133. package/dist/owletto/dist/assets/connected._clientId.index-CNxafNeo.js +2 -0
  134. package/dist/owletto/dist/assets/connection-C3XXFEqh.js +2 -0
  135. package/dist/owletto/dist/assets/connection-feed-detail-CIJJLDP8.js +2 -0
  136. package/dist/owletto/dist/assets/connection-label-BobuYiAG.js +1 -0
  137. package/dist/owletto/dist/assets/connections-browser-CKZjzRz6.js +2 -0
  138. package/dist/owletto/dist/assets/{connector-provenance-BjKiUhYE.js → connector-provenance-8-d8hl10.js} +2 -1
  139. package/dist/owletto/dist/assets/connector-scope-lists-CadPVsI3.js +2 -0
  140. package/dist/owletto/dist/assets/{connectors-Baejya0T.js → connectors-lvLJ30lo.js} +2 -1
  141. package/dist/owletto/dist/assets/consent-CdSvVCgx.js +2 -0
  142. package/dist/owletto/dist/assets/conversations-table-BdXoZAfc.js +2 -0
  143. package/dist/owletto/dist/assets/{core.esm-QA7BQgiK.js → core.esm-CYvgWCuv.js} +2 -1
  144. package/dist/owletto/dist/assets/create-0xW9eXxG.js +2 -0
  145. package/dist/owletto/dist/assets/create-B0qhrrX4.js +2 -0
  146. package/dist/owletto/dist/assets/create-CAfF-yI1.js +2 -0
  147. package/dist/owletto/dist/assets/create-automation-form-CtSSeYj3.js +3 -0
  148. package/dist/owletto/dist/assets/create._connectorKey-i6xxkWKV.js +2 -0
  149. package/dist/owletto/dist/assets/{cronstrue-2GHCtD7h.js → cronstrue-n4qGUraE.js} +2 -1
  150. package/dist/owletto/dist/assets/deployments-4Itm35Xc.js +2 -0
  151. package/dist/owletto/dist/assets/deployments-RvUdVkj3.js +2 -0
  152. package/dist/owletto/dist/assets/{deployments-body-Bm2upStd.js → deployments-body-BMp7UsMo.js} +2 -1
  153. package/dist/owletto/dist/assets/device-CPU6CjkJ.js +2 -0
  154. package/dist/owletto/dist/assets/device-pin-tombstone-CrjG7gPo.js +2 -0
  155. package/dist/owletto/dist/assets/device._deviceId-Cs3ZmXWo.js +2 -0
  156. package/dist/owletto/dist/assets/{entity-options-CrbS6K-i.js → entity-options-uXjgT7y9.js} +2 -1
  157. package/dist/owletto/dist/assets/entity-page-Dc0LGr5U.js +2 -0
  158. package/dist/owletto/dist/assets/entity-type-page-CwZxa0BR.js +2 -0
  159. package/dist/owletto/dist/assets/event-detail-ve2d6Gbb.js +2 -0
  160. package/dist/owletto/dist/assets/events-feed-BtvhZF1f.js +2 -0
  161. package/dist/owletto/dist/assets/filter-editors-Cj-v6NtH.js +2 -0
  162. package/dist/owletto/dist/assets/full-page-spinner-DqpH99np.js +2 -0
  163. package/dist/owletto/dist/assets/guardrails-HFo2Ut8B.js +2 -0
  164. package/dist/owletto/dist/assets/identity-BigVSBCl.js +2 -0
  165. package/dist/owletto/dist/assets/index-B9uPN6FC.js +2 -0
  166. package/dist/owletto/dist/assets/index-BLEcy9-T.css +1 -0
  167. package/dist/owletto/dist/assets/index-BQVliQW1.js +2 -0
  168. package/dist/owletto/dist/assets/index-BfedB4Rc.js +2 -0
  169. package/dist/owletto/dist/assets/index-CDz3-ieP.js +1 -0
  170. package/dist/owletto/dist/assets/index-CUw3aKBI.js +2 -0
  171. package/dist/owletto/dist/assets/index-CXhxUkv3.js +2 -0
  172. package/dist/owletto/dist/assets/index-Cr5hwh-C.js +7950 -0
  173. package/dist/owletto/dist/assets/index-CzkTV4ZQ.js +2 -0
  174. package/dist/owletto/dist/assets/index-DKSx8JN_.js +2 -0
  175. package/dist/owletto/dist/assets/index-DVk7Ug0d.js +2 -0
  176. package/dist/owletto/dist/assets/index-DmZuKGf8.js +2 -0
  177. package/dist/owletto/dist/assets/index-DtqBFgK5.js +1 -0
  178. package/dist/owletto/dist/assets/index-Hio-HRfo.js +2 -0
  179. package/dist/owletto/dist/assets/{index-Cf0GJoiG.js → index-ICgKp3YK.js} +2 -1
  180. package/dist/owletto/dist/assets/index-Vcq4gwWv.js +1 -0
  181. package/dist/owletto/dist/assets/index-cPcroOH0.js +2 -0
  182. package/dist/owletto/dist/assets/{index-DlepU3cY.js → index-n7sTbNv4.js} +2 -1
  183. package/dist/owletto/dist/assets/index-rrnUF981.js +1 -0
  184. package/dist/owletto/dist/assets/index-xiFpcWKv.js +2 -0
  185. package/dist/owletto/dist/assets/json-diff-DBoag_OS.js +4 -0
  186. package/dist/owletto/dist/assets/{list-skeleton-BtWn2eo2.js → list-skeleton-C_GuoxAH.js} +2 -1
  187. package/dist/owletto/dist/assets/login-Ci6ixHuL.js +2 -0
  188. package/dist/owletto/dist/assets/logout-CLGgeZB7.js +2 -0
  189. package/dist/owletto/dist/assets/member-scope-gate-B44INDPY.js +2 -0
  190. package/dist/owletto/dist/assets/memory-browse-page-DyQiRvzl.js +103 -0
  191. package/dist/owletto/dist/assets/model-selector-dAbDgJvx.js +2 -0
  192. package/dist/owletto/dist/assets/models-DpVP7ZwX.js +2 -0
  193. package/dist/owletto/dist/assets/new-BUb7AnEW.js +2 -0
  194. package/dist/owletto/dist/assets/new-BkdULx2r.js +2 -0
  195. package/dist/owletto/dist/assets/new-CHOr-EcI.js +2 -0
  196. package/dist/owletto/dist/assets/oauth-workspace-access-BxsjwgdH.js +2 -0
  197. package/dist/owletto/dist/assets/organization-gxGeDjIV.js +2 -0
  198. package/dist/owletto/dist/assets/peek-pane-content-CHoQHe2H.js +2 -0
  199. package/dist/owletto/dist/assets/{permissions-h_qSft1A.js → permissions-aPHaKLec.js} +2 -1
  200. package/dist/owletto/dist/assets/proposal-review-shell-UcZr87_Q.js +2 -0
  201. package/dist/owletto/dist/assets/public-shell-ready-DcnlADmj.js +2 -0
  202. package/dist/owletto/dist/assets/{recent-JiBNvZzD.js → recent-D-65Pgu-.js} +2 -1
  203. package/dist/owletto/dist/assets/record-activity-CBXH6v1d.js +2 -0
  204. package/dist/owletto/dist/assets/{renderer-DgPLyEbx.js → renderer-mEDnVW0O.js} +28 -27
  205. package/dist/owletto/dist/assets/reset-password-uX_V6bip.js +2 -0
  206. package/dist/owletto/dist/assets/runs-C0rCgGwX.js +2 -0
  207. package/dist/owletto/dist/assets/runs-panel-Du1JMjg5.js +2 -0
  208. package/dist/owletto/dist/assets/runs-table-syPJ6r6T.js +2 -0
  209. package/dist/owletto/dist/assets/settings-9NkNA1G1.js +2 -0
  210. package/dist/owletto/dist/assets/settings-E-10sLQX.js +2 -0
  211. package/dist/owletto/dist/assets/skill-editor-D_W3QlRz.js +1 -0
  212. package/dist/owletto/dist/assets/skills-D2Ri9b4f.js +2 -0
  213. package/dist/owletto/dist/assets/source-record-panels-CPyzlfD1.js +2 -0
  214. package/dist/owletto/dist/assets/status-dot-B-EWMgq6.js +2 -0
  215. package/dist/owletto/dist/assets/tabs-DqIIkCX-.js +2 -0
  216. package/dist/owletto/dist/assets/{use-mention-search-B4DfZFm5.js → use-mention-search-By8RZyKW.js} +3 -2
  217. package/dist/owletto/dist/assets/view-param-filters-CqLZQrnO.js +2 -0
  218. package/dist/owletto/dist/assets/workspace-label-o_QfBuCM.js +2 -0
  219. package/dist/owletto/dist/index.html +46 -4
  220. package/dist/providers.json +1 -1
  221. package/dist/server-main.bundle.mjs +137029 -133673
  222. package/npm-shrinkwrap.json +612 -645
  223. package/package.json +4 -3
  224. package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
  225. package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
  226. package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
  227. package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
  228. package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
  229. package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
  230. package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
  231. package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
  232. package/vendor/connector-sdk/dist/connector-types.d.ts +169 -45
  233. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
  234. package/vendor/connector-sdk/dist/define-connector.js +3 -0
  235. package/vendor/connector-sdk/dist/index.d.ts +8 -2
  236. package/vendor/connector-sdk/dist/index.js +3 -0
  237. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
  238. package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
  239. package/vendor/connector-sdk/package.json +13 -1
  240. package/vendor/core/dist/agent-policy.js +1 -1
  241. package/vendor/core/dist/agent-store.d.ts +2 -0
  242. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  243. package/vendor/core/dist/agent-tooling.js +1 -1
  244. package/vendor/core/dist/capabilities.d.ts +1 -1
  245. package/vendor/core/dist/capabilities.js +2 -1
  246. package/vendor/core/dist/connector-query-errors.d.ts +32 -0
  247. package/vendor/core/dist/connector-query-errors.js +41 -1
  248. package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
  249. package/vendor/core/dist/contracts/agent-settings.js +1 -7
  250. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
  251. package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
  252. package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
  253. package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
  254. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
  255. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
  256. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
  257. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
  258. package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
  259. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
  260. package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
  261. package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
  262. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
  263. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
  264. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
  265. package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
  266. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
  267. package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
  268. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
  269. package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
  270. package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
  271. package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
  272. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
  273. package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
  274. package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
  275. package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
  276. package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
  277. package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
  278. package/vendor/core/dist/contracts/worker/protocol.d.ts +130 -159
  279. package/vendor/core/dist/contracts/worker/protocol.js +88 -76
  280. package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
  281. package/vendor/core/dist/device-pin-tombstones.js +57 -0
  282. package/vendor/core/dist/index.d.ts +5 -5
  283. package/vendor/core/dist/index.js +4 -6
  284. package/vendor/core/dist/json-template.d.ts +6 -10
  285. package/vendor/core/dist/json-template.js +5 -9
  286. package/vendor/core/dist/logger.js +17 -26
  287. package/vendor/core/dist/shell-safety.d.ts +9 -0
  288. package/vendor/core/dist/shell-safety.js +154 -0
  289. package/vendor/core/dist/suggestions.d.ts +1 -1
  290. package/vendor/core/dist/suggestions.js +1 -1
  291. package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
  292. package/vendor/core/dist/tool-trace-summary.js +1 -1
  293. package/vendor/core/dist/types.d.ts +1 -3
  294. package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
  295. package/vendor/core/dist/utils/diagnostic-scrubber.js +437 -0
  296. package/vendor/core/dist/worker/auth.d.ts +44 -6
  297. package/vendor/core/dist/worker/auth.js +44 -11
  298. package/vendor/core/dist/worker/wire.d.ts +0 -10
  299. package/vendor/core/package.json +20 -11
  300. package/vendor/views/dist/api.d.ts +39 -29
  301. package/vendor/views/dist/api.js +110 -83
  302. package/vendor/views/dist/bridge.d.ts +4 -0
  303. package/vendor/views/dist/bridge.js +15 -0
  304. package/vendor/views/dist/index.d.ts +1 -0
  305. package/vendor/views/dist/index.js +0 -7
  306. package/vendor/views/package.json +4 -1
  307. package/dist/owletto/dist/assets/_-CLhipgJI.js +0 -1
  308. package/dist/owletto/dist/assets/_-D0ZVGAIA.js +0 -2
  309. package/dist/owletto/dist/assets/_agentId-BLXUf3ot.js +0 -1
  310. package/dist/owletto/dist/assets/_agentId-DnI66MF3.js +0 -1
  311. package/dist/owletto/dist/assets/_automationId-ziwseLb7.js +0 -1
  312. package/dist/owletto/dist/assets/_connectorKey._connectionId-B6V3ySFK.js +0 -1
  313. package/dist/owletto/dist/assets/_connectorKey.index-CR5u_dtt.js +0 -1
  314. package/dist/owletto/dist/assets/_conversationId-FBMYmOl8.js +0 -1
  315. package/dist/owletto/dist/assets/_deploymentId-DNTXbT_m.js +0 -1
  316. package/dist/owletto/dist/assets/_name-B37LKIxH.js +0 -1
  317. package/dist/owletto/dist/assets/_owner-BxYumqC2.js +0 -1
  318. package/dist/owletto/dist/assets/_shape-Bxz-04jR.js +0 -1
  319. package/dist/owletto/dist/assets/_skillKey-D5MFbiw2.js +0 -1
  320. package/dist/owletto/dist/assets/_slug-Dlhit09k.js +0 -1
  321. package/dist/owletto/dist/assets/_viewKey-C6535i-t.js +0 -1
  322. package/dist/owletto/dist/assets/_viewKey-CQCtY3Y8.js +0 -1
  323. package/dist/owletto/dist/assets/_viewKey-CxKfKbRa.js +0 -1
  324. package/dist/owletto/dist/assets/accept-invitation-BQQwec3R.js +0 -1
  325. package/dist/owletto/dist/assets/activity-route-view-BwThvdGs.js +0 -1
  326. package/dist/owletto/dist/assets/agent-card-controls-B3RhzsPz.js +0 -1
  327. package/dist/owletto/dist/assets/agent-connect-pages-BO4wQn4L.js +0 -1
  328. package/dist/owletto/dist/assets/agent-editor-form-BYC4uSNz.js +0 -1
  329. package/dist/owletto/dist/assets/agent-guardrails-route-Dp02G1AQ.js +0 -1
  330. package/dist/owletto/dist/assets/agent-loading-shells-OagauQzV.js +0 -1
  331. package/dist/owletto/dist/assets/agent-permissions-matrix-B9Ho3P1t.js +0 -1
  332. package/dist/owletto/dist/assets/agent-skills-route-B4VUnVi0.js +0 -1
  333. package/dist/owletto/dist/assets/agent-subpage-shell-Dz8I-GUt.js +0 -1
  334. package/dist/owletto/dist/assets/agent-thread-B9-cdkaV.js +0 -8
  335. package/dist/owletto/dist/assets/agent-thread-storage-U6htL3ad.js +0 -1
  336. package/dist/owletto/dist/assets/agents-D0CIg4b9.js +0 -1
  337. package/dist/owletto/dist/assets/agents-workbench-C2sr5h82.js +0 -1
  338. package/dist/owletto/dist/assets/app-bridge-BH3g2mKG.js +0 -127
  339. package/dist/owletto/dist/assets/app._appId-DLsJ_QWS.js +0 -1
  340. package/dist/owletto/dist/assets/automation-detail-content-9Rjb_I9j.js +0 -1
  341. package/dist/owletto/dist/assets/automations-D0CIg4b9.js +0 -1
  342. package/dist/owletto/dist/assets/calendar-DAiyi1ZL.js +0 -1
  343. package/dist/owletto/dist/assets/claim-CYHnUF7G.js +0 -1
  344. package/dist/owletto/dist/assets/clients-Cp1BJ28u.js +0 -1
  345. package/dist/owletto/dist/assets/code-editor-CYsR2VBP.js +0 -15
  346. package/dist/owletto/dist/assets/connect-CZip2g_B.js +0 -1
  347. package/dist/owletto/dist/assets/connect._clientId-CEKY8Dnv.js +0 -1
  348. package/dist/owletto/dist/assets/connected._clientId-C5xRjxNO.js +0 -1
  349. package/dist/owletto/dist/assets/connection-C06HZ241.js +0 -1
  350. package/dist/owletto/dist/assets/connection-feed-detail-D1whY5hL.js +0 -1
  351. package/dist/owletto/dist/assets/consent-CfYDldcF.js +0 -1
  352. package/dist/owletto/dist/assets/create-C3P-3_8O.js +0 -1
  353. package/dist/owletto/dist/assets/create-CwnrPUEw.js +0 -1
  354. package/dist/owletto/dist/assets/create-DOScS9Gl.js +0 -1
  355. package/dist/owletto/dist/assets/create-automation-form-CuxiIRCF.js +0 -2
  356. package/dist/owletto/dist/assets/create._connectorKey-Bjv3lCf8.js +0 -1
  357. package/dist/owletto/dist/assets/deployments-ByBv1DW-.js +0 -1
  358. package/dist/owletto/dist/assets/deployments-C-_ECORv.js +0 -1
  359. package/dist/owletto/dist/assets/device-B0i7Xp8y.js +0 -1
  360. package/dist/owletto/dist/assets/device-automation-BIjs7DZJ.js +0 -1
  361. package/dist/owletto/dist/assets/device-pin-tombstone-Bd6vS2zu.js +0 -1
  362. package/dist/owletto/dist/assets/device-rows-Bwf8qDte.js +0 -1
  363. package/dist/owletto/dist/assets/device._deviceId-DJLAesm3.js +0 -1
  364. package/dist/owletto/dist/assets/entity-page-ijZe_1-6.js +0 -1
  365. package/dist/owletto/dist/assets/entity-type-page-onp2Tk_E.js +0 -1
  366. package/dist/owletto/dist/assets/event-page-C0B2UDY-.js +0 -1
  367. package/dist/owletto/dist/assets/events-feed-DK35T4g7.js +0 -1
  368. package/dist/owletto/dist/assets/full-page-spinner-Dd8eEaxq.js +0 -1
  369. package/dist/owletto/dist/assets/guardrails-DKO8_J-G.js +0 -1
  370. package/dist/owletto/dist/assets/identity-CKM54vrM.js +0 -1
  371. package/dist/owletto/dist/assets/index--VmN5WxW.js +0 -1
  372. package/dist/owletto/dist/assets/index-B2AmRqYh.js +0 -7898
  373. package/dist/owletto/dist/assets/index-B_rcEgFX.js +0 -1
  374. package/dist/owletto/dist/assets/index-BmAuAhub.css +0 -1
  375. package/dist/owletto/dist/assets/index-BmhGe6-Z.js +0 -1
  376. package/dist/owletto/dist/assets/index-C1dJSGrL.js +0 -1
  377. package/dist/owletto/dist/assets/index-CAFw4qCb.js +0 -1
  378. package/dist/owletto/dist/assets/index-CCcc_xBw.js +0 -52
  379. package/dist/owletto/dist/assets/index-CLU3gXVm.js +0 -1
  380. package/dist/owletto/dist/assets/index-CqQVnAY-.js +0 -1
  381. package/dist/owletto/dist/assets/index-CxT0uyIe.js +0 -1
  382. package/dist/owletto/dist/assets/index-DR08e6Ec.js +0 -1
  383. package/dist/owletto/dist/assets/index-DYb9L5FC.js +0 -1
  384. package/dist/owletto/dist/assets/index-SUUcQGT-.js +0 -1
  385. package/dist/owletto/dist/assets/index-SdiFOfR1.js +0 -1
  386. package/dist/owletto/dist/assets/index-zcfi5r1l.js +0 -1
  387. package/dist/owletto/dist/assets/json-diff-ClBBYBQD.js +0 -3
  388. package/dist/owletto/dist/assets/login-d3PdO-qV.js +0 -1
  389. package/dist/owletto/dist/assets/logout-DgckxwLn.js +0 -1
  390. package/dist/owletto/dist/assets/member-scope-gate-DXOCfx-v.js +0 -1
  391. package/dist/owletto/dist/assets/memory-browse-page-CeAnKoTR.js +0 -101
  392. package/dist/owletto/dist/assets/missing-view-DrZ8m8yo.js +0 -1
  393. package/dist/owletto/dist/assets/model-selector-CapL1ARf.js +0 -1
  394. package/dist/owletto/dist/assets/models-CB8mhq7j.js +0 -1
  395. package/dist/owletto/dist/assets/new-BBUb-VR4.js +0 -1
  396. package/dist/owletto/dist/assets/new-CBLJ25_w.js +0 -1
  397. package/dist/owletto/dist/assets/new-tTXB4qBW.js +0 -1
  398. package/dist/owletto/dist/assets/oauth-workspace-access-DearynqZ.js +0 -1
  399. package/dist/owletto/dist/assets/organization-BgdBg-PJ.js +0 -1
  400. package/dist/owletto/dist/assets/pending-seed-CPbfgnLX.js +0 -1
  401. package/dist/owletto/dist/assets/proposal-review-shell-D4YNrrye.js +0 -1
  402. package/dist/owletto/dist/assets/reset-password-B8tWPtIj.js +0 -1
  403. package/dist/owletto/dist/assets/runs-oHveuEUB.js +0 -1
  404. package/dist/owletto/dist/assets/runs-panel-C56GDaJm.js +0 -1
  405. package/dist/owletto/dist/assets/runs-table-BUKDjiBc.js +0 -1
  406. package/dist/owletto/dist/assets/schema-value-normalization-3JuM_r1H.js +0 -1
  407. package/dist/owletto/dist/assets/settings-DaKg6U5O.js +0 -1
  408. package/dist/owletto/dist/assets/settings-DhnRi2nq.js +0 -1
  409. package/dist/owletto/dist/assets/skills-BpQncuMC.js +0 -1
  410. package/dist/owletto/dist/assets/switch-BQ40_DMb.js +0 -1
  411. package/dist/owletto/dist/assets/use-applied-views-B-Z-Weji.js +0 -1
  412. package/dist/owletto/dist/assets/view-frame-C7ciEoLo.js +0 -1
  413. package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
  414. package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
  415. package/vendor/core/dist/sentry.d.ts +0 -26
  416. package/vendor/core/dist/sentry.js +0 -133
  417. package/vendor/core/dist/tool-policy.d.ts +0 -74
  418. package/vendor/core/dist/tool-policy.js +0 -305
  419. package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
  420. package/vendor/core/dist/utils/sentry-scrubber.js +0 -228
@@ -1 +0,0 @@
1
- import{dU as K,r as o,j as e,cB as H,cC as q,aL as W,af as k,B as N,dO as G,eC as J,cb as M,eh as w,dN as F,bR as X,bS as Q,bT as Y,bU as Z,bV as ee,dL as O,cf as P,b_ as se,n as E,eD as te,eo as ne,E as ae,eE as ce,aP as ie,eF as le,eG as re,eH as oe,eI as de,eJ as ue,eK as me,ej as xe,L as R,eL as V,ab as he,x as A}from"./index-B2AmRqYh.js";import{f as ge,C as pe}from"./entity-options-CrbS6K-i.js";import{V as fe,R as je,S as L,g as $}from"./runs-table-BUKDjiBc.js";function ve({organizationId:s,value:t,onChange:a,entities:n,className:m}){const{data:i=[]}=K(n?void 0:s),u=o.useMemo(()=>n??ge(i),[n,i]),f=new Set(t),l=u.filter(c=>f.has(c.id)),d=c=>{const p=new Set(f);p.has(c)?p.delete(c):p.add(c),a(Array.from(p).sort((v,y)=>v-y))},x=l.length===0?"All entities":l.length===1?l[0].name:`${l.length} entities selected`;return e.jsx(H,{contentClassName:"w-[320px]",searchPlaceholder:"Filter entities...",emptyText:"No entities found.",trigger:c=>e.jsxs(N,{variant:"outline",role:"combobox","aria-expanded":c,className:k("justify-between",m),children:[x,e.jsx(G,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>u.map(c=>{const p=f.has(c.id);return e.jsxs(q,{value:`${c.name} ${c.entityType}`,onSelect:()=>d(c.id),className:"cursor-pointer",children:[e.jsx(W,{className:k("mr-2 h-4 w-4",p?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[c.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",c.entityType,")"]})]})]},c.id)})})}function ye(s){return s?.feeds_schema?Object.entries(s.feeds_schema).map(([t,a])=>({key:t,name:a.name??t,description:a.description,configSchema:a.configSchema})):[]}const Ce="Feeds are optional scheduled sync targets for an existing connection.";function ke({organizationId:s,connections:t,connectorDefinitions:a,entityId:n,onClose:m}){const i=t.length===1,[u,f]=o.useState(i?String(t[0].id):""),[l,d]=o.useState(""),[x,c]=o.useState(n?[n]:[]),[p,v]=o.useState(null),y=J(),_=o.useMemo(()=>new Map(a.map(r=>[r.key,r])),[a]),h=o.useMemo(()=>t.find(r=>String(r.id)===u),[t,u]),b=o.useMemo(()=>h?ye(_.get(h.connector_key)):[],[h,_]),S=o.useMemo(()=>b.find(r=>r.key===l)??null,[b,l]),g=M(`${u}:${l}`,w(S?.configSchema),S?.configSchema),{values:j,setValues:I}=g,D=o.useCallback(()=>{f(i?String(t[0].id):""),d(""),c(n?[n]:[]),v(null)},[n,i,t]),C=o.useCallback(()=>{D(),m()},[m,D]),B=o.useCallback(async()=>{if(!g.canSubmit||!h||!l)return;v(null);const r=F(j);try{await y.mutateAsync({connection_id:h.id,feed_key:l,config:Object.keys(r).length>0?r:void 0,entity_ids:n?[n]:x.length>0?x:void 0}),C()}catch(T){v(T instanceof Error?T.message:"Failed to create feed")}},[j,g.canSubmit,y,n,C,h,x,l]),z=e.jsxs("div",{className:"flex-1 space-y-4 overflow-y-auto py-6 pr-1",children:[!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Connection"}),e.jsx(pe,{connections:t,value:u,onValueChange:r=>{f(r),d(""),v(null)},placeholder:"Select a connection"})]}),h&&b.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Feed Type"}),e.jsxs(X,{value:l,onValueChange:d,children:[e.jsx(Q,{children:e.jsx(Y,{placeholder:"Select feed type"})}),e.jsx(Z,{children:b.map(r=>e.jsx(ee,{value:r.key,children:e.jsxs("div",{children:[e.jsx("span",{children:r.name}),r.description&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["— ",r.description]})]})},r.key))})]})]}),n?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Target Entity"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This feed will be attached to the current entity."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Target Entities"}),e.jsx(ve,{organizationId:s,value:x,onChange:c,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Leave empty to create an unscoped feed."})]}),g.revision&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Feed Configuration"}),e.jsx(O,{schema:g.revision,values:j,onValuesChange:I})]}),h&&b.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connector has no configurable feed types."}),e.jsx(P,{visible:g.hasConflict,onReload:g.reset}),p&&e.jsx("p",{className:"text-sm text-destructive",children:p})]}),U=e.jsx(se,{onCancel:C,className:"mt-2",children:e.jsxs(N,{disabled:!g.canSubmit||!l||y.isPending,onClick:()=>void B(),children:[y.isPending&&e.jsx(E,{size:"lg",className:"mr-2"}),"Create Feed"]})});return e.jsxs("div",{className:"flex flex-col",children:[z,U]})}function we({feed:s,onClose:t,hideHeader:a=!1}){const n=s.display_name?.trim()||s.feed_key,m=s.feed_key.includes(":")?s.feed_key.slice(s.feed_key.indexOf(":")+1):s.feed_key,i=s.external_tenant_id,u=s.connector_key==="slack"&&i?`https://app.slack.com/client/${i}/${m}`:void 0;return e.jsxs("div",{className:"flex max-w-xl flex-col gap-4",children:[a?null:e.jsxs(e.Fragment,{children:[t?e.jsxs("button",{type:"button",onClick:t,className:"inline-flex w-fit items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx(te,{className:"h-3 w-3"}),"Back to connection"]}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"chat channel"})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Messages captured for this channel are available to Lobu Automations. Open Slack to read the channel history."}),u?e.jsx(N,{asChild:!0,variant:"outline",className:"w-full justify-center",children:e.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ae,{className:"mr-2 h-4 w-4"}),"Open in Slack"]})}):null,e.jsxs("div",{className:k(ie,"flex flex-col gap-3 p-4"),children:[e.jsx("div",{className:"text-xs font-medium uppercase text-muted-foreground",children:"Channel"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:n})]}),i?e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace"}),e.jsx("span",{className:"break-all font-mono text-xs",children:i})]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages the bot sees here are captured as they arrive. Open the channel in Slack to read the full history."})]})]})}function Fe(s,t){return s.display_name?s.display_name:t?.feeds_schema?.[s.feed_key]?.name??s.feed_key}function be(s,t){const a=s?.feeds_schema;if(!a)return;if(a[t]?.configSchema)return a[t].configSchema;for(const m of Object.values(a))if(m?.key===t&&m.configSchema)return m.configSchema;const n=Object.values(a);if(n.length===1&&n[0]?.configSchema)return n[0].configSchema}function Ee({feed:s,ownerSlug:t}){return e.jsxs(e.Fragment,{children:[e.jsx(L,{status:$(s.status),showDot:!0,children:s.status}),s.connection_status&&s.connection_status!==s.status&&e.jsxs(L,{status:$(s.connection_status),showDot:!0,children:["Connection: ",s.connection_status]}),s.device_worker_id?e.jsx(R,{to:"/$owner/connectors/device/$deviceId",params:{owner:t,deviceId:s.device_worker_id},children:e.jsx(he,{variant:s.device_status==="offline"?"secondary":"outline",className:"text-xs hover:bg-accent",children:s.device_status==="offline"?`Waiting for ${s.device_label||s.device_platform||"device"}`:`On ${s.device_label||s.device_platform||"device"}`})}):null]})}function De({feed:s}){return s.operations.includes("sync")?e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["Last sync: ",s.last_sync_at?A(s.last_sync_at):"—"]}),e.jsxs("span",{children:["Next: ",s.next_run_at?A(s.next_run_at):"—"]}),e.jsxs("span",{className:"font-mono",children:[(s.event_count??0).toLocaleString()," events"]})]}):e.jsx("span",{children:"Read live when queried"})}function Te({feed:s,connectorDef:t,ownerSlug:a}){const{data:n,refetch:m}=le(s.id),i=re(),u=oe(),f=n?.recent_runs?.some(j=>["running","pending","claimed"].includes(j.status));o.useEffect(()=>{if(!f)return;const j=setInterval(()=>m(),5e3);return()=>clearInterval(j)},[f,m]);const l=o.useMemo(()=>be(t,s.feed_key),[t,s.feed_key]),d=M(s.id,w(l,s.config??{}),l),{values:x,setValues:c,dirty:p}=d,v=o.useCallback(async()=>{d.canSubmit&&(await i.mutateAsync({feed_id:s.id,config:F(x)}),d.accept(x,w(l,F(x))))},[i,s.id,x,l,d.canSubmit,d.accept]),y=o.useCallback(async()=>{const j=s.status==="active"?"paused":"active";await i.mutateAsync({feed_id:s.id,status:j})},[i,s.id,s.status]),_=o.useCallback(async()=>{await u.mutateAsync(s.id)},[u,s.id]),h=s.status==="active",b=s.operations.includes("sync"),S=s.auth_profile_status&&s.auth_profile_status!=="active",g=i.isPending||u.isPending;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(N,{variant:"outline",size:"sm",disabled:g,onClick:()=>void y(),children:[h?e.jsx(de,{className:"h-3.5 w-3.5 mr-1.5"}):e.jsx(ue,{className:"h-3.5 w-3.5 mr-1.5"}),h?"Pause":"Resume"]}),b?e.jsxs(N,{variant:"outline",size:"sm",disabled:g||!h,onClick:()=>void _(),children:[u.isPending?e.jsx(E,{size:"md",className:"mr-1.5"}):e.jsx(me,{className:"h-3.5 w-3.5 mr-1.5"}),"Sync now"]}):null,e.jsx(fe,{ownerSlug:a,scope:{kind:"feed",id:s.id},variant:"ghost",label:"View in memory"})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-950/20 px-3 py-2 text-sm",children:[e.jsx(xe,{className:"h-4 w-4 text-amber-500 shrink-0"}),e.jsxs("span",{className:"text-amber-700 dark:text-amber-400",children:["Authentication issue: ",s.auth_profile_status]}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",className:"ml-auto h-7 text-xs",children:e.jsx(R,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:a,connectorKey:s.connector_key,connectionId:String(s.connection_id)},search:{settings:!0},children:"Fix auth"})})]}),d.revision?e.jsx(V,{title:"Settings",children:e.jsxs("div",{className:"max-w-xl space-y-4",children:[e.jsx(O,{schema:d.revision,values:x,onValuesChange:c}),e.jsx(P,{visible:d.hasConflict,onReload:d.reset}),p&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(N,{size:"sm",disabled:g||!d.canSubmit,onClick:()=>void v(),children:[i.isPending?e.jsx(E,{size:"md",className:"mr-1.5"}):null,"Save"]})})]})}):null,b?e.jsx(V,{title:"Recent syncs",children:n?.recent_runs&&n.recent_runs.length>0?e.jsx(je,{runs:n.recent_runs,ownerSlug:a}):e.jsx("p",{className:"rounded-lg border bg-muted/20 px-3 py-6 text-center text-xs text-muted-foreground",children:"No syncs yet."})}):null]})}export{ke as A,we as C,Ee as F,Te as a,De as b,Ce as c,Fe as f};
@@ -1 +0,0 @@
1
- import{ad as I,p as D,r,j as e,B as M,ac as T,ae as B}from"./index-B2AmRqYh.js";import{u as $,b as F,a as H,s as G,g as J,A as Q,W as K}from"./oauth-workspace-access-DearynqZ.js";import{C as V,a as X,b as Y,d as Z,c as ee}from"./card-CMmh2mzo.js";const se=["client_id","redirect_uri","scope","code_challenge","code_challenge_method"];function ce(){const s=I.useSearch(),f=s.workspace_grants==="1",{session:y,isReady:N}=D(),j=!N,{orgList:L,workspaceAccess:P,setWorkspaceAccess:q,selectedOrgIds:w,toggleSelectedOrgId:E,orgsLoading:O,orgsError:b,retryOrgs:W,workspaceSelectionReady:_}=$({allowMultiple:f}),[n,A]=r.useState(null),[k,a]=r.useState(null);F(!!y,j);const h=r.useMemo(()=>se.filter(t=>!s[t]||s[t]?.length===0),[s]),o=h.length===0,z=s.client_name?.trim()||null,i=r.useMemo(()=>Array.from(new Set((s.scope||"").split(" ").map(t=>t.trim()).filter(Boolean))),[s.scope]),g=H(i),[l,v]=r.useState(g);r.useEffect(()=>{v(g)},[g]);const d=r.useMemo(()=>G(i,l),[l,i]),S=r.useMemo(()=>d.some(t=>t.startsWith("mcp:")),[d]),x=l,u=r.useMemo(()=>J(s.resource),[s.resource]),m=S&&!u,U=()=>{const t=new URL("/auth/login",window.location.origin);t.searchParams.set("callbackUrl",window.location.href),window.location.href=t.toString()},C=async t=>{if(!o){a(`Missing required query params: ${h.join(", ")}`);return}if(t&&m&&!_){a(b?"Workspaces could not be loaded. Retry before approving.":"Choose at least one workspace before approving.");return}A(t?"approve":"deny"),a(null);try{const c=await fetch(`${T}/oauth/authorize/consent`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({client_id:s.client_id,redirect_uri:s.redirect_uri,scope:t?d.join(" "):s.scope,state:s.state??"",code_challenge:s.code_challenge,code_challenge_method:s.code_challenge_method,client_name:s.client_name,resource:s.resource,authorization_intent:s.authorization_intent,approved:t,...t&&m?{workspace_access:P,organization_ids:w}:{}})}),p=await c.json().catch(()=>null);if(c.status===401){U();return}if(!c.ok)throw new Error(p?.error_description||p?.message||p?.error||`Failed to ${t?"approve":"deny"} OAuth consent`);const R=B(p?.redirect_url);if(!R)throw new Error("Consent response did not include a valid redirect URL");window.location.href=R}catch(c){A(null),a(c instanceof Error?c.message:"Unexpected error while submitting consent")}};return j||!y?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..."})}):e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(V,{className:"w-full max-w-lg",children:[e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("h1",{children:"Authorize application"})}),e.jsx(Z,{children:"Review the application, access level, and workspaces."})]}),e.jsxs(ee,{className:"space-y-5","aria-busy":n!==null,children:[e.jsx(Q,{idPrefix:"oauth-consent",clientName:z,requestedScopes:i,accessLevel:l,onAccessLevelChange:v,disabled:n!==null}),m&&e.jsx(K,{idPrefix:"oauth-consent",allowMultiple:f,orgList:L,selectedOrgIds:w,onWorkspaceAccessChange:q,onSelectedOrgChange:E,orgsLoading:O,orgsError:b,onRetry:W,disabled:n!==null||!o}),(u||s.resource)&&e.jsx("section",{className:"rounded-md border bg-muted/20 p-3 text-sm text-muted-foreground space-y-1",children:s.resource&&e.jsx("p",{children:e.jsx("span",{className:"font-medium text-foreground",children:s.resource})})}),S&&u&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-2",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["Workspace access: only ",u]}),e.jsxs("ul",{className:"space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"If this workspace is public, the app can read public data immediately after approval."}),x==="write"&&e.jsx("li",{children:"If you are not already a member, this connection will stay read-only. Ask an organization admin to grant write access, then reconnect the MCP client."}),x==="admin"&&e.jsx("li",{children:"If you are not already an admin or owner, elevated actions will stay blocked. Ask an organization owner to grant the required role, then reconnect the MCP client."}),x==="read"&&e.jsx("li",{children:"Public read access does not require membership."})]})]}),k&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:k}),!o&&e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Missing required query params: ",h.join(", ")]}),e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx(M,{type:"button",variant:"outline",onClick:()=>C(!1),disabled:n!==null||!o,children:n==="deny"?"Denying...":"Deny"}),e.jsx(M,{type:"button",onClick:()=>C(!0),disabled:n!==null||!o||d.length===0||m&&!_,children:n==="approve"?"Approving...":"Approve"})]})]})]})})}export{ce as component};
@@ -1 +0,0 @@
1
- import{ig as r,j as e}from"./index-B2AmRqYh.js";import{a as i}from"./agent-skills-route-B4VUnVi0.js";import"./agent-subpage-shell-Dz8I-GUt.js";import"./agent-skill-context-BAr2Dw3F.js";import"./core.esm-QA7BQgiK.js";import"./skill-editor-D_W3QlRz.js";import"./agent-loading-shells-OagauQzV.js";import"./agent-card-controls-B3RhzsPz.js";import"./switch-BQ40_DMb.js";function c(){const{owner:t,agentId:o}=r.useParams();return e.jsx(i,{owner:t,agentId:o})}export{c as component};
@@ -1 +0,0 @@
1
- import{ii as o,j as e}from"./index-B2AmRqYh.js";import{a}from"./agent-guardrails-route-Dp02G1AQ.js";import"./model-selector-CapL1ARf.js";import"./agent-subpage-shell-Dz8I-GUt.js";import"./agent-loading-shells-OagauQzV.js";import"./agent-card-controls-B3RhzsPz.js";import"./switch-BQ40_DMb.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{j as n,aS as t,Y as c,a as r,ba as i,gA as l,aQ as m,gB as x,L as C,gC as d,gD as u,fP as j}from"./index-B2AmRqYh.js";function p({owner:o,initialConnectorKey:e}){return n.jsx(t,{owner:o,children:a=>n.jsx(h,{ownerSlug:a.ownerSlug,organizationId:a.organizationId,initialConnectorKey:e})})}function h({ownerSlug:o,organizationId:e,initialConnectorKey:a}){const{data:s=[]}=r(e??"");return n.jsxs(i,{className:"flex flex-1 flex-col gap-6",children:[n.jsx(l,{breadcrumb:n.jsx(x,{crumbs:[n.jsx(C,{to:"/$owner/connectors",params:{owner:o},search:{},className:d,children:"Connectors"},"connectors")]}),icon:n.jsx(m.connectors.icon,{className:"h-6 w-6"}),title:"Add a connection",caption:"Pick a connector from the catalog or drop in an MCP URL — Lobu handles auth and brings the data into memory."}),e?n.jsx(u,{ownerSlug:o,organizationId:e,connections:s,initialConnectorKey:a}):n.jsx("div",{className:"max-w-3xl",children:n.jsx(j,{rows:4})})]})}const f=()=>n.jsx(c,{});export{p as ConnectionsCreateRouteContent,f as component};
@@ -1,2 +0,0 @@
1
- import{r as i,j as e,bR as ie,bS as ce,bT as re,bU as le,bV as L,a7 as oe,B as Q,X as Yt,a as xs,d7 as ps,cE as Zt,dJ as gs,dK as fs,S as Ct,a6 as b,af as D,aP as Ie,dL as Et,c_ as vs,d0 as ys,dM as js,cs as es,d1 as _s,bv as Ot,dN as Ns,cB as st,cC as Ke,aL as tt,dO as yt,bu as ts,P as Ge,cx as bs,aj as ks,ac as Ss,d9 as ws,dP as Cs,dQ as Es,dR as Os,dS as As,dT as Fs,ab as Ps,L as Ts,Z as ss,dU as Ls,bt as Ms,b9 as Rs,dV as At,dW as Ds,dX as $s,cl as Is,dY as qs,b_ as gt,n as Ks,dZ as Ws,d_ as Bs,d$ as Us,e0 as Vs,e1 as zs,e2 as Qs,e3 as Js,e4 as Gs,e5 as Hs,bw as Xs,c6 as Ys}from"./index-B2AmRqYh.js";import{c as Zs}from"./cronstrue-2GHCtD7h.js";import{C as en,f as tn}from"./entity-options-CrbS6K-i.js";import{S as sn}from"./switch-BQ40_DMb.js";import{a as nn,A as an}from"./device-automation-BIjs7DZJ.js";import{M as on}from"./model-selector-CapL1ARf.js";import{b as cn}from"./skill-editor-D_W3QlRz.js";import{C as ft}from"./code-editor-CYsR2VBP.js";import{u as rn,M as Ft,a as Pt,s as ln,o as dn,b as un,c as mn,d as hn,e as xn,v as pn,r as gn}from"./use-mention-search-B4DfZFm5.js";const Ze=[{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 fn(n){const t=n.trim();if(!t)return null;try{return Zs.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function vn({value:n,onChange:t,placeholder:s="No schedule",className:c}){const d=n??"",u=Ze.some(f=>f.value===d),[r,o]=i.useState(!u&&d!==""),x=f=>{f==="custom"?o(!0):(o(!1),t(f))},m=d?fn(d):null,S=d?e.jsx("p",{className:m?"text-xs text-muted-foreground":"text-xs text-destructive",children:m??"Not a valid cron expression."}):null;return!d&&!r?e.jsxs(ie,{onValueChange:x,children:[e.jsx(ce,{className:c??"w-full",children:e.jsx(re,{placeholder:s})}),e.jsx(le,{children:Ze.map(f=>e.jsxs(L,{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:[r?e.jsx(oe,{placeholder:"0 */6 * * *",value:d,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(ie,{value:d,onValueChange:x,children:[e.jsx(ce,{className:c??"w-full flex-1",children:e.jsx(re,{children:Ze.find(f=>f.value===d)?.label??d})}),e.jsx(le,{children:Ze.map(f=>e.jsxs(L,{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(Q,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),t("")},children:e.jsx(Yt,{className:"h-4 w-4"})})]}),S]})}const dt="__all_workspace_event_types__",yn=[],jn={};function Tt(n,t,s){const c=new Map;if(!t)for(const[u,r]of Object.entries(s??{}))c.set(u,{key:u,label:Ot(u),description:r.description});const d=[...n].filter(u=>!t||u.slug===t).sort((u,r)=>u.slug.localeCompare(r.slug));for(const u of d)for(const[r,o]of Object.entries(u.event_kinds??{})){const x=c.get(r);if(x){!x.description&&o.description&&(x.description=o.description),JSON.stringify(x.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(x.metadataSchema=void 0);continue}c.set(r,{key:r,label:Ot(r),description:o.description,metadataSchema:o.metadataSchema})}return[...c.values()].sort((u,r)=>u.label.localeCompare(r.label))}function Lt(n){const t=n[0];if(!t)return;const s=d=>JSON.stringify(Object.keys(d?.properties??{}).sort()),c=s(t);return n.every(d=>s(d)===c)?t:void 0}function Mt(n,t,s){const c=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([d])=>!c.has(d))),...s}}function $e(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Rt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Dt(n,t,s){const c=new Set(Object.keys(t?.properties??{})),d=new Set(s.flatMap(u=>Object.keys(u.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(Ns(n)).filter(([u])=>u==="resource_ref"||u==="resource_type"||!d.has(u)||c.has(u)))}function _n({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(c=>e.jsx("button",{type:"button","aria-pressed":n===c.value,onClick:()=>s(c.value),className:D("rounded px-3 py-1 transition-colors",n===c.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:c.label},c.value))})}function $t({events:n,selectedKeys:t,onToggle:s,ariaLabel:c="Events"}){const d=i.useId(),u=n.filter(o=>t.includes(o.key)).map(o=>o.label),r=u.length===0?"Choose events":u.length===1?u[0]:`${u.length} events selected`;return e.jsx(st,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(Q,{type:"button",variant:"outline",role:"combobox","aria-label":c,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:D(u.length===0&&"text-muted-foreground"),children:r}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,x)=>{const m=t.includes(o.key),S=`${d}-${x}-state`;return e.jsxs(Ke,{value:`${o.label} ${o.key}`,onSelect:()=>s(o.key),"aria-label":o.label,"aria-describedby":S,className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",m?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:S,className:"sr-only",children:m?"Selected":"Not selected"})]},o.key)})})}function Nn({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:c,showSectionHeader:d=!0,fieldIdPrefix:u="automation-trigger-"}){const r=xs(n,{status:"active",limit:500}),o=ps(n),x=Zt({organizationId:n}),m=gs({organizationId:n}),S=r.data??[],f=o.data??[],I=x.data??yn,h=m.data??jn,j=i.useMemo(()=>I.filter(l=>l.organization_id===n),[I,n]),y=t?.kind==="event"&&t?.source==="workspace",w=y||t===void 0,M=c?.length?[...c]:["event","time","manual"],_=M.join("|"),q=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return M.includes(l)?l:M[0]??"event"})(),[N,K]=i.useState(q),[X,te]=i.useState(y?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),k=X==="workspace",P=k?"":X,[p,J]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),se=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[$,V]=i.useState(()=>se.filter(l=>typeof l=="string")),[Y,he]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[xe,be]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),ke=typeof t?.timezone=="string"?t.timezone:void 0,[T,pe]=i.useState(t?.kind==="schedule"||w&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[ne,Z]=i.useState(Qe(T,t?.output==="reply_to_source"?"reply_to_source":"silent")),[G,ae]=i.useState(t?.kind==="schedule"||w&&t?.active_run!=="queue"?"coalesce":$e(T,ne,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[Se,Oe]=i.useState(t?.skip_if_unchanged!==!1),[we,g]=i.useState(!1);i.useEffect(()=>{const l=_.split("|");if(!l.includes(N)){const v=l[0]??"event";K(v),pe(v==="time"||v==="event"&&k?"window":"turn"),ae(v==="time"||v==="event"&&k?"coalesce":"queue"),Z("silent")}},[_,N,k]);const W=S.find(l=>String(l.id)===P),H=r.isLoading||o.isLoading,ge=x.isLoading,C=typeof t?.connector_key=="string"?t.connector_key:void 0,Ae=N==="event"&&!k&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===P&&!W,ve=N==="event"&&!k&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&C!==void 0&&P==="",Fe=f.find(l=>l.key===(W?.connector_key??(ve?C:void 0))),de=Fe?.automation_events??[],B=de.filter(l=>$.includes(l.key)),ye=B[0],Te=j.find(l=>l.slug===p),Pe=[...j.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===p),...p&&!Te?[{slug:p,name:p}]:[]],ue=i.useMemo(()=>Tt(j,p||void 0,h),[j,p,h]),Le=ue.filter(l=>$.includes(l.key)),We=Le[0],fe=Lt(B.map(l=>l.filterSchema)),me=Lt(Le.map(l=>l.metadataSchema)),Be=!!(k&&p&&!Te),Me=Ae||ve,Ce=(N==="event"?k?$.length>0&&!Be:!!($.length>0&&(P&&W||Me)):N==="time"?!!xe.trim():!0)&&(N!=="event"||!fs(Y));i.useEffect(()=>{let l;if(Ce&&N==="event"&&!k){const v=Dt(Y,fe,Fe?.automation_events??[]);W||ve?l={kind:"event",source:"connector",connector_key:W?.connector_key??C,...W?{connection_id:Number(P)}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:T,active_run:$e(T,ne,G),output:Qe(T,ne),skip_if_unchanged:Se}:Ae&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&N==="event"&&k){const v=Dt(Y,me,ue.map(E=>({filterSchema:E.metadataSchema})));l={kind:"event",source:"workspace",...p?{entity_type:p}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:T,active_run:G==="queue"?"queue":"coalesce"}}else Ce&&N==="time"&&(l={kind:"schedule",cron:xe.trim(),...ke?{timezone:ke}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:Se});s({ready:Ce,kind:N,trigger:l})},[G,P,W,xe,Fe,$,T,Y,N,C,ke,t,k,s,ne,Ce,fe,me,Se,p,ue,ve,Ae]);const at=l=>{const v=S.find(O=>String(O.id)===l),E=f.find(O=>O.key===v?.connector_key),ee=$.filter(O=>E?.automation_events?.some(De=>De.key===O)),F=E?.automation_events?.find(O=>O.key===ee[0]),je=v?.connector_key!==(W?.connector_key??C);if(te(l),V(ee),!F)he(Rt);else if(je){const O=F.defaults?.execution??"turn",De=F.defaults?.activeRun??"queue",ze=Qe(O,F.defaults?.output??"silent");he(Rt),pe(O),ae($e(O,ze,De)),Z(ze)}},ot=l=>{if(l==="workspace"){te("workspace"),V(v=>v.filter(E=>ue.some(ee=>ee.key===E))),he({}),pe("window"),ae("coalesce"),Z("silent");return}at(l)},Ue=l=>{const v=$.includes(l)?$.filter(O=>O!==l):de.map(O=>O.key).filter(O=>O===l||$.includes(O));if(V(v),v[0]===$[0])return;const E=de.find(O=>O.key===v[0]),ee=E?.defaults?.execution??"turn",F=E?.defaults?.activeRun??"queue",je=Qe(ee,E?.defaults?.output??"silent");pe(ee),ae($e(ee,je,F)),Z(je)},Xe=l=>{const v=l===dt?"":l,E=j.find(F=>F.slug===v),ee=Tt(j,E?.slug,h);J(v),V(F=>F.filter(je=>ee.some(O=>O.key===je))),he({})},Ve=l=>{V(v=>v.includes(l)?v.filter(E=>E!==l):ue.map(E=>E.key).filter(E=>E===l||v.includes(E)))},Re=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>M.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[d?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(_n,{value:N,options:Re,onChange:l=>{K(l),pe(l==="time"||l==="event"&&k?"window":"turn"),ae(l==="time"||l==="event"&&k?"coalesce":"queue"),Z("silent")}}):null,N==="event"?H||k&&ge?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ct,{className:"h-9 w-full"}),e.jsx(Ct,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Source"}),e.jsx(en,{connections:S,value:X,onValueChange:ot,disabled:Me,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),Ae?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."}):ve?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]}),k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx($t,{events:ue,selectedKeys:$,onToggle:Ve}):e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:p?"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 “",p,"”, 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."})]}),me?e.jsx(Et,{schema:me,values:Y,onValuesChange:l=>he(v=>Mt(v,me,l)),fieldIdPrefix:`${u}workspace-`},`${p||"workspace"}:${$.join(",")}`):null]}):W||ve?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:de.length>1?"Events":"Event"}),de.length?e.jsx($t,{events:de,selectedKeys:$,onToggle:Ue}):e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),ye?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:ye.description}):null]}),typeof Y.resource_ref=="string"||fe?e.jsxs("div",{className:"space-y-3",children:[typeof Y.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Resource"}),e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm"),children:Y.resource_ref})]}):null,fe?e.jsx(Et,{schema:fe,values:Y,onValuesChange:l=>he(v=>Mt(v,fe,l)),fieldIdPrefix:u},$.join(",")):null]}):null]}):X?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):N==="time"?e.jsx(vn,{value:xe,onChange:be}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),N!=="manual"&&!Me?e.jsxs(vs,{open:we,onOpenChange:g,children:[e.jsx(ys,{asChild:!0,children:e.jsxs(Q,{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(js,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",T==="turn"?"Each event":"Window"," ·"," ",N==="time"?"Combine":k?G==="queue"?"Queue":"Combine":G==="queue"?"Queue":G==="coalesce"?"Combine":"Update current run",N==="event"&&!k?` · ${T==="turn"&&ne==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(es,{className:D("h-4 w-4 transition-transform",we&&"rotate-180")})]})}),e.jsxs(_s,{className:"space-y-4 pt-3",children:[N==="event"&&k?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity type filter"}),e.jsxs(ie,{value:p||dt,onValueChange:Xe,children:[e.jsx(ce,{"aria-label":"Entity type filter",children:e.jsx(re,{})}),e.jsxs(le,{children:[e.jsx(L,{value:dt,children:"All event types"}),Pe.map(l=>e.jsx(L,{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,N==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Run"}),e.jsxs(ie,{value:T,onValueChange:l=>{const v=l,E=Qe(v,ne);pe(v),Z(E),ae($e(v,E,G))},children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"turn",children:"Start a run for each event"}),e.jsx(L,{value:"window",children:"Batch events into a window"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"When busy"}),e.jsxs(ie,{value:G,onValueChange:l=>ae(l),children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"queue",children:"Queue"}),e.jsx(L,{value:"coalesce",children:"Combine waiting events"}),!k&&T==="turn"&&ne==="reply_to_source"&&ye?.capabilities?.steering?e.jsx(L,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,T==="window"&&(N==="time"||!k)?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(sn,{"aria-label":"Skip unchanged windows",checked:Se,onCheckedChange:Oe})]}):null,N==="event"&&!k&&T==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Result"}),e.jsxs(ie,{value:ne,onValueChange:l=>{const v=l;Z(v),ae($e(T,v,G))},children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(le,{children:[ye?.capabilities?.replyToSource?e.jsx(L,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(L,{value:"silent",children:"Save in Lobu"})]})]}),ye?.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 bn=16;function qe(){return crypto.randomUUID()}function kn(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 ns(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function Sn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function wn(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 d=s.filter(ns).length;return{ready:!s.some(o=>o.kind==="manual")&&d<=1&&s.length>0&&s.every(o=>o.ready&&o.trigger),triggers:s.filter(o=>o.trigger).map(o=>o.trigger)}}function na({organizationId:n,initialTriggers:t,onChange:s}){const c=i.useId(),[d,u]=i.useState(()=>kn(t)),[r,o]=i.useState({}),x=i.useRef("");i.useEffect(()=>{const h=wn(d,r),j=JSON.stringify(h);j!==x.current&&(x.current=j,s(h))},[d,r,s]);const m=d.find(h=>ns(r[h.key]))?.key??d.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!r[h.key])?.key??null,S=i.useCallback((h,j)=>{o(y=>Sn(y[h],j)?y:{...y,[h]:j})},[]),f=()=>{const h=d[0],j=h?r[h.key]:void 0;if(d.length===1&&(j?.kind==="manual"||h?.initial===null)){const y=qe();o({}),u([{key:y,initial:void 0}]);return}u(y=>[...y,{key:qe(),initial:void 0}])},I=h=>{if(d.length<=1){const j=qe();o({}),u([{key:j,initial:null}]);return}o(j=>{const y={...j};return delete y[h],y}),u(j=>j.filter(y=>y.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${c}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${c}-heading`,className:"text-sm font-medium",children:"When"}),d.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:d.map((h,j)=>{const y=d.length>1,w=y?m&&m!==h.key?["event"]:["event","time"]:["event","time","manual"],M=r[h.key],_=y||(M?M.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:D("space-y-3 rounded-lg border bg-card/40 p-3",y&&"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:y?`Trigger ${j+1}`:"Trigger"}),_?e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":y?`Remove trigger ${j+1}`:"Clear trigger",onClick:()=>I(h.key),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Cn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:w,fieldIdPrefix:`${c}-${h.key}-`,onChange:S})]},h.key)})}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:d.length>=bn,children:[e.jsx(Ge,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Cn({slotKey:n,organizationId:t,initial:s,kinds:c,fieldIdPrefix:d,onChange:u}){const r=i.useCallback(o=>u(n,o),[u,n]);return e.jsx(Nn,{organizationId:t,initialTrigger:s,allowedKinds:c,showSectionHeader:!1,fieldIdPrefix:d,onChange:r})}const It={agents:!0,lobuEmbedded:!1};function En(){const{data:n}=bs({queryKey:["features"],queryFn:async()=>{const t=await ks(`${Ss}/api/features`);return t.ok?t.json():It},staleTime:3e4,refetchInterval:6e4});return n??It}const qt=["slack","imessage"],ut="__none__";function Je(n){return`${n.connection_id}:${n.feed_key}`}function On(n){const t=n.indexOf(":");if(t<=0)return null;const s=Number(n.slice(0,t)),c=n.slice(t+1);return!Number.isSafeInteger(s)||s<=0||!c?null:{connection_id:s,channel_id:c}}function mt(n){return n?`${n.connection_id}:${n.channel_id}`:""}function et(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function An({organizationId:n,agentId:t,value:s,onChange:c,disabled:d=!1,automationName:u,onPendingChange:r}){const{data:o=[],isLoading:x}=ws(n),m=mt(s),[S,f]=i.useState(null),[I,h]=i.useState(!1),j=i.useRef(t),y=i.useMemo(()=>o.filter(p=>p.store==="channel_messages"&&p.target_agent_id===t&&qt.includes(p.connector_key)),[o,t]);i.useEffect(()=>{if(j.current===t||(j.current=t,f(null),h(!1),s==null))return;const p=mt(s);if(p==="")return;o.some(se=>se.store==="channel_messages"&&se.target_agent_id===t&&qt.includes(se.connector_key)&&Je(se)===p)||c(null)},[t,o,s,c]);const w=S??m,M=w===""?ut:w,_=y.find(p=>Je(p)===w),q=S!==null&&S!==""&&S!==m;i.useEffect(()=>{r?.(q)},[q,r]);const N=_??(S?void 0:y.find(p=>Je(p)===m)),K=p=>{const J=p===ut?"":p;if(J===""){f(null),h(!1),c(null);return}if(J===m){f(null),h(!1);return}f(J),h(!1)},X=p=>{if(h(p),p&&S){const J=On(S);J&&(f(null),c(J))}else!p&&S&&f(null)},k=(s&&mt(s)!==""?s:void 0)??(_?{connection_id:_.connection_id,channel_id:_.feed_key}:void 0),P=(u??"").trim()||"This automation";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"automation-delivery-target",children:["Digest destination"," ",e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),t?e.jsxs(ie,{value:M,onValueChange:K,disabled:d||x,children:[e.jsx(ce,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(re,{placeholder:x?"Loading bound channels…":y.length===0?"No bound Slack or iMessage channels":"No digest — runs stay silent"})}),e.jsxs(le,{children:[e.jsx(L,{value:ut,children:"No digest — runs stay silent"}),y.map(p=>e.jsxs(L,{value:Je(p),children:[et(p)," · ",p.connector_key]},Je(p)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),t&&!x&&y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No Slack or iMessage channels are bound to this agent yet. Link a private channel first, then select it here."}):null,q&&_?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:p=>X(p.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${et(_)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:et(_)}),". Destination changes are audited."]})]}):null,N||k?e.jsxs("div",{className:D(Ie,"space-y-1.5 px-3 py-2"),children:[e.jsxs("p",{className:"text-xs font-medium",children:["Digest preview →"," ",e.jsx("span",{className:"font-mono font-normal",children:N?`${N.connector_key} ${et(N)} · connection ${N.connection_id}`:`${k?.channel_id} · connection ${k?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[P," applied 2 new + 1 updated"]}),e.jsx("p",{className:"whitespace-pre-line font-mono text-xs text-muted-foreground",children:`+ Example task (#12)
2
- ~ Follow-up item (#34)`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sends only after a successful run with material changes. Runs with zero changes send nothing. Retries reuse the same notification and delivery receipts dedupe channel posts, but provider acceptance with a lost receipt can still duplicate."})]}):null]})}const Kt=4096;function Fn({open:n,onOpenChange:t,initial:s,onSubmit:c}){const[d,u]=i.useState(""),[r,o]=i.useState(""),[x,m]=i.useState(null);i.useEffect(()=>{n&&(u(s?.name??""),o(s?.query??""),m(null))},[n,s]);const S=()=>{const I=d.trim(),h=r.trim();if(!I){m("Give the SQL source a name.");return}if(!h){m("Enter a query.");return}if(h.length>Kt){m(`Query is too long (${h.length} chars, max ${Kt}).`);return}c({name:I,query:h}),t(!1)},f=!!s;return e.jsx(Cs,{open:n,onOpenChange:t,children:e.jsxs(Es,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(As,{children:f?"Edit SQL source":"SQL source"}),e.jsx(Fs,{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(b,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(oe,{id:"sql-source-name",value:d,onChange:I=>u(I.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(b,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(ft,{value:r,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Q,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(Q,{onClick:S,children:f?"Save":"Add source"})]})]})})}const Pn=["skill","feed","connection","connector","metric","entity_type"];function Tn({value:n,onChange:t,library:s,pinned:c,required:d,error:u,owner:r,agentId:o,sources:x,onAddSources:m}){const S=rn(Pn,Ft,{skills:s,skillAgentId:o||null}),f=i.useRef(null),[I,h]=i.useState(null),j=i.useMemo(()=>{if(!x)return[];const _=new Set(x.map(q=>q.query.trim()));return Pt(n).filter(q=>!_.has(q.query.trim()))},[n,x]),y=ln(n),w=dn(c.filter(_=>y.includes(_.name)),s),M=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(b,{htmlFor:"automation-prompt",children:["Instructions"," ",d?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),y.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[y.length,"/",Ft," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(un,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:S,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(_,q)=>h({initial:_,pos:q}),placeholder:M?"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(Fn,{open:I!==null,onOpenChange:_=>{_||h(null)},initial:I?.initial,onSubmit:_=>{f.current?.insertSql(_,I?.pos),h(null)}}),j.length>0&&m?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:[j.length===1?`"${j[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${j.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>m(Pt(n,x)),children:j.length===1?"Add as a source":"Add as sources"})]}):null,y.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:y.map(_=>{const q=w.includes(_),N=!s.some(K=>K.name===_);return e.jsxs(Ps,{variant:N?"destructive":"secondary",className:"font-normal",children:[_,N?" · unavailable":q?" · newer text":null]},_)})}):null,w.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[w.length===1?`"${w[0]}" has been edited since this Automation pinned it.`:`${w.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,u?e.jsx("p",{className:"text-xs text-destructive",children:u}):null,!M&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Ts,{to:"/$owner/agents/$agentId/skills",params:{owner:r,agentId:o},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):u?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:M?"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 Ln=["connection","connector","feed","metric","entity_type"];function Mn({sources:n,onChange:t,disabled:s}){const{currentOwner:c,resolvedOrganizationId:d}=ss(),[u,r]=i.useState(""),{refs:o}=mn({owner:c,organizationId:d,kinds:Ln,query:u,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(x=>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:x.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:x.query})]}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${x.name}`,disabled:s,onClick:()=>t(n.filter(m=>m.query!==x.query)),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})})]},x.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(st,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:r,trigger:()=>e.jsxs(Q,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Ge,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:x=>o.map(m=>e.jsxs(Ke,{value:`${m.label} ${m.kind}`,onSelect:()=>{t(hn(m,n)),x()},children:[e.jsx("span",{className:"truncate text-sm",children:m.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:m.kind})]},`${m.kind}:${m.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 Rn({organizationId:n,value:t,onChange:s,className:c}){const{data:d=[]}=Ls(n),u=tn(d),r=u.find(o=>o.id===t);return e.jsx(st,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(Q,{variant:"outline",role:"combobox","aria-expanded":o,className:D("w-full justify-between",c),children:[r?`${r.name} (${r.entityType})`:"All workspace",e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{value:"all workspace",onSelect:()=>{s(void 0),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),u.map(x=>e.jsxs(Ke,{value:`${x.name} ${x.entityType}`,onSelect:()=>{s(x.id),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",t===x.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[x.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",x.entityType,")"]})]})]},x.id))]})})}function vt(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 Dn=nn.map(n=>({value:n,label:an[n]})),Wt=[{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 Bt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(c=>c.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const $n=["text","number","date","boolean","json"],In=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],ht=[{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 Ut=0;function qn(){return Ut+=1,`field-${Ut}`}function as(n={}){return{id:qn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function He(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Kn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Vt(n){return n?Kn(n.keying_config)?"fields":"json":"fields"}function zt(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Qt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function Jt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const c of s){if(typeof c!="string")continue;const d=He(c);d&&t.set(d,as({name:d,role:"key"}))}return Array.from(t.values())}function _e(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Gt(n,t,s){const c=n?.execution_config?.[t];return typeof c=="string"&&s.includes(c)?c:""}function xt(n,t){const s=n.trim();if(!s)return{};const c=Number(s);return Number.isFinite(c)?{value:c}:{error:`${t} must be a number.`}}function Ht({entityType:n,entityPath:t,fields:s}){const d=s.map(o=>({...o,name:He(o.name)})).filter(o=>o.name).filter(o=>o.role==="key").map(o=>o.name),u=He(n),r=t.trim()||"$";return d.length>0&&!u?{error:"Key fields need an output entity type."}:(d.length>0,{keyingConfig:d.length>0?{entity_type:u,entity_path:r,key_fields:d,key_output_field:`${u}_key`}:void 0})}function Wn(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 Xt(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||vt(n?.tags).length)}function Bn({organizationId:n,entityId:t,prefill:s,onSubmit:c,isSubmitting:d,error:u,isEditing:r,onCancel:o,triggerFields:x,submitLabel:m="Create Automation",submitDisabled:S=!1,triggers:f}){const{lobuEmbedded:I}=En(),{currentOwner:h}=ss(),{data:j=[]}=Ms(),{data:y=[]}=Rs(),[w,M]=i.useState(s?.managed_agent_id??""),_=!!s?.managed_agent_id&&!r,[q,N]=i.useState(s?.delivery_target??null),[K,X]=i.useState(!1),[te,k]=i.useState(s?.device_worker_id??""),[P,p]=i.useState(s?.device_worker_id?"device":"agent"),[J,se]=i.useState(s?.agent_kind??""),{data:$=[]}=Zt({organizationId:n}),[V,Y]=i.useState(s?.name??""),[he,xe]=i.useState(s?.slug??""),[be,ke]=i.useState(!!s?.slug),[T,pe]=i.useState(s?.description??""),[ne,Z]=i.useState(s?.prompt??""),[G,ae]=i.useState(!1),Se=s?.skills??[],[Oe,we]=i.useState(s?.sources??[]),[g,W]=i.useState(s?.entity_id??t),[H,ge]=i.useState(s?.reaction_script??""),[C,Ae]=i.useState(()=>Bt(s)),[ve,Fe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[de,B]=i.useState(null),[ye,Te]=i.useState(()=>Vt(s)),[Pe,ue]=i.useState(()=>zt(s)),[Le,We]=i.useState(()=>Qt(s)),[fe,me]=i.useState(()=>Jt(s)),[Be,Me]=i.useState(s?.reactions_guidance??""),[nt,Ce]=i.useState(()=>_e(s,"timeout_seconds")),[at,ot]=i.useState(()=>_e(s,"max_budget_usd")),[Ue,Xe]=i.useState(()=>_e(s,"model")),[Ve,it]=i.useState(()=>Gt(s,"permission_mode",ht.map(a=>a.value))),[Re,l]=i.useState(()=>_e(s,"effort")),[v,E]=i.useState(()=>_e(s,"finalize_nudges")),[ee,F]=i.useState(null),[je,O]=i.useState(vt(s?.tags).join(", ")),[De,ze]=i.useState(""),[ct,jt]=i.useState(!!(r||Xt(s)));i.useEffect(()=>{s&&(Y(s.name??""),xe(s.slug??""),ke(!!s.slug),pe(s.description??""),Z(s.prompt??""),ae(!1),we(s.sources??[]),W(s.entity_id??t),k(s.device_worker_id??""),p(s.device_worker_id?"device":"agent"),se(s.agent_kind??""),ge(s.reaction_script??""),Ae(Bt(s)),Fe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),B(null),Te(Vt(s)),ue(zt(s)),We(Qt(s)),me(Jt(s)),Me(s.reactions_guidance??""),Ce(_e(s,"timeout_seconds")),ot(_e(s,"max_budget_usd")),Xe(_e(s,"model")),it(Gt(s,"permission_mode",ht.map(a=>a.value))),l(_e(s,"effort")),E(_e(s,"finalize_nudges")),F(null),O(vt(s.tags).join(", ")),ze(""),M(s.managed_agent_id??""),N(s.delivery_target??null),jt(!!(r||Xt(s))))},[s,t,r]);const os=be?he:At(V),{data:is}=Ds(w||null),{data:cs}=$s(w||null,{enabled:!!w}),rt=cn(is??null,cs?.catalog??[]),rs=xn(f),lt=H.trim().length>0,Ye=!r&&C==="code"?"":ne,ls=!r&&C==="agent"?void 0:H.trim()||void 0,_t=(r||C==="code")&&lt,Nt=pn(Ye,rt,f,_t),ds=G||Ye.trim()!==""?Nt:null,bt=gn(Ye,rt),kt=!r&&C!=="agent",St=!!V.trim()&&!Nt&&(!kt||lt)&&!K,us=rs&&!_t&&bt.length===0,ms=()=>{if(!St)return;let a;if(ye==="fields"){const Ne=Ht({entityType:Pe,entityPath:Le,fields:fe});if(Ne.error){B(Ne.error);return}a=Ne.keyingConfig,B(null)}else{if(ve.trim())try{const Ne=JSON.parse(ve);if(typeof Ne!="object"||Array.isArray(Ne)){B("Keying config must be a JSON object.");return}a=Ne}catch{B("Invalid JSON. Please check the syntax.");return}B(null)}const A=xt(nt,"Timeout");if(A.error){F(A.error);return}if(A.value!==void 0&&(!Number.isInteger(A.value)||A.value<1)){F("Timeout must be a whole number greater than 0.");return}const U=xt(at,"Budget");if(U.error){F(U.error);return}if(U.value!==void 0&&U.value<0){F("Budget cannot be negative.");return}const R=xt(v,"Finalize nudges");if(R.error){F(R.error);return}if(R.value!==void 0&&(!Number.isInteger(R.value)||R.value<0||R.value>5)){F("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...A.value!==void 0?{timeout_seconds:A.value}:{},...U.value!==void 0?{max_budget_usd:U.value}:{},...Ue.trim()?{model:Ue.trim()}:{},...Ve?{permission_mode:Ve}:{},...Re.trim()?{effort:Re.trim()}:{},...R.value!==void 0?{finalize_nudges:R.value}:{}},z=Object.keys(Ee).length>0||r?Ee:void 0;F(null);const hs=je.trim()?je.split(",").map(Ne=>Ne.trim()).filter(Boolean):void 0;c({slug:os,name:V.trim(),description:T.trim()||void 0,prompt:Ye,skills:bt,entity_id:g,sources:Oe,reaction_script:ls,keying_config:a,reactions_guidance:Be.trim()||void 0,execution_config:z,tags:hs,change_notes:De.trim()||void 0,managed_agent_id:P==="agent"&&w.trim()||null,device_worker_id:P==="device"&&te.trim()||null,agent_kind:P==="device"&&J.trim()||null,delivery_target:q})},wt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",kt?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(ft,{value:H,onChange:ge,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),r?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(b,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!r&&e.jsx("button",{type:"button",onClick:()=>ke(!be),className:"text-xs text-muted-foreground hover:text-foreground",children:be?"Use automatic slug":"Customize slug"})]}),e.jsx(oe,{id:"scratch-name",value:V,onChange:a=>Y(a.target.value),placeholder:"e.g., Escalation signals"}),!r&&be?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(oe,{id:"scratch-slug",value:he,onChange:a=>xe(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:At(V)||"custom-slug"})]}):null]})}),r?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:Wt.map(a=>e.jsx("button",{type:"button","aria-pressed":C===a.value,onClick:()=>Ae(a.value),className:D("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",C===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:Wt.find(a=>a.value===C)?.hint})]}),r||C!=="code"?e.jsx(Tn,{value:ne,onChange:a=>{ae(!0),Z(a)},library:rt,pinned:Se,required:us,error:ds,owner:h??"",agentId:w,sources:r?Oe:void 0,onAddSources:r?we:void 0}):null,!r&&C!=="agent"?wt:null,r?e.jsx(Mn,{sources:Oe,onChange:we,disabled:d}):null,e.jsx("div",{className:"space-y-4",children:x}),e.jsx(An,{organizationId:n,agentId:P==="agent"?w.trim():"",value:q,onChange:N,disabled:d,automationName:V,onPendingChange:X}),K?e.jsx("p",{className:"text-xs text-destructive",children:"Confirm the digest destination above before saving — an unconfirmed destination is not sent."}):null,e.jsxs(Q,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":ct,"aria-controls":"automation-advanced-settings",onClick:()=>jt(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(es,{className:D("h-4 w-4 transition-transform",ct&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:D("space-y-4",!ct&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-description",children:"Description"}),e.jsx(oe,{id:"scratch-description",value:T,onChange:a=>pe(a.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity scope"}),e.jsx(Rn,{organizationId:n,value:g,onChange:W}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),r?wt: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(b,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys."})]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(ye==="fields"){const a=Ht({entityType:Pe,entityPath:Le,fields:fe});if(a.error){B(a.error);return}Fe(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Te("json")}else Te("fields");B(null)},children:ye==="fields"?"Edit JSON":"Use fields"})]}),ye==="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(b,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(st,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(Q,{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:D("truncate",!Pe&&"text-muted-foreground"),children:Pe||"Select entity type"}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,A)=>{const U=He(A),R=$.filter(z=>!z.backing_sql),Ee=R.some(z=>z.slug===U);return e.jsxs(e.Fragment,{children:[R.map(z=>e.jsxs(Ke,{value:`${z.name??z.slug} ${z.slug}`,onSelect:()=>{ue(z.slug),B(null),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",Pe===z.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:z.slug}),z.name&&z.name!==z.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:z.name})]})]},z.slug)),U&&!Ee&&e.jsxs(Ke,{value:A,onSelect:()=>{ue(U),B(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:U})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(oe,{id:"scratch-output-path",value:Le,onChange:a=>{We(a.target.value),B(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(b,{children:"Fields"}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{me(a=>[...a,as()]),B(null)},children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),fe.length===0?e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:fe.map(a=>e.jsxs("div",{className:D(Ie,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(oe,{value:a.name,onChange:A=>{const U=He(A.target.value);me(R=>R.map(Ee=>Ee.id===a.id?{...Ee,name:U}:Ee)),B(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(ie,{value:a.type,onValueChange:A=>{me(U=>U.map(R=>R.id===a.id?{...R,type:A}:R))},children:[e.jsx(ce,{"aria-label":"Output field type",children:e.jsx(re,{})}),e.jsx(le,{children:$n.map(A=>e.jsx(L,{value:A,children:A},A))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:In.map(A=>e.jsx("button",{type:"button",onClick:()=>{me(U=>U.map(R=>R.id===a.id?{...R,role:A.value}:R)),B(null)},className:D("rounded-sm px-2 py-1 text-xs transition-colors",a.role===A.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:A.label},A.value))}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",onClick:()=>{me(A=>A.filter(U=>U.id!==a.id)),B(null)},"aria-label":"Remove output field",children:e.jsx(ts,{className:"h-4 w-4"})})]},a.id))})]}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(ft,{value:ve,onChange:a=>{Fe(a),B(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(qs,{id:"scratch-reactions-guidance",value:Be,onChange:a=>Me(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:[Wn("Run settings","Choose where the automation runs and the budget it can use."),!_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(ie,{value:P,onValueChange:a=>p(a),children:[e.jsx(ce,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(re,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"agent",children:"Managed agent"}),e.jsx(L,{value:"device",children:"On a device"}),e.jsx(L,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:P==="agent"?"Automated runs dispatch to a managed Lobu agent.":P==="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."})]}),!_&&P==="agent"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-agent-id",children:"Agent"}),I?e.jsxs(ie,{value:w||"__unselected__",onValueChange:a=>{M(a==="__unselected__"?"":a)},children:[e.jsx(ce,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(re,{placeholder:"Select a Lobu agent"})}),e.jsx(le,{children:j.map(a=>e.jsxs(L,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(oe,{id:"scratch-agent-id",value:w,onChange:a=>{M(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"})]}),!_&&P==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(ie,{value:te||"__unselected__",onValueChange:a=>k(a==="__unselected__"?"":a),children:[e.jsx(ce,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(re,{placeholder:"Select a device worker"})}),e.jsx(le,{children:y.map(a=>e.jsx(L,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!_&&P==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(ie,{value:J||"__default__",onValueChange:a=>se(a==="__default__"?"":a),children:[e.jsx(ce,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(re,{placeholder:"Device default"})}),e.jsxs(le,{children:[e.jsx(L,{value:"__default__",children:"Device default"}),Dn.map(a=>e.jsx(L,{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(b,{children:"Model"}),e.jsx(on,{value:Ue,onChange:a=>{Xe(a),F(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(oe,{id:"scratch-timeout",type:"number",min:1,max:86400,value:nt,onChange:a=>{Ce(a.target.value),F(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(b,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(ie,{value:Ve||"__default__",onValueChange:a=>{it(a==="__default__"?"":a),F(null)},children:[e.jsx(ce,{id:"scratch-permission-mode",children:e.jsx(re,{placeholder:"Default"})}),e.jsxs(le,{children:[e.jsx(L,{value:"__default__",children:"Default"}),ht.map(a=>e.jsx(L,{value:a.value,children:a.label},a.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(oe,{id:"scratch-effort",value:Re,onChange:a=>{l(a.target.value),F(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(b,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(oe,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:v,onChange:a=>{E(a.target.value),F(null)},placeholder:"Default"})]})]}),ee&&e.jsx("p",{className:"text-xs text-destructive",children:ee})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(oe,{id:"scratch-tags",value:je,onChange:a=>O(a.target.value),placeholder:"ops, support, risk"})]}),r&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(oe,{id:"scratch-change-notes",value:De,onChange:a=>ze(a.target.value),placeholder:"What changed in this version?"})]})]})]}),u&&!de&&!ee&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u}),e.jsx(gt,{onCancel:o,children:e.jsx(Q,{onClick:ms,disabled:!St||d||S,children:d?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{size:"lg",className:"mr-2"}),r?"Saving...":"Creating..."]}):r?"Save Automation":m})})]})}function Un(n,t){const s=n??null,c=t??null;return s===null||c===null?s===c:s.connection_id===c.connection_id&&s.channel_id===c.channel_id}function Vn(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,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 aa({startFromScratch:n=!1,onClose:t,hideCancel:s=!1,hideHeader:c=!1,organizationId:d,entityId:u,entityName:r,prefillAgentId:o,onSuccess:x,editingAutomation:m,catalogPrefill:S,onDraft:f,triggerFields:I,submitLabel:h,submitDisabled:j,createFields:y,onPrefillTriggers:w}){const M=Ws(),_=Bs(),q=Us(),N=Vs(),K=!!m,[X,te]=i.useState(n?"scratch":"template"),[k,P]=i.useState(void 0),[p,J]=i.useState(void 0),{data:se=[],isLoading:$}=zs(),[V,Y]=i.useState(""),he=i.useMemo(()=>o?{managed_agent_id:o}:void 0,[o]),xe=i.useMemo(()=>se.map(g=>({key:g.id,name:g.name,description:g.description??"",badges:g.detail?.tags??[]})),[se]),be=i.useMemo(()=>xe.filter(g=>g.name.toLowerCase().includes(V.toLowerCase())||g.description.toLowerCase().includes(V.toLowerCase())),[xe,V]),ke=g=>{const W=se.find(ge=>ge.id===g.key);if(!W)return;const H=Vn(W);J(o?{...H,managed_agent_id:o}:H),w?.(H.triggers??[]),te("scratch")},T=()=>{M.reset(),_.reset(),te("template"),P(void 0),J(void 0),t()},pe=K?y?.triggers??m.triggers??[]:y?.triggers??p?.triggers??S?.triggers??[],ne=async g=>{try{if(f){await f(g);return}if(K){const W=y?.triggers??m.triggers??[],H=m.reaction_script??"",ge=g.reaction_script??"";ge&&ge!==H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:ge}),await _.mutateAsync({automation_id:m.automation_id,name:g.name,description:g.description,prompt:g.prompt,sources:g.sources,set_as_current:!0,triggers:W,keying_config:g.keying_config,reactions_guidance:g.reactions_guidance,change_notes:g.change_notes}),!ge&&H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:""});const C={};g.model_config!==void 0&&(C.model_config=g.model_config),g.execution_config!==void 0&&(C.execution_config=g.execution_config),g.tags!==void 0&&(C.tags=g.tags),g.delivery_target!==void 0&&!Un(g.delivery_target,m.delivery_target)&&(C.delivery_target=g.delivery_target),g.managed_agent_id!==void 0&&(C.managed_agent_id=g.managed_agent_id||null),g.agent_kind!==void 0&&(C.agent_kind=g.agent_kind||null),g.device_worker_id!==void 0&&(C.device_worker_id=g.device_worker_id||null),Object.keys(C).length>0&&await N.mutateAsync({automation_id:m.automation_id,...C}),T(),x?.(m.automation_id)}else{const W=y?.triggers??p?.triggers??S?.triggers??[],H=await M.mutateAsync({...g,managed_agent_id:g.managed_agent_id??void 0,device_worker_id:g.device_worker_id??void 0,agent_kind:g.agent_kind??void 0,delivery_target:g.delivery_target??void 0,triggers:W});T(),H.automation_id&&x?.(H.automation_id)}}catch{}},Z=K?_:M;let G="Add an automation";K?G="Edit automation configuration (saves as a new version)":r&&(G=`Add an automation for ${r}`);const ae=m?{entity_id:m.entity_id,name:m.name,slug:m.slug,description:m.description,prompt:m.prompt,sources:m.sources,reaction_script:m.reaction_script,device_worker_id:m.device_worker_id??void 0,agent_kind:m.agent_kind??void 0,keying_config:m.keying_config,reactions_guidance:m.reactions_guidance,model_config:m.model_config,execution_config:m.execution_config,tags:m.tags,managed_agent_id:m.managed_agent_id??void 0,delivery_target:m.delivery_target??void 0}:void 0,Se=K?"Edit Automation":"Create Automation",Oe=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:G})]}),we=e.jsxs("div",{className:"py-6 space-y-6",children:[!K&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(pt,{active:X==="template",onClick:()=>te("template"),icon:e.jsx(Qs,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(pt,{active:X==="scratch",onClick:()=>{te("scratch"),P(void 0),J(void 0)},icon:e.jsx(Ge,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(pt,{active:X==="clone",onClick:()=>te("clone"),icon:e.jsx(Js,{className:"h-4 w-4"}),label:"Clone existing"})]}),!K&&X==="template"?e.jsxs(e.Fragment,{children:[$?e.jsx(Gs,{}):e.jsx(Hs,{items:be,searchQuery:V,onSearchChange:Y,onSelect:ke,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:xe.length===0?"No automation templates available.":void 0}),c&&!s?e.jsx(gt,{onCancel:T}):null]}):!K&&X==="clone"&&!k?e.jsxs(e.Fragment,{children:[e.jsx(zn,{organizationId:d,onSelect:g=>{P(g),w?.(g.triggers??[]),te("scratch")}}),c&&!s?e.jsx(gt,{onCancel:T}):null]}):e.jsx(Bn,{organizationId:d,entityId:u,prefill:ae??k??p??S??he,onSubmit:ne,isSubmitting:Z.isPending,error:Z.error?Z.error.message:null,isEditing:K,onCancel:s?void 0:T,triggerFields:I,submitLabel:h,submitDisabled:j,triggers:pe})]});return e.jsxs("div",{className:"flex flex-col",children:[c?null:Oe,we]})}function pt({active:n,onClick:t,icon:s,label:c}){return e.jsxs("button",{type:"button",onClick:t,className:D("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,c]})}function zn({organizationId:n,onSelect:t}){const{data:s,isLoading:c}=Xs(n),[d,u]=i.useState(""),r=(s||[]).filter(o=>o.name?.toLowerCase().includes(d.toLowerCase()));return c?e.jsx(Ys,{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:d,onChange:o=>u(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:[r.map(o=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,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)),r.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{na as A,aa as C};
@@ -1 +0,0 @@
1
- import{hY as e,j as t,h3 as r}from"./index-B2AmRqYh.js";function a(){const{owner:n,connectorKey:o}=e.useParams();return t.jsx(r,{owner:n,initialConnectorKey:o})}export{a as component};
@@ -1 +0,0 @@
1
- import{cw as r,f3 as l,aj as i,e9 as u,cx as c,ac as d}from"./index-B2AmRqYh.js";function o(e,a=""){return`${d}/api/${e}/deployments${a}`}const y=50;function f(e){const{slug:a}=r();return l({queryKey:["deployments-feed",a,e?.resourceKind,e?.resourceId],queryFn:async({pageParam:t})=>{const n=new URLSearchParams({limit:String(y)});t!==null&&n.set("before_id",String(t)),e&&(n.set("resource_kind",e.resourceKind),n.set("resource_id",e.resourceId));const s=await i(o(a,`?${n.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await u(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:!!a,staleTime:15e3,retry:!1})}function h(e){const{slug:a}=r();return c({queryKey:["deployment-detail",a,e],queryFn:async()=>{const t=await i(o(a,`/${e}`),{credentials:"include"});return t.status===404?null:(await u(t,"Failed to fetch deployment"),await t.json())},enabled:!!a&&!!e,staleTime:15e3,retry:!1})}function g(e){const{slug:a}=r();return c({queryKey:["deployment-change-detail",a,e],queryFn:async()=>{const t=await i(o(a,`/changes/${e}`),{credentials:"include"});return t.status===404?null:(await u(t,"Failed to fetch change"),(await t.json()).change)},enabled:!!a&&!!e,staleTime:15e3,retry:!1})}export{g as a,h as b,f as u};
@@ -1 +0,0 @@
1
- import{j as t,Y as o}from"./index-B2AmRqYh.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +0,0 @@
1
- import{aa as ge,p as xe,r as o,j as e,a7 as ve,B as R,ab as X,ac as oe}from"./index-B2AmRqYh.js";import{s as ye,g as we,u as je,a as be,b as ke,A as Ce,W as Ne}from"./oauth-workspace-access-DearynqZ.js";import{C as Z,a as ee,b as se,d as re,c as te}from"./card-CMmh2mzo.js";function W(r){return r.trim().toUpperCase()}const Se=15e3;async function Ae(r){const c=new AbortController,_=window.setTimeout(()=>c.abort(),Se);try{const i=await fetch(`${oe}/oauth/device/info?user_code=${encodeURIComponent(r)}`,{credentials:"include",signal:c.signal}),b=await i.json().catch(()=>null);return{response:i,data:b}}catch(i){throw c.signal.aborted?new Error("Verification timed out. Check your connection and try again."):i}finally{window.clearTimeout(_)}}function P(r,c){return typeof r?.error_description=="string"&&r.error_description||typeof r?.error=="string"&&r.error||c}function Te(){const r=ge.useSearch(),{session:c,isReady:_}=xe(),i=!_,[b,ne]=o.useState(r.user_code||""),[n,f]=o.useState(null),[O,a]=o.useState(null),[l,ce]=o.useState(null),[I,E]=o.useState(null),[T,L]=o.useState(null),[D,U]=o.useState(!1),g=o.useRef(0),v=r.return_to,M=v?"app":"terminal",ie=!!r.user_code,k=W(b),d=I?.code===k?I:null,h=d!==null,y=d?.scopes??[],ae=o.useMemo(()=>ye(y,T),[T,y]),F=y.some(s=>s.startsWith("mcp:")),C=y.includes("device_worker:run"),le=y.includes("connections:token"),V=C||le,N=we(d?.resource),w=h&&F&&!N,B=d?.multiWorkspaceGrantsEnabled===!0,{orgList:$,workspaceAccess:de,setWorkspaceAccess:ue,selectedOrgIds:G,toggleSelectedOrgId:pe,resetWorkspaceSelection:he,personalOrgId:me,orgsLoading:q,orgsError:S,retryOrgs:Y,workspaceSelectionReady:fe}=je({requirePersonal:w&&C,allowMultiple:B}),x=$.find(s=>s.id===me)??null,A=h&&C&&!N,H=w?fe:!A||!q&&!S&&x!==null,z=o.useCallback(async s=>{const u=++g.current;f("verify"),a(null),U(!1);try{const{response:m,data:t}=await Ae(s);if(u!==g.current)return;if(m.status===401){const j=new URL("/auth/login",window.location.origin);j.searchParams.set("callbackUrl",window.location.href),window.location.href=j.toString();return}if(!m.ok||!t)throw new Error(P(t,"Failed to verify device authorization code"));const p=Array.isArray(t.scopes)?t.scopes:[];E({code:s,clientName:t.client_name??null,scopes:p,resource:typeof t.resource=="string"?t.resource:null,multiWorkspaceGrantsEnabled:t.multi_workspace_grants_enabled===!0}),L(be(p))}catch(m){if(u!==g.current)return;E(null),a(m instanceof Error?m.message:"Unexpected error")}finally{u===g.current&&f(null)}},[]);ke(!!c,i),o.useEffect(()=>{if(!(i||!c||!r.user_code))return z(W(r.user_code)),()=>{g.current+=1}},[c,i,r.user_code,z]);const J=async s=>{const u=k;if(!u){a(`Please enter the code shown in your ${M}.`);return}if(!h){a("Verify the device code before approving or denying access.");return}if(s&&V&&!D){a("Confirm that you initiated this request and that the device code matches.");return}if(s&&!H){a(S?"Workspaces could not be loaded. Retry before approving.":A&&!x?"Your personal workspace is required before this device can be approved.":"Choose at least one workspace before approving.");return}const m=d?.clientName??null;f(s?"approve":"deny"),a(null);try{const t=await fetch(`${oe}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:u,approved:s,...s?{scope:ae.join(" ")}:{},...s&&w?{workspace_access:de,organization_ids:G}:{},...s&&A&&x?{organization_id:x.id}:{}})}),p=await t.json().catch(()=>null);if(t.status===401){const Q=new URL("/auth/login",window.location.origin);Q.searchParams.set("callbackUrl",window.location.href),window.location.href=Q.toString();return}if(!t.ok)throw new Error(P(p,"Failed to process device authorization"));const j=s?"approved":"denied";if(p?.status!==j)throw new Error(P(p,s?"The server did not confirm this approval. The device is still waiting — try again.":"The server did not confirm this denial. Try again."));const K=typeof p.user_code=="string"?W(p.user_code):null;if(K!==null&&K!==u)throw new Error("The server confirmed a different device code. Re-check the code shown on your device.");f(null),ce({outcome:j,code:u,clientName:m})}catch(t){f(null),a(t instanceof Error?t.message:"Unexpected error")}};return o.useEffect(()=>{if(l?.outcome!=="approved"||!v)return;const s=window.setTimeout(()=>{window.location.href=v},600);return()=>window.clearTimeout(s)},[l,v]),i||!c?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..."})}):l?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(Z,{className:"w-full max-w-lg",role:"status","aria-live":"polite",children:[e.jsxs(ee,{children:[e.jsx(se,{children:l.outcome==="approved"?ie?"Access Authorized":"Device Authorized":"Authorization Denied"}),e.jsx(re,{children:l.outcome==="approved"?v?"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(te,{className:"text-sm",children:e.jsxs("dl",{className:"space-y-1",children:[e.jsx("dt",{className:"text-muted-foreground",children:l.outcome==="approved"?"Approved code":"Denied code"}),e.jsx("dd",{className:"font-mono text-base tracking-widest text-foreground",children:l.code}),l.clientName?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Requested by"}),e.jsx("dd",{className:"text-foreground",children:l.clientName})]}):null]})})]})}):e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(Z,{className:"w-full max-w-lg",children:[e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx("h1",{children:h?"Authorize application":"Connect a device"})}),e.jsx(re,{children:h?"Review the application, access level, and workspaces.":`Enter the code shown in your ${M}.`})]}),e.jsxs(te,{className:"space-y-5","aria-busy":n!==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(ve,{id:"user-code",value:b,disabled:n==="approve"||n==="deny",onChange:s=>{g.current+=1,ne(s.target.value.toUpperCase()),E(null),L(null),he(),U(!1),f(null),a(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!r.user_code})]}),d&&e.jsx(Ce,{idPrefix:"oauth-device",clientName:d.clientName,requestedScopes:d.scopes,accessLevel:T,onAccessLevelChange:L,sensitiveScopesAcknowledged:D,onSensitiveScopesAcknowledgedChange:U,disabled:n!==null}),w&&e.jsx(Ne,{idPrefix:"oauth-device",allowMultiple:B,orgList:$,selectedOrgIds:G,onWorkspaceAccessChange:ue,onSelectedOrgChange:pe,orgsLoading:q,orgsError:S,onRetry:Y,disabled:n!==null,personalRequired:C}),h&&F&&N&&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 ",N]}),e.jsx("p",{className:"text-muted-foreground",children:"This request is fixed to the workspace in the MCP resource URL."})]}),A&&!w&&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"}),q?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your personal workspace..."}):S?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(R,{type:"button",variant:"outline",size:"sm",onClick:Y,children:"Retry"})]}):x?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:x.name}),e.jsx(X,{variant:"outline",children:"Personal"}),e.jsx(X,{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."})]}),O&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:O}),e.jsx("div",{className:"flex items-center justify-end gap-3",children:h?e.jsxs(e.Fragment,{children:[e.jsx(R,{type:"button",variant:"outline",onClick:()=>J(!1),disabled:n!==null,children:n==="deny"?"Denying...":"Deny"}),e.jsx(R,{type:"button",onClick:()=>J(!0),disabled:n!==null||!H||V&&!D,children:n==="approve"?"Approving...":"Approve"})]}):e.jsx(R,{type:"button",onClick:()=>z(k),disabled:n!==null||!k,children:n==="verify"?"Verifying...":"Continue"})})]})]})})}export{Te as component};
@@ -1 +0,0 @@
1
- const o=["claude-code","codex","opencode","pi","agy"],i={"claude-code":"Claude Code",codex:"Codex",opencode:"OpenCode",pi:"Pi",agy:"Antigravity (agy)"},l=[{kind:"claude-code",binaryName:"claude",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"claude-config-file",flag:"--mcp-config",extraArgs:["--strict-mcp-config","--allowedTools","mcp__lobu__query_sdk,mcp__lobu__run_sdk"]},headlessArgs:[],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:"--permission-mode",budgetFlag:"--max-budget-usd",timeoutFlag:null,trailingArgs:[]},{kind:"agy",binaryName:"agy",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"none"},headlessArgs:["--dangerously-skip-permissions"],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:{flag:"--print-timeout",suffix:"s"},trailingArgs:[]},{kind:"opencode",binaryName:"opencode",promptDelivery:{kind:"positional",subcommand:["run"]},mcpDelivery:{kind:"opencode-config-env",variable:"OPENCODE_CONFIG_CONTENT"},headlessArgs:["--auto","--print-logs","--log-level","ERROR"],modelFlag:"-m",effortFlag:"--variant",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"codex",binaryName:"codex",promptDelivery:{kind:"positional",subcommand:["exec"]},mcpDelivery:{kind:"none"},headlessArgs:["--skip-git-repo-check","--sandbox","workspace-write","-c","sandbox_workspace_write.network_access=true"],modelFlag:"-m",effortFlag:"-c",effortConfigKey:"model_reasoning_effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"pi",binaryName:"pi",promptDelivery:{kind:"positional",subcommand:[]},mcpDelivery:{kind:"none"},headlessArgs:["-p","--no-session","--tools","read,bash,edit,write"],modelFlag:"--model",effortFlag:"--thinking",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]}];new Map(l.map(e=>[e.kind,e]));export{i as A,o as a};
@@ -1 +0,0 @@
1
- import{j as e,fP as C,i as w,hO as k,r as x,n as b,bk as F,hP as v,B as u,hQ as L,x as A,bu as I,af as P,aP as S,hR as y,aA as R,hS as E,hT as O,eL as _,L as $,P as z,b as T,hU as B,hV as D,o as V,hW as K,eN as q}from"./index-B2AmRqYh.js";import{a as M,R as U}from"./runs-panel-C56GDaJm.js";import{S as H,g as Q,c as N,b as W,d as X}from"./runs-table-BUKDjiBc.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(M,{}),e.jsx(C,{rows:s})]})}function G(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function J({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=k(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),R("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const m=t.config?.folder_id;typeof m=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(m)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(b,{size:"lg"})}):i.length===0?e.jsx(F,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(u,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:P(S,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:G(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${A(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(H,{status:Q(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(I,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,m=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(E,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx(O,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),m==="local.directory"&&e.jsx(J,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(u,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs($,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:m,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(W,{connection:s,ownerSlug:n,connectorKey:m,connectorDef:a})}):e.jsx(X,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(T,{connection:s,ownerSlug:n}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(B,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(U,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=V(),{data:o=[],isLoading:c,isError:r}=K(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
@@ -1 +0,0 @@
1
- import{co as u,eM as l,bo as f}from"./index-B2AmRqYh.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 _(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=_(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{d7 as K,hG as O,j as e,eL as b,S as _,B as j,bo as A,L as w,dj as E,r as N,c_ as F,d0 as G,d1 as H,a as V,_ as W,b9 as Y,hH as q,hI as J,hJ as U,b5 as Q,ba as P,hK as X,hL as Z,hk as ee,bD as se,gA as ne,hM as L,a7 as te,co as R,n as $,bu as ae,F as ie,bn as ce,gB as oe,gC as re,x as le,hN as B,aS as de}from"./index-B2AmRqYh.js";import{c as me,C as xe,R as ue}from"./device-pin-tombstone-Bd6vS2zu.js";import{R as he}from"./runs-panel-C56GDaJm.js";import{S as pe,g as fe}from"./runs-table-BUKDjiBc.js";import{c as ge}from"./connection-label-BobuYiAG.js";import{c as je}from"./device-rows-Bwf8qDte.js";import"./runs-oHveuEUB.js";function ve({device:t,organizationId:s,ownerSlug:r,selectedConnection:p,openSettings:u}){const{data:d=[],isLoading:g,isError:h,refetch:l}=K(s),c=new Map(d.map(i=>[i.key,i])),a=new Map,m=[];for(const i of t.connectors){if(i.organization_slug!==r)continue;const o=c.get(i.connector_key);if(!o||!je(o)){m.push(i);continue}const v=o.required_capability??`connector:${o.key}`,f=a.get(v)??{key:v,name:o.name,connections:[]};f.name=O[v]??o.name,f.connections.push(i),a.set(v,f)}return e.jsxs(e.Fragment,{children:[e.jsxs(b,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),t.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!s||g?e.jsx(_,{className:"h-24 w-full"}):h?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void l(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(i=>e.jsx(Ne,{group:i,deviceId:t.id,organizationId:s,ownerSlug:r,definitionsByKey:c,selectedConnection:p,openSettings:u},i.key))}),A(t)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),s&&m.length>0&&!g&&!h?e.jsxs(b,{title:"Connections",count:String(m.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:m.map(i=>e.jsxs(w,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:r,connectorKey:i.connector_key,connectionId:String(i.connection_id)},search:{},className:"flex items-center gap-3 py-3 text-sm hover:text-primary",children:[e.jsx("span",{className:"min-w-0 flex-1",children:i.display_name||c.get(i.connector_key)?.name||i.connector_key}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.status}),e.jsx(E,{className:"size-3.5 text-muted-foreground"})]},i.connection_id))})]}):null]})}function Ne({group:t,deviceId:s,organizationId:r,ownerSlug:p,definitionsByKey:u,selectedConnection:d,openSettings:g}){const h=t.connections.some(a=>a.connection_id===d),[l,c]=N.useState(h);return N.useEffect(()=>{h&&d!==void 0&&c(!0)},[h,d]),e.jsxs(F,{open:l,onOpenChange:c,children:[e.jsxs(G,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(E,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:t.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:t.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":t.connections.length>1?`${t.connections.length} connections`:"Configured"})]}),e.jsx(H,{forceMount:!0,hidden:!l,className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:t.connections.map(a=>e.jsx(be,{summary:a,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u.get(a.connector_key),openSettings:a.connection_id===d&&g},a.connection_id))})})]})}function be({summary:t,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u,openSettings:d}){const{data:g=[],isLoading:h,isError:l,refetch:c}=V(r,{connectionIds:[t.connection_id]}),a=g.find(o=>o.id===t.connection_id&&o.device_worker_id===s),m=u?.name??t.connector_key,i=a?me(a):null;return e.jsxs("section",{id:`connection-${t.connection_id}`,"aria-label":m,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:ge(a)}),e.jsx("span",{children:a.status})]}):null,h||!r?e.jsx(_,{className:"h-24 w-full"}):l?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void c(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[i?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:i}):null,e.jsx(xe,{connection:a,connectorDef:u,ownerSlug:p,openSettings:d,showActivity:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function _e({ownerSlug:t,deviceId:s,organizationId:r,selectedConnection:p,openSettings:u}){const d=W(),{data:g=[],isLoading:h}=Y(),l=q(),c=J(),[a,m]=N.useState(!1),[i,o]=N.useState(!1),[v,f]=N.useState(""),n=U(g,s),y=n?.id??s,{data:k=[]}=Q(r,{profileKind:"browser_session"}),C=N.useMemo(()=>k.filter(x=>x.device_worker_id===y&&x.status!=="revoked"),[k,y]),D=n?.label?.trim()??"";if(N.useEffect(()=>{i||f(D)},[D,i]),h)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"h-6 w-6 rounded"}),e.jsx(_,{className:"h-5 w-40"})]}),e.jsx(ue,{})]});if(!n)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const I=A(n),T=X(n.app_version),z=Z(n,T),S=()=>{const x=v.trim(),M=n.label?.trim()??"";if(x===M){o(!1);return}c.mutate({deviceWorkerId:n.id,label:x.length===0?null:x},{onSuccess:()=>o(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(ee,{header:e.jsx(ne,{breadcrumb:e.jsx(oe,{crumbs:[e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:re,children:"Connectors"},"connectors")]}),icon:e.jsx(ce,{platform:I,className:"h-5 w-5"}),title:i?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{"aria-label":"Device name",value:v,onChange:x=>f(x.target.value),placeholder:R({...n,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),a||S()):x.key==="Escape"&&(m(!1),f(n.label?.trim()??""),o(!1))}}),a?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",n.connector_count>0?`and un-pins ${n.connector_count} connector${n.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(j,{variant:"destructive",size:"sm",disabled:l.isPending,onClick:()=>l.mutate(n.id,{onSuccess:()=>{m(!1),d({to:"/$owner/connectors",params:{owner:t},search:{}})}}),children:[l.isPending?e.jsx($,{className:"mr-1.5"}):null,l.isPending?"Removing...":"Confirm remove"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:l.isPending,onClick:()=>m(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",onClick:S,disabled:c.isPending,children:[c.isPending?e.jsx($,{className:"mr-1.5"}):null,c.isPending?"Saving...":"Save"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:c.isPending,onClick:()=>{f(n.label?.trim()??""),o(!1)},children:"Cancel"}),e.jsxs(j,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:c.isPending||l.isPending,onClick:()=>m(!0),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[R(n),e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{m(!1),f(n.label?.trim()??""),o(!0)},children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${n.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),n.online?n.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:z||void 0,caption:`Last seen ${L(new Date(n.last_seen_at),{addSuffix:!0})}${n.last_sync_at?` · Last sync ${L(new Date(n.last_sync_at),{addSuffix:!0})}`:""}`}),children:[n.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(se,{className:"h-3.5 w-3.5 shrink-0"}),n.connector_error_count," connector",n.connector_error_count===1?"":"s"," pinned to this device ",n.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(ve,{device:n,organizationId:r,ownerSlug:t,selectedConnection:p,openSettings:u}),C.length>0?e.jsx(b,{title:"Browser auth profiles",children:e.jsx(ye,{profiles:C})}):null,e.jsx(b,{title:"Runs",children:e.jsx(he,{scope:{deviceId:y},ownerSlug:t})})]})})}function ye({profiles:t}){return t.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:t.map(s=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:s.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.connector_key??"Any connector"}),s.browser_kind?e.jsxs("span",{children:["· ",s.browser_kind]}):null,s.captured_at?e.jsxs("span",{title:s.captured_at,children:["· captured ",le(s.captured_at)]}):null,typeof s.cookie_count=="number"?e.jsxs("span",{children:["· ",s.cookie_count," cookie",s.cookie_count===1?"":"s"]}):null]})]}),e.jsx(pe,{status:s.is_expired?"error":fe(s.status),showDot:!0,children:s.is_expired?"expired":s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},s.id))})})}function Re(){const{owner:t,deviceId:s}=B.useParams(),{connection:r,settings:p}=B.useSearch();return e.jsx(de,{owner:t,children:({ownerSlug:u,organizationId:d})=>e.jsx(_e,{ownerSlug:u,deviceId:s,organizationId:d,selectedConnection:r,openSettings:p})})}export{Re as component};
@@ -1 +0,0 @@
1
- import{Z as Q,ip as re,r as _,j as e,S as F,_ as O,iq as le,ab as G,af as E,cy as oe,ir as ce,dE as C,a3 as de,is as U,it as me,aP as ee,fZ as ue,eS as xe,eW as ge,eU as he,eX as H,fR as pe,fS as fe,fL as ye,dr as se,fT as ve,iu as je,cb as be,cc as S,fP as Ne,cf as we,a6 as I,a7 as W,dY as _e,bD as Se,B as N,g2 as ke,ek as Ce,fU as Ee,L as Te,eD as De,iv as Pe,o as Le,iw as $e,dC as Fe,c9 as Ie}from"./index-B2AmRqYh.js";import{a as J,c as q,S as Oe,D as Re,E as Ae}from"./schema-value-normalization-3JuM_r1H.js";import{V as K,T as ze,a as Me,b as X,c as Y}from"./view-frame-C7ciEoLo.js";import{V as Z,M as Ve}from"./missing-view-DrZ8m8yo.js";import{u as Be}from"./use-applied-views-B-Z-Weji.js";import"./calendar-DAiyi1ZL.js";import"./app-bridge-BH3g2mKG.js";function Ue({entityId:s,ownerSlug:t}){const{orgContext:n}=Q(),{data:l,isLoading:a}=re(s,n),i=_.useMemo(()=>{if(!l)return[];const r=new Map;for(const c of l.rows){const d=r.get(c.relationship_type_slug);d?d.rows.push(c):r.set(c.relationship_type_slug,{slug:c.relationship_type_slug,label:c.relationship_type_name,rows:[c]})}return[...r.values()]},[l]);return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{className:"h-4 w-32"}),e.jsx(F,{className:"h-12 w-full rounded-lg"}),e.jsx(F,{className:"h-12 w-full rounded-lg"})]}):!l||l.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:i.map(({slug:r,label:c,rows:d})=>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:[c,e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:d.length})]}),e.jsx("ul",{className:"space-y-1",children:d.map(x=>e.jsx(He,{entityId:s,row:x,ownerSlug:t},x.id))})]},r))})}function He({entityId:s,row:t,ownerSlug:n}){const l=O(),{orgContext:a}=Q(),[i,r]=_.useState(!1),[c,d]=_.useState(!1),x=t.from_entity_id===t.to_entity_id,h=t.from_entity_id===s,p=x?"this entity":h?t.to_entity_name??`Entity #${t.to_entity_id}`:t.from_entity_name??`Entity #${t.from_entity_id}`,u=h?t.to_entity_type:t.from_entity_type,g=h?t.to_entity_id:t.from_entity_id,o=u?`${u} · ${p}`:p;async function f(){r(!0),d(!1);try{const w=[],j=new Set;let b=g;for(;b!==null;){if(j.has(b))throw new Error("Cyclic entity ancestry");j.add(b);const{entity:y}=await oe("manage_entity",{action:"get",entity_id:b},ce(a));w.unshift({entity_type:y.entity_type,slug:y.slug}),b=y.parent_id}await l({to:C(n,w)})}catch{d(!0)}finally{r(!1)}}return e.jsxs("li",{className:E("flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"),children:[e.jsx(le,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),x||!u?e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:o}):e.jsxs("button",{type:"button",onClick:f,disabled:i,"aria-busy":i,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:o}),u?e.jsx(G,{variant:"outline",className:"shrink-0 text-[9px] px-1.5 py-0 h-4 text-muted-foreground",children:u}):null]}),c?e.jsx("span",{role:"alert",className:"text-xs text-destructive",children:"Could not open this record. Try again."}):null]})}function We(s,t){const n=new Set([...Object.keys(s),...Object.keys(t)]);let l=!1;const a={};for(const i of n){const r=i in s,c=i in t;if(!r&&c){a[i]=t[i];continue}r&&(a[i]=s[i],(!c||JSON.stringify(s[i])!==JSON.stringify(t[i]))&&(l=!0))}return l?a:void 0}function Je({entity:s,entityTypeSlug:t,orgContext:n,onDeleted:l}){const{isAdmin:a,isLoading:i}=ye(n.organizationId),r=a&&!i,{data:c,isLoading:d}=se(t,n),x=ve(),h=je(),p=c?.metadata_schema,u=s.field_controls,g=_.useMemo(()=>J(s.metadata??{},p),[s.metadata,p]),o=be(s.id,{name:s.name,slug:s.slug,metadata:g},p),[f,w]=o.field("name"),[j,b]=o.field("slug"),[y,m]=o.field("metadata"),[R,A]=S(s.id,""),[z,T]=S(s.id,null),[te,D]=S(s.id,!1),[M,P]=S(s.id,null),L=_.useMemo(()=>o.hasInvalidInput?void 0:We(q(y),q(o.baseline.metadata)),[o.baseline.metadata,y,o.hasInvalidInput]),$=L!==void 0,ae=f!==o.baseline.name||j!==o.baseline.slug||$,ne=async v=>{if(v.preventDefault(),!(!r||!o.canSubmit)){if(T(null),!f.trim()){T("Name is required");return}try{await x.mutateAsync({entityId:s.id,name:f.trim()!==o.baseline.name.trim()?f.trim():void 0,slug:j,metadata:L,field_note:$&&R.trim()||void 0}),o.accept(o.values,{name:f.trim(),slug:j,metadata:J({...Ce(o.baseline.metadata),...L},p)}),A("")}catch(B){T(B instanceof Error?B.message:"Failed to update entity")}}},ie=async()=>{if(r){P(null);try{await h.mutateAsync({entityId:s.id}),D(!1),l?.()}catch(v){P(v instanceof Error?v.message:"Failed to delete entity")}}},V=[s.total_content>0&&`${s.total_content} content item${s.total_content===1?"":"s"}`,s.automations_count>0&&`${s.automations_count} Automation${s.automations_count===1?"":"s"}`,s.active_connections>0&&`${s.active_connections} connector${s.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return d?e.jsx(Ne,{rows:6}):e.jsxs("form",{onSubmit:ne,className:"space-y-4",children:[e.jsx(we,{visible:o.hasConflict,onReload:o.reset}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",role:"status",children:i?"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(I,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(W,{id:"sidebar-name",readOnly:!r,value:f,onChange:v=>w(v.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(I,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(W,{id:"sidebar-slug",readOnly:!r,value:j,onChange:v=>b(v.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),o.revision&&Object.keys(o.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Oe,{}),e.jsx(Re,{schema:o.revision,values:y,onValuesChange:m,readonly:!r,fieldControls:u,orgContext:n})]}),r&&$&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(I,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(_e,{id:"sidebar-correction-note",value:R,onChange:v=>A(v.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),z&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:z}),r&&(te?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(Se,{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 "',s.name,'"?']}),V&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",V,". This cannot be easily undone."]})]})]}),M&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:M}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{D(!1),P(null)},children:"Cancel"}),e.jsx(N,{type:"button",variant:"destructive",size:"sm",onClick:ie,disabled:h.isPending,children:h.isPending?"Deleting...":`Delete ${c?.name||"entity"}`})]})]}):e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>D(!0),children:"Delete"}),e.jsx(N,{type:"submit",size:"sm",disabled:!o.canSubmit||!ae||x.isPending||!f.trim(),children:x.isPending?"Saving...":"Save"})]}))]})}function qe({entity:s}){const t=new Set(s.measure_columns??[]),n=s.metadata??{},l=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(xe,{children:e.jsx(ge,{children:l.map(a=>{const i=t.has(a);return e.jsxs(he,{children:[e.jsx(H,{className:"w-44 align-top font-medium text-muted-foreground",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[i?a:pe(a.replace(/_/g," ")),i&&e.jsx(G,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]})}),e.jsx(H,{className:E("break-words align-top",i?"text-right tabular-nums":""),children:fe(n[a])})]},a)})})})})})}const k=":overview",Ke={},Xe=()=>{};function Ye({namespace:s,entity:t,recordUrl:n,viewKey:l,onDeleted:a}){const i=de({strict:!1}),r=O(),c={slug:s.slug,organizationId:s.id},d=Be(c),x=d.data??[],h={type:t.entity_type,id:t.id,slug:t.slug,parentId:t.parent_id},p=U(x,h,"overview"),u=U(x,h,"tab"),g=me(u,l),o=m=>`${n}${ke(m)}`,f=m=>void r({to:".",search:m,replace:!0}),w={type:t.entity_type,entity:t.is_derived?t.slug:t.id},j=t.is_derived?e.jsx(qe,{entity:t}):e.jsx(Je,{entity:t,entityTypeSlug:t.entity_type,orgContext:c,onDeleted:a}),b=t.id>0&&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(Ue,{entityId:t.id,ownerSlug:s.slug})]}),y=e.jsxs(e.Fragment,{children:[d.isError&&e.jsx(Z,{onRetry:()=>void d.refetch()}),p.map(m=>e.jsx("section",{className:E(ee,"mb-4 p-2"),"data-testid":"view-card","data-view":m.key,children:e.jsx(K,{orgSlug:s.slug,viewKey:m.key,scope:w,params:Ke,onParamsChange:Xe,contentHash:m.content_hash,title:m.name,minHeight:160})},m.key)),b,e.jsx("div",{className:"mt-4",children:j})]});return l&&d.data===void 0?d.isError?e.jsx(Z,{onRetry:()=>void d.refetch()}):null:g.kind==="missing"?e.jsx(Ve,{viewKey:g.key,backTo:n,backLabel:`Back to ${t.name}`}):u.length===0?e.jsx("div",{className:"mt-4 max-w-xl",children:y}):e.jsx("div",{className:"mt-4",children:e.jsxs(ze,{value:g.kind==="tab"?g.view.key:k,onValueChange:m=>void r({to:m===k?n:o(m)}),children:[e.jsxs(Me,{children:[e.jsx(X,{value:k,children:"Overview"}),u.map(m=>e.jsx(X,{value:m.key,"data-testid":`tab-${m.key}`,children:m.name},m.key))]}),e.jsx(Y,{value:k,className:"max-w-xl",children:y}),g.kind==="tab"&&e.jsx(Y,{value:g.view.key,children:e.jsx(K,{orgSlug:s.slug,viewKey:g.view.key,scope:w,params:ue(i),onParamsChange:f,contentHash:g.view.content_hash,title:g.view.name,minHeight:320})})]})})}function Ze(s){return typeof s=="string"?s:s===null?"None":JSON.stringify(s)??String(s)}function Qe({records:s}){const t=Fe(),[n,l]=_.useState(null);return s.length===0?null:e.jsxs("details",{className:E(ee,"px-4 py-3"),children:[e.jsxs("summary",{className:"cursor-pointer text-sm font-medium",children:["Merged records (",s.length,")"]}),e.jsx("div",{className:"mt-3 space-y-3",children:s.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(N,{type:"button",variant:"destructive",size:"sm",disabled:t.isPending,onClick:()=>t.mutate({entityId:a.id},{onSettled:()=>l(null)}),children:"Confirm undo"}),e.jsx(N,{type:"button",variant:"outline",size:"sm",disabled:t.isPending,onClick:()=>l(null),children:"Cancel"})]}):e.jsxs(N,{type:"button",variant:"outline",size:"sm",disabled:t.isPending,onClick:()=>l(a.id),children:[e.jsx(Ie,{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(([i,r])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground",children:i}),e.jsx("dd",{className:"break-words",children:Ze(r)})]},i))}):null]},a.id))})]})}function Ge(s){return s?.trim()?s:void 0}function es({ownerSlug:s,entityName:t,activityHref:n}){const l=Le();return e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>l?.open({href:n,title:`${t} · Activity`,owner:s}),disabled:!l,children:[e.jsx($e,{className:"mr-2 h-4 w-4"}),"See activity"]})}function os({namespace:s,path:t,entity:n,mergedFrom:l,viewKey:a}){const i=O(),{data:r}=se(n.entity_type,{slug:s.slug}),c=Ge(r?.icon),d=t.map(u=>({entity_type:u.entity_type,slug:u.slug})),x=`/${s.slug}/${Ee(n.entity_type)}`,h=C(s.slug,d),p=t.length>1?C(s.slug,d.slice(0,-1)):x;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:[l?e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsx("strong",{children:l})," 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(N,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-7 w-fit px-2 text-muted-foreground hover:text-foreground",children:e.jsxs(Te,{to:p,children:[e.jsx(De,{className:"mr-1 h-4 w-4"}),"Back"]})}),n.id>0&&e.jsx("div",{className:"ml-auto",children:e.jsx(es,{ownerSlug:s.slug,entityName:n.name,activityHref:`/${s.slug}/events/${Pe(d)}`})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ae,{metadata:n.metadata,metadataSchema:r?.metadata_schema,name:n.name,typeIcon:c,className:"h-6 w-6"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n.name})]})]}),e.jsx(Qe,{records:n.merged_records??[]}),e.jsx(Ye,{namespace:s,entity:n,recordUrl:h,viewKey:a,onDeleted:()=>{const u=t.slice(0,-1);u.length>0?i({to:C(s.slug,u)}):i({to:x})}})]})}export{os as EntityPage};
@@ -1 +0,0 @@
1
- import{j as e,ab as $,Z as H,fC as me,dx as xe,fF as Y,c6 as ae,r as x,fD as he,fE as pe,cp as ge,cq as fe,B as f,P as V,ct as je,a6 as C,bR as q,bS as P,bT as M,bU as L,bV as R,a7 as T,n as ve,fK as Ne,g5 as ye,dH as be,X as W,cs as ne,dj as re,ag as we,bu as le,g6 as ie,g7 as Se,bD as oe,g8 as Ce,g9 as ke,cb as Ee,cc as Z,cf as _e,dY as Re,b_ as Te,ga as De,gb as Oe,af as G}from"./index-B2AmRqYh.js";import{J as B}from"./json-diff-ClBBYBQD.js";import{C as ce}from"./code-editor-CYsR2VBP.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}=H(),{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!==Y),d=i.filter(m=>m.purpose===Y),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}=H(),{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(W,{className:"h-3 w-3"})})})]})}function Ie({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=H(),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(""),[k,E]=x.useState(""),[O,w]=x.useState(!1),[A,_]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),E(""),w(!1),_(null)},D=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),U=async()=>{_(null);try{let l=h;if(o==="new"){if(!g.trim()){_("Name is required");return}const K=k.trim()||F(g);if(!K){_("Slug is required");return}l=(await u.mutateAsync({slug:K,name:g.trim(),is_symmetric:O})).relationship_type.slug}if(!l){_("Select a relationship type");return}if(!S){_("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}),D(!1)}catch(l){_(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:D,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(V,{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(R,{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),k||E("")}}),e.jsx(T,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:k,onChange:l=>E(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:O,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(R,{value:"source",children:"This type → other"}),e.jsx(R,{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(R,{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:U,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ve({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(W,{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(V,{className:"h-3 w-3"})})]})]})}const Ue=[{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(W,{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(V,{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:Ue.map(t=>e.jsx(R,{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(Ve,{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(R,{value:"none",children:"None"}),e.jsx(R,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(R,{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 Q({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 X(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:"auto"}function He({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)),X(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),D=u.some(F=>F.name.trim());m(D?JSON.stringify(v,null,2):""),a(D?v:void 0)},[a]),k=x.useCallback(u=>{i(u),j(u,o)},[j,o]),E=x.useCallback(u=>{d(u),j(t,u)},[j,t]),O=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)),X(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{k([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,k(v)},_=u=>{k(t.filter((p,v)=>v!==u))};return c?e.jsx(Q,{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:()=>_(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(V,{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, otherwise table)."})]}),e.jsxs(q,{value:o,onValueChange:u=>E(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"auto",children:"Auto"}),e.jsx(R,{value:"table",children:"Table"}),e.jsx(R,{value:"board",children:"Board"})]})]})]})]}):e.jsx(Q,{value:h,onChange:O,error:S})]})}function We(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ke({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,k]=o.field("color"),[E,O]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[_,u]=Z(i,n),[p,v]=Z(i,null),D=w.trim().length>0,F=l=>{h(l),!n&&!_&&S(We(l))},U=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=D?{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:D?void 0:E,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:D?void 0:E,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=>k(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"})]}),D?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(He,{value:E,onChange:O})]}),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:U,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Xe({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=De(),{data:y,isLoading:b}=Oe(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,k=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},E=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",O=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:G("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:G("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:E}),e.jsx("p",{className:"text-sm text-muted-foreground",children:O})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ke,{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:k,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{Xe as E};
@@ -1 +0,0 @@
1
- import{j as e,aS as V,p as T,q as y,a3 as L,_ as N,g_ as S,fZ as $,g2 as U}from"./index-B2AmRqYh.js";import{E as h,u as B}from"./events-feed-DK35T4g7.js";import{T as C,a as O,b as g,c as f,V as P}from"./view-frame-C7ciEoLo.js";import{M as w,V as _}from"./missing-view-DrZ8m8yo.js";const o=":event";function H({owner:l,eventId:t,viewKey:n}){return l==="me"?e.jsx("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 py-6 lg:px-6",children:n?e.jsx(w,{viewKey:n,backTo:`/me/events/${t}`,backLabel:"Back to the event"}):e.jsx(h,{organizationId:null,ownerSlug:"me",filters:{contentIds:[t],sortBy:"date",sortOrder:"desc"}})}):e.jsx("div",{className:"flex flex-1 flex-col gap-6 px-4 py-6 lg:px-6",children:e.jsx(V,{owner:l,children:i=>i.organizationId?e.jsx(z,{organizationId:i.organizationId,ownerSlug:i.ownerSlug,eventId:t,viewKey:n}):e.jsx("div",{className:"mx-auto h-40 w-full max-w-3xl animate-pulse rounded-md bg-muted/40"})})})}function z({organizationId:l,ownerSlug:t,eventId:n,viewKey:i}){const{isAuthenticated:x,isReady:d}=T(),{isMember:j,isLoading:b}=y(),m=d&&x&&j,r=B(m?{slug:t,organizationId:l}:null,n),k=L({strict:!1}),v=N(),c=`/${t}/events/${n}`,p=s=>`${c}${U(s)}`,E=s=>void v({to:".",search:s,replace:!0}),u=e.jsx("div",{className:"mx-auto w-full max-w-3xl","data-testid":"event-native",children:e.jsx(h,{organizationId:l,ownerSlug:t,filters:{contentIds:[n]}})});if(i&&(!d||x&&b))return null;if(!m)return u;if(i&&r.isLoading)return null;if(i&&r.isError)return e.jsx(_,{onRetry:r.refetch});const a=S(r.views,i);return a.kind==="missing"?e.jsx(w,{viewKey:a.key,backTo:c,backLabel:"Back to the event"}):r.views.length===0?u:e.jsxs(C,{value:a.kind==="view"?a.view.key:o,onValueChange:s=>void v({to:s===o?c:p(s)}),children:[e.jsxs(O,{children:[e.jsx(g,{value:o,"data-testid":"tab-event",children:"Event"}),r.views.map(s=>e.jsx(g,{value:s.key,"data-testid":`tab-${s.key}`,children:s.name},s.key))]}),e.jsx(f,{value:o,children:u}),a.kind==="view"&&e.jsx(f,{value:a.view.key,children:e.jsx(P,{orgSlug:t,viewKey:a.view.key,scope:{event:n},params:$(k),onParamsChange:E,contentHash:a.view.content_hash,title:a.view.name,minHeight:320})})]})}export{H as E};