@ai-sdk/google 2.0.0-alpha.9 → 2.0.0-beta.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [742b7be]
8
+ - Updated dependencies [7cddb72]
9
+ - Updated dependencies [ccce59b]
10
+ - Updated dependencies [e2b9e4b]
11
+ - Updated dependencies [45c1ea2]
12
+ - Updated dependencies [e025824]
13
+ - Updated dependencies [0d06df6]
14
+ - Updated dependencies [472524a]
15
+ - Updated dependencies [dd3ff01]
16
+ - Updated dependencies [7435eb5]
17
+ - Updated dependencies [cb68df0]
18
+ - Updated dependencies [bfdca8d]
19
+ - Updated dependencies [44f4aba]
20
+ - Updated dependencies [023ba40]
21
+ - Updated dependencies [5e57fae]
22
+ - Updated dependencies [71f938d]
23
+ - Updated dependencies [28a5ed5]
24
+ - @ai-sdk/provider@2.0.0-beta.1
25
+ - @ai-sdk/provider-utils@3.0.0-beta.1
26
+
27
+ ## 2.0.0-alpha.15
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [48d257a]
32
+ - Updated dependencies [8ba77a7]
33
+ - @ai-sdk/provider@2.0.0-alpha.15
34
+ - @ai-sdk/provider-utils@3.0.0-alpha.15
35
+
36
+ ## 2.0.0-alpha.14
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [b5da06a]
41
+ - Updated dependencies [63f9e9b]
42
+ - Updated dependencies [2e13791]
43
+ - @ai-sdk/provider@2.0.0-alpha.14
44
+ - @ai-sdk/provider-utils@3.0.0-alpha.14
45
+
46
+ ## 2.0.0-alpha.13
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [68ecf2f]
51
+ - @ai-sdk/provider@2.0.0-alpha.13
52
+ - @ai-sdk/provider-utils@3.0.0-alpha.13
53
+
54
+ ## 2.0.0-alpha.12
55
+
56
+ ### Patch Changes
57
+
58
+ - e2aceaf: feat: add raw chunk support
59
+ - Updated dependencies [e2aceaf]
60
+ - @ai-sdk/provider@2.0.0-alpha.12
61
+ - @ai-sdk/provider-utils@3.0.0-alpha.12
62
+
63
+ ## 2.0.0-alpha.11
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [c1e6647]
68
+ - @ai-sdk/provider@2.0.0-alpha.11
69
+ - @ai-sdk/provider-utils@3.0.0-alpha.11
70
+
71
+ ## 2.0.0-alpha.10
72
+
73
+ ### Patch Changes
74
+
75
+ - 581a9be: fix (provider/google): prevent error when thinking signature is used
76
+ - Updated dependencies [c4df419]
77
+ - @ai-sdk/provider@2.0.0-alpha.10
78
+ - @ai-sdk/provider-utils@3.0.0-alpha.10
79
+
3
80
  ## 2.0.0-alpha.9
4
81
 
5
82
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -36,10 +36,13 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
36
36
  responseModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<["TEXT", "IMAGE"]>, "many">>;
37
37
  thinkingConfig: z.ZodOptional<z.ZodObject<{
38
38
  thinkingBudget: z.ZodOptional<z.ZodNumber>;
39
+ includeThoughts: z.ZodOptional<z.ZodBoolean>;
39
40
  }, "strip", z.ZodTypeAny, {
40
41
  thinkingBudget?: number | undefined;
42
+ includeThoughts?: boolean | undefined;
41
43
  }, {
42
44
  thinkingBudget?: number | undefined;
45
+ includeThoughts?: boolean | undefined;
43
46
  }>>;
44
47
  /**
45
48
  Optional.
@@ -110,6 +113,7 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
110
113
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
111
114
  thinkingConfig?: {
112
115
  thinkingBudget?: number | undefined;
116
+ includeThoughts?: boolean | undefined;
113
117
  } | undefined;
114
118
  cachedContent?: string | undefined;
115
119
  structuredOutputs?: boolean | undefined;
@@ -128,6 +132,7 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
128
132
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
129
133
  thinkingConfig?: {
130
134
  thinkingBudget?: number | undefined;
135
+ includeThoughts?: boolean | undefined;
131
136
  } | undefined;
132
137
  cachedContent?: string | undefined;
133
138
  structuredOutputs?: boolean | undefined;
package/dist/index.d.ts CHANGED
@@ -36,10 +36,13 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
36
36
  responseModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<["TEXT", "IMAGE"]>, "many">>;
37
37
  thinkingConfig: z.ZodOptional<z.ZodObject<{
38
38
  thinkingBudget: z.ZodOptional<z.ZodNumber>;
39
+ includeThoughts: z.ZodOptional<z.ZodBoolean>;
39
40
  }, "strip", z.ZodTypeAny, {
40
41
  thinkingBudget?: number | undefined;
42
+ includeThoughts?: boolean | undefined;
41
43
  }, {
42
44
  thinkingBudget?: number | undefined;
45
+ includeThoughts?: boolean | undefined;
43
46
  }>>;
44
47
  /**
45
48
  Optional.
@@ -110,6 +113,7 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
110
113
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
111
114
  thinkingConfig?: {
112
115
  thinkingBudget?: number | undefined;
116
+ includeThoughts?: boolean | undefined;
113
117
  } | undefined;
114
118
  cachedContent?: string | undefined;
115
119
  structuredOutputs?: boolean | undefined;
@@ -128,6 +132,7 @@ declare const googleGenerativeAIProviderOptions: z.ZodObject<{
128
132
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
129
133
  thinkingConfig?: {
130
134
  thinkingBudget?: number | undefined;
135
+ includeThoughts?: boolean | undefined;
131
136
  } | undefined;
132
137
  cachedContent?: string | undefined;
133
138
  structuredOutputs?: boolean | undefined;
package/dist/index.js CHANGED
@@ -330,7 +330,7 @@ function convertToGoogleGenerativeAIMessages(prompt) {
330
330
  return {
331
331
  functionCall: {
332
332
  name: part.toolName,
333
- args: part.args
333
+ args: part.input
334
334
  }
335
335
  };
336
336
  }
@@ -348,7 +348,7 @@ function convertToGoogleGenerativeAIMessages(prompt) {
348
348
  name: part.toolName,
349
349
  response: {
350
350
  name: part.toolName,
351
- content: part.result
351
+ content: part.output.value
352
352
  }
353
353
  }
354
354
  }))
@@ -384,7 +384,8 @@ var dynamicRetrievalConfig = import_zod4.z.object({
384
384
  var googleGenerativeAIProviderOptions = import_zod4.z.object({
385
385
  responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).optional(),
386
386
  thinkingConfig: import_zod4.z.object({
387
- thinkingBudget: import_zod4.z.number().optional()
387
+ thinkingBudget: import_zod4.z.number().optional(),
388
+ includeThoughts: import_zod4.z.boolean().optional()
388
389
  }).optional(),
389
390
  /**
390
391
  Optional.
@@ -488,7 +489,7 @@ function prepareTools({
488
489
  functionDeclarations.push({
489
490
  name: tool.name,
490
491
  description: (_a = tool.description) != null ? _a : "",
491
- parameters: convertJSONSchemaToOpenAPISchema(tool.parameters)
492
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
492
493
  });
493
494
  }
494
495
  }
@@ -595,13 +596,19 @@ var GoogleGenerativeAILanguageModel = class {
595
596
  toolChoice,
596
597
  providerOptions
597
598
  }) {
598
- var _a, _b;
599
+ var _a, _b, _c;
599
600
  const warnings = [];
600
601
  const googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
601
602
  provider: "google",
602
603
  providerOptions,
603
604
  schema: googleGenerativeAIProviderOptions
604
605
  });
606
+ if (((_a = googleOptions == null ? void 0 : googleOptions.thinkingConfig) == null ? void 0 : _a.includeThoughts) === true && !this.config.provider.startsWith("google.vertex.")) {
607
+ warnings.push({
608
+ type: "other",
609
+ message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
610
+ });
611
+ }
605
612
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
606
613
  const {
607
614
  tools: googleTools,
@@ -610,7 +617,7 @@ var GoogleGenerativeAILanguageModel = class {
610
617
  } = prepareTools({
611
618
  tools,
612
619
  toolChoice,
613
- useSearchGrounding: (_a = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _a : false,
620
+ useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
614
621
  dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
615
622
  modelId: this.modelId
616
623
  });
@@ -631,7 +638,7 @@ var GoogleGenerativeAILanguageModel = class {
631
638
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
632
639
  // so this is needed as an escape hatch:
633
640
  // TODO convert into provider option
634
- ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
641
+ ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
635
642
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
636
643
  audioTimestamp: googleOptions.audioTimestamp
637
644
  },
@@ -675,16 +682,20 @@ var GoogleGenerativeAILanguageModel = class {
675
682
  const candidate = response.candidates[0];
676
683
  const content = [];
677
684
  const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : (_a = candidate.content.parts) != null ? _a : [];
685
+ const usageMetadata = response.usageMetadata;
678
686
  for (const part of parts) {
679
- if ("text" in part && part.text.length > 0) {
680
- content.push({ type: "text", text: part.text });
687
+ if ("text" in part && part.text != null && part.text.length > 0) {
688
+ if (part.thought === true) {
689
+ content.push({ type: "reasoning", text: part.text });
690
+ } else {
691
+ content.push({ type: "text", text: part.text });
692
+ }
681
693
  } else if ("functionCall" in part) {
682
694
  content.push({
683
695
  type: "tool-call",
684
- toolCallType: "function",
685
696
  toolCallId: this.config.generateId(),
686
697
  toolName: part.functionCall.name,
687
- args: JSON.stringify(part.functionCall.args)
698
+ input: JSON.stringify(part.functionCall.args)
688
699
  });
689
700
  } else if ("inlineData" in part) {
690
701
  content.push({
@@ -701,7 +712,6 @@ var GoogleGenerativeAILanguageModel = class {
701
712
  for (const source of sources) {
702
713
  content.push(source);
703
714
  }
704
- const usageMetadata = response.usageMetadata;
705
715
  return {
706
716
  content,
707
717
  finishReason: mapGoogleGenerativeAIFinishReason({
@@ -757,6 +767,9 @@ var GoogleGenerativeAILanguageModel = class {
757
767
  let providerMetadata = void 0;
758
768
  const generateId2 = this.config.generateId;
759
769
  let hasToolCalls = false;
770
+ let currentTextBlockId = null;
771
+ let currentReasoningBlockId = null;
772
+ let blockCounter = 0;
760
773
  return {
761
774
  stream: response.pipeThrough(
762
775
  new TransformStream({
@@ -764,7 +777,10 @@ var GoogleGenerativeAILanguageModel = class {
764
777
  controller.enqueue({ type: "stream-start", warnings });
765
778
  },
766
779
  transform(chunk, controller) {
767
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
780
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
781
+ if (options.includeRawChunks) {
782
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
783
+ }
768
784
  if (!chunk.success) {
769
785
  controller.enqueue({ type: "error", error: chunk.error });
770
786
  return;
@@ -784,9 +800,51 @@ var GoogleGenerativeAILanguageModel = class {
784
800
  }
785
801
  const content = candidate.content;
786
802
  if (content != null) {
787
- const deltaText = getTextFromParts(content.parts);
788
- if (deltaText != null) {
789
- controller.enqueue(deltaText);
803
+ const parts = (_g = content.parts) != null ? _g : [];
804
+ for (const part of parts) {
805
+ if ("text" in part && part.text != null && part.text.length > 0) {
806
+ if (part.thought === true) {
807
+ if (currentTextBlockId !== null) {
808
+ controller.enqueue({
809
+ type: "text-end",
810
+ id: currentTextBlockId
811
+ });
812
+ currentTextBlockId = null;
813
+ }
814
+ if (currentReasoningBlockId === null) {
815
+ currentReasoningBlockId = String(blockCounter++);
816
+ controller.enqueue({
817
+ type: "reasoning-start",
818
+ id: currentReasoningBlockId
819
+ });
820
+ }
821
+ controller.enqueue({
822
+ type: "reasoning-delta",
823
+ id: currentReasoningBlockId,
824
+ delta: part.text
825
+ });
826
+ } else {
827
+ if (currentReasoningBlockId !== null) {
828
+ controller.enqueue({
829
+ type: "reasoning-end",
830
+ id: currentReasoningBlockId
831
+ });
832
+ currentReasoningBlockId = null;
833
+ }
834
+ if (currentTextBlockId === null) {
835
+ currentTextBlockId = String(blockCounter++);
836
+ controller.enqueue({
837
+ type: "text-start",
838
+ id: currentTextBlockId
839
+ });
840
+ }
841
+ controller.enqueue({
842
+ type: "text-delta",
843
+ id: currentTextBlockId,
844
+ delta: part.text
845
+ });
846
+ }
847
+ }
790
848
  }
791
849
  const inlineDataParts = getInlineDataParts(content.parts);
792
850
  if (inlineDataParts != null) {
@@ -805,18 +863,24 @@ var GoogleGenerativeAILanguageModel = class {
805
863
  if (toolCallDeltas != null) {
806
864
  for (const toolCall of toolCallDeltas) {
807
865
  controller.enqueue({
808
- type: "tool-call-delta",
809
- toolCallType: "function",
810
- toolCallId: toolCall.toolCallId,
811
- toolName: toolCall.toolName,
812
- argsTextDelta: toolCall.args
866
+ type: "tool-input-start",
867
+ id: toolCall.toolCallId,
868
+ toolName: toolCall.toolName
869
+ });
870
+ controller.enqueue({
871
+ type: "tool-input-delta",
872
+ id: toolCall.toolCallId,
873
+ delta: toolCall.args
874
+ });
875
+ controller.enqueue({
876
+ type: "tool-input-end",
877
+ id: toolCall.toolCallId
813
878
  });
814
879
  controller.enqueue({
815
880
  type: "tool-call",
816
- toolCallType: "function",
817
881
  toolCallId: toolCall.toolCallId,
818
882
  toolName: toolCall.toolName,
819
- args: toolCall.args
883
+ input: toolCall.args
820
884
  });
821
885
  hasToolCalls = true;
822
886
  }
@@ -827,22 +891,34 @@ var GoogleGenerativeAILanguageModel = class {
827
891
  finishReason: candidate.finishReason,
828
892
  hasToolCalls
829
893
  });
830
- const sources = (_g = extractSources({
894
+ const sources = (_h = extractSources({
831
895
  groundingMetadata: candidate.groundingMetadata,
832
896
  generateId: generateId2
833
- })) != null ? _g : [];
897
+ })) != null ? _h : [];
834
898
  for (const source of sources) {
835
899
  controller.enqueue(source);
836
900
  }
837
901
  providerMetadata = {
838
902
  google: {
839
- groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
840
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null
903
+ groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
904
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
841
905
  }
842
906
  };
843
907
  }
844
908
  },
845
909
  flush(controller) {
910
+ if (currentTextBlockId !== null) {
911
+ controller.enqueue({
912
+ type: "text-end",
913
+ id: currentTextBlockId
914
+ });
915
+ }
916
+ if (currentReasoningBlockId !== null) {
917
+ controller.enqueue({
918
+ type: "reasoning-end",
919
+ id: currentReasoningBlockId
920
+ });
921
+ }
846
922
  controller.enqueue({
847
923
  type: "finish",
848
924
  finishReason,
@@ -866,19 +942,11 @@ function getToolCallsFromParts({
866
942
  );
867
943
  return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
868
944
  type: "tool-call",
869
- toolCallType: "function",
870
945
  toolCallId: generateId2(),
871
946
  toolName: part.functionCall.name,
872
947
  args: JSON.stringify(part.functionCall.args)
873
948
  }));
874
949
  }
875
- function getTextFromParts(parts) {
876
- const textParts = parts == null ? void 0 : parts.filter((part) => "text" in part);
877
- return textParts == null || textParts.length === 0 ? void 0 : {
878
- type: "text",
879
- text: textParts.map((part) => part.text).join("")
880
- };
881
- }
882
950
  function getInlineDataParts(parts) {
883
951
  return parts == null ? void 0 : parts.filter(
884
952
  (part) => "inlineData" in part
@@ -900,12 +968,9 @@ function extractSources({
900
968
  }));
901
969
  }
902
970
  var contentSchema = import_zod5.z.object({
903
- role: import_zod5.z.string(),
904
971
  parts: import_zod5.z.array(
905
972
  import_zod5.z.union([
906
- import_zod5.z.object({
907
- text: import_zod5.z.string()
908
- }),
973
+ // note: order matters since text can be fully empty
909
974
  import_zod5.z.object({
910
975
  functionCall: import_zod5.z.object({
911
976
  name: import_zod5.z.string(),
@@ -917,6 +982,10 @@ var contentSchema = import_zod5.z.object({
917
982
  mimeType: import_zod5.z.string(),
918
983
  data: import_zod5.z.string()
919
984
  })
985
+ }),
986
+ import_zod5.z.object({
987
+ text: import_zod5.z.string().nullish(),
988
+ thought: import_zod5.z.boolean().nullish()
920
989
  })
921
990
  ])
922
991
  ).nullish()