@ai-sdk/google 2.0.102 → 2.0.103

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,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.103
4
+
5
+ ### Patch Changes
6
+
7
+ - 7c28815: feat(google): add `gemini-4-argon` model id and long decode support: requests that reach the per-request cap (`CONTINUATION`) are continued automatically with usage summed across requests and the first request's prompt token count exposed as `providerMetadata.google.initialPromptTokenCount`, and the `continuationToken` provider option / provider metadata resume responses that used up their `maxOutputTokens` budget
8
+
3
9
  ## 2.0.102
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -47,6 +47,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
47
47
  } | undefined;
48
48
  } | undefined;
49
49
  serviceTier?: "standard" | "flex" | "priority" | undefined;
50
+ continuationToken?: string | undefined;
50
51
  }>;
51
52
  type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
52
53
 
@@ -80,6 +81,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
80
81
  })[] | null | undefined;
81
82
  } | null | undefined;
82
83
  finishReason?: string | null | undefined;
84
+ continuationToken?: string | null | undefined;
83
85
  safetyRatings?: {
84
86
  category?: string | null | undefined;
85
87
  probability?: string | null | undefined;
@@ -184,6 +186,22 @@ interface GoogleGenerativeAIProviderMetadata {
184
186
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
185
187
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
186
188
  serviceTier: string | null;
189
+ /**
190
+ * Opaque token returned when a response stops with `MAX_TOKENS` because it
191
+ * used up its `maxOutputTokens` budget. Pass it back as
192
+ * `providerOptions.google.continuationToken` together with a higher
193
+ * `maxOutputTokens` and the original prompt to resume generation.
194
+ */
195
+ continuationToken?: string | null;
196
+ /**
197
+ * Prompt token count of the first request of a long decode response that
198
+ * was continued automatically (Gemini 4). Usage is summed across requests
199
+ * to match billing, and each continued request re-sends the prompt plus all
200
+ * output so far as input. Use this value instead of the summed input tokens
201
+ * for context window checks and compaction. Only present when the response
202
+ * spanned more than one request.
203
+ */
204
+ initialPromptTokenCount?: number | null;
187
205
  }
188
206
 
189
207
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
package/dist/index.d.ts CHANGED
@@ -47,6 +47,7 @@ declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySche
47
47
  } | undefined;
48
48
  } | undefined;
49
49
  serviceTier?: "standard" | "flex" | "priority" | undefined;
50
+ continuationToken?: string | undefined;
50
51
  }>;
51
52
  type GoogleGenerativeAIProviderOptions = InferValidator<typeof googleGenerativeAIProviderOptions>;
52
53
 
@@ -80,6 +81,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
80
81
  })[] | null | undefined;
81
82
  } | null | undefined;
82
83
  finishReason?: string | null | undefined;
84
+ continuationToken?: string | null | undefined;
83
85
  safetyRatings?: {
84
86
  category?: string | null | undefined;
85
87
  probability?: string | null | undefined;
@@ -184,6 +186,22 @@ interface GoogleGenerativeAIProviderMetadata {
184
186
  urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
185
187
  safetyRatings: GoogleGenerativeAISafetyRating[] | null;
186
188
  serviceTier: string | null;
189
+ /**
190
+ * Opaque token returned when a response stops with `MAX_TOKENS` because it
191
+ * used up its `maxOutputTokens` budget. Pass it back as
192
+ * `providerOptions.google.continuationToken` together with a higher
193
+ * `maxOutputTokens` and the original prompt to resume generation.
194
+ */
195
+ continuationToken?: string | null;
196
+ /**
197
+ * Prompt token count of the first request of a long decode response that
198
+ * was continued automatically (Gemini 4). Usage is summed across requests
199
+ * to match billing, and each continued request re-sends the prompt plus all
200
+ * output so far as input. Use this value instead of the summed input tokens
201
+ * for context window checks and compaction. Only present when the response
202
+ * spanned more than one request.
203
+ */
204
+ initialPromptTokenCount?: number | null;
187
205
  }
188
206
 
189
207
  type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
30
30
  var import_provider_utils15 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.102" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.103" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -241,6 +241,100 @@ var googleGenerativeAISingleEmbeddingResponseSchema = (0, import_provider_utils3
241
241
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
242
242
  var import_v45 = require("zod/v4");
243
243
 
244
+ // src/add-google-generative-ai-usage-metadata.ts
245
+ function addGoogleGenerativeAIUsageMetadata(a, b) {
246
+ if (a == null || b == null) {
247
+ return b != null ? b : a;
248
+ }
249
+ return {
250
+ ...a,
251
+ ...b,
252
+ promptTokenCount: addCounts(a.promptTokenCount, b.promptTokenCount),
253
+ candidatesTokenCount: addCounts(
254
+ a.candidatesTokenCount,
255
+ b.candidatesTokenCount
256
+ ),
257
+ totalTokenCount: addCounts(a.totalTokenCount, b.totalTokenCount),
258
+ cachedContentTokenCount: addCounts(
259
+ a.cachedContentTokenCount,
260
+ b.cachedContentTokenCount
261
+ ),
262
+ thoughtsTokenCount: addCounts(a.thoughtsTokenCount, b.thoughtsTokenCount),
263
+ promptTokensDetails: addTokenDetails(
264
+ a.promptTokensDetails,
265
+ b.promptTokensDetails
266
+ ),
267
+ candidatesTokensDetails: addTokenDetails(
268
+ a.candidatesTokensDetails,
269
+ b.candidatesTokensDetails
270
+ )
271
+ };
272
+ }
273
+ function addCounts(a, b) {
274
+ return a == null && b == null ? b != null ? b : a : (a != null ? a : 0) + (b != null ? b : 0);
275
+ }
276
+ function addTokenDetails(a, b) {
277
+ var _a;
278
+ if (a == null || b == null) {
279
+ return b != null ? b : a;
280
+ }
281
+ const tokenCounts = /* @__PURE__ */ new Map();
282
+ for (const { modality, tokenCount } of [...a, ...b]) {
283
+ tokenCounts.set(modality, ((_a = tokenCounts.get(modality)) != null ? _a : 0) + tokenCount);
284
+ }
285
+ return Array.from(tokenCounts, ([modality, tokenCount]) => ({
286
+ modality,
287
+ tokenCount
288
+ }));
289
+ }
290
+
291
+ // src/continue-google-stream.ts
292
+ function continueGoogleStream({
293
+ stream,
294
+ getContinuationToken,
295
+ continueStream
296
+ }) {
297
+ let reader = stream.getReader();
298
+ let pendingContinuationToken;
299
+ return new ReadableStream({
300
+ async pull(controller) {
301
+ while (true) {
302
+ const { done, value } = await reader.read();
303
+ if (!done) {
304
+ if (value.success) {
305
+ const token = getContinuationToken(value.value);
306
+ if (token != null) {
307
+ pendingContinuationToken = token;
308
+ }
309
+ }
310
+ controller.enqueue(value);
311
+ return;
312
+ }
313
+ if (pendingContinuationToken == null) {
314
+ controller.close();
315
+ return;
316
+ }
317
+ const continuationToken = pendingContinuationToken;
318
+ pendingContinuationToken = void 0;
319
+ try {
320
+ reader = (await continueStream(continuationToken)).getReader();
321
+ } catch (error) {
322
+ controller.enqueue({
323
+ success: false,
324
+ error,
325
+ rawValue: void 0
326
+ });
327
+ controller.close();
328
+ return;
329
+ }
330
+ }
331
+ },
332
+ async cancel(reason) {
333
+ await reader.cancel(reason);
334
+ }
335
+ });
336
+ }
337
+
244
338
  // src/convert-json-schema-to-openapi-schema.ts
245
339
  var import_provider2 = require("@ai-sdk/provider");
246
340
  var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
@@ -896,7 +990,17 @@ var googleGenerativeAIProviderOptions = (0, import_provider_utils5.lazySchema)(
896
990
  /**
897
991
  * Optional. The service tier to use for the request.
898
992
  */
899
- serviceTier: import_v44.z.enum(["standard", "flex", "priority"]).optional()
993
+ serviceTier: import_v44.z.enum(["standard", "flex", "priority"]).optional(),
994
+ /**
995
+ * Optional. Resumes a response that stopped with `MAX_TOKENS` because it
996
+ * used up its `maxOutputTokens` budget (Gemini 4 long decode). Pass the
997
+ * `continuationToken` from the previous response's provider metadata
998
+ * together with the original prompt and a higher `maxOutputTokens` (the
999
+ * budget is cumulative across requests). Requests that reach the
1000
+ * per-request cap while budget remains (`CONTINUATION`) are continued
1001
+ * automatically. Sent as the `continuationToken` body field.
1002
+ */
1003
+ continuationToken: import_v44.z.string().optional()
900
1004
  })
901
1005
  )
902
1006
  );
@@ -1194,6 +1298,9 @@ function mapGoogleGenerativeAIFinishReason({
1194
1298
  case "STOP":
1195
1299
  return hasToolCalls ? "tool-calls" : "stop";
1196
1300
  case "MAX_TOKENS":
1301
+ // Gemini 4 long decode: the per-request cap was reached while budget
1302
+ // remains. Continued automatically; only surfaced if continuing fails.
1303
+ case "CONTINUATION":
1197
1304
  return "length";
1198
1305
  case "IMAGE_SAFETY":
1199
1306
  case "RECITATION":
@@ -1368,43 +1475,70 @@ var GoogleGenerativeAILanguageModel = class {
1368
1475
  } : googleToolConfig,
1369
1476
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
1370
1477
  labels: googleOptions == null ? void 0 : googleOptions.labels,
1371
- serviceTier: sanitizedServiceTier
1478
+ serviceTier: sanitizedServiceTier,
1479
+ ...(googleOptions == null ? void 0 : googleOptions.continuationToken) != null && {
1480
+ continuationToken: googleOptions.continuationToken
1481
+ }
1372
1482
  },
1373
1483
  warnings: [...warnings, ...toolWarnings]
1374
1484
  };
1375
1485
  }
1376
1486
  async doGenerate(options) {
1377
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1487
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1378
1488
  const { args, warnings } = await this.getArgs(options);
1379
1489
  const body = JSON.stringify(args);
1380
1490
  const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
1381
1491
  await (0, import_provider_utils6.resolve)(this.config.headers),
1382
1492
  options.headers
1383
1493
  );
1384
- const {
1385
- responseHeaders,
1386
- value: response,
1387
- rawValue: rawResponse
1388
- } = await (0, import_provider_utils6.postJsonToApi)({
1494
+ const generateContent = (body2) => (0, import_provider_utils6.postJsonToApi)({
1389
1495
  url: `${this.config.baseURL}/${getModelPath(
1390
1496
  this.modelId
1391
1497
  )}:generateContent`,
1392
1498
  headers: mergedHeaders,
1393
- body: args,
1499
+ body: body2,
1394
1500
  failedResponseHandler: googleFailedResponseHandler,
1395
1501
  successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(responseSchema),
1396
1502
  abortSignal: options.abortSignal,
1397
1503
  fetch: this.config.fetch
1398
1504
  });
1399
- const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1400
- const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1505
+ let {
1506
+ responseHeaders,
1507
+ value: response,
1508
+ rawValue: rawResponse
1509
+ } = await generateContent(args);
1510
+ const continuedParts = [];
1511
+ let continuedUsageMetadata;
1512
+ const firstPromptTokenCount = (_a = response.usageMetadata) == null ? void 0 : _a.promptTokenCount;
1513
+ while (true) {
1514
+ const candidate2 = (_b = response.candidates) == null ? void 0 : _b[0];
1515
+ const continuationToken = (candidate2 == null ? void 0 : candidate2.finishReason) === "CONTINUATION" ? candidate2.continuationToken : void 0;
1516
+ if (continuationToken == null) {
1517
+ break;
1518
+ }
1519
+ continuedParts.push(...(_d = (_c = candidate2 == null ? void 0 : candidate2.content) == null ? void 0 : _c.parts) != null ? _d : []);
1520
+ continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
1521
+ continuedUsageMetadata,
1522
+ (_e = response.usageMetadata) != null ? _e : void 0
1523
+ );
1524
+ ({
1525
+ responseHeaders,
1526
+ value: response,
1527
+ rawValue: rawResponse
1528
+ } = await generateContent({ ...args, continuationToken }));
1529
+ }
1530
+ const candidate = (_f = response.candidates) == null ? void 0 : _f[0];
1531
+ const promptBlockReason = (_g = response.promptFeedback) == null ? void 0 : _g.blockReason;
1401
1532
  const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
1402
1533
  const content = [];
1403
- const parts = (_d = (_c = candidate == null ? void 0 : candidate.content) == null ? void 0 : _c.parts) != null ? _d : [];
1404
- const usageMetadata = response.usageMetadata;
1534
+ const parts = [...continuedParts, ...(_i = (_h = candidate == null ? void 0 : candidate.content) == null ? void 0 : _h.parts) != null ? _i : []];
1535
+ const usageMetadata = addGoogleGenerativeAIUsageMetadata(
1536
+ continuedUsageMetadata,
1537
+ (_j = response.usageMetadata) != null ? _j : void 0
1538
+ );
1405
1539
  let lastCodeExecutionToolCallId;
1406
1540
  for (const part of parts) {
1407
- if ("executableCode" in part && ((_e = part.executableCode) == null ? void 0 : _e.code)) {
1541
+ if ("executableCode" in part && ((_k = part.executableCode) == null ? void 0 : _k.code)) {
1408
1542
  const toolCallId = this.config.generateId();
1409
1543
  lastCodeExecutionToolCallId = toolCallId;
1410
1544
  content.push({
@@ -1445,7 +1579,7 @@ var GoogleGenerativeAILanguageModel = class {
1445
1579
  } else if ("functionCall" in part) {
1446
1580
  content.push({
1447
1581
  type: "tool-call",
1448
- toolCallId: (_f = part.functionCall.id) != null ? _f : this.config.generateId(),
1582
+ toolCallId: (_l = part.functionCall.id) != null ? _l : this.config.generateId(),
1449
1583
  toolName: part.functionCall.name,
1450
1584
  input: JSON.stringify(part.functionCall.args),
1451
1585
  providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
@@ -1458,10 +1592,10 @@ var GoogleGenerativeAILanguageModel = class {
1458
1592
  });
1459
1593
  }
1460
1594
  }
1461
- const sources = (_g = extractSources({
1595
+ const sources = (_m = extractSources({
1462
1596
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
1463
1597
  generateId: this.config.generateId
1464
- })) != null ? _g : [];
1598
+ })) != null ? _m : [];
1465
1599
  for (const source of sources) {
1466
1600
  content.push(source);
1467
1601
  }
@@ -1472,20 +1606,22 @@ var GoogleGenerativeAILanguageModel = class {
1472
1606
  hasToolCalls: content.some((part) => part.type === "tool-call")
1473
1607
  }),
1474
1608
  usage: {
1475
- inputTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _h : void 0,
1476
- outputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _i : void 0,
1477
- totalTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _j : void 0,
1478
- reasoningTokens: (_k = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _k : void 0,
1479
- cachedInputTokens: (_l = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _l : void 0
1609
+ inputTokens: (_n = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _n : void 0,
1610
+ outputTokens: (_o = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _o : void 0,
1611
+ totalTokens: (_p = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _p : void 0,
1612
+ reasoningTokens: (_q = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _q : void 0,
1613
+ cachedInputTokens: (_r = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _r : void 0
1480
1614
  },
1481
1615
  warnings,
1482
1616
  providerMetadata: {
1483
1617
  google: {
1484
- promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
1485
- groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
1486
- urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
1487
- safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
1488
- serviceTier: (_q = response.serviceTier) != null ? _q : null,
1618
+ promptFeedback: (_s = response.promptFeedback) != null ? _s : null,
1619
+ groundingMetadata: (_t = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _t : null,
1620
+ urlContextMetadata: (_u = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _u : null,
1621
+ safetyRatings: (_v = candidate == null ? void 0 : candidate.safetyRatings) != null ? _v : null,
1622
+ serviceTier: (_w = response.serviceTier) != null ? _w : null,
1623
+ ...(candidate == null ? void 0 : candidate.continuationToken) != null ? { continuationToken: candidate.continuationToken } : {},
1624
+ ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {},
1489
1625
  usageMetadata: usageMetadata != null ? usageMetadata : null
1490
1626
  }
1491
1627
  },
@@ -1504,17 +1640,27 @@ var GoogleGenerativeAILanguageModel = class {
1504
1640
  await (0, import_provider_utils6.resolve)(this.config.headers),
1505
1641
  options.headers
1506
1642
  );
1507
- const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
1643
+ const streamGenerateContent = (body2) => (0, import_provider_utils6.postJsonToApi)({
1508
1644
  url: `${this.config.baseURL}/${getModelPath(
1509
1645
  this.modelId
1510
1646
  )}:streamGenerateContent?alt=sse`,
1511
1647
  headers,
1512
- body: args,
1648
+ body: body2,
1513
1649
  failedResponseHandler: googleFailedResponseHandler,
1514
1650
  successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(chunkSchema),
1515
1651
  abortSignal: options.abortSignal,
1516
1652
  fetch: this.config.fetch
1517
1653
  });
1654
+ const { responseHeaders, value: firstResponse } = await streamGenerateContent(args);
1655
+ const response = continueGoogleStream({
1656
+ stream: firstResponse,
1657
+ getContinuationToken: (chunk) => {
1658
+ var _a, _b;
1659
+ const candidate = (_a = chunk.candidates) == null ? void 0 : _a[0];
1660
+ return (candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION" ? (_b = candidate.continuationToken) != null ? _b : void 0 : void 0;
1661
+ },
1662
+ continueStream: async (continuationToken) => (await streamGenerateContent({ ...args, continuationToken })).value
1663
+ });
1518
1664
  let finishReason = "unknown";
1519
1665
  const usage = {
1520
1666
  inputTokens: void 0,
@@ -1525,6 +1671,10 @@ var GoogleGenerativeAILanguageModel = class {
1525
1671
  let lastGroundingMetadata = null;
1526
1672
  let lastUrlContextMetadata = null;
1527
1673
  let serviceTier = null;
1674
+ let requestUsageMetadata;
1675
+ let continuedUsageMetadata;
1676
+ let lastContinuationToken = null;
1677
+ let initialPromptTokenCount = void 0;
1528
1678
  const generateId3 = this.config.generateId;
1529
1679
  let hasToolCalls = false;
1530
1680
  let currentTextBlockId = null;
@@ -1548,7 +1698,13 @@ var GoogleGenerativeAILanguageModel = class {
1548
1698
  return;
1549
1699
  }
1550
1700
  const value = chunk.value;
1551
- const usageMetadata = value.usageMetadata;
1701
+ if (value.usageMetadata != null) {
1702
+ requestUsageMetadata = value.usageMetadata;
1703
+ }
1704
+ const usageMetadata = value.usageMetadata == null ? void 0 : addGoogleGenerativeAIUsageMetadata(
1705
+ continuedUsageMetadata,
1706
+ requestUsageMetadata
1707
+ );
1552
1708
  if (usageMetadata != null) {
1553
1709
  usage.inputTokens = (_a = usageMetadata.promptTokenCount) != null ? _a : void 0;
1554
1710
  usage.outputTokens = (_b = usageMetadata.candidatesTokenCount) != null ? _b : void 0;
@@ -1560,6 +1716,19 @@ var GoogleGenerativeAILanguageModel = class {
1560
1716
  serviceTier = value.serviceTier;
1561
1717
  }
1562
1718
  const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
1719
+ if ((candidate == null ? void 0 : candidate.continuationToken) != null) {
1720
+ lastContinuationToken = candidate.continuationToken;
1721
+ }
1722
+ if ((candidate == null ? void 0 : candidate.finishReason) === "CONTINUATION") {
1723
+ if (continuedUsageMetadata == null) {
1724
+ initialPromptTokenCount = requestUsageMetadata == null ? void 0 : requestUsageMetadata.promptTokenCount;
1725
+ }
1726
+ continuedUsageMetadata = addGoogleGenerativeAIUsageMetadata(
1727
+ continuedUsageMetadata,
1728
+ requestUsageMetadata
1729
+ );
1730
+ requestUsageMetadata = void 0;
1731
+ }
1563
1732
  if (candidate == null) {
1564
1733
  const promptBlockReason2 = (_g = value.promptFeedback) == null ? void 0 : _g.blockReason;
1565
1734
  if (promptBlockReason2 != null) {
@@ -1742,7 +1911,12 @@ var GoogleGenerativeAILanguageModel = class {
1742
1911
  groundingMetadata: lastGroundingMetadata,
1743
1912
  urlContextMetadata: lastUrlContextMetadata,
1744
1913
  safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
1745
- serviceTier
1914
+ serviceTier,
1915
+ // Only surface the token when the response stopped early
1916
+ // (budget used up, or continuing failed), not for the
1917
+ // checkpoint tokens of a stream that finished normally.
1918
+ ...lastContinuationToken != null && (rawFinishReason === "MAX_TOKENS" || rawFinishReason === "CONTINUATION") ? { continuationToken: lastContinuationToken } : {},
1919
+ ...initialPromptTokenCount != null ? { initialPromptTokenCount } : {}
1746
1920
  }
1747
1921
  };
1748
1922
  if (usageMetadata != null) {
@@ -2013,6 +2187,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
2013
2187
  import_v45.z.object({
2014
2188
  content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
2015
2189
  finishReason: import_v45.z.string().nullish(),
2190
+ continuationToken: import_v45.z.string().nullish(),
2016
2191
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
2017
2192
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2018
2193
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
@@ -2034,6 +2209,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
2034
2209
  import_v45.z.object({
2035
2210
  content: getContentSchema().nullish(),
2036
2211
  finishReason: import_v45.z.string().nullish(),
2212
+ continuationToken: import_v45.z.string().nullish(),
2037
2213
  safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
2038
2214
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2039
2215
  urlContextMetadata: getUrlContextMetadataSchema().nullish()