feat: add usage tracking API and /usage dialog#7837
feat: add usage tracking API and /usage dialog#7837IgorWarzocha wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found 2 highly related PRs that appear to address similar or overlapping functionality: Potential Duplicates:
These PRs implement similar functionality (usage display for providers), though PR #7837 appears to be a more comprehensive solution with a dedicated |
518983a to
8504003
Compare
This update aligns Copilot usage tracking with the native OpenCode Copilot plugin by utilizing real-time rate-limit headers and token metadata rather than flaky internal API calls.
8504003 to
ce6605e
Compare
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude. Core: - New usage module with fetchers for each provider's usage endpoint - GET /usage endpoint with provider filter and refresh options - Claude token auto-refresh on 401 via console.anthropic.com - usage.updated bus event for real-time sidebar sync Auth: - Second device-flow during Copilot login for copilot_internal/user token - Optional usage field in OAuth schema for provider-specific tokens - Service token exchange attempt via copilot_internal/v2/token TUI: - /usage command with --current and --all flags (always fetches fresh) - Usage dialog with progress bars, reset times, credits/quota display - Sidebar Usage panel refreshes on events and assistant turn completion - tui.show_usage_scope config setting for default scope Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude. Core: - New usage module with fetchers for each provider's usage endpoint - GET /usage endpoint with provider filter and refresh options - Claude token auto-refresh on 401 via console.anthropic.com - usage.updated bus event for real-time sidebar sync Auth: - Second device-flow during Copilot login for copilot_internal/user token - Optional usage field in OAuth schema for provider-specific tokens - Service token exchange attempt via copilot_internal/v2/token TUI: - /usage command with --current and --all flags (always fetches fresh) - Usage dialog with progress bars, reset times, credits/quota display - Sidebar Usage panel refreshes on events and assistant turn completion - tui.show_usage_scope config setting for default scope Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude. Core: - New usage module with fetchers for each provider's usage endpoint - GET /usage endpoint with provider filter and refresh options - Claude token auto-refresh on 401 via console.anthropic.com - usage.updated bus event for real-time sidebar sync Auth: - Second device-flow during Copilot login for copilot_internal/user token - Optional usage field in OAuth schema for provider-specific tokens - Service token exchange attempt via copilot_internal/v2/token TUI: - /usage command with --current and --all flags (always fetches fresh) - Usage dialog with progress bars, reset times, credits/quota display - Sidebar Usage panel refreshes on events and assistant turn completion - tui.show_usage_scope config setting for default scope Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Add /usage as the single source of truth for provider usage data with TUI integration and automatic token refresh for Codex, Copilot, and Claude. Core: - New usage module with fetchers for each provider's usage endpoint - GET /usage endpoint with provider filter and refresh options - Claude token auto-refresh on 401 via console.anthropic.com - usage.updated bus event for real-time sidebar sync Auth: - Second device-flow during Copilot login for copilot_internal/user token - Optional usage field in OAuth schema for provider-specific tokens - Service token exchange attempt via copilot_internal/v2/token TUI: - /usage command with --current and --all flags (always fetches fresh) - Usage dialog with progress bars, reset times, credits/quota display - Sidebar Usage panel refreshes on events and assistant turn completion - tui.show_usage_scope config setting for default scope Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Add /usage as the single source of truth for provider usage data with TUI integration and shared provider registry metadata. Core: - Usage registry shared by server + TUI (auth-key-based providers) - GET /usage endpoint with provider filter and refresh options - Usage cache updates respect explicit nulls and error responses - Claude token auto-refresh on 401 via console.anthropic.com Auth: - Copilot OAuth flow includes optional usage device login (shared for all clients) - Optional usage field in OAuth schema for provider-specific tokens TUI: - /usage command with --current and --all flags (always fetches fresh) - Usage dialog + sidebar with shared formatting helpers - Provider-scoped error lines shown below usage entries - Extra Usage labeling for Claude, quota labeling for Copilot - tui.show_usage_scope config setting for default scope Quality: - Fix shell/command double-submit and restore extmarks after external editor - Expanded usage tests for cache fallback and Claude extra usage - Usage response returns per-provider errors Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Add /usage as the single source of truth for provider usage data with TUI integration and shared provider registry metadata. Core: - Usage registry shared by server + TUI (auth-key-based providers) - GET /usage endpoint with provider filter and refresh options - Parallel provider fetches with error-aware caching - Claude token auto-refresh on 401 via console.anthropic.com Auth: - Copilot OAuth flow includes optional usage device login (shared for all clients) - Optional usage field in OAuth schema for provider-specific tokens TUI: - /usage command with --current and --all flags (always fetches fresh) - Shared usage client for dialog + sidebar fetches - Provider-scoped error lines shown below usage entries - Extra Usage labeling for Claude, quota labeling for Copilot - tui.show_usage_scope config setting for default scope Quality: - Fix shell/command double-submit and restore extmarks after external editor - Usage cache overwrite respects explicit nulls - Expanded usage + Copilot auth tests Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
What does this PR do?
Adds a usage tracking API + TUI dialog for authenticated providers, including Codex and Copilot (rewritten for native Copilot plugin).
/usageserver route plus sharedUsagemodule for fetching, caching, and normalizing usage snapshots/usageautocomplete handling and a unified usage dialog (plan/quota parsing, scaling, reset display)How did you verify your code works?
bun run typecheck(fails inpackages/opencode/src/server/server.ts:202due to existing deep type instantiation error; unchanged from upstream)screenrecording-2026-01-11_18-37-51.mp4