import { findExecutable } from "../../../utils/executable.js";
import { ACPAgentClient } from "./acp-agent.js";
import { formatDiagnosticStatus, formatProviderDiagnostic, formatProviderDiagnosticError, resolveBinaryVersion, toDiagnosticErrorMessage, } from "./diagnostic-utils.js";
const COPILOT_CAPABILITIES = {
    supportsStreaming: true,
    supportsSessionPersistence: true,
    supportsDynamicModes: true,
    supportsMcpServers: true,
    supportsReasoningStream: true,
    supportsToolInvocations: true,
};
const COPILOT_MODES = [
    {
        id: "https://agentclientprotocol.com/protocol/session-modes#agent",
        label: "Agent",
        description: "Default agent mode for conversational interactions",
    },
    {
        id: "https://agentclientprotocol.com/protocol/session-modes#plan",
        label: "Plan",
        description: "Plan mode for creating and executing multi-step plans",
    },
    {
        id: "https://agentclientprotocol.com/protocol/session-modes#autopilot",
        label: "Autopilot",
        description: "Autonomous mode that runs until task completion without user interaction",
    },
];
export class CopilotACPAgentClient extends ACPAgentClient {
    constructor(options) {
        super({
            provider: "copilot",
            logger: options.logger,
            runtimeSettings: options.runtimeSettings,
            defaultCommand: ["copilot", "--acp"],
            defaultModes: COPILOT_MODES,
            capabilities: COPILOT_CAPABILITIES,
        });
    }
    async isAvailable() {
        return super.isAvailable();
    }
    async getDiagnostic() {
        try {
            const available = await this.isAvailable();
            const resolvedBinary = await findExecutable("copilot");
            let modelsValue = "Not checked";
            let status = formatDiagnosticStatus(available);
            if (available) {
                try {
                    const models = await this.listModels();
                    modelsValue = String(models.length);
                }
                catch (error) {
                    modelsValue = `Error - ${toDiagnosticErrorMessage(error)}`;
                    status = formatDiagnosticStatus(available, {
                        source: "model fetch",
                        cause: error,
                    });
                }
                if (!modelsValue.startsWith("Error -")) {
                    try {
                        await this.listModes();
                    }
                    catch (error) {
                        status = formatDiagnosticStatus(available, {
                            source: "mode fetch",
                            cause: error,
                        });
                    }
                }
            }
            return {
                diagnostic: formatProviderDiagnostic("Copilot", [
                    {
                        label: "Binary",
                        value: resolvedBinary ?? "not found",
                    },
                    {
                        label: "Version",
                        value: resolvedBinary ? await resolveBinaryVersion(resolvedBinary) : "unknown",
                    },
                    { label: "Models", value: modelsValue },
                    { label: "Status", value: status },
                ]),
            };
        }
        catch (error) {
            return {
                diagnostic: formatProviderDiagnosticError("Copilot", error),
            };
        }
    }
}
//# sourceMappingURL=copilot-acp-agent.js.map