Commit 89d8b45
fix(google): make urlMetadata optional in urlContextMetadata schema (#12701)
## Summary
The Gemini API can return `urlContextMetadata: {}` (empty object without
`urlMetadata` key) when Google Search grounding is used but no URLs were
fetched via the URL context tool. The Zod schema expected `urlMetadata`
to always be an array, causing an `AI_APICallError` on an otherwise
valid 200 response.
## Changes
- **`google-generative-ai-language-model.ts`**: Make `urlMetadata` field
`.nullish()` in the `getUrlContextMetadataSchema()` schema.
- **Tests**: Added test case for empty object without `urlMetadata` key.
All urlContextMetadata-related tests pass.
Fixes #12698
---------
Co-authored-by: Dmitrii Troitskii <jsleitor@gmail.com>
Co-authored-by: dancer <josh@afterima.ge>
Co-authored-by: dancer <144584931+dancer@users.noreply.github.com>1 parent 39d0544 commit 89d8b45
File tree
3 files changed
+20
-6
lines changed- .changeset
- packages/google/src
3 files changed
+20
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
333 | 340 | | |
334 | 341 | | |
335 | 342 | | |
| |||
Lines changed: 8 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
974 | 974 | | |
975 | 975 | | |
976 | 976 | | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
983 | 985 | | |
984 | 986 | | |
985 | 987 | | |
| |||
0 commit comments