SIGN IN SIGN UP

fix: preserve complete Google Generative Language raw usage metadata (#19827)

## Background

Google generateContent and SSE responses lost documented and
forward-compatible usageMetadata fields from public usage.raw, including
tool-use and cache token details.

## Root Cause

The shared Google usage schema omitted documented fields and used
stripping Zod objects at both the usage and token-detail levels. The
original replay confirmed provider-boundary metadata was removed before
convertGoogleUsage assigned the parsed object to raw.

## Summary

Made only usage metadata and token-detail schemas loose, explicitly
validated the missing documented fields, retained existing normalized
token calculations, and added a patch changeset.

## Testing

Added normal and SSE regression coverage for all documented fields,
unknown top-level and nested properties, final streaming usage
selection, unchanged normalization, and invalid known-field rejection.

## End-to-end Validation

- `functions.replay_original_reproduction`: completed successfully with
matching normal and streaming provider-boundary and final usage.raw
objects.
- `pnpm -C examples/ai-functions exec tsx -e <live Google Search
audit>`: live generate and stream calls both preserved tool-use usage
metadata with deep equality.

## Related Issues

Fixes #19822

Closes #19825

---------

Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: gr2m <39992+gr2m@users.noreply.github.com>
A
ai-sdk-factory[bot] committed
3ad9da96a3a4b096a0e68b0dcd8c7d8fb5fb44ff
Parent: c427238
Committed by GitHub <noreply@github.com> on 8/27/2026, 5:45:33 PM