fix: Hide Agent node in sandboxed apps and relabel LLM

This commit is contained in:
zhsama
2026-02-07 16:07:21 +08:00
parent e9bff0b7b7
commit e528112394
6 changed files with 29 additions and 13 deletions

View File

@ -3,6 +3,7 @@ import type { CommonNodeType, NodeDefault, NodeDefaultBase } from '@/app/compone
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 { 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'
@ -17,6 +18,7 @@ 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 docLink = useDocLink()
const startNodeMetaData = useMemo(() => ({
@ -28,7 +30,9 @@ export const useAvailableNodesMetaData = () => {
}), [isChatMode])
const mergedNodesMetaData = useMemo(() => [
...WORKFLOW_COMMON_NODES,
...(isSandboxed
? WORKFLOW_COMMON_NODES.filter(node => node.metaData.type !== BlockEnum.Agent)
: WORKFLOW_COMMON_NODES),
startNodeMetaData,
...(
isChatMode
@ -40,7 +44,7 @@ export const useAvailableNodesMetaData = () => {
TriggerPluginDefault,
]
),
] as AvailableNodesMetaData['nodes'], [isChatMode, startNodeMetaData])
] as AvailableNodesMetaData['nodes'], [isChatMode, isSandboxed, startNodeMetaData])
const availableNodesMetaData = useMemo<NodeDefaultBase[]>(() => {
const toNodeDefaultBase = (
@ -69,7 +73,9 @@ export const useAvailableNodesMetaData = () => {
// normalize per-node defaults into a shared metadata shape.
const typedNode = node as NodeDefault<CommonNodeType>
const { metaData } = typedNode
const title = t(`blocks.${metaData.type}`, { ns: 'workflow' })
const title = isSandboxed && metaData.type === BlockEnum.LLM
? t('blocks.agent', { ns: 'workflow' })
: t(`blocks.${metaData.type}` as const, { ns: 'workflow' })
const description = t(`blocksAbout.${metaData.type}`, { ns: 'workflow' })
const helpLinkPath = `/use-dify/nodes/${metaData.helpLinkUri}` as DocPathWithoutLang
return toNodeDefaultBase(typedNode, {
@ -83,7 +89,7 @@ export const useAvailableNodesMetaData = () => {
title,
})
})
}, [mergedNodesMetaData, t, docLink])
}, [mergedNodesMetaData, t, docLink, isSandboxed])
const availableNodesMetaDataMap = useMemo(() => availableNodesMetaData.reduce((acc, node) => {
acc![node.metaData.type] = node

View File

@ -1,5 +1,6 @@
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
import { useTranslation } from 'react-i18next'
import { useStore as useAppStore } from '@/app/components/app/store'
import {
NODE_WIDTH_X_OFFSET,
START_INITIAL_POSITION,
@ -12,6 +13,7 @@ import { useIsChatMode } from './use-is-chat-mode'
export const useWorkflowTemplate = () => {
const isChatMode = useIsChatMode()
const isSandboxed = useAppStore(s => s.appDetail?.runtime_type === 'sandboxed')
const { t } = useTranslation()
const { newNode: startNode } = generateNewNode({
@ -24,6 +26,10 @@ export const useWorkflowTemplate = () => {
})
if (isChatMode) {
const llmTitle = isSandboxed
? t('blocks.agent', { ns: 'workflow' })
: t(`blocks.${llmDefault.metaData.type}` as const, { ns: 'workflow' })
const { newNode: llmNode } = generateNewNode({
id: 'llm',
data: {
@ -34,7 +40,7 @@ export const useWorkflowTemplate = () => {
},
selected: true,
type: llmDefault.metaData.type,
title: t(`blocks.${llmDefault.metaData.type}`, { ns: 'workflow' }),
title: llmTitle,
},
position: {
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET,

View File

@ -673,11 +673,11 @@
"nodes.llm.addContext": "Add Context",
"nodes.llm.addMessage": "Add Message",
"nodes.llm.advancedSettings": "Advanced Settings",
"nodes.llm.computerUse.disabledByStructuredOutput": "Computer Use is disabled when Structured Output is enabled.",
"nodes.llm.computerUse.disabledByStructuredOutput": "Agent mode is disabled when Structured Output is enabled.",
"nodes.llm.computerUse.referenceTools": "Reference Tools",
"nodes.llm.computerUse.referenceToolsEmpty": "Tools referenced in the prompt will appear here",
"nodes.llm.computerUse.title": "Computer Use",
"nodes.llm.computerUse.tooltip": "Manage the runtime filesystem and tool access for your agent.",
"nodes.llm.computerUse.title": "Agent mode",
"nodes.llm.computerUse.tooltip": "Manage the runtime filesystem and tool access in Agent mode.",
"nodes.llm.context": "context",
"nodes.llm.contextBlock": "Context Block",
"nodes.llm.contextMissing": "Missing context from node {{nodeName}}. Please select a context variable.",

View File

@ -648,7 +648,9 @@
"nodes.listFilter.selectVariableKeyPlaceholder": "サブ変数キーを選択する",
"nodes.llm.addContext": "コンテキスト追加",
"nodes.llm.addMessage": "メッセージ追加",
"nodes.llm.computerUse.disabledByStructuredOutput": "構造化出力を有効にすると、コンピュータ使用は無効になります。",
"nodes.llm.computerUse.disabledByStructuredOutput": "構造化出力を有効にすると、Agent mode は無効になります。",
"nodes.llm.computerUse.title": "Agent mode",
"nodes.llm.computerUse.tooltip": "Agent mode で実行時ファイルシステムとツールアクセスを管理します。",
"nodes.llm.context": "コンテキスト",
"nodes.llm.contextBlock": "コンテキストブロック",
"nodes.llm.contextMissing": "ノード「{{nodeName}}」のコンテキストがありません。コンテキスト変数を選択してください。",

View File

@ -666,11 +666,11 @@
"nodes.listFilter.selectVariableKeyPlaceholder": "选择子变量的 Key",
"nodes.llm.addContext": "添加上下文",
"nodes.llm.addMessage": "添加消息",
"nodes.llm.computerUse.disabledByStructuredOutput": "启用结构化输出时,将禁用计算机使用。",
"nodes.llm.computerUse.disabledByStructuredOutput": "启用结构化输出时,将禁用 Agent 模式。",
"nodes.llm.computerUse.referenceTools": "引用工具",
"nodes.llm.computerUse.referenceToolsEmpty": "提示词中引用的工具会显示在这里",
"nodes.llm.computerUse.title": "计算机使用",
"nodes.llm.computerUse.tooltip": "管理代理的运行时文件系统与工具访问权限。",
"nodes.llm.computerUse.title": "Agent 模式",
"nodes.llm.computerUse.tooltip": "管理 Agent 模式下的运行时文件系统与工具访问权限。",
"nodes.llm.context": "上下文",
"nodes.llm.contextBlock": "上下文块",
"nodes.llm.contextMissing": "缺少前序节点「{{nodeName}}」的上下文,请先选择上下文变量。",

View File

@ -648,8 +648,10 @@
"nodes.listFilter.selectVariableKeyPlaceholder": "Select sub variable key選擇子變數鍵",
"nodes.llm.addContext": "新增上下文",
"nodes.llm.addMessage": "新增消息",
"nodes.llm.computerUse.disabledByStructuredOutput": "啟用結構化輸出時,將停用電腦使用。",
"nodes.llm.computerUse.disabledByStructuredOutput": "啟用結構化輸出時,將停用 Agent 模式。",
"nodes.llm.computerUse.referenceToolsEmpty": "提示詞中引用的工具會顯示在這裡",
"nodes.llm.computerUse.title": "Agent 模式",
"nodes.llm.computerUse.tooltip": "管理 Agent 模式下的執行階段檔案系統與工具存取權限。",
"nodes.llm.context": "上下文",
"nodes.llm.contextBlock": "上下文區塊",
"nodes.llm.contextMissing": "缺少前序節點「{{nodeName}}」的上下文,請先選擇上下文變數。",