@ai-sdk/google 3.0.75 → 3.0.77

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.
@@ -643,17 +643,32 @@ var googleLanguageModelOptions = lazySchema2(
643
643
  */
644
644
  streamFunctionCallArguments: z2.boolean().optional(),
645
645
  /**
646
- * Optional. The service tier to use for the request.
646
+ * Optional. The service tier to use for the request. Sent as the
647
+ * `serviceTier` body field. Gemini API only.
647
648
  */
648
- serviceTier: z2.enum(["standard", "flex", "priority"]).optional()
649
+ serviceTier: z2.enum(["standard", "flex", "priority"]).optional(),
650
+ /**
651
+ * Optional. Vertex AI only. Sent as the
652
+ * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
653
+ * shared (PayGo) tier. With Provisioned Throughput allocated and
654
+ * `requestType` unset, the request falls back to this tier only if
655
+ * PT capacity is exhausted.
656
+ *
657
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
658
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
659
+ */
660
+ sharedRequestType: z2.enum(["priority", "flex", "standard"]).optional(),
661
+ /**
662
+ * Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
663
+ * request header. Set to `'shared'` together with `sharedRequestType`
664
+ * to bypass Provisioned Throughput entirely.
665
+ *
666
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
667
+ */
668
+ requestType: z2.enum(["shared"]).optional()
649
669
  })
650
670
  )
651
671
  );
652
- var VertexServiceTierMap = {
653
- standard: "SERVICE_TIER_STANDARD",
654
- flex: "SERVICE_TIER_FLEX",
655
- priority: "SERVICE_TIER_PRIORITY"
656
- };
657
672
 
658
673
  // src/google-prepare-tools.ts
659
674
  import {
@@ -1220,10 +1235,27 @@ var GoogleGenerativeAILanguageModel = class {
1220
1235
  message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1221
1236
  });
1222
1237
  }
1223
- let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
1224
1238
  if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
1225
- sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
1239
+ warnings.push({
1240
+ type: "other",
1241
+ message: "'serviceTier' is a Gemini API option and is not supported on Vertex AI. Use 'sharedRequestType' (and optionally 'requestType') instead. See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo"
1242
+ });
1226
1243
  }
1244
+ if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1245
+ warnings.push({
1246
+ type: "other",
1247
+ message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
1248
+ });
1249
+ }
1250
+ const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
1251
+ ...googleOptions.sharedRequestType && {
1252
+ "X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
1253
+ },
1254
+ ...googleOptions.requestType && {
1255
+ "X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
1256
+ }
1257
+ } : void 0;
1258
+ const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1227
1259
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1228
1260
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1229
1261
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
@@ -1295,18 +1327,20 @@ var GoogleGenerativeAILanguageModel = class {
1295
1327
  toolConfig,
1296
1328
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
1297
1329
  labels: googleOptions == null ? void 0 : googleOptions.labels,
1298
- serviceTier: sanitizedServiceTier
1330
+ serviceTier: bodyServiceTier
1299
1331
  },
1300
1332
  warnings: [...warnings, ...toolWarnings],
1301
- providerOptionsName
1333
+ providerOptionsName,
1334
+ extraHeaders: vertexPaygoHeaders
1302
1335
  };
1303
1336
  }
1304
1337
  async doGenerate(options) {
1305
1338
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1306
- const { args, warnings, providerOptionsName } = await this.getArgs(options);
1339
+ const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
1307
1340
  const mergedHeaders = combineHeaders(
1308
1341
  await resolve(this.config.headers),
1309
- options.headers
1342
+ options.headers,
1343
+ extraHeaders
1310
1344
  );
1311
1345
  const {
1312
1346
  responseHeaders,
@@ -1471,7 +1505,7 @@ var GoogleGenerativeAILanguageModel = class {
1471
1505
  safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1472
1506
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1473
1507
  finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1474
- serviceTier: (_r = response.serviceTier) != null ? _r : null
1508
+ serviceTier: (_r = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _r : null
1475
1509
  }
1476
1510
  },
1477
1511
  request: { body: args },
@@ -1483,13 +1517,12 @@ var GoogleGenerativeAILanguageModel = class {
1483
1517
  };
1484
1518
  }
1485
1519
  async doStream(options) {
1486
- const { args, warnings, providerOptionsName } = await this.getArgs(
1487
- options,
1488
- { isStreaming: true }
1489
- );
1520
+ var _a;
1521
+ const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
1490
1522
  const headers = combineHeaders(
1491
1523
  await resolve(this.config.headers),
1492
- options.headers
1524
+ options.headers,
1525
+ extraHeaders
1493
1526
  );
1494
1527
  const { responseHeaders, value: response } = await postJsonToApi({
1495
1528
  url: `${this.config.baseURL}/${getModelPath(
@@ -1510,7 +1543,7 @@ var GoogleGenerativeAILanguageModel = class {
1510
1543
  let providerMetadata = void 0;
1511
1544
  let lastGroundingMetadata = null;
1512
1545
  let lastUrlContextMetadata = null;
1513
- let serviceTier = null;
1546
+ const serviceTier = (_a = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _a : null;
1514
1547
  const generateId2 = this.config.generateId;
1515
1548
  let hasToolCalls = false;
1516
1549
  let currentTextBlockId = null;
@@ -1520,6 +1553,34 @@ var GoogleGenerativeAILanguageModel = class {
1520
1553
  let lastCodeExecutionToolCallId;
1521
1554
  let lastServerToolCallId;
1522
1555
  const activeStreamingToolCalls = [];
1556
+ const finishActiveStreamingToolCall = (controller) => {
1557
+ const active = activeStreamingToolCalls.pop();
1558
+ if (active == null) {
1559
+ return;
1560
+ }
1561
+ const { finalJSON, closingDelta } = active.accumulator.finalize();
1562
+ if (closingDelta.length > 0) {
1563
+ controller.enqueue({
1564
+ type: "tool-input-delta",
1565
+ id: active.toolCallId,
1566
+ delta: closingDelta,
1567
+ providerMetadata: active.providerMetadata
1568
+ });
1569
+ }
1570
+ controller.enqueue({
1571
+ type: "tool-input-end",
1572
+ id: active.toolCallId,
1573
+ providerMetadata: active.providerMetadata
1574
+ });
1575
+ controller.enqueue({
1576
+ type: "tool-call",
1577
+ toolCallId: active.toolCallId,
1578
+ toolName: active.toolName,
1579
+ input: finalJSON,
1580
+ providerMetadata: active.providerMetadata
1581
+ });
1582
+ hasToolCalls = true;
1583
+ };
1523
1584
  return {
1524
1585
  stream: response.pipeThrough(
1525
1586
  new TransformStream({
@@ -1527,7 +1588,7 @@ var GoogleGenerativeAILanguageModel = class {
1527
1588
  controller.enqueue({ type: "stream-start", warnings });
1528
1589
  },
1529
1590
  transform(chunk, controller) {
1530
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1591
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1531
1592
  if (options.includeRawChunks) {
1532
1593
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1533
1594
  }
@@ -1540,10 +1601,7 @@ var GoogleGenerativeAILanguageModel = class {
1540
1601
  if (usageMetadata != null) {
1541
1602
  usage = usageMetadata;
1542
1603
  }
1543
- if (value.serviceTier != null) {
1544
- serviceTier = value.serviceTier;
1545
- }
1546
- const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1604
+ const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
1547
1605
  if (candidate == null) {
1548
1606
  return;
1549
1607
  }
@@ -1732,7 +1790,7 @@ var GoogleGenerativeAILanguageModel = class {
1732
1790
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
1733
1791
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1734
1792
  if (isStreamingChunk) {
1735
- if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1793
+ if (part.functionCall.name != null) {
1736
1794
  const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
1737
1795
  const accumulator = new GoogleJSONAccumulator();
1738
1796
  activeStreamingToolCalls.push({
@@ -1748,9 +1806,8 @@ var GoogleGenerativeAILanguageModel = class {
1748
1806
  providerMetadata: providerMeta
1749
1807
  });
1750
1808
  if (part.functionCall.partialArgs != null) {
1751
- const { textDelta } = accumulator.processPartialArgs(
1752
- part.functionCall.partialArgs
1753
- );
1809
+ const partialArgs = part.functionCall.partialArgs;
1810
+ const { textDelta } = accumulator.processPartialArgs(partialArgs);
1754
1811
  if (textDelta.length > 0) {
1755
1812
  controller.enqueue({
1756
1813
  type: "tool-input-delta",
@@ -1759,12 +1816,14 @@ var GoogleGenerativeAILanguageModel = class {
1759
1816
  providerMetadata: providerMeta
1760
1817
  });
1761
1818
  }
1819
+ if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
1820
+ finishActiveStreamingToolCall(controller);
1821
+ }
1762
1822
  }
1763
1823
  } else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
1764
1824
  const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
1765
- const { textDelta } = active.accumulator.processPartialArgs(
1766
- part.functionCall.partialArgs
1767
- );
1825
+ const partialArgs = part.functionCall.partialArgs;
1826
+ const { textDelta } = active.accumulator.processPartialArgs(partialArgs);
1768
1827
  if (textDelta.length > 0) {
1769
1828
  controller.enqueue({
1770
1829
  type: "tool-input-delta",
@@ -1773,31 +1832,12 @@ var GoogleGenerativeAILanguageModel = class {
1773
1832
  providerMetadata: providerMeta
1774
1833
  });
1775
1834
  }
1835
+ if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
1836
+ finishActiveStreamingToolCall(controller);
1837
+ }
1776
1838
  }
1777
1839
  } else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
1778
- const active = activeStreamingToolCalls.pop();
1779
- const { finalJSON, closingDelta } = active.accumulator.finalize();
1780
- if (closingDelta.length > 0) {
1781
- controller.enqueue({
1782
- type: "tool-input-delta",
1783
- id: active.toolCallId,
1784
- delta: closingDelta,
1785
- providerMetadata: active.providerMetadata
1786
- });
1787
- }
1788
- controller.enqueue({
1789
- type: "tool-input-end",
1790
- id: active.toolCallId,
1791
- providerMetadata: active.providerMetadata
1792
- });
1793
- controller.enqueue({
1794
- type: "tool-call",
1795
- toolCallId: active.toolCallId,
1796
- toolName: active.toolName,
1797
- input: finalJSON,
1798
- providerMetadata: active.providerMetadata
1799
- });
1800
- hasToolCalls = true;
1840
+ finishActiveStreamingToolCall(controller);
1801
1841
  } else if (isCompleteCall) {
1802
1842
  const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
1803
1843
  const toolName = part.functionCall.name;
@@ -2156,8 +2196,7 @@ var responseSchema = lazySchema3(
2156
2196
  promptFeedback: z3.object({
2157
2197
  blockReason: z3.string().nullish(),
2158
2198
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2159
- }).nullish(),
2160
- serviceTier: z3.string().nullish()
2199
+ }).nullish()
2161
2200
  })
2162
2201
  )
2163
2202
  );
@@ -2178,8 +2217,7 @@ var chunkSchema = lazySchema3(
2178
2217
  promptFeedback: z3.object({
2179
2218
  blockReason: z3.string().nullish(),
2180
2219
  safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2181
- }).nullish(),
2182
- serviceTier: z3.string().nullish()
2220
+ }).nullish()
2183
2221
  })
2184
2222
  )
2185
2223
  );