@narumitw/pi-usage 0.60.7 → 0.60.8

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 CHANGED
@@ -8,228 +8,228 @@ export type UsageUnit = "percent" | "usd" | "currency" | "count";
8
8
  export type UsageDisplayState = "current" | "configured";
9
9
 
10
10
  export interface UsageSemantics {
11
- kind: UsageSemanticsKind;
12
- label: string;
11
+ kind: UsageSemanticsKind;
12
+ label: string;
13
13
  }
14
14
 
15
15
  export interface UsageBucket {
16
- id: string;
17
- label: string;
18
- groupId?: string;
19
- groupLabel?: string;
20
- modelKeys?: string[];
21
- used?: number;
22
- remaining?: number;
23
- limit?: number;
24
- unit: UsageUnit;
25
- period?: string;
26
- windowMinutes?: number;
27
- resetsAt?: number;
16
+ id: string;
17
+ label: string;
18
+ groupId?: string;
19
+ groupLabel?: string;
20
+ modelKeys?: string[];
21
+ used?: number;
22
+ remaining?: number;
23
+ limit?: number;
24
+ unit: UsageUnit;
25
+ period?: string;
26
+ windowMinutes?: number;
27
+ resetsAt?: number;
28
28
  }
29
29
 
30
30
  export interface UsageMetric {
31
- id: string;
32
- label: string;
33
- value: number | string;
34
- unit?: UsageUnit;
35
- currency?: string;
31
+ id: string;
32
+ label: string;
33
+ value: number | string;
34
+ unit?: UsageUnit;
35
+ currency?: string;
36
36
  }
37
37
 
38
38
  export interface UsageReport {
39
- providerId: string;
40
- providerName: string;
41
- capturedAt: number;
42
- source: string;
43
- semantics: UsageSemantics;
44
- accountLabel?: string;
45
- buckets: UsageBucket[];
46
- metrics: UsageMetric[];
47
- notes?: string[];
39
+ providerId: string;
40
+ providerName: string;
41
+ capturedAt: number;
42
+ source: string;
43
+ semantics: UsageSemantics;
44
+ accountLabel?: string;
45
+ buckets: UsageBucket[];
46
+ metrics: UsageMetric[];
47
+ notes?: string[];
48
48
  }
49
49
 
50
50
  export interface ResolvedUsageAuth {
51
- apiKey?: string;
52
- headers: Record<string, string>;
53
- fingerprint: string;
54
- secrets: string[];
55
- model: PiModel;
56
- auth?: {
57
- apiKey?: string;
58
- headers?: Record<string, string | null>;
59
- baseUrl?: string;
60
- };
61
- env?: Record<string, string>;
62
- source?: string;
63
- effectiveBaseUrl?: string;
51
+ apiKey?: string;
52
+ headers: Record<string, string>;
53
+ fingerprint: string;
54
+ secrets: string[];
55
+ model: PiModel;
56
+ auth?: {
57
+ apiKey?: string;
58
+ headers?: Record<string, string | null>;
59
+ baseUrl?: string;
60
+ };
61
+ env?: Record<string, string>;
62
+ source?: string;
63
+ effectiveBaseUrl?: string;
64
64
  }
65
65
 
66
66
  export interface UsageQuerySettings {
67
- fireworksAccountId?: string;
67
+ fireworksAccountId?: string;
68
68
  }
69
69
 
70
70
  export type UsageRequestGuard = () => Promise<void>;
71
71
 
72
72
  export interface UsageProviderTarget {
73
- id: string;
74
- label: string;
75
- description?: string;
73
+ id: string;
74
+ label: string;
75
+ description?: string;
76
76
  }
77
77
 
78
78
  export interface UsageTargetResolver {
79
- singularLabel: string;
80
- pluralLabel: string;
81
- list(
82
- auth: ResolvedUsageAuth,
83
- signal: AbortSignal,
84
- timeoutMs: number,
85
- guard: UsageRequestGuard,
86
- ): Promise<readonly UsageProviderTarget[]>;
79
+ singularLabel: string;
80
+ pluralLabel: string;
81
+ list(
82
+ auth: ResolvedUsageAuth,
83
+ signal: AbortSignal,
84
+ timeoutMs: number,
85
+ guard: UsageRequestGuard,
86
+ ): Promise<readonly UsageProviderTarget[]>;
87
87
  }
88
88
 
89
89
  export interface UsageProviderAdapter {
90
- id: string;
91
- displayName: string;
92
- semantics: UsageSemantics;
93
- publishesStatusline?: boolean;
94
- /** Invalidate the matching ready report when the latest query fails; default preserves it. */
95
- invalidateCacheOnFailure?: boolean;
96
- targets?: UsageTargetResolver;
97
- query(
98
- auth: ResolvedUsageAuth,
99
- signal: AbortSignal,
100
- timeoutMs: number,
101
- guard?: UsageRequestGuard,
102
- targetId?: string,
103
- ): Promise<UsageReport>;
90
+ id: string;
91
+ displayName: string;
92
+ semantics: UsageSemantics;
93
+ publishesStatusline?: boolean;
94
+ /** Invalidate the matching ready report when the latest query fails; default preserves it. */
95
+ invalidateCacheOnFailure?: boolean;
96
+ targets?: UsageTargetResolver;
97
+ query(
98
+ auth: ResolvedUsageAuth,
99
+ signal: AbortSignal,
100
+ timeoutMs: number,
101
+ guard?: UsageRequestGuard,
102
+ targetId?: string,
103
+ ): Promise<UsageReport>;
104
104
  }
105
105
 
106
106
  export type ProviderUsageState =
107
- | {
108
- providerId: string;
109
- providerName: string;
110
- displayState: UsageDisplayState;
111
- status: "ready";
112
- report: UsageReport;
113
- }
114
- | {
115
- providerId: string;
116
- providerName: string;
117
- displayState: UsageDisplayState;
118
- status: "selection-required";
119
- singularLabel: string;
120
- pluralLabel: string;
121
- choices: readonly UsageProviderTarget[];
122
- }
123
- | {
124
- providerId: string;
125
- providerName: string;
126
- displayState: UsageDisplayState;
127
- status: "unsupported" | "auth-unavailable" | "query-failed";
128
- message: string;
129
- };
107
+ | {
108
+ providerId: string;
109
+ providerName: string;
110
+ displayState: UsageDisplayState;
111
+ status: "ready";
112
+ report: UsageReport;
113
+ }
114
+ | {
115
+ providerId: string;
116
+ providerName: string;
117
+ displayState: UsageDisplayState;
118
+ status: "selection-required";
119
+ singularLabel: string;
120
+ pluralLabel: string;
121
+ choices: readonly UsageProviderTarget[];
122
+ }
123
+ | {
124
+ providerId: string;
125
+ providerName: string;
126
+ displayState: UsageDisplayState;
127
+ status: "unsupported" | "auth-unavailable" | "query-failed";
128
+ message: string;
129
+ };
130
130
 
131
131
  export type BasetenBillingUsagePayload = {
132
- dedicated_usage?: unknown;
133
- model_apis_usage?: unknown;
134
- training_usage?: unknown;
132
+ dedicated_usage?: unknown;
133
+ model_apis_usage?: unknown;
134
+ training_usage?: unknown;
135
135
  };
136
136
 
137
137
  export type DeepSeekBalancePayload = {
138
- is_available?: unknown;
139
- balance_infos?: unknown;
138
+ is_available?: unknown;
139
+ balance_infos?: unknown;
140
140
  };
141
141
 
142
142
  export type FireworksAccountsPayload = {
143
- accounts?: unknown;
144
- nextPageToken?: unknown;
143
+ accounts?: unknown;
144
+ nextPageToken?: unknown;
145
145
  };
146
146
 
147
147
  export type FireworksBillingSummaryPayload = {
148
- lineItems?: unknown;
148
+ lineItems?: unknown;
149
149
  };
150
150
 
151
151
  export type GitHubCopilotUsagePayload = {
152
- login?: unknown;
153
- copilot_plan?: unknown;
154
- access_type_sku?: unknown;
155
- limited_user_quotas?: unknown;
156
- limited_user_reset_date?: unknown;
157
- monthly_quotas?: unknown;
158
- quota_reset_date?: unknown;
159
- quota_reset_date_utc?: unknown;
160
- quota_snapshots?: unknown;
152
+ login?: unknown;
153
+ copilot_plan?: unknown;
154
+ access_type_sku?: unknown;
155
+ limited_user_quotas?: unknown;
156
+ limited_user_reset_date?: unknown;
157
+ monthly_quotas?: unknown;
158
+ quota_reset_date?: unknown;
159
+ quota_reset_date_utc?: unknown;
160
+ quota_snapshots?: unknown;
161
161
  };
162
162
 
163
163
  export type OpenRouterKeyPayload = {
164
- data?: unknown;
164
+ data?: unknown;
165
165
  };
166
166
 
167
167
  export type MiniMaxUsagePayload = {
168
- available_amount?: unknown;
169
- balance_alert_switch?: unknown;
170
- balance_alert_threshold?: unknown;
171
- base_resp?: unknown;
172
- cash_balance?: unknown;
173
- credit_balance?: unknown;
174
- model_remains?: unknown;
175
- owed_amount?: unknown;
176
- voucher_balance?: unknown;
168
+ available_amount?: unknown;
169
+ balance_alert_switch?: unknown;
170
+ balance_alert_threshold?: unknown;
171
+ base_resp?: unknown;
172
+ cash_balance?: unknown;
173
+ credit_balance?: unknown;
174
+ model_remains?: unknown;
175
+ owed_amount?: unknown;
176
+ voucher_balance?: unknown;
177
177
  };
178
178
 
179
179
  export type MoonshotBalancePayload = {
180
- code?: unknown;
181
- data?: unknown;
182
- scode?: unknown;
183
- status?: unknown;
180
+ code?: unknown;
181
+ data?: unknown;
182
+ scode?: unknown;
183
+ status?: unknown;
184
184
  };
185
185
 
186
186
  export type VercelAIGatewayCreditsPayload = {
187
- balance?: unknown;
188
- total_used?: unknown;
187
+ balance?: unknown;
188
+ total_used?: unknown;
189
189
  };
190
190
 
191
191
  export type OpenCodeZenPayload = {
192
- usage?: unknown;
192
+ usage?: unknown;
193
193
  };
194
194
 
195
195
  export type ZaiQuotaPayload = {
196
- error?: unknown;
197
- code?: unknown;
198
- success?: unknown;
199
- data?: unknown;
196
+ error?: unknown;
197
+ code?: unknown;
198
+ success?: unknown;
199
+ data?: unknown;
200
200
  };
201
201
 
202
202
  export type ZaiSubscriptionPayload = {
203
- error?: unknown;
204
- code?: unknown;
205
- success?: unknown;
206
- data?: unknown;
203
+ error?: unknown;
204
+ code?: unknown;
205
+ success?: unknown;
206
+ data?: unknown;
207
207
  };
208
208
 
209
209
  export interface ZaiPlanInfo {
210
- name: string;
211
- renewsAt?: string;
210
+ name: string;
211
+ renewsAt?: string;
212
212
  }
213
213
 
214
214
  export type KimiCodingUsagePayload = {
215
- usage?: unknown;
216
- limits?: unknown;
217
- boosterWallet?: unknown;
215
+ usage?: unknown;
216
+ limits?: unknown;
217
+ boosterWallet?: unknown;
218
218
  };
219
219
 
220
220
  export type XaiUserPayload = {
221
- userId?: unknown;
222
- subscriptionTier?: unknown;
221
+ userId?: unknown;
222
+ subscriptionTier?: unknown;
223
223
  };
224
224
 
225
225
  export type XaiBillingPayload = {
226
- config?: unknown;
226
+ config?: unknown;
227
227
  };
228
228
 
229
229
  export type CodexBackendPayload = {
230
- plan_type?: unknown;
231
- rate_limit?: unknown;
232
- additional_rate_limits?: unknown;
233
- credits?: unknown;
234
- rate_limit_reset_credits?: unknown;
230
+ plan_type?: unknown;
231
+ rate_limit?: unknown;
232
+ additional_rate_limits?: unknown;
233
+ credits?: unknown;
234
+ rate_limit_reset_credits?: unknown;
235
235
  };
@@ -4,37 +4,37 @@ import { providerIsConfigured, usageAdapters } from "./query.js";
4
4
  import type { PiModel, UsageProviderAdapter } from "./types.js";
5
5
 
6
6
  export function configuredAdapters(ctx: ExtensionContext): UsageProviderAdapter[] {
7
- return usageAdapters().filter(
8
- (adapter) => adapter.id === ctx.model?.provider || providerIsConfigured(ctx, adapter.id),
9
- );
7
+ return usageAdapters().filter(
8
+ (adapter) => adapter.id === ctx.model?.provider || providerIsConfigured(ctx, adapter.id),
9
+ );
10
10
  }
11
11
 
12
12
  export function providerDisplayName(ctx: ExtensionContext, providerId: string): string {
13
- try {
14
- return sanitizeDisplayText(ctx.modelRegistry.getProviderDisplayName(providerId), 80);
15
- } catch {
16
- return sanitizeDisplayText(providerId, 80);
17
- }
13
+ try {
14
+ return sanitizeDisplayText(ctx.modelRegistry.getProviderDisplayName(providerId), 80);
15
+ } catch {
16
+ return sanitizeDisplayText(providerId, 80);
17
+ }
18
18
  }
19
19
 
20
20
  export function setBoundedMap<T>(map: Map<string, T>, key: string, value: T, limit: number): void {
21
- map.delete(key);
22
- while (map.size >= limit) {
23
- const oldest = map.keys().next().value;
24
- if (oldest === undefined) break;
25
- map.delete(oldest);
26
- }
27
- map.set(key, value);
21
+ map.delete(key);
22
+ while (map.size >= limit) {
23
+ const oldest = map.keys().next().value;
24
+ if (oldest === undefined) break;
25
+ map.delete(oldest);
26
+ }
27
+ map.set(key, value);
28
28
  }
29
29
 
30
30
  export function modelIdentity(model: PiModel | undefined): string | undefined {
31
- return model ? `${model.provider}/${model.id}` : undefined;
31
+ return model ? `${model.provider}/${model.id}` : undefined;
32
32
  }
33
33
 
34
34
  export function isAbortError(error: unknown): boolean {
35
- return error instanceof Error && error.name === "AbortError";
35
+ return error instanceof Error && error.name === "AbortError";
36
36
  }
37
37
 
38
38
  export function isTimeoutError(error: unknown): boolean {
39
- return error instanceof Error && error.name === "TimeoutError";
39
+ return error instanceof Error && error.name === "TimeoutError";
40
40
  }