mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
WIP: Debugging and logging
This commit is contained in:
parent
17ef2c63f6
commit
6d1eed8222
|
@ -382,27 +382,61 @@ class AIParametersParser {
|
||||||
description,
|
description,
|
||||||
schema,
|
schema,
|
||||||
func: async (functionArgs: z.infer<typeof schema>) => {
|
func: async (functionArgs: z.infer<typeof schema>) => {
|
||||||
|
// How can we pair this index with the index in that in WorkflowDataProxy.handleFromAi?
|
||||||
const { index } = this.ctx.addInputData(NodeConnectionType.AiTool, [
|
const { index } = this.ctx.addInputData(NodeConnectionType.AiTool, [
|
||||||
[{ json: functionArgs }],
|
[{ json: functionArgs }],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
console.log('\n\x1b%s\x1b', '🔹 Starting node-tool func execution');
|
||||||
|
console.log(
|
||||||
|
'\x1b[33m%s\x1b',
|
||||||
|
' Input data(functionArgs):',
|
||||||
|
JSON.stringify(functionArgs, null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Execute the node with the proxied context
|
// Execute the node with the proxied context
|
||||||
const result = await node.execute?.bind(this.ctx)();
|
console.log('\x1b%s\x1b', '🔹 Executing node');
|
||||||
|
console.log('\n%s', '🔹 Getting input data for index: ', index);
|
||||||
|
|
||||||
|
// Hacky way to only execute input data once(per each item?)
|
||||||
|
const proxiedContext = new Proxy(this.ctx, {
|
||||||
|
get: (target, prop: keyof IExecuteFunctions) => {
|
||||||
|
if (prop === 'getInputData') {
|
||||||
|
console.log('Returning modified input data');
|
||||||
|
return () => [{ json: functionArgs }];
|
||||||
|
}
|
||||||
|
return target[prop];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const result = await node.execute?.bind(proxiedContext)();
|
||||||
|
|
||||||
|
console.log('\x1b[32m%s\x1b', '✅ Node execution successful');
|
||||||
|
console.log('\x1b[33m%s\x1b', ' Raw result:', JSON.stringify(result, null, 2));
|
||||||
|
|
||||||
// Process and map the results
|
// Process and map the results
|
||||||
const mappedResults = result?.[0]?.flatMap((item) => item.json);
|
const mappedResults = result?.[0]?.flatMap((item) => item.json);
|
||||||
|
|
||||||
|
console.log('\x1b%s\x1b', '🔹 Mapped results:');
|
||||||
|
console.log('\x1b[33m%s\x1b', JSON.stringify(mappedResults, null, 2));
|
||||||
|
|
||||||
// Add output data to the context
|
// Add output data to the context
|
||||||
this.ctx.addOutputData(NodeConnectionType.AiTool, index, [
|
this.ctx.addOutputData(NodeConnectionType.AiTool, index, [
|
||||||
[{ json: { response: mappedResults } }],
|
[{ json: { response: mappedResults } }],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
console.log('\x1b%s\x1b', '🔹 Output data added to context');
|
||||||
|
|
||||||
// Return the stringified results
|
// Return the stringified results
|
||||||
return JSON.stringify(mappedResults);
|
return JSON.stringify(mappedResults);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('\x1b[31m%s\x1b', '❌ Error during node execution:');
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
const nodeError = new NodeOperationError(this.ctx.getNode(), error as Error);
|
const nodeError = new NodeOperationError(this.ctx.getNode(), error as Error);
|
||||||
this.ctx.addOutputData(NodeConnectionType.AiTool, index, nodeError);
|
this.ctx.addOutputData(NodeConnectionType.AiTool, index, nodeError);
|
||||||
|
|
||||||
|
console.log('\x1b[31m%s\x1b', ' Error added to context output');
|
||||||
return 'Error during node execution: ' + nodeError.description;
|
return 'Error during node execution: ' + nodeError.description;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -945,14 +945,25 @@ export class WorkflowDataProxy {
|
||||||
_type: string = 'string',
|
_type: string = 'string',
|
||||||
defaultValue?: unknown,
|
defaultValue?: unknown,
|
||||||
) => {
|
) => {
|
||||||
|
console.time('⏱️ fromAI execution');
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
'\n🔹 Starting fromAI function, that.runIndex: ',
|
||||||
|
that.runIndex,
|
||||||
|
', that.itemIndex: ',
|
||||||
|
that.itemIndex,
|
||||||
|
);
|
||||||
if (!name || name === '') {
|
if (!name || name === '') {
|
||||||
|
console.error('\n❌ Error: Missing key');
|
||||||
throw new ExpressionError("Add a key, e.g. $fromAI('placeholder_name')", {
|
throw new ExpressionError("Add a key, e.g. $fromAI('placeholder_name')", {
|
||||||
runIndex: that.runIndex,
|
runIndex: that.runIndex,
|
||||||
itemIndex: that.itemIndex,
|
itemIndex: that.itemIndex,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const nameValidationRegex = /^[a-zA-Z0-9_-]{0,64}$/;
|
const nameValidationRegex = /^[a-zA-Z0-9_-]{0,64}$/;
|
||||||
if (!nameValidationRegex.test(name)) {
|
if (!nameValidationRegex.test(name)) {
|
||||||
|
console.error('\n❌ Error: Invalid parameter key');
|
||||||
throw new ExpressionError(
|
throw new ExpressionError(
|
||||||
'Invalid parameter key, must be between 1 and 64 characters long and only contain lowercase letters, uppercase letters, numbers, underscores, and hyphens',
|
'Invalid parameter key, must be between 1 and 64 characters long and only contain lowercase letters, uppercase letters, numbers, underscores, and hyphens',
|
||||||
{
|
{
|
||||||
|
@ -961,19 +972,35 @@ export class WorkflowDataProxy {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('\n🔹 Fetching placeholders data');
|
||||||
|
const nodeRunData = that.runExecutionData?.resultData.runData[that.activeNodeName] ?? [];
|
||||||
|
const lastInputOverride = nodeRunData[nodeRunData.length - 1]?.inputOverride;
|
||||||
const placeholdersDataInputData =
|
const placeholdersDataInputData =
|
||||||
that.runExecutionData?.resultData.runData[that.activeNodeName]?.[0].inputOverride?.[
|
lastInputOverride?.[NodeConnectionType.AiTool]?.[0]?.[0].json;
|
||||||
NodeConnectionType.AiTool
|
|
||||||
]?.[0]?.[0].json;
|
console.log('\n📝 Placeholders data:');
|
||||||
|
console.log(` ${JSON.stringify(placeholdersDataInputData, null, 2)}`);
|
||||||
|
|
||||||
if (Boolean(!placeholdersDataInputData)) {
|
if (Boolean(!placeholdersDataInputData)) {
|
||||||
|
console.error('\n❌ Error: No execution data available');
|
||||||
throw new ExpressionError('No execution data available', {
|
throw new ExpressionError('No execution data available', {
|
||||||
runIndex: that.runIndex,
|
runIndex: that.runIndex,
|
||||||
itemIndex: that.itemIndex,
|
itemIndex: that.itemIndex,
|
||||||
type: 'no_execution_data',
|
type: 'no_execution_data',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return placeholdersDataInputData?.[name] ?? defaultValue;
|
|
||||||
|
const result = placeholdersDataInputData?.[name] ?? defaultValue;
|
||||||
|
console.log(`\n✅ Success: Returning value for key "${name}"`);
|
||||||
|
console.log(` Value: ${result}`);
|
||||||
|
console.log(`\n🔹 Resolving placeholder for itemIndex: ${that.itemIndex}`);
|
||||||
|
console.log(
|
||||||
|
` Fetched placeholdersDataInputData: ${JSON.stringify(placeholdersDataInputData, null, 2)}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.timeEnd('⏱️ fromAI execution');
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const base = {
|
const base = {
|
||||||
|
|
Loading…
Reference in a new issue