omp-multi-auth 1.4.1 → 1.4.2
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 +2 -0
- package/extensions/lib/providers.ts +30 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,6 +112,8 @@ Run `/multi-auth limits` to inspect quota and usage information for supported pr
|
|
|
112
112
|
|
|
113
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.
|
|
114
114
|
|
|
115
|
+
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.
|
|
116
|
+
|
|
115
117
|
## Configuration files
|
|
116
118
|
|
|
117
119
|
| 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
|
}
|
package/package.json
CHANGED