mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08: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,13 +487,14 @@ 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 {
|
||||||
|
event = this.eventBus.sendWorkflowEvent({
|
||||||
eventName: 'n8n.workflow.failed',
|
eventName: 'n8n.workflow.failed',
|
||||||
payload: {
|
payload: {
|
||||||
...sharedEventPayload,
|
...sharedEventPayload,
|
||||||
|
@ -498,8 +503,10 @@ export class InternalHooks {
|
||||||
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
||||||
errorMessage: telemetryProperties.error_message?.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 a new issue