flujo-ai 3.24.0 → 3.26.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 (363) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +233 -217
  3. package/.next/app-path-routes-manifest.json +8 -8
  4. package/.next/build-manifest.json +5 -5
  5. package/.next/react-loadable-manifest.json +25 -20
  6. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  7. package/.next/server/app/_not-found.html +1 -1
  8. package/.next/server/app/_not-found.rsc +3 -3
  9. package/.next/server/app/api/approvals/[id]/route.js +1 -1
  10. package/.next/server/app/api/approvals/[id]/route.js.nft.json +1 -1
  11. package/.next/server/app/api/approvals/[id]/route_client-reference-manifest.js +1 -1
  12. package/.next/server/app/api/approvals/route.js.nft.json +1 -1
  13. package/.next/server/app/api/approvals/route_client-reference-manifest.js +1 -1
  14. package/.next/server/app/api/backup/route.js +1 -1
  15. package/.next/server/app/api/backup/route.js.nft.json +1 -1
  16. package/.next/server/app/api/backup/route_client-reference-manifest.js +1 -1
  17. package/.next/server/app/api/browse/route.js +1 -1
  18. package/.next/server/app/api/browse/route_client-reference-manifest.js +1 -1
  19. package/.next/server/app/api/bugs/enhance/route.js +1 -1
  20. package/.next/server/app/api/bugs/enhance/route.js.nft.json +1 -1
  21. package/.next/server/app/api/bugs/enhance/route_client-reference-manifest.js +1 -1
  22. package/.next/server/app/api/cwd/route.js +1 -1
  23. package/.next/server/app/api/cwd/route_client-reference-manifest.js +1 -1
  24. package/.next/server/app/api/encryption/secure/route.js +1 -1
  25. package/.next/server/app/api/encryption/secure/route.js.nft.json +1 -1
  26. package/.next/server/app/api/encryption/secure/route_client-reference-manifest.js +1 -1
  27. package/.next/server/app/api/env/route.js +1 -1
  28. package/.next/server/app/api/env/route_client-reference-manifest.js +1 -1
  29. package/.next/server/app/api/flow/[id]/route.js.nft.json +1 -1
  30. package/.next/server/app/api/flow/[id]/route_client-reference-manifest.js +1 -1
  31. package/.next/server/app/api/flow/compile/route.js.nft.json +1 -1
  32. package/.next/server/app/api/flow/compile/route_client-reference-manifest.js +1 -1
  33. package/.next/server/app/api/flow/generate/route.js.nft.json +1 -1
  34. package/.next/server/app/api/flow/generate/route_client-reference-manifest.js +1 -1
  35. package/.next/server/app/api/flow/improve/route.js.nft.json +1 -1
  36. package/.next/server/app/api/flow/improve/route_client-reference-manifest.js +1 -1
  37. package/.next/server/app/api/flow/prompt-renderer/route.js.nft.json +1 -1
  38. package/.next/server/app/api/flow/prompt-renderer/route_client-reference-manifest.js +1 -1
  39. package/.next/server/app/api/flow/quick-chat/route.js.nft.json +1 -1
  40. package/.next/server/app/api/flow/quick-chat/route_client-reference-manifest.js +1 -1
  41. package/.next/server/app/api/flow/repair/route.js.nft.json +1 -1
  42. package/.next/server/app/api/flow/repair/route_client-reference-manifest.js +1 -1
  43. package/.next/server/app/api/flow/route.js.nft.json +1 -1
  44. package/.next/server/app/api/flow/route_client-reference-manifest.js +1 -1
  45. package/.next/server/app/api/git/route.js +1 -1
  46. package/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
  47. package/.next/server/app/api/init/route.js.nft.json +1 -1
  48. package/.next/server/app/api/init/route_client-reference-manifest.js +1 -1
  49. package/.next/server/app/api/local-models/capability/route_client-reference-manifest.js +1 -1
  50. package/.next/server/app/api/local-models/pull/route_client-reference-manifest.js +1 -1
  51. package/.next/server/app/api/local-models/suggest/route_client-reference-manifest.js +1 -1
  52. package/.next/server/app/api/mcp/cancel/route.js.nft.json +1 -1
  53. package/.next/server/app/api/mcp/cancel/route_client-reference-manifest.js +1 -1
  54. package/.next/server/app/api/mcp/servers/[name]/prompts/get/route.js.nft.json +1 -1
  55. package/.next/server/app/api/mcp/servers/[name]/prompts/get/route_client-reference-manifest.js +1 -1
  56. package/.next/server/app/api/mcp/servers/[name]/prompts/route.js.nft.json +1 -1
  57. package/.next/server/app/api/mcp/servers/[name]/prompts/route_client-reference-manifest.js +1 -1
  58. package/.next/server/app/api/mcp/servers/[name]/resources/read/route.js.nft.json +1 -1
  59. package/.next/server/app/api/mcp/servers/[name]/resources/read/route_client-reference-manifest.js +1 -1
  60. package/.next/server/app/api/mcp/servers/[name]/resources/route.js.nft.json +1 -1
  61. package/.next/server/app/api/mcp/servers/[name]/resources/route_client-reference-manifest.js +1 -1
  62. package/.next/server/app/api/mcp/servers/[name]/route.js +1 -1
  63. package/.next/server/app/api/mcp/servers/[name]/route.js.nft.json +1 -1
  64. package/.next/server/app/api/mcp/servers/[name]/route_client-reference-manifest.js +1 -1
  65. package/.next/server/app/api/mcp/servers/[name]/status/route.js.nft.json +1 -1
  66. package/.next/server/app/api/mcp/servers/[name]/status/route_client-reference-manifest.js +1 -1
  67. package/.next/server/app/api/mcp/servers/[name]/tools/[toolName]/route.js.nft.json +1 -1
  68. package/.next/server/app/api/mcp/servers/[name]/tools/[toolName]/route_client-reference-manifest.js +1 -1
  69. package/.next/server/app/api/mcp/servers/[name]/tools/route.js.nft.json +1 -1
  70. package/.next/server/app/api/mcp/servers/[name]/tools/route_client-reference-manifest.js +1 -1
  71. package/.next/server/app/api/mcp/servers/route.js +1 -1
  72. package/.next/server/app/api/mcp/servers/route.js.nft.json +1 -1
  73. package/.next/server/app/api/mcp/servers/route_client-reference-manifest.js +1 -1
  74. package/.next/server/app/api/mcp/test-connection/route.js +1 -1
  75. package/.next/server/app/api/mcp/test-connection/route.js.nft.json +1 -1
  76. package/.next/server/app/api/mcp/test-connection/route_client-reference-manifest.js +1 -1
  77. package/.next/server/app/api/mcp/test-connection/stream/route.js +1 -1
  78. package/.next/server/app/api/mcp/test-connection/stream/route.js.nft.json +1 -1
  79. package/.next/server/app/api/mcp/test-connection/stream/route_client-reference-manifest.js +1 -1
  80. package/.next/server/app/api/mcp-registry/route.js.nft.json +1 -1
  81. package/.next/server/app/api/mcp-registry/route_client-reference-manifest.js +1 -1
  82. package/.next/server/app/api/mcp-registry/spotlight/route_client-reference-manifest.js +1 -1
  83. package/.next/server/app/api/model/[id]/route.js.nft.json +1 -1
  84. package/.next/server/app/api/model/[id]/route_client-reference-manifest.js +1 -1
  85. package/.next/server/app/api/model/provider/route.js.nft.json +1 -1
  86. package/.next/server/app/api/model/provider/route_client-reference-manifest.js +1 -1
  87. package/.next/server/app/api/model/route.js.nft.json +1 -1
  88. package/.next/server/app/api/model/route_client-reference-manifest.js +1 -1
  89. package/.next/server/app/api/model/test/route.js.nft.json +1 -1
  90. package/.next/server/app/api/model/test/route_client-reference-manifest.js +1 -1
  91. package/.next/server/app/api/oauth/callback/route_client-reference-manifest.js +1 -1
  92. package/.next/server/app/api/oauth/initiate/route_client-reference-manifest.js +1 -1
  93. package/.next/server/app/api/oauth/reset/route.js.nft.json +1 -1
  94. package/.next/server/app/api/oauth/reset/route_client-reference-manifest.js +1 -1
  95. package/.next/server/app/api/planned-executions/[id]/route.js.nft.json +1 -1
  96. package/.next/server/app/api/planned-executions/[id]/route_client-reference-manifest.js +1 -1
  97. package/.next/server/app/api/planned-executions/[id]/run/route.js.nft.json +1 -1
  98. package/.next/server/app/api/planned-executions/[id]/run/route_client-reference-manifest.js +1 -1
  99. package/.next/server/app/api/planned-executions/[id]/runs/route.js.nft.json +1 -1
  100. package/.next/server/app/api/planned-executions/[id]/runs/route_client-reference-manifest.js +1 -1
  101. package/.next/server/app/api/planned-executions/preview-schedule/route_client-reference-manifest.js +1 -1
  102. package/.next/server/app/api/planned-executions/reconcile/route.js.nft.json +1 -1
  103. package/.next/server/app/api/planned-executions/reconcile/route_client-reference-manifest.js +1 -1
  104. package/.next/server/app/api/planned-executions/route.js.nft.json +1 -1
  105. package/.next/server/app/api/planned-executions/route_client-reference-manifest.js +1 -1
  106. package/.next/server/app/api/restore/route.js +1 -1
  107. package/.next/server/app/api/restore/route.js.nft.json +1 -1
  108. package/.next/server/app/api/restore/route_client-reference-manifest.js +1 -1
  109. package/.next/server/app/api/runs/active/route.js.nft.json +1 -1
  110. package/.next/server/app/api/runs/active/route_client-reference-manifest.js +1 -1
  111. package/.next/server/app/api/storage/route_client-reference-manifest.js +1 -1
  112. package/.next/server/app/api/update/route.js +1 -1
  113. package/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
  114. package/.next/server/app/api/waves/route.js +1 -1
  115. package/.next/server/app/api/waves/route.js.nft.json +1 -1
  116. package/.next/server/app/api/waves/route_client-reference-manifest.js +1 -1
  117. package/.next/server/app/api/webhooks/[id]/route.js +1 -1
  118. package/.next/server/app/api/webhooks/[id]/route.js.nft.json +1 -1
  119. package/.next/server/app/api/webhooks/[id]/route_client-reference-manifest.js +1 -1
  120. package/.next/server/app/chat/page.js +9 -9
  121. package/.next/server/app/chat/page.js.nft.json +1 -1
  122. package/.next/server/app/chat/page_client-reference-manifest.js +1 -1
  123. package/.next/server/app/chat.html +1 -1
  124. package/.next/server/app/chat.rsc +4 -4
  125. package/.next/server/app/docs/page.js +11 -8
  126. package/.next/server/app/docs/page.js.nft.json +1 -1
  127. package/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  128. package/.next/server/app/docs.html +1 -1
  129. package/.next/server/app/docs.rsc +4 -4
  130. package/.next/server/app/executions/page.js +3 -3
  131. package/.next/server/app/executions/page.js.nft.json +1 -1
  132. package/.next/server/app/executions/page_client-reference-manifest.js +1 -1
  133. package/.next/server/app/executions.html +1 -1
  134. package/.next/server/app/executions.rsc +4 -4
  135. package/.next/server/app/flows/page.js +3 -3
  136. package/.next/server/app/flows/page.js.nft.json +1 -1
  137. package/.next/server/app/flows/page_client-reference-manifest.js +1 -1
  138. package/.next/server/app/flows.html +1 -1
  139. package/.next/server/app/flows.rsc +4 -4
  140. package/.next/server/app/index.html +1 -1
  141. package/.next/server/app/index.rsc +4 -4
  142. package/.next/server/app/mcp/page.js +5 -5
  143. package/.next/server/app/mcp/page.js.nft.json +1 -1
  144. package/.next/server/app/mcp/page_client-reference-manifest.js +1 -1
  145. package/.next/server/app/mcp-flows/route.js +1 -1
  146. package/.next/server/app/mcp-flows/route.js.nft.json +1 -1
  147. package/.next/server/app/mcp-flows/route_client-reference-manifest.js +1 -1
  148. package/.next/server/app/mcp-proxy/[server]/route.js +1 -1
  149. package/.next/server/app/mcp-proxy/[server]/route.js.nft.json +1 -1
  150. package/.next/server/app/mcp-proxy/[server]/route_client-reference-manifest.js +1 -1
  151. package/.next/server/app/mcp.html +1 -1
  152. package/.next/server/app/mcp.rsc +4 -4
  153. package/.next/server/app/models/page.js +2 -2
  154. package/.next/server/app/models/page.js.nft.json +1 -1
  155. package/.next/server/app/models/page_client-reference-manifest.js +1 -1
  156. package/.next/server/app/page.js +2 -2
  157. package/.next/server/app/page_client-reference-manifest.js +1 -1
  158. package/.next/server/app/settings/page.js +2 -57
  159. package/.next/server/app/settings/page.js.nft.json +1 -1
  160. package/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  161. package/.next/server/app/settings.html +1 -1
  162. package/.next/server/app/settings.rsc +4 -4
  163. package/.next/server/app/v1/chat/completions/route.js +1 -1
  164. package/.next/server/app/v1/chat/completions/route.js.nft.json +1 -1
  165. package/.next/server/app/v1/chat/completions/route_client-reference-manifest.js +1 -1
  166. package/.next/server/app/v1/chat/conversations/[conversationId]/breakpoints/route.js +1 -1
  167. package/.next/server/app/v1/chat/conversations/[conversationId]/breakpoints/route.js.nft.json +1 -1
  168. package/.next/server/app/v1/chat/conversations/[conversationId]/breakpoints/route_client-reference-manifest.js +1 -1
  169. package/.next/server/app/v1/chat/conversations/[conversationId]/cancel/route.js +1 -1
  170. package/.next/server/app/v1/chat/conversations/[conversationId]/cancel/route.js.nft.json +1 -1
  171. package/.next/server/app/v1/chat/conversations/[conversationId]/cancel/route_client-reference-manifest.js +1 -1
  172. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/continue/route.js +1 -1
  173. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/continue/route.js.nft.json +1 -1
  174. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/continue/route_client-reference-manifest.js +1 -1
  175. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/step/route.js +1 -1
  176. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/step/route.js.nft.json +1 -1
  177. package/.next/server/app/v1/chat/conversations/[conversationId]/debug/step/route_client-reference-manifest.js +1 -1
  178. package/.next/server/app/v1/chat/conversations/[conversationId]/edit-state/route.js +1 -1
  179. package/.next/server/app/v1/chat/conversations/[conversationId]/edit-state/route.js.nft.json +1 -1
  180. package/.next/server/app/v1/chat/conversations/[conversationId]/edit-state/route_client-reference-manifest.js +1 -1
  181. package/.next/server/app/v1/chat/conversations/[conversationId]/events/route.js.nft.json +1 -1
  182. package/.next/server/app/v1/chat/conversations/[conversationId]/events/route_client-reference-manifest.js +1 -1
  183. package/.next/server/app/v1/chat/conversations/[conversationId]/resources/route_client-reference-manifest.js +1 -1
  184. package/.next/server/app/v1/chat/conversations/[conversationId]/respond/route.js +1 -1
  185. package/.next/server/app/v1/chat/conversations/[conversationId]/respond/route.js.nft.json +1 -1
  186. package/.next/server/app/v1/chat/conversations/[conversationId]/respond/route_client-reference-manifest.js +1 -1
  187. package/.next/server/app/v1/chat/conversations/[conversationId]/route.js +1 -1
  188. package/.next/server/app/v1/chat/conversations/[conversationId]/route.js.nft.json +1 -1
  189. package/.next/server/app/v1/chat/conversations/[conversationId]/route_client-reference-manifest.js +1 -1
  190. package/.next/server/app/v1/chat/conversations/route.js +1 -1
  191. package/.next/server/app/v1/chat/conversations/route.js.nft.json +1 -1
  192. package/.next/server/app/v1/chat/conversations/route_client-reference-manifest.js +1 -1
  193. package/.next/server/app/v1/models/route.js.nft.json +1 -1
  194. package/.next/server/app/v1/models/route_client-reference-manifest.js +1 -1
  195. package/.next/server/app/waves/page.js +3 -3
  196. package/.next/server/app/waves/page.js.nft.json +1 -1
  197. package/.next/server/app/waves/page_client-reference-manifest.js +1 -1
  198. package/.next/server/app/waves.html +1 -1
  199. package/.next/server/app/waves.rsc +4 -4
  200. package/.next/server/app-paths-manifest.json +8 -8
  201. package/.next/server/chunks/1083.js +1 -1
  202. package/.next/server/chunks/1114.js +1 -0
  203. package/.next/server/chunks/1197.js +2 -2
  204. package/.next/server/chunks/1226.js +1 -1
  205. package/.next/server/chunks/166.js +5 -0
  206. package/.next/server/chunks/2373.js +1 -0
  207. package/.next/server/chunks/2859.js +1 -3
  208. package/.next/server/chunks/289.js +1 -1
  209. package/.next/server/chunks/3030.js +1 -1
  210. package/.next/server/chunks/3298.js +2 -0
  211. package/.next/server/chunks/3312.js +1 -0
  212. package/.next/server/chunks/3774.js +1 -1
  213. package/.next/server/chunks/3823.js +7 -7
  214. package/.next/server/chunks/3855.js +1 -0
  215. package/.next/server/chunks/3924.js +52 -0
  216. package/.next/server/chunks/4545.js +6 -2
  217. package/.next/server/chunks/4561.js +7 -7
  218. package/.next/server/chunks/4578.js +1 -0
  219. package/.next/server/chunks/4671.js +1 -1
  220. package/.next/server/chunks/4677.js +37 -0
  221. package/.next/server/chunks/4771.js +2 -2
  222. package/.next/server/chunks/4793.js +2 -0
  223. package/.next/server/chunks/4836.js +1 -0
  224. package/.next/server/chunks/5311.js +1 -1
  225. package/.next/server/chunks/5463.js +1 -0
  226. package/.next/server/chunks/5544.js +5 -0
  227. package/.next/server/chunks/5708.js +11 -8
  228. package/.next/server/chunks/584.js +1 -0
  229. package/.next/server/chunks/62.js +1 -1
  230. package/.next/server/chunks/6240.js +1 -0
  231. package/.next/server/chunks/6306.js +1 -0
  232. package/.next/server/chunks/{3928.js → 6745.js} +1 -1
  233. package/.next/server/chunks/6908.js +2 -2
  234. package/.next/server/chunks/701.js +1 -1
  235. package/.next/server/chunks/7214.js +6 -0
  236. package/.next/server/chunks/7362.js +9 -5
  237. package/.next/server/chunks/7463.js +6 -0
  238. package/.next/server/chunks/7506.js +1 -1
  239. package/.next/server/chunks/7579.js +82 -0
  240. package/.next/server/chunks/8216.js +1 -0
  241. package/.next/server/chunks/8387.js +1 -0
  242. package/.next/server/chunks/856.js +5 -0
  243. package/.next/server/chunks/8739.js +2 -2
  244. package/.next/server/chunks/9165.js +1 -0
  245. package/.next/server/chunks/94.js +1 -0
  246. package/.next/server/chunks/9427.js +1 -0
  247. package/.next/server/functions-config-manifest.json +2 -2
  248. package/.next/server/instrumentation.js.nft.json +1 -1
  249. package/.next/server/middleware-build-manifest.js +1 -1
  250. package/.next/server/middleware-manifest.json +1 -1
  251. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  252. package/.next/server/pages/404.html +1 -1
  253. package/.next/server/pages/500.html +1 -1
  254. package/.next/server/server-reference-manifest.js +1 -1
  255. package/.next/server/server-reference-manifest.json +1 -1
  256. package/.next/server/src/middleware.js +2 -2
  257. package/.next/server/src/middleware.js.map +1 -1
  258. package/.next/static/chunks/1675-773454288de4309d.js +1 -0
  259. package/.next/static/chunks/1731-6e45fb529f9044a3.js +1 -0
  260. package/.next/static/chunks/1871-14c3e63ca865d85e.js +1 -0
  261. package/.next/static/chunks/2003-7710c23acaef11c9.js +1 -0
  262. package/.next/static/chunks/2318-76fcb6c769b1a569.js +1 -0
  263. package/.next/static/chunks/2566-6e2b9d9349814789.js +1 -0
  264. package/.next/static/chunks/2734-59fbe2f62a59df86.js +1 -0
  265. package/.next/static/chunks/3089.6b4e21e1faa304e2.js +1 -0
  266. package/.next/static/chunks/3109-11bdec9bdfd996c3.js +1 -0
  267. package/.next/static/chunks/3217.f728df99ab5da33c.js +1 -0
  268. package/.next/static/chunks/333-5f3c5be57c80c48c.js +1 -0
  269. package/.next/static/chunks/3333-b7b3e5758a568013.js +1 -0
  270. package/.next/static/chunks/3556-3b6f7c99b015b752.js +1 -0
  271. package/.next/static/chunks/{6257-ee5d8d88050d7705.js → 4003-3b3768446ae333df.js} +1 -1
  272. package/.next/static/chunks/4523-a540747aa2ed34e8.js +1 -0
  273. package/.next/static/chunks/4635-0fe310d3be64e71e.js +1 -0
  274. package/.next/static/chunks/4690-ec7d397cfacedac3.js +1 -0
  275. package/.next/static/chunks/4775-cb9c0be621363a08.js +8 -0
  276. package/.next/static/chunks/5336-81da1080de29ebfc.js +1 -0
  277. package/.next/static/chunks/5512.d01d565f73109a1a.js +1 -0
  278. package/.next/static/chunks/6691-117567b2b40cd9f4.js +1 -0
  279. package/.next/static/chunks/7274-1184563607f2b5f5.js +1 -0
  280. package/.next/static/chunks/8166-e75acdc559b34fcd.js +1 -0
  281. package/.next/static/chunks/8345.fbc0af16acce7256.js +1 -0
  282. package/.next/static/chunks/8405.e728bc83a7c9fed6.js +1 -0
  283. package/.next/static/chunks/8470-72cf748472d4d501.js +1 -0
  284. package/.next/static/chunks/8607-5787e42775fc3acb.js +1 -0
  285. package/.next/static/chunks/8610-660d5088bc1dd7a7.js +1 -0
  286. package/.next/static/chunks/8834-faf121e257b517d5.js +1 -0
  287. package/.next/static/chunks/8989-401559d9f3bc80a0.js +1 -0
  288. package/.next/static/chunks/{9164-d9f1abba780231e0.js → 9164-829ab5b085ec06d6.js} +1 -1
  289. package/.next/static/chunks/9240-d0a51f4d504f34b1.js +1 -0
  290. package/.next/static/chunks/9562-b7922ceb400ec536.js +1 -0
  291. package/.next/static/chunks/9704-6b7415964d7c042a.js +1 -0
  292. package/.next/static/chunks/app/chat/page-04ad1fad78048afb.js +1 -0
  293. package/.next/static/chunks/app/docs/page-5475c616764dbb18.js +1 -0
  294. package/.next/static/chunks/app/executions/page-c18708ed96d228ec.js +1 -0
  295. package/.next/static/chunks/app/flows/page-f7e44aa545bcc56e.js +1 -0
  296. package/.next/static/chunks/app/layout-e6fbae80e0f456a6.js +1 -0
  297. package/.next/static/chunks/app/mcp/page-3638fbee04a3a6ea.js +1 -0
  298. package/.next/static/chunks/app/models/error-5732fbb053e182c5.js +1 -0
  299. package/.next/static/chunks/app/models/page-e690a986047b1e62.js +1 -0
  300. package/.next/static/chunks/app/{page-a859e4dbd180df98.js → page-0a95c40a65dbd2eb.js} +1 -1
  301. package/.next/static/chunks/app/settings/page-3ef9b95187e18a5a.js +1 -0
  302. package/.next/static/chunks/app/waves/page-c9a307e2236423a4.js +1 -0
  303. package/.next/static/chunks/webpack-a6844e1074885c2f.js +1 -0
  304. package/.next/static/css/40f9bef305b11bf5.css +1 -0
  305. package/.next/trace +10 -8
  306. package/README.md +31 -1
  307. package/package.json +1 -1
  308. package/.next/server/chunks/1119.js +0 -1
  309. package/.next/server/chunks/1439.js +0 -1
  310. package/.next/server/chunks/1910.js +0 -37
  311. package/.next/server/chunks/1999.js +0 -1
  312. package/.next/server/chunks/2246.js +0 -1
  313. package/.next/server/chunks/2823.js +0 -6
  314. package/.next/server/chunks/2998.js +0 -52
  315. package/.next/server/chunks/3286.js +0 -6
  316. package/.next/server/chunks/3291.js +0 -1
  317. package/.next/server/chunks/4637.js +0 -81
  318. package/.next/server/chunks/6644.js +0 -1
  319. package/.next/server/chunks/7427.js +0 -1
  320. package/.next/server/chunks/7723.js +0 -1
  321. package/.next/server/chunks/7769.js +0 -6
  322. package/.next/server/chunks/8518.js +0 -2
  323. package/.next/static/chunks/1620-0d8ecd877f123f7b.js +0 -1
  324. package/.next/static/chunks/1871-dd8c10ed9d37100b.js +0 -1
  325. package/.next/static/chunks/1983-242862b3dc022a26.js +0 -1
  326. package/.next/static/chunks/2003-460f30484998c05d.js +0 -1
  327. package/.next/static/chunks/2619-04bc32f026a0d946.js +0 -1
  328. package/.next/static/chunks/3217.058098140ec3f563.js +0 -1
  329. package/.next/static/chunks/3454-a8db9caba457e5fa.js +0 -1
  330. package/.next/static/chunks/3730-149f2f058529f75f.js +0 -1
  331. package/.next/static/chunks/3736-5e2b3f6cda1bb923.js +0 -1
  332. package/.next/static/chunks/4207-41abb9622eb4b4f8.js +0 -1
  333. package/.next/static/chunks/4749-f8796d16ff604d54.js +0 -1
  334. package/.next/static/chunks/4812-4a9aceb49632a973.js +0 -1
  335. package/.next/static/chunks/5501-f5b093c8dfd74196.js +0 -1
  336. package/.next/static/chunks/6016.8201fa15ab6aa90e.js +0 -1
  337. package/.next/static/chunks/6288-a285bbbd701e0dbf.js +0 -1
  338. package/.next/static/chunks/6731-c230e88cf0032609.js +0 -1
  339. package/.next/static/chunks/7430-6e78aaeac66988a9.js +0 -1
  340. package/.next/static/chunks/7583.7af90b94e3c263f2.js +0 -1
  341. package/.next/static/chunks/7687-7edf1a6e1f063b08.js +0 -1
  342. package/.next/static/chunks/8083.16fda2c7f6d10d0c.js +0 -1
  343. package/.next/static/chunks/8480-229fd353b68b570f.js +0 -1
  344. package/.next/static/chunks/8548-8e4a95334064e8b2.js +0 -1
  345. package/.next/static/chunks/8611-f6d51119761d52ff.js +0 -8
  346. package/.next/static/chunks/8834-bda798efab40c60a.js +0 -1
  347. package/.next/static/chunks/9356-99ba407b60b9dfe9.js +0 -1
  348. package/.next/static/chunks/9451-680fa09f81f18806.js +0 -1
  349. package/.next/static/chunks/9659-a279e3aaba407251.js +0 -1
  350. package/.next/static/chunks/app/chat/page-6a5b5f9ea2542fb3.js +0 -1
  351. package/.next/static/chunks/app/docs/page-935b0386917b91bb.js +0 -1
  352. package/.next/static/chunks/app/executions/page-d72027b0179e8fa2.js +0 -1
  353. package/.next/static/chunks/app/flows/page-fbce5abe34500f28.js +0 -1
  354. package/.next/static/chunks/app/layout-2ebf01d97702a18a.js +0 -1
  355. package/.next/static/chunks/app/mcp/page-8666173926cabf31.js +0 -1
  356. package/.next/static/chunks/app/models/error-a3183f168e8a9b04.js +0 -1
  357. package/.next/static/chunks/app/models/page-18dbd8e01cf87e98.js +0 -1
  358. package/.next/static/chunks/app/settings/page-7a68583660508ffd.js +0 -1
  359. package/.next/static/chunks/app/waves/page-ec33cf79f6103a9e.js +0 -1
  360. package/.next/static/chunks/webpack-f4a471ab560eb19e.js +0 -1
  361. package/.next/static/css/39393a79f7cb0dee.css +0 -1
  362. /package/.next/static/{eUM7C1boixGI469h5wtIk → Il6IDWxf3CN0dv-P6QQrp}/_buildManifest.js +0 -0
  363. /package/.next/static/{eUM7C1boixGI469h5wtIk → Il6IDWxf3CN0dv-P6QQrp}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3080],{9898:(e,t,r)=>{"use strict";r.d(t,{v:()=>s});var o=r(12115),n=r(17897);let l=(0,r(87021).h)("frontend/hooks/useServerStatus");function a(e){return"stdio"===e.transport?e.args&&e.args.length>0?e.args[0]:"Unknown path":"websocket"===e.transport?e.websocketUrl||"Unknown URL":e.serverUrl||"Unknown URL"}function s(){let[e,t]=(0,o.useState)([]),[r,s]=(0,o.useState)(!0),[i,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(new Set),p=(0,o.useCallback)(async()=>{l.debug("Loading servers"),s(!0),d(null);try{let e=await n.S.loadServerConfigs();if(!e||"error"in e){l.warn("Failed to load server configurations:",null==e?void 0:e.error),d((null==e?void 0:e.error)||"Failed to load server configurations"),s(!1);return}let r=await Promise.all(e.map(async e=>{l.debug("Getting status for server: ".concat(e.name));let t=await n.S.getServerStatus(e.name),r="string"==typeof t?t:t.status,o="object"==typeof t&&t.message?t.message:void 0,s="object"==typeof t&&t.stderrOutput?t.stderrOutput:void 0,i=a(e);return{...e,path:i,status:r,error:o,stderrOutput:s}}));l.debug("Final server states:",r),t(r),s(!1)}catch(e){l.warn("Failed to load servers:",e),d("Failed to load servers"),s(!1)}},[]),f=(0,o.useCallback)(async(r,o)=>{l.debug("Toggling server ".concat(r," to ").concat(o?"enabled":"disabled"));try{let a=e.find(e=>e.name===r);if(!a)return l.warn("Server not found: ".concat(r)),!1;l.debug("Found server ".concat(r,", current disabled state: ").concat(a.disabled));let s=await n.S.updateServerConfig(r,{disabled:!o});if(s.error)return l.warn("Failed to update server config:",[s.error,r]),!1;l.debug("Updating server ".concat(r," state in UI, new disabled state: ").concat(!o)),t(e=>e.map(e=>e.name===r?{...e,disabled:!o}:e)),l.info("Successfully toggled server ".concat(r," to ").concat(o?"enabled":"disabled"));try{let e=await n.S.getServerStatus(r),o="string"==typeof e?e:e.status,l="object"==typeof e&&e.message?e.message:void 0,a="object"==typeof e&&e.stderrOutput?e.stderrOutput:void 0;t(e=>e.map(e=>e.name===r?{...e,status:o,error:l,stderrOutput:a}:e))}catch(e){l.warn("Failed to get status for server ".concat(r," after toggle:"),e)}return!0}catch(e){return l.warn("Failed to toggle server:",e),!1}},[e]),h=(0,o.useCallback)(async r=>{l.debug("Deleting server: ".concat(r));try{if(!e.find(e=>e.name===r))return l.warn("Server not found:",r),!1;let o=await n.S.deleteServerConfig(r);if(o.error)return l.warn("Failed to delete server config:",o.error),!1;return t(e=>e.filter(e=>e.name!==r)),!0}catch(e){return l.warn("Failed to delete server:",e),!1}},[e]),m=(0,o.useCallback)(async e=>{l.debug("Adding server:",e);try{let r=a(e),o={...e,path:r,status:"connecting",tools:[],env:e.env||{}};t(e=>[...e,o]),u(t=>new Set(t).add(e.name));let s=await n.S.updateServerConfig(e.name,e);if(s.error)return l.warn("Failed to update server config:",s.error),t(t=>t.map(t=>t.name===e.name?{...t,status:"error",error:s.error}:t)),u(t=>{let r=new Set(t);return r.delete(e.name),r}),!1;l.info("Successfully added server ".concat(e.name));try{let r=await n.S.getServerStatus(e.name),o="string"==typeof r?r:r.status,l="object"==typeof r&&r.message?r.message:void 0,a="object"==typeof r&&r.stderrOutput?r.stderrOutput:void 0;t(t=>t.map(t=>t.name===e.name?{...t,status:o,error:l,stderrOutput:a}:t))}catch(t){l.warn("Failed to get status for server ".concat(e.name," after adding:"),t)}return u(t=>{let r=new Set(t);return r.delete(e.name),r}),!0}catch(r){return l.warn("Failed to add server:",r),t(t=>t.map(t=>t.name===e.name?{...t,status:"error",error:r instanceof Error?r.message:"Unknown error during server addition"}:t)),u(t=>{let r=new Set(t);return r.delete(e.name),r}),!1}},[]),g=(0,o.useCallback)(async(e,r)=>{let o=null!=r?r:e.name,s=o!==e.name;l.debug("Updating server:",e);try{t(t=>t.map(t=>t.name===o?{...e,path:a(e),status:t.status,error:t.error,stderrOutput:t.stderrOutput}:t));let r=await n.S.updateServerConfig(o,e);if(r.error){if(l.warn("Failed to update server config:",r.error),s)return await p(),!1;return t(t=>t.map(t=>t.name===e.name?{...t,status:"error",error:r.error}:t)),!1}l.info("Successfully updated config for server ".concat(e.name));try{let r=await n.S.getServerStatus(e.name),o="string"==typeof r?r:r.status,l="object"==typeof r&&r.message?r.message:void 0,a="object"==typeof r&&r.stderrOutput?r.stderrOutput:void 0;t(t=>t.map(t=>t.name===e.name?{...t,status:o,error:l,stderrOutput:a}:t))}catch(t){l.warn("Failed to get status for server ".concat(e.name," after config update:"),t)}return!0}catch(o){if(l.warn("Failed to update server:",o),s)return await p(),!1;let r=o instanceof Error?o.message:"Unknown error during update";return t(t=>t.map(t=>t.name===e.name?{...t,status:"error",error:r}:t)),!1}},[p]),x=(0,o.useCallback)(async(e,r)=>{let o=r&&r.trim()?r.trim():"";l.debug("Setting folder for server ".concat(e," to ").concat(o||"(none)"));try{let r=await n.S.updateServerConfig(e,{folder:o});if("error"in r&&r.error)return l.warn("Failed to update server folder:",r.error),!1;return t(t=>t.map(t=>t.name===e?{...t,folder:o||void 0}:t)),!0}catch(e){return l.warn("Failed to set server folder:",e),!1}},[]),v=(0,o.useCallback)(async(r,o)=>{l.debug("Saving environment variables for server: ".concat(r),o);try{if(!e.find(e=>e.name===r))return l.warn("Server not found: ".concat(r)),!1;let a=await n.S.updateServerConfig(r,{env:o});if(a.error)return l.warn("Failed to update server config:",a.error),!1;return l.debug("Updating environment variables in UI for server: ".concat(r)),t(e=>e.map(e=>e.name===r?{...e,env:o}:e)),l.info("Successfully saved environment variables for server: ".concat(r)),!0}catch(e){return l.warn("Failed to save environment variables:",e),!1}},[e]);return(0,o.useEffect)(()=>{p()},[p]),{servers:e,isLoading:r,loadError:i,connectingServers:c,loadServers:p,toggleServer:f,retryServer:(0,o.useCallback)(async e=>{l.debug("Retrying server status for: ".concat(e));try{let r=await n.S.getServerStatus(e),o="string"==typeof r?r:r.status,l="object"==typeof r&&r.message?r.message:void 0,a="object"==typeof r&&r.stderrOutput?r.stderrOutput:void 0;return t(t=>t.map(t=>t.name===e?{...t,status:o,error:l,stderrOutput:a}:t)),!0}catch(e){return l.warn("Failed to retry server status:",e),!1}},[]),deleteServer:h,addServer:m,updateServer:g,setServerFolder:x,saveEnv:v}}},27156:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var o=function(e){return e.MODELS="models",e.FLOWS="flows",e.CHAT_HISTORY="history",e.THEME="theme",e.ENCRYPTION_KEY="encryption_key",e.MCP_SERVERS="mcp_servers",e.GLOBAL_ENV_VARS="global_env_vars",e.CURRENT_CONVERSATION_ID="current_conversation_id",e.SELECTED_FLOW_ID="selected_flow_id",e.LAST_PICKED_FLOW_ID="last_picked_flow_id",e.SPEECH_SETTINGS="speech_settings",e.SPOTLIGHT_SERVERS="spotlight_servers",e.PLANNED_EXECUTIONS="planned_executions",e.MCP_AUTO_INSTALL_SETTINGS="mcp_auto_install_settings",e.MCP_QUALITY_SETTINGS="mcp_quality_settings",e.RUN_RESOURCE_SETTINGS="run_resource_settings",e.KV_STORE_SETTINGS="kv_store_settings",e.PENDING_APPROVALS="pending_approvals",e}({})},29692:(e,t,r)=>{"use strict";r.d(t,{Zg:()=>o.Z,YM:()=>i,VH:()=>s,Mj:()=>a});var o=r(27156),n=r(12115);let l=(0,r(87021).h)("utils/storage/frontend.ts");function a(e,t){l.verbose("useLocalStorage: Entering method");let[r,o]=(0,n.useState)(t),[a,s]=(0,n.useState)(!0),i=(0,n.useRef)(r);return(0,n.useEffect)(()=>{i.current=r},[r]),(0,n.useEffect)(()=>{(async()=>{l.verbose("loadValue: Entering method");try{let r=await fetch("/api/storage?key=".concat(encodeURIComponent(e),"&defaultValue=").concat(encodeURIComponent(JSON.stringify(t)))),n=await r.json();r.ok&&o(n.value)}catch(t){l.warn('Error reading storage key "'.concat(e,'":'),t)}finally{s(!1)}})()},[e]),[r,(0,n.useCallback)(async t=>{l.verbose("setValue: Entering method");try{let r=t instanceof Function?t(i.current):t;if(o(r),!(await fetch("/api/storage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e,value:r})})).ok)throw Error("Failed to save value")}catch(t){l.warn('Error setting storage key "'.concat(e,'":'),t)}},[e]),a]}let s=async(e,t)=>{l.verbose("saveItem: Entering method");try{if(!(await fetch("/api/storage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e,value:t})})).ok)throw Error("Failed to save item")}catch(e){throw l.error("Error saving to storage:",e),e}},i=async(e,t)=>{l.verbose("loadItem: Entering method");try{let r=await fetch("/api/storage?key=".concat(encodeURIComponent(e),"&defaultValue=").concat(encodeURIComponent(JSON.stringify(t))));if(!r.ok)throw Error("Failed to load item");return(await r.json()).value}catch(e){return l.error("Error loading from storage:",e),t}}},32098:()=>{},52759:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>r_});var o=r(95155),n=r(12115),l=r(33567),a=r(94049),s=r(25635),i=r(91871),d=r(5421),c=r(41983),u=r(78470),p=r(50430),f=r(22003),h=r(2778),m=r(52363),g=r(65036),x=r(50001),v=r(9562),b=r(75912),y=r(14287),w=r(86946),j=r(72167),A=r(48116),C=r(2300),S=r(27845),k=r(36314),T=r(86973),N=r(21067),I=r(87021),M=r(22539),P=r(74879),F=r(90057),E=r(17897),R=r(76122);R.TG.ArrowClosed;let D={type:"resourceEdge",animated:!1,style:{stroke:"#009688",strokeWidth:2},markerEnd:{type:R.TG.ArrowClosed,width:20,height:20,color:"#009688"}},L={type:"mcpEdge",animated:!1,style:{stroke:"#1976d2",strokeWidth:2},markerEnd:{type:R.TG.ArrowClosed,width:20,height:20,color:"#1976d2"},markerStart:{type:R.TG.ArrowClosed,width:20,height:20,color:"#1976d2"}};function z(e){return!!e&&e.includes("mcp")}function W(e){return!!e&&e.includes("resource")}function O(e,t,r,o){if("start"===r)return"Start nodes cannot have incoming connections";if("finish"===e)return"Finish nodes cannot have outgoing connections";if("mcp"===e||"mcp"===r||z(t)||z(o))return("mcp"!==e||"process"!==r)&&("process"!==e||"mcp"!==r)?"MCP connections must link an MCP node to a Process node via MCP handles":"process"!==e||z(t)?null:"Connect MCP nodes from the Process node's left/right MCP handles";if("resource"===e||"resource"===r||W(t)||W(o)){if(("resource"!==e||"process"!==r)&&("process"!==e||"resource"!==r))return"Resource connections must link a Resource node to a Process node via resource handles";if("process"===e&&!W(t))return"Connect Resource nodes from the Process node's left/right resource handles"}return null}function B(e,t){return"resource"===e?"resource-in":"process"===e&&W(t)?"process-left-resource":"process"===e&&z(t)?"process-left-mcp":"".concat(e,"-top")}function _(e,t,r){return t.filter(t=>{var o;return!function(e){var t;let r=null==e||null==(t=e.data)?void 0:t.edgeType;return"mcp"===r||"resource"===r}(t)&&(t.source===e?t.target!==r:t.target===e&&null!=(o=t.data)&&!!o.bidirectional&&t.source!==r)})}function H(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return console.error("Invalid connection: Missing source, target, or handles",e),!1;let o=t.find(t=>t.id===e.source),n=t.find(t=>t.id===e.target);if(!o||!n)return console.error("Invalid connection: Source or target node not found",e),!1;let l=O(o.type,e.sourceHandle,n.type,e.targetHandle);return l?(console.error("Invalid connection: ".concat(l)),!1):"subflow"!==o.type||!(_(o.id,r,e.target).length>0)||(console.error("Invalid connection: Subflow nodes can only have one outgoing connection"),!1)}function U(e,t,r){let o=t.find(t=>t.id===e.source),n=t.find(t=>t.id===e.target),l=e.sourceHandle,a=e.targetHandle,s=(null==o?void 0:o.type)==="mcp"||(null==n?void 0:n.type)==="mcp"||z(l)||z(a),i=!s&&((null==o?void 0:o.type)==="resource"||(null==n?void 0:n.type)==="resource"||W(l)||W(a)),d="".concat(e.source,":").concat(l,"->").concat(e.target,":").concat(a);return s?{id:d,...e,type:"mcpEdge",data:{edgeType:"mcp"},animated:!1,markerEnd:L.markerEnd,markerStart:L.markerStart,style:L.style}:i?{id:d,...e,type:"resourceEdge",data:{edgeType:"resource"},animated:!1,markerEnd:D.markerEnd,style:D.style}:{id:d,...e,type:"custom",data:{edgeType:"standard",...r?{condition:r}:{}},animated:!0}}function G(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=t.find(t=>t.id===e.source),n=t.find(t=>t.id===e.target);return!!o&&!!n&&("subflow"!==n.type||!(_(n.id,r,e.source).length>0))&&null===O(n.type,null,o.type,null)}function V(e,t){let r=e=>{var t;return null==(t=e.data)?void 0:t.edgeType},o=e=>"mcp"===r(e),n=e=>"resource"===r(e);return t.filter(t=>t.id===e.id||(o(e)?o(t)&&(t.source===e.source&&t.target===e.target||t.source===e.target&&t.target===e.source):n(e)?n(t)&&t.source===e.source&&t.target===e.target:!o(t)&&!n(t)&&t.source===e.source&&t.target===e.target)).map(e=>e.id)}function $(e){var t;return null==(t=e.data)?void 0:t.edgeType}function J(e){return"mcp"===$(e)}function K(e){return"resource"===$(e)}var Y=r(56682),X=r(33420),q=r(49501),Z=r(17681),Q=r(4484),ee=r(52277),et=r(78095),er=r(14915);let eo=e=>{let{open:t,position:r,onClose:n,onDelete:l,onEditProperties:a,onCopy:s,onPaste:i,canPaste:d,canCopy:c,nodeId:u,selection:p,edgeId:f}=e,h=[];return u&&!p&&h.push((0,o.jsxs)(T.A,{onClick:()=>{a&&a(),n()},children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(er.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{children:"Edit Properties"})]},"edit")),s&&(u||p)&&h.push((0,o.jsxs)(T.A,{onClick:()=>{s&&s(),n()},disabled:!c,children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(ee.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{children:"Copy"})]},"copy")),i&&h.push((0,o.jsxs)(T.A,{onClick:()=>{i&&i(),n()},disabled:!d,children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(et.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{children:"Paste"})]},"paste")),(u||f||p)&&h.push((0,o.jsx)(N.A,{},"delete-divider"),(0,o.jsxs)(T.A,{onClick:()=>{l(),n()},sx:{color:"error.main"},children:[(0,o.jsx)(q.A,{sx:{color:"error.main"},children:(0,o.jsx)(Q.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{children:"Delete"})]},"delete")),(0,o.jsx)(k.A,{open:t,onClose:n,anchorReference:"anchorPosition",anchorPosition:null!==r.y&&null!==r.x?{top:r.y,left:r.x}:void 0,children:h})};var en=r(53911),el=r(71738);function ea(e,t){return t.find(t=>t.id===e)}let es=(0,I.h)("components/flow/FlowBuilder/Canvas/hooks/useCanvasEvents.ts");var ei=r(39047),ed=r(81464),ec=r(12142);let eu=(0,A.Ay)(i.A)(e=>{let{theme:t}=e;return{minWidth:"36px",padding:"6px",margin:"0 4px",backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.05)":"rgba(0, 0, 0, 0.02)","&:hover":{backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)"}}}),ep=()=>{let{zoomIn:e,zoomOut:t,fitView:r}=(0,M.VH)();return(0,o.jsx)(M.Zk,{position:"top-right",style:{margin:"10px"},children:(0,o.jsxs)("div",{style:{display:"flex",gap:"5px"},children:[(0,o.jsx)(u.A,{title:"Zoom In",children:(0,o.jsx)(eu,{variant:"outlined",size:"small",onClick:()=>e(),children:(0,o.jsx)(ei.A,{fontSize:"small"})})}),(0,o.jsx)(u.A,{title:"Zoom Out",children:(0,o.jsx)(eu,{variant:"outlined",size:"small",onClick:()=>t(),children:(0,o.jsx)(ed.A,{fontSize:"small"})})}),(0,o.jsx)(u.A,{title:"Fit View",children:(0,o.jsx)(eu,{variant:"outlined",size:"small",onClick:()=>r(),children:(0,o.jsx)(ec.A,{fontSize:"small"})})})]})})},ef=e=>{let{showMiniMap:t=!0,showControls:r=!0,showBackground:n=!0}=e,a=(0,l.A)(),s="dark"===a.palette.mode;return(0,o.jsxs)(o.Fragment,{children:[n&&(0,o.jsx)(M.VS,{color:s?a.palette.text.disabled:a.palette.divider,gap:20,size:1}),r&&(0,o.jsx)(M.H2,{}),t&&(0,o.jsx)(M.of,{nodeColor:s?a.palette.primary.dark:a.palette.primary.light,maskColor:s?"rgba(0, 0, 0, 0.4)":"rgba(255, 255, 255, 0.6)"})]})},eh=(0,I.h)("components/flow/FlowBuilder/Canvas/Canvas.tsx"),em="flujo:flowClipboard",eg=null;function ex(e){eg=e;try{localStorage.setItem(em,JSON.stringify(e))}catch(e){eh.warn("Could not persist flow clipboard to localStorage",e)}}let ev={start:X.vm,process:X.Uw,finish:X.IK,mcp:X.v2,subflow:X.lA,resource:X.z9,signal:X.z3},eb={custom:en.jY,mcpEdge:en.oY,resourceEdge:en.sZ},ey=e=>{let{open:t,position:r,onClose:n,onSelectNodeType:i,sourceNodeType:d,sourceHandleId:c}=e,u=(0,l.A)(),p=function(e,t){let r=["process","finish","mcp","subflow","resource","signal"];return e&&t?r.filter(r=>null===O(e,t,r,B(r,t))):r}(d,c);eh.debug("NodeSelectionModal: Source node type: ".concat(d,", Source handle ID: ").concat(c)),eh.debug("NodeSelectionModal: Valid node types: ".concat(p.join(", ")));let f=[{type:"process",label:"Process Node",description:"Let a LLM do your work"},{type:"finish",label:"Finish Node",description:"End your flow here"},{type:"mcp",label:"MCP Node",description:"Add functionality"},{type:"subflow",label:"Subflow Node",description:"Run another flow"},{type:"resource",label:"Resource Node",description:"A data artifact steps read or write"},{type:"signal",label:"Signal Node",description:"Emit an event to trigger another flow"}].filter(e=>p.includes(e.type));return r?(0,o.jsx)(Y.A,{open:t,onClose:n,"aria-labelledby":"node-selection-modal",children:(0,o.jsxs)(a.default,{sx:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:300,bgcolor:"background.paper",borderRadius:2,boxShadow:24,p:4},children:[(0,o.jsx)(s.default,{variant:"h6",component:"h2",gutterBottom:!0,children:"Select Node Type"}),(0,o.jsx)(a.default,{display:"flex",flexDirection:"column",gap:2,children:f.map(e=>(0,o.jsxs)(a.default,{sx:{padding:2,borderRadius:1,border:"2px solid ".concat("process"===e.type?u.palette.secondary.main:"finish"===e.type?u.palette.success.main:"subflow"===e.type?u.palette.warning.main:"resource"===e.type?X.nH:u.palette.info.main),cursor:"pointer","&:hover":{boxShadow:3}},onClick:()=>i(e.type,r),children:[(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",gap:1,mb:1,children:[(e=>{switch(e){case"process":default:return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:u.palette.secondary.main,borderRadius:"50%"}});case"finish":return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:u.palette.success.main,borderRadius:"50%"}});case"mcp":return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:u.palette.info.main,borderRadius:"50%"}});case"subflow":return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:u.palette.warning.main,borderRadius:"50%"}});case"resource":return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:X.nH,borderRadius:"50%"}});case"signal":return(0,o.jsx)("div",{style:{width:24,height:24,backgroundColor:X.vp,borderRadius:"50%"}})}})(e.type),(0,o.jsx)(s.default,{variant:"subtitle1",fontWeight:"bold",children:e.label})]}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",children:e.description})]},e.type))})]})}):null},ew=(0,A.Ay)("div")(e=>{let{theme:t}=e;return{width:"100%",height:"80vh",border:"1px solid ".concat(t.palette.divider),borderRadius:"4px",background:t.palette.background.paper,position:"relative"}}),ej=(0,n.forwardRef)((e,t)=>{let r=(0,l.A)(),{nodes:a,edges:s,onNodesChange:i,onEdgesChange:d,onDrop:c,onDragOver:u,onInit:p,reactFlowWrapper:f,onEditNode:h}=e,{contextMenu:m,selectedElements:g,closeContextMenu:x,handleDelete:v,onNodeContextMenu:b,onEdgeContextMenu:y,onPaneContextMenu:w,onSelectionContextMenu:j}=function(e){let{deleteElements:t}=(0,M.VH)(),[r,o]=(0,n.useState)({open:!1,position:{x:0,y:0}}),[l,a]=(0,n.useState)({nodes:[],edges:[]});(0,M.p4)({onChange:e=>{let{nodes:t,edges:r}=e,o=t.map(e=>e.id),n=r.map(e=>e.id);es.debug("Selection changed: ".concat(o.length," nodes, ").concat(n.length," edges selected")),a({nodes:o,edges:n})}});let s=(0,n.useCallback)((e,t,r,n)=>{e.preventDefault(),t?es.debug("Context menu opened for node: ".concat(t)):r?es.debug("Context menu opened for edge: ".concat(r)):n?es.debug("Context menu opened for the current selection"):es.debug("Context menu opened on canvas at (".concat(e.clientX,", ").concat(e.clientY,")")),o({open:!0,position:{x:e.clientX,y:e.clientY},nodeId:t,edgeId:r,selection:n})},[]),i=(0,n.useCallback)(()=>{es.debug("Context menu closed"),o(e=>({...e,open:!1}))},[]),d=(0,n.useCallback)(()=>{if(r.selection)es.debug("handleDelete: Deleting the current selection"),t({nodes:l.nodes.map(e=>({id:e})),edges:l.edges.map(e=>({id:e}))});else if(r.nodeId){if(es.debug("handleDelete: Attempting to delete node ".concat(r.nodeId)),!function(e,t){let r=ea(e,t);return!!r&&"start"!==r.type}(r.nodeId,e)){es.warn("Cannot delete Start node: ".concat(r.nodeId)),alert("Start nodes cannot be deleted");return}t({nodes:[{id:r.nodeId}]})}else r.edgeId&&(es.debug("handleDelete: Deleting edge ".concat(r.edgeId)),t({edges:[{id:r.edgeId}]}))},[r,t,e,l]),c=(0,n.useCallback)((e,t)=>{s(e,t.id)},[s]),u=(0,n.useCallback)((e,t)=>{s(e,void 0,t.id)},[s]),p=(0,n.useCallback)(e=>{s(e)},[s]),f=(0,n.useCallback)(e=>{s(e,void 0,void 0,!0)},[s]);return{contextMenu:r,selectedElements:l,onContextMenu:s,closeContextMenu:i,handleDelete:d,onNodeContextMenu:c,onEdgeContextMenu:u,onPaneContextMenu:p,onSelectionContextMenu:f}}(a),{deleteElements:A}=(0,M.VH)(),C=(0,M.PI)(),S=(0,n.useRef)(null),[k,T]=(0,n.useState)(null),[N,I]=(0,n.useState)({open:!1,position:null}),E=(0,n.useCallback)(e=>[...a.filter(e=>e.selected).map(e=>({type:"select",id:e.id,selected:!1})),{type:"add",item:{...e,selected:!0}}],[a]);(0,n.useEffect)(()=>{if(!h)return;let e=e=>{if(e.detail&&e.detail.nodeId){let t=ea(e.detail.nodeId,a);t&&h(t)}};return document.addEventListener("editNode",e),()=>{document.removeEventListener("editNode",e)}},[a,h]);let D=(0,n.useCallback)(e=>{var t,o;if(!e.sourceHandle||!e.targetHandle)return void eh.error("Invalid connection: Missing source or target handle",e);let n=(null==(t=C.getState().connection.fromHandle)?void 0:t.type)==="target";if(!H(e,a,s))return;let l=U(e,a);if((null==(o=l.data)?void 0:o.edgeType)==="standard"){let t=e=>{var t;return(null==(t=e.data)?void 0:t.edgeType)!=="mcp"},o=e=>{var t;return!!(null==(t=e.data)?void 0:t.bidirectional)},l=s.find(r=>t(r)&&r.source===e.source&&r.target===e.target),i=s.find(r=>t(r)&&r.source===e.target&&r.target===e.source),c=e=>{eh.info("Merging reverse connection into bidirectional edge ".concat(e.id)),d([{type:"replace",id:e.id,item:{...e,data:{...e.data,bidirectional:!0},markerStart:{type:R.TG.ArrowClosed,width:20,height:20,color:r.palette.text.secondary}}}])};if(n){let e=null!=l?l:i;return e?void(!o(e)&&G(e,a,s)&&c(e)):void eh.info("Connection drawn from a top handle is only allowed to convert an existing edge to bidirectional")}if(l&&o(l))return;if(i){!o(i)&&G(i,a,s)&&c(i);return}}d([...V(l,s).map(e=>({type:"remove",id:e})),{type:"add",item:l}])},[a,s,d,C,r.palette.text.secondary]);(0,n.useEffect)(()=>{let e=e=>{var t;let{edgeId:r,waypoints:o}=e.detail,n=s.find(e=>e.id===r);if(!n)return;let{waypoint:l,...a}=null!=(t=n.data)?t:{};d([{type:"replace",id:r,item:{...n,data:{...a,waypoints:null!=o?o:void 0}}}])};return document.addEventListener(el.R,e),()=>document.removeEventListener(el.R,e)},[s,d]);let L=(0,n.useCallback)(async e=>{let{nodes:t,edges:r}=e,o=t.filter(e=>"start"!==e.type),n=new Set(o.map(e=>e.id)),l=new Set(t.map(e=>e.id)),a=r.filter(e=>!!(e.selected||n.has(e.source)||n.has(e.target))||!(l.has(e.source)||l.has(e.target)));return(0!==o.length||0!==a.length)&&{nodes:o,edges:a}},[]),W=(0,n.useCallback)(e=>{T(e),p&&p(e)},[p]);(0,n.useEffect)(()=>{let e=e=>{if(!e.detail||!k)return;let{nodeType:t,position:r}=e.detail,o=F.g.createNode(t,r);i(E(o)),h&&h(o)};return document.addEventListener("addNodeFromPalette",e),()=>{document.removeEventListener("addNodeFromPalette",e)}},[k,i,E,h]);let O=(0,n.useCallback)(()=>{if(m.nodeId&&h){let e=ea(m.nodeId,a);e&&h(e)}},[m.nodeId,a,h]),_=(0,n.useCallback)((e,t)=>{e.preventDefault(),h&&h(t)},[h]),$=(0,n.useCallback)((e,t)=>{var r,o;let{fromNode:n,fromHandle:l,toHandle:a}=t;if(!n||!(null==l?void 0:l.id)||!k)return void eh.debug("onConnectEnd: No valid connection start data");eh.debug("onConnectEnd: Connection ended from node ".concat(n.id,", handle ").concat(l.id));let i="subflow"===n.type&&s.some(e=>{let t=e.data;return(null==t?void 0:t.edgeType)!=="mcp"&&(null==t?void 0:t.edgeType)!=="resource"&&(e.source===n.id||e.target===n.id&&!!(null==t?void 0:t.bidirectional))}),d=!!(null==(o=e.target)||null==(r=o.closest)?void 0:r.call(o,".react-flow__pane"));if(!function(e){let{fromNodeType:t,fromHandleType:r,fromHandleId:o,landedOnHandle:n,droppedOnPane:l,subflowHasOutgoing:a}=e;return!n&&!!l&&!!o&&("target"!==r||!!z(o))&&("subflow"!==t||"source"!==r||!a)}({fromNodeType:n.type,fromHandleType:l.type,fromHandleId:l.id,landedOnHandle:!!a,droppedOnPane:d,subflowHasOutgoing:i}))return;let c=e instanceof MouseEvent?e:e.changedTouches[0],u=k.screenToFlowPosition({x:c.clientX,y:c.clientY});eh.debug("onConnectEnd: Connection dropped on pane at position (".concat(u.x,", ").concat(u.y,")")),I({open:!0,position:u,sourceNodeId:n.id,sourceNodeType:n.type,sourceHandleId:l.id})},[k,s]),J=(0,n.useCallback)((e,t)=>{eh.debug("handleNodeTypeSelection: Selected node type ".concat(e," at position (").concat(t.x,", ").concat(t.y,")"));let r=F.g.createNode(e,t);i(E(r));let{sourceNodeId:o,sourceHandleId:n}=N,l=o?ea(o,a):void 0;if(l&&n){let t=B(e,n),o={source:l.id,sourceHandle:n,target:r.id,targetHandle:t};if(eh.debug("handleNodeTypeSelection: Creating connection from ".concat(o.source," to ").concat(o.target)),H(o,[...a,r],s)){let e=U(o,[...a,r]);d([...V(e,s).map(e=>({type:"remove",id:e})),{type:"add",item:e}]),eh.debug("handleNodeTypeSelection: Edge created with id ".concat(e.id))}}I({open:!1,position:null}),h&&h(r)},[N,a,s,E,i,d,h]),K=(0,n.useCallback)(()=>{eh.debug("handleCloseNodeSelectionModal: Closing node selection modal"),I({open:!1,position:null})},[]),Y=(0,n.useCallback)(()=>{let e=new Set(g.nodes),t=a.filter(t=>e.has(t.id)&&"start"!==t.type);if(0===t.length)return!1;let r=new Set(t.map(e=>e.id)),o=s.filter(e=>r.has(e.source)&&r.has(e.target));return ex({nodes:JSON.parse(JSON.stringify(t)),edges:JSON.parse(JSON.stringify(o))}),eh.debug("Copied ".concat(t.length," node(s) and ").concat(o.length," edge(s)")),!0},[g,a,s]),X=(0,n.useCallback)(()=>{let e=eg;if(!e)try{let t=localStorage.getItem(em);t&&(e=JSON.parse(t))}catch(e){eh.warn("Could not read flow clipboard from localStorage",e)}if(!e||!e.nodes||0===e.nodes.length)return void eh.debug("Paste requested but clipboard is empty");let t=new Map;e.nodes.forEach(e=>t.set(e.id,(0,P.A)()));let r=e.nodes.map(e=>{var r,o,n,l;return{...e,id:t.get(e.id),position:{x:(null!=(n=null==(r=e.position)?void 0:r.x)?n:0)+40,y:(null!=(l=null==(o=e.position)?void 0:o.y)?l:0)+40},selected:!0,data:{...e.data}}}),o=(e.edges||[]).filter(e=>t.has(e.source)&&t.has(e.target)).map(e=>({...e,id:(0,P.A)(),source:t.get(e.source),target:t.get(e.target),selected:!1}));i([...a.filter(e=>e.selected).map(e=>({type:"select",id:e.id,selected:!1})),...r.map(e=>({type:"add",item:e}))]),o.length>0&&d(o.map(e=>({type:"add",item:e}))),eh.info("Pasted ".concat(r.length," node(s) and ").concat(o.length," edge(s)"))},[a,i,d]),q=(0,n.useCallback)(e=>{let t=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();if(t&&"c"===r){Y()&&e.preventDefault();return}if(t&&"x"===r){Y()&&(e.preventDefault(),A({nodes:g.nodes.map(e=>({id:e})),edges:g.edges.map(e=>({id:e}))}));return}if(t&&"v"===r){e.preventDefault(),X();return}},[Y,X,A,g]),Z=(0,n.useCallback)(()=>{if(m.nodeId&&!g.nodes.includes(m.nodeId)){let e=a.find(e=>e.id===m.nodeId);e&&"start"!==e.type&&(ex({nodes:JSON.parse(JSON.stringify([e])),edges:[]}),eh.debug("Copied right-clicked node to clipboard"));return}Y()},[m.nodeId,g,a,Y]),Q=(0,n.useMemo)(()=>{if(eg)return!0;try{return!!localStorage.getItem(em)}catch(e){return!1}},[m.open]),ee=(0,n.useMemo)(()=>{if(m.selection){let e=new Set(g.nodes);return a.some(t=>e.has(t.id)&&"start"!==t.type)}if(m.nodeId){let e=a.find(e=>e.id===m.nodeId);return!!e&&"start"!==e.type}return!1},[m.selection,m.nodeId,g,a]);return(0,o.jsxs)(ew,{ref:e=>{t&&("function"==typeof t?t(e):t.current=e),f&&(f.current=e),S.current=e},children:[(0,o.jsxs)(M.Gc,{nodes:a,edges:s,nodeTypes:ev,edgeTypes:eb,defaultEdgeOptions:(0,n.useMemo)(()=>({type:"custom",animated:!0,style:{stroke:r.palette.text.secondary,strokeWidth:2},markerEnd:{type:R.TG.ArrowClosed,width:20,height:20,color:r.palette.text.secondary}}),[r.palette.text.secondary]),connectionLineType:R.Do.SmoothStep,onNodesChange:i,onEdgesChange:d,onConnect:D,onBeforeDelete:L,deleteKeyCode:["Backspace","Delete"],onDrop:c,onDragOver:u,onInit:W,onNodeContextMenu:b,onEdgeContextMenu:y,onPaneContextMenu:w,onSelectionContextMenu:j,onKeyDown:q,onNodeDoubleClick:_,onConnectEnd:$,tabIndex:0,fitView:!0,attributionPosition:"bottom-right",minZoom:.1,maxZoom:2,snapToGrid:!0,snapGrid:[15,15],connectOnClick:!1,children:[(0,o.jsx)(ep,{}),(0,o.jsx)(ef,{})]}),(0,o.jsx)(eo,{open:m.open,position:m.position,onClose:x,onDelete:v,onEditProperties:O,onCopy:Z,onPaste:X,canPaste:Q,canCopy:ee,nodeId:m.nodeId,selection:m.selection,edgeId:m.edgeId}),(0,o.jsx)(ey,{open:N.open,position:N.position,onClose:K,onSelectNodeType:J,sourceNodeType:N.sourceNodeType,sourceHandleId:N.sourceHandleId})]})});ej.displayName="Canvas";var eA=r(56350),eC=r(77842),eS=r(55930),ek=r(59323),eT=r(20195);let eN=(0,I.h)("components/flow/FlowBuilder/NodePalette.tsx"),eI="NodePalette",eM=(0,A.Ay)(C.A)(e=>{let{theme:t}=e;return{padding:t.spacing(2),width:"200px",height:"80vh",display:"flex",flexDirection:"column",gap:t.spacing(2)}}),eP=(0,A.Ay)(C.A,{shouldForwardProp:e=>"nodeType"!==e})(e=>{let{theme:t,nodeType:r}=e;return{padding:t.spacing(1.5),minWidth:"180px",borderRadius:"8px",backgroundColor:t.palette.background.paper,border:"2px solid ".concat("process"===r?t.palette.secondary.main:"finish"===r?t.palette.success.main:"subflow"===r?t.palette.warning.main:"resource"===r?X.nH:"signal"===r?X.vp:t.palette.info.main),boxShadow:t.shadows[2],transition:"all 0.2s ease",cursor:"grab","&:hover":{boxShadow:"0 0 0 1px ".concat("process"===r?t.palette.secondary.main:"finish"===r?t.palette.success.main:"subflow"===r?t.palette.warning.main:"resource"===r?X.nH:"signal"===r?X.vp:t.palette.info.main,", 0 3px 10px rgba(0,0,0,0.1)")},"&:active":{cursor:"grabbing"}}}),eF=(0,A.Ay)(a.default,{shouldForwardProp:e=>"nodeType"!==e})(e=>{let{theme:t,nodeType:r}=e;return{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid ".concat("process"===r?t.palette.secondary.light:"finish"===r?t.palette.success.light:"subflow"===r?t.palette.warning.light:"resource"===r?"#4DB6AC":"signal"===r?"#B39DDB":t.palette.info.light),marginBottom:t.spacing(1),paddingBottom:t.spacing(.5)}}),eE=(0,A.Ay)(a.default)({display:"flex",alignItems:"center",gap:"8px"}),eR=[{type:"process",label:"Process Node",description:"Let a LLM do your work"},{type:"finish",label:"Finish Node",description:"End your flow here"},{type:"mcp",label:"MCP Node",description:"Add functionality"},{type:"subflow",label:"Subflow Node",description:"Run another flow as a step"},{type:"resource",label:"Resource Node",description:"A data artifact steps read or write"},{type:"signal",label:"Signal Node",description:"Emit an event to trigger another flow"}],eD=()=>{eN.debug("".concat(eI,": Entering component")),(0,l.A)();let e=(0,n.useCallback)(e=>{eN.debug("".concat(eI,".onNodeDoubleClick: Double-clicked on ").concat(e," node"));let t=new CustomEvent("addNodeFromPalette",{detail:{nodeType:e,position:{x:250,y:150}}});document.dispatchEvent(t),eN.info("".concat(eI,".onNodeDoubleClick: Dispatched addNodeFromPalette event for ").concat(e," node"))},[]);return eN.debug("".concat(eI,": Rendering component")),(0,o.jsxs)(eM,{elevation:2,children:[(0,o.jsx)(s.default,{variant:"h6",gutterBottom:!0,children:"Node Types"}),(0,o.jsx)(a.default,{display:"flex",flexDirection:"column",gap:2,children:eR.map(t=>(0,o.jsxs)(eP,{nodeType:t.type,elevation:1,draggable:!0,onDragStart:e=>((e,t)=>{eN.debug("".concat(eI,".onDragStart: Entering method with nodeType=").concat(t)),e.dataTransfer.setData("application/reactflow",t),e.dataTransfer.effectAllowed="move";let r=document.createElement("div");r.innerHTML='<div style="padding: 10px; background: white; border: 1px solid #ccc; border-radius: 4px;">'.concat(t," Node</div>"),document.body.appendChild(r),eN.debug("".concat(eI,".onDragStart: Created drag preview element"));try{e.dataTransfer.setDragImage(r,75,25),eN.debug("".concat(eI,".onDragStart: Set drag image with offset (75, 25)"))}catch(e){eN.error("".concat(eI,".onDragStart: Error setting drag image:"),e)}setTimeout(()=>{document.body.removeChild(r),eN.debug("".concat(eI,".onDragStart: Removed drag preview element"))},0),eN.debug("".concat(eI,".onDragStart: Drag operation initialized"))})(e,t.type),onDragEnd:e=>{var r;return r=t.type,void eN.debug("".concat(eI,".onDragEnd: Drag operation ended for nodeType=").concat(r))},onDoubleClick:()=>e(t.type),children:[(0,o.jsx)(eF,{nodeType:t.type,children:(0,o.jsxs)(eE,{children:[(e=>{switch(e){case"process":default:return(0,o.jsx)(eA.A,{color:"secondary"});case"finish":return(0,o.jsx)(eC.A,{color:"success"});case"mcp":return(0,o.jsx)(eA.A,{color:"info"});case"subflow":return(0,o.jsx)(eS.A,{color:"warning"});case"resource":return(0,o.jsx)(ek.A,{sx:{color:X.nH}});case"signal":return(0,o.jsx)(eT.A,{sx:{color:X.vp}})}})(t.type),(0,o.jsx)(s.default,{variant:"subtitle2",fontWeight:"bold",children:t.label})]})}),(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",children:t.description})]},t.type))})]})};var eL=r(28548),ez=r(4474),eW=r(41602),eO=r(73707),eB=r(23820),e_=r(5155),eH=r(60691),eU=r(76808),eG=r(36741),eV=r(61033);let e$=["contains","regex","equals","always"],eJ=/\$\{var:([^}]+)\}/g,eK=/^[A-Za-z_][\w-]*$/;function eY(e){return"string"==typeof e&&eK.test(e)}let eX=/\$\{kv:([^}]+)\}/g,eq=["global","flow","folder"];function eZ(e){let t=(null!=e?e:"").trim(),r=t.indexOf("/");if(r>0){let e=t.slice(0,r);if(eq.includes(e))return{scope:e,key:t.slice(r+1).trim()}}return{scope:"folder",key:t}}let eQ=/^[A-Za-z_][\w-]*$/;function e0(e){return"string"==typeof e&&eQ.test(e)}function e1(e){var t,r,o;return null!=(o=null!=(r=null==(t=e.data)?void 0:t.type)?r:e.type)?o:"unknown"}function e2(e){var t;return(null==(t=e.data)?void 0:t.label)||e.id}function e5(e){var t;return(null==(t=e.data)?void 0:t.edgeType)==="mcp"}function e4(e){var t;return(null==(t=e.data)?void 0:t.edgeType)==="resource"}function e6(e){return e5(e)||e4(e)}function e3(e){var t,r,o,n,l,a,s,i,d,c,u,p,f,h,m,g,x,v,b,y,w,j,A,C,S;let k=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},T=[],N=Array.isArray(null==e?void 0:e.nodes)?e.nodes:[],I=Array.isArray(null==e?void 0:e.edges)?e.edges:[],M=(e,t,r,o)=>T.push({severity:e,code:t,message:r,nodeId:null==o?void 0:o.id,nodeLabel:o?e2(o):void 0}),P=new Map((null!=(t=k.models)?t:[]).map(e=>[e.id,e])),F=new Map((null!=(r=k.servers)?r:[]).map(e=>[e.name,e])),E=!!k.models,R=!!k.servers,D=N.filter(e=>"start"===e1(e)),L=N.filter(e=>"finish"===e1(e)),z=N.filter(e=>"process"===e1(e)),W=N.filter(e=>"mcp"===e1(e));if(0===D.length)M("error","no-start-node","The flow has no Start node, so it has no entry point.");else if(D.length>1)for(let e of D.slice(1))M("error","multiple-start-nodes","The flow has more than one Start node; only one is allowed.",e);for(let e of(0===L.length&&M("warning","no-finish-node","The flow has no Finish node; it will run but never reaches a defined end."),z)){let t=null!=(n=null==(o=e.data)?void 0:o.properties)?n:{},r=t.boundModel;if(r){if(E&&!P.has(r)){let r="string"==typeof t.modelName&&t.modelName?' (was "'.concat(t.modelName,'")'):"";M("error","process-model-missing",'Process node "'.concat(e2(e),'" is bound to a model that no longer exists').concat(r,"."),e)}}else M("error","process-missing-model",'Process node "'.concat(e2(e),'" has no model bound.'),e)}for(let e of W){let t=(null!=(a=null==(l=e.data)?void 0:l.properties)?a:{}).boundServer;if(t){if(R&&!F.has(t))M("warning","mcp-server-missing",'MCP node "'.concat(e2(e),'" is bound to server "').concat(t,"\", which isn't in your current MCP server list. It may be offline (e.g. not connected), renamed, or removed — if it was renamed or removed, rebind this node."),e);else if(R){let r=F.get(t);if(r.status&&"connected"!==r.status){let o="disabled"===r.status?"disabled":"not connected (".concat(r.status,")");M("warning","mcp-server-disconnected",'MCP node "'.concat(e2(e),'" is bound to server "').concat(t,'", which is currently ').concat(o,". It will provide tools again once it reconnects."),e)}}}else M("warning","mcp-missing-server",'MCP node "'.concat(e2(e),'" is not bound to a server.'),e);I.some(t=>e5(t)&&(t.source===e.id||t.target===e.id))||M("warning","mcp-node-unconnected",'MCP node "'.concat(e2(e),'" is not connected to any Process node.'),e)}for(let e of N.filter(e=>"resource"===e1(e))){let t=null!=(i=null==(s=e.data)?void 0:s.properties)?i:{},r="run"===t.scope?"run":"mcp",o="string"==typeof t.boundServer?t.boundServer:"",n="string"==typeof t.uri?t.uri:"",l="string"==typeof t.runName?t.runName.trim():"";"mcp"!==r||o&&n||M("warning","resource-missing-binding",'Resource node "'.concat(e2(e),'" has no ').concat(o?"resource URI":"server"," bound; connected steps will receive nothing."),e),"run"!==r||l||M("warning","resource-missing-binding",'Resource node "'.concat(e2(e),'" is a run artifact with no name; give it a name so steps can produce/consume it.'),e),"run"===r&&l&&!eY(l)&&M("warning","resource-run-name",'Resource node "'.concat(e2(e),'" is named "').concat(l,'", which is not a valid artifact name (letters, digits, _ and - only, not starting with a digit); it will be awkward to reference with ${res:...}.'),e),"mcp"===r&&o&&R&&!F.has(o)&&M("warning","resource-server-missing",'Resource node "'.concat(e2(e),'" is bound to server "').concat(o,"\", which isn't in your current MCP server list."),e);let a=I.filter(t=>e4(t)&&(t.source===e.id||t.target===e.id));0===a.length&&M("warning","resource-node-unconnected",'Resource node "'.concat(e2(e),'" is not connected to any Process node.'),e);let d=a.filter(t=>t.target===e.id);"mcp"===r&&d.length>0&&M("error","resource-produce-static",'Resource node "'.concat(e2(e),'" is a static MCP resource, but a step writes INTO it. Only run artifacts (scope "run") can be produced by a step — flip the edge or make this a run artifact.'),e),"run"===r&&d.length>1&&M("warning","resource-multiple-producers",'Resource node "'.concat(e2(e),'" is produced by ').concat(d.length," steps; the last writer wins. Consider one producer per artifact."),e),"run"===r&&0===d.length&&a.length>0&&M("warning","resource-consumed-never-produced",'Resource node "'.concat(e2(e),'" is consumed but no step in this flow produces it; it resolves to nothing unless an earlier run captured it.'),e)}for(let e of N.filter(e=>"signal"===e1(e))){let t=null!=(c=null==(d=e.data)?void 0:d.properties)?c:{};("string"==typeof t.topic?t.topic.trim():"")||M("warning","signal-missing-topic",'Signal node "'.concat(e2(e),'" has no topic; it emits nothing. Give it a topic that a flow-event trigger can listen for.'),e)}if(D.length>0){let e=function(e){let t=new Map,r=(e,r)=>{t.has(e)||t.set(e,[]),t.get(e).push(r)};for(let t of e){var o;!e6(t)&&(r(t.source,t.target),(null==(o=t.data)?void 0:o.bidirectional)&&r(t.target,t.source))}return t}(I);for(let t of D)(null==(u=e.get(t.id))?void 0:u.length)||M("error","start-no-outgoing","The Start node is not connected to anything; the flow cannot run.",t);let t=function(e,t){let r=new Set(e),o=[...e];for(;o.length;){var n;let e=o.shift();for(let l of null!=(n=t.get(e))?n:[])r.has(l)||(r.add(l),o.push(l))}return r}(D.map(e=>e.id),e);for(let e of[...z,...L])t.has(e.id)||M("warning","unreachable-node","".concat("finish"===e1(e)?"Finish":"Process",' node "').concat(e2(e),'" is not reachable from the Start node.'),e)}for(let e of N.filter(e=>"subflow"===e1(e))){let t=I.filter(t=>{var r;return!e6(t)&&(t.source===e.id||t.target===e.id&&!!(null==(r=t.data)?void 0:r.bidirectional))});t.length>1&&M("error","subflow-multiple-outgoing",'Subflow node "'.concat(e2(e),'" has ').concat(t.length," outgoing connections; a subflow can only have one (either A > B > C or a bidirectional A <> B)."),e);let r=null!=(f=null==(p=e.data)?void 0:p.properties)?f:{},o="string"==typeof r.subflowId&&r.subflowId?r.subflowId:void 0,n=Array.isArray(r.parallelSubflowIds)?r.parallelSubflowIds.filter(e=>"string"==typeof e&&!!e):[];o&&n.length>0&&M("error","subflow-both-targets",'Subflow node "'.concat(e2(e),'" sets both a single "subflowId" and "parallelSubflowIds"; use one or the other.'),e);let l=!0===r.mapOverList;l&&n.length>0&&M("error","subflow-map-and-parallel",'Subflow node "'.concat(e2(e),'" combines "mapOverList" with "parallelSubflowIds"; map-over-list runs a single child once per item and cannot be combined with parallel fan-out.'),e),l&&!o&&0===n.length&&M("error","subflow-map-no-child",'Subflow node "'.concat(e2(e),'" has "mapOverList" but no child flow ("subflowId"); select a flow to run once per item.'),e);let a="string"==typeof r.parallelSubflowIdsVar?r.parallelSubflowIdsVar.trim():"";if(a&&(eY(a)||M("warning","subflow-parallel-var-name",'Subflow node "'.concat(e2(e),'" reads dynamic fan-out targets from "').concat(a,'", which is not a valid variable name (letters, digits, _ and - only, not starting with a digit); it will be awkward to capture with ${var:...}.'),e),l&&M("error","subflow-map-and-parallel-var",'Subflow node "'.concat(e2(e),'" combines "mapOverList" with dynamic fan-out ("parallelSubflowIdsVar"); map-over-list runs a single child once per item and cannot be combined with fan-out.'),e),N.some(e=>{var t,r;let o=null==(r=e.data)||null==(t=r.properties)?void 0:t.captureVariable;return"string"==typeof o&&o.trim()===a})||M("warning","subflow-parallel-var-uncaptured",'Subflow node "'.concat(e2(e),'" reads dynamic fan-out targets from variable "').concat(a,'", but no node captures it (captureVariable). It may be seeded by the caller; otherwise it resolves to no targets and the node falls back to its static parallel list.'),e)),!0===r.allowCallerFanout&&l&&M("error","subflow-map-and-caller-fanout",'Subflow node "'.concat(e2(e),'" combines "mapOverList" with agentic fan-out ("allowCallerFanout"); map-over-list runs a single child once per item and cannot be combined with fan-out.'),e),n.length>0){let t=r.concurrencyLimit;"number"==typeof t&&t<1&&M("warning","subflow-concurrency-limit",'Subflow node "'.concat(e2(e),'" has a concurrencyLimit of ').concat(t,"; it must be at least 1 (the runtime default will be used)."),e)}}{let e=new Map(N.map(e=>[e.id,e])),t=new Set;for(let r of I){if(e6(r))continue;let o=null==(h=r.data)?void 0:h.condition;if(!o||"object"!=typeof o)continue;let n=e.get(r.source),l=n?e1(n):"unknown";if("process"!==l){M("error","edge-condition-non-process","An edge leaving ".concat("unknown"===l?"an unknown":"the ".concat(l),' node "').concat(n?e2(n):r.source,'" has a routing condition, but only process nodes can route on a condition.'),null!=n?n:void 0);continue}(t.add(r.source),"string"==typeof(S=o.kind)&&e$.includes(S))?"always"===o.kind||("string"!=typeof o.value||0===o.value.length?M("warning","edge-condition-value",'Process node "'.concat(e2(n),'" has an outgoing edge condition with no "value"; it will never match.'),n):"regex"===o.kind&&!function(e){try{return new RegExp(e),!0}catch(e){return!1}}(o.value)&&M("warning","edge-condition-regex",'Process node "'.concat(e2(n),'" has an outgoing edge with a regex condition that does not compile; it will never match.'),n)):M("warning","edge-condition-kind",'Process node "'.concat(e2(n),'" has an outgoing edge whose condition kind "').concat(String(o.kind),'" is unknown; it will never match.'),n)}for(let r of t){let t=e.get(r);t&&(I.some(e=>{var t,o;return!e6(e)&&(e.source===r?!(null==(o=e.data)?void 0:o.condition)||"always"===e.data.condition.kind&&!e.data.condition.negate:e.target===r&&null!=(t=e.data)&&!!t.bidirectional)})||M("warning","edge-condition-no-fallback",'Process node "'.concat(e2(t),'" has conditioned outgoing edges but no bare fallback edge; if no condition matches, the flow ends here.'),t))}}{let e=new Set;for(let t of N){let r=null==(g=t.data)||null==(m=g.properties)?void 0:m.captureVariable;if("string"==typeof r&&r.trim()){let o=r.trim();e.add(o),eY(o)||M("warning","capture-var-name","".concat("subflow"===e1(t)?"Subflow":"Process",' node "').concat(e2(t),'" captures into "').concat(o,'", which is not a valid variable name (letters, digits, _ and - only, not starting with a digit); it will be awkward to reference with ${var:...}.'),t)}}let t=["promptTemplate","isolatedPrompt"],r=new Set;for(let o of N){let n=null!=(v=null==(x=o.data)?void 0:x.properties)?v:{};for(let l of t){let t=n[l];if("string"==typeof t&&t)for(let n of function(e){let t;if("string"!=typeof e||0===e.length)return[];let r=new Set;for(eJ.lastIndex=0;null!==(t=eJ.exec(e));){let e=t[1].trim();e&&r.add(e)}return[...r]}(t)){if(e.has(n))continue;let t="".concat(o.id,":").concat(n);r.has(t)||(r.add(t),M("warning","var-ref-uncaptured","".concat(e2(o)," references ${var:").concat(n,'} but no step in this flow captures "').concat(n,'" (via captureVariable). It resolves to empty unless supplied as a run input — check for a typo or a step ordered after this one.'),o))}}}}{for(let e of N){let t=null==(y=e.data)||null==(b=y.properties)?void 0:b.captureKv;if("string"==typeof t&&t.trim()){let{key:r}=eZ(t.trim());e0(r)||M("warning","capture-kv-name","".concat("subflow"===e1(e)?"Subflow":"Process",' node "').concat(e2(e),'" captures into kv "').concat(t.trim(),'", whose key is not a valid name (letters, digits, _ and - only, not starting with a digit); it will be awkward to reference with ${kv:...}.'),e)}}let e=["promptTemplate","isolatedPrompt"],t=new Set;for(let r of N){let o=null!=(j=null==(w=r.data)?void 0:w.properties)?j:{};for(let n of e){let e=o[n];if("string"==typeof e&&e)for(let o of function(e){let t;if("string"!=typeof e||0===e.length)return[];let r=new Set;for(eX.lastIndex=0;null!==(t=eX.exec(e));){let e=t[1].trim();e&&r.add(e)}return[...r]}(e)){let{key:e}=eZ(o);if(e0(e))continue;let n="".concat(r.id,":").concat(o);t.has(n)||(t.add(n),M("warning","kv-ref-name","".concat(e2(r)," references ${kv:").concat(o,"}, whose key is not a valid name (letters, digits, _ and - only, not starting with a digit); it resolves to empty."),r))}}}}for(let e of z){let t=null==(C=e.data)||null==(A=C.properties)?void 0:A.promptTemplate;if("string"!=typeof t||!t)continue;let r=function(e,t,r){let o=new Map(t.map(e=>[e.id,e])),n=new Set;for(let t of r){var l,a;if(!e5(t))continue;let r=null;if(t.source===e?r=t.target:t.target===e&&(r=t.source),!r)continue;let s=o.get(r);if(!s||"mcp"!==e1(s))continue;let i=null==(a=s.data)||null==(l=a.properties)?void 0:l.boundServer;"string"==typeof i&&i&&n.add(i)}return n}(e.id,N,I),o=new Set;for(let n of(0,eV.A$)(t)){if("handoff"===n.server)continue;let t="".concat(n.kind,":").concat(n.server,":").concat(n.name);!o.has(t)&&(o.add(t),r.has(n.server)?"tool"===n.kind&&k.serverTools&&k.serverTools[n.server]&&!k.serverTools[n.server].includes(n.name)&&M("warning","tool-unavailable",'Process node "'.concat(e2(e),'" references tool "').concat(n.name,'" which server "').concat(n.server,'" no longer provides.'),e):M("error","tool-pill-disconnected",'Process node "'.concat(e2(e),'" references ').concat(n.kind,' "').concat(n.name,'" from server "').concat(n.server,'", but it is not connected to that server (the MCP node was removed or the server was renamed).'),e))}}let O=T.filter(e=>"error"===e.severity).length,B=T.length-O;return{issues:T,errorCount:O,warningCount:B,isRunnable:0===O}}var e8=r(43076);let e7=(0,I.h)("components/flow/FlowBuilder/FlowValidationButton"),e9=e=>{var t,r;let{nodes:l,edges:d}=e,[c,u]=(0,n.useState)(!1),[p,f]=(0,n.useState)(!1),[x,v]=(0,n.useState)(null),y=(0,n.useCallback)(async()=>{f(!0);try{var e;let t=null!=(e=await e8.N.tryLoadModels())?e:void 0,r=await E.S.loadServerConfigs(),o=Array.isArray(r)?r.map(e=>({name:e.name,status:e.disabled?"disabled":void 0})):void 0,n=e3({nodes:l,edges:d},{models:t,servers:o});v(n.issues)}catch(e){e7.warn("Flow validation failed to run",e),v([])}finally{f(!1)}},[l,d]),w=(0,n.useCallback)(()=>{u(!0),v(null),y()},[y]),j=(0,n.useCallback)(e=>{e&&(u(!1),document.dispatchEvent(new CustomEvent("editNode",{detail:{nodeId:e}})))},[]),A=null!=(t=null==x?void 0:x.filter(e=>"error"===e.severity).length)?t:0,C=(null!=(r=null==x?void 0:x.length)?r:0)-A;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{variant:"outlined",color:"primary",onClick:w,startIcon:(0,o.jsx)(e_.A,{}),sx:{textTransform:"none"},children:"Check Flow"}),(0,o.jsxs)(h.A,{open:c,onClose:()=>u(!1),maxWidth:"sm",fullWidth:!0,children:[(0,o.jsxs)(m.A,{component:"div",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)("span",{children:"Flow Check"}),x&&(0,o.jsxs)(a.default,{sx:{display:"flex",gap:1,ml:1},children:[A>0&&(0,o.jsx)(eL.A,{size:"small",color:"error",label:"".concat(A," error").concat(1===A?"":"s")}),C>0&&(0,o.jsx)(eL.A,{size:"small",color:"warning",label:"".concat(C," warning").concat(1===C?"":"s")})]})]}),(0,o.jsx)(g.A,{dividers:!0,children:p?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:2,py:3,justifyContent:"center"},children:[(0,o.jsx)(ez.default,{size:22}),(0,o.jsx)(s.default,{color:"text.secondary",children:"Checking flow…"})]}):x&&0===x.length?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1.5,py:3,justifyContent:"center"},children:[(0,o.jsx)(eG.A,{color:"success"}),(0,o.jsx)(s.default,{children:"No problems found — this flow looks runnable."})]}):(0,o.jsx)(eW.A,{dense:!0,disablePadding:!0,children:(null!=x?x:[]).map((e,t)=>{var r;let n=!!e.nodeId,l=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(q.A,{sx:{minWidth:36},children:"error"===e.severity?(0,o.jsx)(eH.A,{color:"error",fontSize:"small"}):(0,o.jsx)(eU.A,{color:"warning",fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:e.message,secondary:n?"Node: ".concat(null!=(r=e.nodeLabel)?r:e.nodeId," — click to open"):void 0})]});return n?(0,o.jsx)(eO.A,{onClick:()=>j(e.nodeId),alignItems:"flex-start",children:l},t):(0,o.jsx)(eB.Ay,{alignItems:"flex-start",children:l},t)})})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:y,disabled:p,children:"Re-check"}),(0,o.jsx)(i.A,{onClick:()=>u(!1),variant:"contained",children:"Close"})]})]})]})};var te=r(33077),tt=r(57813),tr=r(26466),to=r(77073);function tn(e){let{currentLabel:t,nameIsCustom:r,defaultLabel:o,previousAutoLabel:n,nextAutoLabel:l}=e;return!0===r?t&&t.length>0?t:l:!t||0===t.length||t===o||void 0!==n&&n.length>0&&t===n?l:t}let tl=(0,I.h)("components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useModelManagement.ts");var ta=r(9898);let ts=(0,I.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useServerConnection");var ti=r(18466);function td(e,t){let r=e.replace(/\s+/g," ").trim();if(r.length<=t)return r;let o=r.slice(0,t),n=o.lastIndexOf(" ");return"".concat((n>.6*t?o.slice(0,n):o).trimEnd(),"…")}let tc=(0,I.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useHandoffTools"),tu=e=>{let{nodeData:t,setNodeData:r}=e;return t?(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%",pr:2},children:[(0,o.jsx)(s.default,{variant:"h6",gutterBottom:!0,children:"Node Configuration"}),(0,o.jsx)(v.A,{fullWidth:!0,label:"Node Label",value:t.label||"",onChange:e=>r(t=>({...t,label:e.target.value,properties:{...null==t?void 0:t.properties,nameIsCustom:!0}})),margin:"normal"}),(0,o.jsx)(v.A,{fullWidth:!0,label:"Description",value:t.description||"",onChange:e=>r({...t,description:e.target.value}),margin:"normal",multiline:!0,rows:2,helperText:"This description will be displayed on the node"})]}):null};var tp=r(18369),tf=r(12857),th=r(99162),tm=r(61267),tg=r(68503);let tx=e=>{let{isLoadingModels:t,loadError:r,models:n,selectedModelId:l,handleModelSelect:d,isModelBound:c,handleUnbindModel:u}=e,p=(0,tg.E)("models",n),f=e=>({key:e.id,content:(e=>(0,o.jsx)(tm.A,{model:e,selectable:!0,selected:l===e.id,onSelect:d}))(e)}),h=p.items.map(f),m=p.groups?p.groups.map(e=>({...e,items:e.items.map(f)})):null;return(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Bind to Model"}),(0,o.jsx)(a.default,{role:"radiogroup","aria-label":"Bind to model",children:(0,o.jsx)(th.A,{isLoading:t,error:r,loadingMessage:"Loading models...",emptyMessage:"No models available. Add some in the Model Manager.",searchable:!0,searchPlaceholder:"Search models…",searchTerm:p.searchTerm,onSearchChange:p.setSearchTerm,columns:{xs:12,sm:6},items:h,groups:m,collapsedKeys:p.collapsedKeys,onToggleGroup:p.toggleGroup})}),!t&&!r&&n.length>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(tp.A,{children:l?"This node will use the selected model for processing.":"Select a model to bind this node to."}),c&&(0,o.jsx)(a.default,{sx:{mt:2,display:"flex",justifyContent:"flex-end"},children:(0,o.jsx)(i.A,{startIcon:(0,o.jsx)(tf.A,{}),onClick:u,color:"primary",variant:"outlined",size:"small",children:"Unbind Model"})})]})]})};var tv=r(66177),tb=r(56422),ty=r(29767),tw=r(84578),tj=r(76530),tA=r(25541),tC=r(51611),tS=r(89218),tk=r(96362),tT=r(95906);let tN=(0,I.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerTools"),tI=e=>{var t,r,l;let{isLoadingServers:d,connectedMcpNodes:p,availableServers:f,onConnectMcpServer:h,serverToolsMap:m,serverStatuses:g,isLoadingTools:x,handleSelectToolServer:b,handleInsertToolBinding:y,selectedToolServerNodeId:j,selectedNodeId:A,isLoadingSelectedServerTools:S,promptBuilderRef:k,handleRetryServer:T,handleRestartServer:N}=e,I=null!=(l=null!=j?j:null==(t=p[0])?void 0:t.nodeId)?l:null,[M,P]=(0,n.useState)({}),[F,E]=(0,n.useState)(!1),R=(null!=f?f:[]).filter(e=>!p.some(t=>t.serverName===e.name)),D=!!h&&R.length>0,L=(0,tg.E)("mcp",R),z=e=>({key:e.name,content:(e=>(0,o.jsx)(tT.A,{name:e.name,status:e.status||"disconnected",path:e.rootPath||"",enabled:!e.disabled,transport:e.transport||"stdio",pickerMode:!0,onClick:()=>{var t;return t=e.name,void(E(!1),null==h||h(t))}}))(e)}),W=L.items.map(z),O=L.groups?L.groups.map(e=>({...e,items:e.items.map(z)})):null,B=(0,o.jsx)(tk.A,{open:F,onClose:()=>E(!1),title:"Connect an MCP server",description:"Pick a server to add to this flow and wire to this Process node.",emptyMessage:"No more servers to connect.",searchable:!0,searchPlaceholder:"Search servers…",searchTerm:L.searchTerm,onSearchChange:L.setSearchTerm,columns:{xs:12,sm:6},items:W,groups:O,collapsedKeys:L.collapsedKeys,onToggleGroup:L.toggleGroup}),[_,H]=(0,n.useState)(""),U=e=>{try{let t=p.find(t=>t.nodeId===e);if(!t)return tN.warn("Could not find connected MCP node with ID ".concat(e)),[];let r=t.enabledTools||[];return tN.debug("Enabled tools for node ".concat(e,": ").concat(JSON.stringify(r))),Array.isArray(r)?r:[]}catch(t){return tN.error("Error getting enabled tools for node ".concat(e,":"),t),[]}},G=(e,t,r)=>{try{if(!r||!Array.isArray(r))return tN.warn("Tools array is not available or not an array for server ".concat(t)),[];let o=U(e),n=r;if(o.length>0?n=r.filter(e=>e&&e.name&&o.includes(e.name)):(tN.debug("No tools explicitly enabled for node ".concat(e,", showing none.")),n=[]),_.trim()){let e=_.toLowerCase().trim();n=n.filter(t=>t.name&&t.name.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e)||t.inputSchema&&JSON.stringify(t.inputSchema).toLowerCase().includes(e))}return n}catch(o){return tN.error("Error filtering tools for node ".concat(e," (server ").concat(t,"):"),o),r||[]}},V=e=>{b(e)},$=async(e,t)=>{t.stopPropagation(),tN.debug("Retry button clicked for server: ".concat(e)),P(t=>({...t,[e]:!0}));try{T&&await T(e)}finally{setTimeout(()=>{P(t=>({...t,[e]:!1}))},500)}},J=async(e,t)=>{t.stopPropagation(),tN.debug("Restart button clicked for server: ".concat(e)),P(t=>({...t,[e]:!0}));try{N&&await N(e)}finally{setTimeout(()=>{P(t=>({...t,[e]:!1}))},500)}};(0,n.useEffect)(()=>{p.length>0&&!j&&b(p[0].nodeId)},[p,j,b]);let K=p.find(e=>e.nodeId===I),Y=null==K?void 0:K.serverName;return(0,o.jsxs)(a.default,{sx:{mt:4,display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Connected MCP Servers and Tools"}),d?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(ez.default,{size:20}),(0,o.jsx)(s.default,{color:"text.secondary",children:"Loading connected MCP nodes..."})]}):0===p.length?(0,o.jsxs)(a.default,{sx:{p:2,border:"1px dashed rgba(0, 0, 0, 0.12)",borderRadius:1},children:[(0,o.jsx)(s.default,{color:"text.secondary",align:"center",children:"No MCP nodes connected to this Process node."}),(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:D?"Pick a server below — the MCP node is added to the flow and wired up for you.":"Connect MCP nodes to this Process node using the side handles to access their tools."}),D&&(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,o.jsx)(i.A,{variant:"contained",size:"small",startIcon:(0,o.jsx)(w.A,{}),onClick:()=>E(!0),children:"Connect MCP Server"})}),B]}):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",flexGrow:1,height:"calc(100% - 40px)"},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",mb:2,borderBottom:1,borderColor:"divider"},children:[(0,o.jsx)(tt.A,{value:I||(null==(r=p[0])?void 0:r.nodeId)||"",onChange:(e,t)=>V(t),variant:"scrollable",scrollButtons:"auto",sx:{flexGrow:1},children:p.map(e=>{if(!e||!e.nodeId||!e.serverName)return tN.warn("Skipping invalid MCP node in tabs:",e),null;let t=e.serverName,r=e.nodeId,n=e.status;M[t],x[t];let l=m[t]||[],i=U(r);return G(r,t,l).length,(0,o.jsx)(tr.A,{value:r,label:(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(s.default,{variant:"body2",sx:{color:"connected"===n?"success.main":"error"===n?"error.main":"text.secondary"},children:t}),i.length>0&&(0,o.jsx)(tv.A,{badgeContent:i.length,color:"primary",sx:{ml:1}})]}),sx:{textTransform:"none",minHeight:"48px",opacity:"connected"!==n?.7:1}},r)})}),D&&(0,o.jsx)(u.A,{title:"Connect another MCP server",children:(0,o.jsx)(c.A,{size:"small",onClick:()=>E(!0),sx:{ml:1},children:(0,o.jsx)(w.A,{fontSize:"small"})})}),B]}),K&&Y&&(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"flex-end",mb:2},children:[(0,o.jsx)(u.A,{title:"Retry connection for ".concat(Y),children:(0,o.jsx)("span",{children:(0,o.jsx)(c.A,{size:"small",onClick:e=>$(Y,e),disabled:M[Y]||x[Y],children:M[Y]?(0,o.jsx)(ez.default,{size:16}):(0,o.jsx)(tj.A,{fontSize:"small"})})})}),"connected"===K.status&&N&&(0,o.jsx)(u.A,{title:"Restart server ".concat(Y),children:(0,o.jsx)("span",{children:(0,o.jsx)(c.A,{size:"small",onClick:e=>J(Y,e),disabled:M[Y],sx:{ml:1},children:(0,o.jsx)(tA.A,{fontSize:"small"})})})})]}),(0,o.jsx)(v.A,{placeholder:"Search enabled tools...",variant:"outlined",size:"small",fullWidth:!0,value:_,onChange:e=>H(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(tb.A,{position:"start",children:(0,o.jsx)(tC.A,{fontSize:"small"})})}}),(0,o.jsx)(C.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 140px)"},children:K&&Y&&(()=>{let e=K.nodeId,t=K.serverName;if("connected"!==K.status)return(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsxs)(s.default,{color:"text.secondary",children:["Server '",t,"' is not connected. Connect to view tools."]})},e);if(x[t])return(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,o.jsx)(ez.default,{size:24})},e);let r=m[t]||[],n=G(e,t,r);if(0===n.length){let t=U(e).length;return(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(s.default,{color:"text.secondary",children:_.trim()?'No enabled tools match "'.concat(_,'" for this node.'):0===t?"No tools are enabled for this node instance. Enable tools in the MCP Node properties.":"No tools available or enabled for this node instance."})},e)}return(0,o.jsx)(eW.A,{disablePadding:!0,children:n.map(r=>(0,o.jsxs)(ty.A,{variant:"outlined",onClick:()=>{e!==I?(tN.debug("Node tab not selected, selecting node first",{selectedNodeId:e,serverName:t,toolName:r.name}),V(e)):t&&r.name?(tN.debug("Inserting tool binding",{serverName:t,toolName:r.name}),y(t,r.name)):tN.warn("Cannot insert tool binding, server or tool name is undefined",{serverName:t,toolName:r.name})},sx:{mb:1,mx:1,mt:1,cursor:"pointer",position:"relative","&:hover":{boxShadow:1,bgcolor:"action.hover"}},children:[(0,o.jsx)(tw.A,{sx:{p:2,"&:last-child":{pb:2}},children:(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:(0,o.jsxs)(a.default,{sx:{width:"100%"},children:[(0,o.jsxs)(s.default,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(tS.A,{fontSize:"small",sx:{mr:1,color:"primary.main"}}),r.name]}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:r.description||"No description available"}),r.inputSchema&&(e=>e&&e.properties?(0,o.jsxs)(a.default,{sx:{mt:1},children:[(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",sx:{fontWeight:"medium"},children:"Parameters:"}),(0,o.jsx)(a.default,{sx:{pl:1,mt:.5},children:Object.entries(e.properties).map(t=>{var r;let[n,l]=t;return(0,o.jsxs)(a.default,{sx:{mb:.5},children:[(0,o.jsxs)(s.default,{variant:"caption",component:"span",sx:{fontWeight:"medium"},children:[n,(null==(r=e.required)?void 0:r.includes(n))&&(0,o.jsx)(s.default,{variant:"caption",component:"span",color:"error.main",children:" *"}),": "]}),(0,o.jsx)(s.default,{variant:"caption",component:"span",color:"text.secondary",children:l.description||l.type||"No description"})]},n)})})]}):null)(r.inputSchema)]})})}),(0,o.jsx)(u.A,{title:"Add ".concat(r.name," from ").concat(t," to prompt"),children:(0,o.jsx)(a.default,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0}})})]},r.name))},e)})()})]})]})},tM=(0,I.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerResources"),tP=e=>{let{primary:t,secondary:r,chip:n,onClick:l}=e;return(0,o.jsx)(ty.A,{variant:"outlined",onClick:l,sx:{mb:1,mx:1,mt:1,cursor:"pointer","&:hover":{boxShadow:1,bgcolor:"action.hover"}},children:(0,o.jsx)(tw.A,{sx:{p:2,"&:last-child":{pb:2}},children:(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[(0,o.jsxs)(a.default,{sx:{width:"100%"},children:[(0,o.jsxs)(s.default,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(ek.A,{fontSize:"small",sx:{mr:1,color:"primary.main"}}),t]}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mt:.5,wordBreak:"break-all"},children:r})]}),n&&(0,o.jsx)(eL.A,{size:"small",label:n,sx:{ml:1,flexShrink:0}})]})})})},tF=e=>{var t;let{connectedMcpNodes:r,handleInsertResourceBinding:l,promptBuilderRef:i}=e,[d,c]=(0,n.useState)(null),[u,p]=(0,n.useState)([]),[h,m]=(0,n.useState)([]),[g,x]=(0,n.useState)(!1),[b,y]=(0,n.useState)(),[w,j]=(0,n.useState)(""),A=r.find(e=>e.nodeId===d),S=null==A?void 0:A.serverName;(0,n.useEffect)(()=>{r.length>0&&!d&&c(r[0].nodeId)},[r,d]);let k=(0,n.useCallback)(async e=>{x(!0),y(void 0);try{let t=await E.S.listServerResources(e);p(t.resources||[]),m(t.resourceTemplates||[]),y(t.error)}catch(t){tM.warn("Failed to load resources for ".concat(e),t),y(t instanceof Error?t.message:"Failed to load resources")}finally{x(!1)}},[]);(0,n.useEffect)(()=>{S?k(S):(p([]),m([]))},[S,k]);let T=e=>e.toLowerCase().includes(w.toLowerCase().trim()),N=w.trim()?u.filter(e=>T(e.name||"")||T(e.uri)||T(e.description||"")):u,I=w.trim()?h.filter(e=>T(e.name||"")||T(e.uriTemplate)||T(e.description||"")):h,M=e=>{S&&e&&l(S,e)};return(0,o.jsxs)(a.default,{sx:{mt:4,display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Give this step access to…"}),(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",sx:{mb:1},children:"Pick a resource to insert. Its contents are read and placed into the prompt each time the step runs."}),0===r.length?(0,o.jsxs)(a.default,{sx:{p:2,border:"1px dashed rgba(0, 0, 0, 0.12)",borderRadius:1},children:[(0,o.jsx)(s.default,{color:"text.secondary",align:"center",children:"No MCP nodes connected to this Process node."}),(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:"Connect MCP nodes using the side handles to access their resources."})]}):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",flexGrow:1,height:"calc(100% - 40px)"},children:[(0,o.jsx)(tt.A,{value:d||(null==(t=r[0])?void 0:t.nodeId)||"",onChange:(e,t)=>c(t),variant:"scrollable",scrollButtons:"auto",sx:{mb:2,borderBottom:1,borderColor:"divider"},children:r.map(e=>(0,o.jsx)(tr.A,{value:e.nodeId,label:(0,o.jsx)(s.default,{variant:"body2",sx:{color:"connected"===e.status?"success.main":"error"===e.status?"error.main":"text.secondary"},children:e.serverName}),sx:{textTransform:"none",minHeight:48,opacity:"connected"!==e.status?.7:1}},e.nodeId))}),(0,o.jsx)(v.A,{placeholder:"Search resources…",variant:"outlined",size:"small",fullWidth:!0,value:w,onChange:e=>j(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(tb.A,{position:"start",children:(0,o.jsx)(tC.A,{fontSize:"small"})})}}),b&&(0,o.jsx)(f.A,{severity:"warning",sx:{mb:2},children:b}),(0,o.jsx)(C.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 140px)"},children:A&&"connected"!==A.status?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsxs)(s.default,{color:"text.secondary",children:["Server '",S,"' is not connected. Connect to view resources."]})}):g?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,o.jsx)(ez.default,{size:24})}):0===N.length&&0===I.length?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(s.default,{color:"text.secondary",children:w.trim()?'No resources match "'.concat(w,'".'):"This server does not publish any resources."})}):(0,o.jsxs)(eW.A,{disablePadding:!0,children:[N.map(e=>(0,o.jsx)(tP,{primary:e.name||e.uri,secondary:e.description||e.uri,chip:e.mimeType,tooltip:"Add ".concat(e.name||e.uri," to prompt"),onClick:()=>M(e.uri)},e.uri)),I.map(e=>(0,o.jsx)(tP,{primary:e.name||e.uriTemplate,secondary:e.description||e.uriTemplate,chip:"template",tooltip:"Add template ".concat(e.uriTemplate," to prompt (fill in variables, e.g. with ${global:VAR})"),onClick:()=>M(e.uriTemplate)},e.uriTemplate))]})})]})]})},tE=(0,I.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerTools/AgentTools"),tR=e=>{let{handoffTools:t,isLoadingHandoffTools:r,handleInsertToolBinding:l,promptBuilderRef:i}=e,[d,c]=(0,n.useState)(""),p=t.filter(e=>{if(!d.trim())return!0;let t=d.toLowerCase().trim();return e.name&&e.name.toLowerCase().includes(t)||e.description&&e.description.toLowerCase().includes(t)});return(0,o.jsxs)(a.default,{sx:{mt:4,display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Agent Handoff Tools"}),r?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(ez.default,{size:20}),(0,o.jsx)(s.default,{color:"text.secondary",children:"Loading handoff tools..."})]}):0===t.length?(0,o.jsxs)(a.default,{sx:{p:2,border:"1px dashed rgba(0, 0, 0, 0.12)",borderRadius:1},children:[(0,o.jsx)(s.default,{color:"text.secondary",align:"center",children:"No handoff tools available for this node."}),(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:"Connect this Process node to other nodes to enable handoff tools."})]}):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",flexGrow:1,height:"calc(100% - 40px)"},children:[(0,o.jsx)(v.A,{placeholder:"Search handoff tools...",variant:"outlined",size:"small",fullWidth:!0,value:d,onChange:e=>c(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(tb.A,{position:"start",children:(0,o.jsx)(tC.A,{fontSize:"small"})})}}),(0,o.jsx)(C.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 56px)"},children:0===p.length?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(s.default,{color:"text.secondary",children:d.trim()?'No handoff tools match "'.concat(d,'".'):"No handoff tools available."})}):(0,o.jsx)(eW.A,{disablePadding:!0,children:p.map(e=>(0,o.jsxs)(ty.A,{variant:"outlined",onClick:()=>{e.name?(tE.debug("Inserting handoff tool binding",{toolType:"handoff",toolName:e.name}),l("handoff",e.name)):tE.warn("Cannot insert handoff tool binding, tool name is undefined",{toolName:e.name})},sx:{mb:1,mx:1,mt:1,cursor:"pointer",position:"relative",bgcolor:"rgba(0, 0, 0, 0.04)","&:hover":{boxShadow:1,bgcolor:"rgba(0, 0, 0, 0.08)"}},children:[(0,o.jsx)(tw.A,{sx:{p:2,"&:last-child":{pb:2}},children:(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:(0,o.jsxs)(a.default,{sx:{width:"100%"},children:[(0,o.jsxs)(s.default,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(tS.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),e.name]}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:e.description||"No description available"}),e.inputSchema&&(e=>e&&e.properties&&0!==Object.keys(e.properties).length?(0,o.jsxs)(a.default,{sx:{mt:1},children:[(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",sx:{fontWeight:"medium"},children:"Parameters:"}),(0,o.jsx)(a.default,{sx:{pl:1,mt:.5},children:Object.entries(e.properties).map(t=>{var r;let[n,l]=t;return(0,o.jsxs)(a.default,{sx:{mb:.5},children:[(0,o.jsxs)(s.default,{variant:"caption",component:"span",sx:{fontWeight:"medium"},children:[n,(null==(r=e.required)?void 0:r.includes(n))&&(0,o.jsx)(s.default,{variant:"caption",component:"span",color:"error.main",children:" *"}),": "]}),(0,o.jsx)(s.default,{variant:"caption",component:"span",color:"text.secondary",children:l.description||l.type||"No description"}),l.enum&&(0,o.jsx)(a.default,{sx:{pl:2,mt:.5},children:(0,o.jsxs)(s.default,{variant:"caption",color:"text.secondary",children:["Options: ",l.enum.join(", ")]})})]},n)})})]}):(0,o.jsx)(a.default,{sx:{mt:1},children:(0,o.jsx)(s.default,{variant:"caption",color:"text.secondary",sx:{fontStyle:"italic"},children:"No parameters required."})}))(e.inputSchema)]})})}),(0,o.jsx)(u.A,{title:"Add ".concat(e.name," handoff tool to prompt"),children:(0,o.jsx)(a.default,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0}})})]},e.name))})})]})]})};var tD=r(99944),tL=r(9957),tz=r(16757),tW=r(46496),tO=r(54043),tB=r(54178),t_=r(26811),tH=r(95480);let tU=e=>{let{selected:t,icon:r,title:n,description:l,onClick:i}=e;return(0,o.jsxs)(a.default,{role:"radio","aria-checked":t,tabIndex:0,onClick:i,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),i())},sx:{flex:1,minWidth:180,position:"relative",p:2,borderRadius:2,border:2,borderColor:t?"primary.main":"divider",bgcolor:t?"action.selected":"background.paper",cursor:"pointer",transition:"border-color 120ms, background-color 120ms","&:hover":{borderColor:t?"primary.main":"text.disabled"},outline:"none","&:focus-visible":{boxShadow:e=>"0 0 0 3px ".concat(e.palette.primary.light)}},children:[t&&(0,o.jsx)(eG.A,{color:"primary",fontSize:"small",sx:{position:"absolute",top:8,right:8}}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5,color:t?"primary.main":"text.secondary"},children:[r,(0,o.jsx)(s.default,{variant:"subtitle1",sx:{fontWeight:600,color:"text.primary"},children:n})]}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",children:l})]})},tG=(0,I.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ProcessNodePropertiesModal/PromptTemplateEditor"),tV=(0,n.forwardRef)((e,t)=>{let{promptTemplate:r,handlePromptChange:l,excludeModelPrompt:d,setExcludeModelPrompt:c,excludeStartNodePrompt:u,setExcludeStartNodePrompt:p,excludeSystemPrompt:h,setExcludeSystemPrompt:m,inputMode:g,setInputMode:x,isolatedPrompt:b,setIsolatedPrompt:y,outputMode:w,setOutputMode:j,isModelBound:A,models:S,nodeData:k,flowId:T}=e,[N,I]=(0,n.useState)(""),[M,P]=(0,n.useState)(!1),[F,E]=(0,n.useState)(null),R=(0,n.useRef)(null);(0,n.useImperativeHandle)(t,()=>({insertText:e=>{R.current&&R.current.insertText(e)},getMode:()=>R.current?R.current.getMode():"raw"}));let D=async()=>{if(tG.debug("fetchRenderedPrompt called with:",{flowId:T,nodeId:null==k?void 0:k.id}),!T||!k||!k.id)return void E("Flow ID or Node ID is missing");P(!0),E(null);try{var e;let t=await fetch("/api/flow/prompt-renderer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:T,nodeId:k.id,options:{renderMode:"rendered",includeConversationHistory:!1,excludeModelPrompt:d,excludeStartNodePrompt:u,excludeSystemPrompt:h}})}),r=await t.json();if(!t.ok)throw Error(r.error||"Failed to render prompt");tG.debug("Rendered prompt received",{promptLength:null==(e=r.prompt)?void 0:e.length}),I(r.prompt+"\n\n [Messages sent by User]")}catch(e){tG.error("Error fetching rendered prompt",e),E(e instanceof Error?e.message:"An unknown error occurred")}finally{P(!1)}};return(0,n.useEffect)(()=>{R.current&&"preview"===R.current.getMode()&&D()},[r,d,u,h,T,null==k?void 0:k.id]),(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%",pl:2},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,o.jsx)(s.default,{variant:"h6",children:"Prompt Template"}),(0,o.jsxs)(a.default,{sx:{display:"flex",gap:2},children:[(0,o.jsx)(tD.A,{control:(0,o.jsx)(tL.A,{checked:d,onChange:e=>c(e.target.checked),color:"primary",size:"small"}),label:"Exclude Model Prompt"}),(0,o.jsx)(tD.A,{control:(0,o.jsx)(tL.A,{checked:u,onChange:e=>p(e.target.checked),color:"primary",size:"small"}),label:"Exclude Start Node Prompt"}),(0,o.jsx)(tD.A,{control:(0,o.jsx)(tL.A,{checked:h,onChange:e=>m(e.target.checked),color:"primary",size:"small"}),label:"Exclude System Prompt"})]})]}),(0,o.jsxs)(a.default,{sx:{mb:2,p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,fontSize:"0.85rem"},children:[(0,o.jsx)(s.default,{variant:"caption",sx:{display:"block",mb:1,fontWeight:"bold"},children:"Prompt Rendering Order:"}),(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[!u&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(s.default,{variant:"caption",sx:{color:"primary.main",fontWeight:"medium"},children:"1. Start Node Prompt"}),(0,o.jsx)(s.default,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:"(from the Start node in this flow)"})]}),!d&&A&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(s.default,{variant:"caption",sx:{color:"secondary.main",fontWeight:"medium"},children:[u?"1.":"2."," Model Prompt"]}),(0,o.jsxs)(s.default,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:["(from the selected model: ",(()=>{var e,t;let r=null==(e=k.properties)?void 0:e.boundModel;if(!r)return"None";let o=S.find(e=>e.id===r);return o?o.displayName||o.name:(null==(t=k.properties)?void 0:t.modelName)||"None"})(),")"]})]}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(s.default,{variant:"caption",sx:{fontWeight:"medium"},children:[u||d||!A?u&&(d||!A)?"1.":"2.":"3."," This Node's Prompt"]}),(0,o.jsx)(s.default,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:"(defined below)"})]}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(s.default,{variant:"caption",sx:{fontWeight:"medium"},children:[u||d||!A?u&&(d||!A)?"2.":"3.":"4."," ","isolated"===g?"Isolated prompt":"latest-message"===g?"Latest message only":"Conversation History"]}),(0,o.jsx)(s.default,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:"isolated"===g?"(the prompt below, as the user message)":"latest-message"===g?"(only the most recent user message)":"(coming from ChatCompletion endpoint)"})]})]})]}),(0,o.jsxs)(a.default,{sx:{mb:2},children:[(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mb:1},children:"What does the model receive?"}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":"Model input",sx:{display:"flex",gap:1.5,flexWrap:"wrap"},children:[(0,o.jsx)(tU,{selected:"full-history"===g,onClick:()=>x("full-history"),icon:(0,o.jsx)(tz.A,{fontSize:"small"}),title:"Full conversation",description:"The model sees this node's prompt plus the whole conversation so far. The default."}),(0,o.jsx)(tU,{selected:"latest-message"===g,onClick:()=>x("latest-message"),icon:(0,o.jsx)(tW.A,{fontSize:"small"}),title:"Latest message only",description:"The model sees this node's prompt plus only the most recent user message."}),(0,o.jsx)(tU,{selected:"isolated"===g,onClick:()=>x("isolated"),icon:(0,o.jsx)(tO.A,{fontSize:"small"}),title:"Isolated",description:"The conversation is ignored. The model sees this node's prompt plus the prompt below, sent as the user message."})]}),"isolated"===g&&(0,o.jsx)(v.A,{fullWidth:!0,label:"Isolated prompt",value:b,onChange:e=>y(e.target.value),margin:"normal",multiline:!0,rows:2,helperText:"Sent to the model as the user message. The prior conversation is not shown to the model (it is still kept in the transcript for later nodes)."})]}),(0,o.jsxs)(a.default,{sx:{mb:2},children:[(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mb:1},children:"What do later steps see of this step's work?"}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":"Model output",sx:{display:"flex",gap:1.5,flexWrap:"wrap"},children:[(0,o.jsx)(tU,{selected:"full-conversation"===w,onClick:()=>j("full-conversation"),icon:(0,o.jsx)(tB.A,{fontSize:"small"}),title:"Full conversation",description:"Later steps see everything this step did — tool calls, tool results, and intermediate turns. The default."}),(0,o.jsx)(tU,{selected:"latest-message"===w,onClick:()=>j("latest-message"),icon:(0,o.jsx)(t_.A,{fontSize:"small"}),title:"Latest message only",description:"Later steps see only this step's final response. Its tool calls and results are hidden from later models to save context tokens (they stay visible in the chat and log)."})]})]}),(0,o.jsx)(a.default,{sx:{flexGrow:1,display:"flex",flexDirection:"column",height:"calc(100% - 120px)"},children:(0,o.jsx)(tH.A,{ref:R,value:r,onChange:l,label:"",height:"100%",onModeChange:e=>{"preview"===e&&D()},customPreviewRenderer:()=>M?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(ez.default,{size:40})}):F?(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",p:2},children:[(0,o.jsx)(f.A,{severity:"error",sx:{mb:2},action:(0,o.jsx)(i.A,{color:"inherit",size:"small",onClick:D,children:"Retry"}),children:F}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:2,textAlign:"center"},children:T?"Check that the flow and node IDs are valid and try again.":"This flow hasn't been saved yet. Save the flow first to enable complete preview."})]}):(0,o.jsxs)(a.default,{sx:{p:2},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"medium"},children:"Complete Rendered Prompt"}),(0,o.jsx)(C.A,{elevation:0,sx:{p:2,overflow:"auto",bgcolor:"rgba(0, 0, 0, 0.02)",border:"1px solid rgba(0, 0, 0, 0.1)",borderRadius:1},children:(0,o.jsx)(a.default,{component:"pre",sx:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"monospace",fontSize:"0.875rem",m:0},children:N||"No rendered prompt available. Please check your flow configuration."})})]})})})]})});tV.displayName="PromptTemplateEditor";var t$=r(52641),tJ=r(51221),tK=r(55606);let tY=e=>{let{nodeData:t,handlePropertyChange:r,properties:n}=e;return(0,o.jsx)(o.Fragment,{children:n.length>0&&(0,o.jsxs)(a.default,{sx:{mt:3},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Node Properties"}),n.map(e=>(e=>{var n,l,a;if(!t)return null;let s=null!=(l=null==(n=t.properties)?void 0:n[e.key])?l:"";switch(e.type){case"text":return(0,o.jsx)(v.A,{fullWidth:!0,label:e.label,multiline:e.multiline,rows:e.multiline?4:1,value:s,onChange:t=>r(e.key,t.target.value),margin:"normal",helperText:e.helperText},e.key);case"number":return(0,o.jsx)(v.A,{fullWidth:!0,type:"number",label:e.label,value:s,inputProps:{min:e.min,max:e.max,step:e.step},onChange:t=>{let o=t.target.value;r(e.key,""===o?void 0:Number(o))},margin:"normal",helperText:e.helperText},e.key);case"select":return(0,o.jsxs)(t$.A,{fullWidth:!0,margin:"normal",children:[(0,o.jsx)(tJ.A,{children:e.label}),(0,o.jsx)(tK.A,{value:s||"",label:e.label,onChange:t=>r(e.key,t.target.value),children:null==(a=e.options)?void 0:a.map(e=>(0,o.jsx)(T.A,{value:e,children:e},e))})]},e.key);case"boolean":return(0,o.jsx)(tD.A,{control:(0,o.jsx)(tL.A,{checked:s||!1,onChange:t=>r(e.key,t.target.checked)}),label:e.label,sx:{my:1}},e.key);default:return null}})(e))]})})},tX=(0,I.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ProcessNodePropertiesModal"),tq=e=>{var t;let{open:r,node:l,onClose:d,onSave:u,flowEdges:p=[],flowNodes:f=[],flowId:x,onConnectMcpServer:v}=e;tX.debug("ProcessNodePropertiesModal rendered with:",{node:l,flowId:x});let{nodeData:y,setNodeData:w,handlePropertyChange:j}=(e=>{let[t,r]=(0,n.useState)(null);(0,n.useEffect)(()=>{e&&r({id:e.id,...e.data,properties:{...e.data.properties}})},[e]);let o=(0,n.useCallback)((e,t)=>{r(r=>r?{...r,properties:{...r.properties,[e]:t}}:null)},[]);return{nodeData:t,setNodeData:r,handlePropertyChange:o}})(l),[A,C]=(0,n.useState)(""),[S,k]=(0,n.useState)(!1),[T,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)(!1),[F,R]=(0,n.useState)(!1),[D,L]=(0,n.useState)("full-history"),[z,W]=(0,n.useState)(""),[O,B]=(0,n.useState)("full-conversation"),[_,H]=(0,n.useState)("server"),{models:U,isLoadingModels:G,loadError:V,handleModelSelect:$,handleUnbindModel:J}=((e,t,r,o,l)=>{var a,s;tl.debug("useModelManagement: Entering hook");let[i,d]=(0,n.useState)([]),[c,u]=(0,n.useState)(!1),[p,f]=(0,n.useState)(null);(0,n.useEffect)(()=>{tl.debug("useModelManagement useEffect: Checking if modal is open",{open:e}),e&&h()},[e]),(0,n.useEffect)(()=>{var e,o;if(0===i.length)return;let n=null==t||null==(e=t.properties)?void 0:e.boundModel;if(!n)return;let l=i.find(e=>e.id===n);l&&l.name&&(null==t||null==(o=t.properties)?void 0:o.modelName)!==l.name&&r(e=>{var t;return e&&(null==(t=e.properties)?void 0:t.modelName)!==l.name?{...e,properties:{...e.properties,modelName:l.name}}:e})},[i,null==t||null==(a=t.properties)?void 0:a.boundModel,null==t||null==(s=t.properties)?void 0:s.modelName,r]);let h=async()=>{tl.debug("loadModels: Entering method"),u(!0),f(null);try{let e=await e8.N.loadModels();d(e)}catch(e){tl.warn("loadModels: Failed to load models:",e),f("Failed to load models")}u(!1)},m=(0,n.useCallback)(e=>{tl.debug("handleModelSelect: Entering method",{modelId:e});let t=i.find(t=>t.id===e);t&&(r(r=>{var o;if(!r)return null;let n=i.find(e=>{var t;return e.id===(null==(t=r.properties)?void 0:t.boundModel)}),l=tn({currentLabel:r.label,nameIsCustom:null==(o=r.properties)?void 0:o.nameIsCustom,defaultLabel:"Process Node",previousAutoLabel:n?n.displayName||n.name:void 0,nextAutoLabel:t.displayName||t.name});return{...r,label:l,properties:{...r.properties,boundModel:e,modelName:t.name}}}),l(!0))},[i,r,o,l]);return{models:i,isLoadingModels:c,loadError:p,handleModelSelect:m,handleUnbindModel:(0,n.useCallback)(()=>{tl.debug("handleUnbindModel: Entering method"),r(e=>{if(!e)return null;let{boundModel:t,modelName:r,...o}=e.properties;return{...e,properties:{...o,promptTemplate:o.promptTemplate||""}}}),l(!1)},[r,l])}})(r,y,w,C,k),{connectedMcpNodes:K,allServers:Y,isLoadingServers:X,selectedToolServerNodeId:q,serverToolsMap:Z,serverStatuses:Q,isLoadingTools:ee,handleSelectToolServer:et,isLoadingSelectedServerTools:er,handleRetryServer:eo,handleRestartServer:en}=((e,t,r,o)=>{let l=(0,ta.v)(),a=l.servers||[],s=l.isLoading||!1,[i,d]=(0,n.useState)({}),[c,u]=(0,n.useState)({}),[p,f]=(0,n.useState)({}),[h,m]=(0,n.useState)(null),[g,x]=(0,n.useState)(!1),v=(0,n.useMemo)(()=>t?((e,t)=>[...new Set(t.filter(t=>{var r,o;return t.source===e&&(null==(r=t.data)?void 0:r.edgeType)==="mcp"||t.target===e&&(null==(o=t.data)?void 0:o.edgeType)==="mcp"}).map(t=>t.source===e?t.target:t.source))])(t.id,r):[],[t,r]),b=(0,n.useMemo)(()=>{if(!t||0===v.length)return[];if(!o||!Array.isArray(o))return ts.warn("flowNodes is not available or not an array when filtering connected servers"),[];try{let e=[],t=new Set;return v.forEach(r=>{if(t.has(r))return;let n=o.find(e=>e&&e.id===r);if(!n||!n.data||!n.data.properties)return void ts.warn("Could not find valid MCP node data for ID ".concat(r));let l=n.data.properties.boundServer;if(!l)return void ts.warn("MCP node ".concat(r," is not bound to any server."));let s=a.find(e=>e.name===l),i=(null==s?void 0:s.status)||"unknown",d=n.data.properties.enabledTools||[];e.push({nodeId:r,serverName:l,status:i,enabledTools:Array.isArray(d)?d:[]}),t.add(r)}),ts.debug("Generated connectedMcpNodes:",JSON.stringify(e)),e}catch(e){return ts.error("Error preparing connected MCP nodes:",e),[]}},[t,v,a,o]);(0,n.useEffect)(()=>{if(b&&b.length>0){let e={};b.forEach(t=>{let r=a.find(e=>e.name===t.serverName);e[t.serverName]=(null==r?void 0:r.status)||t.status||"unknown"}),d(e)}},[b,a]),(0,n.useEffect)(()=>{if(e&&b.length>0){let e=Array.from(new Set(b.map(e=>e.serverName)));(async()=>{let t={},r={...c},o=e.filter(e=>{let t=a.find(t=>t.name===e);return(null==t?void 0:t.status)==="connected"&&!c[e]&&!p[e]});0!==o.length&&(o.forEach(e=>{t[e]=!0}),f(e=>({...e,...t})),await Promise.all(o.map(async e=>{try{ts.debug("Loading tools for server: ".concat(e));let t=await E.S.listServerTools(e);if(t.error)ts.warn("Error loading tools for ".concat(e,":"),t.error),r[e]=[];else{let o=t.tools||[];ts.debug("Loaded ".concat(o.length," tools for ").concat(e)),r[e]=o}}catch(t){ts.warn("Failed to load tools for server ".concat(e,":"),t),r[e]=[]}finally{f(t=>({...t,[e]:!1}))}})),u(r))})()}},[e,b,a]);let y=(0,n.useRef)(c);(0,n.useEffect)(()=>{y.current=c},[c]);let w=(0,n.useCallback)(e=>{ts.debug("Selected MCP Node ID: ".concat(e)),m(e);let t=b.find(t=>t.nodeId===e),r=null==t?void 0:t.serverName;!r||y.current[r]||p[r]?x(p[r||""]||!1):(ts.debug("Tools not loaded for server ".concat(r,", loading now.")),x(!0),f(e=>({...e,[r]:!0})),E.S.listServerTools(r).then(e=>{let t=e.tools||[];e.error?ts.warn("Error loading tools for ".concat(r,":"),e.error):ts.debug("Loaded ".concat(t.length," tools for ").concat(r)),u(e=>({...e,[r]:t}))}).catch(e=>{ts.warn("Failed to load tools for server ".concat(r,":"),e),u(e=>({...e,[r]:[]}))}).finally(()=>{x(!1),f(e=>({...e,[r]:!1}))}))},[b,p]),j=(0,n.useRef)(l);return(0,n.useEffect)(()=>{j.current=l},[l]),{connectedMcpNodes:b,allServers:a,isLoadingServers:s,selectedToolServerNodeId:h,serverToolsMap:c,serverStatuses:i,isLoadingTools:p,handleSelectToolServer:w,isLoadingSelectedServerTools:g,handleRetryServer:(0,n.useCallback)(async e=>{ts.debug("Retrying server: ".concat(e)),f(t=>({...t,[e]:!0}));try{await j.current.retryServer(e);let t=await E.S.listServerTools(e);if(t.error)return ts.warn("Error loading tools for ".concat(e," after retry:"),t.error),!1;{let r=t.tools||[];return ts.debug("Loaded ".concat(r.length," tools for ").concat(e," after retry")),u(t=>({...t,[e]:r})),!0}}catch(t){return ts.warn("Failed to retry or load tools for server ".concat(e,":"),t),!1}finally{f(t=>({...t,[e]:!1}))}},[]),handleRestartServer:(0,n.useCallback)(async e=>{ts.debug("Restarting server: ".concat(e)),f(t=>({...t,[e]:!0}));try{await E.S.restartServer(e),await new Promise(e=>setTimeout(e,1e3));let t=await E.S.listServerTools(e);if(t.error)return ts.warn("Error loading tools for ".concat(e," after restart:"),t.error),!1;{let r=t.tools||[];return ts.debug("Loaded ".concat(r.length," tools for ").concat(e," after restart")),u(t=>({...t,[e]:r})),!0}}catch(t){return ts.warn("Failed to restart or load tools for server ".concat(e,":"),t),!1}finally{f(t=>({...t,[e]:!1}))}},[])}})(r,l,p,f),el=((e,t,r,o)=>{let[l,a]=(0,n.useState)([]),[s,i]=(0,n.useState)(!1),d=(0,n.useMemo)(()=>t?function(e,t){let r=[];for(let l of t){var o,n;!("string"==typeof(null==(o=l.data)?void 0:o.edgeType)&&(l.data.edgeType.includes("mcp")||"resource"===l.data.edgeType))&&(l.source===e?r.push(l.target):l.target===e&&(null==(n=l.data)?void 0:n.bidirectional)&&r.push(l.source))}return[...new Set(r)]}(t.id,r):[],[t,r]);return(0,n.useEffect)(()=>{if(e&&t){i(!0);try{let e=d.map(e=>o.find(t=>t.id===e)).filter(e=>!!e),t=(0,ti.E9)(e.map(e=>({id:e.id,label:e.data.label,type:e.type||e.data.type}))),r=e.map(e=>({name:t.get(e.id)||"handoff_to_".concat(e.id),description:function(e){if(e.userDescription&&e.userDescription.trim())return td(e.userDescription,1500);let t="Hand off execution to ".concat(e.label," (").concat(e.type,")."),r=[];!function e(t,r,o){let n=" ".repeat(r);if(t.userDescription&&t.userDescription.trim())return void o.push("".concat(n).concat(td(t.userDescription,200)));if("subflow"===t.type){var l,a;if(t.subflowMissing)return void o.push("".concat(n,"Runs a subflow (referenced flow not found)."));if(t.subflowDetailsUnavailable){let e=t.subflowName?' "'.concat(t.subflowName,'"'):"";o.push("".concat(n,"Runs a subflow").concat(e," (contents summarised when the flow runs)."));return}if(o.push("".concat(n,'Runs the subflow "').concat(null!=(l=t.subflowName)?l:"unknown",'", which contains:')),t.depthCapReached)return void o.push("".concat(n," (nested subflows omitted — recursion depth limit reached)"));let s=null!=(a=t.children)?a:[];if(0===s.length)return void o.push("".concat(n," (no process or subflow steps)"));for(let t of s.slice(0,10))o.push("".concat(n," - ").concat(t.label,":")),e(t,r+2,o);return void(s.length>10&&o.push("".concat(n," - …and ").concat(s.length-10," more step(s)")))}if(t.modelName&&o.push("".concat(n,"Model: ").concat(t.modelName)),t.promptSummary&&o.push("".concat(n,"Role: ").concat(td(t.promptSummary,200))),t.servers&&t.servers.length>0)for(let e of t.servers)if(e.connected&&e.tools&&e.tools.length>0){let t=e.tools.slice(0,10),r=e.tools.length-t.length,l=r>0?", +".concat(r," more"):"";o.push("".concat(n,"Tools (").concat(e.name,"): ").concat(t.join(", ")).concat(l))}else o.push("".concat(n,"Tools (").concat(e.name,"): server not connected"))}(e,0,r);let o=r.join("\n").trim(),n=o?"".concat(t,"\n").concat(o):t;if(n.length<=1500)return n;let l=1500-t.length-2;return l<=0?t:"".concat(t,"\n").concat(td(o,l))}(function(e){let t=e.type||e.data.type||"unknown",r=e.data.label||"Unknown Node",o=e.data.description,n=e.data.properties||{},l={label:r,type:t,userDescription:o};if(o&&o.trim())return l;if("subflow"===t)return l.subflowDetailsUnavailable=!0,l;"string"==typeof n.boundModel&&n.boundModel&&(l.modelName=n.boundModel),"string"==typeof n.promptTemplate&&n.promptTemplate.trim()&&(l.promptSummary=n.promptTemplate);let a=Array.isArray(n.mcpNodes)?n.mcpNodes:[],s=[],i=new Set;for(let e of a){var d,c;let t=null==e||null==(d=e.properties)?void 0:d.boundServer;if(!t||i.has(t))continue;i.add(t);let r=Array.isArray(null==e||null==(c=e.properties)?void 0:c.enabledTools)?e.properties.enabledTools:[];s.push({name:t,connected:!0,tools:r})}return s.length>0&&(l.servers=s),l}(e)),inputSchema:{type:"object",properties:{},required:[]}}));a(r),tc.debug("Generated handoff tools",{toolsCount:r.length})}catch(e){tc.error("Error generating handoff tools",e),a([])}finally{i(!1)}}else a([])},[e,t,d,r,o]),{handoffTools:l,isLoadingHandoffTools:s}})(r,l,p,f),ea=(null==el?void 0:el.handoffTools)||[],es=(null==el?void 0:el.isLoadingHandoffTools)||!1;(0,n.useEffect)(()=>{r&&l&&tX.debug("Handoff tools:",{count:ea.length,tools:ea.map(e=>e.name)})},[r,l,ea]),(0,n.useEffect)(()=>{if(l){var e,t,r,o,n,a,s,i;C((null==(e=l.data.properties)?void 0:e.promptTemplate)||""),(null==(t=l.data.properties)?void 0:t.boundModel)?k(!0):k(!1),I((null==(r=l.data.properties)?void 0:r.excludeModelPrompt)||!1),P((null==(o=l.data.properties)?void 0:o.excludeStartNodePrompt)||!1),R((null==(n=l.data.properties)?void 0:n.excludeSystemPrompt)||!1),L((null==(a=l.data.properties)?void 0:a.inputMode)||"full-history"),W((null==(s=l.data.properties)?void 0:s.isolatedPrompt)||""),B((null==(i=l.data.properties)?void 0:i.outputMode)||"full-conversation")}},[l,r]);let ei=(0,n.useRef)(null),ed=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"server";if(tX.debug("handleInsertToolBinding called with:",JSON.stringify({serverName:e,toolName:t})),!e||!t)return void tX.warn("Invalid parameters for handleInsertToolBinding:",{serverName:e,toolName:t});let o=(Z[e]||[]).find(e=>e.name===t);null==o||o.description;let n="handoff"===r?(0,eV.X8)("tool","handoff",t):(0,eV.X8)("tool",e,t),l=(!(A.length>0)||A.endsWith(" ")||A.endsWith("\n")?"":" ")+n;ei.current?(tX.debug("Inserting text into PromptBuilder:",JSON.stringify({textToInsert:l})),ei.current.insertText(l),tX.debug("Tool binding inserted successfully")):tX.warn("promptBuilderRef.current is null, cannot insert text")};if(!l||!y)return null;let ec=(null==(t=y.properties)?void 0:t.boundModel)||"";return(0,o.jsxs)(h.A,{open:r,onClose:d,maxWidth:"xl",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"secondary.main",width:"95vw",height:"90vh",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(m.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsxs)(s.default,{variant:"h6",children:[y.label||"Process Node"," Properties"]}),(0,o.jsx)(c.A,{edge:"end",color:"inherit",onClick:d,"aria-label":"close",children:(0,o.jsx)(to.A,{})})]})}),(0,o.jsx)(N.A,{}),(0,o.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",p:3,overflow:"auto",height:"calc(90vh - 130px)"},children:(0,o.jsxs)(te.Ay,{container:!0,spacing:2,sx:{flexGrow:1,height:"100%"},children:[(0,o.jsxs)(te.Ay,{item:!0,xs:6,sx:{display:"flex",flexDirection:"column",height:"100%",overflow:"auto"},children:[(0,o.jsx)(a.default,{sx:{mb:3},children:(0,o.jsx)(tu,{nodeData:y,setNodeData:w})}),(0,o.jsx)(a.default,{sx:{mb:3},children:(0,o.jsx)(tx,{isLoadingModels:G,loadError:V,models:U,selectedModelId:ec,handleModelSelect:$,isModelBound:S,handleUnbindModel:J})}),(0,o.jsxs)(a.default,{sx:{mb:3},children:[(0,o.jsx)(a.default,{sx:{borderBottom:1,borderColor:"divider",mb:2},children:(0,o.jsxs)(tt.A,{value:_,onChange:(e,t)=>H(t),children:[(0,o.jsx)(tr.A,{label:"Server Tools",value:"server"}),(0,o.jsx)(tr.A,{label:"Resources",value:"resources"}),(0,o.jsx)(tr.A,{label:"Agent Tools",value:"agent"})]})}),"server"===_&&(0,o.jsx)(tI,{isLoadingServers:X,connectedMcpNodes:K,availableServers:Y,onConnectMcpServer:v,serverStatuses:Q,serverToolsMap:Z,isLoadingTools:ee,handleInsertToolBinding:ed,selectedToolServerNodeId:q,selectedNodeId:(null==l?void 0:l.id)||null,handleSelectToolServer:et,isLoadingSelectedServerTools:er,promptBuilderRef:ei,handleRetryServer:eo,handleRestartServer:en}),"resources"===_&&(0,o.jsx)(tF,{connectedMcpNodes:K,handleInsertResourceBinding:(e,t)=>{if(!e||!t)return void tX.warn("Invalid parameters for handleInsertResourceBinding:",{serverName:e,uri:t});let r=(0,eV.X8)("resource",e,t),o=A.length>0&&!A.endsWith(" ")&&!A.endsWith("\n");ei.current?ei.current.insertText((o?" ":"")+r):tX.warn("promptBuilderRef.current is null, cannot insert resource binding")},promptBuilderRef:ei}),"agent"===_&&(0,o.jsx)(tR,{handoffTools:ea,isLoadingHandoffTools:es,handleInsertToolBinding:(e,t)=>ed(e,t,"handoff"),promptBuilderRef:ei})]}),(0,o.jsx)(a.default,{children:(0,o.jsx)(tY,{nodeData:y,handlePropertyChange:j,properties:[{key:"maxTurns",label:"Max Turns (override)",type:"number",min:1,helperText:"Optional. Overrides the bound model's Max Turns for this node. Leave empty to inherit the model setting (default 50)."}]})})]}),(0,o.jsx)(te.Ay,{item:!0,xs:6,sx:{height:"100%",display:"flex",flexDirection:"column"},children:(0,o.jsx)(tV,{ref:ei,promptTemplate:A,handlePromptChange:e=>{C(e),w(t=>t?{...t,properties:{...t.properties,promptTemplate:e}}:null)},excludeModelPrompt:T,setExcludeModelPrompt:I,excludeStartNodePrompt:M,setExcludeStartNodePrompt:P,excludeSystemPrompt:F,setExcludeSystemPrompt:R,inputMode:D,setInputMode:L,isolatedPrompt:z,setIsolatedPrompt:W,outputMode:O,setOutputMode:B,isModelBound:S,models:U,nodeData:y,flowId:x})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:d,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{if(l&&y){let e={...y,properties:{...y.properties,promptTemplate:A,excludeModelPrompt:T,excludeStartNodePrompt:M,excludeSystemPrompt:F,inputMode:D,isolatedPrompt:z,outputMode:O}};u(l.id,e),d()}},variant:"contained",color:"primary",children:"Save Changes"})]})]})};var tZ=r(71651),tQ=r(94035);let t0=(0,I.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/MCPNodePropertiesModal"),t1=e=>{var t,r,l,d,p,f,x,y;let{open:w,node:j,onClose:A,onSave:C}=e,[S,k]=(0,n.useState)(null),{servers:T,isLoading:I,loadError:M,retryServer:P}=(0,ta.v)(),[F,E]=(0,n.useState)({}),R=(0,tg.E)("mcp",T),[D,L]=(0,n.useState)(!1),z=async()=>{L(!0);try{await Promise.all(T.map(e=>P(e.name)))}finally{setTimeout(()=>L(!1),500)}},{tools:W,isLoading:O,error:B,loadTools:_}=(0,tQ.O)((null==S||null==(t=S.properties)?void 0:t.boundServer)||"");(0,n.useEffect)(()=>{j&&k({...j.data,properties:{...j.data.properties}})},[j,w]);let H=(null==S||null==(r=S.properties)?void 0:r.boundServer)||"";(0,n.useEffect)(()=>{W&&W.length>0&&(e=>{S&&0===(S.properties.enabledTools||[]).length&&e.length>0&&(t0.debug("Enabling all tools by default"),k(t=>t?{...t,properties:{...t.properties,enabledTools:e.map(e=>e.name)}}:null))})(W)},[W]);let U=(e,t)=>{k(r=>r?{...r,properties:{...r.properties,[e]:t}}:null)},G=async(e,t)=>{t&&t.stopPropagation(),t0.debug("Retrying server: ".concat(e)),E(t=>({...t,[e]:!0}));try{return await P(e),e===H&&_(!0),!0}catch(t){return t0.warn("Failed to retry server ".concat(e,": ").concat(t)),!1}finally{setTimeout(()=>{E(t=>({...t,[e]:!1}))},500)}};if(!j||!S)return null;let V=(null==(l=S.properties)?void 0:l.boundServer)||"",$=(null==(d=S.properties)?void 0:d.enabledTools)||[],J=e=>({key:e.name,content:(e=>(0,o.jsx)(tT.A,{name:e.name,status:e.status||"disconnected",path:e.path||e.rootPath||"",enabled:!e.disabled,transport:e.transport||"stdio",pickerMode:!0,selected:V===e.name,onClick:()=>(e=>{t0.debug("Server selected: ".concat(e)),t0.debug("Server selected: ".concat(e)),k(t=>{var r,o;if(!t)return null;let n=tn({currentLabel:t.label,nameIsCustom:null==(r=t.properties)?void 0:r.nameIsCustom,defaultLabel:"MCP Node",previousAutoLabel:(null==(o=t.properties)?void 0:o.boundServer)||void 0,nextAutoLabel:e});return{...t,label:n,properties:{...t.properties,boundServer:e}}})})(e.name)}))(e)}),K=R.items.map(J),Y=R.groups?R.groups.map(e=>({...e,items:e.items.map(J)})):null,X=null==(p=S.properties)?void 0:p.toolTimeout,Q=-1===X;return(0,o.jsxs)(h.A,{open:w,onClose:A,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"info.main",height:"80vh",maxHeight:"80vh"}},children:[(0,o.jsx)(m.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsxs)(s.default,{variant:"h6",children:[S.label||"MCP Node"," Properties"]}),(0,o.jsx)(c.A,{edge:"end",color:"inherit",onClick:A,"aria-label":"close",children:(0,o.jsx)(to.A,{})})]})}),(0,o.jsx)(N.A,{}),(0,o.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",p:3,overflow:"auto"},children:[(0,o.jsx)(v.A,{fullWidth:!0,label:"Node Label",value:S.label||"",onChange:e=>{k(t=>t?{...t,label:e.target.value,properties:{...t.properties,nameIsCustom:!0}}:null)},margin:"normal",helperText:"The display name for this node on the canvas",sx:{mb:2}}),(0,o.jsxs)(a.default,{sx:{mb:4},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Bind to MCP Server"}),(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"flex-end",mb:1},children:(0,o.jsx)(u.A,{title:"Retry all server connections",children:(0,o.jsx)("span",{children:(0,o.jsx)(c.A,{size:"small",onClick:z,disabled:D||I,children:D?(0,o.jsx)(ez.default,{size:16}):(0,o.jsx)(tj.A,{fontSize:"small"})})})})}),(0,o.jsx)(th.A,{isLoading:I,error:M,emptyMessage:"No MCP servers available. Add some in the MCP Manager.",loadingMessage:"Loading MCP servers…",searchable:!0,searchPlaceholder:"Search servers…",searchTerm:R.searchTerm,onSearchChange:R.setSearchTerm,columns:{xs:12,sm:6},items:K,groups:Y,collapsedKeys:R.collapsedKeys,onToggleGroup:R.toggleGroup}),(0,o.jsx)(tp.A,{children:V?'This node will use the "'.concat(V,'" MCP server for processing.'):"Select an MCP server to bind this node to."})]}),(0,o.jsx)(v.A,{fullWidth:!0,label:"Description",value:S.description||"",onChange:e=>k({...S,description:e.target.value}),margin:"normal",multiline:!0,rows:2,helperText:"This description will be displayed on the node"}),V&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Tool Call Timeout"}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:1},children:"How long a single tool call on this server may run before it is aborted. Tools that report progress keep the timeout alive while they work."}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,o.jsx)(v.A,{label:"Timeout (seconds)",type:"number",size:"small",sx:{width:200},value:Q?"":null!=X?X:"",placeholder:String(300),disabled:Q,inputProps:{min:1},onChange:e=>{let t=e.target.value;if(""===t)return void U("toolTimeout",void 0);let r=parseInt(t,10);!isNaN(r)&&r>0&&U("toolTimeout",r)},helperText:Q?"No timeout — tool calls run until they finish.":"Empty = default (".concat(300," seconds / 5 minutes).")}),(0,o.jsx)(tD.A,{control:(0,o.jsx)(tL.A,{checked:Q,onChange:e=>U("toolTimeout",e.target.checked?-1:void 0)}),label:"No timeout (infinite)"})]})]}),V&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(s.default,{variant:"subtitle1",gutterBottom:!0,children:"Allowed Tools"}),(null==(f=T.find(e=>e.name===V))?void 0:f.status)!=="connected"&&(0,o.jsxs)(a.default,{sx:{mb:2,p:2,bgcolor:"error.light",borderRadius:1},children:[(0,o.jsx)(s.default,{color:"error.dark",children:"Server is disconnected. Tools cannot be fetched. Please retry the connection."}),(0,o.jsx)(i.A,{variant:"outlined",size:"small",color:"primary",startIcon:F[V]?(0,o.jsx)(ez.default,{size:16}):(0,o.jsx)(tj.A,{}),onClick:()=>G(V),disabled:F[V],sx:{mt:1},children:"Retry Connection"})]}),O?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(ez.default,{size:20}),(0,o.jsx)(s.default,{color:"text.secondary",children:"Loading tools..."})]}):B?(0,o.jsx)(s.default,{color:"error",children:B}):W&&0!==W.length?(0,o.jsxs)(a.default,{sx:{mt:2},children:[(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Select which tools this node will have access to. This helps limit the tools available to connected process nodes."}),(0,o.jsx)(eW.A,{children:W.map(e=>(0,o.jsxs)(eB.Ay,{sx:{py:0},children:[(0,o.jsx)(q.A,{sx:{minWidth:42},children:(0,o.jsx)(tL.A,{edge:"start",checked:$.includes(e.name),onChange:()=>(e=>{t0.debug("Tool toggled: ".concat(e)),k(t=>{let r;if(!t)return null;let o=t.properties.enabledTools||[];return r=o.includes(e)?o.filter(t=>t!==e):[...o,e],{...t,properties:{...t.properties,enabledTools:r}}})})(e.name)})}),(0,o.jsx)(Z.A,{primary:e.name,secondary:e.description,primaryTypographyProps:{fontWeight:"medium"}})]},e.name))})]}):(0,o.jsx)(s.default,{color:"text.secondary",children:(null==(x=T.find(e=>e.name===V))?void 0:x.status)==="connected"?"No tools available for this MCP server.":"Connect to the server to view available tools."})]}),V&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(tZ.A,{roots:(null==(y=S.properties)?void 0:y.roots)||[],onChange:e=>U("roots",e)}),(0,o.jsxs)(s.default,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:1},children:["These folders apply to this node only and are ",(0,o.jsx)("strong",{children:"added to"}),' the workspace folders configured on the "',V,'" server itself. When neither is set, the server sees its own root dir as its workspace folder.']})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:A,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{j&&S&&(C(j.id,S),A())},variant:"contained",color:"primary",children:"Save Changes"})]})]})},t2=e=>{let{open:t,node:r,onClose:l,onSave:d}=e,[u,p]=(0,n.useState)(null),[f,x]=(0,n.useState)("");return((0,n.useEffect)(()=>{if(r){var e;p({...r.data,properties:{...r.data.properties}}),x((null==(e=r.data.properties)?void 0:e.promptTemplate)||"")}},[r,t]),r&&u)?(0,o.jsxs)(h.A,{open:t,onClose:l,maxWidth:"xl",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"primary.main",width:"95vw",height:"90vh",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(m.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsxs)(s.default,{variant:"h6",children:[u.label||"Start Node"," Properties"]}),(0,o.jsx)(c.A,{edge:"end",color:"inherit",onClick:l,"aria-label":"close",children:(0,o.jsx)(to.A,{})})]})}),(0,o.jsx)(N.A,{}),(0,o.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",p:3,overflow:"auto",height:"calc(90vh - 130px)"},children:(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(s.default,{variant:"h6",gutterBottom:!0,children:"Prompt Template"}),(0,o.jsx)(a.default,{sx:{flexGrow:1,display:"flex",flexDirection:"column",height:"calc(100% - 40px)"},children:(0,o.jsx)(tH.A,{value:f,onChange:e=>{x(e),p(t=>t?{...t,properties:{...t.properties,promptTemplate:e}}:null)},label:"",height:"100%"})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:l,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{if(r&&u){let e={...u,properties:{...u.properties,promptTemplate:f}};d(r.id,e),l()}},variant:"contained",color:"primary",children:"Save Changes"})]})]}):null},t5=e=>{let{open:t,node:r,onClose:l,onSave:d}=e,[u,p]=(0,n.useState)(null);return((0,n.useEffect)(()=>{r&&p({...r.data,properties:{...r.data.properties}})},[r,t]),r&&u)?(0,o.jsxs)(h.A,{open:t,onClose:l,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"success.main",width:"600px",height:"400px",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(m.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsxs)(s.default,{variant:"h6",children:[u.label||"Finish Node"," Properties"]}),(0,o.jsx)(c.A,{edge:"end",color:"inherit",onClick:l,"aria-label":"close",children:(0,o.jsx)(to.A,{})})]})}),(0,o.jsx)(N.A,{}),(0,o.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",p:3,overflow:"auto"},children:(0,o.jsx)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%",justifyContent:"center",alignItems:"center",py:4},children:(0,o.jsxs)(C.A,{elevation:0,sx:{p:4,textAlign:"center",backgroundColor:"rgba(76, 175, 80, 0.08)",borderRadius:2,width:"100%"},children:[(0,o.jsx)(s.default,{variant:"h6",color:"success.main",gutterBottom:!0,children:"Finish Node"}),(0,o.jsx)(s.default,{variant:"body1",color:"text.secondary",children:"This is the end point of your flow. No additional configuration is needed."}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mt:2,fontStyle:"italic"},children:"Future versions will support output formatting options."})]})})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:l,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{r&&u&&(d(r.id,u),l())},variant:"contained",color:"primary",children:"Save"})]})]}):null};var t4=r(22822),t6=r(56900),t3=r(9226);let t8=(0,I.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/SubflowNodePropertiesModal"),t7=e=>{var t,r,l,d,u,p,x,y,w,j,A;let{open:C,node:S,onClose:k,onSave:T,flowId:I}=e,[M,P]=(0,n.useState)(null),[E,R]=(0,n.useState)([]),[D,L]=(0,n.useState)(!1),[z,W]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(S){let e=S.data.properties||{};P({...S.data,properties:{...e}})}},[S,C]),(0,n.useEffect)(()=>{if(!C)return;let e=!1;return L(!0),F.g.loadFlows().then(t=>{e||R(t||[])}).catch(t=>{t8.warn("Failed to load flows for subflow picker",t),e||R([])}).finally(()=>{e||L(!1)}),()=>{e=!0}},[C]);let O=(e,t)=>{P(r=>r?{...r,properties:{...r.properties,[e]:t}}:null)},B=E.filter(e=>e.id!==I),_=(0,tg.E)("flows",B);if(!S||!M)return null;let H=(null==(t=M.properties)?void 0:t.subflowId)||"",U=!!H&&!E.some(e=>e.id===H),G=U?"":(null==(r=E.find(e=>e.id===H))?void 0:r.name)||"",V=(null==(l=M.properties)?void 0:l.promptTemplate)||"",$=(null==(d=M.properties)?void 0:d.inputMode)||(V.trim()?"isolated":"full-history");return(0,o.jsxs)(h.A,{open:C,onClose:k,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"warning.main",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(m.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsxs)(s.default,{variant:"h6",children:[M.label||"Subflow Node"," Properties"]}),(0,o.jsx)(c.A,{edge:"end",color:"inherit",onClick:k,"aria-label":"close",children:(0,o.jsx)(to.A,{})})]})}),(0,o.jsx)(N.A,{}),(0,o.jsxs)(g.A,{sx:{p:3},children:[(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"This step runs another flow inside this one — like calling a helper. When it finishes, its answer becomes part of this conversation and the flow continues to the next node."}),(0,o.jsx)(v.A,{fullWidth:!0,label:"Node Label",value:M.label||"",onChange:e=>P({...M,label:e.target.value}),margin:"normal"}),(0,o.jsxs)(a.default,{sx:{mt:2},children:[(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mb:1},children:"Flow to run"}),(0,o.jsx)(i.A,{variant:"outlined",startIcon:(0,o.jsx)(t6.A,{}),onClick:()=>W(!0),sx:{textTransform:"none",maxWidth:"100%"},children:(0,o.jsx)(a.default,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G||"Choose a flow…"})})]}),U&&(0,o.jsx)(f.A,{severity:"warning",sx:{mt:1},children:"The previously selected flow no longer exists. Please choose another."}),(0,o.jsx)(tk.A,{open:z,onClose:()=>W(!1),title:"Choose a flow to run",description:"This subflow node will run the selected flow as a helper.",isLoading:D,skeleton:(0,o.jsx)(t3.o,{}),emptyMessage:"No other flows available. Create another flow first.",searchable:!0,searchPlaceholder:"Search flows…",searchTerm:_.searchTerm,onSearchChange:_.setSearchTerm,items:_.items.map(e=>({key:e.id,content:(0,o.jsx)(t3.A,{flow:e,selected:e.id===H,onSelect:e=>{O("subflowId",e),W(!1)},pickerMode:!0})})),groups:_.groups?_.groups.map(e=>({...e,items:e.items.map(e=>({key:e.id,content:(0,o.jsx)(t3.A,{flow:e,selected:e.id===H,onSelect:e=>{O("subflowId",e),W(!1)},pickerMode:!0})}))})):null,collapsedKeys:_.collapsedKeys,onToggleGroup:_.toggleGroup}),(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mt:3,mb:1},children:"What does the subflow receive?"}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":"Subflow input",sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[(0,o.jsx)(tU,{selected:"full-history"===$,onClick:()=>O("inputMode","full-history"),icon:(0,o.jsx)(tz.A,{}),title:"Full conversation",description:"The subflow sees the whole conversation so far. Best for a helper that should continue with all the context."}),(0,o.jsx)(tU,{selected:"latest-message"===$,onClick:()=>O("inputMode","latest-message"),icon:(0,o.jsx)(tW.A,{}),title:"Latest message only",description:"The subflow sees only the most recent message. Best for an orchestrator that hands off one task at a time, so old tasks don't leak in."}),(0,o.jsx)(tU,{selected:"isolated"===$,onClick:()=>O("inputMode","isolated"),icon:(0,o.jsx)(tO.A,{}),title:"Isolated",description:"The conversation is ignored. The subflow receives only the prompt you write below, as its first message."})]}),"isolated"===$&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(tD.A,{sx:{mt:1,display:"block"},control:(0,o.jsx)(t4.A,{checked:(null==(u=M.properties)?void 0:u.allowCallerPrompt)!==!1,onChange:e=>O("allowCallerPrompt",e.target.checked)}),label:"Let the caller pass a prompt"}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:1,ml:4,mt:-.5},children:"When on, a step that routes to this subflow can attach an instruction through its handoff tool, overriding the prompt below. The prompt below is then used only as a default when the caller sends none."}),(0,o.jsx)(v.A,{fullWidth:!0,label:(null==(p=M.properties)?void 0:p.allowCallerPrompt)!==!1?"Default prompt (used if the caller sends none)":"Isolated prompt",value:V,onChange:e=>O("promptTemplate",e.target.value),margin:"normal",multiline:!0,rows:3,helperText:(null==(x=M.properties)?void 0:x.allowCallerPrompt)!==!1?"The default first message for the subflow. A routing model may override it via the handoff tool. The parent conversation is not passed.":"Sent to the subflow as its single user message. The parent conversation is not passed."})]}),(0,o.jsx)(tD.A,{sx:{mt:2,display:"block"},control:(0,o.jsx)(t4.A,{checked:!!(null==(y=M.properties)?void 0:y.allowCallerFanout),onChange:e=>O("allowCallerFanout",e.target.checked)}),label:"Let the caller choose parallel flows (agentic fan-out)"}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{mb:1,ml:4,mt:-.5},children:"When on, a step that routes to this subflow can pass a list of flows to run in parallel through its handoff tool, letting the model decide the fan-out set at runtime. Unknown flows are dropped and the count is capped."}),(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mt:3,mb:1},children:"What do you see in the chat while the subflow runs?"}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":"Subflow output",sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[(0,o.jsx)(tU,{selected:"final-only"!==((null==(w=M.properties)?void 0:w.outputMode)||"steps"),onClick:()=>O("outputMode","steps"),icon:(0,o.jsx)(tB.A,{}),title:"Full",description:"You see all of the subflow's messages in the chat, indented under this step — like watching it work."}),(0,o.jsx)(tU,{selected:(null==(j=M.properties)?void 0:j.outputMode)==="final-only",onClick:()=>O("outputMode","final-only"),icon:(0,o.jsx)(t_.A,{}),title:"Condensed",description:"You only see the subflow's final answer as a single message. Its inner steps stay hidden."})]}),(0,o.jsx)(s.default,{variant:"subtitle2",sx:{mt:3,mb:1},children:"Debugging"}),(0,o.jsx)(tD.A,{sx:{display:"block"},control:(0,o.jsx)(tL.A,{checked:(null==(A=M.properties)?void 0:A.saveConversation)!==!1,onChange:e=>O("saveConversation",e.target.checked)}),label:"Save this subflow's conversation to the sidebar (useful for debugging)"}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",sx:{ml:4,mt:-.5},children:'When on, each run of this subflow is persisted as its own conversation in the chat sidebar, linked to the parent run — like a planned execution\'s "Save full conversations". Fan-out and map-over-list runs stay ephemeral.'})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:k,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{S&&M&&(T(S.id,M),k())},variant:"contained",color:"primary",children:"Save"})]})]})};var t9=r(43861),re=r(75656);let rt=(0,I.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ResourceNodePropertiesModal"),rr=e=>{var t,r,l,d,c;let{open:u,node:p,onClose:f,onSave:x}=e,[y,w]=(0,n.useState)(null),{servers:j,isLoading:A}=(0,ta.v)(),[C,S]=(0,n.useState)([]),[k,N]=(0,n.useState)(!1),[I,M]=(0,n.useState)(null);(0,n.useEffect)(()=>{p&&w({...p.data,properties:{scope:"mcp",...p.data.properties}})},[p,u]);let P=(null==y||null==(t=y.properties)?void 0:t.scope)==="run"?"run":"mcp",F=(null==y||null==(r=y.properties)?void 0:r.boundServer)||"",R=(null==y||null==(l=y.properties)?void 0:l.uri)||"",D=(null==y||null==(d=y.properties)?void 0:d.runName)||"",L=(0,n.useCallback)((e,t)=>{w(r=>r?{...r,properties:{...r.properties,[e]:t}}:r)},[]);(0,n.useEffect)(()=>{if(!u||"mcp"!==P||!F){S([]),M(null);return}let e=!1;return N(!0),M(null),E.S.listServerResources(F).then(t=>{if(!e)if(t.error)M(t.error),S([]);else{var r,o;S([...(null!=(r=t.resources)?r:[]).map(e=>({uri:e.uri,name:e.name,description:e.description,mimeType:e.mimeType})),...(null!=(o=t.resourceTemplates)?o:[]).map(e=>({uri:e.uriTemplate,name:e.name?"".concat(e.name," (template)"):"(template)",description:e.description}))])}}).catch(t=>{e||(rt.warn("Failed to browse resources of ".concat(F),t),M(t instanceof Error?t.message:String(t)))}).finally(()=>{e||N(!1)}),()=>{e=!0}},[u,P,F]);let z="run"===P&&!!D.trim()&&!eY(D.trim());return y?(0,o.jsxs)(h.A,{open:u,onClose:f,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(m.A,{children:"Resource Node Properties"}),(0,o.jsx)(g.A,{children:(0,o.jsxs)(a.default,{display:"flex",flexDirection:"column",gap:2,mt:1,children:[(0,o.jsx)(v.A,{label:"Label",value:y.label,onChange:e=>w({...y,label:e.target.value}),fullWidth:!0}),(0,o.jsx)(v.A,{label:"Description",value:null!=(c=y.description)?c:"",onChange:e=>w({...y,description:e.target.value}),fullWidth:!0,multiline:!0,minRows:2}),(0,o.jsxs)(t$.A,{children:[(0,o.jsxs)(t9.A,{row:!0,value:P,onChange:e=>L("scope","run"===e.target.value?"run":"mcp"),children:[(0,o.jsx)(tD.A,{value:"mcp",control:(0,o.jsx)(re.A,{}),label:"MCP resource"}),(0,o.jsx)(tD.A,{value:"run",control:(0,o.jsx)(re.A,{}),label:"Run artifact"})]}),(0,o.jsx)(tp.A,{children:"mcp"===P?"A static resource published by an MCP server. Steps connected FROM this node receive its contents.":"A named piece of run data: a step writing INTO this node saves its output here; steps reading FROM it receive the latest value (also available as ${res:NAME})."})]}),"mcp"===P?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t$.A,{fullWidth:!0,children:[(0,o.jsx)(tJ.A,{id:"resource-server-label",children:"Server"}),(0,o.jsxs)(tK.A,{labelId:"resource-server-label",label:"Server",value:F,onChange:e=>{L("boundServer",e.target.value)},children:[A&&(0,o.jsx)(T.A,{value:"",disabled:!0,children:"Loading servers…"}),j.map(e=>(0,o.jsx)(T.A,{value:e.name,children:e.name},e.name))]})]}),(0,o.jsx)(v.A,{label:"Resource URI",value:R,onChange:e=>L("uri",e.target.value),fullWidth:!0,placeholder:"e.g. file:///data/report.md",helperText:"Pick from the list below or paste a URI / filled-in template."}),k&&(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",gap:1,children:[(0,o.jsx)(ez.default,{size:18}),(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",children:"Loading resources…"})]}),I&&(0,o.jsxs)(s.default,{variant:"body2",color:"warning.main",children:["Could not list resources: ",I]}),!k&&!I&&F&&0===C.length&&(0,o.jsx)(s.default,{variant:"body2",color:"text.secondary",children:"This server publishes no resources (you can still paste a URI above)."}),C.length>0&&(0,o.jsx)(eW.A,{dense:!0,sx:{maxHeight:240,overflow:"auto",border:1,borderColor:"divider",borderRadius:1},children:C.map(e=>(0,o.jsxs)(eO.A,{selected:e.uri===R,onClick:()=>L("uri",e.uri),children:[(0,o.jsx)(q.A,{sx:{minWidth:34},children:(0,o.jsx)(ek.A,{fontSize:"small",sx:{color:"#009688"}})}),(0,o.jsx)(Z.A,{primary:e.name||e.uri,secondary:e.name?e.uri:e.description,secondaryTypographyProps:{sx:{wordBreak:"break-all"}}})]},e.uri))})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(v.A,{label:"Artifact name",value:D,onChange:e=>L("runName",e.target.value),fullWidth:!0,error:z,helperText:z?"Letters, digits, _ and - only; must not start with a digit.":"Steps reference it as ${res:NAME}; a producing edge saves the step output under this name."}),D.trim()&&!z&&(0,o.jsxs)(s.default,{variant:"caption",color:"text.secondary",children:['URI at run time: flujo://run/<conversation>/… (named "',D.trim(),'")']})]})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:f,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{if(!p||!y)return;let e={...y.properties};"run"===P?(delete e.boundServer,delete e.uri,delete e.mimeType,e.scope="run",e.runName=D.trim()):(delete e.runName,e.scope="mcp"),x(p.id,{...y,properties:e})},variant:"contained",children:"Save"})]})]}):null},ro=e=>{var t,r,l,s,d;let{open:c,node:u,onClose:p,onSave:x}=e,[y,w]=(0,n.useState)(null);(0,n.useEffect)(()=>{u&&w({...u.data,properties:{...u.data.properties}})},[u,c]);let j=(e,t)=>{w(r=>r?{...r,properties:{...r.properties,[e]:t}}:r)};if(!y)return null;let A=null!=(l=null==(t=y.properties)?void 0:t.topic)?l:"",C=null!=(s=null==(r=y.properties)?void 0:r.payloadTemplate)?s:"";return(0,o.jsxs)(h.A,{open:c,onClose:p,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(m.A,{children:"Signal Node Properties"}),(0,o.jsx)(g.A,{children:(0,o.jsxs)(a.default,{display:"flex",flexDirection:"column",gap:2,mt:1,children:[(0,o.jsx)(v.A,{label:"Label",value:y.label,onChange:e=>w({...y,label:e.target.value}),fullWidth:!0}),(0,o.jsx)(v.A,{label:"Description",value:null!=(d=y.description)?d:"",onChange:e=>w({...y,description:e.target.value}),fullWidth:!0,multiline:!0,minRows:2}),(0,o.jsx)(v.A,{label:"Topic",value:A,onChange:e=>j("topic",e.target.value),fullWidth:!0,required:!0,error:!A.trim(),placeholder:"e.g. review-blocked",helperText:A.trim()?"A free-form shared name (no registry). A planned execution reacts to it via a flow-event trigger with this topic.":"A topic is required — a flow-event trigger listens for this exact name."}),(0,o.jsx)(v.A,{label:"Payload template",value:C,onChange:e=>j("payloadTemplate",e.target.value),fullWidth:!0,multiline:!0,minRows:3,placeholder:"e.g. Review found blockers: ${var:reviewSummary}",helperText:"Emitted as the signal payload. ${var:NAME} is resolved from run variables at emit time."}),(0,o.jsx)(f.A,{severity:"info",children:"When execution reaches this node it emits the topic and continues immediately (fire-and-forget). To emit conditionally, put a conditioned edge into this node. Runaway signal chains are bounded by the trigger’s max chain depth."})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:p,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:()=>{if(!u||!y)return;let e={...y.properties};e.topic="string"==typeof e.topic?e.topic.trim():"",x(u.id,{...y,properties:e})},variant:"contained",children:"Save"})]})]})};var rn=r(31102),rl=r(18581),ra=r(13179),rs=r(90363),ri=r(67063),rd=r(30989);let rc=(0,I.h)("frontend/components/Flow/FlowManager/ImproveFlowDialog"),ru=e=>{let{open:t,onClose:r,currentFlow:l,onImproved:s,initialDescription:d}=e,[c,u]=(0,n.useState)(""),[p,y]=(0,n.useState)([]),[w,j]=(0,n.useState)(""),[A,C]=(0,n.useState)(!1),[S,k]=(0,n.useState)(!1),[N,I]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&u(null!=d?d:"")},[t,d]),(0,n.useEffect)(()=>{if(!t)return;let e=!1;return e8.N.loadModels().then(t=>{e||(y(t),j(e=>{var r,o;return t.some(t=>t.id===e)?e:null!=(o=null==(r=t[0])?void 0:r.id)?o:""}))}).catch(t=>{rc.warn("Failed to load models for the improve dialog",t),e||I("Could not load your models. Configure a model first.")}),()=>{e=!0}},[t]);let M=(0,n.useCallback)(()=>{S||(I(null),r())},[S,r]),P=(0,n.useCallback)(async()=>{I(null),k(!0);try{let e={...l,nodes:[...l.nodes],edges:[...l.edges]},t=await F.g.improveFlow(e,c.trim(),w,{allowInstall:A});if(!t.success)return void I(t.error);rc.info("Flow improved",{flowId:t.flow.id,attempts:t.attempts,errors:t.validation.errorCount,warnings:t.validation.warningCount,installedServers:t.installedServers.length}),u(""),s({flow:t.flow,errorCount:t.validation.errorCount,warningCount:t.validation.warningCount,attempts:t.attempts,installedServers:t.installedServers})}finally{k(!1)}},[l,c,w,A,s]),E=!S&&c.trim().length>0&&!!w;return(0,o.jsxs)(h.A,{open:t,onClose:M,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(m.A,{children:"Improve this flow with AI"}),(0,o.jsxs)(g.A,{children:[(0,o.jsxs)(x.A,{sx:{mb:2},children:["Describe the changes you want — add or remove a step, rewrite a prompt, wire up a tool, rename a node. The model revises the ",(0,o.jsx)("strong",{children:"current"})," flow and the result opens on the canvas as an unsaved change you can review, undo, and save."]}),N&&(0,o.jsx)(f.A,{severity:"error",sx:{mb:2},onClose:()=>I(null),children:N}),(0,o.jsx)(v.A,{autoFocus:!0,fullWidth:!0,multiline:!0,minRows:4,label:"What should change?",placeholder:"e.g. Add a step after the research that emails the summary, and make the research step use the full conversation",value:c,onChange:e=>u(e.target.value),disabled:S,sx:{mb:2}}),(0,o.jsxs)(t$.A,{fullWidth:!0,disabled:S||0===p.length,children:[(0,o.jsx)(tJ.A,{id:"improve-flow-model-label",children:"Generator model"}),(0,o.jsx)(tK.A,{labelId:"improve-flow-model-label",label:"Generator model",value:w,onChange:e=>j(e.target.value),children:p.map(e=>{var t;return(0,o.jsx)(T.A,{value:e.id,children:(null==(t=e.displayName)?void 0:t.trim())||e.name},e.id)})})]}),(0,o.jsx)(tD.A,{sx:{mt:2},control:(0,o.jsx)(t4.A,{checked:A,onChange:e=>C(e.target.checked),disabled:S}),label:"Let the improver install MCP servers it needs (self-improve)"}),A&&(0,o.jsxs)(f.A,{severity:"warning",sx:{mt:1},children:["The improver may ",(0,o.jsx)("strong",{children:"download, install, and run third-party MCP servers"})," from the public registry on this machine — without asking again. It prefers servers that need no API keys, but anything it installs executes real code with your user's permissions. Installed servers stay configured afterwards (remove them on the MCP page)."]}),S&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1.5,mt:2},children:[(0,o.jsx)(ez.default,{size:20}),(0,o.jsx)(x.A,{children:A?"Improving… the model may search the marketplace and install servers (this can take a few minutes).":"Improving… the model revises the flow and FLUJO checks it (this can take up to a minute)."})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:M,disabled:S,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:P,variant:"contained",color:"primary",startIcon:(0,o.jsx)(rs.A,{}),disabled:!E,children:"Improve"})]})]})};var rp=r(77890);let rf=e=>({source:"".concat(e,"-bottom"),target:"".concat(e,"-top")});function rh(e){var t,r,o;return null!=(o=null!=(r=null==(t=e.data)?void 0:t.type)?r:e.type)?o:"unknown"}let rm=(0,I.h)("components/flow/FlowBuilder/index.tsx"),rg=(0,A.Ay)(a.default)(e=>{let{theme:t}=e;return{display:"flex",height:"calc(100vh - 64px)",gap:"16px",padding:"16px",backgroundColor:t.palette.background.default}}),rx=(0,A.Ay)(C.A)(e=>{let{theme:t}=e;return{padding:t.spacing(1),display:"flex",gap:t.spacing(1),borderBottom:"1px solid",borderColor:t.palette.divider,alignItems:"center",marginBottom:t.spacing(1),backgroundColor:t.palette.background.paper,boxShadow:t.shadows[1]}}),rv=(0,A.Ay)(a.default)({flex:1,display:"flex",flexDirection:"column",position:"relative",overflow:"hidden"}),rb=n.forwardRef((e,t)=>{let{initialFlow:r,onSave:l,onDelete:s,allFlows:d}=e;rm.debug("FlowBuilder rendered with initialFlow:",r);let[y,w]=(0,n.useState)((null==r?void 0:r.nodes)||[]),[j,A]=(0,n.useState)(((null==r?void 0:r.edges)||[]).filter(e=>e.source&&e.target&&e.sourceHandle&&e.targetHandle)),[C,I]=(0,n.useState)((null==r?void 0:r.name)||"NewFlow"),[R,D]=(0,n.useState)(null),[L,z]=(0,n.useState)((null==r?void 0:r.description)||""),[W,B]=(0,n.useState)(!1),[_,H]=(0,n.useState)("none"),[G,V]=(0,n.useState)(""),[$,Y]=(0,n.useState)(null),[X,q]=(0,n.useState)(!1),[Z,Q]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(!1),[er,eo]=(0,n.useState)(!1),[en,el]=(0,n.useState)(!1),[ea,es]=(0,n.useState)(!1),[ei,ed]=(0,n.useState)(!1),[ec,eu]=(0,n.useState)(null),[ep,ef]=(0,n.useState)(!1),[eh,em]=(0,n.useState)(null),[eg,ex]=(0,n.useState)(null),[ev,eb]=(0,n.useState)(""),[ey,ew]=(0,n.useState)([]),[eA,eC]=(0,n.useState)(-1),[ek,eT]=(0,n.useState)(!1),[eN,eI]=(0,n.useState)(!1),eM=(0,n.useRef)(null),eP=(0,n.useRef)(!1),eF=(0,n.useRef)(!0),eE=(0,n.useCallback)(e=>e.filter(e=>e.source&&e.target&&e.sourceHandle&&e.targetHandle),[]);(0,n.useEffect)(()=>{if(eF.current=!0,r){w(r.nodes||[]);let e=eE(r.edges||[]);e.length!==r.edges.length&&console.warn("Filtered out ".concat(r.edges.length-e.length," invalid edges")),A(e),I(r.name),z(r.description||""),ew([{nodes:r.nodes||[],edges:e}]),eC(0)}else{let e=F.g.createStartNode();w([e]),A([]),I("NewFlow"),z(""),ew([{nodes:[e],edges:[]}]),eC(0)}},[r]);let eR=e=>JSON.stringify(e,(e,t)=>"selected"===e||"dragging"===e||"measured"===e||"width"===e||"height"===e||"positionAbsolute"===e||"resizing"===e?void 0:t);(0,n.useEffect)(()=>{if(ek)return void eT(!1);if(eF.current){eF.current=!1;return}if(eP.current)return;let e={nodes:[...y],edges:[...j]},t=ey.slice(0,eA+1);(eA<0||eR(e)!==eR(t[eA]))&&(ew([...t,e]),eC(eA+1),eI(!0))},[y,j]),(0,n.useEffect)(()=>{let e=e=>{if(eN)return e.preventDefault(),e.returnValue="",""};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}},[eN]);let eL=e=>e.trim()?/^[\w-]+$/.test(e)?(!r||r&&r.name!==e)&&d.some(t=>t.id!==((null==r?void 0:r.id)||"")&&t.name.toLowerCase()===e.toLowerCase())?"A flow with this name already exists":null:"Flow name can only contain letters, numbers, underscores, and dashes":"Flow name cannot be empty",ez=(0,n.useCallback)(()=>{rm.debug('handleSave: Attempting to save flow "'.concat(C,'"'));let e=eL(C);if(e)return rm.warn("handleSave: Invalid flow name - ".concat(e)),D(e),"invalid-name";let t=[...y];if(0===t.length&&(rm.debug("handleSave: No nodes found, adding a default Start node"),w(t=[F.g.createStartNode()])),r&&r.name!==C)return rm.debug('handleSave: Flow name changed from "'.concat(r.name,'" to "').concat(C,'", opening rename dialog')),H("rename"),V(C),B(!0),"rename-dialog";let o={id:(null==r?void 0:r.id)||(0,P.A)(),name:C,description:L,nodes:t,edges:j};return rm.info('handleSave: Saving flow "'.concat(C,'" with ').concat(t.length," nodes and ").concat(j.length," edges")),l(o),eI(!1),"saved"},[C,L,y,j,r,l,d]);n.useImperativeHandle(t,()=>({requestNavigation:e=>{eN?(eM.current=e,H("unsaved"),B(!0)):e()}}),[eN]);let eW=(0,n.useCallback)(()=>{r?(rm.info('handleDelete: Deleting flow "'.concat(r.name,'" (ID: ').concat(r.id,")")),s(r.id)):rm.warn("handleDelete: Attempted to delete flow but no initialFlow is available")},[r,s]),eO=(0,n.useCallback)(e=>{rm.info("Applying AI-improved flow to the canvas",{flowId:e.flow.id,attempts:e.attempts,errors:e.errorCount,warnings:e.warningCount}),ef(!1),w(e.flow.nodes||[]),A(eE(e.flow.edges||[])),I(e.flow.name),z(e.flow.description||""),D(eL(e.flow.name)),eI(!0);let t=e.installedServers.filter(e=>!e.alreadyExisted),r=t.length>0?" Installed MCP server(s): ".concat(t.map(e=>e.name).join(", "),"."):"";e.errorCount>0?em({severity:"warning",message:"Flow revised with ".concat(e.errorCount," error(s) and ").concat(e.warningCount," warning(s) — use the Check button, fix, then Save.").concat(r)}):e.warningCount>0?em({severity:"info",message:"Flow revised with ".concat(e.warningCount," warning(s) — review the changes, then Save to keep them.").concat(r)}):em({severity:"success",message:"Flow revised — review the changes (Undo reverts them), then Save to keep them.".concat(r)})},[eE]),eB=(0,n.useCallback)(()=>{ex(null);let{flow:e,changes:t}=function(e){var t,r,o,n,l,a,s,i;let d=(null!=(t=null==e?void 0:e.nodes)?t:[]).map(e=>{var t;return{...e,position:{...null!=(t=e.position)?t:{x:0,y:0}},data:{...e.data}}}),c=[...null!=(r=null==e?void 0:e.edges)?r:[]],u={...e,nodes:d,edges:c},p=[],f=function(e,t){let r=e.filter(e=>"mcp"!==e.type&&"resource"!==e.type&&"string"==typeof e.id),o=new Map(r.map(e=>[e.id,e])),n=new Map,l=new Map,a=new Set;for(let e of r)n.set(e.id,0),l.set(e.id,0);let s=(e,t)=>{var r,o;a.add("".concat(e,"->").concat(t)),l.set(e,(null!=(r=l.get(e))?r:0)+1),n.set(t,(null!=(o=n.get(t))?o:0)+1)};for(let e of t)o.has(e.from)&&o.has(e.to)&&e.from!==e.to&&(s(e.from,e.to),e.bidirectional&&s(e.to,e.from));let i=[];for(let e of[...r].sort((e,t)=>e.y-t.y||e.x-t.x)){let t=i[i.length-1];t&&70>=Math.abs(e.y-t[0].y)?t.push(e):i.push([e])}let d=new Map;i.forEach((e,t)=>e.forEach(e=>d.set(e.id,t)));let c=new Map;for(let e=1;e<i.length;e++){let t=i[e],r=t.filter(e=>"subflow"===e.type);if(r.length>=2&&r.length===t.length){let t=i[e-1];if(1===t.length&&"process"===t[0].type)for(let e of r)c.set(e.id,t[0].id)}}let u=[],p=(e,t)=>{var r;if(e===t||a.has("".concat(e,"->").concat(t)))return!1;let n=o.get(e),s=o.get(t);return!!n&&!!s&&null===O(n.type,rf(n.type).source,s.type,rf(s.type).target)&&("subflow"!==n.type||!((null!=(r=l.get(e))?r:0)>=1))},f=(e,t,r,o)=>{u.push({from:e,to:t,bidirectional:r,reason:o}),s(e,t),r&&s(t,e)},h=e=>{var t;let r=null!=(t=d.get(e.id))?t:0;for(let t=r-1;t>=0;t--){let r=i[t].filter(t=>t.id!==e.id&&"finish"!==t.type&&!c.has(t.id));if(0!==r.length){if(1===r.length)return r[0];return r.reduce((t,r)=>Math.abs(r.x-e.x)<Math.abs(t.x-e.x)?r:t)}}return null};for(let e of i)for(let t of e){var m;if("start"===t.type||(null!=(m=n.get(t.id))?m:0)>0)continue;let e=c.get(t.id);if(e){p(e,t.id)&&f(e,t.id,!0,"auto-bidirectional-subflow");continue}let r=h(t);r&&p(r.id,t.id)&&f(r.id,t.id,!1,"auto-connected")}let g=r.filter(e=>"start"===e.type),x=()=>r.filter(e=>{var t;return"start"!==e.type&&"finish"!==e.type&&!c.has(e.id)&&(null!=(t=n.get(e.id))?t:0)===0}),v=null;if(0===g.length){let e=x();if(e.length>0)v={targets:e.map(e=>e.id)};else{let e=r.filter(e=>"finish"!==e.type).sort((e,t)=>e.y-t.y)[0];e&&(v={targets:[e.id]})}}else{let e=g[0];for(let t of x())p(e.id,t.id)&&f(e.id,t.id,!1,"auto-connected")}let b=r.filter(e=>"finish"===e.type),y=()=>r.filter(e=>{var t;return"start"!==e.type&&"finish"!==e.type&&!c.has(e.id)&&(null!=(t=l.get(e.id))?t:0)===0}),w=null;if(0===b.length){let e=y();e.length>0&&(w={sources:e.map(e=>e.id)})}else{let e=b[0];for(let t of y())p(t.id,e.id)&&f(t.id,e.id,!1,"auto-connected")}return{addEdges:u,addStart:v,addFinish:w}}(d.filter(e=>"mcp"!==rh(e)&&"resource"!==rh(e)).map(e=>{var t,r,o,n;return{id:e.id,type:rh(e),x:null!=(o=null==(t=e.position)?void 0:t.x)?o:0,y:null!=(n=null==(r=e.position)?void 0:r.y)?n:0}}),c.filter(e=>!function(e){var t;let r=null==(t=e.data)?void 0:t.edgeType;return"mcp"===r||"resource"===r}(e)).map(e=>{var t;return{from:e.source,to:e.target,bidirectional:(null==(t=e.data)?void 0:t.bidirectional)===!0}})),h=new Map(d.map(e=>[e.id,e])),m=(e,t,r)=>{let o=h.get(e),n=h.get(t);o&&n&&c.push((0,rp.pX)(o,n,r))};for(let e of f.addEdges)m(e.from,e.to,e.bidirectional),p.push({code:e.reason,message:function(e){switch(e){case"auto-connected":return"Connected a disconnected step into the flow.";case"auto-bidirectional-subflow":return"Wired a parallel subflow with a two-way handoff to its orchestrator.";case"auto-added-start":return"Added a Start node.";case"auto-added-finish":return"Added a Finish node."}}(e.reason),nodeId:e.to});if(f.addStart){let e=f.addStart.targets.map(e=>h.get(e)).filter(Boolean).reduce((e,t)=>!e||t.position.y<e.position.y?t:e,null),t=(s={x:null!=(o=null==e?void 0:e.position.x)?o:250,y:(null!=(n=null==e?void 0:e.position.y)?n:150)-150},{id:(0,P.A)(),type:"start",position:s,data:{label:"Start Node",type:"start",properties:{promptTemplate:""}}});for(let e of(d.unshift(t),h.set(t.id,t),f.addStart.targets))m(t.id,e,!1);p.push({code:"auto-added-start",message:"Added a Start node connected to ".concat(f.addStart.targets.length," entry step(s)."),nodeId:t.id})}if(f.addFinish){let e=f.addFinish.sources.map(e=>h.get(e)).filter(Boolean).reduce((e,t)=>!e||t.position.y>e.position.y?t:e,null),t=(i={x:null!=(l=null==e?void 0:e.position.x)?l:250,y:(null!=(a=null==e?void 0:e.position.y)?a:0)+150},{id:(0,P.A)(),type:"finish",position:i,data:{label:"Finish Node",type:"finish",properties:{}}});for(let e of(d.push(t),h.set(t.id,t),f.addFinish.sources))m(e,t.id,!1);p.push({code:"auto-added-finish",message:"Added a Finish node connected from ".concat(f.addFinish.sources.length," final step(s)."),nodeId:t.id})}return{flow:u,changes:p}}({id:(null==r?void 0:r.id)||"",name:C,description:L,nodes:y,edges:j});if(0===t.length)return void em({severity:"info",message:"Nothing to repair — the flow is already wired up."});rm.info("Applying static auto-repair to the canvas (".concat(t.length," change(s))")),w(e.nodes||[]),A(eE(e.edges||[])),eI(!0);let o=t.filter(e=>"auto-added-start"===e.code||"auto-added-finish"===e.code).length,n=t.length-o,l=[];t.some(e=>"auto-added-start"===e.code)&&l.push("added a Start node"),t.some(e=>"auto-added-finish"===e.code)&&l.push("added a Finish node"),n>0&&l.push("connected ".concat(n," step(s)")),em({severity:"success",message:"Repaired the flow — ".concat(l.join(", "),". Review the changes (Undo reverts them), then Save to keep them.")})},[r,C,L,y,j,eE]),e_=(0,n.useCallback)(()=>{ex(null),eb("Repair this flow's wiring so it is runnable, without changing any node's prompt, model, or servers: add a Start node if one is missing (connected to the first step), add a Finish node if one is missing (connected from the last step), and connect any disconnected process/subflow nodes. Read node placement as intent: nodes stacked top-to-bottom are sequential steps, and nodes on the same horizontal line are parallel branches under a shared parent above them."),ef(!0)},[]),eH=(0,n.useCallback)((e,t)=>{rm.debug('handleCopyFlow: Copying flow "'.concat(e.name,'" to "').concat(t,'"'));let r={id:(0,P.A)(),name:t,description:e.description,nodes:e.nodes,edges:e.edges};rm.info('handleCopyFlow: Created copy of flow "'.concat(e.name,'" with new name "').concat(t,'" (').concat(e.nodes.length," nodes, ").concat(e.edges.length," edges)")),l(r)},[l]),eU=()=>{let e=eM.current;eM.current=null,e&&e()},eG=()=>{eM.current=null,B(!1),H("none"),V(""),Y(null)},eV=()=>{let e=eL(G);if(e)return void Y(e);"duplicate"===_?r&&eH(r,G):"rename"===_&&(l({id:(null==r?void 0:r.id)||(0,P.A)(),name:G,description:L,nodes:y,edges:j}),eI(!1),eU()),eG()},e$=eA>0,eJ=eA<ey.length-1,eK=(0,n.useCallback)(()=>{if(e$){rm.debug("handleUndo: Performing undo operation, moving from history index ".concat(eA," to ").concat(eA-1)),eT(!0);let e=eA-1,t=ey[e];w(t.nodes),A(t.edges),eC(e),rm.info("handleUndo: Restored flow state to previous version (".concat(t.nodes.length," nodes, ").concat(t.edges.length," edges)"))}},[ey,eA,e$]),eY=(0,n.useCallback)(()=>{if(eJ){rm.debug("handleRedo: Performing redo operation, moving from history index ".concat(eA," to ").concat(eA+1)),eT(!0);let e=eA+1,t=ey[e];w(t.nodes),A(t.edges),eC(e),rm.info("handleRedo: Restored flow state to next version (".concat(t.nodes.length," nodes, ").concat(t.edges.length," edges)"))}},[ey,eA,eJ]),eX=(0,n.useCallback)(e=>{for(let t of e)"position"===t.type&&(eP.current=!0===t.dragging);w(t=>(0,M._0)(e,t))},[]),eq=(0,n.useCallback)(e=>{rm.debug("onEdgesChange: Processing ".concat(e.length," edge changes")),e.forEach(e=>{"remove"===e.type?rm.info("onEdgesChange: Edge ".concat(e.id," removed")):"select"===e.type&&rm.debug("onEdgesChange: Edge ".concat(e.id," selection changed to ").concat(e.selected))}),A(t=>(0,M.zW)(e,t))},[]),eZ=(0,n.useRef)(null),[eQ,e0]=(0,n.useState)(null),e1=(0,n.useCallback)(()=>{rm.debug("handleAutoAlign: auto-arranging flow nodes"),w(e=>(function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{direction:o="TB",rankSep:n=120,nodeSep:l=80,mcpOffsetX:a=350,mcpStackY:s=120}=r,i=e.filter(e=>"mcp"===e.type),d=e.filter(e=>"resource"===e.type),c=e.filter(e=>"mcp"!==e.type&&"resource"!==e.type);if(c.length<=1)return e;let u=new Set(c.map(e=>e.id)),p=new Map;for(let e of(c.forEach(e=>p.set(e.id,new Set)),t))!(J(e)||K(e))&&e.source!==e.target&&u.has(e.source)&&u.has(e.target)&&p.get(e.source).add(e.target);let f=new Map;c.forEach(e=>f.set(e.id,0));let h=c.length;for(let e=0;e<h;e++){let e=!1;for(let[t,r]of p){let o=f.get(t)+1;for(let t of r)f.get(t)<o&&(f.set(t,o),e=!0)}if(!e)break}let m=new Map;for(let e of c){let t=f.get(e.id),r=m.get(t);r?r.push(e):m.set(t,[e])}let g=[...m.keys()].sort((e,t)=>e-t),x=new Map,v=0;for(let e of g){let t=m.get(e),r=0,a=0;for(let e of t){let{width:t,height:n}=function(e){var t,r,o,n;let l=e.measured;return{width:null!=(r=null!=(t=null==l?void 0:l.width)?t:e.width)?r:240,height:null!=(n=null!=(o=null==l?void 0:l.height)?o:e.height)?n:80}}(e);"TB"===o?(x.set(e.id,{x:r,y:v}),r+=t+l,a=Math.max(a,n)):(x.set(e.id,{x:v,y:r}),r+=n+l,a=Math.max(a,t))}v+=a+n}let b=(e,r,o)=>{let n=new Set(e.map(e=>e.id)),l=new Map;for(let e of t){let t,o;if(!r(e))continue;let a=n.has(e.source),s=n.has(e.target);a&&!s?(t=e.source,o=e.target):s&&!a&&(t=e.target,o=e.source),t&&o&&x.has(o)&&!l.has(t)&&l.set(t,o)}let a=new Map;for(let t of e){var i;let e=l.get(t.id);if(!e)continue;let r=x.get(e),n=null!=(i=a.get(e))?i:0;a.set(e,n+1),x.set(t.id,{x:r.x+o,y:r.y+n*s})}};return b(i,J,a),b(d,K,-a),e.map(e=>{let t=x.get(e.id);return t?{...e,position:t}:e})})(e,j)),requestAnimationFrame(()=>null==eQ?void 0:eQ.fitView({padding:.2}))},[j,eQ]),e2=(0,n.useCallback)((e,t)=>{rm.debug("handleNodeUpdate: Updating node ".concat(e," properties")),w(r=>r.map(r=>r.id===e?(rm.info("handleNodeUpdate: Node ".concat(e," properties updated")),{...r,data:t}):r)),q(!1),Q(!1),et(!1),eo(!1),el(!1),es(!1),ed(!1),eu(null),rm.debug("handleNodeUpdate: Closed property modals")},[]),e5=(0,n.useCallback)(async(e,t)=>{var r;let o=y.find(t=>t.id===e);if(!o)return void rm.warn("handleConnectMcpServer: process node ".concat(e," not found"));let n=[];try{let e=await E.S.listServerTools(t);!e.error&&Array.isArray(e.tools)&&(n=e.tools.map(e=>e.name))}catch(e){rm.warn("handleConnectMcpServer: could not load tools for ".concat(t),e)}let l=j.filter(t=>{var r;return(null==(r=t.data)?void 0:r.edgeType)==="mcp"&&(t.source===e||t.target===e)}).length,a=F.g.createNode("mcp",{x:o.position.x+350,y:o.position.y+120*l});a.data.label=t,a.data.properties={...null!=(r=a.data.properties)?r:{},boundServer:t,enabledTools:n};let s=U({source:e,sourceHandle:"process-right-mcp",target:a.id,targetHandle:"mcp-left"},[...y,a]);w(e=>[...e,a]),A(e=>[...e,s]),rm.info('Connected MCP server "'.concat(t,'" to process node ').concat(e))},[y,j]),e4=(0,n.useCallback)(e=>{rm.debug("Opening properties for node:",e),eu(e),"mcp"===e.data.type?Q(!0):"start"===e.data.type?et(!0):"finish"===e.data.type?eo(!0):"subflow"===e.data.type?el(!0):"resource"===e.data.type?es(!0):"signal"===e.data.type?ed(!0):q(!0)},[]),e6=(0,n.useCallback)(e=>{rm.debug("onDrop: Node dropped on canvas"),e.preventDefault();let t=e.dataTransfer.getData("application/reactflow");if(rm.debug("onDrop: Node type from data transfer: ".concat(t)),!t||!eQ)return void rm.debug("onDrop: Missing required data - type: ".concat(!!t,", reactFlowInstance: ").concat(!!eQ));let r=eQ.screenToFlowPosition({x:e.clientX,y:e.clientY});rm.debug("onDrop: Calculated position: (".concat(r.x,", ").concat(r.y,")"));let o=F.g.createNode(t,r);rm.info("onDrop: Created new ".concat(t," node with ID: ").concat(o.id)),w(e=>[...e.map(e=>({...e,selected:!1})),{...o,selected:!0}]),e4(o),rm.debug("onDrop: Opened properties modal for new node: ".concat(o.id))},[eQ,e4]),e3=(0,n.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect="move"},[]),e8=(0,n.useCallback)(e=>{rm.debug("onInit: ReactFlow instance initialized"),e0(e)},[]);return(0,o.jsxs)(rg,{children:[(0,o.jsx)(eD,{}),(0,o.jsx)(M.Ln,{children:(0,o.jsxs)(rv,{children:[(0,o.jsxs)(rx,{elevation:1,children:[(0,o.jsx)(v.A,{size:"small",label:"Flow Name",value:C,onChange:e=>{let t=e.target.value;I(t),D(eL(t))},sx:{minWidth:300},error:!!R,helperText:R}),(0,o.jsx)(v.A,{size:"small",label:"Description",value:L,onChange:e=>{z(e.target.value),eI(!0)},multiline:!0,maxRows:3,sx:{minWidth:300,flex:1},placeholder:"Optional — shown on the flow card"}),(0,o.jsx)(i.A,{variant:"contained",color:"primary",onClick:ez,startIcon:(0,o.jsx)(rn.A,{}),disabled:!!R,children:"Save Flow"}),(0,o.jsx)(e9,{nodes:y,edges:j}),(0,o.jsx)(u.A,{title:"Auto-arrange nodes into a clean layout",children:(0,o.jsx)("span",{children:(0,o.jsx)(i.A,{variant:"outlined",color:"primary",onClick:e1,startIcon:(0,o.jsx)(eS.A,{}),disabled:y.length<=1,children:"Auto-Align"})})}),(0,o.jsx)(u.A,{title:"Add a missing Start/Finish and connect disconnected nodes",children:(0,o.jsxs)(S.A,{variant:"outlined",color:"primary",disabled:0===y.length,children:[(0,o.jsx)(i.A,{onClick:eB,startIcon:(0,o.jsx)(ri.A,{}),children:"Repair"}),(0,o.jsx)(i.A,{size:"small",onClick:e=>ex(e.currentTarget),"aria-label":"Repair options",children:(0,o.jsx)(rd.A,{})})]})}),(0,o.jsxs)(k.A,{anchorEl:eg,open:!!eg,onClose:()=>ex(null),children:[(0,o.jsx)(T.A,{onClick:eB,children:"Repair automatically (no model)"}),(0,o.jsx)(T.A,{onClick:e_,children:"Repair with AI…"})]}),r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{variant:"outlined",color:"secondary",onClick:()=>{eb(""),ef(!0)},startIcon:(0,o.jsx)(rs.A,{}),"data-tour":"improve-flow",children:"AI-Improve"}),(0,o.jsx)(i.A,{variant:"outlined",color:"primary",onClick:()=>{H("duplicate"),V("".concat(r.name,"_copy")),B(!0)},children:"Copy Flow"}),(0,o.jsx)(i.A,{variant:"outlined",color:"error",onClick:eW,children:"Delete Flow"})]}),(0,o.jsx)(N.A,{orientation:"vertical",flexItem:!0}),(0,o.jsx)(c.A,{onClick:eK,disabled:!e$,color:"primary",size:"small",children:(0,o.jsx)(rl.A,{})}),(0,o.jsx)(c.A,{onClick:eY,disabled:!eJ,color:"primary",size:"small",children:(0,o.jsx)(ra.A,{})}),(0,o.jsx)(a.default,{sx:{flex:1}})]}),(0,o.jsx)(p.A,{in:!!eh,unmountOnExit:!0,children:eh&&(0,o.jsx)(f.A,{severity:eh.severity,onClose:()=>em(null),sx:{mb:1},children:eh.message})}),(0,o.jsx)(a.default,{sx:{flex:1,position:"relative"},children:(0,o.jsx)(ej,{ref:eZ,nodes:y,edges:j,onNodesChange:eX,onEdgesChange:eq,onDrop:e6,onDragOver:e3,onInit:e8,reactFlowWrapper:eZ,onEditNode:e4})})]})}),(0,o.jsx)(tq,{open:X,node:ec,onClose:()=>q(!1),onSave:e2,flowEdges:j,flowNodes:y,flowId:null==r?void 0:r.id,onConnectMcpServer:e=>{ec&&e5(ec.id,e)}}),(0,o.jsx)(t1,{open:Z,node:ec,onClose:()=>Q(!1),onSave:e2}),(0,o.jsx)(t2,{open:ee,node:ec,onClose:()=>et(!1),onSave:e2}),(0,o.jsx)(t5,{open:er,node:ec,onClose:()=>eo(!1),onSave:e2}),(0,o.jsx)(t7,{open:en,node:ec,onClose:()=>el(!1),onSave:e2,flowId:null==r?void 0:r.id}),(0,o.jsx)(rr,{open:ea,node:ec,onClose:()=>es(!1),onSave:e2}),(0,o.jsx)(ro,{open:ei,node:ec,onClose:()=>ed(!1),onSave:e2}),(0,o.jsx)(ru,{open:ep,onClose:()=>ef(!1),currentFlow:{id:(null==r?void 0:r.id)||"",name:C,description:L,nodes:y,edges:j},onImproved:eO,initialDescription:ev}),(0,o.jsxs)(h.A,{open:W,onClose:eG,children:[(0,o.jsx)(m.A,{children:"duplicate"===_?"Copy Flow":"rename"===_?"Rename Flow":"Unsaved Changes"}),(0,o.jsx)(g.A,{children:"unsaved"===_?(0,o.jsx)(x.A,{children:"You have unsaved changes in the current flow. What would you like to do?"}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(x.A,{children:"duplicate"===_?"Enter a name for the copied flow:":"You are changing the name of this flow. Do you want to rename it or create a copy with the new name?"}),(0,o.jsx)(v.A,{autoFocus:!0,margin:"dense",label:"Flow Name",type:"text",fullWidth:!0,value:G,onChange:e=>{let t=e.target.value;V(t),Y(eL(t))},error:!!$,helperText:$,sx:{mt:2}})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:eG,children:"Cancel"}),"unsaved"===_&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{onClick:()=>{eI(!1),eU(),eG()},color:"error",children:"Discard Changes"}),(0,o.jsx)(i.A,{onClick:()=>{let e=ez();"saved"===e?(eU(),eG()):"invalid-name"===e&&eG()},variant:"contained",color:"primary",children:"Save Changes"})]}),"rename"===_&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{onClick:()=>{let e=eL(G);if(e)return void Y(e);r&&eH(r,G),eG()},children:"Copy"}),(0,o.jsx)(i.A,{onClick:eV,variant:"contained",color:"primary",disabled:!!$,children:"Rename"})]}),"duplicate"===_&&(0,o.jsx)(i.A,{onClick:eV,variant:"contained",color:"primary",disabled:!!$,children:"Copy"})]})]})]})});rb.displayName="FlowBuilder";let ry=(0,I.h)("frontend/components/Flow/FlowManager/GenerateFlowDialog"),rw=e=>{let{open:t,onClose:r,onGenerated:l}=e,[s,d]=(0,n.useState)(""),[c,u]=(0,n.useState)([]),[p,y]=(0,n.useState)(""),[w,A]=(0,n.useState)(!1),[C,S]=(0,n.useState)(!1),[k,N]=(0,n.useState)(2),[I,M]=(0,n.useState)(!1),[P,E]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!t)return;let e=!1;return e8.N.loadModels().then(t=>{e||(u(t),y(e=>{var r,o;return t.some(t=>t.id===e)?e:null!=(o=null==(r=t[0])?void 0:r.id)?o:""}))}).catch(t=>{ry.warn("Failed to load models for the generate dialog",t),e||E("Could not load your models. Configure a model first.")}),()=>{e=!0}},[t]);let R=(0,n.useCallback)(()=>{I||(E(null),r())},[I,r]),D=(0,n.useCallback)(async()=>{E(null),M(!0);try{let e=await F.g.generateFlow(s.trim(),p,{allowInstall:w,allowSubflows:C,...C?{maxDepth:k}:{}});if(!e.success)return void E(e.error);ry.info("Draft flow generated",{flowId:e.flow.id,flowCount:e.flows.length,attempts:e.attempts,errors:e.validation.errorCount,warnings:e.validation.warningCount,installedServers:e.installedServers.length}),d(""),l({flow:e.flow,flows:e.flows.map(e=>e.flow),rootFlowId:e.rootFlowId,errorCount:e.validation.errorCount,warningCount:e.validation.warningCount,attempts:e.attempts,installedServers:e.installedServers})}finally{M(!1)}},[s,p,w,C,k,l]),L=!I&&s.trim().length>0&&!!p;return(0,o.jsxs)(h.A,{open:t,onClose:R,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(m.A,{children:"Generate a flow"}),(0,o.jsxs)(g.A,{children:[(0,o.jsx)(x.A,{sx:{mb:2},children:"Describe what the flow should do — which steps, which tools, what the result is. The generated flow opens in the builder as a draft for you to review before saving."}),P&&(0,o.jsx)(f.A,{severity:"error",sx:{mb:2},onClose:()=>E(null),children:P}),(0,o.jsx)(v.A,{autoFocus:!0,fullWidth:!0,multiline:!0,minRows:4,label:"What should this flow do?",placeholder:"e.g. Research a topic on the web, then summarize the findings as bullet points",value:s,onChange:e=>d(e.target.value),disabled:I,sx:{mb:2}}),(0,o.jsxs)(t$.A,{fullWidth:!0,disabled:I||0===c.length,children:[(0,o.jsx)(tJ.A,{id:"generate-flow-model-label",children:"Generator model"}),(0,o.jsx)(tK.A,{labelId:"generate-flow-model-label",label:"Generator model",value:p,onChange:e=>y(e.target.value),children:c.map(e=>{var t;return(0,o.jsx)(T.A,{value:e.id,children:(null==(t=e.displayName)?void 0:t.trim())||e.name},e.id)})})]}),(0,o.jsx)(tD.A,{sx:{mt:2},control:(0,o.jsx)(t4.A,{checked:w,onChange:e=>A(e.target.checked),disabled:I}),label:"Let the generator install MCP servers it needs (self-improve)"}),(0,o.jsx)(tD.A,{sx:{mt:1,display:"flex"},control:(0,o.jsx)(t4.A,{checked:C,onChange:e=>S(e.target.checked),disabled:I}),label:"Allow multi-level flows (auto-generate nested subflows)"}),C&&(0,o.jsxs)(a.default,{sx:{mt:1,ml:4,display:"flex",flexDirection:"column",gap:1},children:[(0,o.jsxs)(t$.A,{sx:{maxWidth:220},size:"small",disabled:I,children:[(0,o.jsx)(tJ.A,{id:"generate-flow-depth-label",children:"Max nesting depth"}),(0,o.jsxs)(tK.A,{labelId:"generate-flow-depth-label",label:"Max nesting depth",value:k,onChange:e=>N(Number(e.target.value)),children:[(0,o.jsx)(T.A,{value:1,children:"1 level"}),(0,o.jsx)(T.A,{value:2,children:"2 levels"}),(0,o.jsx)(T.A,{value:3,children:"3 levels"})]})]}),(0,o.jsx)(f.A,{severity:"info",children:"The generator can design subflows that are themselves generated (up to a few flows total). This is slower and uses more tokens. You review the whole bundle before anything is saved."})]}),w&&(0,o.jsxs)(f.A,{severity:"warning",sx:{mt:1},children:["The generator may ",(0,o.jsx)("strong",{children:"download, install, and run third-party MCP servers"})," from the public registry on this machine. It prefers servers that need no API keys, but anything it installs executes real code with your user's permissions. The ",(0,o.jsx)("strong",{children:"exact command and arguments"})," of every install are recorded (audited) before it runs, and each installed server is listed in the post-generation summary so you can review — and remove (on the MCP page) — exactly what was added."]}),I&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1.5,mt:2},children:[(0,o.jsx)(ez.default,{size:20}),(0,o.jsx)(x.A,{children:w?"Generating… the model may search the marketplace and install servers (this can take a few minutes).":"Generating… the model designs the flow and FLUJO checks it (this can take up to a minute)."})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:R,disabled:I,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:D,variant:"contained",color:"primary",startIcon:(0,o.jsx)(j.A,{}),disabled:!L,children:"Generate"})]})]})};var rj=r(60530),rA=r(15712),rC=r(64419),rS=r(98405),rk=r(7302),rT=r(70822),rN=r(28466),rI=r(3986),rM=r(94885),rP=r(15686),rF=r(91665),rE=r(22573),rR=r(38459),rD=r(88377),rL=r(97104);let rz=(0,I.h)("components/Flow/FlowDashboard/FlowDashboard");function rW(e,t){return e+Math.round(255*t).toString(16).padStart(2,"0")}let rO=e=>{let{flows:t,selectedFlow:r,onSelectFlow:d,onDeleteFlow:u,onCopyFlow:p,onEditFlow:f,onCreateFlow:h,onSetFolder:m,onToggleFavorite:g,isLoading:x=!1}=e,[b,y]=(0,n.useState)(""),[j,A]=(0,rL.Xk)("flujo-ui:flows:sort","name-asc"),[S,I]=(0,rL.Xk)("flujo-ui:flows:view","grid"),[M,P]=(0,n.useState)(null),[F,E]=(0,rL.Xk)("flujo-ui:flows:group","none"),[R,D]=(0,n.useState)(null),[L,z]=(0,rL.Xk)("flujo-ui:flows:collapsed",[]),W=(0,n.useMemo)(()=>new Set(L),[L]),[O,B]=(0,n.useState)({});(0,n.useEffect)(()=>{let e=!1;return(async()=>{let t={};try{let e=await fetch("/api/model");if(e.ok){let r=await e.json();Array.isArray(r)&&(t.models=r)}}catch(e){rz.warn("Could not load models for flow badges",e)}try{let e=await fetch("/api/mcp/servers");if(e.ok){let r=await e.json();Array.isArray(r)&&(t.servers=r.map(e=>({name:e.name,status:e.disabled?"disabled":void 0})))}}catch(e){rz.warn("Could not load servers for flow badges",e)}e||B(t)})(),()=>{e=!0}},[]);let _=(0,n.useMemo)(()=>{let e={};for(let r of t)try{e[r.id]=e3(r,O)}catch(e){rz.warn("Failed to validate flow for badge",{flowId:r.id,error:e})}return e},[t,O]),H=(0,l.A)(),U=(0,rA.A)(H.breakpoints.down("sm")),G=(0,rA.A)(H.breakpoints.down("md")),V=()=>{P(null)},$=e=>{A(e),V()},J=e=>{E(e),D(null)},K=(0,n.useMemo)(()=>{rz.debug("Filtering and sorting flows",{searchTerm:b,sortOption:j});let e=t;if(""!==b.trim()){let r=b.toLowerCase();e=t.filter(e=>e.name.toLowerCase().includes(r))}return(0,rD.NP)(e,j)},[t,b,j]),Y=(0,n.useMemo)(()=>(0,rR.yF)(t,e=>e.folder),[t]),X=(0,n.useMemo)(()=>"folder"===F?(0,rR.Je)(K,e=>e.folder):"sort"===F?(0,rR.Az)(K,e=>(0,rD.ts)(e,j)):[],[F,K,j]),Q=e=>(0,o.jsx)(te.Ay,{container:!0,spacing:2,children:e.map(e=>(0,o.jsx)(te.Ay,{item:!0,xs:12,sm:"compact"===S?12:6,md:"compact"===S?12:3==("compact"===S||U?1:G?2:3)?4:6,children:(0,o.jsx)(t3.A,{flow:e,selected:r===e.id,onSelect:d,onDelete:u,onCopy:p,onEdit:f,onSetFolder:m,onToggleFavorite:g,folders:Y,validation:_[e.id]})},e.id))});return(0,o.jsxs)(a.default,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,o.jsx)(C.A,{elevation:1,sx:{mb:2,p:1},children:(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},gap:1,alignItems:{xs:"stretch",sm:"center"},justifyContent:"space-between"},children:[(0,o.jsx)(v.A,{placeholder:"Search flows...",variant:"outlined",size:"small",fullWidth:!0,value:b,onChange:e=>{y(e.target.value)},InputProps:{startAdornment:(0,o.jsx)(tb.A,{position:"start",children:(0,o.jsx)(tC.A,{fontSize:"small"})})},sx:{maxWidth:{sm:300}}}),(0,o.jsxs)(a.default,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",backgroundColor:H.palette.background.default,borderRadius:1,border:"1px solid ".concat(H.palette.divider),overflow:"hidden"},children:[(0,o.jsx)(c.A,{size:"small",onClick:()=>I("grid"),color:"grid"===S?"primary":"default",sx:{borderRadius:0,backgroundColor:"grid"===S?rW(H.palette.primary.main,.1):"transparent"},children:(0,o.jsx)(rT.A,{fontSize:"small"})}),(0,o.jsx)(c.A,{size:"small",onClick:()=>I("compact"),color:"compact"===S?"primary":"default",sx:{borderRadius:0,backgroundColor:"compact"===S?rW(H.palette.primary.main,.1):"transparent"},children:(0,o.jsx)(rk.A,{fontSize:"small"})})]}),(0,o.jsx)(c.A,{size:"small",onClick:e=>D(e.currentTarget),color:"none"!==F?"primary":"default",sx:{border:"1px solid ".concat(H.palette.divider),backgroundColor:H.palette.background.default},title:"Group cards",children:(0,o.jsx)(rM.A,{fontSize:"small"})}),(0,o.jsx)(c.A,{size:"small",onClick:e=>{P(e.currentTarget)},sx:{border:"1px solid ".concat(H.palette.divider),backgroundColor:H.palette.background.default},children:(0,o.jsx)(rC.A,{fontSize:"small"})})]})]})}),(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"space-between",mb:2,px:1},children:[(0,o.jsxs)(s.default,{variant:"body2",color:"textSecondary",children:[K.length," of ",t.length," flows",b&&' matching "'.concat(b,'"')]}),(0,o.jsxs)(s.default,{variant:"body2",color:"textSecondary",children:["Sorted by: ","name-asc"===j?"Name (A-Z)":"name-desc"===j?"Name (Z-A)":"newest"===j?"Newest first":"oldest"===j?"Oldest first":"most-nodes"===j?"Most nodes":"Least nodes"]})]}),(0,o.jsx)(a.default,{sx:{flex:1,overflow:"auto",px:1,pb:2},children:x?(0,o.jsx)(te.Ay,{container:!0,spacing:2,children:Array(6).fill(0).map((e,t)=>(0,o.jsx)(te.Ay,{item:!0,xs:12,sm:"compact"===S?12:6,md:"compact"===S?12:4,children:(0,o.jsx)(t3.o,{})},"skeleton-".concat(t)))}):K.length>0?"none"===F?Q(K):X.map(e=>(0,o.jsx)(rE.A,{label:e.label,count:e.items.length,expanded:!W.has(e.key),onToggle:()=>(e=>{z(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e.key),showFolderIcon:"folder"===F,children:Q(e.items)},e.key)):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",p:4,backgroundColor:H.palette.background.paper,borderRadius:1,border:"1px dashed ".concat(H.palette.divider),height:"100%",minHeight:200},children:[(0,o.jsx)(s.default,{variant:"h6",gutterBottom:!0,color:"textSecondary",children:"No flows found"}),b?(0,o.jsxs)(s.default,{variant:"body2",color:"textSecondary",align:"center",children:["No flows match your search criteria.",(0,o.jsxs)(a.default,{component:"span",display:"block",mt:1,children:["Try a different search term or ",(0,o.jsx)(i.A,{size:"small",onClick:()=>y(""),children:"clear the search"})]})]}):(0,o.jsxs)(s.default,{variant:"body2",color:"textSecondary",align:"center",children:["Get started by creating your first flow.",h&&(0,o.jsx)(a.default,{component:"span",display:"block",mt:2,children:(0,o.jsx)(i.A,{variant:"contained",color:"primary",startIcon:(0,o.jsx)(w.A,{}),onClick:h,children:"Create New Flow"})})]})]})}),(0,o.jsxs)(k.A,{anchorEl:R,open:!!R,onClose:()=>D(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[(0,o.jsxs)(T.A,{selected:"none"===F,onClick:()=>J("none"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rP.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"No grouping"})]}),(0,o.jsxs)(T.A,{selected:"folder"===F,onClick:()=>J("folder"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rF.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"By folder"})]}),(0,o.jsxs)(T.A,{selected:"sort"===F,onClick:()=>J("sort"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rM.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"By sort setting"})]})]}),(0,o.jsxs)(k.A,{anchorEl:M,open:!!M,onClose:V,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[(0,o.jsxs)(T.A,{onClick:()=>$("name-asc"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rN.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"Name (A-Z)"})]}),(0,o.jsxs)(T.A,{onClick:()=>$("name-desc"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rN.A,{fontSize:"small",sx:{transform:"scaleX(-1)"}})}),(0,o.jsx)(Z.A,{primary:"Name (Z-A)"})]}),(0,o.jsx)(N.A,{}),(0,o.jsxs)(T.A,{onClick:()=>$("newest"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rI.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"Newest first"})]}),(0,o.jsxs)(T.A,{onClick:()=>$("oldest"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rI.A,{fontSize:"small",sx:{transform:"scaleX(-1)"}})}),(0,o.jsx)(Z.A,{primary:"Oldest first"})]}),(0,o.jsx)(N.A,{}),(0,o.jsxs)(T.A,{onClick:()=>$("most-nodes"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rS.A,{fontSize:"small"})}),(0,o.jsx)(Z.A,{primary:"Most nodes"})]}),(0,o.jsxs)(T.A,{onClick:()=>$("least-nodes"),children:[(0,o.jsx)(q.A,{children:(0,o.jsx)(rS.A,{fontSize:"small",sx:{transform:"scaleY(-1)"}})}),(0,o.jsx)(Z.A,{primary:"Least nodes"})]})]})]})},rB=(0,I.h)("app/flows/page"),r_=()=>{var e;rB.debug("Rendering FlowsPage"),(0,l.A)();let[t,r]=(0,n.useState)([]),[A,C]=(0,n.useState)(null),[S,k]=(0,n.useState)(!0),[T,N]=(0,n.useState)(!1),I=(0,n.useRef)(null),[M,E]=(0,n.useState)(null),[R,D]=(0,n.useState)([]),[L,z]=(0,n.useState)(!1),[W,O]=(0,n.useState)(!1),[B,_]=(0,n.useState)(null),[H,U]=(0,n.useState)(""),[G,V]=(0,n.useState)(null),[$,J]=(0,n.useState)({open:!1,message:"",severity:"info"});(0,n.useEffect)(()=>{rB.info("Loading flows"),(async()=>{k(!0);try{let e=await F.g.loadFlows();rB.debug("Flows loaded successfully",{count:e.length}),r(e),A&&(e.some(e=>e.id===A)||(null==M?void 0:M.id)===A||(rB.warn("Previously selected flow no longer exists",{flowId:A}),C(null),N(!1),X("The previously selected flow is no longer available","warning")))}catch(e){rB.error("Error loading flows",e),X("Failed to load flows","error")}finally{k(!1)}})()},[A,M]);let K=(0,n.useCallback)(e=>{rB.debug("Flow selected",{flowId:e}),C(e),N(!0)},[]),Y=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(Y.current||S)return;let e=new URLSearchParams(window.location.search).get("flow");if(!e){Y.current=!0;return}t.some(t=>t.id===e)&&(Y.current=!0,K(e))},[S,t,K]),(0,n.useEffect)(()=>{if(!(T&&A))return;let e=e=>{I.current?I.current.requestNavigation(e):e()};return(0,rj.QO)(e),()=>(0,rj.bH)(e)},[T,A]);let X=(0,n.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info";rB.debug("Showing snackbar",{message:e,severity:t}),J({open:!0,message:e,severity:t})},[]),q=(0,n.useCallback)(()=>{rB.debug("Returning to dashboard");let e=()=>{if(N(!1),M&&M.id===A){let e=R.length>0;E(null),D([]),C(null),X(e?"Generated draft (and its subflows) discarded":"Generated draft discarded","info")}};I.current?I.current.requestNavigation(e):e()},[M,R,A,X]),Z=(0,n.useCallback)(()=>{J(e=>({...e,open:!1}))},[]);(0,n.useEffect)(()=>{if(!$.open||"error"===$.severity)return;let e=setTimeout(()=>{J(e=>({...e,open:!1}))},6e3);return()=>clearTimeout(e)},[$.open,$.message,$.severity]);let Q=(0,n.useCallback)(e=>(rB.debug("Validating flow name",{name:e}),e.trim())?/^[\w-]+$/.test(e)?t.some(t=>t.name.toLowerCase()===e.toLowerCase())?(rB.debug("Flow name validation failed: duplicate name"),"A flow with this name already exists"):(rB.debug("Flow name validation passed"),null):(rB.debug("Flow name validation failed: invalid characters"),"Flow name can only contain letters, numbers, underscores, and dashes"):(rB.debug("Flow name validation failed: empty name"),"Flow name cannot be empty"),[t]),ee=async e=>{rB.info("Saving flow",{flowId:e.id,flowName:e.name});try{if((null==M?void 0:M.id)===e.id&&R.length>0){for(let e of(rB.info("Persisting generated subflow descendants before the root",{count:R.length}),R)){let r=t.some(t=>t.id===e.id)?await F.g.updateFlow(e):await F.g.addFlow(e);if(!r.success){rB.error("Failed to save a generated subflow",{error:r.error,childId:e.id}),X(r.error||"Failed to save a generated subflow","error");return}}r(e=>{let t=new Set(e.map(e=>e.id)),r=R.filter(e=>!t.has(e.id));return r.length?[...e,...r]:e}),D([])}let o=t.some(t=>t.id===e.id)?await F.g.updateFlow(e):await F.g.addFlow(e);if(!o.success){rB.error("Failed to save flow",{error:o.error}),X(o.error||"Failed to save flow","error");return}rB.debug("Flow saved successfully"),r(t=>{let r=t.findIndex(t=>t.id===e.id);if(!(r>=0))return rB.debug("Adding new flow to state"),[...t,e];{rB.debug("Updating existing flow in state");let o=[...t];return o[r]=e,o}}),(null==M?void 0:M.id)===e.id&&E(null),C(e.id),X("Flow saved successfully","success")}catch(e){rB.error("Error saving flow",e),X("Failed to save flow","error")}},et=async e=>{rB.info("Deleting flow",{flowId:e});try{await F.g.deleteFlow(e),rB.debug("Flow deleted successfully"),r(t=>t.filter(t=>t.id!==e)),A===e&&(rB.debug("Clearing selected flow as it was deleted"),C(null),N(!1)),X("Flow deleted","success")}catch(e){rB.error("Error deleting flow",e),X("Failed to delete flow","error")}},er=(0,n.useCallback)(async(e,o)=>{rB.info("Setting flow folder",{flowId:e,folder:o});let n=t.find(t=>t.id===e);if(!n)return void rB.warn("Flow to move not found",{flowId:e});let l={...n,folder:o&&o.trim()?o.trim():void 0};try{let t=await F.g.updateFlow(l);if(!t.success)return void X(t.error||"Failed to move flow to folder","error");r(t=>t.map(t=>t.id===e?l:t)),X(l.folder?'Moved to "'.concat(l.folder,'"'):"Removed from folder","success")}catch(e){rB.error("Error setting flow folder",e),X("Failed to move flow to folder","error")}},[t,X]),eo=(0,n.useCallback)(async e=>{rB.info("Toggling flow favorite",{flowId:e});let o=t.find(t=>t.id===e);if(!o)return void rB.warn("Flow to favorite not found",{flowId:e});let n=!o.favorite,l={...o,favorite:n||void 0};try{let t=await F.g.updateFlow(l);if(!t.success)return void X(t.error||"Failed to update favorite","error");r(t=>t.map(t=>t.id===e?l:t)),X(n?"Added to favorites":"Removed from favorites","success")}catch(e){rB.error("Error toggling flow favorite",e),X("Failed to update favorite","error")}},[t,X]),en=e=>{rB.info("Copying flow",{flowId:e});let r=t.find(t=>t.id===e);r?(rB.debug("Found flow to copy",{flowName:r.name}),_(r),U("".concat(r.name,"_copy")),O(!0)):(rB.warn("Flow to copy not found",{flowId:e}),X("Flow not found","error"))},el=()=>{rB.debug("Closing copy flow dialog"),O(!1),_(null),U(""),V(null)},ea=async()=>{if(rB.info("Confirming flow copy"),!B){rB.warn("No flow to copy"),X("No flow selected to copy","error");return}let e=Q(H);if(e){rB.debug("Flow name validation failed",{error:e}),V(e);return}let t=(0,P.A)();rB.debug("Creating new flow from copy",{newId:t,newName:H});let r={id:t,name:H,description:B.description,nodes:B.nodes,edges:B.edges};await ee(r),el(),rB.debug("Selecting newly copied flow"),C(r.id),N(!0),X('Created a copy named "'.concat(H,'"'),"success")},es=(0,n.useCallback)(e=>{var t,r,o;rB.info("Opening generated draft flow",{flowId:e.flow.id,attempts:e.attempts,errors:e.errorCount,warnings:e.warningCount}),z(!1);let n=(null!=(r=e.flows)?r:[]).filter(t=>t.id!==e.rootFlowId);E(e.flow),D(n),C(e.flow.id),N(!0);let l=null!=(o=null==(t=e.installedServers)?void 0:t.filter(e=>!e.alreadyExisted))?o:[],a=l.length>0?" Installed MCP server(s): ".concat(l.map(e=>e.name).join(", "),"."):"",s=n.length>0?" Includes ".concat(n.length," auto-generated subflow(s) that save with it."):"";e.errorCount>0?X("Draft generated with ".concat(e.errorCount," error(s) and ").concat(e.warningCount," warning(s) — use the Check button, fix, then save.").concat(s).concat(a),"warning"):e.warningCount>0?X("Draft generated with ".concat(e.warningCount," warning(s) — review, then save to keep it.").concat(s).concat(a),"info"):X("Flow drafted — review it and save to keep it.".concat(s).concat(a),"success")},[X]),ei=async()=>{rB.info("Creating new flow");let e="NewFlow",r=e,o=1;for(;t.some(e=>e.name===r);)r="".concat(e).concat(o),o++;let n=F.g.createNewFlow(r);await ee(n),N(!0),X("New flow created","success")};return(0,o.jsxs)(a.default,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,o.jsxs)(a.default,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:1,borderColor:"divider"},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[T&&A&&(0,o.jsx)(c.A,{color:"primary",onClick:q,sx:{mr:1},children:(0,o.jsx)(y.A,{})}),(0,o.jsx)(a.default,{children:(0,o.jsx)(s.default,{variant:"h5",children:T&&A?(null==M?void 0:M.id)===A?"Editing: ".concat(M.name," (unsaved draft)"):"Editing: ".concat((null==(e=t.find(e=>e.id===A))?void 0:e.name)||"Flow"):"Flow Dashboard"})})]}),!T&&(0,o.jsxs)(a.default,{sx:{display:"flex",gap:1},children:[(0,o.jsx)(u.A,{title:"Describe a flow in plain language and let a model draft it",children:(0,o.jsx)(i.A,{variant:"outlined",color:"primary",startIcon:(0,o.jsx)(j.A,{}),onClick:()=>z(!0),"data-tour":"generate-flow",children:"Generate Flow"})}),(0,o.jsx)(u.A,{title:"Create a new flow with a starter template",children:(0,o.jsx)(i.A,{variant:"contained",color:"primary",startIcon:(0,o.jsx)(w.A,{}),onClick:ei,"data-tour":"new-flow",children:"New Flow"})})]})]}),(0,o.jsx)(p.A,{in:$.open,unmountOnExit:!0,children:(0,o.jsx)(f.A,{severity:$.severity,onClose:Z,sx:{borderRadius:0},children:$.message})}),(0,o.jsx)(a.default,{sx:{flex:1,overflow:"hidden"},children:(()=>{if(T&&A){var e;let r=null!=(e=t.find(e=>e.id===A))?e:(null==M?void 0:M.id)===A?M:void 0;return r?(0,o.jsx)(d.A,{in:!0,timeout:300,children:(0,o.jsx)(a.default,{sx:{height:"100%"},children:(0,o.jsx)(rb,{ref:I,initialFlow:r,onSave:ee,onDelete:et,allFlows:t},A)})}):(0,o.jsxs)(a.default,{sx:{p:4,textAlign:"center"},children:[(0,o.jsx)(s.default,{variant:"h6",color:"error",children:"Selected flow not found"}),(0,o.jsx)(i.A,{variant:"contained",onClick:q,sx:{mt:2},children:"Back to Dashboard"})]})}return(0,o.jsx)(d.A,{in:!0,timeout:300,children:(0,o.jsx)(a.default,{sx:{height:"100%"},children:(0,o.jsx)(rO,{flows:t,selectedFlow:A,onSelectFlow:K,onDeleteFlow:et,onCopyFlow:en,onCreateFlow:ei,onSetFolder:er,onToggleFavorite:eo,isLoading:S})})})})()}),(0,o.jsxs)(h.A,{open:W,onClose:el,children:[(0,o.jsx)(m.A,{children:"Copy Flow"}),(0,o.jsxs)(g.A,{children:[(0,o.jsx)(x.A,{children:"Enter a name for the copied flow:"}),(0,o.jsx)(v.A,{autoFocus:!0,margin:"dense",label:"Flow Name",type:"text",fullWidth:!0,value:H,onChange:e=>{let t=e.target.value;rB.debug("Flow name changed",{name:t}),U(t),V(Q(t))},error:!!G,helperText:G})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(i.A,{onClick:el,children:"Cancel"}),(0,o.jsx)(i.A,{onClick:ea,variant:"contained",color:"primary",disabled:!!G,children:"Copy"})]})]}),(0,o.jsx)(rw,{open:L,onClose:()=>z(!1),onGenerated:es})]})}},60530:(e,t,r)=>{"use strict";r.d(t,{L_:()=>a,QO:()=>n,bH:()=>l});let o=null;function n(e){o=e}function l(e){o===e&&(o=null)}function a(e){return!!o&&(o(e),!0)}},61033:(e,t,r)=>{"use strict";r.d(t,{A$:()=>c,X8:()=>s,YP:()=>u,js:()=>d});let o="_-_-_",n=/^(tool|resource):(.+)$/,l=/\$\{((?:tool|resource):[^}]+|_-_-_[^}]+)\}/g;function a(e,t){return"".concat(e,"__").concat(t)}function s(e,t,r){return"${".concat(e,":").concat(a(t,r),"}")}function i(e){let t=n.exec(e);if(t){let e=t[1],r=function(e){let t=e.indexOf("__");if(t<=0)return null;let r=e.slice(t+2);return r?{server:e.slice(0,t),name:r}:null}(t[2]);return r?{kind:e,server:r.server,name:r.name}:null}if(e.startsWith(o)){let t=e.split(o);if(3===t.length&&t[1]&&t[2])return{kind:"tool",server:t[1],name:t[2]}}return null}function d(e){return e.startsWith("${")&&e.endsWith("}")?i(e.slice(2,-1)):null}function c(e){let t,r=[];for(l.lastIndex=0;null!==(t=l.exec(e));){let e=i(t[1]);e&&r.push({...e,fullMatch:t[0],index:t.index})}return r}function u(e){return"tool"===e.kind&&"handoff"===e.server?"handoff:".concat(e.name):"".concat(e.kind,":").concat(a(e.server,e.name))}},61267:(e,t,r)=>{"use strict";r.d(t,{A:()=>L});var o=r(95155),n=r(12115),l=r(84578),a=r(25635),s=r(94049),i=r(78470),d=r(28548),c=r(29767),u=r(53062),p=r(1702),f=r(41983),h=r(14915),m=r(4484),g=r(89623),x=r(11665),v=r(91665),b=r(88107),y=r(43076),w=r(87021),j=r(2778),A=r(52363),C=r(65036),S=r(4474),k=r(22003),T=r(21067),N=r(75912),I=r(91871),M=r(36741),P=r(48563);let F=e=>{var t,r,n,l,i,c,u,p,f;let{title:h,attempt:m}=e;return(0,o.jsxs)(s.default,{sx:{mb:2},children:[(0,o.jsxs)(s.default,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[m.ok?(0,o.jsx)(M.A,{color:"success",fontSize:"small"}):(0,o.jsx)(P.A,{color:"error",fontSize:"small"}),(0,o.jsx)(a.default,{variant:"subtitle2",children:h}),"number"==typeof m.status&&(0,o.jsx)(d.A,{size:"small",label:"HTTP ".concat(m.status)}),(0,o.jsx)(d.A,{size:"small",variant:"outlined",label:"".concat(m.durationMs," ms")})]}),m.ok?(0,o.jsxs)(a.default,{variant:"body2",color:"text.secondary",sx:{pl:3},children:["Response: ",m.content?'"'.concat(m.content,'"'):"(empty)"]}):(0,o.jsxs)(s.default,{sx:{pl:3},children:[(0,o.jsx)(a.default,{variant:"body2",color:"error.main",children:null==(t=m.error)?void 0:t.message}),((null==(r=m.error)?void 0:r.code)||(null==(n=m.error)?void 0:n.type))&&(0,o.jsxs)(a.default,{variant:"caption",color:"text.secondary",display:"block",children:[(null==(l=m.error)?void 0:l.type)?"type: ".concat(m.error.type):"",(null==(i=m.error)?void 0:i.type)&&(null==(c=m.error)?void 0:c.code)?" \xb7 ":"",(null==(u=m.error)?void 0:u.code)?"code: ".concat(m.error.code):""]}),(null==(p=m.error)?void 0:p.retryAfter)&&(0,o.jsxs)(a.default,{variant:"caption",color:"text.secondary",display:"block",children:["retry-after: ",m.error.retryAfter,"s"]}),(null==(f=m.error)?void 0:f.body)!==void 0&&(0,o.jsx)(s.default,{component:"pre",sx:{mt:.5,p:1,bgcolor:"action.hover",borderRadius:1,fontSize:"0.7rem",overflowX:"auto",maxHeight:160},children:JSON.stringify(m.error.body,null,2)})]})]})},E=e=>{let{open:t,modelLabel:r,loading:n,result:l,error:i,onClose:d,onRetry:c}=e;return(0,o.jsxs)(j.A,{open:t,onClose:d,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsxs)(A.A,{children:["Test model: ",r]}),(0,o.jsx)(C.A,{dividers:!0,children:n?(0,o.jsxs)(s.default,{sx:{display:"flex",alignItems:"center",gap:2,py:3},children:[(0,o.jsx)(S.default,{size:24}),(0,o.jsx)(a.default,{variant:"body2",children:"Sending a direct test request (SDK + axios)…"})]}):i?(0,o.jsx)(k.A,{severity:"error",children:i}):l?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(k.A,{severity:l.ok?"success":"warning",sx:{mb:2},children:l.diagnosis}),(0,o.jsxs)(a.default,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:["model: ",l.model,l.baseUrl?" \xb7 ".concat(l.baseUrl):"",l.provider?" \xb7 ".concat(l.provider):""]}),(0,o.jsx)(T.A,{sx:{mb:2}}),(0,o.jsx)(F,{title:"OpenAI SDK (used by flows)",attempt:l.sdk}),(0,o.jsx)(F,{title:"axios (independent cross-check)",attempt:l.axios})]}):null}),(0,o.jsxs)(N.A,{children:[(0,o.jsx)(I.A,{onClick:c,disabled:n,children:"Run again"}),(0,o.jsx)(I.A,{onClick:d,variant:"contained",children:"Close"})]})]})};var R=r(81956);let D=(0,w.h)("frontend/components/models/list/ModelCard"),L=e=>{let{model:t,onEdit:r,onDelete:w,folder:j,folders:A=[],onSetFolder:C,selectable:S=!1,selected:k=!1,onSelect:T}=e,[N,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)(!1),[F,L]=(0,n.useState)(null),[z,W]=(0,n.useState)(null),[O,B]=(0,n.useState)(null),_=async()=>{P(!0),W(null),L(null);try{let e=await (0,y.X)().testModel({modelId:t.id});L(e)}catch(e){D.error("Model test failed",{modelId:t.id,error:e}),W(e instanceof Error?e.message:"Failed to run test")}finally{P(!1)}},H=(0,o.jsx)(o.Fragment,{children:(0,o.jsxs)(l.A,{sx:{flexGrow:1},children:[(0,o.jsx)(a.default,{variant:"h6",gutterBottom:!0,children:t.displayName||t.name}),(0,o.jsx)(a.default,{variant:"body2",color:"text.secondary",sx:{mb:2},style:{display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"},children:t.description}),(0,o.jsxs)(s.default,{sx:{mb:1},children:[(0,o.jsxs)(a.default,{variant:"body2",color:"text.secondary",children:["Provider: ",(0,b.T_)(t.provider,t.adapter).label]}),t.displayName&&(0,o.jsxs)(a.default,{variant:"body2",color:"text.secondary",noWrap:!0,children:["Model: ",t.name]}),"number"==typeof t.contextWindow&&(0,o.jsxs)(a.default,{variant:"body2",color:"text.secondary",children:["Context: ",t.contextWindow.toLocaleString()," tokens"]})]}),t.baseUrl&&(0,o.jsx)(i.A,{title:t.baseUrl,arrow:!0,placement:"top",children:(0,o.jsxs)(a.default,{variant:"body2",color:"text.secondary",noWrap:!0,children:["Base URL: ",t.baseUrl]})}),j&&(0,o.jsx)(d.A,{icon:(0,o.jsx)(v.A,{}),label:j,size:"small",variant:"outlined",sx:{mt:1,maxWidth:"100%"}})]})});return S?(0,o.jsx)(c.A,{elevation:k?4:2,role:"radio","aria-checked":k,sx:{height:"100%",display:"flex",flexDirection:"column",border:e=>k?"2px solid ".concat(e.palette.primary.main):"2px solid transparent",transition:"border-color 120ms, box-shadow 120ms"},children:(0,o.jsx)(u.A,{onClick:()=>null==T?void 0:T(t.id),sx:{height:"100%",display:"flex",flexDirection:"column",alignItems:"stretch"},children:H})}):(0,o.jsxs)(c.A,{elevation:2,sx:{height:"100%",display:"flex",flexDirection:"column"},children:[H,(0,o.jsxs)(p.A,{disableSpacing:!0,children:[(0,o.jsx)(i.A,{title:"Test model (direct SDK call, no flow)",arrow:!0,children:(0,o.jsx)(f.A,{"aria-label":"test",onClick:()=>{I(!0),_()},children:(0,o.jsx)(g.A,{})})}),(0,o.jsx)(f.A,{"aria-label":"edit",onClick:r,children:(0,o.jsx)(h.A,{})}),(0,o.jsx)(f.A,{"aria-label":"delete",onClick:w,children:(0,o.jsx)(m.A,{})}),C&&(0,o.jsx)(i.A,{title:"Move to folder…",arrow:!0,children:(0,o.jsx)(f.A,{"aria-label":"move to folder",onClick:e=>B(e.currentTarget),sx:{ml:"auto"},children:(0,o.jsx)(x.A,{})})})]}),C&&(0,o.jsx)(R.A,{anchorEl:O,open:!!O,currentFolder:j,folders:A,onClose:()=>B(null),onAssign:C}),(0,o.jsx)(E,{open:N,modelLabel:t.displayName||t.name,loading:M,result:F,error:z,onClose:()=>I(!1),onRetry:_})]})}},71075:(e,t,r)=>{Promise.resolve().then(r.bind(r,52759))},71651:(e,t,r)=>{"use strict";r.d(t,{A:()=>x});var o=r(95155),n=r(12115),l=r(94049),a=r(25635),s=r(80777),i=r(9562),d=r(78470),c=r(41983),u=r(91871),p=r(86946),f=r(4484),h=r(80007),m=r(79299),g=r(62640);let x=e=>{let{roots:t,onChange:r}=e,x=Array.isArray(t)?t:[],[v,b]=(0,n.useState)(null),y=(e,t)=>{r(x.map((r,o)=>o===e?t:r))};return(0,o.jsxs)(l.default,{children:[(0,o.jsxs)(l.default,{sx:{display:"flex",alignItems:"center",mb:.5},children:[(0,o.jsx)(h.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,o.jsx)(a.default,{variant:"subtitle1",children:"Workspace folders"})]}),(0,o.jsxs)(a.default,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:["Limit which folders this server may work in. Advisory only — the server is told these paths via MCP roots; it is not a hard sandbox. Leave empty to default to the server's own root dir. Supports ",(0,o.jsx)("code",{children:"${global:VAR}"}),"."]}),(0,o.jsx)(s.A,{spacing:1,children:x.map((e,t)=>(0,o.jsxs)(l.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(i.A,{size:"small",fullWidth:!0,placeholder:"/path/to/folder or file:///path",value:e,onChange:e=>y(t,e.target.value)}),(0,o.jsx)(d.A,{title:"Browse folders (on the FLUJO machine)",children:(0,o.jsx)(c.A,{size:"small",onClick:()=>b(t),"aria-label":"browse for folder",children:(0,o.jsx)(m.A,{fontSize:"small"})})}),(0,o.jsx)(d.A,{title:"Remove",children:(0,o.jsx)(c.A,{size:"small",onClick:()=>r(x.filter((e,r)=>r!==t)),"aria-label":"remove workspace folder",children:(0,o.jsx)(f.A,{fontSize:"small"})})})]},t))}),(0,o.jsx)(u.A,{size:"small",startIcon:(0,o.jsx)(p.A,{}),onClick:()=>r([...x,""]),sx:{mt:1},children:"Add folder"}),(0,o.jsx)(g.A,{open:null!==v,title:"Choose a workspace folder",initialPath:null!==v&&x[v]||void 0,onClose:()=>b(null),onSelect:e=>{null!==v&&y(v,e)}})]})}},94035:(e,t,r)=>{"use strict";r.d(t,{O:()=>a});var o=r(12115),n=r(17897);let l=(0,r(87021).h)("frontend/hooks/useServerTools");function a(e){let[t,r]=(0,o.useState)([]),[a,s]=(0,o.useState)(!1),[i,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,f]=(0,o.useState)(null),[h,m]=(0,o.useState)(0),[g,x]=(0,o.useState)(!1),v=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,o.useCallback)(async function(){let o=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!e){r([]),d(null);return}if(f(e),!o&&c&&new Date().getTime()-c.getTime()<200&&t.length>0&&e===p)return void l.debug("Rate limiting tool refresh for server: ".concat(e));l.debug("Loading tools for server: ".concat(e)),s(!0),d(null);try{let t=await n.S.listServerTools(e);if(e!==p)return void l.debug("Server changed during tool loading from ".concat(e," to ").concat(p));if(t.error)l.warn("Error loading tools for ".concat(e,":"),t.error),d(t.error),r([]);else{let o=t.tools||[];l.debug("Loaded ".concat(o.length," tools for ").concat(e)),r(o),u(new Date),m(0)}}catch(t){if(e!==p)return void l.debug("Server changed during tool loading from ".concat(e," to ").concat(p));l.warn("Failed to load tools for server ".concat(e,":"),t),d("Failed to load tools: ".concat(t instanceof Error?t.message:"Unknown error")),r([])}finally{e===p&&s(!1)}},[e,c,t.length,p]),y=(0,o.useCallback)(()=>{if(!e)return;v.current&&(clearTimeout(v.current),v.current=null),x(!0);let t=Math.min(1e3*Math.pow(2,h),1e4);return l.debug("Retrying tool load for ".concat(e," in ").concat(t,"ms (attempt ").concat(h+1,")")),v.current=setTimeout(()=>{m(e=>e+1),b(!0),x(!1)},t),()=>{v.current&&clearTimeout(v.current)}},[e,h,b]),w=(0,o.useCallback)(async(t,r,o)=>{if(!e)return{success:!1,output:"",error:"No server selected"};l.debug("Testing tool ".concat(t," on server ").concat(e," with params:"),r);try{let a=await n.S.callTool(e,t,r,o);if(a.error)return l.warn("Error calling tool ".concat(t,":"),a.error),{success:!1,output:"",error:a.error};return l.debug("Tool ".concat(t," executed successfully:"),a),{success:!0,output:JSON.stringify(a,null,2)}}catch(e){return l.error("Exception calling tool ".concat(t,":"),e),{success:!1,output:"",error:e instanceof Error?e.message:"Unknown error occurred"}}},[e]);return(0,o.useEffect)(()=>{l.debug("Server name changed to: ".concat(e||"null")),v.current&&(clearTimeout(v.current),v.current=null),m(0),x(!1),e?(f(e),b()):(l.debug("Clearing tools as no server is selected"),r([]),d(null),f(null))},[e,b]),{tools:t,isLoading:a||g,error:i,loadTools:b,retryLoadTools:y,isRetrying:g,retryCount:h,testTool:w}}},95480:(e,t,r)=>{"use strict";r.d(t,{A:()=>N});var o=r(95155),n=r(12115),l=r(87021),a=r(63941),s=r(29985),i=r(80372),d=r(94049),c=r(25635),u=r(14913),p=r(57883),f=r(2300),h=r(89218),m=r(42063),g=r(17897);r(32098);var x=r(61033);let v=(0,l.h)("frontend/components/shared/PromptBuilder"),b=e=>{v.debug("Deserializing markdown to Slate value");let t=e.split("\n").map(e=>({type:"paragraph",children:(e=>{let t=(0,x.A$)(e);if(0===t.length)return[{text:e}];let r=[],o=0;for(let n of t)n.index>o&&r.push({text:e.slice(o,n.index)}),r.push({type:"binding-reference",kind:n.kind,server:n.server,name:n.name,children:[{text:""}]}),o=n.index+n.fullMatch.length;return o<e.length&&r.push({text:e.slice(o)}),r})(e)}));return t.length>0?t:[{type:"paragraph",children:[{text:""}]}]},y=e=>{v.debug("Serializing Slate value to markdown");let t=0,r=e.map(e=>e.children?e.children.map(e=>a.EY.isText(e)?e.text:"binding-reference"===e.type?(t++,(0,x.X8)(e.kind,e.server,e.name)):"").join(""):"").join("\n");return t>0&&v.debug("Serialized ".concat(t," binding references")),r},w=e=>{let{attributes:t,children:r,element:n}=e;return"binding-reference"===n.type?(0,o.jsxs)("span",{...t,className:"tool-reference-wrapper",children:[(0,o.jsx)(()=>{let e=(0,s.Zi)(),t=(e=>"tool"===e.kind&&"handoff"===e.server)(n),r="resource"===n.kind?"resource":t?"handoff":"",l=()=>{let t=s.rL.findPath(e,n);v.debug("Removing binding reference: ".concat(n.kind,":").concat(n.server,":").concat(n.name)),a.gB.removeNodes(e,{at:t})};return(0,o.jsxs)("span",{contentEditable:!1,className:"tool-reference-container ".concat(r),children:[(0,o.jsx)("span",{className:"tool-reference ".concat(r),children:(0,x.YP)(n)}),(0,o.jsx)("span",{className:"tool-reference-delete ".concat(r),role:"button",tabIndex:0,onClick:e=>{e.preventDefault(),e.stopPropagation(),l()},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),l())},children:"\xd7"})]})},{}),r," "]}):(0,o.jsx)("p",{...t,children:r})},j=e=>{let{attributes:t,children:r,leaf:n}=e,l=r;return n.bold&&(l=(0,o.jsx)("strong",{children:l})),n.italic&&(l=(0,o.jsx)("em",{children:l})),n.code&&(l=(0,o.jsx)("code",{children:l})),(0,o.jsx)("span",{...t,children:l})},A=e=>{let{server:t,name:r}=e,l="handoff"===t,[a,s]=(0,n.useState)(null),[i,d]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=!1;return(async()=>{try{var o;d(!0);let n=null==(o=(await g.S.listServerTools(t)).tools)?void 0:o.find(e=>e.name===r);e||s(n||null)}catch(e){v.error("Failed to fetch tool info for ".concat(t,":").concat(r),e)}finally{e||d(!1)}})(),()=>{e=!0}},[t,r]),i)?(0,o.jsx)("span",{className:"tool-reference-preview loading ".concat(l?"handoff":""),children:"tool:".concat(t,"__").concat(r)}):a?(0,o.jsxs)("span",{className:"tool-reference-preview ".concat(l?"handoff":""),children:["[The user is referencing a ",l?"handoff":"tool"," `tool:",t,"__",r,"` (",a.description||"No description",")]"]}):(0,o.jsx)("span",{className:"tool-reference-preview not-found ".concat(l?"handoff":""),children:"tool:".concat(t,"__").concat(r," (Tool not found)")})},C=e=>{let{server:t,name:r}=e,[l,a]=(0,n.useState)(null),[s,i]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=!1;return(async()=>{try{i(!0);let o=await g.S.listServerResources(t),n=[...o.resources||[],...o.resourceTemplates||[]].find(e=>e.uri===r||e.uriTemplate===r);e||a((null==n?void 0:n.description)||(null==n?void 0:n.name)||null)}catch(e){v.error("Failed to fetch resource info for ".concat(t,":").concat(r),e)}finally{e||i(!1)}})(),()=>{e=!0}},[t,r]),s)?(0,o.jsx)("span",{className:"tool-reference-preview loading resource",children:"resource:".concat(t,"__").concat(r)}):(0,o.jsxs)("span",{className:"tool-reference-preview resource",children:["[The contents of resource `",r,"` from `",t,"`",l?" (".concat(l,")"):""," will be inserted here]"]})},S=e=>{let{binding:t}=e;return"resource"===t.kind?(0,o.jsx)(C,{server:t.server,name:t.name}):(0,o.jsx)(A,{server:t.server,name:t.name})},k=e=>{let{value:t}=e;v.debug("Rendering preview");let r=[],n=0;for(let e of(0,x.A$)(t))e.index>n&&r.push({type:"text",value:t.slice(n,e.index)}),r.push({type:"binding",binding:e,key:e.index}),n=e.index+e.fullMatch.length;n<t.length&&r.push({type:"text",value:t.slice(n)});let l=[],a=[],s=()=>{l.push((0,o.jsx)("p",{children:a},"p-".concat(l.length))),a=[]};for(let e of r)if("text"===e.type){let t=e.value.split("\n");for(let e=0;e<t.length;e++)a.push(t[e]),e<t.length-1&&s()}else a.push((0,o.jsx)(S,{binding:e.binding},"binding-".concat(e.key)));return a.length>0&&s(),(0,o.jsx)("div",{className:"preview-content",children:l})},T=(0,n.forwardRef)((e,t)=>{let{value:r,onChange:l,label:g="Prompt Builder",height:A=300,onModeChange:C,customPreviewRenderer:S}=e;v.info("PromptBuilder initialized");let T=(0,n.useMemo)(()=>{let e=(0,i.$k)((0,s.o$)((0,a.ie)())),{isInline:t,isVoid:r}=e;return e.isInline=e=>"binding-reference"===e.type||t(e),e.isVoid=e=>"binding-reference"===e.type||r(e),e},[]),[N,I]=(0,n.useState)("raw"),[M,P]=(0,n.useState)(()=>b(r||"")),F=(0,n.useRef)(!1),[,E]=(0,n.useState)(0);(0,n.useImperativeHandle)(t,()=>({insertText:e=>{v.info("insertText called with text length: ".concat(e.length));let t=(0,x.js)(e);if(t){v.info("Inserting ".concat(t.kind," reference: ").concat(t.server,":").concat(t.name));let e={type:"binding-reference",kind:t.kind,server:t.server,name:t.name,children:[{text:""}]};T.selection||a.gB.select(T,a.KE.end(T,[])),a.gB.insertNodes(T,e),a.gB.move(T),E(e=>e+1),P([...T.children])}else T.selection||a.gB.select(T,a.KE.end(T,[])),a.gB.insertText(T,e);l(y(T.children)),v.info("insertText completed successfully")},getMode:()=>N})),(0,n.useEffect)(()=>{y(M)!==y(b(r||""))&&(v.debug("External value change detected"),F.current=!0,P(b(r||"")))},[r,M]);let R=(0,n.useCallback)(e=>{if(F.current){F.current=!1;return}P(e),l(y(e))},[l]);return(0,o.jsxs)(d.default,{sx:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},children:[g&&(0,o.jsx)(c.default,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"medium",mb:1},children:g}),(0,o.jsx)(d.default,{sx:{mb:1},children:(0,o.jsxs)(u.A,{value:N,exclusive:!0,onChange:(e,t)=>{null!==t&&(v.info("Mode changed from ".concat(N," to ").concat(t)),I(t),C&&C(t))},size:"small",children:[(0,o.jsxs)(p.A,{value:"raw",children:[(0,o.jsx)(h.A,{fontSize:"small",sx:{mr:.5}}),"Raw"]}),(0,o.jsxs)(p.A,{value:"preview",children:[(0,o.jsx)(m.A,{fontSize:"small",sx:{mr:.5}}),"Preview"]})]})}),(0,o.jsx)(f.A,{elevation:0,sx:{border:"1px solid rgba(0, 0, 0, 0.12)",borderRadius:1,overflow:"hidden",flexGrow:1,display:"flex",flexDirection:"column"},children:"raw"===N?(0,o.jsx)(d.default,{className:"slate-editor-container",sx:{height:"number"==typeof A?A:"100%",overflow:"auto",p:2},children:(0,o.jsx)(s.A,{editor:T,initialValue:M,onChange:R,children:(0,o.jsx)(s.Fo,{className:"slate-editor",renderElement:w,renderLeaf:j,placeholder:"Write your prompt here..."})})}):S?(0,o.jsx)(d.default,{className:"custom-preview-container",sx:{height:"number"==typeof A?A:"100%",overflow:"auto"},children:S()}):(0,o.jsx)(d.default,{className:"preview-container",sx:{height:"number"==typeof A?A:"100%",overflow:"auto",p:2},children:(0,o.jsx)(k,{value:r})})})]})});T.displayName="PromptBuilder";let N=T}},e=>{e.O(0,[1137,3862,7926,2678,4754,9244,8548,1983,1871,2003,5501,488,3272,3077,8598,9659,9451,2403,7687,8480,6731,3730,4749,1620,4812,812,7430,4207,8441,1255,7358],()=>e(e.s=71075)),_N_E=e.O()}]);
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7177],{1150:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return s}});let t=r(95155),o=r(12115),a=r(24437);function l(e){return{default:e&&"default"in e?e.default:e}}r(36552);let i={loader:()=>Promise.resolve(l(()=>null)),loading:null,ssr:!0},s=function(e){let n={...i,...e},r=(0,o.lazy)(()=>n.loader().then(l)),s=n.loading;function c(e){let l=s?(0,t.jsx)(s,{isLoading:!0,pastDelay:!0,error:null}):null,i=!n.ssr||!!n.loading,c=i?o.Suspense:o.Fragment,d=n.ssr?(0,t.jsxs)(t.Fragment,{children:[null,(0,t.jsx)(r,{...e})]}):(0,t.jsx)(a.BailoutToCSR,{reason:"next/dynamic",children:(0,t.jsx)(r,{...e})});return(0,t.jsx)(c,{...i?{fallback:l}:{},children:d})}return c.displayName="LoadableComponent",c}},3946:e=>{e.exports={style:{fontFamily:"'Geist Mono', 'Geist Mono Fallback'",fontStyle:"normal"},className:"__className_c29908",variable:"__variable_c29908"}},8567:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"workAsyncStorage",{enumerable:!0,get:function(){return t.workAsyncStorageInstance}});let t=r(17828)},13673:()=>{},17828:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"workAsyncStorageInstance",{enumerable:!0,get:function(){return t}});let t=(0,r(64054).createAsyncLocalStorage)()},24437:(e,n,r)=>{"use strict";function t(e){let{reason:n,children:r}=e;return r}Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"BailoutToCSR",{enumerable:!0,get:function(){return t}}),r(24553)},36552:(e,n,r)=>{"use strict";function t(e){let{moduleIds:n}=e;return null}Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"PreloadChunks",{enumerable:!0,get:function(){return t}}),r(95155),r(47650),r(8567),r(77278)},59742:e=>{e.exports={style:{fontFamily:"'Geist', 'Geist Fallback'",fontStyle:"normal"},className:"__className_246ccd",variable:"__variable_246ccd"}},64054:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),!function(e,n){for(var r in n)Object.defineProperty(e,r,{enumerable:!0,get:n[r]})}(n,{bindSnapshot:function(){return l},createAsyncLocalStorage:function(){return a},createSnapshot:function(){return i}});let r=Object.defineProperty(Error("Invariant: AsyncLocalStorage accessed in runtime where it is not available"),"__NEXT_ERROR_CODE",{value:"E504",enumerable:!1,configurable:!0});class t{disable(){throw r}getStore(){}run(){throw r}exit(){throw r}enterWith(){throw r}static bind(e){return e}}let o="undefined"!=typeof globalThis&&globalThis.AsyncLocalStorage;function a(){return o?new o:new t}function l(e){return o?o.bind(e):t.bind(e)}function i(){return o?o.snapshot():function(e,...n){return e(...n)}}},68187:(e,n,r)=>{Promise.resolve().then(r.t.bind(r,59742,23)),Promise.resolve().then(r.t.bind(r,3946,23)),Promise.resolve().then(r.t.bind(r,13673,23)),Promise.resolve().then(r.bind(r,72403))},72403:(e,n,r)=>{"use strict";r.d(n,{default:()=>h});var t=r(95155),o=r(12115),a=r(86278),l=r.n(a);let i=(0,r(87021).h)("frontend/components/AppWrapper"),s=l()(()=>Promise.all([r.e(2678),r.e(8598),r.e(7583)]).then(r.bind(r,26796)).then(e=>e.ThemeProvider),{loadableGenerated:{webpack:()=>[26796]},ssr:!1,loading:()=>(0,t.jsx)("div",{children:"Loading theme..."})}),c=l()(()=>r.e(9164).then(r.bind(r,9164)).then(e=>e.StorageProvider),{loadableGenerated:{webpack:()=>[9164]},ssr:!1,loading:()=>(0,t.jsx)("div",{children:"Loading storage..."})}),d=l()(()=>Promise.all([r.e(2678),r.e(4754),r.e(9244),r.e(8548),r.e(1983),r.e(8598),r.e(2619),r.e(6016)]).then(r.bind(r,73667)),{loadableGenerated:{webpack:()=>[73667]},ssr:!1,loading:()=>(0,t.jsx)("div",{children:"Loading navigation..."})}),u=l()(()=>Promise.all([r.e(2678),r.e(4754),r.e(9244),r.e(8548),r.e(1983),r.e(1871),r.e(2003),r.e(5501),r.e(3272),r.e(9164),r.e(3217)]).then(r.bind(r,23217)),{loadableGenerated:{webpack:()=>[23217]},ssr:!1,loading:()=>null}),f=l()(()=>Promise.all([r.e(9164),r.e(9195)]).then(r.bind(r,69195)).then(e=>e.TourProvider),{loadableGenerated:{webpack:()=>[69195]},ssr:!1,loading:()=>null}),b=l()(()=>Promise.all([r.e(2678),r.e(4754),r.e(9244),r.e(8548),r.e(1983),r.e(1871),r.e(2005),r.e(8083),r.e(9164),r.e(3545)]).then(r.bind(r,83545)),{loadableGenerated:{webpack:()=>[83545]},ssr:!1,loading:()=>null});class p extends o.Component{static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){i.error("AppWrapper error boundary caught an error:",e)}render(){return this.state.hasError?(0,t.jsxs)("div",{style:{padding:"20px",textAlign:"center"},children:[(0,t.jsx)("h2",{children:"Something went wrong loading the application."}),(0,t.jsx)("p",{children:"Please try refreshing the page."}),(0,t.jsx)("button",{onClick:()=>window.location.reload(),style:{padding:"8px 16px",background:"#3498DB",color:"white",border:"none",borderRadius:"4px",cursor:"pointer",marginTop:"10px"},children:"Refresh"})]}):this.props.children}constructor(e){super(e),this.state={hasError:!1}}}function h(e){let{children:n}=e;return i.debug("Rendering AppWrapper"),(0,t.jsx)(p,{children:(0,t.jsx)(o.Suspense,{fallback:(0,t.jsx)("div",{children:"Loading application..."}),children:(0,t.jsx)(s,{children:(0,t.jsx)(c,{children:(0,t.jsxs)(f,{children:[(0,t.jsxs)(o.Suspense,{fallback:(0,t.jsx)("div",{children:"Loading navigation..."}),children:[(0,t.jsx)(d,{}),(0,t.jsx)(u,{})]}),(0,t.jsx)("main",{children:n}),(0,t.jsx)(b,{})]})})})})})}},86278:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return o}});let t=r(28140)._(r(1150));function o(e,n){var r;let o={};"function"==typeof e&&(o.loader=e);let a={...o,...n};return(0,t.default)({...a,modules:null==(r=a.loadableGenerated)?void 0:r.modules})}("function"==typeof n.default||"object"==typeof n.default&&null!==n.default)&&void 0===n.default.__esModule&&(Object.defineProperty(n.default,"__esModule",{value:!0}),Object.assign(n.default,n),e.exports=n.default)},87021:(e,n,r)=>{"use strict";r.d(n,{h:()=>s});let t={LOG_LEVEL:3},o={VERBOSE:-1,DEBUG:0,INFO:1,WARN:2,ERROR:3},a="number"==typeof t.LOG_LEVEL?t.LOG_LEVEL:o.ERROR;function l(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(n>6)return String(e);if(!(e instanceof Error))return e;let r={name:e.name,message:e.message};for(let t of Object.getOwnPropertyNames(e)){if("name"===t||"message"===t)continue;let o=e[t];"function"!=typeof o&&("stack"===t?r.stack=o:"cause"===t?r.cause=l(o,n+1):"errors"===t&&Array.isArray(o)?r.errors=o.map(e=>l(e,n+1)):r[t]=o)}return r}function i(e,n,r,t,i){if(e>=("number"==typeof i?i:a)){if("function"==typeof t)try{t=t()}catch(e){t="[lazy log data threw]"}let a=new Date().toISOString(),i="[".concat(a,"] [").concat(n,"]"),s="".concat(i," ").concat(r);if(void 0!==t)if(t instanceof Error||"object"==typeof t)try{let e=t instanceof Error?l(t):t,n=JSON.stringify(e,(e,n)=>n instanceof Error?l(n):n,2);s+=":\n".concat(n)}catch(e){s+=": [Object cannot be stringified]"}else s+=": ".concat(t);switch(e){case o.VERBOSE:console.debug("[VERBOSE] ".concat(s));break;case o.DEBUG:console.debug(s);break;case o.INFO:console.info(s);break;case o.WARN:console.warn(s);break;case o.ERROR:console.error(s);break;default:console.log(s)}}}function s(e,n){let r,t=((r=e.replace(/^src\//,"")).startsWith("/")&&(r=r.substring(1)),r);return{verbose:(e,r)=>{i(o.VERBOSE,t,e,r,n)},debug:(e,r)=>{i(o.DEBUG,t,e,r,n)},info:(e,r)=>{i(o.INFO,t,e,r,n)},warn:(e,r)=>{i(o.WARN,t,e,r,n)},error:(e,r)=>{i(o.ERROR,t,e,r,n)}}}}},e=>{e.O(0,[6317,6714,2978,8441,1255,7358],()=>e(e.s=68187)),_N_E=e.O()}]);