Skip to content

Commit a34b30a

Browse files
authored
feat(n8n Evaluation Node): Add pre-defined metrics to the "Set Metrics" operation (n8n-io#17127)
1 parent ba7b2d8 commit a34b30a

23 files changed

Lines changed: 1975 additions & 146 deletions

File tree

packages/@n8n/nodes-langchain/nodes/mcp/McpTrigger/McpTrigger.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { WebhookAuthorizationError } from 'n8n-nodes-base/dist/nodes/Webhook/error';
22
import { validateWebhookAuthentication } from 'n8n-nodes-base/dist/nodes/Webhook/utils';
33
import type { INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
4-
import { NodeConnectionTypes, Node } from 'n8n-workflow';
4+
import { NodeConnectionTypes, Node, nodeNameToToolName } from 'n8n-workflow';
55

6-
import { getConnectedTools, nodeNameToToolName } from '@utils/helpers';
6+
import { getConnectedTools } from '@utils/helpers';
77

88
import type { CompressionResponse } from './FlushingTransport';
99
import { McpServerManager } from './McpServer';

packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import type {
1212
ExecutionError,
1313
IDataObject,
1414
} from 'n8n-workflow';
15-
import { jsonParse, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
15+
import {
16+
jsonParse,
17+
NodeConnectionTypes,
18+
NodeOperationError,
19+
nodeNameToToolName,
20+
} from 'n8n-workflow';
1621

1722
import {
1823
buildInputSchemaField,
1924
buildJsonSchemaExampleField,
2025
buildJsonSchemaExampleNotice,
2126
schemaTypeField,
2227
} from '@utils/descriptions';
23-
import { nodeNameToToolName } from '@utils/helpers';
2428
import { convertJsonSchemaToZod, generateSchemaFromExample } from '@utils/schemaParsing';
2529
import { getConnectionHintNoticeField } from '@utils/sharedFields';
2630

packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import type {
88
ISupplyDataFunctions,
99
SupplyData,
1010
} from 'n8n-workflow';
11-
import { NodeConnectionTypes } from 'n8n-workflow';
11+
import { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';
1212

13-
import { nodeNameToToolName } from '@utils/helpers';
1413
import { logWrapper } from '@utils/logWrapper';
1514
import { getConnectionHintNoticeField } from '@utils/sharedFields';
1615

packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
INodeTypeDescription,
77
} from 'n8n-workflow';
88

9-
import { nodeNameToToolName } from '@utils/helpers';
9+
import { nodeNameToToolName } from 'n8n-workflow';
1010

1111
import { localResourceMapping } from './methods';
1212
import { WorkflowToolService } from './utils/WorkflowToolService';

packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { VectorStore } from '@langchain/core/vectorstores';
44
import { DynamicTool } from 'langchain/tools';
55
import { NodeConnectionTypes, type ISupplyDataFunctions, type SupplyData } from 'n8n-workflow';
66

7-
import { getMetadataFiltersValues, nodeNameToToolName } from '@utils/helpers';
7+
import { getMetadataFiltersValues } from '@utils/helpers';
8+
import { nodeNameToToolName } from 'n8n-workflow';
89
import { logWrapper } from '@utils/logWrapper';
910

1011
import type { VectorStoreNodeConstructorArgs } from '../types';

packages/@n8n/nodes-langchain/utils/helpers.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { BaseChatMemory } from 'langchain/memory';
88
import { NodeConnectionTypes, NodeOperationError, jsonStringify } from 'n8n-workflow';
99
import type {
1010
AiEvent,
11-
INode,
1211
IDataObject,
1312
IExecuteFunctions,
1413
ISupplyDataFunctions,
@@ -251,14 +250,6 @@ export function unwrapNestedOutput(output: Record<string, unknown>): Record<stri
251250
return output;
252251
}
253252

254-
/**
255-
* Converts a node name to a valid tool name by replacing special characters with underscores
256-
* and collapsing consecutive underscores into a single one.
257-
*/
258-
export function nodeNameToToolName(node: INode): string {
259-
return node.name.replace(/[\s.?!=+#@&*()[\]{}:;,<>\/\\'"^%$]/g, '_').replace(/_+/g, '_');
260-
}
261-
262253
/**
263254
* Detects if a text contains a character that repeats sequentially for a specified threshold.
264255
* This is used to prevent performance issues with tiktoken on highly repetitive content.

packages/@n8n/nodes-langchain/utils/tests/helpers.test.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,10 @@ import {
99
escapeSingleCurlyBrackets,
1010
getConnectedTools,
1111
hasLongSequentialRepeat,
12-
nodeNameToToolName,
1312
unwrapNestedOutput,
1413
} from '../helpers';
1514
import { N8nTool } from '../N8nTool';
1615

17-
describe('nodeNameToToolName', () => {
18-
const getNodeWithName = (name: string): INode => ({
19-
id: 'test-node',
20-
name,
21-
type: 'test',
22-
typeVersion: 1,
23-
position: [0, 0] as [number, number],
24-
parameters: {},
25-
});
26-
it('should replace spaces with underscores', () => {
27-
expect(nodeNameToToolName(getNodeWithName('Test Node'))).toBe('Test_Node');
28-
});
29-
30-
it('should replace dots with underscores', () => {
31-
expect(nodeNameToToolName(getNodeWithName('Test.Node'))).toBe('Test_Node');
32-
});
33-
34-
it('should replace question marks with underscores', () => {
35-
expect(nodeNameToToolName(getNodeWithName('Test?Node'))).toBe('Test_Node');
36-
});
37-
38-
it('should replace exclamation marks with underscores', () => {
39-
expect(nodeNameToToolName(getNodeWithName('Test!Node'))).toBe('Test_Node');
40-
});
41-
42-
it('should replace equals signs with underscores', () => {
43-
expect(nodeNameToToolName(getNodeWithName('Test=Node'))).toBe('Test_Node');
44-
});
45-
46-
it('should replace multiple special characters with underscores', () => {
47-
expect(nodeNameToToolName(getNodeWithName('Test.Node?With!Special=Chars'))).toBe(
48-
'Test_Node_With_Special_Chars',
49-
);
50-
});
51-
52-
it('should handle names that already have underscores', () => {
53-
expect(nodeNameToToolName(getNodeWithName('Test_Node'))).toBe('Test_Node');
54-
});
55-
56-
it('should handle names with consecutive special characters', () => {
57-
expect(nodeNameToToolName(getNodeWithName('Test..!!??==Node'))).toBe('Test_Node');
58-
});
59-
60-
it('should replace various special characters with underscores', () => {
61-
expect(nodeNameToToolName(getNodeWithName('Test#+*()[]{}:;,<>/\\\'"%$Node'))).toBe('Test_Node');
62-
});
63-
});
64-
6516
describe('escapeSingleCurlyBrackets', () => {
6617
it('should return undefined when input is undefined', () => {
6718
expect(escapeSingleCurlyBrackets(undefined)).toBeUndefined();

0 commit comments

Comments
 (0)