@ai-sdk/google 3.0.143 → 3.0.144

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.
@@ -1584,7 +1584,7 @@ var GoogleJSONAccumulator = class {
1584
1584
  const rawPath = jsonPath.replace(/^\$\./, "");
1585
1585
  if (!rawPath || rawPath === "$") continue;
1586
1586
  const segments = parsePath(rawPath);
1587
- if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
1587
+ if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
1588
1588
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1589
1589
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
1590
1590
  if (isStringContinuation) {
@@ -1805,9 +1805,17 @@ function getNestedValue(obj, segments) {
1805
1805
  }
1806
1806
  return current;
1807
1807
  }
1808
- function hasContiguousIndexes(obj, segments) {
1808
+ function normalizeAndCheckIndexes(obj, segments) {
1809
1809
  let current = obj;
1810
- for (const pathSegment of segments) {
1810
+ for (let i = 0; i < segments.length; i++) {
1811
+ let pathSegment = segments[i];
1812
+ if (Array.isArray(current) && typeof pathSegment === "string") {
1813
+ const index = Number(pathSegment);
1814
+ if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
1815
+ pathSegment = index;
1816
+ segments[i] = index;
1817
+ }
1818
+ }
1811
1819
  if (typeof pathSegment === "number") {
1812
1820
  const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
1813
1821
  if (length !== void 0 && pathSegment > length) return false;
@@ -2090,7 +2098,7 @@ var GoogleGenerativeAILanguageModel = class {
2090
2098
  };
2091
2099
  }
2092
2100
  async doGenerate(options) {
2093
- 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, _A, _B;
2101
+ 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, _A, _B, _C;
2094
2102
  const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
2095
2103
  const mergedHeaders = (0, import_provider_utils5.combineHeaders)(
2096
2104
  await (0, import_provider_utils5.resolve)(this.config.headers),
@@ -2292,7 +2300,7 @@ var GoogleGenerativeAILanguageModel = class {
2292
2300
  safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
2293
2301
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2294
2302
  finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
2295
- serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
2303
+ serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
2296
2304
  ...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
2297
2305
  ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
2298
2306
  }
@@ -2300,7 +2308,7 @@ var GoogleGenerativeAILanguageModel = class {
2300
2308
  request: { body: args },
2301
2309
  response: {
2302
2310
  // TODO timestamp, model id
2303
- id: (_B = response.responseId) != null ? _B : void 0,
2311
+ id: (_C = response.responseId) != null ? _C : void 0,
2304
2312
  headers: responseHeaders,
2305
2313
  body: rawResponse
2306
2314
  }
@@ -2776,7 +2784,7 @@ var GoogleGenerativeAILanguageModel = class {
2776
2784
  }
2777
2785
  },
2778
2786
  flush(controller) {
2779
- var _a;
2787
+ var _a, _b;
2780
2788
  usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
2781
2789
  if (currentTextBlockId !== null) {
2782
2790
  controller.enqueue({
@@ -2808,7 +2816,7 @@ var GoogleGenerativeAILanguageModel = class {
2808
2816
  safetyRatings: lastSafetyRatings,
2809
2817
  usageMetadata: usage != null ? usage : null,
2810
2818
  finishMessage: lastFinishMessage,
2811
- serviceTier: (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : null,
2819
+ serviceTier: (_b = (_a = usage == null ? void 0 : usage.serviceTier) != null ? _a : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
2812
2820
  // Only surface the token when the response stopped early
2813
2821
  // (budget used up, or continuing failed), not for the
2814
2822
  // checkpoint tokens of a stream that finished normally.