From d42b340f2fefa5a0a1badc281cff3a690969cb4b Mon Sep 17 00:00:00 2001 From: "G.Wood-Sun" Date: Fri, 20 Jun 2025 17:01:08 +0800 Subject: [PATCH] feat: add config for max-tree-depth --- web/.env.example | 2 ++ web/app/components/workflow/constants.ts | 1 - web/app/components/workflow/hooks/use-checklist.ts | 2 +- web/app/layout.tsx | 1 + web/config/index.ts | 9 +++++++++ web/docker/entrypoint.sh | 1 + 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/web/.env.example b/web/.env.example index 78b4f33e8c..c30064ffed 100644 --- a/web/.env.example +++ b/web/.env.example @@ -56,3 +56,5 @@ NEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER=true NEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL=true NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL=true +# The maximum number of tree node depth for workflow +NEXT_PUBLIC_MAX_TREE_DEPTH=50 diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts index cdfd963cfa..b7432f1203 100644 --- a/web/app/components/workflow/constants.ts +++ b/web/app/components/workflow/constants.ts @@ -408,7 +408,6 @@ export const NODE_WIDTH = 240 export const X_OFFSET = 60 export const NODE_WIDTH_X_OFFSET = NODE_WIDTH + X_OFFSET export const Y_OFFSET = 39 -export const MAX_TREE_DEPTH = 50 export const START_INITIAL_POSITION = { x: 80, y: 282 } export const AUTO_LAYOUT_OFFSET = { x: -42, diff --git a/web/app/components/workflow/hooks/use-checklist.ts b/web/app/components/workflow/hooks/use-checklist.ts index c1b0189b8b..200bee1d26 100644 --- a/web/app/components/workflow/hooks/use-checklist.ts +++ b/web/app/components/workflow/hooks/use-checklist.ts @@ -18,7 +18,6 @@ import { } from '../utils' import { CUSTOM_NODE, - MAX_TREE_DEPTH, } from '../constants' import type { ToolNodeType } from '../nodes/tool/types' import { useIsChatMode } from './use-workflow' @@ -33,6 +32,7 @@ import { useDatasetsDetailStore } from '../datasets-detail-store/store' import type { KnowledgeRetrievalNodeType } from '../nodes/knowledge-retrieval/types' import type { DataSet } from '@/models/datasets' import { fetchDatasets } from '@/service/datasets' +import { MAX_TREE_DEPTH } from '@/config' export const useChecklist = (nodes: Node[], edges: Edge[]) => { const { t } = useTranslation() diff --git a/web/app/layout.tsx b/web/app/layout.tsx index e39b4f3a1b..57210f98bf 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -54,6 +54,7 @@ const LocaleLayout = async ({ data-public-enable-website-jinareader={process.env.NEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER} data-public-enable-website-firecrawl={process.env.NEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL} data-public-enable-website-watercrawl={process.env.NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL} + data-public-max-tree-depth={process.env.NEXT_PUBLIC_MAX_TREE_DEPTH} > diff --git a/web/config/index.ts b/web/config/index.ts index e8aa404bec..2599382115 100644 --- a/web/config/index.ts +++ b/web/config/index.ts @@ -323,3 +323,12 @@ enableWebsiteWaterCrawl = getBooleanConfig(process.env.NEXT_PUBLIC_ENABLE_WEBSIT export const ENABLE_WEBSITE_JINAREADER = enableWebsiteJinaReader export const ENABLE_WEBSITE_FIRECRAWL = enableWebsiteFireCrawl export const ENABLE_WEBSITE_WATERCRAWL = enableWebsiteWaterCrawl + +let defaultMaxTreeDepth = 50 + +if (process.env.NEXT_PUBLIC_MAX_TREE_DEPTH && process.env.NEXT_PUBLIC_MAX_TREE_DEPTH !== '') + defaultMaxTreeDepth = Number.parseInt(process.env.NEXT_PUBLIC_MAX_TREE_DEPTH) +else if (globalThis.document?.body?.getAttribute('data-public-max-tree-depth') && globalThis.document.body.getAttribute('data-public-max-tree-depth') !== '') + defaultMaxTreeDepth = Number.parseInt(globalThis.document.body.getAttribute('data-public-max-tree-depth') as string) + +export const MAX_TREE_DEPTH = defaultMaxTreeDepth diff --git a/web/docker/entrypoint.sh b/web/docker/entrypoint.sh index 59e9c472b3..c9acbdd422 100755 --- a/web/docker/entrypoint.sh +++ b/web/docker/entrypoint.sh @@ -35,4 +35,5 @@ export NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL=${ENABLE_WEBSITE_WATERCRAWL:-true} export NEXT_PUBLIC_LOOP_NODE_MAX_COUNT=${LOOP_NODE_MAX_COUNT} export NEXT_PUBLIC_MAX_PARALLEL_LIMIT=${MAX_PARALLEL_LIMIT} export NEXT_PUBLIC_MAX_ITERATIONS_NUM=${MAX_ITERATIONS_NUM} +export NEXT_PUBLIC_MAX_TREE_DEPTH=${MAX_TREE_DEPTH} pm2 start /app/web/server.js --name dify-web --cwd /app/web -i ${PM2_INSTANCES} --no-daemon