omp-multi-auth 1.4.1 → 1.4.3

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 CHANGED
@@ -40,6 +40,8 @@ omp install git:github.com/tuandinh0801/omp-multi-auth
40
40
  | `/multi-auth status` | Show account and authentication status |
41
41
  | `/multi-auth limits` | Check provider quota and usage |
42
42
 
43
+ On OMP 19's legacy extension bridge, account menus use OMP's built-in selection dialog and quota checks show a progress notification.
44
+
43
45
  ### `/multi-auth-preset`
44
46
 
45
47
  | Command | Description |
@@ -112,6 +114,8 @@ Run `/multi-auth limits` to inspect quota and usage information for supported pr
112
114
 
113
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.
114
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, on OMP versions with the usage registry. 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
+
115
119
  ## Configuration files
116
120
 
117
121
  | Scope | Path | Contents |
@@ -7,7 +7,7 @@ import { join } from "path";
7
7
  import { getAgentDir, type ExtensionAPI, type ProviderConfig, type ProviderModelConfig } from "@oh-my-pi/pi-coding-agent";
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
- import { AssistantMessageEventStream, streamSimple, type Api, type AssistantMessageEvent, type Context, type Model, type SimpleStreamOptions } from "@oh-my-pi/pi-ai";
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
11
  import { buildModel } from "@oh-my-pi/pi-catalog/build";
12
12
  import { fetchCodexModels } from "@oh-my-pi/pi-catalog/discovery/codex";
13
13
  import { CODEX_BASE_URL, getCodexAccountId } from "@oh-my-pi/pi-catalog/wire/codex";
@@ -470,11 +470,39 @@ export function cloneModels(originalProvider: string, index: number): ProviderMo
470
470
  // Register a single subscription as a provider
471
471
  // ==========================================================================
472
472
 
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
+ // Built-in usage fetchers only accept their own provider id, so a sub would get no
479
+ // usage report. Probe as the base provider and relabel the report as the sub. The
480
+ // host caches, invalidates and retains the relabeled report under the sub's id.
481
+ function subUsageProvider(baseProvider: string, name: string): UsageProvider | undefined {
482
+ const base = usageRegistry?.defaultUsageProvider(baseProvider);
483
+ if (!base) return undefined;
484
+ const asSub = (report: UsageReport | null): UsageReport | null =>
485
+ report && {
486
+ ...report,
487
+ provider: name,
488
+ limits: report.limits.map(limit => ({ ...limit, scope: { ...limit.scope, provider: name } })),
489
+ };
490
+ const { supports, parseRateLimitHeaders } = base;
491
+ return {
492
+ ...base,
493
+ id: name,
494
+ fetchUsage: async (params, ctx) => asSub(await base.fetchUsage({ ...params, provider: baseProvider }, ctx)),
495
+ supports: supports && (params => supports({ ...params, provider: baseProvider })),
496
+ parseRateLimitHeaders: parseRateLimitHeaders && ((...args) => asSub(parseRateLimitHeaders(...args))),
497
+ };
498
+ }
499
+
473
500
  function registerCodexSub(pi: ExtensionAPI, name: string, index: number, oauth: ProviderOAuth): void {
474
501
  pi.registerProvider(name, {
475
502
  baseUrl: CODEX_BASE_URL,
476
503
  api: "openai-codex-responses",
477
504
  oauth,
505
+ usage: subUsageProvider("openai-codex", name),
478
506
  async fetchDynamicModels(accessToken) {
479
507
  // OMP peeks at this provider's credential without refreshing it.
480
508
  if (!accessToken) {
@@ -551,6 +579,7 @@ export function registerSub(pi: ExtensionAPI, entry: SubEntry): void {
551
579
  api: transportApi ?? builtinModels[0]?.api,
552
580
  streamSimple,
553
581
  oauth: oauth && modifyModels ? { ...oauth, modifyModels } : oauth,
582
+ usage: subUsageProvider(entry.provider, name),
554
583
  models,
555
584
  });
556
585
  }
@@ -3,12 +3,12 @@
3
3
  // ========================================================================
4
4
  import { randomUUID } from "node:crypto";
5
5
  import type { ExtensionCommandContext, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
6
- import { BorderedLoader } from "@oh-my-pi/pi-coding-agent";
6
+ import * as agent from "@oh-my-pi/pi-coding-agent";
7
7
  import type { Api, Model } from "@oh-my-pi/pi-ai";
8
8
  import { getBaseProvider, subDisplayName, PROVIDER_TEMPLATES } from "./providers.ts";
9
9
  import { getAuthStorage, adaptAuthStorage, getModels, subProviderName, type AuthStorageEntry, type MultiAuthConfig, type QuotaAccount, type QuotaCheckResult, type QuotaStatusKind, type ProviderQuotaChecker, type AuthStorage } from "./core.ts";
10
10
  import { loadGlobalConfig, loadProjectConfig, parseEnvConfig, mergeConfigs, normalizeEntries } from "./config.ts";
11
- import { getWrappedSelectIndex, showWrappedSelect } from "./ui.ts";
11
+ import { showWrappedSelect } from "./ui.ts";
12
12
  import type { SelectItem } from "@oh-my-pi/pi-tui";
13
13
 
14
14
  export const DEFAULT_CODEX_USAGE_BASE_URL = "https://chatgpt.com/backend-api";
@@ -426,7 +426,10 @@ export async function loadQuotaResults(
426
426
  accounts: QuotaAccount[],
427
427
  authStorage: AuthStorage,
428
428
  ): Promise<QuotaCheckResult[] | null> {
429
- if (!ctx.hasUI) {
429
+ const { BorderedLoader } = agent;
430
+ const message = `Checking limits across ${accounts.length} ${accounts.length === 1 ? "account" : "accounts"}...`;
431
+ if (!ctx.hasUI || !BorderedLoader) {
432
+ if (ctx.hasUI) ctx.ui.notify(message, "info");
430
433
  return runQuotaChecks(accounts, authStorage);
431
434
  }
432
435
 
@@ -434,7 +437,7 @@ export async function loadQuotaResults(
434
437
  const loader = new BorderedLoader(
435
438
  tui,
436
439
  theme,
437
- `Checking limits across ${accounts.length} ${accounts.length === 1 ? "account" : "accounts"}...`,
440
+ message,
438
441
  );
439
442
  loader.onAbort = () => done(null);
440
443
 
@@ -1,7 +1,11 @@
1
1
  // Shared TUI select helpers.
2
2
  import type { ExtensionCommandContext } from "@oh-my-pi/pi-coding-agent";
3
- import { DynamicBorder, keyHint } from "@oh-my-pi/pi-coding-agent";
4
- import { Container, Key, SelectList, Text, matchesKey, type SelectItem } from "@oh-my-pi/pi-tui";
3
+ import * as agent from "@oh-my-pi/pi-coding-agent";
4
+ import * as tuiComponents from "@oh-my-pi/pi-tui";
5
+ import type { SelectItem } from "@oh-my-pi/pi-tui";
6
+
7
+ const { DynamicBorder, keyHint } = agent;
8
+ const { Container, Key, SelectList, Text, matchesKey } = tuiComponents;
5
9
 
6
10
  export function getWrappedSelectIndex(items: SelectItem[], value: string | undefined): number {
7
11
  if (!value) return 0;
@@ -22,7 +26,8 @@ export async function showWrappedSelect(
22
26
  ): Promise<string | undefined> {
23
27
  if (options.items.length === 0) return undefined;
24
28
 
25
- if (!ctx.hasUI) {
29
+ // OMP 19's legacy bridge provides native dialogs but omits the TUI components.
30
+ if (!ctx.hasUI || !DynamicBorder || !keyHint || !Container || !Key || !SelectList || !Text || !matchesKey) {
26
31
  const renderedItems = options.items.map((item) =>
27
32
  item.description ? `${item.label} — ${item.description}` : item.label,
28
33
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-multi-auth",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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": [