"use strict";
// =============================================================================
// Coolify tool registrations (in-process path used by agent-runner).
//
// All logic lives in ./coolify-api.ts so the MCP server (src/mcp/coolify-server.ts)
// and this in-process registry call the exact same code path. Keep this file
// purely about: (a) surface-shape for the LLM (name/description/parameters),
// (b) mapping ctx.coolify → CoolifyConfig. No business logic here.
// =============================================================================
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const registry_1 = require("./registry");
const api = __importStar(require("./coolify-api"));
(0, registry_1.registerTool)({
    name: 'coolify_list_projects',
    description: 'List all projects in the Coolify instance. Returns project names and UUIDs.',
    parameters: { type: 'object', properties: {} },
    async handler(_args, ctx) {
        return api.listProjects(ctx.coolify);
    }
});
(0, registry_1.registerTool)({
    name: 'coolify_list_applications',
    description: 'List applications in a Coolify project.',
    parameters: {
        type: 'object',
        properties: {
            project_uuid: { type: 'string', description: 'Project UUID from coolify_list_projects' }
        },
        required: ['project_uuid']
    },
    async handler(args, ctx) {
        return api.listApplications(ctx.coolify, String(args.project_uuid));
    }
});
(0, registry_1.registerTool)({
    name: 'coolify_deploy',
    description: 'Trigger a deployment for a Coolify application.',
    parameters: {
        type: 'object',
        properties: {
            application_uuid: { type: 'string', description: 'Application UUID to deploy' }
        },
        required: ['application_uuid']
    },
    async handler(args, ctx) {
        return api.deploy(ctx.coolify, String(args.application_uuid));
    }
});
(0, registry_1.registerTool)({
    name: 'coolify_get_logs',
    description: 'Get recent deployment logs for a Coolify application.',
    parameters: {
        type: 'object',
        properties: {
            application_uuid: { type: 'string', description: 'Application UUID' }
        },
        required: ['application_uuid']
    },
    async handler(args, ctx) {
        return api.getLogs(ctx.coolify, String(args.application_uuid));
    }
});
(0, registry_1.registerTool)({
    name: 'list_all_apps',
    description: 'List all Coolify applications across all projects with their status (running/stopped/error) and domain.',
    parameters: { type: 'object', properties: {} },
    async handler(_args, ctx) {
        return api.listAllApps(ctx.coolify);
    }
});
(0, registry_1.registerTool)({
    name: 'get_app_status',
    description: 'Get the current deployment status and recent logs for a specific Coolify application by name or UUID.',
    parameters: {
        type: 'object',
        properties: {
            app_name: { type: 'string', description: 'Application name (e.g. "vibn-frontend") or UUID' }
        },
        required: ['app_name']
    },
    async handler(args, ctx) {
        return api.getAppStatus(ctx.coolify, String(args.app_name));
    }
});
(0, registry_1.registerTool)({
    name: 'deploy_app',
    description: 'Trigger a Coolify deployment for an app by name. Use after an agent commits code.',
    parameters: {
        type: 'object',
        properties: {
            app_name: { type: 'string', description: 'Application name (e.g. "vibn-frontend")' }
        },
        required: ['app_name']
    },
    async handler(args, ctx) {
        return api.deployApp(ctx.coolify, String(args.app_name));
    }
});
