@ai-sdk/google 4.0.0-canary.71 → 4.0.0-canary.72

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0-canary.72
4
+
5
+ ### Patch Changes
6
+
7
+ - b71c0d7: feat(provider/google): support Google search grounding when using `generateImage` with Gemini
8
+
3
9
  ## 4.0.0-canary.71
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -217,6 +217,17 @@ interface GoogleProviderMetadata {
217
217
  declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
218
218
  personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
219
219
  aspectRatio?: "1:1" | "3:4" | "4:3" | "9:16" | "16:9" | null | undefined;
220
+ googleSearch?: {
221
+ [x: string]: unknown;
222
+ searchTypes?: {
223
+ webSearch?: Record<string, never> | undefined;
224
+ imageSearch?: Record<string, never> | undefined;
225
+ } | undefined;
226
+ timeRangeFilter?: {
227
+ startTime: string;
228
+ endTime: string;
229
+ } | undefined;
230
+ } | undefined;
220
231
  }>;
221
232
  type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
222
233
 
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.0-canary.71" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.0-canary.72" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -2835,7 +2835,17 @@ var googleImageModelOptionsSchema = lazySchema12(
2835
2835
  () => zodSchema12(
2836
2836
  z13.object({
2837
2837
  personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
2838
- aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
2838
+ aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish(),
2839
+ /**
2840
+ * Enable Google Search grounding for Gemini image models. The value is
2841
+ * forwarded as the args of the `google.tools.googleSearch` provider
2842
+ * tool on the underlying language-model call. Pass `{}` for defaults.
2843
+ *
2844
+ * `generateImage` does not accept a `tools` parameter, so this is the
2845
+ * dedicated escape hatch for grounding image generation the same way
2846
+ * `generateText` does.
2847
+ */
2848
+ googleSearch: googleSearchToolArgsBaseSchema.optional()
2839
2849
  })
2840
2850
  )
2841
2851
  );
@@ -2927,7 +2937,15 @@ var GoogleImageModel = class _GoogleImageModel {
2927
2937
  parameters.aspectRatio = aspectRatio;
2928
2938
  }
2929
2939
  if (googleOptions) {
2930
- Object.assign(parameters, googleOptions);
2940
+ const { googleSearch: imagenGoogleSearch, ...imagenOptions } = googleOptions;
2941
+ if (imagenGoogleSearch != null) {
2942
+ warnings.push({
2943
+ type: "unsupported",
2944
+ feature: "googleSearch",
2945
+ details: "Google Search grounding is only supported on Gemini image models."
2946
+ });
2947
+ }
2948
+ Object.assign(parameters, imagenOptions);
2931
2949
  }
2932
2950
  const body = {
2933
2951
  instances: [{ prompt }],
@@ -2967,7 +2985,7 @@ var GoogleImageModel = class _GoogleImageModel {
2967
2985
  };
2968
2986
  }
2969
2987
  async doGenerateGemini(options) {
2970
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2988
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2971
2989
  const {
2972
2990
  prompt,
2973
2991
  n,
@@ -3025,12 +3043,18 @@ var GoogleImageModel = class _GoogleImageModel {
3025
3043
  const languageModelPrompt = [
3026
3044
  { role: "user", content: userContent }
3027
3045
  ];
3046
+ const googleImageOptions = await parseProviderOptions3({
3047
+ provider: "google",
3048
+ providerOptions,
3049
+ schema: googleImageModelOptionsSchema
3050
+ });
3051
+ const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a = providerOptions == null ? void 0 : providerOptions.google) != null ? _a : {};
3028
3052
  const languageModel = new GoogleLanguageModel(this.modelId, {
3029
3053
  provider: this.config.provider,
3030
3054
  baseURL: this.config.baseURL,
3031
- headers: (_a = this.config.headers) != null ? _a : {},
3055
+ headers: (_b = this.config.headers) != null ? _b : {},
3032
3056
  fetch: this.config.fetch,
3033
- generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId
3057
+ generateId: (_c = this.config.generateId) != null ? _c : defaultGenerateId
3034
3058
  });
3035
3059
  const result = await languageModel.doGenerate({
3036
3060
  prompt: languageModelPrompt,
@@ -3041,9 +3065,17 @@ var GoogleImageModel = class _GoogleImageModel {
3041
3065
  imageConfig: aspectRatio ? {
3042
3066
  aspectRatio
3043
3067
  } : void 0,
3044
- ...(_c = providerOptions == null ? void 0 : providerOptions.google) != null ? _c : {}
3068
+ ...passthroughGoogleOptions
3045
3069
  }
3046
3070
  },
3071
+ tools: (googleImageOptions == null ? void 0 : googleImageOptions.googleSearch) != null ? [
3072
+ {
3073
+ type: "provider",
3074
+ id: "google.google_search",
3075
+ name: "google_search",
3076
+ args: googleImageOptions.googleSearch
3077
+ }
3078
+ ] : void 0,
3047
3079
  headers,
3048
3080
  abortSignal
3049
3081
  });
@@ -3054,23 +3086,25 @@ var GoogleImageModel = class _GoogleImageModel {
3054
3086
  images.push(convertToBase642(part.data.data));
3055
3087
  }
3056
3088
  }
3089
+ const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
3057
3090
  return {
3058
3091
  images,
3059
3092
  warnings,
3060
3093
  providerMetadata: {
3061
3094
  google: {
3095
+ ...languageModelGoogleMetadata,
3062
3096
  images: images.map(() => ({}))
3063
3097
  }
3064
3098
  },
3065
3099
  response: {
3066
3100
  timestamp: currentDate,
3067
3101
  modelId: this.modelId,
3068
- headers: (_g = result.response) == null ? void 0 : _g.headers
3102
+ headers: (_i = result.response) == null ? void 0 : _i.headers
3069
3103
  },
3070
3104
  usage: result.usage ? {
3071
3105
  inputTokens: result.usage.inputTokens.total,
3072
3106
  outputTokens: result.usage.outputTokens.total,
3073
- totalTokens: ((_h = result.usage.inputTokens.total) != null ? _h : 0) + ((_i = result.usage.outputTokens.total) != null ? _i : 0)
3107
+ totalTokens: ((_j = result.usage.inputTokens.total) != null ? _j : 0) + ((_k = result.usage.outputTokens.total) != null ? _k : 0)
3074
3108
  } : void 0
3075
3109
  };
3076
3110
  }