@ai-sdk/google 2.0.93 → 2.0.95
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 +14 -0
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +67 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -5
- package/dist/internal/index.d.ts +6 -5
- package/dist/internal/index.js +66 -31
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +66 -31
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 2.0.95
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [26165ee]
|
|
8
|
+
- @ai-sdk/provider-utils@3.0.36
|
|
9
|
+
|
|
10
|
+
## 2.0.94
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- c43ba7d: Surface prompt-level Google safety blocks without candidates as content-filter results with prompt feedback metadata.
|
|
15
|
+
- 7a292cd: Omit unsupported frequency and presence penalties from Gemini 2.5 requests and return warnings instead.
|
|
16
|
+
|
|
3
17
|
## 2.0.93
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -51,7 +51,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
|
|
|
51
51
|
type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
|
|
52
52
|
|
|
53
53
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
54
|
-
candidates
|
|
54
|
+
candidates?: {
|
|
55
55
|
content?: Record<string, never> | {
|
|
56
56
|
parts?: ({
|
|
57
57
|
functionCall: {
|
|
@@ -141,7 +141,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
141
141
|
urlRetrievalStatus: string;
|
|
142
142
|
}[];
|
|
143
143
|
} | null | undefined;
|
|
144
|
-
}[];
|
|
144
|
+
}[] | null | undefined;
|
|
145
145
|
usageMetadata?: {
|
|
146
146
|
cachedContentTokenCount?: number | null | undefined;
|
|
147
147
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -171,9 +171,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
171
|
} | null | undefined;
|
|
172
172
|
serviceTier?: string | null | undefined;
|
|
173
173
|
}>;
|
|
174
|
-
type
|
|
175
|
-
type
|
|
176
|
-
type
|
|
174
|
+
type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
|
|
175
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
176
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
177
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
177
178
|
|
|
178
179
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
179
180
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
|
|
|
51
51
|
type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
|
|
52
52
|
|
|
53
53
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
54
|
-
candidates
|
|
54
|
+
candidates?: {
|
|
55
55
|
content?: Record<string, never> | {
|
|
56
56
|
parts?: ({
|
|
57
57
|
functionCall: {
|
|
@@ -141,7 +141,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
141
141
|
urlRetrievalStatus: string;
|
|
142
142
|
}[];
|
|
143
143
|
} | null | undefined;
|
|
144
|
-
}[];
|
|
144
|
+
}[] | null | undefined;
|
|
145
145
|
usageMetadata?: {
|
|
146
146
|
cachedContentTokenCount?: number | null | undefined;
|
|
147
147
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -171,9 +171,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
171
171
|
} | null | undefined;
|
|
172
172
|
serviceTier?: string | null | undefined;
|
|
173
173
|
}>;
|
|
174
|
-
type
|
|
175
|
-
type
|
|
176
|
-
type
|
|
174
|
+
type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
|
|
175
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
176
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
177
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
177
178
|
|
|
178
179
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
179
180
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
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.95" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -1219,6 +1219,7 @@ var configurableSafetySettingCategories = [
|
|
|
1219
1219
|
"HARM_CATEGORY_HARASSMENT",
|
|
1220
1220
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1221
1221
|
];
|
|
1222
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1222
1223
|
var GoogleGenerativeAILanguageModel = class {
|
|
1223
1224
|
constructor(modelId, config) {
|
|
1224
1225
|
this.specificationVersion = "v2";
|
|
@@ -1296,6 +1297,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1296
1297
|
threshold: safetyThreshold
|
|
1297
1298
|
})) : void 0;
|
|
1298
1299
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1300
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1301
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1302
|
+
warnings.push({
|
|
1303
|
+
type: "unsupported-setting",
|
|
1304
|
+
setting: "frequencyPenalty"
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1308
|
+
warnings.push({
|
|
1309
|
+
type: "unsupported-setting",
|
|
1310
|
+
setting: "presencePenalty"
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1299
1313
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1300
1314
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1301
1315
|
prompt,
|
|
@@ -1323,8 +1337,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1323
1337
|
temperature,
|
|
1324
1338
|
topK,
|
|
1325
1339
|
topP,
|
|
1326
|
-
frequencyPenalty,
|
|
1327
|
-
presencePenalty,
|
|
1340
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1341
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1328
1342
|
stopSequences,
|
|
1329
1343
|
seed,
|
|
1330
1344
|
// response format:
|
|
@@ -1360,7 +1374,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1360
1374
|
};
|
|
1361
1375
|
}
|
|
1362
1376
|
async doGenerate(options) {
|
|
1363
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1377
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1364
1378
|
const { args, warnings } = await this.getArgs(options);
|
|
1365
1379
|
const body = JSON.stringify(args);
|
|
1366
1380
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
@@ -1382,13 +1396,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1382
1396
|
abortSignal: options.abortSignal,
|
|
1383
1397
|
fetch: this.config.fetch
|
|
1384
1398
|
});
|
|
1385
|
-
const candidate = response.candidates[0];
|
|
1399
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1400
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1401
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1386
1402
|
const content = [];
|
|
1387
|
-
const parts = (
|
|
1403
|
+
const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
|
|
1388
1404
|
const usageMetadata = response.usageMetadata;
|
|
1389
1405
|
let lastCodeExecutionToolCallId;
|
|
1390
1406
|
for (const part of parts) {
|
|
1391
|
-
if ("executableCode" in part && ((
|
|
1407
|
+
if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
|
|
1392
1408
|
const toolCallId = this.config.generateId();
|
|
1393
1409
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1394
1410
|
content.push({
|
|
@@ -1429,7 +1445,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1429
1445
|
} else if ("functionCall" in part) {
|
|
1430
1446
|
content.push({
|
|
1431
1447
|
type: "tool-call",
|
|
1432
|
-
toolCallId: (
|
|
1448
|
+
toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
|
|
1433
1449
|
toolName: part.functionCall.name,
|
|
1434
1450
|
input: JSON.stringify(part.functionCall.args),
|
|
1435
1451
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -1442,34 +1458,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1442
1458
|
});
|
|
1443
1459
|
}
|
|
1444
1460
|
}
|
|
1445
|
-
const sources = (
|
|
1446
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1461
|
+
const sources = (_g = extractSources({
|
|
1462
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1447
1463
|
generateId: this.config.generateId
|
|
1448
|
-
})) != null ?
|
|
1464
|
+
})) != null ? _g : [];
|
|
1449
1465
|
for (const source of sources) {
|
|
1450
1466
|
content.push(source);
|
|
1451
1467
|
}
|
|
1452
1468
|
return {
|
|
1453
1469
|
content,
|
|
1454
|
-
finishReason: mapGoogleGenerativeAIFinishReason({
|
|
1455
|
-
finishReason: candidate.finishReason,
|
|
1470
|
+
finishReason: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1471
|
+
finishReason: candidate == null ? void 0 : candidate.finishReason,
|
|
1456
1472
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
1457
1473
|
}),
|
|
1458
1474
|
usage: {
|
|
1459
|
-
inputTokens: (
|
|
1460
|
-
outputTokens: (
|
|
1461
|
-
totalTokens: (
|
|
1462
|
-
reasoningTokens: (
|
|
1463
|
-
cachedInputTokens: (
|
|
1475
|
+
inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
|
|
1476
|
+
outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
|
|
1477
|
+
totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
|
|
1478
|
+
reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
|
|
1479
|
+
cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
|
|
1464
1480
|
},
|
|
1465
1481
|
warnings,
|
|
1466
1482
|
providerMetadata: {
|
|
1467
1483
|
google: {
|
|
1468
|
-
promptFeedback: (
|
|
1469
|
-
groundingMetadata: (
|
|
1470
|
-
urlContextMetadata: (
|
|
1471
|
-
safetyRatings: (
|
|
1472
|
-
serviceTier: (
|
|
1484
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1485
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
1486
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
1487
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
1488
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null,
|
|
1473
1489
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1474
1490
|
}
|
|
1475
1491
|
},
|
|
@@ -1523,7 +1539,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1523
1539
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1524
1540
|
},
|
|
1525
1541
|
transform(chunk, controller) {
|
|
1526
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1542
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1527
1543
|
if (options.includeRawChunks) {
|
|
1528
1544
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1529
1545
|
}
|
|
@@ -1545,6 +1561,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1545
1561
|
}
|
|
1546
1562
|
const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
|
|
1547
1563
|
if (candidate == null) {
|
|
1564
|
+
const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
|
|
1565
|
+
if (promptBlockReason2 != null) {
|
|
1566
|
+
finishReason = "content-filter";
|
|
1567
|
+
providerMetadata = {
|
|
1568
|
+
google: {
|
|
1569
|
+
promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
|
|
1570
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1571
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1572
|
+
safetyRatings: null,
|
|
1573
|
+
serviceTier
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
if (usageMetadata != null) {
|
|
1577
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1548
1580
|
return;
|
|
1549
1581
|
}
|
|
1550
1582
|
const content = candidate.content;
|
|
@@ -1567,9 +1599,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1567
1599
|
}
|
|
1568
1600
|
}
|
|
1569
1601
|
if (content != null) {
|
|
1570
|
-
const parts = (
|
|
1602
|
+
const parts = (_i = content.parts) != null ? _i : [];
|
|
1571
1603
|
for (const part of parts) {
|
|
1572
|
-
if ("executableCode" in part && ((
|
|
1604
|
+
if ("executableCode" in part && ((_j = part.executableCode) == null ? void 0 : _j.code)) {
|
|
1573
1605
|
const toolCallId = generateId3();
|
|
1574
1606
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1575
1607
|
controller.enqueue({
|
|
@@ -1696,17 +1728,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1696
1728
|
}
|
|
1697
1729
|
}
|
|
1698
1730
|
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1731
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
1732
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
1733
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
1734
|
+
if (rawFinishReason != null) {
|
|
1735
|
+
finishReason = isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1736
|
+
finishReason: rawFinishReason,
|
|
1702
1737
|
hasToolCalls
|
|
1703
1738
|
});
|
|
1704
1739
|
providerMetadata = {
|
|
1705
1740
|
google: {
|
|
1706
|
-
promptFeedback: (
|
|
1741
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
1707
1742
|
groundingMetadata: lastGroundingMetadata,
|
|
1708
1743
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1709
|
-
safetyRatings: (
|
|
1744
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1710
1745
|
serviceTier
|
|
1711
1746
|
}
|
|
1712
1747
|
};
|
|
@@ -1982,7 +2017,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1982
2017
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1983
2018
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1984
2019
|
})
|
|
1985
|
-
),
|
|
2020
|
+
).nullish(),
|
|
1986
2021
|
usageMetadata: usageSchema.nullish(),
|
|
1987
2022
|
promptFeedback: import_v45.z.object({
|
|
1988
2023
|
blockReason: import_v45.z.string().nullish(),
|