@ai-sdk/google 3.0.90 → 3.0.91

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": "3.0.90",
3
+ "version": "3.0.91",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -36,8 +36,8 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@ai-sdk/provider": "3.0.13",
40
- "@ai-sdk/provider-utils": "4.0.37"
39
+ "@ai-sdk/provider": "3.0.14",
40
+ "@ai-sdk/provider-utils": "4.0.38"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -188,6 +188,9 @@ function appendLegacyToolResultParts(
188
188
  });
189
189
  break;
190
190
  case 'image-data':
191
+ case 'file-data': {
192
+ const topLevelMediaType = String(contentPart.mediaType).split('/')[0];
193
+
191
194
  parts.push(
192
195
  {
193
196
  inlineData: {
@@ -196,10 +199,14 @@ function appendLegacyToolResultParts(
196
199
  },
197
200
  },
198
201
  {
199
- text: 'Tool executed successfully and returned this image as a response',
202
+ text:
203
+ `Tool executed successfully and returned this ` +
204
+ `${topLevelMediaType === 'image' ? 'image' : 'file'} ` +
205
+ `as a response`,
200
206
  },
201
207
  );
202
208
  break;
209
+ }
203
210
  default:
204
211
  parts.push({ text: JSON.stringify(contentPart) });
205
212
  break;
@@ -50,6 +50,13 @@ import {
50
50
  } from './google-json-accumulator';
51
51
  import { mapGoogleGenerativeAIFinishReason } from './map-google-generative-ai-finish-reason';
52
52
 
53
+ const configurableSafetySettingCategories = [
54
+ 'HARM_CATEGORY_HATE_SPEECH',
55
+ 'HARM_CATEGORY_DANGEROUS_CONTENT',
56
+ 'HARM_CATEGORY_HARASSMENT',
57
+ 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
58
+ ] as const;
59
+
53
60
  type GoogleGenerativeAIConfig = {
54
61
  provider: string;
55
62
  baseURL: string;
@@ -223,6 +230,16 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
223
230
  ? (googleOptions?.streamFunctionCallArguments ?? false)
224
231
  : undefined;
225
232
 
233
+ const safetyThreshold = googleOptions?.threshold;
234
+ const safetySettings =
235
+ googleOptions?.safetySettings ??
236
+ (safetyThreshold != null
237
+ ? configurableSafetySettingCategories.map(category => ({
238
+ category,
239
+ threshold: safetyThreshold,
240
+ }))
241
+ : undefined);
242
+
226
243
  const toolConfig =
227
244
  googleToolConfig ||
228
245
  streamFunctionCallArguments ||
@@ -282,7 +299,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
282
299
  },
283
300
  contents,
284
301
  systemInstruction: isGemmaModel ? undefined : systemInstruction,
285
- safetySettings: googleOptions?.safetySettings,
302
+ safetySettings,
286
303
  tools: googleTools,
287
304
  toolConfig,
288
305
  cachedContent: googleOptions?.cachedContent,
@@ -110,13 +110,11 @@ function convertFileToGoogleImage(
110
110
  ? file.data
111
111
  : convertUint8ArrayToBase64(file.data);
112
112
 
113
- // The Gemini Developer API (generativelanguage.googleapis.com) requires
114
- // inline image bytes wrapped as `inlineData`.
113
+ // Veo's predictLongRunning endpoint uses Vertex-style image payloads, not
114
+ // Gemini generateContent inlineData.
115
115
  return {
116
- inlineData: {
117
- mimeType: file.mediaType || 'image/png',
118
- data: base64Data,
119
- },
116
+ bytesBase64Encoded: base64Data,
117
+ mimeType: file.mediaType || 'image/png',
120
118
  };
121
119
  }
122
120
 
@@ -125,16 +123,19 @@ function convertProviderReferenceImage(
125
123
  ): Record<string, unknown> {
126
124
  if (refImg.bytesBase64Encoded) {
127
125
  return {
128
- inlineData: {
126
+ image: {
127
+ bytesBase64Encoded: refImg.bytesBase64Encoded,
129
128
  mimeType: 'image/png',
130
- data: refImg.bytesBase64Encoded,
131
129
  },
132
130
  };
133
131
  }
134
132
 
135
133
  if (refImg.gcsUri) {
136
134
  return {
137
- gcsUri: refImg.gcsUri,
135
+ image: {
136
+ gcsUri: refImg.gcsUri,
137
+ mimeType: 'image/png',
138
+ },
138
139
  };
139
140
  }
140
141
 
@@ -146,7 +147,7 @@ function convertInputReferenceImage(
146
147
  warnings: SharedV3Warning[],
147
148
  ): Record<string, unknown> | undefined {
148
149
  const image = convertFileToGoogleImage(file, warnings);
149
- return image != null ? { image, referenceType: 'asset' } : undefined;
150
+ return image != null ? { image } : undefined;
150
151
  }
151
152
 
152
153
  export class GoogleGenerativeAIVideoModel implements Experimental_VideoModelV3 {