@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.
package/dist/index.cjs CHANGED
@@ -6931,7 +6931,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6931
6931
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6932
6932
  const USER_AGENT_HEADER = 'User-Agent';
6933
6933
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6934
- const SDK_VERSION = '1.39.0'; // x-release-please-version
6934
+ const SDK_VERSION = '1.40.0'; // x-release-please-version
6935
6935
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6936
6936
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6937
6937
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -10017,6 +10017,11 @@ async function defaultParseResponse(client, props) {
10017
10017
  const mediaType = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
10018
10018
  const isJSON = (mediaType === null || mediaType === void 0 ? void 0 : mediaType.includes('application/json')) || (mediaType === null || mediaType === void 0 ? void 0 : mediaType.endsWith('+json'));
10019
10019
  if (isJSON) {
10020
+ const contentLength = response.headers.get('content-length');
10021
+ if (contentLength === '0') {
10022
+ // if there is no content we can't do anything
10023
+ return undefined;
10024
+ }
10020
10025
  const json = await response.json();
10021
10026
  return json;
10022
10027
  }
@@ -10476,9 +10481,10 @@ class BaseGeminiNextGenAPIClient {
10476
10481
  }
10477
10482
  async fetchWithTimeout(url, init, ms, controller) {
10478
10483
  const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
10484
+ const abort = controller.abort.bind(controller);
10479
10485
  if (signal)
10480
- signal.addEventListener('abort', () => controller.abort());
10481
- const timeout = setTimeout(() => controller.abort(), ms);
10486
+ signal.addEventListener('abort', abort, { once: true });
10487
+ const timeout = setTimeout(abort, ms);
10482
10488
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
10483
10489
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
10484
10490
  const fetchOptions = Object.assign(Object.assign(Object.assign({ signal: controller.signal }, (isReadableBody ? { duplex: 'half' } : {})), { method: 'GET' }), options);
package/dist/index.mjs CHANGED
@@ -6929,7 +6929,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6929
6929
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6930
6930
  const USER_AGENT_HEADER = 'User-Agent';
6931
6931
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6932
- const SDK_VERSION = '1.39.0'; // x-release-please-version
6932
+ const SDK_VERSION = '1.40.0'; // x-release-please-version
6933
6933
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6934
6934
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6935
6935
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -10015,6 +10015,11 @@ async function defaultParseResponse(client, props) {
10015
10015
  const mediaType = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
10016
10016
  const isJSON = (mediaType === null || mediaType === void 0 ? void 0 : mediaType.includes('application/json')) || (mediaType === null || mediaType === void 0 ? void 0 : mediaType.endsWith('+json'));
10017
10017
  if (isJSON) {
10018
+ const contentLength = response.headers.get('content-length');
10019
+ if (contentLength === '0') {
10020
+ // if there is no content we can't do anything
10021
+ return undefined;
10022
+ }
10018
10023
  const json = await response.json();
10019
10024
  return json;
10020
10025
  }
@@ -10474,9 +10479,10 @@ class BaseGeminiNextGenAPIClient {
10474
10479
  }
10475
10480
  async fetchWithTimeout(url, init, ms, controller) {
10476
10481
  const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
10482
+ const abort = controller.abort.bind(controller);
10477
10483
  if (signal)
10478
- signal.addEventListener('abort', () => controller.abort());
10479
- const timeout = setTimeout(() => controller.abort(), ms);
10484
+ signal.addEventListener('abort', abort, { once: true });
10485
+ const timeout = setTimeout(abort, ms);
10480
10486
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
10481
10487
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
10482
10488
  const fetchOptions = Object.assign(Object.assign(Object.assign({ signal: controller.signal }, (isReadableBody ? { duplex: 'half' } : {})), { method: 'GET' }), options);