omp-multi-auth 1.4.3 → 2.0.0
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/README.md +4 -4
- package/extensions/lib/core.ts +1 -2
- package/extensions/lib/providers.ts +4 -71
- package/extensions/lib/quota.ts +9 -624
- package/extensions/multi-auth.ts +1 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Multi-account OAuth login for [omp (Oh My Pi)](https://github.com/can1357/oh-my-pi). Add, authenticate, and switch between multiple accounts per provider. OMP's built-in fallback handles rate-limit retry and model fallback.
|
|
4
4
|
|
|
5
|
+
Requires the latest omp release. Older omp versions are not supported; a daily CI job tests against the newest omp.
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -75,8 +77,6 @@ Create `.omp/multi-auth.json` in a project to restrict which subscription provid
|
|
|
75
77
|
| `anthropic` | Anthropic (Claude Pro/Max) |
|
|
76
78
|
| `openai-codex` | ChatGPT Plus/Pro (Codex) |
|
|
77
79
|
| `github-copilot` | GitHub Copilot |
|
|
78
|
-
| `google-gemini-cli` | Google Cloud Code Assist |
|
|
79
|
-
| `google-antigravity` | Antigravity |
|
|
80
80
|
| `kimi-code` | Kimi Code |
|
|
81
81
|
| `xai-oauth` | xAI Grok OAuth |
|
|
82
82
|
| `cursor` | Cursor (browser PKCE OAuth or API key) |
|
|
@@ -110,11 +110,11 @@ For `cursor`, `/multi-auth login` prompts for a dashboard API key (`crsr_...`/`c
|
|
|
110
110
|
|
|
111
111
|
## Built-in quotas
|
|
112
112
|
|
|
113
|
-
Run `/multi-auth limits` to inspect quota and usage information for supported providers. This currently includes built-in quota checks for Codex
|
|
113
|
+
Run `/multi-auth limits` to inspect quota and usage information for supported providers. This currently includes built-in quota checks for Codex and OpenCode Go providers. Results depend on provider availability and authenticated account state.
|
|
114
114
|
|
|
115
115
|
OpenCode Go reports 5-hour, weekly, and monthly windows. The status line and ready/low/blocked state use the tighter of the 5-hour and weekly windows; the monthly window is shown for reference only, because an exhausted month can still serve requests when the account's "Use balance" fallback is on.
|
|
116
116
|
|
|
117
|
-
Added accounts also report usage to OMP itself, so `/usage`, `omp usage`, and status lines built on OMP's usage reports show each account (for example `anthropic-2`) next to the base provider. This works for every provider OMP has a usage fetcher for
|
|
117
|
+
Added accounts also report usage to OMP itself, so `/usage`, `omp usage`, and status lines built on OMP's usage reports show each account (for example `anthropic-2`) next to the base provider. This works for every provider OMP has a usage fetcher for. OMP caches, refreshes and invalidates these reports like any other provider's. Until OMP keeps a registered provider's reports across processes ([can1357/oh-my-pi#20030](https://github.com/can1357/oh-my-pi/pull/20030)), each new OMP process probes each added account once.
|
|
118
118
|
|
|
119
119
|
## Configuration files
|
|
120
120
|
|
package/extensions/lib/core.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { ExtensionCommandContext, ExtensionContext, AuthStorage as HostAuthStorage } from "@oh-my-pi/pi-coding-agent";
|
|
3
3
|
import { getBundledModels, type GeneratedProvider } from "@oh-my-pi/pi-catalog";
|
|
4
4
|
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
5
|
-
import type {
|
|
5
|
+
import type { CodexUsageSnapshot, OpenCodeGoUsageSnapshot } from "./quota.ts";
|
|
6
6
|
|
|
7
7
|
export function getModels(providerId: string): Model<Api>[] {
|
|
8
8
|
return getBundledModels(providerId as GeneratedProvider) as Model<Api>[];
|
|
@@ -182,7 +182,6 @@ export interface QuotaCheckResult {
|
|
|
182
182
|
summary: string;
|
|
183
183
|
details: string[];
|
|
184
184
|
score: number;
|
|
185
|
-
googleSnapshot?: GoogleQuotaAccountSnapshot;
|
|
186
185
|
codexSnapshot?: CodexUsageSnapshot;
|
|
187
186
|
opencodeGoSnapshot?: OpenCodeGoUsageSnapshot;
|
|
188
187
|
}
|
|
@@ -8,6 +8,7 @@ import { getAgentDir, type ExtensionAPI, type ProviderConfig, type ProviderModel
|
|
|
8
8
|
import { getProviderDefinition } from "@oh-my-pi/pi-ai/registry";
|
|
9
9
|
import type { OAuthCredentials, OAuthLoginCallbacks } from "@oh-my-pi/pi-ai/oauth";
|
|
10
10
|
import { AssistantMessageEventStream, streamSimple, type Api, type AssistantMessageEvent, type Context, type Model, type SimpleStreamOptions, type UsageProvider, type UsageReport } from "@oh-my-pi/pi-ai";
|
|
11
|
+
import { defaultUsageProvider } from "@oh-my-pi/pi-ai/usage/registry";
|
|
11
12
|
import { buildModel } from "@oh-my-pi/pi-catalog/build";
|
|
12
13
|
import { fetchCodexModels } from "@oh-my-pi/pi-catalog/discovery/codex";
|
|
13
14
|
import { CODEX_BASE_URL, getCodexAccountId } from "@oh-my-pi/pi-catalog/wire/codex";
|
|
@@ -34,9 +35,7 @@ export function getRegisteredProviderApiKey(providerId: string, credentials: OAu
|
|
|
34
35
|
case "kimi-code":
|
|
35
36
|
case "xai-oauth":
|
|
36
37
|
return credentials.access;
|
|
37
|
-
case "github-copilot":
|
|
38
|
-
case "google-gemini-cli":
|
|
39
|
-
case "google-antigravity": {
|
|
38
|
+
case "github-copilot": {
|
|
40
39
|
const registered = credentials as OAuthCredentials & {
|
|
41
40
|
apiEndpoint?: string;
|
|
42
41
|
enterpriseUrl?: string;
|
|
@@ -193,7 +192,6 @@ export function getGitHubCopilotBaseUrl(token: string | undefined, enterpriseUrl
|
|
|
193
192
|
// through one shared wrapper, which restores canonical identity only inside
|
|
194
193
|
// transport and puts subscription identity back on emitted assistant messages.
|
|
195
194
|
export const SUB_TRANSPORT_CONFIG: Record<string, { builtinApi: Api | ((modelId: string) => Api); customApiId: string }> = {
|
|
196
|
-
"google-antigravity": { builtinApi: "google-gemini-cli", customApiId: "google-antigravity-mp" },
|
|
197
195
|
// pi-ai keys X-Api-Key (anthropic-messages) and x-opencode-session on provider === "opencode-go".
|
|
198
196
|
"opencode-go": {
|
|
199
197
|
builtinApi: (modelId) => getModels("opencode-go").find(m => m.id === modelId)?.api ?? "openai-completions",
|
|
@@ -202,44 +200,6 @@ export const SUB_TRANSPORT_CONFIG: Record<string, { builtinApi: Api | ((modelId:
|
|
|
202
200
|
};
|
|
203
201
|
|
|
204
202
|
|
|
205
|
-
const ANTIGRAVITY_ZWSP = "\u200B";
|
|
206
|
-
|
|
207
|
-
/** Substrings that make up Cloud Code Assist's system-prompt abuse fingerprint
|
|
208
|
-
* (omp #11699, #12655). The live trigger is the `<conventions>` tag plus the
|
|
209
|
-
* `RFC 2119: ...` sentence; breaking any one component defeats it. */
|
|
210
|
-
export const ANTIGRAVITY_FINGERPRINTS = ["RFC 2119", "<conventions>", "</conventions>"] as const;
|
|
211
|
-
|
|
212
|
-
/** Break Cloud Code Assist's system-prompt fingerprint so it stops masking
|
|
213
|
-
* requests as 429 RESOURCE_EXHAUSTED (omp #11699, #12655). A zero-width space is
|
|
214
|
-
* inserted into each flagged substring: invisible to the model, but it breaks
|
|
215
|
-
* the contiguous literal the upstream WAF matches. Idempotent — a second pass
|
|
216
|
-
* finds no intact substring. Content is otherwise preserved. */
|
|
217
|
-
export function defeatAntigravityFingerprint(text: string): string {
|
|
218
|
-
let out = text;
|
|
219
|
-
for (const s of ANTIGRAVITY_FINGERPRINTS) {
|
|
220
|
-
out = out.split(s).join(s[0] + ANTIGRAVITY_ZWSP + s.slice(1));
|
|
221
|
-
}
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export function rewriteAntigravitySystemInstruction(payload: unknown): unknown {
|
|
226
|
-
if (!payload || typeof payload !== "object") return payload;
|
|
227
|
-
const body = payload as Record<string, unknown>;
|
|
228
|
-
const request = body.request;
|
|
229
|
-
if (!request || typeof request !== "object") return payload;
|
|
230
|
-
const req = request as Record<string, unknown>;
|
|
231
|
-
const sys = req.systemInstruction;
|
|
232
|
-
if (!sys || typeof sys !== "object") return payload;
|
|
233
|
-
const sysObj = sys as Record<string, unknown>;
|
|
234
|
-
if (!Array.isArray(sysObj.parts)) return payload;
|
|
235
|
-
const parts = sysObj.parts.map(part =>
|
|
236
|
-
part && typeof part === "object" && typeof (part as { text?: unknown }).text === "string"
|
|
237
|
-
? { ...part, text: defeatAntigravityFingerprint((part as { text: string }).text) }
|
|
238
|
-
: part,
|
|
239
|
-
);
|
|
240
|
-
return { ...body, request: { ...req, systemInstruction: { ...sysObj, parts } } };
|
|
241
|
-
}
|
|
242
|
-
|
|
243
203
|
export type SubscriptionStream = (
|
|
244
204
|
model: Model<Api>,
|
|
245
205
|
context: Context,
|
|
@@ -274,14 +234,7 @@ export function createSubscriptionStream(
|
|
|
274
234
|
const internalOptions: SimpleStreamOptions = {
|
|
275
235
|
...(options ?? {}),
|
|
276
236
|
headers: options?.headers,
|
|
277
|
-
onPayload: async (payload: unknown) =>
|
|
278
|
-
const rewritten =
|
|
279
|
-
canonicalProvider === "google-antigravity"
|
|
280
|
-
? rewriteAntigravitySystemInstruction(payload)
|
|
281
|
-
: payload;
|
|
282
|
-
const replacement = await options?.onPayload?.(rewritten, model);
|
|
283
|
-
return replacement ?? rewritten;
|
|
284
|
-
},
|
|
237
|
+
onPayload: async (payload: unknown) => (await options?.onPayload?.(payload, model)) ?? payload,
|
|
285
238
|
onSseEvent: options?.onSseEvent
|
|
286
239
|
? (event: Parameters<NonNullable<SimpleStreamOptions["onSseEvent"]>>[0]) => options.onSseEvent?.(event, model)
|
|
287
240
|
: undefined,
|
|
@@ -380,20 +333,6 @@ export const PROVIDER_TEMPLATES: Record<string, ProviderTemplate> = {
|
|
|
380
333
|
},
|
|
381
334
|
},
|
|
382
335
|
|
|
383
|
-
"google-gemini-cli": {
|
|
384
|
-
displayName: "Google Cloud Code Assist",
|
|
385
|
-
buildOAuth(index: number) {
|
|
386
|
-
return flowBackedOAuth("google-gemini-cli", `Google Cloud Code Assist #${index}`);
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
|
|
390
|
-
"google-antigravity": {
|
|
391
|
-
displayName: "Antigravity",
|
|
392
|
-
buildOAuth(index: number) {
|
|
393
|
-
return flowBackedOAuth("google-antigravity", `Antigravity #${index}`);
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
|
|
397
336
|
"kimi-code": {
|
|
398
337
|
displayName: "Kimi Code",
|
|
399
338
|
buildOAuth(index: number) {
|
|
@@ -424,7 +363,6 @@ for (const spec of API_KEY_PROVIDERS) {
|
|
|
424
363
|
};
|
|
425
364
|
}
|
|
426
365
|
|
|
427
|
-
|
|
428
366
|
export const SUPPORTED_PROVIDERS = Object.keys(PROVIDER_TEMPLATES);
|
|
429
367
|
|
|
430
368
|
export function subDisplayName(entry: SubEntry): string {
|
|
@@ -470,16 +408,11 @@ export function cloneModels(originalProvider: string, index: number): ProviderMo
|
|
|
470
408
|
// Register a single subscription as a provider
|
|
471
409
|
// ==========================================================================
|
|
472
410
|
|
|
473
|
-
// pi-ai added the usage registry after 18.1.20, the lowest host this extension
|
|
474
|
-
// supports. A static import would stop the whole extension from loading there,
|
|
475
|
-
// so older hosts load it and their added accounts get no usage report.
|
|
476
|
-
const usageRegistry = await import("@oh-my-pi/pi-ai/usage/registry").catch(() => undefined);
|
|
477
|
-
|
|
478
411
|
// Built-in usage fetchers only accept their own provider id, so a sub would get no
|
|
479
412
|
// usage report. Probe as the base provider and relabel the report as the sub. The
|
|
480
413
|
// host caches, invalidates and retains the relabeled report under the sub's id.
|
|
481
414
|
function subUsageProvider(baseProvider: string, name: string): UsageProvider | undefined {
|
|
482
|
-
const base =
|
|
415
|
+
const base = defaultUsageProvider(baseProvider);
|
|
483
416
|
if (!base) return undefined;
|
|
484
417
|
const asSub = (report: UsageReport | null): UsageReport | null =>
|
|
485
418
|
report && {
|
package/extensions/lib/quota.ts
CHANGED
|
@@ -4,33 +4,13 @@
|
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import type { ExtensionCommandContext, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
6
6
|
import * as agent from "@oh-my-pi/pi-coding-agent";
|
|
7
|
-
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
8
7
|
import { getBaseProvider, subDisplayName, PROVIDER_TEMPLATES } from "./providers.ts";
|
|
9
|
-
import { getAuthStorage, adaptAuthStorage, getModels, subProviderName, type AuthStorageEntry, type
|
|
8
|
+
import { getAuthStorage, adaptAuthStorage, getModels, subProviderName, type AuthStorageEntry, type QuotaAccount, type QuotaCheckResult, type QuotaStatusKind, type ProviderQuotaChecker, type AuthStorage } from "./core.ts";
|
|
10
9
|
import { loadGlobalConfig, loadProjectConfig, parseEnvConfig, mergeConfigs, normalizeEntries } from "./config.ts";
|
|
11
10
|
import { showWrappedSelect } from "./ui.ts";
|
|
12
11
|
import type { SelectItem } from "@oh-my-pi/pi-tui";
|
|
13
12
|
|
|
14
13
|
export const DEFAULT_CODEX_USAGE_BASE_URL = "https://chatgpt.com/backend-api";
|
|
15
|
-
export const GOOGLE_GEMINI_QUOTA_ENDPOINT = "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota";
|
|
16
|
-
export const GOOGLE_ANTIGRAVITY_QUOTA_ENDPOINTS = [
|
|
17
|
-
"https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:fetchAvailableModels",
|
|
18
|
-
"https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
|
|
19
|
-
] as const;
|
|
20
|
-
export const GOOGLE_GEMINI_HEADERS = {
|
|
21
|
-
"User-Agent": "google-api-nodejs-client/9.15.1",
|
|
22
|
-
"X-Goog-Api-Client": "gl-node/22.17.0",
|
|
23
|
-
};
|
|
24
|
-
export const GOOGLE_ANTIGRAVITY_HEADERS = {
|
|
25
|
-
"User-Agent": "antigravity/1.11.9 windows/amd64",
|
|
26
|
-
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
27
|
-
"Client-Metadata": JSON.stringify({
|
|
28
|
-
ideType: "IDE_UNSPECIFIED",
|
|
29
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
30
|
-
pluginType: "GEMINI",
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
export const GOOGLE_ANTIGRAVITY_HIDDEN_MODELS = new Set(["tab_flash_lite_preview"]);
|
|
34
14
|
export const OPENAI_AUTH_CLAIM = "https://api.openai.com/auth";
|
|
35
15
|
export const OPENAI_PROFILE_CLAIM = "https://api.openai.com/profile";
|
|
36
16
|
|
|
@@ -59,43 +39,6 @@ export interface OpenCodeGoUsageSnapshot {
|
|
|
59
39
|
monthly: OpenCodeGoUsageWindow;
|
|
60
40
|
}
|
|
61
41
|
|
|
62
|
-
export interface GoogleGeminiQuotaResponse {
|
|
63
|
-
buckets?: Array<{
|
|
64
|
-
modelId?: string;
|
|
65
|
-
remainingFraction?: number;
|
|
66
|
-
resetTime?: string;
|
|
67
|
-
}>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface GoogleAntigravityQuotaResponse {
|
|
71
|
-
models?: Record<
|
|
72
|
-
string,
|
|
73
|
-
{
|
|
74
|
-
displayName?: string;
|
|
75
|
-
model?: string;
|
|
76
|
-
isInternal?: boolean;
|
|
77
|
-
quotaInfo?: {
|
|
78
|
-
remainingFraction?: number;
|
|
79
|
-
resetTime?: string;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface GoogleQuotaModelSnapshot {
|
|
86
|
-
model: string;
|
|
87
|
-
remainingPercent?: number;
|
|
88
|
-
resetAt?: number;
|
|
89
|
-
key?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface GoogleQuotaAccountSnapshot {
|
|
93
|
-
endpoint: string;
|
|
94
|
-
projectId?: string;
|
|
95
|
-
models: GoogleQuotaModelSnapshot[];
|
|
96
|
-
worstRemainingPercent?: number;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
42
|
export function decodeJwtPayload(token: string): Record<string, unknown> {
|
|
100
43
|
const parts = token.split(".");
|
|
101
44
|
if (parts.length < 2) return {};
|
|
@@ -359,7 +302,6 @@ export function formatQuotaOverview(results: QuotaCheckResult[]): string {
|
|
|
359
302
|
export function formatQuotaCurrentHint(
|
|
360
303
|
results: QuotaCheckResult[],
|
|
361
304
|
currentProviderName: string | undefined,
|
|
362
|
-
currentModel?: { id: string; name: string },
|
|
363
305
|
): string | undefined {
|
|
364
306
|
if (!currentProviderName) return undefined;
|
|
365
307
|
|
|
@@ -367,13 +309,6 @@ export function formatQuotaCurrentHint(
|
|
|
367
309
|
if (!current) return undefined;
|
|
368
310
|
|
|
369
311
|
let hint = `Current: ${current.account.displayName} is ${formatQuotaKind(current.kind)}`;
|
|
370
|
-
if (current.googleSnapshot && currentModel) {
|
|
371
|
-
const matches = matchGoogleQuotaModels(current.account.baseProvider, currentModel, current.googleSnapshot);
|
|
372
|
-
const worst = pickWorstQuotaModel(matches);
|
|
373
|
-
if (worst) {
|
|
374
|
-
hint += ` • ${worst.model} ${formatRemainingPercent(worst.remainingPercent)} left`;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
312
|
const best = results[0];
|
|
378
313
|
if (best && best.account.providerName !== current.account.providerName) {
|
|
379
314
|
hint += ` • best available: ${best.account.displayName}`;
|
|
@@ -467,7 +402,7 @@ export async function selectQuotaResult(
|
|
|
467
402
|
subtitle: [
|
|
468
403
|
"Select an account to inspect its full quota windows.",
|
|
469
404
|
formatQuotaOverview(results),
|
|
470
|
-
formatQuotaCurrentHint(results, currentProviderName
|
|
405
|
+
formatQuotaCurrentHint(results, currentProviderName),
|
|
471
406
|
].filter(Boolean).join("\n"),
|
|
472
407
|
items: buildQuotaSelectItems(results, currentProviderName),
|
|
473
408
|
initialValue: currentProviderName,
|
|
@@ -478,528 +413,6 @@ export async function selectQuotaResult(
|
|
|
478
413
|
return results.find((result) => result.account.providerName === selectedProviderName);
|
|
479
414
|
}
|
|
480
415
|
|
|
481
|
-
export function normalizeGoogleRemainingPercent(value: unknown): number | undefined {
|
|
482
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
|
|
483
|
-
return Math.max(0, Math.min(100, Math.round(value * 100)));
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export function getGoogleProjectId(account: QuotaAccount, auth: AuthStorageEntry): string | undefined {
|
|
487
|
-
if (typeof auth.projectId === "string" && auth.projectId.length > 0) {
|
|
488
|
-
return auth.projectId;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (account.baseProvider === "google-antigravity") {
|
|
492
|
-
const projectId = process.env.GOOGLE_ANTIGRAVITY_PROJECT_ID || process.env.GOOGLE_ANTIGRAVITY_PROJECT;
|
|
493
|
-
if (projectId) return projectId;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const projectId = process.env.GOOGLE_CLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT_ID;
|
|
497
|
-
return projectId || undefined;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
export function updateGoogleQuotaModel(
|
|
501
|
-
modelsByName: Map<string, GoogleQuotaModelSnapshot>,
|
|
502
|
-
model: string,
|
|
503
|
-
remainingPercent: number | undefined,
|
|
504
|
-
resetAt: number | undefined,
|
|
505
|
-
key?: string,
|
|
506
|
-
): void {
|
|
507
|
-
const existing = modelsByName.get(model);
|
|
508
|
-
if (!existing) {
|
|
509
|
-
modelsByName.set(model, { model, remainingPercent, resetAt, key });
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
let next = existing;
|
|
514
|
-
if (existing.key === undefined && key !== undefined) {
|
|
515
|
-
next = { ...next, key };
|
|
516
|
-
}
|
|
517
|
-
if (remainingPercent !== undefined) {
|
|
518
|
-
if (existing.remainingPercent === undefined || remainingPercent < existing.remainingPercent) {
|
|
519
|
-
next = { ...next, remainingPercent };
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
if (resetAt !== undefined) {
|
|
523
|
-
if (next.resetAt === undefined || resetAt < next.resetAt) {
|
|
524
|
-
next = { ...next, resetAt };
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
if (next !== existing) {
|
|
528
|
-
modelsByName.set(model, next);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
export function buildGoogleQuotaSnapshot(
|
|
533
|
-
endpoint: string,
|
|
534
|
-
projectId: string | undefined,
|
|
535
|
-
modelsByName: Map<string, GoogleQuotaModelSnapshot>,
|
|
536
|
-
): GoogleQuotaAccountSnapshot {
|
|
537
|
-
const models = [...modelsByName.values()];
|
|
538
|
-
const remainingPercents = models
|
|
539
|
-
.map((model) => model.remainingPercent)
|
|
540
|
-
.filter((value): value is number => value !== undefined);
|
|
541
|
-
const worstRemainingPercent = remainingPercents.length > 0
|
|
542
|
-
? Math.min(...remainingPercents)
|
|
543
|
-
: undefined;
|
|
544
|
-
|
|
545
|
-
return {
|
|
546
|
-
endpoint,
|
|
547
|
-
projectId,
|
|
548
|
-
models,
|
|
549
|
-
worstRemainingPercent,
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
export function getGoogleGeminiModelLabel(modelId: string | undefined): string {
|
|
554
|
-
if (!modelId) return "unknown";
|
|
555
|
-
const normalized = modelId.toLowerCase();
|
|
556
|
-
if (normalized.includes("pro")) return "Pro";
|
|
557
|
-
if (normalized.includes("flash")) return "Flash";
|
|
558
|
-
return modelId;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
export function parseGoogleGeminiQuotaSnapshot(
|
|
562
|
-
data: unknown,
|
|
563
|
-
projectId: string | undefined,
|
|
564
|
-
): GoogleQuotaAccountSnapshot {
|
|
565
|
-
const raw = getRecord(data) as GoogleGeminiQuotaResponse | undefined;
|
|
566
|
-
const buckets = Array.isArray(raw?.buckets) ? raw.buckets : [];
|
|
567
|
-
const modelsByName = new Map<string, GoogleQuotaModelSnapshot>();
|
|
568
|
-
|
|
569
|
-
for (const bucketValue of buckets) {
|
|
570
|
-
const bucket = getRecord(bucketValue);
|
|
571
|
-
const rawKey = typeof bucket?.modelId === "string" ? bucket.modelId : undefined;
|
|
572
|
-
if (rawKey && (rawKey.toLowerCase().includes("placeholder") || rawKey.toLowerCase().startsWith("tab_"))) {
|
|
573
|
-
continue;
|
|
574
|
-
}
|
|
575
|
-
const model = getGoogleGeminiModelLabel(rawKey);
|
|
576
|
-
if (model.toLowerCase().includes("placeholder")) continue;
|
|
577
|
-
const remainingPercent = normalizeGoogleRemainingPercent(bucket?.remainingFraction);
|
|
578
|
-
const resetAt = typeof bucket?.resetTime === "string"
|
|
579
|
-
? parseIsoTimestampSeconds(bucket.resetTime)
|
|
580
|
-
: undefined;
|
|
581
|
-
if (remainingPercent === undefined && resetAt === undefined) continue;
|
|
582
|
-
updateGoogleQuotaModel(modelsByName, model, remainingPercent, resetAt, rawKey);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
return buildGoogleQuotaSnapshot(GOOGLE_GEMINI_QUOTA_ENDPOINT, projectId, modelsByName);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
export function isGoogleAntigravityPlaceholder(value: string | undefined): boolean {
|
|
589
|
-
if (!value) return true;
|
|
590
|
-
const lower = value.toLowerCase();
|
|
591
|
-
return lower.includes("placeholder") || lower.startsWith("model_");
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export function isGoogleAntigravityHiddenModel(modelKey: string, displayName?: string): boolean {
|
|
595
|
-
const lowerKey = modelKey.toLowerCase();
|
|
596
|
-
if (
|
|
597
|
-
lowerKey.startsWith("tab_") ||
|
|
598
|
-
lowerKey.startsWith("chat_") ||
|
|
599
|
-
lowerKey.includes("placeholder") ||
|
|
600
|
-
GOOGLE_ANTIGRAVITY_HIDDEN_MODELS.has(lowerKey)
|
|
601
|
-
) {
|
|
602
|
-
return true;
|
|
603
|
-
}
|
|
604
|
-
if (displayName) {
|
|
605
|
-
const lowerName = displayName.toLowerCase();
|
|
606
|
-
if (
|
|
607
|
-
lowerName.includes("placeholder") ||
|
|
608
|
-
GOOGLE_ANTIGRAVITY_HIDDEN_MODELS.has(lowerName)
|
|
609
|
-
) {
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
export function formatAntigravityModelKey(key: string): string {
|
|
617
|
-
const base = key.replace(/-tiered$/, "");
|
|
618
|
-
try {
|
|
619
|
-
const bundled = getModels("google-antigravity");
|
|
620
|
-
const exact = bundled.find((m) => m.id === key);
|
|
621
|
-
if (exact) return exact.name;
|
|
622
|
-
const baseMatch = bundled.find((m) => m.id === base);
|
|
623
|
-
if (baseMatch) return baseMatch.name;
|
|
624
|
-
} catch {
|
|
625
|
-
// Fall back to title-casing below
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
return base
|
|
629
|
-
.split("-")
|
|
630
|
-
.map((part) => (part.length > 0 ? part[0].toUpperCase() + part.slice(1) : part))
|
|
631
|
-
.join(" ");
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
export function parseGoogleAntigravityQuotaSnapshot(
|
|
635
|
-
data: unknown,
|
|
636
|
-
endpoint: string,
|
|
637
|
-
projectId: string | undefined,
|
|
638
|
-
): GoogleQuotaAccountSnapshot {
|
|
639
|
-
const raw = getRecord(data) as GoogleAntigravityQuotaResponse | undefined;
|
|
640
|
-
const rawModels = getRecord(raw?.models);
|
|
641
|
-
const modelsByName = new Map<string, GoogleQuotaModelSnapshot>();
|
|
642
|
-
|
|
643
|
-
if (rawModels) {
|
|
644
|
-
for (const [modelKey, modelValue] of Object.entries(rawModels)) {
|
|
645
|
-
const model = getRecord(modelValue);
|
|
646
|
-
if (model?.isInternal === true) continue;
|
|
647
|
-
if (isGoogleAntigravityHiddenModel(modelKey)) continue;
|
|
648
|
-
|
|
649
|
-
const rawDisplayName = typeof model?.displayName === "string" && model.displayName.length > 0
|
|
650
|
-
? model.displayName
|
|
651
|
-
: typeof model?.model === "string" && model.model.length > 0 && !isGoogleAntigravityPlaceholder(model.model)
|
|
652
|
-
? model.model
|
|
653
|
-
: undefined;
|
|
654
|
-
|
|
655
|
-
const displayName = (rawDisplayName && !isGoogleAntigravityPlaceholder(rawDisplayName))
|
|
656
|
-
? rawDisplayName
|
|
657
|
-
: formatAntigravityModelKey(modelKey);
|
|
658
|
-
|
|
659
|
-
if (isGoogleAntigravityHiddenModel(modelKey, displayName)) continue;
|
|
660
|
-
|
|
661
|
-
const quotaInfo = getRecord(model?.quotaInfo);
|
|
662
|
-
const remainingPercent = normalizeGoogleRemainingPercent(quotaInfo?.remainingFraction);
|
|
663
|
-
const resetAt = typeof quotaInfo?.resetTime === "string"
|
|
664
|
-
? parseIsoTimestampSeconds(quotaInfo.resetTime)
|
|
665
|
-
: undefined;
|
|
666
|
-
if (remainingPercent === undefined && resetAt === undefined) continue;
|
|
667
|
-
updateGoogleQuotaModel(modelsByName, displayName, remainingPercent, resetAt, modelKey);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
return buildGoogleQuotaSnapshot(endpoint, projectId, modelsByName);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
export function normalizeModelToken(value: string): string {
|
|
675
|
-
return value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
export function stripCloneSuffix(name: string): string {
|
|
679
|
-
return name.replace(/\s*\(#\d+\)\s*$/, "");
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
export function getGeminiFamily(model: { id: string; name: string }): "pro" | "flash" | undefined {
|
|
683
|
-
const idNorm = normalizeModelToken(model.id);
|
|
684
|
-
const nameNorm = normalizeModelToken(model.name);
|
|
685
|
-
if (idNorm.includes("pro") || nameNorm.includes("pro")) return "pro";
|
|
686
|
-
if (idNorm.includes("flash") || nameNorm.includes("flash")) return "flash";
|
|
687
|
-
return undefined;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
export function matchGoogleQuotaModels(
|
|
691
|
-
baseProvider: string,
|
|
692
|
-
model: { id: string; name: string },
|
|
693
|
-
snapshot: GoogleQuotaAccountSnapshot,
|
|
694
|
-
): GoogleQuotaModelSnapshot[] {
|
|
695
|
-
if (baseProvider === "google-gemini-cli") {
|
|
696
|
-
const family = getGeminiFamily(model);
|
|
697
|
-
if (!family) return [];
|
|
698
|
-
return snapshot.models.filter((bucket) => bucket.model.toLowerCase() === family);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
const mid = normalizeModelToken(model.id);
|
|
702
|
-
const mname = normalizeModelToken(stripCloneSuffix(model.name));
|
|
703
|
-
|
|
704
|
-
return snapshot.models.filter((bucket) => {
|
|
705
|
-
const bkey = normalizeModelToken(bucket.key ?? "");
|
|
706
|
-
const blabel = normalizeModelToken(bucket.model);
|
|
707
|
-
|
|
708
|
-
if (bkey && mid && bkey === mid) return true;
|
|
709
|
-
if (blabel && mname && blabel === mname) return true;
|
|
710
|
-
|
|
711
|
-
if (bkey && mid && Math.min(bkey.length, mid.length) >= 4) {
|
|
712
|
-
if (bkey.startsWith(mid) || mid.startsWith(bkey)) return true;
|
|
713
|
-
}
|
|
714
|
-
if (blabel && mname && Math.min(blabel.length, mname.length) >= 4) {
|
|
715
|
-
if (blabel.startsWith(mname) || mname.startsWith(blabel)) return true;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
return false;
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
export function pickWorstQuotaModel(models: GoogleQuotaModelSnapshot[]): GoogleQuotaModelSnapshot | undefined {
|
|
723
|
-
if (models.length === 0) return undefined;
|
|
724
|
-
let worst = models[0];
|
|
725
|
-
for (let i = 1; i < models.length; i++) {
|
|
726
|
-
const current = models[i];
|
|
727
|
-
const currentPercent = current.remainingPercent ?? 101;
|
|
728
|
-
const worstPercent = worst.remainingPercent ?? 101;
|
|
729
|
-
if (currentPercent < worstPercent) {
|
|
730
|
-
worst = current;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
return worst;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
export function classifyGoogleQuotaKind(snapshot: GoogleQuotaAccountSnapshot): {
|
|
737
|
-
kind: QuotaStatusKind;
|
|
738
|
-
score: number;
|
|
739
|
-
} {
|
|
740
|
-
const bottleneck = snapshot.worstRemainingPercent;
|
|
741
|
-
if (bottleneck === undefined) {
|
|
742
|
-
return { kind: "error", score: 0 };
|
|
743
|
-
}
|
|
744
|
-
if (bottleneck <= 5) return { kind: "blocked", score: bottleneck };
|
|
745
|
-
if (bottleneck <= 15) return { kind: "low", score: bottleneck };
|
|
746
|
-
if (bottleneck <= 30) return { kind: "watch", score: bottleneck };
|
|
747
|
-
return { kind: "ready", score: bottleneck };
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
export async function resolveGoogleQuotaAccess(
|
|
751
|
-
account: QuotaAccount,
|
|
752
|
-
auth: AuthStorageEntry,
|
|
753
|
-
authStorage: AuthStorage,
|
|
754
|
-
signal?: AbortSignal,
|
|
755
|
-
): Promise<{ accessToken: string; projectId?: string }> {
|
|
756
|
-
const projectId = getGoogleProjectId(account, auth);
|
|
757
|
-
const hasFreshAccess = typeof auth.access === "string"
|
|
758
|
-
&& auth.access.length > 0
|
|
759
|
-
&& (typeof auth.expires !== "number" || auth.expires > Date.now() + 60_000);
|
|
760
|
-
if (hasFreshAccess) {
|
|
761
|
-
return { accessToken: auth.access!, projectId };
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
const storage = adaptAuthStorage(authStorage);
|
|
765
|
-
const access = await (typeof storage.getOAuthAccess === "function"
|
|
766
|
-
? storage.getOAuthAccess(account.providerName, undefined, { signal })
|
|
767
|
-
: undefined);
|
|
768
|
-
if (!access) {
|
|
769
|
-
throw new Error("Unable to refresh Google OAuth credentials. Log in again.");
|
|
770
|
-
}
|
|
771
|
-
return {
|
|
772
|
-
accessToken: access.accessToken,
|
|
773
|
-
projectId: access.projectId || projectId,
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
export async function fetchGoogleGeminiQuotaSnapshot(
|
|
778
|
-
accessToken: string,
|
|
779
|
-
projectId: string | undefined,
|
|
780
|
-
signal?: AbortSignal,
|
|
781
|
-
): Promise<GoogleQuotaAccountSnapshot> {
|
|
782
|
-
const response = await fetch(GOOGLE_GEMINI_QUOTA_ENDPOINT, {
|
|
783
|
-
method: "POST",
|
|
784
|
-
headers: {
|
|
785
|
-
Authorization: `Bearer ${accessToken}`,
|
|
786
|
-
Accept: "application/json",
|
|
787
|
-
"Content-Type": "application/json",
|
|
788
|
-
...GOOGLE_GEMINI_HEADERS,
|
|
789
|
-
},
|
|
790
|
-
body: "{}",
|
|
791
|
-
signal,
|
|
792
|
-
});
|
|
793
|
-
if (!response.ok) {
|
|
794
|
-
throw new Error(await readResponseError(response));
|
|
795
|
-
}
|
|
796
|
-
return parseGoogleGeminiQuotaSnapshot(await response.json(), projectId);
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
export async function fetchGoogleAntigravityQuotaSnapshot(
|
|
800
|
-
accessToken: string,
|
|
801
|
-
projectId: string | undefined,
|
|
802
|
-
signal?: AbortSignal,
|
|
803
|
-
): Promise<GoogleQuotaAccountSnapshot> {
|
|
804
|
-
let lastError = "Google quota lookup failed";
|
|
805
|
-
|
|
806
|
-
for (const endpoint of GOOGLE_ANTIGRAVITY_QUOTA_ENDPOINTS) {
|
|
807
|
-
const response = await fetch(endpoint, {
|
|
808
|
-
method: "POST",
|
|
809
|
-
headers: {
|
|
810
|
-
Authorization: `Bearer ${accessToken}`,
|
|
811
|
-
Accept: "application/json",
|
|
812
|
-
"Content-Type": "application/json",
|
|
813
|
-
...GOOGLE_ANTIGRAVITY_HEADERS,
|
|
814
|
-
},
|
|
815
|
-
body: JSON.stringify(projectId ? { project: projectId } : {}),
|
|
816
|
-
signal,
|
|
817
|
-
});
|
|
818
|
-
if (response.ok) {
|
|
819
|
-
return parseGoogleAntigravityQuotaSnapshot(await response.json(), endpoint, projectId);
|
|
820
|
-
}
|
|
821
|
-
lastError = await readResponseError(response);
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
throw new Error(lastError);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
export function getGoogleQuotaBucketLabel(account: QuotaAccount, count: number): string {
|
|
828
|
-
if (account.baseProvider === "google-gemini-cli") {
|
|
829
|
-
return `${count} ${count === 1 ? "family" : "families"}`;
|
|
830
|
-
}
|
|
831
|
-
return `${count} ${count === 1 ? "model" : "models"}`;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
export function buildGoogleQuotaErrorDetails(
|
|
835
|
-
account: QuotaAccount,
|
|
836
|
-
message: string,
|
|
837
|
-
projectId?: string,
|
|
838
|
-
): string[] {
|
|
839
|
-
const details = [
|
|
840
|
-
`account: ${account.displayName}`,
|
|
841
|
-
`provider: ${account.providerName}`,
|
|
842
|
-
"status: error",
|
|
843
|
-
];
|
|
844
|
-
if (projectId) {
|
|
845
|
-
details.push(`project: ${projectId}`);
|
|
846
|
-
}
|
|
847
|
-
details.push(`details: ${message}`);
|
|
848
|
-
|
|
849
|
-
if (/401|unauthorized/i.test(message)) {
|
|
850
|
-
details.push("login: use /multi-auth login or /login to authenticate this account again");
|
|
851
|
-
return details;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
if (/403|permission/i.test(message)) {
|
|
855
|
-
if (account.baseProvider === "google-gemini-cli") {
|
|
856
|
-
details.push(
|
|
857
|
-
"hint: Google Cloud Code Assist rejected quota access for this account; try /multi-auth login again and verify this account still has Gemini quota access",
|
|
858
|
-
);
|
|
859
|
-
} else {
|
|
860
|
-
details.push(
|
|
861
|
-
"hint: Google rejected this Antigravity quota request; verify the saved project/account pairing is still valid and try /multi-auth login again",
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
return details;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
export function formatGoogleQuotaDetails(
|
|
870
|
-
account: QuotaAccount,
|
|
871
|
-
snapshot: GoogleQuotaAccountSnapshot,
|
|
872
|
-
kind: QuotaStatusKind,
|
|
873
|
-
currentModel?: { id: string; name: string },
|
|
874
|
-
): string[] {
|
|
875
|
-
const details = [
|
|
876
|
-
`account: ${account.displayName}`,
|
|
877
|
-
`provider: ${account.providerName}`,
|
|
878
|
-
`status: ${formatQuotaKind(kind)}`,
|
|
879
|
-
];
|
|
880
|
-
if (snapshot.projectId) {
|
|
881
|
-
details.push(`project: ${snapshot.projectId}`);
|
|
882
|
-
}
|
|
883
|
-
if (snapshot.worstRemainingPercent !== undefined) {
|
|
884
|
-
details.push(`bottleneck: ${formatRemainingPercent(snapshot.worstRemainingPercent)} left`);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
let currentModelLabels = new Set<string>();
|
|
888
|
-
if (currentModel) {
|
|
889
|
-
const matches = matchGoogleQuotaModels(account.baseProvider, currentModel, snapshot);
|
|
890
|
-
const worst = pickWorstQuotaModel(matches);
|
|
891
|
-
if (worst) {
|
|
892
|
-
details.push(
|
|
893
|
-
`current model (${worst.model}): ${formatRemainingPercent(worst.remainingPercent)} left, resets ${formatResetLong(worst.resetAt)}`,
|
|
894
|
-
);
|
|
895
|
-
currentModelLabels = new Set(matches.map((m) => m.model));
|
|
896
|
-
} else {
|
|
897
|
-
details.push(`current model (${currentModel.name}): not tracked by this provider`);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
for (const model of [...snapshot.models].sort((left, right) => {
|
|
902
|
-
const leftPercent = left.remainingPercent ?? 101;
|
|
903
|
-
const rightPercent = right.remainingPercent ?? 101;
|
|
904
|
-
return leftPercent - rightPercent || left.model.localeCompare(right.model);
|
|
905
|
-
})) {
|
|
906
|
-
const suffix = currentModelLabels.has(model.model) ? " ← current" : "";
|
|
907
|
-
details.push(
|
|
908
|
-
`${model.model}: ${formatRemainingPercent(model.remainingPercent)} left, resets ${formatResetLong(model.resetAt)}${suffix}`,
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
details.push(`endpoint: ${snapshot.endpoint}`);
|
|
912
|
-
return details;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
export async function checkGoogleQuotaAccount(
|
|
916
|
-
account: QuotaAccount,
|
|
917
|
-
fetchSnapshot: (
|
|
918
|
-
accessToken: string,
|
|
919
|
-
projectId: string | undefined,
|
|
920
|
-
signal?: AbortSignal,
|
|
921
|
-
) => Promise<GoogleQuotaAccountSnapshot>,
|
|
922
|
-
authStorage: AuthStorage,
|
|
923
|
-
signal?: AbortSignal,
|
|
924
|
-
): Promise<QuotaCheckResult> {
|
|
925
|
-
const auth = account.auth;
|
|
926
|
-
if (!auth || auth.type !== "oauth") {
|
|
927
|
-
return {
|
|
928
|
-
account,
|
|
929
|
-
kind: "missing-auth",
|
|
930
|
-
summary: "not logged in",
|
|
931
|
-
details: [
|
|
932
|
-
`account: ${account.displayName}`,
|
|
933
|
-
`provider: ${account.providerName}`,
|
|
934
|
-
"status: not logged in",
|
|
935
|
-
"login: use /multi-auth login or /login to authenticate this account",
|
|
936
|
-
],
|
|
937
|
-
score: 0,
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
if ((typeof auth.access !== "string" || auth.access.length === 0)
|
|
941
|
-
&& (typeof auth.refresh !== "string" || auth.refresh.length === 0)) {
|
|
942
|
-
return {
|
|
943
|
-
account,
|
|
944
|
-
kind: "missing-auth",
|
|
945
|
-
summary: "missing Google tokens",
|
|
946
|
-
details: [
|
|
947
|
-
`account: ${account.displayName}`,
|
|
948
|
-
`provider: ${account.providerName}`,
|
|
949
|
-
"status: not logged in",
|
|
950
|
-
"details: saved Google credentials are missing both access and refresh tokens",
|
|
951
|
-
"login: use /multi-auth login or /login to authenticate this account again",
|
|
952
|
-
],
|
|
953
|
-
score: 0,
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
let projectId: string | undefined;
|
|
959
|
-
|
|
960
|
-
try {
|
|
961
|
-
const credentials = await resolveGoogleQuotaAccess(account, auth, authStorage, signal);
|
|
962
|
-
projectId = credentials.projectId;
|
|
963
|
-
const snapshot = await fetchSnapshot(credentials.accessToken, credentials.projectId, signal);
|
|
964
|
-
if (snapshot.models.length === 0 || snapshot.worstRemainingPercent === undefined) {
|
|
965
|
-
return {
|
|
966
|
-
account,
|
|
967
|
-
kind: "error",
|
|
968
|
-
summary: "no model quota data returned",
|
|
969
|
-
details: [
|
|
970
|
-
`account: ${account.displayName}`,
|
|
971
|
-
`provider: ${account.providerName}`,
|
|
972
|
-
"status: error",
|
|
973
|
-
...(projectId ? [`project: ${projectId}`] : []),
|
|
974
|
-
"details: Google returned no usable model quota data",
|
|
975
|
-
`endpoint: ${snapshot.endpoint}`,
|
|
976
|
-
],
|
|
977
|
-
score: 0,
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
const classification = classifyGoogleQuotaKind(snapshot);
|
|
982
|
-
return {
|
|
983
|
-
account,
|
|
984
|
-
kind: classification.kind,
|
|
985
|
-
summary: `${getGoogleQuotaBucketLabel(account, snapshot.models.length)} | bottleneck ${formatRemainingPercent(snapshot.worstRemainingPercent)} | ${formatQuotaKind(classification.kind)}`,
|
|
986
|
-
details: formatGoogleQuotaDetails(account, snapshot, classification.kind),
|
|
987
|
-
score: classification.score,
|
|
988
|
-
googleSnapshot: snapshot,
|
|
989
|
-
};
|
|
990
|
-
} catch (error: unknown) {
|
|
991
|
-
if (signal?.aborted || isAbortError(error)) throw error;
|
|
992
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
993
|
-
return {
|
|
994
|
-
account,
|
|
995
|
-
kind: "error",
|
|
996
|
-
summary: message,
|
|
997
|
-
details: buildGoogleQuotaErrorDetails(account, message, projectId),
|
|
998
|
-
score: 0,
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
416
|
export function normalizeQuotaAllowedProviderNames(cwd: string): string[] | undefined {
|
|
1004
417
|
const project = loadProjectConfig(cwd);
|
|
1005
418
|
if (!project?.allowedSubs || project.allowedSubs.length === 0) return undefined;
|
|
@@ -1154,20 +567,6 @@ export const codexQuotaChecker: ProviderQuotaChecker = {
|
|
|
1154
567
|
},
|
|
1155
568
|
};
|
|
1156
569
|
|
|
1157
|
-
export const googleGeminiCliQuotaChecker: ProviderQuotaChecker = {
|
|
1158
|
-
baseProvider: "google-gemini-cli",
|
|
1159
|
-
async check(account: QuotaAccount, authStorage: AuthStorage, signal?: AbortSignal): Promise<QuotaCheckResult> {
|
|
1160
|
-
return checkGoogleQuotaAccount(account, fetchGoogleGeminiQuotaSnapshot, authStorage, signal);
|
|
1161
|
-
},
|
|
1162
|
-
};
|
|
1163
|
-
|
|
1164
|
-
export const googleAntigravityQuotaChecker: ProviderQuotaChecker = {
|
|
1165
|
-
baseProvider: "google-antigravity",
|
|
1166
|
-
async check(account: QuotaAccount, authStorage: AuthStorage, signal?: AbortSignal): Promise<QuotaCheckResult> {
|
|
1167
|
-
return checkGoogleQuotaAccount(account, fetchGoogleAntigravityQuotaSnapshot, authStorage, signal);
|
|
1168
|
-
},
|
|
1169
|
-
};
|
|
1170
|
-
|
|
1171
570
|
export const OPENCODE_GO_DEFAULT_BASE_URL = "https://opencode.ai/inference/go";
|
|
1172
571
|
// Background poll outside any conversation; the route requires some session id.
|
|
1173
572
|
const OPENCODE_GO_USAGE_SESSION = randomUUID();
|
|
@@ -1218,12 +617,11 @@ export function pickOpenCodeGoBottleneck(snapshot: OpenCodeGoUsageSnapshot): {
|
|
|
1218
617
|
export const opencodeGoQuotaChecker: ProviderQuotaChecker = {
|
|
1219
618
|
baseProvider: "opencode-go",
|
|
1220
619
|
async check(account: QuotaAccount, authStorage: AuthStorage, signal?: AbortSignal): Promise<QuotaCheckResult> {
|
|
1221
|
-
|
|
1222
|
-
//
|
|
1223
|
-
//
|
|
1224
|
-
const keys = authStorage.keys as { peek
|
|
1225
|
-
const key =
|
|
1226
|
-
?? (auth?.type === "api_key" && typeof auth.key === "string" ? auth.key : "");
|
|
620
|
+
// The host key cascade covers env/config/runtime/stored keys per provider name,
|
|
621
|
+
// so clones never inherit the canonical provider's env key.
|
|
622
|
+
// AuthStorage's index signature widens `keys` to `unknown`; omp >=19 always exposes `keys.peek`.
|
|
623
|
+
const keys = authStorage.keys as { peek(provider: string): Promise<string | undefined> };
|
|
624
|
+
const key = await keys.peek(account.providerName);
|
|
1227
625
|
const fail = (kind: QuotaStatusKind, summary: string, extra: string[]): QuotaCheckResult => ({
|
|
1228
626
|
account,
|
|
1229
627
|
kind,
|
|
@@ -1297,8 +695,6 @@ export const opencodeGoQuotaChecker: ProviderQuotaChecker = {
|
|
|
1297
695
|
|
|
1298
696
|
export const PROVIDER_QUOTA_CHECKERS: ProviderQuotaChecker[] = [
|
|
1299
697
|
codexQuotaChecker,
|
|
1300
|
-
googleGeminiCliQuotaChecker,
|
|
1301
|
-
googleAntigravityQuotaChecker,
|
|
1302
698
|
opencodeGoQuotaChecker,
|
|
1303
699
|
];
|
|
1304
700
|
|
|
@@ -1306,14 +702,10 @@ export async function showQuotaDetails(
|
|
|
1306
702
|
ctx: ExtensionCommandContext,
|
|
1307
703
|
result: QuotaCheckResult,
|
|
1308
704
|
): Promise<void> {
|
|
1309
|
-
const details = (result.googleSnapshot && result.account.providerName === ctx.model?.provider && ctx.model)
|
|
1310
|
-
? formatGoogleQuotaDetails(result.account, result.googleSnapshot, result.kind, ctx.model)
|
|
1311
|
-
: result.details;
|
|
1312
|
-
|
|
1313
705
|
await showWrappedSelect(ctx, {
|
|
1314
706
|
title: `Limit Details: ${result.account.displayName}`,
|
|
1315
707
|
subtitle: "Press Enter or Escape to go back to the limits list.",
|
|
1316
|
-
items: details.map((detail, index) => ({ value: `${index}:${detail}`, label: detail })),
|
|
708
|
+
items: result.details.map((detail, index) => ({ value: `${index}:${detail}`, label: detail })),
|
|
1317
709
|
confirmHint: "back",
|
|
1318
710
|
cancelHint: "back",
|
|
1319
711
|
});
|
|
@@ -1357,19 +749,12 @@ export const QUOTA_STATUS_KEY = "multi-auth-quota";
|
|
|
1357
749
|
|
|
1358
750
|
export function formatCurrentModelQuota(
|
|
1359
751
|
result: QuotaCheckResult,
|
|
1360
|
-
|
|
752
|
+
_model: { id: string; name: string; provider: string },
|
|
1361
753
|
): string | undefined {
|
|
1362
754
|
if (result.kind === "missing-auth" || result.kind === "error") {
|
|
1363
755
|
return undefined;
|
|
1364
756
|
}
|
|
1365
757
|
|
|
1366
|
-
if (result.googleSnapshot) {
|
|
1367
|
-
const matches = matchGoogleQuotaModels(result.account.baseProvider, model, result.googleSnapshot);
|
|
1368
|
-
const worst = pickWorstQuotaModel(matches);
|
|
1369
|
-
if (!worst) return undefined;
|
|
1370
|
-
return `${worst.model} ${formatRemainingPercent(worst.remainingPercent)} ${formatResetShort(worst.resetAt)}`;
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
758
|
if (result.codexSnapshot) {
|
|
1374
759
|
const s = result.codexSnapshot;
|
|
1375
760
|
const five = getCodexWindowRemaining(s.fiveHour);
|
package/extensions/multi-auth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
2
2
|
import { loadGlobalConfig, parseEnvConfig, mergeConfigs, normalizeEntries, loadEffectiveConfig, formatAllowedProviderSummary, getProjectScopedProviderNames, findSelectableModelForProvider, getProviderDisplayName } from "./lib/config.ts";
|
|
3
|
-
import { registerSub
|
|
3
|
+
import { registerSub } from "./lib/providers.ts";
|
|
4
4
|
import { handleSubsMenu, handleSubsList, handleSubsAdd, handleSubsRemove, handleSubsLogin, handleSubsLogout, handleSubsSwitch, handleSubsStatus } from "./lib/commands-subs.ts";
|
|
5
5
|
import { handleSubsLimits, refreshQuotaStatusLine, invalidateStatusQuota } from "./lib/quota.ts";
|
|
6
6
|
import { handlePresetActivate, handlePresetCreate, handlePresetList, handlePresetToggle, handlePresetRemove, handlePresetMenu } from "./lib/commands-preset.ts";
|
|
@@ -20,13 +20,6 @@ export default function multiSub(pi: ExtensionAPI) {
|
|
|
20
20
|
registerSub(pi, entry);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
// Break Cloud Code Assist's system-prompt fingerprint at the OMP payload seam (base provider).
|
|
24
|
-
pi.on("before_provider_request", (event, ctx) => {
|
|
25
|
-
if (ctx.model?.provider === "google-antigravity") {
|
|
26
|
-
return rewriteAntigravitySystemInstruction(event.payload);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
23
|
let projectRestrictionSwitchInFlight = false;
|
|
31
24
|
const enforceProjectRestriction = async (
|
|
32
25
|
ctx: ExtensionContext | ExtensionCommandContext,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-multi-auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Multi-account OAuth login for omp (Oh My Pi) -- add and manage multiple accounts per provider from one place.",
|
|
6
6
|
"keywords": [
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@oh-my-pi/pi-ai": "^
|
|
37
|
-
"@oh-my-pi/pi-catalog": "^
|
|
38
|
-
"@oh-my-pi/pi-coding-agent": "^
|
|
39
|
-
"@oh-my-pi/pi-tui": "^
|
|
36
|
+
"@oh-my-pi/pi-ai": "^19.3.0",
|
|
37
|
+
"@oh-my-pi/pi-catalog": "^19.3.0",
|
|
38
|
+
"@oh-my-pi/pi-coding-agent": "^19.3.0",
|
|
39
|
+
"@oh-my-pi/pi-tui": "^19.3.0"
|
|
40
40
|
},
|
|
41
41
|
"omp": {
|
|
42
42
|
"extensions": [
|