@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.
@@ -818,11 +818,11 @@ exports.PhishBlockThreshold = void 0;
818
818
  */
819
819
  PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
820
820
  })(exports.PhishBlockThreshold || (exports.PhishBlockThreshold = {}));
821
- /** Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This enum is not supported in Vertex AI. */
821
+ /** 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. */
822
822
  exports.Behavior = void 0;
823
823
  (function (Behavior) {
824
824
  /**
825
- * This value is unused.
825
+ * This value is unspecified.
826
826
  */
827
827
  Behavior["UNSPECIFIED"] = "UNSPECIFIED";
828
828
  /**
@@ -6110,41 +6110,6 @@ function functionCallingConfigToMldev$1(fromObject) {
6110
6110
  }
6111
6111
  return toObject;
6112
6112
  }
6113
- function functionDeclarationToVertex$2(fromObject) {
6114
- const toObject = {};
6115
- const fromDescription = getValueByPath(fromObject, ['description']);
6116
- if (fromDescription != null) {
6117
- setValueByPath(toObject, ['description'], fromDescription);
6118
- }
6119
- const fromName = getValueByPath(fromObject, ['name']);
6120
- if (fromName != null) {
6121
- setValueByPath(toObject, ['name'], fromName);
6122
- }
6123
- const fromParameters = getValueByPath(fromObject, ['parameters']);
6124
- if (fromParameters != null) {
6125
- setValueByPath(toObject, ['parameters'], fromParameters);
6126
- }
6127
- const fromParametersJsonSchema = getValueByPath(fromObject, [
6128
- 'parametersJsonSchema',
6129
- ]);
6130
- if (fromParametersJsonSchema != null) {
6131
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
6132
- }
6133
- const fromResponse = getValueByPath(fromObject, ['response']);
6134
- if (fromResponse != null) {
6135
- setValueByPath(toObject, ['response'], fromResponse);
6136
- }
6137
- const fromResponseJsonSchema = getValueByPath(fromObject, [
6138
- 'responseJsonSchema',
6139
- ]);
6140
- if (fromResponseJsonSchema != null) {
6141
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
6142
- }
6143
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
6144
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
6145
- }
6146
- return toObject;
6147
- }
6148
6113
  function getCachedContentParametersToMldev(apiClient, fromObject) {
6149
6114
  const toObject = {};
6150
6115
  const fromName = getValueByPath(fromObject, ['name']);
@@ -6577,7 +6542,7 @@ function toolToVertex$2(fromObject) {
6577
6542
  let transformedList = fromFunctionDeclarations;
6578
6543
  if (Array.isArray(transformedList)) {
6579
6544
  transformedList = transformedList.map((item) => {
6580
- return functionDeclarationToVertex$2(item);
6545
+ return item;
6581
6546
  });
6582
6547
  }
6583
6548
  setValueByPath(toObject, ['functionDeclarations'], transformedList);
@@ -8010,41 +7975,6 @@ function functionCallToMldev$2(fromObject) {
8010
7975
  }
8011
7976
  return toObject;
8012
7977
  }
8013
- function functionDeclarationToVertex$1(fromObject) {
8014
- const toObject = {};
8015
- const fromDescription = getValueByPath(fromObject, ['description']);
8016
- if (fromDescription != null) {
8017
- setValueByPath(toObject, ['description'], fromDescription);
8018
- }
8019
- const fromName = getValueByPath(fromObject, ['name']);
8020
- if (fromName != null) {
8021
- setValueByPath(toObject, ['name'], fromName);
8022
- }
8023
- const fromParameters = getValueByPath(fromObject, ['parameters']);
8024
- if (fromParameters != null) {
8025
- setValueByPath(toObject, ['parameters'], fromParameters);
8026
- }
8027
- const fromParametersJsonSchema = getValueByPath(fromObject, [
8028
- 'parametersJsonSchema',
8029
- ]);
8030
- if (fromParametersJsonSchema != null) {
8031
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
8032
- }
8033
- const fromResponse = getValueByPath(fromObject, ['response']);
8034
- if (fromResponse != null) {
8035
- setValueByPath(toObject, ['response'], fromResponse);
8036
- }
8037
- const fromResponseJsonSchema = getValueByPath(fromObject, [
8038
- 'responseJsonSchema',
8039
- ]);
8040
- if (fromResponseJsonSchema != null) {
8041
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
8042
- }
8043
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
8044
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
8045
- }
8046
- return toObject;
8047
- }
8048
7978
  function generationConfigToVertex$1(fromObject) {
8049
7979
  const toObject = {};
8050
7980
  const fromModelSelectionConfig = getValueByPath(fromObject, [
@@ -8928,7 +8858,7 @@ function toolToVertex$1(fromObject) {
8928
8858
  let transformedList = fromFunctionDeclarations;
8929
8859
  if (Array.isArray(transformedList)) {
8930
8860
  transformedList = transformedList.map((item) => {
8931
- return functionDeclarationToVertex$1(item);
8861
+ return item;
8932
8862
  });
8933
8863
  }
8934
8864
  setValueByPath(toObject, ['functionDeclarations'], transformedList);
@@ -9943,41 +9873,6 @@ function functionCallingConfigToMldev(fromObject, _rootObject) {
9943
9873
  }
9944
9874
  return toObject;
9945
9875
  }
9946
- function functionDeclarationToVertex(fromObject, _rootObject) {
9947
- const toObject = {};
9948
- const fromDescription = getValueByPath(fromObject, ['description']);
9949
- if (fromDescription != null) {
9950
- setValueByPath(toObject, ['description'], fromDescription);
9951
- }
9952
- const fromName = getValueByPath(fromObject, ['name']);
9953
- if (fromName != null) {
9954
- setValueByPath(toObject, ['name'], fromName);
9955
- }
9956
- const fromParameters = getValueByPath(fromObject, ['parameters']);
9957
- if (fromParameters != null) {
9958
- setValueByPath(toObject, ['parameters'], fromParameters);
9959
- }
9960
- const fromParametersJsonSchema = getValueByPath(fromObject, [
9961
- 'parametersJsonSchema',
9962
- ]);
9963
- if (fromParametersJsonSchema != null) {
9964
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
9965
- }
9966
- const fromResponse = getValueByPath(fromObject, ['response']);
9967
- if (fromResponse != null) {
9968
- setValueByPath(toObject, ['response'], fromResponse);
9969
- }
9970
- const fromResponseJsonSchema = getValueByPath(fromObject, [
9971
- 'responseJsonSchema',
9972
- ]);
9973
- if (fromResponseJsonSchema != null) {
9974
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
9975
- }
9976
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
9977
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
9978
- }
9979
- return toObject;
9980
- }
9981
9876
  function generateContentConfigToMldev(apiClient, fromObject, parentObject, rootObject) {
9982
9877
  const toObject = {};
9983
9878
  const fromSystemInstruction = getValueByPath(fromObject, [
@@ -12294,7 +12189,7 @@ function toolToMldev$1(fromObject, rootObject) {
12294
12189
  }
12295
12190
  return toObject;
12296
12191
  }
12297
- function toolToVertex(fromObject, rootObject) {
12192
+ function toolToVertex(fromObject, _rootObject) {
12298
12193
  const toObject = {};
12299
12194
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
12300
12195
  if (fromRetrieval != null) {
@@ -12334,7 +12229,7 @@ function toolToVertex(fromObject, rootObject) {
12334
12229
  let transformedList = fromFunctionDeclarations;
12335
12230
  if (Array.isArray(transformedList)) {
12336
12231
  transformedList = transformedList.map((item) => {
12337
- return functionDeclarationToVertex(item);
12232
+ return item;
12338
12233
  });
12339
12234
  }
12340
12235
  setValueByPath(toObject, ['functionDeclarations'], transformedList);
@@ -12919,7 +12814,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
12919
12814
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
12920
12815
  const USER_AGENT_HEADER = 'User-Agent';
12921
12816
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
12922
- const SDK_VERSION = '2.0.0'; // x-release-please-version
12817
+ const SDK_VERSION = '2.1.0'; // x-release-please-version
12923
12818
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
12924
12819
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
12925
12820
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -18066,325 +17961,128 @@ class APIResource {
18066
17961
  */
18067
17962
  APIResource._key = [];
18068
17963
 
17964
+ /**
17965
+ * @license
17966
+ * Copyright 2025 Google LLC
17967
+ * SPDX-License-Identifier: Apache-2.0
17968
+ */
17969
+ function concatBytes(buffers) {
17970
+ let length = 0;
17971
+ for (const buffer of buffers) {
17972
+ length += buffer.length;
17973
+ }
17974
+ const output = new Uint8Array(length);
17975
+ let index = 0;
17976
+ for (const buffer of buffers) {
17977
+ output.set(buffer, index);
17978
+ index += buffer.length;
17979
+ }
17980
+ return output;
17981
+ }
17982
+ let encodeUTF8_;
17983
+ function encodeUTF8(str) {
17984
+ let encoder;
17985
+ return (encodeUTF8_ !== null && encodeUTF8_ !== void 0 ? encodeUTF8_ : ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
17986
+ }
17987
+ let decodeUTF8_;
17988
+ function decodeUTF8(bytes) {
17989
+ let decoder;
17990
+ return (decodeUTF8_ !== null && decodeUTF8_ !== void 0 ? decodeUTF8_ : ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
17991
+ }
17992
+
18069
17993
  /**
18070
17994
  * @license
18071
17995
  * Copyright 2025 Google LLC
18072
17996
  * SPDX-License-Identifier: Apache-2.0
18073
17997
  */
18074
17998
  /**
18075
- * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
17999
+ * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
18000
+ * reading lines from text.
18076
18001
  *
18077
- * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
18078
- * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
18079
- * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
18080
- * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
18002
+ * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
18081
18003
  */
18082
- function encodeURIPath(str) {
18083
- return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
18084
- }
18085
- const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
18086
- const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
18087
- // If there are no params, no processing is needed.
18088
- if (statics.length === 1)
18089
- return statics[0];
18090
- let postPath = false;
18091
- const invalidSegments = [];
18092
- const path = statics.reduce((previousValue, currentValue, index) => {
18093
- var _a, _b, _c;
18094
- if (/[?#]/.test(currentValue)) {
18095
- postPath = true;
18004
+ class LineDecoder {
18005
+ constructor() {
18006
+ this.buffer = new Uint8Array();
18007
+ this.carriageReturnIndex = null;
18008
+ this.searchIndex = 0;
18009
+ }
18010
+ decode(chunk) {
18011
+ var _a;
18012
+ if (chunk == null) {
18013
+ return [];
18096
18014
  }
18097
- const value = params[index];
18098
- let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18099
- if (index !== params.length &&
18100
- (value == null ||
18101
- (typeof value === 'object' &&
18102
- // handle values from other realms
18103
- value.toString ===
18104
- ((_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)))) {
18105
- encoded = value + '';
18106
- invalidSegments.push({
18107
- start: previousValue.length + currentValue.length,
18108
- length: encoded.length,
18109
- error: `Value of type ${Object.prototype.toString
18110
- .call(value)
18111
- .slice(8, -1)} is not a valid path parameter`,
18112
- });
18015
+ const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
18016
+ : typeof chunk === 'string' ? encodeUTF8(chunk)
18017
+ : chunk;
18018
+ this.buffer = concatBytes([this.buffer, binaryChunk]);
18019
+ const lines = [];
18020
+ let patternIndex;
18021
+ while ((patternIndex = findNewlineIndex(this.buffer, (_a = this.carriageReturnIndex) !== null && _a !== void 0 ? _a : this.searchIndex)) != null) {
18022
+ if (patternIndex.carriage && this.carriageReturnIndex == null) {
18023
+ // skip until we either get a corresponding `\n`, a new `\r` or nothing
18024
+ this.carriageReturnIndex = patternIndex.index;
18025
+ continue;
18026
+ }
18027
+ // we got double \r or \rtext\n
18028
+ if (this.carriageReturnIndex != null &&
18029
+ (patternIndex.index !== this.carriageReturnIndex + 1 || patternIndex.carriage)) {
18030
+ lines.push(decodeUTF8(this.buffer.subarray(0, this.carriageReturnIndex - 1)));
18031
+ this.buffer = this.buffer.subarray(this.carriageReturnIndex);
18032
+ this.carriageReturnIndex = null;
18033
+ this.searchIndex = 0;
18034
+ continue;
18035
+ }
18036
+ const endIndex = this.carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
18037
+ const line = decodeUTF8(this.buffer.subarray(0, endIndex));
18038
+ lines.push(line);
18039
+ this.buffer = this.buffer.subarray(patternIndex.index);
18040
+ this.carriageReturnIndex = null;
18041
+ this.searchIndex = 0;
18113
18042
  }
18114
- return previousValue + currentValue + (index === params.length ? '' : encoded);
18115
- }, '');
18116
- const pathOnly = path.split(/[?#]/, 1)[0];
18117
- const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18118
- let match;
18119
- // Find all invalid segments
18120
- while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18121
- const hasLeadingSlash = match[0].startsWith('/');
18122
- const offset = hasLeadingSlash ? 1 : 0;
18123
- const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18124
- invalidSegments.push({
18125
- start: match.index + offset,
18126
- length: cleanMatch.length,
18127
- error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18128
- });
18043
+ this.searchIndex = Math.max(0, this.buffer.length - 1);
18044
+ return lines;
18129
18045
  }
18130
- invalidSegments.sort((a, b) => a.start - b.start);
18131
- if (invalidSegments.length > 0) {
18132
- let lastEnd = 0;
18133
- const underline = invalidSegments.reduce((acc, segment) => {
18134
- const spaces = ' '.repeat(segment.start - lastEnd);
18135
- const arrows = '^'.repeat(segment.length);
18136
- lastEnd = segment.start + segment.length;
18137
- return acc + spaces + arrows;
18138
- }, '');
18139
- throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18140
- .map((e) => e.error)
18141
- .join('\n')}\n${path}\n${underline}`);
18046
+ flush() {
18047
+ if (!this.buffer.length) {
18048
+ return [];
18049
+ }
18050
+ return this.decode('\n');
18142
18051
  }
18143
- return path;
18144
- });
18052
+ }
18053
+ // prettier-ignore
18054
+ LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
18055
+ LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
18145
18056
  /**
18146
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18057
+ * This function searches the buffer for the end patterns, (\r or \n)
18058
+ * and returns an object with the index preceding the matched newline and the
18059
+ * index after the newline char. `null` is returned if no new line is found.
18060
+ *
18061
+ * ```ts
18062
+ * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
18063
+ * ```
18147
18064
  */
18148
- const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18149
-
18150
- /**
18151
- * @license
18152
- * Copyright 2025 Google LLC
18153
- * SPDX-License-Identifier: Apache-2.0
18154
- */
18155
- class BaseInteractions extends APIResource {
18156
- create(params, options) {
18157
- var _a;
18158
- const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
18159
- if ('model' in body && 'agent_config' in body) {
18160
- throw new GeminiNextGenAPIClientError(`Invalid request: specified \`model\` and \`agent_config\`. If specifying \`model\`, use \`generation_config\`.`);
18161
- }
18162
- if ('agent' in body && 'generation_config' in body) {
18163
- throw new GeminiNextGenAPIClientError(`Invalid request: specified \`agent\` and \`generation_config\`. If specifying \`agent\`, use \`agent_config\`.`);
18164
- }
18165
- return this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign({ body }, options), { stream: (_a = params.stream) !== null && _a !== void 0 ? _a : false }));
18166
- }
18167
- /**
18168
- * Deletes the interaction by id.
18169
- *
18170
- * @example
18171
- * ```ts
18172
- * const interaction = await client.interactions.delete('id', {
18173
- * api_version: 'api_version',
18174
- * });
18175
- * ```
18176
- */
18177
- delete(id, params = {}, options) {
18178
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18179
- return this._client.delete(path `/${api_version}/interactions/${id}`, options);
18180
- }
18181
- /**
18182
- * Cancels an interaction by id. This only applies to background interactions that
18183
- * are still running.
18184
- *
18185
- * @example
18186
- * ```ts
18187
- * const interaction = await client.interactions.cancel('id', {
18188
- * api_version: 'api_version',
18189
- * });
18190
- * ```
18191
- */
18192
- cancel(id, params = {}, options) {
18193
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18194
- return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
18195
- }
18196
- get(id, params = {}, options) {
18197
- var _a;
18198
- const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
18199
- 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 }));
18200
- }
18201
- }
18202
- BaseInteractions._key = Object.freeze(['interactions']);
18203
- class Interactions extends BaseInteractions {
18204
- }
18205
-
18206
- /**
18207
- * @license
18208
- * Copyright 2025 Google LLC
18209
- * SPDX-License-Identifier: Apache-2.0
18210
- */
18211
- class BaseWebhooks extends APIResource {
18212
- /**
18213
- * Creates a new Webhook.
18214
- */
18215
- create(params, options) {
18216
- const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
18217
- return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
18218
- }
18219
- /**
18220
- * Updates an existing Webhook.
18221
- */
18222
- update(id, params = {}, options) {
18223
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
18224
- return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
18225
- }
18226
- /**
18227
- * Lists all Webhooks.
18228
- */
18229
- list(params = {}, options) {
18230
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
18231
- return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
18232
- }
18233
- /**
18234
- * Deletes a Webhook.
18235
- */
18236
- delete(id, params = {}, options) {
18237
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18238
- return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
18239
- }
18240
- /**
18241
- * Gets a specific Webhook.
18242
- */
18243
- get(id, params = {}, options) {
18244
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18245
- return this._client.get(path `/${api_version}/webhooks/${id}`, options);
18246
- }
18247
- /**
18248
- * Sends a ping event to a Webhook.
18249
- */
18250
- ping(id, params = undefined, options) {
18251
- const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
18252
- return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
18253
- }
18254
- /**
18255
- * Generates a new signing secret for a Webhook.
18256
- */
18257
- rotateSigningSecret(id, params = {}, options) {
18258
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
18259
- return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
18260
- }
18261
- }
18262
- BaseWebhooks._key = Object.freeze(['webhooks']);
18263
- class Webhooks extends BaseWebhooks {
18264
- }
18265
-
18266
- /**
18267
- * @license
18268
- * Copyright 2025 Google LLC
18269
- * SPDX-License-Identifier: Apache-2.0
18270
- */
18271
- function concatBytes(buffers) {
18272
- let length = 0;
18273
- for (const buffer of buffers) {
18274
- length += buffer.length;
18275
- }
18276
- const output = new Uint8Array(length);
18277
- let index = 0;
18278
- for (const buffer of buffers) {
18279
- output.set(buffer, index);
18280
- index += buffer.length;
18281
- }
18282
- return output;
18283
- }
18284
- let encodeUTF8_;
18285
- function encodeUTF8(str) {
18286
- let encoder;
18287
- return (encodeUTF8_ !== null && encodeUTF8_ !== void 0 ? encodeUTF8_ : ((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
18288
- }
18289
- let decodeUTF8_;
18290
- function decodeUTF8(bytes) {
18291
- let decoder;
18292
- return (decodeUTF8_ !== null && decodeUTF8_ !== void 0 ? decodeUTF8_ : ((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
18293
- }
18294
-
18295
- /**
18296
- * @license
18297
- * Copyright 2025 Google LLC
18298
- * SPDX-License-Identifier: Apache-2.0
18299
- */
18300
- /**
18301
- * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
18302
- * reading lines from text.
18303
- *
18304
- * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
18305
- */
18306
- class LineDecoder {
18307
- constructor() {
18308
- this.buffer = new Uint8Array();
18309
- this.carriageReturnIndex = null;
18310
- this.searchIndex = 0;
18311
- }
18312
- decode(chunk) {
18313
- var _a;
18314
- if (chunk == null) {
18315
- return [];
18316
- }
18317
- const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
18318
- : typeof chunk === 'string' ? encodeUTF8(chunk)
18319
- : chunk;
18320
- this.buffer = concatBytes([this.buffer, binaryChunk]);
18321
- const lines = [];
18322
- let patternIndex;
18323
- while ((patternIndex = findNewlineIndex(this.buffer, (_a = this.carriageReturnIndex) !== null && _a !== void 0 ? _a : this.searchIndex)) != null) {
18324
- if (patternIndex.carriage && this.carriageReturnIndex == null) {
18325
- // skip until we either get a corresponding `\n`, a new `\r` or nothing
18326
- this.carriageReturnIndex = patternIndex.index;
18327
- continue;
18328
- }
18329
- // we got double \r or \rtext\n
18330
- if (this.carriageReturnIndex != null &&
18331
- (patternIndex.index !== this.carriageReturnIndex + 1 || patternIndex.carriage)) {
18332
- lines.push(decodeUTF8(this.buffer.subarray(0, this.carriageReturnIndex - 1)));
18333
- this.buffer = this.buffer.subarray(this.carriageReturnIndex);
18334
- this.carriageReturnIndex = null;
18335
- this.searchIndex = 0;
18336
- continue;
18337
- }
18338
- const endIndex = this.carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
18339
- const line = decodeUTF8(this.buffer.subarray(0, endIndex));
18340
- lines.push(line);
18341
- this.buffer = this.buffer.subarray(patternIndex.index);
18342
- this.carriageReturnIndex = null;
18343
- this.searchIndex = 0;
18344
- }
18345
- this.searchIndex = Math.max(0, this.buffer.length - 1);
18346
- return lines;
18347
- }
18348
- flush() {
18349
- if (!this.buffer.length) {
18350
- return [];
18351
- }
18352
- return this.decode('\n');
18353
- }
18354
- }
18355
- // prettier-ignore
18356
- LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
18357
- LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
18358
- /**
18359
- * This function searches the buffer for the end patterns, (\r or \n)
18360
- * and returns an object with the index preceding the matched newline and the
18361
- * index after the newline char. `null` is returned if no new line is found.
18362
- *
18363
- * ```ts
18364
- * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
18365
- * ```
18366
- */
18367
- function findNewlineIndex(buffer, startIndex) {
18368
- const newline = 0x0a; // \n
18369
- const carriage = 0x0d; // \r
18370
- const start = startIndex !== null && startIndex !== void 0 ? startIndex : 0;
18371
- const nextNewline = buffer.indexOf(newline, start);
18372
- const nextCarriage = buffer.indexOf(carriage, start);
18373
- if (nextNewline === -1 && nextCarriage === -1) {
18374
- return null;
18375
- }
18376
- let i;
18377
- if (nextNewline !== -1 && nextCarriage !== -1) {
18378
- i = Math.min(nextNewline, nextCarriage);
18379
- }
18380
- else {
18381
- i = nextNewline !== -1 ? nextNewline : nextCarriage;
18382
- }
18383
- if (buffer[i] === newline) {
18384
- return { preceding: i, index: i + 1, carriage: false };
18385
- }
18386
- return { preceding: i, index: i + 1, carriage: true };
18387
- }
18065
+ function findNewlineIndex(buffer, startIndex) {
18066
+ const newline = 0x0a; // \n
18067
+ const carriage = 0x0d; // \r
18068
+ const start = startIndex !== null && startIndex !== void 0 ? startIndex : 0;
18069
+ const nextNewline = buffer.indexOf(newline, start);
18070
+ const nextCarriage = buffer.indexOf(carriage, start);
18071
+ if (nextNewline === -1 && nextCarriage === -1) {
18072
+ return null;
18073
+ }
18074
+ let i;
18075
+ if (nextNewline !== -1 && nextCarriage !== -1) {
18076
+ i = Math.min(nextNewline, nextCarriage);
18077
+ }
18078
+ else {
18079
+ i = nextNewline !== -1 ? nextNewline : nextCarriage;
18080
+ }
18081
+ if (buffer[i] === newline) {
18082
+ return { preceding: i, index: i + 1, carriage: false };
18083
+ }
18084
+ return { preceding: i, index: i + 1, carriage: true };
18085
+ }
18388
18086
 
18389
18087
  /**
18390
18088
  * @license
@@ -18798,6 +18496,338 @@ function partition(str, delimiter) {
18798
18496
  return [str, '', ''];
18799
18497
  }
18800
18498
 
18499
+ /**
18500
+ * @license
18501
+ * Copyright 2025 Google LLC
18502
+ * SPDX-License-Identifier: Apache-2.0
18503
+ */
18504
+ const LEGACY_LYRIA_MODELS = new Set([
18505
+ 'lyria-3-pro-preview',
18506
+ 'lyria-3-clip-preview',
18507
+ ]);
18508
+ const LEGACY_EVENT_TYPE_RENAMES = {
18509
+ 'interaction.start': 'interaction.created',
18510
+ 'content.start': 'step.start',
18511
+ 'content.delta': 'step.delta',
18512
+ 'content.stop': 'step.stop',
18513
+ 'interaction.complete': 'interaction.completed',
18514
+ };
18515
+ function isLegacyLyriaRequest({ isVertex, model }) {
18516
+ return Boolean(isVertex) && typeof model === 'string' && LEGACY_LYRIA_MODELS.has(model);
18517
+ }
18518
+ /**
18519
+ * Detect whether a client is in vertex mode. Reads the `clientAdapter` field
18520
+ * directly because `BaseGeminiNextGenAPIClient` keeps it `private`; centralizing
18521
+ * the runtime cast here avoids leaking it into resource files.
18522
+ */
18523
+ function isVertexClient(client) {
18524
+ const adapter = client.clientAdapter;
18525
+ return Boolean(adapter && adapter.isVertexAI());
18526
+ }
18527
+ function isPlainObject(value) {
18528
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
18529
+ }
18530
+ /**
18531
+ * Wrap a legacy `outputs: Array<Content>` payload into the modern
18532
+ * `steps: [{type: 'model_output', content: outputs}]` shape. Returns the input
18533
+ * unchanged when `steps` already wins or `outputs` is absent.
18534
+ */
18535
+ function wrapOutputsAsSteps(data) {
18536
+ if (!('outputs' in data) || 'steps' in data) {
18537
+ return data;
18538
+ }
18539
+ const { outputs } = data, rest = __rest(data, ["outputs"]);
18540
+ return Object.assign(Object.assign({}, rest), { steps: [{ type: 'model_output', content: outputs }] });
18541
+ }
18542
+ /**
18543
+ * Non-streaming: rewrite a legacy interaction response so consumers see the
18544
+ * modern `steps` shape.
18545
+ */
18546
+ function coerceLegacyInteractionResponse(data) {
18547
+ if (!isPlainObject(data))
18548
+ return data;
18549
+ return wrapOutputsAsSteps(data);
18550
+ }
18551
+ /**
18552
+ * Streaming: translate one legacy SSE event to its modern equivalent.
18553
+ *
18554
+ * Returns the input unchanged when the `event_type` is not one of the legacy
18555
+ * ones we know how to map. Two non-trivial cases:
18556
+ * 1. `content.start` carries `content: <Content>` — the modern `step.start`
18557
+ * expects `step: {type: 'model_output', content: [<Content>]}`.
18558
+ * 2. `interaction.start` / `interaction.complete` wrap an `interaction`
18559
+ * object that may itself carry the legacy `outputs` field; recurse.
18560
+ */
18561
+ function maybeRemapLegacyStreamEvent(data) {
18562
+ if (!isPlainObject(data))
18563
+ return data;
18564
+ const eventType = data['event_type'];
18565
+ if (typeof eventType !== 'string' || !(eventType in LEGACY_EVENT_TYPE_RENAMES)) {
18566
+ return data;
18567
+ }
18568
+ const renamed = Object.assign(Object.assign({}, data), { event_type: LEGACY_EVENT_TYPE_RENAMES[eventType] });
18569
+ if (eventType === 'content.start') {
18570
+ const { content } = renamed, rest = __rest(renamed, ["content"]);
18571
+ let stepContent;
18572
+ if (content == null) {
18573
+ stepContent = [];
18574
+ }
18575
+ else if (Array.isArray(content)) {
18576
+ stepContent = content;
18577
+ }
18578
+ else {
18579
+ stepContent = [content];
18580
+ }
18581
+ return Object.assign(Object.assign({}, rest), { step: { type: 'model_output', content: stepContent } });
18582
+ }
18583
+ if (eventType === 'interaction.start' || eventType === 'interaction.complete') {
18584
+ const inner = renamed['interaction'];
18585
+ if (isPlainObject(inner)) {
18586
+ renamed['interaction'] = wrapOutputsAsSteps(inner);
18587
+ }
18588
+ }
18589
+ return renamed;
18590
+ }
18591
+ /**
18592
+ * Stream subclass that runs each yielded SSE event through
18593
+ * `maybeRemapLegacyStreamEvent` so consumers always see modern event shapes.
18594
+ *
18595
+ * Wired in via the `__streamClass` request option from `resources/interactions.ts`
18596
+ * (read by `src/internal/parse.ts:defaultParseResponse`).
18597
+ */
18598
+ class LegacyLyriaStream extends Stream {
18599
+ static fromSSEResponse(response, controller, client) {
18600
+ const base = Stream.fromSSEResponse(response, controller, client);
18601
+ function wrappedIterator() {
18602
+ return __asyncGenerator(this, arguments, function* wrappedIterator_1() {
18603
+ var _a, e_1, _b, _c;
18604
+ try {
18605
+ 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) {
18606
+ _c = base_1_1.value;
18607
+ _d = false;
18608
+ const item = _c;
18609
+ yield yield __await(maybeRemapLegacyStreamEvent(item));
18610
+ }
18611
+ }
18612
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
18613
+ finally {
18614
+ try {
18615
+ if (!_d && !_a && (_b = base_1.return)) yield __await(_b.call(base_1));
18616
+ }
18617
+ finally { if (e_1) throw e_1.error; }
18618
+ }
18619
+ });
18620
+ }
18621
+ return new LegacyLyriaStream(wrappedIterator, controller, client);
18622
+ }
18623
+ }
18624
+
18625
+ /**
18626
+ * @license
18627
+ * Copyright 2025 Google LLC
18628
+ * SPDX-License-Identifier: Apache-2.0
18629
+ */
18630
+ /**
18631
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
18632
+ *
18633
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
18634
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
18635
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
18636
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
18637
+ */
18638
+ function encodeURIPath(str) {
18639
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
18640
+ }
18641
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
18642
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
18643
+ // If there are no params, no processing is needed.
18644
+ if (statics.length === 1)
18645
+ return statics[0];
18646
+ let postPath = false;
18647
+ const invalidSegments = [];
18648
+ const path = statics.reduce((previousValue, currentValue, index) => {
18649
+ var _a, _b, _c;
18650
+ if (/[?#]/.test(currentValue)) {
18651
+ postPath = true;
18652
+ }
18653
+ const value = params[index];
18654
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18655
+ if (index !== params.length &&
18656
+ (value == null ||
18657
+ (typeof value === 'object' &&
18658
+ // handle values from other realms
18659
+ value.toString ===
18660
+ ((_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)))) {
18661
+ encoded = value + '';
18662
+ invalidSegments.push({
18663
+ start: previousValue.length + currentValue.length,
18664
+ length: encoded.length,
18665
+ error: `Value of type ${Object.prototype.toString
18666
+ .call(value)
18667
+ .slice(8, -1)} is not a valid path parameter`,
18668
+ });
18669
+ }
18670
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
18671
+ }, '');
18672
+ const pathOnly = path.split(/[?#]/, 1)[0];
18673
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18674
+ let match;
18675
+ // Find all invalid segments
18676
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18677
+ const hasLeadingSlash = match[0].startsWith('/');
18678
+ const offset = hasLeadingSlash ? 1 : 0;
18679
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18680
+ invalidSegments.push({
18681
+ start: match.index + offset,
18682
+ length: cleanMatch.length,
18683
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18684
+ });
18685
+ }
18686
+ invalidSegments.sort((a, b) => a.start - b.start);
18687
+ if (invalidSegments.length > 0) {
18688
+ let lastEnd = 0;
18689
+ const underline = invalidSegments.reduce((acc, segment) => {
18690
+ const spaces = ' '.repeat(segment.start - lastEnd);
18691
+ const arrows = '^'.repeat(segment.length);
18692
+ lastEnd = segment.start + segment.length;
18693
+ return acc + spaces + arrows;
18694
+ }, '');
18695
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18696
+ .map((e) => e.error)
18697
+ .join('\n')}\n${path}\n${underline}`);
18698
+ }
18699
+ return path;
18700
+ });
18701
+ /**
18702
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18703
+ */
18704
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18705
+
18706
+ /**
18707
+ * @license
18708
+ * Copyright 2025 Google LLC
18709
+ * SPDX-License-Identifier: Apache-2.0
18710
+ */
18711
+ class BaseInteractions extends APIResource {
18712
+ create(params, options) {
18713
+ var _a;
18714
+ const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
18715
+ if ('model' in body && 'agent_config' in body) {
18716
+ throw new GeminiNextGenAPIClientError(`Invalid request: specified \`model\` and \`agent_config\`. If specifying \`model\`, use \`generation_config\`.`);
18717
+ }
18718
+ if ('agent' in body && 'generation_config' in body) {
18719
+ throw new GeminiNextGenAPIClientError(`Invalid request: specified \`agent\` and \`generation_config\`. If specifying \`agent\`, use \`agent_config\`.`);
18720
+ }
18721
+ const needsLegacyLyriaShim = isLegacyLyriaRequest({
18722
+ isVertex: isVertexClient(this._client),
18723
+ model: 'model' in body ? body.model : undefined,
18724
+ });
18725
+ const isStreaming = (_a = params.stream) !== null && _a !== void 0 ? _a : false;
18726
+ const promise = this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign(Object.assign({ body }, options), { stream: isStreaming }), (needsLegacyLyriaShim && isStreaming ? { __streamClass: LegacyLyriaStream } : {})));
18727
+ if (needsLegacyLyriaShim && !isStreaming) {
18728
+ return promise._thenUnwrap((data) => coerceLegacyInteractionResponse(data));
18729
+ }
18730
+ return promise;
18731
+ }
18732
+ /**
18733
+ * Deletes the interaction by id.
18734
+ *
18735
+ * @example
18736
+ * ```ts
18737
+ * const interaction = await client.interactions.delete('id', {
18738
+ * api_version: 'api_version',
18739
+ * });
18740
+ * ```
18741
+ */
18742
+ delete(id, params = {}, options) {
18743
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18744
+ return this._client.delete(path `/${api_version}/interactions/${id}`, options);
18745
+ }
18746
+ /**
18747
+ * Cancels an interaction by id. This only applies to background interactions that
18748
+ * are still running.
18749
+ *
18750
+ * @example
18751
+ * ```ts
18752
+ * const interaction = await client.interactions.cancel('id', {
18753
+ * api_version: 'api_version',
18754
+ * });
18755
+ * ```
18756
+ */
18757
+ cancel(id, params = {}, options) {
18758
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18759
+ return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
18760
+ }
18761
+ get(id, params = {}, options) {
18762
+ var _a;
18763
+ const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
18764
+ 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 }));
18765
+ }
18766
+ }
18767
+ BaseInteractions._key = Object.freeze(['interactions']);
18768
+ class Interactions extends BaseInteractions {
18769
+ }
18770
+
18771
+ /**
18772
+ * @license
18773
+ * Copyright 2025 Google LLC
18774
+ * SPDX-License-Identifier: Apache-2.0
18775
+ */
18776
+ class BaseWebhooks extends APIResource {
18777
+ /**
18778
+ * Creates a new Webhook.
18779
+ */
18780
+ create(params, options) {
18781
+ const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
18782
+ return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
18783
+ }
18784
+ /**
18785
+ * Updates an existing Webhook.
18786
+ */
18787
+ update(id, params = {}, options) {
18788
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
18789
+ return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
18790
+ }
18791
+ /**
18792
+ * Lists all Webhooks.
18793
+ */
18794
+ list(params = {}, options) {
18795
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
18796
+ return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
18797
+ }
18798
+ /**
18799
+ * Deletes a Webhook.
18800
+ */
18801
+ delete(id, params = {}, options) {
18802
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18803
+ return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
18804
+ }
18805
+ /**
18806
+ * Gets a specific Webhook.
18807
+ */
18808
+ get(id, params = {}, options) {
18809
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18810
+ return this._client.get(path `/${api_version}/webhooks/${id}`, options);
18811
+ }
18812
+ /**
18813
+ * Sends a ping event to a Webhook.
18814
+ */
18815
+ ping(id, params = undefined, options) {
18816
+ const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
18817
+ return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
18818
+ }
18819
+ /**
18820
+ * Generates a new signing secret for a Webhook.
18821
+ */
18822
+ rotateSigningSecret(id, params = {}, options) {
18823
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
18824
+ return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
18825
+ }
18826
+ }
18827
+ BaseWebhooks._key = Object.freeze(['webhooks']);
18828
+ class Webhooks extends BaseWebhooks {
18829
+ }
18830
+
18801
18831
  /**
18802
18832
  * @license
18803
18833
  * Copyright 2025 Google LLC