UNPKG

n8n-nodes-flowengine-workflow-builder

Version:

n8n community node for FlowEngine Workflow Builder - AI-powered workflow automation

172 lines 6.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowEngineWorkflowBuilder = void 0; const n8n_workflow_1 = require("n8n-workflow"); class FlowEngineWorkflowBuilder { constructor() { this.description = { displayName: 'FlowEngine Workflow Builder', name: 'flowEngineWorkflowBuilder', icon: 'file:flowengine.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'AI-powered workflow automation with FlowEngine', defaults: { name: 'FlowEngine Workflow Builder', }, usableAsTool: true, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'flowEngineWorkflowBuilderApi', required: true, }, ], properties: [ { displayName: 'For API key, go to <a href="https://flowengine.cloud/settings" target="_blank">flowengine.cloud/settings</a>', name: 'notice', type: 'notice', default: '', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Send Message', value: 'sendMessage', description: 'Send a message to FlowEngine AI', action: 'Send a message to flow engine ai', }, ], default: 'sendMessage', }, { displayName: 'Message', name: 'message', type: 'string', typeOptions: { rows: 4, }, default: '', required: true, description: 'The message to send to FlowEngine AI', displayOptions: { show: { operation: ['sendMessage'], }, }, }, { displayName: 'Model', name: 'model', type: 'options', options: [ { name: 'Regular', value: 'regular', description: 'Standard AI model (faster, lower cost)', }, { name: 'Boost', value: 'boost', description: 'More powerful AI model (slower, higher cost)', }, ], default: 'regular', description: 'Choose which AI model to use', displayOptions: { show: { operation: ['sendMessage'], }, }, }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { operation: ['sendMessage'], }, }, options: [ { displayName: 'Conversation ID', name: 'conversationId', type: 'string', default: '', description: 'Optional conversation ID to continue an existing conversation', }, ], }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { if (operation === 'sendMessage') { const message = this.getNodeParameter('message', i); const model = this.getNodeParameter('model', i); const additionalFields = this.getNodeParameter('additionalFields', i); const body = { message, }; if (model && model !== 'regular') { body.model = model; } if (additionalFields.conversationId) { body.conversation_id = additionalFields.conversationId; } const response = await this.helpers.httpRequestWithAuthentication.call(this, 'flowEngineWorkflowBuilderApi', { method: 'POST', url: 'https://flowengine.cloud/api/v1/chat', body, json: true, }); if (response.success) { returnData.push({ json: { success: true, response: response.response, conversation_id: response.conversation_id, credits_remaining: response.credits_remaining, }, pairedItem: i, }); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `FlowEngine API error: ${response.error || 'Unknown error'}`, { itemIndex: i }); } } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { success: false, error: error instanceof Error ? error.message : 'Unknown error', }, pairedItem: i, }); continue; } throw error; } } return [returnData]; } } exports.FlowEngineWorkflowBuilder = FlowEngineWorkflowBuilder; //# sourceMappingURL=FlowEngineWorkflowBuilder.node.js.map