@google/genai 2.2.0 → 2.3.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/README.md +4 -1
- package/dist/genai.d.ts +42 -29
- package/dist/index.cjs +73 -6
- package/dist/index.mjs +73 -6
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +73 -6
- package/dist/node/index.mjs +73 -6
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +42 -29
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/vertex_internal/index.cjs +1 -1
- package/dist/vertex_internal/index.cjs.map +1 -1
- package/dist/vertex_internal/index.d.ts +14 -0
- package/dist/vertex_internal/index.js +1 -1
- package/dist/vertex_internal/index.js.map +1 -1
- package/dist/web/index.mjs +73 -6
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +42 -29
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -8262,6 +8262,12 @@ function liveConnectConfigToMldev$1(fromObject, parentObject) {
|
|
|
8262
8262
|
}
|
|
8263
8263
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
8264
8264
|
}
|
|
8265
|
+
const fromStreamTranslationConfig = getValueByPath(fromObject, [
|
|
8266
|
+
'streamTranslationConfig',
|
|
8267
|
+
]);
|
|
8268
|
+
if (parentObject !== undefined && fromStreamTranslationConfig != null) {
|
|
8269
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'streamTranslationConfig'], fromStreamTranslationConfig);
|
|
8270
|
+
}
|
|
8265
8271
|
return toObject;
|
|
8266
8272
|
}
|
|
8267
8273
|
function liveConnectConfigToVertex(fromObject, parentObject) {
|
|
@@ -8394,6 +8400,9 @@ function liveConnectConfigToVertex(fromObject, parentObject) {
|
|
|
8394
8400
|
}
|
|
8395
8401
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
8396
8402
|
}
|
|
8403
|
+
if (getValueByPath(fromObject, ['streamTranslationConfig']) !== undefined) {
|
|
8404
|
+
throw new Error('streamTranslationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.');
|
|
8405
|
+
}
|
|
8397
8406
|
return toObject;
|
|
8398
8407
|
}
|
|
8399
8408
|
function liveConnectParametersToMldev(apiClient, fromObject) {
|
|
@@ -12814,7 +12823,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12814
12823
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12815
12824
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12816
12825
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12817
|
-
const SDK_VERSION = '2.
|
|
12826
|
+
const SDK_VERSION = '2.3.0'; // x-release-please-version
|
|
12818
12827
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12819
12828
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12820
12829
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -16464,6 +16473,12 @@ function liveConnectConfigToMldev(fromObject, parentObject) {
|
|
|
16464
16473
|
}
|
|
16465
16474
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
16466
16475
|
}
|
|
16476
|
+
const fromStreamTranslationConfig = getValueByPath(fromObject, [
|
|
16477
|
+
'streamTranslationConfig',
|
|
16478
|
+
]);
|
|
16479
|
+
if (parentObject !== undefined && fromStreamTranslationConfig != null) {
|
|
16480
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'streamTranslationConfig'], fromStreamTranslationConfig);
|
|
16481
|
+
}
|
|
16467
16482
|
return toObject;
|
|
16468
16483
|
}
|
|
16469
16484
|
function liveConnectConstraintsToMldev(apiClient, fromObject) {
|
|
@@ -18724,10 +18739,14 @@ class BaseInteractions extends APIResource {
|
|
|
18724
18739
|
});
|
|
18725
18740
|
const isStreaming = (_a = params.stream) !== null && _a !== void 0 ? _a : false;
|
|
18726
18741
|
const promise = this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign(Object.assign({ body }, options), { stream: isStreaming }), (needsLegacyLyriaShim && isStreaming ? { __streamClass: LegacyLyriaStream } : {})));
|
|
18727
|
-
if (
|
|
18728
|
-
return promise
|
|
18742
|
+
if (isStreaming) {
|
|
18743
|
+
return promise;
|
|
18729
18744
|
}
|
|
18730
|
-
|
|
18745
|
+
let nonStreaming = promise;
|
|
18746
|
+
if (needsLegacyLyriaShim) {
|
|
18747
|
+
nonStreaming = nonStreaming._thenUnwrap((data) => coerceLegacyInteractionResponse(data));
|
|
18748
|
+
}
|
|
18749
|
+
return nonStreaming._thenUnwrap(addOutputProperties);
|
|
18731
18750
|
}
|
|
18732
18751
|
/**
|
|
18733
18752
|
* Deletes the interaction by id.
|
|
@@ -18756,17 +18775,64 @@ class BaseInteractions extends APIResource {
|
|
|
18756
18775
|
*/
|
|
18757
18776
|
cancel(id, params = {}, options) {
|
|
18758
18777
|
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18759
|
-
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
|
|
18778
|
+
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options)._thenUnwrap(addOutputProperties);
|
|
18760
18779
|
}
|
|
18761
18780
|
get(id, params = {}, options) {
|
|
18762
18781
|
var _a;
|
|
18763
18782
|
const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
|
|
18764
|
-
|
|
18783
|
+
const response = this._client.get(path `/${api_version}/interactions/${id}`, Object.assign(Object.assign({ query }, options), { stream: (_a = params === null || params === void 0 ? void 0 : params.stream) !== null && _a !== void 0 ? _a : false }));
|
|
18784
|
+
if (params === null || params === void 0 ? void 0 : params.stream) {
|
|
18785
|
+
return response;
|
|
18786
|
+
}
|
|
18787
|
+
return response._thenUnwrap(addOutputProperties);
|
|
18765
18788
|
}
|
|
18766
18789
|
}
|
|
18767
18790
|
BaseInteractions._key = Object.freeze(['interactions']);
|
|
18768
18791
|
class Interactions extends BaseInteractions {
|
|
18769
18792
|
}
|
|
18793
|
+
function addOutputProperties(interaction) {
|
|
18794
|
+
var _a, _b;
|
|
18795
|
+
const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
|
|
18796
|
+
let firstTrailing = steps.length;
|
|
18797
|
+
while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
|
|
18798
|
+
firstTrailing--;
|
|
18799
|
+
}
|
|
18800
|
+
const modelSteps = steps.slice(firstTrailing);
|
|
18801
|
+
const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
|
|
18802
|
+
const textParts = [];
|
|
18803
|
+
for (let i = output.length - 1; i >= 0; i--) {
|
|
18804
|
+
const content = output[i];
|
|
18805
|
+
if (content.type !== 'text')
|
|
18806
|
+
break;
|
|
18807
|
+
textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
|
|
18808
|
+
}
|
|
18809
|
+
const output_text = textParts.reverse().join('');
|
|
18810
|
+
let output_image;
|
|
18811
|
+
let output_audio;
|
|
18812
|
+
let output_video;
|
|
18813
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
18814
|
+
const step = steps[i];
|
|
18815
|
+
const anyStep = step;
|
|
18816
|
+
if (anyStep.type === 'user_input') {
|
|
18817
|
+
break;
|
|
18818
|
+
}
|
|
18819
|
+
if (anyStep.type === 'model_output' && anyStep.content) {
|
|
18820
|
+
for (let j = anyStep.content.length - 1; j >= 0; j--) {
|
|
18821
|
+
const content = anyStep.content[j];
|
|
18822
|
+
if (content.type === 'image' && !output_image) {
|
|
18823
|
+
output_image = content;
|
|
18824
|
+
}
|
|
18825
|
+
if (content.type === 'audio' && !output_audio) {
|
|
18826
|
+
output_audio = content;
|
|
18827
|
+
}
|
|
18828
|
+
if (content.type === 'video' && !output_video) {
|
|
18829
|
+
output_video = content;
|
|
18830
|
+
}
|
|
18831
|
+
}
|
|
18832
|
+
}
|
|
18833
|
+
}
|
|
18834
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, interaction), (output_text && { output_text })), (output_image && { output_image })), (output_audio && { output_audio })), (output_video && { output_video }));
|
|
18835
|
+
}
|
|
18770
18836
|
|
|
18771
18837
|
/**
|
|
18772
18838
|
* @license
|
|
@@ -21319,6 +21385,7 @@ class GoogleGenAI {
|
|
|
21319
21385
|
if (this._interactions !== undefined) {
|
|
21320
21386
|
return this._interactions;
|
|
21321
21387
|
}
|
|
21388
|
+
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
21322
21389
|
this._interactions = this.getNextGenClient().interactions;
|
|
21323
21390
|
return this._interactions;
|
|
21324
21391
|
}
|
package/dist/node/index.mjs
CHANGED
|
@@ -8240,6 +8240,12 @@ function liveConnectConfigToMldev$1(fromObject, parentObject) {
|
|
|
8240
8240
|
}
|
|
8241
8241
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
8242
8242
|
}
|
|
8243
|
+
const fromStreamTranslationConfig = getValueByPath(fromObject, [
|
|
8244
|
+
'streamTranslationConfig',
|
|
8245
|
+
]);
|
|
8246
|
+
if (parentObject !== undefined && fromStreamTranslationConfig != null) {
|
|
8247
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'streamTranslationConfig'], fromStreamTranslationConfig);
|
|
8248
|
+
}
|
|
8243
8249
|
return toObject;
|
|
8244
8250
|
}
|
|
8245
8251
|
function liveConnectConfigToVertex(fromObject, parentObject) {
|
|
@@ -8372,6 +8378,9 @@ function liveConnectConfigToVertex(fromObject, parentObject) {
|
|
|
8372
8378
|
}
|
|
8373
8379
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
8374
8380
|
}
|
|
8381
|
+
if (getValueByPath(fromObject, ['streamTranslationConfig']) !== undefined) {
|
|
8382
|
+
throw new Error('streamTranslationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.');
|
|
8383
|
+
}
|
|
8375
8384
|
return toObject;
|
|
8376
8385
|
}
|
|
8377
8386
|
function liveConnectParametersToMldev(apiClient, fromObject) {
|
|
@@ -12792,7 +12801,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12792
12801
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12793
12802
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12794
12803
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12795
|
-
const SDK_VERSION = '2.
|
|
12804
|
+
const SDK_VERSION = '2.3.0'; // x-release-please-version
|
|
12796
12805
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12797
12806
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12798
12807
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -16442,6 +16451,12 @@ function liveConnectConfigToMldev(fromObject, parentObject) {
|
|
|
16442
16451
|
}
|
|
16443
16452
|
setValueByPath(parentObject, ['setup', 'safetySettings'], transformedList);
|
|
16444
16453
|
}
|
|
16454
|
+
const fromStreamTranslationConfig = getValueByPath(fromObject, [
|
|
16455
|
+
'streamTranslationConfig',
|
|
16456
|
+
]);
|
|
16457
|
+
if (parentObject !== undefined && fromStreamTranslationConfig != null) {
|
|
16458
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'streamTranslationConfig'], fromStreamTranslationConfig);
|
|
16459
|
+
}
|
|
16445
16460
|
return toObject;
|
|
16446
16461
|
}
|
|
16447
16462
|
function liveConnectConstraintsToMldev(apiClient, fromObject) {
|
|
@@ -18702,10 +18717,14 @@ class BaseInteractions extends APIResource {
|
|
|
18702
18717
|
});
|
|
18703
18718
|
const isStreaming = (_a = params.stream) !== null && _a !== void 0 ? _a : false;
|
|
18704
18719
|
const promise = this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign(Object.assign({ body }, options), { stream: isStreaming }), (needsLegacyLyriaShim && isStreaming ? { __streamClass: LegacyLyriaStream } : {})));
|
|
18705
|
-
if (
|
|
18706
|
-
return promise
|
|
18720
|
+
if (isStreaming) {
|
|
18721
|
+
return promise;
|
|
18707
18722
|
}
|
|
18708
|
-
|
|
18723
|
+
let nonStreaming = promise;
|
|
18724
|
+
if (needsLegacyLyriaShim) {
|
|
18725
|
+
nonStreaming = nonStreaming._thenUnwrap((data) => coerceLegacyInteractionResponse(data));
|
|
18726
|
+
}
|
|
18727
|
+
return nonStreaming._thenUnwrap(addOutputProperties);
|
|
18709
18728
|
}
|
|
18710
18729
|
/**
|
|
18711
18730
|
* Deletes the interaction by id.
|
|
@@ -18734,17 +18753,64 @@ class BaseInteractions extends APIResource {
|
|
|
18734
18753
|
*/
|
|
18735
18754
|
cancel(id, params = {}, options) {
|
|
18736
18755
|
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18737
|
-
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
|
|
18756
|
+
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options)._thenUnwrap(addOutputProperties);
|
|
18738
18757
|
}
|
|
18739
18758
|
get(id, params = {}, options) {
|
|
18740
18759
|
var _a;
|
|
18741
18760
|
const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
|
|
18742
|
-
|
|
18761
|
+
const response = this._client.get(path `/${api_version}/interactions/${id}`, Object.assign(Object.assign({ query }, options), { stream: (_a = params === null || params === void 0 ? void 0 : params.stream) !== null && _a !== void 0 ? _a : false }));
|
|
18762
|
+
if (params === null || params === void 0 ? void 0 : params.stream) {
|
|
18763
|
+
return response;
|
|
18764
|
+
}
|
|
18765
|
+
return response._thenUnwrap(addOutputProperties);
|
|
18743
18766
|
}
|
|
18744
18767
|
}
|
|
18745
18768
|
BaseInteractions._key = Object.freeze(['interactions']);
|
|
18746
18769
|
class Interactions extends BaseInteractions {
|
|
18747
18770
|
}
|
|
18771
|
+
function addOutputProperties(interaction) {
|
|
18772
|
+
var _a, _b;
|
|
18773
|
+
const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
|
|
18774
|
+
let firstTrailing = steps.length;
|
|
18775
|
+
while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
|
|
18776
|
+
firstTrailing--;
|
|
18777
|
+
}
|
|
18778
|
+
const modelSteps = steps.slice(firstTrailing);
|
|
18779
|
+
const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
|
|
18780
|
+
const textParts = [];
|
|
18781
|
+
for (let i = output.length - 1; i >= 0; i--) {
|
|
18782
|
+
const content = output[i];
|
|
18783
|
+
if (content.type !== 'text')
|
|
18784
|
+
break;
|
|
18785
|
+
textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
|
|
18786
|
+
}
|
|
18787
|
+
const output_text = textParts.reverse().join('');
|
|
18788
|
+
let output_image;
|
|
18789
|
+
let output_audio;
|
|
18790
|
+
let output_video;
|
|
18791
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
18792
|
+
const step = steps[i];
|
|
18793
|
+
const anyStep = step;
|
|
18794
|
+
if (anyStep.type === 'user_input') {
|
|
18795
|
+
break;
|
|
18796
|
+
}
|
|
18797
|
+
if (anyStep.type === 'model_output' && anyStep.content) {
|
|
18798
|
+
for (let j = anyStep.content.length - 1; j >= 0; j--) {
|
|
18799
|
+
const content = anyStep.content[j];
|
|
18800
|
+
if (content.type === 'image' && !output_image) {
|
|
18801
|
+
output_image = content;
|
|
18802
|
+
}
|
|
18803
|
+
if (content.type === 'audio' && !output_audio) {
|
|
18804
|
+
output_audio = content;
|
|
18805
|
+
}
|
|
18806
|
+
if (content.type === 'video' && !output_video) {
|
|
18807
|
+
output_video = content;
|
|
18808
|
+
}
|
|
18809
|
+
}
|
|
18810
|
+
}
|
|
18811
|
+
}
|
|
18812
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, interaction), (output_text && { output_text })), (output_image && { output_image })), (output_audio && { output_audio })), (output_video && { output_video }));
|
|
18813
|
+
}
|
|
18748
18814
|
|
|
18749
18815
|
/**
|
|
18750
18816
|
* @license
|
|
@@ -21297,6 +21363,7 @@ class GoogleGenAI {
|
|
|
21297
21363
|
if (this._interactions !== undefined) {
|
|
21298
21364
|
return this._interactions;
|
|
21299
21365
|
}
|
|
21366
|
+
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
21300
21367
|
this._interactions = this.getNextGenClient().interactions;
|
|
21301
21368
|
return this._interactions;
|
|
21302
21369
|
}
|