@google/genai 1.39.0 → 1.40.0

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.
@@ -11639,7 +11639,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11639
11639
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11640
11640
  const USER_AGENT_HEADER = 'User-Agent';
11641
11641
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11642
- const SDK_VERSION = '1.39.0'; // x-release-please-version
11642
+ const SDK_VERSION = '1.40.0'; // x-release-please-version
11643
11643
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11644
11644
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11645
11645
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -17412,6 +17412,11 @@ async function defaultParseResponse(client, props) {
17412
17412
  const mediaType = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
17413
17413
  const isJSON = (mediaType === null || mediaType === void 0 ? void 0 : mediaType.includes('application/json')) || (mediaType === null || mediaType === void 0 ? void 0 : mediaType.endsWith('+json'));
17414
17414
  if (isJSON) {
17415
+ const contentLength = response.headers.get('content-length');
17416
+ if (contentLength === '0') {
17417
+ // if there is no content we can't do anything
17418
+ return undefined;
17419
+ }
17415
17420
  const json = await response.json();
17416
17421
  return json;
17417
17422
  }
@@ -17871,9 +17876,10 @@ class BaseGeminiNextGenAPIClient {
17871
17876
  }
17872
17877
  async fetchWithTimeout(url, init, ms, controller) {
17873
17878
  const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
17879
+ const abort = controller.abort.bind(controller);
17874
17880
  if (signal)
17875
- signal.addEventListener('abort', () => controller.abort());
17876
- const timeout = setTimeout(() => controller.abort(), ms);
17881
+ signal.addEventListener('abort', abort, { once: true });
17882
+ const timeout = setTimeout(abort, ms);
17877
17883
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
17878
17884
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
17879
17885
  const fetchOptions = Object.assign(Object.assign(Object.assign({ signal: controller.signal }, (isReadableBody ? { duplex: 'half' } : {})), { method: 'GET' }), options);
@@ -11617,7 +11617,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11617
11617
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11618
11618
  const USER_AGENT_HEADER = 'User-Agent';
11619
11619
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11620
- const SDK_VERSION = '1.39.0'; // x-release-please-version
11620
+ const SDK_VERSION = '1.40.0'; // x-release-please-version
11621
11621
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11622
11622
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11623
11623
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -17390,6 +17390,11 @@ async function defaultParseResponse(client, props) {
17390
17390
  const mediaType = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
17391
17391
  const isJSON = (mediaType === null || mediaType === void 0 ? void 0 : mediaType.includes('application/json')) || (mediaType === null || mediaType === void 0 ? void 0 : mediaType.endsWith('+json'));
17392
17392
  if (isJSON) {
17393
+ const contentLength = response.headers.get('content-length');
17394
+ if (contentLength === '0') {
17395
+ // if there is no content we can't do anything
17396
+ return undefined;
17397
+ }
17393
17398
  const json = await response.json();
17394
17399
  return json;
17395
17400
  }
@@ -17849,9 +17854,10 @@ class BaseGeminiNextGenAPIClient {
17849
17854
  }
17850
17855
  async fetchWithTimeout(url, init, ms, controller) {
17851
17856
  const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
17857
+ const abort = controller.abort.bind(controller);
17852
17858
  if (signal)
17853
- signal.addEventListener('abort', () => controller.abort());
17854
- const timeout = setTimeout(() => controller.abort(), ms);
17859
+ signal.addEventListener('abort', abort, { once: true });
17860
+ const timeout = setTimeout(abort, ms);
17855
17861
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
17856
17862
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
17857
17863
  const fetchOptions = Object.assign(Object.assign(Object.assign({ signal: controller.signal }, (isReadableBody ? { duplex: 'half' } : {})), { method: 'GET' }), options);