@ai-sdk/google 4.0.0-canary.63 → 4.0.0-canary.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.
@@ -94,6 +94,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
94
94
  content?: Record<string, never> | {
95
95
  parts?: ({
96
96
  functionCall: {
97
+ id?: string | null | undefined;
97
98
  name?: string | null | undefined;
98
99
  args?: unknown;
99
100
  partialArgs?: {
@@ -207,7 +207,7 @@ function convertUrlToolResultPart(url) {
207
207
  }
208
208
  };
209
209
  }
210
- function appendToolResultParts(parts, toolName, outputValue) {
210
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
211
211
  const functionResponseParts = [];
212
212
  const responseTextParts = [];
213
213
  for (const contentPart of outputValue) {
@@ -246,6 +246,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
246
246
  }
247
247
  parts.push({
248
248
  functionResponse: {
249
+ ...toolCallId != null ? { id: toolCallId } : {},
249
250
  name: toolName,
250
251
  response: {
251
252
  name: toolName,
@@ -255,12 +256,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
255
256
  }
256
257
  });
257
258
  }
258
- function appendLegacyToolResultParts(parts, toolName, outputValue) {
259
+ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
259
260
  for (const contentPart of outputValue) {
260
261
  switch (contentPart.type) {
261
262
  case "text":
262
263
  parts.push({
263
264
  functionResponse: {
265
+ ...toolCallId != null ? { id: toolCallId } : {},
264
266
  name: toolName,
265
267
  response: {
266
268
  name: toolName,
@@ -495,6 +497,7 @@ function convertToGoogleMessages(prompt, options) {
495
497
  }
496
498
  return {
497
499
  functionCall: {
500
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
498
501
  name: part.toolName,
499
502
  args: part.input
500
503
  },
@@ -551,13 +554,24 @@ function convertToGoogleMessages(prompt, options) {
551
554
  const output = part.output;
552
555
  if (output.type === "content") {
553
556
  if (supportsFunctionResponseParts) {
554
- appendToolResultParts(parts, part.toolName, output.value);
557
+ appendToolResultParts(
558
+ parts,
559
+ part.toolName,
560
+ output.value,
561
+ part.toolCallId
562
+ );
555
563
  } else {
556
- appendLegacyToolResultParts(parts, part.toolName, output.value);
564
+ appendLegacyToolResultParts(
565
+ parts,
566
+ part.toolName,
567
+ output.value,
568
+ part.toolCallId
569
+ );
557
570
  }
558
571
  } else {
559
572
  parts.push({
560
573
  functionResponse: {
574
+ ...part.toolCallId != null ? { id: part.toolCallId } : {},
561
575
  name: part.toolName,
562
576
  response: {
563
577
  name: part.toolName,
@@ -1422,7 +1436,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1422
1436
  };
1423
1437
  }
1424
1438
  async doGenerate(options) {
1425
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1439
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1426
1440
  const { args, warnings, providerOptionsNames } = await this.getArgs(options);
1427
1441
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1428
1442
  providerOptionsNames.map((name) => [name, payload])
@@ -1494,9 +1508,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1494
1508
  } else if ("functionCall" in part && part.functionCall.name != null) {
1495
1509
  content.push({
1496
1510
  type: "tool-call",
1497
- toolCallId: this.config.generateId(),
1511
+ toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
1498
1512
  toolName: part.functionCall.name,
1499
- input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1513
+ input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
1500
1514
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1501
1515
  thoughtSignature: part.thoughtSignature
1502
1516
  }) : void 0
@@ -1513,13 +1527,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1513
1527
  }) : void 0
1514
1528
  });
1515
1529
  } else if ("toolCall" in part && part.toolCall) {
1516
- const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
1530
+ const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
1517
1531
  lastServerToolCallId = toolCallId;
1518
1532
  content.push({
1519
1533
  type: "tool-call",
1520
1534
  toolCallId,
1521
1535
  toolName: `server:${part.toolCall.toolType}`,
1522
- input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
1536
+ input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
1523
1537
  providerExecuted: true,
1524
1538
  dynamic: true,
1525
1539
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1532,12 +1546,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1532
1546
  })
1533
1547
  });
1534
1548
  } else if ("toolResponse" in part && part.toolResponse) {
1535
- const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
1549
+ const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
1536
1550
  content.push({
1537
1551
  type: "tool-result",
1538
1552
  toolCallId: responseToolCallId,
1539
1553
  toolName: `server:${part.toolResponse.toolType}`,
1540
- result: (_i = part.toolResponse.response) != null ? _i : {},
1554
+ result: (_j = part.toolResponse.response) != null ? _j : {},
1541
1555
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1542
1556
  thoughtSignature: part.thoughtSignature,
1543
1557
  serverToolCallId: responseToolCallId,
@@ -1550,10 +1564,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1550
1564
  lastServerToolCallId = void 0;
1551
1565
  }
1552
1566
  }
1553
- const sources = (_j = extractSources({
1567
+ const sources = (_k = extractSources({
1554
1568
  groundingMetadata: candidate.groundingMetadata,
1555
1569
  generateId: this.config.generateId
1556
- })) != null ? _j : [];
1570
+ })) != null ? _k : [];
1557
1571
  for (const source of sources) {
1558
1572
  content.push(source);
1559
1573
  }
@@ -1567,18 +1581,18 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1567
1581
  (part) => part.type === "tool-call" && !part.providerExecuted
1568
1582
  )
1569
1583
  }),
1570
- raw: (_k = candidate.finishReason) != null ? _k : void 0
1584
+ raw: (_l = candidate.finishReason) != null ? _l : void 0
1571
1585
  },
1572
1586
  usage: convertGoogleUsage(usageMetadata),
1573
1587
  warnings,
1574
1588
  providerMetadata: wrapProviderMetadata({
1575
- promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
1576
- groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
1577
- urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
1578
- safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1589
+ promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1590
+ groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
1591
+ urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
1592
+ safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1579
1593
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1580
- finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
1581
- serviceTier: (_q = response.serviceTier) != null ? _q : null
1594
+ finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1595
+ serviceTier: (_r = response.serviceTier) != null ? _r : null
1582
1596
  }),
1583
1597
  request: { body: args },
1584
1598
  response: {
@@ -1636,7 +1650,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1636
1650
  controller.enqueue({ type: "stream-start", warnings });
1637
1651
  },
1638
1652
  transform(chunk, controller) {
1639
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1653
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1640
1654
  if (options.includeRawChunks) {
1641
1655
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1642
1656
  }
@@ -1831,7 +1845,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1831
1845
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1832
1846
  if (isStreamingChunk) {
1833
1847
  if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1834
- const toolCallId = generateId2();
1848
+ const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
1835
1849
  const accumulator = new GoogleJSONAccumulator();
1836
1850
  activeStreamingToolCalls.push({
1837
1851
  toolCallId,
@@ -1897,9 +1911,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1897
1911
  });
1898
1912
  hasToolCalls = true;
1899
1913
  } else if (isCompleteCall) {
1900
- const toolCallId = generateId2();
1914
+ const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
1901
1915
  const toolName = part.functionCall.name;
1902
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
1916
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
1903
1917
  controller.enqueue({
1904
1918
  type: "tool-input-start",
1905
1919
  id: toolCallId,
@@ -1926,7 +1940,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1926
1940
  });
1927
1941
  hasToolCalls = true;
1928
1942
  } else if (isNoArgsCompleteCall) {
1929
- const toolCallId = generateId2();
1943
+ const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
1930
1944
  const toolName = part.functionCall.name;
1931
1945
  controller.enqueue({
1932
1946
  type: "tool-input-start",
@@ -1959,12 +1973,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1959
1973
  raw: candidate.finishReason
1960
1974
  };
1961
1975
  providerMetadata = wrapProviderMetadata({
1962
- promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
1976
+ promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
1963
1977
  groundingMetadata: lastGroundingMetadata,
1964
1978
  urlContextMetadata: lastUrlContextMetadata,
1965
- safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
1979
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1966
1980
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1967
- finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
1981
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1968
1982
  serviceTier
1969
1983
  });
1970
1984
  }
@@ -2222,6 +2236,7 @@ var getContentSchema = () => z3.object({
2222
2236
  // note: order matters since text can be fully empty
2223
2237
  z3.object({
2224
2238
  functionCall: z3.object({
2239
+ id: z3.string().nullish(),
2225
2240
  name: z3.string().nullish(),
2226
2241
  args: z3.unknown().nullish(),
2227
2242
  partialArgs: z3.array(partialArgSchema).nullish(),