mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(usage): show Muse subscription quota in the status bar Reads `muse usage --json` (Muse Code 1.4.13+), which reports the subscription allowance without a model turn, and maps `allowance.window` to the five-hour session meter and `allowance.weekly` to the weekly meter. `rateLimits.muse` now appears in `orca account list --json`. - Gate on `muse --help` listing `usage`: older builds treat an unknown subcommand as a prompt, so Orca never sends `usage` to them. - Run with MUSE_NO_AUTO_UPDATE=1 and MUSE_LOGIN=0 so a background poll never self-updates the launcher or starts a device sign-in. - Missing CLI, signed out, API-key login / no allowance, non-JSON output, and timeouts each map to an explicit unavailable/error snapshot. - Hidden meters skip the spawn, and Muse publishes after the sibling batch so a slow CLI cannot delay Grok/Cursor/ZCode/Antigravity. - Default-on status-bar item with a one-shot migration, CLI-detection gating, visibility menu and Settings toggle, remote-owner mapping. Based on the design in #34232 by ShemYu. Co-authored-by: ShemYu <11490047+ShemYu@users.noreply.github.com> * fix(usage): cap Muse usedPercent and date readings by fetch time Muse can report over-quota usage above 100; clamp to the 0-100 meter contract like the other providers. Use the fetch time for updatedAt so a cached older asOfMs cannot make every window focus trigger a refresh. * fix(usage): prevent Muse launcher installation during polling * fix(usage): gate Muse on its version file and run the active build directly - Read the launcher's `.muse-version` and require 1.4.13 or newer (the release that added `muse usage`); only installs without that file fall back to `muse --help`, cached by launcher path, mtime and size. - Execute `muse-bin-<version>` directly when it exists, so the launcher's update, sign-in and install paths never run; the env guards stay for the launcher fallback. A version change during the call discards the reading as stale. - Start the Muse fetch at the beginning of the full cycle and cap it near 8s (6s usage, 2s help), so a slow CLI holds the shared queue far less. --------- Co-authored-by: ShemYu <11490047+ShemYu@users.noreply.github.com>
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import type { ProviderRateLimits, RateLimitWindow } from './rate-limit-types'
|
||
|
||
// Structural so mobile's decoded snapshot, whose provider id is any string, fits too.
|
||
type ProviderUsageWindows = {
|
||
provider: string
|
||
session: RateLimitWindow | null
|
||
weekly: RateLimitWindow | null
|
||
fableWeekly?: RateLimitWindow | null
|
||
monthly?: RateLimitWindow | null
|
||
buckets?: readonly (RateLimitWindow & { name: string })[]
|
||
}
|
||
|
||
export type UsageWindowSection =
|
||
| { kind: 'bucket'; name: string; window: RateLimitWindow }
|
||
| {
|
||
kind: 'session' | 'weekly' | 'fableWeekly' | 'monthly' | 'plan' | 'mcp'
|
||
window: RateLimitWindow | null
|
||
}
|
||
|
||
// `satisfies` makes a provider added to ProviderRateLimits fail the typecheck until it has a name.
|
||
const PROVIDER_DISPLAY_NAMES: Readonly<Record<string, string>> = {
|
||
claude: 'Claude',
|
||
codex: 'Codex',
|
||
gemini: 'Gemini',
|
||
'opencode-go': 'OpenCode Go',
|
||
kimi: 'Kimi',
|
||
antigravity: 'Antigravity',
|
||
minimax: 'MiniMax',
|
||
grok: 'Grok',
|
||
zcode: 'ZCode',
|
||
cursor: 'Cursor',
|
||
muse: 'Muse'
|
||
} satisfies Record<ProviderRateLimits['provider'], string>
|
||
|
||
// A provider id from a newer host falls back to the id itself.
|
||
export function getProviderDisplayName(provider: string): string {
|
||
return Object.hasOwn(PROVIDER_DISPLAY_NAMES, provider)
|
||
? PROVIDER_DISPLAY_NAMES[provider]
|
||
: provider
|
||
}
|
||
|
||
export function hasUsageData(provider: ProviderUsageWindows): boolean {
|
||
return Boolean(
|
||
provider.session ||
|
||
provider.weekly ||
|
||
provider.fableWeekly ||
|
||
provider.monthly ||
|
||
(provider.buckets && provider.buckets.length > 0)
|
||
)
|
||
}
|
||
|
||
/** The usage windows a provider shows, in order; session and weekly stay as null placeholders. */
|
||
export function getUsageWindowSections(p: ProviderUsageWindows): UsageWindowSection[] {
|
||
if (p.buckets?.length) {
|
||
return [
|
||
...p.buckets.map((bucket) => ({
|
||
kind: 'bucket' as const,
|
||
name: bucket.name,
|
||
window: bucket
|
||
})),
|
||
// Include Cursor’s monthly plan total because pools can understate proximity to its cap.
|
||
...(p.monthly
|
||
? [
|
||
{
|
||
kind: p.provider === 'cursor' ? ('plan' as const) : ('monthly' as const),
|
||
window: p.monthly
|
||
}
|
||
]
|
||
: []),
|
||
{ kind: 'weekly', window: p.weekly }
|
||
]
|
||
}
|
||
const sections: UsageWindowSection[] = [
|
||
{ kind: 'session', window: p.session },
|
||
{ kind: 'weekly', window: p.weekly }
|
||
]
|
||
if (p.fableWeekly) {
|
||
sections.push({ kind: 'fableWeekly', window: p.fableWeekly })
|
||
}
|
||
if (p.monthly) {
|
||
sections.push({ kind: p.provider === 'zcode' ? 'mcp' : 'monthly', window: p.monthly })
|
||
}
|
||
return sections
|
||
}
|