4.8.13 test (#3098)
* perf: loop node refresh * rename context * comment * fix: ts * perf: push chat log
This commit is contained in:
@@ -16,15 +16,15 @@ import { EmptyNode } from '@fastgpt/global/core/workflow/template/system/emptyNo
|
||||
import { StoreEdgeItemType } from '@fastgpt/global/core/workflow/type/edge';
|
||||
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
||||
import { getGlobalVariableNode } from './adapt';
|
||||
import { VARIABLE_NODE_ID, WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { EditorVariablePickerType } from '@fastgpt/web/components/common/Textarea/PromptEditor/type';
|
||||
import {
|
||||
formatEditorVariablePickerIcon,
|
||||
getAppChatConfig,
|
||||
getGuideModule,
|
||||
isReferenceValue,
|
||||
isReferenceValueFormat
|
||||
isValidArrayReferenceValue,
|
||||
isValidReferenceValue
|
||||
} from '@fastgpt/global/core/workflow/utils';
|
||||
import { TFunction } from 'next-i18next';
|
||||
import {
|
||||
@@ -263,17 +263,72 @@ export const getRefData = ({
|
||||
};
|
||||
};
|
||||
|
||||
// 根据数据类型,过滤无效的节点输出
|
||||
export const filterWorkflowNodeOutputsByType = (
|
||||
outputs: FlowNodeOutputItemType[],
|
||||
valueType: WorkflowIOValueTypeEnum
|
||||
): FlowNodeOutputItemType[] => {
|
||||
const validTypeMap: Record<WorkflowIOValueTypeEnum, WorkflowIOValueTypeEnum[]> = {
|
||||
[WorkflowIOValueTypeEnum.string]: [WorkflowIOValueTypeEnum.string],
|
||||
[WorkflowIOValueTypeEnum.number]: [WorkflowIOValueTypeEnum.number],
|
||||
[WorkflowIOValueTypeEnum.boolean]: [WorkflowIOValueTypeEnum.boolean],
|
||||
[WorkflowIOValueTypeEnum.object]: [WorkflowIOValueTypeEnum.object],
|
||||
[WorkflowIOValueTypeEnum.arrayString]: [
|
||||
WorkflowIOValueTypeEnum.string,
|
||||
WorkflowIOValueTypeEnum.arrayString,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.arrayNumber]: [
|
||||
WorkflowIOValueTypeEnum.number,
|
||||
WorkflowIOValueTypeEnum.arrayNumber,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.arrayBoolean]: [
|
||||
WorkflowIOValueTypeEnum.boolean,
|
||||
WorkflowIOValueTypeEnum.arrayBoolean,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.arrayObject]: [
|
||||
WorkflowIOValueTypeEnum.object,
|
||||
WorkflowIOValueTypeEnum.arrayObject,
|
||||
WorkflowIOValueTypeEnum.arrayAny,
|
||||
WorkflowIOValueTypeEnum.chatHistory,
|
||||
WorkflowIOValueTypeEnum.datasetQuote,
|
||||
WorkflowIOValueTypeEnum.dynamic,
|
||||
WorkflowIOValueTypeEnum.selectDataset,
|
||||
WorkflowIOValueTypeEnum.selectApp
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.chatHistory]: [
|
||||
WorkflowIOValueTypeEnum.chatHistory,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.datasetQuote]: [
|
||||
WorkflowIOValueTypeEnum.datasetQuote,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.dynamic]: [
|
||||
WorkflowIOValueTypeEnum.dynamic,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.selectDataset]: [
|
||||
WorkflowIOValueTypeEnum.selectDataset,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.selectApp]: [
|
||||
WorkflowIOValueTypeEnum.selectApp,
|
||||
WorkflowIOValueTypeEnum.arrayAny
|
||||
],
|
||||
[WorkflowIOValueTypeEnum.arrayAny]: [WorkflowIOValueTypeEnum.arrayAny],
|
||||
[WorkflowIOValueTypeEnum.any]: [WorkflowIOValueTypeEnum.arrayAny]
|
||||
};
|
||||
|
||||
return outputs.filter(
|
||||
(output) =>
|
||||
valueType === WorkflowIOValueTypeEnum.any ||
|
||||
valueType === WorkflowIOValueTypeEnum.arrayAny ||
|
||||
!output.valueType ||
|
||||
output.valueType === WorkflowIOValueTypeEnum.any ||
|
||||
output.valueType === valueType ||
|
||||
valueType?.replace('array', '').toLowerCase() === output.valueType
|
||||
validTypeMap[valueType].includes(output.valueType)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -341,46 +396,25 @@ export const checkWorkflowNodeAndConnection = ({
|
||||
if (input.value === undefined) return true;
|
||||
}
|
||||
|
||||
if (
|
||||
node.data.flowNodeType === FlowNodeTypeEnum.pluginOutput &&
|
||||
(input.value?.length === 0 ||
|
||||
(isReferenceValue(input.value, nodeIds) && !input.value?.[1]))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
// Check plugin output
|
||||
// if (
|
||||
// node.data.flowNodeType === FlowNodeTypeEnum.pluginOutput &&
|
||||
// (input.value?.length === 0 ||
|
||||
// (isValidReferenceValue(input.value, nodeIds) && !input.value?.[1]))
|
||||
// ) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// check reference invalid
|
||||
const renderType = input.renderTypeList[input.selectedTypeIndex || 0];
|
||||
if (renderType === FlowNodeInputTypeEnum.reference) {
|
||||
const checkReference = (value: [string, string]) => {
|
||||
if (value[0] === VARIABLE_NODE_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const sourceNode = nodes.find((item) => item.data.nodeId === value[0]);
|
||||
if (!sourceNode) {
|
||||
if (input.valueType?.startsWith('array')) {
|
||||
if (input.required && (!input.value || input.value.length === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const sourceOutput = filterWorkflowNodeOutputsByType(
|
||||
sourceNode.data.outputs,
|
||||
input.valueType as WorkflowIOValueTypeEnum
|
||||
).find((item) => item.id === value[1]);
|
||||
return !sourceOutput;
|
||||
};
|
||||
|
||||
// Old format
|
||||
if (isReferenceValueFormat(input.value)) {
|
||||
return input.required && checkReference(input.value);
|
||||
return isValidArrayReferenceValue(input.value, nodeIds);
|
||||
}
|
||||
|
||||
// New format
|
||||
return input.value.some((inputItem: ReferenceItemValueType) => {
|
||||
if (!Array.isArray(inputItem) || inputItem.length !== 2) {
|
||||
return true;
|
||||
}
|
||||
return checkReference(inputItem as [string, string]);
|
||||
});
|
||||
return input.required && !isValidReferenceValue(input.value, nodeIds);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user