@ai-sdk/google 3.0.71 → 3.0.73

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.73
4
+
5
+ ### Patch Changes
6
+
7
+ - bb1eb98: feat(google): add `fileData` support to embedding model
8
+
9
+ ## 3.0.72
10
+
11
+ ### Patch Changes
12
+
13
+ - b3642fe: feat(provider/google): support cancelling long-running Interactions API agents via AbortSignal, and process their intermittent stream
14
+
3
15
  ## 3.0.71
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -236,6 +236,11 @@ declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
236
236
  mimeType: string;
237
237
  data: string;
238
238
  };
239
+ } | {
240
+ fileData: {
241
+ fileUri: string;
242
+ mimeType: string;
243
+ };
239
244
  })[] | null)[] | undefined;
240
245
  }>;
241
246
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
package/dist/index.d.ts CHANGED
@@ -236,6 +236,11 @@ declare const googleEmbeddingModelOptions: _ai_sdk_provider_utils.LazySchema<{
236
236
  mimeType: string;
237
237
  data: string;
238
238
  };
239
+ } | {
240
+ fileData: {
241
+ fileUri: string;
242
+ mimeType: string;
243
+ };
239
244
  })[] | null)[] | undefined;
240
245
  }>;
241
246
  type GoogleEmbeddingModelOptions = InferSchema<typeof googleEmbeddingModelOptions>;
package/dist/index.js CHANGED
@@ -27,10 +27,10 @@ __export(index_exports, {
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/google-provider.ts
30
- var import_provider_utils21 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils23 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.71" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.73" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -66,6 +66,12 @@ var googleEmbeddingContentPartSchema = import_v42.z.union([
66
66
  mimeType: import_v42.z.string(),
67
67
  data: import_v42.z.string()
68
68
  })
69
+ }),
70
+ import_v42.z.object({
71
+ fileData: import_v42.z.object({
72
+ fileUri: import_v42.z.string(),
73
+ mimeType: import_v42.z.string()
74
+ })
69
75
  })
70
76
  ]);
71
77
  var googleEmbeddingModelOptions = (0, import_provider_utils2.lazySchema)(
@@ -3023,7 +3029,7 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
3023
3029
  );
3024
3030
 
3025
3031
  // src/interactions/google-interactions-language-model.ts
3026
- var import_provider_utils20 = require("@ai-sdk/provider-utils");
3032
+ var import_provider_utils22 = require("@ai-sdk/provider-utils");
3027
3033
 
3028
3034
  // src/interactions/convert-google-interactions-usage.ts
3029
3035
  function convertGoogleInteractionsUsage(usage) {
@@ -4632,7 +4638,39 @@ function parseGoogleInteractionsOutputs({
4632
4638
  }
4633
4639
 
4634
4640
  // src/interactions/poll-google-interactions.ts
4641
+ var import_provider_utils20 = require("@ai-sdk/provider-utils");
4642
+
4643
+ // src/interactions/cancel-google-interaction.ts
4635
4644
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
4645
+ var getOriginalFetch = () => globalThis.fetch;
4646
+ async function cancelGoogleInteraction({
4647
+ baseURL,
4648
+ interactionId,
4649
+ headers,
4650
+ fetch = getOriginalFetch()
4651
+ }) {
4652
+ if (interactionId == null || interactionId.length === 0) {
4653
+ return;
4654
+ }
4655
+ const url = `${baseURL}/interactions/${encodeURIComponent(interactionId)}/cancel`;
4656
+ try {
4657
+ const response = await fetch(url, {
4658
+ method: "POST",
4659
+ headers: (0, import_provider_utils19.withUserAgentSuffix)(
4660
+ (0, import_provider_utils19.combineHeaders)({ "Content-Type": "application/json" }, headers),
4661
+ (0, import_provider_utils19.getRuntimeEnvironmentUserAgent)()
4662
+ ),
4663
+ body: "{}"
4664
+ });
4665
+ try {
4666
+ await response.text();
4667
+ } catch (e) {
4668
+ }
4669
+ } catch (e) {
4670
+ }
4671
+ }
4672
+
4673
+ // src/interactions/poll-google-interactions.ts
4636
4674
  var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "incomplete"]);
4637
4675
  function isTerminalStatus(status) {
4638
4676
  return status != null && TERMINAL_STATUSES.has(status);
@@ -4658,34 +4696,43 @@ async function pollGoogleInteractionUntilTerminal({
4658
4696
  const startedAt = Date.now();
4659
4697
  let nextDelayMs = initialDelayMs;
4660
4698
  const url = `${baseURL}/interactions/${encodeURIComponent(interactionId)}`;
4661
- while (true) {
4662
- if (abortSignal == null ? void 0 : abortSignal.aborted) {
4663
- throw new DOMException("Polling was aborted", "AbortError");
4664
- }
4665
- if (Date.now() - startedAt > timeoutMs) {
4666
- throw new Error(
4667
- `google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
4668
- );
4699
+ const cancelOnServer = () => cancelGoogleInteraction({ baseURL, interactionId, headers, fetch });
4700
+ try {
4701
+ while (true) {
4702
+ if (abortSignal == null ? void 0 : abortSignal.aborted) {
4703
+ await cancelOnServer();
4704
+ throw new DOMException("Polling was aborted", "AbortError");
4705
+ }
4706
+ if (Date.now() - startedAt > timeoutMs) {
4707
+ throw new Error(
4708
+ `google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
4709
+ );
4710
+ }
4711
+ await (0, import_provider_utils20.delay)(nextDelayMs, { abortSignal });
4712
+ const {
4713
+ value: response,
4714
+ rawValue: rawResponse,
4715
+ responseHeaders
4716
+ } = await (0, import_provider_utils20.getFromApi)({
4717
+ url,
4718
+ headers,
4719
+ failedResponseHandler: googleFailedResponseHandler,
4720
+ successfulResponseHandler: (0, import_provider_utils20.createJsonResponseHandler)(
4721
+ googleInteractionsResponseSchema
4722
+ ),
4723
+ abortSignal,
4724
+ fetch
4725
+ });
4726
+ if (isTerminalStatus(response.status)) {
4727
+ return { response, rawResponse, responseHeaders };
4728
+ }
4729
+ nextDelayMs = Math.min(nextDelayMs * 2, maxDelayMs);
4669
4730
  }
4670
- await (0, import_provider_utils19.delay)(nextDelayMs, { abortSignal });
4671
- const {
4672
- value: response,
4673
- rawValue: rawResponse,
4674
- responseHeaders
4675
- } = await (0, import_provider_utils19.getFromApi)({
4676
- url,
4677
- headers,
4678
- failedResponseHandler: googleFailedResponseHandler,
4679
- successfulResponseHandler: (0, import_provider_utils19.createJsonResponseHandler)(
4680
- googleInteractionsResponseSchema
4681
- ),
4682
- abortSignal,
4683
- fetch
4684
- });
4685
- if (isTerminalStatus(response.status)) {
4686
- return { response, rawResponse, responseHeaders };
4731
+ } catch (error) {
4732
+ if ((0, import_provider_utils20.isAbortError)(error)) {
4733
+ await cancelOnServer();
4687
4734
  }
4688
- nextDelayMs = Math.min(nextDelayMs * 2, maxDelayMs);
4735
+ throw error;
4689
4736
  }
4690
4737
  }
4691
4738
 
@@ -4837,6 +4884,169 @@ function prepareGoogleInteractionsTools({
4837
4884
  };
4838
4885
  }
4839
4886
 
4887
+ // src/interactions/stream-google-interactions.ts
4888
+ var import_provider_utils21 = require("@ai-sdk/provider-utils");
4889
+ var DEFAULT_MAX_RETRIES = 3;
4890
+ var DEFAULT_RETRY_DELAY_MS = 500;
4891
+ function streamGoogleInteractionEvents({
4892
+ baseURL,
4893
+ interactionId,
4894
+ headers,
4895
+ fetch,
4896
+ abortSignal,
4897
+ maxRetries = DEFAULT_MAX_RETRIES,
4898
+ retryDelayMs = DEFAULT_RETRY_DELAY_MS
4899
+ }) {
4900
+ if (interactionId.length === 0) {
4901
+ throw new Error(
4902
+ "google.interactions: cannot stream a background interaction without an id."
4903
+ );
4904
+ }
4905
+ const eventSourceHeaders = {
4906
+ ...headers,
4907
+ accept: "text/event-stream"
4908
+ };
4909
+ let lastEventId;
4910
+ let complete = false;
4911
+ let attempt = 0;
4912
+ let receivedAnyEventThisAttempt = false;
4913
+ let currentReader;
4914
+ const internalAbort = new AbortController();
4915
+ const upstreamAbortHandler = () => internalAbort.abort();
4916
+ if (abortSignal != null) {
4917
+ if (abortSignal.aborted) {
4918
+ internalAbort.abort();
4919
+ } else {
4920
+ abortSignal.addEventListener("abort", upstreamAbortHandler, {
4921
+ once: true
4922
+ });
4923
+ }
4924
+ }
4925
+ const effectiveSignal = internalAbort.signal;
4926
+ function buildUrl() {
4927
+ const base = `${baseURL}/interactions/${encodeURIComponent(interactionId)}`;
4928
+ const params = new URLSearchParams({ stream: "true" });
4929
+ if (lastEventId != null) {
4930
+ params.set("last_event_id", lastEventId);
4931
+ }
4932
+ return `${base}?${params.toString()}`;
4933
+ }
4934
+ async function openReader() {
4935
+ const { value: stream } = await (0, import_provider_utils21.getFromApi)({
4936
+ url: buildUrl(),
4937
+ headers: eventSourceHeaders,
4938
+ failedResponseHandler: googleFailedResponseHandler,
4939
+ successfulResponseHandler: (0, import_provider_utils21.createEventSourceResponseHandler)(
4940
+ googleInteractionsEventSchema
4941
+ ),
4942
+ abortSignal: effectiveSignal,
4943
+ fetch
4944
+ });
4945
+ return stream.getReader();
4946
+ }
4947
+ return new ReadableStream({
4948
+ async start(controller) {
4949
+ try {
4950
+ while (!complete && !effectiveSignal.aborted) {
4951
+ if (currentReader == null) {
4952
+ try {
4953
+ currentReader = await openReader();
4954
+ receivedAnyEventThisAttempt = false;
4955
+ } catch (error) {
4956
+ if ((0, import_provider_utils21.isAbortError)(error) || effectiveSignal.aborted) {
4957
+ controller.error(error);
4958
+ return;
4959
+ }
4960
+ attempt++;
4961
+ if (attempt >= maxRetries) {
4962
+ controller.error(error);
4963
+ return;
4964
+ }
4965
+ await (0, import_provider_utils21.delay)(retryDelayMs * attempt, {
4966
+ abortSignal: effectiveSignal
4967
+ });
4968
+ continue;
4969
+ }
4970
+ }
4971
+ try {
4972
+ const { done, value } = await currentReader.read();
4973
+ if (done) {
4974
+ currentReader = void 0;
4975
+ if (complete) break;
4976
+ if (!receivedAnyEventThisAttempt) {
4977
+ attempt++;
4978
+ if (attempt >= maxRetries) {
4979
+ controller.error(
4980
+ new Error(
4981
+ "google.interactions: SSE stream closed without producing any events."
4982
+ )
4983
+ );
4984
+ return;
4985
+ }
4986
+ await (0, import_provider_utils21.delay)(retryDelayMs * attempt, {
4987
+ abortSignal: effectiveSignal
4988
+ });
4989
+ } else {
4990
+ attempt = 0;
4991
+ }
4992
+ continue;
4993
+ }
4994
+ receivedAnyEventThisAttempt = true;
4995
+ if (value.success) {
4996
+ const ev = value.value;
4997
+ if (typeof ev.event_id === "string" && ev.event_id.length > 0) {
4998
+ lastEventId = ev.event_id;
4999
+ }
5000
+ if (ev.event_type === "interaction.complete" || ev.event_type === "error") {
5001
+ complete = true;
5002
+ }
5003
+ }
5004
+ controller.enqueue(value);
5005
+ } catch (error) {
5006
+ if ((0, import_provider_utils21.isAbortError)(error) || effectiveSignal.aborted) {
5007
+ controller.error(error);
5008
+ return;
5009
+ }
5010
+ currentReader = void 0;
5011
+ attempt++;
5012
+ if (attempt >= maxRetries) {
5013
+ controller.error(error);
5014
+ return;
5015
+ }
5016
+ await (0, import_provider_utils21.delay)(retryDelayMs * attempt, {
5017
+ abortSignal: effectiveSignal
5018
+ });
5019
+ }
5020
+ }
5021
+ controller.close();
5022
+ } catch (error) {
5023
+ controller.error(error);
5024
+ } finally {
5025
+ if (abortSignal != null) {
5026
+ abortSignal.removeEventListener("abort", upstreamAbortHandler);
5027
+ }
5028
+ currentReader == null ? void 0 : currentReader.cancel().catch(() => {
5029
+ });
5030
+ currentReader = void 0;
5031
+ if (effectiveSignal.aborted && !complete) {
5032
+ await cancelGoogleInteraction({
5033
+ baseURL,
5034
+ interactionId,
5035
+ headers,
5036
+ fetch
5037
+ });
5038
+ }
5039
+ }
5040
+ },
5041
+ cancel() {
5042
+ internalAbort.abort();
5043
+ currentReader == null ? void 0 : currentReader.cancel().catch(() => {
5044
+ });
5045
+ currentReader = void 0;
5046
+ }
5047
+ });
5048
+ }
5049
+
4840
5050
  // src/interactions/synthesize-google-interactions-agent-stream.ts
4841
5051
  function synthesizeGoogleInteractionsAgentStream({
4842
5052
  response,
@@ -5012,7 +5222,7 @@ var GoogleInteractionsLanguageModel = class {
5012
5222
  async getArgs(options) {
5013
5223
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
5014
5224
  const warnings = [];
5015
- const opts = await (0, import_provider_utils20.parseProviderOptions)({
5225
+ const opts = await (0, import_provider_utils22.parseProviderOptions)({
5016
5226
  provider: "google",
5017
5227
  providerOptions: options.providerOptions,
5018
5228
  schema: googleInteractionsLanguageModelOptions
@@ -5150,16 +5360,16 @@ var GoogleInteractionsLanguageModel = class {
5150
5360
  var _a, _b, _c, _d, _e, _f;
5151
5361
  const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
5152
5362
  const url = `${this.config.baseURL}/interactions`;
5153
- const mergedHeaders = (0, import_provider_utils20.combineHeaders)(
5154
- this.config.headers ? await (0, import_provider_utils20.resolve)(this.config.headers) : void 0,
5363
+ const mergedHeaders = (0, import_provider_utils22.combineHeaders)(
5364
+ this.config.headers ? await (0, import_provider_utils22.resolve)(this.config.headers) : void 0,
5155
5365
  options.headers
5156
5366
  );
5157
- const postResult = await (0, import_provider_utils20.postJsonToApi)({
5367
+ const postResult = await (0, import_provider_utils22.postJsonToApi)({
5158
5368
  url,
5159
5369
  headers: mergedHeaders,
5160
5370
  body: args,
5161
5371
  failedResponseHandler: googleFailedResponseHandler,
5162
- successfulResponseHandler: (0, import_provider_utils20.createJsonResponseHandler)(
5372
+ successfulResponseHandler: (0, import_provider_utils22.createJsonResponseHandler)(
5163
5373
  googleInteractionsResponseSchema
5164
5374
  ),
5165
5375
  abortSignal: options.abortSignal,
@@ -5186,7 +5396,7 @@ var GoogleInteractionsLanguageModel = class {
5186
5396
  const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
5187
5397
  const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
5188
5398
  outputs: (_b = response.outputs) != null ? _b : null,
5189
- generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils20.generateId,
5399
+ generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils22.generateId,
5190
5400
  interactionId
5191
5401
  });
5192
5402
  const finishReason = {
@@ -5230,12 +5440,12 @@ var GoogleInteractionsLanguageModel = class {
5230
5440
  var _a;
5231
5441
  const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
5232
5442
  const url = `${this.config.baseURL}/interactions`;
5233
- const mergedHeaders = (0, import_provider_utils20.combineHeaders)(
5234
- this.config.headers ? await (0, import_provider_utils20.resolve)(this.config.headers) : void 0,
5443
+ const mergedHeaders = (0, import_provider_utils22.combineHeaders)(
5444
+ this.config.headers ? await (0, import_provider_utils22.resolve)(this.config.headers) : void 0,
5235
5445
  options.headers
5236
5446
  );
5237
5447
  if (isAgent) {
5238
- return this.doStreamAgent({
5448
+ return this.doStreamBackground({
5239
5449
  args,
5240
5450
  warnings,
5241
5451
  url,
@@ -5245,12 +5455,12 @@ var GoogleInteractionsLanguageModel = class {
5245
5455
  });
5246
5456
  }
5247
5457
  const body = { ...args, stream: true };
5248
- const { responseHeaders, value: response } = await (0, import_provider_utils20.postJsonToApi)({
5458
+ const { responseHeaders, value: response } = await (0, import_provider_utils22.postJsonToApi)({
5249
5459
  url,
5250
5460
  headers: mergedHeaders,
5251
5461
  body,
5252
5462
  failedResponseHandler: googleFailedResponseHandler,
5253
- successfulResponseHandler: (0, import_provider_utils20.createEventSourceResponseHandler)(
5463
+ successfulResponseHandler: (0, import_provider_utils22.createEventSourceResponseHandler)(
5254
5464
  googleInteractionsEventSchema
5255
5465
  ),
5256
5466
  abortSignal: options.abortSignal,
@@ -5259,7 +5469,7 @@ var GoogleInteractionsLanguageModel = class {
5259
5469
  const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
5260
5470
  const transform = buildGoogleInteractionsStreamTransform({
5261
5471
  warnings,
5262
- generateId: (_a = this.config.generateId) != null ? _a : import_provider_utils20.generateId,
5472
+ generateId: (_a = this.config.generateId) != null ? _a : import_provider_utils22.generateId,
5263
5473
  includeRawChunks: options.includeRawChunks,
5264
5474
  serviceTier: headerServiceTier
5265
5475
  });
@@ -5270,26 +5480,24 @@ var GoogleInteractionsLanguageModel = class {
5270
5480
  };
5271
5481
  }
5272
5482
  /*
5273
- * Drive the streaming surface for agent calls. Agent calls require
5483
+ * Drive the streaming surface for agent calls. Agents require
5274
5484
  * `background: true`, which is incompatible with `stream: true` on POST.
5275
5485
  *
5276
- * In principle the API also exposes `GET /interactions/{id}?stream=true`
5277
- * to replay events as the agent runs. In practice the connection is
5278
- * idle for long stretches while the agent thinks (deep-research can run
5279
- * for a minute or more between SSE events), and undici's default body
5280
- * timeout terminates the request mid-flight with `UND_ERR_BODY_TIMEOUT`.
5281
- * Tuning the timeout per-call would require the caller to thread an
5282
- * `undici.Agent` through `fetch`, which contradicts the AI SDK's
5283
- * pluggable-fetch contract.
5486
+ * Approach:
5487
+ * 1. POST `/interactions` with `background: true`. The response includes
5488
+ * the interaction id and an initial (usually non-terminal) status.
5489
+ * 2. If the POST status is already terminal (rare), synthesize a stream
5490
+ * from the polled outputs and we're done.
5491
+ * 3. Otherwise open `GET /interactions/{id}?stream=true` and pipe the
5492
+ * SSE events through `buildGoogleInteractionsStreamTransform` so the
5493
+ * consumer receives text deltas / thinking summaries / tool events as
5494
+ * they happen instead of all at once at the end.
5284
5495
  *
5285
- * We therefore drive `doStream` exactly like `doGenerate` for agents:
5286
- * POST with `background: true`, poll `GET /interactions/{id}` until
5287
- * terminal, then synthesize the stream from the final outputs. The
5288
- * user-facing surface stays identical -- text-start / text-delta /
5289
- * text-end / finish parts arrive in the same order as a true SSE
5290
- * response, just buffered until the agent completes.
5496
+ * The SSE connection can drop while the agent idles between events
5497
+ * (`UND_ERR_BODY_TIMEOUT`); `streamGoogleInteractionEvents` handles the
5498
+ * reconnect-with-`last_event_id` loop transparently.
5291
5499
  */
5292
- async doStreamAgent({
5500
+ async doStreamBackground({
5293
5501
  args,
5294
5502
  warnings,
5295
5503
  url,
@@ -5298,45 +5506,55 @@ var GoogleInteractionsLanguageModel = class {
5298
5506
  pollingTimeoutMs
5299
5507
  }) {
5300
5508
  var _a, _b;
5301
- const postResult = await (0, import_provider_utils20.postJsonToApi)({
5509
+ const postResult = await (0, import_provider_utils22.postJsonToApi)({
5302
5510
  url,
5303
5511
  headers: mergedHeaders,
5304
5512
  body: args,
5305
5513
  failedResponseHandler: googleFailedResponseHandler,
5306
- successfulResponseHandler: (0, import_provider_utils20.createJsonResponseHandler)(
5514
+ successfulResponseHandler: (0, import_provider_utils22.createJsonResponseHandler)(
5307
5515
  googleInteractionsResponseSchema
5308
5516
  ),
5309
5517
  abortSignal: options.abortSignal,
5310
5518
  fetch: this.config.fetch
5311
5519
  });
5312
- let { responseHeaders: postHeaders, value: postResponse } = postResult;
5520
+ const { responseHeaders: postHeaders, value: postResponse } = postResult;
5313
5521
  const interactionId = postResponse.id;
5314
5522
  if (interactionId == null || interactionId.length === 0) {
5315
5523
  throw new Error(
5316
- "google.interactions: agent POST response did not include an interaction id; cannot poll for the agent result."
5524
+ "google.interactions: background POST response did not include an interaction id; cannot stream the result."
5317
5525
  );
5318
5526
  }
5319
- if (!isTerminalStatus(postResponse.status)) {
5320
- const polled = await pollGoogleInteractionUntilTerminal({
5321
- baseURL: this.config.baseURL,
5322
- interactionId,
5323
- headers: mergedHeaders,
5324
- fetch: this.config.fetch,
5325
- abortSignal: options.abortSignal,
5326
- timeoutMs: pollingTimeoutMs
5527
+ const headerServiceTier = postHeaders == null ? void 0 : postHeaders["x-gemini-service-tier"];
5528
+ if (isTerminalStatus(postResponse.status)) {
5529
+ const synthesized = synthesizeGoogleInteractionsAgentStream({
5530
+ response: postResponse,
5531
+ warnings,
5532
+ generateId: (_a = this.config.generateId) != null ? _a : import_provider_utils22.generateId,
5533
+ includeRawChunks: options.includeRawChunks,
5534
+ headerServiceTier
5327
5535
  });
5328
- postResponse = polled.response;
5329
- postHeaders = (_a = polled.responseHeaders) != null ? _a : postHeaders;
5536
+ return {
5537
+ stream: synthesized,
5538
+ request: { body: args },
5539
+ response: { headers: postHeaders }
5540
+ };
5330
5541
  }
5331
- const stream = synthesizeGoogleInteractionsAgentStream({
5332
- response: postResponse,
5542
+ void pollingTimeoutMs;
5543
+ const events = streamGoogleInteractionEvents({
5544
+ baseURL: this.config.baseURL,
5545
+ interactionId,
5546
+ headers: mergedHeaders,
5547
+ fetch: this.config.fetch,
5548
+ abortSignal: options.abortSignal
5549
+ });
5550
+ const transform = buildGoogleInteractionsStreamTransform({
5333
5551
  warnings,
5334
- generateId: (_b = this.config.generateId) != null ? _b : import_provider_utils20.generateId,
5552
+ generateId: (_b = this.config.generateId) != null ? _b : import_provider_utils22.generateId,
5335
5553
  includeRawChunks: options.includeRawChunks,
5336
- headerServiceTier: postHeaders == null ? void 0 : postHeaders["x-gemini-service-tier"]
5554
+ serviceTier: headerServiceTier
5337
5555
  });
5338
5556
  return {
5339
- stream,
5557
+ stream: events.pipeThrough(transform),
5340
5558
  request: { body: args },
5341
5559
  response: { headers: postHeaders }
5342
5560
  };
@@ -5354,11 +5572,11 @@ function pruneUndefined(obj) {
5354
5572
  // src/google-provider.ts
5355
5573
  function createGoogleGenerativeAI(options = {}) {
5356
5574
  var _a, _b;
5357
- const baseURL = (_a = (0, import_provider_utils21.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
5575
+ const baseURL = (_a = (0, import_provider_utils23.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
5358
5576
  const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
5359
- const getHeaders = () => (0, import_provider_utils21.withUserAgentSuffix)(
5577
+ const getHeaders = () => (0, import_provider_utils23.withUserAgentSuffix)(
5360
5578
  {
5361
- "x-goog-api-key": (0, import_provider_utils21.loadApiKey)({
5579
+ "x-goog-api-key": (0, import_provider_utils23.loadApiKey)({
5362
5580
  apiKey: options.apiKey,
5363
5581
  environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
5364
5582
  description: "Google Generative AI"
@@ -5373,7 +5591,7 @@ function createGoogleGenerativeAI(options = {}) {
5373
5591
  provider: providerName,
5374
5592
  baseURL,
5375
5593
  headers: getHeaders,
5376
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils21.generateId,
5594
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils23.generateId,
5377
5595
  supportedUrls: () => ({
5378
5596
  "*": [
5379
5597
  // Google Generative Language "files" endpoint
@@ -5408,7 +5626,7 @@ function createGoogleGenerativeAI(options = {}) {
5408
5626
  baseURL,
5409
5627
  headers: getHeaders,
5410
5628
  fetch: options.fetch,
5411
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils21.generateId
5629
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils23.generateId
5412
5630
  });
5413
5631
  };
5414
5632
  const createInteractionsModel = (modelIdOrAgent) => {
@@ -5419,7 +5637,7 @@ function createGoogleGenerativeAI(options = {}) {
5419
5637
  provider: `${providerName}.interactions`,
5420
5638
  baseURL,
5421
5639
  headers: getHeaders,
5422
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils21.generateId,
5640
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils23.generateId,
5423
5641
  fetch: options.fetch
5424
5642
  }
5425
5643
  );