mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(n8n Evaluation Node): Add pre-defined metrics to the "Set Metrics" operation (#17127)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { WebhookAuthorizationError } from 'n8n-nodes-base/dist/nodes/Webhook/error';
|
||||
import { validateWebhookAuthentication } from 'n8n-nodes-base/dist/nodes/Webhook/utils';
|
||||
import type { INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, Node } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, Node, nodeNameToToolName } from 'n8n-workflow';
|
||||
|
||||
import { getConnectedTools, nodeNameToToolName } from '@utils/helpers';
|
||||
import { getConnectedTools } from '@utils/helpers';
|
||||
|
||||
import type { CompressionResponse } from './FlushingTransport';
|
||||
import { McpServerManager } from './McpServer';
|
||||
|
||||
@@ -12,7 +12,12 @@ import type {
|
||||
ExecutionError,
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
import { jsonParse, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
import {
|
||||
jsonParse,
|
||||
NodeConnectionTypes,
|
||||
NodeOperationError,
|
||||
nodeNameToToolName,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
buildInputSchemaField,
|
||||
@@ -20,7 +25,6 @@ import {
|
||||
buildJsonSchemaExampleNotice,
|
||||
schemaTypeField,
|
||||
} from '@utils/descriptions';
|
||||
import { nodeNameToToolName } from '@utils/helpers';
|
||||
import { convertJsonSchemaToZod, generateSchemaFromExample } from '@utils/schemaParsing';
|
||||
import { getConnectionHintNoticeField } from '@utils/sharedFields';
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@ import type {
|
||||
ISupplyDataFunctions,
|
||||
SupplyData,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';
|
||||
|
||||
import { nodeNameToToolName } from '@utils/helpers';
|
||||
import { logWrapper } from '@utils/logWrapper';
|
||||
import { getConnectionHintNoticeField } from '@utils/sharedFields';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { nodeNameToToolName } from '@utils/helpers';
|
||||
import { nodeNameToToolName } from 'n8n-workflow';
|
||||
|
||||
import { localResourceMapping } from './methods';
|
||||
import { WorkflowToolService } from './utils/WorkflowToolService';
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { VectorStore } from '@langchain/core/vectorstores';
|
||||
import { DynamicTool } from 'langchain/tools';
|
||||
import { NodeConnectionTypes, type ISupplyDataFunctions, type SupplyData } from 'n8n-workflow';
|
||||
|
||||
import { getMetadataFiltersValues, nodeNameToToolName } from '@utils/helpers';
|
||||
import { getMetadataFiltersValues } from '@utils/helpers';
|
||||
import { nodeNameToToolName } from 'n8n-workflow';
|
||||
import { logWrapper } from '@utils/logWrapper';
|
||||
|
||||
import type { VectorStoreNodeConstructorArgs } from '../types';
|
||||
|
||||
@@ -8,7 +8,6 @@ import type { BaseChatMemory } from 'langchain/memory';
|
||||
import { NodeConnectionTypes, NodeOperationError, jsonStringify } from 'n8n-workflow';
|
||||
import type {
|
||||
AiEvent,
|
||||
INode,
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
ISupplyDataFunctions,
|
||||
@@ -251,14 +250,6 @@ export function unwrapNestedOutput(output: Record<string, unknown>): Record<stri
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a node name to a valid tool name by replacing special characters with underscores
|
||||
* and collapsing consecutive underscores into a single one.
|
||||
*/
|
||||
export function nodeNameToToolName(node: INode): string {
|
||||
return node.name.replace(/[\s.?!=+#@&*()[\]{}:;,<>\/\\'"^%$]/g, '_').replace(/_+/g, '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if a text contains a character that repeats sequentially for a specified threshold.
|
||||
* This is used to prevent performance issues with tiktoken on highly repetitive content.
|
||||
|
||||
@@ -9,59 +9,10 @@ import {
|
||||
escapeSingleCurlyBrackets,
|
||||
getConnectedTools,
|
||||
hasLongSequentialRepeat,
|
||||
nodeNameToToolName,
|
||||
unwrapNestedOutput,
|
||||
} from '../helpers';
|
||||
import { N8nTool } from '../N8nTool';
|
||||
|
||||
describe('nodeNameToToolName', () => {
|
||||
const getNodeWithName = (name: string): INode => ({
|
||||
id: 'test-node',
|
||||
name,
|
||||
type: 'test',
|
||||
typeVersion: 1,
|
||||
position: [0, 0] as [number, number],
|
||||
parameters: {},
|
||||
});
|
||||
it('should replace spaces with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace dots with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test.Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace question marks with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test?Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace exclamation marks with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test!Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace equals signs with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test=Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace multiple special characters with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test.Node?With!Special=Chars'))).toBe(
|
||||
'Test_Node_With_Special_Chars',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle names that already have underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test_Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should handle names with consecutive special characters', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test..!!??==Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace various special characters with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test#+*()[]{}:;,<>/\\\'"%$Node'))).toBe('Test_Node');
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeSingleCurlyBrackets', () => {
|
||||
it('should return undefined when input is undefined', () => {
|
||||
expect(escapeSingleCurlyBrackets(undefined)).toBeUndefined();
|
||||
|
||||
Reference in New Issue
Block a user