@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.
@@ -834,7 +834,7 @@ var GoogleGenerativeAILanguageModel = class {
834
834
  };
835
835
  }
836
836
  async doGenerate(options) {
837
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
837
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
838
838
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
839
839
  const mergedHeaders = combineHeaders(
840
840
  await resolve(this.config.headers),
@@ -879,20 +879,28 @@ var GoogleGenerativeAILanguageModel = class {
879
879
  toolName: "code_execution",
880
880
  result: {
881
881
  outcome: part.codeExecutionResult.outcome,
882
- output: part.codeExecutionResult.output
882
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
883
883
  }
884
884
  });
885
885
  lastCodeExecutionToolCallId = void 0;
886
- } else if ("text" in part && part.text != null && part.text.length > 0) {
887
- content.push({
888
- type: part.thought === true ? "reasoning" : "text",
889
- text: part.text,
890
- providerMetadata: part.thoughtSignature ? {
891
- [providerOptionsName]: {
892
- thoughtSignature: part.thoughtSignature
893
- }
894
- } : void 0
895
- });
886
+ } else if ("text" in part && part.text != null) {
887
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
888
+ [providerOptionsName]: {
889
+ thoughtSignature: part.thoughtSignature
890
+ }
891
+ } : void 0;
892
+ if (part.text.length === 0) {
893
+ if (thoughtSignatureMetadata != null && content.length > 0) {
894
+ const lastContent = content[content.length - 1];
895
+ lastContent.providerMetadata = thoughtSignatureMetadata;
896
+ }
897
+ } else {
898
+ content.push({
899
+ type: part.thought === true ? "reasoning" : "text",
900
+ text: part.text,
901
+ providerMetadata: thoughtSignatureMetadata
902
+ });
903
+ }
896
904
  } else if ("functionCall" in part) {
897
905
  content.push({
898
906
  type: "tool-call",
@@ -918,10 +926,10 @@ var GoogleGenerativeAILanguageModel = class {
918
926
  });
919
927
  }
920
928
  }
921
- const sources = (_d = extractSources({
929
+ const sources = (_e = extractSources({
922
930
  groundingMetadata: candidate.groundingMetadata,
923
931
  generateId: this.config.generateId
924
- })) != null ? _d : [];
932
+ })) != null ? _e : [];
925
933
  for (const source of sources) {
926
934
  content.push(source);
927
935
  }
@@ -935,16 +943,16 @@ var GoogleGenerativeAILanguageModel = class {
935
943
  (part) => part.type === "tool-call" && !part.providerExecuted
936
944
  )
937
945
  }),
938
- raw: (_e = candidate.finishReason) != null ? _e : void 0
946
+ raw: (_f = candidate.finishReason) != null ? _f : void 0
939
947
  },
940
948
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
941
949
  warnings,
942
950
  providerMetadata: {
943
951
  [providerOptionsName]: {
944
- promptFeedback: (_f = response.promptFeedback) != null ? _f : null,
945
- groundingMetadata: (_g = candidate.groundingMetadata) != null ? _g : null,
946
- urlContextMetadata: (_h = candidate.urlContextMetadata) != null ? _h : null,
947
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
952
+ promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
953
+ groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
954
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
955
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
948
956
  usageMetadata: usageMetadata != null ? usageMetadata : null
949
957
  }
950
958
  },
@@ -993,7 +1001,7 @@ var GoogleGenerativeAILanguageModel = class {
993
1001
  controller.enqueue({ type: "stream-start", warnings });
994
1002
  },
995
1003
  transform(chunk, controller) {
996
- var _a, _b, _c, _d, _e, _f, _g;
1004
+ var _a, _b, _c, _d, _e, _f, _g, _h;
997
1005
  if (options.includeRawChunks) {
998
1006
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
999
1007
  }
@@ -1045,13 +1053,27 @@ var GoogleGenerativeAILanguageModel = class {
1045
1053
  toolName: "code_execution",
1046
1054
  result: {
1047
1055
  outcome: part.codeExecutionResult.outcome,
1048
- output: part.codeExecutionResult.output
1056
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
1049
1057
  }
1050
1058
  });
1051
1059
  lastCodeExecutionToolCallId = void 0;
1052
1060
  }
1053
- } else if ("text" in part && part.text != null && part.text.length > 0) {
1054
- if (part.thought === true) {
1061
+ } else if ("text" in part && part.text != null) {
1062
+ const thoughtSignatureMetadata = part.thoughtSignature ? {
1063
+ [providerOptionsName]: {
1064
+ thoughtSignature: part.thoughtSignature
1065
+ }
1066
+ } : void 0;
1067
+ if (part.text.length === 0) {
1068
+ if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
1069
+ controller.enqueue({
1070
+ type: "text-delta",
1071
+ id: currentTextBlockId,
1072
+ delta: "",
1073
+ providerMetadata: thoughtSignatureMetadata
1074
+ });
1075
+ }
1076
+ } else if (part.thought === true) {
1055
1077
  if (currentTextBlockId !== null) {
1056
1078
  controller.enqueue({
1057
1079
  type: "text-end",
@@ -1064,22 +1086,14 @@ var GoogleGenerativeAILanguageModel = class {
1064
1086
  controller.enqueue({
1065
1087
  type: "reasoning-start",
1066
1088
  id: currentReasoningBlockId,
1067
- providerMetadata: part.thoughtSignature ? {
1068
- [providerOptionsName]: {
1069
- thoughtSignature: part.thoughtSignature
1070
- }
1071
- } : void 0
1089
+ providerMetadata: thoughtSignatureMetadata
1072
1090
  });
1073
1091
  }
1074
1092
  controller.enqueue({
1075
1093
  type: "reasoning-delta",
1076
1094
  id: currentReasoningBlockId,
1077
1095
  delta: part.text,
1078
- providerMetadata: part.thoughtSignature ? {
1079
- [providerOptionsName]: {
1080
- thoughtSignature: part.thoughtSignature
1081
- }
1082
- } : void 0
1096
+ providerMetadata: thoughtSignatureMetadata
1083
1097
  });
1084
1098
  } else {
1085
1099
  if (currentReasoningBlockId !== null) {
@@ -1094,22 +1108,14 @@ var GoogleGenerativeAILanguageModel = class {
1094
1108
  controller.enqueue({
1095
1109
  type: "text-start",
1096
1110
  id: currentTextBlockId,
1097
- providerMetadata: part.thoughtSignature ? {
1098
- [providerOptionsName]: {
1099
- thoughtSignature: part.thoughtSignature
1100
- }
1101
- } : void 0
1111
+ providerMetadata: thoughtSignatureMetadata
1102
1112
  });
1103
1113
  }
1104
1114
  controller.enqueue({
1105
1115
  type: "text-delta",
1106
1116
  id: currentTextBlockId,
1107
1117
  delta: part.text,
1108
- providerMetadata: part.thoughtSignature ? {
1109
- [providerOptionsName]: {
1110
- thoughtSignature: part.thoughtSignature
1111
- }
1112
- } : void 0
1118
+ providerMetadata: thoughtSignatureMetadata
1113
1119
  });
1114
1120
  }
1115
1121
  } else if ("inlineData" in part) {
@@ -1165,10 +1171,10 @@ var GoogleGenerativeAILanguageModel = class {
1165
1171
  };
1166
1172
  providerMetadata = {
1167
1173
  [providerOptionsName]: {
1168
- promptFeedback: (_d = value.promptFeedback) != null ? _d : null,
1169
- groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
1170
- urlContextMetadata: (_f = candidate.urlContextMetadata) != null ? _f : null,
1171
- safetyRatings: (_g = candidate.safetyRatings) != null ? _g : null
1174
+ promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1175
+ groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1176
+ urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1177
+ safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1172
1178
  }
1173
1179
  };
1174
1180
  if (usageMetadata != null) {
@@ -1374,7 +1380,7 @@ var getContentSchema = () => z3.object({
1374
1380
  }).nullish(),
1375
1381
  codeExecutionResult: z3.object({
1376
1382
  outcome: z3.string(),
1377
- output: z3.string()
1383
+ output: z3.string().nullish()
1378
1384
  }).nullish(),
1379
1385
  text: z3.string().nullish(),
1380
1386
  thought: z3.boolean().nullish(),