summaryrefslogtreecommitdiffhomepage
path: root/src/features/account-usage/logic/types.ts
blob: ff925901a8f97e4435fd0f8ba412a1f664b14c7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type {
  AccountUsageDailyCredits,
  AccountUsageLimit,
  AccountUsageProviderId,
  AccountUsageReport,
  AccountUsageResponse,
  AccountUsageState,
  UpdateAccountUsageSettingsRequest,
} from "@dispatch/transport-contract";

/**
 * Pure core types for the account-usage feature — zero DOM, zero effects.
 *
 * The backend (`account-usage` extension, transport-contract 0.25.0) polls the
 * Claude + Codex subscription usage endpoints and caches them (5 min TTL,
 * failure cooldowns, last-good retention). The FE reads `GET /usage`; a manual
 * refresh sends `?refresh=1`, which the server still rate-limits.
 */
export type {
  AccountUsageDailyCredits,
  AccountUsageLimit,
  AccountUsageProviderId,
  AccountUsageReport,
  AccountUsageResponse,
  AccountUsageState,
  UpdateAccountUsageSettingsRequest,
};

/** Outcome of `GET /usage`. `unavailable` = the backend extension isn't loaded (503). */
export type AccountUsageResult =
  | { readonly ok: true; readonly usage: AccountUsageResponse }
  | { readonly ok: false; readonly error: string; readonly unavailable?: boolean };

/** Injected port: load the account usage (`refresh` asks the server to bypass its TTL). */
export type LoadAccountUsage = (opts?: {
  readonly refresh?: boolean;
}) => Promise<AccountUsageResult>;

/** Outcome of `PUT /usage/:provider/settings` — the provider's refreshed report. */
export type AccountUsageSettingsResult =
  | { readonly ok: true; readonly report: AccountUsageReport }
  | { readonly ok: false; readonly error: string };

/** Injected port: update a provider's usage settings (today only `hyper`). */
export type SaveAccountUsageSettings = (
  provider: AccountUsageProviderId,
  settings: UpdateAccountUsageSettingsRequest,
) => Promise<AccountUsageSettingsResult>;