@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.
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.75" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.77" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -860,17 +860,32 @@ var googleLanguageModelOptions = lazySchema4(
860
860
  */
861
861
  streamFunctionCallArguments: z4.boolean().optional(),
862
862
  /**
863
- * Optional. The service tier to use for the request.
863
+ * Optional. The service tier to use for the request. Sent as the
864
+ * `serviceTier` body field. Gemini API only.
864
865
  */
865
- serviceTier: z4.enum(["standard", "flex", "priority"]).optional()
866
+ serviceTier: z4.enum(["standard", "flex", "priority"]).optional(),
867
+ /**
868
+ * Optional. Vertex AI only. Sent as the
869
+ * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
870
+ * shared (PayGo) tier. With Provisioned Throughput allocated and
871
+ * `requestType` unset, the request falls back to this tier only if
872
+ * PT capacity is exhausted.
873
+ *
874
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
875
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
876
+ */
877
+ sharedRequestType: z4.enum(["priority", "flex", "standard"]).optional(),
878
+ /**
879
+ * Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
880
+ * request header. Set to `'shared'` together with `sharedRequestType`
881
+ * to bypass Provisioned Throughput entirely.
882
+ *
883
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
884
+ */
885
+ requestType: z4.enum(["shared"]).optional()
866
886
  })
867
887
  )
868
888
  );
869
- var VertexServiceTierMap = {
870
- standard: "SERVICE_TIER_STANDARD",
871
- flex: "SERVICE_TIER_FLEX",
872
- priority: "SERVICE_TIER_PRIORITY"
873
- };
874
889
 
875
890
  // src/google-prepare-tools.ts
876
891
  import {
@@ -1437,10 +1452,27 @@ var GoogleGenerativeAILanguageModel = class {
1437
1452
  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`
1438
1453
  });
1439
1454
  }
1440
- let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
1441
1455
  if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
1442
- sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
1456
+ warnings.push({
1457
+ type: "other",
1458
+ 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"
1459
+ });
1460
+ }
1461
+ if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1462
+ warnings.push({
1463
+ type: "other",
1464
+ message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
1465
+ });
1443
1466
  }
1467
+ const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
1468
+ ...googleOptions.sharedRequestType && {
1469
+ "X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
1470
+ },
1471
+ ...googleOptions.requestType && {
1472
+ "X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
1473
+ }
1474
+ } : void 0;
1475
+ const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1444
1476
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1445
1477
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1446
1478
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
@@ -1512,18 +1544,20 @@ var GoogleGenerativeAILanguageModel = class {
1512
1544
  toolConfig,
1513
1545
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
1514
1546
  labels: googleOptions == null ? void 0 : googleOptions.labels,
1515
- serviceTier: sanitizedServiceTier
1547
+ serviceTier: bodyServiceTier
1516
1548
  },
1517
1549
  warnings: [...warnings, ...toolWarnings],
1518
- providerOptionsName
1550
+ providerOptionsName,
1551
+ extraHeaders: vertexPaygoHeaders
1519
1552
  };
1520
1553
  }
1521
1554
  async doGenerate(options) {
1522
1555
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1523
- const { args, warnings, providerOptionsName } = await this.getArgs(options);
1556
+ const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
1524
1557
  const mergedHeaders = combineHeaders2(
1525
1558
  await resolve2(this.config.headers),
1526
- options.headers
1559
+ options.headers,
1560
+ extraHeaders
1527
1561
  );
1528
1562
  const {
1529
1563
  responseHeaders,
@@ -1688,7 +1722,7 @@ var GoogleGenerativeAILanguageModel = class {
1688
1722
  safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1689
1723
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1690
1724
  finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1691
- serviceTier: (_r = response.serviceTier) != null ? _r : null
1725
+ serviceTier: (_r = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _r : null
1692
1726
  }
1693
1727
  },
1694
1728
  request: { body: args },
@@ -1700,13 +1734,12 @@ var GoogleGenerativeAILanguageModel = class {
1700
1734
  };
1701
1735
  }
1702
1736
  async doStream(options) {
1703
- const { args, warnings, providerOptionsName } = await this.getArgs(
1704
- options,
1705
- { isStreaming: true }
1706
- );
1737
+ var _a;
1738
+ const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
1707
1739
  const headers = combineHeaders2(
1708
1740
  await resolve2(this.config.headers),
1709
- options.headers
1741
+ options.headers,
1742
+ extraHeaders
1710
1743
  );
1711
1744
  const { responseHeaders, value: response } = await postJsonToApi2({
1712
1745
  url: `${this.config.baseURL}/${getModelPath(
@@ -1727,7 +1760,7 @@ var GoogleGenerativeAILanguageModel = class {
1727
1760
  let providerMetadata = void 0;
1728
1761
  let lastGroundingMetadata = null;
1729
1762
  let lastUrlContextMetadata = null;
1730
- let serviceTier = null;
1763
+ const serviceTier = (_a = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _a : null;
1731
1764
  const generateId3 = this.config.generateId;
1732
1765
  let hasToolCalls = false;
1733
1766
  let currentTextBlockId = null;
@@ -1737,6 +1770,34 @@ var GoogleGenerativeAILanguageModel = class {
1737
1770
  let lastCodeExecutionToolCallId;
1738
1771
  let lastServerToolCallId;
1739
1772
  const activeStreamingToolCalls = [];
1773
+ const finishActiveStreamingToolCall = (controller) => {
1774
+ const active = activeStreamingToolCalls.pop();
1775
+ if (active == null) {
1776
+ return;
1777
+ }
1778
+ const { finalJSON, closingDelta } = active.accumulator.finalize();
1779
+ if (closingDelta.length > 0) {
1780
+ controller.enqueue({
1781
+ type: "tool-input-delta",
1782
+ id: active.toolCallId,
1783
+ delta: closingDelta,
1784
+ providerMetadata: active.providerMetadata
1785
+ });
1786
+ }
1787
+ controller.enqueue({
1788
+ type: "tool-input-end",
1789
+ id: active.toolCallId,
1790
+ providerMetadata: active.providerMetadata
1791
+ });
1792
+ controller.enqueue({
1793
+ type: "tool-call",
1794
+ toolCallId: active.toolCallId,
1795
+ toolName: active.toolName,
1796
+ input: finalJSON,
1797
+ providerMetadata: active.providerMetadata
1798
+ });
1799
+ hasToolCalls = true;
1800
+ };
1740
1801
  return {
1741
1802
  stream: response.pipeThrough(
1742
1803
  new TransformStream({
@@ -1744,7 +1805,7 @@ var GoogleGenerativeAILanguageModel = class {
1744
1805
  controller.enqueue({ type: "stream-start", warnings });
1745
1806
  },
1746
1807
  transform(chunk, controller) {
1747
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1808
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1748
1809
  if (options.includeRawChunks) {
1749
1810
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1750
1811
  }
@@ -1757,10 +1818,7 @@ var GoogleGenerativeAILanguageModel = class {
1757
1818
  if (usageMetadata != null) {
1758
1819
  usage = usageMetadata;
1759
1820
  }
1760
- if (value.serviceTier != null) {
1761
- serviceTier = value.serviceTier;
1762
- }
1763
- const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1821
+ const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
1764
1822
  if (candidate == null) {
1765
1823
  return;
1766
1824
  }
@@ -1949,7 +2007,7 @@ var GoogleGenerativeAILanguageModel = class {
1949
2007
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
1950
2008
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
1951
2009
  if (isStreamingChunk) {
1952
- if (part.functionCall.name != null && part.functionCall.willContinue === true) {
2010
+ if (part.functionCall.name != null) {
1953
2011
  const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
1954
2012
  const accumulator = new GoogleJSONAccumulator();
1955
2013
  activeStreamingToolCalls.push({
@@ -1965,9 +2023,8 @@ var GoogleGenerativeAILanguageModel = class {
1965
2023
  providerMetadata: providerMeta
1966
2024
  });
1967
2025
  if (part.functionCall.partialArgs != null) {
1968
- const { textDelta } = accumulator.processPartialArgs(
1969
- part.functionCall.partialArgs
1970
- );
2026
+ const partialArgs = part.functionCall.partialArgs;
2027
+ const { textDelta } = accumulator.processPartialArgs(partialArgs);
1971
2028
  if (textDelta.length > 0) {
1972
2029
  controller.enqueue({
1973
2030
  type: "tool-input-delta",
@@ -1976,12 +2033,14 @@ var GoogleGenerativeAILanguageModel = class {
1976
2033
  providerMetadata: providerMeta
1977
2034
  });
1978
2035
  }
2036
+ if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
2037
+ finishActiveStreamingToolCall(controller);
2038
+ }
1979
2039
  }
1980
2040
  } else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
1981
2041
  const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
1982
- const { textDelta } = active.accumulator.processPartialArgs(
1983
- part.functionCall.partialArgs
1984
- );
2042
+ const partialArgs = part.functionCall.partialArgs;
2043
+ const { textDelta } = active.accumulator.processPartialArgs(partialArgs);
1985
2044
  if (textDelta.length > 0) {
1986
2045
  controller.enqueue({
1987
2046
  type: "tool-input-delta",
@@ -1990,31 +2049,12 @@ var GoogleGenerativeAILanguageModel = class {
1990
2049
  providerMetadata: providerMeta
1991
2050
  });
1992
2051
  }
2052
+ if (part.functionCall.willContinue !== true && partialArgs.every((arg) => arg.willContinue !== true)) {
2053
+ finishActiveStreamingToolCall(controller);
2054
+ }
1993
2055
  }
1994
2056
  } else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
1995
- const active = activeStreamingToolCalls.pop();
1996
- const { finalJSON, closingDelta } = active.accumulator.finalize();
1997
- if (closingDelta.length > 0) {
1998
- controller.enqueue({
1999
- type: "tool-input-delta",
2000
- id: active.toolCallId,
2001
- delta: closingDelta,
2002
- providerMetadata: active.providerMetadata
2003
- });
2004
- }
2005
- controller.enqueue({
2006
- type: "tool-input-end",
2007
- id: active.toolCallId,
2008
- providerMetadata: active.providerMetadata
2009
- });
2010
- controller.enqueue({
2011
- type: "tool-call",
2012
- toolCallId: active.toolCallId,
2013
- toolName: active.toolName,
2014
- input: finalJSON,
2015
- providerMetadata: active.providerMetadata
2016
- });
2017
- hasToolCalls = true;
2057
+ finishActiveStreamingToolCall(controller);
2018
2058
  } else if (isCompleteCall) {
2019
2059
  const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
2020
2060
  const toolName = part.functionCall.name;
@@ -2373,8 +2413,7 @@ var responseSchema = lazySchema5(
2373
2413
  promptFeedback: z5.object({
2374
2414
  blockReason: z5.string().nullish(),
2375
2415
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
2376
- }).nullish(),
2377
- serviceTier: z5.string().nullish()
2416
+ }).nullish()
2378
2417
  })
2379
2418
  )
2380
2419
  );
@@ -2395,8 +2434,7 @@ var chunkSchema = lazySchema5(
2395
2434
  promptFeedback: z5.object({
2396
2435
  blockReason: z5.string().nullish(),
2397
2436
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
2398
- }).nullish(),
2399
- serviceTier: z5.string().nullish()
2437
+ }).nullish()
2400
2438
  })
2401
2439
  )
2402
2440
  );
@@ -4669,7 +4707,61 @@ var googleInteractionsLanguageModelOptions = lazySchema14(
4669
4707
  * call) before giving up. Defaults to 30 minutes. Long-running agents
4670
4708
  * such as deep research can take tens of minutes — increase if needed.
4671
4709
  */
4672
- pollingTimeoutMs: z16.number().int().positive().nullish()
4710
+ pollingTimeoutMs: z16.number().int().positive().nullish(),
4711
+ /**
4712
+ * Run the interaction in the background. Required for agents whose
4713
+ * server-side workflow cannot complete within a single request/response.
4714
+ * When `true`, the POST returns with a non-terminal status and the SDK
4715
+ * polls `GET /interactions/{id}` until the work completes. Some agents
4716
+ * reject `true`; see the agent's documentation for which mode it
4717
+ * requires.
4718
+ */
4719
+ background: z16.boolean().nullish(),
4720
+ /**
4721
+ * Environment configuration for the agent sandbox. Only applies to agent
4722
+ * calls (`google.interactions({ agent })`); ignored on model-id calls.
4723
+ *
4724
+ * - `"remote"`: provision a fresh sandbox for this call.
4725
+ * - any other string: an existing `environment_id` to reuse.
4726
+ * - object: provision a fresh sandbox and optionally preload `sources`
4727
+ * and/or constrain outbound traffic via `network`.
4728
+ */
4729
+ environment: z16.union([
4730
+ z16.string(),
4731
+ z16.object({
4732
+ type: z16.literal("remote"),
4733
+ sources: z16.array(
4734
+ z16.union([
4735
+ z16.object({
4736
+ type: z16.literal("gcs"),
4737
+ source: z16.string(),
4738
+ target: z16.string().nullish()
4739
+ }),
4740
+ z16.object({
4741
+ type: z16.literal("repository"),
4742
+ source: z16.string(),
4743
+ target: z16.string().nullish()
4744
+ }),
4745
+ z16.object({
4746
+ type: z16.literal("inline"),
4747
+ content: z16.string(),
4748
+ target: z16.string()
4749
+ })
4750
+ ])
4751
+ ).nullish(),
4752
+ network: z16.union([
4753
+ z16.literal("disabled"),
4754
+ z16.object({
4755
+ allowlist: z16.array(
4756
+ z16.object({
4757
+ domain: z16.string(),
4758
+ transform: z16.array(z16.record(z16.string(), z16.string())).nullish()
4759
+ })
4760
+ )
4761
+ })
4762
+ ]).nullish()
4763
+ })
4764
+ ]).nullish()
4673
4765
  })
4674
4766
  )
4675
4767
  );
@@ -5411,6 +5503,9 @@ var GoogleInteractionsLanguageModel = class {
5411
5503
  if (typeof modelOrAgent === "string") {
5412
5504
  this.modelId = modelOrAgent;
5413
5505
  this.agent = void 0;
5506
+ } else if ("managedAgent" in modelOrAgent) {
5507
+ this.modelId = modelOrAgent.managedAgent;
5508
+ this.agent = modelOrAgent.managedAgent;
5414
5509
  } else {
5415
5510
  this.modelId = modelOrAgent.agent;
5416
5511
  this.agent = modelOrAgent.agent;
@@ -5436,7 +5531,7 @@ var GoogleInteractionsLanguageModel = class {
5436
5531
  };
5437
5532
  }
5438
5533
  async getArgs(options) {
5439
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
5534
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
5440
5535
  const warnings = [];
5441
5536
  const opts = await parseProviderOptions5({
5442
5537
  provider: "google",
@@ -5593,6 +5688,55 @@ var GoogleInteractionsLanguageModel = class {
5593
5688
  agentConfig = { type: "dynamic" };
5594
5689
  }
5595
5690
  }
5691
+ let environment;
5692
+ if ((opts == null ? void 0 : opts.environment) != null) {
5693
+ if (!isAgent) {
5694
+ warnings.push({
5695
+ type: "other",
5696
+ message: "google.interactions: environment is only supported when an agent is set; environment will be omitted from the request body."
5697
+ });
5698
+ } else if (typeof opts.environment === "string") {
5699
+ environment = opts.environment;
5700
+ } else {
5701
+ const env = opts.environment;
5702
+ const sources = (_u = env.sources) == null ? void 0 : _u.map((s) => {
5703
+ var _a2;
5704
+ if (s.type === "inline") {
5705
+ return {
5706
+ type: "inline",
5707
+ content: s.content,
5708
+ target: s.target
5709
+ };
5710
+ }
5711
+ return pruneUndefined({
5712
+ type: s.type,
5713
+ source: s.source,
5714
+ target: (_a2 = s.target) != null ? _a2 : void 0
5715
+ });
5716
+ });
5717
+ let network;
5718
+ if (env.network === "disabled") {
5719
+ network = "disabled";
5720
+ } else if (env.network != null) {
5721
+ network = {
5722
+ allowlist: env.network.allowlist.map(
5723
+ (entry) => {
5724
+ var _a2;
5725
+ return pruneUndefined({
5726
+ domain: entry.domain,
5727
+ transform: (_a2 = entry.transform) != null ? _a2 : void 0
5728
+ });
5729
+ }
5730
+ )
5731
+ };
5732
+ }
5733
+ environment = pruneUndefined({
5734
+ type: "remote",
5735
+ sources: sources != null && sources.length > 0 ? sources : void 0,
5736
+ network
5737
+ });
5738
+ }
5739
+ }
5596
5740
  const args = pruneUndefined({
5597
5741
  ...isAgent ? { agent: this.agent } : { model: this.modelId },
5598
5742
  input,
@@ -5600,18 +5744,20 @@ var GoogleInteractionsLanguageModel = class {
5600
5744
  tools: toolsForBody,
5601
5745
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
5602
5746
  response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
5603
- previous_interaction_id: (_u = opts == null ? void 0 : opts.previousInteractionId) != null ? _u : void 0,
5604
- service_tier: (_v = opts == null ? void 0 : opts.serviceTier) != null ? _v : void 0,
5605
- store: (_w = opts == null ? void 0 : opts.store) != null ? _w : void 0,
5747
+ previous_interaction_id: (_v = opts == null ? void 0 : opts.previousInteractionId) != null ? _v : void 0,
5748
+ service_tier: (_w = opts == null ? void 0 : opts.serviceTier) != null ? _w : void 0,
5749
+ store: (_x = opts == null ? void 0 : opts.store) != null ? _x : void 0,
5606
5750
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
5607
5751
  agent_config: agentConfig,
5608
- ...isAgent ? { background: true } : {}
5752
+ environment,
5753
+ background: (_y = opts == null ? void 0 : opts.background) != null ? _y : void 0
5609
5754
  });
5610
5755
  return {
5611
5756
  args,
5612
5757
  warnings,
5613
5758
  isAgent,
5614
- pollingTimeoutMs: (_x = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _x : void 0
5759
+ isBackground: (opts == null ? void 0 : opts.background) === true,
5760
+ pollingTimeoutMs: (_z = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _z : void 0
5615
5761
  };
5616
5762
  }
5617
5763
  async doGenerate(options) {
@@ -5697,14 +5843,14 @@ var GoogleInteractionsLanguageModel = class {
5697
5843
  }
5698
5844
  async doStream(options) {
5699
5845
  var _a;
5700
- const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
5846
+ const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
5701
5847
  const url = `${this.config.baseURL}/interactions`;
5702
5848
  const mergedHeaders = combineHeaders6(
5703
5849
  INTERACTIONS_API_REVISION_HEADER,
5704
5850
  this.config.headers ? await resolve5(this.config.headers) : void 0,
5705
5851
  options.headers
5706
5852
  );
5707
- if (isAgent) {
5853
+ if (isBackground) {
5708
5854
  return this.doStreamBackground({
5709
5855
  args,
5710
5856
  warnings,