@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.
@@ -82,7 +82,7 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
82
82
  }, z.core.$strip>>;
83
83
  }, z.core.$strip>;
84
84
  declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
85
- candidates: {
85
+ candidates?: {
86
86
  content?: Record<string, never> | {
87
87
  parts?: ({
88
88
  functionCall: {
@@ -172,7 +172,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
172
172
  urlRetrievalStatus: string;
173
173
  }[];
174
174
  } | null | undefined;
175
- }[];
175
+ }[] | null | undefined;
176
176
  usageMetadata?: {
177
177
  cachedContentTokenCount?: number | null | undefined;
178
178
  thoughtsTokenCount?: number | null | undefined;
@@ -202,9 +202,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
202
202
  } | null | undefined;
203
203
  serviceTier?: string | null | undefined;
204
204
  }>;
205
- type GroundingMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
206
- type UrlContextMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
207
- type SafetyRatingSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
205
+ type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
206
+ type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
207
+ type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
208
+ type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
208
209
 
209
210
  declare const googleTools: {
210
211
  /**
@@ -82,7 +82,7 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
82
82
  }, z.core.$strip>>;
83
83
  }, z.core.$strip>;
84
84
  declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
85
- candidates: {
85
+ candidates?: {
86
86
  content?: Record<string, never> | {
87
87
  parts?: ({
88
88
  functionCall: {
@@ -172,7 +172,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
172
172
  urlRetrievalStatus: string;
173
173
  }[];
174
174
  } | null | undefined;
175
- }[];
175
+ }[] | null | undefined;
176
176
  usageMetadata?: {
177
177
  cachedContentTokenCount?: number | null | undefined;
178
178
  thoughtsTokenCount?: number | null | undefined;
@@ -202,9 +202,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
202
202
  } | null | undefined;
203
203
  serviceTier?: string | null | undefined;
204
204
  }>;
205
- type GroundingMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
206
- type UrlContextMetadataSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
207
- type SafetyRatingSchema = NonNullable<InferValidator<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
205
+ type CandidateSchema = NonNullable<InferValidator<typeof responseSchema>['candidates']>[number];
206
+ type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
207
+ type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
208
+ type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
208
209
 
209
210
  declare const googleTools: {
210
211
  /**
@@ -1029,6 +1029,7 @@ var configurableSafetySettingCategories = [
1029
1029
  "HARM_CATEGORY_HARASSMENT",
1030
1030
  "HARM_CATEGORY_SEXUALLY_EXPLICIT"
1031
1031
  ];
1032
+ var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
1032
1033
  var GoogleGenerativeAILanguageModel = class {
1033
1034
  constructor(modelId, config) {
1034
1035
  this.specificationVersion = "v2";
@@ -1106,6 +1107,19 @@ var GoogleGenerativeAILanguageModel = class {
1106
1107
  threshold: safetyThreshold
1107
1108
  })) : void 0;
1108
1109
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1110
+ const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
1111
+ if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
1112
+ warnings.push({
1113
+ type: "unsupported-setting",
1114
+ setting: "frequencyPenalty"
1115
+ });
1116
+ }
1117
+ if (isGemini25DeveloperApiModel && presencePenalty != null) {
1118
+ warnings.push({
1119
+ type: "unsupported-setting",
1120
+ setting: "presencePenalty"
1121
+ });
1122
+ }
1109
1123
  const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1110
1124
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1111
1125
  prompt,
@@ -1133,8 +1147,8 @@ var GoogleGenerativeAILanguageModel = class {
1133
1147
  temperature,
1134
1148
  topK,
1135
1149
  topP,
1136
- frequencyPenalty,
1137
- presencePenalty,
1150
+ frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
1151
+ presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
1138
1152
  stopSequences,
1139
1153
  seed,
1140
1154
  // response format:
@@ -1170,7 +1184,7 @@ var GoogleGenerativeAILanguageModel = class {
1170
1184
  };
1171
1185
  }
1172
1186
  async doGenerate(options) {
1173
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1187
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1174
1188
  const { args, warnings } = await this.getArgs(options);
1175
1189
  const body = JSON.stringify(args);
1176
1190
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
@@ -1192,13 +1206,15 @@ var GoogleGenerativeAILanguageModel = class {
1192
1206
  abortSignal: options.abortSignal,
1193
1207
  fetch: this.config.fetch
1194
1208
  });
1195
- const candidate = response.candidates[0];
1209
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1210
+ const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1211
+ const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
1196
1212
  const content = [];
1197
- const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
1213
+ const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
1198
1214
  const usageMetadata = response.usageMetadata;
1199
1215
  let lastCodeExecutionToolCallId;
1200
1216
  for (const part of parts) {
1201
- if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
1217
+ if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
1202
1218
  const toolCallId = this.config.generateId();
1203
1219
  lastCodeExecutionToolCallId = toolCallId;
1204
1220
  content.push({
@@ -1239,7 +1255,7 @@ var GoogleGenerativeAILanguageModel = class {
1239
1255
  } else if ("functionCall" in part) {
1240
1256
  content.push({
1241
1257
  type: "tool-call",
1242
- toolCallId: (_d = part.functionCall.id) != null ? _d : this.config.generateId(),
1258
+ toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
1243
1259
  toolName: part.functionCall.name,
1244
1260
  input: JSON.stringify(part.functionCall.args),
1245
1261
  providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
@@ -1252,34 +1268,34 @@ var GoogleGenerativeAILanguageModel = class {
1252
1268
  });
1253
1269
  }
1254
1270
  }
1255
- const sources = (_e = extractSources({
1256
- groundingMetadata: candidate.groundingMetadata,
1271
+ const sources = (_g = extractSources({
1272
+ groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1257
1273
  generateId: this.config.generateId
1258
- })) != null ? _e : [];
1274
+ })) != null ? _g : [];
1259
1275
  for (const source of sources) {
1260
1276
  content.push(source);
1261
1277
  }
1262
1278
  return {
1263
1279
  content,
1264
- finishReason: mapGoogleGenerativeAIFinishReason({
1265
- finishReason: candidate.finishReason,
1280
+ finishReason: isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
1281
+ finishReason: candidate == null ? void 0 : candidate.finishReason,
1266
1282
  hasToolCalls: content.some((part) => part.type === "tool-call")
1267
1283
  }),
1268
1284
  usage: {
1269
- inputTokens: (_f = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _f : void 0,
1270
- outputTokens: (_g = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _g : void 0,
1271
- totalTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _h : void 0,
1272
- reasoningTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _i : void 0,
1273
- cachedInputTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _j : void 0
1285
+ inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
1286
+ outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
1287
+ totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
1288
+ reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
1289
+ cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
1274
1290
  },
1275
1291
  warnings,
1276
1292
  providerMetadata: {
1277
1293
  google: {
1278
- promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1279
- groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1280
- urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1281
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1282
- serviceTier: (_o = response.serviceTier) != null ? _o : null,
1294
+ promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1295
+ groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
1296
+ urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
1297
+ safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
1298
+ serviceTier: (_q = response.serviceTier) != null ? _q : null,
1283
1299
  usageMetadata: usageMetadata != null ? usageMetadata : null
1284
1300
  }
1285
1301
  },
@@ -1333,7 +1349,7 @@ var GoogleGenerativeAILanguageModel = class {
1333
1349
  controller.enqueue({ type: "stream-start", warnings });
1334
1350
  },
1335
1351
  transform(chunk, controller) {
1336
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1352
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1337
1353
  if (options.includeRawChunks) {
1338
1354
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1339
1355
  }
@@ -1355,6 +1371,22 @@ var GoogleGenerativeAILanguageModel = class {
1355
1371
  }
1356
1372
  const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
1357
1373
  if (candidate == null) {
1374
+ const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
1375
+ if (promptBlockReason2 != null) {
1376
+ finishReason = "content-filter";
1377
+ providerMetadata = {
1378
+ google: {
1379
+ promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
1380
+ groundingMetadata: lastGroundingMetadata,
1381
+ urlContextMetadata: lastUrlContextMetadata,
1382
+ safetyRatings: null,
1383
+ serviceTier
1384
+ }
1385
+ };
1386
+ if (usageMetadata != null) {
1387
+ providerMetadata.google.usageMetadata = usageMetadata;
1388
+ }
1389
+ }
1358
1390
  return;
1359
1391
  }
1360
1392
  const content = candidate.content;
@@ -1377,9 +1409,9 @@ var GoogleGenerativeAILanguageModel = class {
1377
1409
  }
1378
1410
  }
1379
1411
  if (content != null) {
1380
- const parts = (_g = content.parts) != null ? _g : [];
1412
+ const parts = (_i = content.parts) != null ? _i : [];
1381
1413
  for (const part of parts) {
1382
- if ("executableCode" in part && ((_h = part.executableCode) == null ? void 0 : _h.code)) {
1414
+ if ("executableCode" in part && ((_j = part.executableCode) == null ? void 0 : _j.code)) {
1383
1415
  const toolCallId = generateId2();
1384
1416
  lastCodeExecutionToolCallId = toolCallId;
1385
1417
  controller.enqueue({
@@ -1506,17 +1538,20 @@ var GoogleGenerativeAILanguageModel = class {
1506
1538
  }
1507
1539
  }
1508
1540
  }
1509
- if (candidate.finishReason != null) {
1510
- finishReason = mapGoogleGenerativeAIFinishReason({
1511
- finishReason: candidate.finishReason,
1541
+ const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
1542
+ const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
1543
+ const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
1544
+ if (rawFinishReason != null) {
1545
+ finishReason = isPromptBlocked ? "content-filter" : mapGoogleGenerativeAIFinishReason({
1546
+ finishReason: rawFinishReason,
1512
1547
  hasToolCalls
1513
1548
  });
1514
1549
  providerMetadata = {
1515
1550
  google: {
1516
- promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
1551
+ promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
1517
1552
  groundingMetadata: lastGroundingMetadata,
1518
1553
  urlContextMetadata: lastUrlContextMetadata,
1519
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
1554
+ safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1520
1555
  serviceTier
1521
1556
  }
1522
1557
  };
@@ -1792,7 +1827,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
1792
1827
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1793
1828
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
1794
1829
  })
1795
- ),
1830
+ ).nullish(),
1796
1831
  usageMetadata: usageSchema.nullish(),
1797
1832
  promptFeedback: import_v43.z.object({
1798
1833
  blockReason: import_v43.z.string().nullish(),