@ai-sdk/google 3.0.72 → 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/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.72" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.74" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -60,6 +60,12 @@ var googleEmbeddingContentPartSchema = z2.union([
60
60
  mimeType: z2.string(),
61
61
  data: z2.string()
62
62
  })
63
+ }),
64
+ z2.object({
65
+ fileData: z2.object({
66
+ fileUri: z2.string(),
67
+ mimeType: z2.string()
68
+ })
63
69
  })
64
70
  ]);
65
71
  var googleEmbeddingModelOptions = lazySchema2(
@@ -429,7 +435,7 @@ function convertUrlToolResultPart(url) {
429
435
  }
430
436
  };
431
437
  }
432
- function appendToolResultParts(parts, toolName, outputValue) {
438
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
433
439
  const functionResponseParts = [];
434
440
  const responseTextParts = [];
435
441
  for (const contentPart of outputValue) {
@@ -468,6 +474,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
468
474
  }
469
475
  parts.push({
470
476
  functionResponse: {
477
+ ...toolCallId != null ? { id: toolCallId } : {},
471
478
  name: toolName,
472
479
  response: {
473
480
  name: toolName,
@@ -477,12 +484,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
477
484
  }
478
485
  });
479
486
  }
480
- function appendLegacyToolResultParts(parts, toolName, outputValue) {
487
+ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
481
488
  for (const contentPart of outputValue) {
482
489
  switch (contentPart.type) {
483
490
  case "text":
484
491
  parts.push({
485
492
  functionResponse: {
493
+ ...toolCallId != null ? { id: toolCallId } : {},
486
494
  name: toolName,
487
495
  response: {
488
496
  name: toolName,
@@ -612,6 +620,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
612
620
  }
613
621
  return {
614
622
  functionCall: {
623
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
615
624
  name: part.toolName,
616
625
  args: part.input
617
626
  },
@@ -668,13 +677,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
668
677
  const output = part.output;
669
678
  if (output.type === "content") {
670
679
  if (supportsFunctionResponseParts) {
671
- appendToolResultParts(parts, part.toolName, output.value);
680
+ appendToolResultParts(
681
+ parts,
682
+ part.toolName,
683
+ output.value,
684
+ part.toolCallId
685
+ );
672
686
  } else {
673
- appendLegacyToolResultParts(parts, part.toolName, output.value);
687
+ appendLegacyToolResultParts(
688
+ parts,
689
+ part.toolName,
690
+ output.value,
691
+ part.toolCallId
692
+ );
674
693
  }
675
694
  } else {
676
695
  parts.push({
677
696
  functionResponse: {
697
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
678
698
  name: part.toolName,
679
699
  response: {
680
700
  name: part.toolName,
@@ -1499,7 +1519,7 @@ var GoogleGenerativeAILanguageModel = class {
1499
1519
  };
1500
1520
  }
1501
1521
  async doGenerate(options) {
1502
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1522
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1503
1523
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1504
1524
  const mergedHeaders = combineHeaders2(
1505
1525
  await resolve2(this.config.headers),
@@ -1570,9 +1590,9 @@ var GoogleGenerativeAILanguageModel = class {
1570
1590
  } else if ("functionCall" in part && part.functionCall.name != null) {
1571
1591
  content.push({
1572
1592
  type: "tool-call",
1573
- toolCallId: this.config.generateId(),
1593
+ toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
1574
1594
  toolName: part.functionCall.name,
1575
- input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1595
+ input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
1576
1596
  providerMetadata: part.thoughtSignature ? {
1577
1597
  [providerOptionsName]: {
1578
1598
  thoughtSignature: part.thoughtSignature
@@ -1594,13 +1614,13 @@ var GoogleGenerativeAILanguageModel = class {
1594
1614
  } : void 0
1595
1615
  });
1596
1616
  } else if ("toolCall" in part && part.toolCall) {
1597
- const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
1617
+ const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
1598
1618
  lastServerToolCallId = toolCallId;
1599
1619
  content.push({
1600
1620
  type: "tool-call",
1601
1621
  toolCallId,
1602
1622
  toolName: `server:${part.toolCall.toolType}`,
1603
- input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
1623
+ input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
1604
1624
  providerExecuted: true,
1605
1625
  dynamic: true,
1606
1626
  providerMetadata: part.thoughtSignature ? {
@@ -1617,12 +1637,12 @@ var GoogleGenerativeAILanguageModel = class {
1617
1637
  }
1618
1638
  });
1619
1639
  } else if ("toolResponse" in part && part.toolResponse) {
1620
- const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
1640
+ const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
1621
1641
  content.push({
1622
1642
  type: "tool-result",
1623
1643
  toolCallId: responseToolCallId,
1624
1644
  toolName: `server:${part.toolResponse.toolType}`,
1625
- result: (_i = part.toolResponse.response) != null ? _i : {},
1645
+ result: (_j = part.toolResponse.response) != null ? _j : {},
1626
1646
  providerMetadata: part.thoughtSignature ? {
1627
1647
  [providerOptionsName]: {
1628
1648
  thoughtSignature: part.thoughtSignature,
@@ -1639,10 +1659,10 @@ var GoogleGenerativeAILanguageModel = class {
1639
1659
  lastServerToolCallId = void 0;
1640
1660
  }
1641
1661
  }
1642
- const sources = (_j = extractSources({
1662
+ const sources = (_k = extractSources({
1643
1663
  groundingMetadata: candidate.groundingMetadata,
1644
1664
  generateId: this.config.generateId
1645
- })) != null ? _j : [];
1665
+ })) != null ? _k : [];
1646
1666
  for (const source of sources) {
1647
1667
  content.push(source);
1648
1668
  }
@@ -1656,19 +1676,19 @@ var GoogleGenerativeAILanguageModel = class {
1656
1676
  (part) => part.type === "tool-call" && !part.providerExecuted
1657
1677
  )
1658
1678
  }),
1659
- raw: (_k = candidate.finishReason) != null ? _k : void 0
1679
+ raw: (_l = candidate.finishReason) != null ? _l : void 0
1660
1680
  },
1661
1681
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1662
1682
  warnings,
1663
1683
  providerMetadata: {
1664
1684
  [providerOptionsName]: {
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,
1685
+ promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1686
+ groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
1687
+ urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
1688
+ safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1669
1689
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1670
- finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
1671
- serviceTier: (_q = response.serviceTier) != null ? _q : null
1690
+ finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1691
+ serviceTier: (_r = response.serviceTier) != null ? _r : null
1672
1692
  }
1673
1693
  },
1674
1694
  request: { body: args },
@@ -1724,7 +1744,7 @@ var GoogleGenerativeAILanguageModel = class {
1724
1744
  controller.enqueue({ type: "stream-start", warnings });
1725
1745
  },
1726
1746
  transform(chunk, controller) {
1727
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1747
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1728
1748
  if (options.includeRawChunks) {
1729
1749
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1730
1750
  }
@@ -1930,7 +1950,7 @@ var GoogleGenerativeAILanguageModel = class {
1930
1950
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1931
1951
  if (isStreamingChunk) {
1932
1952
  if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1933
- const toolCallId = generateId3();
1953
+ const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
1934
1954
  const accumulator = new GoogleJSONAccumulator();
1935
1955
  activeStreamingToolCalls.push({
1936
1956
  toolCallId,
@@ -1996,9 +2016,9 @@ var GoogleGenerativeAILanguageModel = class {
1996
2016
  });
1997
2017
  hasToolCalls = true;
1998
2018
  } else if (isCompleteCall) {
1999
- const toolCallId = generateId3();
2019
+ const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
2000
2020
  const toolName = part.functionCall.name;
2001
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
2021
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
2002
2022
  controller.enqueue({
2003
2023
  type: "tool-input-start",
2004
2024
  id: toolCallId,
@@ -2025,7 +2045,7 @@ var GoogleGenerativeAILanguageModel = class {
2025
2045
  });
2026
2046
  hasToolCalls = true;
2027
2047
  } else if (isNoArgsCompleteCall) {
2028
- const toolCallId = generateId3();
2048
+ const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
2029
2049
  const toolName = part.functionCall.name;
2030
2050
  controller.enqueue({
2031
2051
  type: "tool-input-start",
@@ -2059,12 +2079,12 @@ var GoogleGenerativeAILanguageModel = class {
2059
2079
  };
2060
2080
  providerMetadata = {
2061
2081
  [providerOptionsName]: {
2062
- promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
2082
+ promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
2063
2083
  groundingMetadata: lastGroundingMetadata,
2064
2084
  urlContextMetadata: lastUrlContextMetadata,
2065
- safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
2085
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
2066
2086
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2067
- finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
2087
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
2068
2088
  serviceTier
2069
2089
  }
2070
2090
  };
@@ -2254,6 +2274,7 @@ var getContentSchema = () => z5.object({
2254
2274
  // note: order matters since text can be fully empty
2255
2275
  z5.object({
2256
2276
  functionCall: z5.object({
2277
+ id: z5.string().nullish(),
2257
2278
  name: z5.string().nullish(),
2258
2279
  args: z5.unknown().nullish(),
2259
2280
  partialArgs: z5.array(partialArgSchema).nullish(),