@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.
@@ -4,7 +4,10 @@ import {
4
4
  createEventSourceResponseHandler,
5
5
  createJsonResponseHandler,
6
6
  generateId,
7
+ isCustomReasoning,
7
8
  lazySchema as lazySchema3,
9
+ mapReasoningToProviderBudget,
10
+ mapReasoningToProviderEffort,
8
11
  parseProviderOptions,
9
12
  postJsonToApi,
10
13
  resolve,
@@ -172,13 +175,118 @@ import {
172
175
  UnsupportedFunctionalityError
173
176
  } from "@ai-sdk/provider";
174
177
  import { convertToBase64 } from "@ai-sdk/provider-utils";
178
+ var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
179
+ function parseBase64DataUrl(value) {
180
+ const match = dataUrlRegex.exec(value);
181
+ if (match == null) {
182
+ return void 0;
183
+ }
184
+ return {
185
+ mediaType: match[1],
186
+ data: match[2]
187
+ };
188
+ }
189
+ function convertUrlToolResultPart(url) {
190
+ const parsedDataUrl = parseBase64DataUrl(url);
191
+ if (parsedDataUrl == null) {
192
+ return void 0;
193
+ }
194
+ return {
195
+ inlineData: {
196
+ mimeType: parsedDataUrl.mediaType,
197
+ data: parsedDataUrl.data
198
+ }
199
+ };
200
+ }
201
+ function appendToolResultParts(parts, toolName, outputValue) {
202
+ const functionResponseParts = [];
203
+ const responseTextParts = [];
204
+ for (const contentPart of outputValue) {
205
+ switch (contentPart.type) {
206
+ case "text": {
207
+ responseTextParts.push(contentPart.text);
208
+ break;
209
+ }
210
+ case "image-data":
211
+ case "file-data": {
212
+ functionResponseParts.push({
213
+ inlineData: {
214
+ mimeType: contentPart.mediaType,
215
+ data: contentPart.data
216
+ }
217
+ });
218
+ break;
219
+ }
220
+ case "image-url":
221
+ case "file-url": {
222
+ const functionResponsePart = convertUrlToolResultPart(
223
+ contentPart.url
224
+ );
225
+ if (functionResponsePart != null) {
226
+ functionResponseParts.push(functionResponsePart);
227
+ } else {
228
+ responseTextParts.push(JSON.stringify(contentPart));
229
+ }
230
+ break;
231
+ }
232
+ default: {
233
+ responseTextParts.push(JSON.stringify(contentPart));
234
+ break;
235
+ }
236
+ }
237
+ }
238
+ parts.push({
239
+ functionResponse: {
240
+ name: toolName,
241
+ response: {
242
+ name: toolName,
243
+ content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
244
+ },
245
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
246
+ }
247
+ });
248
+ }
249
+ function appendLegacyToolResultParts(parts, toolName, outputValue) {
250
+ for (const contentPart of outputValue) {
251
+ switch (contentPart.type) {
252
+ case "text":
253
+ parts.push({
254
+ functionResponse: {
255
+ name: toolName,
256
+ response: {
257
+ name: toolName,
258
+ content: contentPart.text
259
+ }
260
+ }
261
+ });
262
+ break;
263
+ case "image-data":
264
+ parts.push(
265
+ {
266
+ inlineData: {
267
+ mimeType: String(contentPart.mediaType),
268
+ data: String(contentPart.data)
269
+ }
270
+ },
271
+ {
272
+ text: "Tool executed successfully and returned this image as a response"
273
+ }
274
+ );
275
+ break;
276
+ default:
277
+ parts.push({ text: JSON.stringify(contentPart) });
278
+ break;
279
+ }
280
+ }
281
+ }
175
282
  function convertToGoogleGenerativeAIMessages(prompt, options) {
176
- var _a, _b, _c;
283
+ var _a, _b, _c, _d, _e, _f, _g, _h;
177
284
  const systemInstructionParts = [];
178
285
  const contents = [];
179
286
  let systemMessagesAllowed = true;
180
287
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
181
288
  const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
289
+ const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
182
290
  for (const { role, content } of prompt) {
183
291
  switch (role) {
184
292
  case "system": {
@@ -226,8 +334,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
226
334
  contents.push({
227
335
  role: "model",
228
336
  parts: content.map((part) => {
229
- var _a2, _b2, _c2, _d;
230
- 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;
337
+ var _a2, _b2, _c2, _d2;
338
+ 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;
231
339
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
232
340
  switch (part.type) {
233
341
  case "text": {
@@ -243,6 +351,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
243
351
  thoughtSignature
244
352
  };
245
353
  }
354
+ case "reasoning-file": {
355
+ if (part.data instanceof URL) {
356
+ throw new UnsupportedFunctionalityError({
357
+ functionality: "File data URLs in assistant messages are not supported"
358
+ });
359
+ }
360
+ return {
361
+ inlineData: {
362
+ mimeType: part.mediaType,
363
+ data: convertToBase64(part.data)
364
+ },
365
+ thought: true,
366
+ thoughtSignature
367
+ };
368
+ }
246
369
  case "file": {
247
370
  if (part.data instanceof URL) {
248
371
  throw new UnsupportedFunctionalityError({
@@ -254,10 +377,23 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
254
377
  mimeType: part.mediaType,
255
378
  data: convertToBase64(part.data)
256
379
  },
380
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
257
381
  thoughtSignature
258
382
  };
259
383
  }
260
384
  case "tool-call": {
385
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
386
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
387
+ if (serverToolCallId && serverToolType) {
388
+ return {
389
+ toolCall: {
390
+ toolType: serverToolType,
391
+ args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
392
+ id: serverToolCallId
393
+ },
394
+ thoughtSignature
395
+ };
396
+ }
261
397
  return {
262
398
  functionCall: {
263
399
  name: part.toolName,
@@ -266,6 +402,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
266
402
  thoughtSignature
267
403
  };
268
404
  }
405
+ case "tool-result": {
406
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
407
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
408
+ if (serverToolCallId && serverToolType) {
409
+ return {
410
+ toolResponse: {
411
+ toolType: serverToolType,
412
+ response: part.output.type === "json" ? part.output.value : {},
413
+ id: serverToolCallId
414
+ },
415
+ thoughtSignature
416
+ };
417
+ }
418
+ return void 0;
419
+ }
269
420
  }
270
421
  }).filter((part) => part !== void 0)
271
422
  });
@@ -278,38 +429,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
278
429
  if (part.type === "tool-approval-response") {
279
430
  continue;
280
431
  }
432
+ 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;
433
+ const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
434
+ const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
435
+ if (serverToolCallId && serverToolType) {
436
+ const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
437
+ if (contents.length > 0) {
438
+ const lastContent = contents[contents.length - 1];
439
+ if (lastContent.role === "model") {
440
+ lastContent.parts.push({
441
+ toolResponse: {
442
+ toolType: serverToolType,
443
+ response: part.output.type === "json" ? part.output.value : {},
444
+ id: serverToolCallId
445
+ },
446
+ thoughtSignature: serverThoughtSignature
447
+ });
448
+ continue;
449
+ }
450
+ }
451
+ }
281
452
  const output = part.output;
282
453
  if (output.type === "content") {
283
- for (const contentPart of output.value) {
284
- switch (contentPart.type) {
285
- case "text":
286
- parts.push({
287
- functionResponse: {
288
- name: part.toolName,
289
- response: {
290
- name: part.toolName,
291
- content: contentPart.text
292
- }
293
- }
294
- });
295
- break;
296
- case "image-data":
297
- parts.push(
298
- {
299
- inlineData: {
300
- mimeType: contentPart.mediaType,
301
- data: contentPart.data
302
- }
303
- },
304
- {
305
- text: "Tool executed successfully and returned this image as a response"
306
- }
307
- );
308
- break;
309
- default:
310
- parts.push({ text: JSON.stringify(contentPart) });
311
- break;
312
- }
454
+ if (supportsFunctionResponseParts) {
455
+ appendToolResultParts(parts, part.toolName, output.value);
456
+ } else {
457
+ appendLegacyToolResultParts(parts, part.toolName, output.value);
313
458
  }
314
459
  } else {
315
460
  parts.push({
@@ -317,7 +462,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
317
462
  name: part.toolName,
318
463
  response: {
319
464
  name: part.toolName,
320
- content: output.type === "execution-denied" ? (_c = output.reason) != null ? _c : "Tool execution denied." : output.value
465
+ content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
321
466
  }
322
467
  }
323
468
  });
@@ -486,7 +631,15 @@ var googleLanguageModelOptions = lazySchema2(
486
631
  latitude: z2.number(),
487
632
  longitude: z2.number()
488
633
  }).optional()
489
- }).optional()
634
+ }).optional(),
635
+ /**
636
+ * Optional. The service tier to use for the request.
637
+ */
638
+ serviceTier: z2.enum([
639
+ "SERVICE_TIER_STANDARD",
640
+ "SERVICE_TIER_FLEX",
641
+ "SERVICE_TIER_PRIORITY"
642
+ ]).optional()
490
643
  })
491
644
  )
492
645
  );
@@ -500,7 +653,7 @@ function prepareTools({
500
653
  toolChoice,
501
654
  modelId
502
655
  }) {
503
- var _a;
656
+ var _a, _b;
504
657
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
505
658
  const toolWarnings = [];
506
659
  const isLatest = [
@@ -509,13 +662,14 @@ function prepareTools({
509
662
  "gemini-pro-latest"
510
663
  ].some((id) => id === modelId);
511
664
  const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
665
+ const isGemini3orNewer = modelId.includes("gemini-3");
512
666
  const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
513
667
  if (tools == null) {
514
668
  return { tools: void 0, toolConfig: void 0, toolWarnings };
515
669
  }
516
670
  const hasFunctionTools = tools.some((tool) => tool.type === "function");
517
671
  const hasProviderTools = tools.some((tool) => tool.type === "provider");
518
- if (hasFunctionTools && hasProviderTools) {
672
+ if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
519
673
  toolWarnings.push({
520
674
  type: "unsupported",
521
675
  feature: `combination of function and provider-defined tools`
@@ -620,6 +774,45 @@ function prepareTools({
620
774
  break;
621
775
  }
622
776
  });
777
+ if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
778
+ const functionDeclarations2 = [];
779
+ for (const tool of tools) {
780
+ if (tool.type === "function") {
781
+ functionDeclarations2.push({
782
+ name: tool.name,
783
+ description: (_a = tool.description) != null ? _a : "",
784
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
785
+ });
786
+ }
787
+ }
788
+ const combinedToolConfig = {
789
+ functionCallingConfig: { mode: "VALIDATED" },
790
+ includeServerSideToolInvocations: true
791
+ };
792
+ if (toolChoice != null) {
793
+ switch (toolChoice.type) {
794
+ case "auto":
795
+ break;
796
+ case "none":
797
+ combinedToolConfig.functionCallingConfig = { mode: "NONE" };
798
+ break;
799
+ case "required":
800
+ combinedToolConfig.functionCallingConfig = { mode: "ANY" };
801
+ break;
802
+ case "tool":
803
+ combinedToolConfig.functionCallingConfig = {
804
+ mode: "ANY",
805
+ allowedFunctionNames: [toolChoice.toolName]
806
+ };
807
+ break;
808
+ }
809
+ }
810
+ return {
811
+ tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
812
+ toolConfig: combinedToolConfig,
813
+ toolWarnings
814
+ };
815
+ }
623
816
  return {
624
817
  tools: googleTools2.length > 0 ? googleTools2 : void 0,
625
818
  toolConfig: void 0,
@@ -633,7 +826,7 @@ function prepareTools({
633
826
  case "function":
634
827
  functionDeclarations.push({
635
828
  name: tool.name,
636
- description: (_a = tool.description) != null ? _a : "",
829
+ description: (_b = tool.description) != null ? _b : "",
637
830
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
638
831
  });
639
832
  if (tool.strict === true) {
@@ -732,7 +925,7 @@ function mapGoogleGenerativeAIFinishReason({
732
925
  // src/google-generative-ai-language-model.ts
733
926
  var GoogleGenerativeAILanguageModel = class {
734
927
  constructor(modelId, config) {
735
- this.specificationVersion = "v3";
928
+ this.specificationVersion = "v4";
736
929
  var _a;
737
930
  this.modelId = modelId;
738
931
  this.config = config;
@@ -758,6 +951,7 @@ var GoogleGenerativeAILanguageModel = class {
758
951
  seed,
759
952
  tools,
760
953
  toolChoice,
954
+ reasoning,
761
955
  providerOptions
762
956
  }) {
763
957
  var _a;
@@ -784,9 +978,14 @@ var GoogleGenerativeAILanguageModel = class {
784
978
  });
785
979
  }
786
980
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
981
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
787
982
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
788
983
  prompt,
789
- { isGemmaModel, providerOptionsName }
984
+ {
985
+ isGemmaModel,
986
+ providerOptionsName,
987
+ supportsFunctionResponseParts
988
+ }
790
989
  );
791
990
  const {
792
991
  tools: googleTools2,
@@ -797,6 +996,12 @@ var GoogleGenerativeAILanguageModel = class {
797
996
  toolChoice,
798
997
  modelId: this.modelId
799
998
  });
999
+ const resolvedThinking = resolveThinkingConfig({
1000
+ reasoning,
1001
+ modelId: this.modelId,
1002
+ warnings
1003
+ });
1004
+ const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
800
1005
  return {
801
1006
  args: {
802
1007
  generationConfig: {
@@ -820,7 +1025,7 @@ var GoogleGenerativeAILanguageModel = class {
820
1025
  },
821
1026
  // provider options:
822
1027
  responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
823
- thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig,
1028
+ thinkingConfig,
824
1029
  ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
825
1030
  mediaResolution: googleOptions.mediaResolution
826
1031
  },
@@ -837,14 +1042,15 @@ var GoogleGenerativeAILanguageModel = class {
837
1042
  retrievalConfig: googleOptions.retrievalConfig
838
1043
  } : googleToolConfig,
839
1044
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
840
- labels: googleOptions == null ? void 0 : googleOptions.labels
1045
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
1046
+ serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
841
1047
  },
842
1048
  warnings: [...warnings, ...toolWarnings],
843
1049
  providerOptionsName
844
1050
  };
845
1051
  }
846
1052
  async doGenerate(options) {
847
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1053
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
848
1054
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
849
1055
  const mergedHeaders = combineHeaders(
850
1056
  await resolve(this.config.headers),
@@ -870,6 +1076,7 @@ var GoogleGenerativeAILanguageModel = class {
870
1076
  const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
871
1077
  const usageMetadata = response.usageMetadata;
872
1078
  let lastCodeExecutionToolCallId;
1079
+ let lastServerToolCallId;
873
1080
  for (const part of parts) {
874
1081
  if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
875
1082
  const toolCallId = this.config.generateId();
@@ -924,22 +1131,68 @@ var GoogleGenerativeAILanguageModel = class {
924
1131
  } : void 0
925
1132
  });
926
1133
  } else if ("inlineData" in part) {
1134
+ const hasThought = part.thought === true;
1135
+ const hasThoughtSignature = !!part.thoughtSignature;
927
1136
  content.push({
928
- type: "file",
1137
+ type: hasThought ? "reasoning-file" : "file",
929
1138
  data: part.inlineData.data,
930
1139
  mediaType: part.inlineData.mimeType,
931
- providerMetadata: part.thoughtSignature ? {
1140
+ providerMetadata: hasThoughtSignature ? {
932
1141
  [providerOptionsName]: {
933
1142
  thoughtSignature: part.thoughtSignature
934
1143
  }
935
1144
  } : void 0
936
1145
  });
1146
+ } else if ("toolCall" in part && part.toolCall) {
1147
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1148
+ lastServerToolCallId = toolCallId;
1149
+ content.push({
1150
+ type: "tool-call",
1151
+ toolCallId,
1152
+ toolName: `server:${part.toolCall.toolType}`,
1153
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1154
+ providerExecuted: true,
1155
+ dynamic: true,
1156
+ providerMetadata: part.thoughtSignature ? {
1157
+ [providerOptionsName]: {
1158
+ thoughtSignature: part.thoughtSignature,
1159
+ serverToolCallId: toolCallId,
1160
+ serverToolType: part.toolCall.toolType
1161
+ }
1162
+ } : {
1163
+ [providerOptionsName]: {
1164
+ serverToolCallId: toolCallId,
1165
+ serverToolType: part.toolCall.toolType
1166
+ }
1167
+ }
1168
+ });
1169
+ } else if ("toolResponse" in part && part.toolResponse) {
1170
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1171
+ content.push({
1172
+ type: "tool-result",
1173
+ toolCallId: responseToolCallId,
1174
+ toolName: `server:${part.toolResponse.toolType}`,
1175
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1176
+ providerMetadata: part.thoughtSignature ? {
1177
+ [providerOptionsName]: {
1178
+ thoughtSignature: part.thoughtSignature,
1179
+ serverToolCallId: responseToolCallId,
1180
+ serverToolType: part.toolResponse.toolType
1181
+ }
1182
+ } : {
1183
+ [providerOptionsName]: {
1184
+ serverToolCallId: responseToolCallId,
1185
+ serverToolType: part.toolResponse.toolType
1186
+ }
1187
+ }
1188
+ });
1189
+ lastServerToolCallId = void 0;
937
1190
  }
938
1191
  }
939
- const sources = (_e = extractSources({
1192
+ const sources = (_i = extractSources({
940
1193
  groundingMetadata: candidate.groundingMetadata,
941
1194
  generateId: this.config.generateId
942
- })) != null ? _e : [];
1195
+ })) != null ? _i : [];
943
1196
  for (const source of sources) {
944
1197
  content.push(source);
945
1198
  }
@@ -953,17 +1206,19 @@ var GoogleGenerativeAILanguageModel = class {
953
1206
  (part) => part.type === "tool-call" && !part.providerExecuted
954
1207
  )
955
1208
  }),
956
- raw: (_f = candidate.finishReason) != null ? _f : void 0
1209
+ raw: (_j = candidate.finishReason) != null ? _j : void 0
957
1210
  },
958
1211
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
959
1212
  warnings,
960
1213
  providerMetadata: {
961
1214
  [providerOptionsName]: {
962
- promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
963
- groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
964
- urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
965
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
966
- usageMetadata: usageMetadata != null ? usageMetadata : null
1215
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1216
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1217
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1218
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1219
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1220
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1221
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
967
1222
  }
968
1223
  },
969
1224
  request: { body: args },
@@ -999,6 +1254,7 @@ var GoogleGenerativeAILanguageModel = class {
999
1254
  let providerMetadata = void 0;
1000
1255
  let lastGroundingMetadata = null;
1001
1256
  let lastUrlContextMetadata = null;
1257
+ let serviceTier = null;
1002
1258
  const generateId2 = this.config.generateId;
1003
1259
  let hasToolCalls = false;
1004
1260
  let currentTextBlockId = null;
@@ -1006,6 +1262,7 @@ var GoogleGenerativeAILanguageModel = class {
1006
1262
  let blockCounter = 0;
1007
1263
  const emittedSourceUrls = /* @__PURE__ */ new Set();
1008
1264
  let lastCodeExecutionToolCallId;
1265
+ let lastServerToolCallId;
1009
1266
  return {
1010
1267
  stream: response.pipeThrough(
1011
1268
  new TransformStream({
@@ -1013,7 +1270,7 @@ var GoogleGenerativeAILanguageModel = class {
1013
1270
  controller.enqueue({ type: "stream-start", warnings });
1014
1271
  },
1015
1272
  transform(chunk, controller) {
1016
- var _a, _b, _c, _d, _e, _f;
1273
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1017
1274
  if (options.includeRawChunks) {
1018
1275
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1019
1276
  }
@@ -1026,6 +1283,9 @@ var GoogleGenerativeAILanguageModel = class {
1026
1283
  if (usageMetadata != null) {
1027
1284
  usage = usageMetadata;
1028
1285
  }
1286
+ if (value.serviceTier != null) {
1287
+ serviceTier = value.serviceTier;
1288
+ }
1029
1289
  const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1030
1290
  if (candidate == null) {
1031
1291
  return;
@@ -1151,17 +1411,55 @@ var GoogleGenerativeAILanguageModel = class {
1151
1411
  });
1152
1412
  currentReasoningBlockId = null;
1153
1413
  }
1154
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1414
+ const hasThought = part.thought === true;
1415
+ const hasThoughtSignature = !!part.thoughtSignature;
1416
+ const fileMeta = hasThoughtSignature ? {
1155
1417
  [providerOptionsName]: {
1156
1418
  thoughtSignature: part.thoughtSignature
1157
1419
  }
1158
1420
  } : void 0;
1159
1421
  controller.enqueue({
1160
- type: "file",
1422
+ type: hasThought ? "reasoning-file" : "file",
1161
1423
  mediaType: part.inlineData.mimeType,
1162
1424
  data: part.inlineData.data,
1163
- providerMetadata: thoughtSignatureMetadata
1425
+ providerMetadata: fileMeta
1426
+ });
1427
+ } else if ("toolCall" in part && part.toolCall) {
1428
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
1429
+ lastServerToolCallId = toolCallId;
1430
+ const serverMeta = {
1431
+ [providerOptionsName]: {
1432
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1433
+ serverToolCallId: toolCallId,
1434
+ serverToolType: part.toolCall.toolType
1435
+ }
1436
+ };
1437
+ controller.enqueue({
1438
+ type: "tool-call",
1439
+ toolCallId,
1440
+ toolName: `server:${part.toolCall.toolType}`,
1441
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1442
+ providerExecuted: true,
1443
+ dynamic: true,
1444
+ providerMetadata: serverMeta
1164
1445
  });
1446
+ } else if ("toolResponse" in part && part.toolResponse) {
1447
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
1448
+ const serverMeta = {
1449
+ [providerOptionsName]: {
1450
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1451
+ serverToolCallId: responseToolCallId,
1452
+ serverToolType: part.toolResponse.toolType
1453
+ }
1454
+ };
1455
+ controller.enqueue({
1456
+ type: "tool-result",
1457
+ toolCallId: responseToolCallId,
1458
+ toolName: `server:${part.toolResponse.toolType}`,
1459
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1460
+ providerMetadata: serverMeta
1461
+ });
1462
+ lastServerToolCallId = void 0;
1165
1463
  }
1166
1464
  }
1167
1465
  const toolCallDeltas = getToolCallsFromParts({
@@ -1209,15 +1507,15 @@ var GoogleGenerativeAILanguageModel = class {
1209
1507
  };
1210
1508
  providerMetadata = {
1211
1509
  [providerOptionsName]: {
1212
- promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1510
+ promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
1213
1511
  groundingMetadata: lastGroundingMetadata,
1214
1512
  urlContextMetadata: lastUrlContextMetadata,
1215
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1513
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1514
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1515
+ finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
1516
+ serviceTier
1216
1517
  }
1217
1518
  };
1218
- if (usageMetadata != null) {
1219
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1220
- }
1221
1519
  }
1222
1520
  },
1223
1521
  flush(controller) {
@@ -1247,6 +1545,75 @@ var GoogleGenerativeAILanguageModel = class {
1247
1545
  };
1248
1546
  }
1249
1547
  };
1548
+ function isGemini3Model(modelId) {
1549
+ return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
1550
+ }
1551
+ function getMaxOutputTokensForGemini25Model() {
1552
+ return 65536;
1553
+ }
1554
+ function getMaxThinkingTokensForGemini25Model(modelId) {
1555
+ const id = modelId.toLowerCase();
1556
+ if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
1557
+ return 32768;
1558
+ }
1559
+ return 24576;
1560
+ }
1561
+ function resolveThinkingConfig({
1562
+ reasoning,
1563
+ modelId,
1564
+ warnings
1565
+ }) {
1566
+ if (!isCustomReasoning(reasoning)) {
1567
+ return void 0;
1568
+ }
1569
+ if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
1570
+ return resolveGemini3ThinkingConfig({ reasoning, warnings });
1571
+ }
1572
+ return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
1573
+ }
1574
+ function resolveGemini3ThinkingConfig({
1575
+ reasoning,
1576
+ warnings
1577
+ }) {
1578
+ if (reasoning === "none") {
1579
+ return { thinkingLevel: "minimal" };
1580
+ }
1581
+ const thinkingLevel = mapReasoningToProviderEffort({
1582
+ reasoning,
1583
+ effortMap: {
1584
+ minimal: "minimal",
1585
+ low: "low",
1586
+ medium: "medium",
1587
+ high: "high",
1588
+ xhigh: "high"
1589
+ },
1590
+ warnings
1591
+ });
1592
+ if (thinkingLevel == null) {
1593
+ return void 0;
1594
+ }
1595
+ return { thinkingLevel };
1596
+ }
1597
+ function resolveGemini25ThinkingConfig({
1598
+ reasoning,
1599
+ modelId,
1600
+ warnings
1601
+ }) {
1602
+ if (reasoning === "none") {
1603
+ return { thinkingBudget: 0 };
1604
+ }
1605
+ const thinkingBudget = mapReasoningToProviderBudget({
1606
+ reasoning,
1607
+ maxOutputTokens: getMaxOutputTokensForGemini25Model(),
1608
+ maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
1609
+ minReasoningBudget: 0,
1610
+ warnings
1611
+ });
1612
+ if (thinkingBudget == null) {
1613
+ return void 0;
1614
+ }
1615
+ return { thinkingBudget };
1616
+ }
1250
1617
  function getToolCallsFromParts({
1251
1618
  parts,
1252
1619
  generateId: generateId2,
@@ -1426,6 +1793,23 @@ var getContentSchema = () => z3.object({
1426
1793
  mimeType: z3.string(),
1427
1794
  data: z3.string()
1428
1795
  }),
1796
+ thought: z3.boolean().nullish(),
1797
+ thoughtSignature: z3.string().nullish()
1798
+ }),
1799
+ z3.object({
1800
+ toolCall: z3.object({
1801
+ toolType: z3.string(),
1802
+ args: z3.unknown().nullish(),
1803
+ id: z3.string()
1804
+ }),
1805
+ thoughtSignature: z3.string().nullish()
1806
+ }),
1807
+ z3.object({
1808
+ toolResponse: z3.object({
1809
+ toolType: z3.string(),
1810
+ response: z3.unknown().nullish(),
1811
+ id: z3.string()
1812
+ }),
1429
1813
  thoughtSignature: z3.string().nullish()
1430
1814
  }),
1431
1815
  z3.object({
@@ -1476,6 +1860,7 @@ var responseSchema = lazySchema3(
1476
1860
  z3.object({
1477
1861
  content: getContentSchema().nullish().or(z3.object({}).strict()),
1478
1862
  finishReason: z3.string().nullish(),
1863
+ finishMessage: z3.string().nullish(),
1479
1864
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1480
1865
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1481
1866
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1485,7 +1870,8 @@ var responseSchema = lazySchema3(
1485
1870
  promptFeedback: z3.object({
1486
1871
  blockReason: z3.string().nullish(),
1487
1872
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1488
- }).nullish()
1873
+ }).nullish(),
1874
+ serviceTier: z3.string().nullish()
1489
1875
  })
1490
1876
  )
1491
1877
  );
@@ -1496,6 +1882,7 @@ var chunkSchema = lazySchema3(
1496
1882
  z3.object({
1497
1883
  content: getContentSchema().nullish(),
1498
1884
  finishReason: z3.string().nullish(),
1885
+ finishMessage: z3.string().nullish(),
1499
1886
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1500
1887
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1501
1888
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -1505,7 +1892,8 @@ var chunkSchema = lazySchema3(
1505
1892
  promptFeedback: z3.object({
1506
1893
  blockReason: z3.string().nullish(),
1507
1894
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1508
- }).nullish()
1895
+ }).nullish(),
1896
+ serviceTier: z3.string().nullish()
1509
1897
  })
1510
1898
  )
1511
1899
  );