@lobu/runtime-server 24.6.0 → 24.8.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 (261) hide show
  1. package/dist/catalogs/connectors.json +199 -316
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/imessage.ts +953 -0
  4. package/dist/connectors/linkedin.ts +20 -377
  5. package/dist/dependencies.bun.lock +124 -92
  6. package/dist/embeddings-server.mjs +14 -2
  7. package/dist/owletto/dist/assets/_-B0tmXZ86.js +2 -0
  8. package/dist/owletto/dist/assets/_-DwXULq4r.js +3 -0
  9. package/dist/owletto/dist/assets/_agentId-B1dNkhnr.js +2 -0
  10. package/dist/owletto/dist/assets/_agentId-sYjvnBaB.js +2 -0
  11. package/dist/owletto/dist/assets/_automationId-Bnw_CnT_.js +2 -0
  12. package/dist/owletto/dist/assets/_connectorKey._connectionId-D7Z8DQ-B.js +2 -0
  13. package/dist/owletto/dist/assets/_connectorKey.index-DM5MTO8c.js +2 -0
  14. package/dist/owletto/dist/assets/_conversationId-OJrZjd0o.js +2 -0
  15. package/dist/owletto/dist/assets/_eventId-CfB0_2zK.js +2 -0
  16. package/dist/owletto/dist/assets/_owner-BDvTUY0a.js +3 -0
  17. package/dist/owletto/dist/assets/_shape-BZidoJMB.js +2 -0
  18. package/dist/owletto/dist/assets/_slug-R989vOiM.js +2 -0
  19. package/dist/owletto/dist/assets/_viewKey-BDUSrpe5.js +2 -0
  20. package/dist/owletto/dist/assets/_viewKey-BnFqh5-t.js +2 -0
  21. package/dist/owletto/dist/assets/{accept-invitation-CQZQ0wwC.js → accept-invitation-BC-ZIsrf.js} +2 -2
  22. package/dist/owletto/dist/assets/activity-route-view-CN2dOiCD.js +2 -0
  23. package/dist/owletto/dist/assets/agent-connect-pages-CdDjrHjn.js +4 -0
  24. package/dist/owletto/dist/assets/agent-editor-form-CDAHRNWl.js +2 -0
  25. package/dist/owletto/dist/assets/{agent-loading-shells-_18OREnx.js → agent-loading-shells-BupiSjR-.js} +2 -2
  26. package/dist/owletto/dist/assets/agent-permissions-matrix-ju7L2M0l.js +2 -0
  27. package/dist/owletto/dist/assets/{agent-skill-context-1DBn7Xc_.js → agent-skill-context-B0ZYVE3n.js} +2 -2
  28. package/dist/owletto/dist/assets/agent-subpage-shell-ByU0xhXn.js +2 -0
  29. package/dist/owletto/dist/assets/{agent-thread-FyEO-y44.js → agent-thread-DiVKn1WX.js} +4 -4
  30. package/dist/owletto/dist/assets/agent-thread-storage-Bx2-WBHQ.js +2 -0
  31. package/dist/owletto/dist/assets/app._appId-BQWElSoP.js +2 -0
  32. package/dist/owletto/dist/assets/assist-composer-igTXq3DL.js +2 -0
  33. package/dist/owletto/dist/assets/automation-detail-content-BJwRU6qT.js +2 -0
  34. package/dist/owletto/dist/assets/{callback-9xSHyA12.js → callback-Dmaio9CX.js} +2 -2
  35. package/dist/owletto/dist/assets/{card-g4yxo4Hr.js → card-rE4Ctuy6.js} +2 -2
  36. package/dist/owletto/dist/assets/{claim-B98IhDra.js → claim-BN17CPYh.js} +2 -2
  37. package/dist/owletto/dist/assets/{client-activity-scopes-BD2HBo-_.js → client-activity-scopes-B7xVaUA-.js} +2 -2
  38. package/dist/owletto/dist/assets/{client-rows-x_CxeWkP.js → client-rows-B3LULJxW.js} +2 -2
  39. package/dist/owletto/dist/assets/clients-CydgUHrc.js +2 -0
  40. package/dist/owletto/dist/assets/code-editor-UppEMWpt.js +26 -0
  41. package/dist/owletto/dist/assets/connect-OdHpIVV9.js +2 -0
  42. package/dist/owletto/dist/assets/connect-menu-B9u86bb2.js +2 -0
  43. package/dist/owletto/dist/assets/connect._clientId-EI1tcdSE.js +2 -0
  44. package/dist/owletto/dist/assets/connected._clientId-CaF-ZWlZ.js +2 -0
  45. package/dist/owletto/dist/assets/{connection-B6fM2KHN.js → connection-D8ZAMHBT.js} +2 -2
  46. package/dist/owletto/dist/assets/connection-feed-detail-CJYqryAV.js +2 -0
  47. package/dist/owletto/dist/assets/connector-boxes-BWPXijAk.js +2 -0
  48. package/dist/owletto/dist/assets/connector-page-shell-C23dWdKz.js +2 -0
  49. package/dist/owletto/dist/assets/connector-provenance-CW4CXtCz.js +2 -0
  50. package/dist/owletto/dist/assets/{connectors-DnOUxX_U.js → connectors-Bp08_KPq.js} +2 -2
  51. package/dist/owletto/dist/assets/consent-_PpYI1cT.js +2 -0
  52. package/dist/owletto/dist/assets/copy-button-1ALlvZU1.js +2 -0
  53. package/dist/owletto/dist/assets/{core.esm-BsXtvNoI.js → core.esm-6koO33th.js} +3 -3
  54. package/dist/owletto/dist/assets/create-DULVO0HS.js +2 -0
  55. package/dist/owletto/dist/assets/create-Drx9tcnG.js +2 -0
  56. package/dist/owletto/dist/assets/create-automation-form-BhujNbRr.js +3 -0
  57. package/dist/owletto/dist/assets/create-kUevP9Xx.js +2 -0
  58. package/dist/owletto/dist/assets/create._connectorKey-N6fhcIPy.js +2 -0
  59. package/dist/owletto/dist/assets/custom-guardrail-edits-B_aCgvoZ.js +2 -0
  60. package/dist/owletto/dist/assets/definition-comparison-3zKUSTt8.js +2 -0
  61. package/dist/owletto/dist/assets/detail-page-skeleton-BmxqqIsH.js +2 -0
  62. package/dist/owletto/dist/assets/{device-DdCoCj-Q.js → device-D2eUt_nr.js} +2 -2
  63. package/dist/owletto/dist/assets/device-automation-Dp3faMvp.js +2 -0
  64. package/dist/owletto/dist/assets/device-pin-tombstone-BFPbTM_o.js +2 -0
  65. package/dist/owletto/dist/assets/device._deviceId-Dqtmb1Xp.js +2 -0
  66. package/dist/owletto/dist/assets/dynamic-schema-form-D3KnzCsW.js +2 -0
  67. package/dist/owletto/dist/assets/entity-options-IUdQ-64R.js +2 -0
  68. package/dist/owletto/dist/assets/entity-page-B3Im65EI.js +2 -0
  69. package/dist/owletto/dist/assets/entity-pages-DJNSQrfB.js +2 -0
  70. package/dist/owletto/dist/assets/entity-type-page-CouHZbc9.js +2 -0
  71. package/dist/owletto/dist/assets/event-detail-CvaRN1qB.js +2 -0
  72. package/dist/owletto/dist/assets/event-kind-options-fHAIXu24.js +2 -0
  73. package/dist/owletto/dist/assets/events-feed-DwOkLk6A.js +2 -0
  74. package/dist/owletto/dist/assets/filter-editors-DQ5V4Cvh.js +2 -0
  75. package/dist/owletto/dist/assets/{full-page-spinner-B5xXnKtV.js → full-page-spinner-B7A6Ycyi.js} +2 -2
  76. package/dist/owletto/dist/assets/home-stream-Bg97PUBJ.js +2 -0
  77. package/dist/owletto/dist/assets/home-toolbar-CpCcHA6z.js +2 -0
  78. package/dist/owletto/dist/assets/index-9PGnv4-5.js +2 -0
  79. package/dist/owletto/dist/assets/{index-TkPy_P_u.js → index-B-dZruj6.js} +2 -2
  80. package/dist/owletto/dist/assets/index-BztXeLBN.js +2 -0
  81. package/dist/owletto/dist/assets/index-C2TCKJDP.js +7901 -0
  82. package/dist/owletto/dist/assets/index-C7QM3aqU.js +2 -0
  83. package/dist/owletto/dist/assets/index-CWn46a4y.js +2 -0
  84. package/dist/owletto/dist/assets/index-CxJONizf.js +2 -0
  85. package/dist/owletto/dist/assets/index-DJhb3li3.js +2 -0
  86. package/dist/owletto/dist/assets/{index-BDl1_w6U.js → index-DXfYVs5m.js} +2 -2
  87. package/dist/owletto/dist/assets/{index-BdNR51Ua.js → index-DY-YGnCe.js} +2 -2
  88. package/dist/owletto/dist/assets/index-j3v7ITPb.js +2 -0
  89. package/dist/owletto/dist/assets/index-oiy6ygaI.js +2 -0
  90. package/dist/owletto/dist/assets/index-pEgtAY1t.js +2 -0
  91. package/dist/owletto/dist/assets/index-xAvK3IyQ.css +1 -0
  92. package/dist/owletto/dist/assets/json-diff-CJK-gzCt.js +4 -0
  93. package/dist/owletto/dist/assets/list-skeleton-bQAZ0hQp.js +2 -0
  94. package/dist/owletto/dist/assets/{login-TWR0vF4_.js → login-DLqL54Rk.js} +2 -2
  95. package/dist/owletto/dist/assets/{logout-BA5kojS0.js → logout-H0F3IfiO.js} +2 -2
  96. package/dist/owletto/dist/assets/member-scope-gate-Doic_6qX.js +2 -0
  97. package/dist/owletto/dist/assets/memory-browse-page-CUea2Llz.js +74 -0
  98. package/dist/owletto/dist/assets/model-selector-BrfaDwIg.js +2 -0
  99. package/dist/owletto/dist/assets/new-5GkxlOuQ.js +2 -0
  100. package/dist/owletto/dist/assets/{new-Dc5Bbotb.js → new-BiA4DGoN.js} +2 -2
  101. package/dist/owletto/dist/assets/new-M-MX_T5C.js +2 -0
  102. package/dist/owletto/dist/assets/organization-CLrcmgNK.js +2 -0
  103. package/dist/owletto/dist/assets/peek-pane-content-B29OcHwm.js +2 -0
  104. package/dist/owletto/dist/assets/{pending-seed-BP3xHM2d.js → pending-seed-DYYOoCvj.js} +2 -2
  105. package/dist/owletto/dist/assets/proposal-review-shell-BVwOMoq9.js +2 -0
  106. package/dist/owletto/dist/assets/public-shell-ready-BbjPgh3k.js +2 -0
  107. package/dist/owletto/dist/assets/record-activity-BCpNKaUo.js +2 -0
  108. package/dist/owletto/dist/assets/{record-session-DOFgdd43.js → record-session-KuEDuF3S.js} +2 -2
  109. package/dist/owletto/dist/assets/{renderer-CHPS-1vD.js → renderer-ucwCQmBk.js} +26 -26
  110. package/dist/owletto/dist/assets/{reset-password-BmNM-apc.js → reset-password-BkiAmXZW.js} +2 -2
  111. package/dist/owletto/dist/assets/run-initiator-8vdkq-3o.js +2 -0
  112. package/dist/owletto/dist/assets/{runs-BntGAKQG.js → runs-B_iywKWb.js} +2 -2
  113. package/dist/owletto/dist/assets/runs-list-CJJFRhTl.js +2 -0
  114. package/dist/owletto/dist/assets/schema-type-editor-panel-C4e8pq1A.js +2 -0
  115. package/dist/owletto/dist/assets/{schema-value-BFb7jCBo.js → schema-value-CefbtPIY.js} +3 -3
  116. package/dist/owletto/dist/assets/scoped-feed-bar-CapleZvS.js +2 -0
  117. package/dist/owletto/dist/assets/{settings-DubSpJfg.js → settings-DvzkRYQy.js} +2 -2
  118. package/dist/owletto/dist/assets/skill-route-key-sF006xiz.js +2 -0
  119. package/dist/owletto/dist/assets/source-record-panels-LJIWGtHb.js +2 -0
  120. package/dist/owletto/dist/assets/status-variants-BxHtpMOj.js +2 -0
  121. package/dist/owletto/dist/assets/subDays-DwIOMzYC.js +2 -0
  122. package/dist/owletto/dist/assets/{table-DALHuXPE.js → table-1O-ik4_O.js} +2 -2
  123. package/dist/owletto/dist/assets/{use-automations-D9hKpufo.js → use-automations-lV8PuE8L.js} +2 -2
  124. package/dist/owletto/dist/assets/use-login-redirect-CfCbEeJR.js +2 -0
  125. package/dist/owletto/dist/assets/use-mention-search-CA-evCDf.js +91 -0
  126. package/dist/owletto/dist/assets/view-param-filters-Bp84PUMd.js +2 -0
  127. package/dist/owletto/dist/assets/{views-access-required-CZ1fvAks.js → views-access-required-BerT4Z1d.js} +2 -2
  128. package/dist/owletto/dist/index.html +2 -2
  129. package/dist/server-main.bundle.mjs +358 -141
  130. package/npm-shrinkwrap.json +540 -447
  131. package/package.json +4 -2
  132. package/vendor/connector-sdk/package.json +1 -1
  133. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  134. package/vendor/core/dist/connector-query-errors.js +4 -0
  135. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -0
  136. package/vendor/core/dist/contracts/tools/manage-entity.js +7 -0
  137. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +2 -0
  138. package/vendor/core/dist/contracts/tools/manage-feeds.js +3 -0
  139. package/vendor/core/dist/contracts/tools/view-host.js +2 -0
  140. package/vendor/core/dist/error-report.js +1 -0
  141. package/vendor/core/package.json +1 -1
  142. package/vendor/views/package.json +1 -1
  143. package/dist/connectors/linkedin-takeout.ts +0 -577
  144. package/dist/connectors/takeout-utils.ts +0 -240
  145. package/dist/owletto/dist/assets/_-DT3E3BmS.js +0 -3
  146. package/dist/owletto/dist/assets/_-DtqBFgK5.js +0 -2
  147. package/dist/owletto/dist/assets/_-c1xy7bLu.js +0 -2
  148. package/dist/owletto/dist/assets/_agentId-CTfoi0-7.js +0 -2
  149. package/dist/owletto/dist/assets/_agentId-DV8utajn.js +0 -2
  150. package/dist/owletto/dist/assets/_automationId-DvP3qyYL.js +0 -2
  151. package/dist/owletto/dist/assets/_connectorKey._connectionId-CL5SivCn.js +0 -2
  152. package/dist/owletto/dist/assets/_connectorKey.index-tnMwC67b.js +0 -2
  153. package/dist/owletto/dist/assets/_conversationId-DXN_8m88.js +0 -2
  154. package/dist/owletto/dist/assets/_eventId-SdpFT7jB.js +0 -2
  155. package/dist/owletto/dist/assets/_name-CM1AMywz.js +0 -2
  156. package/dist/owletto/dist/assets/_owner-CaGsXXBW.js +0 -3
  157. package/dist/owletto/dist/assets/_shape-DGAkETDp.js +0 -2
  158. package/dist/owletto/dist/assets/_skillKey-Dd4ZHPY8.js +0 -2
  159. package/dist/owletto/dist/assets/_slug-cRvJQtNo.js +0 -2
  160. package/dist/owletto/dist/assets/_view-B5I7mmkl.js +0 -2
  161. package/dist/owletto/dist/assets/_viewKey-Bwn0dyLo.js +0 -2
  162. package/dist/owletto/dist/assets/_viewKey-YjSYD0wc.js +0 -2
  163. package/dist/owletto/dist/assets/activity-route-view-CZykJXQp.js +0 -2
  164. package/dist/owletto/dist/assets/agent-card-controls-DuQJhtqp.js +0 -2
  165. package/dist/owletto/dist/assets/agent-client-setup-list-CpUTAjXf.js +0 -4
  166. package/dist/owletto/dist/assets/agent-connect-pages-Br_ycC0z.js +0 -2
  167. package/dist/owletto/dist/assets/agent-editor-form-BXQBFHSv.js +0 -2
  168. package/dist/owletto/dist/assets/agent-guardrails-route-CN7vpC0X.js +0 -2
  169. package/dist/owletto/dist/assets/agent-list-row-BnP6r4pm.js +0 -2
  170. package/dist/owletto/dist/assets/agent-permissions-matrix-DSjidWHL.js +0 -2
  171. package/dist/owletto/dist/assets/agent-skills-route-d5jh3oBR.js +0 -2
  172. package/dist/owletto/dist/assets/agent-tab-intro-DKrC3SQt.js +0 -2
  173. package/dist/owletto/dist/assets/agent-thread-storage-U6htL3ad.js +0 -2
  174. package/dist/owletto/dist/assets/agents-kXojozTU.js +0 -2
  175. package/dist/owletto/dist/assets/agents-workbench-CDpJmUVN.js +0 -2
  176. package/dist/owletto/dist/assets/app._appId-DwNeXRJp.js +0 -2
  177. package/dist/owletto/dist/assets/assist-composer-Mn9EfX4X.js +0 -2
  178. package/dist/owletto/dist/assets/automation-detail-content-Bs3vwAPd.js +0 -2
  179. package/dist/owletto/dist/assets/automation-row-B5Q1B10y.js +0 -2
  180. package/dist/owletto/dist/assets/automation-source-list-Dhucq1sI.js +0 -2
  181. package/dist/owletto/dist/assets/automations-kXojozTU.js +0 -2
  182. package/dist/owletto/dist/assets/change-summary-DeuXQEpb.js +0 -2
  183. package/dist/owletto/dist/assets/clients-Cmp0LmOp.js +0 -2
  184. package/dist/owletto/dist/assets/connect-menu-CezOH3s7.js +0 -2
  185. package/dist/owletto/dist/assets/connect-zUot_0kG.js +0 -2
  186. package/dist/owletto/dist/assets/connect._clientId-nsGxe6yO.js +0 -2
  187. package/dist/owletto/dist/assets/connected._clientId-DnclRRXk.js +0 -2
  188. package/dist/owletto/dist/assets/connected._clientId.activity-CDB8atTX.js +0 -2
  189. package/dist/owletto/dist/assets/connected._clientId.index-DBNP2mZo.js +0 -2
  190. package/dist/owletto/dist/assets/connection-feed-detail-Ckq-qEbD.js +0 -2
  191. package/dist/owletto/dist/assets/connection-label-BobuYiAG.js +0 -2
  192. package/dist/owletto/dist/assets/connections-browser-BXsJqieG.js +0 -2
  193. package/dist/owletto/dist/assets/connector-boxes-CbqSFeVm.js +0 -2
  194. package/dist/owletto/dist/assets/connector-page-shell-Di6XzkVo.js +0 -2
  195. package/dist/owletto/dist/assets/connector-provenance-BrnasBW4.js +0 -2
  196. package/dist/owletto/dist/assets/connector-scope-lists-dQnZARCD.js +0 -2
  197. package/dist/owletto/dist/assets/consent-Byli4yMs.js +0 -2
  198. package/dist/owletto/dist/assets/copy-button-Ddf7lBjZ.js +0 -2
  199. package/dist/owletto/dist/assets/create-B34eskZ_.js +0 -2
  200. package/dist/owletto/dist/assets/create-DLB9sXgU.js +0 -2
  201. package/dist/owletto/dist/assets/create-YdAnh3ml.js +0 -2
  202. package/dist/owletto/dist/assets/create-automation-form-C9PMX7N8.js +0 -3
  203. package/dist/owletto/dist/assets/create._connectorKey-Bz4OYRiC.js +0 -2
  204. package/dist/owletto/dist/assets/definition-comparison-B5WgZILB.js +0 -2
  205. package/dist/owletto/dist/assets/device-pin-tombstone-B06J7Af1.js +0 -2
  206. package/dist/owletto/dist/assets/device._deviceId-Bh9S4bFp.js +0 -2
  207. package/dist/owletto/dist/assets/dynamic-schema-form-qWSRtOAv.js +0 -2
  208. package/dist/owletto/dist/assets/entity-options-BkU_En_f.js +0 -2
  209. package/dist/owletto/dist/assets/entity-page-BPFDHY8q.js +0 -2
  210. package/dist/owletto/dist/assets/entity-pages-DxgbjLMt.js +0 -2
  211. package/dist/owletto/dist/assets/entity-type-page-D0ghgRgq.js +0 -2
  212. package/dist/owletto/dist/assets/event-card-CjA_dLzq.js +0 -2
  213. package/dist/owletto/dist/assets/event-detail-CmC-DVrK.js +0 -2
  214. package/dist/owletto/dist/assets/events-feed-CGzA1w3R.js +0 -2
  215. package/dist/owletto/dist/assets/filter-bar-CQ_oE7a9.js +0 -2
  216. package/dist/owletto/dist/assets/guardrails-DkXatmea.js +0 -2
  217. package/dist/owletto/dist/assets/identity-BwJy3ixB.js +0 -2
  218. package/dist/owletto/dist/assets/index-35ehGReZ.js +0 -2
  219. package/dist/owletto/dist/assets/index-B9hYiwBw.js +0 -2
  220. package/dist/owletto/dist/assets/index-BjcZVe7n.js +0 -7899
  221. package/dist/owletto/dist/assets/index-BqAVebvY.js +0 -2
  222. package/dist/owletto/dist/assets/index-BvK1fS1J.js +0 -2
  223. package/dist/owletto/dist/assets/index-CNEpTkgw.css +0 -1
  224. package/dist/owletto/dist/assets/index-CRc73k1t.js +0 -2
  225. package/dist/owletto/dist/assets/index-CYGaSD3y.js +0 -2
  226. package/dist/owletto/dist/assets/index-CfZGe-zn.js +0 -2
  227. package/dist/owletto/dist/assets/index-CkiyxW4w.js +0 -2
  228. package/dist/owletto/dist/assets/index-CzLDNB2E.js +0 -2
  229. package/dist/owletto/dist/assets/index-D-o5iOVd.js +0 -2
  230. package/dist/owletto/dist/assets/index-DjYVV1Ml.js +0 -2
  231. package/dist/owletto/dist/assets/index-VyAX-asP.js +0 -2
  232. package/dist/owletto/dist/assets/json-diff-DtZtra_g.js +0 -28
  233. package/dist/owletto/dist/assets/list-skeleton-CIHWCi2a.js +0 -2
  234. package/dist/owletto/dist/assets/manage-gear-C-0BAMbC.js +0 -2
  235. package/dist/owletto/dist/assets/member-scope-gate-BQiRAqtx.js +0 -2
  236. package/dist/owletto/dist/assets/memory-browse-page-Ba32-vVL.js +0 -74
  237. package/dist/owletto/dist/assets/model-C2q7WDcS.js +0 -2
  238. package/dist/owletto/dist/assets/model-selector-B2cjCn0V.js +0 -2
  239. package/dist/owletto/dist/assets/models-CZkH5gtj.js +0 -2
  240. package/dist/owletto/dist/assets/nav-pill-Bam6s3jj.js +0 -2
  241. package/dist/owletto/dist/assets/new-BJst6K0b.js +0 -2
  242. package/dist/owletto/dist/assets/new-DgbivfDe.js +0 -2
  243. package/dist/owletto/dist/assets/organization-B9U1L-56.js +0 -2
  244. package/dist/owletto/dist/assets/peek-pane-content-Cq8P38s3.js +0 -2
  245. package/dist/owletto/dist/assets/permissions-BVlbeY4u.js +0 -2
  246. package/dist/owletto/dist/assets/proposal-review-shell-BED-DO9C.js +0 -2
  247. package/dist/owletto/dist/assets/public-shell-ready-Diq15_QW.js +0 -2
  248. package/dist/owletto/dist/assets/record-activity-CTLwq8s1.js +0 -2
  249. package/dist/owletto/dist/assets/run-activity-link-Dh1YyCfk.js +0 -2
  250. package/dist/owletto/dist/assets/run-initiator-CCxNv0rK.js +0 -2
  251. package/dist/owletto/dist/assets/runs-panel-BwTVaRsE.js +0 -2
  252. package/dist/owletto/dist/assets/runs-table-CYS1jDdL.js +0 -2
  253. package/dist/owletto/dist/assets/schema-type-editor-panel-v3nR2Oa2.js +0 -2
  254. package/dist/owletto/dist/assets/settings-DBgT60nY.js +0 -2
  255. package/dist/owletto/dist/assets/skills-DDoeRGhJ.js +0 -2
  256. package/dist/owletto/dist/assets/source-record-panels-m8gECt82.js +0 -2
  257. package/dist/owletto/dist/assets/status-dot-BnQPFrcU.js +0 -2
  258. package/dist/owletto/dist/assets/use-login-redirect-ciwfc-7A.js +0 -2
  259. package/dist/owletto/dist/assets/use-mention-search-CJGCatFS.js +0 -96
  260. package/dist/owletto/dist/assets/use-scroll-sentinel-BWCrmNIB.js +0 -2
  261. package/dist/owletto/dist/assets/view-param-filters-CDvwie_f.js +0 -2
@@ -0,0 +1,3 @@
1
+ import{r,j as e,bg as oe,bh as ce,bi as re,bj as ie,bk as L,U as ae,B as X,X as Cs,ht as Es,ct as Os,aH as As,x as ds,hu as Fs,hv as Ts,m as Dt,T as b,i as R,dN as We,eR as Rt,h3 as Ls,h4 as Ms,gw as Ps,e6 as us,h6 as Ds,fN as Rs,hw as $t,hx as $s,gF as it,dq as Ue,a4 as rt,gH as bt,c1 as ms,dh as Ye,cC as Is,aa as qs,$ as Ks,d4 as Bs,hy as Ws,hz as zs,hA as Us,hB as Vs,hC as Qs,a2 as Js,L as Gs,G as hs,hs as Hs,s as Xs,aM as Ys,er as It,fV as qt,h0 as Zs,hD as en,S as tn,eK as sn,bI as _t,ai as nn,hE as an,fD as on,hF as cn,hG as rn,bH as ln}from"./index-C2TCKJDP.js";import{C as dn,f as un}from"./entity-options-IUdQ-64R.js";import{c as mn,d as hn,e as xn,f as gn,g as pn,u as fn}from"./use-automations-lV8PuE8L.js";import{a as vn,A as yn}from"./device-automation-Dp3faMvp.js";import{M as jn}from"./model-selector-BrfaDwIg.js";import{b as _n}from"./skill-editor-D_W3QlRz.js";import{C as Nt}from"./code-editor-UppEMWpt.js";import{A as Nn,J as Kt}from"./json-diff-CJK-gzCt.js";import{u as bn,b as Bt,c as Wt,s as kn,o as Sn,a as wn,d as Cn,e as En,f as On,v as An,r as Fn}from"./use-mention-search-CA-evCDf.js";const at=[{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 Tn(n){const s=n.trim();if(!s)return null;try{return Es.toString(s,{throwExceptionOnParseError:!0})}catch{return null}}function Ln({value:n,onChange:s,placeholder:t="No schedule",className:i}){const d=n??"",u=at.some(g=>g.value===d),[c,o]=r.useState(!u&&d!==""),f=g=>{g==="custom"?o(!0):(o(!1),s(g))},N=d?Tn(d):null,m=d?e.jsx("p",{className:N?"text-xs text-muted-foreground":"text-xs text-destructive",children:N??"Not a valid cron expression."}):null;return!d&&!c?e.jsxs(oe,{onValueChange:f,children:[e.jsx(ce,{className:i??"w-full",children:e.jsx(re,{placeholder:t})}),e.jsx(ie,{children:at.map(g=>e.jsxs(L,{value:g.value,children:[g.label,g.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:g.value})]},g.value))})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(ae,{placeholder:"0 */6 * * *",value:d,onChange:g=>s(g.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(oe,{value:d,onValueChange:f,children:[e.jsx(ce,{className:i??"w-full flex-1",children:e.jsx(re,{children:at.find(g=>g.value===d)?.label??d})}),e.jsx(ie,{children:at.map(g=>e.jsxs(L,{value:g.value,children:[g.label,g.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:g.value})]},g.value))})]}),e.jsx(X,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),s("")},children:e.jsx(Cs,{className:"h-4 w-4"})})]}),m]})}const gt="__all_workspace_event_types__",Mn=[],Pn={};function zt(n,s,t){const i=new Map;if(!s)for(const[u,c]of Object.entries(t??{}))i.set(u,{key:u,label:$t(u),description:c.description});const d=[...n].filter(u=>!s||u.slug===s).sort((u,c)=>u.slug.localeCompare(c.slug));for(const u of d)for(const[c,o]of Object.entries(u.event_kinds??{})){const f=i.get(c);if(f){!f.description&&o.description&&(f.description=o.description),JSON.stringify(f.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(f.metadataSchema=void 0);continue}i.set(c,{key:c,label:$t(c),description:o.description,metadataSchema:o.metadataSchema})}return[...i.values()].sort((u,c)=>u.label.localeCompare(c.label))}function Ut(n){const s=n[0];if(!s)return;const t=d=>JSON.stringify(Object.keys(d?.properties??{}).sort()),i=t(s);return n.every(d=>t(d)===i)?s:void 0}function Vt(n,s,t){const i=new Set(Object.keys(s.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([d])=>!i.has(d))),...t}}function Be(n,s,t){return t==="steer"&&(n==="window"||s!=="reply_to_source")?"coalesce":t}function He(n,s){return n==="window"?"silent":s}function Qt(n){return Object.fromEntries(Object.entries(n).filter(([s])=>s==="resource_ref"||s==="resource_type"))}function Jt(n,s,t){const i=new Set(Object.keys(s?.properties??{})),d=new Set(t.flatMap(u=>Object.keys(u.filterSchema?.properties??{})));return Object.fromEntries(Object.entries($s(n)).filter(([u])=>u==="resource_ref"||u==="resource_type"||!d.has(u)||i.has(u)))}function Dn({value:n,options:s,onChange:t}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:s.map(i=>e.jsx("button",{type:"button","aria-pressed":n===i.value,onClick:()=>t(i.value),className:R("rounded px-3 py-1 transition-colors",n===i.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:i.label},i.value))})}function Gt({events:n,selectedKeys:s,onToggle:t,ariaLabel:i="Events"}){const d=r.useId(),u=n.filter(o=>s.includes(o.key)).map(o=>o.label),c=u.length===0?"Choose events":u.length===1?u[0]:`${u.length} events selected`;return e.jsx(it,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(X,{type:"button",variant:"outline",role:"combobox","aria-label":i,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:R(u.length===0&&"text-muted-foreground"),children:c}),e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,f)=>{const N=s.includes(o.key),m=`${d}-${f}-state`;return e.jsxs(Ue,{value:`${o.label} ${o.key}`,onSelect:()=>t(o.key),"aria-label":o.label,"aria-describedby":m,className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",N?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:m,className:"sr-only",children:N?"Selected":"Not selected"})]},o.key)})})}function Rn({organizationId:n,initialTrigger:s,onChange:t,allowedKinds:i,showSectionHeader:d=!0,fieldIdPrefix:u="automation-trigger-"}){const c=Os(n,{status:"active",limit:500}),o=As(n),f=ds({organizationId:n}),N=Fs({organizationId:n}),m=c.data??[],g=o.data??[],$=f.data??Mn,h=N.data??Pn,k=r.useMemo(()=>$.filter(l=>l.organization_id===n),[$,n]),S=s?.kind==="event"&&s?.source==="workspace",O=S||s===void 0,W=i?.length?[...i]:["event","time","manual"],p=W.join("|"),M=(()=>{const l=s===null?"manual":s?.kind==="schedule"?"time":"event";return W.includes(l)?l:W[0]??"event"})(),[j,le]=r.useState(M),[I,de]=r.useState(S?"workspace":typeof s?.connection_id=="number"?String(s.connection_id):s?.kind==="event"&&s.connector_key?"":"workspace"),w=I==="workspace",Y=w?"":I,[v,_]=r.useState(typeof s?.entity_type=="string"?s.entity_type:""),Se=r.useMemo(()=>Array.isArray(s?.event_types)?s.event_types:[],[s]),[E,ge]=r.useState(()=>Se.filter(l=>typeof l=="string")),[z,pe]=r.useState(s?.match&&typeof s.match=="object"&&!Array.isArray(s.match)?s.match:{}),[fe,ve]=r.useState(typeof s?.cron=="string"?s.cron:"0 9 * * 1-5"),Ne=typeof s?.timezone=="string"?s.timezone:void 0,[q,ye]=r.useState(s?.kind==="schedule"||O&&s?.execution!=="turn"||s?.execution==="window"?"window":"turn"),[K,ue]=r.useState(He(q,s?.output==="reply_to_source"?"reply_to_source":"silent")),[J,Z]=r.useState(s?.kind==="schedule"||O&&s?.active_run!=="queue"?"coalesce":Be(q,K,s?.active_run==="coalesce"||s?.active_run==="steer"?s.active_run:"queue")),[je,Te]=r.useState(s?.skip_if_unchanged!==!1),[Le,Me]=r.useState(!1);r.useEffect(()=>{const l=p.split("|");if(!l.includes(j)){const y=l[0]??"event";le(y),ye(y==="time"||y==="event"&&w?"window":"turn"),Z(y==="time"||y==="event"&&w?"coalesce":"queue"),ue("silent")}},[p,j,w]);const se=m.find(l=>String(l.id)===Y),x=c.isLoading||o.isLoading,me=f.isLoading,U=typeof s?.connector_key=="string"?s.connector_key:void 0,te=j==="event"&&!w&&s?.kind==="event"&&s?.source!=="workspace"&&typeof s.connection_id=="number"&&String(s.connection_id)===Y&&!se,P=j==="event"&&!w&&s?.kind==="event"&&s?.source!=="workspace"&&s.connection_id==null&&U!==void 0&&Y==="",Pe=g.find(l=>l.key===(se?.connector_key??(P?U:void 0))),G=Pe?.automation_events??[],Ve=G.filter(l=>E.includes(l.key)),we=Ve[0],De=k.find(l=>l.slug===v),Oe=[...k.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===v),...v&&!De?[{slug:v,name:v}]:[]],A=r.useMemo(()=>zt(k,v||void 0,h),[k,v,h]),Ae=A.filter(l=>E.includes(l.key)),Re=Ae[0],he=Ut(Ve.map(l=>l.filterSchema)),Ce=Ut(Ae.map(l=>l.metadataSchema)),$e=!!(w&&v&&!De),Ie=te||P,xe=(j==="event"?w?E.length>0&&!$e:!!(E.length>0&&(Y&&se||Ie)):j==="time"?!!fe.trim():!0)&&(j!=="event"||!Ts(z));r.useEffect(()=>{let l;if(xe&&j==="event"&&!w){const y=Jt(z,he,Pe?.automation_events??[]);se||P?l={kind:"event",source:"connector",connector_key:se?.connector_key??U,...se?{connection_id:Number(Y)}:{},event_types:E,...Object.keys(y).length>0?{match:y}:{},execution:q,active_run:Be(q,K,J),output:He(q,K),skip_if_unchanged:je}:te&&(l=s?{...s,source:"connector"}:void 0)}else if(xe&&j==="event"&&w){const y=Jt(z,Ce,A.map(F=>({filterSchema:F.metadataSchema})));l={kind:"event",source:"workspace",...v?{entity_type:v}:{},event_types:E,...Object.keys(y).length>0?{match:y}:{},execution:q,active_run:J==="queue"?"queue":"coalesce"}}else xe&&j==="time"&&(l={kind:"schedule",cron:fe.trim(),...Ne?{timezone:Ne}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:je});t({ready:xe,kind:j,trigger:l})},[J,Y,se,fe,Pe,E,q,z,j,U,Ne,s,w,t,K,xe,he,Ce,je,v,A,P,te]);const qe=l=>{const y=m.find(T=>String(T.id)===l),F=g.find(T=>T.key===y?.connector_key),ee=E.filter(T=>F?.automation_events?.some(ke=>ke.key===T)),ne=F?.automation_events?.find(T=>T.key===ee[0]),be=y?.connector_key!==(se?.connector_key??U);if(de(l),ge(ee),!ne)pe(Qt);else if(be){const T=ne.defaults?.execution??"turn",ke=ne.defaults?.activeRun??"queue",V=He(T,ne.defaults?.output??"silent");pe(Qt),ye(T),Z(Be(T,V,ke)),ue(V)}},et=l=>{if(l==="workspace"){de("workspace"),ge(y=>y.filter(F=>A.some(ee=>ee.key===F))),pe({}),ye("window"),Z("coalesce"),ue("silent");return}qe(l)},Je=l=>{const y=E.includes(l)?E.filter(T=>T!==l):G.map(T=>T.key).filter(T=>T===l||E.includes(T));if(ge(y),y[0]===E[0])return;const F=G.find(T=>T.key===y[0]),ee=F?.defaults?.execution??"turn",ne=F?.defaults?.activeRun??"queue",be=He(ee,F?.defaults?.output??"silent");ye(ee),Z(Be(ee,be,ne)),ue(be)},tt=l=>{const y=l===gt?"":l,F=k.find(ne=>ne.slug===y),ee=zt(k,F?.slug,h);_(y),ge(ne=>ne.filter(be=>ee.some(T=>T.key===be))),pe({})},st=l=>{ge(y=>y.includes(l)?y.filter(F=>F!==l):A.map(F=>F.key).filter(F=>F===l||y.includes(F)))},Fe=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>W.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,Fe.length>1?e.jsx(Dn,{value:j,options:Fe,onChange:l=>{le(l),ye(l==="time"||l==="event"&&w?"window":"turn"),Z(l==="time"||l==="event"&&w?"coalesce":"queue"),ue("silent")}}):null,j==="event"?x||w&&me?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Dt,{className:"h-9 w-full"}),e.jsx(Dt,{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(dn,{connections:m,value:I,onValueChange:et,disabled:Ie,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),te?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."}):P?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(s?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),w?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:A.length>1?"Events":"Event"}),A.length>0?e.jsx(Gt,{events:A,selectedKeys:E,onToggle:st}):e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:v?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),Re?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:Re.description}):null,$e?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",v,"”, 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."})]}),Ce?e.jsx(Rt,{schema:Ce,values:z,onValuesChange:l=>pe(y=>Vt(y,Ce,l)),fieldIdPrefix:`${u}workspace-`},`${v||"workspace"}:${E.join(",")}`):null]}):se||P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:G.length>1?"Events":"Event"}),G.length?e.jsx(Gt,{events:G,selectedKeys:E,onToggle:Je}):e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),we?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:we.description}):null]}),typeof z.resource_ref=="string"||he?e.jsxs("div",{className:"space-y-3",children:[typeof z.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Resource"}),e.jsx("div",{className:R(We,"px-3 py-2 text-sm"),children:z.resource_ref})]}):null,he?e.jsx(Rt,{schema:he,values:z,onValuesChange:l=>pe(y=>Vt(y,he,l)),fieldIdPrefix:u},E.join(",")):null]}):null]}):I?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):j==="time"?e.jsx(Ln,{value:fe,onChange:ve}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),j!=="manual"&&!Ie?e.jsxs(Ls,{open:Le,onOpenChange:Me,children:[e.jsx(Ms,{asChild:!0,children:e.jsxs(X,{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(Ps,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",q==="turn"?"Each event":"Window"," ·"," ",j==="time"?"Combine":w?J==="queue"?"Queue":"Combine":J==="queue"?"Queue":J==="coalesce"?"Combine":"Update current run",j==="event"&&!w?` · ${q==="turn"&&K==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(us,{className:R("h-4 w-4 transition-transform",Le&&"rotate-180")})]})}),e.jsxs(Ds,{className:"space-y-4 pt-3",children:[j==="event"&&w?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity type filter"}),e.jsxs(oe,{value:v||gt,onValueChange:tt,children:[e.jsx(ce,{"aria-label":"Entity type filter",children:e.jsx(re,{})}),e.jsxs(ie,{children:[e.jsx(L,{value:gt,children:"All event types"}),Oe.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,j==="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(oe,{value:q,onValueChange:l=>{const y=l,F=He(y,K);ye(y),ue(F),Z(Be(y,F,J))},children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(ie,{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(oe,{value:J,onValueChange:l=>Z(l),children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(ie,{children:[e.jsx(L,{value:"queue",children:"Queue"}),e.jsx(L,{value:"coalesce",children:"Combine waiting events"}),!w&&q==="turn"&&K==="reply_to_source"&&we?.capabilities?.steering?e.jsx(L,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,q==="window"&&(j==="time"||!w)?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(Rs,{"aria-label":"Skip unchanged windows",checked:je,onCheckedChange:Te})]}):null,j==="event"&&!w&&q==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Result"}),e.jsxs(oe,{value:K,onValueChange:l=>{const y=l;ue(y),Z(Be(q,y,J))},children:[e.jsx(ce,{children:e.jsx(re,{})}),e.jsxs(ie,{children:[we?.capabilities?.replyToSource?e.jsx(L,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(L,{value:"silent",children:"Save in Lobu"})]})]}),we?.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 $n=16;function ze(){return crypto.randomUUID()}function In(n){return n===void 0?[{key:ze(),initial:void 0}]:n.length===0?[{key:ze(),initial:null}]:n.map(s=>({key:ze(),initial:s}))}function xs(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function qn(n,s){return n?n.ready===s.ready&&n.kind===s.kind&&JSON.stringify(n.trigger)===JSON.stringify(s.trigger):!1}function Kn(n,s){const t=n.map(o=>s[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&t[0]?.kind==="manual")return{ready:t[0].ready,triggers:[]};const d=t.filter(xs).length;return{ready:!t.some(o=>o.kind==="manual")&&d<=1&&t.length>0&&t.every(o=>o.ready&&o.trigger),triggers:t.filter(o=>o.trigger).map(o=>o.trigger)}}function ya({organizationId:n,initialTriggers:s,onChange:t}){const i=r.useId(),[d,u]=r.useState(()=>In(s)),[c,o]=r.useState({}),f=r.useRef("");r.useEffect(()=>{const h=Kn(d,c),k=JSON.stringify(h);k!==f.current&&(f.current=k,t(h))},[d,c,t]);const N=d.find(h=>xs(c[h.key]))?.key??d.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,m=r.useCallback((h,k)=>{o(S=>qn(S[h],k)?S:{...S,[h]:k})},[]),g=()=>{const h=d[0],k=h?c[h.key]:void 0;if(d.length===1&&(k?.kind==="manual"||h?.initial===null)){const S=ze();o({}),u([{key:S,initial:void 0}]);return}u(S=>[...S,{key:ze(),initial:void 0}])},$=h=>{if(d.length<=1){const k=ze();o({}),u([{key:k,initial:null}]);return}o(k=>{const S={...k};return delete S[h],S}),u(k=>k.filter(S=>S.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${i}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${i}-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,k)=>{const S=d.length>1,O=S?N&&N!==h.key?["event"]:["event","time"]:["event","time","manual"],W=c[h.key],p=S||(W?W.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:R("space-y-3 rounded-lg border bg-card/40 p-3",S&&"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:S?`Trigger ${k+1}`:"Trigger"}),p?e.jsx(X,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":S?`Remove trigger ${k+1}`:"Clear trigger",onClick:()=>$(h.key),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Bn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:O,fieldIdPrefix:`${i}-${h.key}-`,onChange:m})]},h.key)})}),e.jsxs(X,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:g,disabled:d.length>=$n,children:[e.jsx(Ye,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Bn({slotKey:n,organizationId:s,initial:t,kinds:i,fieldIdPrefix:d,onChange:u}){const c=r.useCallback(o=>u(n,o),[u,n]);return e.jsx(Rn,{organizationId:s,initialTrigger:t,allowedKinds:i,showSectionHeader:!1,fieldIdPrefix:d,onChange:c})}const Ht={agents:!0,lobuEmbedded:!1};function Wn(){const{data:n}=Is({queryKey:["features"],queryFn:async()=>{const s=await qs(`${Ks}/api/features`);return s.ok?s.json():Ht},staleTime:3e4,refetchInterval:6e4});return n??Ht}const pt="__none__";function Xe(n){return`${n.connection_id}:${n.feed_key}`}function zn(n){const s=n.indexOf(":");if(s<=0)return null;const t=Number(n.slice(0,s)),i=n.slice(s+1);return!Number.isSafeInteger(t)||t<=0||!i?null:{connection_id:t,channel_id:i}}function ft(n){return n?`${n.connection_id}:${n.channel_id}`:""}function ot(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function Un(n){return n.connection_name?`connection ${n.connection_id} (${n.connection_name})`:`connection ${n.connection_id}`}function Xt(n,s){return n.store==="channel_messages"&&n.target_agent_id===s&&n.connection_status==="active"}function Vn({organizationId:n,agentId:s,value:t,onChange:i,disabled:d=!1,automationName:u,onPendingChange:c}){const{data:o=[],isLoading:f}=Bs(n),N=ft(t),[m,g]=r.useState(null),[$,h]=r.useState(!1),k=r.useRef(s),S=r.useMemo(()=>o.filter(v=>Xt(v,s)),[o,s]);r.useEffect(()=>{if(k.current===s)return;const v=k.current;if(k.current=s,g(null),h(!1),!v||t==null)return;const _=ft(t);if(_==="")return;o.some(E=>Xt(E,s)&&Xe(E)===_)||i(null)},[s,o,t,i]);const O=m??N,W=O===""?pt:O,p=S.find(v=>Xe(v)===O),M=m!==null&&m!==""&&m!==N;r.useEffect(()=>{c?.(M)},[M,c]);const j=p??(m?void 0:S.find(v=>Xe(v)===N)),le=v=>{const _=v===pt?"":v;if(_===""){g(null),h(!1),i(null);return}if(_===N){g(null),h(!1);return}g(_),h(!1)},I=v=>{if(h(v),v&&m){const _=zn(m);_&&(g(null),i(_))}else!v&&m&&g(null)},w=(t&&ft(t)!==""?t:void 0)??(p?{connection_id:p.connection_id,channel_id:p.feed_key}:void 0),Y=(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)"})]}),s?e.jsxs(oe,{value:W,onValueChange:le,disabled:d||f,children:[e.jsx(ce,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(re,{placeholder:f?"Loading bound channels…":S.length===0?"No bound chat channels":"No digest — runs stay silent"})}),e.jsxs(ie,{children:[e.jsx(L,{value:pt,children:"No digest — runs stay silent"}),S.map(v=>e.jsxs(L,{value:Xe(v),children:[ot(v)," · ",v.connector_key]},Xe(v)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),s&&!f&&S.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No active chat channels are bound to this agent yet. Link a private channel first, then select it here."}):null,M&&p?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:v=>I(v.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${ot(p)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:ot(p)}),". Destination changes are audited."]})]}):null,j||w?e.jsxs("div",{className:R(We,"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:j?`${j.connector_key} ${ot(j)} · ${Un(j)}`:`${w?.channel_id} · connection ${w?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[Y," 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 Yt=4096;function Qn({open:n,onOpenChange:s,initial:t,onSubmit:i}){const[d,u]=r.useState(""),[c,o]=r.useState(""),[f,N]=r.useState(null);r.useEffect(()=>{n&&(u(t?.name??""),o(t?.query??""),N(null))},[n,t]);const m=()=>{const $=d.trim(),h=c.trim();if(!$){N("Give the SQL source a name.");return}if(!h){N("Enter a query.");return}if(h.length>Yt){N(`Query is too long (${h.length} chars, max ${Yt}).`);return}i({name:$,query:h}),s(!1)},g=!!t;return e.jsx(Ws,{open:n,onOpenChange:s,children:e.jsxs(zs,{className:"max-w-2xl",children:[e.jsxs(Us,{children:[e.jsx(Vs,{children:g?"Edit SQL source":"SQL source"}),e.jsx(Qs,{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(ae,{id:"sql-source-name",value:d,onChange:$=>u($.target.value),placeholder:"recent_cancellations",autoFocus:!g}),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(Nt,{value:c,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),f?e.jsx("p",{className:"text-sm text-destructive",children:f}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(X,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(X,{onClick:m,children:g?"Save":"Add source"})]})]})})}const Jn=["skill","feed","connection","connector","metric","entity_type"];function Gn({value:n,onChange:s,library:t,pinned:i,required:d,error:u,owner:c,agentId:o,sources:f,onAddSources:N}){const m=bn(Jn,Bt,{skills:t,skillAgentId:o||null}),g=r.useRef(null),[$,h]=r.useState(null),k=r.useMemo(()=>{if(!f)return[];const p=new Set(f.map(M=>M.query.trim()));return Wt(n).filter(M=>!p.has(M.query.trim()))},[n,f]),S=kn(n),O=Sn(i.filter(p=>S.includes(p.name)),t),W=t.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)"})]}),S.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[S.length,"/",Bt," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(wn,{value:n,onChange:s,onSubmit:()=>{},submitOnEnter:!1,searchRefs:m,handleRef:g,onSqlRequest:()=>h({}),onSqlEdit:(p,M)=>h({initial:p,pos:M}),placeholder:W?"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(Qn,{open:$!==null,onOpenChange:p=>{p||h(null)},initial:$?.initial,onSubmit:p=>{g.current?.insertSql(p,$?.pos),h(null)}}),k.length>0&&N?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:[k.length===1?`"${k[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${k.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(X,{type:"button",variant:"outline",size:"sm",onClick:()=>N(Wt(n,f)),children:k.length===1?"Add as a source":"Add as sources"})]}):null,S.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:S.map(p=>{const M=O.includes(p),j=!t.some(le=>le.name===p);return e.jsxs(Js,{variant:j?"destructive":"secondary",className:"font-normal",children:[p,j?" · unavailable":M?" · newer text":null]},p)})}):null,O.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[O.length===1?`"${O[0]}" has been edited since this Automation pinned it.`:`${O.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,u?e.jsx("p",{className:"text-xs text-destructive",children:u}):null,!W&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Gs,{to:"/$owner/agents/$agentId",params:{owner:c,agentId:o},hash:"skills",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:W?"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 Hn=["connection","connector","feed","metric","entity_type"];function Xn({sources:n,onChange:s,disabled:t}){const{currentOwner:i,resolvedOrganizationId:d}=hs(),[u,c]=r.useState(""),{refs:o}=Cn({owner:i,organizationId:d,kinds:Hn,query:u,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Sources"}),e.jsx(Nn,{sources:n,disabled:t,onRemove:f=>s(n.filter(N=>N.query!==f.query))}),e.jsx("div",{className:"flex gap-2",children:e.jsx(it,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(X,{type:"button",variant:"outline",size:"sm",disabled:t,children:[e.jsx(Ye,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:f=>o.map(N=>e.jsxs(Ue,{value:`${N.label} ${N.kind}`,onSelect:()=>{s(En(N,n)),f()},children:[e.jsx("span",{className:"truncate text-sm",children:N.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:N.kind})]},`${N.kind}:${N.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 Yn({organizationId:n,value:s,onChange:t,className:i}){const{data:d=[]}=Hs(n),u=un(d),c=u.find(o=>o.id===s);return e.jsx(it,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(X,{variant:"outline",role:"combobox","aria-expanded":o,className:R("w-full justify-between",i),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs(Ue,{value:"all workspace",onSelect:()=>{t(void 0),o()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",s===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),u.map(f=>e.jsxs(Ue,{value:`${f.name} ${f.entityType}`,onSelect:()=>{t(f.id),o()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",s===f.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[f.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",f.entityType,")"]})]})]},f.id))]})})}function ct(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const s=n.slice(1,-1);return s?s.split(",").map(t=>t.trim()):[]}return[]}function Zt(n){return JSON.stringify(n,(s,t)=>t&&typeof t=="object"&&!Array.isArray(t)?Object.fromEntries(Object.keys(t).sort().map(i=>[i,t[i]])):t)}const Zn=vn.map(n=>({value:n,label:yn[n]})),es=[{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 ts(n){const s=!!(n?.prompt?.trim()||n?.skills?.some(i=>i.content.trim())),t=!!n?.reaction_script?.trim();return s&&t?"both":t?"code":"agent"}const ea=["text","number","date","boolean","json"],ta=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],vt=[{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 ss=0;function sa(){return ss+=1,`field-${ss}`}function gs(n={}){return{id:sa(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function Ze(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function na(n){return n?Object.keys(n).every(s=>["entity_type","entity_path","key_fields","key_output_field"].includes(s)):!0}function ns(n){return n?na(n.keying_config)?"fields":"json":"fields"}function as(n){const s=n?.keying_config?.entity_type;return typeof s=="string"?s:""}function os(n){const s=n?.keying_config?.entity_path;return typeof s=="string"&&s.trim()?s:"$"}function cs(n){const s=new Map,t=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const i of t){if(typeof i!="string")continue;const d=Ze(i);d&&s.set(d,gs({name:d,role:"key"}))}return Array.from(s.values())}function H(n,s){const t=n?.execution_config?.[s];return typeof t=="number"||typeof t=="string"?String(t):""}function rs(n,s,t){const i=n?.execution_config?.[s];return typeof i=="string"&&t.includes(i)?i:""}function yt(n,s){const t=n.trim();if(!t)return{};const i=Number(t);return Number.isFinite(i)?{value:i}:{error:`${s} must be a number.`}}function is({entityType:n,entityPath:s,fields:t}){const d=t.map(o=>({...o,name:Ze(o.name)})).filter(o=>o.name).filter(o=>o.role==="key").map(o=>o.name),u=Ze(n),c=s.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:c,key_fields:d,key_output_field:`${u}_key`}:void 0})}function aa(n,s){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:s})]})}function ls(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||ct(n?.tags).length)}function oa({organizationId:n,entityId:s,prefill:t,onSubmit:i,isSubmitting:d,error:u,isEditing:c,onCancel:o,triggerFields:f,submitLabel:N="Create Automation",submitDisabled:m=!1,triggers:g,savedTriggers:$=g,agentFirst:h=!1}){const{lobuEmbedded:k}=Wn(),{currentOwner:S}=hs(),{data:O=[]}=Xs(),{data:W=[]}=Ys(),[p,M]=r.useState(t?.managed_agent_id??""),j=!!t?.managed_agent_id&&!c,[le,I]=r.useState(t?.delivery_target??null),[de,w]=r.useState(!1),[Y,v]=r.useState(t?.device_worker_id??""),[_,Se]=r.useState(()=>{const a=It(t);return a==="manual"&&!c?"agent":a}),E=_==="external"||_==="script",ge=E&&c,[z,pe]=r.useState(t?.agent_kind??""),{data:fe=[]}=ds({organizationId:n}),[ve,Ne]=r.useState(t?.name??""),[q,ye]=r.useState(t?.slug??""),[K,ue]=r.useState(!!t?.slug),[J,Z]=r.useState(t?.description??""),[je,Te]=r.useState(t?.prompt??""),[Le,Me]=r.useState(!1),se=t?.skills??[],[x,me]=r.useState(t?.sources??[]),[U,te]=r.useState(t?.entity_id??s),[P,Pe]=r.useState(t?.reaction_script??""),[G,Ve]=r.useState(()=>ts(t)),[we,De]=r.useState(t?.keying_config?JSON.stringify(t.keying_config,null,2):""),[Oe,A]=r.useState(null),[Ae,Re]=r.useState(()=>ns(t)),[he,Ce]=r.useState(()=>as(t)),[$e,Ie]=r.useState(()=>os(t)),[Qe,xe]=r.useState(()=>cs(t)),[qe,et]=r.useState(t?.reactions_guidance??""),[Je,tt]=r.useState(()=>H(t,"timeout_seconds")),[st,kt]=r.useState(()=>H(t,"max_budget_usd")),[Fe,l]=r.useState(()=>H(t,"model")),[y,F]=r.useState(()=>rs(t,"permission_mode",vt.map(a=>a.value))),[ee,ne]=r.useState(()=>H(t,"effort")),[be,T]=r.useState(()=>H(t,"finalize_nudges")),[ke,V]=r.useState(null),[nt,St]=r.useState(ct(t?.tags).join(", ")),[lt,wt]=r.useState(""),[dt,Ct]=r.useState(!!(c||ls(t)));r.useEffect(()=>{if(!t)return;Ne(t.name??""),ye(t.slug??""),ue(!!t.slug),Z(t.description??""),Te(t.prompt??""),Me(!1),me(t.sources??[]),te(t.entity_id??s),v(t.device_worker_id??"");const a=It(t);Se(a==="manual"&&!c?"agent":a),pe(t.agent_kind??""),Pe(t.reaction_script??""),Ve(ts(t)),De(t.keying_config?JSON.stringify(t.keying_config,null,2):""),A(null),Re(ns(t)),Ce(as(t)),Ie(os(t)),xe(cs(t)),et(t.reactions_guidance??""),tt(H(t,"timeout_seconds")),kt(H(t,"max_budget_usd")),l(H(t,"model")),F(rs(t,"permission_mode",vt.map(C=>C.value))),ne(H(t,"effort")),T(H(t,"finalize_nudges")),V(null),St(ct(t.tags).join(", ")),wt(""),M(t.managed_agent_id??""),I(t.delivery_target??null),Ct(!!(c||ls(t)))},[t,s,c]);const ps=K?q:qt(ve),{data:fs}=Zs(p||null),{data:vs}=en(p||null,{enabled:!!p}),ut=_n(fs??null,vs?.catalog??[]),ys=On(g),mt=P.trim().length>0,Ge=!c&&G==="code"?"":je,js=!c&&G==="agent"?void 0:P.trim()||void 0,Et=_==="script"||(c||G==="code")&&mt,Ot=An(Ge,ut,g,Et),_s=Le||Ge.trim()!==""?Ot:null,At=Fn(Ge,ut),ht=[["Name",t?.name??"",ve],["Description",t?.description??"",J],["Instructions",t?.prompt??"",Ge],["Sources",t?.sources??[],x],["Triggers",$??[],g??[]],["Reaction script",t?.reaction_script??"",P],["Reactions guidance",t?.reactions_guidance??"",qe],["Agent",t?.managed_agent_id??null,_==="manual"?null:p||null],["Device",t?.device_worker_id??null,_==="device"&&Y||null],["Device runtime",t?.agent_kind??null,_==="device"&&z||null],["Delivery target",t?.delivery_target??null,le],["Timeout seconds",H(t,"timeout_seconds"),Je],["Budget USD",H(t,"max_budget_usd"),st],["Model",H(t,"model"),Fe],["Permission mode",H(t,"permission_mode"),y],["Effort",H(t,"effort"),ee],["Finalize nudges",H(t,"finalize_nudges"),be],["Tags",ct(t?.tags),nt.split(",").map(a=>a.trim()).filter(Boolean)],["Change notes","",lt]].filter(([,a,C])=>Zt(a)!==Zt(C)),Ft=!c&&G!=="agent",Ke=h&&!c,Tt=_==="device"||_==="script"||Ke&&_==="agent",Ns=Tt&&!p.trim(),xt=O.length===1?O[0]?.agentId:void 0;r.useEffect(()=>{Ke&&_==="agent"&&!p&&xt&&M(xt)},[Ke,_,p,xt]);const Lt=!!ve.trim()&&!Ns&&!Ot&&(!Ft||mt)&&!de,bs=ys&&!Et&&At.length===0,ks=()=>{if(E&&!c){V("Choose a native agent or code module before creating a copy of a legacy Automation.");return}if(!Lt)return;let a;if(!c&&Ae==="fields"){const _e=is({entityType:he,entityPath:$e,fields:Qe});if(_e.error){A(_e.error);return}a=_e.keyingConfig,A(null)}else if(!c){if(we.trim())try{const _e=JSON.parse(we);if(typeof _e!="object"||Array.isArray(_e)){A("Keying config must be a JSON object.");return}a=_e}catch{A("Invalid JSON. Please check the syntax.");return}A(null)}const C=yt(Je,"Timeout");if(C.error){V(C.error);return}if(C.value!==void 0&&(!Number.isInteger(C.value)||C.value<1)){V("Timeout must be a whole number greater than 0.");return}const B=yt(st,"Budget");if(B.error){V(B.error);return}if(B.value!==void 0&&B.value<0){V("Budget cannot be negative.");return}const D=yt(be,"Finalize nudges");if(D.error){V(D.error);return}if(D.value!==void 0&&(!Number.isInteger(D.value)||D.value<0||D.value>5)){V("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...Object.fromEntries(Object.entries(t?.execution_config??{}).filter(([_e])=>!["timeout_seconds","max_budget_usd","model","permission_mode","effort","finalize_nudges"].includes(_e))),...C.value!==void 0?{timeout_seconds:C.value}:{},...B.value!==void 0?{max_budget_usd:B.value}:{},...Fe.trim()?{model:Fe.trim()}:{},...y?{permission_mode:y}:{},...ee.trim()?{effort:ee.trim()}:{},...D.value!==void 0?{finalize_nudges:D.value}:{}},Q=E?void 0:Object.keys(Ee).length>0||c?Ee:void 0;V(null);const ws=nt.trim()?nt.split(",").map(_e=>_e.trim()).filter(Boolean):c?[]:void 0;i({slug:ps,name:ve.trim(),description:c?J.trim():J.trim()||void 0,prompt:Ge,skills:At,entity_id:U,sources:x,reaction_script:js,keying_config:a,reactions_guidance:c?qe.trim():qe.trim()||void 0,execution_config:Q,tags:ws,outputs:t?.outputs,change_notes:lt.trim()||void 0,managed_agent_id:ge?t?.managed_agent_id??null:_==="manual"?null:p.trim()||null,device_worker_id:_==="device"&&Y.trim()||null,agent_kind:_==="device"&&z.trim()||null,delivery_target:le})},Mt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",Ft?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(Nt,{value:P,onChange:Pe,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),c?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Export ",e.jsx("code",{children:"prepare"})," to save sources before analysis and a default handler to run after completion. A module without agent instructions, extraction input or outputs runs without an LLM."]})]}),Pt=!j&&!ge&&_!=="manual"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-agent-id",children:[E?"Owning agent":"Agent",Tt&&e.jsx("span",{className:"text-destructive",children:" *"})]}),k?e.jsxs(oe,{value:p,onValueChange:M,disabled:O.length===0,children:[e.jsx(ce,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(re,{placeholder:O.length===0?"No agents yet":"Select a Lobu agent"})}),e.jsx(ie,{children:O.map(a=>e.jsxs(L,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:p,onChange:a=>{M(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"}),_==="device"?e.jsx("p",{className:"text-xs text-muted-foreground",children:"The device run uses this agent's memory and tools, acting as the agent's owner."}):Ke?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This agent answers the conversation's messages."}):null]}):null,Ss=O.find(a=>a.agentId===p)?.name??p;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:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>ue(!K),className:"text-xs text-muted-foreground hover:text-foreground",children:K?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:ve,onChange:a=>Ne(a.target.value),placeholder:"e.g., Escalation signals"}),!c&&K?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:q,onChange:a=>ye(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:qt(ve)||"custom-slug"})]}):null]})}),Ke?j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Agent"}),e.jsx("p",{className:"text-sm",children:Ss})]}):Pt:null,c?null:e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"How does this run?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:es.map(a=>e.jsx("button",{type:"button","aria-pressed":G===a.value,onClick:()=>Ve(a.value),className:R("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",G===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:es.find(a=>a.value===G)?.hint})]}),c||G!=="code"?e.jsx(Gn,{value:je,onChange:a=>{Me(!0),Te(a)},library:ut,pinned:se,required:bs,error:_s,owner:S??"",agentId:p,sources:c?x:void 0,onAddSources:c?me:void 0}):null,!c&&G!=="agent"?Mt:null,c?e.jsx(Xn,{sources:x,onChange:me,disabled:d}):null,e.jsx("div",{className:"space-y-4",children:f}),e.jsx(Vn,{organizationId:n,agentId:_==="agent"?p.trim():"",value:le,onChange:I,disabled:d,automationName:ve,onPendingChange:w}),de?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(X,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":dt,"aria-controls":"automation-advanced-settings",onClick:()=>Ct(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(tn,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(us,{className:R("h-4 w-4 transition-transform",dt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:R("space-y-4",!dt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-description",children:"Description"}),e.jsx(ae,{id:"scratch-description",value:J,onChange:a=>Z(a.target.value),placeholder:"What this automation does"})]}),!c&&!s&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity scope"}),e.jsx(Yn,{organizationId:n,value:U,onChange:te}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?Mt:null,c?e.jsxs("section",{"aria-label":"Legacy output configuration",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Legacy output keying is read-only here. This editor cannot save changes to it."}),t?.keying_config?e.jsx(Kt,{before:null,after:t.keying_config}):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(X,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(Ae==="fields"){const a=is({entityType:he,entityPath:$e,fields:Qe});if(a.error){A(a.error);return}De(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Re("json")}else Re("fields");A(null)},children:Ae==="fields"?"Edit JSON":"Use fields"})]}),Ae==="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(it,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(X,{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:R("truncate",!he&&"text-muted-foreground"),children:he||"Select entity type"}),e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,C)=>{const B=Ze(C),D=fe.filter(Q=>!Q.backing_sql),Ee=D.some(Q=>Q.slug===B);return e.jsxs(e.Fragment,{children:[D.map(Q=>e.jsxs(Ue,{value:`${Q.name??Q.slug} ${Q.slug}`,onSelect:()=>{Ce(Q.slug),A(null),a()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",he===Q.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:Q.slug}),Q.name&&Q.name!==Q.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:Q.name})]})]},Q.slug)),B&&!Ee&&e.jsxs(Ue,{value:C,onSelect:()=>{Ce(B),A(null),a()},className:"cursor-pointer",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:B})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(ae,{id:"scratch-output-path",value:$e,onChange:a=>{Ie(a.target.value),A(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(X,{type:"button",variant:"outline",size:"sm",onClick:()=>{xe(a=>[...a,gs()]),A(null)},children:[e.jsx(Ye,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),Qe.length===0?e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:Qe.map(a=>e.jsxs("div",{className:R(We,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:C=>{const B=Ze(C.target.value);xe(D=>D.map(Ee=>Ee.id===a.id?{...Ee,name:B}:Ee)),A(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(oe,{value:a.type,onValueChange:C=>{xe(B=>B.map(D=>D.id===a.id?{...D,type:C}:D))},children:[e.jsx(ce,{"aria-label":"Output field type",children:e.jsx(re,{})}),e.jsx(ie,{children:ea.map(C=>e.jsx(L,{value:C,children:C},C))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:ta.map(C=>e.jsx("button",{type:"button",onClick:()=>{xe(B=>B.map(D=>D.id===a.id?{...D,role:C.value}:D)),A(null)},className:R("rounded-sm px-2 py-1 text-xs transition-colors",a.role===C.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:C.label},C.value))}),e.jsx(X,{type:"button",variant:"ghost",size:"icon",onClick:()=>{xe(C=>C.filter(B=>B.id!==a.id)),A(null)},"aria-label":"Remove output field",children:e.jsx(ms,{className:"h-4 w-4"})})]},a.id))})]}),Oe&&e.jsx("p",{className:"text-xs text-destructive",children:Oe})]}):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(Nt,{value:we,onChange:a=>{De(a),A(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),Oe&&e.jsx("p",{className:"text-xs text-destructive",children:Oe})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(sn,{id:"scratch-reactions-guidance",value:qe,onChange:a=>et(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:[aa("Run settings","Choose where the automation runs and the budget it can use."),E?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Runs on"}),e.jsx("p",{className:"text-sm",children:_==="external"?"External executor":"Script"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This executor is configured outside this editor."}),ge&&e.jsxs(e.Fragment,{children:[e.jsx(b,{children:"Owning agent"}),e.jsx("p",{className:"text-sm",children:p||"None assigned"})]})]}):!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(oe,{value:_,onValueChange:a=>Se(a),children:[e.jsx(ce,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(re,{})}),e.jsxs(ie,{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:_==="agent"?"Automated runs dispatch to a managed Lobu agent.":_==="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."})]}),!Ke&&Pt,!j&&_==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(oe,{value:Y||"__unselected__",onValueChange:a=>v(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(ie,{children:W.map(a=>e.jsx(L,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!j&&_==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(oe,{value:z||"__default__",onValueChange:a=>pe(a==="__default__"?"":a),children:[e.jsx(ce,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(re,{placeholder:"Device default"})}),e.jsxs(ie,{children:[e.jsx(L,{value:"__default__",children:"Device default"}),Zn.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&&e.jsxs(e.Fragment,{children:[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(jn,{value:Fe,onChange:a=>{l(a),V(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(ae,{id:"scratch-timeout",type:"number",min:1,max:86400,value:Je,onChange:a=>{tt(a.target.value),V(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(oe,{value:y||"__default__",onValueChange:a=>{F(a==="__default__"?"":a),V(null)},children:[e.jsx(ce,{id:"scratch-permission-mode",children:e.jsx(re,{placeholder:"Default"})}),e.jsxs(ie,{children:[e.jsx(L,{value:"__default__",children:"Default"}),vt.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(ae,{id:"scratch-effort",value:ee,onChange:a=>{ne(a.target.value),V(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(ae,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:be,onChange:a=>{T(a.target.value),V(null)},placeholder:"Default"})]})]}),ke&&e.jsx("p",{className:"text-xs text-destructive",children:ke})]})]}),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(ae,{id:"scratch-tags",value:nt,onChange:a=>St(a.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(ae,{id:"scratch-change-notes",value:lt,onChange:a=>wt(a.target.value),placeholder:"What changed in this version?"})]})]})]}),(E&&ke||u&&!Oe&&!ke)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:E&&ke?ke:u}),c&&ht.length>0?e.jsxs("section",{"aria-label":"Review changes",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Review changes"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saved values compared with this draft. Only changed fields are shown."}),e.jsx(Kt,{before:Object.fromEntries(ht.map(([a,C])=>[a,C])),after:Object.fromEntries(ht.map(([a,,C])=>[a,C]))})]}):null,e.jsx(_t,{onCancel:o,children:e.jsx(X,{onClick:ks,disabled:!Lt||d||m,children:d?e.jsxs(e.Fragment,{children:[e.jsx(nn,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":N})})]})}function ca(n,s){const t=n??null,i=s??null;return t===null||i===null?t===i:t.connection_id===i.connection_id&&t.channel_id===i.channel_id}function ra(n){const s=n.detail??{};return{name:n.name,slug:s.slug,description:s.description??n.description??void 0,prompt:s.prompt,triggers:s.triggers,sources:s.sources,keying_config:s.keying_config,reactions_guidance:s.reactions_guidance,reaction_script:s.reaction_script,model_config:s.model_config,execution_config:s.execution_config,tags:s.tags,outputs:s.outputs}}function ja({startFromScratch:n=!1,onClose:s,hideCancel:t=!1,hideHeader:i=!1,organizationId:d,entityId:u,entityName:c,prefillAgentId:o,conversationSetup:f,onSuccess:N,editingAutomation:m,catalogPrefill:g,onDraft:$,triggerFields:h,submitLabel:k,submitDisabled:S,createFields:O,onPrefillTriggers:W}){const p=mn(),M=hn(),j=xn(),le=gn(),I=!!m,[de,w]=r.useState(n?"scratch":"template"),[Y,v]=r.useState(void 0),[_,Se]=r.useState(void 0),{data:E=[],isLoading:ge}=pn(),[z,pe]=r.useState(""),fe=f?.name,ve=r.useMemo(()=>o||fe?{...fe?{name:fe}:{},...o?{managed_agent_id:o}:{}}:void 0,[o,fe]),Ne=r.useMemo(()=>E.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[E]),q=r.useMemo(()=>Ne.filter(x=>x.name.toLowerCase().includes(z.toLowerCase())||x.description.toLowerCase().includes(z.toLowerCase())),[Ne,z]),ye=x=>{const me=E.find(te=>te.id===x.key);if(!me)return;const U=ra(me);Se(o?{...U,managed_agent_id:o}:U),W?.(U.triggers??[]),w("scratch")},K=()=>{p.reset(),M.reset(),w("template"),v(void 0),Se(void 0),s()},ue=I?O?.triggers??m.triggers??[]:O?.triggers??_?.triggers??g?.triggers??[],J=async x=>{try{if($){await $(x);return}if(I){const me=O?.triggers??m.triggers??[],U=m.reaction_script??"",te=x.reaction_script??"";te&&te!==U&&await j.mutateAsync({automation_id:m.automation_id,reaction_script:te}),await M.mutateAsync({automation_id:m.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:me,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!te&&U&&await j.mutateAsync({automation_id:m.automation_id,reaction_script:""});const P={};x.model_config!==void 0&&(P.model_config=x.model_config),x.execution_config!==void 0&&(P.execution_config=x.execution_config),x.tags!==void 0&&(P.tags=x.tags),x.delivery_target!==void 0&&!ca(x.delivery_target,m.delivery_target)&&(P.delivery_target=x.delivery_target),x.managed_agent_id!==void 0&&(P.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(P.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(P.device_worker_id=x.device_worker_id||null),Object.keys(P).length>0&&await le.mutateAsync({automation_id:m.automation_id,...P}),K(),N?.(m.automation_id)}else{const me=O?.triggers??_?.triggers??g?.triggers??[],U=await p.mutateAsync({...x,managed_agent_id:x.managed_agent_id??void 0,device_worker_id:x.device_worker_id??void 0,agent_kind:x.agent_kind??void 0,delivery_target:x.delivery_target??void 0,triggers:me});K(),U.automation_id&&N?.(U.automation_id)}}catch{}},Z=I?M:p;let je="Add an automation";I?je="Edit automation configuration (saves as a new version)":c&&(je=`Add an automation for ${c}`);const Te=r.useMemo(()=>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,[m]),Le=I?"Edit Automation":"Create Automation",Me=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:Le}),e.jsx("p",{className:"text-sm text-muted-foreground",children:je})]}),se=e.jsxs("div",{className:"py-6 space-y-6",children:[!I&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(jt,{active:de==="template",onClick:()=>w("template"),icon:e.jsx(an,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(jt,{active:de==="scratch",onClick:()=>{w("scratch"),v(void 0),Se(void 0)},icon:e.jsx(Ye,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(jt,{active:de==="clone",onClick:()=>w("clone"),icon:e.jsx(on,{className:"h-4 w-4"}),label:"Clone existing"})]}),!I&&de==="template"?e.jsxs(e.Fragment,{children:[ge?e.jsx(cn,{}):e.jsx(rn,{items:q,searchQuery:z,onSearchChange:pe,onSelect:ye,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:Ne.length===0?"No automation templates available.":void 0}),i&&!t?e.jsx(_t,{onCancel:K}):null]}):!I&&de==="clone"&&!Y?e.jsxs(e.Fragment,{children:[e.jsx(ia,{organizationId:d,onSelect:x=>{v(x),W?.(x.triggers??[]),w("scratch")}}),i&&!t?e.jsx(_t,{onCancel:K}):null]}):e.jsx(oa,{organizationId:d,entityId:u,prefill:Te??Y??_??g??ve,onSubmit:J,isSubmitting:Z.isPending,error:Z.error?Z.error.message:null,isEditing:I,onCancel:t?void 0:K,triggerFields:h,submitLabel:k,submitDisabled:S,triggers:ue,savedTriggers:m?.triggers,agentFirst:!!f})]});return e.jsxs("div",{className:"flex flex-col",children:[i?null:Me,se]})}function jt({active:n,onClick:s,icon:t,label:i}){return e.jsxs("button",{type:"button",onClick:s,className:R("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:[t,i]})}function ia({organizationId:n,onSelect:s}){const{data:t,isLoading:i}=fn(n),[d,u]=r.useState(""),c=(t||[]).filter(o=>o.name?.toLowerCase().includes(d.toLowerCase()));return i?e.jsx(ln,{label:"automations",variant:"list-picker",rows:4}):!t||t.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:[c.map(o=>e.jsxs("button",{type:"button",onClick:()=>s({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,outputs:o.outputs}),className:"w-full text-left rounded-md border p-3 hover:border-primary/50 hover:bg-primary/5 transition-colors",children:[e.jsx("p",{className:"text-sm font-medium",children:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{ya as A,ja as C};
3
+ //# sourceMappingURL=create-automation-form-BhujNbRr.js.map
@@ -0,0 +1,2 @@
1
+ import{c as A,r as t,j as e,dh as I,T as g,U as F,eK as P,bI as R,B as L,i as $,dN as E,hF as M,hG as T,jv as B}from"./index-C2TCKJDP.js";import{u as D,c as H,f as K}from"./agent-skill-context-B0ZYVE3n.js";import{A as Q,a as z}from"./agent-subpage-shell-ByU0xhXn.js";import{a as k}from"./skill-route-key-sF006xiz.js";import"./core.esm-6koO33th.js";import"./skill-editor-D_W3QlRz.js";function G({owner:a,agentId:l}){const r=A(),[o,x]=t.useState(""),[p,c]=t.useState(!1),[n,f]=t.useState(""),[u,j]=t.useState(""),{skillRows:d,catalog:m,isLoading:S,addSkillFromCatalog:C,addCustomSkill:v}=D(),h=t.useMemo(()=>new Set(d.map(s=>s.repo)),[d]),i=t.useMemo(()=>H(m?.catalog??[],h),[m?.catalog,h]),N=t.useMemo(()=>K(i,o),[i,o]),w=s=>{C(s),r({to:"/$owner/agents/$agentId",params:{owner:a,agentId:l},search:{skill:k(s)},hash:"skills"})},y=()=>{const s=v({name:n,instructions:u});s&&r({to:"/$owner/agents/$agentId",params:{owner:a,agentId:l},search:{skill:k(s)},hash:"skills"})},b=e.jsx(Q,{title:"Add a skill",description:"Skills bundle instructions, tools, and knowledge an agent can reuse. Pick one from the catalog or create your own."});return e.jsxs("div",{className:"space-y-6",children:[b,e.jsx("div",{className:$(E,"w-full"),children:p?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"custom-skill-name",children:"Name"}),e.jsx(F,{id:"custom-skill-name",value:n,onChange:s=>f(s.target.value),placeholder:"my-skill"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"custom-skill-instructions",children:"Instructions"}),e.jsx(P,{id:"custom-skill-instructions",value:u,onChange:s=>j(s.target.value),placeholder:"Instructions for the agent when this skill is active...",rows:3})]})]}),e.jsx(R,{onCancel:()=>c(!1),children:e.jsx(L,{type:"button",size:"sm",onClick:y,disabled:!n.trim(),children:"Add custom skill"})})]}):e.jsxs("button",{type:"button",className:"flex w-full items-center gap-3 p-3 text-left text-muted-foreground transition-colors hover:text-foreground",onClick:()=>c(!0),children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted",children:e.jsx(I,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Create custom skill"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define instructions and packages"})]})]})}),S?e.jsx(M,{}):e.jsx(T,{items:N,searchQuery:o,onSearchChange:x,onSelect:s=>w(s.key),searchPlaceholder:"Search skills...",searchAriaLabel:"Search skills",emptyMessage:o.trim()?`No skills match "${o}"`:i.length===0?"All catalog skills are already configured":"No skills available"})]})}function O({owner:a,agentId:l}){return e.jsx(z,{children:e.jsx(G,{owner:a,agentId:l})})}function W(){const{owner:a,agentId:l}=B.useParams();return e.jsx(O,{owner:a,agentId:l})}export{W as component};
2
+ //# sourceMappingURL=create-kUevP9Xx.js.map
@@ -0,0 +1,2 @@
1
+ import{je as o,j as t,hY as r}from"./index-C2TCKJDP.js";function a(){const{owner:n,connectorKey:e}=o.useParams();return t.jsx(r,{owner:n,initialConnectorKey:e})}export{a as component};
2
+ //# sourceMappingURL=create._connectorKey-N6fhcIPy.js.map
@@ -0,0 +1,2 @@
1
+ import{r as m,j as e,T as u,U as g,bg as A,bh as F,bi as L,bj as _,bk as D,eK as O,B as S}from"./index-C2TCKJDP.js";import{M as B}from"./model-selector-BrfaDwIg.js";const R=[{value:"input",label:"Input",hint:"the user message, before the agent runs"},{value:"output",label:"Output",hint:"the agent's reply, before the user sees it"},{value:"pre-tool",label:"Pre-tool",hint:"a tool call, before it executes"},{value:"egress",label:"Egress",hint:"an outbound request to a judged domain"}];function J({initial:t,judgeModelDefault:a,submitLabel:r,submitting:s,onSubmit:i,onCancel:o}){const[d,n]=m.useState(t?.name??""),[c,k]=m.useState(t?.stage??"input"),[b,E]=m.useState(t?.policy??""),[y,T]=m.useState(t?.model??""),[p,f]=m.useState((t?.tools??[]).join(", ")),[x,G]=m.useState((t?.domains??[]).join(", ")),j=t?.kind,h=j==="require-tool",w=l=>{l.preventDefault();const N=p.split(",").map(v=>v.trim()).filter(Boolean);i({name:d,stage:c,...j?{kind:j}:{},policy:b,model:y.trim()||void 0,tools:(h||c==="pre-tool")&&N.length>0?N:void 0,domains:c==="egress"&&x.trim()?x.split(",").map(v=>v.trim()).filter(Boolean):void 0,enabled:t?.enabled??!0})};return e.jsxs("form",{onSubmit:w,className:"space-y-5",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(u,{htmlFor:"guardrail-name",children:["Name ",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(g,{id:"guardrail-name",value:d,onChange:l=>n(l.target.value),placeholder:"no-competitor-mentions",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Shown in the list and on every trip. Must be unique."})]}),h?null:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(u,{htmlFor:"guardrail-stage",children:"Stage"}),e.jsxs(A,{value:c,onValueChange:l=>k(l),disabled:s,children:[e.jsx(F,{id:"guardrail-stage",children:e.jsx(L,{})}),e.jsx(_,{children:R.map(l=>e.jsxs(D,{value:l.value,children:[l.label," — ",l.hint]},l.value))})]})]}),h?e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(u,{htmlFor:"guardrail-required-tools",children:["Required tools ",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(g,{id:"guardrail-required-tools",value:p,onChange:l=>f(l.target.value),placeholder:"suggest_actions",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Comma-separated. The turn trips if the agent finishes without calling every one of these. No judge model runs — this is a lookup against the tools the turn actually used."})]}):null,h?null:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(u,{htmlFor:"guardrail-policy",children:["Policy ",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(O,{id:"guardrail-policy",rows:5,value:b,onChange:l=>E(l.target.value),placeholder:"Deny any response that names a competitor (Acme, Globex) or quotes their pricing.",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"A judge model reads this and the text at the chosen stage, then allows or denies. Write it as an instruction to a reviewer."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(u,{htmlFor:"guardrail-model",children:["Judge model",a?null:e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(B,{value:y,onChange:T,placeholder:a?`Default (${a})`:"Select a model",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a?"Optional. Leave blank to use the gateway's default judge model.":"Required: the gateway has no default judge model (EGRESS_JUDGE_MODEL is unset)."})]})]}),!h&&c==="pre-tool"?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(u,{htmlFor:"guardrail-tools",children:"Tool scope"}),e.jsx(g,{id:"guardrail-tools",value:p,onChange:l=>f(l.target.value),placeholder:"github.delete_repo, fs.delete",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Optional, comma-separated. Leave blank to judge every tool call."})]}):null,c==="egress"?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(u,{htmlFor:"guardrail-domains",children:"Domains"}),e.jsx(g,{id:"guardrail-domains",value:x,onChange:l=>G(l.target.value),placeholder:"api.github.com, .slack.com",disabled:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Comma-separated hostnames this judge gates — exact (api.github.com) or wildcard (.slack.com). Leave blank to route nothing."})]}):null,e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:justify-end",children:[o?e.jsx(S,{type:"button",variant:"outline",onClick:o,disabled:s,children:"Cancel"}):null,e.jsx(S,{type:"submit",disabled:s,children:s?"Saving…":r})]})]})}function q(t){return t.kind==="require-tool"}function $(t,a,r,s,i){const o=t.name.trim();return o?/^[a-zA-Z0-9][a-zA-Z0-9 _-]*$/.test(o)?r.includes(o)?`"${o}" is a built-in guardrail name — pick another.`:a.some(n=>n.name===o&&n.name!==i)?`A custom guardrail named "${o}" already exists.`:q(t)?t.stage!=="output"?"A required-tool guardrail only runs at the output stage.":t.tools?.some(n=>n.trim())?null:"List at least one tool that must be used.":t.policy.trim()?!s&&!t.model?.trim()?"Judge model is required — the gateway has no default (EGRESS_JUDGE_MODEL is unset).":null:"Policy is required.":"Name may use letters, numbers, spaces, hyphens, and underscores.":"Name is required."}function C(t){const a=q(t),s=(a||t.stage==="pre-tool")&&t.tools&&t.tools.length>0?t.tools.map(n=>n.trim()).filter(Boolean):void 0,i=t.stage==="egress"&&t.domains&&t.domains.length>0?t.domains.map(n=>n.trim()).filter(Boolean):void 0,o=t.model?.trim()||void 0,d=t.policy.trim();return{name:t.name.trim(),enabled:t.enabled,stage:t.stage,...a?{kind:"require-tool"}:{},...a?d?{policy:d}:{}:{policy:d},...o?{model:o}:{},...s&&s.length>0?{tools:s}:{},...i&&i.length>0?{domains:i}:{}}}function z(t,a){return[...t,C(a)]}function M(t,a,r){return t.map(s=>s.name===a?C(r):s)}function U(t,a){return t.filter(r=>r.name!==a)}function V(t,a,r){return t.map(s=>s.name===a?{...s,enabled:r}:s)}export{J as A,z as a,U as r,V as s,M as u,$ as v};
2
+ //# sourceMappingURL=custom-guardrail-edits-B_aCgvoZ.js.map
@@ -0,0 +1,2 @@
1
+ import{r as y,j as e,cz as fe,T as h,eK as v,U as w,a6 as je,bg as be,bh as ye,bi as Ne,bj as ve,bk as L,ft as we,bp as M,fu as Te,fv as $,fw as Ce,fx as Me,fy as Se,fz as Ie,fA as G,bs as Ae,B as _e}from"./index-C2TCKJDP.js";import{A as Fe,J as $e}from"./json-diff-CJK-gzCt.js";import{S as De}from"./schema-value-CefbtPIY.js";import{C as Re}from"./code-editor-UppEMWpt.js";const Ee=72,Oe=2e3;function Pe({value:s,onChange:t,section:a="all",create:r=!1,disabled:l=!1,loading:m=!1,modelsEditor:d,sandboxes:x=[],includedFields:g}){const o=y.useId(),i=n=>!g||g.includes(n),{name:c,description:f,identityMd:te,soulMd:ne,userMd:ae,models:re,showToolCalls:ie,sandboxId:I,starters:A}=s,j=(n,b)=>t?.({...s,[n]:b}),oe=n=>j("name",n),de=n=>j("description",n),le=n=>j("identityMd",n),ce=n=>j("soulMd",n),ue=n=>j("userMd",n),me=n=>j("showToolCalls",n),xe=n=>j("sandboxId",n),E=n=>j("starters",n),O=r,p=l||!t,he=m,pe=r||a==="settings"||a==="all",ge=!r&&(a==="identity"||a==="settings"||a==="all"),P=!r&&(a==="settings"||a==="all"),k=!r&&(a==="models"||a==="all");return e.jsxs("div",{className:"grid content-start gap-4 py-2",children:[ge?he?e.jsx(fe,{rows:4}):e.jsxs(e.Fragment,{children:[i("identityMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-identity-md`,children:"Identity"}),e.jsx(v,{id:`${o}-identity-md`,rows:6,value:te,onChange:n=>le(n.target.value),readOnly:p,placeholder:"You are a market intelligence agent. Track competitors, analyze launches and signals, and surface concise, decision-ready insights."})]}):null,i("soulMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-soul-md`,children:"Soul"}),e.jsx(v,{id:`${o}-soul-md`,rows:6,value:ne,onChange:n=>ce(n.target.value),readOnly:p,placeholder:"Be rigorous, skeptical of weak signals, and calm under ambiguity. Prefer crisp summaries, explicit evidence, and clear confidence levels."})]}):null,i("userMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-user-md`,children:"User prompt"}),e.jsx(v,{id:`${o}-user-md`,rows:6,value:ae,onChange:n=>ue(n.target.value),readOnly:p,placeholder:"Monitor the market for notable competitor moves, pricing changes, launches, partnerships, and customer sentiment shifts. Summarize what changed, why it matters, and what to watch next."})]}):null]}):null,pe?e.jsxs(e.Fragment,{children:[i("name")?e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(h,{htmlFor:`${o}-agent-name`,children:["Name ",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(w,{id:`${o}-agent-name`,placeholder:"Support Bot",value:c,onChange:n=>oe(n.target.value),readOnly:p,required:!0}),O?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The agent ID will be generated automatically from the name."}):null]}):null,O||!i("description")?null:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-agent-description`,children:"Description"}),e.jsx(v,{id:`${o}-agent-description`,placeholder:"Handles customer support and triage across channels.",value:f,onChange:n=>de(n.target.value),readOnly:p,rows:3})]})]}):null,P&&i("showToolCalls")?e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/20 p-3",children:[e.jsx(je,{id:`${o}-show-tool-calls`,checked:ie,onCheckedChange:n=>me(n===!0),disabled:p,className:"mt-0.5"}),e.jsxs("div",{className:"grid gap-0.5",children:[e.jsx(h,{htmlFor:`${o}-show-tool-calls`,className:"cursor-pointer",children:"Show tool calls in chat"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Render the agent's tool invocations (name, arguments, and result) as cards in the web chat. Off by default."})]})]}):null,P&&i("starters")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{children:"Conversation starters"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Up to three prompts offered on a new chat, on the web and in Slack. The message is sent as the user when tapped."}),A.map((n,b)=>e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[12rem_1fr]",children:[e.jsx(w,{"aria-label":`Starter ${b+1} title`,placeholder:"Plan this week",maxLength:Ee,value:n.title,onChange:_=>E(A.map((N,F)=>F===b?{...N,title:_.target.value}:N)),readOnly:p}),e.jsx(w,{"aria-label":`Starter ${b+1} message`,placeholder:"Plan this week's posts from what's trending",maxLength:Oe,value:n.message,onChange:_=>E(A.map((N,F)=>F===b?{...N,message:_.target.value}:N)),readOnly:p})]},b))]}):null,k&&i("models")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{children:"Models"}),d??e.jsx("ol",{className:"grid gap-2",children:re.map(n=>e.jsx("li",{className:"rounded-lg border px-3 py-2 text-sm",children:n},n))}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ordered list; the first is the default. Only these models may be used — a request for anything else falls back to the first available one. Leave empty to use the org default."})]}):null,k&&i("sandboxId")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-agent-sandbox`,children:"Run in sandbox"}),t?e.jsxs(be,{value:I,onValueChange:xe,disabled:p,children:[e.jsx(ye,{id:`${o}-agent-sandbox`,className:"w-full",children:e.jsx(Ne,{placeholder:"Built-in"})}),e.jsxs(ve,{children:[e.jsx(L,{value:"builtin",children:"Built-in (default)"}),x.map(n=>e.jsxs(L,{value:n.id,children:[n.name," (",n.providerKind,")",n.connected?"":" — no credential"]},n.id))]})]}):e.jsx(w,{"aria-label":"Run in sandbox",value:I==="builtin"?"Built-in (default)":I,readOnly:!0}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Where this agent's commands execute. Built-in runs in-process; sandboxes run on a connected provider. Manage sandboxes under Connect › Runtime."})]}):null]})}function z(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:{}}function u(s){return typeof s=="string"?s:""}function q(s){return Array.isArray(s)?s.map(z):[]}function ke(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function T({label:s,children:t}){return e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s}),t]})}function D({label:s,value:t,multiline:a=!1}){return e.jsxs(h,{className:"grid gap-2",children:[e.jsx("span",{children:s}),t===void 0?e.jsx("span",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):t===null?e.jsx("span",{className:"text-sm text-muted-foreground",children:"Not set"}):a?e.jsx(v,{value:u(t),readOnly:!0,rows:6}):e.jsx(w,{value:u(t),readOnly:!0})]})}function C({value:s}){return s===null?e.jsx("span",{className:"text-muted-foreground",children:"Not set"}):Array.isArray(s)?s.length?e.jsx("ol",{className:"grid gap-3",children:s.map((t,a)=>e.jsx("li",{className:"min-w-0 rounded-lg border p-3",children:e.jsx(C,{value:t})},a))}):e.jsx("span",{className:"text-muted-foreground",children:"Empty list"}):s&&typeof s=="object"?e.jsx("dl",{className:"grid gap-3",children:Object.entries(s).map(([t,a])=>e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t.replaceAll("_"," ")}),e.jsx("dd",{className:"min-w-0 whitespace-pre-wrap text-sm",children:e.jsx(C,{value:a})})]},t))}):s===""?e.jsx("span",{className:"text-muted-foreground",children:"Empty text"}):e.jsx(De,{value:s})}function K({value:s,omit:t}){const a=Object.entries(s).filter(([r])=>!t.includes(r));return a.length?e.jsx(T,{label:"Settings",children:e.jsx("dl",{className:"grid gap-4",children:a.map(([r,l])=>e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("dt",{className:"text-sm text-muted-foreground",children:r.replaceAll("_"," ")}),e.jsx("dd",{className:"min-w-0 text-sm",children:e.jsx(C,{value:l})})]},r))})}):null}function Ye({value:s}){const t=q(s.sources).map(a=>({name:u(a.name),query:u(a.query)}));return e.jsxs("div",{className:"grid gap-6 py-2 [&_.cm-content_span]:text-inherit",children:[e.jsx(D,{label:"Name",value:s.name}),e.jsx(D,{label:"Description",value:s.description}),e.jsx(D,{label:"Instructions",value:s.prompt,multiline:!0}),e.jsx(T,{label:"Sources",children:s.sources===void 0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):t.length?e.jsx(Fe,{sources:t,wrap:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No sources."})}),e.jsx(T,{label:"When",children:s.triggers===void 0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):Array.isArray(s.triggers)&&s.triggers.length?e.jsx(C,{value:s.triggers}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manual only."})}),s.outputs!==void 0?e.jsx(T,{label:"Outputs",children:e.jsx(C,{value:s.outputs})}):null,typeof s.reaction_script=="string"?e.jsx(T,{label:"Code",children:e.jsx(Re,{value:s.reaction_script,language:"typescript",readonly:!0})}):null,e.jsx(K,{value:s,omit:["name","description","prompt","sources","triggers","outputs","reaction_script"]})]})}function Qe({value:s}){const t=z(s.settings);return e.jsxs("div",{className:"grid gap-6",children:[e.jsx(Pe,{includedFields:[...s.name!==void 0?["name"]:[],...s.description!==void 0?["description"]:[],...s.identity_md!==void 0||s.identityMd!==void 0?["identityMd"]:[],...s.soul_md!==void 0||s.soulMd!==void 0?["soulMd"]:[],...s.user_md!==void 0||s.userMd!==void 0?["userMd"]:[],...s.models!==void 0||t.models!==void 0?["models"]:[],...s.showToolCalls!==void 0||t.showToolCalls!==void 0?["showToolCalls"]:[],...s.sandboxId!==void 0||t.sandboxId!==void 0?["sandboxId"]:[],...s.starters!==void 0?["starters"]:[]],value:{name:u(s.name),description:u(s.description),identityMd:u(s.identity_md??s.identityMd),soulMd:u(s.soul_md??s.soulMd),userMd:u(s.user_md??s.userMd),models:ke(s.models??t.models),showToolCalls:(s.showToolCalls??t.showToolCalls)===!0,sandboxId:u(s.sandboxId??t.sandboxId)||"builtin",starters:q(s.starters).map(a=>({title:u(a.title),message:u(a.message)}))}}),e.jsx(K,{value:s,omit:["name","description","identity_md","identityMd","soul_md","soulMd","user_md","userMd","models","showToolCalls","sandboxId","starters"]})]})}var S="Tabs",[Le]=Ae(S,[G]),U=G(),[Ve,R]=Le(S),H=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,onValueChange:l,defaultValue:m,orientation:d="horizontal",dir:x,activationMode:g="automatic",...o}=s,i=Me(x),[c,f]=Se({prop:r,onChange:l,defaultProp:m??"",caller:S});return e.jsx(Ve,{scope:a,baseId:Ie(),value:c,onValueChange:f,orientation:d,dir:i,activationMode:g,children:e.jsx(M.div,{dir:i,"data-orientation":d,...o,ref:t})})});H.displayName=S;var J="TabsList",W=y.forwardRef((s,t)=>{const{__scopeTabs:a,loop:r=!0,...l}=s,m=R(J,a),d=U(a);return e.jsx(Ce,{asChild:!0,...d,orientation:m.orientation,dir:m.dir,loop:r,children:e.jsx(M.div,{role:"tablist","aria-orientation":m.orientation,...l,ref:t})})});W.displayName=J;var X="TabsTrigger",Y=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,disabled:l=!1,...m}=s,d=R(X,a),x=U(a),g=ee(d.baseId,r),o=se(d.baseId,r),i=r===d.value;return e.jsx(Te,{asChild:!0,...x,focusable:!l,active:i,children:e.jsx(M.button,{type:"button",role:"tab","aria-selected":i,"aria-controls":o,"data-state":i?"active":"inactive","data-disabled":l?"":void 0,disabled:l,id:g,...m,ref:t,onMouseDown:$(s.onMouseDown,c=>{!l&&c.button===0&&c.ctrlKey===!1?d.onValueChange(r):c.preventDefault()}),onKeyDown:$(s.onKeyDown,c=>{[" ","Enter"].includes(c.key)&&d.onValueChange(r)}),onFocus:$(s.onFocus,()=>{const c=d.activationMode!=="manual";!i&&!l&&c&&d.onValueChange(r)})})})});Y.displayName=X;var Q="TabsContent",Z=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,forceMount:l,children:m,...d}=s,x=R(Q,a),g=ee(x.baseId,r),o=se(x.baseId,r),i=r===x.value,c=y.useRef(i);return y.useEffect(()=>{const f=requestAnimationFrame(()=>c.current=!1);return()=>cancelAnimationFrame(f)},[]),e.jsx(we,{present:l||i,children:({present:f})=>e.jsx(M.div,{"data-state":i?"active":"inactive","data-orientation":x.orientation,role:"tabpanel","aria-labelledby":g,hidden:!f,id:o,tabIndex:0,...d,ref:t,style:{...s.style,animationDuration:c.current?"0s":void 0},children:f&&m})})});Z.displayName=Q;function ee(s,t){return`${s}-trigger-${t}`}function se(s,t){return`${s}-content-${t}`}var Be=H,Ge=W,ze=Y,qe=Z;function Ke({defaultValue:s,children:t}){return e.jsx(Be,{defaultValue:s,className:"space-y-4",children:t})}function Ue({label:s="Views",children:t}){return e.jsx(Ge,{"aria-label":s,className:"flex flex-wrap gap-1 border-b pb-2",children:t})}function V({value:s,children:t}){return e.jsx(ze,{value:s,asChild:!0,children:e.jsx(_e,{type:"button",variant:"ghost",size:"sm",className:"data-[state=active]:bg-secondary data-[state=active]:text-secondary-foreground",children:t})})}function B({value:s,children:t}){return e.jsx(qe,{value:s,children:t})}function Ze({current:s,proposed:t,render:a}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Ke,{defaultValue:"proposed",children:[e.jsxs(Ue,{label:"Definition version",children:[e.jsx(V,{value:"current",children:"Current"}),e.jsx(V,{value:"proposed",children:"Proposed"})]}),e.jsx(B,{value:"current",children:s?a(s):e.jsx("p",{className:"py-4 text-sm text-muted-foreground",children:"No current definition."})}),e.jsx(B,{value:"proposed",children:t?a(t):e.jsx("p",{className:"py-4 text-sm text-muted-foreground",children:"This definition will be removed."})})]}),e.jsxs("details",{className:"text-sm",children:[e.jsx("summary",{className:"cursor-pointer rounded-sm py-2 text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Show technical diff"}),e.jsx($e,{before:s,after:t})]})]})}export{Qe as A,Ze as D,B as T,Ye as a,V as b,Ue as c,Ke as d,Pe as e};
2
+ //# sourceMappingURL=definition-comparison-3zKUSTt8.js.map
@@ -0,0 +1,2 @@
1
+ import{j as e,i as y,e$ as S,r as o,B as R,as as k,m as r}from"./index-C2TCKJDP.js";import{L as w,a as B}from"./list-skeleton-bQAZ0hQp.js";import{u as P}from"./runs-B_iywKWb.js";import{a as A,o as C}from"./filter-editors-DQ5V4Cvh.js";import{a as L}from"./runs-list-CJJFRhTl.js";const E=[{value:"all",label:"All"},{value:"automation",label:"Automation"},{value:"sync",label:"Sync"},{value:"action",label:"Action"},{value:"auth",label:"Auth"}],u=[{value:"running",label:"Running"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"},{value:"pending",label:"Pending"},{value:"claimed",label:"Claimed"},{value:"cancelled",label:"Cancelled"},{value:"timeout",label:"Timed out"}];function F({bucket:t,status:a,onBucketChange:s,onStatusChange:n}){return e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-2",children:[e.jsx("div",{className:"inline-flex max-w-full flex-wrap rounded-md border bg-muted/30 p-0.5 text-sm",children:E.map(l=>e.jsx("button",{type:"button",onClick:()=>s(l.value),className:y("rounded px-3 py-1 transition-colors",t===l.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:l.label},l.value))}),e.jsx(A,{label:"Run filters",className:"w-full min-w-0",fields:[{key:"status",label:"Status",icon:e.jsx(S,{className:"h-4 w-4"}),editor:C({searchPlaceholder:"Search statuses...",options:u,selected:a==="all"?[]:[a],onSelect:n})}],chips:a==="all"?[]:[{id:"status",label:"Status",op:"is",value:u.find(l=>l.value===a)?.label??a,onRemove:()=>n("all")}]})]})}function I({scope:t,ownerSlug:a}){const[s,n]=o.useState("all"),[l,c]=o.useState("all"),i=o.useMemo(()=>({runTypes:s==="all"?void 0:[s],status:l==="all"?void 0:l}),[s,l]),{data:d,isLoading:m,isError:x,hasNextPage:h,isFetching:f,isFetchingNextPage:v,fetchNextPage:p,refetch:b}=P(t,i,a),g=o.useMemo(()=>d?.pages.flatMap(N=>N.runs)??[],[d]),j={feed:!0,connection:"deviceId"in t||"connectorKey"in t,startedBy:!0};return e.jsxs("div",{className:"space-y-3",children:[e.jsx(F,{bucket:s,status:l,onBucketChange:n,onStatusChange:c}),m?e.jsx(w,{label:"Loading runs",rows:6,bordered:!1}):x?e.jsxs("p",{className:"rounded-lg border bg-destructive/5 px-3 py-6 text-center text-xs text-destructive",children:["Failed to load runs."," ",e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>void b(),children:"Retry"})]}):e.jsx(L,{runs:g,ownerSlug:a,columns:j,emptyState:e.jsx("p",{className:"rounded-lg border bg-muted/20 px-3 py-6 text-center text-xs text-muted-foreground",children:s==="all"&&l==="all"?"No runs yet.":"No runs match these filters."}),hasNextPage:!!h,isFetching:f,isFetchingNextPage:v,onLoadMore:()=>void p()})]})}function K({label:t,sections:a=2,rows:s=3}){return e.jsx(k,{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:e.jsxs("div",{role:"status","aria-label":t,children:[e.jsxs("div",{className:"flex flex-col gap-2 pb-1",children:[e.jsx(r,{className:"h-4 w-56"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(r,{className:"h-8 w-8 shrink-0 rounded-lg"}),e.jsx(r,{className:"h-6 w-56"})]})]}),e.jsx("div",{className:"mt-4 space-y-7",children:Array.from({length:a},(n,l)=>e.jsxs("div",{children:[e.jsx("div",{className:"mb-2.5 border-b pb-2",children:e.jsx(r,{className:"h-3.5 w-24"})}),Array.from({length:s},(c,i)=>e.jsx(B,{},i))]},l))})]})})}export{K as D,I as R};
2
+ //# sourceMappingURL=detail-page-skeleton-BmxqqIsH.js.map
@@ -1,2 +1,2 @@
1
- import{M as Ce,q as je,r as h,P as Ne,j as e,I as Se,B as ce,Q as ie}from"./index-BjcZVe7n.js";import{u as Ae,r as te,o as M,g as _e,a as De,C as ne,A as Ee,W as Re,b as re,c as Te,R as Pe}from"./use-login-redirect-ciwfc-7A.js";import{F as Ie}from"./full-page-spinner-B5xXnKtV.js";import{w as A}from"./workspace-label-o_QfBuCM.js";import"./card-g4yxo4Hr.js";const Le=[];function F(t){return t.trim().toUpperCase()}const Oe=15e3;async function ze(t){const i=new AbortController,p=window.setTimeout(()=>i.abort(),Oe);try{const n=await fetch(`${ie}/oauth/device/info?user_code=${encodeURIComponent(t)}`,{credentials:"include",signal:i.signal}),u=await n.json().catch(()=>null);return{response:n,data:u}}catch(n){throw i.signal.aborted?new Error("Verification timed out. Check your connection and try again."):n}finally{window.clearTimeout(p)}}function Ue({isVerified:t,requiresDeviceHome:i,requiresWorkspaceAccess:p,homeLabel:n,workspaceCount:u}){if(!t||p&&u===0)return null;const b=`${u} workspace${u===1?"":"s"}`;return i?n?p?`Pairs this device in ${n} and grants MCP access to ${b}.`:`Pairs this device in ${n} with no workspace data access.`:null:p?`Grants MCP access to ${b}.`:null}function Ve(){const t=Ce.useSearch(),{session:i,isReady:p}=je(),n=!p,[u,b]=h.useState(t.user_code||""),[r,g]=h.useState(null),[w,s]=h.useState(null),[a,ae]=h.useState(null),[$,P]=h.useState(null),[le,q]=h.useState(null),k=h.useRef(0),j=Ne(t.return_to),V=j?"app":"terminal",de=!!t.user_code,_=F(u),m=$?.code===_?$:null,v=m!==null,D=m?.scopes??Le,E=D.includes("device_worker:run"),ue=D.includes("connections:token"),I=m?.multiWorkspaceGrantsEnabled===!0,{accessLevel:G,setAccessLevel:L,selectedScopes:me,resourceOrg:O,hasMcpScopes:he,requiresWorkspaceAccess:N,orgList:C,workspaceAccess:pe,setWorkspaceAccess:ve,selectedOrgIds:z,toggleSelectedOrgId:fe,resetWorkspaceSelection:ge,deviceHomeOrgId:R,orgsLoading:U,orgsError:T,retryOrgs:B,workspaceSelectionReady:xe}=Ae({requestedScopes:D,resource:m?.resource??null,allowMultiple:I,requireDeviceHome:E,deviceHomeOrgId:le}),l=v&&E&&!O,d=C.find(o=>o.id===R)??null,Y=U||T!==null||C.length>1,J=C.length===1?C[0]:void 0,we=J!==void 0&&!J.isPersonal,Q=l&&(Y||R===null||we),K=N&&Y&&(I||!l),X=!N&&!l||xe,W=h.useCallback(async o=>{const x=++k.current;g("verify"),s(null);try{const{response:y,data:c}=await ze(o);if(x!==k.current)return;if(y.status===401){te();return}if(!y.ok||!c)throw new Error(M(c,"Failed to verify device authorization code"));const f=Array.isArray(c.scopes)?c.scopes:[];P({code:o,clientName:c.client_name??null,logoUri:typeof c.logo_uri=="string"?c.logo_uri:null,clientUri:typeof c.client_uri=="string"?c.client_uri:null,scopes:f,resource:typeof c.resource=="string"?c.resource:null,multiWorkspaceGrantsEnabled:c.multi_workspace_grants_enabled===!0}),L(_e(f))}catch(y){if(x!==k.current)return;P(null),s(y instanceof Error?y.message:"Unexpected error")}finally{x===k.current&&g(null)}},[L]);De(!!i,n),h.useEffect(()=>{if(!(n||!i||!t.user_code))return W(F(t.user_code)),()=>{k.current+=1}},[i,n,t.user_code,W]);const Z=async o=>{const x=_;if(!x){s(`Please enter the code shown in your ${V}.`);return}if(!v){s("Verify the device code before approving or denying access.");return}if(o&&!X){s(T?"Workspaces could not be loaded. Retry before approving.":l&&!d?"Choose a workspace for this device before approving.":"Choose at least one workspace before approving.");return}const y=m?.clientName??null,c=l&&d?A(d):null;g(o?"approve":"deny"),s(null);try{const f=await fetch(`${ie}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:x,approved:o,...o?{scope:me.join(" ")}:{},...o&&N?{workspace_access:pe,organization_ids:z}:{},...o&&l&&d?{organization_id:d.id}:{}})}),S=await f.json().catch(()=>null);if(f.status===401){te();return}if(!f.ok)throw new Error(M(S,"Failed to process device authorization"));const oe=o?"approved":"denied";if(S?.status!==oe)throw new Error(M(S,o?"The server did not confirm this approval. The device is still waiting — try again.":"The server did not confirm this denial. Try again."));const se=typeof S.user_code=="string"?F(S.user_code):null;if(se!==null&&se!==x)throw new Error("The server confirmed a different device code. Re-check the code shown on your device.");g(null),ae({outcome:oe,code:x,clientName:y,deviceHomeLabel:c})}catch(f){g(null),s(f instanceof Error?f.message:"Unexpected error")}};if(h.useEffect(()=>{if(a?.outcome!=="approved"||!j)return;const o=window.setTimeout(()=>{window.location.href=j},600);return()=>window.clearTimeout(o)},[a,j]),n||!i)return e.jsx(Ie,{className:"min-h-[calc(100vh-3.5rem)]"});if(a)return e.jsx(ne,{live:!0,title:a.outcome==="approved"?de?"Access Authorized":"Device Authorized":"Authorization Denied",description:a.outcome==="approved"?j?"You can close this tab and return to the Lobu app.":"You can close this tab and return to your terminal.":"The device was not authorized. You can close this tab.",review:e.jsxs("div",{className:"space-y-4 text-sm",children:[a.outcome==="approved"&&a.deviceHomeLabel?e.jsxs("p",{className:"text-muted-foreground",children:["This device now lives in ",a.deviceHomeLabel,". Change its workspace or share its connections from the device page under Connectors."]}):null,e.jsxs("dl",{className:"space-y-1",children:[e.jsx("dt",{className:"text-muted-foreground",children:a.outcome==="approved"?"Approved code":"Denied code"}),e.jsx("dd",{className:"font-mono text-base tracking-widest text-foreground",children:a.code}),a.clientName?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Requested by"}),e.jsx("dd",{className:"text-foreground",children:a.clientName})]}):null]})]})});const ye=Ue({isVerified:v,requiresDeviceHome:l,requiresWorkspaceAccess:N,homeLabel:d?A(d):null,workspaceCount:z.length}),ee=e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"user-code",className:"text-sm font-medium",children:"Device code"}),e.jsx(Se,{id:"user-code",value:u,disabled:r==="approve"||r==="deny",onChange:o=>{k.current+=1,b(o.target.value.toUpperCase()),P(null),ge(),q(null),g(null),s(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!t.user_code})]}),H=Q?e.jsx(We,{deviceName:m?.clientName??null,orgList:C,deviceHomeOrgId:R,onChange:q,orgsLoading:U,orgsError:T,onRetry:B,disabled:r!==null}):null,be=v?e.jsxs("div",{className:"space-y-5",children:[ee,e.jsx(Ee,{idPrefix:"oauth-device",clientName:m?.clientName??null,clientNote:E?"This device can run commands and control apps.":void 0,requestedScopes:D,accessLevel:G,onAccessLevelChange:L,allowNoAccess:E,disabled:r!==null,resource:m?.resource??null,logoUri:m?.logoUri??null,clientUri:m?.clientUri??null}),ue?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Can fetch tokens for your connected services."}):null,v&&l&&!Q&&d?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device will live in ",A(d),".",N?" MCP access follows the device home.":""]}):null,H&&!K?H:null]}):ee,ke=K?e.jsxs("div",{className:"space-y-4",children:[H,l&&d?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A(d)," is always included as the device home. Additional workspaces grant MCP access only."]}):null,e.jsx(Re,{idPrefix:"oauth-device",heading:l?"Additional workspaces":void 0,allowMultiple:I,includedOrgId:l?R:null,orgList:C,selectedOrgIds:z,onWorkspaceAccessChange:ve,onSelectedOrgChange:fe,orgsLoading:U,orgsError:T,onRetry:B,disabled:r!==null})]}):void 0;return e.jsx(ne,{title:v?"Authorize application":"Connect a device",description:v?void 0:`Enter the code shown in your ${V}.`,busy:r!==null,error:w,review:be,aside:ke,below:v&&he&&O?e.jsx(Pe,{resourceOrg:O,accessLevel:G}):null,footer:v?e.jsx(re,{summary:ye,children:e.jsx(Te,{busy:r==="approve"||r==="deny"?r:null,approveDisabled:r!==null||!X,denyDisabled:r!==null,onApprove:()=>Z(!0),onDeny:()=>Z(!1)})}):e.jsx(re,{children:e.jsx(ce,{type:"button",onClick:()=>W(_),disabled:r!==null||!_,children:r==="verify"?"Verifying...":"Continue"})})})}function We({deviceName:t,orgList:i,deviceHomeOrgId:p,onChange:n,orgsLoading:u,orgsError:b,onRetry:r,disabled:g}){const w=i.find(s=>s.id===p)??null;return e.jsxs("section",{className:"space-y-2 rounded-md border bg-card p-3 text-sm",children:[e.jsx("label",{htmlFor:"oauth-device-home",className:"block font-medium text-foreground",children:"Device home"}),u?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your workspaces..."}):b?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(ce,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("select",{id:"oauth-device-home",value:w?.id??"",disabled:g,onChange:s=>n(s.target.value),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 text-sm focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[w?null:e.jsx("option",{value:"",disabled:!0,children:"Choose a workspace"}),i.map(s=>e.jsx("option",{value:s.id,children:A(s)},s.id))]}),w&&!w.isPersonal?e.jsxs("p",{role:"note",className:"rounded-md bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-400",children:[t??"This device"," will be added to ",w.name,". Its Shell and Browser connections will be private to you — teammates can't use them unless you share them from the device page."]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Where this device is registered. Its connectors and Automations run here. A device that is already paired keeps its workspace; change it from the Devices page."})]})]})}export{Ve as component};
2
- //# sourceMappingURL=device-DdCoCj-Q.js.map
1
+ import{Y as Ce,z as je,r as h,Z as Ne,j as e,U as Se,B as ce,$ as ie}from"./index-C2TCKJDP.js";import{u as Ae,r as te,o as F,g as _e,a as De,C as ne,A as Ee,W as Re,b as re,c as Te,R as Pe}from"./use-login-redirect-CfCbEeJR.js";import{F as Le}from"./full-page-spinner-B7A6Ycyi.js";import{w as A}from"./workspace-label-o_QfBuCM.js";import"./card-rE4Ctuy6.js";const Ie=[];function M(t){return t.trim().toUpperCase()}const Oe=15e3;async function ze(t){const i=new AbortController,p=window.setTimeout(()=>i.abort(),Oe);try{const n=await fetch(`${ie}/oauth/device/info?user_code=${encodeURIComponent(t)}`,{credentials:"include",signal:i.signal}),u=await n.json().catch(()=>null);return{response:n,data:u}}catch(n){throw i.signal.aborted?new Error("Verification timed out. Check your connection and try again."):n}finally{window.clearTimeout(p)}}function Ue({isVerified:t,requiresDeviceHome:i,requiresWorkspaceAccess:p,homeLabel:n,workspaceCount:u}){if(!t||p&&u===0)return null;const b=`${u} workspace${u===1?"":"s"}`;return i?n?p?`Pairs this device in ${n} and grants MCP access to ${b}.`:`Pairs this device in ${n} with no workspace data access.`:null:p?`Grants MCP access to ${b}.`:null}function qe(){const t=Ce.useSearch(),{session:i,isReady:p}=je(),n=!p,[u,b]=h.useState(t.user_code||""),[r,g]=h.useState(null),[w,s]=h.useState(null),[a,ae]=h.useState(null),[$,P]=h.useState(null),[le,V]=h.useState(null),k=h.useRef(0),j=Ne(t.return_to),q=j?"app":"terminal",de=!!t.user_code,_=M(u),m=$?.code===_?$:null,v=m!==null,D=m?.scopes??Ie,E=D.includes("device_worker:run"),ue=D.includes("connections:token"),L=m?.multiWorkspaceGrantsEnabled===!0,{accessLevel:G,setAccessLevel:I,selectedScopes:me,resourceOrg:O,hasMcpScopes:he,requiresWorkspaceAccess:N,orgList:C,workspaceAccess:pe,setWorkspaceAccess:ve,selectedOrgIds:z,toggleSelectedOrgId:fe,resetWorkspaceSelection:ge,deviceHomeOrgId:R,orgsLoading:U,orgsError:T,retryOrgs:B,workspaceSelectionReady:xe}=Ae({requestedScopes:D,resource:m?.resource??null,allowMultiple:L,requireDeviceHome:E,deviceHomeOrgId:le}),l=v&&E&&!O,d=C.find(o=>o.id===R)??null,Y=U||T!==null||C.length>1,J=C.length===1?C[0]:void 0,we=J!==void 0&&!J.isPersonal,Z=l&&(Y||R===null||we),K=N&&Y&&(L||!l),Q=!N&&!l||xe,W=h.useCallback(async o=>{const x=++k.current;g("verify"),s(null);try{const{response:y,data:c}=await ze(o);if(x!==k.current)return;if(y.status===401){te();return}if(!y.ok||!c)throw new Error(F(c,"Failed to verify device authorization code"));const f=Array.isArray(c.scopes)?c.scopes:[];P({code:o,clientName:c.client_name??null,logoUri:typeof c.logo_uri=="string"?c.logo_uri:null,clientUri:typeof c.client_uri=="string"?c.client_uri:null,scopes:f,resource:typeof c.resource=="string"?c.resource:null,multiWorkspaceGrantsEnabled:c.multi_workspace_grants_enabled===!0}),I(_e(f))}catch(y){if(x!==k.current)return;P(null),s(y instanceof Error?y.message:"Unexpected error")}finally{x===k.current&&g(null)}},[I]);De(!!i,n),h.useEffect(()=>{if(!(n||!i||!t.user_code))return W(M(t.user_code)),()=>{k.current+=1}},[i,n,t.user_code,W]);const X=async o=>{const x=_;if(!x){s(`Please enter the code shown in your ${q}.`);return}if(!v){s("Verify the device code before approving or denying access.");return}if(o&&!Q){s(T?"Workspaces could not be loaded. Retry before approving.":l&&!d?"Choose a workspace for this device before approving.":"Choose at least one workspace before approving.");return}const y=m?.clientName??null,c=l&&d?A(d):null;g(o?"approve":"deny"),s(null);try{const f=await fetch(`${ie}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:x,approved:o,...o?{scope:me.join(" ")}:{},...o&&N?{workspace_access:pe,organization_ids:z}:{},...o&&l&&d?{organization_id:d.id}:{}})}),S=await f.json().catch(()=>null);if(f.status===401){te();return}if(!f.ok)throw new Error(F(S,"Failed to process device authorization"));const oe=o?"approved":"denied";if(S?.status!==oe)throw new Error(F(S,o?"The server did not confirm this approval. The device is still waiting — try again.":"The server did not confirm this denial. Try again."));const se=typeof S.user_code=="string"?M(S.user_code):null;if(se!==null&&se!==x)throw new Error("The server confirmed a different device code. Re-check the code shown on your device.");g(null),ae({outcome:oe,code:x,clientName:y,deviceHomeLabel:c})}catch(f){g(null),s(f instanceof Error?f.message:"Unexpected error")}};if(h.useEffect(()=>{if(a?.outcome!=="approved"||!j)return;const o=window.setTimeout(()=>{window.location.href=j},600);return()=>window.clearTimeout(o)},[a,j]),n||!i)return e.jsx(Le,{className:"min-h-[calc(100vh-3.5rem)]"});if(a)return e.jsx(ne,{live:!0,title:a.outcome==="approved"?de?"Access Authorized":"Device Authorized":"Authorization Denied",description:a.outcome==="approved"?j?"You can close this tab and return to the Lobu app.":"You can close this tab and return to your terminal.":"The device was not authorized. You can close this tab.",review:e.jsxs("div",{className:"space-y-4 text-sm",children:[a.outcome==="approved"&&a.deviceHomeLabel?e.jsxs("p",{className:"text-muted-foreground",children:["This device now lives in ",a.deviceHomeLabel,". Change its workspace or share its connections from the device page under Connectors."]}):null,e.jsxs("dl",{className:"space-y-1",children:[e.jsx("dt",{className:"text-muted-foreground",children:a.outcome==="approved"?"Approved code":"Denied code"}),e.jsx("dd",{className:"font-mono text-base tracking-widest text-foreground",children:a.code}),a.clientName?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Requested by"}),e.jsx("dd",{className:"text-foreground",children:a.clientName})]}):null]})]})});const ye=Ue({isVerified:v,requiresDeviceHome:l,requiresWorkspaceAccess:N,homeLabel:d?A(d):null,workspaceCount:z.length}),ee=e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"user-code",className:"text-sm font-medium",children:"Device code"}),e.jsx(Se,{id:"user-code",value:u,disabled:r==="approve"||r==="deny",onChange:o=>{k.current+=1,b(o.target.value.toUpperCase()),P(null),ge(),V(null),g(null),s(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!t.user_code})]}),H=Z?e.jsx(We,{deviceName:m?.clientName??null,orgList:C,deviceHomeOrgId:R,onChange:V,orgsLoading:U,orgsError:T,onRetry:B,disabled:r!==null}):null,be=v?e.jsxs("div",{className:"space-y-5",children:[ee,e.jsx(Ee,{idPrefix:"oauth-device",clientName:m?.clientName??null,clientNote:E?"This device can run commands and control apps.":void 0,requestedScopes:D,accessLevel:G,onAccessLevelChange:I,allowNoAccess:E,disabled:r!==null,resource:m?.resource??null,logoUri:m?.logoUri??null,clientUri:m?.clientUri??null}),ue?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Can fetch tokens for your connected services."}):null,v&&l&&!Z&&d?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device will live in ",A(d),".",N?" MCP access follows the device home.":""]}):null,H&&!K?H:null]}):ee,ke=K?e.jsxs("div",{className:"space-y-4",children:[H,l&&d?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A(d)," is always included as the device home. Additional workspaces grant MCP access only."]}):null,e.jsx(Re,{idPrefix:"oauth-device",heading:l?"Additional workspaces":void 0,allowMultiple:L,includedOrgId:l?R:null,orgList:C,selectedOrgIds:z,onWorkspaceAccessChange:ve,onSelectedOrgChange:fe,orgsLoading:U,orgsError:T,onRetry:B,disabled:r!==null})]}):void 0;return e.jsx(ne,{title:v?"Authorize application":"Connect a device",description:v?void 0:`Enter the code shown in your ${q}.`,busy:r!==null,error:w,review:be,aside:ke,below:v&&he&&O?e.jsx(Pe,{resourceOrg:O,accessLevel:G}):null,footer:v?e.jsx(re,{summary:ye,children:e.jsx(Te,{busy:r==="approve"||r==="deny"?r:null,approveDisabled:r!==null||!Q,denyDisabled:r!==null,onApprove:()=>X(!0),onDeny:()=>X(!1)})}):e.jsx(re,{children:e.jsx(ce,{type:"button",onClick:()=>W(_),disabled:r!==null||!_,children:r==="verify"?"Verifying...":"Continue"})})})}function We({deviceName:t,orgList:i,deviceHomeOrgId:p,onChange:n,orgsLoading:u,orgsError:b,onRetry:r,disabled:g}){const w=i.find(s=>s.id===p)??null;return e.jsxs("section",{className:"space-y-2 rounded-md border bg-card p-3 text-sm",children:[e.jsx("label",{htmlFor:"oauth-device-home",className:"block font-medium text-foreground",children:"Device home"}),u?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your workspaces..."}):b?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(ce,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("select",{id:"oauth-device-home",value:w?.id??"",disabled:g,onChange:s=>n(s.target.value),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 text-sm focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[w?null:e.jsx("option",{value:"",disabled:!0,children:"Choose a workspace"}),i.map(s=>e.jsx("option",{value:s.id,children:A(s)},s.id))]}),w&&!w.isPersonal?e.jsxs("p",{role:"note",className:"rounded-md bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-400",children:[t??"This device"," will be added to ",w.name,". Its Shell and Browser connections will be private to you — teammates can't use them unless you share them from the device page."]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Where this device is registered. Its connectors and Automations run here. A device that is already paired keeps its workspace; change it from the Devices page."})]})]})}export{qe as component};
2
+ //# sourceMappingURL=device-D2eUt_nr.js.map
@@ -0,0 +1,2 @@
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__search_sdk,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};
2
+ //# sourceMappingURL=device-automation-Dp3faMvp.js.map
@@ -0,0 +1,2 @@
1
+ import{r as v,j5 as y,j as e,j6 as f,j7 as g,hV as C,j8 as k,B as A,L as E,dh as I,j9 as P,ja as N,jb as O,jc as w,u as F,jd as $,im as b}from"./index-C2TCKJDP.js";import{R as L}from"./detail-page-skeleton-BmxqqIsH.js";function z({connection:s,connectorDef:t,ownerSlug:a,openSettings:i=!1,authResult:o,showActivity:r=!0,embedded:n=!1,showShare:c=!0}){const[l,d]=v.useState(i);v.useEffect(()=>{i&&d(!0)},[i]);const u=s.id,m=s.connector_key,p=s.facets?.chat??!1,h=p?"Channels":"Feeds",j=s.has_operations===!0,_=s.feed_count>0||y(t),x=e.jsx(w,{connection:s,connectorDef:t,ownerSlug:a,showShare:c});return e.jsxs("div",{className:"space-y-6",children:[o&&e.jsx(f,{result:o}),s.auth_profile_kind==="oauth_account"&&e.jsx(g,{connection:s,connectorDef:t,onReview:()=>{d(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),(_||j)&&e.jsxs("div",{className:n?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[_&&(n?e.jsx(C,{title:h,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:y(t)?e.jsx(A,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(E,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:a,connectorKey:m,connectionId:String(u)},search:{addFeed:!0},children:[e.jsx(I,{className:"h-3.5 w-3.5"}),p?"Add channel":"Add source"]})}):null,children:e.jsx(k,{connection:s,ownerSlug:a,connectorKey:m,connectorDef:t})}):e.jsx(P,{connection:s,ownerSlug:a,title:h})),j&&(n?e.jsx(N,{connection:s,ownerSlug:a}):e.jsx(B,{connection:s,ownerSlug:a}))]}),n?e.jsx(O,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:l,onOpenChange:d,children:x}):x,r&&e.jsx(C,{title:"Runs",children:e.jsx(L,{scope:{connectionId:u},ownerSlug:a})})]})}function B({connection:s,ownerSlug:t}){const a=F(),{data:i=[],isLoading:o,isError:r}=$(s.id),n=i.filter(l=>l.readiness==="scope_upgrade_required").length,c=o?"Loading actions…":r?"Could not load actions — open to retry":`${i.length} actions${n?` · ${n} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(b,{title:"Actions",summary:c,onOpen:()=>a?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:t}})})}const R=new Set(["Device was removed","Device was moved to another workspace"]);function K(s){const t=s.error_message??null;return!t||!R.has(t)?t:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:t}export{z as C,K as c};
2
+ //# sourceMappingURL=device-pin-tombstone-BFPbTM_o.js.map
@@ -0,0 +1,2 @@
1
+ import{aU as F,iU as ne,iV as U,r as v,j as e,iW as P,B as b,ai as L,iX as C,ct as V,aH as te,hV as z,m as Y,b8 as M,h3 as ae,h4 as ie,C as ce,h6 as oe,dC as re,iY as le,a8 as de,c as me,aM as ue,iZ as xe,i_ as he,i$ as pe,aN as fe,aI as ge,as as A,b7 as T,L as E,j0 as je,j1 as ve,a_ as ye,j2 as be,j3 as Ne,a3 as _e,cu as ke,iQ as q,U as we,c1 as Ce,cL as Se,cw as $e,cx as K,d3 as De,j4 as O,aF as Pe}from"./index-C2TCKJDP.js";import{C as Le}from"./connector-page-shell-C23dWdKz.js";import{D as ze,R as Ie}from"./detail-page-skeleton-BmxqqIsH.js";import{S as Ae,g as Ee}from"./status-variants-BxHtpMOj.js";import{c as G,C as Re}from"./device-pin-tombstone-BFPbTM_o.js";import{w as R}from"./workspace-label-o_QfBuCM.js";import"./list-skeleton-bQAZ0hQp.js";import"./runs-B_iywKWb.js";import"./filter-editors-DQ5V4Cvh.js";import"./subDays-DwIOMzYC.js";import"./runs-list-CJJFRhTl.js";import"./run-initiator-8vdkq-3o.js";import"./use-automations-lV8PuE8L.js";import"./clients-CydgUHrc.js";function Me(s,n,o){const h=new Set(s.capabilities??[]),m=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key)),r=new Set(Q(s,o).map(t=>t.connector_key));return n.filter(t=>F(t)&&!!t.required_capability&&h.has(t.required_capability)&&!m.has(t.key)&&!r.has(t.key))}function Q(s,n){return s.organization_slug===n?s.update_required:[]}function Be(s,n,o){const h=s.organization_slug;if(!h||h===o)return[];const m=new Set(n.map(t=>t.key)),r=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key));return s.connectors.filter(t=>t.organization_slug!==h||m.has(t.connector_key)||r.has(t.connector_key)?!1:(r.add(t.connector_key),!0))}function Te({device:s,organizationId:n,ownerSlug:o,connectable:h,unavailable:m}){const r=ne(),t=U(),[u,p]=v.useState(null),[g,a]=v.useState(null),[f,N]=v.useState(null),[j,d]=v.useState([]),x=s.organization_id===n,y=async i=>{p(null),N(null),a(i.key);try{x||await t.mutateAsync({deviceWorkerId:s.id,organizationId:n});const w=await r.mutateAsync({connector_key:i.key,device_worker_id:s.id}),S=w.connection_id??w.connection?.id;if(S===void 0)throw new Error(w.instructions??"The connection was not created.");d($=>[...$.filter(D=>D.connectorKey!==i.key),{connectorKey:i.key,name:i.name,connectionId:S,instructions:w.status==="setup_required"?w.instructions:void 0}])}catch(w){N({key:i.key,message:w instanceof Error?w.message:"Could not connect."})}finally{a(null)}},_=new Set(j.map(i=>i.connectorKey)),l=Q(s,o),c=h.filter(i=>!_.has(i.key));return e.jsxs("div",{className:"mt-4 space-y-3",children:[j.map(i=>e.jsx(qe,{outcome:i,device:s,organizationId:n},i.connectorKey)),c.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Supported by this device"}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Not connected in this workspace yet.",x?null:" Connecting one moves the device here; you will be asked to confirm first."]}),e.jsx("div",{className:"divide-y border-y",children:c.map(i=>e.jsxs("div",{className:"space-y-2 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-sm font-medium",children:[i.name,i.required_capability&&P[i.required_capability]&&P[i.required_capability]!==i.name?e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:P[i.required_capability]}):null]}),e.jsxs(b,{size:"sm",variant:"outline","aria-label":`Connect ${i.name}`,disabled:g!==null,onClick:()=>x?void y(i):p(i.key),children:[g===i.key?e.jsx(L,{className:"mr-1.5"}):null,"Connect"]})]}),u===i.key?e.jsx(X,{device:s,ownerSlug:o,title:"Move device to this workspace",intro:`${C(s)} lives in ${s.organization_name??"another workspace"}. A device serves one workspace at a time, so it has to move here before it can be connected.`,confirmLabel:"Move here and connect",onConfirm:()=>void y(i),onCancel:()=>p(null)}):null,f?.key===i.key?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.message}):null]},i.key))})]}):null,l.length>0?e.jsxs("div",{role:"status",children:[e.jsx("p",{className:"text-xs font-medium",children:"Update Lobu on this device"}),e.jsx("ul",{className:"mt-1 space-y-1 text-xs text-muted-foreground",children:l.map(i=>e.jsx("li",{children:`${i.display_name} — this device has ${i.device_version}, this workspace uses ${i.workspace_version}`},i.connector_key))})]}):null,m.length>0?e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:m.map(i=>e.jsx("li",{children:`${i.display_name} — set up on this device in ${s.organization_name??"its home workspace"}, not available in this workspace yet`},i.connector_key))}):null]})}function X({device:s,ownerSlug:n,title:o,intro:h,aftermath:m,confirmLabel:r,pending:t=!1,onConfirm:u,onCancel:p}){const g=s.connector_count,a=s.connectors.filter(f=>f.organization_slug===n).length;return e.jsxs("div",{role:"alertdialog","aria-label":o,className:"space-y-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs",children:[e.jsx("p",{children:h}),e.jsxs("p",{className:"text-muted-foreground",children:[g>0?`Moving pauses and unpins all ${g} connection${g===1?"":"s"} pinned to it${a>0?`, including ${a} in this workspace`:""}. They stay paused until you reconnect them.`:"It has no pinned connections, so nothing is paused.",m?` ${m}`:null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{size:"sm",disabled:t,onClick:u,children:[t?e.jsx(L,{className:"mr-1.5"}):null,r]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:t,onClick:p,children:"Cancel"})]})]})}function qe({outcome:s,device:n,organizationId:o}){const{data:h=[],isLoading:m}=V(o,{connectionIds:[s.connectionId]}),r=h.find(p=>p.id===s.connectionId),t=C(n);if(m)return e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Checking ",s.name,"…"]});const u=[];if(!r)u.push(`${s.name} was created but could not be loaded yet.`);else if(r.status!=="active"){const p=G(r);u.push(`${s.name} is ${r.status}${p?`: ${p}`:"."}`)}return s.instructions&&u.push(s.instructions),n.online||u.push(`${t} is offline. ${s.name} runs once it reconnects.`),e.jsx("div",{role:"status",className:"rounded-lg border px-3 py-2 text-sm",children:u.length===0?e.jsxs("p",{children:[s.name," is ready on ",t,"."]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium",children:[s.name," connected, not ready yet"]}),e.jsx("ul",{className:"mt-1 list-disc pl-4 text-xs text-muted-foreground",children:u.map(p=>e.jsx("li",{children:p},p))})]})})}function H({device:s,organizationId:n,ownerSlug:o,selectedConnection:h,openSettings:m}){const{data:r=[],isLoading:t,isError:u,refetch:p}=te(n),g=new Map(r.map(d=>[d.key,d])),a=new Map,f=[];for(const d of s.connectors){if(d.organization_slug!==o)continue;const x=g.get(d.connector_key);if(!x||!F(x)){f.push(d);continue}const y=x.required_capability??`connector:${x.key}`,_=a.get(y)??{key:y,name:x.name,connections:[]};_.name=P[y]??x.name,_.connections.push(d),a.set(y,_)}const N=Me(s,r,o),j=Be(s,r,o);return e.jsxs(e.Fragment,{children:[e.jsxs(z,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),s.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."}),!n||t?e.jsx(Y,{className:"h-24 w-full"}):u?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void p(),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(d=>e.jsx(W,{group:d,deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d.key))}),n&&!t&&!u?e.jsx(Te,{device:s,organizationId:n,ownerSlug:o,connectable:N,unavailable:j}):null,M(s)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),n&&f.length>0&&!t&&!u?e.jsxs(z,{title:"Apps and sources",count:String(f.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:[...new Set(f.map(d=>d.connector_key))].map(d=>e.jsx(W,{group:{key:d,name:g.get(d)?.name??d,connections:f.filter(x=>x.connector_key===d)},deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d))})]}):null]})}function W({group:s,deviceId:n,organizationId:o,ownerSlug:h,definitionsByKey:m,selectedConnection:r,openSettings:t}){const u=s.connections.some(a=>a.connection_id===r),[p,g]=v.useState(u);return v.useEffect(()=>{u&&r!==void 0&&g(!0)},[u,r]),e.jsxs(ae,{open:p,onOpenChange:g,children:[e.jsxs(ie,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(ce,{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:s.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:s.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":s.connections.length>1?`${s.connections.length} connections`:"Configured"})]}),e.jsx(oe,{className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:s.connections.map(a=>e.jsx(Ke,{summary:a,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m.get(a.connector_key),openSettings:a.connection_id===r&&t},a.connection_id))})})]})}function Ke({summary:s,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m,openSettings:r}){const{data:t=[],isLoading:u,isError:p,refetch:g}=V(o,{connectionIds:[s.connection_id]}),a=t.find(j=>j.id===s.connection_id&&j.device_worker_id===n),f=m?.name??s.connector_key,N=a?G(a):null;return e.jsxs("section",{id:`connection-${s.connection_id}`,"aria-label":f,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:re(a)}),e.jsx("span",{children:a.status})]}):null,u||!o?e.jsx(Y,{className:"h-24 w-full"}):p?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[N?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:N}):null,e.jsx("div",{className:"mb-4",children:e.jsx(le,{connection:a})}),e.jsx(Re,{connection:a,connectorDef:m,ownerSlug:h,openSettings:r,showActivity:!1,showShare:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function Oe({device:s,ownerSlug:n}){const o=v.useId(),{data:h=[]}=de(),m=U(),[r,t]=v.useState(!1),[u,p]=v.useState(null),[g,a]=v.useState(null),f=h.filter(l=>l.is_member).map(l=>({id:l.id,name:l.name,isPersonal:l.is_personal===!0})),N=f.find(l=>l.id===s.organization_id),j=N?R(N):s.organization_name??"No workspace",d=f.filter(l=>l.id!==s.organization_id),x=d.find(l=>l.id===u)??null,y=()=>{t(!1),p(null)},_=async l=>{a(null);try{await m.mutateAsync({deviceWorkerId:s.id,organizationId:l}),y()}catch(c){a(c instanceof Error?c.message:"Could not move the device.")}};return e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace: "}),j]}),!r&&d.length>0?e.jsx(b,{size:"sm",variant:"outline",onClick:()=>{a(null),t(!0)},children:"Change workspace"}):null]}),r?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:o,className:"text-xs text-muted-foreground",children:"Move to"}),e.jsxs("select",{id:o,value:u??"",disabled:m.isPending,onChange:l=>p(l.target.value||null),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Choose a workspace"}),d.map(l=>e.jsx("option",{value:l.id,children:R(l)},l.id))]}),x?null:e.jsx(b,{size:"sm",variant:"ghost",onClick:y,children:"Cancel"})]}):null,x?e.jsx(X,{device:s,ownerSlug:n,title:`Move device to ${x.name}`,intro:`Move ${C(s)} from ${j} to ${R(x)}?`,aftermath:`It is set up fresh in ${x.name}, with its connections there private to you until you share them.`,confirmLabel:"Move device",pending:m.isPending,onConfirm:()=>void _(x.id),onCancel:y}):null,g?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:g}):null]})}function He({ownerSlug:s,deviceId:n,organizationId:o,selectedConnection:h,openSettings:m}){const r=me(),{data:t=[],isLoading:u,isError:p,refetch:g}=ue(),a=xe(),f=he(),[N,j]=v.useState(!1),[d,x]=v.useState(!1),[y,_]=v.useState(""),l=pe(t,n),c=l&&fe(l,s)?l:void 0,i=c?.id??n,{data:w=[]}=ge(o,{profileKind:"browser_session"}),S=v.useMemo(()=>w.filter(k=>k.device_worker_id===i&&k.status!=="revoked"),[w,i]),$=c?.label?.trim()??"";if(v.useEffect(()=>{d||_($)},[$,d]),u)return e.jsx(ze,{label:"Loading device"});if(p)return e.jsx(A,{children:e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{children:"Could not load this device."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]})});if(!c&&l&&o)return e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{platform:M(l),className:"h-5 w-5"}),e.jsx("h1",{className:"text-base font-semibold",children:C(l)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device lives in"," ",l.organization_name??"another workspace",", not this workspace."]}),e.jsx(H,{device:l,organizationId:o,ownerSlug:s})]});if(!c)return e.jsxs(A,{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(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const D=je(c),I=D?ve(s,D,ye()):void 0,Z=M(c),J=be(c.app_version),ee=Ne(c,J),B=()=>{const k=y.trim(),se=c.label?.trim()??"";if(k===se){x(!1);return}f.mutate({deviceWorkerId:c.id,label:k.length===0?null:k},{onSuccess:()=>x(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(Le,{header:e.jsx(ke,{breadcrumb:e.jsx($e,{crumbs:[e.jsx(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:K,children:"Connectors"},"connectors"),...I?[e.jsx(E,{to:"/$owner/connectors/app/$appId",params:{owner:s,appId:I.id},className:K,children:I.name},"app")]:[]]}),icon:e.jsx(T,{platform:Z,className:"h-5 w-5"}),title:d?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(we,{"aria-label":"Device name",value:y,onChange:k=>_(k.target.value),placeholder:C({...c,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:k=>{k.key==="Enter"?(k.preventDefault(),N||B()):k.key==="Escape"&&(j(!1),_(c.label?.trim()??""),x(!1))}}),N?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"," ",c.connector_count>0?`and un-pins ${c.connector_count} connector${c.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(b,{variant:"destructive",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(c.id,{onSuccess:()=>{j(!1),r({to:"/$owner/connectors",params:{owner:s},search:{}})}}),children:[a.isPending?e.jsx(L,{className:"mr-1.5"}):null,a.isPending?"Removing...":"Confirm remove"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:a.isPending,onClick:()=>j(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{size:"sm",onClick:B,disabled:f.isPending,children:[f.isPending?e.jsx(L,{className:"mr-1.5"}):null,f.isPending?"Saving...":"Save"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>{_(c.label?.trim()??""),x(!1)},children:"Cancel"}),e.jsxs(b,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:f.isPending||a.isPending,onClick:()=>j(!0),children:[e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[C(c),e.jsx(b,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{j(!1),_(c.label?.trim()??""),x(!0)},children:e.jsx(Se,{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 ${c.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),c.online?c.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:ee||void 0,caption:`Last seen ${q(new Date(c.last_seen_at),{addSuffix:!0})}${c.last_sync_at?` · Last sync ${q(new Date(c.last_sync_at),{addSuffix:!0})}`:""}`}),children:[e.jsx(Oe,{device:c,ownerSlug:s}),c.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(_e,{className:"h-3.5 w-3.5 shrink-0"}),c.connector_error_count," connector",c.connector_error_count===1?"":"s"," pinned to this device ",c.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(H,{device:c,organizationId:o,ownerSlug:s,selectedConnection:h,openSettings:m}),S.length>0?e.jsx(z,{title:"Browser auth profiles",children:e.jsx(We,{profiles:S})}):null,e.jsx(z,{title:"Runs",children:e.jsx(Ie,{scope:{deviceId:i},ownerSlug:s})})]})})}function We({profiles:s}){return s.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:s.map(n=>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:n.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:n.connector_key??"Any connector"}),n.browser_kind?e.jsxs("span",{children:["· ",n.browser_kind]}):null,n.captured_at?e.jsxs("span",{title:n.captured_at,children:["· captured ",De(n.captured_at)]}):null,typeof n.cookie_count=="number"?e.jsxs("span",{children:["· ",n.cookie_count," cookie",n.cookie_count===1?"":"s"]}):null]})]}),e.jsx(Ae,{status:n.is_expired?"error":Ee(n.status),showDot:!0,children:n.is_expired?"expired":n.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},n.id))})})}function is(){const{owner:s,deviceId:n}=O.useParams(),{connection:o,settings:h}=O.useSearch();return e.jsx(Pe,{owner:s,children:({ownerSlug:m,organizationId:r})=>e.jsx(He,{ownerSlug:m,deviceId:n,organizationId:r,selectedConnection:o,openSettings:h})})}export{is as component};
2
+ //# sourceMappingURL=device._deviceId-Dqtmb1Xp.js.map
@@ -0,0 +1,2 @@
1
+ import{j as e,fi as M,T as q,a6 as ae,bg as ie,bh as re,bi as ne,bj as le,bk as ce,fC as de,gz as me,gA as E,gB as H,gC as oe,gD as k,gE as ue,B as O,c1 as U,dh as G,U as L,dx as xe,fk as be,gF as je,dq as Q,gG as fe,a4 as ye,i as z,gH as he,r as Z,e3 as Ne,e4 as ge,gI as we,e7 as Se,ec as $e,dO as R}from"./index-C2TCKJDP.js";import{d as I,h as ve,F as Oe,i as J,j as Te}from"./renderer-ucwCQmBk.js";import{T as Be,a as De,b as C,c as X,d as Ee,e as P}from"./table-1O-ik4_O.js";import{p as K,a as Ae}from"./schema-value-CefbtPIY.js";function ee(l){return l.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ie(l,r=!1){return l?Ae(l,r):r?"Pick a date and time":"Pick a date"}function V(l){if(!l)return"";const r=K(l);if(Number.isNaN(r.getTime()))return"";const s=r.getTimezoneOffset()*6e4;return new Date(r.getTime()-s).toISOString().slice(0,16)}function W(l){if(!l)return;const r=new Date(l);if(!Number.isNaN(r.getTime()))return r.toISOString()}function A(l,r){const s=r==="slug"?l.slug:l.metadata?.[r];return s==null?"":String(s)}function Y({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,includeTime:N=!1,clearable:j}){const d=r?K(r):void 0,[m,u]=Z.useState(()=>V(r).slice(11));return Z.useEffect(()=>{u(V(r).slice(11))},[r]),e.jsx("div",{className:"relative",children:e.jsxs(Ne,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",disabled:a,className:z("w-full justify-start rounded-md bg-muted px-3 text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(we,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:Ie(r,N)})]})}),e.jsxs(Se,{className:"w-auto space-y-3 p-0",align:"start",children:[e.jsx($e,{mode:"single",selected:d,defaultMonth:d,onSelect:i=>{if(!i)return;if(!N){s(R(i,"yyyy-MM-dd"));return}const t=m||"00:00";s(W(`${R(i,"yyyy-MM-dd")}T${t}`))},initialFocus:!0}),N?e.jsxs("div",{className:"border-t p-3 pt-0",children:[e.jsx(q,{htmlFor:`${l}-time`,className:"text-xs text-muted-foreground",children:"Time"}),e.jsx(L,{id:`${l}-time`,type:"time",value:m,onChange:i=>{u(i.target.value);const t=r?V(r).slice(0,10):d?R(d,"yyyy-MM-dd"):"";t&&s(W(`${t}T${i.target.value}`))},disabled:a})]}):null,j&&r?e.jsx("div",{className:"border-t p-2",children:e.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:()=>s(void 0),children:"Clear"})}):null]})]})})}function Fe({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,entityType:N,lookupField:j,numeric:d=!1,orgContext:m}){const u=o=>{if(o===void 0||o==="")return s(void 0);if(!d)return s(o);const x=Number(o);s(Number.isFinite(x)?x:o)},{data:i}=xe(N,m,{limit:be}),t=(i?.entities??[]).filter(o=>A(o,j)!==""),S=r==null?"":String(r),v=t.find(o=>A(o,j)===S);return m?a?e.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm",children:v?.name||S||"-"}):e.jsx(je,{contentClassName:"w-[320px]",searchPlaceholder:`Search ${J(N).toLowerCase()}...`,emptyText:`No ${N} found.`,trigger:o=>e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsx("span",{className:z("truncate",!S&&"text-muted-foreground"),children:v?.name||S||`Select ${J(N).toLowerCase()}`}),e.jsx(he,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,x)=>{const n=x.trim(),f=n.length>0&&!t.some(y=>A(y,j)===n);return e.jsxs(e.Fragment,{children:[f?e.jsxs(Q,{value:`use ${n}`,onSelect:()=>{u(n),o()},children:[e.jsx(fe,{className:"mr-2 h-3.5 w-3.5 opacity-60"}),e.jsxs("span",{className:"truncate",children:["Use ",e.jsx("span",{className:"font-medium",children:n})]})]}):null,t.map(y=>{const h=A(y,j),T=h===S;return e.jsxs(Q,{value:`${y.name} ${y.slug} ${y.entity_type} ${h}`,onSelect:()=>{u(h||void 0),o()},children:[e.jsx(ye,{className:z("mr-2 h-4 w-4",T?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:y.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.slug})]})]},`${y.id}-${h}`)})]})}}):e.jsx(L,{id:l,"aria-label":c,"aria-describedby":w,type:d?"number":"text",value:S,onChange:o=>u(o.target.value||void 0),disabled:a})}function se({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:j,ariaLabel:d,helpId:m}){const u=I(r,s),i=ee(l),t=N||s.readOnly===!0,S=s.type==="object"||!!s.properties,v=s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties),o=s.type==="array"&&!!s.items&&(s.items?.type==="string"||s.items?.type==="number"||s.items?.type==="integer"||s.items?.type==="boolean");if(s.type==="boolean")return e.jsx(ae,{id:i,"aria-label":d,"aria-describedby":m,checked:a??!1,onCheckedChange:n=>c(n),disabled:t});let x;if(s.enum&&Array.isArray(s.enum))x=e.jsxs(ie,{value:a==null?"":String(a),onValueChange:n=>c(n===""?void 0:s.type==="number"||s.type==="integer"?Number(n):n),disabled:t,children:[e.jsx(re,{id:i,"aria-label":d,"aria-describedby":m,children:e.jsx(ne,{placeholder:`Select ${u.toLowerCase()}`})}),e.jsx(le,{children:s.enum.map(n=>{const f=String(n);return e.jsx(ce,{value:f,children:de(s,n)??J(f)},f)})})]});else if(s["x-link-entity-type"])x=e.jsx(Fe,{id:i,value:a,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,entityType:s["x-link-entity-type"],lookupField:s["x-link-lookup-field"]||"slug",numeric:s.type==="number"||s.type==="integer",orgContext:j});else if(s.type==="number"||s.type==="integer")x=e.jsx(me,{id:i,ariaLabel:d,ariaDescribedBy:m,value:a,onChange:c,integer:s.type==="integer",placeholder:`Enter ${u.toLowerCase()}`,readOnly:t});else if(S){const n=M(s.properties),f=new Set(s.required??[]),y=E(a)?a:{};x=Object.keys(s.properties??{}).length===0||!E(a)&&a!==void 0&&a!==null?e.jsx(H,{id:i,value:a,ariaLabel:`${u} JSON object`,ariaDescribedBy:m,readOnly:t,onChange:c}):e.jsx("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3 rounded-md border p-3",children:n.map(([h,T])=>e.jsx(te,{fieldPath:`${l}.${h}`,fieldKey:h,prop:T,value:y[h],onChange:$=>{const b={...y};$===void 0?delete b[h]:b[h]=$,c(b)},isRequired:f.has(h),readonly:t,orgContext:j},h))})}else if(o)x=a!=null&&!oe(a)?e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c}):e.jsx(ue,{id:i,value:a,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,ariaLabel:d,ariaDescribedBy:m,readOnly:t,showHelp:!d,onChange:c});else if(v&&s.items){const n=Array.isArray(a)?a:[],f=M(s.items.properties),y=new Set(s.items.required??[]),h=s.maxItems===void 0||n.length<s.maxItems,T=s.minItems===void 0||n.length>s.minItems;x=!Array.isArray(a)&&a!==void 0&&a!==null||Object.keys(s.items.properties??{}).length>0&&n.some($=>!E($))?e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:"object",minItems:s.minItems,maxItems:s.maxItems,onChange:c}):Object.keys(s.items.properties??{}).length===0?e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No rows"}):n.map(($,b)=>e.jsxs("fieldset",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("legend",{className:"px-1 text-xs font-medium text-muted-foreground",children:["Row ",b+1]}),e.jsx(H,{id:`${i}-${b}-json`,value:$,ariaLabel:`${u} row ${b+1} JSON object`,readOnly:t,onChange:B=>{const g=[...n];g[b]=B,c(g)}}),t?null:e.jsxs(O,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((B,g)=>g!==b)),children:[e.jsx(U,{className:"mr-1.5 h-4 w-4"}),"Remove row"]})]},`${l}.${b}`)),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]}):e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Be,{children:[e.jsx(De,{children:e.jsxs(C,{children:[f.map(([$,b])=>e.jsxs(X,{children:[I($,b),y.has($)?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]},$)),t?null:e.jsx(X,{className:"w-12"})]})}),e.jsx(Ee,{children:n.length===0?e.jsx(C,{children:e.jsx(P,{colSpan:f.length+(t?0:1),className:"text-sm text-muted-foreground",children:"No rows"})}):n.map(($,b)=>{const B=E($)?$:{};return e.jsxs(C,{children:[f.map(([g,D])=>e.jsx(P,{className:"align-top",children:e.jsx(se,{fieldPath:`${l}.${b}.${g}`,fieldKey:g,prop:D,ariaLabel:I(g,D),value:B[g],onChange:_=>{const p=[...n],F={...B};_===void 0?delete F[g]:F[g]=_,p[b]=F,c(p)},isRequired:y.has(g),readonly:t,orgContext:j})},g)),t?null:e.jsx(P,{className:"align-top",children:e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((g,D)=>D!==b)),children:e.jsx(U,{className:"h-4 w-4"})})})]},`${l}.${b}`)})})]})}),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]})}else if(s.type==="array")x=e.jsx(k,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c});else if(s.format==="date")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,clearable:!w});else if(s.format==="date-time")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,includeTime:!0,clearable:!w});else{const n=s.format==="uri"||s.format==="url";x=e.jsx(L,{id:i,"aria-label":d,"aria-describedby":m,type:n?"url":"text",value:a??"",onChange:f=>c(f.target.value||void 0),placeholder:n?"https://example.com":`Enter ${u.toLowerCase()}`,disabled:t})}return x}function te({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,control:j,orgContext:d,customControl:m}){const u=I(r,s),i=ve(s),t=ee(l),S=i?`${t}-description`:void 0,v=i?e.jsx("p",{id:S,className:"text-xs text-muted-foreground",children:i}):null,o=j?e.jsx(Oe,{control:j}):null,x=m??e.jsx(se,{fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:d,helpId:S});if(s.type==="boolean"){const f=e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[x,e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5 font-normal",children:[u,o]})]});return v?e.jsxs("div",{className:"space-y-1",children:[f,v]}):f}const n=s.type==="object"||!!s.properties||s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties);return e.jsxs("div",{className:"space-y-1.5",children:[n?e.jsxs("p",{id:`${t}-label`,className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}):e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}),x,v]})}function Ve(l){const r={};for(const[s,a]of Object.entries(l)){const c=Te(a);c!==void 0&&(r[s]=c)}return r}function Me({schema:l,values:r,onValuesChange:s,readonly:a=!1,fieldControls:c,orgContext:w,renderControl:N}){const j=l,d=j?.properties,m=new Set(j?.required??[]),u=(i,t)=>{s({...r,[i]:t})};return!d||Object.keys(d).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:M(d).map(([i,t])=>"x-measure"in t||"x-dimension"in t?null:e.jsx(te,{fieldPath:i,fieldKey:i,prop:t,value:r[i],onChange:S=>u(i,S),isRequired:m.has(i),readonly:a,control:c?.[i],orgContext:w,customControl:N?.(i,t,r[i])},i))})}export{Me as D,se as S,Ve as c};
2
+ //# sourceMappingURL=dynamic-schema-form-D3KnzCsW.js.map
@@ -0,0 +1,2 @@
1
+ import{c as x,n as C,j as e,bg as _,bh as m,bi as S,bj as b,bk as c,fM as u,dC as w}from"./index-C2TCKJDP.js";const h="__connection_picker_create_new__";function E({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:o=!1,ariaLabel:p="Connection"}){const f=x(),l=C().org?.slug,i=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(_,{value:r,onValueChange:j,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[o?e.jsxs(e.Fragment,{children:[e.jsx(c,{value:"workspace",children:"Current workspace"}),i.length>0?e.jsx(u,{}):null]}):null,i.map(t=>e.jsx(c,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[i.length>0||o?e.jsx(u,{}):null,e.jsx(c,{value:h,children:"Connect an app…"})]}):null]})]})}function k(s){const r=[];for(const n of s)typeof n.id=="number"&&r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...k(n.children));return r}export{E as C,k as f};
2
+ //# sourceMappingURL=entity-options-IUdQ-64R.js.map
@@ -0,0 +1,2 @@
1
+ import{dP as we,r as E,bX as Se,j_ as S,ga as Re,ej as te,j as e,B as N,u as Q,jS as Ee,m as se,gk as me,j$ as Fe,M as De,c as he,b as Ce,bY as B,n as Le,w as Be,el as X,eH as Pe,jT as Te,k0 as Ve,cL as $e,c9 as ae,fB as Me,gf as Oe,cz as Ie,hy as Ae,hz as ze,hA as Ue,hB as He,hC as Ke,k1 as We,c0 as qe,T as K,U as ne,eK as Ge,a3 as Xe,g8 as ie,eV as W,cw as Ye,L as q,cx as G}from"./index-C2TCKJDP.js";import{N as Qe,d as Je,f as Ze,g as et,S as tt,h as st}from"./entity-pages-DJNSQrfB.js";import{R as at}from"./record-activity-BCpNKaUo.js";import{D as nt}from"./dynamic-schema-form-D3KnzCsW.js";import{r as it,V as ot}from"./views-access-required-BerT4Z1d.js";import{a as pe,V as oe,M as rt,b as lt}from"./view-param-filters-Bp84PUMd.js";import{m as ct,j as Y,d as dt,o as re,c as fe,R as xe,q as ut,r as mt}from"./renderer-ucwCQmBk.js";import"./table-1O-ik4_O.js";import{a as ht}from"./source-record-panels-LJIWGtHb.js";import{r as pt,R as le,b as ft}from"./events-feed-DwOkLk6A.js";import{a as xt}from"./record-session-KuEDuF3S.js";import"./schema-value-CefbtPIY.js";import"./home-toolbar-CpCcHA6z.js";import"./filter-editors-DQ5V4Cvh.js";import"./subDays-DwIOMzYC.js";import"./runs-B_iywKWb.js";import"./event-kind-options-fHAIXu24.js";import"./clients-CydgUHrc.js";import"./client-activity-scopes-B7xVaUA-.js";import"./client-rows-B3LULJxW.js";import"./run-initiator-8vdkq-3o.js";import"./list-skeleton-bQAZ0hQp.js";import"./use-automations-lV8PuE8L.js";import"./agent-loading-shells-BupiSjR-.js";import"./member-scope-gate-Doic_6qX.js";import"./app-bridge-C4nPtae3.js";import"./card-rE4Ctuy6.js";import"./definition-comparison-3zKUSTt8.js";import"./json-diff-CJK-gzCt.js";import"./code-editor-UppEMWpt.js";import"./index-Vcq4gwWv.js";import"./copy-button-1ALlvZU1.js";import"./device-automation-Dp3faMvp.js";function gt(t,s){if(t===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in t)return t;if(typeof t=="function")return{shouldBlockFn:async()=>await t(),enableBeforeUnload:!0,withResolver:!1};const i=!!(t.condition??!0),n=t.blockerFn;return{shouldBlockFn:async()=>i&&n!==void 0?await n():i,enableBeforeUnload:i,withResolver:n===void 0}}function vt(t,s){const{shouldBlockFn:i,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:c=!1}=gt(t),o=we(),{history:r}=o,[u,x]=E.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return E.useEffect(()=>{const p=async f=>{function l(j){const b=o.parseLocation(j),v=o.getMatchedRoutes(b.pathname);return v.foundRoute===void 0?{routeId:"__notFound__",fullPath:b.pathname,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}:{routeId:v.foundRoute.id,fullPath:v.foundRoute.fullPath,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}}const m=l(f.currentLocation),d=l(f.nextLocation);if(m.routeId==="__notFound__"&&d.routeId!=="__notFound__")return!1;const h=await i({action:f.action,current:m,next:d});if(!c)return h;if(!h)return!1;const k=await new Promise(j=>{x({status:"blocked",current:m,next:d,action:f.action,proceed:()=>j(!1),reset:()=>j(!0)})});return x({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),k};return a?void 0:r.block({blockerFn:p,enableBeforeUnload:n})},[i,n,a,c,r,o]),u}function U(t,s){return te(Y(t))===te(Y(s))}function jt(t,s){const i={};for(const n of new Set([...Object.keys(t),...Object.keys(s)]))U(t[n],s[n])||(i[n]=Y(t[n])??null);return Object.keys(i).length>0?i:void 0}function yt(t,s){return[...new Set([...Object.keys(t),...Object.keys(s)])].filter(i=>{try{return!U(t[i],s[i])}catch{return!0}})}function ce(t,s){return{name:t.name,slug:t.slug,metadata:ct(t.metadata??{},s)}}function bt(t,s,i){const n=new Set(i),a={},c={},o=new Set([...Object.keys(t.values.metadata),...Object.keys(t.baseline.metadata),...Object.keys(s.metadata)]);for(const r of o){const u=n.has(r),x=u?t.values.metadata[r]:t.baseline.metadata[r],p=U(x,s.metadata[r])?x:s.metadata[r];p!==void 0&&(a[r]=p);let f=!1;if(!u)try{f=!U(t.values.metadata[r],t.baseline.metadata[r])}catch{f=!0}const l=f?t.values.metadata[r]:p;l!==void 0&&(c[r]=l)}return{baseline:{name:s.name,slug:s.slug,metadata:a},values:{name:s.name,slug:s.slug,metadata:c}}}function kt({entity:t,schema:s,orgContext:i}){const n=E.useMemo(()=>ce(t,s),[t,s]),a=Se(S(t),n,s),c=Re(i),{values:o,baseline:r,commit:u}=a,x=E.useMemo(()=>yt(o.metadata,r.metadata),[o.metadata,r.metadata]),p=o.name!==r.name||o.slug!==r.slug,f=E.useCallback((m,d)=>a.setValues(h=>({...h,metadata:{...h.metadata,[m]:d}})),[a.setValues]),l=async({note:m}={})=>{if(typeof t.id!="number")throw new Error("Source records are read-only");if(!a.canSubmit)return null;const d=jt(o.metadata,r.metadata),h=o.name.trim()!==r.name.trim();if(!d&&!p)return null;const k=await c.mutateAsync({entityId:t.id,name:h?o.name.trim():void 0,slug:o.slug,metadata:d,field_note:d&&m?.trim()||void 0}),j=ce(k.entity,s);return u(b=>bt(b,j,Object.keys(d??{})),j),{held:k.blocked_fields??[],approvalUrl:k.approval_url}};return{values:o,baseline:r,revision:a.revision,setValues:a.setValues,setMetadataField:f,reset:a.reset,save:l,saving:c.isPending,dirtyKeys:x,identityDirty:p,isDirty:p||x.length>0,canSubmit:a.canSubmit,hasConflict:a.hasConflict,hasInvalidInput:a.hasInvalidInput}}const _t=3,Nt=50;function ge(t){const s=E.useRef(null);return E.useEffect(()=>{t&&(s.current?.scrollIntoView?.({block:"start"}),s.current?.focus())},[t]),s}function T({headingRef:t,children:s}){return e.jsx("h3",{ref:t,tabIndex:-1,className:"text-xs font-medium uppercase tracking-wide text-muted-foreground outline-none",children:s})}function wt({entityId:t,entityName:s,ownerSlug:i,orgContext:n,focus:a,collapsed:c=!1}){const o=Q(),r=ge(a),{data:u,isLoading:x,isError:p,refetch:f}=Ee(t,n,{limit:Nt});if(t===void 0)return null;if(x)return e.jsxs("section",{className:"space-y-2","aria-busy":"true",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(se,{className:"h-4 w-24"}),e.jsx(se,{className:"h-6 w-full rounded-md"})]});if(p||!u)return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Could not load this record's links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void f(),children:"Retry"})]})]});if(u.countsByType.length===0&&!u.hasMore&&!u.failures?.length)return a?e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No links to other records yet."})]}):null;if(c){const l=u.countsByType.flatMap(m=>{const d=m.count===1?u.rows.find(h=>h.relationship_type_slug===m.relationship_type_slug):void 0;return d?[pt(d,m.relationship_type_name)]:[m.relationship_type_name,String(m.count)]});return e.jsxs("section",{className:"space-y-1","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),e.jsx("p",{"data-testid":"linked-summary",className:"truncate text-sm text-muted-foreground",children:l.join(" · ")})]})}return e.jsxs("section",{className:"space-y-3","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),u.hasMore&&o?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>o.open({href:"",key:`record-links:${t}`,title:"Linked records",recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,label:"Linked records"}}),children:"Browse linked records"}):null,u.countsByType.map(l=>{const m=u.rows.filter(h=>h.relationship_type_slug===l.relationship_type_slug).slice(0,_t),d=l.count>m.length;return e.jsxs("div",{className:"space-y-1 text-sm",children:[d||m.length===0?e.jsxs("p",{className:"text-muted-foreground",children:[l.relationship_type_name,d?e.jsxs("span",{className:"tabular-nums text-muted-foreground/70",children:[" ","· ",l.count,u.countsScope==="page"?" shown":""]}):null]}):null,e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[m.map(h=>e.jsx(ft,{row:h,label:l.relationship_type_name,entityId:t,ownerSlug:i,orgContext:n},h.id)),d&&o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary",onClick:()=>o.open({href:"",key:`record-links:${t}:${l.relationship_type_slug}`,title:`${l.relationship_type_name} · ${l.count}`,recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,relationshipType:l.relationship_type_slug,label:l.relationship_type_name}}),children:["Show all ",l.count]}):null]})]},l.relationship_type_slug)})]})}function St({record:t,ownerSlug:s,orgContext:i,focus:n}){const[a,c]=E.useState(n),o=ge(n);return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:o,children:"Linked"}),a?e.jsx(ht,{record:t,ownerSlug:s,orgContext:i}):e.jsx(N,{type:"button",variant:"outline",size:"sm",className:"h-7",onClick:()=>c(!0),children:"Find linked records"})]})}const Rt="$name";function ve({outcome:t,schema:s}){if(!t||t.held.length===0)return null;const i=s?.properties??{},n=t.held.map(a=>a===Rt?"Name":dt(a,i[a]??{}));return e.jsxs("div",{role:"status",className:"rounded-md bg-amber-500/10 px-3 py-2 text-sm text-amber-700 dark:text-amber-300",children:[n.join(", ")," ",n.length===1?"needs":"need"," approval before ",n.length===1?"it changes":"they change",".",t.approvalUrl?e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:t.approvalUrl,className:"underline",children:"Review"})]}):null]})}const Et=320,Ft={},Dt=()=>{};function Ct({view:t,orgSlug:s,recordUrl:i,scope:n}){const a=Q(),c=`${i}${me(t.key)}`,o=a?()=>a.open({href:c,title:t.name}):void 0;return e.jsxs("section",{className:"min-w-0 rounded-lg border","data-testid":"view-card","data-view":t.key,children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium",children:t.name}),t.description?e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.description}):null]}),o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:o,"aria-label":`Open ${t.name}`,children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),"Open"]}):null]}),e.jsx("div",{className:"px-4 pb-3",children:e.jsx(pe,{orgSlug:s,viewKey:t.key,scope:n,params:Ft,onParamsChange:Dt,contentHash:t.content_hash,title:t.name,minHeight:64,displayMode:"inline",maxHeight:Et,onRequestDisplayMode:o?r=>{r==="fullscreen"&&o()}:void 0})})]})}function Lt({recordUrl:t,dirty:s,onDiscard:i}){const n=vt({disabled:!s,enableBeforeUnload:s,withResolver:!0,shouldBlockFn:({next:c})=>c.pathname!==t&&!c.pathname.startsWith(`${t}${me("")}`)}),a=n.status==="blocked";return e.jsx(Ae,{open:a,onOpenChange:c=>{!c&&a&&n.reset()},children:e.jsxs(ze,{className:"max-w-sm",children:[e.jsxs(Ue,{children:[e.jsx(He,{children:"Discard unsaved changes?"}),e.jsx(Ke,{children:"This record has edits that are not saved. Leaving discards them."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>a&&n.reset(),children:"Keep editing"}),e.jsx(N,{type:"button",variant:"destructive",onClick:()=>{a&&(i(),n.proceed())},children:"Discard"})]})]})})}const de=6;function Bt({entity:t,ownerSlug:s,orgContext:i,recordUrl:n,schema:a,entityTypeName:c,isTypeLoading:o,record:r,canEdit:u,editing:x,onEditingChange:p,outcome:f,onSaved:l,formId:m,fieldLimit:d,onDeleted:h}){const k=x&&u,j=Q(),b={entity:{id:S(t),name:t.name,entity_type:t.entity_type},ownerSlug:s,orgContext:i,schema:a,record:r,editing:k};xt(b);const v=j?.item?.recordField,D={ownerSlug:s,orgContext:i,controls:t.field_controls,dirtyKeys:r.dirtyKeys,openField:j?L=>j.open(it(b,L.key)):void 0,openFieldKey:v?.entityId===S(t)?v.field:void 0},C=e.jsx(Lt,{recordUrl:n,dirty:k&&r.isDirty,onDiscard:()=>{r.reset(),p(!1)}});if(o)return e.jsx(Ie,{rows:6});if(k)return e.jsxs(e.Fragment,{children:[C,e.jsx(Pt,{formId:m,entity:t,entityTypeName:c,schema:a,record:r,orgContext:i,renderControl:(L,P,F)=>ut(P)?e.jsx(mt,{field:{key:L,prop:P},value:F,context:D}):void 0,onSaved:l,onDeleted:h,onDone:()=>p(!1)})]});const R=fe(r.revision);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ve,{outcome:f,schema:a}),e.jsx(xe,{fields:R,fieldLimit:d,values:r.values.metadata,context:D})]})}function Pt({formId:t,entity:s,entityTypeName:i,schema:n,record:a,orgContext:c,renderControl:o,onSaved:r,onDeleted:u,onDone:x}){const p=We(),f=s.field_controls,{name:l,slug:m,metadata:d}=a.values,h=g=>a.setValues(y=>({...y,name:g})),k=g=>a.setValues(y=>({...y,slug:g})),j=g=>a.setValues(y=>({...y,metadata:g})),[b,v]=B(S(s),""),[D,C]=B(S(s),null),[R,L]=B(S(s),null),[P,F]=B(S(s),!1),[w,V]=B(S(s),null),$=a.dirtyKeys.length>0,I=async g=>{if(g.preventDefault(),!!a.canSubmit){if(C(null),!l.trim()){C("Name is required");return}try{const y=await a.save({note:b});L(y),r(y),v(""),y?.held.length||x()}catch(y){C(y instanceof Error?y.message:"Failed to update entity")}}},H=async()=>{V(null);try{if(typeof s.id!="number")throw new Error("Source records are read-only");await p.mutateAsync({entityId:s.id}),F(!1),u?.()}catch(g){V(g instanceof Error?g.message:"Failed to delete entity")}},A=[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 e.jsxs("form",{id:t,onSubmit:I,className:"space-y-4",children:[e.jsx(qe,{visible:a.hasConflict,onReload:a.reset}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(K,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ne,{id:"sidebar-name",value:l,onChange:g=>h(g.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(ne,{id:"sidebar-slug",value:m,onChange:g=>k(g.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),a.revision&&Object.keys(a.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{}),e.jsx(nt,{schema:a.revision,values:d,onValuesChange:j,fieldControls:f,orgContext:c,renderControl:o})]}),$&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:b,onChange:g=>v(g.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),D&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx(ve,{outcome:R,schema:n}),P?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(Xe,{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,'"?']}),A&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",A,". This cannot be easily undone."]})]})]}),w&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:w}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{F(!1),V(null)},children:"Cancel"}),e.jsx(N,{type:"button",variant:"destructive",size:"sm",onClick:H,disabled:p.isPending,children:p.isPending?"Deleting...":`Delete ${i||"entity"}`})]})]}):e.jsx("div",{className:"pt-2",children:e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>F(!0),children:"Delete"})})]})}function je(t,s){const i=new Set(t.measure_columns??[]),n=s?.properties??{};return Object.keys(t.metadata??{}).filter(a=>a!=="id"&&a!=="slug"&&a!=="name"&&!Me(n[a])&&n[a]?.const===void 0).map(a=>({key:a,prop:n[a]??{},label:n[a]?.["x-table-label"]??(i.has(a)?a:Oe(a.replace(/_/g," "))),numeric:i.has(a)}))}function Tt({entity:t,schema:s,ownerSlug:i,fieldLimit:n}){const a=je(t,s);return e.jsxs("div",{children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Managed by the source"}),e.jsx(xe,{fields:a,fieldLimit:n,values:t.metadata??{},context:{ownerSlug:i}})]})}const ue="owletto:record-details-expanded";function Vt(){const[t,s]=E.useState(()=>{try{return window.localStorage.getItem(ue)==="1"}catch{return!1}});return[t,n=>{s(n);try{window.localStorage.setItem(ue,n?"1":"0")}catch{}}]}function $t({namespace:t,entity:s,recordUrl:i,viewKey:n,title:a,onDeleted:c}){const o=De({strict:!1}),r=he(),u=E.useRef(null),x=Ce(u,Qe),[p,f]=Vt(),[l,m]=B(S(s),!1),d={slug:t.slug,organizationId:t.id},{isMember:h,isPublic:k,isLoading:j}=Le(t.slug),b=h||k,v=Be({...d,organizationId:h?t.id:null}),{data:D,isLoading:C}=X(s.entity_type,d),R=D?.metadata_schema,{isAdmin:L,isLoading:P}=Pe(h?d.organizationId:void 0),F=h&&L&&!P&&!s.is_derived,w=kt({entity:s,schema:R,orgContext:d}),[V,$]=B(S(s),null),I=`record-form-${s.id}`,H=l&&F,A=b?v.data??[]:[],g=Te(A,{type:s.entity_type,id:S(s)}),y=Ve(g,n),z=!n&&o.tab==="relationships",ye=_=>void r({to:".",search:_,replace:!0}),J={type:s.entity_type,entity:s.is_derived?s.slug:s.id??s.slug},M=x&&!p&&!l&&!z,Z=s.is_derived?re(je(s,R),s.metadata??{}).length:re(fe(w.revision),w.values.metadata).length,ee=M?de:void 0,be=e.jsxs("div",{className:"space-y-6",children:[s.is_derived?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{entity:s,schema:R,ownerSlug:t.slug,fieldLimit:ee}),e.jsx(St,{record:{type:s.entity_type,key:s.slug},ownerSlug:t.slug,orgContext:d,focus:z})]}):e.jsxs(e.Fragment,{children:[e.jsx(Bt,{entity:s,ownerSlug:t.slug,orgContext:d,recordUrl:i,schema:R,entityTypeName:D?.name,isTypeLoading:C,record:w,canEdit:F,editing:l,onEditingChange:m,outcome:V,onSaved:$,formId:I,fieldLimit:ee,onDeleted:c}),e.jsx(wt,{entityId:typeof s.id=="number"?s.id:void 0,entityName:s.name,ownerSlug:t.slug,orgContext:d,focus:z,collapsed:M})]}),x&&!l&&!z?e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary","aria-expanded":!M,onClick:()=>f(M),children:M?Z>de?`Show all ${Z} fields`:"Show all details":"Show fewer"}):null]}),ke=_=>e.jsx(Ze,{rootRef:u,narrow:x,details:be,summary:e.jsx(et,{entity:s,schema:R}),children:_}),_e=H?e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{w.reset(),$(null),m(!1)},children:"Cancel"}),e.jsx(N,{type:"submit",form:I,size:"sm",disabled:!w.canSubmit||!w.isDirty||w.saving||!w.values.name.trim(),children:w.saving?"Saving...":"Save"})]}):F&&!C?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:()=>{$(null),m(!0)},children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"Edit"]}):null,O=_=>e.jsx(Je,{entity:s,owner:t.slug,schema:R,title:a??null,actions:_e,layout:"content",children:_});if(n&&!b)return O(j?null:e.jsx(ot,{}));if(n&&v.data===void 0)return O(v.isError?e.jsx(oe,{onRetry:()=>void v.refetch()}):null);if(y.kind==="missing")return O(e.jsx(rt,{viewKey:y.key,backTo:i,backLabel:`Back to ${s.name}`}));if(y.kind==="view"){const{view:_}=y;return O(e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx(lt,{decls:_.params,params:ae(o),onParamsChange:Ne=>void r({to:".",search:Ne})}),e.jsx(pe,{orgSlug:t.slug,viewKey:_.key,scope:J,params:ae(o),onParamsChange:ye,contentHash:_.content_hash,title:_.name,minHeight:320})]}))}return O(ke(e.jsxs("div",{className:"min-w-0 space-y-4",children:[b&&v.isError&&e.jsx(oe,{onRetry:()=>void v.refetch()}),g.map(_=>e.jsx(Ct,{view:_,orgSlug:t.slug,recordUrl:i,scope:J},_.key)),e.jsxs("section",{"aria-labelledby":"record-activity-heading",className:"min-w-0",children:[e.jsx("h2",{id:"record-activity-heading",className:"mb-2 text-sm font-medium text-muted-foreground",children:"Activity"}),e.jsx(at,{entity:s,organizationId:t.id,ownerSlug:t.slug})]})]})))}function Mt(t){return t?.trim()?t:void 0}function vs({namespace:t,path:s,entity:i,viewKey:n}){const a=he(),{data:c}=X(i.entity_type,{slug:t.slug}),o=s[0]?.entity_type??i.entity_type,{data:r}=X(o,{slug:t.slug}),u=Mt(c?.icon),x=s.map(l=>({entity_type:l.entity_type,slug:l.slug})),p=`/${t.slug}/${ie(i.entity_type)}`,f=W(t.slug,x);return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:[e.jsx(Ye,{crumbs:[...o==="$member"?[]:[e.jsx(q,{to:"/$owner/data",params:{owner:t.slug},className:G,children:"Memory"},"memory")],e.jsx(q,{to:`/${t.slug}/${ie(o)}`,className:G,children:o==="$member"?"Team":r?.name??o},"type"),...s.slice(0,-1).map((l,m)=>e.jsx(q,{to:W(t.slug,x.slice(0,m+1)),className:G,children:l.name},l.id))],current:i.name}),e.jsx($t,{namespace:t,entity:i,recordUrl:f,viewKey:n,title:e.jsx(st,{entity:i,schema:c?.metadata_schema,icon:u}),onDeleted:()=>{const l=s.slice(0,-1);l.length>0?a({to:W(t.slug,l)}):a({to:p})}})]})}export{vs as EntityPage};
2
+ //# sourceMappingURL=entity-page-B3Im65EI.js.map
@@ -0,0 +1,2 @@
1
+ import{r as x,j as e,bp as ue,i as H,e3 as me,e4 as xe,B as T,gh as he,e7 as pe,dE as ge,fi as ne,gf as F,fB as fe,dm as P,a2 as q,L as A,eV as je,b as ve,m as E}from"./index-C2TCKJDP.js";import{p as S,n as be,e as re,b as ye,g as Ne,f as J,R as we,c as _e}from"./renderer-ucwCQmBk.js";import{S as U}from"./schema-value-CefbtPIY.js";import{T as Se,a as ke,b as $,c as Y,d as Ce,e as K}from"./table-1O-ik4_O.js";var Ee="Separator",ee="horizontal",Re=["horizontal","vertical"],ae=x.forwardRef((t,s)=>{const{decorative:n,orientation:a=ee,...i}=t,o=Le(a)?a:ee,h=n?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return e.jsx(ue.div,{"data-orientation":o,...h,...i,ref:s})});ae.displayName=Ee;function Le(t){return Re.includes(t)}var oe=ae;const Me=x.forwardRef(({className:t,orientation:s="horizontal",decorative:n=!0,...a},i)=>e.jsx(oe,{ref:i,decorative:n,orientation:s,className:H("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...a}));Me.displayName=oe.displayName;function Ae({choices:t,visible:s,onChange:n}){return e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:e.jsx(he,{className:"h-4 w-4"})})}),e.jsxs(pe,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),t.map(a=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[e.jsx("input",{type:"checkbox",checked:!s||s.includes(a.field),onChange:i=>{const o=s??t.map(c=>c.field);n(i.target.checked?[...o,a.field]:o.filter(c=>c!==a.field))}}),a.label]},a.field))]})]})}function Pe({direction:t}){return t?e.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:t==="asc"?"Sort ascending":"Sort descending"}),t==="asc"?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):e.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:"Sort"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function te(t,s){const n=t?.properties;if(n)return Object.entries(n).find(([,a])=>a[s])?.[0]}function Te(t){const s=t.trim(),n=s.split(/[\s._@/-]+/).filter(Boolean),a=n.length>=2?`${n[0][0]}${n[1][0]}`:(n[0]??s).slice(0,2);let i=0;for(let o=0;o<s.length;o++)i=i*31+s.charCodeAt(o)>>>0;return{initials:a.toUpperCase()||"?",hue:i%360}}function Fe(t){const[s,n]=x.useState();return x.useEffect(()=>{if(!t||!globalThis.crypto?.subtle){n(void 0);return}let a=!1;const i=t.trim().toLowerCase();return crypto.subtle.digest("SHA-256",new TextEncoder().encode(i)).then(o=>{a||n(Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join(""))}),()=>{a=!0}},[t]),s?`https://www.gravatar.com/avatar/${s}?d=identicon&s=80`:void 0}function ie({metadata:t,metadataSchema:s,name:n,typeIcon:a,className:i="h-6 w-6",iconClassName:o="h-5 w-5",initialsFallback:c=!1}){const h=te(s,"x-image"),j=te(s,"x-email"),y=h&&t?.[h]||void 0,v=j&&t?.[j]||void 0,N=Fe(y?void 0:v),w=y||N,[k,R]=x.useState(!1);if(x.useEffect(()=>{R(!1)},[w]),w&&!k)return e.jsx("img",{src:w,alt:n,referrerPolicy:"no-referrer",onError:()=>R(!0),className:H("rounded-full object-cover border border-border",i)});if(c){const L=n.trim()||v||Oe(t,s)||n,{initials:O,hue:z}=Te(L);return e.jsx("span",{role:"img","aria-label":n,className:H("inline-grid place-items-center rounded-full border border-border font-semibold text-white select-none",i),style:{background:`oklch(0.55 0.13 ${z})`,fontSize:"0.85em"},children:O})}return e.jsx(ge,{icon:a,className:o})}function Oe(t,s){if(!t)return;const n=s?.properties,a=["email","handle","username","login","github","x_handle","slug"],i=Object.keys(n||t);for(const o of i)if(a.includes(o.toLowerCase())){const c=t[o];if(typeof c=="string"&&c.trim())return c}}function _({column:t,children:s,alignRight:n=!1}){return e.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${n?" ml-auto":""}`,onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[s,e.jsx(Pe,{direction:t.getIsSorted()})]})}function se(t,s,n){const a=ne(t?.properties).filter(([o,c])=>(!s||o!=="name")&&!c["x-image"]&&c["x-table-column"]===!0);if(a.length)return a.map(([o,c])=>({field:o,label:c["x-table-label"]??F(o.replaceAll("_"," "))}));if(!s)return[];const i=n.find(o=>Object.keys(S(o.metadata)).length>0);return Object.keys(S(i?.metadata)).filter(o=>o!=="id"&&o!=="slug"&&o!=="name"&&!fe(t?.properties?.[o])).map(o=>({field:o,label:F(o.replaceAll("_"," "))}))}function ze(t){return t.some(s=>Object.hasOwn(S(s.metadata),"name"))}function Ie(t,s){return P(t,re(s))}function Be(t){return`${t.entityType}:${t.lookupField}`}const $e=new Set(["stage","category","round_type","investor_type"]);function Ke(t,s){const n=t.toLowerCase();return n==="mrr"||n==="arr"||n==="revenue"||n==="valuation"||n==="funding_raised"||n==="fund_size"||n.endsWith("_usd")||s.description?.toLowerCase().includes("usd")===!0}function He(t,s){if(Ke(t,s))return"currency";if($e.has(t)||t.endsWith("_slug"))return"enum"}function Ue({entities:t,owner:s,schema:n,entityTypeIcon:a,isDerived:i,measureColumns:o,linkedEntityLookups:c,hasAnyParents:h,sorting:j,onSortingChange:y,visibleColumns:v,columnChoices:N,onVisibleColumnsChange:w,page:k,pageSize:R,totalCount:L,hasMore:O,pageTitle:z,onPrevPage:le,onNextPage:ce}){const M=N?.length&&w?e.jsx(Ae,{choices:N,visible:v,onChange:w}):null,f=n?.properties,V=!i||ze(t),W=x.useMemo(()=>f?Object.fromEntries(Object.entries(f).flatMap(([l,r])=>r["x-link-entity-type"]?[[l,{entityType:r["x-link-entity-type"],lookupField:r["x-link-lookup-field"]||"slug"}]]:[])):{},[f]),C=x.useMemo(()=>f?se({properties:f},i,[]).map(({field:r})=>[r,f[r]]).map(([r,u])=>{const m=W[r],d=m?c[Be(m)]:void 0;return{id:i?r:`meta_${r}`,accessorFn:p=>{const g=S(p.metadata);return be(g[r],u.enum)},header:({column:p})=>{const g=u["x-table-label"]||u.title||u.description||F(r.replace(/_/g," "));return i?e.jsx(_,{column:p,children:g}):g},cell:({getValue:p})=>e.jsx(U,{value:p(),prop:u,format:He(r,u),className:"text-muted-foreground",resolveLink:d?g=>{const b=d[g];return b?{label:b.name,to:P(s,[{entity_type:b.entity_type,slug:b.slug}])}:void 0}:void 0})}}):[],[i,W,c,s,f]),D=x.useMemo(()=>new Set(o),[o]),I=x.useMemo(()=>!i||C.length>0?[]:se({properties:f},!0,t).map(({field:r})=>r).map(r=>{const u=D.has(r);return{id:r,accessorFn:m=>S(m.metadata)[r],header:({column:m})=>e.jsxs(_,{column:m,children:[u?r:F(r.replace(/_/g," ")),u&&e.jsx(q,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:m})=>e.jsx(U,{value:m(),prop:f?.[r],className:u?"tabular-nums":"text-muted-foreground"}),meta:u?{align:"right"}:void 0}}),[i,C,t,D,f]),G=x.useMemo(()=>{const l=n?.["x-table-relationships"];return!l||l.length===0?[]:l.map(r=>({id:`rel_${r.relationship_type}`,accessorFn:u=>u.relationships?.[r.relationship_type]??[],header:r.label,cell:({getValue:u})=>{const m=u();return!m||m.length===0?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:m.map((d,p)=>{const g=P(s,[{entity_type:d.entity_type,slug:d.slug}]);return e.jsxs("span",{children:[e.jsx(A,{to:g,className:"text-primary hover:underline",onClick:b=>b.stopPropagation(),children:d.name}),p<m.length-1&&","]},d.id)})})}}))},[s,n]),Q=x.useMemo(()=>h||t.some(r=>r.parent_name&&r.parent_slug&&r.parent_entity_type)?[{id:"parent",accessorFn:r=>r.parent_name,header:"Parent",cell:({row:r})=>{if(!r.original.parent_name||!r.original.parent_slug||!r.original.parent_entity_type)return e.jsx("span",{className:"text-muted-foreground",children:"-"});const u=P(s,[{entity_type:r.original.parent_entity_type,slug:r.original.parent_slug}]);return e.jsx(A,{to:u,className:"text-primary hover:underline",children:r.original.parent_name})}}]:[],[t,h,s]),X=x.useMemo(()=>{const l=[],r=t.some(d=>(d.total_content??0)>0),u=t.some(d=>(d.active_connections??0)>0),m=t.some(d=>(d.automations_count??0)>0);return r&&l.push({accessorKey:"total_content",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Activity"}),cell:({row:d,getValue:p})=>{const g=p()??0;if(g===0)return e.jsx("span",{className:"tabular-nums",children:"0"});const b=re(d.original);return e.jsx(A,{to:je(s,b),className:"tabular-nums hover:underline",children:g})},meta:{align:"right"}}),u&&l.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:d})=>{const p=d();return p&&p>0?e.jsxs(q,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[p," active"]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),m&&l.push({accessorKey:"automations_count",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Automations"}),cell:({getValue:d})=>e.jsx("span",{className:"tabular-nums",children:d()??0}),meta:{align:"right"}}),l},[t,s]),Z=x.useMemo(()=>[{accessorKey:"name",header:({column:l})=>V?e.jsx(_,{column:l,children:"Name"}):"Name",cell:({row:l})=>{const r=S(l.original.metadata);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{metadata:r,metadataSchema:n,name:l.original.name,typeIcon:a,className:"h-6 w-6 shrink-0"}),e.jsx("div",{className:"min-w-0",children:(()=>{const u=Ie(s,l.original);return e.jsx(A,{to:u,className:"block max-w-56 truncate font-medium hover:underline",title:l.original.name,children:l.original.name})})()})]})}},...Q,...C,...I,...G,...X,...i?[]:[{accessorKey:"created_at",header:({column:l})=>e.jsx(_,{column:l,children:"Created"}),cell:({getValue:l})=>e.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(l()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[s,Q,C,I,G,X,n,a,i,V]),B=ye({data:t,columns:Z,state:{sorting:j,columnVisibility:Object.fromEntries([...C,...I].flatMap(l=>l.id?[[l.id,!v||v.includes(i?l.id:l.id.replace(/^meta_/,""))]]:[]))},onSortingChange:y,getCoreRowModel:Ne(),manualSorting:!0,enableSortingRemoval:!1}),de=t.length>0||k>0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border",children:e.jsxs(Se,{className:"min-w-[48rem]",children:[e.jsx(ke,{children:B.getHeaderGroups().map(l=>e.jsxs($,{children:[l.headers.map(r=>e.jsx(Y,{"aria-sort":r.column.getIsSorted()==="asc"?"ascending":r.column.getIsSorted()==="desc"?"descending":void 0,className:r.column.columnDef.meta?.align==="right"?"text-right":"",children:r.isPlaceholder?null:J(r.column.columnDef.header,r.getContext())},r.id)),M?e.jsx(Y,{className:"w-10 pr-2 text-right",children:M}):null]},l.id))}),e.jsx(Ce,{children:B.getRowModel().rows.length?B.getRowModel().rows.map(l=>e.jsxs($,{children:[l.getVisibleCells().map(r=>e.jsx(K,{className:r.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:J(r.column.columnDef.cell,r.getContext())},r.id)),M?e.jsx(K,{}):null]},l.id)):e.jsx($,{children:e.jsx(K,{colSpan:Z.length+(M?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),de&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:["Showing ",t.length," of ",L," ",z.toLowerCase()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",k+1," of ",Math.max(1,Math.ceil(L/R))]}),e.jsx(T,{variant:"outline",size:"sm",onClick:le,disabled:k===0,children:"Previous"}),e.jsx(T,{variant:"outline",size:"sm",onClick:ce,disabled:!O,children:"Next"})]})]})]})}const Ve=720;function We(){return e.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(E,{className:"h-9 max-w-sm flex-1"}),e.jsx(E,{className:"h-9 w-28"})]}),e.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[e.jsx("div",{className:"border-b px-4 py-3",children:e.jsx(E,{className:"h-3 w-1/3"})}),e.jsx("div",{className:"divide-y",children:Array.from({length:5},(t,s)=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx(E,{className:"h-3 flex-1"}),e.jsx(E,{className:"h-3 w-16 shrink-0"})]},s))})]})]})}function et({title:t,actions:s,controls:n,table:a,children:i,loading:o=!1,error:c=null,onRetry:h,empty:j=e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"No records."})}){return e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[typeof t=="string"?e.jsx("h2",{className:"text-lg font-semibold",children:t}):t,s]}),e.jsxs("div",{children:[n,o?e.jsx(We,{}):c!==null?e.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[c,h?e.jsx(T,{className:"ml-3",variant:"outline",size:"sm",onClick:h,children:"Retry"}):null]}):i!==void 0?i:a?e.jsx(Ue,{...a}):j]})]})}function De(t,s){return s?.properties?ne(s.properties).map(([n,a])=>({key:n,prop:a})):Object.keys(t.metadata??{}).map(n=>({key:n,prop:{}}))}function Ge({entity:t,schema:s,icon:n}){return e.jsxs(e.Fragment,{children:[e.jsx(ie,{metadata:t.metadata,metadataSchema:s?{...s}:void 0,name:t.name,typeIcon:n,className:"h-6 w-6 shrink-0"}),e.jsx("h2",{className:"truncate text-lg font-semibold leading-tight",children:t.name})]})}function Qe({entity:t,schema:s}){const n=_e(s?{...s}:void 0).filter(({key:a,prop:i})=>i["x-table-column"]===!0&&!i["x-image"]&&t.metadata?.[a]!==void 0&&t.metadata[a]!==null&&t.metadata[a]!=="");return n.length?e.jsx("p",{"data-testid":"record-summary",className:"-mt-2 truncate text-sm text-muted-foreground tabular-nums",children:n.map(({key:a,prop:i},o)=>e.jsxs("span",{children:[o>0?" · ":null,e.jsx(U,{value:t.metadata?.[a],prop:i})]},a))}):null}function Xe({details:t,summary:s,children:n,rootRef:a,narrow:i}){return e.jsx("div",{ref:a,className:"min-w-0 space-y-4",children:i?e.jsxs(e.Fragment,{children:[s,e.jsx("section",{"aria-label":"Details","data-testid":"record-details",children:t}),n]}):e.jsxs("div",{className:"grid grid-cols-[18rem_minmax(0,1fr)] gap-6",children:[e.jsx("aside",{className:"sticky top-12 max-h-[calc(100dvh-7rem)] min-w-0 self-start overflow-y-auto overscroll-contain pr-2 pb-16",children:t}),n]})})}function tt({entity:t,owner:s,schema:n,title:a,actions:i,details:o,summary:c,children:h,layout:j="record"}){const y=x.useRef(null),v=ve(y,Ve),N=e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"record-header",className:"sticky top-0 z-30 -mx-4 flex h-12 items-center justify-between gap-3 bg-background px-4 lg:-mx-6 lg:px-6",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:a===void 0?e.jsx(Ge,{entity:t,schema:n}):a}),i]}),j==="content"?h:e.jsx(Xe,{rootRef:y,narrow:v,details:o===void 0?e.jsx(we,{fields:De(t,n),values:t.metadata??{},context:{ownerSlug:s}}):o,summary:c===void 0?e.jsx(Qe,{entity:t,schema:n}):c,children:h})]});return j==="content"?N:e.jsx("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:N})}export{ie as E,Ve as N,Me as S,Ue as a,et as b,We as c,tt as d,se as e,Xe as f,Qe as g,Ge as h};
2
+ //# sourceMappingURL=entity-pages-DJNSQrfB.js.map