refactor(ai): deduplicated usage provider coercion helpers

- Deleted usage/shared.ts's duplicate toNumber; every consumer in the directory
  now resolves the single catalog implementation.
- Promoted HOUR_MS, DAY_MS, WEEK_MS, parseIsoTimestamp, parsePositiveTimestamp
  and usageStatus into usage/shared.ts and dropped the local copies.
- Left the epoch coercers, status thresholds and base-url normalizers alone:
  they disagree on the 1e12 boundary, non-positive values and warn levels, so
  merging them would change reported usage.
This commit is contained in:
can1357
2026-08-08 06:32:00 +02:00
parent 5fa578fa3b
commit 2efbdeaab9
16 changed files with 114 additions and 173 deletions
+3 -2
View File
@@ -18,6 +18,7 @@ import type {
UsageWindow,
} from "../usage";
import { isRecord } from "../utils";
import { parseIsoTimestamp } from "./shared";
type CopilotQuotaDetail = {
entitlement: number;
@@ -74,8 +75,8 @@ function resolveGitHubApiBaseUrl(params: UsageFetchParams): string {
function buildWindow(resetDate: string | undefined): UsageWindow | undefined {
if (!resetDate) return undefined;
const resetAt = Date.parse(resetDate);
if (!Number.isFinite(resetAt)) return undefined;
const resetAt = parseIsoTimestamp(resetDate);
if (resetAt === undefined) return undefined;
return {
id: "monthly",
label: "Monthly",