"use strict";
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
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 });
exports.registerMcpTool = exports.getToolContext = exports.getActivityIdentity = exports.McpEscalationStrategy = exports.DefaultEscalationStrategy = exports.escalationStrategyRegistry = exports.McpVisionServer = exports.McpTranslationServer = exports.McpServer = exports.McpClient = exports.McpService = exports.BuiltInMcpAdapter = exports.mcpRegistry = exports.defaultMaintenanceConfig = exports.maintenanceRegistry = exports.PinoLoggerAdapter = exports.loggerRegistry = exports.HoneycombTelemetryAdapter = exports.telemetryRegistry = exports.publishKnowledgeEvent = exports.publishAgentEvent = exports.publishWorkflowEvent = exports.publishActivityEvent = exports.publishEscalationEvent = exports.publishTaskEvent = exports.publishMilestoneEvent = exports.SocketIOEventAdapter = exports.InMemoryEventAdapter = exports.NatsEventAdapter = exports.eventRegistry = exports.ltConfig = exports.seedConfigTopics = exports.seedSystemTopics = exports.TopicService = exports.UserService = exports.ConfigService = exports.EscalationService = exports.TaskService = exports.setAuthAdapter = exports.signToken = exports.requireAdmin = exports.requireAuth = exports.createAuthMiddleware = exports.JwtAuthAdapter = exports.conditionLT = exports.executeLT = exports.createLTActivityInterceptor = exports.createLTInterceptor = exports.registerLT = exports.start = void 0;
exports.LTExpressAdapter = exports.api = exports.KnowledgeApi = exports.resolveCredential = exports.mimeFromPath = exports.getStorageBackend = exports.listOAuthConnections = exports.getFreshAccessToken = exports.createClient = exports.CallbackEventAdapter = exports.builtinMcpServerFactories = exports.getSystemAgents = exports.getSystemWorkers = void 0;
const config_1 = require("./modules/config");
const logger_1 = require("./lib/logger");
const start_1 = require("./start");
// ─── Package Exports ─────────────────────────────────────────────────────────
var start_2 = require("./start");
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_2.start; } });
var interceptor_1 = require("./services/interceptor");
Object.defineProperty(exports, "registerLT", { enumerable: true, get: function () { return interceptor_1.registerLT; } });
Object.defineProperty(exports, "createLTInterceptor", { enumerable: true, get: function () { return interceptor_1.createLTInterceptor; } });
var activity_interceptor_1 = require("./services/interceptor/activity-interceptor");
Object.defineProperty(exports, "createLTActivityInterceptor", { enumerable: true, get: function () { return activity_interceptor_1.createLTActivityInterceptor; } });
var orchestrator_1 = require("./services/orchestrator");
Object.defineProperty(exports, "executeLT", { enumerable: true, get: function () { return orchestrator_1.executeLT; } });
var condition_1 = require("./services/orchestrator/condition");
Object.defineProperty(exports, "conditionLT", { enumerable: true, get: function () { return condition_1.conditionLT; } });
var auth_1 = require("./modules/auth");
Object.defineProperty(exports, "JwtAuthAdapter", { enumerable: true, get: function () { return auth_1.JwtAuthAdapter; } });
Object.defineProperty(exports, "createAuthMiddleware", { enumerable: true, get: function () { return auth_1.createAuthMiddleware; } });
Object.defineProperty(exports, "requireAuth", { enumerable: true, get: function () { return auth_1.requireAuth; } });
Object.defineProperty(exports, "requireAdmin", { enumerable: true, get: function () { return auth_1.requireAdmin; } });
Object.defineProperty(exports, "signToken", { enumerable: true, get: function () { return auth_1.signToken; } });
Object.defineProperty(exports, "setAuthAdapter", { enumerable: true, get: function () { return auth_1.setAuthAdapter; } });
__exportStar(require("./types"), exports);
exports.TaskService = __importStar(require("./services/task"));
exports.EscalationService = __importStar(require("./services/escalation"));
exports.ConfigService = __importStar(require("./services/config"));
exports.UserService = __importStar(require("./services/user"));
exports.TopicService = __importStar(require("./services/topics"));
var system_topics_1 = require("./services/topics/system-topics");
Object.defineProperty(exports, "seedSystemTopics", { enumerable: true, get: function () { return system_topics_1.seedSystemTopics; } });
Object.defineProperty(exports, "seedConfigTopics", { enumerable: true, get: function () { return system_topics_1.seedConfigTopics; } });
var ltconfig_1 = require("./modules/ltconfig");
Object.defineProperty(exports, "ltConfig", { enumerable: true, get: function () { return ltconfig_1.ltConfig; } });
var events_1 = require("./lib/events");
Object.defineProperty(exports, "eventRegistry", { enumerable: true, get: function () { return events_1.eventRegistry; } });
var nats_1 = require("./lib/events/nats");
Object.defineProperty(exports, "NatsEventAdapter", { enumerable: true, get: function () { return nats_1.NatsEventAdapter; } });
var memory_1 = require("./lib/events/memory");
Object.defineProperty(exports, "InMemoryEventAdapter", { enumerable: true, get: function () { return memory_1.InMemoryEventAdapter; } });
var socketio_1 = require("./lib/events/socketio");
Object.defineProperty(exports, "SocketIOEventAdapter", { enumerable: true, get: function () { return socketio_1.SocketIOEventAdapter; } });
var publish_1 = require("./lib/events/publish");
Object.defineProperty(exports, "publishMilestoneEvent", { enumerable: true, get: function () { return publish_1.publishMilestoneEvent; } });
Object.defineProperty(exports, "publishTaskEvent", { enumerable: true, get: function () { return publish_1.publishTaskEvent; } });
Object.defineProperty(exports, "publishEscalationEvent", { enumerable: true, get: function () { return publish_1.publishEscalationEvent; } });
Object.defineProperty(exports, "publishActivityEvent", { enumerable: true, get: function () { return publish_1.publishActivityEvent; } });
Object.defineProperty(exports, "publishWorkflowEvent", { enumerable: true, get: function () { return publish_1.publishWorkflowEvent; } });
Object.defineProperty(exports, "publishAgentEvent", { enumerable: true, get: function () { return publish_1.publishAgentEvent; } });
Object.defineProperty(exports, "publishKnowledgeEvent", { enumerable: true, get: function () { return publish_1.publishKnowledgeEvent; } });
var telemetry_1 = require("./lib/telemetry");
Object.defineProperty(exports, "telemetryRegistry", { enumerable: true, get: function () { return telemetry_1.telemetryRegistry; } });
var honeycomb_1 = require("./lib/telemetry/honeycomb");
Object.defineProperty(exports, "HoneycombTelemetryAdapter", { enumerable: true, get: function () { return honeycomb_1.HoneycombTelemetryAdapter; } });
var logger_2 = require("./lib/logger");
Object.defineProperty(exports, "loggerRegistry", { enumerable: true, get: function () { return logger_2.loggerRegistry; } });
var pino_1 = require("./lib/logger/pino");
Object.defineProperty(exports, "PinoLoggerAdapter", { enumerable: true, get: function () { return pino_1.PinoLoggerAdapter; } });
var maintenance_1 = require("./services/maintenance");
Object.defineProperty(exports, "maintenanceRegistry", { enumerable: true, get: function () { return maintenance_1.maintenanceRegistry; } });
var maintenance_2 = require("./modules/maintenance");
Object.defineProperty(exports, "defaultMaintenanceConfig", { enumerable: true, get: function () { return maintenance_2.defaultMaintenanceConfig; } });
var mcp_1 = require("./services/mcp");
Object.defineProperty(exports, "mcpRegistry", { enumerable: true, get: function () { return mcp_1.mcpRegistry; } });
var adapter_1 = require("./services/mcp/adapter");
Object.defineProperty(exports, "BuiltInMcpAdapter", { enumerable: true, get: function () { return adapter_1.BuiltInMcpAdapter; } });
exports.McpService = __importStar(require("./services/mcp/db"));
exports.McpClient = __importStar(require("./services/mcp/client"));
exports.McpServer = __importStar(require("./services/mcp/server"));
exports.McpTranslationServer = __importStar(require("./system/mcp-servers/translation"));
exports.McpVisionServer = __importStar(require("./system/mcp-servers/vision"));
var escalation_strategy_1 = require("./services/escalation-strategy");
Object.defineProperty(exports, "escalationStrategyRegistry", { enumerable: true, get: function () { return escalation_strategy_1.escalationStrategyRegistry; } });
var default_1 = require("./services/escalation-strategy/default");
Object.defineProperty(exports, "DefaultEscalationStrategy", { enumerable: true, get: function () { return default_1.DefaultEscalationStrategy; } });
var mcp_2 = require("./services/escalation-strategy/mcp");
Object.defineProperty(exports, "McpEscalationStrategy", { enumerable: true, get: function () { return mcp_2.McpEscalationStrategy; } });
var activity_1 = require("./services/iam/activity");
Object.defineProperty(exports, "getActivityIdentity", { enumerable: true, get: function () { return activity_1.getActivityIdentity; } });
var context_1 = require("./services/iam/context");
Object.defineProperty(exports, "getToolContext", { enumerable: true, get: function () { return context_1.getToolContext; } });
var register_tool_1 = require("./services/mcp/register-tool");
Object.defineProperty(exports, "registerMcpTool", { enumerable: true, get: function () { return register_tool_1.registerMcpTool; } });
var system_1 = require("./system");
Object.defineProperty(exports, "getSystemWorkers", { enumerable: true, get: function () { return system_1.getSystemWorkers; } });
Object.defineProperty(exports, "getSystemAgents", { enumerable: true, get: function () { return system_1.getSystemAgents; } });
Object.defineProperty(exports, "builtinMcpServerFactories", { enumerable: true, get: function () { return system_1.builtinMcpServerFactories; } });
var callback_1 = require("./lib/events/callback");
Object.defineProperty(exports, "CallbackEventAdapter", { enumerable: true, get: function () { return callback_1.CallbackEventAdapter; } });
var sdk_1 = require("./sdk");
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return sdk_1.createClient; } });
var oauth_1 = require("./services/oauth");
Object.defineProperty(exports, "getFreshAccessToken", { enumerable: true, get: function () { return oauth_1.getFreshAccessToken; } });
Object.defineProperty(exports, "listOAuthConnections", { enumerable: true, get: function () { return oauth_1.listOAuthConnections; } });
var storage_1 = require("./lib/storage");
Object.defineProperty(exports, "getStorageBackend", { enumerable: true, get: function () { return storage_1.getStorageBackend; } });
var mime_1 = require("./lib/storage/mime");
Object.defineProperty(exports, "mimeFromPath", { enumerable: true, get: function () { return mime_1.mimeFromPath; } });
var credentials_1 = require("./services/iam/credentials");
Object.defineProperty(exports, "resolveCredential", { enumerable: true, get: function () { return credentials_1.resolveCredential; } });
exports.KnowledgeApi = __importStar(require("./api/knowledge"));
exports.api = __importStar(require("./api"));
var express_1 = require("./adapters/express");
Object.defineProperty(exports, "LTExpressAdapter", { enumerable: true, get: function () { return express_1.LTExpressAdapter; } });
// ─── Server ──────────────────────────────────────────────────────────────────
async function main() {
    const honeycombKey = process.env.HONEYCOMB_API_KEY;
    await (0, start_1.start)({
        database: {
            host: config_1.config.POSTGRES_HOST,
            port: config_1.config.POSTGRES_PORT,
            user: config_1.config.POSTGRES_USER,
            password: config_1.config.POSTGRES_PASSWORD,
            database: config_1.config.POSTGRES_DB,
        },
        server: {
            port: config_1.config.PORT,
        },
        seed: {
            admin: {
                externalId: 'superadmin',
                displayName: 'Super Admin',
                email: 'admin@longtail.local',
                password: 'l0ngt@1l',
            },
        },
        examples: true,
        mcp: {
            server: { enabled: true },
        },
        escalation: {
            strategy: 'mcp',
        },
        telemetry: honeycombKey ? { honeycomb: { apiKey: honeycombKey } } : undefined,
        events: process.env.NATS_URL
            ? { nats: { url: config_1.config.NATS_URL, token: process.env.NATS_TOKEN || 'dev_api_secret' } }
            : undefined,
    });
}
// Run server when executed directly
if (require.main === module) {
    require('dotenv').config();
    main().catch((err) => {
        logger_1.loggerRegistry.error(`[long-tail] fatal: ${err}`);
        process.exit(1);
    });
}
