codex-multi-auth 2.15.0 → 2.17.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/.codex-plugin/plugin.json +1 -1
- package/README.md +22 -1
- package/config/README.md +2 -2
- package/config/codex-legacy.json +109 -184
- package/config/codex-modern.json +44 -114
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- 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 +21 -3
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +229 -17
- 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.map +1 -1
- package/dist/lib/codex-manager/commands/forecast.js +5 -1
- 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 +56 -6
- 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 +14 -5
- 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/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 +143 -8
- 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/model-context-windows.d.ts +1 -1
- package/dist/lib/context-budget/model-context-windows.d.ts.map +1 -1
- package/dist/lib/context-budget/model-context-windows.js +9 -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/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.d.ts.map +1 -1
- package/dist/lib/prompts/codex.js +3 -1
- 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/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/error-classification.d.ts.map +1 -1
- package/dist/lib/request/error-classification.js +39 -25
- package/dist/lib/request/fetch-helpers.js +1 -1
- package/dist/lib/request/helpers/model-map.d.ts +12 -2
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
- package/dist/lib/request/helpers/model-map.js +174 -147
- 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 +79 -9
- package/dist/lib/runtime/automatic-account-checks.d.ts +31 -0
- package/dist/lib/runtime/automatic-account-checks.d.ts.map +1 -0
- package/dist/lib/runtime/automatic-account-checks.js +113 -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 +57 -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 +855 -46
- 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 +17 -0
- package/dist/lib/storage/pending-auth.d.ts.map +1 -0
- package/dist/lib/storage/pending-auth.js +153 -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/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.d.ts +19 -2
- package/dist/lib/usage/pricing.d.ts.map +1 -1
- package/dist/lib/usage/pricing.js +101 -40
- 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/package.json +7 -4
- package/scripts/codex-app-router.js +7 -0
- package/scripts/codex-bin-resolver.js +40 -8
- package/scripts/codex-routing.js +1 -0
- package/scripts/codex.js +209 -126
|
@@ -6,6 +6,7 @@ import { extractAccountEmail, extractAccountId, formatAccountLabel, sanitizeEmai
|
|
|
6
6
|
import { loadQuotaCache, saveQuotaCache } from "../quota-cache.js";
|
|
7
7
|
import { fetchCodexQuotaSnapshot, CODEX_UNAVAILABLE_PROBE_NOTE, } from "../quota-probe.js";
|
|
8
8
|
import { isCodexUnavailableError } from "../errors.js";
|
|
9
|
+
import { codexAuthAccountIdsMatch, codexCliAccountIdFor, codexCliActiveIdentity, isOpenAiOrgId, } from "../auth/token-utils.js";
|
|
9
10
|
import { queuedRefresh } from "../refresh-queue.js";
|
|
10
11
|
import { findMatchingAccountIndex, getStoragePath, loadAccounts, loadFlaggedAccounts, setStoragePath, withAccountStorageTransaction, withAccountAndFlaggedStorageTransaction, withFlaggedStorageTransaction, } from "../storage.js";
|
|
11
12
|
import { getCodexCliAuthPath, getCodexCliConfigPath, loadCodexCliState, } from "../codex-cli/state.js";
|
|
@@ -28,6 +29,7 @@ function printFixUsage() {
|
|
|
28
29
|
" - Refreshes tokens for enabled accounts",
|
|
29
30
|
" - Disables hard-failed accounts (never deletes)",
|
|
30
31
|
" - Recommends a better current account when needed",
|
|
32
|
+
" - With --live, rebinds an org workspace id the backend no longer authorizes",
|
|
31
33
|
].join("\n"));
|
|
32
34
|
}
|
|
33
35
|
function printVerifyFlaggedUsage() {
|
|
@@ -160,7 +162,8 @@ function summarizeFixReports(reports) {
|
|
|
160
162
|
healthy += 1;
|
|
161
163
|
else if (report.outcome === "disabled-hard-failure")
|
|
162
164
|
disabled += 1;
|
|
163
|
-
else if (report.outcome === "warning-soft-failure"
|
|
165
|
+
else if (report.outcome === "warning-soft-failure" ||
|
|
166
|
+
report.outcome === "rebound-unauthorized-workspace")
|
|
164
167
|
warnings += 1;
|
|
165
168
|
else
|
|
166
169
|
skipped += 1;
|
|
@@ -186,7 +189,11 @@ function hasAccountStorageMutation(before, after) {
|
|
|
186
189
|
|| before.email !== after.email
|
|
187
190
|
|| before.accountId !== after.accountId
|
|
188
191
|
|| before.accountIdSource !== after.accountIdSource
|
|
189
|
-
|| before.enabled !== after.enabled
|
|
192
|
+
|| before.enabled !== after.enabled
|
|
193
|
+
|| before.accountLabel !== after.accountLabel
|
|
194
|
+
|| before.currentWorkspaceIndex !== after.currentWorkspaceIndex
|
|
195
|
+
|| JSON.stringify(before.workspaces) !== JSON.stringify(after.workspaces)
|
|
196
|
+
|| JSON.stringify(before.codexCliMirror) !== JSON.stringify(after.codexCliMirror));
|
|
190
197
|
}
|
|
191
198
|
function collectAccountStorageMutations(beforeAccounts, afterAccounts) {
|
|
192
199
|
const mutations = [];
|
|
@@ -224,6 +231,33 @@ function applyAccountStorageMutations(storage, mutations) {
|
|
|
224
231
|
target.accountId = mutation.after.accountId;
|
|
225
232
|
target.accountIdSource = mutation.after.accountIdSource;
|
|
226
233
|
target.enabled = mutation.after.enabled;
|
|
234
|
+
// Only the workspace rebind in `fix --live` moves these; copying them
|
|
235
|
+
// unconditionally would clobber a label/workspace change made on disk
|
|
236
|
+
// since this run loaded storage.
|
|
237
|
+
if (mutation.before.accountLabel !== mutation.after.accountLabel) {
|
|
238
|
+
target.accountLabel = mutation.after.accountLabel;
|
|
239
|
+
}
|
|
240
|
+
if (JSON.stringify(mutation.before.codexCliMirror) !==
|
|
241
|
+
JSON.stringify(mutation.after.codexCliMirror)) {
|
|
242
|
+
target.codexCliMirror = mutation.after.codexCliMirror;
|
|
243
|
+
if (!target.codexCliMirror)
|
|
244
|
+
delete target.codexCliMirror;
|
|
245
|
+
}
|
|
246
|
+
// The pointer indexes the list, so the two move together: copying only
|
|
247
|
+
// the list would keep a pointer moved on disk meanwhile, possibly out
|
|
248
|
+
// of range of the new list.
|
|
249
|
+
if (mutation.before.currentWorkspaceIndex !== mutation.after.currentWorkspaceIndex ||
|
|
250
|
+
JSON.stringify(mutation.before.workspaces) !==
|
|
251
|
+
JSON.stringify(mutation.after.workspaces)) {
|
|
252
|
+
const workspaces = mutation.after.workspaces;
|
|
253
|
+
const pointer = mutation.after.currentWorkspaceIndex;
|
|
254
|
+
target.workspaces = workspaces;
|
|
255
|
+
target.currentWorkspaceIndex =
|
|
256
|
+
!workspaces ||
|
|
257
|
+
(typeof pointer === "number" && pointer >= 0 && pointer < workspaces.length)
|
|
258
|
+
? pointer
|
|
259
|
+
: Math.max(0, workspaces.findIndex((workspace) => workspace.id === mutation.after.accountId));
|
|
260
|
+
}
|
|
227
261
|
}
|
|
228
262
|
}
|
|
229
263
|
function findExistingAccountIndexForFlagged(storage, flagged, nextRefreshToken, nextAccountId, nextEmail) {
|
|
@@ -866,6 +900,29 @@ export async function runFix(args, deps) {
|
|
|
866
900
|
const reports = [];
|
|
867
901
|
const refreshFailures = new Map();
|
|
868
902
|
const hardDisabledIndexes = [];
|
|
903
|
+
// A rebind mutates the account before its live probe, so a later rebind
|
|
904
|
+
// attempt on the refresh path sees a `token` source and reports nothing.
|
|
905
|
+
// Tracking it per index keeps the note on whichever report ends up final.
|
|
906
|
+
const reboundIndexes = new Set();
|
|
907
|
+
// Explicit accounts whose CodexCliMirror this run set or cleared. Checked
|
|
908
|
+
// once per account even when the refresh path runs after a failed probe.
|
|
909
|
+
const mirrorUpdates = new Map();
|
|
910
|
+
const checkMirror = async (index, accessToken) => {
|
|
911
|
+
const account = storage.accounts[index];
|
|
912
|
+
if (!account || mirrorUpdates.has(index))
|
|
913
|
+
return;
|
|
914
|
+
const update = await deps.refreshCodexCliMirror(account, accessToken);
|
|
915
|
+
mirrorUpdates.set(index, update);
|
|
916
|
+
if (update)
|
|
917
|
+
accountStorageChanged = true;
|
|
918
|
+
};
|
|
919
|
+
const noteRebound = (index) => {
|
|
920
|
+
reboundIndexes.add(index);
|
|
921
|
+
accountStorageChanged = true;
|
|
922
|
+
if (workingQuotaCache) {
|
|
923
|
+
quotaEmailFallbackState = deps.buildQuotaEmailFallbackState(storage.accounts);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
869
926
|
for (let i = 0; i < storage.accounts.length; i += 1) {
|
|
870
927
|
const account = storage.accounts[i];
|
|
871
928
|
if (!account)
|
|
@@ -884,6 +941,12 @@ export async function runFix(args, deps) {
|
|
|
884
941
|
let refreshAfterLiveProbeFailure = false;
|
|
885
942
|
if (options.live) {
|
|
886
943
|
const currentAccessToken = account.accessToken;
|
|
944
|
+
if (currentAccessToken &&
|
|
945
|
+
(await deps.reboundUnauthorizedAccountIdentity(account, currentAccessToken))) {
|
|
946
|
+
noteRebound(i);
|
|
947
|
+
}
|
|
948
|
+
if (currentAccessToken)
|
|
949
|
+
await checkMirror(i, currentAccessToken);
|
|
887
950
|
const probeAccountId = currentAccessToken
|
|
888
951
|
? account.accountId ?? extractAccountId(currentAccessToken)
|
|
889
952
|
: undefined;
|
|
@@ -962,6 +1025,10 @@ export async function runFix(args, deps) {
|
|
|
962
1025
|
deps.pruneUnsafeQuotaEmailCacheEntry(workingQuotaCache, previousEmail, storage.accounts, quotaEmailFallbackState) || quotaCacheChanged;
|
|
963
1026
|
}
|
|
964
1027
|
if (options.live) {
|
|
1028
|
+
if (await deps.reboundUnauthorizedAccountIdentity(account, refreshResult.access)) {
|
|
1029
|
+
noteRebound(i);
|
|
1030
|
+
}
|
|
1031
|
+
await checkMirror(i, refreshResult.access);
|
|
965
1032
|
const probeAccountId = account.accountId ?? nextAccountId;
|
|
966
1033
|
if (probeAccountId) {
|
|
967
1034
|
try {
|
|
@@ -1068,8 +1135,32 @@ export async function runFix(args, deps) {
|
|
|
1068
1135
|
refreshFailure: refreshFailures.get(index),
|
|
1069
1136
|
})));
|
|
1070
1137
|
const recommendation = recommendForecastAccount(forecastResults);
|
|
1138
|
+
for (const report of reports) {
|
|
1139
|
+
const mirrorUpdate = mirrorUpdates.get(report.index);
|
|
1140
|
+
if (mirrorUpdate === "set") {
|
|
1141
|
+
report.message = `explicit workspace is not authorized for these credentials; Codex CLI auth uses the backend default. ${report.message}`;
|
|
1142
|
+
}
|
|
1143
|
+
else if (mirrorUpdate === "cleared") {
|
|
1144
|
+
report.message = `explicit workspace is authorized again; Codex CLI auth uses it. ${report.message}`;
|
|
1145
|
+
}
|
|
1146
|
+
if (!reboundIndexes.has(report.index))
|
|
1147
|
+
continue;
|
|
1148
|
+
report.label = formatAccountLabel(storage.accounts[report.index], report.index);
|
|
1149
|
+
report.message = `workspace was not authorized for these credentials; rebound to the account's default identity. ${report.message}`;
|
|
1150
|
+
if (report.outcome === "healthy") {
|
|
1151
|
+
report.outcome = "rebound-unauthorized-workspace";
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1071
1154
|
const reportSummary = summarizeFixReports(reports);
|
|
1072
1155
|
const accountMutations = collectAccountStorageMutations(originalAccounts, storage.accounts);
|
|
1156
|
+
// ~/.codex/auth.json still carries the rejected id for the active account,
|
|
1157
|
+
// and Codex CLI keeps refusing it until something rewrites that file. The
|
|
1158
|
+
// mirror is taken from the committed snapshot, not this run's in-memory
|
|
1159
|
+
// view, and written while the storage lock is still held: another process
|
|
1160
|
+
// may switch the active account around this run, and a sync outside the
|
|
1161
|
+
// lock could put the old selection back into auth.json.
|
|
1162
|
+
let codexActiveSynced = null;
|
|
1163
|
+
let committedActiveIndex = activeIndex;
|
|
1073
1164
|
if (accountStorageChanged && !options.dryRun) {
|
|
1074
1165
|
await withAccountStorageTransaction(async (loadedStorage, persist) => {
|
|
1075
1166
|
const nextStorage = loadedStorage
|
|
@@ -1077,6 +1168,28 @@ export async function runFix(args, deps) {
|
|
|
1077
1168
|
: createEmptyAccountStorage();
|
|
1078
1169
|
applyAccountStorageMutations(nextStorage, accountMutations);
|
|
1079
1170
|
await persist(nextStorage);
|
|
1171
|
+
committedActiveIndex = deps.resolveActiveIndex(nextStorage, "codex");
|
|
1172
|
+
const committedActive = nextStorage.accounts[committedActiveIndex];
|
|
1173
|
+
const syncIndexes = [
|
|
1174
|
+
...reboundIndexes,
|
|
1175
|
+
...[...mirrorUpdates].filter(([, update]) => update).map(([index]) => index),
|
|
1176
|
+
];
|
|
1177
|
+
const isRebound = committedActive !== undefined &&
|
|
1178
|
+
syncIndexes.some((index) => {
|
|
1179
|
+
const rebound = storage.accounts[index];
|
|
1180
|
+
return (rebound !== undefined &&
|
|
1181
|
+
rebound.accountId === committedActive.accountId &&
|
|
1182
|
+
rebound.refreshToken === committedActive.refreshToken);
|
|
1183
|
+
});
|
|
1184
|
+
if (isRebound && committedActive.enabled !== false) {
|
|
1185
|
+
codexActiveSynced = await setCodexCliActiveSelection({
|
|
1186
|
+
accountId: codexCliAccountIdFor(committedActive, committedActive.accessToken),
|
|
1187
|
+
email: committedActive.email,
|
|
1188
|
+
accessToken: committedActive.accessToken,
|
|
1189
|
+
refreshToken: committedActive.refreshToken,
|
|
1190
|
+
expiresAt: committedActive.expiresAt,
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1080
1193
|
});
|
|
1081
1194
|
}
|
|
1082
1195
|
let quotaCacheSaveError = null;
|
|
@@ -1103,6 +1216,7 @@ export async function runFix(args, deps) {
|
|
|
1103
1216
|
changed,
|
|
1104
1217
|
quotaCacheChanged,
|
|
1105
1218
|
quotaCacheSaveError,
|
|
1219
|
+
codexActiveSynced,
|
|
1106
1220
|
summary: reportSummary,
|
|
1107
1221
|
recommendation,
|
|
1108
1222
|
recommendedSwitchCommand: recommendation.recommendedIndex !== null
|
|
@@ -1129,6 +1243,9 @@ export async function runFix(args, deps) {
|
|
|
1129
1243
|
if (quotaCacheSaveError) {
|
|
1130
1244
|
console.log(deps.stylePromptText(`Warning: quota cache save failed (${quotaCacheSaveError}); account fixes were saved.`, "warning"));
|
|
1131
1245
|
}
|
|
1246
|
+
if (codexActiveSynced === false) {
|
|
1247
|
+
console.log(deps.stylePromptText(`Warning: the rebound active account could not be synced into Codex auth state; run \`codex-multi-auth switch ${committedActiveIndex + 1}\` to retry.`, "warning"));
|
|
1248
|
+
}
|
|
1132
1249
|
if (display.showPerAccountRows) {
|
|
1133
1250
|
console.log("");
|
|
1134
1251
|
for (const report of reports) {
|
|
@@ -1136,14 +1253,16 @@ export async function runFix(args, deps) {
|
|
|
1136
1253
|
? "✓"
|
|
1137
1254
|
: report.outcome === "disabled-hard-failure"
|
|
1138
1255
|
? "✗"
|
|
1139
|
-
: report.outcome === "warning-soft-failure"
|
|
1256
|
+
: report.outcome === "warning-soft-failure" ||
|
|
1257
|
+
report.outcome === "rebound-unauthorized-workspace"
|
|
1140
1258
|
? "!"
|
|
1141
1259
|
: "-";
|
|
1142
1260
|
const tone = report.outcome === "healthy"
|
|
1143
1261
|
? "success"
|
|
1144
1262
|
: report.outcome === "disabled-hard-failure"
|
|
1145
1263
|
? "danger"
|
|
1146
|
-
: report.outcome === "warning-soft-failure"
|
|
1264
|
+
: report.outcome === "warning-soft-failure" ||
|
|
1265
|
+
report.outcome === "rebound-unauthorized-workspace"
|
|
1147
1266
|
? "warning"
|
|
1148
1267
|
: "muted";
|
|
1149
1268
|
console.log(`${deps.stylePromptText(prefix, tone)} ${deps.stylePromptText(`${report.index + 1}. ${report.label}`, "accent")} ${deps.stylePromptText("|", "muted")} ${deps.styleAccountDetailText(report.message, tone === "success" ? "muted" : tone)}`);
|
|
@@ -1233,6 +1352,7 @@ export async function runDoctor(args, deps) {
|
|
|
1233
1352
|
const codexConfigFileExists = existsSync(codexConfigPath);
|
|
1234
1353
|
let codexAuthEmail;
|
|
1235
1354
|
let codexAuthAccountId;
|
|
1355
|
+
let codexAuthFileAccountId;
|
|
1236
1356
|
addCheck({
|
|
1237
1357
|
key: "codex-auth-file",
|
|
1238
1358
|
severity: codexAuthFileExists ? "ok" : "warn",
|
|
@@ -1269,6 +1389,7 @@ export async function runDoctor(args, deps) {
|
|
|
1269
1389
|
: undefined;
|
|
1270
1390
|
const emailFromFile = typeof payload.email === "string" ? payload.email : undefined;
|
|
1271
1391
|
codexAuthEmail = sanitizeEmail(emailFromFile ?? extractAccountEmail(accessToken, idToken));
|
|
1392
|
+
codexAuthFileAccountId = accountIdFromFile;
|
|
1272
1393
|
codexAuthAccountId = accountIdFromFile ?? extractAccountId(accessToken);
|
|
1273
1394
|
addCheck({
|
|
1274
1395
|
key: "codex-auth-readable",
|
|
@@ -1553,9 +1674,23 @@ export async function runDoctor(args, deps) {
|
|
|
1553
1674
|
const isEmailMismatch = !!managerActiveEmail
|
|
1554
1675
|
&& !!codexActiveEmail
|
|
1555
1676
|
&& managerActiveEmail !== codexActiveEmail;
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1677
|
+
// A stored "org-..." id is written to auth.json as the token's
|
|
1678
|
+
// workspace id, while the legacy accounts.json keeps the raw id (#700).
|
|
1679
|
+
const codexActiveIdentity = codexCliState?.activeAccountId
|
|
1680
|
+
? codexCliActiveIdentity(codexCliState)
|
|
1681
|
+
: { accountId: codexActiveAccountId };
|
|
1682
|
+
// An org account_id in auth.json itself (written before #700) is
|
|
1683
|
+
// rejected by Codex CLI 0.156+, so it is never aligned.
|
|
1684
|
+
const isAccountIdMismatch = isOpenAiOrgId(codexAuthFileAccountId)
|
|
1685
|
+
|| (!!managerActiveAccountId
|
|
1686
|
+
&& !!codexActiveAccountId
|
|
1687
|
+
&& !codexAuthAccountIdsMatch({
|
|
1688
|
+
// As the writer would write it (CodexCliMirror applied).
|
|
1689
|
+
accountId: activeAccount
|
|
1690
|
+
? codexCliAccountIdFor(activeAccount, activeAccount.accessToken)
|
|
1691
|
+
: managerActiveAccountId,
|
|
1692
|
+
accessToken: activeAccount?.accessToken,
|
|
1693
|
+
}, codexActiveIdentity));
|
|
1559
1694
|
addCheck({
|
|
1560
1695
|
key: "active-selection-sync",
|
|
1561
1696
|
severity: isEmailMismatch || isAccountIdMismatch ? "warn" : "ok",
|
|
@@ -1627,7 +1762,7 @@ export async function runDoctor(args, deps) {
|
|
|
1627
1762
|
}
|
|
1628
1763
|
if (!options.dryRun && canSyncActiveAccount) {
|
|
1629
1764
|
pendingCodexActiveSync = {
|
|
1630
|
-
accountId: activeAccount
|
|
1765
|
+
accountId: codexCliAccountIdFor(activeAccount, syncAccessToken, syncIdToken),
|
|
1631
1766
|
email: activeAccount.email,
|
|
1632
1767
|
accessToken: syncAccessToken,
|
|
1633
1768
|
refreshToken: syncRefreshToken,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-manager.d.ts","sourceRoot":"","sources":["../../lib/codex-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-manager.d.ts","sourceRoot":"","sources":["../../lib/codex-manager.ts"],"names":[],"mappings":"AAsEA,OAAO,EAIN,yBAAyB,EACzB,MAAM,eAAe,CAAC;AA8BvB,OAAO,EAEN,mBAAmB,EAMnB,sBAAsB,EAGtB,MAAM,qCAAqC,CAAC;AA+B7C,OAAO,EAEN,KAAK,gBAAgB,EAWrB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;AA8IvD,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,OAAO,CAAC,CAyGrE;AACD,mFAAmF;AACnF,wBAAgB,wBAAwB,IAAI,CAC3C,OAAO,EAAE,gBAAgB,KACrB,OAAO,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAwEzD;AAyQD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C7E"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { runResetsCommand } from "./codex-manager/commands/resets.js";
|
|
2
|
+
import { loadResetCreditState } from "./runtime/account-reset-credits.js";
|
|
3
|
+
import { loadApiRoutes } from "./api-route-store.js";
|
|
4
|
+
import { loadInferenceRequestTimes } from "./runtime/inference-activity.js";
|
|
5
|
+
import { loadModelInventory, refreshAndPrintModelInventory } from "./runtime/model-discovery-status.js";
|
|
1
6
|
import { AUTH_INVALIDATION_MARKER, AccountManager, extractAccountEmail, extractAccountId, formatAccountLabel, formatWaitTime, sanitizeEmail, } from "./accounts.js";
|
|
7
|
+
import { reboundUnauthorizedAccountIdentity, refreshCodexCliMirror, } from "./auth/account-access.js";
|
|
8
|
+
import { codexCliAccountIdFor } from "./auth/token-utils.js";
|
|
2
9
|
import { loadCodexCliState } from "./codex-cli/state.js";
|
|
3
10
|
import { setCodexCliActiveSelection } from "./codex-cli/writer.js";
|
|
4
11
|
import { parseBestArgs, printBestUsage, runBestCommand, } from "./codex-manager/commands/best.js";
|
|
@@ -27,6 +34,7 @@ import { evaluateRuntimePolicy, loadRuntimePolicyState, } from "./policy/runtime
|
|
|
27
34
|
import { CURRENT_CODEX_MODEL } from "./request/helpers/model-map.js";
|
|
28
35
|
import { runDoctor as runRepairDoctor, runFix as runRepairFix, runVerifyFlagged as runRepairVerifyFlagged, } from "./codex-manager/repair-commands.js";
|
|
29
36
|
import { runUninstallCommand } from "./codex-manager/commands/uninstall.js";
|
|
37
|
+
import { clearAccountsAndCredentialSidecars } from "./storage/credential-sidecars.js";
|
|
30
38
|
import { runForecastCommand } from "./codex-manager/commands/forecast.js";
|
|
31
39
|
import { runInitConfigCommand } from "./codex-manager/commands/init-config.js";
|
|
32
40
|
import { runReportCommand } from "./codex-manager/commands/report.js";
|
|
@@ -73,6 +81,8 @@ function createRepairCommandDeps() {
|
|
|
73
81
|
formatCompactQuotaSnapshot,
|
|
74
82
|
resolveStoredAccountIdentity,
|
|
75
83
|
applyTokenAccountIdentity,
|
|
84
|
+
reboundUnauthorizedAccountIdentity,
|
|
85
|
+
refreshCodexCliMirror,
|
|
76
86
|
};
|
|
77
87
|
}
|
|
78
88
|
const IMPLEMENTED_FEATURES = [
|
|
@@ -210,7 +220,6 @@ export async function autoSyncActiveAccountToCodex() {
|
|
|
210
220
|
let syncRefreshToken = account.refreshToken;
|
|
211
221
|
let syncExpiresAt = account.expiresAt;
|
|
212
222
|
let syncIdToken;
|
|
213
|
-
let syncAccountId = account.accountId;
|
|
214
223
|
let syncEmail = account.email;
|
|
215
224
|
let changed = false;
|
|
216
225
|
let nextStoredAccount = null;
|
|
@@ -245,7 +254,6 @@ export async function autoSyncActiveAccountToCodex() {
|
|
|
245
254
|
syncRefreshToken = refreshResult.refresh;
|
|
246
255
|
syncExpiresAt = refreshResult.expires;
|
|
247
256
|
syncIdToken = refreshResult.idToken;
|
|
248
|
-
syncAccountId = nextStoredAccount.accountId;
|
|
249
257
|
syncEmail = nextStoredAccount.email;
|
|
250
258
|
}
|
|
251
259
|
if (changed && nextStoredAccount) {
|
|
@@ -273,7 +281,7 @@ export async function autoSyncActiveAccountToCodex() {
|
|
|
273
281
|
}
|
|
274
282
|
}
|
|
275
283
|
return setCodexCliActiveSelection({
|
|
276
|
-
accountId:
|
|
284
|
+
accountId: codexCliAccountIdFor(nextStoredAccount ?? account, syncAccessToken, syncIdToken),
|
|
277
285
|
email: syncEmail,
|
|
278
286
|
accessToken: syncAccessToken,
|
|
279
287
|
refreshToken: syncRefreshToken,
|
|
@@ -349,6 +357,10 @@ export function buildSelectAccountTraced() {
|
|
|
349
357
|
* Shared handler for `list` and `status` (aliases of the same view).
|
|
350
358
|
*/
|
|
351
359
|
const runListOrStatusCommand = (rest) => runStatusCommand({
|
|
360
|
+
loadApiRoutes,
|
|
361
|
+
loadResetCreditState,
|
|
362
|
+
loadInferenceRequestTimes,
|
|
363
|
+
loadModelInventory,
|
|
352
364
|
setStoragePath,
|
|
353
365
|
getStoragePath,
|
|
354
366
|
loadAccounts,
|
|
@@ -357,7 +369,7 @@ const runListOrStatusCommand = (rest) => runStatusCommand({
|
|
|
357
369
|
formatRateLimitEntry,
|
|
358
370
|
loadRuntimeObservabilitySnapshot: loadPersistedRuntimeObservabilitySnapshot,
|
|
359
371
|
loadAppBindStatus: async () => getAppBindStatus()
|
|
360
|
-
.then((status) => (status.running ? status.router : null))
|
|
372
|
+
.then((status) => (status.running && status.router ? { ...status.router, nativeOpenai: status.state?.nativeOpenai === true } : null))
|
|
361
373
|
.catch(() => null),
|
|
362
374
|
loadAppHelperStatus: readAppRuntimeHelperAccountSignal,
|
|
363
375
|
loadQuotaCache,
|
|
@@ -413,7 +425,11 @@ const CLI_COMMAND_HANDLERS = new Map([
|
|
|
413
425
|
saveAccounts,
|
|
414
426
|
}),
|
|
415
427
|
],
|
|
416
|
-
["check", () => runCheckCommand({
|
|
428
|
+
["check", (rest) => runCheckCommand({
|
|
429
|
+
runHealthCheck,
|
|
430
|
+
runResetCheck: () => runResetsCommand(["list", "--refresh"]),
|
|
431
|
+
runCapabilityCheck: () => refreshAndPrintModelInventory(console.log, { forceProbes: true }),
|
|
432
|
+
}, rest)],
|
|
417
433
|
[
|
|
418
434
|
"features",
|
|
419
435
|
() => runFeaturesCommand({ implementedFeatures: IMPLEMENTED_FEATURES }),
|
|
@@ -468,6 +484,7 @@ const CLI_COMMAND_HANDLERS = new Map([
|
|
|
468
484
|
}),
|
|
469
485
|
],
|
|
470
486
|
["usage", (rest) => runUsageCommand(rest)],
|
|
487
|
+
["resets", (rest) => runResetsCommand(rest)],
|
|
471
488
|
[
|
|
472
489
|
"rotation",
|
|
473
490
|
(rest) => runRotationCommand(rest, {
|
|
@@ -531,7 +548,9 @@ const CLI_COMMAND_HANDLERS = new Map([
|
|
|
531
548
|
],
|
|
532
549
|
["fix", (rest) => runRepairFix(rest, createRepairCommandDeps())],
|
|
533
550
|
["doctor", (rest) => runRepairDoctor(rest, createRepairCommandDeps())],
|
|
534
|
-
["uninstall", (rest) => runUninstallCommand(rest, {
|
|
551
|
+
["uninstall", (rest) => runUninstallCommand(rest, {
|
|
552
|
+
clearAccounts: () => clearAccountsAndCredentialSidecars(clearAccounts),
|
|
553
|
+
})],
|
|
535
554
|
[
|
|
536
555
|
"config",
|
|
537
556
|
(rest) => {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Bounded independent work, refilling free slots immediately and preserving result order. */
|
|
2
|
+
export declare function mapWithConcurrency<T, R>(items: readonly T[], limit: number, worker: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
3
|
+
//# sourceMappingURL=concurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrency.d.ts","sourceRoot":"","sources":["../../lib/concurrency.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CA6B/I"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Bounded independent work, refilling free slots immediately and preserving result order. */
|
|
2
|
+
export async function mapWithConcurrency(items, limit, worker) {
|
|
3
|
+
if (!Number.isInteger(limit) || limit < 1)
|
|
4
|
+
throw new RangeError("Concurrency must be a positive integer");
|
|
5
|
+
const results = new Array(items.length);
|
|
6
|
+
let next = 0;
|
|
7
|
+
let failed = false;
|
|
8
|
+
let failure;
|
|
9
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
10
|
+
while (!failed) {
|
|
11
|
+
const index = next++;
|
|
12
|
+
if (index >= items.length)
|
|
13
|
+
return;
|
|
14
|
+
const item = items[index];
|
|
15
|
+
if (item === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
results[index] = await worker(item, index);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!failed)
|
|
22
|
+
failure = error;
|
|
23
|
+
failed = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
// Drain active work before returning an error, so no detached writes survive the caller.
|
|
28
|
+
if (failed)
|
|
29
|
+
throw failure;
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* behavior (see the v2.5.0 release notes) closely enough to launch that no
|
|
7
7
|
* estimate here has been reviewed for it yet.
|
|
8
8
|
*/
|
|
9
|
-
export declare const UNESTIMATED_ROUTABLE_MODELS: readonly ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-6-astra", "gpt-6-astra-aeon", "gpt-daybreak-blue-latest", "gpt-daybreak-red-latest"];
|
|
9
|
+
export declare const UNESTIMATED_ROUTABLE_MODELS: readonly ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-6-astra", "gpt-6-astra-aeon", "gpt-6-sol", "gpt-6-luna", "gpt-daybreak-blue-latest", "gpt-daybreak-red-latest"];
|
|
10
10
|
export interface EffectiveContextWindow {
|
|
11
11
|
tokens: number;
|
|
12
12
|
source: "override" | "estimate";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-context-windows.d.ts","sourceRoot":"","sources":["../../../lib/context-budget/model-context-windows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-context-windows.d.ts","sourceRoot":"","sources":["../../../lib/context-budget/model-context-windows.ts"],"names":[],"mappings":"AAoCA;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,gLAoB9B,CAAC;AAgCX,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,sBAAsB,GAAG,IAAI,CA0B/B;AAED,wBAAgB,gCAAgC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzE"}
|
|
@@ -22,19 +22,14 @@ import { getNormalizedModel } from "../request/helpers/model-map.js";
|
|
|
22
22
|
* in doubt about a model's real ceiling, leave it out of this table and add
|
|
23
23
|
* it to UNESTIMATED_ROUTABLE_MODELS instead.
|
|
24
24
|
*/
|
|
25
|
+
//
|
|
26
|
+
// Retired models (`gpt-5.1` through `gpt-5.4-*`, `gpt-5-mini`/`nano`, the codex
|
|
27
|
+
// models) are deliberately absent. Their ids now route to a replacement, and
|
|
28
|
+
// estimating the window from the retired name would evaluate a request against
|
|
29
|
+
// a model it no longer runs on.
|
|
25
30
|
const ESTIMATED_MODEL_CONTEXT_WINDOWS = {
|
|
26
|
-
"gpt-5.1": 260_000,
|
|
27
|
-
"gpt-5.2": 260_000,
|
|
28
|
-
"gpt-5.2-pro": 260_000,
|
|
29
|
-
"gpt-5.3-codex": 260_000,
|
|
30
|
-
"gpt-5.4": 260_000,
|
|
31
|
-
"gpt-5.4-mini": 260_000,
|
|
32
|
-
"gpt-5.4-nano": 260_000,
|
|
33
|
-
"gpt-5.4-pro": 260_000,
|
|
34
31
|
"gpt-5.5": 260_000,
|
|
35
32
|
"gpt-5.5-pro": 260_000,
|
|
36
|
-
"gpt-5-mini": 260_000,
|
|
37
|
-
"gpt-5-nano": 260_000,
|
|
38
33
|
};
|
|
39
34
|
/**
|
|
40
35
|
* Routable models this guard consciously does not estimate a window for.
|
|
@@ -58,6 +53,10 @@ export const UNESTIMATED_ROUTABLE_MODELS = [
|
|
|
58
53
|
// `contextBudgetGuardModelWindowOverrides` once you know your real ceiling.
|
|
59
54
|
"gpt-6-astra",
|
|
60
55
|
"gpt-6-astra-aeon",
|
|
56
|
+
// Sol and Luna carry the same 272K Codex / 872K max split in the upstream
|
|
57
|
+
// catalog as Astra, so the same reasoning keeps them unestimated.
|
|
58
|
+
"gpt-6-sol",
|
|
59
|
+
"gpt-6-luna",
|
|
61
60
|
"gpt-daybreak-blue-latest",
|
|
62
61
|
"gpt-daybreak-red-latest",
|
|
63
62
|
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Model selection is the explicit routing signal; never infer a privacy route from prompt text. */
|
|
2
|
+
export type ModelRouteKind = "oauth" | "api" | "zdr";
|
|
3
|
+
export type RouteModel = Record<string, unknown> & {
|
|
4
|
+
slug: string;
|
|
5
|
+
};
|
|
6
|
+
export interface RouteCatalog {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: ModelRouteKind;
|
|
9
|
+
priority: number;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
models: RouteModel[];
|
|
12
|
+
/** API credentials expose nothing until the user chooses an allowlist. */
|
|
13
|
+
visibleModels: string[] | null;
|
|
14
|
+
}
|
|
15
|
+
export interface ResolvedModelRoute {
|
|
16
|
+
kind: ModelRouteKind;
|
|
17
|
+
upstreamModel: string;
|
|
18
|
+
candidates: RouteCatalog[];
|
|
19
|
+
serviceTier?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function parseModelRoute(model: string): {
|
|
22
|
+
kind: ModelRouteKind;
|
|
23
|
+
upstreamModel: string;
|
|
24
|
+
serviceTier?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function modelServiceTiers(model: RouteModel): Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function canonicalServiceTier(tier: string): string;
|
|
32
|
+
export declare function supportsModelSettings(model: RouteModel, reasoningEffort?: string, serviceTier?: string): boolean;
|
|
33
|
+
export declare function resolveModelRoute(model: string, catalogs: RouteCatalog[], settings?: {
|
|
34
|
+
reasoningEffort?: string;
|
|
35
|
+
serviceTier?: string;
|
|
36
|
+
}): ResolvedModelRoute;
|
|
37
|
+
export declare function buildVisibleModelUnion(catalogs: RouteCatalog[]): RouteModel[];
|
|
38
|
+
/** Whitelist capability metadata; never persist model instructions or arbitrary fields. */
|
|
39
|
+
export declare function modelEntitlements(model: RouteModel): {
|
|
40
|
+
serviceTiers: {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
}[];
|
|
44
|
+
reasoningLevels: string[];
|
|
45
|
+
accessPrograms: string[];
|
|
46
|
+
probes?: {
|
|
47
|
+
[k: string]: "unsupported" | "verified" | "unverified" | "downgraded";
|
|
48
|
+
} | undefined;
|
|
49
|
+
checkedAt?: number | undefined;
|
|
50
|
+
model: string;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=model-route-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-route-policy.d.ts","sourceRoot":"","sources":["../../lib/model-route-policy.ts"],"names":[],"mappings":"AAEA,oGAAoG;AACpG,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;AACrD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACpE,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,0EAA0E;IAC1E,aAAa,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC/B;AACD,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,cAAc,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AACD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG;IAC/C,IAAI,EAAE,cAAc,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAwBA;AACD,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,UAAU,GACf,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAY1D;AACD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AACD,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,UAAU,EACjB,eAAe,CAAC,EAAE,MAAM,EACxB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAcT;AAeD,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,YAAY,EAAE,EACxB,QAAQ,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/D,kBAAkB,CAuBpB;AACD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,CAyC7E;AAED,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU;;;;;;;;;;;;EAiDlD"}
|