@ai-sdk/google 3.0.78 → 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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-image-model.ts +55 -4
- package/src/tool/google-search.ts +1 -1
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
...(
|
|
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
|
);
|
|
@@ -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({
|