n8n
Version:
n8n Workflow Automation Tool
64 lines • 3.2 kB
JavaScript
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AiAssistantController = void 0;
const decorators_1 = require("../decorators");
const aiAsisstant_service_1 = require("../services/aiAsisstant.service");
const node_stream_1 = require("node:stream");
const openapi_validator_1 = require("express-openapi-validator/dist/openapi.validator");
const node_assert_1 = require("node:assert");
const n8n_workflow_1 = require("n8n-workflow");
let AiAssistantController = class AiAssistantController {
constructor(aiAssistantService) {
this.aiAssistantService = aiAssistantService;
}
async chat(req, res) {
try {
const stream = await this.aiAssistantService.chat(req.body, req.user);
if (stream.body) {
await node_stream_1.promises.pipeline(node_stream_1.Readable.fromWeb(stream.body), res);
}
}
catch (e) {
(0, node_assert_1.strict)(e instanceof Error);
n8n_workflow_1.ErrorReporterProxy.error(e);
throw new openapi_validator_1.InternalServerError({ message: `Something went wrong: ${e.message}` });
}
}
async applySuggestion(req) {
try {
return await this.aiAssistantService.applySuggestion(req.body, req.user);
}
catch (e) {
(0, node_assert_1.strict)(e instanceof Error);
n8n_workflow_1.ErrorReporterProxy.error(e);
throw new openapi_validator_1.InternalServerError({ message: `Something went wrong: ${e.message}` });
}
}
};
exports.AiAssistantController = AiAssistantController;
__decorate([
(0, decorators_1.Post)('/chat', { rateLimit: { limit: 100 } }),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], AiAssistantController.prototype, "chat", null);
__decorate([
(0, decorators_1.Post)('/chat/apply-suggestion'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], AiAssistantController.prototype, "applySuggestion", null);
exports.AiAssistantController = AiAssistantController = __decorate([
(0, decorators_1.RestController)('/ai-assistant'),
__metadata("design:paramtypes", [aiAsisstant_service_1.AiAssistantService])
], AiAssistantController);
//# sourceMappingURL=aiAssistant.controller.js.map
;