@google/genai 1.52.0 → 2.0.1

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.
@@ -2071,7 +2071,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
2071
2071
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
2072
2072
  const USER_AGENT_HEADER = 'User-Agent';
2073
2073
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
2074
- const SDK_VERSION = '1.52.0'; // x-release-please-version
2074
+ const SDK_VERSION = '2.0.1'; // x-release-please-version
2075
2075
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
2076
2076
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
2077
2077
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -2336,6 +2336,24 @@ class ApiClient {
2336
2336
  const abortController = new AbortController();
2337
2337
  const signal = abortController.signal;
2338
2338
  if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
2339
+ // In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
2340
+ // dispatcher on the global scope which tracks its internal headersTimeout and
2341
+ // bodyTimeout using Symbol properties.
2342
+ const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
2343
+ const globalDispatcher = globalThis[dispatcherSymbol];
2344
+ if (globalDispatcher) {
2345
+ const symbols = Object.getOwnPropertySymbols(globalDispatcher);
2346
+ for (const sym of symbols) {
2347
+ const desc = sym.description;
2348
+ if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
2349
+ (desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
2350
+ const currentTimeout = globalDispatcher[sym];
2351
+ if (typeof currentTimeout === 'number') {
2352
+ globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
2353
+ }
2354
+ }
2355
+ }
2356
+ }
2339
2357
  const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
2340
2358
  if (timeoutHandle &&
2341
2359
  typeof timeoutHandle.unref ===
@@ -2369,7 +2387,7 @@ class ApiClient {
2369
2387
  throw e;
2370
2388
  }
2371
2389
  else {
2372
- throw new Error(JSON.stringify(e));
2390
+ throw new Error(`exception ${e} sending request`, { cause: e });
2373
2391
  }
2374
2392
  });
2375
2393
  }
@@ -2384,7 +2402,7 @@ class ApiClient {
2384
2402
  throw e;
2385
2403
  }
2386
2404
  else {
2387
- throw new Error(JSON.stringify(e));
2405
+ throw new Error(`exception ${e} sending request`, { cause: e });
2388
2406
  }
2389
2407
  });
2390
2408
  }
@@ -2512,11 +2530,14 @@ class ApiClient {
2512
2530
  for (const [key, value] of Object.entries(httpOptions.headers)) {
2513
2531
  headers.append(key, value);
2514
2532
  }
2515
- // Append a timeout header if it is set, note that the timeout option is
2516
- // in milliseconds but the header is in seconds.
2517
- if (httpOptions.timeout && httpOptions.timeout > 0) {
2518
- headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
2519
- }
2533
+ }
2534
+ // Append a timeout header if it is set, note that the timeout option is
2535
+ // in milliseconds but the header is in seconds.
2536
+ // NOTE: This is intentionally outside the httpOptions.headers guard above
2537
+ // so that the X-Server-Timeout header is always sent whenever a timeout
2538
+ // is configured, even if the caller did not supply any custom headers.
2539
+ if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
2540
+ headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
2520
2541
  }
2521
2542
  await this.clientOptions.auth.addAuthHeaders(headers, url);
2522
2543
  return headers;