omp-multi-auth 1.3.1 → 1.4.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/README.md +18 -1
- package/extensions/lib/core.ts +4 -2
- package/extensions/lib/providers.ts +57 -9
- package/extensions/lib/quota.ts +157 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ Each added Codex account (e.g. `openai-codex-2`) discovers its own model catalog
|
|
|
99
99
|
| `zai` | Z.AI (GLM) |
|
|
100
100
|
| `minimax` | MiniMax (Global) |
|
|
101
101
|
| `minimax-cn` | MiniMax (China) |
|
|
102
|
+
| `opencode-go` | OpenCode Go |
|
|
102
103
|
| `cursor` | Cursor (dashboard API key `crsr_...` / `cursor_...` or browser sign-in) |
|
|
103
104
|
|
|
104
105
|
API-key providers support full multi-account operation. Add an account with `/multi-auth add`, select the provider, then authenticate via `/multi-auth login` (or `/login <name>`) and paste your API key when prompted. Each account stores its own key independently in OMP auth storage.
|
|
@@ -107,7 +108,9 @@ For `cursor`, `/multi-auth login` prompts for a dashboard API key (`crsr_...`/`c
|
|
|
107
108
|
|
|
108
109
|
## Built-in quotas
|
|
109
110
|
|
|
110
|
-
Run `/multi-auth limits` to inspect quota and usage information for supported providers. This currently includes built-in quota checks for Codex and
|
|
111
|
+
Run `/multi-auth limits` to inspect quota and usage information for supported providers. This currently includes built-in quota checks for Codex, Google, and OpenCode Go providers. Results depend on provider availability and authenticated account state.
|
|
112
|
+
|
|
113
|
+
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.
|
|
111
114
|
|
|
112
115
|
## Configuration files
|
|
113
116
|
|
|
@@ -116,6 +119,20 @@ Run `/multi-auth limits` to inspect quota and usage information for supported pr
|
|
|
116
119
|
| Global | `~/.omp/agent/multi-auth.json` | Subscriptions and presets |
|
|
117
120
|
| Project | `.omp/multi-auth.json` | `allowedSubs` allow-list |
|
|
118
121
|
|
|
122
|
+
### Proxy or gateway endpoints
|
|
123
|
+
|
|
124
|
+
An added account takes the `baseUrl` and `headers` that `~/.omp/agent/models.yml` sets for its base provider, so its requests go through the same gateway as the base account. omp-multi-auth reads `models.yaml` instead only when `models.yml` does not exist, as omp does; it never merges the two files, and `models.json` is not read. Each account still signs in with its own credential. Without a `baseUrl`, an account keeps the provider's built-in endpoints, so a provider with several API dialects (OpenCode Go) still uses the right URL for each model. A `baseUrl` replaces the endpoint for every model of that provider, and for GitHub Copilot accounts it replaces the endpoint derived from the sign-in token.
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
providers:
|
|
128
|
+
anthropic:
|
|
129
|
+
baseUrl: http://127.0.0.1:8080/anthropic
|
|
130
|
+
headers:
|
|
131
|
+
x-proxy-key: example
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
With this file, `anthropic-2` and `anthropic-3` send their requests to `http://127.0.0.1:8080/anthropic` with `x-proxy-key` too. Codex accounts (`openai-codex-N`) are not covered yet. omp reads the file when it starts, so restart omp after you change it.
|
|
135
|
+
|
|
119
136
|
## Credits
|
|
120
137
|
|
|
121
138
|
Originally based on [`pi-multi-pass`](https://github.com/hjanuschka/pi-multi-pass).
|
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 { GoogleQuotaAccountSnapshot, CodexUsageSnapshot } from "./quota.ts";
|
|
5
|
+
import type { GoogleQuotaAccountSnapshot, 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>[];
|
|
@@ -155,7 +155,8 @@ export function adaptAuthStorage(raw: unknown): MultiAuthStorage {
|
|
|
155
155
|
if (typeof prop === "string" && prop in adapter) {
|
|
156
156
|
return adapter[prop];
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
// Receiver stays `base`: host getters (e.g. `keys`) read private fields and throw on the proxy.
|
|
159
|
+
const value = Reflect.get(base, prop);
|
|
159
160
|
if (typeof value === "function") {
|
|
160
161
|
return value.bind(base);
|
|
161
162
|
}
|
|
@@ -183,6 +184,7 @@ export interface QuotaCheckResult {
|
|
|
183
184
|
score: number;
|
|
184
185
|
googleSnapshot?: GoogleQuotaAccountSnapshot;
|
|
185
186
|
codexSnapshot?: CodexUsageSnapshot;
|
|
187
|
+
opencodeGoSnapshot?: OpenCodeGoUsageSnapshot;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
export interface ProviderQuotaChecker {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// ========================================================================
|
|
2
2
|
// Provider templates
|
|
3
3
|
// ========================================================================
|
|
4
|
-
import
|
|
4
|
+
import { YAML } from "bun";
|
|
5
|
+
import { existsSync, readFileSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import { getAgentDir, type ExtensionAPI, type ProviderConfig, type ProviderModelConfig } from "@oh-my-pi/pi-coding-agent";
|
|
5
8
|
import { getProviderDefinition } from "@oh-my-pi/pi-ai/registry";
|
|
6
9
|
import type { OAuthCredentials, OAuthLoginCallbacks } from "@oh-my-pi/pi-ai/oauth";
|
|
7
10
|
import { AssistantMessageEventStream, streamSimple, type Api, type AssistantMessageEvent, type Context, type Model, type SimpleStreamOptions } from "@oh-my-pi/pi-ai";
|
|
@@ -191,6 +194,11 @@ export function getGitHubCopilotBaseUrl(token: string | undefined, enterpriseUrl
|
|
|
191
194
|
// transport and puts subscription identity back on emitted assistant messages.
|
|
192
195
|
export const SUB_TRANSPORT_CONFIG: Record<string, { builtinApi: Api | ((modelId: string) => Api); customApiId: string }> = {
|
|
193
196
|
"google-antigravity": { builtinApi: "google-gemini-cli", customApiId: "google-antigravity-mp" },
|
|
197
|
+
// pi-ai keys X-Api-Key (anthropic-messages) and x-opencode-session on provider === "opencode-go".
|
|
198
|
+
"opencode-go": {
|
|
199
|
+
builtinApi: (modelId) => getModels("opencode-go").find(m => m.id === modelId)?.api ?? "openai-completions",
|
|
200
|
+
customApiId: "opencode-go-mp",
|
|
201
|
+
},
|
|
194
202
|
};
|
|
195
203
|
|
|
196
204
|
|
|
@@ -244,12 +252,25 @@ export function restoreSubscriptionProvider(event: AssistantMessageEvent, provid
|
|
|
244
252
|
return { ...event, partial: { ...event.partial, provider } };
|
|
245
253
|
}
|
|
246
254
|
|
|
247
|
-
export function createSubscriptionStream(
|
|
255
|
+
export function createSubscriptionStream(
|
|
256
|
+
canonicalProvider: string,
|
|
257
|
+
builtinApi: Api | ((modelId: string) => Api),
|
|
258
|
+
baseUrl?: string,
|
|
259
|
+
): SubscriptionStream {
|
|
248
260
|
return (model, context, options) => {
|
|
249
261
|
const internalApi = typeof builtinApi === "function" ? builtinApi(model.id) : builtinApi;
|
|
250
262
|
const baseModel = getModels(canonicalProvider).find(candidate => candidate.id === model.id);
|
|
251
263
|
if (!baseModel) throw new Error(`Missing bundled model ${canonicalProvider}/${model.id}`);
|
|
252
|
-
|
|
264
|
+
// The host resolves model.resolveHeaders into model.headers before dispatching here, so the clone's
|
|
265
|
+
// headers must ride along. Without an explicit baseUrl keep the catalog's per-model URL (mixed dialects).
|
|
266
|
+
const internalModel = {
|
|
267
|
+
...baseModel,
|
|
268
|
+
api: internalApi,
|
|
269
|
+
provider: canonicalProvider,
|
|
270
|
+
baseUrl: baseUrl ?? baseModel.baseUrl,
|
|
271
|
+
headers: model.headers ?? baseModel.headers,
|
|
272
|
+
resolveHeaders: model.resolveHeaders,
|
|
273
|
+
} as Model<Api>;
|
|
253
274
|
const internalOptions: SimpleStreamOptions = {
|
|
254
275
|
...(options ?? {}),
|
|
255
276
|
headers: options?.headers,
|
|
@@ -281,9 +302,10 @@ export function createSubscriptionStream(canonicalProvider: string, builtinApi:
|
|
|
281
302
|
};
|
|
282
303
|
}
|
|
283
304
|
export const SUBSCRIPTION_STREAMS: Record<string, SubscriptionStream> = {};
|
|
284
|
-
export function getSubscriptionStream(baseProvider: string): SubscriptionStream | undefined {
|
|
305
|
+
export function getSubscriptionStream(baseProvider: string, baseUrl?: string): SubscriptionStream | undefined {
|
|
285
306
|
const config = SUB_TRANSPORT_CONFIG[baseProvider];
|
|
286
307
|
if (!config) return undefined;
|
|
308
|
+
if (baseUrl) return createSubscriptionStream(baseProvider, config.builtinApi, baseUrl);
|
|
287
309
|
let stream = SUBSCRIPTION_STREAMS[baseProvider];
|
|
288
310
|
if (!stream) {
|
|
289
311
|
stream = createSubscriptionStream(baseProvider, config.builtinApi);
|
|
@@ -306,8 +328,9 @@ interface ApiKeyProviderSpec {
|
|
|
306
328
|
placeholder: string; // key-format hint shown in the login prompt
|
|
307
329
|
}
|
|
308
330
|
|
|
309
|
-
// Direct-API-key providers with a static baseUrl
|
|
310
|
-
//
|
|
331
|
+
// Direct-API-key providers with a static baseUrl in the bundled catalog. A row
|
|
332
|
+
// is enough for plain bearer auth; providers whose pi-ai auth/headers are keyed
|
|
333
|
+
// on the provider name also need a SUB_TRANSPORT_CONFIG entry.
|
|
311
334
|
export const API_KEY_PROVIDERS: ApiKeyProviderSpec[] = [
|
|
312
335
|
{ id: "openai", displayName: "OpenAI (API key)", placeholder: "sk-..." },
|
|
313
336
|
{ id: "deepseek", displayName: "DeepSeek", placeholder: "sk-..." },
|
|
@@ -323,6 +346,7 @@ export const API_KEY_PROVIDERS: ApiKeyProviderSpec[] = [
|
|
|
323
346
|
{ id: "zai", displayName: "Z.AI (GLM)", placeholder: "..." },
|
|
324
347
|
{ id: "minimax", displayName: "MiniMax (Global)", placeholder: "..." },
|
|
325
348
|
{ id: "minimax-cn", displayName: "MiniMax (China)", placeholder: "..." },
|
|
349
|
+
{ id: "opencode-go", displayName: "OpenCode Go", placeholder: "oc_sk_..." },
|
|
326
350
|
];
|
|
327
351
|
|
|
328
352
|
export const PROVIDER_TEMPLATES: Record<string, ProviderTemplate> = {
|
|
@@ -480,6 +504,27 @@ function registerCodexSub(pi: ExtensionAPI, name: string, index: number, oauth:
|
|
|
480
504
|
});
|
|
481
505
|
}
|
|
482
506
|
|
|
507
|
+
// An account takes the endpoint its base provider is configured with in
|
|
508
|
+
// models.yml (a gateway or proxy baseUrl and its headers), because
|
|
509
|
+
// models.yml overrides are keyed by provider id and never reach the
|
|
510
|
+
// `<provider>-N` ids registered here. Credentials stay the account's own.
|
|
511
|
+
function baseProviderTransport(provider: string): { baseUrl?: string; headers?: Record<string, string> } {
|
|
512
|
+
let parsed: { providers?: Record<string, { baseUrl?: unknown; headers?: unknown }> } | null;
|
|
513
|
+
// Same lookup as the host: models.yaml is read only when models.yml is absent.
|
|
514
|
+
const yml = join(getAgentDir(), "models.yml");
|
|
515
|
+
try {
|
|
516
|
+
parsed = YAML.parse(readFileSync(existsSync(yml) ? yml : join(getAgentDir(), "models.yaml"), "utf8")) as typeof parsed;
|
|
517
|
+
} catch {
|
|
518
|
+
return {};
|
|
519
|
+
}
|
|
520
|
+
const override = parsed?.providers?.[provider];
|
|
521
|
+
const headers = override?.headers;
|
|
522
|
+
return {
|
|
523
|
+
baseUrl: typeof override?.baseUrl === "string" ? override.baseUrl : undefined,
|
|
524
|
+
headers: headers && typeof headers === "object" ? { ...(headers as Record<string, string>) } : undefined,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
483
528
|
export function registerSub(pi: ExtensionAPI, entry: SubEntry): void {
|
|
484
529
|
const template = PROVIDER_TEMPLATES[entry.provider];
|
|
485
530
|
if (!template) return;
|
|
@@ -489,17 +534,20 @@ export function registerSub(pi: ExtensionAPI, entry: SubEntry): void {
|
|
|
489
534
|
registerCodexSub(pi, name, entry.index, oauth);
|
|
490
535
|
return;
|
|
491
536
|
}
|
|
492
|
-
const
|
|
537
|
+
const transport = baseProviderTransport(entry.provider);
|
|
538
|
+
// An explicit baseUrl wins over the token-derived Copilot endpoint.
|
|
539
|
+
const modifyModels = transport.baseUrl ? undefined : template.buildModifyModels?.(name);
|
|
493
540
|
|
|
494
541
|
const builtinModels = getModels(entry.provider);
|
|
495
542
|
const transportApi = SUB_TRANSPORT_CONFIG[entry.provider]?.customApiId;
|
|
496
|
-
const streamSimple = getSubscriptionStream(entry.provider);
|
|
497
|
-
const baseUrl = builtinModels[0]?.baseUrl || "";
|
|
543
|
+
const streamSimple = getSubscriptionStream(entry.provider, transport.baseUrl);
|
|
544
|
+
const baseUrl = transport.baseUrl ?? (builtinModels[0]?.baseUrl || "");
|
|
498
545
|
const models = cloneModels(entry.provider, entry.index);
|
|
499
546
|
|
|
500
547
|
// Static `models` provide startup catalog for this subscription.
|
|
501
548
|
pi.registerProvider(name, {
|
|
502
549
|
baseUrl,
|
|
550
|
+
headers: transport.headers,
|
|
503
551
|
api: transportApi ?? builtinModels[0]?.api,
|
|
504
552
|
streamSimple,
|
|
505
553
|
oauth: oauth && modifyModels ? { ...oauth, modifyModels } : oauth,
|
package/extensions/lib/quota.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// ========================================================================
|
|
2
2
|
// Built-in quota checking
|
|
3
3
|
// ========================================================================
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
4
5
|
import type { ExtensionCommandContext, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
5
6
|
import { BorderedLoader } from "@oh-my-pi/pi-coding-agent";
|
|
6
7
|
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
@@ -46,6 +47,18 @@ export interface CodexUsageSnapshot {
|
|
|
46
47
|
weekly?: CodexUsageWindow;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
export interface OpenCodeGoUsageWindow {
|
|
51
|
+
usedPercent: number;
|
|
52
|
+
resetAt: number; // epoch seconds
|
|
53
|
+
rateLimited: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface OpenCodeGoUsageSnapshot {
|
|
57
|
+
rolling: OpenCodeGoUsageWindow;
|
|
58
|
+
weekly: OpenCodeGoUsageWindow;
|
|
59
|
+
monthly: OpenCodeGoUsageWindow;
|
|
60
|
+
}
|
|
61
|
+
|
|
49
62
|
export interface GoogleGeminiQuotaResponse {
|
|
50
63
|
buckets?: Array<{
|
|
51
64
|
modelId?: string;
|
|
@@ -215,13 +228,10 @@ export async function readResponseError(response: Response): Promise<string> {
|
|
|
215
228
|
return `HTTP ${response.status}: ${raw}`;
|
|
216
229
|
}
|
|
217
230
|
|
|
218
|
-
export function
|
|
231
|
+
export function classifyRemainingBottleneck(values: number[]): {
|
|
219
232
|
kind: QuotaStatusKind;
|
|
220
233
|
score: number;
|
|
221
234
|
} {
|
|
222
|
-
const fiveHourLeft = getCodexWindowRemaining(snapshot.fiveHour);
|
|
223
|
-
const weeklyLeft = getCodexWindowRemaining(snapshot.weekly);
|
|
224
|
-
const values = [fiveHourLeft, weeklyLeft].filter((value): value is number => value !== undefined);
|
|
225
235
|
if (values.length === 0) {
|
|
226
236
|
return { kind: "error", score: 0 };
|
|
227
237
|
}
|
|
@@ -232,6 +242,16 @@ export function classifyCodexQuotaKind(snapshot: CodexUsageSnapshot): {
|
|
|
232
242
|
return { kind: "ready", score: bottleneck };
|
|
233
243
|
}
|
|
234
244
|
|
|
245
|
+
export function classifyCodexQuotaKind(snapshot: CodexUsageSnapshot): {
|
|
246
|
+
kind: QuotaStatusKind;
|
|
247
|
+
score: number;
|
|
248
|
+
} {
|
|
249
|
+
return classifyRemainingBottleneck(
|
|
250
|
+
[getCodexWindowRemaining(snapshot.fiveHour), getCodexWindowRemaining(snapshot.weekly)]
|
|
251
|
+
.filter((value): value is number => value !== undefined),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
235
255
|
export function formatQuotaKind(kind: QuotaStatusKind): string {
|
|
236
256
|
switch (kind) {
|
|
237
257
|
case "ready":
|
|
@@ -1145,10 +1165,138 @@ export const googleAntigravityQuotaChecker: ProviderQuotaChecker = {
|
|
|
1145
1165
|
},
|
|
1146
1166
|
};
|
|
1147
1167
|
|
|
1168
|
+
export const OPENCODE_GO_DEFAULT_BASE_URL = "https://opencode.ai/inference/go";
|
|
1169
|
+
// Background poll outside any conversation; the route requires some session id.
|
|
1170
|
+
const OPENCODE_GO_USAGE_SESSION = randomUUID();
|
|
1171
|
+
|
|
1172
|
+
export function opencodeGoUsageUrl(): string {
|
|
1173
|
+
const base = getModels("opencode-go").find((m) => m.baseUrl)?.baseUrl ?? OPENCODE_GO_DEFAULT_BASE_URL;
|
|
1174
|
+
return `${base.trim().replace(/\/+$/, "").replace(/\/v1$/i, "")}/v1/usage`;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
function normalizeOpenCodeGoWindow(raw: unknown): OpenCodeGoUsageWindow | undefined {
|
|
1178
|
+
const w = getRecord(raw);
|
|
1179
|
+
if (!w) return undefined;
|
|
1180
|
+
const { percent, status, resetsAt } = w;
|
|
1181
|
+
if (typeof percent !== "number" || !Number.isFinite(percent) || percent < 0 || percent > 100) return undefined;
|
|
1182
|
+
if (status !== "ok" && status !== "rate-limited") return undefined;
|
|
1183
|
+
const resetAt = typeof resetsAt === "string" ? parseIsoTimestampSeconds(resetsAt) : undefined;
|
|
1184
|
+
if (resetAt === undefined) return undefined;
|
|
1185
|
+
return { usedPercent: percent, resetAt, rateLimited: status === "rate-limited" };
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/** All-or-nothing: the route's shape is undocumented, so a partial decode is treated as unusable. */
|
|
1189
|
+
export function parseOpenCodeGoUsageSnapshot(data: unknown): OpenCodeGoUsageSnapshot | undefined {
|
|
1190
|
+
const usage = getRecord(getRecord(data)?.usage);
|
|
1191
|
+
const rolling = normalizeOpenCodeGoWindow(usage?.rolling);
|
|
1192
|
+
const weekly = normalizeOpenCodeGoWindow(usage?.weekly);
|
|
1193
|
+
const monthly = normalizeOpenCodeGoWindow(usage?.monthly);
|
|
1194
|
+
return rolling && weekly && monthly ? { rolling, weekly, monthly } : undefined;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function getOpenCodeGoRemaining(window: OpenCodeGoUsageWindow): number {
|
|
1198
|
+
return window.rateLimited ? 0 : Math.max(0, Math.min(100, 100 - window.usedPercent));
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/** Rolling and weekly decide status. Monthly is display-only: an exhausted month can still
|
|
1202
|
+
* serve requests when the account's "Use balance" fallback is on, and the route does not report that. */
|
|
1203
|
+
export function pickOpenCodeGoBottleneck(snapshot: OpenCodeGoUsageSnapshot): {
|
|
1204
|
+
shortLabel: string;
|
|
1205
|
+
window: OpenCodeGoUsageWindow;
|
|
1206
|
+
remaining: number;
|
|
1207
|
+
} {
|
|
1208
|
+
const rolling = getOpenCodeGoRemaining(snapshot.rolling);
|
|
1209
|
+
const weekly = getOpenCodeGoRemaining(snapshot.weekly);
|
|
1210
|
+
return rolling <= weekly
|
|
1211
|
+
? { shortLabel: "5h", window: snapshot.rolling, remaining: rolling }
|
|
1212
|
+
: { shortLabel: "7d", window: snapshot.weekly, remaining: weekly };
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
export const opencodeGoQuotaChecker: ProviderQuotaChecker = {
|
|
1216
|
+
baseProvider: "opencode-go",
|
|
1217
|
+
async check(account: QuotaAccount, authStorage: AuthStorage, signal?: AbortSignal): Promise<QuotaCheckResult> {
|
|
1218
|
+
const auth = account.auth;
|
|
1219
|
+
// The host key cascade also covers env/config/runtime keys and is looked up per provider name,
|
|
1220
|
+
// so clones never inherit the canonical provider's env key. Older hosts lack it: use the stored key.
|
|
1221
|
+
const keys = authStorage.keys as { peek?: (provider: string) => Promise<string | undefined> } | undefined;
|
|
1222
|
+
const key = (await keys?.peek?.(account.providerName))
|
|
1223
|
+
?? (auth?.type === "api_key" && typeof auth.key === "string" ? auth.key : "");
|
|
1224
|
+
const fail = (kind: QuotaStatusKind, summary: string, extra: string[]): QuotaCheckResult => ({
|
|
1225
|
+
account,
|
|
1226
|
+
kind,
|
|
1227
|
+
summary,
|
|
1228
|
+
details: [`account: ${account.displayName}`, `provider: ${account.providerName}`, ...extra],
|
|
1229
|
+
score: 0,
|
|
1230
|
+
});
|
|
1231
|
+
if (!key) {
|
|
1232
|
+
return fail("missing-auth", "not logged in", [
|
|
1233
|
+
"status: not logged in",
|
|
1234
|
+
"login: use /multi-auth login or /login to authenticate this account",
|
|
1235
|
+
]);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const url = opencodeGoUsageUrl();
|
|
1239
|
+
try {
|
|
1240
|
+
const response = await fetch(url, {
|
|
1241
|
+
method: "GET",
|
|
1242
|
+
headers: {
|
|
1243
|
+
Accept: "application/json",
|
|
1244
|
+
Authorization: `Bearer ${key}`,
|
|
1245
|
+
"User-Agent": "omp-multi-auth",
|
|
1246
|
+
"x-opencode-session": OPENCODE_GO_USAGE_SESSION,
|
|
1247
|
+
},
|
|
1248
|
+
signal,
|
|
1249
|
+
});
|
|
1250
|
+
if (!response.ok) {
|
|
1251
|
+
const error = await readResponseError(response);
|
|
1252
|
+
return fail("error", error, ["status: error", `details: ${error}`]);
|
|
1253
|
+
}
|
|
1254
|
+
const snapshot = parseOpenCodeGoUsageSnapshot(await response.json());
|
|
1255
|
+
if (!snapshot) {
|
|
1256
|
+
const error = "unexpected usage response";
|
|
1257
|
+
return fail("error", error, ["status: error", `details: ${error}`]);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
const worst = pickOpenCodeGoBottleneck(snapshot);
|
|
1261
|
+
const { kind, score } = classifyRemainingBottleneck([worst.remaining]);
|
|
1262
|
+
const rollingLeft = getOpenCodeGoRemaining(snapshot.rolling);
|
|
1263
|
+
const weeklyLeft = getOpenCodeGoRemaining(snapshot.weekly);
|
|
1264
|
+
const monthlyLeft = getOpenCodeGoRemaining(snapshot.monthly);
|
|
1265
|
+
const summary = [
|
|
1266
|
+
`5h ${formatRemainingPercent(rollingLeft)} (${formatResetShort(snapshot.rolling.resetAt)})`,
|
|
1267
|
+
`7d ${formatRemainingPercent(weeklyLeft)} (${formatResetShort(snapshot.weekly.resetAt)})`,
|
|
1268
|
+
`month ${formatRemainingPercent(monthlyLeft)} (${formatResetShort(snapshot.monthly.resetAt)})`,
|
|
1269
|
+
formatQuotaKind(kind),
|
|
1270
|
+
].join(" | ");
|
|
1271
|
+
return {
|
|
1272
|
+
account,
|
|
1273
|
+
kind,
|
|
1274
|
+
summary,
|
|
1275
|
+
details: [
|
|
1276
|
+
`account: ${account.displayName}`,
|
|
1277
|
+
`provider: ${account.providerName}`,
|
|
1278
|
+
`status: ${formatQuotaKind(kind)}`,
|
|
1279
|
+
`5-hour window: ${formatRemainingPercent(rollingLeft)} left, resets ${formatResetLong(snapshot.rolling.resetAt)}`,
|
|
1280
|
+
`7-day window: ${formatRemainingPercent(weeklyLeft)} left, resets ${formatResetLong(snapshot.weekly.resetAt)}`,
|
|
1281
|
+
`monthly window: ${formatRemainingPercent(monthlyLeft)} left, resets ${formatResetLong(snapshot.monthly.resetAt)} (display only, not part of status)`,
|
|
1282
|
+
`endpoint: ${url}`,
|
|
1283
|
+
],
|
|
1284
|
+
score,
|
|
1285
|
+
opencodeGoSnapshot: snapshot,
|
|
1286
|
+
};
|
|
1287
|
+
} catch (error: unknown) {
|
|
1288
|
+
if (signal?.aborted || isAbortError(error)) throw error;
|
|
1289
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1290
|
+
return fail("error", message, ["status: error", `details: ${message}`]);
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1148
1295
|
export const PROVIDER_QUOTA_CHECKERS: ProviderQuotaChecker[] = [
|
|
1149
1296
|
codexQuotaChecker,
|
|
1150
1297
|
googleGeminiCliQuotaChecker,
|
|
1151
1298
|
googleAntigravityQuotaChecker,
|
|
1299
|
+
opencodeGoQuotaChecker,
|
|
1152
1300
|
];
|
|
1153
1301
|
|
|
1154
1302
|
export async function showQuotaDetails(
|
|
@@ -1251,6 +1399,11 @@ export function formatCurrentModelQuota(
|
|
|
1251
1399
|
return `${windowLabel} ${formatRemainingPercent(remaining)} ${formatResetShort(resetAt)}`;
|
|
1252
1400
|
}
|
|
1253
1401
|
|
|
1402
|
+
if (result.opencodeGoSnapshot) {
|
|
1403
|
+
const worst = pickOpenCodeGoBottleneck(result.opencodeGoSnapshot);
|
|
1404
|
+
return `${worst.shortLabel} ${formatRemainingPercent(worst.remaining)} ${formatResetShort(worst.window.resetAt)}`;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1254
1407
|
return undefined;
|
|
1255
1408
|
}
|
|
1256
1409
|
|
package/package.json
CHANGED