@ai-sdk/google 4.0.17 → 4.0.19

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.
@@ -498,7 +498,7 @@ The response will contain the tool calls and results from the code execution.
498
498
  With [Google Search grounding](https://ai.google.dev/gemini-api/docs/google-search),
499
499
  the model has access to the latest information using Google Search.
500
500
 
501
- ```ts highlight="8,17-20"
501
+ ```ts highlight="8,17-19"
502
502
  import { google } from '@ai-sdk/google';
503
503
  import { GoogleProviderMetadata } from '@ai-sdk/google';
504
504
  import { generateText } from 'ai';
@@ -657,7 +657,7 @@ Google provides a provider-defined URL context tool.
657
657
 
658
658
  The URL context tool allows you to provide specific URLs that you want the model to analyze directly in from the prompt.
659
659
 
660
- ```ts highlight="9,13-17"
660
+ ```ts highlight="9,13-15"
661
661
  import { google } from '@ai-sdk/google';
662
662
  import { generateText } from 'ai';
663
663
 
@@ -818,7 +818,7 @@ This enables the model to provide answers based on your specific data sources an
818
818
  Google provider (`@ai-sdk/google`) to use this feature.
819
819
  </Note>
820
820
 
821
- ```ts highlight="8,17-20"
821
+ ```ts highlight="5-8,13-17,25-27"
822
822
  import { createGoogleVertex } from '@ai-sdk/google-vertex';
823
823
  import { GoogleProviderMetadata } from '@ai-sdk/google';
824
824
  import { generateText } from 'ai';
@@ -2024,7 +2024,7 @@ spoken text, so `instructions: 'Say cheerfully'` with `text: 'Hello'` speaks `Sa
2024
2024
  For multi-speaker dialogue, pass a `multiSpeakerVoiceConfig` through `providerOptions`. Each speaker
2025
2025
  name must match a name used in the input text. When set, it overrides the top-level `voice`.
2026
2026
 
2027
- ```ts highlight="8-23"
2027
+ ```ts highlight="7-22"
2028
2028
  import { generateSpeech } from 'ai';
2029
2029
  import { google, type GoogleSpeechModelOptions } from '@ai-sdk/google';
2030
2030
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.17",
3
+ "version": "4.0.19",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.3",
39
- "@ai-sdk/provider-utils": "5.0.10"
39
+ "@ai-sdk/provider-utils": "5.0.11"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "22.19.19",
@@ -414,7 +414,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
414
414
 
415
415
  const usageMetadata = response.usageMetadata;
416
416
 
417
- // Associates a code execution result with its preceding call.
417
+ // Associates code execution results with their preceding call.
418
418
  let lastCodeExecutionToolCallId: string | undefined;
419
419
  // Associates a server-side tool response with its preceding call (tool combination).
420
420
  let lastServerToolCallId: string | undefined;
@@ -435,7 +435,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
435
435
  } else if ('codeExecutionResult' in part && part.codeExecutionResult) {
436
436
  content.push({
437
437
  type: 'tool-result',
438
- // Assumes a result directly follows its corresponding call part.
438
+ // Results correspond to the most recent executable code part.
439
439
  toolCallId: lastCodeExecutionToolCallId!,
440
440
  toolName: 'code_execution',
441
441
  result: {
@@ -443,8 +443,6 @@ export class GoogleLanguageModel implements LanguageModelV4 {
443
443
  output: part.codeExecutionResult.output ?? '',
444
444
  },
445
445
  });
446
- // Clear the ID after use to avoid accidental reuse.
447
- lastCodeExecutionToolCallId = undefined;
448
446
  } else if ('text' in part && part.text != null) {
449
447
  const thoughtSignatureMetadata = part.thoughtSignature
450
448
  ? wrapProviderMetadata({
@@ -569,7 +567,8 @@ export class GoogleLanguageModel implements LanguageModelV4 {
569
567
  } satisfies GoogleProviderMetadata),
570
568
  request: { body: args },
571
569
  response: {
572
- // TODO timestamp, model id, id
570
+ // TODO timestamp, model id
571
+ id: response.responseId ?? undefined,
573
572
  headers: responseHeaders,
574
573
  body: rawResponse,
575
574
  },
@@ -615,6 +614,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
615
614
 
616
615
  const generateId = this.config.generateId;
617
616
  let hasToolCalls = false;
617
+ let hasEmittedResponseMetadata = false;
618
618
 
619
619
  // Track active blocks to group consecutive parts of same type
620
620
  let currentTextBlockId: string | null = null;
@@ -623,7 +623,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
623
623
 
624
624
  // Track emitted sources to prevent duplicates
625
625
  const emittedSourceUrls = new Set<string>();
626
- // Associates a code execution result with its preceding call.
626
+ // Associates code execution results with their preceding call.
627
627
  let lastCodeExecutionToolCallId: string | undefined;
628
628
  // Associates a server-side tool response with its preceding call (tool combination).
629
629
  let lastServerToolCallId: string | undefined;
@@ -693,6 +693,14 @@ export class GoogleLanguageModel implements LanguageModelV4 {
693
693
 
694
694
  const value = chunk.value;
695
695
 
696
+ if (!hasEmittedResponseMetadata && value.responseId != null) {
697
+ hasEmittedResponseMetadata = true;
698
+ controller.enqueue({
699
+ type: 'response-metadata',
700
+ id: value.responseId,
701
+ });
702
+ }
703
+
696
704
  const usageMetadata = value.usageMetadata;
697
705
 
698
706
  if (usageMetadata != null) {
@@ -751,7 +759,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
751
759
  'codeExecutionResult' in part &&
752
760
  part.codeExecutionResult
753
761
  ) {
754
- // Assumes a result directly follows its corresponding call part.
762
+ // Results correspond to the most recent executable code part.
755
763
  const toolCallId = lastCodeExecutionToolCallId;
756
764
 
757
765
  if (toolCallId) {
@@ -764,8 +772,6 @@ export class GoogleLanguageModel implements LanguageModelV4 {
764
772
  output: part.codeExecutionResult.output ?? '',
765
773
  },
766
774
  });
767
- // Clear the ID after use.
768
- lastCodeExecutionToolCallId = undefined;
769
775
  }
770
776
  } else if ('text' in part && part.text != null) {
771
777
  const thoughtSignatureMetadata = part.thoughtSignature
@@ -1531,6 +1537,7 @@ export const getUrlContextMetadataSchema = () =>
1531
1537
  const responseSchema = lazySchema(() =>
1532
1538
  zodSchema(
1533
1539
  z.object({
1540
+ responseId: z.string().nullish(),
1534
1541
  candidates: z.array(
1535
1542
  z.object({
1536
1543
  content: getContentSchema().nullish().or(z.object({}).strict()),
@@ -1577,6 +1584,7 @@ export type UsageMetadataSchema = NonNullable<
1577
1584
  const chunkSchema = lazySchema(() =>
1578
1585
  zodSchema(
1579
1586
  z.object({
1587
+ responseId: z.string().nullish(),
1580
1588
  candidates: z
1581
1589
  .array(
1582
1590
  z.object({