@ai-sdk/google 2.0.103 → 2.0.105
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 +15 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +64 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -36
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +61 -33
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +61 -33
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 2.0.105
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 36a19fd: Defer validation schema construction until first use to reduce provider import time.
|
|
8
|
+
- Updated dependencies [d7b0ffa]
|
|
9
|
+
- Updated dependencies [4146790]
|
|
10
|
+
- @ai-sdk/provider-utils@3.0.42
|
|
11
|
+
|
|
12
|
+
## 2.0.104
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 1275533: Preserve grounding metadata from each automatically continued Google response in `groundingMetadataPerRequest`. Previously, a later response without grounding could leave earlier Search queries absent from the final provider metadata even though their sources were returned. The new array preserves request order and includes `null` for requests without grounding.
|
|
17
|
+
|
|
3
18
|
## 2.0.103
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -183,6 +183,8 @@ type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
|
183
183
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
184
184
|
interface GoogleGenerativeAIProviderMetadata {
|
|
185
185
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
186
|
+
/** Grounding from each automatically continued request, in request order. */
|
|
187
|
+
groundingMetadataPerRequest?: Array<GoogleGenerativeAIGroundingMetadata | null>;
|
|
186
188
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
187
189
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
188
190
|
serviceTier: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,8 @@ type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
|
183
183
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
184
184
|
interface GoogleGenerativeAIProviderMetadata {
|
|
185
185
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
186
|
+
/** Grounding from each automatically continued request, in request order. */
|
|
187
|
+
groundingMetadataPerRequest?: Array<GoogleGenerativeAIGroundingMetadata | null>;
|
|
186
188
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
187
189
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
188
190
|
serviceTier: string | null;
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.105" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -60,7 +60,7 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
|
60
60
|
// src/google-generative-ai-embedding-options.ts
|
|
61
61
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
62
62
|
var import_v42 = require("zod/v4");
|
|
63
|
-
var googleEmbeddingContentPartSchema = import_v42.z.union([
|
|
63
|
+
var googleEmbeddingContentPartSchema = () => import_v42.z.union([
|
|
64
64
|
import_v42.z.object({ text: import_v42.z.string() }),
|
|
65
65
|
import_v42.z.object({
|
|
66
66
|
inlineData: import_v42.z.object({
|
|
@@ -108,7 +108,7 @@ var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazy
|
|
|
108
108
|
* The array length must match the number of values being embedded. In
|
|
109
109
|
* the case of a single embedding, the array length must be 1.
|
|
110
110
|
*/
|
|
111
|
-
content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
111
|
+
content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema()).min(1).nullable()).optional()
|
|
112
112
|
})
|
|
113
113
|
)
|
|
114
114
|
);
|
|
@@ -1484,7 +1484,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1484
1484
|
};
|
|
1485
1485
|
}
|
|
1486
1486
|
async doGenerate(options) {
|
|
1487
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1487
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
1488
1488
|
const { args, warnings } = await this.getArgs(options);
|
|
1489
1489
|
const body = JSON.stringify(args);
|
|
1490
1490
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
@@ -1508,18 +1508,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1508
1508
|
rawValue: rawResponse
|
|
1509
1509
|
} = await generateContent(args);
|
|
1510
1510
|
const continuedParts = [];
|
|
1511
|
+
const groundingMetadataPerRequest = [];
|
|
1511
1512
|
let continuedUsageMetadata;
|
|
1512
1513
|
const firstPromptTokenCount = (_a = response.usageMetadata) == null ? void 0 : _a.promptTokenCount;
|
|
1513
1514
|
while (true) {
|
|
1514
1515
|
const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
|
|
1516
|
+
groundingMetadataPerRequest.push((_c = candidate2 == null ? void 0 : candidate2.groundingMetadata) != null ? _c : null);
|
|
1515
1517
|
const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
|
|
1516
1518
|
if (continuationToken == null) {
|
|
1517
1519
|
break;
|
|
1518
1520
|
}
|
|
1519
|
-
continuedParts.push(...(
|
|
1521
|
+
continuedParts.push(...(_e = (_d = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _d.parts) != null ? _e : []);
|
|
1520
1522
|
continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1521
1523
|
continuedUsageMetadata,
|
|
1522
|
-
(
|
|
1524
|
+
(_f = response.usageMetadata) != null ? _f : void 0
|
|
1523
1525
|
);
|
|
1524
1526
|
({
|
|
1525
1527
|
responseHeaders,
|
|
@@ -1527,18 +1529,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1527
1529
|
rawValue: rawResponse
|
|
1528
1530
|
} = await generateContent({ ...args, continuationToken }));
|
|
1529
1531
|
}
|
|
1530
|
-
const candidate = (
|
|
1531
|
-
const promptBlockReason = (
|
|
1532
|
+
const candidate = (_g = response.candidates) == null ? void 0 : _g[0];
|
|
1533
|
+
const promptBlockReason = (_h = response.promptFeedback) == null ? void 0 : _h.blockReason;
|
|
1532
1534
|
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1533
1535
|
const content = [];
|
|
1534
|
-
const parts = [...continuedParts, ...(
|
|
1536
|
+
const parts = [...continuedParts, ...(_j = (_i = candidate == null ? void 0 : candidate.content) == null ? void 0 : _i.parts) != null ? _j : []];
|
|
1535
1537
|
const usageMetadata = addGoogleGenerativeAIUsageMetadata(
|
|
1536
1538
|
continuedUsageMetadata,
|
|
1537
|
-
(
|
|
1539
|
+
(_k = response.usageMetadata) != null ? _k : void 0
|
|
1538
1540
|
);
|
|
1539
1541
|
let lastCodeExecutionToolCallId;
|
|
1540
1542
|
for (const part of parts) {
|
|
1541
|
-
if ("executableCode" in part && ((
|
|
1543
|
+
if ("executableCode" in part && ((_l = part.executableCode) == null ? void 0 : _l.code)) {
|
|
1542
1544
|
const toolCallId = this.config.generateId();
|
|
1543
1545
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1544
1546
|
content.push({
|
|
@@ -1579,7 +1581,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1579
1581
|
} else if ("functionCall" in part) {
|
|
1580
1582
|
content.push({
|
|
1581
1583
|
type: "tool-call",
|
|
1582
|
-
toolCallId: (
|
|
1584
|
+
toolCallId: (_m = part.functionCall.id) != null ? _m : this.config.generateId(),
|
|
1583
1585
|
toolName: part.functionCall.name,
|
|
1584
1586
|
input: JSON.stringify(part.functionCall.args),
|
|
1585
1587
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -1592,10 +1594,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1592
1594
|
});
|
|
1593
1595
|
}
|
|
1594
1596
|
}
|
|
1595
|
-
const sources = (
|
|
1597
|
+
const sources = (_n = extractSources({
|
|
1596
1598
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1597
1599
|
generateId: this.config.generateId
|
|
1598
|
-
})) != null ?
|
|
1600
|
+
})) != null ? _n : [];
|
|
1599
1601
|
for (const source of sources) {
|
|
1600
1602
|
content.push(source);
|
|
1601
1603
|
}
|
|
@@ -1606,21 +1608,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1606
1608
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
1607
1609
|
}),
|
|
1608
1610
|
usage: {
|
|
1609
|
-
inputTokens: (
|
|
1610
|
-
outputTokens: (
|
|
1611
|
-
totalTokens: (
|
|
1612
|
-
reasoningTokens: (
|
|
1613
|
-
cachedInputTokens: (
|
|
1611
|
+
inputTokens: (_o = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _o : void 0,
|
|
1612
|
+
outputTokens: (_p = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _p : void 0,
|
|
1613
|
+
totalTokens: (_q = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _q : void 0,
|
|
1614
|
+
reasoningTokens: (_r = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _r : void 0,
|
|
1615
|
+
cachedInputTokens: (_s = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _s : void 0
|
|
1614
1616
|
},
|
|
1615
1617
|
warnings,
|
|
1616
1618
|
providerMetadata: {
|
|
1617
1619
|
google: {
|
|
1618
|
-
promptFeedback: (
|
|
1619
|
-
groundingMetadata: (
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1620
|
+
promptFeedback: (_t = response.promptFeedback) != null ? _t : null,
|
|
1621
|
+
groundingMetadata: (_u = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _u : null,
|
|
1622
|
+
...groundingMetadataPerRequest.length > 1 ? { groundingMetadataPerRequest } : {},
|
|
1623
|
+
urlContextMetadata: (_v = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _v : null,
|
|
1624
|
+
safetyRatings: (_w = candidate == null ? void 0 : candidate.safetyRatings) != null ? _w : null,
|
|
1625
|
+
serviceTier: (_x = response.serviceTier) != null ? _x : null,
|
|
1626
|
+
...(candidate == null ? void 0 : candidate.continuationToken) != null && candidate.finishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
|
|
1624
1627
|
...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {},
|
|
1625
1628
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1626
1629
|
}
|
|
@@ -1652,14 +1655,27 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1652
1655
|
fetch: this.config.fetch
|
|
1653
1656
|
});
|
|
1654
1657
|
const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
|
|
1658
|
+
const groundingMetadataPerRequest = [];
|
|
1659
|
+
let requestGroundingMetadata = null;
|
|
1655
1660
|
const response = continueGoogleStream({
|
|
1656
1661
|
stream: firstResponse,
|
|
1657
1662
|
getContinuationToken: (chunk) => {
|
|
1658
1663
|
var _a, _b;
|
|
1659
1664
|
const candidate = (_a = chunk.candidates) == null ? void 0 : _a[0];
|
|
1665
|
+
if ((candidate == null ? void 0 : candidate.groundingMetadata) != null) {
|
|
1666
|
+
requestGroundingMetadata = candidate.groundingMetadata;
|
|
1667
|
+
}
|
|
1660
1668
|
return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
|
|
1661
1669
|
},
|
|
1662
|
-
continueStream: async (continuationToken) =>
|
|
1670
|
+
continueStream: async (continuationToken) => {
|
|
1671
|
+
const { value } = await streamGenerateContent({
|
|
1672
|
+
...args,
|
|
1673
|
+
continuationToken
|
|
1674
|
+
});
|
|
1675
|
+
groundingMetadataPerRequest.push(requestGroundingMetadata);
|
|
1676
|
+
requestGroundingMetadata = null;
|
|
1677
|
+
return value;
|
|
1678
|
+
}
|
|
1663
1679
|
});
|
|
1664
1680
|
let finishReason = "unknown";
|
|
1665
1681
|
const usage = {
|
|
@@ -1937,6 +1953,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1937
1953
|
id: currentReasoningBlockId
|
|
1938
1954
|
});
|
|
1939
1955
|
}
|
|
1956
|
+
if (groundingMetadataPerRequest.length > 0) {
|
|
1957
|
+
providerMetadata = {
|
|
1958
|
+
...providerMetadata,
|
|
1959
|
+
google: {
|
|
1960
|
+
...providerMetadata == null ? void 0 : providerMetadata.google,
|
|
1961
|
+
groundingMetadataPerRequest: [
|
|
1962
|
+
...groundingMetadataPerRequest,
|
|
1963
|
+
requestGroundingMetadata
|
|
1964
|
+
]
|
|
1965
|
+
}
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1940
1968
|
controller.enqueue({
|
|
1941
1969
|
type: "finish",
|
|
1942
1970
|
finishReason,
|
|
@@ -2154,13 +2182,13 @@ var getSafetyRatingSchema = () => import_v45.z.object({
|
|
|
2154
2182
|
severityScore: import_v45.z.number().nullish(),
|
|
2155
2183
|
blocked: import_v45.z.boolean().nullish()
|
|
2156
2184
|
});
|
|
2157
|
-
var tokenDetailsSchema = import_v45.z.array(
|
|
2185
|
+
var tokenDetailsSchema = () => import_v45.z.array(
|
|
2158
2186
|
import_v45.z.object({
|
|
2159
2187
|
modality: import_v45.z.string(),
|
|
2160
2188
|
tokenCount: import_v45.z.number()
|
|
2161
2189
|
})
|
|
2162
2190
|
).nullish();
|
|
2163
|
-
var usageSchema = import_v45.z.object({
|
|
2191
|
+
var usageSchema = () => import_v45.z.object({
|
|
2164
2192
|
cachedContentTokenCount: import_v45.z.number().nullish(),
|
|
2165
2193
|
thoughtsTokenCount: import_v45.z.number().nullish(),
|
|
2166
2194
|
promptTokenCount: import_v45.z.number().nullish(),
|
|
@@ -2169,8 +2197,8 @@ var usageSchema = import_v45.z.object({
|
|
|
2169
2197
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2170
2198
|
trafficType: import_v45.z.string().nullish(),
|
|
2171
2199
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2172
|
-
promptTokensDetails: tokenDetailsSchema,
|
|
2173
|
-
candidatesTokensDetails: tokenDetailsSchema
|
|
2200
|
+
promptTokensDetails: tokenDetailsSchema(),
|
|
2201
|
+
candidatesTokensDetails: tokenDetailsSchema()
|
|
2174
2202
|
});
|
|
2175
2203
|
var getUrlContextMetadataSchema = () => import_v45.z.object({
|
|
2176
2204
|
urlMetadata: import_v45.z.array(
|
|
@@ -2193,7 +2221,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
2193
2221
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2194
2222
|
})
|
|
2195
2223
|
).nullish(),
|
|
2196
|
-
usageMetadata: usageSchema.nullish(),
|
|
2224
|
+
usageMetadata: usageSchema().nullish(),
|
|
2197
2225
|
promptFeedback: import_v45.z.object({
|
|
2198
2226
|
blockReason: import_v45.z.string().nullish(),
|
|
2199
2227
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
@@ -2215,7 +2243,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
2215
2243
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2216
2244
|
})
|
|
2217
2245
|
).nullish(),
|
|
2218
|
-
usageMetadata: usageSchema.nullish(),
|
|
2246
|
+
usageMetadata: usageSchema().nullish(),
|
|
2219
2247
|
promptFeedback: import_v45.z.object({
|
|
2220
2248
|
blockReason: import_v45.z.string().nullish(),
|
|
2221
2249
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
@@ -2253,7 +2281,7 @@ var enterpriseWebSearch = (0, import_provider_utils8.createProviderDefinedToolFa
|
|
|
2253
2281
|
// src/tool/file-search.ts
|
|
2254
2282
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
2255
2283
|
var import_v48 = require("zod/v4");
|
|
2256
|
-
var fileSearchArgsBaseSchema = import_v48.z.object({
|
|
2284
|
+
var fileSearchArgsBaseSchema = () => import_v48.z.object({
|
|
2257
2285
|
/** The names of the file_search_stores to retrieve from.
|
|
2258
2286
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
2259
2287
|
*/
|
|
@@ -2270,7 +2298,7 @@ var fileSearchArgsBaseSchema = import_v48.z.object({
|
|
|
2270
2298
|
).optional()
|
|
2271
2299
|
}).passthrough();
|
|
2272
2300
|
var fileSearchArgsSchema = (0, import_provider_utils9.lazySchema)(
|
|
2273
|
-
() => (0, import_provider_utils9.zodSchema)(fileSearchArgsBaseSchema)
|
|
2301
|
+
() => (0, import_provider_utils9.zodSchema)(fileSearchArgsBaseSchema())
|
|
2274
2302
|
);
|
|
2275
2303
|
var fileSearch = (0, import_provider_utils9.createProviderDefinedToolFactory)({
|
|
2276
2304
|
id: "google.file_search",
|
|
@@ -2290,7 +2318,7 @@ var googleMaps = (0, import_provider_utils10.createProviderDefinedToolFactory)({
|
|
|
2290
2318
|
// src/tool/google-search.ts
|
|
2291
2319
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
2292
2320
|
var import_v410 = require("zod/v4");
|
|
2293
|
-
var googleSearchToolArgsBaseSchema = import_v410.z.object({
|
|
2321
|
+
var googleSearchToolArgsBaseSchema = () => import_v410.z.object({
|
|
2294
2322
|
searchTypes: import_v410.z.object({
|
|
2295
2323
|
webSearch: import_v410.z.object({}).optional(),
|
|
2296
2324
|
imageSearch: import_v410.z.object({}).optional()
|
|
@@ -2301,7 +2329,7 @@ var googleSearchToolArgsBaseSchema = import_v410.z.object({
|
|
|
2301
2329
|
}).optional()
|
|
2302
2330
|
}).passthrough();
|
|
2303
2331
|
var googleSearchToolArgsSchema = (0, import_provider_utils11.lazySchema)(
|
|
2304
|
-
() => (0, import_provider_utils11.zodSchema)(googleSearchToolArgsBaseSchema)
|
|
2332
|
+
() => (0, import_provider_utils11.zodSchema)(googleSearchToolArgsBaseSchema())
|
|
2305
2333
|
);
|
|
2306
2334
|
var googleSearch = (0, import_provider_utils11.createProviderDefinedToolFactory)({
|
|
2307
2335
|
id: "google.google_search",
|