@google/genai 1.37.0 → 1.38.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/genai.d.ts +32 -17
- package/dist/index.cjs +96 -47
- package/dist/index.mjs +97 -48
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +99 -47
- package/dist/node/index.mjs +100 -48
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +32 -17
- package/dist/tokenizer/node.cjs +12 -0
- package/dist/tokenizer/node.d.ts +14 -0
- package/dist/tokenizer/node.mjs +12 -0
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/web/index.mjs +97 -48
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +32 -17
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -1355,6 +1355,18 @@ exports.PartMediaResolutionLevel = void 0;
|
|
|
1355
1355
|
*/
|
|
1356
1356
|
PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
|
|
1357
1357
|
})(exports.PartMediaResolutionLevel || (exports.PartMediaResolutionLevel = {}));
|
|
1358
|
+
/** Resource scope. */
|
|
1359
|
+
exports.ResourceScope = void 0;
|
|
1360
|
+
(function (ResourceScope) {
|
|
1361
|
+
/**
|
|
1362
|
+
* When setting base_url, this value configures resource scope to be the collection.
|
|
1363
|
+
The resource name will not include api version, project, or location.
|
|
1364
|
+
For example, if base_url is set to "https://aiplatform.googleapis.com",
|
|
1365
|
+
then the resource name for a Model would be
|
|
1366
|
+
"https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
|
|
1367
|
+
*/
|
|
1368
|
+
ResourceScope["COLLECTION"] = "COLLECTION";
|
|
1369
|
+
})(exports.ResourceScope || (exports.ResourceScope = {}));
|
|
1358
1370
|
/** Options for feature selection preference. */
|
|
1359
1371
|
exports.FeatureSelectionPreference = void 0;
|
|
1360
1372
|
(function (FeatureSelectionPreference) {
|
|
@@ -4191,6 +4203,9 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
|
|
|
4191
4203
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
4192
4204
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
4193
4205
|
}
|
|
4206
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
4207
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
4208
|
+
}
|
|
4194
4209
|
return toObject;
|
|
4195
4210
|
}
|
|
4196
4211
|
function generateContentResponseFromMldev$1(fromObject) {
|
|
@@ -8948,6 +8963,9 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
|
|
|
8948
8963
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
8949
8964
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
8950
8965
|
}
|
|
8966
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
8967
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
8968
|
+
}
|
|
8951
8969
|
return toObject;
|
|
8952
8970
|
}
|
|
8953
8971
|
function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
@@ -9116,6 +9134,12 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
|
9116
9134
|
undefined) {
|
|
9117
9135
|
throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
|
|
9118
9136
|
}
|
|
9137
|
+
const fromModelArmorConfig = getValueByPath(fromObject, [
|
|
9138
|
+
'modelArmorConfig',
|
|
9139
|
+
]);
|
|
9140
|
+
if (parentObject !== undefined && fromModelArmorConfig != null) {
|
|
9141
|
+
setValueByPath(parentObject, ['modelArmorConfig'], fromModelArmorConfig);
|
|
9142
|
+
}
|
|
9119
9143
|
return toObject;
|
|
9120
9144
|
}
|
|
9121
9145
|
function generateContentParametersToMldev(apiClient, fromObject) {
|
|
@@ -11532,7 +11556,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11532
11556
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11533
11557
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11534
11558
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11535
|
-
const SDK_VERSION = '1.
|
|
11559
|
+
const SDK_VERSION = '1.38.0'; // x-release-please-version
|
|
11536
11560
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11537
11561
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11538
11562
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11542,19 +11566,57 @@ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
|
11542
11566
|
*/
|
|
11543
11567
|
class ApiClient {
|
|
11544
11568
|
constructor(opts) {
|
|
11545
|
-
var _a, _b;
|
|
11546
|
-
this.clientOptions = Object.assign(
|
|
11569
|
+
var _a, _b, _c;
|
|
11570
|
+
this.clientOptions = Object.assign({}, opts);
|
|
11571
|
+
this.customBaseUrl = (_a = opts.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
|
11572
|
+
if (this.clientOptions.vertexai) {
|
|
11573
|
+
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11574
|
+
this.clientOptions.apiKey = undefined;
|
|
11575
|
+
}
|
|
11576
|
+
else if (this.clientOptions.apiKey) {
|
|
11577
|
+
this.clientOptions.project = undefined;
|
|
11578
|
+
this.clientOptions.location = undefined;
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11547
11581
|
const initHttpOptions = {};
|
|
11548
11582
|
if (this.clientOptions.vertexai) {
|
|
11583
|
+
if (!this.clientOptions.location &&
|
|
11584
|
+
!this.clientOptions.apiKey &&
|
|
11585
|
+
!this.customBaseUrl) {
|
|
11586
|
+
this.clientOptions.location = 'global';
|
|
11587
|
+
}
|
|
11588
|
+
const hasSufficientAuth = (this.clientOptions.project && this.clientOptions.location) ||
|
|
11589
|
+
this.clientOptions.apiKey;
|
|
11590
|
+
if (!hasSufficientAuth && !this.customBaseUrl) {
|
|
11591
|
+
throw new Error('Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.');
|
|
11592
|
+
}
|
|
11593
|
+
const hasConstructorAuth = (opts.project && opts.location) || !!opts.apiKey;
|
|
11594
|
+
if (this.customBaseUrl && !hasConstructorAuth) {
|
|
11595
|
+
initHttpOptions.baseUrl = this.customBaseUrl;
|
|
11596
|
+
this.clientOptions.project = undefined;
|
|
11597
|
+
this.clientOptions.location = undefined;
|
|
11598
|
+
}
|
|
11599
|
+
else if (this.clientOptions.apiKey ||
|
|
11600
|
+
this.clientOptions.location === 'global') {
|
|
11601
|
+
// Vertex Express or global endpoint case.
|
|
11602
|
+
initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
|
|
11603
|
+
}
|
|
11604
|
+
else if (this.clientOptions.project && this.clientOptions.location) {
|
|
11605
|
+
initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11606
|
+
}
|
|
11549
11607
|
initHttpOptions.apiVersion =
|
|
11550
|
-
(
|
|
11551
|
-
initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
|
|
11552
|
-
this.normalizeAuthParameters();
|
|
11608
|
+
(_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : VERTEX_AI_API_DEFAULT_VERSION;
|
|
11553
11609
|
}
|
|
11554
11610
|
else {
|
|
11555
11611
|
// Gemini API
|
|
11612
|
+
if (!this.clientOptions.apiKey) {
|
|
11613
|
+
throw new ApiError({
|
|
11614
|
+
message: 'API key must be set when using the Gemini API.',
|
|
11615
|
+
status: 403,
|
|
11616
|
+
});
|
|
11617
|
+
}
|
|
11556
11618
|
initHttpOptions.apiVersion =
|
|
11557
|
-
(
|
|
11619
|
+
(_c = this.clientOptions.apiVersion) !== null && _c !== void 0 ? _c : GOOGLE_AI_API_DEFAULT_VERSION;
|
|
11558
11620
|
initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
|
|
11559
11621
|
}
|
|
11560
11622
|
initHttpOptions.headers = this.getDefaultHeaders();
|
|
@@ -11563,39 +11625,6 @@ class ApiClient {
|
|
|
11563
11625
|
this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
|
|
11564
11626
|
}
|
|
11565
11627
|
}
|
|
11566
|
-
/**
|
|
11567
|
-
* Determines the base URL for Vertex AI based on project and location.
|
|
11568
|
-
* Uses the global endpoint if location is 'global' or if project/location
|
|
11569
|
-
* are not specified (implying API key usage).
|
|
11570
|
-
* @private
|
|
11571
|
-
*/
|
|
11572
|
-
baseUrlFromProjectLocation() {
|
|
11573
|
-
if (this.clientOptions.project &&
|
|
11574
|
-
this.clientOptions.location &&
|
|
11575
|
-
this.clientOptions.location !== 'global') {
|
|
11576
|
-
// Regional endpoint
|
|
11577
|
-
return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11578
|
-
}
|
|
11579
|
-
// Global endpoint (covers 'global' location and API key usage)
|
|
11580
|
-
return `https://aiplatform.googleapis.com/`;
|
|
11581
|
-
}
|
|
11582
|
-
/**
|
|
11583
|
-
* Normalizes authentication parameters for Vertex AI.
|
|
11584
|
-
* If project and location are provided, API key is cleared.
|
|
11585
|
-
* If project and location are not provided (implying API key usage),
|
|
11586
|
-
* project and location are cleared.
|
|
11587
|
-
* @private
|
|
11588
|
-
*/
|
|
11589
|
-
normalizeAuthParameters() {
|
|
11590
|
-
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11591
|
-
// Using project/location for auth, clear potential API key
|
|
11592
|
-
this.clientOptions.apiKey = undefined;
|
|
11593
|
-
return;
|
|
11594
|
-
}
|
|
11595
|
-
// Using API key for auth (or no auth provided yet), clear project/location
|
|
11596
|
-
this.clientOptions.project = undefined;
|
|
11597
|
-
this.clientOptions.location = undefined;
|
|
11598
|
-
}
|
|
11599
11628
|
isVertexAI() {
|
|
11600
11629
|
var _a;
|
|
11601
11630
|
return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
|
|
@@ -11606,6 +11635,9 @@ class ApiClient {
|
|
|
11606
11635
|
getLocation() {
|
|
11607
11636
|
return this.clientOptions.location;
|
|
11608
11637
|
}
|
|
11638
|
+
getCustomBaseUrl() {
|
|
11639
|
+
return this.customBaseUrl;
|
|
11640
|
+
}
|
|
11609
11641
|
async getAuthHeaders() {
|
|
11610
11642
|
const headers = new Headers();
|
|
11611
11643
|
await this.clientOptions.auth.addAuthHeaders(headers);
|
|
@@ -11683,7 +11715,11 @@ class ApiClient {
|
|
|
11683
11715
|
const url = new URL(`${urlElement.join('/')}`);
|
|
11684
11716
|
return url;
|
|
11685
11717
|
}
|
|
11686
|
-
shouldPrependVertexProjectPath(request) {
|
|
11718
|
+
shouldPrependVertexProjectPath(request, httpOptions) {
|
|
11719
|
+
if (httpOptions.baseUrl &&
|
|
11720
|
+
httpOptions.baseUrlResourceScope === exports.ResourceScope.COLLECTION) {
|
|
11721
|
+
return false;
|
|
11722
|
+
}
|
|
11687
11723
|
if (this.clientOptions.apiKey) {
|
|
11688
11724
|
return false;
|
|
11689
11725
|
}
|
|
@@ -11709,7 +11745,7 @@ class ApiClient {
|
|
|
11709
11745
|
if (request.httpOptions) {
|
|
11710
11746
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11711
11747
|
}
|
|
11712
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11748
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11713
11749
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11714
11750
|
if (request.queryParams) {
|
|
11715
11751
|
for (const [key, value] of Object.entries(request.queryParams)) {
|
|
@@ -11752,7 +11788,7 @@ class ApiClient {
|
|
|
11752
11788
|
if (request.httpOptions) {
|
|
11753
11789
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11754
11790
|
}
|
|
11755
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11791
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11756
11792
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11757
11793
|
if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
|
|
11758
11794
|
url.searchParams.set('alt', 'sse');
|
|
@@ -12679,8 +12715,19 @@ class Live {
|
|
|
12679
12715
|
}
|
|
12680
12716
|
const headers = mapToHeaders(clientHeaders);
|
|
12681
12717
|
if (this.apiClient.isVertexAI()) {
|
|
12682
|
-
|
|
12683
|
-
|
|
12718
|
+
const project = this.apiClient.getProject();
|
|
12719
|
+
const location = this.apiClient.getLocation();
|
|
12720
|
+
const apiKey = this.apiClient.getApiKey();
|
|
12721
|
+
const hasStandardAuth = (!!project && !!location) || !!apiKey;
|
|
12722
|
+
if (this.apiClient.getCustomBaseUrl() && !hasStandardAuth) {
|
|
12723
|
+
// Custom base URL without standard auth (e.g., proxy).
|
|
12724
|
+
url = websocketBaseUrl;
|
|
12725
|
+
// Auth headers are assumed to be in `clientHeaders` from httpOptions.
|
|
12726
|
+
}
|
|
12727
|
+
else {
|
|
12728
|
+
url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
|
|
12729
|
+
await this.auth.addAuthHeaders(headers, url);
|
|
12730
|
+
}
|
|
12684
12731
|
}
|
|
12685
12732
|
else {
|
|
12686
12733
|
const apiKey = this.apiClient.getApiKey();
|
|
@@ -12726,8 +12773,10 @@ class Live {
|
|
|
12726
12773
|
transformedModel.startsWith('publishers/')) {
|
|
12727
12774
|
const project = this.apiClient.getProject();
|
|
12728
12775
|
const location = this.apiClient.getLocation();
|
|
12729
|
-
|
|
12730
|
-
|
|
12776
|
+
if (project && location) {
|
|
12777
|
+
transformedModel =
|
|
12778
|
+
`projects/${project}/locations/${location}/` + transformedModel;
|
|
12779
|
+
}
|
|
12731
12780
|
}
|
|
12732
12781
|
let clientMessage = {};
|
|
12733
12782
|
if (this.apiClient.isVertexAI() &&
|
|
@@ -19541,6 +19590,9 @@ class GoogleGenAI {
|
|
|
19541
19590
|
this.apiKey = (_c = options.apiKey) !== null && _c !== void 0 ? _c : envApiKey;
|
|
19542
19591
|
this.project = (_d = options.project) !== null && _d !== void 0 ? _d : envProject;
|
|
19543
19592
|
this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
|
|
19593
|
+
if (!this.vertexai && !this.apiKey) {
|
|
19594
|
+
throw new Error('API key must be set when using the Gemini API.');
|
|
19595
|
+
}
|
|
19544
19596
|
// Handle when to use Vertex AI in express mode (api key)
|
|
19545
19597
|
if (options.vertexai) {
|
|
19546
19598
|
if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
|
package/dist/node/index.mjs
CHANGED
|
@@ -1333,6 +1333,18 @@ var PartMediaResolutionLevel;
|
|
|
1333
1333
|
*/
|
|
1334
1334
|
PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
|
|
1335
1335
|
})(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
|
|
1336
|
+
/** Resource scope. */
|
|
1337
|
+
var ResourceScope;
|
|
1338
|
+
(function (ResourceScope) {
|
|
1339
|
+
/**
|
|
1340
|
+
* When setting base_url, this value configures resource scope to be the collection.
|
|
1341
|
+
The resource name will not include api version, project, or location.
|
|
1342
|
+
For example, if base_url is set to "https://aiplatform.googleapis.com",
|
|
1343
|
+
then the resource name for a Model would be
|
|
1344
|
+
"https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
|
|
1345
|
+
*/
|
|
1346
|
+
ResourceScope["COLLECTION"] = "COLLECTION";
|
|
1347
|
+
})(ResourceScope || (ResourceScope = {}));
|
|
1336
1348
|
/** Options for feature selection preference. */
|
|
1337
1349
|
var FeatureSelectionPreference;
|
|
1338
1350
|
(function (FeatureSelectionPreference) {
|
|
@@ -4169,6 +4181,9 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
|
|
|
4169
4181
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
4170
4182
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
4171
4183
|
}
|
|
4184
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
4185
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
4186
|
+
}
|
|
4172
4187
|
return toObject;
|
|
4173
4188
|
}
|
|
4174
4189
|
function generateContentResponseFromMldev$1(fromObject) {
|
|
@@ -8926,6 +8941,9 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
|
|
|
8926
8941
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
8927
8942
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
8928
8943
|
}
|
|
8944
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
8945
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
8946
|
+
}
|
|
8929
8947
|
return toObject;
|
|
8930
8948
|
}
|
|
8931
8949
|
function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
@@ -9094,6 +9112,12 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
|
9094
9112
|
undefined) {
|
|
9095
9113
|
throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
|
|
9096
9114
|
}
|
|
9115
|
+
const fromModelArmorConfig = getValueByPath(fromObject, [
|
|
9116
|
+
'modelArmorConfig',
|
|
9117
|
+
]);
|
|
9118
|
+
if (parentObject !== undefined && fromModelArmorConfig != null) {
|
|
9119
|
+
setValueByPath(parentObject, ['modelArmorConfig'], fromModelArmorConfig);
|
|
9120
|
+
}
|
|
9097
9121
|
return toObject;
|
|
9098
9122
|
}
|
|
9099
9123
|
function generateContentParametersToMldev(apiClient, fromObject) {
|
|
@@ -11510,7 +11534,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11510
11534
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11511
11535
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11512
11536
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11513
|
-
const SDK_VERSION = '1.
|
|
11537
|
+
const SDK_VERSION = '1.38.0'; // x-release-please-version
|
|
11514
11538
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11515
11539
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11516
11540
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11520,19 +11544,57 @@ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
|
11520
11544
|
*/
|
|
11521
11545
|
class ApiClient {
|
|
11522
11546
|
constructor(opts) {
|
|
11523
|
-
var _a, _b;
|
|
11524
|
-
this.clientOptions = Object.assign(
|
|
11547
|
+
var _a, _b, _c;
|
|
11548
|
+
this.clientOptions = Object.assign({}, opts);
|
|
11549
|
+
this.customBaseUrl = (_a = opts.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
|
11550
|
+
if (this.clientOptions.vertexai) {
|
|
11551
|
+
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11552
|
+
this.clientOptions.apiKey = undefined;
|
|
11553
|
+
}
|
|
11554
|
+
else if (this.clientOptions.apiKey) {
|
|
11555
|
+
this.clientOptions.project = undefined;
|
|
11556
|
+
this.clientOptions.location = undefined;
|
|
11557
|
+
}
|
|
11558
|
+
}
|
|
11525
11559
|
const initHttpOptions = {};
|
|
11526
11560
|
if (this.clientOptions.vertexai) {
|
|
11561
|
+
if (!this.clientOptions.location &&
|
|
11562
|
+
!this.clientOptions.apiKey &&
|
|
11563
|
+
!this.customBaseUrl) {
|
|
11564
|
+
this.clientOptions.location = 'global';
|
|
11565
|
+
}
|
|
11566
|
+
const hasSufficientAuth = (this.clientOptions.project && this.clientOptions.location) ||
|
|
11567
|
+
this.clientOptions.apiKey;
|
|
11568
|
+
if (!hasSufficientAuth && !this.customBaseUrl) {
|
|
11569
|
+
throw new Error('Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.');
|
|
11570
|
+
}
|
|
11571
|
+
const hasConstructorAuth = (opts.project && opts.location) || !!opts.apiKey;
|
|
11572
|
+
if (this.customBaseUrl && !hasConstructorAuth) {
|
|
11573
|
+
initHttpOptions.baseUrl = this.customBaseUrl;
|
|
11574
|
+
this.clientOptions.project = undefined;
|
|
11575
|
+
this.clientOptions.location = undefined;
|
|
11576
|
+
}
|
|
11577
|
+
else if (this.clientOptions.apiKey ||
|
|
11578
|
+
this.clientOptions.location === 'global') {
|
|
11579
|
+
// Vertex Express or global endpoint case.
|
|
11580
|
+
initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
|
|
11581
|
+
}
|
|
11582
|
+
else if (this.clientOptions.project && this.clientOptions.location) {
|
|
11583
|
+
initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11584
|
+
}
|
|
11527
11585
|
initHttpOptions.apiVersion =
|
|
11528
|
-
(
|
|
11529
|
-
initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
|
|
11530
|
-
this.normalizeAuthParameters();
|
|
11586
|
+
(_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : VERTEX_AI_API_DEFAULT_VERSION;
|
|
11531
11587
|
}
|
|
11532
11588
|
else {
|
|
11533
11589
|
// Gemini API
|
|
11590
|
+
if (!this.clientOptions.apiKey) {
|
|
11591
|
+
throw new ApiError({
|
|
11592
|
+
message: 'API key must be set when using the Gemini API.',
|
|
11593
|
+
status: 403,
|
|
11594
|
+
});
|
|
11595
|
+
}
|
|
11534
11596
|
initHttpOptions.apiVersion =
|
|
11535
|
-
(
|
|
11597
|
+
(_c = this.clientOptions.apiVersion) !== null && _c !== void 0 ? _c : GOOGLE_AI_API_DEFAULT_VERSION;
|
|
11536
11598
|
initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
|
|
11537
11599
|
}
|
|
11538
11600
|
initHttpOptions.headers = this.getDefaultHeaders();
|
|
@@ -11541,39 +11603,6 @@ class ApiClient {
|
|
|
11541
11603
|
this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
|
|
11542
11604
|
}
|
|
11543
11605
|
}
|
|
11544
|
-
/**
|
|
11545
|
-
* Determines the base URL for Vertex AI based on project and location.
|
|
11546
|
-
* Uses the global endpoint if location is 'global' or if project/location
|
|
11547
|
-
* are not specified (implying API key usage).
|
|
11548
|
-
* @private
|
|
11549
|
-
*/
|
|
11550
|
-
baseUrlFromProjectLocation() {
|
|
11551
|
-
if (this.clientOptions.project &&
|
|
11552
|
-
this.clientOptions.location &&
|
|
11553
|
-
this.clientOptions.location !== 'global') {
|
|
11554
|
-
// Regional endpoint
|
|
11555
|
-
return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11556
|
-
}
|
|
11557
|
-
// Global endpoint (covers 'global' location and API key usage)
|
|
11558
|
-
return `https://aiplatform.googleapis.com/`;
|
|
11559
|
-
}
|
|
11560
|
-
/**
|
|
11561
|
-
* Normalizes authentication parameters for Vertex AI.
|
|
11562
|
-
* If project and location are provided, API key is cleared.
|
|
11563
|
-
* If project and location are not provided (implying API key usage),
|
|
11564
|
-
* project and location are cleared.
|
|
11565
|
-
* @private
|
|
11566
|
-
*/
|
|
11567
|
-
normalizeAuthParameters() {
|
|
11568
|
-
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11569
|
-
// Using project/location for auth, clear potential API key
|
|
11570
|
-
this.clientOptions.apiKey = undefined;
|
|
11571
|
-
return;
|
|
11572
|
-
}
|
|
11573
|
-
// Using API key for auth (or no auth provided yet), clear project/location
|
|
11574
|
-
this.clientOptions.project = undefined;
|
|
11575
|
-
this.clientOptions.location = undefined;
|
|
11576
|
-
}
|
|
11577
11606
|
isVertexAI() {
|
|
11578
11607
|
var _a;
|
|
11579
11608
|
return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
|
|
@@ -11584,6 +11613,9 @@ class ApiClient {
|
|
|
11584
11613
|
getLocation() {
|
|
11585
11614
|
return this.clientOptions.location;
|
|
11586
11615
|
}
|
|
11616
|
+
getCustomBaseUrl() {
|
|
11617
|
+
return this.customBaseUrl;
|
|
11618
|
+
}
|
|
11587
11619
|
async getAuthHeaders() {
|
|
11588
11620
|
const headers = new Headers();
|
|
11589
11621
|
await this.clientOptions.auth.addAuthHeaders(headers);
|
|
@@ -11661,7 +11693,11 @@ class ApiClient {
|
|
|
11661
11693
|
const url = new URL(`${urlElement.join('/')}`);
|
|
11662
11694
|
return url;
|
|
11663
11695
|
}
|
|
11664
|
-
shouldPrependVertexProjectPath(request) {
|
|
11696
|
+
shouldPrependVertexProjectPath(request, httpOptions) {
|
|
11697
|
+
if (httpOptions.baseUrl &&
|
|
11698
|
+
httpOptions.baseUrlResourceScope === ResourceScope.COLLECTION) {
|
|
11699
|
+
return false;
|
|
11700
|
+
}
|
|
11665
11701
|
if (this.clientOptions.apiKey) {
|
|
11666
11702
|
return false;
|
|
11667
11703
|
}
|
|
@@ -11687,7 +11723,7 @@ class ApiClient {
|
|
|
11687
11723
|
if (request.httpOptions) {
|
|
11688
11724
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11689
11725
|
}
|
|
11690
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11726
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11691
11727
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11692
11728
|
if (request.queryParams) {
|
|
11693
11729
|
for (const [key, value] of Object.entries(request.queryParams)) {
|
|
@@ -11730,7 +11766,7 @@ class ApiClient {
|
|
|
11730
11766
|
if (request.httpOptions) {
|
|
11731
11767
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11732
11768
|
}
|
|
11733
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11769
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11734
11770
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11735
11771
|
if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
|
|
11736
11772
|
url.searchParams.set('alt', 'sse');
|
|
@@ -12657,8 +12693,19 @@ class Live {
|
|
|
12657
12693
|
}
|
|
12658
12694
|
const headers = mapToHeaders(clientHeaders);
|
|
12659
12695
|
if (this.apiClient.isVertexAI()) {
|
|
12660
|
-
|
|
12661
|
-
|
|
12696
|
+
const project = this.apiClient.getProject();
|
|
12697
|
+
const location = this.apiClient.getLocation();
|
|
12698
|
+
const apiKey = this.apiClient.getApiKey();
|
|
12699
|
+
const hasStandardAuth = (!!project && !!location) || !!apiKey;
|
|
12700
|
+
if (this.apiClient.getCustomBaseUrl() && !hasStandardAuth) {
|
|
12701
|
+
// Custom base URL without standard auth (e.g., proxy).
|
|
12702
|
+
url = websocketBaseUrl;
|
|
12703
|
+
// Auth headers are assumed to be in `clientHeaders` from httpOptions.
|
|
12704
|
+
}
|
|
12705
|
+
else {
|
|
12706
|
+
url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
|
|
12707
|
+
await this.auth.addAuthHeaders(headers, url);
|
|
12708
|
+
}
|
|
12662
12709
|
}
|
|
12663
12710
|
else {
|
|
12664
12711
|
const apiKey = this.apiClient.getApiKey();
|
|
@@ -12704,8 +12751,10 @@ class Live {
|
|
|
12704
12751
|
transformedModel.startsWith('publishers/')) {
|
|
12705
12752
|
const project = this.apiClient.getProject();
|
|
12706
12753
|
const location = this.apiClient.getLocation();
|
|
12707
|
-
|
|
12708
|
-
|
|
12754
|
+
if (project && location) {
|
|
12755
|
+
transformedModel =
|
|
12756
|
+
`projects/${project}/locations/${location}/` + transformedModel;
|
|
12757
|
+
}
|
|
12709
12758
|
}
|
|
12710
12759
|
let clientMessage = {};
|
|
12711
12760
|
if (this.apiClient.isVertexAI() &&
|
|
@@ -19519,6 +19568,9 @@ class GoogleGenAI {
|
|
|
19519
19568
|
this.apiKey = (_c = options.apiKey) !== null && _c !== void 0 ? _c : envApiKey;
|
|
19520
19569
|
this.project = (_d = options.project) !== null && _d !== void 0 ? _d : envProject;
|
|
19521
19570
|
this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
|
|
19571
|
+
if (!this.vertexai && !this.apiKey) {
|
|
19572
|
+
throw new Error('API key must be set when using the Gemini API.');
|
|
19573
|
+
}
|
|
19522
19574
|
// Handle when to use Vertex AI in express mode (api key)
|
|
19523
19575
|
if (options.vertexai) {
|
|
19524
19576
|
if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
|
|
@@ -19612,5 +19664,5 @@ function getApiKeyFromEnv() {
|
|
|
19612
19664
|
return envGoogleApiKey || envGeminiApiKey || undefined;
|
|
19613
19665
|
}
|
|
19614
19666
|
|
|
19615
|
-
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
19667
|
+
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
19616
19668
|
//# sourceMappingURL=index.mjs.map
|