"use strict";
/**
 * Copilot dispatch flow — GitHub Copilot subscription via copilot-api proxy.
 *
 * Extracted from src/ccs.ts main() profileInfo.type === 'copilot' branch.
 */
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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCopilotFlow = void 0;
const ui_1 = require("../../utils/ui");
const websearch_manager_1 = require("../../utils/websearch-manager");
const image_analysis_1 = require("../../utils/image-analysis");
const image_analyzer_profile_hook_injector_1 = require("../../utils/hooks/image-analyzer-profile-hook-injector");
const hooks_1 = require("../../utils/hooks");
async function runCopilotFlow(ctx) {
    const { profileInfo, resolvedTarget, claudeCli, remainingArgs, resolveProfileContinuityInheritance, } = ctx;
    (0, websearch_manager_1.ensureWebSearchMcpOrThrow)();
    const imageAnalysisMcpReady = (0, image_analysis_1.ensureImageAnalysisMcpOrThrow)();
    if (resolvedTarget === 'claude') {
        if (imageAnalysisMcpReady) {
            (0, image_analyzer_profile_hook_injector_1.removeImageAnalysisProfileHook)(profileInfo.name);
        }
        else {
            const imageAnalysisFallbackHookReady = (0, hooks_1.prepareImageAnalysisFallbackHook)();
            (0, image_analyzer_profile_hook_injector_1.ensureProfileHooks)({
                profileName: profileInfo.name,
                profileType: profileInfo.type,
                sharedHookInstalled: imageAnalysisFallbackHookReady,
            });
        }
    }
    const { executeCopilotProfile } = await Promise.resolve().then(() => __importStar(require('../../copilot')));
    const copilotConfig = profileInfo.copilotConfig;
    if (!copilotConfig) {
        console.error((0, ui_1.fail)('Copilot configuration not found'));
        process.exit(1);
    }
    const continuityInheritance = await resolveProfileContinuityInheritance({
        profileName: profileInfo.name,
        profileType: profileInfo.type,
        target: resolvedTarget,
    });
    if (continuityInheritance.sourceAccount && process.env.CCS_DEBUG) {
        console.error((0, ui_1.info)(`Continuity inheritance active: profile "${profileInfo.name}" -> account "${continuityInheritance.sourceAccount}"`));
    }
    const exitCode = await executeCopilotProfile(copilotConfig, remainingArgs, continuityInheritance.claudeConfigDir, claudeCli);
    process.exit(exitCode);
}
exports.runCopilotFlow = runCopilotFlow;
//# sourceMappingURL=copilot-flow.js.map