@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/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.79" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -1722,7 +1722,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1722
1722
|
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1723
1723
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1724
1724
|
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1725
|
-
serviceTier: (_r =
|
|
1725
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1726
1726
|
}
|
|
1727
1727
|
},
|
|
1728
1728
|
request: { body: args },
|
|
@@ -1734,7 +1734,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1734
1734
|
};
|
|
1735
1735
|
}
|
|
1736
1736
|
async doStream(options) {
|
|
1737
|
-
var _a;
|
|
1738
1737
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
1739
1738
|
const headers = combineHeaders2(
|
|
1740
1739
|
await resolve2(this.config.headers),
|
|
@@ -1760,7 +1759,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1760
1759
|
let providerMetadata = void 0;
|
|
1761
1760
|
let lastGroundingMetadata = null;
|
|
1762
1761
|
let lastUrlContextMetadata = null;
|
|
1763
|
-
const serviceTier = (_a = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _a : null;
|
|
1764
1762
|
const generateId3 = this.config.generateId;
|
|
1765
1763
|
let hasToolCalls = false;
|
|
1766
1764
|
let currentTextBlockId = null;
|
|
@@ -1805,7 +1803,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1805
1803
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1806
1804
|
},
|
|
1807
1805
|
transform(chunk, controller) {
|
|
1808
|
-
var
|
|
1806
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1809
1807
|
if (options.includeRawChunks) {
|
|
1810
1808
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1811
1809
|
}
|
|
@@ -1818,7 +1816,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1818
1816
|
if (usageMetadata != null) {
|
|
1819
1817
|
usage = usageMetadata;
|
|
1820
1818
|
}
|
|
1821
|
-
const candidate = (
|
|
1819
|
+
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1822
1820
|
if (candidate == null) {
|
|
1823
1821
|
return;
|
|
1824
1822
|
}
|
|
@@ -2125,7 +2123,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2125
2123
|
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2126
2124
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2127
2125
|
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2128
|
-
serviceTier
|
|
2126
|
+
serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
|
|
2129
2127
|
}
|
|
2130
2128
|
};
|
|
2131
2129
|
}
|
|
@@ -2384,6 +2382,7 @@ var usageSchema = z5.object({
|
|
|
2384
2382
|
totalTokenCount: z5.number().nullish(),
|
|
2385
2383
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2386
2384
|
trafficType: z5.string().nullish(),
|
|
2385
|
+
serviceTier: z5.string().nullish(),
|
|
2387
2386
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2388
2387
|
promptTokensDetails: tokenDetailsSchema,
|
|
2389
2388
|
candidatesTokensDetails: tokenDetailsSchema
|
|
@@ -2709,7 +2708,15 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2709
2708
|
parameters.aspectRatio = aspectRatio;
|
|
2710
2709
|
}
|
|
2711
2710
|
if (googleOptions) {
|
|
2712
|
-
|
|
2711
|
+
const { googleSearch: imagenGoogleSearch, ...imagenOptions } = googleOptions;
|
|
2712
|
+
if (imagenGoogleSearch != null) {
|
|
2713
|
+
warnings.push({
|
|
2714
|
+
type: "unsupported",
|
|
2715
|
+
feature: "googleSearch",
|
|
2716
|
+
details: "Google Search grounding is only supported on Gemini image models."
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
Object.assign(parameters, imagenOptions);
|
|
2713
2720
|
}
|
|
2714
2721
|
const body = {
|
|
2715
2722
|
instances: [{ prompt }],
|
|
@@ -2746,7 +2753,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2746
2753
|
};
|
|
2747
2754
|
}
|
|
2748
2755
|
async doGenerateGemini(options) {
|
|
2749
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2756
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2750
2757
|
const {
|
|
2751
2758
|
prompt,
|
|
2752
2759
|
n,
|
|
@@ -2801,12 +2808,18 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2801
2808
|
const languageModelPrompt = [
|
|
2802
2809
|
{ role: "user", content: userContent }
|
|
2803
2810
|
];
|
|
2811
|
+
const googleImageOptions = await parseProviderOptions3({
|
|
2812
|
+
provider: "google",
|
|
2813
|
+
providerOptions,
|
|
2814
|
+
schema: googleImageModelOptionsSchema
|
|
2815
|
+
});
|
|
2816
|
+
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a = providerOptions == null ? void 0 : providerOptions.google) != null ? _a : {};
|
|
2804
2817
|
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
2805
2818
|
provider: this.config.provider,
|
|
2806
2819
|
baseURL: this.config.baseURL,
|
|
2807
|
-
headers: (
|
|
2820
|
+
headers: (_b = this.config.headers) != null ? _b : {},
|
|
2808
2821
|
fetch: this.config.fetch,
|
|
2809
|
-
generateId: (
|
|
2822
|
+
generateId: (_c = this.config.generateId) != null ? _c : defaultGenerateId
|
|
2810
2823
|
});
|
|
2811
2824
|
const result = await languageModel.doGenerate({
|
|
2812
2825
|
prompt: languageModelPrompt,
|
|
@@ -2817,9 +2830,17 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2817
2830
|
imageConfig: aspectRatio ? {
|
|
2818
2831
|
aspectRatio
|
|
2819
2832
|
} : void 0,
|
|
2820
|
-
...
|
|
2833
|
+
...passthroughGoogleOptions
|
|
2821
2834
|
}
|
|
2822
2835
|
},
|
|
2836
|
+
tools: (googleImageOptions == null ? void 0 : googleImageOptions.googleSearch) != null ? [
|
|
2837
|
+
{
|
|
2838
|
+
type: "provider",
|
|
2839
|
+
id: "google.google_search",
|
|
2840
|
+
name: "google_search",
|
|
2841
|
+
args: googleImageOptions.googleSearch
|
|
2842
|
+
}
|
|
2843
|
+
] : void 0,
|
|
2823
2844
|
headers,
|
|
2824
2845
|
abortSignal
|
|
2825
2846
|
});
|
|
@@ -2830,23 +2851,25 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
2830
2851
|
images.push(convertToBase642(part.data));
|
|
2831
2852
|
}
|
|
2832
2853
|
}
|
|
2854
|
+
const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
|
|
2833
2855
|
return {
|
|
2834
2856
|
images,
|
|
2835
2857
|
warnings,
|
|
2836
2858
|
providerMetadata: {
|
|
2837
2859
|
google: {
|
|
2860
|
+
...languageModelGoogleMetadata,
|
|
2838
2861
|
images: images.map(() => ({}))
|
|
2839
2862
|
}
|
|
2840
2863
|
},
|
|
2841
2864
|
response: {
|
|
2842
2865
|
timestamp: currentDate,
|
|
2843
2866
|
modelId: this.modelId,
|
|
2844
|
-
headers: (
|
|
2867
|
+
headers: (_i = result.response) == null ? void 0 : _i.headers
|
|
2845
2868
|
},
|
|
2846
2869
|
usage: result.usage ? {
|
|
2847
2870
|
inputTokens: result.usage.inputTokens.total,
|
|
2848
2871
|
outputTokens: result.usage.outputTokens.total,
|
|
2849
|
-
totalTokens: ((
|
|
2872
|
+
totalTokens: ((_j = result.usage.inputTokens.total) != null ? _j : 0) + ((_k = result.usage.outputTokens.total) != null ? _k : 0)
|
|
2850
2873
|
} : void 0
|
|
2851
2874
|
};
|
|
2852
2875
|
}
|
|
@@ -2865,7 +2888,17 @@ var googleImageModelOptionsSchema = lazySchema11(
|
|
|
2865
2888
|
() => zodSchema11(
|
|
2866
2889
|
z13.object({
|
|
2867
2890
|
personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
2868
|
-
aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
|
2891
|
+
aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish(),
|
|
2892
|
+
/**
|
|
2893
|
+
* Enable Google Search grounding for Gemini image models. The value is
|
|
2894
|
+
* forwarded as the args of the `google.tools.googleSearch` provider
|
|
2895
|
+
* tool on the underlying language-model call. Pass `{}` for defaults.
|
|
2896
|
+
*
|
|
2897
|
+
* `generateImage` does not accept a `tools` parameter, so this is the
|
|
2898
|
+
* dedicated escape hatch for grounding image generation the same way
|
|
2899
|
+
* `generateText` does.
|
|
2900
|
+
*/
|
|
2901
|
+
googleSearch: googleSearchToolArgsBaseSchema.optional()
|
|
2869
2902
|
})
|
|
2870
2903
|
)
|
|
2871
2904
|
);
|