@ai-sdk/google 3.0.73 → 3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.74
4
+
5
+ ### Patch Changes
6
+
7
+ - 3ca0daa: fix(provider/google): support `functionCall.id` when returned by Gemini API and provide matching `functionResponse.id`
8
+
3
9
  ## 3.0.73
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -49,6 +49,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
49
49
  content?: Record<string, never> | {
50
50
  parts?: ({
51
51
  functionCall: {
52
+ id?: string | null | undefined;
52
53
  name?: string | null | undefined;
53
54
  args?: unknown;
54
55
  partialArgs?: {
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
49
49
  content?: Record<string, never> | {
50
50
  parts?: ({
51
51
  functionCall: {
52
+ id?: string | null | undefined;
52
53
  name?: string | null | undefined;
53
54
  args?: unknown;
54
55
  partialArgs?: {
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
30
30
  var import_provider_utils23 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.73" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.74" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -429,7 +429,7 @@ function convertUrlToolResultPart(url) {
429
429
  }
430
430
  };
431
431
  }
432
- function appendToolResultParts(parts, toolName, outputValue) {
432
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
433
433
  const functionResponseParts = [];
434
434
  const responseTextParts = [];
435
435
  for (const contentPart of outputValue) {
@@ -468,6 +468,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
468
468
  }
469
469
  parts.push({
470
470
  functionResponse: {
471
+ ...toolCallId != null ? { id: toolCallId } : {},
471
472
  name: toolName,
472
473
  response: {
473
474
  name: toolName,
@@ -477,12 +478,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
477
478
  }
478
479
  });
479
480
  }
480
- function appendLegacyToolResultParts(parts, toolName, outputValue) {
481
+ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
481
482
  for (const contentPart of outputValue) {
482
483
  switch (contentPart.type) {
483
484
  case "text":
484
485
  parts.push({
485
486
  functionResponse: {
487
+ ...toolCallId != null ? { id: toolCallId } : {},
486
488
  name: toolName,
487
489
  response: {
488
490
  name: toolName,
@@ -612,6 +614,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
612
614
  }
613
615
  return {
614
616
  functionCall: {
617
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
615
618
  name: part.toolName,
616
619
  args: part.input
617
620
  },
@@ -668,13 +671,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
668
671
  const output = part.output;
669
672
  if (output.type === "content") {
670
673
  if (supportsFunctionResponseParts) {
671
- appendToolResultParts(parts, part.toolName, output.value);
674
+ appendToolResultParts(
675
+ parts,
676
+ part.toolName,
677
+ output.value,
678
+ part.toolCallId
679
+ );
672
680
  } else {
673
- appendLegacyToolResultParts(parts, part.toolName, output.value);
681
+ appendLegacyToolResultParts(
682
+ parts,
683
+ part.toolName,
684
+ output.value,
685
+ part.toolCallId
686
+ );
674
687
  }
675
688
  } else {
676
689
  parts.push({
677
690
  functionResponse: {
691
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
678
692
  name: part.toolName,
679
693
  response: {
680
694
  name: part.toolName,
@@ -1494,7 +1508,7 @@ var GoogleGenerativeAILanguageModel = class {
1494
1508
  };
1495
1509
  }
1496
1510
  async doGenerate(options) {
1497
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1511
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1498
1512
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1499
1513
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1500
1514
  await (0, import_provider_utils6.resolve)(this.config.headers),
@@ -1565,9 +1579,9 @@ var GoogleGenerativeAILanguageModel = class {
1565
1579
  } else if ("functionCall" in part && part.functionCall.name != null) {
1566
1580
  content.push({
1567
1581
  type: "tool-call",
1568
- toolCallId: this.config.generateId(),
1582
+ toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
1569
1583
  toolName: part.functionCall.name,
1570
- input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1584
+ input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
1571
1585
  providerMetadata: part.thoughtSignature ? {
1572
1586
  [providerOptionsName]: {
1573
1587
  thoughtSignature: part.thoughtSignature
@@ -1589,13 +1603,13 @@ var GoogleGenerativeAILanguageModel = class {
1589
1603
  } : void 0
1590
1604
  });
1591
1605
  } else if ("toolCall" in part && part.toolCall) {
1592
- const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
1606
+ const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
1593
1607
  lastServerToolCallId = toolCallId;
1594
1608
  content.push({
1595
1609
  type: "tool-call",
1596
1610
  toolCallId,
1597
1611
  toolName: `server:${part.toolCall.toolType}`,
1598
- input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
1612
+ input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
1599
1613
  providerExecuted: true,
1600
1614
  dynamic: true,
1601
1615
  providerMetadata: part.thoughtSignature ? {
@@ -1612,12 +1626,12 @@ var GoogleGenerativeAILanguageModel = class {
1612
1626
  }
1613
1627
  });
1614
1628
  } else if ("toolResponse" in part && part.toolResponse) {
1615
- const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
1629
+ const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
1616
1630
  content.push({
1617
1631
  type: "tool-result",
1618
1632
  toolCallId: responseToolCallId,
1619
1633
  toolName: `server:${part.toolResponse.toolType}`,
1620
- result: (_i = part.toolResponse.response) != null ? _i : {},
1634
+ result: (_j = part.toolResponse.response) != null ? _j : {},
1621
1635
  providerMetadata: part.thoughtSignature ? {
1622
1636
  [providerOptionsName]: {
1623
1637
  thoughtSignature: part.thoughtSignature,
@@ -1634,10 +1648,10 @@ var GoogleGenerativeAILanguageModel = class {
1634
1648
  lastServerToolCallId = void 0;
1635
1649
  }
1636
1650
  }
1637
- const sources = (_j = extractSources({
1651
+ const sources = (_k = extractSources({
1638
1652
  groundingMetadata: candidate.groundingMetadata,
1639
1653
  generateId: this.config.generateId
1640
- })) != null ? _j : [];
1654
+ })) != null ? _k : [];
1641
1655
  for (const source of sources) {
1642
1656
  content.push(source);
1643
1657
  }
@@ -1651,19 +1665,19 @@ var GoogleGenerativeAILanguageModel = class {
1651
1665
  (part) => part.type === "tool-call" && !part.providerExecuted
1652
1666
  )
1653
1667
  }),
1654
- raw: (_k = candidate.finishReason) != null ? _k : void 0
1668
+ raw: (_l = candidate.finishReason) != null ? _l : void 0
1655
1669
  },
1656
1670
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1657
1671
  warnings,
1658
1672
  providerMetadata: {
1659
1673
  [providerOptionsName]: {
1660
- promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
1661
- groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
1662
- urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
1663
- safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1674
+ promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1675
+ groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
1676
+ urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
1677
+ safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1664
1678
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1665
- finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
1666
- serviceTier: (_q = response.serviceTier) != null ? _q : null
1679
+ finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1680
+ serviceTier: (_r = response.serviceTier) != null ? _r : null
1667
1681
  }
1668
1682
  },
1669
1683
  request: { body: args },
@@ -1719,7 +1733,7 @@ var GoogleGenerativeAILanguageModel = class {
1719
1733
  controller.enqueue({ type: "stream-start", warnings });
1720
1734
  },
1721
1735
  transform(chunk, controller) {
1722
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1736
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1723
1737
  if (options.includeRawChunks) {
1724
1738
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1725
1739
  }
@@ -1925,7 +1939,7 @@ var GoogleGenerativeAILanguageModel = class {
1925
1939
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1926
1940
  if (isStreamingChunk) {
1927
1941
  if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1928
- const toolCallId = generateId3();
1942
+ const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
1929
1943
  const accumulator = new GoogleJSONAccumulator();
1930
1944
  activeStreamingToolCalls.push({
1931
1945
  toolCallId,
@@ -1991,9 +2005,9 @@ var GoogleGenerativeAILanguageModel = class {
1991
2005
  });
1992
2006
  hasToolCalls = true;
1993
2007
  } else if (isCompleteCall) {
1994
- const toolCallId = generateId3();
2008
+ const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
1995
2009
  const toolName = part.functionCall.name;
1996
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
2010
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
1997
2011
  controller.enqueue({
1998
2012
  type: "tool-input-start",
1999
2013
  id: toolCallId,
@@ -2020,7 +2034,7 @@ var GoogleGenerativeAILanguageModel = class {
2020
2034
  });
2021
2035
  hasToolCalls = true;
2022
2036
  } else if (isNoArgsCompleteCall) {
2023
- const toolCallId = generateId3();
2037
+ const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
2024
2038
  const toolName = part.functionCall.name;
2025
2039
  controller.enqueue({
2026
2040
  type: "tool-input-start",
@@ -2054,12 +2068,12 @@ var GoogleGenerativeAILanguageModel = class {
2054
2068
  };
2055
2069
  providerMetadata = {
2056
2070
  [providerOptionsName]: {
2057
- promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
2071
+ promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
2058
2072
  groundingMetadata: lastGroundingMetadata,
2059
2073
  urlContextMetadata: lastUrlContextMetadata,
2060
- safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
2074
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
2061
2075
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2062
- finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
2076
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
2063
2077
  serviceTier
2064
2078
  }
2065
2079
  };
@@ -2249,6 +2263,7 @@ var getContentSchema = () => import_v45.z.object({
2249
2263
  // note: order matters since text can be fully empty
2250
2264
  import_v45.z.object({
2251
2265
  functionCall: import_v45.z.object({
2266
+ id: import_v45.z.string().nullish(),
2252
2267
  name: import_v45.z.string().nullish(),
2253
2268
  args: import_v45.z.unknown().nullish(),
2254
2269
  partialArgs: import_v45.z.array(partialArgSchema).nullish(),