mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-03 00:40:38 +08:00
feat: add last run store
This commit is contained in:
parent
379d382914
commit
ea40cf5bcc
@ -102,6 +102,7 @@ import Confirm from '@/app/components/base/confirm'
|
|||||||
import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants'
|
import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants'
|
||||||
import { fetchFileUploadConfig } from '@/service/common'
|
import { fetchFileUploadConfig } from '@/service/common'
|
||||||
import DatasetsDetailProvider from './datasets-detail-store/provider'
|
import DatasetsDetailProvider from './datasets-detail-store/provider'
|
||||||
|
import LastRunProvider from './last-run-store/provider'
|
||||||
import CurrentVarsProvider from './current-vars-store/provider'
|
import CurrentVarsProvider from './current-vars-store/provider'
|
||||||
|
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
@ -454,13 +455,15 @@ const WorkflowWrap = memo(() => {
|
|||||||
edges={edgesData} >
|
edges={edgesData} >
|
||||||
<FeaturesProvider features={initialFeatures}>
|
<FeaturesProvider features={initialFeatures}>
|
||||||
<DatasetsDetailProvider nodes={nodesData}>
|
<DatasetsDetailProvider nodes={nodesData}>
|
||||||
<CurrentVarsProvider>
|
<LastRunProvider>
|
||||||
<Workflow
|
<CurrentVarsProvider>
|
||||||
nodes={nodesData}
|
<Workflow
|
||||||
edges={edgesData}
|
nodes={nodesData}
|
||||||
viewport={data?.graph.viewport}
|
edges={edgesData}
|
||||||
/>
|
viewport={data?.graph.viewport}
|
||||||
</CurrentVarsProvider>
|
/>
|
||||||
|
</CurrentVarsProvider>
|
||||||
|
</LastRunProvider>
|
||||||
</DatasetsDetailProvider>
|
</DatasetsDetailProvider>
|
||||||
</FeaturesProvider>
|
</FeaturesProvider>
|
||||||
</WorkflowHistoryProvider>
|
</WorkflowHistoryProvider>
|
||||||
|
30
web/app/components/workflow/last-run-store/provider.tsx
Normal file
30
web/app/components/workflow/last-run-store/provider.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import type { FC } from 'react'
|
||||||
|
import { createContext, useRef } from 'react'
|
||||||
|
import { createLastRunStore } from './store'
|
||||||
|
|
||||||
|
type LastRunStoreApi = ReturnType<typeof createLastRunStore>
|
||||||
|
|
||||||
|
type LastRunContextType = LastRunStoreApi | undefined
|
||||||
|
|
||||||
|
export const LastRunContext = createContext<LastRunContextType>(undefined)
|
||||||
|
|
||||||
|
type LastRunProviderProps = {
|
||||||
|
children: React.ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
const LastRunProvider: FC<LastRunProviderProps> = ({
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
const storeRef = useRef<LastRunStoreApi>()
|
||||||
|
|
||||||
|
if (!storeRef.current)
|
||||||
|
storeRef.current = createLastRunStore()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LastRunContext.Provider value={storeRef.current!}>
|
||||||
|
{children}
|
||||||
|
</LastRunContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LastRunProvider
|
67
web/app/components/workflow/last-run-store/store.ts
Normal file
67
web/app/components/workflow/last-run-store/store.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import { useContext } from 'react'
|
||||||
|
import { createStore, useStore } from 'zustand'
|
||||||
|
import { LastRunContext } from './provider'
|
||||||
|
|
||||||
|
type NodeInfo = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
vars: {
|
||||||
|
key: string
|
||||||
|
type: string
|
||||||
|
value: any
|
||||||
|
}[]
|
||||||
|
} & {
|
||||||
|
input: Record<string, any>
|
||||||
|
output: Record<string, any>
|
||||||
|
}
|
||||||
|
|
||||||
|
type LastRunState = {
|
||||||
|
nodes: NodeInfo[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type LastRunActions = {
|
||||||
|
setInfos: (vars: NodeInfo[]) => void
|
||||||
|
getInfos: () => NodeInfo[]
|
||||||
|
getNodeInfo: (nodeId: string) => NodeInfo | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
type LastRunStore = LastRunState & LastRunActions
|
||||||
|
|
||||||
|
export const createLastRunStore = () => {
|
||||||
|
return createStore<LastRunStore>((set, get) => ({
|
||||||
|
nodes: [{
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
type: '',
|
||||||
|
vars: [],
|
||||||
|
input: {},
|
||||||
|
output: {},
|
||||||
|
}],
|
||||||
|
setInfos: (vars) => {
|
||||||
|
set(() => ({
|
||||||
|
nodes: vars,
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
getInfos: () => {
|
||||||
|
return get().nodes
|
||||||
|
},
|
||||||
|
clearVars: () => {
|
||||||
|
set(() => ({
|
||||||
|
nodes: [],
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
getNodeInfo: (nodeId) => {
|
||||||
|
const nodes = get().nodes
|
||||||
|
return nodes.find(node => node.id === nodeId)
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useLastRunStore = <T>(selector: (state: LastRunStore) => T): T => {
|
||||||
|
const store = useContext(LastRunContext)
|
||||||
|
if (!store)
|
||||||
|
throw new Error('Missing LastRunContext.Provider in the tree')
|
||||||
|
|
||||||
|
return useStore(store, selector)
|
||||||
|
}
|
@ -21,6 +21,7 @@ import ResultPanel from '@/app/components/workflow/run/result-panel'
|
|||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||||
import { useCurrentVarsStore } from '../../current-vars-store/store'
|
import { useCurrentVarsStore } from '../../current-vars-store/store'
|
||||||
|
import { useLastRunStore } from '../../last-run-store/store'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.llm'
|
const i18nPrefix = 'workflow.nodes.llm'
|
||||||
|
|
||||||
@ -30,7 +31,8 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const currentVars = useCurrentVarsStore(state => state.getVars())
|
const currentVars = useCurrentVarsStore(state => state.getVars())
|
||||||
console.log(currentVars)
|
const lastRunInfo = useLastRunStore(state => state.getInfos())
|
||||||
|
console.log(currentVars, lastRunInfo)
|
||||||
const {
|
const {
|
||||||
readOnly,
|
readOnly,
|
||||||
inputs,
|
inputs,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user