(input: {
provider: Provider.Info
sessionID?: string
timePeriod?: TimePeriod
})
| 1513 | } |
| 1514 | |
| 1515 | async function fetchAntigravityUsage(input: { |
| 1516 | provider: Provider.Info |
| 1517 | sessionID?: string |
| 1518 | timePeriod?: TimePeriod |
| 1519 | }): Promise<Omit<Record, "providerID" | "providerName" | "fetchedAt">> { |
| 1520 | const auth = await Auth.get(input.provider.id) |
| 1521 | if (!auth || auth.type !== "oauth") { |
| 1522 | throw new Error("Antigravity OAuth authentication is required. Run `arctic auth login` and select Antigravity.") |
| 1523 | } |
| 1524 | |
| 1525 | const accessToken = await ensureAntigravityAccessToken(auth, input.provider.id) |
| 1526 | |
| 1527 | // Fetch quota information from Antigravity API |
| 1528 | const quotas = await fetchAntigravityModels(accessToken) |
| 1529 | |
| 1530 | if (quotas.length === 0) { |
| 1531 | return { |
| 1532 | planType: "Antigravity (No quota information available)", |
| 1533 | credits: { |
| 1534 | hasCredits: true, |
| 1535 | unlimited: true, |
| 1536 | }, |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | // Find the model with the lowest remaining fraction (most constrained) |
| 1541 | let lowestRemaining = 1.0 |
| 1542 | let resetTime: string | null = null |
| 1543 | |
| 1544 | for (const quota of quotas) { |
| 1545 | const remaining = quota.remainingFraction ?? 1.0 |
| 1546 | if (remaining < lowestRemaining) { |
| 1547 | lowestRemaining = remaining |
| 1548 | resetTime = quota.resetTime |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | // Format quota details for display |
| 1553 | const quotaEntries = quotas |
| 1554 | .map((quota) => { |
| 1555 | const percent = quota.remainingFraction !== null ? Math.round(quota.remainingFraction * 100) : "N/A" |
| 1556 | return `${quota.displayName}: ${percent}% remaining` |
| 1557 | }) |
| 1558 | .slice(0, 10) // Limit to first 10 models to avoid clutter |
| 1559 | |
| 1560 | const quotaDetails = quotaEntries.map((entry) => `- ${entry}`).join("\n") |
| 1561 | const planType = `Antigravity\n${quotaDetails}` |
| 1562 | |
| 1563 | // Parse reset time if available |
| 1564 | let resetsAt: number | undefined |
| 1565 | if (resetTime) { |
| 1566 | const resetDate = new Date(resetTime) |
| 1567 | if (!Number.isNaN(resetDate.getTime())) { |
| 1568 | resetsAt = Math.floor(resetDate.getTime() / 1000) |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | const usedPercent = Math.max(0, Math.min(100, (1 - lowestRemaining) * 100)) |
nothing calls this directly
no test coverage detected