Issue #3609167 by codeitwisely: Track embeddings operations correctly
Closes https://www.drupal.org/project/ai_metering/issues/3609167
What changed
Embeddings normalise to a vector array, not a text object, and carry no token usage, so the chat-shaped metering path mishandled them.
- extractOutputText() guarded with is_object() before method_exists(): the vector array no longer triggers a TypeError, so the call is recorded instead of being swallowed by the subscriber's try/catch.
- Output-token estimation is skipped for the embeddings operation type: an embedding has no generated output, so output tokens stay 0 instead of hitting the 50-token estimation floor. Input is still estimated from the prompt.
Testing steps
- Enable ai_provider_ollama, run an embeddings op with nomic-embed-text.
- Check the usage log: a row is recorded with input > 0 and output = 0, no watchdog error.
Verified live (Drupal 11.3, ai 1.4.3, Ollama nomic-embed-text): the op records input=14, output=0 (was output=50 before). Kernel test added. Suite green (158 tests, 587 assertions), PHPCS and PHPStan clean.
AI assistance
Found through live multi-provider testing; fix with AI assistance.
Edited by Jérôme Tchania