mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-06 02:06:05 +08:00
feat: support change run value
This commit is contained in:
parent
da4df45543
commit
9e9f2d11d7
@ -53,6 +53,7 @@ import LastRun from './last-run'
|
||||
import useOneStepRun from '../../hooks/use-one-step-run'
|
||||
import type { PanelExposedType } from '@/types/workflow'
|
||||
import BeforeRunForm from '../before-run-form'
|
||||
import { sleep } from '@/utils'
|
||||
|
||||
type BasePanelProps = {
|
||||
children: ReactNode
|
||||
@ -110,6 +111,8 @@ const BasePanel: FC<BasePanelProps> = ({
|
||||
}, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory])
|
||||
|
||||
const isSupportSingleRun = canRunBySingle(data.type)
|
||||
const childPanelRef = useRef<PanelExposedType>(null)
|
||||
|
||||
const {
|
||||
isShowSingleRun,
|
||||
showSingleRun,
|
||||
@ -119,7 +122,7 @@ const BasePanel: FC<BasePanelProps> = ({
|
||||
handleRun,
|
||||
handleStop,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
setRunInputData: doSetRunInputData,
|
||||
runResult,
|
||||
getInputVars,
|
||||
} = useOneStepRun<typeof data>({
|
||||
@ -127,9 +130,15 @@ const BasePanel: FC<BasePanelProps> = ({
|
||||
data,
|
||||
defaultRunInputData: {},
|
||||
})
|
||||
const childPanelRef = useRef<PanelExposedType>(null)
|
||||
const [singleRunParams, setSingleRunParams] = useState<PanelExposedType['singleRunParams'] | undefined>(undefined)
|
||||
|
||||
const setRunInputData = useCallback(async (data: Record<string, any>) => {
|
||||
doSetRunInputData(data)
|
||||
// console.log(childPanelRef.current?.singleRunParams)
|
||||
await sleep(0) // wait for childPanelRef.current?.singleRunParams refresh
|
||||
setSingleRunParams(childPanelRef.current?.singleRunParams)
|
||||
}, [doSetRunInputData])
|
||||
|
||||
const [tabType, setTabType] = useState<TabType>(TabType.settings)
|
||||
const hasLastRunData = true // TODO: add disabled logic
|
||||
|
||||
@ -217,7 +226,17 @@ const BasePanel: FC<BasePanelProps> = ({
|
||||
{tabType === TabType.settings && (
|
||||
<>
|
||||
<div>
|
||||
{cloneElement(children as any, { id, data, ref: childPanelRef })}
|
||||
{cloneElement(children as any, {
|
||||
id,
|
||||
data,
|
||||
panelProps: {
|
||||
getInputVars,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
runResult,
|
||||
},
|
||||
ref: childPanelRef,
|
||||
})}
|
||||
</div>
|
||||
<Split />
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { forwardRef, memo, useImperativeHandle, useMemo } from 'react'
|
||||
import { forwardRef, memo, useImperativeHandle } from 'react'
|
||||
import type { NodePanelProps } from '../../types'
|
||||
import { AgentFeature, type AgentNodeType } from './types'
|
||||
import Field from '../_base/components/field'
|
||||
@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next'
|
||||
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
||||
import type { StrategyParamItem } from '@/app/components/plugins/types'
|
||||
import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import formatTracing from '@/app/components/workflow/run/utils/format-log'
|
||||
import { useLogs } from '@/app/components/workflow/run/hooks'
|
||||
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
|
||||
import { toType } from '@/app/components/tools/utils/to-form-schema'
|
||||
@ -28,6 +27,10 @@ export function strategyParamToCredientialForm(param: StrategyParamItem): Creden
|
||||
}
|
||||
|
||||
const AgentPanel = forwardRef<PanelExposedType, NodePanelProps<AgentNodeType>>((props, ref) => {
|
||||
const {
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
} = props.panelProps
|
||||
const {
|
||||
inputs,
|
||||
setInputs,
|
||||
@ -38,28 +41,21 @@ const AgentPanel = forwardRef<PanelExposedType, NodePanelProps<AgentNodeType>>((
|
||||
availableNodesWithParent,
|
||||
availableVars,
|
||||
readOnly,
|
||||
runResult,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
varInputs,
|
||||
outputSchema,
|
||||
handleMemoryChange,
|
||||
} = useConfig(props.id, props.data)
|
||||
} = useConfig(props.id, props.data, props.panelProps)
|
||||
const { t } = useTranslation()
|
||||
const nodeInfo = useMemo(() => {
|
||||
if (!runResult)
|
||||
return
|
||||
return formatTracing([runResult], t)[0]
|
||||
}, [runResult, t])
|
||||
|
||||
const logsParams = useLogs()
|
||||
const singleRunForms = (() => {
|
||||
const forms: FormProps[] = []
|
||||
|
||||
if (varInputs.length > 0) {
|
||||
if (varInputs!.length > 0) {
|
||||
forms.push(
|
||||
{
|
||||
label: t(`${i18nPrefix}.singleRun.variable`)!,
|
||||
inputs: varInputs,
|
||||
inputs: varInputs!,
|
||||
values: runInputData,
|
||||
onChange: setRunInputData,
|
||||
},
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { useStrategyProviderDetail } from '@/service/use-strategy'
|
||||
import useNodeCrud from '../_base/hooks/use-node-crud'
|
||||
import useVarList from '../_base/hooks/use-var-list'
|
||||
import useOneStepRun from '../_base/hooks/use-one-step-run'
|
||||
import type { AgentNodeType } from './types'
|
||||
import {
|
||||
useIsChatMode,
|
||||
@ -14,6 +13,7 @@ import type { Memory, Var } from '../../types'
|
||||
import { VarType as VarKindType } from '../../types'
|
||||
import useAvailableVarList from '../_base/hooks/use-available-var-list'
|
||||
import produce from 'immer'
|
||||
import type { PanelProps } from '@/types/workflow'
|
||||
|
||||
export type StrategyStatus = {
|
||||
plugin: {
|
||||
@ -63,7 +63,9 @@ export const useStrategyInfo = (
|
||||
}
|
||||
}
|
||||
|
||||
const useConfig = (id: string, payload: AgentNodeType) => {
|
||||
const useConfig = (id: string, payload: AgentNodeType, panelProps?: PanelProps) => {
|
||||
const getInputVars = panelProps?.getInputVars
|
||||
|
||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||
const { inputs, setInputs } = useNodeCrud<AgentNodeType>(id, payload)
|
||||
// variables
|
||||
@ -130,23 +132,7 @@ const useConfig = (id: string, payload: AgentNodeType) => {
|
||||
})
|
||||
|
||||
// single run
|
||||
const {
|
||||
isShowSingleRun,
|
||||
showSingleRun,
|
||||
hideSingleRun,
|
||||
toVarInputs,
|
||||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
runResult,
|
||||
getInputVars,
|
||||
} = useOneStepRun<AgentNodeType>({
|
||||
id,
|
||||
data: inputs,
|
||||
defaultRunInputData: {},
|
||||
})
|
||||
|
||||
const allVarStrArr = (() => {
|
||||
const arr = currentStrategy?.parameters.filter(item => item.type === 'string').map((item) => {
|
||||
return formData[item.name]
|
||||
@ -155,7 +141,7 @@ const useConfig = (id: string, payload: AgentNodeType) => {
|
||||
return arr
|
||||
})()
|
||||
const varInputs = (() => {
|
||||
const vars = getInputVars(allVarStrArr)
|
||||
const vars = getInputVars?.(allVarStrArr)
|
||||
|
||||
return vars
|
||||
})()
|
||||
@ -198,17 +184,6 @@ const useConfig = (id: string, payload: AgentNodeType) => {
|
||||
pluginDetail: pluginDetail.data?.plugins.at(0),
|
||||
availableVars,
|
||||
availableNodesWithParent,
|
||||
|
||||
isShowSingleRun,
|
||||
showSingleRun,
|
||||
hideSingleRun,
|
||||
toVarInputs,
|
||||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
runResult,
|
||||
varInputs,
|
||||
outputSchema,
|
||||
handleMemoryChange,
|
||||
|
@ -6,7 +6,7 @@ import type {
|
||||
import type { Resolution, TransferMethod } from '@/types/app'
|
||||
import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types'
|
||||
import type { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
|
||||
import type { FileResponse, NodeTracing } from '@/types/workflow'
|
||||
import type { FileResponse, NodeTracing, PanelProps } from '@/types/workflow'
|
||||
import type { Collection, Tool } from '@/app/components/tools/types'
|
||||
import type { ChatVarType } from '@/app/components/workflow/panel/chat-variable-panel/type'
|
||||
import type {
|
||||
@ -114,6 +114,7 @@ export type NodeProps<T = unknown> = { id: string; data: CommonNodeType<T> }
|
||||
export type NodePanelProps<T> = {
|
||||
id: string
|
||||
data: CommonNodeType<T>
|
||||
panelProps: PanelProps
|
||||
}
|
||||
export type Edge = ReactFlowEdge<CommonEdgeType>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { Viewport } from 'reactflow'
|
||||
import type { BlockEnum, ConversationVariable, Edge, EnvironmentVariable, Node } from '@/app/components/workflow/types'
|
||||
import type { BlockEnum, ConversationVariable, Edge, EnvironmentVariable, InputVar, Node } from '@/app/components/workflow/types'
|
||||
import type { TransferMethod } from '@/types/app'
|
||||
import type { ErrorHandleTypeEnum } from '@/app/components/workflow/nodes/_base/components/error-handle/types'
|
||||
import type { BeforeRunFormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form'
|
||||
@ -357,3 +357,10 @@ export type UpdateWorkflowParams = {
|
||||
export type PanelExposedType = {
|
||||
singleRunParams: Pick<BeforeRunFormProps, 'forms'> & Partial<SpecialResultPanelProps>
|
||||
}
|
||||
|
||||
export type PanelProps = {
|
||||
getInputVars: (textList: string[]) => InputVar[]
|
||||
runInputData: Record<string, any>
|
||||
setRunInputData: (data: Record<string, any>) => void
|
||||
runResult: any
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user