(input: {
provider: Provider.Info
})
| 739 | } |
| 740 | |
| 741 | async function fetchCodexUsage(input: { |
| 742 | provider: Provider.Info |
| 743 | }): Promise<Omit<Record, "providerID" | "providerName" | "fetchedAt">> { |
| 744 | const directAuth = await Auth.get(input.provider.id) |
| 745 | const baseKey = input.provider.baseProvider ?? input.provider.id |
| 746 | const baseAuth = baseKey !== input.provider.id ? await Auth.get(baseKey) : undefined |
| 747 | const auth = directAuth ?? baseAuth |
| 748 | if (!auth) { |
| 749 | throw new Error("Codex authentication is required. Run `arctic auth codex` to connect your account.") |
| 750 | } |
| 751 | |
| 752 | const authKey = directAuth ? input.provider.id : baseKey |
| 753 | const { accessToken, accountId } = await resolveCodexCredentials(auth, authKey) |
| 754 | const payload = await fetchCodexUsagePayload({ |
| 755 | baseUrl: resolveCodexBaseUrl(auth), |
| 756 | accessToken, |
| 757 | accountId, |
| 758 | }) |
| 759 | const rateLimit = payload.rate_limit ?? undefined |
| 760 | |
| 761 | return { |
| 762 | planType: payload.plan_type, |
| 763 | allowed: rateLimit?.allowed, |
| 764 | limitReached: rateLimit?.limit_reached, |
| 765 | limits: { |
| 766 | primary: mapCodexWindow(rateLimit?.primary_window, "5h"), |
| 767 | secondary: mapCodexWindow(rateLimit?.secondary_window, "Weekly"), |
| 768 | }, |
| 769 | credits: mapCredits(payload.credits), |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | function mapCodexWindow( |
| 774 | window: CodexRateLimitWindowSnapshot | null | undefined, |
nothing calls this directly
no test coverage detected