@depup/ai-sdk__google 4.0.72-depup.0 → 4.0.75-depup.0

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.
@@ -22,18 +22,20 @@ import { z as z3 } from "zod/v4";
22
22
  // src/convert-google-usage.ts
23
23
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
24
24
  function convertGoogleUsage(usage) {
25
- var _a, _b, _c, _d;
25
+ var _a, _b, _c, _d, _e;
26
26
  if (usage == null) {
27
27
  return createNullLanguageModelUsage();
28
28
  }
29
29
  const promptTokens = (_a = usage.promptTokenCount) != null ? _a : 0;
30
30
  const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
31
- const cachedContentTokens = (_c = usage.cachedContentTokenCount) != null ? _c : 0;
32
- const thoughtsTokens = (_d = usage.thoughtsTokenCount) != null ? _d : 0;
31
+ const toolUsePromptTokens = (_c = usage.toolUsePromptTokenCount) != null ? _c : 0;
32
+ const cachedContentTokens = (_d = usage.cachedContentTokenCount) != null ? _d : 0;
33
+ const thoughtsTokens = (_e = usage.thoughtsTokenCount) != null ? _e : 0;
34
+ const inputTokens = promptTokens + toolUsePromptTokens;
33
35
  return {
34
36
  inputTokens: {
35
- total: promptTokens,
36
- noCache: promptTokens - cachedContentTokens,
37
+ total: inputTokens,
38
+ noCache: inputTokens - cachedContentTokens,
37
39
  cacheRead: cachedContentTokens,
38
40
  cacheWrite: void 0
39
41
  },
@@ -1645,27 +1647,30 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1645
1647
  providerOptionsNames,
1646
1648
  toolNameMapping
1647
1649
  }) {
1648
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
1650
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
1649
1651
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1650
1652
  providerOptionsNames.map((name) => [name, payload])
1651
1653
  );
1652
1654
  const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1653
1655
  const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1654
- const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
1655
- const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
1656
+ const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
1657
+ promptBlockReason
1658
+ ) ? promptBlockReason : void 0;
1659
+ const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
1660
+ const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
1656
1661
  const content = [];
1657
- const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
1662
+ const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
1658
1663
  const usageMetadata = response.usageMetadata;
1659
1664
  let lastCodeExecutionToolCallId;
1660
1665
  let lastServerToolCallId;
1661
1666
  for (const part of parts) {
1662
- if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
1667
+ if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
1663
1668
  const toolCallId = config.generateId();
1664
1669
  lastCodeExecutionToolCallId = toolCallId;
1665
1670
  content.push({
1666
1671
  type: "tool-call",
1667
1672
  toolCallId,
1668
- toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1673
+ toolName: (_g = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _g : "code_execution",
1669
1674
  input: JSON.stringify(part.executableCode),
1670
1675
  providerExecuted: true
1671
1676
  });
@@ -1674,10 +1679,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1674
1679
  type: "tool-result",
1675
1680
  // Results correspond to the most recent executable code part.
1676
1681
  toolCallId: lastCodeExecutionToolCallId,
1677
- toolName: (_i = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _i : "code_execution",
1682
+ toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1678
1683
  result: {
1679
1684
  outcome: part.codeExecutionResult.outcome,
1680
- output: (_j = part.codeExecutionResult.output) != null ? _j : ""
1685
+ output: (_i = part.codeExecutionResult.output) != null ? _i : ""
1681
1686
  }
1682
1687
  });
1683
1688
  } else if ("text" in part && part.text != null) {
@@ -1701,7 +1706,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1701
1706
  type: "tool-call",
1702
1707
  toolCallId: part.functionCall.id || config.generateId(),
1703
1708
  toolName: part.functionCall.name,
1704
- input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
1709
+ input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
1705
1710
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1706
1711
  thoughtSignature: part.thoughtSignature
1707
1712
  }) : void 0
@@ -1724,7 +1729,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1724
1729
  type: "tool-call",
1725
1730
  toolCallId,
1726
1731
  toolName: `server:${part.toolCall.toolType}`,
1727
- input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
1732
+ input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
1728
1733
  providerExecuted: true,
1729
1734
  dynamic: true,
1730
1735
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1742,7 +1747,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1742
1747
  type: "tool-result",
1743
1748
  toolCallId: responseToolCallId,
1744
1749
  toolName: `server:${part.toolResponse.toolType}`,
1745
- result: (_m = part.toolResponse.response) != null ? _m : {},
1750
+ result: (_l = part.toolResponse.response) != null ? _l : {},
1746
1751
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1747
1752
  thoughtSignature: part.thoughtSignature,
1748
1753
  serverToolCallId: responseToolCallId,
@@ -1755,10 +1760,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1755
1760
  lastServerToolCallId = void 0;
1756
1761
  }
1757
1762
  }
1758
- const sources = (_n = extractSources({
1763
+ const sources = (_m = extractSources({
1759
1764
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1760
1765
  generateId: config.generateId
1761
- })) != null ? _n : [];
1766
+ })) != null ? _m : [];
1762
1767
  for (const source of sources) {
1763
1768
  content.push(source);
1764
1769
  }
@@ -1777,17 +1782,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1777
1782
  usage: convertGoogleUsage(usageMetadata),
1778
1783
  warnings,
1779
1784
  providerMetadata: wrapProviderMetadata({
1780
- promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
1781
- groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
1782
- urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
1783
- safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
1785
+ promptFeedback: (_n = response.promptFeedback) != null ? _n : null,
1786
+ groundingMetadata: (_o = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _o : null,
1787
+ urlContextMetadata: (_p = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _p : null,
1788
+ safetyRatings: (_q = candidate == null ? void 0 : candidate.safetyRatings) != null ? _q : null,
1784
1789
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1785
- finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
1786
- serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
1790
+ finishMessage: (_r = candidate == null ? void 0 : candidate.finishMessage) != null ? _r : null,
1791
+ serviceTier: (_s = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _s : null
1787
1792
  }),
1788
1793
  response: {
1789
1794
  // TODO timestamp, model id
1790
- id: (_u = response.responseId) != null ? _u : void 0
1795
+ id: (_t = response.responseId) != null ? _t : void 0
1791
1796
  }
1792
1797
  };
1793
1798
  }
@@ -1868,9 +1873,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1868
1873
  raw: void 0
1869
1874
  };
1870
1875
  let usage = void 0;
1871
- let providerMetadata = void 0;
1876
+ let promptFeedback = null;
1872
1877
  let lastGroundingMetadata = null;
1873
1878
  let lastUrlContextMetadata = null;
1879
+ let lastSafetyRatings = null;
1880
+ let lastFinishMessage = null;
1881
+ let confirmedPromptBlockReason;
1874
1882
  const generateId2 = this.config.generateId;
1875
1883
  let hasToolCalls = false;
1876
1884
  let hasEmittedResponseMetadata = false;
@@ -1916,7 +1924,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1916
1924
  controller.enqueue({ type: "stream-start", warnings });
1917
1925
  },
1918
1926
  transform(chunk, controller) {
1919
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1927
+ var _a, _b, _c, _d, _e, _f, _g;
1920
1928
  if (options.includeRawChunks) {
1921
1929
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1922
1930
  }
@@ -1936,33 +1944,35 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1936
1944
  if (usageMetadata != null) {
1937
1945
  usage = usageMetadata;
1938
1946
  }
1939
- const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1940
- if (candidate == null) {
1941
- const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
1942
- if (promptBlockReason2 != null) {
1947
+ if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
1948
+ promptFeedback = value.promptFeedback;
1949
+ if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
1950
+ confirmedPromptBlockReason = value.promptFeedback.blockReason;
1943
1951
  finishReason = {
1944
1952
  unified: "content-filter",
1945
- raw: promptBlockReason2
1953
+ raw: confirmedPromptBlockReason
1946
1954
  };
1947
- providerMetadata = wrapProviderMetadata({
1948
- promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
1949
- groundingMetadata: lastGroundingMetadata,
1950
- urlContextMetadata: lastUrlContextMetadata,
1951
- safetyRatings: null,
1952
- usageMetadata: usageMetadata != null ? usageMetadata : null,
1953
- finishMessage: null,
1954
- serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
1955
- });
1956
1955
  }
1957
- return;
1958
1956
  }
1959
- const content = candidate.content;
1960
- if (candidate.groundingMetadata != null) {
1961
- lastGroundingMetadata = candidate.groundingMetadata;
1957
+ const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1958
+ if (candidate != null) {
1959
+ if (candidate.groundingMetadata != null) {
1960
+ lastGroundingMetadata = candidate.groundingMetadata;
1961
+ }
1962
+ if (candidate.urlContextMetadata != null) {
1963
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1964
+ }
1965
+ if (candidate.safetyRatings != null) {
1966
+ lastSafetyRatings = candidate.safetyRatings;
1967
+ }
1968
+ if (candidate.finishMessage != null) {
1969
+ lastFinishMessage = candidate.finishMessage;
1970
+ }
1962
1971
  }
1963
- if (candidate.urlContextMetadata != null) {
1964
- lastUrlContextMetadata = candidate.urlContextMetadata;
1972
+ if (confirmedPromptBlockReason != null || candidate == null) {
1973
+ return;
1965
1974
  }
1975
+ const content = candidate.content;
1966
1976
  const sources = extractSources({
1967
1977
  groundingMetadata: candidate.groundingMetadata,
1968
1978
  generateId: generateId2
@@ -1976,9 +1986,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1976
1986
  }
1977
1987
  }
1978
1988
  if (content != null) {
1979
- const parts = (_e = content.parts) != null ? _e : [];
1989
+ const parts = (_b = content.parts) != null ? _b : [];
1980
1990
  for (const part of parts) {
1981
- if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
1991
+ if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
1982
1992
  const toolCallId = generateId2();
1983
1993
  lastCodeExecutionToolCallId = toolCallId;
1984
1994
  controller.enqueue({
@@ -1997,7 +2007,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1997
2007
  toolName: toolNameMapping.toCustomToolName("code_execution"),
1998
2008
  result: {
1999
2009
  outcome: part.codeExecutionResult.outcome,
2000
- output: (_g = part.codeExecutionResult.output) != null ? _g : ""
2010
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
2001
2011
  }
2002
2012
  });
2003
2013
  }
@@ -2097,7 +2107,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2097
2107
  type: "tool-call",
2098
2108
  toolCallId,
2099
2109
  toolName: `server:${part.toolCall.toolType}`,
2100
- input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
2110
+ input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
2101
2111
  providerExecuted: true,
2102
2112
  dynamic: true,
2103
2113
  providerMetadata: serverMeta
@@ -2113,7 +2123,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2113
2123
  type: "tool-result",
2114
2124
  toolCallId: responseToolCallId,
2115
2125
  toolName: `server:${part.toolResponse.toolType}`,
2116
- result: (_i = part.toolResponse.response) != null ? _i : {},
2126
+ result: (_f = part.toolResponse.response) != null ? _f : {},
2117
2127
  providerMetadata: serverMeta
2118
2128
  });
2119
2129
  lastServerToolCallId = void 0;
@@ -2180,7 +2190,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2180
2190
  } else if (isCompleteCall) {
2181
2191
  const toolCallId = part.functionCall.id || generateId2();
2182
2192
  const toolName = part.functionCall.name;
2183
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_j = part.functionCall.args) != null ? _j : {});
2193
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
2184
2194
  controller.enqueue({
2185
2195
  type: "tool-input-start",
2186
2196
  id: toolCallId,
@@ -2231,29 +2241,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2231
2241
  }
2232
2242
  }
2233
2243
  }
2234
- const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
2235
- const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
2236
- const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
2237
- if (rawFinishReason != null) {
2244
+ if (candidate.finishReason != null) {
2238
2245
  finishReason = {
2239
- unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
2240
- finishReason: rawFinishReason,
2246
+ unified: mapGoogleFinishReason({
2247
+ finishReason: candidate.finishReason,
2241
2248
  hasToolCalls
2242
2249
  }),
2243
- raw: rawFinishReason
2250
+ raw: candidate.finishReason
2244
2251
  };
2245
- providerMetadata = wrapProviderMetadata({
2246
- promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
2247
- groundingMetadata: lastGroundingMetadata,
2248
- urlContextMetadata: lastUrlContextMetadata,
2249
- safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
2250
- usageMetadata: usageMetadata != null ? usageMetadata : null,
2251
- finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
2252
- serviceTier: (_q = usage == null ? void 0 : usage.serviceTier) != null ? _q : null
2253
- });
2254
2252
  }
2255
2253
  },
2256
2254
  flush(controller) {
2255
+ var _a;
2257
2256
  if (currentTextBlockId !== null) {
2258
2257
  controller.enqueue({
2259
2258
  type: "text-end",
@@ -2270,7 +2269,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2270
2269
  type: "finish",
2271
2270
  finishReason,
2272
2271
  usage: convertGoogleUsage(usage),
2273
- providerMetadata
2272
+ providerMetadata: wrapProviderMetadata({
2273
+ promptFeedback,
2274
+ groundingMetadata: lastGroundingMetadata,
2275
+ urlContextMetadata: lastUrlContextMetadata,
2276
+ safetyRatings: lastSafetyRatings,
2277
+ usageMetadata: usage != null ? usage : null,
2278
+ finishMessage: lastFinishMessage,
2279
+ serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
2280
+ })
2274
2281
  });
2275
2282
  }
2276
2283
  })
@@ -2651,6 +2658,9 @@ var chunkSchema = lazySchema3(
2651
2658
  })
2652
2659
  )
2653
2660
  );
2661
+ function isConfirmedPromptBlockReason(blockReason) {
2662
+ return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
2663
+ }
2654
2664
 
2655
2665
  // src/google-speech-model.ts
2656
2666
  import {