@ai-sdk/google 4.0.0-beta.2 → 4.0.0-beta.20

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.
@@ -18,14 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/internal/index.ts
21
- var internal_exports = {};
22
- __export(internal_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  GoogleGenerativeAILanguageModel: () => GoogleGenerativeAILanguageModel,
24
24
  getGroundingMetadataSchema: () => getGroundingMetadataSchema,
25
25
  getUrlContextMetadataSchema: () => getUrlContextMetadataSchema,
26
26
  googleTools: () => googleTools
27
27
  });
28
- module.exports = __toCommonJS(internal_exports);
28
+ module.exports = __toCommonJS(index_exports);
29
29
 
30
30
  // src/google-generative-ai-language-model.ts
31
31
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
@@ -189,13 +189,118 @@ function isEmptyObjectSchema(jsonSchema) {
189
189
  // src/convert-to-google-generative-ai-messages.ts
190
190
  var import_provider = require("@ai-sdk/provider");
191
191
  var import_provider_utils = require("@ai-sdk/provider-utils");
192
+ var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
193
+ function parseBase64DataUrl(value) {
194
+ const match = dataUrlRegex.exec(value);
195
+ if (match == null) {
196
+ return void 0;
197
+ }
198
+ return {
199
+ mediaType: match[1],
200
+ data: match[2]
201
+ };
202
+ }
203
+ function convertUrlToolResultPart(url) {
204
+ const parsedDataUrl = parseBase64DataUrl(url);
205
+ if (parsedDataUrl == null) {
206
+ return void 0;
207
+ }
208
+ return {
209
+ inlineData: {
210
+ mimeType: parsedDataUrl.mediaType,
211
+ data: parsedDataUrl.data
212
+ }
213
+ };
214
+ }
215
+ function appendToolResultParts(parts, toolName, outputValue) {
216
+ const functionResponseParts = [];
217
+ const responseTextParts = [];
218
+ for (const contentPart of outputValue) {
219
+ switch (contentPart.type) {
220
+ case "text": {
221
+ responseTextParts.push(contentPart.text);
222
+ break;
223
+ }
224
+ case "image-data":
225
+ case "file-data": {
226
+ functionResponseParts.push({
227
+ inlineData: {
228
+ mimeType: contentPart.mediaType,
229
+ data: contentPart.data
230
+ }
231
+ });
232
+ break;
233
+ }
234
+ case "image-url":
235
+ case "file-url": {
236
+ const functionResponsePart = convertUrlToolResultPart(
237
+ contentPart.url
238
+ );
239
+ if (functionResponsePart != null) {
240
+ functionResponseParts.push(functionResponsePart);
241
+ } else {
242
+ responseTextParts.push(JSON.stringify(contentPart));
243
+ }
244
+ break;
245
+ }
246
+ default: {
247
+ responseTextParts.push(JSON.stringify(contentPart));
248
+ break;
249
+ }
250
+ }
251
+ }
252
+ parts.push({
253
+ functionResponse: {
254
+ name: toolName,
255
+ response: {
256
+ name: toolName,
257
+ content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
258
+ },
259
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
260
+ }
261
+ });
262
+ }
263
+ function appendLegacyToolResultParts(parts, toolName, outputValue) {
264
+ for (const contentPart of outputValue) {
265
+ switch (contentPart.type) {
266
+ case "text":
267
+ parts.push({
268
+ functionResponse: {
269
+ name: toolName,
270
+ response: {
271
+ name: toolName,
272
+ content: contentPart.text
273
+ }
274
+ }
275
+ });
276
+ break;
277
+ case "image-data":
278
+ parts.push(
279
+ {
280
+ inlineData: {
281
+ mimeType: String(contentPart.mediaType),
282
+ data: String(contentPart.data)
283
+ }
284
+ },
285
+ {
286
+ text: "Tool executed successfully and returned this image as a response"
287
+ }
288
+ );
289
+ break;
290
+ default:
291
+ parts.push({ text: JSON.stringify(contentPart) });
292
+ break;
293
+ }
294
+ }
295
+ }
192
296
  function convertToGoogleGenerativeAIMessages(prompt, options) {
193
- var _a, _b, _c;
297
+ var _a, _b, _c, _d, _e, _f, _g, _h;
194
298
  const systemInstructionParts = [];
195
299
  const contents = [];
196
300
  let systemMessagesAllowed = true;
197
301
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
198
302
  const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
303
+ const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
199
304
  for (const { role, content } of prompt) {
200
305
  switch (role) {
201
306
  case "system": {
@@ -243,8 +348,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
243
348
  contents.push({
244
349
  role: "model",
245
350
  parts: content.map((part) => {
246
- var _a2, _b2, _c2, _d;
247
- const providerOpts = (_d = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
351
+ var _a2, _b2, _c2, _d2;
352
+ const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
248
353
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
249
354
  switch (part.type) {
250
355
  case "text": {
@@ -260,6 +365,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
260
365
  thoughtSignature
261
366
  };
262
367
  }
368
+ case "reasoning-file": {
369
+ if (part.data instanceof URL) {
370
+ throw new import_provider.UnsupportedFunctionalityError({
371
+ functionality: "File data URLs in assistant messages are not supported"
372
+ });
373
+ }
374
+ return {
375
+ inlineData: {
376
+ mimeType: part.mediaType,
377
+ data: (0, import_provider_utils.convertToBase64)(part.data)
378
+ },
379
+ thought: true,
380
+ thoughtSignature
381
+ };
382
+ }
263
383
  case "file": {
264
384
  if (part.data instanceof URL) {
265
385
  throw new import_provider.UnsupportedFunctionalityError({
@@ -271,10 +391,23 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
271
391
  mimeType: part.mediaType,
272
392
  data: (0, import_provider_utils.convertToBase64)(part.data)
273
393
  },
394
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
274
395
  thoughtSignature
275
396
  };
276
397
  }
277
398
  case "tool-call": {
399
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
400
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
401
+ if (serverToolCallId && serverToolType) {
402
+ return {
403
+ toolCall: {
404
+ toolType: serverToolType,
405
+ args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
406
+ id: serverToolCallId
407
+ },
408
+ thoughtSignature
409
+ };
410
+ }
278
411
  return {
279
412
  functionCall: {
280
413
  name: part.toolName,
@@ -283,6 +416,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
283
416
  thoughtSignature
284
417
  };
285
418
  }
419
+ case "tool-result": {
420
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
421
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
422
+ if (serverToolCallId && serverToolType) {
423
+ return {
424
+ toolResponse: {
425
+ toolType: serverToolType,
426
+ response: part.output.type === "json" ? part.output.value : {},
427
+ id: serverToolCallId
428
+ },
429
+ thoughtSignature
430
+ };
431
+ }
432
+ return void 0;
433
+ }
286
434
  }
287
435
  }).filter((part) => part !== void 0)
288
436
  });
@@ -295,38 +443,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
295
443
  if (part.type === "tool-approval-response") {
296
444
  continue;
297
445
  }
446
+ 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;
447
+ const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
448
+ const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
449
+ if (serverToolCallId && serverToolType) {
450
+ const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
451
+ if (contents.length > 0) {
452
+ const lastContent = contents[contents.length - 1];
453
+ if (lastContent.role === "model") {
454
+ lastContent.parts.push({
455
+ toolResponse: {
456
+ toolType: serverToolType,
457
+ response: part.output.type === "json" ? part.output.value : {},
458
+ id: serverToolCallId
459
+ },
460
+ thoughtSignature: serverThoughtSignature
461
+ });
462
+ continue;
463
+ }
464
+ }
465
+ }
298
466
  const output = part.output;
299
467
  if (output.type === "content") {
300
- for (const contentPart of output.value) {
301
- switch (contentPart.type) {
302
- case "text":
303
- parts.push({
304
- functionResponse: {
305
- name: part.toolName,
306
- response: {
307
- name: part.toolName,
308
- content: contentPart.text
309
- }
310
- }
311
- });
312
- break;
313
- case "image-data":
314
- parts.push(
315
- {
316
- inlineData: {
317
- mimeType: contentPart.mediaType,
318
- data: contentPart.data
319
- }
320
- },
321
- {
322
- text: "Tool executed successfully and returned this image as a response"
323
- }
324
- );
325
- break;
326
- default:
327
- parts.push({ text: JSON.stringify(contentPart) });
328
- break;
329
- }
468
+ if (supportsFunctionResponseParts) {
469
+ appendToolResultParts(parts, part.toolName, output.value);
470
+ } else {
471
+ appendLegacyToolResultParts(parts, part.toolName, output.value);
330
472
  }
331
473
  } else {
332
474
  parts.push({
@@ -334,7 +476,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
334
476
  name: part.toolName,
335
477
  response: {
336
478
  name: part.toolName,
337
- content: output.type === "execution-denied" ? (_c = output.reason) != null ? _c : "Tool execution denied." : output.value
479
+ content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
338
480
  }
339
481
  }
340
482
  });
@@ -499,7 +641,15 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
499
641
  latitude: import_v42.z.number(),
500
642
  longitude: import_v42.z.number()
501
643
  }).optional()
502
- }).optional()
644
+ }).optional(),
645
+ /**
646
+ * Optional. The service tier to use for the request.
647
+ */
648
+ serviceTier: import_v42.z.enum([
649
+ "SERVICE_TIER_STANDARD",
650
+ "SERVICE_TIER_FLEX",
651
+ "SERVICE_TIER_PRIORITY"
652
+ ]).optional()
503
653
  })
504
654
  )
505
655
  );
@@ -511,7 +661,7 @@ function prepareTools({
511
661
  toolChoice,
512
662
  modelId
513
663
  }) {
514
- var _a;
664
+ var _a, _b;
515
665
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
516
666
  const toolWarnings = [];
517
667
  const isLatest = [
@@ -520,13 +670,14 @@ function prepareTools({
520
670
  "gemini-pro-latest"
521
671
  ].some((id) => id === modelId);
522
672
  const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
673
+ const isGemini3orNewer = modelId.includes("gemini-3");
523
674
  const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
524
675
  if (tools == null) {
525
676
  return { tools: void 0, toolConfig: void 0, toolWarnings };
526
677
  }
527
678
  const hasFunctionTools = tools.some((tool) => tool.type === "function");
528
679
  const hasProviderTools = tools.some((tool) => tool.type === "provider");
529
- if (hasFunctionTools && hasProviderTools) {
680
+ if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
530
681
  toolWarnings.push({
531
682
  type: "unsupported",
532
683
  feature: `combination of function and provider-defined tools`
@@ -631,6 +782,45 @@ function prepareTools({
631
782
  break;
632
783
  }
633
784
  });
785
+ if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
786
+ const functionDeclarations2 = [];
787
+ for (const tool of tools) {
788
+ if (tool.type === "function") {
789
+ functionDeclarations2.push({
790
+ name: tool.name,
791
+ description: (_a = tool.description) != null ? _a : "",
792
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
793
+ });
794
+ }
795
+ }
796
+ const combinedToolConfig = {
797
+ functionCallingConfig: { mode: "VALIDATED" },
798
+ includeServerSideToolInvocations: true
799
+ };
800
+ if (toolChoice != null) {
801
+ switch (toolChoice.type) {
802
+ case "auto":
803
+ break;
804
+ case "none":
805
+ combinedToolConfig.functionCallingConfig = { mode: "NONE" };
806
+ break;
807
+ case "required":
808
+ combinedToolConfig.functionCallingConfig = { mode: "ANY" };
809
+ break;
810
+ case "tool":
811
+ combinedToolConfig.functionCallingConfig = {
812
+ mode: "ANY",
813
+ allowedFunctionNames: [toolChoice.toolName]
814
+ };
815
+ break;
816
+ }
817
+ }
818
+ return {
819
+ tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
820
+ toolConfig: combinedToolConfig,
821
+ toolWarnings
822
+ };
823
+ }
634
824
  return {
635
825
  tools: googleTools2.length > 0 ? googleTools2 : void 0,
636
826
  toolConfig: void 0,
@@ -644,7 +834,7 @@ function prepareTools({
644
834
  case "function":
645
835
  functionDeclarations.push({
646
836
  name: tool.name,
647
- description: (_a = tool.description) != null ? _a : "",
837
+ description: (_b = tool.description) != null ? _b : "",
648
838
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
649
839
  });
650
840
  if (tool.strict === true) {
@@ -743,7 +933,7 @@ function mapGoogleGenerativeAIFinishReason({
743
933
  // src/google-generative-ai-language-model.ts
744
934
  var GoogleGenerativeAILanguageModel = class {
745
935
  constructor(modelId, config) {
746
- this.specificationVersion = "v3";
936
+ this.specificationVersion = "v4";
747
937
  var _a;
748
938
  this.modelId = modelId;
749
939
  this.config = config;
@@ -769,6 +959,7 @@ var GoogleGenerativeAILanguageModel = class {
769
959
  seed,
770
960
  tools,
771
961
  toolChoice,
962
+ reasoning,
772
963
  providerOptions
773
964
  }) {
774
965
  var _a;
@@ -795,9 +986,14 @@ var GoogleGenerativeAILanguageModel = class {
795
986
  });
796
987
  }
797
988
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
989
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
798
990
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
799
991
  prompt,
800
- { isGemmaModel, providerOptionsName }
992
+ {
993
+ isGemmaModel,
994
+ providerOptionsName,
995
+ supportsFunctionResponseParts
996
+ }
801
997
  );
802
998
  const {
803
999
  tools: googleTools2,
@@ -808,6 +1004,12 @@ var GoogleGenerativeAILanguageModel = class {
808
1004
  toolChoice,
809
1005
  modelId: this.modelId
810
1006
  });
1007
+ const resolvedThinking = resolveThinkingConfig({
1008
+ reasoning,
1009
+ modelId: this.modelId,
1010
+ warnings
1011
+ });
1012
+ const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
811
1013
  return {
812
1014
  args: {
813
1015
  generationConfig: {
@@ -831,7 +1033,7 @@ var GoogleGenerativeAILanguageModel = class {
831
1033
  },
832
1034
  // provider options:
833
1035
  responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
834
- thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig,
1036
+ thinkingConfig,
835
1037
  ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
836
1038
  mediaResolution: googleOptions.mediaResolution
837
1039
  },
@@ -848,14 +1050,15 @@ var GoogleGenerativeAILanguageModel = class {
848
1050
  retrievalConfig: googleOptions.retrievalConfig
849
1051
  } : googleToolConfig,
850
1052
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
851
- labels: googleOptions == null ? void 0 : googleOptions.labels
1053
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
1054
+ serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
852
1055
  },
853
1056
  warnings: [...warnings, ...toolWarnings],
854
1057
  providerOptionsName
855
1058
  };
856
1059
  }
857
1060
  async doGenerate(options) {
858
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1061
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
859
1062
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
860
1063
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
861
1064
  await (0, import_provider_utils4.resolve)(this.config.headers),
@@ -881,6 +1084,7 @@ var GoogleGenerativeAILanguageModel = class {
881
1084
  const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
882
1085
  const usageMetadata = response.usageMetadata;
883
1086
  let lastCodeExecutionToolCallId;
1087
+ let lastServerToolCallId;
884
1088
  for (const part of parts) {
885
1089
  if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
886
1090
  const toolCallId = this.config.generateId();
@@ -935,22 +1139,68 @@ var GoogleGenerativeAILanguageModel = class {
935
1139
  } : void 0
936
1140
  });
937
1141
  } else if ("inlineData" in part) {
1142
+ const hasThought = part.thought === true;
1143
+ const hasThoughtSignature = !!part.thoughtSignature;
938
1144
  content.push({
939
- type: "file",
1145
+ type: hasThought ? "reasoning-file" : "file",
940
1146
  data: part.inlineData.data,
941
1147
  mediaType: part.inlineData.mimeType,
942
- providerMetadata: part.thoughtSignature ? {
1148
+ providerMetadata: hasThoughtSignature ? {
943
1149
  [providerOptionsName]: {
944
1150
  thoughtSignature: part.thoughtSignature
945
1151
  }
946
1152
  } : void 0
947
1153
  });
1154
+ } else if ("toolCall" in part && part.toolCall) {
1155
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1156
+ lastServerToolCallId = toolCallId;
1157
+ content.push({
1158
+ type: "tool-call",
1159
+ toolCallId,
1160
+ toolName: `server:${part.toolCall.toolType}`,
1161
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1162
+ providerExecuted: true,
1163
+ dynamic: true,
1164
+ providerMetadata: part.thoughtSignature ? {
1165
+ [providerOptionsName]: {
1166
+ thoughtSignature: part.thoughtSignature,
1167
+ serverToolCallId: toolCallId,
1168
+ serverToolType: part.toolCall.toolType
1169
+ }
1170
+ } : {
1171
+ [providerOptionsName]: {
1172
+ serverToolCallId: toolCallId,
1173
+ serverToolType: part.toolCall.toolType
1174
+ }
1175
+ }
1176
+ });
1177
+ } else if ("toolResponse" in part && part.toolResponse) {
1178
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1179
+ content.push({
1180
+ type: "tool-result",
1181
+ toolCallId: responseToolCallId,
1182
+ toolName: `server:${part.toolResponse.toolType}`,
1183
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1184
+ providerMetadata: part.thoughtSignature ? {
1185
+ [providerOptionsName]: {
1186
+ thoughtSignature: part.thoughtSignature,
1187
+ serverToolCallId: responseToolCallId,
1188
+ serverToolType: part.toolResponse.toolType
1189
+ }
1190
+ } : {
1191
+ [providerOptionsName]: {
1192
+ serverToolCallId: responseToolCallId,
1193
+ serverToolType: part.toolResponse.toolType
1194
+ }
1195
+ }
1196
+ });
1197
+ lastServerToolCallId = void 0;
948
1198
  }
949
1199
  }
950
- const sources = (_e = extractSources({
1200
+ const sources = (_i = extractSources({
951
1201
  groundingMetadata: candidate.groundingMetadata,
952
1202
  generateId: this.config.generateId
953
- })) != null ? _e : [];
1203
+ })) != null ? _i : [];
954
1204
  for (const source of sources) {
955
1205
  content.push(source);
956
1206
  }
@@ -964,17 +1214,19 @@ var GoogleGenerativeAILanguageModel = class {
964
1214
  (part) => part.type === "tool-call" && !part.providerExecuted
965
1215
  )
966
1216
  }),
967
- raw: (_f = candidate.finishReason) != null ? _f : void 0
1217
+ raw: (_j = candidate.finishReason) != null ? _j : void 0
968
1218
  },
969
1219
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
970
1220
  warnings,
971
1221
  providerMetadata: {
972
1222
  [providerOptionsName]: {
973
- promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
974
- groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
975
- urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
976
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
977
- usageMetadata: usageMetadata != null ? usageMetadata : null
1223
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1224
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1225
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1226
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1227
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1228
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1229
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
978
1230
  }
979
1231
  },
980
1232
  request: { body: args },
@@ -1010,6 +1262,7 @@ var GoogleGenerativeAILanguageModel = class {
1010
1262
  let providerMetadata = void 0;
1011
1263
  let lastGroundingMetadata = null;
1012
1264
  let lastUrlContextMetadata = null;
1265
+ let serviceTier = null;
1013
1266
  const generateId2 = this.config.generateId;
1014
1267
  let hasToolCalls = false;
1015
1268
  let currentTextBlockId = null;
@@ -1017,6 +1270,7 @@ var GoogleGenerativeAILanguageModel = class {
1017
1270
  let blockCounter = 0;
1018
1271
  const emittedSourceUrls = /* @__PURE__ */ new Set();
1019
1272
  let lastCodeExecutionToolCallId;
1273
+ let lastServerToolCallId;
1020
1274
  return {
1021
1275
  stream: response.pipeThrough(
1022
1276
  new TransformStream({
@@ -1024,7 +1278,7 @@ var GoogleGenerativeAILanguageModel = class {
1024
1278
  controller.enqueue({ type: "stream-start", warnings });
1025
1279
  },
1026
1280
  transform(chunk, controller) {
1027
- var _a, _b, _c, _d, _e, _f;
1281
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1028
1282
  if (options.includeRawChunks) {
1029
1283
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1030
1284
  }
@@ -1037,6 +1291,9 @@ var GoogleGenerativeAILanguageModel = class {
1037
1291
  if (usageMetadata != null) {
1038
1292
  usage = usageMetadata;
1039
1293
  }
1294
+ if (value.serviceTier != null) {
1295
+ serviceTier = value.serviceTier;
1296
+ }
1040
1297
  const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1041
1298
  if (candidate == null) {
1042
1299
  return;
@@ -1162,17 +1419,55 @@ var GoogleGenerativeAILanguageModel = class {
1162
1419
  });
1163
1420
  currentReasoningBlockId = null;
1164
1421
  }
1165
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1422
+ const hasThought = part.thought === true;
1423
+ const hasThoughtSignature = !!part.thoughtSignature;
1424
+ const fileMeta = hasThoughtSignature ? {
1166
1425
  [providerOptionsName]: {
1167
1426
  thoughtSignature: part.thoughtSignature
1168
1427
  }
1169
1428
  } : void 0;
1170
1429
  controller.enqueue({
1171
- type: "file",
1430
+ type: hasThought ? "reasoning-file" : "file",
1172
1431
  mediaType: part.inlineData.mimeType,
1173
1432
  data: part.inlineData.data,
1174
- providerMetadata: thoughtSignatureMetadata
1433
+ providerMetadata: fileMeta
1434
+ });
1435
+ } else if ("toolCall" in part && part.toolCall) {
1436
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
1437
+ lastServerToolCallId = toolCallId;
1438
+ const serverMeta = {
1439
+ [providerOptionsName]: {
1440
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1441
+ serverToolCallId: toolCallId,
1442
+ serverToolType: part.toolCall.toolType
1443
+ }
1444
+ };
1445
+ controller.enqueue({
1446
+ type: "tool-call",
1447
+ toolCallId,
1448
+ toolName: `server:${part.toolCall.toolType}`,
1449
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1450
+ providerExecuted: true,
1451
+ dynamic: true,
1452
+ providerMetadata: serverMeta
1175
1453
  });
1454
+ } else if ("toolResponse" in part && part.toolResponse) {
1455
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
1456
+ const serverMeta = {
1457
+ [providerOptionsName]: {
1458
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1459
+ serverToolCallId: responseToolCallId,
1460
+ serverToolType: part.toolResponse.toolType
1461
+ }
1462
+ };
1463
+ controller.enqueue({
1464
+ type: "tool-result",
1465
+ toolCallId: responseToolCallId,
1466
+ toolName: `server:${part.toolResponse.toolType}`,
1467
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1468
+ providerMetadata: serverMeta
1469
+ });
1470
+ lastServerToolCallId = void 0;
1176
1471
  }
1177
1472
  }
1178
1473
  const toolCallDeltas = getToolCallsFromParts({
@@ -1220,15 +1515,15 @@ var GoogleGenerativeAILanguageModel = class {
1220
1515
  };
1221
1516
  providerMetadata = {
1222
1517
  [providerOptionsName]: {
1223
- promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1518
+ promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
1224
1519
  groundingMetadata: lastGroundingMetadata,
1225
1520
  urlContextMetadata: lastUrlContextMetadata,
1226
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1521
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1522
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1523
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
1524
+ serviceTier
1227
1525
  }
1228
1526
  };
1229
- if (usageMetadata != null) {
1230
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1231
- }
1232
1527
  }
1233
1528
  },
1234
1529
  flush(controller) {
@@ -1258,6 +1553,75 @@ var GoogleGenerativeAILanguageModel = class {
1258
1553
  };
1259
1554
  }
1260
1555
  };
1556
+ function isGemini3Model(modelId) {
1557
+ return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
1558
+ }
1559
+ function getMaxOutputTokensForGemini25Model() {
1560
+ return 65536;
1561
+ }
1562
+ function getMaxThinkingTokensForGemini25Model(modelId) {
1563
+ const id = modelId.toLowerCase();
1564
+ if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
1565
+ return 32768;
1566
+ }
1567
+ return 24576;
1568
+ }
1569
+ function resolveThinkingConfig({
1570
+ reasoning,
1571
+ modelId,
1572
+ warnings
1573
+ }) {
1574
+ if (!(0, import_provider_utils4.isCustomReasoning)(reasoning)) {
1575
+ return void 0;
1576
+ }
1577
+ if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
1578
+ return resolveGemini3ThinkingConfig({ reasoning, warnings });
1579
+ }
1580
+ return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
1581
+ }
1582
+ function resolveGemini3ThinkingConfig({
1583
+ reasoning,
1584
+ warnings
1585
+ }) {
1586
+ if (reasoning === "none") {
1587
+ return { thinkingLevel: "minimal" };
1588
+ }
1589
+ const thinkingLevel = (0, import_provider_utils4.mapReasoningToProviderEffort)({
1590
+ reasoning,
1591
+ effortMap: {
1592
+ minimal: "minimal",
1593
+ low: "low",
1594
+ medium: "medium",
1595
+ high: "high",
1596
+ xhigh: "high"
1597
+ },
1598
+ warnings
1599
+ });
1600
+ if (thinkingLevel == null) {
1601
+ return void 0;
1602
+ }
1603
+ return { thinkingLevel };
1604
+ }
1605
+ function resolveGemini25ThinkingConfig({
1606
+ reasoning,
1607
+ modelId,
1608
+ warnings
1609
+ }) {
1610
+ if (reasoning === "none") {
1611
+ return { thinkingBudget: 0 };
1612
+ }
1613
+ const thinkingBudget = (0, import_provider_utils4.mapReasoningToProviderBudget)({
1614
+ reasoning,
1615
+ maxOutputTokens: getMaxOutputTokensForGemini25Model(),
1616
+ maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
1617
+ minReasoningBudget: 0,
1618
+ warnings
1619
+ });
1620
+ if (thinkingBudget == null) {
1621
+ return void 0;
1622
+ }
1623
+ return { thinkingBudget };
1624
+ }
1261
1625
  function getToolCallsFromParts({
1262
1626
  parts,
1263
1627
  generateId: generateId2,
@@ -1437,6 +1801,23 @@ var getContentSchema = () => import_v43.z.object({
1437
1801
  mimeType: import_v43.z.string(),
1438
1802
  data: import_v43.z.string()
1439
1803
  }),
1804
+ thought: import_v43.z.boolean().nullish(),
1805
+ thoughtSignature: import_v43.z.string().nullish()
1806
+ }),
1807
+ import_v43.z.object({
1808
+ toolCall: import_v43.z.object({
1809
+ toolType: import_v43.z.string(),
1810
+ args: import_v43.z.unknown().nullish(),
1811
+ id: import_v43.z.string()
1812
+ }),
1813
+ thoughtSignature: import_v43.z.string().nullish()
1814
+ }),
1815
+ import_v43.z.object({
1816
+ toolResponse: import_v43.z.object({
1817
+ toolType: import_v43.z.string(),
1818
+ response: import_v43.z.unknown().nullish(),
1819
+ id: import_v43.z.string()
1820
+ }),
1440
1821
  thoughtSignature: import_v43.z.string().nullish()
1441
1822
  }),
1442
1823
  import_v43.z.object({
@@ -1487,6 +1868,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
1487
1868
  import_v43.z.object({
1488
1869
  content: getContentSchema().nullish().or(import_v43.z.object({}).strict()),
1489
1870
  finishReason: import_v43.z.string().nullish(),
1871
+ finishMessage: import_v43.z.string().nullish(),
1490
1872
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
1491
1873
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1492
1874
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1496,7 +1878,8 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
1496
1878
  promptFeedback: import_v43.z.object({
1497
1879
  blockReason: import_v43.z.string().nullish(),
1498
1880
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1499
- }).nullish()
1881
+ }).nullish(),
1882
+ serviceTier: import_v43.z.string().nullish()
1500
1883
  })
1501
1884
  )
1502
1885
  );
@@ -1507,6 +1890,7 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
1507
1890
  import_v43.z.object({
1508
1891
  content: getContentSchema().nullish(),
1509
1892
  finishReason: import_v43.z.string().nullish(),
1893
+ finishMessage: import_v43.z.string().nullish(),
1510
1894
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
1511
1895
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1512
1896
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1516,7 +1900,8 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
1516
1900
  promptFeedback: import_v43.z.object({
1517
1901
  blockReason: import_v43.z.string().nullish(),
1518
1902
  safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1519
- }).nullish()
1903
+ }).nullish(),
1904
+ serviceTier: import_v43.z.string().nullish()
1520
1905
  })
1521
1906
  )
1522
1907
  );