= ({
children,
}) => {
const { nodesReadOnly } = useNodesReadOnly()
- const toolsets = useStore(s => s.toolsets)
- const toolIcon = useMemo(() => {
- if (data.type === BlockEnum.Tool)
- return toolsets.find(toolset => toolset.id === data.provider_id)?.icon
- }, [data, toolsets])
-
+ const toolIcon = useToolIcon(data)
return (
= ({
const { nodesReadOnly } = useNodesReadOnly()
const nodesExtraData = useNodesExtraData()
const availableNextNodes = nodesExtraData[data.type].availableNextNodes
-
- const toolsets = useStore(s => s.toolsets)
- const toolIcon = useMemo(() => {
- if (data.type === BlockEnum.Tool)
- return toolsets.find(toolset => toolset.id === data.provider_id)?.icon
- }, [data, toolsets])
+ const toolIcon = useToolIcon(data)
const {
handleNodeDataUpdate,
diff --git a/web/app/components/workflow/nodes/tool/use-config.ts b/web/app/components/workflow/nodes/tool/use-config.ts
index 0d874248b1..82d3396a9c 100644
--- a/web/app/components/workflow/nodes/tool/use-config.ts
+++ b/web/app/components/workflow/nodes/tool/use-config.ts
@@ -7,8 +7,7 @@ import { type ToolNodeType, type ToolVarInput, VarType } from './types'
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import { CollectionType } from '@/app/components/tools/types'
-import type { Collection, Tool } from '@/app/components/tools/types'
-import { fetchBuiltInToolList, fetchCollectionList, fetchCustomToolList, updateBuiltInToolCredential } from '@/service/tools'
+import { updateBuiltInToolCredential } from '@/service/tools'
import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
import Toast from '@/app/components/base/toast'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
@@ -16,40 +15,27 @@ import { VarType as VarVarType } from '@/app/components/workflow/types'
import type { InputVar, Var } from '@/app/components/workflow/types'
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
import {
+ useFetchToolsData,
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
const useConfig = (id: string, payload: ToolNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
+ const { handleFetchAllTools } = useFetchToolsData()
const { t } = useTranslation()
const language = useLanguage()
- const toolsMap = useStore(s => s.toolsMap)
- const setToolsMap = useStore(s => s.setToolsMap)
-
const { inputs, setInputs } = useNodeCrud(id, payload)
/*
* tool_configurations: tool setting, not dynamic setting
* tool_parameters: tool dynamic setting(by user)
*/
- const { provider_id, provider_name, provider_type, tool_name, tool_configurations } = inputs
+ const { provider_id, provider_type, tool_name, tool_configurations } = inputs
const isBuiltIn = provider_type === CollectionType.builtIn
- const [currCollection, setCurrCollection] = useState(null)
- const fetchCurrCollection = useCallback(async () => {
- if (!provider_id)
- return
- const res = await fetchCollectionList()
- const currCollection = res.find(item => item.id === provider_id)
- setCurrCollection(currCollection)
- }, [provider_id])
-
- useEffect(() => {
- if (!provider_id || !isBuiltIn)
- return
-
- fetchCurrCollection()
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [provider_id])
+ const buildInTools = useStore(s => s.buildInTools)
+ const customTools = useStore(s => s.customTools)
+ const currentTools = isBuiltIn ? buildInTools : customTools
+ const currCollection = currentTools.find(item => item.id === provider_id)
// Auth
const needAuth = !!currCollection?.allow_delete
@@ -67,11 +53,11 @@ const useConfig = (id: string, payload: ToolNodeType) => {
type: 'success',
message: t('common.api.actionSuccess'),
})
- await fetchCurrCollection()
+ handleFetchAllTools(provider_type)
hideSetAuthModal()
- }, [currCollection?.name, fetchCurrCollection, hideSetAuthModal, t])
+ }, [currCollection?.name, hideSetAuthModal, t, handleFetchAllTools, provider_type])
- const [currTool, setCurrTool] = useState(null)
+ const currTool = currCollection?.tools.find(tool => tool.name === tool_name)
const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
const toolInputVarSchema = formSchemas.filter((item: any) => item.form === 'llm')
// use setting
@@ -122,26 +108,6 @@ const useConfig = (id: string, payload: ToolNodeType) => {
const isLoading = currTool && (isBuiltIn ? !currCollection : false)
- useEffect(() => {
- (async () => {
- let list: Tool[] = []
- if (toolsMap[provider_id]?.length) {
- list = toolsMap[provider_id]
- }
- else {
- list = isBuiltIn ? await fetchBuiltInToolList(provider_name || provider_id) : await fetchCustomToolList(provider_name)
-
- setToolsMap(produce(toolsMap, (draft) => {
- draft[provider_id] = list
- }))
- }
- const currTool = list.find(tool => tool.name === tool_name)
- if (currTool)
- setCurrTool(currTool)
- })()
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [provider_name])
-
// single run
const [inputVarValues, doSetInputVarValues] = useState>({})
const setInputVarValues = (value: Record) => {
diff --git a/web/app/components/workflow/store.ts b/web/app/components/workflow/store.ts
index 9f82efd00e..03fa3ace44 100644
--- a/web/app/components/workflow/store.ts
+++ b/web/app/components/workflow/store.ts
@@ -9,16 +9,12 @@ import type {
HelpLineHorizontalPosition,
HelpLineVerticalPosition,
} from './help-line/types'
-import type {
- CollectionWithExpanded,
- ToolInWorkflow,
- ToolsMap,
-} from './block-selector/types'
import type {
Edge,
HistoryWorkflowData,
Node,
RunFile,
+ ToolWithProvider,
WorkflowRunningData,
} from './types'
import { WorkflowContext } from './context'
@@ -36,10 +32,6 @@ type Shape = {
setHelpLineHorizontal: (helpLineHorizontal?: HelpLineHorizontalPosition) => void
helpLineVertical?: HelpLineVerticalPosition
setHelpLineVertical: (helpLineVertical?: HelpLineVerticalPosition) => void
- toolsets: CollectionWithExpanded[]
- setToolsets: (toolsets: CollectionWithExpanded[]) => void
- toolsMap: ToolsMap
- setToolsMap: (toolsMap: Record) => void
draftUpdatedAt: number
setDraftUpdatedAt: (draftUpdatedAt: number) => void
publishedAt: number
@@ -65,6 +57,10 @@ type Shape = {
isRestoring: boolean
setIsRestoring: (isRestoring: boolean) => void
debouncedSyncWorkflowDraft: (fn: () => void) => void
+ buildInTools: ToolWithProvider[]
+ setBuildInTools: (tools: ToolWithProvider[]) => void
+ customTools: ToolWithProvider[]
+ setCustomTools: (tools: ToolWithProvider[]) => void
}
export const createWorkflowStore = () => {
@@ -81,10 +77,6 @@ export const createWorkflowStore = () => {
setHelpLineHorizontal: helpLineHorizontal => set(() => ({ helpLineHorizontal })),
helpLineVertical: undefined,
setHelpLineVertical: helpLineVertical => set(() => ({ helpLineVertical })),
- toolsets: [],
- setToolsets: toolsets => set(() => ({ toolsets })),
- toolsMap: {},
- setToolsMap: toolsMap => set(() => ({ toolsMap })),
draftUpdatedAt: 0,
setDraftUpdatedAt: draftUpdatedAt => set(() => ({ draftUpdatedAt: draftUpdatedAt ? draftUpdatedAt * 1000 : 0 })),
publishedAt: 0,
@@ -108,6 +100,10 @@ export const createWorkflowStore = () => {
debouncedSyncWorkflowDraft: debounce((syncWorkflowDraft) => {
syncWorkflowDraft()
}, 5000),
+ buildInTools: [],
+ setBuildInTools: buildInTools => set(() => ({ buildInTools })),
+ customTools: [],
+ setCustomTools: customTools => set(() => ({ customTools })),
}))
}
diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts
index b5e2ba5531..d9d8e243aa 100644
--- a/web/app/components/workflow/types.ts
+++ b/web/app/components/workflow/types.ts
@@ -6,6 +6,7 @@ import type { TransferMethod } from '@/types/app'
import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types'
import type { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
import type { NodeTracing } from '@/types/workflow'
+import type { Collection, Tool } from '@/app/components/tools/types'
export enum BlockEnum {
Start = 'start',
@@ -263,3 +264,7 @@ export type MoreInfo = {
afterKey: string
}
}
+
+export type ToolWithProvider = Collection & {
+ tools: Tool[]
+}
diff --git a/web/context/i18n.ts b/web/context/i18n.ts
index 985f716f80..5416ae7872 100644
--- a/web/context/i18n.ts
+++ b/web/context/i18n.ts
@@ -1,5 +1,9 @@
-import { createContext } from 'use-context-selector'
+import {
+ createContext,
+ useContext,
+} from 'use-context-selector'
import type { Locale } from '@/i18n'
+import { getLanguage } from '@/i18n/language'
type II18NContext = {
locale: Locale
@@ -13,4 +17,11 @@ const I18NContext = createContext({
setLocaleOnClient: (lang: Locale, reloadPage?: boolean) => { },
})
+export const useI18N = () => useContext(I18NContext)
+export const useGetLanguage = () => {
+ const { locale } = useI18N()
+
+ return getLanguage(locale)
+}
+
export default I18NContext
diff --git a/web/service/tools.ts b/web/service/tools.ts
index ac59e2e508..53430f89f5 100644
--- a/web/service/tools.ts
+++ b/web/service/tools.ts
@@ -1,5 +1,6 @@
import { get, post } from './base'
import type { Collection, CustomCollectionBackend, CustomParamSchema, Tool, ToolCredential } from '@/app/components/tools/types'
+import type { ToolWithProvider } from '@/app/components/workflow/types'
export const fetchCollectionList = () => {
return get('/workspaces/current/tool-providers')
@@ -86,3 +87,11 @@ export const testAPIAvailable = (payload: any) => {
},
})
}
+
+export const fetchAllBuiltInTools = () => {
+ return get('/workspaces/current/tools/builtin')
+}
+
+export const fetchAllCustomTools = () => {
+ return get('/workspaces/current/tools/api')
+}