@ai-sdk/google 3.0.23 → 3.0.24

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.
@@ -268,18 +268,27 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
268
268
  });
269
269
  // Clear the ID after use to avoid accidental reuse.
270
270
  lastCodeExecutionToolCallId = undefined;
271
- } else if ('text' in part && part.text != null && part.text.length > 0) {
272
- content.push({
273
- type: part.thought === true ? 'reasoning' : 'text',
274
- text: part.text,
275
- providerMetadata: part.thoughtSignature
276
- ? {
277
- [providerOptionsName]: {
278
- thoughtSignature: part.thoughtSignature,
279
- },
280
- }
281
- : undefined,
282
- });
271
+ } else if ('text' in part && part.text != null) {
272
+ const thoughtSignatureMetadata = part.thoughtSignature
273
+ ? {
274
+ [providerOptionsName]: {
275
+ thoughtSignature: part.thoughtSignature,
276
+ },
277
+ }
278
+ : undefined;
279
+
280
+ if (part.text.length === 0) {
281
+ if (thoughtSignatureMetadata != null && content.length > 0) {
282
+ const lastContent = content[content.length - 1];
283
+ lastContent.providerMetadata = thoughtSignatureMetadata;
284
+ }
285
+ } else {
286
+ content.push({
287
+ type: part.thought === true ? 'reasoning' : 'text',
288
+ text: part.text,
289
+ providerMetadata: thoughtSignatureMetadata,
290
+ });
291
+ }
283
292
  } else if ('functionCall' in part) {
284
293
  content.push({
285
294
  type: 'tool-call' as const,
@@ -482,12 +491,28 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
482
491
  // Clear the ID after use.
483
492
  lastCodeExecutionToolCallId = undefined;
484
493
  }
485
- } else if (
486
- 'text' in part &&
487
- part.text != null &&
488
- part.text.length > 0
489
- ) {
490
- if (part.thought === true) {
494
+ } else if ('text' in part && part.text != null) {
495
+ const thoughtSignatureMetadata = part.thoughtSignature
496
+ ? {
497
+ [providerOptionsName]: {
498
+ thoughtSignature: part.thoughtSignature,
499
+ },
500
+ }
501
+ : undefined;
502
+
503
+ if (part.text.length === 0) {
504
+ if (
505
+ thoughtSignatureMetadata != null &&
506
+ currentTextBlockId !== null
507
+ ) {
508
+ controller.enqueue({
509
+ type: 'text-delta',
510
+ id: currentTextBlockId,
511
+ delta: '',
512
+ providerMetadata: thoughtSignatureMetadata,
513
+ });
514
+ }
515
+ } else if (part.thought === true) {
491
516
  // End any active text block before starting reasoning
492
517
  if (currentTextBlockId !== null) {
493
518
  controller.enqueue({
@@ -503,13 +528,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
503
528
  controller.enqueue({
504
529
  type: 'reasoning-start',
505
530
  id: currentReasoningBlockId,
506
- providerMetadata: part.thoughtSignature
507
- ? {
508
- [providerOptionsName]: {
509
- thoughtSignature: part.thoughtSignature,
510
- },
511
- }
512
- : undefined,
531
+ providerMetadata: thoughtSignatureMetadata,
513
532
  });
514
533
  }
515
534
 
@@ -517,16 +536,9 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
517
536
  type: 'reasoning-delta',
518
537
  id: currentReasoningBlockId,
519
538
  delta: part.text,
520
- providerMetadata: part.thoughtSignature
521
- ? {
522
- [providerOptionsName]: {
523
- thoughtSignature: part.thoughtSignature,
524
- },
525
- }
526
- : undefined,
539
+ providerMetadata: thoughtSignatureMetadata,
527
540
  });
528
541
  } else {
529
- // End any active reasoning block before starting text
530
542
  if (currentReasoningBlockId !== null) {
531
543
  controller.enqueue({
532
544
  type: 'reasoning-end',
@@ -535,19 +547,12 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
535
547
  currentReasoningBlockId = null;
536
548
  }
537
549
 
538
- // Start new text block if not already active
539
550
  if (currentTextBlockId === null) {
540
551
  currentTextBlockId = String(blockCounter++);
541
552
  controller.enqueue({
542
553
  type: 'text-start',
543
554
  id: currentTextBlockId,
544
- providerMetadata: part.thoughtSignature
545
- ? {
546
- [providerOptionsName]: {
547
- thoughtSignature: part.thoughtSignature,
548
- },
549
- }
550
- : undefined,
555
+ providerMetadata: thoughtSignatureMetadata,
551
556
  });
552
557
  }
553
558
 
@@ -555,13 +560,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
555
560
  type: 'text-delta',
556
561
  id: currentTextBlockId,
557
562
  delta: part.text,
558
- providerMetadata: part.thoughtSignature
559
- ? {
560
- [providerOptionsName]: {
561
- thoughtSignature: part.thoughtSignature,
562
- },
563
- }
564
- : undefined,
563
+ providerMetadata: thoughtSignatureMetadata,
565
564
  });
566
565
  }
567
566
  } else if ('inlineData' in part) {
@@ -644,7 +643,6 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
644
643
  },
645
644
 
646
645
  flush(controller) {
647
- // Close any open blocks before finishing
648
646
  if (currentTextBlockId !== null) {
649
647
  controller.enqueue({
650
648
  type: 'text-end',