@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/web/index.mjs
CHANGED
|
@@ -1324,6 +1324,18 @@ var PartMediaResolutionLevel;
|
|
|
1324
1324
|
*/
|
|
1325
1325
|
PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
|
|
1326
1326
|
})(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
|
|
1327
|
+
/** Resource scope. */
|
|
1328
|
+
var ResourceScope;
|
|
1329
|
+
(function (ResourceScope) {
|
|
1330
|
+
/**
|
|
1331
|
+
* When setting base_url, this value configures resource scope to be the collection.
|
|
1332
|
+
The resource name will not include api version, project, or location.
|
|
1333
|
+
For example, if base_url is set to "https://aiplatform.googleapis.com",
|
|
1334
|
+
then the resource name for a Model would be
|
|
1335
|
+
"https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview
|
|
1336
|
+
*/
|
|
1337
|
+
ResourceScope["COLLECTION"] = "COLLECTION";
|
|
1338
|
+
})(ResourceScope || (ResourceScope = {}));
|
|
1327
1339
|
/** Options for feature selection preference. */
|
|
1328
1340
|
var FeatureSelectionPreference;
|
|
1329
1341
|
(function (FeatureSelectionPreference) {
|
|
@@ -4160,6 +4172,9 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
|
|
|
4160
4172
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
4161
4173
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
4162
4174
|
}
|
|
4175
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
4176
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
4177
|
+
}
|
|
4163
4178
|
return toObject;
|
|
4164
4179
|
}
|
|
4165
4180
|
function generateContentResponseFromMldev$1(fromObject) {
|
|
@@ -8917,6 +8932,9 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
|
|
|
8917
8932
|
if (fromEnableEnhancedCivicAnswers != null) {
|
|
8918
8933
|
setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
|
|
8919
8934
|
}
|
|
8935
|
+
if (getValueByPath(fromObject, ['modelArmorConfig']) !== undefined) {
|
|
8936
|
+
throw new Error('modelArmorConfig parameter is not supported in Gemini API.');
|
|
8937
|
+
}
|
|
8920
8938
|
return toObject;
|
|
8921
8939
|
}
|
|
8922
8940
|
function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
@@ -9085,6 +9103,12 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
|
|
|
9085
9103
|
undefined) {
|
|
9086
9104
|
throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
|
|
9087
9105
|
}
|
|
9106
|
+
const fromModelArmorConfig = getValueByPath(fromObject, [
|
|
9107
|
+
'modelArmorConfig',
|
|
9108
|
+
]);
|
|
9109
|
+
if (parentObject !== undefined && fromModelArmorConfig != null) {
|
|
9110
|
+
setValueByPath(parentObject, ['modelArmorConfig'], fromModelArmorConfig);
|
|
9111
|
+
}
|
|
9088
9112
|
return toObject;
|
|
9089
9113
|
}
|
|
9090
9114
|
function generateContentParametersToMldev(apiClient, fromObject) {
|
|
@@ -11501,7 +11525,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11501
11525
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11502
11526
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11503
11527
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11504
|
-
const SDK_VERSION = '1.
|
|
11528
|
+
const SDK_VERSION = '1.38.0'; // x-release-please-version
|
|
11505
11529
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11506
11530
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11507
11531
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11511,19 +11535,57 @@ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
|
11511
11535
|
*/
|
|
11512
11536
|
class ApiClient {
|
|
11513
11537
|
constructor(opts) {
|
|
11514
|
-
var _a, _b;
|
|
11515
|
-
this.clientOptions = Object.assign(
|
|
11538
|
+
var _a, _b, _c;
|
|
11539
|
+
this.clientOptions = Object.assign({}, opts);
|
|
11540
|
+
this.customBaseUrl = (_a = opts.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
|
11541
|
+
if (this.clientOptions.vertexai) {
|
|
11542
|
+
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11543
|
+
this.clientOptions.apiKey = undefined;
|
|
11544
|
+
}
|
|
11545
|
+
else if (this.clientOptions.apiKey) {
|
|
11546
|
+
this.clientOptions.project = undefined;
|
|
11547
|
+
this.clientOptions.location = undefined;
|
|
11548
|
+
}
|
|
11549
|
+
}
|
|
11516
11550
|
const initHttpOptions = {};
|
|
11517
11551
|
if (this.clientOptions.vertexai) {
|
|
11552
|
+
if (!this.clientOptions.location &&
|
|
11553
|
+
!this.clientOptions.apiKey &&
|
|
11554
|
+
!this.customBaseUrl) {
|
|
11555
|
+
this.clientOptions.location = 'global';
|
|
11556
|
+
}
|
|
11557
|
+
const hasSufficientAuth = (this.clientOptions.project && this.clientOptions.location) ||
|
|
11558
|
+
this.clientOptions.apiKey;
|
|
11559
|
+
if (!hasSufficientAuth && !this.customBaseUrl) {
|
|
11560
|
+
throw new Error('Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.');
|
|
11561
|
+
}
|
|
11562
|
+
const hasConstructorAuth = (opts.project && opts.location) || !!opts.apiKey;
|
|
11563
|
+
if (this.customBaseUrl && !hasConstructorAuth) {
|
|
11564
|
+
initHttpOptions.baseUrl = this.customBaseUrl;
|
|
11565
|
+
this.clientOptions.project = undefined;
|
|
11566
|
+
this.clientOptions.location = undefined;
|
|
11567
|
+
}
|
|
11568
|
+
else if (this.clientOptions.apiKey ||
|
|
11569
|
+
this.clientOptions.location === 'global') {
|
|
11570
|
+
// Vertex Express or global endpoint case.
|
|
11571
|
+
initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
|
|
11572
|
+
}
|
|
11573
|
+
else if (this.clientOptions.project && this.clientOptions.location) {
|
|
11574
|
+
initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11575
|
+
}
|
|
11518
11576
|
initHttpOptions.apiVersion =
|
|
11519
|
-
(
|
|
11520
|
-
initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
|
|
11521
|
-
this.normalizeAuthParameters();
|
|
11577
|
+
(_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : VERTEX_AI_API_DEFAULT_VERSION;
|
|
11522
11578
|
}
|
|
11523
11579
|
else {
|
|
11524
11580
|
// Gemini API
|
|
11581
|
+
if (!this.clientOptions.apiKey) {
|
|
11582
|
+
throw new ApiError({
|
|
11583
|
+
message: 'API key must be set when using the Gemini API.',
|
|
11584
|
+
status: 403,
|
|
11585
|
+
});
|
|
11586
|
+
}
|
|
11525
11587
|
initHttpOptions.apiVersion =
|
|
11526
|
-
(
|
|
11588
|
+
(_c = this.clientOptions.apiVersion) !== null && _c !== void 0 ? _c : GOOGLE_AI_API_DEFAULT_VERSION;
|
|
11527
11589
|
initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
|
|
11528
11590
|
}
|
|
11529
11591
|
initHttpOptions.headers = this.getDefaultHeaders();
|
|
@@ -11532,39 +11594,6 @@ class ApiClient {
|
|
|
11532
11594
|
this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
|
|
11533
11595
|
}
|
|
11534
11596
|
}
|
|
11535
|
-
/**
|
|
11536
|
-
* Determines the base URL for Vertex AI based on project and location.
|
|
11537
|
-
* Uses the global endpoint if location is 'global' or if project/location
|
|
11538
|
-
* are not specified (implying API key usage).
|
|
11539
|
-
* @private
|
|
11540
|
-
*/
|
|
11541
|
-
baseUrlFromProjectLocation() {
|
|
11542
|
-
if (this.clientOptions.project &&
|
|
11543
|
-
this.clientOptions.location &&
|
|
11544
|
-
this.clientOptions.location !== 'global') {
|
|
11545
|
-
// Regional endpoint
|
|
11546
|
-
return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11547
|
-
}
|
|
11548
|
-
// Global endpoint (covers 'global' location and API key usage)
|
|
11549
|
-
return `https://aiplatform.googleapis.com/`;
|
|
11550
|
-
}
|
|
11551
|
-
/**
|
|
11552
|
-
* Normalizes authentication parameters for Vertex AI.
|
|
11553
|
-
* If project and location are provided, API key is cleared.
|
|
11554
|
-
* If project and location are not provided (implying API key usage),
|
|
11555
|
-
* project and location are cleared.
|
|
11556
|
-
* @private
|
|
11557
|
-
*/
|
|
11558
|
-
normalizeAuthParameters() {
|
|
11559
|
-
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11560
|
-
// Using project/location for auth, clear potential API key
|
|
11561
|
-
this.clientOptions.apiKey = undefined;
|
|
11562
|
-
return;
|
|
11563
|
-
}
|
|
11564
|
-
// Using API key for auth (or no auth provided yet), clear project/location
|
|
11565
|
-
this.clientOptions.project = undefined;
|
|
11566
|
-
this.clientOptions.location = undefined;
|
|
11567
|
-
}
|
|
11568
11597
|
isVertexAI() {
|
|
11569
11598
|
var _a;
|
|
11570
11599
|
return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
|
|
@@ -11575,6 +11604,9 @@ class ApiClient {
|
|
|
11575
11604
|
getLocation() {
|
|
11576
11605
|
return this.clientOptions.location;
|
|
11577
11606
|
}
|
|
11607
|
+
getCustomBaseUrl() {
|
|
11608
|
+
return this.customBaseUrl;
|
|
11609
|
+
}
|
|
11578
11610
|
async getAuthHeaders() {
|
|
11579
11611
|
const headers = new Headers();
|
|
11580
11612
|
await this.clientOptions.auth.addAuthHeaders(headers);
|
|
@@ -11652,7 +11684,11 @@ class ApiClient {
|
|
|
11652
11684
|
const url = new URL(`${urlElement.join('/')}`);
|
|
11653
11685
|
return url;
|
|
11654
11686
|
}
|
|
11655
|
-
shouldPrependVertexProjectPath(request) {
|
|
11687
|
+
shouldPrependVertexProjectPath(request, httpOptions) {
|
|
11688
|
+
if (httpOptions.baseUrl &&
|
|
11689
|
+
httpOptions.baseUrlResourceScope === ResourceScope.COLLECTION) {
|
|
11690
|
+
return false;
|
|
11691
|
+
}
|
|
11656
11692
|
if (this.clientOptions.apiKey) {
|
|
11657
11693
|
return false;
|
|
11658
11694
|
}
|
|
@@ -11678,7 +11714,7 @@ class ApiClient {
|
|
|
11678
11714
|
if (request.httpOptions) {
|
|
11679
11715
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11680
11716
|
}
|
|
11681
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11717
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11682
11718
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11683
11719
|
if (request.queryParams) {
|
|
11684
11720
|
for (const [key, value] of Object.entries(request.queryParams)) {
|
|
@@ -11721,7 +11757,7 @@ class ApiClient {
|
|
|
11721
11757
|
if (request.httpOptions) {
|
|
11722
11758
|
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11723
11759
|
}
|
|
11724
|
-
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11760
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request, patchedHttpOptions);
|
|
11725
11761
|
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11726
11762
|
if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
|
|
11727
11763
|
url.searchParams.set('alt', 'sse');
|
|
@@ -12648,8 +12684,19 @@ class Live {
|
|
|
12648
12684
|
}
|
|
12649
12685
|
const headers = mapToHeaders(clientHeaders);
|
|
12650
12686
|
if (this.apiClient.isVertexAI()) {
|
|
12651
|
-
|
|
12652
|
-
|
|
12687
|
+
const project = this.apiClient.getProject();
|
|
12688
|
+
const location = this.apiClient.getLocation();
|
|
12689
|
+
const apiKey = this.apiClient.getApiKey();
|
|
12690
|
+
const hasStandardAuth = (!!project && !!location) || !!apiKey;
|
|
12691
|
+
if (this.apiClient.getCustomBaseUrl() && !hasStandardAuth) {
|
|
12692
|
+
// Custom base URL without standard auth (e.g., proxy).
|
|
12693
|
+
url = websocketBaseUrl;
|
|
12694
|
+
// Auth headers are assumed to be in `clientHeaders` from httpOptions.
|
|
12695
|
+
}
|
|
12696
|
+
else {
|
|
12697
|
+
url = `${websocketBaseUrl}/ws/google.cloud.aiplatform.${apiVersion}.LlmBidiService/BidiGenerateContent`;
|
|
12698
|
+
await this.auth.addAuthHeaders(headers, url);
|
|
12699
|
+
}
|
|
12653
12700
|
}
|
|
12654
12701
|
else {
|
|
12655
12702
|
const apiKey = this.apiClient.getApiKey();
|
|
@@ -12695,8 +12742,10 @@ class Live {
|
|
|
12695
12742
|
transformedModel.startsWith('publishers/')) {
|
|
12696
12743
|
const project = this.apiClient.getProject();
|
|
12697
12744
|
const location = this.apiClient.getLocation();
|
|
12698
|
-
|
|
12699
|
-
|
|
12745
|
+
if (project && location) {
|
|
12746
|
+
transformedModel =
|
|
12747
|
+
`projects/${project}/locations/${location}/` + transformedModel;
|
|
12748
|
+
}
|
|
12700
12749
|
}
|
|
12701
12750
|
let clientMessage = {};
|
|
12702
12751
|
if (this.apiClient.isVertexAI() &&
|
|
@@ -19243,5 +19292,5 @@ class GoogleGenAI {
|
|
|
19243
19292
|
}
|
|
19244
19293
|
}
|
|
19245
19294
|
|
|
19246
|
-
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 };
|
|
19295
|
+
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 };
|
|
19247
19296
|
//# sourceMappingURL=index.mjs.map
|