UNPKG

n8n-nodes-handit

Version:

n8n community nodes for Handit tracing and prompt management

219 lines 9.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HanditTracing = void 0; class HanditTracing { constructor() { this.description = { displayName: 'Handit Tracing', name: 'handitTracing', icon: 'file:handit.svg', group: ['transform'], version: 1, description: 'Collect workflow data and send to Handit API for tracing', defaults: { name: 'Handit Tracing', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'handitApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', options: [ { name: 'Trace Workflow', value: 'trace', description: 'Collect and send workflow data to Handit API', action: 'Trace workflow data', }, ], default: 'trace', noDataExpression: true, }, { displayName: 'User Token', name: 'userToken', type: 'string', typeOptions: { password: true, }, default: '', required: true, description: 'Your Handit user token for authentication', displayOptions: { show: { operation: ['trace'], }, }, }, { displayName: 'Node Names', name: 'nodeNames', type: 'string', default: '', placeholder: 'Telegram Trigger, Edit Fields, AI Agent, Telegram', description: 'Comma-separated list of node names to trace (leave empty to auto-detect)', displayOptions: { show: { operation: ['trace'], }, }, }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { operation: ['trace'], }, }, options: [ { displayName: 'Workflow ID', name: 'workflowId', type: 'string', default: '', description: 'Custom workflow identifier', }, { displayName: 'User ID', name: 'userId', type: 'string', default: '', description: 'User identifier for tracing', }, { displayName: 'Environment', name: 'environment', type: 'options', options: [ { name: 'Development', value: 'development', }, { name: 'Staging', value: 'staging', }, { name: 'Production', value: 'production', }, ], default: 'production', description: 'Environment where the workflow is running', }, ], }, ], }; } async execute() { var _a; const items = this.getInputData(); const returnData = []; const operation = this.getNodeParameter('operation', 0); if (operation === 'trace') { for (let i = 0; i < items.length; i++) { try { const apiEndpoint = 'https://handit-api-oss-299768392189.us-central1.run.app/api/track'; const userToken = this.getNodeParameter('userToken', i); const nodeNamesInput = this.getNodeParameter('nodeNames', i); const additionalFields = this.getNodeParameter('additionalFields', i); let nodeNames = []; if (nodeNamesInput.trim()) { nodeNames = nodeNamesInput.split(',').map(name => name.trim()); } else { nodeNames = ['Telegram Trigger', 'Edit Fields', 'AI Agent', 'Telegram']; } const workflowDataArray = []; for (let j = 0; j < nodeNames.length; j++) { const nodeName = nodeNames[j]; try { let output = {}; let input = {}; let previousSteps = {}; try { const inputData = this.getInputData(); if (inputData && inputData.length > i) { output = inputData[i].json || {}; if (output['intermediateSteps']) { previousSteps = output['intermediateSteps']; } } } catch (error) { } input = { nodeName, timestamp: new Date().toISOString(), ...additionalFields, }; workflowDataArray.push({ slug: nodeName, input: { ...input, previousSteps, }, output, }); } catch (error) { workflowDataArray.push({ slug: nodeName, input: { nodeName }, output: {}, error: error.message, }); } } const payload = { workflowData: workflowDataArray, timestamp: new Date().toISOString(), executionId: ((_a = this.getExecutionId) === null || _a === void 0 ? void 0 : _a.call(this)) || 'unknown', workflowId: additionalFields.workflowId || 'unknown', ...additionalFields, }; const requestOptions = { method: 'POST', url: apiEndpoint, body: payload, json: true, headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${userToken}`, }, }; const response = await this.helpers.requestWithAuthentication.call(this, 'handitApi', requestOptions); returnData.push({ success: true, response, tracedNodes: nodeNames.length, payload, }); } catch (error) { returnData.push({ success: false, error: error.message, timestamp: new Date().toISOString(), }); } } } return [this.helpers.returnJsonArray(returnData)]; } } exports.HanditTracing = HanditTracing; //# sourceMappingURL=HanditTracing.node.js.map