const DEFAULT_GROK_PROXY_HOST = "127.0.0.1";
const DEFAULT_GROK_PROXY_PORT = 18645;
function normalizeBaseUrl(url) {
    return url.replace(/\/v1\/?$/, "").replace(/\/$/, "");
}
export function getGrokProxyBaseUrl(ctx = {}) {
    const grokCfg = ctx.config?.grokProvider || {};
    const explicitUrl = ctx.grokUrl;
    if (explicitUrl)
        return normalizeBaseUrl(explicitUrl);
    const host = grokCfg.proxyHost || DEFAULT_GROK_PROXY_HOST;
    const port = ctx.grokActualPort || grokCfg.proxyPort || DEFAULT_GROK_PROXY_PORT;
    return `http://${host}:${port}`;
}
export function getGrokProxyUrl(ctx = {}, path = "/v1") {
    const normalizedPath = path.startsWith("/") ? path : `/${path}`;
    return `${getGrokProxyBaseUrl(ctx)}${normalizedPath}`;
}
export function getGrokDirectBaseUrl() {
    return "https://api.x.ai";
}
