@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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.144
4
+
5
+ ### Patch Changes
6
+
7
+ - d55ff04: Preserve the served service tier from the `x-gemini-service-tier` response header when usage metadata omits it, for generated and streamed responses.
8
+ - 733b167: Apply contiguous array-index validation to dotted numeric paths in streamed tool arguments, while preserving numeric object keys and valid contiguous array updates.
9
+ - Updated dependencies [88bb257]
10
+ - @ai-sdk/provider-utils@4.0.66
11
+
3
12
  ## 3.0.143
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -278,7 +278,7 @@ var googleInteractionsTranscriptionResponseSchema = (0, import_provider_utils3.l
278
278
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
279
279
 
280
280
  // src/version.ts
281
- var VERSION = true ? "3.0.143" : "0.0.0-test";
281
+ var VERSION = true ? "3.0.144" : "0.0.0-test";
282
282
 
283
283
  // src/google-generative-ai-embedding-model.ts
284
284
  var import_provider2 = require("@ai-sdk/provider");
@@ -2001,7 +2001,7 @@ var GoogleJSONAccumulator = class {
2001
2001
  const rawPath = jsonPath.replace(/^\$\./, "");
2002
2002
  if (!rawPath || rawPath === "$") continue;
2003
2003
  const segments = parsePath(rawPath);
2004
- if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
2004
+ if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
2005
2005
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
2006
2006
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
2007
2007
  if (isStringContinuation) {
@@ -2222,9 +2222,17 @@ function getNestedValue(obj, segments) {
2222
2222
  }
2223
2223
  return current;
2224
2224
  }
2225
- function hasContiguousIndexes(obj, segments) {
2225
+ function normalizeAndCheckIndexes(obj, segments) {
2226
2226
  let current = obj;
2227
- for (const pathSegment of segments) {
2227
+ for (let i = 0; i < segments.length; i++) {
2228
+ let pathSegment = segments[i];
2229
+ if (Array.isArray(current) && typeof pathSegment === "string") {
2230
+ const index = Number(pathSegment);
2231
+ if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
2232
+ pathSegment = index;
2233
+ segments[i] = index;
2234
+ }
2235
+ }
2228
2236
  if (typeof pathSegment === "number") {
2229
2237
  const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
2230
2238
  if (length !== void 0 && pathSegment > length) return false;
@@ -2507,7 +2515,7 @@ var GoogleGenerativeAILanguageModel = class {
2507
2515
  };
2508
2516
  }
2509
2517
  async doGenerate(options) {
2510
- 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;
2518
+ 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;
2511
2519
  const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
2512
2520
  const mergedHeaders = (0, import_provider_utils9.combineHeaders)(
2513
2521
  await (0, import_provider_utils9.resolve)(this.config.headers),
@@ -2709,7 +2717,7 @@ var GoogleGenerativeAILanguageModel = class {
2709
2717
  safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
2710
2718
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2711
2719
  finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
2712
- serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
2720
+ serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
2713
2721
  ...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
2714
2722
  ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
2715
2723
  }
@@ -2717,7 +2725,7 @@ var GoogleGenerativeAILanguageModel = class {
2717
2725
  request: { body: args },
2718
2726
  response: {
2719
2727
  // TODO timestamp, model id
2720
- id: (_B = response.responseId) != null ? _B : void 0,
2728
+ id: (_C = response.responseId) != null ? _C : void 0,
2721
2729
  headers: responseHeaders,
2722
2730
  body: rawResponse
2723
2731
  }
@@ -3193,7 +3201,7 @@ var GoogleGenerativeAILanguageModel = class {
3193
3201
  }
3194
3202
  },
3195
3203
  flush(controller) {
3196
- var _a2;
3204
+ var _a2, _b;
3197
3205
  usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
3198
3206
  if (currentTextBlockId !== null) {
3199
3207
  controller.enqueue({
@@ -3225,7 +3233,7 @@ var GoogleGenerativeAILanguageModel = class {
3225
3233
  safetyRatings: lastSafetyRatings,
3226
3234
  usageMetadata: usage != null ? usage : null,
3227
3235
  finishMessage: lastFinishMessage,
3228
- serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
3236
+ serviceTier: (_b = (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
3229
3237
  // Only surface the token when the response stopped early
3230
3238
  // (budget used up, or continuing failed), not for the
3231
3239
  // checkpoint tokens of a stream that finished normally.