upfynai-code 3.0.4 → 3.2.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 (258) hide show
  1. package/README.md +69 -92
  2. package/bin/cli.js +191 -0
  3. package/dist/client/assets/AppContent-M14Au3SB.js +542 -0
  4. package/{client/dist/assets/BrowserPanel-0TLEl-IC.js → dist/client/assets/BrowserPanel-TFKm2NDJ.js} +2 -2
  5. package/dist/client/assets/DashboardPanel-C88HjsCh.js +1 -0
  6. package/dist/client/assets/FileTree-DvO1xnDE.js +1 -0
  7. package/{client/dist/assets/GitPanel-C_xFM-N2.js → dist/client/assets/GitPanel-D-slVlyy.js} +2 -2
  8. package/dist/client/assets/LoginModal-Chi4SYcr.js +21 -0
  9. package/{client/dist/assets/MarkdownPreview-CESjI261.js → dist/client/assets/MarkdownPreview-CuIix2u9.js} +1 -1
  10. package/dist/client/assets/MermaidBlock-Dq9uFv82.js +2 -0
  11. package/dist/client/assets/Onboarding-QYXx24dX.js +1 -0
  12. package/{client/dist/assets/PreviewPanel-CqCa92Tf.js → dist/client/assets/PreviewPanel-Dd8q-jo0.js} +1 -1
  13. package/dist/client/assets/SetupForm-CrspaUva.js +1 -0
  14. package/dist/client/assets/WorkflowsPanel-DIlYAdhB.js +1 -0
  15. package/dist/client/assets/index-CnNNzw9A.css +1 -0
  16. package/{client/dist/assets/index-HaY-3pK1.js → dist/client/assets/index-rUkK9FDP.js} +26 -26
  17. package/{client/dist/assets/vendor-codemirror-D2ALgpaX.js → dist/client/assets/vendor-codemirror-jc6nyJQg.js} +1 -1
  18. package/{client/dist/assets/vendor-diff-DNQpbhrT.js → dist/client/assets/vendor-diff-THJmAcEI.js} +1 -1
  19. package/{client/dist/assets/vendor-icons-GyYE35HP.js → dist/client/assets/vendor-icons-CfjIpdrD.js} +145 -155
  20. package/{client/dist/assets/vendor-markdown-CimbIo6Y.js → dist/client/assets/vendor-markdown-Cdm6NEGf.js} +1 -1
  21. package/dist/client/assets/vendor-mermaid-DTPaBx-U.js +2559 -0
  22. package/{client/dist/assets/vendor-react-96lCPsRK.js → dist/client/assets/vendor-react-wFkb6mSf.js} +1 -1
  23. package/{client/dist/assets/vendor-syntax-LS_Nt30I.js → dist/client/assets/vendor-syntax-C_UZR7tc.js} +1 -1
  24. package/dist/client/favicon.png +0 -0
  25. package/dist/client/icons/icon-128x128.png +0 -0
  26. package/dist/client/icons/icon-144x144.png +0 -0
  27. package/dist/client/icons/icon-152x152.png +0 -0
  28. package/dist/client/icons/icon-192x192.png +0 -0
  29. package/dist/client/icons/icon-384x384.png +0 -0
  30. package/dist/client/icons/icon-512x512.png +0 -0
  31. package/dist/client/icons/icon-72x72.png +0 -0
  32. package/dist/client/icons/icon-96x96.png +0 -0
  33. package/{client/dist → dist/client}/index.html +37 -36
  34. package/dist/client/logo-128.png +0 -0
  35. package/dist/client/logo-256.png +0 -0
  36. package/dist/client/logo-32.png +0 -0
  37. package/dist/client/logo-512.png +0 -0
  38. package/dist/client/logo-64.png +0 -0
  39. package/dist/client/logo.png +0 -0
  40. package/{client/dist → dist/client}/manifest.json +12 -12
  41. package/{client/dist → dist/client}/mcp-docs.html +1 -1
  42. package/{client/dist → dist/client}/sw.js +2 -2
  43. package/package.json +56 -105
  44. package/scripts/postinstall.js +9 -0
  45. package/scripts/prepublish.js +77 -0
  46. package/src/animation.js +228 -0
  47. package/src/auth.js +142 -0
  48. package/src/config.js +40 -0
  49. package/src/connect.js +416 -0
  50. package/src/launch.js +81 -0
  51. package/src/mcp.js +57 -0
  52. package/src/permissions.js +140 -0
  53. package/src/persistent-shell.js +261 -0
  54. package/src/server.js +54 -0
  55. package/client/dist/assets/AppContent-CwrTP6TW.js +0 -545
  56. package/client/dist/assets/CanvasFullScreen-D1GWQsGL.js +0 -1
  57. package/client/dist/assets/CanvasWorkspace-D7ORj358.js +0 -163
  58. package/client/dist/assets/DashboardPanel-BV7ybUDe.js +0 -1
  59. package/client/dist/assets/FileTree-5qfhBqdE.js +0 -1
  60. package/client/dist/assets/LoginModal-CImJHRjX.js +0 -13
  61. package/client/dist/assets/MermaidBlock-BFM21cwe.js +0 -2
  62. package/client/dist/assets/Onboarding-B3cteLu2.js +0 -1
  63. package/client/dist/assets/SetupForm-P6dsYgHO.js +0 -1
  64. package/client/dist/assets/WorkflowsPanel-CBoN80kc.js +0 -1
  65. package/client/dist/assets/index-46kkVu2i.css +0 -1
  66. package/client/dist/assets/pdf-CE_K4jFx.js +0 -12
  67. package/client/dist/assets/vendor-canvas-BZV40eAE.css +0 -1
  68. package/client/dist/assets/vendor-canvas-DvHJ_Pn2.js +0 -49
  69. package/client/dist/assets/vendor-mermaid-DucWyDEe.js +0 -2556
  70. package/client/dist/favicon.png +0 -0
  71. package/client/dist/icons/icon-128x128.png +0 -0
  72. package/client/dist/icons/icon-144x144.png +0 -0
  73. package/client/dist/icons/icon-152x152.png +0 -0
  74. package/client/dist/icons/icon-192x192.png +0 -0
  75. package/client/dist/icons/icon-384x384.png +0 -0
  76. package/client/dist/icons/icon-512x512.png +0 -0
  77. package/client/dist/icons/icon-72x72.png +0 -0
  78. package/client/dist/icons/icon-96x96.png +0 -0
  79. package/client/dist/logo-128.png +0 -0
  80. package/client/dist/logo-256.png +0 -0
  81. package/client/dist/logo-32.png +0 -0
  82. package/client/dist/logo-512.png +0 -0
  83. package/client/dist/logo-64.png +0 -0
  84. package/commands/upfynai-connect.md +0 -59
  85. package/commands/upfynai-disconnect.md +0 -31
  86. package/commands/upfynai-doctor.md +0 -99
  87. package/commands/upfynai-export.md +0 -49
  88. package/commands/upfynai-local.md +0 -82
  89. package/commands/upfynai-status.md +0 -75
  90. package/commands/upfynai-stop.md +0 -49
  91. package/commands/upfynai-uninstall.md +0 -58
  92. package/commands/upfynai.md +0 -69
  93. package/scripts/build-client.js +0 -17
  94. package/scripts/fix-node-pty.js +0 -67
  95. package/scripts/install-commands.js +0 -78
  96. package/server/agent-loop.js +0 -242
  97. package/server/auto-compact.js +0 -99
  98. package/server/browser.js +0 -131
  99. package/server/claude-sdk.js +0 -797
  100. package/server/cli-ui.js +0 -798
  101. package/server/cli.js +0 -751
  102. package/server/constants/config.js +0 -31
  103. package/server/cursor-cli.js +0 -270
  104. package/server/database/auth.db +0 -0
  105. package/server/database/db.js +0 -1547
  106. package/server/database/init.sql +0 -70
  107. package/server/index.js +0 -3813
  108. package/server/load-env.js +0 -26
  109. package/server/mcp-server.js +0 -621
  110. package/server/middleware/auth.js +0 -184
  111. package/server/middleware/relayHelpers.js +0 -44
  112. package/server/middleware/sandboxRouter.js +0 -174
  113. package/server/openai-codex.js +0 -403
  114. package/server/openrouter.js +0 -137
  115. package/server/projects.js +0 -1807
  116. package/server/provider-factory.js +0 -174
  117. package/server/relay-client.js +0 -390
  118. package/server/routes/agent.js +0 -1234
  119. package/server/routes/auth.js +0 -559
  120. package/server/routes/browser.js +0 -419
  121. package/server/routes/canvas.js +0 -53
  122. package/server/routes/cli-auth.js +0 -263
  123. package/server/routes/codex.js +0 -396
  124. package/server/routes/commands.js +0 -707
  125. package/server/routes/composio.js +0 -176
  126. package/server/routes/cursor.js +0 -770
  127. package/server/routes/dashboard.js +0 -295
  128. package/server/routes/git.js +0 -1208
  129. package/server/routes/keys.js +0 -34
  130. package/server/routes/mcp-utils.js +0 -48
  131. package/server/routes/mcp.js +0 -661
  132. package/server/routes/payments.js +0 -227
  133. package/server/routes/projects.js +0 -754
  134. package/server/routes/sessions.js +0 -146
  135. package/server/routes/settings.js +0 -261
  136. package/server/routes/taskmaster.js +0 -1928
  137. package/server/routes/user.js +0 -106
  138. package/server/routes/vapi-chat.js +0 -624
  139. package/server/routes/voice.js +0 -235
  140. package/server/routes/webhooks.js +0 -166
  141. package/server/routes/workflows.js +0 -312
  142. package/server/sandbox.js +0 -120
  143. package/server/services/browser-ai.js +0 -154
  144. package/server/services/composio.js +0 -204
  145. package/server/services/sessionRegistry.js +0 -139
  146. package/server/services/whisperService.js +0 -84
  147. package/server/services/workflowScheduler.js +0 -211
  148. package/server/tests/relay-flow.test.js +0 -570
  149. package/server/tests/sessions.test.js +0 -259
  150. package/server/utils/commandParser.js +0 -303
  151. package/server/utils/email.js +0 -66
  152. package/server/utils/gitConfig.js +0 -24
  153. package/server/utils/mcp-detector.js +0 -198
  154. package/server/utils/taskmaster-websocket.js +0 -129
  155. package/shared/integrationCatalog.d.ts +0 -12
  156. package/shared/integrationCatalog.js +0 -172
  157. package/shared/modelConstants.js +0 -96
  158. /package/{shared → dist}/agents/claude.js +0 -0
  159. /package/{shared → dist}/agents/codex.js +0 -0
  160. /package/{shared → dist}/agents/cursor.js +0 -0
  161. /package/{shared → dist}/agents/detect.js +0 -0
  162. /package/{shared → dist}/agents/exec.js +0 -0
  163. /package/{shared → dist}/agents/files.js +0 -0
  164. /package/{shared → dist}/agents/git.js +0 -0
  165. /package/{shared → dist}/agents/gitagent.js +0 -0
  166. /package/{shared → dist}/agents/index.js +0 -0
  167. /package/{shared → dist}/agents/shell.js +0 -0
  168. /package/{shared → dist}/agents/utils.js +0 -0
  169. /package/{client/dist → dist/client}/api-docs.html +0 -0
  170. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  171. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  172. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  173. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  174. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  175. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  176. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  177. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  178. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  179. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  180. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  181. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  182. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  183. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  184. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  185. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  186. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  187. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  188. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  189. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  190. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  191. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  192. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  193. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  194. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  195. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  196. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  197. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  198. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  199. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  200. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  201. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  202. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  203. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  204. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  205. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  206. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  207. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  208. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  209. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  210. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  211. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  212. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  213. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  214. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  215. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  216. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  217. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  218. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  219. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  220. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  221. /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  222. /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  223. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  224. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  225. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  226. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  227. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  228. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  229. /package/{client/dist → dist/client}/assets/vendor-i18n-DCFGyhQR.js +0 -0
  230. /package/{client/dist → dist/client}/assets/vendor-xterm-CZq1hqo1.js +0 -0
  231. /package/{client/dist → dist/client}/assets/vendor-xterm-qxJ8_QYu.css +0 -0
  232. /package/{client/dist → dist/client}/clear-cache.html +0 -0
  233. /package/{client/dist → dist/client}/convert-icons.md +0 -0
  234. /package/{client/dist → dist/client}/favicon.svg +0 -0
  235. /package/{client/dist → dist/client}/generate-icons.js +0 -0
  236. /package/{client/dist → dist/client}/icons/claude-ai-icon.svg +0 -0
  237. /package/{client/dist → dist/client}/icons/codex-white.svg +0 -0
  238. /package/{client/dist → dist/client}/icons/codex.svg +0 -0
  239. /package/{client/dist → dist/client}/icons/cursor-white.svg +0 -0
  240. /package/{client/dist → dist/client}/icons/cursor.svg +0 -0
  241. /package/{client/dist → dist/client}/icons/icon-128x128.svg +0 -0
  242. /package/{client/dist → dist/client}/icons/icon-144x144.svg +0 -0
  243. /package/{client/dist → dist/client}/icons/icon-152x152.svg +0 -0
  244. /package/{client/dist → dist/client}/icons/icon-192x192.svg +0 -0
  245. /package/{client/dist → dist/client}/icons/icon-384x384.svg +0 -0
  246. /package/{client/dist → dist/client}/icons/icon-512x512.svg +0 -0
  247. /package/{client/dist → dist/client}/icons/icon-72x72.svg +0 -0
  248. /package/{client/dist → dist/client}/icons/icon-96x96.svg +0 -0
  249. /package/{client/dist → dist/client}/icons/icon-template.svg +0 -0
  250. /package/{client/dist → dist/client}/logo.svg +0 -0
  251. /package/{client/dist → dist/client}/offline.html +0 -0
  252. /package/{client/dist → dist/client}/screenshots/cli-selection.png +0 -0
  253. /package/{client/dist → dist/client}/screenshots/desktop-main.png +0 -0
  254. /package/{client/dist → dist/client}/screenshots/mobile-chat.png +0 -0
  255. /package/{client/dist → dist/client}/screenshots/tools-modal.png +0 -0
  256. /package/{shared → dist}/gitagent/index.js +0 -0
  257. /package/{shared → dist}/gitagent/parser.js +0 -0
  258. /package/{shared → dist}/gitagent/prompt-builder.js +0 -0
@@ -1 +0,0 @@
1
- import{r as s,j as e,R as be}from"./vendor-react-96lCPsRK.js";import{d as U,b as $}from"./index-HaY-3pK1.js";import{L as D,b4 as Q,P as J,X as q,f as ne,b as re,b5 as fe,a8 as je,ad as me,b2 as ue,k as ge,i as oe,g as ee,C as te,h as ae,b6 as V,v as le,j as ie,M as Ne,Z,G as ye,b7 as ve,a5 as we,Y as ke,ab as Ce,l as Se,b8 as Ee,R as Ae,b9 as Ie,ba as Te,bb as _e,bc as Le,bd as Re,be as De,bf as Oe,bg as Pe,bh as Ge,a3 as Me,w as Ue,aF as $e,bi as Fe,ax as We,bj as He}from"./vendor-icons-GyYE35HP.js";import"./vendor-syntax-LS_Nt30I.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-i18n-DCFGyhQR.js";const Be={"ai-prompt":"bg-blue-500/10 text-blue-400 ring-blue-500/20",webhook:"bg-yellow-500/10 text-yellow-400 ring-yellow-500/20",delay:"bg-purple-500/10 text-purple-400 ring-purple-500/20",condition:"bg-green-500/10 text-green-400 ring-green-500/20",integration:"bg-cyan-500/10 text-cyan-400 ring-cyan-500/20"},Ke=["Send a Slack message when a GitHub issue is created","Email me a daily summary of calendar events","Create a Notion page from each new Trello card","Notify Discord when a payment is received"];function ze({onEdit:o,onCreate:h,refreshKey:b}){const[N,E]=s.useState([]),[A,C]=s.useState(!0),[d,f]=s.useState(null),[m,v]=s.useState(null),[l,j]=s.useState(null),[c,t]=s.useState([]),[u,g]=s.useState(!1),[w,S]=s.useState(!1),[T,R]=s.useState(""),[M,O]=s.useState(!1),[F,I]=s.useState(""),P=s.useCallback(async()=>{try{const a=await U("/api/workflows");if(a.ok){const n=await a.json();E(n.workflows||[])}}catch{}C(!1)},[]);s.useEffect(()=>{P()},[P,b]);const G=async a=>{if(l===a){j(null);return}j(a),g(!0);try{const n=await U(`/api/workflows/${a}/runs`);if(n.ok){const i=await n.json();t(i.runs||[])}}catch{t([])}g(!1)},B=async a=>{try{await U(`/api/workflows/${a}`,{method:"DELETE"}),P()}catch{}},W=async a=>{var n;f(a),v(null);try{const L=await(await U(`/api/workflows/${a}/run`,{method:"POST"})).json();v({id:a,success:L.success,message:L.success?`Completed ${((n=L.results)==null?void 0:n.length)||0} steps`:L.error||"Failed",results:L.results}),P()}catch{v({id:a,success:!1,message:"Network error"})}f(null)},K=async()=>{if(T.trim()){O(!0),I("");try{const a=await U("/api/workflows/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:T.trim()})}),n=await a.json();a.ok&&n.success?(S(!1),R(""),P(),n.workflow&&o(n.workflow)):I(n.error||"Failed to generate workflow")}catch{I("Network error")}O(!1)}};return A?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading workflows..."})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Workflows"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:"Automate tasks with AI prompts, webhooks, and integrations"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>S(!w),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium rounded-lg transition-all ${w?"bg-primary/10 text-primary":"bg-muted/30 text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),"AI Create"]}),e.jsxs("button",{onClick:h,className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"New Workflow"]})]})]}),w&&e.jsxs("div",{className:"bg-gradient-to-br from-primary/[0.03] to-transparent border border-primary/15 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Q,{className:"w-3.5 h-3.5 text-primary"})}),e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Describe your workflow"})]}),e.jsx("button",{onClick:()=>{S(!1),I("")},className:"p-1 text-muted-foreground/40 hover:text-foreground rounded-lg transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsx("textarea",{value:T,onChange:a=>R(a.target.value),placeholder:"Describe what you want to automate in plain English...",rows:3,className:"w-full px-3.5 py-2.5 text-sm bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 resize-none transition-colors",onKeyDown:a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&!M&&K()}}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ke.map(a=>e.jsx("button",{onClick:()=>R(a),className:"px-2.5 py-1 text-[10px] text-muted-foreground/50 hover:text-foreground bg-muted/20 hover:bg-muted/40 rounded-full transition-colors",children:a},a))}),F&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),F]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:K,disabled:M||!T.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity disabled:opacity-40",children:M?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"Generate Workflow"]})})})]}),N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(re,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"No workflows yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed mb-5",children:"Chain AI prompts, webhook calls, conditions, and app integrations into automated pipelines."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>S(!0),className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-primary/10 text-primary rounded-lg hover:bg-primary/15 transition-colors",children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),"Create with AI"]}),e.jsxs("button",{onClick:h,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Create Manually"]})]})]}):e.jsx("div",{className:"space-y-3",children:N.map((a,n)=>e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 hover:border-border/50 transition-all duration-200",style:{animationDelay:`${n*30}ms`},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight",children:a.name}),a.schedule&&a.schedule_enabled?e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-primary/70 bg-primary/5 px-1.5 py-0.5 rounded-full",children:[e.jsx(fe,{className:"w-2.5 h-2.5"}),"Scheduled"]}):null]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground/60 mb-3 line-clamp-1",children:a.description}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.steps.map((i,L)=>e.jsxs(be.Fragment,{children:[e.jsx("span",{className:`inline-flex items-center gap-1 text-[10px] font-medium px-2 py-0.5 rounded-full ring-1 ${Be[i.type]||"bg-muted text-muted-foreground ring-border/30"}`,children:i.label}),L<a.steps.length-1&&e.jsx(je,{className:"w-3 h-3 text-muted-foreground/20 flex-shrink-0"})]},i.id||L)),a.steps.length===0&&e.jsx("span",{className:"text-[10px] text-muted-foreground/30 italic",children:"No steps configured"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 text-[10px] text-muted-foreground/35",children:[e.jsxs("span",{children:[a.steps.length," step",a.steps.length!==1?"s":""]}),a.schedule&&a.schedule_enabled&&e.jsx("span",{className:"font-mono",children:a.schedule}),a.last_run&&e.jsxs("span",{children:["Last run ",new Date(a.last_run).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>W(a.id),disabled:d===a.id||a.steps.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-green-500/8 text-green-400 hover:bg-green-500/15 rounded-lg transition-colors disabled:opacity-30",title:"Run workflow",children:[d===a.id?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(me,{className:"w-3.5 h-3.5"}),"Run"]}),e.jsx("button",{onClick:()=>G(a.id),className:`p-2 rounded-lg transition-colors ${l===a.id?"text-primary bg-primary/5":"text-muted-foreground/40 hover:text-foreground hover:bg-muted/30"}`,title:"Execution history",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>o(a),className:"p-2 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",title:"Edit",children:e.jsx(ge,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>B(a.id),className:"p-2 text-muted-foreground/40 hover:text-red-400 hover:bg-red-500/5 rounded-lg transition-colors",title:"Delete",children:e.jsx(oe,{className:"w-3.5 h-3.5"})})]})]}),(m==null?void 0:m.id)===a.id&&e.jsxs("div",{className:`mt-3 p-3 rounded-xl text-xs ${m.success?"bg-green-500/[0.03] border border-green-500/15":"bg-red-500/[0.03] border border-red-500/15"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[m.success?e.jsx(ee,{className:"w-3.5 h-3.5 text-green-400"}):e.jsx(te,{className:"w-3.5 h-3.5 text-red-400"}),e.jsx("span",{className:`font-medium ${m.success?"text-green-400":"text-red-400"}`,children:m.message})]}),m.results&&e.jsx("div",{className:"space-y-1 mt-2",children:m.results.map((i,L)=>{var H;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[i.success?e.jsx(ee,{className:"w-2.5 h-2.5 text-green-400/60"}):e.jsx(te,{className:"w-2.5 h-2.5 text-red-400/60"}),e.jsx("span",{className:"text-muted-foreground",children:i.label}),((H=i.result)==null?void 0:H.status)&&e.jsxs("span",{className:"text-muted-foreground/30",children:["(",i.result.status,")"]}),i.error&&e.jsx("span",{className:"text-red-400/60",children:i.error})]},L)})})]}),l===a.id&&e.jsxs("div",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2.5",children:[e.jsx(ue,{className:"w-3 h-3 text-muted-foreground/50"}),e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:"Execution History"})]}),u?e.jsxs("div",{className:"flex items-center gap-2 py-3 text-[10px] text-muted-foreground/40",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Loading..."]}):c.length===0?e.jsx("div",{className:"text-[10px] text-muted-foreground/30 py-3 italic",children:"No runs yet"}):e.jsx("div",{className:"space-y-1.5 max-h-48 overflow-y-auto",children:c.map(i=>e.jsxs("div",{className:"flex items-start gap-2.5 text-[10px] bg-muted/10 rounded-lg p-2.5",children:[e.jsx("div",{className:"shrink-0 mt-0.5",children:i.status==="completed"?e.jsx(ee,{className:"w-3 h-3 text-green-400"}):i.status==="failed"?e.jsx(te,{className:"w-3 h-3 text-red-400"}):i.status==="running"?e.jsx(D,{className:"w-3 h-3 text-yellow-400 animate-spin"}):e.jsx(ae,{className:"w-3 h-3 text-muted-foreground/40"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${i.status==="completed"?"text-green-400":i.status==="failed"?"text-red-400":"text-muted-foreground"}`,children:i.status==="completed"?"Success":i.status==="failed"?"Failed":i.status}),e.jsxs("span",{className:"text-muted-foreground/25",children:[i.steps_completed,"/",i.total_steps," steps"]}),e.jsx("span",{className:"text-muted-foreground/25",children:new Date(i.started_at).toLocaleString()})]}),i.error&&e.jsx("p",{className:"text-red-400/60 mt-0.5 truncate",children:i.error}),i.completed_at&&e.jsxs("span",{className:"text-muted-foreground/20",children:["Duration: ",Math.round((new Date(i.completed_at).getTime()-new Date(i.started_at).getTime())/1e3),"s"]})]})]},i.id))})]})]},a.id))})]})}const de=[{id:"GMAIL",name:"Gmail",icon:"mail",keywords:["gmail","email","send email","inbox","mail"],authConfigId:null,popularActions:[{slug:"GMAIL_SEND_EMAIL",label:"Send Email",params:["to","subject","body"]},{slug:"GMAIL_FETCH_EMAILS",label:"Fetch Emails",params:["query","max_results"]}]},{id:"GOOGLECALENDAR",name:"Google Calendar",icon:"calendar",keywords:["calendar","event","meeting","schedule meeting"],authConfigId:null,popularActions:[{slug:"GOOGLECALENDAR_CREATE_EVENT",label:"Create Event",params:["summary","start_time","end_time"]},{slug:"GOOGLECALENDAR_LIST_EVENTS",label:"List Events",params:["time_min","time_max"]}]},{id:"SLACK",name:"Slack",icon:"hash",keywords:["slack","channel","slack message"],authConfigId:null,popularActions:[{slug:"SLACK_SENDS_A_MESSAGE_TO_A_SLACK_CHANNEL",label:"Send Message",params:["channel","text"]}]},{id:"GITHUB",name:"GitHub",icon:"github",keywords:["github","repository","pull request","issue","commit"],authConfigId:null,popularActions:[{slug:"GITHUB_CREATE_AN_ISSUE",label:"Create Issue",params:["owner","repo","title","body"]},{slug:"GITHUB_CREATE_A_PULL_REQUEST",label:"Create PR",params:["owner","repo","title","head","base"]}]},{id:"NOTION",name:"Notion",icon:"file-text",keywords:["notion","page","note"],authConfigId:null,popularActions:[{slug:"NOTION_CREATE_A_PAGE",label:"Create Page",params:["parent_id","title","content"]}]},{id:"DISCORD",name:"Discord",icon:"message-circle",keywords:["discord"],authConfigId:null,popularActions:[{slug:"DISCORD_SEND_MESSAGE",label:"Send Message",params:["channel_id","content"]}]},{id:"GOOGLEDRIVE",name:"Google Drive",icon:"hard-drive",keywords:["drive","google drive","upload file","file storage"],authConfigId:null,popularActions:[{slug:"GOOGLEDRIVE_UPLOAD_FILE",label:"Upload File",params:["file_name","content"]},{slug:"GOOGLEDRIVE_LIST_FILES",label:"List Files",params:["query"]}]},{id:"TRELLO",name:"Trello",icon:"kanban",keywords:["trello","board","card","kanban"],authConfigId:null,popularActions:[{slug:"TRELLO_CREATE_CARD",label:"Create Card",params:["list_id","name","desc"]}]},{id:"LINEAR",name:"Linear",icon:"bug",keywords:["linear","ticket","linear issue"],authConfigId:null,popularActions:[{slug:"LINEAR_CREATE_ISSUE",label:"Create Issue",params:["team_id","title","description"]},{slug:"LINEAR_LIST_ISSUES",label:"List Issues",params:["team_id","status"]}]},{id:"JIRA",name:"Jira",icon:"bug",keywords:["jira","sprint","jira issue","jira ticket"],authConfigId:null,popularActions:[{slug:"JIRA_CREATE_ISSUE",label:"Create Issue",params:["project_key","summary","description","issue_type"]},{slug:"JIRA_GET_ISSUE",label:"Get Issue",params:["issue_key"]}]},{id:"ASANA",name:"Asana",icon:"list-checks",keywords:["asana","task","asana task","project management"],authConfigId:null,popularActions:[{slug:"ASANA_CREATE_TASK",label:"Create Task",params:["project_id","name","notes"]},{slug:"ASANA_LIST_TASKS",label:"List Tasks",params:["project_id"]}]},{id:"STRIPE",name:"Stripe",icon:"credit-card",keywords:["stripe","payment","invoice","charge","billing"],authConfigId:null,popularActions:[{slug:"STRIPE_CREATE_INVOICE",label:"Create Invoice",params:["customer_id","amount","currency"]},{slug:"STRIPE_LIST_PAYMENTS",label:"List Payments",params:["limit"]}]},{id:"TWILIO",name:"Twilio",icon:"phone",keywords:["twilio","sms","text message","phone"],authConfigId:null,popularActions:[{slug:"TWILIO_SEND_SMS",label:"Send SMS",params:["to","body"]}]},{id:"AIRTABLE",name:"Airtable",icon:"table",keywords:["airtable","spreadsheet","database","airtable record"],authConfigId:null,popularActions:[{slug:"AIRTABLE_CREATE_RECORD",label:"Create Record",params:["base_id","table_name","fields"]},{slug:"AIRTABLE_LIST_RECORDS",label:"List Records",params:["base_id","table_name"]}]}],Y={};for(const o of de)for(const h of o.keywords)Y[h.toLowerCase()]=o.id;const ce={};for(const o of de)ce[o.id]=o;function Je({stepId:o,config:h,onUpdateConfig:b}){const[N,E]=s.useState([]),[A,C]=s.useState(!0),[d,f]=s.useState(!1),[m,v]=s.useState(!1);s.useEffect(()=>{$.composio.catalog().then(t=>t.json()).then(t=>{E(t.catalog||[]),v(t.composioAvailable),C(!1)}).catch(()=>{E(de.map(t=>({...t,connected:!1,connectionId:null}))),C(!1)})},[]);const l=N.find(t=>t.id===h.integrationId),j=l==null?void 0:l.popularActions.find(t=>t.slug===h.toolSlug),c=async t=>{f(!0);try{const g=await(await $.composio.connect(t)).json();if(g.redirectUrl){const w=window.open(g.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),S=setInterval(async()=>{try{if((await(await $.composio.waitForConnection(g.connectedAccountId)).json()).status==="ACTIVE"){clearInterval(S),w==null||w.close();const O=await(await $.composio.catalog()).json();E(O.catalog||[]),f(!1)}}catch{}},2e3);setTimeout(()=>{clearInterval(S),f(!1)},12e4)}}catch{f(!1)}};return A?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/50 py-3",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Loading integrations..."]}):m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Integration"}),e.jsxs("select",{value:h.integrationId||"",onChange:t=>{const u=t.target.value;b("integrationId",u),b("toolSlug",""),b("arguments",{})},className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select an integration..."}),N.map(t=>e.jsxs("option",{value:t.id,children:[t.name," ",t.connected?"(Connected)":""]},t.id))]})]}),l&&!l.connected&&e.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-yellow-500/[0.03] border border-yellow-500/15 rounded-xl",children:[e.jsxs("span",{className:"text-[10px] text-yellow-400 flex-1",children:[l.name," is not connected yet."]}),e.jsxs("button",{onClick:()=>c(l.id),disabled:d,className:"flex items-center gap-1 px-2.5 py-1.5 text-[10px] font-medium bg-foreground text-background rounded-lg hover:opacity-90 disabled:opacity-50 transition-opacity",children:[d?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(le,{className:"w-3 h-3"}),"Connect"]})]}),l&&l.connected&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-green-400 font-medium",children:[e.jsx(ie,{className:"w-3 h-3"}),"Connected"]}),l&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Action"}),e.jsxs("select",{value:h.toolSlug||"",onChange:t=>{b("toolSlug",t.target.value),b("arguments",{})},className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select an action..."}),l.popularActions.map(t=>e.jsx("option",{value:t.slug,children:t.label},t.slug))]})]}),j&&j.params.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 block",children:"Parameters"}),j.params.map(t=>{var u;return e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground/40 mb-0.5 block capitalize",children:t.replace(/_/g," ")}),e.jsx("input",{value:((u=h.arguments)==null?void 0:u[t])||"",onChange:g=>{const w={...h.arguments||{},[t]:g.target.value};b("arguments",w)},placeholder:`{{prev.${t}}} or value`,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/25 focus:outline-none focus:border-primary/40 font-mono transition-colors"})]},t)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/30",children:["Use ","{{prev.field}}"," to reference output from the previous step."]})]})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/50 py-3",children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Composio not configured. Set ",e.jsx("code",{className:"px-1 py-0.5 bg-muted/40 rounded text-[10px] font-mono",children:"COMPOSIO_API_KEY"})," on the server."]})]})}function Ve({keyword:o,integrationId:h,integrationName:b,position:N,onDismiss:E,onAddAction:A}){const[C,d]=s.useState(null),[f,m]=s.useState(!1),v=s.useRef(null),l=ce[h],j=(l==null?void 0:l.popularActions)||[];s.useEffect(()=>{$.composio.catalog().then(t=>t.json()).then(t=>{const u=(t.catalog||[]).find(g=>g.id===h);d((u==null?void 0:u.connected)||!1)}).catch(()=>d(!1))},[h]),s.useEffect(()=>{const t=g=>{v.current&&!v.current.contains(g.target)&&E()},u=g=>{g.key==="Escape"&&E()};return document.addEventListener("mousedown",t),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",u)}},[E]);const c=async()=>{m(!0);try{const u=await(await $.composio.connect(h)).json();if(u.redirectUrl){const g=window.open(u.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),w=setInterval(async()=>{try{(await(await $.composio.waitForConnection(u.connectedAccountId)).json()).status==="ACTIVE"&&(clearInterval(w),g==null||g.close(),d(!0),m(!1))}catch{}},2e3);setTimeout(()=>{clearInterval(w),m(!1)},12e4)}}catch{m(!1)}};return e.jsxs("div",{ref:v,className:"fixed z-50 bg-card border border-border/40 rounded-2xl shadow-2xl overflow-hidden min-w-[240px] max-w-[300px]",style:{top:N.top,left:Math.min(N.left,window.innerWidth-320)},children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 bg-muted/20 border-b border-border/20",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-cyan-500/10",children:e.jsx(re,{className:"w-3.5 h-3.5 text-cyan-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground",children:b}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/40",children:['Detected "',e.jsx("span",{className:"text-primary/60 font-medium",children:o}),'"']})]}),e.jsx("button",{onClick:E,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded-lg transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"p-1.5",children:[C===null&&e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-3 text-xs text-muted-foreground/50",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Checking connection..."]}),C===!1&&e.jsxs("button",{onClick:c,disabled:f,className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 text-xs text-foreground hover:bg-muted/30 rounded-xl transition-colors",children:[f?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin text-primary"}):e.jsx(le,{className:"w-3.5 h-3.5 text-primary"}),e.jsxs("span",{children:["Connect ",b," to use this"]})]}),C===!0&&j.length>0&&e.jsx("div",{className:"space-y-0.5",children:j.map(t=>e.jsxs("button",{onClick:()=>A(h,t.slug,t.label),className:"w-full flex items-center gap-2.5 px-2.5 py-2 text-xs text-foreground hover:bg-muted/30 rounded-xl transition-colors group",children:[e.jsx(J,{className:"w-3.5 h-3.5 text-cyan-400 group-hover:text-cyan-300"}),e.jsxs("span",{className:"flex-1 text-left",children:["Add: ",t.label]})]},t.slug))})]})]})}function qe(){const[o,h]=s.useState(null),b=s.useRef(null),N=s.useRef(null),E=s.useCallback((d,f,m)=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{if(!d||f===0){h(null);return}const l=d.slice(0,f).toLowerCase().split(/\s+/).filter(Boolean);let j=null;if(l.length>=2){const c=`${l[l.length-2]} ${l[l.length-1]}`;Y[c]&&(j=c)}if(!j&&l.length>=1){const c=l[l.length-1];Y[c]&&(j=c)}if(j&&j!==N.current){const c=Y[j],t=ce[c];if(t){h({keyword:j,integrationId:c,integrationName:t.name,position:m?{top:m.bottom+4,left:m.left}:{top:0,left:0}});return}}h(null)},300)},[]),A=s.useCallback(()=>{o&&(N.current=o.keyword),h(null)},[o]),C=s.useCallback(()=>{N.current=null},[]);return s.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]),{activeMatch:o,detectKeywords:E,dismiss:A,resetDismissed:C}}const se=[{value:"ai-prompt",label:"AI Prompt",desc:"Ask AI to process data",icon:Ne,color:"text-blue-400 bg-blue-500/10",ring:"ring-blue-500/20"},{value:"webhook",label:"Webhook",desc:"Call an HTTP endpoint",icon:Z,color:"text-yellow-400 bg-yellow-500/10",ring:"ring-yellow-500/20"},{value:"delay",label:"Delay",desc:"Wait before continuing",icon:ae,color:"text-purple-400 bg-purple-500/10",ring:"ring-purple-500/20"},{value:"condition",label:"Condition",desc:"Branch on a condition",icon:ye,color:"text-green-400 bg-green-500/10",ring:"ring-green-500/20"},{value:"integration",label:"Integration",desc:"Use a connected app",icon:V,color:"text-cyan-400 bg-cyan-500/10",ring:"ring-cyan-500/20"}];let Ye=0;const xe=()=>`step_${Date.now()}_${++Ye}`,Ze=[{label:"Every minute",cron:"* * * * *"},{label:"Every 5 minutes",cron:"*/5 * * * *"},{label:"Every 15 minutes",cron:"*/15 * * * *"},{label:"Every hour",cron:"0 * * * *"},{label:"Every 6 hours",cron:"0 */6 * * *"},{label:"Daily at midnight",cron:"0 0 * * *"},{label:"Daily at 9 AM",cron:"0 9 * * *"},{label:"Weekly (Monday)",cron:"0 9 * * 1"},{label:"Monthly (1st)",cron:"0 0 1 * *"}];function Xe({workflow:o,onSave:h,onCancel:b}){const[N,E]=s.useState((o==null?void 0:o.name)||""),[A,C]=s.useState((o==null?void 0:o.description)||""),[d,f]=s.useState((o==null?void 0:o.steps)||[]),[m,v]=s.useState((o==null?void 0:o.schedule)||""),[l,j]=s.useState(!!(o!=null&&o.schedule_enabled)),[c,t]=s.useState((o==null?void 0:o.schedule_timezone)||Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"),[u,g]=s.useState([]),[w,S]=s.useState(!1),[T,R]=s.useState(""),[M,O]=s.useState(null),[F,I]=s.useState(!1),P=s.useRef(null),{activeMatch:G,detectKeywords:B,dismiss:W}=qe();s.useEffect(()=>{U("/api/webhooks").then(r=>r.json()).then(r=>{g(r.webhooks||[])}).catch(()=>{})},[]);const K=s.useCallback(r=>{const k=se.find(y=>y.value===r),p={id:xe(),type:r,label:(k==null?void 0:k.label)||r,config:r==="delay"?{seconds:5}:{},order:d.length};f(y=>[...y,p]),O(p.id),I(!1)},[d.length]),a=s.useCallback(r=>{f(k=>k.filter(p=>p.id!==r).map((p,y)=>({...p,order:y}))),M===r&&O(null)},[M]),n=s.useCallback((r,k)=>{f(p=>{const y=p.findIndex(z=>z.id===r);if(y<0)return p;const _=k==="up"?y-1:y+1;if(_<0||_>=p.length)return p;const x=[...p];return[x[y],x[_]]=[x[_],x[y]],x.map((z,he)=>({...z,order:he}))})},[]),i=s.useCallback((r,k,p)=>{f(y=>y.map(_=>_.id===r?{..._,config:{..._.config,[k]:p}}:_))},[]),L=s.useCallback((r,k)=>{f(p=>p.map(y=>y.id===r?{...y,label:k}:y))},[]),H=s.useCallback((r,k,p)=>{const y={id:xe(),type:"integration",label:p,config:{integrationId:r,toolSlug:k,arguments:{}},order:d.length};f(_=>[..._,y]),O(y.id),W()},[d.length,W]),X=s.useCallback(r=>{const k=r.target.value;C(k);const p=r.target.getBoundingClientRect();B(k,r.target.selectionStart||0,p)},[B]),pe=async()=>{if(R(""),!N.trim()){R("Workflow name is required");return}if(d.length===0){R("Add at least one step");return}S(!0);try{const r={name:N,description:A,steps:d,schedule:m||null,schedule_enabled:l,schedule_timezone:c},k=o!=null&&o.id?`/api/workflows/${o.id}`:"/api/workflows",p=o!=null&&o.id?"PUT":"POST",y=await U(k,{method:p,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!y.ok){const _=await y.json();R(_.error||"Failed to save"),S(!1);return}h()}catch{R("Network error")}S(!1)};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/20 bg-card/50",children:[e.jsx("button",{onClick:b,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-sm font-semibold text-foreground tracking-tight",children:o!=null&&o.id?"Edit Workflow":"New Workflow"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:pe,disabled:w,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity disabled:opacity-50",children:[e.jsx(we,{className:"w-3.5 h-3.5"}),w?"Saving...":"Save Workflow"]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Name"}),e.jsx("input",{value:N,onChange:r=>E(r.target.value),placeholder:"My Workflow",className:"w-full px-3.5 py-2.5 text-sm bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Description"}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:P,value:A,onChange:X,placeholder:"Describe what this workflow does... Try typing 'email', 'slack', or 'calendar' to auto-detect integrations",rows:2,className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 resize-none transition-colors"}),G&&e.jsx(Ve,{keyword:G.keyword,integrationId:G.integrationId,integrationName:G.integrationName,position:G.position,onDismiss:W,onAddAction:H})]})]})]}),e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-semibold text-foreground flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-purple-500/10",children:e.jsx(ae,{className:"w-3.5 h-3.5 text-purple-400"})}),"Schedule"]}),e.jsx("button",{onClick:()=>j(!l),className:`relative w-9 h-5 rounded-full transition-colors ${l?"bg-primary":"bg-muted/60"}`,children:e.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform ${l?"translate-x-[18px]":"translate-x-0.5"}`})})]}),l&&e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Cron Expression"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:m,onChange:r=>v(r.target.value),placeholder:"*/15 * * * *",className:"flex-1 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono transition-colors"}),e.jsxs("select",{value:m,onChange:r=>v(r.target.value),className:"px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Presets..."}),Ze.map(r=>e.jsx("option",{value:r.cron,children:r.label},r.cron))]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Timezone"}),e.jsx("input",{value:c,onChange:r=>t(r.target.value),placeholder:"UTC",className:"w-48 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 transition-colors"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground/35 leading-relaxed",children:'Runs automatically when the server is online. Missed runs while offline appear as "missed" in execution history.'})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("span",{className:"text-xs font-semibold text-foreground",children:["Steps (",d.length,")"]})}),d.length===0?e.jsx("div",{className:"text-center py-10 border border-dashed border-border/30 rounded-2xl",children:e.jsx("p",{className:"text-xs text-muted-foreground/40",children:"No steps yet. Add your first step below."})}):e.jsx("div",{className:"space-y-2",children:d.map((r,k)=>{const p=se.find(x=>x.value===r.type),y=(p==null?void 0:p.icon)||Z,_=M===r.id;return e.jsxs("div",{className:`border rounded-2xl overflow-hidden transition-colors ${_?"border-border/50 bg-card/50":"border-border/25 bg-card/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer hover:bg-muted/20 transition-colors",onClick:()=>O(_?null:r.id),children:[e.jsx(ke,{className:"w-3 h-3 text-muted-foreground/20 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-muted-foreground/40 w-5 text-center font-mono",children:k+1}),e.jsx("div",{className:`p-1.5 rounded-lg ${(p==null?void 0:p.color)||"bg-muted text-muted-foreground"}`,children:e.jsx(y,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"text-xs font-medium text-foreground flex-1 min-w-0 truncate",children:r.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground/35",children:p==null?void 0:p.label}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{onClick:x=>{x.stopPropagation(),n(r.id,"up")},disabled:k===0,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded transition-colors disabled:opacity-20",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),n(r.id,"down")},disabled:k===d.length-1,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded transition-colors disabled:opacity-20",children:e.jsx(Se,{className:"w-3 h-3"})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(r.id)},className:"p-1 text-muted-foreground/30 hover:text-red-400 rounded transition-colors",children:e.jsx(oe,{className:"w-3 h-3"})})]})]}),_&&e.jsxs("div",{className:"px-4 pb-4 pt-2 border-t border-border/15 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Step Label"}),e.jsx("input",{value:r.label,onChange:x=>L(r.id,x.target.value),className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors"})]}),r.type==="ai-prompt"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Prompt"}),e.jsx("textarea",{value:r.config.prompt||"",onChange:x=>i(r.id,"prompt",x.target.value),placeholder:"Describe what the AI should do...",rows:3,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 resize-none transition-colors"})]}),r.type==="webhook"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Webhook"}),e.jsxs("select",{value:r.config.webhookId||"",onChange:x=>i(r.id,"webhookId",x.target.value),className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select a webhook..."}),u.map(x=>e.jsxs("option",{value:x.id,children:[x.name," (",x.method," ",x.url,")"]},x.id))]}),u.length===0&&e.jsx("p",{className:"text-[10px] text-muted-foreground/35 mt-1",children:"No webhooks created yet. Go to the Webhooks tab first."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Payload Template (JSON)"}),e.jsx("textarea",{value:r.config.payloadTemplate||"",onChange:x=>i(r.id,"payloadTemplate",x.target.value),placeholder:'{"key": "value"}',rows:2,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 resize-none font-mono transition-colors"})]})]}),r.type==="delay"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Delay (seconds, max 30)"}),e.jsx("input",{type:"number",min:1,max:30,value:r.config.seconds||5,onChange:x=>i(r.id,"seconds",Math.min(30,Math.max(1,parseInt(x.target.value)||1))),className:"w-24 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors"})]}),r.type==="condition"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Condition Expression"}),e.jsx("input",{value:r.config.expression||"",onChange:x=>i(r.id,"expression",x.target.value),placeholder:"e.g. response.status === 200",className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono transition-colors"}),e.jsx("p",{className:"text-[10px] text-muted-foreground/30 mt-1",children:"Condition evaluation coming soon"})]}),r.type==="integration"&&e.jsx(Je,{stepId:r.id,config:r.config,onUpdateConfig:(x,z)=>i(r.id,x,z)})]})]},r.id)})}),e.jsx("div",{className:"mt-3",children:F?e.jsxs("div",{className:"border border-border/30 rounded-2xl p-3 bg-card/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:"Add a step"}),e.jsx("button",{onClick:()=>I(!1),className:"p-1 text-muted-foreground/40 hover:text-foreground rounded transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:se.map(r=>{const k=r.icon;return e.jsxs("button",{onClick:()=>K(r.value),className:"flex flex-col items-center gap-2 p-3 rounded-xl border border-border/20 bg-background/50 hover:border-border/50 hover:bg-muted/20 transition-all text-center",children:[e.jsx("div",{className:`p-2 rounded-xl ${r.color}`,children:e.jsx(k,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-foreground block",children:r.label}),e.jsx("span",{className:"text-[9px] text-muted-foreground/40",children:r.desc})]})]},r.value)})})]}):e.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-1.5 py-2.5 text-xs text-muted-foreground/50 hover:text-foreground border border-dashed border-border/30 hover:border-border/50 rounded-2xl transition-colors",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Add Step"]})})]}),T&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),T]})]})]})}const Qe=["GET","POST","PUT","PATCH","DELETE"],et={GET:"bg-green-500/10 text-green-400",POST:"bg-blue-500/10 text-blue-400",PUT:"bg-yellow-500/10 text-yellow-400",PATCH:"bg-orange-500/10 text-orange-400",DELETE:"bg-red-500/10 text-red-400"};function tt({onWebhooksChange:o}){const[h,b]=s.useState([]),[N,E]=s.useState(!0),[A,C]=s.useState(!1),[d,f]=s.useState(null),[m,v]=s.useState(null),[l,j]=s.useState(null),[c,t]=s.useState(""),[u,g]=s.useState(""),[w,S]=s.useState("POST"),[T,R]=s.useState("{}"),[M,O]=s.useState(""),[F,I]=s.useState(""),P=s.useCallback(async()=>{try{const n=await U("/api/webhooks");if(n.ok){const i=await n.json();b(i.webhooks||[])}}catch{}E(!1)},[]);s.useEffect(()=>{P()},[P]);const G=()=>{t(""),g(""),S("POST"),R("{}"),O(""),I(""),f(null),C(!1)},B=n=>{t(n.name),g(n.url),S(n.method),R(n.headers||"{}"),O(n.description||""),f(n.id),C(!0),I("")},W=async()=>{if(I(""),!c.trim()){I("Name is required");return}if(!u.trim()){I("URL is required");return}try{new URL(u)}catch{I("Invalid URL");return}try{JSON.parse(T)}catch{I("Headers must be valid JSON");return}try{const n={name:c,url:u,method:w,headers:T,description:M},i=d?`/api/webhooks/${d}`:"/api/webhooks",H=await U(i,{method:d?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!H.ok){const X=await H.json();I(X.error||"Failed to save");return}G(),P(),o==null||o()}catch{I("Network error")}},K=async n=>{try{await U(`/api/webhooks/${n}`,{method:"DELETE"}),P(),o==null||o()}catch{}},a=async n=>{v(n),j(null);try{const L=await(await U(`/api/webhooks/${n}/test`,{method:"POST"})).json();j({id:n,result:L.result,success:L.success})}catch{j({id:n,result:{error:"Network error"},success:!1})}v(null)};return N?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading webhooks..."})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Webhooks"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:"HTTP endpoints that workflows can call during execution"})]}),!A&&e.jsxs("button",{onClick:()=>{G(),C(!0)},className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Add Webhook"]})]}),A&&e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:d?"Edit Webhook":"New Webhook"}),e.jsx("button",{onClick:G,className:"p-1.5 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",children:e.jsx(q,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Name"}),e.jsx("input",{value:c,onChange:n=>t(n.target.value),placeholder:"My Webhook",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Method"}),e.jsx("select",{value:w,onChange:n=>S(n.target.value),className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:Qe.map(n=>e.jsx("option",{value:n,children:n},n))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"URL"}),e.jsx("input",{value:u,onChange:n=>g(n.target.value),placeholder:"https://example.com/webhook",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Headers (JSON)"}),e.jsx("textarea",{value:T,onChange:n=>R(n.target.value),placeholder:'{"Authorization": "Bearer ..."}',rows:2,className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono resize-none transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Description"}),e.jsx("input",{value:M,onChange:n=>O(n.target.value),placeholder:"Optional description...",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 transition-colors"})]}),F&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),F]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:G,className:"px-3.5 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:W,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(ie,{className:"w-3.5 h-3.5"}),d?"Update":"Create"]})]})]}),h.length===0&&!A?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(Ee,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"No webhooks yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed",children:"Create a webhook endpoint to use in your workflow steps."})]}):e.jsx("div",{className:"space-y-3",children:h.map((n,i)=>e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 hover:border-border/50 transition-all duration-200",style:{animationDelay:`${i*30}ms`},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground tracking-tight",children:n.name}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-mono font-medium ${et[n.method]||"bg-muted text-muted-foreground"}`,children:n.method})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground/50 font-mono truncate",children:n.url}),n.description&&e.jsx("p",{className:"text-[11px] text-muted-foreground/40 mt-1",children:n.description}),n.last_triggered&&e.jsxs("p",{className:"text-[10px] text-muted-foreground/30 mt-1.5",children:["Last triggered: ",new Date(n.last_triggered).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>a(n.id),disabled:m===n.id,className:"p-2 text-muted-foreground/40 hover:text-green-400 hover:bg-green-500/5 rounded-lg transition-colors disabled:opacity-50",title:"Test webhook",children:m===n.id?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(me,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>B(n),className:"p-2 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",title:"Edit",children:e.jsx(ge,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>K(n.id),className:"p-2 text-muted-foreground/40 hover:text-red-400 hover:bg-red-500/5 rounded-lg transition-colors",title:"Delete",children:e.jsx(oe,{className:"w-3.5 h-3.5"})})]})]}),(l==null?void 0:l.id)===n.id&&e.jsx("div",{className:`mt-3 p-3 rounded-xl text-xs ${l.success?"bg-green-500/[0.03] border border-green-500/15":"bg-red-500/[0.03] border border-red-500/15"}`,children:l.result.error?e.jsx("span",{className:"text-red-400",children:l.result.error}):e.jsxs("div",{children:[e.jsxs("span",{className:l.result.status&&l.result.status<400?"text-green-400 font-medium":"text-red-400 font-medium",children:[l.result.status," ",l.result.statusText]}),l.result.body&&e.jsx("pre",{className:"mt-2 text-[10px] text-muted-foreground/50 font-mono overflow-x-auto max-h-24 overflow-y-auto p-2 bg-background/50 rounded-lg",children:typeof l.result.body=="string"?l.result.body:JSON.stringify(l.result.body,null,2)})]})})]},n.id))})]})}const st={mail:We,calendar:Fe,hash:$e,github:Ue,"file-text":Me,"message-circle":Ge,"hard-drive":Pe,"layout-grid":Oe,zap:Z,bug:De,"list-checks":Re,"credit-card":Le,phone:_e,table:Te,kanban:Ie},rt={GMAIL:{bg:"bg-red-500/8",text:"text-red-400",ring:"ring-red-500/20"},GOOGLECALENDAR:{bg:"bg-blue-500/8",text:"text-blue-400",ring:"ring-blue-500/20"},SLACK:{bg:"bg-purple-500/8",text:"text-purple-400",ring:"ring-purple-500/20"},GITHUB:{bg:"bg-neutral-500/8",text:"text-neutral-300",ring:"ring-neutral-500/20"},NOTION:{bg:"bg-neutral-500/8",text:"text-neutral-300",ring:"ring-neutral-500/20"},DISCORD:{bg:"bg-indigo-500/8",text:"text-indigo-400",ring:"ring-indigo-500/20"},GOOGLEDRIVE:{bg:"bg-yellow-500/8",text:"text-yellow-400",ring:"ring-yellow-500/20"},TRELLO:{bg:"bg-blue-500/8",text:"text-blue-400",ring:"ring-blue-500/20"},LINEAR:{bg:"bg-violet-500/8",text:"text-violet-400",ring:"ring-violet-500/20"},JIRA:{bg:"bg-blue-600/8",text:"text-blue-500",ring:"ring-blue-600/20"},ASANA:{bg:"bg-rose-500/8",text:"text-rose-400",ring:"ring-rose-500/20"},STRIPE:{bg:"bg-violet-500/8",text:"text-violet-400",ring:"ring-violet-500/20"},TWILIO:{bg:"bg-red-500/8",text:"text-red-400",ring:"ring-red-500/20"},AIRTABLE:{bg:"bg-teal-500/8",text:"text-teal-400",ring:"ring-teal-500/20"}},nt={bg:"bg-primary/8",text:"text-primary",ring:"ring-primary/20"};function ot(){const[o,h]=s.useState([]),[b,N]=s.useState(!0),[E,A]=s.useState(!1),[C,d]=s.useState(null),[f,m]=s.useState(null),v=s.useCallback(async()=>{try{const u=await(await $.composio.catalog()).json();h(u.catalog||[]),A(u.composioAvailable)}catch{A(!1)}N(!1)},[]);s.useEffect(()=>{v()},[v]);const l=async t=>{d(t);try{const g=await(await $.composio.connect(t)).json();if(g.redirectUrl){const w=window.open(g.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),S=setInterval(async()=>{try{(await(await $.composio.waitForConnection(g.connectedAccountId)).json()).status==="ACTIVE"&&(clearInterval(S),w==null||w.close(),d(null),v())}catch{}},2e3);setTimeout(()=>{clearInterval(S),d(null)},12e4)}}catch{d(null)}},j=async t=>{if(t.connectionId){m(t.id);try{await $.composio.disconnect(t.connectionId),await v()}catch{}m(null)}};if(b)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading integrations..."})]});if(!E)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(V,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"Composio Not Configured"}),e.jsxs("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed",children:["Set ",e.jsx("code",{className:"px-1 py-0.5 bg-muted/40 rounded text-[10px] font-mono",children:"COMPOSIO_API_KEY"})," in your server environment to unlock 850+ app integrations."]})]});const c=o.filter(t=>t.connected).length;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Integrations"}),e.jsxs("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:[c," of ",o.length," connected"]})]}),e.jsxs("button",{onClick:v,className:"flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground bg-muted/30 hover:bg-muted/50 rounded-lg transition-colors",title:"Refresh",children:[e.jsx(Ae,{className:"w-3.5 h-3.5"}),"Refresh"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:o.map((t,u)=>{const g=rt[t.id]||nt,w=st[t.icon]||V,S=C===t.id,T=f===t.id;return e.jsxs("div",{className:`group relative flex flex-col items-center text-center p-4 rounded-2xl border transition-all duration-200 ${t.connected?"bg-green-500/[0.03] border-green-500/15 hover:border-green-500/30":"bg-card/50 border-border/30 hover:border-border/60 hover:bg-muted/20"}`,style:{animationDelay:`${u*40}ms`},children:[t.connected&&e.jsx("div",{className:"absolute top-2.5 right-2.5",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-400 ring-2 ring-green-400/20"})}),e.jsx("div",{className:`w-12 h-12 rounded-xl ${g.bg} ring-1 ${g.ring} flex items-center justify-center mb-3 transition-transform duration-200 group-hover:scale-105`,children:e.jsx(w,{className:`w-5 h-5 ${g.text}`})}),e.jsx("span",{className:"text-xs font-semibold text-foreground mb-0.5",children:t.name}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/40 mb-3",children:[t.popularActions.length," action",t.popularActions.length!==1?"s":""]}),t.connected?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-green-400 font-medium flex-1 justify-center",children:[e.jsx(ie,{className:"w-3 h-3"}),"Connected"]}),e.jsx("button",{onClick:()=>j(t),disabled:T,className:"p-1 text-muted-foreground/30 hover:text-red-400 transition-colors opacity-0 group-hover:opacity-100",title:"Disconnect",children:T?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(q,{className:"w-3 h-3"})})]}):e.jsxs("button",{onClick:()=>l(t.id),disabled:S,className:"flex items-center justify-center gap-1.5 w-full px-3 py-1.5 text-[11px] font-medium bg-foreground/[0.06] hover:bg-foreground/10 text-foreground rounded-lg transition-colors disabled:opacity-50",children:[S?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(le,{className:"w-3 h-3"}),"Connect"]})]},t.id)})})]})}const at=[{id:"workflows",label:"Workflows",icon:Z},{id:"webhooks",label:"Webhooks",icon:He},{id:"integrations",label:"Integrations",icon:V}];function mt({selectedProject:o}){const[h,b]=s.useState("list"),[N,E]=s.useState("workflows"),[A,C]=s.useState(null),[d,f]=s.useState(0),m=s.useCallback(c=>{C(c),b("editor")},[]),v=s.useCallback(()=>{C(null),b("editor")},[]),l=s.useCallback(()=>{b("list"),E("workflows"),C(null),f(c=>c+1)},[]),j=s.useCallback(()=>{b("list"),C(null)},[]);return h==="editor"?e.jsx("div",{className:"h-full",children:e.jsx(Xe,{workflow:A,onSave:l,onCancel:j})}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"flex-shrink-0 px-4 pt-4 pb-0",children:e.jsx("div",{className:"flex sm:inline-flex items-center bg-muted/30 rounded-xl p-1 gap-0.5",children:at.map(c=>{const t=c.icon,u=N===c.id;return e.jsxs("button",{onClick:()=>E(c.id),className:`flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium rounded-lg transition-all duration-150 ${u?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(t,{className:"w-3.5 h-3.5"}),c.label]},c.id)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[N==="workflows"&&e.jsx(ze,{onEdit:m,onCreate:v,refreshKey:d}),N==="webhooks"&&e.jsx(tt,{onWebhooksChange:()=>f(c=>c+1)}),N==="integrations"&&e.jsx(ot,{})]})]})}export{mt as default};