feat: Add more AI node info to telemetry (#8827)

This commit is contained in:
Michael Kret
2024-03-07 12:46:07 +02:00
committed by GitHub
parent 0f7ae3f50a
commit ed6dc86d60
7 changed files with 128 additions and 34 deletions

View File

@@ -8,10 +8,18 @@ import type {
INodesGraphResult,
IWorkflowBase,
INodeTypes,
IDataObject,
} from './Interfaces';
import { ApplicationError } from './errors/application.error';
const STICKY_NODE_TYPE = 'n8n-nodes-base.stickyNote';
import {
AGENT_LANGCHAIN_NODE_TYPE,
CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE,
HTTP_REQUEST_NODE_TYPE,
LANGCHAIN_CUSTOM_TOOLS,
OPENAI_LANGCHAIN_NODE_TYPE,
STICKY_NODE_TYPE,
WEBHOOK_NODE_TYPE,
} from './Constants';
export function getNodeTypeForName(workflow: IWorkflowBase, nodeName: string): INode | undefined {
return workflow.nodes.find((node) => node.name === nodeName);
@@ -95,6 +103,7 @@ export function generateNodesGraph(
options?: {
sourceInstanceId?: string;
nodeIdMap?: { [curr: string]: string };
isCloudDeployment?: boolean;
},
): INodesGraphResult {
const nodeGraph: INodesGraph = {
@@ -158,15 +167,15 @@ export function generateNodesGraph(
nodeItem.src_node_id = options.nodeIdMap[node.id];
}
if (node.type === '@n8n/n8n-nodes-langchain.agent') {
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
nodeItem.agent = (node.parameters.agent as string) || 'conversationalAgent';
} else if (node.type === 'n8n-nodes-base.httpRequest' && node.typeVersion === 1) {
} else if (node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 1) {
try {
nodeItem.domain = new URL(node.parameters.url as string).hostname;
} catch {
nodeItem.domain = getDomainBase(node.parameters.url as string);
}
} else if (node.type === 'n8n-nodes-base.httpRequest' && node.typeVersion > 1) {
} else if (node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion > 1) {
const { authentication } = node.parameters as { authentication: string };
nodeItem.credential_type = {
@@ -182,7 +191,7 @@ export function generateNodesGraph(
nodeItem.domain_base = getDomainBase(url);
nodeItem.domain_path = getDomainPath(url);
nodeItem.method = node.parameters.requestMethod as string;
} else if (node.type === 'n8n-nodes-base.webhook') {
} else if (node.type === WEBHOOK_NODE_TYPE) {
webhookNodeNames.push(node.name);
} else {
try {
@@ -216,6 +225,58 @@ export function generateNodesGraph(
}
}
if (options?.isCloudDeployment === true) {
if (node.type === OPENAI_LANGCHAIN_NODE_TYPE) {
nodeItem.prompts =
(((node.parameters?.messages as IDataObject) || {}).values as IDataObject[]) || [];
}
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
const prompts: IDataObject = {};
if (node.parameters?.text) {
prompts.text = node.parameters.text as string;
}
const nodeOptions = node.parameters?.options as IDataObject;
if (nodeOptions) {
const optionalMessagesKeys = [
'humanMessage',
'systemMessage',
'humanMessageTemplate',
'prefix',
'suffixChat',
'suffix',
'prefixPrompt',
'suffixPrompt',
];
for (const key of optionalMessagesKeys) {
if (nodeOptions[key]) {
prompts[key] = nodeOptions[key] as string;
}
}
}
if (Object.keys(prompts).length) {
nodeItem.prompts = prompts;
}
}
if (node.type === CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE) {
nodeItem.prompts = (
(((node.parameters?.options as IDataObject) || {})
.summarizationMethodAndPrompts as IDataObject) || {}
).values as IDataObject;
}
if (LANGCHAIN_CUSTOM_TOOLS.includes(node.type)) {
nodeItem.prompts = {
description: (node.parameters?.description as string) || '',
};
}
}
nodeGraph.nodes[index.toString()] = nodeItem;
nameIndices[node.name] = index.toString();
});