"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AgentNodeElement: ()=>AgentNodeElement
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const index_cjs_namespaceObject = require("../../../icons/index.cjs");
const react_cjs_namespaceObject = require("../../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const external_types_cjs_namespaceObject = require("../../../types.cjs");
const icon_registry_cjs_namespaceObject = require("../../../utils/icon-registry.cjs");
const BaseNode_cjs_namespaceObject = require("../../BaseNode/BaseNode.cjs");
const BaseNodeConfigContext_cjs_namespaceObject = require("../../BaseNode/BaseNodeConfigContext.cjs");
const external_FloatingCanvasPanel_index_cjs_namespaceObject = require("../../FloatingCanvasPanel/index.cjs");
const external_AgentFlow_constants_cjs_namespaceObject = require("../AgentFlow.constants.cjs");
const agent_flow_store_cjs_namespaceObject = require("../store/agent-flow-store.cjs");
const external_AgentNode_styles_cjs_namespaceObject = require("./AgentNode.styles.cjs");
const HOVER_DELAY_MS = 500;
const HOVER_HIDE_DELAY_MS = 300;
const alwaysShowNotches = ()=>true;
const AgentNodeComponent = /*#__PURE__*/ (0, external_react_namespaceObject.memo)((props)=>{
    const { id, data, selected = false, mode = 'design', hasMemory = false, hasContext = false, hasEscalation = false, hasTool = false, hasMcp = false, hasA2a = false, a2aEnabled = false, mcpEnabled = true, hasError = false, hasSuccess = false, hasRunning = false, onAddResource, onAddInstructions, translations, enableMemory, enableInstructions = false, healthScore, onHealthScoreClick, suggestionTranslations, suggestionGroupVersion, ...nodeProps } = props;
    const { actOnSuggestion } = (0, agent_flow_store_cjs_namespaceObject.useAgentFlowStore)();
    const [isNodeHovered, setIsNodeHovered] = (0, external_react_namespaceObject.useState)(false);
    const [isPanelHovered, setIsPanelHovered] = (0, external_react_namespaceObject.useState)(false);
    const hoverTimeoutRef = (0, external_react_namespaceObject.useRef)(null);
    const hideTimeoutRef = (0, external_react_namespaceObject.useRef)(null);
    const showSettingsPreview = isNodeHovered || isPanelHovered;
    const { name, definition, suggestionId } = data;
    const isSuggestion = data.isSuggestion ?? false;
    const suggestionType = isSuggestion ? data.suggestionType : void 0;
    const isConversational = definition?.metadata?.isConversational === true;
    const suggestTranslations = suggestionTranslations ?? external_types_cjs_namespaceObject.DefaultSuggestionTranslations;
    const agentIcon = (0, external_react_namespaceObject.useMemo)(()=>{
        if (isConversational) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ConversationalAgentIcon, {
            color: "var(--canvas-foreground-de-emp)",
            w: 32,
            h: 32
        });
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.AutonomousAgentIcon, {
            color: "var(--canvas-foreground-de-emp)",
            w: 32,
            h: 32
        });
    }, [
        isConversational
    ]);
    const settings = definition?.settings;
    const handleMouseEnter = (0, external_react_namespaceObject.useCallback)(()=>{
        if (!enableInstructions) return;
        if (hideTimeoutRef.current) {
            clearTimeout(hideTimeoutRef.current);
            hideTimeoutRef.current = null;
        }
        hoverTimeoutRef.current = setTimeout(()=>{
            setIsNodeHovered(true);
        }, HOVER_DELAY_MS);
    }, [
        enableInstructions
    ]);
    const handleMouseLeave = (0, external_react_namespaceObject.useCallback)(()=>{
        if (!enableInstructions) return;
        if (hoverTimeoutRef.current) {
            clearTimeout(hoverTimeoutRef.current);
            hoverTimeoutRef.current = null;
        }
        hideTimeoutRef.current = setTimeout(()=>{
            setIsNodeHovered(false);
        }, HOVER_HIDE_DELAY_MS);
    }, [
        enableInstructions
    ]);
    const handlePanelMouseEnter = (0, external_react_namespaceObject.useCallback)(()=>{
        if (hideTimeoutRef.current) {
            clearTimeout(hideTimeoutRef.current);
            hideTimeoutRef.current = null;
        }
        setIsPanelHovered(true);
    }, []);
    const handlePanelMouseLeave = (0, external_react_namespaceObject.useCallback)(()=>{
        hideTimeoutRef.current = setTimeout(()=>{
            setIsPanelHovered(false);
        }, HOVER_HIDE_DELAY_MS);
    }, []);
    (0, external_react_namespaceObject.useEffect)(()=>()=>{
            if (hoverTimeoutRef.current) clearTimeout(hoverTimeoutRef.current);
            if (hideTimeoutRef.current) clearTimeout(hideTimeoutRef.current);
        }, []);
    const executionStatus = (0, external_react_namespaceObject.useMemo)(()=>{
        if (hasError) return 'Failed';
        if (hasSuccess) return 'Completed';
        if (hasRunning) return 'InProgress';
    }, [
        hasError,
        hasSuccess,
        hasRunning
    ]);
    const displayMemory = true === enableMemory && ('design' === mode || 'view' === mode && hasMemory);
    const displayContext = 'design' === mode || 'view' === mode && hasContext;
    const displayEscalation = 'design' === mode || 'view' === mode && hasEscalation;
    const displayTool = 'design' === mode || 'view' === mode && hasTool;
    const isMcpEnabled = false !== mcpEnabled;
    const displayMcp = 'design' === mode && isMcpEnabled || 'view' === mode && !!hasMcp;
    const isA2aEnabled = true === a2aEnabled;
    const displayA2a = 'design' === mode && isA2aEnabled || 'view' === mode && !!hasA2a;
    const handleConfigurations = (0, external_react_namespaceObject.useMemo)(()=>{
        const configs = [];
        const topHandles = [];
        const bottomHandles = [];
        if (displayMemory) topHandles.push({
            id: external_AgentFlow_constants_cjs_namespaceObject.ResourceNodeType.MemorySpace,
            type: 'source',
            handleType: 'artifact',
            label: translations.memory,
            showButton: 'design' === mode && !hasMemory,
            labelBackgroundColor: 'var(--canvas-background-secondary)',
            visible: displayMemory,
            onAction: (_e)=>{
                onAddResource?.('memorySpace');
            }
        });
        if (displayEscalation) topHandles.push({
            id: external_AgentFlow_constants_cjs_namespaceObject.ResourceNodeType.Escalation,
            type: 'source',
            handleType: 'artifact',
            label: translations.escalations,
            showButton: 'design' === mode,
            labelBackgroundColor: 'var(--canvas-background-secondary)',
            visible: displayEscalation,
            onAction: (_e)=>{
                onAddResource?.('escalation');
            }
        });
        if (topHandles.length) configs.push({
            position: react_cjs_namespaceObject.Position.Top,
            handles: topHandles,
            visible: true
        });
        if (displayContext || displayTool || displayMcp || displayA2a) {
            bottomHandles.push({
                id: external_AgentFlow_constants_cjs_namespaceObject.ResourceNodeType.Context,
                type: 'source',
                handleType: 'artifact',
                label: translations.context,
                showButton: 'design' === mode,
                labelBackgroundColor: 'var(--canvas-background-secondary)',
                visible: displayContext,
                onAction: (_e)=>{
                    onAddResource?.('context');
                }
            }, {
                id: external_AgentFlow_constants_cjs_namespaceObject.ResourceNodeType.Tool,
                type: 'source',
                handleType: 'artifact',
                label: translations.tools,
                showButton: 'design' === mode,
                labelBackgroundColor: 'var(--canvas-background-secondary)',
                visible: displayTool || displayMcp || displayA2a,
                onAction: (_e)=>{
                    if (displayTool) onAddResource?.('tool');
                    else if (displayMcp) onAddResource?.('mcp');
                    else if (displayA2a) onAddResource?.('a2a');
                }
            });
            configs.push({
                position: react_cjs_namespaceObject.Position.Bottom,
                handles: bottomHandles,
                visible: true
            });
        }
        return configs;
    }, [
        mode,
        displayContext,
        displayMemory,
        displayMcp,
        displayTool,
        displayA2a,
        displayEscalation,
        hasMemory,
        onAddResource,
        translations
    ]);
    const healthScoreBadge = (0, external_react_namespaceObject.useMemo)(()=>{
        if (void 0 === healthScore) return null;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.HealthScoreBadge, {
            onClick: (e)=>{
                if (onHealthScoreClick) {
                    e.stopPropagation();
                    onHealthScoreClick();
                }
            },
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.HealthScoreIcon, {
                    w: 14,
                    h: 14
                }),
                healthScore.toString()
            ]
        });
    }, [
        healthScore,
        onHealthScoreClick
    ]);
    const subLabelWithHealthScore = (0, external_react_namespaceObject.useMemo)(()=>{
        const baseSubLabel = isConversational ? translations.conversationalAgent : translations.autonomousAgent;
        if (!healthScoreBadge) return baseSubLabel;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SubLabelContainer, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    children: baseSubLabel
                }),
                healthScoreBadge
            ]
        });
    }, [
        isConversational,
        translations,
        healthScoreBadge
    ]);
    const { instructionsFooter, footerVariant } = (0, external_react_namespaceObject.useMemo)(()=>{
        if (!enableInstructions) return {
            instructionsFooter: null,
            footerVariant: 'none'
        };
        const system = data.instructions?.system;
        const user = data.instructions?.user;
        const hasSystem = Boolean(system);
        const hasUser = Boolean(user);
        const hasContent = hasSystem || hasUser;
        if (hasContent) return {
            instructionsFooter: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.InstructionsPreview, {
                onClick: (e)=>{
                    e.stopPropagation();
                    onAddInstructions?.();
                },
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.InstructionsLabel, {
                        children: translations.instructions
                    }),
                    system && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.InstructionsLine, {
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("strong", {
                                children: [
                                    translations.system,
                                    ":"
                                ]
                            }),
                            ' "',
                            system,
                            '"'
                        ]
                    }),
                    user && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.InstructionsLine, {
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("strong", {
                                children: [
                                    translations.user,
                                    ":"
                                ]
                            }),
                            ' "',
                            user,
                            '"'
                        ]
                    })
                ]
            }),
            footerVariant: hasSystem && hasUser ? 'double' : 'single'
        };
        if ('design' !== mode || !onAddInstructions) return {
            instructionsFooter: null,
            footerVariant: 'none'
        };
        return {
            instructionsFooter: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.AddInstructionsButton, {
                type: "button",
                onClick: (e)=>{
                    e.stopPropagation();
                    onAddInstructions();
                },
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                        icon: "plus",
                        size: 14
                    }),
                    translations.addInstructions
                ]
            }),
            footerVariant: 'button'
        };
    }, [
        enableInstructions,
        data.instructions,
        mode,
        onAddInstructions,
        translations
    ]);
    const shouldShowAddButtonFn = (opts)=>opts.showAddButton || opts.selected;
    const handleActOnSuggestion = (0, external_react_namespaceObject.useCallback)((suggestionId, action)=>{
        actOnSuggestion(suggestionId, action);
    }, [
        actOnSuggestion
    ]);
    const toolbarConfig = (0, external_react_namespaceObject.useMemo)(()=>{
        if ('view' === mode) return null;
        if (isSuggestion && suggestionId) {
            if ('0.0.1' === suggestionGroupVersion) return null;
            const rejectAction = {
                id: 'reject-suggestion',
                icon: 'x',
                label: suggestTranslations.reject,
                disabled: false,
                onAction: ()=>handleActOnSuggestion(suggestionId, 'reject')
            };
            const acceptAction = {
                id: 'accept-suggestion',
                icon: 'check',
                label: suggestTranslations.accept,
                disabled: false,
                onAction: ()=>handleActOnSuggestion(suggestionId, 'accept')
            };
            return {
                actions: [
                    rejectAction,
                    acceptAction
                ],
                overflowActions: [],
                overflowLabel: '',
                position: 'top',
                align: 'center'
            };
        }
        return null;
    }, [
        mode,
        isSuggestion,
        suggestionId,
        suggestionGroupVersion,
        suggestTranslations,
        handleActOnSuggestion
    ]);
    const settingsPreviewContent = (0, external_react_namespaceObject.useMemo)(()=>{
        const systemPrompt = data.instructions?.system ?? '';
        const userPrompt = data.instructions?.user ?? '';
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsPreviewContainer, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsPreviewHeader, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsPreviewTitle, {
                            children: translations.agentSettings
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsPreviewSubtitle, {
                            children: translations.readOnlyPreview
                        })
                    ]
                }),
                settings?.model && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsSection, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsSectionLabel, {
                            children: translations.model
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsSectionValue, {
                            children: settings.model
                        })
                    ]
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsSection, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsSectionLabel, {
                            children: translations.systemPrompt
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsPromptBox, {
                            isEmpty: !systemPrompt,
                            children: systemPrompt || translations.notConfigured
                        })
                    ]
                }),
                !isConversational && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsSection, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsSectionLabel, {
                            children: translations.userPrompt
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsPromptBox, {
                            isEmpty: !userPrompt,
                            children: userPrompt || translations.notConfigured
                        })
                    ]
                }),
                settings?.temperature !== void 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsRow, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowLabel, {
                            children: translations.temperature
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowValue, {
                            children: settings.temperature
                        })
                    ]
                }),
                settings?.maxTokens !== void 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsRow, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowLabel, {
                            children: translations.maxTokens
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowValue, {
                            children: settings.maxTokens
                        })
                    ]
                }),
                settings?.maxIterations !== void 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_AgentNode_styles_cjs_namespaceObject.SettingsRow, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowLabel, {
                            children: translations.maxIterations
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_AgentNode_styles_cjs_namespaceObject.SettingsRowValue, {
                            children: settings.maxIterations
                        })
                    ]
                })
            ]
        });
    }, [
        data.instructions,
        settings,
        translations,
        isConversational
    ]);
    const baseNodeConfig = (0, external_react_namespaceObject.useMemo)(()=>({
            executionStatusOverride: executionStatus,
            suggestionType,
            handleConfigurations,
            toolbarConfig,
            footerVariant,
            iconComponent: agentIcon,
            footerComponent: instructionsFooter,
            subLabelComponent: subLabelWithHealthScore,
            shouldShowAddButtonFn,
            shouldShowButtonHandleNotchesFn: alwaysShowNotches
        }), [
        executionStatus,
        suggestionType,
        handleConfigurations,
        toolbarConfig,
        footerVariant,
        agentIcon,
        instructionsFooter,
        subLabelWithHealthScore,
        shouldShowAddButtonFn
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        onMouseEnter: handleMouseEnter,
        onMouseLeave: handleMouseLeave,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BaseNodeConfigContext_cjs_namespaceObject.BaseNodeOverrideConfigProvider, {
                value: baseNodeConfig,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BaseNode_cjs_namespaceObject.BaseNode, {
                    ...nodeProps,
                    id: id,
                    type: isConversational ? 'uipath.agent.conversational' : 'uipath.agent.autonomous',
                    data: {
                        ...data,
                        display: {
                            label: name,
                            subLabel: isConversational ? translations.conversationalAgent : translations.autonomousAgent,
                            shape: 'rectangle',
                            background: 'var(--canvas-background)',
                            iconBackground: 'var(--canvas-background-secondary)'
                        }
                    },
                    selected: selected
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_FloatingCanvasPanel_index_cjs_namespaceObject.FloatingCanvasPanel, {
                open: showSettingsPreview,
                nodeId: id,
                placement: "right-start",
                offset: 16,
                onMouseEnter: handlePanelMouseEnter,
                onMouseLeave: handlePanelMouseLeave,
                children: settingsPreviewContent
            })
        ]
    });
});
AgentNodeComponent.displayName = 'AgentNodeComponent';
const AgentNodeWrapper = (props)=>{
    const { data, mode, hasMemory, hasContext, hasEscalation, hasTool, hasMcp, hasA2a, a2aEnabled, mcpEnabled, hasError, hasSuccess, hasRunning, onAddResource, onAddInstructions, translations, enableMemory, enableInstructions, healthScore, onHealthScoreClick, suggestionTranslations, suggestionGroupVersion, ...nodeProps } = props;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AgentNodeComponent, {
        ...nodeProps,
        data: data,
        mode: mode,
        hasMemory: hasMemory,
        hasContext: hasContext,
        hasEscalation: hasEscalation,
        hasTool: hasTool,
        hasMcp: hasMcp,
        hasA2a: hasA2a,
        a2aEnabled: a2aEnabled,
        mcpEnabled: mcpEnabled,
        hasError: hasError,
        hasSuccess: hasSuccess,
        hasRunning: hasRunning,
        onAddResource: onAddResource,
        onAddInstructions: onAddInstructions,
        translations: translations,
        enableMemory: enableMemory,
        enableInstructions: enableInstructions,
        healthScore: healthScore,
        onHealthScoreClick: onHealthScoreClick,
        suggestionTranslations: suggestionTranslations,
        suggestionGroupVersion: suggestionGroupVersion
    });
};
const AgentNodeElement = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(AgentNodeWrapper);
exports.AgentNodeElement = __webpack_exports__.AgentNodeElement;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AgentNodeElement"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
