UNPKG

n8n

Version:

n8n Workflow Automation Tool

63 lines 2.88 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AiAssistantService = void 0; const typedi_1 = require("typedi"); const ai_assistant_sdk_1 = require("@n8n_io/ai-assistant-sdk"); const n8n_workflow_1 = require("n8n-workflow"); const License_1 = require("../License"); const constants_1 = require("../constants"); const config_1 = __importDefault(require("../config")); let AiAssistantService = class AiAssistantService { constructor(licenseService) { this.licenseService = licenseService; } async init() { const aiAssistantEnabled = this.licenseService.isAiAssistantEnabled(); if (!aiAssistantEnabled) { return; } const licenseCert = await this.licenseService.loadCertStr(); const consumerId = this.licenseService.getConsumerId(); const baseUrl = config_1.default.get('aiAssistant.baseUrl'); const logLevel = config_1.default.getEnv('logs.level'); this.client = new ai_assistant_sdk_1.AiAssistantClient({ licenseCert, consumerId, n8nVersion: constants_1.N8N_VERSION, baseUrl, logLevel, }); } async chat(payload, user) { if (!this.client) { await this.init(); } (0, n8n_workflow_1.assert)(this.client, 'Assistant client not setup'); return await this.client.chat(payload, { id: user.id }); } async applySuggestion(payload, user) { if (!this.client) { await this.init(); } (0, n8n_workflow_1.assert)(this.client, 'Assistant client not setup'); return await this.client.applySuggestion(payload, { id: user.id }); } }; exports.AiAssistantService = AiAssistantService; exports.AiAssistantService = AiAssistantService = __decorate([ (0, typedi_1.Service)(), __metadata("design:paramtypes", [License_1.License]) ], AiAssistantService); //# sourceMappingURL=aiAsisstant.service.js.map