mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
feat: Unify sandbox detection and apply Agent icon override
This commit is contained in:
@ -4,6 +4,7 @@ import type { DocPathWithoutLang } from '@/types/doc-paths'
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { useFeatures } from '@/app/components/base/features/hooks'
|
||||
import { WORKFLOW_COMMON_NODES } from '@/app/components/workflow/constants/node'
|
||||
import AnswerDefault from '@/app/components/workflow/nodes/answer/default'
|
||||
import EndDefault from '@/app/components/workflow/nodes/end/default'
|
||||
@ -18,7 +19,9 @@ import { useIsChatMode } from './use-is-chat-mode'
|
||||
export const useAvailableNodesMetaData = () => {
|
||||
const { t } = useTranslation()
|
||||
const isChatMode = useIsChatMode()
|
||||
const isSandboxed = useAppStore(s => s.appDetail?.runtime_type === 'sandboxed')
|
||||
const isSandboxFeatureEnabled = useFeatures(s => s.features.sandbox?.enabled) ?? false
|
||||
const isSandboxRuntime = useAppStore(s => s.appDetail?.runtime_type === 'sandboxed')
|
||||
const isSandboxed = isSandboxFeatureEnabled || isSandboxRuntime
|
||||
const docLink = useDocLink()
|
||||
|
||||
const startNodeMetaData = useMemo(() => ({
|
||||
@ -76,10 +79,14 @@ export const useAvailableNodesMetaData = () => {
|
||||
const title = isSandboxed && metaData.type === BlockEnum.LLM
|
||||
? t('blocks.agent', { ns: 'workflow' })
|
||||
: t(`blocks.${metaData.type}` as const, { ns: 'workflow' })
|
||||
const iconTypeOverride = isSandboxed && metaData.type === BlockEnum.LLM
|
||||
? BlockEnum.Agent
|
||||
: undefined
|
||||
const description = t(`blocksAbout.${metaData.type}`, { ns: 'workflow' })
|
||||
const helpLinkPath = `/use-dify/nodes/${metaData.helpLinkUri}` as DocPathWithoutLang
|
||||
return toNodeDefaultBase(typedNode, {
|
||||
...metaData,
|
||||
iconType: iconTypeOverride,
|
||||
title,
|
||||
description,
|
||||
helpLinkUri: docLink(helpLinkPath),
|
||||
@ -87,6 +94,7 @@ export const useAvailableNodesMetaData = () => {
|
||||
...typedNode.defaultValue,
|
||||
type: metaData.type,
|
||||
title,
|
||||
_iconTypeOverride: iconTypeOverride,
|
||||
})
|
||||
})
|
||||
}, [mergedNodesMetaData, t, docLink, isSandboxed])
|
||||
|
||||
@ -8,12 +8,20 @@ import {
|
||||
import answerDefault from '@/app/components/workflow/nodes/answer/default'
|
||||
import llmDefault from '@/app/components/workflow/nodes/llm/default'
|
||||
import startDefault from '@/app/components/workflow/nodes/start/default'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { generateNewNode } from '@/app/components/workflow/utils'
|
||||
import { STORAGE_KEYS } from '@/config/storage-keys'
|
||||
import { storage } from '@/utils/storage'
|
||||
import { useIsChatMode } from './use-is-chat-mode'
|
||||
|
||||
export const useWorkflowTemplate = () => {
|
||||
const isChatMode = useIsChatMode()
|
||||
const isSandboxed = useAppStore(s => s.appDetail?.runtime_type === 'sandboxed')
|
||||
const appDetail = useAppStore(s => s.appDetail)
|
||||
const isSandboxedByType = appDetail?.runtime_type === 'sandboxed'
|
||||
const isSandboxedBySelection = appDetail?.id
|
||||
? storage.getBoolean(`${STORAGE_KEYS.LOCAL.WORKFLOW.SANDBOX_RUNTIME_PREFIX}${appDetail.id}`) === true
|
||||
: false
|
||||
const isSandboxed = isSandboxedByType || isSandboxedBySelection
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { newNode: startNode } = generateNewNode({
|
||||
@ -39,6 +47,7 @@ export const useWorkflowTemplate = () => {
|
||||
query_prompt_template: '{{#sys.query#}}\n\n{{#sys.files#}}',
|
||||
},
|
||||
selected: true,
|
||||
_iconTypeOverride: isSandboxed ? BlockEnum.Agent : undefined,
|
||||
type: llmDefault.metaData.type,
|
||||
title: llmTitle,
|
||||
},
|
||||
|
||||
@ -28,6 +28,7 @@ import OnlineUsers from '@/app/components/workflow/header/online-users'
|
||||
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { useTriggerStatusStore } from '@/app/components/workflow/store/trigger-status'
|
||||
import {
|
||||
BlockEnum,
|
||||
SupportUploadFileTypes,
|
||||
ViewType,
|
||||
} from '@/app/components/workflow/types'
|
||||
@ -221,14 +222,32 @@ const WorkflowAppWithAdditionalContext = () => {
|
||||
}
|
||||
}, [workflowStore])
|
||||
|
||||
const isSandboxRuntime = appDetail?.runtime_type === 'sandboxed'
|
||||
const isSandboxFeatureEnabled = data?.features?.sandbox?.enabled === true
|
||||
const isSandboxed = isSandboxRuntime || isSandboxFeatureEnabled
|
||||
|
||||
const nodesData = useMemo(() => {
|
||||
if (data) {
|
||||
const processedNodes = initialNodes(data.graph.nodes, data.graph.edges)
|
||||
collaborationManager.setNodes([], processedNodes)
|
||||
return processedNodes
|
||||
const resolvedNodes = isSandboxed
|
||||
? processedNodes.map((node) => {
|
||||
if (node.data.type !== BlockEnum.LLM)
|
||||
return node
|
||||
|
||||
return {
|
||||
...node,
|
||||
data: {
|
||||
...node.data,
|
||||
_iconTypeOverride: BlockEnum.Agent,
|
||||
},
|
||||
}
|
||||
})
|
||||
: processedNodes
|
||||
collaborationManager.setNodes([], resolvedNodes)
|
||||
return resolvedNodes
|
||||
}
|
||||
return []
|
||||
}, [data])
|
||||
}, [data, isSandboxed])
|
||||
|
||||
const edgesData = useMemo(() => {
|
||||
if (data) {
|
||||
@ -304,7 +323,7 @@ const WorkflowAppWithAdditionalContext = () => {
|
||||
}, [replayRunId, workflowStore, getWorkflowRunAndTraceUrl])
|
||||
|
||||
const isDataReady = !(!data || isLoading || isLoadingCurrentWorkspace || !currentWorkspace.id)
|
||||
const sandboxEnabled = data?.features?.sandbox?.enabled === true
|
||||
const sandboxEnabled = isSandboxFeatureEnabled
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDataReady || !appId)
|
||||
|
||||
Reference in New Issue
Block a user