@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/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 ? "2.0.
|
|
10
|
+
var VERSION = true ? "2.0.95" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -1232,6 +1232,7 @@ var configurableSafetySettingCategories = [
|
|
|
1232
1232
|
"HARM_CATEGORY_HARASSMENT",
|
|
1233
1233
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1234
1234
|
];
|
|
1235
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1235
1236
|
var GoogleGenerativeAILanguageModel = class {
|
|
1236
1237
|
constructor(modelId, config) {
|
|
1237
1238
|
this.specificationVersion = "v2";
|
|
@@ -1309,6 +1310,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1309
1310
|
threshold: safetyThreshold
|
|
1310
1311
|
})) : void 0;
|
|
1311
1312
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1313
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1314
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1315
|
+
warnings.push({
|
|
1316
|
+
type: "unsupported-setting",
|
|
1317
|
+
setting: "frequencyPenalty"
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1321
|
+
warnings.push({
|
|
1322
|
+
type: "unsupported-setting",
|
|
1323
|
+
setting: "presencePenalty"
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1312
1326
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1313
1327
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1314
1328
|
prompt,
|
|
@@ -1336,8 +1350,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1336
1350
|
temperature,
|
|
1337
1351
|
topK,
|
|
1338
1352
|
topP,
|
|
1339
|
-
frequencyPenalty,
|
|
1340
|
-
presencePenalty,
|
|
1353
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1354
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1341
1355
|
stopSequences,
|
|
1342
1356
|
seed,
|
|
1343
1357
|
// response format:
|
|
@@ -1373,7 +1387,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1373
1387
|
};
|
|
1374
1388
|
}
|
|
1375
1389
|
async doGenerate(options) {
|
|
1376
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1390
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1377
1391
|
const { args, warnings } = await this.getArgs(options);
|
|
1378
1392
|
const body = JSON.stringify(args);
|
|
1379
1393
|
const mergedHeaders = combineHeaders2(
|
|
@@ -1395,13 +1409,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1395
1409
|
abortSignal: options.abortSignal,
|
|
1396
1410
|
fetch: this.config.fetch
|
|
1397
1411
|
});
|
|
1398
|
-
const candidate = response.candidates[0];
|
|
1412
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1413
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1414
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1399
1415
|
const content = [];
|
|
1400
|
-
const parts = (
|
|
1416
|
+
const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
|
|
1401
1417
|
const usageMetadata = response.usageMetadata;
|
|
1402
1418
|
let lastCodeExecutionToolCallId;
|
|
1403
1419
|
for (const part of parts) {
|
|
1404
|
-
if ("executableCode" in part && ((
|
|
1420
|
+
if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
|
|
1405
1421
|
const toolCallId = this.config.generateId();
|
|
1406
1422
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1407
1423
|
content.push({
|
|
@@ -1442,7 +1458,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1442
1458
|
} else if ("functionCall" in part) {
|
|
1443
1459
|
content.push({
|
|
1444
1460
|
type: "tool-call",
|
|
1445
|
-
toolCallId: (
|
|
1461
|
+
toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
|
|
1446
1462
|
toolName: part.functionCall.name,
|
|
1447
1463
|
input: JSON.stringify(part.functionCall.args),
|
|
1448
1464
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -1455,34 +1471,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1455
1471
|
});
|
|
1456
1472
|
}
|
|
1457
1473
|
}
|
|
1458
|
-
const sources = (
|
|
1459
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1474
|
+
const sources = (_g = extractSources({
|
|
1475
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1460
1476
|
generateId: this.config.generateId
|
|
1461
|
-
})) != null ?
|
|
1477
|
+
})) != null ? _g : [];
|
|
1462
1478
|
for (const source of sources) {
|
|
1463
1479
|
content.push(source);
|
|
1464
1480
|
}
|
|
1465
1481
|
return {
|
|
1466
1482
|
content,
|
|
1467
|
-
finishReason: mapGoogleGenerativeAIFinishReason({
|
|
1468
|
-
finishReason: candidate.finishReason,
|
|
1483
|
+
finishReason: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1484
|
+
finishReason: candidate == null ? void 0 : candidate.finishReason,
|
|
1469
1485
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
1470
1486
|
}),
|
|
1471
1487
|
usage: {
|
|
1472
|
-
inputTokens: (
|
|
1473
|
-
outputTokens: (
|
|
1474
|
-
totalTokens: (
|
|
1475
|
-
reasoningTokens: (
|
|
1476
|
-
cachedInputTokens: (
|
|
1488
|
+
inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
|
|
1489
|
+
outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
|
|
1490
|
+
totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
|
|
1491
|
+
reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
|
|
1492
|
+
cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
|
|
1477
1493
|
},
|
|
1478
1494
|
warnings,
|
|
1479
1495
|
providerMetadata: {
|
|
1480
1496
|
google: {
|
|
1481
|
-
promptFeedback: (
|
|
1482
|
-
groundingMetadata: (
|
|
1483
|
-
urlContextMetadata: (
|
|
1484
|
-
safetyRatings: (
|
|
1485
|
-
serviceTier: (
|
|
1497
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1498
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
1499
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
1500
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
1501
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null,
|
|
1486
1502
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1487
1503
|
}
|
|
1488
1504
|
},
|
|
@@ -1536,7 +1552,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1536
1552
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1537
1553
|
},
|
|
1538
1554
|
transform(chunk, controller) {
|
|
1539
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1555
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1540
1556
|
if (options.includeRawChunks) {
|
|
1541
1557
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1542
1558
|
}
|
|
@@ -1558,6 +1574,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1558
1574
|
}
|
|
1559
1575
|
const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
|
|
1560
1576
|
if (candidate == null) {
|
|
1577
|
+
const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
|
|
1578
|
+
if (promptBlockReason2 != null) {
|
|
1579
|
+
finishReason = "content-filter";
|
|
1580
|
+
providerMetadata = {
|
|
1581
|
+
google: {
|
|
1582
|
+
promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
|
|
1583
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1584
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1585
|
+
safetyRatings: null,
|
|
1586
|
+
serviceTier
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
if (usageMetadata != null) {
|
|
1590
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1561
1593
|
return;
|
|
1562
1594
|
}
|
|
1563
1595
|
const content = candidate.content;
|
|
@@ -1580,9 +1612,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1580
1612
|
}
|
|
1581
1613
|
}
|
|
1582
1614
|
if (content != null) {
|
|
1583
|
-
const parts = (
|
|
1615
|
+
const parts = (_i = content.parts) != null ? _i : [];
|
|
1584
1616
|
for (const part of parts) {
|
|
1585
|
-
if ("executableCode" in part && ((
|
|
1617
|
+
if ("executableCode" in part && ((_j = part.executableCode) == null ? void 0 : _j.code)) {
|
|
1586
1618
|
const toolCallId = generateId3();
|
|
1587
1619
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1588
1620
|
controller.enqueue({
|
|
@@ -1709,17 +1741,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1709
1741
|
}
|
|
1710
1742
|
}
|
|
1711
1743
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1744
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
1745
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
1746
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
1747
|
+
if (rawFinishReason != null) {
|
|
1748
|
+
finishReason = isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1749
|
+
finishReason: rawFinishReason,
|
|
1715
1750
|
hasToolCalls
|
|
1716
1751
|
});
|
|
1717
1752
|
providerMetadata = {
|
|
1718
1753
|
google: {
|
|
1719
|
-
promptFeedback: (
|
|
1754
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
1720
1755
|
groundingMetadata: lastGroundingMetadata,
|
|
1721
1756
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1722
|
-
safetyRatings: (
|
|
1757
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1723
1758
|
serviceTier
|
|
1724
1759
|
}
|
|
1725
1760
|
};
|
|
@@ -1995,7 +2030,7 @@ var responseSchema = lazySchema5(
|
|
|
1995
2030
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1996
2031
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1997
2032
|
})
|
|
1998
|
-
),
|
|
2033
|
+
).nullish(),
|
|
1999
2034
|
usageMetadata: usageSchema.nullish(),
|
|
2000
2035
|
promptFeedback: z5.object({
|
|
2001
2036
|
blockReason: z5.string().nullish(),
|