import type { FC } from 'react' import type { ToolNodeType } from './types' import type { NodeProps } from '@/app/components/workflow/types' import * as React from 'react' import { useTranslation } from 'react-i18next' import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { isToolAuthorizationRequired } from './auth' import useCurrentToolCollection from './hooks/use-current-tool-collection' const Node: FC> = ({ data, }) => { const { t } = useTranslation() const { tool_configurations, paramSchemas } = data const toolConfigs = Object.keys(tool_configurations || {}) const { isChecking, isMissing, uniqueIdentifier, canInstall, onInstallSuccess, shouldDim, } = useNodePluginInstallation(data) const { currCollection } = useCurrentToolCollection(data.provider_type, data.provider_id) const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier const showAuthorizationWarning = isToolAuthorizationRequired(data.provider_type, currCollection) const hasConfigs = toolConfigs.length > 0 if (!showInstallButton && !hasConfigs && !showAuthorizationWarning) return null return (
{showInstallButton && (
)} {(hasConfigs || showAuthorizationWarning) && (
{hasConfigs && toolConfigs.map(key => (
{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}
)}
))} {showAuthorizationWarning && (
{t('nodes.tool.authorizationRequired', { ns: 'workflow' })}
)}
)}
) } export default React.memo(Node)