mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
Claude plan label: read subscriptionType so a Team seat is not shown as Max 5x (#1492)
* quota: Claude plan label prefers the subscription type * desktop: Claude plan label prefers the subscription type * menubar: Claude plan label prefers the subscription type * mac: Claude plan label prefers the subscription type
This commit is contained in:
parent
14c4a52145
commit
42710db3c2
9 changed files with 195 additions and 55 deletions
|
|
@ -8,7 +8,7 @@ import type { QuotaProvider, QuotaWindow } from './types.js'
|
|||
const ENDPOINT = 'https://api.anthropic.com/api/oauth/usage'
|
||||
const KEYCHAIN_SERVICE = 'Claude Code-credentials'
|
||||
|
||||
type ClaudeCredential = { accessToken: string; expiresAt?: number; rateLimitTier?: string }
|
||||
type ClaudeCredential = { accessToken: string; expiresAt?: number; rateLimitTier?: string; subscriptionType?: string }
|
||||
export type ClaudeDeps = {
|
||||
fetch: typeof fetch
|
||||
credentialPath: string
|
||||
|
|
@ -36,6 +36,7 @@ function parseCredential(raw: string): ClaudeCredential | null {
|
|||
accessToken: oauth.accessToken,
|
||||
expiresAt: typeof oauth.expiresAt === 'number' ? oauth.expiresAt : undefined,
|
||||
rateLimitTier: typeof oauth.rateLimitTier === 'string' ? oauth.rateLimitTier : undefined,
|
||||
subscriptionType: typeof oauth.subscriptionType === 'string' ? oauth.subscriptionType : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,13 +63,23 @@ function windowOf(label: string, value: unknown): QuotaWindow | null {
|
|||
return { label, percent, resetsAt }
|
||||
}
|
||||
|
||||
function tierLabel(raw: string | undefined): string {
|
||||
const value = raw?.toLowerCase() ?? ''
|
||||
if (value.includes('max_20x') || value.includes('max20x') || value.includes('max-20x')) return 'Max 20x'
|
||||
if (value.includes('max_5x') || value.includes('max5x') || value.includes('max-5x') || value.includes('max')) return 'Max 5x'
|
||||
if (value.includes('pro')) return 'Pro'
|
||||
if (value.includes('team')) return 'Team'
|
||||
if (value.includes('enterprise')) return 'Enterprise'
|
||||
export function planLabel(credential: Pick<ClaudeCredential, 'subscriptionType' | 'rateLimitTier'>): string {
|
||||
const subscriptionType = credential.subscriptionType?.toLowerCase() ?? ''
|
||||
const tier = credential.rateLimitTier?.toLowerCase() ?? ''
|
||||
const hasMax20 = tier.includes('max_20x') || tier.includes('max20x') || tier.includes('max-20x')
|
||||
const hasMax = tier.includes('max')
|
||||
if (subscriptionType === 'team' || (subscriptionType === '' && tier.includes('team'))) {
|
||||
return hasMax ? 'Team Premium' : 'Team'
|
||||
}
|
||||
if (subscriptionType === 'enterprise' || (subscriptionType === '' && tier.includes('enterprise'))) {
|
||||
return hasMax ? 'Enterprise Premium' : 'Enterprise'
|
||||
}
|
||||
if (subscriptionType === 'max' || hasMax) {
|
||||
return hasMax20 ? 'Max 20x' : 'Max 5x'
|
||||
}
|
||||
if (subscriptionType === 'pro' || tier.includes('pro')) {
|
||||
return 'Pro'
|
||||
}
|
||||
return 'Subscription'
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +105,7 @@ export function decodeClaudeUsage(body: unknown, credential: ClaudeCredential):
|
|||
return {
|
||||
provider: 'claude', connection: 'connected', primary: weekly,
|
||||
details: [five, weekly, opus, sonnet].filter((row): row is QuotaWindow => row !== null).concat(scoped),
|
||||
planLabel: tierLabel(credential.rateLimitTier), footerLines: [],
|
||||
planLabel: planLabel(credential), footerLines: [],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue