From ed737beb4a0b683de839be7e4c4f8e7086ae93f1 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 18 Jul 2025 17:38:17 +0800 Subject: [PATCH] chore: can set to value --- .../config/automatic/get-automatic-res.tsx | 21 +++++++++++-------- .../configuration/config/automatic/result.tsx | 15 +++++++------ .../config/automatic/use-gen-data.ts | 6 +++--- .../llm/components/config-prompt-item.tsx | 4 +++- .../nodes/llm/components/config-prompt.tsx | 1 + 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx b/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx index b9ac9e5ce2..7e4cf634b9 100644 --- a/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx +++ b/web/app/components/app/configuration/config/automatic/get-automatic-res.tsx @@ -165,17 +165,17 @@ const GetAutomaticRes: FC = ({ } const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false) const storageKey = `${flowId}${isBasicMode ? '' : `-${nodeId}`}` - const { versions, addVersion, current } = useGenData({ + const { addVersion, current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({ storageKey, }) - useEffect(() => { - // if (!versions.length) { - addVersion({ - modified: 'ddd', - }) - // } - }, []) + // useEffect(() => { + // // if (!versions.length) { + // addVersion({ + // modified: 'ddd', + // }) + // // } + // }, []) useEffect(() => { if (defaultModel) { @@ -387,7 +387,10 @@ const GetAutomaticRes: FC = ({ {
diff --git a/web/app/components/app/configuration/config/automatic/result.tsx b/web/app/components/app/configuration/config/automatic/result.tsx index 262a489311..858003cdb5 100644 --- a/web/app/components/app/configuration/config/automatic/result.tsx +++ b/web/app/components/app/configuration/config/automatic/result.tsx @@ -5,25 +5,28 @@ import { useTranslation } from 'react-i18next' import { GeneratorType } from './types' import PromptToast from './prompt-toast' import Button from '@/app/components/base/button' -import useGenData from './use-gen-data' import VersionSelector from './version-selector' +import type { GenRes } from '@/service/debug' type Props = { - storageKey: string + current: GenRes + currentVersionIndex: number + setCurrentVersionIndex: (index: number) => void + versions: GenRes[] onApply: () => void generatorType: GeneratorType } const Result: FC = ({ - storageKey, + current, + currentVersionIndex, + setCurrentVersionIndex, + versions, onApply, generatorType, }) => { const { t } = useTranslation() const isGeneratorPrompt = generatorType === GeneratorType.prompt - const { current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({ - storageKey, - }) return (
diff --git a/web/app/components/app/configuration/config/automatic/use-gen-data.ts b/web/app/components/app/configuration/config/automatic/use-gen-data.ts index 8da4ba2c6e..521d2ad7f0 100644 --- a/web/app/components/app/configuration/config/automatic/use-gen-data.ts +++ b/web/app/components/app/configuration/config/automatic/use-gen-data.ts @@ -15,14 +15,14 @@ const useGenData = ({ storageKey }: Params) => { defaultValue: 0, }) - const current = versions[currentVersionIndex] + const current = versions?.[currentVersionIndex || 0] const addVersion = useCallback((version: GenRes) => { - setCurrentVersionIndex(() => versions.length) + setCurrentVersionIndex(() => versions?.length || 0) setVersions((prev) => { return [...prev!, version] }) - }, [setVersions, setCurrentVersionIndex, versions.length]) + }, [setVersions, setCurrentVersionIndex, versions?.length]) return { versions, diff --git a/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx b/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx index 91e25a2436..ff571af9d2 100644 --- a/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx +++ b/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx @@ -19,6 +19,7 @@ type Props = { canNotChooseSystemRole?: boolean readOnly: boolean id: string + nodeId: string canRemove: boolean isChatModel: boolean isChatApp: boolean @@ -63,6 +64,7 @@ const ConfigPromptItem: FC = ({ canNotChooseSystemRole, readOnly, id, + nodeId, canRemove, handleChatModeMessageRoleChange, isChatModel, @@ -136,7 +138,7 @@ const ConfigPromptItem: FC = ({ hasSetBlockStatus={hasSetBlockStatus} nodesOutputVars={availableVars} availableNodes={availableNodes} - nodeId={id} + nodeId={nodeId} isSupportPromptGenerator={payload.role === PromptRole.system} onGenerated={handleGenerated} modelConfig={modelConfig} diff --git a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx index eb14f302e0..b8a68f364f 100644 --- a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx +++ b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx @@ -188,6 +188,7 @@ const ConfigPrompt: FC = ({ canRemove={payload.length > 1 && !(index === 0 && item.role === PromptRole.system)} readOnly={readOnly} id={item.id!} + nodeId={nodeId} handleChatModeMessageRoleChange={handleChatModeMessageRoleChange(index)} isChatModel={isChatModel} isChatApp={isChatApp}