import { ClaudeAgentClient } from "./providers/claude-agent.js";
import { CodexAppServerAgentClient } from "./providers/codex-app-server-agent.js";
import { OpenCodeAgentClient, OpenCodeServerManager } from "./providers/opencode-agent.js";
import { CopilotACPAgentClient } from "./providers/copilot-acp-agent.js";
import { PiACPAgentClient } from "./providers/pi-acp-agent.js";
import { AGENT_PROVIDER_DEFINITIONS, getAgentProviderDefinition, } from "./provider-manifest.js";
export { AGENT_PROVIDER_DEFINITIONS, getAgentProviderDefinition };
const PROVIDER_CLIENT_FACTORIES = {
    claude: (logger, runtimeSettings) => new ClaudeAgentClient({
        logger,
        runtimeSettings: runtimeSettings?.claude,
    }),
    codex: (logger, runtimeSettings) => new CodexAppServerAgentClient(logger, runtimeSettings?.codex),
    copilot: (logger, runtimeSettings) => new CopilotACPAgentClient({
        logger,
        runtimeSettings: runtimeSettings?.copilot,
    }),
    opencode: (logger, runtimeSettings) => new OpenCodeAgentClient(logger, runtimeSettings?.opencode),
    pi: (logger, runtimeSettings) => new PiACPAgentClient({ logger, runtimeSettings: runtimeSettings?.pi }),
};
function getProviderClientFactory(provider) {
    const factory = PROVIDER_CLIENT_FACTORIES[provider];
    if (!factory) {
        throw new Error(`No provider client factory registered for '${provider}'`);
    }
    return factory;
}
export function buildProviderRegistry(logger, options) {
    const runtimeSettings = options?.runtimeSettings;
    return Object.fromEntries(AGENT_PROVIDER_DEFINITIONS.map((definition) => {
        const createClient = getProviderClientFactory(definition.id);
        const modelClient = createClient(logger, runtimeSettings);
        return [
            definition.id,
            {
                ...definition,
                createClient: (providerLogger) => createClient(providerLogger, runtimeSettings),
                fetchModels: (listOptions) => modelClient.listModels(listOptions),
                fetchModes: (listOptions) => modelClient.listModes
                    ? modelClient.listModes(listOptions)
                    : Promise.resolve(definition.modes),
            },
        ];
    }));
}
// Deprecated: Use buildProviderRegistry instead
export const PROVIDER_REGISTRY = null;
export function createAllClients(logger, options) {
    const registry = buildProviderRegistry(logger, options);
    return Object.fromEntries(Object.entries(registry).map(([provider, definition]) => [
        provider,
        definition.createClient(logger),
    ]));
}
export async function shutdownProviders(logger, options) {
    await OpenCodeServerManager.getInstance(logger, options?.runtimeSettings?.opencode).shutdown();
}
//# sourceMappingURL=provider-registry.js.map