@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/CHANGELOG.md +18 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +48 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +5 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +5 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-google-generative-ai-usage.ts +1 -0
- package/src/google-generative-ai-image-model.ts +55 -4
- package/src/google-generative-ai-language-model.ts +3 -4
- package/src/tool/google-search.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.79
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cfa0cb2: feat(provider/google): support Google search grounding when using `generateImage` with Gemini
|
|
8
|
+
|
|
9
|
+
## 3.0.78
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cf63828: fix(google): read `serviceTier` from `usageMetadata.serviceTier` in both generate and stream paths
|
|
14
|
+
|
|
15
|
+
The previous implementation read `serviceTier` from the `x-gemini-service-tier`
|
|
16
|
+
response header, which is only populated on non-streaming responses. Gemini
|
|
17
|
+
streaming includes the value in `usageMetadata.serviceTier` on every chunk, so
|
|
18
|
+
`providerMetadata.google.serviceTier` was always `null` for streams. Read from
|
|
19
|
+
`usageMetadata` for both paths instead.
|
|
20
|
+
|
|
3
21
|
## 3.0.77
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -171,6 +171,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
171
|
candidatesTokenCount?: number | null | undefined;
|
|
172
172
|
totalTokenCount?: number | null | undefined;
|
|
173
173
|
trafficType?: string | null | undefined;
|
|
174
|
+
serviceTier?: string | null | undefined;
|
|
174
175
|
promptTokensDetails?: {
|
|
175
176
|
modality: string;
|
|
176
177
|
tokenCount: number;
|
|
@@ -224,6 +225,17 @@ interface GoogleGenerativeAIImageSettings {
|
|
|
224
225
|
declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
225
226
|
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
|
226
227
|
aspectRatio?: "1:1" | "3:4" | "4:3" | "9:16" | "16:9" | null | undefined;
|
|
228
|
+
googleSearch?: {
|
|
229
|
+
[x: string]: unknown;
|
|
230
|
+
searchTypes?: {
|
|
231
|
+
webSearch?: Record<string, never> | undefined;
|
|
232
|
+
imageSearch?: Record<string, never> | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
timeRangeFilter?: {
|
|
235
|
+
startTime: string;
|
|
236
|
+
endTime: string;
|
|
237
|
+
} | undefined;
|
|
238
|
+
} | undefined;
|
|
227
239
|
}>;
|
|
228
240
|
type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
|
|
229
241
|
|
package/dist/index.d.ts
CHANGED
|
@@ -171,6 +171,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
171
|
candidatesTokenCount?: number | null | undefined;
|
|
172
172
|
totalTokenCount?: number | null | undefined;
|
|
173
173
|
trafficType?: string | null | undefined;
|
|
174
|
+
serviceTier?: string | null | undefined;
|
|
174
175
|
promptTokensDetails?: {
|
|
175
176
|
modality: string;
|
|
176
177
|
tokenCount: number;
|
|
@@ -224,6 +225,17 @@ interface GoogleGenerativeAIImageSettings {
|
|
|
224
225
|
declare const googleImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
225
226
|
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
|
226
227
|
aspectRatio?: "1:1" | "3:4" | "4:3" | "9:16" | "16:9" | null | undefined;
|
|
228
|
+
googleSearch?: {
|
|
229
|
+
[x: string]: unknown;
|
|
230
|
+
searchTypes?: {
|
|
231
|
+
webSearch?: Record<string, never> | undefined;
|
|
232
|
+
imageSearch?: Record<string, never> | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
timeRangeFilter?: {
|
|
235
|
+
startTime: string;
|
|
236
|
+
endTime: string;
|
|
237
|
+
} | undefined;
|
|
238
|
+
} | undefined;
|
|
227
239
|
}>;
|
|
228
240
|
type GoogleImageModelOptions = InferSchema<typeof googleImageModelOptionsSchema>;
|
|
229
241
|
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.79" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -1711,7 +1711,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1711
1711
|
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1712
1712
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1713
1713
|
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1714
|
-
serviceTier: (_r =
|
|
1714
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1715
1715
|
}
|
|
1716
1716
|
},
|
|
1717
1717
|
request: { body: args },
|
|
@@ -1723,7 +1723,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1723
1723
|
};
|
|
1724
1724
|
}
|
|
1725
1725
|
async doStream(options) {
|
|
1726
|
-
var _a;
|
|
1727
1726
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
1728
1727
|
const headers = (0, import_provider_utils6.combineHeaders)(
|
|
1729
1728
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1749,7 +1748,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1749
1748
|
let providerMetadata = void 0;
|
|
1750
1749
|
let lastGroundingMetadata = null;
|
|
1751
1750
|
let lastUrlContextMetadata = null;
|
|
1752
|
-
const serviceTier = (_a = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _a : null;
|
|
1753
1751
|
const generateId3 = this.config.generateId;
|
|
1754
1752
|
let hasToolCalls = false;
|
|
1755
1753
|
let currentTextBlockId = null;
|
|
@@ -1794,7 +1792,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1794
1792
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1795
1793
|
},
|
|
1796
1794
|
transform(chunk, controller) {
|
|
1797
|
-
var
|
|
1795
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1798
1796
|
if (options.includeRawChunks) {
|
|
1799
1797
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1800
1798
|
}
|
|
@@ -1807,7 +1805,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1807
1805
|
if (usageMetadata != null) {
|
|
1808
1806
|
usage = usageMetadata;
|
|
1809
1807
|
}
|
|
1810
|
-
const candidate = (
|
|
1808
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1811
1809
|
if (candidate == null) {
|
|
1812
1810
|
return;
|
|
1813
1811
|
}
|
|
@@ -2114,7 +2112,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2114
2112
|
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2115
2113
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2116
2114
|
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2117
|
-
serviceTier
|
|
2115
|
+
serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
|
|
2118
2116
|
}
|
|
2119
2117
|
};
|
|
2120
2118
|
}
|
|
@@ -2373,6 +2371,7 @@ var usageSchema = import_v45.z.object({
|
|
|
2373
2371
|
totalTokenCount: import_v45.z.number().nullish(),
|
|
2374
2372
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2375
2373
|
trafficType: import_v45.z.string().nullish(),
|
|
2374
|
+
serviceTier: import_v45.z.string().nullish(),
|
|
2376
2375
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2377
2376
|
promptTokensDetails: tokenDetailsSchema,
|
|
2378
2377
|
candidatesTokensDetails: tokenDetailsSchema
|
|
@@ -2668,7 +2667,15 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2668
2667
|
parameters.aspectRatio = aspectRatio;
|
|
2669
2668
|
}
|
|
2670
2669
|
if (googleOptions) {
|
|
2671
|
-
|
|
2670
|
+
const { googleSearch: imagenGoogleSearch, ...imagenOptions } = googleOptions;
|
|
2671
|
+
if (imagenGoogleSearch != null) {
|
|
2672
|
+
warnings.push({
|
|
2673
|
+
type: "unsupported",
|
|
2674
|
+
feature: "googleSearch",
|
|
2675
|
+
details: "Google Search grounding is only supported on Gemini image models."
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
Object.assign(parameters, imagenOptions);
|
|
2672
2679
|
}
|
|
2673
2680
|
const body = {
|
|
2674
2681
|
instances: [{ prompt }],
|
|
@@ -2705,7 +2712,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2705
2712
|
};
|
|
2706
2713
|
}
|
|
2707
2714
|
async doGenerateGemini(options) {
|
|
2708
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2715
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2709
2716
|
const {
|
|
2710
2717
|
prompt,
|
|
2711
2718
|
n,
|
|
@@ -2760,12 +2767,18 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2760
2767
|
const languageModelPrompt = [
|
|
2761
2768
|
{ role: "user", content: userContent }
|
|
2762
2769
|
];
|
|
2770
|
+
const googleImageOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
2771
|
+
provider: "google",
|
|
2772
|
+
providerOptions,
|
|
2773
|
+
schema: googleImageModelOptionsSchema
|
|
2774
|
+
});
|
|
2775
|
+
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a = providerOptions == null ? void 0 : providerOptions.google) != null ? _a : {};
|
|
2763
2776
|
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
2764
2777
|
provider: this.config.provider,
|
|
2765
2778
|
baseURL: this.config.baseURL,
|
|
2766
|
-
headers: (
|
|
2779
|
+
headers: (_b = this.config.headers) != null ? _b : {},
|
|
2767
2780
|
fetch: this.config.fetch,
|
|
2768
|
-
generateId: (
|
|
2781
|
+
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils14.generateId
|
|
2769
2782
|
});
|
|
2770
2783
|
const result = await languageModel.doGenerate({
|
|
2771
2784
|
prompt: languageModelPrompt,
|
|
@@ -2776,9 +2789,17 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2776
2789
|
imageConfig: aspectRatio ? {
|
|
2777
2790
|
aspectRatio
|
|
2778
2791
|
} : void 0,
|
|
2779
|
-
...
|
|
2792
|
+
...passthroughGoogleOptions
|
|
2780
2793
|
}
|
|
2781
2794
|
},
|
|
2795
|
+
tools: (googleImageOptions == null ? void 0 : googleImageOptions.googleSearch) != null ? [
|
|
2796
|
+
{
|
|
2797
|
+
type: "provider",
|
|
2798
|
+
id: "google.google_search",
|
|
2799
|
+
name: "google_search",
|
|
2800
|
+
args: googleImageOptions.googleSearch
|
|
2801
|
+
}
|
|
2802
|
+
] : void 0,
|
|
2782
2803
|
headers,
|
|
2783
2804
|
abortSignal
|
|
2784
2805
|
});
|
|
@@ -2789,23 +2810,25 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2789
2810
|
images.push((0, import_provider_utils14.convertToBase64)(part.data));
|
|
2790
2811
|
}
|
|
2791
2812
|
}
|
|
2813
|
+
const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
|
|
2792
2814
|
return {
|
|
2793
2815
|
images,
|
|
2794
2816
|
warnings,
|
|
2795
2817
|
providerMetadata: {
|
|
2796
2818
|
google: {
|
|
2819
|
+
...languageModelGoogleMetadata,
|
|
2797
2820
|
images: images.map(() => ({}))
|
|
2798
2821
|
}
|
|
2799
2822
|
},
|
|
2800
2823
|
response: {
|
|
2801
2824
|
timestamp: currentDate,
|
|
2802
2825
|
modelId: this.modelId,
|
|
2803
|
-
headers: (
|
|
2826
|
+
headers: (_i = result.response) == null ? void 0 : _i.headers
|
|
2804
2827
|
},
|
|
2805
2828
|
usage: result.usage ? {
|
|
2806
2829
|
inputTokens: result.usage.inputTokens.total,
|
|
2807
2830
|
outputTokens: result.usage.outputTokens.total,
|
|
2808
|
-
totalTokens: ((
|
|
2831
|
+
totalTokens: ((_j = result.usage.inputTokens.total) != null ? _j : 0) + ((_k = result.usage.outputTokens.total) != null ? _k : 0)
|
|
2809
2832
|
} : void 0
|
|
2810
2833
|
};
|
|
2811
2834
|
}
|
|
@@ -2824,7 +2847,17 @@ var googleImageModelOptionsSchema = (0, import_provider_utils14.lazySchema)(
|
|
|
2824
2847
|
() => (0, import_provider_utils14.zodSchema)(
|
|
2825
2848
|
import_v413.z.object({
|
|
2826
2849
|
personGeneration: import_v413.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2827
|
-
aspectRatio: import_v413.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
2850
|
+
aspectRatio: import_v413.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish(),
|
|
2851
|
+
/**
|
|
2852
|
+
* Enable Google Search grounding for Gemini image models. The value is
|
|
2853
|
+
* forwarded as the args of the `google.tools.googleSearch` provider
|
|
2854
|
+
* tool on the underlying language-model call. Pass `{}` for defaults.
|
|
2855
|
+
*
|
|
2856
|
+
* `generateImage` does not accept a `tools` parameter, so this is the
|
|
2857
|
+
* dedicated escape hatch for grounding image generation the same way
|
|
2858
|
+
* `generateText` does.
|
|
2859
|
+
*/
|
|
2860
|
+
googleSearch: googleSearchToolArgsBaseSchema.optional()
|
|
2828
2861
|
})
|
|
2829
2862
|
)
|
|
2830
2863
|
);
|