codex-multi-auth 2.16.0 → 2.17.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/.codex-plugin/plugin.json +9 -9
- package/LICENSE +21 -21
- package/README.md +487 -463
- package/assets/codex-multi-auth-icon.svg +39 -39
- package/assets/readme-hero.svg +31 -31
- package/config/README.md +31 -31
- package/config/codex-legacy.json +1221 -1221
- package/config/codex-modern.json +423 -423
- package/config/minimal-codex.json +15 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/lib/account-policy.d.ts +4 -0
- package/dist/lib/account-policy.d.ts.map +1 -1
- package/dist/lib/account-policy.js +8 -0
- package/dist/lib/accounts/rate-limits.d.ts.map +1 -1
- package/dist/lib/accounts/rate-limits.js +2 -0
- package/dist/lib/accounts.d.ts +15 -3
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +231 -30
- package/dist/lib/api-route-store.d.ts +24 -0
- package/dist/lib/api-route-store.d.ts.map +1 -0
- package/dist/lib/api-route-store.js +145 -0
- package/dist/lib/auth/account-access.d.ts +115 -0
- package/dist/lib/auth/account-access.d.ts.map +1 -0
- package/dist/lib/auth/account-access.js +214 -0
- package/dist/lib/auth/token-utils.d.ts +54 -1
- package/dist/lib/auth/token-utils.d.ts.map +1 -1
- package/dist/lib/auth/token-utils.js +92 -7
- package/dist/lib/cli.d.ts +1 -1
- package/dist/lib/cli.d.ts.map +1 -1
- package/dist/lib/cli.js +4 -0
- package/dist/lib/codex-cli/state.d.ts +7 -0
- package/dist/lib/codex-cli/state.d.ts.map +1 -1
- package/dist/lib/codex-cli/state.js +18 -0
- package/dist/lib/codex-cli/writer.d.ts.map +1 -1
- package/dist/lib/codex-cli/writer.js +60 -8
- package/dist/lib/codex-manager/account-manager-commands.d.ts.map +1 -1
- package/dist/lib/codex-manager/account-manager-commands.js +1 -0
- package/dist/lib/codex-manager/account-pool-write.d.ts +3 -1
- package/dist/lib/codex-manager/account-pool-write.d.ts.map +1 -1
- package/dist/lib/codex-manager/account-pool-write.js +4 -0
- package/dist/lib/codex-manager/api-login-menu.d.ts +14 -0
- package/dist/lib/codex-manager/api-login-menu.d.ts.map +1 -0
- package/dist/lib/codex-manager/api-login-menu.js +224 -0
- package/dist/lib/codex-manager/commands/account.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/account.js +27 -0
- package/dist/lib/codex-manager/commands/best.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/best.js +6 -2
- package/dist/lib/codex-manager/commands/check.d.ts +7 -1
- package/dist/lib/codex-manager/commands/check.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/check.js +24 -3
- package/dist/lib/codex-manager/commands/forecast.d.ts +1 -1
- package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/forecast.js +7 -3
- package/dist/lib/codex-manager/commands/report.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/report.js +5 -1
- package/dist/lib/codex-manager/commands/resets.d.ts +2 -0
- package/dist/lib/codex-manager/commands/resets.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/resets.js +67 -0
- package/dist/lib/codex-manager/commands/rotation.d.ts +2 -2
- package/dist/lib/codex-manager/commands/rotation.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/rotation.js +63 -12
- package/dist/lib/codex-manager/commands/status.d.ts +12 -1
- package/dist/lib/codex-manager/commands/status.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/status.js +166 -22
- package/dist/lib/codex-manager/commands/uninstall.js +1 -1
- package/dist/lib/codex-manager/formatters/quota-formatters.d.ts.map +1 -1
- package/dist/lib/codex-manager/formatters/quota-formatters.js +3 -2
- package/dist/lib/codex-manager/health-check.d.ts +3 -0
- package/dist/lib/codex-manager/health-check.d.ts.map +1 -1
- package/dist/lib/codex-manager/health-check.js +57 -7
- package/dist/lib/codex-manager/help.d.ts.map +1 -1
- package/dist/lib/codex-manager/help.js +4 -2
- package/dist/lib/codex-manager/login-flow.d.ts.map +1 -1
- package/dist/lib/codex-manager/login-flow.js +69 -7
- package/dist/lib/codex-manager/login-menu-data.d.ts.map +1 -1
- package/dist/lib/codex-manager/login-menu-data.js +21 -8
- package/dist/lib/codex-manager/login-oauth.d.ts +3 -0
- package/dist/lib/codex-manager/login-oauth.d.ts.map +1 -1
- package/dist/lib/codex-manager/login-oauth.js +6 -1
- package/dist/lib/codex-manager/login-workspace-choice.d.ts +11 -0
- package/dist/lib/codex-manager/login-workspace-choice.d.ts.map +1 -0
- package/dist/lib/codex-manager/login-workspace-choice.js +37 -0
- package/dist/lib/codex-manager/persist-selected-account.d.ts.map +1 -1
- package/dist/lib/codex-manager/persist-selected-account.js +2 -1
- package/dist/lib/codex-manager/quota-cache-helpers.d.ts +7 -1
- package/dist/lib/codex-manager/quota-cache-helpers.d.ts.map +1 -1
- package/dist/lib/codex-manager/quota-cache-helpers.js +34 -19
- package/dist/lib/codex-manager/repair-commands.d.ts +13 -0
- package/dist/lib/codex-manager/repair-commands.d.ts.map +1 -1
- package/dist/lib/codex-manager/repair-commands.js +144 -9
- package/dist/lib/codex-manager.d.ts.map +1 -1
- package/dist/lib/codex-manager.js +25 -6
- package/dist/lib/concurrency.d.ts +3 -0
- package/dist/lib/concurrency.d.ts.map +1 -0
- package/dist/lib/concurrency.js +31 -0
- package/dist/lib/context-budget-response.js +8 -8
- package/dist/lib/context-overflow.js +10 -10
- package/dist/lib/model-route-policy.d.ts +52 -0
- package/dist/lib/model-route-policy.d.ts.map +1 -0
- package/dist/lib/model-route-policy.js +159 -0
- package/dist/lib/oauth-success.html +125 -125
- package/dist/lib/policy/runtime-policy.d.ts +1 -0
- package/dist/lib/policy/runtime-policy.d.ts.map +1 -1
- package/dist/lib/policy/runtime-policy.js +3 -0
- package/dist/lib/preemptive-quota-scheduler.d.ts +2 -0
- package/dist/lib/preemptive-quota-scheduler.d.ts.map +1 -1
- package/dist/lib/preemptive-quota-scheduler.js +4 -0
- package/dist/lib/prompts/codex-host-bridge.js +138 -138
- package/dist/lib/prompts/codex.js +79 -79
- package/dist/lib/quota-cache.d.ts +7 -3
- package/dist/lib/quota-cache.d.ts.map +1 -1
- package/dist/lib/quota-cache.js +91 -59
- package/dist/lib/quota-probe.d.ts +5 -0
- package/dist/lib/quota-probe.d.ts.map +1 -1
- package/dist/lib/quota-probe.js +26 -2
- package/dist/lib/quota-readiness.d.ts +7 -2
- package/dist/lib/quota-readiness.d.ts.map +1 -1
- package/dist/lib/quota-readiness.js +25 -4
- package/dist/lib/request/client-cancellation.d.ts +5 -0
- package/dist/lib/request/client-cancellation.d.ts.map +1 -0
- package/dist/lib/request/client-cancellation.js +7 -0
- package/dist/lib/request/response-outcome.d.ts +25 -0
- package/dist/lib/request/response-outcome.d.ts.map +1 -0
- package/dist/lib/request/response-outcome.js +49 -0
- package/dist/lib/request/stream-failover-runtime.d.ts +2 -1
- package/dist/lib/request/stream-failover-runtime.d.ts.map +1 -1
- package/dist/lib/request/stream-failover-runtime.js +29 -10
- package/dist/lib/runtime/account-check.d.ts.map +1 -1
- package/dist/lib/runtime/account-check.js +2 -8
- package/dist/lib/runtime/account-model-catalog.d.ts +64 -0
- package/dist/lib/runtime/account-model-catalog.d.ts.map +1 -0
- package/dist/lib/runtime/account-model-catalog.js +154 -0
- package/dist/lib/runtime/account-pool.d.ts +3 -1
- package/dist/lib/runtime/account-pool.d.ts.map +1 -1
- package/dist/lib/runtime/account-pool.js +4 -0
- package/dist/lib/runtime/account-reset-credits.d.ts +42 -0
- package/dist/lib/runtime/account-reset-credits.d.ts.map +1 -0
- package/dist/lib/runtime/account-reset-credits.js +82 -0
- package/dist/lib/runtime/api-model-capabilities.d.ts +30 -0
- package/dist/lib/runtime/api-model-capabilities.d.ts.map +1 -0
- package/dist/lib/runtime/api-model-capabilities.js +434 -0
- package/dist/lib/runtime/api-model-runtime.d.ts +42 -0
- package/dist/lib/runtime/api-model-runtime.d.ts.map +1 -0
- package/dist/lib/runtime/api-model-runtime.js +358 -0
- package/dist/lib/runtime/app-bind.d.ts +19 -1
- package/dist/lib/runtime/app-bind.d.ts.map +1 -1
- package/dist/lib/runtime/app-bind.js +89 -11
- package/dist/lib/runtime/automatic-account-checks.d.ts +35 -0
- package/dist/lib/runtime/automatic-account-checks.d.ts.map +1 -0
- package/dist/lib/runtime/automatic-account-checks.js +140 -0
- package/dist/lib/runtime/automatic-subscription-checks.d.ts +7 -0
- package/dist/lib/runtime/automatic-subscription-checks.d.ts.map +1 -0
- package/dist/lib/runtime/automatic-subscription-checks.js +54 -0
- package/dist/lib/runtime/catalog-capabilities.d.ts +8 -0
- package/dist/lib/runtime/catalog-capabilities.d.ts.map +1 -0
- package/dist/lib/runtime/catalog-capabilities.js +61 -0
- package/dist/lib/runtime/inference-activity.d.ts +15 -0
- package/dist/lib/runtime/inference-activity.d.ts.map +1 -0
- package/dist/lib/runtime/inference-activity.js +95 -0
- package/dist/lib/runtime/model-discovery-status.d.ts +100 -0
- package/dist/lib/runtime/model-discovery-status.d.ts.map +1 -0
- package/dist/lib/runtime/model-discovery-status.js +387 -0
- package/dist/lib/runtime/native-account-storage.d.ts +11 -0
- package/dist/lib/runtime/native-account-storage.d.ts.map +1 -0
- package/dist/lib/runtime/native-account-storage.js +50 -0
- package/dist/lib/runtime/native-account-sync.d.ts +19 -0
- package/dist/lib/runtime/native-account-sync.d.ts.map +1 -0
- package/dist/lib/runtime/native-account-sync.js +62 -0
- package/dist/lib/runtime/native-binding-lock.d.ts +3 -0
- package/dist/lib/runtime/native-binding-lock.d.ts.map +1 -0
- package/dist/lib/runtime/native-binding-lock.js +5 -0
- package/dist/lib/runtime/native-client-auth.d.ts +3 -0
- package/dist/lib/runtime/native-client-auth.d.ts.map +1 -0
- package/dist/lib/runtime/native-client-auth.js +42 -0
- package/dist/lib/runtime/native-provider-config.d.ts +4 -0
- package/dist/lib/runtime/native-provider-config.d.ts.map +1 -0
- package/dist/lib/runtime/native-provider-config.js +52 -0
- package/dist/lib/runtime/native-rate-limits.d.ts +18 -0
- package/dist/lib/runtime/native-rate-limits.d.ts.map +1 -0
- package/dist/lib/runtime/native-rate-limits.js +135 -0
- package/dist/lib/runtime/reset-credit-routing.d.ts +41 -0
- package/dist/lib/runtime/reset-credit-routing.d.ts.map +1 -0
- package/dist/lib/runtime/reset-credit-routing.js +66 -0
- package/dist/lib/runtime/reset-credits.d.ts +101 -0
- package/dist/lib/runtime/reset-credits.d.ts.map +1 -0
- package/dist/lib/runtime/reset-credits.js +162 -0
- package/dist/lib/runtime/response-output-history.d.ts +17 -0
- package/dist/lib/runtime/response-output-history.d.ts.map +1 -0
- package/dist/lib/runtime/response-output-history.js +85 -0
- package/dist/lib/runtime/responses-websocket.d.ts +31 -0
- package/dist/lib/runtime/responses-websocket.d.ts.map +1 -0
- package/dist/lib/runtime/responses-websocket.js +636 -0
- package/dist/lib/runtime/resume-picker.d.ts +41 -0
- package/dist/lib/runtime/resume-picker.d.ts.map +1 -0
- package/dist/lib/runtime/resume-picker.js +169 -0
- package/dist/lib/runtime/rotation-account-selection.d.ts +6 -0
- package/dist/lib/runtime/rotation-account-selection.d.ts.map +1 -1
- package/dist/lib/runtime/rotation-account-selection.js +63 -0
- package/dist/lib/runtime/rotation-proxy-state.d.ts +33 -0
- package/dist/lib/runtime/rotation-proxy-state.d.ts.map +1 -1
- package/dist/lib/runtime/rotation-server-types.d.ts +18 -0
- package/dist/lib/runtime/rotation-server-types.d.ts.map +1 -1
- package/dist/lib/runtime/runtime-capability-failures.d.ts +14 -0
- package/dist/lib/runtime/runtime-capability-failures.d.ts.map +1 -0
- package/dist/lib/runtime/runtime-capability-failures.js +76 -0
- package/dist/lib/runtime/runtime-observability.d.ts +7 -0
- package/dist/lib/runtime/runtime-observability.d.ts.map +1 -1
- package/dist/lib/runtime/runtime-observability.js +42 -2
- package/dist/lib/runtime/subscription-first-use.d.ts +10 -0
- package/dist/lib/runtime/subscription-first-use.d.ts.map +1 -0
- package/dist/lib/runtime/subscription-first-use.js +64 -0
- package/dist/lib/runtime/subscription-quota-event.d.ts +6 -0
- package/dist/lib/runtime/subscription-quota-event.d.ts.map +1 -0
- package/dist/lib/runtime/subscription-quota-event.js +31 -0
- package/dist/lib/runtime/subscription-quota-order.d.ts +17 -0
- package/dist/lib/runtime/subscription-quota-order.d.ts.map +1 -0
- package/dist/lib/runtime/subscription-quota-order.js +31 -0
- package/dist/lib/runtime/workspace-model-scopes.d.ts +15 -0
- package/dist/lib/runtime/workspace-model-scopes.d.ts.map +1 -0
- package/dist/lib/runtime/workspace-model-scopes.js +34 -0
- package/dist/lib/runtime-constants.d.ts +3 -0
- package/dist/lib/runtime-constants.d.ts.map +1 -1
- package/dist/lib/runtime-constants.js +5 -0
- package/dist/lib/runtime-paths.d.ts.map +1 -1
- package/dist/lib/runtime-paths.js +4 -1
- package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -1
- package/dist/lib/runtime-rotation-proxy.js +852 -42
- package/dist/lib/schemas.d.ts +20 -0
- package/dist/lib/schemas.d.ts.map +1 -1
- package/dist/lib/schemas.js +3 -0
- package/dist/lib/storage/credential-sidecars.d.ts +13 -0
- package/dist/lib/storage/credential-sidecars.d.ts.map +1 -0
- package/dist/lib/storage/credential-sidecars.js +52 -0
- package/dist/lib/storage/file-lock.d.ts +9 -0
- package/dist/lib/storage/file-lock.d.ts.map +1 -0
- package/dist/lib/storage/file-lock.js +186 -0
- package/dist/lib/storage/flagged-storage.d.ts.map +1 -1
- package/dist/lib/storage/flagged-storage.js +12 -0
- package/dist/lib/storage/path-state.d.ts +2 -0
- package/dist/lib/storage/path-state.d.ts.map +1 -1
- package/dist/lib/storage/path-state.js +9 -0
- package/dist/lib/storage/paths.js +4 -4
- package/dist/lib/storage/pending-auth.d.ts +18 -0
- package/dist/lib/storage/pending-auth.d.ts.map +1 -0
- package/dist/lib/storage/pending-auth.js +155 -0
- package/dist/lib/storage/public-types.d.ts +13 -0
- package/dist/lib/storage/public-types.d.ts.map +1 -1
- package/dist/lib/storage/record-identity.d.ts +16 -0
- package/dist/lib/storage/record-identity.d.ts.map +1 -0
- package/dist/lib/storage/record-identity.js +16 -0
- package/dist/lib/storage/snapshot-merge.d.ts +16 -0
- package/dist/lib/storage/snapshot-merge.d.ts.map +1 -0
- package/dist/lib/storage/snapshot-merge.js +206 -0
- package/dist/lib/storage/transactions.d.ts.map +1 -1
- package/dist/lib/storage/transactions.js +5 -4
- package/dist/lib/storage.d.ts +6 -0
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/storage.js +77 -7
- package/dist/lib/ui/auth-menu-builder.d.ts +2 -0
- package/dist/lib/ui/auth-menu-builder.d.ts.map +1 -1
- package/dist/lib/ui/auth-menu-builder.js +1 -0
- package/dist/lib/ui/auth-menu.d.ts.map +1 -1
- package/dist/lib/ui/auth-menu.js +1 -0
- package/dist/lib/ui/check-progress.d.ts +8 -0
- package/dist/lib/ui/check-progress.d.ts.map +1 -0
- package/dist/lib/ui/check-progress.js +30 -0
- package/dist/lib/ui/format.d.ts +3 -1
- package/dist/lib/ui/format.d.ts.map +1 -1
- package/dist/lib/ui/format.js +8 -0
- package/dist/lib/ui/ui-copy.d.ts +2 -2
- package/dist/lib/ui/ui-copy.js +2 -2
- package/dist/lib/usage/pricing.js +2 -2
- package/dist/lib/usage/usage-extraction.d.ts +3 -1
- package/dist/lib/usage/usage-extraction.d.ts.map +1 -1
- package/dist/lib/usage/usage-extraction.js +46 -9
- package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
- package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
- package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
- package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
- package/node_modules/@codex-ai/plugin/package.json +9 -9
- package/node_modules/@codex-ai/sdk/dist/index.d.ts +4 -4
- package/node_modules/@codex-ai/sdk/dist/index.js +2 -2
- package/node_modules/@codex-ai/sdk/package.json +8 -8
- package/package.json +200 -197
- package/scripts/codex-app-launcher.js +653 -653
- package/scripts/codex-app-router.js +373 -366
- package/scripts/codex-bin-resolver.js +313 -281
- package/scripts/codex-multi-auth.js +59 -59
- package/scripts/codex-routing.js +62 -61
- package/scripts/codex.js +6642 -6564
- package/scripts/install-codex-auth-utils.js +213 -213
- package/scripts/mcodex.js +367 -367
- package/scripts/postinstall.js +114 -114
- package/scripts/preuninstall.js +265 -265
- package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
- package/vendor/codex-ai-plugin/dist/index.js +2 -2
- package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
- package/vendor/codex-ai-plugin/dist/tool.js +29 -29
- package/vendor/codex-ai-plugin/package.json +9 -9
- package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
- package/vendor/codex-ai-sdk/dist/index.js +2 -2
- package/vendor/codex-ai-sdk/package.json +8 -8
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare class CatalogRetryError extends Error {
|
|
2
|
+
readonly retryAfterMs: number;
|
|
3
|
+
constructor(retryAfterMs: number);
|
|
4
|
+
}
|
|
5
|
+
export type CatalogModel = Record<string, unknown> & {
|
|
6
|
+
slug: string;
|
|
7
|
+
};
|
|
8
|
+
/** Upper bound for a catalog 429 backoff, whatever Retry-After the upstream sends. */
|
|
9
|
+
export declare const MAX_CATALOG_RETRY_MS: number;
|
|
10
|
+
export declare function clampCatalogRetryMs(retryAfterMs: number | null | undefined): number;
|
|
11
|
+
/**
|
|
12
|
+
* Per-proxy discovery cache. Failed refreshes never advertise stale access, but
|
|
13
|
+
* they are "unknown", not "empty": only a successful fetch can exclude a model.
|
|
14
|
+
* Routing fails open: an outage or throttle lets inference through, and the last
|
|
15
|
+
* successfully fetched catalog (whatever its age) is the only thing that excludes.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AccountModelCatalog {
|
|
18
|
+
private readonly fetchCatalog;
|
|
19
|
+
private readonly now;
|
|
20
|
+
private readonly ttlMs;
|
|
21
|
+
private readonly cache;
|
|
22
|
+
private readonly updated;
|
|
23
|
+
private readonly pending;
|
|
24
|
+
constructor(fetchCatalog: (accountKey: string) => Promise<unknown>, now?: () => number, ttlMs?: number);
|
|
25
|
+
private read;
|
|
26
|
+
/** Picker-only stale-while-refresh view; routing still awaits fresh discovery. */
|
|
27
|
+
cachedList(accountKeys: string[]): CatalogModel[];
|
|
28
|
+
invalidate(): void;
|
|
29
|
+
/** Retry discovery while retaining known routing exclusions if it fails. */
|
|
30
|
+
refresh(): void;
|
|
31
|
+
supportsCached(key: string, model: string, effort?: string, tier?: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Routing view: the last successful catalog decides, whatever its age. A workspace
|
|
34
|
+
* that has never been fetched successfully (outage, throttle, slow discovery) is
|
|
35
|
+
* unknown and stays routable; only a fetched catalog can exclude a model.
|
|
36
|
+
*/
|
|
37
|
+
supportsForRouting(key: string, model: string, effort?: string, tier?: string): boolean;
|
|
38
|
+
/** Refresh in the background; one fresh eligible route is enough to dispatch early.
|
|
39
|
+
* After the wait, routing falls back to {@link supportsForRouting}. The caller still ranks eligible accounts.
|
|
40
|
+
*/
|
|
41
|
+
prepareRouting(keys: string[], model: string, effort?: string, tier?: string, eligible?: (key: string) => boolean, waitMs?: number): Promise<"ready" | "unavailable">;
|
|
42
|
+
list(accountKeys: string[], referenceKey?: string): Promise<CatalogModel[]>;
|
|
43
|
+
/** True unless a successfully fetched catalog omits the model. */
|
|
44
|
+
supports(accountKey: string, model: string, effort?: string, tier?: string): Promise<boolean>;
|
|
45
|
+
snapshot(key: string): {
|
|
46
|
+
checkedAt: number;
|
|
47
|
+
models: string[];
|
|
48
|
+
entitlements: {
|
|
49
|
+
serviceTiers: {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
}[];
|
|
53
|
+
reasoningLevels: string[];
|
|
54
|
+
accessPrograms: string[];
|
|
55
|
+
probes?: {
|
|
56
|
+
[k: string]: "unsupported" | "verified" | "unverified" | "downgraded";
|
|
57
|
+
} | undefined;
|
|
58
|
+
checkedAt?: number | undefined;
|
|
59
|
+
model: string;
|
|
60
|
+
}[];
|
|
61
|
+
error: boolean;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=account-model-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-model-catalog.d.ts","sourceRoot":"","sources":["../../../lib/runtime/account-model-catalog.ts"],"names":[],"mappings":"AAKA,qBAAa,iBAAkB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM;gBAApB,YAAY,EAAE,MAAM;CACzC;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,QAAc,CAAC;AAChD,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAGnF;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAQ9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IATvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGlB;IACJ,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqD;gBAE3D,YAAY,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EACtD,GAAG,GAAE,MAAM,MAAiB,EAC5B,KAAK,SAAa;YAEtB,IAAI;IAkDlB,kFAAkF;IAClF,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE;IAOjD,UAAU,IAAI,IAAI;IAClB,4EAA4E;IAC5E,OAAO,IAAI,IAAI;IACf,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IAInF;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IAIvF;;OAEG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EACjF,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAoB,EAAE,MAAM,SAAO,GAC5D,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC;IAe7B,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAYjF,kEAAkE;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInG,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;CAIpB"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { buildVisibleModelUnion, supportsModelSettings, modelEntitlements } from "../model-route-policy.js";
|
|
2
|
+
import { mapWithConcurrency } from "../concurrency.js";
|
|
3
|
+
import { clampCatalogContext, supportsCatalogSettings } from "./catalog-capabilities.js";
|
|
4
|
+
import { isRecord } from "../utils.js";
|
|
5
|
+
export class CatalogRetryError extends Error {
|
|
6
|
+
retryAfterMs;
|
|
7
|
+
constructor(retryAfterMs) {
|
|
8
|
+
super("Catalog temporarily rate limited");
|
|
9
|
+
this.retryAfterMs = retryAfterMs;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Upper bound for a catalog 429 backoff, whatever Retry-After the upstream sends. */
|
|
13
|
+
export const MAX_CATALOG_RETRY_MS = 15 * 60_000;
|
|
14
|
+
export function clampCatalogRetryMs(retryAfterMs) {
|
|
15
|
+
const value = typeof retryAfterMs === "number" && Number.isFinite(retryAfterMs) ? retryAfterMs : 60_000;
|
|
16
|
+
return Math.min(MAX_CATALOG_RETRY_MS, Math.max(60_000, value));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Per-proxy discovery cache. Failed refreshes never advertise stale access, but
|
|
20
|
+
* they are "unknown", not "empty": only a successful fetch can exclude a model.
|
|
21
|
+
* Routing fails open: an outage or throttle lets inference through, and the last
|
|
22
|
+
* successfully fetched catalog (whatever its age) is the only thing that excludes.
|
|
23
|
+
*/
|
|
24
|
+
export class AccountModelCatalog {
|
|
25
|
+
fetchCatalog;
|
|
26
|
+
now;
|
|
27
|
+
ttlMs;
|
|
28
|
+
cache = new Map();
|
|
29
|
+
updated = new Set();
|
|
30
|
+
pending = new Map();
|
|
31
|
+
constructor(fetchCatalog, now = Date.now, ttlMs = 5 * 60_000) {
|
|
32
|
+
this.fetchCatalog = fetchCatalog;
|
|
33
|
+
this.now = now;
|
|
34
|
+
this.ttlMs = ttlMs;
|
|
35
|
+
}
|
|
36
|
+
async read(key) {
|
|
37
|
+
const cached = this.cache.get(key);
|
|
38
|
+
if (cached && cached.expires > this.now())
|
|
39
|
+
return cached.models;
|
|
40
|
+
const existing = this.pending.get(key);
|
|
41
|
+
if (existing)
|
|
42
|
+
return existing;
|
|
43
|
+
const task = (async () => {
|
|
44
|
+
let models = null;
|
|
45
|
+
let retryMs = Math.min(this.ttlMs, 5000);
|
|
46
|
+
try {
|
|
47
|
+
const value = await this.fetchCatalog(key);
|
|
48
|
+
if (!isRecord(value) ||
|
|
49
|
+
!Array.isArray(value.models) ||
|
|
50
|
+
value.models.length > 1000 ||
|
|
51
|
+
!value.models.every((m) => isRecord(m) &&
|
|
52
|
+
typeof m.slug === "string" &&
|
|
53
|
+
m.slug.length > 0 &&
|
|
54
|
+
m.slug.length < 256)) {
|
|
55
|
+
throw new Error("Invalid account model catalog");
|
|
56
|
+
}
|
|
57
|
+
models = value.models;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof CatalogRetryError)
|
|
61
|
+
retryMs = clampCatalogRetryMs(error.retryAfterMs);
|
|
62
|
+
/* Unknown; list() advertises nothing from it and supports() fails open. */
|
|
63
|
+
}
|
|
64
|
+
const previous = this.cache.get(key);
|
|
65
|
+
if (!previous && this.cache.size >= 3000)
|
|
66
|
+
this.cache.delete(this.cache.keys().next().value ?? "");
|
|
67
|
+
this.cache.set(key, {
|
|
68
|
+
lastGood: models ?? previous?.lastGood ?? null,
|
|
69
|
+
checkedAt: this.now(), error: models === null,
|
|
70
|
+
expires: this.now() +
|
|
71
|
+
(models !== null ? this.ttlMs : retryMs),
|
|
72
|
+
models,
|
|
73
|
+
});
|
|
74
|
+
for (const notify of this.updated)
|
|
75
|
+
notify();
|
|
76
|
+
return models;
|
|
77
|
+
})();
|
|
78
|
+
this.pending.set(key, task);
|
|
79
|
+
try {
|
|
80
|
+
return await task;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
this.pending.delete(key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Picker-only stale-while-refresh view; routing still awaits fresh discovery. */
|
|
87
|
+
cachedList(accountKeys) {
|
|
88
|
+
return buildVisibleModelUnion(accountKeys.map((key, index) => {
|
|
89
|
+
const entry = this.cache.get(key);
|
|
90
|
+
const usable = entry && !entry.error && entry.checkedAt <= this.now() && this.now() - entry.checkedAt < 15 * 60_000;
|
|
91
|
+
return { id: key, kind: "oauth", priority: index, enabled: true, models: usable ? entry.models ?? [] : [], visibleModels: null };
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
invalidate() { this.cache.clear(); }
|
|
95
|
+
/** Retry discovery while retaining known routing exclusions if it fails. */
|
|
96
|
+
refresh() { for (const entry of this.cache.values())
|
|
97
|
+
entry.expires = Number.NEGATIVE_INFINITY; }
|
|
98
|
+
supportsCached(key, model, effort, tier) {
|
|
99
|
+
const cached = this.cache.get(key);
|
|
100
|
+
return Boolean(cached && !cached.error && cached.expires > this.now() && cached.models?.some(entry => entry.slug === model && supportsModelSettings(entry, effort, tier)));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Routing view: the last successful catalog decides, whatever its age. A workspace
|
|
104
|
+
* that has never been fetched successfully (outage, throttle, slow discovery) is
|
|
105
|
+
* unknown and stays routable; only a fetched catalog can exclude a model.
|
|
106
|
+
*/
|
|
107
|
+
supportsForRouting(key, model, effort, tier) {
|
|
108
|
+
const known = this.cache.get(key)?.lastGood;
|
|
109
|
+
return !known || known.some(entry => entry.slug === model && supportsModelSettings(entry, effort, tier));
|
|
110
|
+
}
|
|
111
|
+
/** Refresh in the background; one fresh eligible route is enough to dispatch early.
|
|
112
|
+
* After the wait, routing falls back to {@link supportsForRouting}. The caller still ranks eligible accounts.
|
|
113
|
+
*/
|
|
114
|
+
async prepareRouting(keys, model, effort, tier, eligible = () => true, waitMs = 2000) {
|
|
115
|
+
const ready = () => keys.some(key => eligible(key) && this.supportsCached(key, model, effort, tier));
|
|
116
|
+
let notify;
|
|
117
|
+
const available = new Promise(resolve => { notify = () => { if (ready())
|
|
118
|
+
resolve(); }; });
|
|
119
|
+
this.updated.add(notify);
|
|
120
|
+
let timer;
|
|
121
|
+
try {
|
|
122
|
+
const refresh = this.list(keys).then(() => undefined, () => undefined);
|
|
123
|
+
if (!ready())
|
|
124
|
+
await Promise.race([refresh, available, new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]);
|
|
125
|
+
return ready() || keys.some(key => eligible(key) && this.supportsForRouting(key, model, effort, tier)) ? "ready" : "unavailable";
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
if (timer)
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
this.updated.delete(notify);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async list(accountKeys, referenceKey) {
|
|
134
|
+
const models = new Map();
|
|
135
|
+
const catalogs = await mapWithConcurrency([...new Set([...accountKeys, ...(referenceKey ? [referenceKey] : [])])], 3, key => this.read(key));
|
|
136
|
+
const combined = buildVisibleModelUnion(catalogs.map((models, index) => ({ id: String(index), kind: "oauth", enabled: true, priority: index, models: models ?? [], visibleModels: null })));
|
|
137
|
+
for (const model of combined)
|
|
138
|
+
models.set(model.slug, model);
|
|
139
|
+
if (referenceKey) {
|
|
140
|
+
const reference = await this.read(referenceKey);
|
|
141
|
+
return (reference ?? []).map(model => clampCatalogContext(model, models.get(model.slug) ?? model));
|
|
142
|
+
}
|
|
143
|
+
return [...models.values()];
|
|
144
|
+
}
|
|
145
|
+
/** True unless a successfully fetched catalog omits the model. */
|
|
146
|
+
async supports(accountKey, model, effort, tier) {
|
|
147
|
+
const models = await this.read(accountKey);
|
|
148
|
+
return models === null ? true : models.some((entry) => entry.slug === model && supportsCatalogSettings(entry, effort, tier));
|
|
149
|
+
}
|
|
150
|
+
snapshot(key) {
|
|
151
|
+
const entry = this.cache.get(key);
|
|
152
|
+
return { checkedAt: entry?.checkedAt ?? 0, models: entry?.models?.map(m => m.slug) ?? [], entitlements: entry?.models?.map(modelEntitlements) ?? [], error: entry?.error ?? true };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Workspace } from "../accounts.js";
|
|
2
2
|
import type { ModelFamily } from "../prompts/codex.js";
|
|
3
|
-
import type { AccountStorageV3 } from "../storage.js";
|
|
3
|
+
import type { AccountMetadataV3, AccountStorageV3 } from "../storage.js";
|
|
4
4
|
import type { AccountIdSource, TokenResult } from "../types.js";
|
|
5
5
|
export type TokenSuccessWithAccount = Extract<TokenResult, {
|
|
6
6
|
type: "success";
|
|
@@ -9,6 +9,8 @@ export type TokenSuccessWithAccount = Extract<TokenResult, {
|
|
|
9
9
|
accountIdSource?: AccountIdSource;
|
|
10
10
|
accountLabel?: string;
|
|
11
11
|
workspaces?: Workspace[];
|
|
12
|
+
/** Set, keep (undefined) or clear (null) the saved CodexCliMirror. */
|
|
13
|
+
codexCliMirror?: AccountMetadataV3["codexCliMirror"] | null;
|
|
12
14
|
};
|
|
13
15
|
export declare function persistAccountPoolResults(params: {
|
|
14
16
|
results: TokenSuccessWithAccount[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../lib/runtime/account-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../lib/runtime/account-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC5C,WAAW,EACX;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CACnB,GAAG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,sEAAsE;IACtE,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;CAC5D,CAAC;AAEF,wBAAsB,yBAAyB,CAAC,MAAM,EAAE;IACvD,OAAO,EAAE,uBAAuB,EAAE,CAAC;IACnC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,SAAS,WAAW,EAAE,CAAC;IACtC,6BAA6B,EAAE,CAAC,CAAC,EAChC,OAAO,EAAE,CACR,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,OAAO,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,KACjD,OAAO,CAAC,CAAC,CAAC,KACX,OAAO,CAAC,CAAC,CAAC,CAAC;IAChB,wBAAwB,EAAE,cAAc,eAAe,EAAE,wBAAwB,CAAC;IAClF,gBAAgB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9D,mBAAmB,EAAE,CACpB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,KACZ,MAAM,GAAG,SAAS,CAAC;IACxB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS,CAAC;CACjE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiLhB"}
|
|
@@ -48,6 +48,7 @@ export async function persistAccountPoolResults(params) {
|
|
|
48
48
|
lastUsed: now,
|
|
49
49
|
workspaces: result.workspaces,
|
|
50
50
|
currentWorkspaceIndex: initialWorkspaceIndex,
|
|
51
|
+
...(result.codexCliMirror ? { codexCliMirror: result.codexCliMirror } : {}),
|
|
51
52
|
});
|
|
52
53
|
continue;
|
|
53
54
|
}
|
|
@@ -105,6 +106,9 @@ export async function persistAccountPoolResults(params) {
|
|
|
105
106
|
lastUsed: now,
|
|
106
107
|
workspaces: mergedWorkspaces,
|
|
107
108
|
currentWorkspaceIndex: nextCurrentWorkspaceIndex,
|
|
109
|
+
codexCliMirror: result.codexCliMirror === null
|
|
110
|
+
? undefined
|
|
111
|
+
: (result.codexCliMirror ?? existing.codexCliMirror),
|
|
108
112
|
};
|
|
109
113
|
}
|
|
110
114
|
if (accounts.length === 0)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AccountManager } from '../accounts.js';
|
|
2
|
+
import { type AccountMetadataV3 } from '../storage.js';
|
|
3
|
+
import { ResetCreditService, type ResetTarget } from './reset-credits.js';
|
|
4
|
+
export declare function resetTargetForStoredAccount(account: AccountMetadataV3): ResetTarget | null;
|
|
5
|
+
export declare function isResetTargetEnabled(account: AccountMetadataV3, target: ResetTarget): boolean;
|
|
6
|
+
export declare function createResetCreditService(manager?: AccountManager): ResetCreditService;
|
|
7
|
+
export declare function loadResetCreditState(): Promise<{
|
|
8
|
+
version: 1;
|
|
9
|
+
policy: "manual" | "last-resort";
|
|
10
|
+
snapshots: Record<string, {
|
|
11
|
+
updatedAt: number;
|
|
12
|
+
availableCount: number | null;
|
|
13
|
+
ordinaryUsageAllowed: boolean | null;
|
|
14
|
+
planType: string | null;
|
|
15
|
+
primary: {
|
|
16
|
+
usedPercent?: number | undefined;
|
|
17
|
+
resetsAt?: number | null | undefined;
|
|
18
|
+
windowDurationMins?: number | null | undefined;
|
|
19
|
+
};
|
|
20
|
+
secondary: {
|
|
21
|
+
usedPercent?: number | undefined;
|
|
22
|
+
resetsAt?: number | null | undefined;
|
|
23
|
+
windowDurationMins?: number | null | undefined;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
pending?: {
|
|
27
|
+
key: string;
|
|
28
|
+
idempotencyKey: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
lastAutomaticCheckAt?: number | undefined;
|
|
31
|
+
lastRedemptionAt?: number | undefined;
|
|
32
|
+
lastRedemption?: {
|
|
33
|
+
key: string;
|
|
34
|
+
at: number;
|
|
35
|
+
outcome: "reset" | "nothingToReset" | "noCredit" | "alreadyRedeemed";
|
|
36
|
+
automatic: boolean;
|
|
37
|
+
} | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
/** Local terminal labels only; never used in provider requests or public artifacts. */
|
|
40
|
+
export declare function resetAccountLabel(account: Pick<AccountMetadataV3, "email">, index: number): string;
|
|
41
|
+
export declare function refreshAndPrintResetCredits(log: (message: string) => void): Promise<void>;
|
|
42
|
+
//# sourceMappingURL=account-reset-credits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-reset-credits.d.ts","sourceRoot":"","sources":["../../../lib/runtime/account-reset-credits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA2D,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOrE,OAAO,EAAE,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG1E,wBAAgB,2BAA2B,CAAC,OAAO,EAAC,iBAAiB,GAAE,WAAW,GAAC,IAAI,CAOtF;AACD,wBAAgB,oBAAoB,CAAC,OAAO,EAAC,iBAAiB,EAAC,MAAM,EAAC,WAAW,GAAE,OAAO,CAMzF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAC,cAAc,GAAE,kBAAkB,CA2BnF;AACD,wBAAsB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA+C;AACzF,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIlG;AACD,wBAAsB,2BAA2B,CAAC,GAAG,EAAC,CAAC,OAAO,EAAC,MAAM,KAAG,IAAI,iBAQ3E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { AccountManager, extractAccountId, resolveAccountRecordId, sanitizeEmail } from '../accounts.js';
|
|
3
|
+
import { loadAccounts } from '../storage.js';
|
|
4
|
+
import { getCodexMultiAuthDir } from '../runtime-paths.js';
|
|
5
|
+
import { ensureFreshAccessToken } from './rotation-token-refresh.js';
|
|
6
|
+
import { modelScopeId, workspaceModelScopes } from './workspace-model-scopes.js';
|
|
7
|
+
import { nativeRateLimitsRpc } from './native-rate-limits.js';
|
|
8
|
+
import { codexCliAccountIdFor } from '../auth/token-utils.js';
|
|
9
|
+
import { isRecord } from '../utils.js';
|
|
10
|
+
import { ResetCreditService } from './reset-credits.js';
|
|
11
|
+
import { withCheckProgress } from '../ui/check-progress.js';
|
|
12
|
+
export function resetTargetForStoredAccount(account) {
|
|
13
|
+
// Organization display aliases are not native ChatGPT workspace identities.
|
|
14
|
+
const stored = account.accountId?.trim();
|
|
15
|
+
const id = stored?.startsWith("org-") ? extractAccountId(account.accessToken)?.trim() : stored;
|
|
16
|
+
const workspace = account.workspaces?.find(w => w.id === id);
|
|
17
|
+
if (!id || id.startsWith("org-") || account.enabled === false || workspace?.enabled === false)
|
|
18
|
+
return null;
|
|
19
|
+
return { key: modelScopeId('oauth', resolveAccountRecordId(account), id), accountId: id };
|
|
20
|
+
}
|
|
21
|
+
export function isResetTargetEnabled(account, target) {
|
|
22
|
+
if (account.enabled === false)
|
|
23
|
+
return false;
|
|
24
|
+
const canonical = resetTargetForStoredAccount(account);
|
|
25
|
+
if (canonical?.key === target.key && canonical.accountId === target.accountId)
|
|
26
|
+
return true;
|
|
27
|
+
const scopeKey = modelScopeId('oauth', resolveAccountRecordId(account), target.accountId);
|
|
28
|
+
return !target.accountId.startsWith('org-') && scopeKey === target.key && Boolean(account.workspaces?.some(w => w.id === target.accountId && w.enabled !== false));
|
|
29
|
+
}
|
|
30
|
+
export function createResetCreditService(manager) {
|
|
31
|
+
const auth = async (target) => {
|
|
32
|
+
const account = manager?.getAccountsSnapshot().find(a => workspaceModelScopes(a).some(s => s.id === target.key && s.accountId === target.accountId && s.routable) || (resetTargetForStoredAccount({ ...a, accessToken: a.access })?.key === target.key && resetTargetForStoredAccount({ ...a, accessToken: a.access })?.accountId === target.accountId));
|
|
33
|
+
const current = account && manager?.getAccountByIndex(account.index);
|
|
34
|
+
if (!manager || !current || current.enabled === false)
|
|
35
|
+
throw Error('Reset workspace is not enabled');
|
|
36
|
+
const fresh = await ensureFreshAccessToken({ accountManager: manager, account: current, family: 'codex', model: null, now: Date.now(), tokenRefreshSkewMs: 60000, tokenInvalidationCooldownMs: 300000 });
|
|
37
|
+
if (!fresh.ok)
|
|
38
|
+
throw Error('Reset account authentication unavailable');
|
|
39
|
+
// The mirror carries the id Codex CLI accepts when the backend refused an explicit binding.
|
|
40
|
+
return { accessToken: fresh.accessToken, accountId: target.accountId, expiresAt: fresh.account.expires ?? 0, codexCliMirror: current.codexCliMirror };
|
|
41
|
+
};
|
|
42
|
+
return new ResetCreditService(join(getCodexMultiAuthDir(), 'reset-credits.json'), {
|
|
43
|
+
read: async (target) => {
|
|
44
|
+
// The backend answers for the id written into its auth.json (the mirror id when one
|
|
45
|
+
// applies). Verify the reply against that id; the snapshot stays keyed on the target.
|
|
46
|
+
const freshAuth = await auth(target);
|
|
47
|
+
const sent = codexCliAccountIdFor(freshAuth, freshAuth.accessToken) ?? freshAuth.accountId;
|
|
48
|
+
const reply = await nativeRateLimitsRpc(freshAuth, 'account/rateLimits/read', { excludeResetCreditDetails: true });
|
|
49
|
+
if (!isRecord(reply) || reply.accountId !== sent)
|
|
50
|
+
throw Error('Reset credit workspace identity mismatch');
|
|
51
|
+
return { ...reply, accountId: target.accountId };
|
|
52
|
+
},
|
|
53
|
+
consume: async (target, idempotencyKey) => {
|
|
54
|
+
const freshAuth = await auth(target);
|
|
55
|
+
const disk = await loadAccounts();
|
|
56
|
+
if (!disk?.accounts.some(a => isResetTargetEnabled(a, target)))
|
|
57
|
+
throw Error('Reset target was removed, disabled, or changed; no credit consumed');
|
|
58
|
+
return nativeRateLimitsRpc(freshAuth, 'account/rateLimitResetCredit/consume', { idempotencyKey });
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export async function loadResetCreditState() { return createResetCreditService().status(); }
|
|
63
|
+
/** Local terminal labels only; never used in provider requests or public artifacts. */
|
|
64
|
+
export function resetAccountLabel(account, index) {
|
|
65
|
+
const email = sanitizeEmail(account.email);
|
|
66
|
+
const printable = email && !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(email);
|
|
67
|
+
return `Account ${index + 1}${printable ? ` (${email})` : ""}`;
|
|
68
|
+
}
|
|
69
|
+
export async function refreshAndPrintResetCredits(log) {
|
|
70
|
+
const storage = await loadAccounts();
|
|
71
|
+
if (!storage?.accounts.length)
|
|
72
|
+
return;
|
|
73
|
+
const manager = new AccountManager(undefined, storage);
|
|
74
|
+
const targets = storage.accounts.map(resetTargetForStoredAccount).filter((t) => Boolean(t));
|
|
75
|
+
try {
|
|
76
|
+
const snapshots = await withCheckProgress(`Checking reset credits for ${targets.length} accounts`, () => createResetCreditService(manager).refresh(targets), log);
|
|
77
|
+
storage.accounts.forEach((a, i) => { const target = resetTargetForStoredAccount(a); const count = target ? snapshots[target.key]?.availableCount : undefined; log(`${resetAccountLabel(a, i)}: available subscription resets: ${count ?? 'unknown (not verified)'}`); });
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
await manager.flushPendingSave();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ApiRouteCredential } from "../api-route-store.js";
|
|
2
|
+
import { type RouteModel } from "../model-route-policy.js";
|
|
3
|
+
/** Read the explicit model-specific statement, never surrounding examples or another model's settings. */
|
|
4
|
+
export declare function parseApiReasoningDocumentation(id: string, text: string): string[];
|
|
5
|
+
export type ProbeResult = {
|
|
6
|
+
at: number;
|
|
7
|
+
levels: string[];
|
|
8
|
+
tiers: string[];
|
|
9
|
+
status: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export declare class ApiModelCapabilities {
|
|
12
|
+
private readonly fetchImpl;
|
|
13
|
+
private readonly now;
|
|
14
|
+
private activeProbes;
|
|
15
|
+
private readonly probeWaiters;
|
|
16
|
+
private withProbeSlot;
|
|
17
|
+
private readonly inFlight;
|
|
18
|
+
private readonly probes;
|
|
19
|
+
private readonly cache;
|
|
20
|
+
constructor(fetchImpl?: typeof fetch, now?: () => number);
|
|
21
|
+
/** Probe results keyed by an opaque hash, for a fresh CLI process to honour the 15-minute cache. */
|
|
22
|
+
exportProbes(): Array<[string, ProbeResult]>;
|
|
23
|
+
importProbes(entries: Array<[string, ProbeResult]>): void;
|
|
24
|
+
reasoning(id: string, refresh?: boolean): Promise<string[]>;
|
|
25
|
+
private documentation;
|
|
26
|
+
private probe;
|
|
27
|
+
private runProbe;
|
|
28
|
+
enrich(models: RouteModel[], refresh?: boolean, route?: ApiRouteCredential, forceProbes?: boolean): Promise<RouteModel[]>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=api-model-capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-model-capabilities.d.ts","sourceRoot":"","sources":["../../../lib/runtime/api-model-capabilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAEN,KAAK,UAAU,EACf,MAAM,0BAA0B,CAAC;AAYlC,0GAA0G;AAC1G,wBAAgB,8BAA8B,CAC7C,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACV,MAAM,EAAE,CAuBV;AACD,MAAM,MAAM,WAAW,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAwCF,qBAAa,oBAAoB;IA2B/B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG;IA3BrB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyB;YACxC,aAAa;IAY3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2C;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAQnB;IACJ,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8D;gBAElE,SAAS,GAAE,OAAO,KAAa,EAC/B,GAAG,GAAE,MAAM,MAAiB;IAE9C,oGAAoG;IACpG,YAAY,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAG5C,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,IAAI;IAMnD,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YAGjD,aAAa;YA4Cb,KAAK;YAyBL,QAAQ;IA8MhB,MAAM,CACX,MAAM,EAAE,UAAU,EAAE,EACpB,OAAO,UAAQ,EACf,KAAK,CAAC,EAAE,kBAAkB,EAC1B,WAAW,UAAQ,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC;CAqDxB"}
|