refactor: provider namespace unification and architecture overhaul#90
Conversation
Replace hardcoded MODEL_PROVIDER_OVERRIDES in pass-through.ts, provider === 'claude' ? 'anthropic' : 'openai' remap in service.ts, and provider === 'openai' billing special-case in pricing.ts with a unified CanonicalProvider resolver that derives provider from model prefix using longest-prefix matching. The resolver merges default rules with ProviderRegistry model lists so custom providers from PROVIDERS_JSON auto-participate without code changes. Billing semantics (anthropic vs openai cache-read handling) are now determined by provider type from the registry. Add three new admin API endpoints: - GET /admin/providers: registered provider list with source info - GET /admin/pricing: pricing cache freshness and path - GET /admin/config: non-secret configuration snapshot
Move anthropic bypass logic from AgentPlugin transform methods to the new ProviderTransform registry. AgentPlugin now handles tool identification only (id + matches). pass-through.ts applies provider transforms based on the resolved provider id instead of the matched agent plugin.
Add actual_provider column to request_logs via migration 011. During finalize, derive actual_provider from the response's actual_model using CanonicalProvider.fromModel(). Cost calculation is unchanged in this commit — actual_provider is shadow-recorded for validation before switching cost basis.
Cost computation now uses the response's actual_model and actual_provider (derived from CanonicalProvider) instead of the request-time proxy provider and model. This ensures pricing matches the model that actually served the request. daily_usage aggregation and cost_audit now reflect actual provider/model combinations.
…t endpoint Remove actual_model and reasoning_tokens from correlator writes since these are now captured at finalize time. Correlator now only attributes cliproxy_account, cliproxy_auth_index, and cliproxy_source. Add GET /admin/logs/:id/cost-audit endpoint to expose the cost calculation audit trail for a specific request log.
…pshots Always start the quota refresh loop when CLIPROXY_AUTH_DIR is configured and readable, even if no .json auth files exist yet. This ensures OAuth logins added later are picked up on the next tick. Clean up stale quota snapshots for accounts whose auth files have been removed, preventing ghost accounts in the latest quota view.
…ier quotas Add nullable model column to quota_snapshots via migration 012. Parse additional_rate_limits from OpenAI wham/usage response in the codex probe, storing model-tier-specific rate limits (e.g. o3, gpt-4.1) as separate quota snapshots with the model dimension populated. Account-level snapshots keep model as NULL; model-tier snapshots use the limit_name as the model identifier.
…alidation Add post-hoc account mismatch detection: when the correlator attributes a request to an account not in the API key's allowedAccounts, emit a warning event for monitoring. Validate allowedProviders against the provider registry on API key create/update, returning warnings for unknown provider IDs. Add GET /admin/quotas/probes endpoint exposing registered quota probe types.
AgentPlugins registry is unused after ProviderTransform split. Tool identification is handled by RequestInspector. Move anthropic bypass helpers into provider/transforms/anthropic.ts and delete the entire agent-plugins directory.
Remove subscription_code plumbing from types, repos, and service since no code path sets it. Remove unused function exports from ProviderTransforms, ProviderRegistry, CanonicalProvider, and UsageRepo. Remove unused barrel index files.
Move hardcoded pricing model overrides and aliases to config-driven PRICING_OVERRIDES_JSON and PRICING_ALIASES_JSON environment variables with backward-compatible defaults. Remove stale subscription plans documentation from README, update admin endpoint table with new endpoints, and sync project description.
Add migration 013 to DROP the account_subscriptions table and its index. The table was created in migration 006 for subscription plan bindings but was never used after plans were removed. Fix stale 'subscription' wording in CLI init prompt.
Replace 13 incremental migrations with a single 001_init.sql that creates the final schema directly. Remove ensureColumn compatibility shims and stale-row UPDATE from db.ts since fresh installs are the only supported path. Drop account_subscriptions table (unused). Update storage-lifecycle-cost tests to match the consolidated schema.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (50)
📝 WalkthroughWalkthroughThis PR restructures provider request handling by removing the agent-plugin system and replacing it with canonical provider resolution and per-provider transforms. Database schema consolidation merges incremental migrations into a single initialization. Cost and usage tracking now separate actual and cost providers, with configurable pricing overrides/aliases and stronger API key scope validation. ChangesProvider Transforms & Cost Attribution Consolidation
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly Related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
Summary
Major architecture refactor that unifies the provider namespace, separates bypass from tool identification, and switches cost calculation to use actual upstream response data.
50 files changed, +694 / -1,100 lines (net reduction of 406 lines)
Changes by Phase
Phase 1: Provider namespace foundation
CanonicalProviderresolver — single source of truth for model→provider mappingMODEL_PROVIDER_OVERRIDES,provider === 'claude' ? 'anthropic' : 'openai', andprovider === 'openai'billing special-caseGET /admin/providers,GET /admin/pricing,GET /admin/configPhase 2: ProviderTransform split
ProviderTransformregistryPhase 3-4: actual_provider + cost switch
actual_providercolumn onrequest_logs(migration 011)actual_model + actual_providerfrom upstream responsePhase 5: Correlator reduction
cliproxy_account,cliproxy_auth_index)actual_modelandreasoning_tokensnow captured at finalize timeGET /admin/logs/:id/cost-auditendpointPhase 6: Quota improvements
additional_rate_limitsparsing for model-tier quotasmodeldimension added toquota_snapshots(migration 012)Phase 7: API key enforcement
allowedAccountsmismatch monitoring on correlationallowedProviderssoft validation against registry on key create/updateGET /admin/quotas/probesendpointCleanup
agent-plugins/directory andidentification/modulesubscription_coderemnants and unused exportsPRICING_OVERRIDES_JSON/PRICING_ALIASES_JSON001_init.sqlaccount_subscriptionstableNew Admin API Endpoints
/admin/providers/admin/pricing/admin/config/admin/logs/:id/cost-audit/admin/quotas/probesDB Migrations
001_init.sqlcreates full schemaactual_provider+quota_snapshots.modelcolumnsVerification
bun run typecheck✅bun test tests/unit/— 166 pass, 0 fail ✅bun run build✅Summary by cubic
Unifies provider mapping with a single
CanonicalProvider, moves bypass to provider-level transforms, and switches cost calculation to the actual upstream provider/model. Adds new admin endpoints and streamlines quotas, pricing overrides, and schema.New Features
GET /admin/providers,GET /admin/pricing,GET /admin/config,GET /admin/logs/:id/cost-audit,GET /admin/quotas/probes.modelfield), codex probe parses model limits, refresh loop starts without auth files and cleans stale accounts.allowedProvidersagainst the registry and warn onallowedAccountsmismatches.Migration
001_init.sql.request_logs.actual_providerandquota_snapshots.model, then drop legacy migrations and theaccount_subscriptionstable.Written for commit 15b9df2. Summary will update on new commits.
Review in cubic
Summary by CodeRabbit
Release Notes
New Features
Documentation