quotaService property

ProviderQuotaService get quotaService

The session's quota service, built on first use — no IO at rest: the adapters resolve credentials lazily and fetch only when a surface peeks or refreshes. Tests inject the http client through AgentCliConfig.quotaHttpClient; production shares the keep-alive provider client.

Implementation

ProviderQuotaService get quotaService =>
    _quotaService ??= ProviderQuotaService(
      adapters: {
        'openrouter': OpenRouterQuotaAdapter(
          client: config.quotaHttpClient ?? sharedProviderHttpClient(),
          resolveApiKey: () async {
            final spec = providerCatalog['openrouter']!;
            return _providerKeyFor(spec, spec.defaultBaseUrl);
          },
        ),
        'codemie': CodeMieQuotaAdapter(
          client: config.quotaHttpClient ?? sharedProviderHttpClient(),
          // OQ1 lean (b): no pinned limits endpoint — the adapter stays
          // dark until the endpoint is confirmed, and renders its reason.
          resolveSessionCookie: _resolveCodeMieSessionCookie,
        ),
      },
      // DIAL-class endpoints carry no per-key billing surface.
      unmeteredProviders: {
        for (final spec in enabledProviders())
          if (spec.kind == 'dial') spec.name,
      },
      ttl: config.quotaTtl ?? const Duration(minutes: 15),
    );