@ai-sdk/google 3.0.134 → 3.0.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -360,6 +360,14 @@ and long coding or agentic tasks.
360
360
  - Complex requests can run for several minutes. Make sure your HTTP client
361
361
  allows read timeouts of at least 15 to 20 minutes.
362
362
 
363
+ **Grounding across requests.** When a response is continued automatically,
364
+ `providerMetadata.google.groundingMetadataPerRequest` contains the grounding
365
+ metadata from each request, in order. An entry is `null` if that request did
366
+ not return grounding metadata. This preserves earlier Search results even if
367
+ the final request returns none, and keeps citation indices scoped to their
368
+ original request. The existing `groundingMetadata` field keeps its current
369
+ behavior; use the per-request array when inspecting a continued response.
370
+
363
371
  **Usage across requests.** Each continued request re-sends the prompt plus all
364
372
  output so far as input, so its prompt token count includes everything
365
373
  generated before it. `usage` is the sum of all requests, which matches what
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "3.0.134",
3
+ "version": "3.0.136",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ai-sdk/provider": "3.0.19",
40
- "@ai-sdk/provider-utils": "4.0.60"
40
+ "@ai-sdk/provider-utils": "4.0.61"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -428,11 +428,14 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
428
428
  // the prompt plus all output so far as input, so the first request's
429
429
  // prompt token count is kept separately for context window checks.
430
430
  const continuedParts: ContentPartSchema[] = [];
431
+ const groundingMetadataPerRequest: Array<GroundingMetadataSchema | null> =
432
+ [];
431
433
  let continuedUsageMetadata: GoogleGenerativeAIUsageMetadata | undefined;
432
434
  const firstPromptTokenCount = response.usageMetadata?.promptTokenCount;
433
435
 
434
436
  while (true) {
435
437
  const candidate = response.candidates?.[0];
438
+ groundingMetadataPerRequest.push(candidate?.groundingMetadata ?? null);
436
439
  const continuationToken =
437
440
  candidate?.finishReason === 'CONTINUATION'
438
441
  ? candidate.continuationToken
@@ -642,6 +645,9 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
642
645
  [providerOptionsName]: {
643
646
  promptFeedback: response.promptFeedback ?? null,
644
647
  groundingMetadata: candidate?.groundingMetadata ?? null,
648
+ ...(groundingMetadataPerRequest.length > 1
649
+ ? { groundingMetadataPerRequest }
650
+ : {}),
645
651
  urlContextMetadata: candidate?.urlContextMetadata ?? null,
646
652
  safetyRatings: candidate?.safetyRatings ?? null,
647
653
  usageMetadata: usageMetadata ?? null,
@@ -695,6 +701,10 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
695
701
  const { responseHeaders, value: firstResponse } =
696
702
  await streamGenerateContent(args);
697
703
 
704
+ const groundingMetadataPerRequest: Array<GroundingMetadataSchema | null> =
705
+ [];
706
+ let requestGroundingMetadata: GroundingMetadataSchema | null = null;
707
+
698
708
  // Gemini 4 long decode: when a stream reaches the per-request cap while
699
709
  // `maxOutputTokens` budget remains, its last chunk finishes with
700
710
  // `CONTINUATION`. Resend the same request with the continuation token and
@@ -703,12 +713,22 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
703
713
  stream: firstResponse,
704
714
  getContinuationToken: chunk => {
705
715
  const candidate = chunk.candidates?.[0];
716
+ if (candidate?.groundingMetadata != null) {
717
+ requestGroundingMetadata = candidate.groundingMetadata;
718
+ }
706
719
  return candidate?.finishReason === 'CONTINUATION'
707
720
  ? (candidate.continuationToken ?? undefined)
708
721
  : undefined;
709
722
  },
710
- continueStream: async continuationToken =>
711
- (await streamGenerateContent({ ...args, continuationToken })).value,
723
+ continueStream: async continuationToken => {
724
+ const { value } = await streamGenerateContent({
725
+ ...args,
726
+ continuationToken,
727
+ });
728
+ groundingMetadataPerRequest.push(requestGroundingMetadata);
729
+ requestGroundingMetadata = null;
730
+ return value;
731
+ },
712
732
  });
713
733
 
714
734
  let finishReason: LanguageModelV3FinishReason = {
@@ -1293,6 +1313,14 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
1293
1313
  [providerOptionsName]: {
1294
1314
  promptFeedback,
1295
1315
  groundingMetadata: lastGroundingMetadata,
1316
+ ...(groundingMetadataPerRequest.length > 0
1317
+ ? {
1318
+ groundingMetadataPerRequest: [
1319
+ ...groundingMetadataPerRequest,
1320
+ requestGroundingMetadata,
1321
+ ],
1322
+ }
1323
+ : {}),
1296
1324
  urlContextMetadata: lastUrlContextMetadata,
1297
1325
  safetyRatings: lastSafetyRatings,
1298
1326
  usageMetadata: usage ?? null,
@@ -74,6 +74,8 @@ export type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
74
74
  export interface GoogleGenerativeAIProviderMetadata {
75
75
  promptFeedback: GoogleGenerativeAIPromptFeedback | null;
76
76
  groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
77
+ /** Grounding from each automatically continued request, in request order. */
78
+ groundingMetadataPerRequest?: Array<GoogleGenerativeAIGroundingMetadata | null>;
77
79
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
78
80
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
79
81
  usageMetadata: GoogleGenerativeAIUsageMetadata | null;