@ai-sdk/google 3.0.53 → 3.0.55

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.
@@ -97,6 +97,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
97
97
  };
98
98
  thought?: boolean | null | undefined;
99
99
  thoughtSignature?: string | null | undefined;
100
+ } | {
101
+ toolCall: {
102
+ toolType: string;
103
+ id: string;
104
+ args?: unknown;
105
+ };
106
+ thoughtSignature?: string | null | undefined;
107
+ } | {
108
+ toolResponse: {
109
+ toolType: string;
110
+ id: string;
111
+ response?: unknown;
112
+ };
113
+ thoughtSignature?: string | null | undefined;
100
114
  } | {
101
115
  executableCode?: {
102
116
  language: string;
@@ -194,6 +208,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
194
208
  blocked?: boolean | null | undefined;
195
209
  }[] | null | undefined;
196
210
  } | null | undefined;
211
+ serviceTier?: string | null | undefined;
197
212
  }>;
198
213
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
199
214
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
@@ -97,6 +97,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
97
97
  };
98
98
  thought?: boolean | null | undefined;
99
99
  thoughtSignature?: string | null | undefined;
100
+ } | {
101
+ toolCall: {
102
+ toolType: string;
103
+ id: string;
104
+ args?: unknown;
105
+ };
106
+ thoughtSignature?: string | null | undefined;
107
+ } | {
108
+ toolResponse: {
109
+ toolType: string;
110
+ id: string;
111
+ response?: unknown;
112
+ };
113
+ thoughtSignature?: string | null | undefined;
100
114
  } | {
101
115
  executableCode?: {
102
116
  language: string;
@@ -194,6 +208,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
194
208
  blocked?: boolean | null | undefined;
195
209
  }[] | null | undefined;
196
210
  } | null | undefined;
211
+ serviceTier?: string | null | undefined;
197
212
  }>;
198
213
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
199
214
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
@@ -294,7 +294,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
294
294
  }
295
295
  }
296
296
  function convertToGoogleGenerativeAIMessages(prompt, options) {
297
- var _a, _b, _c, _d;
297
+ var _a, _b, _c, _d, _e, _f, _g, _h;
298
298
  const systemInstructionParts = [];
299
299
  const contents = [];
300
300
  let systemMessagesAllowed = true;
@@ -381,6 +381,18 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
381
381
  };
382
382
  }
383
383
  case "tool-call": {
384
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
385
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
386
+ if (serverToolCallId && serverToolType) {
387
+ return {
388
+ toolCall: {
389
+ toolType: serverToolType,
390
+ args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
391
+ id: serverToolCallId
392
+ },
393
+ thoughtSignature
394
+ };
395
+ }
384
396
  return {
385
397
  functionCall: {
386
398
  name: part.toolName,
@@ -389,6 +401,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
389
401
  thoughtSignature
390
402
  };
391
403
  }
404
+ case "tool-result": {
405
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
406
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
407
+ if (serverToolCallId && serverToolType) {
408
+ return {
409
+ toolResponse: {
410
+ toolType: serverToolType,
411
+ response: part.output.type === "json" ? part.output.value : {},
412
+ id: serverToolCallId
413
+ },
414
+ thoughtSignature
415
+ };
416
+ }
417
+ return void 0;
418
+ }
392
419
  }
393
420
  }).filter((part) => part !== void 0)
394
421
  });
@@ -401,6 +428,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
401
428
  if (part.type === "tool-approval-response") {
402
429
  continue;
403
430
  }
431
+ const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
432
+ const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
433
+ const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
434
+ if (serverToolCallId && serverToolType) {
435
+ const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
436
+ if (contents.length > 0) {
437
+ const lastContent = contents[contents.length - 1];
438
+ if (lastContent.role === "model") {
439
+ lastContent.parts.push({
440
+ toolResponse: {
441
+ toolType: serverToolType,
442
+ response: part.output.type === "json" ? part.output.value : {},
443
+ id: serverToolCallId
444
+ },
445
+ thoughtSignature: serverThoughtSignature
446
+ });
447
+ continue;
448
+ }
449
+ }
450
+ }
404
451
  const output = part.output;
405
452
  if (output.type === "content") {
406
453
  if (supportsFunctionResponseParts) {
@@ -414,7 +461,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
414
461
  name: part.toolName,
415
462
  response: {
416
463
  name: part.toolName,
417
- content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool execution denied." : output.value
464
+ content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
418
465
  }
419
466
  }
420
467
  });
@@ -579,7 +626,15 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
579
626
  latitude: import_v42.z.number(),
580
627
  longitude: import_v42.z.number()
581
628
  }).optional()
582
- }).optional()
629
+ }).optional(),
630
+ /**
631
+ * Optional. The service tier to use for the request.
632
+ */
633
+ serviceTier: import_v42.z.enum([
634
+ "SERVICE_TIER_STANDARD",
635
+ "SERVICE_TIER_FLEX",
636
+ "SERVICE_TIER_PRIORITY"
637
+ ]).optional()
583
638
  })
584
639
  )
585
640
  );
@@ -591,7 +646,7 @@ function prepareTools({
591
646
  toolChoice,
592
647
  modelId
593
648
  }) {
594
- var _a;
649
+ var _a, _b;
595
650
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
596
651
  const toolWarnings = [];
597
652
  const isLatest = [
@@ -600,13 +655,14 @@ function prepareTools({
600
655
  "gemini-pro-latest"
601
656
  ].some((id) => id === modelId);
602
657
  const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
658
+ const isGemini3orNewer = modelId.includes("gemini-3");
603
659
  const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
604
660
  if (tools == null) {
605
661
  return { tools: void 0, toolConfig: void 0, toolWarnings };
606
662
  }
607
663
  const hasFunctionTools = tools.some((tool) => tool.type === "function");
608
664
  const hasProviderTools = tools.some((tool) => tool.type === "provider");
609
- if (hasFunctionTools && hasProviderTools) {
665
+ if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
610
666
  toolWarnings.push({
611
667
  type: "unsupported",
612
668
  feature: `combination of function and provider-defined tools`
@@ -711,6 +767,45 @@ function prepareTools({
711
767
  break;
712
768
  }
713
769
  });
770
+ if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
771
+ const functionDeclarations2 = [];
772
+ for (const tool of tools) {
773
+ if (tool.type === "function") {
774
+ functionDeclarations2.push({
775
+ name: tool.name,
776
+ description: (_a = tool.description) != null ? _a : "",
777
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
778
+ });
779
+ }
780
+ }
781
+ const combinedToolConfig = {
782
+ functionCallingConfig: { mode: "VALIDATED" },
783
+ includeServerSideToolInvocations: true
784
+ };
785
+ if (toolChoice != null) {
786
+ switch (toolChoice.type) {
787
+ case "auto":
788
+ break;
789
+ case "none":
790
+ combinedToolConfig.functionCallingConfig = { mode: "NONE" };
791
+ break;
792
+ case "required":
793
+ combinedToolConfig.functionCallingConfig = { mode: "ANY" };
794
+ break;
795
+ case "tool":
796
+ combinedToolConfig.functionCallingConfig = {
797
+ mode: "ANY",
798
+ allowedFunctionNames: [toolChoice.toolName]
799
+ };
800
+ break;
801
+ }
802
+ }
803
+ return {
804
+ tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
805
+ toolConfig: combinedToolConfig,
806
+ toolWarnings
807
+ };
808
+ }
714
809
  return {
715
810
  tools: googleTools2.length > 0 ? googleTools2 : void 0,
716
811
  toolConfig: void 0,
@@ -724,7 +819,7 @@ function prepareTools({
724
819
  case "function":
725
820
  functionDeclarations.push({
726
821
  name: tool.name,
727
- description: (_a = tool.description) != null ? _a : "",
822
+ description: (_b = tool.description) != null ? _b : "",
728
823
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
729
824
  });
730
825
  if (tool.strict === true) {
@@ -933,14 +1028,15 @@ var GoogleGenerativeAILanguageModel = class {
933
1028
  retrievalConfig: googleOptions.retrievalConfig
934
1029
  } : googleToolConfig,
935
1030
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
936
- labels: googleOptions == null ? void 0 : googleOptions.labels
1031
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
1032
+ serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
937
1033
  },
938
1034
  warnings: [...warnings, ...toolWarnings],
939
1035
  providerOptionsName
940
1036
  };
941
1037
  }
942
1038
  async doGenerate(options) {
943
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1039
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
944
1040
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
945
1041
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
946
1042
  await (0, import_provider_utils4.resolve)(this.config.headers),
@@ -966,6 +1062,7 @@ var GoogleGenerativeAILanguageModel = class {
966
1062
  const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
967
1063
  const usageMetadata = response.usageMetadata;
968
1064
  let lastCodeExecutionToolCallId;
1065
+ let lastServerToolCallId;
969
1066
  for (const part of parts) {
970
1067
  if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
971
1068
  const toolCallId = this.config.generateId();
@@ -1033,12 +1130,56 @@ var GoogleGenerativeAILanguageModel = class {
1033
1130
  }
1034
1131
  } : void 0
1035
1132
  });
1133
+ } else if ("toolCall" in part && part.toolCall) {
1134
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1135
+ lastServerToolCallId = toolCallId;
1136
+ content.push({
1137
+ type: "tool-call",
1138
+ toolCallId,
1139
+ toolName: `server:${part.toolCall.toolType}`,
1140
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1141
+ providerExecuted: true,
1142
+ dynamic: true,
1143
+ providerMetadata: part.thoughtSignature ? {
1144
+ [providerOptionsName]: {
1145
+ thoughtSignature: part.thoughtSignature,
1146
+ serverToolCallId: toolCallId,
1147
+ serverToolType: part.toolCall.toolType
1148
+ }
1149
+ } : {
1150
+ [providerOptionsName]: {
1151
+ serverToolCallId: toolCallId,
1152
+ serverToolType: part.toolCall.toolType
1153
+ }
1154
+ }
1155
+ });
1156
+ } else if ("toolResponse" in part && part.toolResponse) {
1157
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1158
+ content.push({
1159
+ type: "tool-result",
1160
+ toolCallId: responseToolCallId,
1161
+ toolName: `server:${part.toolResponse.toolType}`,
1162
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1163
+ providerMetadata: part.thoughtSignature ? {
1164
+ [providerOptionsName]: {
1165
+ thoughtSignature: part.thoughtSignature,
1166
+ serverToolCallId: responseToolCallId,
1167
+ serverToolType: part.toolResponse.toolType
1168
+ }
1169
+ } : {
1170
+ [providerOptionsName]: {
1171
+ serverToolCallId: responseToolCallId,
1172
+ serverToolType: part.toolResponse.toolType
1173
+ }
1174
+ }
1175
+ });
1176
+ lastServerToolCallId = void 0;
1036
1177
  }
1037
1178
  }
1038
- const sources = (_e = extractSources({
1179
+ const sources = (_i = extractSources({
1039
1180
  groundingMetadata: candidate.groundingMetadata,
1040
1181
  generateId: this.config.generateId
1041
- })) != null ? _e : [];
1182
+ })) != null ? _i : [];
1042
1183
  for (const source of sources) {
1043
1184
  content.push(source);
1044
1185
  }
@@ -1052,18 +1193,19 @@ var GoogleGenerativeAILanguageModel = class {
1052
1193
  (part) => part.type === "tool-call" && !part.providerExecuted
1053
1194
  )
1054
1195
  }),
1055
- raw: (_f = candidate.finishReason) != null ? _f : void 0
1196
+ raw: (_j = candidate.finishReason) != null ? _j : void 0
1056
1197
  },
1057
1198
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1058
1199
  warnings,
1059
1200
  providerMetadata: {
1060
1201
  [providerOptionsName]: {
1061
- promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
1062
- groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
1063
- urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
1064
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1202
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1203
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1204
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1205
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1065
1206
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1066
- finishMessage: (_k = candidate.finishMessage) != null ? _k : null
1207
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1208
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
1067
1209
  }
1068
1210
  },
1069
1211
  request: { body: args },
@@ -1099,6 +1241,7 @@ var GoogleGenerativeAILanguageModel = class {
1099
1241
  let providerMetadata = void 0;
1100
1242
  let lastGroundingMetadata = null;
1101
1243
  let lastUrlContextMetadata = null;
1244
+ let serviceTier = null;
1102
1245
  const generateId2 = this.config.generateId;
1103
1246
  let hasToolCalls = false;
1104
1247
  let currentTextBlockId = null;
@@ -1106,6 +1249,7 @@ var GoogleGenerativeAILanguageModel = class {
1106
1249
  let blockCounter = 0;
1107
1250
  const emittedSourceUrls = /* @__PURE__ */ new Set();
1108
1251
  let lastCodeExecutionToolCallId;
1252
+ let lastServerToolCallId;
1109
1253
  return {
1110
1254
  stream: response.pipeThrough(
1111
1255
  new TransformStream({
@@ -1113,7 +1257,7 @@ var GoogleGenerativeAILanguageModel = class {
1113
1257
  controller.enqueue({ type: "stream-start", warnings });
1114
1258
  },
1115
1259
  transform(chunk, controller) {
1116
- var _a, _b, _c, _d, _e, _f, _g;
1260
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1117
1261
  if (options.includeRawChunks) {
1118
1262
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1119
1263
  }
@@ -1126,6 +1270,9 @@ var GoogleGenerativeAILanguageModel = class {
1126
1270
  if (usageMetadata != null) {
1127
1271
  usage = usageMetadata;
1128
1272
  }
1273
+ if (value.serviceTier != null) {
1274
+ serviceTier = value.serviceTier;
1275
+ }
1129
1276
  const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1130
1277
  if (candidate == null) {
1131
1278
  return;
@@ -1265,6 +1412,42 @@ var GoogleGenerativeAILanguageModel = class {
1265
1412
  data: part.inlineData.data,
1266
1413
  providerMetadata: fileMeta
1267
1414
  });
1415
+ } else if ("toolCall" in part && part.toolCall) {
1416
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
1417
+ lastServerToolCallId = toolCallId;
1418
+ const serverMeta = {
1419
+ [providerOptionsName]: {
1420
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1421
+ serverToolCallId: toolCallId,
1422
+ serverToolType: part.toolCall.toolType
1423
+ }
1424
+ };
1425
+ controller.enqueue({
1426
+ type: "tool-call",
1427
+ toolCallId,
1428
+ toolName: `server:${part.toolCall.toolType}`,
1429
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1430
+ providerExecuted: true,
1431
+ dynamic: true,
1432
+ providerMetadata: serverMeta
1433
+ });
1434
+ } else if ("toolResponse" in part && part.toolResponse) {
1435
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
1436
+ const serverMeta = {
1437
+ [providerOptionsName]: {
1438
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1439
+ serverToolCallId: responseToolCallId,
1440
+ serverToolType: part.toolResponse.toolType
1441
+ }
1442
+ };
1443
+ controller.enqueue({
1444
+ type: "tool-result",
1445
+ toolCallId: responseToolCallId,
1446
+ toolName: `server:${part.toolResponse.toolType}`,
1447
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1448
+ providerMetadata: serverMeta
1449
+ });
1450
+ lastServerToolCallId = void 0;
1268
1451
  }
1269
1452
  }
1270
1453
  const toolCallDeltas = getToolCallsFromParts({
@@ -1312,12 +1495,13 @@ var GoogleGenerativeAILanguageModel = class {
1312
1495
  };
1313
1496
  providerMetadata = {
1314
1497
  [providerOptionsName]: {
1315
- promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1498
+ promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
1316
1499
  groundingMetadata: lastGroundingMetadata,
1317
1500
  urlContextMetadata: lastUrlContextMetadata,
1318
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
1501
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1319
1502
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1320
- finishMessage: (_g = candidate.finishMessage) != null ? _g : null
1503
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
1504
+ serviceTier
1321
1505
  }
1322
1506
  };
1323
1507
  }
@@ -1531,6 +1715,22 @@ var getContentSchema = () => import_v43.z.object({
1531
1715
  thought: import_v43.z.boolean().nullish(),
1532
1716
  thoughtSignature: import_v43.z.string().nullish()
1533
1717
  }),
1718
+ import_v43.z.object({
1719
+ toolCall: import_v43.z.object({
1720
+ toolType: import_v43.z.string(),
1721
+ args: import_v43.z.unknown().nullish(),
1722
+ id: import_v43.z.string()
1723
+ }),
1724
+ thoughtSignature: import_v43.z.string().nullish()
1725
+ }),
1726
+ import_v43.z.object({
1727
+ toolResponse: import_v43.z.object({
1728
+ toolType: import_v43.z.string(),
1729
+ response: import_v43.z.unknown().nullish(),
1730
+ id: import_v43.z.string()
1731
+ }),
1732
+ thoughtSignature: import_v43.z.string().nullish()
1733
+ }),
1534
1734
  import_v43.z.object({
1535
1735
  executableCode: import_v43.z.object({
1536
1736
  language: import_v43.z.string(),
@@ -1589,7 +1789,8 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
1589
1789
  promptFeedback: import_v43.z.object({
1590
1790
  blockReason: import_v43.z.string().nullish(),
1591
1791
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1592
- }).nullish()
1792
+ }).nullish(),
1793
+ serviceTier: import_v43.z.string().nullish()
1593
1794
  })
1594
1795
  )
1595
1796
  );
@@ -1610,7 +1811,8 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
1610
1811
  promptFeedback: import_v43.z.object({
1611
1812
  blockReason: import_v43.z.string().nullish(),
1612
1813
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1613
- }).nullish()
1814
+ }).nullish(),
1815
+ serviceTier: import_v43.z.string().nullish()
1614
1816
  })
1615
1817
  )
1616
1818
  );