@narumitw/pi-codex-usage 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,121 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+
3
+ export type UsageSource = "pi-auth" | "codex-app-server";
4
+ export type PiModel = NonNullable<ExtensionContext["model"]>;
5
+ export type CodexUsageModel = Pick<PiModel, "id" | "name" | "provider">;
6
+
7
+ export type QueryUsageOptions = {
8
+ clearStatusline: boolean;
9
+ refresh: boolean;
10
+ statusline: boolean;
11
+ timeoutMs: number;
12
+ };
13
+
14
+ export type CachedReport = {
15
+ createdAt: number;
16
+ report: CodexUsageReport;
17
+ };
18
+
19
+ export type QueryUsageResult =
20
+ | { ok: true; report: CodexUsageReport }
21
+ | { ok: false; errors: UsageQueryError[] };
22
+
23
+ export type UsageQueryError = {
24
+ source: UsageSource;
25
+ message: string;
26
+ cause?: unknown;
27
+ };
28
+
29
+ export type CodexUsageReport = {
30
+ source: UsageSource;
31
+ capturedAt: number;
32
+ planType?: string;
33
+ snapshots: NormalizedRateLimitSnapshot[];
34
+ };
35
+
36
+ export type NormalizedRateLimitSnapshot = {
37
+ limitId: string;
38
+ limitName?: string;
39
+ primary?: NormalizedRateLimitWindow;
40
+ secondary?: NormalizedRateLimitWindow;
41
+ credits?: NormalizedCredits;
42
+ };
43
+
44
+ export type NormalizedRateLimitWindow = {
45
+ usedPercent: number;
46
+ windowMinutes?: number;
47
+ resetsAt?: number;
48
+ };
49
+
50
+ export type NormalizedCredits = {
51
+ hasCredits: boolean;
52
+ unlimited: boolean;
53
+ balance?: string;
54
+ };
55
+
56
+ export type RateLimitStatusPayload = {
57
+ plan_type?: unknown;
58
+ rate_limit?: unknown;
59
+ additional_rate_limits?: unknown;
60
+ credits?: unknown;
61
+ };
62
+
63
+ export type BackendRateLimitDetails = {
64
+ primary_window?: unknown;
65
+ secondary_window?: unknown;
66
+ };
67
+
68
+ export type BackendWindowSnapshot = {
69
+ used_percent?: unknown;
70
+ limit_window_seconds?: unknown;
71
+ reset_at?: unknown;
72
+ };
73
+
74
+ export type BackendAdditionalRateLimit = {
75
+ limit_name?: unknown;
76
+ metered_feature?: unknown;
77
+ rate_limit?: unknown;
78
+ };
79
+
80
+ export type BackendCreditsSnapshot = {
81
+ has_credits?: unknown;
82
+ unlimited?: unknown;
83
+ balance?: unknown;
84
+ };
85
+
86
+ export type AppServerRateLimitResponse = {
87
+ rateLimits?: unknown;
88
+ rateLimitsByLimitId?: unknown;
89
+ };
90
+
91
+ export type AppServerRateLimitSnapshot = {
92
+ limitId?: unknown;
93
+ limitName?: unknown;
94
+ primary?: unknown;
95
+ secondary?: unknown;
96
+ credits?: unknown;
97
+ planType?: unknown;
98
+ };
99
+
100
+ export type AppServerWindowSnapshot = {
101
+ usedPercent?: unknown;
102
+ windowDurationMins?: unknown;
103
+ resetsAt?: unknown;
104
+ };
105
+
106
+ export type AppServerCreditsSnapshot = {
107
+ hasCredits?: unknown;
108
+ unlimited?: unknown;
109
+ balance?: unknown;
110
+ };
111
+
112
+ export type RpcResponse = {
113
+ id?: unknown;
114
+ result?: unknown;
115
+ error?: { message?: unknown; code?: unknown };
116
+ };
117
+
118
+ export type PendingRpc = {
119
+ resolve: (value: unknown) => void;
120
+ reject: (error: Error) => void;
121
+ };