@ai-sdk/google 4.0.45 → 4.0.47

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.45",
3
+ "version": "4.0.47",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.7",
39
- "@ai-sdk/provider-utils": "5.0.27"
39
+ "@ai-sdk/provider-utils": "5.0.28"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "22.19.19",
@@ -466,7 +466,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
466
466
  } else if ('functionCall' in part && part.functionCall.name != null) {
467
467
  content.push({
468
468
  type: 'tool-call' as const,
469
- toolCallId: part.functionCall.id ?? this.config.generateId(),
469
+ toolCallId: part.functionCall.id || this.config.generateId(),
470
470
  toolName: part.functionCall.name,
471
471
  input: JSON.stringify(part.functionCall.args ?? {}),
472
472
  providerMetadata: part.thoughtSignature
@@ -489,7 +489,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
489
489
  : undefined,
490
490
  });
491
491
  } else if ('toolCall' in part && part.toolCall) {
492
- const toolCallId = part.toolCall.id ?? this.config.generateId();
492
+ const toolCallId = part.toolCall.id || this.config.generateId();
493
493
  lastServerToolCallId = toolCallId;
494
494
  content.push({
495
495
  type: 'tool-call',
@@ -511,8 +511,8 @@ export class GoogleLanguageModel implements LanguageModelV4 {
511
511
  });
512
512
  } else if ('toolResponse' in part && part.toolResponse) {
513
513
  const responseToolCallId =
514
- lastServerToolCallId ??
515
- part.toolResponse.id ??
514
+ lastServerToolCallId ||
515
+ part.toolResponse.id ||
516
516
  this.config.generateId();
517
517
  content.push({
518
518
  type: 'tool-result',
@@ -876,7 +876,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
876
876
  providerMetadata: fileMeta,
877
877
  });
878
878
  } else if ('toolCall' in part && part.toolCall) {
879
- const toolCallId = part.toolCall.id ?? generateId();
879
+ const toolCallId = part.toolCall.id || generateId();
880
880
  lastServerToolCallId = toolCallId;
881
881
  const serverMeta = wrapProviderMetadata({
882
882
  ...(part.thoughtSignature
@@ -897,8 +897,8 @@ export class GoogleLanguageModel implements LanguageModelV4 {
897
897
  });
898
898
  } else if ('toolResponse' in part && part.toolResponse) {
899
899
  const responseToolCallId =
900
- lastServerToolCallId ??
901
- part.toolResponse.id ??
900
+ lastServerToolCallId ||
901
+ part.toolResponse.id ||
902
902
  generateId();
903
903
  const serverMeta = wrapProviderMetadata({
904
904
  ...(part.thoughtSignature
@@ -952,7 +952,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
952
952
 
953
953
  if (isStreamingChunk) {
954
954
  if (part.functionCall.name != null) {
955
- const toolCallId = part.functionCall.id ?? generateId();
955
+ const toolCallId = part.functionCall.id || generateId();
956
956
  const accumulator = new GoogleJSONAccumulator();
957
957
  activeStreamingToolCalls.push({
958
958
  toolCallId,
@@ -1021,7 +1021,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
1021
1021
  ) {
1022
1022
  finishActiveStreamingToolCall(controller);
1023
1023
  } else if (isCompleteCall) {
1024
- const toolCallId = part.functionCall.id ?? generateId();
1024
+ const toolCallId = part.functionCall.id || generateId();
1025
1025
  const toolName = part.functionCall.name!;
1026
1026
  const args =
1027
1027
  typeof part.functionCall.args === 'string'
@@ -1058,7 +1058,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
1058
1058
 
1059
1059
  hasToolCalls = true;
1060
1060
  } else if (isNoArgsCompleteCall) {
1061
- const toolCallId = part.functionCall.id ?? generateId();
1061
+ const toolCallId = part.functionCall.id || generateId();
1062
1062
  const toolName = part.functionCall.name!;
1063
1063
 
1064
1064
  controller.enqueue({
@@ -1188,9 +1188,7 @@ function resolveGemini3ThinkingConfig({
1188
1188
  modelId: string;
1189
1189
  warnings: SharedV4Warning[];
1190
1190
  }): Pick<GoogleThinkingConfig, 'thinkingLevel'> | undefined {
1191
- const minimumThinkingLevel = /(^|\/)gemini-3\.7-flash$/i.test(modelId)
1192
- ? 'low'
1193
- : 'minimal';
1191
+ const minimumThinkingLevel = getMinimumThinkingLevelForGemini3Model(modelId);
1194
1192
 
1195
1193
  if (reasoning === 'none') {
1196
1194
  // It's not possible to fully disable thinking with Gemini 3.
@@ -1216,6 +1214,31 @@ function resolveGemini3ThinkingConfig({
1216
1214
  return { thinkingLevel };
1217
1215
  }
1218
1216
 
1217
+ function getMinimumThinkingLevelForGemini3Model(
1218
+ modelId: string,
1219
+ ): 'minimal' | 'low' {
1220
+ const modelName = modelId.split('/').at(-1)?.toLowerCase();
1221
+
1222
+ if (modelName === 'gemini-flash-latest') {
1223
+ return 'low';
1224
+ }
1225
+
1226
+ const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
1227
+ modelName ?? '',
1228
+ );
1229
+
1230
+ if (versionMatch == null) {
1231
+ return 'minimal';
1232
+ }
1233
+
1234
+ const majorVersion = Number(versionMatch[1]);
1235
+ const minorVersion = Number(versionMatch[2]);
1236
+
1237
+ return majorVersion > 3 || (majorVersion === 3 && minorVersion >= 7)
1238
+ ? 'low'
1239
+ : 'minimal';
1240
+ }
1241
+
1219
1242
  function resolveGemini25ThinkingConfig({
1220
1243
  reasoning,
1221
1244
  modelId,
@@ -335,7 +335,7 @@ export function buildGoogleInteractionsStreamTransform({
335
335
  }
336
336
  }
337
337
  } else if (stepType === 'function_call') {
338
- const toolCallId = step?.id ?? blockId;
338
+ const toolCallId = step?.id || blockId;
339
339
  const toolName = step?.name ?? 'unknown';
340
340
  hasFunctionCall = true;
341
341
  const state: Extract<OpenBlockState, { kind: 'function_call' }> = {
@@ -360,7 +360,7 @@ export function buildGoogleInteractionsStreamTransform({
360
360
  stepType === 'mcp_server_tool_call'
361
361
  ? (step?.name ?? 'mcp_server_tool')
362
362
  : builtinToolNameFromCallType(stepType);
363
- const toolCallId = step?.id ?? blockId;
363
+ const toolCallId = step?.id || blockId;
364
364
  const state: Extract<
365
365
  OpenBlockState,
366
366
  { kind: 'builtin_tool_call' }
@@ -382,7 +382,7 @@ export function buildGoogleInteractionsStreamTransform({
382
382
  stepType === 'mcp_server_tool_result'
383
383
  ? (step?.name ?? 'mcp_server_tool')
384
384
  : builtinToolNameFromResultType(stepType);
385
- const callId = step?.call_id ?? blockId;
385
+ const callId = step?.call_id || blockId;
386
386
  const state: Extract<
387
387
  OpenBlockState,
388
388
  { kind: 'builtin_tool_result' }
@@ -608,7 +608,7 @@ export function buildGoogleInteractionsStreamTransform({
608
608
  delta: slice,
609
609
  });
610
610
  }
611
- if (delta.id != null) {
611
+ if (delta.id != null && delta.id.length > 0) {
612
612
  open.toolCallId = delta.id;
613
613
  }
614
614
  if (delta.signature != null) {
@@ -619,7 +619,9 @@ export function buildGoogleInteractionsStreamTransform({
619
619
  open.kind === 'builtin_tool_call' &&
620
620
  delta?.type === open.blockType
621
621
  ) {
622
- if (delta.id != null) open.toolCallId = delta.id;
622
+ if (delta.id != null && delta.id.length > 0) {
623
+ open.toolCallId = delta.id;
624
+ }
623
625
  if (
624
626
  delta.arguments != null &&
625
627
  typeof delta.arguments === 'object'
@@ -636,7 +638,9 @@ export function buildGoogleInteractionsStreamTransform({
636
638
  open.kind === 'builtin_tool_result' &&
637
639
  delta?.type === open.blockType
638
640
  ) {
639
- if (delta.call_id != null) open.callId = delta.call_id;
641
+ if (delta.call_id != null && delta.call_id.length > 0) {
642
+ open.callId = delta.call_id;
643
+ }
640
644
  if (delta.result !== undefined) open.result = delta.result;
641
645
  if (delta.is_error != null) open.isError = delta.is_error;
642
646
  if (
@@ -233,7 +233,7 @@ export function parseGoogleInteractionsOutputs({
233
233
  const input = JSON.stringify(call.arguments ?? {});
234
234
  content.push({
235
235
  type: 'tool-call',
236
- toolCallId: call.id ?? generateId(),
236
+ toolCallId: call.id || generateId(),
237
237
  toolName,
238
238
  input,
239
239
  providerExecuted: true,
@@ -251,7 +251,7 @@ export function parseGoogleInteractionsOutputs({
251
251
  : builtinToolNameFromResultType(type);
252
252
  content.push({
253
253
  type: 'tool-result',
254
- toolCallId: result.call_id ?? generateId(),
254
+ toolCallId: result.call_id || generateId(),
255
255
  toolName,
256
256
  result: (result.result ?? null) as NonNullable<JSONValue>,
257
257
  });