template-saas/apps/backend/dist/modules/ai/ai.controller.js
rckrdmrd 50a821a415
Some checks failed
CI / Backend CI (push) Has been cancelled
CI / Frontend CI (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / CI Summary (push) Has been cancelled
[SIMCO-V38] feat: Actualizar a SIMCO v3.8.0
- HERENCIA-SIMCO.md actualizado con directivas v3.7 y v3.8
- Actualizaciones de configuracion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 08:53:08 -06:00

128 lines
6.0 KiB
JavaScript

"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 __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const jwt_auth_guard_1 = require("../auth/guards/jwt-auth.guard");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
const services_1 = require("./services");
const dto_1 = require("./dto");
let AIController = class AIController {
constructor(aiService) {
this.aiService = aiService;
}
async chat(user, dto) {
return this.aiService.chat(user.tenant_id, user.id, dto);
}
async getModels() {
return this.aiService.getModels();
}
async getConfig(user) {
const config = await this.aiService.getConfig(user.tenant_id);
return config;
}
async updateConfig(user, dto) {
const config = await this.aiService.updateConfig(user.tenant_id, dto);
return config;
}
async getUsage(user, page = 1, limit = 20) {
return this.aiService.getUsageHistory(user.tenant_id, page, limit);
}
async getCurrentUsage(user) {
return this.aiService.getCurrentMonthUsage(user.tenant_id);
}
async health() {
return {
status: this.aiService.isServiceReady() ? 'ready' : 'not_configured',
timestamp: new Date().toISOString(),
};
}
};
exports.AIController = AIController;
__decorate([
(0, common_1.Post)('chat'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiOperation)({ summary: 'Send chat completion request' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Chat response', type: dto_1.ChatResponseDto }),
(0, swagger_1.ApiResponse)({ status: 400, description: 'Bad request or AI disabled' }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, dto_1.ChatRequestDto]),
__metadata("design:returntype", Promise)
], AIController.prototype, "chat", null);
__decorate([
(0, common_1.Get)('models'),
(0, swagger_1.ApiOperation)({ summary: 'List available AI models' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'List of models', type: [dto_1.AIModelDto] }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], AIController.prototype, "getModels", null);
__decorate([
(0, common_1.Get)('config'),
(0, swagger_1.ApiOperation)({ summary: 'Get AI configuration for tenant' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'AI configuration', type: dto_1.AIConfigResponseDto }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], AIController.prototype, "getConfig", null);
__decorate([
(0, common_1.Patch)('config'),
(0, swagger_1.ApiOperation)({ summary: 'Update AI configuration' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Updated configuration', type: dto_1.AIConfigResponseDto }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, dto_1.UpdateAIConfigDto]),
__metadata("design:returntype", Promise)
], AIController.prototype, "updateConfig", null);
__decorate([
(0, common_1.Get)('usage'),
(0, swagger_1.ApiOperation)({ summary: 'Get usage history' }),
(0, swagger_1.ApiQuery)({ name: 'page', required: false, type: Number }),
(0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Query)('page')),
__param(2, (0, common_1.Query)('limit')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object, Object]),
__metadata("design:returntype", Promise)
], AIController.prototype, "getUsage", null);
__decorate([
(0, common_1.Get)('usage/current'),
(0, swagger_1.ApiOperation)({ summary: 'Get current month usage stats' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Usage statistics', type: dto_1.UsageStatsDto }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], AIController.prototype, "getCurrentUsage", null);
__decorate([
(0, common_1.Get)('health'),
(0, swagger_1.ApiOperation)({ summary: 'Check AI service health' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], AIController.prototype, "health", null);
exports.AIController = AIController = __decorate([
(0, swagger_1.ApiTags)('ai'),
(0, common_1.Controller)('ai'),
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
(0, swagger_1.ApiBearerAuth)(),
__metadata("design:paramtypes", [services_1.AIService])
], AIController);
//# sourceMappingURL=ai.controller.js.map