@ai-sdk/google 4.0.72 → 4.0.74

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.
@@ -1868,9 +1868,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1868
1868
  raw: void 0
1869
1869
  };
1870
1870
  let usage = void 0;
1871
- let providerMetadata = void 0;
1871
+ let promptFeedback = null;
1872
1872
  let lastGroundingMetadata = null;
1873
1873
  let lastUrlContextMetadata = null;
1874
+ let lastSafetyRatings = null;
1875
+ let lastFinishMessage = null;
1876
+ let confirmedPromptBlockReason;
1874
1877
  const generateId2 = this.config.generateId;
1875
1878
  let hasToolCalls = false;
1876
1879
  let hasEmittedResponseMetadata = false;
@@ -1916,7 +1919,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1916
1919
  controller.enqueue({ type: "stream-start", warnings });
1917
1920
  },
1918
1921
  transform(chunk, controller) {
1919
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1922
+ var _a, _b, _c, _d, _e, _f, _g;
1920
1923
  if (options.includeRawChunks) {
1921
1924
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1922
1925
  }
@@ -1936,33 +1939,35 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1936
1939
  if (usageMetadata != null) {
1937
1940
  usage = usageMetadata;
1938
1941
  }
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) {
1942
+ if (value.promptFeedback != null && confirmedPromptBlockReason == null) {
1943
+ promptFeedback = value.promptFeedback;
1944
+ if (isConfirmedPromptBlockReason(value.promptFeedback.blockReason)) {
1945
+ confirmedPromptBlockReason = value.promptFeedback.blockReason;
1943
1946
  finishReason = {
1944
1947
  unified: "content-filter",
1945
- raw: promptBlockReason2
1948
+ raw: confirmedPromptBlockReason
1946
1949
  };
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
1950
  }
1957
- return;
1958
1951
  }
1959
- const content = candidate.content;
1960
- if (candidate.groundingMetadata != null) {
1961
- lastGroundingMetadata = candidate.groundingMetadata;
1952
+ const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1953
+ if (candidate != null) {
1954
+ if (candidate.groundingMetadata != null) {
1955
+ lastGroundingMetadata = candidate.groundingMetadata;
1956
+ }
1957
+ if (candidate.urlContextMetadata != null) {
1958
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1959
+ }
1960
+ if (candidate.safetyRatings != null) {
1961
+ lastSafetyRatings = candidate.safetyRatings;
1962
+ }
1963
+ if (candidate.finishMessage != null) {
1964
+ lastFinishMessage = candidate.finishMessage;
1965
+ }
1962
1966
  }
1963
- if (candidate.urlContextMetadata != null) {
1964
- lastUrlContextMetadata = candidate.urlContextMetadata;
1967
+ if (confirmedPromptBlockReason != null || candidate == null) {
1968
+ return;
1965
1969
  }
1970
+ const content = candidate.content;
1966
1971
  const sources = extractSources({
1967
1972
  groundingMetadata: candidate.groundingMetadata,
1968
1973
  generateId: generateId2
@@ -1976,9 +1981,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1976
1981
  }
1977
1982
  }
1978
1983
  if (content != null) {
1979
- const parts = (_e = content.parts) != null ? _e : [];
1984
+ const parts = (_b = content.parts) != null ? _b : [];
1980
1985
  for (const part of parts) {
1981
- if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
1986
+ if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
1982
1987
  const toolCallId = generateId2();
1983
1988
  lastCodeExecutionToolCallId = toolCallId;
1984
1989
  controller.enqueue({
@@ -1997,7 +2002,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1997
2002
  toolName: toolNameMapping.toCustomToolName("code_execution"),
1998
2003
  result: {
1999
2004
  outcome: part.codeExecutionResult.outcome,
2000
- output: (_g = part.codeExecutionResult.output) != null ? _g : ""
2005
+ output: (_d = part.codeExecutionResult.output) != null ? _d : ""
2001
2006
  }
2002
2007
  });
2003
2008
  }
@@ -2097,7 +2102,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2097
2102
  type: "tool-call",
2098
2103
  toolCallId,
2099
2104
  toolName: `server:${part.toolCall.toolType}`,
2100
- input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
2105
+ input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
2101
2106
  providerExecuted: true,
2102
2107
  dynamic: true,
2103
2108
  providerMetadata: serverMeta
@@ -2113,7 +2118,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2113
2118
  type: "tool-result",
2114
2119
  toolCallId: responseToolCallId,
2115
2120
  toolName: `server:${part.toolResponse.toolType}`,
2116
- result: (_i = part.toolResponse.response) != null ? _i : {},
2121
+ result: (_f = part.toolResponse.response) != null ? _f : {},
2117
2122
  providerMetadata: serverMeta
2118
2123
  });
2119
2124
  lastServerToolCallId = void 0;
@@ -2180,7 +2185,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2180
2185
  } else if (isCompleteCall) {
2181
2186
  const toolCallId = part.functionCall.id || generateId2();
2182
2187
  const toolName = part.functionCall.name;
2183
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_j = part.functionCall.args) != null ? _j : {});
2188
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
2184
2189
  controller.enqueue({
2185
2190
  type: "tool-input-start",
2186
2191
  id: toolCallId,
@@ -2231,29 +2236,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2231
2236
  }
2232
2237
  }
2233
2238
  }
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) {
2239
+ if (candidate.finishReason != null) {
2238
2240
  finishReason = {
2239
- unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
2240
- finishReason: rawFinishReason,
2241
+ unified: mapGoogleFinishReason({
2242
+ finishReason: candidate.finishReason,
2241
2243
  hasToolCalls
2242
2244
  }),
2243
- raw: rawFinishReason
2245
+ raw: candidate.finishReason
2244
2246
  };
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
2247
  }
2255
2248
  },
2256
2249
  flush(controller) {
2250
+ var _a;
2257
2251
  if (currentTextBlockId !== null) {
2258
2252
  controller.enqueue({
2259
2253
  type: "text-end",
@@ -2270,7 +2264,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2270
2264
  type: "finish",
2271
2265
  finishReason,
2272
2266
  usage: convertGoogleUsage(usage),
2273
- providerMetadata
2267
+ providerMetadata: wrapProviderMetadata({
2268
+ promptFeedback,
2269
+ groundingMetadata: lastGroundingMetadata,
2270
+ urlContextMetadata: lastUrlContextMetadata,
2271
+ safetyRatings: lastSafetyRatings,
2272
+ usageMetadata: usage != null ? usage : null,
2273
+ finishMessage: lastFinishMessage,
2274
+ serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null
2275
+ })
2274
2276
  });
2275
2277
  }
2276
2278
  })
@@ -2651,6 +2653,9 @@ var chunkSchema = lazySchema3(
2651
2653
  })
2652
2654
  )
2653
2655
  );
2656
+ function isConfirmedPromptBlockReason(blockReason) {
2657
+ return blockReason != null && blockReason !== "" && blockReason !== "BLOCK_REASON_UNSPECIFIED" && blockReason !== "BLOCKED_REASON_UNSPECIFIED";
2658
+ }
2654
2659
 
2655
2660
  // src/google-speech-model.ts
2656
2661
  import {