@google/genai 2.3.0 → 2.4.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
@@ -7596,7 +7596,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
7596
7596
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
7597
7597
  const USER_AGENT_HEADER = 'User-Agent';
7598
7598
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
7599
- const SDK_VERSION = '2.3.0'; // x-release-please-version
7599
+ const SDK_VERSION = '2.4.0'; // x-release-please-version
7600
7600
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
7601
7601
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
7602
7602
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -9563,7 +9563,9 @@ class APIConnectionError extends APIError {
9563
9563
  }
9564
9564
  class APIConnectionTimeoutError extends APIConnectionError {
9565
9565
  constructor({ message } = {}) {
9566
- super({ message: message !== null && message !== void 0 ? message : 'Request timed out.' });
9566
+ super({
9567
+ message: message !== null && message !== void 0 ? message : 'Request timed out. This is a client-side timeout. You can increase the timeout by setting the `timeout` argument in your request or client http options.',
9568
+ });
9567
9569
  }
9568
9570
  }
9569
9571
  class BadRequestError extends APIError {
@@ -9930,6 +9932,126 @@ class APIResource {
9930
9932
  */
9931
9933
  APIResource._key = [];
9932
9934
 
9935
+ /**
9936
+ * @license
9937
+ * Copyright 2025 Google LLC
9938
+ * SPDX-License-Identifier: Apache-2.0
9939
+ */
9940
+ /**
9941
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
9942
+ *
9943
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
9944
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
9945
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
9946
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
9947
+ */
9948
+ function encodeURIPath(str) {
9949
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
9950
+ }
9951
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
9952
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
9953
+ // If there are no params, no processing is needed.
9954
+ if (statics.length === 1)
9955
+ return statics[0];
9956
+ let postPath = false;
9957
+ const invalidSegments = [];
9958
+ const path = statics.reduce((previousValue, currentValue, index) => {
9959
+ var _a, _b, _c;
9960
+ if (/[?#]/.test(currentValue)) {
9961
+ postPath = true;
9962
+ }
9963
+ const value = params[index];
9964
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
9965
+ if (index !== params.length &&
9966
+ (value == null ||
9967
+ (typeof value === 'object' &&
9968
+ // handle values from other realms
9969
+ value.toString ===
9970
+ ((_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)))) {
9971
+ encoded = value + '';
9972
+ invalidSegments.push({
9973
+ start: previousValue.length + currentValue.length,
9974
+ length: encoded.length,
9975
+ error: `Value of type ${Object.prototype.toString
9976
+ .call(value)
9977
+ .slice(8, -1)} is not a valid path parameter`,
9978
+ });
9979
+ }
9980
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
9981
+ }, '');
9982
+ const pathOnly = path.split(/[?#]/, 1)[0];
9983
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
9984
+ let match;
9985
+ // Find all invalid segments
9986
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
9987
+ const hasLeadingSlash = match[0].startsWith('/');
9988
+ const offset = hasLeadingSlash ? 1 : 0;
9989
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
9990
+ invalidSegments.push({
9991
+ start: match.index + offset,
9992
+ length: cleanMatch.length,
9993
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
9994
+ });
9995
+ }
9996
+ invalidSegments.sort((a, b) => a.start - b.start);
9997
+ if (invalidSegments.length > 0) {
9998
+ let lastEnd = 0;
9999
+ const underline = invalidSegments.reduce((acc, segment) => {
10000
+ const spaces = ' '.repeat(segment.start - lastEnd);
10001
+ const arrows = '^'.repeat(segment.length);
10002
+ lastEnd = segment.start + segment.length;
10003
+ return acc + spaces + arrows;
10004
+ }, '');
10005
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
10006
+ .map((e) => e.error)
10007
+ .join('\n')}\n${path}\n${underline}`);
10008
+ }
10009
+ return path;
10010
+ });
10011
+ /**
10012
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
10013
+ */
10014
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
10015
+
10016
+ /**
10017
+ * @license
10018
+ * Copyright 2025 Google LLC
10019
+ * SPDX-License-Identifier: Apache-2.0
10020
+ */
10021
+ class BaseAgents extends APIResource {
10022
+ /**
10023
+ * Creates a new Agent (Typed version for SDK).
10024
+ */
10025
+ create(params = {}, options) {
10026
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
10027
+ return this._client.post(path `/${api_version}/agents`, Object.assign({ body }, options));
10028
+ }
10029
+ /**
10030
+ * Lists all Agents.
10031
+ */
10032
+ list(params = {}, options) {
10033
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
10034
+ return this._client.get(path `/${api_version}/agents`, Object.assign({ query }, options));
10035
+ }
10036
+ /**
10037
+ * Deletes an Agent.
10038
+ */
10039
+ delete(id, params = {}, options) {
10040
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10041
+ return this._client.delete(path `/${api_version}/agents/${id}`, options);
10042
+ }
10043
+ /**
10044
+ * Gets a specific Agent.
10045
+ */
10046
+ get(id, params = {}, options) {
10047
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10048
+ return this._client.get(path `/${api_version}/agents/${id}`, options);
10049
+ }
10050
+ }
10051
+ BaseAgents._key = Object.freeze(['agents']);
10052
+ class Agents extends BaseAgents {
10053
+ }
10054
+
9933
10055
  /**
9934
10056
  * @license
9935
10057
  * Copyright 2025 Google LLC
@@ -10591,87 +10713,6 @@ class LegacyLyriaStream extends Stream {
10591
10713
  }
10592
10714
  }
10593
10715
 
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
10716
  /**
10676
10717
  * @license
10677
10718
  * Copyright 2025 Google LLC
@@ -10747,18 +10788,32 @@ class Interactions extends BaseInteractions {
10747
10788
  function addOutputProperties(interaction) {
10748
10789
  var _a, _b;
10749
10790
  const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
10750
- let firstTrailing = steps.length;
10751
- while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
10752
- firstTrailing--;
10753
- }
10754
- const modelSteps = steps.slice(firstTrailing);
10755
- const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
10791
+ // output_text: scan backwards across all steps (stopping at user_input),
10792
+ // skip non-text content until the first text item is found, then collect
10793
+ // text until a non-text barrier is hit.
10756
10794
  const textParts = [];
10757
- for (let i = output.length - 1; i >= 0; i--) {
10758
- const content = output[i];
10759
- if (content.type !== 'text')
10795
+ let collecting = false;
10796
+ outer: for (let i = steps.length - 1; i >= 0; i--) {
10797
+ const step = steps[i];
10798
+ if (step.type === 'user_input')
10760
10799
  break;
10761
- textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
10800
+ if (step.type !== 'model_output' || !step.content) {
10801
+ if (collecting)
10802
+ break outer;
10803
+ continue;
10804
+ }
10805
+ const content = step.content;
10806
+ for (let j = content.length - 1; j >= 0; j--) {
10807
+ const item = content[j];
10808
+ if (item.type === 'text') {
10809
+ collecting = true;
10810
+ textParts.push((_b = item.text) !== null && _b !== void 0 ? _b : '');
10811
+ }
10812
+ else if (collecting) {
10813
+ // Hit a non-text barrier after we started collecting.
10814
+ break outer;
10815
+ }
10816
+ }
10762
10817
  }
10763
10818
  const output_text = textParts.reverse().join('');
10764
10819
  let output_image;
@@ -11501,6 +11556,7 @@ class GeminiNextGenAPIClient extends BaseGeminiNextGenAPIClient {
11501
11556
  super(...arguments);
11502
11557
  this.interactions = new Interactions(this);
11503
11558
  this.webhooks = new Webhooks(this);
11559
+ this.agents = new Agents(this);
11504
11560
  }
11505
11561
  }
11506
11562
  _a = GeminiNextGenAPIClient;
@@ -11521,6 +11577,7 @@ GeminiNextGenAPIClient.UnprocessableEntityError = UnprocessableEntityError;
11521
11577
  GeminiNextGenAPIClient.toFile = toFile;
11522
11578
  GeminiNextGenAPIClient.Interactions = Interactions;
11523
11579
  GeminiNextGenAPIClient.Webhooks = Webhooks;
11580
+ GeminiNextGenAPIClient.Agents = Agents;
11524
11581
 
11525
11582
  /**
11526
11583
  * @license
@@ -20953,6 +21010,14 @@ class GoogleGenAI {
20953
21010
  this._webhooks = this.getNextGenClient().webhooks;
20954
21011
  return this._webhooks;
20955
21012
  }
21013
+ get agents() {
21014
+ if (this._agents !== undefined) {
21015
+ return this._agents;
21016
+ }
21017
+ console.warn('GoogleGenAI.agents: Agents usage is experimental and may change in future versions.');
21018
+ this._agents = this.getNextGenClient().agents;
21019
+ return this._agents;
21020
+ }
20956
21021
  constructor(options) {
20957
21022
  var _a, _b;
20958
21023
  if (options.apiKey == null) {
package/dist/index.mjs CHANGED
@@ -7594,7 +7594,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
7594
7594
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
7595
7595
  const USER_AGENT_HEADER = 'User-Agent';
7596
7596
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
7597
- const SDK_VERSION = '2.3.0'; // x-release-please-version
7597
+ const SDK_VERSION = '2.4.0'; // x-release-please-version
7598
7598
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
7599
7599
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
7600
7600
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -9561,7 +9561,9 @@ class APIConnectionError extends APIError {
9561
9561
  }
9562
9562
  class APIConnectionTimeoutError extends APIConnectionError {
9563
9563
  constructor({ message } = {}) {
9564
- super({ message: message !== null && message !== void 0 ? message : 'Request timed out.' });
9564
+ super({
9565
+ message: message !== null && message !== void 0 ? message : 'Request timed out. This is a client-side timeout. You can increase the timeout by setting the `timeout` argument in your request or client http options.',
9566
+ });
9565
9567
  }
9566
9568
  }
9567
9569
  class BadRequestError extends APIError {
@@ -9928,6 +9930,126 @@ class APIResource {
9928
9930
  */
9929
9931
  APIResource._key = [];
9930
9932
 
9933
+ /**
9934
+ * @license
9935
+ * Copyright 2025 Google LLC
9936
+ * SPDX-License-Identifier: Apache-2.0
9937
+ */
9938
+ /**
9939
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
9940
+ *
9941
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
9942
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
9943
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
9944
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
9945
+ */
9946
+ function encodeURIPath(str) {
9947
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
9948
+ }
9949
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
9950
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
9951
+ // If there are no params, no processing is needed.
9952
+ if (statics.length === 1)
9953
+ return statics[0];
9954
+ let postPath = false;
9955
+ const invalidSegments = [];
9956
+ const path = statics.reduce((previousValue, currentValue, index) => {
9957
+ var _a, _b, _c;
9958
+ if (/[?#]/.test(currentValue)) {
9959
+ postPath = true;
9960
+ }
9961
+ const value = params[index];
9962
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
9963
+ if (index !== params.length &&
9964
+ (value == null ||
9965
+ (typeof value === 'object' &&
9966
+ // handle values from other realms
9967
+ value.toString ===
9968
+ ((_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)))) {
9969
+ encoded = value + '';
9970
+ invalidSegments.push({
9971
+ start: previousValue.length + currentValue.length,
9972
+ length: encoded.length,
9973
+ error: `Value of type ${Object.prototype.toString
9974
+ .call(value)
9975
+ .slice(8, -1)} is not a valid path parameter`,
9976
+ });
9977
+ }
9978
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
9979
+ }, '');
9980
+ const pathOnly = path.split(/[?#]/, 1)[0];
9981
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
9982
+ let match;
9983
+ // Find all invalid segments
9984
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
9985
+ const hasLeadingSlash = match[0].startsWith('/');
9986
+ const offset = hasLeadingSlash ? 1 : 0;
9987
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
9988
+ invalidSegments.push({
9989
+ start: match.index + offset,
9990
+ length: cleanMatch.length,
9991
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
9992
+ });
9993
+ }
9994
+ invalidSegments.sort((a, b) => a.start - b.start);
9995
+ if (invalidSegments.length > 0) {
9996
+ let lastEnd = 0;
9997
+ const underline = invalidSegments.reduce((acc, segment) => {
9998
+ const spaces = ' '.repeat(segment.start - lastEnd);
9999
+ const arrows = '^'.repeat(segment.length);
10000
+ lastEnd = segment.start + segment.length;
10001
+ return acc + spaces + arrows;
10002
+ }, '');
10003
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
10004
+ .map((e) => e.error)
10005
+ .join('\n')}\n${path}\n${underline}`);
10006
+ }
10007
+ return path;
10008
+ });
10009
+ /**
10010
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
10011
+ */
10012
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
10013
+
10014
+ /**
10015
+ * @license
10016
+ * Copyright 2025 Google LLC
10017
+ * SPDX-License-Identifier: Apache-2.0
10018
+ */
10019
+ class BaseAgents extends APIResource {
10020
+ /**
10021
+ * Creates a new Agent (Typed version for SDK).
10022
+ */
10023
+ create(params = {}, options) {
10024
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
10025
+ return this._client.post(path `/${api_version}/agents`, Object.assign({ body }, options));
10026
+ }
10027
+ /**
10028
+ * Lists all Agents.
10029
+ */
10030
+ list(params = {}, options) {
10031
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
10032
+ return this._client.get(path `/${api_version}/agents`, Object.assign({ query }, options));
10033
+ }
10034
+ /**
10035
+ * Deletes an Agent.
10036
+ */
10037
+ delete(id, params = {}, options) {
10038
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10039
+ return this._client.delete(path `/${api_version}/agents/${id}`, options);
10040
+ }
10041
+ /**
10042
+ * Gets a specific Agent.
10043
+ */
10044
+ get(id, params = {}, options) {
10045
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
10046
+ return this._client.get(path `/${api_version}/agents/${id}`, options);
10047
+ }
10048
+ }
10049
+ BaseAgents._key = Object.freeze(['agents']);
10050
+ class Agents extends BaseAgents {
10051
+ }
10052
+
9931
10053
  /**
9932
10054
  * @license
9933
10055
  * Copyright 2025 Google LLC
@@ -10589,87 +10711,6 @@ class LegacyLyriaStream extends Stream {
10589
10711
  }
10590
10712
  }
10591
10713
 
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
10714
  /**
10674
10715
  * @license
10675
10716
  * Copyright 2025 Google LLC
@@ -10745,18 +10786,32 @@ class Interactions extends BaseInteractions {
10745
10786
  function addOutputProperties(interaction) {
10746
10787
  var _a, _b;
10747
10788
  const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
10748
- let firstTrailing = steps.length;
10749
- while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
10750
- firstTrailing--;
10751
- }
10752
- const modelSteps = steps.slice(firstTrailing);
10753
- const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
10789
+ // output_text: scan backwards across all steps (stopping at user_input),
10790
+ // skip non-text content until the first text item is found, then collect
10791
+ // text until a non-text barrier is hit.
10754
10792
  const textParts = [];
10755
- for (let i = output.length - 1; i >= 0; i--) {
10756
- const content = output[i];
10757
- if (content.type !== 'text')
10793
+ let collecting = false;
10794
+ outer: for (let i = steps.length - 1; i >= 0; i--) {
10795
+ const step = steps[i];
10796
+ if (step.type === 'user_input')
10758
10797
  break;
10759
- textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
10798
+ if (step.type !== 'model_output' || !step.content) {
10799
+ if (collecting)
10800
+ break outer;
10801
+ continue;
10802
+ }
10803
+ const content = step.content;
10804
+ for (let j = content.length - 1; j >= 0; j--) {
10805
+ const item = content[j];
10806
+ if (item.type === 'text') {
10807
+ collecting = true;
10808
+ textParts.push((_b = item.text) !== null && _b !== void 0 ? _b : '');
10809
+ }
10810
+ else if (collecting) {
10811
+ // Hit a non-text barrier after we started collecting.
10812
+ break outer;
10813
+ }
10814
+ }
10760
10815
  }
10761
10816
  const output_text = textParts.reverse().join('');
10762
10817
  let output_image;
@@ -11499,6 +11554,7 @@ class GeminiNextGenAPIClient extends BaseGeminiNextGenAPIClient {
11499
11554
  super(...arguments);
11500
11555
  this.interactions = new Interactions(this);
11501
11556
  this.webhooks = new Webhooks(this);
11557
+ this.agents = new Agents(this);
11502
11558
  }
11503
11559
  }
11504
11560
  _a = GeminiNextGenAPIClient;
@@ -11519,6 +11575,7 @@ GeminiNextGenAPIClient.UnprocessableEntityError = UnprocessableEntityError;
11519
11575
  GeminiNextGenAPIClient.toFile = toFile;
11520
11576
  GeminiNextGenAPIClient.Interactions = Interactions;
11521
11577
  GeminiNextGenAPIClient.Webhooks = Webhooks;
11578
+ GeminiNextGenAPIClient.Agents = Agents;
11522
11579
 
11523
11580
  /**
11524
11581
  * @license
@@ -20951,6 +21008,14 @@ class GoogleGenAI {
20951
21008
  this._webhooks = this.getNextGenClient().webhooks;
20952
21009
  return this._webhooks;
20953
21010
  }
21011
+ get agents() {
21012
+ if (this._agents !== undefined) {
21013
+ return this._agents;
21014
+ }
21015
+ console.warn('GoogleGenAI.agents: Agents usage is experimental and may change in future versions.');
21016
+ this._agents = this.getNextGenClient().agents;
21017
+ return this._agents;
21018
+ }
20954
21019
  constructor(options) {
20955
21020
  var _a, _b;
20956
21021
  if (options.apiKey == null) {