@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/index.cjs CHANGED
@@ -760,11 +760,11 @@ exports.PhishBlockThreshold = void 0;
760
760
  */
761
761
  PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
762
762
  })(exports.PhishBlockThreshold || (exports.PhishBlockThreshold = {}));
763
- /** Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This enum is not supported in Vertex AI. */
763
+ /** 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. */
764
764
  exports.Behavior = void 0;
765
765
  (function (Behavior) {
766
766
  /**
767
- * This value is unused.
767
+ * This value is unspecified.
768
768
  */
769
769
  Behavior["UNSPECIFIED"] = "UNSPECIFIED";
770
770
  /**
@@ -6052,41 +6052,6 @@ function functionCallingConfigToMldev$1(fromObject) {
6052
6052
  }
6053
6053
  return toObject;
6054
6054
  }
6055
- function functionDeclarationToVertex$2(fromObject) {
6056
- const toObject = {};
6057
- const fromDescription = getValueByPath(fromObject, ['description']);
6058
- if (fromDescription != null) {
6059
- setValueByPath(toObject, ['description'], fromDescription);
6060
- }
6061
- const fromName = getValueByPath(fromObject, ['name']);
6062
- if (fromName != null) {
6063
- setValueByPath(toObject, ['name'], fromName);
6064
- }
6065
- const fromParameters = getValueByPath(fromObject, ['parameters']);
6066
- if (fromParameters != null) {
6067
- setValueByPath(toObject, ['parameters'], fromParameters);
6068
- }
6069
- const fromParametersJsonSchema = getValueByPath(fromObject, [
6070
- 'parametersJsonSchema',
6071
- ]);
6072
- if (fromParametersJsonSchema != null) {
6073
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
6074
- }
6075
- const fromResponse = getValueByPath(fromObject, ['response']);
6076
- if (fromResponse != null) {
6077
- setValueByPath(toObject, ['response'], fromResponse);
6078
- }
6079
- const fromResponseJsonSchema = getValueByPath(fromObject, [
6080
- 'responseJsonSchema',
6081
- ]);
6082
- if (fromResponseJsonSchema != null) {
6083
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
6084
- }
6085
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
6086
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
6087
- }
6088
- return toObject;
6089
- }
6090
6055
  function getCachedContentParametersToMldev(apiClient, fromObject) {
6091
6056
  const toObject = {};
6092
6057
  const fromName = getValueByPath(fromObject, ['name']);
@@ -6519,7 +6484,7 @@ function toolToVertex$2(fromObject) {
6519
6484
  let transformedList = fromFunctionDeclarations;
6520
6485
  if (Array.isArray(transformedList)) {
6521
6486
  transformedList = transformedList.map((item) => {
6522
- return functionDeclarationToVertex$2(item);
6487
+ return item;
6523
6488
  });
6524
6489
  }
6525
6490
  setValueByPath(toObject, ['functionDeclarations'], transformedList);
@@ -7631,7 +7596,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
7631
7596
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
7632
7597
  const USER_AGENT_HEADER = 'User-Agent';
7633
7598
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
7634
- const SDK_VERSION = '2.0.0'; // x-release-please-version
7599
+ const SDK_VERSION = '2.1.0'; // x-release-please-version
7635
7600
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
7636
7601
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
7637
7602
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -9965,203 +9930,6 @@ class APIResource {
9965
9930
  */
9966
9931
  APIResource._key = [];
9967
9932
 
9968
- /**
9969
- * @license
9970
- * Copyright 2025 Google LLC
9971
- * SPDX-License-Identifier: Apache-2.0
9972
- */
9973
- /**
9974
- * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
9975
- *
9976
- * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
9977
- * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
9978
- * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
9979
- * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
9980
- */
9981
- function encodeURIPath(str) {
9982
- return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
9983
- }
9984
- const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
9985
- const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
9986
- // If there are no params, no processing is needed.
9987
- if (statics.length === 1)
9988
- return statics[0];
9989
- let postPath = false;
9990
- const invalidSegments = [];
9991
- const path = statics.reduce((previousValue, currentValue, index) => {
9992
- var _a, _b, _c;
9993
- if (/[?#]/.test(currentValue)) {
9994
- postPath = true;
9995
- }
9996
- const value = params[index];
9997
- let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
9998
- if (index !== params.length &&
9999
- (value == null ||
10000
- (typeof value === 'object' &&
10001
- // handle values from other realms
10002
- value.toString ===
10003
- ((_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)))) {
10004
- encoded = value + '';
10005
- invalidSegments.push({
10006
- start: previousValue.length + currentValue.length,
10007
- length: encoded.length,
10008
- error: `Value of type ${Object.prototype.toString
10009
- .call(value)
10010
- .slice(8, -1)} is not a valid path parameter`,
10011
- });
10012
- }
10013
- return previousValue + currentValue + (index === params.length ? '' : encoded);
10014
- }, '');
10015
- const pathOnly = path.split(/[?#]/, 1)[0];
10016
- const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
10017
- let match;
10018
- // Find all invalid segments
10019
- while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
10020
- const hasLeadingSlash = match[0].startsWith('/');
10021
- const offset = hasLeadingSlash ? 1 : 0;
10022
- const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
10023
- invalidSegments.push({
10024
- start: match.index + offset,
10025
- length: cleanMatch.length,
10026
- error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
10027
- });
10028
- }
10029
- invalidSegments.sort((a, b) => a.start - b.start);
10030
- if (invalidSegments.length > 0) {
10031
- let lastEnd = 0;
10032
- const underline = invalidSegments.reduce((acc, segment) => {
10033
- const spaces = ' '.repeat(segment.start - lastEnd);
10034
- const arrows = '^'.repeat(segment.length);
10035
- lastEnd = segment.start + segment.length;
10036
- return acc + spaces + arrows;
10037
- }, '');
10038
- throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
10039
- .map((e) => e.error)
10040
- .join('\n')}\n${path}\n${underline}`);
10041
- }
10042
- return path;
10043
- });
10044
- /**
10045
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
10046
- */
10047
- const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
10048
-
10049
- /**
10050
- * @license
10051
- * Copyright 2025 Google LLC
10052
- * SPDX-License-Identifier: Apache-2.0
10053
- */
10054
- class BaseInteractions extends APIResource {
10055
- create(params, options) {
10056
- var _a;
10057
- const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
10058
- if ('model' in body && 'agent_config' in body) {
10059
- throw new GeminiNextGenAPIClientError(`Invalid request: specified \`model\` and \`agent_config\`. If specifying \`model\`, use \`generation_config\`.`);
10060
- }
10061
- if ('agent' in body && 'generation_config' in body) {
10062
- throw new GeminiNextGenAPIClientError(`Invalid request: specified \`agent\` and \`generation_config\`. If specifying \`agent\`, use \`agent_config\`.`);
10063
- }
10064
- return this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign({ body }, options), { stream: (_a = params.stream) !== null && _a !== void 0 ? _a : false }));
10065
- }
10066
- /**
10067
- * Deletes the interaction by id.
10068
- *
10069
- * @example
10070
- * ```ts
10071
- * const interaction = await client.interactions.delete('id', {
10072
- * api_version: 'api_version',
10073
- * });
10074
- * ```
10075
- */
10076
- delete(id, params = {}, options) {
10077
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10078
- return this._client.delete(path `/${api_version}/interactions/${id}`, options);
10079
- }
10080
- /**
10081
- * Cancels an interaction by id. This only applies to background interactions that
10082
- * are still running.
10083
- *
10084
- * @example
10085
- * ```ts
10086
- * const interaction = await client.interactions.cancel('id', {
10087
- * api_version: 'api_version',
10088
- * });
10089
- * ```
10090
- */
10091
- cancel(id, params = {}, options) {
10092
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10093
- return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
10094
- }
10095
- get(id, params = {}, options) {
10096
- var _a;
10097
- const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
10098
- 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 }));
10099
- }
10100
- }
10101
- BaseInteractions._key = Object.freeze(['interactions']);
10102
- class Interactions extends BaseInteractions {
10103
- }
10104
-
10105
- /**
10106
- * @license
10107
- * Copyright 2025 Google LLC
10108
- * SPDX-License-Identifier: Apache-2.0
10109
- */
10110
- class BaseWebhooks extends APIResource {
10111
- /**
10112
- * Creates a new Webhook.
10113
- */
10114
- create(params, options) {
10115
- const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
10116
- return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
10117
- }
10118
- /**
10119
- * Updates an existing Webhook.
10120
- */
10121
- update(id, params = {}, options) {
10122
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
10123
- return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
10124
- }
10125
- /**
10126
- * Lists all Webhooks.
10127
- */
10128
- list(params = {}, options) {
10129
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
10130
- return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
10131
- }
10132
- /**
10133
- * Deletes a Webhook.
10134
- */
10135
- delete(id, params = {}, options) {
10136
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10137
- return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
10138
- }
10139
- /**
10140
- * Gets a specific Webhook.
10141
- */
10142
- get(id, params = {}, options) {
10143
- const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10144
- return this._client.get(path `/${api_version}/webhooks/${id}`, options);
10145
- }
10146
- /**
10147
- * Sends a ping event to a Webhook.
10148
- */
10149
- ping(id, params = undefined, options) {
10150
- const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
10151
- return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
10152
- }
10153
- /**
10154
- * Generates a new signing secret for a Webhook.
10155
- */
10156
- rotateSigningSecret(id, params = {}, options) {
10157
- const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
10158
- return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
10159
- }
10160
- }
10161
- BaseWebhooks._key = Object.freeze(['webhooks']);
10162
- class Webhooks extends BaseWebhooks {
10163
- }
10164
-
10165
9933
  /**
10166
9934
  * @license
10167
9935
  * Copyright 2025 Google LLC
@@ -10702,20 +10470,352 @@ function partition(str, delimiter) {
10702
10470
  * Copyright 2025 Google LLC
10703
10471
  * SPDX-License-Identifier: Apache-2.0
10704
10472
  */
10705
- async function defaultParseResponse(client, props) {
10706
- const { response, requestLogID, retryOfRequestLogID, startTime } = props;
10707
- const body = await (async () => {
10708
- var _a;
10709
- if (props.options.stream) {
10710
- loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
10711
- // Note: there is an invariant here that isn't represented in the type system
10712
- // that if you set `stream: true` the response type must also be `Stream<T>`
10713
- if (props.options.__streamClass) {
10714
- return props.options.__streamClass.fromSSEResponse(response, props.controller, client);
10715
- }
10716
- return Stream.fromSSEResponse(response, props.controller, client);
10473
+ const LEGACY_LYRIA_MODELS = new Set([
10474
+ 'lyria-3-pro-preview',
10475
+ 'lyria-3-clip-preview',
10476
+ ]);
10477
+ const LEGACY_EVENT_TYPE_RENAMES = {
10478
+ 'interaction.start': 'interaction.created',
10479
+ 'content.start': 'step.start',
10480
+ 'content.delta': 'step.delta',
10481
+ 'content.stop': 'step.stop',
10482
+ 'interaction.complete': 'interaction.completed',
10483
+ };
10484
+ function isLegacyLyriaRequest({ isVertex, model }) {
10485
+ return Boolean(isVertex) && typeof model === 'string' && LEGACY_LYRIA_MODELS.has(model);
10486
+ }
10487
+ /**
10488
+ * Detect whether a client is in vertex mode. Reads the `clientAdapter` field
10489
+ * directly because `BaseGeminiNextGenAPIClient` keeps it `private`; centralizing
10490
+ * the runtime cast here avoids leaking it into resource files.
10491
+ */
10492
+ function isVertexClient(client) {
10493
+ const adapter = client.clientAdapter;
10494
+ return Boolean(adapter && adapter.isVertexAI());
10495
+ }
10496
+ function isPlainObject(value) {
10497
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
10498
+ }
10499
+ /**
10500
+ * Wrap a legacy `outputs: Array<Content>` payload into the modern
10501
+ * `steps: [{type: 'model_output', content: outputs}]` shape. Returns the input
10502
+ * unchanged when `steps` already wins or `outputs` is absent.
10503
+ */
10504
+ function wrapOutputsAsSteps(data) {
10505
+ if (!('outputs' in data) || 'steps' in data) {
10506
+ return data;
10507
+ }
10508
+ const { outputs } = data, rest = __rest(data, ["outputs"]);
10509
+ return Object.assign(Object.assign({}, rest), { steps: [{ type: 'model_output', content: outputs }] });
10510
+ }
10511
+ /**
10512
+ * Non-streaming: rewrite a legacy interaction response so consumers see the
10513
+ * modern `steps` shape.
10514
+ */
10515
+ function coerceLegacyInteractionResponse(data) {
10516
+ if (!isPlainObject(data))
10517
+ return data;
10518
+ return wrapOutputsAsSteps(data);
10519
+ }
10520
+ /**
10521
+ * Streaming: translate one legacy SSE event to its modern equivalent.
10522
+ *
10523
+ * Returns the input unchanged when the `event_type` is not one of the legacy
10524
+ * ones we know how to map. Two non-trivial cases:
10525
+ * 1. `content.start` carries `content: <Content>` — the modern `step.start`
10526
+ * expects `step: {type: 'model_output', content: [<Content>]}`.
10527
+ * 2. `interaction.start` / `interaction.complete` wrap an `interaction`
10528
+ * object that may itself carry the legacy `outputs` field; recurse.
10529
+ */
10530
+ function maybeRemapLegacyStreamEvent(data) {
10531
+ if (!isPlainObject(data))
10532
+ return data;
10533
+ const eventType = data['event_type'];
10534
+ if (typeof eventType !== 'string' || !(eventType in LEGACY_EVENT_TYPE_RENAMES)) {
10535
+ return data;
10536
+ }
10537
+ const renamed = Object.assign(Object.assign({}, data), { event_type: LEGACY_EVENT_TYPE_RENAMES[eventType] });
10538
+ if (eventType === 'content.start') {
10539
+ const { content } = renamed, rest = __rest(renamed, ["content"]);
10540
+ let stepContent;
10541
+ if (content == null) {
10542
+ stepContent = [];
10717
10543
  }
10718
- // fetch refuses to read the body when the status code is 204.
10544
+ else if (Array.isArray(content)) {
10545
+ stepContent = content;
10546
+ }
10547
+ else {
10548
+ stepContent = [content];
10549
+ }
10550
+ return Object.assign(Object.assign({}, rest), { step: { type: 'model_output', content: stepContent } });
10551
+ }
10552
+ if (eventType === 'interaction.start' || eventType === 'interaction.complete') {
10553
+ const inner = renamed['interaction'];
10554
+ if (isPlainObject(inner)) {
10555
+ renamed['interaction'] = wrapOutputsAsSteps(inner);
10556
+ }
10557
+ }
10558
+ return renamed;
10559
+ }
10560
+ /**
10561
+ * Stream subclass that runs each yielded SSE event through
10562
+ * `maybeRemapLegacyStreamEvent` so consumers always see modern event shapes.
10563
+ *
10564
+ * Wired in via the `__streamClass` request option from `resources/interactions.ts`
10565
+ * (read by `src/internal/parse.ts:defaultParseResponse`).
10566
+ */
10567
+ class LegacyLyriaStream extends Stream {
10568
+ static fromSSEResponse(response, controller, client) {
10569
+ const base = Stream.fromSSEResponse(response, controller, client);
10570
+ function wrappedIterator() {
10571
+ return __asyncGenerator(this, arguments, function* wrappedIterator_1() {
10572
+ var _a, e_1, _b, _c;
10573
+ try {
10574
+ 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) {
10575
+ _c = base_1_1.value;
10576
+ _d = false;
10577
+ const item = _c;
10578
+ yield yield __await(maybeRemapLegacyStreamEvent(item));
10579
+ }
10580
+ }
10581
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
10582
+ finally {
10583
+ try {
10584
+ if (!_d && !_a && (_b = base_1.return)) yield __await(_b.call(base_1));
10585
+ }
10586
+ finally { if (e_1) throw e_1.error; }
10587
+ }
10588
+ });
10589
+ }
10590
+ return new LegacyLyriaStream(wrappedIterator, controller, client);
10591
+ }
10592
+ }
10593
+
10594
+ /**
10595
+ * @license
10596
+ * Copyright 2025 Google LLC
10597
+ * SPDX-License-Identifier: Apache-2.0
10598
+ */
10599
+ /**
10600
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
10601
+ *
10602
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
10603
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
10604
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
10605
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
10606
+ */
10607
+ function encodeURIPath(str) {
10608
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
10609
+ }
10610
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
10611
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
10612
+ // If there are no params, no processing is needed.
10613
+ if (statics.length === 1)
10614
+ return statics[0];
10615
+ let postPath = false;
10616
+ const invalidSegments = [];
10617
+ const path = statics.reduce((previousValue, currentValue, index) => {
10618
+ var _a, _b, _c;
10619
+ if (/[?#]/.test(currentValue)) {
10620
+ postPath = true;
10621
+ }
10622
+ const value = params[index];
10623
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
10624
+ if (index !== params.length &&
10625
+ (value == null ||
10626
+ (typeof value === 'object' &&
10627
+ // handle values from other realms
10628
+ value.toString ===
10629
+ ((_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)))) {
10630
+ encoded = value + '';
10631
+ invalidSegments.push({
10632
+ start: previousValue.length + currentValue.length,
10633
+ length: encoded.length,
10634
+ error: `Value of type ${Object.prototype.toString
10635
+ .call(value)
10636
+ .slice(8, -1)} is not a valid path parameter`,
10637
+ });
10638
+ }
10639
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
10640
+ }, '');
10641
+ const pathOnly = path.split(/[?#]/, 1)[0];
10642
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
10643
+ let match;
10644
+ // Find all invalid segments
10645
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
10646
+ const hasLeadingSlash = match[0].startsWith('/');
10647
+ const offset = hasLeadingSlash ? 1 : 0;
10648
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
10649
+ invalidSegments.push({
10650
+ start: match.index + offset,
10651
+ length: cleanMatch.length,
10652
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
10653
+ });
10654
+ }
10655
+ invalidSegments.sort((a, b) => a.start - b.start);
10656
+ if (invalidSegments.length > 0) {
10657
+ let lastEnd = 0;
10658
+ const underline = invalidSegments.reduce((acc, segment) => {
10659
+ const spaces = ' '.repeat(segment.start - lastEnd);
10660
+ const arrows = '^'.repeat(segment.length);
10661
+ lastEnd = segment.start + segment.length;
10662
+ return acc + spaces + arrows;
10663
+ }, '');
10664
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
10665
+ .map((e) => e.error)
10666
+ .join('\n')}\n${path}\n${underline}`);
10667
+ }
10668
+ return path;
10669
+ });
10670
+ /**
10671
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
10672
+ */
10673
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
10674
+
10675
+ /**
10676
+ * @license
10677
+ * Copyright 2025 Google LLC
10678
+ * SPDX-License-Identifier: Apache-2.0
10679
+ */
10680
+ class BaseInteractions extends APIResource {
10681
+ create(params, options) {
10682
+ var _a;
10683
+ const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
10684
+ if ('model' in body && 'agent_config' in body) {
10685
+ throw new GeminiNextGenAPIClientError(`Invalid request: specified \`model\` and \`agent_config\`. If specifying \`model\`, use \`generation_config\`.`);
10686
+ }
10687
+ if ('agent' in body && 'generation_config' in body) {
10688
+ throw new GeminiNextGenAPIClientError(`Invalid request: specified \`agent\` and \`generation_config\`. If specifying \`agent\`, use \`agent_config\`.`);
10689
+ }
10690
+ const needsLegacyLyriaShim = isLegacyLyriaRequest({
10691
+ isVertex: isVertexClient(this._client),
10692
+ model: 'model' in body ? body.model : undefined,
10693
+ });
10694
+ const isStreaming = (_a = params.stream) !== null && _a !== void 0 ? _a : false;
10695
+ const promise = this._client.post(path `/${api_version}/interactions`, Object.assign(Object.assign(Object.assign({ body }, options), { stream: isStreaming }), (needsLegacyLyriaShim && isStreaming ? { __streamClass: LegacyLyriaStream } : {})));
10696
+ if (needsLegacyLyriaShim && !isStreaming) {
10697
+ return promise._thenUnwrap((data) => coerceLegacyInteractionResponse(data));
10698
+ }
10699
+ return promise;
10700
+ }
10701
+ /**
10702
+ * Deletes the interaction by id.
10703
+ *
10704
+ * @example
10705
+ * ```ts
10706
+ * const interaction = await client.interactions.delete('id', {
10707
+ * api_version: 'api_version',
10708
+ * });
10709
+ * ```
10710
+ */
10711
+ delete(id, params = {}, options) {
10712
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10713
+ return this._client.delete(path `/${api_version}/interactions/${id}`, options);
10714
+ }
10715
+ /**
10716
+ * Cancels an interaction by id. This only applies to background interactions that
10717
+ * are still running.
10718
+ *
10719
+ * @example
10720
+ * ```ts
10721
+ * const interaction = await client.interactions.cancel('id', {
10722
+ * api_version: 'api_version',
10723
+ * });
10724
+ * ```
10725
+ */
10726
+ cancel(id, params = {}, options) {
10727
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10728
+ return this._client.post(path `/${api_version}/interactions/${id}/cancel`, options);
10729
+ }
10730
+ get(id, params = {}, options) {
10731
+ var _a;
10732
+ const _b = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _b, query = __rest(_b, ["api_version"]);
10733
+ 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 }));
10734
+ }
10735
+ }
10736
+ BaseInteractions._key = Object.freeze(['interactions']);
10737
+ class Interactions extends BaseInteractions {
10738
+ }
10739
+
10740
+ /**
10741
+ * @license
10742
+ * Copyright 2025 Google LLC
10743
+ * SPDX-License-Identifier: Apache-2.0
10744
+ */
10745
+ class BaseWebhooks extends APIResource {
10746
+ /**
10747
+ * Creates a new Webhook.
10748
+ */
10749
+ create(params, options) {
10750
+ const { api_version = this._client.apiVersion } = params, body = __rest(params, ["api_version"]);
10751
+ return this._client.post(path `/${api_version}/webhooks`, Object.assign({ body }, options));
10752
+ }
10753
+ /**
10754
+ * Updates an existing Webhook.
10755
+ */
10756
+ update(id, params = {}, options) {
10757
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion, update_mask } = _a, body = __rest(_a, ["api_version", "update_mask"]);
10758
+ return this._client.patch(path `/${api_version}/webhooks/${id}`, Object.assign({ query: { update_mask }, body }, options));
10759
+ }
10760
+ /**
10761
+ * Lists all Webhooks.
10762
+ */
10763
+ list(params = {}, options) {
10764
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
10765
+ return this._client.get(path `/${api_version}/webhooks`, Object.assign({ query }, options));
10766
+ }
10767
+ /**
10768
+ * Deletes a Webhook.
10769
+ */
10770
+ delete(id, params = {}, options) {
10771
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10772
+ return this._client.delete(path `/${api_version}/webhooks/${id}`, options);
10773
+ }
10774
+ /**
10775
+ * Gets a specific Webhook.
10776
+ */
10777
+ get(id, params = {}, options) {
10778
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10779
+ return this._client.get(path `/${api_version}/webhooks/${id}`, options);
10780
+ }
10781
+ /**
10782
+ * Sends a ping event to a Webhook.
10783
+ */
10784
+ ping(id, params = undefined, options) {
10785
+ const { api_version = this._client.apiVersion, body } = params !== null && params !== void 0 ? params : {};
10786
+ return this._client.post(path `/${api_version}/webhooks/${id}:ping`, Object.assign({ body: body }, options));
10787
+ }
10788
+ /**
10789
+ * Generates a new signing secret for a Webhook.
10790
+ */
10791
+ rotateSigningSecret(id, params = {}, options) {
10792
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
10793
+ return this._client.post(path `/${api_version}/webhooks/${id}:rotateSigningSecret`, Object.assign({ body }, options));
10794
+ }
10795
+ }
10796
+ BaseWebhooks._key = Object.freeze(['webhooks']);
10797
+ class Webhooks extends BaseWebhooks {
10798
+ }
10799
+
10800
+ /**
10801
+ * @license
10802
+ * Copyright 2025 Google LLC
10803
+ * SPDX-License-Identifier: Apache-2.0
10804
+ */
10805
+ async function defaultParseResponse(client, props) {
10806
+ const { response, requestLogID, retryOfRequestLogID, startTime } = props;
10807
+ const body = await (async () => {
10808
+ var _a;
10809
+ if (props.options.stream) {
10810
+ loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
10811
+ // Note: there is an invariant here that isn't represented in the type system
10812
+ // that if you set `stream: true` the response type must also be `Stream<T>`
10813
+ if (props.options.__streamClass) {
10814
+ return props.options.__streamClass.fromSSEResponse(response, props.controller, client);
10815
+ }
10816
+ return Stream.fromSSEResponse(response, props.controller, client);
10817
+ }
10818
+ // fetch refuses to read the body when the status code is 204.
10719
10819
  if (response.status === 204) {
10720
10820
  return null;
10721
10821
  }
@@ -11498,41 +11598,6 @@ function functionCallToMldev$2(fromObject) {
11498
11598
  }
11499
11599
  return toObject;
11500
11600
  }
11501
- function functionDeclarationToVertex$1(fromObject) {
11502
- const toObject = {};
11503
- const fromDescription = getValueByPath(fromObject, ['description']);
11504
- if (fromDescription != null) {
11505
- setValueByPath(toObject, ['description'], fromDescription);
11506
- }
11507
- const fromName = getValueByPath(fromObject, ['name']);
11508
- if (fromName != null) {
11509
- setValueByPath(toObject, ['name'], fromName);
11510
- }
11511
- const fromParameters = getValueByPath(fromObject, ['parameters']);
11512
- if (fromParameters != null) {
11513
- setValueByPath(toObject, ['parameters'], fromParameters);
11514
- }
11515
- const fromParametersJsonSchema = getValueByPath(fromObject, [
11516
- 'parametersJsonSchema',
11517
- ]);
11518
- if (fromParametersJsonSchema != null) {
11519
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
11520
- }
11521
- const fromResponse = getValueByPath(fromObject, ['response']);
11522
- if (fromResponse != null) {
11523
- setValueByPath(toObject, ['response'], fromResponse);
11524
- }
11525
- const fromResponseJsonSchema = getValueByPath(fromObject, [
11526
- 'responseJsonSchema',
11527
- ]);
11528
- if (fromResponseJsonSchema != null) {
11529
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
11530
- }
11531
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
11532
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
11533
- }
11534
- return toObject;
11535
- }
11536
11601
  function generationConfigToVertex$1(fromObject) {
11537
11602
  const toObject = {};
11538
11603
  const fromModelSelectionConfig = getValueByPath(fromObject, [
@@ -12416,7 +12481,7 @@ function toolToVertex$1(fromObject) {
12416
12481
  let transformedList = fromFunctionDeclarations;
12417
12482
  if (Array.isArray(transformedList)) {
12418
12483
  transformedList = transformedList.map((item) => {
12419
- return functionDeclarationToVertex$1(item);
12484
+ return item;
12420
12485
  });
12421
12486
  }
12422
12487
  setValueByPath(toObject, ['functionDeclarations'], transformedList);
@@ -13431,41 +13496,6 @@ function functionCallingConfigToMldev(fromObject, _rootObject) {
13431
13496
  }
13432
13497
  return toObject;
13433
13498
  }
13434
- function functionDeclarationToVertex(fromObject, _rootObject) {
13435
- const toObject = {};
13436
- const fromDescription = getValueByPath(fromObject, ['description']);
13437
- if (fromDescription != null) {
13438
- setValueByPath(toObject, ['description'], fromDescription);
13439
- }
13440
- const fromName = getValueByPath(fromObject, ['name']);
13441
- if (fromName != null) {
13442
- setValueByPath(toObject, ['name'], fromName);
13443
- }
13444
- const fromParameters = getValueByPath(fromObject, ['parameters']);
13445
- if (fromParameters != null) {
13446
- setValueByPath(toObject, ['parameters'], fromParameters);
13447
- }
13448
- const fromParametersJsonSchema = getValueByPath(fromObject, [
13449
- 'parametersJsonSchema',
13450
- ]);
13451
- if (fromParametersJsonSchema != null) {
13452
- setValueByPath(toObject, ['parametersJsonSchema'], fromParametersJsonSchema);
13453
- }
13454
- const fromResponse = getValueByPath(fromObject, ['response']);
13455
- if (fromResponse != null) {
13456
- setValueByPath(toObject, ['response'], fromResponse);
13457
- }
13458
- const fromResponseJsonSchema = getValueByPath(fromObject, [
13459
- 'responseJsonSchema',
13460
- ]);
13461
- if (fromResponseJsonSchema != null) {
13462
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
13463
- }
13464
- if (getValueByPath(fromObject, ['behavior']) !== undefined) {
13465
- throw new Error('behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).');
13466
- }
13467
- return toObject;
13468
- }
13469
13499
  function generateContentConfigToMldev(apiClient, fromObject, parentObject, rootObject) {
13470
13500
  const toObject = {};
13471
13501
  const fromSystemInstruction = getValueByPath(fromObject, [
@@ -15782,7 +15812,7 @@ function toolToMldev$1(fromObject, rootObject) {
15782
15812
  }
15783
15813
  return toObject;
15784
15814
  }
15785
- function toolToVertex(fromObject, rootObject) {
15815
+ function toolToVertex(fromObject, _rootObject) {
15786
15816
  const toObject = {};
15787
15817
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
15788
15818
  if (fromRetrieval != null) {
@@ -15822,7 +15852,7 @@ function toolToVertex(fromObject, rootObject) {
15822
15852
  let transformedList = fromFunctionDeclarations;
15823
15853
  if (Array.isArray(transformedList)) {
15824
15854
  transformedList = transformedList.map((item) => {
15825
- return functionDeclarationToVertex(item);
15855
+ return item;
15826
15856
  });
15827
15857
  }
15828
15858
  setValueByPath(toObject, ['functionDeclarations'], transformedList);