Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 1 addition & 47 deletions shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,53 +318,7 @@ export interface ApiError {

export type { PaneFindMatch, PaneFindRequest, PaneFindResponse } from "./find.ts";

/** The subscriptions whose plan limits GET /api/usage can read from a CLI's own sign-in. */
export type UsageProviderId = "claude" | "codex" | "cursor" | "copilot" | "grok" | "antigravity" | "opencode";

/** One limit of a plan: how much of it is used and when it starts over. */
export interface UsageWindow {
/** the span the limit counts over: a rolling session (5 hours), a day, a week or a billing month */
readonly kind: "session" | "day" | "week" | "month";
/** the model or quota a plan limits on its own ("Sonnet", "Premium"); null for the plan-wide limit */
readonly scope: string | null;
/** 0 to 100 */
readonly used_percent: number;
/** ISO 8601; null when the provider does not say */
readonly resets_at: string | null;
/** ISO 8601 time this window began counting; null when the provider states neither it nor the window's length */
readonly starts_at: string | null;
}

/**
* Why a provider's numbers are missing or old: its sign-in expired or was refused; the provider
* asked to slow down; the request failed; the macOS keychain holding the sign-in could not be
* read from this server's session.
*/
export type UsageProblem = "expired" | "rate_limited" | "failed" | "locked";

export interface ProviderUsage {
readonly id: UsageProviderId;
/**
* One account of one provider, stable across reads: the provider and its account id, or, for a
* sign-in that does not say whose it is, the provider and where it was found. A PC signed in to
* two accounts of one provider lists both.
*/
readonly key: string;
/** whose plan this is, as its owner knows the account: an email, or a GitHub login; null when unknown */
readonly account: string | null;
/** the plan's name as the provider states it ("max", "pro"), when it does */
readonly plan: string | null;
/** the last numbers read; kept through a later failure, which `problem` then names */
readonly windows: readonly UsageWindow[];
readonly problem: UsageProblem | null;
/** ISO 8601 time `windows` were read; null when they never were */
readonly checked_at: string | null;
}

/** GET /api/usage: only providers a CLI on this PC is signed in to are listed, once per account. */
export interface UsageReport {
readonly providers: readonly ProviderUsage[];
}
export type { UsageProviderId, UsageWindow, UsageProblem, ProviderUsage, UsageReport } from "./usage.ts";

export type { CLIProxyStatus, CLIProxyProvider, CLIProxyLogin, CLIProxyLoginStatus } from "./cliproxy.ts";

Expand Down
47 changes: 47 additions & 0 deletions shared/usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** The subscriptions whose plan limits GET /api/usage can read from a CLI's own sign-in. */
export type UsageProviderId = "claude" | "codex" | "cursor" | "copilot" | "grok" | "antigravity" | "opencode";

/** One limit of a plan: how much of it is used and when it starts over. */
export interface UsageWindow {
/** the span the limit counts over: a rolling session (5 hours), a day, a week or a billing month */
readonly kind: "session" | "day" | "week" | "month";
/** the model or quota a plan limits on its own ("Sonnet", "Premium"); null for the plan-wide limit */
readonly scope: string | null;
/** 0 to 100 */
readonly used_percent: number;
/** ISO 8601; null when the provider does not say */
readonly resets_at: string | null;
/** ISO 8601 time this window began counting; null when the provider states neither it nor the window's length */
readonly starts_at: string | null;
}

/**
* Why a provider's numbers are missing or old: its sign-in expired or was refused; the provider
* asked to slow down; the request failed; the macOS keychain holding the sign-in could not be
* read from this server's session.
*/
export type UsageProblem = "expired" | "rate_limited" | "failed" | "locked";

export interface ProviderUsage {
readonly id: UsageProviderId;
/**
* One account of one provider, stable across reads: the provider and its account id, or, for a
* sign-in that does not say whose it is, the provider and where it was found. A PC signed in to
* two accounts of one provider lists both.
*/
readonly key: string;
/** whose plan this is, as its owner knows the account: an email, or a GitHub login; null when unknown */
readonly account: string | null;
/** the plan's name as the provider states it ("max", "pro"), when it does */
readonly plan: string | null;
/** the last numbers read; kept through a later failure, which `problem` then names */
readonly windows: readonly UsageWindow[];
readonly problem: UsageProblem | null;
/** ISO 8601 time `windows` were read; null when they never were */
readonly checked_at: string | null;
}

/** GET /api/usage: only providers a CLI on this PC is signed in to are listed, once per account. */
export interface UsageReport {
readonly providers: readonly ProviderUsage[];
}
Loading