@ai-sdk/google 3.0.77 → 3.0.79

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.77",
3
+ "version": "3.0.79",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -12,6 +12,7 @@ export type GoogleGenerativeAIUsageMetadata = {
12
12
  cachedContentTokenCount?: number | null;
13
13
  thoughtsTokenCount?: number | null;
14
14
  trafficType?: string | null;
15
+ serviceTier?: string | null;
15
16
  promptTokensDetails?: GoogleGenerativeAITokenDetail[] | null;
16
17
  candidatesTokensDetails?: GoogleGenerativeAITokenDetail[] | null;
17
18
  };
@@ -14,8 +14,8 @@ import {
14
14
  resolve,
15
15
  zodSchema,
16
16
  type FetchFunction,
17
- type Resolvable,
18
17
  type InferSchema,
18
+ type Resolvable,
19
19
  } from '@ai-sdk/provider-utils';
20
20
  import { z } from 'zod/v4';
21
21
  import { googleFailedResponseHandler } from './google-error';
@@ -25,6 +25,7 @@ import type {
25
25
  } from './google-generative-ai-image-settings';
26
26
  import { GoogleGenerativeAILanguageModel } from './google-generative-ai-language-model';
27
27
  import type { GoogleLanguageModelOptions } from './google-generative-ai-options';
28
+ import { googleSearchToolArgsBaseSchema } from './tool/google-search';
28
29
 
29
30
  interface GoogleGenerativeAIImageModelConfig {
30
31
  provider: string;
@@ -139,7 +140,17 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
139
140
  }
140
141
 
141
142
  if (googleOptions) {
142
- Object.assign(parameters, googleOptions);
143
+ const { googleSearch: imagenGoogleSearch, ...imagenOptions } =
144
+ googleOptions;
145
+ if (imagenGoogleSearch != null) {
146
+ warnings.push({
147
+ type: 'unsupported',
148
+ feature: 'googleSearch',
149
+ details:
150
+ 'Google Search grounding is only supported on Gemini image models.',
151
+ });
152
+ }
153
+ Object.assign(parameters, imagenOptions);
143
154
  }
144
155
 
145
156
  const body = {
@@ -257,6 +268,18 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
257
268
  { role: 'user', content: userContent },
258
269
  ];
259
270
 
271
+ // Parse image-model-specific provider options so we can map them onto
272
+ // the underlying language-model call. `googleSearch` is the dedicated
273
+ // escape hatch for grounding (generateImage has no `tools` parameter).
274
+ const googleImageOptions = await parseProviderOptions({
275
+ provider: 'google',
276
+ providerOptions,
277
+ schema: googleImageModelOptionsSchema,
278
+ });
279
+
280
+ const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } =
281
+ providerOptions?.google ?? {};
282
+
260
283
  // Instantiate language model
261
284
  const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
262
285
  provider: this.config.provider,
@@ -280,12 +303,23 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
280
303
  >['aspectRatio'],
281
304
  }
282
305
  : undefined,
283
- ...((providerOptions?.google as Omit<
306
+ ...(passthroughGoogleOptions as Omit<
284
307
  GoogleLanguageModelOptions,
285
308
  'responseModalities' | 'imageConfig'
286
- >) ?? {}),
309
+ >),
287
310
  } satisfies GoogleLanguageModelOptions,
288
311
  },
312
+ tools:
313
+ googleImageOptions?.googleSearch != null
314
+ ? [
315
+ {
316
+ type: 'provider',
317
+ id: 'google.google_search',
318
+ name: 'google_search',
319
+ args: googleImageOptions.googleSearch,
320
+ },
321
+ ]
322
+ : undefined,
289
323
  headers,
290
324
  abortSignal,
291
325
  });
@@ -300,11 +334,17 @@ export class GoogleGenerativeAIImageModel implements ImageModelV3 {
300
334
  }
301
335
  }
302
336
 
337
+ const languageModelGoogleMetadata =
338
+ (result.providerMetadata?.google as
339
+ | Record<string, unknown>
340
+ | undefined) ?? {};
341
+
303
342
  return {
304
343
  images,
305
344
  warnings,
306
345
  providerMetadata: {
307
346
  google: {
347
+ ...languageModelGoogleMetadata,
308
348
  images: images.map(() => ({})),
309
349
  },
310
350
  },
@@ -350,6 +390,17 @@ const googleImageModelOptionsSchema = lazySchema(() =>
350
390
  .enum(['dont_allow', 'allow_adult', 'allow_all'])
351
391
  .nullish(),
352
392
  aspectRatio: z.enum(['1:1', '3:4', '4:3', '9:16', '16:9']).nullish(),
393
+
394
+ /**
395
+ * Enable Google Search grounding for Gemini image models. The value is
396
+ * forwarded as the args of the `google.tools.googleSearch` provider
397
+ * tool on the underlying language-model call. Pass `{}` for defaults.
398
+ *
399
+ * `generateImage` does not accept a `tools` parameter, so this is the
400
+ * dedicated escape hatch for grounding image generation the same way
401
+ * `generateText` does.
402
+ */
403
+ googleSearch: googleSearchToolArgsBaseSchema.optional(),
353
404
  }),
354
405
  ),
355
406
  );
@@ -498,7 +498,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
498
498
  safetyRatings: candidate.safetyRatings ?? null,
499
499
  usageMetadata: usageMetadata ?? null,
500
500
  finishMessage: candidate.finishMessage ?? null,
501
- serviceTier: responseHeaders?.['x-gemini-service-tier'] ?? null,
501
+ serviceTier: usageMetadata?.serviceTier ?? null,
502
502
  } satisfies GoogleGenerativeAIProviderMetadata,
503
503
  },
504
504
  request: { body: args },
@@ -542,8 +542,6 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
542
542
  let providerMetadata: SharedV3ProviderMetadata | undefined = undefined;
543
543
  let lastGroundingMetadata: GroundingMetadataSchema | null = null;
544
544
  let lastUrlContextMetadata: UrlContextMetadataSchema | null = null;
545
- const serviceTier: string | null =
546
- responseHeaders?.['x-gemini-service-tier'] ?? null;
547
545
 
548
546
  const generateId = this.config.generateId;
549
547
  let hasToolCalls = false;
@@ -1043,7 +1041,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
1043
1041
  safetyRatings: candidate.safetyRatings ?? null,
1044
1042
  usageMetadata: usageMetadata ?? null,
1045
1043
  finishMessage: candidate.finishMessage ?? null,
1046
- serviceTier,
1044
+ serviceTier: usage?.serviceTier ?? null,
1047
1045
  } satisfies GoogleGenerativeAIProviderMetadata,
1048
1046
  };
1049
1047
  }
@@ -1389,6 +1387,7 @@ const usageSchema = z.object({
1389
1387
  totalTokenCount: z.number().nullish(),
1390
1388
  // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1391
1389
  trafficType: z.string().nullish(),
1390
+ serviceTier: z.string().nullish(),
1392
1391
  // https://ai.google.dev/api/generate-content#Modality
1393
1392
  promptTokensDetails: tokenDetailsSchema,
1394
1393
  candidatesTokensDetails: tokenDetailsSchema,
@@ -9,7 +9,7 @@ import { z } from 'zod/v4';
9
9
  // https://ai.google.dev/api/generate-content#GroundingSupport
10
10
  // https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-search
11
11
 
12
- const googleSearchToolArgsBaseSchema = z
12
+ export const googleSearchToolArgsBaseSchema = z
13
13
  .object({
14
14
  searchTypes: z
15
15
  .object({