@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.
package/dist/index.mjs CHANGED
@@ -272,7 +272,7 @@ import {
272
272
  } from "@ai-sdk/provider-utils";
273
273
 
274
274
  // src/version.ts
275
- var VERSION = true ? "3.0.143" : "0.0.0-test";
275
+ var VERSION = true ? "3.0.144" : "0.0.0-test";
276
276
 
277
277
  // src/google-generative-ai-embedding-model.ts
278
278
  import {
@@ -2039,7 +2039,7 @@ var GoogleJSONAccumulator = class {
2039
2039
  const rawPath = jsonPath.replace(/^\$\./, "");
2040
2040
  if (!rawPath || rawPath === "$") continue;
2041
2041
  const segments = parsePath(rawPath);
2042
- if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
2042
+ if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
2043
2043
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
2044
2044
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
2045
2045
  if (isStringContinuation) {
@@ -2260,9 +2260,17 @@ function getNestedValue(obj, segments) {
2260
2260
  }
2261
2261
  return current;
2262
2262
  }
2263
- function hasContiguousIndexes(obj, segments) {
2263
+ function normalizeAndCheckIndexes(obj, segments) {
2264
2264
  let current = obj;
2265
- for (const pathSegment of segments) {
2265
+ for (let i = 0; i < segments.length; i++) {
2266
+ let pathSegment = segments[i];
2267
+ if (Array.isArray(current) && typeof pathSegment === "string") {
2268
+ const index = Number(pathSegment);
2269
+ if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
2270
+ pathSegment = index;
2271
+ segments[i] = index;
2272
+ }
2273
+ }
2266
2274
  if (typeof pathSegment === "number") {
2267
2275
  const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
2268
2276
  if (length !== void 0 && pathSegment > length) return false;
@@ -2545,7 +2553,7 @@ var GoogleGenerativeAILanguageModel = class {
2545
2553
  };
2546
2554
  }
2547
2555
  async doGenerate(options) {
2548
- 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, _B;
2556
+ 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, _B, _C;
2549
2557
  const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
2550
2558
  const mergedHeaders = combineHeaders3(
2551
2559
  await resolve3(this.config.headers),
@@ -2747,7 +2755,7 @@ var GoogleGenerativeAILanguageModel = class {
2747
2755
  safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
2748
2756
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2749
2757
  finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
2750
- serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
2758
+ serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
2751
2759
  ...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
2752
2760
  ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
2753
2761
  }
@@ -2755,7 +2763,7 @@ var GoogleGenerativeAILanguageModel = class {
2755
2763
  request: { body: args },
2756
2764
  response: {
2757
2765
  // TODO timestamp, model id
2758
- id: (_B = response.responseId) != null ? _B : void 0,
2766
+ id: (_C = response.responseId) != null ? _C : void 0,
2759
2767
  headers: responseHeaders,
2760
2768
  body: rawResponse
2761
2769
  }
@@ -3231,7 +3239,7 @@ var GoogleGenerativeAILanguageModel = class {
3231
3239
  }
3232
3240
  },
3233
3241
  flush(controller) {
3234
- var _a2;
3242
+ var _a2, _b;
3235
3243
  usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
3236
3244
  if (currentTextBlockId !== null) {
3237
3245
  controller.enqueue({
@@ -3263,7 +3271,7 @@ var GoogleGenerativeAILanguageModel = class {
3263
3271
  safetyRatings: lastSafetyRatings,
3264
3272
  usageMetadata: usage != null ? usage : null,
3265
3273
  finishMessage: lastFinishMessage,
3266
- serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
3274
+ serviceTier: (_b = (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
3267
3275
  // Only surface the token when the response stopped early
3268
3276
  // (budget used up, or continuing failed), not for the
3269
3277
  // checkpoint tokens of a stream that finished normally.