"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); }
};
var McpAuditService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.McpAuditService = void 0;
const api_prisma_1 = require("@hed-hog/api-prisma");
const common_1 = require("@nestjs/common");
const access_log_service_1 = require("../access-log/access-log.service");
let McpAuditService = McpAuditService_1 = class McpAuditService {
    constructor(prisma, accessLogService) {
        this.prisma = prisma;
        this.accessLogService = accessLogService;
        this.logger = new common_1.Logger(McpAuditService_1.name);
    }
    async record(data) {
        var _a;
        const sanitized = JSON.stringify(data.input).slice(0, 1000);
        try {
            await this.prisma.mcp_tool_call_log.create({
                data: {
                    user_id: data.userId || null,
                    tool_name: data.toolName,
                    input: sanitized,
                    success: data.success,
                    error: (_a = data.error) !== null && _a !== void 0 ? _a : null,
                    duration_ms: data.durationMs,
                },
            });
        }
        catch (e) {
            this.logger.warn(`Failed to persist MCP audit record: ${e.message}`);
        }
        this.accessLogService.recordMcp({
            userId: data.userId || undefined,
            mcpTool: data.toolName,
            mcpPrompt: sanitized,
        });
    }
};
exports.McpAuditService = McpAuditService;
exports.McpAuditService = McpAuditService = McpAuditService_1 = __decorate([
    (0, common_1.Injectable)(),
    __param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => access_log_service_1.AccessLogService))),
    __metadata("design:paramtypes", [api_prisma_1.PrismaService,
        access_log_service_1.AccessLogService])
], McpAuditService);
//# sourceMappingURL=mcp-audit.service.js.map