import type { FC } from 'react' import React, { useEffect } from 'react' import type { NodeProps } from '@/app/components/workflow/types' import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update' import type { ToolNodeType } from './types' const Node: FC> = ({ id, data, }) => { const { tool_configurations, paramSchemas } = data const toolConfigs = Object.keys(tool_configurations || {}) const { isChecking, isMissing, uniqueIdentifier, canInstall, onInstallSuccess, shouldDim, } = useNodePluginInstallation(data) const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier const { handleNodeDataUpdate } = useNodeDataUpdate() const shouldLock = !isChecking && isMissing && canInstall && Boolean(uniqueIdentifier) useEffect(() => { if (data._pluginInstallLocked === shouldLock && data._dimmed === shouldDim) return handleNodeDataUpdate({ id, data: { _pluginInstallLocked: shouldLock, _dimmed: shouldDim, }, }) }, [data._pluginInstallLocked, data._dimmed, handleNodeDataUpdate, id, shouldDim, shouldLock]) const hasConfigs = toolConfigs.length > 0 if (!showInstallButton && !hasConfigs) return null return (
{showInstallButton && (
)} {hasConfigs && (
{toolConfigs.map((key, index) => (
{key}
{typeof tool_configurations[key].value === 'string' && (
{paramSchemas?.find(i => i.name === key)?.type === FormTypeEnum.secretInput ? '********' : tool_configurations[key].value}
)} {typeof tool_configurations[key].value === 'number' && (
{Number.isNaN(tool_configurations[key].value) ? '' : tool_configurations[key].value}
)} {typeof tool_configurations[key] !== 'string' && tool_configurations[key]?.type === FormTypeEnum.modelSelector && (
{tool_configurations[key].model}
)}
))}
)}
) } export default React.memo(Node)