import { i as normalizeProviderId } from "./provider-id-Dq06Bcx6.js";
//#region src/infra/provider-usage.shared.ts
const DEFAULT_TIMEOUT_MS = 5e3;
const PROVIDER_LABELS = {
	anthropic: "Claude",
	"github-copilot": "Copilot",
	"google-gemini-cli": "Gemini",
	minimax: "MiniMax",
	"openai-codex": "Codex",
	xiaomi: "Xiaomi",
	"xiaomi-token-plan": "Xiaomi Token Plan",
	zai: "z.ai"
};
const usageProviders = [
	"anthropic",
	"github-copilot",
	"google-gemini-cli",
	"minimax",
	"openai-codex",
	"xiaomi",
	"xiaomi-token-plan",
	"zai"
];
function resolveUsageProviderId(provider, options) {
	if (!provider) return;
	const normalized = normalizeProviderId(provider);
	if (normalized === "openai" && (options?.credentialType === "oauth" || options?.credentialType === "token")) return "openai-codex";
	if (normalized === "minimax-portal" || normalized === "minimax-cn" || normalized === "minimax-portal-cn") return "minimax";
	return usageProviders.includes(normalized) ? normalized : void 0;
}
const ignoredErrors = new Set([
	"No credentials",
	"No token",
	"No API key",
	"Not logged in",
	"No auth"
]);
const clampPercent = (value) => Math.max(0, Math.min(100, Number.isFinite(value) ? value : 0));
const withTimeout = async (work, ms, fallback) => {
	let timeout;
	try {
		return await Promise.race([work, new Promise((resolve) => {
			timeout = setTimeout(() => resolve(fallback), ms);
		})]);
	} finally {
		if (timeout) clearTimeout(timeout);
	}
};
//#endregion
export { resolveUsageProviderId as a, ignoredErrors as i, PROVIDER_LABELS as n, usageProviders as o, clampPercent as r, withTimeout as s, DEFAULT_TIMEOUT_MS as t };
