mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -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> {
|
||||
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 overlappingCount = Object.values(nodeGraph.notes).filter(
|
||||
|
@ -483,23 +487,26 @@ export class InternalHooks {
|
|||
workflowName: workflow.name,
|
||||
metaData: runData?.data?.resultData?.metadata,
|
||||
};
|
||||
promises.push(
|
||||
telemetryProperties.success
|
||||
? this.eventBus.sendWorkflowEvent({
|
||||
eventName: 'n8n.workflow.success',
|
||||
payload: sharedEventPayload,
|
||||
})
|
||||
: this.eventBus.sendWorkflowEvent({
|
||||
eventName: 'n8n.workflow.failed',
|
||||
payload: {
|
||||
...sharedEventPayload,
|
||||
lastNodeExecuted: runData?.data.resultData.lastNodeExecuted,
|
||||
errorNodeType: telemetryProperties.error_node_type,
|
||||
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
||||
errorMessage: telemetryProperties.error_message?.toString(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
let event;
|
||||
if (telemetryProperties.success) {
|
||||
event = this.eventBus.sendWorkflowEvent({
|
||||
eventName: 'n8n.workflow.success',
|
||||
payload: sharedEventPayload,
|
||||
});
|
||||
} else {
|
||||
event = this.eventBus.sendWorkflowEvent({
|
||||
eventName: 'n8n.workflow.failed',
|
||||
payload: {
|
||||
...sharedEventPayload,
|
||||
lastNodeExecuted: runData?.data.resultData.lastNodeExecuted,
|
||||
errorNodeType: telemetryProperties.error_node_type,
|
||||
errorNodeId: telemetryProperties.error_node_id?.toString(),
|
||||
errorMessage: telemetryProperties.error_message?.toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
promises.push(event);
|
||||
|
||||
void Promise.all([...promises, this.telemetry.trackWorkflowExecution(telemetryProperties)]);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ export const NODES_WITH_RENAMABLE_CONTENT = new Set([
|
|||
//@n8n/n8n-nodes-langchain
|
||||
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 CHAIN_LLM_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.chainLlm';
|
||||
export const OPENAI_LANGCHAIN_NODE_TYPE = '@n8n/n8n-nodes-langchain.openAi';
|
||||
export const CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE =
|
||||
'@n8n/n8n-nodes-langchain.chainSummarization';
|
||||
|
|
|
@ -13,6 +13,7 @@ import type {
|
|||
import { ApplicationError } from './errors/application.error';
|
||||
import {
|
||||
AGENT_LANGCHAIN_NODE_TYPE,
|
||||
CHAIN_LLM_LANGCHAIN_NODE_TYPE,
|
||||
CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE,
|
||||
HTTP_REQUEST_NODE_TYPE,
|
||||
LANGCHAIN_CUSTOM_TOOLS,
|
||||
|
@ -168,7 +169,7 @@ export function generateNodesGraph(
|
|||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
nodeItem.domain = new URL(node.parameters.url as string).hostname;
|
||||
|
@ -228,7 +229,7 @@ export function generateNodesGraph(
|
|||
if (options?.isCloudDeployment === true) {
|
||||
if (node.type === OPENAI_LANGCHAIN_NODE_TYPE) {
|
||||
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) {
|
||||
|
@ -265,16 +266,21 @@ export function generateNodesGraph(
|
|||
|
||||
if (node.type === CHAIN_SUMMARIZATION_LANGCHAIN_NODE_TYPE) {
|
||||
nodeItem.prompts = (
|
||||
(((node.parameters?.options as IDataObject) || {})
|
||||
.summarizationMethodAndPrompts as IDataObject) || {}
|
||||
(((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) || '',
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue