@ai-sdk/google 4.0.54 → 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.
@@ -232,7 +232,8 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
232
232
  }, z.core.$strip>>>>;
233
233
  }, z.core.$strip>;
234
234
  declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
235
- candidates: {
235
+ responseId?: string | null | undefined;
236
+ candidates?: {
236
237
  content?: Record<string, never> | {
237
238
  parts?: ({
238
239
  functionCall: {
@@ -348,21 +349,34 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
348
349
  urlRetrievalStatus: string;
349
350
  }[] | null | undefined;
350
351
  } | null | undefined;
351
- }[];
352
- responseId?: string | null | undefined;
352
+ }[] | null | undefined;
353
353
  usageMetadata?: {
354
+ [x: string]: unknown;
354
355
  cachedContentTokenCount?: number | null | undefined;
355
356
  thoughtsTokenCount?: number | null | undefined;
356
357
  promptTokenCount?: number | null | undefined;
357
358
  candidatesTokenCount?: number | null | undefined;
359
+ toolUsePromptTokenCount?: number | null | undefined;
358
360
  totalTokenCount?: number | null | undefined;
359
361
  trafficType?: string | null | undefined;
360
362
  serviceTier?: string | null | undefined;
361
363
  promptTokensDetails?: {
364
+ [x: string]: unknown;
365
+ modality: string;
366
+ tokenCount: number;
367
+ }[] | null | undefined;
368
+ cacheTokensDetails?: {
369
+ [x: string]: unknown;
362
370
  modality: string;
363
371
  tokenCount: number;
364
372
  }[] | null | undefined;
365
373
  candidatesTokensDetails?: {
374
+ [x: string]: unknown;
375
+ modality: string;
376
+ tokenCount: number;
377
+ }[] | null | undefined;
378
+ toolUsePromptTokensDetails?: {
379
+ [x: string]: unknown;
366
380
  modality: string;
367
381
  tokenCount: number;
368
382
  }[] | null | undefined;
@@ -379,9 +393,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
379
393
  }[] | null | undefined;
380
394
  } | null | undefined;
381
395
  }>;
382
- type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
383
- type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
384
- type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
396
+ type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
397
+ type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
398
+ type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
399
+ type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
385
400
  type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
386
401
  type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
387
402
 
@@ -1553,6 +1553,7 @@ var configurableSafetySettingCategories = [
1553
1553
  "HARM_CATEGORY_HARASSMENT",
1554
1554
  "HARM_CATEGORY_SEXUALLY_EXPLICIT"
1555
1555
  ];
1556
+ var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
1556
1557
  var GoogleLanguageModel = class _GoogleLanguageModel {
1557
1558
  constructor(modelId, config) {
1558
1559
  this.specificationVersion = "v4";
@@ -1670,6 +1671,19 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1670
1671
  }
1671
1672
  }
1672
1673
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1674
+ const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
1675
+ if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
1676
+ warnings.push({
1677
+ type: "unsupported",
1678
+ feature: "frequencyPenalty"
1679
+ });
1680
+ }
1681
+ if (isGemini25DeveloperApiModel && presencePenalty != null) {
1682
+ warnings.push({
1683
+ type: "unsupported",
1684
+ feature: "presencePenalty"
1685
+ });
1686
+ }
1673
1687
  const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1674
1688
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1675
1689
  isGemmaModel,
@@ -1721,8 +1735,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1721
1735
  temperature,
1722
1736
  topK,
1723
1737
  topP,
1724
- frequencyPenalty,
1725
- presencePenalty,
1738
+ frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
1739
+ presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
1726
1740
  stopSequences,
1727
1741
  seed,
1728
1742
  // response format:
@@ -1761,18 +1775,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1761
1775
  warnings,
1762
1776
  providerOptionsNames
1763
1777
  }) {
1764
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1778
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1765
1779
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1766
1780
  providerOptionsNames.map((name) => [name, payload])
1767
1781
  );
1768
- const candidate = response.candidates[0];
1782
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1783
+ const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1784
+ const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
1785
+ const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
1769
1786
  const content = [];
1770
- const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
1787
+ const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
1771
1788
  const usageMetadata = response.usageMetadata;
1772
1789
  let lastCodeExecutionToolCallId;
1773
1790
  let lastServerToolCallId;
1774
1791
  for (const part of parts) {
1775
- if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
1792
+ if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
1776
1793
  const toolCallId = this.config.generateId();
1777
1794
  lastCodeExecutionToolCallId = toolCallId;
1778
1795
  content.push({
@@ -1790,7 +1807,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1790
1807
  toolName: "code_execution",
1791
1808
  result: {
1792
1809
  outcome: part.codeExecutionResult.outcome,
1793
- output: (_d = part.codeExecutionResult.output) != null ? _d : ""
1810
+ output: (_h = part.codeExecutionResult.output) != null ? _h : ""
1794
1811
  }
1795
1812
  });
1796
1813
  } else if ("text" in part && part.text != null) {
@@ -1814,7 +1831,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1814
1831
  type: "tool-call",
1815
1832
  toolCallId: part.functionCall.id || this.config.generateId(),
1816
1833
  toolName: part.functionCall.name,
1817
- input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1834
+ input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
1818
1835
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1819
1836
  thoughtSignature: part.thoughtSignature
1820
1837
  }) : void 0
@@ -1837,7 +1854,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1837
1854
  type: "tool-call",
1838
1855
  toolCallId,
1839
1856
  toolName: `server:${part.toolCall.toolType}`,
1840
- input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1857
+ input: JSON.stringify((_j = part.toolCall.args) != null ? _j : {}),
1841
1858
  providerExecuted: true,
1842
1859
  dynamic: true,
1843
1860
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1855,7 +1872,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1855
1872
  type: "tool-result",
1856
1873
  toolCallId: responseToolCallId,
1857
1874
  toolName: `server:${part.toolResponse.toolType}`,
1858
- result: (_g = part.toolResponse.response) != null ? _g : {},
1875
+ result: (_k = part.toolResponse.response) != null ? _k : {},
1859
1876
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1860
1877
  thoughtSignature: part.thoughtSignature,
1861
1878
  serverToolCallId: responseToolCallId,
@@ -1868,39 +1885,39 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1868
1885
  lastServerToolCallId = void 0;
1869
1886
  }
1870
1887
  }
1871
- const sources = (_h = extractSources({
1872
- groundingMetadata: candidate.groundingMetadata,
1888
+ const sources = (_l = extractSources({
1889
+ groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1873
1890
  generateId: this.config.generateId
1874
- })) != null ? _h : [];
1891
+ })) != null ? _l : [];
1875
1892
  for (const source of sources) {
1876
1893
  content.push(source);
1877
1894
  }
1878
1895
  return {
1879
1896
  content,
1880
1897
  finishReason: {
1881
- unified: mapGoogleFinishReason({
1882
- finishReason: candidate.finishReason,
1898
+ unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
1899
+ finishReason: rawFinishReason,
1883
1900
  // Only count client-executed tool calls for finish reason determination.
1884
1901
  hasToolCalls: content.some(
1885
1902
  (part) => part.type === "tool-call" && !part.providerExecuted
1886
1903
  )
1887
1904
  }),
1888
- raw: (_i = candidate.finishReason) != null ? _i : void 0
1905
+ raw: rawFinishReason
1889
1906
  },
1890
1907
  usage: convertGoogleUsage(usageMetadata),
1891
1908
  warnings,
1892
1909
  providerMetadata: wrapProviderMetadata({
1893
- promptFeedback: (_j = response.promptFeedback) != null ? _j : null,
1894
- groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
1895
- urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
1896
- safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null,
1910
+ promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1911
+ groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
1912
+ urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
1913
+ safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
1897
1914
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1898
- finishMessage: (_n = candidate.finishMessage) != null ? _n : null,
1899
- serviceTier: (_o = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _o : null
1915
+ finishMessage: (_q = candidate == null ? void 0 : candidate.finishMessage) != null ? _q : null,
1916
+ serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
1900
1917
  }),
1901
1918
  response: {
1902
1919
  // TODO timestamp, model id
1903
- id: (_p = response.responseId) != null ? _p : void 0
1920
+ id: (_s = response.responseId) != null ? _s : void 0
1904
1921
  }
1905
1922
  };
1906
1923
  }
@@ -2015,7 +2032,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2015
2032
  controller.enqueue({ type: "stream-start", warnings });
2016
2033
  },
2017
2034
  transform(chunk, controller) {
2018
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2035
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2019
2036
  if (options.includeRawChunks) {
2020
2037
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2021
2038
  }
@@ -2037,6 +2054,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2037
2054
  }
2038
2055
  const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
2039
2056
  if (candidate == null) {
2057
+ const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
2058
+ if (promptBlockReason2 != null) {
2059
+ finishReason = {
2060
+ unified: "content-filter",
2061
+ raw: promptBlockReason2
2062
+ };
2063
+ providerMetadata = wrapProviderMetadata({
2064
+ promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
2065
+ groundingMetadata: lastGroundingMetadata,
2066
+ urlContextMetadata: lastUrlContextMetadata,
2067
+ safetyRatings: null,
2068
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
2069
+ finishMessage: null,
2070
+ serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
2071
+ });
2072
+ }
2040
2073
  return;
2041
2074
  }
2042
2075
  const content = candidate.content;
@@ -2059,9 +2092,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2059
2092
  }
2060
2093
  }
2061
2094
  if (content != null) {
2062
- const parts = (_b = content.parts) != null ? _b : [];
2095
+ const parts = (_e = content.parts) != null ? _e : [];
2063
2096
  for (const part of parts) {
2064
- if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
2097
+ if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
2065
2098
  const toolCallId = generateId2();
2066
2099
  lastCodeExecutionToolCallId = toolCallId;
2067
2100
  controller.enqueue({
@@ -2080,7 +2113,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2080
2113
  toolName: "code_execution",
2081
2114
  result: {
2082
2115
  outcome: part.codeExecutionResult.outcome,
2083
- output: (_d = part.codeExecutionResult.output) != null ? _d : ""
2116
+ output: (_g = part.codeExecutionResult.output) != null ? _g : ""
2084
2117
  }
2085
2118
  });
2086
2119
  }
@@ -2180,7 +2213,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2180
2213
  type: "tool-call",
2181
2214
  toolCallId,
2182
2215
  toolName: `server:${part.toolCall.toolType}`,
2183
- input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
2216
+ input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
2184
2217
  providerExecuted: true,
2185
2218
  dynamic: true,
2186
2219
  providerMetadata: serverMeta
@@ -2196,7 +2229,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2196
2229
  type: "tool-result",
2197
2230
  toolCallId: responseToolCallId,
2198
2231
  toolName: `server:${part.toolResponse.toolType}`,
2199
- result: (_f = part.toolResponse.response) != null ? _f : {},
2232
+ result: (_i = part.toolResponse.response) != null ? _i : {},
2200
2233
  providerMetadata: serverMeta
2201
2234
  });
2202
2235
  lastServerToolCallId = void 0;
@@ -2263,7 +2296,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2263
2296
  } else if (isCompleteCall) {
2264
2297
  const toolCallId = part.functionCall.id || generateId2();
2265
2298
  const toolName = part.functionCall.name;
2266
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
2299
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_j = part.functionCall.args) != null ? _j : {});
2267
2300
  controller.enqueue({
2268
2301
  type: "tool-input-start",
2269
2302
  id: toolCallId,
@@ -2314,22 +2347,25 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2314
2347
  }
2315
2348
  }
2316
2349
  }
2317
- if (candidate.finishReason != null) {
2350
+ const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
2351
+ const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
2352
+ const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
2353
+ if (rawFinishReason != null) {
2318
2354
  finishReason = {
2319
- unified: mapGoogleFinishReason({
2320
- finishReason: candidate.finishReason,
2355
+ unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
2356
+ finishReason: rawFinishReason,
2321
2357
  hasToolCalls
2322
2358
  }),
2323
- raw: candidate.finishReason
2359
+ raw: rawFinishReason
2324
2360
  };
2325
2361
  providerMetadata = wrapProviderMetadata({
2326
- promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
2362
+ promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
2327
2363
  groundingMetadata: lastGroundingMetadata,
2328
2364
  urlContextMetadata: lastUrlContextMetadata,
2329
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
2365
+ safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
2330
2366
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2331
- finishMessage: (_j = candidate.finishMessage) != null ? _j : null,
2332
- serviceTier: (_k = usage == null ? void 0 : usage.serviceTier) != null ? _k : null
2367
+ finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
2368
+ serviceTier: (_q = usage == null ? void 0 : usage.serviceTier) != null ? _q : null
2333
2369
  });
2334
2370
  }
2335
2371
  },
@@ -2661,21 +2697,24 @@ var tokenDetailsSchema = z3.array(
2661
2697
  z3.object({
2662
2698
  modality: z3.string(),
2663
2699
  tokenCount: z3.number()
2664
- })
2700
+ }).loose()
2665
2701
  ).nullish();
2666
2702
  var usageSchema = z3.object({
2667
2703
  cachedContentTokenCount: z3.number().nullish(),
2668
2704
  thoughtsTokenCount: z3.number().nullish(),
2669
2705
  promptTokenCount: z3.number().nullish(),
2670
2706
  candidatesTokenCount: z3.number().nullish(),
2707
+ toolUsePromptTokenCount: z3.number().nullish(),
2671
2708
  totalTokenCount: z3.number().nullish(),
2672
2709
  // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
2673
2710
  trafficType: z3.string().nullish(),
2674
2711
  serviceTier: z3.string().nullish(),
2675
2712
  // https://ai.google.dev/api/generate-content#Modality
2676
2713
  promptTokensDetails: tokenDetailsSchema,
2677
- candidatesTokensDetails: tokenDetailsSchema
2678
- });
2714
+ cacheTokensDetails: tokenDetailsSchema,
2715
+ candidatesTokensDetails: tokenDetailsSchema,
2716
+ toolUsePromptTokensDetails: tokenDetailsSchema
2717
+ }).loose();
2679
2718
  var getUrlContextMetadataSchema = () => z3.object({
2680
2719
  urlMetadata: z3.array(
2681
2720
  z3.object({
@@ -2697,7 +2736,7 @@ var responseSchema = lazySchema3(
2697
2736
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2698
2737
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
2699
2738
  })
2700
- ),
2739
+ ).nullish(),
2701
2740
  usageMetadata: usageSchema.nullish(),
2702
2741
  promptFeedback: z3.object({
2703
2742
  blockReason: z3.string().nullish(),