@ai-sdk/google 4.0.51 → 4.0.53

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,26 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.53
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [3e125ba]
8
+ - @ai-sdk/provider-utils@5.0.32
9
+
10
+ ## 4.0.52
11
+
12
+ ### Patch Changes
13
+
14
+ - 7de3612: Encode provider-returned identifiers before using them in credentialed follow-up request paths.
15
+ - a9782e1: fix: align batch result parsing, request counts, and lifecycle behavior across providers
16
+ - 92e08e6: Preserve recursive tool input schemas without aborting Google model calls.
17
+ - 35841f5: feat: normalize mid-stream provider error events across supported providers into public StreamProviderError instances and preserve provider-owned type, code, status, retry, and raw payload metadata
18
+ - 0246209: Fix Google file uploads failing to type-check with TypeScript 5.9 DOM types.
19
+ - Updated dependencies [a9782e1]
20
+ - Updated dependencies [35841f5]
21
+ - Updated dependencies [d2f3353]
22
+ - @ai-sdk/provider-utils@5.0.31
23
+
3
24
  ## 4.0.51
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.51" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.53" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -253,18 +253,18 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
253
253
 
254
254
  // src/google-batch.ts
255
255
  import {
256
- EmptyResponseBodyError,
257
256
  InvalidArgumentError,
258
257
  InvalidResponseDataError
259
258
  } from "@ai-sdk/provider";
260
259
  import {
261
260
  combineHeaders as combineHeaders3,
262
261
  convertAsyncIteratorToReadableStream,
262
+ createJsonLinesResponseHandler,
263
263
  createJsonResponseHandler as createJsonResponseHandler3,
264
264
  generateId as generateId2,
265
265
  getFromApi,
266
266
  lazySchema as lazySchema6,
267
- parseJSON,
267
+ normalizeBatchRequestCounts,
268
268
  postJsonToApi as postJsonToApi3,
269
269
  postToApi,
270
270
  resolve as resolve3,
@@ -331,6 +331,10 @@ function convertGoogleUsage(usage) {
331
331
  import {
332
332
  UnsupportedFunctionalityError
333
333
  } from "@ai-sdk/provider";
334
+ var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
335
+ function isRecursiveJSONSchemaReferenceError(error) {
336
+ return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
337
+ }
334
338
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
335
339
  const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
336
340
  return convertJSONSchemaDefinition(jsonSchema, isRoot, {
@@ -471,7 +475,7 @@ function convertJSONSchemaReference({
471
475
  );
472
476
  if (referenceContext.resolvingReferences.has(referenceKey)) {
473
477
  throw new UnsupportedFunctionalityError({
474
- functionality: `recursive JSON Schema reference: ${reference}`,
478
+ functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
475
479
  message: "Google schema conversion does not support recursive JSON Schema references."
476
480
  });
477
481
  }
@@ -1278,7 +1282,6 @@ function prepareTools({
1278
1282
  modelId,
1279
1283
  isVertexProvider = false
1280
1284
  }) {
1281
- var _a, _b;
1282
1285
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1283
1286
  const toolWarnings = [];
1284
1287
  const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
@@ -1396,11 +1399,7 @@ function prepareTools({
1396
1399
  const functionDeclarations2 = [];
1397
1400
  for (const tool of tools) {
1398
1401
  if (tool.type === "function") {
1399
- functionDeclarations2.push({
1400
- name: tool.name,
1401
- description: (_a = tool.description) != null ? _a : "",
1402
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1403
- });
1402
+ functionDeclarations2.push(prepareFunctionDeclaration(tool));
1404
1403
  }
1405
1404
  }
1406
1405
  const combinedToolConfig = {
@@ -1444,11 +1443,7 @@ function prepareTools({
1444
1443
  for (const tool of tools) {
1445
1444
  switch (tool.type) {
1446
1445
  case "function":
1447
- functionDeclarations.push({
1448
- name: tool.name,
1449
- description: (_b = tool.description) != null ? _b : "",
1450
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1451
- });
1446
+ functionDeclarations.push(prepareFunctionDeclaration(tool));
1452
1447
  if (tool.strict === true) {
1453
1448
  hasStrictTools = true;
1454
1449
  }
@@ -1515,6 +1510,27 @@ function prepareTools({
1515
1510
  }
1516
1511
  }
1517
1512
  }
1513
+ function prepareFunctionDeclaration(tool) {
1514
+ var _a;
1515
+ const declaration = {
1516
+ name: tool.name,
1517
+ description: (_a = tool.description) != null ? _a : ""
1518
+ };
1519
+ try {
1520
+ return {
1521
+ ...declaration,
1522
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1523
+ };
1524
+ } catch (error) {
1525
+ if (!isRecursiveJSONSchemaReferenceError(error)) {
1526
+ throw error;
1527
+ }
1528
+ return {
1529
+ ...declaration,
1530
+ parametersJsonSchema: tool.inputSchema
1531
+ };
1532
+ }
1533
+ }
1518
1534
 
1519
1535
  // src/google-json-accumulator.ts
1520
1536
  var GoogleJSONAccumulator = class {
@@ -3254,17 +3270,19 @@ var GoogleBatchLanguageModel = class _GoogleBatchLanguageModel extends GoogleLan
3254
3270
  });
3255
3271
  }
3256
3272
  const encodedResponsesFile = responsesFile.split("/").map((segment) => encodeURIComponent(segment)).join("/");
3257
- const { value: stream } = await getFromApi({
3273
+ const { value: lines } = await getFromApi({
3258
3274
  url: `${this.getBaseOrigin()}/download/v1beta/${encodedResponsesFile}:download?alt=media`,
3259
3275
  headers: await this.getHeaders(options.headers),
3260
3276
  failedResponseHandler: googleFailedResponseHandler,
3261
- successfulResponseHandler: rawStreamResponseHandler,
3277
+ successfulResponseHandler: createJsonLinesResponseHandler(
3278
+ googleBatchResultLineSchema
3279
+ ),
3262
3280
  abortSignal: options.abortSignal,
3263
3281
  fetch: this.batchConfig.fetch,
3264
3282
  validateUrl: false
3265
3283
  });
3266
3284
  return convertAsyncIteratorToReadableStream(
3267
- this.iterateBatchResults(parseJsonLines(stream))
3285
+ this.iterateBatchResults(lines)
3268
3286
  );
3269
3287
  }
3270
3288
  async retrieveBatch(options) {
@@ -3430,15 +3448,12 @@ function convertGoogleRequestCounts(counts) {
3430
3448
  const completed = parseCount((_a = counts == null ? void 0 : counts.successfulRequestCount) != null ? _a : 0);
3431
3449
  const failed = parseCount((_b = counts == null ? void 0 : counts.failedRequestCount) != null ? _b : 0);
3432
3450
  const pending = parseCount((_c = counts == null ? void 0 : counts.pendingRequestCount) != null ? _c : 0);
3433
- if (total == null || completed == null || failed == null || pending == null || completed + failed + pending !== total) {
3434
- return void 0;
3435
- }
3436
- return {
3451
+ return normalizeBatchRequestCounts({
3437
3452
  total,
3438
3453
  pending,
3439
3454
  completed,
3440
3455
  failed
3441
- };
3456
+ });
3442
3457
  }
3443
3458
  function parseCount(value) {
3444
3459
  const count = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
@@ -3464,54 +3479,6 @@ var googleUploadUrlResponseHandler = async ({
3464
3479
  }
3465
3480
  return { value: uploadUrl };
3466
3481
  };
3467
- var rawStreamResponseHandler = async ({ response }) => {
3468
- if (response.body == null) {
3469
- throw new EmptyResponseBodyError();
3470
- }
3471
- return { value: response.body };
3472
- };
3473
- async function* parseJsonLines(stream) {
3474
- const reader = stream.getReader();
3475
- const decoder = new TextDecoder();
3476
- let buffer = "";
3477
- let finished = false;
3478
- try {
3479
- while (true) {
3480
- const { done, value } = await reader.read();
3481
- if (done) {
3482
- finished = true;
3483
- buffer += decoder.decode();
3484
- break;
3485
- }
3486
- buffer += decoder.decode(value, { stream: true });
3487
- let lineEnd = buffer.indexOf("\n");
3488
- while (lineEnd !== -1) {
3489
- const line = buffer.slice(0, lineEnd).replace(/\r$/, "");
3490
- buffer = buffer.slice(lineEnd + 1);
3491
- if (line.trim().length > 0) {
3492
- yield await parseJSON({
3493
- text: line,
3494
- schema: googleBatchResultLineSchema
3495
- });
3496
- }
3497
- lineEnd = buffer.indexOf("\n");
3498
- }
3499
- }
3500
- const finalLine = buffer.replace(/\r$/, "");
3501
- if (finalLine.trim().length > 0) {
3502
- yield await parseJSON({
3503
- text: finalLine,
3504
- schema: googleBatchResultLineSchema
3505
- });
3506
- }
3507
- } finally {
3508
- if (!finished) {
3509
- await reader.cancel().catch(() => {
3510
- });
3511
- }
3512
- reader.releaseLock();
3513
- }
3514
- }
3515
3482
 
3516
3483
  // src/tool/code-execution.ts
3517
3484
  import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
@@ -3902,6 +3869,10 @@ import {
3902
3869
  getFromApi as getFromApi2
3903
3870
  } from "@ai-sdk/provider-utils";
3904
3871
  import { z as z15 } from "zod/v4";
3872
+ function encodePathSegment(value) {
3873
+ const encodedValue = encodeURIComponent(value);
3874
+ return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
3875
+ }
3905
3876
  var GoogleFiles = class {
3906
3877
  constructor(config) {
3907
3878
  this.config = config;
@@ -3963,7 +3934,7 @@ var GoogleFiles = class {
3963
3934
  "X-Goog-Upload-Offset": "0",
3964
3935
  "X-Goog-Upload-Command": "upload, finalize"
3965
3936
  },
3966
- body: fileBytes
3937
+ body: ensureArrayBufferBacked(fileBytes)
3967
3938
  });
3968
3939
  if (!uploadResponse.ok) {
3969
3940
  const errorBody = await uploadResponse.text();
@@ -3985,8 +3956,10 @@ var GoogleFiles = class {
3985
3956
  });
3986
3957
  }
3987
3958
  await delay(pollIntervalMs);
3959
+ const fileNameMatch = /^files\/([^/]+)$/.exec(file.name);
3960
+ const filePath = fileNameMatch != null ? `files/${encodePathSegment(fileNameMatch[1])}` : encodePathSegment(file.name);
3988
3961
  const { value: fileStatus } = await getFromApi2({
3989
- url: `${this.config.baseURL}/${file.name}`,
3962
+ url: `${this.config.baseURL}/${filePath}`,
3990
3963
  validateUrl: false,
3991
3964
  headers: combineHeaders4(resolvedHeaders),
3992
3965
  successfulResponseHandler: createJsonResponseHandler4(
@@ -4024,6 +3997,12 @@ var GoogleFiles = class {
4024
3997
  };
4025
3998
  }
4026
3999
  };
4000
+ function ensureArrayBufferBacked(data) {
4001
+ if (data.buffer instanceof ArrayBuffer) {
4002
+ return data;
4003
+ }
4004
+ return new Uint8Array(data);
4005
+ }
4027
4006
  var googleFileResponseSchema = lazySchema14(
4028
4007
  () => zodSchema14(
4029
4008
  z15.object({
@@ -4683,6 +4662,11 @@ import {
4683
4662
  WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
4684
4663
  } from "@ai-sdk/provider-utils";
4685
4664
 
4665
+ // src/interactions/build-google-interactions-stream-transform.ts
4666
+ import {
4667
+ createProviderStreamError
4668
+ } from "@ai-sdk/provider-utils";
4669
+
4686
4670
  // src/interactions/convert-google-interactions-usage.ts
4687
4671
  import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
4688
4672
  function convertGoogleInteractionsUsage(usage) {
@@ -4977,7 +4961,7 @@ function buildGoogleInteractionsStreamTransform({
4977
4961
  controller.enqueue({ type: "stream-start", warnings });
4978
4962
  },
4979
4963
  transform(chunk, controller) {
4980
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
4964
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4981
4965
  if (includeRawChunks) {
4982
4966
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4983
4967
  }
@@ -5388,10 +5372,15 @@ function buildGoogleInteractionsStreamTransform({
5388
5372
  case "error": {
5389
5373
  const event = value;
5390
5374
  finishStatus = "failed";
5391
- const errorPayload = (_q = event.error) != null ? _q : {
5392
- message: "Unknown interaction error"
5393
- };
5394
- controller.enqueue({ type: "error", error: errorPayload });
5375
+ controller.enqueue({
5376
+ type: "error",
5377
+ error: createProviderStreamError({
5378
+ message: (_r = (_q = event.error) == null ? void 0 : _q.message) != null ? _r : "Unknown interaction error",
5379
+ type: event.event_type,
5380
+ code: (_t = (_s = event.error) == null ? void 0 : _s.code) != null ? _t : void 0,
5381
+ data: event
5382
+ })
5383
+ });
5395
5384
  break;
5396
5385
  }
5397
5386
  default: