@ai-sdk/google 4.0.63 → 4.0.64

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.
@@ -1,5 +1,5 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
- import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
2
+ import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction, InferSchema, createToolNameMapping } from '@ai-sdk/provider-utils';
3
3
  import * as _ai_sdk_provider from '@ai-sdk/provider';
4
4
  import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, SharedV4Warning, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SpeechModelV4 } from '@ai-sdk/provider';
5
5
  import { z } from 'zod/v4';
@@ -169,11 +169,13 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
169
169
  warnings: SharedV4Warning[];
170
170
  providerOptionsNames: readonly string[];
171
171
  extraHeaders: Record<string, string> | undefined;
172
+ toolNameMapping: _ai_sdk_provider_utils.ToolNameMapping;
172
173
  }>;
173
- protected convertGenerateContentResponse({ response, warnings, providerOptionsNames, }: {
174
+ protected convertGenerateContentResponse({ response, warnings, providerOptionsNames, toolNameMapping, }: {
174
175
  response: InferSchema<typeof responseSchema>;
175
176
  warnings: SharedV4Warning[];
176
177
  providerOptionsNames: readonly string[];
178
+ toolNameMapping?: ReturnType<typeof createToolNameMapping>;
177
179
  }): LanguageModelV4GenerateResult;
178
180
  doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
179
181
  doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
@@ -1,6 +1,7 @@
1
1
  // src/google-language-model.ts
2
2
  import {
3
3
  combineHeaders,
4
+ createToolNameMapping,
4
5
  createEventSourceResponseHandler,
5
6
  createJsonResponseHandler,
6
7
  generateId,
@@ -97,6 +98,8 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
97
98
  format,
98
99
  const: constValue,
99
100
  minLength,
101
+ minItems,
102
+ maxItems,
100
103
  enum: enumValues
101
104
  } = jsonSchema;
102
105
  const result = {};
@@ -179,6 +182,12 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
179
182
  if (minLength !== void 0) {
180
183
  result.minLength = minLength;
181
184
  }
185
+ if (minItems !== void 0) {
186
+ result.minItems = minItems;
187
+ }
188
+ if (maxItems !== void 0) {
189
+ result.maxItems = maxItems;
190
+ }
182
191
  return result;
183
192
  }
184
193
  function convertJSONSchemaReference({
@@ -1703,6 +1712,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1703
1712
  modelId: this.modelId,
1704
1713
  isVertexProvider
1705
1714
  });
1715
+ const toolNameMapping = createToolNameMapping({
1716
+ tools,
1717
+ providerToolNames: {
1718
+ "google.code_execution": "code_execution"
1719
+ }
1720
+ });
1706
1721
  const resolvedThinking = resolveThinkingConfig({
1707
1722
  reasoning,
1708
1723
  modelId: this.modelId,
@@ -1767,15 +1782,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1767
1782
  },
1768
1783
  warnings: [...warnings, ...toolWarnings],
1769
1784
  providerOptionsNames,
1770
- extraHeaders: vertexPaygoHeaders
1785
+ extraHeaders: vertexPaygoHeaders,
1786
+ toolNameMapping
1771
1787
  };
1772
1788
  }
1773
1789
  convertGenerateContentResponse({
1774
1790
  response,
1775
1791
  warnings,
1776
- providerOptionsNames
1792
+ providerOptionsNames,
1793
+ toolNameMapping
1777
1794
  }) {
1778
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1795
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
1779
1796
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1780
1797
  providerOptionsNames.map((name) => [name, payload])
1781
1798
  );
@@ -1795,7 +1812,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1795
1812
  content.push({
1796
1813
  type: "tool-call",
1797
1814
  toolCallId,
1798
- toolName: "code_execution",
1815
+ toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1799
1816
  input: JSON.stringify(part.executableCode),
1800
1817
  providerExecuted: true
1801
1818
  });
@@ -1804,10 +1821,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1804
1821
  type: "tool-result",
1805
1822
  // Results correspond to the most recent executable code part.
1806
1823
  toolCallId: lastCodeExecutionToolCallId,
1807
- toolName: "code_execution",
1824
+ toolName: (_i = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _i : "code_execution",
1808
1825
  result: {
1809
1826
  outcome: part.codeExecutionResult.outcome,
1810
- output: (_h = part.codeExecutionResult.output) != null ? _h : ""
1827
+ output: (_j = part.codeExecutionResult.output) != null ? _j : ""
1811
1828
  }
1812
1829
  });
1813
1830
  } else if ("text" in part && part.text != null) {
@@ -1831,7 +1848,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1831
1848
  type: "tool-call",
1832
1849
  toolCallId: part.functionCall.id || this.config.generateId(),
1833
1850
  toolName: part.functionCall.name,
1834
- input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
1851
+ input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
1835
1852
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1836
1853
  thoughtSignature: part.thoughtSignature
1837
1854
  }) : void 0
@@ -1854,7 +1871,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1854
1871
  type: "tool-call",
1855
1872
  toolCallId,
1856
1873
  toolName: `server:${part.toolCall.toolType}`,
1857
- input: JSON.stringify((_j = part.toolCall.args) != null ? _j : {}),
1874
+ input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
1858
1875
  providerExecuted: true,
1859
1876
  dynamic: true,
1860
1877
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1872,7 +1889,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1872
1889
  type: "tool-result",
1873
1890
  toolCallId: responseToolCallId,
1874
1891
  toolName: `server:${part.toolResponse.toolType}`,
1875
- result: (_k = part.toolResponse.response) != null ? _k : {},
1892
+ result: (_m = part.toolResponse.response) != null ? _m : {},
1876
1893
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1877
1894
  thoughtSignature: part.thoughtSignature,
1878
1895
  serverToolCallId: responseToolCallId,
@@ -1885,10 +1902,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1885
1902
  lastServerToolCallId = void 0;
1886
1903
  }
1887
1904
  }
1888
- const sources = (_l = extractSources({
1905
+ const sources = (_n = extractSources({
1889
1906
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1890
1907
  generateId: this.config.generateId
1891
- })) != null ? _l : [];
1908
+ })) != null ? _n : [];
1892
1909
  for (const source of sources) {
1893
1910
  content.push(source);
1894
1911
  }
@@ -1907,22 +1924,28 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1907
1924
  usage: convertGoogleUsage(usageMetadata),
1908
1925
  warnings,
1909
1926
  providerMetadata: wrapProviderMetadata({
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,
1927
+ promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
1928
+ groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
1929
+ urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
1930
+ safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
1914
1931
  usageMetadata: usageMetadata != null ? usageMetadata : 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
1932
+ finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
1933
+ serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
1917
1934
  }),
1918
1935
  response: {
1919
1936
  // TODO timestamp, model id
1920
- id: (_s = response.responseId) != null ? _s : void 0
1937
+ id: (_u = response.responseId) != null ? _u : void 0
1921
1938
  }
1922
1939
  };
1923
1940
  }
1924
1941
  async doGenerate(options) {
1925
- const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
1942
+ const {
1943
+ args,
1944
+ warnings,
1945
+ providerOptionsNames,
1946
+ extraHeaders,
1947
+ toolNameMapping
1948
+ } = await this.getArgs(options);
1926
1949
  const mergedHeaders = combineHeaders(
1927
1950
  this.config.headers ? await resolve(this.config.headers) : void 0,
1928
1951
  options.headers,
@@ -1946,7 +1969,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1946
1969
  const result = this.convertGenerateContentResponse({
1947
1970
  response,
1948
1971
  warnings,
1949
- providerOptionsNames
1972
+ providerOptionsNames,
1973
+ toolNameMapping
1950
1974
  });
1951
1975
  return {
1952
1976
  ...result,
@@ -1959,7 +1983,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1959
1983
  };
1960
1984
  }
1961
1985
  async doStream(options) {
1962
- const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options, { isStreaming: true });
1986
+ const {
1987
+ args,
1988
+ warnings,
1989
+ providerOptionsNames,
1990
+ extraHeaders,
1991
+ toolNameMapping
1992
+ } = await this.getArgs(options, { isStreaming: true });
1963
1993
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1964
1994
  providerOptionsNames.map((name) => [name, payload])
1965
1995
  );
@@ -2100,7 +2130,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2100
2130
  controller.enqueue({
2101
2131
  type: "tool-call",
2102
2132
  toolCallId,
2103
- toolName: "code_execution",
2133
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2104
2134
  input: JSON.stringify(part.executableCode),
2105
2135
  providerExecuted: true
2106
2136
  });
@@ -2110,7 +2140,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2110
2140
  controller.enqueue({
2111
2141
  type: "tool-result",
2112
2142
  toolCallId,
2113
- toolName: "code_execution",
2143
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2114
2144
  result: {
2115
2145
  outcome: part.codeExecutionResult.outcome,
2116
2146
  output: (_g = part.codeExecutionResult.output) != null ? _g : ""