@ai-sdk/google 3.0.22 → 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.
@@ -96,7 +96,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
96
96
  } | null | undefined;
97
97
  codeExecutionResult?: {
98
98
  outcome: string;
99
- output: string;
99
+ output?: string | null | undefined;
100
100
  } | null | undefined;
101
101
  text?: string | null | undefined;
102
102
  thought?: boolean | null | undefined;
@@ -96,7 +96,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
96
96
  } | null | undefined;
97
97
  codeExecutionResult?: {
98
98
  outcome: string;
99
- output: string;
99
+ output?: string | null | undefined;
100
100
  } | null | undefined;
101
101
  text?: string | null | undefined;
102
102
  thought?: boolean | null | undefined;
@@ -845,7 +845,7 @@ var GoogleGenerativeAILanguageModel = class {
845
845
  };
846
846
  }
847
847
  async doGenerate(options) {
848
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
848
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
849
849
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
850
850
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
851
851
  await (0, import_provider_utils4.resolve)(this.config.headers),
@@ -890,20 +890,28 @@ var GoogleGenerativeAILanguageModel = class {
890
890
  toolName: "code_execution",
891
891
  result: {
892
892
  outcome: part.codeExecutionResult.outcome,
893
- output: part.codeExecutionResult.output
893
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
894
894
  }
895
895
  });
896
896
  lastCodeExecutionToolCallId = void 0;
897
- } else if ("text" in part && part.text != null && part.text.length > 0) {
898
- content.push({
899
- type: part.thought === true ? "reasoning" : "text",
900
- text: part.text,
901
- providerMetadata: part.thoughtSignature ? {
902
- [providerOptionsName]: {
903
- thoughtSignature: part.thoughtSignature
904
- }
905
- } : void 0
906
- });
897
+ } else if ("text" in part && part.text != null) {
898
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
899
+ [providerOptionsName]: {
900
+ thoughtSignature: part.thoughtSignature
901
+ }
902
+ } : void 0;
903
+ if (part.text.length === 0) {
904
+ if (thoughtSignatureMetadata != null && content.length > 0) {
905
+ const lastContent = content[content.length - 1];
906
+ lastContent.providerMetadata = thoughtSignatureMetadata;
907
+ }
908
+ } else {
909
+ content.push({
910
+ type: part.thought === true ? "reasoning" : "text",
911
+ text: part.text,
912
+ providerMetadata: thoughtSignatureMetadata
913
+ });
914
+ }
907
915
  } else if ("functionCall" in part) {
908
916
  content.push({
909
917
  type: "tool-call",
@@ -929,10 +937,10 @@ var GoogleGenerativeAILanguageModel = class {
929
937
  });
930
938
  }
931
939
  }
932
- const sources = (_d = extractSources({
940
+ const sources = (_e = extractSources({
933
941
  groundingMetadata: candidate.groundingMetadata,
934
942
  generateId: this.config.generateId
935
- })) != null ? _d : [];
943
+ })) != null ? _e : [];
936
944
  for (const source of sources) {
937
945
  content.push(source);
938
946
  }
@@ -946,16 +954,16 @@ var GoogleGenerativeAILanguageModel = class {
946
954
  (part) => part.type === "tool-call" && !part.providerExecuted
947
955
  )
948
956
  }),
949
- raw: (_e = candidate.finishReason) != null ? _e : void 0
957
+ raw: (_f = candidate.finishReason) != null ? _f : void 0
950
958
  },
951
959
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
952
960
  warnings,
953
961
  providerMetadata: {
954
962
  [providerOptionsName]: {
955
- promptFeedback: (_f = response.promptFeedback) != null ? _f : null,
956
- groundingMetadata: (_g = candidate.groundingMetadata) != null ? _g : null,
957
- urlContextMetadata: (_h = candidate.urlContextMetadata) != null ? _h : null,
958
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
963
+ promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
964
+ groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
965
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
966
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
959
967
  usageMetadata: usageMetadata != null ? usageMetadata : null
960
968
  }
961
969
  },
@@ -1004,7 +1012,7 @@ var GoogleGenerativeAILanguageModel = class {
1004
1012
  controller.enqueue({ type: "stream-start", warnings });
1005
1013
  },
1006
1014
  transform(chunk, controller) {
1007
- var _a, _b, _c, _d, _e, _f, _g;
1015
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1008
1016
  if (options.includeRawChunks) {
1009
1017
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1010
1018
  }
@@ -1056,13 +1064,27 @@ var GoogleGenerativeAILanguageModel = class {
1056
1064
  toolName: "code_execution",
1057
1065
  result: {
1058
1066
  outcome: part.codeExecutionResult.outcome,
1059
- output: part.codeExecutionResult.output
1067
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
1060
1068
  }
1061
1069
  });
1062
1070
  lastCodeExecutionToolCallId = void 0;
1063
1071
  }
1064
- } else if ("text" in part && part.text != null && part.text.length > 0) {
1065
- if (part.thought === true) {
1072
+ } else if ("text" in part && part.text != null) {
1073
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
1074
+ [providerOptionsName]: {
1075
+ thoughtSignature: part.thoughtSignature
1076
+ }
1077
+ } : void 0;
1078
+ if (part.text.length === 0) {
1079
+ if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
1080
+ controller.enqueue({
1081
+ type: "text-delta",
1082
+ id: currentTextBlockId,
1083
+ delta: "",
1084
+ providerMetadata: thoughtSignatureMetadata
1085
+ });
1086
+ }
1087
+ } else if (part.thought === true) {
1066
1088
  if (currentTextBlockId !== null) {
1067
1089
  controller.enqueue({
1068
1090
  type: "text-end",
@@ -1075,22 +1097,14 @@ var GoogleGenerativeAILanguageModel = class {
1075
1097
  controller.enqueue({
1076
1098
  type: "reasoning-start",
1077
1099
  id: currentReasoningBlockId,
1078
- providerMetadata: part.thoughtSignature ? {
1079
- [providerOptionsName]: {
1080
- thoughtSignature: part.thoughtSignature
1081
- }
1082
- } : void 0
1100
+ providerMetadata: thoughtSignatureMetadata
1083
1101
  });
1084
1102
  }
1085
1103
  controller.enqueue({
1086
1104
  type: "reasoning-delta",
1087
1105
  id: currentReasoningBlockId,
1088
1106
  delta: part.text,
1089
- providerMetadata: part.thoughtSignature ? {
1090
- [providerOptionsName]: {
1091
- thoughtSignature: part.thoughtSignature
1092
- }
1093
- } : void 0
1107
+ providerMetadata: thoughtSignatureMetadata
1094
1108
  });
1095
1109
  } else {
1096
1110
  if (currentReasoningBlockId !== null) {
@@ -1105,22 +1119,14 @@ var GoogleGenerativeAILanguageModel = class {
1105
1119
  controller.enqueue({
1106
1120
  type: "text-start",
1107
1121
  id: currentTextBlockId,
1108
- providerMetadata: part.thoughtSignature ? {
1109
- [providerOptionsName]: {
1110
- thoughtSignature: part.thoughtSignature
1111
- }
1112
- } : void 0
1122
+ providerMetadata: thoughtSignatureMetadata
1113
1123
  });
1114
1124
  }
1115
1125
  controller.enqueue({
1116
1126
  type: "text-delta",
1117
1127
  id: currentTextBlockId,
1118
1128
  delta: part.text,
1119
- providerMetadata: part.thoughtSignature ? {
1120
- [providerOptionsName]: {
1121
- thoughtSignature: part.thoughtSignature
1122
- }
1123
- } : void 0
1129
+ providerMetadata: thoughtSignatureMetadata
1124
1130
  });
1125
1131
  }
1126
1132
  } else if ("inlineData" in part) {
@@ -1176,10 +1182,10 @@ var GoogleGenerativeAILanguageModel = class {
1176
1182
  };
1177
1183
  providerMetadata = {
1178
1184
  [providerOptionsName]: {
1179
- promptFeedback: (_d = value.promptFeedback) != null ? _d : null,
1180
- groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
1181
- urlContextMetadata: (_f = candidate.urlContextMetadata) != null ? _f : null,
1182
- safetyRatings: (_g = candidate.safetyRatings) != null ? _g : null
1185
+ promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1186
+ groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1187
+ urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1188
+ safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1183
1189
  }
1184
1190
  };
1185
1191
  if (usageMetadata != null) {
@@ -1385,7 +1391,7 @@ var getContentSchema = () => import_v43.z.object({
1385
1391
  }).nullish(),
1386
1392
  codeExecutionResult: import_v43.z.object({
1387
1393
  outcome: import_v43.z.string(),
1388
- output: import_v43.z.string()
1394
+ output: import_v43.z.string().nullish()
1389
1395
  }).nullish(),
1390
1396
  text: import_v43.z.string().nullish(),
1391
1397
  thought: import_v43.z.boolean().nullish(),