feat: add realmode parameter to workflow dispatch and update interactive handling

This commit is contained in:
sd0ric4
2025-03-25 18:42:23 +08:00
parent ccc9260ed5
commit 369c4b247b
5 changed files with 20 additions and 246 deletions

View File

@@ -65,6 +65,7 @@ export type ModuleDispatchProps<T> = ChatDispatchProps & {
runtimeNodes: RuntimeNodeItemType[]; runtimeNodes: RuntimeNodeItemType[];
runtimeEdges: RuntimeEdgeItemType[]; runtimeEdges: RuntimeEdgeItemType[];
params: T; params: T;
realmode?: 'test' | 'chat' | 'debug';
}; };
export type SystemVariablesType = { export type SystemVariablesType = {

View File

@@ -581,7 +581,8 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
runtimeNodes, runtimeNodes,
runtimeEdges, runtimeEdges,
params, params,
mode: props.mode === 'debug' ? 'test' : props.mode mode: props.mode === 'debug' ? 'test' : props.mode,
realmode: props.mode
}; };
// run module // run module

View File

@@ -32,11 +32,11 @@ export const dispatchFormInput = async (props: Props): Promise<FormInputResponse
query query
} = props; } = props;
const { isEntry } = node; const { isEntry } = node;
const mode = props.realmode;
const interactive = getLastInteractiveValue(histories); const interactive = getLastInteractiveValue(histories);
// Interactive node is not the entry node, return interactive result // Interactive node is not the entry node, return interactive result
if (!isEntry || interactive?.type !== 'userInput') { if ((!isEntry || interactive?.type !== 'userInput') && mode !== 'debug') {
return { return {
[DispatchNodeResponseKeyEnum.interactive]: { [DispatchNodeResponseKeyEnum.interactive]: {
type: 'userInput', type: 'userInput',

View File

@@ -30,11 +30,11 @@ export const dispatchUserSelect = async (props: Props): Promise<UserSelectRespon
query query
} = props; } = props;
const { nodeId, isEntry } = node; const { nodeId, isEntry } = node;
const mode = props.realmode;
const interactive = getLastInteractiveValue(histories); const interactive = getLastInteractiveValue(histories);
// Interactive node is not the entry node, return interactive result // Interactive node is not the entry node, return interactive result
if (!isEntry || interactive?.type !== 'userSelect') { if ((!isEntry || interactive?.type !== 'userSelect') && mode !== 'debug') {
return { return {
[DispatchNodeResponseKeyEnum.interactive]: { [DispatchNodeResponseKeyEnum.interactive]: {
type: 'userSelect', type: 'userSelect',

View File

@@ -48,246 +48,18 @@ async function handler(
} }
} }
]; ];
const histories_form_input: ChatItemType[] = requestHistories || [
{ const query: UserChatItemValueItemType[] =
dataId: 'j2ywiLkIbMivBll5fzYvkuGK', requestQuery ||
obj: ChatRoleEnum.Human, [
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '123213'
}
}
]
},
{
dataId: 'lRXcu9MtfCHlpUqeQWGSY4gu',
obj: ChatRoleEnum.AI,
value: [
{
type: ChatItemValueTypeEnum.interactive,
interactive: {
type: 'userInput',
params: {
description: '这是个表单输入',
inputForm: [
{
type: 'input',
key: '未知',
label: '未知',
description: '未知',
value: '',
maxLength: 20,
defaultValue: '未知',
valueType: 'string',
required: true,
list: [
{
label: '',
value: ''
}
]
},
{
type: 'numberInput',
key: '数字',
label: '数字',
description: '数字',
value: '',
defaultValue: 2,
valueType: 'number',
required: false,
list: [
{
label: '',
value: ''
}
],
max: 2,
min: 2
}
]
},
entryNodeIds: ['mYvt4SN5KFwZ'],
memoryEdges: [
{
source: 'workflowStartNodeId',
target: 'oQKWr1cGFVBG',
sourceHandle: 'workflowStartNodeId-source-right',
targetHandle: 'oQKWr1cGFVBG-target-left',
status: 'waiting'
},
{
source: 'oQKWr1cGFVBG',
target: 'uFnqha6Nx9qw',
sourceHandle: 'oQKWr1cGFVBG-source-option1',
targetHandle: 'uFnqha6Nx9qw-target-left',
status: 'waiting'
},
{
source: 'oQKWr1cGFVBG',
target: '7kwgL1dVlwG6',
sourceHandle: 'oQKWr1cGFVBG-source-option2',
targetHandle: '7kwgL1dVlwG6-target-left',
status: 'waiting'
},
{
source: '7kwgL1dVlwG6',
target: 'dZpDaSXFO0td',
sourceHandle: '7kwgL1dVlwG6-source-right',
targetHandle: 'dZpDaSXFO0td-target-left',
status: 'waiting'
},
{
source: 'dZpDaSXFO0td',
target: 'uFnqha6Nx9qw',
sourceHandle: 'dZpDaSXFO0td-source-option2',
targetHandle: 'uFnqha6Nx9qw-target-left',
status: 'waiting'
},
{
source: 'workflowStartNodeId',
target: 'mYvt4SN5KFwZ',
sourceHandle: 'workflowStartNodeId-source-right',
targetHandle: 'mYvt4SN5KFwZ-target-left',
status: 'waiting'
},
{
source: 'mYvt4SN5KFwZ',
target: 'dfh8AqxAkoL4',
sourceHandle: 'mYvt4SN5KFwZ-source-right',
targetHandle: 'dfh8AqxAkoL4-target-left',
status: 'waiting'
}
],
nodeOutputs: [
{
nodeId: 'workflowStartNodeId',
key: NodeOutputKeyEnum.userChatInput,
value: '123213'
}
]
}
}
]
}
];
const query: UserChatItemValueItemType[] = requestQuery || [];
const histories: ChatItemType[] = requestHistories || [];
// || [
// {
// dataId: 'debug-history-1',
// obj: ChatRoleEnum.Human,
// value: [
// { // {
// type: ChatItemValueTypeEnum.text, // type: ChatItemValueTypeEnum.text,
// text: { // text: {
// content: '启动工作流' // content: 'Cancel'
// } // }
// } // }
// ] ];
// },
// {
// dataId: 'debug-history-2',
// obj: ChatRoleEnum.AI,
// value: [
// {
// type: ChatItemValueTypeEnum.interactive,
// interactive: {
// type: 'userSelect',
// params: {
// description: '请选择操作',
// userSelectOptions: [
// { value: 'Confirm', key: 'option1' },
// { value: 'Cancel', key: 'option2' }
// ],
// // 已选择的值使得此交互不会被getLastInteractiveValue返回
// userSelectedVal: 'Confirm'
// },
// entryNodeIds: ['nodeId1'],
// memoryEdges: [
// {
// source: 'workflowStartNodeId',
// target: 'nodeId1',
// sourceHandle: 'workflowStartNodeId-source-right',
// targetHandle: 'nodeId1-target-left',
// status: 'active'
// }
// ],
// nodeOutputs: [
// {
// nodeId: 'workflowStartNodeId',
// key: NodeOutputKeyEnum.userChatInput,
// value: '启动工作流'
// }
// ]
// }
// }
// ]
// },
// {
// dataId: 'bglb040v1wPQ3C1iNaDStPhm',
// obj: ChatRoleEnum.AI, // 使用枚举值
// value: [
// {
// type: ChatItemValueTypeEnum.interactive, // 使用枚举值
// interactive: {
// type: 'userSelect',
// params: {
// description: '你是谁',
// userSelectOptions: [
// {
// value: 'Confirm',
// key: 'option1'
// },
// {
// value: 'Cancel',
// key: 'option2'
// },
// {
// value: 'wqeqweqwe',
// key: 'y7eOdrYzYS5C'
// }
// ]
// // 重要:这里没有 userSelectedVal所以这个交互会被getLastInteractiveValue返回
// },
// entryNodeIds: ['oQKWr1cGFVBG'],
// memoryEdges: [
// {
// source: 'workflowStartNodeId',
// target: 'oQKWr1cGFVBG',
// sourceHandle: 'workflowStartNodeId-source-right',
// targetHandle: 'oQKWr1cGFVBG-target-left',
// status: 'waiting'
// },
// {
// source: 'oQKWr1cGFVBG',
// target: 'uFnqha6Nx9qw',
// sourceHandle: 'oQKWr1cGFVBG-source-option1',
// targetHandle: 'uFnqha6Nx9qw-target-left',
// status: 'waiting'
// },
// {
// source: 'oQKWr1cGFVBG',
// target: '7kwgL1dVlwG6',
// sourceHandle: 'oQKWr1cGFVBG-source-option2',
// targetHandle: '7kwgL1dVlwG6-target-left',
// status: 'waiting'
// }
// ],
// nodeOutputs: [
// {
// nodeId: 'workflowStartNodeId',
// key: NodeOutputKeyEnum.userChatInput,
// value: 'Confirm'
// }
// ]
// }
// }
// ]
// }
// ];
/* user auth */ /* user auth */
const [{ teamId, tmbId }, { app }] = await Promise.all([ const [{ teamId, tmbId }, { app }] = await Promise.all([
authCert({ authCert({
@@ -324,7 +96,7 @@ async function handler(
variables, variables,
query: query, query: query,
chatConfig: defaultApp.chatConfig, chatConfig: defaultApp.chatConfig,
histories: histories, histories: [],
stream: false, stream: false,
maxRunTimes: WORKFLOW_MAX_RUN_TIMES maxRunTimes: WORKFLOW_MAX_RUN_TIMES
}); });