@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.
@@ -656,7 +656,8 @@ var import_provider2 = require("@ai-sdk/provider");
656
656
  function prepareTools({
657
657
  tools,
658
658
  toolChoice,
659
- modelId
659
+ modelId,
660
+ isVertexProvider = false
660
661
  }) {
661
662
  var _a, _b;
662
663
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -792,7 +793,9 @@ function prepareTools({
792
793
  }
793
794
  const combinedToolConfig = {
794
795
  functionCallingConfig: { mode: "VALIDATED" },
795
- includeServerSideToolInvocations: true
796
+ ...!isVertexProvider && {
797
+ includeServerSideToolInvocations: true
798
+ }
796
799
  };
797
800
  if (toolChoice != null) {
798
801
  switch (toolChoice.type) {
@@ -1232,7 +1235,8 @@ var GoogleGenerativeAILanguageModel = class {
1232
1235
  } = prepareTools({
1233
1236
  tools,
1234
1237
  toolChoice,
1235
- modelId: this.modelId
1238
+ modelId: this.modelId,
1239
+ isVertexProvider
1236
1240
  });
1237
1241
  const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
1238
1242
  const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
@@ -1292,7 +1296,7 @@ var GoogleGenerativeAILanguageModel = class {
1292
1296
  };
1293
1297
  }
1294
1298
  async doGenerate(options) {
1295
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1299
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1296
1300
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
1297
1301
  const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
1298
1302
  await (0, import_provider_utils4.resolve)(this.config.headers),
@@ -1360,12 +1364,12 @@ var GoogleGenerativeAILanguageModel = class {
1360
1364
  providerMetadata: thoughtSignatureMetadata
1361
1365
  });
1362
1366
  }
1363
- } else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
1367
+ } else if ("functionCall" in part && part.functionCall.name != null) {
1364
1368
  content.push({
1365
1369
  type: "tool-call",
1366
1370
  toolCallId: this.config.generateId(),
1367
1371
  toolName: part.functionCall.name,
1368
- input: JSON.stringify(part.functionCall.args),
1372
+ input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1369
1373
  providerMetadata: part.thoughtSignature ? {
1370
1374
  [providerOptionsName]: {
1371
1375
  thoughtSignature: part.thoughtSignature
@@ -1387,13 +1391,13 @@ var GoogleGenerativeAILanguageModel = class {
1387
1391
  } : void 0
1388
1392
  });
1389
1393
  } else if ("toolCall" in part && part.toolCall) {
1390
- const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1394
+ const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
1391
1395
  lastServerToolCallId = toolCallId;
1392
1396
  content.push({
1393
1397
  type: "tool-call",
1394
1398
  toolCallId,
1395
1399
  toolName: `server:${part.toolCall.toolType}`,
1396
- input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1400
+ input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
1397
1401
  providerExecuted: true,
1398
1402
  dynamic: true,
1399
1403
  providerMetadata: part.thoughtSignature ? {
@@ -1410,12 +1414,12 @@ var GoogleGenerativeAILanguageModel = class {
1410
1414
  }
1411
1415
  });
1412
1416
  } else if ("toolResponse" in part && part.toolResponse) {
1413
- const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1417
+ const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
1414
1418
  content.push({
1415
1419
  type: "tool-result",
1416
1420
  toolCallId: responseToolCallId,
1417
1421
  toolName: `server:${part.toolResponse.toolType}`,
1418
- result: (_h = part.toolResponse.response) != null ? _h : {},
1422
+ result: (_i = part.toolResponse.response) != null ? _i : {},
1419
1423
  providerMetadata: part.thoughtSignature ? {
1420
1424
  [providerOptionsName]: {
1421
1425
  thoughtSignature: part.thoughtSignature,
@@ -1432,10 +1436,10 @@ var GoogleGenerativeAILanguageModel = class {
1432
1436
  lastServerToolCallId = void 0;
1433
1437
  }
1434
1438
  }
1435
- const sources = (_i = extractSources({
1439
+ const sources = (_j = extractSources({
1436
1440
  groundingMetadata: candidate.groundingMetadata,
1437
1441
  generateId: this.config.generateId
1438
- })) != null ? _i : [];
1442
+ })) != null ? _j : [];
1439
1443
  for (const source of sources) {
1440
1444
  content.push(source);
1441
1445
  }
@@ -1449,19 +1453,19 @@ var GoogleGenerativeAILanguageModel = class {
1449
1453
  (part) => part.type === "tool-call" && !part.providerExecuted
1450
1454
  )
1451
1455
  }),
1452
- raw: (_j = candidate.finishReason) != null ? _j : void 0
1456
+ raw: (_k = candidate.finishReason) != null ? _k : void 0
1453
1457
  },
1454
1458
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
1455
1459
  warnings,
1456
1460
  providerMetadata: {
1457
1461
  [providerOptionsName]: {
1458
- promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1459
- groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1460
- urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1461
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1462
+ promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
1463
+ groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
1464
+ urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
1465
+ safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1462
1466
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1463
- finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1464
- serviceTier: (_p = response.serviceTier) != null ? _p : null
1467
+ finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
1468
+ serviceTier: (_q = response.serviceTier) != null ? _q : null
1465
1469
  }
1466
1470
  },
1467
1471
  request: { body: args },
@@ -1720,6 +1724,7 @@ var GoogleGenerativeAILanguageModel = class {
1720
1724
  const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
1721
1725
  const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
1722
1726
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
1727
+ const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1723
1728
  if (isStreamingChunk) {
1724
1729
  if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1725
1730
  const toolCallId = generateId2();
@@ -1816,6 +1821,28 @@ var GoogleGenerativeAILanguageModel = class {
1816
1821
  providerMetadata: providerMeta
1817
1822
  });
1818
1823
  hasToolCalls = true;
1824
+ } else if (isNoArgsCompleteCall) {
1825
+ const toolCallId = generateId2();
1826
+ const toolName = part.functionCall.name;
1827
+ controller.enqueue({
1828
+ type: "tool-input-start",
1829
+ id: toolCallId,
1830
+ toolName,
1831
+ providerMetadata: providerMeta
1832
+ });
1833
+ controller.enqueue({
1834
+ type: "tool-input-end",
1835
+ id: toolCallId,
1836
+ providerMetadata: providerMeta
1837
+ });
1838
+ controller.enqueue({
1839
+ type: "tool-call",
1840
+ toolCallId,
1841
+ toolName,
1842
+ input: "{}",
1843
+ providerMetadata: providerMeta
1844
+ });
1845
+ hasToolCalls = true;
1819
1846
  }
1820
1847
  }
1821
1848
  }