feat(core): Improve debugging of sub-workflows (#11602)

This commit is contained in:
Mutasem Aldmour
2024-11-14 23:04:43 +01:00
committed by GitHub
parent f4ca4b792f
commit fd3254d587
36 changed files with 1843 additions and 265 deletions

View File

@@ -10,6 +10,7 @@ import type {
INodeTypeDescription,
SupplyData,
INodeParameterResourceLocator,
ExecuteWorkflowData,
} from 'n8n-workflow';
import { BaseRetriever, type BaseRetrieverInput } from '@langchain/core/retrievers';
@@ -293,6 +294,8 @@ export class RetrieverWorkflow implements INodeType {
};
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
const workflowProxy = this.getWorkflowDataProxy(0);
class WorkflowRetriever extends BaseRetriever {
lc_namespace = ['n8n-nodes-langchain', 'retrievers', 'workflow'];
@@ -349,6 +352,9 @@ export class RetrieverWorkflow implements INodeType {
},
);
}
// same as current workflow
baseMetadata.workflowId = workflowProxy.$workflow.id;
}
const rawData: IDataObject = { query };
@@ -384,21 +390,29 @@ export class RetrieverWorkflow implements INodeType {
const items = [newItem] as INodeExecutionData[];
let receivedItems: INodeExecutionData[][];
let receivedData: ExecuteWorkflowData;
try {
receivedItems = (await this.executeFunctions.executeWorkflow(
receivedData = await this.executeFunctions.executeWorkflow(
workflowInfo,
items,
config?.getChild(),
)) as INodeExecutionData[][];
{
parentExecution: {
executionId: workflowProxy.$execution.id,
workflowId: workflowProxy.$workflow.id,
},
},
);
} catch (error) {
// Make sure a valid error gets returned that can by json-serialized else it will
// not show up in the frontend
throw new NodeOperationError(this.executeFunctions.getNode(), error as Error);
}
const receivedItems = receivedData.data?.[0] ?? [];
const returnData: Document[] = [];
for (const [index, itemData] of receivedItems[0].entries()) {
for (const [index, itemData] of receivedItems.entries()) {
const pageContent = objectToString(itemData.json);
returnData.push(
new Document({
@@ -406,6 +420,7 @@ export class RetrieverWorkflow implements INodeType {
metadata: {
...baseMetadata,
itemIndex: index,
executionId: receivedData.executionId,
},
}),
);