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