Add CountTokensInterface operation type for provider-native token counting
## Summary Add `CountTokensInterface` and `CountTokensOutput` to drupal/ai core so that provider-native token counting participates in the `ProviderProxy` event pipeline — enabling quota enforcement, rate limiting, and cost attribution for pre-flight token checks. ## Problem `AnthropicProvider::countTokens()` (added in [ai_provider_anthropic #3607960](https://www.drupal.org/project/ai_provider_anthropic/issues/3607960)) calls the upstream SDK directly, bypassing `ProviderProxy`. No `ai.pre_generate_response` / `ai.post_generate_response` events fire, so consumers such as ai_metering never see the request. Quota enforcement, rate limiting, and cost attribution all break silently for sites running pre-flight token checks before agent tasks. This is distinct from the existing `ai.tokenizer` service, which estimates tokens locally using tiktoken with OpenAI encodings. Provider-native counting is exact and handles PDFs, images, and tool schemas server-side in ways a local estimator cannot. The same gap will exist for any provider that ships a native count method. Benefit: site builders and module developers (ai_metering, rate-limiting contrib, custom quota systems) who need accurate pre-flight token tracking per provider. ## Proposed solution `ProviderProxy` auto-detects any interface extending `OperationTypeInterface` whose method name matches the interface name. Adding `CountTokensInterface` (with `countTokens()`) and a typed `CountTokensOutput` DTO is sufficient — no new events needed in core. Consumers already subscribing to `ai.post_generate_response` and filtering on `getOperationType()` will pick up `count_tokens` calls automatically, with `requestThreadId` correlation and typed exception mapping inherited from the proxy. Architecture confirmed with @camoa in [ai_provider_anthropic #3607960 comment #5](https://www.drupal.org/project/ai_provider_anthropic/issues/3607960#comment-16670077). Once this lands, the provider side (implementing `CountTokensInterface` in `AnthropicProvider`, returning `CountTokensOutput` instead of `int`) will be handled in ai_provider_anthropic. DTO naming should align with [#3541284](https://www.drupal.org/node/3541284). ## Workaround None. Consumers cannot intercept `countTokens()` calls without this interface. ## Affected modules / components `ProviderProxy`, Provider API, `OperationTypeInterface` The problem, proposed solution, and architecture were identified through live testing of MR !35 on ai_provider_anthropic. The issue text was drafted with AI assistance (Claude Code) from that analysis and the architectural guidance in comment #5 of #3607960.
issue