@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/dist/index.ts +91 -339
- package/dist/index.ts.map +2 -2
- package/docs/providers.md +2 -1
- package/package.json +73 -74
- package/src/codex-fast-runtime.ts +148 -184
- package/src/codex-fast.ts +74 -83
- package/src/codex-resets.ts +249 -278
- package/src/core.ts +204 -206
- package/src/format.ts +519 -574
- package/src/index.ts +77 -77
- package/src/oauth-credential-source.ts +57 -65
- package/src/providers/baseten.ts +32 -36
- package/src/providers/codex.ts +109 -120
- package/src/providers/deepseek.ts +59 -64
- package/src/providers/fireworks.ts +219 -238
- package/src/providers/github-copilot.ts +89 -95
- package/src/providers/kimi-coding.ts +202 -213
- package/src/providers/minimax.ts +214 -219
- package/src/providers/moonshot.ts +41 -46
- package/src/providers/opencode-zen.ts +56 -59
- package/src/providers/openrouter.ts +50 -53
- package/src/providers/vercel-ai-gateway.ts +33 -33
- package/src/providers/xai.ts +141 -148
- package/src/providers/zai-errors.ts +75 -75
- package/src/providers/zai.ts +173 -189
- package/src/query.ts +887 -967
- package/src/settings.ts +275 -304
- package/src/types.ts +145 -145
- package/src/usage-helpers.ts +18 -18
- package/src/usage-settings-ui.ts +117 -126
- package/src/usage-targets.ts +98 -114
- package/src/usage.ts +1264 -1426
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
|
-
|
|
12
|
-
|
|
11
|
+
kind: UsageSemanticsKind;
|
|
12
|
+
label: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface UsageBucket {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
+
fireworksAccountId?: string;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export type UsageRequestGuard = () => Promise<void>;
|
|
71
71
|
|
|
72
72
|
export interface UsageProviderTarget {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
id: string;
|
|
74
|
+
label: string;
|
|
75
|
+
description?: string;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export interface UsageTargetResolver {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
dedicated_usage?: unknown;
|
|
133
|
+
model_apis_usage?: unknown;
|
|
134
|
+
training_usage?: unknown;
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
export type DeepSeekBalancePayload = {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
is_available?: unknown;
|
|
139
|
+
balance_infos?: unknown;
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
export type FireworksAccountsPayload = {
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
accounts?: unknown;
|
|
144
|
+
nextPageToken?: unknown;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
export type FireworksBillingSummaryPayload = {
|
|
148
|
-
|
|
148
|
+
lineItems?: unknown;
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
export type GitHubCopilotUsagePayload = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
164
|
+
data?: unknown;
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
export type MiniMaxUsagePayload = {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
code?: unknown;
|
|
181
|
+
data?: unknown;
|
|
182
|
+
scode?: unknown;
|
|
183
|
+
status?: unknown;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
export type VercelAIGatewayCreditsPayload = {
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
balance?: unknown;
|
|
188
|
+
total_used?: unknown;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
export type OpenCodeZenPayload = {
|
|
192
|
-
|
|
192
|
+
usage?: unknown;
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
export type ZaiQuotaPayload = {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
error?: unknown;
|
|
197
|
+
code?: unknown;
|
|
198
|
+
success?: unknown;
|
|
199
|
+
data?: unknown;
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
export type ZaiSubscriptionPayload = {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
error?: unknown;
|
|
204
|
+
code?: unknown;
|
|
205
|
+
success?: unknown;
|
|
206
|
+
data?: unknown;
|
|
207
207
|
};
|
|
208
208
|
|
|
209
209
|
export interface ZaiPlanInfo {
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
name: string;
|
|
211
|
+
renewsAt?: string;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
export type KimiCodingUsagePayload = {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
usage?: unknown;
|
|
216
|
+
limits?: unknown;
|
|
217
|
+
boosterWallet?: unknown;
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
export type XaiUserPayload = {
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
userId?: unknown;
|
|
222
|
+
subscriptionTier?: unknown;
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
export type XaiBillingPayload = {
|
|
226
|
-
|
|
226
|
+
config?: unknown;
|
|
227
227
|
};
|
|
228
228
|
|
|
229
229
|
export type CodexBackendPayload = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
plan_type?: unknown;
|
|
231
|
+
rate_limit?: unknown;
|
|
232
|
+
additional_rate_limits?: unknown;
|
|
233
|
+
credits?: unknown;
|
|
234
|
+
rate_limit_reset_credits?: unknown;
|
|
235
235
|
};
|
package/src/usage-helpers.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
+
return model ? `${model.provider}/${model.id}` : undefined;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function isAbortError(error: unknown): boolean {
|
|
35
|
-
|
|
35
|
+
return error instanceof Error && error.name === "AbortError";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function isTimeoutError(error: unknown): boolean {
|
|
39
|
-
|
|
39
|
+
return error instanceof Error && error.name === "TimeoutError";
|
|
40
40
|
}
|