@ai-sdk/google 4.0.0-canary.69 → 4.0.0-canary.71
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.ts +3 -1
- package/dist/index.js +57 -30
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +56 -29
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +12 -5
- package/package.json +1 -1
- package/src/convert-google-usage.ts +1 -0
- package/src/google-language-model-options.ts +23 -8
- package/src/google-language-model.ts +45 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.0-canary.71
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 045d2e8: fix(google): read `serviceTier` from `usageMetadata.serviceTier` in both generate and stream paths
|
|
8
|
+
|
|
9
|
+
The previous implementation read `serviceTier` from the `x-gemini-service-tier`
|
|
10
|
+
response header, which is only populated on non-streaming responses. Gemini
|
|
11
|
+
streaming includes the value in `usageMetadata.serviceTier` on every chunk, so
|
|
12
|
+
`providerMetadata.google.serviceTier` was always `null` for streams. Read from
|
|
13
|
+
`usageMetadata` for both paths instead.
|
|
14
|
+
|
|
15
|
+
## 4.0.0-canary.70
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- aeea161: feat(google): read `serviceTier` from `x-gemini-service-tier` response header in Gemini API and use PayGo for Vertex
|
|
20
|
+
|
|
3
21
|
## 4.0.0-canary.69
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
41
41
|
} | undefined;
|
|
42
42
|
streamFunctionCallArguments?: boolean | undefined;
|
|
43
43
|
serviceTier?: "standard" | "flex" | "priority" | undefined;
|
|
44
|
+
sharedRequestType?: "standard" | "flex" | "priority" | undefined;
|
|
45
|
+
requestType?: "shared" | undefined;
|
|
44
46
|
}>;
|
|
45
47
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
46
48
|
|
|
@@ -169,6 +171,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
169
171
|
candidatesTokenCount?: number | null | undefined;
|
|
170
172
|
totalTokenCount?: number | null | undefined;
|
|
171
173
|
trafficType?: string | null | undefined;
|
|
174
|
+
serviceTier?: string | null | undefined;
|
|
172
175
|
promptTokensDetails?: {
|
|
173
176
|
modality: string;
|
|
174
177
|
tokenCount: number;
|
|
@@ -189,7 +192,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
189
192
|
blocked?: boolean | null | undefined;
|
|
190
193
|
}[] | null | undefined;
|
|
191
194
|
} | null | undefined;
|
|
192
|
-
serviceTier?: string | null | undefined;
|
|
193
195
|
}>;
|
|
194
196
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
195
197
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
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.
|
|
10
|
+
var VERSION = true ? "4.0.0-canary.71" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -989,17 +989,32 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
989
989
|
*/
|
|
990
990
|
streamFunctionCallArguments: z4.boolean().optional(),
|
|
991
991
|
/**
|
|
992
|
-
* Optional. The service tier to use for the request.
|
|
992
|
+
* Optional. The service tier to use for the request. Sent as the
|
|
993
|
+
* `serviceTier` body field. Gemini API only.
|
|
993
994
|
*/
|
|
994
|
-
serviceTier: z4.enum(["standard", "flex", "priority"]).optional()
|
|
995
|
+
serviceTier: z4.enum(["standard", "flex", "priority"]).optional(),
|
|
996
|
+
/**
|
|
997
|
+
* Optional. Vertex AI only. Sent as the
|
|
998
|
+
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
999
|
+
* shared (PayGo) tier. With Provisioned Throughput allocated and
|
|
1000
|
+
* `requestType` unset, the request falls back to this tier only if
|
|
1001
|
+
* PT capacity is exhausted.
|
|
1002
|
+
*
|
|
1003
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1004
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
|
|
1005
|
+
*/
|
|
1006
|
+
sharedRequestType: z4.enum(["priority", "flex", "standard"]).optional(),
|
|
1007
|
+
/**
|
|
1008
|
+
* Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
|
|
1009
|
+
* request header. Set to `'shared'` together with `sharedRequestType`
|
|
1010
|
+
* to bypass Provisioned Throughput entirely.
|
|
1011
|
+
*
|
|
1012
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1013
|
+
*/
|
|
1014
|
+
requestType: z4.enum(["shared"]).optional()
|
|
995
1015
|
})
|
|
996
1016
|
)
|
|
997
1017
|
);
|
|
998
|
-
var VertexServiceTierMap = {
|
|
999
|
-
standard: "SERVICE_TIER_STANDARD",
|
|
1000
|
-
flex: "SERVICE_TIER_FLEX",
|
|
1001
|
-
priority: "SERVICE_TIER_PRIORITY"
|
|
1002
|
-
};
|
|
1003
1018
|
|
|
1004
1019
|
// src/google-prepare-tools.ts
|
|
1005
1020
|
import {
|
|
@@ -1580,10 +1595,27 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1580
1595
|
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
1581
1596
|
});
|
|
1582
1597
|
}
|
|
1583
|
-
let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1584
1598
|
if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
|
|
1585
|
-
|
|
1599
|
+
warnings.push({
|
|
1600
|
+
type: "other",
|
|
1601
|
+
message: "'serviceTier' is a Gemini API option and is not supported on Vertex AI. Use 'sharedRequestType' (and optionally 'requestType') instead. See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo"
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
|
|
1605
|
+
warnings.push({
|
|
1606
|
+
type: "other",
|
|
1607
|
+
message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
|
|
1608
|
+
});
|
|
1586
1609
|
}
|
|
1610
|
+
const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
|
|
1611
|
+
...googleOptions.sharedRequestType && {
|
|
1612
|
+
"X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
|
|
1613
|
+
},
|
|
1614
|
+
...googleOptions.requestType && {
|
|
1615
|
+
"X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
|
|
1616
|
+
}
|
|
1617
|
+
} : void 0;
|
|
1618
|
+
const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1587
1619
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1588
1620
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1589
1621
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
@@ -1658,21 +1690,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1658
1690
|
toolConfig,
|
|
1659
1691
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1660
1692
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1661
|
-
serviceTier:
|
|
1693
|
+
serviceTier: bodyServiceTier
|
|
1662
1694
|
},
|
|
1663
1695
|
warnings: [...warnings, ...toolWarnings],
|
|
1664
|
-
providerOptionsNames
|
|
1696
|
+
providerOptionsNames,
|
|
1697
|
+
extraHeaders: vertexPaygoHeaders
|
|
1665
1698
|
};
|
|
1666
1699
|
}
|
|
1667
1700
|
async doGenerate(options) {
|
|
1668
1701
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1669
|
-
const { args, warnings, providerOptionsNames } = await this.getArgs(options);
|
|
1702
|
+
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
|
|
1670
1703
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1671
1704
|
providerOptionsNames.map((name) => [name, payload])
|
|
1672
1705
|
);
|
|
1673
1706
|
const mergedHeaders = combineHeaders2(
|
|
1674
1707
|
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1675
|
-
options.headers
|
|
1708
|
+
options.headers,
|
|
1709
|
+
extraHeaders
|
|
1676
1710
|
);
|
|
1677
1711
|
const {
|
|
1678
1712
|
responseHeaders,
|
|
@@ -1821,7 +1855,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1821
1855
|
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1822
1856
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1823
1857
|
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1824
|
-
serviceTier: (_r =
|
|
1858
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1825
1859
|
}),
|
|
1826
1860
|
request: { body: args },
|
|
1827
1861
|
response: {
|
|
@@ -1832,16 +1866,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1832
1866
|
};
|
|
1833
1867
|
}
|
|
1834
1868
|
async doStream(options) {
|
|
1835
|
-
const { args, warnings, providerOptionsNames } = await this.getArgs(
|
|
1836
|
-
options,
|
|
1837
|
-
{ isStreaming: true }
|
|
1838
|
-
);
|
|
1869
|
+
const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
1839
1870
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1840
1871
|
providerOptionsNames.map((name) => [name, payload])
|
|
1841
1872
|
);
|
|
1842
1873
|
const headers = combineHeaders2(
|
|
1843
1874
|
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
1844
|
-
options.headers
|
|
1875
|
+
options.headers,
|
|
1876
|
+
extraHeaders
|
|
1845
1877
|
);
|
|
1846
1878
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1847
1879
|
url: `${this.config.baseURL}/${getModelPath(
|
|
@@ -1862,7 +1894,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1862
1894
|
let providerMetadata = void 0;
|
|
1863
1895
|
let lastGroundingMetadata = null;
|
|
1864
1896
|
let lastUrlContextMetadata = null;
|
|
1865
|
-
let serviceTier = null;
|
|
1866
1897
|
const generateId3 = this.config.generateId;
|
|
1867
1898
|
let hasToolCalls = false;
|
|
1868
1899
|
let currentTextBlockId = null;
|
|
@@ -1907,7 +1938,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1907
1938
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1908
1939
|
},
|
|
1909
1940
|
transform(chunk, controller) {
|
|
1910
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1941
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1911
1942
|
if (options.includeRawChunks) {
|
|
1912
1943
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1913
1944
|
}
|
|
@@ -1920,9 +1951,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1920
1951
|
if (usageMetadata != null) {
|
|
1921
1952
|
usage = usageMetadata;
|
|
1922
1953
|
}
|
|
1923
|
-
if (value.serviceTier != null) {
|
|
1924
|
-
serviceTier = value.serviceTier;
|
|
1925
|
-
}
|
|
1926
1954
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1927
1955
|
if (candidate == null) {
|
|
1928
1956
|
return;
|
|
@@ -2218,7 +2246,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2218
2246
|
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
2219
2247
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2220
2248
|
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
2221
|
-
serviceTier
|
|
2249
|
+
serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
|
|
2222
2250
|
});
|
|
2223
2251
|
}
|
|
2224
2252
|
},
|
|
@@ -2545,6 +2573,7 @@ var usageSchema = z5.object({
|
|
|
2545
2573
|
totalTokenCount: z5.number().nullish(),
|
|
2546
2574
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2547
2575
|
trafficType: z5.string().nullish(),
|
|
2576
|
+
serviceTier: z5.string().nullish(),
|
|
2548
2577
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2549
2578
|
promptTokensDetails: tokenDetailsSchema,
|
|
2550
2579
|
candidatesTokensDetails: tokenDetailsSchema
|
|
@@ -2574,8 +2603,7 @@ var responseSchema = lazySchema5(
|
|
|
2574
2603
|
promptFeedback: z5.object({
|
|
2575
2604
|
blockReason: z5.string().nullish(),
|
|
2576
2605
|
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
2577
|
-
}).nullish()
|
|
2578
|
-
serviceTier: z5.string().nullish()
|
|
2606
|
+
}).nullish()
|
|
2579
2607
|
})
|
|
2580
2608
|
)
|
|
2581
2609
|
);
|
|
@@ -2596,8 +2624,7 @@ var chunkSchema = lazySchema5(
|
|
|
2596
2624
|
promptFeedback: z5.object({
|
|
2597
2625
|
blockReason: z5.string().nullish(),
|
|
2598
2626
|
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
2599
|
-
}).nullish()
|
|
2600
|
-
serviceTier: z5.string().nullish()
|
|
2627
|
+
}).nullish()
|
|
2601
2628
|
})
|
|
2602
2629
|
)
|
|
2603
2630
|
);
|