@ai-sdk/google 3.0.68 → 3.0.71

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.
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.68" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.71" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -859,7 +859,8 @@ import {
859
859
  function prepareTools({
860
860
  tools,
861
861
  toolChoice,
862
- modelId
862
+ modelId,
863
+ isVertexProvider = false
863
864
  }) {
864
865
  var _a, _b;
865
866
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -995,7 +996,9 @@ function prepareTools({
995
996
  }
996
997
  const combinedToolConfig = {
997
998
  functionCallingConfig: { mode: "VALIDATED" },
998
- includeServerSideToolInvocations: true
999
+ ...!isVertexProvider && {
1000
+ includeServerSideToolInvocations: true
1001
+ }
999
1002
  };
1000
1003
  if (toolChoice != null) {
1001
1004
  switch (toolChoice.type) {
@@ -1435,7 +1438,8 @@ var GoogleGenerativeAILanguageModel = class {
1435
1438
  } = prepareTools({
1436
1439
  tools,
1437
1440
  toolChoice,
1438
- modelId: this.modelId
1441
+ modelId: this.modelId,
1442
+ isVertexProvider
1439
1443
  });
1440
1444
  const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
1441
1445
  const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
@@ -1495,7 +1499,7 @@ var GoogleGenerativeAILanguageModel = class {
1495
1499
  };
1496
1500
  }
1497
1501
  async doGenerate(options) {
1498
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1502
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1499
1503
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1500
1504
  const mergedHeaders = combineHeaders2(
1501
1505
  await resolve2(this.config.headers),
@@ -1563,12 +1567,12 @@ var GoogleGenerativeAILanguageModel = class {
1563
1567
  providerMetadata: thoughtSignatureMetadata
1564
1568
  });
1565
1569
  }
1566
- } else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
1570
+ } else if ("functionCall" in part && part.functionCall.name != null) {
1567
1571
  content.push({
1568
1572
  type: "tool-call",
1569
1573
  toolCallId: this.config.generateId(),
1570
1574
  toolName: part.functionCall.name,
1571
- input: JSON.stringify(part.functionCall.args),
1575
+ input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1572
1576
  providerMetadata: part.thoughtSignature ? {
1573
1577
  [providerOptionsName]: {
1574
1578
  thoughtSignature: part.thoughtSignature
@@ -1590,13 +1594,13 @@ var GoogleGenerativeAILanguageModel = class {
1590
1594
  } : void 0
1591
1595
  });
1592
1596
  } else if ("toolCall" in part && part.toolCall) {
1593
- const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1597
+ const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
1594
1598
  lastServerToolCallId = toolCallId;
1595
1599
  content.push({
1596
1600
  type: "tool-call",
1597
1601
  toolCallId,
1598
1602
  toolName: `server:${part.toolCall.toolType}`,
1599
- input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1603
+ input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
1600
1604
  providerExecuted: true,
1601
1605
  dynamic: true,
1602
1606
  providerMetadata: part.thoughtSignature ? {
@@ -1613,12 +1617,12 @@ var GoogleGenerativeAILanguageModel = class {
1613
1617
  }
1614
1618
  });
1615
1619
  } else if ("toolResponse" in part && part.toolResponse) {
1616
- const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1620
+ const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
1617
1621
  content.push({
1618
1622
  type: "tool-result",
1619
1623
  toolCallId: responseToolCallId,
1620
1624
  toolName: `server:${part.toolResponse.toolType}`,
1621
- result: (_h = part.toolResponse.response) != null ? _h : {},
1625
+ result: (_i = part.toolResponse.response) != null ? _i : {},
1622
1626
  providerMetadata: part.thoughtSignature ? {
1623
1627
  [providerOptionsName]: {
1624
1628
  thoughtSignature: part.thoughtSignature,
@@ -1635,10 +1639,10 @@ var GoogleGenerativeAILanguageModel = class {
1635
1639
  lastServerToolCallId = void 0;
1636
1640
  }
1637
1641
  }
1638
- const sources = (_i = extractSources({
1642
+ const sources = (_j = extractSources({
1639
1643
  groundingMetadata: candidate.groundingMetadata,
1640
1644
  generateId: this.config.generateId
1641
- })) != null ? _i : [];
1645
+ })) != null ? _j : [];
1642
1646
  for (const source of sources) {
1643
1647
  content.push(source);
1644
1648
  }
@@ -1652,19 +1656,19 @@ var GoogleGenerativeAILanguageModel = class {
1652
1656
  (part) => part.type === "tool-call" && !part.providerExecuted
1653
1657
  )
1654
1658
  }),
1655
- raw: (_j = candidate.finishReason) != null ? _j : void 0
1659
+ raw: (_k = candidate.finishReason) != null ? _k : void 0
1656
1660
  },
1657
1661
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1658
1662
  warnings,
1659
1663
  providerMetadata: {
1660
1664
  [providerOptionsName]: {
1661
- promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1662
- groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1663
- urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1664
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1665
+ promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
1666
+ groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
1667
+ urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
1668
+ safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1665
1669
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1666
- finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1667
- serviceTier: (_p = response.serviceTier) != null ? _p : null
1670
+ finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
1671
+ serviceTier: (_q = response.serviceTier) != null ? _q : null
1668
1672
  }
1669
1673
  },
1670
1674
  request: { body: args },
@@ -1923,6 +1927,7 @@ var GoogleGenerativeAILanguageModel = class {
1923
1927
  const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
1924
1928
  const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
1925
1929
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
1930
+ const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1926
1931
  if (isStreamingChunk) {
1927
1932
  if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1928
1933
  const toolCallId = generateId3();
@@ -2019,6 +2024,28 @@ var GoogleGenerativeAILanguageModel = class {
2019
2024
  providerMetadata: providerMeta
2020
2025
  });
2021
2026
  hasToolCalls = true;
2027
+ } else if (isNoArgsCompleteCall) {
2028
+ const toolCallId = generateId3();
2029
+ const toolName = part.functionCall.name;
2030
+ controller.enqueue({
2031
+ type: "tool-input-start",
2032
+ id: toolCallId,
2033
+ toolName,
2034
+ providerMetadata: providerMeta
2035
+ });
2036
+ controller.enqueue({
2037
+ type: "tool-input-end",
2038
+ id: toolCallId,
2039
+ providerMetadata: providerMeta
2040
+ });
2041
+ controller.enqueue({
2042
+ type: "tool-call",
2043
+ toolCallId,
2044
+ toolName,
2045
+ input: "{}",
2046
+ providerMetadata: providerMeta
2047
+ });
2048
+ hasToolCalls = true;
2022
2049
  }
2023
2050
  }
2024
2051
  }
@@ -3808,6 +3835,15 @@ function convertToGoogleInteractionsInput({
3808
3835
  ...signature != null ? { signature } : {},
3809
3836
  summary: part.text.length > 0 ? [{ type: "text", text: part.text }] : void 0
3810
3837
  });
3838
+ } else if (part.type === "file") {
3839
+ const fileBlock = convertFilePartToContent({
3840
+ part,
3841
+ warnings,
3842
+ mediaResolution
3843
+ });
3844
+ if (fileBlock != null) {
3845
+ content.push(fileBlock);
3846
+ }
3811
3847
  } else if (part.type === "tool-call") {
3812
3848
  const signature = (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.signature;
3813
3849
  const args = typeof part.input === "string" ? safeParseToolArgs(part.input) : (_e = part.input) != null ? _e : {};