feat: add optional query parameter to PostWorkflowDebugProps and remove realmode from ModuleDispatchProps
This commit is contained in:
@@ -29,6 +29,16 @@ import { WorkflowEventContext } from '../../../context/workflowEventContext';
|
||||
import MyImage from '@fastgpt/web/components/common/Image/MyImage';
|
||||
import MyIconButton from '@fastgpt/web/components/common/Icon/button';
|
||||
import UseGuideModal from '@/components/common/Modal/UseGuideModal';
|
||||
import {
|
||||
RenderUserSelectInteractive,
|
||||
RenderUserFormInteractive
|
||||
} from '@/components/core/chat/components/InteractiveComponents';
|
||||
import {
|
||||
InteractiveBasicType,
|
||||
UserInputInteractive,
|
||||
UserSelectInteractive,
|
||||
WorkflowInteractiveResponseType
|
||||
} from '@fastgpt/global/core/workflow/template/system/interactive/type';
|
||||
|
||||
type Props = FlowNodeItemType & {
|
||||
children?: React.ReactNode | React.ReactNode[] | string;
|
||||
@@ -62,6 +72,7 @@ const NodeCard = (props: Props) => {
|
||||
w = 'full',
|
||||
h = 'full',
|
||||
nodeId,
|
||||
flowNodeType,
|
||||
selected,
|
||||
menuForbid,
|
||||
isTool = false,
|
||||
@@ -670,12 +681,60 @@ const NodeDebugResponse = React.memo(function NodeDebugResponse({
|
||||
debugResult: FlowNodeItemType['debugResult'];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const nodeList = useContextSelector(WorkflowContext, (v) => v.nodeList);
|
||||
|
||||
// 获取当前节点
|
||||
const node = useMemo(() => nodeList.find((node) => node.nodeId === nodeId), [nodeList, nodeId]);
|
||||
const firstInteractive = useMemo(() => {
|
||||
if (
|
||||
node &&
|
||||
node.flowNodeType === FlowNodeTypeEnum.userSelect &&
|
||||
!node.debugResult?.response?.userSelectResult
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
node &&
|
||||
node.flowNodeType === FlowNodeTypeEnum.formInput &&
|
||||
!node.debugResult?.response?.formInputResult
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false; // 明确返回值
|
||||
}, [node]);
|
||||
|
||||
const { onChangeNode, onStopNodeDebug, onNextNodeDebug, workflowDebugData } = useContextSelector(
|
||||
WorkflowContext,
|
||||
(v) => v
|
||||
);
|
||||
|
||||
const interactive: UserSelectInteractive | UserInputInteractive | undefined = useMemo(() => {
|
||||
const description = node?.inputs?.find((input) => input.key === 'description')?.value;
|
||||
const userSelectOptions = node?.inputs?.find(
|
||||
(input) => input.key === 'userSelectOptions'
|
||||
)?.value;
|
||||
const formInputForms = node?.inputs?.find((input) => input.key === 'userInputForms')?.value;
|
||||
if (node?.flowNodeType === FlowNodeTypeEnum.userSelect) {
|
||||
return {
|
||||
type: 'userSelect',
|
||||
params: {
|
||||
description,
|
||||
userSelectOptions
|
||||
}
|
||||
};
|
||||
}
|
||||
if (node?.flowNodeType === FlowNodeTypeEnum.formInput) {
|
||||
return {
|
||||
type: 'userInput',
|
||||
params: {
|
||||
description,
|
||||
inputForm: formInputForms
|
||||
}
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}, [node]);
|
||||
|
||||
const { openConfirm, ConfirmModal } = useConfirm({
|
||||
content: t('common:core.workflow.Confirm stop debug')
|
||||
});
|
||||
@@ -784,16 +843,18 @@ const NodeDebugResponse = React.memo(function NodeDebugResponse({
|
||||
{t('common:common.Next Step')}
|
||||
</Button>
|
||||
)}
|
||||
{workflowDebugData?.nextRunNodes && workflowDebugData?.nextRunNodes.length === 0 && (
|
||||
<Button ml={2} size={'sm'} variant={'primary'} onClick={onStopNodeDebug}>
|
||||
{t('common:core.workflow.debug.Done')}
|
||||
</Button>
|
||||
)}
|
||||
{!firstInteractive &&
|
||||
workflowDebugData?.nextRunNodes &&
|
||||
workflowDebugData?.nextRunNodes.length === 0 && (
|
||||
<Button ml={2} size={'sm'} variant={'primary'} onClick={onStopNodeDebug}>
|
||||
{t('common:core.workflow.debug.Done')}
|
||||
</Button>
|
||||
)}
|
||||
</Flex>
|
||||
{/* Response list */}
|
||||
{debugResult.status !== 'skipped' && (
|
||||
<Box borderTop={'base'} mt={1} overflowY={'auto'} minH={'250px'}>
|
||||
{!debugResult.message && !response && (
|
||||
{!debugResult.message && !response && !firstInteractive && (
|
||||
<EmptyTip text={t('common:core.workflow.debug.Not result')} pt={2} pb={5} />
|
||||
)}
|
||||
{debugResult.message && (
|
||||
@@ -801,6 +862,16 @@ const NodeDebugResponse = React.memo(function NodeDebugResponse({
|
||||
{debugResult.message}
|
||||
</Box>
|
||||
)}
|
||||
{firstInteractive && interactive && (
|
||||
<>
|
||||
{interactive.type === 'userSelect' && (
|
||||
<RenderUserSelectInteractive interactive={interactive} nodeId={nodeId} />
|
||||
)}
|
||||
{interactive.type === 'userInput' && (
|
||||
<RenderUserFormInteractive interactive={interactive} nodeId={nodeId} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{response && <WholeResponseContent activeModule={response} />}
|
||||
</Box>
|
||||
)}
|
||||
@@ -809,6 +880,8 @@ const NodeDebugResponse = React.memo(function NodeDebugResponse({
|
||||
</>
|
||||
) : null;
|
||||
}, [
|
||||
interactive,
|
||||
firstInteractive,
|
||||
debugResult,
|
||||
nodeId,
|
||||
onChangeNode,
|
||||
|
||||
@@ -35,6 +35,8 @@ import WorkflowInitContextProvider, { WorkflowNodeEdgeContext } from './workflow
|
||||
import WorkflowEventContextProvider from './workflowEventContext';
|
||||
import { getAppConfigByDiff } from '@/web/core/app/diff';
|
||||
import WorkflowStatusContextProvider from './workflowStatusContext';
|
||||
import { ChatItemType, UserChatItemValueItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { ChatRoleEnum, ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
|
||||
|
||||
/*
|
||||
Context
|
||||
@@ -161,18 +163,34 @@ type WorkflowContextType = {
|
||||
runtimeNodes: RuntimeNodeItemType[];
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
nextRunNodes: RuntimeNodeItemType[];
|
||||
query?: UserChatItemValueItemType[];
|
||||
variables: Record<string, any>;
|
||||
}
|
||||
| undefined;
|
||||
setWorkflowDebugData: React.Dispatch<
|
||||
React.SetStateAction<
|
||||
| {
|
||||
runtimeNodes: RuntimeNodeItemType[];
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
nextRunNodes: RuntimeNodeItemType[];
|
||||
query?: UserChatItemValueItemType[];
|
||||
variables: Record<string, any>;
|
||||
}
|
||||
| undefined
|
||||
>
|
||||
>;
|
||||
onNextNodeDebug: () => Promise<void>;
|
||||
onStartNodeDebug: ({
|
||||
entryNodeId,
|
||||
runtimeNodes,
|
||||
runtimeEdges,
|
||||
query,
|
||||
variables
|
||||
}: {
|
||||
entryNodeId: string;
|
||||
runtimeNodes: RuntimeNodeItemType[];
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
query?: UserChatItemValueItemType[];
|
||||
variables: Record<string, any>;
|
||||
}) => Promise<void>;
|
||||
onStopNodeDebug: () => void;
|
||||
@@ -194,6 +212,7 @@ type DebugDataType = {
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
nextRunNodes: RuntimeNodeItemType[];
|
||||
variables: Record<string, any>;
|
||||
query?: UserChatItemValueItemType[];
|
||||
};
|
||||
|
||||
export const WorkflowContext = createContext<WorkflowContextType>({
|
||||
@@ -236,6 +255,20 @@ export const WorkflowContext = createContext<WorkflowContextType>({
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
workflowDebugData: undefined,
|
||||
setWorkflowDebugData: function (
|
||||
value: React.SetStateAction<
|
||||
| {
|
||||
runtimeNodes: RuntimeNodeItemType[];
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
nextRunNodes: RuntimeNodeItemType[];
|
||||
query?: UserChatItemValueItemType[];
|
||||
variables: Record<string, any>;
|
||||
}
|
||||
| undefined
|
||||
>
|
||||
): void {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
onNextNodeDebug: function (): Promise<void> {
|
||||
throw new Error('Function not implemented.');
|
||||
},
|
||||
@@ -549,7 +582,37 @@ const WorkflowContextProvider = ({
|
||||
});
|
||||
|
||||
/* debug */
|
||||
const [workflowDebugData, setWorkflowDebugData] = useState<DebugDataType>();
|
||||
const [workflowDebugData, setWorkflowDebugData] = useState<
|
||||
DebugDataType & {
|
||||
query?: UserChatItemValueItemType[];
|
||||
}
|
||||
>();
|
||||
// 添加这个函数用于捕获入口节点的输入值
|
||||
const captureEntryInputValues = (entryNodeId: string, nodes: RuntimeNodeItemType[]) => {
|
||||
const entryNode = nodes.find((node) => node.nodeId === entryNodeId);
|
||||
if (!entryNode || !entryNode.inputs) return null;
|
||||
|
||||
// 提取用户输入值
|
||||
const userInput = entryNode.inputs.find((input) => input.key === 'userChatInput')?.value || '';
|
||||
return userInput;
|
||||
};
|
||||
// 添加函数用于准备调试数据
|
||||
const prepareDebugData = (entryNodeId: string, nodes: RuntimeNodeItemType[]) => {
|
||||
const userInput = captureEntryInputValues(entryNodeId, nodes);
|
||||
if (!userInput) return null;
|
||||
|
||||
// 构建查询项
|
||||
const queryItem: UserChatItemValueItemType = {
|
||||
type: ChatItemValueTypeEnum.text,
|
||||
text: {
|
||||
content: userInput
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
query: [queryItem]
|
||||
};
|
||||
};
|
||||
const onNextNodeDebug = useCallback(
|
||||
async (debugData = workflowDebugData) => {
|
||||
if (!debugData) return;
|
||||
@@ -611,7 +674,7 @@ const WorkflowContextProvider = ({
|
||||
});
|
||||
|
||||
try {
|
||||
// 4. Run one step
|
||||
// 4. Run one step - 添加历史记录和查询到请求中
|
||||
const { finishedEdges, finishedNodes, nextStepRunNodes, flowResponses, newVariables } =
|
||||
await postWorkflowDebug({
|
||||
nodes: runtimeNodes,
|
||||
@@ -621,6 +684,7 @@ const WorkflowContextProvider = ({
|
||||
cTime: formatTime2YMDHMW(),
|
||||
...debugData.variables
|
||||
},
|
||||
query: debugData.query || [],
|
||||
appId
|
||||
});
|
||||
// 5. Store debug result
|
||||
@@ -629,7 +693,8 @@ const WorkflowContextProvider = ({
|
||||
// edges need to save status
|
||||
runtimeEdges: finishedEdges,
|
||||
nextRunNodes: nextStepRunNodes,
|
||||
variables: newVariables
|
||||
variables: newVariables,
|
||||
query: debugData.query // 保留查询
|
||||
};
|
||||
setWorkflowDebugData(newStoreDebugData);
|
||||
|
||||
@@ -719,10 +784,12 @@ const WorkflowContextProvider = ({
|
||||
runtimeEdges: RuntimeEdgeItemType[];
|
||||
variables: Record<string, any>;
|
||||
}) => {
|
||||
const debugHistoryData = prepareDebugData(entryNodeId, runtimeNodes);
|
||||
const data = {
|
||||
runtimeNodes,
|
||||
runtimeEdges,
|
||||
nextRunNodes: runtimeNodes.filter((node) => node.nodeId === entryNodeId),
|
||||
query: debugHistoryData?.query || [],
|
||||
variables
|
||||
};
|
||||
onStopNodeDebug();
|
||||
@@ -992,6 +1059,7 @@ const WorkflowContextProvider = ({
|
||||
flowData2StoreData,
|
||||
|
||||
// debug
|
||||
setWorkflowDebugData,
|
||||
workflowDebugData,
|
||||
onNextNodeDebug,
|
||||
onStartNodeDebug,
|
||||
|
||||
Reference in New Issue
Block a user