@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/internal/index.mjs
CHANGED
|
@@ -1023,6 +1023,7 @@ var configurableSafetySettingCategories = [
|
|
|
1023
1023
|
"HARM_CATEGORY_HARASSMENT",
|
|
1024
1024
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1025
1025
|
];
|
|
1026
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1026
1027
|
var GoogleGenerativeAILanguageModel = class {
|
|
1027
1028
|
constructor(modelId, config) {
|
|
1028
1029
|
this.specificationVersion = "v2";
|
|
@@ -1100,6 +1101,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1100
1101
|
threshold: safetyThreshold
|
|
1101
1102
|
})) : void 0;
|
|
1102
1103
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1104
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1105
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1106
|
+
warnings.push({
|
|
1107
|
+
type: "unsupported-setting",
|
|
1108
|
+
setting: "frequencyPenalty"
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1112
|
+
warnings.push({
|
|
1113
|
+
type: "unsupported-setting",
|
|
1114
|
+
setting: "presencePenalty"
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1103
1117
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1104
1118
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1105
1119
|
prompt,
|
|
@@ -1127,8 +1141,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1127
1141
|
temperature,
|
|
1128
1142
|
topK,
|
|
1129
1143
|
topP,
|
|
1130
|
-
frequencyPenalty,
|
|
1131
|
-
presencePenalty,
|
|
1144
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1145
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1132
1146
|
stopSequences,
|
|
1133
1147
|
seed,
|
|
1134
1148
|
// response format:
|
|
@@ -1164,7 +1178,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1164
1178
|
};
|
|
1165
1179
|
}
|
|
1166
1180
|
async doGenerate(options) {
|
|
1167
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1181
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1168
1182
|
const { args, warnings } = await this.getArgs(options);
|
|
1169
1183
|
const body = JSON.stringify(args);
|
|
1170
1184
|
const mergedHeaders = combineHeaders(
|
|
@@ -1186,13 +1200,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1186
1200
|
abortSignal: options.abortSignal,
|
|
1187
1201
|
fetch: this.config.fetch
|
|
1188
1202
|
});
|
|
1189
|
-
const candidate = response.candidates[0];
|
|
1203
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1204
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1205
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1190
1206
|
const content = [];
|
|
1191
|
-
const parts = (
|
|
1207
|
+
const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
|
|
1192
1208
|
const usageMetadata = response.usageMetadata;
|
|
1193
1209
|
let lastCodeExecutionToolCallId;
|
|
1194
1210
|
for (const part of parts) {
|
|
1195
|
-
if ("executableCode" in part && ((
|
|
1211
|
+
if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
|
|
1196
1212
|
const toolCallId = this.config.generateId();
|
|
1197
1213
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1198
1214
|
content.push({
|
|
@@ -1233,7 +1249,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1233
1249
|
} else if ("functionCall" in part) {
|
|
1234
1250
|
content.push({
|
|
1235
1251
|
type: "tool-call",
|
|
1236
|
-
toolCallId: (
|
|
1252
|
+
toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
|
|
1237
1253
|
toolName: part.functionCall.name,
|
|
1238
1254
|
input: JSON.stringify(part.functionCall.args),
|
|
1239
1255
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -1246,34 +1262,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1246
1262
|
});
|
|
1247
1263
|
}
|
|
1248
1264
|
}
|
|
1249
|
-
const sources = (
|
|
1250
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1265
|
+
const sources = (_g = extractSources({
|
|
1266
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1251
1267
|
generateId: this.config.generateId
|
|
1252
|
-
})) != null ?
|
|
1268
|
+
})) != null ? _g : [];
|
|
1253
1269
|
for (const source of sources) {
|
|
1254
1270
|
content.push(source);
|
|
1255
1271
|
}
|
|
1256
1272
|
return {
|
|
1257
1273
|
content,
|
|
1258
|
-
finishReason: mapGoogleGenerativeAIFinishReason({
|
|
1259
|
-
finishReason: candidate.finishReason,
|
|
1274
|
+
finishReason: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1275
|
+
finishReason: candidate == null ? void 0 : candidate.finishReason,
|
|
1260
1276
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
1261
1277
|
}),
|
|
1262
1278
|
usage: {
|
|
1263
|
-
inputTokens: (
|
|
1264
|
-
outputTokens: (
|
|
1265
|
-
totalTokens: (
|
|
1266
|
-
reasoningTokens: (
|
|
1267
|
-
cachedInputTokens: (
|
|
1279
|
+
inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
|
|
1280
|
+
outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
|
|
1281
|
+
totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
|
|
1282
|
+
reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
|
|
1283
|
+
cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
|
|
1268
1284
|
},
|
|
1269
1285
|
warnings,
|
|
1270
1286
|
providerMetadata: {
|
|
1271
1287
|
google: {
|
|
1272
|
-
promptFeedback: (
|
|
1273
|
-
groundingMetadata: (
|
|
1274
|
-
urlContextMetadata: (
|
|
1275
|
-
safetyRatings: (
|
|
1276
|
-
serviceTier: (
|
|
1288
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1289
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
1290
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
1291
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
1292
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null,
|
|
1277
1293
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1278
1294
|
}
|
|
1279
1295
|
},
|
|
@@ -1327,7 +1343,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1327
1343
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1328
1344
|
},
|
|
1329
1345
|
transform(chunk, controller) {
|
|
1330
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1346
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1331
1347
|
if (options.includeRawChunks) {
|
|
1332
1348
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1333
1349
|
}
|
|
@@ -1349,6 +1365,22 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1349
1365
|
}
|
|
1350
1366
|
const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
|
|
1351
1367
|
if (candidate == null) {
|
|
1368
|
+
const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
|
|
1369
|
+
if (promptBlockReason2 != null) {
|
|
1370
|
+
finishReason = "content-filter";
|
|
1371
|
+
providerMetadata = {
|
|
1372
|
+
google: {
|
|
1373
|
+
promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
|
|
1374
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1375
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1376
|
+
safetyRatings: null,
|
|
1377
|
+
serviceTier
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
if (usageMetadata != null) {
|
|
1381
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1352
1384
|
return;
|
|
1353
1385
|
}
|
|
1354
1386
|
const content = candidate.content;
|
|
@@ -1371,9 +1403,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1371
1403
|
}
|
|
1372
1404
|
}
|
|
1373
1405
|
if (content != null) {
|
|
1374
|
-
const parts = (
|
|
1406
|
+
const parts = (_i = content.parts) != null ? _i : [];
|
|
1375
1407
|
for (const part of parts) {
|
|
1376
|
-
if ("executableCode" in part && ((
|
|
1408
|
+
if ("executableCode" in part && ((_j = part.executableCode) == null ? void 0 : _j.code)) {
|
|
1377
1409
|
const toolCallId = generateId2();
|
|
1378
1410
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1379
1411
|
controller.enqueue({
|
|
@@ -1500,17 +1532,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1500
1532
|
}
|
|
1501
1533
|
}
|
|
1502
1534
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1535
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
1536
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
1537
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
1538
|
+
if (rawFinishReason != null) {
|
|
1539
|
+
finishReason = isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
|
|
1540
|
+
finishReason: rawFinishReason,
|
|
1506
1541
|
hasToolCalls
|
|
1507
1542
|
});
|
|
1508
1543
|
providerMetadata = {
|
|
1509
1544
|
google: {
|
|
1510
|
-
promptFeedback: (
|
|
1545
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
1511
1546
|
groundingMetadata: lastGroundingMetadata,
|
|
1512
1547
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1513
|
-
safetyRatings: (
|
|
1548
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1514
1549
|
serviceTier
|
|
1515
1550
|
}
|
|
1516
1551
|
};
|
|
@@ -1786,7 +1821,7 @@ var responseSchema = lazySchema3(
|
|
|
1786
1821
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1787
1822
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1788
1823
|
})
|
|
1789
|
-
),
|
|
1824
|
+
).nullish(),
|
|
1790
1825
|
usageMetadata: usageSchema.nullish(),
|
|
1791
1826
|
promptFeedback: z3.object({
|
|
1792
1827
|
blockReason: z3.string().nullish(),
|