@ai-sdk/google 4.0.0-beta.0 → 4.0.0-beta.10

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.
@@ -254,6 +254,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
254
254
  mimeType: part.mediaType,
255
255
  data: convertToBase64(part.data)
256
256
  },
257
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
257
258
  thoughtSignature
258
259
  };
259
260
  }
@@ -627,6 +628,7 @@ function prepareTools({
627
628
  };
628
629
  }
629
630
  const functionDeclarations = [];
631
+ let hasStrictTools = false;
630
632
  for (const tool of tools) {
631
633
  switch (tool.type) {
632
634
  case "function":
@@ -635,6 +637,9 @@ function prepareTools({
635
637
  description: (_a = tool.description) != null ? _a : "",
636
638
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
637
639
  });
640
+ if (tool.strict === true) {
641
+ hasStrictTools = true;
642
+ }
638
643
  break;
639
644
  default:
640
645
  toolWarnings.push({
@@ -647,7 +652,7 @@ function prepareTools({
647
652
  if (toolChoice == null) {
648
653
  return {
649
654
  tools: [{ functionDeclarations }],
650
- toolConfig: void 0,
655
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
651
656
  toolWarnings
652
657
  };
653
658
  }
@@ -656,7 +661,11 @@ function prepareTools({
656
661
  case "auto":
657
662
  return {
658
663
  tools: [{ functionDeclarations }],
659
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
664
+ toolConfig: {
665
+ functionCallingConfig: {
666
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
667
+ }
668
+ },
660
669
  toolWarnings
661
670
  };
662
671
  case "none":
@@ -668,7 +677,11 @@ function prepareTools({
668
677
  case "required":
669
678
  return {
670
679
  tools: [{ functionDeclarations }],
671
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
680
+ toolConfig: {
681
+ functionCallingConfig: {
682
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
683
+ }
684
+ },
672
685
  toolWarnings
673
686
  };
674
687
  case "tool":
@@ -676,7 +689,7 @@ function prepareTools({
676
689
  tools: [{ functionDeclarations }],
677
690
  toolConfig: {
678
691
  functionCallingConfig: {
679
- mode: "ANY",
692
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
680
693
  allowedFunctionNames: [toolChoice.toolName]
681
694
  }
682
695
  },
@@ -720,7 +733,7 @@ function mapGoogleGenerativeAIFinishReason({
720
733
  // src/google-generative-ai-language-model.ts
721
734
  var GoogleGenerativeAILanguageModel = class {
722
735
  constructor(modelId, config) {
723
- this.specificationVersion = "v3";
736
+ this.specificationVersion = "v4";
724
737
  var _a;
725
738
  this.modelId = modelId;
726
739
  this.config = config;
@@ -832,7 +845,7 @@ var GoogleGenerativeAILanguageModel = class {
832
845
  };
833
846
  }
834
847
  async doGenerate(options) {
835
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
848
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
836
849
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
837
850
  const mergedHeaders = combineHeaders(
838
851
  await resolve(this.config.headers),
@@ -912,13 +925,16 @@ var GoogleGenerativeAILanguageModel = class {
912
925
  } : void 0
913
926
  });
914
927
  } else if ("inlineData" in part) {
928
+ const hasThought = part.thought === true;
929
+ const hasThoughtSignature = !!part.thoughtSignature;
915
930
  content.push({
916
931
  type: "file",
917
932
  data: part.inlineData.data,
918
933
  mediaType: part.inlineData.mimeType,
919
- providerMetadata: part.thoughtSignature ? {
934
+ providerMetadata: hasThought || hasThoughtSignature ? {
920
935
  [providerOptionsName]: {
921
- thoughtSignature: part.thoughtSignature
936
+ ...hasThought ? { thought: true } : {},
937
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
922
938
  }
923
939
  } : void 0
924
940
  });
@@ -951,7 +967,8 @@ var GoogleGenerativeAILanguageModel = class {
951
967
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
952
968
  urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
953
969
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
954
- usageMetadata: usageMetadata != null ? usageMetadata : null
970
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
971
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null
955
972
  }
956
973
  },
957
974
  request: { body: args },
@@ -985,6 +1002,8 @@ var GoogleGenerativeAILanguageModel = class {
985
1002
  };
986
1003
  let usage = void 0;
987
1004
  let providerMetadata = void 0;
1005
+ let lastGroundingMetadata = null;
1006
+ let lastUrlContextMetadata = null;
988
1007
  const generateId2 = this.config.generateId;
989
1008
  let hasToolCalls = false;
990
1009
  let currentTextBlockId = null;
@@ -999,7 +1018,7 @@ var GoogleGenerativeAILanguageModel = class {
999
1018
  controller.enqueue({ type: "stream-start", warnings });
1000
1019
  },
1001
1020
  transform(chunk, controller) {
1002
- var _a, _b, _c, _d, _e, _f, _g, _h;
1021
+ var _a, _b, _c, _d, _e, _f, _g;
1003
1022
  if (options.includeRawChunks) {
1004
1023
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1005
1024
  }
@@ -1017,6 +1036,12 @@ var GoogleGenerativeAILanguageModel = class {
1017
1036
  return;
1018
1037
  }
1019
1038
  const content = candidate.content;
1039
+ if (candidate.groundingMetadata != null) {
1040
+ lastGroundingMetadata = candidate.groundingMetadata;
1041
+ }
1042
+ if (candidate.urlContextMetadata != null) {
1043
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1044
+ }
1020
1045
  const sources = extractSources({
1021
1046
  groundingMetadata: candidate.groundingMetadata,
1022
1047
  generateId: generateId2
@@ -1131,16 +1156,19 @@ var GoogleGenerativeAILanguageModel = class {
1131
1156
  });
1132
1157
  currentReasoningBlockId = null;
1133
1158
  }
1134
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1159
+ const hasThought = part.thought === true;
1160
+ const hasThoughtSignature = !!part.thoughtSignature;
1161
+ const fileMeta = hasThought || hasThoughtSignature ? {
1135
1162
  [providerOptionsName]: {
1136
- thoughtSignature: part.thoughtSignature
1163
+ ...hasThought ? { thought: true } : {},
1164
+ ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1137
1165
  }
1138
1166
  } : void 0;
1139
1167
  controller.enqueue({
1140
1168
  type: "file",
1141
1169
  mediaType: part.inlineData.mimeType,
1142
1170
  data: part.inlineData.data,
1143
- providerMetadata: thoughtSignatureMetadata
1171
+ providerMetadata: fileMeta
1144
1172
  });
1145
1173
  }
1146
1174
  }
@@ -1190,14 +1218,13 @@ var GoogleGenerativeAILanguageModel = class {
1190
1218
  providerMetadata = {
1191
1219
  [providerOptionsName]: {
1192
1220
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1193
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1194
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1195
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1221
+ groundingMetadata: lastGroundingMetadata,
1222
+ urlContextMetadata: lastUrlContextMetadata,
1223
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
1224
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1225
+ finishMessage: (_g = candidate.finishMessage) != null ? _g : null
1196
1226
  }
1197
1227
  };
1198
- if (usageMetadata != null) {
1199
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1200
- }
1201
1228
  }
1202
1229
  },
1203
1230
  flush(controller) {
@@ -1406,6 +1433,7 @@ var getContentSchema = () => z3.object({
1406
1433
  mimeType: z3.string(),
1407
1434
  data: z3.string()
1408
1435
  }),
1436
+ thought: z3.boolean().nullish(),
1409
1437
  thoughtSignature: z3.string().nullish()
1410
1438
  }),
1411
1439
  z3.object({
@@ -1456,6 +1484,7 @@ var responseSchema = lazySchema3(
1456
1484
  z3.object({
1457
1485
  content: getContentSchema().nullish().or(z3.object({}).strict()),
1458
1486
  finishReason: z3.string().nullish(),
1487
+ finishMessage: z3.string().nullish(),
1459
1488
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1460
1489
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1461
1490
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1476,6 +1505,7 @@ var chunkSchema = lazySchema3(
1476
1505
  z3.object({
1477
1506
  content: getContentSchema().nullish(),
1478
1507
  finishReason: z3.string().nullish(),
1508
+ finishMessage: z3.string().nullish(),
1479
1509
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1480
1510
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1481
1511
  urlContextMetadata: getUrlContextMetadataSchema().nullish()