omp-multi-auth 1.3.1 → 1.4.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 -1
- package/extensions/lib/core.ts +4 -2
- package/extensions/lib/providers.ts +9 -2
- 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
|
|
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 {
|
|
@@ -191,6 +191,11 @@ export function getGitHubCopilotBaseUrl(token: string | undefined, enterpriseUrl
|
|
|
191
191
|
// transport and puts subscription identity back on emitted assistant messages.
|
|
192
192
|
export const SUB_TRANSPORT_CONFIG: Record<string, { builtinApi: Api | ((modelId: string) => Api); customApiId: string }> = {
|
|
193
193
|
"google-antigravity": { builtinApi: "google-gemini-cli", customApiId: "google-antigravity-mp" },
|
|
194
|
+
// pi-ai keys X-Api-Key (anthropic-messages) and x-opencode-session on provider === "opencode-go".
|
|
195
|
+
"opencode-go": {
|
|
196
|
+
builtinApi: (modelId) => getModels("opencode-go").find(m => m.id === modelId)?.api ?? "openai-completions",
|
|
197
|
+
customApiId: "opencode-go-mp",
|
|
198
|
+
},
|
|
194
199
|
};
|
|
195
200
|
|
|
196
201
|
|
|
@@ -306,8 +311,9 @@ interface ApiKeyProviderSpec {
|
|
|
306
311
|
placeholder: string; // key-format hint shown in the login prompt
|
|
307
312
|
}
|
|
308
313
|
|
|
309
|
-
// Direct-API-key providers with a static baseUrl
|
|
310
|
-
//
|
|
314
|
+
// Direct-API-key providers with a static baseUrl in the bundled catalog. A row
|
|
315
|
+
// is enough for plain bearer auth; providers whose pi-ai auth/headers are keyed
|
|
316
|
+
// on the provider name also need a SUB_TRANSPORT_CONFIG entry.
|
|
311
317
|
export const API_KEY_PROVIDERS: ApiKeyProviderSpec[] = [
|
|
312
318
|
{ id: "openai", displayName: "OpenAI (API key)", placeholder: "sk-..." },
|
|
313
319
|
{ id: "deepseek", displayName: "DeepSeek", placeholder: "sk-..." },
|
|
@@ -323,6 +329,7 @@ export const API_KEY_PROVIDERS: ApiKeyProviderSpec[] = [
|
|
|
323
329
|
{ id: "zai", displayName: "Z.AI (GLM)", placeholder: "..." },
|
|
324
330
|
{ id: "minimax", displayName: "MiniMax (Global)", placeholder: "..." },
|
|
325
331
|
{ id: "minimax-cn", displayName: "MiniMax (China)", placeholder: "..." },
|
|
332
|
+
{ id: "opencode-go", displayName: "OpenCode Go", placeholder: "oc_sk_..." },
|
|
326
333
|
];
|
|
327
334
|
|
|
328
335
|
export const PROVIDER_TEMPLATES: Record<string, ProviderTemplate> = {
|
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