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