@google/genai 2.0.1 → 2.1.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 +147 -12
- package/dist/index.cjs +352 -322
- package/dist/index.mjs +352 -322
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +447 -417
- package/dist/node/index.mjs +447 -417
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +147 -12
- package/dist/tokenizer/node.cjs +2 -2
- package/dist/tokenizer/node.d.ts +3 -3
- package/dist/tokenizer/node.mjs +2 -2
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/vertex_internal/index.cjs +3 -3
- package/dist/vertex_internal/index.cjs.map +1 -1
- package/dist/vertex_internal/index.d.ts +3 -3
- package/dist/vertex_internal/index.js +3 -3
- package/dist/vertex_internal/index.js.map +1 -1
- package/dist/web/index.mjs +447 -417
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +147 -12
- package/package.json +1 -1
package/dist/web/index.mjs
CHANGED
|
@@ -788,11 +788,11 @@ var PhishBlockThreshold;
|
|
|
788
788
|
*/
|
|
789
789
|
PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
|
|
790
790
|
})(PhishBlockThreshold || (PhishBlockThreshold = {}));
|
|
791
|
-
/** Specifies the function Behavior. Currently only supported
|
|
791
|
+
/** Specifies the function Behavior. Currently only non-blocking functions are supported. If not specified, the system keeps the current function call behavior. This field is currently only supported by the BidiGenerateContent method. */
|
|
792
792
|
var Behavior;
|
|
793
793
|
(function (Behavior) {
|
|
794
794
|
/**
|
|
795
|
-
* This value is
|
|
795
|
+
* This value is unspecified.
|
|
796
796
|
*/
|
|
797
797
|
Behavior["UNSPECIFIED"] = "UNSPECIFIED";
|
|
798
798
|
/**
|
|
@@ -6080,41 +6080,6 @@ function functionCallingConfigToMldev$1(fromObject) {
|
|
|
6080
6080
|
}
|
|
6081
6081
|
return toObject;
|
|
6082
6082
|
}
|
|
6083
|
-
function functionDeclarationToVertex$2(fromObject) {
|
|
6084
|
-
const toObject = {};
|
|
6085
|
-
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
6086
|
-
if (fromDescription != null) {
|
|
6087
|
-
setValueByPath(toObject, ['description'], fromDescription);
|
|
6088
|
-
}
|
|
6089
|
-
const fromName = getValueByPath(fromObject, ['name']);
|
|
6090
|
-
if (fromName != null) {
|
|
6091
|
-
setValueByPath(toObject, ['name'], fromName);
|
|
6092
|
-
}
|
|
6093
|
-
const fromParameters = getValueByPath(fromObject, ['parameters']);
|
|
6094
|
-
if (fromParameters != null) {
|
|
6095
|
-
setValueByPath(toObject, ['parameters'], fromParameters);
|
|
6096
|
-
}
|
|
6097
|
-
const fromParametersJsonSchema = getValueByPath(fromObject, [
|
|
6098
|
-
'parametersJsonSchema',
|
|
6099
|
-
]);
|
|
6100
|
-
if (fromParametersJsonSchema != null) {
|
|
6101
|
-
setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
|
|
6102
|
-
}
|
|
6103
|
-
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
6104
|
-
if (fromResponse != null) {
|
|
6105
|
-
setValueByPath(toObject, ['response'], fromResponse);
|
|
6106
|
-
}
|
|
6107
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
6108
|
-
'responseJsonSchema',
|
|
6109
|
-
]);
|
|
6110
|
-
if (fromResponseJsonSchema != null) {
|
|
6111
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
6112
|
-
}
|
|
6113
|
-
if (getValueByPath(fromObject, ['behavior']) !== undefined) {
|
|
6114
|
-
throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
|
|
6115
|
-
}
|
|
6116
|
-
return toObject;
|
|
6117
|
-
}
|
|
6118
6083
|
function getCachedContentParametersToMldev(apiClient, fromObject) {
|
|
6119
6084
|
const toObject = {};
|
|
6120
6085
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
@@ -6547,7 +6512,7 @@ function toolToVertex$2(fromObject) {
|
|
|
6547
6512
|
let transformedList = fromFunctionDeclarations;
|
|
6548
6513
|
if (Array.isArray(transformedList)) {
|
|
6549
6514
|
transformedList = transformedList.map((item) => {
|
|
6550
|
-
return
|
|
6515
|
+
return item;
|
|
6551
6516
|
});
|
|
6552
6517
|
}
|
|
6553
6518
|
setValueByPath(toObject, ['functionDeclarations'], transformedList);
|
|
@@ -7980,41 +7945,6 @@ function functionCallToMldev$2(fromObject) {
|
|
|
7980
7945
|
}
|
|
7981
7946
|
return toObject;
|
|
7982
7947
|
}
|
|
7983
|
-
function functionDeclarationToVertex$1(fromObject) {
|
|
7984
|
-
const toObject = {};
|
|
7985
|
-
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
7986
|
-
if (fromDescription != null) {
|
|
7987
|
-
setValueByPath(toObject, ['description'], fromDescription);
|
|
7988
|
-
}
|
|
7989
|
-
const fromName = getValueByPath(fromObject, ['name']);
|
|
7990
|
-
if (fromName != null) {
|
|
7991
|
-
setValueByPath(toObject, ['name'], fromName);
|
|
7992
|
-
}
|
|
7993
|
-
const fromParameters = getValueByPath(fromObject, ['parameters']);
|
|
7994
|
-
if (fromParameters != null) {
|
|
7995
|
-
setValueByPath(toObject, ['parameters'], fromParameters);
|
|
7996
|
-
}
|
|
7997
|
-
const fromParametersJsonSchema = getValueByPath(fromObject, [
|
|
7998
|
-
'parametersJsonSchema',
|
|
7999
|
-
]);
|
|
8000
|
-
if (fromParametersJsonSchema != null) {
|
|
8001
|
-
setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
|
|
8002
|
-
}
|
|
8003
|
-
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
8004
|
-
if (fromResponse != null) {
|
|
8005
|
-
setValueByPath(toObject, ['response'], fromResponse);
|
|
8006
|
-
}
|
|
8007
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
8008
|
-
'responseJsonSchema',
|
|
8009
|
-
]);
|
|
8010
|
-
if (fromResponseJsonSchema != null) {
|
|
8011
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
8012
|
-
}
|
|
8013
|
-
if (getValueByPath(fromObject, ['behavior']) !== undefined) {
|
|
8014
|
-
throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
|
|
8015
|
-
}
|
|
8016
|
-
return toObject;
|
|
8017
|
-
}
|
|
8018
7948
|
function generationConfigToVertex$1(fromObject) {
|
|
8019
7949
|
const toObject = {};
|
|
8020
7950
|
const fromModelSelectionConfig = getValueByPath(fromObject, [
|
|
@@ -8898,7 +8828,7 @@ function toolToVertex$1(fromObject) {
|
|
|
8898
8828
|
let transformedList = fromFunctionDeclarations;
|
|
8899
8829
|
if (Array.isArray(transformedList)) {
|
|
8900
8830
|
transformedList = transformedList.map((item) => {
|
|
8901
|
-
return
|
|
8831
|
+
return item;
|
|
8902
8832
|
});
|
|
8903
8833
|
}
|
|
8904
8834
|
setValueByPath(toObject, ['functionDeclarations'], transformedList);
|
|
@@ -9913,41 +9843,6 @@ function functionCallingConfigToMldev(fromObject, _rootObject) {
|
|
|
9913
9843
|
}
|
|
9914
9844
|
return toObject;
|
|
9915
9845
|
}
|
|
9916
|
-
function functionDeclarationToVertex(fromObject, _rootObject) {
|
|
9917
|
-
const toObject = {};
|
|
9918
|
-
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
9919
|
-
if (fromDescription != null) {
|
|
9920
|
-
setValueByPath(toObject, ['description'], fromDescription);
|
|
9921
|
-
}
|
|
9922
|
-
const fromName = getValueByPath(fromObject, ['name']);
|
|
9923
|
-
if (fromName != null) {
|
|
9924
|
-
setValueByPath(toObject, ['name'], fromName);
|
|
9925
|
-
}
|
|
9926
|
-
const fromParameters = getValueByPath(fromObject, ['parameters']);
|
|
9927
|
-
if (fromParameters != null) {
|
|
9928
|
-
setValueByPath(toObject, ['parameters'], fromParameters);
|
|
9929
|
-
}
|
|
9930
|
-
const fromParametersJsonSchema = getValueByPath(fromObject, [
|
|
9931
|
-
'parametersJsonSchema',
|
|
9932
|
-
]);
|
|
9933
|
-
if (fromParametersJsonSchema != null) {
|
|
9934
|
-
setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
|
|
9935
|
-
}
|
|
9936
|
-
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
9937
|
-
if (fromResponse != null) {
|
|
9938
|
-
setValueByPath(toObject, ['response'], fromResponse);
|
|
9939
|
-
}
|
|
9940
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
9941
|
-
'responseJsonSchema',
|
|
9942
|
-
]);
|
|
9943
|
-
if (fromResponseJsonSchema != null) {
|
|
9944
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
9945
|
-
}
|
|
9946
|
-
if (getValueByPath(fromObject, ['behavior']) !== undefined) {
|
|
9947
|
-
throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
|
|
9948
|
-
}
|
|
9949
|
-
return toObject;
|
|
9950
|
-
}
|
|
9951
9846
|
function generateContentConfigToMldev(apiClient, fromObject, parentObject, rootObject) {
|
|
9952
9847
|
const toObject = {};
|
|
9953
9848
|
const fromSystemInstruction = getValueByPath(fromObject, [
|
|
@@ -12264,7 +12159,7 @@ function toolToMldev$1(fromObject, rootObject) {
|
|
|
12264
12159
|
}
|
|
12265
12160
|
return toObject;
|
|
12266
12161
|
}
|
|
12267
|
-
function toolToVertex(fromObject,
|
|
12162
|
+
function toolToVertex(fromObject, _rootObject) {
|
|
12268
12163
|
const toObject = {};
|
|
12269
12164
|
const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
|
|
12270
12165
|
if (fromRetrieval != null) {
|
|
@@ -12304,7 +12199,7 @@ function toolToVertex(fromObject, rootObject) {
|
|
|
12304
12199
|
let transformedList = fromFunctionDeclarations;
|
|
12305
12200
|
if (Array.isArray(transformedList)) {
|
|
12306
12201
|
transformedList = transformedList.map((item) => {
|
|
12307
|
-
return
|
|
12202
|
+
return item;
|
|
12308
12203
|
});
|
|
12309
12204
|
}
|
|
12310
12205
|
setValueByPath(toObject, ['functionDeclarations'], transformedList);
|
|
@@ -12889,7 +12784,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12889
12784
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12890
12785
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12891
12786
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12892
|
-
const SDK_VERSION = '2.0
|
|
12787
|
+
const SDK_VERSION = '2.1.0'; // x-release-please-version
|
|
12893
12788
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12894
12789
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12895
12790
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -18036,325 +17931,128 @@ class APIResource {
|
|
|
18036
17931
|
*/
|
|
18037
17932
|
APIResource._key = [];
|
|
18038
17933
|
|
|
17934
|
+
/**
|
|
17935
|
+
* @license
|
|
17936
|
+
* Copyright 2025 Google LLC
|
|
17937
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17938
|
+
*/
|
|
17939
|
+
function concatBytes(buffers) {
|
|
17940
|
+
let length = 0;
|
|
17941
|
+
for (const buffer of buffers) {
|
|
17942
|
+
length += buffer.length;
|
|
17943
|
+
}
|
|
17944
|
+
const output = new Uint8Array(length);
|
|
17945
|
+
let index = 0;
|
|
17946
|
+
for (const buffer of buffers) {
|
|
17947
|
+
output.set(buffer, index);
|
|
17948
|
+
index += buffer.length;
|
|
17949
|
+
}
|
|
17950
|
+
return output;
|
|
17951
|
+
}
|
|
17952
|
+
let encodeUTF8_;
|
|
17953
|
+
function encodeUTF8(str) {
|
|
17954
|
+
let encoder;
|
|
17955
|
+
return (encodeUTF8_ !== null && encodeUTF8_ !== void 0 ? encodeUTF8_ : ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
|
|
17956
|
+
}
|
|
17957
|
+
let decodeUTF8_;
|
|
17958
|
+
function decodeUTF8(bytes) {
|
|
17959
|
+
let decoder;
|
|
17960
|
+
return (decodeUTF8_ !== null && decodeUTF8_ !== void 0 ? decodeUTF8_ : ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
|
|
17961
|
+
}
|
|
17962
|
+
|
|
18039
17963
|
/**
|
|
18040
17964
|
* @license
|
|
18041
17965
|
* Copyright 2025 Google LLC
|
|
18042
17966
|
* SPDX-License-Identifier: Apache-2.0
|
|
18043
17967
|
*/
|
|
18044
17968
|
/**
|
|
18045
|
-
*
|
|
17969
|
+
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
17970
|
+
* reading lines from text.
|
|
18046
17971
|
*
|
|
18047
|
-
*
|
|
18048
|
-
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
18049
|
-
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
18050
|
-
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
17972
|
+
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
18051
17973
|
*/
|
|
18052
|
-
|
|
18053
|
-
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
|
|
18060
|
-
|
|
18061
|
-
|
|
18062
|
-
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
18063
|
-
var _a, _b, _c;
|
|
18064
|
-
if (/[?#]/.test(currentValue)) {
|
|
18065
|
-
postPath = true;
|
|
17974
|
+
class LineDecoder {
|
|
17975
|
+
constructor() {
|
|
17976
|
+
this.buffer = new Uint8Array();
|
|
17977
|
+
this.carriageReturnIndex = null;
|
|
17978
|
+
this.searchIndex = 0;
|
|
17979
|
+
}
|
|
17980
|
+
decode(chunk) {
|
|
17981
|
+
var _a;
|
|
17982
|
+
if (chunk == null) {
|
|
17983
|
+
return [];
|
|
18066
17984
|
}
|
|
18067
|
-
const
|
|
18068
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
|
|
18082
|
-
|
|
17985
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
17986
|
+
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
|
17987
|
+
: chunk;
|
|
17988
|
+
this.buffer = concatBytes([this.buffer, binaryChunk]);
|
|
17989
|
+
const lines = [];
|
|
17990
|
+
let patternIndex;
|
|
17991
|
+
while ((patternIndex = findNewlineIndex(this.buffer, (_a = this.carriageReturnIndex) !== null && _a !== void 0 ? _a : this.searchIndex)) != null) {
|
|
17992
|
+
if (patternIndex.carriage && this.carriageReturnIndex == null) {
|
|
17993
|
+
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
|
17994
|
+
this.carriageReturnIndex = patternIndex.index;
|
|
17995
|
+
continue;
|
|
17996
|
+
}
|
|
17997
|
+
// we got double \r or \rtext\n
|
|
17998
|
+
if (this.carriageReturnIndex != null &&
|
|
17999
|
+
(patternIndex.index !== this.carriageReturnIndex + 1 || patternIndex.carriage)) {
|
|
18000
|
+
lines.push(decodeUTF8(this.buffer.subarray(0, this.carriageReturnIndex - 1)));
|
|
18001
|
+
this.buffer = this.buffer.subarray(this.carriageReturnIndex);
|
|
18002
|
+
this.carriageReturnIndex = null;
|
|
18003
|
+
this.searchIndex = 0;
|
|
18004
|
+
continue;
|
|
18005
|
+
}
|
|
18006
|
+
const endIndex = this.carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
|
18007
|
+
const line = decodeUTF8(this.buffer.subarray(0, endIndex));
|
|
18008
|
+
lines.push(line);
|
|
18009
|
+
this.buffer = this.buffer.subarray(patternIndex.index);
|
|
18010
|
+
this.carriageReturnIndex = null;
|
|
18011
|
+
this.searchIndex = 0;
|
|
18083
18012
|
}
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
const pathOnly = path.split(/[?#]/, 1)[0];
|
|
18087
|
-
const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
18088
|
-
let match;
|
|
18089
|
-
// Find all invalid segments
|
|
18090
|
-
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
18091
|
-
const hasLeadingSlash = match[0].startsWith('/');
|
|
18092
|
-
const offset = hasLeadingSlash ? 1 : 0;
|
|
18093
|
-
const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
|
|
18094
|
-
invalidSegments.push({
|
|
18095
|
-
start: match.index + offset,
|
|
18096
|
-
length: cleanMatch.length,
|
|
18097
|
-
error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
|
|
18098
|
-
});
|
|
18013
|
+
this.searchIndex = Math.max(0, this.buffer.length - 1);
|
|
18014
|
+
return lines;
|
|
18099
18015
|
}
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
const arrows = '^'.repeat(segment.length);
|
|
18106
|
-
lastEnd = segment.start + segment.length;
|
|
18107
|
-
return acc + spaces + arrows;
|
|
18108
|
-
}, '');
|
|
18109
|
-
throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
18110
|
-
.map((e) => e.error)
|
|
18111
|
-
.join('\n')}\n${path}\n${underline}`);
|
|
18016
|
+
flush() {
|
|
18017
|
+
if (!this.buffer.length) {
|
|
18018
|
+
return [];
|
|
18019
|
+
}
|
|
18020
|
+
return this.decode('\n');
|
|
18112
18021
|
}
|
|
18113
|
-
|
|
18114
|
-
|
|
18022
|
+
}
|
|
18023
|
+
// prettier-ignore
|
|
18024
|
+
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
|
|
18025
|
+
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
18115
18026
|
/**
|
|
18116
|
-
*
|
|
18027
|
+
* This function searches the buffer for the end patterns, (\r or \n)
|
|
18028
|
+
* and returns an object with the index preceding the matched newline and the
|
|
18029
|
+
* index after the newline char. `null` is returned if no new line is found.
|
|
18030
|
+
*
|
|
18031
|
+
* ```ts
|
|
18032
|
+
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
|
18033
|
+
* ```
|
|
18117
18034
|
*/
|
|
18118
|
-
|
|
18119
|
-
|
|
18120
|
-
|
|
18121
|
-
|
|
18122
|
-
|
|
18123
|
-
|
|
18124
|
-
|
|
18125
|
-
|
|
18126
|
-
|
|
18127
|
-
|
|
18128
|
-
|
|
18129
|
-
|
|
18130
|
-
|
|
18131
|
-
|
|
18132
|
-
|
|
18133
|
-
|
|
18134
|
-
|
|
18135
|
-
return
|
|
18136
|
-
}
|
|
18137
|
-
|
|
18138
|
-
|
|
18139
|
-
*
|
|
18140
|
-
* @example
|
|
18141
|
-
* ```ts
|
|
18142
|
-
* const interaction = await client.interactions.delete('id', {
|
|
18143
|
-
* api_version: 'api_version',
|
|
18144
|
-
* });
|
|
18145
|
-
* ```
|
|
18146
|
-
*/
|
|
18147
|
-
delete(id, params = {}, options) {
|
|
18148
|
-
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18149
|
-
return this._client.delete(path `/${api_version}/interactions/${id}`, options);
|
|
18150
|
-
}
|
|
18151
|
-
/**
|
|
18152
|
-
* Cancels an interaction by id. This only applies to background interactions that
|
|
18153
|
-
* are still running.
|
|
18154
|
-
*
|
|
18155
|
-
* @example
|
|
18156
|
-
* ```ts
|
|
18157
|
-
* const interaction = await client.interactions.cancel('id', {
|
|
18158
|
-
* api_version: 'api_version',
|
|
18159
|
-
* });
|
|
18160
|
-
* ```
|
|
18161
|
-
*/
|
|
18162
|
-
cancel(id, params = {}, options) {
|
|
18163
|
-
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18164
|
-
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
|
|
18165
|
-
}
|
|
18166
|
-
get(id, params = {}, options) {
|
|
18167
|
-
var _a;
|
|
18168
|
-
const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
|
|
18169
|
-
return 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 }));
|
|
18170
|
-
}
|
|
18171
|
-
}
|
|
18172
|
-
BaseInteractions._key = Object.freeze(['interactions']);
|
|
18173
|
-
class Interactions extends BaseInteractions {
|
|
18174
|
-
}
|
|
18175
|
-
|
|
18176
|
-
/**
|
|
18177
|
-
* @license
|
|
18178
|
-
* Copyright 2025 Google LLC
|
|
18179
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
18180
|
-
*/
|
|
18181
|
-
class BaseWebhooks extends APIResource {
|
|
18182
|
-
/**
|
|
18183
|
-
* Creates a new Webhook.
|
|
18184
|
-
*/
|
|
18185
|
-
create(params, options) {
|
|
18186
|
-
const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
|
|
18187
|
-
return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
|
|
18188
|
-
}
|
|
18189
|
-
/**
|
|
18190
|
-
* Updates an existing Webhook.
|
|
18191
|
-
*/
|
|
18192
|
-
update(id, params = {}, options) {
|
|
18193
|
-
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
|
|
18194
|
-
return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
|
|
18195
|
-
}
|
|
18196
|
-
/**
|
|
18197
|
-
* Lists all Webhooks.
|
|
18198
|
-
*/
|
|
18199
|
-
list(params = {}, options) {
|
|
18200
|
-
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
|
|
18201
|
-
return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
|
|
18202
|
-
}
|
|
18203
|
-
/**
|
|
18204
|
-
* Deletes a Webhook.
|
|
18205
|
-
*/
|
|
18206
|
-
delete(id, params = {}, options) {
|
|
18207
|
-
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18208
|
-
return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
|
|
18209
|
-
}
|
|
18210
|
-
/**
|
|
18211
|
-
* Gets a specific Webhook.
|
|
18212
|
-
*/
|
|
18213
|
-
get(id, params = {}, options) {
|
|
18214
|
-
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18215
|
-
return this._client.get(path `/${api_version}/webhooks/${id}`, options);
|
|
18216
|
-
}
|
|
18217
|
-
/**
|
|
18218
|
-
* Sends a ping event to a Webhook.
|
|
18219
|
-
*/
|
|
18220
|
-
ping(id, params = undefined, options) {
|
|
18221
|
-
const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
|
|
18222
|
-
return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
|
|
18223
|
-
}
|
|
18224
|
-
/**
|
|
18225
|
-
* Generates a new signing secret for a Webhook.
|
|
18226
|
-
*/
|
|
18227
|
-
rotateSigningSecret(id, params = {}, options) {
|
|
18228
|
-
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
|
|
18229
|
-
return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
|
|
18230
|
-
}
|
|
18231
|
-
}
|
|
18232
|
-
BaseWebhooks._key = Object.freeze(['webhooks']);
|
|
18233
|
-
class Webhooks extends BaseWebhooks {
|
|
18234
|
-
}
|
|
18235
|
-
|
|
18236
|
-
/**
|
|
18237
|
-
* @license
|
|
18238
|
-
* Copyright 2025 Google LLC
|
|
18239
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
18240
|
-
*/
|
|
18241
|
-
function concatBytes(buffers) {
|
|
18242
|
-
let length = 0;
|
|
18243
|
-
for (const buffer of buffers) {
|
|
18244
|
-
length += buffer.length;
|
|
18245
|
-
}
|
|
18246
|
-
const output = new Uint8Array(length);
|
|
18247
|
-
let index = 0;
|
|
18248
|
-
for (const buffer of buffers) {
|
|
18249
|
-
output.set(buffer, index);
|
|
18250
|
-
index += buffer.length;
|
|
18251
|
-
}
|
|
18252
|
-
return output;
|
|
18253
|
-
}
|
|
18254
|
-
let encodeUTF8_;
|
|
18255
|
-
function encodeUTF8(str) {
|
|
18256
|
-
let encoder;
|
|
18257
|
-
return (encodeUTF8_ !== null && encodeUTF8_ !== void 0 ? encodeUTF8_ : ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
|
|
18258
|
-
}
|
|
18259
|
-
let decodeUTF8_;
|
|
18260
|
-
function decodeUTF8(bytes) {
|
|
18261
|
-
let decoder;
|
|
18262
|
-
return (decodeUTF8_ !== null && decodeUTF8_ !== void 0 ? decodeUTF8_ : ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
|
|
18263
|
-
}
|
|
18264
|
-
|
|
18265
|
-
/**
|
|
18266
|
-
* @license
|
|
18267
|
-
* Copyright 2025 Google LLC
|
|
18268
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
18269
|
-
*/
|
|
18270
|
-
/**
|
|
18271
|
-
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
18272
|
-
* reading lines from text.
|
|
18273
|
-
*
|
|
18274
|
-
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
18275
|
-
*/
|
|
18276
|
-
class LineDecoder {
|
|
18277
|
-
constructor() {
|
|
18278
|
-
this.buffer = new Uint8Array();
|
|
18279
|
-
this.carriageReturnIndex = null;
|
|
18280
|
-
this.searchIndex = 0;
|
|
18281
|
-
}
|
|
18282
|
-
decode(chunk) {
|
|
18283
|
-
var _a;
|
|
18284
|
-
if (chunk == null) {
|
|
18285
|
-
return [];
|
|
18286
|
-
}
|
|
18287
|
-
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
18288
|
-
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
|
18289
|
-
: chunk;
|
|
18290
|
-
this.buffer = concatBytes([this.buffer, binaryChunk]);
|
|
18291
|
-
const lines = [];
|
|
18292
|
-
let patternIndex;
|
|
18293
|
-
while ((patternIndex = findNewlineIndex(this.buffer, (_a = this.carriageReturnIndex) !== null && _a !== void 0 ? _a : this.searchIndex)) != null) {
|
|
18294
|
-
if (patternIndex.carriage && this.carriageReturnIndex == null) {
|
|
18295
|
-
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
|
18296
|
-
this.carriageReturnIndex = patternIndex.index;
|
|
18297
|
-
continue;
|
|
18298
|
-
}
|
|
18299
|
-
// we got double \r or \rtext\n
|
|
18300
|
-
if (this.carriageReturnIndex != null &&
|
|
18301
|
-
(patternIndex.index !== this.carriageReturnIndex + 1 || patternIndex.carriage)) {
|
|
18302
|
-
lines.push(decodeUTF8(this.buffer.subarray(0, this.carriageReturnIndex - 1)));
|
|
18303
|
-
this.buffer = this.buffer.subarray(this.carriageReturnIndex);
|
|
18304
|
-
this.carriageReturnIndex = null;
|
|
18305
|
-
this.searchIndex = 0;
|
|
18306
|
-
continue;
|
|
18307
|
-
}
|
|
18308
|
-
const endIndex = this.carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
|
18309
|
-
const line = decodeUTF8(this.buffer.subarray(0, endIndex));
|
|
18310
|
-
lines.push(line);
|
|
18311
|
-
this.buffer = this.buffer.subarray(patternIndex.index);
|
|
18312
|
-
this.carriageReturnIndex = null;
|
|
18313
|
-
this.searchIndex = 0;
|
|
18314
|
-
}
|
|
18315
|
-
this.searchIndex = Math.max(0, this.buffer.length - 1);
|
|
18316
|
-
return lines;
|
|
18317
|
-
}
|
|
18318
|
-
flush() {
|
|
18319
|
-
if (!this.buffer.length) {
|
|
18320
|
-
return [];
|
|
18321
|
-
}
|
|
18322
|
-
return this.decode('\n');
|
|
18323
|
-
}
|
|
18324
|
-
}
|
|
18325
|
-
// prettier-ignore
|
|
18326
|
-
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
|
|
18327
|
-
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
18328
|
-
/**
|
|
18329
|
-
* This function searches the buffer for the end patterns, (\r or \n)
|
|
18330
|
-
* and returns an object with the index preceding the matched newline and the
|
|
18331
|
-
* index after the newline char. `null` is returned if no new line is found.
|
|
18332
|
-
*
|
|
18333
|
-
* ```ts
|
|
18334
|
-
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
|
18335
|
-
* ```
|
|
18336
|
-
*/
|
|
18337
|
-
function findNewlineIndex(buffer, startIndex) {
|
|
18338
|
-
const newline = 0x0a; // \n
|
|
18339
|
-
const carriage = 0x0d; // \r
|
|
18340
|
-
const start = startIndex !== null && startIndex !== void 0 ? startIndex : 0;
|
|
18341
|
-
const nextNewline = buffer.indexOf(newline, start);
|
|
18342
|
-
const nextCarriage = buffer.indexOf(carriage, start);
|
|
18343
|
-
if (nextNewline === -1 && nextCarriage === -1) {
|
|
18344
|
-
return null;
|
|
18345
|
-
}
|
|
18346
|
-
let i;
|
|
18347
|
-
if (nextNewline !== -1 && nextCarriage !== -1) {
|
|
18348
|
-
i = Math.min(nextNewline, nextCarriage);
|
|
18349
|
-
}
|
|
18350
|
-
else {
|
|
18351
|
-
i = nextNewline !== -1 ? nextNewline : nextCarriage;
|
|
18352
|
-
}
|
|
18353
|
-
if (buffer[i] === newline) {
|
|
18354
|
-
return { preceding: i, index: i + 1, carriage: false };
|
|
18355
|
-
}
|
|
18356
|
-
return { preceding: i, index: i + 1, carriage: true };
|
|
18357
|
-
}
|
|
18035
|
+
function findNewlineIndex(buffer, startIndex) {
|
|
18036
|
+
const newline = 0x0a; // \n
|
|
18037
|
+
const carriage = 0x0d; // \r
|
|
18038
|
+
const start = startIndex !== null && startIndex !== void 0 ? startIndex : 0;
|
|
18039
|
+
const nextNewline = buffer.indexOf(newline, start);
|
|
18040
|
+
const nextCarriage = buffer.indexOf(carriage, start);
|
|
18041
|
+
if (nextNewline === -1 && nextCarriage === -1) {
|
|
18042
|
+
return null;
|
|
18043
|
+
}
|
|
18044
|
+
let i;
|
|
18045
|
+
if (nextNewline !== -1 && nextCarriage !== -1) {
|
|
18046
|
+
i = Math.min(nextNewline, nextCarriage);
|
|
18047
|
+
}
|
|
18048
|
+
else {
|
|
18049
|
+
i = nextNewline !== -1 ? nextNewline : nextCarriage;
|
|
18050
|
+
}
|
|
18051
|
+
if (buffer[i] === newline) {
|
|
18052
|
+
return { preceding: i, index: i + 1, carriage: false };
|
|
18053
|
+
}
|
|
18054
|
+
return { preceding: i, index: i + 1, carriage: true };
|
|
18055
|
+
}
|
|
18358
18056
|
|
|
18359
18057
|
/**
|
|
18360
18058
|
* @license
|
|
@@ -18768,6 +18466,338 @@ function partition(str, delimiter) {
|
|
|
18768
18466
|
return [str, '', ''];
|
|
18769
18467
|
}
|
|
18770
18468
|
|
|
18469
|
+
/**
|
|
18470
|
+
* @license
|
|
18471
|
+
* Copyright 2025 Google LLC
|
|
18472
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18473
|
+
*/
|
|
18474
|
+
const LEGACY_LYRIA_MODELS = new Set([
|
|
18475
|
+
'lyria-3-pro-preview',
|
|
18476
|
+
'lyria-3-clip-preview',
|
|
18477
|
+
]);
|
|
18478
|
+
const LEGACY_EVENT_TYPE_RENAMES = {
|
|
18479
|
+
'interaction.start': 'interaction.created',
|
|
18480
|
+
'content.start': 'step.start',
|
|
18481
|
+
'content.delta': 'step.delta',
|
|
18482
|
+
'content.stop': 'step.stop',
|
|
18483
|
+
'interaction.complete': 'interaction.completed',
|
|
18484
|
+
};
|
|
18485
|
+
function isLegacyLyriaRequest({ isVertex, model }) {
|
|
18486
|
+
return Boolean(isVertex) && typeof model === 'string' && LEGACY_LYRIA_MODELS.has(model);
|
|
18487
|
+
}
|
|
18488
|
+
/**
|
|
18489
|
+
* Detect whether a client is in vertex mode. Reads the `clientAdapter` field
|
|
18490
|
+
* directly because `BaseGeminiNextGenAPIClient` keeps it `private`; centralizing
|
|
18491
|
+
* the runtime cast here avoids leaking it into resource files.
|
|
18492
|
+
*/
|
|
18493
|
+
function isVertexClient(client) {
|
|
18494
|
+
const adapter = client.clientAdapter;
|
|
18495
|
+
return Boolean(adapter && adapter.isVertexAI());
|
|
18496
|
+
}
|
|
18497
|
+
function isPlainObject(value) {
|
|
18498
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18499
|
+
}
|
|
18500
|
+
/**
|
|
18501
|
+
* Wrap a legacy `outputs: Array<Content>` payload into the modern
|
|
18502
|
+
* `steps: [{type: 'model_output', content: outputs}]` shape. Returns the input
|
|
18503
|
+
* unchanged when `steps` already wins or `outputs` is absent.
|
|
18504
|
+
*/
|
|
18505
|
+
function wrapOutputsAsSteps(data) {
|
|
18506
|
+
if (!('outputs' in data) || 'steps' in data) {
|
|
18507
|
+
return data;
|
|
18508
|
+
}
|
|
18509
|
+
const { outputs } = data, rest = __rest(data, ["outputs"]);
|
|
18510
|
+
return Object.assign(Object.assign({}, rest), { steps: [{ type: 'model_output', content: outputs }] });
|
|
18511
|
+
}
|
|
18512
|
+
/**
|
|
18513
|
+
* Non-streaming: rewrite a legacy interaction response so consumers see the
|
|
18514
|
+
* modern `steps` shape.
|
|
18515
|
+
*/
|
|
18516
|
+
function coerceLegacyInteractionResponse(data) {
|
|
18517
|
+
if (!isPlainObject(data))
|
|
18518
|
+
return data;
|
|
18519
|
+
return wrapOutputsAsSteps(data);
|
|
18520
|
+
}
|
|
18521
|
+
/**
|
|
18522
|
+
* Streaming: translate one legacy SSE event to its modern equivalent.
|
|
18523
|
+
*
|
|
18524
|
+
* Returns the input unchanged when the `event_type` is not one of the legacy
|
|
18525
|
+
* ones we know how to map. Two non-trivial cases:
|
|
18526
|
+
* 1. `content.start` carries `content: <Content>` — the modern `step.start`
|
|
18527
|
+
* expects `step: {type: 'model_output', content: [<Content>]}`.
|
|
18528
|
+
* 2. `interaction.start` / `interaction.complete` wrap an `interaction`
|
|
18529
|
+
* object that may itself carry the legacy `outputs` field; recurse.
|
|
18530
|
+
*/
|
|
18531
|
+
function maybeRemapLegacyStreamEvent(data) {
|
|
18532
|
+
if (!isPlainObject(data))
|
|
18533
|
+
return data;
|
|
18534
|
+
const eventType = data['event_type'];
|
|
18535
|
+
if (typeof eventType !== 'string' || !(eventType in LEGACY_EVENT_TYPE_RENAMES)) {
|
|
18536
|
+
return data;
|
|
18537
|
+
}
|
|
18538
|
+
const renamed = Object.assign(Object.assign({}, data), { event_type: LEGACY_EVENT_TYPE_RENAMES[eventType] });
|
|
18539
|
+
if (eventType === 'content.start') {
|
|
18540
|
+
const { content } = renamed, rest = __rest(renamed, ["content"]);
|
|
18541
|
+
let stepContent;
|
|
18542
|
+
if (content == null) {
|
|
18543
|
+
stepContent = [];
|
|
18544
|
+
}
|
|
18545
|
+
else if (Array.isArray(content)) {
|
|
18546
|
+
stepContent = content;
|
|
18547
|
+
}
|
|
18548
|
+
else {
|
|
18549
|
+
stepContent = [content];
|
|
18550
|
+
}
|
|
18551
|
+
return Object.assign(Object.assign({}, rest), { step: { type: 'model_output', content: stepContent } });
|
|
18552
|
+
}
|
|
18553
|
+
if (eventType === 'interaction.start' || eventType === 'interaction.complete') {
|
|
18554
|
+
const inner = renamed['interaction'];
|
|
18555
|
+
if (isPlainObject(inner)) {
|
|
18556
|
+
renamed['interaction'] = wrapOutputsAsSteps(inner);
|
|
18557
|
+
}
|
|
18558
|
+
}
|
|
18559
|
+
return renamed;
|
|
18560
|
+
}
|
|
18561
|
+
/**
|
|
18562
|
+
* Stream subclass that runs each yielded SSE event through
|
|
18563
|
+
* `maybeRemapLegacyStreamEvent` so consumers always see modern event shapes.
|
|
18564
|
+
*
|
|
18565
|
+
* Wired in via the `__streamClass` request option from `resources/interactions.ts`
|
|
18566
|
+
* (read by `src/internal/parse.ts:defaultParseResponse`).
|
|
18567
|
+
*/
|
|
18568
|
+
class LegacyLyriaStream extends Stream {
|
|
18569
|
+
static fromSSEResponse(response, controller, client) {
|
|
18570
|
+
const base = Stream.fromSSEResponse(response, controller, client);
|
|
18571
|
+
function wrappedIterator() {
|
|
18572
|
+
return __asyncGenerator(this, arguments, function* wrappedIterator_1() {
|
|
18573
|
+
var _a, e_1, _b, _c;
|
|
18574
|
+
try {
|
|
18575
|
+
for (var _d = true, base_1 = __asyncValues(base), base_1_1; base_1_1 = yield __await(base_1.next()), _a = base_1_1.done, !_a; _d = true) {
|
|
18576
|
+
_c = base_1_1.value;
|
|
18577
|
+
_d = false;
|
|
18578
|
+
const item = _c;
|
|
18579
|
+
yield yield __await(maybeRemapLegacyStreamEvent(item));
|
|
18580
|
+
}
|
|
18581
|
+
}
|
|
18582
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
18583
|
+
finally {
|
|
18584
|
+
try {
|
|
18585
|
+
if (!_d && !_a && (_b = base_1.return)) yield __await(_b.call(base_1));
|
|
18586
|
+
}
|
|
18587
|
+
finally { if (e_1) throw e_1.error; }
|
|
18588
|
+
}
|
|
18589
|
+
});
|
|
18590
|
+
}
|
|
18591
|
+
return new LegacyLyriaStream(wrappedIterator, controller, client);
|
|
18592
|
+
}
|
|
18593
|
+
}
|
|
18594
|
+
|
|
18595
|
+
/**
|
|
18596
|
+
* @license
|
|
18597
|
+
* Copyright 2025 Google LLC
|
|
18598
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18599
|
+
*/
|
|
18600
|
+
/**
|
|
18601
|
+
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
18602
|
+
*
|
|
18603
|
+
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
|
18604
|
+
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
18605
|
+
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
18606
|
+
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
18607
|
+
*/
|
|
18608
|
+
function encodeURIPath(str) {
|
|
18609
|
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
18610
|
+
}
|
|
18611
|
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
18612
|
+
const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
|
|
18613
|
+
// If there are no params, no processing is needed.
|
|
18614
|
+
if (statics.length === 1)
|
|
18615
|
+
return statics[0];
|
|
18616
|
+
let postPath = false;
|
|
18617
|
+
const invalidSegments = [];
|
|
18618
|
+
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
18619
|
+
var _a, _b, _c;
|
|
18620
|
+
if (/[?#]/.test(currentValue)) {
|
|
18621
|
+
postPath = true;
|
|
18622
|
+
}
|
|
18623
|
+
const value = params[index];
|
|
18624
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
18625
|
+
if (index !== params.length &&
|
|
18626
|
+
(value == null ||
|
|
18627
|
+
(typeof value === 'object' &&
|
|
18628
|
+
// handle values from other realms
|
|
18629
|
+
value.toString ===
|
|
18630
|
+
((_c = Object.getPrototypeOf((_b = Object.getPrototypeOf((_a = value.hasOwnProperty) !== null && _a !== void 0 ? _a : EMPTY)) !== null && _b !== void 0 ? _b : EMPTY)) === null || _c === void 0 ? void 0 : _c.toString)))) {
|
|
18631
|
+
encoded = value + '';
|
|
18632
|
+
invalidSegments.push({
|
|
18633
|
+
start: previousValue.length + currentValue.length,
|
|
18634
|
+
length: encoded.length,
|
|
18635
|
+
error: `Value of type ${Object.prototype.toString
|
|
18636
|
+
.call(value)
|
|
18637
|
+
.slice(8, -1)} is not a valid path parameter`,
|
|
18638
|
+
});
|
|
18639
|
+
}
|
|
18640
|
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
18641
|
+
}, '');
|
|
18642
|
+
const pathOnly = path.split(/[?#]/, 1)[0];
|
|
18643
|
+
const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
18644
|
+
let match;
|
|
18645
|
+
// Find all invalid segments
|
|
18646
|
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
18647
|
+
const hasLeadingSlash = match[0].startsWith('/');
|
|
18648
|
+
const offset = hasLeadingSlash ? 1 : 0;
|
|
18649
|
+
const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
|
|
18650
|
+
invalidSegments.push({
|
|
18651
|
+
start: match.index + offset,
|
|
18652
|
+
length: cleanMatch.length,
|
|
18653
|
+
error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
|
|
18654
|
+
});
|
|
18655
|
+
}
|
|
18656
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
18657
|
+
if (invalidSegments.length > 0) {
|
|
18658
|
+
let lastEnd = 0;
|
|
18659
|
+
const underline = invalidSegments.reduce((acc, segment) => {
|
|
18660
|
+
const spaces = ' '.repeat(segment.start - lastEnd);
|
|
18661
|
+
const arrows = '^'.repeat(segment.length);
|
|
18662
|
+
lastEnd = segment.start + segment.length;
|
|
18663
|
+
return acc + spaces + arrows;
|
|
18664
|
+
}, '');
|
|
18665
|
+
throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
18666
|
+
.map((e) => e.error)
|
|
18667
|
+
.join('\n')}\n${path}\n${underline}`);
|
|
18668
|
+
}
|
|
18669
|
+
return path;
|
|
18670
|
+
});
|
|
18671
|
+
/**
|
|
18672
|
+
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
|
18673
|
+
*/
|
|
18674
|
+
const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
18675
|
+
|
|
18676
|
+
/**
|
|
18677
|
+
* @license
|
|
18678
|
+
* Copyright 2025 Google LLC
|
|
18679
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18680
|
+
*/
|
|
18681
|
+
class BaseInteractions extends APIResource {
|
|
18682
|
+
create(params, options) {
|
|
18683
|
+
var _a;
|
|
18684
|
+
const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
|
|
18685
|
+
if ('model' in body && 'agent_config' in body) {
|
|
18686
|
+
throw new GeminiNextGenAPIClientError(`Invalid request: specified \`model\` and \`agent_config\`. If specifying \`model\`, use \`generation_config\`.`);
|
|
18687
|
+
}
|
|
18688
|
+
if ('agent' in body && 'generation_config' in body) {
|
|
18689
|
+
throw new GeminiNextGenAPIClientError(`Invalid request: specified \`agent\` and \`generation_config\`. If specifying \`agent\`, use \`agent_config\`.`);
|
|
18690
|
+
}
|
|
18691
|
+
const needsLegacyLyriaShim = isLegacyLyriaRequest({
|
|
18692
|
+
isVertex: isVertexClient(this._client),
|
|
18693
|
+
model: 'model' in body ? body.model : undefined,
|
|
18694
|
+
});
|
|
18695
|
+
const isStreaming = (_a = params.stream) !== null && _a !== void 0 ? _a : false;
|
|
18696
|
+
const promise = this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign(Object.assign({ body }, options), { stream: isStreaming }), (needsLegacyLyriaShim && isStreaming ? { __streamClass: LegacyLyriaStream } : {})));
|
|
18697
|
+
if (needsLegacyLyriaShim && !isStreaming) {
|
|
18698
|
+
return promise._thenUnwrap((data) => coerceLegacyInteractionResponse(data));
|
|
18699
|
+
}
|
|
18700
|
+
return promise;
|
|
18701
|
+
}
|
|
18702
|
+
/**
|
|
18703
|
+
* Deletes the interaction by id.
|
|
18704
|
+
*
|
|
18705
|
+
* @example
|
|
18706
|
+
* ```ts
|
|
18707
|
+
* const interaction = await client.interactions.delete('id', {
|
|
18708
|
+
* api_version: 'api_version',
|
|
18709
|
+
* });
|
|
18710
|
+
* ```
|
|
18711
|
+
*/
|
|
18712
|
+
delete(id, params = {}, options) {
|
|
18713
|
+
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18714
|
+
return this._client.delete(path `/${api_version}/interactions/${id}`, options);
|
|
18715
|
+
}
|
|
18716
|
+
/**
|
|
18717
|
+
* Cancels an interaction by id. This only applies to background interactions that
|
|
18718
|
+
* are still running.
|
|
18719
|
+
*
|
|
18720
|
+
* @example
|
|
18721
|
+
* ```ts
|
|
18722
|
+
* const interaction = await client.interactions.cancel('id', {
|
|
18723
|
+
* api_version: 'api_version',
|
|
18724
|
+
* });
|
|
18725
|
+
* ```
|
|
18726
|
+
*/
|
|
18727
|
+
cancel(id, params = {}, options) {
|
|
18728
|
+
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18729
|
+
return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
|
|
18730
|
+
}
|
|
18731
|
+
get(id, params = {}, options) {
|
|
18732
|
+
var _a;
|
|
18733
|
+
const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
|
|
18734
|
+
return 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 }));
|
|
18735
|
+
}
|
|
18736
|
+
}
|
|
18737
|
+
BaseInteractions._key = Object.freeze(['interactions']);
|
|
18738
|
+
class Interactions extends BaseInteractions {
|
|
18739
|
+
}
|
|
18740
|
+
|
|
18741
|
+
/**
|
|
18742
|
+
* @license
|
|
18743
|
+
* Copyright 2025 Google LLC
|
|
18744
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18745
|
+
*/
|
|
18746
|
+
class BaseWebhooks extends APIResource {
|
|
18747
|
+
/**
|
|
18748
|
+
* Creates a new Webhook.
|
|
18749
|
+
*/
|
|
18750
|
+
create(params, options) {
|
|
18751
|
+
const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
|
|
18752
|
+
return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
|
|
18753
|
+
}
|
|
18754
|
+
/**
|
|
18755
|
+
* Updates an existing Webhook.
|
|
18756
|
+
*/
|
|
18757
|
+
update(id, params = {}, options) {
|
|
18758
|
+
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
|
|
18759
|
+
return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
|
|
18760
|
+
}
|
|
18761
|
+
/**
|
|
18762
|
+
* Lists all Webhooks.
|
|
18763
|
+
*/
|
|
18764
|
+
list(params = {}, options) {
|
|
18765
|
+
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
|
|
18766
|
+
return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
|
|
18767
|
+
}
|
|
18768
|
+
/**
|
|
18769
|
+
* Deletes a Webhook.
|
|
18770
|
+
*/
|
|
18771
|
+
delete(id, params = {}, options) {
|
|
18772
|
+
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18773
|
+
return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
|
|
18774
|
+
}
|
|
18775
|
+
/**
|
|
18776
|
+
* Gets a specific Webhook.
|
|
18777
|
+
*/
|
|
18778
|
+
get(id, params = {}, options) {
|
|
18779
|
+
const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
|
|
18780
|
+
return this._client.get(path `/${api_version}/webhooks/${id}`, options);
|
|
18781
|
+
}
|
|
18782
|
+
/**
|
|
18783
|
+
* Sends a ping event to a Webhook.
|
|
18784
|
+
*/
|
|
18785
|
+
ping(id, params = undefined, options) {
|
|
18786
|
+
const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
|
|
18787
|
+
return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
|
|
18788
|
+
}
|
|
18789
|
+
/**
|
|
18790
|
+
* Generates a new signing secret for a Webhook.
|
|
18791
|
+
*/
|
|
18792
|
+
rotateSigningSecret(id, params = {}, options) {
|
|
18793
|
+
const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
|
|
18794
|
+
return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
|
|
18795
|
+
}
|
|
18796
|
+
}
|
|
18797
|
+
BaseWebhooks._key = Object.freeze(['webhooks']);
|
|
18798
|
+
class Webhooks extends BaseWebhooks {
|
|
18799
|
+
}
|
|
18800
|
+
|
|
18771
18801
|
/**
|
|
18772
18802
|
* @license
|
|
18773
18803
|
* Copyright 2025 Google LLC
|