feat: invalidate sandbox files cache on workflow/chatflow run completion

Add useInvalidateSandboxFiles hook and call it alongside
fetchInspectVars/invalidAllLastRun so the Artifacts tab refreshes
automatically when a chatflow preview or workflow debug run finishes.
This commit is contained in:
yyh
2026-02-03 16:47:05 +08:00
parent 19a5aee38e
commit 0fcddfe9a5
3 changed files with 19 additions and 3 deletions

View File

@ -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 = () => {

View File

@ -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,
])

View File

@ -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) => {