2025-09-18 12:49:10 +08:00
|
|
|
import type { Dispatch, FC, SetStateAction } from 'react'
|
2025-11-12 17:59:37 +08:00
|
|
|
import { memo, useEffect, useMemo } from 'react'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import { useAllBuiltInTools, useAllCustomTools, useAllMCPTools, useAllWorkflowTools, useInvalidateAllBuiltInTools } from '@/service/use-tools'
|
2025-09-18 12:49:10 +08:00
|
|
|
import type {
|
|
|
|
|
BlockEnum,
|
|
|
|
|
NodeDefault,
|
|
|
|
|
OnSelectBlock,
|
|
|
|
|
ToolWithProvider,
|
|
|
|
|
} from '../types'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { TabsEnum } from './types'
|
|
|
|
|
import Blocks from './blocks'
|
2025-11-12 17:59:37 +08:00
|
|
|
import AllStartBlocks from './all-start-blocks'
|
2024-05-27 21:57:08 +08:00
|
|
|
import AllTools from './all-tools'
|
2025-09-18 12:49:10 +08:00
|
|
|
import DataSources from './data-sources'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2025-11-12 17:59:37 +08:00
|
|
|
import { useFeaturedToolsRecommendations } from '@/service/use-plugins'
|
|
|
|
|
import { useGlobalPublicStore } from '@/context/global-public-context'
|
|
|
|
|
import { useWorkflowStore } from '../store'
|
|
|
|
|
import { basePath } from '@/utils/var'
|
|
|
|
|
import Tooltip from '@/app/components/base/tooltip'
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
|
export type TabsProps = {
|
2024-08-08 15:33:02 +08:00
|
|
|
activeTab: TabsEnum
|
|
|
|
|
onActiveTabChange: (activeTab: TabsEnum) => void
|
2024-04-08 18:51:46 +08:00
|
|
|
searchText: string
|
2025-02-17 17:05:13 +08:00
|
|
|
tags: string[]
|
2025-09-18 12:49:10 +08:00
|
|
|
onTagsChange: Dispatch<SetStateAction<string[]>>
|
|
|
|
|
onSelect: OnSelectBlock
|
2024-04-08 18:51:46 +08:00
|
|
|
availableBlocksTypes?: BlockEnum[]
|
2025-09-18 12:49:10 +08:00
|
|
|
blocks: NodeDefault[]
|
|
|
|
|
dataSources?: ToolWithProvider[]
|
|
|
|
|
tabs: Array<{
|
|
|
|
|
key: TabsEnum
|
|
|
|
|
name: string
|
2025-11-12 17:59:37 +08:00
|
|
|
disabled?: boolean
|
2025-09-18 12:49:10 +08:00
|
|
|
}>
|
2025-07-10 14:14:02 +08:00
|
|
|
filterElem: React.ReactNode
|
2024-05-27 21:57:08 +08:00
|
|
|
noBlocks?: boolean
|
2025-09-18 12:49:10 +08:00
|
|
|
noTools?: boolean
|
2025-11-12 17:59:37 +08:00
|
|
|
forceShowStartContent?: boolean // Force show Start content even when noBlocks=true
|
|
|
|
|
allowStartNodeSelection?: boolean // Allow user input option even when trigger node already exists (e.g. change-node flow or when no Start node yet).
|
2024-04-08 18:51:46 +08:00
|
|
|
}
|
|
|
|
|
const Tabs: FC<TabsProps> = ({
|
2024-08-08 15:33:02 +08:00
|
|
|
activeTab,
|
|
|
|
|
onActiveTabChange,
|
2025-02-17 17:05:13 +08:00
|
|
|
tags,
|
2025-09-18 12:49:10 +08:00
|
|
|
onTagsChange,
|
2024-04-08 18:51:46 +08:00
|
|
|
searchText,
|
|
|
|
|
onSelect,
|
|
|
|
|
availableBlocksTypes,
|
2025-09-18 12:49:10 +08:00
|
|
|
blocks,
|
|
|
|
|
dataSources = [],
|
|
|
|
|
tabs = [],
|
2025-07-10 14:14:02 +08:00
|
|
|
filterElem,
|
2024-05-27 21:57:08 +08:00
|
|
|
noBlocks,
|
2025-09-18 12:49:10 +08:00
|
|
|
noTools,
|
2025-11-12 17:59:37 +08:00
|
|
|
forceShowStartContent = false,
|
|
|
|
|
allowStartNodeSelection = false,
|
2024-04-08 18:51:46 +08:00
|
|
|
}) => {
|
2025-11-12 17:59:37 +08:00
|
|
|
const { t } = useTranslation()
|
2025-02-17 17:05:13 +08:00
|
|
|
const { data: buildInTools } = useAllBuiltInTools()
|
|
|
|
|
const { data: customTools } = useAllCustomTools()
|
|
|
|
|
const { data: workflowTools } = useAllWorkflowTools()
|
2025-07-10 14:14:02 +08:00
|
|
|
const { data: mcpTools } = useAllMCPTools()
|
2025-11-12 17:59:37 +08:00
|
|
|
const invalidateBuiltInTools = useInvalidateAllBuiltInTools()
|
|
|
|
|
const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
|
|
|
|
|
const workflowStore = useWorkflowStore()
|
|
|
|
|
const inRAGPipeline = dataSources.length > 0
|
|
|
|
|
const {
|
|
|
|
|
plugins: featuredPlugins = [],
|
|
|
|
|
isLoading: isFeaturedLoading,
|
|
|
|
|
} = useFeaturedToolsRecommendations(enable_marketplace && !inRAGPipeline)
|
|
|
|
|
|
|
|
|
|
const normalizeToolList = useMemo(() => {
|
|
|
|
|
return (list?: ToolWithProvider[]) => {
|
|
|
|
|
if (!list)
|
|
|
|
|
return list
|
|
|
|
|
if (!basePath)
|
|
|
|
|
return list
|
|
|
|
|
let changed = false
|
|
|
|
|
const normalized = list.map((provider) => {
|
|
|
|
|
if (typeof provider.icon === 'string') {
|
|
|
|
|
const icon = provider.icon
|
|
|
|
|
const shouldPrefix = Boolean(basePath)
|
|
|
|
|
&& icon.startsWith('/')
|
|
|
|
|
&& !icon.startsWith(`${basePath}/`)
|
|
|
|
|
|
|
|
|
|
if (shouldPrefix) {
|
|
|
|
|
changed = true
|
|
|
|
|
return {
|
|
|
|
|
...provider,
|
|
|
|
|
icon: `${basePath}${icon}`,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return provider
|
|
|
|
|
})
|
|
|
|
|
return changed ? normalized : list
|
|
|
|
|
}
|
|
|
|
|
}, [basePath])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
workflowStore.setState((state) => {
|
|
|
|
|
const updates: Partial<typeof state> = {}
|
|
|
|
|
const normalizedBuiltIn = normalizeToolList(buildInTools)
|
|
|
|
|
const normalizedCustom = normalizeToolList(customTools)
|
|
|
|
|
const normalizedWorkflow = normalizeToolList(workflowTools)
|
|
|
|
|
const normalizedMCP = normalizeToolList(mcpTools)
|
|
|
|
|
|
|
|
|
|
if (normalizedBuiltIn !== undefined && state.buildInTools !== normalizedBuiltIn)
|
|
|
|
|
updates.buildInTools = normalizedBuiltIn
|
|
|
|
|
if (normalizedCustom !== undefined && state.customTools !== normalizedCustom)
|
|
|
|
|
updates.customTools = normalizedCustom
|
|
|
|
|
if (normalizedWorkflow !== undefined && state.workflowTools !== normalizedWorkflow)
|
|
|
|
|
updates.workflowTools = normalizedWorkflow
|
|
|
|
|
if (normalizedMCP !== undefined && state.mcpTools !== normalizedMCP)
|
|
|
|
|
updates.mcpTools = normalizedMCP
|
|
|
|
|
if (!Object.keys(updates).length)
|
|
|
|
|
return state
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
...updates,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}, [workflowStore, normalizeToolList, buildInTools, customTools, workflowTools, mcpTools])
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div onClick={e => e.stopPropagation()}>
|
|
|
|
|
{
|
2024-05-27 21:57:08 +08:00
|
|
|
!noBlocks && (
|
2025-07-10 14:14:02 +08:00
|
|
|
<div className='relative flex bg-background-section-burn pl-1 pt-1'>
|
2024-05-27 21:57:08 +08:00
|
|
|
{
|
2025-11-12 17:59:37 +08:00
|
|
|
tabs.map((tab) => {
|
|
|
|
|
const commonProps = {
|
|
|
|
|
'className': cn(
|
|
|
|
|
'system-sm-medium relative mr-0.5 flex h-8 items-center rounded-t-lg px-3',
|
|
|
|
|
tab.disabled
|
|
|
|
|
? 'cursor-not-allowed text-text-disabled opacity-60'
|
|
|
|
|
: activeTab === tab.key
|
|
|
|
|
? 'sm-no-bottom cursor-default bg-components-panel-bg text-text-accent'
|
|
|
|
|
: 'cursor-pointer text-text-tertiary',
|
|
|
|
|
),
|
|
|
|
|
'aria-disabled': tab.disabled,
|
|
|
|
|
'onClick': () => {
|
|
|
|
|
if (tab.disabled || activeTab === tab.key)
|
|
|
|
|
return
|
|
|
|
|
onActiveTabChange(tab.key)
|
|
|
|
|
},
|
|
|
|
|
} as const
|
|
|
|
|
if (tab.disabled) {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip
|
|
|
|
|
key={tab.key}
|
|
|
|
|
position='top'
|
|
|
|
|
popupClassName='max-w-[200px]'
|
|
|
|
|
popupContent={t('workflow.tabs.startDisabledTip')}
|
|
|
|
|
>
|
|
|
|
|
<div {...commonProps}>
|
|
|
|
|
{tab.name}
|
|
|
|
|
</div>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={tab.key}
|
|
|
|
|
{...commonProps}
|
|
|
|
|
>
|
|
|
|
|
{tab.name}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
2024-05-27 21:57:08 +08:00
|
|
|
}
|
|
|
|
|
</div>
|
2024-04-08 18:51:46 +08:00
|
|
|
)
|
|
|
|
|
}
|
2025-07-10 14:14:02 +08:00
|
|
|
{filterElem}
|
2025-11-12 17:59:37 +08:00
|
|
|
{
|
|
|
|
|
activeTab === TabsEnum.Start && (!noBlocks || forceShowStartContent) && (
|
|
|
|
|
<div className='border-t border-divider-subtle'>
|
|
|
|
|
<AllStartBlocks
|
|
|
|
|
allowUserInputSelection={allowStartNodeSelection}
|
|
|
|
|
searchText={searchText}
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
availableBlocksTypes={availableBlocksTypes}
|
|
|
|
|
tags={tags}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-04-08 18:51:46 +08:00
|
|
|
{
|
2024-05-27 21:57:08 +08:00
|
|
|
activeTab === TabsEnum.Blocks && !noBlocks && (
|
2025-07-10 14:14:02 +08:00
|
|
|
<div className='border-t border-divider-subtle'>
|
|
|
|
|
<Blocks
|
|
|
|
|
searchText={searchText}
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
availableBlocksTypes={availableBlocksTypes}
|
2025-09-18 12:49:10 +08:00
|
|
|
blocks={blocks}
|
2025-07-10 14:14:02 +08:00
|
|
|
/>
|
|
|
|
|
</div>
|
2024-04-08 18:51:46 +08:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
{
|
2025-09-18 12:49:10 +08:00
|
|
|
activeTab === TabsEnum.Sources && !!dataSources.length && (
|
|
|
|
|
<div className='border-t border-divider-subtle'>
|
|
|
|
|
<DataSources
|
|
|
|
|
searchText={searchText}
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
dataSources={dataSources}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
activeTab === TabsEnum.Tools && !noTools && (
|
2024-05-27 21:57:08 +08:00
|
|
|
<AllTools
|
2024-04-08 18:51:46 +08:00
|
|
|
searchText={searchText}
|
|
|
|
|
onSelect={onSelect}
|
2025-02-17 17:05:13 +08:00
|
|
|
tags={tags}
|
2025-07-10 14:14:02 +08:00
|
|
|
canNotSelectMultiple
|
2025-02-17 17:05:13 +08:00
|
|
|
buildInTools={buildInTools || []}
|
|
|
|
|
customTools={customTools || []}
|
|
|
|
|
workflowTools={workflowTools || []}
|
2025-07-10 14:14:02 +08:00
|
|
|
mcpTools={mcpTools || []}
|
|
|
|
|
canChooseMCPTool
|
2025-09-18 12:49:10 +08:00
|
|
|
onTagsChange={onTagsChange}
|
2025-11-12 17:59:37 +08:00
|
|
|
isInRAGPipeline={inRAGPipeline}
|
|
|
|
|
featuredPlugins={featuredPlugins}
|
|
|
|
|
featuredLoading={isFeaturedLoading}
|
|
|
|
|
showFeatured={enable_marketplace && !inRAGPipeline}
|
|
|
|
|
onFeaturedInstallSuccess={async () => {
|
|
|
|
|
invalidateBuiltInTools()
|
|
|
|
|
}}
|
2024-04-08 18:51:46 +08:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(Tabs)
|