"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 __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreAiMcpTools = void 0;
const common_1 = require("@nestjs/common");
const ai_service_1 = require("../../ai/ai.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreAiMcpTools = class CoreAiMcpTools {
    constructor(aiService) {
        this.aiService = aiService;
    }
    async chat(args, _context) {
        return this.aiService.chat({ message: args.message, context: args.context });
    }
    async listAgents(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.aiService.listAgents({
            page: (_a = args.page) !== null && _a !== void 0 ? _a : 1,
            pageSize: (_b = args.pageSize) !== null && _b !== void 0 ? _b : 20,
            search: (_c = args.search) !== null && _c !== void 0 ? _c : '',
            sortField: (_d = args.sortField) !== null && _d !== void 0 ? _d : 'id',
            sortOrder: (_e = args.sortOrder) !== null && _e !== void 0 ? _e : 'asc',
            fields: '',
        });
    }
    async getAgent(args, _context) {
        return this.aiService.getAgentById(args.agentId);
    }
    async getAgentBySlug(args, _context) {
        return this.aiService.getAgentBySlug(args.slug);
    }
    async createAgent(args, _context) {
        return this.aiService.createAgent(args);
    }
    async updateAgent(args, _context) {
        const { agentId } = args, data = __rest(args, ["agentId"]);
        return this.aiService.updateAgent(agentId, data);
    }
    async deleteAgents(args, _context) {
        return this.aiService.deleteAgents({ ids: args.ids });
    }
    async chatWithAgent(args, _context) {
        return this.aiService.chatWithAgent(args.slug, { message: args.message, context: args.context });
    }
};
exports.CoreAiMcpTools = CoreAiMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.chat',
        description: 'Sends a message to the AI and returns a response.',
        inputSchema: {
            type: 'object',
            properties: {
                message: { type: 'string', description: 'Message to send to the AI' },
                context: { type: 'string', description: 'Additional context for the AI' },
            },
            required: ['message'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "chat", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.list',
        description: 'Lists AI agents with optional pagination. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
                search: { type: 'string', description: 'Search term' },
                sortField: { type: 'string', description: 'Field to sort by' },
                sortOrder: { type: 'string', enum: ['asc', 'desc'], description: 'Sort direction' },
            },
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "listAgents", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.get',
        description: 'Returns a single AI agent by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                agentId: { type: 'number', description: 'Agent ID' },
            },
            required: ['agentId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "getAgent", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.get-by-slug',
        description: 'Returns a single AI agent by slug.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Agent slug' },
            },
            required: ['slug'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "getAgentBySlug", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.create',
        description: 'Creates a new AI agent. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Agent slug (unique identifier)' },
                provider: { type: 'string', description: 'AI provider (e.g. openai, gemini)' },
                model: { type: 'string', description: 'AI model identifier' },
                instructions: { type: 'string', description: 'System instructions for the agent' },
            },
            required: ['slug'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "createAgent", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.update',
        description: 'Updates an existing AI agent by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                agentId: { type: 'number', description: 'Agent ID' },
                slug: { type: 'string', description: 'New slug' },
                provider: { type: 'string', description: 'New AI provider' },
                model: { type: 'string', description: 'New AI model' },
                instructions: { type: 'string', description: 'New system instructions' },
            },
            required: ['agentId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "updateAgent", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.delete',
        description: 'Deletes one or more AI agents by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Agent IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "deleteAgents", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.ai.agents.chat',
        description: 'Sends a message to a specific AI agent and returns a response.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Agent slug' },
                message: { type: 'string', description: 'Message to send to the agent' },
                context: { type: 'string', description: 'Additional context for the agent' },
            },
            required: ['slug', 'message'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreAiMcpTools.prototype, "chatWithAgent", null);
exports.CoreAiMcpTools = CoreAiMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [ai_service_1.AiService])
], CoreAiMcpTools);
//# sourceMappingURL=core-ai.mcp-tools.js.map