"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 __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 assert = __importStar(require("assert"));
const Gateway_1 = require("./orchestrator/Gateway");
async function main() {
    process.env.OPENLIFE_TELEGRAM_ALLOWED_USER_ID = '';
    process.env.OPENLIFE_ENABLE_TTS = 'false';
    const gateway = new Gateway_1.Gateway();
    gateway.classifier = { classify: async () => ({ intent: 'KNOWLEDGE_RETRIEVAL', budgetLimit: 0.01 }) };
    gateway.gatekeeper = { routeTask: async (_task, input) => `Resposta final para: ${input}` };
    gateway.voiceManager = { generateSpeech: async (_text) => '/tmp/openlife-on-demand-voice-test.mp3' };
    const result = await gateway.processTextForTestDetailed('1344110010', '/voice explique o AIOBUILDER em uma frase');
    assert.equal(result.events.some((e) => e.kind === 'voice'), true);
    assert.equal(result.finalText.includes('Resposta final para: explique o AIOBUILDER em uma frase'), true);
    assert.equal(result.finalText.includes('/voice'), false);
    const noVoice = await gateway.processTextForTestDetailed('1344110010', 'explique o AIOBUILDER em uma frase');
    assert.equal(noVoice.events.some((e) => e.kind === 'voice'), false);
    assert.equal(noVoice.events.some((e) => e.kind === 'edit'), true);
    const fallbackGateway = new Gateway_1.Gateway();
    fallbackGateway.classifier = gateway.classifier;
    fallbackGateway.gatekeeper = gateway.gatekeeper;
    fallbackGateway.voiceManager = { generateSpeech: async () => { throw new Error('NO_TTS_PROVIDER'); } };
    const fallback = await fallbackGateway.processTextForTestDetailed('1344110010', 'responda por voz: diga olá');
    assert.equal(fallback.events.some((e) => e.kind === 'voice'), false);
    assert.match(fallback.finalText, /Não consegui gerar a voz/);
    assert.match(fallback.finalText, /OPENAI_API_KEY|ELEVENLABS_API_KEY/);
    console.log('ON_DEMAND_VOICE_REPLY_OK');
}
main().catch((err) => {
    console.error(err);
    process.exit(1);
});
