import { m as readProviderJsonResponse } from "./provider-http-errors-Bh4de1Nm.js";
import { v as buildCopilotIdeHeaders } from "./provider-request-config-C8QSmO3a.js";
import "./provider-auth-ShvzbnnU.js";
import "./provider-http-D6eC_5jF.js";
import { n as PROVIDER_LABELS, r as clampPercent } from "./provider-usage.shared-BtRIPHWE.js";
import { c as buildUsageHttpErrorSnapshot, l as fetchJson } from "./provider-usage-BA2bBnvd.js";
import { t as PUBLIC_GITHUB_COPILOT_DOMAIN } from "./domain-DePLHDkO.js";
//#region extensions/github-copilot/usage.ts
async function fetchCopilotUsage(token, timeoutMs, fetchFn, githubDomain = PUBLIC_GITHUB_COPILOT_DOMAIN) {
	const res = await fetchJson(`https://api.${githubDomain}/copilot_internal/user`, { headers: {
		Authorization: `token ${token}`,
		...buildCopilotIdeHeaders({ includeApiVersion: true })
	} }, timeoutMs, fetchFn);
	if (!res.ok) {
		await res.body?.cancel().catch(() => void 0);
		return buildUsageHttpErrorSnapshot({
			provider: "github-copilot",
			status: res.status
		});
	}
	const data = await readProviderJsonResponse(res, "github-copilot-usage");
	const windows = [];
	if (data.quota_snapshots?.premium_interactions) {
		const remaining = data.quota_snapshots.premium_interactions.percent_remaining;
		windows.push({
			label: "Premium",
			usedPercent: clampPercent(100 - (remaining ?? 0))
		});
	}
	if (data.quota_snapshots?.chat) {
		const remaining = data.quota_snapshots.chat.percent_remaining;
		windows.push({
			label: "Chat",
			usedPercent: clampPercent(100 - (remaining ?? 0))
		});
	}
	return {
		provider: "github-copilot",
		displayName: PROVIDER_LABELS["github-copilot"],
		windows,
		plan: data.copilot_plan
	};
}
//#endregion
export { fetchCopilotUsage as t };
