@ai-sdk/google 4.0.64 → 4.0.66

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.
@@ -96,7 +96,10 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
96
96
  constructor(modelId: GoogleModelId, config: GoogleLanguageModelConfig);
97
97
  get provider(): string;
98
98
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
99
- protected getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, }: LanguageModelV4CallOptions, { isStreaming }?: {
99
+ static prepareRequest({ modelId, config, options: { prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, }, isStreaming, }: {
100
+ modelId: GoogleModelId;
101
+ config: GoogleLanguageModelConfig;
102
+ options: LanguageModelV4CallOptions;
100
103
  isStreaming?: boolean;
101
104
  }): Promise<{
102
105
  args: {
@@ -171,7 +174,9 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
171
174
  extraHeaders: Record<string, string> | undefined;
172
175
  toolNameMapping: _ai_sdk_provider_utils.ToolNameMapping;
173
176
  }>;
174
- protected convertGenerateContentResponse({ response, warnings, providerOptionsNames, toolNameMapping, }: {
177
+ private getArgs;
178
+ static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping, }: {
179
+ config: GoogleLanguageModelConfig;
175
180
  response: InferSchema<typeof responseSchema>;
176
181
  warnings: SharedV4Warning[];
177
182
  providerOptionsNames: readonly string[];
@@ -1587,25 +1587,32 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1587
1587
  var _a, _b, _c;
1588
1588
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
1589
1589
  }
1590
- async getArgs({
1591
- prompt,
1592
- maxOutputTokens,
1593
- temperature,
1594
- topP,
1595
- topK,
1596
- frequencyPenalty,
1597
- presencePenalty,
1598
- stopSequences,
1599
- responseFormat,
1600
- seed,
1601
- tools,
1602
- toolChoice,
1603
- reasoning,
1604
- providerOptions
1605
- }, { isStreaming = false } = {}) {
1590
+ static async prepareRequest({
1591
+ modelId,
1592
+ config,
1593
+ options: {
1594
+ prompt,
1595
+ maxOutputTokens,
1596
+ temperature,
1597
+ topP,
1598
+ topK,
1599
+ frequencyPenalty,
1600
+ presencePenalty,
1601
+ stopSequences,
1602
+ responseFormat,
1603
+ seed,
1604
+ tools,
1605
+ toolChoice,
1606
+ reasoning,
1607
+ providerOptions
1608
+ },
1609
+ isStreaming = false
1610
+ }) {
1606
1611
  var _a, _b, _c;
1607
1612
  const warnings = [];
1608
- const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
1613
+ const providerOptionsNames = config.provider.includes(
1614
+ "vertex"
1615
+ ) ? ["googleVertex", "vertex"] : ["google"];
1609
1616
  let googleOptions;
1610
1617
  for (const name of providerOptionsNames) {
1611
1618
  googleOptions = await parseProviderOptions({
@@ -1622,19 +1629,19 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1622
1629
  schema: googleLanguageModelOptions
1623
1630
  });
1624
1631
  }
1625
- const isVertexProvider = this.config.provider.startsWith("google.vertex.");
1632
+ const isVertexProvider = config.provider.startsWith("google.vertex.");
1626
1633
  if ((tools == null ? void 0 : tools.some(
1627
1634
  (tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
1628
1635
  )) && !isVertexProvider) {
1629
1636
  warnings.push({
1630
1637
  type: "other",
1631
- message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
1638
+ message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${config.provider}).`
1632
1639
  });
1633
1640
  }
1634
1641
  if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
1635
1642
  warnings.push({
1636
1643
  type: "other",
1637
- message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1644
+ message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1638
1645
  });
1639
1646
  }
1640
1647
  if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
@@ -1646,7 +1653,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1646
1653
  if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1647
1654
  warnings.push({
1648
1655
  type: "other",
1649
- message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
1656
+ message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${config.provider}).`
1650
1657
  });
1651
1658
  }
1652
1659
  const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
@@ -1674,13 +1681,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1674
1681
  if (droppedImageConfigFields.length > 0) {
1675
1682
  warnings.push({
1676
1683
  type: "other",
1677
- message: `${droppedImageConfigFields.join(", ")} ${droppedImageConfigFields.length === 1 ? "is a Vertex AI option and is" : "are Vertex AI options and are"} ignored with the current Google provider (${this.config.provider}).`
1684
+ message: `${droppedImageConfigFields.join(", ")} ${droppedImageConfigFields.length === 1 ? "is a Vertex AI option and is" : "are Vertex AI options and are"} ignored with the current Google provider (${config.provider}).`
1678
1685
  });
1679
1686
  imageConfig = geminiApiImageConfig;
1680
1687
  }
1681
1688
  }
1682
- const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1683
- const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
1689
+ const isGemmaModel = modelId.toLowerCase().startsWith("gemma-");
1690
+ const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(modelId);
1684
1691
  if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
1685
1692
  warnings.push({
1686
1693
  type: "unsupported",
@@ -1693,7 +1700,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1693
1700
  feature: "presencePenalty"
1694
1701
  });
1695
1702
  }
1696
- const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1703
+ const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
1697
1704
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1698
1705
  isGemmaModel,
1699
1706
  isGemini3Model: usesGemini3Features,
@@ -1709,7 +1716,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1709
1716
  } = prepareTools({
1710
1717
  tools,
1711
1718
  toolChoice,
1712
- modelId: this.modelId,
1719
+ modelId,
1713
1720
  isVertexProvider
1714
1721
  });
1715
1722
  const toolNameMapping = createToolNameMapping({
@@ -1720,7 +1727,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1720
1727
  });
1721
1728
  const resolvedThinking = resolveThinkingConfig({
1722
1729
  reasoning,
1723
- modelId: this.modelId,
1730
+ modelId,
1724
1731
  warnings
1725
1732
  });
1726
1733
  const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
@@ -1786,7 +1793,16 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1786
1793
  toolNameMapping
1787
1794
  };
1788
1795
  }
1789
- convertGenerateContentResponse({
1796
+ getArgs(options, { isStreaming = false } = {}) {
1797
+ return _GoogleLanguageModel.prepareRequest({
1798
+ modelId: this.modelId,
1799
+ config: this.config,
1800
+ options,
1801
+ isStreaming
1802
+ });
1803
+ }
1804
+ static convertGenerateContentResponse({
1805
+ config,
1790
1806
  response,
1791
1807
  warnings,
1792
1808
  providerOptionsNames,
@@ -1807,7 +1823,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1807
1823
  let lastServerToolCallId;
1808
1824
  for (const part of parts) {
1809
1825
  if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
1810
- const toolCallId = this.config.generateId();
1826
+ const toolCallId = config.generateId();
1811
1827
  lastCodeExecutionToolCallId = toolCallId;
1812
1828
  content.push({
1813
1829
  type: "tool-call",
@@ -1846,7 +1862,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1846
1862
  } else if ("functionCall" in part && part.functionCall.name != null) {
1847
1863
  content.push({
1848
1864
  type: "tool-call",
1849
- toolCallId: part.functionCall.id || this.config.generateId(),
1865
+ toolCallId: part.functionCall.id || config.generateId(),
1850
1866
  toolName: part.functionCall.name,
1851
1867
  input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
1852
1868
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1865,7 +1881,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1865
1881
  }) : void 0
1866
1882
  });
1867
1883
  } else if ("toolCall" in part && part.toolCall) {
1868
- const toolCallId = part.toolCall.id || this.config.generateId();
1884
+ const toolCallId = part.toolCall.id || config.generateId();
1869
1885
  lastServerToolCallId = toolCallId;
1870
1886
  content.push({
1871
1887
  type: "tool-call",
@@ -1884,7 +1900,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1884
1900
  })
1885
1901
  });
1886
1902
  } else if ("toolResponse" in part && part.toolResponse) {
1887
- const responseToolCallId = lastServerToolCallId || part.toolResponse.id || this.config.generateId();
1903
+ const responseToolCallId = lastServerToolCallId || part.toolResponse.id || config.generateId();
1888
1904
  content.push({
1889
1905
  type: "tool-result",
1890
1906
  toolCallId: responseToolCallId,
@@ -1904,7 +1920,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1904
1920
  }
1905
1921
  const sources = (_n = extractSources({
1906
1922
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1907
- generateId: this.config.generateId
1923
+ generateId: config.generateId
1908
1924
  })) != null ? _n : [];
1909
1925
  for (const source of sources) {
1910
1926
  content.push(source);
@@ -1966,7 +1982,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1966
1982
  abortSignal: options.abortSignal,
1967
1983
  fetch: this.config.fetch
1968
1984
  });
1969
- const result = this.convertGenerateContentResponse({
1985
+ const result = _GoogleLanguageModel.convertGenerateContentResponse({
1986
+ config: this.config,
1970
1987
  response,
1971
1988
  warnings,
1972
1989
  providerOptionsNames,