@ai-sdk/google 3.0.121 → 3.0.122

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.121",
3
+ "version": "3.0.122",
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.15",
40
- "@ai-sdk/provider-utils": "4.0.50"
39
+ "@ai-sdk/provider": "3.0.16",
40
+ "@ai-sdk/provider-utils": "4.0.51"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "20.17.24",
@@ -159,7 +159,9 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
159
159
  };
160
160
 
161
161
  const { responseHeaders, value: response } = await postJsonToApi<{
162
- predictions: Array<{ bytesBase64Encoded: string }>;
162
+ predictions: Array<
163
+ { bytesBase64Encoded: string } | { raiFilteredReason: string }
164
+ >;
163
165
  }>({
164
166
  url: `${this.config.baseURL}/models/${this.modelId}:predict`,
165
167
  headers: combineHeaders(await resolve(this.config.headers), headers),
@@ -171,14 +173,22 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
171
173
  abortSignal,
172
174
  fetch: this.config.fetch,
173
175
  });
176
+ const imagePredictions = response.predictions.filter(
177
+ (prediction): prediction is { bytesBase64Encoded: string } =>
178
+ 'bytesBase64Encoded' in prediction,
179
+ );
180
+
174
181
  return {
175
- images: response.predictions.map(
176
- (p: { bytesBase64Encoded: string }) => p.bytesBase64Encoded,
182
+ images: imagePredictions.map(
183
+ ({ bytesBase64Encoded }) => bytesBase64Encoded,
177
184
  ),
185
+ ...(response.predictions.some(
186
+ prediction => 'raiFilteredReason' in prediction,
187
+ ) && { isRetryable: false }),
178
188
  warnings,
179
189
  providerMetadata: {
180
190
  google: {
181
- images: response.predictions.map(() => ({
191
+ images: imagePredictions.map(() => ({
182
192
  // Add any prediction-specific metadata here
183
193
  })),
184
194
  },
@@ -341,6 +351,9 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
341
351
 
342
352
  return {
343
353
  images,
354
+ ...(result.finishReason.unified === 'content-filter'
355
+ ? { isRetryable: false }
356
+ : {}),
344
357
  warnings,
345
358
  providerMetadata: {
346
359
  google: {
@@ -375,7 +388,12 @@ const googleImageResponseSchema = lazySchema(() =>
375
388
  zodSchema(
376
389
  z.object({
377
390
  predictions: z
378
- .array(z.object({ bytesBase64Encoded: z.string() }))
391
+ .array(
392
+ z.union([
393
+ z.object({ bytesBase64Encoded: z.string() }),
394
+ z.object({ raiFilteredReason: z.string() }),
395
+ ]),
396
+ )
379
397
  .default([]),
380
398
  }),
381
399
  ),