// Centralize direct SDK provider imports here.
// The rest of Kanban should talk to the SDK through local service modules so
// auth, catalog, and provider-settings behavior stay behind one boundary.

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="48d61817-6bbc-5a2a-ae86-c5a540cfd3ad")}catch(e){}}();
import { ClineAccountService, getValidClineCredentials, getValidOcaCredentials, getValidOpenAICodexCredentials, InMemoryMcpManager, loginClineOAuth, loginOcaOAuth, loginOpenAICodex, ProviderSettingsManager, } from "@clinebot/core/node";
import { LlmsModels as llmsModels } from "@clinebot/llms";
import { createMcpTools } from "@clinebot/agents";
function buildOcaOauthConfig(baseUrl) {
    const normalizedBaseUrl = baseUrl?.trim() ?? "";
    if (!normalizedBaseUrl) {
        return undefined;
    }
    return {
        mode: normalizedBaseUrl.includes("code-internal") ? "internal" : "external",
        config: {
            internal: { baseUrl: normalizedBaseUrl },
            external: { baseUrl: normalizedBaseUrl },
        },
    };
}
export async function refreshManagedOauthCredentials(input) {
    if (input.providerId === "cline") {
        const credentials = await getValidClineCredentials(input.currentCredentials, {
            apiBaseUrl: input.baseUrl?.trim() || "https://api.cline.bot",
            provider: input.oauthProvider?.trim() || undefined,
        });
        return credentials ?? null;
    }
    if (input.providerId === "oca") {
        const credentials = await getValidOcaCredentials(input.currentCredentials, undefined, buildOcaOauthConfig(input.baseUrl));
        return credentials ?? null;
    }
    const credentials = await getValidOpenAICodexCredentials(input.currentCredentials);
    return credentials ?? null;
}
export async function loginManagedOauthProvider(input) {
    if (input.providerId === "cline") {
        return await loginClineOAuth({
            apiBaseUrl: input.baseUrl?.trim() || "https://api.cline.bot",
            provider: input.oauthProvider?.trim() || undefined,
            callbacks: input.callbacks,
        });
    }
    if (input.providerId === "oca") {
        return await loginOcaOAuth({
            ...(buildOcaOauthConfig(input.baseUrl) ?? { mode: "external" }),
            callbacks: input.callbacks,
        });
    }
    return await loginOpenAICodex({
        ...input.callbacks,
        originator: "kanban-runtime",
    });
}
export async function listSdkProviderCatalog() {
    return await llmsModels.getAllProviders();
}
export async function listSdkProviderModels(providerId) {
    return await llmsModels.getModelsForProvider(providerId);
}
const providerManager = new ProviderSettingsManager();
export function getSdkProviderSettings(providerId) {
    return (providerManager.getProviderSettings(providerId) ?? null);
}
export function getLastUsedSdkProviderSettings() {
    return (providerManager.getLastUsedProviderSettings() ?? null);
}
export function saveSdkProviderSettings(input) {
    const settings = {
        ...input.settings,
        provider: input.settings.provider.trim(),
    };
    if (settings.model !== undefined) {
        const model = settings.model.trim();
        if (!model) {
            delete settings.model;
        }
        else {
            settings.model = model;
        }
    }
    if (settings.baseUrl !== undefined) {
        const baseUrl = settings.baseUrl.trim();
        if (!baseUrl) {
            delete settings.baseUrl;
        }
        else {
            settings.baseUrl = baseUrl;
            if (settings.provider === "oca") {
                settings.oca = {
                    mode: baseUrl.includes("code-internal") ? "internal" : "external",
                };
            }
        }
    }
    if (settings.apiKey !== undefined) {
        const apiKey = settings.apiKey.trim();
        if (!apiKey) {
            delete settings.apiKey;
        }
        else {
            settings.apiKey = apiKey;
        }
    }
    if (settings.auth) {
        const auth = { ...settings.auth };
        if (auth.accountId !== undefined && auth.accountId !== null) {
            const accountId = auth.accountId.trim();
            auth.accountId = accountId || undefined;
        }
        settings.auth = auth;
    }
    providerManager.saveProviderSettings(settings, {
        setLastUsed: input.setLastUsed,
        tokenSource: input.tokenSource,
    });
}
export function createSdkInMemoryMcpManager(options) {
    const managerConstructor = InMemoryMcpManager;
    if (!managerConstructor) {
        throw new Error("InMemoryMcpManager is not available from @clinebot/core/node.");
    }
    return new managerConstructor(options);
}
export async function createSdkMcpTools(options) {
    return await createMcpTools(options);
}
export async function fetchSdkClineAccountProfile(input) {
    const accountServiceConstructor = ClineAccountService;
    if (!accountServiceConstructor) {
        throw new Error("ClineAccountService is not available from @clinebot/core/node.");
    }
    const accountService = new accountServiceConstructor({
        apiBaseUrl: input.apiBaseUrl,
        getAuthToken: async () => input.accessToken,
    });
    const me = await accountService.fetchMe();
    return {
        id: me.id,
        email: me.email,
        displayName: me.displayName,
    };
}
export async function fetchSdkClineUserRemoteConfig(input) {
    const accountServiceConstructor = ClineAccountService;
    if (!accountServiceConstructor) {
        throw new Error("ClineAccountService is not available from @clinebot/core/node.");
    }
    const accountService = new accountServiceConstructor({
        apiBaseUrl: input.apiBaseUrl,
        getAuthToken: async () => input.accessToken,
    });
    return await accountService.fetchRemoteConfig();
}
//# sourceMappingURL=sdk-provider-boundary.js.map
//# debugId=48d61817-6bbc-5a2a-ae86-c5a540cfd3ad
