feat: 完成工作流多文件文档解析闭环
- 支持文档解析节点批量解析并收口为 documents 轻量输出 - 收口引用树、节点输出展示与旧工作流固定输出兼容 - 修复共享按钮点击事件,恢复多个节点加号交互
This commit is contained in:
@@ -359,8 +359,12 @@ describe('workflow node fields', () => {
|
||||
|
||||
expect(documentsParameter?.displayName).toBe('知识库 > documents');
|
||||
expect(documentsParameter?.formLabel).toBe('知识库 > documents');
|
||||
expect(contentParameter?.displayName).toBe('知识库 > documents.content');
|
||||
expect(contentParameter?.formLabel).toBe('知识库 > documents.content');
|
||||
expect(documentsParameter?.pathLabel).toBe('documents');
|
||||
expect(documentsParameter?.isCollection).toBe(true);
|
||||
expect(contentParameter?.displayName).toBe('知识库 > documents.[].content');
|
||||
expect(contentParameter?.formLabel).toBe('知识库 > documents.[].content');
|
||||
expect(contentParameter?.pathLabel).toBe('documents.[].content');
|
||||
expect(contentParameter?.itemTypeLabel).toBe('数组项字段');
|
||||
});
|
||||
|
||||
it('uses document node child outputs for reference display', () => {
|
||||
@@ -385,14 +389,6 @@ describe('workflow node fields', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'contents',
|
||||
formLabel: '逐文件内容',
|
||||
},
|
||||
{
|
||||
name: 'count',
|
||||
formLabel: '数量',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -419,13 +415,9 @@ describe('workflow node fields', () => {
|
||||
expect(parameters.find((item) => item.name === 'doc_1.documents')?.displayName)
|
||||
.toBe('文档解析 > documents');
|
||||
expect(parameters.find((item) => item.name === 'doc_1.documents.fileName')?.displayName)
|
||||
.toBe('文档解析 > documents.fileName');
|
||||
.toBe('文档解析 > documents.[].fileName');
|
||||
expect(parameters.find((item) => item.name === 'doc_1.documents.content')?.displayName)
|
||||
.toBe('文档解析 > documents.content');
|
||||
expect(parameters.find((item) => item.name === 'doc_1.contents')?.displayName)
|
||||
.toBe('文档解析 > contents');
|
||||
expect(parameters.find((item) => item.name === 'doc_1.count')?.displayName)
|
||||
.toBe('文档解析 > count');
|
||||
.toBe('文档解析 > documents.[].content');
|
||||
});
|
||||
|
||||
it('applies default binding to llm user prompt after connect', () => {
|
||||
|
||||
@@ -160,6 +160,38 @@ function getReferenceParameterLabel(parameter?: Parameter | null) {
|
||||
return asString(parameter?.name).trim() || getParameterLabel(parameter);
|
||||
}
|
||||
|
||||
function isCollectionOutputParameter(parameter?: Parameter | null) {
|
||||
const dataType = asString(parameter?.dataType).trim();
|
||||
return (
|
||||
!!parameter?.children?.length &&
|
||||
(
|
||||
dataType === 'Array' ||
|
||||
dataType.length === 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function getCollectionDisplayName(label: string) {
|
||||
return label.endsWith('.[]') ? label : `${label}.[]`;
|
||||
}
|
||||
|
||||
function buildCollectionAwareLabel(
|
||||
referenceLabel: string,
|
||||
parentLabel: string,
|
||||
parentIsCollection: boolean,
|
||||
) {
|
||||
const normalizedReferenceLabel = asString(referenceLabel).trim();
|
||||
if (!normalizedReferenceLabel) {
|
||||
return parentLabel;
|
||||
}
|
||||
if (!parentLabel) {
|
||||
return normalizedReferenceLabel;
|
||||
}
|
||||
return parentIsCollection
|
||||
? `${parentLabel}.[].${normalizedReferenceLabel}`
|
||||
: `${parentLabel}.${normalizedReferenceLabel}`;
|
||||
}
|
||||
|
||||
function buildDisconnectedDisplayName(parameter: Parameter) {
|
||||
const displayName =
|
||||
asString(parameter.displayName).trim() ||
|
||||
@@ -200,6 +232,7 @@ function flattenOutputDefs(
|
||||
parameters: Parameter[],
|
||||
parentPath = '',
|
||||
parentLabel = '',
|
||||
parentIsCollection = false,
|
||||
): Parameter[] {
|
||||
if (!parameters.length) {
|
||||
return [];
|
||||
@@ -212,17 +245,21 @@ function flattenOutputDefs(
|
||||
}
|
||||
|
||||
const path = parentPath ? `${parentPath}.${rawName}` : rawName;
|
||||
const label = parentLabel
|
||||
? `${parentLabel}.${getReferenceParameterLabel(parameter)}`
|
||||
: getReferenceParameterLabel(parameter);
|
||||
const referenceLabel = getReferenceParameterLabel(parameter);
|
||||
const label = buildCollectionAwareLabel(referenceLabel, parentLabel, parentIsCollection);
|
||||
const displayName = `${getNodeTitle(node)} > ${label}`;
|
||||
const isCollection = isCollectionOutputParameter(parameter);
|
||||
const fullRef = `${node.id}.${path}`;
|
||||
const baseCandidate: Parameter = ensureParameterId({
|
||||
name: fullRef,
|
||||
ref: fullRef,
|
||||
refType: 'ref',
|
||||
dataType: parameter.dataType || 'String',
|
||||
displayName: `${getNodeTitle(node)} > ${label}`,
|
||||
formLabel: `${getNodeTitle(node)} > ${label}`,
|
||||
displayName,
|
||||
formLabel: displayName,
|
||||
pathLabel: label,
|
||||
itemTypeLabel: parentIsCollection ? '数组项字段' : undefined,
|
||||
isCollection,
|
||||
nameDisabled: true,
|
||||
dataTypeDisabled: true,
|
||||
deleteDisabled: true,
|
||||
@@ -234,6 +271,7 @@ function flattenOutputDefs(
|
||||
parameter.children || [],
|
||||
path,
|
||||
label,
|
||||
isCollection,
|
||||
);
|
||||
|
||||
return [baseCandidate, ...children];
|
||||
@@ -1227,7 +1265,7 @@ export function renameStartFieldReferencesInNodes(
|
||||
startNodeId: string,
|
||||
currentKey: string,
|
||||
nextKey: string,
|
||||
) {
|
||||
): Node[] {
|
||||
const normalizedStartNodeId = trimString(startNodeId);
|
||||
const normalizedCurrentKey = trimString(currentKey);
|
||||
const normalizedNextKey = trimString(nextKey);
|
||||
|
||||
Reference in New Issue
Block a user