diff --git a/web/app/components/workflow-app/hooks/use-workflow-run.ts b/web/app/components/workflow-app/hooks/use-workflow-run.ts index 7628e685e2..88249dc7f5 100644 --- a/web/app/components/workflow-app/hooks/use-workflow-run.ts +++ b/web/app/components/workflow-app/hooks/use-workflow-run.ts @@ -23,6 +23,7 @@ import { useWorkflowStore } from '@/app/components/workflow/store' import { WorkflowRunningStatus } from '@/app/components/workflow/types' import { handleStream, post, ssePost } from '@/service/base' import { ContentType } from '@/service/fetch' +import { useInvalidateSandboxFiles } from '@/service/use-sandbox-file' import { useInvalidAllLastRun } from '@/service/use-workflow' import { stopWorkflowRun } from '@/service/workflow' import { AppModeEnum } from '@/types/app' @@ -66,6 +67,7 @@ export const useWorkflowRun = () => { const configsMap = useConfigsMap() const { flowId, flowType } = configsMap const invalidAllLastRun = useInvalidAllLastRun(flowType, flowId) + const invalidateSandboxFiles = useInvalidateSandboxFiles() const { fetchInspectVars } = useSetWorkflowVarsWithValue({ ...configsMap, @@ -392,6 +394,7 @@ export const useWorkflowRun = () => { if (isInWorkflowDebug) { fetchInspectVars({}) invalidAllLastRun() + invalidateSandboxFiles() } }, onNodeStarted: (params) => { @@ -667,7 +670,7 @@ export const useWorkflowRun = () => { }, }, ) - }, [store, doSyncWorkflowDraft, workflowStore, pathname, handleWorkflowStarted, handleWorkflowFinished, fetchInspectVars, invalidAllLastRun, handleWorkflowFailed, handleWorkflowNodeStarted, handleWorkflowNodeFinished, handleWorkflowNodeIterationStarted, handleWorkflowNodeIterationNext, handleWorkflowNodeIterationFinished, handleWorkflowNodeLoopStarted, handleWorkflowNodeLoopNext, handleWorkflowNodeLoopFinished, handleWorkflowNodeRetry, handleWorkflowAgentLog, handleWorkflowTextChunk, handleWorkflowTextReplace]) + }, [store, doSyncWorkflowDraft, workflowStore, pathname, handleWorkflowStarted, handleWorkflowFinished, fetchInspectVars, invalidAllLastRun, invalidateSandboxFiles, handleWorkflowFailed, handleWorkflowNodeStarted, handleWorkflowNodeFinished, handleWorkflowNodeIterationStarted, handleWorkflowNodeIterationNext, handleWorkflowNodeIterationFinished, handleWorkflowNodeLoopStarted, handleWorkflowNodeLoopNext, handleWorkflowNodeLoopFinished, handleWorkflowNodeRetry, handleWorkflowAgentLog, handleWorkflowTextChunk, handleWorkflowTextReplace]) const handleStopRun = useCallback((taskId: string) => { const setStoppedState = () => { diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks/use-chat-message-sender.ts b/web/app/components/workflow/panel/debug-and-preview/hooks/use-chat-message-sender.ts index c313e31058..8f43a5e1ed 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks/use-chat-message-sender.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks/use-chat-message-sender.ts @@ -8,6 +8,7 @@ import { v4 as uuidV4 } from 'uuid' import { getProcessedInputs } from '@/app/components/base/chat/chat/utils' import { getProcessedFiles, getProcessedFilesFromResponse } from '@/app/components/base/file-uploader/utils' import { useToastContext } from '@/app/components/base/toast' +import { useInvalidateSandboxFiles } from '@/service/use-sandbox-file' import { useInvalidAllLastRun } from '@/service/use-workflow' import { TransferMethod } from '@/types/app' import { useSetWorkflowVarsWithValue, useWorkflowRun } from '../../../hooks' @@ -44,6 +45,7 @@ export function useChatMessageSender({ const configsMap = useHooksStore(s => s.configsMap) const invalidAllLastRun = useInvalidAllLastRun(configsMap?.flowType, configsMap?.flowId) + const invalidateSandboxFiles = useInvalidateSandboxFiles() const { fetchInspectVars } = useSetWorkflowVarsWithValue() const setConversationId = useStore(s => s.setConversationId) const setTargetMessageId = useStore(s => s.setTargetMessageId) @@ -268,6 +270,7 @@ export function useChatMessageSender({ handleResponding(false) fetchInspectVars({}) invalidAllLastRun() + invalidateSandboxFiles() if (hasError) { if (errorMessage) { @@ -398,6 +401,7 @@ export function useChatMessageSender({ startRun, fetchInspectVars, invalidAllLastRun, + invalidateSandboxFiles, workflowStore, ]) diff --git a/web/service/use-sandbox-file.ts b/web/service/use-sandbox-file.ts index b37ef7fd9c..030205860d 100644 --- a/web/service/use-sandbox-file.ts +++ b/web/service/use-sandbox-file.ts @@ -3,8 +3,8 @@ import type { SandboxFileNode, SandboxFileTreeNode, } from '@/types/sandbox-file' -import { useMutation, useQuery } from '@tanstack/react-query' -import { useMemo } from 'react' +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { useCallback, useMemo } from 'react' import { consoleClient, consoleQuery } from '@/service/client' type UseGetSandboxFilesOptions = { @@ -50,6 +50,15 @@ export function useSandboxFileDownloadUrl( }) } +export function useInvalidateSandboxFiles() { + const queryClient = useQueryClient() + return useCallback(() => { + queryClient.invalidateQueries({ + queryKey: consoleQuery.sandboxFile.listFiles.key(), + }) + }, [queryClient]) +} + export function useDownloadSandboxFile(appId: string | undefined) { return useMutation({ mutationFn: (path: string) => {