codex-multi-auth 2.17.0 → 2.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +9 -9
- package/LICENSE +21 -21
- package/README.md +142 -484
- 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 +0 -1
- package/dist/lib/account-policy.d.ts +18 -2
- package/dist/lib/account-policy.js +97 -40
- package/dist/lib/accounts/rate-limits.d.ts +0 -1
- package/dist/lib/accounts.d.ts +1 -8
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +7 -19
- package/dist/lib/api-route-store.d.ts +0 -1
- package/dist/lib/audit.d.ts +0 -1
- package/dist/lib/audit.js +43 -12
- package/dist/lib/auth/account-access.d.ts +0 -1
- package/dist/lib/auth/account-access.js +5 -1
- package/dist/lib/auth/auth.d.ts +4 -3
- package/dist/lib/auth/auth.js +220 -28
- package/dist/lib/auth/browser.d.ts +0 -1
- package/dist/lib/auth/callback-guidance.d.ts +0 -1
- package/dist/lib/auth/device-auth.d.ts +0 -1
- package/dist/lib/auth/index.d.ts +0 -1
- package/dist/lib/auth/org-override.d.ts +0 -1
- package/dist/lib/auth/server.d.ts +1 -2
- package/dist/lib/auth/server.js +100 -53
- package/dist/lib/auth/token-utils.d.ts +0 -1
- package/dist/lib/auth-rate-limit.d.ts +0 -1
- package/dist/lib/budget-guard.d.ts +16 -2
- package/dist/lib/budget-guard.js +123 -43
- package/dist/lib/capability-policy.d.ts +0 -1
- package/dist/lib/circuit-breaker.d.ts +20 -1
- package/dist/lib/circuit-breaker.js +24 -5
- package/dist/lib/cli.d.ts +0 -1
- package/dist/lib/codex-cli/index.d.ts +0 -1
- package/dist/lib/codex-cli/observability.d.ts +0 -1
- package/dist/lib/codex-cli/state.d.ts +0 -1
- package/dist/lib/codex-cli/sync.d.ts +0 -1
- package/dist/lib/codex-cli/writer.d.ts +0 -1
- package/dist/lib/codex-manager/account-credentials.d.ts +0 -1
- package/dist/lib/codex-manager/account-manager-commands.d.ts +0 -1
- package/dist/lib/codex-manager/account-pool-write.d.ts +0 -1
- package/dist/lib/codex-manager/active-account-sync.d.ts +6 -0
- package/dist/lib/codex-manager/active-account-sync.js +336 -0
- package/dist/lib/codex-manager/api-login-menu.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-entry.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-helpers.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-schema.d.ts +0 -1
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/commands/account.d.ts +8 -3
- package/dist/lib/codex-manager/commands/account.js +46 -34
- package/dist/lib/codex-manager/commands/best.d.ts +0 -1
- package/dist/lib/codex-manager/commands/bridge.d.ts +0 -1
- package/dist/lib/codex-manager/commands/budget.d.ts +8 -3
- package/dist/lib/codex-manager/commands/budget.js +6 -4
- package/dist/lib/codex-manager/commands/check.d.ts +0 -1
- package/dist/lib/codex-manager/commands/config-explain.d.ts +0 -1
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts +0 -1
- package/dist/lib/codex-manager/commands/forecast.d.ts +1 -2
- package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/forecast.js +2 -2
- package/dist/lib/codex-manager/commands/history.d.ts +0 -1
- package/dist/lib/codex-manager/commands/init-config.d.ts +0 -1
- package/dist/lib/codex-manager/commands/integrations.d.ts +0 -1
- package/dist/lib/codex-manager/commands/limits.d.ts +0 -1
- package/dist/lib/codex-manager/commands/models.d.ts +0 -1
- package/dist/lib/codex-manager/commands/monitor.d.ts +0 -1
- package/dist/lib/codex-manager/commands/report.d.ts +0 -1
- package/dist/lib/codex-manager/commands/resets.d.ts +0 -1
- package/dist/lib/codex-manager/commands/resets.js +9 -1
- package/dist/lib/codex-manager/commands/rotation.d.ts +0 -1
- package/dist/lib/codex-manager/commands/status.d.ts +0 -1
- package/dist/lib/codex-manager/commands/switch.d.ts +0 -1
- package/dist/lib/codex-manager/commands/uninstall.d.ts +0 -1
- package/dist/lib/codex-manager/commands/unpin.d.ts +0 -1
- package/dist/lib/codex-manager/commands/usage.d.ts +0 -1
- package/dist/lib/codex-manager/commands/verify.d.ts +0 -1
- package/dist/lib/codex-manager/commands/why-selected.d.ts +0 -1
- package/dist/lib/codex-manager/commands/workspace.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-sync-target.d.ts +0 -1
- package/dist/lib/codex-manager/forecast-report-shared.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/account-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/index.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/model-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/quota-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/text-style.d.ts +0 -1
- package/dist/lib/codex-manager/health-check.d.ts +0 -1
- package/dist/lib/codex-manager/health-check.js +1 -1
- package/dist/lib/codex-manager/help.d.ts +0 -1
- package/dist/lib/codex-manager/login-action-panel.d.ts +0 -1
- package/dist/lib/codex-manager/login-flow.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-actions.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-data.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-data.d.ts.map +1 -1
- package/dist/lib/codex-manager/login-menu-data.js +7 -3
- package/dist/lib/codex-manager/login-oauth.d.ts +0 -1
- package/dist/lib/codex-manager/login-workspace-choice.d.ts +0 -1
- package/dist/lib/codex-manager/manual-callback.d.ts +0 -1
- package/dist/lib/codex-manager/persist-selected-account.d.ts +0 -1
- package/dist/lib/codex-manager/quota-cache-helpers.d.ts +7 -2
- 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/rate-limit-markers.d.ts +0 -1
- package/dist/lib/codex-manager/repair-commands.d.ts +0 -1
- package/dist/lib/codex-manager/repair-commands.js +1 -1
- package/dist/lib/codex-manager/settings-hub/backend.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/dashboard.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/experimental.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/index.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/shared.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-entry.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-menu.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub.d.ts +0 -1
- package/dist/lib/codex-manager/settings-panels.d.ts +0 -1
- package/dist/lib/codex-manager/settings-persist-utils.d.ts +0 -1
- package/dist/lib/codex-manager/settings-preview.d.ts +0 -1
- package/dist/lib/codex-manager/settings-write-queue.d.ts +0 -1
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/theme-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/unified-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/unified-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager.d.ts +1 -2
- package/dist/lib/codex-manager.js +5 -95
- package/dist/lib/concurrency.d.ts +0 -1
- package/dist/lib/config-schema.d.ts +0 -1
- package/dist/lib/config.d.ts +0 -1
- package/dist/lib/config.js +46 -241
- package/dist/lib/constants.d.ts +0 -1
- package/dist/lib/context-budget/model-context-windows.d.ts +0 -1
- package/dist/lib/context-budget-guard.d.ts +0 -1
- package/dist/lib/context-budget-response.d.ts +0 -1
- package/dist/lib/context-budget-response.js +8 -8
- package/dist/lib/context-overflow.d.ts +0 -1
- package/dist/lib/context-overflow.js +10 -10
- package/dist/lib/dashboard-settings.d.ts +0 -1
- package/dist/lib/entitlement-cache.d.ts +0 -1
- package/dist/lib/env-parsing.d.ts +13 -1
- package/dist/lib/env-parsing.js +21 -0
- package/dist/lib/errors.d.ts +0 -1
- package/dist/lib/forecast.d.ts +0 -1
- package/dist/lib/fs-retry.d.ts +0 -1
- package/dist/lib/health.d.ts +0 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/integration-generators.d.ts +0 -1
- package/dist/lib/live-account-sync.d.ts +0 -1
- package/dist/lib/local-bridge.d.ts +0 -1
- package/dist/lib/local-bridge.js +4 -1
- package/dist/lib/local-client-tokens.d.ts +0 -1
- package/dist/lib/local-client-tokens.js +125 -30
- package/dist/lib/logger.d.ts +0 -1
- package/dist/lib/logger.js +11 -1
- package/dist/lib/model-capability-matrix.d.ts +0 -1
- package/dist/lib/model-route-policy.d.ts +1 -2
- package/dist/lib/named-backup-export.d.ts +0 -1
- package/dist/lib/oauth-success.html +125 -125
- package/dist/lib/oc-chatgpt-import-adapter.d.ts +0 -1
- package/dist/lib/oc-chatgpt-orchestrator.d.ts +0 -1
- package/dist/lib/oc-chatgpt-target-detection.d.ts +0 -1
- package/dist/lib/parallel-probe.d.ts +0 -1
- package/dist/lib/policy/runtime-policy-cache.d.ts +80 -0
- package/dist/lib/policy/runtime-policy-cache.js +310 -0
- package/dist/lib/policy/runtime-policy.d.ts +1 -2
- package/dist/lib/policy/runtime-policy.js +46 -19
- package/dist/lib/preemptive-quota-scheduler.d.ts +0 -1
- package/dist/lib/proactive-refresh.d.ts +0 -1
- package/dist/lib/prompts/codex-host-bridge.d.ts +0 -1
- package/dist/lib/prompts/codex-host-bridge.js +138 -138
- package/dist/lib/prompts/codex.d.ts +0 -1
- package/dist/lib/prompts/codex.js +79 -79
- package/dist/lib/prompts/fetch-utils.d.ts +0 -1
- package/dist/lib/prompts/host-codex-prompt.d.ts +0 -1
- package/dist/lib/quota-cache.d.ts +7 -4
- package/dist/lib/quota-cache.d.ts.map +1 -1
- package/dist/lib/quota-cache.js +117 -61
- package/dist/lib/quota-probe.d.ts +0 -1
- package/dist/lib/quota-probe.js +5 -2
- package/dist/lib/quota-readiness.d.ts +7 -3
- package/dist/lib/quota-readiness.d.ts.map +1 -1
- package/dist/lib/quota-readiness.js +25 -4
- package/dist/lib/recovery/constants.d.ts +0 -1
- package/dist/lib/recovery/storage.d.ts +0 -1
- package/dist/lib/recovery/types.d.ts +0 -1
- package/dist/lib/recovery.d.ts +0 -1
- package/dist/lib/redaction.d.ts +0 -1
- package/dist/lib/refresh-guardian.d.ts +0 -1
- package/dist/lib/refresh-lease.d.ts +0 -1
- package/dist/lib/refresh-queue.d.ts +0 -1
- package/dist/lib/request/client-cancellation.d.ts +0 -1
- package/dist/lib/request/error-classification.d.ts +0 -1
- package/dist/lib/request/failover-config.d.ts +0 -1
- package/dist/lib/request/failure-policy.d.ts +0 -1
- package/dist/lib/request/fetch-helpers.d.ts +0 -1
- package/dist/lib/request/headers.d.ts +0 -1
- package/dist/lib/request/helpers/input-utils.d.ts +0 -1
- package/dist/lib/request/helpers/input-utils.js +88 -34
- package/dist/lib/request/helpers/model-map.d.ts +0 -1
- package/dist/lib/request/helpers/tool-utils.d.ts +0 -1
- package/dist/lib/request/helpers/tool-utils.js +421 -4
- package/dist/lib/request/index.d.ts +0 -1
- package/dist/lib/request/rate-limit-backoff.d.ts +0 -1
- package/dist/lib/request/rate-limit-decision.d.ts +0 -1
- package/dist/lib/request/request-attempt-budget.d.ts +0 -1
- package/dist/lib/request/request-init.d.ts +0 -1
- package/dist/lib/request/request-resilience.d.ts +0 -1
- package/dist/lib/request/request-transformer.d.ts +0 -1
- package/dist/lib/request/request-transformer.js +50 -25
- package/dist/lib/request/response-compaction.d.ts +0 -1
- package/dist/lib/request/response-handler.d.ts +0 -1
- package/dist/lib/request/response-metadata.d.ts +0 -1
- package/dist/lib/request/response-outcome.d.ts +0 -1
- package/dist/lib/request/stream-failover-runtime.d.ts +0 -1
- package/dist/lib/request/stream-failover.d.ts +0 -1
- package/dist/lib/request/stream-failover.js +28 -4
- package/dist/lib/request/token-refresh.d.ts +0 -1
- package/dist/lib/request/url-rewriting.d.ts +0 -1
- package/dist/lib/request/wait-utils.d.ts +0 -1
- package/dist/lib/rotation.d.ts +0 -1
- package/dist/lib/routing-mutex.d.ts +0 -1
- package/dist/lib/routing-profiles.d.ts +16 -2
- package/dist/lib/routing-profiles.js +119 -44
- package/dist/lib/runtime/account-check-helpers.d.ts +0 -1
- package/dist/lib/runtime/account-check-types.d.ts +0 -1
- package/dist/lib/runtime/account-check.d.ts +0 -1
- package/dist/lib/runtime/account-manager-cache-entry.d.ts +0 -1
- package/dist/lib/runtime/account-manager-cache.d.ts +0 -1
- package/dist/lib/runtime/account-model-catalog.d.ts +1 -2
- package/dist/lib/runtime/account-pool.d.ts +0 -1
- package/dist/lib/runtime/account-reset-credits.d.ts +0 -1
- package/dist/lib/runtime/account-reset-credits.js +8 -2
- package/dist/lib/runtime/account-scope.d.ts +0 -1
- package/dist/lib/runtime/account-select-event.d.ts +0 -1
- package/dist/lib/runtime/account-selection.d.ts +0 -1
- package/dist/lib/runtime/account-state.d.ts +0 -1
- package/dist/lib/runtime/account-status.d.ts +0 -1
- package/dist/lib/runtime/account-storage-scope-entry.d.ts +0 -1
- package/dist/lib/runtime/api-model-capabilities.d.ts +0 -1
- package/dist/lib/runtime/api-model-runtime.d.ts +0 -1
- package/dist/lib/runtime/app-bind.d.ts +0 -1
- package/dist/lib/runtime/app-bind.d.ts.map +1 -1
- package/dist/lib/runtime/app-bind.js +10 -2
- package/dist/lib/runtime/app-helper-selection.d.ts +0 -1
- package/dist/lib/runtime/auth-facade.d.ts +0 -1
- package/dist/lib/runtime/automatic-account-checks.d.ts +5 -2
- package/dist/lib/runtime/automatic-account-checks.d.ts.map +1 -1
- package/dist/lib/runtime/automatic-account-checks.js +29 -2
- package/dist/lib/runtime/automatic-subscription-checks.d.ts +1 -2
- package/dist/lib/runtime/automatic-subscription-checks.d.ts.map +1 -1
- package/dist/lib/runtime/automatic-subscription-checks.js +13 -16
- package/dist/lib/runtime/browser-oauth-flow.d.ts +0 -1
- package/dist/lib/runtime/capability-boost.d.ts +0 -1
- package/dist/lib/runtime/catalog-capabilities.d.ts +0 -1
- package/dist/lib/runtime/config-toml.d.ts +0 -1
- package/dist/lib/runtime/context-budget-settings.d.ts +0 -1
- package/dist/lib/runtime/event-handler.d.ts +0 -1
- package/dist/lib/runtime/first-run.d.ts +0 -1
- package/dist/lib/runtime/flagged-verify-types.d.ts +0 -1
- package/dist/lib/runtime/hydrate-emails.d.ts +0 -1
- package/dist/lib/runtime/inference-activity.d.ts +0 -1
- package/dist/lib/runtime/live-sync-entry.d.ts +0 -1
- package/dist/lib/runtime/live-sync.d.ts +0 -1
- package/dist/lib/runtime/loader-setup.d.ts +0 -1
- package/dist/lib/runtime/login-menu-accounts.d.ts +0 -1
- package/dist/lib/runtime/manual-oauth-flow.d.ts +0 -1
- package/dist/lib/runtime/model-discovery-status.d.ts +2 -3
- package/dist/lib/runtime/native-account-storage.d.ts +0 -1
- package/dist/lib/runtime/native-account-sync.d.ts +0 -1
- package/dist/lib/runtime/native-binding-lock.d.ts +0 -1
- package/dist/lib/runtime/native-client-auth.d.ts +0 -1
- package/dist/lib/runtime/native-provider-config.d.ts +0 -1
- package/dist/lib/runtime/native-rate-limits.d.ts +2 -1
- package/dist/lib/runtime/native-rate-limits.js +23 -6
- package/dist/lib/runtime/preemptive-quota.d.ts +0 -1
- package/dist/lib/runtime/quota-headers.d.ts +0 -1
- package/dist/lib/runtime/quota-probe.d.ts +0 -1
- package/dist/lib/runtime/quota-settings.d.ts +0 -1
- package/dist/lib/runtime/refresh-guardian-entry.d.ts +0 -1
- package/dist/lib/runtime/refresh-guardian.d.ts +0 -1
- package/dist/lib/runtime/request-init.d.ts +0 -1
- package/dist/lib/runtime/reset-credit-routing.d.ts +0 -1
- package/dist/lib/runtime/reset-credits.d.ts +0 -1
- package/dist/lib/runtime/response-output-history.d.ts +0 -1
- package/dist/lib/runtime/responses-websocket.d.ts +0 -1
- package/dist/lib/runtime/resume-picker.d.ts +0 -1
- package/dist/lib/runtime/rotation-account-selection.d.ts +0 -1
- package/dist/lib/runtime/rotation-proxy-state.d.ts +0 -1
- package/dist/lib/runtime/rotation-server-types.d.ts +0 -1
- package/dist/lib/runtime/rotation-storage-meta.d.ts +0 -1
- package/dist/lib/runtime/rotation-token-refresh.d.ts +0 -1
- package/dist/lib/runtime/runtime-capability-failures.d.ts +0 -1
- package/dist/lib/runtime/runtime-current-account.d.ts +0 -1
- package/dist/lib/runtime/runtime-observability.d.ts +0 -1
- package/dist/lib/runtime/runtime-services.d.ts +0 -1
- package/dist/lib/runtime/session-affinity-entry.d.ts +0 -1
- package/dist/lib/runtime/session-recovery.d.ts +0 -1
- package/dist/lib/runtime/status-marker.d.ts +0 -1
- package/dist/lib/runtime/storage-scope.d.ts +0 -1
- package/dist/lib/runtime/subscription-first-use.d.ts +0 -1
- package/dist/lib/runtime/subscription-quota-event.d.ts +0 -1
- package/dist/lib/runtime/subscription-quota-order.d.ts +0 -1
- package/dist/lib/runtime/toast.d.ts +0 -1
- package/dist/lib/runtime/ui-runtime-entry.d.ts +0 -1
- package/dist/lib/runtime/ui-runtime.d.ts +0 -1
- package/dist/lib/runtime/verify-flagged.d.ts +0 -1
- package/dist/lib/runtime/workspace-model-scopes.d.ts +0 -1
- package/dist/lib/runtime-constants.d.ts +0 -1
- package/dist/lib/runtime-paths.d.ts +0 -1
- package/dist/lib/runtime-rotation-proxy.d.ts +1 -1
- package/dist/lib/runtime-rotation-proxy.js +136 -3
- package/dist/lib/schemas.d.ts +35 -13
- package/dist/lib/schemas.js +19 -2
- package/dist/lib/session-affinity.d.ts +0 -1
- package/dist/lib/shutdown.d.ts +0 -1
- package/dist/lib/storage/account-clear-entry.d.ts +0 -1
- package/dist/lib/storage/account-clear.d.ts +0 -1
- package/dist/lib/storage/account-match-utils.d.ts +0 -1
- package/dist/lib/storage/account-persistence.d.ts +0 -1
- package/dist/lib/storage/account-port.d.ts +0 -1
- package/dist/lib/storage/account-save-entry.d.ts +0 -1
- package/dist/lib/storage/account-save.d.ts +9 -2
- package/dist/lib/storage/account-save.js +4 -1
- package/dist/lib/storage/account-snapshot.d.ts +0 -1
- package/dist/lib/storage/backup-metadata-builder.d.ts +0 -1
- package/dist/lib/storage/backup-metadata.d.ts +0 -1
- package/dist/lib/storage/backup-paths.d.ts +0 -1
- package/dist/lib/storage/backup-restore.d.ts +0 -1
- package/dist/lib/storage/cache-artifacts.d.ts +0 -1
- package/dist/lib/storage/credential-sidecars.d.ts +0 -1
- package/dist/lib/storage/error-hints.d.ts +0 -1
- package/dist/lib/storage/file-lock.d.ts +0 -1
- package/dist/lib/storage/file-lock.js +33 -1
- package/dist/lib/storage/file-paths.d.ts +0 -1
- package/dist/lib/storage/fixture-guards.d.ts +0 -1
- package/dist/lib/storage/flagged-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-load-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-save-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-storage-file.d.ts +0 -1
- package/dist/lib/storage/flagged-storage-io.d.ts +0 -1
- package/dist/lib/storage/flagged-storage.d.ts +0 -1
- package/dist/lib/storage/gitignore.d.ts +0 -1
- package/dist/lib/storage/hash.d.ts +0 -1
- package/dist/lib/storage/health.d.ts +0 -1
- package/dist/lib/storage/identity.d.ts +0 -1
- package/dist/lib/storage/import-export.d.ts +0 -1
- package/dist/lib/storage/json-store-lock.d.ts +105 -0
- package/dist/lib/storage/json-store-lock.js +259 -0
- package/dist/lib/storage/metadata-section.d.ts +0 -1
- package/dist/lib/storage/migrations.d.ts +0 -1
- package/dist/lib/storage/migrations.js +31 -18
- package/dist/lib/storage/named-backup-entry.d.ts +0 -1
- package/dist/lib/storage/named-backups-entry.d.ts +0 -1
- package/dist/lib/storage/named-backups.d.ts +0 -1
- package/dist/lib/storage/path-state.d.ts +0 -1
- package/dist/lib/storage/paths.d.ts +0 -1
- package/dist/lib/storage/pending-auth.d.ts +10 -3
- package/dist/lib/storage/pending-auth.d.ts.map +1 -1
- package/dist/lib/storage/pending-auth.js +33 -9
- package/dist/lib/storage/project-migration.d.ts +0 -1
- package/dist/lib/storage/public-types.d.ts +0 -1
- package/dist/lib/storage/record-identity.d.ts +15 -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/record-utils.d.ts +0 -1
- package/dist/lib/storage/restore-assessment.d.ts +0 -1
- package/dist/lib/storage/restore-backup-entry.d.ts +0 -1
- package/dist/lib/storage/restore-metadata.d.ts +0 -1
- package/dist/lib/storage/save-retry.d.ts +0 -1
- package/dist/lib/storage/snapshot-inspectors.d.ts +0 -1
- package/dist/lib/storage/snapshot-merge.d.ts +0 -1
- package/dist/lib/storage/storage-parser.d.ts +2 -1
- package/dist/lib/storage/storage-parser.js +10 -2
- package/dist/lib/storage/transactions.d.ts +0 -1
- package/dist/lib/storage.d.ts +15 -2
- package/dist/lib/storage.js +612 -25
- package/dist/lib/synthetic-response.d.ts +0 -1
- package/dist/lib/table-formatter.d.ts +0 -1
- package/dist/lib/temp-path.d.ts +0 -1
- package/dist/lib/tools/hashline-tools.d.ts +0 -1
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/ui/ansi.d.ts +0 -1
- package/dist/lib/ui/auth-menu-builder.d.ts +0 -1
- package/dist/lib/ui/auth-menu.d.ts +0 -1
- package/dist/lib/ui/check-progress.d.ts +0 -1
- package/dist/lib/ui/confirm.d.ts +0 -1
- package/dist/lib/ui/display-width.d.ts +0 -1
- package/dist/lib/ui/format.d.ts +0 -1
- package/dist/lib/ui/index.d.ts +0 -1
- package/dist/lib/ui/runtime.d.ts +0 -1
- package/dist/lib/ui/select.d.ts +0 -1
- package/dist/lib/ui/theme.d.ts +0 -1
- package/dist/lib/ui/ui-copy.d.ts +0 -1
- package/dist/lib/unified-settings.d.ts +13 -11
- package/dist/lib/unified-settings.js +22 -14
- package/dist/lib/update-notice.d.ts +0 -1
- package/dist/lib/usage/index.d.ts +0 -1
- package/dist/lib/usage/ledger.d.ts +0 -1
- package/dist/lib/usage/pricing.d.ts +0 -1
- package/dist/lib/usage/redaction.d.ts +0 -1
- package/dist/lib/usage/stream-usage-deferral.d.ts +0 -1
- package/dist/lib/usage/types.d.ts +0 -1
- package/dist/lib/usage/usage-extraction.d.ts +0 -1
- package/dist/lib/utils.d.ts +21 -1
- package/dist/lib/utils.js +31 -0
- package/dist/lib/wsl.d.ts +0 -1
- 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 +206 -200
- package/scripts/codex-app-launcher.js +653 -653
- package/scripts/codex-app-router.js +373 -373
- package/scripts/codex-bin-resolver.js +332 -313
- package/scripts/codex-multi-auth.js +65 -59
- package/scripts/codex-routing.js +62 -62
- package/scripts/codex.js +6923 -6642
- 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/skills/codex-auth-setup/SKILL.md +73 -0
- 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
|
@@ -1,373 +1,373 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
chmodSync,
|
|
5
|
-
closeSync,
|
|
6
|
-
fstatSync,
|
|
7
|
-
ftruncateSync,
|
|
8
|
-
mkdirSync,
|
|
9
|
-
openSync,
|
|
10
|
-
readFileSync,
|
|
11
|
-
renameSync,
|
|
12
|
-
rmSync,
|
|
13
|
-
statSync,
|
|
14
|
-
truncateSync,
|
|
15
|
-
writeSync,
|
|
16
|
-
writeFileSync,
|
|
17
|
-
} from "node:fs";
|
|
18
|
-
import { basename, dirname, join } from "node:path";
|
|
19
|
-
import process from "node:process";
|
|
20
|
-
|
|
21
|
-
const DEFAULT_MAX_LOG_BYTES = 1024 * 1024;
|
|
22
|
-
const LOG_SIZE_CHECK_INTERVAL_MS = 60_000;
|
|
23
|
-
|
|
24
|
-
function parsePort(value) {
|
|
25
|
-
if (typeof value !== "string" && typeof value !== "number") return Number.NaN;
|
|
26
|
-
const text = String(value).trim();
|
|
27
|
-
if (!/^\d+$/.test(text)) return Number.NaN;
|
|
28
|
-
const port = Number(text);
|
|
29
|
-
return Number.isInteger(port) && port >= 0 && port <= 65535
|
|
30
|
-
? port
|
|
31
|
-
: Number.NaN;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function parseArgs(argv) {
|
|
35
|
-
const result = {
|
|
36
|
-
host: "127.0.0.1",
|
|
37
|
-
port: 0,
|
|
38
|
-
statusPath: "",
|
|
39
|
-
identityToken: "",
|
|
40
|
-
statePath: "",
|
|
41
|
-
logPath: "",
|
|
42
|
-
maxLogBytes: DEFAULT_MAX_LOG_BYTES,
|
|
43
|
-
};
|
|
44
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
45
|
-
const arg = argv[index];
|
|
46
|
-
const next = argv[index + 1] ?? "";
|
|
47
|
-
if (arg === "--host") {
|
|
48
|
-
result.host = next;
|
|
49
|
-
index += 1;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (arg === "--port") {
|
|
53
|
-
result.port = parsePort(next);
|
|
54
|
-
index += 1;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (arg === "--status") {
|
|
58
|
-
result.statusPath = next;
|
|
59
|
-
index += 1;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (arg === "--identity-token") {
|
|
63
|
-
result.identityToken = next;
|
|
64
|
-
index += 1;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (arg === "--state") {
|
|
68
|
-
result.statePath = next;
|
|
69
|
-
index += 1;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (arg === "--max-log-bytes") {
|
|
73
|
-
const parsed = Number.parseInt(next, 10);
|
|
74
|
-
result.maxLogBytes =
|
|
75
|
-
Number.isFinite(parsed) && parsed > 0
|
|
76
|
-
? parsed
|
|
77
|
-
: DEFAULT_MAX_LOG_BYTES;
|
|
78
|
-
index += 1;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (arg === "--log") {
|
|
82
|
-
result.logPath = next;
|
|
83
|
-
index += 1;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function readState(path) {
|
|
90
|
-
if (!path) return null;
|
|
91
|
-
try {
|
|
92
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
93
|
-
} catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function readTrimmedString(record, key) {
|
|
99
|
-
const value = record?.[key];
|
|
100
|
-
return typeof value === "string" && value.trim().length > 0
|
|
101
|
-
? value.trim()
|
|
102
|
-
: undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function writeStatus(statusPath, payload) {
|
|
106
|
-
if (!statusPath) return;
|
|
107
|
-
const statusDir = dirname(statusPath);
|
|
108
|
-
const tempPath = join(
|
|
109
|
-
statusDir,
|
|
110
|
-
[
|
|
111
|
-
`.${basename(statusPath)}`,
|
|
112
|
-
String(process.pid),
|
|
113
|
-
String(Date.now()),
|
|
114
|
-
"tmp",
|
|
115
|
-
].join("."),
|
|
116
|
-
);
|
|
117
|
-
let fd = null;
|
|
118
|
-
try {
|
|
119
|
-
mkdirSync(statusDir, { recursive: true });
|
|
120
|
-
fd = openSync(tempPath, "w", 0o600);
|
|
121
|
-
writeFileSync(fd, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
|
|
122
|
-
closeSync(fd);
|
|
123
|
-
fd = null;
|
|
124
|
-
chmodSync(tempPath, 0o600);
|
|
125
|
-
renameSync(tempPath, statusPath);
|
|
126
|
-
chmodSync(statusPath, 0o600);
|
|
127
|
-
} catch {
|
|
128
|
-
// Status is best-effort. The router should keep serving if telemetry is locked.
|
|
129
|
-
try {
|
|
130
|
-
if (fd !== null) closeSync(fd);
|
|
131
|
-
} catch {
|
|
132
|
-
// Preserve the original status-write failure.
|
|
133
|
-
}
|
|
134
|
-
try {
|
|
135
|
-
rmSync(tempPath, { force: true });
|
|
136
|
-
} catch {
|
|
137
|
-
// Preserve the original status-write failure.
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function createStatusPayload({
|
|
143
|
-
state,
|
|
144
|
-
proxyServer,
|
|
145
|
-
error,
|
|
146
|
-
stateRecord,
|
|
147
|
-
startedAt,
|
|
148
|
-
statusPath,
|
|
149
|
-
routerScriptPath,
|
|
150
|
-
identityToken,
|
|
151
|
-
}) {
|
|
152
|
-
const proxyStatus =
|
|
153
|
-
typeof proxyServer?.getStatus === "function" ? proxyServer.getStatus() : {};
|
|
154
|
-
const lastAccountIndex = proxyStatus.lastAccountIndex ?? null;
|
|
155
|
-
const lastAccountLabel =
|
|
156
|
-
typeof proxyStatus.lastAccountLabel === "string" &&
|
|
157
|
-
!proxyStatus.lastAccountLabel.includes("@")
|
|
158
|
-
? proxyStatus.lastAccountLabel
|
|
159
|
-
: typeof lastAccountIndex === "number"
|
|
160
|
-
? `Account ${lastAccountIndex + 1}`
|
|
161
|
-
: null;
|
|
162
|
-
return {
|
|
163
|
-
version: 1,
|
|
164
|
-
kind: "codex-app-runtime-rotation-router",
|
|
165
|
-
state,
|
|
166
|
-
pid: process.pid,
|
|
167
|
-
startedAt,
|
|
168
|
-
statusPath: statusPath || readTrimmedString(stateRecord, "statusPath") || null,
|
|
169
|
-
identityToken:
|
|
170
|
-
identityToken || readTrimmedString(stateRecord, "identityToken") || null,
|
|
171
|
-
routerScriptPath:
|
|
172
|
-
routerScriptPath ||
|
|
173
|
-
readTrimmedString(stateRecord, "routerScriptPath") ||
|
|
174
|
-
process.argv[1] ||
|
|
175
|
-
null,
|
|
176
|
-
updatedAt: Date.now(),
|
|
177
|
-
baseUrl: proxyServer?.baseUrl ?? stateRecord?.baseUrl ?? null,
|
|
178
|
-
totalRequests: proxyStatus.totalRequests ?? 0,
|
|
179
|
-
upstreamRequests: proxyStatus.upstreamRequests ?? 0,
|
|
180
|
-
websocketConnections: proxyStatus.websocketConnections ?? 0,
|
|
181
|
-
websocketUpstreamRequests: proxyStatus.websocketUpstreamRequests ?? 0,
|
|
182
|
-
streamQuotaUpdates: proxyStatus.streamQuotaUpdates ?? 0,
|
|
183
|
-
lastStreamQuotaUpdateAt: proxyStatus.lastStreamQuotaUpdateAt ?? null,
|
|
184
|
-
retries: proxyStatus.retries ?? 0,
|
|
185
|
-
rotations: proxyStatus.rotations ?? 0,
|
|
186
|
-
lastAccountIndex,
|
|
187
|
-
lastAccountLabel,
|
|
188
|
-
lastAccountId: proxyStatus.lastAccountId ?? null,
|
|
189
|
-
lastRequestedWorkspaceId: proxyStatus.lastRequestedWorkspaceId ?? null,
|
|
190
|
-
lastAccountUpdatedAt: proxyStatus.lastAccountUpdatedAt ?? null,
|
|
191
|
-
lastError: error ? (error instanceof Error ? error.message : String(error)) : proxyStatus.lastError ?? null,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function isLoopbackHost(host) {
|
|
196
|
-
if (typeof host !== "string") return false;
|
|
197
|
-
const normalized = host.trim().toLowerCase();
|
|
198
|
-
const unbracketed =
|
|
199
|
-
normalized.startsWith("[") && normalized.endsWith("]")
|
|
200
|
-
? normalized.slice(1, -1)
|
|
201
|
-
: normalized;
|
|
202
|
-
return (
|
|
203
|
-
unbracketed === "127.0.0.1" ||
|
|
204
|
-
unbracketed === "::1" ||
|
|
205
|
-
unbracketed === "localhost"
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function truncateLogFdIfTooLarge(fd, maxBytes) {
|
|
210
|
-
if (!Number.isFinite(maxBytes) || maxBytes <= 0) return;
|
|
211
|
-
try {
|
|
212
|
-
const stats = fstatSync(fd);
|
|
213
|
-
if (!stats.isFile() || stats.size <= maxBytes) return;
|
|
214
|
-
ftruncateSync(fd, 0);
|
|
215
|
-
writeSync(
|
|
216
|
-
fd,
|
|
217
|
-
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
218
|
-
);
|
|
219
|
-
} catch {
|
|
220
|
-
// stdout/stderr may be pipes or otherwise unavailable; logging must not fail startup.
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function truncateLogPathIfTooLarge(logPath, maxBytes) {
|
|
225
|
-
if (!logPath || !Number.isFinite(maxBytes) || maxBytes <= 0) return false;
|
|
226
|
-
try {
|
|
227
|
-
const stats = statSync(logPath);
|
|
228
|
-
if (!stats.isFile() || stats.size <= maxBytes) return false;
|
|
229
|
-
truncateSync(logPath, 0);
|
|
230
|
-
return true;
|
|
231
|
-
} catch {
|
|
232
|
-
// Log path may not exist yet or may be locked; fd-level checks can still work.
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function writeLogTruncatedMarker(maxBytes) {
|
|
238
|
-
try {
|
|
239
|
-
writeSync(
|
|
240
|
-
1,
|
|
241
|
-
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
242
|
-
);
|
|
243
|
-
} catch {
|
|
244
|
-
// A closed stdout/stderr should not crash the router while enforcing log bounds.
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function installLogBounds(maxBytes, logPath) {
|
|
249
|
-
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
250
|
-
writeLogTruncatedMarker(maxBytes);
|
|
251
|
-
}
|
|
252
|
-
truncateLogFdIfTooLarge(1, maxBytes);
|
|
253
|
-
truncateLogFdIfTooLarge(2, maxBytes);
|
|
254
|
-
return setInterval(() => {
|
|
255
|
-
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
256
|
-
writeLogTruncatedMarker(maxBytes);
|
|
257
|
-
}
|
|
258
|
-
truncateLogFdIfTooLarge(1, maxBytes);
|
|
259
|
-
truncateLogFdIfTooLarge(2, maxBytes);
|
|
260
|
-
}, LOG_SIZE_CHECK_INTERVAL_MS);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async function main() {
|
|
264
|
-
const routerStartedAt = Date.now();
|
|
265
|
-
const args = parseArgs(process.argv.slice(2));
|
|
266
|
-
installLogBounds(args.maxLogBytes, args.logPath).unref?.();
|
|
267
|
-
const stateRecord = readState(args.statePath);
|
|
268
|
-
if (args.statePath && stateRecord === null) {
|
|
269
|
-
const error = new Error(
|
|
270
|
-
"Codex app runtime router state is unreadable; refusing to bind an ephemeral port.",
|
|
271
|
-
);
|
|
272
|
-
writeStatus(
|
|
273
|
-
args.statusPath,
|
|
274
|
-
createStatusPayload({
|
|
275
|
-
state: "error",
|
|
276
|
-
proxyServer: null,
|
|
277
|
-
error,
|
|
278
|
-
stateRecord: null,
|
|
279
|
-
startedAt: routerStartedAt,
|
|
280
|
-
statusPath: args.statusPath,
|
|
281
|
-
routerScriptPath: process.argv[1],
|
|
282
|
-
identityToken: args.identityToken,
|
|
283
|
-
}),
|
|
284
|
-
);
|
|
285
|
-
throw error;
|
|
286
|
-
}
|
|
287
|
-
const host =
|
|
288
|
-
typeof stateRecord?.host === "string" && stateRecord.host.trim().length > 0
|
|
289
|
-
? stateRecord.host.trim()
|
|
290
|
-
: args.host;
|
|
291
|
-
const statePort = parsePort(stateRecord?.port);
|
|
292
|
-
const port = Number.isFinite(statePort) ? statePort : args.port;
|
|
293
|
-
const clientApiKey = readTrimmedString(stateRecord, "clientApiKey");
|
|
294
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
295
|
-
throw new Error(
|
|
296
|
-
"A valid --port in the range 0-65535 is required for the Codex app runtime router.",
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
if (!isLoopbackHost(host)) {
|
|
300
|
-
throw new Error(
|
|
301
|
-
"Codex app runtime router host must be loopback-only (127.0.0.1, ::1, or localhost).",
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
if (!clientApiKey) {
|
|
305
|
-
throw new Error(
|
|
306
|
-
"Codex app runtime router state is missing its client token.",
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
let proxyServer = null;
|
|
311
|
-
const writeCurrentStatus = (state, error) => {
|
|
312
|
-
writeStatus(
|
|
313
|
-
args.statusPath || stateRecord?.statusPath || "",
|
|
314
|
-
createStatusPayload({
|
|
315
|
-
state,
|
|
316
|
-
proxyServer,
|
|
317
|
-
error,
|
|
318
|
-
stateRecord,
|
|
319
|
-
startedAt: routerStartedAt,
|
|
320
|
-
statusPath: args.statusPath || stateRecord?.statusPath || "",
|
|
321
|
-
routerScriptPath: stateRecord?.routerScriptPath || process.argv[1],
|
|
322
|
-
identityToken:
|
|
323
|
-
args.identityToken || stateRecord?.identityToken || "",
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
const proxyModule = await import("../dist/lib/runtime-rotation-proxy.js");
|
|
330
|
-
proxyServer = await proxyModule.startRuntimeRotationProxy({
|
|
331
|
-
nativeOpenai: stateRecord?.nativeOpenai === true,
|
|
332
|
-
catalogAccount: stateRecord?.catalogAccount,
|
|
333
|
-
host,
|
|
334
|
-
port,
|
|
335
|
-
clientApiKey,
|
|
336
|
-
});
|
|
337
|
-
writeCurrentStatus("running");
|
|
338
|
-
const timer = setInterval(() => writeCurrentStatus("running"), 1000);
|
|
339
|
-
let cleanupPromise = null;
|
|
340
|
-
const cleanup = async (state) => {
|
|
341
|
-
clearInterval(timer);
|
|
342
|
-
try {
|
|
343
|
-
await proxyServer?.close?.();
|
|
344
|
-
} finally {
|
|
345
|
-
writeCurrentStatus(state);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
const cleanupOnce = (state) => {
|
|
349
|
-
cleanupPromise ??= cleanup(state);
|
|
350
|
-
return cleanupPromise;
|
|
351
|
-
};
|
|
352
|
-
process.once("SIGINT", () => {
|
|
353
|
-
void cleanupOnce("stopped").finally(() => process.exit(130));
|
|
354
|
-
});
|
|
355
|
-
process.once("SIGTERM", () => {
|
|
356
|
-
void cleanupOnce("stopped").finally(() => process.exit(0));
|
|
357
|
-
});
|
|
358
|
-
process.once("SIGHUP", () => {
|
|
359
|
-
void cleanupOnce("stopped").finally(() => process.exit(0));
|
|
360
|
-
});
|
|
361
|
-
await new Promise(() => undefined);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
writeCurrentStatus("error", error);
|
|
364
|
-
throw error;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
main().catch((error) => {
|
|
369
|
-
console.error(
|
|
370
|
-
`codex-multi-auth app router failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
371
|
-
);
|
|
372
|
-
process.exitCode = 1;
|
|
373
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
closeSync,
|
|
6
|
+
fstatSync,
|
|
7
|
+
ftruncateSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
openSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
statSync,
|
|
14
|
+
truncateSync,
|
|
15
|
+
writeSync,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
} from "node:fs";
|
|
18
|
+
import { basename, dirname, join } from "node:path";
|
|
19
|
+
import process from "node:process";
|
|
20
|
+
|
|
21
|
+
const DEFAULT_MAX_LOG_BYTES = 1024 * 1024;
|
|
22
|
+
const LOG_SIZE_CHECK_INTERVAL_MS = 60_000;
|
|
23
|
+
|
|
24
|
+
function parsePort(value) {
|
|
25
|
+
if (typeof value !== "string" && typeof value !== "number") return Number.NaN;
|
|
26
|
+
const text = String(value).trim();
|
|
27
|
+
if (!/^\d+$/.test(text)) return Number.NaN;
|
|
28
|
+
const port = Number(text);
|
|
29
|
+
return Number.isInteger(port) && port >= 0 && port <= 65535
|
|
30
|
+
? port
|
|
31
|
+
: Number.NaN;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseArgs(argv) {
|
|
35
|
+
const result = {
|
|
36
|
+
host: "127.0.0.1",
|
|
37
|
+
port: 0,
|
|
38
|
+
statusPath: "",
|
|
39
|
+
identityToken: "",
|
|
40
|
+
statePath: "",
|
|
41
|
+
logPath: "",
|
|
42
|
+
maxLogBytes: DEFAULT_MAX_LOG_BYTES,
|
|
43
|
+
};
|
|
44
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
45
|
+
const arg = argv[index];
|
|
46
|
+
const next = argv[index + 1] ?? "";
|
|
47
|
+
if (arg === "--host") {
|
|
48
|
+
result.host = next;
|
|
49
|
+
index += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (arg === "--port") {
|
|
53
|
+
result.port = parsePort(next);
|
|
54
|
+
index += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (arg === "--status") {
|
|
58
|
+
result.statusPath = next;
|
|
59
|
+
index += 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (arg === "--identity-token") {
|
|
63
|
+
result.identityToken = next;
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--state") {
|
|
68
|
+
result.statePath = next;
|
|
69
|
+
index += 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (arg === "--max-log-bytes") {
|
|
73
|
+
const parsed = Number.parseInt(next, 10);
|
|
74
|
+
result.maxLogBytes =
|
|
75
|
+
Number.isFinite(parsed) && parsed > 0
|
|
76
|
+
? parsed
|
|
77
|
+
: DEFAULT_MAX_LOG_BYTES;
|
|
78
|
+
index += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (arg === "--log") {
|
|
82
|
+
result.logPath = next;
|
|
83
|
+
index += 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function readState(path) {
|
|
90
|
+
if (!path) return null;
|
|
91
|
+
try {
|
|
92
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readTrimmedString(record, key) {
|
|
99
|
+
const value = record?.[key];
|
|
100
|
+
return typeof value === "string" && value.trim().length > 0
|
|
101
|
+
? value.trim()
|
|
102
|
+
: undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function writeStatus(statusPath, payload) {
|
|
106
|
+
if (!statusPath) return;
|
|
107
|
+
const statusDir = dirname(statusPath);
|
|
108
|
+
const tempPath = join(
|
|
109
|
+
statusDir,
|
|
110
|
+
[
|
|
111
|
+
`.${basename(statusPath)}`,
|
|
112
|
+
String(process.pid),
|
|
113
|
+
String(Date.now()),
|
|
114
|
+
"tmp",
|
|
115
|
+
].join("."),
|
|
116
|
+
);
|
|
117
|
+
let fd = null;
|
|
118
|
+
try {
|
|
119
|
+
mkdirSync(statusDir, { recursive: true });
|
|
120
|
+
fd = openSync(tempPath, "w", 0o600);
|
|
121
|
+
writeFileSync(fd, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
|
|
122
|
+
closeSync(fd);
|
|
123
|
+
fd = null;
|
|
124
|
+
chmodSync(tempPath, 0o600);
|
|
125
|
+
renameSync(tempPath, statusPath);
|
|
126
|
+
chmodSync(statusPath, 0o600);
|
|
127
|
+
} catch {
|
|
128
|
+
// Status is best-effort. The router should keep serving if telemetry is locked.
|
|
129
|
+
try {
|
|
130
|
+
if (fd !== null) closeSync(fd);
|
|
131
|
+
} catch {
|
|
132
|
+
// Preserve the original status-write failure.
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
rmSync(tempPath, { force: true });
|
|
136
|
+
} catch {
|
|
137
|
+
// Preserve the original status-write failure.
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function createStatusPayload({
|
|
143
|
+
state,
|
|
144
|
+
proxyServer,
|
|
145
|
+
error,
|
|
146
|
+
stateRecord,
|
|
147
|
+
startedAt,
|
|
148
|
+
statusPath,
|
|
149
|
+
routerScriptPath,
|
|
150
|
+
identityToken,
|
|
151
|
+
}) {
|
|
152
|
+
const proxyStatus =
|
|
153
|
+
typeof proxyServer?.getStatus === "function" ? proxyServer.getStatus() : {};
|
|
154
|
+
const lastAccountIndex = proxyStatus.lastAccountIndex ?? null;
|
|
155
|
+
const lastAccountLabel =
|
|
156
|
+
typeof proxyStatus.lastAccountLabel === "string" &&
|
|
157
|
+
!proxyStatus.lastAccountLabel.includes("@")
|
|
158
|
+
? proxyStatus.lastAccountLabel
|
|
159
|
+
: typeof lastAccountIndex === "number"
|
|
160
|
+
? `Account ${lastAccountIndex + 1}`
|
|
161
|
+
: null;
|
|
162
|
+
return {
|
|
163
|
+
version: 1,
|
|
164
|
+
kind: "codex-app-runtime-rotation-router",
|
|
165
|
+
state,
|
|
166
|
+
pid: process.pid,
|
|
167
|
+
startedAt,
|
|
168
|
+
statusPath: statusPath || readTrimmedString(stateRecord, "statusPath") || null,
|
|
169
|
+
identityToken:
|
|
170
|
+
identityToken || readTrimmedString(stateRecord, "identityToken") || null,
|
|
171
|
+
routerScriptPath:
|
|
172
|
+
routerScriptPath ||
|
|
173
|
+
readTrimmedString(stateRecord, "routerScriptPath") ||
|
|
174
|
+
process.argv[1] ||
|
|
175
|
+
null,
|
|
176
|
+
updatedAt: Date.now(),
|
|
177
|
+
baseUrl: proxyServer?.baseUrl ?? stateRecord?.baseUrl ?? null,
|
|
178
|
+
totalRequests: proxyStatus.totalRequests ?? 0,
|
|
179
|
+
upstreamRequests: proxyStatus.upstreamRequests ?? 0,
|
|
180
|
+
websocketConnections: proxyStatus.websocketConnections ?? 0,
|
|
181
|
+
websocketUpstreamRequests: proxyStatus.websocketUpstreamRequests ?? 0,
|
|
182
|
+
streamQuotaUpdates: proxyStatus.streamQuotaUpdates ?? 0,
|
|
183
|
+
lastStreamQuotaUpdateAt: proxyStatus.lastStreamQuotaUpdateAt ?? null,
|
|
184
|
+
retries: proxyStatus.retries ?? 0,
|
|
185
|
+
rotations: proxyStatus.rotations ?? 0,
|
|
186
|
+
lastAccountIndex,
|
|
187
|
+
lastAccountLabel,
|
|
188
|
+
lastAccountId: proxyStatus.lastAccountId ?? null,
|
|
189
|
+
lastRequestedWorkspaceId: proxyStatus.lastRequestedWorkspaceId ?? null,
|
|
190
|
+
lastAccountUpdatedAt: proxyStatus.lastAccountUpdatedAt ?? null,
|
|
191
|
+
lastError: error ? (error instanceof Error ? error.message : String(error)) : proxyStatus.lastError ?? null,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function isLoopbackHost(host) {
|
|
196
|
+
if (typeof host !== "string") return false;
|
|
197
|
+
const normalized = host.trim().toLowerCase();
|
|
198
|
+
const unbracketed =
|
|
199
|
+
normalized.startsWith("[") && normalized.endsWith("]")
|
|
200
|
+
? normalized.slice(1, -1)
|
|
201
|
+
: normalized;
|
|
202
|
+
return (
|
|
203
|
+
unbracketed === "127.0.0.1" ||
|
|
204
|
+
unbracketed === "::1" ||
|
|
205
|
+
unbracketed === "localhost"
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function truncateLogFdIfTooLarge(fd, maxBytes) {
|
|
210
|
+
if (!Number.isFinite(maxBytes) || maxBytes <= 0) return;
|
|
211
|
+
try {
|
|
212
|
+
const stats = fstatSync(fd);
|
|
213
|
+
if (!stats.isFile() || stats.size <= maxBytes) return;
|
|
214
|
+
ftruncateSync(fd, 0);
|
|
215
|
+
writeSync(
|
|
216
|
+
fd,
|
|
217
|
+
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
218
|
+
);
|
|
219
|
+
} catch {
|
|
220
|
+
// stdout/stderr may be pipes or otherwise unavailable; logging must not fail startup.
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function truncateLogPathIfTooLarge(logPath, maxBytes) {
|
|
225
|
+
if (!logPath || !Number.isFinite(maxBytes) || maxBytes <= 0) return false;
|
|
226
|
+
try {
|
|
227
|
+
const stats = statSync(logPath);
|
|
228
|
+
if (!stats.isFile() || stats.size <= maxBytes) return false;
|
|
229
|
+
truncateSync(logPath, 0);
|
|
230
|
+
return true;
|
|
231
|
+
} catch {
|
|
232
|
+
// Log path may not exist yet or may be locked; fd-level checks can still work.
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function writeLogTruncatedMarker(maxBytes) {
|
|
238
|
+
try {
|
|
239
|
+
writeSync(
|
|
240
|
+
1,
|
|
241
|
+
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
242
|
+
);
|
|
243
|
+
} catch {
|
|
244
|
+
// A closed stdout/stderr should not crash the router while enforcing log bounds.
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function installLogBounds(maxBytes, logPath) {
|
|
249
|
+
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
250
|
+
writeLogTruncatedMarker(maxBytes);
|
|
251
|
+
}
|
|
252
|
+
truncateLogFdIfTooLarge(1, maxBytes);
|
|
253
|
+
truncateLogFdIfTooLarge(2, maxBytes);
|
|
254
|
+
return setInterval(() => {
|
|
255
|
+
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
256
|
+
writeLogTruncatedMarker(maxBytes);
|
|
257
|
+
}
|
|
258
|
+
truncateLogFdIfTooLarge(1, maxBytes);
|
|
259
|
+
truncateLogFdIfTooLarge(2, maxBytes);
|
|
260
|
+
}, LOG_SIZE_CHECK_INTERVAL_MS);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function main() {
|
|
264
|
+
const routerStartedAt = Date.now();
|
|
265
|
+
const args = parseArgs(process.argv.slice(2));
|
|
266
|
+
installLogBounds(args.maxLogBytes, args.logPath).unref?.();
|
|
267
|
+
const stateRecord = readState(args.statePath);
|
|
268
|
+
if (args.statePath && stateRecord === null) {
|
|
269
|
+
const error = new Error(
|
|
270
|
+
"Codex app runtime router state is unreadable; refusing to bind an ephemeral port.",
|
|
271
|
+
);
|
|
272
|
+
writeStatus(
|
|
273
|
+
args.statusPath,
|
|
274
|
+
createStatusPayload({
|
|
275
|
+
state: "error",
|
|
276
|
+
proxyServer: null,
|
|
277
|
+
error,
|
|
278
|
+
stateRecord: null,
|
|
279
|
+
startedAt: routerStartedAt,
|
|
280
|
+
statusPath: args.statusPath,
|
|
281
|
+
routerScriptPath: process.argv[1],
|
|
282
|
+
identityToken: args.identityToken,
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
const host =
|
|
288
|
+
typeof stateRecord?.host === "string" && stateRecord.host.trim().length > 0
|
|
289
|
+
? stateRecord.host.trim()
|
|
290
|
+
: args.host;
|
|
291
|
+
const statePort = parsePort(stateRecord?.port);
|
|
292
|
+
const port = Number.isFinite(statePort) ? statePort : args.port;
|
|
293
|
+
const clientApiKey = readTrimmedString(stateRecord, "clientApiKey");
|
|
294
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
"A valid --port in the range 0-65535 is required for the Codex app runtime router.",
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
if (!isLoopbackHost(host)) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
"Codex app runtime router host must be loopback-only (127.0.0.1, ::1, or localhost).",
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
if (!clientApiKey) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"Codex app runtime router state is missing its client token.",
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
let proxyServer = null;
|
|
311
|
+
const writeCurrentStatus = (state, error) => {
|
|
312
|
+
writeStatus(
|
|
313
|
+
args.statusPath || stateRecord?.statusPath || "",
|
|
314
|
+
createStatusPayload({
|
|
315
|
+
state,
|
|
316
|
+
proxyServer,
|
|
317
|
+
error,
|
|
318
|
+
stateRecord,
|
|
319
|
+
startedAt: routerStartedAt,
|
|
320
|
+
statusPath: args.statusPath || stateRecord?.statusPath || "",
|
|
321
|
+
routerScriptPath: stateRecord?.routerScriptPath || process.argv[1],
|
|
322
|
+
identityToken:
|
|
323
|
+
args.identityToken || stateRecord?.identityToken || "",
|
|
324
|
+
}),
|
|
325
|
+
);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
const proxyModule = await import("../dist/lib/runtime-rotation-proxy.js");
|
|
330
|
+
proxyServer = await proxyModule.startRuntimeRotationProxy({
|
|
331
|
+
nativeOpenai: stateRecord?.nativeOpenai === true,
|
|
332
|
+
catalogAccount: stateRecord?.catalogAccount,
|
|
333
|
+
host,
|
|
334
|
+
port,
|
|
335
|
+
clientApiKey,
|
|
336
|
+
});
|
|
337
|
+
writeCurrentStatus("running");
|
|
338
|
+
const timer = setInterval(() => writeCurrentStatus("running"), 1000);
|
|
339
|
+
let cleanupPromise = null;
|
|
340
|
+
const cleanup = async (state) => {
|
|
341
|
+
clearInterval(timer);
|
|
342
|
+
try {
|
|
343
|
+
await proxyServer?.close?.();
|
|
344
|
+
} finally {
|
|
345
|
+
writeCurrentStatus(state);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const cleanupOnce = (state) => {
|
|
349
|
+
cleanupPromise ??= cleanup(state);
|
|
350
|
+
return cleanupPromise;
|
|
351
|
+
};
|
|
352
|
+
process.once("SIGINT", () => {
|
|
353
|
+
void cleanupOnce("stopped").finally(() => process.exit(130));
|
|
354
|
+
});
|
|
355
|
+
process.once("SIGTERM", () => {
|
|
356
|
+
void cleanupOnce("stopped").finally(() => process.exit(0));
|
|
357
|
+
});
|
|
358
|
+
process.once("SIGHUP", () => {
|
|
359
|
+
void cleanupOnce("stopped").finally(() => process.exit(0));
|
|
360
|
+
});
|
|
361
|
+
await new Promise(() => undefined);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
writeCurrentStatus("error", error);
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
main().catch((error) => {
|
|
369
|
+
console.error(
|
|
370
|
+
`codex-multi-auth app router failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
371
|
+
);
|
|
372
|
+
process.exitCode = 1;
|
|
373
|
+
});
|