UNPKG

n8n-nodes-smartgent

Version:

SmartGent custom nodes for n8n - AI-powered automation and intelligent workflow integrations including LiteLLM chat completions, SharePoint file monitoring, and enterprise search

260 lines 11.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartGentEnterpriseSearch = void 0; const n8n_workflow_1 = require("n8n-workflow"); class SmartGentEnterpriseSearch { constructor() { this.description = { displayName: 'SmartGent Enterprise Search', name: 'smartGentEnterpriseSearch', icon: 'file:smartgent.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] === "getChatbots" ? "Get Chatbots" : $parameter["operation"] + ": " + $parameter["query"]}}', description: 'Search enterprise data using SmartGent AI-powered search', defaults: { name: 'SmartGent Enterprise Search', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'smartGentApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Get Chatbots', value: 'getChatbots', description: 'Retrieve list of available chatbots', action: 'Retrieve list of available chatbots', }, { name: 'Search', value: 'search', description: 'Search using a selected chatbot', action: 'Search using a selected chatbot', }, ], default: 'getChatbots', required: true, }, { displayName: 'Chatbot Name or ID', name: 'chatbotGuid', type: 'options', typeOptions: { loadOptionsMethod: 'getChatbots', }, default: '', required: true, displayOptions: { show: { operation: ['search'], }, }, description: 'Select the chatbot to use for search. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.', }, { displayName: 'Search Query', name: 'query', type: 'string', default: '', required: true, placeholder: 'Enter your search query...', description: 'The search query to execute', displayOptions: { show: { operation: ['search'], }, }, }, { displayName: 'Additional Options', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, options: [ { displayName: 'Max Results', name: 'maxResults', type: 'number', default: 10, description: 'Maximum number of results to return', }, { displayName: 'Include Pricing', name: 'includePricing', type: 'boolean', default: true, description: 'Whether to include pricing information in results', }, { displayName: 'Search Filters', name: 'filters', type: 'fixedCollection', placeholder: 'Add Filter', typeOptions: { multipleValues: true, }, default: {}, options: [ { name: 'filter', displayName: 'Filter', values: [ { displayName: 'Field', name: 'field', type: 'string', default: '', description: 'Field to filter on', }, { displayName: 'Value', name: 'value', type: 'string', default: '', description: 'Filter value', }, ], }, ], }, ], }, ], }; this.methods = { loadOptions: { async getChatbots() { try { const credentials = await this.getCredentials('smartGentApi'); const options = { method: 'GET', url: `${credentials.baseUrl}/api/v1/rag/enterprise/group/chatbot`, headers: { 'smartgen-api-key': credentials.apiKey, Accept: 'application/json', }, json: true, }; const response = await this.helpers.httpRequest(options); if (response.success && Array.isArray(response.result)) { return response.result.map((chatbot) => ({ name: chatbot.name, value: chatbot.guid, })); } return []; } catch (error) { return []; } }, }, }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const operation = this.getNodeParameter('operation', i); if (operation === 'getChatbots') { const credentials = await this.getCredentials('smartGentApi'); const options = { method: 'GET', url: `${credentials.baseUrl}/api/v1/rag/enterprise/group/chatbot`, headers: { 'smartgen-api-key': credentials.apiKey, Accept: 'application/json', }, json: true, }; const response = await this.helpers.httpRequest(options); const executionData = { json: { operation: 'getChatbots', success: response.success || false, chatbots: response.result || [], chatbotCount: Array.isArray(response.result) ? response.result.length : 0, timestamp: new Date().toISOString(), }, pairedItem: { item: i }, }; returnData.push(executionData); } else if (operation === 'search') { const chatbotGuid = this.getNodeParameter('chatbotGuid', i); const query = this.getNodeParameter('query', i); const additionalFields = this.getNodeParameter('additionalFields', i); const formData = { question: query, chatbot_guid: chatbotGuid, }; if (additionalFields.maxResults) { formData.limit = additionalFields.maxResults.toString(); } const formDataString = Object.keys(formData) .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(formData[key])}`) .join('&'); const credentials = await this.getCredentials('smartGentApi'); const options = { method: 'POST', url: `${credentials.baseUrl}/api/v1/rag/enterprise/groupsearch`, headers: { 'smartgen-api-key': credentials.apiKey, Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', }, body: formDataString, json: true, }; const response = await this.helpers.httpRequest(options); const executionData = { json: { operation: 'search', chatbotGuid, query, results: response, timestamp: new Date().toISOString(), resultCount: Array.isArray(response.results) ? response.results.length : 0, }, pairedItem: { item: i }, }; returnData.push(executionData); } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, operation: this.getNodeParameter('operation', i), timestamp: new Date().toISOString(), }, pairedItem: { item: i }, }); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i, description: `Failed to execute SmartGent Enterprise Search: ${error.message}`, }); } } } return [returnData]; } } exports.SmartGentEnterpriseSearch = SmartGentEnterpriseSearch; //# sourceMappingURL=SmartGentEnterpriseSearch.node.js.map