flujo-ai 3.40.0 → 3.41.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.
- package/.next/BUILD_ID +1 -1
- package/.next/app-build-manifest.json +400 -384
- package/.next/app-path-routes-manifest.json +53 -53
- package/.next/build-manifest.json +5 -5
- package/.next/prerender-manifest.json +33 -33
- package/.next/react-loadable-manifest.json +9 -9
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +3 -3
- package/.next/server/app/api/approvals/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/approvals/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/backup/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/browse/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/bugs/enhance/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/cwd/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/encryption/secure/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/env/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/[id]/convert-process-to-subflow/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/[id]/versions/[versionId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/[id]/versions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/assist/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/compile/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/generate/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/generator/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/improve/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/prompt-renderer/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/quick-chat/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/repair/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/flow/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/init/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/local-models/capability/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/local-models/pull/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/local-models/suggest/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/app-sandbox/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/cancel/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/authoring/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/automation/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/flows/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/resources/read/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/resources/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/servers/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/state/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/flujo/tools/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/oauth-capability/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/prompts/get/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/prompts/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/resources/read/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/resources/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/status/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/tools/[toolName]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/[name]/tools/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/servers/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/test-connection/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp/test-connection/stream/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp-registry/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/mcp-registry/spotlight/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/model/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/model/provider/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/model/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/model/test/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/oauth/callback/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/oauth/initiate/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/oauth/reset/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/build/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/derive-secrets/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/install/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/install/status/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/installed/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/resolve/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/scan-targets/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/search/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/packages/uninstall/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/[id]/run/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/[id]/runs/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/preview-schedule/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/reconcile/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/planned-executions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/auth/resend/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/auth/reset/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/auth/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/feedback/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/oauth/callback/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/oauth/initiate/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/packages/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/publish/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/registry/settings/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/restore/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/runs/active/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/setup/ai-cli/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/statistics/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/storage/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/telemetry/daily-active/route.js +1 -1
- package/.next/server/app/api/telemetry/daily-active/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/waves/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/webhooks/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/automation/triggers/page.js +1 -1
- package/.next/server/app/automation/triggers/page.js.nft.json +1 -1
- package/.next/server/app/automation/triggers/page_client-reference-manifest.js +1 -1
- package/.next/server/app/automation/triggers.html +1 -1
- package/.next/server/app/automation/triggers.rsc +4 -4
- package/.next/server/app/automation/waves/page_client-reference-manifest.js +1 -1
- package/.next/server/app/automation/waves.html +1 -1
- package/.next/server/app/automation/waves.rsc +4 -4
- package/.next/server/app/chat/page.js +2 -2
- package/.next/server/app/chat/page_client-reference-manifest.js +1 -1
- package/.next/server/app/chat.html +1 -1
- package/.next/server/app/chat.rsc +4 -4
- package/.next/server/app/docs/page.js +3 -3
- package/.next/server/app/docs/page_client-reference-manifest.js +1 -1
- package/.next/server/app/docs.html +1 -1
- package/.next/server/app/docs.rsc +4 -4
- package/.next/server/app/executions/page.js +1 -1
- package/.next/server/app/executions/page.js.nft.json +1 -1
- package/.next/server/app/executions/page_client-reference-manifest.js +1 -1
- package/.next/server/app/executions.html +1 -1
- package/.next/server/app/executions.rsc +4 -4
- package/.next/server/app/flows/page.js +5 -3
- package/.next/server/app/flows/page.js.nft.json +1 -1
- package/.next/server/app/flows/page_client-reference-manifest.js +1 -1
- package/.next/server/app/flows.html +1 -1
- package/.next/server/app/flows.rsc +4 -4
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +4 -4
- package/.next/server/app/mcp/page.js +73 -44
- package/.next/server/app/mcp/page.js.nft.json +1 -1
- package/.next/server/app/mcp/page_client-reference-manifest.js +1 -1
- package/.next/server/app/mcp-flows/route.js +1 -1
- package/.next/server/app/mcp-flows/route_client-reference-manifest.js +1 -1
- package/.next/server/app/mcp-proxy/[server]/route.js +1 -1
- package/.next/server/app/mcp-proxy/[server]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/mcp.html +1 -1
- package/.next/server/app/mcp.rsc +4 -4
- package/.next/server/app/models/page.js +7 -7
- package/.next/server/app/models/page_client-reference-manifest.js +1 -1
- package/.next/server/app/packages/page.js +1 -1
- package/.next/server/app/packages/page_client-reference-manifest.js +1 -1
- package/.next/server/app/packages.html +1 -1
- package/.next/server/app/packages.rsc +4 -4
- package/.next/server/app/page.js +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/settings/page.js +2 -2
- package/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/server/app/settings.html +1 -1
- package/.next/server/app/settings.rsc +4 -4
- package/.next/server/app/statistics/page.js +2 -2
- package/.next/server/app/statistics/page_client-reference-manifest.js +1 -1
- package/.next/server/app/statistics.html +1 -1
- package/.next/server/app/statistics.rsc +4 -4
- package/.next/server/app/v1/chat/completions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/breakpoints/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/cancel/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/debug/continue/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/debug/step/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/edit-state/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/events/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/inject/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/resources/[resourceId]/content/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/resources/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/respond/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/revert/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/[conversationId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/conversations/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/chat/events/route_client-reference-manifest.js +1 -1
- package/.next/server/app/v1/models/route_client-reference-manifest.js +1 -1
- package/.next/server/app/waves/page_client-reference-manifest.js +1 -1
- package/.next/server/app/waves.html +1 -1
- package/.next/server/app/waves.rsc +4 -4
- package/.next/server/app-paths-manifest.json +53 -53
- package/.next/server/chunks/1227.js +1 -1
- package/.next/server/chunks/1403.js +2 -2
- package/.next/server/chunks/1539.js +1 -1
- package/.next/server/chunks/2069.js +1 -1
- package/.next/server/chunks/2372.js +1 -1
- package/.next/server/chunks/2828.js +2 -2
- package/.next/server/chunks/3422.js +1 -0
- package/.next/server/chunks/3945.js +3 -3
- package/.next/server/chunks/519.js +2 -2
- package/.next/server/chunks/5444.js +2 -2
- package/.next/server/chunks/5750.js +1 -1
- package/.next/server/chunks/5918.js +10 -10
- package/.next/server/chunks/6226.js +2 -2
- package/.next/server/chunks/9088.js +2 -2
- package/.next/server/chunks/9490.js +5 -0
- package/.next/server/chunks/9543.js +3 -3
- package/.next/server/chunks/9624.js +8 -8
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-manifest.json +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/{1161-19176c3e7c655121.js → 1161-563a8028f59f00de.js} +1 -1
- package/.next/static/chunks/1521-9ad145dcb8e3abfc.js +1 -0
- package/.next/static/chunks/1576.06797b29a19fa26c.js +1 -0
- package/.next/static/chunks/{4386-e9621d3c94969a68.js → 2005-f9d38c39f10c321f.js} +1 -1
- package/.next/static/chunks/2493-da85c47ef972c066.js +1 -0
- package/.next/static/chunks/361.c88d43436e974006.js +1 -0
- package/.next/static/chunks/3731-c18f48522b159d7f.js +1 -0
- package/.next/static/chunks/3781.5086bce03aa281f7.js +1 -0
- package/.next/static/chunks/3969-15a32253b112652c.js +1 -0
- package/.next/static/chunks/4167.2ce97ca450815df1.js +1 -0
- package/.next/static/chunks/4814-52b7254ab573a455.js +1 -0
- package/.next/static/chunks/4965.d401547984d71b7a.js +1 -0
- package/.next/static/chunks/5148-9174ba300221fd1b.js +1 -0
- package/.next/static/chunks/5417-fb7d3760cc288ab1.js +1 -0
- package/.next/static/chunks/5967-34735763d1b03ccc.js +1 -0
- package/.next/static/chunks/7260-743e4b0cc4211dcb.js +1 -0
- package/.next/static/chunks/7711-7323dabe7dc02311.js +1 -0
- package/.next/static/chunks/8124-f99060fe1dfc119e.js +1 -0
- package/.next/static/chunks/8135-7fe07a34a8c49967.js +1 -0
- package/.next/static/chunks/8529.6187e01de8e9a692.js +1 -0
- package/.next/static/chunks/9136-e9ee57cc581ddd50.js +1 -0
- package/.next/static/chunks/9140.9180b569c4b26168.js +1 -0
- package/.next/static/chunks/9195-6a18a5867bb76c64.js +1 -0
- package/.next/static/chunks/app/automation/triggers/{page-594a6294c58344bf.js → page-34b9a8a2e6f28c2f.js} +1 -1
- package/.next/static/chunks/app/automation/waves/{page-ce2fef4996cad8e6.js → page-fd4929ea308183b2.js} +1 -1
- package/.next/static/chunks/app/chat/page-fb8a33db7628ecd0.js +1 -0
- package/.next/static/chunks/app/docs/page-3e21583b1cd5d7ca.js +1 -0
- package/.next/static/chunks/app/executions/{page-fcc848de86714386.js → page-56ecca56c17c05d7.js} +1 -1
- package/.next/static/chunks/app/flows/page-8c1a656197b15894.js +1 -0
- package/.next/static/chunks/app/layout-6e2756704ddc9f39.js +1 -0
- package/.next/static/chunks/app/mcp/page-4c4390354fdd94c8.js +1 -0
- package/.next/static/chunks/app/models/error-ea477f0ad52f4dcb.js +1 -0
- package/.next/static/chunks/app/models/page-e237ac64a0f62c3d.js +1 -0
- package/.next/static/chunks/app/packages/page-8680e4bea6b7ea45.js +1 -0
- package/.next/static/chunks/app/page-6dca06b6b7667181.js +1 -0
- package/.next/static/chunks/app/settings/page-a5f7fedcbf9e3a7f.js +1 -0
- package/.next/static/chunks/app/statistics/page-f9f9627d1c1ff963.js +1 -0
- package/.next/static/chunks/app/waves/{page-5b53af3eb9409414.js → page-7529febc48eb473d.js} +1 -1
- package/.next/static/chunks/{webpack-9fbd3587b9ef4dca.js → webpack-f3df493faa0bd612.js} +1 -1
- package/.next/static/css/{400b1b927c3ffaf6.css → 9f9b7f1374ac2d01.css} +1 -1
- package/.next/trace +11 -11
- package/README.md +1 -1
- package/mcp-servers/bash/package.json +1 -1
- package/mcp-servers/browser/package.json +1 -1
- package/mcp-servers/filesystem/package.json +1 -1
- package/mcp-servers/flujo/package.json +1 -1
- package/package.json +5 -5
- package/.next/server/chunks/7508.js +0 -5
- package/.next/server/chunks/8598.js +0 -1
- package/.next/static/chunks/1521-1c98c9a56726e053.js +0 -1
- package/.next/static/chunks/1576.bc6ae6c9e6d939d8.js +0 -1
- package/.next/static/chunks/2005.300528b5119c2d38.js +0 -1
- package/.next/static/chunks/2499-92cd97ce4993999f.js +0 -1
- package/.next/static/chunks/361.51d642c530c84295.js +0 -1
- package/.next/static/chunks/3731-64070760ae44448f.js +0 -1
- package/.next/static/chunks/4814-31eb5f3b10c651c1.js +0 -1
- package/.next/static/chunks/4965.39e24b54c3c6ca58.js +0 -1
- package/.next/static/chunks/5967-59fde8c214c9ca9f.js +0 -1
- package/.next/static/chunks/6417.70056fe81ca21682.js +0 -1
- package/.next/static/chunks/7711-4b017720ec49c96d.js +0 -1
- package/.next/static/chunks/8124-94140ee1dd8ed87c.js +0 -1
- package/.next/static/chunks/8135-5b975b9014f8920b.js +0 -1
- package/.next/static/chunks/8529.b5a43e728bb5bb8a.js +0 -1
- package/.next/static/chunks/9001-4c27a608feddb878.js +0 -1
- package/.next/static/chunks/9136-9c415453ec02519c.js +0 -1
- package/.next/static/chunks/9140.6502327a2c098d33.js +0 -1
- package/.next/static/chunks/9195-3c9c4300e7505d9e.js +0 -1
- package/.next/static/chunks/9524-b9d2c7e4426edd07.js +0 -1
- package/.next/static/chunks/app/chat/page-203cb7bf21638ada.js +0 -1
- package/.next/static/chunks/app/docs/page-c466a58caf5e3336.js +0 -1
- package/.next/static/chunks/app/flows/page-172c759ca81ba02f.js +0 -1
- package/.next/static/chunks/app/layout-a6ca531683a518a7.js +0 -1
- package/.next/static/chunks/app/mcp/page-0a96e6b30e45b1e6.js +0 -1
- package/.next/static/chunks/app/models/error-1964203c5c6e7d0e.js +0 -1
- package/.next/static/chunks/app/models/page-ad1cbea6d3324966.js +0 -1
- package/.next/static/chunks/app/packages/page-dda48425be9fc137.js +0 -1
- package/.next/static/chunks/app/page-04189aa1b1318c2d.js +0 -1
- package/.next/static/chunks/app/settings/page-906c229c87011ead.js +0 -1
- package/.next/static/chunks/app/statistics/page-9b13a95549f438c0.js +0 -1
- /package/.next/static/{b1aMk0634gkkiunttd1SQ → utOrEUSzguWncIosxgCeR}/_buildManifest.js +0 -0
- /package/.next/static/{b1aMk0634gkkiunttd1SQ → utOrEUSzguWncIosxgCeR}/_ssgManifest.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3080],{3986:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M21 10.12h-6.78l2.74-2.82c-2.73-2.7-7.15-2.8-9.88-.1-2.73 2.71-2.73 7.08 0 9.79s7.15 2.71 9.88 0C18.32 15.65 19 14.08 19 12.1h2c0 1.98-.88 4.55-2.64 6.29-3.51 3.48-9.21 3.48-12.72 0-3.5-3.47-3.53-9.11-.02-12.58s9.14-3.47 12.65 0L21 3zM12.5 8v4.25l3.5 2.08-.72 1.21L11 13V8z"}),"Update")},4097:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"m18.04 7.99-.63-1.4-1.4-.63c-.39-.18-.39-.73 0-.91l1.4-.63.63-1.4c.18-.39.73-.39.91 0l.63 1.4 1.4.63c.39.18.39.73 0 .91l-1.4.63-.63 1.4c-.17.39-.73.39-.91 0m3.24 4.73-.32-.72c-.18-.39-.73-.39-.91 0l-.32.72-.73.32c-.39.18-.39.73 0 .91l.72.32.32.73c.18.39.73.39.91 0l.32-.72.73-.32c.39-.18.39-.73 0-.91zm-5.04 1.65 1.23.93c.4.3.51.86.26 1.3l-1.62 2.8c-.25.44-.79.62-1.25.42l-1.43-.6c-.2.13-.42.26-.64.37l-.19 1.54c-.06.5-.49.88-.99.88H8.38c-.5 0-.93-.38-.99-.88l-.19-1.54c-.22-.11-.43-.23-.64-.37l-1.43.6c-.46.2-1 .02-1.25-.42l-1.62-2.8c-.25-.44-.14-.99.26-1.3l1.23-.93V14c0-.12 0-.25.01-.37l-1.23-.93c-.4-.3-.51-.86-.26-1.3l1.62-2.8c.25-.44.79-.62 1.25-.42l1.43.6c.2-.13.42-.26.64-.37l.19-1.54c.05-.49.48-.87.98-.87h3.23c.5 0 .93.38.99.88l.19 1.54c.22.11.43.23.64.37l1.43-.6c.46-.2 1-.02 1.25.42l1.62 2.8c.25.44.14.99-.26 1.3l-1.23.93c.01.12.01.24.01.37s0 .24-.01.36M13 14c0-1.66-1.34-3-3-3s-3 1.34-3 3 1.34 3 3 3 3-1.34 3-3"}),"SettingsSuggestRounded")},7107:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"m9.78 11.16-1.42 1.42c-.68-.69-1.34-1.58-1.79-2.94l1.94-.49c.32.89.77 1.5 1.27 2.01M11 6 7 2 3 6h3.02c.02.81.08 1.54.19 2.17l1.94-.49C8.08 7.2 8.03 6.63 8.02 6zm10 0-4-4-4 4h2.99c-.1 3.68-1.28 4.75-2.54 5.88-.5.44-1.01.92-1.45 1.55-.34-.49-.73-.88-1.13-1.24L9.46 13.6c.93.85 1.54 1.54 1.54 3.4v5h2v-5c0-2.02.71-2.66 1.79-3.63 1.38-1.24 3.08-2.78 3.2-7.37z"}),"AltRoute")},10076:(e,t,l)=>{Promise.resolve().then(l.bind(l,38693))},14418:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2M9.29 16.29 5.7 12.7a.996.996 0 0 1 0-1.41c.39-.39 1.02-.39 1.41 0L10 14.17l6.88-6.88c.39-.39 1.02-.39 1.41 0s.39 1.02 0 1.41l-7.59 7.59c-.38.39-1.02.39-1.41 0"}),"CheckCircleRounded")},22590:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M19.3 16.9c.4-.7.7-1.5.7-2.4 0-2.5-2-4.5-4.5-4.5S11 12 11 14.5s2 4.5 4.5 4.5c.9 0 1.7-.3 2.4-.7l3.2 3.2 1.4-1.4zm-3.8.1c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.5 2.5-2.5 2.5 1.1 2.5 2.5-1.1 2.5-2.5 2.5M12 20v2C6.48 22 2 17.52 2 12S6.48 2 12 2c4.84 0 8.87 3.44 9.8 8h-2.07c-.64-2.46-2.4-4.47-4.73-5.41V5c0 1.1-.9 2-2 2h-2v2c0 .55-.45 1-1 1H8v2h2v3H9l-4.79-4.79C4.08 10.79 4 11.38 4 12c0 4.41 3.59 8 8 8"}),"TravelExplore")},24610:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)([(0,r.jsx)("path",{d:"M13 8.57c-.79 0-1.43.64-1.43 1.43s.64 1.43 1.43 1.43 1.43-.64 1.43-1.43-.64-1.43-1.43-1.43"},"0"),(0,r.jsx)("path",{d:"M13 3C9.25 3 6.2 5.94 6.02 9.64L4.1 12.2c-.25.33-.01.8.4.8H6v3c0 1.1.9 2 2 2h1v3h7v-4.68c2.36-1.12 4-3.53 4-6.32 0-3.87-3.13-7-7-7m3 7c0 .13-.01.26-.02.39l.83.66c.08.06.1.16.05.25l-.8 1.39c-.05.09-.16.12-.24.09l-.99-.4c-.21.16-.43.29-.67.39L14 13.83c-.01.1-.1.17-.2.17h-1.6c-.1 0-.18-.07-.2-.17l-.15-1.06c-.25-.1-.47-.23-.68-.39l-.99.4c-.09.03-.2 0-.25-.09l-.8-1.39c-.05-.08-.03-.19.05-.25l.84-.66c-.01-.13-.02-.26-.02-.39s.02-.27.04-.39l-.85-.66c-.08-.06-.1-.16-.05-.26l.8-1.38c.05-.09.15-.12.24-.09l1 .4c.2-.15.43-.29.67-.39L12 6.17c.02-.1.1-.17.2-.17h1.6c.1 0 .18.07.2.17l.15 1.06c.24.1.46.23.67.39l1-.4c.09-.03.2 0 .24.09l.8 1.38c.05.09.03.2-.05.26l-.85.66c.03.12.04.25.04.39"},"1")],"Psychology")},25541:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}),"RestartAlt")},25766:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M3 18c0 .55.45 1 1 1h5v-2H4c-.55 0-1 .45-1 1M3 6c0 .55.45 1 1 1h9V5H4c-.55 0-1 .45-1 1m10 14v-1h7c.55 0 1-.45 1-1s-.45-1-1-1h-7v-1c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .55.45 1 1 1s1-.45 1-1M7 10v1H4c-.55 0-1 .45-1 1s.45 1 1 1h3v1c0 .55.45 1 1 1s1-.45 1-1v-4c0-.55-.45-1-1-1s-1 .45-1 1m14 2c0-.55-.45-1-1-1h-9v2h9c.55 0 1-.45 1-1m-5-3c.55 0 1-.45 1-1V7h3c.55 0 1-.45 1-1s-.45-1-1-1h-3V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .55.45 1 1 1"}),"TuneRounded")},26842:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M9 16.17 5.53 12.7a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L20.29 7.71c.39-.39.39-1.02 0-1.41a.996.996 0 0 0-1.41 0z"}),"CheckRounded")},30351:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M18 19H6c-.55 0-1-.45-1-1V6c0-.55.45-1 1-1h5c.55 0 1-.45 1-1s-.45-1-1-1H5c-1.11 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-6c0-.55-.45-1-1-1s-1 .45-1 1v5c0 .55-.45 1-1 1M14 4c0 .55.45 1 1 1h2.59l-9.13 9.13c-.39.39-.39 1.02 0 1.41s1.02.39 1.41 0L19 6.41V9c0 .55.45 1 1 1s1-.45 1-1V4c0-.55-.45-1-1-1h-5c-.55 0-1 .45-1 1"}),"OpenInNewRounded")},38693:(e,t,l)=>{"use strict";l.r(t),l.d(t,{default:()=>oY});var o=l(95155),r=l(12115),s=l(20063),n=l(33567),a=l(94049),i=l(25635),d=l(91871),c=l(5421),u=l(41983),p=l(78470),f=l(50430),m=l(22003),h=l(2778),g=l(52363),x=l(65036),w=l(50001),v=l(9562),b=l(75912),y=l(15485);let j=(0,y.A)((0,o.jsx)("path",{d:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z"}),"ArrowBack");var A=l(86946);let C=(0,y.A)((0,o.jsx)("path",{d:"m19 9 1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25z"}),"AutoAwesome");var S=l(38343),k=l(25766),T=l(48116),M=l(2300),I=l(28548),N=l(4474),F=l(99944),P=l(9957),R=l(21067),z=l(36314),H=l(86973),E=l(73288),W=l(22539),L=l(74879),D=l(90057),B=l(17897),V=l(43076),O=l(93764),U=l(57563);function K(e){var t;return null==(t=e.data)?void 0:t.edgeType}function G(e){return"mcp"===K(e)}function X(e){return"resource"===K(e)}var _=l(18466),$=l(61033);function q(e){return{id:e.id,label:e.data.label,type:e.type||e.data.type}}var Y=l(38700);l(18037);var Q=l(8532),J=l(56422),Z=l(56350),ee=l(77842),et=l(55930),el=l(59323),eo=l(20195),er=l(11096),es=l(52393),en=l(96429),ea=l(98008),ei=l(41603),ed=l(36773);let ec=(0,E.h)("components/flow/FlowBuilder/NodePalette.tsx"),eu="NodePalette",ep=(0,T.Ay)(M.A)(e=>{let{theme:t}=e;return{padding:t.spacing(1.4),width:"218px",height:"100%",minHeight:0,flexShrink:0,display:"flex",flexDirection:"column",gap:t.spacing(1.2),overflowY:"auto",border:"1px solid ".concat(t.palette.divider),borderRadius:16,backgroundColor:"dark"===t.palette.mode?"rgba(17, 22, 41, 0.86)":"rgba(255, 255, 255, 0.9)",boxShadow:"dark"===t.palette.mode?"0 16px 45px rgba(0,0,0,.22)":"0 16px 45px rgba(49,45,99,.09)",backdropFilter:"blur(18px)",[t.breakpoints.down("md")]:{width:"176px",padding:t.spacing(1)},[t.breakpoints.down("md")]:{width:"100%",height:"68px",padding:t.spacing(.65),gap:t.spacing(.6),alignItems:"flex-start",overflowX:"auto",overflowY:"hidden"}}}),ef=(0,T.Ay)(M.A,{shouldForwardProp:e=>"nodeType"!==e})(e=>{let{theme:t,nodeType:l}=e;return{padding:t.spacing(1.25),width:"100%",minWidth:0,borderRadius:"12px",backgroundColor:(0,Q.X4)(t.palette.background.paper,.72),border:"1px solid ".concat(t.palette.divider),borderLeft:"3px solid ".concat("process"===l?t.palette.primary.main:"finish"===l?t.palette.success.main:"subflow"===l?t.palette.warning.main:"resource"===l?ei.nH:"signal"===l?ei.vp:"trigger"===l?ei.$Q:t.palette.info.main),boxShadow:"none",transition:"transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease",cursor:"grab","&:hover":{transform:"translateY(-2px)",borderColor:(0,Q.X4)("process"===l?t.palette.primary.main:"finish"===l?t.palette.success.main:"subflow"===l?t.palette.warning.main:"resource"===l?ei.nH:"signal"===l?ei.vp:"trigger"===l?ei.$Q:t.palette.info.main,.55),boxShadow:"0 0 0 1px ".concat("process"===l?t.palette.primary.main:"finish"===l?t.palette.success.main:"subflow"===l?t.palette.warning.main:"resource"===l?ei.nH:"signal"===l?ei.vp:"trigger"===l?ei.$Q:t.palette.info.main,", 0 14px 30px rgba(0,0,0,0.12)")},"&:active":{cursor:"grabbing"},[t.breakpoints.down("md")]:{width:64,minWidth:64,minHeight:54,padding:t.spacing(.55),flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",borderLeftWidth:2}}}),em=(0,T.Ay)(a.default,{shouldForwardProp:e=>"nodeType"!==e})(e=>{let{theme:t,nodeType:l}=e;return{display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid ".concat("process"===l?t.palette.primary.light:"finish"===l?t.palette.success.light:"subflow"===l?t.palette.warning.light:"resource"===l?"#4DB6AC":"signal"===l?"#B39DDB":"trigger"===l?ei.C2:t.palette.info.light),marginBottom:t.spacing(1),paddingBottom:t.spacing(.5),[t.breakpoints.down("md")]:{width:"100%",marginBottom:0,paddingBottom:0,borderBottom:0,justifyContent:"center"}}}),eh=(0,T.Ay)(a.default)(e=>{let{theme:t}=e;return{display:"flex",alignItems:"center",gap:"8px",[t.breakpoints.down("md")]:{flexDirection:"column",justifyContent:"center",gap:2}}}),eg=e=>{let{authoringMode:t="guided",onAddNode:l}=e;ec.debug("".concat(eu,": Entering component"));let{t:s}=(0,ed.s9)(),n=(0,r.useMemo)(()=>(e=>[{type:"process",label:e("flows.palette.process"),shortLabel:e("flows.palette.processShort"),description:e("flows.palette.processHelp")},{type:"finish",label:e("flows.palette.finish"),shortLabel:e("flows.palette.finishShort"),description:e("flows.palette.finishHelp")},{type:"mcp",label:e("flows.palette.mcp"),shortLabel:e("flows.palette.mcpShort"),description:e("flows.palette.mcpHelp")},{type:"subflow",label:e("flows.palette.subflow"),shortLabel:e("flows.palette.subflowShort"),description:e("flows.palette.subflowHelp")},{type:"resource",label:e("flows.palette.resource"),shortLabel:e("flows.palette.resourceShort"),description:e("flows.palette.resourceHelp")},{type:"signal",label:e("flows.palette.signal"),shortLabel:e("flows.palette.signalShort"),description:e("flows.palette.signalHelp")},{type:"trigger",label:e("flows.palette.trigger"),shortLabel:e("flows.palette.triggerShort"),description:e("flows.palette.triggerHelp")}])(s),[s]),[d,c]=(0,r.useState)(""),u=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=()=>{var e,t;null==(e=u.current)||e.focus(),null==(t=u.current)||t.select()};return document.addEventListener("openFlowQuickAdd",e),()=>document.removeEventListener("openFlowQuickAdd",e)},[]);let p=(0,r.useCallback)(e=>{ec.debug("".concat(eu,".addNodeFromPalette: Adding ").concat(e," node")),null==l||l(e),ec.info("".concat(eu,".addNodeFromPalette: Requested ").concat(e," node"))},[l]),f=(0,r.useMemo)(()=>{let e=d.trim().toLowerCase();return n.filter(e=>"advanced"===t||"process"===e.type).filter(t=>!e||"".concat(t.label," ").concat(t.description," ").concat(t.shortLabel).toLowerCase().includes(e))},[t,n,d]);return ec.debug("".concat(eu,": Rendering component")),(0,o.jsxs)(ep,{elevation:2,children:[(0,o.jsxs)(a.default,{sx:{display:{xs:"none",md:"flex"},alignItems:"baseline",justifyContent:"space-between"},children:[(0,o.jsx)(i.A,{className:"node-palette-title",variant:"subtitle1",fontWeight:800,children:s("flows.palette.title")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:"A"})]}),(0,o.jsx)(v.A,{inputRef:u,value:d,onChange:e=>c(e.target.value),size:"small",placeholder:s("flows.palette.search"),inputProps:{"aria-label":s("flows.palette.searchAria")},sx:{display:{xs:"none",md:"flex"}},InputProps:{startAdornment:(0,o.jsx)(J.A,{position:"start",children:(0,o.jsx)(ea.A,{fontSize:"small"})})}}),(0,o.jsxs)(a.default,{display:"flex",flexDirection:{xs:"row",md:"column"},gap:{xs:.75,md:1},width:{xs:"max-content",md:"100%"},children:[f.map(e=>(0,o.jsxs)(ef,{nodeType:e.type,elevation:1,draggable:!0,role:"button",tabIndex:0,"aria-label":"".concat(e.label,": ").concat(e.description),title:"".concat(e.label," — ").concat(e.description),onDragStart:t=>((e,t)=>{var l;ec.debug("".concat(eu,".onDragStart: Entering method with nodeType=").concat(t)),e.dataTransfer.setData("application/reactflow",t),e.dataTransfer.effectAllowed="move";let o=document.createElement("div"),r=n.find(e=>e.type===t);o.textContent=null!=(l=null==r?void 0:r.label)?l:s("flows.palette.step"),Object.assign(o.style,{padding:"10px",background:"white",border:"1px solid #ccc",borderRadius:"8px"}),document.body.appendChild(o),ec.debug("".concat(eu,".onDragStart: Created drag preview element"));try{e.dataTransfer.setDragImage(o,75,25),ec.debug("".concat(eu,".onDragStart: Set drag image with offset (75, 25)"))}catch(e){ec.error("".concat(eu,".onDragStart: Error setting drag image:"),e)}setTimeout(()=>{document.body.removeChild(o),ec.debug("".concat(eu,".onDragStart: Removed drag preview element"))},0),ec.debug("".concat(eu,".onDragStart: Drag operation initialized"))})(t,e.type),onDragEnd:t=>{var l;return l=e.type,void ec.debug("".concat(eu,".onDragEnd: Drag operation ended for nodeType=").concat(l))},onClick:()=>p(e.type),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),p(e.type))},children:[(0,o.jsx)(em,{nodeType:e.type,children:(0,o.jsxs)(eh,{children:[(e=>{switch(e){case"process":return(0,o.jsx)(en.default,{color:"primary"});case"finish":return(0,o.jsx)(ee.A,{color:"success"});case"mcp":return(0,o.jsx)(es.A,{color:"info"});case"subflow":return(0,o.jsx)(et.A,{color:"warning"});case"resource":return(0,o.jsx)(el.A,{sx:{color:ei.nH}});case"signal":return(0,o.jsx)(eo.A,{sx:{color:ei.vp}});case"trigger":return(0,o.jsx)(er.A,{sx:{color:ei.$Q}});default:return(0,o.jsx)(Z.A,{color:"primary"})}})(e.type),(0,o.jsx)(i.A,{variant:"caption",fontWeight:"bold",sx:{display:{xs:"block",md:"none"},fontSize:"0.62rem",lineHeight:1},children:e.shortLabel}),(0,o.jsx)(i.A,{variant:"subtitle2",fontWeight:"bold",sx:{display:{xs:"none",md:"block"}},children:e.label})]})}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{display:{xs:"none",md:"block"}},children:e.description})]},e.type)),0===f.length&&(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{px:.5,py:1},children:s("flows.palette.noMatches")})]})]})};var ex=l(3004),ew=l(8279),ev=l(41602),eb=l(49501),ey=l(17681),ej=l(73707),eA=l(23820);let eC=(0,y.A)((0,o.jsx)("path",{fillRule:"evenodd",d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2M10 17H5v-2h5zm0-4H5v-2h5zm0-4H5V7h5zm4.82 6L12 12.16l1.41-1.41 1.41 1.42L17.99 9l1.42 1.42z"}),"FactCheck");var eS=l(60691),ek=l(76808),eT=l(36741),eM=l(19875);let eI=/\$\{var:([^}]+)\}/g,eN=/^[A-Za-z_][\w-]*$/;function eF(e){return"string"==typeof e&&eN.test(e)}let eP=/\$\{kv:([^}]+)\}/g,eR=["global","flow","folder"];function ez(e){let t=(null!=e?e:"").trim(),l=t.indexOf("/");if(l>0){let e=t.slice(0,l);if(eR.includes(e))return{scope:e,key:t.slice(l+1).trim()}}return{scope:"folder",key:t}}function eH(e,t){let l=(null!=t?t:"").trim();return l?"folder"===e?l:"".concat(e,"/").concat(l):""}let eE=/^[A-Za-z_][\w-]*$/;function eW(e){return"string"==typeof e&&eE.test(e)}function eL(e){var t,l,o;return null!=(o=null!=(l=null==(t=e.data)?void 0:t.type)?l:e.type)?o:"unknown"}function eD(e){var t;return(null==(t=e.data)?void 0:t.label)||e.id}function eB(e){var t;return(null==(t=e.data)?void 0:t.edgeType)==="mcp"}function eV(e){var t;return(null==(t=e.data)?void 0:t.edgeType)==="resource"}function eO(e){return eB(e)||eV(e)}function eU(e,t,l){let o=new Map(t.map(e=>[e.id,e])),r=new Set;for(let t of l){var s,n;if(!eB(t))continue;let l=null;if(t.source===e?l=t.target:t.target===e&&(l=t.source),!l)continue;let a=o.get(l);if(!a||"mcp"!==eL(a))continue;let i=null==(n=a.data)||null==(s=n.properties)?void 0:s.boundServer;"string"==typeof i&&i&&r.add(i)}return r}function eK(e,t,l){let o=new Map(t.map(e=>[e.id,e])),r=[],s=new Set;for(let t of l){var n;if(eO(t))continue;let l=null;t.source===e?l=t.target:t.target===e&&(null==(n=t.data)?void 0:n.bidirectional)&&(l=t.source),!l||s.has(l)||(s.add(l),r.push(l))}let a=r.map(e=>o.get(e)).filter(e=>!!e).map(e=>{var t;return{id:e.id,label:null==(t=e.data)?void 0:t.label,type:eL(e)}});return new Set((0,_.E9)(a).values())}function eG(e){let t=e.replace(/\S*\$\{[^}]*\}\S*/g," ");return/(?:^|[\s("'`])file:\/\/(?:\/|[^/\s]+\/)[^\s<>"'`]+/i.test(t)||/(?:^|[\s("'`])(?:[A-Za-z]:[\\/][^\s<>"'`]*|\\\\[^\\\s<>"'`]+\\[^\\\s<>"'`]+(?:\\[^\s<>"'`]*)?)/.test(t)||/(?:^|[\s("'`])\/(?!\/)[^\s<>"'`]+/.test(t)}function eX(e){if("string"!=typeof e)return!1;let t=e.trim();if(!t)return!1;if(/^\$\{global:[^{}]+\}$/.test(t))return!0;if(t.includes("${"))return!1;if(/^file:/i.test(t))try{let e=new URL(t);return"file:"===e.protocol&&(!!e.hostname||!!e.pathname)}catch(e){return!1}return!t.includes("\0")}function e_(e){var t,l,o,r,s,n,a,i,d,c,u,p,f,m,h,g,x,w,v,b,y,j,A,C,S,k;let T=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},M=[],I=Array.isArray(null==e?void 0:e.nodes)?e.nodes:[],N=Array.isArray(null==e?void 0:e.edges)?e.edges:[],F=(e,t,l,o)=>M.push({severity:e,code:t,message:l,nodeId:null==o?void 0:o.id,nodeLabel:o?eD(o):void 0}),P=new Map((null!=(t=T.models)?t:[]).map(e=>[e.id,e])),R=new Map((null!=(l=T.servers)?l:[]).map(e=>[e.name,e])),z=!!T.models,H=!!T.servers,E=I.filter(e=>"start"===eL(e)),W=I.filter(e=>"finish"===eL(e)),L=I.filter(e=>"process"===eL(e)),D=I.filter(e=>"mcp"===eL(e));if(0===E.length)F("error","no-start-node","The flow has no Start node, so it has no entry point.");else if(E.length>1)for(let e of E.slice(1))F("error","multiple-start-nodes","The flow has more than one Start node; only one is allowed.",e);for(let e of(0===W.length&&F("warning","no-finish-node","The flow has no Finish node; it will run but never reaches a defined end."),L)){let t=null!=(r=null==(o=e.data)?void 0:o.properties)?r:{},l=t.boundModel;if(l){if(z&&!P.has(l)){let l="string"==typeof t.modelName&&t.modelName?' (was "'.concat(t.modelName,'")'):"";F("error","process-model-missing",'Process node "'.concat(eD(e),'" is bound to a model that no longer exists').concat(l,"."),e)}}else F("error","process-missing-model",'Process node "'.concat(eD(e),'" has no model bound.'),e)}for(let e of D){let t=(null!=(n=null==(s=e.data)?void 0:s.properties)?n:{}).boundServer;if(t){if(H&&!R.has(t))F("warning","mcp-server-missing",'MCP node "'.concat(eD(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(H){let l=R.get(t);if(l.status&&"connected"!==l.status){let o="disabled"===l.status?"disabled":"not connected (".concat(l.status,")");F("warning","mcp-server-disconnected",'MCP node "'.concat(eD(e),'" is bound to server "').concat(t,'", which is currently ').concat(o,". It will provide tools again once it reconnects."),e)}}}else F("warning","mcp-missing-server",'MCP node "'.concat(eD(e),'" is not bound to a server.'),e);N.some(t=>eB(t)&&(t.source===e.id||t.target===e.id))||F("warning","mcp-node-unconnected",'MCP node "'.concat(eD(e),'" is not connected to any Process node.'),e)}if(T.fileAccessMcp){let e=T.fileAccessMcp,t=Object.entries(e).filter(e=>{let[,t]=e;return t.configured&&!t.disabled&&"usable"===t.usability}).map(e=>{let[t]=e;return t}),l=Object.values(e).some(e=>e.configured&&!e.disabled&&"unknown"===e.usability);for(let o of L)if((function(e){var t,l;let o=null!=(l=null==(t=e.data)?void 0:t.properties)?l:{},r=[];return"string"==typeof o.promptTemplate&&o.promptTemplate&&r.push(o.promptTemplate),"isolated"===o.inputMode&&"string"==typeof o.isolatedPrompt&&o.isolatedPrompt&&r.push(o.isolatedPrompt),r})(o).some(eG)){if(0===t.length){l||F("warning","process-filepath-mcp-unavailable",'Process node "'.concat(eD(o),'" contains a literal filepath, but no configured file-access MCP server is currently available. Enable or reconnect one so this flow can access the path.'),o);continue}!l&&t.every(t=>!function(e,t,l){return!![...Array.isArray(t.roots)?t.roots:[],...l.filter(t=>{var l,o;return(null==(o=t.data)||null==(l=o.properties)?void 0:l.boundServer)===e}).flatMap(e=>{var t,l;let o=null==(l=e.data)||null==(t=l.properties)?void 0:t.roots;return Array.isArray(o)?o:[]})].some(eX)||eX(t.rootPath)}(t,e[t],D))&&F("warning","process-filepath-mcp-roots-missing",'Process node "'.concat(eD(o),'" contains a literal filepath, but the available file-access MCP servers have no effective roots configured. Add roots globally or on the corresponding MCP node in this flow.'),o)}}for(let e of I.filter(e=>"resource"===eL(e))){let t=null!=(i=null==(a=e.data)?void 0:a.properties)?i:{},l="run"===t.scope?"run":"mcp",o="string"==typeof t.boundServer?t.boundServer:"",r="string"==typeof t.uri?t.uri:"",s="string"==typeof t.runName?t.runName.trim():"";"mcp"!==l||o&&r||F("warning","resource-missing-binding",'Resource node "'.concat(eD(e),'" has no ').concat(o?"resource URI":"server"," bound; connected steps will receive nothing."),e),"run"!==l||s||F("warning","resource-missing-binding",'Resource node "'.concat(eD(e),'" is a run artifact with no name; give it a name so steps can produce/consume it.'),e),"run"===l&&s&&!eF(s)&&F("warning","resource-run-name",'Resource node "'.concat(eD(e),'" is named "').concat(s,'", 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"===l&&o&&H&&!R.has(o)&&F("warning","resource-server-missing",'Resource node "'.concat(eD(e),'" is bound to server "').concat(o,"\", which isn't in your current MCP server list."),e);let n=N.filter(t=>eV(t)&&(t.source===e.id||t.target===e.id));0===n.length&&F("warning","resource-node-unconnected",'Resource node "'.concat(eD(e),'" is not connected to any Process node.'),e);let d=n.filter(t=>t.target===e.id);"mcp"===l&&d.length>0&&F("error","resource-produce-static",'Resource node "'.concat(eD(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"===l&&d.length>1&&F("warning","resource-multiple-producers",'Resource node "'.concat(eD(e),'" is produced by ').concat(d.length," steps; the last writer wins. Consider one producer per artifact."),e),"run"===l&&0===d.length&&n.length>0&&F("warning","resource-consumed-never-produced",'Resource node "'.concat(eD(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 I.filter(e=>"signal"===eL(e))){let t=null!=(c=null==(d=e.data)?void 0:d.properties)?c:{};("string"==typeof t.topic?t.topic.trim():"")||F("warning","signal-missing-topic",'Signal node "'.concat(eD(e),'" has no topic; it emits nothing. Give it a topic that a flow-event trigger can listen for.'),e)}if(E.length>0){let e=function(e){let t=new Map,l=(e,l)=>{t.has(e)||t.set(e,[]),t.get(e).push(l)};for(let t of e){var o;!eO(t)&&(l(t.source,t.target),(null==(o=t.data)?void 0:o.bidirectional)&&l(t.target,t.source))}return t}(N);for(let t of E)(null==(u=e.get(t.id))?void 0:u.length)||F("error","start-no-outgoing","The Start node is not connected to anything; the flow cannot run.",t);let t=function(e,t){let l=new Set(e),o=[...e];for(;o.length;){var r;let e=o.shift();for(let s of null!=(r=t.get(e))?r:[])l.has(s)||(l.add(s),o.push(s))}return l}(E.map(e=>e.id),e);for(let e of[...L,...W])t.has(e.id)||F("warning","unreachable-node","".concat("finish"===eL(e)?"Finish":"Process",' node "').concat(eD(e),'" is not reachable from the Start node.'),e)}for(let e of I.filter(e=>"subflow"===eL(e))){let t=N.filter(t=>{var l;return!eO(t)&&(t.source===e.id||t.target===e.id&&!!(null==(l=t.data)?void 0:l.bidirectional))});t.length>1&&F("error","subflow-multiple-outgoing",'Subflow node "'.concat(eD(e),'" has ').concat(t.length," outgoing connections; a subflow can only have one (either A > B > C or a bidirectional A <> B)."),e);let l=null!=(f=null==(p=e.data)?void 0:p.properties)?f:{},o="string"==typeof l.subflowId&&l.subflowId?l.subflowId:void 0,r=Array.isArray(l.parallelSubflowIds)?l.parallelSubflowIds.filter(e=>"string"==typeof e&&!!e):[];o&&r.length>0&&F("error","subflow-both-targets",'Subflow node "'.concat(eD(e),'" sets both a single "subflowId" and "parallelSubflowIds"; use one or the other.'),e);let s=!0===l.mapOverList;s&&r.length>0&&F("error","subflow-map-and-parallel",'Subflow node "'.concat(eD(e),'" combines "mapOverList" with "parallelSubflowIds"; map-over-list runs a single child once per item and cannot be combined with parallel fan-out.'),e),s&&!o&&0===r.length&&F("error","subflow-map-no-child",'Subflow node "'.concat(eD(e),'" has "mapOverList" but no child flow ("subflowId"); select a flow to run once per item.'),e);let n=Array.isArray(l.spawnBriefs)?l.spawnBriefs.filter(e=>"string"==typeof e&&""!==e.trim()):[];n.length>0&&!o&&F("error","subflow-spawn-no-child",'Subflow node "'.concat(eD(e),'" has spawn briefs but no sub-agent flow ("subflowId"); select the flow to spawn once per brief.'),e),n.length>0&&r.length>0&&F("error","subflow-spawn-and-parallel",'Subflow node "'.concat(eD(e),'" combines "spawnBriefs" with "parallelSubflowIds"; spawn briefs run one sub-agent per brief and cannot be combined with a multi-flow fan-out list.'),e),n.length>0&&s&&F("error","subflow-spawn-and-map",'Subflow node "'.concat(eD(e),'" combines "spawnBriefs" with "mapOverList"; use one lane source or the other.'),e);let a="string"==typeof l.parallelSubflowIdsVar?l.parallelSubflowIdsVar.trim():"";if(a&&(eF(a)||F("warning","subflow-parallel-var-name",'Subflow node "'.concat(eD(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),s&&F("error","subflow-map-and-parallel-var",'Subflow node "'.concat(eD(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),I.some(e=>{var t,l;let o=null==(l=e.data)||null==(t=l.properties)?void 0:t.captureVariable;return"string"==typeof o&&o.trim()===a})||F("warning","subflow-parallel-var-uncaptured",'Subflow node "'.concat(eD(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===l.allowCallerFanout&&s&&F("error","subflow-map-and-caller-fanout",'Subflow node "'.concat(eD(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),r.length>0||n.length>0){let t=l.concurrencyLimit;"number"==typeof t&&t<1&&F("warning","subflow-concurrency-limit",'Subflow node "'.concat(eD(e),'" has a concurrencyLimit of ').concat(t,"; it must be at least 1 (the runtime default will be used)."),e)}}{let e=new Map(I.map(e=>[e.id,e])),t=new Set;for(let l of N){if(eO(l))continue;let o=null==(m=l.data)?void 0:m.condition;if(!o||"object"!=typeof o)continue;let r=e.get(l.source),s=r?eL(r):"unknown";if("process"!==s){F("error","edge-condition-non-process","An edge leaving ".concat("unknown"===s?"an unknown":"the ".concat(s),' node "').concat(r?eD(r):l.source,'" has a routing condition, but only process nodes can route on a condition.'),null!=r?r:void 0);continue}t.add(l.source),(0,eM.C)(o.kind)?"always"===o.kind||("string"!=typeof o.value||0===o.value.length?F("warning","edge-condition-value",'Process node "'.concat(eD(r),'" has an outgoing edge condition with no "value"; it will never match.'),r):"regex"!==o.kind||(0,eM.wM)(o.value)||F("warning","edge-condition-regex",'Process node "'.concat(eD(r),'" has an outgoing edge with a regex condition that does not compile; it will never match.'),r)):F("warning","edge-condition-kind",'Process node "'.concat(eD(r),'" has an outgoing edge whose condition kind "').concat(String(o.kind),'" is unknown; it will never match.'),r)}for(let l of t){let t=e.get(l);t&&(N.some(e=>{var t,o;return!eO(e)&&(e.source===l?!(null==(o=e.data)?void 0:o.condition)||"always"===e.data.condition.kind&&!e.data.condition.negate:e.target===l&&null!=(t=e.data)&&!!t.bidirectional)})||F("warning","edge-condition-no-fallback",'Process node "'.concat(eD(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 I){let l=null==(g=t.data)||null==(h=g.properties)?void 0:h.captureVariable;if("string"==typeof l&&l.trim()){let o=l.trim();e.add(o),eF(o)||F("warning","capture-var-name","".concat("subflow"===eL(t)?"Subflow":"Process",' node "').concat(eD(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"],l=new Set;for(let o of I){let r=null!=(w=null==(x=o.data)?void 0:x.properties)?w:{};for(let s of t){let t=r[s];if("string"==typeof t&&t)for(let r of function(e){let t;if("string"!=typeof e||0===e.length)return[];let l=new Set;for(eI.lastIndex=0;null!==(t=eI.exec(e));){let e=t[1].trim();e&&l.add(e)}return[...l]}(t)){if(e.has(r))continue;let t="".concat(o.id,":").concat(r);l.has(t)||(l.add(t),F("warning","var-ref-uncaptured","".concat(eD(o)," references ${var:").concat(r,'} but no step in this flow captures "').concat(r,'" (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 I){let t=null==(b=e.data)||null==(v=b.properties)?void 0:v.captureKv;if("string"==typeof t&&t.trim()){let{key:l}=ez(t.trim());eW(l)||F("warning","capture-kv-name","".concat("subflow"===eL(e)?"Subflow":"Process",' node "').concat(eD(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 l of I){let o=null!=(j=null==(y=l.data)?void 0:y.properties)?j:{};for(let r of e){let e=o[r];if("string"==typeof e&&e)for(let o of function(e){let t;if("string"!=typeof e||0===e.length)return[];let l=new Set;for(eP.lastIndex=0;null!==(t=eP.exec(e));){let e=t[1].trim();e&&l.add(e)}return[...l]}(e)){let{key:e}=ez(o);if(eW(e))continue;let r="".concat(l.id,":").concat(o);t.has(r)||(t.add(r),F("warning","kv-ref-name","".concat(eD(l)," references ${kv:").concat(o,"}, whose key is not a valid name (letters, digits, _ and - only, not starting with a digit); it resolves to empty."),l))}}}}for(let e of L){let t=null==(C=e.data)||null==(A=C.properties)?void 0:A.promptTemplate;if("string"!=typeof t||!t)continue;let l=eU(e.id,I,N),o=null,r=new Set,s=new Set;for(let n of(0,$.A$)(t)){if("handoff"===n.server){let t="handoff:".concat(n.name);if(s.has(t))continue;s.add(t),r.add(n.name),o||(o=eK(e.id,I,N)),o.has(n.name)||F("warning","handoff-pill-obsolete",'Process node "'.concat(eD(e),'" references handoff tool "').concat(n.name,'", which no longer exists (the target node was removed, or renamed so the tool name changed). Update or remove the pill.'),e);continue}let t="".concat(n.kind,":").concat(n.server,":").concat(n.name);!s.has(t)&&(s.add(t),l.has(n.server)?"tool"===n.kind&&T.serverTools&&T.serverTools[n.server]&&!T.serverTools[n.server].includes(n.name)&&F("warning","tool-unavailable",'Process node "'.concat(eD(e),'" references tool "').concat(n.name,'" which server "').concat(n.server,'" does not currently expose.'),e):F("error","tool-pill-disconnected",'Process node "'.concat(eD(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))}if(r.size>0)for(let t of null!=o?o:eK(e.id,I,N))r.has(t)||F("warning","handoff-target-unreferenced",'Process node "'.concat(eD(e),'" can hand off to "').concat(t,'" but its prompt never references ${tool:handoff__').concat(t,"}, so the model may never route there."),e)}if(T.serverTools)for(let e of L){let t=eU(e.id,I,N),l=new Set;for(let o of t){let t=T.serverTools[o];if(Array.isArray(t)&&0===t.length&&F("warning","mcp-server-no-tools",'Process node "'.concat(eD(e),'" is connected to MCP server "').concat(o,'", which currently exposes 0 tools. The connection has no effect until the server provides tools.'),e),Array.isArray(t))for(let r of Array.isArray(null==(k=e.data)||null==(S=k.properties)?void 0:S.enabledTools)?e.data.properties.enabledTools:[]){let s="enabledTool:".concat(o,":").concat(r);!l.has(s)&&(t.includes(r)||(l.add(s),F("warning","tool-unavailable",'Process node "'.concat(eD(e),'" has enabledTool "').concat(r,'" which server "').concat(o,'" does not currently expose.'),e)))}}}let B=M.filter(e=>"error"===e.severity).length,V=M.length-B;return{issues:M,errorCount:B,warningCount:V,isRunnable:0===B}}var e$=l(37209);let eq=(0,E.h)("components/flow/FlowBuilder/FlowValidationButton"),eY=e=>{var t,l;let{nodes:s,edges:n}=e,{t:c,tp:u}=(0,ed.s9)(),[p,f]=(0,r.useState)(!1),[m,h]=(0,r.useState)(null),[g,x]=(0,r.useState)(!1),[w,v]=(0,r.useState)(null),[b,y]=(0,r.useState)(null),j=(0,r.useRef)(null),A=(0,r.useRef)(null),C=(0,r.useId)(),S=(0,r.useId)(),k=(0,r.useId)();(0,r.useEffect)(()=>{if(!p)return;let e=window.requestAnimationFrame(()=>{var e;null==(e=A.current)||e.focus()});return()=>window.cancelAnimationFrame(e)},[p]);let T=(0,r.useCallback)(()=>{f(!1),window.requestAnimationFrame(()=>{var e;null==(e=j.current)||e.focus()})},[]),F=(0,r.useCallback)(()=>{var e;let t=null==(e=A.current)?void 0:e.contains(document.activeElement);f(!1),t&&window.requestAnimationFrame(()=>{var e;null==(e=j.current)||e.focus()})},[]),P=(0,r.useCallback)(async()=>{x(!0),y(null);try{var e,t,l,o,r,a;let i=null!=(e=await V.N.tryLoadModels())?e:void 0,d=await B.S.loadServerConfigs(),c=Array.isArray(d)?d:void 0,u=null==c?void 0:c.map(e=>({name:e.name,status:e.disabled?"disabled":void 0})),p={},f=new Map,m=null!=(t=null==c?void 0:c.filter(e=>!!e.hostPathAccess))?t:[],h=new Set(m.map(e=>e.name));if(c){let e=new Map(c.map(e=>[e.name,!!e.disabled])),t=new Set;for(let e of s){let s=null!=(a=null==e||null==(l=e.data)?void 0:l.type)?a:null==e?void 0:e.type,n=null==e||null==(r=e.data)||null==(o=r.properties)?void 0:o.boundServer;"mcp"===s&&"string"==typeof n&&n&&t.add(n)}for(let{name:e,disabled:l}of m)l||t.add(e);await Promise.all([...t].map(async t=>{if(!e.get(t))try{let e=await B.S.listServerTools(t);!e.error&&Array.isArray(e.tools)?(p[t]=e.tools.map(e=>null==e?void 0:e.name).filter(e=>"string"==typeof e),f.set(t,"usable")):h.has(t)&&f.set(t,"unknown")}catch(e){h.has(t)&&f.set(t,"unknown"),eq.debug('Could not gather MCP tool list for "'.concat(t,'" during the flow check'),e)}}))}let g=c?Object.fromEntries(m.map(e=>[e.name,function(e,t,l){var o;let r=t.find(t=>t.name===e);if(!r)return{configured:!1,disabled:!1,usability:"unavailable"};let s=!!r.disabled;return{configured:!0,disabled:s,usability:s?"unavailable":null!=(o=l.get(e))?o:"unknown",roots:r.roots,rootPath:r.rootPath}}(e.name,c,f)])):void 0,x=e_({nodes:s,edges:n},{models:i,servers:u,serverTools:p,fileAccessMcp:g});v(x.issues)}catch(e){eq.warn("Flow validation failed to run",e),v(null),y(c("flows.validation.failed"))}finally{x(!1)}},[s,n,c]),z=(0,r.useCallback)(e=>{h(e.currentTarget),f(!0),v(null),y(null),P()},[P]),H=(0,r.useCallback)(e=>{e&&(T(),document.dispatchEvent(new CustomEvent("selectNode",{detail:{nodeId:e}})))},[T]),E=null!=(t=null==w?void 0:w.filter(e=>"error"===e.severity).length)?t:0,W=(null!=(l=null==w?void 0:w.length)?l:0)-E;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(d.A,{ref:j,id:C,variant:"outlined",color:"primary",onClick:z,startIcon:(0,o.jsx)(eC,{}),"aria-haspopup":"dialog","aria-expanded":p,"aria-controls":S,sx:{textTransform:"none"},children:[c("flows.validation.check"),w&&w.length>0&&(0,o.jsx)(I.A,{size:"small",color:E>0?"error":"warning",label:w.length,sx:{ml:1,height:20}})]}),(0,o.jsx)(ex.A,{open:p,anchorEl:m,placement:"bottom-end",sx:{zIndex:e=>e.zIndex.modal+1},modifiers:[{name:"offset",options:{offset:[0,10]}}],children:(0,o.jsx)(ew.x,{onClickAway:F,children:(0,o.jsxs)(M.A,{ref:A,id:S,role:"dialog","aria-modal":"false","aria-labelledby":k,"aria-busy":g,tabIndex:-1,onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),T())},elevation:18,sx:{width:"min(92vw, 440px)",maxHeight:"min(68dvh, 560px)",overflow:"hidden",border:1,borderColor:"divider",borderRadius:3},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1,px:2,py:1.5},children:[(0,o.jsx)(i.A,{id:k,variant:"subtitle1",fontWeight:800,children:c("flows.validation.title")}),w&&(0,o.jsxs)(a.default,{sx:{display:"flex",gap:.75,ml:.5},children:[E>0&&(0,o.jsx)(I.A,{size:"small",color:"error",label:u("flows.validation.error",E)}),W>0&&(0,o.jsx)(I.A,{size:"small",color:"warning",label:u("flows.validation.warning",W)})]})]}),(0,o.jsx)(R.A,{}),(0,o.jsx)(a.default,{sx:{maxHeight:"min(52dvh, 420px)",overflowY:"auto",p:1},children:g?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:2,py:3,justifyContent:"center"},children:[(0,o.jsx)(N.default,{size:22}),(0,o.jsx)(i.A,{color:"text.secondary",children:c("flows.validation.checking")})]}):b?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,py:2,px:1},children:[(0,o.jsx)(eS.A,{color:"error"}),(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{fontWeight:700,children:c("flows.validation.unavailable")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:b})]})]}):w&&0===w.length?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1.5,py:3,px:1,justifyContent:"center"},children:[(0,o.jsx)(eT.A,{color:"success"}),(0,o.jsx)(i.A,{children:c("flows.validation.healthy")})]}):(0,o.jsx)(ev.A,{dense:!0,disablePadding:!0,children:(null!=w?w:[]).map((e,t)=>{var l,r;let s=!!e.nodeId,n=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(eb.A,{sx:{minWidth:36},children:"error"===e.severity?(0,o.jsx)(eS.A,{color:"error",fontSize:"small"}):(0,o.jsx)(ek.A,{color:"warning",fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:(0,e$.z)(e,c),secondary:s?c("flows.validation.revealNode",{node:null!=(r=null!=(l=e.nodeLabel)?l:e.nodeId)?r:""}):void 0})]});return s?(0,o.jsx)(ej.A,{onClick:()=>H(e.nodeId),alignItems:"flex-start",children:n},t):(0,o.jsx)(eA.Ay,{alignItems:"flex-start",children:n},t)})})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"flex-end",gap:1,p:1},children:[(0,o.jsx)(d.A,{onClick:P,disabled:g,children:c("flows.validation.recheck")}),(0,o.jsx)(d.A,{onClick:T,variant:"contained",children:c("flows.validation.done")})]})]})})})]})};var eQ=l(80777),eJ=l(57813),eZ=l(26466),e0=l(83478),e1=l(30351),e2=l(4097),e5=l(60700),e4=l(95070);let e3=(0,y.A)((0,o.jsx)("path",{d:"M18 13h-5v5c0 .55-.45 1-1 1s-1-.45-1-1v-5H6c-.55 0-1-.45-1-1s.45-1 1-1h5V6c0-.55.45-1 1-1s1 .45 1 1v5h5c.55 0 1 .45 1 1s-.45 1-1 1"}),"AddRounded"),e9=(0,y.A)((0,o.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2zM9 9h6c.55 0 1 .45 1 1v8c0 .55-.45 1-1 1H9c-.55 0-1-.45-1-1v-8c0-.55.45-1 1-1m6.5-5-.71-.71c-.18-.18-.44-.29-.7-.29H9.91c-.26 0-.52.11-.7.29L8.5 4H6c-.55 0-1 .45-1 1s.45 1 1 1h12c.55 0 1-.45 1-1s-.45-1-1-1z"}),"DeleteOutlineRounded");var e6=l(91287),e8=l(96362),e7=l(95906),te=l(68503);let tt=e=>{let{processNodeId:t,connections:l,beginnerMode:s=!1,onConnect:n,onRemove:d,loadServers:c}=e,{t:f}=(0,ed.s9)(),[m,h]=(0,r.useState)(!1),[g,x]=(0,r.useState)([]),[w,v]=(0,r.useState)(!1),[b,y]=(0,r.useState)(null),j=(0,r.useMemo)(()=>new Set(l.map(e=>e.serverName)),[l]),A=(0,r.useMemo)(()=>g.filter(e=>!j.has(e.name)),[g,j]),C=(0,te.E)("mcp",A),S=async()=>{h(!0),v(!0),y(null);try{x(await c())}catch(e){y(e instanceof Error?e.message:f("flows.inspector.mcpLoadError"))}finally{v(!1)}},k=async e=>{h(!1),await n(t,e)},T=e=>({key:e.name,content:s?(0,o.jsxs)(e4.A,{onClick:()=>{k(e.name)},sx:e=>({width:"100%",minHeight:74,px:1.5,py:1.25,justifyContent:"flex-start",textAlign:"left",border:"1px solid ".concat(e.palette.divider),borderRadius:2.5,transition:e.transitions.create(["border-color","background-color"]),"&:hover":{borderColor:"primary.main",backgroundColor:"action.hover"}}),children:[(0,o.jsx)(e6.A,{color:"primary",sx:{mr:1.25}}),(0,o.jsxs)(a.default,{sx:{minWidth:0},children:[(0,o.jsx)(i.A,{variant:"body2",fontWeight:800,noWrap:!0,children:e.name}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:f("flows.inspector.allAppToolsIncluded")})]})]}):(0,o.jsx)(e7.A,{name:e.name,status:(e=>"connected"===e||"disconnected"===e||"error"===e||"connecting"===e||"initialization"===e||"requires_authentication"===e?e:"starting"===e?"connecting":"disconnected")(e.status),path:e.rootPath||e.serverUrl||e.websocketUrl||"",enabled:!e.disabled,transport:(e=>"websocket"===e||"sse"===e||"streamable"===e?e:"stdio")(e.transport),pickerMode:!0,onClick:()=>{k(e.name)}})}),M=C.items.map(T),I=C.groups?C.groups.map(e=>({...e,items:e.items.map(T)})):null,N=s?f("flows.inspector.stepApps"):f("flows.inspector.connectedMcpServers"),F=s?f("flows.inspector.addApp"):f("flows.inspector.addMcpServer");return(0,o.jsxs)(a.default,{sx:e=>({border:"1px solid ".concat(e.palette.divider),borderRadius:2.5,overflow:"hidden"}),children:[(0,o.jsxs)(eQ.A,{direction:"row",alignItems:"center",justifyContent:"space-between",sx:{px:1.25,py:.75},children:[(0,o.jsx)(i.A,{variant:"caption",fontWeight:800,children:N}),(0,o.jsx)(p.A,{title:F,children:(0,o.jsx)(u.A,{size:"small","aria-label":F,onClick:()=>{S()},children:(0,o.jsx)(e3,{fontSize:"small"})})})]}),0===l.length?(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",display:"block",sx:{px:1.25,pb:1.25},children:s?f("flows.inspector.noApps"):f("flows.inspector.noMcpServers")}):(0,o.jsx)(eQ.A,{sx:{borderTop:1,borderColor:"divider"},children:l.map((e,l)=>(0,o.jsxs)(eQ.A,{direction:"row",alignItems:"center",gap:.75,sx:{minHeight:42,px:1,borderTop:+(0!==l),borderColor:"divider"},children:[(0,o.jsx)(e6.A,{color:"primary",sx:{fontSize:17}}),(0,o.jsx)(i.A,{variant:"body2",noWrap:!0,sx:{flex:1,minWidth:0},children:e.serverName}),(0,o.jsx)(p.A,{title:f(s?"flows.inspector.removeApp":"flows.inspector.removeMcpServer",{server:e.serverName}),children:(0,o.jsx)(u.A,{size:"small",color:"error","aria-label":f(s?"flows.inspector.removeApp":"flows.inspector.removeMcpServer",{server:e.serverName}),onClick:()=>d(t,e.nodeId),children:(0,o.jsx)(e9,{fontSize:"small"})})})]},e.nodeId))}),(0,o.jsx)(e8.A,{open:m,onClose:()=>h(!1),ariaLabel:s?f("flows.inspector.chooseApp"):f("flows.serverTools.connectTitle"),isLoading:w,error:b,emptyMessage:s?f("flows.inspector.noAppsToAdd"):f("flows.serverTools.noneToConnect"),searchable:!0,searchPlaceholder:s?f("flows.inspector.searchApps"):f("flows.serverTools.searchServers"),searchTerm:C.searchTerm,onSearchChange:C.setSearchTerm,columns:{xs:12,sm:6},items:M,groups:I,collapsedKeys:C.collapsedKeys,onToggleGroup:C.toggleGroup})]})},tl=(0,T.Ay)(M.A)(e=>{let{theme:t}=e;return{width:320,minWidth:320,height:"100%",minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid ".concat(t.palette.divider),borderRadius:16,backgroundColor:"dark"===t.palette.mode?"rgba(17, 22, 41, 0.9)":"rgba(255, 255, 255, 0.92)",boxShadow:"dark"===t.palette.mode?"0 18px 55px rgba(0,0,0,.24)":"0 18px 55px rgba(49,45,99,.1)",backdropFilter:"blur(20px) saturate(140%)",[t.breakpoints.down("lg")]:{width:286,minWidth:286},[t.breakpoints.down("md")]:{width:"100%",minWidth:0,height:"auto",maxHeight:"none"}}}),to=e=>{var t,l,s,n;let{selectedNode:c,onClearSelection:f,onCommitNode:m,onOpenAdvanced:h,flowName:g,flowNameError:x,onFlowNameChange:w,flowDescription:b,onFlowDescriptionChange:y,authoringMode:j,onAuthoringModeChange:A,permissionRuleCount:C,onOpenPermissionRules:S,beginnerMode:T=!1,onSuggestTools:M,onCheckPlausibility:N,connectedMcpServers:z=[],onConnectMcpServer:H,onRemoveMcpServer:E,loadMcpServers:W}=e,{t:L,tp:D}=(0,ed.s9)(),[B,V]=(0,r.useState)(c?"node":"flow"),[O,U]=(0,r.useState)(null!=(l=null==c?void 0:c.data.label)?l:""),[K,G]=(0,r.useState)(null!=(s=null==c?void 0:c.data.description)?s:""),[X,_]=(0,r.useState)(String(null!=(n=null==c||null==(t=c.data.properties)?void 0:t.promptTemplate)?n:""));(0,r.useEffect)(()=>{c?V("node"):V("flow")},[null==c?void 0:c.id]),(0,r.useEffect)(()=>{var e,t,l,o;U(null!=(t=null==c?void 0:c.data.label)?t:""),G(null!=(l=null==c?void 0:c.data.description)?l:""),_(String(null!=(o=null==c||null==(e=c.data.properties)?void 0:e.promptTemplate)?o:""))},[null==c?void 0:c.id,null==c?void 0:c.data]);let $=(0,r.useMemo)(()=>{var e;if(!c)return[];let t=null!=(e=c.data.properties)?e:{},l=[];return"string"==typeof t.modelId&&t.modelId?l.push({label:T?L("flows.inspector.summary.ai"):L("flows.inspector.summary.model"),value:t.modelId}):"string"==typeof t.model&&t.model&&l.push({label:T?L("flows.inspector.summary.ai"):L("flows.inspector.summary.model"),value:t.model}),"string"==typeof t.boundServer&&t.boundServer&&l.push({label:T?L("flows.inspector.summary.app"):L("flows.inspector.summary.server"),value:t.boundServer}),"string"==typeof t.subflowId&&t.subflowId&&l.push({label:T?L("flows.inspector.summary.agent"):L("flows.inspector.flow"),value:t.subflowId}),"string"==typeof t.signalName&&t.signalName&&l.push({label:T?L("flows.inspector.summary.notification"):L("flows.inspector.summary.signal"),value:t.signalName}),l},[c,T,L]),q=()=>{var e;if(!c)return null;let t={...null!=(e=c.data.properties)?e:{}};("process"===c.data.type||"start"===c.data.type)&&(t.promptTemplate=X);let l={...c.data,label:O.trim()||c.data.label,description:K.trim()||void 0,properties:t};return JSON.stringify(l)!==JSON.stringify(c.data)&&m(c.id,l),{...c,data:l}};return(0,o.jsxs)(tl,{elevation:0,"aria-label":T&&c?L("flows.inspector.stepSettings"):T?L("flows.inspector.agentSettings"):L("flows.inspector.flowInspector"),children:[(0,o.jsxs)(a.default,{sx:{px:1.5,pt:1.25},children:[(0,o.jsxs)(eQ.A,{direction:"row",alignItems:"center",justifyContent:"space-between",gap:1,children:[(0,o.jsxs)(a.default,{sx:{minWidth:0},children:[(0,o.jsx)(i.A,{variant:"overline",color:"text.secondary",sx:{letterSpacing:".12em"},children:T?c?L("flows.inspector.editStep"):L("flows.inspector.agentSettings"):L("flows.inspector.inspector")}),(0,o.jsx)(i.A,{variant:"subtitle1",fontWeight:800,noWrap:!0,children:c?c.data.label:g})]}),c&&(0,o.jsx)(p.A,{title:T?L("flows.inspector.closeStep"):L("flows.inspector.clearSelection"),children:(0,o.jsx)(u.A,{size:"small","aria-label":T?L("flows.inspector.closeStep"):L("flows.inspector.closeNode"),onClick:f,children:(0,o.jsx)(e0.A,{fontSize:"small"})})})]}),!T&&(0,o.jsxs)(eJ.A,{value:B,onChange:(e,t)=>V(t),variant:"fullWidth",sx:{mt:.5,minHeight:38,"& .MuiTab-root":{minHeight:38}},children:[(0,o.jsx)(eZ.A,{value:"node",label:L("flows.inspector.node"),disabled:!c}),(0,o.jsx)(eZ.A,{value:"flow",label:L("flows.inspector.flow")})]})]}),(0,o.jsx)(R.A,{}),(0,o.jsx)(a.default,{sx:{p:1.5,overflowY:"auto",flex:1},children:"node"===B&&c?(0,o.jsxs)(eQ.A,{spacing:1.5,children:[(0,o.jsxs)(eQ.A,{direction:"row",alignItems:"center",gap:1,children:[(0,o.jsx)(I.A,{size:"small",label:((e,t,l)=>{let o=String(e.data.type||e.type||"node");if(t){var r;return null!=(r=({start:l("flows.inspector.type.start"),process:l("flows.inspector.type.process"),finish:l("flows.inspector.type.finish"),mcp:l("flows.inspector.type.mcp"),subflow:l("flows.inspector.type.subflow"),resource:l("flows.inspector.type.resource"),signal:l("flows.inspector.type.signal"),trigger:l("flows.inspector.type.trigger")})[o])?r:l("flows.inspector.type.step")}return"mcp"===o?"MCP":"".concat(o.charAt(0).toUpperCase()).concat(o.slice(1))})(c,T,L),color:"finish"===c.data.type?"success":"primary",variant:"outlined"}),!T&&(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",noWrap:!0,children:c.id})]}),(0,o.jsx)(v.A,{label:T?L("flows.inspector.stepName"):L("flows.inspector.nodeName"),size:"small",fullWidth:!0,value:O,onChange:e=>U(e.target.value),onBlur:q,onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur()}}),(0,o.jsx)(v.A,{label:T?L("flows.inspector.shortNote"):L("flows.inspector.whatStepDoes"),size:"small",fullWidth:!0,multiline:!0,minRows:2,maxRows:4,value:K,onChange:e=>G(e.target.value),onBlur:q,placeholder:T?L("flows.inspector.notePlaceholder"):L("flows.inspector.optionalNote")}),("process"===c.data.type||"start"===c.data.type)&&(0,o.jsx)(v.A,{label:T?"start"===c.data.type?L("flows.inspector.helpfulBackground"):L("flows.inspector.aiTask"):"start"===c.data.type?L("flows.inspector.startingContext"):L("flows.inspector.taskPrompt"),size:"small",fullWidth:!0,multiline:!0,minRows:5,maxRows:12,value:X,onChange:e=>_(e.target.value),onBlur:q,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),q())},placeholder:"start"===c.data.type?T?L("flows.inspector.startBeginnerPlaceholder"):L("flows.inspector.startPlaceholder"):T?L("flows.inspector.taskBeginnerPlaceholder"):L("flows.inspector.taskPlaceholder"),helperText:T?L("flows.inspector.blurHelp"):L("flows.inspector.keyboardHelp")}),!T&&$.length>0&&(0,o.jsx)(a.default,{sx:e=>({p:1.25,borderRadius:2.5,border:"1px solid ".concat(e.palette.divider),bgcolor:(0,Q.X4)(e.palette.primary.main,.05)}),children:$.map(e=>(0,o.jsxs)(eQ.A,{direction:"row",justifyContent:"space-between",gap:1,mb:.5,children:[(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:e.label}),(0,o.jsx)(i.A,{variant:"caption",fontWeight:700,noWrap:!0,children:e.value})]},e.label))}),(0,o.jsx)(d.A,{variant:T?"outlined":"contained",startIcon:(0,o.jsx)(k.A,{}),endIcon:(0,o.jsx)(e1.A,{}),onClick:()=>{let e=q();e&&h(e)},children:T?L("flows.inspector.moreOptions"):L("flows.inspector.fullSettings")}),"process"===c.data.type&&H&&E&&W&&(0,o.jsx)(tt,{processNodeId:c.id,connections:z,beginnerMode:T,onConnect:H,onRemove:E,loadServers:W}),"process"===c.data.type&&M&&(0,o.jsx)(d.A,{variant:"contained",startIcon:(0,o.jsx)(e5.A,{}),onClick:()=>{let e=q();e&&M(e)},children:L("flows.inspector.suggestTools")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:T?L("flows.inspector.beginnerTip"):L("flows.inspector.expertTip")})]}):(0,o.jsxs)(eQ.A,{spacing:1.5,children:[(0,o.jsxs)(eQ.A,{direction:"row",gap:1,alignItems:"center",children:[(0,o.jsx)(e2.A,{color:"primary",fontSize:"small"}),(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"subtitle2",fontWeight:800,children:T?L("flows.inspector.aboutAgent"):L("flows.inspector.flowDetails")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:T?L("flows.inspector.aboutHelp"):L("flows.inspector.flowHelp")})]})]}),(0,o.jsx)(v.A,{size:"small",label:T?L("flows.inspector.agentName"):L("flows.inspector.flowName"),value:g,onChange:e=>w(e.target.value),error:!!x,helperText:null!=x?x:T?L("flows.inspector.agentNameHelp"):L("flows.inspector.renameHelp"),fullWidth:!0}),N&&(0,o.jsx)(d.A,{variant:"outlined",startIcon:(0,o.jsx)(e5.A,{}),onClick:N,children:L("flows.inspector.checkAgent")}),(0,o.jsx)(v.A,{size:"small",label:T?L("flows.inspector.helpQuestion"):L("flows.inspector.description"),value:b,onChange:e=>y(e.target.value),multiline:!0,minRows:3,maxRows:7,fullWidth:!0,placeholder:T?L("flows.inspector.agentDescriptionPlaceholder"):L("flows.inspector.flowDescriptionPlaceholder")}),!T&&(0,o.jsxs)(a.default,{sx:e=>({p:1.25,borderRadius:2.5,border:"1px solid ".concat(e.palette.divider),bgcolor:(0,Q.X4)(e.palette.primary.main,.04)}),children:[(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{size:"small",checked:"advanced"===j,onChange:e=>A(e.target.checked?"advanced":"guided")}),label:"advanced"===j?L("flows.inspector.advanced"):L("flows.inspector.guided")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",display:"block",children:"advanced"===j?L("flows.inspector.advancedHelp"):L("flows.inspector.guidedHelp")})]}),"advanced"===j&&(0,o.jsx)(d.A,{variant:"outlined",onClick:S,startIcon:(0,o.jsx)(e2.A,{}),children:C?D("flows.inspector.permissionRules",C):L("flows.inspector.permissionRules")}),!T&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(R.A,{}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:L("flows.inspector.shortcuts")})]})]})})]})};var tr=l(52641),ts=l(95436),tn=l(55606);let ta=(0,y.A)((0,o.jsx)("path",{d:"M11 5v11.17l-4.88-4.88c-.39-.39-1.03-.39-1.42 0s-.39 1.02 0 1.41l6.59 6.59c.39.39 1.02.39 1.41 0l6.59-6.59c.39-.39.39-1.02 0-1.41a.996.996 0 0 0-1.41 0L13 16.17V5c0-.55-.45-1-1-1s-1 .45-1 1"}),"ArrowDownwardRounded");var ti=l(26842);let td=(0,y.A)((0,o.jsx)("path",{d:"M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18c.62-.39.62-1.29 0-1.69L9.54 5.98C8.87 5.55 8 6.03 8 6.82"}),"PlayArrowRounded"),tc=new Set(["Process Node","Subflow Node","Signal Node"]),tu=e=>{let{children:t,complete:l=!1}=e;return(0,o.jsx)(a.default,{"aria-hidden":"true",sx:{display:"grid",width:34,height:34,flexShrink:0,placeItems:"center",borderRadius:"50%",color:l?"success.contrastText":"primary.contrastText",bgcolor:l?"success.main":"primary.main",fontWeight:850,boxShadow:e=>"0 8px 24px ".concat((0,Q.X4)(l?e.palette.success.main:e.palette.primary.main,.28))},children:l?(0,o.jsx)(ti.A,{fontSize:"small"}):t})},tp=e=>{let{nodes:t,orderedStepIds:l=[],selectedNodeId:s,flowName:n,flowNameError:c,onFlowNameChange:u,onSelectNode:p,onAddTask:f,onTry:h,isSaving:g=!1,hasAdvancedFeatures:x=!1,readyToTry:w=!0,needsAIConnection:b=!1,onSwitchAdvanced:y,models:j=[],aiAssistance:A="manual",selectedModelId:C,onChooseAssistance:S,onModelChange:T,onCheckPlausibility:N}=e,{t:F}=(0,ed.s9)(),[P,R]=(0,r.useState)(""),z=(0,r.useMemo)(()=>{let e=new Map(l.map((e,t)=>[e,t]));return t.filter(e=>["process","subflow","signal"].includes(e.data.type)).sort((t,l)=>{var o,r,s,n,a,i;return(null!=(s=e.get(t.id))?s:Number.MAX_SAFE_INTEGER)-(null!=(n=e.get(l.id))?n:Number.MAX_SAFE_INTEGER)||(null!=(a=null==(o=t.position)?void 0:o.y)?a:0)-(null!=(i=null==(r=l.position)?void 0:r.y)?i:0)})},[t,l]),E=!!n.trim()&&!/^(?:NewFlow\d*|Untitled (?:assistant|agent)(?: \d+)?)$/i.test(n.trim())&&!c,W=!!P.trim()&&!x&&"unasked"!==A&&("assisted"!==A||!!C),L=E&&z.length>0&&w&&!g,D=()=>{let e=P.trim();e&&(f(e),R(""))};return(0,o.jsx)(a.default,{"aria-label":F("flows.guided.aria"),sx:{flex:1,minHeight:0,overflowY:"auto",px:{xs:.5,sm:1.5,lg:3},py:{xs:1,sm:1.5,lg:2.5}},children:(0,o.jsxs)(a.default,{sx:{width:"100%",maxWidth:780,mx:"auto"},children:[(0,o.jsxs)(eQ.A,{spacing:.8,sx:{mb:2.5},children:[(0,o.jsx)(I.A,{icon:(0,o.jsx)(e5.A,{}),label:F("flows.guided.simple"),color:"primary",variant:"outlined",sx:{alignSelf:"flex-start"}}),(0,o.jsx)(i.A,{variant:"h4",children:F("flows.guided.recipe")}),(0,o.jsx)(i.A,{color:"text.secondary",children:F("flows.guided.intro")})]}),(0,o.jsxs)(eQ.A,{spacing:1.5,children:[j.length>0&&S&&(0,o.jsx)(M.A,{elevation:0,sx:{p:{xs:2,sm:2.5},border:1,borderColor:"unasked"===A?"primary.main":"divider",borderRadius:4},children:(0,o.jsxs)(eQ.A,{spacing:1.5,children:[(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"h6",children:F("flows.guided.aiQuestion")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:F("flows.guided.aiHelp")})]}),"unasked"===A?(0,o.jsxs)(eQ.A,{direction:{xs:"column",sm:"row"},spacing:1,children:[(0,o.jsx)(d.A,{variant:"contained",startIcon:(0,o.jsx)(e5.A,{}),onClick:()=>S("assisted"),children:F("flows.guided.yesHelp")}),(0,o.jsx)(d.A,{variant:"outlined",onClick:()=>S("manual"),children:F("flows.guided.manual")})]}):(0,o.jsxs)(eQ.A,{direction:{xs:"column",sm:"row"},spacing:1.5,alignItems:{sm:"center"},children:[(0,o.jsx)(I.A,{color:"assisted"===A?"primary":"default",label:"assisted"===A?F("flows.guided.aiOn"):F("flows.guided.manualSetup")}),"assisted"===A&&T&&(0,o.jsxs)(tr.A,{size:"small",sx:{minWidth:260},children:[(0,o.jsx)(ts.A,{id:"guided-helper-model-label",children:F("flows.guided.aiHelper")}),(0,o.jsx)(tn.A,{labelId:"guided-helper-model-label",label:F("flows.guided.aiHelper"),value:null!=C?C:"",onChange:e=>T(String(e.target.value)),children:j.map(e=>(0,o.jsx)(H.A,{value:e.id,children:e.displayName||e.name},e.id))})]}),(0,o.jsx)(d.A,{size:"small",onClick:()=>S("assisted"===A?"manual":"assisted"),children:"assisted"===A?F("flows.guided.turnOff"):F("flows.guided.turnOn")})]})]})}),(0,o.jsx)(M.A,{elevation:0,sx:{p:{xs:2,sm:2.5},border:1,borderColor:E?"success.main":"divider",borderRadius:4,bgcolor:"background.paper"},children:(0,o.jsxs)(eQ.A,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[(0,o.jsx)(tu,{complete:E,children:"1"}),(0,o.jsxs)(a.default,{sx:{flex:1,minWidth:0},children:[(0,o.jsx)(i.A,{variant:"h6",children:F("flows.guided.nameTitle")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:F("flows.guided.nameHelp")}),(0,o.jsx)(v.A,{fullWidth:!0,size:"small",label:F("flows.guided.name"),value:n,error:!!c,helperText:null!=c?c:E?F("flows.guided.looksGood"):F("flows.guided.nameHint"),onChange:e=>u(e.target.value),onFocus:e=>{/^(?:NewFlow\d*|Untitled (?:assistant|agent)(?: \d+)?)$/i.test(e.currentTarget.value)&&e.currentTarget.select()}})]})]})}),(0,o.jsx)(M.A,{elevation:0,sx:{p:{xs:2,sm:2.5},border:1,borderColor:z.length>0?"success.main":"divider",borderRadius:4,bgcolor:"background.paper"},children:(0,o.jsxs)(eQ.A,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[(0,o.jsx)(tu,{complete:z.length>0,children:"2"}),(0,o.jsxs)(a.default,{sx:{flex:1,minWidth:0},children:[(0,o.jsx)(i.A,{variant:"h6",children:z.length?F("flows.guided.addAnother"):F("flows.guided.goalQuestion")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:z.length?F("flows.guided.nextHelp"):F("flows.guided.goalHelp")}),x&&(0,o.jsx)(m.A,{severity:"info",action:(0,o.jsx)(d.A,{color:"inherit",size:"small",onClick:y,children:F("flows.guided.openExpert")}),sx:{mt:1.5},children:F("flows.guided.advancedWarning")}),(0,o.jsxs)(eQ.A,{spacing:1,sx:{mt:2},children:[(0,o.jsxs)(a.default,{sx:{px:1.5,py:1,borderRadius:3,color:"text.secondary",bgcolor:e=>(0,Q.X4)(e.palette.primary.main,.055),border:1,borderColor:"divider"},children:[(0,o.jsx)(i.A,{variant:"caption",fontWeight:800,color:"primary.main",children:F("flows.guided.when").toLocaleUpperCase()}),(0,o.jsx)(i.A,{variant:"body2",fontWeight:700,children:F("flows.guided.someoneAsks")})]}),z.map((e,t)=>(0,o.jsxs)(r.Fragment,{children:[(0,o.jsx)(ta,{"aria-hidden":"true",sx:{alignSelf:"center",color:"text.disabled",fontSize:20}}),(0,o.jsx)(e4.A,{onClick:()=>p(e.id),sx:{display:"block",width:"100%",borderRadius:3,textAlign:"left"},children:(0,o.jsx)(M.A,{elevation:0,sx:{width:"100%",p:1.5,border:1,borderColor:s===e.id?"primary.main":"divider",borderRadius:3,bgcolor:s===e.id?e=>(0,Q.X4)(e.palette.primary.main,.1):"background.default",boxShadow:s===e.id?e=>"0 0 0 3px ".concat((0,Q.X4)(e.palette.primary.main,.12)):"none"},children:(0,o.jsxs)(eQ.A,{direction:"row",spacing:1.25,alignItems:"flex-start",children:[(0,o.jsx)(a.default,{sx:{display:"grid",width:30,height:30,flexShrink:0,placeItems:"center",borderRadius:2,color:"primary.contrastText",bgcolor:"primary.main",fontWeight:850},children:t+1}),(0,o.jsxs)(a.default,{sx:{minWidth:0,flex:1},children:[(0,o.jsx)(i.A,{variant:"overline",color:"primary.main",children:((e,t)=>t("subflow"===e?"flows.guided.type.subflow":"signal"===e?"flows.guided.type.signal":"flows.guided.type.process"))(e.data.type,F)}),(0,o.jsx)(i.A,{variant:"subtitle1",fontWeight:800,children:((e,t)=>{var l;let o=null==(l=e.data.label)?void 0:l.trim();return!o||tc.has(o)?t("process"===e.data.type?"flows.guided.default.process":"subflow"===e.data.type?"flows.guided.default.subflow":"signal"===e.data.type?"flows.guided.default.signal":"flows.guided.default.step"):o})(e,F)}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:.35,display:"-webkit-box",overflow:"hidden",WebkitBoxOrient:"vertical",WebkitLineClamp:2},children:((e,t)=>{var l,o,r;let s=String(null!=(r=null==(l=e.data.properties)?void 0:l.promptTemplate)?r:"").trim();return s||((null==(o=e.data.description)?void 0:o.trim())?e.data.description.trim():t("subflow"===e.data.type?"flows.guided.summary.subflow":"signal"===e.data.type?"flows.guided.summary.signal":"flows.guided.summary.process"))})(e,F)})]}),(0,o.jsx)(k.A,{color:"action",fontSize:"small"})]})})})]},e.id)),(0,o.jsx)(ta,{"aria-hidden":"true",sx:{alignSelf:"center",color:"text.disabled",fontSize:20}}),(0,o.jsxs)(a.default,{sx:{px:1.5,py:1,borderRadius:3,color:"text.secondary",bgcolor:e=>(0,Q.X4)(e.palette.success.main,.055),border:1,borderColor:"divider"},children:[(0,o.jsx)(i.A,{variant:"caption",fontWeight:800,color:"success.main",children:F("flows.guided.then").toLocaleUpperCase()}),(0,o.jsx)(i.A,{variant:"body2",fontWeight:700,children:F("flows.guided.sendAnswer")})]})]}),(0,o.jsxs)(eQ.A,{direction:{xs:"column",sm:"row"},spacing:1,alignItems:"stretch",sx:{mt:2},children:[(0,o.jsx)(v.A,{fullWidth:!0,multiline:!0,minRows:2,maxRows:5,label:z.length?F("flows.guided.nextLabel"):F("flows.guided.goalLabel"),placeholder:F("flows.guided.goalPlaceholder"),value:P,disabled:x,onChange:e=>R(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&W&&(e.preventDefault(),D())}}),(0,o.jsx)(d.A,{variant:"contained",startIcon:(0,o.jsx)(e3,{}),disabled:!W,onClick:D,sx:{minWidth:{sm:150}},children:z.length?F("flows.guided.addStep"):F("flows.guided.createGoal")})]})]})]})}),(0,o.jsx)(M.A,{elevation:0,sx:{p:{xs:2,sm:2.5},border:1,borderColor:L?"primary.main":"divider",borderRadius:4,bgcolor:e=>(0,Q.X4)(e.palette.primary.main,L?.075:.025)},children:(0,o.jsxs)(eQ.A,{direction:{xs:"column",sm:"row"},spacing:1.5,alignItems:{sm:"center"},children:[(0,o.jsx)(tu,{children:"3"}),(0,o.jsxs)(a.default,{sx:{flex:1},children:[(0,o.jsx)(i.A,{variant:"h6",children:F("flows.guided.tryTitle")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:F("flows.guided.tryHelp")}),b&&z.some(e=>"process"===e.data.type)&&(0,o.jsx)(m.A,{severity:"warning",sx:{mt:1},children:F("flows.guided.needsAi")})]}),h&&(0,o.jsxs)(eQ.A,{spacing:1,children:[N&&"assisted"===A&&(0,o.jsx)(d.A,{variant:"outlined",startIcon:(0,o.jsx)(e5.A,{}),disabled:0===z.length,onClick:N,children:F("flows.guided.checkAi")}),(0,o.jsx)(d.A,{size:"large",variant:"contained",startIcon:(0,o.jsx)(td,{}),disabled:!L,onClick:h,children:g?F("flows.guided.saving"):F("flows.guided.tryAgent")})]})]})})]})]})})};var tf=l(22822);let tm=(0,y.A)((0,o.jsx)("path",{d:"M12.09 2.91C10.08.9 7.07.49 4.65 1.67L8.28 5.3c.39.39.39 1.02 0 1.41L6.69 8.3c-.39.4-1.02.4-1.41 0L1.65 4.67C.48 7.1.89 10.09 2.9 12.1c1.86 1.86 4.58 2.35 6.89 1.48l7.96 7.96c1.03 1.03 2.69 1.03 3.71 0 1.03-1.03 1.03-2.69 0-3.71L13.54 9.9c.92-2.34.44-5.1-1.45-6.99"}),"BuildRounded"),th=(0,y.A)((0,o.jsx)("path",{fillRule:"evenodd",d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2M9 17H6c-.55 0-1-.45-1-1s.45-1 1-1h3c.55 0 1 .45 1 1s-.45 1-1 1m0-4H6c-.55 0-1-.45-1-1s.45-1 1-1h3c.55 0 1 .45 1 1s-.45 1-1 1m0-4H6c-.55 0-1-.45-1-1s.45-1 1-1h3c.55 0 1 .45 1 1s-.45 1-1 1m9.7 2.12-3.17 3.17c-.39.39-1.03.39-1.42 0l-1.41-1.42a.996.996 0 0 1 0-1.41c.39-.39 1.02-.39 1.41 0l.71.71 2.47-2.47c.39-.39 1.02-.39 1.41 0l.01.01c.38.39.38 1.03-.01 1.41"}),"FactCheckRounded");function tg(e){let{open:t,flow:l,relatedFlows:s=[],nodeId:n,modelId:c,models:u=[],onApply:p,onApplyRelatedFlows:f,onClose:w}=e,{t:v,tp:y}=(0,ed.s9)(),[j,A]=(0,r.useState)("suggesting"),[C,S]=(0,r.useState)(null),[k,T]=(0,r.useState)(new Set),[P,R]=(0,r.useState)(null),[z,E]=(0,r.useState)(l),[W,L]=(0,r.useState)(null!=c?c:""),[B,V]=(0,r.useState)(null),O=async e=>{A("checking"),V(null);try{let t=await D.g.checkPlausibility({flow:e,relatedFlows:s,modelId:W||c||void 0,intendedContext:"chat"});R(t),A("plausibility")}catch(e){V(e instanceof Error?e.message:v("flows.assistance.checkFailed")),A("plausibility")}};(0,r.useEffect)(()=>{if(!t)return;let e=!0;return(E(l),S(null),R(null),T(new Set),L(null!=c?c:""),V(null),n)?c?(A("suggesting"),D.g.suggestToolsForStep({flow:l,nodeId:n,modelId:c,goal:l.description}).then(t=>{e&&(S(t),T(new Set(t.suggestions.map(e=>"".concat(e.server,"\0").concat(e.tool)))),0===t.suggestions.length?O(l):A("tools"))}).catch(t=>{e&&(V(t instanceof Error?t.message:v("flows.assistance.suggestFailed")),A("tools"))}),()=>{e=!1}):(A("tools"),()=>{e=!1}):(O(l),()=>{e=!1})},[t,n,c]);let U=(0,r.useMemo)(()=>{var e;return null!=(e=null==C?void 0:C.suggestions.filter(e=>k.has("".concat(e.server,"\0").concat(e.tool))))?e:[]},[k,C]),K=(0,r.useMemo)(()=>{if(!P)return 0;let e=new Set([l.id,...s.map(e=>e.id)]);return P.patches.filter(t=>e.has(t.flowId)).length},[l.id,P,s]),G=async()=>{if(n&&W){A("suggesting"),V(null);try{let e=await D.g.suggestToolsForStep({flow:z,nodeId:n,modelId:W,goal:z.description});S(e),T(new Set(e.suggestions.map(e=>"".concat(e.server,"\0").concat(e.tool)))),0===e.suggestions.length?await O(z):A("tools")}catch(e){V(e instanceof Error?e.message:v("flows.assistance.suggestFailed")),A("tools")}}},X=async()=>{if(n&&C){A("suggesting"),V(null);try{let e=await D.g.applyToolsToStep({flow:z,nodeId:n,selections:U,proposedPrompt:C.proposedPrompt});E(e),p(e),await O(e)}catch(e){V(e instanceof Error?e.message:v("flows.assistance.connectFailed")),A("tools")}}},_="suggesting"===j||"checking"===j;return(0,o.jsxs)(h.A,{open:t,onClose:_?void 0:w,fullWidth:!0,maxWidth:"md",children:[(0,o.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(e5.A,{color:"primary"}),"plausibility"===j||"checking"===j?v("flows.assistance.plausibilityTitle"):v("flows.assistance.toolsTitle")]}),(0,o.jsxs)(x.A,{dividers:!0,children:[_&&(0,o.jsxs)(eQ.A,{alignItems:"center",spacing:1.5,sx:{py:5},children:[(0,o.jsx)(N.default,{}),(0,o.jsx)(i.A,{color:"text.secondary",children:"suggesting"===j?v("flows.assistance.finding"):v("flows.assistance.checking")})]}),B&&!_&&(0,o.jsx)(m.A,{severity:"error",sx:{mb:2},children:B}),"tools"===j&&!C&&(0,o.jsx)(eQ.A,{spacing:2,children:0===u.length?(0,o.jsx)(m.A,{severity:"warning",children:v("flows.assistance.needModel")}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(m.A,{severity:"info",children:v("flows.assistance.chooseModel")}),(0,o.jsxs)(tr.A,{fullWidth:!0,size:"small",children:[(0,o.jsx)(ts.A,{id:"assistance-model-label",children:v("flows.assistance.aiHelper")}),(0,o.jsx)(tn.A,{labelId:"assistance-model-label",label:v("flows.assistance.aiHelper"),value:W,onChange:e=>L(String(e.target.value)),children:u.map(e=>(0,o.jsx)(H.A,{value:e.id,children:e.displayName||e.name},e.id))})]})]})}),"tools"===j&&C&&(0,o.jsxs)(eQ.A,{spacing:1.5,children:[(0,o.jsx)(m.A,{severity:"info",children:v("flows.assistance.approvalHelp")}),0===C.suggestions.length?(0,o.jsx)(m.A,{severity:"success",children:v("flows.assistance.noTool")}):C.suggestions.map(e=>{let t="".concat(e.server,"\0").concat(e.tool);return(0,o.jsx)(M.A,{variant:"outlined",sx:{p:1.25},children:(0,o.jsx)(F.A,{control:(0,o.jsx)(tf.A,{checked:k.has(t),onChange:e=>{T(l=>{let o=new Set(l);return e.target.checked?o.add(t):o.delete(t),o})}}),label:(0,o.jsxs)(a.default,{children:[(0,o.jsxs)(eQ.A,{direction:"row",spacing:1,alignItems:"center",children:[(0,o.jsx)(I.A,{size:"small",label:e.server}),(0,o.jsx)(i.A,{fontWeight:800,children:e.tool})]}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:e.reason})]})})},t)}),(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"subtitle2",children:v("flows.assistance.promptPreview")}),(0,o.jsx)(M.A,{variant:"outlined",sx:{p:1.25,mt:.5,whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto"},children:(0,o.jsx)(i.A,{variant:"body2",component:"pre",sx:{m:0,fontFamily:"inherit",whiteSpace:"pre-wrap"},children:C.proposedPrompt})})]})]}),"plausibility"===j&&P&&(0,o.jsxs)(eQ.A,{spacing:1.5,children:[(0,o.jsx)(eQ.A,{direction:"row",gap:1,flexWrap:"wrap",children:P.contexts.map(e=>{var t;return(0,o.jsx)(I.A,{label:e.label},"".concat(e.kind,"-").concat(null!=(t=e.sourceId)?t:""))})}),0===P.issues.length?(0,o.jsx)(m.A,{severity:"success",children:v("flows.assistance.plausible")}):P.issues.map((e,t)=>{var r,s;let n=P.repairedFlows.find(t=>t.id===e.flowId);return(0,o.jsxs)(m.A,{severity:e.severity,children:[n&&n.id!==l.id?"".concat(n.name,": "):"",(0,e$.z)(e,v)]},"".concat(e.code,"-").concat(null!=(r=e.flowId)?r:"","-").concat(null!=(s=e.nodeId)?s:"","-").concat(t))}),K>0&&(0,o.jsx)(m.A,{severity:"info",children:y("flows.assistance.patch",K)}),P.patches.length>K&&(0,o.jsx)(m.A,{severity:"warning",children:y("flows.assistance.savedPatch",P.patches.length-K)})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:w,disabled:_,children:v("flows.assistance.close")}),"tools"===j&&!C&&u.length>0&&(0,o.jsx)(d.A,{variant:"contained",disabled:!W,onClick:()=>void G(),children:v("flows.assistance.suggest")}),"tools"===j&&C&&0===C.suggestions.length&&(0,o.jsx)(d.A,{startIcon:(0,o.jsx)(th,{}),onClick:()=>void O(z),children:v("flows.assistance.checkFlow")}),"tools"===j&&C&&C.suggestions.length>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.A,{onClick:()=>void O(z),children:v("flows.assistance.skip")}),(0,o.jsx)(d.A,{variant:"contained",startIcon:(0,o.jsx)(tm,{}),disabled:0===U.length,onClick:()=>void X(),children:y("flows.assistance.connect",U.length)})]}),"plausibility"===j&&P&&K>0?(0,o.jsx)(d.A,{variant:"contained",startIcon:(0,o.jsx)(th,{}),onClick:()=>{p(P.repairedFlow);let e=new Map(P.repairedFlows.map(e=>[e.id,e]));null==f||f(s.map(t=>{var l;return null!=(l=e.get(t.id))?l:t})),w()},children:v("flows.assistance.apply")}):null]})]})}var tx=l(77073),tw=l(90880);function tv(e){let{currentLabel:t,nameIsCustom:l,defaultLabel:o,previousAutoLabel:r,nextAutoLabel:s}=e;return!0===l?t&&t.length>0?t:s:!t||0===t.length||t===o||void 0!==r&&r.length>0&&t===r?s:t}let tb=(0,E.h)("components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useModelManagement.ts");var ty=l(9898);let tj=(0,E.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useServerConnection");function tA(e,t){let l=e.replace(/\s+/g," ").trim();if(l.length<=t)return l;let o=l.slice(0,t),r=o.lastIndexOf(" ");return"".concat((r>.6*t?o.slice(0,r):o).trimEnd(),"…")}let tC=(0,E.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/hooks/useHandoffTools"),tS=e=>{let{nodeData:t,setNodeData:l}=e,{t:r}=(0,ed.s9)();return t?(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%",pr:2},children:[(0,o.jsx)(i.A,{variant:"h6",gutterBottom:!0,children:r("flows.process.configTitle")}),(0,o.jsx)(v.A,{fullWidth:!0,label:r("flows.mcpNode.label"),value:t.label||"",onChange:e=>l(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:r("flows.process.description"),value:t.description||"",onChange:e=>l({...t,description:e.target.value}),margin:"normal",multiline:!0,rows:2,helperText:r("flows.process.descriptionHelp")})]}):null};var tk=l(18369),tT=l(12857),tM=l(99162),tI=l(61267);let tN=e=>{let{isLoadingModels:t,loadError:l,models:r,selectedModelId:s,handleModelSelect:n,isModelBound:c,handleUnbindModel:u}=e,{t:p}=(0,ed.s9)(),f=(0,te.E)("models",r),m=e=>({key:e.id,content:(e=>(0,o.jsx)(tI.A,{model:e,selectable:!0,selected:s===e.id,onSelect:n}))(e)}),h=f.items.map(m),g=f.groups?f.groups.map(e=>({...e,items:e.items.map(m)})):null;return(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:p("flows.process.bindModel")}),(0,o.jsx)(a.default,{role:"radiogroup","aria-label":p("flows.process.bindModelAria"),children:(0,o.jsx)(tM.A,{isLoading:t,error:l,loadingMessage:p("flows.process.loadingModels"),emptyMessage:p("flows.process.noModels"),searchable:!0,searchPlaceholder:p("flows.process.searchModels"),searchTerm:f.searchTerm,onSearchChange:f.setSearchTerm,columns:{xs:12,sm:6},items:h,groups:g,collapsedKeys:f.collapsedKeys,onToggleGroup:f.toggleGroup})}),!t&&!l&&r.length>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(tk.A,{children:p(s?"flows.process.modelSelected":"flows.process.modelSelect")}),c&&(0,o.jsx)(a.default,{sx:{mt:2,display:"flex",justifyContent:"flex-end"},children:(0,o.jsx)(d.A,{startIcon:(0,o.jsx)(tT.A,{}),onClick:u,color:"primary",variant:"outlined",size:"small",children:p("flows.process.unbindModel")})})]})]})};var tF=l(66177),tP=l(29767),tR=l(84578),tz=l(76530),tH=l(25541),tE=l(51611),tW=l(89218),tL=l(63186),tD=l(62962);let tB=(0,E.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerTools"),tV=e=>{var t,l,s;let{isLoadingServers:n,connectedMcpNodes:c,availableServers:f,onConnectMcpServer:m,serverToolsMap:h,serverStatuses:g,isLoadingTools:x,handleSelectToolServer:w,handleInsertToolBinding:b,selectedToolServerNodeId:y,selectedNodeId:j,isLoadingSelectedServerTools:C,promptBuilderRef:S,handleRetryServer:k,handleRestartServer:T}=e,{t:I,tp:F}=(0,ed.s9)(),P=null!=(s=null!=y?y:null==(t=c[0])?void 0:t.nodeId)?s:null,[R,z]=(0,r.useState)({}),[H,E]=(0,r.useState)(!1),W=(null!=f?f:[]).filter(e=>!c.some(t=>t.serverName===e.name)),L=!!m&&W.length>0,D=(0,te.E)("mcp",W),B=e=>({key:e.name,content:(e=>(0,o.jsx)(e7.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==m||m(t))}}))(e)}),V=D.items.map(B),O=D.groups?D.groups.map(e=>({...e,items:e.items.map(B)})):null,U=(0,o.jsx)(e8.A,{open:H,onClose:()=>E(!1),title:I("flows.serverTools.connectTitle"),description:I("flows.serverTools.connectDescription"),emptyMessage:I("flows.serverTools.noneToConnect"),searchable:!0,searchPlaceholder:I("flows.serverTools.searchServers"),searchTerm:D.searchTerm,onSearchChange:D.setSearchTerm,columns:{xs:12,sm:6},items:V,groups:O,collapsedKeys:D.collapsedKeys,onToggleGroup:D.toggleGroup}),[K,G]=(0,r.useState)(""),[X,_]=(0,r.useState)({}),$=(e,t,l)=>{if(e!==P){tB.debug("Node tab not selected, selecting node first",{selectedNodeId:e,serverName:t,toolName:l}),Q(e);return}t&&l?(tB.debug("Inserting tool binding",{serverName:t,toolName:l}),b(t,l)):tB.warn("Cannot insert tool binding, server or tool name is undefined",{serverName:t,toolName:l})},q=e=>{try{let t=c.find(t=>t.nodeId===e);if(!t)return tB.warn("Could not find connected MCP node with ID ".concat(e)),[];let l=t.enabledTools||[];return tB.debug("Enabled tools for node ".concat(e,": ").concat(JSON.stringify(l))),Array.isArray(l)?l:[]}catch(t){return tB.error("Error getting enabled tools for node ".concat(e,":"),t),[]}},Y=(e,t,l)=>{try{if(!l||!Array.isArray(l))return tB.warn("Tools array is not available or not an array for server ".concat(t)),[];let o=q(e),r=l;if(o.length>0?r=l.filter(e=>e&&e.name&&o.includes(e.name)):(tB.debug("No tools explicitly enabled for node ".concat(e,", showing none.")),r=[]),K.trim()){let e=K.toLowerCase().trim();r=r.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 r}catch(o){return tB.error("Error filtering tools for node ".concat(e," (server ").concat(t,"):"),o),l||[]}},Q=e=>{w(e)},Z=async(e,t)=>{t.stopPropagation(),tB.debug("Retry button clicked for server: ".concat(e)),z(t=>({...t,[e]:!0}));try{k&&await k(e)}finally{setTimeout(()=>{z(t=>({...t,[e]:!1}))},500)}},ee=async(e,t)=>{t.stopPropagation(),tB.debug("Restart button clicked for server: ".concat(e)),z(t=>({...t,[e]:!0}));try{T&&await T(e)}finally{setTimeout(()=>{z(t=>({...t,[e]:!1}))},500)}};(0,r.useEffect)(()=>{c.length>0&&!y&&w(c[0].nodeId)},[c,y,w]);let et=c.find(e=>e.nodeId===P),el=null==et?void 0:et.serverName;return(0,o.jsxs)(a.default,{sx:{mt:4,display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:I("flows.serverTools.title")}),n?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(N.default,{size:20}),(0,o.jsx)(i.A,{color:"text.secondary",children:I("flows.serverTools.loadingNodes")})]}):0===c.length?(0,o.jsxs)(a.default,{sx:{p:2,border:"1px dashed rgba(0, 0, 0, 0.12)",borderRadius:1},children:[(0,o.jsx)(i.A,{color:"text.secondary",align:"center",children:I("flows.serverTools.noneConnected")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:L?I("flows.serverTools.pickHelp"):I("flows.serverTools.connectHelp")}),L&&(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,o.jsx)(d.A,{variant:"contained",size:"small",startIcon:(0,o.jsx)(A.A,{}),onClick:()=>E(!0),children:I("flows.serverTools.connect")})}),U]}):(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)(eJ.A,{value:P||(null==(l=c[0])?void 0:l.nodeId)||"",onChange:(e,t)=>Q(t),variant:"scrollable",scrollButtons:"auto",sx:{flexGrow:1},children:c.map(e=>{if(!e||!e.nodeId||!e.serverName)return tB.warn("Skipping invalid MCP node in tabs:",e),null;let t=e.serverName,l=e.nodeId,r=e.status;R[t],x[t];let s=h[t]||[],n=q(l);return Y(l,t,s).length,(0,o.jsx)(eZ.A,{value:l,label:(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(i.A,{variant:"body2",sx:{color:"connected"===r?"success.main":"error"===r?"error.main":"text.secondary"},children:t}),n.length>0&&(0,o.jsx)(tF.A,{badgeContent:n.length,color:"primary",sx:{ml:1}})]}),sx:{textTransform:"none",minHeight:"48px",opacity:"connected"!==r?.7:1}},l)})}),L&&(0,o.jsx)(p.A,{title:I("flows.serverTools.connectAnother"),children:(0,o.jsx)(u.A,{size:"small",onClick:()=>E(!0),sx:{ml:1},children:(0,o.jsx)(A.A,{fontSize:"small"})})}),U]}),et&&el&&(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"flex-end",mb:2},children:[(0,o.jsx)(p.A,{title:I("flows.serverTools.retry",{server:el}),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{size:"small",onClick:e=>Z(el,e),disabled:R[el]||x[el],children:R[el]?(0,o.jsx)(N.default,{size:16}):(0,o.jsx)(tz.A,{fontSize:"small"})})})}),"connected"===et.status&&T&&(0,o.jsx)(p.A,{title:I("flows.serverTools.restart",{server:el}),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{size:"small",onClick:e=>ee(el,e),disabled:R[el],sx:{ml:1},children:(0,o.jsx)(tH.A,{fontSize:"small"})})})})]}),(0,o.jsx)(v.A,{placeholder:I("flows.serverTools.searchTools"),variant:"outlined",size:"small",fullWidth:!0,value:K,onChange:e=>G(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(J.A,{position:"start",children:(0,o.jsx)(tE.A,{fontSize:"small"})})}}),(0,o.jsx)(M.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 140px)"},children:et&&el&&(()=>{let e=et.nodeId,t=et.serverName;if("connected"!==et.status)return(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(i.A,{color:"text.secondary",children:I("flows.serverTools.notConnectedTools",{server:t})})},e);if(x[t])return(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,o.jsx)(N.default,{size:24})},e);let l=h[t]||[],r=Y(e,t,l);if(0===r.length){let t=q(e).length;return(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(i.A,{color:"text.secondary",children:K.trim()?I("flows.serverTools.noMatch",{search:K}):0===t?I("flows.serverTools.noneEnabled"):I("flows.serverTools.noneAvailable")})},e)}return(0,o.jsx)(ev.A,{disablePadding:!0,children:r.map(l=>{let r,s=(r=l.name,"".concat(e,"::").concat(r)),n=!!X[s],d=l.description||I("flows.agentTools.noDescription"),c=(e=>{var t;let l=Object.keys(null!=(t=null==e?void 0:e.properties)?t:{}).length;if(0===l)return I("flows.serverTools.parameter.none");let o=Array.isArray(null==e?void 0:e.required)?e.required.length:0,r=o>0?F("flows.serverTools.required",o):"";return F("flows.serverTools.parameter",l,{required:r})})(l.inputSchema);return(0,o.jsx)(tP.A,{variant:"outlined",role:"button",tabIndex:0,"aria-label":I("flows.serverTools.addTool",{tool:l.name,server:t}),onClick:()=>$(e,t,l.name),onKeyDown:o=>{o.target===o.currentTarget&&("Enter"===o.key||" "===o.key)&&(o.preventDefault(),$(e,t,l.name))},sx:{mb:1,mx:1,mt:1,cursor:"pointer","&:hover":{boxShadow:1,bgcolor:"action.hover"},"&:focus-visible":{outline:"2px solid",outlineColor:"primary.main",outlineOffset:1}},children:(0,o.jsxs)(tR.A,{sx:{p:1.25,"&:last-child":{pb:1.25}},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"flex-start",gap:1},children:[(0,o.jsxs)(a.default,{sx:{flexGrow:1,minWidth:0},children:[(0,o.jsxs)(i.A,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(tW.A,{fontSize:"small",sx:{mr:1,color:"primary.main",flexShrink:0}}),(0,o.jsx)(a.default,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.name})]}),(0,o.jsx)(p.A,{title:d,describeChild:!0,placement:"top-start",children:(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",tabIndex:0,sx:{mt:.5,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden"},children:d})}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:.5},children:c})]}),(0,o.jsx)(p.A,{title:I(n?"flows.serverTools.collapse":"flows.serverTools.expand",{tool:l.name}),children:(0,o.jsx)(u.A,{size:"small","aria-label":I(n?"flows.serverTools.collapse":"flows.serverTools.expand",{tool:l.name}),"aria-expanded":n,"aria-controls":"".concat(s,"-details"),onClick:e=>((e,t)=>{t.stopPropagation(),_(t=>({...t,[e]:!t[e]}))})(s,e),children:n?(0,o.jsx)(tD.A,{}):(0,o.jsx)(tL.A,{})})})]}),n&&(0,o.jsxs)(a.default,{id:"".concat(s,"-details"),sx:{mt:1,pt:1,borderTop:1,borderColor:"divider"},onClick:e=>e.stopPropagation(),children:[(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{whiteSpace:"pre-wrap"},children:d}),l.inputSchema&&(e=>e&&e.properties?(0,o.jsxs)(a.default,{sx:{mt:1},children:[(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{fontWeight:"medium"},children:I("flows.agentTools.parameters")}),(0,o.jsx)(a.default,{sx:{pl:1,mt:.5},children:Object.entries(e.properties).map(t=>{var l;let[r,s]=t;return(0,o.jsxs)(a.default,{sx:{mb:.5},children:[(0,o.jsxs)(i.A,{variant:"caption",component:"span",sx:{fontWeight:"medium"},children:[r,(null==(l=e.required)?void 0:l.includes(r))&&(0,o.jsx)(i.A,{variant:"caption",component:"span",color:"error.main",children:" *"}),": "]}),(0,o.jsx)(i.A,{variant:"caption",component:"span",color:"text.secondary",children:s.description||s.type||I("flows.agentTools.noDescription")})]},r)})})]}):null)(l.inputSchema)]})]})},l.name)})},e)})()})]})]})},tO=(0,E.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerResources"),tU=e=>{let{primary:t,secondary:l,chip:r,tooltip:s,onClick:n}=e;return(0,o.jsx)(tP.A,{variant:"outlined",onClick:n,title:s,sx:{mb:1,mx:1,mt:1,cursor:"pointer","&:hover":{boxShadow:1,bgcolor:"action.hover"}},children:(0,o.jsx)(tR.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)(i.A,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(el.A,{fontSize:"small",sx:{mr:1,color:"primary.main"}}),t]}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:.5,wordBreak:"break-all"},children:l})]}),r&&(0,o.jsx)(I.A,{size:"small",label:r,sx:{ml:1,flexShrink:0}})]})})})},tK=e=>{var t;let{connectedMcpNodes:l,handleInsertResourceBinding:s,promptBuilderRef:n}=e,{t:d}=(0,ed.s9)(),[c,u]=(0,r.useState)(null),[p,f]=(0,r.useState)([]),[h,g]=(0,r.useState)([]),[x,w]=(0,r.useState)(!1),[b,y]=(0,r.useState)(),[j,A]=(0,r.useState)(""),C=l.find(e=>e.nodeId===c),S=null==C?void 0:C.serverName;(0,r.useEffect)(()=>{l.length>0&&!c&&u(l[0].nodeId)},[l,c]);let k=(0,r.useCallback)(async e=>{w(!0),y(void 0);try{let t=await B.S.listServerResources(e);f(t.resources||[]),g(t.resourceTemplates||[]),y(t.error)}catch(t){tO.warn("Failed to load resources for ".concat(e),t),y(t instanceof Error?t.message:d("flows.serverResources.loadFailed"))}finally{w(!1)}},[d]);(0,r.useEffect)(()=>{S?k(S):(f([]),g([]))},[S,k]);let T=e=>e.toLowerCase().includes(j.toLowerCase().trim()),I=j.trim()?p.filter(e=>T(e.name||"")||T(e.uri)||T(e.description||"")):p,F=j.trim()?h.filter(e=>T(e.name||"")||T(e.uriTemplate)||T(e.description||"")):h,P=e=>{S&&e&&s(S,e)};return(0,o.jsxs)(a.default,{sx:{mt:4,display:"flex",flexDirection:"column",height:"100%"},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:d("flows.serverResources.title")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{mb:1},children:d("flows.serverResources.help")}),0===l.length?(0,o.jsxs)(a.default,{sx:{p:2,border:"1px dashed rgba(0, 0, 0, 0.12)",borderRadius:1},children:[(0,o.jsx)(i.A,{color:"text.secondary",align:"center",children:d("flows.serverTools.noneConnected")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:d("flows.serverResources.connectHelp")})]}):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",flexGrow:1,height:"calc(100% - 40px)"},children:[(0,o.jsx)(eJ.A,{value:c||(null==(t=l[0])?void 0:t.nodeId)||"",onChange:(e,t)=>u(t),variant:"scrollable",scrollButtons:"auto",sx:{mb:2,borderBottom:1,borderColor:"divider"},children:l.map(e=>(0,o.jsx)(eZ.A,{value:e.nodeId,label:(0,o.jsx)(i.A,{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:d("flows.serverResources.search"),variant:"outlined",size:"small",fullWidth:!0,value:j,onChange:e=>A(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(J.A,{position:"start",children:(0,o.jsx)(tE.A,{fontSize:"small"})})}}),b&&(0,o.jsx)(m.A,{severity:"warning",sx:{mb:2},children:b}),(0,o.jsx)(M.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 140px)"},children:C&&"connected"!==C.status?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(i.A,{color:"text.secondary",children:d("flows.serverResources.notConnected",{server:S||""})})}):x?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,o.jsx)(N.default,{size:24})}):0===I.length&&0===F.length?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(i.A,{color:"text.secondary",children:j.trim()?d("flows.serverResources.noMatch",{search:j}):d("flows.serverResources.none")})}):(0,o.jsxs)(ev.A,{disablePadding:!0,children:[I.map(e=>(0,o.jsx)(tU,{primary:e.name||e.uri,secondary:e.description||e.uri,chip:e.mimeType,tooltip:d("flows.serverResources.add",{resource:e.name||e.uri}),onClick:()=>P(e.uri)},e.uri)),F.map(e=>(0,o.jsx)(tU,{primary:e.name||e.uriTemplate,secondary:e.description||e.uriTemplate,chip:"template",tooltip:d("flows.serverResources.addTemplate",{template:e.uriTemplate}),onClick:()=>P(e.uriTemplate)},e.uriTemplate))]})})]})]})},tG=(0,y.A)((0,o.jsx)("path",{d:"M19 12v7H5v-7H3v7c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-7zm-6 .67 2.59-2.58L17 11.5l-5 5-5-5 1.41-1.41L11 12.67V3h2z"}),"SaveAlt"),tX=e=>{let{wiredResources:t,promptBuilderRef:l}=e,{t:r}=(0,ed.s9)();return 0===t.length?null:(0,o.jsxs)(a.default,{sx:{mb:3},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:r("flows.wired.title")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:r("flows.wired.help")}),(0,o.jsx)(ev.A,{disablePadding:!0,children:t.map(e=>(0,o.jsx)(tP.A,{variant:"outlined",sx:{mb:1,mt:1},children:(0,o.jsx)(tR.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)(i.A,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(el.A,{fontSize:"small",sx:{mr:1,color:"primary.main"}}),e.label]}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:.5,wordBreak:"break-all"},children:"run"===e.scope?e.runName?r("flows.wired.temporaryNamed",{name:e.runName}):r("flows.wired.temporaryUnnamed"):r("flows.wired.mcp",{uri:e.uri?" ".concat(e.uri):"",server:e.boundServer?r("flows.wired.onServer",{server:e.boundServer}):""})})]}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",flexShrink:0,ml:1,gap:.5},children:["run"===e.scope&&e.runName&&(0,o.jsx)(p.A,{title:r("flows.wired.insert",{reference:"${res:".concat(e.runName,"}")}),children:(0,o.jsx)(I.A,{size:"small",icon:(0,o.jsx)(tG,{}),label:"${res:".concat(e.runName,"}"),onClick:()=>(e=>{e&&l.current&&l.current.insertText("${res:".concat(e,"}"))})(e.runName),clickable:!0,sx:{maxWidth:220}})}),(0,o.jsx)(I.A,{size:"small",color:"produce"===e.role?"secondary":"default",label:"produce"===e.role?r("flows.wired.produce"):r("flows.wired.consume")})]})]})})},"".concat(e.role,"-").concat(e.id)))})]})},t_=(0,E.h)("frontend/components/flow/FlowBuilder/Modals/ProcessNodePropertiesModal/ServerTools/AgentTools"),t$=e=>{let{handoffTools:t,isLoadingHandoffTools:l,handleInsertToolBinding:s,promptBuilderRef:n}=e,{t:d,formatList:c}=(0,ed.s9)(),[u,f]=(0,r.useState)(""),m=t.filter(e=>{if(!u.trim())return!0;let t=u.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)(i.A,{variant:"subtitle1",gutterBottom:!0,children:d("flows.agentTools.title")}),l?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(N.default,{size:20}),(0,o.jsx)(i.A,{color:"text.secondary",children:d("flows.agentTools.loading")})]}):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)(i.A,{color:"text.secondary",align:"center",children:d("flows.agentTools.none")}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",align:"center",display:"block",sx:{mt:1},children:d("flows.agentTools.connectHelp")})]}):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",flexGrow:1,height:"calc(100% - 40px)"},children:[(0,o.jsx)(v.A,{placeholder:d("flows.agentTools.search"),variant:"outlined",size:"small",fullWidth:!0,value:u,onChange:e=>f(e.target.value),sx:{mb:2},InputProps:{startAdornment:(0,o.jsx)(J.A,{position:"start",children:(0,o.jsx)(tE.A,{fontSize:"small"})})}}),(0,o.jsx)(M.A,{variant:"outlined",sx:{flexGrow:1,overflow:"auto",p:0,height:"calc(100% - 56px)"},children:0===m.length?(0,o.jsx)(a.default,{sx:{p:2,textAlign:"center"},children:(0,o.jsx)(i.A,{color:"text.secondary",children:u.trim()?d("flows.agentTools.noMatch",{search:u}):d("flows.agentTools.none")})}):(0,o.jsx)(ev.A,{disablePadding:!0,children:m.map(e=>(0,o.jsxs)(tP.A,{variant:"outlined",onClick:()=>{e.name?(t_.debug("Inserting handoff tool binding",{toolType:"handoff",toolName:e.name}),s("handoff",e.name)):t_.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)(tR.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)(i.A,{variant:"subtitle2",component:"div",sx:{display:"flex",alignItems:"center"},children:[(0,o.jsx)(tW.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),e.name]}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:.5},children:e.description||d("flows.agentTools.noDescription")}),e.inputSchema&&(e=>e&&e.properties&&0!==Object.keys(e.properties).length?(0,o.jsxs)(a.default,{sx:{mt:1},children:[(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{fontWeight:"medium"},children:d("flows.agentTools.parameters")}),(0,o.jsx)(a.default,{sx:{pl:1,mt:.5},children:Object.entries(e.properties).map(t=>{var l;let[r,s]=t;return(0,o.jsxs)(a.default,{sx:{mb:.5},children:[(0,o.jsxs)(i.A,{variant:"caption",component:"span",sx:{fontWeight:"medium"},children:[r,(null==(l=e.required)?void 0:l.includes(r))&&(0,o.jsx)(i.A,{variant:"caption",component:"span",color:"error.main",children:" *"}),": "]}),(0,o.jsx)(i.A,{variant:"caption",component:"span",color:"text.secondary",children:s.description||s.type||d("flows.agentTools.noDescription")}),s.enum&&(0,o.jsx)(a.default,{sx:{pl:2,mt:.5},children:(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:d("flows.agentTools.options",{options:c(s.enum)})})})]},r)})})]}):(0,o.jsx)(a.default,{sx:{mt:1},children:(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{fontStyle:"italic"},children:d("flows.agentTools.noParameters")})}))(e.inputSchema)]})})}),(0,o.jsx)(p.A,{title:d("flows.agentTools.insert",{tool:e.name}),children:(0,o.jsx)(a.default,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0}})})]},e.name))})})]})]})};var tq=l(95480);let tY=(0,E.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ProcessNodePropertiesModal/PromptTemplateEditor"),tQ=(0,r.forwardRef)((e,t)=>{let{t:l}=(0,ed.s9)(),{promptTemplate:s,handlePromptChange:n,excludeModelPrompt:c,excludeStartNodePrompt:u,excludeSystemPrompt:p,nodeData:f,flowId:h,suggestions:g}=e,[x,w]=(0,r.useState)(""),[v,b]=(0,r.useState)(!1),[y,j]=(0,r.useState)(null),A=(0,r.useRef)(null);(0,r.useImperativeHandle)(t,()=>({insertText:e=>{A.current&&A.current.insertText(e)},getMode:()=>A.current?A.current.getMode():"raw"}));let C=async()=>{if(tY.debug("fetchRenderedPrompt called with:",{flowId:h,nodeId:null==f?void 0:f.id}),!h||!f||!f.id)return void j(l("flows.promptPreview.missingIds"));b(!0),j(null);try{var e;let t=await fetch("/api/flow/prompt-renderer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:h,nodeId:f.id,options:{renderMode:"rendered",includeConversationHistory:!1,excludeModelPrompt:c,excludeStartNodePrompt:u,excludeSystemPrompt:p}})}),o=await t.json();if(!t.ok)throw Error(o.error||l("flows.promptPreview.failed"));tY.debug("Rendered prompt received",{promptLength:null==(e=o.prompt)?void 0:e.length}),w("".concat(o.prompt,"\n\n[").concat(l("flows.promptPreview.userMessages"),"]"))}catch(e){tY.error("Error fetching rendered prompt",e),j(e instanceof Error?e.message:l("flows.promptPreview.unknownError"))}finally{b(!1)}};return(0,r.useEffect)(()=>{A.current&&"preview"===A.current.getMode()&&C()},[s,c,u,p,h,null==f?void 0:f.id]),(0,o.jsx)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:(0,o.jsx)(tq.A,{ref:A,value:s,onChange:n,label:"",height:"100%",onModeChange:e=>{"preview"===e&&C()},customPreviewRenderer:()=>v?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(N.default,{size:40})}):y?(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",p:2},children:[(0,o.jsx)(m.A,{severity:"error",sx:{mb:2},action:(0,o.jsx)(d.A,{color:"inherit",size:"small",onClick:C,children:l("flows.promptPreview.retry")}),children:y}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:2,textAlign:"center"},children:h?l("flows.promptPreview.checkIds"):l("flows.promptPreview.unsaved")})]}):(0,o.jsxs)(a.default,{sx:{p:2},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"medium"},children:l("flows.promptPreview.title")}),(0,o.jsx)(M.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:x||l("flows.promptPreview.empty")})})]}),suggestions:g})})});tQ.displayName="PromptTemplateEditor";let tJ=(0,y.A)((0,o.jsx)("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9m-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8z"}),"History"),tZ=(0,y.A)((0,o.jsx)("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"}),"ShortText"),t0=(0,y.A)((0,o.jsx)("path",{d:"M3 10h11v2H3zm0-2h11V6H3zm0 8h7v-2H3zm15.01-3.13.71-.71c.39-.39 1.02-.39 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71-5.3 5.3V21h2.12l5.3-5.3z"}),"EditNote");var t1=l(54178);let t2=(0,y.A)((0,o.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 14H6l-2 2V4h16z"}),"ChatBubbleOutline"),t5=e=>{let{selected:t,icon:l,title:r,description:s,onClick:n}=e;return(0,o.jsxs)(a.default,{role:"radio","aria-checked":t,tabIndex:0,onClick:n,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),n())},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)(eT.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:[l,(0,o.jsx)(i.A,{variant:"subtitle1",sx:{fontWeight:600,color:"text.primary"},children:r})]}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:s})]})},t4=e=>{let{excludeModelPrompt:t,setExcludeModelPrompt:l,excludeStartNodePrompt:r,setExcludeStartNodePrompt:s,excludeSystemPrompt:n,setExcludeSystemPrompt:d,inputMode:c,setInputMode:u,isolatedPrompt:p,setIsolatedPrompt:f,allowCallerPrompt:m,setAllowCallerPrompt:h,outputMode:g,setOutputMode:x,isModelBound:w,models:b,nodeData:y}=e,{t:j}=(0,ed.s9)();return(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column"},children:[(0,o.jsxs)(a.default,{sx:{display:"flex",gap:2,flexWrap:"wrap",mb:2},children:[(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:t,onChange:e=>l(e.target.checked),color:"primary",size:"small"}),label:j("flows.process.excludeModel")}),(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:r,onChange:e=>s(e.target.checked),color:"primary",size:"small"}),label:j("flows.process.excludeStart")}),(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:n,onChange:e=>d(e.target.checked),color:"primary",size:"small"}),label:j("flows.process.excludeSystem")})]}),(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)(i.A,{variant:"caption",sx:{display:"block",mb:1,fontWeight:"bold"},children:j("flows.process.renderOrder")}),(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[!r&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(i.A,{variant:"caption",sx:{color:"primary.main",fontWeight:"medium"},children:["1. ",j("flows.process.startPrompt")]}),(0,o.jsx)(i.A,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:j("flows.process.fromStart")})]}),!t&&w&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(i.A,{variant:"caption",sx:{color:"secondary.main",fontWeight:"medium"},children:[r?"1.":"2."," ",j("flows.process.modelPrompt")]}),(0,o.jsx)(i.A,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:j("flows.process.fromModel",{model:(()=>{var e,t;let l=null==(e=y.properties)?void 0:e.boundModel;if(!l)return j("flows.process.none");let o=b.find(e=>e.id===l);return o?o.displayName||o.name:(null==(t=y.properties)?void 0:t.modelName)||j("flows.process.none")})()})})]}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(i.A,{variant:"caption",sx:{fontWeight:"medium"},children:[r||t||!w?r&&(t||!w)?"1.":"2.":"3."," ",j("flows.process.nodePrompt")]}),(0,o.jsx)(i.A,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:j("flows.process.fromTask")})]}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center"},children:[(0,o.jsxs)(i.A,{variant:"caption",sx:{fontWeight:"medium"},children:[r||t||!w?r&&(t||!w)?"2.":"3.":"4."," ","isolated"===c?j("flows.subflow.isolatedPrompt"):"latest-message"===c?j("flows.subflow.latest"):j("flows.process.history")]}),(0,o.jsx)(i.A,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:"isolated"===c?j("flows.process.isolatedDetail"):"latest-message"===c?j("flows.process.latestDetail"):j("flows.process.historyDetail")})]})]})]}),(0,o.jsxs)(a.default,{sx:{mb:2},children:[(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mb:1},children:j("flows.process.receiveTitle")}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":j("flows.process.inputAria"),sx:{display:"flex",gap:1.5,flexWrap:"wrap"},children:[(0,o.jsx)(t5,{selected:"full-history"===c,onClick:()=>u("full-history"),icon:(0,o.jsx)(tJ,{fontSize:"small"}),title:j("flows.subflow.fullHistory"),description:j("flows.process.fullInputHelp")}),(0,o.jsx)(t5,{selected:"latest-message"===c,onClick:()=>u("latest-message"),icon:(0,o.jsx)(tZ,{fontSize:"small"}),title:j("flows.subflow.latest"),description:j("flows.process.latestInputHelp")}),(0,o.jsx)(t5,{selected:"isolated"===c,onClick:()=>u("isolated"),icon:(0,o.jsx)(t0,{fontSize:"small"}),title:j("flows.subflow.isolated"),description:j("flows.process.isolatedInputHelp")})]}),"isolated"===c&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(F.A,{sx:{mt:1,display:"block"},control:(0,o.jsx)(tf.A,{checked:m,onChange:e=>h(e.target.checked)}),label:j("flows.subflow.allowCallerPrompt")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{ml:4,mt:-.5},children:j("flows.process.callerPromptHelp")}),(0,o.jsx)(v.A,{fullWidth:!0,label:m?j("flows.subflow.defaultPrompt"):j("flows.subflow.isolatedPrompt"),value:p,onChange:e=>f(e.target.value),margin:"normal",multiline:!0,rows:2,helperText:m?j("flows.process.defaultUserHelp"):j("flows.process.isolatedUserHelp")})]})]}),(0,o.jsxs)(a.default,{sx:{mb:1},children:[(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mb:1},children:j("flows.process.outputTitle")}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":j("flows.process.outputAria"),sx:{display:"flex",gap:1.5,flexWrap:"wrap"},children:[(0,o.jsx)(t5,{selected:"full-conversation"===g,onClick:()=>x("full-conversation"),icon:(0,o.jsx)(t1.A,{fontSize:"small"}),title:j("flows.subflow.fullHistory"),description:j("flows.process.fullOutputHelp")}),(0,o.jsx)(t5,{selected:"latest-message"===g,onClick:()=>x("latest-message"),icon:(0,o.jsx)(t2,{fontSize:"small"}),title:j("flows.subflow.latest"),description:j("flows.process.latestOutputHelp")})]})]})]})},t3=e=>{let{nodeData:t,handlePropertyChange:l,properties:r}=e,{t:s}=(0,ed.s9)();return(0,o.jsx)(o.Fragment,{children:r.length>0&&(0,o.jsxs)(a.default,{sx:{mt:3},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:s("flows.nodeProperties.title")}),r.map(e=>(e=>{var r,s,n;if(!t)return null;let a=null!=(s=null==(r=t.properties)?void 0:r[e.key])?s:"";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:a,onChange:t=>l(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:a,inputProps:{min:e.min,max:e.max,step:e.step},onChange:t=>{let o=t.target.value;l(e.key,""===o?void 0:Number(o))},margin:"normal",helperText:e.helperText},e.key);case"select":return(0,o.jsxs)(tr.A,{fullWidth:!0,margin:"normal",children:[(0,o.jsx)(ts.A,{children:e.label}),(0,o.jsx)(tn.A,{value:a||"",label:e.label,onChange:t=>l(e.key,t.target.value),children:null==(n=e.options)?void 0:n.map(e=>(0,o.jsx)(H.A,{value:e,children:e},e))})]},e.key);case"boolean":return(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:a||!1,onChange:t=>l(e.key,t.target.checked)}),label:e.label,sx:{my:1}},e.key);default:return null}})(e))]})})},t9=e=>{let{value:t,onChange:l,onInsertRef:r}=e,{t:s}=(0,ed.s9)(),n=t.captureVariable.trim(),c=t.captureKvKey.trim(),u=t.captureResource.trim(),p=""===n||eF(n),f=""===c||eW(c);return(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mb:.5},children:s("flows.capture.title")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:2},children:s("flows.capture.help")}),(0,o.jsxs)(eQ.A,{direction:"row",spacing:1,alignItems:"flex-start",sx:{mb:2},children:[(0,o.jsx)(v.A,{fullWidth:!0,size:"small",label:s("flows.capture.variable"),value:t.captureVariable,onChange:e=>l({captureVariable:e.target.value}),error:!p,helperText:p?s("flows.capture.variableHelp"):s("flows.capture.invalidName")}),r&&(0,o.jsx)(d.A,{variant:"outlined",size:"small",sx:{mt:.5,whiteSpace:"nowrap",textTransform:"none"},disabled:!n||!p,onClick:()=>r("${var:".concat(n,"}")),children:s("flows.capture.insert",{token:"${var:NAME}"})})]}),(0,o.jsxs)(eQ.A,{direction:"row",spacing:1,alignItems:"flex-start",sx:{mb:2},children:[(0,o.jsx)(v.A,{fullWidth:!0,size:"small",label:s("flows.capture.resource"),value:t.captureResource,onChange:e=>l({captureResource:e.target.value}),helperText:s("flows.capture.resourceHelp")}),r&&(0,o.jsx)(d.A,{variant:"outlined",size:"small",sx:{mt:.5,whiteSpace:"nowrap",textTransform:"none"},disabled:!u,onClick:()=>r("${res:".concat(u,"}")),children:s("flows.capture.insert",{token:"${res:NAME}"})})]}),(0,o.jsxs)(eQ.A,{direction:"row",spacing:1,alignItems:"flex-start",children:[(0,o.jsx)(v.A,{select:!0,size:"small",label:s("flows.capture.scope"),sx:{width:130,flexShrink:0},value:t.captureKvScope,onChange:e=>l({captureKvScope:e.target.value}),children:eR.map(e=>(0,o.jsx)(H.A,{value:e,children:"folder"===e?s("flows.capture.scope.folder"):"flow"===e?s("flows.capture.scope.flow"):s("flows.capture.scope.global")},e))}),(0,o.jsx)(v.A,{fullWidth:!0,size:"small",label:s("flows.capture.kv"),value:t.captureKvKey,onChange:e=>l({captureKvKey:e.target.value}),error:!f,helperText:f?s("flows.capture.kvHelp"):s("flows.capture.invalidName")}),r&&(0,o.jsx)(d.A,{variant:"outlined",size:"small",sx:{mt:.5,whiteSpace:"nowrap",textTransform:"none"},disabled:!c||!f,onClick:()=>r("${kv:".concat(c,"}")),children:s("flows.capture.insert",{token:"${kv:NAME}"})})]})]})},t6=(0,E.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ProcessNodePropertiesModal"),t8=["basic","model","io","task","advanced"],t7=e=>{var t;let{open:l,node:s,onClose:n,onSave:c,flowEdges:p=[],flowNodes:f=[],flowId:m,onConnectMcpServer:w,authoringMode:v="advanced",mode:y="edit"}=e;t6.debug("ProcessNodePropertiesModal rendered with:",{node:s,flowId:m});let{t:j}=(0,ed.s9)(),A={basic:j("flows.process.basic"),model:j("flows.process.model"),io:j("flows.process.io"),task:j("flows.process.task"),advanced:j("flows.process.advanced")},{nodeData:C,setNodeData:S,handlePropertyChange:k}=(e=>{let[t,l]=(0,r.useState)(null);(0,r.useEffect)(()=>{e&&l({id:e.id,...e.data,properties:{...e.data.properties}})},[e]);let o=(0,r.useCallback)((e,t)=>{l(l=>l?{...l,properties:{...l.properties,[e]:t}}:null)},[]);return{nodeData:t,setNodeData:l,handlePropertyChange:o}})(s),[T,M]=(0,r.useState)(""),[I,N]=(0,r.useState)(!1),[z,H]=(0,r.useState)(!1),[E,W]=(0,r.useState)(!1),[L,D]=(0,r.useState)(!1),[O,U]=(0,r.useState)("full-history"),[K,G]=(0,r.useState)(""),[X,q]=(0,r.useState)(!0),[Y,Q]=(0,r.useState)("full-conversation"),[J,Z]=(0,r.useState)(!1),[ee,et]=(0,r.useState)(""),[el,eo]=(0,r.useState)(""),[er,es]=(0,r.useState)("folder"),[en,ea]=(0,r.useState)(""),[ei,ec]=(0,r.useState)("server"),[eu,ep]=(0,r.useState)("basic"),ef="advanced"===v?t8:t8.filter(e=>["basic","model","task"].includes(e)),em=(0,r.useRef)(null),eh=(0,r.useRef)(null),eg=(0,r.useRef)(null),ex=(0,r.useRef)(null),ew=(0,r.useRef)(null),ev=(0,r.useRef)(null),eb={basic:eh,model:eg,io:ex,task:ew,advanced:ev},ey=(0,r.useRef)(!1);(0,r.useEffect)(()=>{"guided"===v&&("io"===eu||"advanced"===eu)&&ep("basic"),"guided"===v&&"server"!==ei&&ec("server")},[eu,ei,v]);let{models:ej,isLoadingModels:eA,loadError:eC,handleModelSelect:eS,handleUnbindModel:ek}=((e,t,l,o,s)=>{var n,a;let{t:i}=(0,ed.s9)();tb.debug("useModelManagement: Entering hook");let[d,c]=(0,r.useState)([]),[u,p]=(0,r.useState)(!1),[f,m]=(0,r.useState)(null);(0,r.useEffect)(()=>{tb.debug("useModelManagement useEffect: Checking if modal is open",{open:e}),e&&h()},[e]),(0,r.useEffect)(()=>{var e,o;if(0===d.length)return;let r=null==t||null==(e=t.properties)?void 0:e.boundModel;if(!r)return;let s=d.find(e=>e.id===r);s&&s.name&&(null==t||null==(o=t.properties)?void 0:o.modelName)!==s.name&&l(e=>{var t;return e&&(null==(t=e.properties)?void 0:t.modelName)!==s.name?{...e,properties:{...e.properties,modelName:s.name}}:e})},[d,null==t||null==(n=t.properties)?void 0:n.boundModel,null==t||null==(a=t.properties)?void 0:a.modelName,l]);let h=async()=>{tb.debug("loadModels: Entering method"),p(!0),m(null);try{let e=await V.N.loadModels();c(e)}catch(e){tb.warn("loadModels: Failed to load models:",e),m(i("flows.process.loadModelsFailed"))}p(!1)},g=(0,r.useCallback)(e=>{tb.debug("handleModelSelect: Entering method",{modelId:e});let t=d.find(t=>t.id===e);t&&(l(l=>{var o;if(!l)return null;let r=d.find(e=>{var t;return e.id===(null==(t=l.properties)?void 0:t.boundModel)}),s=tv({currentLabel:l.label,nameIsCustom:null==(o=l.properties)?void 0:o.nameIsCustom,defaultLabel:"Process Node",previousAutoLabel:r?r.displayName||r.name:void 0,nextAutoLabel:t.displayName||t.name});return{...l,label:s,properties:{...l.properties,boundModel:e,modelName:t.name}}}),s(!0))},[d,l,o,s]);return{models:d,isLoadingModels:u,loadError:f,handleModelSelect:g,handleUnbindModel:(0,r.useCallback)(()=>{tb.debug("handleUnbindModel: Entering method"),l(e=>{if(!e)return null;let{boundModel:t,modelName:l,...o}=e.properties;return{...e,properties:{...o,promptTemplate:o.promptTemplate||""}}}),s(!1)},[l,s])}})(l,C,S,M,N),{connectedMcpNodes:eT,allServers:eM,isLoadingServers:eI,selectedToolServerNodeId:eN,serverToolsMap:eF,serverStatuses:eP,isLoadingTools:eR,handleSelectToolServer:eE,isLoadingSelectedServerTools:eW,handleRetryServer:eL,handleRestartServer:eD}=((e,t,l,o)=>{let s=(0,ty.v)(),n=s.servers||[],a=s.isLoading||!1,[i,d]=(0,r.useState)({}),[c,u]=(0,r.useState)({}),[p,f]=(0,r.useState)({}),[m,h]=(0,r.useState)(null),[g,x]=(0,r.useState)(!1),w=(0,r.useMemo)(()=>t?((e,t)=>[...new Set(t.filter(t=>{var l,o;return t.source===e&&(null==(l=t.data)?void 0:l.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,l):[],[t,l]),v=(0,r.useMemo)(()=>{if(!t||0===w.length)return[];if(!o||!Array.isArray(o))return tj.warn("flowNodes is not available or not an array when filtering connected servers"),[];try{let e=[],t=new Set;return w.forEach(l=>{if(t.has(l))return;let r=o.find(e=>e&&e.id===l);if(!r||!r.data||!r.data.properties)return void tj.warn("Could not find valid MCP node data for ID ".concat(l));let s=r.data.properties.boundServer;if(!s)return void tj.warn("MCP node ".concat(l," is not bound to any server."));let a=n.find(e=>e.name===s),i=(null==a?void 0:a.status)||"unknown",d=r.data.properties.enabledTools||[],c=r.data.properties.enabledResources;e.push({nodeId:l,serverName:s,status:i,enabledTools:Array.isArray(d)?d:[],enabledResources:c}),t.add(l)}),tj.debug("Generated connectedMcpNodes:",JSON.stringify(e)),e}catch(e){return tj.error("Error preparing connected MCP nodes:",e),[]}},[t,w,n,o]);(0,r.useEffect)(()=>{if(v&&v.length>0){let e={};v.forEach(t=>{let l=n.find(e=>e.name===t.serverName);e[t.serverName]=(null==l?void 0:l.status)||t.status||"unknown"}),d(e)}},[v,n]),(0,r.useEffect)(()=>{if(e&&v.length>0){let e=Array.from(new Set(v.map(e=>e.serverName)));(async()=>{let t={},l={...c},o=e.filter(e=>{let t=n.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{tj.debug("Loading tools for server: ".concat(e));let t=await B.S.listServerTools(e);if(t.error)tj.warn("Error loading tools for ".concat(e,":"),t.error),l[e]=[];else{let o=t.tools||[];tj.debug("Loaded ".concat(o.length," tools for ").concat(e)),l[e]=o}}catch(t){tj.warn("Failed to load tools for server ".concat(e,":"),t),l[e]=[]}finally{f(t=>({...t,[e]:!1}))}})),u(l))})()}},[e,v,n]);let b=(0,r.useRef)(c);(0,r.useEffect)(()=>{b.current=c},[c]);let y=(0,r.useCallback)(e=>{tj.debug("Selected MCP Node ID: ".concat(e)),h(e);let t=v.find(t=>t.nodeId===e),l=null==t?void 0:t.serverName;!l||b.current[l]||p[l]?x(p[l||""]||!1):(tj.debug("Tools not loaded for server ".concat(l,", loading now.")),x(!0),f(e=>({...e,[l]:!0})),B.S.listServerTools(l).then(e=>{let t=e.tools||[];e.error?tj.warn("Error loading tools for ".concat(l,":"),e.error):tj.debug("Loaded ".concat(t.length," tools for ").concat(l)),u(e=>({...e,[l]:t}))}).catch(e=>{tj.warn("Failed to load tools for server ".concat(l,":"),e),u(e=>({...e,[l]:[]}))}).finally(()=>{x(!1),f(e=>({...e,[l]:!1}))}))},[v,p]),j=(0,r.useRef)(s);return(0,r.useEffect)(()=>{j.current=s},[s]),{connectedMcpNodes:v,allServers:n,isLoadingServers:a,selectedToolServerNodeId:m,serverToolsMap:c,serverStatuses:i,isLoadingTools:p,handleSelectToolServer:y,isLoadingSelectedServerTools:g,handleRetryServer:(0,r.useCallback)(async e=>{tj.debug("Retrying server: ".concat(e)),f(t=>({...t,[e]:!0}));try{await j.current.retryServer(e);let t=await B.S.listServerTools(e);if(t.error)return tj.warn("Error loading tools for ".concat(e," after retry:"),t.error),!1;{let l=t.tools||[];return tj.debug("Loaded ".concat(l.length," tools for ").concat(e," after retry")),u(t=>({...t,[e]:l})),!0}}catch(t){return tj.warn("Failed to retry or load tools for server ".concat(e,":"),t),!1}finally{f(t=>({...t,[e]:!1}))}},[]),handleRestartServer:(0,r.useCallback)(async e=>{tj.debug("Restarting server: ".concat(e)),f(t=>({...t,[e]:!0}));try{await B.S.restartServer(e),await new Promise(e=>setTimeout(e,1e3));let t=await B.S.listServerTools(e);if(t.error)return tj.warn("Error loading tools for ".concat(e," after restart:"),t.error),!1;{let l=t.tools||[];return tj.debug("Loaded ".concat(l.length," tools for ").concat(e," after restart")),u(t=>({...t,[e]:l})),!0}}catch(t){return tj.warn("Failed to restart or load tools for server ".concat(e,":"),t),!1}finally{f(t=>({...t,[e]:!1}))}},[])}})(l,s,p,f),[eB,eV]=(0,r.useState)([]);(0,r.useEffect)(()=>{let e=!1,t=[...new Set(eT.filter(e=>"connected"===e.status).map(e=>e.serverName))];return l&&0!==t.length?(Promise.all(t.map(async e=>{try{var t,l;let o=await B.S.listServerResources(e),r=eT.filter(t=>t.serverName===e),s=e=>r.some(t=>{let l=t.enabledResources;return void 0===l||"all"===l||l.includes(e)});return[...(null!=(t=o.resources)?t:[]).filter(e=>s(e.uri)).map(t=>(0,tw.Ub)({kind:"resource",server:e,name:t.uri},t.name||t.uri,t.description||"".concat(e," \xb7 ").concat(t.uri))),...(null!=(l=o.resourceTemplates)?l:[]).filter(e=>s(e.uriTemplate)).map(t=>(0,tw.Ub)({kind:"resource",server:e,name:t.uriTemplate},t.name||t.uriTemplate,t.description||"".concat(e," \xb7 ").concat(t.uriTemplate)))]}catch(t){return t6.warn("Failed to load @ resource suggestions for ".concat(e),t),[]}})).then(t=>{e||eV(t.flat())}),()=>{e=!0}):(eV([]),()=>{e=!0})},[l,eT]);let eO=r.useMemo(()=>[...eT.flatMap(e=>{var t,l;let o=new Set(null!=(t=e.enabledTools)?t:[]);return(null!=(l=eF[e.serverName])?l:[]).filter(e=>(null==e?void 0:e.name)&&o.has(e.name)).map(t=>(0,tw.Ub)({kind:"tool",server:e.serverName,name:t.name},t.name,t.description||e.serverName))}),...eB],[eT,eB,eF]),eU=r.useMemo(()=>{if(!s)return[];let e=[];for(let r of p){var t,l,o;let n,a;if((null==(t=r.data)?void 0:t.edgeType)!=="resource"||(r.target===s.id?(n=r.source,a="consume"):r.source===s.id&&(n=r.target,a="produce"),!n||!a))continue;let i=f.find(e=>e.id===n);if(!i||"resource"!==i.type)continue;let d=null!=(o=null==(l=i.data)?void 0:l.properties)?o:{};e.push({id:n,role:a,label:d.name||d.runName||d.uri||n,scope:d.scope,runName:d.runName,uri:d.uri,boundServer:d.boundServer})}return e},[s,p,f]),eK=((e,t,l,o)=>{let[s,n]=(0,r.useState)([]),[a,i]=(0,r.useState)(!1),d=(0,r.useMemo)(()=>t?function(e,t){let l=[];for(let s of t){var o,r;!("string"==typeof(null==(o=s.data)?void 0:o.edgeType)&&(s.data.edgeType.includes("mcp")||"resource"===s.data.edgeType))&&(s.source===e?l.push(s.target):s.target===e&&(null==(r=s.data)?void 0:r.bidirectional)&&l.push(s.source))}return[...new Set(l)]}(t.id,l):[],[t,l]);return(0,r.useEffect)(()=>{if(e&&t){i(!0);try{let e=d.map(e=>o.find(t=>t.id===e)).filter(e=>!!e),t=(0,_.E9)(e.map(e=>({id:e.id,label:e.data.label,type:e.type||e.data.type}))),l=e.map(e=>({name:t.get(e.id)||"handoff_to_".concat(e.id),description:function(e){if(e.userDescription&&e.userDescription.trim())return tA(e.userDescription,1500);let t="Hand off execution to ".concat(e.label," (").concat(e.type,")."),l=[];!function e(t,l,o){let r=" ".repeat(l);if(t.userDescription&&t.userDescription.trim())return void o.push("".concat(r).concat(tA(t.userDescription,200)));if("subflow"===t.type){var s,n;if(t.subflowMissing)return void o.push("".concat(r,"Runs a subflow (referenced flow not found)."));if(t.subflowDetailsUnavailable){let e=t.subflowName?' "'.concat(t.subflowName,'"'):"";o.push("".concat(r,"Runs a subflow").concat(e," (contents summarised when the flow runs)."));return}if(o.push("".concat(r,'Runs the subflow "').concat(null!=(s=t.subflowName)?s:"unknown",'", which contains:')),t.depthCapReached)return void o.push("".concat(r," (nested subflows omitted — recursion depth limit reached)"));let a=null!=(n=t.children)?n:[];if(0===a.length)return void o.push("".concat(r," (no process or subflow steps)"));for(let t of a.slice(0,10))o.push("".concat(r," - ").concat(t.label,":")),e(t,l+2,o);return void(a.length>10&&o.push("".concat(r," - …and ").concat(a.length-10," more step(s)")))}if(t.modelName&&o.push("".concat(r,"Model: ").concat(t.modelName)),t.promptSummary&&o.push("".concat(r,"Role: ").concat(tA(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),l=e.tools.length-t.length,s=l>0?", +".concat(l," more"):"";o.push("".concat(r,"Tools (").concat(e.name,"): ").concat(t.join(", ")).concat(s))}else o.push("".concat(r,"Tools (").concat(e.name,"): server not connected"))}(e,0,l);let o=l.join("\n").trim(),r=o?"".concat(t,"\n").concat(o):t;if(r.length<=1500)return r;let s=1500-t.length-2;return s<=0?t:"".concat(t,"\n").concat(tA(o,s))}(function(e){let t=e.type||e.data.type||"unknown",l=e.data.label||"Unknown Node",o=e.data.description,r=e.data.properties||{},s={label:l,type:t,userDescription:o};if(o&&o.trim())return s;if("subflow"===t)return s.subflowDetailsUnavailable=!0,s;"string"==typeof r.boundModel&&r.boundModel&&(s.modelName=r.boundModel),"string"==typeof r.promptTemplate&&r.promptTemplate.trim()&&(s.promptSummary=r.promptTemplate);let n=Array.isArray(r.mcpNodes)?r.mcpNodes:[],a=[],i=new Set;for(let e of n){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 l=Array.isArray(null==e||null==(c=e.properties)?void 0:c.enabledTools)?e.properties.enabledTools:[];a.push({name:t,connected:!0,tools:l})}return a.length>0&&(s.servers=a),s}(e)),inputSchema:{type:"object",properties:{},required:[]}}));n(l),tC.debug("Generated handoff tools",{toolsCount:l.length})}catch(e){tC.error("Error generating handoff tools",e),n([])}finally{i(!1)}}else n([])},[e,t,d,l,o]),{handoffTools:s,isLoadingHandoffTools:a}})(l,s,p,f),eG=(null==eK?void 0:eK.handoffTools)||[],eX=(null==eK?void 0:eK.isLoadingHandoffTools)||!1;(0,r.useEffect)(()=>{l&&s&&t6.debug("Handoff tools:",{count:eG.length,tools:eG.map(e=>e.name)})},[l,s,eG]),(0,r.useEffect)(()=>{var e,t,o,r,n,a,i,d,c,u,p,f,m,h;if(!l)return;if(s){M((null==(t=s.data.properties)?void 0:t.promptTemplate)||""),(null==(o=s.data.properties)?void 0:o.boundModel)?N(!0):N(!1),H((null==(r=s.data.properties)?void 0:r.excludeModelPrompt)||!1),W((null==(n=s.data.properties)?void 0:n.excludeStartNodePrompt)||!1),D((null==(a=s.data.properties)?void 0:a.excludeSystemPrompt)||!1),U((null==(i=s.data.properties)?void 0:i.inputMode)||"full-history"),G((null==(d=s.data.properties)?void 0:d.isolatedPrompt)||""),q((null==(c=s.data.properties)?void 0:c.allowCallerPrompt)!==!1),Q((null==(u=s.data.properties)?void 0:u.outputMode)||"full-conversation"),Z((null==(p=s.data.properties)?void 0:p.enableTodoTool)||!1),et((null==(f=s.data.properties)?void 0:f.captureVariable)||""),eo((null==(m=s.data.properties)?void 0:m.captureResource)||"");let e=ez((null==(h=s.data.properties)?void 0:h.captureKv)||"");es(e.scope),ea(e.key||"")}let g="create"===y?"basic":function(e,t){return"guided"===e&&"string"==typeof t&&t.trim().length>0?"task":"basic"}(v,null==s||null==(e=s.data.properties)?void 0:e.promptTemplate);ep(g),ec("server"),ey.current=!0;let x=window.requestAnimationFrame(()=>{let e=eb[g].current;if(e&&"function"==typeof e.scrollIntoView)e.scrollIntoView({behavior:"auto",block:"start"});else if(em.current){var t;em.current.scrollTop=null!=(t=null==e?void 0:e.offsetTop)?t:0}ey.current=!1});return()=>{window.cancelAnimationFrame(x),ey.current=!1}},[s,l,y,v]),(0,r.useEffect)(()=>{if(!l)return;let e=em.current;if(!e)return;let t=new IntersectionObserver(e=>{var t,l;if(ey.current)return;let o=null==(l=e.filter(e=>e.isIntersecting).sort((e,t)=>t.intersectionRatio-e.intersectionRatio)[0])||null==(t=l.target)?void 0:t.dataset.section;o&&ep(o)},{root:e,threshold:[.15,.4,.75],rootMargin:"0px 0px -45% 0px"});return Object.values(eb).forEach(e=>{e.current&&t.observe(e.current)}),()=>t.disconnect()},[l,s]);let e_=(0,r.useRef)(null),e$=function(e,t){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"server";if(t6.debug("handleInsertToolBinding called with:",JSON.stringify({serverName:e,toolName:t})),!e||!t)return void t6.warn("Invalid parameters for handleInsertToolBinding:",{serverName:e,toolName:t});let o=(eF[e]||[]).find(e=>e.name===t);null==o||o.description;let r="handoff"===l?(0,$.X8)("tool","handoff",t):(0,$.X8)("tool",e,t),s=(!(T.length>0)||T.endsWith(" ")||T.endsWith("\n")?"":" ")+r;e_.current?(t6.debug("Inserting text into PromptBuilder:",JSON.stringify({textToInsert:s})),e_.current.insertText(s),t6.debug("Tool binding inserted successfully")):t6.warn("promptBuilderRef.current is null, cannot insert text")};if(!s||!C)return null;let eq=(e=>[{key:"maxTurns",label:e?e("flows.nodeProperties.maxTurns"):"Maximum turns (override)",type:"number",min:1,helperText:e?e("flows.nodeProperties.maxTurnsHelp"):"Optional. Replaces the bound model's maximum turns for this node. Leave empty to inherit the model setting (default: 50)."},{key:"maxTokens",label:e?e("flows.nodeProperties.maxTokens"):"Maximum output tokens (override)",type:"number",min:1,helperText:e?e("flows.nodeProperties.maxTokensHelp"):"Optional. Replaces the bound model's maximum output tokens for this node. Leave empty to inherit the adapter default. The Claude subscription adapter does not enforce this value."}])(j),eY=(null==(t=C.properties)?void 0:t.boundModel)||"",eQ={minHeight:"100%",scrollSnapAlign:"start",scrollSnapStop:"always",display:"flex",flexDirection:"column",pb:4},e0=(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:["advanced"===v&&(0,o.jsx)(a.default,{sx:{borderBottom:1,borderColor:"divider",flexShrink:0},children:(0,o.jsxs)(eJ.A,{value:ei,onChange:(e,t)=>ec(t),variant:"scrollable",scrollButtons:"auto","aria-label":j("flows.process.toolsAria"),children:[(0,o.jsx)(eZ.A,{id:"process-task-tab-server","aria-controls":"process-task-panel-server",label:j("flows.process.mcpTab"),value:"server"}),(0,o.jsx)(eZ.A,{id:"process-task-tab-agent","aria-controls":"process-task-panel-agent",label:j("flows.process.nodesTab"),value:"agent"}),(0,o.jsx)(eZ.A,{id:"process-task-tab-resources","aria-controls":"process-task-panel-resources",label:j("flows.process.resourcesTab"),value:"resources"})]})}),(0,o.jsxs)(a.default,{id:"process-task-panel-".concat(ei),role:"tabpanel","aria-labelledby":"process-task-tab-".concat(ei),"data-testid":"process-task-tools-scroll",sx:{flexGrow:1,minHeight:0,overflow:"auto",pr:.5},children:["server"===ei&&(0,o.jsx)(tV,{isLoadingServers:eI,connectedMcpNodes:eT,availableServers:eM,onConnectMcpServer:w,serverStatuses:eP,serverToolsMap:eF,isLoadingTools:eR,handleInsertToolBinding:e$,selectedToolServerNodeId:eN,selectedNodeId:(null==s?void 0:s.id)||null,handleSelectToolServer:eE,isLoadingSelectedServerTools:eW,promptBuilderRef:e_,handleRetryServer:eL,handleRestartServer:eD}),"advanced"===v&&"resources"===ei&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(tX,{wiredResources:eU,promptBuilderRef:e_}),(0,o.jsx)(tK,{connectedMcpNodes:eT,handleInsertResourceBinding:(e,t)=>{if(!e||!t)return void t6.warn("Invalid parameters for handleInsertResourceBinding:",{serverName:e,uri:t});let l=(0,$.X8)("resource",e,t),o=T.length>0&&!T.endsWith(" ")&&!T.endsWith("\n");e_.current?e_.current.insertText((o?" ":"")+l):t6.warn("promptBuilderRef.current is null, cannot insert resource binding")},promptBuilderRef:e_})]}),"advanced"===v&&"agent"===ei&&(0,o.jsx)(t$,{handoffTools:eG,isLoadingHandoffTools:eX,handleInsertToolBinding:(e,t)=>e$(e,t,"handoff"),promptBuilderRef:e_})]})]});return(0,o.jsxs)(h.A,{open:l,onClose:n,slotProps:{transition:{onEntered:()=>{var e;"task"===eu&&(ey.current=!0,null==(e=ew.current)||e.scrollIntoView({block:"start"}),window.setTimeout(()=>{ey.current=!1},0))}}},maxWidth:"xl",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"secondary.main",width:"95vw",height:"90vh",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:j("flows.modal.properties",{name:C.label||j("flows.process.title")})}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:n,"aria-label":j("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(x.A,{sx:{display:"flex",flexDirection:"column",p:0,overflow:"hidden",height:"calc(90vh - 130px)"},children:[(0,o.jsx)(a.default,{sx:{borderBottom:1,borderColor:"divider",px:2,flexShrink:0},children:(0,o.jsx)(eJ.A,{value:eu,onChange:(e,t)=>(e=>{ep(e),ey.current=!0;let t=eb[e].current;if(t&&"function"==typeof t.scrollIntoView)t.scrollIntoView({behavior:"smooth",block:"start"});else if(em.current){var l;em.current.scrollTop=null!=(l=null==t?void 0:t.offsetTop)?l:0}window.setTimeout(()=>{ey.current=!1},700)})(t),variant:"scrollable",scrollButtons:"auto",children:ef.map(e=>(0,o.jsx)(eZ.A,{label:A[e],value:e},e))})}),(0,o.jsxs)(a.default,{ref:em,sx:{flexGrow:1,overflow:"auto",p:3,scrollSnapType:"y mandatory",scrollPaddingTop:"24px"},children:[(0,o.jsxs)(a.default,{ref:eh,"data-section":"basic",sx:eQ,children:[(0,o.jsx)(i.A,{variant:"h6",sx:{mb:2},children:j("flows.process.basic")}),(0,o.jsx)(tS,{nodeData:C,setNodeData:S})]}),(0,o.jsxs)(a.default,{ref:eg,"data-section":"model",sx:eQ,children:[(0,o.jsx)(i.A,{variant:"h6",sx:{mb:2},children:j("flows.process.model")}),(0,o.jsx)(tN,{isLoadingModels:eA,loadError:eC,models:ej,selectedModelId:eY,handleModelSelect:eS,isModelBound:I,handleUnbindModel:ek})]}),"advanced"===v&&(0,o.jsxs)(a.default,{ref:ex,"data-section":"io",sx:eQ,children:[(0,o.jsx)(i.A,{variant:"h6",sx:{mb:2},children:j("flows.process.io")}),(0,o.jsx)(t4,{excludeModelPrompt:z,setExcludeModelPrompt:H,excludeStartNodePrompt:E,setExcludeStartNodePrompt:W,excludeSystemPrompt:L,setExcludeSystemPrompt:D,inputMode:O,setInputMode:U,isolatedPrompt:K,setIsolatedPrompt:G,allowCallerPrompt:X,setAllowCallerPrompt:q,outputMode:Y,setOutputMode:Q,isModelBound:I,models:ej,nodeData:C}),(0,o.jsx)(F.A,{sx:{mt:1},control:(0,o.jsx)(P.A,{checked:J,onChange:e=>Z(e.target.checked)}),label:j("flows.process.todo")})]}),(0,o.jsxs)(a.default,{ref:ew,"data-section":"task",sx:eQ,children:[(0,o.jsx)(i.A,{variant:"h6",sx:{mb:2},children:j("flows.process.task")}),(0,o.jsxs)(a.default,{sx:{display:"flex",gap:2,flexGrow:1,minHeight:480},children:[(0,o.jsx)(a.default,{sx:{flex:"0 0 340px",minWidth:0,display:"flex",flexDirection:"column",minHeight:0},children:e0}),(0,o.jsx)(a.default,{sx:{flex:"1 1 auto",minWidth:0,display:"flex",flexDirection:"column",minHeight:0},children:(0,o.jsx)(tQ,{ref:e_,promptTemplate:T,handlePromptChange:e=>{M(e),S(t=>t?{...t,properties:{...t.properties,promptTemplate:e}}:null)},excludeModelPrompt:z,excludeStartNodePrompt:E,excludeSystemPrompt:L,nodeData:C,flowId:m,suggestions:eO})})]})]}),"advanced"===v&&(0,o.jsxs)(a.default,{ref:ev,"data-section":"advanced",sx:eQ,children:[(0,o.jsx)(i.A,{variant:"h6",sx:{mb:2},children:j("flows.process.advanced")}),(0,o.jsx)(a.default,{sx:{mb:3},children:(0,o.jsx)(t3,{nodeData:C,handlePropertyChange:k,properties:eq})}),(0,o.jsx)(a.default,{children:(0,o.jsx)(t9,{value:{captureVariable:ee,captureResource:el,captureKvScope:er,captureKvKey:en},onChange:e=>{void 0!==e.captureVariable&&et(e.captureVariable),void 0!==e.captureResource&&eo(e.captureResource),void 0!==e.captureKvScope&&es(e.captureKvScope),void 0!==e.captureKvKey&&ea(e.captureKvKey)},onInsertRef:e=>{let t=T.length>0&&!T.endsWith(" ")&&!T.endsWith("\n");e_.current?e_.current.insertText((t?" ":"")+e):t6.warn("promptBuilderRef.current is null, cannot insert capture reference")}})})]})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:n,children:j("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{if(s&&C){let e={...C.properties,promptTemplate:T};if("advanced"===v){Object.assign(e,{excludeModelPrompt:z,excludeStartNodePrompt:E,excludeSystemPrompt:L,inputMode:O,isolatedPrompt:K,allowCallerPrompt:X,outputMode:Y}),J?e.enableTodoTool=!0:delete e.enableTodoTool;let t=ee.trim();t?e.captureVariable=t:delete e.captureVariable;let l=el.trim();l?e.captureResource=l:delete e.captureResource;let o=eH(er,en);o?e.captureKv=o:delete e.captureKv}c(s.id,{...C,properties:e}),n()}},variant:"contained",color:"primary",children:j("flows.modal.saveChanges")})]})]})};var le=l(71651),lt=l(94035);let ll=(0,E.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/MCPNodePropertiesModal"),lo=e=>{var t,l,s,n,c,f,m,w;let{open:y,node:j,onClose:A,onSave:C,authoringMode:S="advanced"}=e,{t:k}=(0,ed.s9)(),[T,M]=(0,r.useState)(null),{servers:I,isLoading:z,loadError:H,retryServer:E}=(0,ty.v)(),[W,L]=(0,r.useState)({}),D=(0,te.E)("mcp",I),[B,V]=(0,r.useState)(!1),O=async()=>{V(!0);try{await Promise.all(I.map(e=>E(e.name)))}finally{setTimeout(()=>V(!1),500)}},{tools:U,isLoading:K,error:G,loadTools:X}=(0,lt.O)((null==T||null==(t=T.properties)?void 0:t.boundServer)||"");(0,r.useEffect)(()=>{j&&M({...j.data,properties:{...j.data.properties}})},[j,y]);let _=(null==T||null==(l=T.properties)?void 0:l.boundServer)||"";(0,r.useEffect)(()=>{U&&U.length>0&&(e=>{T&&0===(T.properties.enabledTools||[]).length&&e.length>0&&(ll.debug("Enabling all tools by default"),M(t=>t?{...t,properties:{...t.properties,enabledTools:e.map(e=>e.name)}}:null))})(U)},[U]);let $=(e,t)=>{M(l=>l?{...l,properties:{...l.properties,[e]:t}}:null)},q=async(e,t)=>{t&&t.stopPropagation(),ll.debug("Retrying server: ".concat(e)),L(t=>({...t,[e]:!0}));try{return await E(e),e===_&&X(!0),!0}catch(t){return ll.warn("Failed to retry server ".concat(e,": ").concat(t)),!1}finally{setTimeout(()=>{L(t=>({...t,[e]:!1}))},500)}};if(!j||!T)return null;let Y=(null==(s=T.properties)?void 0:s.boundServer)||"",Q=(null==(n=T.properties)?void 0:n.enabledTools)||[],J=e=>({key:e.name,content:(e=>(0,o.jsx)(e7.A,{name:e.name,status:e.status||"disconnected",path:e.path||e.rootPath||"",enabled:!e.disabled,transport:e.transport||"stdio",pickerMode:!0,selected:Y===e.name,onClick:()=>(e=>{ll.debug("Server selected: ".concat(e)),ll.debug("Server selected: ".concat(e)),M(t=>{var l,o;if(!t)return null;let r=tv({currentLabel:t.label,nameIsCustom:null==(l=t.properties)?void 0:l.nameIsCustom,defaultLabel:"MCP Node",previousAutoLabel:(null==(o=t.properties)?void 0:o.boundServer)||void 0,nextAutoLabel:e});return{...t,label:r,properties:{...t.properties,boundServer:e}}})})(e.name)}))(e)}),Z=D.items.map(J),ee=D.groups?D.groups.map(e=>({...e,items:e.items.map(J)})):null,et=null==(c=T.properties)?void 0:c.toolTimeout,el=-1===et;return(0,o.jsxs)(h.A,{open:y,onClose:A,maxWidth:"guided"===S?"xl":"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"info.main",width:"guided"===S?"95vw":void 0,height:"guided"===S?"90vh":"80vh",maxWidth:"guided"===S?"95vw":void 0,maxHeight:"guided"===S?"90vh":"80vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:k("flows.modal.properties",{name:T.label||k("flows.mcpNode.title")})}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:A,"aria-label":k("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(x.A,{sx:{display:"flex",flexDirection:"column",p:3,overflow:"auto"},children:[(0,o.jsx)(v.A,{fullWidth:!0,label:k("flows.mcpNode.label"),value:T.label||"",onChange:e=>{M(t=>t?{...t,label:e.target.value,properties:{...t.properties,nameIsCustom:!0}}:null)},margin:"normal",helperText:k("flows.mcpNode.labelHelp"),sx:{mb:2}}),(0,o.jsxs)(a.default,{sx:{mb:4},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:k("flows.mcpNode.bind")}),(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"flex-end",mb:1},children:(0,o.jsx)(p.A,{title:k("flows.mcpNode.retryAll"),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{size:"small",onClick:O,disabled:B||z,children:B?(0,o.jsx)(N.default,{size:16}):(0,o.jsx)(tz.A,{fontSize:"small"})})})})}),(0,o.jsx)(tM.A,{isLoading:z,error:H,emptyMessage:k("flows.mcpNode.empty"),loadingMessage:k("flows.mcpNode.loadingServers"),searchable:!0,searchPlaceholder:k("flows.mcpNode.searchServers"),searchTerm:D.searchTerm,onSearchChange:D.setSearchTerm,columns:{xs:12,sm:6},items:Z,groups:ee,collapsedKeys:D.collapsedKeys,onToggleGroup:D.toggleGroup}),(0,o.jsx)(tk.A,{children:Y?k("flows.mcpNode.bound",{server:Y}):k("flows.mcpNode.select")})]}),(0,o.jsx)(v.A,{fullWidth:!0,label:k("flows.mcpNode.description"),value:T.description||"",onChange:e=>M({...T,description:e.target.value}),margin:"normal",multiline:!0,rows:2,helperText:k("flows.mcpNode.descriptionHelp")}),Y&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:k("flows.mcpNode.timeoutTitle")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:k("flows.mcpNode.timeoutHelp")}),(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,o.jsx)(v.A,{label:k("flows.mcpNode.timeoutSeconds"),type:"number",size:"small",sx:{width:200},value:el?"":null!=et?et:"",placeholder:String(300),disabled:el,inputProps:{min:1},onChange:e=>{let t=e.target.value;if(""===t)return void $("toolTimeout",void 0);let l=parseInt(t,10);!isNaN(l)&&l>0&&$("toolTimeout",l)},helperText:el?k("flows.mcpNode.noTimeoutHelp"):k("flows.mcpNode.defaultTimeout",{seconds:300})}),(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:el,onChange:e=>$("toolTimeout",e.target.checked?-1:void 0)}),label:k("flows.mcpNode.noTimeout")})]})]}),Y&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(i.A,{variant:"subtitle1",gutterBottom:!0,children:k("flows.mcpNode.allowedTools")}),(null==(f=I.find(e=>e.name===Y))?void 0:f.status)!=="connected"&&(0,o.jsxs)(a.default,{sx:{mb:2,p:2,bgcolor:"error.light",borderRadius:1},children:[(0,o.jsx)(i.A,{color:"error.dark",children:k("flows.mcpNode.disconnected")}),(0,o.jsx)(d.A,{variant:"outlined",size:"small",color:"primary",startIcon:W[Y]?(0,o.jsx)(N.default,{size:16}):(0,o.jsx)(tz.A,{}),onClick:()=>q(Y),disabled:W[Y],sx:{mt:1},children:k("flows.mcpNode.retry")})]}),K?(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(N.default,{size:20}),(0,o.jsx)(i.A,{color:"text.secondary",children:k("flows.mcpNode.loadingTools")})]}):G?(0,o.jsx)(i.A,{color:"error",children:G}):U&&0!==U.length?(0,o.jsxs)(a.default,{sx:{mt:2},children:[(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:2},children:k("flows.mcpNode.toolsHelp")}),(0,o.jsx)(ev.A,{children:U.map(e=>(0,o.jsxs)(eA.Ay,{sx:{py:0},children:[(0,o.jsx)(eb.A,{sx:{minWidth:42},children:(0,o.jsx)(P.A,{edge:"start",checked:Q.includes(e.name),onChange:()=>(e=>{ll.debug("Tool toggled: ".concat(e)),M(t=>{let l;if(!t)return null;let o=t.properties.enabledTools||[];return l=o.includes(e)?o.filter(t=>t!==e):[...o,e],{...t,properties:{...t.properties,enabledTools:l}}})})(e.name)})}),(0,o.jsx)(ey.A,{primary:e.name,secondary:e.description,primaryTypographyProps:{fontWeight:"medium"}})]},e.name))})]}):(0,o.jsx)(i.A,{color:"text.secondary",children:k((null==(m=I.find(e=>e.name===Y))?void 0:m.status)==="connected"?"flows.mcpNode.noTools":"flows.mcpNode.connectForTools")})]}),Y&&(0,o.jsxs)(a.default,{sx:{mt:4},children:[(0,o.jsx)(le.A,{roots:(null==(w=T.properties)?void 0:w.roots)||[],onChange:e=>$("roots",e)}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:1},children:k("flows.mcpNode.rootsHelp",{server:Y})})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:A,children:k("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{j&&T&&(C(j.id,T),A())},variant:"contained",color:"primary",children:k("flows.modal.saveChanges")})]})]})},lr=e=>{let{open:t,node:l,onClose:s,onSave:n}=e,{t:c}=(0,ed.s9)(),[p,f]=(0,r.useState)(null),[m,w]=(0,r.useState)("");return((0,r.useEffect)(()=>{if(l){var e;f({...l.data,properties:{...l.data.properties}}),w((null==(e=l.data.properties)?void 0:e.promptTemplate)||"")}},[l,t]),l&&p)?(0,o.jsxs)(h.A,{open:t,onClose:s,maxWidth:"xl",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"primary.main",width:"95vw",height:"90vh",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:c("flows.modal.properties",{name:p.label||c("flows.modal.startNode")})}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:s,"aria-label":c("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsx)(x.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)(i.A,{variant:"h6",gutterBottom:!0,children:c("flows.modal.promptTemplate")}),(0,o.jsx)(a.default,{sx:{flexGrow:1,display:"flex",flexDirection:"column",height:"calc(100% - 40px)"},children:(0,o.jsx)(tq.A,{value:m,onChange:e=>{w(e),f(t=>t?{...t,properties:{...t.properties,promptTemplate:e}}:null)},label:"",height:"100%"})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:s,children:c("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{if(l&&p){let e={...p,properties:{...p.properties,promptTemplate:m}};n(l.id,e),s()}},variant:"contained",color:"primary",children:c("flows.modal.saveChanges")})]})]}):null},ls=e=>{let{open:t,node:l,onClose:s,onSave:n}=e,{t:c}=(0,ed.s9)(),[p,f]=(0,r.useState)(null);return((0,r.useEffect)(()=>{l&&f({...l.data,properties:{...l.data.properties}})},[l,t]),l&&p)?(0,o.jsxs)(h.A,{open:t,onClose:s,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"success.main",width:"600px",height:"400px",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:c("flows.modal.properties",{name:p.label||c("flows.modal.finishNode")})}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:s,"aria-label":c("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsx)(x.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)(M.A,{elevation:0,sx:{p:4,textAlign:"center",backgroundColor:"rgba(76, 175, 80, 0.08)",borderRadius:2,width:"100%"},children:[(0,o.jsx)(i.A,{variant:"h6",color:"success.main",gutterBottom:!0,children:c("flows.modal.finishNode")}),(0,o.jsx)(i.A,{variant:"body1",color:"text.secondary",children:c("flows.modal.finishHelp")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:2,fontStyle:"italic"},children:c("flows.modal.finishFuture")})]})})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:s,children:c("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{l&&p&&(n(l.id,p),s())},variant:"contained",color:"primary",children:c("flows.modal.save")})]})]}):null},ln=e=>{let{open:t,edge:l,onClose:s,onSave:n}=e,{t:c}=(0,ed.s9)(),p={contains:c("flows.edgeModal.contains"),regex:c("flows.edgeModal.regex"),equals:c("flows.edgeModal.equals"),always:c("flows.edgeModal.always")},f={"last-assistant":c("flows.edgeModal.lastAgent"),"last-message":c("flows.edgeModal.lastMessage")},[m,w]=(0,r.useState)(!1),[y,j]=(0,r.useState)("contains"),[A,C]=(0,r.useState)(""),[S,k]=(0,r.useState)("last-assistant"),[T,M]=(0,r.useState)(!1),[I,N]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{var e,t;let o=null==l||null==(e=l.data)?void 0:e.condition;o?(w(!0),j(o.kind),C("string"==typeof o.value?o.value:""),k(null!=(t=o.target)?t:"last-assistant"),M(!!o.ignoreCase),N(!!o.negate)):(w(!1),j("contains"),C(""),k("last-assistant"),M(!1),N(!1))},[l,t]),!l)return null;let z="always"!==y,E=m&&"regex"===y&&A.length>0&&!(0,eM.wM)(A),W=m&&z&&0===A.length;return(0,o.jsxs)(h.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"primary.main",width:"520px",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:c("flows.edgeModal.title")}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:s,"aria-label":c("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(x.A,{sx:{display:"flex",flexDirection:"column",gap:2,p:3},children:[(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:c("flows.edgeModal.help")}),(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:m,onChange:e=>w(e.target.checked)}),label:c("flows.edgeModal.conditional")}),m&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(tr.A,{fullWidth:!0,size:"small",children:[(0,o.jsx)(ts.A,{id:"edge-condition-kind-label",children:c("flows.edgeModal.kind")}),(0,o.jsx)(tn.A,{labelId:"edge-condition-kind-label",label:c("flows.edgeModal.kind"),value:y,onChange:e=>j(e.target.value),children:eM.w4.map(e=>(0,o.jsx)(H.A,{value:e,children:p[e]},e))})]}),z&&(0,o.jsx)(v.A,{fullWidth:!0,size:"small",label:c("regex"===y?"flows.edgeModal.pattern":"flows.edgeModal.value"),value:A,onChange:e=>C(e.target.value),error:E||W,helperText:E?c("flows.edgeModal.invalidRegex"):W?c("flows.edgeModal.valueRequired"):" "}),(0,o.jsxs)(tr.A,{fullWidth:!0,size:"small",children:[(0,o.jsx)(ts.A,{id:"edge-condition-target-label",children:c("flows.edgeModal.testAgainst")}),(0,o.jsx)(tn.A,{labelId:"edge-condition-target-label",label:c("flows.edgeModal.testAgainst"),value:S,onChange:e=>k(e.target.value),children:eM.L2.map(e=>(0,o.jsx)(H.A,{value:e,children:f[e]},e))})]}),(0,o.jsxs)(a.default,{display:"flex",gap:2,flexWrap:"wrap",children:[z&&(0,o.jsx)(F.A,{control:(0,o.jsx)(tf.A,{checked:T,onChange:e=>M(e.target.checked)}),label:c("flows.edgeModal.ignoreCase")}),(0,o.jsx)(F.A,{control:(0,o.jsx)(tf.A,{checked:I,onChange:e=>N(e.target.checked)}),label:c("flows.edgeModal.negate")})]}),(0,o.jsx)(tk.A,{children:c("flows.edgeModal.runtimeSafety")})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:s,children:c("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{if(!m){n(l.id,void 0),s();return}let e={kind:y};z&&(e.value=A,T&&(e.ignoreCase=!0)),"last-assistant"!==S&&(e.target=S),I&&(e.negate=!0),n(l.id,e),s()},variant:"contained",color:"primary",disabled:E,children:c("flows.modal.save")})]})]})};var la=l(56900);let li=(0,y.A)((0,o.jsx)("path",{d:"m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"}),"ArrowForward");var ld=l(92241);let lc=(0,E.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/SubflowNodePropertiesModal"),lu=e=>{var t,l,s,n,c,p,f,w,y,j,A,C,S,k,T,M,I,N,z;let{open:E,node:W,onClose:L,onSave:B,onNavigateToFlow:V,flowId:O,authoringMode:U="advanced"}=e,{t:K,tp:G,formatList:X}=(0,ed.s9)(),[_,$]=(0,r.useState)(null),[q,Y]=(0,r.useState)([]),[Q,J]=(0,r.useState)(!1),[Z,ee]=(0,r.useState)(!1),[et,el]=(0,r.useState)(""),[eo,er]=(0,r.useState)(""),[es,en]=(0,r.useState)(""),[ea,ei]=(0,r.useState)("folder"),[ec,eu]=(0,r.useState)("");(0,r.useEffect)(()=>{if(W){let e=W.data.properties||{};$({...W.data,properties:{...e}}),el(Array.isArray(e.spawnBriefs)?e.spawnBriefs.filter(e=>"string"==typeof e).join("\n"):""),er(e.captureVariable||""),en(e.captureResource||"");let t=ez(e.captureKv||"");ei(t.scope),eu(t.key||"")}},[W,E]),(0,r.useEffect)(()=>{if(!E)return;let e=!1;return J(!0),D.g.loadFlows().then(t=>{e||Y(t||[])}).catch(t=>{lc.warn("Failed to load flows for subflow picker",t),e||Y([])}).finally(()=>{e||J(!1)}),()=>{e=!0}},[E]);let ep=(e,t)=>{$(l=>l?{...l,properties:{...l.properties,[e]:t}}:null)},ef=e=>{$(t=>{if(!t)return null;let l={...t.properties};return delete l[e],{...t,properties:l}})},em=q.filter(e=>e.id!==O),eh=(0,te.E)("flows",em);if(!W||!_)return null;let eg=(null==(t=_.properties)?void 0:t.subflowId)||"",ex=!!eg&&!q.some(e=>e.id===eg),ew=ex?"":(null==(l=q.find(e=>e.id===eg))?void 0:l.name)||"",ev=Array.isArray(null==(s=_.properties)?void 0:s.parallelSubflowIds)?_.properties.parallelSubflowIds.filter(e=>"string"==typeof e&&""!==e):[],eb=ev.map(e=>{var t;return(null==(t=q.find(t=>t.id===e))?void 0:t.name)||e}),ey="string"==typeof(null==(n=_.properties)?void 0:n.parallelSubflowIdsVar)?_.properties.parallelSubflowIdsVar.trim():"",ej=(null==(c=_.properties)?void 0:c.mapOverList)===!0,eA=!!(null==(p=_.properties)?void 0:p.allowCallerFanout),eC=et.split("\n").some(e=>""!==e.trim()),eS=eA||eC||ev.length>0||!!ey||ej,ek=ev.length>0,eT=eA||eC,eM=!ek&&!ey&&!eT,eI=!ej&&!ek,eN=(null==(f=_.properties)?void 0:f.promptTemplate)||"",eF=(null==(w=_.properties)?void 0:w.inputMode)||(eN.trim()?"isolated":"full-history");return(0,o.jsxs)(h.A,{open:E,onClose:L,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"warning.main",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:K("flows.modal.properties",{name:_.label||K("flows.subflow.title")})}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:L,"aria-label":K("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(x.A,{sx:{p:3},children:[(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:2},children:K("flows.subflow.intro")}),(0,o.jsx)(v.A,{fullWidth:!0,label:K("flows.subflow.nodeLabel"),value:_.label||"",onChange:e=>$({..._,label:e.target.value}),margin:"normal"}),(0,o.jsxs)(a.default,{sx:{mt:2},children:[(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mb:1},children:K("flows.subflow.flowToRun")}),(0,o.jsx)(d.A,{variant:"outlined",startIcon:(0,o.jsx)(la.A,{}),onClick:()=>ee(!0),sx:{textTransform:"none",maxWidth:"100%"},children:(0,o.jsx)(a.default,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ew||(ev.length>0?G("flows.subflow.parallel",ev.length):ey?K("flows.subflow.targetsVariable",{name:ey}):K("flows.subflow.choose"))})})]}),ex&&(0,o.jsx)(m.A,{severity:"warning",sx:{mt:1},children:K("flows.subflow.missing")}),ev.length>0&&(0,o.jsx)(m.A,{severity:"info",sx:{mt:1},children:K("flows.subflow.parallelInfo",{count:ev.length,names:X(eb)})}),(0,o.jsx)(e8.A,{open:Z,onClose:()=>ee(!1),title:K("flows.subflow.pickerTitle"),description:K("flows.subflow.pickerHelp"),isLoading:Q,skeleton:(0,o.jsx)(ld.o,{}),emptyMessage:K("flows.subflow.pickerEmpty"),searchable:!0,searchPlaceholder:K("flows.subflow.search"),searchTerm:eh.searchTerm,onSearchChange:eh.setSearchTerm,items:eh.items.map(e=>({key:e.id,content:(0,o.jsx)(ld.A,{flow:e,selected:e.id===eg,onSelect:e=>{ep("subflowId",e),ee(!1)},pickerMode:!0})})),groups:eh.groups?eh.groups.map(e=>({...e,items:e.items.map(e=>({key:e.id,content:(0,o.jsx)(ld.A,{flow:e,selected:e.id===eg,onSelect:e=>{ep("subflowId",e),ee(!1)},pickerMode:!0})}))})):null,collapsedKeys:eh.collapsedKeys,onToggleGroup:eh.toggleGroup}),"guided"===U&&(0,o.jsx)(v.A,{fullWidth:!0,label:K("flows.subflow.helperTask"),value:_.description||"",onChange:e=>$({..._,description:e.target.value}),margin:"normal",multiline:!0,minRows:2,helperText:K("flows.subflow.helperTaskHelp")}),"advanced"===U&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mt:3,mb:1},children:K("flows.subflow.inputTitle")}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":K("flows.subflow.inputAria"),sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[(0,o.jsx)(t5,{selected:"full-history"===eF,onClick:()=>ep("inputMode","full-history"),icon:(0,o.jsx)(tJ,{}),title:K("flows.subflow.fullHistory"),description:K("flows.subflow.fullHistoryHelp")}),(0,o.jsx)(t5,{selected:"latest-message"===eF,onClick:()=>ep("inputMode","latest-message"),icon:(0,o.jsx)(tZ,{}),title:K("flows.subflow.latest"),description:K("flows.subflow.latestHelp")}),(0,o.jsx)(t5,{selected:"isolated"===eF,onClick:()=>ep("inputMode","isolated"),icon:(0,o.jsx)(t0,{}),title:K("flows.subflow.isolated"),description:K("flows.subflow.isolatedHelp")})]}),"isolated"===eF&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(F.A,{sx:{mt:1,display:"block"},control:(0,o.jsx)(tf.A,{checked:(null==(y=_.properties)?void 0:y.allowCallerPrompt)!==!1,onChange:e=>ep("allowCallerPrompt",e.target.checked)}),label:K("flows.subflow.allowCallerPrompt")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:1,ml:4,mt:-.5},children:K("flows.subflow.allowCallerPromptHelp")}),(0,o.jsx)(v.A,{fullWidth:!0,label:K((null==(j=_.properties)?void 0:j.allowCallerPrompt)!==!1?"flows.subflow.defaultPrompt":"flows.subflow.isolatedPrompt"),value:eN,onChange:e=>ep("promptTemplate",e.target.value),margin:"normal",multiline:!0,rows:3,helperText:K((null==(A=_.properties)?void 0:A.allowCallerPrompt)!==!1?"flows.subflow.defaultPromptHelp":"flows.subflow.isolatedPromptHelp")})]}),(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mt:3,mb:1},children:K("flows.subflow.dynamicTitle")}),(0,o.jsx)(v.A,{fullWidth:!0,label:K("flows.subflow.parallelVariable"),value:ey,disabled:!eI,onChange:e=>{let t=e.target.value.trim();t?ep("parallelSubflowIdsVar",t):ef("parallelSubflowIdsVar")},margin:"normal",helperText:K(eI?"flows.subflow.parallelVariableHelp":ej?"flows.subflow.parallelDisabledMap":"flows.subflow.parallelDisabledStatic")}),(0,o.jsx)(F.A,{sx:{display:"block",mt:1},control:(0,o.jsx)(tf.A,{checked:ej,disabled:!eM&&!ej,onChange:e=>{e.target.checked?ep("mapOverList",!0):$(e=>{if(!e)return null;let{mapOverList:t,itemSplit:l,sequential:o,...r}=e.properties;return{...e,properties:r}})}}),label:K("flows.subflow.map")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:1,ml:4,mt:-.5},children:K(eM||ej?"flows.subflow.mapHelp":"flows.subflow.mapDisabled")}),ej&&(0,o.jsxs)(a.default,{sx:{display:"flex",gap:2,flexWrap:"wrap",alignItems:"center",ml:4,mt:1},children:[(0,o.jsxs)(v.A,{label:K("flows.subflow.split"),select:!0,size:"small",sx:{width:240},value:(null==(C=_.properties)?void 0:C.itemSplit)==="lines"?"lines":"json-array",onChange:e=>{"lines"===e.target.value?ep("itemSplit","lines"):ef("itemSplit")},helperText:K("flows.subflow.splitHelp"),children:[(0,o.jsx)(H.A,{value:"json-array",children:K("flows.subflow.jsonArray")}),(0,o.jsx)(H.A,{value:"lines",children:K("flows.subflow.lines")})]}),(0,o.jsx)(F.A,{control:(0,o.jsx)(tf.A,{checked:(null==(S=_.properties)?void 0:S.sequential)===!0,onChange:e=>{e.target.checked?ep("sequential",!0):ef("sequential")}}),label:K("flows.subflow.sequential")})]}),(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mt:3,mb:1},children:K("flows.subflow.workersTitle")}),(0,o.jsx)(F.A,{sx:{display:"block"},control:(0,o.jsx)(tf.A,{checked:eA,onChange:e=>ep("allowCallerFanout",e.target.checked)}),label:K("flows.subflow.allowSpawn")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mb:1,ml:4,mt:-.5},children:K("flows.subflow.spawnHelp")}),(0,o.jsx)(v.A,{fullWidth:!0,label:K("flows.subflow.briefs"),value:et,onChange:e=>el(e.target.value),margin:"normal",multiline:!0,minRows:2,helperText:K("flows.subflow.briefsHelp")}),eS&&(0,o.jsxs)(a.default,{sx:{display:"flex",gap:2,flexWrap:"wrap",mt:1},children:[(0,o.jsx)(v.A,{label:K("flows.subflow.maxCopies"),type:"number",size:"small",sx:{width:160},value:"number"==typeof(null==(k=_.properties)?void 0:k.concurrencyLimit)?_.properties.concurrencyLimit:"",onChange:e=>{let t=e.target.value;if(""===t)$(e=>{if(!e)return null;let{concurrencyLimit:t,...l}=e.properties;return{...e,properties:l}});else{let e=Math.max(1,Math.floor(Number(t)));Number.isNaN(e)||ep("concurrencyLimit",e)}},helperText:K("flows.subflow.defaultFour")}),(0,o.jsxs)(v.A,{label:K("flows.subflow.errorHandling"),select:!0,size:"small",sx:{width:220},value:(null==(T=_.properties)?void 0:T.errorStrategy)==="fail-fast"?"fail-fast":"collect-all",onChange:e=>ep("errorStrategy",e.target.value),helperText:K("flows.subflow.errorHelp"),children:[(0,o.jsx)(H.A,{value:"collect-all",children:K("flows.subflow.collect")}),(0,o.jsx)(H.A,{value:"fail-fast",children:K("flows.subflow.failFast")})]}),(0,o.jsx)(v.A,{label:K("flows.subflow.separator"),size:"small",sx:{width:260},multiline:!0,maxRows:2,value:"string"==typeof(null==(M=_.properties)?void 0:M.joinSeparator)?_.properties.joinSeparator:"",onChange:e=>{let t=e.target.value;""===t?$(e=>{if(!e)return null;let{joinSeparator:t,...l}=e.properties;return{...e,properties:l}}):ep("joinSeparator",t)},helperText:K("flows.subflow.blankLine")})]}),(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mt:3,mb:1},children:K("flows.subflow.outputTitle")}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":K("flows.subflow.outputAria"),sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[(0,o.jsx)(t5,{selected:"final-only"!==((null==(I=_.properties)?void 0:I.outputMode)||"steps"),onClick:()=>ep("outputMode","steps"),icon:(0,o.jsx)(t1.A,{}),title:K("flows.subflow.fullOutput"),description:K("flows.subflow.fullOutputHelp")}),(0,o.jsx)(t5,{selected:(null==(N=_.properties)?void 0:N.outputMode)==="final-only",onClick:()=>ep("outputMode","final-only"),icon:(0,o.jsx)(t2,{}),title:K("flows.subflow.condensed"),description:K("flows.subflow.condensedHelp")})]}),(0,o.jsx)(i.A,{variant:"subtitle2",sx:{mt:3,mb:1},children:K("flows.subflow.debugging")}),(0,o.jsx)(F.A,{sx:{display:"block"},control:(0,o.jsx)(P.A,{checked:(null==(z=_.properties)?void 0:z.saveConversation)!==!1,onChange:e=>ep("saveConversation",e.target.checked)}),label:K("flows.subflow.saveConversation")}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{ml:4,mt:-.5},children:K("flows.subflow.saveConversationHelp")}),(0,o.jsx)(R.A,{sx:{my:3}}),(0,o.jsx)(t9,{value:{captureVariable:eo,captureResource:es,captureKvScope:ea,captureKvKey:ec},onChange:e=>{void 0!==e.captureVariable&&er(e.captureVariable),void 0!==e.captureResource&&en(e.captureResource),void 0!==e.captureKvScope&&ei(e.captureKvScope),void 0!==e.captureKvKey&&eu(e.captureKvKey)}})]})]}),(0,o.jsxs)(b.A,{children:[eg&&!ex&&V&&(0,o.jsx)(d.A,{onClick:()=>V(eg),startIcon:(0,o.jsx)(li,{}),children:K("flows.subflow.openTarget")}),(0,o.jsx)(a.default,{sx:{flex:1}}),(0,o.jsx)(d.A,{onClick:L,children:K("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{if(W&&_){if("guided"===U){B(W.id,_),L();return}let e=et.split("\n").map(e=>e.trim()).filter(e=>""!==e),t={..._.properties};e.length>0?t.spawnBriefs=e:delete t.spawnBriefs;let l=eo.trim();l?t.captureVariable=l:delete t.captureVariable;let o=es.trim();o?t.captureResource=o:delete t.captureResource;let r=eH(ea,ec);r?t.captureKv=r:delete t.captureKv,B(W.id,{..._,properties:t}),L()}},variant:"contained",color:"primary",children:K("flows.modal.save")})]})]})};var lp=l(43861),lf=l(75656),lm=l(98286),lh=l(32683);let lg=(0,E.h)("frontend/components/Flow/FlowManager/FlowBuilder/Modals/ResourceNodePropertiesModal"),lx=e=>{var t,l,s,n,c;let{open:u,node:p,onClose:m,onSave:w,flowNodes:y}=e,{t:j}=(0,ed.s9)(),[A,C]=(0,r.useState)(null),{servers:S,isLoading:k}=(0,ty.v)(),[T,M]=(0,r.useState)([]),[I,P]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[E,W]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(p){C({...p.data,properties:{scope:"run",...p.data.properties}});let e=!!p.data.label&&"Resource Node"!==p.data.label.trim(),t=!!p.data.description&&p.data.description.trim().length>0;W(e||t)}},[p,u]);let L=(null==A||null==(t=A.properties)?void 0:t.scope)==="mcp"?"mcp":"run",D=(null==A||null==(l=A.properties)?void 0:l.boundServer)||"",V=(null==A||null==(s=A.properties)?void 0:s.uri)||"",O=(null==A||null==(n=A.properties)?void 0:n.runName)||"",U=(0,r.useMemo)(()=>{let e=(null!=y?y:[]).filter(e=>e.id!==(null==p?void 0:p.id)).map(e=>{try{var t,l;return JSON.stringify(null!=(l=null==(t=e.data)?void 0:t.properties)?l:{})}catch(e){return""}});return(0,tw.jX)(e)},[y,null==p?void 0:p.id]),K=(0,r.useCallback)((e,t)=>{C(l=>l?{...l,properties:{...l.properties,[e]:t}}:l)},[]);(0,r.useEffect)(()=>{if(!u||"mcp"!==L||!D){M([]),z(null);return}let e=!1;return P(!0),z(null),B.S.listServerResources(D).then(t=>{if(!e)if(t.error)z(t.error),M([]);else{var l,o;M([...(null!=(l=t.resources)?l:[]).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," (").concat(j("flows.resource.template"),")"):"(".concat(j("flows.resource.template"),")"),description:e.description}))])}}).catch(t=>{e||(lg.warn("Failed to browse resources of ".concat(D),t),z(t instanceof Error?t.message:String(t)))}).finally(()=>{e||P(!1)}),()=>{e=!0}},[u,L,D,j]);let G="run"===L&&!!O.trim()&&!eF(O.trim());return A?(0,o.jsxs)(h.A,{open:u,onClose:m,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(g.A,{children:j("flows.resource.title")}),(0,o.jsx)(x.A,{children:(0,o.jsxs)(a.default,{display:"flex",flexDirection:"column",gap:2,mt:1,children:[(0,o.jsxs)(tr.A,{children:[(0,o.jsxs)(lp.A,{row:!0,value:L,onChange:e=>K("scope","mcp"===e.target.value?"mcp":"run"),children:[(0,o.jsx)(F.A,{value:"run",control:(0,o.jsx)(lf.A,{}),label:j("flows.resource.temporary")}),(0,o.jsx)(F.A,{value:"mcp",control:(0,o.jsx)(lf.A,{}),label:j("flows.resource.mcp")})]}),(0,o.jsx)(tk.A,{children:"mcp"===L?j("flows.resource.mcpHelp"):j("flows.resource.temporaryHelp")})]}),"mcp"===L?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(tr.A,{fullWidth:!0,children:[(0,o.jsx)(ts.A,{id:"resource-server-label",children:j("flows.resource.server")}),(0,o.jsxs)(tn.A,{labelId:"resource-server-label",label:j("flows.resource.server"),value:D,onChange:e=>{K("boundServer",e.target.value)},children:[k&&(0,o.jsx)(H.A,{value:"",disabled:!0,children:j("flows.resource.loadingServers")}),S.map(e=>(0,o.jsx)(H.A,{value:e.name,children:e.name},e.name))]})]}),(0,o.jsx)(v.A,{label:j("flows.resource.uri"),value:V,onChange:e=>K("uri",e.target.value),fullWidth:!0,placeholder:j("flows.resource.uriPlaceholder"),helperText:j("flows.resource.uriHelp")}),I&&(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",gap:1,children:[(0,o.jsx)(N.default,{size:18}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:j("flows.resource.loading")})]}),R&&(0,o.jsx)(i.A,{variant:"body2",color:"warning.main",children:j("flows.resource.loadFailed",{error:R})}),!I&&!R&&D&&0===T.length&&(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:j("flows.resource.none")}),T.length>0&&(0,o.jsx)(ev.A,{dense:!0,sx:{maxHeight:240,overflow:"auto",border:1,borderColor:"divider",borderRadius:1},children:T.map(e=>(0,o.jsxs)(ej.A,{selected:e.uri===V,onClick:()=>K("uri",e.uri),children:[(0,o.jsx)(eb.A,{sx:{minWidth:34},children:(0,o.jsx)(el.A,{fontSize:"small",sx:{color:"#009688"}})}),(0,o.jsx)(ey.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)(lm.A,{freeSolo:!0,options:U,inputValue:O,onInputChange:(e,t)=>K("runName",t),renderInput:e=>(0,o.jsx)(v.A,{...e,label:j("flows.resource.temporaryName"),fullWidth:!0,error:G,helperText:G?j("flows.resource.invalidName"):U.length>0?j("flows.resource.nameSuggestions"):j("flows.resource.nameHelp")})}),O.trim()&&!G&&(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:j("flows.resource.runtimeUri",{name:O.trim()})})]}),(0,o.jsx)(lh.A,{component:"button",type:"button",underline:"hover",onClick:()=>W(e=>!e),sx:{alignSelf:"flex-start"},children:E?j("flows.resource.hideAdvanced"):j("flows.resource.showAdvanced")}),(0,o.jsx)(f.A,{in:E,unmountOnExit:!0,children:(0,o.jsxs)(a.default,{display:"flex",flexDirection:"column",gap:2,children:[(0,o.jsx)(v.A,{label:j("flows.resource.label"),value:A.label,onChange:e=>C({...A,label:e.target.value}),fullWidth:!0,helperText:j("flows.resource.labelHelp")}),(0,o.jsx)(v.A,{label:j("flows.resource.description"),value:null!=(c=A.description)?c:"",onChange:e=>C({...A,description:e.target.value}),fullWidth:!0,multiline:!0,minRows:2})]})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:m,children:j("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{var e;if(!p||!A)return;let t={...A.properties};"run"===L?(delete t.boundServer,delete t.uri,delete t.mimeType,t.scope="run",t.runName=O.trim()):(delete t.runName,t.scope="mcp");let l=(null!=(e=A.label)?e:"").trim()||("run"===L?O.trim()||j("flows.resource.temporary"):j("flows.resource.mcp"));w(p.id,{...A,label:l,properties:t})},variant:"contained",children:j("flows.modal.save")})]})]}):null},lw=e=>{var t,l,s,n;let{open:i,node:c,onClose:u,onSave:p}=e,{t:w}=(0,ed.s9)(),[y,j]=(0,r.useState)(null),[A,C]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(c){var e;j({...c.data,properties:{...c.data.properties}}),C(!!(null==(e=c.data.properties)?void 0:e.payloadTemplate))}},[c,i]);let S=(e,t)=>{j(l=>l?{...l,properties:{...l.properties,[e]:t}}:l)};if(!y)return null;let k=null!=(s=null==(t=y.properties)?void 0:t.topic)?s:"",T=null!=(n=null==(l=y.properties)?void 0:l.payloadTemplate)?n:"";return(0,o.jsxs)(h.A,{open:i,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(g.A,{children:w("flows.signal.title")}),(0,o.jsx)(x.A,{children:(0,o.jsxs)(a.default,{display:"flex",flexDirection:"column",gap:2,mt:1,children:[(0,o.jsx)(v.A,{label:w("flows.signal.name"),value:k,onChange:e=>S("topic",e.target.value),fullWidth:!0,required:!0,autoFocus:!0,error:!k.trim(),placeholder:w("flows.signal.placeholder"),helperText:k.trim()?w("flows.signal.nameHelp"):w("flows.signal.required")}),(0,o.jsx)(m.A,{severity:"info",children:w("flows.signal.behavior")}),(0,o.jsx)(lh.A,{component:"button",type:"button",underline:"hover",onClick:()=>C(e=>!e),sx:{alignSelf:"flex-start"},children:A?w("flows.signal.hideAdvanced"):w("flows.signal.showAdvanced")}),(0,o.jsx)(f.A,{in:A,unmountOnExit:!0,children:(0,o.jsx)(v.A,{label:w("flows.signal.payload"),value:T,onChange:e=>S("payloadTemplate",e.target.value),fullWidth:!0,multiline:!0,minRows:3,placeholder:w("flows.signal.payloadPlaceholder"),helperText:w("flows.signal.payloadHelp")})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:u,children:w("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:()=>{if(!c||!y)return;let e={...y.properties},t="string"==typeof e.topic?e.topic.trim():"";e.topic=t;let l=t||w("flows.signal.defaultName");p(c.id,{...y,label:l,properties:e})},variant:"contained",children:w("flows.modal.save")})]})]})};var lv=l(26922),lb=l(40520),ly=l(79299),lj=l(22590),lA=l(53657),lC=l(7107),lS=l(93632),lk=l(23143),lT=l(84765),lM=l(43673),lI=l(21997),lN=l(80811),lF=l(14368),lP=l(23833);let lR=(0,E.h)("frontend/components/FlowBuilder/Modals/TriggerNodePropertiesModal"),lz={type:"schedule",cron:"0 9 * * *"},lH={type:"file-watch",path:"",events:["add","change"]},lE={type:"mcp-poll",serverName:"",toolName:"",args:{},cron:"*/5 * * * *",evaluate:{mode:"on-change"}},lW={type:"url-watch",url:"",cron:"*/15 * * * *"},lL={type:"flow-event",source:{flowId:""},on:["completed"]},lD=e=>{let{open:t,node:l,flowId:s,onClose:n,onSave:c}=e,{t:p}=(0,ed.s9)(),[f,w]=(0,r.useState)(p("flows.trigger.defaultName")),[y,j]=(0,r.useState)(!0),[A,C]=(0,r.useState)(lz),[S,k]=(0,r.useState)("skip"),[T,M]=(0,r.useState)(""),[I,z]=(0,r.useState)(!1),[E,W]=(0,r.useState)(null),[L,B]=(0,r.useState)([]),[V,O]=(0,r.useState)(()=>crypto.randomUUID()),[U,K]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(!t||!l)return;W(null);let e=l.data.properties||{};w("string"==typeof e.name?e.name:p("flows.trigger.defaultName")),j(!1!==e.enabled),C(e.trigger||lz),k(e.overlapStrategy||"skip"),M("string"==typeof e.prompt?e.prompt:""),"string"==typeof e.executionId&&e.executionId?(O(e.executionId),K(!0)):(O(crypto.randomUUID()),K(!1))},[t,l,p]),(0,r.useEffect)(()=>{if(!t)return;let e=!1;return D.g.loadFlows().then(t=>{e||B(t||[])}).catch(()=>{e||B([])}),()=>{e=!0}},[t]);let G=(0,r.useCallback)(async()=>{if(!l)return;z(!0),W(null);let e={name:f.trim()||p("flows.trigger.defaultName"),flowId:s,prompt:T,overlapStrategy:S,trigger:A,enabled:y};try{let t;if(!(t=U?await lS.P.update(V,e):await lS.P.create({...e,id:V})).success){W(t.error||p("flows.trigger.saveFailed")),z(!1);return}K(!0);let o=f.trim()||p("flows.trigger.defaultNode");c(l.id,{...l.data,label:o,type:"trigger",properties:{executionId:V,name:f,enabled:y,trigger:A,overlapStrategy:S,prompt:T}})}catch(e){W(e instanceof Error?e.message:p("flows.trigger.saveFailed")),z(!1);return}z(!1),lR.info("TriggerNodePropertiesModal: Saved trigger node for executionId=".concat(V))},[l,V,f,y,A,S,T,s,U,c,p]);return l?(0,o.jsx)(o.Fragment,{children:(0,o.jsxs)(h.A,{open:t,onClose:n,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderTop:5,borderColor:"#E91E63",maxWidth:"95vw",maxHeight:"90vh"}},children:[(0,o.jsx)(g.A,{component:"div",children:(0,o.jsxs)(a.default,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[(0,o.jsx)(i.A,{variant:"h6",children:p("flows.trigger.title")}),(0,o.jsx)(u.A,{edge:"end",color:"inherit",onClick:n,"aria-label":p("flows.modal.close"),children:(0,o.jsx)(tx.A,{})})]})}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(x.A,{sx:{p:3},children:[(0,o.jsxs)(m.A,{severity:"info",sx:{mb:2},children:[p("flows.trigger.info"),!U&&(0,o.jsxs)(o.Fragment,{children:[" ",p("flows.trigger.createdOnSave")]})]}),(0,o.jsx)(v.A,{fullWidth:!0,label:p("flows.trigger.name"),value:f,onChange:e=>w(e.target.value),margin:"normal",placeholder:p("flows.trigger.namePlaceholder")}),(0,o.jsx)(F.A,{control:(0,o.jsx)(P.A,{checked:y,onChange:e=>j(e.target.checked),color:"primary"}),label:p("flows.trigger.enabled"),sx:{mt:1,mb:1}}),(0,o.jsx)(i.A,{variant:"subtitle1",sx:{mt:2,mb:1,fontWeight:600},children:p("flows.trigger.when")}),(0,o.jsxs)(a.default,{role:"radiogroup","aria-label":p("flows.trigger.typeAria"),sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[(0,o.jsx)(lk.A,{selected:"schedule"===A.type,onClick:()=>{"schedule"!==A.type&&C(lz)},icon:(0,o.jsx)(lv.A,{}),title:p("flows.trigger.schedule"),description:p("flows.trigger.scheduleHelp")}),(0,o.jsx)(lk.A,{selected:"webhook"===A.type,onClick:()=>{"webhook"!==A.type&&C({type:"webhook",token:crypto.randomUUID()})},icon:(0,o.jsx)(lb.A,{}),title:p("flows.trigger.webhook"),description:p("flows.trigger.webhookHelp")}),(0,o.jsx)(lk.A,{selected:"file-watch"===A.type,onClick:()=>{"file-watch"!==A.type&&C(lH)},icon:(0,o.jsx)(ly.A,{}),title:p("flows.trigger.files"),description:p("flows.trigger.filesHelp")}),(0,o.jsx)(lk.A,{selected:"mcp-poll"===A.type,onClick:()=>{"mcp-poll"!==A.type&&C(lE)},icon:(0,o.jsx)(lj.A,{}),title:p("flows.trigger.tool"),description:p("flows.trigger.toolHelp")}),(0,o.jsx)(lk.A,{selected:"url-watch"===A.type,onClick:()=>{"url-watch"!==A.type&&C(lW)},icon:(0,o.jsx)(lA.A,{}),title:p("flows.trigger.url"),description:p("flows.trigger.urlHelp")}),(0,o.jsx)(lk.A,{selected:"flow-event"===A.type,onClick:()=>{"flow-event"!==A.type&&C(lL)},icon:(0,o.jsx)(lC.A,{}),title:p("flows.trigger.flow"),description:p("flows.trigger.flowHelp")})]}),"schedule"===A.type&&(0,o.jsx)(lT.A,{cron:A.cron,timezone:A.timezone,onChange:e=>{let{cron:t,timezone:l}=e;return C({...A,cron:t,timezone:l})},catchUp:!0===A.catchUp,onCatchUpChange:e=>C({...A,catchUp:e})}),"webhook"===A.type&&(0,o.jsx)(lM.A,{config:A,onChange:C,executionId:V,saved:U}),"file-watch"===A.type&&(0,o.jsx)(lI.A,{config:A,onChange:C}),"mcp-poll"===A.type&&(0,o.jsx)(lN.A,{config:A,onChange:C}),"url-watch"===A.type&&(0,o.jsx)(lF.A,{config:A,onChange:C}),"flow-event"===A.type&&(0,o.jsx)(lP.A,{config:A,onChange:C,flows:L,currentExecutionId:V}),(0,o.jsxs)(tr.A,{fullWidth:!0,margin:"normal",children:[(0,o.jsx)(ts.A,{id:"overlap-strategy-label",children:p("flows.trigger.overlap")}),(0,o.jsxs)(tn.A,{labelId:"overlap-strategy-label",label:p("flows.trigger.overlap"),value:S,onChange:e=>k(e.target.value),children:[(0,o.jsx)(H.A,{value:"skip",children:p("flows.trigger.overlapSkip")}),(0,o.jsx)(H.A,{value:"queue",children:p("flows.trigger.overlapQueue")}),(0,o.jsx)(H.A,{value:"parallel",children:p("flows.trigger.overlapParallel")}),(0,o.jsx)(H.A,{value:"error",children:p("flows.trigger.overlapError")})]})]}),(0,o.jsx)(v.A,{fullWidth:!0,label:p("flows.trigger.prompt"),value:T,onChange:e=>M(e.target.value),margin:"normal",multiline:!0,minRows:2,placeholder:p("flows.trigger.promptPlaceholder"),helperText:p("flows.trigger.promptHelp")}),E&&(0,o.jsx)(m.A,{severity:"error",sx:{mt:2},children:E})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:n,disabled:I,children:p("flows.modal.cancel")}),(0,o.jsx)(d.A,{onClick:G,variant:"contained",disabled:I,startIcon:I?(0,o.jsx)(N.default,{size:16}):void 0,sx:{backgroundColor:"#E91E63","&:hover":{backgroundColor:"#C2185B"}},children:I?p("flows.builder.saving"):p("flows.modal.save")})]})]})}):null};var lB=l(50291),lV=l(76122);let lO=e=>{let{flow:t}=e,l=(0,n.A)(),s=(0,r.useMemo)(()=>(t.edges||[]).filter(e=>e.source&&e.target&&e.sourceHandle&&e.targetHandle),[t.edges]),a=(0,r.useMemo)(()=>({type:"custom",animated:!1,style:{stroke:l.palette.text.secondary,strokeWidth:2},markerEnd:{type:lV.TG.ArrowClosed,width:20,height:20,color:l.palette.text.secondary}}),[l.palette.text.secondary]);return(0,o.jsx)(W.Gc,{nodes:t.nodes||[],edges:s,nodeTypes:Y.c_,edgeTypes:Y.nd,defaultEdgeOptions:a,connectionLineType:lV.Do.SmoothStep,fitView:!0,minZoom:.1,maxZoom:2,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,deleteKeyCode:null,proOptions:{hideAttribution:!0},children:(0,o.jsx)(W.VS,{})})},lU=e=>(0,o.jsx)(W.Ln,{children:(0,o.jsx)(lO,{...e})}),lK=(0,E.h)("components/flow/FlowBuilder/Modals/FlowVersionHistoryDialog"),lG=e=>{let{open:t,flowId:l,onClose:s,onRestore:n}=e,{t:c,tp:u,formatDate:p}=(0,ed.s9)(),[f,m]=(0,r.useState)(!1),[w,v]=(0,r.useState)([]),[y,j]=(0,r.useState)(null),[A,C]=(0,r.useState)(!1),[S,k]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!t||!l)return;let e=!1;return m(!0),v([]),j(null),k(null),D.g.listFlowVersions(l).then(t=>{e||v(t)}).finally(()=>{e||m(!1)}),()=>{e=!0}},[t,l]);let T=(0,r.useCallback)(e=>{l&&(j(e),C(!0),k(null),D.g.getFlowVersion(l,e).then(t=>{t?k(t.flow):lK.warn("Version ".concat(e," could not be loaded (pruned?)"))}).finally(()=>C(!1)))},[l]),M=(0,r.useCallback)(()=>{S&&n(S)},[S,n]);return(0,o.jsxs)(h.A,{open:t,onClose:s,maxWidth:"lg",fullWidth:!0,children:[(0,o.jsx)(g.A,{children:c("flows.history.title")}),(0,o.jsx)(x.A,{dividers:!0,sx:{p:0},children:(0,o.jsxs)(a.default,{sx:{display:"flex",height:"65vh"},children:[(0,o.jsx)(a.default,{sx:{width:300,borderRight:1,borderColor:"divider",overflowY:"auto"},children:f?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,o.jsx)(N.default,{size:28})}):0===w.length?(0,o.jsx)(a.default,{sx:{p:3},children:(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:c("flows.history.empty")})}):(0,o.jsx)(ev.A,{disablePadding:!0,children:w.map((e,t)=>(0,o.jsxs)(r.Fragment,{children:[(0,o.jsx)(ej.A,{selected:e.versionId===y,onClick:()=>T(e.versionId),children:(0,o.jsx)(ey.A,{primary:(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(i.A,{variant:"body2",children:p(e.savedAt,{dateStyle:"medium",timeStyle:"short"})}),0===t&&(0,o.jsx)(I.A,{label:c("flows.history.mostRecent"),size:"small"})]}),secondary:"".concat(u("flows.history.node",e.nodeCount)," \xb7 ").concat(u("flows.history.edge",e.edgeCount))})}),(0,o.jsx)(R.A,{component:"li"})]},e.versionId))})}),(0,o.jsx)(a.default,{sx:{flex:1,position:"relative",minWidth:0},children:A?(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(N.default,{size:32})}):S?(0,o.jsx)(lU,{flow:S}):(0,o.jsx)(a.default,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",p:4},children:(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",align:"center",children:0===w.length?c("flows.history.afterSave"):c("flows.history.select")})})})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:s,children:c("common.close")}),(0,o.jsx)(d.A,{variant:"contained",color:"primary",startIcon:(0,o.jsx)(lB.A,{}),onClick:M,disabled:!S,children:c("flows.history.restore")})]})]})},lX=(e,t,l,o)=>e?e(t,o):l,l_=(e,t,l,o)=>e?e(t,l):o,l$=e=>{var t;return(null==(t=e.data)?void 0:t.bidirectional)===!0},lq=e=>!(0,U.BY)(e),lY=e=>{var t,l,o;return String(null!=(o=null!=(l=null==e?void 0:e.type)?l:null==e||null==(t=e.data)?void 0:t.type)?o:"")},lQ=e=>{var t,l,o;return String(null!=(o=null!=(l=null==e||null==(t=e.data)?void 0:t.label)?l:null==e?void 0:e.id)?o:"Unknown node")};function lJ(e,t,l,o,r,s){if(s){var n;return{...s,id:e,source:t,target:l,sourceHandle:o,targetHandle:r,data:{...null!=(n=s.data)?n:{},edgeType:"standard",bidirectional:!1},markerStart:void 0}}return{id:e,source:t,target:l,sourceHandle:o,targetHandle:r,type:"custom",animated:!0,data:{edgeType:"standard"}}}function lZ(e){let{open:t,processNodeId:l,parentFlow:s,existingFlowNames:n,onClose:c,onAccept:u}=e,{t:p,tp:f,formatList:y}=(0,ed.s9)(),[j,A]=(0,r.useState)(""),[C,S]=(0,r.useState)(null),[k,T]=(0,r.useState)(!1),[M,N]=(0,r.useState)(null);(0,r.useEffect)(()=>{var e;if(!t)return;let o=s.nodes.find(e=>e.id===l);A("".concat(String((null==o||null==(e=o.data)?void 0:e.label)||p("flows.convert.processDefault")).replace(/[^\w-]+/g,"_"),"_subflow")),S(null),T(!1),N(null)},[t,l,s.nodes,p]);let F=()=>{l&&(N(null),S(function(e){var t,l;let{parentFlow:o,processNodeId:r,subflowName:s,existingFlowNames:n=[],createId:a=L.A,t:i,tp:d}=e,c=[],u=[],p=null!=(t=o.nodes)?t:[],f=null!=(l=o.edges)?l:[],m=new Map(p.map(e=>[e.id,e])),h=m.get(r),g=s.trim();h&&"process"===lY(h)||c.push({code:"target-not-process",message:lX(i,"flows.convert.error.target","The selected node no longer exists or is not a Process node."),nodeId:r}),g?/^[\w-]+$/.test(g)?n.some(e=>e.toLowerCase()===g.toLowerCase())&&c.push({code:"duplicate-name",message:lX(i,"flows.convert.error.duplicateName",'A flow named "'.concat(g,'" already exists.'),{name:g})}):c.push({code:"invalid-name",message:lX(i,"flows.convert.error.invalidName","The subflow name may contain only letters, numbers, underscores, and dashes.")}):c.push({code:"name-required",message:lX(i,"flows.convert.error.nameRequired","Enter a name for the new subflow.")});let x=new Set;h&&x.add(h.id);let w=h?[h.id]:[];for(;w.length>0;){let e=w.shift();for(let t of f){if(!lq(t))continue;let l=[];for(let o of(t.source===e&&l.push(t.target),l$(t)&&t.target===e&&l.push(t.source),l)){if(x.has(o))continue;let e=m.get(o);if(!e){c.push({code:"missing-edge-node",message:lX(i,"flows.convert.error.missingEdgeNode",'Edge "'.concat(t.id,'" points to a missing node. Repair the flow before converting.'),{edge:t.id}),edgeId:t.id});continue}let l=lY(e);"signal"===l?(x.add(o),w.push(o)):("mcp"===l||"resource"===l)&&c.push({code:"attachment-on-control-edge",message:lX(i,"flows.convert.error.attachmentControl","".concat(lQ(e)," is connected as control flow. Reconnect it with its ").concat(l.toUpperCase()," attachment handles before converting."),{node:lQ(e),type:l.toUpperCase()}),nodeId:o,edgeId:t.id})}}}let v=!0;for(;v;)for(let e of(v=!1,f)){if(!(0,U.BY)(e))continue;let t=x.has(e.source);if(t===x.has(e.target))continue;let l=t?e.target:e.source,o=lY(m.get(l));"mcp"===o||"resource"===o?(x.add(l),v=!0):c.push({code:"unsupported-attachment",message:lX(i,"flows.convert.error.unsupportedAttachment",'Attachment edge "'.concat(e.id,'" does not connect to an MCP or Resource node.'),{edge:e.id}),edgeId:e.id,nodeId:l})}let b=f.filter(e=>x.has(e.source)&&x.has(e.target)),y=[],j=[],A=new Set;for(let e of f){let t=x.has(e.source);if(t===x.has(e.target))continue;if((0,U.BY)(e)){c.push({code:"shared-attachment",message:lX(i,"flows.convert.error.sharedAttachment",'Attachment "'.concat(e.id,'" is also used outside the converted region. Duplicate or disconnect that attachment first.'),{edge:e.id}),edgeId:e.id});continue}let l=t?e.source:e.target,o=t?e.target:e.source,r={edge:e,edgeId:e.id,insideNodeId:l,outsideNodeId:o,outsideLabel:lQ(m.get(o))};A.add(o),t?j.push(r):y.push(r),l$(e)&&((t?y:j).push(r),c.push({code:"bidirectional-boundary",message:lX(i,"flows.convert.error.bidirectional",'Boundary edge "'.concat(e.id,'" is bidirectional. Make it one-way before converting; internal bidirectional edges are preserved.'),{edge:e.id}),edgeId:e.id}))}let C=[...new Map(j.map(e=>[e.edgeId,e])).values()];C.length>1&&c.push({code:"multiple-outputs",message:l_(d,"flows.convert.error.outputs",C.length,"This region has ".concat(C.length," distinct parent exits. A Subflow supports one outgoing control path; join the branches before converting."))});let S=p.filter(e=>x.has(e.id)),k={includedNodes:S.map(e=>({id:e.id,label:lQ(e),type:lY(e)})),attachmentCount:S.filter(e=>"mcp"===lY(e)||"resource"===lY(e)).length,signalCount:S.filter(e=>"signal"===lY(e)).length,internalEdgeCount:b.length,inputCount:new Set(y.map(e=>e.edgeId)).size,outputCount:C.length,excludedBoundaryNodes:[...A].map(e=>{let t=m.get(e);return{id:e,label:lQ(t),type:lY(t)}}),rewires:[l_(d,"flows.convert.rewire.inputs",new Set(y.map(e=>e.edgeId)).size,"".concat(new Set(y.map(e=>e.edgeId)).size," parent input edge(s) will target the new Subflow node.")),1===C.length?lX(i,"flows.convert.rewire.output","The parent output to ".concat(C[0].outsideLabel," will leave the new Subflow node."),{node:C[0].outsideLabel}):lX(i,"flows.convert.rewire.noOutput","The new Subflow node will have no parent output."),lX(i,"flows.convert.rewire.childInput","The child Start node will provide an isolated input to the converted Process.")],warnings:u};0===C.length&&u.push(lX(i,"flows.convert.warning.noFollowup","No parent follow-up exists; the extracted fan-out will finish inside the child flow."));let T=y.map(e=>{let{edge:t,...l}=e;return l}),M=j.map(e=>{let{edge:t,...l}=e;return l}),I={valid:0===c.length,errors:c,selectedNodeIds:[...x],selectedEdgeIds:b.map(e=>e.id),boundaryInputs:T,boundaryOutputs:M,preview:k};if(c.length>0||!h)return I;let N=a(),F=a(),P=a(),R=()=>"conversion-".concat(a()),z=S.filter(e=>{let t=lY(e);return"process"===t||"signal"===t}),H=Math.min(...S.map(e=>e.position.y),h.position.y),E=Math.max(...S.map(e=>e.position.y),h.position.y),W={id:F,type:"start",position:{x:h.position.x,y:H-180},data:{label:"Start Node",type:"start",properties:{promptTemplate:""}}},D={id:P,type:"finish",position:{x:h.position.x,y:E+180},data:{label:"Finish Node",type:"finish",properties:{}}},B=[...b.map(e=>({...e,data:e.data?{...e.data}:e.data})),lJ(R(),F,h.id,"start-bottom","process-top")];if(1===C.length){let e=C[0];B.push(lJ(R(),e.insideNodeId,P,"signal"===lY(m.get(e.insideNodeId))?"signal-bottom":"process-bottom","finish-top",e.edge))}else{let e=z.filter(e=>!f.some(t=>!!lq(t)&&(!!(t.source===e.id&&x.has(t.target))||l$(t)&&t.target===e.id&&x.has(t.source)))),t=e.length>0?e:[h];for(let e of(t.length>1&&u.push(l_(d,"flows.convert.warning.branches",t.length,"".concat(t.length," internal branches will converge on the child Finish node."))),t))B.push(lJ(R(),e.id,P,"signal"===lY(e)?"signal-bottom":"process-bottom","finish-top"))}let V={id:N,name:g,description:"Converted from ".concat(lQ(h)," in ").concat(o.name),nodes:[W,...S,D],edges:B},O={...h,type:"subflow",selected:!1,data:{label:g,type:"subflow",description:"Runs the ".concat(g," subflow"),properties:{subflowId:N,inputMode:"isolated",outputMode:"final-only",allowCallerPrompt:!0}}},K=p.filter(e=>!x.has(e.id));K.push(O);let G=f.flatMap(e=>{let t=x.has(e.source),l=x.has(e.target);return t&&l?[]:t||l?(0,U.BY)(e)?[]:[{...e,source:t?O.id:e.source,target:l?O.id:e.target,sourceHandle:t?"subflow-bottom":e.sourceHandle,targetHandle:l?"subflow-top":e.targetHandle,data:e.data?{...e.data}:e.data}]:[e]}),X={...o,nodes:K,edges:G};return{...I,valid:!0,childFlow:V,parentFlow:X}}({parentFlow:s,processNodeId:l,subflowName:j,existingFlowNames:n,t:p,tp:f})))},P=async()=>{if((null==C?void 0:C.valid)&&C.childFlow&&C.parentFlow){T(!0),N(null);try{await u(C),c()}catch(e){N(e instanceof Error?e.message:p("flows.convert.saveFailed"))}finally{T(!1)}}};return(0,o.jsxs)(h.A,{open:t,onClose:k?void 0:c,fullWidth:!0,maxWidth:"md",children:[(0,o.jsx)(g.A,{children:C?p("flows.convert.previewTitle"):p("flows.convert.title")}),(0,o.jsx)(x.A,{children:C?(0,o.jsxs)(eQ.A,{spacing:2,children:[C.errors.length>0&&(0,o.jsxs)(m.A,{severity:"error",children:[(0,o.jsx)(i.A,{fontWeight:600,children:p("flows.convert.invalid")}),(0,o.jsx)(ev.A,{dense:!0,disablePadding:!0,children:C.errors.map((e,t)=>(0,o.jsx)(eA.Ay,{disableGutters:!0,children:(0,o.jsx)(ey.A,{primary:e.message})},"".concat(e.code,"-").concat(t)))})]}),M&&(0,o.jsx)(m.A,{severity:"error",children:M}),C.preview.warnings.map((e,t)=>(0,o.jsx)(m.A,{severity:"warning",children:e},"".concat(e,"-").concat(t))),(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"subtitle1",fontWeight:600,children:p("flows.convert.included",{name:j.trim()})}),(0,o.jsx)(eQ.A,{direction:"row",gap:1,flexWrap:"wrap",sx:{mt:1},children:C.preview.includedNodes.map(e=>(0,o.jsx)(I.A,{label:"".concat(e.label," \xb7 ").concat(e.type),size:"small"},e.id))}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:p("flows.convert.summary",{attachments:f("flows.convert.attachment",C.preview.attachmentCount),signals:f("flows.convert.signal",C.preview.signalCount),edges:f("flows.convert.edge",C.preview.internalEdgeCount)})})]}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(a.default,{children:[(0,o.jsx)(i.A,{variant:"subtitle1",fontWeight:600,children:p("flows.convert.boundary")}),(0,o.jsx)(ev.A,{dense:!0,children:C.preview.rewires.map(e=>(0,o.jsx)(eA.Ay,{disableGutters:!0,children:(0,o.jsx)(ey.A,{primary:e})},e))}),C.preview.excludedBoundaryNodes.length>0&&(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:p("flows.convert.keptParent",{nodes:y(C.preview.excludedBoundaryNodes.map(e=>"".concat(e.label," (").concat(e.type,")")))})})]}),(0,o.jsx)(m.A,{severity:"info",children:p("flows.convert.atomic")})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(w.A,{sx:{mb:2},children:p("flows.convert.help")}),(0,o.jsx)(v.A,{autoFocus:!0,fullWidth:!0,label:p("flows.convert.name"),value:j,onChange:e=>A(e.target.value),onKeyDown:e=>{"Enter"===e.key&&F()}})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:c,disabled:k,children:C?p("flows.convert.reject"):p("flows.modal.cancel")}),C?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.A,{onClick:()=>{S(null),N(null)},disabled:k,children:p("flows.convert.back")}),(0,o.jsx)(d.A,{variant:"contained",onClick:P,disabled:!C.valid||k,children:k?p("flows.convert.converting"):p("flows.convert.accept")})]}):(0,o.jsx)(d.A,{variant:"contained",onClick:F,children:p("flows.convert.preview")})]})]})}let l0=(0,y.A)((0,o.jsx)("path",{d:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3m3-10H5V5h10z"}),"Save"),l1=(0,y.A)((0,o.jsx)("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"}),"Undo"),l2=(0,y.A)((0,o.jsx)("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"}),"Redo"),l5=(0,y.A)((0,o.jsx)("path",{d:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"}),"MoreHoriz");var l4=l(51314),l3=l(40171);let l9=(0,y.A)((0,o.jsx)("path",{d:"m20 12-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8z"}),"ArrowDownward");var l6=l(90363);let l8=(0,E.h)("frontend/components/Flow/FlowManager/ImproveFlowDialog"),l7=e=>{let{open:t,onClose:l,currentFlow:s,onImproved:n,initialDescription:i}=e,{t:c}=(0,ed.s9)(),[u,p]=(0,r.useState)(""),[f,y]=(0,r.useState)([]),[j,A]=(0,r.useState)(""),[C,S]=(0,r.useState)(!1),[k,T]=(0,r.useState)(!1),[M,I]=(0,r.useState)(null);(0,r.useEffect)(()=>{t&&p(null!=i?i:"")},[t,i]),(0,r.useEffect)(()=>{if(!t)return;let e=!1;return V.N.loadModels().then(t=>{e||(y(t),A(e=>{var l,o;return t.some(t=>t.id===e)?e:null!=(o=null==(l=t[0])?void 0:l.id)?o:""}))}).catch(t=>{l8.warn("Failed to load models for the improve dialog",t),e||I(c("flows.generator.modelsFailed"))}),()=>{e=!0}},[t,c]);let P=(0,r.useCallback)(()=>{k||(I(null),l())},[k,l]),R=(0,r.useCallback)(async()=>{I(null),T(!0);try{let e={...s,nodes:[...s.nodes],edges:[...s.edges]},t=await D.g.improveFlow(e,u.trim(),j,{allowInstall:C});if(!t.success)return void I(t.error);l8.info("Flow improved",{flowId:t.flow.id,attempts:t.attempts,errors:t.validation.errorCount,warnings:t.validation.warningCount,installedServers:t.installedServers.length}),p(""),n({flow:t.flow,errorCount:t.validation.errorCount,warningCount:t.validation.warningCount,attempts:t.attempts,installedServers:t.installedServers})}finally{T(!1)}},[s,u,j,C,n]),z=!k&&u.trim().length>0&&!!j;return(0,o.jsxs)(h.A,{open:t,onClose:P,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(g.A,{children:c("flows.improve.title")}),(0,o.jsxs)(x.A,{children:[(0,o.jsx)(w.A,{sx:{mb:2},children:c("flows.improve.description")}),M&&(0,o.jsx)(m.A,{severity:"error",sx:{mb:2},onClose:()=>I(null),children:M}),(0,o.jsx)(v.A,{autoFocus:!0,fullWidth:!0,multiline:!0,minRows:4,label:c("flows.improve.change"),placeholder:c("flows.improve.placeholder"),value:u,onChange:e=>p(e.target.value),disabled:k,sx:{mb:2}}),(0,o.jsxs)(tr.A,{fullWidth:!0,disabled:k||0===f.length,children:[(0,o.jsx)(ts.A,{id:"improve-flow-model-label",children:c("flows.improve.model")}),(0,o.jsx)(tn.A,{labelId:"improve-flow-model-label",label:c("flows.improve.model"),value:j,onChange:e=>A(e.target.value),children:f.map(e=>{var t;return(0,o.jsx)(H.A,{value:e.id,children:(null==(t=e.displayName)?void 0:t.trim())||e.name},e.id)})})]}),(0,o.jsx)(F.A,{sx:{mt:2},control:(0,o.jsx)(tf.A,{checked:C,onChange:e=>S(e.target.checked),disabled:k}),label:c("flows.improve.allowInstall")}),C&&(0,o.jsx)(m.A,{severity:"warning",sx:{mt:1},children:c("flows.improve.installWarning")}),k&&(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1.5,mt:2},children:[(0,o.jsx)(N.default,{size:20}),(0,o.jsx)(w.A,{children:C?c("flows.improve.workingInstall"):c("flows.improve.working")})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:P,disabled:k,children:c("flows.improve.cancel")}),(0,o.jsx)(d.A,{onClick:R,variant:"contained",color:"primary",startIcon:(0,o.jsx)(l6.A,{}),disabled:!z,children:c("flows.improve.action")})]})]})};var oe=l(77890);let ot=e=>({source:"".concat(e,"-bottom"),target:"".concat(e,"-top")});function ol(e){var t,l,o;return null!=(o=null!=(l=null==(t=e.data)?void 0:t.type)?l:e.type)?o:"unknown"}let oo=(0,y.A)((0,o.jsx)("path",{d:"M13 2H4c-1.1 0-2 .9-2 2v9c0 .55.45 1 1 1s1-.45 1-1V4h9c.55 0 1-.45 1-1s-.45-1-1-1m4 4H8c-1.1 0-2 .9-2 2v9c0 .55.45 1 1 1s1-.45 1-1V8h9c.55 0 1-.45 1-1s-.45-1-1-1m3 4h-8c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2"}),"AutoAwesomeMotionRounded");var or=l(14418);let os=(0,y.A)((0,o.jsx)("path",{d:"M24 15c0-2.64-2.05-4.78-4.65-4.96C18.67 6.59 15.64 4 12 4c-1.33 0-2.57.36-3.65.97l1.49 1.49C10.51 6.17 11.23 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 .99-.48 1.85-1.21 2.4l1.41 1.41c1.09-.92 1.8-2.27 1.8-3.81M3.71 4.56c-.39.39-.39 1.02 0 1.41l2.06 2.06h-.42c-3.28.35-5.76 3.34-5.29 6.79C.46 17.84 3.19 20 6.22 20h11.51l1.29 1.29c.39.39 1.02.39 1.41 0s.39-1.02 0-1.41L5.12 4.56a.996.996 0 0 0-1.41 0M6 18c-2.21 0-4-1.79-4-4s1.79-4 4-4h1.73l8 8z"}),"CloudOffRounded");var on=l(97104);let oa=new Set(["maxTurns","excludeModelPrompt","excludeStartNodePrompt","excludeSystemPrompt","allowedTools","isolatedPrompt","allowCallerPrompt","enableTodoTool","captureVariable","captureResource","captureKv","resourceNodes"]),oi=new Set(["parallelSubflowIds","parallelSubflowIdsVar","mapOverList","itemSplit","sequential","allowCallerFanout","spawnBriefs","concurrencyLimit","joinSeparator","errorStrategy","allowCallerPrompt","saveConversation","captureVariable","captureResource","captureKv"]);function od(e){var t,l,o,r,s;if(void 0!==e.permissionRules)return!0;for(let s of null!=(t=e.nodes)?t:[]){if(!["start","process","finish","subflow","mcp"].includes(null!=(o=s.type)?o:""))return!0;let e=null!=(r=null==(l=s.data)?void 0:l.properties)?r:{},t=Object.keys(e);if("process"===s.type&&t.some(e=>oa.has(e))||"subflow"===s.type&&t.some(e=>oi.has(e))||"process"===s.type&&(void 0!==e.inputMode&&"full-history"!==e.inputMode||void 0!==e.outputMode&&"latest-message"!==e.outputMode)||"subflow"===s.type&&(void 0!==e.inputMode&&"full-history"!==e.inputMode||void 0!==e.outputMode&&"final-only"!==e.outputMode))return!0}return(null!=(s=e.edges)?s:[]).some(e=>{let t=e.data;return!!(null==t?void 0:t.condition)||(null==t?void 0:t.bidirectional)===!0||(null==t?void 0:t.edgeType)==="resource"})}var oc=l(56717);let ou=(0,E.h)("components/flow/FlowBuilder/index.tsx"),op=(0,T.Ay)(a.default)(e=>{let{theme:t}=e;return{display:"flex",height:"100%",minHeight:0,gap:"12px",padding:"12px",overflow:"hidden",backgroundColor:"transparent",[t.breakpoints.down("md")]:{flexDirection:"column",gap:"8px",padding:"8px",height:"auto",overflow:"visible"}}}),of=(0,T.Ay)(M.A)(e=>{let{theme:t}=e;return{padding:t.spacing(1.1),display:"flex",flexWrap:"wrap",gap:t.spacing(1),border:"1px solid ".concat(t.palette.divider),borderRadius:14,alignItems:"center",marginBottom:t.spacing(1),backgroundColor:"dark"===t.palette.mode?"rgba(17, 22, 41, 0.86)":"rgba(255, 255, 255, 0.9)",boxShadow:"dark"===t.palette.mode?"0 16px 45px rgba(0,0,0,.25)":"0 16px 45px rgba(49,45,99,.1)",backdropFilter:"blur(20px) saturate(140%)"}}),om=(0,T.Ay)(a.default)(e=>{let{theme:t}=e;return{flex:1,display:"flex",flexDirection:"column",position:"relative",overflow:"hidden",minWidth:0,minHeight:0,[t.breakpoints.down("md")]:{flex:"0 0 640px",height:640,overflow:"hidden"},[t.breakpoints.down("sm")]:{flexBasis:"auto",height:"auto",minHeight:0,overflow:"visible"}}}),oh=new Set(["start","process","finish","subflow","signal"]),og=(e,t)=>{var l,o;let r=e.filter(e=>oh.has(e.data.type)),s=new Set(r.map(e=>e.id)),n=t.filter(e=>{var t;return s.has(e.source)&&s.has(e.target)&&(null==(t=e.data)?void 0:t.edgeType)!=="resource"}),a=new Map,i=new Map;n.forEach(e=>{var t,l;a.set(e.source,[...null!=(t=a.get(e.source))?t:[],e]),i.set(e.target,[...null!=(l=i.get(e.target))?l:[],e])});let d=r.filter(e=>"start"===e.data.type),c=r.filter(e=>"finish"===e.data.type),u=1!==d.length||c.length>1;r.forEach(e=>{var t,l,o,r;let s=null!=(o=null==(t=i.get(e.id))?void 0:t.length)?o:0,n=null!=(r=null==(l=a.get(e.id))?void 0:l.length)?r:0;"start"===e.data.type?u||(u=0!==s||n>1):"finish"===e.data.type?u||(u=1!==s||0!==n):u||(u=1!==s||n>1)});let p=[],f=new Set,m=null==(l=d[0])?void 0:l.id;for(;m&&!f.has(m);){f.add(m),p.push(m);let e=null!=(o=a.get(m))?o:[];if(1!==e.length)break;m=e[0].target}return u||(u=0===r.length||f.size!==r.length),{unsafe:u,orderedNodeIds:p}},ox=r.forwardRef((e,t)=>{var l,s;let{initialFlow:n,onSave:c,onDelete:y,onConversionCommitted:j,allFlows:C,relatedDraftFlows:S=[],onRelatedDraftFlowsChange:k,isDraft:T=!1,onTry:M,onNavigateToFlow:E}=e;ou.debug("FlowBuilder rendered with initialFlow:",n);let{t:K,tp:Q,formatList:J}=(0,ed.s9)(),[Z,ee]=(0,r.useState)((null==n?void 0:n.nodes)||[]),[et,el]=(0,r.useState)(((null==n?void 0:n.edges)||[]).filter(e=>e.source&&e.target&&e.sourceHandle&&e.targetHandle)),[eo,er]=(0,r.useState)((null==n?void 0:n.name)||K("flows.page.untitled")),[es,en]=(0,r.useState)(null),[ea,ei]=(0,r.useState)((null==n?void 0:n.description)||""),ec=(0,r.useMemo)(()=>new Map(C.map(e=>[e.id,e.name])),[C]),eu=!!n&&(od({nodes:n.nodes||[],edges:n.edges||[],permissionRules:n.permissionRules})||og(n.nodes||[],n.edges||[]).unsafe),[ep,ef]=(0,on.Xk)("flujo-ui:flow-builder:mode","guided"),[em,eh]=(0,r.useState)(()=>eu?"advanced":ep),ex=(0,r.useCallback)(e=>{eh(e),ef(e)},[ef]),ew=(0,r.useRef)(0),ev=(0,r.useCallback)(e=>({...e,id:"permission-rule-".concat(++ew.current)}),[]),[eb,ey]=(0,r.useState)(()=>((null==n?void 0:n.permissionRules)||[]).map(ev)),[ej,eA]=(0,r.useState)((null==n?void 0:n.permissionRules)!==void 0),[eC,eS]=(0,r.useState)(!1),[ek,eT]=(0,r.useState)(null),eM=od({nodes:Z,edges:et,permissionRules:null==n?void 0:n.permissionRules}),eI=og(Z,et),eN=eM||eI.unsafe,[eF,eP]=(0,r.useState)(!1),[eR,ez]=(0,r.useState)("none"),[eH,eE]=(0,r.useState)(""),[eW,eL]=(0,r.useState)(null),[eD,eB]=(0,r.useState)(!1),[eV,eO]=(0,r.useState)(!1),[eU,eK]=(0,r.useState)(!1),[eG,eX]=(0,r.useState)(!1),[e_,e$]=(0,r.useState)(!1),[eq,eQ]=(0,r.useState)(!1),[eJ,eZ]=(0,r.useState)(!1),[e0,e1]=(0,r.useState)(!1),[e2,e5]=(0,r.useState)(null),[e4,e3]=(0,r.useState)(null),[e9,e6]=(0,r.useState)("edit"),[e8,e7]=(0,r.useState)(null),[te,tt]=(0,r.useState)(null),[tl,tr]=(0,r.useState)(!1),[ts,tn]=(0,r.useState)(null),[ta,ti]=(0,r.useState)(null),[tc,tu]=(0,r.useState)(""),[tf,tm]=(0,r.useState)(!1),[th,tx]=(0,r.useState)([]),[tw,tv]=(0,r.useState)(-1),[tb,ty]=(0,r.useState)(!1),[tj,tA]=(0,r.useState)(!1),[tC,tS]=(0,r.useState)(T?"unsaved":"saved"),[tk,tT]=(0,r.useState)([]),[tM,tI]=(0,r.useState)(null),[tN,tF]=(0,r.useState)(()=>{var e;return T&&!(null!=(e=null==n?void 0:n.nodes)?e:[]).some(e=>"process"===e.data.type)?"unasked":"manual"}),[tP,tR]=(0,r.useState)(!1),[tz,tH]=(0,r.useState)(null),tE=(0,r.useRef)(null!=(l=null==n?void 0:n.id)?l:(0,L.A)()),tW=(0,r.useRef)(0),tL=(0,r.useRef)(null),tD=(0,r.useRef)(Z.some(e=>"trigger"===e.type));tD.current=Z.some(e=>"trigger"===e.type);let tB=(0,r.useRef)(null),tV=(0,r.useRef)(!1),tO=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=!0;return V.N.loadModels().then(t=>{e&&(tT(t),0===t.length&&tF(e=>"unasked"===e?"manual":e))}).catch(t=>{ou.warn("Could not load connected AIs for Guided mode",t),e&&(tT([]),tF(e=>"unasked"===e?"manual":e))}),()=>{e=!1}},[]);let tU=(0,r.useCallback)(e=>e.filter(e=>e.source&&e.target&&e.sourceHandle&&e.targetHandle).map(e=>{var t;return(null==(t=e.data)?void 0:t.edgeType)==="resource"&&"resourceEdge"!==e.type?{...e,type:"resourceEdge"}:e}),[]);(0,r.useEffect)(()=>{if(tO.current=!0,tW.current=0,tA(!1),tS(T?"unsaved":"saved"),n){let e=n.nodes||[],t=T?e.map(e=>({...e,selected:!1})):e;ee(t);let l=tU(n.edges||[]);l.length!==n.edges.length&&console.warn("Filtered out ".concat(n.edges.length-l.length," invalid edges")),el(l),er(n.name),ei(n.description||""),ey((n.permissionRules||[]).map(ev)),eA(void 0!==n.permissionRules),eT(null),(od({nodes:e,edges:l,permissionRules:n.permissionRules})||og(e,l).unsafe)&&ex("advanced"),tx([{nodes:t,edges:l}]),tv(0)}else{let e=D.g.createStartNode();ee([e]),el([]),er(K("flows.page.untitled")),ei(""),ey([]),eA(!1),eT(null),tx([{nodes:[e],edges:[]}]),tv(0)}},[null==n?void 0:n.id,ev,ex]);let tK=e=>JSON.stringify(e,(e,t)=>"selected"===e||"dragging"===e||"measured"===e||"width"===e||"height"===e||"positionAbsolute"===e||"resizing"===e?void 0:t);(0,r.useEffect)(()=>{if(tb)return void ty(!1);if(tO.current){tO.current=!1;return}if(tV.current)return;let e={nodes:[...Z],edges:[...et]},t=th.slice(0,tw+1);(tw<0||tK(e)!==tK(t[tw]))&&(tx([...t,e]),tv(tw+1),tA(!0),tW.current+=1,tS("unsaved"))},[Z,et]),(0,r.useEffect)(()=>{let e=e=>{if(tj)return e.preventDefault(),e.returnValue="",""};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}},[tj]);let tG=e=>e.trim()?RegExp("^[\\p{L}\\p{N}_ -]+$","u").test(e.trim())?(!n||n&&n.name!==e)&&C.some(t=>t.id!==((null==n?void 0:n.id)||"")&&t.name.trim().toLowerCase()===e.trim().toLowerCase())?K("flows.page.nameDuplicate"):null:K("flows.page.nameCharacters"):K("flows.page.nameEmpty"),tX=(0,r.useCallback)(()=>{tA(!0),tW.current+=1,tS("unsaved")},[]),t_=(e,t)=>{ey(l=>l.map(l=>l.id===e?{...l,...t}:l)),eA(!0),eT(null),tX()},t$=(e,t)=>{let l=e+t;l<0||l>=eb.length||(ey(t=>{let o=[...t];return[o[e],o[l]]=[o[l],o[e]],o}),eA(!0),tX())},tq=(0,r.useCallback)(()=>ej?eb.map(e=>{let{id:t,...l}=e;return l}):void 0,[eb,ej]),tY=(0,r.useCallback)(()=>!eb.find(e=>!e.action.trim()||!e.resource.trim())||(eT(K("flows.builder.permissionInvalid")),eS(!0),!1),[eb,K]),tQ=(0,r.useCallback)(()=>{if(tL.current)return tL.current;let e=(async()=>{ou.debug('handleSave: Attempting to save flow "'.concat(eo,'"'));let e=tG(eo);if(e)return ou.warn("handleSave: Invalid flow name - ".concat(e)),en(e),"invalid-name";if(!tY())return"invalid-name";let t=[...Z];0===t.length&&(ou.debug("handleSave: No nodes found, adding a default Start node"),ee(t=[D.g.createStartNode()]));let l={id:(null==n?void 0:n.id)||(0,L.A)(),name:eo.trim(),description:ea,nodes:t,edges:et,folder:null==n?void 0:n.folder,favorite:null==n?void 0:n.favorite,permissionRules:tq()};ou.info('handleSave: Saving flow "'.concat(eo,'" with ').concat(t.length," nodes and ").concat(et.length," edges"));let o=tW.current;tS("saving");try{let e=await c(l);if(!1===e)return tS("error"),"failed";return tW.current===o?(tA(!1),tS("saved")):(tA(!0),tS("unsaved")),"saved"}catch(e){return ou.error("handleSave: Persistence failed",e),tS("error"),tA(!0),"failed"}})();return tL.current=e,e.finally(()=>{tL.current===e&&(tL.current=null)}),e},[eo,ea,Z,et,n,c,tq,tY]),tJ=(0,r.useCallback)(async()=>{M&&((T||tj||"saved"!==tC)&&"saved"!==await tQ()||M())},[M,T,tj,tC,tQ]),tZ=(0,r.useCallback)(e=>{tj?(tB.current=e,ez("unsaved"),eP(!0)):e()},[tj]);r.useImperativeHandle(t,()=>({requestNavigation:tZ}),[tZ]);let t0=(0,r.useCallback)(()=>{n?(ou.info('handleDelete: Deleting flow "'.concat(n.name,'" (ID: ').concat(n.id,")")),y(n.id)):ou.warn("handleDelete: Attempted to delete flow but no initialFlow is available")},[n,y]),t1=(0,r.useCallback)(e=>{ou.info("Applying AI-improved flow to the canvas",{flowId:e.flow.id,attempts:e.attempts,errors:e.errorCount,warnings:e.warningCount}),tr(!1),ee(e.flow.nodes||[]),el(tU(e.flow.edges||[])),er(e.flow.name),ei(e.flow.description||""),void 0!==e.flow.permissionRules&&(ey(e.flow.permissionRules.map(ev)),eA(!0)),en(tG(e.flow.name)),tA(!0);let t=e.installedServers.filter(e=>!e.alreadyExisted),l=t.length>0?K("flows.builder.installNote",{servers:J(t.map(e=>e.name))}):"";e.errorCount>0?tn({severity:"warning",message:K("flows.builder.revisedIssues",{errors:Q("flows.validation.error",e.errorCount),warnings:Q("flows.validation.warning",e.warningCount),installNote:l})}):e.warningCount>0?tn({severity:"info",message:K("flows.builder.revisedWarnings",{warnings:Q("flows.validation.warning",e.warningCount),installNote:l})}):tn({severity:"success",message:K("flows.builder.revisedClean",{installNote:l})})},[tU,J,K,Q]),t2=(0,r.useCallback)(e=>{var t,l,o,r;ou.info("Restoring an archived flow version to the canvas",{flowId:e.id,nodes:null!=(o=null==(t=e.nodes)?void 0:t.length)?o:0,edges:null!=(r=null==(l=e.edges)?void 0:l.length)?r:0}),tm(!1),ee(e.nodes||[]),el(tU(e.edges||[])),er(e.name),ei(e.description||""),ey((e.permissionRules||[]).map(ev)),eA(void 0!==e.permissionRules),en(tG(e.name)),tA(!0),tn({severity:"info",message:K("flows.builder.restored")})},[tU,K]),t5=(0,r.useCallback)(()=>{ti(null);let{flow:e,changes:t}=function(e){var t,l,o,r,s,n,a,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!=(l=null==e?void 0:e.edges)?l:[]],u={...e,nodes:d,edges:c},p=[],f=function(e,t){let l=e.filter(e=>"mcp"!==e.type&&"resource"!==e.type&&"string"==typeof e.id),o=new Map(l.map(e=>[e.id,e])),r=new Map,s=new Map,n=new Set;for(let e of l)r.set(e.id,0),s.set(e.id,0);let a=(e,t)=>{var l,o;n.add("".concat(e,"->").concat(t)),s.set(e,(null!=(l=s.get(e))?l:0)+1),r.set(t,(null!=(o=r.get(t))?o:0)+1)};for(let e of t)o.has(e.from)&&o.has(e.to)&&e.from!==e.to&&(a(e.from,e.to),e.bidirectional&&a(e.to,e.from));let i=[];for(let e of[...l].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],l=t.filter(e=>"subflow"===e.type);if(l.length>=2&&l.length===t.length){let t=i[e-1];if(1===t.length&&"process"===t[0].type)for(let e of l)c.set(e.id,t[0].id)}}let u=[],p=(e,t)=>{var l;if(e===t||n.has("".concat(e,"->").concat(t)))return!1;let r=o.get(e),a=o.get(t);return!!r&&!!a&&null===(0,U.vC)(r.type,ot(r.type).source,a.type,ot(a.type).target)&&("subflow"!==r.type||!((null!=(l=s.get(e))?l:0)>=1))},f=(e,t,l,o)=>{u.push({from:e,to:t,bidirectional:l,reason:o}),a(e,t),l&&a(t,e)},m=e=>{var t;let l=null!=(t=d.get(e.id))?t:0;for(let t=l-1;t>=0;t--){let l=i[t].filter(t=>t.id!==e.id&&"finish"!==t.type&&!c.has(t.id));if(0!==l.length){if(1===l.length)return l[0];return l.reduce((t,l)=>Math.abs(l.x-e.x)<Math.abs(t.x-e.x)?l:t)}}return null};for(let e of i)for(let t of e){var h;if("start"===t.type||(null!=(h=r.get(t.id))?h: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 l=m(t);l&&p(l.id,t.id)&&f(l.id,t.id,!1,"auto-connected")}let g=l.filter(e=>"start"===e.type),x=()=>l.filter(e=>{var t;return"start"!==e.type&&"finish"!==e.type&&!c.has(e.id)&&(null!=(t=r.get(e.id))?t:0)===0}),w=null;if(0===g.length){let e=x();if(e.length>0)w={targets:e.map(e=>e.id)};else{let e=l.filter(e=>"finish"!==e.type).sort((e,t)=>e.y-t.y)[0];e&&(w={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 v=l.filter(e=>"finish"===e.type),b=()=>l.filter(e=>{var t;return"start"!==e.type&&"finish"!==e.type&&!c.has(e.id)&&(null!=(t=s.get(e.id))?t:0)===0}),y=null;if(0===v.length){let e=b();e.length>0&&(y={sources:e.map(e=>e.id)})}else{let e=v[0];for(let t of b())p(t.id,e.id)&&f(t.id,e.id,!1,"auto-connected")}return{addEdges:u,addStart:w,addFinish:y}}(d.filter(e=>"mcp"!==ol(e)&&"resource"!==ol(e)).map(e=>{var t,l,o,r;return{id:e.id,type:ol(e),x:null!=(o=null==(t=e.position)?void 0:t.x)?o:0,y:null!=(r=null==(l=e.position)?void 0:l.y)?r:0}}),c.filter(e=>!function(e){var t;let l=null==(t=e.data)?void 0:t.edgeType;return"mcp"===l||"resource"===l}(e)).map(e=>{var t;return{from:e.source,to:e.target,bidirectional:(null==(t=e.data)?void 0:t.bidirectional)===!0}})),m=new Map(d.map(e=>[e.id,e])),h=(e,t,l)=>{let o=m.get(e),r=m.get(t);o&&r&&c.push((0,oe.pX)(o,r,l))};for(let e of f.addEdges)h(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=>m.get(e)).filter(Boolean).reduce((e,t)=>!e||t.position.y<e.position.y?t:e,null),t=(a={x:null!=(o=null==e?void 0:e.position.x)?o:250,y:(null!=(r=null==e?void 0:e.position.y)?r:150)-150},{id:(0,L.A)(),type:"start",position:a,data:{label:"Start Node",type:"start",properties:{promptTemplate:""}}});for(let e of(d.unshift(t),m.set(t.id,t),f.addStart.targets))h(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=>m.get(e)).filter(Boolean).reduce((e,t)=>!e||t.position.y>e.position.y?t:e,null),t=(i={x:null!=(s=null==e?void 0:e.position.x)?s:250,y:(null!=(n=null==e?void 0:e.position.y)?n:0)+150},{id:(0,L.A)(),type:"finish",position:i,data:{label:"Finish Node",type:"finish",properties:{}}});for(let e of(d.push(t),m.set(t.id,t),f.addFinish.sources))h(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==n?void 0:n.id)||"",name:eo,description:ea,nodes:Z,edges:et,folder:null==n?void 0:n.folder,favorite:null==n?void 0:n.favorite,permissionRules:tq()});if(0===t.length)return void tn({severity:"info",message:K("flows.builder.nothingRepair")});ou.info("Applying static auto-repair to the canvas (".concat(t.length," change(s))")),ee(e.nodes||[]),el(tU(e.edges||[])),tA(!0);let l=t.filter(e=>"auto-added-start"===e.code||"auto-added-finish"===e.code).length,o=t.length-l,r=[];t.some(e=>"auto-added-start"===e.code)&&r.push(K("flows.builder.repairAddedStart")),t.some(e=>"auto-added-finish"===e.code)&&r.push(K("flows.builder.repairAddedFinish")),o>0&&r.push(Q("flows.builder.repairConnected",o)),tn({severity:"success",message:K("flows.builder.repaired",{changes:J(r)})})},[n,eo,ea,Z,et,tU,tq,J,K,Q]),t4=(0,r.useCallback)(()=>{ti(null),tu(K("flows.builder.aiRepairPrompt")),tr(!0)},[K]),t3=(0,r.useCallback)(async(e,t)=>{ou.debug('handleCopyFlow: Copying flow "'.concat(e.name,'" to "').concat(t,'"'));let l={id:(0,L.A)(),name:t,description:e.description,nodes:e.nodes,edges:e.edges,folder:e.folder,favorite:e.favorite,permissionRules:e.permissionRules};return ou.info('handleCopyFlow: Created copy of flow "'.concat(e.name,'" with new name "').concat(t,'" (').concat(e.nodes.length," nodes, ").concat(e.edges.length," edges)")),await c(l)!==!1},[c]),t9=()=>{let e=tB.current;tB.current=null,e&&e()},t6=()=>{tB.current=null,eP(!1),ez("none"),eE(""),eL(null)},t8=async()=>{let e=tG(eH);if(e)return void eL(e);if("duplicate"===eR){if(n&&!await t3(n,eH))return}else if("rename"===eR){let e={id:(null==n?void 0:n.id)||(0,L.A)(),name:eH,description:ea,nodes:Z,edges:et,folder:null==n?void 0:n.folder,favorite:null==n?void 0:n.favorite,permissionRules:tq()};if(await c(e)===!1)return void tS("error");tA(!1),tS("saved"),t9()}t6()},le=async()=>{let e=await tQ();"saved"===e?(t9(),t6()):"invalid-name"===e&&t6()},lt=tw>0,ll=tw<th.length-1,la=(0,r.useCallback)(()=>{if(lt){ou.debug("handleUndo: Performing undo operation, moving from history index ".concat(tw," to ").concat(tw-1)),ty(!0);let e=tw-1,t=th[e];ee(t.nodes),el(t.edges),tv(e),tX(),ou.info("handleUndo: Restored flow state to previous version (".concat(t.nodes.length," nodes, ").concat(t.edges.length," edges)"))}},[th,tw,lt,tX]),li=(0,r.useCallback)(()=>{if(ll){ou.debug("handleRedo: Performing redo operation, moving from history index ".concat(tw," to ").concat(tw+1)),ty(!0);let e=tw+1,t=th[e];ee(t.nodes),el(t.edges),tv(e),tX(),ou.info("handleRedo: Restored flow state to next version (".concat(t.nodes.length," nodes, ").concat(t.edges.length," edges)"))}},[th,tw,ll,tX]);(0,r.useEffect)(()=>{let e=e=>{let t=e.target,l=(null==t?void 0:t.tagName)==="INPUT"||(null==t?void 0:t.tagName)==="TEXTAREA"||(null==t?void 0:t.isContentEditable),o=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();if(o&&"s"===r){e.preventDefault(),tQ();return}if(!l&&o&&"z"===r){e.preventDefault(),e.shiftKey?li():la();return}if(!l&&o&&"y"===r){e.preventDefault(),li();return}l||(!o||"k"!==r)&&(o||"a"!==r&&"/"!==e.key)||(e.preventDefault(),document.dispatchEvent(new CustomEvent("openFlowQuickAdd")))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[tQ,la,li]);let ld=(0,r.useCallback)(async e=>{if(!n||!te||!e.parentFlow||!e.childFlow)throw Error("Save the parent flow before converting a Process node.");let t=await D.g.convertProcessToSubflow(e.parentFlow,e.childFlow,te,n.updatedAt);if(!t.success)throw Error(t.error);let l={nodes:t.parentFlow.nodes,edges:t.parentFlow.edges},o=[...th.slice(0,tw+1),l];ty(!0),tx(o),tv(o.length-1),ee(t.parentFlow.nodes),el(t.parentFlow.edges),tA(!1),tS("saved"),tt(null),null==j||j(t.parentFlow,t.childFlow)},[n,te,th,tw,j]),lc=(0,r.useCallback)(e=>{for(let t of e)"position"===t.type&&(tV.current=!0===t.dragging);ee(t=>(0,W._0)(e,t))},[]),lp=(0,r.useCallback)((e,t)=>{el(l=>l.map(l=>{var o;if(l.id!==e)return l;let r={...null!=(o=l.data)?o:{}};return t?r.condition=t:delete r.condition,{...l,data:r}})),ou.info("handleSaveEdgeCondition: ".concat(t?"set":"cleared"," condition on edge ").concat(e))},[]),lf=(0,r.useCallback)(e=>{ou.debug("onEdgesChange: Processing ".concat(e.length," edge changes")),e.forEach(e=>{"remove"===e.type?ou.info("onEdgesChange: Edge ".concat(e.id," removed")):"select"===e.type&&ou.debug("onEdgesChange: Edge ".concat(e.id," selection changed to ").concat(e.selected))}),el(t=>(0,W.zW)(e,t))},[]),lm=(0,r.useRef)(null),[lh,lg]=(0,r.useState)(null),lv=(0,r.useCallback)(e=>{e5(e),setTimeout(()=>e5(t=>t===e?null:t),5e3)},[]),lb=(0,r.useCallback)((e,t,l)=>{if("trigger"===e&&tD.current)return lv(K("flows.builder.triggerExists")),null;"trigger"===e&&(tD.current=!0);let o=null!=l?l:D.g.createNode(e,t);return ee(e=>[...e.map(e=>({...e,selected:!1})),{...o,selected:!0}]),o},[lv,K]),ly=(0,r.useCallback)(e=>{var t,l;let o=null!=(l=Z.find(e=>e.selected))?l:1===Z.length&&"start"===Z[0].data.type?Z[0]:void 0,r=null==(t=lm.current)?void 0:t.getBoundingClientRect(),s=r&&lh?lh.screenToFlowPosition({x:r.left+r.width/2,y:r.top+r.height/2}):{x:250,y:180},n=o&&!["mcp","resource","trigger"].includes(e)?{x:o.position.x,y:o.position.y+180}:s;for(let e=0;e<12&&Z.some(e=>90>Math.abs(e.position.x-n.x)&&70>Math.abs(e.position.y-n.y));e+=1)n={x:n.x+36,y:n.y+36};let a=!!o&&["process","finish","subflow","signal"].includes(e),i=D.g.createNode(e,n);if(o&&a){let t={start:"start-bottom",process:"process-bottom",subflow:"subflow-bottom",signal:"signal-bottom"}[o.type];if(!t)return lv(K("flows.builder.selectedCannotLead",{node:o.data.label||K("flows.builder.selectedNode")})),null;let l={source:o.id,sourceHandle:t,target:i.id,targetHandle:(0,U.CW)(e,t)},r=[...Z,i];if(!(0,O.JL)(l,r,et))return lv(K("flows.builder.cannotAppend")),null;let s=lb(e,n,i);if(!s)return null;let a=(0,O.wn)(l,r);return el(e=>[...e,a]),s}return lb(e,n,i)},[Z,et,lh,lb,lv,K]),lj=(0,r.useCallback)(e=>{var t,l;if(eN)return void lv(K("flows.builder.customWiring"));let o=Z.find(e=>"start"===e.data.type),r=Z.find(e=>"finish"===e.data.type),s=null!=(t=[...eI.orderedNodeIds.map(e=>Z.find(t=>t.id===e)).filter(e=>!!e)].reverse().find(e=>["start","process","subflow","signal"].includes(e.data.type)))?t:o;if(!s)return void lv(K("flows.builder.missingStart"));let n={start:"start-bottom",process:"process-bottom",subflow:"subflow-bottom",signal:"signal-bottom"}[s.data.type];if(!n)return void lv(K("flows.builder.addExpert"));let a=D.g.createNode("process",{x:s.position.x,y:s.position.y+180});a.data={...a.data,label:K("flows.builder.aiTask"),properties:{...null!=(l=a.data.properties)?l:{},promptTemplate:e,inputMode:"full-history",outputMode:"latest-message",..."assisted"===tN&&tM?{boundModel:tM}:{}}};let i=null!=r?r:D.g.createNode("finish",{x:s.position.x,y:s.position.y+360}),d=[...Z.filter(e=>e.id!==i.id).map(e=>({...e,selected:!1})),{...a,selected:!0},{...i,position:{x:s.position.x,y:s.position.y+360},selected:!1}],c=et.filter(e=>!(r&&e.source===s.id&&e.target===r.id)),u={source:s.id,sourceHandle:n,target:a.id,targetHandle:(0,U.CW)("process",n)},p={source:a.id,sourceHandle:"process-bottom",target:i.id,targetHandle:(0,U.CW)("finish","process-bottom")};ee(d),el([...c,(0,O.wn)(u,d),(0,O.wn)(p,d)]),Z.some(e=>"process"===e.data.type)||ea.trim()||ei(e),"assisted"===tN&&tM?(tH(a.id),tR(!0)):tM||lv(K("flows.builder.connectModel"))},[Z,et,tN,tM,eI.orderedNodeIds,eN,lv,ea,K]),lA=null!=(s=Z.find(e=>e.selected))?s:null,lC=(0,r.useMemo)(()=>{if(!lA||"process"!==lA.data.type)return[];let e=new Set(et.filter(e=>{var t;return(null==(t=e.data)?void 0:t.edgeType)==="mcp"&&(e.source===lA.id||e.target===lA.id)}).map(e=>e.source===lA.id?e.target:e.source));return Z.flatMap(t=>{var l;if(!e.has(t.id)||"mcp"!==t.data.type)return[];let o=null==(l=t.data.properties)?void 0:l.boundServer;return"string"==typeof o&&o?[{nodeId:t.id,serverName:o}]:[]})},[et,Z,lA]),lS=Z.some(e=>["process","subflow"].includes(e.data.type)),lk=Z.filter(e=>"process"===e.data.type).every(e=>{var t;return"string"==typeof(null==(t=e.data.properties)?void 0:t.boundModel)&&!!e.data.properties.boundModel}),lT=!!eo.trim()&&!/^(?:NewFlow\d*|Untitled (?:assistant|agent)(?: \d+)?)$/i.test(eo.trim())&&!es,lM=lS&&lk&&lT&&!eN&&"saving"!==tC,lI=(0,r.useCallback)(e=>{ee(t=>t.map(t=>({...t,selected:t.id===e})))},[]),lN=(0,r.useMemo)(()=>{var e;return{...null!=n?n:{id:tE.current,name:eo,nodes:[],edges:[]},id:null!=(e=null==n?void 0:n.id)?e:tE.current,name:eo,...ea.trim()?{description:ea}:{},nodes:Z,edges:et,permissionRules:ej?eb.map(e=>{let{id:t,...l}=e;return l}):void 0}},[et,ea,eo,n,Z,eb,ej]),lF=(0,r.useMemo)(()=>{var e,t,l;if(tz){let e=Z.find(e=>e.id===tz),t=null==e||null==(l=e.data.properties)?void 0:l.boundModel;if("string"==typeof t&&t)return t}if(tM)return tM;let o=null==(t=Z.find(e=>{var t;return"process"===e.data.type&&"string"==typeof(null==(t=e.data.properties)?void 0:t.boundModel)&&!!e.data.properties.boundModel}))||null==(e=t.data.properties)?void 0:e.boundModel;return"string"==typeof o?o:null},[tz,tM,Z]),lP=(0,r.useCallback)(e=>{ee(e.nodes),el(e.edges),void 0!==e.description&&ei(e.description),tX()},[tX]),lR=(0,r.useCallback)(()=>{let e=Z.filter(e=>e.selected).map(e=>({type:"select",id:e.id,selected:!1}));e.length>0&&lc(e)},[Z,lc]),lz=(0,r.useCallback)(()=>{ou.debug("handleAutoAlign: auto-arranging flow nodes"),ee(e=>(function(e,t){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{direction:o="TB",rankSep:r=120,nodeSep:s=80,mcpOffsetX:n=350,mcpStackY:a=120}=l,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))!(G(e)||X(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 m=c.length;for(let e=0;e<m;e++){let e=!1;for(let[t,l]of p){let o=f.get(t)+1;for(let t of l)f.get(t)<o&&(f.set(t,o),e=!0)}if(!e)break}let h=new Map;for(let e of c){let t=f.get(e.id),l=h.get(t);l?l.push(e):h.set(t,[e])}let g=[...h.keys()].sort((e,t)=>e-t),x=new Map,w=0;for(let e of g){let t=h.get(e),l=0,n=0;for(let e of t){let{width:t,height:r}=function(e){var t,l,o,r;let s=e.measured;return{width:null!=(l=null!=(t=null==s?void 0:s.width)?t:e.width)?l:240,height:null!=(r=null!=(o=null==s?void 0:s.height)?o:e.height)?r:80}}(e);"TB"===o?(x.set(e.id,{x:l,y:w}),l+=t+s,n=Math.max(n,r)):(x.set(e.id,{x:w,y:l}),l+=r+s,n=Math.max(n,t))}w+=n+r}let v=(e,l,o)=>{let r=new Set(e.map(e=>e.id)),s=new Map;for(let e of t){let t,o;if(!l(e))continue;let n=r.has(e.source),a=r.has(e.target);n&&!a?(t=e.source,o=e.target):a&&!n&&(t=e.target,o=e.source),t&&o&&x.has(o)&&!s.has(t)&&s.set(t,o)}let n=new Map;for(let t of e){var i;let e=s.get(t.id);if(!e)continue;let l=x.get(e),r=null!=(i=n.get(e))?i:0;n.set(e,r+1),x.set(t.id,{x:l.x+o,y:l.y+r*a})}};return v(i,G,n),v(d,X,-n),e.map(e=>{let t=x.get(e.id);return t?{...e,position:t}:e})})(e,et)),requestAnimationFrame(()=>null==lh?void 0:lh.fitView({padding:.2}))},[et,lh]),lH=(0,r.useCallback)((e,t)=>{ou.debug("handleNodeUpdate: Updating node ".concat(e," properties")),ee(l=>{let o=l.map(l=>l.id===e?(ou.info("handleNodeUpdate: Node ".concat(e," properties updated")),{...l,data:t}):l);return function(e,t,l){let o=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e])),s=!1;for(let[e,t]of r){let l=o.get(e);if(l&&l.data.label!==t.data.label){s=!0;break}}return s?t.map(e=>{var t;let s=null==(t=e.data.properties)?void 0:t.promptTemplate;if("string"!=typeof s||!s)return e;let n=function(e,t){let l=[];for(let s of t){var o,r;!("string"==typeof(null==(o=s.data)?void 0:o.edgeType)&&(s.data.edgeType.includes("mcp")||"resource"===s.data.edgeType))&&(s.source===e?l.push(s.target):s.target===e&&(null==(r=s.data)?void 0:r.bidirectional)&&l.push(s.source))}return[...new Set(l)]}(e.id,l);if(0===n.length)return e;let a=[],i=[];for(let e of n){let t=r.get(e);if(!t)continue;let l=o.get(e)||t;a.push(q(l)),i.push(q(t))}if(0===i.length)return e;let d=(0,_.E9)(a),c=(0,_.E9)(i),u=new Map;for(let e of n){let t=d.get(e),l=c.get(e);t&&l&&t!==l&&u.set(t,l)}if(0===u.size)return e;let p=function(e,t){if(!e||0===t.size)return e;let l=(0,$.A$)(e);if(0===l.length)return e;let o="",r=0,s=!1;for(let n of l){o+=e.slice(r,n.index);let l="tool"===n.kind&&"handoff"===n.server?t.get(n.name):void 0;l?(o+=(0,$.X8)("tool","handoff",l),s=!0):o+=n.fullMatch,r=n.index+n.fullMatch.length}return o+=e.slice(r),s?o:e}(s,u);return p===s?e:{...e,data:{...e.data,properties:{...e.data.properties,promptTemplate:p}}}}):t}(l,o,et)})},[et]),lE=(0,r.useCallback)((e,t)=>{lH(e,t),eB(!1),e6("edit"),eO(!1),eK(!1),eX(!1),e$(!1),eQ(!1),eZ(!1),e1(!1),e3(null),ou.debug("handleNodeUpdate: Closed property modals")},[lH]),lW=(0,r.useCallback)(async(e,t)=>{var l;let o=Z.find(t=>t.id===e);if(!o)return void ou.warn("handleConnectMcpServer: process node ".concat(e," not found"));let r=[];try{let e=await B.S.listServerTools(t);!e.error&&Array.isArray(e.tools)&&(r=e.tools.map(e=>e.name))}catch(e){ou.warn("handleConnectMcpServer: could not load tools for ".concat(t),e)}let s=et.filter(t=>{var l;return(null==(l=t.data)?void 0:l.edgeType)==="mcp"&&(t.source===e||t.target===e)}).length,n=D.g.createNode("mcp",{x:o.position.x+350,y:o.position.y+120*s});n.data.label=t,n.data.properties={...null!=(l=n.data.properties)?l:{},boundServer:t,enabledTools:r};let a=(0,O.wn)({source:e,sourceHandle:"process-right-mcp",target:n.id,targetHandle:"mcp-left"},[...Z,n]);ee(e=>[...e,n]),el(e=>[...e,a]),ou.info('Connected MCP server "'.concat(t,'" to process node ').concat(e))},[Z,et]),lL=(0,r.useCallback)((e,t)=>{let l=l=>{var o;return(null==(o=l.data)?void 0:o.edgeType)==="mcp"&&(l.source===e&&l.target===t||l.source===t&&l.target===e)};if(!et.some(l))return;let o=et.filter(e=>!l(e)),r=o.some(e=>e.source===t||e.target===t);el(o),r||ee(e=>e.filter(e=>e.id!==t)),ou.info("Removed MCP node ".concat(t," from process node ").concat(e))},[et]),lB=(0,r.useCallback)(async()=>{let e=await B.S.loadServerConfigs();if(!Array.isArray(e))throw Error((null==e?void 0:e.error)||K("flows.inspector.mcpLoadError"));return Promise.all(e.map(async e=>{let t=await B.S.getServerStatus(e.name),l="string"==typeof t?t:t.status;return{...e,status:l}}))},[K]),lV=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"edit";ou.debug("Opening properties for node:",e),e3(e),"process"===e.data.type&&e6(t),"mcp"===e.data.type?eO(!0):"start"===e.data.type?eK(!0):"finish"===e.data.type?eX(!0):"subflow"===e.data.type?e$(!0):"resource"===e.data.type?eQ(!0):"signal"===e.data.type?eZ(!0):"trigger"===e.data.type?e1(!0):eB(!0)},[]),lO=(0,r.useCallback)(e=>{ou.debug("onDrop: Node dropped on canvas"),e.preventDefault();let t=e.dataTransfer.getData("application/reactflow");if(ou.debug("onDrop: Node type from data transfer: ".concat(t)),!t||!lh)return void ou.debug("onDrop: Missing required data - type: ".concat(!!t,", reactFlowInstance: ").concat(!!lh));let l=lh.screenToFlowPosition({x:e.clientX,y:e.clientY});ou.debug("onDrop: Calculated position: (".concat(l.x,", ").concat(l.y,")"));let o=lb(t,l);o&&(ou.info("onDrop: Created new ".concat(t," node with ID: ").concat(o.id)),ou.debug("onDrop: Selected new node ".concat(o.id," in the inspector")))},[lh,lb]),lU=(0,r.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect="move"},[]),lK=(0,r.useCallback)(e=>{ou.debug("onInit: ReactFlow instance initialized"),lg(e)},[]);return(0,o.jsxs)(op,{children:["advanced"===em&&(0,o.jsx)(eg,{authoringMode:em,onAddNode:ly}),(0,o.jsx)(oc.G.Provider,{value:ec,children:(0,o.jsx)(W.Ln,{children:(0,o.jsxs)(om,{children:[(0,o.jsxs)(of,{elevation:1,children:[(0,o.jsxs)(a.default,{sx:{minWidth:0,flex:"1 1 180px"},children:[(0,o.jsx)(i.A,{variant:"subtitle2",fontWeight:850,noWrap:!0,children:eo}),(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:"guided"===em?Q("flows.builder.step",Z.filter(e=>["process","subflow","signal"].includes(e.data.type)).length):"".concat(Q("flows.builder.node",Z.length)," \xb7 ").concat(Q("flows.builder.connection",et.length))})]}),(0,o.jsx)(I.A,{size:"small",variant:"outlined",color:"error"===tC?"error":"saved"===tC?"success":"default",icon:"saving"===tC?(0,o.jsx)(N.default,{size:14}):"error"===tC?(0,o.jsx)(os,{}):"saved"===tC?(0,o.jsx)(or.A,{}):void 0,label:"saving"===tC?K("flows.builder.saving"):"error"===tC?K("flows.builder.saveFailed"):"unsaved"===tC?T&&!tj?K("flows.builder.draft"):K("flows.builder.unsaved"):K("flows.builder.saved"),"aria-label":K("flows.builder.saveStatus",{status:"saving"===tC?K("flows.builder.saving"):"error"===tC?K("flows.builder.saveFailed"):tj?K("flows.builder.unsaved"):K("flows.builder.saved")})}),(0,o.jsx)(F.A,{sx:{m:0,whiteSpace:"nowrap"},control:(0,o.jsx)(P.A,{size:"small",checked:"advanced"===em,onChange:e=>ex(e.target.checked?"advanced":"guided"),inputProps:{"aria-label":K("flows.builder.expertView")}}),label:"advanced"===em?K("flows.builder.expert"):K("flows.builder.easy")}),"advanced"===em&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.A,{variant:"outlined",size:"small",startIcon:(0,o.jsx)(A.A,{}),onClick:()=>ly("process"),"aria-label":K("flows.builder.addNode"),title:K("flows.builder.addNodeHelp"),children:K("flows.builder.addNode")}),(0,o.jsx)(eY,{nodes:Z,edges:et}),(0,o.jsx)(p.A,{title:K("flows.builder.autoAlign"),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.autoAlign"),onClick:lz,disabled:Z.length<=1,color:"primary",size:"small",children:(0,o.jsx)(oo,{})})})}),(0,o.jsx)(R.A,{orientation:"vertical",flexItem:!0}),(0,o.jsx)(p.A,{title:"".concat(K("flows.builder.undo")," \xb7 Ctrl/⌘ Z"),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.undo"),onClick:la,disabled:!lt,color:"primary",size:"small",children:(0,o.jsx)(l1,{})})})}),(0,o.jsx)(p.A,{title:"".concat(K("flows.builder.redo")," \xb7 Ctrl/⌘ Shift Z"),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.redo"),onClick:li,disabled:!ll,color:"primary",size:"small",children:(0,o.jsx)(l2,{})})})})]}),(0,o.jsx)(d.A,{variant:"guided"===em?"outlined":"contained",color:"primary",onClick:()=>void tQ(),startIcon:"saving"===tC?(0,o.jsx)(N.default,{size:16,color:"inherit"}):(0,o.jsx)(l0,{}),disabled:!!es||"saving"===tC,"aria-label":K("flows.builder.saveFlow"),children:K("flows.builder.save")}),"guided"===em&&M&&(0,o.jsx)(d.A,{variant:"contained",color:"primary",onClick:()=>void tJ(),startIcon:(0,o.jsx)(td,{}),disabled:!lM,children:K("flows.builder.try")}),("advanced"===em||n&&!T)&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(p.A,{title:K("flows.builder.moreCommands"),children:(0,o.jsx)(u.A,{id:"more-actions-button","data-tour":"improve-flow","aria-label":K("flows.builder.moreActions"),"aria-controls":ta?"more-actions-menu":void 0,"aria-haspopup":"menu","aria-expanded":ta?"true":void 0,onClick:e=>ti(e.currentTarget),color:"primary",size:"small",children:(0,o.jsx)(l5,{})})}),(0,o.jsxs)(z.A,{id:"more-actions-menu",anchorEl:ta,open:!!ta,onClose:()=>ti(null),MenuListProps:{"aria-labelledby":"more-actions-button"},children:["advanced"===em&&(0,o.jsx)(H.A,{disabled:Z.length<=1,onClick:()=>{ti(null),lz()},children:K("flows.builder.autoAlign")}),"advanced"===em&&(0,o.jsx)(H.A,{disabled:0===Z.length,onClick:t5,children:K("flows.builder.repairAutomatic")}),"advanced"===em&&(0,o.jsx)(H.A,{disabled:0===Z.length,onClick:t4,children:K("flows.builder.repairAi")}),n&&!T&&(0,o.jsx)(R.A,{}),n&&!T&&"advanced"===em&&(0,o.jsx)(H.A,{onClick:()=>{ti(null),tu(""),tr(!0)},children:K("flows.builder.improveAi")}),n&&!T&&(0,o.jsx)(H.A,{onClick:()=>{ti(null),tm(!0)},children:"guided"===em?K("flows.builder.previousVersions"):K("flows.builder.history")}),n&&!T&&(0,o.jsx)(H.A,{onClick:()=>{ti(null),ez("duplicate"),eE(K("flows.page.copyName",{name:n.name})),eP(!0)},children:"guided"===em?K("flows.builder.duplicateAgent"):K("flows.builder.duplicateFlow")}),n&&!T&&(0,o.jsx)(H.A,{sx:{color:"error.main"},onClick:()=>{ti(null),t0()},children:"guided"===em?K("flows.builder.deleteAgent"):K("flows.builder.deleteFlow")})]})]})]}),(0,o.jsx)(f.A,{in:!!e2,unmountOnExit:!0,children:e2&&(0,o.jsx)(m.A,{severity:"warning",onClose:()=>e5(null),sx:{mb:1},children:e2})}),(0,o.jsx)(f.A,{in:!!ts,unmountOnExit:!0,children:ts&&(0,o.jsx)(m.A,{severity:ts.severity,onClose:()=>tn(null),sx:{mb:1},children:ts.message})}),"guided"===em?(0,o.jsx)(tp,{nodes:Z,orderedStepIds:eI.orderedNodeIds,selectedNodeId:null==lA?void 0:lA.id,flowName:eo,flowNameError:es,onFlowNameChange:e=>{er(e),en(tG(e)),tX()},onSelectNode:lI,onAddTask:lj,onTry:M?()=>{tJ()}:void 0,isSaving:"saving"===tC,hasAdvancedFeatures:eN,readyToTry:lM,needsAIConnection:!lk,onSwitchAdvanced:()=>ex("advanced"),models:tk,aiAssistance:tN,selectedModelId:tM,onChooseAssistance:e=>{tF(e),"manual"===e&&tI(null)},onModelChange:tI,onCheckPlausibility:()=>{tH(null),tR(!0)}}):(0,o.jsx)(a.default,{sx:{flex:1,width:"100%",minWidth:0,minHeight:0,position:"relative",display:"flex",flexDirection:"column"},children:(0,o.jsx)(Y.Ay,{ref:lm,nodes:Z,edges:et,onNodesChange:lc,onEdgesChange:lf,onDrop:lO,onDragOver:lU,onInit:lK,reactFlowWrapper:lm,onEditNode:lV,onCreateNode:lb,onConvertProcessToSubflow:n?e=>tt(e.id):void 0,onEditEdge:e=>e7(e)})})]})})}),("advanced"===em||lA)&&(0,o.jsx)(to,{selectedNode:lA,onClearSelection:lR,onCommitNode:lH,onOpenAdvanced:lV,flowName:eo,flowNameError:es,onFlowNameChange:e=>{er(e),en(tG(e)),tX()},flowDescription:ea,onFlowDescriptionChange:e=>{ei(e),tX()},authoringMode:em,beginnerMode:"guided"===em,onAuthoringModeChange:ex,permissionRuleCount:eb.length,onOpenPermissionRules:()=>eS(!0),onSuggestTools:e=>{tH(e.id),tR(!0)},onCheckPlausibility:()=>{tH(null),tR(!0)},connectedMcpServers:lC,onConnectMcpServer:lW,onRemoveMcpServer:lL,loadMcpServers:lB}),(0,o.jsx)(t7,{open:eD,node:e4,onClose:()=>{eB(!1),e6("edit")},onSave:lE,mode:e9,flowEdges:et,flowNodes:Z,flowId:null==n?void 0:n.id,onConnectMcpServer:e=>{e4&&lW(e4.id,e)},authoringMode:em}),(0,o.jsx)(tg,{open:tP,flow:lN,relatedFlows:S,nodeId:tz,modelId:lF,models:tk,onApply:lP,onApplyRelatedFlows:k,onClose:()=>tR(!1)}),(0,o.jsx)(lo,{open:eV,node:e4,onClose:()=>eO(!1),onSave:lE,authoringMode:em}),(0,o.jsx)(lr,{open:eU,node:e4,onClose:()=>eK(!1),onSave:lE}),(0,o.jsx)(ls,{open:eG,node:e4,onClose:()=>eX(!1),onSave:lE}),(0,o.jsx)(lu,{open:e_,node:e4,onClose:()=>e$(!1),onSave:lE,onNavigateToFlow:E?e=>{e$(!1),tZ(()=>E(e))}:void 0,flowId:null==n?void 0:n.id,authoringMode:em}),(0,o.jsx)(lx,{open:eq,node:e4,onClose:()=>eQ(!1),onSave:lE,flowNodes:Z}),(0,o.jsx)(lw,{open:eJ,node:e4,onClose:()=>eZ(!1),onSave:lE}),(0,o.jsx)(lD,{open:e0,node:e4,flowId:(null==n?void 0:n.id)||"",onClose:()=>{e1(!1),e3(null)},onSave:lE}),(0,o.jsx)(ln,{open:!!e8,edge:e8,onClose:()=>e7(null),onSave:lp}),(0,o.jsx)(lZ,{open:!!te,processNodeId:te,parentFlow:{id:(null==n?void 0:n.id)||"",name:eo,description:ea,folder:null==n?void 0:n.folder,favorite:null==n?void 0:n.favorite,permissionRules:tq(),createdAt:null==n?void 0:n.createdAt,updatedAt:null==n?void 0:n.updatedAt,nodes:Z,edges:et},existingFlowNames:C.map(e=>e.name),onClose:()=>tt(null),onAccept:ld}),(0,o.jsx)(lG,{open:tf,flowId:null==n?void 0:n.id,onClose:()=>tm(!1),onRestore:t2}),(0,o.jsx)(l7,{open:tl,onClose:()=>tr(!1),currentFlow:{id:(null==n?void 0:n.id)||"",name:eo,description:ea,permissionRules:tq(),nodes:Z,edges:et},onImproved:t1,initialDescription:tc}),(0,o.jsxs)(h.A,{open:eC,onClose:()=>eS(!1),fullWidth:!0,maxWidth:"md","aria-labelledby":"permission-rules-dialog-title",children:[(0,o.jsx)(g.A,{id:"permission-rules-dialog-title",children:K("flows.builder.permissionsTitle")}),(0,o.jsxs)(x.A,{children:[(0,o.jsx)(w.A,{sx:{mb:2},children:K("flows.builder.permissionsHelp")}),ek&&(0,o.jsx)(m.A,{severity:"error",sx:{mb:2},children:ek}),0===eb.length?(0,o.jsx)(i.A,{color:"text.secondary",sx:{mb:2},children:K("flows.builder.noPermissions")}):eb.map((e,t)=>(0,o.jsxs)(a.default,{sx:{display:"flex",alignItems:"center",gap:1,mb:1},children:[(0,o.jsxs)(i.A,{"aria-label":K("flows.builder.rule",{number:t+1}),sx:{minWidth:24},children:[t+1,"."]}),(0,o.jsx)(v.A,{label:K("flows.builder.action"),size:"small",value:e.action,onChange:t=>t_(e.id,{action:t.target.value}),inputProps:{"aria-label":"".concat(K("flows.builder.rule",{number:t+1}),": ").concat(K("flows.builder.action"))},sx:{flex:1}}),(0,o.jsx)(v.A,{label:K("flows.builder.resource"),size:"small",value:e.resource,onChange:t=>t_(e.id,{resource:t.target.value}),inputProps:{"aria-label":"".concat(K("flows.builder.rule",{number:t+1}),": ").concat(K("flows.builder.resource"))},sx:{flex:1}}),(0,o.jsxs)(v.A,{select:!0,label:K("flows.builder.effect"),size:"small",value:e.effect,onChange:t=>t_(e.id,{effect:t.target.value}),inputProps:{"aria-label":"".concat(K("flows.builder.rule",{number:t+1}),": ").concat(K("flows.builder.effect"))},sx:{minWidth:100},children:[(0,o.jsx)(H.A,{value:"allow",children:K("flows.builder.allow")}),(0,o.jsx)(H.A,{value:"deny",children:K("flows.builder.deny")}),(0,o.jsx)(H.A,{value:"ask",children:K("flows.builder.ask")})]}),(0,o.jsx)(p.A,{title:K("flows.builder.moveRuleUp",{number:t+1}),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.moveRuleUp",{number:t+1}),onClick:()=>t$(t,-1),disabled:0===t,children:(0,o.jsx)(l3.A,{})})})}),(0,o.jsx)(p.A,{title:K("flows.builder.moveRuleDown",{number:t+1}),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.moveRuleDown",{number:t+1}),onClick:()=>t$(t,1),disabled:t===eb.length-1,children:(0,o.jsx)(l9,{})})})}),(0,o.jsx)(p.A,{title:K("flows.builder.deleteRule",{number:t+1}),children:(0,o.jsx)(u.A,{"aria-label":K("flows.builder.deleteRule",{number:t+1}),onClick:()=>{var t;return t=e.id,void(ey(e=>e.filter(e=>e.id!==t)),eA(!0),eT(null),tX())},children:(0,o.jsx)(l4.A,{})})})]},e.id)),(0,o.jsx)(d.A,{startIcon:(0,o.jsx)(A.A,{}),onClick:()=>{ey(e=>[...e,ev({action:"",resource:"",effect:"ask"})]),eA(!0),eT(null),tX()},children:K("flows.builder.addRule")})]}),(0,o.jsx)(b.A,{children:(0,o.jsx)(d.A,{onClick:()=>eS(!1),children:K("flows.builder.done")})})]}),(0,o.jsxs)(h.A,{open:eF,onClose:t6,children:[(0,o.jsx)(g.A,{children:"duplicate"===eR?"guided"===em?K("flows.builder.copyAgent"):K("flows.builder.copyFlow"):"rename"===eR?"guided"===em?K("flows.builder.renameAgent"):K("flows.builder.renameFlow"):K("flows.builder.unsavedChanges")}),(0,o.jsx)(x.A,{children:"unsaved"===eR?(0,o.jsx)(w.A,{children:K("flows.builder.unsavedQuestion")}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(w.A,{children:"duplicate"===eR?K("flows.builder.copyPrompt"):K("flows.builder.renameQuestion")}),(0,o.jsx)(v.A,{autoFocus:!0,margin:"dense",label:"guided"===em?K("flows.builder.agentName"):K("flows.builder.flowName"),type:"text",fullWidth:!0,value:eH,onChange:e=>{let t=e.target.value;eE(t),eL(tG(t))},error:!!eW,helperText:eW,sx:{mt:2}})]})}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:t6,children:K("flows.builder.cancel")}),"unsaved"===eR&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.A,{onClick:()=>{tA(!1),t9(),t6()},color:"error",children:K("flows.builder.discard")}),(0,o.jsx)(d.A,{onClick:le,variant:"contained",color:"primary",children:K("flows.builder.saveChanges")})]}),"rename"===eR&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.A,{onClick:()=>{let e=tG(eH);if(e)return void eL(e);n&&t3(n,eH),t6()},children:K("flows.builder.copy")}),(0,o.jsx)(d.A,{onClick:t8,variant:"contained",color:"primary",disabled:!!eW,children:K("flows.builder.rename")})]}),"duplicate"===eR&&(0,o.jsx)(d.A,{onClick:t8,variant:"contained",color:"primary",disabled:!!eW,children:K("flows.builder.copy")})]})]})]})});ox.displayName="FlowBuilder";var ow=l(10915),ov=l(76750),ob=l(49479),oy=l(9164);let oj=(0,E.h)("frontend/components/Flow/FlowManager/GenerateFlowDialog");function oA(e,t){return{id:(0,L.A)(),role:e,content:t,timestamp:Date.now()}}function oC(e){if("string"!=typeof e)return e;try{return JSON.parse(e)}catch(t){return e}}function oS(e,t,l,o){let r=l(t?"flows.generator.updated":"flows.generator.readyNamed",{name:e.flow.name}),s=Math.max(0,e.flows.length-1),n=s?o("flows.generator.helper",s):"",a=e.errorCount+e.warningCount;return[r,n,a?o("flows.generator.review",a):l("flows.generator.readyReview")].filter(Boolean).join(" ")}let ok=e=>{var t;let{open:l,onClose:s,onGenerated:n}=e,{settings:c,settingsHydrated:f}=(0,oy.useStorage)(),{t:w,tp:v}=(0,ed.s9)(),y=f&&(null==c||null==(t=c.experimental)?void 0:t.enabled)===!0&&!0===c.experimental.flowBasedGenerator,[j,A]=(0,r.useState)([]),[S,k]=(0,r.useState)(""),[T,M]=(0,r.useState)(null),[N,P]=(0,r.useState)([]),[R,z]=(0,r.useState)(null),[E,W]=(0,r.useState)(!1),[B,O]=(0,r.useState)(!1),[U,K]=(0,r.useState)(!1),[G,X]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!l)return;let e=!1;return V.N.loadModels().then(t=>{e||(A(t),k(e=>{var l,o;return t.some(t=>t.id===e)?e:null!=(o=null==(l=t[0])?void 0:l.id)?o:""}))}).catch(t=>{oj.warn("Failed to load generator models",t),e||X(w("flows.generator.modelsFailed"))}),()=>{e=!0}},[l,w]),(0,r.useEffect)(()=>{l&&(M(null),P([]),z(null),W(!1),X(null))},[y,l]);let _=(0,r.useMemo)(()=>N.filter(e=>("user"===e.role||"assistant"===e.role)&&"string"==typeof e.content&&e.content.trim()).map((e,t)=>({id:"string"==typeof e.id?e.id:"flow-generator-".concat(t),role:e.role,content:e.content,timestamp:"number"==typeof e.timestamp?e.timestamp:Date.now()+t,processNodeId:e.processNodeId})),[N]),$=(0,r.useCallback)(async()=>{if(T)return T;let e=(0,L.A)(),{flow:t}=await ob.O.synthesizeFlowGenerator({conversationId:e,modelId:S,allowInstall:E}),l=Date.now();return await ob.O.createConversation({id:e,title:w("flows.generator.conversationTitle"),flowId:t.id,flowSnapshot:t,createdAt:l,updatedAt:l}),M(e),e},[E,T,S,w]),q=(0,r.useCallback)(async e=>{let t=e.trim();if(!t||B||!S)return;let l=[...N,oA("user",t)];P(l),X(null),O(!0);try{if(y){var o,r,s,n;let e=await $(),t=await ob.O.completeFlowGeneratorTurn({conversationId:e,messages:l}),a=Array.isArray(null==t?void 0:t.messages)?t.messages:l;P(a);let i=function(e){let t=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(l>6)return null;let o=oC(e);if(!o||"object"!=typeof o)return null;if(o.flow&&Array.isArray(o.flows)&&"string"==typeof o.rootFlowId)return o;if(Array.isArray(o.content))for(let e=o.content.length-1;e>=0;e--){let r=t(o.content[e],l+1);if(r)return r}for(let e of["text","data","result"])if(e in o){let r=t(o[e],l+1);if(r)return r}return null};for(let o=e.length-1;o>=0;o--){var l;let r=t(null==(l=e[o])?void 0:l.content);if(r)return r}return null}(a);if(!i)return void X(w("flows.generator.experimentalNoDraft"));let d={flow:i.flow,flows:i.flows,rootFlowId:i.rootFlowId,errorCount:null!=(s=null==(o=i.validation)?void 0:o.errorCount)?s:0,warningCount:null!=(n=null==(r=i.validation)?void 0:r.warningCount)?n:0,attempts:a.filter(e=>"user"===e.role).length,installedServers:function(e){let t=new Map,l=function(e){let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(o>6)return;let r=oC(e);if(r&&"object"==typeof r){if(!0===r.installed&&"string"==typeof r.serverName&&Array.isArray(r.tools)){var s,n,a;t.set(r.serverName,{name:r.serverName,tools:r.tools.map(e=>{var t;return"string"==typeof e?e:e&&"object"==typeof e?String(null!=(t=e.name)?t:""):""}).filter(Boolean),alreadyExisted:!0===r.alreadyExisted,..."string"==typeof(null==(s=r.plan)?void 0:s.command)?{command:r.plan.command}:{},...Array.isArray(null==(n=r.plan)?void 0:n.args)?{args:r.plan.args.map(String)}:{},..."string"==typeof(null==(a=r.plan)?void 0:a.verificationStatus)?{verificationStatus:r.plan.verificationStatus}:{}})}for(let e of Object.values(r))l(e,o+1)}};for(let t of e)l(t.content);return[...t.values()]}(a)};z(d),oj.info("Experimental Generation Flow returned a draft",{flowId:d.rootFlowId,flowCount:d.flows.length,errors:d.errorCount,warnings:d.warningCount});return}if(!R){let e=await D.g.generateFlow(t,S,{allowInstall:E,allowSubflows:!0,maxDepth:2});if(!e.success)return void X(e.error);let o={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};oj.info("Draft flow generated",{flowId:o.rootFlowId,flowCount:o.flows.length,attempts:o.attempts,errors:o.errorCount,warnings:o.warningCount,installedServers:o.installedServers.length}),z(o),P([...l,oA("assistant",oS(o,!1,w,v))]);return}let e=R.flows.filter(e=>e.id!==R.rootFlowId),a=await D.g.improveFlow(R.flow,t,S,{allowInstall:E,relatedFlows:e});if(!a.success)return void X(a.error);let i={flow:a.flow,flows:a.flows.map(e=>e.flow),rootFlowId:a.rootFlowId,errorCount:a.validation.errorCount,warningCount:a.validation.warningCount,attempts:R.attempts+a.attempts,installedServers:[...R.installedServers,...a.installedServers]};oj.info("Draft flow improved",{flowId:i.rootFlowId,flowCount:i.flows.length,attempts:i.attempts,errors:i.errorCount,warnings:i.warningCount,installedServers:i.installedServers.length}),z(i),P([...l,oA("assistant",oS(i,!0,w,v))])}catch(e){X(e instanceof Error?e.message:String(e))}finally{O(!1)}},[E,R,y,B,S,$,w,v,N]),Y=(0,r.useCallback)(()=>{R&&n(R)},[R,n]),Q=(0,r.useCallback)(async()=>{if(!B&&!U){K(!0),X(null);try{await ob.O.restoreFlowGenerator(),M(null),P([]),z(null)}catch(e){X(e instanceof Error?e.message:String(e))}finally{K(!1)}}},[U,B]),J=(0,r.useCallback)(()=>{B||U||(M(null),P([]),z(null),W(!1),X(null),s())},[U,B,s]);return(0,o.jsxs)(h.A,{open:l,onClose:J,maxWidth:"md",fullWidth:!0,children:[(0,o.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,o.jsx)(C,{color:"primary"}),(0,o.jsxs)(a.default,{sx:{flex:1},children:[w("flows.generator.title"),y&&(0,o.jsx)(I.A,{label:w("flows.generator.experimentalChip"),size:"small",color:"warning",variant:"outlined",sx:{ml:1}}),(0,o.jsx)(i.A,{variant:"body2",color:"text.secondary",children:y?w("flows.generator.experimentalDescription"):w("flows.generator.description")})]}),y&&(0,o.jsx)(p.A,{title:w("flows.generator.restore"),children:(0,o.jsx)("span",{children:(0,o.jsx)(u.A,{"aria-label":w("flows.generator.restore"),onClick:()=>{Q()},disabled:B||U,children:(0,o.jsx)(tH.A,{})})})})]}),(0,o.jsxs)(x.A,{dividers:!0,sx:{p:0},children:[(0,o.jsxs)(a.default,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:[G&&(0,o.jsx)(m.A,{severity:"error",sx:{mb:1.5},onClose:()=>X(null),children:G}),y&&(0,o.jsx)(m.A,{severity:"warning",sx:{mb:1.5},children:w("flows.generator.experimentalWarning")}),(0,o.jsxs)(a.default,{component:"details",sx:{mt:G||y?1.5:0,border:1,borderColor:"divider",borderRadius:2.5,"&[open]":{p:1.5},"&[open] > summary":{mb:1.5}},children:[(0,o.jsx)(a.default,{component:"summary",sx:{px:1.5,py:1.1,cursor:"pointer",color:"text.secondary",fontSize:"0.86rem",fontWeight:700},children:w("flows.generator.advanced")}),(0,o.jsxs)(tr.A,{size:"small",fullWidth:!0,disabled:B||y&&!!T,children:[(0,o.jsx)(ts.A,{id:"flow-generator-model-label",children:w("flows.generator.model")}),(0,o.jsx)(tn.A,{labelId:"flow-generator-model-label",label:w("flows.generator.model"),value:S,onChange:e=>k(e.target.value),children:j.map(e=>{var t;return(0,o.jsx)(H.A,{value:e.id,children:(null==(t=e.displayName)?void 0:t.trim())||e.name},e.id)})})]}),(0,o.jsx)(F.A,{sx:{mt:1},control:(0,o.jsx)(tf.A,{checked:E,onChange:e=>W(e.target.checked),disabled:B||y&&!!T}),label:w("flows.generator.allowTools")}),(0,o.jsxs)(i.A,{variant:"caption",color:"text.secondary",display:"block",children:[w("flows.generator.allowToolsHelp"),y&&" ".concat(w("flows.generator.depth",{count:2}))]}),E&&(0,o.jsx)(m.A,{severity:"warning",sx:{mt:1},children:w("flows.generator.installWarning")})]})]}),(0,o.jsx)(a.default,{sx:{minHeight:360,maxHeight:"55vh",overflowY:"auto",p:2},children:0===_.length?(0,o.jsxs)(a.default,{sx:{py:8,textAlign:"center",color:"text.secondary"},children:[(0,o.jsx)(i.A,{variant:"h6",children:w("flows.generator.question")}),(0,o.jsx)(i.A,{variant:"body2",children:w("flows.generator.example")})]}):(0,o.jsx)(ov.A,{messages:_,conversationId:"new-flow-generator",onToggleDisabled:()=>void 0,onSplitConversation:()=>void 0})}),R&&(0,o.jsx)(m.A,{severity:R.errorCount?"warning":"success",sx:{mx:2,mb:1},children:R.errorCount?v("flows.generator.draftAttention",R.errorCount):w("flows.generator.draftReady")}),(0,o.jsxs)(a.default,{sx:{p:1.5,borderTop:1,borderColor:"divider"},children:[(0,o.jsx)(ow.A,{onSendMessage:e=>{q(e)},disabled:B||!S,placeholder:w("flows.generator.placeholder")}),B&&(0,o.jsx)(i.A,{variant:"caption",color:"text.secondary",children:R?w("flows.generator.applying"):y?w("flows.generator.runningExperimental"):w("flows.generator.building")})]})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:J,disabled:B||U,children:w("flows.generator.close")}),(0,o.jsx)(d.A,{variant:"contained",onClick:Y,disabled:!R||B,startIcon:(0,o.jsx)(C,{}),children:w("flows.generator.continue")})]})]})};var oT=l(79508),oM=l(60530),oI=l(15712),oN=l(33077),oF=l(64419);let oP=(0,y.A)((0,o.jsx)("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}),"FilterList"),oR=(0,y.A)((0,o.jsx)("path",{d:"M3 14h4v-4H3zm0 5h4v-4H3zM3 9h4V5H3zm5 5h13v-4H8zm0 5h13v-4H8zM8 5v4h13V5z"}),"ViewList"),oz=(0,y.A)((0,o.jsx)("path",{d:"M14.67 5v6.5H9.33V5zm1 6.5H21V5h-5.33zm-1 7.5v-6.5H9.33V19zm1-6.5V19H21v-6.5zm-7.34 0H3V19h5.33zm0-1V5H3v6.5z"}),"ViewModule");var oH=l(28466),oE=l(3986),oW=l(94885),oL=l(15686),oD=l(91665),oB=l(22573),oV=l(38459),oO=l(88377),oU=l(64598),oK=l(23201),oG=l(8964);let oX=(0,E.h)("components/Flow/FlowDashboard/FlowDashboard");function o_(e,t){return e+Math.round(255*t).toString(16).padStart(2,"0")}let o$=e=>{let{flows:t,selectedFlow:l,onSelectFlow:s,onDeleteFlow:c,onCopyFlow:p,onEditFlow:f,onOpenInChat:m,onCreateFlow:h,onSetFolder:g,onToggleFavorite:x,isLoading:w=!1}=e,{t:b,tp:y,formatNumber:j}=(0,ed.s9)(),[C,S]=(0,r.useState)(""),[k,T]=(0,on.Xk)("flujo-ui:flows:sort","name-asc"),[I,N]=(0,on.Xk)("flujo-ui:flows:view","grid"),[F,P]=(0,r.useState)(null),[E,W]=(0,on.Xk)("flujo-ui:flows:group",oV.FM),[L,D]=(0,r.useState)(null),[B,V]=(0,on.Xk)("flujo-ui:flows:collapsed",[]),O=(0,r.useMemo)(()=>new Set(B),[B]),[U,K]=(0,r.useState)({});(0,r.useEffect)(()=>{let e=!1;return(async()=>{let t={};try{let e=await fetch("/api/model");if(e.ok){let l=await e.json();Array.isArray(l)&&(t.models=l)}}catch(e){oX.warn("Could not load models for flow badges",e)}try{let e=await fetch("/api/mcp/servers");if(e.ok){let l=await e.json();Array.isArray(l)&&(t.servers=l.map(e=>({name:e.name,status:e.disabled?"disabled":void 0})))}}catch(e){oX.warn("Could not load servers for flow badges",e)}e||K(t)})(),()=>{e=!0}},[]);let G=(0,r.useMemo)(()=>{let e={};for(let l of t)try{e[l.id]=e_(l,U)}catch(e){oX.warn("Failed to validate flow for badge",{flowId:l.id,error:e})}return e},[t,U]),X=(0,n.A)(),_=(0,oI.A)(X.breakpoints.down("sm")),$=(0,oI.A)(X.breakpoints.down("md")),q=()=>{P(null)},Y=e=>{T(e),q()},Q=e=>{W(e),D(null)},Z=(0,r.useMemo)(()=>{oX.debug("Filtering and sorting flows",{searchTerm:C,sortOption:k});let e=t;if(""!==C.trim()){let l=C.toLowerCase();e=t.filter(e=>e.name.toLowerCase().includes(l))}return(0,oO.NP)(e,k)},[t,C,k]),{ref:ee,showBackToTop:et,scrollToTop:el}=(0,oU.R)("flujo-ui:scroll:flows",{deps:[w,Z.length]}),eo=(0,r.useMemo)(()=>(0,oV.yF)(t,e=>e.folder),[t]),er=(0,r.useMemo)(()=>"folder"===E?(0,oV.Je)(Z,e=>e.folder,b("flows.group.ungrouped")):"sort"===E?(0,oV.Az)(Z,e=>{var t;let l=(0,oO.ts)(e,k),o={"recency:unknown":b("flows.group.noDate"),"recency:today":b("flows.group.today"),"recency:week":b("flows.group.week"),"recency:month":b("flows.group.month"),"recency:older":b("flows.group.older"),"nodes:0":b("flows.group.nodes0"),"nodes:1-2":b("flows.group.nodes12"),"nodes:3-5":b("flows.group.nodes35"),"nodes:6-10":b("flows.group.nodes610"),"nodes:11+":b("flows.group.nodes11"),all:b("flows.group.all")};return{...l,label:null!=(t=o[l.key])?t:l.label}}):[],[E,Z,k,b]),es="name-asc"===k?b("flows.sort.nameAsc"):"name-desc"===k?b("flows.sort.nameDesc"):"newest"===k?b("flows.sort.newest"):"oldest"===k?b("flows.sort.oldest"):"most-nodes"===k?b("flows.sort.mostSteps"):b("flows.sort.fewestSteps"),en=e=>(0,o.jsx)(oN.Ay,{container:!0,spacing:2.5,children:e.map(e=>(0,o.jsx)(oN.Ay,{item:!0,xs:12,sm:"compact"===I?12:6,md:"compact"===I?12:3==("compact"===I||_?1:$?2:3)?4:6,children:(0,o.jsx)(ld.A,{flow:e,selected:l===e.id,onSelect:s,onDelete:c,onCopy:p,onEdit:f,onOpenInChat:m,onSetFolder:g,onToggleFavorite:x,folders:eo,validation:G[e.id]})},e.id))});return(0,o.jsxs)(a.default,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,o.jsx)(M.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:b("flows.dashboard.search"),variant:"outlined",size:"small",fullWidth:!0,value:C,onChange:e=>{S(e.target.value)},InputProps:{startAdornment:(0,o.jsx)(J.A,{position:"start",children:(0,o.jsx)(tE.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:X.palette.background.default,borderRadius:1,border:"1px solid ".concat(X.palette.divider),overflow:"hidden"},children:[(0,o.jsx)(u.A,{"aria-label":b("flows.dashboard.cards"),size:"small",onClick:()=>N("grid"),color:"grid"===I?"primary":"default",sx:{borderRadius:0,backgroundColor:"grid"===I?o_(X.palette.primary.main,.1):"transparent"},children:(0,o.jsx)(oz,{fontSize:"small"})}),(0,o.jsx)(u.A,{"aria-label":b("flows.dashboard.compact"),size:"small",onClick:()=>N("compact"),color:"compact"===I?"primary":"default",sx:{borderRadius:0,backgroundColor:"compact"===I?o_(X.palette.primary.main,.1):"transparent"},children:(0,o.jsx)(oR,{fontSize:"small"})})]}),(0,o.jsx)(u.A,{size:"small",onClick:e=>D(e.currentTarget),color:"none"!==E?"primary":"default",sx:{border:"1px solid ".concat(X.palette.divider),backgroundColor:X.palette.background.default},title:b("flows.dashboard.groupCards"),"aria-label":b("flows.dashboard.groupAgents"),children:(0,o.jsx)(oW.A,{fontSize:"small"})}),(0,o.jsx)(u.A,{"aria-label":b("flows.dashboard.sortAgents"),size:"small",onClick:e=>{P(e.currentTarget)},sx:{border:"1px solid ".concat(X.palette.divider),backgroundColor:X.palette.background.default},children:(0,o.jsx)(oF.A,{fontSize:"small"})})]})]})}),(0,o.jsxs)(a.default,{sx:{display:"flex",justifyContent:"space-between",mb:2,px:1},children:[(0,o.jsxs)(i.A,{variant:"body2",color:"textSecondary",children:[y("flows.dashboard.count",t.length,{shown:j(Z.length),total:j(t.length)}),C&&b("flows.dashboard.matching",{search:C})]}),(0,o.jsx)(i.A,{variant:"body2",color:"textSecondary",children:b("flows.dashboard.showing",{sort:es})})]}),(0,o.jsx)(a.default,{ref:ee,sx:{flex:1,overflow:"auto",px:1,pb:2},children:w?(0,o.jsx)(oN.Ay,{container:!0,spacing:2.5,children:Array(6).fill(0).map((e,t)=>(0,o.jsx)(oN.Ay,{item:!0,xs:12,sm:"compact"===I?12:6,md:"compact"===I?12:4,children:(0,o.jsx)(ld.o,{})},"skeleton-".concat(t)))}):Z.length>0?"none"===E?en(Z):er.map(e=>(0,o.jsx)(oB.A,{label:e.label,count:e.items.length,expanded:!O.has(e.key),onToggle:()=>(e=>{V(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e.key),showFolderIcon:"folder"===E,children:en(e.items)},e.key)):(0,o.jsxs)(a.default,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",p:4,backgroundColor:X.palette.background.paper,borderRadius:1,border:"1px dashed ".concat(X.palette.divider),height:"100%",minHeight:200},children:[(0,o.jsx)(i.A,{variant:"h6",gutterBottom:!0,color:"textSecondary",children:C?b("flows.dashboard.noMatches"):b("flows.dashboard.empty")}),C?(0,o.jsxs)(i.A,{variant:"body2",color:"textSecondary",align:"center",children:[b("flows.dashboard.noMatchHelp"),(0,o.jsx)(a.default,{component:"span",display:"block",mt:1,children:(0,o.jsx)(oG.A,{message:"flows.dashboard.trySearch",values:{clearAction:(0,o.jsx)(d.A,{size:"small",onClick:()=>S(""),children:b("flows.dashboard.clearSearch")})}})})]}):(0,o.jsxs)(i.A,{variant:"body2",color:"textSecondary",align:"center",children:[b("flows.dashboard.emptyHelp"),h&&(0,o.jsx)(a.default,{component:"span",display:"block",mt:2,children:(0,o.jsx)(d.A,{variant:"contained",color:"primary",startIcon:(0,o.jsx)(A.A,{}),onClick:h,children:b("flows.dashboard.createFirst")})})]})]})}),(0,o.jsxs)(z.A,{anchorEl:L,open:!!L,onClose:()=>D(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[(0,o.jsxs)(H.A,{selected:"none"===E,onClick:()=>Q("none"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oL.A,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.group.none")})]}),(0,o.jsxs)(H.A,{selected:"folder"===E,onClick:()=>Q("folder"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oD.A,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.group.folder")})]}),(0,o.jsxs)(H.A,{selected:"sort"===E,onClick:()=>Q("sort"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oW.A,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.group.sort")})]})]}),(0,o.jsxs)(z.A,{anchorEl:F,open:!!F,onClose:q,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[(0,o.jsxs)(H.A,{onClick:()=>Y("name-asc"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oH.A,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.nameAsc")})]}),(0,o.jsxs)(H.A,{onClick:()=>Y("name-desc"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oH.A,{fontSize:"small",sx:{transform:"scaleX(-1)"}})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.nameDesc")})]}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(H.A,{onClick:()=>Y("newest"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oE.A,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.newest")})]}),(0,o.jsxs)(H.A,{onClick:()=>Y("oldest"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oE.A,{fontSize:"small",sx:{transform:"scaleX(-1)"}})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.oldest")})]}),(0,o.jsx)(R.A,{}),(0,o.jsxs)(H.A,{onClick:()=>Y("most-nodes"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oP,{fontSize:"small"})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.mostSteps")})]}),(0,o.jsxs)(H.A,{onClick:()=>Y("least-nodes"),children:[(0,o.jsx)(eb.A,{children:(0,o.jsx)(oP,{fontSize:"small",sx:{transform:"scaleY(-1)"}})}),(0,o.jsx)(ey.A,{primary:b("flows.sort.fewestSteps")})]})]}),(0,o.jsx)(oK.A,{show:et,onClick:el})]})},oq=(0,E.h)("app/flows/page"),oY=()=>{var e;oq.debug("Rendering FlowsPage"),(0,n.A)();let t=(0,s.useRouter)(),{t:l,tp:y,formatList:T}=(0,ed.s9)(),[M,I]=(0,r.useState)([]),[N,F]=(0,r.useState)(null),[P,R]=(0,r.useState)(!0),[z,H]=(0,r.useState)(!1),E=(0,r.useRef)(null),[W,B]=(0,r.useState)(null),[V,O]=(0,r.useState)([]),[U,K]=(0,r.useState)(!1),G=(0,r.useRef)(!1),[X,_]=(0,r.useState)(!1),[$,q]=(0,r.useState)(null),[Y,Q]=(0,r.useState)(""),[J,Z]=(0,r.useState)(null),[ee,et]=(0,r.useState)({open:!1,message:"",severity:"info"});(0,r.useEffect)(()=>{oq.info("Loading flows"),(async()=>{R(!0);try{let e=await D.g.loadFlows();oq.debug("Flows loaded successfully",{count:e.length}),I(e),N&&(e.some(e=>e.id===N)||(null==W?void 0:W.id)===N||(oq.warn("Previously selected flow no longer exists",{flowId:N}),F(null),H(!1),en(l("flows.page.previousMissing"),"warning")))}catch(e){oq.error("Error loading flows",e),en(l("flows.page.loadFailed"),"error")}finally{R(!1)}})()},[N,W,l]);let el=(0,r.useCallback)(e=>{oq.debug("Flow selected",{flowId:e}),F(e),H(!0)},[]),eo=(0,r.useCallback)(e=>{oq.debug("Opening flow in chat",{flowId:e}),t.push("/chat?flow=".concat(encodeURIComponent(e)))},[t]),er=(0,r.useCallback)(()=>{N&&t.push("/chat?flow=".concat(encodeURIComponent(N)))},[N,t]),es=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(es.current||P)return;let e=new URLSearchParams(window.location.search).get("flow");if(!e){es.current=!0;return}M.some(t=>t.id===e)&&(es.current=!0,el(e))},[P,M,el]),(0,r.useEffect)(()=>{if(!(z&&N))return;let e=e=>{E.current?E.current.requestNavigation(e):e()};return(0,oM.QO)(e),()=>(0,oM.bH)(e)},[z,N]);let en=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info";oq.debug("Showing snackbar",{message:e,severity:t}),et({open:!0,message:e,severity:t})},[]),ea=(0,r.useCallback)(()=>{oq.debug("Returning to dashboard");let e=()=>{if(H(!1),W&&W.id===N){let e=V.length>0;B(null),O([]),F(null),en(e?l("flows.page.draftBundleDiscarded"):l("flows.page.draftDiscarded"),"info")}};E.current?E.current.requestNavigation(e):e()},[W,V,N,en,l]),ei=(0,r.useCallback)(()=>{et(e=>({...e,open:!1}))},[]);(0,r.useEffect)(()=>{if(!ee.open||"error"===ee.severity)return;let e=setTimeout(()=>{et(e=>({...e,open:!1}))},6e3);return()=>clearTimeout(e)},[ee.open,ee.message,ee.severity]);let ec=(0,r.useCallback)(e=>(oq.debug("Validating flow name",{name:e}),e.trim())?RegExp("^[\\p{L}\\p{N}_ -]+$","u").test(e.trim())?M.some(t=>t.name.trim().toLowerCase()===e.trim().toLowerCase())?(oq.debug("Flow name validation failed: duplicate name"),l("flows.page.nameDuplicate")):(oq.debug("Flow name validation passed"),null):(oq.debug("Flow name validation failed: invalid characters"),l("flows.page.nameCharacters")):(oq.debug("Flow name validation failed: empty name"),l("flows.page.nameEmpty")),[M,l]),eu=async e=>{oq.info("Saving flow",{flowId:e.id,flowName:e.name});try{if((null==W?void 0:W.id)===e.id&&V.length>0){for(let e of(oq.info("Persisting generated subflow descendants before the root",{count:V.length}),V)){let t=M.some(t=>t.id===e.id)?await D.g.updateFlow(e):await D.g.addFlow(e);if(!t.success)return oq.error("Failed to save a generated subflow",{error:t.error,childId:e.id}),en(t.error||l("flows.page.saveSubflowFailed"),"error"),!1}I(e=>{let t=new Set(e.map(e=>e.id)),l=V.filter(e=>!t.has(e.id));return l.length?[...e,...l]:e}),O([])}let t=M.some(t=>t.id===e.id)?await D.g.updateFlow(e):await D.g.addFlow(e);if(!t.success)return oq.error("Failed to save flow",{error:t.error}),en(t.error||l("flows.page.saveFailed"),"error"),!1;return oq.debug("Flow saved successfully"),I(t=>{let l=t.findIndex(t=>t.id===e.id);if(!(l>=0))return oq.debug("Adding new flow to state"),[...t,e];{oq.debug("Updating existing flow in state");let o=[...t];return o[l]=e,o}}),(null==W?void 0:W.id)===e.id&&B(null),F(e.id),en(l("flows.page.saved"),"success"),!0}catch(e){return oq.error("Error saving flow",e),en(l("flows.page.saveFailed"),"error"),!1}},ep=(0,r.useCallback)((e,t)=>{I(l=>[...l.filter(l=>l.id!==e.id&&l.id!==t.id),e,t]),F(e.id),en(l("flows.page.subflowCreated",{name:t.name}),"success")},[en,l]),ef=async e=>{oq.info("Deleting flow",{flowId:e});try{await D.g.deleteFlow(e),oq.debug("Flow deleted successfully"),I(t=>t.filter(t=>t.id!==e)),N===e&&(oq.debug("Clearing selected flow as it was deleted"),F(null),H(!1)),en(l("flows.page.deleted"),"success")}catch(e){oq.error("Error deleting flow",e),en(l("flows.page.deleteFailed"),"error")}},em=(0,r.useCallback)(async(e,t)=>{oq.info("Setting flow folder",{flowId:e,folder:t});let o=M.find(t=>t.id===e);if(!o)return void oq.warn("Flow to move not found",{flowId:e});let r={...o,folder:t&&t.trim()?t.trim():void 0};try{let t=await D.g.updateFlow(r);if(!t.success)return void en(t.error||l("flows.page.moveFailed"),"error");I(t=>t.map(t=>t.id===e?r:t)),en(r.folder?l("flows.page.moved",{folder:r.folder}):l("flows.page.removedFolder"),"success")}catch(e){oq.error("Error setting flow folder",e),en(l("flows.page.moveFailed"),"error")}},[M,en,l]),eh=(0,r.useCallback)(async e=>{oq.info("Toggling flow favorite",{flowId:e});let t=M.find(t=>t.id===e);if(!t)return void oq.warn("Flow to favorite not found",{flowId:e});let o=!t.favorite,r={...t,favorite:o||void 0};try{let t=await D.g.updateFlow(r);if(!t.success)return void en(t.error||l("flows.page.favoriteFailed"),"error");I(t=>t.map(t=>t.id===e?r:t)),en(o?l("flows.page.favoriteAdded"):l("flows.page.favoriteRemoved"),"success")}catch(e){oq.error("Error toggling flow favorite",e),en(l("flows.page.favoriteFailed"),"error")}},[M,en,l]),eg=e=>{oq.info("Copying flow",{flowId:e});let t=M.find(t=>t.id===e);t?(oq.debug("Found flow to copy",{flowName:t.name}),q(t),Q(l("flows.page.copyName",{name:t.name})),_(!0)):(oq.warn("Flow to copy not found",{flowId:e}),en(l("flows.page.notFound"),"error"))},ex=()=>{oq.debug("Closing copy flow dialog"),_(!1),q(null),Q(""),Z(null)},ew=async()=>{if(oq.info("Confirming flow copy"),!$){oq.warn("No flow to copy"),en(l("flows.page.noCopySelection"),"error");return}let e=ec(Y);if(e){oq.debug("Flow name validation failed",{error:e}),Z(e);return}let t=(0,L.A)();oq.debug("Creating new flow from copy",{newId:t,newName:Y});let o={id:t,name:Y,description:$.description,nodes:$.nodes,edges:$.edges,folder:$.folder,favorite:$.favorite};await eu(o)&&(ex(),oq.debug("Selecting newly copied flow"),F(o.id),H(!0),en(l("flows.page.copyCreated",{name:Y}),"success"))},ev=(0,r.useCallback)(e=>{var t,o,r;oq.info("Opening generated draft flow",{flowId:e.flow.id,attempts:e.attempts,errors:e.errorCount,warnings:e.warningCount}),K(!1);let s=(null!=(o=e.flows)?o:[]).filter(t=>t.id!==e.rootFlowId);B(e.flow),O(s),F(e.flow.id),H(!0);let n=null!=(r=null==(t=e.installedServers)?void 0:t.filter(e=>!e.alreadyExisted))?r:[],a=n.length>0?l("flows.page.connectedServers",{servers:T(n.map(e=>e.name))}):"",i=[s.length>0?y("flows.page.helper",s.length):"",a].filter(Boolean).join(" ");e.errorCount>0?en("".concat(y("flows.page.draftAttention",e.errorCount)).concat(i?" ".concat(i):""),"warning"):e.warningCount>0?en("".concat(l("flows.page.draftSuggestions")).concat(i?" ".concat(i):""),"info"):en("".concat(l("flows.page.draftReady")).concat(i?" ".concat(i):""),"success")},[en,l,y,T]),eb=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"guided";oq.info("Creating new flow");let t=l("flows.page.untitled"),o=t,r=2;for(;M.some(e=>e.name===o);)o="".concat(t," ").concat(r),r++;let s=D.g.createNewFlow(o);(0,on.vi)("flujo-ui:flow-builder:mode",e),B(s),O([]),F(s.id),H(!0),en("advanced"===e?l("flows.page.newExpert"):l("flows.page.newGuided"),"info")},[M,en,l]);return(0,r.useEffect)(()=>{if(!G.current&&!P){if("assistant"!==new URLSearchParams(window.location.search).get("create")){G.current=!0;return}G.current=!0,eb("guided"),t.replace("/flows")}},[eb,P,t]),(0,o.jsxs)(a.default,{sx:{height:{xs:"auto",md:"calc(100dvh - var(--app-bar-height))"},minHeight:"calc(100dvh - var(--app-bar-height))",display:"flex",flexDirection:"column",overflow:{xs:"visible",md:"hidden"}},children:[(0,o.jsx)(oT.default,{eyebrow:z?l("flows.page.eyebrowMine"):l("flows.page.eyebrowCreate"),icon:S.A,compact:z,title:z&&N?(null==W?void 0:W.id)===N?l("flows.page.draftSuffix",{name:W.name}):(null==(e=M.find(e=>e.id===N))?void 0:e.name)||l("flows.page.agent"):l("flows.page.title"),description:z?l("flows.page.editDescription"):l("flows.page.description"),leading:z&&N?(0,o.jsx)(u.A,{color:"primary",onClick:ea,"aria-label":l("flows.page.back"),sx:{border:1,borderColor:"divider"},children:(0,o.jsx)(j,{})}):void 0,actions:z?void 0:(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(p.A,{title:l("flows.page.aiHelp"),describeChild:!0,children:(0,o.jsx)(d.A,{variant:"contained",color:"primary",startIcon:(0,o.jsx)(C,{}),onClick:()=>K(!0),"data-tour":"generate-flow",children:l("flows.page.createAi")})}),(0,o.jsx)(p.A,{title:l("flows.page.simpleHelp"),describeChild:!0,children:(0,o.jsx)(d.A,{variant:"outlined",color:"primary",startIcon:(0,o.jsx)(A.A,{}),onClick:()=>eb("guided"),"data-tour":"new-flow",children:l("flows.page.startSimple")})}),(0,o.jsx)(p.A,{title:l("flows.page.expertHelp"),describeChild:!0,children:(0,o.jsx)(d.A,{variant:"outlined",color:"primary",startIcon:(0,o.jsx)(k.A,{}),onClick:()=>eb("advanced"),"data-tour":"new-expert-flow",children:l("flows.page.startExpert")})})]})}),(0,o.jsx)(f.A,{in:ee.open,unmountOnExit:!0,children:(0,o.jsx)(m.A,{severity:ee.severity,onClose:ei,sx:{borderRadius:0},children:ee.message})}),(0,o.jsx)(a.default,{sx:{flex:1,minHeight:0,overflow:{xs:"visible",md:"hidden"}},children:(()=>{if(z&&N){var e;let t=null!=(e=M.find(e=>e.id===N))?e:(null==W?void 0:W.id)===N?W:void 0;return t?(0,o.jsx)(c.A,{in:!0,timeout:300,children:(0,o.jsx)(a.default,{sx:{height:{xs:"auto",md:"100%"}},children:(0,o.jsx)(ox,{ref:E,initialFlow:t,onSave:eu,onDelete:ef,onConversionCommitted:ep,allFlows:[...M.filter(e=>!V.some(t=>t.id===e.id)),...V],relatedDraftFlows:V,onRelatedDraftFlowsChange:O,isDraft:(null==W?void 0:W.id)===t.id,onTry:er,onNavigateToFlow:el},N)})}):(0,o.jsxs)(a.default,{sx:{p:4,textAlign:"center"},children:[(0,o.jsx)(i.A,{variant:"h6",color:"error",children:l("flows.page.notFound")}),(0,o.jsx)(d.A,{variant:"contained",onClick:ea,sx:{mt:2},children:l("flows.page.back")})]})}return(0,o.jsx)(c.A,{in:!0,timeout:300,children:(0,o.jsx)(a.default,{sx:{height:{xs:"auto",md:"100%"}},children:(0,o.jsx)(o$,{flows:M,selectedFlow:N,onSelectFlow:el,onDeleteFlow:ef,onCopyFlow:eg,onCreateFlow:()=>eb("guided"),onSetFolder:em,onToggleFavorite:eh,onOpenInChat:eo,isLoading:P})})})})()}),(0,o.jsxs)(h.A,{open:X,onClose:ex,children:[(0,o.jsx)(g.A,{children:l("flows.page.copyTitle")}),(0,o.jsxs)(x.A,{children:[(0,o.jsx)(w.A,{children:l("flows.page.copyPrompt")}),(0,o.jsx)(v.A,{autoFocus:!0,margin:"dense",label:l("flows.page.nameLabel"),type:"text",fullWidth:!0,value:Y,onChange:e=>{let t=e.target.value;oq.debug("Flow name changed",{name:t}),Q(t),Z(ec(t))},error:!!J,helperText:J})]}),(0,o.jsxs)(b.A,{children:[(0,o.jsx)(d.A,{onClick:ex,children:l("common.cancel")}),(0,o.jsx)(d.A,{onClick:ew,variant:"contained",color:"primary",disabled:!!J,children:l("flows.page.copyAction")})]})]}),(0,o.jsx)(ok,{open:U,onClose:()=>K(!1),onGenerated:ev})]})}},40520:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M10 15h5.88c.27-.31.67-.5 1.12-.5.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5c-.44 0-.84-.19-1.12-.5H11.9c-.46 2.28-2.48 4-4.9 4-2.76 0-5-2.24-5-5 0-2.42 1.72-4.44 4-4.9v2.07c-1.16.41-2 1.53-2 2.83 0 1.65 1.35 3 3 3s3-1.35 3-3zm2.5-11c1.65 0 3 1.35 3 3h2c0-2.76-2.24-5-5-5s-5 2.24-5 5c0 1.43.6 2.71 1.55 3.62l-2.35 3.9c-.68.14-1.2.75-1.2 1.48 0 .83.67 1.5 1.5 1.5s1.5-.67 1.5-1.5c0-.16-.02-.31-.07-.45l3.38-5.63C10.49 9.61 9.5 8.42 9.5 7c0-1.65 1.35-3 3-3m4.5 9c-.64 0-1.23.2-1.72.54l-3.05-5.07C11.53 8.35 11 7.74 11 7c0-.83.67-1.5 1.5-1.5S14 6.17 14 7c0 .15-.02.29-.06.43l2.19 3.65c.28-.05.57-.08.87-.08 2.76 0 5 2.24 5 5s-2.24 5-5 5c-1.85 0-3.47-1.01-4.33-2.5h2.67c.48.32 1.05.5 1.66.5 1.65 0 3-1.35 3-3s-1.35-3-3-3"}),"Webhook")},41356:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M18 23H4c-1.1 0-2-.9-2-2V7h2v14h14zM15 1H8c-1.1 0-1.99.9-1.99 2L6 17c0 1.1.89 2 1.99 2H19c1.1 0 2-.9 2-2V7zm1.5 14h-6v-2h6zm0-6h-2v2h-2V9h-2V7h2V5h2v2h2z"}),"Difference")},51314:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM8 9h8v10H8zm7.5-5-1-1h-5l-1 1H5v2h14V4z"}),"DeleteOutline")},60530:(e,t,l)=>{"use strict";l.d(t,{L_:()=>n,QO:()=>r,bH:()=>s});let o=null;function r(e){o=e}function s(e){o===e&&(o=null)}function n(e){return!!o&&(o(e),!0)}},61267:(e,t,l)=>{"use strict";l.d(t,{A:()=>V});var o=l(95155),r=l(12115),s=l(33567),n=l(78470),a=l(41983),i=l(8532),d=l(84578),c=l(94049),u=l(25635),p=l(28548),f=l(29767),m=l(53062),h=l(1702),g=l(14915),x=l(4484),w=l(89623),v=l(11665),b=l(91665),y=l(62291),j=l(47529),A=l(88107),C=l(43076),S=l(73288),k=l(2778),T=l(52363),M=l(65036),I=l(4474),N=l(22003),F=l(21067),P=l(75912),R=l(91871),z=l(36741),H=l(48563),E=l(36773);let W=e=>{var t,l,r,s,n,a,i,d,f;let{title:m,attempt:h}=e,{t:g,formatNumber:x}=(0,E.s9)();return(0,o.jsxs)(c.default,{sx:{mb:2},children:[(0,o.jsxs)(c.default,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[h.ok?(0,o.jsx)(z.A,{color:"success",fontSize:"small"}):(0,o.jsx)(H.A,{color:"error",fontSize:"small"}),(0,o.jsx)(u.A,{variant:"subtitle2",children:m}),"number"==typeof h.status&&(0,o.jsx)(p.A,{size:"small",label:"HTTP ".concat(h.status)}),(0,o.jsx)(p.A,{size:"small",variant:"outlined",label:"".concat(x(h.durationMs)," ms")})]}),h.ok?(0,o.jsx)(u.A,{variant:"body2",color:"text.secondary",sx:{pl:3},children:g("models.test.response",{response:h.content?'"'.concat(h.content,'"'):g("models.test.empty")})}):(0,o.jsxs)(c.default,{sx:{pl:3},children:[(0,o.jsx)(u.A,{variant:"body2",color:"error.main",children:null==(t=h.error)?void 0:t.message}),((null==(l=h.error)?void 0:l.code)||(null==(r=h.error)?void 0:r.type))&&(0,o.jsxs)(u.A,{variant:"caption",color:"text.secondary",display:"block",children:[(null==(s=h.error)?void 0:s.type)?"type: ".concat(h.error.type):"",(null==(n=h.error)?void 0:n.type)&&(null==(a=h.error)?void 0:a.code)?" \xb7 ":"",(null==(i=h.error)?void 0:i.code)?"code: ".concat(h.error.code):""]}),(null==(d=h.error)?void 0:d.retryAfter)&&(0,o.jsxs)(u.A,{variant:"caption",color:"text.secondary",display:"block",children:["retry-after: ",h.error.retryAfter,"s"]}),(null==(f=h.error)?void 0:f.body)!==void 0&&(0,o.jsx)(c.default,{component:"pre",sx:{mt:.5,p:1,bgcolor:"action.hover",borderRadius:1,fontSize:"0.7rem",overflowX:"auto",maxHeight:160},children:JSON.stringify(h.error.body,null,2)})]})]})},L=e=>{let{open:t,modelLabel:l,loading:r,result:s,error:n,onClose:a,onRetry:i}=e,{t:d}=(0,E.s9)(),p=d((null==s?void 0:s.provider)==="codex"?"models.test.codexSdk":"models.test.openaiSdk");return(0,o.jsxs)(k.A,{open:t,onClose:a,maxWidth:"sm",fullWidth:!0,children:[(0,o.jsx)(T.A,{children:d("models.test.title",{model:l})}),(0,o.jsx)(M.A,{dividers:!0,children:r?(0,o.jsxs)(c.default,{sx:{display:"flex",alignItems:"center",gap:2,py:3},children:[(0,o.jsx)(I.default,{size:24}),(0,o.jsx)(u.A,{variant:"body2",children:d("models.test.sending")})]}):n?(0,o.jsx)(N.A,{severity:"error",children:n}):s?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(N.A,{severity:s.ok?"success":"warning",sx:{mb:2},children:s.diagnosis}),(0,o.jsxs)(u.A,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:[d("models.test.modelLabel",{model:s.model}),s.baseUrl?" \xb7 ".concat(s.baseUrl):"",s.provider?" \xb7 ".concat(s.provider):""]}),(0,o.jsx)(F.A,{sx:{mb:2}}),(0,o.jsx)(W,{title:p,attempt:s.sdk}),(0,o.jsx)(W,{title:d("models.test.axios"),attempt:s.axios})]}):null}),(0,o.jsxs)(P.A,{children:[(0,o.jsx)(R.A,{onClick:i,disabled:r,children:d("models.test.runAgain")}),(0,o.jsx)(R.A,{onClick:a,variant:"contained",children:d("common.close")})]})]})};var D=l(81956);let B=(0,S.h)("frontend/components/models/list/ModelCard"),V=e=>{let{model:t,onEdit:l,onDelete:S,folder:k,folders:T=[],onSetFolder:M,selectable:I=!1,selected:N=!1,onSelect:F,onToggleFavorite:P}=e,{t:R,formatNumber:z}=(0,E.s9)(),H=(0,s.A)(),[W,V]=(0,r.useState)(!1),[O,U]=(0,r.useState)(!1),[K,G]=(0,r.useState)(null),[X,_]=(0,r.useState)(null),[$,q]=(0,r.useState)(null),Y=async()=>{U(!0),_(null),G(null);try{let e=await (0,C.X)().testModel({modelId:t.id});G(e)}catch(e){B.error("Model test failed",{modelId:t.id,error:e}),_(e instanceof Error?e.message:R("models.test.failed"))}finally{U(!1)}},Q=P?(0,o.jsx)(n.A,{title:t.favorite?R("models.favorite.remove"):R("models.favorite.add"),arrow:!0,placement:"top",children:(0,o.jsx)(a.A,{size:"small","aria-label":t.favorite?R("models.favorite.remove"):R("models.favorite.add"),onClick:e=>{e.stopPropagation(),null==P||P(t.id)},sx:{position:"absolute",top:4,left:4,zIndex:2,color:t.favorite?H.palette.warning.main:H.palette.text.secondary,backgroundColor:(0,i.X4)(H.palette.background.paper,.6),"&:hover":{backgroundColor:(0,i.X4)(H.palette.background.paper,.9)}},children:t.favorite?(0,o.jsx)(y.A,{fontSize:"small"}):(0,o.jsx)(j.A,{fontSize:"small"})})}):null,J=(0,o.jsx)(o.Fragment,{children:(0,o.jsxs)(d.A,{sx:{flexGrow:1,p:2.25},children:[(0,o.jsxs)(c.default,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:1,mb:1.2},children:[(0,o.jsx)(u.A,{variant:"h6",sx:{pr:1},children:t.displayName||t.name}),(0,o.jsx)(p.A,{label:(0,A.T_)(t.provider,t.adapter).label,size:"small",sx:{flexShrink:0,color:"primary.light",bgcolor:(0,i.X4)(H.palette.primary.main,.09),border:"1px solid ".concat((0,i.X4)(H.palette.primary.main,.16))}})]}),(0,o.jsx)(u.A,{variant:"body2",color:"text.secondary",sx:{mb:2,minHeight:42},style:{display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis"},children:t.description}),(0,o.jsxs)(c.default,{sx:{mb:1,p:1.25,border:1,borderColor:"divider",borderRadius:2.5,bgcolor:(0,i.X4)(H.palette.background.default,.44)},children:[t.displayName&&(0,o.jsxs)(u.A,{variant:"body2",color:"text.secondary",noWrap:!0,children:[(0,o.jsx)(c.default,{component:"span",sx:{color:"text.primary",fontWeight:650},children:R("models.card.model")})," \xb7 ",t.name]}),"number"==typeof t.contextWindow&&(0,o.jsxs)(u.A,{variant:"body2",color:"text.secondary",children:[(0,o.jsx)(c.default,{component:"span",sx:{color:"text.primary",fontWeight:650},children:R("models.card.context")})," \xb7 ",z(t.contextWindow)," ",R("models.card.tokens")]})]}),t.baseUrl&&(0,o.jsx)(n.A,{title:t.baseUrl,arrow:!0,placement:"top",children:(0,o.jsxs)(u.A,{variant:"body2",color:"text.secondary",noWrap:!0,children:[R("models.card.baseUrl"),": ",t.baseUrl]})}),k&&(0,o.jsx)(p.A,{icon:(0,o.jsx)(b.A,{}),label:k,size:"small",variant:"outlined",sx:{mt:1,maxWidth:"100%"}})]})});return I?(0,o.jsxs)(f.A,{elevation:0,role:"radio","aria-checked":N,sx:{height:"100%",display:"flex",flexDirection:"column",position:"relative",border:e=>"1px solid ".concat(N?e.palette.primary.main:e.palette.divider),boxShadow:N?"0 0 0 3px ".concat((0,i.X4)(H.palette.primary.main,.13)):void 0,transition:"transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease","&:hover":{borderColor:(0,i.X4)(H.palette.primary.main,.42),transform:"translateY(-3px)"}},children:[Q,(0,o.jsx)(m.A,{onClick:()=>null==F?void 0:F(t.id),sx:{height:"100%",display:"flex",flexDirection:"column",alignItems:"stretch"},children:J})]}):(0,o.jsxs)(f.A,{elevation:0,sx:{height:"100%",display:"flex",flexDirection:"column",position:"relative",transition:"transform 200ms ease, border-color 200ms ease, box-shadow 200ms ease","&:hover":{borderColor:(0,i.X4)(H.palette.primary.main,.38),boxShadow:"0 22px 60px ".concat((0,i.X4)(H.palette.primary.main,.12)),transform:"translateY(-4px)"}},children:[Q,J,(0,o.jsxs)(h.A,{disableSpacing:!0,sx:{px:1.5,pb:1.4,borderTop:1,borderColor:"divider"},children:[(0,o.jsx)(n.A,{title:R("models.card.testTooltip"),arrow:!0,children:(0,o.jsx)(a.A,{"aria-label":R("models.card.testAria"),onClick:()=>{V(!0),Y()},children:(0,o.jsx)(w.A,{})})}),(0,o.jsx)(a.A,{"aria-label":R("models.card.editAria"),onClick:l,children:(0,o.jsx)(g.A,{})}),(0,o.jsx)(a.A,{"aria-label":R("models.card.deleteAria"),onClick:S,children:(0,o.jsx)(x.A,{})}),M&&(0,o.jsx)(n.A,{title:R("models.card.moveTooltip"),arrow:!0,children:(0,o.jsx)(a.A,{"aria-label":R("models.card.moveAria"),onClick:e=>q(e.currentTarget),sx:{ml:"auto"},children:(0,o.jsx)(v.A,{})})})]}),M&&(0,o.jsx)(D.A,{anchorEl:$,open:!!$,currentFolder:k,folders:T,onClose:()=>q(null),onAssign:M}),(0,o.jsx)(L,{open:W,modelLabel:t.displayName||t.name,loading:O,result:K,error:X,onClose:()=>V(!1),onRetry:Y})]})}},83478:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M18.3 5.71a.996.996 0 0 0-1.41 0L12 10.59 7.11 5.7a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41L10.59 12 5.7 16.89c-.39.39-.39 1.02 0 1.41s1.02.39 1.41 0L12 13.41l4.89 4.89c.39.39 1.02.39 1.41 0s.39-1.02 0-1.41L13.41 12l4.89-4.89c.38-.38.38-1.02 0-1.4"}),"CloseRounded")},89218:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M9.4 16.6 4.8 12l4.6-4.6L8 6l-6 6 6 6zm5.2 0 4.6-4.6-4.6-4.6L16 6l6 6-6 6z"}),"Code")},89623:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M19.8 18.4 14 10.67V6.5l1.35-1.69c.26-.33.03-.81-.39-.81H9.04c-.42 0-.65.48-.39.81L10 6.5v4.17L4.2 18.4c-.49.66-.02 1.6.8 1.6h14c.82 0 1.29-.94.8-1.6"}),"Science")},90363:(e,t,l)=>{"use strict";l.d(t,{A:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M7.5 5.6 10 7 8.6 4.5 10 2 7.5 3.4 5 2l1.4 2.5L5 7zm12 9.8L17 14l1.4 2.5L17 19l2.5-1.4L22 19l-1.4-2.5L22 14zM22 2l-2.5 1.4L17 2l1.4 2.5L17 7l2.5-1.4L22 7l-1.4-2.5zm-7.63 5.29a.996.996 0 0 0-1.41 0L1.29 18.96c-.39.39-.39 1.02 0 1.41l2.34 2.34c.39.39 1.02.39 1.41 0L16.7 11.05c.39-.39.39-1.02 0-1.41zm-1.03 5.49-2.12-2.12 2.44-2.44 2.12 2.12z"}),"AutoFixHigh")},95480:(e,t,l)=>{"use strict";l.d(t,{A:()=>k});var o=l(95155),r=l(12115),s=l(94049),n=l(25635),a=l(14913),i=l(57883),d=l(2300),c=l(89218),u=l(42063),p=l(17897),f=l(9164),m=l(73288),h=l(90880),g=l(11433);l(32098);var x=l(36773);let w=(0,m.h)("frontend/components/shared/PromptBuilder"),v=e=>{let{server:t,name:l}=e,{t:s}=(0,x.s9)(),n="handoff"===t,[a,i]=(0,r.useState)(null),[d,c]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let e=!1;return(async()=>{try{var o;c(!0);let r=null==(o=(await p.S.listServerTools(t)).tools)?void 0:o.find(e=>e.name===l);e||i(r||null)}catch(e){w.error("Failed to fetch tool info for ".concat(t,":").concat(l),e)}finally{e||c(!1)}})(),()=>{e=!0}},[t,l]),d)?(0,o.jsx)("span",{className:"tool-reference-preview loading ".concat(n?"handoff":""),children:"tool:".concat(t,"__").concat(l)}):a?(0,o.jsx)("span",{className:"tool-reference-preview ".concat(n?"handoff":""),children:s("promptBuilder.toolPreview",{kind:s(n?"promptBuilder.kind.handoff":"promptBuilder.kind.tool"),reference:"tool:".concat(t,"__").concat(l),description:a.description||s("promptBuilder.noDescription")})}):(0,o.jsx)("span",{className:"tool-reference-preview not-found ".concat(n?"handoff":""),children:s("promptBuilder.notFound",{reference:"tool:".concat(t,"__").concat(l)})})},b=e=>{let{server:t,name:l}=e,{t:s}=(0,x.s9)(),[n,a]=(0,r.useState)(null),[i,d]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let e=!1;return(async()=>{try{d(!0);let o=await p.S.listServerResources(t),r=[...o.resources||[],...o.resourceTemplates||[]].find(e=>e.uri===l||e.uriTemplate===l);e||a((null==r?void 0:r.description)||(null==r?void 0:r.name)||null)}catch(e){w.error("Failed to fetch resource info for ".concat(t,":").concat(l),e)}finally{e||d(!1)}})(),()=>{e=!0}},[t,l]),i)?(0,o.jsx)("span",{className:"tool-reference-preview loading resource",children:"resource:".concat(t,"__").concat(l)}):(0,o.jsx)("span",{className:"tool-reference-preview resource",children:s("promptBuilder.resourcePreview",{name:l,server:t,description:n?" (".concat(n,")"):""})})},y=e=>{let{name:t}=e,{t:l}=(0,x.s9)();return(0,o.jsx)("span",{className:"tool-reference-preview runres",children:l("promptBuilder.tempPreview",{name:t})})},j=e=>{let{name:t}=e,{t:l}=(0,x.s9)();return(0,o.jsx)("span",{className:"tool-reference-preview global",children:l("promptBuilder.globalPreview",{reference:"${global:".concat(t,"}")})})},A=e=>{let{binding:t}=e;return"global"===t.kind?(0,o.jsx)(j,{name:t.name}):"runres"===t.kind?(0,o.jsx)(y,{name:t.name}):"resource"===t.kind?(0,o.jsx)(b,{server:t.server,name:t.name}):(0,o.jsx)(v,{server:t.server,name:t.name})},C=e=>{let{value:t}=e,l=[],r=0;for(let e of(0,h.sE)(t))e.index>r&&l.push({type:"text",value:t.slice(r,e.index)}),l.push({type:"binding",binding:e,key:e.index}),r=e.index+e.fullMatch.length;r<t.length&&l.push({type:"text",value:t.slice(r)});let s=[],n=[],a=()=>{s.push((0,o.jsx)("p",{children:n},"p-".concat(s.length))),n=[]};for(let e of l)if("text"===e.type){let t=e.value.split("\n");for(let e=0;e<t.length;e++)n.push(t[e]),e<t.length-1&&a()}else n.push((0,o.jsx)(A,{binding:e.binding},"binding-".concat(e.key)));return(n.length>0||0===s.length)&&a(),(0,o.jsx)("div",{className:"preview-content",children:s})},S=(0,r.forwardRef)((e,t)=>{let{value:l,onChange:p,label:m,height:w=300,onModeChange:v,customPreviewRenderer:b,suggestions:y=[]}=e,{t:j}=(0,x.s9)(),A=null!=m?m:j("promptBuilder.title"),{globalEnvVars:S}=(0,f.useStorage)(),k=(0,r.useMemo)(()=>Object.entries(S).filter(e=>{var t;let[,l]=e;return!(null==(t=l.metadata)?void 0:t.isSecret)}).map(e=>{let[t]=e;return t}).sort((e,t)=>e.localeCompare(t)),[S]),T=(0,r.useMemo)(()=>[...y,...k.map(e=>(0,h.Ub)({kind:"global",server:"",name:e},e))],[k,y]),M=(0,r.useRef)(null),[I,N]=(0,r.useState)("raw");return(0,r.useImperativeHandle)(t,()=>({insertText:e=>{var t;return null==(t=M.current)?void 0:t.insertText(e)},getMode:()=>I}),[I]),(0,o.jsxs)(s.default,{sx:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},children:[A&&(0,o.jsx)(n.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"medium",mb:1},children:A}),(0,o.jsx)(s.default,{sx:{mb:1},children:(0,o.jsxs)(a.A,{value:I,exclusive:!0,onChange:(e,t)=>{t&&(N(t),null==v||v(t))},size:"small",children:[(0,o.jsxs)(i.A,{value:"raw",children:[(0,o.jsx)(c.A,{fontSize:"small",sx:{mr:.5}}),j("promptBuilder.raw")]}),(0,o.jsxs)(i.A,{value:"preview",children:[(0,o.jsx)(u.A,{fontSize:"small",sx:{mr:.5}}),j("promptBuilder.preview")]})]})}),(0,o.jsx)(d.A,{elevation:0,sx:{border:"1px solid rgba(0, 0, 0, 0.12)",borderRadius:1,overflow:"visible",flexGrow:1,display:"flex",flexDirection:"column"},children:"raw"===I?(0,o.jsx)(s.default,{className:"slate-editor-container",sx:{height:"number"==typeof w?w:"100%",overflow:"visible",p:2},children:(0,o.jsx)(g.Ay,{ref:M,value:l,onChange:p,suggestions:T,placeholder:j("promptBuilder.placeholder"),bare:!0,minRows:4,containerSx:{height:"100%"},ariaLabel:A||j("promptBuilder.editorAria")})}):b?(0,o.jsx)(s.default,{className:"custom-preview-container",sx:{height:"number"==typeof w?w:"100%",overflow:"auto"},children:b()}):(0,o.jsx)(s.default,{className:"preview-container",sx:{height:"number"==typeof w?w:"100%",overflow:"auto",p:2},children:(0,o.jsx)(C,{value:l})})})]})});S.displayName="PromptBuilder";let k=S},96429:(e,t,l)=>{"use strict";l.d(t,{default:()=>s});var o=l(15485),r=l(95155);let s=(0,o.A)((0,r.jsx)("path",{d:"M14 9h-4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-4c0-.55-.45-1-1-1m-1 4h-2v-2h2zm8-3c0-.55-.45-1-1-1h-1V7c0-1.1-.9-2-2-2h-2V4c0-.55-.45-1-1-1s-1 .45-1 1v1h-2V4c0-.55-.45-1-1-1s-1 .45-1 1v1H7c-1.1 0-2 .9-2 2v2H4c-.55 0-1 .45-1 1s.45 1 1 1h1v2H4c-.55 0-1 .45-1 1s.45 1 1 1h1v2c0 1.1.9 2 2 2h2v1c0 .55.45 1 1 1s1-.45 1-1v-1h2v1c0 .55.45 1 1 1s1-.45 1-1v-1h2c1.1 0 2-.9 2-2v-2h1c.55 0 1-.45 1-1s-.45-1-1-1h-1v-2h1c.55 0 1-.45 1-1m-5 7H8c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1h8c.55 0 1 .45 1 1v8c0 .55-.45 1-1 1"}),"MemoryRounded")}},e=>{e.O(0,[1137,3862,7926,4754,7758,3392,2678,981,1983,1871,5954,9562,3816,3272,155,4123,8598,9611,3303,5418,1675,2005,6547,4122,8620,8326,2141,4483,4755,5148,1161,4814,1521,3969,8124,3731,5967,5417,8441,1255,7358],()=>e(e.s=10076)),_N_E=e.O()}]);
|