/**
 * CC-Switch Adapters 共享类型和工具函数
 *
 * 从 cc-switch-sdk 包导入接口定义，在此实现具体适配器
 */
/**
 * 将 OpenCode/Claudecode server 格式转换为 MCP spec
 */
export function toMcpSpecFromOpenCode(input) {
    if (input.type === "local") {
        const [command, ...args] = input.command;
        return {
            type: "stdio",
            command,
            args,
            env: input.environment,
            cwd: input.cwd,
        };
    }
    return {
        type: "sse",
        url: input.url,
        headers: input.headers,
    };
}
/**
 * 将 MCP spec 转换为 OpenCode/Claudecode server 格式
 */
export function toOpenCodeServer(input) {
    if (input.type === "stdio") {
        const commandParts = [input.command, ...(input.args ?? [])].filter((entry) => Boolean(entry));
        return {
            type: "local",
            command: commandParts,
            environment: input.env,
            cwd: input.cwd,
            enabled: true,
        };
    }
    return {
        type: "remote",
        url: input.url ?? "",
        headers: input.headers,
        enabled: true,
    };
}
/**
 * 导入时合并 App 标记
 */
export function mergeAppFlagOnImport(server, appId) {
    return {
        ...server,
        apps: {
            ...server.apps,
            [appId]: true,
        },
    };
}
// Claudecode uses the same conversion functions as OpenCode
export const toMcpSpecFromClaudecode = toMcpSpecFromOpenCode;
export const toClaudecodeServer = toOpenCodeServer;
