@ai-sdk/google 3.0.131 → 3.0.133

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
@@ -224,7 +224,7 @@ import {
224
224
  } from "@ai-sdk/provider-utils";
225
225
 
226
226
  // src/version.ts
227
- var VERSION = true ? "3.0.131" : "0.0.0-test";
227
+ var VERSION = true ? "3.0.133" : "0.0.0-test";
228
228
 
229
229
  // src/google-generative-ai-embedding-model.ts
230
230
  import {
@@ -473,6 +473,53 @@ import {
473
473
  } from "@ai-sdk/provider-utils";
474
474
  import { z as z7 } from "zod/v4";
475
475
 
476
+ // src/continue-google-stream.ts
477
+ function continueGoogleStream({
478
+ stream,
479
+ getContinuationToken,
480
+ continueStream
481
+ }) {
482
+ let reader = stream.getReader();
483
+ let pendingContinuationToken;
484
+ return new ReadableStream({
485
+ async pull(controller) {
486
+ while (true) {
487
+ const { done, value } = await reader.read();
488
+ if (!done) {
489
+ if (value.success) {
490
+ const token = getContinuationToken(value.value);
491
+ if (token != null) {
492
+ pendingContinuationToken = token;
493
+ }
494
+ }
495
+ controller.enqueue(value);
496
+ return;
497
+ }
498
+ if (pendingContinuationToken == null) {
499
+ controller.close();
500
+ return;
501
+ }
502
+ const continuationToken = pendingContinuationToken;
503
+ pendingContinuationToken = void 0;
504
+ try {
505
+ reader = (await continueStream(continuationToken)).getReader();
506
+ } catch (error) {
507
+ controller.enqueue({
508
+ success: false,
509
+ error,
510
+ rawValue: void 0
511
+ });
512
+ controller.close();
513
+ return;
514
+ }
515
+ }
516
+ },
517
+ async cancel(reason) {
518
+ await reader.cancel(reason);
519
+ }
520
+ });
521
+ }
522
+
476
523
  // src/convert-google-generative-ai-usage.ts
477
524
  function convertGoogleGenerativeAIUsage(usage) {
478
525
  var _a2, _b, _c, _d;
@@ -511,6 +558,63 @@ function convertGoogleGenerativeAIUsage(usage) {
511
558
  raw: usage
512
559
  };
513
560
  }
561
+ function addGoogleGenerativeAIUsageMetadata(a, b) {
562
+ if (a == null || b == null) {
563
+ return b != null ? b : a;
564
+ }
565
+ return {
566
+ ...a,
567
+ ...b,
568
+ promptTokenCount: addCounts(a.promptTokenCount, b.promptTokenCount),
569
+ candidatesTokenCount: addCounts(
570
+ a.candidatesTokenCount,
571
+ b.candidatesTokenCount
572
+ ),
573
+ toolUsePromptTokenCount: addCounts(
574
+ a.toolUsePromptTokenCount,
575
+ b.toolUsePromptTokenCount
576
+ ),
577
+ totalTokenCount: addCounts(a.totalTokenCount, b.totalTokenCount),
578
+ cachedContentTokenCount: addCounts(
579
+ a.cachedContentTokenCount,
580
+ b.cachedContentTokenCount
581
+ ),
582
+ thoughtsTokenCount: addCounts(a.thoughtsTokenCount, b.thoughtsTokenCount),
583
+ promptTokensDetails: addTokenDetails(
584
+ a.promptTokensDetails,
585
+ b.promptTokensDetails
586
+ ),
587
+ cacheTokensDetails: addTokenDetails(
588
+ a.cacheTokensDetails,
589
+ b.cacheTokensDetails
590
+ ),
591
+ candidatesTokensDetails: addTokenDetails(
592
+ a.candidatesTokensDetails,
593
+ b.candidatesTokensDetails
594
+ ),
595
+ toolUsePromptTokensDetails: addTokenDetails(
596
+ a.toolUsePromptTokensDetails,
597
+ b.toolUsePromptTokensDetails
598
+ )
599
+ };
600
+ }
601
+ function addCounts(a, b) {
602
+ return a == null && b == null ? b != null ? b : a : (a != null ? a : 0) + (b != null ? b : 0);
603
+ }
604
+ function addTokenDetails(a, b) {
605
+ var _a2;
606
+ if (a == null || b == null) {
607
+ return b != null ? b : a;
608
+ }
609
+ const tokenCounts = /* @__PURE__ */ new Map();
610
+ for (const { modality, tokenCount } of [...a, ...b]) {
611
+ tokenCounts.set(modality, ((_a2 = tokenCounts.get(modality)) != null ? _a2 : 0) + tokenCount);
612
+ }
613
+ return Array.from(tokenCounts, ([modality, tokenCount]) => ({
614
+ modality,
615
+ tokenCount
616
+ }));
617
+ }
514
618
 
515
619
  // src/convert-json-schema-to-openapi-schema.ts
516
620
  import {
@@ -1416,6 +1520,16 @@ var googleLanguageModelOptions = lazySchema4(
1416
1520
  * `serviceTier` body field. Gemini API only.
1417
1521
  */
1418
1522
  serviceTier: z6.enum(["standard", "flex", "priority"]).optional(),
1523
+ /**
1524
+ * Optional. Resumes a response that stopped with `MAX_TOKENS` because it
1525
+ * used up its `maxOutputTokens` budget (Gemini 4 long decode). Pass the
1526
+ * `continuationToken` from the previous response's provider metadata
1527
+ * together with the original prompt and a higher `maxOutputTokens` (the
1528
+ * budget is cumulative across requests). Requests that reach the
1529
+ * per-request cap while budget remains (`CONTINUATION`) are continued
1530
+ * automatically. Sent as the `continuationToken` body field.
1531
+ */
1532
+ continuationToken: z6.string().optional(),
1419
1533
  /**
1420
1534
  * Optional. Vertex AI only. Sent as the
1421
1535
  * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
@@ -1966,6 +2080,9 @@ function mapGoogleGenerativeAIFinishReason({
1966
2080
  case "STOP":
1967
2081
  return hasToolCalls ? "tool-calls" : "stop";
1968
2082
  case "MAX_TOKENS":
2083
+ // Gemini 4 long decode: the per-request cap was reached while budget
2084
+ // remains. Continued automatically; only surfaced if continuing fails.
2085
+ case "CONTINUATION":
1969
2086
  return "length";
1970
2087
  case "IMAGE_SAFETY":
1971
2088
  case "RECITATION":
@@ -2197,7 +2314,10 @@ var GoogleGenerativeAILanguageModel = class {
2197
2314
  toolConfig,
2198
2315
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
2199
2316
  labels: googleOptions == null ? void 0 : googleOptions.labels,
2200
- serviceTier: bodyServiceTier
2317
+ serviceTier: bodyServiceTier,
2318
+ ...(googleOptions == null ? void 0 : googleOptions.continuationToken) != null && {
2319
+ continuationToken: googleOptions.continuationToken
2320
+ }
2201
2321
  },
2202
2322
  warnings: [...warnings, ...toolWarnings],
2203
2323
  providerOptionsName,
@@ -2205,42 +2325,66 @@ var GoogleGenerativeAILanguageModel = class {
2205
2325
  };
2206
2326
  }
2207
2327
  async doGenerate(options) {
2208
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2328
+ var _a2, _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, _A;
2209
2329
  const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
2210
2330
  const mergedHeaders = combineHeaders3(
2211
2331
  await resolve3(this.config.headers),
2212
2332
  options.headers,
2213
2333
  extraHeaders
2214
2334
  );
2215
- const {
2216
- responseHeaders,
2217
- value: response,
2218
- rawValue: rawResponse
2219
- } = await postJsonToApi3({
2335
+ const generateContent = (body) => postJsonToApi3({
2220
2336
  url: `${this.config.baseURL}/${getModelPath(
2221
2337
  this.modelId
2222
2338
  )}:generateContent`,
2223
2339
  headers: mergedHeaders,
2224
- body: args,
2340
+ body,
2225
2341
  failedResponseHandler: googleFailedResponseHandler,
2226
2342
  successfulResponseHandler: createJsonResponseHandler3(responseSchema),
2227
2343
  abortSignal: options.abortSignal,
2228
2344
  fetch: this.config.fetch
2229
2345
  });
2230
- const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
2231
- const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
2346
+ let {
2347
+ responseHeaders,
2348
+ value: response,
2349
+ rawValue: rawResponse
2350
+ } = await generateContent(args);
2351
+ const continuedParts = [];
2352
+ let continuedUsageMetadata;
2353
+ const firstPromptTokenCount = (_a2 = response.usageMetadata) == null ? void 0 : _a2.promptTokenCount;
2354
+ while (true) {
2355
+ const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
2356
+ const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
2357
+ if (continuationToken == null) {
2358
+ break;
2359
+ }
2360
+ continuedParts.push(...(_d = (_c = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _c.parts) != null ? _d : []);
2361
+ continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
2362
+ continuedUsageMetadata,
2363
+ (_e = response.usageMetadata) != null ? _e : void 0
2364
+ );
2365
+ ({
2366
+ responseHeaders,
2367
+ value: response,
2368
+ rawValue: rawResponse
2369
+ } = await generateContent({ ...args, continuationToken }));
2370
+ }
2371
+ const candidate = (_f = response.candidates) == null ? void 0 : _f[0];
2372
+ const promptBlockReason = (_g = response.promptFeedback) == null ? void 0 : _g.blockReason;
2232
2373
  const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
2233
2374
  promptBlockReason
2234
2375
  ) ? promptBlockReason : void 0;
2235
2376
  const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
2236
- const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
2377
+ const rawFinishReason = (_h = candidate == null ? void 0 : candidate.finishReason) != null ? _h : confirmedPromptBlockReason;
2237
2378
  const content = [];
2238
- const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
2239
- const usageMetadata = response.usageMetadata;
2379
+ const parts = [...continuedParts, ...(_j = (_i = candidate == null ? void 0 : candidate.content) == null ? void 0 : _i.parts) != null ? _j : []];
2380
+ const usageMetadata = addGoogleGenerativeAIUsageMetadata(
2381
+ continuedUsageMetadata,
2382
+ (_k = response.usageMetadata) != null ? _k : void 0
2383
+ );
2240
2384
  let lastCodeExecutionToolCallId;
2241
2385
  let lastServerToolCallId;
2242
2386
  for (const part of parts) {
2243
- if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
2387
+ if ("executableCode" in part && ((_l = part.executableCode) == null ? void 0 : _l.code)) {
2244
2388
  const toolCallId = this.config.generateId();
2245
2389
  lastCodeExecutionToolCallId = toolCallId;
2246
2390
  content.push({
@@ -2258,7 +2402,7 @@ var GoogleGenerativeAILanguageModel = class {
2258
2402
  toolName: "code_execution",
2259
2403
  result: {
2260
2404
  outcome: part.codeExecutionResult.outcome,
2261
- output: (_g = part.codeExecutionResult.output) != null ? _g : ""
2405
+ output: (_m = part.codeExecutionResult.output) != null ? _m : ""
2262
2406
  }
2263
2407
  });
2264
2408
  } else if ("text" in part && part.text != null) {
@@ -2282,9 +2426,9 @@ var GoogleGenerativeAILanguageModel = class {
2282
2426
  } else if ("functionCall" in part && part.functionCall.name != null) {
2283
2427
  content.push({
2284
2428
  type: "tool-call",
2285
- toolCallId: (_h = part.functionCall.id) != null ? _h : this.config.generateId(),
2429
+ toolCallId: (_n = part.functionCall.id) != null ? _n : this.config.generateId(),
2286
2430
  toolName: part.functionCall.name,
2287
- input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
2431
+ input: JSON.stringify((_o = part.functionCall.args) != null ? _o : {}),
2288
2432
  providerMetadata: part.thoughtSignature ? {
2289
2433
  [providerOptionsName]: {
2290
2434
  thoughtSignature: part.thoughtSignature
@@ -2306,13 +2450,13 @@ var GoogleGenerativeAILanguageModel = class {
2306
2450
  } : void 0
2307
2451
  });
2308
2452
  } else if ("toolCall" in part && part.toolCall) {
2309
- const toolCallId = (_j = part.toolCall.id) != null ? _j : this.config.generateId();
2453
+ const toolCallId = (_p = part.toolCall.id) != null ? _p : this.config.generateId();
2310
2454
  lastServerToolCallId = toolCallId;
2311
2455
  content.push({
2312
2456
  type: "tool-call",
2313
2457
  toolCallId,
2314
2458
  toolName: `server:${part.toolCall.toolType}`,
2315
- input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
2459
+ input: JSON.stringify((_q = part.toolCall.args) != null ? _q : {}),
2316
2460
  providerExecuted: true,
2317
2461
  dynamic: true,
2318
2462
  providerMetadata: part.thoughtSignature ? {
@@ -2329,12 +2473,12 @@ var GoogleGenerativeAILanguageModel = class {
2329
2473
  }
2330
2474
  });
2331
2475
  } else if ("toolResponse" in part && part.toolResponse) {
2332
- const responseToolCallId = (_l = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _l : this.config.generateId();
2476
+ const responseToolCallId = (_r = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _r : this.config.generateId();
2333
2477
  content.push({
2334
2478
  type: "tool-result",
2335
2479
  toolCallId: responseToolCallId,
2336
2480
  toolName: `server:${part.toolResponse.toolType}`,
2337
- result: (_m = part.toolResponse.response) != null ? _m : {},
2481
+ result: (_s = part.toolResponse.response) != null ? _s : {},
2338
2482
  providerMetadata: part.thoughtSignature ? {
2339
2483
  [providerOptionsName]: {
2340
2484
  thoughtSignature: part.thoughtSignature,
@@ -2351,10 +2495,10 @@ var GoogleGenerativeAILanguageModel = class {
2351
2495
  lastServerToolCallId = void 0;
2352
2496
  }
2353
2497
  }
2354
- const sources = (_n = extractSources({
2498
+ const sources = (_t = extractSources({
2355
2499
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
2356
2500
  generateId: this.config.generateId
2357
- })) != null ? _n : [];
2501
+ })) != null ? _t : [];
2358
2502
  for (const source of sources) {
2359
2503
  content.push(source);
2360
2504
  }
@@ -2374,19 +2518,21 @@ var GoogleGenerativeAILanguageModel = class {
2374
2518
  warnings,
2375
2519
  providerMetadata: {
2376
2520
  [providerOptionsName]: {
2377
- promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
2378
- groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
2379
- urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
2380
- safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
2521
+ promptFeedback: (_u = response.promptFeedback) != null ? _u : null,
2522
+ groundingMetadata: (_v = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _v : null,
2523
+ urlContextMetadata: (_w = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _w : null,
2524
+ safetyRatings: (_x = candidate == null ? void 0 : candidate.safetyRatings) != null ? _x : null,
2381
2525
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2382
- finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
2383
- serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
2526
+ finishMessage: (_y = candidate == null ? void 0 : candidate.finishMessage) != null ? _y : null,
2527
+ serviceTier: (_z = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _z : null,
2528
+ ...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
2529
+ ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
2384
2530
  }
2385
2531
  },
2386
2532
  request: { body: args },
2387
2533
  response: {
2388
2534
  // TODO timestamp, model id
2389
- id: (_u = response.responseId) != null ? _u : void 0,
2535
+ id: (_A = response.responseId) != null ? _A : void 0,
2390
2536
  headers: responseHeaders,
2391
2537
  body: rawResponse
2392
2538
  }
@@ -2399,27 +2545,40 @@ var GoogleGenerativeAILanguageModel = class {
2399
2545
  options.headers,
2400
2546
  extraHeaders
2401
2547
  );
2402
- const { responseHeaders, value: response } = await postJsonToApi3({
2548
+ const streamGenerateContent = (body) => postJsonToApi3({
2403
2549
  url: `${this.config.baseURL}/${getModelPath(
2404
2550
  this.modelId
2405
2551
  )}:streamGenerateContent?alt=sse`,
2406
2552
  headers,
2407
- body: args,
2553
+ body,
2408
2554
  failedResponseHandler: googleFailedResponseHandler,
2409
2555
  successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
2410
2556
  abortSignal: options.abortSignal,
2411
2557
  fetch: this.config.fetch
2412
2558
  });
2559
+ const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
2560
+ const response = continueGoogleStream({
2561
+ stream: firstResponse,
2562
+ getContinuationToken: (chunk) => {
2563
+ var _a2, _b;
2564
+ const candidate = (_a2 = chunk.candidates) == null ? void 0 : _a2[0];
2565
+ return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
2566
+ },
2567
+ continueStream: async (continuationToken) => (await streamGenerateContent({ ...args, continuationToken })).value
2568
+ });
2413
2569
  let finishReason = {
2414
2570
  unified: "other",
2415
2571
  raw: void 0
2416
2572
  };
2417
2573
  let usage = void 0;
2574
+ let continuedUsage = void 0;
2575
+ let initialPromptTokenCount = void 0;
2418
2576
  let promptFeedback = null;
2419
2577
  let lastGroundingMetadata = null;
2420
2578
  let lastUrlContextMetadata = null;
2421
2579
  let lastSafetyRatings = null;
2422
2580
  let lastFinishMessage = null;
2581
+ let lastContinuationToken = null;
2423
2582
  let confirmedPromptBlockReason;
2424
2583
  const generateId3 = this.config.generateId;
2425
2584
  let hasToolCalls = false;
@@ -2510,6 +2669,9 @@ var GoogleGenerativeAILanguageModel = class {
2510
2669
  if (candidate.finishMessage != null) {
2511
2670
  lastFinishMessage = candidate.finishMessage;
2512
2671
  }
2672
+ if (candidate.continuationToken != null) {
2673
+ lastContinuationToken = candidate.continuationToken;
2674
+ }
2513
2675
  }
2514
2676
  if (confirmedPromptBlockReason != null || candidate == null) {
2515
2677
  return;
@@ -2794,6 +2956,16 @@ var GoogleGenerativeAILanguageModel = class {
2794
2956
  }
2795
2957
  }
2796
2958
  }
2959
+ if (candidate.finishReason === "CONTINUATION") {
2960
+ if (continuedUsage == null) {
2961
+ initialPromptTokenCount = usage == null ? void 0 : usage.promptTokenCount;
2962
+ }
2963
+ continuedUsage = addGoogleGenerativeAIUsageMetadata(
2964
+ continuedUsage,
2965
+ usage
2966
+ );
2967
+ usage = void 0;
2968
+ }
2797
2969
  if (candidate.finishReason != null) {
2798
2970
  finishReason = {
2799
2971
  unified: mapGoogleGenerativeAIFinishReason({
@@ -2806,6 +2978,7 @@ var GoogleGenerativeAILanguageModel = class {
2806
2978
  },
2807
2979
  flush(controller) {
2808
2980
  var _a2;
2981
+ usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
2809
2982
  if (currentTextBlockId !== null) {
2810
2983
  controller.enqueue({
2811
2984
  type: "text-end",
@@ -2830,7 +3003,12 @@ var GoogleGenerativeAILanguageModel = class {
2830
3003
  safetyRatings: lastSafetyRatings,
2831
3004
  usageMetadata: usage != null ? usage : null,
2832
3005
  finishMessage: lastFinishMessage,
2833
- serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
3006
+ serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
3007
+ // Only surface the token when the response stopped early
3008
+ // (budget used up, or continuing failed), not for the
3009
+ // checkpoint tokens of a stream that finished normally.
3010
+ ...lastContinuationToken != null && (finishReason.raw === "MAX_TOKENS" || finishReason.raw === "CONTINUATION") ? { continuationToken: lastContinuationToken } : {},
3011
+ ...initialPromptTokenCount != null ? { initialPromptTokenCount } : {}
2834
3012
  }
2835
3013
  }
2836
3014
  });
@@ -3102,6 +3280,7 @@ var responseSchema = lazySchema5(
3102
3280
  content: getContentSchema().nullish().or(z7.object({}).strict()),
3103
3281
  finishReason: z7.string().nullish(),
3104
3282
  finishMessage: z7.string().nullish(),
3283
+ continuationToken: z7.string().nullish(),
3105
3284
  safetyRatings: z7.array(getSafetyRatingSchema()).nullish(),
3106
3285
  groundingMetadata: getGroundingMetadataSchema().nullish(),
3107
3286
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -3124,6 +3303,7 @@ var chunkSchema = lazySchema5(
3124
3303
  content: getContentSchema().nullish(),
3125
3304
  finishReason: z7.string().nullish(),
3126
3305
  finishMessage: z7.string().nullish(),
3306
+ continuationToken: z7.string().nullish(),
3127
3307
  safetyRatings: z7.array(getSafetyRatingSchema()).nullish(),
3128
3308
  groundingMetadata: getGroundingMetadataSchema().nullish(),
3129
3309
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -6677,7 +6857,7 @@ var GoogleInteractionsLanguageModel = class {
6677
6857
  }
6678
6858
  async doGenerate(options) {
6679
6859
  var _a2, _b, _c, _d, _e, _f;
6680
- const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
6860
+ const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
6681
6861
  const url = `${this.config.baseURL}/interactions`;
6682
6862
  const mergedHeaders = combineHeaders7(
6683
6863
  INTERACTIONS_API_REVISION_HEADER,
@@ -6700,7 +6880,7 @@ var GoogleInteractionsLanguageModel = class {
6700
6880
  value: response,
6701
6881
  rawValue: rawResponse
6702
6882
  } = postResult;
6703
- if (isAgent && !isTerminalStatus(response.status)) {
6883
+ if ((isAgent || isBackground) && !isTerminalStatus(response.status)) {
6704
6884
  const polled = await pollGoogleInteractionUntilTerminal({
6705
6885
  baseURL: this.config.baseURL,
6706
6886
  interactionId: response.id,