mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-11 13:15:28 +03:00
feat: Telemetry include basic llm optional promps, trigger on save workflow event (#8981)
This commit is contained in:
parent
295b650fb8
commit
335f363ca1
@ -202,7 +202,11 @@ export class InternalHooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onWorkflowSaved(user: User, workflow: IWorkflowDb, publicApi: boolean): Promise<void> {
|
async onWorkflowSaved(user: User, workflow: IWorkflowDb, publicApi: boolean): Promise<void> {
|
||||||
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow, this.nodeTypes);
|
const isCloudDeployment = config.getEnv('deployment.type') === 'cloud';
|
||||||
|
|
||||||
|
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow, this.nodeTypes, {
|
||||||
|
isCloudDeployment,
|
||||||
|
});
|
||||||
|
|
||||||
const notesCount = Object.keys(nodeGraph.notes).length;
|
const notesCount = Object.keys(nodeGraph.notes).length;
|
||||||
const overlappingCount = Object.values(nodeGraph.notes).filter(
|
const overlappingCount = Object.values(nodeGraph.notes).filter(
|
||||||
@ -483,23 +487,26 @@ export class InternalHooks {
|
|||||||
workflowName: workflow.name,
|
workflowName: workflow.name,
|
||||||
metaData: runData?.data?.resultData?.metadata,
|
metaData: runData?.data?.resultData?.metadata,
|
||||||
};
|
};
|
||||||
promises.push(
|
let event;
|
||||||
telemetryProperties.success
|
if (telemetryProperties.success) {
|
||||||
? this.eventBus.sendWorkflowEvent({
|
event = this.eventBus.sendWorkflowEvent({
|
||||||
eventName: 'n8n.workflow.success',
|
eventName: 'n8n.workflow.success',
|
||||||
payload: sharedEventPayload,
|
payload: sharedEventPayload,
|
||||||
})
|
});
|
||||||
: this.eventBus.sendWorkflowEvent({
|
} else {
|
||||||
eventName: 'n8n.workflow.failed',
|
event = this.eventBus.sendWorkflowEvent({
|
||||||
payload: {
|
eventName: 'n8n.workflow.failed',
|
||||||
...sharedEventPayload,
|
payload: {
|
||||||
lastNodeExecuted: runData?.data.resultData.lastNodeExecuted,
|
...sharedEventPayload,
|
||||||
errorNodeType: telemetryProperties.error_node_type,
|
lastNodeExecuted: runData?.data.resultData.lastNodeExecuted,
|
||||||
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
errorNodeType: telemetryProperties.error_node_type,
|
||||||
errorMessage: telemetryProperties.error_message?.toString(),
|
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
||||||
},
|
errorMessage: telemetryProperties.error_message?.toString(),
|
||||||
}),
|
},
|
||||||
);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
promises.push(event);
|
||||||
|
|
||||||
void Promise.all([...promises, this.telemetry.trackWorkflowExecution(telemetryProperties)]);
|
void Promise.all([...promises, this.telemetry.trackWorkflowExecution(telemetryProperties)]);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ export const NODES_WITH_RENAMABLE_CONTENT = new Set([
|
|||||||
//@n8n/n8n-nodes-langchain
|
//@n8n/n8n-nodes-langchain
|
||||||
export const MANUAL_CHAT_TRIGGER_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.manualChatTrigger';
|
export const MANUAL_CHAT_TRIGGER_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.manualChatTrigger';
|
||||||
export const AGENT_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.agent';
|
export const AGENT_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.agent';
|
||||||
|
export const CHAIN_LLM_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.chainLlm';
|
||||||
export const OPENAI_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.openAi';
|
export const OPENAI_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.openAi';
|
||||||
export const CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE =
|
export const CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE =
|
||||||
'@n8n/n8n-nodes-langchain.chainSummarization';
|
'@n8n/n8n-nodes-langchain.chainSummarization';
|
||||||
|
@ -13,6 +13,7 @@ import type {
|
|||||||
import { ApplicationError } from './errors/application.error';
|
import { ApplicationError } from './errors/application.error';
|
||||||
import {
|
import {
|
||||||
AGENT_LANGCHAIN_NODE_TYPE,
|
AGENT_LANGCHAIN_NODE_TYPE,
|
||||||
|
CHAIN_LLM_LANGCHAIN_NODE_TYPE,
|
||||||
CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE,
|
CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE,
|
||||||
HTTP_REQUEST_NODE_TYPE,
|
HTTP_REQUEST_NODE_TYPE,
|
||||||
LANGCHAIN_CUSTOM_TOOLS,
|
LANGCHAIN_CUSTOM_TOOLS,
|
||||||
@ -168,7 +169,7 @@ export function generateNodesGraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
|
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
|
||||||
nodeItem.agent = (node.parameters.agent as string) || 'conversationalAgent';
|
nodeItem.agent = (node.parameters.agent as string) ?? 'conversationalAgent';
|
||||||
} else if (node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 1) {
|
} else if (node.type === HTTP_REQUEST_NODE_TYPE && node.typeVersion === 1) {
|
||||||
try {
|
try {
|
||||||
nodeItem.domain = new URL(node.parameters.url as string).hostname;
|
nodeItem.domain = new URL(node.parameters.url as string).hostname;
|
||||||
@ -228,7 +229,7 @@ export function generateNodesGraph(
|
|||||||
if (options?.isCloudDeployment === true) {
|
if (options?.isCloudDeployment === true) {
|
||||||
if (node.type === OPENAI_LANGCHAIN_NODE_TYPE) {
|
if (node.type === OPENAI_LANGCHAIN_NODE_TYPE) {
|
||||||
nodeItem.prompts =
|
nodeItem.prompts =
|
||||||
(((node.parameters?.messages as IDataObject) || {}).values as IDataObject[]) || [];
|
(((node.parameters?.messages as IDataObject) ?? {}).values as IDataObject[]) ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
|
if (node.type === AGENT_LANGCHAIN_NODE_TYPE) {
|
||||||
@ -265,16 +266,21 @@ export function generateNodesGraph(
|
|||||||
|
|
||||||
if (node.type === CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE) {
|
if (node.type === CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE) {
|
||||||
nodeItem.prompts = (
|
nodeItem.prompts = (
|
||||||
(((node.parameters?.options as IDataObject) || {})
|
(((node.parameters?.options as IDataObject) ?? {})
|
||||||
.summarizationMethodAndPrompts as IDataObject) || {}
|
.summarizationMethodAndPrompts as IDataObject) ?? {}
|
||||||
).values as IDataObject;
|
).values as IDataObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LANGCHAIN_CUSTOM_TOOLS.includes(node.type)) {
|
if (LANGCHAIN_CUSTOM_TOOLS.includes(node.type)) {
|
||||||
nodeItem.prompts = {
|
nodeItem.prompts = {
|
||||||
description: (node.parameters?.description as string) || '',
|
description: (node.parameters?.description as string) ?? '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === CHAIN_LLM_LANGCHAIN_NODE_TYPE) {
|
||||||
|
nodeItem.prompts =
|
||||||
|
(((node.parameters?.messages as IDataObject) ?? {}).messageValues as IDataObject[]) ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeGraph.nodes[index.toString()] = nodeItem;
|
nodeGraph.nodes[index.toString()] = nodeItem;
|
||||||
|
Loading…
Reference in New Issue
Block a user