@google/genai 1.33.0 → 1.34.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.
@@ -786,21 +786,29 @@ var PhishBlockThreshold;
786
786
  */
787
787
  PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
788
788
  })(PhishBlockThreshold || (PhishBlockThreshold = {}));
789
- /** The level of thoughts tokens that the model should generate. */
789
+ /** The number of thoughts tokens that the model should generate. */
790
790
  var ThinkingLevel;
791
791
  (function (ThinkingLevel) {
792
792
  /**
793
- * Default value.
793
+ * Unspecified thinking level.
794
794
  */
795
795
  ThinkingLevel["THINKING_LEVEL_UNSPECIFIED"] = "THINKING_LEVEL_UNSPECIFIED";
796
796
  /**
797
797
  * Low thinking level.
798
798
  */
799
799
  ThinkingLevel["LOW"] = "LOW";
800
+ /**
801
+ * Medium thinking level.
802
+ */
803
+ ThinkingLevel["MEDIUM"] = "MEDIUM";
800
804
  /**
801
805
  * High thinking level.
802
806
  */
803
807
  ThinkingLevel["HIGH"] = "HIGH";
808
+ /**
809
+ * MINIMAL thinking level.
810
+ */
811
+ ThinkingLevel["MINIMAL"] = "MINIMAL";
804
812
  })(ThinkingLevel || (ThinkingLevel = {}));
805
813
  /** Harm category. */
806
814
  var HarmCategory;
@@ -1271,6 +1279,10 @@ var PartMediaResolutionLevel;
1271
1279
  * Media resolution set to high.
1272
1280
  */
1273
1281
  PartMediaResolutionLevel["MEDIA_RESOLUTION_HIGH"] = "MEDIA_RESOLUTION_HIGH";
1282
+ /**
1283
+ * Media resolution set to ultra high.
1284
+ */
1285
+ PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1274
1286
  })(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
1275
1287
  /** Options for feature selection preference. */
1276
1288
  var FeatureSelectionPreference;
@@ -7246,7 +7258,7 @@ function generationConfigToVertex$1(fromObject) {
7246
7258
  }
7247
7259
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7248
7260
  if (fromSpeechConfig != null) {
7249
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex$1(fromSpeechConfig));
7261
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
7250
7262
  }
7251
7263
  const fromStopSequences = getValueByPath(fromObject, [
7252
7264
  'stopSequences',
@@ -7462,7 +7474,7 @@ function liveConnectConfigToVertex(fromObject, parentObject) {
7462
7474
  }
7463
7475
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
7464
7476
  if (parentObject !== undefined && fromSpeechConfig != null) {
7465
- setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], speechConfigToVertex$1(tLiveSpeechConfig(fromSpeechConfig)));
7477
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
7466
7478
  }
7467
7479
  const fromThinkingConfig = getValueByPath(fromObject, [
7468
7480
  'thinkingConfig',
@@ -7787,21 +7799,6 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7787
7799
  }
7788
7800
  return toObject;
7789
7801
  }
7790
- function speechConfigToVertex$1(fromObject) {
7791
- const toObject = {};
7792
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7793
- if (fromVoiceConfig != null) {
7794
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7795
- }
7796
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7797
- if (fromLanguageCode != null) {
7798
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7799
- }
7800
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7801
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7802
- }
7803
- return toObject;
7804
- }
7805
7802
  function toolToMldev$2(fromObject) {
7806
7803
  const toObject = {};
7807
7804
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -9044,7 +9041,7 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
9044
9041
  }
9045
9042
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
9046
9043
  if (fromSpeechConfig != null) {
9047
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(tSpeechConfig(fromSpeechConfig)));
9044
+ setValueByPath(toObject, ['speechConfig'], tSpeechConfig(fromSpeechConfig));
9048
9045
  }
9049
9046
  const fromAudioTimestamp = getValueByPath(fromObject, [
9050
9047
  'audioTimestamp',
@@ -9990,7 +9987,7 @@ function generationConfigToVertex(fromObject) {
9990
9987
  }
9991
9988
  const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
9992
9989
  if (fromSpeechConfig != null) {
9993
- setValueByPath(toObject, ['speechConfig'], speechConfigToVertex(fromSpeechConfig));
9990
+ setValueByPath(toObject, ['speechConfig'], fromSpeechConfig);
9994
9991
  }
9995
9992
  const fromStopSequences = getValueByPath(fromObject, [
9996
9993
  'stopSequences',
@@ -10792,21 +10789,6 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10792
10789
  }
10793
10790
  return toObject;
10794
10791
  }
10795
- function speechConfigToVertex(fromObject) {
10796
- const toObject = {};
10797
- const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10798
- if (fromVoiceConfig != null) {
10799
- setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10800
- }
10801
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10802
- if (fromLanguageCode != null) {
10803
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10804
- }
10805
- if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10806
- throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10807
- }
10808
- return toObject;
10809
- }
10810
10792
  function toolConfigToMldev(fromObject) {
10811
10793
  const toObject = {};
10812
10794
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -11488,7 +11470,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11488
11470
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11489
11471
  const USER_AGENT_HEADER = 'User-Agent';
11490
11472
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11491
- const SDK_VERSION = '1.33.0'; // x-release-please-version
11473
+ const SDK_VERSION = '1.34.0'; // x-release-please-version
11492
11474
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11493
11475
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11494
11476
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11562,6 +11544,11 @@ class ApiClient {
11562
11544
  getLocation() {
11563
11545
  return this.clientOptions.location;
11564
11546
  }
11547
+ async getAuthHeaders() {
11548
+ const headers = new Headers();
11549
+ await this.clientOptions.auth.addAuthHeaders(headers);
11550
+ return headers;
11551
+ }
11565
11552
  getApiVersion() {
11566
11553
  if (this.clientOptions.httpOptions &&
11567
11554
  this.clientOptions.httpOptions.apiVersion !== undefined) {
@@ -17434,7 +17421,7 @@ class BaseGeminiNextGenAPIClient {
17434
17421
  */
17435
17422
  constructor(_b) {
17436
17423
  var _c, _d, _e, _f, _g, _h, _j;
17437
- var _k = _b === void 0 ? {} : _b, { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _k, opts = __rest(_k, ["baseURL", "apiKey", "apiVersion"]);
17424
+ var { baseURL = readEnv('GEMINI_NEXT_GEN_API_BASE_URL'), apiKey = (_c = readEnv('GEMINI_API_KEY')) !== null && _c !== void 0 ? _c : null, apiVersion = 'v1beta' } = _b, opts = __rest(_b, ["baseURL", "apiKey", "apiVersion"]);
17438
17425
  const options = Object.assign(Object.assign({ apiKey,
17439
17426
  apiVersion }, opts), { baseURL: baseURL || `https://generativelanguage.googleapis.com` });
17440
17427
  this.baseURL = options.baseURL;
@@ -17452,6 +17439,7 @@ class BaseGeminiNextGenAPIClient {
17452
17439
  this._options = options;
17453
17440
  this.apiKey = apiKey;
17454
17441
  this.apiVersion = apiVersion;
17442
+ this.clientAdapter = options.clientAdapter;
17455
17443
  }
17456
17444
  /**
17457
17445
  * Create a new client instance re-using the same options given to the current client with optional overriding.
@@ -17470,6 +17458,10 @@ class BaseGeminiNextGenAPIClient {
17470
17458
  return this._options.defaultQuery;
17471
17459
  }
17472
17460
  validateHeaders({ values, nulls }) {
17461
+ // The headers object handles case insensitivity.
17462
+ if (values.has('authorization') || values.has('x-goog-api-key')) {
17463
+ return;
17464
+ }
17473
17465
  if (this.apiKey && values.get('x-goog-api-key')) {
17474
17466
  return;
17475
17467
  }
@@ -17479,10 +17471,17 @@ class BaseGeminiNextGenAPIClient {
17479
17471
  throw new Error('Could not resolve authentication method. Expected the apiKey to be set. Or for the "x-goog-api-key" headers to be explicitly omitted');
17480
17472
  }
17481
17473
  async authHeaders(opts) {
17482
- if (this.apiKey == null) {
17474
+ const existingHeaders = buildHeaders([opts.headers]);
17475
+ if (existingHeaders.values.has('authorization') || existingHeaders.values.has('x-goog-api-key')) {
17483
17476
  return undefined;
17484
17477
  }
17485
- return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17478
+ if (this.apiKey) {
17479
+ return buildHeaders([{ 'x-goog-api-key': this.apiKey }]);
17480
+ }
17481
+ if (this.clientAdapter.isVertexAI()) {
17482
+ return buildHeaders([await this.clientAdapter.getAuthHeaders()]);
17483
+ }
17484
+ return undefined;
17486
17485
  }
17487
17486
  /**
17488
17487
  * Basic re-implementation of `qs.stringify` for primitive types.
@@ -17526,8 +17525,16 @@ class BaseGeminiNextGenAPIClient {
17526
17525
  }
17527
17526
  /**
17528
17527
  * Used as a callback for mutating the given `FinalRequestOptions` object.
17528
+
17529
17529
  */
17530
- async prepareOptions(options) { }
17530
+ async prepareOptions(options) {
17531
+ if (this.clientAdapter &&
17532
+ this.clientAdapter.isVertexAI() &&
17533
+ !options.path.startsWith(`/${this.apiVersion}/projects/`)) {
17534
+ const oldPath = options.path.slice(this.apiVersion.length + 1);
17535
+ options.path = `/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${oldPath}`;
17536
+ }
17537
+ }
17531
17538
  /**
17532
17539
  * Used as a callback for mutating the given `RequestInit` object.
17533
17540
  *
@@ -17769,13 +17776,14 @@ class BaseGeminiNextGenAPIClient {
17769
17776
  options.idempotencyKey = this.defaultIdempotencyKey();
17770
17777
  idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
17771
17778
  }
17772
- const headers = buildHeaders([
17779
+ const authHeaders = await this.authHeaders(options);
17780
+ let headers = buildHeaders([
17773
17781
  idempotencyHeaders,
17774
17782
  Object.assign(Object.assign({ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'X-Stainless-Retry-Count': String(retryCount) }, (options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {})), getPlatformHeaders()),
17775
- await this.authHeaders(options),
17776
17783
  this._options.defaultHeaders,
17777
17784
  bodyHeaders,
17778
17785
  options.headers,
17786
+ authHeaders,
17779
17787
  ]);
17780
17788
  this.validateHeaders(headers);
17781
17789
  return headers.values;
@@ -19140,9 +19148,6 @@ class GoogleGenAI {
19140
19148
  return this._interactions;
19141
19149
  }
19142
19150
  console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
19143
- if (this.vertexai) {
19144
- throw new Error('This version of the GenAI SDK does not support Vertex AI API for interactions.');
19145
- }
19146
19151
  const httpOpts = this.httpOptions;
19147
19152
  // Unsupported Options Warnings
19148
19153
  if (httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.extraBody) {
@@ -19151,6 +19156,8 @@ class GoogleGenAI {
19151
19156
  const nextGenClient = new GeminiNextGenAPIClient({
19152
19157
  baseURL: this.apiClient.getBaseUrl(),
19153
19158
  apiKey: this.apiKey,
19159
+ apiVersion: this.apiClient.getApiVersion(),
19160
+ clientAdapter: this.apiClient,
19154
19161
  defaultHeaders: this.apiClient.getDefaultHeaders(),
19155
19162
  timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
19156
19163
  });