@ai-sdk/google-vertex 4.0.197 → 4.0.198

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.
@@ -174,11 +174,24 @@ export class GoogleVertexImageModel implements ImageModelV3 {
174
174
  fetch: this.config.fetch,
175
175
  });
176
176
 
177
+ const imagePredictions =
178
+ response.predictions?.filter(
179
+ (
180
+ prediction,
181
+ ): prediction is {
182
+ bytesBase64Encoded: string;
183
+ mimeType: string;
184
+ prompt?: string | null;
185
+ } => 'bytesBase64Encoded' in prediction,
186
+ ) ?? [];
187
+
177
188
  return {
178
- images:
179
- response.predictions?.map(
180
- ({ bytesBase64Encoded }) => bytesBase64Encoded,
181
- ) ?? [],
189
+ images: imagePredictions.map(
190
+ ({ bytesBase64Encoded }) => bytesBase64Encoded,
191
+ ),
192
+ ...(response.predictions?.some(
193
+ prediction => 'raiFilteredReason' in prediction,
194
+ ) && { isRetryable: false }),
182
195
  warnings,
183
196
  response: {
184
197
  timestamp: currentDate,
@@ -188,7 +201,7 @@ export class GoogleVertexImageModel implements ImageModelV3 {
188
201
  providerMetadata: {
189
202
  vertex: {
190
203
  images:
191
- response.predictions?.map(prediction => {
204
+ imagePredictions.map(prediction => {
192
205
  const {
193
206
  // normalize revised prompt property
194
207
  prompt: revisedPrompt,
@@ -317,6 +330,9 @@ export class GoogleVertexImageModel implements ImageModelV3 {
317
330
 
318
331
  return {
319
332
  images,
333
+ ...(result.finishReason.unified === 'content-filter'
334
+ ? { isRetryable: false }
335
+ : {}),
320
336
  warnings,
321
337
  providerMetadata: {
322
338
  vertex: {
@@ -350,11 +366,14 @@ function isGeminiModel(modelId: string): boolean {
350
366
  const vertexImageResponseSchema = z.object({
351
367
  predictions: z
352
368
  .array(
353
- z.object({
354
- bytesBase64Encoded: z.string(),
355
- mimeType: z.string(),
356
- prompt: z.string().nullish(),
357
- }),
369
+ z.union([
370
+ z.object({
371
+ bytesBase64Encoded: z.string(),
372
+ mimeType: z.string(),
373
+ prompt: z.string().nullish(),
374
+ }),
375
+ z.object({ raiFilteredReason: z.string() }),
376
+ ]),
358
377
  )
359
378
  .nullish(),
360
379
  });