"use strict";
/**
 * Orchestrator integrations: pre-approve Chorus's MCP tools in
 * third-party editors / CLIs so users don't get prompted on every tool
 * call. Same logic the `chorus connect` CLI uses, exposed via daemon
 * HTTP so the cockpit's /connect page can do it with one click.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CHORUS_TOOLS = void 0;
exports.listOrchestrators = listOrchestrators;
exports.connectByName = connectByName;
exports.autoConnectAll = autoConnectAll;
const antigravity_js_1 = require("./antigravity.js");
const claude_js_1 = require("./claude.js");
const codex_js_1 = require("./codex.js");
const cursor_windsurf_js_1 = require("./cursor-windsurf.js");
const gemini_js_1 = require("./gemini.js");
const grok_js_1 = require("./grok.js");
const kimi_js_1 = require("./kimi.js");
const opencode_js_1 = require("./opencode.js");
var shared_js_1 = require("./shared.js");
Object.defineProperty(exports, "CHORUS_TOOLS", { enumerable: true, get: function () { return shared_js_1.CHORUS_TOOLS; } });
const ORCHESTRATORS = [
    claude_js_1.claudeOrchestrator,
    codex_js_1.codexOrchestrator,
    gemini_js_1.geminiOrchestrator,
    opencode_js_1.opencodeOrchestrator,
    kimi_js_1.kimiOrchestrator,
    grok_js_1.grokOrchestrator,
    antigravity_js_1.antigravityOrchestrator,
    cursor_windsurf_js_1.cursorOrchestrator,
    cursor_windsurf_js_1.windsurfOrchestrator,
];
function listOrchestrators() {
    return ORCHESTRATORS.map((o) => o.getStatus());
}
async function connectByName(name, opts = { binPath: '' }) {
    const def = ORCHESTRATORS.find((o) => o.name === name);
    if (!def)
        throw new Error(`Unknown orchestrator '${name}'.`);
    if (def.name === 'claude')
        await (0, claude_js_1.registerClaudeMcpServer)(opts);
    const result = await def.connect(opts);
    return result.full;
}
/**
 * Detect every CLI we know about and connect to all that are present.
 * Pass `only` to limit to a subset (e.g. ['claude', 'gemini']).
 */
async function autoConnectAll(opts) {
    const steps = [];
    const allowed = opts.only ? new Set(opts.only) : null;
    for (const def of ORCHESTRATORS) {
        if (allowed && !allowed.has(def.name))
            continue;
        if (!def.detect()) {
            steps.push({
                name: def.name,
                label: def.label,
                detected: false,
                registered: false,
                toolsAdded: 0,
            });
            continue;
        }
        try {
            const result = await def.connect(opts);
            steps.push({
                name: def.name,
                label: def.label,
                detected: true,
                registered: result.registered,
                toolsAdded: result.toolsAdded,
                slashCommand: result.slashCommand,
            });
        }
        catch (err) {
            steps.push({
                name: def.name,
                label: def.label,
                detected: true,
                registered: false,
                toolsAdded: 0,
                error: err instanceof Error ? err.message : String(err),
            });
        }
    }
    const anyConnected = steps.some((s) => s.detected && !s.unsupported && !s.error);
    return { steps, anyConnected };
}
//# sourceMappingURL=index.js.map