@ai-sdk/google 4.0.55 → 4.0.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.55",
3
+ "version": "4.0.56",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -9,13 +9,16 @@ export type GoogleTokenDetail = {
9
9
  export type GoogleUsageMetadata = {
10
10
  promptTokenCount?: number | null;
11
11
  candidatesTokenCount?: number | null;
12
+ toolUsePromptTokenCount?: number | null;
12
13
  totalTokenCount?: number | null;
13
14
  cachedContentTokenCount?: number | null;
14
15
  thoughtsTokenCount?: number | null;
15
16
  trafficType?: string | null;
16
17
  serviceTier?: string | null;
17
18
  promptTokensDetails?: GoogleTokenDetail[] | null;
19
+ cacheTokensDetails?: GoogleTokenDetail[] | null;
18
20
  candidatesTokensDetails?: GoogleTokenDetail[] | null;
21
+ toolUsePromptTokensDetails?: GoogleTokenDetail[] | null;
19
22
  };
20
23
 
21
24
  export function convertGoogleUsage(
@@ -62,6 +62,8 @@ const configurableSafetySettingCategories = [
62
62
  'HARM_CATEGORY_SEXUALLY_EXPLICIT',
63
63
  ] as const;
64
64
 
65
+ const gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
66
+
65
67
  export type GoogleLanguageModelConfig = {
66
68
  provider: string;
67
69
  baseURL: string;
@@ -258,6 +260,22 @@ export class GoogleLanguageModel implements LanguageModelV4 {
258
260
  }
259
261
 
260
262
  const isGemmaModel = this.modelId.toLowerCase().startsWith('gemma-');
263
+ const isGemini25DeveloperApiModel =
264
+ !isVertexProvider && gemini25ModelPattern.test(this.modelId);
265
+
266
+ if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
267
+ warnings.push({
268
+ type: 'unsupported',
269
+ feature: 'frequencyPenalty',
270
+ });
271
+ }
272
+ if (isGemini25DeveloperApiModel && presencePenalty != null) {
273
+ warnings.push({
274
+ type: 'unsupported',
275
+ feature: 'presencePenalty',
276
+ });
277
+ }
278
+
261
279
  const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
262
280
 
263
281
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
@@ -331,8 +349,12 @@ export class GoogleLanguageModel implements LanguageModelV4 {
331
349
  temperature,
332
350
  topK,
333
351
  topP,
334
- frequencyPenalty,
335
- presencePenalty,
352
+ frequencyPenalty: isGemini25DeveloperApiModel
353
+ ? undefined
354
+ : frequencyPenalty,
355
+ presencePenalty: isGemini25DeveloperApiModel
356
+ ? undefined
357
+ : presencePenalty,
336
358
  stopSequences,
337
359
  seed,
338
360
 
@@ -1583,26 +1605,33 @@ const getSafetyRatingSchema = () =>
1583
1605
 
1584
1606
  const tokenDetailsSchema = z
1585
1607
  .array(
1586
- z.object({
1587
- modality: z.string(),
1588
- tokenCount: z.number(),
1589
- }),
1608
+ z
1609
+ .object({
1610
+ modality: z.string(),
1611
+ tokenCount: z.number(),
1612
+ })
1613
+ .loose(),
1590
1614
  )
1591
1615
  .nullish();
1592
1616
 
1593
- const usageSchema = z.object({
1594
- cachedContentTokenCount: z.number().nullish(),
1595
- thoughtsTokenCount: z.number().nullish(),
1596
- promptTokenCount: z.number().nullish(),
1597
- candidatesTokenCount: z.number().nullish(),
1598
- totalTokenCount: z.number().nullish(),
1599
- // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1600
- trafficType: z.string().nullish(),
1601
- serviceTier: z.string().nullish(),
1602
- // https://ai.google.dev/api/generate-content#Modality
1603
- promptTokensDetails: tokenDetailsSchema,
1604
- candidatesTokensDetails: tokenDetailsSchema,
1605
- });
1617
+ const usageSchema = z
1618
+ .object({
1619
+ cachedContentTokenCount: z.number().nullish(),
1620
+ thoughtsTokenCount: z.number().nullish(),
1621
+ promptTokenCount: z.number().nullish(),
1622
+ candidatesTokenCount: z.number().nullish(),
1623
+ toolUsePromptTokenCount: z.number().nullish(),
1624
+ totalTokenCount: z.number().nullish(),
1625
+ // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1626
+ trafficType: z.string().nullish(),
1627
+ serviceTier: z.string().nullish(),
1628
+ // https://ai.google.dev/api/generate-content#Modality
1629
+ promptTokensDetails: tokenDetailsSchema,
1630
+ cacheTokensDetails: tokenDetailsSchema,
1631
+ candidatesTokensDetails: tokenDetailsSchema,
1632
+ toolUsePromptTokensDetails: tokenDetailsSchema,
1633
+ })
1634
+ .loose();
1606
1635
 
1607
1636
  // https://ai.google.dev/api/generate-content#UrlRetrievalMetadata
1608
1637
  export const getUrlContextMetadataSchema = () =>